limixbot 0.3.2 → 0.3.4
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.
- package/dist/assets/{ActivityPanel-BDwrkDBX.js → ActivityPanel-BG18nJiz.js} +1 -1
- package/dist/assets/{App-Cb2UOJS6.js → App-8heymKKb.js} +119 -119
- package/dist/assets/{AppEventEditor-B383TR3m.js → AppEventEditor-D5dGKlRO.js} +1 -1
- package/dist/assets/{BotSettingsDialog-CbbZerHF.js → BotSettingsDialog-Ct_Yktk8.js} +4 -4
- package/dist/assets/{BrowserPanel-DY-yCZ9T.js → BrowserPanel-Cyws1YTJ.js} +2 -2
- package/dist/assets/{BrowserProfilesManager-BmOMzdgM.js → BrowserProfilesManager-BEUgS3Me.js} +1 -1
- package/dist/assets/CloudAddDialog-UEPtzvka.js +1 -0
- package/dist/assets/{ComputerFilesPane-CB2u6MXN.js → ComputerFilesPane-BGywdHPB.js} +1 -1
- package/dist/assets/ComputerPanel-DLV2INTM.js +2 -0
- package/dist/assets/{DataPanel-fAjB6GSn.js → DataPanel-CIvvbY5b.js} +1 -1
- package/dist/assets/{DesktopViewer-mWGetNwB.js → DesktopViewer-BNIgo9Nm.js} +1 -1
- package/dist/assets/{FilesView-CLR6NiY2.js → FilesView-Cd5kwljm.js} +1 -1
- package/dist/assets/{GrokMoveDialog-lZOa5ZKz.js → GrokMoveDialog-B2Vgd-vB.js} +6 -6
- package/dist/assets/{InspectorPanel-lOPEUSb8.js → InspectorPanel-Bxm2bVHy.js} +2 -2
- package/dist/assets/{KeyboardShortcutsModal-BGRMc9wJ.js → KeyboardShortcutsModal-Dfcfy-EA.js} +1 -1
- package/dist/assets/{LiveDesktop-LRjYEzUz.js → LiveDesktop-fbnBEFRL.js} +1 -1
- package/dist/assets/LocalVmWorkspace-CBe48xft.js +1 -0
- package/dist/assets/{MacLocalControl-DuTxY3A3.js → MacLocalControl-CpVqwJts.js} +1 -1
- package/dist/assets/MarkdownFilePreview--PNcCEvm.js +1 -0
- package/dist/assets/{MenuMotion-DKMkKESs.js → MenuMotion-IQitGKH4.js} +1 -1
- package/dist/assets/{NewBotDialog-Bpi6-xSj.js → NewBotDialog-CZbVbamH.js} +1 -1
- package/dist/assets/PhoneAppDialog-B9oozUp0.js +1 -0
- package/dist/assets/{PlacesRail-4ErVypbT.js → PlacesRail-v1XIqiBG.js} +9 -9
- package/dist/assets/{PluginsPanel-Cw8XeQBF.js → PluginsPanel-Bj3Pn0Iw.js} +2 -2
- package/dist/assets/{ProIntroduction-DPYk--IK.js → ProIntroduction-qFeFSzyk.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-qxzESq_H.js → RemoteAgentSettingsPanel-CcbUTgTg.js} +1 -1
- package/dist/assets/{RoomPanel-DaoRmKS_.js → RoomPanel-k0hQwspJ.js} +2 -2
- package/dist/assets/{RoutinesPage-CD1DvtyW.js → RoutinesPage-aANJQ--g.js} +1 -1
- package/dist/assets/SettingsModal-t10M3Ahi.js +11 -0
- package/dist/assets/{ShareTeamDialog-rc1xx02E.js → ShareTeamDialog-DeRaL6zM.js} +1 -1
- package/dist/assets/{SignedInSites-CPp5ofCJ.js → SignedInSites-CfhTex9p.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-D-iDVZPU.js → TeamLibraryPanel-C7LZ7Onp.js} +1 -1
- package/dist/assets/TeamMapPage-BSvk8tOC.js +1 -0
- package/dist/assets/{TriggersPage-D2ovyRGM.js → TriggersPage-BdePfInC.js} +1 -1
- package/dist/assets/{VisibilitySection-oSi2vtmx.js → VisibilitySection-CCwpvTlJ.js} +1 -1
- package/dist/assets/{WebhookTrigger-CyP8At0y.js → WebhookTrigger-wqj5vki5.js} +1 -1
- package/dist/assets/WorksOnGrid-CenOXsZe.js +1 -0
- package/dist/assets/{abnfDiagram-YUKMZFIV-C7wn2CLu.js → abnfDiagram-YUKMZFIV-CBzJU2O6.js} +1 -1
- package/dist/assets/{activity-Cru8B1z7.js → activity-bd7MWK8m.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-DgFc7YIC.js → architectureDiagram-47P4ROYG-DVR1DP3v.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-qR-t8DMo.js → blockDiagram-E7TT5TSB-BYqUHhoh.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-DdmUjVbB.js → c4Diagram-CRA5TL53-BtQERHwr.js} +1 -1
- package/dist/assets/{calendar-days-CN7x0QvP.js → calendar-days-YMHxUvlg.js} +1 -1
- package/dist/assets/channel-D6e78p3W.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-D09jrdDt.js → chunk-2Q5K7J3B-Cwf_xeHP.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-DJXT-XDN.js → chunk-5VM5RSS4-Doo-zxI4.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-CaULsRlr.js → chunk-7TKQ45FW-CD2AgrRj.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-BcEB179w.js → chunk-AW2ZBBNX-e5OuWeq_.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-DMhPq4_N.js → chunk-FVRAUYC3-C8jo43it.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-DcoWRcH-.js → chunk-HTAEGDNF-DLsD4agj.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CpN6DEZO.js → chunk-JWPE2WC7-UZDUbeTy.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-BxIldIqB.js → chunk-KQW6MTUR-DR9SuVX3.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY--M4TxaOR.js → chunk-XXDRQBXY-DwEl4815.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-DQUUn5pg.js → classDiagram-v2-K4WV4PDN-CQZho8e0.js} +1 -1
- package/dist/assets/{coins-DxQLVJqa.js → coins-DpzGN3sd.js} +1 -1
- package/dist/assets/{core-CjjU--NA.js → core-C_G-J8y-.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-DCCMLnpT.js → cose-bilkent-JH36ORCC-DUZ9OWzu.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-iK--S4gB.js → cynefin-EF2NZ3EQ-DVHnJdjN.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-DiwEQVzk.js → cynefinDiagram-3GCD6N5R-dYhbIkRt.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-Bb-WXIrp.js → dagre-W4DXFKR2-DqJNpw5w.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-CU1G-LPy.js → diagram-2UJZ2QOL-DKNDqAnE.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-KUL_hQtY.js → diagram-OVF4WLC6-DENMVM-d.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-Du0EMvGo.js → diagram-PFPMY2P6-CrRFeR5V.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-BUNv47Vc.js → diagram-UMYRVEAY-B5w-desO.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-DyWO406P.js → diagram-YEKJPTXX-C7AVX3MB.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-DGps1w58.js → diagram-ZIFT7M5P-BgkTRwwr.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-BxaaJRK8.js → ebnfDiagram-VR2GEFS7-yY_2KNsK.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BuVZZmTr.js → elk-IJKZMXRS-xWtfkoqT.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-qhhsO6Fp.js → erDiagram-O2IAPWRE-BMM4saPI.js} +1 -1
- package/dist/assets/{file-up-BiK20g0M.js → file-up-Bl7ViNTL.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-BsRrcKnA.js → flowDiagram-OXPTDLAJ-BCRe8i6T.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-jVqCmREp.js → ganttDiagram-R7TSEDQI-COBrcDi7.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-COi9bChD.js → gitGraphDiagram-XJZIOB7I-Dc4RKydD.js} +1 -1
- package/dist/assets/{import-name-CrWA8Hw3.js → import-name-CKE76uoY.js} +1 -1
- package/dist/assets/index-BBsdMDZV.js +2 -0
- package/dist/assets/{index-Dy5VWChH.js → index-BXLNny-w.js} +1 -1
- package/dist/assets/{index-BIC6c7Sg.js → index-jlMtdqfJ.js} +1 -1
- package/dist/assets/{infoDiagram-5W2HQ5XZ-CUfzOgVW.js → infoDiagram-5W2HQ5XZ-BV8RRI_4.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-DMR_Ey1I.js → ishikawaDiagram-K3B6WC7H-H-XILdGm.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-UiPc_2sp.js → journeyDiagram-COXZFDF6-ChLduKEj.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-VvQXCMxr.js → kanban-definition-P3RFRI5V-FSZ9F3JH.js} +1 -1
- package/dist/assets/{mcp-servers-CBCpG62C.js → mcp-servers-DGQioE-C.js} +1 -1
- package/dist/assets/{mermaid.core-BZKmLobY.js → mermaid.core-BRsJ02Pz.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-BJi3q0s6.js → mindmap-definition-LZFPQGKD-TWHzZjNT.js} +1 -1
- package/dist/assets/{minimize-B78LHbd3.js → minimize-BYscOtPM.js} +1 -1
- package/dist/assets/{monitor-UBjV7Qf5.js → monitor-DFEzCfQk.js} +1 -1
- package/dist/assets/{new-bot-D0DDXTKe.js → new-bot-7IqfI7S4.js} +2 -2
- package/dist/assets/{org-library-BdlqWown.js → org-library-BW4CqVd6.js} +1 -1
- package/dist/assets/{package-format-EwGfXp1v.js → package-format-BOH5_nvi.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-C6W87HN9.js → pegDiagram-BGZESJAR-LQWOF7IE.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-B1E_Ycub.js → pieDiagram-CAPJLFHJ-BRXp4qFw.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-BasGTzC_.js → quadrantDiagram-GDMTTRAM-DyIdGBZo.js} +1 -1
- package/dist/assets/{rail-BFRrwJ6b.js → rail-Du7tlPwj.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-BZVzOUlx.js → railroadDiagram-SM67HX2B-BrL1MhW1.js} +1 -1
- package/dist/assets/{remote-desktop-panel--ikzFjV8.js → remote-desktop-panel-B9rqQRMc.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-C8s2XakO.js → requirementDiagram-X7JNWC4A-DTYjaC8j.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-CCCP1mnQ.js → sankeyDiagram-UM26HJRW-BR9dASO5.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-BvwC79vw.js → sequenceDiagram-ZO4K6R2Y-BR1k8h2_.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-DzRVDjCL.js → sizeCapture-INFHLROL-u8zOvZVi.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-CKVmZfLe.js → stateDiagram-v2-TBUQTH76-mQ64BAFv.js} +1 -1
- package/dist/assets/{styles-Bo7bYxUt.js → styles-BlayaJti.js} +6 -6
- package/dist/assets/{swimlanes-N4OXWK64-BaSkTx2s.js → swimlanes-N4OXWK64-CmzC3Mu0.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-Coei7rJr.js +8 -0
- package/dist/assets/{team-share-BgI5VFVf.js → team-share-C3w1L3WL.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-Np9aXu8d.js → timeline-definition-YOQAKGHF-9aPCRsK2.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-CaHpESyo.js → usecaseDiagram-VIAY4XPW--ngAouwr.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-BpnM9QrV.js → vennDiagram-BLWOH2XV-C3zKxuAB.js} +1 -1
- package/dist/assets/{vi-B8BbvT0G.js → vi-uLErku_e.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-Cb0psm8G.js → wardleyDiagram-YMQ3BMBF-CZWsQPSF.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-Bi_SjN1M.js → xychartDiagram-TAQBALBS-BTcsDP6v.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/rail.html +4 -4
- package/dist-server/package.json +1 -1
- package/package.json +1 -1
- package/dist/assets/CloudAddDialog-DP5-ha1H.js +0 -1
- package/dist/assets/ComputerPanel-DI10c-7Z.js +0 -2
- package/dist/assets/LocalVmWorkspace-Bwq-s97O.js +0 -1
- package/dist/assets/MarkdownFilePreview-B69UWgiO.js +0 -1
- package/dist/assets/PhoneAppDialog-V46SXKel.js +0 -1
- package/dist/assets/SettingsModal-C359HBUM.js +0 -11
- package/dist/assets/TeamMapPage-od4f3NJr.js +0 -1
- package/dist/assets/WorksOnGrid-DbfBPgPv.js +0 -1
- package/dist/assets/channel-BIffrG1w.js +0 -1
- package/dist/assets/index-Bhz3ZrDI.js +0 -2
- package/dist/assets/module-DCUsy2BQ.js +0 -3
- package/dist/assets/swimlanesDiagram-K3J5GTZL-D67LlSLv.js +0 -8
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as st,j as e,t,r as l,a as O,S as jt,f as ve,p as Se,g as Ds,a9 as il,X as We,aT as gn,i as Us,C as rl,aa as Ja,L as Dt,aK as ll,aU as ol,a1 as cl,B as dl,b as Ve,aV as ul,aW as pl,aX as fn,ap as bn,aY as ml,aq as xl,aZ as hl,a_ as gl,a4 as fl,G as bl,a$ as yl,b0 as _s,b1 as vl,b2 as kl,b3 as yn,b4 as $s,l as jl,b5 as Nl,m as vn,b6 as Ya,d as wl,b7 as Sl,q as Cl,b8 as El,o as Al,at as Pl,b9 as kn,as as Il,ba as Rl,bb as jn,bc as Nn,bd as wn,be as Tl,bf as Bl,ad as Ll,bg as Ol,bh as zl}from"./styles-BlayaJti.js";import{bO as Gt,u as G,S as be,n as F,D as ye,cL as Ml,cH as Xa,T as Le,gX as He,eJ as dt,gY as Fl,$ as Ge,eH as Dl,eI as Ul,gZ as ws,g_ as ft,g$ as Qa,h0 as Ks,h1 as Hs,h2 as _l,d$ as Sn,h3 as Za,h4 as ei,h5 as $l,h6 as Kl,h7 as Hl,bM as ge,bZ as X,e7 as Ss,eG as Wl,h8 as ti,h9 as zt,ha as Vt,hb as si,hc as ni,hd as $e,he as tt,hf as Gl,hg as Vl,hh as ql,hi as Jl,hj as Yl,C as ut,hk as ai,hl as Xl,hm as Ql,hn as ii,ho as ri,hp as Ce,hq as Ee,dn as Cn,hr as qt,hs as Zl,ht as eo,hu as to,hv as so,hw as no,gQ as li,bs as ao,hx as gt,U as io,dG as ro,dj as lo,hy as ct,bG as oi,ez as oo,K as Ws,hz as ci,hA as co,aP as Ut,fs as yt,ft as vt,hB as uo,P as Gs,r as po,cj as mo,gF as xo,hC as Jt,hD as di,hE as ho,hF as go,hG as En,hH as ui,hI as Yt,hJ as pi,hK as fo,hL as bo,hM as yo,hN as vo,G as ko,hO as jo,hP as kt,ee as Xt,hQ as No,hR as wo,hS as So,hT as Co,fA as Eo,hU as An,hV as Ao,hW as Po,hX as Pn,hY as Io,ec as mi,hZ as Ro,h_ as To,h$ as Bo,i0 as Lo,i1 as Oo,i2 as zo,i3 as xi,i4 as Mo,i5 as Fo,i6 as Do,i7 as Uo,i8 as _o,i9 as $o,ia as hi,ib as Ko,ic as Ho,dM as Wo,id as Go,e8 as Vo,ie as qo,ig as Jo,ih as Yo,c as Xo,ii as In,ij as Qo,ik as Rn,l as Zo,il as ec,im as tc,io as sc,ip as nc,iq as ac,ir as ic,is as rc,it as gi,fq as mt,iu as lc,fp as oc,iv as cc,iw as dc,ix as uc,iy as pc,iz as mc,iA as xc,iB as hc,iC as gc,iD as Vs,iE as fc,fg as fi,m as bc,iF as yc,iG as vc,iH as Tn,iI as kc,iJ as jc,iK as Bn,iL as Nc,bi as wc,iM as Sc,iN as Cc,iO as Ec,iP as Ac,iQ as Pc,iR as Ln,iS as Ic,bx as bi,iT as Rc,by as Tc,iU as Bc,iV as Lc,iW as Oc,iX as zc,iY as Mc,iZ as Fc,i_ as Dc,i$ as Uc,j0 as On,gt as _c,j1 as $c,j2 as Kc,j3 as yi,j4 as Hc,j5 as Wc,j6 as Gc,j7 as vi,j8 as ki,j9 as ji,ja as Vc,jb as qc,jc as Jc,d4 as Yc,I as Xc,jd as Qc,eB as Zc,bX as zn,je as Mn,e_ as Fn,d_ as ed,a1 as td,aB as sd,jf as nd,jg as ad,jh as id}from"./App-8heymKKb.js";import{L as q,P as Oe,z as Nt,E as Ni,M as rd,ak as ld,a0 as od,X as cd,x as Qt,C as qs,al as dd,K as wi,Y as Si,U as Js,B as Zt,am as ud,an as pd,ao as md,d as Ci,r as xd,A as hd,c as gd,ap as fd,aq as bd,N as yd,ac as vd,ar as kd,b as jd,y as Nd,V as wd,O as is}from"./PlacesRail-v1XIqiBG.js";import{C as Ys,a as Sd,R as De}from"./MenuMotion-IQitGKH4.js";import{l as Ei,M as Cd,w as Ed}from"./MacLocalControl-CpVqwJts.js";import{Q as es}from"./index-BXLNny-w.js";import{r as Ai,a as Pi,b as Ii,i as Ad,C as Pd,c as Id,p as Rd}from"./index-BBsdMDZV.js";import{Q as Td,T as Bd,U as Ld,W as Od,X as zd}from"./VisibilitySection-CCwpvTlJ.js";import{c as Md,A as Fd,w as Dd,d as Ud,e as Dn}from"./activity-bd7MWK8m.js";import{U as Ri,R as Ti,B as Bi,S as Li,a as Oi,D as zi,T as Mi,C as Fi,L as Cs,b as Di,F as Ui,A as Es,E as _d,c as $d,P as Kd,d as Hd,e as Wd,N as Gd}from"./NewBotDialog-CZbVbamH.js";import{a as Vd,u as qd,C as _i,b as Jd,P as Yd}from"./ProIntroduction-qFeFSzyk.js";import{M as $i}from"./monitor-DFEzCfQk.js";import{C as Xd}from"./coins-DpzGN3sd.js";import"./org-library-BW4CqVd6.js";import"./package-format-BOH5_nvi.js";import"./mcp-servers-DGQioE-C.js";import"./WorksOnGrid-CenOXsZe.js";import"./new-bot-7IqfI7S4.js";import"./RoutinesPage-aANJQ--g.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-C3w1L3WL.js";import"./BrowserProfilesManager-BEUgS3Me.js";import"./SignedInSites-CfhTex9p.js";const Qd=[["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"}]],Zd=st("cloud-download",Qd);const eu=[["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"}]],tu=st("palette",eu);const su=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],nu=st("qr-code",su);const au=[["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"}]],iu=st("scroll-text",au);const ru=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],lu=st("terminal",ru);const ou=[["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"}]],cu=st("unplug",ou);const du=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],uu=st("wifi",du);function Xs(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}function Ae({children:s,note:n="settings.adminOnly.change"}){return Gt()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Qs(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 pu(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 mu(){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),F("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!o}})}).then(u=>n({type:"configStatus",config:u})).catch(u=>c(u.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(be,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}function rs(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const et=O(He,"font-sans"),xu=[5,10,20,30,60],ls="ui-icon-button shrink-0 hover:text-ink",os={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},As={count:64,length:200},hu=s=>s.length<=As.count&&s.every(n=>n.length<=As.length),Ps=(s,n)=>F(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function Ki({server:s,disabled:n,onPick:a}){return e.jsxs(ye,{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([...xu,...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 gu(){const{state:s,dispatch:n,refreshInstances:a}=G(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(p=>p.instanceId==="openaiCompat"&&p.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const u=p=>{i||(r(!0),o(null),Ps(d.instanceId,{replyWaitMinutes:p}).then(async({instances:m})=>{Array.isArray(m)?n({type:"instances",instances:m}):await a({reportErrors:!0})}).catch(m=>o(m.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(Ki,{server:d,disabled:i,onPick:u}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.replyWaitHint")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:c})]})}function fu(){const{state:s}=G();return e.jsx(bu,{servers:Xs(s.instances)})}function bu({servers:s}){const{dispatch:n,refreshInstances:a}=G(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,u]=l.useState(""),[p,m]=l.useState(""),[x,h]=l.useState(null),[f,b]=l.useState(null),[y,g]=l.useState(null),[v,C]=l.useState(""),w=!!(i.trim()&&c.trim()&&d.trim()),N=(j,L,k,P)=>{x||(h(j),b(null),L().then(async({instances:S})=>{Array.isArray(S)?n({type:"instances",instances:S}):await a({reportErrors:!0}),k?.()}).catch(S=>b({text:S.message||t("apiInstances.failed"),at:P})).finally(()=>h(null)))},I=()=>w&&N("add",()=>F("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...rs(p).length?{models:rs(p)}:{}})}).then(j=>(dt("custom_endpoint","settings","unverified"),j),j=>{throw dt("custom_endpoint","settings","error"),j}),()=>{r(""),o(""),u(""),m("")});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(j=>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:j.displayName}),j.url&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:j.url})]}),e.jsx(Ki,{server:j,disabled:x!==null,onPick:L=>N("other",()=>Ps(j.instanceId,{replyWaitMinutes:L}))}),e.jsx("button",{type:"button",onClick:()=>{C((j.managedModels??[]).join(", ")),g(y===j.instanceId?null:j.instanceId),b(null)},disabled:x!==null,"aria-label":t("apiInstances.editModels",{name:j.displayName}),"aria-expanded":y===j.instanceId,title:t("apiInstances.editModels",{name:j.displayName}),className:ls,children:e.jsx(Ml,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>N("other",()=>F(`/api/instances/${encodeURIComponent(j.instanceId)}/refresh-models`,{method:"POST"})),disabled:x!==null,"aria-label":t("apiInstances.refreshModels",{name:j.displayName}),title:t("apiInstances.refreshModels",{name:j.displayName}),className:ls,children:e.jsx(Xa,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>N("other",()=>F(`/api/instances/${encodeURIComponent(j.instanceId)}`,{method:"DELETE"})),disabled:x!==null,"aria-label":t("apiInstances.remove",{name:j.displayName}),title:t("apiInstances.remove",{name:j.displayName}),className:`${ls} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Le,{size:13,"aria-hidden":"true"})})]}),y===j.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsx("input",{value:v,onChange:L=>C(L.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:j.displayName}),spellCheck:!1,disabled:x!==null,className:O(et,"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 L=rs(v);if(!hu(L)){b({text:t("apiInstances.modelsLimit",As),at:j.instanceId});return}N("other",()=>Ps(j.instanceId,{models:L}),()=>g(null),j.instanceId)},disabled:x!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>g(null),disabled:x!==null,className:"ui-button",children:t("common.cancel")})]}),f?.at===j.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:f.text})]})]},j.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(os.name),o(os.url)},disabled:x!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===os.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:j=>r(j.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:x!==null,className:et}),e.jsx("input",{type:"url",value:c,onChange:j=>o(j.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:x!==null,className:O(et,"font-mono")}),e.jsx("input",{type:"password",value:d,onChange:j=>u(j.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:x!==null,className:O(et,"font-mono")}),e.jsx("input",{value:p,onChange:j=>m(j.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:x!==null,className:O(et,"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(q,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Oe,{size:12,"aria-hidden":"true"}),x==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),f&&!f.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:f.text})]})}const yu="lm-studio";function vu(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 ku({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=G(),r=Xs(n.instances),[c,o]=l.useState("1234"),[d,u]=l.useState(""),[p,m]=l.useState(!1),[x,h]=l.useState(null),f=vu(c),b=!!(f&&r.some(g=>g.url===f)),y=()=>{p||!f||b||(m(!0),h(null),F("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:f,key:d.trim()||yu,catalog:"lmstudio"})}).then(async g=>{dt("custom_endpoint","settings","unverified"),Array.isArray(g.instances)?a({type:"instances",instances:g.instances}):await i({reportErrors:!0}),u("")},g=>{dt("custom_endpoint","settings","error"),h(g instanceof Error&&g.message?g.message:t("apiInstances.failed"))}).finally(()=>m(!1)))};return e.jsxs("div",{className:O(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:O("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:g=>o(g.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:p,className:O(et,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:g=>u(g.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:p,className:O(et,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),f&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:f}),e.jsxs("button",{type:"button",onClick:y,disabled:p||!f||b,className:"ui-button self-start",children:[p?e.jsx(q,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Oe,{size:12,"aria-hidden":"true"}),p?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 ju="ollama",Nu="https://ollama.com/download",wu=s=>`${s.replace(/\/+$/,"")}/v1`,Su=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Cu({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=G(),[r,c]=l.useState(""),[o,d]=l.useState(null),[u,p]=l.useState(!1),[m,x]=l.useState(!1),[h,f]=l.useState(null),b=l.useRef(0),y=l.useRef(!1),g=l.useCallback(I=>{const j=++b.current;p(!0),f(null),F(`/api/instances/ollama${I?`?url=${encodeURIComponent(I)}`:""}`).then(L=>{j===b.current&&d(L.status)}).catch(L=>{j===b.current&&(d(null),f(L.message||t("apiInstances.failed")))}).finally(()=>{j===b.current&&p(!1)})},[]);l.useEffect(()=>{!s||y.current||(y.current=!0,g(""))},[s,g]);const v=o?wu(o.url):null,C=!!(v&&(Xs(n.instances).some(I=>I.url===v)||Su(n.config?.openaiCompat?.url,v))),w=!!(v&&!C&&!m&&!u&&(o?.state==="ready"||o?.state==="no-models")),N=()=>{!w||!v||(x(!0),f(null),F("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:v,key:ju,catalog:"ollama"})}).then(async I=>{dt("custom_endpoint","settings","unverified"),Array.isArray(I.instances)?a({type:"instances",instances:I.instances}):await i({reportErrors:!0})},I=>{dt("custom_endpoint","settings","error"),f(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:u?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(q,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(Fl,{status:o})}),!u&&o?.state==="not-running"&&e.jsx("a",{href:Nu,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"&&g(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:m,className:O(He,"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:N,disabled:!w,className:"ui-button",children:[m?e.jsx(q,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Oe,{size:12,"aria-hidden":"true"}),m?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>g(r.trim()),disabled:u||m,className:"ui-button",children:[e.jsx(Xa,{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,u]=l.useState(!1),[p,m]=l.useState(null),[x,h]=l.useState(null),f=d||p!==null,b=(v,C)=>F("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[v]:C}}})}).then(w=>n({type:"configStatus",config:w})),y=()=>{const v=i.trim().toUpperCase(),C=Dl(c);if(!(f||!v||!C)){if(!Ul(C)){h(t("keys.notAKey"));return}u(!0),h(null),b(v,C).then(()=>{r(""),o("")}).catch(w=>h(w.message)).finally(()=>u(!1))}},g=v=>{f||(m(v),h(null),b(v,"").catch(C=>h(C.message)).finally(()=>m(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((v,C)=>C===0?[v]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},C),v])}),a.map(v=>e.jsxs("div",{"data-opencode-provider-key":v,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:O(He,"block flex-1 truncate text-ink"),children:v}),e.jsx("button",{type:"button",onClick:()=>g(v),disabled:f,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:v}),className:"ui-button shrink-0",children:p===v?e.jsx(q,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},v)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:v=>{h(null),r(v.target.value)},onKeyDown:v=>v.key==="Enter"&&y(),disabled:f,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:O(He,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:v=>{h(null),o(v.target.value)},onKeyDown:v=>v.key==="Enter"&&y(),disabled:f,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:O(He,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:y,disabled:f||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(q,{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 Au(){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),F("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!o}})}).then(u=>n({type:"configStatus",config:u})).catch(u=>c(u.message)).finally(()=>i(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.anthropic.everyBot")}),e.jsx("div",{className:"text-[12px] leading-4 text-ink-secondary",children:o?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(be,{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(Ge,{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 Pu(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=!!s.config?.vps?.configured,p=!a.trim()&&u;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const m=()=>{r||!a.trim()&&!u||(c(!0),d(null),F("/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/milind-soni/OpenMausBot/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"&&m(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:O(He,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:m,disabled:r||!a.trim()&&!u||a.trim()===(s.config?.vps?.sshAlias??""),className:O("ui-button shrink-0",!p&&"ui-button-primary"),title:p?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(q,{size:13,className:"animate-spin","aria-hidden":"true"}):p?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function Iu(){const{state:s,dispatch:n}=G(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,u]=l.useState(null),p=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const m=i.trim()!==a,x=()=>{p.current||!m||(p.current=!0,o(!0),u(null),F("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(h=>n({type:"configStatus",config:h})).catch(h=>u(h.message)).finally(()=>{p.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:O(He,"pr-8")}),c&&e.jsx(q,{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 Ru="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",Tu=1600,Bu={opencodeProviders:()=>e.jsx(Eu,{}),ollama:s=>e.jsx(Cu,{visible:s}),lmStudio:()=>e.jsx(ku,{heading:!1}),vps:()=>e.jsx(Pu,{})},Lu={anthropic:()=>e.jsx(Au,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(Iu,{}),e.jsx(gu,{}),e.jsx(fu,{})]}),box:()=>e.jsx(Hl,{}),liveKey:()=>e.jsx(Kl,{})};function Hi(s,n){if(s.kind==="uses")return!1;const a=Hs(s,n);return a.configured||a.included===!0}function Ou({entry:s,visible:n}){const{state:a}=G(),i=l.useId(),c=Hs(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:Za,children:[e.jsx(ei,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:Bu[s.id]?.(n)})]})}function zu({entry:s}){const{state:n,dispatch:a}=G(),i=l.useId(),r=s.opens,c=Hs(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:Za,children:[e.jsx(ei,{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($l,{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 Mu({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(Sn,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(Ou,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(zu,{entry:s}):e.jsx(Sn,{id:s.id,children:Lu[s.id]?.()})}function Fu({id:s,rows:n,open:a,onToggle:i}){const{state:r}=G(),c=ws.find(p=>p.id===s),o=l.useId(),d=l.useId(),u=n.filter(p=>Hi(p,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:Ru,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)})]}),u>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:u})}),e.jsx(Ys,{size:14,"aria-hidden":"true",className:O("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none",a&&"rotate-90")})]}),e.jsxs("div",{id:d,hidden:!a,className:"flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)",children:[n.map(p=>e.jsx(Mu,{entry:p,visible:a},p.id)),s==="voice"&&e.jsx(mu,{})]})]})}function Du(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=pu(i);return r&&Qs(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"),Tu)),!0}function Uu(){const{state:s}=G(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(ws.filter(x=>x.id==="ai"||ft.some(h=>h.section===x.id&&Hi(h,s.config))).map(x=>x.id))),c=l.useRef(null),o=Qa(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const x=ft.find(y=>y.id===o.row)?.section??"ai";a(""),r(y=>y.has(x)?y:new Set([...y,x]));let h=0,f=0;const b=()=>{Du(c.current,o,x)||++f>60?_l(o):h=window.requestAnimationFrame(b)};return h=window.requestAnimationFrame(b),()=>window.cancelAnimationFrame(h)},[o]);const u=s.config?.live?.provider==="azure",p=ft.filter(x=>Ks(x,d)&&!(u&&x.id==="liveCalls")),m=ws.flatMap(x=>{const h=p.filter(f=>f.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(jt,{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"})]}),m.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()})}):m.map(({id:x,rows:h})=>e.jsx(Fu,{id:x,rows:h,open:d!==""||i.has(x),onToggle:()=>r(f=>{const b=new Set(f);return b.has(x)?b.delete(x):b.add(x),b})},x))]})}function Wi({simple:s=!1}){return null}function Gi({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 p=!0;return n?.state().then(m=>{p&&i(m)}).catch(()=>{}),()=>{p=!1}},[n]),!n||!a?.available)return null;const u=p=>{c(!0),d(!1),n.set(p).then(i,()=>d(!0)).finally(()=>c(!1))};return e.jsx(ge,{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(be,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>u(!a.on)})})}function _u(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 Vi(){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??"",u=x=>{r(!0),o(!1),s.set(x).then(a,()=>o(!0)).finally(()=>r(!1))},p=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,m=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(ye,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:x=>u({key:x.target.value}),children:n.keys.map(x=>e.jsx("option",{value:x.id,children:x.label},x.id))}),p&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:p})]});return e.jsx(ge,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||p?m:null,children:e.jsx(be,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>u({enabled:!n.enabled})})})}const cs=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function qi(){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 p=!0;return F("/api/attachment-storage").then(m=>{p&&n(m)}).catch(()=>{}),()=>{p=!1}},[]),!s)return null;const u=async()=>{c(!0),d(null);try{const p=await F("/api/attachment-storage",{method:"POST"});n(p);const m=t("settings.attachments.cleared",{count:p.removed,freed:cs(p.freedBytes)});d(p.failed>0?{kind:"error",message:`${m} ${t("settings.attachments.failed",{count:p.failed})}`}:{kind:"success",message:m})}catch(p){d({kind:"error",message:p instanceof Error?p.message:String(p)})}finally{c(!1),i(!1)}};return e.jsx(ge,{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:cs(s.usedBytes),max:cs(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:O(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:()=>{u()},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 Ji({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 m=await window.ogb.exportDiagnostics();m&&r({kind:"success",message:t("settings.diagnostics.saved",{path:m})})}catch(m){r({kind:"error",message:m instanceof Error?m.message:String(m)})}finally{a(!1)}}},u=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const m=await window.ogb.openLogsFolder();o(m.folder),m.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:m.folder})})}catch(m){r({kind:"error",message:m instanceof Error?m.message:String(m)})}}},p=!!window.ogb?.exportDiagnostics;return e.jsx(ge,{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:O("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(p?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:p&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[window.ogb?.openLogsFolder&&e.jsx("button",{type:"button",onClick:()=>{u()},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 $u="https://dash.cloudflare.com/profile/api-tokens",Ku=/^[0-9a-f]{32}$/i,Un="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 Hu({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),[u,p]=l.useState(""),[m,x]=l.useState(!1),[h,f]=l.useState(!1),[b,y]=l.useState(null),[g,v]=l.useState(null),C=(o??c).trim(),w=u.trim(),N=!w&&r&&o===null,I=o!==null&&C!==c,j=P=>a({type:"configStatus",config:P}),L=async()=>{if(!(m||!w&&!r&&!I)){if(w&&!Ku.test(C))return y(t("decider.workersAi.needsAccount"));x(!0),y(null),v(null);try{(I||w&&!c)&&j(await F("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:C}})})),(w||N)&&j(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",w):await F("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:w}})})),p(""),d(null)}catch(P){y(P instanceof Error?P.message:String(P))}finally{x(!1)}}},k=async()=>{if(!(h||m||!w&&!r)){f(!0),v(null),y(null);try{const P=await F("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...w?{key:w,accountId:C}:{}})}),S=P.extraction?[t(P.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];v(P.ok?{ok:P.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(P.latencyMs)}),...S].join(" ")}:{ok:!1,text:s(P)})}catch(P){v({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{f(!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:P=>{v(null),y(null),d(P.target.value)},disabled:m,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:Un}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:u,onChange:P=>{v(null),y(null),p(P.target.value)},onKeyDown:P=>P.key==="Enter"&&void L(),disabled:m,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:Un}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{L()},disabled:m||!w&&!r&&!I,title:N?t("keys.removeKey"):t("common.save"),className:O("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",N?"text-danger":"text-ink"),children:m?e.jsx(q,{size:13,className:"animate-spin"}):N?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{k()},disabled:h||m||!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}),g&&e.jsx("p",{role:"status",className:O("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("a",{href:$u,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(Nt,{size:11,"aria-hidden":"true"})]})]})}const Wu={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},Gu=1500,Zs={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"},_n={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},Vu={...Zs,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"},qu={...Zs,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"},ds={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(ds[n.provider]??ds.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(ds[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function $n(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=qu[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&&_n[s.reason])return t(_n[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=Zs[s.reason];return i?t(i):t("decider.error.other")}const Yu=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Xu(){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",u=r&&a?.sharedKey===!0,p=c&&!o&&!d,m=a?.enabled??!1,x=a?.jobs.roomRouting??!0,[h,f]=l.useState(""),[b,y]=l.useState(!1),[g,v]=l.useState(!1),[C,w]=l.useState(!1),[N,I]=l.useState(null),[j,L]=l.useState(null),[k,P]=l.useState(null),S=h.trim(),M=!S&&p,se=!r||o?null:d?"decider.openrouter.status.sharedHint":c?u?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",ne=T=>n({type:"configStatus",config:T}),V=async T=>{if(!g){v(!0),I(null);try{ne(await F("/api/config",{method:"PUT",body:JSON.stringify({decider:T})}))}catch(R){I(R instanceof Error?R.message:String(R))}finally{v(!1)}}};l.useEffect(()=>{if(!r||k)return;let T=!1;return F("/api/decider/models").then(R=>{T||P(R)},()=>{}),()=>{T=!0}},[r,k]);const ie=T=>{f(""),L(null),V(T)},re=async()=>{if(!(b||!S&&!p)){y(!0),I(null),L(null);try{const T=window.ogb?.setCredential?await window.ogb.setCredential(r?"openrouterDeciderKey":"jevApiKey",S):await F("/api/config",{method:"PUT",body:JSON.stringify({decider:{[r?"openrouterKey":"key"]:S}})});ne(T),f("")}catch(T){I(T instanceof Error?T.message:String(T))}finally{y(!1)}}},oe=async()=>{if(C||b||!S&&!c)return;w(!0),L(null),I(null);const T=!S&&o,R=!S&&d;try{const E=await F("/api/decider/test",{method:"POST",body:JSON.stringify(S?{key:S}:{})});L(E.ok?{ok:!0,text:r?[t(R?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(E.latencyMs)}),...E.latencyMs>Gu?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(E.latencyMs)})}:{ok:!1,text:$n(E,T,i)})}catch(E){L({ok:!1,text:E instanceof Error?E.message:String(E)})}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(Hu,{failureText:T=>$n(T,!1,"workersai")}),e.jsx(ge,{title:t("decider.provider.label"),children:e.jsxs(ye,{className:"w-48","data-testid":"decider-provider",value:i,onChange:T=>ie({provider:T.target.value==="openrouter"?"openrouter":"jev"}),disabled:g||!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(ge,{title:t("decider.model.label"),subtitle:k?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(ye,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:T=>ie({openrouterModel:T.target.value,openrouterApi:k?.models.find(R=>R.id===T.target.value)?.api??"chat"}),disabled:g,"aria-label":t("decider.model.label"),children:[a?.model&&!k?.models.some(T=>T.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(T=>{const R=k?.models.filter(E=>E.group===T)??[];return R.length>0&&e.jsx("optgroup",{label:t(T==="recommended"?"decider.model.recommended":"decider.model.more"),children:R.map(E=>e.jsx("option",{value:E.id,children:E.name},E.id))},T)})]})}),e.jsx(ge,{title:t(r?"decider.openrouter.master":"decider.master"),subtitle:c?void 0:t(r?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(be,{"data-testid":"decider-master","aria-label":t(r?"decider.openrouter.master":"decider.master"),checked:m,disabled:!c||g||!s.config,onClick:()=>{V({enabled:!m})},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:O("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(u?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected")})]}),se&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(se),!p&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(Ss("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=>{L(null),I(null),f(T.target.value)},onKeyDown:T=>T.key==="Enter"&&void re(),disabled:b,placeholder:p?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:()=>{re()},disabled:b||!S&&!p,title:M?t("keys.removeKey"):t("common.save"),className:O("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",M?"text-danger":"text-ink"),children:b?e.jsx(q,{size:13,className:"animate-spin"}):M?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{oe()},disabled:C||b||!S&&!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")})]}),N&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:N}),j&&e.jsx("p",{role:"status",className:O("mt-1 text-[12px]",j.ok?"text-success":"text-danger"),children:j.text}),!d&&e.jsxs("a",{href:Wu[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(Nt,{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(be,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:m&&x,disabled:!m||g,onClick:()=>{V({jobs:{roomRouting:!x}})},className:"cursor-pointer"})]}),Yu.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 Qu=["openai","xai","gemini","openrouter","custom"],Zu=4,Yi={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},ep={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 tp(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 _t={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},sp={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"}},np={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},Kn={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},Is="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",Hn="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",us="\0other";function ap(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 ip(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 rp(){const{state:s,dispatch:n}=G(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??Yi.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,u]=l.useState(null),[p,m]=l.useState(null),x=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!x||p)return;let y=!1;return F("/api/images/openrouter-models").then(g=>{y||m(Array.isArray(g?.models)?g:{source:"builtin",models:[]})},()=>{y||m({source:"builtin",models:[]})}),()=>{y=!0}},[x,p]);const h=async y=>{o(!0),u(null);try{const g=await F("/api/config",{method:"PUT",body:JSON.stringify(y)});n({type:"configStatus",config:g})}catch(g){u(g instanceof Error?g.message:String(g))}finally{o(!1)}},f=(y,g)=>{if(y==="fallback"&&g==="")return void h({imageGen:{fallback:null}});const v=g,C=y==="primary"&&r?.provider===v;h({imageGen:{[y]:{provider:v},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((y,g,v)=>v.indexOf(y)===g);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:O("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:_t[i.provider]}):t("imageGen.status.backupOnly",{provider:_t[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(Wn,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:p,disabled:c||!s.config,onProvider:f,onModel:y=>{h({imageGen:{primary:{provider:i.provider,model:y}}})}}),e.jsx(Wn,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:p,disabled:c||!s.config,onProvider:f,onModel:y=>r&&void h({imageGen:{fallback:{provider:r.provider,model:y}}})}),e.jsx(ge,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(ye,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??Zu),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,g)=>g+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(op,{provider:y,status:a},y))]})}function Wn({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:u}){const p=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(ge,{title:p,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(ye,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:m=>d(s,m.target.value),disabled:o,"aria-label":p,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),Qu.filter(m=>m!==r).map(m=>e.jsx("option",{value:m,children:_t[m]},m))]})}),n&&e.jsx(lp,{slot:s,slotLabel:p,provider:n,model:a,openrouterModels:c,disabled:o,onModel:u})]})}function lp({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,u]=l.useState(null),m=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??ep[a].map(b=>({...b,group:"recommended"})),x=d!==null||m.length===0,h=()=>{d!==null&&(u(null),d.trim()&&d.trim()!==i&&o(d.trim()))},f=b=>{if(b===us)return u(i);u(null),o(b)};return e.jsx(ge,{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:[m.length>0&&e.jsxs(ye,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:x?us:i,onChange:b=>f(b.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[i&&!m.some(b=>b.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(b=>{const y=m.filter(g=>g.group===b);return y.length>0&&e.jsx("optgroup",{label:t(b==="recommended"?"decider.model.recommended":"decider.model.more"),children:y.map(g=>e.jsx("option",{value:g.id,children:g.name},g.id))},b)}),e.jsx("option",{value:us,children:t("imageGen.model.other")})]}),x&&e.jsx("input",{value:d??i,onChange:b=>u(b.target.value),onBlur:h,onKeyDown:b=>b.key==="Enter"&&h(),disabled:c,placeholder:Yi[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:O(Is,"w-64 max-w-full")})]})})}function op({provider:s,status:n}){const{dispatch:a}=G(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,u]=l.useState(!1),[p,m]=l.useState(null),[x,h]=l.useState(!1),[f,b]=l.useState(null),y=s==="openrouter"?[n?.primary,n?.fallback].filter(S=>S?.provider===s).map(S=>S?.model).join(" "):"",g=f?.models===y?f:null,v=S=>b(S&&{...S,models:y}),C=ip(n,s),w=s==="openai"||s==="gemini"||s==="custom"?sp[s]:null,N=s==="xai"||s==="openrouter"?np[s]:null,I=c??n?.customUrl??"",j=async S=>{u(!0),m(null),v(null);try{a({type:"configStatus",config:await S()}),r(""),o(null)}catch(M){m(M instanceof Error?M.message:String(M))}finally{u(!1)}},L=S=>j(async()=>s==="xai"||s==="openrouter"?Wl(s,S,!1):window.ogb?.setCredential&&w?window.ogb.setCredential(w.credential,S):F("/api/config",{method:"PUT",body:JSON.stringify(w.patch(S))})),k=()=>j(async()=>{const S=I.trim()?tp(I.trim()):"";return F("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:S}})})}),P=async()=>{h(!0),v(null);try{v(ap(s,await F("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(S){v({ok:!1,text:S instanceof Error?S.message:String(S)})}finally{h(!1)}};return e.jsxs(X,{title:_t[s],children:[e.jsx(cp,{configured:C,optional:s==="custom"}),N&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(N.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:S=>o(S.target.value),onKeyDown:S=>S.key==="Enter"&&void k(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:Is}),e.jsxs("button",{type:"button",onClick:()=>{k()},disabled:d||c===null,className:Hn,children:[d?e.jsx(q,{size:13,className:"animate-spin"}):e.jsx(ve,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:S=>r(S.target.value),onKeyDown:S=>S.key==="Enter"&&i.trim()&&void L(i.trim()),disabled:d,placeholder:C?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((w??N).label),autoComplete:"off",spellCheck:!1,className:Is}),e.jsxs("button",{type:"button",onClick:()=>{L(i.trim())},disabled:d||!i.trim(),className:Hn,children:[d?e.jsx(q,{size:13,className:"animate-spin"}):e.jsx(ve,{size:13}),t("common.save")]}),C&&e.jsx("button",{type:"button",onClick:()=>{P()},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")})]}),g&&e.jsx("p",{role:"status",className:O("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[Kn[s]?e.jsx("a",{href:Kn[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:Se()})}),C&&e.jsx("button",{type:"button",onClick:()=>{L("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),p&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:p})]})}function cp({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:O("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 ps(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")&&ti(s.driverKind)==="codex"?"chatgpt":null}function en(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const tn={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function dp(s,n){return{signOut:en(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 Xi(s){return s.some($e)}function up(s,n){const a=n.filter(o=>en(o)==="signedIn"),i=Xi(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??Yl(n[0]);return{title:t(tn[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 pp({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=G(),[o,d]=l.useState(!1),[u,p]=l.useState(null),[m,x]=l.useState(!1),[h,f]=l.useState(null),b=l.useRef(null),{signOut:y,remove:g}=dp(s,n),v=i.bots.filter(N=>N.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const N=j=>{j.key==="Escape"&&(j.stopPropagation(),d(!1))},I=j=>{j.target instanceof Node&&!b.current?.contains(j.target)&&d(!1)};return window.addEventListener("keydown",N,!0),window.addEventListener("pointerdown",I),()=>{window.removeEventListener("keydown",N,!0),window.removeEventListener("pointerdown",I)}},[o]);const C=async N=>{p(null),x(!0),f(null);try{const I=`/api/instances/${encodeURIComponent(n.instanceId)}${N==="signOut"?"/auth/sign-out":""}`,{instances:j}=await F(I,N==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(j)?r({type:"instances",instances:j}):await c().catch(()=>{})}catch(I){f(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:[g&&e.jsx("button",{type:"button",disabled:m||v>0,onClick:()=>p("remove"),title:v>0?t("accounts.inUse",{count:String(v)}):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(N=>!N),disabled:m,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:tt(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:m?e.jsx(q,{size:14,className:"animate-spin"}):e.jsx(Ni,{size:16})}),o&&e.jsxs("div",{role:"menu",className:O("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]",rd),children:[e.jsx("button",{type:"button",role:"menuitem",className:O(w,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),y&&e.jsx("button",{type:"button",role:"menuitem",className:O(w,"text-ink"),onClick:()=>{d(!1),p("signOut")},children:t("accounts.signOut")}),g&&v>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(v)})})]}),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(ut,{open:u==="signOut",title:t("accounts.signOutTitle",{name:tt(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>p(null),onConfirm:()=>{C("signOut")}}),e.jsx(ut,{open:u==="remove",title:t("accounts.removeTitle",{name:tt(n)}),body:t(tn[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>p(null),onConfirm:()=>{C("remove")}})]})}function mp({instance:s,onDone:n}){const{dispatch:a}=G(),[i,r]=l.useState(tt(s)),[c,o]=l.useState(!1),[d,u]=l.useState(null),p=async()=>{const m=i.trim();if(!m||m===tt(s))return n();o(!0),u(null);try{const{instances:x}=await F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:m})});Array.isArray(x)&&a({type:"instances",instances:x}),n()}catch(x){u(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:m=>{m.preventDefault(),p()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:m=>r(m.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:m=>{m.key==="Escape"&&(m.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(q,{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 xp({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=en(n),u=n.snapshot.account,p=n.snapshot.authenticationUnavailableReason,m=p&&d!=="signedIn"?p:d==="signedIn"?u?.method==="api-key"?t("accounts.apiKey"):[u?.email,u?.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:O("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(ve,{size:13}):e.jsx("span",{className:O("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(mp,{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:tt(n),children:tt(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:m,children:m})]}),d!=="signedIn"&&d!=="unavailable"&&!p&&!a&&e.jsx("button",{type:"button",onClick:i,className:O("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(pp,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Gl,{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(Vl,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(ql,{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(Jl,{instanceId:n.instanceId,welcome:!1})})]})}function Qi({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=G(),[d,u]=l.useState(!1),[p,m]=l.useState(""),[x,h]=l.useState(""),[f,b]=l.useState(!1),[y,g]=l.useState(null),v=async()=>{if(!(f||!p.trim())){b(!0),g(null);try{const C={displayName:p.trim(),...a,...i&&x.trim()?{configDir:x.trim()}:{}},w=await F(n,{method:"POST",body:JSON.stringify(C)});Array.isArray(w.instances)&&o({type:"instances",instances:w.instances}),u(!1),m(""),h(""),typeof w.instanceId=="string"&&c(w.instanceId)}catch(C){g(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(),v()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:p,onChange:C=>m(C.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:f,"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:f,"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:()=>{u(!1),g(null)},disabled:f,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:f||!p.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:[f&&e.jsx(q,{size:13,className:"animate-spin"}),t("accounts.addSubmit")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>u(!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(Oe,{size:14}),s]})}function hp({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(m=>m.snapshot.state==="available"),u=n.find(m=>m.policy)?.policy,p=l.useId();return e.jsxs(zt,{instance:o,summary:up(s,n),bare:i,children:[u&&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:u.organizationName})})," · ",u.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(m=>e.jsx(xp,{group:s,instance:m,signingIn:r===m.instanceId,onSignIn:()=>c(m.instanceId),onSignInDone:()=>c(x=>x===m.instanceId?null:x)},m.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(Qi,{label:t(tn[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?p:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:p,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(Vt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(si,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(ni,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const gp={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},Et=O(He,"font-sans"),fp={name:"",url:"",token:"",model:""},bp=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:""});function Gn({instance:s,engine:n,onDone:a}){const{dispatch:i}=G(),r=gp[n],[c,o]=l.useState(s?bp(s):fp),[d,u]=l.useState(!1),[p,m]=l.useState(null),x=b=>({value:c[b],onChange:y=>o(g=>({...g,[b]:y.target.value})),spellCheck:!1,disabled:d}),h=!!(c.name.trim()&&(c.url.trim()||n==="codex")&&(s||c.token.trim())),f=async()=>{if(d||!h)return;u(!0),m(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 F(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await F(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(y.instances)&&i({type:"instances",instances:y.instances}),a()}catch(y){m(y instanceof Error&&y.message?y.message:t("claudeEndpoints.failed"))}finally{u(!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(),f()},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:Et})]}),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:O(Et,"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:O(Et,"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:O(Et,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),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(q,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function yp({instance:s,onEdit:n}){const{state:a,dispatch:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,p]=l.useState(null),m=a.bots.filter(f=>f.modelSelection.instanceId===s.instanceId||f.fallback?.some(b=>b.instanceId===s.instanceId)||f.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeEndpoint??s.codexEndpoint,h=async()=>{c(!1),d(!0),p(null);try{const f=await F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(f.instances)&&i({type:"instances",instances:f.instances})}catch(f){p(f instanceof Error?f.message:String(f))}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||m>0,onClick:()=>c(!0),title:m>0?t("accounts.inUse",{count:String(m)}):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(q,{size:14,className:"animate-spin"}):e.jsx(Le,{size:14})})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u}),e.jsx(ut,{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 Zi({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(Gn,{engine:s,instance:c,onDone:()=>r(null)})},c.instanceId):e.jsx(yp,{instance:c,onEdit:()=>r(c.instanceId)},c.instanceId))}),i==="new"?e.jsx(Gn,{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(Oe,{size:14}),t("claudeEndpoints.add")]})]})}function ms(){return e.jsx(Zi,{engine:"claude"})}function xs(){return e.jsx(Zi,{engine:"codex"})}const xt=O(He,"font-sans"),vp={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"},Vn=["opusModel","sonnetModel","haikuModel","smallFastModel"],kp={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},jp=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??""}},qn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function Jn({instance:s,onDone:n}){const{dispatch:a}=G(),[i,r]=l.useState(s?jp(s):kp),[c,o]=l.useState(!1),[d,u]=l.useState(null),p=h=>({value:i[h],onChange:f=>r(b=>({...b,[h]:f.target.value})),spellCheck:!1,disabled:c}),m=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),x=async()=>{if(c||!m)return;o(!0),u(null);const h={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(Vn.map(f=>[f,i[f].trim()]))};try{const f=s?await F(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(h)}):await F("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(h)});Array.isArray(f.instances)&&a({type:"instances",instances:f.instances}),n()}catch(f){u(f instanceof Error&&f.message?f.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",{...p("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:xt})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...p("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:O(xt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...p("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:O(xt,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...p("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:O(xt,"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:Vn.map(h=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(qn[h]),e.jsx("input",{...p(h),maxLength:160,placeholder:vp[h],"aria-label":t(qn[h]),className:O(xt,"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||!m,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(q,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Np({instance:s,onEdit:n}){const{state:a,dispatch:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,p]=l.useState(null),m=a.bots.filter(f=>f.modelSelection.instanceId===s.instanceId||f.fallback?.some(b=>b.instanceId===s.instanceId)||f.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeBedrock,h=async()=>{c(!1),d(!0),p(null);try{const f=await F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(f.instances)&&i({type:"instances",instances:f.instances})}catch(f){p(f instanceof Error?f.message:String(f))}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(ai,{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||m>0,onClick:()=>c(!0),title:m>0?t("accounts.inUse",{count:String(m)}):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(q,{size:14,className:"animate-spin"}):e.jsx(Le,{size:14})})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u}),e.jsx(ut,{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 hs(){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(Jn,{instance:r,onDone:()=>i(null)})},r.instanceId):e.jsx(Np,{instance:r,onEdit:()=>i(r.instanceId)},r.instanceId))}),a==="new"?e.jsx(Jn,{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(Oe,{size:14}),t("claudeBedrock.add")]})]})}function Yn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function wp({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 m=await F(o);i(m.folders>0?{kind:"found",bytes:m.bytes,complete:m.complete}:{kind:"none"})}catch(m){c(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},u=async()=>{c(null),i({kind:"deleting"});try{const m=await F(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:m.freedBytes,remaining:m.remaining})}catch(m){c(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},p=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(ld,{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"||p)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:p,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:[p&&e.jsx(q,{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:Yn(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:()=>{u()},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:Yn(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 gs=[60,120,180,360,720];function er(){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 u=async m=>{if(!o.current){o.current=!0,i(!0),c("");try{const x=await F("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:m.enabled,windowMinutes:m.windowMinutes}})});n({type:"configStatus",config:x})}catch(x){c(x instanceof Error?x.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},p=gs.includes(d.windowMinutes)?[...gs]:[...gs,d.windowMinutes].sort((m,x)=>m-x);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(be,{id:"cache-keepwarm-enabled",checked:d.enabled,disabled:a,"aria-describedby":"cache-keepwarm-help cache-keepwarm-cost",onClick:()=>{u({...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(ye,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:m=>{u({...d,windowMinutes:Number(m.target.value)})},children:p.map(m=>e.jsx("option",{value:m,children:t("settings.keepWarm.hours",{hours:Number((m/60).toFixed(2))})},m))})]}),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 Sp({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[u,p]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[m,x]=l.useState(!1),[h,f]=l.useState(null),[b,y]=l.useState(!1),[g,v]=l.useState(null),C=l.useRef(!1);l.useEffect(()=>{C.current||(C.current=!0,F(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:k})=>{c(k),s.cli&&(k.includes(s.cli)?d(s.cli):p(s.cli))}).catch(()=>c(k=>k??[])))},[n,s.cli]);const w=u.trim()||o,N=w!==(s.cli??""),I=m||b;l.useEffect(()=>{f(null)},[w]);const j=()=>{if(I||!w||!N)return;y(!0),v(null);const k=w;F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:k})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(P=>v(P.message)).finally(()=>y(!1))},L=()=>{I||!w||!N||(x(!0),v(null),F("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(k=>{f(k),k.ok&&j()}).catch(k=>v(k.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(ye,{className:"w-full font-mono",value:u.trim()?"":o,onChange:k=>{d(k.target.value),p("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(k=>e.jsx("option",{value:k,children:k},k))]}),e.jsx("input",{type:"text",value:u,onChange:k=>p(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),!(!w||!N)&&L())},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(Ge,{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})}),g&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:g}),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:()=>f(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:()=>j(),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(q,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:L,disabled:I||!w||!N,className:O("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(q,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:13}),t("common.save")]})})]})]})}function tr({instance:s}){const{refreshInstances:n}=G(),[a,i]=l.useState(!1),r=Sd(a),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[p,m]=l.useState(null),[x,h]=l.useState(null),f=l.useRef(null);l.useEffect(()=>{f.current!==null&&f.current!==s.cli&&i(!1),f.current=s.cli??null},[s.cli]);const b=()=>{c||d||(o(!0),h(null),F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(v=>h(v.message)).finally(()=>o(!1)))},y=()=>{c||d||(o(!0),h(null),F(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(v=>h(v.message)).finally(()=>o(!1)))},g=()=>{c||d||(u(!0),m(null),h(null),F(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:v})=>{m(v),await Promise.resolve(n()).catch(()=>{})}).catch(v=>h(v.message)).finally(()=>u(!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:g,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(q,{size:12,className:"animate-spin"}):e.jsx(De,{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(v=>!v),disabled:d,"aria-expanded":a,className:O("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")})]}),p&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:p})}),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(Sp,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function Xn({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=G(),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[p,m]=l.useState(null),x=n==="remove",h=x?a.bots.filter(y=>y.modelSelection.instanceId===s.instanceId).length:0,f=t(x?"accounts.remove":"accounts.signOut"),b=async()=>{o(!1),u(!0),m(null);try{const y=`/api/instances/${encodeURIComponent(s.instanceId)}${x?"":"/auth/sign-out"}`,{instances:g}=await F(y,{method:x?"DELETE":"POST"});Array.isArray(g)?i({type:"instances",instances:g}):await r()}catch(y){m(y instanceof Error?y.message:String(y))}finally{u(!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:O("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(q,{size:13,className:"animate-spin"}):f}),h>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})})]}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),e.jsx(ut,{open:c,title:t(x?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(x?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:f,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{b()}})]})}function Cp({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(Qi,{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(Vt,{instance:r,unframed:!0})})]})}function Ep({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(zt,{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":$e(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(zt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!$e(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(zt,{instance:s,bare:n,children:[a,!$e(s)&&e.jsx(Vt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),$e(s)&&e.jsx(eo,{instance:s,className:"mt-3"}),$e(s)&&s.serverKind==="ollama"&&e.jsx(to,{instance:s,className:"mt-3"}),$e(s)&&e.jsx(so,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(si,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(ni,{warning:s.snapshot.warning,className:"mt-3"}),$e(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(ve,{size:13}),t(no[ti(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(ve,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(wp,{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(Cp,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(Xn,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(Xn,{instance:s,action:"remove"})]}),e.jsx(tr,{instance:s})]})}function Ap(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?Zl(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function Pp({rows:s,isReady:n,renderEngine:a,more:i}){const[r,c]=l.useState(null),o=s.filter(u=>n(u)||u.authentication!==void 0),d=s.filter(u=>!o.includes(u));return e.jsxs(e.Fragment,{children:[e.jsx(Ce,{label:t("settings.simple.ai.yours"),actions:e.jsx(ii,{}),children:e.jsx(Ee,{children:o.map(u=>{const p=n(u),m=r===u.instanceId;return e.jsxs("div",{"data-simple-engine":u.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:u,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:u.displayName}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:Ap(u,p)})]})]}),e.jsx("button",{type:"button","aria-expanded":m,className:"ui-button ml-auto shrink-0",onClick:()=>c(m?null:u.instanceId),children:t(m?"common.done":p?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),m&&e.jsx("div",{className:"px-4 pb-3",children:a(u,!0)})]},u.instanceId)})})}),d.length>0&&e.jsx(qt,{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(u=>e.jsx("span",{className:"flex size-[18px] items-center justify-center rounded-full bg-menu",children:e.jsx(Cn,{instance:u,size:14,subtle:!0})},u.instanceId))}),...i,children:e.jsx(ri,{instances:d,isReady:n,renderEngine:u=>a(u)})})]})}function Ip(){const{state:s,refreshInstances:n}=G(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let p=!0;return F("/api/instances/hidden").then(m=>{p&&i(Array.isArray(m?.instances)?m.instances:[])}).catch(()=>{}),()=>{p=!1}},[s.instances]),a.length===0)return null;const u=p=>{c(p),d(null),F(`/api/instances/${encodeURIComponent(p)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(m=>d(m.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(p=>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:p.displayName}),e.jsx("button",{type:"button","data-unhide-engine":p.instanceId,disabled:r!==null,onClick:()=>u(p.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===p.instanceId?t("engines.unhiding"):t("engines.unhide")})]},p.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function sr({simple:s=!1,more:n}){const{state:a}=G();l.useEffect(()=>Xl,[]);const i=a.instances.filter(h=>h.readOnly||h.cli!==void 0||h.cliDefault!==void 0||h.snapshot.state==="unavailable"||Ql(h)||h.claudeEndpoint!==void 0||h.claudeBedrock!==void 0||h.codexEndpoint!==void 0),r=new Map;for(const h of i){const f=ps(h);f&&r.set(f,[...r.get(f)??[],h])}const c=h=>{const f=ps(h);return f&&r.get(f)?.[0]===h?f:null},o=i.filter(h=>!ps(h)||c(h)),d=o.length>0&&o.every(h=>h.readOnly),u=!r.has("chatgpt")&&!d,p=!r.has("claude")&&!d,m=h=>{const f=c(h);return f?Xi(r.get(f)):$e(h)},x=(h,f=!1)=>{const b=c(h);return b?e.jsx(hp,{group:b,accounts:r.get(b),bare:f,advanced:e.jsxs(e.Fragment,{children:[b==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(ms,{}),e.jsx(hs,{})]}):e.jsx(xs,{}),e.jsx(tr,{instance:h})]})}):e.jsx(Ep,{instance:h,bare:f})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(Pp,{rows:o,isReady:m,renderEngine:x,more:n}),p&&e.jsxs("div",{className:"px-4",children:[e.jsx(ms,{}),e.jsx(hs,{})]}),u&&e.jsx("div",{className:"px-4",children:e.jsx(xs,{})})]}):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(ii,{})]}),e.jsx(ri,{instances:o,isReady:m,renderEngine:x}),p&&e.jsxs("div",{className:"px-4",children:[e.jsx(ms,{}),e.jsx(hs,{})]}),u&&e.jsx("div",{className:"px-4",children:e.jsx(xs,{})}),e.jsx(Ip,{}),e.jsx(er,{})]})}const Rp={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function At(s,n){return[Rp[s],{signal:n}]}function sn(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Tp({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:u}){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(li,{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(De,{size:12,className:O(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(Ge,{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(q,{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(Ge,{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(od,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((p,m)=>{const x=$p(p),h=nn(x),f=r===p.name,b=an(p.name);return e.jsxs("div",{className:O("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.vps.orphan",{id:b}):p.ownerName}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",p.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:p.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:i||p.inUse||r!==null,"aria-busy":f||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f?e.jsx(q,{size:12,className:"animate-spin"}):e.jsx(Le,{size:12}),t("vm.vps.remove")]})]},`${p.vpsAlias??""}:${p.name}`)})]})]})}const Bp=[1e3,2e3,4e3];function Lp(s){return new Promise(n=>window.setTimeout(n,s))}const Op={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},zp={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 nn(s){return t(zp[s])}function Mp(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function Fp(s){return nn(Mp(s))}function Dp(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 nr(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 Up(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:nr(Array.isArray(s.instances)?s.instances:[],n,a)}function _p(s){return["idle","ready","running"].includes(s.state)}function $p(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 an(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function Kp(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:sn(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Hp(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:sn(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function Wp(s){const n=an(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:sn(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function fs(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function Gp({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:u}){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(li,{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(De,{size:12,className:O(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(q,{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(Ge,{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(Ds,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((p,m)=>{const x=Dp(p),h=nn(x),f=i?.boxId===p.boxId,b=_p(p),y=x==="removing";return e.jsxs("div",{className:O("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.cloud.orphan"):p.ownerName}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",p.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.jsxs("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:[p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",p.name]}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!b,"aria-busy":f&&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:[f&&i?.action==="sleep"?e.jsx(q,{size:12,className:"animate-spin"}):e.jsx(cd,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:a||p.inUse||i!==null||y,"aria-busy":f&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="delete"?e.jsx(q,{size:12,className:"animate-spin"}):e.jsx(Le,{size:12}),t("common.delete")]})]})]},p.boxId)})})]})}function Vp({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d}){return e.jsxs(X,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null,"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(De,{size:12,className:O(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,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(q,{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(Ge,{size:14,className:"shrink-0 text-warning"})," ",c]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((u,p)=>{const m=Fp(u),x=i===u.botId,h=u.managed===!0;return e.jsxs("div",{className:O("flex items-start justify-between gap-3 px-3 py-3",p>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",h?u.inUse||u.ready?"bg-success/15 text-success":u.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:m})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Op[u.destination])})}),!h&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),h&&u.problem&&!u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:Ei(u.problem)}),h&&u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),h&&e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null,"aria-busy":x||void 0,title:u.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:u.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[x?e.jsx(q,{size:12,className:"animate-spin"}):e.jsx(Le,{size:12}),t("common.delete")]})]},u.botId)})})]})}function Pt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:O("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(ve,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:O("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 rt({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:O("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(q,{size:13,className:"animate-spin"}),a]})}const ar=5,ir=1440,qp=480;function Jp(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=ar&&a<=ir?a:null}function Yp({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[p,m]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const x=async()=>{if(!c||p)return;const h=Jp(i);if(h===null){u(t("vm.idle.range"));return}m(!0);try{await a(h),r(String(h)),o(!1),u("")}catch(f){u(f instanceof Error?f.message:t("vm.idle.error"))}finally{m(!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:O("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:ar,max:ir,step:1,inputMode:"numeric",value:i,disabled:n||p,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:h=>{r(h.target.value),o(!0),u("")},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 rr(){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[u,p]=l.useState(null),[m,x]=l.useState(!1),[h,f]=l.useState(0),[b,y]=l.useState([]),[g,v]=l.useState(2),[C,w]=l.useState(!1),[N,I]=l.useState(null),[j,L]=l.useState(null),[k,P]=l.useState(null),[S,M]=l.useState(0),[se,ne]=l.useState([]),[V,ie]=l.useState(null),[re,oe]=l.useState(!0),[T,R]=l.useState(null),[E,D]=l.useState(null),[Q,le]=l.useState(null),[ae,U]=l.useState(0),te=l.useRef([]),me=l.useRef({}),[ce,xe]=l.useState([]),[de,je]=l.useState(null),[_,pe]=l.useState([]),[B,A]=l.useState(!0),[H,he]=l.useState(null),[W,Ne]=l.useState(null),[ze,qe]=l.useState(null),[$,ee]=l.useState(0),[Z,ue]=l.useState(""),fe=l.useCallback(async z=>{const K=await fetch(...At("status",z)),J=await K.json().catch(()=>({}));if(!z?.aborted){if(!K.ok)throw new Error(J.error??t("vm.err.status",{code:K.status}));return a(J),p(null),J}},[]),Pe=l.useCallback(async z=>{const K=await fetch(...At("local-vms",z)),J=await K.json().catch(()=>({}));if(!K.ok)throw new Error(J.error??t("vm.err.inventory",{code:K.status}));const Y=J;y(Y.instances),v(Y.maxInstances),L(Y.available?null:Ei(Y.problem)??t("vm.err.runtimeUnavailable")),I(null)},[]),Je=l.useCallback(async z=>{const K=await fetch(...At("cloud",z)),J=await K.json().catch(()=>({}));if(!K.ok)throw new Error(J.error??t("vm.err.cloudInventory",{code:K.status}));const Y=J,we=Up(Y,te.current,me.current);me.current=we.overrides,te.current=we.instances,ne(we.instances),ie(Y.configured===!0),D(Y.available||!Y.configured?null:Y.problem??t("vm.err.cloudUnavailable")),R(null)},[]),Ye=l.useCallback(async z=>{const K=await fetch(...At("vps",z)),J=await K.json().catch(()=>({}));if(!K.ok)throw new Error(J.error??t("vm.err.vpsInventory",{code:K.status}));const Y=J;xe(Array.isArray(Y.instances)?Y.instances:[]),je(Y.configured===!0),pe(Array.isArray(Y.vpsAliases)?Y.vpsAliases:[]),Ne(Y.available||!Y.configured?null:Y.problem??t("vm.err.vpsUnavailable")),he(null)},[]);l.useEffect(()=>{if(s)return;let z=!0,K,J;const Y=async()=>{J=new AbortController;try{await fe(J.signal)}catch(we){z&&!(we instanceof DOMException&&we.name==="AbortError")&&(a(null),p(we instanceof Error?we.message:String(we)))}finally{z&&(r(!1),K=window.setTimeout(()=>{Y()},5e3))}};return Y(),()=>{z=!1,J?.abort(),K!==void 0&&window.clearTimeout(K)}},[s,fe,h]),l.useEffect(()=>{if(n?.mode!=="per-bot"){y([]),w(!1),I(null),L(null);return}const z=new AbortController;return w(!0),Pe(z.signal).catch(K=>{K instanceof DOMException&&K.name==="AbortError"||I(K instanceof Error?K.message:String(K))}).finally(()=>{z.signal.aborted||w(!1)}),()=>z.abort()},[S,Pe,n?.mode]),l.useEffect(()=>{const z=new AbortController;return oe(!0),Je(z.signal).catch(K=>{K instanceof DOMException&&K.name==="AbortError"||D(K instanceof Error?K.message:String(K))}).finally(()=>{z.signal.aborted||oe(!1)}),()=>z.abort()},[ae,Je]),l.useEffect(()=>{const z=new AbortController;return A(!0),Ye(z.signal).catch(K=>{K instanceof DOMException&&K.name==="AbortError"||Ne(K instanceof Error?K.message:String(K))}).finally(()=>{z.signal.aborted||A(!1)}),()=>z.abort()},[Ye,$]);const ke=async(z,K)=>{const J=await fetch(`/api/local-computer/${z}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:K}),Y=await J.json().catch(()=>({})),we={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!J.ok)throw new Error(Y.error??t(we[z]));return K.throwIfAborted(),a(Y),Y},pt=z=>window.ogb?.confirm?window.ogb.confirm(z):window.confirm(z),Ue=async z=>{if(c!==null||d.current)return;const K=new AbortController;d.current=K,o(z),p(null);try{if(z==="remove"&&!await pt(t("vm.confirm.deleteShared"))||z==="recreate"&&!await pt(t("vm.confirm.recreate")))return;let J;if(z==="recreate"?(await ke("remove",K.signal),J=await ke("run",K.signal)):J=await ke(z,K.signal),(z==="run"||z==="start"||z==="recreate")&&(J=await Ed(J,async()=>await fe(K.signal)??J,K.signal),!J.ready))throw new Error(J.problem??t("vm.err.start"));await fe(),ue(z==="remove"?t("vm.announce.deleted"):z==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(J){if(K.signal.aborted)return;p(J instanceof Error?J.message:String(J))}finally{d.current=null,K.signal.aborted||o(null)}},Xe=async(z,K)=>{x(!0),p(null);try{const J=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:z,maxInstances:K}})}),Y=await J.json().catch(()=>({}));if(!J.ok)throw new Error(Y.error??t("vm.policyError"));a(we=>we&&{...we,mode:z,max_instances:K}),await fe()}catch(J){p(J instanceof Error?J.message:String(J))}finally{x(!1)}},wt=async z=>{const K=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:z}})}),J=await K.json().catch(()=>({}));if(!K.ok)throw new Error(J.error??t("vm.idle.error"));a(Y=>Y&&{...Y,idle_timeout_ms:z*6e4})},nt=async z=>{if(!z.managed){I(t("vm.unmanagedError"));return}const K=fs(Kp(z),J=>window.confirm(J));if(K){P(z.botId),I(null);try{const J=await fetch(...K),Y=await J.json().catch(()=>({}));if(!J.ok)throw new Error(Y.error??t("vm.deleteError"));await Pe(),ue(t("vm.announce.deletedBot",{name:z.name}))}catch(J){I(J instanceof Error?J.message:String(J))}finally{P(null)}}},Re=async(z,K)=>{const J=fs(Hp(z,K),Y=>window.confirm(Y));if(J){le({boxId:K.boxId,action:z}),R(null),ue("");try{const Y=await fetch(...J),we=await Y.json().catch(()=>({}));if(!Y.ok)throw new Error(we.error??t(z==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const ns=z==="delete"&&we?.pending===!0;me.current={...me.current,[K.boxId]:z==="delete"?ns?"deleting":"deleted":"sleeping"};const as=nr(te.current,te.current,me.current);me.current=as.overrides,te.current=as.instances,ne(as.instances);const at=K.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:K.ownerName??""});if(ue(ns?`${at}: ${t("vm.state.removing")}.`:t(z==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:at})),ns){for(const Me of Bp){await Lp(Me);try{await Je()}catch{}if(me.current[K.boxId]!=="deleting"){ue(t("vm.announce.cloudDeleted",{subject:at}));return}}const it={...me.current};delete it[K.boxId],me.current=it;const Ct=te.current.map(Me=>Me.boxId===K.boxId?{...Me,state:K.state}:Me);te.current=Ct,ne(Ct);try{await Je(),te.current.some(Me=>Me.boxId===K.boxId)||ue(t("vm.announce.cloudDeleted",{subject:at}))}catch(Me){const al=Me instanceof Error?Me.message:String(Me);R(`${at}: ${t("vm.state.removing")}. ${al}`)}return}try{await Je()}catch(it){const Ct=it instanceof Error?it.message:String(it);R(t(z==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:at,detail:Ct}))}}catch(Y){R(Y instanceof Error?Y.message:String(Y))}finally{le(null)}}},St=async z=>{const K=an(z.name),J=fs(Wp(z),Y=>window.confirm(Y));if(J){qe(z.name),he(null);try{const Y=await fetch(...J),we=await Y.json().catch(()=>({}));if(!Y.ok)throw new Error(we.error??t("vm.vpsRemoveError"));await Ye(),ue(t("vm.announce.vpsRemoved",{subject:z.orphaned?t("vm.announce.orphanVps",{id:K}):t("vm.confirm.ownedVps",{name:z.ownerName??""})}))}catch(Y){he(Y instanceof Error?Y.message:String(Y))}finally{qe(null)}}},Ie=n?.commands,Qe=n?.ready===!0,_e=n?.container!=="missing",mn=!!(_e&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),xn=!i&&!n,hn=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Te=n?.mode==="per-bot",ts=Te&&n?.runtime==="container",ss=Te?!!(n?.daemonUp&&n?.image&&!ts):Qe;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Z}),e.jsx(Gp,{instances:se,configured:V,loading:re,pending:Q,error:T,unavailableReason:E,onRefresh:()=>U(z=>z+1),onSleep:z=>{Re("sleep",z)},onDelete:z=>{Re("delete",z)}}),e.jsx(Tp,{instances:ce,configured:de,aliases:_,loading:B,removingName:ze,error:H,unavailableReason:W,onRefresh:()=>ee(z=>z+1),onRemove:z=>{St(z)}}),e.jsx(Cd,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(X,{title:t("vm.main.title"),subtitle:Te?t("vm.main.perBotSubtitle",{host:hn}):t("vm.main.sharedSubtitle",{host:hn}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:O("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px]",ss?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(q,{size:12,className:"animate-spin"}):ss?e.jsx(ve,{size:12}):e.jsx(ao,{size:9}),i?t("common.checking"):xn?t("vm.main.statusUnavailable"):Te&&ss?t("vm.main.readyPerBot"):ts?t("vm.main.perBotUnsupported"):Qe?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),f(z=>z+1),M(z=>z+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(De,{size:12})," ",t("vm.main.recheck")]}),Qe&&!Te&&e.jsxs("a",{href:n?.viewer_url??Ie?.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(Nt,{size:12})," ",t("vm.main.watch")]})]}),u&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:u})]}),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((z,K)=>e.jsx("button",{type:"button",disabled:!n||m,onClick:()=>{Xe(z,n?.max_instances??2)},className:O("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",K>0&&"border-l border-hairline/40",n?.mode===z?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:z==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},z))}),Te&&e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("vm.isolation.max")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx(ye,{size:"sm","aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||m,onChange:z=>{Xe(n?.mode??"shared",Number(z.target.value))},children:[1,2,3,4,5,6,7,8].map(z=>e.jsx("option",{value:z,children:z},z))})]}),e.jsx(Yp,{minutes:n?Math.round(n.idle_timeout_ms/6e4):qp,disabled:!n||m,onSave:wt}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(q,{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(Pt,{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")}),Ie?.install?e.jsx(gt,{command:Ie.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(Pt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Ie?.runtimeStart?e.jsx(gt,{command:Ie.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(Pt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(rt,{action:"pull",pending:c,onClick:()=>{Ue("pull")},children:t("vm.setup.prepare")}),Ie?.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(gt,{command:Ie.pull})})]})]}),e.jsxs(Pt,{n:4,title:Te?t("vm.setup.step4PerBot"):mn?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!Te&&Qe,children:[Te?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:ts?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):mn?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Ge,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(rt,{action:"recreate",pending:c,onClick:()=>{Ue("recreate")},danger:!0,children:[e.jsx(io,{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(rt,{action:"start",pending:c,onClick:()=>{Ue("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(q,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(rt,{action:"run",pending:c,onClick:()=>{Ue("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Ie?.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(gt,{command:Ie.run})})]})]})]})}),Te&&e.jsx(Vp,{instances:b,maxInstances:g||n?.max_instances||2,loading:C,deletingBotId:k,error:N,unavailableReason:j,onRefresh:()=>M(z=>z+1),onDelete:z=>{nt(z)}}),xn&&e.jsx(X,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Ge,{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:Te?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:[_e&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(rt,{action:"stop",pending:c,onClick:()=>{Ue("stop")},children:[e.jsx(ro,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(rt,{action:"remove",pending:c,onClick:()=>{Ue("remove")},danger:!0,children:[e.jsx(Le,{size:12})," ",Te?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]})]})]})]})}const Qn=/^[A-Za-z0-9_-]+$/,Xp=/^relay[1-9][0-9]?\.openmausbot\.com$/;function Qp(s){if(!s||s.v!==1||typeof s.k!="string"||s.k.length!==87||!Qn.test(s.k))return null;const n=typeof s.h=="string"&&Array.isArray(s.r)&&s.r.length>=1&&s.r.length<=4&&s.h.length===22&&Qn.test(s.h)&&s.r.every(r=>Xp.test(r))?{h:s.h,r:s.r}:{},a=JSON.stringify({v:1,k:s.k,...n}),i=btoa(a).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");return i.length<=1024?i:null}const lr=8,Zp=new Set(["hosted","tailnet","lan","bonjour"]);function Ke(s){const n=new Set,a=[];for(const i of s??[])if(!(!i||!Zp.has(i.kind)||!Number.isInteger(i.priority)||i.priority<0||i.priority>1e6))try{const r=new URL(i.url),c=i.kind==="hosted"?"https:":"http:",o=r.port?Number(r.port):null,d=r.hostname.toLowerCase().replace(/\.$/,"");if(r.protocol!==c||d.split(".").includes("")||i.kind==="tailnet"&&!d.endsWith(".ts.net")||o!==null&&(!Number.isInteger(o)||o<1||o>65535)||r.username||r.password||r.pathname!=="/"||r.search||r.hash||n.has(r.origin))continue;n.add(r.origin),a.push({url:r.origin,kind:i.kind,priority:i.priority})}catch{}return a.sort((i,r)=>i.priority-r.priority).slice(0,lr)}function em(s){const n=new TextEncoder().encode(JSON.stringify(s));let a="";for(const i of n)a+=String.fromCharCode(i);return btoa(a).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function tm(s){if(!s||!/^[A-Za-z0-9_-]{87}$/.test(s))return null;try{const n=s.replaceAll("-","+").replaceAll("_","/")+"=",a=atob(n);if(a.length!==65||a.charCodeAt(0)!==4)return null;let i="";for(let r=0;r<a.length;r+=1)i+=a[r];return btoa(i).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")===s?s:null}catch{return null}}function sm(s,n){const a=s.trim();if(!a)return null;if(/^https?:\/\//i.test(a))try{const r=new URL(a);return r.username||r.password||r.pathname!=="/"||r.search||r.hash?null:r.origin}catch{return null}return n===void 0||!Number.isInteger(n)||n<1||n>65535?null:`${a.includes(":")&&!a.startsWith("[")?`[${a}]`:a}:${n}`}function nm({address:s,port:n,token:a,code:i,name:r,hosts:c,endpoints:o,secretPublicKey:d,e2e:u}){const p=sm(s,n);if(!p||!/^omb_pair_[A-Za-z0-9_-]{43}$/.test(a)||i!==void 0&&!/^\d{6}$/.test(i))return null;const m=[["address",p],["token",a]];i!==void 0&&m.push(["code",i]),r?.trim()&&m.push(["name",r.trim()]);const x=(c??[]).map(y=>y.trim()).filter(y=>y&&!/[\s/?#,[\]]/.test(y)).slice(0,lr);x.length&&m.push(["hosts",x.join(",")]);const h=Ke(o);h.length&&m.push(["endpoints",em(h)]);const f=tm(d);f&&m.push(["secretKey",f]);const b=Qp(u);return b&&m.push(["e2e",b]),`openmausbot://pair?${m.map(([y,g])=>`${y}=${encodeURIComponent(g)}`).join("&")}`}function rn(s){return t("pairing.worksOnceUntil",{time:il(s)})}function Rs(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)})}function am(s){const n=s.endpoints?.find(a=>{if(a.kind!=="hosted")return!1;try{return new URL(a.url).hostname===s.address}catch{return!1}});return n?new URL(n.url).origin:`${s.address}:${s.port}`}const bs=s=>{const n=new Set,a=[];for(const i of s){const r=i.trim();!r||n.has(r)||(n.add(r),a.push(r))}return a},ys=(s,n)=>`http://${s.includes(":")&&!s.startsWith("[")?`[${s}]`:s}:${n}`;function Mt(s,n){if(n==="automatic"){const m=Ke(s.endpoints).filter(y=>y.kind==="hosted"),x=m[0]??null;if(!x)return null;const h=new URL(x.url),f=h.hostname,b=h.port?Number(h.port):443;return{address:f,port:b,hosts:bs([f,...m.map(y=>new URL(y.url).hostname)]),endpoints:m}}const a=Ke(s.endpoints);if(n==="tailscale"){if(s.routes?.tailscale?.on===!1)return null;let m=null;if(s.routes?.tailscale?.on){const g=s.routes.tailscale.name?.trim();g&&(m=Ke([{url:ys(g,s.port),kind:"tailnet",priority:0}])[0]??null)}if(m??=a.find(g=>g.kind==="tailnet")??null,!m&&s.tailnetName?.trim()&&(m=Ke([{url:ys(s.tailnetName.trim(),s.port),kind:"tailnet",priority:0}])[0]??null),!m)return null;const x=new URL(m.url),h=x.hostname,f=x.port?Number(x.port):80,b=a.filter(g=>g.url!==m.url&&["hosted","tailnet"].includes(g.kind)),y=[m,...b].map((g,v)=>({...g,priority:v*100}));return{address:h,port:f,hosts:bs([h,...(s.hosts??[]).filter(g=>g.trim().toLowerCase().replace(/\.$/,"").endsWith(".ts.net"))]),endpoints:y}}let i=a.find(m=>m.kind==="lan")??(s.discovery?.advertising?a.find(m=>m.kind==="bonjour"):null)??null;if(!i){const m=s.lan?.trim()||(s.discovery?.advertising?s.hosts?.find(x=>x.trim().toLowerCase().endsWith(".local")):null);if(!m)return null;i=Ke([{url:ys(m.trim(),s.port),kind:m.trim().toLowerCase().endsWith(".local")?"bonjour":"lan",priority:0}])[0]??null}if(!i)return null;const r=new URL(i.url),c=r.hostname,o=r.port?Number(r.port):80,d=a.filter(m=>m.url!==i.url&&m.kind==="hosted"),u=a.filter(m=>m.url!==i.url&&!["hosted","tailnet"].includes(m.kind)),p=[i,...d,...u].map((m,x)=>({...m,priority:x*100}));return{address:c,port:o,hosts:bs([c,...(s.hosts??[]).filter(m=>!m.trim().toLowerCase().replace(/\.$/,"").endsWith(".ts.net"))]),endpoints:p}}function im(s,n){const a=Mt(s,n);if(!a)return null;const i=Ke(a.endpoints),r=i[0]??null,c=n==="local"?null:n==="tailscale"?i.find(d=>d.kind==="tailnet")??null:r?.kind==="hosted"?r:null;if(n!=="local"&&!c)return null;const o=Ke(s.endpoints);return{route:{...a,endpoints:i},protectedEndpoint:c,protectedEndpointAdvertised:c?o.some(d=>d.kind===c.kind&&d.url===c.url):!1}}function rm(s,n){if(!n.protectedEndpoint)return!0;const a=Ke(s.endpoints).some(o=>o.kind===n.protectedEndpoint?.kind&&o.url===n.protectedEndpoint.url);if(n.protectedEndpoint.kind!=="tailnet")return a;if(s.routes?.tailscale?.on===!1)return!1;const i=s.routes?.tailscale?.on?s.routes.tailscale.name?.trim().toLowerCase().replace(/\.$/,""):void 0,r=lm(n.protectedEndpoint.url);if(i&&r!==i)return!1;if(a)return!0;if(n.protectedEndpointAdvertised)return!1;if(i)return r===i;const c=s.tailnetName?.trim().toLowerCase().replace(/\.$/,"");return!!c&&r===c}const lm=s=>{try{return new URL(s).hostname.toLowerCase().replace(/\.$/,"")}catch{return}},or={active:!1,localFallback:!1,tailscaleFallback:!1,baselineDeviceIds:[],pairingAttempted:!1,pairedDeviceName:null};function om(s,n){switch(n.type){case"start":case"resume":return{active:!0,localFallback:!1,tailscaleFallback:!1,baselineDeviceIds:[...n.deviceIds],pairingAttempted:!1,pairedDeviceName:null};case"use-local":return{...s,active:!0,localFallback:!0,tailscaleFallback:!1,pairingAttempted:!1};case"use-tailscale":return{...s,active:!0,localFallback:!1,tailscaleFallback:!0,pairingAttempted:!1};case"pairing-opened":return{...s,baselineDeviceIds:[...n.deviceIds],pairingAttempted:!0};case"paired":return{...s,active:!0,pairedDeviceName:n.deviceName};case"reset":return or}}const cm=3e4;function dm(s,n){return s.pairedDeviceName?"success":s.active?n.pairingOpen||s.pairingAttempted?"qr":n.provisioningTimedOut?"sign-in":s.localFallback||s.tailscaleFallback?"verifying":n.accountStatus==="signed-out"||n.accountStatus==="unavailable"||n.accountStatus==="error"?"sign-in":(n.accountBusy||n.provisioning,"verifying"):"intro"}async function um(s,n,a){let i=await(n?a.read():a.start());return n&&!i.enabled&&(a.shouldContinue?.()??!0)&&(i=await a.start()),s==="tailscale"&&i.enabled&&!i.error&&(a.shouldContinue?.()??!0)&&(i=await a.refreshTailscale()),i}const pm=(s,n)=>n?.endpoints?.some(a=>a.kind==="hosted")?"hosted-ready":!s?.available||s.status==="signed-out"||s.status==="error"?"local-only":s.status==="ready"&&!n?.enabled?"hosted-startable":"hosted-connecting";function Ft(s,n,a){if(a)return"open";switch(pm(s,n)){case"hosted-ready":return"open";case"hosted-startable":return"start";case"hosted-connecting":return"wait";case"local-only":return"account-required"}}function mm(s,n,a){return s!=="automatic"?!1:n==="open"?!0:n==="wait"&&a?.available===!0&&(a.status==="ready"||a.status==="connecting")}function xm(s,n){return s?.available===!0&&s.status==="ready"&&!s.endpoint&&Ft(s,n,!1)==="wait"}function hm(s,n){const a=new Set(s);return n.find(i=>!a.has(i.id))??null}function gm(s,n){return!s.active||!s.pairingAttempted||s.pairedDeviceName?null:hm(s.baselineDeviceIds,n)}function It(s){return s?s.map(n=>n.id):null}function fm(s,n){return s.active&&n.provisioning&&!n.provisioningTimedOut}function bm(s,n){return s.generation===n?!1:(s.generation=n,!0)}function ht(s,n){return s.generation!==n?!1:(s.generation=null,!0)}function ym(s,n){return s.active?.generation===n.generation||s.pending?.generation===n.generation?"duplicate":s.active?(s.pending=n,"queued"):(s.active=n,"start")}function vm(s,n){if(s.active?.generation!==n)return null;const a=s.pending;return s.active=a,s.pending=null,a}function Rt(s,n){s.pending?.generation===n&&(s.pending=null)}const km=()=>t("phone.setup.pairingOpenFailed",{advanced:t("remote.advanced"),remote:t("remote.title")});function jm(s,n=null,a=Date.now()){const i=cr(s);if(i)return i;const r=s.pairing;return!r||r.token===n||!/^omb_pair_[A-Za-z0-9_-]{43}$/.test(r.token)||!/^\d{6}$/.test(r.code??"")||!Number.isFinite(r.expiresAt)||(r.expiresAt??0)<=a?km():null}async function Tt(s,n,a,i){const r=s.pairing?.token;if(!r||!i())return!1;let c;try{c=await n()}catch{return!1}if(!i()||c.pairing?.token!==r)return!1;try{return await a(),!0}catch{return!1}}async function Nm(s,n,a){const i=await s();return a()?i:(await n(i).catch(()=>{}),null)}function wm(s,n,a={set:(i,r)=>setTimeout(i,r),clear:i=>clearTimeout(i)}){let i=!1,r=null;const c=()=>{i||(r=a.set(()=>{Promise.resolve().then(s).catch(()=>{}).finally(c)},n))};return c(),()=>{i=!0,r!==null&&a.clear(r)}}const Sm=()=>t("phone.setup.startFailed",{advanced:t("remote.advanced"),remote:t("remote.title")});function cr(s){return s.enabled&&!s.error?null:s.error?.trim()||Sm()}const Zn=/\bReference:\s*([0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\.?/i,Cm=/^Error invoking remote method ['"][^'"\r\n]+['"]:\s*(?:Error:\s*)?/i,Em=[/^Enter a valid email address\.$/,/^The secure connection request (?:was not accepted|was not allowed)\./,/^That code (?:is not valid|expired)\./,/^Your sign-in expired\./,/^OpenMausBot could not reach its secure connection service\./,/^Too many attempts were made\./,/^This computer was reconnected too often\./,/^This account has reached its computer limit\./,/^This computer is already connected\./,/^The secure connection (?:is still being prepared|service could not finish setup|is still being removed)\./,/^Secure HTTPS links are temporarily full\./,/^Secure access is not available right now\./,/^The secure connection service (?:had a problem|returned an unexpected response|is busy right now)\./,/^The secure connection request could not be completed\./];function lt(s,n){const a=s instanceof Error?s.message:"",i=a.replace(Cm,"").replace(/^Error:\s*/i,"").trim(),r=i.match(Zn)?.[1]??"",c=i.replace(Zn,"").trim(),d=!(/remote method ['"]companion-account:request-code['"]/i.test(a)&&c.startsWith("The secure connection request was not allowed."))&&Em.some(u=>u.test(c))?c:n;return r?t("phone.error.reference",{message:d,reference:r}):d}const Be=async(s,n)=>{s.current+=1;try{return await n()}finally{s.current+=1}},Am=(s,n)=>s.current===n,Pm=(s,n)=>s?n?"details":"direct":"hidden",Im=s=>s.length<=3?"…":s.length<10?`${s.slice(0,3)}…`:s.length<17?`${s.slice(0,4)}…${s.slice(-3)}`:`${s.slice(0,10)}…${s.slice(-6)}`;function Rm({label:s,value:n}){const[a,i]=l.useState(!1),{state:r,copy:c}=Qt(n);return e.jsxs("div",{className:"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-[11px] font-medium uppercase tracking-wide text-ink-secondary",children:s}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-[12px] text-ink",children:a?n:Im(n)})]}),e.jsx("button",{onClick:()=>i(o=>!o),className:"shrink-0 rounded px-2 py-1 text-[11px] text-ink-secondary hover:bg-control hover:text-ink",children:t(a?"connectionDetail.hide":"connectionDetail.reveal")}),e.jsx("button",{onClick:c,"aria-label":r==="failed"?t("common.copyFailed"):t("connectionDetail.copy",{label:s}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-ink",children:r==="copied"?e.jsx(ve,{size:13,className:"text-success"}):r==="failed"?e.jsx(We,{size:13,className:"text-danger"}):e.jsx(qs,{size:13})})]})}const Tm=1e5;function vs({on:s,label:n,value:a}){return e.jsxs("div",{className:"flex h-7 items-center gap-2 text-left",children:[s?e.jsx(ve,{size:14,className:"shrink-0 text-success"}):e.jsx(lo,{size:14,className:"shrink-0 text-ink-tertiary"}),e.jsx("span",{className:"w-[120px] shrink-0 text-[13px] text-ink",children:n}),e.jsx("span",{className:"min-w-0 truncate text-[12px] text-ink-secondary",children:a})]})}function Bm({c:s,signedIn:n}){const[a,i]=l.useState(!1),[r,c]=l.useState(!1),o=s.state,d=!!o?.pairing;if(l.useEffect(()=>{if(!d)return;const x=setInterval(()=>{s.act(h=>h.renewPairing?h.renewPairing():h.pairing(!0))},Tm);return()=>clearInterval(x)},[d,s]),!o||!s.pairingLink)return null;const u=o.lan??o.addresses?.[0]??null,p=o.e2e?.descriptor?.r?.length?o.e2e.relay:null,m=()=>{wi(s.pairingLink??"").then(()=>{i(!0),setTimeout(()=>i(!1),2500)})};return e.jsxs("div",{className:"flex w-full max-w-[440px] flex-col items-center text-center",children:[e.jsx("div",{className:"rounded-2xl bg-white p-3.5 transition-opacity duration-150","aria-label":t("phone.code.qrAria"),children:e.jsx(es,{value:s.pairingLink,size:320,level:"L",marginSize:1,bgColor:"#ffffff",fgColor:"#111111"},o.pairing?.token)}),e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("phone.code.e2e.scan",{app:Se()})}),e.jsxs("div",{className:"mt-5 w-full px-2",children:[e.jsx(vs,{on:!!u,label:t("phone.code.e2e.wifi"),value:u??""}),e.jsx(vs,{on:!!o.tailnetName,label:t("phone.code.e2e.tailscale"),value:o.tailnetName??t("phone.code.e2e.tailscaleOff")}),e.jsx(vs,{on:!!p,label:t("phone.code.e2e.relay"),value:p?t("phone.code.e2e.fromAnywhere"):n?t("phone.code.e2e.relayOff"):t("phone.code.e2e.signIn")})]}),s.localFallback&&o.publicNetwork&&e.jsx("p",{role:"note",className:"mt-3 w-full rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-left text-[12px] leading-relaxed text-warning",children:t("phone.code.publicNetwork",{network:o.publicNetwork})}),e.jsxs("p",{className:"mt-4 flex items-start gap-1.5 px-2 text-left text-[12px] text-ink-tertiary",children:[e.jsx(dd,{size:12,className:"mt-0.5 shrink-0"}),t("phone.code.e2e.encrypted")]}),e.jsxs("div",{className:"relative mt-5 flex w-full items-center justify-between px-2",children:[e.jsx("button",{onClick:m,className:"text-[12px] text-ink-secondary hover:text-ink",children:t("phone.code.e2e.copyLink")}),gn,gn]}),a&&e.jsx("div",{role:"status",className:"mt-3 rounded-lg bg-inset px-3 py-1.5 text-[12px] text-ink",children:t("phone.code.e2e.copied")})]})}function Lm({c:s}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"my-4 flex items-center gap-3 text-[11px] text-ink-secondary",children:[e.jsx("span",{className:"h-px flex-1 bg-hairline/40"})," ",t("phone.signIn.or")," ",e.jsx("span",{className:"h-px flex-1 bg-hairline/40"})]}),e.jsxs("button",{disabled:s.busy||s.accountBusy,onClick:s.useLocal,className:"flex items-center justify-center gap-2 rounded-lg border border-hairline/50 py-2.5 text-[13px] text-ink hover:bg-control disabled:opacity-40",children:[e.jsx(uu,{size:15})," ",t("phone.signIn.wifiInstead")]}),e.jsx("p",{className:"mt-2 text-center text-[11px] leading-relaxed text-ink-secondary",children:t("phone.signIn.wifiNote")}),s.tailscaleAvailable&&e.jsx("button",{disabled:s.busy||s.accountBusy,onClick:s.useTailscale,className:"mt-2 flex items-center justify-center gap-2 rounded-lg border border-hairline/50 py-2.5 text-[13px] text-ink hover:bg-control disabled:opacity-40",children:t("phone.signIn.tailscaleInstead")}),s.tailscaleAvailable&&e.jsx("p",{className:"mt-2 text-center text-[11px] leading-relaxed text-ink-secondary",children:t("phone.signIn.tailnetNote")})]})}const ea=()=>t("phone.error.directUnavailable"),ta=()=>t("phone.error.protectedUnavailable"),Ze=()=>globalThis.ogb?.companionAccount??null,Om=async(s,n)=>{const[a,i]=await Promise.allSettled([s?Promise.resolve().then(()=>s.state()):Promise.resolve(null),n?Promise.resolve().then(()=>n.state()):Promise.resolve(null)]);return{companion:a.status==="fulfilled"?a.value:null,account:i.status==="fulfilled"?i.value:null}},zm=(s,n)=>!s&&!!n.email,dr=(s,n)=>n||(s?.status==="signed-out"?s.message??null:null);function Mm(s=""){const[n,a]=l.useState(null),[i,r]=l.useState(null),[c,o]=l.useState(s),[d,u]=l.useState(""),[p,m]=l.useState(!1),[x,h]=l.useState(!1),[f,b]=l.useState(!1),[y,g]=l.useState(!1),[v,C]=l.useState(!1),[w,N]=l.useState(!1),[I,j]=l.useState(null),[L,k]=l.useState(null),[,P]=l.useState(()=>Date.now()),[S,M]=l.useReducer(om,or),se=l.useRef(!1),ne=l.useRef({generation:null}),V=l.useRef({active:null,pending:null}),ie=l.useRef(async()=>{}),re=l.useRef(null),[oe,T]=l.useState(null),R=l.useRef(0),E=l.useRef(!0),D=l.useRef(0),Q=l.useRef(null),le=l.useCallback($=>{re.current=$,T($)},[]);l.useEffect(()=>(E.current=!0,()=>{E.current=!1,R.current+=1}),[]);const ae=l.useCallback(()=>{if(Q.current)return Q.current;const $=D.current,ee=(async()=>{const Z=await Om(ct(),Ze());E.current&&(Z.companion&&Am(D,$)&&a(Z.companion),Z.account&&(r(Z.account),zm(se.current,Z.account)&&o(Z.account.email??"")))})().finally(()=>{Q.current===ee&&(Q.current=null)});return Q.current=ee,ee},[]);l.useEffect(()=>{ae()},[ae]),l.useEffect(()=>{!se.current&&s&&o(s)},[s]);const U=l.useCallback(async $=>{const ee=ct();if(ee){h(!0),j(null);try{const Z=await Be(D,()=>$(ee));E.current&&a(Z)}catch(Z){E.current&&j(lt(Z,t("phone.error.remoteUpdate")))}finally{E.current&&h(!1)}}},[]),te=l.useCallback(async $=>{const ee=Ze();if(ee){g(!0),k(null);try{const Z=await Be(D,()=>$(ee));if(!E.current)return;r(Z),await ae()}catch(Z){E.current&&k(lt(Z,t("phone.error.secureUpdate")))}finally{E.current&&g(!1)}}},[ae]),me=l.useCallback(async({routeMode:$,accountOverride:ee,generation:Z})=>{const ue=()=>{ht(ne.current,Z)&&E.current&&b(!1);const ke=vm(V.current,Z);ke&&ie.current(ke)},fe=()=>E.current&&R.current===Z;if(!fe()){ue();return}const Pe=ct();if(!Pe){E.current&&R.current===Z&&j(t("phone.error.desktopOnly")),ue();return}const Je=()=>{const ke=re.current;return!ke||ke.generation===Z},Ye=re.current;Ye&&Ye.generation!==Z&&(le(null),a(ke=>ke?.pairing?.token===Ye.token?{...ke,pairing:null}:ke)),j(null);try{const ke=await um($,!!n?.enabled,{read:()=>Pe.state(),start:()=>Be(D,()=>Pe.start($==="automatic"?void 0:[])),refreshTailscale:()=>Be(D,()=>Pe.refreshTailscale()),shouldContinue:fe});if(!fe())return;a(ke);const pt=cr(ke);if(pt){C(!1),j(pt),M({type:"reset"});return}const Ue=$!=="automatic",Xe=Ft(ee??i,ke,Ue),wt=Ze(),nt=wt?.prepare&&mm($,Xe,ee??i)?wt.prepare:null;if(Xe!=="open"){if(C(Xe==="wait"||Xe==="start"),nt){const _e=await Be(D,()=>nt());fe()&&r(_e)}return}if(nt&&Promise.resolve().then(()=>nt()).catch(()=>{}),Ue&&!Mt(ke,$)){C(!1),j($==="tailscale"?t("phone.error.tailscaleUnavailable"):ea()),M({type:"reset"});return}const Re=await Nm(()=>Be(D,()=>Pe.pairing(!0)),_e=>Tt(_e,()=>Pe.state(),()=>Be(D,()=>Pe.pairing(!1,_e.pairing?.token)),Je),fe);if(!Re)return;const St=Re.pairing,Ie=jm(Re,ke.pairing?.token??null),Qe=Ie?null:im(Re,$);if(Ie||!Qe||!St){if(await Tt(Re,()=>Pe.state(),()=>Be(D,()=>Pe.pairing(!1,Re.pairing?.token)),fe),!fe())return;le(null),a({...Re,pairing:null}),C(!1),j(Ie??($==="local"?ea():$==="tailscale"?t("phone.error.tailscaleUnavailable"):ta())),M({type:"reset"});return}le({...Qe,generation:Z,token:St.token}),a(Re),C(!1),N(!1),M({type:"pairing-opened",deviceIds:Re.devices.map(_e=>_e.id)})}catch(ke){if(!fe())return;le(null),C(!1),j(lt(ke,t("phone.error.pairingPrepare"))),M({type:"reset"})}finally{ue()}},[i,le,n]);l.useLayoutEffect(()=>{ie.current=me},[me]);const ce=l.useCallback(($,ee,Z=R.current)=>{const ue={routeMode:$,accountOverride:ee,generation:Z},fe=ym(V.current,ue);fe!=="duplicate"&&(bm(ne.current,Z),b(!0),fe==="start"&&ie.current(ue))},[]),xe=l.useCallback(()=>{const $=It(n?.devices??null);if(!$)return;const ee=++R.current;M({type:"start",deviceIds:$}),j(null),k(null),N(!1),(Ft(i,n,!1)==="open"||i?.available&&(i.status==="ready"||i.status==="connecting"))&&(C(!0),ce("automatic",i,ee))},[i,ce,n]),de=l.useCallback(()=>{const $=It(n?.devices??null);if(!$)return;S.active||M({type:"start",deviceIds:$});const ee=++R.current;M({type:"use-local"}),C(!0),N(!1),k(null),ce("local",void 0,ee)},[S.active,ce,n?.devices]),je=l.useCallback(()=>{const $=It(n?.devices??null);if(!$)return;S.active||M({type:"start",deviceIds:$});const ee=++R.current;M({type:"use-tailscale"}),C(!0),N(!1),k(null),ce("tailscale",void 0,ee)},[S.active,ce,n?.devices]),_=l.useCallback(()=>{U($=>$.refreshTailscale())},[U]),pe=l.useCallback(()=>{const $=Ze(),ee=c.trim().toLowerCase();if(!$||!ee)return;const Z=R.current;g(!0),k(null),$.requestCode(ee).then(ue=>{!E.current||R.current!==Z||(r(ue),m(!0))}).catch(ue=>{!E.current||R.current!==Z||k(lt(ue,t("phone.error.sendCode")))}).finally(()=>{E.current&&R.current===Z&&g(!1)})},[c]),B=l.useCallback(()=>{const $=Ze(),ee=c.trim().toLowerCase();if(!$||d.length!==8)return;const Z=R.current;g(!0),C(!0),N(!1),k(null),Be(D,()=>$.verifyCode(ee,d)).then(async ue=>{!E.current||R.current!==Z||(r(ue),u(""),m(!1),await ce("automatic",ue,Z))}).catch(ue=>{!E.current||R.current!==Z||(C(!1),k(lt(ue,t("phone.error.verifyCode"))))}).finally(()=>{E.current&&R.current===Z&&g(!1)})},[d,c,ce]),A=l.useCallback(()=>{const $=Ze();if(!$)return;const ee=S.active?It(n?.devices??null):null,Z=++R.current;ee&&M({type:"start",deviceIds:ee}),g(!0),C(!0),N(!1),k(null),Be(D,()=>$.retry()).then(async ue=>{!E.current||R.current!==Z||(r(ue),S.active?await ce("automatic",ue,Z):(await ae(),E.current&&R.current===Z&&C(!1)))}).catch(ue=>{!E.current||R.current!==Z||(C(!1),k(lt(ue,t("phone.error.restore"))))}).finally(()=>{E.current&&R.current===Z&&g(!1)})},[S.active,ae,ce,n?.devices]),H=dm(S,{accountStatus:i?.available?i.status:"unavailable",accountBusy:y,provisioning:v,provisioningTimedOut:w,pairingOpen:!!(n?.pairing&&oe?.token===n.pairing.token)});l.useEffect(()=>{!S.active||S.localFallback||S.tailscaleFallback||!i||i.available&&i.status!=="signed-out"&&i.status!=="error"||C(!1)},[i,S.active,S.localFallback,S.tailscaleFallback]),l.useEffect(()=>{if(!fm(S,{provisioning:v,provisioningTimedOut:w}))return;const $=window.setTimeout(()=>{const ee=R.current;R.current+=1,Rt(V.current,ee),ht(ne.current,ee),b(!1),g(!1),C(!1),N(!0)},cm);return()=>window.clearTimeout($)},[S,v,w]),l.useEffect(()=>{const $=oe;if(!$||!n)return;if(!n.pairing){le(null);return}const ee=n.pairing.token===$.token,Z=rm(n,$);if(ee&&Z)return;const ue=ct();R.current===$.generation&&(R.current+=1),Rt(V.current,$.generation),ht(ne.current,$.generation),b(!1),le(null),a(fe=>fe&&{...fe,pairing:null}),C(!1),N(!1),j(ee?ta():t("phone.error.codeChanged")),M({type:"reset"}),ee&&ue&&Tt(n,()=>ue.state(),()=>Be(D,()=>ue.pairing(!1,n.pairing?.token)),()=>{const fe=re.current;return!fe||fe.generation===$.generation})},[oe,le,n]),l.useEffect(()=>{if(!n)return;const $=gm(S,n.devices);$&&M({type:"paired",deviceName:$.name})},[S,n]),l.useEffect(()=>{!S.active||S.localFallback||S.tailscaleFallback||S.pairingAttempted||w||!n||(Ft(i,n,!1)==="open"||!v&&xm(i,n))&&ce("automatic")},[i,S.active,S.localFallback,S.pairingAttempted,S.tailscaleFallback,ce,v,w,n]);const he=S.active||!!n?.pairing;l.useEffect(()=>wm(()=>(P(Date.now()),ae()),he?1e3:1e4),[ae,he]);const W=S.localFallback?"local":S.tailscaleFallback?"tailscale":"automatic",Ne=l.useMemo(()=>n?n.pairing?oe?.token===n.pairing.token?oe.route:null:Mt(n,W):null,[W,oe,n]),ze=l.useMemo(()=>!n?.pairing||!Ne?null:nm({...Ne,code:n.e2e?.enabled?void 0:n.pairing.code,token:n.pairing.token,name:n.discovery?.name,secretPublicKey:n.secretPublicKey,e2e:n.e2e?.descriptor}),[Ne,n]),qe=l.useCallback(()=>{const $=R.current;R.current+=1,Rt(V.current,$),ht(ne.current,$),b(!1);const ee=n,Z=ct();le(null),a(ue=>ue&&{...ue,pairing:null}),Z&&ee?.pairing&&Tt(ee,()=>Z.state(),()=>Be(D,()=>Z.pairing(!1,ee.pairing?.token)),()=>re.current===null),C(!1),g(!1),N(!1),m(!1),u(""),M({type:"reset"})},[le,n]);return{state:n,account:i,phase:H,email:c,code:d,codeSent:p,busy:x||f,accountBusy:y,error:I,accountError:L,pairingLink:ze,address:Ne?.address,pairingPort:Ne?.port??n?.port??8810,addressText:Ne?am(Ne):void 0,hostedReady:!!n?.endpoints?.some($=>$.kind==="hosted"),localFallback:S.localFallback,tailscaleFallback:S.tailscaleFallback,tailscaleAvailable:!!(n&&Mt(n,"tailscale")),pairingExpired:S.pairingAttempted&&!n?.pairing,setupTimedOut:w,setEmail:$=>{se.current=!0,o($)},setCode:$=>u($.replaceAll(/\D/g,"").slice(0,8)),changeEmail:()=>{u(""),m(!1),k(null)},start:xe,useLocal:de,useTailscale:je,refreshTailscale:_,requestCode:pe,verifyCode:B,retryAccount:A,cancel:qe,refreshCode:()=>{const $=++R.current;ce(W,void 0,$)},finish:()=>{const $=R.current;R.current+=1,Rt(V.current,$),ht(ne.current,$),b(!1),le(null),N(!1),M({type:"reset"})},act:U,accountAct:te}}function Fm(){const s=[{Icon:Si,title:t("phone.value.chats"),detail:t("phone.value.chatsDetail")},{Icon:ve,title:t("phone.value.approvals"),detail:t("phone.value.approvalsDetail")},{Icon:Ws,title:t("phone.value.private"),detail:t("phone.value.privateDetail")}];return e.jsx("div",{className:"mt-5 grid w-full gap-2 sm:grid-cols-3",children:s.map(({Icon:n,title:a,detail:i})=>e.jsxs("div",{className:"rounded-xl bg-inset px-3 py-3 text-left",children:[e.jsx(n,{size:16,className:"text-accent"}),e.jsx("div",{className:"mt-2 text-[13px] font-medium text-ink",children:a}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]},a))})}function Dm({controller:s}){const n=s,a=dr(n.account,n.accountError),i=/^\S+@\S+\.\S+$/.test(n.email.trim()),r=Pm(!!n.state?.pairing,n.pairingLink);if(n.phase==="qr"&&n.state?.e2e?.enabled&&n.pairingLink)return e.jsx(Bm,{c:n,signedIn:!!n.account?.email});if(n.phase==="intro")return e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsx("div",{className:"flex size-14 items-center justify-center rounded-2xl bg-accent/12 text-accent",children:e.jsx(Si,{size:26})}),e.jsx("h2",{className:"mt-4 text-[19px] font-semibold text-ink",children:t("phone.intro.title",{app:Se()})}),e.jsx("p",{className:"mt-1.5 max-w-[460px] text-[14px] leading-relaxed text-ink-secondary",children:t("phone.intro.detail")}),e.jsx(Fm,{}),e.jsx("button",{"data-phone-pairing-action":!0,onClick:n.start,disabled:!n.state||n.busy||n.accountBusy,className:"mt-5 w-full max-w-[320px] rounded-lg bg-accent py-2.5 text-[14px] font-medium text-white hover:opacity-90 disabled:cursor-wait disabled:opacity-40",children:n.state?.devices.length?t("phone.intro.pairAnother"):t("phone.intro.pair")}),n.error&&e.jsx("p",{role:"alert",className:"mt-3 max-w-[390px] text-[13px] text-danger",children:n.error})]});if(n.phase==="sign-in"){const c=!n.account?.available,o=n.account?.status==="error"||n.setupTimedOut;return e.jsxs("div",{className:"mx-auto flex w-full max-w-[430px] flex-col",children:[e.jsxs("button",{onClick:n.cancel,className:"mb-4 flex w-fit items-center gap-1.5 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(oi,{size:13})," ",t("phone.back")]}),e.jsx("div",{className:"flex size-11 items-center justify-center rounded-xl bg-accent/12 text-accent",children:e.jsx(oo,{size:20})}),e.jsx("h2",{className:"mt-3 text-[18px] font-semibold text-ink",children:c||o?t("phone.signIn.attention"):t("phone.signIn.title")}),e.jsx("p",{role:n.setupTimedOut?"alert":void 0,className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:c?t("phone.signIn.unavailable"):n.setupTimedOut?t("phone.signIn.timedOut"):o?n.account?.message??t("phone.signIn.failed"):t("phone.signIn.emailPrompt")}),!c&&!o&&e.jsxs("div",{className:"mt-5 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:t("phone.signIn.email")}),e.jsx("input",{autoFocus:!0,autoComplete:"email",inputMode:"email",value:n.email,disabled:n.accountBusy||n.codeSent,onChange:d=>n.setEmail(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!n.codeSent&&i&&n.requestCode()},placeholder:t("common.emailPlaceholder"),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[14px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent disabled:opacity-50"})]}),n.codeSent&&e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:t("phone.signIn.emailCode")}),e.jsx("input",{autoFocus:!0,autoComplete:"one-time-code",inputMode:"numeric",value:n.code,disabled:n.accountBusy,onChange:d=>n.setCode(d.target.value),onKeyDown:d=>{d.key==="Enter"&&n.code.length===8&&n.verifyCode()},placeholder:"12345678",className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 font-mono text-[16px] tracking-[0.18em] text-ink outline-none placeholder:tracking-normal placeholder:text-ink-tertiary focus:border-accent disabled:opacity-50"})]}),e.jsx("button",{disabled:n.accountBusy||!n.codeSent&&!i||n.codeSent&&n.code.length!==8,onClick:n.codeSent?n.verifyCode:n.requestCode,className:"rounded-lg bg-accent py-2.5 text-[14px] font-medium text-white hover:opacity-90 disabled:opacity-40",children:n.accountBusy?t("phone.signIn.working"):n.codeSent?t("phone.signIn.verify"):t("phone.signIn.sendCode")}),n.codeSent&&e.jsx("button",{disabled:n.accountBusy,onClick:n.changeEmail,className:"text-[12px] text-ink-secondary hover:text-ink disabled:opacity-40",children:t("phone.signIn.otherEmail")}),n.codeSent&&!a&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("phone.signIn.expires")})]}),(c||o)&&e.jsx("button",{disabled:n.accountBusy,onClick:n.retryAccount,className:"mt-5 rounded-lg bg-accent py-2.5 text-[14px] font-medium text-white disabled:opacity-40",children:n.accountBusy?t("remote.account.retrying"):t("phone.signIn.retry")}),a&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:a}),e.jsx(Lm,{c:n})]})}return n.phase==="verifying"?e.jsxs("div",{className:"flex flex-col items-center py-8 text-center",children:[e.jsx("div",{className:"flex size-14 items-center justify-center rounded-2xl bg-accent/12 text-accent",children:e.jsx(q,{size:25,className:"animate-spin"})}),e.jsx("h2",{className:"mt-4 text-[18px] font-semibold text-ink",children:n.localFallback?t("phone.verifying.local"):n.tailscaleFallback?t("phone.verifying.tailscale"):t("phone.verifying.secure")}),e.jsx("p",{className:"mt-1.5 max-w-[360px] text-[13px] leading-relaxed text-ink-secondary",children:n.localFallback?t("phone.verifying.localDetail"):n.tailscaleFallback?t("phone.verifying.tailscaleDetail"):t("phone.verifying.secureDetail")}),(n.error||n.accountError)&&e.jsx("p",{role:"alert",className:"mt-3 max-w-[380px] text-[13px] text-danger",children:n.error??n.accountError}),e.jsx("button",{onClick:n.cancel,className:"mt-5 text-[12px] text-ink-secondary hover:text-ink",children:t("common.cancel")})]}):n.phase==="success"?e.jsxs("div",{className:"flex flex-col items-center py-6 text-center",children:[e.jsx("div",{className:"flex size-14 items-center justify-center rounded-full bg-success/15 text-success",children:e.jsx(ve,{size:28})}),e.jsx("h2",{className:"mt-4 text-[19px] font-semibold text-ink",children:t("phone.success.title")}),e.jsx("p",{className:"mt-1.5 text-[13px] text-ink-secondary",children:t("phone.success.detail")}),e.jsx("button",{onClick:n.finish,className:"mt-5 w-full max-w-[280px] rounded-lg bg-accent py-2.5 text-[14px] font-medium text-white",children:t("phone.success.done")})]}):e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-white text-black",children:e.jsx(nu,{size:23})}),e.jsx("h2",{className:"mt-3 text-[18px] font-semibold text-ink",children:n.pairingExpired?t("phone.code.expired"):t("phone.code.title")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:n.pairingExpired?t("phone.code.expiredDetail"):t("phone.code.detail")}),!n.pairingExpired&&n.pairingLink&&e.jsx("div",{className:"mt-4 rounded-2xl bg-white p-3.5","aria-label":t("phone.code.qrAria"),children:e.jsx(es,{value:n.pairingLink,size:180,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}),!n.pairingExpired&&r==="direct"&&n.state?.pairing&&e.jsxs("div",{className:"mt-4 w-full max-w-[320px] rounded-xl bg-inset px-4 py-3 text-[13px] text-ink-secondary",children:[e.jsx("div",{children:t("phone.code.typeIntro",{app:Se()})}),e.jsx("div",{className:"mt-2 font-mono text-[22px] tracking-[0.25em] text-ink",children:n.state.pairing.code})]}),!n.pairingExpired&&r==="details"&&n.state?.pairing&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:rn(n.state.pairing.expiresAt)}),!n.pairingExpired&&n.localFallback&&n.state?.publicNetwork&&e.jsx("p",{role:"note",className:"mt-3 w-full max-w-[390px] rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-left text-[12px] leading-relaxed text-warning",children:t("phone.code.publicNetwork",{network:n.state.publicNetwork})}),n.pairingExpired&&e.jsx("button",{onClick:n.refreshCode,className:"mt-5 rounded-lg bg-accent px-5 py-2.5 text-[14px] font-medium text-white",children:t("phone.code.createNew")}),!n.pairingExpired&&n.state?.pairing&&e.jsxs("details",{className:"mt-4 w-full max-w-[390px] rounded-lg border border-hairline/40 px-3 py-2 text-left",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:t("phone.code.trouble")}),e.jsxs("div",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("phone.code.pairingCode"),e.jsx("div",{className:"mt-1 font-mono text-[22px] tracking-[0.25em] text-ink",children:n.state.pairing.code}),n.address&&e.jsx("div",{className:"mt-3",children:e.jsx(Rm,{label:t("phone.code.address"),value:n.addressText??`${n.address}:${n.pairingPort}`})})]})]}),e.jsx("button",{onClick:n.cancel,className:"mt-4 text-[12px] text-ink-secondary hover:text-ink",children:t("common.cancel")})]})}function Um(){const{phase:s,phones:n,refresh:a}=Td(),{dispatch:i}=G(),[r,c]=l.useState(null);if(s==="loading")return null;const o=d=>{r||(c(d),F(Od(d),{method:"DELETE"}).catch(u=>i({type:"error",message:u instanceof Error?u.message:String(u)})).finally(()=>{c(null),a()}))};return e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.phones.title")}),n.length===0?e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("remote.phones.empty")}):e.jsx("ul",{className:"mt-3 flex flex-col gap-2",children:n.map(d=>{const{name:u,platform:p}=d.registration;return e.jsxs("li",{className:"rounded-xl bg-inset px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"truncate text-[14px] font-medium text-ink",children:[u," ",e.jsxs("span",{className:"font-normal text-ink-secondary",children:["· ",Bd(p)]})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:d.online?t("remote.phones.online"):t("remote.phones.offline",{when:pr(d.seen)})})]}),e.jsx("button",{disabled:r!==null,onClick:()=>o(d.key),"aria-label":t("remote.phones.remove",{name:u}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-40",children:e.jsx(Le,{size:14})})]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Ld(d).map(m=>e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 text-[11px] text-ink-secondary",children:t(`botAccess.phone.cap.${m}`)},m))})]},d.key)})})]})}const _m={wifi:"remote.devices.route.wifi",tailscale:"remote.devices.route.tailscale",relay:"remote.devices.route.relay"};function $m(s,n){return[...s].sort((a,i)=>Number(n.has(i.id))-Number(n.has(a.id))||i.lastSeenAt-a.lastSeenAt)}function sa(s,n,a){const i=[];return s.route?i.push(t("remote.devices.connected",{route:t(_m[s.route])})):n?i.push(a&&!s.e2eAt?t("remote.devices.connectedLegacy"):t("remote.devices.connectedNow")):i.push(t("remote.devices.lastSeen",{when:pr(s.lastSeenAt)})),a&&s.routes==="local"&&i.push(t("remote.devices.localOnly")),i.join(" · ")}function Km({device:s,connected:n,state:a,c:i,onRemoved:r,onPairAgain:c,defaultOpen:o=!1}){const[d,u]=l.useState(o),p=a.e2e?.enabled===!0,m=n||!!s.route;return e.jsxs("li",{className:"border-t border-hairline/30 first:border-t-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-3",children:[e.jsx("span",{className:"flex size-3 shrink-0 items-center justify-center",title:sa(s,n,p),children:e.jsx("span",{className:`size-2 rounded-full ${m?"bg-success":"bg-ink-tertiary/40"}`})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[14px] font-medium text-ink",children:s.name}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",children:sa(s,n,p)}),i.account?.paused&&e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",children:t("remote.devices.paused")}),i.account?.tunnelRetired&&!s.e2eAt&&e.jsxs("div",{className:"text-[12px] leading-relaxed text-warning","data-phone-retired":"",children:[t("remote.devices.retired"),c&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:"text-accent hover:underline",onClick:c,children:t("remote.devices.pairAgain")})]})]})]}),e.jsx("button",{onClick:()=>u(x=>!x),"aria-expanded":d,"aria-label":t("remote.devices.more",{name:s.name}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control",children:e.jsx(Ni,{size:15})})]}),d&&e.jsxs("div",{className:"flex flex-col gap-3 border-t border-hairline/30 px-3 py-3",children:[p&&e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.connectFrom")}),e.jsx("div",{role:"radiogroup","aria-label":t("remote.devices.connectFrom"),className:"flex rounded-lg bg-inset p-0.5 text-[12px]",children:["any","local"].map(x=>e.jsx("button",{role:"radio","aria-checked":(s.routes??"any")===x,disabled:i.busy,onClick:()=>{i.act(h=>h.routes?h.routes(s.id,x):h.state())},className:`rounded-md px-2.5 py-1 ${(s.routes??"any")===x?"bg-card text-ink shadow-sm":"text-ink-secondary"}`,children:x==="any"?t("remote.devices.anywhere"):t("remote.devices.localOnly")},x))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowView")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowViewDetail")})]}),e.jsx(be,{checked:s.cloudDesktopAccess,"aria-label":t("remote.devices.viewAria",{name:s.name}),disabled:i.busy,onClick:()=>{i.act(x=>x.cloudDesktop(s.id,!s.cloudDesktopAccess))}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowBrowser")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowBrowserDetail")})]}),e.jsx(be,{checked:s.browserControlAccess===!0,"aria-label":t("remote.devices.browserAria",{name:s.name}),disabled:i.busy,onClick:()=>{i.act(x=>x.browserControl(s.id,!s.browserControlAccess))}})]}),e.jsx("button",{disabled:i.busy,onClick:()=>{i.act(x=>x.revoke(s.id)).then(()=>r(s.name))},"aria-label":t("remote.devices.remove",{name:s.name}),className:"self-start text-[12px] text-danger hover:underline disabled:opacity-40",children:t("remote.devices.removePhone")})]})]})}function na({c:s,state:n,onPairAgain:a}){const[i,r]=l.useState(null),c=new Set(n.connectedDeviceIds??[]);return n.devices.length===0&&!i?null:e.jsxs(e.Fragment,{children:[n.devices.length>0&&e.jsx("ul",{className:"rounded-xl border border-hairline/40 bg-card",children:$m(n.devices,c).map(o=>e.jsx(Km,{device:o,connected:c.has(o.id),state:n,c:s,onRemoved:r,onPairAgain:a},o.id))}),i&&e.jsx("div",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("remote.devices.removed",{name:i})})]})}const Hm="/api/team/phone-pairing",aa="/api/team/phones",Wm=4e3;function Gm(s){return`${s.label} · ${s.email}`}function Vm({team:s,blocked:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(null),[u,p]=l.useState(!1),[m,x]=l.useState(null),[h,f]=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 F(aa);c(Array.isArray(w?.phones)?w.phones:[]),d(typeof w?.current=="string"?w.current:null)}catch(w){b(w)}}l.useEffect(()=>{y()},[]);const g=a?a.expiresAt<=h:!1;l.useEffect(()=>{if(!a)return;const w=setInterval(()=>f(Date.now()),15e3);return()=>clearInterval(w)},[a]),l.useEffect(()=>{if(!a||g)return;const w=setInterval(()=>{y()},Wm);return()=>clearInterval(w)},[a,g]);async function v(){p(!0),x(null);try{i(await F(Hm,{method:"POST",body:"{}"})),f(Date.now())}catch(w){b(w)}finally{p(!1)}}async function C(w){x(null);try{await F(`${aa}/${encodeURIComponent(w)}`,{method:"DELETE"})}catch(N){b(N)}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:()=>{v()},disabled:u||!!n,title:n??void 0,className:"ui-button ui-button-primary",children:u?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:g?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(es,{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:rn(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:[Gm(w),e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("remote.serverPairing.seen",{when:Rs(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,m?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:m}):null]})}function qm({saved:s,onSaved:n,className:a}){const[i,r]=l.useState(s),[c,o]=l.useState(!1),[d,u]=l.useState(null);l.useEffect(()=>r(s),[s]);async function p(){const m=i.trim();if(!(c||m===s)){o(!0),u(null);try{const x=await F("/api/config",{method:"PATCH",body:JSON.stringify({computerName:m})});n(x.computerName??m)}catch(x){u(t("remote.computerName.error",{error:x instanceof Error?x.message:String(x)}))}finally{o(!1)}}}return e.jsxs("div",{"data-computer-name":!0,className:O("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:m=>r(m.target.value),onBlur:()=>{p()},onKeyDown:m=>{m.key==="Enter"&&m.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 bt(s){return Ad(s)}function Jm(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function Ym(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}const Xm="ui-button ui-button-primary",ia="ui-button";function ur({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0,team:r,teamPhoneBlocked:c=null,simple:o=!1,reveal:d=!0}){const[u,p]=l.useState(s),[m,x]=l.useState(n),[h,f]=l.useState(null),[b,y]=l.useState("admin"),[g,v]=l.useState(null),[C,w]=l.useState([]),[N,I]=l.useState(null),[j,L]=l.useState(!1),[k,P]=l.useState("idle"),[S,M]=l.useState(null),[se,ne]=l.useState(()=>Date.now()),V=l.useRef(null),ie=l.useRef(0);async function re(){try{const U=await F("/api/auth/sessions");w(Array.isArray(U?.sessions)?U.sessions:[]),I(typeof U?.current=="string"?U.current:null)}catch(U){M(t("remote.serverPairing.error",{error:U instanceof Error?U.message:String(U)}))}}if(l.useEffect(()=>{Ai().then(U=>{p(U),bt(U)&&re(),(U.kind==="loopback"||U.kind==="session")&&F("/api/config").then(te=>{x(Pi(te).pairingCodes),bt(U)&&f(typeof te?.computerName=="string"?te.computerName:"")}).catch(()=>{})})},[]),l.useEffect(()=>{i?ie.current!==i&&Ii(V.current)&&(ie.current=i):ie.current=0},[i,u]),l.useEffect(()=>{if(!g)return;const U=setInterval(()=>ne(Date.now()),15e3);return()=>clearInterval(U)},[g]),r&&u?.kind==="session"&&u.team)return e.jsx("div",{ref:V,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(Vm,{team:r,blocked:c})});if(!bt(u))return Jm(u)!=="chat-only"?null:e.jsx("div",{ref:V,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(m?"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(m?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const oe=g?g.expiresAt<=se:!1,T=Ym(C,a);async function R(){L(!0),M(null),P("idle");try{const U=await F("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:b==="admin"||a?["admin","client"]:["client"]})});v(U),ne(Date.now())}catch(U){M(t("remote.serverPairing.error",{error:U instanceof Error?U.message:String(U)}))}finally{L(!1)}}async function E(U){M(null);try{await F(`/api/auth/sessions/${encodeURIComponent(U)}`,{method:"DELETE"}),await re()}catch(te){M(t("remote.serverPairing.error",{error:te instanceof Error?te.message:String(te)}))}}async function D(){if(!g?.url)return;const U=await wi(g.url);U!=="empty"&&P(U)}const Q=m&&g?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:oe?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:[g.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(es,{value:g.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:g.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:rn(g.expiresAt)}),g.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:g.url}),e.jsx("button",{type:"button",onClick:()=>{D()},className:ia,children:t(k==="copied"?"remote.serverPairing.copied":k==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:g.hint??t("remote.serverPairing.noLink")})]})]})}):null,le=U=>m&&!a&&h!==null?e.jsx(qm,{saved:h,onSaved:f,className:U}):null,ae=U=>t(U.scopes.includes("admin")?"remote.serverPairing.scope.admin":"remote.serverPairing.scope.client");return o?e.jsxs("div",{ref:V,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:O(ci,"flex flex-col"),children:[le("px-4 py-2.5"),e.jsx(ge,{title:t("settings.simple.computer.pair"),subtitle:m?a?t("remote.serverPairing.cloudPersonal"):void 0:t("remote.serverPairing.portal"),children:m?e.jsxs("div",{className:"flex items-center gap-2",children:[a?null:e.jsxs(ye,{variant:"ghost",value:b,"aria-label":t("remote.serverPairing.title"),onChange:U=>y(U.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:j,className:"ui-button",children:j?t("remote.serverPairing.creating"):t("settings.simple.computer.createCode")})]}):null}),Q?e.jsx("div",{className:"px-4 pb-2.5 [&>div]:mt-0",children:Q}):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(U=>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:[U.label,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ae(U)," · ",t("remote.serverPairing.seen",{when:Rs(U.lastSeenAt,se)}),U.id===N?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),U.id===N?null:e.jsx("button",{type:"button",onClick:()=>{E(U.id)},className:"ui-button ml-auto shrink-0",children:t("remote.serverPairing.signOut")})]},U.id))]}),S?e.jsx("p",{className:"pl-4 text-[12px] leading-4 text-danger",children:S}):null]}):e.jsx("div",{ref:V,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(m?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[m&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,le("mt-3"),m?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:j,className:Xm,children:j?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")}),Q,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(m?"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(U=>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:[U.label,U.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",U.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",U.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:Rs(U.lastSeenAt,se)}),U.id===N?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),U.id===N?null:e.jsx("button",{type:"button",onClick:()=>{E(U.id)},className:ia,children:t("remote.serverPairing.signOut")})]},U.id))}),S?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:S}):null]})})}const Qm="rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40";function Zm(s){return s?.on?s.origin?t(s.https?"devices.computers.https":"devices.computers.http",{address:s.origin}):t("devices.computers.waiting",{app:Se()}):null}function ex({c:s,state:n,blocked:a,simple:i}){const r=n.routes?.tailscale?.computers===!0,c=Zm(n.tailnetShare);return e.jsxs("div",{className:"flex flex-col gap-3 border-t border-hairline/30 pt-4","data-route-row":"tailscale-computers",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("devices.computers.title")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("devices.computers.detail")}),r&&c&&e.jsx("div",{"data-tailnet-share":!0,className:"mt-1 break-words text-[12px] leading-relaxed text-ink","aria-live":"polite",children:c})]}),e.jsx("button",{type:"button",className:Qm,disabled:s.busy||s.accountBusy||!!a&&!r,title:a??void 0,onClick:()=>{s.act(o=>o.setTailscaleComputers?.(!r)??o.state())},children:r?t("devices.route.turnOff"):t("devices.route.turnOn")})]}),r&&n.tailnetShare?.origin&&e.jsx(ur,{simple:i,reveal:!1})]})}const tx=s=>s.routes?Object.values(s.routes).some(n=>n.on):s.enabled;function sx(s){if(s.tailscaleProblem==="not-installed")return{kind:"not-installed",title:t("remote.tailscale.notInstalled"),detail:""};if(s.tailscaleProblem==="no-cli")return{kind:"signed-out",title:t("remote.tailscale.noCli"),detail:""};if(s.tailscaleProblem==="not-running")return{kind:"signed-out",title:t("remote.tailscale.notRunning"),detail:""};if(s.tailscaleProblem==="needs-permission")return{kind:"signed-out",title:t("remote.tailscale.needsPermission",{app:Se()}),detail:""};if(s.tailscaleProblem==="signed-out")return{kind:"signed-out",title:t("remote.tailscale.signIn"),detail:""};if(s.error)return{kind:"error",title:t("remote.status.attention"),detail:s.error};const n=s.routes?.tailscale;if(!n?.on)return{kind:"off",title:t("remote.status.off"),detail:""};if(!n.name)return{kind:"magicdns",title:t("remote.tailscale.magicDns"),detail:t("remote.tailscale.magicDnsDetail")};const a=t("remote.tailscale.ready",{name:n.name});return s.enabled?{kind:"ready",title:a,detail:t("remote.tailscale.readyDetail")}:{kind:"waiting",title:a,detail:t("remote.tailscale.linkOff")}}function $t(s,n){return s.setTailscale?s.setTailscale(n):n?s.refreshTailscale():s.state()}const nx={wifi:"remote.notice.wifi",relay:"remote.notice.relay",tailscale:"remote.notice.tailscale",https:"remote.notice.https"};function ra({c:s,notices:n}){return n.length===0?null:e.jsx("div",{className:"flex flex-col gap-2","data-route-notices":"",children:n.map(a=>e.jsxs("div",{role:"status","data-route-notice":a,className:"flex flex-wrap items-center justify-between gap-3 rounded-xl bg-inset px-3 py-2.5 text-[13px] text-ink",children:[e.jsx("span",{className:"min-w-0",children:t(nx[a])}),e.jsxs("span",{className:"flex shrink-0 gap-2",children:[e.jsx("button",{type:"button",disabled:s.busy,className:"rounded-lg border border-hairline/40 px-2.5 py-1 text-[12px] hover:bg-control disabled:opacity-40",onClick:()=>{s.act(i=>a==="tailscale"?$t(i,!1):i.setRoute?.(a,!1)??i.state())},children:t("remote.notice.turnOff")}),e.jsx("button",{type:"button",disabled:s.busy,className:"rounded-lg px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-40",onClick:()=>{s.act(i=>i.dismissNotice?.(a)??i.state())},children:t("common.ok")})]})]},a))})}function ax(s,n){return s?.paused===!0&&s.available&&n?.enabled===!0&&!n.error&&n.devices.length>0}const pr=s=>{const n=Math.round((Date.now()-s)/1e3);if(n<90)return t("remote.time.justNow");const a=Math.round(n/60);if(a<60)return t("remote.time.minutes",{count:a});const i=Math.round(a/60);return i<24?t("remote.time.hours",{count:i}):t("remote.time.days",{count:Math.round(i/24)})},ix=s=>{try{return new URL(s).host}catch{return s}},Kt={wifi:{name:"devices.route.wifi",detail:"devices.route.wifiDetail"},relay:{name:"devices.route.relay",detail:"devices.route.relayDetail"}},Fe="rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40";function mr(s,n){return s?.on?n===0?t("devices.route.waiting"):s.since?t("devices.route.onSince",{date:new Date(s.since).toLocaleDateString(void 0,{month:"short",day:"numeric"})}):t("devices.route.on"):t("devices.route.off")}function ln(s,n,a){return n==="tailscale"?$t(s,a):s.setRoute?.(n,a)??(a?s.start([n]):s.state())}function la({c:s,state:n,route:a,blocked:i}){const r=n.routes?.[a];return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3","data-route-row":a,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t(Kt[a].name,{app:Se()})}),e.jsxs("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:[mr(r,n.devices.length)," · ",t(Kt[a].detail,{app:Se()})]})]}),e.jsx("button",{type:"button",className:Fe,disabled:s.busy||!!i&&!r?.on,title:i??void 0,onClick:()=>{s.act(c=>ln(c,a,!r?.on))},children:r?.on?t("devices.route.turnOff"):t("devices.route.turnOn")})]})}const oa='button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])';function ca({c:s,state:n,onClose:a,secureAddress:i=!1}){const[r,c]=l.useState({wifi:!0,relay:!0}),o=["wifi","relay"],d=o.some(g=>n.routes?.[g]?.on)||n.routes?.tailscale?.on===!0,[u,p]=l.useState(d||i?"pairing":"consent"),{start:m}=s;l.useEffect(()=>{i&&m()},[i,m]);const x=o.filter(g=>r[g]),h=async()=>{for(const g of x)await s.act(v=>ln(v,g,!0));p("pairing"),s.useLocal()},f=u==="consent"?a:()=>{s.cancel(),a()},b=l.useRef(null);l.useEffect(()=>{const g=document.activeElement instanceof HTMLElement?document.activeElement:null,v=b.current;return v&&!v.contains(document.activeElement)&&v.querySelector(oa)?.focus(),()=>{g?.isConnected&&g.focus()}},[]),l.useEffect(()=>{const g=v=>{const C=b.current;if(!C||v.defaultPrevented||v.isComposing||v.key!=="Escape"&&v.key!=="Tab")return;if(v.preventDefault(),v.key==="Escape"){f();return}const w=[...C.querySelectorAll(oa)].filter(j=>j.getClientRects().length);if(!w.length)return;const N=w.indexOf(document.activeElement),I=N<0?v.shiftKey?-1:0:N+(v.shiftKey?-1:1);w.at(I%w.length).focus()};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[f]);const y=e.jsx("div",{ref:b,role:"dialog","aria-modal":"true","aria-label":u==="consent"?t("devices.pair.title"):t("devices.pair.titlePhone"),className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4","data-pair-dialog":u,children:e.jsxs("div",{className:"flex max-h-full w-full max-w-[460px] flex-col gap-4 overflow-y-auto rounded-2xl bg-card p-5 shadow-xl",children:[e.jsx("div",{className:"text-[15px] font-semibold text-ink",children:u==="consent"?t("devices.pair.title"):t("devices.pair.titlePhone")}),u==="consent"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2 text-[13px] text-ink",children:[e.jsx("div",{children:t("devices.pair.willTurnOn",{app:Se()})}),o.map(g=>e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",className:"mt-0.5",checked:r[g],onChange:v=>c(C=>({...C,[g]:v.target.checked}))}),e.jsxs("span",{children:[t(Kt[g].name,{app:Se()}),g==="relay"&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t(Kt.relay.detail,{app:Se()})})]})]},g)),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("devices.pair.changeLater")}),x.length===0&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("devices.pair.pickOne")})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:Fe,onClick:f,children:t("common.cancel")}),e.jsx("button",{type:"button",disabled:x.length===0||s.busy,onClick:()=>{h()},className:"rounded-lg bg-accent px-3 py-1.5 text-[12px] font-medium text-white disabled:opacity-40",children:t("devices.route.turnOn")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Dm,{controller:s}),e.jsx("div",{className:"text-[12px] leading-relaxed text-ink-secondary",children:xr(n)}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",className:Fe,onClick:f,children:t("devices.pair.done")})})]})]})});return e.jsx(Js,{modal:!0,children:y})}function rx({c:s,state:n}){const a=n.pairing;if(!a)return null;const i=new Date(a.expiresAt).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-hairline/40 bg-card px-3 py-2.5","data-open-code":"",children:[e.jsx("div",{className:"min-w-0 text-[13px] text-ink",children:t("devices.openCode",{until:i})}),e.jsx("button",{type:"button",className:Fe,disabled:s.busy,onClick:()=>{s.act(r=>r.pairing(!1,a.token))},children:t("devices.revoke")})]})}function xr(s){const n=i=>s.routes?.[i]?.on===!0,a=[n("wifi")&&t("devices.reach.wifi"),n("tailscale")&&t("devices.reach.tailscale"),n("https")&&t("devices.reach.https",{app:Se()}),n("relay")&&t("devices.reach.relay",{app:Se()})].filter(i=>!!i);return a.length===0?t("devices.reach.none"):t("devices.reach.line",{ways:new Intl.ListFormat(void 0,{type:"conjunction"}).format(a)})}function lx({profileEmail:s="",focusRequest:n=0,simple:a=!1}){const i=Mm(s),r=i.state,c=l.useRef(null),o=l.useRef(0),d=!!r,[u,p]=l.useState(!1),[m,x]=l.useState(!a);l.useEffect(()=>{n?o.current!==n&&Ii(c.current)&&(o.current=n):o.current=0},[n,d]);const h=l.useRef(!1),f=ax(i.account,r),{accountAct:b}=i;l.useEffect(()=>{!f||h.current||!Ze()?.prepare||(h.current=!0,b(S=>S.prepare?.()??S.state()))},[f,b]);const y=G().state.config?.managedPolicy,g=y?.remoteAccess===!1?t("policy.remoteBlocked",{organization:y.organizationName}):null,v=y?.remoteAccess===!1?t("policy.managedBy",{organization:y.organizationName}):null;if(!ct())return null;if(!r)return e.jsx(X,{title:t("devices.title"),subtitle:t("remote.checking"),children:e.jsx(q,{size:15,className:"animate-spin text-ink-secondary"})});const C=r.devices.length,w=dr(i.account,i.accountError),N=sx(r),I=r.routes?.tailscale?.on===!0,j=r.routes?.https?.on===!0,L=r.endpoints?.find(S=>S.kind==="hosted"),k=i.busy||g?void 0:()=>p("device"),P=S=>e.jsx("button",{type:"button",disabled:i.busy||!!g,title:v??void 0,onClick:()=>p("device"),className:"w-fit rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-40","data-pair-device":"",children:S});return a&&!m?e.jsxs("div",{className:"flex flex-col gap-3",ref:c,tabIndex:-1,"data-phone-pairing":"computer",children:[e.jsx(ra,{c:i,notices:r.notices??[]}),C===0?e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border border-hairline/40 bg-card px-4 py-3",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("devices.simple.setUpTitle",{app:Se()})}),e.jsx("button",{type:"button",className:Fe,disabled:i.busy||!!g,onClick:()=>p("device"),children:t("devices.simple.setUp")})]}):e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-hairline/40 bg-card px-4 py-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("devices.simple.yourPhone")}),e.jsx(na,{c:i,state:r,onPairAgain:k}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[xr(r)," ",e.jsx("button",{type:"button",className:"text-accent hover:underline",onClick:()=>x(!0),children:t("devices.change")})]}),P(t("devices.pairAnother"))]}),u&&e.jsx(ca,{c:i,state:r,onClose:()=>p(!1)})]}):e.jsxs("div",{className:"flex flex-col gap-4",ref:c,tabIndex:-1,"data-phone-pairing":"computer",children:[g&&e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink-secondary",children:g}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("devices.intro")}),P(t("devices.pair")),e.jsx(ra,{c:i,notices:r.notices??[]}),u&&e.jsx(ca,{c:i,state:r,onClose:()=>p(!1),secureAddress:u==="https"}),e.jsxs("section",{className:"flex flex-col gap-2","data-devices-block":"paired",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("devices.paired")}),co(i.account,r)&&e.jsx("p",{role:"status","data-devices-notice":"tunnel-retired",className:"rounded-xl bg-inset px-3 py-2.5 text-[13px] leading-relaxed text-ink",children:t("remote.devices.retiredNotice")}),e.jsx(rx,{c:i,state:r}),C?e.jsx(na,{c:i,state:r,onPairAgain:k}):!r.pairing&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("devices.pairedNone")}),e.jsx(Um,{})]}),e.jsxs("section",{className:"flex flex-col rounded-xl border border-hairline/40 bg-card px-4","data-devices-block":"routes",children:[e.jsx("div",{className:"pt-3 text-[13px] font-medium text-ink",children:t("devices.howTheyReach")}),e.jsx(la,{c:i,state:r,route:"wifi",blocked:v}),e.jsx("div",{className:"border-t border-hairline/30",children:e.jsx(la,{c:i,state:r,route:"relay",blocked:v})}),e.jsxs("details",{className:"border-t border-hairline/30 py-3",open:I||j||void 0,children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink",children:t("devices.moreWays")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-4","data-route-row":"tailscale",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:"Tailscale"}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("remote.tailscaleSwitch.detail",{app:Se()})})]}),e.jsx("button",{type:"button",className:Fe,disabled:i.busy||i.accountBusy||!!v&&!I,onClick:()=>{i.act(S=>$t(S,!I))},children:I?t("devices.route.turnOff"):t("devices.route.turnOn")})]}),N.kind!=="off"&&e.jsxs("div",{"data-tailscale-status":N.kind,className:"rounded-xl bg-inset px-3 py-3","aria-live":"polite",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Ws,{size:16,className:`mt-0.5 shrink-0 ${N.kind==="ready"?"text-success":"text-ink-secondary"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:N.title}),N.detail&&e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:N.detail})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[I&&N.kind!=="error"&&e.jsx("button",{type:"button",className:Fe,disabled:i.busy||i.accountBusy,onClick:i.refreshTailscale,children:i.busy?t("common.checking"):t("remote.checkAgain")}),N.kind==="not-installed"&&e.jsx("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",className:Fe,children:t("remote.tailscale.getIt")}),N.kind==="signed-out"&&e.jsx("button",{type:"button",className:Fe,disabled:i.busy||i.accountBusy,onClick:()=>{i.act(S=>$t(S,!0))},children:t("common.tryAgain")})]})]}),I&&r.routes?.tailscale?.name&&e.jsx(ex,{c:i,state:r,blocked:v,simple:a}),e.jsxs("div",{className:"flex items-start justify-between gap-4 border-t border-hairline/30 pt-4","data-route-row":"https",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("devices.route.https")}),e.jsxs("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:[j&&L?t("devices.route.httpsOn",{address:ix(L.url)}):mr(r.routes?.https,C)," · ",t("devices.route.httpsDetail",{app:Se()})]}),i.account?.status==="ready"&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("remote.account.signedIn",{email:i.account.email??t("remote.account.yourAccount")})}),w&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:w})]}),j?e.jsx("button",{type:"button",className:Fe,disabled:i.busy,onClick:()=>{i.act(S=>ln(S,"https",!1))},children:t("devices.route.turnOff")}):e.jsx("button",{type:"button",className:Fe,disabled:i.busy||i.accountBusy||!!v,onClick:()=>p("https"),children:t("devices.route.setUp")})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.keepAwake")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("remote.keepAwakeDetail")})]}),e.jsx(be,{checked:r.keepAwake,"aria-label":t("remote.keepAwakeAria"),disabled:i.busy||!tx(r),onClick:()=>{i.act(S=>S.keepAwake(!r.keepAwake))}})]}),a&&e.jsx("button",{type:"button",className:"w-fit text-[12px] text-accent hover:underline",onClick:()=>x(!1),children:t("devices.done")}),(i.error||r.error)&&e.jsx("div",{className:"text-[12px] text-danger",children:i.error??r.error})]})}function ox(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 da(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 cx(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function ua(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function dx(s,n,a){const i=[],r=new Set,c=(o,d)=>{const u=o.trim().toLowerCase();if(!u||r.has(u))return;r.add(u);const p=n.filter(x=>x.email?.toLowerCase()===u),m=a.find(x=>x.key===`user:${u}`);i.push({entry:u,role:d,isDomain:u.startsWith("@"),lastSeenAt:p.length?Math.max(...p.map(x=>x.lastSeenAt)):null,devices:p.length,turns:m?.turns??0,costUsd:m?.costUsd??null,...yt(m?.estimatedUsd)&&m.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 ux(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 px(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 hr({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:O(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:O(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:O("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?"—":px(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:yt(d.costUsd)?`${d.estimated?"~":""}${vt(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(uo,{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 gr({link:s}){const{state:n,copy:a}=Qt(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(ve,{size:13,className:"text-success"}):n==="failed"?e.jsx(We,{size:13,className:"text-danger"}):e.jsx(qs,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function mx({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(Nt,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(hr,{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 fr({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[u,p]=l.useState(null),[m,x]=l.useState(null),[h,f]=l.useState([]),[b,y]=l.useState(typeof window<"u"?window.location.origin:""),[g,v]=l.useState(null),[C,w]=l.useState(""),[N,I]=l.useState("member"),[j,L]=l.useState(null),[k,P]=l.useState(!1),[S,M]=l.useState(!1),[se,ne]=l.useState(null),V=l.useCallback(async()=>{M(!0),ne(null);try{const[R,E,D,Q,le]=await Promise.all([F("/api/config"),F("/api/auth/sessions").catch(()=>({sessions:[]})),F("/api/usage?groupBy=user").catch(()=>({groups:[]})),F("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(ce=>ce.ok?ce.json():null).catch(()=>null)]),ae={admins:Array.isArray(R?.signIn?.admins)?R.signIn.admins:[],members:Array.isArray(R?.signIn?.members)?R.signIn.members:[]},U=Pi(R);p(U),x(ae);const te=Array.isArray(E?.sessions)?E.sessions:[],me=Array.isArray(D?.groups)?D.groups:[];f(U.authority==="portal"?ux(te,me):dx(ae,te,me)),typeof Q?.publicUrl=="string"&&Q.publicUrl&&y(Q.publicUrl),v(le?.capabilities?.emailSignIn===!0?!0:le?!1:null)}catch(R){ne(R instanceof Error?R.message:String(R))}finally{M(!1)}},[]);l.useEffect(()=>{Ai().then(R=>{d(R),bt(R)&&V()})},[V]);const ie=async R=>{P(!0),ne(null);try{await F("/api/config",{method:"PUT",body:JSON.stringify({signIn:R})}),await V()}catch(E){ne(E instanceof Error?E.message:String(E))}finally{P(!1)}},re=async()=>{if(c(!0),!m||k)return;const R=ox(C);if(!R){ne(t("remote.signInAccess.invalid"));return}await ie(da(m,R,N)),w(""),L(ua(b,R))};if(!bt(o))return null;const oe=u?.authority==="portal"?e.jsx(mx,{peopleUrl:u.peopleUrl,people:h}):null,T=e.jsxs(e.Fragment,{children:[g===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(u?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:R=>{R.preventDefault(),re()},children:[e.jsx("input",{value:C,onChange:R=>w(R.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:k,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(ye,{value:N,onChange:R=>I(R.target.value),"aria-label":t("people.colRole"),disabled:k,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:k||!C.trim(),className:"ui-button ui-button-primary",children:[k?e.jsx(q,{size:13,className:"animate-spin"}):e.jsx(Oe,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{V()},disabled:S||k,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(De,{size:13,className:O(S&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),j&&e.jsx(gr,{link:j}),se&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:se}),e.jsx("div",{className:"mt-4",children:e.jsx(hr,{people:h,busy:k,onRole:(R,E)=>{m&&ie(da(m,R.entry,E))},onRemove:R=>{m&&ie(cx(m,R.entry))},onLink:R=>L(ua(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(Ut,{size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("people.title")}),e.jsx("div",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.people")})]}),e.jsx("button",{type:"button","aria-expanded":a,className:"ui-button shrink-0",onClick:()=>i(!a),children:a?t("common.done"):t("settings.simple.people.invite")})]}),a&&e.jsx("div",{className:"px-3.5 pb-3.5 pt-1",children:oe??T})]}):oe??e.jsx(X,{title:t("people.title"),subtitle:t("people.subtitle"),children:T})}const ks="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 xx({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(Us())}),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:Dd(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:Ud(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:po(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(Ys,{size:12,className:O("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:Dn(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Dn(s.after?.[r])})]},r))]})]})]})})}function br(){const[s,n]=l.useState({who:"",what:"all",from:"",to:""}),[a,i]=l.useState([]),[r,c]=l.useState(0),[o,d]=l.useState(null),[u,p]=l.useState(!1),[m,x]=l.useState(null),h=Md(s),f=l.useCallback(async()=>{p(!0),x(null);try{const y=await F(`/api/admin-activity${h}`);i(y.entries),c(y.total),d(y.retentionDays)}catch(y){x(y instanceof Error?y.message:String(y))}finally{p(!1)}},[h]);l.useEffect(()=>{const y=window.setTimeout(()=>{f()},250);return()=>window.clearTimeout(y)},[f]);const b=y=>n(g=>({...g,...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:O(ks,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(ye,{value:s.what,onChange:y=>b({what:y.target.value}),children:Fd.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:ks})]}),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:ks})]}),e.jsx("button",{type:"button",onClick:()=>{f()},disabled:u,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:u?e.jsx(q,{size:14,className:"animate-spin"}):e.jsx(De,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${h}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Gs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:m})}),!m&&a.length===0&&!u&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((y,g)=>e.jsx(xx,{entry:y},`${y.at}-${g}`))}),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 pa=4,on="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",cn="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",hx=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),yr=(s,n)=>Jt(s)===n||pi(Yt(s),n)!=="none",vr=(s,n)=>{const a=di(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},ma=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function gx(){const{state:s}=G(),n=mo(),a=xo(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[u,p]=l.useState(null),[m,x]=l.useState(null),h=l.useRef(null),[f,b]=l.useState(null),[y,g]=l.useState(""),v=l.useCallback(()=>b(null),[]);if(l.useEffect(()=>{m||!h.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(k=>k.dataset.accessPerson===h.current)?.focus(),h.current=null)},[m]),!n||!a)return null;const C=n.people.filter(k=>k.role==="member").sort((k,P)=>k.name.localeCompare(P.name)),w=hx(s.bots),N=u?w.find(k=>k.id===u):void 0,I=m?C.find(k=>k.email===m):void 0,j=o.trim().toLowerCase(),L=async(k,P,S)=>{g("");const M=Yt(k);try{await En(k.id,P),b({botId:k.id,before:M,after:P,text:S})}catch(se){g(se instanceof Error?se.message:String(se))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[I?e.jsx(vx,{person:I,bots:w.filter(k=>yr(k,I.email)),team:n,teamName:a,apply:L,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(jt,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value: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:k=>d(k.target.value),onKeyDown:k=>{k.key==="Escape"&&o&&(k.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(k=>e.jsx("button",{type:"button","aria-pressed":r===k,"data-access-listing":k,onClick:()=>{c(k),d("")},className:O("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===k?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(k==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},k))})]}),r==="bot"?e.jsx(fx,{bots:w.filter(k=>!j||ma(j,k.name,di(k,n)?.name,Jt(k)??void 0)),anyBots:w.length>0,team:n,onOpen:p}):e.jsx(yx,{people:C.filter(k=>!j||ma(j,k.name,k.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}),N&&e.jsx(ho,{bot:N,teamName:a,onClose:()=>p(null),onChanged:k=>b({botId:N.id,...k})}),f&&e.jsx(go,{text:f.text,onUndo:()=>En(f.botId,f.before),onDone:v},`${f.botId}:${f.text}:${JSON.stringify(f.after)}`)]})}function fx({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:cn,children:s.map(r=>{const c=Yt(r),o=Jt(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:O(on,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Zt,{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:vr(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(bx,{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 bx({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>bo(r,n)).join(", "),i=s.length-pa;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,pa).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(yo,{person:vo(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 yx({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:cn,children:s.map(r=>{const c=a.filter(o=>yr(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:O(on,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(ui,{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 vx({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(rl,{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(ui,{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:cn,children:n.map(o=>e.jsx(kx,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function kx({bot:s,person:n,team:a,teamName:i,apply:r}){const c=Yt(s),o=Jt(s)===n.email,d=c.people[n.email],u=pi(c,n.email);return e.jsxs("li",{className:on,"data-access-person-bot":s.id,children:[e.jsx(Zt,{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&&u===c.everyone?t("botAccess.everyoneUse",{team:i}):vr(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,fo(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 jx(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 Nx({domain:s,serverIpv4:n}){const a=jx(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(gt,{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 wx(s){return`bots.example.com {
|
|
2
|
+
handle /hooks/* {
|
|
3
|
+
reverse_proxy 127.0.0.1:${s.webhookPort}
|
|
4
|
+
}
|
|
5
|
+
handle {
|
|
6
|
+
reverse_proxy 127.0.0.1:${s.appPort} {
|
|
7
|
+
flush_interval -1
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}`}function Sx({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:wx(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/milind-soni/OpenMausBot/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings",target:"_blank",rel:"noopener noreferrer",children:[t("settings.domain.fullGuide")," ",e.jsx(Nt,{size:12})]})]})}function Cx(){const[s,n]=l.useState(null),[a,i]=l.useState(""),[r,c]=l.useState("loading"),[o,d]=l.useState(null),[u,p]=l.useState(null);l.useEffect(()=>{const x=new AbortController;return F("/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 m=async x=>{c(x?"removing":"saving"),d(null),p(null);try{const h=await F("/api/settings/custom-domain",{method:x?"DELETE":"POST",...x?{}:{body:JSON.stringify({domain:a.trim()})}});n(h),i(h.customDomain??""),p(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(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(q,{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&&m(!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),p(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(Nx,{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(q,{size:14,className:"animate-spin"}):e.jsx(ko,{size:14}),r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{m(!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(Sx,{status:s})]}),u&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(ve,{size:14,className:"mt-0.5 shrink-0"}),u]}),o&&e.jsx("p",{role:"alert",className:"text-[12px] leading-relaxed text-danger",children:o})]})})}const Ex=jo,Ts="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",Bs="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function kr({onSubmit:s,onCancel:n,pending:a,error:i,submitLabel:r,children:c,form: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(Xt,{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(q,{size:13,className:"animate-spin"}),r]})]})]})}function xa({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=l.useState(s?.name??""),[o,d]=l.useState(""),[u,p]=l.useState(s?.bots??"all"),[m,x]=l.useState(!1),[h,f]=l.useState(null),b=async y=>{if(y.preventDefault(),!m){x(!0),f(null);try{s?await No(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:o,bots:u}):await wo(r.trim(),o,u),d(""),await i()}catch(g){f(g instanceof Error&&g.message?g.message:t("settings.vault.secret.saveError"))}finally{x(!1)}}};return e.jsxs(kr,{form:"secret-form",onSubmit:y=>{b(y)},onCancel:a,pending:m,error:h,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:Bs,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:Ex,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:y=>c(y.target.value),disabled:m,className:Ts}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:Bs,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:m,className:Ts})]}),e.jsx(kt,{value:u,onChange:p,bots:n,disabled:m})]})}function Ax({bots:s,onCancel:n,onSaved:a}){const[i,r]=l.useState(""),[c,o]=l.useState("all"),[d,u]=l.useState(!1),[p,m]=l.useState(null),[x,h]=l.useState(null),f=async b=>{if(b.preventDefault(),d)return;const y=So(i);if(!y.length){m(t("settings.vault.env.none"));return}u(!0),m(null),h(null);try{h(await Co(y,c)),r("")}catch(g){m(g instanceof Error&&g.message?g.message:t("settings.vault.secret.saveError"))}finally{u(!1),await a().catch(()=>{})}};return e.jsxs(kr,{form:"env-form",onSubmit:b=>{f(b)},onCancel:n,pending:d,error:p,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:Bs,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:`${Ts} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(kt,{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 ha={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",linked:"settings.logins.source.1password"},Ls="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",Px=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function Ix(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 jr(){const{state:s,dispatch:n}=G(),a=Gt(),i=s.bots.map(A=>({id:A.id,name:A.name})),[r,c]=l.useState(null),[o,d]=l.useState([]),[u,p]=l.useState({connected:!1}),[m,x]=l.useState(null),[h,f]=l.useState(""),[b,y]=l.useState("all"),[g,v]=l.useState(!1),[C,w]=l.useState(null),[N,I]=l.useState(""),[j,L]=l.useState("all"),[k,P]=l.useState(!1),[S,M]=l.useState(null),[se,ne]=l.useState("all"),[V,ie]=l.useState(!1),[re,oe]=l.useState(!1),[T,R]=l.useState(null),[E,D]=l.useState(!1),[Q,le]=l.useState([]),ae=async()=>{try{const A=await Po();c(A.logins??[]),d(A.secrets??[]),p(A.onePassword??{connected:!1}),x(null)}catch(A){x(A instanceof Error&&A.message?A.message:t("settings.vault.loadError"))}};if(l.useEffect(()=>{a&&ae()},[a]),a===!1)return e.jsx(X,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const U=A=>{if(A==="all")return t("settings.logins.allBots");const H=A.flatMap(he=>i.find(W=>W.id===he)?.name??[]);return H.length?H.join(", "):t("settings.logins.noBots")},te=A=>A?t("settings.logins.used",{when:zd(A)}):t("settings.logins.neverUsed"),me=(A,H)=>{w(null),R(null),oe(!1),H&&(ne(H.bots),ie(H.exactHost)),M(A)},ce=A=>{v(!1),M(null),R(null),w(A)},xe=async(A,H)=>{if(T!==A){R(A);return}D(!0),le([]);try{H==="login"?await To(A):le(await Bo(A)),R(null),await ae()}catch(he){x(he instanceof Error&&he.message?he.message:t("settings.logins.deleteError"))}finally{D(!1)}},de=(A,H,he,W)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx("button",{type:"button",className:Ls,disabled:E,onClick:W,"aria-label":H==="login"?t("settings.logins.changeFor",{site:he}):t("settings.vault.secret.changeFor",{name:he}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:Ls,disabled:E,onClick:()=>{xe(A,H)},"aria-label":T===A?t("settings.logins.deleteConfirm"):H==="login"?t("settings.logins.deleteFor",{site:he}):t("settings.vault.secret.deleteFor",{name:he}),children:[e.jsx(Le,{size:13}),T===A?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),je=Ix(r??[],o,b,h),_=r!==null&&r.length===0&&o.length===0,pe=A=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":A.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Xt,{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:A.site,children:A.site}),A.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(Ws,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:A.username||t("settings.logins.noUsername")}),ga(A)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:ga(A)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(ha[A.source]),U(A.bots),te(A.lastUsedAt)].join(" · ")}),Pn(A,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:U(Pn(A,s.bots))})})]}),A.source!=="1password"&&de(A.id,"login",A.site,()=>me(A.id,A))]}),S===A.id&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(An,{username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>M(null),onSubmit:async H=>{await Io(A.id,{password:H.password,totp:H.totp,removeTotp:re,bots:se,...V===A.exactHost?{}:{exactHost:V}}),M(null),await ae()},children:[A.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:re,onChange:H=>oe(H.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(fa,{checked:V,onChange:ie,label:t("settings.logins.exactHostFor",{hosts:A.hosts.join(", "),site:A.site})}),e.jsx(kt,{value:se,onChange:ne,bots:i})]})})]},A.id),B=A=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":A.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(mi,{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:A.name,children:A.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(ha[A.source]),U(A.bots),te(A.lastUsedAt)].join(" · ")})]}),A.source!=="linked"&&de(A.id,"secret",A.name,()=>me(A.id))]}),S===A.id&&A.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx(xa,{secret:A,bots:i,onCancel:()=>M(null),onSaved:async()=>{M(null),await ae()}})})]},A.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||E,"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(jt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-vault-search":!0,type:"text",value:h,onChange:A=>f(A.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":g,onClick:()=>v(!g),onKeyDown:A=>{A.key==="Escape"&&v(!1)},children:[e.jsx(Oe,{size:14}),t("settings.vault.add"),e.jsx(Ja,{size:13,"aria-hidden":"true"})]}),g&&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:Px.map(([A,H])=>e.jsx("button",{type:"button",className:"rounded-md px-2.5 py-1.5 text-start text-[13px] text-ink hover:bg-control",onClick:()=>ce(A),children:t(H)},A))})]})]}),e.jsx(Eo,{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(An,{site:{value:N,onChange:I},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>w(null),onSubmit:async A=>{await Ao(N,A,j,k),w(null),I(""),L("all"),P(!1),await ae()},children:[e.jsx(fa,{checked:k,onChange:P,label:t("settings.logins.exactHost")}),e.jsx(kt,{value:j,onChange:L,bots:i})]})}),C==="secret"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(xa,{bots:i,onCancel:()=>w(null),onSaved:async()=>{w(null),await ae()}})}),C==="env"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(Ax,{bots:i,onCancel:()=>w(null),onSaved:ae})}),r===null&&!m&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.vault.loading")}),_&&!C&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.vault.empty")}),!_&&r!==null&&je.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary","data-vault-none":!0,children:t("settings.vault.noMatch")}),je.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/30","data-logins-list":!0,children:je.map(A=>A.kind==="login"?pe(A.login):B(A.secret))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-tertiary",children:t("settings.logins.limits")}),Q.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:Q.join(", ")})}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),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(Tx,{status:u,disabled:r===null,bots:i,botNames:U,onChange:async A=>{p(A),await ae()}})]})})}function ga(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 fa({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 Rx({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,o]=l.useState(!1),[d,u]=l.useState(s.bots),[p,m]=l.useState(!1),[x,h]=l.useState(null),f=async()=>{m(!0),h(null);try{await r(await Lo(s.id,d)),o(!1)}catch(b){h(b instanceof Error&&b.message?b.message:t("settings.logins.onePassword.error"))}finally{m(!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:Ls,disabled:i||p,onClick:()=>{u(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(kt,{value:d,onChange:u,bots:n,disabled:p}),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:p,onClick:()=>o(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:p,onClick:()=>{f()},children:t("settings.logins.saveChange")})]})]})]})}function Tx({status:s,disabled:n,bots:a,botNames:i,onChange:r}){const[c,o]=l.useState(""),[d,u]=l.useState(null),[p,m]=l.useState(null),x=async(f,b)=>{if(!d){u(f),m(null);try{await r(await b()),f==="connect"&&o("")}catch(y){m(y instanceof Error&&y.message?y.message:t("settings.logins.onePassword.error"))}finally{u(null)}}},h=f=>{f.preventDefault(),c.trim()&&x("connect",()=>Ro(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(f=>f.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(f=>e.jsx(Rx,{vault:f,bots:a,botNames:i,disabled:n,onChange:r},f.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",Oo)},children:[d==="refresh"?e.jsx(q,{size:13,className:"animate-spin"}):e.jsx(De,{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",zo)},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:f=>o(f.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(q,{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(Xt,{size:11,"aria-hidden":"true",className:"mt-[3px] shrink-0"})," ",t("settings.logins.onePassword.note")]}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p})]})}const js="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 ba(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Bx(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=ll(n);return a.ok&&(a.code!==null||a.credential!==null)}function Lx({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"),[u,p]=l.useState(""),[m,x]=l.useState(""),[h,f]=l.useState(""),[b,y]=l.useState(!1),[g,v]=l.useState(""),C=l.useRef(!1),w=!!i&&o==="server",N=l.useRef(!0),I=l.useCallback(()=>{a?.state().then(k=>{N.current&&c(k)}).catch(()=>{})},[a]);l.useEffect(()=>(N.current=!0,I(),()=>{N.current=!1}),[I]);const j=async()=>{if(!(C.current||!a&&!i)){C.current=!0,y(!0),v("");try{if(w&&i){if(!Bx(u))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(u.trim()),I()}else a&&(await a.pair(m,h),I())}catch(k){v(ba(k))}finally{C.current=!1,y(!1)}}},L=async()=>{if(!(!a||C.current)){C.current=!0,y(!0),v("");try{await a.disconnect(),I()}catch(k){v(ba(k))}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(Dt,{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:()=>{L()},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(q,{size:14,className:"animate-spin"}):e.jsx(cu,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:k=>{k.preventDefault(),j()},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(ye,{value:o,disabled:b,onChange:k=>{d(k.target.value),v("")},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:u,onChange:k=>p(k.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:b,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:js})]}),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:m,onChange:k=>x(k.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:b,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:js})]}),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:k=>f(k.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:b,inputMode:"numeric",autoComplete:"one-time-code",className:`${js} max-w-40 font-mono tracking-[0.2em]`})]})]}),g?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:g}):null,e.jsxs("button",{type:"submit",disabled:b||(w?!u.trim():m.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(q,{size:14,className:"animate-spin"}):e.jsx(Dt,{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&&g?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:g}):null]})}const Ox={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 zx({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(Us())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(Ox[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 Mx({workspace:s,own:n=!1,onClose:a}){const{state:i}=G(),c=n||xi(i.config)?window.ogb?.computerSharing:void 0,[o,d]=l.useState(null),[u,p]=l.useState([]),[m,x]=l.useState(!1),[h,f]=l.useState(!1),[b,y]=l.useState(!1),[g,v]=l.useState(""),[C,w]=l.useState(null),N=l.useRef(!1),I=l.useRef(!1),j=l.useRef(null),L=P=>{d(P),p(P.folders),x(P.terminal),f(P.computer)};l.useEffect(()=>{N.current=!0,j.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(M=>{N.current&&L(M)}).catch(()=>{N.current&&v(t("computerSharing.loadFailed"))});const P=()=>{c?.state(s.id).then(M=>{N.current&&d(M)}).catch(()=>{}),c?.activity?.(s.id).then(M=>{N.current&&w(M)}).catch(()=>{})};P();const S=setInterval(P,3e3);return()=>{N.current=!1,clearInterval(S)}},[c,s.id]);const k=async P=>{if(!I.current){I.current=!0,y(!0),v("");try{await P()}catch(S){N.current&&v(String(S?.message??S).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{I.current=!1,N.current&&y(!1)}}};return c?e.jsx("div",{ref:j,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(We,{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:()=>{k(async()=>{await(o.paused?c.resume?.():c.pause?.());const P=await c.state(s.id);N.current&&d(P)})},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")}),u.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.noFolders")}),u.map(P=>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:P.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:P.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:P.write,onChange:S=>p(M=>M.map(se=>se.id===P.id?{...se,write:S.target.checked}:se))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:P.name}),onClick:()=>p(S=>S.filter(M=>M.id!==P.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(We,{size:14})})]},P.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{k(async()=>{const P=await c.chooseFolder();N.current&&P&&p(S=>S.some(M=>M.path===P.path)?S:[...S,P])})},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(Mo,{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:m,onChange:P=>x(P.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:P=>f(P.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")})]})]})]}),(g||o?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:g||o?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:b||!o||!u.length&&!m&&!h,onClick:()=>{k(async()=>{const P=await c.save(s.id,{folders:u,terminal:m,computer:h});N.current&&P&&L(P)})},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:()=>{k(async()=>{const P=await c.revoke(s.id);N.current&&L(P)})},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(zx,{entries:C})})]})})}):null}const Fx={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},Bt=s=>s.kind!=="local"&&!!s.origin&&!s.home&&!s.cloud&&!("team"in s&&s.team),Dx=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function Ux(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 _x({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=Qt(Ux(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(We,{size:13})})]})}function $x({origin:s,name:n}){const{state:a,copy:i}=Qt(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(ve,{size:14}):e.jsx(qs,{size:14})})}function Kx({status:s,onTryNow:n,onPairAgain:a,onEdit:i}){if(!s||s.state==="connected")return null;const r=(d,u)=>e.jsx("button",{type:"button",onClick:u,className:"ml-2 font-medium text-accent-text hover:underline",children:d}),c=s.state==="checking"?t("servers.state.checking"):s.state==="reconnecting"?t("servers.state.reconnecting"):s.state==="cantReach"?t("servers.state.cantReach",{time:Dx(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 Hx({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(be,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function Wx({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:o,onComputerAccess:d,onShare:u=()=>{}}){const p=window.ogb?.environments,[m,x]=l.useState([]),[h,f]=l.useState([]),[b,y]=l.useState(null);l.useEffect(()=>{if(!p?.status)return;let N=!0;const I=()=>{p.status().then(L=>{N&&x(L)}).catch(()=>{})};I();const j=p.onStatus?.(I);return()=>{N=!1,j?.()}},[p,s]);const g=N=>m.find(I=>I.id===N),v=N=>y({address:N.origin,locked:!0,title:t("servers.pairAgainTitle",{name:N.name})}),C=N=>y({address:N.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),w=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(N=>N.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:w.map(N=>{const I=N.id===s.activeId,j=Bt(N)?g(N.id):void 0,L=N.id==="local"?Dt:Ds,k=N.id==="local"?t("servers.localHint"):Bt(N)?`${new URL(N.origin).host} · ${t(Fx[ol(N.origin)])}`:N.home?t("servers.managed"):new URL(N.origin).host,P=i.find(M=>M.id===N.id),S=j?.behind===!0&&r!==null&&!h.includes(`${N.id}:${j.version}`);return e.jsxs("li",{"data-server-row":N.id,className:"py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[cl(N.color)?e.jsx(dl,{color:N.color,size:20}):e.jsx(L,{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:N.name}),e.jsx("div",{"data-server-where":!0,className:"break-all text-[12px] text-ink-secondary",children:k}),e.jsx(Kx,{status:j,onTryNow:()=>{p?.retry?.(N.id)},onPairAgain:()=>v(N),onEdit:()=>C(N)})]}),I?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ve,{size:13}),t("servers.current")]}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:N.name}),onClick:()=>c(N.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.switch")}),Bt(N)&&j?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>v(N),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.pairAgain")}),N.id!=="local"&&!N.home&&!N.cloud&&!P&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:N.name}),onClick:()=>d(N.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("servers.computerAccess")}),Bt(N)&&e.jsx($x,{origin:N.origin,name:N.name}),N.id!=="local"&&!N.home&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.removeName",{name:N.name}),title:t("servers.removeName",{name:N.name}),onClick:()=>o(N.id),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Le,{size:14})})]}),P&&e.jsx(Hx,{name:N.name,share:P,busy:n,onShare:M=>u(N.id,M),onOpen:()=>d(N.id)}),S&&e.jsx(_x,{name:N.name,status:j,appVersion:r,onHide:()=>f(M=>[...M,`${N.id}:${j.version}`])})]},N.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(Oe,{size:14}),t("connect.title")]}),b&&e.jsx(ud,{focusKey:b.locked?"pair-again":"connect",onClose:()=>y(null),children:e.jsx(pd,{onBack:null,onConnected:()=>y(null),start:b})})]})}function ya(){const s=window.ogb?.environments,{state:n}=G(),a=xi(n.config)&&!!window.ogb?.computerSharing,i=window.ogb?.computerSharing,[r,c]=l.useState([]),[o,d]=l.useState(null),[u,p]=l.useState(!1),[m,x]=l.useState(""),[h,f]=l.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[b,y]=l.useState(""),[g,v]=l.useState(""),[C,w]=l.useState(null),[N,I]=l.useState(!1),[j,L]=l.useState(""),k=l.useRef(!1),P=l.useRef(0);l.useEffect(()=>{const T=++P.current;return s?.state().then(R=>{P.current===T&&d(R)}).catch(()=>{P.current===T&&x(t("servers.loadFailed"))}),()=>{P.current++}},[s]),l.useEffect(()=>{if(!i?.servers||!o)return;let T=!0;const R=()=>{i.servers().then(D=>{T&&c(D)}).catch(()=>{})};R();const E=setInterval(R,5e3);return()=>{T=!1,clearInterval(E)}},[i,o]);const S=(T,R)=>{M(async()=>{R?await i?.allow?.(T)&&f(T):await i?.revoke(T),i?.servers&&c(await i.servers())})};l.useEffect(()=>{const T=R=>{R&&f(R);const E=new URL(window.location.href);E.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${E.pathname}${E.search}${E.hash}`)};return T(),s?.onOpenSettings?.(T)},[s]);const M=async(T,R=x)=>{if(k.current||!s)return;k.current=!0,p(!0),x(""),L("");const E=P.current;try{if(await T()===!0)return;const D=await s.state();P.current===E&&d(D)}catch(D){P.current===E&&R(String(D?.message??D).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{k.current=!1,P.current===E&&p(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const se=T=>window.ogb?.confirm?window.ogb.confirm(T):window.confirm(T),ne=o?.environments.find(T=>T.id===h),V=ne?.origin&&!ne.home?{id:ne.id,name:ne.name,origin:ne.origin}:void 0,ie=!!(V&&r.some(T=>T.id===V.id)),re=o?.environments.filter(T=>T.kind==="local")??[],oe=re.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:[j&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:j}),re.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:re.map(T=>{const R=T.id===o.activeId;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(Dt,{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(ve,{size:13}),t("connectedWorkspaces.current")]}):e.jsx("button",{type:"button",disabled:u,"aria-label":t("connectedWorkspaces.switchTo",{name:T.name}),onClick:()=>{M(async()=>{if(!await se(t("connectedWorkspaces.switchConfirm",{name:T.name})))return;const E=await s.switch(T.id);if(E&&E.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},L)},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:u,"aria-label":t("connectedWorkspaces.forgetName",{name:T.name}),title:t("connectedWorkspaces.forgetName",{name:T.name}),onClick:()=>{w(T.id),I(!1)},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Le,{size:14})})]},T.id)})}),oe&&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:N,disabled:u,className:"mt-0.5",onChange:T=>I(T.target.checked)}),t("connectedWorkspaces.forgetPurge",{path:oe.dataDir??""})]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",disabled:u,onClick:()=>{M(async()=>{const T=N?await s.forget(oe.id,!0):await s.forget(oe.id);if(T&&T.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));w(null)},L)},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()&&M(async()=>{if(!(await s.create(b.trim(),g.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));y(""),v("")},L)},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:u,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:g,disabled:u,onChange:T=>v(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:u,onClick:()=>{M(async()=>{const T=await s.pickDir();T?.ok&&T.path&&v(T.path)},L)},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:u||!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:[u&&e.jsx(q,{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(Wx,{saved:o,busy:u,sharingOffered:a,ownServers:r,appVersion:window.ogb?.app?.version??null,onShare:S,onSwitch:T=>{M(async()=>(await s.switch(T),!0))},onForget:T=>{M(()=>s.forget(T))},onComputerAccess:f}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t(m?"servers.yours.loadFailed":"servers.yours.loading")}),o&&m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]}),(a||ie)&&V&&e.jsx(Mx,{workspace:V,own:ie,onClose:()=>f(null)},V.id)]})}const Gx={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function Vx({banner:s,canChange:n,subtitle:a}){const i=l.useRef(null),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=Fo(s),p=async h=>{c(!0),d(null);const f=await Promise.resolve().then(h).catch(()=>({ok:!1,problem:"failed"}));c(!1),f.ok||d(Gx[f.problem])},m=h=>{i.current&&(i.current.value=""),!(!h||!n)&&p(async()=>{const f=await Uo(h);return f.ok?_o(f.blob):f})},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":u?"set":"none",children:e.jsx(ge,{title:t("placeLook.sidebarPicture"),subtitle:a,message:x,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[u&&e.jsx("img",{src:u,alt:t("placeLook.currentImage"),className:"h-8 w-14 rounded-md border border-ink/10 object-cover"}),e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>i.current?.click(),children:r?t("placeLook.imageSaving"):t(u?"placeLook.changeImage":"placeLook.useImage")}),u&&e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>{p($o)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:Do,hidden:!0,"data-place-picture-input":!0,onChange:h=>m(h.target.files?.[0])})]})})})}function Nr(){const s=Ko(),{state:n}=G(),a=Gt()===!0,i=window.ogb?.app?.ownPage===!0,[r,c]=l.useState(null),[o,d]=l.useState(null),u=s?.change===null,p=x=>{!s||u||r||x===s.swatch||(c(x),d(null),Ho(x).then(h=>{c(null),d(h)}))},m=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(ge,{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")}):m&&e.jsx("p",{className:"text-ink-secondary",children:m}),children:e.jsx(md,{value:r??s.swatch,onChange:p,label:i?t("placeLook.sidebarColor"):t("placeLook.aria",{name:s.name}),disabled:u,offset:"menu",none:!0})})}),e.jsx(Vx,{banner:n.config?.workspaceBanner??null,canChange:a,subtitle:t(i?"placeLook.sidebarPictureSub":"placeLook.sharedPictureSub")})]})}function qx(){return e.jsx("div",{"data-sidebar-look":!0,"data-settings-look":"simple",className:hi,children:e.jsx(Ee,{children:e.jsx(Nr,{})})})}function wr(){const{capabilities:s}=Ci(),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(u=>{d&&i(u)}).catch(()=>{}),()=>{d=!1}},[n]);const r=s.host?.platform;if(!n||!a||r!=="darwin"&&r!=="win32")return null;const c=window.ogb?.relaunch,o=()=>{n.set(!a.on).then(i).catch(()=>{})};return e.jsxs("div",{"data-window-frame-switch":!0,children:[e.jsx(ge,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(be,{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:Se()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}function Sr(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function Jx(s,n){return s.find(a=>Sr(a)&&a.instanceId.endsWith(`.${n}`))}function dn(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function va(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return dn(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function Yx(s,n){const a=n.filter(o=>Sr(o)&&dn(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=Wo(o);if(va(o.modelSelection,n)||va(d.modelSelection,n))continue;([o,d].some(p=>Go(Vo(p),c(p.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(o)}return r}const Xx={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function Qx({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=G(),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=Yx(n.bots,n.instances),p=u.target,m=h=>h.map(f=>f.name).join(", "),x=async()=>{if(!p||!u.bots.length||r)return;const h=u.bots,f={instanceId:p.instanceId,model:p.models.default};c(!0),d(null);for(const b of h)a({type:"setModel",botId:b.id,selection:f});try{const b=await Promise.all(h.map(g=>i(g.id).catch(()=>null))),y=h.filter((g,v)=>b[v]?.modelSelection.instanceId===f.instanceId);y.length&&d({name:p.displayName,bots:y.map(g=>g.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:Xx[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(Zx,{instance:Jx(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(", ")})}),p&&u.bots.length>0&&e.jsxs("div",{"data-company-switch":!0,className:"flex flex-col items-start gap-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"break-words text-[13px] text-ink",children:t("organization.useCompanyBots",{names:m(u.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{x()},children:u.bots.length===1?t("organization.useCompanyOne",{name:p.displayName}):t("organization.useCompanyMany",{name:p.displayName,count:u.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),p&&u.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:m(u.needsAsk)})})]})}function Zx({instance:s,instances:n}){if(!s)return null;if(s.policy)return e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s.policy.reason});if(dn(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(ve,{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&&qo(a)?e.jsx(Vt,{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 eh={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},ka="https://admin.limixbot.com",ja={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 th(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(ja,a))?s.message:n.map(a=>t(ja[a])).join(" ")}function Cr(){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,u]=l.useState(""),[p,m]=l.useState(!1),x=l.useRef(!1),h=l.useRef(0),f=l.useRef(0),b=l.useRef(void 0),y=j=>{const L=b.current!==j.status;b.current=j.status,a(j),L&&u(""),j.status!=="connected"&&j.status!=="reauth-required"&&m(!1)};l.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const j=++h.current,L=f.current,k=S=>{h.current===j&&(f.current++,y(S))},P=s?.onState(k);return s?.state().then(S=>{f.current===L&&k(S)}).catch(()=>{h.current===j&&f.current===L&&u(t("organization.loadFailed"))}),()=>{h.current++,P?.()}},[s]);const g=async j=>{if(!s||x.current)return;x.current=!0,o(!0),u("");const L=h.current,k=f.current;try{const P=await j();h.current===L&&f.current===k&&y(P)}catch{h.current===L&&f.current===k&&u(t("organization.actionFailed"))}finally{x.current=!1,h.current===L&&o(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const v=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,N=typeof w=="number"&&Number.isFinite(w)?new Date(w):null,I=N&&Number.isFinite(N.getTime())?new Intl.DateTimeFormat(Ve(),{dateStyle:"medium",timeStyle:"short"}).format(N):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:th(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:()=>{g(()=>s.begin({portalOrigin:ka}))},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:j=>{j.preventDefault(),i.trim()&&g(()=>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:j=>r(j.target.value),placeholder:ka,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:()=>{g(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{g(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),v&&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(j=>j.configured&&j.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:n.providers.filter(j=>j.configured&&j.models.length>0).map(j=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:eh[j.id]??j.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},j.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(j=>j.configured&&j.models.length>0)?e.jsx(Qx,{providers:n.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,p?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:()=>m(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button text-danger",onClick:()=>{g(()=>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:()=>{g(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>m(!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:()=>{g(()=>s.refresh())},children:t("organization.refresh")})]})]})}const sh="https://cal.com/milind-soni-002qed/30min",nh=["feature","price","setup","broken","later","other"],ah={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},Na=2e3,Os=s=>new Intl.DateTimeFormat(Ve(),{dateStyle:"medium"}).format(new Date(s)),ih=s=>s.endsAt??s.renewsAt;function Er(s){const n=ih(s);return s.trial?n?t("cloudCancel.endedTrial",{date:Os(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:Os(n)}):t("cloudCancel.endedPlanNoDate")}function rh(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 lh(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:Os(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function Ar({renewal:s,actions:n,onChanged:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,u]=l.useState(null);if(!s||!n)return null;const p=()=>{o(!0),u(null),n.keep().then(m=>{m.outcome==="kept"?a?.():u(m.outcome==="browser"?"browser":"failed")},()=>u("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:Er(s)}),e.jsx("button",{type:"button",className:"ui-button",disabled:c,onClick:p,children:t(c?"cloudCancel.keeping":"cloudCancel.keep")}),d&&e.jsx("p",{role:d==="failed"?"alert":"status",className:O("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:()=>{u(null),r(s)},children:t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan")}),i&&e.jsx(oh,{renewal:i,actions:n,onClose:m=>{r(null),m&&a?.()}})]})}function oh({renewal:s,actions:n,onClose:a}){const[i,r]=l.useState(null),[c,o]=l.useState(""),[d,u]=l.useState(""),[p,m]=l.useState({step:"ask"}),[x,h]=l.useState(!1),[f,b]=l.useState(!1),y=l.useRef(!1),g=l.useRef(null),v=()=>{x||a(y.current)};l.useEffect(()=>{const k=document.activeElement instanceof HTMLElement?document.activeElement:null;return g.current?.querySelector("button[aria-pressed]")?.focus(),()=>{k?.isConnected&&k.focus()}},[]);const C=k=>{h(!0),b(!1),k().catch(()=>b(!0)).finally(()=>h(!1))},w=()=>C(async()=>{const k=i!==null||c.trim()!==""||d.trim()!=="",P=await n.cancel(k?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);P.outcome==="cancelled"?(y.current=!0,m({step:"done",renewal:P.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:P.surveyed})):P.outcome==="browser"?m({step:"browser"}):b(!0)}),N=()=>C(async()=>{const k=await n.keep();k.outcome==="kept"?(y.current=!0,a(!0)):k.outcome==="browser"?m({step:"browser"}):b(!0)}),I=t(s.trial?"cloudCancel.titleTrial":"cloudCancel.titlePlan"),j="mt-1.5 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-60",L=f&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return xd.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:k=>{k.target===k.currentTarget&&v()},children:e.jsxs("div",{ref:g,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":x,tabIndex:-1,"data-cloud-cancel-sheet":p.step,className:"flex max-h-[90vh] w-full max-w-[480px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel text-ink shadow-2xl outline-none",onKeyDown:k=>{if(k.key==="Escape"&&(k.stopPropagation(),v()),k.key==="Tab"){const P=g.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!P?.length)return;const S=P[0],M=P[P.length-1];k.shiftKey&&document.activeElement===S?(k.preventDefault(),M.focus()):!k.shiftKey&&document.activeElement===M&&(k.preventDefault(),S.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:v,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(We,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[p.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:lh(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:nh.map(k=>e.jsx("button",{type:"button","aria-pressed":i===k,onClick:()=>r(P=>P===k?null:k),className:O("ui-button ui-button-pill",i===k&&"border-accent bg-accent/10 font-medium"),children:t(ah[k])},k))})]}),e.jsxs("label",{className:"mt-4 block text-[13px] text-ink",children:[t("cloudCancel.expected")," ",e.jsx("span",{className:"text-ink-secondary",children:t("cloudCancel.optional")}),e.jsx("textarea",{rows:2,maxLength:Na,value:c,disabled:x,onChange:k=>o(k.target.value),className:j})]}),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:Na,value:d,disabled:x,onChange:k=>u(k.target.value),className:j})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:sh,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),L,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:v,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")})]})]}),p.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:Er(p.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:rh(p.renewal)}),p.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),L,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:N,children:t(x?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:x,onClick:v,children:t("cloudCancel.done")})]})]}),p.step==="browser"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink",children:t("cloudCancel.browser")}),e.jsx("div",{className:"mt-5 flex justify-end",children:e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:v,children:t("cloudCancel.done")})})]})]})]})}),document.body)}function wa({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(ch,{bridge:s,read:n,write:a}):null}function ch({bridge:s,read:n,write:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[p,m]=l.useState(null);if(l.useEffect(()=>{let f=!0;const b=()=>{n().then(g=>{f&&r(g)}).catch(()=>{})};b();const y=s.onNotice(b);return()=>{f=!1,y()}},[s,n]),!i?.shown)return null;const x=f=>{o(!1),u(!0),m(null),a(f).then(b=>r(b),b=>m(ul(b)??t("cloudAccount.keepHere.failed"))).finally(()=>u(!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(be,{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")})]})]}),p&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:p})]})}function dh({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 uh={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},Pr=s=>new Intl.DateTimeFormat(Ve(),{timeStyle:"short"}).format(new Date(s)),ph=s=>new Intl.DateTimeFormat(Ve(),{dateStyle:"medium"}).format(new Date(s));function Ir(s,n){if(!s&&!n)return null;const a=s?_s(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:vl(n)})]})}function Sa({machine:s,busy:n,failed:a,onConnect:i,trial:r=!1,waking:c=!1,moving:o=null,team:d=null}){const u=s.status==="ready"?s.unreachable:void 0,p=s.status==="ready"&&!u,m=u?t(u.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):o??(c&&p?t("cloudHome.waking"):d?.name&&s.status==="ready"?t("cloudHome.team.ready",{name:d.name}):s.status==="ready"&&s.power?.sleeps?t("cloudHome.readySleeps"):r&&(s.status==="stopped"||s.status==="payment-problem")?t("cloudHome.stoppedTrial"):s.status==="failed"&&s.retryAt?t("cloudHome.failedRetry",{time:Pr(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(uh[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":u?.cause,"data-cloud-waking":c&&p?!0:void 0,"data-cloud-moving":o&&!u?!0:void 0,className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:p?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:m}),s.status==="provisioning"&&s.setup&&e.jsx(Pd,{step:s.setup.step}),p&&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&&Xo()&&e.jsx(dh,{label:t("cloudHome.filesLink"),className:"text-[13px] font-medium text-accent-text underline underline-offset-2 hover:text-ink"})]}),a&&!u&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudHome.connectFailed")})]})})}function mh({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 xh(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 hh={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function gh(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(hh[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:ph(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 fh(s,n){const a=s.trial&&!s.renewal?.cancelled?_s(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 bh({bridge:s,onConnectPhone:n}){const[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,p]=l.useState(0);l.useEffect(()=>{let y=!0;return s.state().then(g=>{y&&i(g)}).catch(()=>{y&&d(!0)}),()=>{y=!1}},[s,u]);const m=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 x=bl(a?.tier),h=a?.home===!0,f=a?.status==="paid"?t(yl(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(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:[f?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:f}):!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")}),Ir(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&&_s(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(Yo,{})]}),a?.renewal&&e.jsx(Ar,{renewal:a.renewal,actions:m,onChanged:()=>p(y=>y+1)}),r&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function yh({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 vh({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}=Ci().capabilities.host,[u,p]=l.useState(null),[m,x]=l.useState(!1),[h,f]=l.useState(!1),[b,y]=l.useState(!1),[g,v]=l.useState(!1),[C,w]=l.useState(!1),[N,I]=l.useState(!1),j=l.useRef(0),L=l.useRef(0),k=l.useRef(!1),P=l.useRef({request:0,arrived:!1,connected:!1});l.useEffect(()=>{const xe=++j.current,de=L.current,je=pe=>{j.current===xe&&(L.current++,p(pe),f(!1),pe.status==="signed-out"&&y(!1))},_=o?.onState(je);return o?.state().then(pe=>{L.current===de&&je(pe)}).catch(()=>{j.current===xe&&L.current===de&&f(!0)}),()=>{j.current++,_?.()}},[o]);const S=async xe=>{if(!o||k.current)return;k.current=!0,x(!0),f(!1);const de=j.current,je=L.current;try{const _=await xe();j.current===de&&L.current===je&&p(_)}catch{j.current===de&&L.current===je&&f(!0)}finally{k.current=!1,j.current===de&&x(!1)}},M=()=>{o&&(w(!1),S(async()=>{try{return await o.connectHome()}catch{return w(!0),o.state()}}))},se=xe=>{o?.openTeam&&(w(!1),S(async()=>{try{await o.openTeam(xe)}catch{w(!0)}return o.state()}))},ne=()=>{o&&(I(!1),S(async()=>{try{return await o.connectHomeForPhone()}catch{return I(!0),o.state()}}))};l.useEffect(()=>{if(s||(P.current.request=0),!o||!s||!u||k.current||(P.current.request!==s&&(P.current={request:s,arrived:!0,connected:!1}),u.status==="signed-out"&&u.message==="restoring"))return;const xe=xh(u,P.current);P.current.arrived=!1,xe==="sign-in"&&S(()=>o.begin()),xe==="connect"&&(P.current.connected=!0,M())},[o,s,u,m]);const[V]=Jo(o?window.ogb?.cloudSendPage:void 0),ie=V?.move?pl(V.move,"local"):null,re=ie&&ie.kind!=="done"?ie.text:null,oe=Vd(!!u&&fn(bn(u)),u?.offer),T=o?.cancelPlan&&o.keepPlan?{cancel:xe=>o.cancelPlan(xe),keep:()=>o.keepPlan()}:null;if(!o){const xe=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return e.jsxs(e.Fragment,{children:[n&&a?e.jsx(yh,{team:a}):xe?e.jsx(bh,{bridge:xe,onConnectPhone:i}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")}),xe&&!a&&e.jsx(wa,{bridge:window.ogb?.cloudSendPage})]})}const R=bn(u),E=u&&["connected","unavailable","reauth-required"].includes(u.status),D=gh(u,R,d),Q=ml(R),le=xl(u),ae=hl(u),U=R.kind==="paid"?{status:"provisioning"}:void 0,te=le?ae?.machine??U:u?.status==="connected"?u.machine??U:void 0,me=u?.status==="connecting"?u.enrollment:void 0;gl(oe);const ce=r&&fn();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:[u?.staging&&e.jsx(fl,{className:"mb-3"}),(!u||R.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),D&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:D}),(R.kind==="signed-out"||R.kind==="removed")&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[ce,e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>c?c():void S(()=>o.begin()),children:t("cloudAccount.signIn")})]}),u?.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")}),me&&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:me.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:Pr(me.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>{S(()=>o.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>{S(()=>o.cancel())},children:t("organization.cancel")})]})]}),E&&e.jsxs("div",{className:"flex flex-col gap-3",children:[u.account&&e.jsx("p",{className:"break-all text-[14px] text-ink",children:u.account.email}),Q&&e.jsxs("p",{role:"status","data-cloud-plan":R.kind,className:"text-[15px] font-medium text-ink",children:[Q,R.kind==="paid"&&R.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),u.status==="connected"&&Ir(u.trial,u.credit),R.kind==="free"&&ce,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[R.kind==="reauth"?e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>{S(()=>o.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[!(R.kind==="free"&&ce)&&e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>{S(()=>o.openDashboard())},children:R.kind==="free"?t("cloudAccount.dashboard"):fh(u,R)}),e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>{S(()=>o.refresh())},children:t("organization.refresh")})]}),!b&&e.jsx("button",{type:"button",disabled:m,className:"ui-button",onClick:()=>y(!0),children:t("cloudAccount.signOut")})]}),u.status==="connected"&&u.renewal&&e.jsx(Ar,{renewal:u.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:m,className:"underline hover:text-ink",onClick:()=>window.ogb?.accounts?v(!0):y(!0),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),g&&e.jsx(hd,{adding:"",onClose:()=>v(!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:m,className:"ui-button",onClick:()=>y(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:m,className:"ui-button text-danger",onClick:()=>{S(()=>o.signOut())},children:t("cloudAccount.signOut")})]})]})]}),h&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!u&&e.jsx("button",{type:"button",disabled:m,className:"ui-button mt-3",onClick:()=>{S(()=>o.state())},children:t("organization.refresh")})]}),te&&Sa(le?{machine:te,busy:m,failed:C,onConnect:()=>{ae&&se(ae.id)},team:{name:ae?.name??null}}:{machine:te,busy:m,failed:C,onConnect:M,trial:!!u?.trial,waking:u?.waking===!0,moving:re}),E&&R.kind==="paid"&&!le&&mh({ready:te?.status==="ready",busy:m,failed:N,onUse:ne}),e.jsx(wa,{bridge:window.ogb?.cloudSendPage})]})}function Ca(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Ve(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function Rr(s){return t("planUsage.spendAmounts",{used:Ca(s.usedMinor,s.currency,s.exponent),limit:Ca(s.limitMinor,s.currency,s.exponent)})}function Tr(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 kh(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 jh(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function Ea(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function Ht(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 Nh(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:Ht({name:a[1]})}):n}function Lt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?Tr(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:O("h-full rounded-full",jh(o)),style:{width:`${Math.min(100,Math.max(0,o))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function Br(){const[s,n]=l.useState(null),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(()=>Date.now()),u=l.useRef(new Set),p=l.useCallback(async(m=!1)=>{i(!0),c("");try{const x=await F(m?"/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(()=>{p(!1)},[p]),l.useEffect(()=>{const m=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(m)},[]),l.useEffect(()=>{if(!s)return;const m=kh(s,o,u.current);if(m.length!==0){for(const x of m)u.current.add(x);p(!0)}},[s,o,p]),{report:s,loading:a,error:r,now:o,load:p}}function wh(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 Sh(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 Ch(){const{report:s,now:n}=Br();if(!s)return null;const a=Sh(s),i=a?null:wh(s);if(i){const d=Ht(i.provider),u=Math.round(Math.min(100,Math.max(0,i.budget.usedPercent)));return e.jsx(In,{kind:"plan",title:t("settings.simple.billing.monthlySpend",{provider:d}),percent:u,label:`${d}: ${t("planUsage.used",{used:u})}`,note:i.budget.spend?Rr(i.budget.spend):null})}if(!a)return e.jsx("section",{"data-usage-summary":"own-ai",className:O(ci,"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=Tr(a.provider.weekly.resetsAt,n),o=Ht(a.provider);return e.jsx(In,{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 Eh(){const{report:s,loading:n,error:a,now:i,load:r}=Br();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(q,{size:14,className:"animate-spin"}):e.jsx(De,{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:Ht(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(Lt,{label:t("planUsage.fiveHour"),window:c.fiveHour,now:i}),e.jsx(Lt,{label:t("planUsage.weekly"),window:c.weekly,now:i}),c.extra.map((o,d)=>e.jsx(Lt,{label:Ea(o.label),now:i,usedHeadline:!!o.spend,detail:o.spend?Rr(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,u)=>e.jsx(Lt,{label:Ea(d.label),now:i,usedHeadline:!0,window:{available:!0,remainingPercent:d.remainingPercent,usedPercent:d.usedPercent,resetsAt:d.resetsAt}},`${o.name}-${d.label}-${u}`))]},o.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:Nh(c)})]},c.id))})]})}function Aa(s,n){return s?.edition?.features?.includes(n)===!0}function Ah(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function Ph({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)),[u,p]=l.useState(!1),[m,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(u)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}p(!0),x(null);try{const g=await F("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:b,warnAtPercent:y}})});a({type:"configStatus",config:g})}catch(g){x(g instanceof Error?g.message:String(g))}finally{p(!1)}},f=Ah(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:O(f==="danger"?"text-danger":f==="warning"?"text-warning":"text-ink"),children:s.exceeded?t("usage.budget.reached"):s.warn?t("usage.budget.nearing"):t("usage.budget.within")}),e.jsx("span",{className:"tabular-nums text-ink-secondary",children:t("usage.budget.spent",{spent:vt(s.spentUsd),cap:vt(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:O("h-full rounded-full",f==="danger"?"bg-danger":f==="warning"?"bg-warning":"bg-accent"),style:{width:`${Math.min(100,s.percent)}%`}})})]}):e.jsx("p",{className:"mb-4 text-[13px] text-ink-secondary",children:t("usage.budget.none")}),e.jsxs("form",{className:"flex flex-wrap items-end gap-3",onSubmit: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:u,className:"w-32 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.warnAt"),e.jsx("input",{value:o,onChange:b=>d(b.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:u,className:"w-20 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("button",{type:"submit",disabled:u,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[u&&e.jsx(q,{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")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Pa(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 Ih(){const{state:s,dispatch:n}=G(),a=s.config?.billing,[i,r]=l.useState(a?.currency??"USD"),[c,o]=l.useState(Pa(a?.prices)),[d,u]=l.useState(!1),[p,m]=l.useState(null);l.useEffect(()=>{r(a?.currency??"USD"),o(Pa(a?.prices))},[a]);const x=(b,y)=>o(g=>g.map((v,C)=>C===b?{...v,...y}:v)),h=async()=>{if(d)return;const b={};for(const y of c){const g=y.key.trim();if(!g)continue;const v=Number(y.input),C=Number(y.output),w=y.cached.trim()===""?void 0:Number(y.cached);if(!Number.isFinite(v)||!Number.isFinite(C)||v<0||C<0||w!==void 0&&(!Number.isFinite(w)||w<0)){m(t("usage.prices.invalid",{model:g}));return}b[g]={inputPerMillion:v,outputPerMillion:C,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){m(t("usage.prices.currencyInvalid"));return}u(!0),m(null);try{const y=await F("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:b}})});n({type:"configStatus",config:y})}catch(y){m(y instanceof Error?y.message:String(y))}finally{u(!1)}},f="w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50";return e.jsxs(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:g=>x(y,{key:g.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:O(f,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:b.input,onChange:g=>x(y,{input:g.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:f}),e.jsx("input",{value:b.output,onChange:g=>x(y,{output:g.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:f}),e.jsx("input",{value:b.cached,onChange:g=>x(y,{cached:g.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:f}),e.jsx("button",{type:"button",onClick:()=>o(g=>g.filter((v,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(Le,{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(Oe,{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(q,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.prices.hint")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}function Rh({budget:s}){const{state:n}=G(),a=Aa(n.config,"budgets"),i=Aa(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(Ph,{budget:s}),i&&e.jsx(Ih,{})]})}const Th=["model","user","department","day","engine","routine"],Ia={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"},Bh={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},Lh=2e3;function Oh(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 Ra(s,n,a){const[i,r]=l.useState(null);return l.useEffect(()=>{let c=!0;return F(`/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 Ta({groupBy:s,groups:n}){const{state:a}=G(),i=[...n].sort((c,o)=>mt(o)-mt(c)).slice(0,6),r=Math.max(...i.map(mt),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(Zt,{bot:o,state:"idle",size:18,animated:!1}),e.jsx("span",{className:"truncate",children:s==="model"?lc(c.label,a.instances):Oh(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,mt(c)/r*100)}%`}})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[oc(mt(c)),yt(c.costUsd)&&c.costUsd>0&&` · ${gi(c.costUsd)}`]})]},c.key)})})}function zh({range:s,version:n,onBudget:a}){const[i,r]=l.useState("model"),c=Ra(s,"bot",n),o=Ra(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(Ia.bot)}),c?e.jsx(Ta,{groupBy:"bot",groups:c.groups}):e.jsx(q,{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:Th.map(d=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===d,onClick:()=>r(d),className:O("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(Ia[d])},d))}),o?.groupBy===i?e.jsx(Ta,{groupBy:i,groups:o.groups}):e.jsx(q,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}function Mh(s){return new Date(s).toLocaleString(kl(Ve()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Fh({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:O("rounded-full ring-2 ring-card",c>1&&"hidden sm:block"),children:e.jsx(Zt,{bot:o,state:"idle",size:22,animated:!1})},r.id):e.jsx("span",{className:O("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:[Mh(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(ic,{}),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:rc(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:gi(s.costUsd)}),e.jsx(Ys,{size:14,className:"text-ink-tertiary"})]})]})})}function Lr(){const[s,n]=l.useState("month"),a=l.useMemo(()=>Qo(s),[s]),[i,r]=l.useState(null),[c,o]=l.useState(null),[d,u]=l.useState(0),[p,m]=l.useState(null),[x,h]=l.useState(null),f=l.useRef(null);l.useEffect(()=>{let g=!0;return Rn(a).then(v=>{g&&(r(v),o(null))}).catch(v=>{g&&o(v instanceof Error?v.message:String(v))}),()=>{g=!1}},[a,d]),l.useEffect(()=>Zo({onFrame:g=>{if(g.kind!=="runtime"||f.current)return;const v=g.event?.type;v!=="turn.started"&&v!=="turn.completed"||(f.current=setTimeout(()=>{f.current=null,u(C=>C+1)},Lh))},onMissedFrames:()=>u(g=>g+1)}),[]),l.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const b=()=>{i?.next&&Rn(a,i.next).then(g=>r(v=>v?{...g,roots:[...v.roots,...g.roots]}:g))},y=i?.roots.some(g=>!g.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(ye,{size:"sm",value:s,onChange:g=>{n(g.target.value),h(null)},"aria-label":t("usage.history.period"),children:ec.map(g=>e.jsx("option",{value:g,children:t(Bh[g])},g))}),e.jsxs("a",{href:tc(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(Gs,{size:13}),t("usage.history.export")]})]})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:c}),x?e.jsx(sc,{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(oi,{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(nc,{items:ac(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(q,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(zh,{range:a,version:d,onBudget:m}),e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-2","aria-label":t("usage.page.runs"),children:[e.jsxs("div",{className:"px-3 pb-1 pt-3",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.runs")}),e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t("usage.page.runsHint")})]}),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(g=>e.jsx(Fh,{root:g,onOpen:()=>h({id:g.id,at:g.startedAt})},g.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(Eh,{}),e.jsx(Rh,{budget:p})]})}function Dh(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 Or({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(Us())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function Uh(){const{state:s}=G(),[n,a]=l.useState([]),[i,r]=l.useState(!0),[c,o]=l.useState(""),[d,u]=l.useState(""),[p,m]=l.useState(null),[x,h]=l.useState(null),[f,b]=l.useState(""),[y,g]=l.useState(""),[v,C]=l.useState(!1),[w,N]=l.useState(""),[I,j]=l.useState(""),L=l.useRef(!1),k=s.bots.filter(E=>!E.hidden),P=l.useMemo(()=>[...new Set(n.flatMap(E=>E.tags))].sort((E,D)=>E.localeCompare(D)),[n]),S=Dh(n,d,p),M=async E=>{try{const D=await fetch("/api/skills-library"),Q=await D.json();if(!D.ok)throw new Error(Q.error??t("skills.library.loadError"));if(E?.())return;a(Q.skills??[]),o("")}catch(D){E?.()||o(D instanceof Error?D.message:t("skills.library.loadError"))}finally{E?.()||r(!1)}};l.useEffect(()=>{let E=!1;return r(!0),M(()=>E),()=>{E=!0}},[]);const se=async(E,D,Q)=>{if(L.current)return;L.current=!0;const le=`${D}:${E}`;b(le),o("");try{const ae=await fetch("/api/skills-library"),U=await ae.json();if(!ae.ok)throw new Error(U.error??t("skills.library.loadError"));const te=(U.skills??[]).filter(de=>de.assignedBots.some(je=>je.id===E)).map(de=>de.name),me=Q?te.filter(de=>de!==D):[...new Set([...te,D])],ce=await fetch(`/api/bots/${encodeURIComponent(E)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:me})}),xe=await ce.json();if(!ce.ok)throw new Error(xe.error??t("skills.error.assignments"));await M()}catch(ae){o(ae instanceof Error?ae.message:t("skills.error.assignments"))}finally{L.current=!1,b("")}},ne=async E=>{I&&await se(I,E.name,!1)},V=async(E,D)=>{await se(D,E.name,!0)},ie=async(E,D=!1)=>{if(!L.current){if(!E.enabled&&!D)return oe(E,!0);L.current=!0,b(E.name),o("");try{const Q=await fetch(`/api/skills-library/${encodeURIComponent(E.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!E.enabled})}),le=await Q.json();if(!Q.ok)throw new Error(le.error??t("skills.error.update"));D&&h(null),await M()}catch(Q){o(Q instanceof Error?Q.message:t("skills.error.update"))}finally{L.current=!1,b("")}}},re=async E=>{if(!L.current){L.current=!0,b(E.name),o("");try{const D=await fetch(`/api/skills-library/${encodeURIComponent(E.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({everyBot:!E.everyBot})}),Q=await D.json();if(!D.ok)throw new Error(Q.error??"Could not update this skill.");await M()}catch(D){o(D instanceof Error?D.message:"Could not update this skill.")}finally{L.current=!1,b("")}}},oe=async(E,D=!1)=>{o("");try{const Q=await fetch(`/api/skills-library/${encodeURIComponent(E.name)}`),le=await Q.json();if(!Q.ok)throw new Error(le.error??t("skills.error.load"));if(!le.text)throw new Error(t("skills.error.contentsImport"));h({skill:E,text:le.text,review:D})}catch(Q){o(Q instanceof Error?Q.message:t("skills.error.load"))}},T=async()=>{const E=y.trim();if(E){C(!0),o(""),N("");try{const D=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:E})}),Q=await D.json();if(!D.ok)throw new Error(Q.error??t("skills.error.import"));N(t("skills.library.imported",{name:Q.skill?.name??""})),g(""),await M()}catch(D){o(D instanceof Error?D.message:t("skills.error.import"))}finally{C(!1)}}},R="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(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(jt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:R,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:d,onChange:E=>u(E.target.value)})]}),P.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>m(null),className:p===null?"rounded-full bg-control px-2.5 py-1 text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),P.map(E=>e.jsx("button",{type:"button",onClick:()=>m(p===E?null:E),className:p===E?"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:E},E))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):S.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:n.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:S.map(E=>e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{oe(E)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:E.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:E.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:E.description})]}),e.jsx(be,{checked:E.enabled,"aria-label":E.enabled?t("skills.library.disable",{skill:E.name}):t("skills.library.enable",{skill:E.name}),disabled:!!(f||v),onClick:()=>{ie(E)}})]}),e.jsx(Or,{skill:E}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3 rounded-lg bg-inset px-2.5 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("skills.library.everyBot")}),e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t("skills.library.everyBotHint")})]}),e.jsx(be,{checked:E.everyBot,"aria-label":t("skills.library.everyBot"),disabled:!!(f||v),onClick:()=>{re(E)}})]}),E.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:E.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:E.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):E.assignedBots.map(D=>e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-control px-2 py-0.5",children:[e.jsx("span",{className:"max-w-40 truncate",children:D.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:D.name}),title:t("skills.library.removeAssignment",{bot:D.name}),disabled:!!(f||v),onClick:()=>{V(E,D.id)},className:"flex size-4 items-center justify-center rounded-full text-ink-secondary hover:bg-danger/10 hover:text-danger disabled:opacity-40",children:e.jsx(We,{size:11})})]},D.id))}),k.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs(ye,{size:"sm","aria-label":t("skills.library.assignLabel"),value:I,disabled:!!(f||v),onChange:D=>j(D.target.value),className:"max-w-45",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),k.map(D=>e.jsx("option",{value:D.id,children:D.name},D.id))]}),e.jsx("button",{type:"button",disabled:!I||!!(f||v),onClick:()=>{ne(E)},className:"rounded-lg bg-control px-2.5 py-1 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:t("skills.library.assign")})]})]},E.name))}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}),e.jsx(X,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:E=>{E.preventDefault(),T()},children:[e.jsx("textarea",{className:`${R} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:y,onChange:E=>g(E.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:w}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:v||!!f||!y.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:v?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),x&&e.jsx(Js,{modal:!0,children:e.jsx(_h,{viewing:x,error:c,working:!!f,onClose:()=>{f||h(null)},onEnable:()=>{ie(x.skill,!0)}})})]})}function _h({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=l.useRef(null);return gd(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(Or,{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 $h(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 Ba({config:s}){const n=$h(s);return n?e.jsxs("div",{role:"status",className:O("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(Ge,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function zr(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Kh=()=>F("/api/fleet");function Hh({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:O("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:[yt(i.usage.costUsd)?vt(i.usage.costUsd):"—",yt(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",vt(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 Wh({domain:s,onCreated:n,disabled:a}){const[i,r]=l.useState(""),[c,o]=l.useState(""),[d,u]=l.useState(""),[p,m]=l.useState(""),[x,h]=l.useState(""),[f,b]=l.useState(!1),[y,g]=l.useState(null),v=async()=>{if(!f){b(!0),g(null);try{const w={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(I=>I.trim()).filter(Boolean),...p.trim()?{cap:Number(p)}:{},...x.trim()?{anthropicKey:x.trim()}:{}},N=await F("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});r(""),o(""),u(""),m(""),h(""),n(N.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){g(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(),v()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:w=>r(w.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||f,"aria-label":t("workspaces.name"),className: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||f,"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=>u(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||f,"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:p,onChange:w=>m(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||f,"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||f,"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||f,className:"ui-button ui-button-primary",children:[f?e.jsx(q,{size:13,className:"animate-spin"}):e.jsx(Oe,{size:13}),f?t("workspaces.creating"):t("workspaces.create")]})})]})}function Gh({slug:s,onDone:n}){const[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),[u,p]=l.useState(null),m=async x=>{if(!o){d(x),p(null);try{const h=await F(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:x,email:a.trim(),chatOnly:r})});i(""),n(h.log??[])}catch(h){p(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:()=>{m("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:()=>{m("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")})]}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function Vh({load:s=Kh}){const{state:n}=G(),[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[u,p]=l.useState(null),[m,x]=l.useState([]),[h,f]=l.useState(null),[b,y]=l.useState(null),[g,v]=l.useState(!1),[C,w]=l.useState(null),N=l.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(k){c(k instanceof Error?k.message:String(k))}finally{d(!1)}},[s]);l.useEffect(()=>{N()},[N]);const I=async(k,P)=>{if(P==="users"){f(S=>S===k?null:k);return}if(P==="delete"){y({slug:k,keepData:!1});return}p(k),c(null);try{const S=await F(`/api/fleet/workspaces/${encodeURIComponent(k)}/${P}`,{method:"POST"});x(S.log??[]),await N()}catch(S){c(S instanceof Error?S.message:String(S))}finally{p(null)}},j=async()=>{if(!b)return;const{slug:k,keepData:P}=b;y(null),p(k),c(null);try{const S=await F(`/api/fleet/workspaces/${encodeURIComponent(k)}`,{method:"DELETE",body:JSON.stringify({keepData:P})});x(S.log??[]),await N()}catch(S){c(S instanceof Error?S.message:String(S))}finally{p(null)}},L=async()=>{p("*"),c(null);try{const k=await F("/api/fleet/upgrade",{method:"POST"});x(k.log??[t("workspaces.upgraded")]),await N()}catch(k){c(k instanceof Error?k.message:String(k))}finally{p(null)}};return zr(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:()=>{N()},disabled:o||u!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(De,{size:12,className:O(o&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>v(k=>!k),disabled:u!==null,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx(Oe,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{L()},disabled:u!==null||!a?.workspaces.length,className:"rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:u==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),g&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(Wh,{domain:a.domain,disabled:u!==null,onCreated:(k,P)=>{v(!1),x(k),w(`https://${P.slug}.${a.domain}/pair?email=${encodeURIComponent(P.admin)}`),N()}})}),C&&e.jsx("div",{className:"mb-4",children:e.jsx(gr,{link:C})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(Hh,{fleet:a,onAct:(k,P)=>{I(k,P)},busy:u}):o?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(q,{size:14,className:"animate-spin"}),t("common.checking")]}):null,h&&e.jsx(Gh,{slug:h,onDone:k=>{x(k),N()}}),m.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:m.join(`
|
|
11
|
+
`)})]}),e.jsx(ut,{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:()=>{j()}}),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:k=>y({...b,keepData:k.target.checked})}),t("workspaces.keepData")]})]}):null}const La=[{choice:"system",label:"settings.theme.system"},{choice:yn.light,label:"settings.theme.light"},{choice:yn.dark,label:"settings.theme.dark"}];function un(){return l.useSyncExternalStore(Nl,vn,vn)}function Mr({simple:s=!1}){const n=un(),a=La.some(i=>i.choice===n)?void 0:$s.find(i=>i.id===n)?.name;return e.jsx(ge,{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:La.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>jl(i.choice),className:s?O("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"):O("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 qh({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 Jh={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function Yh({festival:s}){const n=bd(),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:Jh[s].map(i=>e.jsx(yd,{color:i,bodyId:vd[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(be,{checked:n,"aria-label":a,onClick:()=>kd(!n)})]})}function Fr(){const s=Ya(un());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:$s.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Sl(n.id)},"aria-pressed":a,className:O("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(qh,{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:wl(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(ve,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),fd(s)&&e.jsx(Yh,{festival:s})]})}function Xh(){const[s,n]=l.useState(Cl);return e.jsx(ge,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(ye,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Al(i),n(i)},children:El.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Qh(){const[s,n]=l.useState(Pl);return e.jsx(ge,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(ye,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=kn.find(r=>r===a.target.value);i&&(Il(i),n(i))},children:kn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Zh(){const s=cc();return e.jsx(ge,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(ye,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>uc(pc(n.target.value)),children:dc.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function Dr(){const{state:s,dispatch:n}=G(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[p,m]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||x.current)return;const f=hc(i);if(!f.ok){u(t("settings.roomTurns.range"));return}x.current=!0,m(!0);try{const b=await F("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:b}),r(String(b.rooms.turnTimeoutMinutes)),o(!1),u("")}catch(b){u(b instanceof Error?b.message:t("settings.roomTurns.error"))}finally{x.current=!1,m(!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:xc,max:mc,step:1,inputMode:"numeric",value:i,disabled:p,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:f=>{r(f.target.value),o(!0),u("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.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 eg=10,Ur=1,_r=60,Oa="Enter a whole number from 1 to 60.";function tg(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:Oa};const a=Number(n);return a<Ur||a>_r?{ok:!1,error:Oa}:{ok:!0,minutes:a}}function za(s){return s?.mcp?.callTimeoutMinutes??eg}function $r(){const{state:s,dispatch:n}=G(),a=za(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[p,m]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||x.current)return;const f=tg(i);if(!f.ok){u(t("settings.mcpCalls.range"));return}x.current=!0,m(!0);try{const b=await F("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:b}),r(String(za(b))),o(!1),u("")}catch(b){u(b instanceof Error?b.message:t("settings.mcpCalls.error"))}finally{x.current=!1,m(!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:Ur,max:_r,step:1,inputMode:"numeric",value:i,disabled:p,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:f=>{r(f.target.value),o(!0),u("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.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 Kr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(p,m)=>{a={value:p,status:m};for(const x of o)x()},u=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const p=a.value;await n(p),i=a.value!==p}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(p){return o.add(p),()=>{o.delete(p)}},confirm(p){!i&&!r&&p!==a.value&&d(p,"idle")},edit(p){i=!0,d(p,"idle"),clearTimeout(c),c=setTimeout(()=>{u()},600)},flush:u}}const Ma=new WeakMap;function sg(){const{state:s,dispatch:n}=G(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=Ma.get(n);if(!r){const p={current:i};r={team:p,controller:Kr(a,async m=>{const x=p.current?await Vs({aboutMe:m}):(await F("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:m}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:x?.aboutMe??m}})})},Ma.set(n,r)}r.team.current=i;const c=r.controller,{value:o,status:d}=l.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:u}=c;return l.useEffect(()=>{c.confirm(a)},[c,a]),l.useEffect(()=>()=>{u()},[u]),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(gc,{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:p=>c.edit(p.target.value),onBlur:()=>{u()},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(ng,{onChanged:p=>{c.confirm(p),n({type:"profileSaved",profile:{aboutMe:p}})}}),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:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function ng({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let u=!1;return F("/api/profile/learned").then(p=>{u||a(p.learned)}).catch(()=>{}),()=>{u=!0}},[]);const d=async u=>{r(u),o(!1);try{const p=await F(`/api/profile/learned/${encodeURIComponent(u)}/remove`,{method:"POST"});a(p.learned),s(p.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(u=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[u.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:u.botName})})]}),e.jsx("button",{type:"button",disabled:i===u.id,onClick:()=>{d(u.id)},className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},u.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const Fa=new WeakMap;function ag(){const{state:s,dispatch:n}=G(),a=s.config?.everyBotRules;let i=Fa.get(n);i||(i=Kr(a??"",async p=>{const m=await F("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:p}),timeoutMs:1e4});n({type:"configStatus",config:m})}),Fa.set(n,i));const{value:r,status:c}=l.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:o,edit:d,flush:u}=i;return l.useEffect(()=>{o(a??"")},[o,a]),l.useEffect(()=>()=>{u()},[u]),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:p=>d(p.target.value),onBlur:()=>{u()},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:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const Da=64,Ua=8192,Ot=512;function ig(s){return yc(s)?s.size>vc?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function rg(s,n){return s<Da||n<Da?"settings.profile.avatar.tooSmall":s>Ua||n>Ua?"settings.profile.avatar.tooLargeDimensions":null}async function Hr(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 lg(s,n){return Hr(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=Ot,r.height=Ot;const c=r.getContext("2d");if(!c)throw new Error("canvas-unavailable");c.drawImage(a,(a.naturalWidth-i)/2,(a.naturalHeight-i)/2,i,i,0,0,Ot,Ot);const o=await new Promise((d,u)=>r.toBlob(p=>p?d(p):u(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function og(){const{state:s,dispatch:n}=G(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,u]=l.useState(null),p=l.useRef(null),m=g=>{const v=p.current;v&&v.previewUrl!==g?.previewUrl&&URL.revokeObjectURL(v.previewUrl),p.current=g,u(g)};l.useEffect(()=>()=>{p.current&&URL.revokeObjectURL(p.current.previewUrl)},[]);const x=!!s.config?.team,h=async g=>{const v=x?await Vs({avatarUrl:g}):(await F("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:g}})})).profile;n({type:"profileSaved",profile:{avatarUrl:v?.avatarUrl}})},f=g=>{if(!g)return;o(null);const v=ig(g);if(v)return o(t(v));Hr(g,C=>({width:C.naturalWidth,height:C.naturalHeight})).then(({width:C,height:w})=>{const N=rg(C,w);if(N)return o(t(N));m({file:g,previewUrl:URL.createObjectURL(g),width:C,height:w,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},b=g=>{r(!0),o(null),lg(g.file,g.zoom).then(v=>bc(v)).then(v=>{const C=v?jd(v.path):null;if(!C)throw new Error("avatar");return h(C)}).then(()=>m(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:g=>m({...d,zoom:Number(g.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>m(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled: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:g=>{const v=g.target.files?.[0];g.currentTarget.value="",f(v)}})]}),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 Wr(){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){Vs({name:a.trim()}).then(p=>n({type:"profileSaved",profile:{name:p.name,email:p.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(p=>{if(!p.ok)throw new Error("Profile save failed");return p.json()}).then(p=>{p.profile&&n({type:"profileSaved",profile:{name:p.profile.name,email:p.profile.email}})}).catch(()=>{})},u="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(og,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:p=>i(p.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:u}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:p=>c(p.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:u}),e.jsx(sg,{}),e.jsx(ag,{})]})}function cg({profile:s}){const[n,a]=l.useState(null),i=fc(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(fi,{size:20,"aria-hidden":"true"})})}function dg(){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(cg,{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(Wr,{})})]})}function Gr({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 u=!0;return F("/api/me/away-emails",{timeoutMs:1e4}).then(p=>{u&&i(p.on)},()=>{}),()=>{u=!1}},[n]);const d=u=>{const p=a;i(u),c(!1),F("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:u}),timeoutMs:1e4}).then(m=>i(m.on),()=>{i(p),c(!0)})};return!n||a===null?null:e.jsxs("div",{className:s?"flex flex-col gap-1 px-4 py-[13px]":"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{id:o,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(be,{"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 Vr(){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(""),u=l.useRef(!1),p=async m=>{if(!(u.current||m===a)){u.current=!0,c(m),d("");try{const x=await F("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:m}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.threads.error"))}finally{u.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(ye,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:m=>{p(Number(m.target.value))},children:Array.from({length:16},(m,x)=>x+1).map(m=>e.jsx("option",{value:m,children:m},m))}),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 qr(){const{state:s,dispatch:n}=G(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),u=l.useRef(!1),p=a??s.config?.automaticRecovery??{enabled:!1},m=s.instances.filter(g=>g.snapshot.state==="available"&&!g.policy),x=m.find(g=>g.instanceId===p.backup?.instanceId),h=x?.models.options.filter(g=>!g.orgBlocked&&!g.needsCliUpdate&&(x.snapshot.authenticated!==!1||g.custom))??[],f=h.some(g=>g.id===p.backup?.model),b=g=>{i(g),d("")},y=async()=>{if(!(!a||u.current||p.enabled&&!f)){u.current=!0,c(!0),d("");try{const g=await F("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:g}),i(null)}catch(g){d(g instanceof Error?g.message:t("settings.recovery.error"))}finally{u.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(be,{id:"automatic-recovery-enabled",checked:p.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>b({...p,enabled:!p.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(ye,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:p.backup?.instanceId??"",disabled:r||!p.enabled,onChange:g=>b({enabled:p.enabled,...g.target.value?{backup:{instanceId:g.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),p.backup&&!x&&e.jsx("option",{value:p.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:p.backup.instanceId})}),m.map(g=>e.jsx("option",{value:g.instanceId,disabled:!g.models.options.some(v=>g.snapshot.authenticated!==!1||v.custom),children:g.displayName},g.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(ye,{className:"mt-2 w-full",id:"automatic-recovery-model",value:p.backup?.model??"",disabled:r||!p.enabled||!x,onChange:g=>b({enabled:p.enabled,backup:{instanceId:x.instanceId,model:g.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),p.backup?.model&&!f&&e.jsx("option",{value:p.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:p.backup.model})}),h.map(g=>e.jsx("option",{value:g.id,children:g.label},g.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),p.enabled&&!f&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||p.enabled&&!f,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 Jr=1,Yr=3650,ug=30,Wt=1024*1024,zs=256*1024,Xr=4*1024*1024*1024,pg=50;function _a(s){const n=Number(s);return Number.isInteger(n)&&n>=Jr&&n<=Yr?n:null}function $a(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Wt);return a>=zs&&a<=Xr&&a%zs===0?a:null}function Ka(s){const n=s/Wt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function Qr(){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),[u,p]=l.useState(null),[m,x]=l.useState(""),[h,f]=l.useState(null),b=l.useRef(!1),y=r??String(a===null?ug:a),g=o??(i===null?String(pg):Ka(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&Ka(i)===o&&d(null)},[i,o]);const v=async(j,L)=>{if(!b.current){b.current=!0,p(L),x(""),f(null);try{const k=await F("/api/config",{method:"PATCH",body:JSON.stringify({threads:j})});n({type:"configStatus",config:k})}catch(k){x(k instanceof Error?k.message:t("settings.threadCleanup.error"))}finally{b.current=!1,p(null)}}},C=j=>{if(!j){c(null),x(""),f(null),v({eventLogRetentionDays:null},"retention");return}const L=_a(y);if(L===null){x(t("settings.threadCleanup.invalidRetention")),f("retention");return}v({eventLogRetentionDays:L},"retention")},w=j=>{if(!j){d(null),x(""),f(null),v({eventLogMaxBytes:null},"cap");return}const L=$a(g);if(L===null){x(t("settings.threadCleanup.invalidCap")),f("cap");return}v({eventLogMaxBytes:L},"cap")},N=()=>{if(a===null)return;const j=_a(y);if(j===null){x(t("settings.threadCleanup.invalidRetention")),f("retention");return}if(j===a){c(null),x("");return}v({eventLogRetentionDays:j},"retention")},I=()=>{if(i===null)return;const j=$a(g);if(j===null){x(t("settings.threadCleanup.invalidCap")),f("cap");return}if(j===i){d(null),x("");return}v({eventLogMaxBytes:j},"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:u!==null,onChange:j=>C(j.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:Jr,max:Yr,step:1,inputMode:"numeric",value:y,disabled:a===null||u!==null,"aria-invalid":h==="retention","aria-describedby":"thread-log-retention-help",onChange:j=>{c(j.target.value),x(""),f(null)},onBlur:N,onKeyDown:j=>{j.key==="Enter"&&j.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:u!==null,onChange:j=>w(j.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:zs/Wt,max:Xr/Wt,step:.25,inputMode:"decimal",value:g,disabled:i===null||u!==null,"aria-invalid":h==="cap","aria-describedby":"thread-log-cap-help",onChange:j=>{d(j.target.value),x(""),f(null)},onBlur:I,onKeyDown:j=>{j.key==="Enter"&&j.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")})]}),u!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}const Ha="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function mg(){const s=Rl(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=jn,u=()=>{const p=Tl({name:n,url:i},window.location.origin);if(!p.ok){o(p.error);return}Nn([...s,{id:Bl(s),name:p.name,url:p.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(p=>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:p.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:p.url,children:p.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>Nn(s.filter(m=>m.id!==p.id)),children:t("webPanels.settings.remove")})]},p.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:wn,disabled:d,"aria-invalid":c==="name",onChange:p=>{a(p.target.value),o("")},className:`${Ha} 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:p=>{r(p.target.value),o("")},onKeyDown:p=>{p.key==="Enter"&&u()},className:`${Ha} 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:u,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:wn})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:jn}):t("webPanels.settings.help")})]})})}const Ns="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",ot=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Ve(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},Wa=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Ve(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function xg(){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 u=m=>{r.current===o&&(c.current++,i(m))},p=s?.onState(u);return s?.state().then(m=>{c.current===d&&u(m)}).catch(()=>{}),()=>{r.current++,p?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(hg,{bridge:n}):e.jsx(gg,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function hg({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 p=++d.current,m=s.onState(x=>{p===d.current&&a(x.schedule??null)});return s.state().then(x=>{p===d.current&&a(x.schedule??null)}).catch(()=>{}),()=>{d.current++,m()}},[s]),!s.configureSchedule||!n?.enabled)return null;const u=async()=>{if(i||!s.configureSchedule)return;const p=d.current;r(!0),o("");try{const m=await s.configureSchedule({enabled:!1});p===d.current&&a(m.schedule??null)}catch{p===d.current&&o(t("companyBackup.scheduleFailed"))}finally{p===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(be,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{u()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),c&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:c})]})})}function gg({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[u,p]=l.useState(null),[m,x]=l.useState(""),[h,f]=l.useState(null),[b,y]=l.useState(""),[g,v]=l.useState(""),[C,w]=l.useState(null),[N,I]=l.useState(!1),j=l.useRef(0),L=l.useRef(0),k=l.useRef(0),P=l.useRef(void 0),S=l.useRef(!1),M=l.useRef(null),se=async()=>{const _=j.current,pe=++k.current,B=L.current;d(!0);try{await Promise.all([n.state().then(A=>{_===j.current&&pe===k.current&&L.current===B&&i(A)}),n.list().then(A=>{_===j.current&&pe===k.current&&c(A)})]),_===j.current&&pe===k.current&&x("")}catch{_===j.current&&pe===k.current&&x(t("companyBackup.loadFailed"))}finally{_===j.current&&pe===k.current&&d(!1)}};l.useEffect(()=>{const _=++j.current,pe=A=>{if(_!==j.current)return;L.current++,i(A);const H=A.lastBackupAt??A.schedule?.lastBackupAt;!A.busy&&!A.pendingRestore&&H&&H!==P.current&&(P.current=H,se())},B=n.onState(pe);return se(),()=>{j.current++,k.current++,B()}},[n]),l.useEffect(()=>{const _=M.current;if(!(!h||!_))return _.showModal(),()=>{_.close()}},[h]);const ne=N||a?.pendingRestore===!0,V=u!==null||!a||a.busy||ne,ie=()=>{f(null),y(""),v(""),w(null)},re=_=>{V||S.current||(x(""),y(""),v(""),w(null),f(_))},oe=async(_,pe)=>{if(V||S.current)return;S.current=!0,p(_),x("");const B=j.current;try{await pe(()=>B===j.current)}catch{B===j.current&&x(t(_==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{S.current=!1,B===j.current&&p(null)}},T=()=>{h?.kind==="create"&&oe("create",async _=>{await n.create({clientState:jc()}),_()&&(ie(),await se())})},R=async _=>{if(!n.configureSchedule||S.current||!a||_&&(V||h?.kind!=="schedule"||g!=="BACK UP THIS WORKSPACE DAILY"))return;S.current=!0,p("schedule"),x("");const pe=j.current,B=L.current;v("");try{const A=await n.configureSchedule(_?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});pe===j.current&&(L.current===B&&i(A),ie())}catch{pe===j.current&&x(t("companyBackup.scheduleFailed"))}finally{S.current=!1,pe===j.current&&p(null)}},E=()=>{h?.kind!=="restore"||h.entry.passwordRequired!==!1&&(b.length<12||b.length>1024)||oe("prepare",async _=>{const pe=b;y(""),w(null),v("");const B=await n.prepareRestore({id:h.entry.id,...h.entry.passwordRequired!==!1?{password:pe}:{}});_()&&w(B)})},D=()=>{h?.kind!=="restore"||!C||g!=="REPLACE"||oe("restore",async _=>{const pe=localStorage.getItem(Bn);if(pe&&pe!==C.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(Bn,C.id),await n.restore({id:C.id,confirmation:"REPLACE"}),_()&&(I(!0),ie())})},Q=()=>{h?.kind!=="delete"||g!=="DELETE"||oe("delete",async _=>{await n.delete({id:h.entry.id,confirmation:"DELETE"}),_()&&(ie(),await se())})},le=async()=>{const _=j.current;try{await n.cancel()}catch{_===j.current&&x(t("companyBackup.actionFailed"))}},ae=r?.backups.filter(_=>_.status==="ready")??[],U=r?r.backups.length-ae.length:0,te=a?.progress,me=m||a?.message,ce=(a?.busy||u)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:u==="restore"?t("backup.restoring"):te?t(`companyBackup.phase.${te.phase}`):t("companyBackup.working")}),te&&te.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:te.totalBytes,value:Math.min(te.bytesTransferred,te.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:ot(te.bytesTransferred),total:ot(te.totalBytes)})})]}),a?.busy&&u!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{le()},children:t("companyBackup.cancelTransfer")})]}),xe=h?.kind==="restore"?t("companyBackup.restore"):h?.kind==="delete"?t("companyBackup.delete"):h?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),de=a?.schedule,je=_=>new Intl.DateTimeFormat(Ve(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(_));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&&de&&e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.scheduleHelp")})]}),e.jsx(be,{"aria-label":t("companyBackup.daily"),checked:de.enabled,disabled:u!==null||!a||!de.enabled&&V,onClick:()=>de.enabled?void R(!1):re({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${de.status}`)}),de.enabled&&de.nextBackupAt&&Number.isFinite(de.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:je(de.nextBackupAt)})}),de.lastBackupAt&&Number.isFinite(de.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:je(de.lastBackupAt)})}),de.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:de.message})]}),ne?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(Tn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:V,onClick:()=>re({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:u!==null||a?.busy||ne||o,onClick:()=>{se()},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:ot(r.usedBytes),total:ot(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),U>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:U})}),r&&ae.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:ae.map(_=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0 text-[13px]",children:[e.jsx("div",{className:"text-ink",children:Wa(_)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[ot(_.sizeBytes),_.appVersion?` · ${_.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:_.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:V,onClick:()=>re({kind:"restore",entry:_}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:V,onClick:()=>re({kind:"delete",entry:_}),children:t("companyBackup.delete")})]})]},_.id))})]}),!h&&ce,!h&&me&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:me})]}),h&&e.jsx("dialog",{ref:M,"aria-labelledby":"company-backup-dialog-title",onKeyDown:_=>{(_.key==="Escape"||_.key==="Tab")&&_.stopPropagation()},onCancel:_=>{_.preventDefault(),u||ie()},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:xe}),ne&&e.jsx(Tn,{}),(h.kind==="restore"||h.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[Wa(h.entry)," · ",ot(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:_=>{_.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:V,checked:g==="BACK UP THIS WORKSPACE DAILY",onChange:_=>v(_.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:V||h.kind==="schedule"&&g!=="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(kc,{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:V,value:g,onChange:_=>v(_.target.value),className:Ns})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:V||g!=="REPLACE",onClick:D,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:_=>{_.preventDefault(),E()},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:V,value:b,onChange:_=>y(_.target.value),className:Ns})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:V||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:V,value:g,onChange:_=>v(_.target.value),className:Ns})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:V||g!=="DELETE",onClick:Q,children:t("companyBackup.delete")})]}),ce,me&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:me}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:u!==null,onClick:ie,children:t("companyBackup.cancel")})]})})]})}function fg({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(Oc,{size:12},a);case"cursor":return e.jsx(Lc,{size:12},a);case"gemini":return e.jsx(ai,{preset:"google",size:12},a);default:return e.jsx(Bc,{size:12},a)}})})}function Ga({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:o,onChange:d}){return e.jsxs("label",{className:O("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:u=>d(u.target.checked),className:"mt-0.5 size-4 shrink-0 cursor-[inherit] accent-[var(--color-accent)]"}),e.jsx("span",{className:"mt-0.5 flex size-4 shrink-0 items-center justify-center text-ink-secondary",children:s}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"text-[13px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"mr-2 text-[14px] font-medium text-ink",children:n}),e.jsx(fg,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const Zr="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 bg({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:o}){const d=i==="working";let u;if(!s)u=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)u=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(q,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:p,notes:m,done:x}=Ec(r);u=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:O("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(ve,{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:p}),m.map(h=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:h},h))]})]})}else!n||Pc(n)===0?u=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):u=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(Ga,{icon:e.jsx(bi,{size:15}),label:t("onboarding.import.skills"),summary:Ic(n),hint:t("onboarding.import.skillsHint"),sources:Ln(n.skills),checked:a.skills,disabled:d,onChange:p=>c({...a,skills:p})}),n.tools.length>0&&e.jsx(Ga,{icon:e.jsx(Tc,{size:15}),label:t("onboarding.import.tools"),summary:Rc(n),hint:t("onboarding.import.toolsHint"),sources:Ln(n.tools),checked:a.tools,disabled:d,onChange:p=>c({...a,tools:p})})]}),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:O(Zr,"mt-3"),children:[d&&e.jsx(q,{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:u})]})}function yg({client:s,local:n}){const[a,i]=l.useState(void 0),[r,c]=l.useState({skills:!0,tools:!0}),[o,d]=l.useState("idle"),[u,p]=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 m=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);Nd("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),p(h),d("idle")}catch{d("failed")}}};return e.jsx(bg,{local:n,detection:a,chosen:r,status:o,result:u,onChoose:c,onBring:()=>{m()}})}function vg(){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(Sc,{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:O(Zr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Ja,{size:14,"aria-hidden":"true",className:O("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Cc,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function el({client:s=Nc}){const{state:n}=G();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(yg,{client:s,local:wc(n.config?.cloudHome===!0)}),e.jsx(vg,{})]})}function tl({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(kg,{simple:s}),e.jsx(jg,{simple:s}),e.jsx(Ng,{simple:s})]})}const Va=()=>typeof Notification<"u"?Notification.permission:"default";function kg({simple:s=!1}){const[n,a]=l.useState(Va),i=zc();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(Va())};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 On(!i);const o=await _c();o&&(a(o),o==="granted"&&On(!0))};return e.jsx(ge,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(be,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function jg({simple:s=!1}){const n=Mc();return e.jsx(ge,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(be,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Fc(!n)})})}function Ng({simple:s=!1}){const n=Dc();return e.jsx(ge,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(be,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>Uc(!n)})})}function sl(){const{state:s,dispatch:n}=G(),a=$c(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!Kc(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const u=await F("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:u})}catch(u){o(u instanceof Error?u.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(ge,{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(be,{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 wg=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],Sg=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function Cg({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(Ce,{label:t("settings.group.account"),block:"general",children:e.jsxs(Ee,{children:[s("general")&&e.jsx(dg,{}),s("general")&&e.jsx(Gr,{row:!0}),s("general")&&e.jsx(_i,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(fr,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(Ce,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(Ee,{children:[e.jsx(Mr,{simple:!0}),e.jsx(Eg,{onLooks:a}),e.jsx(Nr,{}),e.jsx(ki,{}),e.jsx(wr,{}),e.jsx(Fi,{simple:!0})]})}),s("appearance")&&e.jsx(Ce,{label:t("settings.simple.group.typing"),children:e.jsxs(Ee,{children:[e.jsx(Cs,{simple:!0}),e.jsx(Di,{simple:!0}),e.jsx(Ui,{simple:!0})]})}),s("appearance")&&e.jsx(Ce,{label:t("notifications.title"),children:e.jsx(Ee,{children:e.jsx(tl,{simple:!0})})}),s("general")&&e.jsx(Ce,{label:t("settings.simple.group.system"),children:e.jsxs(Ee,{children:[e.jsx(Gi,{simple:!0}),e.jsx(ji,{simple:!0}),e.jsx(Vi,{}),e.jsx(qi,{}),e.jsx(Wi,{simple:!0})]})}),s("import")&&e.jsx(Ce,{label:t("settings.section.import"),block:"import",children:e.jsx(Ae,{children:e.jsx(el,{})})}),s("organization")&&e.jsx(Ce,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Cr,{})}),s("activity")&&e.jsx(Ce,{label:t("settings.section.activity"),block:"activity",children:e.jsx(br,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(Ee,{children:e.jsx(ge,{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(Ee,{children:e.jsx(Es,{simple:!0})})})]})}function Eg({onLooks:s}){const n=un(),a=$s.find(r=>r.id===Ya(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(ge,{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 Ag({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(Fr,{})}),n&&e.jsx(Ee,{children:e.jsx(Mi,{})})]})}function Pg({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(Ce,{block:"more-sections",children:e.jsx(Ee,{children:s.map(({id:i,labelKey:r})=>e.jsx(ge,{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(Ce,{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(Dr,{})}),e.jsx(X,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx($r,{})}),e.jsx(Vr,{}),e.jsx(qr,{}),e.jsx(Qr,{}),e.jsx(er,{}),e.jsx(Ee,{children:e.jsx(sl,{})})]})})]})}function Ig({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(Ae,{children:[e.jsx(sr,{simple:!0,more:n("ai-more")}),e.jsx(Ee,{children:e.jsx(zi,{simple:!0})})]})}),s("connections")&&e.jsx(Ae,{children:e.jsx(qt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function Rg({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(Ce,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(Ae,{children:e.jsx(rr,{})})}),s("companion")&&e.jsxs(Ce,{label:t(vi()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(Ce,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(Ee,{children:[e.jsx(Bi,{}),e.jsx(Li,{})]}),e.jsx(Oi,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(jr,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(qt,{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 Tg({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=Hc();return qd(),e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(Wc,{usage:i,upgrade:r,children:c}):e.jsx(Ae,{note:"settings.adminOnly.usage",children:e.jsx(Ch,{})})}),(i||s("usage"))&&e.jsxs(qt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(Gc,{usage:i,upgrade:r}),s("usage")&&e.jsx(Ae,{note:"settings.adminOnly.usage",children:e.jsx(Lr,{})})]}),s("cloudAccount")&&e.jsxs(Ce,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(Jd,{}),children:[e.jsx(Ee,{children:e.jsx(_i,{place:"plan",usage:i,upgrade:r})}),e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const nl=()=>`${Se()} ${Vc()}`;function Bg(){const s=qc(!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(ge,{title:nl(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function Lg({remoteActive:s}){return e.jsx(Ce,{block:"updates",children:e.jsxs(Ee,{children:[window.ogb?.updater?e.jsx(Ri,{title:nl()}):e.jsx(Bg,{}),e.jsx(yi,{}),!s&&e.jsx(Ti,{}),e.jsx(Ji,{simple:!0})]})})}const qa=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],pn=[{id:"general",group:"you",labelKey:"settings.section.general",icon:fi,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",..._u()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:tu,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:Jc,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:lu,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:mi,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:Yc,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:Xc,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:bi,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:is,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:$i,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:Xt,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:Ds,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:is,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:Xd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:Qc,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:Gs,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:Ut,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:Ut,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:iu,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:is,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:Zc,keywords:["early","preview","learn","skill","authoring"]}],Og=[{id:"general",labelKey:"settings.section.general",icon:ed,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:Ut,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:td,sections:["engines","connections"],keywords:["new bots","defaults","effort"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:$i,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:sd,sections:["usage","cloudAccount"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:Zd,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],Ms=["backups","experimental","workspaces","skills","decisionModel","imageGeneration"],zg={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function Mg(s,n){const a=Og.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=Ms.includes(n)&&s.has(n)?pn.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 Fg(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Qs(s,i)}function Dg(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=pn.find(r=>r.id===a);return i?Fs(i,n):!1})}function Fs(s,n){return!n||s.id==="connections"&&ft.some(a=>Ks(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function Ug(s){return s?ft.filter(n=>Ks(n,s)).slice(0,8):[]}const _g=s=>s.uses?Ss(s.uses,s.id):Ss(s.id);function mf(){return e.jsx(Js,{modal:!0,children:e.jsx($g,{})})}function $g(){const s=wd(),{state:n,dispatch:a}=G(),i=Ll(),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),u=l.useRef(null),p=l.useRef(i),[m,x]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>x("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>x("")),[]);const h=m.trim().toLowerCase(),f=Gt(),b=vi(),y=pn.map(B=>B.id==="companion"?{...B,labelKey:b?"settings.section.phoneDevices":"settings.section.thisServer"}:B),v=y.filter(B=>!r||B.id==="companion"||B.id==="appearance"||B.id==="desktopWorkspaces").filter(B=>B.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(B=>B.id!=="organization"||!!window.ogb?.organization).filter(B=>B.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(B=>B.id!=="workspaces"||zr(n.config)).filter(B=>B.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(B=>B.id!=="activity"||!window.ogb&&f===!0).filter(B=>B.id!=="botAccess"||!!n.config?.team&&f===!0).filter(B=>(B.id!=="skills"||zn(n.config))&&(B.id!=="cloudAccount"||Ol)),C=v.filter(B=>Fs(B,h)),w=new Set([...v.map(B=>B.id),...r?[]:["updates"]]),N=i?[]:Mg(w,o),I=N.filter(B=>Dg(B,h)),j=N.find(B=>B.sections.includes(o)),L=i?y.find(B=>B.id===o)?.labelKey:j?.labelKey,k=i?C.some(B=>B.id===o)?void 0:C[0]?.id:j&&I.includes(j)?void 0:I[0]&&(I[0].sections.find(B=>C.some(A=>A.id===B))??I[0].sections[0]);l.useEffect(()=>{k&&a({type:"toggleAppSettings",open:!0,section:k})},[a,k]);const[P,S]=l.useState({}),M=Qa();l.useEffect(()=>{M&&S(B=>B["ai-keys"]?B:{...B,"ai-keys":!0})},[M]);const se=B=>{const A=h!==""||(P[B]??zg[c]===B);return{id:B,open:A,onToggle:()=>S(H=>({...H,[B]:!A}))}},[ne,V]=l.useState(null),ie=ne?.for===c?ne.view:null,re=(B,A=c)=>V(B&&{view:B,for:A});l.useEffect(()=>{V(B=>B?.for===c?B:null)},[c]);const[oe,T]=l.useState(null),R=i||zl||!h?[]:wg.filter(B=>t(B).toLowerCase().includes(h)),E=v.filter(B=>Ms.includes(B.id)),D=r||!v.some(B=>B.id==="connections")?[]:Ug(h),Q=B=>D.map(A=>e.jsx("button",{type:"button","data-settings-key-result":A.id,className:B,onClick:()=>{x(""),re(null),a(_g(A))},children:e.jsxs("span",{children:[t(A.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(nd(A).titleKey)]})]})},A.id)),le=j?.sections.indexOf(o)??0,ae=!i&&c==="remote"?"remote":o;l.useEffect(()=>{u.current&&Fg(u.current,ae,i?0:ae===o?le:1)},[i,ae,o,le]),l.useEffect(()=>{if(!oe)return;const B=u.current?.querySelector(`[data-settings-block="${oe}"]`);u.current&&B&&Qs(u.current,B),T(null)},[oe]),l.useEffect(()=>{const B=document.activeElement instanceof HTMLElement?document.activeElement:null,A=d.current,H=A?.querySelector("[data-settings-search]");p.current&&H?.checkVisibility()?H.focus():A?.focus();const he=W=>{if(!s())return;if(!p.current&&A&&document.activeElement===A&&W.key.length===1&&!W.metaKey&&!W.ctrlKey&&!W.altKey&&H?.checkVisibility()){W.preventDefault(),H.focus(),x(ee=>ee+W.key);return}if(W.defaultPrevented||A&&[...A.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(ee=>ee.getClientRects().length))return;if(W.key==="Escape"){W.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(W.key!=="Tab"||!A)return;const Ne=Array.from(A.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(ee=>ee.checkVisibility());if(Ne.length===0){W.preventDefault(),A.focus();return}const ze=Ne[0],qe=Ne[Ne.length-1],$=document.activeElement;W.shiftKey&&($===ze||!A.contains($))?(W.preventDefault(),qe.focus()):!W.shiftKey&&$===qe&&(W.preventDefault(),ze.focus())};return window.addEventListener("keydown",he),()=>{window.removeEventListener("keydown",he),B?.focus()}},[a,s]);const U=B=>a({type:"toggleAppSettings",open:!0,section:B}),te=n.appSettingsPhonePairing,me=Id(n.config?.cloudHome===!0)==="computer",ce={client:e.jsx(Lx,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||b?null:e.jsx(Cx,{}),pairing:b?null:e.jsx(ur,{cloudHome:n.config?.cloudHome===!0,focusRequest:me?0:te,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(lx,{profileEmail:n.config?.profile?.email,focusRequest:te,simple:!i}):null},xe=B=>{switch(B){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(ya,{}),ce.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Cr,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(vh,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>a(Rd()),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(Es,{}),e.jsx(ji,{}),e.jsx(Vi,{}),e.jsx(Yd,{}),e.jsx(id,{}),e.jsxs(X,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(Wr,{}),e.jsx(Gr,{})]}),e.jsx(Cs,{}),e.jsx(Gi,{}),e.jsx(Gd,{}),e.jsx(sl,{}),e.jsx(Wi,{}),e.jsx(yi,{}),e.jsx(zi,{}),e.jsx(X,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(Dr,{})}),e.jsx(X,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx($r,{})}),e.jsx(Vr,{}),e.jsx(qr,{}),e.jsx(Qr,{}),e.jsx(qi,{}),e.jsx(mg,{}),!r&&e.jsx(Ti,{}),e.jsx(Ri,{}),e.jsx(Ji,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(Mr,{}),e.jsx(X,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(Fr,{})}),e.jsx(qx,{}),r&&e.jsx(Es,{}),r&&e.jsx(Cs,{}),e.jsx(Xh,{}),e.jsx(Qh,{}),e.jsx(Fi,{}),e.jsx(Di,{}),e.jsx(Ui,{}),e.jsx(Zh,{}),e.jsx(ki,{}),e.jsx(wr,{}),e.jsx($d,{}),e.jsx(Kd,{}),e.jsx(Hd,{}),e.jsx(tl,{}),!r&&e.jsx(Mi,{}),e.jsx(Wd,{})]});case"experimental":return e.jsx(_d,{});case"connections":return e.jsx(Ae,{children:e.jsx(Uu,{})});case"decisionModel":return e.jsx(Ae,{children:e.jsx(Xu,{})});case"imageGeneration":return e.jsx(Ae,{children:e.jsx(rp,{})});case"engines":return e.jsx(Ae,{children:e.jsx(sr,{})});case"backups":return e.jsxs(Ae,{children:[e.jsx(ad,{}),e.jsx(xg,{})]});case"import":return e.jsx(Ae,{children:e.jsx(el,{})});case"companion":return e.jsxs(e.Fragment,{children:[ce.companion,ce.pairing,ce.domain,window.ogb?.environments?null:ce.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(Bi,{}),e.jsx(Li,{}),e.jsx(Oi,{}),e.jsx(Ae,{children:e.jsx(rr,{})})]});case"logins":return e.jsx(jr,{});case"usage":return e.jsx(Ae,{note:"settings.adminOnly.usage",children:e.jsx(Lr,{})});case"skills":return zn(n.config)?e.jsx(Uh,{}):null;case"people":return e.jsx(fr,{});case"activity":return e.jsx(br,{});case"botAccess":return e.jsx(gx,{});case"workspaces":return e.jsx(Vh,{});default:return null}},de=()=>{U("general"),re("more","general")},je=B=>{const A=H=>B.sections.includes(H);switch(B.id){case"general":return ie==="looks"?e.jsx(Ag,{toolCalls:!r,onBack:()=>{re(null),T("appearance")}}):ie==="more"?e.jsx(Pg,{sections:E,onOpen:H=>{re(null),U(H)},onBack:()=>{re(null),T("more")}}):e.jsx(Cg,{has:A,peopleOpen:o==="people",onLooks:()=>re("looks"),onMore:A("general")?()=>re("more"):void 0});case"ai":return e.jsx(Ig,{has:A,disclose:se,connections:xe("connections")});case"computer":return e.jsx(Rg,{has:A,remoteAccess:ce,servers:e.jsx(ya,{}),disclose:se});case"billing":return e.jsx(Tg,{has:A,disclose:se,cloudAccount:xe("cloudAccount")});case"updates":return e.jsx(Lg,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[Ms.includes(B.sections[0])&&w.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:de,children:t("settings.simple.looks.back")})}),B.sections.map(H=>e.jsx("section",{"data-settings-block":H,className:"flex scroll-mt-4 flex-col gap-4",children:xe(H)},H))]})}},_=()=>a({type:"toggleAppSettings",open:!1}),pe=(B,A)=>e.jsxs("div",{className:B,children:[e.jsx(jt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:m,onChange:H=>x(H.target.value),onKeyDown:H=>{H.key==="Escape"&&(H.stopPropagation(),m?x(""):_())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:A})]});if(!i){const B=j?.id==="general"?ie:null,A="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",H=W=>{re(null),U(W)},he=h?[...E.filter(W=>Fs(W,h)).map(W=>({key:W.id,labelKey:W.labelKey,open:()=>H(W.id)})),...(w.has("general")?Sg:[]).filter(W=>t(W).toLowerCase().includes(h)).map(W=>({key:W,labelKey:W,open:()=>{de(),T("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:Fn(),onMouseDown:W=>W.target===W.currentTarget&&_(),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.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:[pe("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&&R.length===0&&he.length===0&&D.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:m.trim()})}),I.map(W=>{const Ne=W.icon,ze=W===j;return e.jsxs("button",{type:"button","data-settings-page":W.id,onClick:()=>H(W.sections[0]),"aria-current":ze?"page":void 0,className:O("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",ze?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(Ne,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:t(W.labelKey)})]},W.id)}),R.map(W=>e.jsx("button",{type:"button","data-settings-advanced-only":W,onClick:()=>{x(""),H("general"),T("advanced-mode")},className:A,children:e.jsxs("span",{children:[t(W)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},W)),he.map(W=>e.jsx("button",{type:"button","data-settings-more-result":W.key,onClick:()=>{x(""),W.open()},className:A,children:e.jsxs("span",{children:[t(W.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},W.key)),Q(A)]}),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(ye,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:j?.id??"",onChange:W=>{x("");const Ne=N.find(ze=>ze.id===W.target.value);Ne&&H(Ne.sections[0])},children:N.map(W=>e.jsx("option",{value:W.id,children:t(W.labelKey)},W.id))}),e.jsx("h2",{className:"hidden truncate text-[17px] font-medium leading-6 tracking-[-0.008em] text-ink sm:block",children:B==="looks"?t("settings.simple.page.looks"):B==="more"?t("settings.simple.more.title"):j?t(j.labelKey):null})]}),e.jsx("button",{type:"button",onClick:_,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Mn("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(We,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{ref:u,"data-settings-scroll":!0,className:O("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]",hi,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(Ba,{config:n.config}),j?je(j):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:Fn(),onMouseDown:B=>B.target===B.currentTarget&&_(),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")}),pe("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:m.trim()})}),qa.map(B=>{const A=C.filter(H=>H.group===B.id);return A.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${B.id}`,"data-settings-group":B.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${B.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(B.labelKey)}),A.map(({id:H,labelKey:he,icon:W})=>e.jsxs("button",{"data-settings-section":H,onClick:()=>U(H),"aria-current":o===H?"page":void 0,className:O("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===H?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(W,{size:15,className:"shrink-0"}),t(he)]},H))]},B.id)}),Q("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(ye,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:B=>{x(""),U(B.target.value)},children:qa.map(B=>{const A=v.filter(H=>H.group===B.id);return A.length===0?null:e.jsx("optgroup",{label:t(B.labelKey),children:A.map(({id:H,labelKey:he})=>e.jsx("option",{value:H,children:t(he)},H))},B.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:L?t(L):null}),e.jsx("button",{onClick:_,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Mn("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(We,{size:18})})]}),e.jsxs("div",{ref:u,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(Ba,{config:n.config}),xe(o)]})]})]})]})}export{pn as SECTIONS,qa as SETTINGS_GROUPS,zg as SIMPLE_FOLDED,Ms as SIMPLE_HIDDEN_SECTIONS,Og as SIMPLE_PAGES,mf as SettingsModal,Ug as keySearchResults,_g as openKeyResult,Fg as revealSettingsBlock,Fs as sectionMatches,Mg as simpleSettingsPages};
|