limixbot 0.3.38 → 0.3.40

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 (131) hide show
  1. package/dist/assets/{ActivityPanel-BOGOh4ZF.js → ActivityPanel-C78UlJ_B.js} +1 -1
  2. package/dist/assets/{App-CmgJZ6UZ.js → App-DoK6OnP_.js} +9 -9
  3. package/dist/assets/{AppEventEditor-DPlpUtIr.js → AppEventEditor-CrUG4a3D.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-BziyWGCo.js → BotSettingsDialog-CvcYYLw-.js} +1 -1
  5. package/dist/assets/{BrowserPanel-CzmQXe5J.js → BrowserPanel-CCfO4ItU.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-CDYMGnL1.js → BrowserProfilesManager-BfuF_oUa.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-CQA6KE_h.js → CloudAddDialog-DSqiG9RZ.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-DtVi0vfS.js → ComputerFilesPane-q5cwxKow.js} +1 -1
  9. package/dist/assets/{ComputerPanel-CmdbPD7R.js → ComputerPanel-Cqw5ivpE.js} +2 -2
  10. package/dist/assets/{DataPanel-Cr4h7Coo.js → DataPanel-CI_7GCCI.js} +1 -1
  11. package/dist/assets/{DesktopViewer-B9vApE1S.js → DesktopViewer-BX0YJJ9T.js} +1 -1
  12. package/dist/assets/{FilesView-DvKL7zC3.js → FilesView-CePiPQtk.js} +1 -1
  13. package/dist/assets/{GrokMoveDialog-CrRdpK7_.js → GrokMoveDialog-plHjPcxW.js} +1 -1
  14. package/dist/assets/{InspectorPanel-DcMd4fV0.js → InspectorPanel-BtJWpmNb.js} +1 -1
  15. package/dist/assets/{KeyboardShortcutsModal-CaU5r2LI.js → KeyboardShortcutsModal-CvI39Dyv.js} +1 -1
  16. package/dist/assets/{LiveDesktop-C4LFugZf.js → LiveDesktop-CWCNNVVb.js} +1 -1
  17. package/dist/assets/{LocalVmWorkspace-ohSgFrCf.js → LocalVmWorkspace-Dj0D8KZg.js} +1 -1
  18. package/dist/assets/{MacLocalControl-CsrY8QAl.js → MacLocalControl-DI9rmipM.js} +1 -1
  19. package/dist/assets/{MarkdownFilePreview-CTlnFIy4.js → MarkdownFilePreview-C2wq8ggW.js} +1 -1
  20. package/dist/assets/{MenuMotion-DQh3Is8R.js → MenuMotion-9KpZfoc6.js} +1 -1
  21. package/dist/assets/{NewBotDialog-CoFNQVYw.js → NewBotDialog-yH4tNqbg.js} +1 -1
  22. package/dist/assets/{PhoneAppDialog-DCj5iqhX.js → PhoneAppDialog-C7-lv79J.js} +1 -1
  23. package/dist/assets/{PlacesRail-Cq-ZB7CK.js → PlacesRail-DgLRkWzN.js} +1 -1
  24. package/dist/assets/{PluginsPanel-BG2jguvx.js → PluginsPanel-BjhDlFfS.js} +1 -1
  25. package/dist/assets/{ProIntroduction-BiUctEhJ.js → ProIntroduction-CX5wa_L9.js} +1 -1
  26. package/dist/assets/{RemoteAgentSettingsPanel-CbqD-SQ9.js → RemoteAgentSettingsPanel-uKPEbc5u.js} +1 -1
  27. package/dist/assets/{RoomPanel-cWDdFpMA.js → RoomPanel-CUN0w3uU.js} +1 -1
  28. package/dist/assets/{RoutinesPage-YfPH0exd.js → RoutinesPage-C1DsUtyJ.js} +1 -1
  29. package/dist/assets/{SettingsModal-DDT4_jvU.js → SettingsModal-Ly5CgfzY.js} +4 -4
  30. package/dist/assets/{ShareTeamDialog-B6ycp6wT.js → ShareTeamDialog-bekuOz52.js} +1 -1
  31. package/dist/assets/{SignedInSites-iY5S4w8F.js → SignedInSites-B3Pypdn7.js} +1 -1
  32. package/dist/assets/{TeamLibraryPanel-CZqqN2A8.js → TeamLibraryPanel-D6jp7yJH.js} +1 -1
  33. package/dist/assets/{TeamMapPage-D39wDKzA.js → TeamMapPage-Ds-NTRhm.js} +1 -1
  34. package/dist/assets/{TriggersPage-CTpXasDB.js → TriggersPage-B9I-fybZ.js} +1 -1
  35. package/dist/assets/{VisibilitySection-C1VqWahV.js → VisibilitySection-Bmoy4R5T.js} +1 -1
  36. package/dist/assets/{WebhookTrigger-BH7ozW43.js → WebhookTrigger-D222Fm7h.js} +1 -1
  37. package/dist/assets/{WorksOnGrid-Ck6Ote94.js → WorksOnGrid-Ihbs1ZDY.js} +1 -1
  38. package/dist/assets/{abnfDiagram-YUKMZFIV-Cmmc-JqZ.js → abnfDiagram-YUKMZFIV-iRkRRTmn.js} +1 -1
  39. package/dist/assets/{activity-B0HCw_YB.js → activity-D3yGGWz9.js} +1 -1
  40. package/dist/assets/{architectureDiagram-47P4ROYG-Cygk56V9.js → architectureDiagram-47P4ROYG-B-l-Tbc0.js} +1 -1
  41. package/dist/assets/{blockDiagram-E7TT5TSB-Dt_ucQNN.js → blockDiagram-E7TT5TSB-BPHNVO2-.js} +1 -1
  42. package/dist/assets/{c4Diagram-CRA5TL53-DhzbTQMn.js → c4Diagram-CRA5TL53-Ces14mNL.js} +1 -1
  43. package/dist/assets/{calendar-days-zGEHZHsR.js → calendar-days-DNgw_jzq.js} +1 -1
  44. package/dist/assets/channel-CLFluAXE.js +1 -0
  45. package/dist/assets/{chunk-2Q5K7J3B-Bw-JIErR.js → chunk-2Q5K7J3B-BBv2HgLY.js} +1 -1
  46. package/dist/assets/{chunk-5VM5RSS4-CXKPVT0R.js → chunk-5VM5RSS4-Ms8vx6uj.js} +1 -1
  47. package/dist/assets/{chunk-7TKQ45FW-BxSyX0ew.js → chunk-7TKQ45FW-CoQ_n3fY.js} +1 -1
  48. package/dist/assets/{chunk-AW2ZBBNX-BqlPBPxb.js → chunk-AW2ZBBNX-CLnH6qE9.js} +1 -1
  49. package/dist/assets/{chunk-FVRAUYC3-Dk0ar-fZ.js → chunk-FVRAUYC3-CzEI0PkV.js} +2 -2
  50. package/dist/assets/{chunk-HTAEGDNF-CL6sWWEP.js → chunk-HTAEGDNF-tQeKhP4P.js} +1 -1
  51. package/dist/assets/{chunk-JWPE2WC7-kxRDp2MG.js → chunk-JWPE2WC7-Bels7hbY.js} +1 -1
  52. package/dist/assets/{chunk-KQW6MTUR-CPu99H_Q.js → chunk-KQW6MTUR-C_OPTqju.js} +1 -1
  53. package/dist/assets/{chunk-XXDRQBXY-CitCT4ko.js → chunk-XXDRQBXY-lLPvGZOB.js} +1 -1
  54. package/dist/assets/{classDiagram-v2-K4WV4PDN-BYD3SvLH.js → classDiagram-v2-K4WV4PDN-DEGC9KSb.js} +1 -1
  55. package/dist/assets/{coins-DvRSEyo-.js → coins-BUPhLqLr.js} +1 -1
  56. package/dist/assets/{core-CMXrjSID.js → core-Cmvm9EBY.js} +1 -1
  57. package/dist/assets/{cose-bilkent-JH36ORCC-BXMQu6mM.js → cose-bilkent-JH36ORCC-B4guJJ7b.js} +1 -1
  58. package/dist/assets/{cynefin-EF2NZ3EQ-D9AJi1tA.js → cynefin-EF2NZ3EQ-DzL2Ko-S.js} +1 -1
  59. package/dist/assets/{cynefinDiagram-3GCD6N5R-CXDYCg5C.js → cynefinDiagram-3GCD6N5R-DOhRhSCa.js} +1 -1
  60. package/dist/assets/{dagre-W4DXFKR2-DiOrg6oT.js → dagre-W4DXFKR2-ClVlfmbp.js} +1 -1
  61. package/dist/assets/{diagram-2UJZ2QOL-DLGorqN9.js → diagram-2UJZ2QOL-CCORQMGQ.js} +1 -1
  62. package/dist/assets/{diagram-OVF4WLC6-BqS3ZVMg.js → diagram-OVF4WLC6-BA05pSeN.js} +1 -1
  63. package/dist/assets/{diagram-PFPMY2P6-DuABPcmU.js → diagram-PFPMY2P6-Buk95mAY.js} +1 -1
  64. package/dist/assets/{diagram-UMYRVEAY-DQ7coaLd.js → diagram-UMYRVEAY-C_N8yC5C.js} +1 -1
  65. package/dist/assets/{diagram-YEKJPTXX-B6ladKGK.js → diagram-YEKJPTXX-BcGFdDU0.js} +1 -1
  66. package/dist/assets/{diagram-ZIFT7M5P-bL4zZXwc.js → diagram-ZIFT7M5P-CrsI0m0f.js} +1 -1
  67. package/dist/assets/{ebnfDiagram-VR2GEFS7-vlmGocwO.js → ebnfDiagram-VR2GEFS7-ZuofO3J3.js} +1 -1
  68. package/dist/assets/{elk-IJKZMXRS-DjRkBuW7.js → elk-IJKZMXRS-B9HPBoMc.js} +1 -1
  69. package/dist/assets/{erDiagram-O2IAPWRE-CzM5EgMB.js → erDiagram-O2IAPWRE-yblUS7CX.js} +1 -1
  70. package/dist/assets/{file-up-B6Iqt3Df.js → file-up-CJGgT920.js} +1 -1
  71. package/dist/assets/{flowDiagram-OXPTDLAJ-988-3L2t.js → flowDiagram-OXPTDLAJ-BoRQKWEE.js} +1 -1
  72. package/dist/assets/{ganttDiagram-R7TSEDQI-DPKqo_OS.js → ganttDiagram-R7TSEDQI-Mqmf_lTP.js} +1 -1
  73. package/dist/assets/{gitGraphDiagram-XJZIOB7I-B8M3sAez.js → gitGraphDiagram-XJZIOB7I-ChOVYU-I.js} +1 -1
  74. package/dist/assets/{import-name-DLNARoxV.js → import-name-D_O0Z9qB.js} +1 -1
  75. package/dist/assets/{index-BEz8yQqm.js → index-BNuCZ6CX.js} +2 -2
  76. package/dist/assets/{index-CWUEi7VF.js → index-BvjpOIdn.js} +1 -1
  77. package/dist/assets/{infoDiagram-5W2HQ5XZ-L9hSU2yH.js → infoDiagram-5W2HQ5XZ-DzVrRFee.js} +1 -1
  78. package/dist/assets/{ishikawaDiagram-K3B6WC7H-D-4BbbRE.js → ishikawaDiagram-K3B6WC7H-B1AtMtWp.js} +1 -1
  79. package/dist/assets/{journeyDiagram-COXZFDF6-00nZ63b2.js → journeyDiagram-COXZFDF6-D98AinIQ.js} +1 -1
  80. package/dist/assets/{kanban-definition-P3RFRI5V-DmyWYjFi.js → kanban-definition-P3RFRI5V-DyF07Cia.js} +1 -1
  81. package/dist/assets/{mcp-servers-IPuVOp3v.js → mcp-servers-CWLCIWVv.js} +1 -1
  82. package/dist/assets/{mermaid.core-BoYzy4T6.js → mermaid.core-BkGLuasi.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LZFPQGKD-BO5FJxVo.js → mindmap-definition-LZFPQGKD-CtEZ4egD.js} +1 -1
  84. package/dist/assets/{minimize-zVujF16t.js → minimize-D02to6Fy.js} +1 -1
  85. package/dist/assets/{monitor-D4StKPgF.js → monitor-cPSwTZbh.js} +1 -1
  86. package/dist/assets/{new-bot-Dx98N2o7.js → new-bot-BAm0i3N-.js} +1 -1
  87. package/dist/assets/{org-library-CFROpeeR.js → org-library-CVRs5XpH.js} +1 -1
  88. package/dist/assets/{package-format-C3F2bHdL.js → package-format-nP_LfEpp.js} +1 -1
  89. package/dist/assets/{pegDiagram-BGZESJAR-D-3JZOS5.js → pegDiagram-BGZESJAR-BA9RLREu.js} +1 -1
  90. package/dist/assets/{pieDiagram-CAPJLFHJ-BMYxuny0.js → pieDiagram-CAPJLFHJ-BR2mMjlL.js} +1 -1
  91. package/dist/assets/{quadrantDiagram-GDMTTRAM-CfoQHrBh.js → quadrantDiagram-GDMTTRAM-F5WV656C.js} +1 -1
  92. package/dist/assets/{rail-Cj6Euigf.js → rail-C4RLSvjm.js} +1 -1
  93. package/dist/assets/{railroadDiagram-SM67HX2B-CiK1qT26.js → railroadDiagram-SM67HX2B-Cd6uxfxc.js} +1 -1
  94. package/dist/assets/{remote-desktop-panel-DNbYEaiU.js → remote-desktop-panel-eUh-91Nm.js} +1 -1
  95. package/dist/assets/{requirementDiagram-X7JNWC4A-Dt9XKURP.js → requirementDiagram-X7JNWC4A-Cfo_0cMh.js} +1 -1
  96. package/dist/assets/{sankeyDiagram-UM26HJRW-C49xf8OP.js → sankeyDiagram-UM26HJRW-TDjyYx-y.js} +1 -1
  97. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-D98EvmRQ.js → sequenceDiagram-ZO4K6R2Y-Ko062Fce.js} +1 -1
  98. package/dist/assets/{sizeCapture-INFHLROL-CswrwSYS.js → sizeCapture-INFHLROL-BrrtOSNi.js} +1 -1
  99. package/dist/assets/{stateDiagram-v2-TBUQTH76-DsDaEEKh.js → stateDiagram-v2-TBUQTH76-B1qzPqwN.js} +1 -1
  100. package/dist/assets/{styles-h5tFt3-N.js → styles-CYPAO9i1.js} +5 -5
  101. package/dist/assets/{swimlanes-N4OXWK64-C6s_q3Zy.js → swimlanes-N4OXWK64-Dsuqhiei.js} +1 -1
  102. package/dist/assets/swimlanesDiagram-K3J5GTZL-Ck2z47VC.js +8 -0
  103. package/dist/assets/{team-share-4fayckbz.js → team-share-zViFUsSH.js} +1 -1
  104. package/dist/assets/{timeline-definition-YOQAKGHF-GpdVhXM5.js → timeline-definition-YOQAKGHF-zBd8HYLV.js} +1 -1
  105. package/dist/assets/{usecaseDiagram-VIAY4XPW-t4q34LDq.js → usecaseDiagram-VIAY4XPW-DkA9LTMv.js} +1 -1
  106. package/dist/assets/{vennDiagram-BLWOH2XV-BHz44-A_.js → vennDiagram-BLWOH2XV-BU2g61ns.js} +1 -1
  107. package/dist/assets/{vi-DpKxsr6f.js → vi-D2CCwYiV.js} +1 -1
  108. package/dist/assets/{wardleyDiagram-YMQ3BMBF-Br9pWGTd.js → wardleyDiagram-YMQ3BMBF-Bigp2Sxm.js} +1 -1
  109. package/dist/assets/{xychartDiagram-TAQBALBS-Qr27JhVO.js → xychartDiagram-TAQBALBS-DrSgdkAt.js} +1 -1
  110. package/dist/index.html +2 -2
  111. package/dist/rail.html +4 -4
  112. package/dist-server/container-mcp.js +5 -4
  113. package/dist-server/drivers/agents-proxy.js +2 -2
  114. package/dist-server/index.js +296 -289
  115. package/dist-server/openmausbot.js +50 -47
  116. package/dist-server/package.json +1 -1
  117. package/dist-server/pair-cli.js +50 -47
  118. package/dist-server/server/avatar-image.js +2 -0
  119. package/dist-server/server/drivers/agents-image-tools.js +1 -1
  120. package/dist-server/server/drivers/codex.js +1 -1
  121. package/dist-server/server/image-generation-config.js +2 -0
  122. package/dist-server/server/image-generation.js +26 -6
  123. package/dist-server/server/index.js +12 -1
  124. package/dist-server/server/limix-image-connections.js +22 -0
  125. package/dist-server/server/routes/image-settings.js +31 -1
  126. package/dist-server/shared/image-generation.js +1 -1
  127. package/dist-server/vps-container-mcp.js +5 -4
  128. package/dist-server/workspace-backup.worker.js +5 -4
  129. package/package.json +1 -1
  130. package/dist/assets/channel-ChTUuA50.js +0 -1
  131. package/dist/assets/swimlanesDiagram-K3J5GTZL-B0D3dNt9.js +0 -8
@@ -1,4 +1,4 @@
1
- import{c as ut,r as l,j as e,t,a as M,S as mt,f as ge,p as ks,g as js,a8 as Lr,X as _e,i as Ns,C as Br,a9 as Na,L as wt,aK as Or,aT as Mr,a0 as zr,B as Ur,b as Oe,aU as Dr,aV as Fr,aW as Qs,ao as Zs,aX as _r,ap as $r,aY as Kr,aZ as Hr,a3 as Wr,G as Gr,a_ as Vr,a$ as ws,b0 as qr,b1 as Jr,b2 as en,b3 as Ss,l as Yr,b4 as Xr,m as tn,b5 as wa,d as Qr,b6 as Zr,q as el,b7 as tl,o as sl,as as nl,b8 as sn,ar as al,b9 as il,ba as nn,bb as an,bc as rn,bd as rl,be as ll,ac as ol,bf as cl,bg as dl}from"./styles-h5tFt3-N.js";import{bB as z,bP as It,u as V,S as ue,n as D,D as me,cM as ul,cI as Sa,T as Se,gY as Le,eK as Xe,gZ as ml,a0 as Be,eI as pl,eJ as xl,g_ as is,g$ as rt,h0 as Ca,h1 as Cs,h2 as Es,h3 as hl,e0 as ln,h4 as Ea,h5 as Aa,h6 as gl,h7 as fl,h8 as bl,bN as ce,b_ as Q,e8 as rs,eH as yl,h9 as Ia,ha as Nt,hb as Pt,hc as Pa,hd as Ra,he as Te,hf as Fe,hg as vl,hh as kl,hi as jl,hj as Nl,hk as wl,C as Qe,hl as Ta,hm as Sl,hn as Cl,ho as La,hp as Ba,hq as ye,hr as ve,dp as on,hs as Rt,ht as El,hu as Al,hv as Il,hw as Pl,hx as Rl,gR as Oa,bt as Tl,hy as it,W as Ll,dH as Bl,Q as Ma,hz as za,hA as Ol,aQ as St,ft as ot,fu as ct,hB as Ml,P as Ye,r as zl,ck as Ul,gG as Dl,hC as Tt,hD as Ua,hE as Fl,hF as _l,hG as cn,hH as Da,hI as Lt,hJ as Fa,hK as $l,hL as Kl,hM as Hl,hN as Wl,G as Gl,hO as Vl,hP as dt,ef as Bt,hQ as ql,hR as Jl,hS as Yl,hT as Xl,fB as Ql,hU as dn,hV as Zl,hW as eo,K as to,hX as un,hY as so,ed as _a,hZ as no,h_ as ao,h$ as io,i0 as ro,i1 as lo,i2 as oo,i3 as $a,i4 as co,i5 as uo,i6 as mo,i7 as po,i8 as xo,i9 as ho,ia as Ka,ib as go,ic as fo,dN as bo,id as yo,e9 as vo,ie as ko,ig as jo,ih as No,c as wo,ii as mn,ij as So,ik as pn,l as Co,il as Eo,im as Ao,io as Io,bH as Po,ip as Ro,iq as To,ir as Lo,is as Bo,it as Ha,fr as st,iu as Oo,fq as Mo,iv as Wa,iw as zo,ix as Ga,iy as Uo,iz as xn,iA as Do,iB as Fo,iC as _o,iD as $o,iE as Ko,iF as Ho,iG as Wo,iH as Go,iI as As,iJ as Vo,fh as Va,m as qo,iK as Jo,iL as Yo,iM as hn,iN as Xo,iO as Qo,iP as gn,iQ as Zo,bj as ec,iR as tc,iS as sc,iT as nc,iU as ac,iV as ic,iW as fn,iX as rc,by as Is,iY as lc,bz as oc,iZ as cc,i_ as dc,i$ as uc,j0 as mc,j1 as pc,j2 as xc,j3 as hc,j4 as gc,j5 as bn,gu as fc,j6 as bc,j7 as yc,j8 as qa,j9 as vc,ja as kc,jb as jc,jc as Ja,jd as Ya,je as Xa,jf as Nc,jg as wc,jh as Sc,d5 as Cc,I as Ec,ji as Qa,eC as Ac,bY as yn,jj as vn,e$ as kn,d$ as Ic,a2 as Pc,aC as Rc,jk as Tc,jl as Lc,jm as Bc}from"./App-CmgJZ6UZ.js";import{L as J,P as Ce,z as pt,E as Oc,M as Mc,ak as zc,a0 as Uc,X as Dc,K as Fc,x as Ps,C as Za,B as Ot,al as _c,am as $c,an as Kc,d as ei,r as Hc,A as Wc,U as ti,c as Gc,ao as Vc,ap as qc,N as Jc,ac as Yc,aq as Xc,b as Qc,y as Zc,V as ed,O as Ft}from"./PlacesRail-Cq-ZB7CK.js";import{C as Rs,a as td,R as we}from"./MenuMotion-DQh3Is8R.js";import{l as si,M as sd,w as jn}from"./MacLocalControl-CsrY8QAl.js";import{Q as nd}from"./VisibilitySection-C1VqWahV.js";import{r as ni,a as ai,b as ad,i as id,C as rd,c as ld,p as od}from"./index-BEz8yQqm.js";import{c as cd,A as dd,w as ud,d as md,e as Nn}from"./activity-B0HCw_YB.js";import{U as ii,R as ri,B as li,S as oi,a as ci,D as di,T as ui,C as mi,L as ls,b as pi,F as xi,A as os,E as pd,c as xd,P as hd,d as gd,e as fd,N as bd}from"./NewBotDialog-CoFNQVYw.js";import{a as yd,u as vd,C as hi,b as kd,P as jd}from"./ProIntroduction-BiUctEhJ.js";import{M as gi}from"./monitor-D4StKPgF.js";import{C as Nd}from"./coins-DvRSEyo-.js";import"./org-library-CFROpeeR.js";import"./package-format-C3F2bHdL.js";import"./mcp-servers-IPuVOp3v.js";import"./WorksOnGrid-Ck6Ote94.js";import"./new-bot-Dx98N2o7.js";import"./RoutinesPage-YfPH0exd.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-4fayckbz.js";import"./BrowserProfilesManager-CDYMGnL1.js";import"./SignedInSites-iY5S4w8F.js";const wd=[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]],Sd=ut("cloud-download",wd);const Cd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ed=ut("palette",Cd);const Ad=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],Id=ut("scroll-text",Ad);const Pd=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Rd=ut("terminal",Pd);const Td=[["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"}]],Ld=ut("unplug",Td);function Ts(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}const cs="limix.settings.size",Bd=640,Od=460,_t=()=>typeof window<"u"&&window.innerWidth>=768;function $t(s,n,a){const i=Math.max(320,window.innerWidth-32),r=Math.max(320,window.innerHeight-96);s.style.width=`${Math.round(Math.min(Math.max(n,Math.min(Bd,i)),i))}px`,s.style.height=`${Math.round(Math.min(Math.max(a,Math.min(Od,r)),r))}px`}function Md(s){s.style.width="",s.style.height="";try{window.localStorage.removeItem(cs)}catch{}}const zd=[{sx:1,sy:0,cls:"right-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:-1,sy:0,cls:"left-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:0,sy:1,cls:"bottom-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:0,sy:-1,cls:"top-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:1,sy:1,cls:"bottom-0 right-0 h-4 w-4",cursor:"cursor-nwse-resize"},{sx:-1,sy:1,cls:"bottom-0 left-0 h-4 w-4",cursor:"cursor-nesw-resize"}];function Ud(){const s=l.useRef(null);l.useEffect(()=>{const a=s.current?.parentElement;if(!a)return;if(a.style.maxWidth="100%",a.style.maxHeight="100%",_t())try{const r=JSON.parse(window.localStorage.getItem(cs)??"null");r&&typeof r.w=="number"&&typeof r.h=="number"&&$t(a,r.w,r.h)}catch{}const i=()=>{a.style.width&&(_t()?$t(a,a.offsetWidth,a.offsetHeight):(a.style.width="",a.style.height=""))};return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);const n=a=>i=>{const r=s.current?.parentElement;if(!r||!_t())return;i.preventDefault();const c=i.clientX,o=i.clientY,d=r.offsetWidth,m=r.offsetHeight,u=x=>$t(r,d+a.sx*(x.clientX-c)*2,m+a.sy*(x.clientY-o)*2),p=()=>{window.removeEventListener("pointermove",u);try{window.localStorage.setItem(cs,JSON.stringify({w:r.offsetWidth,h:r.offsetHeight}))}catch{}};window.addEventListener("pointermove",u),window.addEventListener("pointerup",p,{once:!0})};return e.jsx("span",{ref:s,className:"contents",children:zd.map(a=>e.jsx("span",{"aria-hidden":"true",title:z("Kéo để đổi kích thước (bấm đúp để đặt lại)","Drag to resize (double-click to reset)"),className:`absolute z-20 hidden touch-none md:block ${a.cls} ${a.cursor}`,onPointerDown:n(a),onDoubleClick:()=>{const i=s.current?.parentElement;i&&Md(i)}},`${a.sx}${a.sy}`))})}function ke({children:s,note:n="settings.adminOnly.change"}){return It()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Ls(s,n,a="start",i=0){const r=n.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,a==="center"?r-(s.clientHeight-(n.offsetHeight??0))/2:r-i)}function Dd(s){for(let n=s.parentElement;n;n=n.parentElement){const a=getComputedStyle(n).overflowY;if((a==="auto"||a==="scroll")&&n.scrollHeight>n.clientHeight)return n}return null}function Fd(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(!1),[r,c]=l.useState(null),o=s.config?.tts?.everyReply===!0,d=()=>{i(!0),c(null),D("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1))};return 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(ue,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}function Kt(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const De=M(Le,"font-sans"),_d=[5,10,20,30,60],Ht="ui-icon-button shrink-0 hover:text-ink",Wt={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},ds={count:64,length:200},$d=s=>s.length<=ds.count&&s.every(n=>n.length<=ds.length),us=(s,n)=>D(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function fi({server:s,disabled:n,onPick:a}){return e.jsxs(me,{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([..._d,...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 Kd(){const{state:s,dispatch:n,refreshInstances:a}=V(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(u=>u.instanceId==="openaiCompat"&&u.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const m=u=>{i||(r(!0),o(null),us(d.instanceId,{replyWaitMinutes:u}).then(async({instances:p})=>{Array.isArray(p)?n({type:"instances",instances:p}):await a({reportErrors:!0})}).catch(p=>o(p.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(fi,{server:d,disabled:i,onPick:m}),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 Hd(){const{state:s}=V();return e.jsx(Wd,{servers:Ts(s.instances)})}function Wd({servers:s}){const{dispatch:n,refreshInstances:a}=V(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,p]=l.useState(""),[x,h]=l.useState(null),[g,b]=l.useState(null),[y,f]=l.useState(null),[j,C]=l.useState(""),w=!!(i.trim()&&c.trim()&&d.trim()),S=(k,B,v,A)=>{x||(h(k),b(null),B().then(async({instances:P})=>{Array.isArray(P)?n({type:"instances",instances:P}):await a({reportErrors:!0}),v?.()}).catch(P=>b({text:P.message||t("apiInstances.failed"),at:A})).finally(()=>h(null)))},I=()=>w&&S("add",()=>D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...Kt(u).length?{models:Kt(u)}:{}})}).then(k=>(Xe("custom_endpoint","settings","unverified"),k),k=>{throw Xe("custom_endpoint","settings","error"),k}),()=>{r(""),o(""),m(""),p("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] 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(k=>e.jsxs("div",{className:"mb-1.5 rounded-lg border border-hairline/60 bg-inset px-3 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-[12px] text-ink",children:k.displayName}),k.url&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:k.url})]}),e.jsx(fi,{server:k,disabled:x!==null,onPick:B=>S("other",()=>us(k.instanceId,{replyWaitMinutes:B}))}),e.jsx("button",{type:"button",onClick:()=>{C((k.managedModels??[]).join(", ")),f(y===k.instanceId?null:k.instanceId),b(null)},disabled:x!==null,"aria-label":t("apiInstances.editModels",{name:k.displayName}),"aria-expanded":y===k.instanceId,title:t("apiInstances.editModels",{name:k.displayName}),className:Ht,children:e.jsx(ul,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>S("other",()=>D(`/api/instances/${encodeURIComponent(k.instanceId)}/refresh-models`,{method:"POST"})),disabled:x!==null,"aria-label":t("apiInstances.refreshModels",{name:k.displayName}),title:t("apiInstances.refreshModels",{name:k.displayName}),className:Ht,children:e.jsx(Sa,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>S("other",()=>D(`/api/instances/${encodeURIComponent(k.instanceId)}`,{method:"DELETE"})),disabled:x!==null,"aria-label":t("apiInstances.remove",{name:k.displayName}),title:t("apiInstances.remove",{name:k.displayName}),className:`${Ht} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Se,{size:13,"aria-hidden":"true"})})]}),y===k.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsx("input",{value:j,onChange:B=>C(B.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:k.displayName}),spellCheck:!1,disabled:x!==null,className:M(De,"font-mono")}),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 B=Kt(j);if(!$d(B)){b({text:t("apiInstances.modelsLimit",ds),at:k.instanceId});return}S("other",()=>us(k.instanceId,{models:B}),()=>f(null),k.instanceId)},disabled:x!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>f(null),disabled:x!==null,className:"ui-button",children:t("common.cancel")})]}),g?.at===k.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g.text})]})]},k.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Wt.name),o(Wt.url)},disabled:x!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===Wt.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:k=>r(k.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:x!==null,className:De}),e.jsx("input",{type:"url",value:c,onChange:k=>o(k.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:x!==null,className:M(De,"font-mono")}),e.jsx("input",{type:"password",value:d,onChange:k=>m(k.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:x!==null,className:M(De,"font-mono")}),e.jsx("input",{value:u,onChange:k=>p(k.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:x!==null,className:M(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsxs("button",{type:"button",onClick:I,disabled:x!==null||!w,className:"ui-button self-start",children:[x==="add"?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),x==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),g&&!g.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:g.text})]})}const Gd="lm-studio";function Vd(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 qd({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=V(),r=Ts(n.instances),[c,o]=l.useState("1234"),[d,m]=l.useState(""),[u,p]=l.useState(!1),[x,h]=l.useState(null),g=Vd(c),b=!!(g&&r.some(f=>f.url===g)),y=()=>{u||!g||b||(p(!0),h(null),D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:g,key:d.trim()||Gd,catalog:"lmstudio"})}).then(async f=>{Xe("custom_endpoint","settings","unverified"),Array.isArray(f.instances)?a({type:"instances",instances:f.instances}):await i({reportErrors:!0}),m("")},f=>{Xe("custom_endpoint","settings","error"),h(f instanceof Error&&f.message?f.message:t("apiInstances.failed"))}).finally(()=>p(!1)))};return e.jsxs("div",{className:M(s&&"rounded-lg border border-hairline/40 bg-inset px-3 py-2"),children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:M("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 text-[12px] leading-4 text-ink-secondary",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:f=>o(f.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:u,className:M(De,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:f=>m(f.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:u,className:M(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),g&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:g}),e.jsxs("button",{type:"button",onClick:y,disabled:u||!g||b,className:"ui-button self-start",children:[u?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),u?t("lmStudio.adding"):t("lmStudio.add")]}),b&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),x&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:x})]})}const Jd="ollama",Yd="https://ollama.com/download",Xd=s=>`${s.replace(/\/+$/,"")}/v1`,Qd=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Zd({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=V(),[r,c]=l.useState(""),[o,d]=l.useState(null),[m,u]=l.useState(!1),[p,x]=l.useState(!1),[h,g]=l.useState(null),b=l.useRef(0),y=l.useRef(!1),f=l.useCallback(I=>{const k=++b.current;u(!0),g(null),D(`/api/instances/ollama${I?`?url=${encodeURIComponent(I)}`:""}`).then(B=>{k===b.current&&d(B.status)}).catch(B=>{k===b.current&&(d(null),g(B.message||t("apiInstances.failed")))}).finally(()=>{k===b.current&&u(!1)})},[]);l.useEffect(()=>{!s||y.current||(y.current=!0,f(""))},[s,f]);const j=o?Xd(o.url):null,C=!!(j&&(Ts(n.instances).some(I=>I.url===j)||Qd(n.config?.openaiCompat?.url,j))),w=!!(j&&!C&&!p&&!m&&(o?.state==="ready"||o?.state==="no-models")),S=()=>{!w||!j||(x(!0),g(null),D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:j,key:Jd,catalog:"ollama"})}).then(async I=>{Xe("custom_endpoint","settings","unverified"),Array.isArray(I.instances)?a({type:"instances",instances:I.instances}):await i({reportErrors:!0})},I=>{Xe("custom_endpoint","settings","error"),g(I instanceof Error&&I.message?I.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:m?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(J,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(ml,{status:o})}),!m&&o?.state==="not-running"&&e.jsx("a",{href:Yd,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:I=>c(I.target.value),onKeyDown:I=>{I.key==="Enter"&&f(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:p,className:M(Le,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs("button",{type:"button",onClick:S,disabled:!w,className:"ui-button",children:[p?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),p?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>f(r.trim()),disabled:m||p,className:"ui-button",children:[e.jsx(Sa,{size:12,"aria-hidden":"true"}),t("common.checkAgain")]})]}),C&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),h&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:h})]})}function eu(){const{state:s,dispatch:n}=V(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(!1),[u,p]=l.useState(null),[x,h]=l.useState(null),g=d||u!==null,b=(j,C)=>D("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[j]:C}}})}).then(w=>n({type:"configStatus",config:w})),y=()=>{const j=i.trim().toUpperCase(),C=pl(c);if(!(g||!j||!C)){if(!xl(C)){h(t("keys.notAKey"));return}m(!0),h(null),b(j,C).then(()=>{r(""),o("")}).catch(w=>h(w.message)).finally(()=>m(!1))}},f=j=>{g||(p(j),h(null),b(j,"").catch(C=>h(C.message)).finally(()=>p(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((j,C)=>C===0?[j]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},C),j])}),a.map(j=>e.jsxs("div",{"data-opencode-provider-key":j,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:M(Le,"block flex-1 truncate text-ink"),children:j}),e.jsx("button",{type:"button",onClick:()=>f(j),disabled:g,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:j}),className:"ui-button shrink-0",children:u===j?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},j)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:j=>{h(null),r(j.target.value)},onKeyDown:j=>j.key==="Enter"&&y(),disabled:g,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:M(Le,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:j=>{h(null),o(j.target.value)},onKeyDown:j=>j.key==="Enter"&&y(),disabled:g,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:M(Le,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:y,disabled:g||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),x&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:x})]})}function tu(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(!1),[r,c]=l.useState(null);if(!s.config?.anthropic?.configured)return null;const o=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),D("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.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:o?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(ue,{checked:o,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),o&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx(Be,{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 su(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=!!s.config?.vps?.configured,u=!a.trim()&&m;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const p=()=>{r||!a.trim()&&!m||(c(!0),d(null),D("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(x=>{n({type:"configStatus",config:x}),i(x.vps?.sshAlias??"")}).catch(x=>d(x.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/leomieo/limix-bot/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.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:x=>i(x.target.value),onKeyDown:x=>x.key==="Enter"&&p(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:M(Le,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:p,disabled:r||!a.trim()&&!m||a.trim()===(s.config?.vps?.sshAlias??""),className:M("ui-button shrink-0",!u&&"ui-button-primary"),title:u?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):u?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function nu(){const{state:s,dispatch:n}=V(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const p=i.trim()!==a,x=()=>{u.current||!p||(u.current=!0,o(!0),m(null),D("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(h=>n({type:"configStatus",config:h})).catch(h=>m(h.message)).finally(()=>{u.current=!1,o(!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:h=>r(h.target.value),onBlur:x,onKeyDown:h=>h.key==="Enter"&&x(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:M(Le,"pr-8")}),c&&e.jsx(J,{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 au="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",iu=1600,ru={opencodeProviders:()=>e.jsx(eu,{}),ollama:s=>e.jsx(Zd,{visible:s}),lmStudio:()=>e.jsx(qd,{heading:!1}),vps:()=>e.jsx(su,{})},lu={anthropic:()=>e.jsx(tu,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(nu,{}),e.jsx(Kd,{}),e.jsx(Hd,{})]}),box:()=>e.jsx(bl,{}),liveKey:()=>e.jsx(fl,{})};function bi(s,n){if(s.kind==="uses")return!1;const a=Es(s,n);return a.configured||a.included===!0}function ou({entry:s,visible:n}){const{state:a}=V(),i=l.useId(),c=Es(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:Ea,children:[e.jsx(Aa,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:ru[s.id]?.(n)})]})}function cu({entry:s}){const{state:n,dispatch:a}=V(),i=l.useId(),r=s.opens,c=Es(s,n.config),o=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ea,children:[e.jsx(Aa,{entry:s,status:o,titleId:i}),e.jsxs("div",{className:"flex flex-col gap-2 pl-8",children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(gl,{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 du({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(ln,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(ou,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(cu,{entry:s}):e.jsx(ln,{id:s.id,children:lu[s.id]?.()})}function uu({id:s,rows:n,open:a,onToggle:i}){const{state:r}=V(),c=is.find(u=>u.id===s),o=l.useId(),d=l.useId(),m=n.filter(u=>bi(u,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:au,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:o,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)})]}),m>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:m})}),e.jsx(Rs,{size:14,"aria-hidden":"true",className:M("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(u=>e.jsx(du,{entry:u,visible:a},u.id)),s==="voice"&&e.jsx(Fd,{})]})]})}function mu(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=Dd(i);return r&&Ls(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"),iu)),!0}function pu(){const{state:s}=V(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(is.filter(x=>x.id==="ai"||rt.some(h=>h.section===x.id&&bi(h,s.config))).map(x=>x.id))),c=l.useRef(null),o=Ca(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const x=rt.find(y=>y.id===o.row)?.section??"ai";a(""),r(y=>y.has(x)?y:new Set([...y,x]));let h=0,g=0;const b=()=>{mu(c.current,o,x)||++g>60?hl(o):h=window.requestAnimationFrame(b)};return h=window.requestAnimationFrame(b),()=>window.cancelAnimationFrame(h)},[o]);const m=s.config?.live?.provider==="azure",u=rt.filter(x=>Cs(x,d)&&!(m&&x.id==="liveCalls")),p=is.flatMap(x=>{const h=u.filter(g=>g.section===x.id);return h.length>0?[{id:x.id,rows:h}]:[]});return e.jsxs("div",{ref:c,"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(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:n,onChange:x=>a(x.target.value),onKeyDown:x=>{x.key!=="Escape"||!n||(x.preventDefault(),x.stopPropagation(),a(""))},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"})]}),p.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:n.trim()})}):p.map(({id:x,rows:h})=>e.jsx(uu,{id:x,rows:h,open:d!==""||i.has(x),onToggle:()=>r(g=>{const b=new Set(g);return b.has(x)?b.delete(x):b.add(x),b})},x))]})}function yi({simple:s=!1}){return null}function vi({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1);if(l.useEffect(()=>{let u=!0;return n?.state().then(p=>{u&&i(p)}).catch(()=>{}),()=>{u=!1}},[n]),!n||!a?.available)return null;const m=u=>{c(!0),d(!1),n.set(u).then(p=>{i(p),d(p.on!==u)},()=>d(!0)).finally(()=>c(!1))};return e.jsx(ce,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:o?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(ue,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>m(!a.on)})})}function xu(s=typeof window>"u"?void 0:window.ogb){return s?.platform==="darwin"&&s.talkShortcut?["talk","voice","shortcut","hotkey","hold to talk","push to talk","quick asks"]:[]}function ki(){const s=window.ogb?.talkShortcut,[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(!1);if(l.useEffect(()=>{let x=!0;return s?.state().then(h=>{x&&a(h)}).catch(()=>{}),()=>{x=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(x=>x.id===n.key)?.label??"",m=x=>{r(!0),o(!1),s.set(x).then(a,()=>o(!0)).finally(()=>r(!1))},u=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,p=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:x=>m({key:x.target.value}),children:n.keys.map(x=>e.jsx("option",{value:x.id,children:x.label},x.id))}),u&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:u})]});return e.jsx(ce,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||u?p:null,children:e.jsx(ue,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>m({enabled:!n.enabled})})})}const Gt=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function ji(){const[s,n]=l.useState(null),[a,i]=l.useState(!1),[r,c]=l.useState(!1),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return D("/api/attachment-storage").then(p=>{u&&n(p)}).catch(()=>{}),()=>{u=!1}},[]),!s)return null;const m=async()=>{c(!0),d(null);try{const u=await D("/api/attachment-storage",{method:"POST"});n(u);const p=t("settings.attachments.cleared",{count:u.removed,freed:Gt(u.freedBytes)});d(u.failed>0?{kind:"error",message:`${p} ${t("settings.attachments.failed",{count:u.failed})}`}:{kind:"success",message:p})}catch(u){d({kind:"error",message:u instanceof Error?u.message:String(u)})}finally{c(!1),i(!1)}};return e.jsx(ce,{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:Gt(s.usedBytes),max:Gt(s.maxBytes)})}),e.jsx("span",{className:"block",children:t(a?"settings.attachments.confirmText":"settings.attachments.help")})]}),message:o&&e.jsx("p",{role:o.kind==="error"?"alert":"status",className:M(o.kind==="error"?"text-danger":"text-success"),children:o.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:()=>{m()},disabled:r,className:"ui-button text-danger",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}function Ni({simple:s=!1}){const[n,a]=l.useState(!1),[i,r]=l.useState(null),[c,o]=l.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const p=await window.ogb.exportDiagnostics();p&&r({kind:"success",message:t("settings.diagnostics.saved",{path:p})})}catch(p){r({kind:"error",message:p instanceof Error?p.message:String(p)})}finally{a(!1)}}},m=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const p=await window.ogb.openLogsFolder();o(p.folder),p.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:p.folder})})}catch(p){r({kind:"error",message:p instanceof Error?p.message:String(p)})}}},u=!!window.ogb?.exportDiagnostics;return e.jsx(ce,{title:t("settings.diagnostics.title"),subtitle:t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),message: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:M("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),e.jsx("p",{"data-logs-help":!0,className:"text-ink-tertiary",children:t(u?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:u&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[window.ogb?.openLogsFolder&&e.jsx("button",{type:"button",onClick:()=>{m()},className:"ui-button",children:t("settings.diagnostics.openLogs")}),e.jsx("button",{onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})]})})}const hu="https://dash.cloudflare.com/profile/api-tokens",gu=/^[0-9a-f]{32}$/i,wn="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";function fu({failureText:s}){const{state:n,dispatch:a}=V(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[o,d]=l.useState(null),[m,u]=l.useState(""),[p,x]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(null),[f,j]=l.useState(null),C=(o??c).trim(),w=m.trim(),S=!w&&r&&o===null,I=o!==null&&C!==c,k=A=>a({type:"configStatus",config:A}),B=async()=>{if(!(p||!w&&!r&&!I)){if(w&&!gu.test(C))return y(t("decider.workersAi.needsAccount"));x(!0),y(null),j(null);try{(I||w&&!c)&&k(await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:C}})})),(w||S)&&k(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",w):await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:w}})})),u(""),d(null)}catch(A){y(A instanceof Error?A.message:String(A))}finally{x(!1)}}},v=async()=>{if(!(h||p||!w&&!r)){g(!0),j(null),y(null);try{const A=await D("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...w?{key:w,accountId:C}:{}})}),P=A.extraction?[t(A.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];j(A.ok?{ok:A.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(A.latencyMs)}),...P].join(" ")}:{ok:!1,text:s(A)})}catch(A){j({ok:!1,text:A instanceof Error?A.message:String(A)})}finally{g(!1)}}};return e.jsxs(Q,{title:t("decider.workersAi.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.workersAi.detail")}),r&&e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-success"}),e.jsx("span",{children:t("decider.status.connected")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:o??c,onChange:A=>{j(null),y(null),d(A.target.value)},disabled:p,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:wn}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:m,onChange:A=>{j(null),y(null),u(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void B(),disabled:p,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:wn}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{B()},disabled:p||!w&&!r&&!I,title:S?t("keys.removeKey"):t("common.save"),className:M("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",S?"text-danger":"text-ink"),children:p?e.jsx(J,{size:13,className:"animate-spin"}):S?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{v()},disabled:h||p||!w&&!r,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:h?t("keys.testing"):t("keys.test")})]})]}),b&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:b}),f&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("a",{href:hu,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.workersAi.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]})}const bu={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},yu=1500,Bs={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"},Sn={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},vu={...Bs,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"},ku={...Bs,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"},Vt={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter"};function ju(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(Vt[n.provider]??Vt.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(Vt[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function Cn(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=ku[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=vu[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&&Sn[s.reason])return t(Sn[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=Bs[s.reason];return i?t(i):t("decider.error.other")}const Nu=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function wu(){const{state:s,dispatch:n}=V(),a=s.config?.decider,i=a?.provider==="openrouter"?"openrouter":"jev",r=i==="openrouter",c=a?.configured??!1,o=c&&a?.included===!0,d=r&&c&&a?.keySource==="shared",m=r&&a?.sharedKey===!0,u=c&&!o&&!d,p=a?.enabled??!1,x=a?.jobs.roomRouting??!0,[h,g]=l.useState(""),[b,y]=l.useState(!1),[f,j]=l.useState(!1),[C,w]=l.useState(!1),[S,I]=l.useState(null),[k,B]=l.useState(null),[v,A]=l.useState(null),P=h.trim(),_=!P&&u,U=!r||o?null:d?"decider.openrouter.status.sharedHint":c?m?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",X=R=>n({type:"configStatus",config:R}),H=async R=>{if(!f){j(!0),I(null);try{X(await D("/api/config",{method:"PUT",body:JSON.stringify({decider:R})}))}catch(T){I(T instanceof Error?T.message:String(T))}finally{j(!1)}}};l.useEffect(()=>{if(!r||v)return;let R=!1;return D("/api/decider/models").then(T=>{R||A(T)},()=>{}),()=>{R=!0}},[r,v]);const N=R=>{g(""),B(null),H(R)},Z=async()=>{if(!(b||!P&&!u)){y(!0),I(null),B(null);try{const R=window.ogb?.setCredential?await window.ogb.setCredential(r?"openrouterDeciderKey":"jevApiKey",P):await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{[r?"openrouterKey":"key"]:P}})});X(R),g("")}catch(R){I(R instanceof Error?R.message:String(R))}finally{y(!1)}}},te=async()=>{if(C||b||!P&&!c)return;w(!0),B(null),I(null);const R=!P&&o,T=!P&&d;try{const Y=await D("/api/decider/test",{method:"POST",body:JSON.stringify(P?{key:P}:{})});B(Y.ok?{ok:!0,text:r?[t(T?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(Y.latencyMs)}),...Y.latencyMs>yu?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(Y.latencyMs)})}:{ok:!1,text:Cn(Y,R,i)})}catch(Y){B({ok:!1,text:Y instanceof Error?Y.message:String(Y)})}finally{w(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("p",{role:"status","data-testid":"helpers-status",className:"text-[13px] font-medium text-ink",children:ju(s.config)})]}),e.jsx(fu,{failureText:R=>Cn(R,!1,"workersai")}),e.jsx(ce,{title:t("decider.provider.label"),children:e.jsxs(me,{className:"w-48","data-testid":"decider-provider",value:i,onChange:R=>N({provider:R.target.value==="openrouter"?"openrouter":"jev"}),disabled:f||!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")})]})}),r&&e.jsx(ce,{title:t("decider.model.label"),subtitle:v?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(me,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:R=>N({openrouterModel:R.target.value,openrouterApi:v?.models.find(T=>T.id===R.target.value)?.api??"chat"}),disabled:f,"aria-label":t("decider.model.label"),children:[a?.model&&!v?.models.some(R=>R.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(R=>{const T=v?.models.filter(Y=>Y.group===R)??[];return T.length>0&&e.jsx("optgroup",{label:t(R==="recommended"?"decider.model.recommended":"decider.model.more"),children:T.map(Y=>e.jsx("option",{value:Y.id,children:Y.name},Y.id))},R)})]})}),e.jsx(ce,{title:t(r?"decider.openrouter.master":"decider.master"),subtitle:c?void 0:t(r?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(ue,{"data-testid":"decider-master","aria-label":t(r?"decider.openrouter.master":"decider.master"),checked:p,disabled:!c||f||!s.config,onClick:()=>{H({enabled:!p})},className:"cursor-pointer"})}),e.jsxs(Q,{title:t(r?"decider.openrouter.key.label":"decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:M("size-1.5 rounded-full",c?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:c?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):d?t("decider.openrouter.status.shared"):c?t(m?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected")})]}),U&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(U),!u&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(rs("openrouter")),className:"cursor-pointer text-accent hover:underline",children:t("decider.openrouter.key.manageLink")})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:h,onChange:R=>{B(null),I(null),g(R.target.value)},onKeyDown:R=>R.key==="Enter"&&void Z(),disabled:b,placeholder:u?t("keys.replace"):t(d?"decider.openrouter.key.overridePlaceholder":r?"decider.openrouter.key.placeholder":"decider.key.placeholder"),"aria-label":t(r?"decider.openrouter.key.label":"decider.key.label"),autoComplete:"off",spellCheck:!1,className:"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"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{Z()},disabled:b||!P&&!u,title:_?t("keys.removeKey"):t("common.save"),className:M("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",_?"text-danger":"text-ink"),children:b?e.jsx(J,{size:13,className:"animate-spin"}):_?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{te()},disabled:C||b||!P&&!c,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:C?t("keys.testing"):t("keys.test")})]}),S&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:S}),k&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",k.ok?"text-success":"text-danger"),children:k.text}),!d&&e.jsxs("a",{href:bu[i],target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t(r?"decider.openrouter.key.getKey":"decider.key.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]}),e.jsx(Q,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(ue,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:p&&x,disabled:!p||f,onClick:()=>{H({jobs:{roomRouting:!x}})},className:"cursor-pointer"})]}),Nu.map(R=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(R)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},R))]})})]})}const Su=["openai","xai","gemini","openrouter","custom"],Cu=4,wi={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},Eu={openai:[{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 Au(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 Ct={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},Iu={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"}},Pu={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},En={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},ms="w-full min-w-0 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",An="flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",qt="\0other";function Ru(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 Tu(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 Lu(){const{state:s,dispatch:n}=V(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??wi.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,m]=l.useState(null),[u,p]=l.useState(null),x=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!x||u)return;let y=!1;return D("/api/images/openrouter-models").then(f=>{y||p(Array.isArray(f?.models)?f:{source:"builtin",models:[]})},()=>{y||p({source:"builtin",models:[]})}),()=>{y=!0}},[x,u]);const h=async y=>{o(!0),m(null);try{const f=await D("/api/config",{method:"PUT",body:JSON.stringify(y)});n({type:"configStatus",config:f})}catch(f){m(f instanceof Error?f.message:String(f))}finally{o(!1)}},g=(y,f)=>{if(y==="fallback"&&f==="")return void h({imageGen:{fallback:null}});const j=f,C=y==="primary"&&r?.provider===j;h({imageGen:{[y]:{provider:j},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((y,f,j)=>j.indexOf(y)===f);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("imageGen.intro")}),e.jsxs("p",{role:"status","data-testid":"image-gen-status",className:"flex items-center gap-2 text-[13px] font-medium text-ink",children:[e.jsx("span",{className:M("size-1.5 shrink-0 rounded-full",a?.ready?i.configured?"bg-success":"bg-warning":"bg-raised-hover")}),a?.ready?i.configured?t("imageGen.status.ready",{provider:Ct[i.provider]}):t("imageGen.status.backupOnly",{provider:Ct[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(In,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:u,disabled:c||!s.config,onProvider:g,onModel:y=>{h({imageGen:{primary:{provider:i.provider,model:y}}})}}),e.jsx(In,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:u,disabled:c||!s.config,onProvider:g,onModel:y=>r&&void h({imageGen:{fallback:{provider:r.provider,model:y}}})}),e.jsx(ce,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(me,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??Cu),onChange:y=>{h({imageGen:{maxPerTurn:Number(y.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(y,f)=>f+1).map(y=>e.jsx("option",{value:y,children:y},y))})}),d&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:d}),b.map(y=>e.jsx(Ou,{provider:y,status:a},y))]})}function In({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:m}){const u=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(ce,{title:u,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(me,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:p=>d(s,p.target.value),disabled:o,"aria-label":u,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),Su.filter(p=>p!==r).map(p=>e.jsx("option",{value:p,children:Ct[p]},p))]})}),n&&e.jsx(Bu,{slot:s,slotLabel:u,provider:n,model:a,openrouterModels:c,disabled:o,onModel:m})]})}function Bu({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,m]=l.useState(null),p=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??Eu[a].map(b=>({...b,group:"recommended"})),x=d!==null||p.length===0,h=()=>{d!==null&&(m(null),d.trim()&&d.trim()!==i&&o(d.trim()))},g=b=>{if(b===qt)return m(i);m(null),o(b)};return e.jsx(ce,{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:[p.length>0&&e.jsxs(me,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:x?qt:i,onChange:b=>g(b.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[i&&!p.some(b=>b.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(b=>{const y=p.filter(f=>f.group===b);return y.length>0&&e.jsx("optgroup",{label:t(b==="recommended"?"decider.model.recommended":"decider.model.more"),children:y.map(f=>e.jsx("option",{value:f.id,children:f.name},f.id))},b)}),e.jsx("option",{value:qt,children:t("imageGen.model.other")})]}),x&&e.jsx("input",{value:d??i,onChange:b=>m(b.target.value),onBlur:h,onKeyDown:b=>b.key==="Enter"&&h(),disabled:c,placeholder:wi[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:M(ms,"w-64 max-w-full")})]})})}function Ou({provider:s,status:n}){const{dispatch:a}=V(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,m]=l.useState(!1),[u,p]=l.useState(null),[x,h]=l.useState(!1),[g,b]=l.useState(null),y=s==="openrouter"?[n?.primary,n?.fallback].filter(P=>P?.provider===s).map(P=>P?.model).join(" "):"",f=g?.models===y?g:null,j=P=>b(P&&{...P,models:y}),C=Tu(n,s),w=s==="openai"||s==="gemini"||s==="custom"?Iu[s]:null,S=s==="xai"||s==="openrouter"?Pu[s]:null,I=c??n?.customUrl??"",k=async P=>{m(!0),p(null),j(null);try{a({type:"configStatus",config:await P()}),r(""),o(null)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{m(!1)}},B=P=>k(async()=>s==="xai"||s==="openrouter"?yl(s,P,!1):window.ogb?.setCredential&&w?window.ogb.setCredential(w.credential,P):D("/api/config",{method:"PUT",body:JSON.stringify(w.patch(P))})),v=()=>k(async()=>{const P=I.trim()?Au(I.trim()):"";return D("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:P}})})}),A=async()=>{h(!0),j(null);try{j(Ru(s,await D("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(P){j({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{h(!1)}};return e.jsxs(Q,{title:Ct[s],children:[e.jsx(Mu,{configured:C,optional:s==="custom"}),S&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(S.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent hover:underline",children:t("imageGen.key.manage")})]}),s==="custom"&&e.jsxs("div",{className:"mb-2 flex gap-2",children:[e.jsx("input",{type:"url",value:I,onChange:P=>o(P.target.value),onKeyDown:P=>P.key==="Enter"&&void v(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:ms}),e.jsxs("button",{type:"button",onClick:()=>{v()},disabled:d||c===null,className:An,children:[d?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:P=>r(P.target.value),onKeyDown:P=>P.key==="Enter"&&i.trim()&&void B(i.trim()),disabled:d,placeholder:C?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((w??S).label),autoComplete:"off",spellCheck:!1,className:ms}),e.jsxs("button",{type:"button",onClick:()=>{B(i.trim())},disabled:d||!i.trim(),className:An,children:[d?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]}),C&&e.jsx("button",{type:"button",onClick:()=>{A()},disabled:x||d,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:x?t("keys.testing"):t("keys.test")})]}),f&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[En[s]?e.jsx("a",{href:En[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:ks()})}),C&&e.jsx("button",{type:"button",onClick:()=>{B("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u})]})}function Mu({configured:s,optional:n=!1}){return e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:M("size-1.5 rounded-full",s?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:s?"text-success":void 0,children:t(s?"imageGen.key.saved":n?"imageGen.key.optional":"imageGen.key.missing")})]})}function Jt(s){if(s.readOnly||s.trialCredit||s.access==="custom"||s.access==="api")return null;if(s.driverKind==="claudeAgent")return"claude";const n=s.authentication?.method;return s.snapshot.chatgptPlan===!0||(n==="device-code"||n==="browser-pkce")&&Ia(s.driverKind)==="codex"?"chatgpt":null}function Os(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const Ms={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function zu(s,n){return{signOut:Os(n)==="signedIn"&&n.authentication?.signOut===!0&&n.snapshot.account?.method!=="api-key",remove:s==="claude"?n.instanceId!=="claude"&&n.claudeAccount?.isDefault!==!0:n.instanceId.startsWith("chatgpt-")}}function Si(s){return s.some(Te)}function Uu(s,n){const a=n.filter(o=>Os(o)==="signedIn"),i=Si(n),r=n.some(o=>o.snapshot.state==="available"),c=n.length>1?t("accounts.count",{count:String(n.length),signedIn:String(a.length)}):a[0]?.snapshot.account?.email??wl(n[0]);return{title:t(Ms[s].title),subtitle:c,ready:i,status:i?t("onboarding.engines.ready"):r?t("model.signInRequired"):t("onboarding.engines.needsSetup"),action:i?t("engines.library.manage"):r?t("accounts.signIn"):t("engines.library.setup")}}function Du({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=V(),[o,d]=l.useState(!1),[m,u]=l.useState(null),[p,x]=l.useState(!1),[h,g]=l.useState(null),b=l.useRef(null),{signOut:y,remove:f}=zu(s,n),j=i.bots.filter(S=>S.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const S=k=>{k.key==="Escape"&&(k.stopPropagation(),d(!1))},I=k=>{k.target instanceof Node&&!b.current?.contains(k.target)&&d(!1)};return window.addEventListener("keydown",S,!0),window.addEventListener("pointerdown",I),()=>{window.removeEventListener("keydown",S,!0),window.removeEventListener("pointerdown",I)}},[o]);const C=async S=>{u(null),x(!0),g(null);try{const I=`/api/instances/${encodeURIComponent(n.instanceId)}${S==="signOut"?"/auth/sign-out":""}`,{instances:k}=await D(I,S==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(k)?r({type:"instances",instances:k}):await c().catch(()=>{})}catch(I){g(I instanceof Error?I.message:String(I))}finally{x(!1)}},w="ui-menu-row w-full text-left disabled:cursor-not-allowed disabled:opacity-50";return e.jsxs("div",{ref:b,className:"relative flex items-center gap-1",children:[f&&e.jsx("button",{type:"button",disabled:p||j>0,onClick:()=>u("remove"),title:j>0?t("accounts.inUse",{count:String(j)}):void 0,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:t("accounts.remove")}),e.jsx("button",{type:"button",onClick:()=>d(S=>!S),disabled:p,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:Fe(n)}),className:"flex size-8 items-center justify-center rounded-lg text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:p?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Oc,{size:16})}),o&&e.jsxs("div",{role:"menu",className:M("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]",Mc),children:[e.jsx("button",{type:"button",role:"menuitem",className:M(w,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),y&&e.jsx("button",{type:"button",role:"menuitem",className:M(w,"text-ink"),onClick:()=>{d(!1),u("signOut")},children:t("accounts.signOut")}),f&&j>0&&e.jsx("p",{className:"px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary",children:t("accounts.inUse",{count:String(j)})})]}),h&&e.jsx("p",{role:"alert",className:"absolute right-0 top-full z-30 mt-1 w-[260px] rounded-lg bg-card p-2 text-[12px] text-danger shadow-lg",children:h}),e.jsx(Qe,{open:m==="signOut",title:t("accounts.signOutTitle",{name:Fe(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>u(null),onConfirm:()=>{C("signOut")}}),e.jsx(Qe,{open:m==="remove",title:t("accounts.removeTitle",{name:Fe(n)}),body:t(Ms[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>u(null),onConfirm:()=>{C("remove")}})]})}function Fu({instance:s,onDone:n}){const{dispatch:a}=V(),[i,r]=l.useState(Fe(s)),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=async()=>{const p=i.trim();if(!p||p===Fe(s))return n();o(!0),m(null);try{const{instances:x}=await D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:p})});Array.isArray(x)&&a({type:"instances",instances:x}),n()}catch(x){m(x instanceof Error?x.message:String(x))}finally{o(!1)}};return e.jsxs("form",{className:"flex min-w-0 flex-1 flex-col gap-1",onSubmit:p=>{p.preventDefault(),u()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:p=>r(p.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:p=>{p.key==="Escape"&&(p.stopPropagation(),n())},className:"min-w-0 flex-1 rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:c?e.jsx(J,{size:13,className:"animate-spin"}):t("common.save")}),e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control",children:t("common.cancel")})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d})]})}function _u({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=Os(n),m=n.snapshot.account,u=n.snapshot.authenticationUnavailableReason,p=u&&d!=="signedIn"?u:d==="signedIn"?m?.method==="api-key"?t("accounts.apiKey"):[m?.email,m?.organization].filter(Boolean).join(" · ")||t("accounts.signedIn"):d==="signedOut"?t("accounts.notSignedIn"):d==="unknown"?t("accounts.unknown"):n.snapshot.reason??t("onboarding.engines.needsSetup");return e.jsxs("li",{"data-account":n.instanceId,"data-account-state":d,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:M("flex size-6 shrink-0 items-center justify-center rounded-full",d==="signedIn"?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:d==="signedIn"?e.jsx(ge,{size:13}):e.jsx("span",{className:M("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(Fu,{instance:n,onDone:()=>o(!1)}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:Fe(n),children:Fe(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:p,children:p})]}),d!=="signedIn"&&d!=="unavailable"&&!u&&!a&&e.jsx("button",{type:"button",onClick:i,className:M("shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-semibold",d==="signedOut"?"bg-accent text-white hover:brightness-110":"bg-control text-ink hover:bg-raised-hover"),children:t("accounts.signIn")}),e.jsx(Du,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(vl,{instanceId:n.instanceId,autoStart:!0,onDone:r}),n.claudeAccount?.signInCommand&&e.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("engineSetup.preferTerminal")}),e.jsx(kl,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(jl,{instanceId:n.instanceId,provider:"codex",browserPkce:n.authentication?.method==="browser-pkce",autoStart:!0,onDone:r})}),s==="chatgpt"&&d==="signedIn"&&n.snapshot.chatgptPlan&&e.jsx("div",{className:"pl-9",children:e.jsx(Nl,{instanceId:n.instanceId,welcome:!1})})]})}function Ci({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=V(),[d,m]=l.useState(!1),[u,p]=l.useState(""),[x,h]=l.useState(""),[g,b]=l.useState(!1),[y,f]=l.useState(null),j=async()=>{if(!(g||!u.trim())){b(!0),f(null);try{const C={displayName:u.trim(),...a,...i&&x.trim()?{configDir:x.trim()}:{}},w=await D(n,{method:"POST",body:JSON.stringify(C)});Array.isArray(w.instances)&&o({type:"instances",instances:w.instances}),m(!1),p(""),h(""),typeof w.instanceId=="string"&&c(w.instanceId)}catch(C){f(C instanceof Error?C.message:String(C))}finally{b(!1)}}};return d?e.jsxs("form",{"data-add-account":n,className:"space-y-2.5 rounded-xl border border-hairline/50 bg-app p-3",onSubmit:C=>{C.preventDefault(),j()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:u,onChange:C=>p(C.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:g,"aria-describedby":r,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] font-normal text-ink outline-none focus:border-accent-border disabled:opacity-50"})]}),i&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("accounts.folderToggle")}),e.jsx("input",{value:x,onChange:C=>h(C.target.value),placeholder:"~/.claude-work",maxLength:4096,spellCheck:!1,disabled:g,"aria-label":t("accounts.folderToggle"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("p",{className:"mt-1 leading-relaxed",children:t("accounts.folderHint")})]}),y&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:y}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),f(null)},disabled:g,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:g||!u.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[g&&e.jsx(J,{size:13,className:"animate-spin"}),t("accounts.addSubmit")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>m(!0),"aria-describedby":r,className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),s]})}function $u({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(p=>p.snapshot.state==="available"),m=n.find(p=>p.policy)?.policy,u=l.useId();return e.jsxs(Nt,{instance:o,summary:Uu(s,n),bare:i,children:[m&&e.jsxs("p",{className:"mb-3 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:m.organizationName})})," · ",m.reason]}),d?e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{"data-accounts":s,className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(p=>e.jsx(_u,{group:s,instance:p,signingIn:r===p.instanceId,onSignIn:()=>c(p.instanceId),onSignInDone:()=>c(x=>x===p.instanceId?null:x)},p.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(Ci,{label:t(Ms[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?u:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:u,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(Pt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(Pa,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(Ra,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const Ku={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},ft=M(Le,"font-sans"),Hu={name:"",url:"",token:"",model:""},Wu=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:""});function Pn({instance:s,engine:n,onDone:a}){const{dispatch:i}=V(),r=Ku[n],[c,o]=l.useState(s?Wu(s):Hu),[d,m]=l.useState(!1),[u,p]=l.useState(null),x=b=>({value:c[b],onChange:y=>o(f=>({...f,[b]:y.target.value})),spellCheck:!1,disabled:d}),h=!!(c.name.trim()&&(c.url.trim()||n==="codex")&&(s||c.token.trim())),g=async()=>{if(d||!h)return;m(!0),p(null);const b={displayName:c.name.trim(),baseUrl:c.url.trim()||r.url,...c.token.trim()?{token:c.token.trim()}:{},...c.model.trim()?{model:c.model.trim()}:{}};try{const y=s?await D(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await D(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(y.instances)&&i({type:"instances",instances:y.instances}),a()}catch(y){p(y instanceof Error&&y.message?y.message:t("claudeEndpoints.failed"))}finally{m(!1)}};return e.jsxs("form",{"data-claude-endpoint-form":n==="claude"?s?.instanceId??"new":void 0,"data-codex-endpoint-form":n==="codex"?s?.instanceId??"new":void 0,className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:b=>{b.preventDefault(),g()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(n==="codex"?"agentEndpoints.responses":"agentEndpoints.messages")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.name"),e.jsx("input",{...x("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeEndpoints.name"),className:ft})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.baseUrl"),e.jsx("input",{...x("url"),type:"url",maxLength:2048,placeholder:r.url,"aria-label":t("claudeEndpoints.baseUrl"),className:M(ft,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.token"),e.jsx("input",{...x("token"),type:"password",maxLength:4096,autoComplete:"off","aria-label":t("claudeEndpoints.token"),className:M(ft,"font-mono"),placeholder:s?t("claudeEndpoints.tokenKeep"):""})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.model"),e.jsx("input",{...x("model"),maxLength:160,placeholder:r.model,"aria-label":t("claudeEndpoints.model"),className:M(ft,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:a,disabled:d,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:d||!h,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[d&&e.jsx(J,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Gu({instance:s,onEdit:n}){const{state:a,dispatch:i}=V(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),p=a.bots.filter(g=>g.modelSelection.instanceId===s.instanceId||g.fallback?.some(b=>b.instanceId===s.instanceId)||g.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeEndpoint??s.codexEndpoint,h=async()=>{c(!1),d(!0),u(null);try{const g=await D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(g.instances)&&i({type:"instances",instances:g.instances})}catch(g){u(g instanceof Error?g.message:String(g))}finally{d(!1)}};return e.jsxs("li",{"data-claude-endpoint":s.claudeEndpoint?s.instanceId:void 0,"data-codex-endpoint":s.codexEndpoint?s.instanceId:void 0,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:x?.baseUrl,children:x?.baseUrl})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeEndpoints.edit")}),e.jsx("button",{type:"button",disabled:o||p>0,onClick:()=>c(!0),title:p>0?t("accounts.inUse",{count:String(p)}):t("accounts.remove"),"aria-label":t("claudeEndpoints.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeEndpoints.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function Ei({engine:s}){const{state:n}=V(),a=n.instances.filter(c=>s==="claude"?c.claudeEndpoint:c.codexEndpoint),[i,r]=l.useState(null);return e.jsxs("div",{"data-claude-endpoints":s==="claude"?"":void 0,"data-codex-endpoints":s==="codex"?"":void 0,className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t(s==="claude"?"claudeEndpoints.title":"agentEndpoints.codexTitle")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(s==="claude"?"claudeEndpoints.hint":"agentEndpoints.codexHint")}),a.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:a.map(c=>i===c.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Pn,{engine:s,instance:c,onDone:()=>r(null)})},c.instanceId):e.jsx(Gu,{instance:c,onEdit:()=>r(c.instanceId)},c.instanceId))}),i==="new"?e.jsx(Pn,{engine:s,onDone:()=>r(null)}):e.jsxs("button",{type:"button",onClick:()=>r("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeEndpoints.add")]})]})}function Yt(){return e.jsx(Ei,{engine:"claude"})}function Xt(){return e.jsx(Ei,{engine:"codex"})}const nt=M(Le,"font-sans"),Vu={opusModel:"global.anthropic.claude-opus-5-5",sonnetModel:"global.anthropic.claude-sonnet-5-5",haikuModel:"global.anthropic.claude-haiku-5-5",smallFastModel:"global.anthropic.claude-haiku-5-5"},Rn=["opusModel","sonnetModel","haikuModel","smallFastModel"],qu={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},Ju=s=>{const n=s.claudeBedrock;return{name:s.displayName,awsProfile:n?.awsProfile||"default",awsRegion:n?.awsRegion??"",model:n?.model??"",opusModel:n?.opusModel??"",sonnetModel:n?.sonnetModel??"",haikuModel:n?.haikuModel??"",smallFastModel:n?.smallFastModel??""}},Tn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function Ln({instance:s,onDone:n}){const{dispatch:a}=V(),[i,r]=l.useState(s?Ju(s):qu),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=h=>({value:i[h],onChange:g=>r(b=>({...b,[h]:g.target.value})),spellCheck:!1,disabled:c}),p=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),x=async()=>{if(c||!p)return;o(!0),m(null);const h={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(Rn.map(g=>[g,i[g].trim()]))};try{const g=s?await D(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(h)}):await D("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(h)});Array.isArray(g.instances)&&a({type:"instances",instances:g.instances}),n()}catch(g){m(g instanceof Error&&g.message?g.message:t("claudeBedrock.failed"))}finally{o(!1)}};return e.jsxs("form",{"data-claude-bedrock-form":s?.instanceId??"new",className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:h=>{h.preventDefault(),x()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.awsHint")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.name"),e.jsx("input",{...u("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:nt})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...u("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:M(nt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...u("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:M(nt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...u("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:M(nt,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.modelHint")}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary outline-none hover:text-ink",children:t("claudeBedrock.tiers")}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:Rn.map(h=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(Tn[h]),e.jsx("input",{...u(h),maxLength:160,placeholder:Vu[h],"aria-label":t(Tn[h]),className:M(nt,"font-mono")})]},h))})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!p,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[c&&e.jsx(J,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Yu({instance:s,onEdit:n}){const{state:a,dispatch:i}=V(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),p=a.bots.filter(g=>g.modelSelection.instanceId===s.instanceId||g.fallback?.some(b=>b.instanceId===s.instanceId)||g.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeBedrock,h=async()=>{c(!1),d(!0),u(null);try{const g=await D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(g.instances)&&i({type:"instances",instances:g.instances})}catch(g){u(g instanceof Error?g.message:String(g))}finally{d(!1)}};return e.jsxs("li",{"data-claude-bedrock":s.instanceId,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx(Ta,{preset:"aws",size:16,className:"shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:t("claudeBedrock.rowSubtitle",{profile:x?.awsProfile??"",region:x?.awsRegion??""})})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeBedrock.edit")}),e.jsx("button",{type:"button",disabled:o||p>0,onClick:()=>c(!0),title:p>0?t("accounts.inUse",{count:String(p)}):t("accounts.remove"),"aria-label":t("claudeBedrock.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeBedrock.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function Qt(){const{state:s}=V(),n=s.instances.filter(r=>r.claudeBedrock),[a,i]=l.useState(null);return e.jsxs("div",{"data-claude-bedrock-endpoints":"",className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("claudeBedrock.title")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.hint")}),n.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(r=>a===r.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Ln,{instance:r,onDone:()=>i(null)})},r.instanceId):e.jsx(Yu,{instance:r,onEdit:()=>i(r.instanceId)},r.instanceId))}),a==="new"?e.jsx(Ln,{onDone:()=>i(null)}):e.jsxs("button",{type:"button",onClick:()=>i("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeBedrock.add")]})]})}function Bn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Xu({instance:s,initial:n={kind:"idle"}}){const[a,i]=l.useState(n),[r,c]=l.useState(null),o=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,d=async()=>{c(null),i({kind:"scanning"});try{const p=await D(o);i(p.folders>0?{kind:"found",bytes:p.bytes,complete:p.complete}:{kind:"none"})}catch(p){c(p instanceof Error?p.message:String(p)),i({kind:"idle"})}},m=async()=>{c(null),i({kind:"deleting"});try{const p=await D(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:p.freedBytes,remaining:p.remaining})}catch(p){c(p instanceof Error?p.message:String(p)),i({kind:"idle"})}},u=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(zc,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||u)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:u,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[u&&e.jsx(J,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Bn(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Bn(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}const Zt=[60,120,180,360,720];function Ai(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(!1),[r,c]=l.useState(""),o=l.useRef(!1),d=s.config?.cacheKeepWarm;if(!d)return null;const m=async p=>{if(!o.current){o.current=!0,i(!0),c("");try{const x=await D("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:p.enabled,windowMinutes:p.windowMinutes}})});n({type:"configStatus",config:x})}catch(x){c(x instanceof Error?x.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},u=Zt.includes(d.windowMinutes)?[...Zt]:[...Zt,d.windowMinutes].sort((p,x)=>p-x);return e.jsxs(Q,{title:t("settings.keepWarm.title"),subtitle:t("settings.keepWarm.subtitle"),children:[e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.enable")}),e.jsx(ue,{id:"cache-keepwarm-enabled",checked:d.enabled,disabled:a,"aria-describedby":"cache-keepwarm-help cache-keepwarm-cost",onClick:()=>{m({...d,enabled:!d.enabled})}})]}),e.jsx("p",{id:"cache-keepwarm-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.help")}),e.jsx("p",{id:"cache-keepwarm-cost",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.cost")}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-window",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.window")}),e.jsx(me,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:p=>{m({...d,windowMinutes:Number(p.target.value)})},children:u.map(p=>e.jsx("option",{value:p,children:t("settings.keepWarm.hours",{hours:Number((p/60).toFixed(2))})},p))})]}),a&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}function Qu({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[m,u]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[p,x]=l.useState(!1),[h,g]=l.useState(null),[b,y]=l.useState(!1),[f,j]=l.useState(null),C=l.useRef(!1);l.useEffect(()=>{C.current||(C.current=!0,D(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:v})=>{c(v),s.cli&&(v.includes(s.cli)?d(s.cli):u(s.cli))}).catch(()=>c(v=>v??[])))},[n,s.cli]);const w=m.trim()||o,S=w!==(s.cli??""),I=p||b;l.useEffect(()=>{g(null)},[w]);const k=()=>{if(I||!w||!S)return;y(!0),j(null);const v=w;D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:v})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(A=>j(A.message)).finally(()=>y(!1))},B=()=>{I||!w||!S||(x(!0),j(null),D("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(v=>{g(v),v.ok&&k()}).catch(v=>j(v.message)).finally(()=>x(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[r!==null&&r.length>0&&e.jsxs(me,{className:"w-full font-mono",value:m.trim()?"":o,onChange:v=>{d(v.target.value),u("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(v=>e.jsx("option",{value:v,children:v},v))]}),e.jsx("input",{type:"text",value:m,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),!(!w||!S)&&B())},placeholder:r?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:I,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),h&&!h.ok&&h.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(Be,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:h.message})})]}),h?.ok&&h.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:h.version})}),f&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),h&&!h.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>g(null),disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>k(),disabled:I,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:b?e.jsx(J,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:B,disabled:I||!w||!S,className:M("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:I?e.jsx(J,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})})]})]})}function Ii({instance:s}){const{refreshInstances:n}=V(),[a,i]=l.useState(!1),r=td(a),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,p]=l.useState(null),[x,h]=l.useState(null),g=l.useRef(null);l.useEffect(()=>{g.current!==null&&g.current!==s.cli&&i(!1),g.current=s.cli??null},[s.cli]);const b=()=>{c||d||(o(!0),h(null),D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>h(j.message)).finally(()=>o(!1)))},y=()=>{c||d||(o(!0),h(null),D(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>h(j.message)).finally(()=>o(!1)))},f=()=>{c||d||(m(!0),p(null),h(null),D(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{p(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>h(j.message)).finally(()=>m(!1)))};return e.jsxs("details",{className:"mt-4 border-t border-hairline/40 pt-3",children:[e.jsx("summary",{className:"cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[12px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:f,disabled:c||d,className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[d?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),d?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:b,disabled:c||d,className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:c?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{type:"button","data-hide-engine":s.instanceId,onClick:y,disabled:c||d,title:t("engines.hideHint"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:t("engines.hide")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:d,"aria-expanded":a,className:M("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),u&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:u})}),x&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:x}),r.shown&&e.jsx("div",{className:r.className,...r.exitProps,children:e.jsx(Qu,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function On({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=V(),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,p]=l.useState(null),x=n==="remove",h=x?a.bots.filter(y=>y.modelSelection.instanceId===s.instanceId).length:0,g=t(x?"accounts.remove":"accounts.signOut"),b=async()=>{o(!1),m(!0),p(null);try{const y=`/api/instances/${encodeURIComponent(s.instanceId)}${x?"":"/auth/sign-out"}`,{instances:f}=await D(y,{method:x?"DELETE":"POST"});Array.isArray(f)?i({type:"instances",instances:f}):await r()}catch(y){p(y instanceof Error?y.message:String(y))}finally{m(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",disabled:d||h>0,onClick:()=>o(!0),className:M("rounded-lg px-2.5 py-1.5 text-[12px] font-medium disabled:cursor-not-allowed disabled:opacity-50",x?"text-danger hover:bg-danger/10":"text-ink-secondary hover:bg-raised hover:text-ink"),children:d?e.jsx(J,{size:13,className:"animate-spin"}):g}),h>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})})]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsx(Qe,{open:c,title:t(x?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(x?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:g,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{b()}})]})}function Zu({source:s}){const{state:n}=V(),[a,i]=l.useState(null),r=a?n.instances.find(c=>c.instanceId===a&&c.snapshot.authenticated!==!0):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(Ci,{label:t("engineSetup.antigravity.addAccount"),endpoint:"/api/instances/antigravity-accounts",extra:{sourceInstanceId:s.instanceId},onAdded:i}),r&&e.jsx("div",{"data-antigravity-added":r.instanceId,children:e.jsx(Pt,{instance:r,unframed:!0})})]})}function em({instance:s,bare:n=!1}){const a=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.trialCredit?e.jsx(Nt,{instance:s,bare:n,children:e.jsx("p",{"data-trial-credit":s.trialCredit,className:"text-[13px] leading-relaxed text-ink-secondary",children:t(s.trialCredit==="used_up"?"engines.trialCreditUsedUp":s.trialCredit==="ended"?"engines.trialCreditEnded":Te(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(Nt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!Te(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(Nt,{instance:s,bare:n,children:[a,!Te(s)&&e.jsx(Pt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),Te(s)&&e.jsx(Al,{instance:s,className:"mt-3"}),Te(s)&&s.serverKind==="ollama"&&e.jsx(Il,{instance:s,className:"mt-3"}),Te(s)&&e.jsx(Pl,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(Pa,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(Ra,{warning:s.snapshot.warning,className:"mt-3"}),Te(s)&&s.snapshot.authenticated===!0&&(s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t(Rl[Ia(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Xu,{instance:s}),s.driverKind==="antigravityAgent"&&e.jsxs("div",{className:"mt-3 space-y-3",children:[s.snapshot.authenticated&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:s.snapshot.account?.email??t("engineSetup.antigravity.emailUnavailable")}),e.jsx(Zu,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(On,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(On,{instance:s,action:"remove"})]}),e.jsx(Ii,{instance:s})]})}function tm(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?El(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function sm({rows:s,isReady:n,renderEngine:a,more:i}){const[r,c]=l.useState(null),o=s.filter(m=>n(m)||m.authentication!==void 0),d=s.filter(m=>!o.includes(m));return e.jsxs(e.Fragment,{children:[e.jsx(ye,{label:t("settings.simple.ai.yours"),actions:e.jsx(La,{}),children:e.jsx(ve,{children:o.map(m=>{const u=n(m),p=r===m.instanceId;return e.jsxs("div",{"data-simple-engine":m.instanceId,className:"group",children:[e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"flex min-w-[min(100%,15rem)] flex-1 items-center gap-3",children:[e.jsx(on,{instance:m,size:14,subtle:!0}),e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"truncate text-[14px] leading-5 text-ink",children:m.displayName}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:tm(m,u)})]})]}),e.jsx("button",{type:"button","aria-expanded":p,className:"ui-button ml-auto shrink-0",onClick:()=>c(p?null:m.instanceId),children:t(p?"common.done":u?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),p&&e.jsx("div",{className:"px-4 pb-3",children:a(m,!0)})]},m.instanceId)})})}),d.length>0&&e.jsx(Rt,{title:t("settings.simple.ai.more",{count:String(d.length)}),trailing:e.jsx("span",{"aria-hidden":"true",className:"flex items-center -space-x-1",children:d.slice(0,4).map(m=>e.jsx("span",{className:"flex size-[18px] items-center justify-center rounded-full bg-menu",children:e.jsx(on,{instance:m,size:14,subtle:!0})},m.instanceId))}),...i,children:e.jsx(Ba,{instances:d,isReady:n,renderEngine:m=>a(m)})})]})}function nm(){const{state:s,refreshInstances:n}=V(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return D("/api/instances/hidden").then(p=>{u&&i(Array.isArray(p?.instances)?p.instances:[])}).catch(()=>{}),()=>{u=!1}},[s.instances]),a.length===0)return null;const m=u=>{c(u),d(null),D(`/api/instances/${encodeURIComponent(u)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(p=>d(p.message)).finally(()=>c(null))};return e.jsxs("details",{"data-hidden-engines":!0,className:"px-4",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink",children:t("engines.hiddenTitle",{count:String(a.length)})}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.hiddenHint")}),e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:a.map(u=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",children:u.displayName}),e.jsx("button",{type:"button","data-unhide-engine":u.instanceId,disabled:r!==null,onClick:()=>m(u.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===u.instanceId?t("engines.unhiding"):t("engines.unhide")})]},u.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function Pi({simple:s=!1,more:n}){const{state:a}=V();l.useEffect(()=>Sl,[]);const i=a.instances.filter(h=>h.readOnly||h.cli!==void 0||h.cliDefault!==void 0||h.snapshot.state==="unavailable"||Cl(h)||h.claudeEndpoint!==void 0||h.claudeBedrock!==void 0||h.codexEndpoint!==void 0),r=new Map;for(const h of i){const g=Jt(h);g&&r.set(g,[...r.get(g)??[],h])}const c=h=>{const g=Jt(h);return g&&r.get(g)?.[0]===h?g:null},o=i.filter(h=>!Jt(h)||c(h)),d=o.length>0&&o.every(h=>h.readOnly),m=!r.has("chatgpt")&&!d,u=!r.has("claude")&&!d,p=h=>{const g=c(h);return g?Si(r.get(g)):Te(h)},x=(h,g=!1)=>{const b=c(h);return b?e.jsx($u,{group:b,accounts:r.get(b),bare:g,advanced:e.jsxs(e.Fragment,{children:[b==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsx(Qt,{})]}):e.jsx(Xt,{}),e.jsx(Ii,{instance:h})]})}):e.jsx(em,{instance:h,bare:g})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(sm,{rows:o,isReady:p,renderEngine:x,more:n}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Yt,{}),e.jsx(Qt,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(Xt,{})})]}):e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60 space-y-2 px-4",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(La,{})]}),e.jsx(Ba,{instances:o,isReady:p,renderEngine:x}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Yt,{}),e.jsx(Qt,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(Xt,{})}),e.jsx(nm,{}),e.jsx(Ai,{})]})}const am={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function bt(s,n){return[am[s],{signal:n}]}function zs(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function im({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:m}){return e.jsxs(Q,{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(Oa,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(i&&"animate-spin")})," ",t("vm.refresh")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):o?t("vm.vps.unavailable",{reason:o}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!o)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[o&&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(Be,{size:14,className:"shrink-0 text-warning"})," ",o]}),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(J,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):o&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{size:14,className:"shrink-0 text-warning"})," ",o]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Uc,{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((u,p)=>{const x=hm(u),h=Us(x),g=r===u.name,b=Ds(u.name);return e.jsxs("div",{className:M("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.orphaned?t("vm.vps.orphan",{id:b}):u.ownerName}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",u.inUse||x==="running"?"bg-success/15 text-success":x==="stopped"||x==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:u.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:i||u.inUse||r!==null,"aria-busy":g||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:[g?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("vm.vps.remove")]})]},`${u.vpsAlias??""}:${u.name}`)})]})]})}const rm=[1e3,2e3,4e3];function lm(s){return new Promise(n=>window.setTimeout(n,s))}const om={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},cm={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 Us(s){return t(cm[s])}function dm(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function um(s){return Us(dm(s))}function mm(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 Ri(s,n,a){const i={...a},r=new Set(s.map(o=>o.boxId)),c=s.flatMap(o=>{const d=a[o.boxId];return d==="deleted"?[]:d==="deleting"?[{...o,state:"removing"}]:d!=="sleeping"?[o]:o.state==="archived"?(delete i[o.boxId],[o]):[{...o,state:"archived"}]});for(const o of n)a[o.boxId]!=="sleeping"||r.has(o.boxId)||c.push({...o,state:"archived"});for(const[o,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(o)&&delete i[o];return{instances:c,overrides:i}}function pm(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ri(Array.isArray(s.instances)?s.instances:[],n,a)}function xm(s){return["idle","ready","running"].includes(s.state)}function hm(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 Ds(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function gm(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:zs(`/api/bots/${s.botId}/local-computer/remove`,{})}}function fm(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:zs(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function bm(s){const n=Ds(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:zs(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function es(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function ym({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:m}){return e.jsxs(Q,{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(Oa,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] 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.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{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(js,{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((u,p)=>{const x=mm(u),h=Us(x),g=i?.boxId===u.boxId,b=xm(u),y=x==="removing";return e.jsxs("div",{className:M("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.orphaned?t("vm.cloud.orphan"):t("vm.cloud.ofBot",{name:u.ownerName??""})}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",u.inUse||x==="running"?"bg-success/15 text-success":x==="sleeping"||x==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h})]}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.cloud.machineId",{id:u.name})}),u.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(u),disabled:a||u.inUse||i!==null||!b,"aria-busy":g&&i?.action==="sleep"?!0:void 0,title:b?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:h.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:[g&&i?.action==="sleep"?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Dc,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:a||u.inUse||i!==null||y,"aria-busy":g&&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:[g&&i?.action==="delete"?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]})]},u.boxId)})})]})}function vm({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d,runningInstances:m,powerPending:u,onPower:p}){return e.jsxs(Q,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):m===void 0?t("vm.perBot.created",{count:s.length,max:n}):z(`Đã tạo ${s.length} máy · Đang chạy ${m}/${n}`,`${s.length} desktops created · ${m}/${n} running`)}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m===void 0?t("vm.perBot.deleteHint"):z("Ứng dụng không giới hạn số máy đã tạo; số lượng thực tế phụ thuộc dung lượng ổ đĩa. Dừng một máy để giải phóng tài nguyên cho máy khác.","The app does not cap created desktops; their number depends on disk space. Stop a desktop to free resources for another.")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null||!!u,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] 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||!!u,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{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((x,h)=>{const g=um(x),b=i===x.botId,y=x.managed===!0;return e.jsxs("div",{className:M("flex items-start justify-between gap-3 px-3 py-3",h>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:x.name}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",y?x.inUse||x.ready?"bg-success/15 text-success":x.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:g})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(om[x.destination])})}),!y&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),y&&x.problem&&!x.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:si(x.problem)}),y&&x.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),y&&e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[p&&e.jsxs("button",{type:"button",onClick:()=>p(x,x.container==="running"?"stop":"start"),disabled:a||x.inUse||i!==null||!!u||x.container==="stopped"&&m!==void 0&&m>=n,"aria-busy":u?.botId===x.botId||void 0,className:"flex items-center gap-1.5 rounded-lg bg-control px-2.5 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-40",children:[u?.botId===x.botId&&e.jsx(J,{size:12,className:"animate-spin"}),x.container==="running"?z("Dừng","Stop"):z("Bật","Start")]}),e.jsxs("button",{type:"button",onClick:()=>d(x),disabled:a||x.inUse||i!==null||!!u,"aria-busy":b||void 0,title:x.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:x.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:[b?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]})]},x.botId)})})]})}function yt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:M("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(ge,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:M("text-[14px]",a?"text-ink-secondary line-through":"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 Ve({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:M("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] font-medium disabled:opacity-50",r?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(J,{size:13,className:"animate-spin"}),a]})}const Ti=5,Li=1440,km=480;function jm(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Ti&&a<=Li?a:null}function Nm({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,p]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const x=async()=>{if(!c||u)return;const h=jm(i);if(h===null){m(t("vm.idle.range"));return}p(!0);try{await a(h),r(String(h)),o(!1),m("")}catch(g){m(g instanceof Error?g.message:t("vm.idle.error"))}finally{p(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[12px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:M("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",d?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Ti,max:Li,step:1,inputMode:"numeric",value:i,disabled:n||u,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:h=>{r(h.target.value),o(!0),m("")},onBlur:()=>{x()},onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[13px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:d}):null]})}function Bi(){const s=V().state.config?.cloudHome===!0,[n,a]=l.useState(null),[i,r]=l.useState(!0),[c,o]=l.useState(null),d=l.useRef(null);l.useEffect(()=>()=>d.current?.abort(),[]);const[m,u]=l.useState(null),[p,x]=l.useState(!1),[h,g]=l.useState(0),[b,y]=l.useState([]),[f,j]=l.useState(2),[C,w]=l.useState(!1),[S,I]=l.useState(null),[k,B]=l.useState(null),[v,A]=l.useState(null),[P,_]=l.useState(null),[U,X]=l.useState(0),[H,N]=l.useState([]),[Z,te]=l.useState(null),[R,T]=l.useState(!0),[Y,re]=l.useState(null),[pe,xe]=l.useState(null),[le,$]=l.useState(null),[ne,fe]=l.useState(0),oe=l.useRef([]),se=l.useRef({}),[ie,be]=l.useState([]),[K,ae]=l.useState(null),[L,E]=l.useState([]),[W,de]=l.useState(!0),[q,je]=l.useState(null),[Ie,Ze]=l.useState(null),[et,Me]=l.useState(null),[Sr,Cr]=l.useState(0),[Er,ze]=l.useState(""),$e=l.useCallback(async O=>{const F=await fetch(...bt("status",O)),ee=await F.json().catch(()=>({}));if(!O?.aborted){if(!F.ok)throw new Error(ee.error??t("vm.err.status",{code:F.status}));return a(ee),u(null),ee}},[]),xt=l.useCallback(async O=>{const F=await fetch(...bt("local-vms",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.inventory",{code:F.status}));const G=ee;y(G.instances),j(G.maxInstances),B(G.available?null:si(G.problem)??t("vm.err.runtimeUnavailable")),I(null)},[]),tt=l.useCallback(async O=>{const F=await fetch(...bt("cloud",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.cloudInventory",{code:F.status}));const G=ee,he=pm(G,oe.current,se.current);se.current=he.overrides,oe.current=he.instances,N(he.instances),te(G.configured===!0),xe(G.available||!G.configured?null:G.problem??t("vm.err.cloudUnavailable")),re(null)},[]),Mt=l.useCallback(async O=>{const F=await fetch(...bt("vps",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.vpsInventory",{code:F.status}));const G=ee;be(Array.isArray(G.instances)?G.instances:[]),ae(G.configured===!0),E(Array.isArray(G.vpsAliases)?G.vpsAliases:[]),Ze(G.available||!G.configured?null:G.problem??t("vm.err.vpsUnavailable")),je(null)},[]);l.useEffect(()=>{if(s)return;let O=!0,F,ee;const G=async()=>{ee=new AbortController;try{await $e(ee.signal)}catch(he){O&&!(he instanceof DOMException&&he.name==="AbortError")&&(a(null),u(he instanceof Error?he.message:String(he)))}finally{O&&(r(!1),F=window.setTimeout(()=>{G()},5e3))}};return G(),()=>{O=!1,ee?.abort(),F!==void 0&&window.clearTimeout(F)}},[s,$e,h]),l.useEffect(()=>{if(n?.mode!=="per-bot"){y([]),w(!1),I(null),B(null);return}const O=new AbortController;return w(!0),xt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||I(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||w(!1)}),()=>O.abort()},[U,xt,n?.mode]),l.useEffect(()=>{const O=new AbortController;return T(!0),tt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||xe(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||T(!1)}),()=>O.abort()},[ne,tt]),l.useEffect(()=>{const O=new AbortController;return de(!0),Mt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||Ze(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||de(!1)}),()=>O.abort()},[Mt,Sr]);const zt=async(O,F)=>{const ee=await fetch(`/api/local-computer/${O}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:F}),G=await ee.json().catch(()=>({})),he={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!ee.ok)throw new Error(G.error??t(he[O]));return F.throwIfAborted(),a(G),G},Ws=O=>window.ogb?.confirm?window.ogb.confirm(O):window.confirm(O),Ke=async O=>{if(c!==null||d.current)return;const F=new AbortController;d.current=F,o(O),u(null);try{if(O==="remove"&&!await Ws(t("vm.confirm.deleteShared"))||O==="recreate"&&!await Ws(t("vm.confirm.recreate")))return;let ee;if(O==="recreate"?(await zt("remove",F.signal),ee=await zt("run",F.signal)):ee=await zt(O,F.signal),(O==="run"||O==="start"||O==="recreate")&&(ee=await jn(ee,async()=>await $e(F.signal)??ee,F.signal),!ee.ready&&!ee.capacity_limited))throw new Error(ee.problem??t("vm.err.start"));await $e(),ze(O==="remove"?t("vm.announce.deleted"):O==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(ee){if(F.signal.aborted)return;u(ee instanceof Error?ee.message:String(ee))}finally{d.current=null,F.signal.aborted||o(null)}},Ar=async(O,F)=>{if(P||v)return;_({botId:O.botId,action:F}),I(null);const ee=new AbortController;try{const G=`/api/bots/${encodeURIComponent(O.botId)}/local-computer`,he=await fetch(`${G}/${F}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}"});let Re=await he.json();if(!he.ok)throw new Error(Re.error??t("vm.err.start"));if(F==="start"&&(Re=await jn(Re,async()=>{const He=await fetch(G);if(!He.ok)throw new Error(t("vm.err.start"));return He.json()},ee.signal)),F==="start"&&!Re.ready)throw new Error(Re.problem??t("vm.err.start"));await Promise.all([xt(),$e()])}catch(G){I(G instanceof Error?G.message:String(G))}finally{_(null)}},Gs=async O=>{x(!0),u(null);try{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:O,automaticCapacity:!0}})}),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.policyError"));a(G=>G&&{...G,mode:O}),await $e()}catch(F){u(F instanceof Error?F.message:String(F))}finally{x(!1)}},Ir=async O=>{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:O}})}),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.idle.error"));a(G=>G&&{...G,idle_timeout_ms:O*6e4})},Pr=async O=>{if(!O.managed){I(t("vm.unmanagedError"));return}const F=es(gm(O),ee=>window.confirm(ee));if(F){A(O.botId),I(null);try{const ee=await fetch(...F),G=await ee.json().catch(()=>({}));if(!ee.ok)throw new Error(G.error??t("vm.deleteError"));await xt(),ze(t("vm.announce.deletedBot",{name:O.name}))}catch(ee){I(ee instanceof Error?ee.message:String(ee))}finally{A(null)}}},Vs=async(O,F)=>{const ee=es(fm(O,F),G=>window.confirm(G));if(ee){$({boxId:F.boxId,action:O}),re(null),ze("");try{const G=await fetch(...ee),he=await G.json().catch(()=>({}));if(!G.ok)throw new Error(he.error??t(O==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const Re=O==="delete"&&he?.pending===!0;se.current={...se.current,[F.boxId]:O==="delete"?Re?"deleting":"deleted":"sleeping"};const He=Ri(oe.current,oe.current,se.current);se.current=He.overrides,oe.current=He.instances,N(He.instances);const We=F.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:F.ownerName??""});if(ze(Re?`${We}: ${t("vm.state.removing")}.`:t(O==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:We})),Re){for(const Ee of rm){await lm(Ee);try{await tt()}catch{}if(se.current[F.boxId]!=="deleting"){ze(t("vm.announce.cloudDeleted",{subject:We}));return}}const Ge={...se.current};delete Ge[F.boxId],se.current=Ge;const gt=oe.current.map(Ee=>Ee.boxId===F.boxId?{...Ee,state:F.state}:Ee);oe.current=gt,N(gt);try{await tt(),oe.current.some(Ee=>Ee.boxId===F.boxId)||ze(t("vm.announce.cloudDeleted",{subject:We}))}catch(Ee){const Tr=Ee instanceof Error?Ee.message:String(Ee);re(`${We}: ${t("vm.state.removing")}. ${Tr}`)}return}try{await tt()}catch(Ge){const gt=Ge instanceof Error?Ge.message:String(Ge);re(t(O==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:We,detail:gt}))}}catch(G){re(G instanceof Error?G.message:String(G))}finally{$(null)}}},Rr=async O=>{const F=Ds(O.name),ee=es(bm(O),G=>window.confirm(G));if(ee){Me(O.name),je(null);try{const G=await fetch(...ee),he=await G.json().catch(()=>({}));if(!G.ok)throw new Error(he.error??t("vm.vpsRemoveError"));await Mt(),ze(t("vm.announce.vpsRemoved",{subject:O.orphaned?t("vm.announce.orphanVps",{id:F}):t("vm.confirm.ownedVps",{name:O.ownerName??""})}))}catch(G){je(G instanceof Error?G.message:String(G))}finally{Me(null)}}},Pe=n?.commands,ht=n?.ready===!0,qs=n?.container!=="missing",Js=!!(qs&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ys=!i&&!n,Xs=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ne=n?.mode==="per-bot",Ut=Ne&&n?.runtime==="container",Dt=Ne?!!(n?.daemonUp&&n?.image&&!Ut):ht;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Er}),e.jsx(ym,{instances:H,configured:Z,loading:R,pending:le,error:Y,unavailableReason:pe,onRefresh:()=>fe(O=>O+1),onSleep:O=>{Vs("sleep",O)},onDelete:O=>{Vs("delete",O)}}),e.jsx(im,{instances:ie,configured:K,aliases:L,loading:W,removingName:et,error:q,unavailableReason:Ie,onRefresh:()=>Cr(O=>O+1),onRemove:O=>{Rr(O)}}),e.jsx(sd,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(Q,{title:t("vm.main.title"),subtitle:Ne?t("vm.main.perBotSubtitle",{host:Xs}):t("vm.main.sharedSubtitle",{host:Xs}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:M("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px]",Dt?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(J,{size:12,className:"animate-spin"}):Dt?e.jsx(ge,{size:12}):e.jsx(Tl,{size:9}),i?t("common.checking"):Ys?t("vm.main.statusUnavailable"):Ne&&Dt?t("vm.main.readyPerBot"):Ut?t("vm.main.perBotUnsupported"):ht?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),g(O=>O+1),X(O=>O+1)},disabled:i||c!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(we,{size:12})," ",t("vm.main.recheck")]}),ht&&!Ne&&e.jsxs("a",{href:n?.viewer_url??Pe?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink hover:bg-control",children:[e.jsx(pt,{size:12})," ",t("vm.main.watch")]})]}),m&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:m})]}),e.jsxs(Q,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((O,F)=>e.jsx("button",{type:"button",disabled:!n||p,onClick:()=>{Gs(O)},className:M("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",F>0&&"border-l border-hairline/40",n?.mode===O?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:O==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},O))}),Ne&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:z("Số máy ảo chạy cùng lúc tối đa","Maximum desktops running at once")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:z("Không giới hạn số máy đã tạo trong ứng dụng. Giới hạn chạy cùng lúc tự tính theo RAM/CPU cấp cho Docker hoặc Podman, có dự phòng cho hệ thống. Khi đủ chỗ đang chạy, máy mới vẫn được tạo ở trạng thái dừng.","The app does not cap created desktops. The running limit is calculated from Docker or Podman memory/CPU with a system reserve. When running slots are full, new desktops are still created in a stopped state.")}),n?.capacity&&e.jsxs("div",{className:"mt-1 text-[12px] text-ink-secondary",children:[n.capacity.source==="host"?z("Ước tính từ máy chủ; chưa đọc được tài nguyên Docker/Podman","Host estimate; Docker/Podman resources have not been read"):n.capacity.source==="docker"?"Docker":"Podman",` · ${n.capacity.memoryGb.toFixed(1)} GB RAM · ${n.capacity.cpus} CPU`,` · ${z("Mỗi máy","Each desktop")}: ${n.capacity.perVmMemoryGb} GB / ${n.capacity.perVmCpus} CPU`,` · ${z("Dành cho hệ thống","System reserve")}: ${n.capacity.reservedMemoryGb.toFixed(1)} GB / ${n.capacity.reservedCpus} CPU`]}),n?.automatic_capacity===!1&&e.jsx("button",{type:"button",disabled:p,onClick:()=>{Gs(n.mode)},className:"mt-1 text-[12px] text-accent hover:underline",children:z("Chuyển sang tự động","Switch to automatic")}),n&&(n.running_instances??0)>n.max_instances&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:z("Số máy đang chạy vượt mức ước tính mới. Ứng dụng giữ nguyên chúng; dừng bớt máy trước khi bật máy khác.","The running desktops exceed the new estimate. They are kept; stop some before starting another.")})]}),e.jsxs("div",{className:"shrink-0 rounded-lg bg-control px-3 py-2 text-center text-[13px] text-ink",children:[e.jsx("div",{className:"text-[11px] text-ink-secondary",children:n?.automatic_capacity===!1?z("Thủ công","Manual"):z("Tự động","Automatic")}),e.jsx("div",{className:"font-semibold tabular-nums",children:n?.max_instances??"…"})]})]}),e.jsx(Nm,{minutes:n?Math.round(n.idle_timeout_ms/6e4):km,disabled:!n||p,onSave:Ir}),p&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(J,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(Q,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(yt,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Pe?.install?e.jsx(it,{command:Pe.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(yt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Pe?.runtimeStart?e.jsx(it,{command:Pe.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(yt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ve,{action:"pull",pending:c,onClick:()=>{Ke("pull")},children:t("vm.setup.prepare")}),Pe?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(it,{command:Pe.pull})})]})]}),e.jsxs(yt,{n:4,title:Ne?t("vm.setup.step4PerBot"):Js?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:Ne?b.some(O=>O.managed):ht,children:[Ne?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Ut?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):Js?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Be,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ve,{action:"recreate",pending:c,onClick:()=>{Ke("recreate")},danger:!0,children:[e.jsx(Ll,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ve,{action:"start",pending:c,onClick:()=>{Ke("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{action:"run",pending:c,onClick:()=>{Ke("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Pe?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(it,{command:Pe.run})})]})]})]})}),Ne&&e.jsx(vm,{instances:b,maxInstances:n?.max_instances??f,runningInstances:n?.running_instances,powerPending:P,onPower:(O,F)=>{Ar(O,F)},loading:C,deletingBotId:v,error:S,unavailableReason:k,onRefresh:()=>X(O=>O+1),onDelete:O=>{Pr(O)}}),Ys&&e.jsx(Q,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Be,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(Q,{title:t("vm.safety.title"),subtitle:Ne?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[qs&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ve,{action:"stop",pending:c,onClick:()=>{Ke("stop")},children:[e.jsx(Bl,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ve,{action:"remove",pending:c,onClick:()=>{Ke("remove")},danger:!0,children:[e.jsx(Se,{size:12})," ",Ne?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.37.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function Oi(s){return t("pairing.worksOnceUntil",{time:Lr(s)})}function ps(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const wm="/api/team/phone-pairing",Mn="/api/team/phones",Sm=4e3;function Cm(s){return`${s.label} · ${s.email}`}function Em({team:s,blocked:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(!1),[p,x]=l.useState(null),[h,g]=l.useState(()=>Date.now()),b=w=>x(t("remote.serverPairing.error",{error:w instanceof Error?w.message:String(w)}));async function y(){try{const w=await D(Mn);c(Array.isArray(w?.phones)?w.phones:[]),d(typeof w?.current=="string"?w.current:null)}catch(w){b(w)}}l.useEffect(()=>{y()},[]);const f=a?a.expiresAt<=h:!1;l.useEffect(()=>{if(!a)return;const w=setInterval(()=>g(Date.now()),15e3);return()=>clearInterval(w)},[a]),l.useEffect(()=>{if(!a||f)return;const w=setInterval(()=>{y()},Sm);return()=>clearInterval(w)},[a,f]);async function j(){u(!0),x(null);try{i(await D(wm,{method:"POST",body:"{}"})),g(Date.now())}catch(w){b(w)}finally{u(!1)}}async function C(w){x(null);try{await D(`${Mn}/${encodeURIComponent(w)}`,{method:"DELETE"})}catch(S){b(S)}await y()}return e.jsxs(Q,{title:t("teamPhone.title"),subtitle:t("teamPhone.subtitle",{team:s}),children:[e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{j()},disabled:m||!!n,title:n??void 0,className:"ui-button ui-button-primary",children:m?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})}),n?e.jsx("p",{role:"status","data-team-phone-blocked":!0,className:"mt-3 text-[13px] text-ink-secondary",children:n}):null,a?e.jsx("div",{"data-team-phone-code":!0,className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:f?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[a.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Ma,{value:a.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:a.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:Oi(a.expiresAt)}),a.url?null:e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:a.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:t("teamPhone.stays",{team:s})}),r?e.jsxs("div",{"data-team-phones":!0,children:[e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t("remote.serverPairing.devices")}),r.length===0?e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:r.map(w=>e.jsxs("li",{"data-team-phone":w.id,className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[Cm(w),e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("remote.serverPairing.seen",{when:ps(w.lastSeenAt,h)}),w.id===o?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),w.id===o?null:e.jsx("button",{type:"button","data-team-phone-remove":!0,onClick:()=>{C(w.id)},className:"ui-button",children:t("teamPhone.remove")})]},w.id))})]}):null,p?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:p}):null]})}function Am({saved:s,onSaved:n,className:a}){const[i,r]=l.useState(s),[c,o]=l.useState(!1),[d,m]=l.useState(null);l.useEffect(()=>r(s),[s]);async function u(){const p=i.trim();if(!(c||p===s)){o(!0),m(null);try{const x=await D("/api/config",{method:"PATCH",body:JSON.stringify({computerName:p})});n(x.computerName??p)}catch(x){m(t("remote.computerName.error",{error:x instanceof Error?x.message:String(x)}))}finally{o(!1)}}}return e.jsxs("div",{"data-computer-name":!0,className:M("flex flex-col gap-1",a),children:[e.jsx("label",{htmlFor:"computer-name",className:"text-[13px] font-medium text-ink",children:t("remote.computerName.title")}),e.jsx("input",{id:"computer-name",value:i,disabled:c,placeholder:t("remote.computerName.placeholder"),"aria-describedby":"computer-name-help",onChange:p=>r(p.target.value),onBlur:()=>{u()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"w-full max-w-xs rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("p",{id:"computer-name-help",className:"text-[12px] leading-4 text-ink-secondary",children:t("remote.computerName.help")}),d?e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d}):null]})}function lt(s){return id(s)}function Im(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function Pm(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}const Rm="ui-button ui-button-primary",zn="ui-button";function Tm({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0,team:r,teamPhoneBlocked:c=null,simple:o=!1,reveal:d=!0}){const[m,u]=l.useState(s),[p,x]=l.useState(n),[h,g]=l.useState(null),[b,y]=l.useState("admin"),[f,j]=l.useState(null),[C,w]=l.useState([]),[S,I]=l.useState(null),[k,B]=l.useState(!1),[v,A]=l.useState("idle"),[P,_]=l.useState(null),[U,X]=l.useState(()=>Date.now()),H=l.useRef(null),N=l.useRef(0);async function Z(){try{const $=await D("/api/auth/sessions");w(Array.isArray($?.sessions)?$.sessions:[]),I(typeof $?.current=="string"?$.current:null)}catch($){_(t("remote.serverPairing.error",{error:$ instanceof Error?$.message:String($)}))}}if(l.useEffect(()=>{ni().then($=>{u($),lt($)&&Z(),($.kind==="loopback"||$.kind==="session")&&D("/api/config").then(ne=>{x(ai(ne).pairingCodes),lt($)&&g(typeof ne?.computerName=="string"?ne.computerName:"")}).catch(()=>{})})},[]),l.useEffect(()=>{i?N.current!==i&&ad(H.current)&&(N.current=i):N.current=0},[i,m]),l.useEffect(()=>{if(!f)return;const $=setInterval(()=>X(Date.now()),15e3);return()=>clearInterval($)},[f]),r&&m?.kind==="session"&&m.team)return e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(Em,{team:r,blocked:c})});if(!lt(m))return Im(m)!=="chat-only"?null:e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(Q,{title:t("remote.serverPairing.title"),subtitle:t(p?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(p?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const te=f?f.expiresAt<=U:!1,R=Pm(C,a);async function T(){B(!0),_(null),A("idle");try{const $=await D("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:b==="admin"||a?["admin","client"]:["client"]})});j($),X(Date.now())}catch($){_(t("remote.serverPairing.error",{error:$ instanceof Error?$.message:String($)}))}finally{B(!1)}}async function Y($){_(null);try{await D(`/api/auth/sessions/${encodeURIComponent($)}`,{method:"DELETE"}),await Z()}catch(ne){_(t("remote.serverPairing.error",{error:ne instanceof Error?ne.message:String(ne)}))}}async function re(){if(!f?.url)return;const $=await Fc(f.url);$!=="empty"&&A($)}const pe=p&&f?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:te?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[f.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Ma,{value:f.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:f.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:Oi(f.expiresAt)}),f.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:f.url}),e.jsx("button",{type:"button",onClick:()=>{re()},className:zn,children:t(v==="copied"?"remote.serverPairing.copied":v==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:f.hint??t("remote.serverPairing.noLink")})]})]})}):null,xe=$=>p&&!a&&h!==null?e.jsx(Am,{saved:h,onSaved:g,className:$}):null,le=$=>t($.scopes.includes("admin")?"remote.serverPairing.scope.admin":"remote.serverPairing.scope.client");return o?e.jsxs("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"flex scroll-mt-4 flex-col gap-1.5 focus:outline-none",children:[e.jsxs("div",{"data-settings-rows":"",className:M(za,"flex flex-col"),children:[xe("px-4 py-2.5"),e.jsx(ce,{title:t("settings.simple.computer.pair"),subtitle:p?a?t("remote.serverPairing.cloudPersonal"):void 0:t("remote.serverPairing.portal"),children:p?e.jsxs("div",{className:"flex items-center gap-2",children:[a?null:e.jsxs(me,{variant:"ghost",value:b,"aria-label":t("remote.serverPairing.title"),onChange:$=>y($.target.value==="client"?"client":"admin"),children:[e.jsx("option",{value:"admin",children:t("remote.serverPairing.scope.admin")}),e.jsx("option",{value:"client",children:t("remote.serverPairing.scope.client")})]}),e.jsx("button",{type:"button","data-phone-pairing-action":d?"":void 0,onClick:()=>{T()},disabled:k,className:"ui-button",children:k?t("remote.serverPairing.creating"):t("settings.simple.computer.createCode")})]}):null}),pe?e.jsx("div",{className:"px-4 pb-2.5 [&>div]:mt-0",children:pe}):null,R.length===0?e.jsx("p",{className:"px-4 py-2.5 text-[13px] leading-[18px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):R.map($=>e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"min-w-[min(100%,15rem)] flex-1 text-[14px] leading-5 text-ink",children:[$.label,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",le($)," · ",t("remote.serverPairing.seen",{when:ps($.lastSeenAt,U)}),$.id===S?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),$.id===S?null:e.jsx("button",{type:"button",onClick:()=>{Y($.id)},className:"ui-button ml-auto shrink-0",children:t("remote.serverPairing.signOut")})]},$.id))]}),P?e.jsx("p",{className:"pl-4 text-[12px] leading-4 text-danger",children:P}):null]}):e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(Q,{title:t("remote.serverPairing.title"),subtitle:t(p?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[p&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,xe("mt-3"),p?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="admin",onChange:()=>y("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="client",onChange:()=>y("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":d?"":void 0,onClick:()=>{T()},disabled:k,className:Rm,children:k?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),pe,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(p?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),R.length===0?e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:R.map($=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[$.label,$.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",$.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",$.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:ps($.lastSeenAt,U)}),$.id===S?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),$.id===S?null:e.jsx("button",{type:"button",onClick:()=>{Y($.id)},className:zn,children:t("remote.serverPairing.signOut")})]},$.id))}),P?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:P}):null]})})}function Lm({profileEmail:s="",focusRequest:n=0,simple:a=!1}){return e.jsx(Ol,{})}function Bm(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 Un(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 Om(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function Dn(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function Mm(s,n,a){const i=[],r=new Set,c=(o,d)=>{const m=o.trim().toLowerCase();if(!m||r.has(m))return;r.add(m);const u=n.filter(x=>x.email?.toLowerCase()===m),p=a.find(x=>x.key===`user:${m}`);i.push({entry:m,role:d,isDomain:m.startsWith("@"),lastSeenAt:u.length?Math.max(...u.map(x=>x.lastSeenAt)):null,devices:u.length,turns:p?.turns??0,costUsd:p?.costUsd??null,...ot(p?.estimatedUsd)&&p.estimatedUsd>0?{estimated:!0}:{}})};for(const o of s.admins)c(o,"admin");for(const o of s.members)c(o,"member");return i}function zm(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(o=>o.key===`user:${i}`);return{entry:i,role:r.some(o=>o.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(o=>o.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 Um(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 Mi({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 o="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:M(o,"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:M(o,"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:M("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?"—":Um(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:ot(d.costUsd)?`${d.estimated?"~":""}${ct(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(Ml,{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 zi({link:s}){const{state:n,copy:a}=Ps(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(ge,{size:13,className:"text-success"}):n==="failed"?e.jsx(_e,{size:13,className:"text-danger"}):e.jsx(Za,{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 Dm({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(Q,{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(pt,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Mi,{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 Ui({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),[p,x]=l.useState(null),[h,g]=l.useState([]),[b,y]=l.useState(typeof window<"u"?window.location.origin:""),[f,j]=l.useState(null),[C,w]=l.useState(""),[S,I]=l.useState("member"),[k,B]=l.useState(null),[v,A]=l.useState(!1),[P,_]=l.useState(!1),[U,X]=l.useState(null),H=l.useCallback(async()=>{_(!0),X(null);try{const[T,Y,re,pe,xe]=await Promise.all([D("/api/config"),D("/api/auth/sessions").catch(()=>({sessions:[]})),D("/api/usage?groupBy=user").catch(()=>({groups:[]})),D("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(oe=>oe.ok?oe.json():null).catch(()=>null)]),le={admins:Array.isArray(T?.signIn?.admins)?T.signIn.admins:[],members:Array.isArray(T?.signIn?.members)?T.signIn.members:[]},$=ai(T);u($),x(le);const ne=Array.isArray(Y?.sessions)?Y.sessions:[],fe=Array.isArray(re?.groups)?re.groups:[];g($.authority==="portal"?zm(ne,fe):Mm(le,ne,fe)),typeof pe?.publicUrl=="string"&&pe.publicUrl&&y(pe.publicUrl),j(xe?.capabilities?.emailSignIn===!0?!0:xe?!1:null)}catch(T){X(T instanceof Error?T.message:String(T))}finally{_(!1)}},[]);l.useEffect(()=>{ni().then(T=>{d(T),lt(T)&&H()})},[H]);const N=async T=>{A(!0),X(null);try{await D("/api/config",{method:"PUT",body:JSON.stringify({signIn:T})}),await H()}catch(Y){X(Y instanceof Error?Y.message:String(Y))}finally{A(!1)}},Z=async()=>{if(c(!0),!p||v)return;const T=Bm(C);if(!T){X(t("remote.signInAccess.invalid"));return}await N(Un(p,T,S)),w(""),B(Dn(b,T))};if(!lt(o))return null;const te=m?.authority==="portal"?e.jsx(Dm,{peopleUrl:m.peopleUrl,people:h}):null,R=e.jsxs(e.Fragment,{children:[f===!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(m?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:T=>{T.preventDefault(),Z()},children:[e.jsx("input",{value:C,onChange:T=>w(T.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:v,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(me,{value:S,onChange:T=>I(T.target.value),"aria-label":t("people.colRole"),disabled:v,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:v||!C.trim(),className:"ui-button ui-button-primary",children:[v?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{H()},disabled:P||v,"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(we,{size:13,className:M(P&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),k&&e.jsx(zi,{link:k}),U&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:U}),e.jsx("div",{className:"mt-4",children:e.jsx(Mi,{people:h,busy:v,onRole:(T,Y)=>{p&&N(Un(p,T.entry,Y))},onRemove:T=>{p&&N(Om(p,T.entry))},onLink:T=>B(Dn(b,T.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(St,{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:te??R})]}):te??e.jsx(Q,{title:t("people.title"),subtitle:t("people.subtitle"),children:R})}const ts="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 Fm({entry:s}){const[n,a]=l.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(Ns())}),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:ud(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:md(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:zl(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(Rs,{size:12,className:M("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:Nn(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Nn(s.after?.[r])})]},r))]})]})]})})}function Di(){const[s,n]=l.useState({who:"",what:"all",from:"",to:""}),[a,i]=l.useState([]),[r,c]=l.useState(0),[o,d]=l.useState(null),[m,u]=l.useState(!1),[p,x]=l.useState(null),h=cd(s),g=l.useCallback(async()=>{u(!0),x(null);try{const y=await D(`/api/admin-activity${h}`);i(y.entries),c(y.total),d(y.retentionDays)}catch(y){x(y instanceof Error?y.message:String(y))}finally{u(!1)}},[h]);l.useEffect(()=>{const y=window.setTimeout(()=>{g()},250);return()=>window.clearTimeout(y)},[g]);const b=y=>n(f=>({...f,...y}));return e.jsxs(Q,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(o??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:y=>b({who:y.target.value}),placeholder:t("activity.whoPlaceholder"),className:M(ts,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(me,{value:s.what,onChange:y=>b({what:y.target.value}),children:dd.map(y=>e.jsx("option",{value:y,children:t(`activity.what.${y}`)},y))})]}),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:y=>b({from:y.target.value}),className:ts})]}),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:y=>b({to:y.target.value}),className:ts})]}),e.jsx("button",{type:"button",onClick:()=>{g()},disabled:m,"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:m?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(we,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${h}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Ye,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),p&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:p})}),!p&&a.length===0&&!m&&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((y,f)=>e.jsx(Fm,{entry:y},`${y.at}-${f}`))}),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 Fn=4,Fs="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",_s="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",_m=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),Fi=(s,n)=>Tt(s)===n||Fa(Lt(s),n)!=="none",_i=(s,n)=>{const a=Ua(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},_n=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function $m(){const{state:s}=V(),n=Ul(),a=Dl(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[m,u]=l.useState(null),[p,x]=l.useState(null),h=l.useRef(null),[g,b]=l.useState(null),[y,f]=l.useState(""),j=l.useCallback(()=>b(null),[]);if(l.useEffect(()=>{p||!h.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(v=>v.dataset.accessPerson===h.current)?.focus(),h.current=null)},[p]),!n||!a)return null;const C=n.people.filter(v=>v.role==="member").sort((v,A)=>v.name.localeCompare(A.name)),w=_m(s.bots),S=m?w.find(v=>v.id===m):void 0,I=p?C.find(v=>v.email===p):void 0,k=o.trim().toLowerCase(),B=async(v,A,P)=>{f("");const _=Lt(v);try{await cn(v.id,A),b({botId:v.id,before:_,after:A,text:P})}catch(U){f(U instanceof Error?U.message:String(U))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[I?e.jsx(Gm,{person:I,bots:w.filter(v=>Fi(v,I.email)),team:n,teamName:a,apply:B,onBack:()=>{h.current=I.email,x(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(mt,{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:o,"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:v=>d(v.target.value),onKeyDown:v=>{v.key==="Escape"&&o&&(v.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(v=>e.jsx("button",{type:"button","aria-pressed":r===v,"data-access-listing":v,onClick:()=>{c(v),d("")},className:M("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===v?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(v==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},v))})]}),r==="bot"?e.jsx(Km,{bots:w.filter(v=>!k||_n(k,v.name,Ua(v,n)?.name,Tt(v)??void 0)),anyBots:w.length>0,team:n,onOpen:u}):e.jsx(Wm,{people:C.filter(v=>!k||_n(k,v.name,v.email)),anyPeople:C.length>0,bots:w,onOpen:x}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),y&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:y}),S&&e.jsx(Fl,{bot:S,teamName:a,onClose:()=>u(null),onChanged:v=>b({botId:S.id,...v})}),g&&e.jsx(_l,{text:g.text,onUndo:()=>cn(g.botId,g.before),onDone:j},`${g.botId}:${g.text}:${JSON.stringify(g.after)}`)]})}function Km({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:_s,children:s.map(r=>{const c=Lt(r),o=Tt(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:M(Fs,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Ot,{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:_i(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(Hm,{entries:Object.keys(c.people).filter(d=>d!==o),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 Hm({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>Kl(r,n)).join(", "),i=s.length-Fn;return e.jsxs("span",{role:"img","aria-label":a,title:a,"data-access-stack":s.length,className:"flex shrink-0 -space-x-0.5 rtl:space-x-reverse",children:[s.slice(0,Fn).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(Hl,{person:Wl(r,n),size:22})},r)),i>0&&e.jsxs("span",{className:"flex h-[22px] min-w-[22px] items-center justify-center rounded-full bg-card px-1 text-[11px] font-medium text-ink-secondary ring-2 ring-card",children:["+",i]})]})}function Wm({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:_s,children:s.map(r=>{const c=a.filter(o=>Fi(o,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:M(Fs,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Da,{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 Gm({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(Br,{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(Da,{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:_s,children:n.map(o=>e.jsx(Vm,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function Vm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=Lt(s),o=Tt(s)===n.email,d=c.people[n.email],m=Fa(c,n.email);return e.jsxs("li",{className:Fs,"data-access-person-bot":s.id,children:[e.jsx(Ot,{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&&!o&&m===c.everyone?t("botAccess.everyoneUse",{team:i}):_i(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:o?e.jsx("span",{className:"px-2",children:t("lookedAfter.badge")}):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,$l(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})]})}function qm(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 Jm({domain:s,serverIpv4:n}){const a=qm(s);if(!a)return e.jsx("p",{className:"text-[12px] 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:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([r,c])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(it,{command:c,copyLabel:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Ym(s){return`bots.example.com {
1
+ import{c as ut,r as l,j as e,t,a as M,S as mt,f as ge,p as js,g as Ns,a8 as Lr,X as _e,i as ws,C as Br,a9 as Na,L as wt,aK as Or,aT as Mr,a0 as zr,B as Ur,b as Oe,aU as Dr,aV as Fr,aW as Zs,ao as en,aX as _r,ap as $r,aY as Kr,aZ as Hr,a3 as Wr,G as Gr,a_ as Vr,a$ as Ss,b0 as qr,b1 as Jr,b2 as tn,b3 as Cs,l as Yr,b4 as Xr,m as sn,b5 as wa,d as Qr,b6 as Zr,q as el,b7 as tl,o as sl,as as nl,b8 as nn,ar as al,b9 as il,ba as an,bb as rn,bc as ln,bd as rl,be as ll,ac as ol,bf as cl,bg as dl}from"./styles-CYPAO9i1.js";import{bB as z,bP as Pt,u as G,S as me,n as U,D as de,cM as ul,cI as Sa,T as Se,gY as Le,eK as Xe,gZ as ml,a0 as Be,eI as pl,eJ as xl,g_ as rs,g$ as rt,h0 as Ca,h1 as Es,h2 as As,h3 as hl,e0 as on,h4 as Ea,h5 as Aa,h6 as gl,h7 as fl,h8 as bl,bN as ce,b_ as X,e8 as ls,eH as yl,h9 as Ia,ha as Nt,hb as Tt,hc as Pa,hd as Ta,he as Re,hf as Fe,hg as vl,hh as kl,hi as jl,hj as Nl,hk as wl,C as Qe,hl as Ra,hm as Sl,hn as Cl,ho as La,hp as Ba,hq as ye,hr as ve,dp as cn,hs as Rt,ht as El,hu as Al,hv as Il,hw as Pl,hx as Tl,gR as Oa,bt as Rl,hy as it,W as Ll,dH as Bl,Q as Ma,hz as za,hA as Ol,aQ as St,ft as ot,fu as ct,hB as Ml,P as Ye,r as zl,ck as Ul,gG as Dl,hC as Lt,hD as Ua,hE as Fl,hF as _l,hG as dn,hH as Da,hI as Bt,hJ as Fa,hK as $l,hL as Kl,hM as Hl,hN as Wl,G as Gl,hO as Vl,hP as dt,ef as Ot,hQ as ql,hR as Jl,hS as Yl,hT as Xl,fB as Ql,hU as un,hV as Zl,hW as eo,K as to,hX as mn,hY as so,ed as _a,hZ as no,h_ as ao,h$ as io,i0 as ro,i1 as lo,i2 as oo,i3 as $a,i4 as co,i5 as uo,i6 as mo,i7 as po,i8 as xo,i9 as ho,ia as Ka,ib as go,ic as fo,dN as bo,id as yo,e9 as vo,ie as ko,ig as jo,ih as No,c as wo,ii as pn,ij as So,ik as xn,l as Co,il as Eo,im as Ao,io as Io,bH as Po,ip as To,iq as Ro,ir as Lo,is as Bo,it as Ha,fr as st,iu as Oo,fq as Mo,iv as Wa,iw as zo,ix as Ga,iy as Uo,iz as hn,iA as Do,iB as Fo,iC as _o,iD as $o,iE as Ko,iF as Ho,iG as Wo,iH as Go,iI as Is,iJ as Vo,fh as Va,m as qo,iK as Jo,iL as Yo,iM as gn,iN as Xo,iO as Qo,iP as fn,iQ as Zo,bj as ec,iR as tc,iS as sc,iT as nc,iU as ac,iV as ic,iW as bn,iX as rc,by as Ps,iY as lc,bz as oc,iZ as cc,i_ as dc,i$ as uc,j0 as mc,j1 as pc,j2 as xc,j3 as hc,j4 as gc,j5 as yn,gu as fc,j6 as bc,j7 as yc,j8 as qa,j9 as vc,ja as kc,jb as jc,jc as Ja,jd as Ya,je as Xa,jf as Nc,jg as wc,jh as Sc,d5 as Cc,I as Ec,ji as Qa,eC as Ac,bY as vn,jj as kn,e$ as jn,d$ as Ic,a2 as Pc,aC as Tc,jk as Rc,jl as Lc,jm as Bc}from"./App-DoK6OnP_.js";import{L as J,P as Ce,z as pt,E as Oc,M as Mc,ak as zc,a0 as Uc,X as Dc,K as Fc,x as Ts,C as Za,B as Mt,al as _c,am as $c,an as Kc,d as ei,r as Hc,A as Wc,U as ti,c as Gc,ao as Vc,ap as qc,N as Jc,ac as Yc,aq as Xc,b as Qc,y as Zc,V as ed,O as _t}from"./PlacesRail-DgLRkWzN.js";import{C as Rs,a as td,R as we}from"./MenuMotion-9KpZfoc6.js";import{l as si,M as sd,w as Nn}from"./MacLocalControl-DI9rmipM.js";import{Q as nd}from"./VisibilitySection-Bmoy4R5T.js";import{r as ni,a as ai,b as ad,i as id,C as rd,c as ld,p as od}from"./index-BNuCZ6CX.js";import{c as cd,A as dd,w as ud,d as md,e as wn}from"./activity-D3yGGWz9.js";import{U as ii,R as ri,B as li,S as oi,a as ci,D as di,T as ui,C as mi,L as os,b as pi,F as xi,A as cs,E as pd,c as xd,P as hd,d as gd,e as fd,N as bd}from"./NewBotDialog-yH4tNqbg.js";import{a as yd,u as vd,C as hi,b as kd,P as jd}from"./ProIntroduction-CX5wa_L9.js";import{M as gi}from"./monitor-cPSwTZbh.js";import{C as Nd}from"./coins-BUPhLqLr.js";import"./org-library-CVRs5XpH.js";import"./package-format-nP_LfEpp.js";import"./mcp-servers-CWLCIWVv.js";import"./WorksOnGrid-Ihbs1ZDY.js";import"./new-bot-BAm0i3N-.js";import"./RoutinesPage-C1DsUtyJ.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-zViFUsSH.js";import"./BrowserProfilesManager-BfuF_oUa.js";import"./SignedInSites-B3Pypdn7.js";const wd=[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]],Sd=ut("cloud-download",wd);const Cd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ed=ut("palette",Cd);const Ad=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],Id=ut("scroll-text",Ad);const Pd=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Td=ut("terminal",Pd);const Rd=[["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"}]],Ld=ut("unplug",Rd);function Ls(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}const ds="limix.settings.size",Bd=640,Od=460,$t=()=>typeof window<"u"&&window.innerWidth>=768;function Kt(s,n,a){const i=Math.max(320,window.innerWidth-32),r=Math.max(320,window.innerHeight-96);s.style.width=`${Math.round(Math.min(Math.max(n,Math.min(Bd,i)),i))}px`,s.style.height=`${Math.round(Math.min(Math.max(a,Math.min(Od,r)),r))}px`}function Md(s){s.style.width="",s.style.height="";try{window.localStorage.removeItem(ds)}catch{}}const zd=[{sx:1,sy:0,cls:"right-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:-1,sy:0,cls:"left-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:0,sy:1,cls:"bottom-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:0,sy:-1,cls:"top-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:1,sy:1,cls:"bottom-0 right-0 h-4 w-4",cursor:"cursor-nwse-resize"},{sx:-1,sy:1,cls:"bottom-0 left-0 h-4 w-4",cursor:"cursor-nesw-resize"}];function Ud(){const s=l.useRef(null);l.useEffect(()=>{const a=s.current?.parentElement;if(!a)return;if(a.style.maxWidth="100%",a.style.maxHeight="100%",$t())try{const r=JSON.parse(window.localStorage.getItem(ds)??"null");r&&typeof r.w=="number"&&typeof r.h=="number"&&Kt(a,r.w,r.h)}catch{}const i=()=>{a.style.width&&($t()?Kt(a,a.offsetWidth,a.offsetHeight):(a.style.width="",a.style.height=""))};return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);const n=a=>i=>{const r=s.current?.parentElement;if(!r||!$t())return;i.preventDefault();const c=i.clientX,o=i.clientY,d=r.offsetWidth,m=r.offsetHeight,u=p=>Kt(r,d+a.sx*(p.clientX-c)*2,m+a.sy*(p.clientY-o)*2),x=()=>{window.removeEventListener("pointermove",u);try{window.localStorage.setItem(ds,JSON.stringify({w:r.offsetWidth,h:r.offsetHeight}))}catch{}};window.addEventListener("pointermove",u),window.addEventListener("pointerup",x,{once:!0})};return e.jsx("span",{ref:s,className:"contents",children:zd.map(a=>e.jsx("span",{"aria-hidden":"true",title:z("Kéo để đổi kích thước (bấm đúp để đặt lại)","Drag to resize (double-click to reset)"),className:`absolute z-20 hidden touch-none md:block ${a.cls} ${a.cursor}`,onPointerDown:n(a),onDoubleClick:()=>{const i=s.current?.parentElement;i&&Md(i)}},`${a.sx}${a.sy}`))})}function ke({children:s,note:n="settings.adminOnly.change"}){return Pt()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Bs(s,n,a="start",i=0){const r=n.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,a==="center"?r-(s.clientHeight-(n.offsetHeight??0))/2:r-i)}function Dd(s){for(let n=s.parentElement;n;n=n.parentElement){const a=getComputedStyle(n).overflowY;if((a==="auto"||a==="scroll")&&n.scrollHeight>n.clientHeight)return n}return null}function Fd(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(!1),[r,c]=l.useState(null),o=s.config?.tts?.everyReply===!0,d=()=>{i(!0),c(null),U("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1))};return 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(me,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}function Ht(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const De=M(Le,"font-sans"),_d=[5,10,20,30,60],Wt="ui-icon-button shrink-0 hover:text-ink",Gt={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},us={count:64,length:200},$d=s=>s.length<=us.count&&s.every(n=>n.length<=us.length),ms=(s,n)=>U(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function fi({server:s,disabled:n,onPick:a}){return e.jsxs(de,{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([..._d,...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 Kd(){const{state:s,dispatch:n,refreshInstances:a}=G(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(u=>u.instanceId==="openaiCompat"&&u.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const m=u=>{i||(r(!0),o(null),ms(d.instanceId,{replyWaitMinutes:u}).then(async({instances:x})=>{Array.isArray(x)?n({type:"instances",instances:x}):await a({reportErrors:!0})}).catch(x=>o(x.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(fi,{server:d,disabled:i,onPick:m}),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 Hd(){const{state:s}=G();return e.jsx(Wd,{servers:Ls(s.instances)})}function Wd({servers:s}){const{dispatch:n,refreshInstances:a}=G(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState(""),[p,h]=l.useState(null),[g,b]=l.useState(null),[y,f]=l.useState(null),[j,C]=l.useState(""),w=!!(i.trim()&&c.trim()&&d.trim()),S=(k,B,v,A)=>{p||(h(k),b(null),B().then(async({instances:I})=>{Array.isArray(I)?n({type:"instances",instances:I}):await a({reportErrors:!0}),v?.()}).catch(I=>b({text:I.message||t("apiInstances.failed"),at:A})).finally(()=>h(null)))},P=()=>w&&S("add",()=>U("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...Ht(u).length?{models:Ht(u)}:{}})}).then(k=>(Xe("custom_endpoint","settings","unverified"),k),k=>{throw Xe("custom_endpoint","settings","error"),k}),()=>{r(""),o(""),m(""),x("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] 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(k=>e.jsxs("div",{className:"mb-1.5 rounded-lg border border-hairline/60 bg-inset px-3 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-[12px] text-ink",children:k.displayName}),k.url&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:k.url})]}),e.jsx(fi,{server:k,disabled:p!==null,onPick:B=>S("other",()=>ms(k.instanceId,{replyWaitMinutes:B}))}),e.jsx("button",{type:"button",onClick:()=>{C((k.managedModels??[]).join(", ")),f(y===k.instanceId?null:k.instanceId),b(null)},disabled:p!==null,"aria-label":t("apiInstances.editModels",{name:k.displayName}),"aria-expanded":y===k.instanceId,title:t("apiInstances.editModels",{name:k.displayName}),className:Wt,children:e.jsx(ul,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>S("other",()=>U(`/api/instances/${encodeURIComponent(k.instanceId)}/refresh-models`,{method:"POST"})),disabled:p!==null,"aria-label":t("apiInstances.refreshModels",{name:k.displayName}),title:t("apiInstances.refreshModels",{name:k.displayName}),className:Wt,children:e.jsx(Sa,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>S("other",()=>U(`/api/instances/${encodeURIComponent(k.instanceId)}`,{method:"DELETE"})),disabled:p!==null,"aria-label":t("apiInstances.remove",{name:k.displayName}),title:t("apiInstances.remove",{name:k.displayName}),className:`${Wt} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Se,{size:13,"aria-hidden":"true"})})]}),y===k.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsx("input",{value:j,onChange:B=>C(B.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:k.displayName}),spellCheck:!1,disabled:p!==null,className:M(De,"font-mono")}),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 B=Ht(j);if(!$d(B)){b({text:t("apiInstances.modelsLimit",us),at:k.instanceId});return}S("other",()=>ms(k.instanceId,{models:B}),()=>f(null),k.instanceId)},disabled:p!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>f(null),disabled:p!==null,className:"ui-button",children:t("common.cancel")})]}),g?.at===k.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g.text})]})]},k.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Gt.name),o(Gt.url)},disabled:p!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===Gt.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:k=>r(k.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:p!==null,className:De}),e.jsx("input",{type:"url",value:c,onChange:k=>o(k.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:p!==null,className:M(De,"font-mono")}),e.jsx("input",{type:"password",value:d,onChange:k=>m(k.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:p!==null,className:M(De,"font-mono")}),e.jsx("input",{value:u,onChange:k=>x(k.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:p!==null,className:M(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsxs("button",{type:"button",onClick:P,disabled:p!==null||!w,className:"ui-button self-start",children:[p==="add"?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),p==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),g&&!g.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:g.text})]})}const Gd="lm-studio";function Vd(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 qd({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=G(),r=Ls(n.instances),[c,o]=l.useState("1234"),[d,m]=l.useState(""),[u,x]=l.useState(!1),[p,h]=l.useState(null),g=Vd(c),b=!!(g&&r.some(f=>f.url===g)),y=()=>{u||!g||b||(x(!0),h(null),U("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:g,key:d.trim()||Gd,catalog:"lmstudio"})}).then(async f=>{Xe("custom_endpoint","settings","unverified"),Array.isArray(f.instances)?a({type:"instances",instances:f.instances}):await i({reportErrors:!0}),m("")},f=>{Xe("custom_endpoint","settings","error"),h(f instanceof Error&&f.message?f.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{className:M(s&&"rounded-lg border border-hairline/40 bg-inset px-3 py-2"),children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:M("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 text-[12px] leading-4 text-ink-secondary",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:f=>o(f.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:u,className:M(De,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:f=>m(f.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:u,className:M(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),g&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:g}),e.jsxs("button",{type:"button",onClick:y,disabled:u||!g||b,className:"ui-button self-start",children:[u?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),u?t("lmStudio.adding"):t("lmStudio.add")]}),b&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),p&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:p})]})}const Jd="ollama",Yd="https://ollama.com/download",Xd=s=>`${s.replace(/\/+$/,"")}/v1`,Qd=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Zd({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=G(),[r,c]=l.useState(""),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(!1),[h,g]=l.useState(null),b=l.useRef(0),y=l.useRef(!1),f=l.useCallback(P=>{const k=++b.current;u(!0),g(null),U(`/api/instances/ollama${P?`?url=${encodeURIComponent(P)}`:""}`).then(B=>{k===b.current&&d(B.status)}).catch(B=>{k===b.current&&(d(null),g(B.message||t("apiInstances.failed")))}).finally(()=>{k===b.current&&u(!1)})},[]);l.useEffect(()=>{!s||y.current||(y.current=!0,f(""))},[s,f]);const j=o?Xd(o.url):null,C=!!(j&&(Ls(n.instances).some(P=>P.url===j)||Qd(n.config?.openaiCompat?.url,j))),w=!!(j&&!C&&!x&&!m&&(o?.state==="ready"||o?.state==="no-models")),S=()=>{!w||!j||(p(!0),g(null),U("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:j,key:Jd,catalog:"ollama"})}).then(async P=>{Xe("custom_endpoint","settings","unverified"),Array.isArray(P.instances)?a({type:"instances",instances:P.instances}):await i({reportErrors:!0})},P=>{Xe("custom_endpoint","settings","error"),g(P instanceof Error&&P.message?P.message:t("apiInstances.failed"))}).finally(()=>p(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:m?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(J,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(ml,{status:o})}),!m&&o?.state==="not-running"&&e.jsx("a",{href:Yd,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:P=>c(P.target.value),onKeyDown:P=>{P.key==="Enter"&&f(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:x,className:M(Le,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs("button",{type:"button",onClick:S,disabled:!w,className:"ui-button",children:[x?e.jsx(J,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),x?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>f(r.trim()),disabled:m||x,className:"ui-button",children:[e.jsx(Sa,{size:12,"aria-hidden":"true"}),t("common.checkAgain")]})]}),C&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),h&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:h})]})}function eu(){const{state:s,dispatch:n}=G(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),g=d||u!==null,b=(j,C)=>U("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[j]:C}}})}).then(w=>n({type:"configStatus",config:w})),y=()=>{const j=i.trim().toUpperCase(),C=pl(c);if(!(g||!j||!C)){if(!xl(C)){h(t("keys.notAKey"));return}m(!0),h(null),b(j,C).then(()=>{r(""),o("")}).catch(w=>h(w.message)).finally(()=>m(!1))}},f=j=>{g||(x(j),h(null),b(j,"").catch(C=>h(C.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((j,C)=>C===0?[j]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},C),j])}),a.map(j=>e.jsxs("div",{"data-opencode-provider-key":j,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:M(Le,"block flex-1 truncate text-ink"),children:j}),e.jsx("button",{type:"button",onClick:()=>f(j),disabled:g,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:j}),className:"ui-button shrink-0",children:u===j?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},j)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:j=>{h(null),r(j.target.value)},onKeyDown:j=>j.key==="Enter"&&y(),disabled:g,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:M(Le,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:j=>{h(null),o(j.target.value)},onKeyDown:j=>j.key==="Enter"&&y(),disabled:g,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:M(Le,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:y,disabled:g||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),p&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:p})]})}function tu(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(!1),[r,c]=l.useState(null);if(!s.config?.anthropic?.configured)return null;const o=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),U("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.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:o?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(me,{checked:o,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),o&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx(Be,{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 su(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=!!s.config?.vps?.configured,u=!a.trim()&&m;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const x=()=>{r||!a.trim()&&!m||(c(!0),d(null),U("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(p=>{n({type:"configStatus",config:p}),i(p.vps?.sshAlias??"")}).catch(p=>d(p.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/leomieo/limix-bot/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.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:p=>i(p.target.value),onKeyDown:p=>p.key==="Enter"&&x(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:M(Le,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:x,disabled:r||!a.trim()&&!m||a.trim()===(s.config?.vps?.sshAlias??""),className:M("ui-button shrink-0",!u&&"ui-button-primary"),title:u?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(J,{size:13,className:"animate-spin","aria-hidden":"true"}):u?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function nu(){const{state:s,dispatch:n}=G(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const x=i.trim()!==a,p=()=>{u.current||!x||(u.current=!0,o(!0),m(null),U("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(h=>n({type:"configStatus",config:h})).catch(h=>m(h.message)).finally(()=>{u.current=!1,o(!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:h=>r(h.target.value),onBlur:p,onKeyDown:h=>h.key==="Enter"&&p(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:M(Le,"pr-8")}),c&&e.jsx(J,{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 au="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",iu=1600,ru={opencodeProviders:()=>e.jsx(eu,{}),ollama:s=>e.jsx(Zd,{visible:s}),lmStudio:()=>e.jsx(qd,{heading:!1}),vps:()=>e.jsx(su,{})},lu={anthropic:()=>e.jsx(tu,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(nu,{}),e.jsx(Kd,{}),e.jsx(Hd,{})]}),box:()=>e.jsx(bl,{}),liveKey:()=>e.jsx(fl,{})};function bi(s,n){if(s.kind==="uses")return!1;const a=As(s,n);return a.configured||a.included===!0}function ou({entry:s,visible:n}){const{state:a}=G(),i=l.useId(),c=As(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:Ea,children:[e.jsx(Aa,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:ru[s.id]?.(n)})]})}function cu({entry:s}){const{state:n,dispatch:a}=G(),i=l.useId(),r=s.opens,c=As(s,n.config),o=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ea,children:[e.jsx(Aa,{entry:s,status:o,titleId:i}),e.jsxs("div",{className:"flex flex-col gap-2 pl-8",children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(gl,{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 du({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(on,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(ou,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(cu,{entry:s}):e.jsx(on,{id:s.id,children:lu[s.id]?.()})}function uu({id:s,rows:n,open:a,onToggle:i}){const{state:r}=G(),c=rs.find(u=>u.id===s),o=l.useId(),d=l.useId(),m=n.filter(u=>bi(u,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:au,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:o,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)})]}),m>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:m})}),e.jsx(Rs,{size:14,"aria-hidden":"true",className:M("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(u=>e.jsx(du,{entry:u,visible:a},u.id)),s==="voice"&&e.jsx(Fd,{})]})]})}function mu(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=Dd(i);return r&&Bs(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"),iu)),!0}function pu(){const{state:s}=G(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(rs.filter(p=>p.id==="ai"||rt.some(h=>h.section===p.id&&bi(h,s.config))).map(p=>p.id))),c=l.useRef(null),o=Ca(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const p=rt.find(y=>y.id===o.row)?.section??"ai";a(""),r(y=>y.has(p)?y:new Set([...y,p]));let h=0,g=0;const b=()=>{mu(c.current,o,p)||++g>60?hl(o):h=window.requestAnimationFrame(b)};return h=window.requestAnimationFrame(b),()=>window.cancelAnimationFrame(h)},[o]);const m=s.config?.live?.provider==="azure",u=rt.filter(p=>Es(p,d)&&!(m&&p.id==="liveCalls")),x=rs.flatMap(p=>{const h=u.filter(g=>g.section===p.id);return h.length>0?[{id:p.id,rows:h}]:[]});return e.jsxs("div",{ref:c,"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(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:n,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key!=="Escape"||!n||(p.preventDefault(),p.stopPropagation(),a(""))},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"})]}),x.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:n.trim()})}):x.map(({id:p,rows:h})=>e.jsx(uu,{id:p,rows:h,open:d!==""||i.has(p),onToggle:()=>r(g=>{const b=new Set(g);return b.has(p)?b.delete(p):b.add(p),b})},p))]})}function yi({simple:s=!1}){return null}function vi({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1);if(l.useEffect(()=>{let u=!0;return n?.state().then(x=>{u&&i(x)}).catch(()=>{}),()=>{u=!1}},[n]),!n||!a?.available)return null;const m=u=>{c(!0),d(!1),n.set(u).then(x=>{i(x),d(x.on!==u)},()=>d(!0)).finally(()=>c(!1))};return e.jsx(ce,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:o?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(me,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>m(!a.on)})})}function xu(s=typeof window>"u"?void 0:window.ogb){return s?.platform==="darwin"&&s.talkShortcut?["talk","voice","shortcut","hotkey","hold to talk","push to talk","quick asks"]:[]}function ki(){const s=window.ogb?.talkShortcut,[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(!1);if(l.useEffect(()=>{let p=!0;return s?.state().then(h=>{p&&a(h)}).catch(()=>{}),()=>{p=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(p=>p.id===n.key)?.label??"",m=p=>{r(!0),o(!1),s.set(p).then(a,()=>o(!0)).finally(()=>r(!1))},u=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(de,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:p=>m({key:p.target.value}),children:n.keys.map(p=>e.jsx("option",{value:p.id,children:p.label},p.id))}),u&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:u})]});return e.jsx(ce,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||u?x:null,children:e.jsx(me,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>m({enabled:!n.enabled})})})}const Vt=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function ji(){const[s,n]=l.useState(null),[a,i]=l.useState(!1),[r,c]=l.useState(!1),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return U("/api/attachment-storage").then(x=>{u&&n(x)}).catch(()=>{}),()=>{u=!1}},[]),!s)return null;const m=async()=>{c(!0),d(null);try{const u=await U("/api/attachment-storage",{method:"POST"});n(u);const x=t("settings.attachments.cleared",{count:u.removed,freed:Vt(u.freedBytes)});d(u.failed>0?{kind:"error",message:`${x} ${t("settings.attachments.failed",{count:u.failed})}`}:{kind:"success",message:x})}catch(u){d({kind:"error",message:u instanceof Error?u.message:String(u)})}finally{c(!1),i(!1)}};return e.jsx(ce,{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:Vt(s.usedBytes),max:Vt(s.maxBytes)})}),e.jsx("span",{className:"block",children:t(a?"settings.attachments.confirmText":"settings.attachments.help")})]}),message:o&&e.jsx("p",{role:o.kind==="error"?"alert":"status",className:M(o.kind==="error"?"text-danger":"text-success"),children:o.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:()=>{m()},disabled:r,className:"ui-button text-danger",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}function Ni({simple:s=!1}){const[n,a]=l.useState(!1),[i,r]=l.useState(null),[c,o]=l.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)}}},m=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const x=await window.ogb.openLogsFolder();o(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)})}}},u=!!window.ogb?.exportDiagnostics;return e.jsx(ce,{title:t("settings.diagnostics.title"),subtitle:t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),message: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:M("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),e.jsx("p",{"data-logs-help":!0,className:"text-ink-tertiary",children:t(u?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:u&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[window.ogb?.openLogsFolder&&e.jsx("button",{type:"button",onClick:()=>{m()},className:"ui-button",children:t("settings.diagnostics.openLogs")}),e.jsx("button",{onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})]})})}const hu="https://dash.cloudflare.com/profile/api-tokens",gu=/^[0-9a-f]{32}$/i,Sn="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";function fu({failureText:s}){const{state:n,dispatch:a}=G(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[o,d]=l.useState(null),[m,u]=l.useState(""),[x,p]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(null),[f,j]=l.useState(null),C=(o??c).trim(),w=m.trim(),S=!w&&r&&o===null,P=o!==null&&C!==c,k=A=>a({type:"configStatus",config:A}),B=async()=>{if(!(x||!w&&!r&&!P)){if(w&&!gu.test(C))return y(t("decider.workersAi.needsAccount"));p(!0),y(null),j(null);try{(P||w&&!c)&&k(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:C}})})),(w||S)&&k(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",w):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:w}})})),u(""),d(null)}catch(A){y(A instanceof Error?A.message:String(A))}finally{p(!1)}}},v=async()=>{if(!(h||x||!w&&!r)){g(!0),j(null),y(null);try{const A=await U("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...w?{key:w,accountId:C}:{}})}),I=A.extraction?[t(A.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];j(A.ok?{ok:A.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(A.latencyMs)}),...I].join(" ")}:{ok:!1,text:s(A)})}catch(A){j({ok:!1,text:A instanceof Error?A.message:String(A)})}finally{g(!1)}}};return e.jsxs(X,{title:t("decider.workersAi.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.workersAi.detail")}),r&&e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-success"}),e.jsx("span",{children:t("decider.status.connected")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:o??c,onChange:A=>{j(null),y(null),d(A.target.value)},disabled:x,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:Sn}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:m,onChange:A=>{j(null),y(null),u(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void B(),disabled:x,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:Sn}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{B()},disabled:x||!w&&!r&&!P,title:S?t("keys.removeKey"):t("common.save"),className:M("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",S?"text-danger":"text-ink"),children:x?e.jsx(J,{size:13,className:"animate-spin"}):S?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{v()},disabled:h||x||!w&&!r,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:h?t("keys.testing"):t("keys.test")})]})]}),b&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:b}),f&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("a",{href:hu,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.workersAi.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]})}const bu={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},yu=1500,Os={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"},Cn={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},vu={...Os,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"},ku={...Os,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"},qt={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter"};function ju(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(qt[n.provider]??qt.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(qt[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function En(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=ku[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=vu[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&&Cn[s.reason])return t(Cn[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=Os[s.reason];return i?t(i):t("decider.error.other")}const Nu=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function wu(){const{state:s,dispatch:n}=G(),a=s.config?.decider,i=a?.provider==="openrouter"?"openrouter":"jev",r=i==="openrouter",c=a?.configured??!1,o=c&&a?.included===!0,d=r&&c&&a?.keySource==="shared",m=r&&a?.sharedKey===!0,u=c&&!o&&!d,x=a?.enabled??!1,p=a?.jobs.roomRouting??!0,[h,g]=l.useState(""),[b,y]=l.useState(!1),[f,j]=l.useState(!1),[C,w]=l.useState(!1),[S,P]=l.useState(null),[k,B]=l.useState(null),[v,A]=l.useState(null),I=h.trim(),_=!I&&u,D=!r||o?null:d?"decider.openrouter.status.sharedHint":c?m?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",Q=T=>n({type:"configStatus",config:T}),H=async T=>{if(!f){j(!0),P(null);try{Q(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:T})}))}catch(R){P(R instanceof Error?R.message:String(R))}finally{j(!1)}}};l.useEffect(()=>{if(!r||v)return;let T=!1;return U("/api/decider/models").then(R=>{T||A(R)},()=>{}),()=>{T=!0}},[r,v]);const N=T=>{g(""),B(null),H(T)},Z=async()=>{if(!(b||!I&&!u)){y(!0),P(null),B(null);try{const T=window.ogb?.setCredential?await window.ogb.setCredential(r?"openrouterDeciderKey":"jevApiKey",I):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{[r?"openrouterKey":"key"]:I}})});Q(T),g("")}catch(T){P(T instanceof Error?T.message:String(T))}finally{y(!1)}}},te=async()=>{if(C||b||!I&&!c)return;w(!0),B(null),P(null);const T=!I&&o,R=!I&&d;try{const Y=await U("/api/decider/test",{method:"POST",body:JSON.stringify(I?{key:I}:{})});B(Y.ok?{ok:!0,text:r?[t(R?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(Y.latencyMs)}),...Y.latencyMs>yu?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(Y.latencyMs)})}:{ok:!1,text:En(Y,T,i)})}catch(Y){B({ok:!1,text:Y instanceof Error?Y.message:String(Y)})}finally{w(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("p",{role:"status","data-testid":"helpers-status",className:"text-[13px] font-medium text-ink",children:ju(s.config)})]}),e.jsx(fu,{failureText:T=>En(T,!1,"workersai")}),e.jsx(ce,{title:t("decider.provider.label"),children:e.jsxs(de,{className:"w-48","data-testid":"decider-provider",value:i,onChange:T=>N({provider:T.target.value==="openrouter"?"openrouter":"jev"}),disabled:f||!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")})]})}),r&&e.jsx(ce,{title:t("decider.model.label"),subtitle:v?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(de,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:T=>N({openrouterModel:T.target.value,openrouterApi:v?.models.find(R=>R.id===T.target.value)?.api??"chat"}),disabled:f,"aria-label":t("decider.model.label"),children:[a?.model&&!v?.models.some(T=>T.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(T=>{const R=v?.models.filter(Y=>Y.group===T)??[];return R.length>0&&e.jsx("optgroup",{label:t(T==="recommended"?"decider.model.recommended":"decider.model.more"),children:R.map(Y=>e.jsx("option",{value:Y.id,children:Y.name},Y.id))},T)})]})}),e.jsx(ce,{title:t(r?"decider.openrouter.master":"decider.master"),subtitle:c?void 0:t(r?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(me,{"data-testid":"decider-master","aria-label":t(r?"decider.openrouter.master":"decider.master"),checked:x,disabled:!c||f||!s.config,onClick:()=>{H({enabled:!x})},className:"cursor-pointer"})}),e.jsxs(X,{title:t(r?"decider.openrouter.key.label":"decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:M("size-1.5 rounded-full",c?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:c?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):d?t("decider.openrouter.status.shared"):c?t(m?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected")})]}),D&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(D),!u&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(ls("openrouter")),className:"cursor-pointer text-accent hover:underline",children:t("decider.openrouter.key.manageLink")})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:h,onChange:T=>{B(null),P(null),g(T.target.value)},onKeyDown:T=>T.key==="Enter"&&void Z(),disabled:b,placeholder:u?t("keys.replace"):t(d?"decider.openrouter.key.overridePlaceholder":r?"decider.openrouter.key.placeholder":"decider.key.placeholder"),"aria-label":t(r?"decider.openrouter.key.label":"decider.key.label"),autoComplete:"off",spellCheck:!1,className:"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"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{Z()},disabled:b||!I&&!u,title:_?t("keys.removeKey"):t("common.save"),className:M("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",_?"text-danger":"text-ink"),children:b?e.jsx(J,{size:13,className:"animate-spin"}):_?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{te()},disabled:C||b||!I&&!c,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:C?t("keys.testing"):t("keys.test")})]}),S&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:S}),k&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",k.ok?"text-success":"text-danger"),children:k.text}),!d&&e.jsxs("a",{href:bu[i],target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t(r?"decider.openrouter.key.getKey":"decider.key.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]}),e.jsx(X,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(me,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:x&&p,disabled:!x||f,onClick:()=>{H({jobs:{roomRouting:!p}})},className:"cursor-pointer"})]}),Nu.map(T=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(T)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},T))]})})]})}const Su=["openai","xai","gemini","openrouter","custom"],Cu=4,wi={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},Eu={openai:[{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 Au(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|responses)$/,""),a.toString().replace(/\/+$/,"")}const Ct={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},Iu={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"}},Pu={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},An={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},ps="w-full min-w-0 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",Et="flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",Jt="\0other";function Tu(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 Ru(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 Lu(){const{state:s,dispatch:n}=G(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??wi.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,m]=l.useState(null),[u,x]=l.useState(null),p=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!p||u)return;let y=!1;return U("/api/images/openrouter-models").then(f=>{y||x(Array.isArray(f?.models)?f:{source:"builtin",models:[]})},()=>{y||x({source:"builtin",models:[]})}),()=>{y=!0}},[p,u]);const h=async y=>{o(!0),m(null);try{const f=await U("/api/config",{method:"PUT",body:JSON.stringify(y)});n({type:"configStatus",config:f})}catch(f){m(f instanceof Error?f.message:String(f))}finally{o(!1)}},g=(y,f)=>{if(y==="fallback"&&f==="")return void h({imageGen:{fallback:null}});const j=f,C=y==="primary"&&r?.provider===j;h({imageGen:{[y]:{provider:j},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((y,f,j)=>j.indexOf(y)===f);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("imageGen.intro")}),e.jsxs("p",{role:"status","data-testid":"image-gen-status",className:"flex items-center gap-2 text-[13px] font-medium text-ink",children:[e.jsx("span",{className:M("size-1.5 shrink-0 rounded-full",a?.ready?i.configured?"bg-success":"bg-warning":"bg-raised-hover")}),a?.ready?i.configured?t("imageGen.status.ready",{provider:Ct[i.provider]}):t("imageGen.status.backupOnly",{provider:Ct[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(Bu,{disabled:c}),e.jsx(In,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:u,disabled:c||!s.config,onProvider:g,onModel:y=>{h({imageGen:{primary:{provider:i.provider,model:y}}})}}),e.jsx(In,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:u,disabled:c||!s.config,onProvider:g,onModel:y=>r&&void h({imageGen:{fallback:{provider:r.provider,model:y}}})}),e.jsx(ce,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(de,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??Cu),onChange:y=>{h({imageGen:{maxPerTurn:Number(y.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(y,f)=>f+1).map(y=>e.jsx("option",{value:y,children:y},y))})}),d&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:d}),b.map(y=>e.jsx(Mu,{provider:y,status:a},y))]})}function Bu({disabled:s}){const{dispatch:n}=G(),[a,i]=l.useState(null),[r,c]=l.useState(""),[o,d]=l.useState(!1),[m,u]=l.useState(""),x=async p=>{d(!0),u("");try{if(p){const h=await U("/api/images/connections",{method:"POST",body:JSON.stringify({id:r})});n({type:"configStatus",config:h}),i(null),c("")}else{const h=await U("/api/images/connections");i(h.connections),c(h.connections[0]?.id??"")}}catch(h){u(h instanceof Error?h.message:String(h))}finally{d(!1)}};return e.jsxs(X,{title:t("imageGen.saved.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] text-ink-secondary",children:t("imageGen.saved.help")}),a===null?e.jsx("button",{type:"button",className:Et,disabled:o||s,onClick:()=>{x(!1)},children:t("imageGen.saved.title")}):a.length?e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(de,{"aria-label":t("imageGen.saved.title"),value:r,disabled:o,onChange:p=>c(p.target.value),children:a.map(p=>e.jsxs("option",{value:p.id,children:[p.name," · ",p.url]},p.id))}),e.jsx("button",{type:"button",className:Et,disabled:o||s||!r,onClick:()=>{x(!0)},children:t("imageGen.saved.apply")})]}):e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.saved.empty")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m})]})}function In({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:m}){const u=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(ce,{title:u,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(de,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:x=>d(s,x.target.value),disabled:o,"aria-label":u,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),Su.filter(x=>x!==r).map(x=>e.jsx("option",{value:x,children:Ct[x]},x))]})}),n&&e.jsx(Ou,{slot:s,slotLabel:u,provider:n,model:a,openrouterModels:c,disabled:o,onModel:m})]})}function Ou({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,m]=l.useState(null),{state:u}=G(),x=a==="custom"&&u.config?.imageGen?.customApi==="responses",h=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??(x?[{id:"gpt-6.1-sol",name:"GPT-6.1 Sol"},{id:"gpt-6-astra",name:"GPT-6 Astra"}]:Eu[a]).map(f=>({...f,group:"recommended"})),g=d!==null||h.length===0,b=()=>{d!==null&&(m(null),d.trim()&&d.trim()!==i&&o(d.trim()))},y=f=>{if(f===Jt)return m(i);m(null),o(f)};return e.jsx(ce,{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:[h.length>0&&e.jsxs(de,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:g?Jt:i,onChange:f=>y(f.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[!i&&e.jsx("option",{value:"",disabled:!0,children:t("imageGen.model.placeholder")}),i&&!h.some(f=>f.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(f=>{const j=h.filter(C=>C.group===f);return j.length>0&&e.jsx("optgroup",{label:t(f==="recommended"?"decider.model.recommended":"decider.model.more"),children:j.map(C=>e.jsx("option",{value:C.id,children:C.name},C.id))},f)}),e.jsx("option",{value:Jt,children:t("imageGen.model.other")})]}),g&&e.jsx("input",{value:d??i,onChange:f=>m(f.target.value),onBlur:b,onKeyDown:f=>f.key==="Enter"&&b(),disabled:c,placeholder:wi[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:M(ps,"w-64 max-w-full")})]})})}function Mu({provider:s,status:n}){const{dispatch:a}=G(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(!1),[g,b]=l.useState(null),y=s==="openrouter"?[n?.primary,n?.fallback].filter(I=>I?.provider===s).map(I=>I?.model).join(" "):"",f=g?.models===y?g:null,j=I=>b(I&&{...I,models:y}),C=Ru(n,s),w=s==="openai"||s==="gemini"||s==="custom"?Iu[s]:null,S=s==="xai"||s==="openrouter"?Pu[s]:null,P=c??n?.customUrl??"",k=async I=>{m(!0),x(null),j(null);try{a({type:"configStatus",config:await I()}),r(""),o(null)}catch(_){x(_ instanceof Error?_.message:String(_))}finally{m(!1)}},B=I=>k(async()=>s==="xai"||s==="openrouter"?yl(s,I,!1):window.ogb?.setCredential&&w?window.ogb.setCredential(w.credential,I):U("/api/config",{method:"PUT",body:JSON.stringify(w.patch(I))})),v=()=>k(async()=>{const I=P.trim()?Au(P.trim()):"";return U("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:I}})})}),A=async()=>{h(!0),j(null);try{j(Tu(s,await U("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(I){j({ok:!1,text:I instanceof Error?I.message:String(I)})}finally{h(!1)}};return e.jsxs(X,{title:Ct[s],children:[e.jsx(zu,{configured:C,optional:s==="custom"}),S&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(S.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent hover:underline",children:t("imageGen.key.manage")})]}),s==="custom"&&e.jsxs("div",{className:"mb-3 space-y-2",children:[e.jsx("label",{className:"block text-[13px] text-ink-secondary",children:t("imageGen.custom.api")}),e.jsxs(de,{"aria-label":t("imageGen.custom.api"),value:n?.customApi??"images",disabled:d,onChange:I=>{k(()=>U("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customApi:I.target.value}})}))},children:[e.jsx("option",{value:"images",children:"Images API"}),e.jsx("option",{value:"responses",children:"Responses API · image_generation"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.custom.apiHelp")}),n?.customApi==="responses"&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:n.customLocalImageExtension===!0,disabled:d,onChange:I=>{k(()=>U("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customLocalImageExtension:I.target.checked}})}))}}),t("imageGen.custom.extension")]})]}),s==="custom"&&e.jsxs("div",{className:"mb-2 flex gap-2",children:[e.jsx("input",{type:"url",value:P,onChange:I=>o(I.target.value),onKeyDown:I=>I.key==="Enter"&&void v(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:ps}),e.jsxs("button",{type:"button",onClick:()=>{v()},disabled:d||c===null,className:Et,children:[d?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:I=>r(I.target.value),onKeyDown:I=>I.key==="Enter"&&i.trim()&&void B(i.trim()),disabled:d,placeholder:C?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((w??S).label),autoComplete:"off",spellCheck:!1,className:ps}),e.jsxs("button",{type:"button",onClick:()=>{B(i.trim())},disabled:d||!i.trim(),className:Et,children:[d?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]}),C&&e.jsx("button",{type:"button",onClick:()=>{A()},disabled:p||d,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:p?t("keys.testing"):t("keys.test")})]}),f&&e.jsx("p",{role:"status",className:M("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[An[s]?e.jsx("a",{href:An[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:js()})}),C&&e.jsx("button",{type:"button",onClick:()=>{B("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u})]})}function zu({configured:s,optional:n=!1}){return e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:M("size-1.5 rounded-full",s?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:s?"text-success":void 0,children:t(s?"imageGen.key.saved":n?"imageGen.key.optional":"imageGen.key.missing")})]})}function Yt(s){if(s.readOnly||s.trialCredit||s.access==="custom"||s.access==="api")return null;if(s.driverKind==="claudeAgent")return"claude";const n=s.authentication?.method;return s.snapshot.chatgptPlan===!0||(n==="device-code"||n==="browser-pkce")&&Ia(s.driverKind)==="codex"?"chatgpt":null}function Ms(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const zs={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function Uu(s,n){return{signOut:Ms(n)==="signedIn"&&n.authentication?.signOut===!0&&n.snapshot.account?.method!=="api-key",remove:s==="claude"?n.instanceId!=="claude"&&n.claudeAccount?.isDefault!==!0:n.instanceId.startsWith("chatgpt-")}}function Si(s){return s.some(Re)}function Du(s,n){const a=n.filter(o=>Ms(o)==="signedIn"),i=Si(n),r=n.some(o=>o.snapshot.state==="available"),c=n.length>1?t("accounts.count",{count:String(n.length),signedIn:String(a.length)}):a[0]?.snapshot.account?.email??wl(n[0]);return{title:t(zs[s].title),subtitle:c,ready:i,status:i?t("onboarding.engines.ready"):r?t("model.signInRequired"):t("onboarding.engines.needsSetup"),action:i?t("engines.library.manage"):r?t("accounts.signIn"):t("engines.library.setup")}}function Fu({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=G(),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,g]=l.useState(null),b=l.useRef(null),{signOut:y,remove:f}=Uu(s,n),j=i.bots.filter(S=>S.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const S=k=>{k.key==="Escape"&&(k.stopPropagation(),d(!1))},P=k=>{k.target instanceof Node&&!b.current?.contains(k.target)&&d(!1)};return window.addEventListener("keydown",S,!0),window.addEventListener("pointerdown",P),()=>{window.removeEventListener("keydown",S,!0),window.removeEventListener("pointerdown",P)}},[o]);const C=async S=>{u(null),p(!0),g(null);try{const P=`/api/instances/${encodeURIComponent(n.instanceId)}${S==="signOut"?"/auth/sign-out":""}`,{instances:k}=await U(P,S==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(k)?r({type:"instances",instances:k}):await c().catch(()=>{})}catch(P){g(P instanceof Error?P.message:String(P))}finally{p(!1)}},w="ui-menu-row w-full text-left disabled:cursor-not-allowed disabled:opacity-50";return e.jsxs("div",{ref:b,className:"relative flex items-center gap-1",children:[f&&e.jsx("button",{type:"button",disabled:x||j>0,onClick:()=>u("remove"),title:j>0?t("accounts.inUse",{count:String(j)}):void 0,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:t("accounts.remove")}),e.jsx("button",{type:"button",onClick:()=>d(S=>!S),disabled:x,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:Fe(n)}),className:"flex size-8 items-center justify-center rounded-lg text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:x?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Oc,{size:16})}),o&&e.jsxs("div",{role:"menu",className:M("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]",Mc),children:[e.jsx("button",{type:"button",role:"menuitem",className:M(w,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),y&&e.jsx("button",{type:"button",role:"menuitem",className:M(w,"text-ink"),onClick:()=>{d(!1),u("signOut")},children:t("accounts.signOut")}),f&&j>0&&e.jsx("p",{className:"px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary",children:t("accounts.inUse",{count:String(j)})})]}),h&&e.jsx("p",{role:"alert",className:"absolute right-0 top-full z-30 mt-1 w-[260px] rounded-lg bg-card p-2 text-[12px] text-danger shadow-lg",children:h}),e.jsx(Qe,{open:m==="signOut",title:t("accounts.signOutTitle",{name:Fe(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>u(null),onConfirm:()=>{C("signOut")}}),e.jsx(Qe,{open:m==="remove",title:t("accounts.removeTitle",{name:Fe(n)}),body:t(zs[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>u(null),onConfirm:()=>{C("remove")}})]})}function _u({instance:s,onDone:n}){const{dispatch:a}=G(),[i,r]=l.useState(Fe(s)),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=async()=>{const x=i.trim();if(!x||x===Fe(s))return n();o(!0),m(null);try{const{instances:p}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:x})});Array.isArray(p)&&a({type:"instances",instances:p}),n()}catch(p){m(p instanceof Error?p.message:String(p))}finally{o(!1)}};return e.jsxs("form",{className:"flex min-w-0 flex-1 flex-col gap-1",onSubmit:x=>{x.preventDefault(),u()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:x=>r(x.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:x=>{x.key==="Escape"&&(x.stopPropagation(),n())},className:"min-w-0 flex-1 rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:c?e.jsx(J,{size:13,className:"animate-spin"}):t("common.save")}),e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control",children:t("common.cancel")})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d})]})}function $u({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=Ms(n),m=n.snapshot.account,u=n.snapshot.authenticationUnavailableReason,x=u&&d!=="signedIn"?u:d==="signedIn"?m?.method==="api-key"?t("accounts.apiKey"):[m?.email,m?.organization].filter(Boolean).join(" · ")||t("accounts.signedIn"):d==="signedOut"?t("accounts.notSignedIn"):d==="unknown"?t("accounts.unknown"):n.snapshot.reason??t("onboarding.engines.needsSetup");return e.jsxs("li",{"data-account":n.instanceId,"data-account-state":d,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:M("flex size-6 shrink-0 items-center justify-center rounded-full",d==="signedIn"?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:d==="signedIn"?e.jsx(ge,{size:13}):e.jsx("span",{className:M("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(_u,{instance:n,onDone:()=>o(!1)}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:Fe(n),children:Fe(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:x,children:x})]}),d!=="signedIn"&&d!=="unavailable"&&!u&&!a&&e.jsx("button",{type:"button",onClick:i,className:M("shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-semibold",d==="signedOut"?"bg-accent text-white hover:brightness-110":"bg-control text-ink hover:bg-raised-hover"),children:t("accounts.signIn")}),e.jsx(Fu,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(vl,{instanceId:n.instanceId,autoStart:!0,onDone:r}),n.claudeAccount?.signInCommand&&e.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("engineSetup.preferTerminal")}),e.jsx(kl,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(jl,{instanceId:n.instanceId,provider:"codex",browserPkce:n.authentication?.method==="browser-pkce",autoStart:!0,onDone:r})}),s==="chatgpt"&&d==="signedIn"&&n.snapshot.chatgptPlan&&e.jsx("div",{className:"pl-9",children:e.jsx(Nl,{instanceId:n.instanceId,welcome:!1})})]})}function Ci({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=G(),[d,m]=l.useState(!1),[u,x]=l.useState(""),[p,h]=l.useState(""),[g,b]=l.useState(!1),[y,f]=l.useState(null),j=async()=>{if(!(g||!u.trim())){b(!0),f(null);try{const C={displayName:u.trim(),...a,...i&&p.trim()?{configDir:p.trim()}:{}},w=await U(n,{method:"POST",body:JSON.stringify(C)});Array.isArray(w.instances)&&o({type:"instances",instances:w.instances}),m(!1),x(""),h(""),typeof w.instanceId=="string"&&c(w.instanceId)}catch(C){f(C instanceof Error?C.message:String(C))}finally{b(!1)}}};return d?e.jsxs("form",{"data-add-account":n,className:"space-y-2.5 rounded-xl border border-hairline/50 bg-app p-3",onSubmit:C=>{C.preventDefault(),j()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:u,onChange:C=>x(C.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:g,"aria-describedby":r,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] font-normal text-ink outline-none focus:border-accent-border disabled:opacity-50"})]}),i&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("accounts.folderToggle")}),e.jsx("input",{value:p,onChange:C=>h(C.target.value),placeholder:"~/.claude-work",maxLength:4096,spellCheck:!1,disabled:g,"aria-label":t("accounts.folderToggle"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("p",{className:"mt-1 leading-relaxed",children:t("accounts.folderHint")})]}),y&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:y}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),f(null)},disabled:g,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:g||!u.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[g&&e.jsx(J,{size:13,className:"animate-spin"}),t("accounts.addSubmit")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>m(!0),"aria-describedby":r,className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),s]})}function Ku({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(x=>x.snapshot.state==="available"),m=n.find(x=>x.policy)?.policy,u=l.useId();return e.jsxs(Nt,{instance:o,summary:Du(s,n),bare:i,children:[m&&e.jsxs("p",{className:"mb-3 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:m.organizationName})})," · ",m.reason]}),d?e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{"data-accounts":s,className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(x=>e.jsx($u,{group:s,instance:x,signingIn:r===x.instanceId,onSignIn:()=>c(x.instanceId),onSignInDone:()=>c(p=>p===x.instanceId?null:p)},x.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(Ci,{label:t(zs[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?u:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:u,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(Tt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(Pa,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(Ta,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const Hu={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},ft=M(Le,"font-sans"),Wu={name:"",url:"",token:"",model:""},Gu=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:""});function Pn({instance:s,engine:n,onDone:a}){const{dispatch:i}=G(),r=Hu[n],[c,o]=l.useState(s?Gu(s):Wu),[d,m]=l.useState(!1),[u,x]=l.useState(null),p=b=>({value:c[b],onChange:y=>o(f=>({...f,[b]:y.target.value})),spellCheck:!1,disabled:d}),h=!!(c.name.trim()&&(c.url.trim()||n==="codex")&&(s||c.token.trim())),g=async()=>{if(d||!h)return;m(!0),x(null);const b={displayName:c.name.trim(),baseUrl:c.url.trim()||r.url,...c.token.trim()?{token:c.token.trim()}:{},...c.model.trim()?{model:c.model.trim()}:{}};try{const y=s?await U(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await U(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(y.instances)&&i({type:"instances",instances:y.instances}),a()}catch(y){x(y instanceof Error&&y.message?y.message:t("claudeEndpoints.failed"))}finally{m(!1)}};return e.jsxs("form",{"data-claude-endpoint-form":n==="claude"?s?.instanceId??"new":void 0,"data-codex-endpoint-form":n==="codex"?s?.instanceId??"new":void 0,className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:b=>{b.preventDefault(),g()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(n==="codex"?"agentEndpoints.responses":"agentEndpoints.messages")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.name"),e.jsx("input",{...p("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeEndpoints.name"),className:ft})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.baseUrl"),e.jsx("input",{...p("url"),type:"url",maxLength:2048,placeholder:r.url,"aria-label":t("claudeEndpoints.baseUrl"),className:M(ft,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.token"),e.jsx("input",{...p("token"),type:"password",maxLength:4096,autoComplete:"off","aria-label":t("claudeEndpoints.token"),className:M(ft,"font-mono"),placeholder:s?t("claudeEndpoints.tokenKeep"):""})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.model"),e.jsx("input",{...p("model"),maxLength:160,placeholder:r.model,"aria-label":t("claudeEndpoints.model"),className:M(ft,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:a,disabled:d,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:d||!h,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[d&&e.jsx(J,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Vu({instance:s,onEdit:n}){const{state:a,dispatch:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),x=a.bots.filter(g=>g.modelSelection.instanceId===s.instanceId||g.fallback?.some(b=>b.instanceId===s.instanceId)||g.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,p=s.claudeEndpoint??s.codexEndpoint,h=async()=>{c(!1),d(!0),u(null);try{const g=await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(g.instances)&&i({type:"instances",instances:g.instances})}catch(g){u(g instanceof Error?g.message:String(g))}finally{d(!1)}};return e.jsxs("li",{"data-claude-endpoint":s.claudeEndpoint?s.instanceId:void 0,"data-codex-endpoint":s.codexEndpoint?s.instanceId:void 0,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:p?.baseUrl,children:p?.baseUrl})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeEndpoints.edit")}),e.jsx("button",{type:"button",disabled:o||x>0,onClick:()=>c(!0),title:x>0?t("accounts.inUse",{count:String(x)}):t("accounts.remove"),"aria-label":t("claudeEndpoints.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeEndpoints.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function Ei({engine:s}){const{state:n}=G(),a=n.instances.filter(c=>s==="claude"?c.claudeEndpoint:c.codexEndpoint),[i,r]=l.useState(null);return e.jsxs("div",{"data-claude-endpoints":s==="claude"?"":void 0,"data-codex-endpoints":s==="codex"?"":void 0,className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t(s==="claude"?"claudeEndpoints.title":"agentEndpoints.codexTitle")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(s==="claude"?"claudeEndpoints.hint":"agentEndpoints.codexHint")}),a.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:a.map(c=>i===c.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Pn,{engine:s,instance:c,onDone:()=>r(null)})},c.instanceId):e.jsx(Vu,{instance:c,onEdit:()=>r(c.instanceId)},c.instanceId))}),i==="new"?e.jsx(Pn,{engine:s,onDone:()=>r(null)}):e.jsxs("button",{type:"button",onClick:()=>r("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeEndpoints.add")]})]})}function Xt(){return e.jsx(Ei,{engine:"claude"})}function Qt(){return e.jsx(Ei,{engine:"codex"})}const nt=M(Le,"font-sans"),qu={opusModel:"global.anthropic.claude-opus-5-5",sonnetModel:"global.anthropic.claude-sonnet-5-5",haikuModel:"global.anthropic.claude-haiku-5-5",smallFastModel:"global.anthropic.claude-haiku-5-5"},Tn=["opusModel","sonnetModel","haikuModel","smallFastModel"],Ju={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},Yu=s=>{const n=s.claudeBedrock;return{name:s.displayName,awsProfile:n?.awsProfile||"default",awsRegion:n?.awsRegion??"",model:n?.model??"",opusModel:n?.opusModel??"",sonnetModel:n?.sonnetModel??"",haikuModel:n?.haikuModel??"",smallFastModel:n?.smallFastModel??""}},Rn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function Ln({instance:s,onDone:n}){const{dispatch:a}=G(),[i,r]=l.useState(s?Yu(s):Ju),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=h=>({value:i[h],onChange:g=>r(b=>({...b,[h]:g.target.value})),spellCheck:!1,disabled:c}),x=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),p=async()=>{if(c||!x)return;o(!0),m(null);const h={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(Tn.map(g=>[g,i[g].trim()]))};try{const g=s?await U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(h)}):await U("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(h)});Array.isArray(g.instances)&&a({type:"instances",instances:g.instances}),n()}catch(g){m(g instanceof Error&&g.message?g.message:t("claudeBedrock.failed"))}finally{o(!1)}};return e.jsxs("form",{"data-claude-bedrock-form":s?.instanceId??"new",className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:h=>{h.preventDefault(),p()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.awsHint")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.name"),e.jsx("input",{...u("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:nt})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...u("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:M(nt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...u("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:M(nt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...u("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:M(nt,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.modelHint")}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary outline-none hover:text-ink",children:t("claudeBedrock.tiers")}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:Tn.map(h=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(Rn[h]),e.jsx("input",{...u(h),maxLength:160,placeholder:qu[h],"aria-label":t(Rn[h]),className:M(nt,"font-mono")})]},h))})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!x,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[c&&e.jsx(J,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Xu({instance:s,onEdit:n}){const{state:a,dispatch:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),x=a.bots.filter(g=>g.modelSelection.instanceId===s.instanceId||g.fallback?.some(b=>b.instanceId===s.instanceId)||g.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,p=s.claudeBedrock,h=async()=>{c(!1),d(!0),u(null);try{const g=await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(g.instances)&&i({type:"instances",instances:g.instances})}catch(g){u(g instanceof Error?g.message:String(g))}finally{d(!1)}};return e.jsxs("li",{"data-claude-bedrock":s.instanceId,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx(Ra,{preset:"aws",size:16,className:"shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:t("claudeBedrock.rowSubtitle",{profile:p?.awsProfile??"",region:p?.awsRegion??""})})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeBedrock.edit")}),e.jsx("button",{type:"button",disabled:o||x>0,onClick:()=>c(!0),title:x>0?t("accounts.inUse",{count:String(x)}):t("accounts.remove"),"aria-label":t("claudeBedrock.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeBedrock.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function Zt(){const{state:s}=G(),n=s.instances.filter(r=>r.claudeBedrock),[a,i]=l.useState(null);return e.jsxs("div",{"data-claude-bedrock-endpoints":"",className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("claudeBedrock.title")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.hint")}),n.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(r=>a===r.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Ln,{instance:r,onDone:()=>i(null)})},r.instanceId):e.jsx(Xu,{instance:r,onEdit:()=>i(r.instanceId)},r.instanceId))}),a==="new"?e.jsx(Ln,{onDone:()=>i(null)}):e.jsxs("button",{type:"button",onClick:()=>i("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeBedrock.add")]})]})}function Bn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Qu({instance:s,initial:n={kind:"idle"}}){const[a,i]=l.useState(n),[r,c]=l.useState(null),o=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,d=async()=>{c(null),i({kind:"scanning"});try{const x=await U(o);i(x.folders>0?{kind:"found",bytes:x.bytes,complete:x.complete}:{kind:"none"})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},m=async()=>{c(null),i({kind:"deleting"});try{const x=await U(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:x.freedBytes,remaining:x.remaining})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},u=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(zc,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||u)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:u,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[u&&e.jsx(J,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Bn(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Bn(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}const es=[60,120,180,360,720];function Ai(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(!1),[r,c]=l.useState(""),o=l.useRef(!1),d=s.config?.cacheKeepWarm;if(!d)return null;const m=async x=>{if(!o.current){o.current=!0,i(!0),c("");try{const p=await U("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:x.enabled,windowMinutes:x.windowMinutes}})});n({type:"configStatus",config:p})}catch(p){c(p instanceof Error?p.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},u=es.includes(d.windowMinutes)?[...es]:[...es,d.windowMinutes].sort((x,p)=>x-p);return e.jsxs(X,{title:t("settings.keepWarm.title"),subtitle:t("settings.keepWarm.subtitle"),children:[e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.enable")}),e.jsx(me,{id:"cache-keepwarm-enabled",checked:d.enabled,disabled:a,"aria-describedby":"cache-keepwarm-help cache-keepwarm-cost",onClick:()=>{m({...d,enabled:!d.enabled})}})]}),e.jsx("p",{id:"cache-keepwarm-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.help")}),e.jsx("p",{id:"cache-keepwarm-cost",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.cost")}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-window",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.window")}),e.jsx(de,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:x=>{m({...d,windowMinutes:Number(x.target.value)})},children:u.map(x=>e.jsx("option",{value:x,children:t("settings.keepWarm.hours",{hours:Number((x/60).toFixed(2))})},x))})]}),a&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}function Zu({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[m,u]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[x,p]=l.useState(!1),[h,g]=l.useState(null),[b,y]=l.useState(!1),[f,j]=l.useState(null),C=l.useRef(!1);l.useEffect(()=>{C.current||(C.current=!0,U(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:v})=>{c(v),s.cli&&(v.includes(s.cli)?d(s.cli):u(s.cli))}).catch(()=>c(v=>v??[])))},[n,s.cli]);const w=m.trim()||o,S=w!==(s.cli??""),P=x||b;l.useEffect(()=>{g(null)},[w]);const k=()=>{if(P||!w||!S)return;y(!0),j(null);const v=w;U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:v})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(A=>j(A.message)).finally(()=>y(!1))},B=()=>{P||!w||!S||(p(!0),j(null),U("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(v=>{g(v),v.ok&&k()}).catch(v=>j(v.message)).finally(()=>p(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[r!==null&&r.length>0&&e.jsxs(de,{className:"w-full font-mono",value:m.trim()?"":o,onChange:v=>{d(v.target.value),u("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:P,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(v=>e.jsx("option",{value:v,children:v},v))]}),e.jsx("input",{type:"text",value:m,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),!(!w||!S)&&B())},placeholder:r?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:P,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),h&&!h.ok&&h.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(Be,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:h.message})})]}),h?.ok&&h.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:h.version})}),f&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),h&&!h.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>g(null),disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>k(),disabled:P,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:b?e.jsx(J,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:B,disabled:P||!w||!S,className:M("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:P?e.jsx(J,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})})]})]})}function Ii({instance:s}){const{refreshInstances:n}=G(),[a,i]=l.useState(!1),r=td(a),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),g=l.useRef(null);l.useEffect(()=>{g.current!==null&&g.current!==s.cli&&i(!1),g.current=s.cli??null},[s.cli]);const b=()=>{c||d||(o(!0),h(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>h(j.message)).finally(()=>o(!1)))},y=()=>{c||d||(o(!0),h(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>h(j.message)).finally(()=>o(!1)))},f=()=>{c||d||(m(!0),x(null),h(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{x(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>h(j.message)).finally(()=>m(!1)))};return e.jsxs("details",{className:"mt-4 border-t border-hairline/40 pt-3",children:[e.jsx("summary",{className:"cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[12px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:f,disabled:c||d,className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[d?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),d?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:b,disabled:c||d,className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:c?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{type:"button","data-hide-engine":s.instanceId,onClick:y,disabled:c||d,title:t("engines.hideHint"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:t("engines.hide")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:d,"aria-expanded":a,className:M("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),u&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:u})}),p&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:p}),r.shown&&e.jsx("div",{className:r.className,...r.exitProps,children:e.jsx(Zu,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function On({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=G(),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),p=n==="remove",h=p?a.bots.filter(y=>y.modelSelection.instanceId===s.instanceId).length:0,g=t(p?"accounts.remove":"accounts.signOut"),b=async()=>{o(!1),m(!0),x(null);try{const y=`/api/instances/${encodeURIComponent(s.instanceId)}${p?"":"/auth/sign-out"}`,{instances:f}=await U(y,{method:p?"DELETE":"POST"});Array.isArray(f)?i({type:"instances",instances:f}):await r()}catch(y){x(y instanceof Error?y.message:String(y))}finally{m(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",disabled:d||h>0,onClick:()=>o(!0),className:M("rounded-lg px-2.5 py-1.5 text-[12px] font-medium disabled:cursor-not-allowed disabled:opacity-50",p?"text-danger hover:bg-danger/10":"text-ink-secondary hover:bg-raised hover:text-ink"),children:d?e.jsx(J,{size:13,className:"animate-spin"}):g}),h>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})})]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsx(Qe,{open:c,title:t(p?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(p?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:g,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{b()}})]})}function em({source:s}){const{state:n}=G(),[a,i]=l.useState(null),r=a?n.instances.find(c=>c.instanceId===a&&c.snapshot.authenticated!==!0):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(Ci,{label:t("engineSetup.antigravity.addAccount"),endpoint:"/api/instances/antigravity-accounts",extra:{sourceInstanceId:s.instanceId},onAdded:i}),r&&e.jsx("div",{"data-antigravity-added":r.instanceId,children:e.jsx(Tt,{instance:r,unframed:!0})})]})}function tm({instance:s,bare:n=!1}){const a=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.trialCredit?e.jsx(Nt,{instance:s,bare:n,children:e.jsx("p",{"data-trial-credit":s.trialCredit,className:"text-[13px] leading-relaxed text-ink-secondary",children:t(s.trialCredit==="used_up"?"engines.trialCreditUsedUp":s.trialCredit==="ended"?"engines.trialCreditEnded":Re(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(Nt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!Re(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(Nt,{instance:s,bare:n,children:[a,!Re(s)&&e.jsx(Tt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),Re(s)&&e.jsx(Al,{instance:s,className:"mt-3"}),Re(s)&&s.serverKind==="ollama"&&e.jsx(Il,{instance:s,className:"mt-3"}),Re(s)&&e.jsx(Pl,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(Pa,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(Ta,{warning:s.snapshot.warning,className:"mt-3"}),Re(s)&&s.snapshot.authenticated===!0&&(s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t(Tl[Ia(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Qu,{instance:s}),s.driverKind==="antigravityAgent"&&e.jsxs("div",{className:"mt-3 space-y-3",children:[s.snapshot.authenticated&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:s.snapshot.account?.email??t("engineSetup.antigravity.emailUnavailable")}),e.jsx(em,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(On,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(On,{instance:s,action:"remove"})]}),e.jsx(Ii,{instance:s})]})}function sm(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?El(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function nm({rows:s,isReady:n,renderEngine:a,more:i}){const[r,c]=l.useState(null),o=s.filter(m=>n(m)||m.authentication!==void 0),d=s.filter(m=>!o.includes(m));return e.jsxs(e.Fragment,{children:[e.jsx(ye,{label:t("settings.simple.ai.yours"),actions:e.jsx(La,{}),children:e.jsx(ve,{children:o.map(m=>{const u=n(m),x=r===m.instanceId;return e.jsxs("div",{"data-simple-engine":m.instanceId,className:"group",children:[e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"flex min-w-[min(100%,15rem)] flex-1 items-center gap-3",children:[e.jsx(cn,{instance:m,size:14,subtle:!0}),e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"truncate text-[14px] leading-5 text-ink",children:m.displayName}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:sm(m,u)})]})]}),e.jsx("button",{type:"button","aria-expanded":x,className:"ui-button ml-auto shrink-0",onClick:()=>c(x?null:m.instanceId),children:t(x?"common.done":u?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),x&&e.jsx("div",{className:"px-4 pb-3",children:a(m,!0)})]},m.instanceId)})})}),d.length>0&&e.jsx(Rt,{title:t("settings.simple.ai.more",{count:String(d.length)}),trailing:e.jsx("span",{"aria-hidden":"true",className:"flex items-center -space-x-1",children:d.slice(0,4).map(m=>e.jsx("span",{className:"flex size-[18px] items-center justify-center rounded-full bg-menu",children:e.jsx(cn,{instance:m,size:14,subtle:!0})},m.instanceId))}),...i,children:e.jsx(Ba,{instances:d,isReady:n,renderEngine:m=>a(m)})})]})}function am(){const{state:s,refreshInstances:n}=G(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return U("/api/instances/hidden").then(x=>{u&&i(Array.isArray(x?.instances)?x.instances:[])}).catch(()=>{}),()=>{u=!1}},[s.instances]),a.length===0)return null;const m=u=>{c(u),d(null),U(`/api/instances/${encodeURIComponent(u)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(x=>d(x.message)).finally(()=>c(null))};return e.jsxs("details",{"data-hidden-engines":!0,className:"px-4",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink",children:t("engines.hiddenTitle",{count:String(a.length)})}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.hiddenHint")}),e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:a.map(u=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",children:u.displayName}),e.jsx("button",{type:"button","data-unhide-engine":u.instanceId,disabled:r!==null,onClick:()=>m(u.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===u.instanceId?t("engines.unhiding"):t("engines.unhide")})]},u.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function Pi({simple:s=!1,more:n}){const{state:a}=G();l.useEffect(()=>Sl,[]);const i=a.instances.filter(h=>h.readOnly||h.cli!==void 0||h.cliDefault!==void 0||h.snapshot.state==="unavailable"||Cl(h)||h.claudeEndpoint!==void 0||h.claudeBedrock!==void 0||h.codexEndpoint!==void 0),r=new Map;for(const h of i){const g=Yt(h);g&&r.set(g,[...r.get(g)??[],h])}const c=h=>{const g=Yt(h);return g&&r.get(g)?.[0]===h?g:null},o=i.filter(h=>!Yt(h)||c(h)),d=o.length>0&&o.every(h=>h.readOnly),m=!r.has("chatgpt")&&!d,u=!r.has("claude")&&!d,x=h=>{const g=c(h);return g?Si(r.get(g)):Re(h)},p=(h,g=!1)=>{const b=c(h);return b?e.jsx(Ku,{group:b,accounts:r.get(b),bare:g,advanced:e.jsxs(e.Fragment,{children:[b==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Xt,{}),e.jsx(Zt,{})]}):e.jsx(Qt,{}),e.jsx(Ii,{instance:h})]})}):e.jsx(tm,{instance:h,bare:g})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(nm,{rows:o,isReady:x,renderEngine:p,more:n}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Xt,{}),e.jsx(Zt,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(Qt,{})})]}):e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60 space-y-2 px-4",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(La,{})]}),e.jsx(Ba,{instances:o,isReady:x,renderEngine:p}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Xt,{}),e.jsx(Zt,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(Qt,{})}),e.jsx(am,{}),e.jsx(Ai,{})]})}const im={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function bt(s,n){return[im[s],{signal:n}]}function Us(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function rm({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:m}){return e.jsxs(X,{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(Oa,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(i&&"animate-spin")})," ",t("vm.refresh")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):o?t("vm.vps.unavailable",{reason:o}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!o)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[o&&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(Be,{size:14,className:"shrink-0 text-warning"})," ",o]}),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(J,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):o&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{size:14,className:"shrink-0 text-warning"})," ",o]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Uc,{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((u,x)=>{const p=gm(u),h=Ds(p),g=r===u.name,b=Fs(u.name);return e.jsxs("div",{className:M("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:u.orphaned?t("vm.vps.orphan",{id:b}):u.ownerName}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="stopped"||p==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:u.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:i||u.inUse||r!==null,"aria-busy":g||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:[g?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("vm.vps.remove")]})]},`${u.vpsAlias??""}:${u.name}`)})]})]})}const lm=[1e3,2e3,4e3];function om(s){return new Promise(n=>window.setTimeout(n,s))}const cm={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},dm={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 Ds(s){return t(dm[s])}function um(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function mm(s){return Ds(um(s))}function pm(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 Ti(s,n,a){const i={...a},r=new Set(s.map(o=>o.boxId)),c=s.flatMap(o=>{const d=a[o.boxId];return d==="deleted"?[]:d==="deleting"?[{...o,state:"removing"}]:d!=="sleeping"?[o]:o.state==="archived"?(delete i[o.boxId],[o]):[{...o,state:"archived"}]});for(const o of n)a[o.boxId]!=="sleeping"||r.has(o.boxId)||c.push({...o,state:"archived"});for(const[o,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(o)&&delete i[o];return{instances:c,overrides:i}}function xm(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ti(Array.isArray(s.instances)?s.instances:[],n,a)}function hm(s){return["idle","ready","running"].includes(s.state)}function gm(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 Fs(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function fm(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:Us(`/api/bots/${s.botId}/local-computer/remove`,{})}}function bm(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:Us(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function ym(s){const n=Fs(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:Us(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function ts(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function vm({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:m}){return e.jsxs(X,{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(Oa,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] 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.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{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(Ns,{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((u,x)=>{const p=pm(u),h=Ds(p),g=i?.boxId===u.boxId,b=hm(u),y=p==="removing";return e.jsxs("div",{className:M("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:u.orphaned?t("vm.cloud.orphan"):t("vm.cloud.ofBot",{name:u.ownerName??""})}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="sleeping"||p==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h})]}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.cloud.machineId",{id:u.name})}),u.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(u),disabled:a||u.inUse||i!==null||!b,"aria-busy":g&&i?.action==="sleep"?!0:void 0,title:b?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:h.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:[g&&i?.action==="sleep"?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Dc,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:a||u.inUse||i!==null||y,"aria-busy":g&&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:[g&&i?.action==="delete"?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]})]},u.boxId)})})]})}function km({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d,runningInstances:m,powerPending:u,onPower:x}){return e.jsxs(X,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):m===void 0?t("vm.perBot.created",{count:s.length,max:n}):z(`Đã tạo ${s.length} máy · Đang chạy ${m}/${n}`,`${s.length} desktops created · ${m}/${n} running`)}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m===void 0?t("vm.perBot.deleteHint"):z("Ứng dụng không giới hạn số máy đã tạo; số lượng thực tế phụ thuộc dung lượng ổ đĩa. Dừng một máy để giải phóng tài nguyên cho máy khác.","The app does not cap created desktops; their number depends on disk space. Stop a desktop to free resources for another.")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null||!!u,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 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:opacity-40",children:[e.jsx(we,{size:12,className:M(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] 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||!!u,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Be,{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((p,h)=>{const g=mm(p),b=i===p.botId,y=p.managed===!0;return e.jsxs("div",{className:M("flex items-start justify-between gap-3 px-3 py-3",h>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.name}),e.jsx("span",{className:M("rounded-full px-2 py-0.5 text-[11px]",y?p.inUse||p.ready?"bg-success/15 text-success":p.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:g})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(cm[p.destination])})}),!y&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),y&&p.problem&&!p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:si(p.problem)}),y&&p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),y&&e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[x&&e.jsxs("button",{type:"button",onClick:()=>x(p,p.container==="running"?"stop":"start"),disabled:a||p.inUse||i!==null||!!u||p.container==="stopped"&&m!==void 0&&m>=n,"aria-busy":u?.botId===p.botId||void 0,className:"flex items-center gap-1.5 rounded-lg bg-control px-2.5 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-40",children:[u?.botId===p.botId&&e.jsx(J,{size:12,className:"animate-spin"}),p.container==="running"?z("Dừng","Stop"):z("Bật","Start")]}),e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!!u,"aria-busy":b||void 0,title:p.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:p.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:[b?e.jsx(J,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]})]},p.botId)})})]})}function yt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:M("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(ge,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:M("text-[14px]",a?"text-ink-secondary line-through":"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 Ve({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:M("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] font-medium disabled:opacity-50",r?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(J,{size:13,className:"animate-spin"}),a]})}const Ri=5,Li=1440,jm=480;function Nm(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Ri&&a<=Li?a:null}function wm({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const p=async()=>{if(!c||u)return;const h=Nm(i);if(h===null){m(t("vm.idle.range"));return}x(!0);try{await a(h),r(String(h)),o(!1),m("")}catch(g){m(g instanceof Error?g.message:t("vm.idle.error"))}finally{x(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[12px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:M("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",d?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Ri,max:Li,step:1,inputMode:"numeric",value:i,disabled:n||u,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:h=>{r(h.target.value),o(!0),m("")},onBlur:()=>{p()},onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[13px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:d}):null]})}function Bi(){const s=G().state.config?.cloudHome===!0,[n,a]=l.useState(null),[i,r]=l.useState(!0),[c,o]=l.useState(null),d=l.useRef(null);l.useEffect(()=>()=>d.current?.abort(),[]);const[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,g]=l.useState(0),[b,y]=l.useState([]),[f,j]=l.useState(2),[C,w]=l.useState(!1),[S,P]=l.useState(null),[k,B]=l.useState(null),[v,A]=l.useState(null),[I,_]=l.useState(null),[D,Q]=l.useState(0),[H,N]=l.useState([]),[Z,te]=l.useState(null),[T,R]=l.useState(!0),[Y,re]=l.useState(null),[pe,xe]=l.useState(null),[le,$]=l.useState(null),[ne,fe]=l.useState(0),oe=l.useRef([]),se=l.useRef({}),[ie,be]=l.useState([]),[K,ae]=l.useState(null),[L,E]=l.useState([]),[W,ue]=l.useState(!0),[q,je]=l.useState(null),[Ie,Ze]=l.useState(null),[et,Me]=l.useState(null),[Sr,Cr]=l.useState(0),[Er,ze]=l.useState(""),$e=l.useCallback(async O=>{const F=await fetch(...bt("status",O)),ee=await F.json().catch(()=>({}));if(!O?.aborted){if(!F.ok)throw new Error(ee.error??t("vm.err.status",{code:F.status}));return a(ee),u(null),ee}},[]),xt=l.useCallback(async O=>{const F=await fetch(...bt("local-vms",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.inventory",{code:F.status}));const V=ee;y(V.instances),j(V.maxInstances),B(V.available?null:si(V.problem)??t("vm.err.runtimeUnavailable")),P(null)},[]),tt=l.useCallback(async O=>{const F=await fetch(...bt("cloud",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.cloudInventory",{code:F.status}));const V=ee,he=xm(V,oe.current,se.current);se.current=he.overrides,oe.current=he.instances,N(he.instances),te(V.configured===!0),xe(V.available||!V.configured?null:V.problem??t("vm.err.cloudUnavailable")),re(null)},[]),zt=l.useCallback(async O=>{const F=await fetch(...bt("vps",O)),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.err.vpsInventory",{code:F.status}));const V=ee;be(Array.isArray(V.instances)?V.instances:[]),ae(V.configured===!0),E(Array.isArray(V.vpsAliases)?V.vpsAliases:[]),Ze(V.available||!V.configured?null:V.problem??t("vm.err.vpsUnavailable")),je(null)},[]);l.useEffect(()=>{if(s)return;let O=!0,F,ee;const V=async()=>{ee=new AbortController;try{await $e(ee.signal)}catch(he){O&&!(he instanceof DOMException&&he.name==="AbortError")&&(a(null),u(he instanceof Error?he.message:String(he)))}finally{O&&(r(!1),F=window.setTimeout(()=>{V()},5e3))}};return V(),()=>{O=!1,ee?.abort(),F!==void 0&&window.clearTimeout(F)}},[s,$e,h]),l.useEffect(()=>{if(n?.mode!=="per-bot"){y([]),w(!1),P(null),B(null);return}const O=new AbortController;return w(!0),xt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||P(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||w(!1)}),()=>O.abort()},[D,xt,n?.mode]),l.useEffect(()=>{const O=new AbortController;return R(!0),tt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||xe(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||R(!1)}),()=>O.abort()},[ne,tt]),l.useEffect(()=>{const O=new AbortController;return ue(!0),zt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||Ze(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||ue(!1)}),()=>O.abort()},[zt,Sr]);const Ut=async(O,F)=>{const ee=await fetch(`/api/local-computer/${O}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:F}),V=await ee.json().catch(()=>({})),he={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!ee.ok)throw new Error(V.error??t(he[O]));return F.throwIfAborted(),a(V),V},Gs=O=>window.ogb?.confirm?window.ogb.confirm(O):window.confirm(O),Ke=async O=>{if(c!==null||d.current)return;const F=new AbortController;d.current=F,o(O),u(null);try{if(O==="remove"&&!await Gs(t("vm.confirm.deleteShared"))||O==="recreate"&&!await Gs(t("vm.confirm.recreate")))return;let ee;if(O==="recreate"?(await Ut("remove",F.signal),ee=await Ut("run",F.signal)):ee=await Ut(O,F.signal),(O==="run"||O==="start"||O==="recreate")&&(ee=await Nn(ee,async()=>await $e(F.signal)??ee,F.signal),!ee.ready&&!ee.capacity_limited))throw new Error(ee.problem??t("vm.err.start"));await $e(),ze(O==="remove"?t("vm.announce.deleted"):O==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(ee){if(F.signal.aborted)return;u(ee instanceof Error?ee.message:String(ee))}finally{d.current=null,F.signal.aborted||o(null)}},Ar=async(O,F)=>{if(I||v)return;_({botId:O.botId,action:F}),P(null);const ee=new AbortController;try{const V=`/api/bots/${encodeURIComponent(O.botId)}/local-computer`,he=await fetch(`${V}/${F}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}"});let Te=await he.json();if(!he.ok)throw new Error(Te.error??t("vm.err.start"));if(F==="start"&&(Te=await Nn(Te,async()=>{const He=await fetch(V);if(!He.ok)throw new Error(t("vm.err.start"));return He.json()},ee.signal)),F==="start"&&!Te.ready)throw new Error(Te.problem??t("vm.err.start"));await Promise.all([xt(),$e()])}catch(V){P(V instanceof Error?V.message:String(V))}finally{_(null)}},Vs=async O=>{p(!0),u(null);try{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:O,automaticCapacity:!0}})}),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.policyError"));a(V=>V&&{...V,mode:O}),await $e()}catch(F){u(F instanceof Error?F.message:String(F))}finally{p(!1)}},Ir=async O=>{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:O}})}),ee=await F.json().catch(()=>({}));if(!F.ok)throw new Error(ee.error??t("vm.idle.error"));a(V=>V&&{...V,idle_timeout_ms:O*6e4})},Pr=async O=>{if(!O.managed){P(t("vm.unmanagedError"));return}const F=ts(fm(O),ee=>window.confirm(ee));if(F){A(O.botId),P(null);try{const ee=await fetch(...F),V=await ee.json().catch(()=>({}));if(!ee.ok)throw new Error(V.error??t("vm.deleteError"));await xt(),ze(t("vm.announce.deletedBot",{name:O.name}))}catch(ee){P(ee instanceof Error?ee.message:String(ee))}finally{A(null)}}},qs=async(O,F)=>{const ee=ts(bm(O,F),V=>window.confirm(V));if(ee){$({boxId:F.boxId,action:O}),re(null),ze("");try{const V=await fetch(...ee),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t(O==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const Te=O==="delete"&&he?.pending===!0;se.current={...se.current,[F.boxId]:O==="delete"?Te?"deleting":"deleted":"sleeping"};const He=Ti(oe.current,oe.current,se.current);se.current=He.overrides,oe.current=He.instances,N(He.instances);const We=F.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:F.ownerName??""});if(ze(Te?`${We}: ${t("vm.state.removing")}.`:t(O==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:We})),Te){for(const Ee of lm){await om(Ee);try{await tt()}catch{}if(se.current[F.boxId]!=="deleting"){ze(t("vm.announce.cloudDeleted",{subject:We}));return}}const Ge={...se.current};delete Ge[F.boxId],se.current=Ge;const gt=oe.current.map(Ee=>Ee.boxId===F.boxId?{...Ee,state:F.state}:Ee);oe.current=gt,N(gt);try{await tt(),oe.current.some(Ee=>Ee.boxId===F.boxId)||ze(t("vm.announce.cloudDeleted",{subject:We}))}catch(Ee){const Rr=Ee instanceof Error?Ee.message:String(Ee);re(`${We}: ${t("vm.state.removing")}. ${Rr}`)}return}try{await tt()}catch(Ge){const gt=Ge instanceof Error?Ge.message:String(Ge);re(t(O==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:We,detail:gt}))}}catch(V){re(V instanceof Error?V.message:String(V))}finally{$(null)}}},Tr=async O=>{const F=Fs(O.name),ee=ts(ym(O),V=>window.confirm(V));if(ee){Me(O.name),je(null);try{const V=await fetch(...ee),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t("vm.vpsRemoveError"));await zt(),ze(t("vm.announce.vpsRemoved",{subject:O.orphaned?t("vm.announce.orphanVps",{id:F}):t("vm.confirm.ownedVps",{name:O.ownerName??""})}))}catch(V){je(V instanceof Error?V.message:String(V))}finally{Me(null)}}},Pe=n?.commands,ht=n?.ready===!0,Js=n?.container!=="missing",Ys=!!(Js&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Xs=!i&&!n,Qs=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ne=n?.mode==="per-bot",Dt=Ne&&n?.runtime==="container",Ft=Ne?!!(n?.daemonUp&&n?.image&&!Dt):ht;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Er}),e.jsx(vm,{instances:H,configured:Z,loading:T,pending:le,error:Y,unavailableReason:pe,onRefresh:()=>fe(O=>O+1),onSleep:O=>{qs("sleep",O)},onDelete:O=>{qs("delete",O)}}),e.jsx(rm,{instances:ie,configured:K,aliases:L,loading:W,removingName:et,error:q,unavailableReason:Ie,onRefresh:()=>Cr(O=>O+1),onRemove:O=>{Tr(O)}}),e.jsx(sd,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(X,{title:t("vm.main.title"),subtitle:Ne?t("vm.main.perBotSubtitle",{host:Qs}):t("vm.main.sharedSubtitle",{host:Qs}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:M("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px]",Ft?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(J,{size:12,className:"animate-spin"}):Ft?e.jsx(ge,{size:12}):e.jsx(Rl,{size:9}),i?t("common.checking"):Xs?t("vm.main.statusUnavailable"):Ne&&Ft?t("vm.main.readyPerBot"):Dt?t("vm.main.perBotUnsupported"):ht?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),g(O=>O+1),Q(O=>O+1)},disabled:i||c!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(we,{size:12})," ",t("vm.main.recheck")]}),ht&&!Ne&&e.jsxs("a",{href:n?.viewer_url??Pe?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink hover:bg-control",children:[e.jsx(pt,{size:12})," ",t("vm.main.watch")]})]}),m&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:m})]}),e.jsxs(X,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((O,F)=>e.jsx("button",{type:"button",disabled:!n||x,onClick:()=>{Vs(O)},className:M("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",F>0&&"border-l border-hairline/40",n?.mode===O?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:O==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},O))}),Ne&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:z("Số máy ảo chạy cùng lúc tối đa","Maximum desktops running at once")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:z("Không giới hạn số máy đã tạo trong ứng dụng. Giới hạn chạy cùng lúc tự tính theo RAM/CPU cấp cho Docker hoặc Podman, có dự phòng cho hệ thống. Khi đủ chỗ đang chạy, máy mới vẫn được tạo ở trạng thái dừng.","The app does not cap created desktops. The running limit is calculated from Docker or Podman memory/CPU with a system reserve. When running slots are full, new desktops are still created in a stopped state.")}),n?.capacity&&e.jsxs("div",{className:"mt-1 text-[12px] text-ink-secondary",children:[n.capacity.source==="host"?z("Ước tính từ máy chủ; chưa đọc được tài nguyên Docker/Podman","Host estimate; Docker/Podman resources have not been read"):n.capacity.source==="docker"?"Docker":"Podman",` · ${n.capacity.memoryGb.toFixed(1)} GB RAM · ${n.capacity.cpus} CPU`,` · ${z("Mỗi máy","Each desktop")}: ${n.capacity.perVmMemoryGb} GB / ${n.capacity.perVmCpus} CPU`,` · ${z("Dành cho hệ thống","System reserve")}: ${n.capacity.reservedMemoryGb.toFixed(1)} GB / ${n.capacity.reservedCpus} CPU`]}),n?.automatic_capacity===!1&&e.jsx("button",{type:"button",disabled:x,onClick:()=>{Vs(n.mode)},className:"mt-1 text-[12px] text-accent hover:underline",children:z("Chuyển sang tự động","Switch to automatic")}),n&&(n.running_instances??0)>n.max_instances&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:z("Số máy đang chạy vượt mức ước tính mới. Ứng dụng giữ nguyên chúng; dừng bớt máy trước khi bật máy khác.","The running desktops exceed the new estimate. They are kept; stop some before starting another.")})]}),e.jsxs("div",{className:"shrink-0 rounded-lg bg-control px-3 py-2 text-center text-[13px] text-ink",children:[e.jsx("div",{className:"text-[11px] text-ink-secondary",children:n?.automatic_capacity===!1?z("Thủ công","Manual"):z("Tự động","Automatic")}),e.jsx("div",{className:"font-semibold tabular-nums",children:n?.max_instances??"…"})]})]}),e.jsx(wm,{minutes:n?Math.round(n.idle_timeout_ms/6e4):jm,disabled:!n||x,onSave:Ir}),x&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(J,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(X,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(yt,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Pe?.install?e.jsx(it,{command:Pe.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(yt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Pe?.runtimeStart?e.jsx(it,{command:Pe.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(yt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ve,{action:"pull",pending:c,onClick:()=>{Ke("pull")},children:t("vm.setup.prepare")}),Pe?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(it,{command:Pe.pull})})]})]}),e.jsxs(yt,{n:4,title:Ne?t("vm.setup.step4PerBot"):Ys?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:Ne?b.some(O=>O.managed):ht,children:[Ne?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Dt?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):Ys?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Be,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ve,{action:"recreate",pending:c,onClick:()=>{Ke("recreate")},danger:!0,children:[e.jsx(Ll,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ve,{action:"start",pending:c,onClick:()=>{Ke("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{action:"run",pending:c,onClick:()=>{Ke("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Pe?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(it,{command:Pe.run})})]})]})]})}),Ne&&e.jsx(km,{instances:b,maxInstances:n?.max_instances??f,runningInstances:n?.running_instances,powerPending:I,onPower:(O,F)=>{Ar(O,F)},loading:C,deletingBotId:v,error:S,unavailableReason:k,onRefresh:()=>Q(O=>O+1),onDelete:O=>{Pr(O)}}),Xs&&e.jsx(X,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Be,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(X,{title:t("vm.safety.title"),subtitle:Ne?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[Js&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ve,{action:"stop",pending:c,onClick:()=>{Ke("stop")},children:[e.jsx(Bl,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ve,{action:"remove",pending:c,onClick:()=>{Ke("remove")},danger:!0,children:[e.jsx(Se,{size:12})," ",Ne?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.37.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function Oi(s){return t("pairing.worksOnceUntil",{time:Lr(s)})}function xs(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const Sm="/api/team/phone-pairing",Mn="/api/team/phones",Cm=4e3;function Em(s){return`${s.label} · ${s.email}`}function Am({team:s,blocked:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(null),[h,g]=l.useState(()=>Date.now()),b=w=>p(t("remote.serverPairing.error",{error:w instanceof Error?w.message:String(w)}));async function y(){try{const w=await U(Mn);c(Array.isArray(w?.phones)?w.phones:[]),d(typeof w?.current=="string"?w.current:null)}catch(w){b(w)}}l.useEffect(()=>{y()},[]);const f=a?a.expiresAt<=h:!1;l.useEffect(()=>{if(!a)return;const w=setInterval(()=>g(Date.now()),15e3);return()=>clearInterval(w)},[a]),l.useEffect(()=>{if(!a||f)return;const w=setInterval(()=>{y()},Cm);return()=>clearInterval(w)},[a,f]);async function j(){u(!0),p(null);try{i(await U(Sm,{method:"POST",body:"{}"})),g(Date.now())}catch(w){b(w)}finally{u(!1)}}async function C(w){p(null);try{await U(`${Mn}/${encodeURIComponent(w)}`,{method:"DELETE"})}catch(S){b(S)}await y()}return e.jsxs(X,{title:t("teamPhone.title"),subtitle:t("teamPhone.subtitle",{team:s}),children:[e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{j()},disabled:m||!!n,title:n??void 0,className:"ui-button ui-button-primary",children:m?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})}),n?e.jsx("p",{role:"status","data-team-phone-blocked":!0,className:"mt-3 text-[13px] text-ink-secondary",children:n}):null,a?e.jsx("div",{"data-team-phone-code":!0,className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:f?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[a.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Ma,{value:a.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:a.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:Oi(a.expiresAt)}),a.url?null:e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:a.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:t("teamPhone.stays",{team:s})}),r?e.jsxs("div",{"data-team-phones":!0,children:[e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t("remote.serverPairing.devices")}),r.length===0?e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:r.map(w=>e.jsxs("li",{"data-team-phone":w.id,className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[Em(w),e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("remote.serverPairing.seen",{when:xs(w.lastSeenAt,h)}),w.id===o?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),w.id===o?null:e.jsx("button",{type:"button","data-team-phone-remove":!0,onClick:()=>{C(w.id)},className:"ui-button",children:t("teamPhone.remove")})]},w.id))})]}):null,x?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:x}):null]})}function Im({saved:s,onSaved:n,className:a}){const[i,r]=l.useState(s),[c,o]=l.useState(!1),[d,m]=l.useState(null);l.useEffect(()=>r(s),[s]);async function u(){const x=i.trim();if(!(c||x===s)){o(!0),m(null);try{const p=await U("/api/config",{method:"PATCH",body:JSON.stringify({computerName:x})});n(p.computerName??x)}catch(p){m(t("remote.computerName.error",{error:p instanceof Error?p.message:String(p)}))}finally{o(!1)}}}return e.jsxs("div",{"data-computer-name":!0,className:M("flex flex-col gap-1",a),children:[e.jsx("label",{htmlFor:"computer-name",className:"text-[13px] font-medium text-ink",children:t("remote.computerName.title")}),e.jsx("input",{id:"computer-name",value:i,disabled:c,placeholder:t("remote.computerName.placeholder"),"aria-describedby":"computer-name-help",onChange:x=>r(x.target.value),onBlur:()=>{u()},onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()},className:"w-full max-w-xs rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("p",{id:"computer-name-help",className:"text-[12px] leading-4 text-ink-secondary",children:t("remote.computerName.help")}),d?e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d}):null]})}function lt(s){return id(s)}function Pm(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function Tm(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}const Rm="ui-button ui-button-primary",zn="ui-button";function Lm({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0,team:r,teamPhoneBlocked:c=null,simple:o=!1,reveal:d=!0}){const[m,u]=l.useState(s),[x,p]=l.useState(n),[h,g]=l.useState(null),[b,y]=l.useState("admin"),[f,j]=l.useState(null),[C,w]=l.useState([]),[S,P]=l.useState(null),[k,B]=l.useState(!1),[v,A]=l.useState("idle"),[I,_]=l.useState(null),[D,Q]=l.useState(()=>Date.now()),H=l.useRef(null),N=l.useRef(0);async function Z(){try{const $=await U("/api/auth/sessions");w(Array.isArray($?.sessions)?$.sessions:[]),P(typeof $?.current=="string"?$.current:null)}catch($){_(t("remote.serverPairing.error",{error:$ instanceof Error?$.message:String($)}))}}if(l.useEffect(()=>{ni().then($=>{u($),lt($)&&Z(),($.kind==="loopback"||$.kind==="session")&&U("/api/config").then(ne=>{p(ai(ne).pairingCodes),lt($)&&g(typeof ne?.computerName=="string"?ne.computerName:"")}).catch(()=>{})})},[]),l.useEffect(()=>{i?N.current!==i&&ad(H.current)&&(N.current=i):N.current=0},[i,m]),l.useEffect(()=>{if(!f)return;const $=setInterval(()=>Q(Date.now()),15e3);return()=>clearInterval($)},[f]),r&&m?.kind==="session"&&m.team)return e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(Am,{team:r,blocked:c})});if(!lt(m))return Pm(m)!=="chat-only"?null:e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(X,{title:t("remote.serverPairing.title"),subtitle:t(x?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(x?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const te=f?f.expiresAt<=D:!1,T=Tm(C,a);async function R(){B(!0),_(null),A("idle");try{const $=await U("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:b==="admin"||a?["admin","client"]:["client"]})});j($),Q(Date.now())}catch($){_(t("remote.serverPairing.error",{error:$ instanceof Error?$.message:String($)}))}finally{B(!1)}}async function Y($){_(null);try{await U(`/api/auth/sessions/${encodeURIComponent($)}`,{method:"DELETE"}),await Z()}catch(ne){_(t("remote.serverPairing.error",{error:ne instanceof Error?ne.message:String(ne)}))}}async function re(){if(!f?.url)return;const $=await Fc(f.url);$!=="empty"&&A($)}const pe=x&&f?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:te?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[f.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Ma,{value:f.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:f.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:Oi(f.expiresAt)}),f.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:f.url}),e.jsx("button",{type:"button",onClick:()=>{re()},className:zn,children:t(v==="copied"?"remote.serverPairing.copied":v==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:f.hint??t("remote.serverPairing.noLink")})]})]})}):null,xe=$=>x&&!a&&h!==null?e.jsx(Im,{saved:h,onSaved:g,className:$}):null,le=$=>t($.scopes.includes("admin")?"remote.serverPairing.scope.admin":"remote.serverPairing.scope.client");return o?e.jsxs("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"flex scroll-mt-4 flex-col gap-1.5 focus:outline-none",children:[e.jsxs("div",{"data-settings-rows":"",className:M(za,"flex flex-col"),children:[xe("px-4 py-2.5"),e.jsx(ce,{title:t("settings.simple.computer.pair"),subtitle:x?a?t("remote.serverPairing.cloudPersonal"):void 0:t("remote.serverPairing.portal"),children:x?e.jsxs("div",{className:"flex items-center gap-2",children:[a?null:e.jsxs(de,{variant:"ghost",value:b,"aria-label":t("remote.serverPairing.title"),onChange:$=>y($.target.value==="client"?"client":"admin"),children:[e.jsx("option",{value:"admin",children:t("remote.serverPairing.scope.admin")}),e.jsx("option",{value:"client",children:t("remote.serverPairing.scope.client")})]}),e.jsx("button",{type:"button","data-phone-pairing-action":d?"":void 0,onClick:()=>{R()},disabled:k,className:"ui-button",children:k?t("remote.serverPairing.creating"):t("settings.simple.computer.createCode")})]}):null}),pe?e.jsx("div",{className:"px-4 pb-2.5 [&>div]:mt-0",children:pe}):null,T.length===0?e.jsx("p",{className:"px-4 py-2.5 text-[13px] leading-[18px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):T.map($=>e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"min-w-[min(100%,15rem)] flex-1 text-[14px] leading-5 text-ink",children:[$.label,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",le($)," · ",t("remote.serverPairing.seen",{when:xs($.lastSeenAt,D)}),$.id===S?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),$.id===S?null:e.jsx("button",{type:"button",onClick:()=>{Y($.id)},className:"ui-button ml-auto shrink-0",children:t("remote.serverPairing.signOut")})]},$.id))]}),I?e.jsx("p",{className:"pl-4 text-[12px] leading-4 text-danger",children:I}):null]}):e.jsx("div",{ref:H,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(X,{title:t("remote.serverPairing.title"),subtitle:t(x?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[x&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,xe("mt-3"),x?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="admin",onChange:()=>y("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="client",onChange:()=>y("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":d?"":void 0,onClick:()=>{R()},disabled:k,className:Rm,children:k?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),pe,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(x?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),T.length===0?e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:T.map($=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[$.label,$.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",$.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",$.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:xs($.lastSeenAt,D)}),$.id===S?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),$.id===S?null:e.jsx("button",{type:"button",onClick:()=>{Y($.id)},className:zn,children:t("remote.serverPairing.signOut")})]},$.id))}),I?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:I}):null]})})}function Bm({profileEmail:s="",focusRequest:n=0,simple:a=!1}){return e.jsx(Ol,{})}function Om(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 Un(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 Mm(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function Dn(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function zm(s,n,a){const i=[],r=new Set,c=(o,d)=>{const m=o.trim().toLowerCase();if(!m||r.has(m))return;r.add(m);const u=n.filter(p=>p.email?.toLowerCase()===m),x=a.find(p=>p.key===`user:${m}`);i.push({entry:m,role:d,isDomain:m.startsWith("@"),lastSeenAt:u.length?Math.max(...u.map(p=>p.lastSeenAt)):null,devices:u.length,turns:x?.turns??0,costUsd:x?.costUsd??null,...ot(x?.estimatedUsd)&&x.estimatedUsd>0?{estimated:!0}:{}})};for(const o of s.admins)c(o,"admin");for(const o of s.members)c(o,"member");return i}function Um(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(o=>o.key===`user:${i}`);return{entry:i,role:r.some(o=>o.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(o=>o.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 Dm(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 Mi({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 o="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:M(o,"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:M(o,"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:M("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?"—":Dm(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:ot(d.costUsd)?`${d.estimated?"~":""}${ct(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(Ml,{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 zi({link:s}){const{state:n,copy:a}=Ts(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(ge,{size:13,className:"text-success"}):n==="failed"?e.jsx(_e,{size:13,className:"text-danger"}):e.jsx(Za,{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 Fm({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(X,{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(pt,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Mi,{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 Ui({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(null),[h,g]=l.useState([]),[b,y]=l.useState(typeof window<"u"?window.location.origin:""),[f,j]=l.useState(null),[C,w]=l.useState(""),[S,P]=l.useState("member"),[k,B]=l.useState(null),[v,A]=l.useState(!1),[I,_]=l.useState(!1),[D,Q]=l.useState(null),H=l.useCallback(async()=>{_(!0),Q(null);try{const[R,Y,re,pe,xe]=await Promise.all([U("/api/config"),U("/api/auth/sessions").catch(()=>({sessions:[]})),U("/api/usage?groupBy=user").catch(()=>({groups:[]})),U("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(oe=>oe.ok?oe.json():null).catch(()=>null)]),le={admins:Array.isArray(R?.signIn?.admins)?R.signIn.admins:[],members:Array.isArray(R?.signIn?.members)?R.signIn.members:[]},$=ai(R);u($),p(le);const ne=Array.isArray(Y?.sessions)?Y.sessions:[],fe=Array.isArray(re?.groups)?re.groups:[];g($.authority==="portal"?Um(ne,fe):zm(le,ne,fe)),typeof pe?.publicUrl=="string"&&pe.publicUrl&&y(pe.publicUrl),j(xe?.capabilities?.emailSignIn===!0?!0:xe?!1:null)}catch(R){Q(R instanceof Error?R.message:String(R))}finally{_(!1)}},[]);l.useEffect(()=>{ni().then(R=>{d(R),lt(R)&&H()})},[H]);const N=async R=>{A(!0),Q(null);try{await U("/api/config",{method:"PUT",body:JSON.stringify({signIn:R})}),await H()}catch(Y){Q(Y instanceof Error?Y.message:String(Y))}finally{A(!1)}},Z=async()=>{if(c(!0),!x||v)return;const R=Om(C);if(!R){Q(t("remote.signInAccess.invalid"));return}await N(Un(x,R,S)),w(""),B(Dn(b,R))};if(!lt(o))return null;const te=m?.authority==="portal"?e.jsx(Fm,{peopleUrl:m.peopleUrl,people:h}):null,T=e.jsxs(e.Fragment,{children:[f===!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(m?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:R=>{R.preventDefault(),Z()},children:[e.jsx("input",{value:C,onChange:R=>w(R.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:v,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(de,{value:S,onChange:R=>P(R.target.value),"aria-label":t("people.colRole"),disabled:v,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:v||!C.trim(),className:"ui-button ui-button-primary",children:[v?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{H()},disabled:I||v,"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(we,{size:13,className:M(I&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),k&&e.jsx(zi,{link:k}),D&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:D}),e.jsx("div",{className:"mt-4",children:e.jsx(Mi,{people:h,busy:v,onRole:(R,Y)=>{x&&N(Un(x,R.entry,Y))},onRemove:R=>{x&&N(Mm(x,R.entry))},onLink:R=>B(Dn(b,R.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(St,{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:te??T})]}):te??e.jsx(X,{title:t("people.title"),subtitle:t("people.subtitle"),children:T})}const ss="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 _m({entry:s}){const[n,a]=l.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(ws())}),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:ud(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:md(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:zl(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(Rs,{size:12,className:M("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:wn(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:wn(s.after?.[r])})]},r))]})]})]})})}function Di(){const[s,n]=l.useState({who:"",what:"all",from:"",to:""}),[a,i]=l.useState([]),[r,c]=l.useState(0),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=cd(s),g=l.useCallback(async()=>{u(!0),p(null);try{const y=await U(`/api/admin-activity${h}`);i(y.entries),c(y.total),d(y.retentionDays)}catch(y){p(y instanceof Error?y.message:String(y))}finally{u(!1)}},[h]);l.useEffect(()=>{const y=window.setTimeout(()=>{g()},250);return()=>window.clearTimeout(y)},[g]);const b=y=>n(f=>({...f,...y}));return e.jsxs(X,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(o??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:y=>b({who:y.target.value}),placeholder:t("activity.whoPlaceholder"),className:M(ss,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(de,{value:s.what,onChange:y=>b({what:y.target.value}),children:dd.map(y=>e.jsx("option",{value:y,children:t(`activity.what.${y}`)},y))})]}),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:y=>b({from:y.target.value}),className:ss})]}),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:y=>b({to:y.target.value}),className:ss})]}),e.jsx("button",{type:"button",onClick:()=>{g()},disabled:m,"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:m?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(we,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${h}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Ye,{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&&!m&&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((y,f)=>e.jsx(_m,{entry:y},`${y.at}-${f}`))}),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 Fn=4,_s="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",$s="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",$m=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),Fi=(s,n)=>Lt(s)===n||Fa(Bt(s),n)!=="none",_i=(s,n)=>{const a=Ua(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},_n=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function Km(){const{state:s}=G(),n=Ul(),a=Dl(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[m,u]=l.useState(null),[x,p]=l.useState(null),h=l.useRef(null),[g,b]=l.useState(null),[y,f]=l.useState(""),j=l.useCallback(()=>b(null),[]);if(l.useEffect(()=>{x||!h.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(v=>v.dataset.accessPerson===h.current)?.focus(),h.current=null)},[x]),!n||!a)return null;const C=n.people.filter(v=>v.role==="member").sort((v,A)=>v.name.localeCompare(A.name)),w=$m(s.bots),S=m?w.find(v=>v.id===m):void 0,P=x?C.find(v=>v.email===x):void 0,k=o.trim().toLowerCase(),B=async(v,A,I)=>{f("");const _=Bt(v);try{await dn(v.id,A),b({botId:v.id,before:_,after:A,text:I})}catch(D){f(D instanceof Error?D.message:String(D))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[P?e.jsx(Vm,{person:P,bots:w.filter(v=>Fi(v,P.email)),team:n,teamName:a,apply:B,onBack:()=>{h.current=P.email,p(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(mt,{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:o,"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:v=>d(v.target.value),onKeyDown:v=>{v.key==="Escape"&&o&&(v.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(v=>e.jsx("button",{type:"button","aria-pressed":r===v,"data-access-listing":v,onClick:()=>{c(v),d("")},className:M("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===v?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(v==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},v))})]}),r==="bot"?e.jsx(Hm,{bots:w.filter(v=>!k||_n(k,v.name,Ua(v,n)?.name,Lt(v)??void 0)),anyBots:w.length>0,team:n,onOpen:u}):e.jsx(Gm,{people:C.filter(v=>!k||_n(k,v.name,v.email)),anyPeople:C.length>0,bots:w,onOpen:p}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),y&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:y}),S&&e.jsx(Fl,{bot:S,teamName:a,onClose:()=>u(null),onChanged:v=>b({botId:S.id,...v})}),g&&e.jsx(_l,{text:g.text,onUndo:()=>dn(g.botId,g.before),onDone:j},`${g.botId}:${g.text}:${JSON.stringify(g.after)}`)]})}function Hm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:$s,children:s.map(r=>{const c=Bt(r),o=Lt(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:M(_s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Mt,{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:_i(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(Wm,{entries:Object.keys(c.people).filter(d=>d!==o),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 Wm({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>Kl(r,n)).join(", "),i=s.length-Fn;return e.jsxs("span",{role:"img","aria-label":a,title:a,"data-access-stack":s.length,className:"flex shrink-0 -space-x-0.5 rtl:space-x-reverse",children:[s.slice(0,Fn).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(Hl,{person:Wl(r,n),size:22})},r)),i>0&&e.jsxs("span",{className:"flex h-[22px] min-w-[22px] items-center justify-center rounded-full bg-card px-1 text-[11px] font-medium text-ink-secondary ring-2 ring-card",children:["+",i]})]})}function Gm({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:$s,children:s.map(r=>{const c=a.filter(o=>Fi(o,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:M(_s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Da,{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 Vm({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(Br,{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(Da,{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:$s,children:n.map(o=>e.jsx(qm,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function qm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=Bt(s),o=Lt(s)===n.email,d=c.people[n.email],m=Fa(c,n.email);return e.jsxs("li",{className:_s,"data-access-person-bot":s.id,children:[e.jsx(Mt,{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&&!o&&m===c.everyone?t("botAccess.everyoneUse",{team:i}):_i(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:o?e.jsx("span",{className:"px-2",children:t("lookedAfter.badge")}):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,$l(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})]})}function Jm(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 Ym({domain:s,serverIpv4:n}){const a=Jm(s);if(!a)return e.jsx("p",{className:"text-[12px] 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:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([r,c])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(it,{command:c,copyLabel:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Xm(s){return`bots.example.com {
2
2
  handle /hooks/* {
3
3
  reverse_proxy 127.0.0.1:${s.webhookPort}
4
4
  }
@@ -7,7 +7,7 @@ import{c as ut,r as l,j as e,t,a as M,S as mt,f as ge,p as ks,g as js,a8 as Lr,X
7
7
  flush_interval -1
8
8
  }
9
9
  }
10
- }`}function Xm({status:s}){return e.jsxs("details",{className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:t("settings.domain.guide")}),e.jsxs("ol",{className:"mt-3 list-decimal space-y-3 pl-4 leading-relaxed",children:[e.jsx("li",{children:t("settings.domain.dns")}),e.jsxs("li",{children:[t("settings.domain.proxy"),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-md bg-app p-3 text-[11px] leading-relaxed text-ink",children:e.jsx("code",{children:Ym(s)})}),e.jsx("p",{className:"mt-2",children:t("settings.domain.proxyHint")})]}),e.jsx("li",{children:t("settings.domain.verifyHint")})]}),e.jsx("p",{className:"mt-3 text-warning",children:t("settings.domain.loopbackWarning")}),!s.serverIpv4&&e.jsx("p",{className:"mt-3",children:t("settings.domain.ipAdminHint")}),e.jsx("p",{className:"mt-3",children:t("settings.domain.scope")}),e.jsxs("a",{className:"mt-3 inline-flex items-center gap-1.5 text-accent hover:underline",href:"https://github.com/leomieo/limix-bot/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings",target:"_blank",rel:"noopener noreferrer",children:[t("settings.domain.fullGuide")," ",e.jsx(pt,{size:12})]})]})}function Qm(){const[s,n]=l.useState(null),[a,i]=l.useState(""),[r,c]=l.useState("loading"),[o,d]=l.useState(null),[m,u]=l.useState(null);l.useEffect(()=>{const x=new AbortController;return D("/api/settings/custom-domain",{signal:x.signal}).then(h=>{x.signal.aborted||(n(h),i(h.customDomain??""))}).catch(h=>{x.signal.aborted||d(h instanceof Error?h.message:t("settings.domain.failed"))}).finally(()=>{x.signal.aborted||c(null)}),()=>x.abort()},[]);const p=async x=>{c(x?"removing":"saving"),d(null),u(null);try{const h=await D("/api/settings/custom-domain",{method:x?"DELETE":"POST",...x?{}:{body:JSON.stringify({domain:a.trim()})}});n(h),i(h.customDomain??""),u(x?t("settings.domain.removed"):t("settings.domain.saved"))}catch(h){d(h instanceof Error?h.message:t("settings.domain.failed"))}finally{c(null)}};return e.jsx(Q,{title:t("settings.domain.title"),subtitle:t("settings.domain.subtitle"),children:e.jsxs("div",{className:"space-y-3","data-custom-domain-settings":!0,children:[r==="loading"&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("settings.domain.loading")]}),s&&!s.supported&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:x=>{x.preventDefault(),a.trim()&&!r&&p(!1)},className:"space-y-2",children:[e.jsx("label",{htmlFor:"custom-domain",className:"block text-[13px] font-medium text-ink",children:t("settings.domain.label")}),e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:r!==null,onChange:x=>{i(x.target.value),u(null),d(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx(Jm,{domain:a,serverIpv4:s.serverIpv4}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.httpsNeeded")}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs("button",{type:"submit",disabled:!a.trim()||r!==null,className:"ui-button ui-button-primary",children:[r==="saving"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Gl,{size:14}),r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{p(!0)},className:"rounded-lg bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:r==="removing"?t("settings.domain.removing"):t("settings.domain.remove")})]})]}),s.publicUrl&&e.jsxs("p",{className:"break-all text-[12px] text-ink-secondary",children:[t("settings.domain.current"),": ",e.jsx("span",{className:"text-ink",children:s.publicUrl})]}),s.customDomain&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")}),e.jsx(Xm,{status:s})]}),m&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(ge,{size:14,className:"mt-0.5 shrink-0"}),m]}),o&&e.jsx("p",{role:"alert",className:"text-[12px] leading-relaxed text-danger",children:o})]})})}const Zm=Vl,xs="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",hs="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function $i({onSubmit:s,onCancel:n,pending:a,error:i,submitLabel:r,children:c,form:o}){return e.jsxs("form",{onSubmit:s,className:"flex flex-col gap-2.5","aria-busy":a,[`data-${o}`]:"",children:[c,e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Bt,{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(J,{size:13,className:"animate-spin"}),r]})]})]})}function $n({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=l.useState(s?.name??""),[o,d]=l.useState(""),[m,u]=l.useState(s?.bots??"all"),[p,x]=l.useState(!1),[h,g]=l.useState(null),b=async y=>{if(y.preventDefault(),!p){x(!0),g(null);try{s?await ql(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:o,bots:m}):await Jl(r.trim(),o,m),d(""),await i()}catch(f){g(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{x(!1)}}};return e.jsxs($i,{form:"secret-form",onSubmit:y=>{b(y)},onCancel:a,pending:p,error:h,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:hs,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:Zm,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:y=>c(y.target.value),disabled:p,className:xs}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:hs,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:o,placeholder:"••••••••",onChange:y=>d(y.target.value),disabled:p,className:xs})]}),e.jsx(dt,{value:m,onChange:u,bots:n,disabled:p})]})}function ep({bots:s,onCancel:n,onSaved:a}){const[i,r]=l.useState(""),[c,o]=l.useState("all"),[d,m]=l.useState(!1),[u,p]=l.useState(null),[x,h]=l.useState(null),g=async b=>{if(b.preventDefault(),d)return;const y=Yl(i);if(!y.length){p(t("settings.vault.env.none"));return}m(!0),p(null),h(null);try{h(await Xl(y,c)),r("")}catch(f){p(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{m(!1),await a().catch(()=>{})}};return e.jsxs($i,{form:"env-form",onSubmit:b=>{g(b)},onCancel:n,pending:d,error:u,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:hs,children:[t("settings.vault.env.label"),e.jsx("textarea",{name:"envText",rows:5,autoComplete:"off",spellCheck:!1,autoFocus:!0,value:i,onChange:b=>r(b.target.value),disabled:d,placeholder:"STRIPE_SECRET_KEY=…",dir:"ltr",className:`${xs} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(dt,{value:c,onChange:o,bots:s,disabled:d}),x!==null&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("settings.vault.env.done",{count:String(x)})})]})}const Kn={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",linked:"settings.logins.source.1password"},gs="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",tp=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function sp(s,n,a,i){const r=i.trim().toLowerCase();return[...a==="secrets"?[]:s.map(o=>({kind:"login",key:[o.site,o.username,...o.hosts].join(" "),login:o})),...a==="logins"?[]:n.map(o=>({kind:"secret",key:o.name,secret:o}))].filter(o=>!r||o.key.toLowerCase().includes(r)).sort((o,d)=>o.key.localeCompare(d.key))}function Ki(){const{state:s,dispatch:n}=V(),a=It(),i=s.bots.map(E=>({id:E.id,name:E.name})),[r,c]=l.useState(null),[o,d]=l.useState([]),[m,u]=l.useState({connected:!1}),[p,x]=l.useState(null),[h,g]=l.useState(""),[b,y]=l.useState("all"),[f,j]=l.useState(!1),[C,w]=l.useState(null),[S,I]=l.useState(""),[k,B]=l.useState("all"),[v,A]=l.useState(!1),[P,_]=l.useState(null),[U,X]=l.useState("all"),[H,N]=l.useState(!1),[Z,te]=l.useState(!1),[R,T]=l.useState(null),[Y,re]=l.useState(!1),[pe,xe]=l.useState([]),le=async()=>{try{const E=await eo();c(E.logins??[]),d(E.secrets??[]),u(E.onePassword??{connected:!1}),x(null)}catch(E){x(E instanceof Error&&E.message?E.message:t("settings.vault.loadError"))}};if(l.useEffect(()=>{a&&le()},[a]),a===!1)return e.jsx(Q,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const $=E=>{if(E==="all")return t("settings.logins.allBots");const W=E.flatMap(de=>i.find(q=>q.id===de)?.name??[]);return W.length?W.join(", "):t("settings.logins.noBots")},ne=E=>E?t("settings.logins.used",{when:nd(E)}):t("settings.logins.neverUsed"),fe=(E,W)=>{w(null),T(null),te(!1),W&&(X(W.bots),N(W.exactHost)),_(E)},oe=E=>{j(!1),_(null),T(null),w(E)},se=async(E,W)=>{if(R!==E){T(E);return}re(!0),xe([]);try{W==="login"?await ao(E):xe(await io(E)),T(null),await le()}catch(de){x(de instanceof Error&&de.message?de.message:t("settings.logins.deleteError"))}finally{re(!1)}},ie=(E,W,de,q)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx("button",{type:"button",className:gs,disabled:Y,onClick:q,"aria-label":W==="login"?t("settings.logins.changeFor",{site:de}):t("settings.vault.secret.changeFor",{name:de}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:gs,disabled:Y,onClick:()=>{se(E,W)},"aria-label":R===E?t("settings.logins.deleteConfirm"):W==="login"?t("settings.logins.deleteFor",{site:de}):t("settings.vault.secret.deleteFor",{name:de}),children:[e.jsx(Se,{size:13}),R===E?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),be=sp(r??[],o,b,h),K=r!==null&&r.length===0&&o.length===0,ae=E=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":E.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Bt,{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:E.site,children:E.site}),E.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(to,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:E.username||t("settings.logins.noUsername")}),Hn(E)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:Hn(E)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Kn[E.source]),$(E.bots),ne(E.lastUsedAt)].join(" · ")}),un(E,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:$(un(E,s.bots))})})]}),E.source!=="1password"&&ie(E.id,"login",E.site,()=>fe(E.id,E))]}),P===E.id&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(dn,{username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>_(null),onSubmit:async W=>{await so(E.id,{password:W.password,totp:W.totp,removeTotp:Z,bots:U,...H===E.exactHost?{}:{exactHost:H}}),_(null),await le()},children:[E.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:Z,onChange:W=>te(W.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(Wn,{checked:H,onChange:N,label:t("settings.logins.exactHostFor",{hosts:E.hosts.join(", "),site:E.site})}),e.jsx(dt,{value:U,onChange:X,bots:i})]})})]},E.id),L=E=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":E.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(_a,{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:E.name,children:E.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Kn[E.source]),$(E.bots),ne(E.lastUsedAt)].join(" · ")})]}),E.source!=="linked"&&ie(E.id,"secret",E.name,()=>fe(E.id))]}),P===E.id&&E.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx($n,{secret:E,bots:i,onCancel:()=>_(null),onSaved:async()=>{_(null),await le()}})})]},E.id);return e.jsx(Q,{title:t("settings.vault.title"),subtitle:t("settings.vault.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3","aria-busy":r===null||Y,"data-vault":!0,children:[s.config?.cloudHome===!0&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary","data-logins-cloud-own":!0,children:t("settings.logins.cloudOwn")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex h-8 min-w-[12rem] flex-1 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-vault-search":!0,type:"text",value:h,onChange:E=>g(E.target.value),autoComplete:"off",spellCheck:!1,placeholder:t("settings.vault.search"),"aria-label":t("settings.vault.search"),className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",className:"ui-button ui-button-md",disabled:r===null,"aria-expanded":f,onClick:()=>j(!f),onKeyDown:E=>{E.key==="Escape"&&j(!1)},children:[e.jsx(Ce,{size:14}),t("settings.vault.add"),e.jsx(Na,{size:13,"aria-hidden":"true"})]}),f&&e.jsx("div",{className:"absolute end-0 top-full z-10 mt-1 flex min-w-[11rem] flex-col rounded-lg border border-hairline/60 bg-menu p-1 shadow-lg","data-vault-add":!0,children:tp.map(([E,W])=>e.jsx("button",{type:"button",className:"rounded-md px-2.5 py-1.5 text-start text-[13px] text-ink hover:bg-control",onClick:()=>oe(E),children:t(W)},E))})]})]}),e.jsx(Ql,{label:t("settings.vault.filter"),attr:"data-vault-filter",value:b,onChange:y,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")}]}),C==="login"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsxs(dn,{site:{value:S,onChange:I},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>w(null),onSubmit:async E=>{await Zl(S,E,k,v),w(null),I(""),B("all"),A(!1),await le()},children:[e.jsx(Wn,{checked:v,onChange:A,label:t("settings.logins.exactHost")}),e.jsx(dt,{value:k,onChange:B,bots:i})]})}),C==="secret"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx($n,{bots:i,onCancel:()=>w(null),onSaved:async()=>{w(null),await le()}})}),C==="env"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(ep,{bots:i,onCancel:()=>w(null),onSaved:le})}),r===null&&!p&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.vault.loading")}),K&&!C&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.vault.empty")}),!K&&r!==null&&be.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary","data-vault-none":!0,children:t("settings.vault.noMatch")}),be.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/30","data-logins-list":!0,children:be.map(E=>E.kind==="login"?ae(E.login):L(E.secret))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-tertiary",children:t("settings.logins.limits")}),pe.length>0&&e.jsx("p",{role:"status",className:"text-[12px] leading-relaxed text-warning","data-vault-keys-off":!0,children:t("settings.vault.secret.keyOff",{servers:pe.join(", ")})}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline/30 pt-3","data-vault-keys":!0,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.vault.keys.title")}),e.jsx("div",{className:"text-[12px] leading-snug text-ink-tertiary",children:t("settings.vault.keys.hint")})]}),e.jsx("button",{type:"button",className:"ui-button ui-button-md shrink-0",onClick:()=>n({type:"toggleAppSettings",open:!0,section:"connections"}),children:t("keys.row.open")})]}),e.jsx(ap,{status:m,disabled:r===null,bots:i,botNames:$,onChange:async E=>{u(E),await le()}})]})})}function Hn(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 Wn({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 np({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,o]=l.useState(!1),[d,m]=l.useState(s.bots),[u,p]=l.useState(!1),[x,h]=l.useState(null),g=async()=>{p(!0),h(null);try{await r(await ro(s.id,d)),o(!1)}catch(b){h(b instanceof Error&&b.message?b.message:t("settings.logins.onePassword.error"))}finally{p(!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:gs,disabled:i||u,onClick:()=>{m(s.bots),o(!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(dt,{value:d,onChange:m,bots:n,disabled:u}),x&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:x}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:u,onClick:()=>o(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:u,onClick:()=>{g()},children:t("settings.logins.saveChange")})]})]})]})}function ap({status:s,disabled:n,bots:a,botNames:i,onChange:r}){const[c,o]=l.useState(""),[d,m]=l.useState(null),[u,p]=l.useState(null),x=async(g,b)=>{if(!d){m(g),p(null);try{await r(await b()),g==="connect"&&o("")}catch(y){p(y instanceof Error&&y.message?y.message:t("settings.logins.onePassword.error"))}finally{m(null)}}},h=g=>{g.preventDefault(),c.trim()&&x("connect",()=>no(c.trim()))};return e.jsxs("section",{className:"mt-1 flex flex-col gap-2 border-t border-hairline/30 pt-3","aria-label":t("settings.vault.manager"),"data-onepassword":!0,children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.vault.manager")}),e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:t("settings.logins.onePassword.title")}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-snug text-ink-secondary",children:t("settings.logins.onePassword.connected",{vaults:(s.vaults??[]).map(g=>g.title).join(", ")||"—",count:String(s.items??0)})}),s.error&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:s.error}),!!s.vaults?.length&&e.jsx("ul",{className:"divide-y divide-hairline/30","aria-label":t("settings.logins.onePassword.vaults"),children:s.vaults.map(g=>e.jsx(np,{vault:g,bots:a,botNames:i,disabled:n,onChange:r},g.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",className:"ui-button ui-button-md",disabled:n||d!==null,onClick:()=>{x("refresh",lo)},children:[d==="refresh"?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(we,{size:13}),t("settings.logins.onePassword.refresh")]}),e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:n||d!==null,onClick:()=>{x("disconnect",oo)},children:t("settings.logins.onePassword.disconnect")})]})]}):e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:h,children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.logins.onePassword.guide")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{name:"onePasswordToken",type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:c,onChange:g=>o(g.target.value),disabled:n||d!==null,"aria-label":t("settings.logins.onePassword.token"),placeholder:t("settings.logins.onePassword.token"),className:"min-w-0 flex-1 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"}),e.jsxs("button",{type:"submit",className:"ui-button ui-button-md ui-button-primary",disabled:n||d!==null||!c.trim(),children:[d==="connect"&&e.jsx(J,{size:13,className:"animate-spin"}),t("settings.logins.onePassword.connect")]})]})]}),e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Bt,{size:11,"aria-hidden":"true",className:"mt-[3px] shrink-0"})," ",t("settings.logins.onePassword.note")]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u})]})}const ss="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 Gn(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function ip(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=Or(n);return a.ok&&(a.code!==null||a.credential!==null)}function rp({hideWhenUnavailable:s=!1,legacyOnly:n=!1}){const a=window.ogb?.remoteClient,i=window.ogb?.environments,[r,c]=l.useState({active:a?.active===!0}),[o,d]=l.useState(i?"server":"companion"),[m,u]=l.useState(""),[p,x]=l.useState(""),[h,g]=l.useState(""),[b,y]=l.useState(!1),[f,j]=l.useState(""),C=l.useRef(!1),w=!!i&&o==="server",S=l.useRef(!0),I=l.useCallback(()=>{a?.state().then(v=>{S.current&&c(v)}).catch(()=>{})},[a]);l.useEffect(()=>(S.current=!0,I(),()=>{S.current=!1}),[I]);const k=async()=>{if(!(C.current||!a&&!i)){C.current=!0,y(!0),j("");try{if(w&&i){if(!ip(m))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(m.trim()),I()}else a&&(await a.pair(p,h),I())}catch(v){j(Gn(v))}finally{C.current=!1,y(!1)}}},B=async()=>{if(!(!a||C.current)){C.current=!0,y(!0),j("");try{await a.disconnect(),I()}catch(v){j(Gn(v))}finally{C.current=!1,y(!1)}}};return!a&&!i&&s||n&&!r.active?null:e.jsxs(Q,{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(wt,{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:b,onClick:()=>{B()},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:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Ld,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:v=>{v.preventDefault(),k()},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(me,{value:o,disabled:b,onChange:v=>{d(v.target.value),j("")},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 limixbot 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 limixbot 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:m,onChange:v=>u(v.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:b,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:ss})]}),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:p,onChange:v=>x(v.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:b,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:ss})]}),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:h,onChange:v=>g(v.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:b,inputMode:"numeric",autoComplete:"one-time-code",className:`${ss} max-w-40 font-mono tracking-[0.2em]`})]})]}),f?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:f}):null,e.jsxs("button",{type:"submit",disabled:b||(w?!m.trim():p.trim()===""||h.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:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(wt,{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&&f?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:f}):null]})}const lp={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 op({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(Ns())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(lp[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 cp({workspace:s,own:n=!1,onClose:a}){const{state:i}=V(),c=n||$a(i.config)?window.ogb?.computerSharing:void 0,[o,d]=l.useState(null),[m,u]=l.useState([]),[p,x]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(!1),[f,j]=l.useState(""),[C,w]=l.useState(null),S=l.useRef(!1),I=l.useRef(!1),k=l.useRef(null),B=A=>{d(A),u(A.folders),x(A.terminal),g(A.computer)};l.useEffect(()=>{S.current=!0,k.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(_=>{S.current&&B(_)}).catch(()=>{S.current&&j(t("computerSharing.loadFailed"))});const A=()=>{c?.state(s.id).then(_=>{S.current&&d(_)}).catch(()=>{}),c?.activity?.(s.id).then(_=>{S.current&&w(_)}).catch(()=>{})};A();const P=setInterval(A,3e3);return()=>{S.current=!1,clearInterval(P)}},[c,s.id]);const v=async A=>{if(!I.current){I.current=!0,y(!0),j("");try{await A()}catch(P){S.current&&j(String(P?.message??P).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{I.current=!1,S.current&&y(!1)}}};return c?e.jsx("div",{ref:k,children:e.jsx(Q,{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:o?o.enabled?o.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(_e,{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&&o?.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(o.paused?"computerSharing.paused":"computerSharing.pauseHint")}),e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{await(o.paused?c.resume?.():c.pause?.());const A=await c.state(s.id);S.current&&d(A)})},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(o.paused?"computerSharing.resume":"computerSharing.pause")})]}),e.jsxs("fieldset",{disabled:b||!o,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:t("computerSharing.folders")}),m.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.noFolders")}),m.map(A=>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:A.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:A.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:A.write,onChange:P=>u(_=>_.map(U=>U.id===A.id?{...U,write:P.target.checked}:U))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:A.name}),onClick:()=>u(P=>P.filter(_=>_.id!==A.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(_e,{size:14})})]},A.id)),e.jsxs("button",{type:"button",disabled:m.length>=20,onClick:()=>{v(async()=>{const A=await c.chooseFolder();S.current&&A&&u(P=>P.some(_=>_.path===A.path)?P:[...P,A])})},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(co,{size:14}),t("computerSharing.chooseFolder")]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.smallFiles")})]}),e.jsxs("fieldset",{disabled:b||!o,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:p,onChange:A=>x(A.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:h,onChange:A=>g(A.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")})]})]})]}),(f||o?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:f||o?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:b||!o||!m.length&&!p&&!h,onClick:()=>{v(async()=>{const A=await c.save(s.id,{folders:m,terminal:p,computer:h});S.current&&A&&B(A)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:t(o?.enabled?"computerSharing.save":"computerSharing.share")}),o?.enabled&&e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{const A=await c.revoke(s.id);S.current&&B(A)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:t("computerSharing.stop")})]}),o?.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(op,{entries:C})})]})})}):null}const dp={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},vt=s=>s.kind!=="local"&&!!s.origin&&!s.home&&!s.cloud&&!("team"in s&&s.team),up=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function mp(s,n){return s==="docker"?"git pull && ./update.sh":s==="global"?`npm install -g openmausbot@${n}`:s==="source"?"git pull && pnpm install":`npx openmausbot@${n} serve`}function pp({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=Ps(mp(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(_e,{size:13})})]})}function xp({origin:s,name:n}){const{state:a,copy:i}=Ps(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(ge,{size:14}):e.jsx(Za,{size:14})})}function hp({status:s,onTryNow:n,onPairAgain:a,onEdit:i}){if(!s||s.state==="connected")return null;const r=(d,m)=>e.jsx("button",{type:"button",onClick:m,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:up(s.since)}):s.state==="signedOut"?t("servers.state.signedOut"):t("servers.state.insecure"),o=s.state==="signedOut"||s.state==="insecure";return e.jsxs("div",{"data-server-state":s.state,className:o||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 gp({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(ue,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function fp({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:o,onComputerAccess:d,onShare:m=()=>{}}){const u=window.ogb?.environments,[p,x]=l.useState([]),[h,g]=l.useState([]),[b,y]=l.useState(null);l.useEffect(()=>{if(!u?.status)return;let S=!0;const I=()=>{u.status().then(B=>{S&&x(B)}).catch(()=>{})};I();const k=u.onStatus?.(I);return()=>{S=!1,k?.()}},[u,s]);const f=S=>p.find(I=>I.id===S),j=S=>y({address:S.origin,locked:!0,title:t("servers.pairAgainTitle",{name:S.name})}),C=S=>y({address:S.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),w=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(S=>S.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:w.map(S=>{const I=S.id===s.activeId,k=vt(S)?f(S.id):void 0,B=S.id==="local"?wt:js,v=S.id==="local"?t("servers.localHint"):vt(S)?`${new URL(S.origin).host} · ${t(dp[Mr(S.origin)])}`:S.home?t("servers.managed"):new URL(S.origin).host,A=i.find(_=>_.id===S.id),P=k?.behind===!0&&r!==null&&!h.includes(`${S.id}:${k.version}`);return e.jsxs("li",{"data-server-row":S.id,className:"py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[zr(S.color)?e.jsx(Ur,{color:S.color,size:20}):e.jsx(B,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:S.name}),e.jsx("div",{"data-server-where":!0,className:"break-all text-[12px] text-ink-secondary",children:v}),e.jsx(hp,{status:k,onTryNow:()=>{u?.retry?.(S.id)},onPairAgain:()=>j(S),onEdit:()=>C(S)})]}),I?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{size:13}),t("servers.current")]}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:S.name}),onClick:()=>c(S.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.switch")}),vt(S)&&k?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>j(S),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.pairAgain")}),S.id!=="local"&&!S.home&&!S.cloud&&!A&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:S.name}),onClick:()=>d(S.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("servers.computerAccess")}),vt(S)&&e.jsx(xp,{origin:S.origin,name:S.name}),S.id!=="local"&&!S.home&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.removeName",{name:S.name}),title:t("servers.removeName",{name:S.name}),onClick:()=>o(S.id),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]}),A&&e.jsx(gp,{name:S.name,share:A,busy:n,onShare:_=>m(S.id,_),onOpen:()=>d(S.id)}),P&&e.jsx(pp,{name:S.name,status:k,appVersion:r,onHide:()=>g(_=>[..._,`${S.id}:${k.version}`])})]},S.id)})}),e.jsxs("button",{type:"button","data-server-connect":!0,disabled:n,onClick:()=>y({address:"",locked:!1,title:t("connect.title")}),className:"mt-3 flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[e.jsx(Ce,{size:14}),t("connect.title")]}),b&&e.jsx(_c,{focusKey:b.locked?"pair-again":"connect",onClose:()=>y(null),children:e.jsx($c,{onBack:null,onConnected:()=>y(null),start:b})})]})}function Vn(){const s=window.ogb?.environments,{state:n}=V(),a=$a(n.config)&&!!window.ogb?.computerSharing,i=window.ogb?.computerSharing,[r,c]=l.useState([]),[o,d]=l.useState(null),[m,u]=l.useState(!1),[p,x]=l.useState(""),[h,g]=l.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[b,y]=l.useState(""),[f,j]=l.useState(""),[C,w]=l.useState(null),[S,I]=l.useState(!1),[k,B]=l.useState(""),v=l.useRef(!1),A=l.useRef(0);l.useEffect(()=>{const R=++A.current;return s?.state().then(T=>{A.current===R&&d(T)}).catch(()=>{A.current===R&&x(t("servers.loadFailed"))}),()=>{A.current++}},[s]),l.useEffect(()=>{if(!i?.servers||!o)return;let R=!0;const T=()=>{i.servers().then(re=>{R&&c(re)}).catch(()=>{})};T();const Y=setInterval(T,5e3);return()=>{R=!1,clearInterval(Y)}},[i,o]);const P=(R,T)=>{_(async()=>{T?await i?.allow?.(R)&&g(R):await i?.revoke(R),i?.servers&&c(await i.servers())})};l.useEffect(()=>{const R=T=>{T&&g(T);const Y=new URL(window.location.href);Y.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${Y.pathname}${Y.search}${Y.hash}`)};return R(),s?.onOpenSettings?.(R)},[s]);const _=async(R,T=x)=>{if(v.current||!s)return;v.current=!0,u(!0),x(""),B("");const Y=A.current;try{if(await R()===!0)return;const re=await s.state();A.current===Y&&d(re)}catch(re){A.current===Y&&T(String(re?.message??re).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{v.current=!1,A.current===Y&&u(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const U=R=>window.ogb?.confirm?window.ogb.confirm(R):window.confirm(R),X=o?.environments.find(R=>R.id===h),H=X?.origin&&!X.home?{id:X.id,name:X.name,origin:X.origin}:void 0,N=!!(H&&r.some(R=>R.id===H.id)),Z=o?.environments.filter(R=>R.kind==="local")??[],te=Z.find(R=>R.id===C);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("servers.intro")}),o?.packaged&&e.jsxs(Q,{title:t("connectedWorkspaces.localTitle"),subtitle:t("connectedWorkspaces.localSubtitle"),children:[k&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:k}),Z.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:Z.map(R=>{const T=R.id===o.activeId;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(wt,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:R.name}),e.jsxs("div",{className:"break-all text-[12px] text-ink-secondary",children:[R.dataDir,R.missing&&e.jsx("span",{className:"ml-2 rounded-md bg-inset px-1.5 py-0.5 text-[11px]",children:t("connectedWorkspaces.missing")})]})]}),T?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{size:13}),t("connectedWorkspaces.current")]}):e.jsx("button",{type:"button",disabled:m,"aria-label":t("connectedWorkspaces.switchTo",{name:R.name}),onClick:()=>{_(async()=>{if(!await U(t("connectedWorkspaces.switchConfirm",{name:R.name})))return;const Y=await s.switch(R.id);if(Y&&Y.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},B)},className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.switch")}),!T&&e.jsx("button",{type:"button",disabled:m,"aria-label":t("connectedWorkspaces.forgetName",{name:R.name}),title:t("connectedWorkspaces.forgetName",{name:R.name}),onClick:()=>{w(R.id),I(!1)},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]},R.id)})}),te&&e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 p-3",children:[e.jsxs("label",{className:"flex items-start gap-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:S,disabled:m,className:"mt-0.5",onChange:R=>I(R.target.checked)}),t("connectedWorkspaces.forgetPurge",{path:te.dataDir??""})]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",disabled:m,onClick:()=>{_(async()=>{const R=S?await s.forget(te.id,!0):await s.forget(te.id);if(R&&R.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));w(null)},B)},className:"rounded-lg px-3 py-1.5 text-[12px] font-medium text-danger hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.forget")}),e.jsx("button",{type:"button",onClick:()=>w(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink hover:bg-control",children:t("connectedWorkspaces.cancel")})]})]}),e.jsx("p",{className:"mt-4 text-[13px] font-medium text-ink",children:t("connectedWorkspaces.newEnvironment")}),e.jsxs("form",{className:"flex flex-col gap-3 pt-2",onSubmit:R=>{R.preventDefault(),b.trim()&&_(async()=>{if(!(await s.create(b.trim(),f.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));y(""),j("")},B)},children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.name"),e.jsx("input",{required:!0,value:b,disabled:m,maxLength:60,onChange:R=>y(R.target.value),placeholder:t("connectedWorkspaces.environmentPlaceholder"),className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.dataFolder"),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("input",{value:f,disabled:m,onChange:R=>j(R.target.value),placeholder:t("connectedWorkspaces.defaultFolder"),className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"}),e.jsx("button",{type:"button",disabled:m,onClick:()=>{_(async()=>{const R=await s.pickDir();R?.ok&&R.path&&j(R.path)},B)},className:"shrink-0 rounded-lg border border-hairline/40 px-3 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.choose")})]})]}),e.jsxs("button",{type:"submit",disabled:m||!b.trim(),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[m&&e.jsx(J,{size:14,className:"animate-spin"}),t("connectedWorkspaces.create")]})]})]}),e.jsxs(Q,{title:t("servers.yours.title"),subtitle:t("servers.yours.subtitle"),children:[o?e.jsx(fp,{saved:o,busy:m,sharingOffered:a,ownServers:r,appVersion:window.ogb?.app?.version??null,onShare:P,onSwitch:R=>{_(async()=>(await s.switch(R),!0))},onForget:R=>{_(()=>s.forget(R))},onComputerAccess:g}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t(p?"servers.yours.loadFailed":"servers.yours.loading")}),o&&p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]}),(a||N)&&H&&e.jsx(cp,{workspace:H,own:N,onClose:()=>g(null)},H.id)]})}const bp={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function yp({banner:s,canChange:n,subtitle:a}){const i=l.useRef(null),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=uo(s),u=async h=>{c(!0),d(null);const g=await Promise.resolve().then(h).catch(()=>({ok:!1,problem:"failed"}));c(!1),g.ok||d(bp[g.problem])},p=h=>{i.current&&(i.current.value=""),!(!h||!n)&&u(async()=>{const g=await po(h);return g.ok?xo(g.blob):g})},x=o?e.jsx("p",{role:"alert",className:"text-danger",children:t(o)}):n?null:e.jsx("p",{className:"text-ink-secondary",children:t("placeLook.imageAdmins")});return e.jsx("div",{"data-place-picture":m?"set":"none",children:e.jsx(ce,{title:t("placeLook.sidebarPicture"),subtitle:a,message:x,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[m&&e.jsx("img",{src:m,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(m?"placeLook.changeImage":"placeLook.useImage")}),m&&e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>{u(ho)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:mo,hidden:!0,"data-place-picture-input":!0,onChange:h=>p(h.target.files?.[0])})]})})})}function Hi(){const s=go(),{state:n}=V(),a=It()===!0,i=window.ogb?.app?.ownPage===!0,[r,c]=l.useState(null),[o,d]=l.useState(null),m=s?.change===null,u=x=>{!s||m||r||x===s.swatch||(c(x),d(null),fo(x).then(h=>{c(null),d(h)}))},p=s?.reason==="member"||o==="refused"?t("placeLook.member"):s?.reason==="signed-out"?t("placeLook.signedOut"):o==="unsupported"?t("placeLook.unsupported"):null;return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{"data-place-look":s.change??"locked",children:e.jsx(ce,{title:t("placeLook.sidebarColor"),subtitle:i?t("placeLook.sidebarColorSub"):t("placeLook.sub",{name:s.name}),message:o==="failed"?e.jsx("p",{role:"alert",className:"text-danger",children:t("placeLook.failed")}):p&&e.jsx("p",{className:"text-ink-secondary",children:p}),children:e.jsx(Kc,{value:r??s.swatch,onChange:u,label:i?t("placeLook.sidebarColor"):t("placeLook.aria",{name:s.name}),disabled:m,offset:"menu",none:!0})})}),e.jsx(yp,{banner:n.config?.workspaceBanner??null,canChange:a,subtitle:t(i?"placeLook.sidebarPictureSub":"placeLook.sharedPictureSub")})]})}function vp(){return e.jsx("div",{"data-sidebar-look":!0,"data-settings-look":"simple",className:Ka,children:e.jsx(ve,{children:e.jsx(Hi,{})})})}function Wi(){const{capabilities:s}=ei(),n=typeof window>"u"?void 0:window.ogb?.windowFrame,[a,i]=l.useState(null);l.useEffect(()=>{if(!n)return;let d=!0;return n.state().then(m=>{d&&i(m)}).catch(()=>{}),()=>{d=!1}},[n]);const r=s.host?.platform;if(!n||!a||r!=="darwin"&&r!=="win32")return null;const c=window.ogb?.relaunch,o=()=>{n.set(!a.on).then(i).catch(()=>{})};return e.jsxs("div",{"data-window-frame-switch":!0,children:[e.jsx(ce,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(ue,{checked:a.on,"aria-label":t("settings.windowFrame.title"),onClick:o})}),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:ks()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}function Gi(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function kp(s,n){return s.find(a=>Gi(a)&&a.instanceId.endsWith(`.${n}`))}function $s(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function qn(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return $s(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function jp(s,n){const a=n.filter(o=>Gi(o)&&$s(o)),i=a.find(o=>o.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const r={target:i,bots:[],needsAsk:[]},c=o=>n.find(d=>d.instanceId===o)?.driverKind;for(const o of s){if(o.hidden)continue;const d=bo(o);if(qn(o.modelSelection,n)||qn(d.modelSelection,n))continue;([o,d].some(u=>yo(vo(u),c(u.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(o)}return r}const Np={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function wp({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=V(),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=jp(n.bots,n.instances),u=m.target,p=h=>h.map(g=>g.name).join(", "),x=async()=>{if(!u||!m.bots.length||r)return;const h=m.bots,g={instanceId:u.instanceId,model:u.models.default};c(!0),d(null);for(const b of h)a({type:"setModel",botId:b.id,selection:g});try{const b=await Promise.all(h.map(f=>i(f.id).catch(()=>null))),y=h.filter((f,j)=>b[j]?.modelSelection.instanceId===g.instanceId);y.length&&d({name:u.displayName,bots:y.map(f=>f.name)})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(h=>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:Np[h.id]??h.id}),e.jsx("span",{className:"text-ink-secondary",children:h.configured?t("organization.modelCount",{count:h.models.length}):t("organization.notConfigured")})]}),h.configured&&h.models.length>0&&e.jsx(Sp,{instance:kp(n.instances,h.id),instances:n.instances})]},h.id))}),o&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:o.name,names:o.bots.join(", ")})}),u&&m.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:p(m.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{x()},children:m.bots.length===1?t("organization.useCompanyOne",{name:u.displayName}):t("organization.useCompanyMany",{name:u.displayName,count:m.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),u&&m.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:p(m.needsAsk)})})]})}function Sp({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($s(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{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&&ko(a)?e.jsx(Pt,{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 Cp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},Jn="https://admin.limixbot.com",Yn={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 Ep(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(Yn,a))?s.message:n.map(a=>t(Yn[a])).join(" ")}function Vi(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[n,a]=l.useState(null),[i,r]=l.useState(""),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,p]=l.useState(!1),x=l.useRef(!1),h=l.useRef(0),g=l.useRef(0),b=l.useRef(void 0),y=k=>{const B=b.current!==k.status;b.current=k.status,a(k),B&&m(""),k.status!=="connected"&&k.status!=="reauth-required"&&p(!1)};l.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const k=++h.current,B=g.current,v=P=>{h.current===k&&(g.current++,y(P))},A=s?.onState(v);return s?.state().then(P=>{g.current===B&&v(P)}).catch(()=>{h.current===k&&g.current===B&&m(t("organization.loadFailed"))}),()=>{h.current++,A?.()}},[s]);const f=async k=>{if(!s||x.current)return;x.current=!0,o(!0),m("");const B=h.current,v=g.current;try{const A=await k();h.current===B&&g.current===v&&y(A)}catch{h.current===B&&g.current===v&&m(t("organization.actionFailed"))}finally{x.current=!1,h.current===B&&o(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const j=n?.status==="connected"||n?.status==="reauth-required"||n?.status==="unavailable"||n?.status==="license-expired",C=n?.status==="license-expired"||n?.notice==="license-expired",w=n?.enrollment?.expiresAt??n?.expiresAt,S=typeof w=="number"&&Number.isFinite(w)?new Date(w):null,I=S&&Number.isFinite(S.getTime())?new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(S):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.additive")}),e.jsxs(Q,{title:t("settings.section.organization"),subtitle:t("organization.privacy"),children:[!n&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:d||t("organization.loading")}),n?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:Ep(n)}),C&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),n?.status==="signed-out"&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.signInHelp")}),e.jsx("button",{type:"button",disabled:c,onClick:()=>{f(()=>s.begin({portalOrigin:Jn}))},className:"w-fit rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:c?t("organization.working"):t("organization.signIn")}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.advanced")}),e.jsxs("form",{className:"mt-2 flex flex-col gap-2",onSubmit:k=>{k.preventDefault(),i.trim()&&f(()=>s.begin({portalOrigin:i.trim()}))},children:[e.jsx("p",{children:t("organization.advancedHelp")}),e.jsxs("label",{className:"flex flex-col gap-1.5",children:[t("organization.address"),e.jsx("input",{type:"url",required:!0,value:i,disabled:c,onChange:k=>r(k.target.value),placeholder:Jn,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"ui-button w-fit",children:t("organization.customSignIn")})]})]})]}),n?.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")}),n.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:n.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.enrollment&&s.reopen&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[n.branding?.logo&&e.jsx("img",{src:n.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:n.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:n.email})]}),n.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):n.status==="license-expired"?e.jsx(e.Fragment,{children:n.providers?.some(k=>k.configured&&k.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:n.providers.filter(k=>k.configured&&k.models.length>0).map(k=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:Cp[k.id]??k.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},k.id))})}):n.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),n.providers?.some(k=>k.configured&&k.models.length>0)?e.jsx(wp,{providers:n.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,u?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:c,className:"ui-button",onClick:()=>p(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button text-danger",onClick:()=>{f(()=>s.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>p(!0),children:t("organization.disconnect")})]})]}),n?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),I&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:I})}),d&&n&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:d}),!n&&e.jsx("button",{type:"button",disabled:c,className:"ui-button mt-3",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")})]})]})}const Ap="https://cal.com/milind-soni-002qed/30min",Ip=["feature","price","setup","broken","later","other"],Pp={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},Xn=2e3,fs=s=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium"}).format(new Date(s)),Rp=s=>s.endsAt??s.renewsAt;function qi(s){const n=Rp(s);return s.trial?n?t("cloudCancel.endedTrial",{date:fs(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:fs(n)}):t("cloudCancel.endedPlanNoDate")}function Tp(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 Lp(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:fs(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function Ji({renewal:s,actions:n,onChanged:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,m]=l.useState(null);if(!s||!n)return null;const u=()=>{o(!0),m(null),n.keep().then(p=>{p.outcome==="kept"?a?.():m(p.outcome==="browser"?"browser":"failed")},()=>m("failed")).finally(()=>o(!1))};return e.jsxs(e.Fragment,{children:[s.cancelled?e.jsxs("div",{"data-cloud-cancel":"cancelled",className:"flex flex-col items-start gap-2 self-start",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink",children:qi(s)}),e.jsx("button",{type:"button",className:"ui-button",disabled:c,onClick:u,children:t(c?"cloudCancel.keeping":"cloudCancel.keep")}),d&&e.jsx("p",{role:d==="failed"?"alert":"status",className:M("text-[13px]",d==="failed"?"text-danger":"text-ink-secondary"),children:t(d==="failed"?"cloudCancel.failed":"cloudCancel.browser")})]}):e.jsx("button",{type:"button","data-cloud-cancel":"renewing",className:"ui-button self-start",onClick:()=>{m(null),r(s)},children:t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan")}),i&&e.jsx(Bp,{renewal:i,actions:n,onClose:p=>{r(null),p&&a?.()}})]})}function Bp({renewal:s,actions:n,onClose:a}){const[i,r]=l.useState(null),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,p]=l.useState({step:"ask"}),[x,h]=l.useState(!1),[g,b]=l.useState(!1),y=l.useRef(!1),f=l.useRef(null),j=()=>{x||a(y.current)};l.useEffect(()=>{const v=document.activeElement instanceof HTMLElement?document.activeElement:null;return f.current?.querySelector("button[aria-pressed]")?.focus(),()=>{v?.isConnected&&v.focus()}},[]);const C=v=>{h(!0),b(!1),v().catch(()=>b(!0)).finally(()=>h(!1))},w=()=>C(async()=>{const v=i!==null||c.trim()!==""||d.trim()!=="",A=await n.cancel(v?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);A.outcome==="cancelled"?(y.current=!0,p({step:"done",renewal:A.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:A.surveyed})):A.outcome==="browser"?p({step:"browser"}):b(!0)}),S=()=>C(async()=>{const v=await n.keep();v.outcome==="kept"?(y.current=!0,a(!0)):v.outcome==="browser"?p({step:"browser"}):b(!0)}),I=t(s.trial?"cloudCancel.titleTrial":"cloudCancel.titlePlan"),k="mt-1.5 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-60",B=g&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return Hc.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:v=>v.stopPropagation(),children:e.jsxs("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":x,tabIndex:-1,"data-cloud-cancel-sheet":u.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:v=>{if(v.key==="Escape"&&(v.stopPropagation(),j()),v.key==="Tab"){const A=f.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!A?.length)return;const P=A[0],_=A[A.length-1];v.shiftKey&&document.activeElement===P?(v.preventDefault(),_.focus()):!v.shiftKey&&document.activeElement===_&&(v.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:I}),e.jsx("button",{type:"button","aria-label":t("cloudCancel.close"),disabled:x,onClick:j,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(_e,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[u.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Lp(s)}),e.jsxs("fieldset",{className:"mt-4",disabled:x,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:Ip.map(v=>e.jsx("button",{type:"button","aria-pressed":i===v,onClick:()=>r(A=>A===v?null:v),className:M("ui-button ui-button-pill",i===v&&"border-accent bg-accent/10 font-medium"),children:t(Pp[v])},v))})]}),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:Xn,value:c,disabled:x,onChange:v=>o(v.target.value),className:k})]}),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:Xn,value:d,disabled:x,onChange:v=>m(v.target.value),className:k})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:Ap,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),B,e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:x,onClick:j,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:x,onClick:w,children:t(x?"cloudCancel.cancelling":s.trial?"cloudCancel.confirmTrial":"cloudCancel.confirmPlan")})]})]}),u.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:qi(u.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:Tp(u.renewal)}),u.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),B,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:x,onClick:S,children:t(x?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:x,onClick:j,children:t("cloudCancel.done")})]})]}),u.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:j,children:t("cloudCancel.done")})})]})]})]})}),document.body)}function Qn({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(Op,{bridge:s,read:n,write:a}):null}function Op({bridge:s,read:n,write:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,p]=l.useState(null);if(l.useEffect(()=>{let g=!0;const b=()=>{n().then(f=>{g&&r(f)}).catch(()=>{})};b();const y=s.onNotice(b);return()=>{g=!1,y()}},[s,n]),!i?.shown)return null;const x=g=>{o(!1),m(!0),p(null),a(g).then(b=>r(b),b=>p(Dr(b)??t("cloudAccount.keepHere.failed"))).finally(()=>m(!1))},h=()=>{i.on?x(!1):i.moved?o(!0):x(!0)};return e.jsxs("div",{"data-cloud-keep":i.coming?"coming":i.on?"on":"off",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:t("cloudAccount.keepHere.title")}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("cloudAccount.keepHere.line")})]}),e.jsx(ue,{checked:i.on||i.coming,disabled:d||i.coming,"aria-label":t("cloudAccount.keepHere.title"),onClick:h})]}),i.coming&&e.jsx("p",{role:"status",className:"mt-3 text-[13px] text-ink-secondary",children:t("cloudAccount.keepHere.coming")}),c&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.keepHere.confirmTitle"),className:"mt-3 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:t("cloudAccount.keepHere.confirmTitle")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.keepHere.confirm")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button",onClick:()=>o(!1),children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>x(!0),children:t("cloudAccount.keepHere.bringBack")})]})]}),u&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u})]})}function Mp({label:s,suggest:n,className:a="ui-button"}){const{dispatch:i}=V();return e.jsx("button",{type:"button",className:a,onClick:()=>i({type:"showFiles",...n?{suggest:n}:{}}),children:s})}const zp={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},Yi=s=>new Intl.DateTimeFormat(Oe(),{timeStyle:"short"}).format(new Date(s)),Up=s=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium"}).format(new Date(s));function Xi(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:qr(n)})]})}function Zn({machine:s,busy:n,failed:a,onConnect:i,trial:r=!1,waking:c=!1,moving:o=null,team:d=null}){const m=s.status==="ready"?s.unreachable:void 0,u=s.status==="ready"&&!m,p=m?t(m.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):o??(c&&u?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:Yi(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(zp[s.status]));return e.jsx(Q,{title:d?d.name??t("cloudHome.team.title"):t("cloudHome.title"),children:e.jsxs("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-unreachable":m?.cause,"data-cloud-waking":c&&u?!0:void 0,"data-cloud-moving":o&&!m?!0:void 0,className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:u?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:p}),s.status==="provisioning"&&s.setup&&e.jsx(rd,{step:s.setup.step}),u&&e.jsxs(e.Fragment,{children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:d?.name?t("cloudBuy.setup.open",{name:d.name}):t("cloudHome.connect")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudHome.connectHelp")})]}),!d&&wo()&&e.jsx(Mp,{label:t("cloudHome.filesLink"),className:"text-[13px] font-medium text-accent-text underline underline-offset-2 hover:text-ink"})]}),a&&!m&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudHome.connectFailed")})]})})}function Dp({ready:s,busy:n,failed:a,onUse:i}){return e.jsx(Q,{title:t("cloudPhone.title"),subtitle:t("cloudPhone.subtitle"),children:e.jsxs("div",{"data-cloud-phone":s?"open":"steps",className:"flex flex-col items-start gap-3",children:[s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudPhone.action")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudPhone.help")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudPhone.failed")}),(!s||a)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(s?"cloudPhone.stepsIntro":"cloudPhone.notReady")}),e.jsxs("ol",{className:"list-decimal ps-5 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("li",{children:t("cloudPhone.step1")}),e.jsx("li",{children:t("cloudPhone.step2")})]})]})]})})}function Fp(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 _p={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function $p(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(_p[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:Up(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 Kp(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 Hp({bridge:s,onConnectPhone:n}){const[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(0);l.useEffect(()=>{let y=!0;return s.state().then(f=>{y&&i(f)}).catch(()=>{y&&d(!0)}),()=>{y=!1}},[s,m]);const p=s.cancel&&s.keep?{cancel:y=>s.cancel(y),keep:()=>s.keep()}:null;if(o)return e.jsx(Q,{title:t("settings.section.cloudAccount"),children:e.jsx("p",{"data-cloud-plan":"elsewhere",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudNone")})});const x=Gr(a?.tier),h=a?.home===!0,g=a?.status==="paid"?t(Vr(a.trial)?"cloudAccount.trialPlan":"cloudAccount.pro",{plan:x}):a?.status==="attention"?t("cloudAccount.inactive",{plan:a.tier?x:"Limix Bot Cloud"}):a?.status==="checking"?t("cloudAccount.lastPlan",{plan:x}):a?.status==="signin"?a.tier?t("cloudAccount.planName",{plan:x}):null:a?t(h?"cloudAccount.onCloudNoneHome":"cloudAccount.onCloudNone"):null,b=y=>{c(!1),y().catch(()=>c(!0))};return e.jsx(Q,{title:t("settings.section.cloudAccount"),subtitle:t(h?"cloudAccount.onCloudHome":"cloudAccount.onCloud"),children:e.jsxs("div",{"data-cloud-plan":a?.status??"loading",className:"flex flex-col items-start gap-3",children:[g?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:g}):!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),a?.status==="signin"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudSignIn")}),Xi(a?.trial,a?.credit),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a?.status==="signin"&&s.signIn&&e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>b(()=>s.signIn()),children:t("cloudAccount.signInAgain")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>b(()=>s.manage()),children:a?.trial&&!a.renewal?.cancelled&&ws(a.trial).action?.label||t("cloudAccount.manageInBrowser")}),a&&n&&e.jsx("button",{type:"button",className:"ui-button",onClick:n,children:t("cloudPhone.action")}),e.jsx(No,{})]}),a?.renewal&&e.jsx(Ji,{renewal:a.renewal,actions:p,onChanged:()=>u(y=>y+1)}),r&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function Wp({team:s}){return e.jsx(Q,{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("cloudAccount.teamPeopleBody",{team:s.name})}),s.cloudPage&&e.jsx("a",{className:"ui-button",href:s.cloudPage,target:"_blank",rel:"noreferrer",children:t("cloudAccount.teamPeopleOpen")})]})})}function Gp({linkRequest:s=0,cloudHome:n=!1,teamHome:a,onConnectPhone:i,onAddCloud:r,onSignIn:c}={}){const o=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:d}=ei().capabilities.host,[m,u]=l.useState(null),[p,x]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(!1),[f,j]=l.useState(!1),[C,w]=l.useState(!1),[S,I]=l.useState(!1),k=l.useRef(0),B=l.useRef(0),v=l.useRef(!1),A=l.useRef({request:0,arrived:!1,connected:!1});l.useEffect(()=>{const se=++k.current,ie=B.current,be=ae=>{k.current===se&&(B.current++,u(ae),g(!1),ae.status==="signed-out"&&y(!1))},K=o?.onState(be);return o?.state().then(ae=>{B.current===ie&&be(ae)}).catch(()=>{k.current===se&&B.current===ie&&g(!0)}),()=>{k.current++,K?.()}},[o]);const P=async se=>{if(!o||v.current)return;v.current=!0,x(!0),g(!1);const ie=k.current,be=B.current;try{const K=await se();k.current===ie&&B.current===be&&u(K)}catch{k.current===ie&&B.current===be&&g(!0)}finally{v.current=!1,k.current===ie&&x(!1)}},_=()=>{o&&(w(!1),P(async()=>{try{return await o.connectHome()}catch{return w(!0),o.state()}}))},U=se=>{o?.openTeam&&(w(!1),P(async()=>{try{await o.openTeam(se)}catch{w(!0)}return o.state()}))},X=()=>{o&&(I(!1),P(async()=>{try{return await o.connectHomeForPhone()}catch{return I(!0),o.state()}}))};l.useEffect(()=>{if(s||(A.current.request=0),!o||!s||!m||v.current||(A.current.request!==s&&(A.current={request:s,arrived:!0,connected:!1}),m.status==="signed-out"&&m.message==="restoring"))return;const se=Fp(m,A.current);A.current.arrived=!1,se==="sign-in"&&P(()=>o.begin()),se==="connect"&&(A.current.connected=!0,_())},[o,s,m,p]);const[H]=jo(o?window.ogb?.cloudSendPage:void 0),N=H?.move?Fr(H.move,"local"):null,Z=N&&N.kind!=="done"?N.text:null,te=yd(!!m&&Qs(Zs(m)),m?.offer),R=o?.cancelPlan&&o.keepPlan?{cancel:se=>o.cancelPlan(se),keep:()=>o.keepPlan()}:null;if(!o){const se=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return e.jsxs(e.Fragment,{children:[n&&a?e.jsx(Wp,{team:a}):se?e.jsx(Hp,{bridge:se,onConnectPhone:i}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")}),se&&!a&&e.jsx(Qn,{bridge:window.ogb?.cloudSendPage})]})}const T=Zs(m),Y=m&&["connected","unavailable","reauth-required"].includes(m.status),re=$p(m,T,d),pe=_r(T),xe=$r(m),le=Kr(m),$=T.kind==="paid"?{status:"provisioning"}:void 0,ne=xe?le?.machine??$:m?.status==="connected"?m.machine??$:void 0,fe=m?.status==="connecting"?m.enrollment:void 0;Hr(te);const oe=r&&Qs();return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.optional")}),e.jsxs(Q,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.separate"),children:[m?.staging&&e.jsx(Wr,{className:"mb-3"}),(!m||T.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),re&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:re}),(T.kind==="signed-out"||T.kind==="removed")&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[oe,e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>c?c():void P(()=>o.begin()),children:t("cloudAccount.signIn")})]}),m?.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("cloudAccount.browser")}),fe&&e.jsxs("div",{"data-cloud-code":!0,className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.codeCheck")}),e.jsx("code",{dir:"ltr",className:"select-all text-[18px] font-semibold tracking-widest text-ink",children:fe.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:Yi(fe.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{P(()=>o.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{P(()=>o.cancel())},children:t("organization.cancel")})]})]}),Y&&e.jsxs("div",{className:"flex flex-col gap-3",children:[m.account&&e.jsx("p",{className:"break-all text-[14px] text-ink",children:m.account.email}),pe&&e.jsxs("p",{role:"status","data-cloud-plan":T.kind,className:"text-[15px] font-medium text-ink",children:[pe,T.kind==="paid"&&T.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),m.status==="connected"&&Xi(m.trial,m.credit),T.kind==="free"&&oe,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[T.kind==="reauth"?e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{P(()=>o.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[!(T.kind==="free"&&oe)&&e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{P(()=>o.openDashboard())},children:T.kind==="free"?t("cloudAccount.dashboard"):Kp(m,T)}),e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{P(()=>o.refresh())},children:t("organization.refresh")})]}),!b&&e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>y(!0),children:t("cloudAccount.signOut")})]}),m.status==="connected"&&m.renewal&&e.jsx(Ji,{renewal:m.renewal,actions:R}),T.kind==="free"&&!b&&e.jsxs("p",{className:"text-[12px] text-ink-secondary",children:[t(window.ogb?.accounts?"cloudAccount.otherEmailOrTeam":"cloudAccount.otherEmail")," ",e.jsx("button",{type:"button","data-cloud-other-email":!0,disabled:p,className:"underline hover:text-ink",onClick:()=>window.ogb?.accounts?j(!0):y(!0),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),f&&e.jsx(Wc,{adding:"",onClose:()=>j(!1)}),b&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.signoutTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.signoutHelp")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:p,className:"ui-button",onClick:()=>y(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:p,className:"ui-button text-danger",onClick:()=>{P(()=>o.signOut())},children:t("cloudAccount.signOut")})]})]})]}),h&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!m&&e.jsx("button",{type:"button",disabled:p,className:"ui-button mt-3",onClick:()=>{P(()=>o.state())},children:t("organization.refresh")})]}),ne&&Zn(xe?{machine:ne,busy:p,failed:C,onConnect:()=>{le&&U(le.id)},team:{name:le?.name??null}}:{machine:ne,busy:p,failed:C,onConnect:_,trial:!!m?.trial,waking:m?.waking===!0,moving:Z}),Y&&T.kind==="paid"&&!xe&&Dp({ready:ne?.status==="ready",busy:p,failed:S,onUse:X}),e.jsx(Qn,{bridge:window.ogb?.cloudSendPage})]})}function ea(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Oe(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function Qi(s){return t("planUsage.spendAmounts",{used:ea(s.usedMinor,s.currency,s.exponent),limit:ea(s.limitMinor,s.currency,s.exponent)})}function Zi(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),o=i%60;return r>0?c>0?`${r}d ${c}h`:`${r}d`:c>0?o>0?`${c}h ${o}m`:`${c}h`:`${o}m`}function Vp(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(o=>o.resetsAt),...(r.models??[]).flatMap(o=>o.windows.map(d=>d.resetsAt))];for(const o of c){if(!o||a.has(o)||i.includes(o))continue;const d=Date.parse(o);Number.isFinite(d)&&d<=n&&i.push(o)}}return i}function qp(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function ta(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function Et(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 Jp(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:Et({name:a[1]})}):n}function kt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?Zi(n.resetsAt,a):null,o=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,o))),children:e.jsx("div",{className:M("h-full rounded-full",qp(o)),style:{width:`${Math.min(100,Math.max(0,o))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function er(){const[s,n]=l.useState(null),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(()=>Date.now()),m=l.useRef(new Set),u=l.useCallback(async(p=!1)=>{i(!0),c("");try{const x=await D(p?"/api/plan-usage?refresh=1":"/api/plan-usage");n(x),d(Date.now())}catch(x){c(x instanceof Error&&x.message?x.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return l.useEffect(()=>{u(!1)},[u]),l.useEffect(()=>{const p=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(p)},[]),l.useEffect(()=>{if(!s)return;const p=Vp(s,o,m.current);if(p.length!==0){for(const x of p)m.current.add(x);u(!0)}},[s,o,u]),{report:s,loading:a,error:r,now:o,load:u}}function Yp(s){for(const n of s?.providers??[]){const a=n.ok&&!n.weekly.available?n.extra.find(i=>i.label==="Monthly spend"):void 0;if(a)return{provider:n,budget:a}}return null}function Xp(s){let n=null;for(const a of s?.providers??[]){const i=a.ok&&a.weekly.available?a.weekly.usedPercent:null;i!==null&&(!n||i>n.used)&&(n={provider:a,used:i})}return n}function Qp(){const{report:s,now:n}=er();if(!s)return null;const a=Xp(s),i=a?null:Yp(s);if(i){const d=Et(i.provider),m=Math.round(Math.min(100,Math.max(0,i.budget.usedPercent)));return e.jsx(mn,{kind:"plan",title:t("settings.simple.billing.monthlySpend",{provider:d}),percent:m,label:`${d}: ${t("planUsage.used",{used:m})}`,note:i.budget.spend?Qi(i.budget.spend):null})}if(!a)return e.jsx("section",{"data-usage-summary":"own-ai",className:M(za,"px-4 py-3.5 text-[14px] leading-5 text-ink-secondary"),children:t("settings.simple.billing.ownAi")});const r=Math.round(Math.min(100,Math.max(0,a.used))),c=Zi(a.provider.weekly.resetsAt,n),o=Et(a.provider);return e.jsx(mn,{kind:"plan",title:t("settings.simple.billing.weekly",{provider:o}),percent:r,label:`${o}: ${t("planUsage.used",{used:r})}`,note:c?t("planUsage.resetsIn",{when:c}):null})}function Zp(){const{report:s,loading:n,error:a,now:i,load:r}=er();return e.jsxs(Q,{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(J,{size:14,className:"animate-spin"}):e.jsx(we,{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(c=>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:Et(c)}),c.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:c.plan})]}),c.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(kt,{label:t("planUsage.fiveHour"),window:c.fiveHour,now:i}),e.jsx(kt,{label:t("planUsage.weekly"),window:c.weekly,now:i}),c.extra.map((o,d)=>e.jsx(kt,{label:ta(o.label),now:i,usedHeadline:!!o.spend,detail:o.spend?Qi(o.spend):void 0,window:{available:!0,remainingPercent:o.remainingPercent,usedPercent:o.usedPercent,resetsAt:o.resetsAt}},`${o.label}-${d}`)),(c.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")}),(c.models??[]).map(o=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:o.name}),o.windows.map((d,m)=>e.jsx(kt,{label:ta(d.label),now:i,usedHeadline:!0,window:{available:!0,remainingPercent:d.remainingPercent,usedPercent:d.usedPercent,resetsAt:d.resetsAt}},`${o.name}-${d.label}-${m}`))]},o.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:Jp(c)})]},c.id))})]})}function sa(s,n){return s?.edition?.features?.includes(n)===!0}function ex(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function tx({budget:s}){const{state:n,dispatch:a}=V(),i=n.config?.budgets??{},[r,c]=l.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[o,d]=l.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[m,u]=l.useState(!1),[p,x]=l.useState(null);l.useEffect(()=>{c(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),d(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const h=async()=>{if(m)return;const b=r.trim()===""?0:Number(r),y=Number(o);if(!Number.isFinite(b)||b<0||!Number.isInteger(y)||y<1||y>100){x(t("usage.budget.invalid"));return}u(!0),x(null);try{const f=await D("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:b,warnAtPercent:y}})});a({type:"configStatus",config:f})}catch(f){x(f instanceof Error?f.message:String(f))}finally{u(!1)}},g=ex(s);return e.jsxs(Q,{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:M(g==="danger"?"text-danger":g==="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:ct(s.spentUsd),cap:ct(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:M("h-full rounded-full",g==="danger"?"bg-danger":g==="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:b=>{b.preventDefault(),h()},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:b=>c(b.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:m,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:o,onChange:b=>d(b.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:m,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:m,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:[m&&e.jsx(J,{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")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}function na(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 sx(){const{state:s,dispatch:n}=V(),a=s.config?.billing,[i,r]=l.useState(a?.currency??"USD"),[c,o]=l.useState(na(a?.prices)),[d,m]=l.useState(!1),[u,p]=l.useState(null);l.useEffect(()=>{r(a?.currency??"USD"),o(na(a?.prices))},[a]);const x=(b,y)=>o(f=>f.map((j,C)=>C===b?{...j,...y}:j)),h=async()=>{if(d)return;const b={};for(const y of c){const f=y.key.trim();if(!f)continue;const j=Number(y.input),C=Number(y.output),w=y.cached.trim()===""?void 0:Number(y.cached);if(!Number.isFinite(j)||!Number.isFinite(C)||j<0||C<0||w!==void 0&&(!Number.isFinite(w)||w<0)){p(t("usage.prices.invalid",{model:f}));return}b[f]={inputPerMillion:j,outputPerMillion:C,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){p(t("usage.prices.currencyInvalid"));return}m(!0),p(null);try{const y=await D("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:b}})});n({type:"configStatus",config:y})}catch(y){p(y instanceof Error?y.message:String(y))}finally{m(!1)}},g="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(Q,{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:b=>r(b.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((b,y)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:b.key,onChange:f=>x(y,{key:f.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:M(g,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:b.input,onChange:f=>x(y,{input:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:g}),e.jsx("input",{value:b.output,onChange:f=>x(y,{output:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:g}),e.jsx("input",{value:b.cached,onChange:f=>x(y,{cached:f.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:g}),e.jsx("button",{type:"button",onClick:()=>o(f=>f.filter((j,C)=>C!==y)),"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(Se,{size:13})})]},y))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>o(b=>[...b,{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(Ce,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{h()},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(J,{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")}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function nx({budget:s}){const{state:n}=V(),a=sa(n.config,"budgets"),i=sa(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(tx,{budget:s}),i&&e.jsx(sx,{})]})}const ax=["model","user","department","day","engine","routine"],aa={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"},ix={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},rx=2e3;function lx(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 ia(s,n,a){const[i,r]=l.useState(null);return l.useEffect(()=>{let c=!0;return D(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}`).then(o=>{c&&r(o)}).catch(()=>{c&&r(null)}),()=>{c=!1}},[s.from,s.to,n,a]),i}function ra({groupBy:s,groups:n}){const{state:a}=V(),i=[...n].sort((c,o)=>st(o)-st(c)).slice(0,6),r=Math.max(...i.map(st),0);return!i.length||r<=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:i.map(c=>{const o=s==="bot"?a.bots.find(d=>`bot:${d.id}`===c.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(c.turns)}),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2 text-ink",children:[o&&e.jsx(Ot,{bot:o,state:"idle",size:18,animated:!1}),e.jsx("span",{className:"truncate",children:s==="model"?Oo(c.label,a.instances):lx(s,c)})]}),e.jsx("span",{className:"h-2 overflow-hidden rounded-full bg-raised",children:e.jsx("span",{className:"block h-full rounded-full bg-accent/70",style:{width:`${Math.max(2,st(c)/r*100)}%`}})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[Mo(st(c)),ot(c.costUsd)&&c.costUsd>0&&` · ${Ha(c.costUsd)}`]})]},c.key)})})}function ox({range:s,version:n,onBudget:a}){const[i,r]=l.useState("model"),c=ia(s,"bot",n),o=ia(s,i,n);return l.useEffect(()=>{a(c?.budget??null)},[c,a]),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(aa.bot)}),c?e.jsx(ra,{groupBy:"bot",groups:c.groups}):e.jsx(J,{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:ax.map(d=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===d,onClick:()=>r(d),className:M("rounded-md px-2 py-0.5 text-[11px] font-medium uppercase tracking-[0.06em]",i===d?"bg-accent/12 text-accent":"text-ink-secondary hover:bg-raised/60 hover:text-ink"),children:t(aa[d])},d))}),o?.groupBy===i?e.jsx(ra,{groupBy:i,groups:o.groups}):e.jsx(J,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}function cx(s){return new Date(s).toLocaleString(Jr(Oe()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function dx({root:s,onOpen:n}){const{state:a}=V(),i=s.title||t(`trace.source.${s.source}`,{bot:s.bots[0]?.name??""});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((r,c)=>{const o=a.bots.find(d=>d.id===r.id);return o?e.jsx("span",{className:M("rounded-full ring-2 ring-card",c>1&&"hidden sm:block"),children:e.jsx(Ot,{bot:o,state:"idle",size:22,animated:!1})},r.id):e.jsx("span",{className:M("flex size-[22px] items-center justify-center rounded-full bg-raised text-[10px] font-semibold text-ink-secondary ring-2 ring-card",c>1&&"hidden sm:flex"),children:r.name.slice(0,1).toUpperCase()},r.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:[cx(s.startedAt)," · ",s.bots.map(r=>r.name).join(", ")]})]}),e.jsxs("span",{className:"flex items-center gap-3 text-[13px] tabular-nums text-ink-secondary",children:[s.running&&e.jsx(Lo,{}),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:Bo(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:Ha(s.costUsd)}),e.jsx(Rs,{size:14,className:"text-ink-tertiary"})]})]})})}function tr(){const[s,n]=l.useState("month"),a=l.useMemo(()=>So(s),[s]),[i,r]=l.useState(null),[c,o]=l.useState(null),[d,m]=l.useState(0),[u,p]=l.useState(null),[x,h]=l.useState(null),g=l.useRef(null);l.useEffect(()=>{let f=!0;return pn(a).then(j=>{f&&(r(j),o(null))}).catch(j=>{f&&o(j instanceof Error?j.message:String(j))}),()=>{f=!1}},[a,d]),l.useEffect(()=>Co({onFrame:f=>{if(f.kind!=="runtime"||g.current)return;const j=f.event?.type;j!=="turn.started"&&j!=="turn.completed"||(g.current=setTimeout(()=>{g.current=null,m(C=>C+1)},rx))},onMissedFrames:()=>m(f=>f+1)}),[]),l.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]);const b=()=>{i?.next&&pn(a,i.next).then(f=>r(j=>j?{...f,roots:[...j.roots,...f.roots]}:f))},y=i?.roots.some(f=>!f.timed);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(me,{size:"sm",value:s,onChange:f=>{n(f.target.value),h(null)},"aria-label":t("usage.history.period"),children:Eo.map(f=>e.jsx("option",{value:f,children:t(ix[f])},f))}),e.jsxs("a",{href:Ao(a),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(Ye,{size:13}),t("usage.history.export")]})]})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:c}),x?e.jsx(Io,{id:x.id,at:x.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(Po,{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:i?e.jsx(Ro,{items:To(i.totals,t("trace.stat.time"))}):e.jsxs("div",{className:"flex items-center gap-2 p-5 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(ox,{range:a,version:d,onBudget:p}),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")})]}),i&&!i.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:i?.roots.map(f=>e.jsx(dx,{root:f,onOpen:()=>h({id:f.id,at:f.startedAt})},f.id))}),i?.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(Zp,{}),e.jsx(nx,{budget:u})]})}function ux(){const[s,n]=l.useState(null);return l.useEffect(()=>{fetch("/api/limix/bundled-skills").then(a=>a.ok?a.json():{skills:[]}).then(a=>n(a.skills??[])).catch(()=>n([]))},[]),e.jsx(Q,{title:z("Kĩ năng có sẵn của Limix Bot","Skills built into Limix Bot"),subtitle:z("Đi kèm ứng dụng. Kĩ năng gốc luôn bật cho mọi bot; các kĩ năng khác nằm trong kho, thêm cho từng bot ở mục Kĩ Năng (Skills) của bot.","Shipped with the app. Core skills are always on for every bot; the others wait in the store, and you add them to one bot at a time under the bot's Skills page."),children:e.jsx("div",{className:"flex flex-col gap-3",children:s===null?null:s.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:z("Chưa thấy kỹ năng có sẵn nào trong bản cài này.","No built-in skills were found in this install.")}):e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40",children:s.map(a=>e.jsxs("li",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-[13px] text-ink",children:a.id}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:a.core?z("Kĩ năng gốc · mọi bot","Core skill · every bot"):z("Trong kho · thêm cho từng bot","In the store · add per bot")})]}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:a.description}),a.triggerTerms.length>0&&e.jsxs("p",{className:"mt-1 text-[12px] text-ink-tertiary",children:[z("Từ khóa","Keywords"),": ",a.triggerTerms.slice(0,6).join(", "),a.triggerTerms.length>6?"…":""]})]},a.id))})})})}function mx(){const[s,n]=l.useState(!1);return e.jsxs(Q,{title:z("Công cụ cho kỹ năng","Tools for skills"),subtitle:z("Chương trình mà các kỹ năng cần để chạy: Docker, Node.js, ffmpeg, Java, JADX, Ghidra, Agent-Reach… Thiếu gì thì bấm cài.","Programs the skills need to run: Docker, Node.js, ffmpeg, Java, JADX, Ghidra, Agent-Reach… Install whatever is missing."),children:[Wa()?e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"inline-flex w-fit items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover",children:[e.jsx(zo,{size:14}),z("Xem và cài công cụ còn thiếu","See and install missing tools")]}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:z("Mở mục này trong ứng dụng Limix Bot trên máy tính.","Open this in the Limix Bot desktop app.")}),s&&e.jsx(Ga,{onClose:()=>n(!1)})]})}const at=12,px=[["discover",()=>z("Khám phá","Discover")],["recommended",()=>z("Khuyên dùng","Recommended")],["installed",()=>z("Đã cài","Installed")],["updates",()=>z("Cập nhật","Updates")],["security",()=>z("Bảo mật","Security")],["settings",()=>z("Cài đặt","Settings")]],qe=s=>{const n=new Date(s);return Number.isNaN(n.getTime())?s:n.toLocaleDateString(z("vi-VN","en-US"))},xx=s=>({excellent:z("Xuất sắc","Excellent"),recommended:z("Khuyên dùng","Recommended"),review:z("Cần xem xét","Needs review"),rejected:z("Từ chối","Rejected")})[s],hx=s=>({"instructions-only":z("Chỉ hướng dẫn","Instructions only"),"skill-with-tools":z("Kèm tool/script","With tools/scripts"),"mcp-bundle":z("Kèm MCP","With MCP")})[s],ns=s=>({clean:z("Sạch","Clean"),warning:z("Có cảnh báo","Warnings"),quarantined:z("Cách ly","Quarantined")})[s],Ue="inline-flex items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50";async function Ae(s,n){const a=await fetch(s,n===void 0?void 0:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}),i=await a.json().catch(()=>({}));if(!a.ok)throw new Error(i.error??z(`Lỗi ${a.status}`,`Error ${a.status}`));return i}function gx(){const[s,n]=l.useState(null),[a,i]=l.useState("recommended"),[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(""),[p,x]=l.useState(""),[h,g]=l.useState(!1),[b,y]=l.useState(null),[f,j]=l.useState(null),[C,w]=l.useState(at);l.useEffect(()=>w(at),[a,m,p]);const S=l.useCallback(async()=>{try{n(await Ae("/api/limix/hub"))}catch(N){d(N instanceof Error?N.message:String(N))}},[]);l.useEffect(()=>{S()},[S]);const I=async(N,Z)=>{c(N),d(null);try{await Z(),await S()}catch(te){d(te instanceof Error?te.message:String(te))}finally{c(null)}},k=s?.skills??[],B=l.useMemo(()=>[...new Set(k.map(N=>N.category))].sort(),[k]),v=l.useMemo(()=>{const N=m.trim().toLowerCase();return k.filter(Z=>{if(p&&Z.category!==p||N&&!`${Z.name} ${Z.description} ${Z.description_vi??""} ${Z.tags.join(" ")}`.toLowerCase().includes(N))return!1;switch(a){case"discover":return!0;case"recommended":return!Z.blocked&&!Z.risky&&(Z.grade==="excellent"||Z.grade==="recommended");case"installed":return Z.installed;case"updates":return Z.updateAvailable;case"security":return Z.security_status!=="clean"||!!Z.risky;default:return!1}})},[k,a,m,p]),A=()=>I("sync",()=>Ae("/api/limix/hub/sync",{})),P={excellent:"bg-emerald-500/15 text-emerald-500",recommended:"bg-sky-500/15 text-sky-500",review:"bg-amber-500/15 text-amber-500",rejected:"bg-danger/15 text-danger"},_="rounded-md bg-ink/[0.06] px-1.5 py-0.5 text-[11px] text-ink-secondary",U=N=>{window.confirm(z(`CẢNH BÁO: "${N.name}" bị cách ly vì ${N.risky??"có dấu hiệu nguy hiểm"}
10
+ }`}function Qm({status:s}){return e.jsxs("details",{className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:t("settings.domain.guide")}),e.jsxs("ol",{className:"mt-3 list-decimal space-y-3 pl-4 leading-relaxed",children:[e.jsx("li",{children:t("settings.domain.dns")}),e.jsxs("li",{children:[t("settings.domain.proxy"),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-md bg-app p-3 text-[11px] leading-relaxed text-ink",children:e.jsx("code",{children:Xm(s)})}),e.jsx("p",{className:"mt-2",children:t("settings.domain.proxyHint")})]}),e.jsx("li",{children:t("settings.domain.verifyHint")})]}),e.jsx("p",{className:"mt-3 text-warning",children:t("settings.domain.loopbackWarning")}),!s.serverIpv4&&e.jsx("p",{className:"mt-3",children:t("settings.domain.ipAdminHint")}),e.jsx("p",{className:"mt-3",children:t("settings.domain.scope")}),e.jsxs("a",{className:"mt-3 inline-flex items-center gap-1.5 text-accent hover:underline",href:"https://github.com/leomieo/limix-bot/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings",target:"_blank",rel:"noopener noreferrer",children:[t("settings.domain.fullGuide")," ",e.jsx(pt,{size:12})]})]})}function Zm(){const[s,n]=l.useState(null),[a,i]=l.useState(""),[r,c]=l.useState("loading"),[o,d]=l.useState(null),[m,u]=l.useState(null);l.useEffect(()=>{const p=new AbortController;return U("/api/settings/custom-domain",{signal:p.signal}).then(h=>{p.signal.aborted||(n(h),i(h.customDomain??""))}).catch(h=>{p.signal.aborted||d(h instanceof Error?h.message:t("settings.domain.failed"))}).finally(()=>{p.signal.aborted||c(null)}),()=>p.abort()},[]);const x=async p=>{c(p?"removing":"saving"),d(null),u(null);try{const h=await U("/api/settings/custom-domain",{method:p?"DELETE":"POST",...p?{}:{body:JSON.stringify({domain:a.trim()})}});n(h),i(h.customDomain??""),u(p?t("settings.domain.removed"):t("settings.domain.saved"))}catch(h){d(h instanceof Error?h.message:t("settings.domain.failed"))}finally{c(null)}};return e.jsx(X,{title:t("settings.domain.title"),subtitle:t("settings.domain.subtitle"),children:e.jsxs("div",{className:"space-y-3","data-custom-domain-settings":!0,children:[r==="loading"&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("settings.domain.loading")]}),s&&!s.supported&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:p=>{p.preventDefault(),a.trim()&&!r&&x(!1)},className:"space-y-2",children:[e.jsx("label",{htmlFor:"custom-domain",className:"block text-[13px] font-medium text-ink",children:t("settings.domain.label")}),e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:r!==null,onChange:p=>{i(p.target.value),u(null),d(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx(Ym,{domain:a,serverIpv4:s.serverIpv4}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.httpsNeeded")}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs("button",{type:"submit",disabled:!a.trim()||r!==null,className:"ui-button ui-button-primary",children:[r==="saving"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Gl,{size:14}),r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{x(!0)},className:"rounded-lg bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:r==="removing"?t("settings.domain.removing"):t("settings.domain.remove")})]})]}),s.publicUrl&&e.jsxs("p",{className:"break-all text-[12px] text-ink-secondary",children:[t("settings.domain.current"),": ",e.jsx("span",{className:"text-ink",children:s.publicUrl})]}),s.customDomain&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")}),e.jsx(Qm,{status:s})]}),m&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(ge,{size:14,className:"mt-0.5 shrink-0"}),m]}),o&&e.jsx("p",{role:"alert",className:"text-[12px] leading-relaxed text-danger",children:o})]})})}const ep=Vl,hs="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",gs="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function $i({onSubmit:s,onCancel:n,pending:a,error:i,submitLabel:r,children:c,form:o}){return e.jsxs("form",{onSubmit:s,className:"flex flex-col gap-2.5","aria-busy":a,[`data-${o}`]:"",children:[c,e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Ot,{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(J,{size:13,className:"animate-spin"}),r]})]})]})}function $n({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=l.useState(s?.name??""),[o,d]=l.useState(""),[m,u]=l.useState(s?.bots??"all"),[x,p]=l.useState(!1),[h,g]=l.useState(null),b=async y=>{if(y.preventDefault(),!x){p(!0),g(null);try{s?await ql(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:o,bots:m}):await Jl(r.trim(),o,m),d(""),await i()}catch(f){g(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{p(!1)}}};return e.jsxs($i,{form:"secret-form",onSubmit:y=>{b(y)},onCancel:a,pending:x,error:h,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:gs,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:ep,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:y=>c(y.target.value),disabled:x,className:hs}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:gs,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:o,placeholder:"••••••••",onChange:y=>d(y.target.value),disabled:x,className:hs})]}),e.jsx(dt,{value:m,onChange:u,bots:n,disabled:x})]})}function tp({bots:s,onCancel:n,onSaved:a}){const[i,r]=l.useState(""),[c,o]=l.useState("all"),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),g=async b=>{if(b.preventDefault(),d)return;const y=Yl(i);if(!y.length){x(t("settings.vault.env.none"));return}m(!0),x(null),h(null);try{h(await Xl(y,c)),r("")}catch(f){x(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{m(!1),await a().catch(()=>{})}};return e.jsxs($i,{form:"env-form",onSubmit:b=>{g(b)},onCancel:n,pending:d,error:u,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:gs,children:[t("settings.vault.env.label"),e.jsx("textarea",{name:"envText",rows:5,autoComplete:"off",spellCheck:!1,autoFocus:!0,value:i,onChange:b=>r(b.target.value),disabled:d,placeholder:"STRIPE_SECRET_KEY=…",dir:"ltr",className:`${hs} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(dt,{value:c,onChange:o,bots:s,disabled:d}),p!==null&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("settings.vault.env.done",{count:String(p)})})]})}const Kn={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",linked:"settings.logins.source.1password"},fs="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",sp=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function np(s,n,a,i){const r=i.trim().toLowerCase();return[...a==="secrets"?[]:s.map(o=>({kind:"login",key:[o.site,o.username,...o.hosts].join(" "),login:o})),...a==="logins"?[]:n.map(o=>({kind:"secret",key:o.name,secret:o}))].filter(o=>!r||o.key.toLowerCase().includes(r)).sort((o,d)=>o.key.localeCompare(d.key))}function Ki(){const{state:s,dispatch:n}=G(),a=Pt(),i=s.bots.map(E=>({id:E.id,name:E.name})),[r,c]=l.useState(null),[o,d]=l.useState([]),[m,u]=l.useState({connected:!1}),[x,p]=l.useState(null),[h,g]=l.useState(""),[b,y]=l.useState("all"),[f,j]=l.useState(!1),[C,w]=l.useState(null),[S,P]=l.useState(""),[k,B]=l.useState("all"),[v,A]=l.useState(!1),[I,_]=l.useState(null),[D,Q]=l.useState("all"),[H,N]=l.useState(!1),[Z,te]=l.useState(!1),[T,R]=l.useState(null),[Y,re]=l.useState(!1),[pe,xe]=l.useState([]),le=async()=>{try{const E=await eo();c(E.logins??[]),d(E.secrets??[]),u(E.onePassword??{connected:!1}),p(null)}catch(E){p(E instanceof Error&&E.message?E.message:t("settings.vault.loadError"))}};if(l.useEffect(()=>{a&&le()},[a]),a===!1)return e.jsx(X,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const $=E=>{if(E==="all")return t("settings.logins.allBots");const W=E.flatMap(ue=>i.find(q=>q.id===ue)?.name??[]);return W.length?W.join(", "):t("settings.logins.noBots")},ne=E=>E?t("settings.logins.used",{when:nd(E)}):t("settings.logins.neverUsed"),fe=(E,W)=>{w(null),R(null),te(!1),W&&(Q(W.bots),N(W.exactHost)),_(E)},oe=E=>{j(!1),_(null),R(null),w(E)},se=async(E,W)=>{if(T!==E){R(E);return}re(!0),xe([]);try{W==="login"?await ao(E):xe(await io(E)),R(null),await le()}catch(ue){p(ue instanceof Error&&ue.message?ue.message:t("settings.logins.deleteError"))}finally{re(!1)}},ie=(E,W,ue,q)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx("button",{type:"button",className:fs,disabled:Y,onClick:q,"aria-label":W==="login"?t("settings.logins.changeFor",{site:ue}):t("settings.vault.secret.changeFor",{name:ue}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:fs,disabled:Y,onClick:()=>{se(E,W)},"aria-label":T===E?t("settings.logins.deleteConfirm"):W==="login"?t("settings.logins.deleteFor",{site:ue}):t("settings.vault.secret.deleteFor",{name:ue}),children:[e.jsx(Se,{size:13}),T===E?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),be=np(r??[],o,b,h),K=r!==null&&r.length===0&&o.length===0,ae=E=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":E.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Ot,{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:E.site,children:E.site}),E.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(to,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:E.username||t("settings.logins.noUsername")}),Hn(E)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:Hn(E)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Kn[E.source]),$(E.bots),ne(E.lastUsedAt)].join(" · ")}),mn(E,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:$(mn(E,s.bots))})})]}),E.source!=="1password"&&ie(E.id,"login",E.site,()=>fe(E.id,E))]}),I===E.id&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(un,{username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>_(null),onSubmit:async W=>{await so(E.id,{password:W.password,totp:W.totp,removeTotp:Z,bots:D,...H===E.exactHost?{}:{exactHost:H}}),_(null),await le()},children:[E.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:Z,onChange:W=>te(W.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(Wn,{checked:H,onChange:N,label:t("settings.logins.exactHostFor",{hosts:E.hosts.join(", "),site:E.site})}),e.jsx(dt,{value:D,onChange:Q,bots:i})]})})]},E.id),L=E=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":E.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(_a,{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:E.name,children:E.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Kn[E.source]),$(E.bots),ne(E.lastUsedAt)].join(" · ")})]}),E.source!=="linked"&&ie(E.id,"secret",E.name,()=>fe(E.id))]}),I===E.id&&E.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx($n,{secret:E,bots:i,onCancel:()=>_(null),onSaved:async()=>{_(null),await le()}})})]},E.id);return e.jsx(X,{title:t("settings.vault.title"),subtitle:t("settings.vault.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3","aria-busy":r===null||Y,"data-vault":!0,children:[s.config?.cloudHome===!0&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary","data-logins-cloud-own":!0,children:t("settings.logins.cloudOwn")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex h-8 min-w-[12rem] flex-1 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-vault-search":!0,type:"text",value:h,onChange:E=>g(E.target.value),autoComplete:"off",spellCheck:!1,placeholder:t("settings.vault.search"),"aria-label":t("settings.vault.search"),className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",className:"ui-button ui-button-md",disabled:r===null,"aria-expanded":f,onClick:()=>j(!f),onKeyDown:E=>{E.key==="Escape"&&j(!1)},children:[e.jsx(Ce,{size:14}),t("settings.vault.add"),e.jsx(Na,{size:13,"aria-hidden":"true"})]}),f&&e.jsx("div",{className:"absolute end-0 top-full z-10 mt-1 flex min-w-[11rem] flex-col rounded-lg border border-hairline/60 bg-menu p-1 shadow-lg","data-vault-add":!0,children:sp.map(([E,W])=>e.jsx("button",{type:"button",className:"rounded-md px-2.5 py-1.5 text-start text-[13px] text-ink hover:bg-control",onClick:()=>oe(E),children:t(W)},E))})]})]}),e.jsx(Ql,{label:t("settings.vault.filter"),attr:"data-vault-filter",value:b,onChange:y,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")}]}),C==="login"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsxs(un,{site:{value:S,onChange:P},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>w(null),onSubmit:async E=>{await Zl(S,E,k,v),w(null),P(""),B("all"),A(!1),await le()},children:[e.jsx(Wn,{checked:v,onChange:A,label:t("settings.logins.exactHost")}),e.jsx(dt,{value:k,onChange:B,bots:i})]})}),C==="secret"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx($n,{bots:i,onCancel:()=>w(null),onSaved:async()=>{w(null),await le()}})}),C==="env"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(tp,{bots:i,onCancel:()=>w(null),onSaved:le})}),r===null&&!x&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.vault.loading")}),K&&!C&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.vault.empty")}),!K&&r!==null&&be.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary","data-vault-none":!0,children:t("settings.vault.noMatch")}),be.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/30","data-logins-list":!0,children:be.map(E=>E.kind==="login"?ae(E.login):L(E.secret))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-tertiary",children:t("settings.logins.limits")}),pe.length>0&&e.jsx("p",{role:"status",className:"text-[12px] leading-relaxed text-warning","data-vault-keys-off":!0,children:t("settings.vault.secret.keyOff",{servers:pe.join(", ")})}),x&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:x}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline/30 pt-3","data-vault-keys":!0,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.vault.keys.title")}),e.jsx("div",{className:"text-[12px] leading-snug text-ink-tertiary",children:t("settings.vault.keys.hint")})]}),e.jsx("button",{type:"button",className:"ui-button ui-button-md shrink-0",onClick:()=>n({type:"toggleAppSettings",open:!0,section:"connections"}),children:t("keys.row.open")})]}),e.jsx(ip,{status:m,disabled:r===null,bots:i,botNames:$,onChange:async E=>{u(E),await le()}})]})})}function Hn(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 Wn({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 ap({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,o]=l.useState(!1),[d,m]=l.useState(s.bots),[u,x]=l.useState(!1),[p,h]=l.useState(null),g=async()=>{x(!0),h(null);try{await r(await ro(s.id,d)),o(!1)}catch(b){h(b instanceof Error&&b.message?b.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:fs,disabled:i||u,onClick:()=>{m(s.bots),o(!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(dt,{value:d,onChange:m,bots:n,disabled:u}),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:[e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:u,onClick:()=>o(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:u,onClick:()=>{g()},children:t("settings.logins.saveChange")})]})]})]})}function ip({status:s,disabled:n,bots:a,botNames:i,onChange:r}){const[c,o]=l.useState(""),[d,m]=l.useState(null),[u,x]=l.useState(null),p=async(g,b)=>{if(!d){m(g),x(null);try{await r(await b()),g==="connect"&&o("")}catch(y){x(y instanceof Error&&y.message?y.message:t("settings.logins.onePassword.error"))}finally{m(null)}}},h=g=>{g.preventDefault(),c.trim()&&p("connect",()=>no(c.trim()))};return e.jsxs("section",{className:"mt-1 flex flex-col gap-2 border-t border-hairline/30 pt-3","aria-label":t("settings.vault.manager"),"data-onepassword":!0,children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.vault.manager")}),e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:t("settings.logins.onePassword.title")}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-snug text-ink-secondary",children:t("settings.logins.onePassword.connected",{vaults:(s.vaults??[]).map(g=>g.title).join(", ")||"—",count:String(s.items??0)})}),s.error&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:s.error}),!!s.vaults?.length&&e.jsx("ul",{className:"divide-y divide-hairline/30","aria-label":t("settings.logins.onePassword.vaults"),children:s.vaults.map(g=>e.jsx(ap,{vault:g,bots:a,botNames:i,disabled:n,onChange:r},g.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",className:"ui-button ui-button-md",disabled:n||d!==null,onClick:()=>{p("refresh",lo)},children:[d==="refresh"?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(we,{size:13}),t("settings.logins.onePassword.refresh")]}),e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:n||d!==null,onClick:()=>{p("disconnect",oo)},children:t("settings.logins.onePassword.disconnect")})]})]}):e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:h,children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.logins.onePassword.guide")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{name:"onePasswordToken",type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:c,onChange:g=>o(g.target.value),disabled:n||d!==null,"aria-label":t("settings.logins.onePassword.token"),placeholder:t("settings.logins.onePassword.token"),className:"min-w-0 flex-1 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"}),e.jsxs("button",{type:"submit",className:"ui-button ui-button-md ui-button-primary",disabled:n||d!==null||!c.trim(),children:[d==="connect"&&e.jsx(J,{size:13,className:"animate-spin"}),t("settings.logins.onePassword.connect")]})]})]}),e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Ot,{size:11,"aria-hidden":"true",className:"mt-[3px] shrink-0"})," ",t("settings.logins.onePassword.note")]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u})]})}const ns="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 Gn(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function rp(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=Or(n);return a.ok&&(a.code!==null||a.credential!==null)}function lp({hideWhenUnavailable:s=!1,legacyOnly:n=!1}){const a=window.ogb?.remoteClient,i=window.ogb?.environments,[r,c]=l.useState({active:a?.active===!0}),[o,d]=l.useState(i?"server":"companion"),[m,u]=l.useState(""),[x,p]=l.useState(""),[h,g]=l.useState(""),[b,y]=l.useState(!1),[f,j]=l.useState(""),C=l.useRef(!1),w=!!i&&o==="server",S=l.useRef(!0),P=l.useCallback(()=>{a?.state().then(v=>{S.current&&c(v)}).catch(()=>{})},[a]);l.useEffect(()=>(S.current=!0,P(),()=>{S.current=!1}),[P]);const k=async()=>{if(!(C.current||!a&&!i)){C.current=!0,y(!0),j("");try{if(w&&i){if(!rp(m))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(m.trim()),P()}else a&&(await a.pair(x,h),P())}catch(v){j(Gn(v))}finally{C.current=!1,y(!1)}}},B=async()=>{if(!(!a||C.current)){C.current=!0,y(!0),j("");try{await a.disconnect(),P()}catch(v){j(Gn(v))}finally{C.current=!1,y(!1)}}};return!a&&!i&&s||n&&!r.active?null:e.jsxs(X,{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(wt,{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:b,onClick:()=>{B()},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:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(Ld,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:v=>{v.preventDefault(),k()},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(de,{value:o,disabled:b,onChange:v=>{d(v.target.value),j("")},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 limixbot 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 limixbot 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:m,onChange:v=>u(v.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:b,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:ns})]}),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:v=>p(v.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:b,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:ns})]}),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:h,onChange:v=>g(v.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:b,inputMode:"numeric",autoComplete:"one-time-code",className:`${ns} max-w-40 font-mono tracking-[0.2em]`})]})]}),f?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:f}):null,e.jsxs("button",{type:"submit",disabled:b||(w?!m.trim():x.trim()===""||h.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:[b?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(wt,{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&&f?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:f}):null]})}const op={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 cp({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(ws())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(op[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 dp({workspace:s,own:n=!1,onClose:a}){const{state:i}=G(),c=n||$a(i.config)?window.ogb?.computerSharing:void 0,[o,d]=l.useState(null),[m,u]=l.useState([]),[x,p]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(!1),[f,j]=l.useState(""),[C,w]=l.useState(null),S=l.useRef(!1),P=l.useRef(!1),k=l.useRef(null),B=A=>{d(A),u(A.folders),p(A.terminal),g(A.computer)};l.useEffect(()=>{S.current=!0,k.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(_=>{S.current&&B(_)}).catch(()=>{S.current&&j(t("computerSharing.loadFailed"))});const A=()=>{c?.state(s.id).then(_=>{S.current&&d(_)}).catch(()=>{}),c?.activity?.(s.id).then(_=>{S.current&&w(_)}).catch(()=>{})};A();const I=setInterval(A,3e3);return()=>{S.current=!1,clearInterval(I)}},[c,s.id]);const v=async A=>{if(!P.current){P.current=!0,y(!0),j("");try{await A()}catch(I){S.current&&j(String(I?.message??I).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{P.current=!1,S.current&&y(!1)}}};return c?e.jsx("div",{ref:k,children:e.jsx(X,{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:o?o.enabled?o.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(_e,{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&&o?.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(o.paused?"computerSharing.paused":"computerSharing.pauseHint")}),e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{await(o.paused?c.resume?.():c.pause?.());const A=await c.state(s.id);S.current&&d(A)})},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(o.paused?"computerSharing.resume":"computerSharing.pause")})]}),e.jsxs("fieldset",{disabled:b||!o,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:t("computerSharing.folders")}),m.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.noFolders")}),m.map(A=>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:A.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:A.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:A.write,onChange:I=>u(_=>_.map(D=>D.id===A.id?{...D,write:I.target.checked}:D))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:A.name}),onClick:()=>u(I=>I.filter(_=>_.id!==A.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(_e,{size:14})})]},A.id)),e.jsxs("button",{type:"button",disabled:m.length>=20,onClick:()=>{v(async()=>{const A=await c.chooseFolder();S.current&&A&&u(I=>I.some(_=>_.path===A.path)?I:[...I,A])})},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(co,{size:14}),t("computerSharing.chooseFolder")]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.smallFiles")})]}),e.jsxs("fieldset",{disabled:b||!o,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:A=>p(A.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:h,onChange:A=>g(A.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")})]})]})]}),(f||o?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:f||o?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:b||!o||!m.length&&!x&&!h,onClick:()=>{v(async()=>{const A=await c.save(s.id,{folders:m,terminal:x,computer:h});S.current&&A&&B(A)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:t(o?.enabled?"computerSharing.save":"computerSharing.share")}),o?.enabled&&e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{const A=await c.revoke(s.id);S.current&&B(A)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:t("computerSharing.stop")})]}),o?.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(cp,{entries:C})})]})})}):null}const up={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},vt=s=>s.kind!=="local"&&!!s.origin&&!s.home&&!s.cloud&&!("team"in s&&s.team),mp=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function pp(s,n){return s==="docker"?"git pull && ./update.sh":s==="global"?`npm install -g openmausbot@${n}`:s==="source"?"git pull && pnpm install":`npx openmausbot@${n} serve`}function xp({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=Ts(pp(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(_e,{size:13})})]})}function hp({origin:s,name:n}){const{state:a,copy:i}=Ts(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(ge,{size:14}):e.jsx(Za,{size:14})})}function gp({status:s,onTryNow:n,onPairAgain:a,onEdit:i}){if(!s||s.state==="connected")return null;const r=(d,m)=>e.jsx("button",{type:"button",onClick:m,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:mp(s.since)}):s.state==="signedOut"?t("servers.state.signedOut"):t("servers.state.insecure"),o=s.state==="signedOut"||s.state==="insecure";return e.jsxs("div",{"data-server-state":s.state,className:o||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 fp({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(me,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function bp({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:o,onComputerAccess:d,onShare:m=()=>{}}){const u=window.ogb?.environments,[x,p]=l.useState([]),[h,g]=l.useState([]),[b,y]=l.useState(null);l.useEffect(()=>{if(!u?.status)return;let S=!0;const P=()=>{u.status().then(B=>{S&&p(B)}).catch(()=>{})};P();const k=u.onStatus?.(P);return()=>{S=!1,k?.()}},[u,s]);const f=S=>x.find(P=>P.id===S),j=S=>y({address:S.origin,locked:!0,title:t("servers.pairAgainTitle",{name:S.name})}),C=S=>y({address:S.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),w=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(S=>S.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:w.map(S=>{const P=S.id===s.activeId,k=vt(S)?f(S.id):void 0,B=S.id==="local"?wt:Ns,v=S.id==="local"?t("servers.localHint"):vt(S)?`${new URL(S.origin).host} · ${t(up[Mr(S.origin)])}`:S.home?t("servers.managed"):new URL(S.origin).host,A=i.find(_=>_.id===S.id),I=k?.behind===!0&&r!==null&&!h.includes(`${S.id}:${k.version}`);return e.jsxs("li",{"data-server-row":S.id,className:"py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[zr(S.color)?e.jsx(Ur,{color:S.color,size:20}):e.jsx(B,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:S.name}),e.jsx("div",{"data-server-where":!0,className:"break-all text-[12px] text-ink-secondary",children:v}),e.jsx(gp,{status:k,onTryNow:()=>{u?.retry?.(S.id)},onPairAgain:()=>j(S),onEdit:()=>C(S)})]}),P?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{size:13}),t("servers.current")]}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:S.name}),onClick:()=>c(S.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.switch")}),vt(S)&&k?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>j(S),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.pairAgain")}),S.id!=="local"&&!S.home&&!S.cloud&&!A&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:S.name}),onClick:()=>d(S.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("servers.computerAccess")}),vt(S)&&e.jsx(hp,{origin:S.origin,name:S.name}),S.id!=="local"&&!S.home&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.removeName",{name:S.name}),title:t("servers.removeName",{name:S.name}),onClick:()=>o(S.id),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]}),A&&e.jsx(fp,{name:S.name,share:A,busy:n,onShare:_=>m(S.id,_),onOpen:()=>d(S.id)}),I&&e.jsx(xp,{name:S.name,status:k,appVersion:r,onHide:()=>g(_=>[..._,`${S.id}:${k.version}`])})]},S.id)})}),e.jsxs("button",{type:"button","data-server-connect":!0,disabled:n,onClick:()=>y({address:"",locked:!1,title:t("connect.title")}),className:"mt-3 flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[e.jsx(Ce,{size:14}),t("connect.title")]}),b&&e.jsx(_c,{focusKey:b.locked?"pair-again":"connect",onClose:()=>y(null),children:e.jsx($c,{onBack:null,onConnected:()=>y(null),start:b})})]})}function Vn(){const s=window.ogb?.environments,{state:n}=G(),a=$a(n.config)&&!!window.ogb?.computerSharing,i=window.ogb?.computerSharing,[r,c]=l.useState([]),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(""),[h,g]=l.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[b,y]=l.useState(""),[f,j]=l.useState(""),[C,w]=l.useState(null),[S,P]=l.useState(!1),[k,B]=l.useState(""),v=l.useRef(!1),A=l.useRef(0);l.useEffect(()=>{const T=++A.current;return s?.state().then(R=>{A.current===T&&d(R)}).catch(()=>{A.current===T&&p(t("servers.loadFailed"))}),()=>{A.current++}},[s]),l.useEffect(()=>{if(!i?.servers||!o)return;let T=!0;const R=()=>{i.servers().then(re=>{T&&c(re)}).catch(()=>{})};R();const Y=setInterval(R,5e3);return()=>{T=!1,clearInterval(Y)}},[i,o]);const I=(T,R)=>{_(async()=>{R?await i?.allow?.(T)&&g(T):await i?.revoke(T),i?.servers&&c(await i.servers())})};l.useEffect(()=>{const T=R=>{R&&g(R);const Y=new URL(window.location.href);Y.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${Y.pathname}${Y.search}${Y.hash}`)};return T(),s?.onOpenSettings?.(T)},[s]);const _=async(T,R=p)=>{if(v.current||!s)return;v.current=!0,u(!0),p(""),B("");const Y=A.current;try{if(await T()===!0)return;const re=await s.state();A.current===Y&&d(re)}catch(re){A.current===Y&&R(String(re?.message??re).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{v.current=!1,A.current===Y&&u(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const D=T=>window.ogb?.confirm?window.ogb.confirm(T):window.confirm(T),Q=o?.environments.find(T=>T.id===h),H=Q?.origin&&!Q.home?{id:Q.id,name:Q.name,origin:Q.origin}:void 0,N=!!(H&&r.some(T=>T.id===H.id)),Z=o?.environments.filter(T=>T.kind==="local")??[],te=Z.find(T=>T.id===C);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("servers.intro")}),o?.packaged&&e.jsxs(X,{title:t("connectedWorkspaces.localTitle"),subtitle:t("connectedWorkspaces.localSubtitle"),children:[k&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:k}),Z.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:Z.map(T=>{const R=T.id===o.activeId;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(wt,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:T.name}),e.jsxs("div",{className:"break-all text-[12px] text-ink-secondary",children:[T.dataDir,T.missing&&e.jsx("span",{className:"ml-2 rounded-md bg-inset px-1.5 py-0.5 text-[11px]",children:t("connectedWorkspaces.missing")})]})]}),R?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{size:13}),t("connectedWorkspaces.current")]}):e.jsx("button",{type:"button",disabled:m,"aria-label":t("connectedWorkspaces.switchTo",{name:T.name}),onClick:()=>{_(async()=>{if(!await D(t("connectedWorkspaces.switchConfirm",{name:T.name})))return;const Y=await s.switch(T.id);if(Y&&Y.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},B)},className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.switch")}),!R&&e.jsx("button",{type:"button",disabled:m,"aria-label":t("connectedWorkspaces.forgetName",{name:T.name}),title:t("connectedWorkspaces.forgetName",{name:T.name}),onClick:()=>{w(T.id),P(!1)},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]},T.id)})}),te&&e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 p-3",children:[e.jsxs("label",{className:"flex items-start gap-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:S,disabled:m,className:"mt-0.5",onChange:T=>P(T.target.checked)}),t("connectedWorkspaces.forgetPurge",{path:te.dataDir??""})]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",disabled:m,onClick:()=>{_(async()=>{const T=S?await s.forget(te.id,!0):await s.forget(te.id);if(T&&T.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));w(null)},B)},className:"rounded-lg px-3 py-1.5 text-[12px] font-medium text-danger hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.forget")}),e.jsx("button",{type:"button",onClick:()=>w(null),className:"rounded-lg px-3 py-1.5 text-[12px] text-ink hover:bg-control",children:t("connectedWorkspaces.cancel")})]})]}),e.jsx("p",{className:"mt-4 text-[13px] font-medium text-ink",children:t("connectedWorkspaces.newEnvironment")}),e.jsxs("form",{className:"flex flex-col gap-3 pt-2",onSubmit:T=>{T.preventDefault(),b.trim()&&_(async()=>{if(!(await s.create(b.trim(),f.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));y(""),j("")},B)},children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.name"),e.jsx("input",{required:!0,value:b,disabled:m,maxLength:60,onChange:T=>y(T.target.value),placeholder:t("connectedWorkspaces.environmentPlaceholder"),className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.dataFolder"),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("input",{value:f,disabled:m,onChange:T=>j(T.target.value),placeholder:t("connectedWorkspaces.defaultFolder"),className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"}),e.jsx("button",{type:"button",disabled:m,onClick:()=>{_(async()=>{const T=await s.pickDir();T?.ok&&T.path&&j(T.path)},B)},className:"shrink-0 rounded-lg border border-hairline/40 px-3 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.choose")})]})]}),e.jsxs("button",{type:"submit",disabled:m||!b.trim(),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[m&&e.jsx(J,{size:14,className:"animate-spin"}),t("connectedWorkspaces.create")]})]})]}),e.jsxs(X,{title:t("servers.yours.title"),subtitle:t("servers.yours.subtitle"),children:[o?e.jsx(bp,{saved:o,busy:m,sharingOffered:a,ownServers:r,appVersion:window.ogb?.app?.version??null,onShare:I,onSwitch:T=>{_(async()=>(await s.switch(T),!0))},onForget:T=>{_(()=>s.forget(T))},onComputerAccess:g}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t(x?"servers.yours.loadFailed":"servers.yours.loading")}),o&&x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]}),(a||N)&&H&&e.jsx(dp,{workspace:H,own:N,onClose:()=>g(null)},H.id)]})}const yp={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function vp({banner:s,canChange:n,subtitle:a}){const i=l.useRef(null),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=uo(s),u=async h=>{c(!0),d(null);const g=await Promise.resolve().then(h).catch(()=>({ok:!1,problem:"failed"}));c(!1),g.ok||d(yp[g.problem])},x=h=>{i.current&&(i.current.value=""),!(!h||!n)&&u(async()=>{const g=await po(h);return g.ok?xo(g.blob):g})},p=o?e.jsx("p",{role:"alert",className:"text-danger",children:t(o)}):n?null:e.jsx("p",{className:"text-ink-secondary",children:t("placeLook.imageAdmins")});return e.jsx("div",{"data-place-picture":m?"set":"none",children:e.jsx(ce,{title:t("placeLook.sidebarPicture"),subtitle:a,message:p,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[m&&e.jsx("img",{src:m,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(m?"placeLook.changeImage":"placeLook.useImage")}),m&&e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>{u(ho)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:mo,hidden:!0,"data-place-picture-input":!0,onChange:h=>x(h.target.files?.[0])})]})})})}function Hi(){const s=go(),{state:n}=G(),a=Pt()===!0,i=window.ogb?.app?.ownPage===!0,[r,c]=l.useState(null),[o,d]=l.useState(null),m=s?.change===null,u=p=>{!s||m||r||p===s.swatch||(c(p),d(null),fo(p).then(h=>{c(null),d(h)}))},x=s?.reason==="member"||o==="refused"?t("placeLook.member"):s?.reason==="signed-out"?t("placeLook.signedOut"):o==="unsupported"?t("placeLook.unsupported"):null;return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{"data-place-look":s.change??"locked",children:e.jsx(ce,{title:t("placeLook.sidebarColor"),subtitle:i?t("placeLook.sidebarColorSub"):t("placeLook.sub",{name:s.name}),message:o==="failed"?e.jsx("p",{role:"alert",className:"text-danger",children:t("placeLook.failed")}):x&&e.jsx("p",{className:"text-ink-secondary",children:x}),children:e.jsx(Kc,{value:r??s.swatch,onChange:u,label:i?t("placeLook.sidebarColor"):t("placeLook.aria",{name:s.name}),disabled:m,offset:"menu",none:!0})})}),e.jsx(vp,{banner:n.config?.workspaceBanner??null,canChange:a,subtitle:t(i?"placeLook.sidebarPictureSub":"placeLook.sharedPictureSub")})]})}function kp(){return e.jsx("div",{"data-sidebar-look":!0,"data-settings-look":"simple",className:Ka,children:e.jsx(ve,{children:e.jsx(Hi,{})})})}function Wi(){const{capabilities:s}=ei(),n=typeof window>"u"?void 0:window.ogb?.windowFrame,[a,i]=l.useState(null);l.useEffect(()=>{if(!n)return;let d=!0;return n.state().then(m=>{d&&i(m)}).catch(()=>{}),()=>{d=!1}},[n]);const r=s.host?.platform;if(!n||!a||r!=="darwin"&&r!=="win32")return null;const c=window.ogb?.relaunch,o=()=>{n.set(!a.on).then(i).catch(()=>{})};return e.jsxs("div",{"data-window-frame-switch":!0,children:[e.jsx(ce,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(me,{checked:a.on,"aria-label":t("settings.windowFrame.title"),onClick:o})}),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:js()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}function Gi(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function jp(s,n){return s.find(a=>Gi(a)&&a.instanceId.endsWith(`.${n}`))}function Ks(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function qn(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return Ks(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function Np(s,n){const a=n.filter(o=>Gi(o)&&Ks(o)),i=a.find(o=>o.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const r={target:i,bots:[],needsAsk:[]},c=o=>n.find(d=>d.instanceId===o)?.driverKind;for(const o of s){if(o.hidden)continue;const d=bo(o);if(qn(o.modelSelection,n)||qn(d.modelSelection,n))continue;([o,d].some(u=>yo(vo(u),c(u.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(o)}return r}const wp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function Sp({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=Np(n.bots,n.instances),u=m.target,x=h=>h.map(g=>g.name).join(", "),p=async()=>{if(!u||!m.bots.length||r)return;const h=m.bots,g={instanceId:u.instanceId,model:u.models.default};c(!0),d(null);for(const b of h)a({type:"setModel",botId:b.id,selection:g});try{const b=await Promise.all(h.map(f=>i(f.id).catch(()=>null))),y=h.filter((f,j)=>b[j]?.modelSelection.instanceId===g.instanceId);y.length&&d({name:u.displayName,bots:y.map(f=>f.name)})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(h=>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:wp[h.id]??h.id}),e.jsx("span",{className:"text-ink-secondary",children:h.configured?t("organization.modelCount",{count:h.models.length}):t("organization.notConfigured")})]}),h.configured&&h.models.length>0&&e.jsx(Cp,{instance:jp(n.instances,h.id),instances:n.instances})]},h.id))}),o&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:o.name,names:o.bots.join(", ")})}),u&&m.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(m.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{p()},children:m.bots.length===1?t("organization.useCompanyOne",{name:u.displayName}):t("organization.useCompanyMany",{name:u.displayName,count:m.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),u&&m.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:x(m.needsAsk)})})]})}function Cp({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(Ks(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ge,{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&&ko(a)?e.jsx(Tt,{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 Ep={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},Jn="https://admin.limixbot.com",Yn={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 Ap(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(Yn,a))?s.message:n.map(a=>t(Yn[a])).join(" ")}function Vi(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[n,a]=l.useState(null),[i,r]=l.useState(""),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1),h=l.useRef(0),g=l.useRef(0),b=l.useRef(void 0),y=k=>{const B=b.current!==k.status;b.current=k.status,a(k),B&&m(""),k.status!=="connected"&&k.status!=="reauth-required"&&x(!1)};l.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const k=++h.current,B=g.current,v=I=>{h.current===k&&(g.current++,y(I))},A=s?.onState(v);return s?.state().then(I=>{g.current===B&&v(I)}).catch(()=>{h.current===k&&g.current===B&&m(t("organization.loadFailed"))}),()=>{h.current++,A?.()}},[s]);const f=async k=>{if(!s||p.current)return;p.current=!0,o(!0),m("");const B=h.current,v=g.current;try{const A=await k();h.current===B&&g.current===v&&y(A)}catch{h.current===B&&g.current===v&&m(t("organization.actionFailed"))}finally{p.current=!1,h.current===B&&o(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const j=n?.status==="connected"||n?.status==="reauth-required"||n?.status==="unavailable"||n?.status==="license-expired",C=n?.status==="license-expired"||n?.notice==="license-expired",w=n?.enrollment?.expiresAt??n?.expiresAt,S=typeof w=="number"&&Number.isFinite(w)?new Date(w):null,P=S&&Number.isFinite(S.getTime())?new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(S):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.additive")}),e.jsxs(X,{title:t("settings.section.organization"),subtitle:t("organization.privacy"),children:[!n&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:d||t("organization.loading")}),n?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:Ap(n)}),C&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),n?.status==="signed-out"&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.signInHelp")}),e.jsx("button",{type:"button",disabled:c,onClick:()=>{f(()=>s.begin({portalOrigin:Jn}))},className:"w-fit rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:c?t("organization.working"):t("organization.signIn")}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.advanced")}),e.jsxs("form",{className:"mt-2 flex flex-col gap-2",onSubmit:k=>{k.preventDefault(),i.trim()&&f(()=>s.begin({portalOrigin:i.trim()}))},children:[e.jsx("p",{children:t("organization.advancedHelp")}),e.jsxs("label",{className:"flex flex-col gap-1.5",children:[t("organization.address"),e.jsx("input",{type:"url",required:!0,value:i,disabled:c,onChange:k=>r(k.target.value),placeholder:Jn,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"ui-button w-fit",children:t("organization.customSignIn")})]})]})]}),n?.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")}),n.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:n.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.enrollment&&s.reopen&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[n.branding?.logo&&e.jsx("img",{src:n.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:n.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:n.email})]}),n.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):n.status==="license-expired"?e.jsx(e.Fragment,{children:n.providers?.some(k=>k.configured&&k.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:n.providers.filter(k=>k.configured&&k.models.length>0).map(k=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:Ep[k.id]??k.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},k.id))})}):n.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),n.providers?.some(k=>k.configured&&k.models.length>0)?e.jsx(Sp,{providers:n.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,u?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:c,className:"ui-button",onClick:()=>x(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button text-danger",onClick:()=>{f(()=>s.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>x(!0),children:t("organization.disconnect")})]})]}),n?.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})}),d&&n&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:d}),!n&&e.jsx("button",{type:"button",disabled:c,className:"ui-button mt-3",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")})]})]})}const Ip="https://cal.com/milind-soni-002qed/30min",Pp=["feature","price","setup","broken","later","other"],Tp={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},Xn=2e3,bs=s=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium"}).format(new Date(s)),Rp=s=>s.endsAt??s.renewsAt;function qi(s){const n=Rp(s);return s.trial?n?t("cloudCancel.endedTrial",{date:bs(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:bs(n)}):t("cloudCancel.endedPlanNoDate")}function Lp(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 Bp(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:bs(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function Ji({renewal:s,actions:n,onChanged:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,m]=l.useState(null);if(!s||!n)return null;const u=()=>{o(!0),m(null),n.keep().then(x=>{x.outcome==="kept"?a?.():m(x.outcome==="browser"?"browser":"failed")},()=>m("failed")).finally(()=>o(!1))};return e.jsxs(e.Fragment,{children:[s.cancelled?e.jsxs("div",{"data-cloud-cancel":"cancelled",className:"flex flex-col items-start gap-2 self-start",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink",children:qi(s)}),e.jsx("button",{type:"button",className:"ui-button",disabled:c,onClick:u,children:t(c?"cloudCancel.keeping":"cloudCancel.keep")}),d&&e.jsx("p",{role:d==="failed"?"alert":"status",className:M("text-[13px]",d==="failed"?"text-danger":"text-ink-secondary"),children:t(d==="failed"?"cloudCancel.failed":"cloudCancel.browser")})]}):e.jsx("button",{type:"button","data-cloud-cancel":"renewing",className:"ui-button self-start",onClick:()=>{m(null),r(s)},children:t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan")}),i&&e.jsx(Op,{renewal:i,actions:n,onClose:x=>{r(null),x&&a?.()}})]})}function Op({renewal:s,actions:n,onClose:a}){const[i,r]=l.useState(null),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState({step:"ask"}),[p,h]=l.useState(!1),[g,b]=l.useState(!1),y=l.useRef(!1),f=l.useRef(null),j=()=>{p||a(y.current)};l.useEffect(()=>{const v=document.activeElement instanceof HTMLElement?document.activeElement:null;return f.current?.querySelector("button[aria-pressed]")?.focus(),()=>{v?.isConnected&&v.focus()}},[]);const C=v=>{h(!0),b(!1),v().catch(()=>b(!0)).finally(()=>h(!1))},w=()=>C(async()=>{const v=i!==null||c.trim()!==""||d.trim()!=="",A=await n.cancel(v?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);A.outcome==="cancelled"?(y.current=!0,x({step:"done",renewal:A.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:A.surveyed})):A.outcome==="browser"?x({step:"browser"}):b(!0)}),S=()=>C(async()=>{const v=await n.keep();v.outcome==="kept"?(y.current=!0,a(!0)):v.outcome==="browser"?x({step:"browser"}):b(!0)}),P=t(s.trial?"cloudCancel.titleTrial":"cloudCancel.titlePlan"),k="mt-1.5 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-60",B=g&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return Hc.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:v=>v.stopPropagation(),children:e.jsxs("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":p,tabIndex:-1,"data-cloud-cancel-sheet":u.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:v=>{if(v.key==="Escape"&&(v.stopPropagation(),j()),v.key==="Tab"){const A=f.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!A?.length)return;const I=A[0],_=A[A.length-1];v.shiftKey&&document.activeElement===I?(v.preventDefault(),_.focus()):!v.shiftKey&&document.activeElement===_&&(v.preventDefault(),I.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:P}),e.jsx("button",{type:"button","aria-label":t("cloudCancel.close"),disabled:p,onClick:j,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(_e,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[u.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Bp(s)}),e.jsxs("fieldset",{className:"mt-4",disabled:p,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:Pp.map(v=>e.jsx("button",{type:"button","aria-pressed":i===v,onClick:()=>r(A=>A===v?null:v),className:M("ui-button ui-button-pill",i===v&&"border-accent bg-accent/10 font-medium"),children:t(Tp[v])},v))})]}),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:Xn,value:c,disabled:p,onChange:v=>o(v.target.value),className:k})]}),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:Xn,value:d,disabled:p,onChange:v=>m(v.target.value),className:k})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:Ip,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),B,e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:p,onClick:j,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:p,onClick:w,children:t(p?"cloudCancel.cancelling":s.trial?"cloudCancel.confirmTrial":"cloudCancel.confirmPlan")})]})]}),u.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:qi(u.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:Lp(u.renewal)}),u.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),B,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:p,onClick:S,children:t(p?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:p,onClick:j,children:t("cloudCancel.done")})]})]}),u.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:j,children:t("cloudCancel.done")})})]})]})]})}),document.body)}function Qn({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(Mp,{bridge:s,read:n,write:a}):null}function Mp({bridge:s,read:n,write:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null);if(l.useEffect(()=>{let g=!0;const b=()=>{n().then(f=>{g&&r(f)}).catch(()=>{})};b();const y=s.onNotice(b);return()=>{g=!1,y()}},[s,n]),!i?.shown)return null;const p=g=>{o(!1),m(!0),x(null),a(g).then(b=>r(b),b=>x(Dr(b)??t("cloudAccount.keepHere.failed"))).finally(()=>m(!1))},h=()=>{i.on?p(!1):i.moved?o(!0):p(!0)};return e.jsxs("div",{"data-cloud-keep":i.coming?"coming":i.on?"on":"off",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:t("cloudAccount.keepHere.title")}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("cloudAccount.keepHere.line")})]}),e.jsx(me,{checked:i.on||i.coming,disabled:d||i.coming,"aria-label":t("cloudAccount.keepHere.title"),onClick:h})]}),i.coming&&e.jsx("p",{role:"status",className:"mt-3 text-[13px] text-ink-secondary",children:t("cloudAccount.keepHere.coming")}),c&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.keepHere.confirmTitle"),className:"mt-3 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:t("cloudAccount.keepHere.confirmTitle")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.keepHere.confirm")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button",onClick:()=>o(!1),children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>p(!0),children:t("cloudAccount.keepHere.bringBack")})]})]}),u&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u})]})}function zp({label:s,suggest:n,className:a="ui-button"}){const{dispatch:i}=G();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"},Yi=s=>new Intl.DateTimeFormat(Oe(),{timeStyle:"short"}).format(new Date(s)),Dp=s=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium"}).format(new Date(s));function Xi(s,n){if(!s&&!n)return null;const a=s?Ss(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:qr(n)})]})}function Zn({machine:s,busy:n,failed:a,onConnect:i,trial:r=!1,waking:c=!1,moving:o=null,team:d=null}){const m=s.status==="ready"?s.unreachable:void 0,u=s.status==="ready"&&!m,x=m?t(m.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):o??(c&&u?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:Yi(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(Up[s.status]));return e.jsx(X,{title:d?d.name??t("cloudHome.team.title"):t("cloudHome.title"),children:e.jsxs("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-unreachable":m?.cause,"data-cloud-waking":c&&u?!0:void 0,"data-cloud-moving":o&&!m?!0:void 0,className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:u?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:x}),s.status==="provisioning"&&s.setup&&e.jsx(rd,{step:s.setup.step}),u&&e.jsxs(e.Fragment,{children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:d?.name?t("cloudBuy.setup.open",{name:d.name}):t("cloudHome.connect")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudHome.connectHelp")})]}),!d&&wo()&&e.jsx(zp,{label:t("cloudHome.filesLink"),className:"text-[13px] font-medium text-accent-text underline underline-offset-2 hover:text-ink"})]}),a&&!m&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudHome.connectFailed")})]})})}function Fp({ready:s,busy:n,failed:a,onUse:i}){return e.jsx(X,{title:t("cloudPhone.title"),subtitle:t("cloudPhone.subtitle"),children:e.jsxs("div",{"data-cloud-phone":s?"open":"steps",className:"flex flex-col items-start gap-3",children:[s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudPhone.action")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudPhone.help")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudPhone.failed")}),(!s||a)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(s?"cloudPhone.stepsIntro":"cloudPhone.notReady")}),e.jsxs("ol",{className:"list-decimal ps-5 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("li",{children:t("cloudPhone.step1")}),e.jsx("li",{children:t("cloudPhone.step2")})]})]})]})})}function _p(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 $p={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function Kp(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($p[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:Dp(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?Ss(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 Wp({bridge:s,onConnectPhone:n}){const[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(0);l.useEffect(()=>{let y=!0;return s.state().then(f=>{y&&i(f)}).catch(()=>{y&&d(!0)}),()=>{y=!1}},[s,m]);const x=s.cancel&&s.keep?{cancel:y=>s.cancel(y),keep:()=>s.keep()}:null;if(o)return e.jsx(X,{title:t("settings.section.cloudAccount"),children:e.jsx("p",{"data-cloud-plan":"elsewhere",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudNone")})});const p=Gr(a?.tier),h=a?.home===!0,g=a?.status==="paid"?t(Vr(a.trial)?"cloudAccount.trialPlan":"cloudAccount.pro",{plan:p}):a?.status==="attention"?t("cloudAccount.inactive",{plan:a.tier?p:"Limix Bot Cloud"}):a?.status==="checking"?t("cloudAccount.lastPlan",{plan:p}):a?.status==="signin"?a.tier?t("cloudAccount.planName",{plan:p}):null:a?t(h?"cloudAccount.onCloudNoneHome":"cloudAccount.onCloudNone"):null,b=y=>{c(!1),y().catch(()=>c(!0))};return e.jsx(X,{title:t("settings.section.cloudAccount"),subtitle:t(h?"cloudAccount.onCloudHome":"cloudAccount.onCloud"),children:e.jsxs("div",{"data-cloud-plan":a?.status??"loading",className:"flex flex-col items-start gap-3",children:[g?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:g}):!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),a?.status==="signin"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudSignIn")}),Xi(a?.trial,a?.credit),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a?.status==="signin"&&s.signIn&&e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>b(()=>s.signIn()),children:t("cloudAccount.signInAgain")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>b(()=>s.manage()),children:a?.trial&&!a.renewal?.cancelled&&Ss(a.trial).action?.label||t("cloudAccount.manageInBrowser")}),a&&n&&e.jsx("button",{type:"button",className:"ui-button",onClick:n,children:t("cloudPhone.action")}),e.jsx(No,{})]}),a?.renewal&&e.jsx(Ji,{renewal:a.renewal,actions:x,onChanged:()=>u(y=>y+1)}),r&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function Gp({team:s}){return e.jsx(X,{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("cloudAccount.teamPeopleBody",{team:s.name})}),s.cloudPage&&e.jsx("a",{className:"ui-button",href:s.cloudPage,target:"_blank",rel:"noreferrer",children:t("cloudAccount.teamPeopleOpen")})]})})}function Vp({linkRequest:s=0,cloudHome:n=!1,teamHome:a,onConnectPhone:i,onAddCloud:r,onSignIn:c}={}){const o=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:d}=ei().capabilities.host,[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,g]=l.useState(!1),[b,y]=l.useState(!1),[f,j]=l.useState(!1),[C,w]=l.useState(!1),[S,P]=l.useState(!1),k=l.useRef(0),B=l.useRef(0),v=l.useRef(!1),A=l.useRef({request:0,arrived:!1,connected:!1});l.useEffect(()=>{const se=++k.current,ie=B.current,be=ae=>{k.current===se&&(B.current++,u(ae),g(!1),ae.status==="signed-out"&&y(!1))},K=o?.onState(be);return o?.state().then(ae=>{B.current===ie&&be(ae)}).catch(()=>{k.current===se&&B.current===ie&&g(!0)}),()=>{k.current++,K?.()}},[o]);const I=async se=>{if(!o||v.current)return;v.current=!0,p(!0),g(!1);const ie=k.current,be=B.current;try{const K=await se();k.current===ie&&B.current===be&&u(K)}catch{k.current===ie&&B.current===be&&g(!0)}finally{v.current=!1,k.current===ie&&p(!1)}},_=()=>{o&&(w(!1),I(async()=>{try{return await o.connectHome()}catch{return w(!0),o.state()}}))},D=se=>{o?.openTeam&&(w(!1),I(async()=>{try{await o.openTeam(se)}catch{w(!0)}return o.state()}))},Q=()=>{o&&(P(!1),I(async()=>{try{return await o.connectHomeForPhone()}catch{return P(!0),o.state()}}))};l.useEffect(()=>{if(s||(A.current.request=0),!o||!s||!m||v.current||(A.current.request!==s&&(A.current={request:s,arrived:!0,connected:!1}),m.status==="signed-out"&&m.message==="restoring"))return;const se=_p(m,A.current);A.current.arrived=!1,se==="sign-in"&&I(()=>o.begin()),se==="connect"&&(A.current.connected=!0,_())},[o,s,m,x]);const[H]=jo(o?window.ogb?.cloudSendPage:void 0),N=H?.move?Fr(H.move,"local"):null,Z=N&&N.kind!=="done"?N.text:null,te=yd(!!m&&Zs(en(m)),m?.offer),T=o?.cancelPlan&&o.keepPlan?{cancel:se=>o.cancelPlan(se),keep:()=>o.keepPlan()}:null;if(!o){const se=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return e.jsxs(e.Fragment,{children:[n&&a?e.jsx(Gp,{team:a}):se?e.jsx(Wp,{bridge:se,onConnectPhone:i}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")}),se&&!a&&e.jsx(Qn,{bridge:window.ogb?.cloudSendPage})]})}const R=en(m),Y=m&&["connected","unavailable","reauth-required"].includes(m.status),re=Kp(m,R,d),pe=_r(R),xe=$r(m),le=Kr(m),$=R.kind==="paid"?{status:"provisioning"}:void 0,ne=xe?le?.machine??$:m?.status==="connected"?m.machine??$:void 0,fe=m?.status==="connecting"?m.enrollment:void 0;Hr(te);const oe=r&&Zs();return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.optional")}),e.jsxs(X,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.separate"),children:[m?.staging&&e.jsx(Wr,{className:"mb-3"}),(!m||R.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),re&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:re}),(R.kind==="signed-out"||R.kind==="removed")&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[oe,e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>c?c():void I(()=>o.begin()),children:t("cloudAccount.signIn")})]}),m?.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("cloudAccount.browser")}),fe&&e.jsxs("div",{"data-cloud-code":!0,className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.codeCheck")}),e.jsx("code",{dir:"ltr",className:"select-all text-[18px] font-semibold tracking-widest text-ink",children:fe.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:Yi(fe.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>{I(()=>o.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>{I(()=>o.cancel())},children:t("organization.cancel")})]})]}),Y&&e.jsxs("div",{className:"flex flex-col gap-3",children:[m.account&&e.jsx("p",{className:"break-all text-[14px] text-ink",children:m.account.email}),pe&&e.jsxs("p",{role:"status","data-cloud-plan":R.kind,className:"text-[15px] font-medium text-ink",children:[pe,R.kind==="paid"&&R.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),m.status==="connected"&&Xi(m.trial,m.credit),R.kind==="free"&&oe,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[R.kind==="reauth"?e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>{I(()=>o.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[!(R.kind==="free"&&oe)&&e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>{I(()=>o.openDashboard())},children:R.kind==="free"?t("cloudAccount.dashboard"):Hp(m,R)}),e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>{I(()=>o.refresh())},children:t("organization.refresh")})]}),!b&&e.jsx("button",{type:"button",disabled:x,className:"ui-button",onClick:()=>y(!0),children:t("cloudAccount.signOut")})]}),m.status==="connected"&&m.renewal&&e.jsx(Ji,{renewal:m.renewal,actions:T}),R.kind==="free"&&!b&&e.jsxs("p",{className:"text-[12px] text-ink-secondary",children:[t(window.ogb?.accounts?"cloudAccount.otherEmailOrTeam":"cloudAccount.otherEmail")," ",e.jsx("button",{type:"button","data-cloud-other-email":!0,disabled:x,className:"underline hover:text-ink",onClick:()=>window.ogb?.accounts?j(!0):y(!0),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),f&&e.jsx(Wc,{adding:"",onClose:()=>j(!1)}),b&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.signoutTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.signoutHelp")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:x,className:"ui-button",onClick:()=>y(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:x,className:"ui-button text-danger",onClick:()=>{I(()=>o.signOut())},children:t("cloudAccount.signOut")})]})]})]}),h&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!m&&e.jsx("button",{type:"button",disabled:x,className:"ui-button mt-3",onClick:()=>{I(()=>o.state())},children:t("organization.refresh")})]}),ne&&Zn(xe?{machine:ne,busy:x,failed:C,onConnect:()=>{le&&D(le.id)},team:{name:le?.name??null}}:{machine:ne,busy:x,failed:C,onConnect:_,trial:!!m?.trial,waking:m?.waking===!0,moving:Z}),Y&&R.kind==="paid"&&!xe&&Fp({ready:ne?.status==="ready",busy:x,failed:S,onUse:Q}),e.jsx(Qn,{bridge:window.ogb?.cloudSendPage})]})}function ea(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Oe(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function Qi(s){return t("planUsage.spendAmounts",{used:ea(s.usedMinor,s.currency,s.exponent),limit:ea(s.limitMinor,s.currency,s.exponent)})}function Zi(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),o=i%60;return r>0?c>0?`${r}d ${c}h`:`${r}d`:c>0?o>0?`${c}h ${o}m`:`${c}h`:`${o}m`}function qp(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(o=>o.resetsAt),...(r.models??[]).flatMap(o=>o.windows.map(d=>d.resetsAt))];for(const o of c){if(!o||a.has(o)||i.includes(o))continue;const d=Date.parse(o);Number.isFinite(d)&&d<=n&&i.push(o)}}return i}function Jp(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function ta(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function At(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 Yp(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:At({name:a[1]})}):n}function kt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?Zi(n.resetsAt,a):null,o=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,o))),children:e.jsx("div",{className:M("h-full rounded-full",Jp(o)),style:{width:`${Math.min(100,Math.max(0,o))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function er(){const[s,n]=l.useState(null),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(()=>Date.now()),m=l.useRef(new Set),u=l.useCallback(async(x=!1)=>{i(!0),c("");try{const p=await U(x?"/api/plan-usage?refresh=1":"/api/plan-usage");n(p),d(Date.now())}catch(p){c(p instanceof Error&&p.message?p.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return l.useEffect(()=>{u(!1)},[u]),l.useEffect(()=>{const x=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(x)},[]),l.useEffect(()=>{if(!s)return;const x=qp(s,o,m.current);if(x.length!==0){for(const p of x)m.current.add(p);u(!0)}},[s,o,u]),{report:s,loading:a,error:r,now:o,load:u}}function Xp(s){for(const n of s?.providers??[]){const a=n.ok&&!n.weekly.available?n.extra.find(i=>i.label==="Monthly spend"):void 0;if(a)return{provider:n,budget:a}}return null}function Qp(s){let n=null;for(const a of s?.providers??[]){const i=a.ok&&a.weekly.available?a.weekly.usedPercent:null;i!==null&&(!n||i>n.used)&&(n={provider:a,used:i})}return n}function Zp(){const{report:s,now:n}=er();if(!s)return null;const a=Qp(s),i=a?null:Xp(s);if(i){const d=At(i.provider),m=Math.round(Math.min(100,Math.max(0,i.budget.usedPercent)));return e.jsx(pn,{kind:"plan",title:t("settings.simple.billing.monthlySpend",{provider:d}),percent:m,label:`${d}: ${t("planUsage.used",{used:m})}`,note:i.budget.spend?Qi(i.budget.spend):null})}if(!a)return e.jsx("section",{"data-usage-summary":"own-ai",className:M(za,"px-4 py-3.5 text-[14px] leading-5 text-ink-secondary"),children:t("settings.simple.billing.ownAi")});const r=Math.round(Math.min(100,Math.max(0,a.used))),c=Zi(a.provider.weekly.resetsAt,n),o=At(a.provider);return e.jsx(pn,{kind:"plan",title:t("settings.simple.billing.weekly",{provider:o}),percent:r,label:`${o}: ${t("planUsage.used",{used:r})}`,note:c?t("planUsage.resetsIn",{when:c}):null})}function ex(){const{report:s,loading:n,error:a,now:i,load:r}=er();return e.jsxs(X,{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(J,{size:14,className:"animate-spin"}):e.jsx(we,{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(c=>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:At(c)}),c.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:c.plan})]}),c.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(kt,{label:t("planUsage.fiveHour"),window:c.fiveHour,now:i}),e.jsx(kt,{label:t("planUsage.weekly"),window:c.weekly,now:i}),c.extra.map((o,d)=>e.jsx(kt,{label:ta(o.label),now:i,usedHeadline:!!o.spend,detail:o.spend?Qi(o.spend):void 0,window:{available:!0,remainingPercent:o.remainingPercent,usedPercent:o.usedPercent,resetsAt:o.resetsAt}},`${o.label}-${d}`)),(c.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")}),(c.models??[]).map(o=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:o.name}),o.windows.map((d,m)=>e.jsx(kt,{label:ta(d.label),now:i,usedHeadline:!0,window:{available:!0,remainingPercent:d.remainingPercent,usedPercent:d.usedPercent,resetsAt:d.resetsAt}},`${o.name}-${d.label}-${m}`))]},o.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:Yp(c)})]},c.id))})]})}function sa(s,n){return s?.edition?.features?.includes(n)===!0}function tx(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function sx({budget:s}){const{state:n,dispatch:a}=G(),i=n.config?.budgets??{},[r,c]=l.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[o,d]=l.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[m,u]=l.useState(!1),[x,p]=l.useState(null);l.useEffect(()=>{c(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),d(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const h=async()=>{if(m)return;const b=r.trim()===""?0:Number(r),y=Number(o);if(!Number.isFinite(b)||b<0||!Number.isInteger(y)||y<1||y>100){p(t("usage.budget.invalid"));return}u(!0),p(null);try{const f=await U("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:b,warnAtPercent:y}})});a({type:"configStatus",config:f})}catch(f){p(f instanceof Error?f.message:String(f))}finally{u(!1)}},g=tx(s);return e.jsxs(X,{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:M(g==="danger"?"text-danger":g==="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:ct(s.spentUsd),cap:ct(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:M("h-full rounded-full",g==="danger"?"bg-danger":g==="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:b=>{b.preventDefault(),h()},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:b=>c(b.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:m,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:o,onChange:b=>d(b.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:m,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:m,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:[m&&e.jsx(J,{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 na(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 nx(){const{state:s,dispatch:n}=G(),a=s.config?.billing,[i,r]=l.useState(a?.currency??"USD"),[c,o]=l.useState(na(a?.prices)),[d,m]=l.useState(!1),[u,x]=l.useState(null);l.useEffect(()=>{r(a?.currency??"USD"),o(na(a?.prices))},[a]);const p=(b,y)=>o(f=>f.map((j,C)=>C===b?{...j,...y}:j)),h=async()=>{if(d)return;const b={};for(const y of c){const f=y.key.trim();if(!f)continue;const j=Number(y.input),C=Number(y.output),w=y.cached.trim()===""?void 0:Number(y.cached);if(!Number.isFinite(j)||!Number.isFinite(C)||j<0||C<0||w!==void 0&&(!Number.isFinite(w)||w<0)){x(t("usage.prices.invalid",{model:f}));return}b[f]={inputPerMillion:j,outputPerMillion:C,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){x(t("usage.prices.currencyInvalid"));return}m(!0),x(null);try{const y=await U("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:b}})});n({type:"configStatus",config:y})}catch(y){x(y instanceof Error?y.message:String(y))}finally{m(!1)}},g="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(X,{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:b=>r(b.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((b,y)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:b.key,onChange:f=>p(y,{key:f.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:M(g,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:b.input,onChange:f=>p(y,{input:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:g}),e.jsx("input",{value:b.output,onChange:f=>p(y,{output:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:g}),e.jsx("input",{value:b.cached,onChange:f=>p(y,{cached:f.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:g}),e.jsx("button",{type:"button",onClick:()=>o(f=>f.filter((j,C)=>C!==y)),"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(Se,{size:13})})]},y))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>o(b=>[...b,{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(Ce,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{h()},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(J,{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")}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function ax({budget:s}){const{state:n}=G(),a=sa(n.config,"budgets"),i=sa(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(sx,{budget:s}),i&&e.jsx(nx,{})]})}const ix=["model","user","department","day","engine","routine"],aa={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"},rx={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},lx=2e3;function ox(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 ia(s,n,a){const[i,r]=l.useState(null);return l.useEffect(()=>{let c=!0;return U(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}`).then(o=>{c&&r(o)}).catch(()=>{c&&r(null)}),()=>{c=!1}},[s.from,s.to,n,a]),i}function ra({groupBy:s,groups:n}){const{state:a}=G(),i=[...n].sort((c,o)=>st(o)-st(c)).slice(0,6),r=Math.max(...i.map(st),0);return!i.length||r<=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:i.map(c=>{const o=s==="bot"?a.bots.find(d=>`bot:${d.id}`===c.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(c.turns)}),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2 text-ink",children:[o&&e.jsx(Mt,{bot:o,state:"idle",size:18,animated:!1}),e.jsx("span",{className:"truncate",children:s==="model"?Oo(c.label,a.instances):ox(s,c)})]}),e.jsx("span",{className:"h-2 overflow-hidden rounded-full bg-raised",children:e.jsx("span",{className:"block h-full rounded-full bg-accent/70",style:{width:`${Math.max(2,st(c)/r*100)}%`}})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[Mo(st(c)),ot(c.costUsd)&&c.costUsd>0&&` · ${Ha(c.costUsd)}`]})]},c.key)})})}function cx({range:s,version:n,onBudget:a}){const[i,r]=l.useState("model"),c=ia(s,"bot",n),o=ia(s,i,n);return l.useEffect(()=>{a(c?.budget??null)},[c,a]),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(aa.bot)}),c?e.jsx(ra,{groupBy:"bot",groups:c.groups}):e.jsx(J,{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:ix.map(d=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===d,onClick:()=>r(d),className:M("rounded-md px-2 py-0.5 text-[11px] font-medium uppercase tracking-[0.06em]",i===d?"bg-accent/12 text-accent":"text-ink-secondary hover:bg-raised/60 hover:text-ink"),children:t(aa[d])},d))}),o?.groupBy===i?e.jsx(ra,{groupBy:i,groups:o.groups}):e.jsx(J,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}function dx(s){return new Date(s).toLocaleString(Jr(Oe()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function ux({root:s,onOpen:n}){const{state:a}=G(),i=s.title||t(`trace.source.${s.source}`,{bot:s.bots[0]?.name??""});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((r,c)=>{const o=a.bots.find(d=>d.id===r.id);return o?e.jsx("span",{className:M("rounded-full ring-2 ring-card",c>1&&"hidden sm:block"),children:e.jsx(Mt,{bot:o,state:"idle",size:22,animated:!1})},r.id):e.jsx("span",{className:M("flex size-[22px] items-center justify-center rounded-full bg-raised text-[10px] font-semibold text-ink-secondary ring-2 ring-card",c>1&&"hidden sm:flex"),children:r.name.slice(0,1).toUpperCase()},r.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:[dx(s.startedAt)," · ",s.bots.map(r=>r.name).join(", ")]})]}),e.jsxs("span",{className:"flex items-center gap-3 text-[13px] tabular-nums text-ink-secondary",children:[s.running&&e.jsx(Lo,{}),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:Bo(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:Ha(s.costUsd)}),e.jsx(Rs,{size:14,className:"text-ink-tertiary"})]})]})})}function tr(){const[s,n]=l.useState("month"),a=l.useMemo(()=>So(s),[s]),[i,r]=l.useState(null),[c,o]=l.useState(null),[d,m]=l.useState(0),[u,x]=l.useState(null),[p,h]=l.useState(null),g=l.useRef(null);l.useEffect(()=>{let f=!0;return xn(a).then(j=>{f&&(r(j),o(null))}).catch(j=>{f&&o(j instanceof Error?j.message:String(j))}),()=>{f=!1}},[a,d]),l.useEffect(()=>Co({onFrame:f=>{if(f.kind!=="runtime"||g.current)return;const j=f.event?.type;j!=="turn.started"&&j!=="turn.completed"||(g.current=setTimeout(()=>{g.current=null,m(C=>C+1)},lx))},onMissedFrames:()=>m(f=>f+1)}),[]),l.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]);const b=()=>{i?.next&&xn(a,i.next).then(f=>r(j=>j?{...f,roots:[...j.roots,...f.roots]}:f))},y=i?.roots.some(f=>!f.timed);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(de,{size:"sm",value:s,onChange:f=>{n(f.target.value),h(null)},"aria-label":t("usage.history.period"),children:Eo.map(f=>e.jsx("option",{value:f,children:t(rx[f])},f))}),e.jsxs("a",{href:Ao(a),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(Ye,{size:13}),t("usage.history.export")]})]})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:c}),p?e.jsx(Io,{id:p.id,at:p.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(Po,{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:i?e.jsx(To,{items:Ro(i.totals,t("trace.stat.time"))}):e.jsxs("div",{className:"flex items-center gap-2 p-5 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(cx,{range:a,version:d,onBudget:x}),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")})]}),i&&!i.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:i?.roots.map(f=>e.jsx(ux,{root:f,onOpen:()=>h({id:f.id,at:f.startedAt})},f.id))}),i?.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(ex,{}),e.jsx(ax,{budget:u})]})}function mx(){const[s,n]=l.useState(null);return l.useEffect(()=>{fetch("/api/limix/bundled-skills").then(a=>a.ok?a.json():{skills:[]}).then(a=>n(a.skills??[])).catch(()=>n([]))},[]),e.jsx(X,{title:z("Kĩ năng có sẵn của Limix Bot","Skills built into Limix Bot"),subtitle:z("Đi kèm ứng dụng. Kĩ năng gốc luôn bật cho mọi bot; các kĩ năng khác nằm trong kho, thêm cho từng bot ở mục Kĩ Năng (Skills) của bot.","Shipped with the app. Core skills are always on for every bot; the others wait in the store, and you add them to one bot at a time under the bot's Skills page."),children:e.jsx("div",{className:"flex flex-col gap-3",children:s===null?null:s.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:z("Chưa thấy kỹ năng có sẵn nào trong bản cài này.","No built-in skills were found in this install.")}):e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40",children:s.map(a=>e.jsxs("li",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-[13px] text-ink",children:a.id}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:a.core?z("Kĩ năng gốc · mọi bot","Core skill · every bot"):z("Trong kho · thêm cho từng bot","In the store · add per bot")})]}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:a.description}),a.triggerTerms.length>0&&e.jsxs("p",{className:"mt-1 text-[12px] text-ink-tertiary",children:[z("Từ khóa","Keywords"),": ",a.triggerTerms.slice(0,6).join(", "),a.triggerTerms.length>6?"…":""]})]},a.id))})})})}function px(){const[s,n]=l.useState(!1);return e.jsxs(X,{title:z("Công cụ cho kỹ năng","Tools for skills"),subtitle:z("Chương trình mà các kỹ năng cần để chạy: Docker, Node.js, ffmpeg, Java, JADX, Ghidra, Agent-Reach… Thiếu gì thì bấm cài.","Programs the skills need to run: Docker, Node.js, ffmpeg, Java, JADX, Ghidra, Agent-Reach… Install whatever is missing."),children:[Wa()?e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"inline-flex w-fit items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover",children:[e.jsx(zo,{size:14}),z("Xem và cài công cụ còn thiếu","See and install missing tools")]}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:z("Mở mục này trong ứng dụng Limix Bot trên máy tính.","Open this in the Limix Bot desktop app.")}),s&&e.jsx(Ga,{onClose:()=>n(!1)})]})}const at=12,xx=[["discover",()=>z("Khám phá","Discover")],["recommended",()=>z("Khuyên dùng","Recommended")],["installed",()=>z("Đã cài","Installed")],["updates",()=>z("Cập nhật","Updates")],["security",()=>z("Bảo mật","Security")],["settings",()=>z("Cài đặt","Settings")]],qe=s=>{const n=new Date(s);return Number.isNaN(n.getTime())?s:n.toLocaleDateString(z("vi-VN","en-US"))},hx=s=>({excellent:z("Xuất sắc","Excellent"),recommended:z("Khuyên dùng","Recommended"),review:z("Cần xem xét","Needs review"),rejected:z("Từ chối","Rejected")})[s],gx=s=>({"instructions-only":z("Chỉ hướng dẫn","Instructions only"),"skill-with-tools":z("Kèm tool/script","With tools/scripts"),"mcp-bundle":z("Kèm MCP","With MCP")})[s],as=s=>({clean:z("Sạch","Clean"),warning:z("Có cảnh báo","Warnings"),quarantined:z("Cách ly","Quarantined")})[s],Ue="inline-flex items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50";async function Ae(s,n){const a=await fetch(s,n===void 0?void 0:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}),i=await a.json().catch(()=>({}));if(!a.ok)throw new Error(i.error??z(`Lỗi ${a.status}`,`Error ${a.status}`));return i}function fx(){const[s,n]=l.useState(null),[a,i]=l.useState("recommended"),[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(""),[x,p]=l.useState(""),[h,g]=l.useState(!1),[b,y]=l.useState(null),[f,j]=l.useState(null),[C,w]=l.useState(at);l.useEffect(()=>w(at),[a,m,x]);const S=l.useCallback(async()=>{try{n(await Ae("/api/limix/hub"))}catch(N){d(N instanceof Error?N.message:String(N))}},[]);l.useEffect(()=>{S()},[S]);const P=async(N,Z)=>{c(N),d(null);try{await Z(),await S()}catch(te){d(te instanceof Error?te.message:String(te))}finally{c(null)}},k=s?.skills??[],B=l.useMemo(()=>[...new Set(k.map(N=>N.category))].sort(),[k]),v=l.useMemo(()=>{const N=m.trim().toLowerCase();return k.filter(Z=>{if(x&&Z.category!==x||N&&!`${Z.name} ${Z.description} ${Z.description_vi??""} ${Z.tags.join(" ")}`.toLowerCase().includes(N))return!1;switch(a){case"discover":return!0;case"recommended":return!Z.blocked&&!Z.risky&&(Z.grade==="excellent"||Z.grade==="recommended");case"installed":return Z.installed;case"updates":return Z.updateAvailable;case"security":return Z.security_status!=="clean"||!!Z.risky;default:return!1}})},[k,a,m,x]),A=()=>P("sync",()=>Ae("/api/limix/hub/sync",{})),I={excellent:"bg-emerald-500/15 text-emerald-500",recommended:"bg-sky-500/15 text-sky-500",review:"bg-amber-500/15 text-amber-500",rejected:"bg-danger/15 text-danger"},_="rounded-md bg-ink/[0.06] px-1.5 py-0.5 text-[11px] text-ink-secondary",D=N=>{window.confirm(z(`CẢNH BÁO: "${N.name}" bị cách ly vì ${N.risky??"có dấu hiệu nguy hiểm"}
11
11
 
12
12
  Không khuyến khích cài. Kỹ năng này có thể chứa mã độc hoặc lệnh nguy hiểm. Chỉ cài nếu bạn hiểu rõ và tin tưởng nguồn ${N.source.repository??"này"}.
13
13
 
@@ -15,5 +15,5 @@ Vẫn cài đặt (kỹ năng sẽ ở trạng thái tắt)?`,`WARNING: "${N.nam
15
15
 
16
16
  Installing is not recommended. This skill may contain malware or dangerous commands. Only install it if you understand the risk and trust ${N.source.repository??"the source"}.
17
17
 
18
- Install anyway (the skill will stay switched off)?`))&&I(N.id,()=>Ae("/api/limix/hub/install",{id:N.id,allowRisky:!0}))},X=N=>{!N.enabled&&N.risky&&!window.confirm(z(`"${N.name}" bị cách ly (${N.risky}). Vẫn bật cho bot dùng?`,`"${N.name}" is quarantined (${N.risky}). Switch it on for bots anyway?`))||I(N.id,()=>Ae("/api/limix/hub/enable",{id:N.id,enabled:!N.enabled}))},H=N=>{const Z=N.description_vi||N.description,te=f===N.id,R=(N.permissions.runs_code||N.permissions.mcp)&&!N.blocked;return e.jsx("li",{className:"px-4 py-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[14px] font-semibold text-ink",children:N.name}),e.jsxs("span",{className:`rounded-md px-1.5 py-0.5 text-[11px] font-medium ${P[N.grade]??"bg-ink/10 text-ink-secondary"}`,children:[N.quality_score,"/100 · ",xx(N.grade)??N.grade]}),typeof N.stars=="number"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[12px] text-ink-secondary",children:[e.jsx(Uo,{size:12}),N.stars.toLocaleString(z("vi-VN","en-US"))]})]}),e.jsx("p",{className:`mt-1 text-[12.5px] leading-relaxed text-ink-secondary ${te?"":"line-clamp-3"}`,children:Z}),Z.length>220&&e.jsx("button",{type:"button",className:"mt-0.5 text-[12px] text-ink underline-offset-2 hover:underline",onClick:()=>j(te?null:N.id),children:te?z("Thu gọn","Show less"):z("Xem thêm","Show more")}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:_,children:hx(N.kind)??N.kind}),e.jsxs("span",{className:`${_} ${N.security_status==="clean"?"":N.security_status==="quarantined"?"!bg-danger/15 !text-danger":"!bg-amber-500/15 !text-amber-500"}`,children:[z("Bảo mật","Security"),": ",ns(N.security_status)??N.security_status]}),e.jsx("span",{className:_,children:N.license??z("Chưa có giấy phép","No license")}),N.dependencies.length>0&&e.jsxs("span",{className:_,children:[z("Cần","Needs"),": ",N.dependencies.join(", ")]})]}),e.jsxs("p",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-tertiary",children:[N.source.repository??z("Không rõ nguồn","Unknown source"),N.created_at&&z(` · Tạo ${qe(N.created_at)}`,` · Created ${qe(N.created_at)}`),N.pushed_at&&z(` · Cập nhật ${qe(N.pushed_at)}`,` · Updated ${qe(N.pushed_at)}`),N.stats_checked&&z(` · số sao đo ngày ${qe(N.stats_checked)}`,` · stars measured ${qe(N.stats_checked)}`)]}),N.risky&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 rounded-lg bg-danger/10 p-2 text-[12px] leading-relaxed text-danger",children:[e.jsx(xn,{size:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[N.risky," ",z("Không khuyến khích cài.","Installing is not recommended.")]})]}),N.blocked&&e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-danger",children:[e.jsx(xn,{size:13}),N.blocked]}),R&&e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 bg-raised/50 p-2.5 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("button",{type:"button",className:"text-ink underline-offset-2 hover:underline",onClick:()=>y(b===N.id?null:N.id),children:b===N.id?z("Ẩn hướng dẫn cài đặt","Hide install guide"):z("Kỹ năng này có tool: xem hướng dẫn cài đặt","This skill has tools: see the install guide")}),b===N.id&&e.jsxs("ol",{className:"mt-2 list-decimal space-y-1.5 pl-4",children:[e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài kỹ năng:"}),' bấm "Cài đặt". Mặc định chỉ lấy phần hướng dẫn (SKILL.md). Kỹ năng được tải từ GitHub và kiểm tra SHA-256 từng file.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the skill:"}),' press "Install". By default only the instructions (SKILL.md) are taken. The skill is downloaded from GitHub and every file is checked with SHA-256.']}))}),N.compatibility.runtimes.length>0&&e.jsxs("li",{children:[e.jsxs("b",{className:"text-ink",children:[z("Chuẩn bị máy","Prepare this computer"),":"]})," ",z("kỹ năng cần","the skill needs")," ",N.compatibility.runtimes.map(T=>T.name).join(", "),".",N.compatibility.runtimes.filter(T=>T.installerId).length>0&&e.jsxs(e.Fragment,{children:[" ",z("Limix Bot cài được","Limix Bot can install"),": ",N.compatibility.runtimes.filter(T=>T.installerId).map(T=>T.name).join(", "),". "]}),N.compatibility.runtimes.some(T=>!T.installerId)&&e.jsxs(e.Fragment,{children:[" ",z("Phải cài tay","Install by hand"),": ",N.compatibility.runtimes.filter(T=>!T.installerId).map(T=>T.name).join(", ")," (",z('Python: tải từ python.org, tick "Add python.exe to PATH"','Python: download from python.org, tick "Add python.exe to PATH"'),"). "]}),Wa()&&e.jsx("button",{type:"button",className:"ml-1 text-ink underline",onClick:()=>g(!0),children:z('Mở "Công cụ cho kỹ năng"','Open "Tools for skills"')})]}),N.permissions.runs_code&&e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài phần script:"}),' bấm "Cài đặt kèm tool". Các file script nằm trong thư mục kỹ năng và bot có thể chạy chúng. Chỉ làm khi bạn tin nguồn ',N.source.repository??"này"," (đã quét: ",ns(N.security_status)??N.security_status,")."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the scripts:"}),' press "Install with tools". The script files go in the skill folder and the bot can run them. Only do this if you trust ',N.source.repository??"the source"," (scanned: ",ns(N.security_status)??N.security_status,")."]}))}),N.permissions.mcp&&e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," file cấu hình MCP chỉ được chép vào thư mục kỹ năng, không tự bật. Muốn dùng, thêm máy chủ MCP ở Cài đặt rồi bật."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," the MCP config file is only copied into the skill folder and is not switched on. To use it, add the MCP server in Settings and turn it on."]}))}),e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Bật:"}),' sau khi cài, gạt công tắc "Đang tắt" sang bật, rồi mở cài đặt của bot → Kĩ Năng (Skills) để thêm.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Switch on:"}),' after installing, flip the "Off" switch to on, then add it in the bot’s Settings → Skills.']}))})]})]}),a==="security"&&N.security_findings?.slice(0,5).map((T,Y)=>e.jsxs("p",{className:"text-[11px] text-ink-tertiary",children:[T.severity," · ",T.rule," · ",T.file,T.line?`:${T.line}`:""]},Y)),N.notes.map(T=>e.jsx("p",{className:"mt-0.5 text-[11px] text-ink-tertiary",children:T},T))]}),e.jsx("div",{className:"flex shrink-0 flex-row flex-wrap items-center gap-2 sm:w-[168px] sm:flex-col sm:items-stretch",children:r===N.id?e.jsx(J,{size:15,className:"animate-spin text-ink-secondary sm:self-end"}):N.installed?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[N.enabled?z("Đang bật","On"):z("Đang tắt","Off"),e.jsx(ue,{checked:N.enabled,disabled:r!==null,onClick:()=>X(N)})]}),N.updateAvailable&&e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{I(N.id,()=>Ae("/api/limix/hub/update",{id:N.id,allowRisky:!!N.risky}))},children:[e.jsx(we,{size:14}),z("Cập nhật","Update")]}),e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{I(N.id,()=>Ae("/api/limix/hub/remove",{id:N.id}))},children:[e.jsx(Se,{size:14}),z("Gỡ","Remove")]})]}):e.jsxs(e.Fragment,{children:[N.risky?e.jsxs("button",{type:"button",className:`${Ue} justify-center !border-danger/40 !text-danger`,disabled:!!N.blocked||r!==null,onClick:()=>U(N),children:[e.jsx(Ye,{size:14}),z("Cài đặt (không khuyến khích)","Install (not recommended)")]}):e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:!!N.blocked||r!==null,onClick:()=>{I(N.id,()=>Ae("/api/limix/hub/install",{id:N.id}))},children:[e.jsx(Ye,{size:14}),z("Cài đặt","Install")]}),N.permissions.runs_code&&!N.blocked&&!N.risky&&e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{window.confirm(z(`Cài cả script của "${N.name}"? Bot có thể chạy các script này. Chỉ làm khi bạn tin nguồn.`,`Install the scripts of "${N.name}" too? Bots can run these scripts. Only do this if you trust the source.`))&&I(N.id,()=>Ae("/api/limix/hub/install",{id:N.id,allowTools:!0}))},children:[e.jsx(Ye,{size:14}),z("Cài đặt kèm tool","Install with tools")]})]})})]})},N.id)};return e.jsxs(Q,{title:z("Kho kỹ năng Limix","Limix Skill Catalog"),subtitle:z("Kĩ năng đã quét bảo mật và chấm điểm. Cài xong, kĩ năng nằm sẵn trong kho nhưng chưa bot nào dùng: mở bot → Kĩ Năng (Skills) → Kho Kĩ Năng (Skills) để thêm cho từng bot.","Skills that are security-scanned and scored. Once installed, a skill waits in the store and no bot uses it yet: open a bot → Skills → Skills Store to add it to one bot."),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:px.map(([N,Z])=>{const te=N==="installed"?k.filter(R=>R.installed).length:N==="updates"?k.filter(R=>R.updateAvailable).length:N==="discover"?k.length:null;return e.jsxs("button",{type:"button",onClick:()=>i(N),className:`rounded-lg px-2.5 py-1 text-[13px] ${a===N?"bg-raised text-ink":"text-ink-secondary hover:bg-raised-hover"}`,children:[Z(),te?e.jsx("span",{className:"ml-1 text-[11px] text-ink-tertiary",children:te}):null]},N)})}),o&&e.jsx("p",{className:"text-[12px] text-danger",children:o}),s?a==="settings"?e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] text-ink",children:[e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[z("Tự đồng bộ danh mục","Sync the catalog automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:z("Chỉ cập nhật danh sách, không cài gì.","Only refreshes the list, installs nothing.")})]}),e.jsx(ue,{checked:s.settings.autoSync,onClick:()=>{I("settings",()=>Ae("/api/limix/hub/settings",{autoSync:!s.settings.autoSync}))}})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[z("Tự cài kỹ năng mới","Install new skills automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:z("Mặc định tắt. Nếu bật: chỉ cài loại chỉ có hướng dẫn, đã duyệt, điểm từ 80; vẫn ở trạng thái tắt.","Off by default. When on: only instruction-only skills that are approved and score 80 or more are installed, and they stay switched off.")})]}),e.jsx(ue,{checked:s.settings.autoInstall,onClick:()=>{I("settings",()=>Ae("/api/limix/hub/settings",{autoInstall:!s.settings.autoInstall}))}})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{value:m,onChange:N=>u(N.target.value),placeholder:z("Tìm kỹ năng…","Search skills…"),className:"min-w-[160px] flex-1 rounded-lg border border-hairline/60 bg-card px-3 py-1.5 text-[13px] text-ink"}),e.jsxs("select",{value:p,onChange:N=>x(N.target.value),className:"rounded-lg border border-hairline/60 bg-card px-2 py-1.5 text-[13px] text-ink",children:[e.jsx("option",{value:"",children:z("Mọi nhóm","All categories")}),B.map(N=>e.jsx("option",{value:N,children:N},N))]}),a==="discover"&&e.jsxs("button",{type:"button",className:`${Ue} shrink-0`,disabled:r!==null,onClick:()=>{A()},children:[r==="sync"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),z("Đồng bộ ngay","Sync now")]})]}),a==="discover"&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",role:"status",children:[z("Đồng bộ gần nhất","Last sync"),": ",s.settings.lastSync?new Date(s.settings.lastSync).toLocaleString(z("vi-VN","en-US")):z("chưa lần nào","never")]}),s.settings.lastError&&e.jsxs("p",{className:"text-[12px] text-danger",children:[z("Lỗi đồng bộ gần nhất","Last sync error"),": ",s.settings.lastError]})]}),v.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:k.length===0?z("Chưa có danh mục. Mở Khám phá và bấm Đồng bộ ngay.","No catalog yet. Open Discover and press Sync now."):z("Không có kỹ năng nào ở mục này.","No skills in this tab.")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",children:[v.length," ",z("kỹ năng","skills")]}),e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40 bg-card",children:v.slice(0,C).map(H)}),v.length>C&&e.jsx("button",{type:"button",className:`${Ue} w-fit self-center`,onClick:()=>w(N=>N+at),children:z(`Xem thêm ${Math.min(at,v.length-C)} kỹ năng`,`Show ${Math.min(at,v.length-C)} more`)})]}),a==="installed"&&v.length>0&&e.jsxs("p",{className:"flex items-center gap-1 text-[12px] text-ink-tertiary",children:[e.jsx(ge,{size:13}),z("Kỹ năng đã bật nằm trong thư viện bên dưới. Mở cài đặt của từng bot → Kĩ Năng (Skills) để thêm.","Enabled skills are in the library below. Add them from each bot’s Settings → Skills.")]})]}):e.jsx(J,{size:15,className:"animate-spin text-ink-secondary"})]}),h&&e.jsx(Ga,{onClose:()=>g(!1)})]})}function fx(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 sr({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(Ns())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function bx(){const[s,n]=l.useState([]),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(""),[m,u]=l.useState(null),[p,x]=l.useState(null),[h,g]=l.useState(""),[b,y]=l.useState(""),[f,j]=l.useState(!1),[C,w]=l.useState(""),S=l.useRef(!1),I=l.useMemo(()=>[...new Set(s.flatMap(U=>U.tags))].sort((U,X)=>U.localeCompare(X)),[s]),k=fx(s,o,m),B=async U=>{try{const X=await fetch("/api/skills-library"),H=await X.json();if(!X.ok)throw new Error(H.error??t("skills.library.loadError"));if(U?.())return;n(H.skills??[]),c("")}catch(X){U?.()||c(X instanceof Error?X.message:t("skills.library.loadError"))}finally{U?.()||i(!1)}};l.useEffect(()=>{let U=!1;return i(!0),B(()=>U),()=>{U=!0}},[]);const v=async(U,X=!1)=>{if(!S.current){if(!U.enabled&&!X)return A(U,!0);S.current=!0,g(U.name),c("");try{const H=await fetch(`/api/skills-library/${encodeURIComponent(U.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!U.enabled})}),N=await H.json();if(!H.ok)throw new Error(N.error??t("skills.error.update"));X&&x(null),await B()}catch(H){c(H instanceof Error?H.message:t("skills.error.update"))}finally{S.current=!1,g("")}}},A=async(U,X=!1)=>{c("");try{const H=await fetch(`/api/skills-library/${encodeURIComponent(U.name)}`),N=await H.json();if(!H.ok)throw new Error(N.error??t("skills.error.load"));if(!N.text)throw new Error(t("skills.error.contentsImport"));x({skill:U,text:N.text,review:X})}catch(H){c(H instanceof Error?H.message:t("skills.error.load"))}},P=async()=>{const U=b.trim();if(U){j(!0),c(""),w("");try{const X=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:U})}),H=await X.json();if(!X.ok)throw new Error(H.error??t("skills.error.import"));w(t("skills.library.imported",{name:H.skill?.name??""})),y(""),await B()}catch(X){c(X instanceof Error?X.message:t("skills.error.import"))}finally{j(!1)}}},_="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(mx,{}),e.jsx(ux,{}),e.jsx(gx,{}),e.jsx(Q,{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(mt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:_,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:o,onChange:U=>d(U.target.value)})]}),I.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u(null),className:m===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")}),I.map(U=>e.jsx("button",{type:"button",onClick:()=>u(m===U?null:U),className:m===U?"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:U},U))]}),a?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):k.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:s.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:k.map(U=>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:()=>{A(U)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:U.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:U.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:U.description})]}),e.jsx(ue,{checked:U.enabled,"aria-label":U.enabled?t("skills.library.disable",{skill:U.name}):t("skills.library.enable",{skill:U.name}),disabled:!!(h||f),onClick:()=>{v(U)}})]}),e.jsx(sr,{skill:U}),U.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:U.warnings.join(" · ")})]},U.name))}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}),e.jsx(Q,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:U=>{U.preventDefault(),P()},children:[e.jsx("textarea",{className:`${_} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:b,onChange:U=>y(U.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:C}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:f||!!h||!b.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:f?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),p&&e.jsx(ti,{modal:!0,children:e.jsx(yx,{viewing:p,error:r,working:!!h,onClose:()=>{h||x(null)},onEnable:()=>{v(p.skill,!0)}})})]})}function yx({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=l.useRef(null);return Gc(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(sr,{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 vx(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 la({config:s}){const n=vx(s);return n?e.jsxs("div",{role:"status",className:M("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(Be,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function nr(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const kx=()=>D("/api/fleet");function jx({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,o=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:M("text-right",r||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:o}),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:[ot(i.usage.costUsd)?ct(i.usage.costUsd):"—",ot(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ct(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 Nx({domain:s,onCreated:n,disabled:a}){const[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,p]=l.useState(""),[x,h]=l.useState(""),[g,b]=l.useState(!1),[y,f]=l.useState(null),j=async()=>{if(!g){b(!0),f(null);try{const w={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(I=>I.trim()).filter(Boolean),...u.trim()?{cap:Number(u)}:{},...x.trim()?{anthropicKey:x.trim()}:{}},S=await D("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});r(""),o(""),m(""),p(""),h(""),n(S.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){f(w instanceof Error?w.message:String(w))}finally{b(!1)}}},C="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(),j()},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||g,"aria-label":t("workspaces.name"),className:C}),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=>o(w.target.value),type:"email",required:!0,disabled:a||g,"aria-label":t("workspaces.adminEmail"),className:C})]}),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=>m(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||g,"aria-label":t("workspaces.members"),className:C})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:u,onChange:w=>p(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||g,"aria-label":t("workspaces.cap"),className:C})]}),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:x,onChange:w=>h(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||g,"aria-label":t("workspaces.anthropicKey"),className:C})]})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),y&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:y}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||g,className:"ui-button ui-button-primary",children:[g?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),g?t("workspaces.creating"):t("workspaces.create")]})})]})}function wx({slug:s,onDone:n}){const[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),p=async x=>{if(!o){d(x),u(null);try{const h=await D(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:x,email:a.trim(),chatOnly:r})});i(""),n(h.log??[])}catch(h){u(h instanceof Error?h.message:String(h))}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:x=>i(x.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:o!==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:x=>c(x.target.checked),disabled:o!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{p("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:o==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{p("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:o==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Sx({load:s=kx}){const{state:n}=V(),[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[p,x]=l.useState([]),[h,g]=l.useState(null),[b,y]=l.useState(null),[f,j]=l.useState(!1),[C,w]=l.useState(null),S=l.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(v){c(v instanceof Error?v.message:String(v))}finally{d(!1)}},[s]);l.useEffect(()=>{S()},[S]);const I=async(v,A)=>{if(A==="users"){g(P=>P===v?null:v);return}if(A==="delete"){y({slug:v,keepData:!1});return}u(v),c(null);try{const P=await D(`/api/fleet/workspaces/${encodeURIComponent(v)}/${A}`,{method:"POST"});x(P.log??[]),await S()}catch(P){c(P instanceof Error?P.message:String(P))}finally{u(null)}},k=async()=>{if(!b)return;const{slug:v,keepData:A}=b;y(null),u(v),c(null);try{const P=await D(`/api/fleet/workspaces/${encodeURIComponent(v)}`,{method:"DELETE",body:JSON.stringify({keepData:A})});x(P.log??[]),await S()}catch(P){c(P instanceof Error?P.message:String(P))}finally{u(null)}},B=async()=>{u("*"),c(null);try{const v=await D("/api/fleet/upgrade",{method:"POST"});x(v.log??[t("workspaces.upgraded")]),await S()}catch(v){c(v instanceof Error?v.message:String(v))}finally{u(null)}};return nr(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(Q,{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:()=>{S()},disabled:o||m!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(we,{size:12,className:M(o&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>j(v=>!v),disabled:m!==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(Ce,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{B()},disabled:m!==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:m==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),f&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(Nx,{domain:a.domain,disabled:m!==null,onCreated:(v,A)=>{j(!1),x(v),w(`https://${A.slug}.${a.domain}/pair?email=${encodeURIComponent(A.admin)}`),S()}})}),C&&e.jsx("div",{className:"mb-4",children:e.jsx(zi,{link:C})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(jx,{fleet:a,onAct:(v,A)=>{I(v,A)},busy:m}):o?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("common.checking")]}):null,h&&e.jsx(wx,{slug:h,onDone:v=>{x(v),S()}}),p.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:p.join(`
19
- `)})]}),e.jsx(Qe,{open:b!==null,title:t("workspaces.deleteTitle",{slug:b?.slug??""}),body:t(b?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>y(null),onConfirm:()=>{k()}}),b&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:b.keepData,onChange:v=>y({...b,keepData:v.target.checked})}),t("workspaces.keepData")]})]}):null}const oa=[{choice:"system",label:"settings.theme.system"},{choice:en.light,label:"settings.theme.light"},{choice:en.dark,label:"settings.theme.dark"}];function Ks(){return l.useSyncExternalStore(Xr,tn,tn)}function ar({simple:s=!1}){const n=Ks(),a=oa.some(i=>i.choice===n)?void 0:Ss.find(i=>i.id===n)?.name;return e.jsx(ce,{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:oa.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Yr(i.choice),className:s?M("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"):M("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 Cx({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)"}})})]})]})]})}const Ex={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function Ax({festival:s}){const n=qc(),a=t("settings.skin.dressUp.title");return e.jsxs("div",{"data-dress-up":!0,className:"mt-4 flex items-center gap-4 rounded-xl border border-accent-border/40 bg-accent/[0.06] p-3",children:[e.jsx("div",{className:"flex shrink-0 -space-x-1.5","aria-hidden":"true",children:Ex[s].map(i=>e.jsx(Jc,{color:i,bodyId:Yc[s].costumes[i],size:30,animated:!1,trackPointer:!1},i))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:a}),e.jsx("div",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.skin.dressUp.subtitle")})]}),e.jsx(ue,{checked:n,"aria-label":a,onClick:()=>Xc(!n)})]})}function ir(){const s=wa(Ks());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:Ss.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Zr(n.id)},"aria-pressed":a,className:M("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",a?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Cx,{skin:n.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:n.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:Qr(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(ge,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),Vc(s)&&e.jsx(Ax,{festival:s})]})}function Ix(){const[s,n]=l.useState(el);return e.jsx(ce,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;sl(i),n(i)},children:tl.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Px(){const[s,n]=l.useState(nl);return e.jsx(ce,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=sn.find(r=>r===a.target.value);i&&(al(i),n(i))},children:sn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Rx(){const s=Do();return e.jsx(ce,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>_o($o(n.target.value)),children:Fo.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function rr(){const{state:s,dispatch:n}=V(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,p]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||x.current)return;const g=Wo(i);if(!g.ok){m(t("settings.roomTurns.range"));return}x.current=!0,p(!0);try{const b=await D("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:g.minutes}})});n({type:"configStatus",config:b}),r(String(b.rooms.turnTimeoutMinutes)),o(!1),m("")}catch(b){m(b instanceof Error?b.message:t("settings.roomTurns.error"))}finally{x.current=!1,p(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:Ho,max:Ko,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:g=>{r(g.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),d?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}const Tx=10,lr=1,or=60,ca="Enter a whole number from 1 to 60.";function Lx(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:ca};const a=Number(n);return a<lr||a>or?{ok:!1,error:ca}:{ok:!0,minutes:a}}function da(s){return s?.mcp?.callTimeoutMinutes??Tx}function cr(){const{state:s,dispatch:n}=V(),a=da(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,p]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||x.current)return;const g=Lx(i);if(!g.ok){m(t("settings.mcpCalls.range"));return}x.current=!0,p(!0);try{const b=await D("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:g.minutes}})});n({type:"configStatus",config:b}),r(String(da(b))),o(!1),m("")}catch(b){m(b instanceof Error?b.message:t("settings.mcpCalls.error"))}finally{x.current=!1,p(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:lr,max:or,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:g=>{r(g.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),d?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}function dr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(u,p)=>{a={value:u,status:p};for(const x of o)x()},m=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const u=a.value;await n(u),i=a.value!==u}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(u){return o.add(u),()=>{o.delete(u)}},confirm(u){!i&&!r&&u!==a.value&&d(u,"idle")},edit(u){i=!0,d(u,"idle"),clearTimeout(c),c=setTimeout(()=>{m()},600)},flush:m}}const ua=new WeakMap;function Bx(){const{state:s,dispatch:n}=V(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=ua.get(n);if(!r){const u={current:i};r={team:u,controller:dr(a,async p=>{const x=u.current?await As({aboutMe:p}):(await D("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:p}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:x?.aboutMe??p}})})},ua.set(n,r)}r.team.current=i;const c=r.controller,{value:o,status:d}=l.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:m}=c;return l.useEffect(()=>{c.confirm(a)},[c,a]),l.useEffect(()=>()=>{m()},[m]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(Go,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:i?4e3:24e3,onChange:u=>c.edit(u.target.value),onBlur:()=>{m()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Ox,{onChanged:u=>{c.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",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:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Ox({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let m=!1;return D("/api/profile/learned").then(u=>{m||a(u.learned)}).catch(()=>{}),()=>{m=!0}},[]);const d=async m=>{r(m),o(!1);try{const u=await D(`/api/profile/learned/${encodeURIComponent(m)}/remove`,{method:"POST"});a(u.learned),s(u.aboutMe)}catch{o(!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(m=>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:[m.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:m.botName})})]}),e.jsx("button",{type:"button",disabled:i===m.id,onClick:()=>{d(m.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")})]},m.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const ma=new WeakMap;function Mx(){const{state:s,dispatch:n}=V(),a=s.config?.everyBotRules;let i=ma.get(n);i||(i=dr(a??"",async u=>{const p=await D("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:u}),timeoutMs:1e4});n({type:"configStatus",config:p})}),ma.set(n,i));const{value:r,status:c}=l.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:o,edit:d,flush:m}=i;return l.useEffect(()=>{o(a??"")},[o,a]),l.useEffect(()=>()=>{m()},[m]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[14px] 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:u=>d(u.target.value),onBlur:()=>{m()},className:"min-h-[96px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsxs("div",{className:"min-h-4 text-[12px]",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:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const pa=64,xa=8192,jt=512;function zx(s){return Jo(s)?s.size>Yo?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function Ux(s,n){return s<pa||n<pa?"settings.profile.avatar.tooSmall":s>xa||n>xa?"settings.profile.avatar.tooLargeDimensions":null}async function ur(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const o=new Image;o.onload=()=>r(o),o.onerror=()=>c(new Error("invalid-image")),o.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function Dx(s,n){return ur(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=jt,r.height=jt;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,jt,jt);const o=await new Promise((d,m)=>r.toBlob(u=>u?d(u):m(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function Fx(){const{state:s,dispatch:n}=V(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,m]=l.useState(null),u=l.useRef(null),p=f=>{const j=u.current;j&&j.previewUrl!==f?.previewUrl&&URL.revokeObjectURL(j.previewUrl),u.current=f,m(f)};l.useEffect(()=>()=>{u.current&&URL.revokeObjectURL(u.current.previewUrl)},[]);const x=!!s.config?.team,h=async f=>{const j=x?await As({avatarUrl:f}):(await D("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:f}})})).profile;n({type:"profileSaved",profile:{avatarUrl:j?.avatarUrl}})},g=f=>{if(!f)return;o(null);const j=zx(f);if(j)return o(t(j));ur(f,C=>({width:C.naturalWidth,height:C.naturalHeight})).then(({width:C,height:w})=>{const S=Ux(C,w);if(S)return o(t(S));p({file:f,previewUrl:URL.createObjectURL(f),width:C,height:w,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},b=f=>{r(!0),o(null),Dx(f.file,f.zoom).then(j=>qo(j)).then(j=>{const C=j?Qc(j.path):null;if(!C)throw new Error("avatar");return h(C)}).then(()=>p(null),()=>o(t("settings.profile.avatar.saveError"))).finally(()=>r(!1))},y=()=>{o(null),h("").catch(()=>o(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[d?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:d.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${d.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:[d.width," × ",d.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:d.zoom,onChange:f=>p({...d,zoom:Number(f.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:()=>p(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:i,onClick:()=>b(d),children:t("settings.profile.avatar.save")})]})}):a?e.jsx("img",{src:a,alt:"",className:"size-12 rounded-full object-cover"}):e.jsx("div",{className:"size-12 rounded-full bg-raised"}),e.jsxs("label",{className:"cursor-pointer rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[i?t("settings.profile.avatar.uploading"):t("settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:i,onChange:f=>{const j=f.target.files?.[0];f.currentTarget.value="",g(j)}})]}),a&&!d&&e.jsx("button",{type:"button",className:"text-[12px] text-ink-secondary underline",onClick:y,children:t("settings.profile.avatar.remove")})]}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:c})]})}function mr(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(s.config?.profile?.name??""),[r,c]=l.useState(s.config?.profile?.email??"");l.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const o=!!s.config?.team,d=()=>{if(o){As({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(()=>{})},m="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-3",children:[e.jsx(Fx,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:m}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:m}),e.jsx(Bx,{}),e.jsx(Mx,{})]})}function _x({profile:s}){const[n,a]=l.useState(null),i=Vo(s),r=s?.avatarUrl&&n!==s.avatarUrl?s.avatarUrl:null;return e.jsx("span",{className:"flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-full bg-ink/[0.06] text-[15px] font-medium text-ink-secondary",children:r?e.jsx("img",{src:r,alt:"",onError:()=>a(r),className:"size-full object-cover"}):i!=="?"?i:e.jsx(Va,{size:20,"aria-hidden":"true"})})}function $x(){const{state:s}=V(),[n,a]=l.useState(!1),i=s.config?.profile,r=i?.name?.trim()??"",c=i?.email?.trim()??"",o=l.useId(),d=l.useRef(null);return l.useEffect(()=>{n&&d.current?.querySelector("input:not([type=file])")?.focus()},[n]),e.jsxs("div",{"data-profile-summary":"",className:"px-4 py-[13px]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_x,{profile:i}),e.jsx("div",{className:"min-w-0 flex-1",children:r||c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:r||c}),r&&c&&e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("settings.simple.account.yourName")}),e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.account.noNameHint")})]})}),e.jsx("button",{type:"button","aria-expanded":n,"aria-controls":o,className:"ui-button shrink-0",onClick:()=>a(!n),children:n?t("common.done"):t(r||c?"settings.simple.account.edit":"settings.simple.account.add")})]}),e.jsx("div",{id:o,ref:d,hidden:!n,className:"mt-4",children:n&&e.jsx(mr,{})})]})}function pr({row:s=!1}){const n=!!V().state.config?.team,[a,i]=l.useState(null),[r,c]=l.useState(!1),o=l.useId();l.useEffect(()=>{if(!n)return;let m=!0;return D("/api/me/away-emails",{timeoutMs:1e4}).then(u=>{m&&i(u.on)},()=>{}),()=>{m=!1}},[n]);const d=m=>{const u=a;i(m),c(!1),D("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:m}),timeoutMs:1e4}).then(p=>i(p.on),()=>{i(u),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:o,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(ue,{"aria-labelledby":o,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 xr(){const{state:s,dispatch:n}=V(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=l.useState(null),[o,d]=l.useState(""),m=l.useRef(!1),u=async p=>{if(!(m.current||p===a)){m.current=!0,c(p),d("");try{const x=await D("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:p}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.threads.error"))}finally{m.current=!1,c(null)}}};return e.jsxs(Q,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx(me,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:p=>{u(Number(p.target.value))},children:Array.from({length:16},(p,x)=>x+1).map(p=>e.jsx("option",{value:p,children:p},p))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:i?t("settings.threads.starter"):t("settings.threads.helpHanded")}),r!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function hr(){const{state:s,dispatch:n}=V(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),m=l.useRef(!1),u=a??s.config?.automaticRecovery??{enabled:!1},p=s.instances.filter(f=>f.snapshot.state==="available"&&!f.policy),x=p.find(f=>f.instanceId===u.backup?.instanceId),h=x?.models.options.filter(f=>!f.orgBlocked&&!f.needsCliUpdate&&(x.snapshot.authenticated!==!1||f.custom))??[],g=h.some(f=>f.id===u.backup?.model),b=f=>{i(f),d("")},y=async()=>{if(!(!a||m.current||u.enabled&&!g)){m.current=!0,c(!0),d("");try{const f=await D("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:f}),i(null)}catch(f){d(f instanceof Error?f.message:t("settings.recovery.error"))}finally{m.current=!1,c(!1)}}};return e.jsxs(Q,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(ue,{id:"automatic-recovery-enabled",checked:u.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>b({...u,enabled:!u.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scopeHanded")}),e.jsx("p",{id:"automatic-recovery-own",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.ownBackups")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs(me,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:u.backup?.instanceId??"",disabled:r||!u.enabled,onChange:f=>b({enabled:u.enabled,...f.target.value?{backup:{instanceId:f.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),u.backup&&!x&&e.jsx("option",{value:u.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.instanceId})}),p.map(f=>e.jsx("option",{value:f.instanceId,disabled:!f.models.options.some(j=>f.snapshot.authenticated!==!1||j.custom),children:f.displayName},f.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs(me,{className:"mt-2 w-full",id:"automatic-recovery-model",value:u.backup?.model??"",disabled:r||!u.enabled||!x,onChange:f=>b({enabled:u.enabled,backup:{instanceId:x.instanceId,model:f.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),u.backup?.model&&!g&&e.jsx("option",{value:u.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.model})}),h.map(f=>e.jsx("option",{value:f.id,children:f.label},f.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),u.enabled&&!g&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||u.enabled&&!g,onClick:()=>{y()},className:"mt-3 cursor-pointer rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:r?t("settings.threads.saving"):t("common.save")}),r&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}const gr=1,fr=3650,Kx=30,At=1024*1024,bs=256*1024,br=4*1024*1024*1024,Hx=50;function ha(s){const n=Number(s);return Number.isInteger(n)&&n>=gr&&n<=fr?n:null}function ga(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*At);return a>=bs&&a<=br&&a%bs===0?a:null}function fa(s){const n=s/At;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function yr(){const{state:s,dispatch:n}=V(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(null),[p,x]=l.useState(""),[h,g]=l.useState(null),b=l.useRef(!1),y=r??String(a===null?Kx:a),f=o??(i===null?String(Hx):fa(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&fa(i)===o&&d(null)},[i,o]);const j=async(k,B)=>{if(!b.current){b.current=!0,u(B),x(""),g(null);try{const v=await D("/api/config",{method:"PATCH",body:JSON.stringify({threads:k})});n({type:"configStatus",config:v})}catch(v){x(v instanceof Error?v.message:t("settings.threadCleanup.error"))}finally{b.current=!1,u(null)}}},C=k=>{if(!k){c(null),x(""),g(null),j({eventLogRetentionDays:null},"retention");return}const B=ha(y);if(B===null){x(t("settings.threadCleanup.invalidRetention")),g("retention");return}j({eventLogRetentionDays:B},"retention")},w=k=>{if(!k){d(null),x(""),g(null),j({eventLogMaxBytes:null},"cap");return}const B=ga(f);if(B===null){x(t("settings.threadCleanup.invalidCap")),g("cap");return}j({eventLogMaxBytes:B},"cap")},S=()=>{if(a===null)return;const k=ha(y);if(k===null){x(t("settings.threadCleanup.invalidRetention")),g("retention");return}if(k===a){c(null),x("");return}j({eventLogRetentionDays:k},"retention")},I=()=>{if(i===null)return;const k=ga(f);if(k===null){x(t("settings.threadCleanup.invalidCap")),g("cap");return}if(k===i){d(null),x("");return}j({eventLogMaxBytes:k},"cap")};return e.jsxs(Q,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:m!==null,onChange:k=>C(k.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:gr,max:fr,step:1,inputMode:"numeric",value:y,disabled:a===null||m!==null,"aria-invalid":h==="retention","aria-describedby":"thread-log-retention-help",onChange:k=>{c(k.target.value),x(""),g(null)},onBlur:S,onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:m!==null,onChange:k=>w(k.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:bs/At,max:br/At,step:.25,inputMode:"decimal",value:f,disabled:i===null||m!==null,"aria-invalid":h==="cap","aria-describedby":"thread-log-cap-help",onChange:k=>{d(k.target.value),x(""),g(null)},onBlur:I,onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),m!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}const ba="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function Wx(){const s=il(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=nn,m=()=>{const u=rl({name:n,url:i},window.location.origin);if(!u.ok){o(u.error);return}an([...s,{id:ll(s),name:u.name,url:u.url}]),a(""),r(""),o("")};return e.jsx(Q,{title:t("webPanels.settings.title"),subtitle:t("webPanels.settings.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[s.length>0&&e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-lg border border-hairline/40",children:s.map(u=>e.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:u.url,children:u.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>an(s.filter(p=>p.id!==u.id)),children:t("webPanels.settings.remove")})]},u.id))}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{"aria-label":t("webPanels.settings.name"),placeholder:t("webPanels.settings.name"),value:n,maxLength:rn,disabled:d,"aria-invalid":c==="name",onChange:u=>{a(u.target.value),o("")},className:`${ba} sm:w-40 ${c==="name"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("input",{"aria-label":t("webPanels.settings.url"),placeholder:"https://",type:"url",inputMode:"url",value:i,disabled:d,"aria-invalid":c==="url"||c==="self",onChange:u=>{r(u.target.value),o("")},onKeyDown:u=>{u.key==="Enter"&&m()},className:`${ba} flex-1 ${c==="url"||c==="self"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:m,children:t("webPanels.settings.add")})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:rn})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:nn}):t("webPanels.settings.help")})]})})}const as="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Je=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Oe(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},ya=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Gx(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=l.useState(null),r=l.useRef(0),c=l.useRef(0);return l.useEffect(()=>{const o=++r.current,d=c.current;i(null);const m=p=>{r.current===o&&(c.current++,i(p))},u=s?.onState(m);return s?.state().then(p=>{c.current===d&&m(p)}).catch(()=>{}),()=>{r.current++,u?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Vx,{bridge:n}):e.jsx(qx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Vx({bridge:s}){const[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(""),d=l.useRef(0);if(l.useEffect(()=>{const u=++d.current,p=s.onState(x=>{u===d.current&&a(x.schedule??null)});return s.state().then(x=>{u===d.current&&a(x.schedule??null)}).catch(()=>{}),()=>{d.current++,p()}},[s]),!s.configureSchedule||!n?.enabled)return null;const m=async()=>{if(i||!s.configureSchedule)return;const u=d.current;r(!0),o("");try{const p=await s.configureSchedule({enabled:!1});u===d.current&&a(p.schedule??null)}catch{u===d.current&&o(t("companyBackup.scheduleFailed"))}finally{u===d.current&&r(!1)}};return e.jsx(Q,{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(ue,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{m()}})]}),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 qx({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[p,x]=l.useState(""),[h,g]=l.useState(null),[b,y]=l.useState(""),[f,j]=l.useState(""),[C,w]=l.useState(null),[S,I]=l.useState(!1),k=l.useRef(0),B=l.useRef(0),v=l.useRef(0),A=l.useRef(void 0),P=l.useRef(!1),_=l.useRef(null),U=async()=>{const K=k.current,ae=++v.current,L=B.current;d(!0);try{await Promise.all([n.state().then(E=>{K===k.current&&ae===v.current&&B.current===L&&i(E)}),n.list().then(E=>{K===k.current&&ae===v.current&&c(E)})]),K===k.current&&ae===v.current&&x("")}catch{K===k.current&&ae===v.current&&x(t("companyBackup.loadFailed"))}finally{K===k.current&&ae===v.current&&d(!1)}};l.useEffect(()=>{const K=++k.current,ae=E=>{if(K!==k.current)return;B.current++,i(E);const W=E.lastBackupAt??E.schedule?.lastBackupAt;!E.busy&&!E.pendingRestore&&W&&W!==A.current&&(A.current=W,U())},L=n.onState(ae);return U(),()=>{k.current++,v.current++,L()}},[n]),l.useEffect(()=>{const K=_.current;if(!(!h||!K))return K.showModal(),()=>{K.close()}},[h]);const X=S||a?.pendingRestore===!0,H=m!==null||!a||a.busy||X,N=()=>{g(null),y(""),j(""),w(null)},Z=K=>{H||P.current||(x(""),y(""),j(""),w(null),g(K))},te=async(K,ae)=>{if(H||P.current)return;P.current=!0,u(K),x("");const L=k.current;try{await ae(()=>L===k.current)}catch{L===k.current&&x(t(K==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{P.current=!1,L===k.current&&u(null)}},R=()=>{h?.kind==="create"&&te("create",async K=>{await n.create({clientState:Qo()}),K()&&(N(),await U())})},T=async K=>{if(!n.configureSchedule||P.current||!a||K&&(H||h?.kind!=="schedule"||f!=="BACK UP THIS WORKSPACE DAILY"))return;P.current=!0,u("schedule"),x("");const ae=k.current,L=B.current;j("");try{const E=await n.configureSchedule(K?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});ae===k.current&&(B.current===L&&i(E),N())}catch{ae===k.current&&x(t("companyBackup.scheduleFailed"))}finally{P.current=!1,ae===k.current&&u(null)}},Y=()=>{h?.kind!=="restore"||h.entry.passwordRequired!==!1&&(b.length<12||b.length>1024)||te("prepare",async K=>{const ae=b;y(""),w(null),j("");const L=await n.prepareRestore({id:h.entry.id,...h.entry.passwordRequired!==!1?{password:ae}:{}});K()&&w(L)})},re=()=>{h?.kind!=="restore"||!C||f!=="REPLACE"||te("restore",async K=>{const ae=localStorage.getItem(gn);if(ae&&ae!==C.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(gn,C.id),await n.restore({id:C.id,confirmation:"REPLACE"}),K()&&(I(!0),N())})},pe=()=>{h?.kind!=="delete"||f!=="DELETE"||te("delete",async K=>{await n.delete({id:h.entry.id,confirmation:"DELETE"}),K()&&(N(),await U())})},xe=async()=>{const K=k.current;try{await n.cancel()}catch{K===k.current&&x(t("companyBackup.actionFailed"))}},le=r?.backups.filter(K=>K.status==="ready")??[],$=r?r.backups.length-le.length:0,ne=a?.progress,fe=p||a?.message,oe=(a?.busy||m)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:m==="restore"?t("backup.restoring"):ne?t(`companyBackup.phase.${ne.phase}`):t("companyBackup.working")}),ne&&ne.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:ne.totalBytes,value:Math.min(ne.bytesTransferred,ne.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Je(ne.bytesTransferred),total:Je(ne.totalBytes)})})]}),a?.busy&&m!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{xe()},children:t("companyBackup.cancelTransfer")})]}),se=h?.kind==="restore"?t("companyBackup.restore"):h?.kind==="delete"?t("companyBackup.delete"):h?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ie=a?.schedule,be=K=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(K));return e.jsxs(Q,{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&&ie&&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(ue,{"aria-label":t("companyBackup.daily"),checked:ie.enabled,disabled:m!==null||!a||!ie.enabled&&H,onClick:()=>ie.enabled?void T(!1):Z({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ie.status}`)}),ie.enabled&&ie.nextBackupAt&&Number.isFinite(ie.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:be(ie.nextBackupAt)})}),ie.lastBackupAt&&Number.isFinite(ie.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:be(ie.lastBackupAt)})}),ie.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ie.message})]}),X?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(hn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:H,onClick:()=>Z({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m!==null||a?.busy||X||o,onClick:()=>{U()},children:t("companyBackup.refresh")})]}),o&&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:Je(r.usedBytes),total:Je(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),$>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:$})}),r&&le.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:le.map(K=>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:ya(K)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Je(K.sizeBytes),K.appVersion?` · ${K.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:K.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:H,onClick:()=>Z({kind:"restore",entry:K}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H,onClick:()=>Z({kind:"delete",entry:K}),children:t("companyBackup.delete")})]})]},K.id))})]}),!h&&oe,!h&&fe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:fe})]}),h&&e.jsx("dialog",{ref:_,"aria-labelledby":"company-backup-dialog-title",onKeyDown:K=>{(K.key==="Escape"||K.key==="Tab")&&K.stopPropagation()},onCancel:K=>{K.preventDefault(),m||N()},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}),X&&e.jsx(hn,{}),(h.kind==="restore"||h.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[ya(h.entry)," · ",Je(h.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:h.entry.id})]}),(h.kind==="create"||h.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:K=>{K.preventDefault(),h.kind==="schedule"?T(!0):R()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(h.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),h.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")}),h.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:H,checked:f==="BACK UP THIS WORKSPACE DAILY",onChange:K=>j(K.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:H||h.kind==="schedule"&&f!=="BACK UP THIS WORKSPACE DAILY",children:t(h.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),h.kind==="restore"&&(C?e.jsxs(e.Fragment,{children:[e.jsx(Xo,{summary:C.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:H,value:f,onChange:K=>j(K.target.value),className:as})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H||f!=="REPLACE",onClick:re,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:K=>{K.preventDefault(),Y()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),h.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:H,value:b,onChange:K=>y(K.target.value),className:as})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:H||h.entry.passwordRequired!==!1&&(b.length<12||b.length>1024),children:t("backup.validate")})]})),h.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:H,value:f,onChange:K=>j(K.target.value),className:as})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H||f!=="DELETE",onClick:pe,children:t("companyBackup.delete")})]}),oe,fe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:fe}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:m!==null,onClick:N,children:t("companyBackup.cancel")})]})})]})}function Jx({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(dc,{size:12},a);case"gemini":return e.jsx(Ta,{preset:"google",size:12},a);default:return e.jsx(cc,{size:12},a)}})})}function va({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:o,onChange:d}){return e.jsxs("label",{className:M("flex items-start gap-3 px-3.5 py-3 transition-colors",o?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:o,onChange:m=>d(m.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(Jx,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const vr="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 Yx({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:o}){const d=i==="working";let m;if(!s)m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)m=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:u,notes:p,done:x}=nc(r);m=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:M("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",x?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:x?e.jsx(ge,{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:u}),p.map(h=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:h},h))]})]})}else!n||ic(n)===0?m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):m=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(va,{icon:e.jsx(Is,{size:15}),label:t("onboarding.import.skills"),summary:rc(n),hint:t("onboarding.import.skillsHint"),sources:fn(n.skills),checked:a.skills,disabled:d,onChange:u=>c({...a,skills:u})}),n.tools.length>0&&e.jsx(va,{icon:e.jsx(oc,{size:15}),label:t("onboarding.import.tools"),summary:lc(n),hint:t("onboarding.import.toolsHint"),sources:fn(n.tools),checked:a.tools,disabled:d,onChange:u=>c({...a,tools:u})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:o,disabled:d||!(a.skills||a.tools),className:M(vr,"mt-3"),children:[d&&e.jsx(J,{size:14,className:"animate-spin"}),d?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return 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:m})]})}function Xx({client:s,local:n}){const[a,i]=l.useState(void 0),[r,c]=l.useState({skills:!0,tools:!0}),[o,d]=l.useState("idle"),[m,u]=l.useState(null);l.useEffect(()=>{if(!n)return;const x=new AbortController;return s.detect(x.signal).then(i,()=>i(null)),()=>x.abort()},[s,n]);const p=async()=>{if(!a||o==="working")return;const x={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!x.skills&&!x.tools)){d("working");try{const h=await s.apply(x);Zc("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),u(h),d("idle")}catch{d("failed")}}};return e.jsx(Yx,{local:n,detection:a,chosen:r,status:o,result:m,onChoose:c,onBring:()=>{p()}})}function Qx(){const[s,n]=l.useState(!1),[a,i]=l.useState(!1);return 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(tc,{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:M(vr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Na,{size:14,"aria-hidden":"true",className:M("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(sc,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function kr({client:s=Zo}){const{state:n}=V();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Xx,{client:s,local:ec(n.config?.cloudHome===!0)}),e.jsx(Qx,{})]})}function jr({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(Zx,{simple:s}),e.jsx(eh,{simple:s}),e.jsx(th,{simple:s})]})}const ka=()=>typeof Notification<"u"?Notification.permission:"default";function Zx({simple:s=!1}){const[n,a]=l.useState(ka),i=mc();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(ka())};return window.addEventListener("focus",o),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",o),document.removeEventListener("visibilitychange",o)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return bn(!i);const o=await fc();o&&(a(o),o==="granted"&&bn(!0))};return e.jsx(ce,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(ue,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function eh({simple:s=!1}){const n=pc();return e.jsx(ce,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(ue,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>xc(!n)})})}function th({simple:s=!1}){const n=hc();return e.jsx(ce,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(ue,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>gc(!n)})})}function Nr(){const{state:s,dispatch:n}=V(),a=bc(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!yc(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const m=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:m})}catch(m){o(m instanceof Error?m.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(ce,{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(ue,{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 sh=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],nh=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function ah({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(ye,{label:t("settings.group.account"),block:"general",children:e.jsxs(ve,{children:[s("general")&&e.jsx($x,{}),s("general")&&e.jsx(pr,{row:!0}),s("general")&&e.jsx(hi,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(Ui,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(ye,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(ve,{children:[e.jsx(ar,{simple:!0}),e.jsx(ih,{onLooks:a}),e.jsx(Hi,{}),e.jsx(Ya,{}),e.jsx(Wi,{}),e.jsx(mi,{simple:!0})]})}),s("appearance")&&e.jsx(ye,{label:t("settings.simple.group.typing"),children:e.jsxs(ve,{children:[e.jsx(ls,{simple:!0}),e.jsx(pi,{simple:!0}),e.jsx(xi,{simple:!0})]})}),s("appearance")&&e.jsx(ye,{label:t("notifications.title"),children:e.jsx(ve,{children:e.jsx(jr,{simple:!0})})}),s("general")&&e.jsx(ye,{label:t("settings.simple.group.system"),children:e.jsxs(ve,{children:[e.jsx(vi,{simple:!0}),e.jsx(Xa,{simple:!0}),e.jsx(ki,{}),e.jsx(ji,{}),e.jsx(yi,{simple:!0})]})}),s("import")&&e.jsx(ye,{label:t("settings.section.import"),block:"import",children:e.jsx(ke,{children:e.jsx(kr,{})})}),s("organization")&&e.jsx(ye,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Vi,{})}),s("activity")&&e.jsx(ye,{label:t("settings.section.activity"),block:"activity",children:e.jsx(Di,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(ve,{children:e.jsx(ce,{title:t("settings.simple.more.title"),subtitle:t("settings.simple.more.subtitle"),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more":"",onClick:i,children:t("settings.simple.more.open")})})})}),e.jsx("div",{"data-settings-block":"advanced-mode",className:"scroll-mt-4",children:e.jsx(ve,{children:e.jsx(os,{simple:!0})})})]})}function ih({onLooks:s}){const n=Ks(),a=Ss.find(r=>r.id===wa(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(ce,{title:t("settings.theme.title"),subtitle:i,children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.themes.browse")})})}function rh({onBack:s,toolCalls:n=!0}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.looks.back")})}),e.jsx("div",{"data-settings-block":"looks",children:e.jsx(ir,{})}),n&&e.jsx(ve,{children:e.jsx(ui,{})})]})}function lh({sections:s,onOpen:n,onBack:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("settings.simple.looks.back")})}),s.length>0&&e.jsx(ye,{block:"more-sections",children:e.jsx(ve,{children:s.map(({id:i,labelKey:r})=>e.jsx(ce,{title:t(r),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more-section":i,onClick:()=>n(i),children:t("settings.simple.more.open")})},i))})}),e.jsx(ye,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Q,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(rr,{})}),e.jsx(Q,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(cr,{})}),e.jsx(xr,{}),e.jsx(hr,{}),e.jsx(yr,{}),e.jsx(Ai,{}),e.jsx(ve,{children:e.jsx(Nr,{})})]})})]})}function oh({has:s,disclose:n,connections:a}){return e.jsxs(e.Fragment,{children:[s("engines")&&e.jsx("div",{"data-settings-block":"engines",className:"flex scroll-mt-4 flex-col gap-7",children:e.jsxs(ke,{children:[e.jsx(Pi,{simple:!0,more:n("ai-more")}),e.jsx(ve,{children:e.jsx(di,{simple:!0})})]})}),s("connections")&&e.jsx(ke,{children:e.jsx(Rt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function ch({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(ye,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(ke,{children:e.jsx(Bi,{})})}),s("companion")&&e.jsxs(ye,{label:t(Ja()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(ye,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(ve,{children:[e.jsx(li,{}),e.jsx(oi,{})]}),e.jsx(ci,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(Ki,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(Rt,{title:t("settings.simple.computer.elsewhere"),block:"elsewhere",...i("computer-elsewhere"),children:[s("desktopWorkspaces")&&e.jsx("div",{"data-settings-block":"desktopWorkspaces",className:"flex scroll-mt-4 flex-col gap-4",children:a}),s("companion")&&e.jsx("div",{"data-settings-block":"remote",className:"flex scroll-mt-4 flex-col gap-4 empty:hidden",children:n.client})]})]})}function dh({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=vc();return vd(),e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(kc,{usage:i,upgrade:r,children:c}):e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(Qp,{})})}),(i||s("usage"))&&e.jsxs(Rt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(jc,{usage:i,upgrade:r}),s("usage")&&e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(tr,{})})]}),s("cloudAccount")&&e.jsxs(ye,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(kd,{}),children:[e.jsx(ve,{children:e.jsx(hi,{place:"plan",usage:i,upgrade:r})}),e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const wr=()=>`${ks()} ${Nc()}`;function uh(){const s=wc(!0);if(!s)return null;const n=s.phase==="idle"?void 0:[s.label,s.item.subtitle].filter(Boolean).join(" "),a=s.phase==="available"?t("settings.simple.updates.seeRelease"):s.phase==="reload"?t("settings.simple.updates.reload"):s.phase==="checking"?t("common.checking"):t("settings.updates.check");return e.jsx(ce,{title:wr(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function mh({remoteActive:s}){return e.jsx(ye,{block:"updates",children:e.jsxs(ve,{children:[window.ogb?.updater?e.jsx(ii,{title:wr()}):e.jsx(uh,{}),e.jsx(qa,{}),!s&&e.jsx(ri,{}),e.jsx(Ni,{simple:!0})]})})}const ja=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Hs=[{id:"general",group:"you",labelKey:"settings.section.general",icon:Va,keywords:["profile","pinned panels","web panel","dashboard","pin a page","name","email","about me","about","suggestions","suggested","memory","analytics","updates","product updates","newsletter","email updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","attachments","clear attachments","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule","usage","limit","plan","upgrade","cloud desktop hours","storage","saved steps","repeat","replay","computer tasks","without ai","forget",...xu()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ed,keywords:["skin","theme","appearance","font","typeface","chat width","width","wide","full width","bubble","bubbles","tools","tool calls","threads","show threads","hide threads","sidebar","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top","send","enter","return","shift+enter","ctrl+enter","cmd+enter","⌘+enter","new line","keyboard","ime","japanese","message color","my messages","toolbar","tools layout","footer","routines","triggers","team map","color","colour","cloud color","server color","tint","sidebar color","sidebar picture","picture","image","banner","background","computers","your computers","rail","strip","frame","window frame","title bar"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Sc,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:Rd,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:_a,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","meta","muse","vps","router","openrouter","base url","openai","anthropic","groq","greenference","modelgo","opencode","deepseek","provider","ollama","lm studio","lmstudio","llm studio","llmstudio","bionic"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:Cc,keywords:["decision","extraction","jev","typesafe","cloudflare","workers ai","clef","clairic","email","routing","auto","rooms","who answers"]},{id:"imageGeneration",group:"ai",labelKey:"settings.section.imageGeneration",icon:Ec,keywords:["image","images","picture","generate","avatar","gpt image","grok imagine","gemini","nano banana","openrouter","flux","backup"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:Is,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:Ft,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:gi,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:Bt,keywords:["vault","logins","login","passwords","password","sign in","2fa","one-time code","totp","fill_login","1password","password manager","secrets","secret","token",".env","env"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:js,keywords:["cloud","my cloud","account","personal","sign in","pro","subscription","billing","sync","send","this computer","bots","logins","1password"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:Ft,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:Nd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:Qa,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:Ye,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:St,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:St,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:Id,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:Ft,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:Ac,keywords:["early","preview","learn","skill","authoring"]}],ph=[{id:"general",labelKey:"settings.section.general",icon:Ic,sections:["general","appearance","people","import","organization","activity"],keywords:["account","theme","looks","open at login","startup","analytics","advanced mode","more settings","limits","timeout"]},{id:"botAccess",labelKey:"settings.section.botAccess",icon:St,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:Pc,sections:["engines","connections"],keywords:["new bots","defaults","effort"]},{id:"skills",labelKey:"settings.section.skills",icon:Is,sections:["skills"],keywords:["skills","skill hub","library","kỹ năng","thư viện"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:gi,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:Rc,sections:["usage","cloudAccount"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"backups",labelKey:"settings.section.backups",icon:Qa,sections:["backups"],keywords:["chuyển máy offline","transfer","export","import","restore","sao lưu"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:Sd,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],ys=["experimental","workspaces","decisionModel","imageGeneration"],xh={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function hh(s,n){const a=ph.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=ys.includes(n)&&s.has(n)?Hs.find(r=>r.id===n):void 0;return i&&a.push({id:i.id,labelKey:i.labelKey,icon:i.icon,sections:[i.id]}),a}function gh(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Ls(s,i)}function fh(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=Hs.find(r=>r.id===a);return i?vs(i,n):!1})}function vs(s,n){return!n||s.id==="connections"&&rt.some(a=>Cs(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function bh(s){return s?rt.filter(n=>Cs(n,s)).slice(0,8):[]}const yh=s=>s.uses?rs(s.uses,s.id):rs(s.id);function Kh(){return e.jsx(ti,{modal:!0,children:e.jsx(vh,{})})}function vh(){const s=ed(),{state:n,dispatch:a}=V(),i=ol(),r=window.ogb?.remoteClient?.active===!0,c=n.appSettingsSection,o=i&&c==="remote"&&window.ogb?.environments?"desktopWorkspaces":r&&!["appearance","desktopWorkspaces"].includes(c)||c==="remote"?"companion":i&&c==="updates"?"general":c,d=l.useRef(null),m=l.useRef(null),u=l.useRef(i),[p,x]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>x("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>x("")),[]);const h=p.trim().toLowerCase(),g=It(),b=Ja(),y=Hs.map(L=>L.id==="companion"?{...L,labelKey:b?"settings.section.phoneDevices":"settings.section.thisServer"}:L),j=y.filter(L=>!r||L.id==="companion"||L.id==="appearance"||L.id==="desktopWorkspaces").filter(L=>L.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(L=>L.id!=="organization"||!!window.ogb?.organization).filter(L=>L.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(L=>L.id!=="workspaces"||nr(n.config)).filter(L=>L.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(L=>L.id!=="activity"||!window.ogb&&g===!0).filter(L=>L.id!=="botAccess"||!!n.config?.team&&g===!0).filter(L=>(L.id!=="skills"||yn(n.config))&&(L.id!=="cloudAccount"||cl)),C=j.filter(L=>vs(L,h)),w=new Set([...j.map(L=>L.id),...r?[]:["updates"]]),S=i?[]:hh(w,o),I=S.filter(L=>fh(L,h)),k=S.find(L=>L.sections.includes(o)),B=i?y.find(L=>L.id===o)?.labelKey:k?.labelKey,v=i?C.some(L=>L.id===o)?void 0:C[0]?.id:k&&I.includes(k)?void 0:I[0]&&(I[0].sections.find(L=>C.some(E=>E.id===L))??I[0].sections[0]);l.useEffect(()=>{v&&a({type:"toggleAppSettings",open:!0,section:v})},[a,v]);const[A,P]=l.useState({}),_=Ca();l.useEffect(()=>{_&&P(L=>L["ai-keys"]?L:{...L,"ai-keys":!0})},[_]);const U=L=>{const E=h!==""||(A[L]??xh[c]===L);return{id:L,open:E,onToggle:()=>P(W=>({...W,[L]:!E}))}},[X,H]=l.useState(null),N=X?.for===c?X.view:null,Z=(L,E=c)=>H(L&&{view:L,for:E});l.useEffect(()=>{H(L=>L?.for===c?L:null)},[c]);const[te,R]=l.useState(null),T=i||dl||!h?[]:sh.filter(L=>t(L).toLowerCase().includes(h)),Y=j.filter(L=>ys.includes(L.id)),re=r||!j.some(L=>L.id==="connections")?[]:bh(h),pe=L=>re.map(E=>e.jsx("button",{type:"button","data-settings-key-result":E.id,className:L,onClick:()=>{x(""),Z(null),a(yh(E))},children:e.jsxs("span",{children:[t(E.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(Tc(E).titleKey)]})]})},E.id)),xe=k?.sections.indexOf(o)??0,le=!i&&c==="remote"?"remote":o;l.useEffect(()=>{m.current&&gh(m.current,le,i?0:le===o?xe:1)},[i,le,o,xe]),l.useEffect(()=>{if(!te)return;const L=m.current?.querySelector(`[data-settings-block="${te}"]`);m.current&&L&&Ls(m.current,L),R(null)},[te]),l.useEffect(()=>{const L=document.activeElement instanceof HTMLElement?document.activeElement:null,E=d.current,W=E?.querySelector("[data-settings-search]");u.current&&W?.checkVisibility()?W.focus():E?.focus();const de=q=>{if(!s())return;if(!u.current&&E&&document.activeElement===E&&q.key.length===1&&!q.metaKey&&!q.ctrlKey&&!q.altKey&&W?.checkVisibility()){q.preventDefault(),W.focus(),x(Me=>Me+q.key);return}if(q.defaultPrevented||E&&[...E.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(Me=>Me.getClientRects().length))return;if(q.key==="Escape"){q.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(q.key!=="Tab"||!E)return;const je=Array.from(E.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(Me=>Me.checkVisibility());if(je.length===0){q.preventDefault(),E.focus();return}const Ie=je[0],Ze=je[je.length-1],et=document.activeElement;q.shiftKey&&(et===Ie||!E.contains(et))?(q.preventDefault(),Ze.focus()):!q.shiftKey&&et===Ze&&(q.preventDefault(),Ie.focus())};return window.addEventListener("keydown",de),()=>{window.removeEventListener("keydown",de),L?.focus()}},[a,s]);const $=L=>a({type:"toggleAppSettings",open:!0,section:L}),ne=n.appSettingsPhonePairing,fe=ld(n.config?.cloudHome===!0)==="computer",oe={client:e.jsx(rp,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||b?null:e.jsx(Qm,{}),pairing:b?null:e.jsx(Tm,{cloudHome:n.config?.cloudHome===!0,focusRequest:fe?0:ne,team:n.config?.team?.name,teamPhoneBlocked:n.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:n.config.managedPolicy.organizationName}):null,simple:!i}),companion:b?e.jsx(Lm,{profileEmail:n.config?.profile?.email,focusRequest:ne,simple:!i}):null},se=L=>{switch(L){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(Vn,{}),oe.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Vi,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(Gp,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>a(od()),onAddCloud:i?()=>a({type:"openCloudAdd",source:"app_settings"}):void 0,onSignIn:()=>a({type:"openCloudAdd",source:"app_settings",signIn:!0})}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx(os,{}),e.jsx(Xa,{}),e.jsx(ki,{}),e.jsx(jd,{}),e.jsx(Bc,{}),e.jsxs(Q,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(mr,{}),e.jsx(pr,{})]}),e.jsx(ls,{}),e.jsx(vi,{}),e.jsx(bd,{}),e.jsx(Nr,{}),e.jsx(yi,{}),e.jsx(qa,{}),e.jsx(di,{}),e.jsx(Q,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(rr,{})}),e.jsx(Q,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(cr,{})}),e.jsx(xr,{}),e.jsx(hr,{}),e.jsx(yr,{}),e.jsx(ji,{}),e.jsx(Wx,{}),!r&&e.jsx(ri,{}),e.jsx(ii,{}),e.jsx(Ni,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(ar,{}),e.jsx(Q,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(ir,{})}),e.jsx(vp,{}),r&&e.jsx(os,{}),r&&e.jsx(ls,{}),e.jsx(Ix,{}),e.jsx(Px,{}),e.jsx(mi,{}),e.jsx(pi,{}),e.jsx(xi,{}),e.jsx(Rx,{}),e.jsx(Ya,{}),e.jsx(Wi,{}),e.jsx(xd,{}),e.jsx(hd,{}),e.jsx(gd,{}),e.jsx(jr,{}),!r&&e.jsx(ui,{}),e.jsx(fd,{})]});case"experimental":return e.jsx(pd,{});case"connections":return e.jsx(ke,{children:e.jsx(pu,{})});case"decisionModel":return e.jsx(ke,{children:e.jsx(wu,{})});case"imageGeneration":return e.jsx(ke,{children:e.jsx(Lu,{})});case"engines":return e.jsx(ke,{children:e.jsx(Pi,{})});case"backups":return e.jsxs(ke,{children:[e.jsx(Lc,{}),e.jsx(Gx,{})]});case"import":return e.jsx(ke,{children:e.jsx(kr,{})});case"companion":return e.jsxs(e.Fragment,{children:[oe.companion,oe.pairing,oe.domain,window.ogb?.environments?null:oe.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(li,{}),e.jsx(oi,{}),e.jsx(ci,{}),e.jsx(ke,{children:e.jsx(Bi,{})})]});case"logins":return e.jsx(Ki,{});case"usage":return e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(tr,{})});case"skills":return yn(n.config)?e.jsx(bx,{}):null;case"people":return e.jsx(Ui,{});case"activity":return e.jsx(Di,{});case"botAccess":return e.jsx($m,{});case"workspaces":return e.jsx(Sx,{});default:return null}},ie=()=>{$("general"),Z("more","general")},be=L=>{const E=W=>L.sections.includes(W);switch(L.id){case"general":return N==="looks"?e.jsx(rh,{toolCalls:!r,onBack:()=>{Z(null),R("appearance")}}):N==="more"?e.jsx(lh,{sections:Y,onOpen:W=>{Z(null),$(W)},onBack:()=>{Z(null),R("more")}}):e.jsx(ah,{has:E,peopleOpen:o==="people",onLooks:()=>Z("looks"),onMore:E("general")?()=>Z("more"):void 0});case"ai":return e.jsx(oh,{has:E,disclose:U,connections:se("connections")});case"computer":return e.jsx(ch,{has:E,remoteAccess:oe,servers:e.jsx(Vn,{}),disclose:U});case"billing":return e.jsx(dh,{has:E,disclose:U,cloudAccount:se("cloudAccount")});case"updates":return e.jsx(mh,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[ys.includes(L.sections[0])&&w.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:ie,children:t("settings.simple.looks.back")})}),L.sections.map(W=>e.jsx("section",{"data-settings-block":W,className:"flex scroll-mt-4 flex-col gap-4",children:se(W)},W))]})}},K=()=>a({type:"toggleAppSettings",open:!1}),ae=(L,E)=>e.jsxs("div",{className:L,children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:p,onChange:W=>x(W.target.value),onKeyDown:W=>{W.key==="Escape"&&(W.stopPropagation(),p?x(""):K())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:E})]});if(!i){const L=k?.id==="general"?N:null,E="flex min-h-8 shrink-0 cursor-pointer items-center rounded-lg px-[9px] py-1.5 text-left text-[13px] leading-[18px] text-ink transition-colors hover:bg-ink/[0.06] motion-reduce:transition-none",W=q=>{Z(null),$(q)},de=h?[...Y.filter(q=>vs(q,h)).map(q=>({key:q.id,labelKey:q.labelKey,open:()=>W(q.id)})),...(w.has("general")?nh:[]).filter(q=>t(q).toLowerCase().includes(h)).map(q=>({key:q,labelKey:q,open:()=>{ie(),R("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:kn(),onMouseDown:q=>q.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsx(Ud,{}),e.jsxs("nav",{"aria-label":t("settings.title"),className:"glass-rail hidden min-h-0 w-[198px] shrink-0 flex-col gap-0.5 overflow-y-auto px-3 py-4 sm:flex",children:[ae("mb-2 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"),I.length===0&&T.length===0&&de.length===0&&re.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:p.trim()})}),I.map(q=>{const je=q.icon,Ie=q===k;return e.jsxs("button",{type:"button","data-settings-page":q.id,onClick:()=>W(q.sections[0]),"aria-current":Ie?"page":void 0,className:M("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",Ie?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(je,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:t(q.labelKey)})]},q.id)}),T.map(q=>e.jsx("button",{type:"button","data-settings-advanced-only":q,onClick:()=>{x(""),W("general"),R("advanced-mode")},className:E,children:e.jsxs("span",{children:[t(q)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},q)),de.map(q=>e.jsx("button",{type:"button","data-settings-more-result":q.key,onClick:()=>{x(""),q.open()},className:E,children:e.jsxs("span",{children:[t(q.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},q.key)),pe(E)]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center gap-3 py-3 pl-4 pr-14 sm:pb-1.5 sm:pl-12 sm:pt-8",children:[e.jsx(me,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:k?.id??"",onChange:q=>{x("");const je=S.find(Ie=>Ie.id===q.target.value);je&&W(je.sections[0])},children:S.map(q=>e.jsx("option",{value:q.id,children:t(q.labelKey)},q.id))}),e.jsx("h2",{className:"hidden truncate text-[17px] font-medium leading-6 tracking-[-0.008em] text-ink sm:block",children:L==="looks"?t("settings.simple.page.looks"):L==="more"?t("settings.simple.more.title"):k?t(k.labelKey):null})]}),e.jsx("button",{type:"button",onClick:K,"aria-label":t("settings.close"),title:`${t("settings.close")} (${vn("close-panel")})`,className:"absolute right-5 top-[18px] flex size-8 cursor-pointer items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink motion-reduce:transition-none",children:e.jsx(_e,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{ref:m,"data-settings-scroll":!0,className:M("settings-scroll flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-4 pb-10 pt-4 sm:px-8 sm:pb-12 sm:pt-[22px]",Ka,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(la,{config:n.config}),k?be(k):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:kn(),onMouseDown:L=>L.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),ae("mb-2 mt-1 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-tertiary focus:outline-none"),C.length===0&&e.jsx("div",{className:"px-2.5 py-4 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:p.trim()})}),ja.map(L=>{const E=C.filter(W=>W.group===L.id);return E.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${L.id}`,"data-settings-group":L.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${L.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(L.labelKey)}),E.map(({id:W,labelKey:de,icon:q})=>e.jsxs("button",{"data-settings-section":W,onClick:()=>$(W),"aria-current":o===W?"page":void 0,className:M("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",o===W?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(q,{size:15,className:"shrink-0"}),t(de)]},W))]},L.id)}),pe("cursor-pointer flex min-h-9 items-center rounded-lg px-2.5 py-2 text-left text-[13px] text-ink transition-colors hover:bg-control/50 motion-reduce:transition-none")]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:pl-9",children:[e.jsx(me,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:L=>{x(""),$(L.target.value)},children:ja.map(L=>{const E=j.filter(W=>W.group===L.id);return E.length===0?null:e.jsx("optgroup",{label:t(L.labelKey),children:E.map(({id:W,labelKey:de})=>e.jsx("option",{value:W,children:t(de)},W))},L.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:B?t(B):null}),e.jsx("button",{onClick:K,"aria-label":t("settings.close"),title:`${t("settings.close")} (${vn("close-panel")})`,className:"ui-icon-button cursor-pointer shrink-0 max-md:size-9 max-md:rounded-full max-md:border max-md:border-hairline max-md:bg-card",children:e.jsx(_e,{size:18})})]}),e.jsxs("div",{ref:m,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(la,{config:n.config}),se(o)]})]})]})]})}export{Hs as SECTIONS,ja as SETTINGS_GROUPS,xh as SIMPLE_FOLDED,ys as SIMPLE_HIDDEN_SECTIONS,ph as SIMPLE_PAGES,Kh as SettingsModal,bh as keySearchResults,yh as openKeyResult,gh as revealSettingsBlock,vs as sectionMatches,hh as simpleSettingsPages};
18
+ Install anyway (the skill will stay switched off)?`))&&P(N.id,()=>Ae("/api/limix/hub/install",{id:N.id,allowRisky:!0}))},Q=N=>{!N.enabled&&N.risky&&!window.confirm(z(`"${N.name}" bị cách ly (${N.risky}). Vẫn bật cho bot dùng?`,`"${N.name}" is quarantined (${N.risky}). Switch it on for bots anyway?`))||P(N.id,()=>Ae("/api/limix/hub/enable",{id:N.id,enabled:!N.enabled}))},H=N=>{const Z=N.description_vi||N.description,te=f===N.id,T=(N.permissions.runs_code||N.permissions.mcp)&&!N.blocked;return e.jsx("li",{className:"px-4 py-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[14px] font-semibold text-ink",children:N.name}),e.jsxs("span",{className:`rounded-md px-1.5 py-0.5 text-[11px] font-medium ${I[N.grade]??"bg-ink/10 text-ink-secondary"}`,children:[N.quality_score,"/100 · ",hx(N.grade)??N.grade]}),typeof N.stars=="number"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[12px] text-ink-secondary",children:[e.jsx(Uo,{size:12}),N.stars.toLocaleString(z("vi-VN","en-US"))]})]}),e.jsx("p",{className:`mt-1 text-[12.5px] leading-relaxed text-ink-secondary ${te?"":"line-clamp-3"}`,children:Z}),Z.length>220&&e.jsx("button",{type:"button",className:"mt-0.5 text-[12px] text-ink underline-offset-2 hover:underline",onClick:()=>j(te?null:N.id),children:te?z("Thu gọn","Show less"):z("Xem thêm","Show more")}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:_,children:gx(N.kind)??N.kind}),e.jsxs("span",{className:`${_} ${N.security_status==="clean"?"":N.security_status==="quarantined"?"!bg-danger/15 !text-danger":"!bg-amber-500/15 !text-amber-500"}`,children:[z("Bảo mật","Security"),": ",as(N.security_status)??N.security_status]}),e.jsx("span",{className:_,children:N.license??z("Chưa có giấy phép","No license")}),N.dependencies.length>0&&e.jsxs("span",{className:_,children:[z("Cần","Needs"),": ",N.dependencies.join(", ")]})]}),e.jsxs("p",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-tertiary",children:[N.source.repository??z("Không rõ nguồn","Unknown source"),N.created_at&&z(` · Tạo ${qe(N.created_at)}`,` · Created ${qe(N.created_at)}`),N.pushed_at&&z(` · Cập nhật ${qe(N.pushed_at)}`,` · Updated ${qe(N.pushed_at)}`),N.stats_checked&&z(` · số sao đo ngày ${qe(N.stats_checked)}`,` · stars measured ${qe(N.stats_checked)}`)]}),N.risky&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 rounded-lg bg-danger/10 p-2 text-[12px] leading-relaxed text-danger",children:[e.jsx(hn,{size:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[N.risky," ",z("Không khuyến khích cài.","Installing is not recommended.")]})]}),N.blocked&&e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-danger",children:[e.jsx(hn,{size:13}),N.blocked]}),T&&e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 bg-raised/50 p-2.5 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("button",{type:"button",className:"text-ink underline-offset-2 hover:underline",onClick:()=>y(b===N.id?null:N.id),children:b===N.id?z("Ẩn hướng dẫn cài đặt","Hide install guide"):z("Kỹ năng này có tool: xem hướng dẫn cài đặt","This skill has tools: see the install guide")}),b===N.id&&e.jsxs("ol",{className:"mt-2 list-decimal space-y-1.5 pl-4",children:[e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài kỹ năng:"}),' bấm "Cài đặt". Mặc định chỉ lấy phần hướng dẫn (SKILL.md). Kỹ năng được tải từ GitHub và kiểm tra SHA-256 từng file.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the skill:"}),' press "Install". By default only the instructions (SKILL.md) are taken. The skill is downloaded from GitHub and every file is checked with SHA-256.']}))}),N.compatibility.runtimes.length>0&&e.jsxs("li",{children:[e.jsxs("b",{className:"text-ink",children:[z("Chuẩn bị máy","Prepare this computer"),":"]})," ",z("kỹ năng cần","the skill needs")," ",N.compatibility.runtimes.map(R=>R.name).join(", "),".",N.compatibility.runtimes.filter(R=>R.installerId).length>0&&e.jsxs(e.Fragment,{children:[" ",z("Limix Bot cài được","Limix Bot can install"),": ",N.compatibility.runtimes.filter(R=>R.installerId).map(R=>R.name).join(", "),". "]}),N.compatibility.runtimes.some(R=>!R.installerId)&&e.jsxs(e.Fragment,{children:[" ",z("Phải cài tay","Install by hand"),": ",N.compatibility.runtimes.filter(R=>!R.installerId).map(R=>R.name).join(", ")," (",z('Python: tải từ python.org, tick "Add python.exe to PATH"','Python: download from python.org, tick "Add python.exe to PATH"'),"). "]}),Wa()&&e.jsx("button",{type:"button",className:"ml-1 text-ink underline",onClick:()=>g(!0),children:z('Mở "Công cụ cho kỹ năng"','Open "Tools for skills"')})]}),N.permissions.runs_code&&e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài phần script:"}),' bấm "Cài đặt kèm tool". Các file script nằm trong thư mục kỹ năng và bot có thể chạy chúng. Chỉ làm khi bạn tin nguồn ',N.source.repository??"này"," (đã quét: ",as(N.security_status)??N.security_status,")."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the scripts:"}),' press "Install with tools". The script files go in the skill folder and the bot can run them. Only do this if you trust ',N.source.repository??"the source"," (scanned: ",as(N.security_status)??N.security_status,")."]}))}),N.permissions.mcp&&e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," file cấu hình MCP chỉ được chép vào thư mục kỹ năng, không tự bật. Muốn dùng, thêm máy chủ MCP ở Cài đặt rồi bật."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," the MCP config file is only copied into the skill folder and is not switched on. To use it, add the MCP server in Settings and turn it on."]}))}),e.jsx("li",{children:z(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Bật:"}),' sau khi cài, gạt công tắc "Đang tắt" sang bật, rồi mở cài đặt của bot → Kĩ Năng (Skills) để thêm.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Switch on:"}),' after installing, flip the "Off" switch to on, then add it in the bot’s Settings → Skills.']}))})]})]}),a==="security"&&N.security_findings?.slice(0,5).map((R,Y)=>e.jsxs("p",{className:"text-[11px] text-ink-tertiary",children:[R.severity," · ",R.rule," · ",R.file,R.line?`:${R.line}`:""]},Y)),N.notes.map(R=>e.jsx("p",{className:"mt-0.5 text-[11px] text-ink-tertiary",children:R},R))]}),e.jsx("div",{className:"flex shrink-0 flex-row flex-wrap items-center gap-2 sm:w-[168px] sm:flex-col sm:items-stretch",children:r===N.id?e.jsx(J,{size:15,className:"animate-spin text-ink-secondary sm:self-end"}):N.installed?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[N.enabled?z("Đang bật","On"):z("Đang tắt","Off"),e.jsx(me,{checked:N.enabled,disabled:r!==null,onClick:()=>Q(N)})]}),N.updateAvailable&&e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{P(N.id,()=>Ae("/api/limix/hub/update",{id:N.id,allowRisky:!!N.risky}))},children:[e.jsx(we,{size:14}),z("Cập nhật","Update")]}),e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{P(N.id,()=>Ae("/api/limix/hub/remove",{id:N.id}))},children:[e.jsx(Se,{size:14}),z("Gỡ","Remove")]})]}):e.jsxs(e.Fragment,{children:[N.risky?e.jsxs("button",{type:"button",className:`${Ue} justify-center !border-danger/40 !text-danger`,disabled:!!N.blocked||r!==null,onClick:()=>D(N),children:[e.jsx(Ye,{size:14}),z("Cài đặt (không khuyến khích)","Install (not recommended)")]}):e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:!!N.blocked||r!==null,onClick:()=>{P(N.id,()=>Ae("/api/limix/hub/install",{id:N.id}))},children:[e.jsx(Ye,{size:14}),z("Cài đặt","Install")]}),N.permissions.runs_code&&!N.blocked&&!N.risky&&e.jsxs("button",{type:"button",className:`${Ue} justify-center`,disabled:r!==null,onClick:()=>{window.confirm(z(`Cài cả script của "${N.name}"? Bot có thể chạy các script này. Chỉ làm khi bạn tin nguồn.`,`Install the scripts of "${N.name}" too? Bots can run these scripts. Only do this if you trust the source.`))&&P(N.id,()=>Ae("/api/limix/hub/install",{id:N.id,allowTools:!0}))},children:[e.jsx(Ye,{size:14}),z("Cài đặt kèm tool","Install with tools")]})]})})]})},N.id)};return e.jsxs(X,{title:z("Kho kỹ năng Limix","Limix Skill Catalog"),subtitle:z("Kĩ năng đã quét bảo mật và chấm điểm. Cài xong, kĩ năng nằm sẵn trong kho nhưng chưa bot nào dùng: mở bot → Kĩ Năng (Skills) → Kho Kĩ Năng (Skills) để thêm cho từng bot.","Skills that are security-scanned and scored. Once installed, a skill waits in the store and no bot uses it yet: open a bot → Skills → Skills Store to add it to one bot."),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:xx.map(([N,Z])=>{const te=N==="installed"?k.filter(T=>T.installed).length:N==="updates"?k.filter(T=>T.updateAvailable).length:N==="discover"?k.length:null;return e.jsxs("button",{type:"button",onClick:()=>i(N),className:`rounded-lg px-2.5 py-1 text-[13px] ${a===N?"bg-raised text-ink":"text-ink-secondary hover:bg-raised-hover"}`,children:[Z(),te?e.jsx("span",{className:"ml-1 text-[11px] text-ink-tertiary",children:te}):null]},N)})}),o&&e.jsx("p",{className:"text-[12px] text-danger",children:o}),s?a==="settings"?e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] text-ink",children:[e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[z("Tự đồng bộ danh mục","Sync the catalog automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:z("Chỉ cập nhật danh sách, không cài gì.","Only refreshes the list, installs nothing.")})]}),e.jsx(me,{checked:s.settings.autoSync,onClick:()=>{P("settings",()=>Ae("/api/limix/hub/settings",{autoSync:!s.settings.autoSync}))}})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[z("Tự cài kỹ năng mới","Install new skills automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:z("Mặc định tắt. Nếu bật: chỉ cài loại chỉ có hướng dẫn, đã duyệt, điểm từ 80; vẫn ở trạng thái tắt.","Off by default. When on: only instruction-only skills that are approved and score 80 or more are installed, and they stay switched off.")})]}),e.jsx(me,{checked:s.settings.autoInstall,onClick:()=>{P("settings",()=>Ae("/api/limix/hub/settings",{autoInstall:!s.settings.autoInstall}))}})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{value:m,onChange:N=>u(N.target.value),placeholder:z("Tìm kỹ năng…","Search skills…"),className:"min-w-[160px] flex-1 rounded-lg border border-hairline/60 bg-card px-3 py-1.5 text-[13px] text-ink"}),e.jsxs("select",{value:x,onChange:N=>p(N.target.value),className:"rounded-lg border border-hairline/60 bg-card px-2 py-1.5 text-[13px] text-ink",children:[e.jsx("option",{value:"",children:z("Mọi nhóm","All categories")}),B.map(N=>e.jsx("option",{value:N,children:N},N))]}),a==="discover"&&e.jsxs("button",{type:"button",className:`${Ue} shrink-0`,disabled:r!==null,onClick:()=>{A()},children:[r==="sync"?e.jsx(J,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),z("Đồng bộ ngay","Sync now")]})]}),a==="discover"&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",role:"status",children:[z("Đồng bộ gần nhất","Last sync"),": ",s.settings.lastSync?new Date(s.settings.lastSync).toLocaleString(z("vi-VN","en-US")):z("chưa lần nào","never")]}),s.settings.lastError&&e.jsxs("p",{className:"text-[12px] text-danger",children:[z("Lỗi đồng bộ gần nhất","Last sync error"),": ",s.settings.lastError]})]}),v.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:k.length===0?z("Chưa có danh mục. Mở Khám phá và bấm Đồng bộ ngay.","No catalog yet. Open Discover and press Sync now."):z("Không có kỹ năng nào ở mục này.","No skills in this tab.")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",children:[v.length," ",z("kỹ năng","skills")]}),e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40 bg-card",children:v.slice(0,C).map(H)}),v.length>C&&e.jsx("button",{type:"button",className:`${Ue} w-fit self-center`,onClick:()=>w(N=>N+at),children:z(`Xem thêm ${Math.min(at,v.length-C)} kỹ năng`,`Show ${Math.min(at,v.length-C)} more`)})]}),a==="installed"&&v.length>0&&e.jsxs("p",{className:"flex items-center gap-1 text-[12px] text-ink-tertiary",children:[e.jsx(ge,{size:13}),z("Kỹ năng đã bật nằm trong thư viện bên dưới. Mở cài đặt của từng bot → Kĩ Năng (Skills) để thêm.","Enabled skills are in the library below. Add them from each bot’s Settings → Skills.")]})]}):e.jsx(J,{size:15,className:"animate-spin text-ink-secondary"})]}),h&&e.jsx(Ga,{onClose:()=>g(!1)})]})}function bx(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 sr({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(ws())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function yx(){const[s,n]=l.useState([]),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(""),[m,u]=l.useState(null),[x,p]=l.useState(null),[h,g]=l.useState(""),[b,y]=l.useState(""),[f,j]=l.useState(!1),[C,w]=l.useState(""),S=l.useRef(!1),P=l.useMemo(()=>[...new Set(s.flatMap(D=>D.tags))].sort((D,Q)=>D.localeCompare(Q)),[s]),k=bx(s,o,m),B=async D=>{try{const Q=await fetch("/api/skills-library"),H=await Q.json();if(!Q.ok)throw new Error(H.error??t("skills.library.loadError"));if(D?.())return;n(H.skills??[]),c("")}catch(Q){D?.()||c(Q instanceof Error?Q.message:t("skills.library.loadError"))}finally{D?.()||i(!1)}};l.useEffect(()=>{let D=!1;return i(!0),B(()=>D),()=>{D=!0}},[]);const v=async(D,Q=!1)=>{if(!S.current){if(!D.enabled&&!Q)return A(D,!0);S.current=!0,g(D.name),c("");try{const H=await fetch(`/api/skills-library/${encodeURIComponent(D.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!D.enabled})}),N=await H.json();if(!H.ok)throw new Error(N.error??t("skills.error.update"));Q&&p(null),await B()}catch(H){c(H instanceof Error?H.message:t("skills.error.update"))}finally{S.current=!1,g("")}}},A=async(D,Q=!1)=>{c("");try{const H=await fetch(`/api/skills-library/${encodeURIComponent(D.name)}`),N=await H.json();if(!H.ok)throw new Error(N.error??t("skills.error.load"));if(!N.text)throw new Error(t("skills.error.contentsImport"));p({skill:D,text:N.text,review:Q})}catch(H){c(H instanceof Error?H.message:t("skills.error.load"))}},I=async()=>{const D=b.trim();if(D){j(!0),c(""),w("");try{const Q=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:D})}),H=await Q.json();if(!Q.ok)throw new Error(H.error??t("skills.error.import"));w(t("skills.library.imported",{name:H.skill?.name??""})),y(""),await B()}catch(Q){c(Q instanceof Error?Q.message:t("skills.error.import"))}finally{j(!1)}}},_="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(px,{}),e.jsx(mx,{}),e.jsx(fx,{}),e.jsx(X,{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(mt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:_,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:o,onChange:D=>d(D.target.value)})]}),P.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u(null),className:m===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")}),P.map(D=>e.jsx("button",{type:"button",onClick:()=>u(m===D?null:D),className:m===D?"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:D},D))]}),a?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):k.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:s.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:k.map(D=>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:()=>{A(D)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:D.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:D.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:D.description})]}),e.jsx(me,{checked:D.enabled,"aria-label":D.enabled?t("skills.library.disable",{skill:D.name}):t("skills.library.enable",{skill:D.name}),disabled:!!(h||f),onClick:()=>{v(D)}})]}),e.jsx(sr,{skill:D}),D.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:D.warnings.join(" · ")})]},D.name))}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}),e.jsx(X,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:D=>{D.preventDefault(),I()},children:[e.jsx("textarea",{className:`${_} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:b,onChange:D=>y(D.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:C}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:f||!!h||!b.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:f?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),x&&e.jsx(ti,{modal:!0,children:e.jsx(vx,{viewing:x,error:r,working:!!h,onClose:()=>{h||p(null)},onEnable:()=>{v(x.skill,!0)}})})]})}function vx({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=l.useRef(null);return Gc(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(sr,{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 kx(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 la({config:s}){const n=kx(s);return n?e.jsxs("div",{role:"status",className:M("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(Be,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function nr(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const jx=()=>U("/api/fleet");function Nx({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,o=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:M("text-right",r||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:o}),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:[ot(i.usage.costUsd)?ct(i.usage.costUsd):"—",ot(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ct(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 wx({domain:s,onCreated:n,disabled:a}){const[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState(""),[p,h]=l.useState(""),[g,b]=l.useState(!1),[y,f]=l.useState(null),j=async()=>{if(!g){b(!0),f(null);try{const w={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(P=>P.trim()).filter(Boolean),...u.trim()?{cap:Number(u)}:{},...p.trim()?{anthropicKey:p.trim()}:{}},S=await U("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});r(""),o(""),m(""),x(""),h(""),n(S.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){f(w instanceof Error?w.message:String(w))}finally{b(!1)}}},C="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(),j()},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||g,"aria-label":t("workspaces.name"),className:C}),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=>o(w.target.value),type:"email",required:!0,disabled:a||g,"aria-label":t("workspaces.adminEmail"),className:C})]}),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=>m(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||g,"aria-label":t("workspaces.members"),className:C})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:u,onChange:w=>x(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||g,"aria-label":t("workspaces.cap"),className:C})]}),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:p,onChange:w=>h(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||g,"aria-label":t("workspaces.anthropicKey"),className:C})]})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),y&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:y}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||g,className:"ui-button ui-button-primary",children:[g?e.jsx(J,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),g?t("workspaces.creating"):t("workspaces.create")]})})]})}function Sx({slug:s,onDone:n}){const[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),x=async p=>{if(!o){d(p),u(null);try{const h=await U(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:p,email:a.trim(),chatOnly:r})});i(""),n(h.log??[])}catch(h){u(h instanceof Error?h.message:String(h))}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:p=>i(p.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:o!==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:p=>c(p.target.checked),disabled:o!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:o!==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:o==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{x("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:o==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Cx({load:s=jx}){const{state:n}=G(),[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState([]),[h,g]=l.useState(null),[b,y]=l.useState(null),[f,j]=l.useState(!1),[C,w]=l.useState(null),S=l.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(v){c(v instanceof Error?v.message:String(v))}finally{d(!1)}},[s]);l.useEffect(()=>{S()},[S]);const P=async(v,A)=>{if(A==="users"){g(I=>I===v?null:v);return}if(A==="delete"){y({slug:v,keepData:!1});return}u(v),c(null);try{const I=await U(`/api/fleet/workspaces/${encodeURIComponent(v)}/${A}`,{method:"POST"});p(I.log??[]),await S()}catch(I){c(I instanceof Error?I.message:String(I))}finally{u(null)}},k=async()=>{if(!b)return;const{slug:v,keepData:A}=b;y(null),u(v),c(null);try{const I=await U(`/api/fleet/workspaces/${encodeURIComponent(v)}`,{method:"DELETE",body:JSON.stringify({keepData:A})});p(I.log??[]),await S()}catch(I){c(I instanceof Error?I.message:String(I))}finally{u(null)}},B=async()=>{u("*"),c(null);try{const v=await U("/api/fleet/upgrade",{method:"POST"});p(v.log??[t("workspaces.upgraded")]),await S()}catch(v){c(v instanceof Error?v.message:String(v))}finally{u(null)}};return nr(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(X,{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:()=>{S()},disabled:o||m!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(we,{size:12,className:M(o&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>j(v=>!v),disabled:m!==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(Ce,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{B()},disabled:m!==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:m==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),f&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(wx,{domain:a.domain,disabled:m!==null,onCreated:(v,A)=>{j(!1),p(v),w(`https://${A.slug}.${a.domain}/pair?email=${encodeURIComponent(A.admin)}`),S()}})}),C&&e.jsx("div",{className:"mb-4",children:e.jsx(zi,{link:C})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(Nx,{fleet:a,onAct:(v,A)=>{P(v,A)},busy:m}):o?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("common.checking")]}):null,h&&e.jsx(Sx,{slug:h,onDone:v=>{p(v),S()}}),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(`
19
+ `)})]}),e.jsx(Qe,{open:b!==null,title:t("workspaces.deleteTitle",{slug:b?.slug??""}),body:t(b?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>y(null),onConfirm:()=>{k()}}),b&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:b.keepData,onChange:v=>y({...b,keepData:v.target.checked})}),t("workspaces.keepData")]})]}):null}const oa=[{choice:"system",label:"settings.theme.system"},{choice:tn.light,label:"settings.theme.light"},{choice:tn.dark,label:"settings.theme.dark"}];function Hs(){return l.useSyncExternalStore(Xr,sn,sn)}function ar({simple:s=!1}){const n=Hs(),a=oa.some(i=>i.choice===n)?void 0:Cs.find(i=>i.id===n)?.name;return e.jsx(ce,{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:oa.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Yr(i.choice),className:s?M("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"):M("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 Ex({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)"}})})]})]})]})}const Ax={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function Ix({festival:s}){const n=qc(),a=t("settings.skin.dressUp.title");return e.jsxs("div",{"data-dress-up":!0,className:"mt-4 flex items-center gap-4 rounded-xl border border-accent-border/40 bg-accent/[0.06] p-3",children:[e.jsx("div",{className:"flex shrink-0 -space-x-1.5","aria-hidden":"true",children:Ax[s].map(i=>e.jsx(Jc,{color:i,bodyId:Yc[s].costumes[i],size:30,animated:!1,trackPointer:!1},i))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:a}),e.jsx("div",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.skin.dressUp.subtitle")})]}),e.jsx(me,{checked:n,"aria-label":a,onClick:()=>Xc(!n)})]})}function ir(){const s=wa(Hs());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:Cs.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Zr(n.id)},"aria-pressed":a,className:M("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",a?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Ex,{skin:n.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:n.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:Qr(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(ge,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),Vc(s)&&e.jsx(Ix,{festival:s})]})}function Px(){const[s,n]=l.useState(el);return e.jsx(ce,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;sl(i),n(i)},children:tl.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Tx(){const[s,n]=l.useState(nl);return e.jsx(ce,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=nn.find(r=>r===a.target.value);i&&(al(i),n(i))},children:nn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Rx(){const s=Do();return e.jsx(ce,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>_o($o(n.target.value)),children:Fo.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function rr(){const{state:s,dispatch:n}=G(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const g=Wo(i);if(!g.ok){m(t("settings.roomTurns.range"));return}p.current=!0,x(!0);try{const b=await U("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:g.minutes}})});n({type:"configStatus",config:b}),r(String(b.rooms.turnTimeoutMinutes)),o(!1),m("")}catch(b){m(b instanceof Error?b.message:t("settings.roomTurns.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:Ho,max:Ko,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:g=>{r(g.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),d?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}const Lx=10,lr=1,or=60,ca="Enter a whole number from 1 to 60.";function Bx(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:ca};const a=Number(n);return a<lr||a>or?{ok:!1,error:ca}:{ok:!0,minutes:a}}function da(s){return s?.mcp?.callTimeoutMinutes??Lx}function cr(){const{state:s,dispatch:n}=G(),a=da(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const g=Bx(i);if(!g.ok){m(t("settings.mcpCalls.range"));return}p.current=!0,x(!0);try{const b=await U("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:g.minutes}})});n({type:"configStatus",config:b}),r(String(da(b))),o(!1),m("")}catch(b){m(b instanceof Error?b.message:t("settings.mcpCalls.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:lr,max:or,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:g=>{r(g.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),d?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}function dr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(u,x)=>{a={value:u,status:x};for(const p of o)p()},m=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const u=a.value;await n(u),i=a.value!==u}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(u){return o.add(u),()=>{o.delete(u)}},confirm(u){!i&&!r&&u!==a.value&&d(u,"idle")},edit(u){i=!0,d(u,"idle"),clearTimeout(c),c=setTimeout(()=>{m()},600)},flush:m}}const ua=new WeakMap;function Ox(){const{state:s,dispatch:n}=G(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=ua.get(n);if(!r){const u={current:i};r={team:u,controller:dr(a,async x=>{const p=u.current?await Is({aboutMe:x}):(await U("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:x}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:p?.aboutMe??x}})})},ua.set(n,r)}r.team.current=i;const c=r.controller,{value:o,status:d}=l.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:m}=c;return l.useEffect(()=>{c.confirm(a)},[c,a]),l.useEffect(()=>()=>{m()},[m]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(Go,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:i?4e3:24e3,onChange:u=>c.edit(u.target.value),onBlur:()=>{m()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Mx,{onChanged:u=>{c.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",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:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Mx({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let m=!1;return U("/api/profile/learned").then(u=>{m||a(u.learned)}).catch(()=>{}),()=>{m=!0}},[]);const d=async m=>{r(m),o(!1);try{const u=await U(`/api/profile/learned/${encodeURIComponent(m)}/remove`,{method:"POST"});a(u.learned),s(u.aboutMe)}catch{o(!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(m=>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:[m.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:m.botName})})]}),e.jsx("button",{type:"button",disabled:i===m.id,onClick:()=>{d(m.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")})]},m.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const ma=new WeakMap;function zx(){const{state:s,dispatch:n}=G(),a=s.config?.everyBotRules;let i=ma.get(n);i||(i=dr(a??"",async u=>{const x=await U("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:u}),timeoutMs:1e4});n({type:"configStatus",config:x})}),ma.set(n,i));const{value:r,status:c}=l.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:o,edit:d,flush:m}=i;return l.useEffect(()=>{o(a??"")},[o,a]),l.useEffect(()=>()=>{m()},[m]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[14px] 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:u=>d(u.target.value),onBlur:()=>{m()},className:"min-h-[96px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsxs("div",{className:"min-h-4 text-[12px]",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:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const pa=64,xa=8192,jt=512;function Ux(s){return Jo(s)?s.size>Yo?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function Dx(s,n){return s<pa||n<pa?"settings.profile.avatar.tooSmall":s>xa||n>xa?"settings.profile.avatar.tooLargeDimensions":null}async function ur(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const o=new Image;o.onload=()=>r(o),o.onerror=()=>c(new Error("invalid-image")),o.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function Fx(s,n){return ur(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=jt,r.height=jt;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,jt,jt);const o=await new Promise((d,m)=>r.toBlob(u=>u?d(u):m(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function _x(){const{state:s,dispatch:n}=G(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,m]=l.useState(null),u=l.useRef(null),x=f=>{const j=u.current;j&&j.previewUrl!==f?.previewUrl&&URL.revokeObjectURL(j.previewUrl),u.current=f,m(f)};l.useEffect(()=>()=>{u.current&&URL.revokeObjectURL(u.current.previewUrl)},[]);const p=!!s.config?.team,h=async f=>{const j=p?await Is({avatarUrl:f}):(await U("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:f}})})).profile;n({type:"profileSaved",profile:{avatarUrl:j?.avatarUrl}})},g=f=>{if(!f)return;o(null);const j=Ux(f);if(j)return o(t(j));ur(f,C=>({width:C.naturalWidth,height:C.naturalHeight})).then(({width:C,height:w})=>{const S=Dx(C,w);if(S)return o(t(S));x({file:f,previewUrl:URL.createObjectURL(f),width:C,height:w,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},b=f=>{r(!0),o(null),Fx(f.file,f.zoom).then(j=>qo(j)).then(j=>{const C=j?Qc(j.path):null;if(!C)throw new Error("avatar");return h(C)}).then(()=>x(null),()=>o(t("settings.profile.avatar.saveError"))).finally(()=>r(!1))},y=()=>{o(null),h("").catch(()=>o(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[d?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:d.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${d.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:[d.width," × ",d.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:d.zoom,onChange:f=>x({...d,zoom:Number(f.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:()=>x(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:i,onClick:()=>b(d),children:t("settings.profile.avatar.save")})]})}):a?e.jsx("img",{src:a,alt:"",className:"size-12 rounded-full object-cover"}):e.jsx("div",{className:"size-12 rounded-full bg-raised"}),e.jsxs("label",{className:"cursor-pointer rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[i?t("settings.profile.avatar.uploading"):t("settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:i,onChange:f=>{const j=f.target.files?.[0];f.currentTarget.value="",g(j)}})]}),a&&!d&&e.jsx("button",{type:"button",className:"text-[12px] text-ink-secondary underline",onClick:y,children:t("settings.profile.avatar.remove")})]}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:c})]})}function mr(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(s.config?.profile?.name??""),[r,c]=l.useState(s.config?.profile?.email??"");l.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const o=!!s.config?.team,d=()=>{if(o){Is({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(()=>{})},m="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-3",children:[e.jsx(_x,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:m}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:m}),e.jsx(Ox,{}),e.jsx(zx,{})]})}function $x({profile:s}){const[n,a]=l.useState(null),i=Vo(s),r=s?.avatarUrl&&n!==s.avatarUrl?s.avatarUrl:null;return e.jsx("span",{className:"flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-full bg-ink/[0.06] text-[15px] font-medium text-ink-secondary",children:r?e.jsx("img",{src:r,alt:"",onError:()=>a(r),className:"size-full object-cover"}):i!=="?"?i:e.jsx(Va,{size:20,"aria-hidden":"true"})})}function Kx(){const{state:s}=G(),[n,a]=l.useState(!1),i=s.config?.profile,r=i?.name?.trim()??"",c=i?.email?.trim()??"",o=l.useId(),d=l.useRef(null);return l.useEffect(()=>{n&&d.current?.querySelector("input:not([type=file])")?.focus()},[n]),e.jsxs("div",{"data-profile-summary":"",className:"px-4 py-[13px]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx($x,{profile:i}),e.jsx("div",{className:"min-w-0 flex-1",children:r||c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:r||c}),r&&c&&e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("settings.simple.account.yourName")}),e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.account.noNameHint")})]})}),e.jsx("button",{type:"button","aria-expanded":n,"aria-controls":o,className:"ui-button shrink-0",onClick:()=>a(!n),children:n?t("common.done"):t(r||c?"settings.simple.account.edit":"settings.simple.account.add")})]}),e.jsx("div",{id:o,ref:d,hidden:!n,className:"mt-4",children:n&&e.jsx(mr,{})})]})}function pr({row:s=!1}){const n=!!G().state.config?.team,[a,i]=l.useState(null),[r,c]=l.useState(!1),o=l.useId();l.useEffect(()=>{if(!n)return;let m=!0;return U("/api/me/away-emails",{timeoutMs:1e4}).then(u=>{m&&i(u.on)},()=>{}),()=>{m=!1}},[n]);const d=m=>{const u=a;i(m),c(!1),U("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:m}),timeoutMs:1e4}).then(x=>i(x.on),()=>{i(u),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:o,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(me,{"aria-labelledby":o,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 xr(){const{state:s,dispatch:n}=G(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=l.useState(null),[o,d]=l.useState(""),m=l.useRef(!1),u=async x=>{if(!(m.current||x===a)){m.current=!0,c(x),d("");try{const p=await U("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:x}})});n({type:"configStatus",config:p})}catch(p){d(p instanceof Error?p.message:t("settings.threads.error"))}finally{m.current=!1,c(null)}}};return e.jsxs(X,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx(de,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:x=>{u(Number(x.target.value))},children:Array.from({length:16},(x,p)=>p+1).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:i?t("settings.threads.starter"):t("settings.threads.helpHanded")}),r!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function hr(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),m=l.useRef(!1),u=a??s.config?.automaticRecovery??{enabled:!1},x=s.instances.filter(f=>f.snapshot.state==="available"&&!f.policy),p=x.find(f=>f.instanceId===u.backup?.instanceId),h=p?.models.options.filter(f=>!f.orgBlocked&&!f.needsCliUpdate&&(p.snapshot.authenticated!==!1||f.custom))??[],g=h.some(f=>f.id===u.backup?.model),b=f=>{i(f),d("")},y=async()=>{if(!(!a||m.current||u.enabled&&!g)){m.current=!0,c(!0),d("");try{const f=await U("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:f}),i(null)}catch(f){d(f instanceof Error?f.message:t("settings.recovery.error"))}finally{m.current=!1,c(!1)}}};return e.jsxs(X,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(me,{id:"automatic-recovery-enabled",checked:u.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>b({...u,enabled:!u.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scopeHanded")}),e.jsx("p",{id:"automatic-recovery-own",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.ownBackups")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs(de,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:u.backup?.instanceId??"",disabled:r||!u.enabled,onChange:f=>b({enabled:u.enabled,...f.target.value?{backup:{instanceId:f.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),u.backup&&!p&&e.jsx("option",{value:u.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.instanceId})}),x.map(f=>e.jsx("option",{value:f.instanceId,disabled:!f.models.options.some(j=>f.snapshot.authenticated!==!1||j.custom),children:f.displayName},f.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs(de,{className:"mt-2 w-full",id:"automatic-recovery-model",value:u.backup?.model??"",disabled:r||!u.enabled||!p,onChange:f=>b({enabled:u.enabled,backup:{instanceId:p.instanceId,model:f.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),u.backup?.model&&!g&&e.jsx("option",{value:u.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.model})}),h.map(f=>e.jsx("option",{value:f.id,children:f.label},f.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),u.enabled&&!g&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||u.enabled&&!g,onClick:()=>{y()},className:"mt-3 cursor-pointer rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:r?t("settings.threads.saving"):t("common.save")}),r&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}const gr=1,fr=3650,Hx=30,It=1024*1024,ys=256*1024,br=4*1024*1024*1024,Wx=50;function ha(s){const n=Number(s);return Number.isInteger(n)&&n>=gr&&n<=fr?n:null}function ga(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*It);return a>=ys&&a<=br&&a%ys===0?a:null}function fa(s){const n=s/It;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function yr(){const{state:s,dispatch:n}=G(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,g]=l.useState(null),b=l.useRef(!1),y=r??String(a===null?Hx:a),f=o??(i===null?String(Wx):fa(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&fa(i)===o&&d(null)},[i,o]);const j=async(k,B)=>{if(!b.current){b.current=!0,u(B),p(""),g(null);try{const v=await U("/api/config",{method:"PATCH",body:JSON.stringify({threads:k})});n({type:"configStatus",config:v})}catch(v){p(v instanceof Error?v.message:t("settings.threadCleanup.error"))}finally{b.current=!1,u(null)}}},C=k=>{if(!k){c(null),p(""),g(null),j({eventLogRetentionDays:null},"retention");return}const B=ha(y);if(B===null){p(t("settings.threadCleanup.invalidRetention")),g("retention");return}j({eventLogRetentionDays:B},"retention")},w=k=>{if(!k){d(null),p(""),g(null),j({eventLogMaxBytes:null},"cap");return}const B=ga(f);if(B===null){p(t("settings.threadCleanup.invalidCap")),g("cap");return}j({eventLogMaxBytes:B},"cap")},S=()=>{if(a===null)return;const k=ha(y);if(k===null){p(t("settings.threadCleanup.invalidRetention")),g("retention");return}if(k===a){c(null),p("");return}j({eventLogRetentionDays:k},"retention")},P=()=>{if(i===null)return;const k=ga(f);if(k===null){p(t("settings.threadCleanup.invalidCap")),g("cap");return}if(k===i){d(null),p("");return}j({eventLogMaxBytes:k},"cap")};return e.jsxs(X,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:m!==null,onChange:k=>C(k.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:gr,max:fr,step:1,inputMode:"numeric",value:y,disabled:a===null||m!==null,"aria-invalid":h==="retention","aria-describedby":"thread-log-retention-help",onChange:k=>{c(k.target.value),p(""),g(null)},onBlur:S,onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:m!==null,onChange:k=>w(k.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:ys/It,max:br/It,step:.25,inputMode:"decimal",value:f,disabled:i===null||m!==null,"aria-invalid":h==="cap","aria-describedby":"thread-log-cap-help",onChange:k=>{d(k.target.value),p(""),g(null)},onBlur:P,onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),m!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}const ba="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function Gx(){const s=il(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=an,m=()=>{const u=rl({name:n,url:i},window.location.origin);if(!u.ok){o(u.error);return}rn([...s,{id:ll(s),name:u.name,url:u.url}]),a(""),r(""),o("")};return e.jsx(X,{title:t("webPanels.settings.title"),subtitle:t("webPanels.settings.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[s.length>0&&e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-lg border border-hairline/40",children:s.map(u=>e.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:u.url,children:u.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>rn(s.filter(x=>x.id!==u.id)),children:t("webPanels.settings.remove")})]},u.id))}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{"aria-label":t("webPanels.settings.name"),placeholder:t("webPanels.settings.name"),value:n,maxLength:ln,disabled:d,"aria-invalid":c==="name",onChange:u=>{a(u.target.value),o("")},className:`${ba} sm:w-40 ${c==="name"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("input",{"aria-label":t("webPanels.settings.url"),placeholder:"https://",type:"url",inputMode:"url",value:i,disabled:d,"aria-invalid":c==="url"||c==="self",onChange:u=>{r(u.target.value),o("")},onKeyDown:u=>{u.key==="Enter"&&m()},className:`${ba} flex-1 ${c==="url"||c==="self"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:m,children:t("webPanels.settings.add")})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:ln})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:an}):t("webPanels.settings.help")})]})})}const is="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Je=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Oe(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},ya=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Vx(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=l.useState(null),r=l.useRef(0),c=l.useRef(0);return l.useEffect(()=>{const o=++r.current,d=c.current;i(null);const m=x=>{r.current===o&&(c.current++,i(x))},u=s?.onState(m);return s?.state().then(x=>{c.current===d&&m(x)}).catch(()=>{}),()=>{r.current++,u?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(qx,{bridge:n}):e.jsx(Jx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function qx({bridge:s}){const[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(""),d=l.useRef(0);if(l.useEffect(()=>{const u=++d.current,x=s.onState(p=>{u===d.current&&a(p.schedule??null)});return s.state().then(p=>{u===d.current&&a(p.schedule??null)}).catch(()=>{}),()=>{d.current++,x()}},[s]),!s.configureSchedule||!n?.enabled)return null;const m=async()=>{if(i||!s.configureSchedule)return;const u=d.current;r(!0),o("");try{const x=await s.configureSchedule({enabled:!1});u===d.current&&a(x.schedule??null)}catch{u===d.current&&o(t("companyBackup.scheduleFailed"))}finally{u===d.current&&r(!1)}};return e.jsx(X,{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(me,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{m()}})]}),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 Jx({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,g]=l.useState(null),[b,y]=l.useState(""),[f,j]=l.useState(""),[C,w]=l.useState(null),[S,P]=l.useState(!1),k=l.useRef(0),B=l.useRef(0),v=l.useRef(0),A=l.useRef(void 0),I=l.useRef(!1),_=l.useRef(null),D=async()=>{const K=k.current,ae=++v.current,L=B.current;d(!0);try{await Promise.all([n.state().then(E=>{K===k.current&&ae===v.current&&B.current===L&&i(E)}),n.list().then(E=>{K===k.current&&ae===v.current&&c(E)})]),K===k.current&&ae===v.current&&p("")}catch{K===k.current&&ae===v.current&&p(t("companyBackup.loadFailed"))}finally{K===k.current&&ae===v.current&&d(!1)}};l.useEffect(()=>{const K=++k.current,ae=E=>{if(K!==k.current)return;B.current++,i(E);const W=E.lastBackupAt??E.schedule?.lastBackupAt;!E.busy&&!E.pendingRestore&&W&&W!==A.current&&(A.current=W,D())},L=n.onState(ae);return D(),()=>{k.current++,v.current++,L()}},[n]),l.useEffect(()=>{const K=_.current;if(!(!h||!K))return K.showModal(),()=>{K.close()}},[h]);const Q=S||a?.pendingRestore===!0,H=m!==null||!a||a.busy||Q,N=()=>{g(null),y(""),j(""),w(null)},Z=K=>{H||I.current||(p(""),y(""),j(""),w(null),g(K))},te=async(K,ae)=>{if(H||I.current)return;I.current=!0,u(K),p("");const L=k.current;try{await ae(()=>L===k.current)}catch{L===k.current&&p(t(K==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{I.current=!1,L===k.current&&u(null)}},T=()=>{h?.kind==="create"&&te("create",async K=>{await n.create({clientState:Qo()}),K()&&(N(),await D())})},R=async K=>{if(!n.configureSchedule||I.current||!a||K&&(H||h?.kind!=="schedule"||f!=="BACK UP THIS WORKSPACE DAILY"))return;I.current=!0,u("schedule"),p("");const ae=k.current,L=B.current;j("");try{const E=await n.configureSchedule(K?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});ae===k.current&&(B.current===L&&i(E),N())}catch{ae===k.current&&p(t("companyBackup.scheduleFailed"))}finally{I.current=!1,ae===k.current&&u(null)}},Y=()=>{h?.kind!=="restore"||h.entry.passwordRequired!==!1&&(b.length<12||b.length>1024)||te("prepare",async K=>{const ae=b;y(""),w(null),j("");const L=await n.prepareRestore({id:h.entry.id,...h.entry.passwordRequired!==!1?{password:ae}:{}});K()&&w(L)})},re=()=>{h?.kind!=="restore"||!C||f!=="REPLACE"||te("restore",async K=>{const ae=localStorage.getItem(fn);if(ae&&ae!==C.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(fn,C.id),await n.restore({id:C.id,confirmation:"REPLACE"}),K()&&(P(!0),N())})},pe=()=>{h?.kind!=="delete"||f!=="DELETE"||te("delete",async K=>{await n.delete({id:h.entry.id,confirmation:"DELETE"}),K()&&(N(),await D())})},xe=async()=>{const K=k.current;try{await n.cancel()}catch{K===k.current&&p(t("companyBackup.actionFailed"))}},le=r?.backups.filter(K=>K.status==="ready")??[],$=r?r.backups.length-le.length:0,ne=a?.progress,fe=x||a?.message,oe=(a?.busy||m)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:m==="restore"?t("backup.restoring"):ne?t(`companyBackup.phase.${ne.phase}`):t("companyBackup.working")}),ne&&ne.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:ne.totalBytes,value:Math.min(ne.bytesTransferred,ne.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Je(ne.bytesTransferred),total:Je(ne.totalBytes)})})]}),a?.busy&&m!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{xe()},children:t("companyBackup.cancelTransfer")})]}),se=h?.kind==="restore"?t("companyBackup.restore"):h?.kind==="delete"?t("companyBackup.delete"):h?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ie=a?.schedule,be=K=>new Intl.DateTimeFormat(Oe(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(K));return e.jsxs(X,{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&&ie&&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(me,{"aria-label":t("companyBackup.daily"),checked:ie.enabled,disabled:m!==null||!a||!ie.enabled&&H,onClick:()=>ie.enabled?void R(!1):Z({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ie.status}`)}),ie.enabled&&ie.nextBackupAt&&Number.isFinite(ie.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:be(ie.nextBackupAt)})}),ie.lastBackupAt&&Number.isFinite(ie.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:be(ie.lastBackupAt)})}),ie.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ie.message})]}),Q?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(gn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:H,onClick:()=>Z({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m!==null||a?.busy||Q||o,onClick:()=>{D()},children:t("companyBackup.refresh")})]}),o&&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:Je(r.usedBytes),total:Je(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),$>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:$})}),r&&le.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:le.map(K=>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:ya(K)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Je(K.sizeBytes),K.appVersion?` · ${K.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:K.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:H,onClick:()=>Z({kind:"restore",entry:K}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H,onClick:()=>Z({kind:"delete",entry:K}),children:t("companyBackup.delete")})]})]},K.id))})]}),!h&&oe,!h&&fe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:fe})]}),h&&e.jsx("dialog",{ref:_,"aria-labelledby":"company-backup-dialog-title",onKeyDown:K=>{(K.key==="Escape"||K.key==="Tab")&&K.stopPropagation()},onCancel:K=>{K.preventDefault(),m||N()},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(gn,{}),(h.kind==="restore"||h.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[ya(h.entry)," · ",Je(h.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:h.entry.id})]}),(h.kind==="create"||h.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:K=>{K.preventDefault(),h.kind==="schedule"?R(!0):T()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(h.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),h.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")}),h.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:H,checked:f==="BACK UP THIS WORKSPACE DAILY",onChange:K=>j(K.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:H||h.kind==="schedule"&&f!=="BACK UP THIS WORKSPACE DAILY",children:t(h.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),h.kind==="restore"&&(C?e.jsxs(e.Fragment,{children:[e.jsx(Xo,{summary:C.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:H,value:f,onChange:K=>j(K.target.value),className:is})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H||f!=="REPLACE",onClick:re,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:K=>{K.preventDefault(),Y()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),h.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:H,value:b,onChange:K=>y(K.target.value),className:is})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:H||h.entry.passwordRequired!==!1&&(b.length<12||b.length>1024),children:t("backup.validate")})]})),h.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:H,value:f,onChange:K=>j(K.target.value),className:is})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:H||f!=="DELETE",onClick:pe,children:t("companyBackup.delete")})]}),oe,fe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:fe}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:m!==null,onClick:N,children:t("companyBackup.cancel")})]})})]})}function Yx({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(dc,{size:12},a);case"gemini":return e.jsx(Ra,{preset:"google",size:12},a);default:return e.jsx(cc,{size:12},a)}})})}function va({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:o,onChange:d}){return e.jsxs("label",{className:M("flex items-start gap-3 px-3.5 py-3 transition-colors",o?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:o,onChange:m=>d(m.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(Yx,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const vr="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 Xx({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:o}){const d=i==="working";let m;if(!s)m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)m=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(J,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:u,notes:x,done:p}=nc(r);m=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:M("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",p?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:p?e.jsx(ge,{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:u}),x.map(h=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:h},h))]})]})}else!n||ic(n)===0?m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):m=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(va,{icon:e.jsx(Ps,{size:15}),label:t("onboarding.import.skills"),summary:rc(n),hint:t("onboarding.import.skillsHint"),sources:bn(n.skills),checked:a.skills,disabled:d,onChange:u=>c({...a,skills:u})}),n.tools.length>0&&e.jsx(va,{icon:e.jsx(oc,{size:15}),label:t("onboarding.import.tools"),summary:lc(n),hint:t("onboarding.import.toolsHint"),sources:bn(n.tools),checked:a.tools,disabled:d,onChange:u=>c({...a,tools:u})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:o,disabled:d||!(a.skills||a.tools),className:M(vr,"mt-3"),children:[d&&e.jsx(J,{size:14,className:"animate-spin"}),d?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return 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:m})]})}function Qx({client:s,local:n}){const[a,i]=l.useState(void 0),[r,c]=l.useState({skills:!0,tools:!0}),[o,d]=l.useState("idle"),[m,u]=l.useState(null);l.useEffect(()=>{if(!n)return;const p=new AbortController;return s.detect(p.signal).then(i,()=>i(null)),()=>p.abort()},[s,n]);const x=async()=>{if(!a||o==="working")return;const p={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!p.skills&&!p.tools)){d("working");try{const h=await s.apply(p);Zc("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),u(h),d("idle")}catch{d("failed")}}};return e.jsx(Xx,{local:n,detection:a,chosen:r,status:o,result:m,onChoose:c,onBring:()=>{x()}})}function Zx(){const[s,n]=l.useState(!1),[a,i]=l.useState(!1);return 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(tc,{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:M(vr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Na,{size:14,"aria-hidden":"true",className:M("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(sc,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function kr({client:s=Zo}){const{state:n}=G();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Qx,{client:s,local:ec(n.config?.cloudHome===!0)}),e.jsx(Zx,{})]})}function jr({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(eh,{simple:s}),e.jsx(th,{simple:s}),e.jsx(sh,{simple:s})]})}const ka=()=>typeof Notification<"u"?Notification.permission:"default";function eh({simple:s=!1}){const[n,a]=l.useState(ka),i=mc();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(ka())};return window.addEventListener("focus",o),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",o),document.removeEventListener("visibilitychange",o)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return yn(!i);const o=await fc();o&&(a(o),o==="granted"&&yn(!0))};return e.jsx(ce,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(me,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function th({simple:s=!1}){const n=pc();return e.jsx(ce,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>xc(!n)})})}function sh({simple:s=!1}){const n=hc();return e.jsx(ce,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>gc(!n)})})}function Nr(){const{state:s,dispatch:n}=G(),a=bc(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!yc(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const m=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:m})}catch(m){o(m instanceof Error?m.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(ce,{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(me,{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 nh=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],ah=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function ih({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(ye,{label:t("settings.group.account"),block:"general",children:e.jsxs(ve,{children:[s("general")&&e.jsx(Kx,{}),s("general")&&e.jsx(pr,{row:!0}),s("general")&&e.jsx(hi,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(Ui,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(ye,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(ve,{children:[e.jsx(ar,{simple:!0}),e.jsx(rh,{onLooks:a}),e.jsx(Hi,{}),e.jsx(Ya,{}),e.jsx(Wi,{}),e.jsx(mi,{simple:!0})]})}),s("appearance")&&e.jsx(ye,{label:t("settings.simple.group.typing"),children:e.jsxs(ve,{children:[e.jsx(os,{simple:!0}),e.jsx(pi,{simple:!0}),e.jsx(xi,{simple:!0})]})}),s("appearance")&&e.jsx(ye,{label:t("notifications.title"),children:e.jsx(ve,{children:e.jsx(jr,{simple:!0})})}),s("general")&&e.jsx(ye,{label:t("settings.simple.group.system"),children:e.jsxs(ve,{children:[e.jsx(vi,{simple:!0}),e.jsx(Xa,{simple:!0}),e.jsx(ki,{}),e.jsx(ji,{}),e.jsx(yi,{simple:!0})]})}),s("import")&&e.jsx(ye,{label:t("settings.section.import"),block:"import",children:e.jsx(ke,{children:e.jsx(kr,{})})}),s("organization")&&e.jsx(ye,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Vi,{})}),s("activity")&&e.jsx(ye,{label:t("settings.section.activity"),block:"activity",children:e.jsx(Di,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(ve,{children:e.jsx(ce,{title:t("settings.simple.more.title"),subtitle:t("settings.simple.more.subtitle"),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more":"",onClick:i,children:t("settings.simple.more.open")})})})}),e.jsx("div",{"data-settings-block":"advanced-mode",className:"scroll-mt-4",children:e.jsx(ve,{children:e.jsx(cs,{simple:!0})})})]})}function rh({onLooks:s}){const n=Hs(),a=Cs.find(r=>r.id===wa(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(ce,{title:t("settings.theme.title"),subtitle:i,children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.themes.browse")})})}function lh({onBack:s,toolCalls:n=!0}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.looks.back")})}),e.jsx("div",{"data-settings-block":"looks",children:e.jsx(ir,{})}),n&&e.jsx(ve,{children:e.jsx(ui,{})})]})}function oh({sections:s,onOpen:n,onBack:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("settings.simple.looks.back")})}),s.length>0&&e.jsx(ye,{block:"more-sections",children:e.jsx(ve,{children:s.map(({id:i,labelKey:r})=>e.jsx(ce,{title:t(r),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more-section":i,onClick:()=>n(i),children:t("settings.simple.more.open")})},i))})}),e.jsx(ye,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(X,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(rr,{})}),e.jsx(X,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(cr,{})}),e.jsx(xr,{}),e.jsx(hr,{}),e.jsx(yr,{}),e.jsx(Ai,{}),e.jsx(ve,{children:e.jsx(Nr,{})})]})})]})}function ch({has:s,disclose:n,connections:a}){return e.jsxs(e.Fragment,{children:[s("engines")&&e.jsx("div",{"data-settings-block":"engines",className:"flex scroll-mt-4 flex-col gap-7",children:e.jsxs(ke,{children:[e.jsx(Pi,{simple:!0,more:n("ai-more")}),e.jsx(ve,{children:e.jsx(di,{simple:!0})})]})}),s("connections")&&e.jsx(ke,{children:e.jsx(Rt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function dh({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(ye,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(ke,{children:e.jsx(Bi,{})})}),s("companion")&&e.jsxs(ye,{label:t(Ja()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(ye,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(ve,{children:[e.jsx(li,{}),e.jsx(oi,{})]}),e.jsx(ci,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(Ki,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(Rt,{title:t("settings.simple.computer.elsewhere"),block:"elsewhere",...i("computer-elsewhere"),children:[s("desktopWorkspaces")&&e.jsx("div",{"data-settings-block":"desktopWorkspaces",className:"flex scroll-mt-4 flex-col gap-4",children:a}),s("companion")&&e.jsx("div",{"data-settings-block":"remote",className:"flex scroll-mt-4 flex-col gap-4 empty:hidden",children:n.client})]})]})}function uh({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=vc();return vd(),e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(kc,{usage:i,upgrade:r,children:c}):e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(Zp,{})})}),(i||s("usage"))&&e.jsxs(Rt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(jc,{usage:i,upgrade:r}),s("usage")&&e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(tr,{})})]}),s("cloudAccount")&&e.jsxs(ye,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(kd,{}),children:[e.jsx(ve,{children:e.jsx(hi,{place:"plan",usage:i,upgrade:r})}),e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const wr=()=>`${js()} ${Nc()}`;function mh(){const s=wc(!0);if(!s)return null;const n=s.phase==="idle"?void 0:[s.label,s.item.subtitle].filter(Boolean).join(" "),a=s.phase==="available"?t("settings.simple.updates.seeRelease"):s.phase==="reload"?t("settings.simple.updates.reload"):s.phase==="checking"?t("common.checking"):t("settings.updates.check");return e.jsx(ce,{title:wr(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function ph({remoteActive:s}){return e.jsx(ye,{block:"updates",children:e.jsxs(ve,{children:[window.ogb?.updater?e.jsx(ii,{title:wr()}):e.jsx(mh,{}),e.jsx(qa,{}),!s&&e.jsx(ri,{}),e.jsx(Ni,{simple:!0})]})})}const ja=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Ws=[{id:"general",group:"you",labelKey:"settings.section.general",icon:Va,keywords:["profile","pinned panels","web panel","dashboard","pin a page","name","email","about me","about","suggestions","suggested","memory","analytics","updates","product updates","newsletter","email updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","attachments","clear attachments","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule","usage","limit","plan","upgrade","cloud desktop hours","storage","saved steps","repeat","replay","computer tasks","without ai","forget",...xu()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ed,keywords:["skin","theme","appearance","font","typeface","chat width","width","wide","full width","bubble","bubbles","tools","tool calls","threads","show threads","hide threads","sidebar","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top","send","enter","return","shift+enter","ctrl+enter","cmd+enter","⌘+enter","new line","keyboard","ime","japanese","message color","my messages","toolbar","tools layout","footer","routines","triggers","team map","color","colour","cloud color","server color","tint","sidebar color","sidebar picture","picture","image","banner","background","computers","your computers","rail","strip","frame","window frame","title bar"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Sc,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:Td,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:_a,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","meta","muse","vps","router","openrouter","base url","openai","anthropic","groq","greenference","modelgo","opencode","deepseek","provider","ollama","lm studio","lmstudio","llm studio","llmstudio","bionic"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:Cc,keywords:["decision","extraction","jev","typesafe","cloudflare","workers ai","clef","clairic","email","routing","auto","rooms","who answers"]},{id:"imageGeneration",group:"ai",labelKey:"settings.section.imageGeneration",icon:Ec,keywords:["image","images","picture","generate","avatar","gpt image","grok imagine","gemini","nano banana","openrouter","flux","backup"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:Ps,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:_t,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:gi,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:Ot,keywords:["vault","logins","login","passwords","password","sign in","2fa","one-time code","totp","fill_login","1password","password manager","secrets","secret","token",".env","env"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:Ns,keywords:["cloud","my cloud","account","personal","sign in","pro","subscription","billing","sync","send","this computer","bots","logins","1password"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:_t,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:Nd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:Qa,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:Ye,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:St,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:St,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:Id,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:_t,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:Ac,keywords:["early","preview","learn","skill","authoring"]}],xh=[{id:"general",labelKey:"settings.section.general",icon:Ic,sections:["general","appearance","people","import","organization","activity"],keywords:["account","theme","looks","open at login","startup","analytics","advanced mode","more settings","limits","timeout"]},{id:"botAccess",labelKey:"settings.section.botAccess",icon:St,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:Pc,sections:["engines","connections","imageGeneration"],keywords:["new bots","defaults","effort"]},{id:"skills",labelKey:"settings.section.skills",icon:Ps,sections:["skills"],keywords:["skills","skill hub","library","kỹ năng","thư viện"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:gi,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:Tc,sections:["usage","cloudAccount"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"backups",labelKey:"settings.section.backups",icon:Qa,sections:["backups"],keywords:["chuyển máy offline","transfer","export","import","restore","sao lưu"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:Sd,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],vs=["experimental","workspaces","decisionModel"],hh={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function gh(s,n){const a=xh.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=vs.includes(n)&&s.has(n)?Ws.find(r=>r.id===n):void 0;return i&&a.push({id:i.id,labelKey:i.labelKey,icon:i.icon,sections:[i.id]}),a}function fh(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Bs(s,i)}function bh(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=Ws.find(r=>r.id===a);return i?ks(i,n):!1})}function ks(s,n){return!n||s.id==="connections"&&rt.some(a=>Es(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function yh(s){return s?rt.filter(n=>Es(n,s)).slice(0,8):[]}const vh=s=>s.uses?ls(s.uses,s.id):ls(s.id);function Hh(){return e.jsx(ti,{modal:!0,children:e.jsx(kh,{})})}function kh(){const s=ed(),{state:n,dispatch:a}=G(),i=ol(),r=window.ogb?.remoteClient?.active===!0,c=n.appSettingsSection,o=i&&c==="remote"&&window.ogb?.environments?"desktopWorkspaces":r&&!["appearance","desktopWorkspaces"].includes(c)||c==="remote"?"companion":i&&c==="updates"?"general":c,d=l.useRef(null),m=l.useRef(null),u=l.useRef(i),[x,p]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>p("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>p("")),[]);const h=x.trim().toLowerCase(),g=Pt(),b=Ja(),y=Ws.map(L=>L.id==="companion"?{...L,labelKey:b?"settings.section.phoneDevices":"settings.section.thisServer"}:L),j=y.filter(L=>!r||L.id==="companion"||L.id==="appearance"||L.id==="desktopWorkspaces").filter(L=>L.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(L=>L.id!=="organization"||!!window.ogb?.organization).filter(L=>L.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(L=>L.id!=="workspaces"||nr(n.config)).filter(L=>L.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(L=>L.id!=="activity"||!window.ogb&&g===!0).filter(L=>L.id!=="botAccess"||!!n.config?.team&&g===!0).filter(L=>(L.id!=="skills"||vn(n.config))&&(L.id!=="cloudAccount"||cl)),C=j.filter(L=>ks(L,h)),w=new Set([...j.map(L=>L.id),...r?[]:["updates"]]),S=i?[]:gh(w,o),P=S.filter(L=>bh(L,h)),k=S.find(L=>L.sections.includes(o)),B=i?y.find(L=>L.id===o)?.labelKey:k?.labelKey,v=i?C.some(L=>L.id===o)?void 0:C[0]?.id:k&&P.includes(k)?void 0:P[0]&&(P[0].sections.find(L=>C.some(E=>E.id===L))??P[0].sections[0]);l.useEffect(()=>{v&&a({type:"toggleAppSettings",open:!0,section:v})},[a,v]);const[A,I]=l.useState({}),_=Ca();l.useEffect(()=>{_&&I(L=>L["ai-keys"]?L:{...L,"ai-keys":!0})},[_]);const D=L=>{const E=h!==""||(A[L]??hh[c]===L);return{id:L,open:E,onToggle:()=>I(W=>({...W,[L]:!E}))}},[Q,H]=l.useState(null),N=Q?.for===c?Q.view:null,Z=(L,E=c)=>H(L&&{view:L,for:E});l.useEffect(()=>{H(L=>L?.for===c?L:null)},[c]);const[te,T]=l.useState(null),R=i||dl||!h?[]:nh.filter(L=>t(L).toLowerCase().includes(h)),Y=j.filter(L=>vs.includes(L.id)),re=r||!j.some(L=>L.id==="connections")?[]:yh(h),pe=L=>re.map(E=>e.jsx("button",{type:"button","data-settings-key-result":E.id,className:L,onClick:()=>{p(""),Z(null),a(vh(E))},children:e.jsxs("span",{children:[t(E.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(Rc(E).titleKey)]})]})},E.id)),xe=k?.sections.indexOf(o)??0,le=!i&&c==="remote"?"remote":o;l.useEffect(()=>{m.current&&fh(m.current,le,i?0:le===o?xe:1)},[i,le,o,xe]),l.useEffect(()=>{if(!te)return;const L=m.current?.querySelector(`[data-settings-block="${te}"]`);m.current&&L&&Bs(m.current,L),T(null)},[te]),l.useEffect(()=>{const L=document.activeElement instanceof HTMLElement?document.activeElement:null,E=d.current,W=E?.querySelector("[data-settings-search]");u.current&&W?.checkVisibility()?W.focus():E?.focus();const ue=q=>{if(!s())return;if(!u.current&&E&&document.activeElement===E&&q.key.length===1&&!q.metaKey&&!q.ctrlKey&&!q.altKey&&W?.checkVisibility()){q.preventDefault(),W.focus(),p(Me=>Me+q.key);return}if(q.defaultPrevented||E&&[...E.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(Me=>Me.getClientRects().length))return;if(q.key==="Escape"){q.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(q.key!=="Tab"||!E)return;const je=Array.from(E.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(Me=>Me.checkVisibility());if(je.length===0){q.preventDefault(),E.focus();return}const Ie=je[0],Ze=je[je.length-1],et=document.activeElement;q.shiftKey&&(et===Ie||!E.contains(et))?(q.preventDefault(),Ze.focus()):!q.shiftKey&&et===Ze&&(q.preventDefault(),Ie.focus())};return window.addEventListener("keydown",ue),()=>{window.removeEventListener("keydown",ue),L?.focus()}},[a,s]);const $=L=>a({type:"toggleAppSettings",open:!0,section:L}),ne=n.appSettingsPhonePairing,fe=ld(n.config?.cloudHome===!0)==="computer",oe={client:e.jsx(lp,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||b?null:e.jsx(Zm,{}),pairing:b?null:e.jsx(Lm,{cloudHome:n.config?.cloudHome===!0,focusRequest:fe?0:ne,team:n.config?.team?.name,teamPhoneBlocked:n.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:n.config.managedPolicy.organizationName}):null,simple:!i}),companion:b?e.jsx(Bm,{profileEmail:n.config?.profile?.email,focusRequest:ne,simple:!i}):null},se=L=>{switch(L){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(Vn,{}),oe.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Vi,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(Vp,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>a(od()),onAddCloud:i?()=>a({type:"openCloudAdd",source:"app_settings"}):void 0,onSignIn:()=>a({type:"openCloudAdd",source:"app_settings",signIn:!0})}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx(cs,{}),e.jsx(Xa,{}),e.jsx(ki,{}),e.jsx(jd,{}),e.jsx(Bc,{}),e.jsxs(X,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(mr,{}),e.jsx(pr,{})]}),e.jsx(os,{}),e.jsx(vi,{}),e.jsx(bd,{}),e.jsx(Nr,{}),e.jsx(yi,{}),e.jsx(qa,{}),e.jsx(di,{}),e.jsx(X,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(rr,{})}),e.jsx(X,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(cr,{})}),e.jsx(xr,{}),e.jsx(hr,{}),e.jsx(yr,{}),e.jsx(ji,{}),e.jsx(Gx,{}),!r&&e.jsx(ri,{}),e.jsx(ii,{}),e.jsx(Ni,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(ar,{}),e.jsx(X,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(ir,{})}),e.jsx(kp,{}),r&&e.jsx(cs,{}),r&&e.jsx(os,{}),e.jsx(Px,{}),e.jsx(Tx,{}),e.jsx(mi,{}),e.jsx(pi,{}),e.jsx(xi,{}),e.jsx(Rx,{}),e.jsx(Ya,{}),e.jsx(Wi,{}),e.jsx(xd,{}),e.jsx(hd,{}),e.jsx(gd,{}),e.jsx(jr,{}),!r&&e.jsx(ui,{}),e.jsx(fd,{})]});case"experimental":return e.jsx(pd,{});case"connections":return e.jsx(ke,{children:e.jsx(pu,{})});case"decisionModel":return e.jsx(ke,{children:e.jsx(wu,{})});case"imageGeneration":return e.jsx(ke,{children:e.jsx(Lu,{})});case"engines":return e.jsx(ke,{children:e.jsx(Pi,{})});case"backups":return e.jsxs(ke,{children:[e.jsx(Lc,{}),e.jsx(Vx,{})]});case"import":return e.jsx(ke,{children:e.jsx(kr,{})});case"companion":return e.jsxs(e.Fragment,{children:[oe.companion,oe.pairing,oe.domain,window.ogb?.environments?null:oe.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(li,{}),e.jsx(oi,{}),e.jsx(ci,{}),e.jsx(ke,{children:e.jsx(Bi,{})})]});case"logins":return e.jsx(Ki,{});case"usage":return e.jsx(ke,{note:"settings.adminOnly.usage",children:e.jsx(tr,{})});case"skills":return vn(n.config)?e.jsx(yx,{}):null;case"people":return e.jsx(Ui,{});case"activity":return e.jsx(Di,{});case"botAccess":return e.jsx(Km,{});case"workspaces":return e.jsx(Cx,{});default:return null}},ie=()=>{$("general"),Z("more","general")},be=L=>{const E=W=>L.sections.includes(W);switch(L.id){case"general":return N==="looks"?e.jsx(lh,{toolCalls:!r,onBack:()=>{Z(null),T("appearance")}}):N==="more"?e.jsx(oh,{sections:Y,onOpen:W=>{Z(null),$(W)},onBack:()=>{Z(null),T("more")}}):e.jsx(ih,{has:E,peopleOpen:o==="people",onLooks:()=>Z("looks"),onMore:E("general")?()=>Z("more"):void 0});case"ai":return e.jsx(ch,{has:E,disclose:D,connections:se("connections")});case"computer":return e.jsx(dh,{has:E,remoteAccess:oe,servers:e.jsx(Vn,{}),disclose:D});case"billing":return e.jsx(uh,{has:E,disclose:D,cloudAccount:se("cloudAccount")});case"updates":return e.jsx(ph,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[vs.includes(L.sections[0])&&w.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:ie,children:t("settings.simple.looks.back")})}),L.sections.map(W=>e.jsx("section",{"data-settings-block":W,className:"flex scroll-mt-4 flex-col gap-4",children:se(W)},W))]})}},K=()=>a({type:"toggleAppSettings",open:!1}),ae=(L,E)=>e.jsxs("div",{className:L,children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:x,onChange:W=>p(W.target.value),onKeyDown:W=>{W.key==="Escape"&&(W.stopPropagation(),x?p(""):K())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:E})]});if(!i){const L=k?.id==="general"?N:null,E="flex min-h-8 shrink-0 cursor-pointer items-center rounded-lg px-[9px] py-1.5 text-left text-[13px] leading-[18px] text-ink transition-colors hover:bg-ink/[0.06] motion-reduce:transition-none",W=q=>{Z(null),$(q)},ue=h?[...Y.filter(q=>ks(q,h)).map(q=>({key:q.id,labelKey:q.labelKey,open:()=>W(q.id)})),...(w.has("general")?ah:[]).filter(q=>t(q).toLowerCase().includes(h)).map(q=>({key:q,labelKey:q,open:()=>{ie(),T("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:jn(),onMouseDown:q=>q.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsx(Ud,{}),e.jsxs("nav",{"aria-label":t("settings.title"),className:"glass-rail hidden min-h-0 w-[198px] shrink-0 flex-col gap-0.5 overflow-y-auto px-3 py-4 sm:flex",children:[ae("mb-2 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"),P.length===0&&R.length===0&&ue.length===0&&re.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),P.map(q=>{const je=q.icon,Ie=q===k;return e.jsxs("button",{type:"button","data-settings-page":q.id,onClick:()=>W(q.sections[0]),"aria-current":Ie?"page":void 0,className:M("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",Ie?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(je,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:t(q.labelKey)})]},q.id)}),R.map(q=>e.jsx("button",{type:"button","data-settings-advanced-only":q,onClick:()=>{p(""),W("general"),T("advanced-mode")},className:E,children:e.jsxs("span",{children:[t(q)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},q)),ue.map(q=>e.jsx("button",{type:"button","data-settings-more-result":q.key,onClick:()=>{p(""),q.open()},className:E,children:e.jsxs("span",{children:[t(q.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},q.key)),pe(E)]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center gap-3 py-3 pl-4 pr-14 sm:pb-1.5 sm:pl-12 sm:pt-8",children:[e.jsx(de,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:k?.id??"",onChange:q=>{p("");const je=S.find(Ie=>Ie.id===q.target.value);je&&W(je.sections[0])},children:S.map(q=>e.jsx("option",{value:q.id,children:t(q.labelKey)},q.id))}),e.jsx("h2",{className:"hidden truncate text-[17px] font-medium leading-6 tracking-[-0.008em] text-ink sm:block",children:L==="looks"?t("settings.simple.page.looks"):L==="more"?t("settings.simple.more.title"):k?t(k.labelKey):null})]}),e.jsx("button",{type:"button",onClick:K,"aria-label":t("settings.close"),title:`${t("settings.close")} (${kn("close-panel")})`,className:"absolute right-5 top-[18px] flex size-8 cursor-pointer items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink motion-reduce:transition-none",children:e.jsx(_e,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{ref:m,"data-settings-scroll":!0,className:M("settings-scroll flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-4 pb-10 pt-4 sm:px-8 sm:pb-12 sm:pt-[22px]",Ka,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(la,{config:n.config}),k?be(k):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:jn(),onMouseDown:L=>L.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),ae("mb-2 mt-1 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-tertiary focus:outline-none"),C.length===0&&e.jsx("div",{className:"px-2.5 py-4 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),ja.map(L=>{const E=C.filter(W=>W.group===L.id);return E.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${L.id}`,"data-settings-group":L.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${L.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(L.labelKey)}),E.map(({id:W,labelKey:ue,icon:q})=>e.jsxs("button",{"data-settings-section":W,onClick:()=>$(W),"aria-current":o===W?"page":void 0,className:M("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",o===W?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(q,{size:15,className:"shrink-0"}),t(ue)]},W))]},L.id)}),pe("cursor-pointer flex min-h-9 items-center rounded-lg px-2.5 py-2 text-left text-[13px] text-ink transition-colors hover:bg-control/50 motion-reduce:transition-none")]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:pl-9",children:[e.jsx(de,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:L=>{p(""),$(L.target.value)},children:ja.map(L=>{const E=j.filter(W=>W.group===L.id);return E.length===0?null:e.jsx("optgroup",{label:t(L.labelKey),children:E.map(({id:W,labelKey:ue})=>e.jsx("option",{value:W,children:t(ue)},W))},L.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:B?t(B):null}),e.jsx("button",{onClick:K,"aria-label":t("settings.close"),title:`${t("settings.close")} (${kn("close-panel")})`,className:"ui-icon-button cursor-pointer shrink-0 max-md:size-9 max-md:rounded-full max-md:border max-md:border-hairline max-md:bg-card",children:e.jsx(_e,{size:18})})]}),e.jsxs("div",{ref:m,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(la,{config:n.config}),se(o)]})]})]})]})}export{Ws as SECTIONS,ja as SETTINGS_GROUPS,hh as SIMPLE_FOLDED,vs as SIMPLE_HIDDEN_SECTIONS,xh as SIMPLE_PAGES,Hh as SettingsModal,yh as keySearchResults,vh as openKeyResult,fh as revealSettingsBlock,ks as sectionMatches,gh as simpleSettingsPages};