limixbot 0.3.11 → 0.3.12
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-BODxWmfO.js → ActivityPanel-CJM61CWQ.js} +1 -1
- package/dist/assets/{App-DPG1sq1r.js → App-DRnqqiJP.js} +125 -125
- package/dist/assets/{AppEventEditor-QyHQdp7V.js → AppEventEditor-1hupO_kL.js} +1 -1
- package/dist/assets/{BotSettingsDialog-BCNOcqOS.js → BotSettingsDialog-B56-kmya.js} +4 -4
- package/dist/assets/{BrowserPanel-BqPnj2Bz.js → BrowserPanel-BXBygd1y.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-BMk7i2tc.js → BrowserProfilesManager-CzzGhZGz.js} +1 -1
- package/dist/assets/CloudAddDialog-MMhMrVK3.js +1 -0
- package/dist/assets/{ComputerFilesPane-BWmAv8JT.js → ComputerFilesPane-Hpxjnk2e.js} +1 -1
- package/dist/assets/ComputerPanel-CMce64RT.js +2 -0
- package/dist/assets/{DataPanel-BgfqxYo9.js → DataPanel-BQ7Ua1Oq.js} +1 -1
- package/dist/assets/{DesktopViewer-BMD84CFj.js → DesktopViewer-BRzNtGEm.js} +1 -1
- package/dist/assets/{FilesView-CGYpajry.js → FilesView-DQYXl0zm.js} +1 -1
- package/dist/assets/{GrokMoveDialog-B3aEa4hb.js → GrokMoveDialog-Dk-pwczv.js} +1 -1
- package/dist/assets/{InspectorPanel-CTNcZYHr.js → InspectorPanel-CvnM0TFW.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-CBmbtwhH.js → KeyboardShortcutsModal-BQ8aAw16.js} +1 -1
- package/dist/assets/{LiveDesktop-7h7Mxr41.js → LiveDesktop-Cr7uAFoQ.js} +1 -1
- package/dist/assets/LocalVmWorkspace-BJ-i68MR.js +1 -0
- package/dist/assets/MacLocalControl-DE8MVZkU.js +1 -0
- package/dist/assets/{MarkdownFilePreview-_1MC5Db0.js → MarkdownFilePreview-B_6azXNT.js} +1 -1
- package/dist/assets/{MenuMotion-C1J3xC0E.js → MenuMotion-BDYr4RxL.js} +1 -1
- package/dist/assets/{NewBotDialog-C35vqYL4.js → NewBotDialog-D9fUysLU.js} +1 -1
- package/dist/assets/PhoneAppDialog-DUv4Qx8n.js +1 -0
- package/dist/assets/{PlacesRail-DnedL3jM.js → PlacesRail-yZdo57pP.js} +1 -1
- package/dist/assets/{PluginsPanel-CvZhoTE-.js → PluginsPanel-DYuWdWZd.js} +1 -1
- package/dist/assets/{ProIntroduction-B1QqcZmr.js → ProIntroduction-DapZkP7I.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-DU6QyjIY.js → RemoteAgentSettingsPanel-sNv3TbBd.js} +1 -1
- package/dist/assets/{RoomPanel-Om9r5yMG.js → RoomPanel-DrlyOJKZ.js} +1 -1
- package/dist/assets/{RoutinesPage-BWJ5Z1Sk.js → RoutinesPage-CIo30TVq.js} +2 -2
- package/dist/assets/SettingsModal-BpJhi2nc.js +11 -0
- package/dist/assets/{ShareTeamDialog-DkKdhm01.js → ShareTeamDialog-CH1ts7Uj.js} +1 -1
- package/dist/assets/{SignedInSites-Dxnqcjlx.js → SignedInSites-CisTAQW0.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-C3QFOJmQ.js → TeamLibraryPanel-DvnKye05.js} +1 -1
- package/dist/assets/TeamMapPage-JOiilgs0.js +1 -0
- package/dist/assets/TriggersPage-DQ3HQ6_i.js +1 -0
- package/dist/assets/{VisibilitySection-DiD7SczA.js → VisibilitySection-DXfPp0Ql.js} +1 -1
- package/dist/assets/{WebhookTrigger-w_Pjci5K.js → WebhookTrigger-BYeOyOpX.js} +1 -1
- package/dist/assets/{WorksOnGrid-B84wDbPo.js → WorksOnGrid-8fCnUzpQ.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-Dr-8nZOt.js → abnfDiagram-YUKMZFIV-Boj-Bkbs.js} +1 -1
- package/dist/assets/{activity-bTJO9mSI.js → activity-MpAxS_kw.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-23P1y-s5.js → architectureDiagram-47P4ROYG-Cl-ocqce.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-D1mBvWuR.js → blockDiagram-E7TT5TSB-0nSQiv6g.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-BKK5iCAq.js → c4Diagram-CRA5TL53-Cx9iymkb.js} +1 -1
- package/dist/assets/{calendar-days-Ckb7s5k5.js → calendar-days-DXHDRm_4.js} +1 -1
- package/dist/assets/channel-BStWWrSt.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-C6ElI8Gj.js → chunk-2Q5K7J3B-0rIrumUG.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-B9VKa5BI.js → chunk-5VM5RSS4-w9e6iKvs.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-CrgJv6B8.js → chunk-7TKQ45FW-c4KxVKkf.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-CVe28FV5.js → chunk-AW2ZBBNX-DmaBcuOP.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-BLPrVPPQ.js → chunk-FVRAUYC3-BLzfqLHR.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-BB9kWhE5.js → chunk-HTAEGDNF-BN48XtBm.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-y2b0u5g-.js → chunk-JWPE2WC7-D2NACa6i.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-BMp5NWQw.js → chunk-KQW6MTUR-CbAfnxxG.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-gUdzE10_.js → chunk-XXDRQBXY-Bwg-DPP_.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-DNfrg4LR.js → classDiagram-v2-K4WV4PDN-Dh3ohoZp.js} +1 -1
- package/dist/assets/{coins-CBbaS4z-.js → coins-Bv8-qll4.js} +1 -1
- package/dist/assets/{core-BNIINisk.js → core-DeJAGBXR.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-D84YhUzh.js → cose-bilkent-JH36ORCC-DCHadn0L.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-DMBZCt-X.js → cynefin-EF2NZ3EQ-ClpPPxUg.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-BZhcnyNF.js → cynefinDiagram-3GCD6N5R-DZ5l7nkL.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-DY68eKcA.js → dagre-W4DXFKR2-BagTvT62.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-Bv-0-qqw.js → diagram-2UJZ2QOL-DuByootb.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-CEnRLa7p.js → diagram-OVF4WLC6-BQ8Cvr0D.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-D3UjLOE9.js → diagram-PFPMY2P6-D_pklaf9.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-CJCYH8n7.js → diagram-UMYRVEAY-1BuHq7tR.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-D_YEp1XW.js → diagram-YEKJPTXX-CK0cPx8n.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-C7RgDQ_I.js → diagram-ZIFT7M5P-DVzPho45.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-CVbikCfA.js → ebnfDiagram-VR2GEFS7-D8UO_5sE.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BQv73EB6.js → elk-IJKZMXRS-BRigfR5V.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-ZMuLXVBq.js → erDiagram-O2IAPWRE-CXHPobWj.js} +1 -1
- package/dist/assets/{file-up-BsMMeeDy.js → file-up-CQezfdJk.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-CkF5DDZj.js → flowDiagram-OXPTDLAJ-CqKD6jh8.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-BaYEK3at.js → ganttDiagram-R7TSEDQI-C9FV3gsA.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-eVpEz6un.js → gitGraphDiagram-XJZIOB7I-CRu4dnr_.js} +1 -1
- package/dist/assets/{import-name-DzZIJafj.js → import-name-dEG0japD.js} +1 -1
- package/dist/assets/{index-BSIcl6wl.js → index-B4HW_T-k.js} +1 -1
- package/dist/assets/{index-BkcZ5EE3.js → index-COnd2OMZ.js} +2 -2
- package/dist/assets/{infoDiagram-5W2HQ5XZ-cLDLLbyG.js → infoDiagram-5W2HQ5XZ-CCRjb2CQ.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-Dxie_tdO.js → ishikawaDiagram-K3B6WC7H-TaNPsGZS.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-DWzHn4oz.js → journeyDiagram-COXZFDF6-Dz7YIIc2.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-BFNqkDTK.js → kanban-definition-P3RFRI5V-Cg69Fpp8.js} +1 -1
- package/dist/assets/{mcp-servers-DJceaBjT.js → mcp-servers-Ih6dI7Ga.js} +1 -1
- package/dist/assets/{mermaid.core-Cn7buzY3.js → mermaid.core-DiG3LoLz.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-DVS-3JPN.js → mindmap-definition-LZFPQGKD-nxP4f0fq.js} +1 -1
- package/dist/assets/{minimize-BpyGl78C.js → minimize-B_k_fmmo.js} +1 -1
- package/dist/assets/{monitor-FKQbSjca.js → monitor-BfmnPU-I.js} +1 -1
- package/dist/assets/{new-bot-Df7cGS3Z.js → new-bot-CQm0FPc5.js} +2 -2
- package/dist/assets/{org-library-CT3HZbof.js → org-library-C2li0IRL.js} +1 -1
- package/dist/assets/{package-format-CgnYlqV5.js → package-format-B3whu9DW.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-qwRUMAPC.js → pegDiagram-BGZESJAR-gPjpGcNH.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-CTzsGZac.js → pieDiagram-CAPJLFHJ-Cgh25Z4_.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-B7Mx793h.js → quadrantDiagram-GDMTTRAM-DD9luyqA.js} +1 -1
- package/dist/assets/{rail-B_BFwBxk.js → rail-B1mj4zlo.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-zMy3LSMK.js → railroadDiagram-SM67HX2B-CS_TYko7.js} +1 -1
- package/dist/assets/{remote-desktop-panel-DPutXzoI.js → remote-desktop-panel-DIllbP7i.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-Dm_K18IR.js → requirementDiagram-X7JNWC4A-BePHia6E.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-Dx_FP9cL.js → sankeyDiagram-UM26HJRW-24ExCXGS.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-D3tIz4Te.js → sequenceDiagram-ZO4K6R2Y-Dtmx27I5.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-CwiX8-_Z.js → sizeCapture-INFHLROL-2LvmoT1T.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-Biv0Rjec.js → stateDiagram-v2-TBUQTH76-moL2SIo9.js} +1 -1
- package/dist/assets/{styles-Cm26P6hN.js → styles-6RbfQIY7.js} +1 -1
- package/dist/assets/{swimlanes-N4OXWK64-Daie2jEh.js → swimlanes-N4OXWK64-D95Pk8qh.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-DByi9G3i.js +8 -0
- package/dist/assets/{team-share-DyK3j6N2.js → team-share-0GXKeixY.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-_OnzqB6-.js → timeline-definition-YOQAKGHF-HM-J25k2.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-CITmAUqx.js → usecaseDiagram-VIAY4XPW-C6q6bCzJ.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-BAx_UxlU.js → vennDiagram-BLWOH2XV-hf0dh2yT.js} +1 -1
- package/dist/assets/{vi-GKa1-xWX.js → vi-CVDyZGky.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-DjWzxLzl.js → wardleyDiagram-YMQ3BMBF-CpT_eRn9.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-DpQbiSMS.js → xychartDiagram-TAQBALBS-D6g1V9DG.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-S7ngrMRc.js +0 -1
- package/dist/assets/ComputerPanel-BDPrbwmC.js +0 -2
- package/dist/assets/LocalVmWorkspace-Bxvn8CQX.js +0 -1
- package/dist/assets/MacLocalControl-C3rHusSl.js +0 -1
- package/dist/assets/PhoneAppDialog-DhEEfxbl.js +0 -1
- package/dist/assets/SettingsModal-DmFTwQIH.js +0 -11
- package/dist/assets/TeamMapPage-CpPh11mE.js +0 -1
- package/dist/assets/TriggersPage-YjklCz2p.js +0 -1
- package/dist/assets/channel-_uzpXF9W.js +0 -1
- package/dist/assets/index-DvRd5uj9.js +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-EP8Nb7CO.js +0 -8
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as nt,j as e,t,r as l,a as O,S as at,f as fe,p as us,g as ms,a8 as hr,X as Be,i as ps,C as fr,a9 as ua,L as gt,aK as br,aT as yr,a0 as vr,B as jr,b as Te,aU as kr,aV as Nr,aW as Ks,ao as Hs,aX as wr,ap as Sr,aY as Cr,aZ as Er,a3 as Ar,G as Ir,a_ as Pr,a$ as xs,b0 as Rr,b1 as Tr,b2 as $s,b3 as gs,l as Br,b4 as Lr,m as Ws,b5 as ma,d as Or,b6 as zr,q as Mr,b7 as Ur,o as Fr,as as Dr,b8 as Gs,ar as _r,b9 as Kr,ba as Vs,bb as qs,bc as Js,bd as Hr,be as $r,ac as Wr,bf as Gr,bg as Vr}from"./styles-6RbfQIY7.js";import{bP as vt,u as $,S as xe,n as M,D as me,cM as qr,cI as pa,T as Se,gY as Pe,eK as He,gZ as Jr,a0 as Re,eI as Yr,eJ as Xr,g_ as Yt,g$ as Qe,h0 as xa,h1 as hs,h2 as fs,h3 as Qr,e0 as Ys,h4 as ga,h5 as ha,h6 as Zr,h7 as el,h8 as tl,bN as de,b_ as J,e8 as Xt,eH as sl,h9 as fa,ha as xt,hb as jt,hc as ba,hd as ya,he as Ie,hf as Me,hg as nl,hh as al,hi as il,hj as rl,hk as ll,C as $e,hl as va,hm as ol,hn as cl,ho as ja,hp as ka,hq as be,hr as ye,dp as Xs,hs as kt,ht as dl,hu as ul,hv as ml,hw as pl,hx as xl,gR as Na,bt as gl,hy as Xe,W as hl,dH as fl,Q as wa,hz as Sa,hA as bl,aQ as ht,ft as et,fu as tt,hB as yl,P as bs,r as vl,ck as jl,gG as kl,hC as Nt,hD as Ca,hE as Nl,hF as wl,hG as Qs,hH as Ea,hI as wt,hJ as Aa,hK as Sl,hL as Cl,hM as El,hN as Al,G as Il,hO as Pl,hP as st,ef as St,hQ as Rl,hR as Tl,hS as Bl,hT as Ll,fB as Ol,hU as Zs,hV as zl,hW as Ml,K as Ul,hX as en,hY as Fl,ed as Ia,hZ as Dl,h_ as _l,h$ as Kl,i0 as Hl,i1 as $l,i2 as Wl,i3 as Pa,i4 as Gl,i5 as Vl,i6 as ql,i7 as Jl,i8 as Yl,i9 as Xl,ia as Ra,ib as Ql,ic as Zl,dN as eo,id as to,e9 as so,ie as no,ig as ao,ih as io,c as ro,ii as tn,ij as lo,ik as sn,l as oo,il as co,im as uo,io as mo,bH as po,ip as xo,iq as go,ir as ho,is as fo,it as Ta,fr as Je,iu as bo,fq as yo,iv as vo,iw as jo,ix as ko,iy as No,iz as wo,iA as So,iB as Co,iC as Eo,iD as ys,iE as Ao,fh as Ba,m as Io,iF as Po,iG as Ro,iH as nn,iI as To,iJ as Bo,iK as an,iL as Lo,bj as Oo,iM as zo,iN as Mo,iO as Uo,iP as Fo,iQ as Do,iR as rn,iS as _o,by as La,iT as Ko,bz as Ho,iU as $o,iV as Wo,iW as Go,iX as Vo,iY as qo,iZ as Jo,i_ as Yo,i$ as Xo,j0 as ln,gu as Qo,j1 as Zo,j2 as ec,j3 as Oa,j4 as tc,j5 as sc,j6 as nc,j7 as za,j8 as Ma,j9 as Ua,ja as ac,jb as ic,jc as rc,d5 as lc,I as oc,jd as cc,eC as dc,bY as on,je as cn,e$ as dn,d$ as uc,a2 as mc,aC as pc,jf as xc,jg as gc,jh as hc}from"./App-DRnqqiJP.js";import{L as V,P as Ne,z as it,E as fc,M as bc,ak as yc,a0 as vc,X as jc,K as kc,x as vs,C as Fa,B as Ct,al as Nc,am as wc,an as Sc,d as Da,r as Cc,A as Ec,U as _a,c as Ac,ao as Ic,ap as Pc,N as Rc,ac as Tc,aq as Bc,b as Lc,y as Oc,V as zc,O as Lt}from"./PlacesRail-yZdo57pP.js";import{C as js,a as Mc,R as Ce}from"./MenuMotion-BDYr4RxL.js";import{l as Ka,M as Uc,w as Fc}from"./MacLocalControl-DE8MVZkU.js";import{Q as Dc}from"./VisibilitySection-DXfPp0Ql.js";import{r as Ha,a as $a,b as _c,i as Kc,C as Hc,c as $c,p as Wc}from"./index-COnd2OMZ.js";import{c as Gc,A as Vc,w as qc,d as Jc,e as un}from"./activity-MpAxS_kw.js";import{U as Wa,R as Ga,B as Va,S as qa,a as Ja,D as Ya,T as Xa,C as Qa,L as Qt,b as Za,F as ei,A as Zt,E as Yc,c as Xc,P as Qc,d as Zc,e as ed,N as td}from"./NewBotDialog-D9fUysLU.js";import{a as sd,u as nd,C as ti,b as ad,P as id}from"./ProIntroduction-DapZkP7I.js";import{M as si}from"./monitor-BfmnPU-I.js";import{C as rd}from"./coins-Bv8-qll4.js";import"./org-library-C2li0IRL.js";import"./package-format-B3whu9DW.js";import"./mcp-servers-Ih6dI7Ga.js";import"./WorksOnGrid-8fCnUzpQ.js";import"./new-bot-CQm0FPc5.js";import"./RoutinesPage-CIo30TVq.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-0GXKeixY.js";import"./BrowserProfilesManager-CzzGhZGz.js";import"./SignedInSites-CisTAQW0.js";const ld=[["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"}]],od=nt("cloud-download",ld);const cd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],dd=nt("palette",cd);const ud=[["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"}]],md=nt("scroll-text",ud);const pd=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],xd=nt("terminal",pd);const gd=[["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"}]],hd=nt("unplug",gd);function ks(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}function ve({children:s,note:n="settings.adminOnly.change"}){return vt()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Ns(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 fd(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 bd(){const{state:s,dispatch:n}=$(),[a,i]=l.useState(!1),[r,c]=l.useState(null),o=s.config?.tts?.everyReply===!0,d=()=>{i(!0),c(null),M("/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(xe,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}function Ot(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const ze=O(Pe,"font-sans"),yd=[5,10,20,30,60],zt="ui-icon-button shrink-0 hover:text-ink",Mt={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},es={count:64,length:200},vd=s=>s.length<=es.count&&s.every(n=>n.length<=es.length),ts=(s,n)=>M(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function ni({server:s,disabled:n,onPick:a}){return e.jsxs(me,{size:"sm",className:"shrink-0",value:s.replyWaitMinutes??"",onChange:i=>a(i.target.value?Number(i.target.value):null),disabled:n,"aria-label":t("apiInstances.replyWaitFor",{name:s.displayName}),title:t("apiInstances.replyWaitHint"),children:[e.jsx("option",{value:"",children:t("apiInstances.replyWaitDefault")}),[...new Set([...yd,...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 jd(){const{state:s,dispatch:n,refreshInstances:a}=$(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(m=>m.instanceId==="openaiCompat"&&m.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const u=m=>{i||(r(!0),o(null),ts(d.instanceId,{replyWaitMinutes:m}).then(async({instances:p})=>{Array.isArray(p)?n({type:"instances",instances:p}):await a({reportErrors:!0})}).catch(p=>o(p.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(ni,{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 kd(){const{state:s}=$();return e.jsx(Nd,{servers:ks(s.instances)})}function Nd({servers:s}){const{dispatch:n,refreshInstances:a}=$(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,u]=l.useState(""),[m,p]=l.useState(""),[x,g]=l.useState(null),[h,b]=l.useState(null),[y,f]=l.useState(null),[k,C]=l.useState(""),N=!!(i.trim()&&c.trim()&&d.trim()),w=(j,B,v,E)=>{x||(g(j),b(null),B().then(async({instances:A})=>{Array.isArray(A)?n({type:"instances",instances:A}):await a({reportErrors:!0}),v?.()}).catch(A=>b({text:A.message||t("apiInstances.failed"),at:E})).finally(()=>g(null)))},R=()=>N&&w("add",()=>M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...Ot(m).length?{models:Ot(m)}:{}})}).then(j=>(He("custom_endpoint","settings","unverified"),j),j=>{throw He("custom_endpoint","settings","error"),j}),()=>{r(""),o(""),u(""),p("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] leading-[18px] text-ink",children:t("apiInstances.title")}),e.jsx("p",{className:"mb-2 text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.subtitle")}),s.length===0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.empty")}),s.map(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(ni,{server:j,disabled:x!==null,onPick:B=>w("other",()=>ts(j.instanceId,{replyWaitMinutes:B}))}),e.jsx("button",{type:"button",onClick:()=>{C((j.managedModels??[]).join(", ")),f(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:zt,children:e.jsx(qr,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/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:zt,children:e.jsx(pa,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/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:`${zt} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Se,{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:k,onChange:B=>C(B.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:j.displayName}),spellCheck:!1,disabled:x!==null,className:O(ze,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.editModelsHint")}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{const B=Ot(k);if(!vd(B)){b({text:t("apiInstances.modelsLimit",es),at:j.instanceId});return}w("other",()=>ts(j.instanceId,{models:B}),()=>f(null),j.instanceId)},disabled:x!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>f(null),disabled:x!==null,className:"ui-button",children:t("common.cancel")})]}),h?.at===j.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:h.text})]})]},j.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Mt.name),o(Mt.url)},disabled:x!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===Mt.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:ze}),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(ze,"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(ze,"font-mono")}),e.jsx("input",{value:m,onChange:j=>p(j.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:x!==null,className:O(ze,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsxs("button",{type:"button",onClick:R,disabled:x!==null||!N,className:"ui-button self-start",children:[x==="add"?e.jsx(V,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ne,{size:12,"aria-hidden":"true"}),x==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),h&&!h.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:h.text})]})}const wd="lm-studio";function Sd(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 Cd({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=$(),r=ks(n.instances),[c,o]=l.useState("1234"),[d,u]=l.useState(""),[m,p]=l.useState(!1),[x,g]=l.useState(null),h=Sd(c),b=!!(h&&r.some(f=>f.url===h)),y=()=>{m||!h||b||(p(!0),g(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:h,key:d.trim()||wd,catalog:"lmstudio"})}).then(async f=>{He("custom_endpoint","settings","unverified"),Array.isArray(f.instances)?a({type:"instances",instances:f.instances}):await i({reportErrors:!0}),u("")},f=>{He("custom_endpoint","settings","error"),g(f instanceof Error&&f.message?f.message:t("apiInstances.failed"))}).finally(()=>p(!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:f=>o(f.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:m,className:O(ze,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:f=>u(f.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:m,className:O(ze,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),h&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:h}),e.jsxs("button",{type:"button",onClick:y,disabled:m||!h||b,className:"ui-button self-start",children:[m?e.jsx(V,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ne,{size:12,"aria-hidden":"true"}),m?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 Ed="ollama",Ad="https://ollama.com/download",Id=s=>`${s.replace(/\/+$/,"")}/v1`,Pd=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Rd({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=$(),[r,c]=l.useState(""),[o,d]=l.useState(null),[u,m]=l.useState(!1),[p,x]=l.useState(!1),[g,h]=l.useState(null),b=l.useRef(0),y=l.useRef(!1),f=l.useCallback(R=>{const j=++b.current;m(!0),h(null),M(`/api/instances/ollama${R?`?url=${encodeURIComponent(R)}`:""}`).then(B=>{j===b.current&&d(B.status)}).catch(B=>{j===b.current&&(d(null),h(B.message||t("apiInstances.failed")))}).finally(()=>{j===b.current&&m(!1)})},[]);l.useEffect(()=>{!s||y.current||(y.current=!0,f(""))},[s,f]);const k=o?Id(o.url):null,C=!!(k&&(ks(n.instances).some(R=>R.url===k)||Pd(n.config?.openaiCompat?.url,k))),N=!!(k&&!C&&!p&&!u&&(o?.state==="ready"||o?.state==="no-models")),w=()=>{!N||!k||(x(!0),h(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:k,key:Ed,catalog:"ollama"})}).then(async R=>{He("custom_endpoint","settings","unverified"),Array.isArray(R.instances)?a({type:"instances",instances:R.instances}):await i({reportErrors:!0})},R=>{He("custom_endpoint","settings","error"),h(R instanceof Error&&R.message?R.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(V,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(Jr,{status:o})}),!u&&o?.state==="not-running"&&e.jsx("a",{href:Ad,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:R=>c(R.target.value),onKeyDown:R=>{R.key==="Enter"&&f(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:p,className:O(Pe,"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:w,disabled:!N,className:"ui-button",children:[p?e.jsx(V,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ne,{size:12,"aria-hidden":"true"}),p?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>f(r.trim()),disabled:u||p,className:"ui-button",children:[e.jsx(pa,{size:12,"aria-hidden":"true"}),t("common.checkAgain")]})]}),C&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g})]})}function Td(){const{state:s,dispatch:n}=$(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=l.useState(""),[c,o]=l.useState(""),[d,u]=l.useState(!1),[m,p]=l.useState(null),[x,g]=l.useState(null),h=d||m!==null,b=(k,C)=>M("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[k]:C}}})}).then(N=>n({type:"configStatus",config:N})),y=()=>{const k=i.trim().toUpperCase(),C=Yr(c);if(!(h||!k||!C)){if(!Xr(C)){g(t("keys.notAKey"));return}u(!0),g(null),b(k,C).then(()=>{r(""),o("")}).catch(N=>g(N.message)).finally(()=>u(!1))}},f=k=>{h||(p(k),g(null),b(k,"").catch(C=>g(C.message)).finally(()=>p(null)))};return e.jsxs("div",{"data-opencode-provider-keys":!0,className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.otherProviders.hint")}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((k,C)=>C===0?[k]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},C),k])}),a.map(k=>e.jsxs("div",{"data-opencode-provider-key":k,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:O(Pe,"block flex-1 truncate text-ink"),children:k}),e.jsx("button",{type:"button",onClick:()=>f(k),disabled:h,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:k}),className:"ui-button shrink-0",children:m===k?e.jsx(V,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},k)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:k=>{g(null),r(k.target.value)},onKeyDown:k=>k.key==="Enter"&&y(),disabled:h,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:O(Pe,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:k=>{g(null),o(k.target.value)},onKeyDown:k=>k.key==="Enter"&&y(),disabled:h,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:O(Pe,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:y,disabled:h||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(V,{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 Bd(){const{state:s,dispatch:n}=$(),[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),M("/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(xe,{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(Re,{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 Ld(){const{state:s,dispatch:n}=$(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=!!s.config?.vps?.configured,m=!a.trim()&&u;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const p=()=>{r||!a.trim()&&!u||(c(!0),d(null),M("/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"&&p(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:O(Pe,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:p,disabled:r||!a.trim()&&!u||a.trim()===(s.config?.vps?.sshAlias??""),className:O("ui-button shrink-0",!m&&"ui-button-primary"),title:m?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(V,{size:13,className:"animate-spin","aria-hidden":"true"}):m?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function Od(){const{state:s,dispatch:n}=$(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,u]=l.useState(null),m=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const p=i.trim()!==a,x=()=>{m.current||!p||(m.current=!0,o(!0),u(null),M("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(g=>n({type:"configStatus",config:g})).catch(g=>u(g.message)).finally(()=>{m.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:g=>r(g.target.value),onBlur:x,onKeyDown:g=>g.key==="Enter"&&x(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:O(Pe,"pr-8")}),c&&e.jsx(V,{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 zd="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",Md=1600,Ud={opencodeProviders:()=>e.jsx(Td,{}),ollama:s=>e.jsx(Rd,{visible:s}),lmStudio:()=>e.jsx(Cd,{heading:!1}),vps:()=>e.jsx(Ld,{})},Fd={anthropic:()=>e.jsx(Bd,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(Od,{}),e.jsx(jd,{}),e.jsx(kd,{})]}),box:()=>e.jsx(tl,{}),liveKey:()=>e.jsx(el,{})};function ai(s,n){if(s.kind==="uses")return!1;const a=fs(s,n);return a.configured||a.included===!0}function Dd({entry:s,visible:n}){const{state:a}=$(),i=l.useId(),c=fs(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:ga,children:[e.jsx(ha,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:Ud[s.id]?.(n)})]})}function _d({entry:s}){const{state:n,dispatch:a}=$(),i=l.useId(),r=s.opens,c=fs(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:ga,children:[e.jsx(ha,{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(Zr,{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 Kd({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(Ys,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(Dd,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(_d,{entry:s}):e.jsx(Ys,{id:s.id,children:Fd[s.id]?.()})}function Hd({id:s,rows:n,open:a,onToggle:i}){const{state:r}=$(),c=Yt.find(m=>m.id===s),o=l.useId(),d=l.useId(),u=n.filter(m=>ai(m,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:zd,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(js,{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(m=>e.jsx(Kd,{entry:m,visible:a},m.id)),s==="voice"&&e.jsx(bd,{})]})]})}function $d(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=fd(i);return r&&Ns(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"),Md)),!0}function Wd(){const{state:s}=$(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(Yt.filter(x=>x.id==="ai"||Qe.some(g=>g.section===x.id&&ai(g,s.config))).map(x=>x.id))),c=l.useRef(null),o=xa(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const x=Qe.find(y=>y.id===o.row)?.section??"ai";a(""),r(y=>y.has(x)?y:new Set([...y,x]));let g=0,h=0;const b=()=>{$d(c.current,o,x)||++h>60?Qr(o):g=window.requestAnimationFrame(b)};return g=window.requestAnimationFrame(b),()=>window.cancelAnimationFrame(g)},[o]);const u=s.config?.live?.provider==="azure",m=Qe.filter(x=>hs(x,d)&&!(u&&x.id==="liveCalls")),p=Yt.flatMap(x=>{const g=m.filter(h=>h.section===x.id);return g.length>0?[{id:x.id,rows:g}]:[]});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(at,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:n,onChange:x=>a(x.target.value),onKeyDown:x=>{x.key!=="Escape"||!n||(x.preventDefault(),x.stopPropagation(),a(""))},placeholder:t("keys.search.placeholder"),"aria-label":t("keys.search.aria"),autoComplete:"off",spellCheck:!1,className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),p.length===0?e.jsx("p",{"data-keys-empty":!0,className:"px-1 text-[13px] leading-[18px] text-ink-secondary",children:t("keys.search.none",{query:n.trim()})}):p.map(({id:x,rows:g})=>e.jsx(Hd,{id:x,rows:g,open:d!==""||i.has(x),onToggle:()=>r(h=>{const b=new Set(h);return b.has(x)?b.delete(x):b.add(x),b})},x))]})}function ii({simple:s=!1}){return null}function ri({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 m=!0;return n?.state().then(p=>{m&&i(p)}).catch(()=>{}),()=>{m=!1}},[n]),!n||!a?.available)return null;const u=m=>{c(!0),d(!1),n.set(m).then(i,()=>d(!0)).finally(()=>c(!1))};return e.jsx(de,{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(xe,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>u(!a.on)})})}function Gd(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 li(){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(g=>{x&&a(g)}).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))},m=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,p=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:x=>u({key:x.target.value}),children:n.keys.map(x=>e.jsx("option",{value:x.id,children:x.label},x.id))}),m&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:m})]});return e.jsx(de,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||m?p:null,children:e.jsx(xe,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>u({enabled:!n.enabled})})})}const Ut=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function oi(){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 m=!0;return M("/api/attachment-storage").then(p=>{m&&n(p)}).catch(()=>{}),()=>{m=!1}},[]),!s)return null;const u=async()=>{c(!0),d(null);try{const m=await M("/api/attachment-storage",{method:"POST"});n(m);const p=t("settings.attachments.cleared",{count:m.removed,freed:Ut(m.freedBytes)});d(m.failed>0?{kind:"error",message:`${p} ${t("settings.attachments.failed",{count:m.failed})}`}:{kind:"success",message:p})}catch(m){d({kind:"error",message:m instanceof Error?m.message:String(m)})}finally{c(!1),i(!1)}};return e.jsx(de,{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:Ut(s.usedBytes),max:Ut(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 ci({simple:s=!1}){const[n,a]=l.useState(!1),[i,r]=l.useState(null),[c,o]=l.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const p=await window.ogb.exportDiagnostics();p&&r({kind:"success",message:t("settings.diagnostics.saved",{path:p})})}catch(p){r({kind:"error",message:p instanceof Error?p.message:String(p)})}finally{a(!1)}}},u=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const p=await window.ogb.openLogsFolder();o(p.folder),p.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:p.folder})})}catch(p){r({kind:"error",message:p instanceof Error?p.message:String(p)})}}},m=!!window.ogb?.exportDiagnostics;return e.jsx(de,{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(m?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:m&&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 Vd="https://dash.cloudflare.com/profile/api-tokens",qd=/^[0-9a-f]{32}$/i,mn="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 Jd({failureText:s}){const{state:n,dispatch:a}=$(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[o,d]=l.useState(null),[u,m]=l.useState(""),[p,x]=l.useState(!1),[g,h]=l.useState(!1),[b,y]=l.useState(null),[f,k]=l.useState(null),C=(o??c).trim(),N=u.trim(),w=!N&&r&&o===null,R=o!==null&&C!==c,j=E=>a({type:"configStatus",config:E}),B=async()=>{if(!(p||!N&&!r&&!R)){if(N&&!qd.test(C))return y(t("decider.workersAi.needsAccount"));x(!0),y(null),k(null);try{(R||N&&!c)&&j(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:C}})})),(N||w)&&j(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",N):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:N}})})),m(""),d(null)}catch(E){y(E instanceof Error?E.message:String(E))}finally{x(!1)}}},v=async()=>{if(!(g||p||!N&&!r)){h(!0),k(null),y(null);try{const E=await M("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...N?{key:N,accountId:C}:{}})}),A=E.extraction?[t(E.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];k(E.ok?{ok:E.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(E.latencyMs)}),...A].join(" ")}:{ok:!1,text:s(E)})}catch(E){k({ok:!1,text:E instanceof Error?E.message:String(E)})}finally{h(!1)}}};return e.jsxs(J,{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:E=>{k(null),y(null),d(E.target.value)},disabled:p,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:mn}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:u,onChange:E=>{k(null),y(null),m(E.target.value)},onKeyDown:E=>E.key==="Enter"&&void B(),disabled:p,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:mn}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{B()},disabled:p||!N&&!r&&!R,title:w?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",w?"text-danger":"text-ink"),children:p?e.jsx(V,{size:13,className:"animate-spin"}):w?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(fe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{v()},disabled:g||p||!N&&!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:g?t("keys.testing"):t("keys.test")})]})]}),b&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:b}),f&&e.jsx("p",{role:"status",className:O("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("a",{href:Vd,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(it,{size:11,"aria-hidden":"true"})]})]})}const Yd={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},Xd=1500,ws={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"},pn={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},Qd={...ws,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"},Zd={...ws,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"},Ft={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter"};function eu(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(Ft[n.provider]??Ft.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(Ft[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function xn(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=Zd[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=Qd[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&&pn[s.reason])return t(pn[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=ws[s.reason];return i?t(i):t("decider.error.other")}const tu=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function su(){const{state:s,dispatch:n}=$(),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,m=c&&!o&&!d,p=a?.enabled??!1,x=a?.jobs.roomRouting??!0,[g,h]=l.useState(""),[b,y]=l.useState(!1),[f,k]=l.useState(!1),[C,N]=l.useState(!1),[w,R]=l.useState(null),[j,B]=l.useState(null),[v,E]=l.useState(null),A=g.trim(),_=!A&&m,Z=!r||o?null:d?"decider.openrouter.status.sharedHint":c?u?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",ee=P=>n({type:"configStatus",config:P}),Y=async P=>{if(!f){k(!0),R(null);try{ee(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:P})}))}catch(L){R(L instanceof Error?L.message:String(L))}finally{k(!1)}}};l.useEffect(()=>{if(!r||v)return;let P=!1;return M("/api/decider/models").then(L=>{P||E(L)},()=>{}),()=>{P=!0}},[r,v]);const te=P=>{h(""),B(null),Y(P)},ne=async()=>{if(!(b||!A&&!m)){y(!0),R(null),B(null);try{const P=window.ogb?.setCredential?await window.ogb.setCredential(r?"openrouterDeciderKey":"jevApiKey",A):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{[r?"openrouterKey":"key"]:A}})});ee(P),h("")}catch(P){R(P instanceof Error?P.message:String(P))}finally{y(!1)}}},ie=async()=>{if(C||b||!A&&!c)return;N(!0),B(null),R(null);const P=!A&&o,L=!A&&d;try{const I=await M("/api/decider/test",{method:"POST",body:JSON.stringify(A?{key:A}:{})});B(I.ok?{ok:!0,text:r?[t(L?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(I.latencyMs)}),...I.latencyMs>Xd?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(I.latencyMs)})}:{ok:!1,text:xn(I,P,i)})}catch(I){B({ok:!1,text:I instanceof Error?I.message:String(I)})}finally{N(!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:eu(s.config)})]}),e.jsx(Jd,{failureText:P=>xn(P,!1,"workersai")}),e.jsx(de,{title:t("decider.provider.label"),children:e.jsxs(me,{className:"w-48","data-testid":"decider-provider",value:i,onChange:P=>te({provider:P.target.value==="openrouter"?"openrouter":"jev"}),disabled:f||!s.config,"aria-label":t("decider.provider.label"),children:[e.jsx("option",{value:"jev",children:t("decider.provider.jev")}),e.jsx("option",{value:"openrouter",children:t("decider.provider.openrouter")})]})}),r&&e.jsx(de,{title:t("decider.model.label"),subtitle:v?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(me,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:P=>te({openrouterModel:P.target.value,openrouterApi:v?.models.find(L=>L.id===P.target.value)?.api??"chat"}),disabled:f,"aria-label":t("decider.model.label"),children:[a?.model&&!v?.models.some(P=>P.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(P=>{const L=v?.models.filter(I=>I.group===P)??[];return L.length>0&&e.jsx("optgroup",{label:t(P==="recommended"?"decider.model.recommended":"decider.model.more"),children:L.map(I=>e.jsx("option",{value:I.id,children:I.name},I.id))},P)})]})}),e.jsx(de,{title:t(r?"decider.openrouter.master":"decider.master"),subtitle:c?void 0:t(r?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(xe,{"data-testid":"decider-master","aria-label":t(r?"decider.openrouter.master":"decider.master"),checked:p,disabled:!c||f||!s.config,onClick:()=>{Y({enabled:!p})},className:"cursor-pointer"})}),e.jsxs(J,{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")})]}),Z&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(Z),!m&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(Xt("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:g,onChange:P=>{B(null),R(null),h(P.target.value)},onKeyDown:P=>P.key==="Enter"&&void ne(),disabled:b,placeholder:m?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:()=>{ne()},disabled:b||!A&&!m,title:_?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",_?"text-danger":"text-ink"),children:b?e.jsx(V,{size:13,className:"animate-spin"}):_?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(fe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{ie()},disabled:C||b||!A&&!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")})]}),w&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:w}),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:Yd[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(it,{size:11,"aria-hidden":"true"})]})]}),e.jsx(J,{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(xe,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:p&&x,disabled:!p||f,onClick:()=>{Y({jobs:{roomRouting:!x}})},className:"cursor-pointer"})]}),tu.map(P=>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(P)}),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")})]},P))]})})]})}const nu=["openai","xai","gemini","openrouter","custom"],au=4,di={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},iu={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 ru(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 ft={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},lu={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"}},ou={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},gn={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},ss="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",Dt="\0other";function cu(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 du(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 uu(){const{state:s,dispatch:n}=$(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??di.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,u]=l.useState(null),[m,p]=l.useState(null),x=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!x||m)return;let y=!1;return M("/api/images/openrouter-models").then(f=>{y||p(Array.isArray(f?.models)?f:{source:"builtin",models:[]})},()=>{y||p({source:"builtin",models:[]})}),()=>{y=!0}},[x,m]);const g=async y=>{o(!0),u(null);try{const f=await M("/api/config",{method:"PUT",body:JSON.stringify(y)});n({type:"configStatus",config:f})}catch(f){u(f instanceof Error?f.message:String(f))}finally{o(!1)}},h=(y,f)=>{if(y==="fallback"&&f==="")return void g({imageGen:{fallback:null}});const k=f,C=y==="primary"&&r?.provider===k;g({imageGen:{[y]:{provider:k},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((y,f,k)=>k.indexOf(y)===f);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("imageGen.intro")}),e.jsxs("p",{role:"status","data-testid":"image-gen-status",className:"flex items-center gap-2 text-[13px] font-medium text-ink",children:[e.jsx("span",{className: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:ft[i.provider]}):t("imageGen.status.backupOnly",{provider:ft[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(fn,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:m,disabled:c||!s.config,onProvider:h,onModel:y=>{g({imageGen:{primary:{provider:i.provider,model:y}}})}}),e.jsx(fn,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:m,disabled:c||!s.config,onProvider:h,onModel:y=>r&&void g({imageGen:{fallback:{provider:r.provider,model:y}}})}),e.jsx(de,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(me,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??au),onChange:y=>{g({imageGen:{maxPerTurn:Number(y.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(y,f)=>f+1).map(y=>e.jsx("option",{value:y,children:y},y))})}),d&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:d}),b.map(y=>e.jsx(pu,{provider:y,status:a},y))]})}function fn({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:u}){const m=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(de,{title:m,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(me,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:p=>d(s,p.target.value),disabled:o,"aria-label":m,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),nu.filter(p=>p!==r).map(p=>e.jsx("option",{value:p,children:ft[p]},p))]})}),n&&e.jsx(mu,{slot:s,slotLabel:m,provider:n,model:a,openrouterModels:c,disabled:o,onModel:u})]})}function mu({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,u]=l.useState(null),p=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??iu[a].map(b=>({...b,group:"recommended"})),x=d!==null||p.length===0,g=()=>{d!==null&&(u(null),d.trim()&&d.trim()!==i&&o(d.trim()))},h=b=>{if(b===Dt)return u(i);u(null),o(b)};return e.jsx(de,{title:t("decider.model.label"),subtitle:a==="openrouter"&&r?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[p.length>0&&e.jsxs(me,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:x?Dt:i,onChange:b=>h(b.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[i&&!p.some(b=>b.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(b=>{const y=p.filter(f=>f.group===b);return y.length>0&&e.jsx("optgroup",{label:t(b==="recommended"?"decider.model.recommended":"decider.model.more"),children:y.map(f=>e.jsx("option",{value:f.id,children:f.name},f.id))},b)}),e.jsx("option",{value:Dt,children:t("imageGen.model.other")})]}),x&&e.jsx("input",{value:d??i,onChange:b=>u(b.target.value),onBlur:g,onKeyDown:b=>b.key==="Enter"&&g(),disabled:c,placeholder:di[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:O(ss,"w-64 max-w-full")})]})})}function pu({provider:s,status:n}){const{dispatch:a}=$(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,u]=l.useState(!1),[m,p]=l.useState(null),[x,g]=l.useState(!1),[h,b]=l.useState(null),y=s==="openrouter"?[n?.primary,n?.fallback].filter(A=>A?.provider===s).map(A=>A?.model).join(" "):"",f=h?.models===y?h:null,k=A=>b(A&&{...A,models:y}),C=du(n,s),N=s==="openai"||s==="gemini"||s==="custom"?lu[s]:null,w=s==="xai"||s==="openrouter"?ou[s]:null,R=c??n?.customUrl??"",j=async A=>{u(!0),p(null),k(null);try{a({type:"configStatus",config:await A()}),r(""),o(null)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{u(!1)}},B=A=>j(async()=>s==="xai"||s==="openrouter"?sl(s,A,!1):window.ogb?.setCredential&&N?window.ogb.setCredential(N.credential,A):M("/api/config",{method:"PUT",body:JSON.stringify(N.patch(A))})),v=()=>j(async()=>{const A=R.trim()?ru(R.trim()):"";return M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:A}})})}),E=async()=>{g(!0),k(null);try{k(cu(s,await M("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(A){k({ok:!1,text:A instanceof Error?A.message:String(A)})}finally{g(!1)}};return e.jsxs(J,{title:ft[s],children:[e.jsx(xu,{configured:C,optional:s==="custom"}),w&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(w.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:R,onChange:A=>o(A.target.value),onKeyDown:A=>A.key==="Enter"&&void v(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:ss}),e.jsxs("button",{type:"button",onClick:()=>{v()},disabled:d||c===null,className:hn,children:[d?e.jsx(V,{size:13,className:"animate-spin"}):e.jsx(fe,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:A=>r(A.target.value),onKeyDown:A=>A.key==="Enter"&&i.trim()&&void B(i.trim()),disabled:d,placeholder:C?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((N??w).label),autoComplete:"off",spellCheck:!1,className:ss}),e.jsxs("button",{type:"button",onClick:()=>{B(i.trim())},disabled:d||!i.trim(),className:hn,children:[d?e.jsx(V,{size:13,className:"animate-spin"}):e.jsx(fe,{size:13}),t("common.save")]}),C&&e.jsx("button",{type:"button",onClick:()=>{E()},disabled:x||d,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:x?t("keys.testing"):t("keys.test")})]}),f&&e.jsx("p",{role:"status",className:O("mt-1 text-[12px]",f.ok?"text-success":"text-danger"),children:f.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[gn[s]?e.jsx("a",{href:gn[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:us()})}),C&&e.jsx("button",{type:"button",onClick:()=>{B("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m})]})}function xu({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 _t(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")&&fa(s.driverKind)==="codex"?"chatgpt":null}function Ss(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const Cs={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function gu(s,n){return{signOut:Ss(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 ui(s){return s.some(Ie)}function hu(s,n){const a=n.filter(o=>Ss(o)==="signedIn"),i=ui(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??ll(n[0]);return{title:t(Cs[s].title),subtitle:c,ready:i,status:i?t("onboarding.engines.ready"):r?t("model.signInRequired"):t("onboarding.engines.needsSetup"),action:i?t("engines.library.manage"):r?t("accounts.signIn"):t("engines.library.setup")}}function fu({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=$(),[o,d]=l.useState(!1),[u,m]=l.useState(null),[p,x]=l.useState(!1),[g,h]=l.useState(null),b=l.useRef(null),{signOut:y,remove:f}=gu(s,n),k=i.bots.filter(w=>w.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const w=j=>{j.key==="Escape"&&(j.stopPropagation(),d(!1))},R=j=>{j.target instanceof Node&&!b.current?.contains(j.target)&&d(!1)};return window.addEventListener("keydown",w,!0),window.addEventListener("pointerdown",R),()=>{window.removeEventListener("keydown",w,!0),window.removeEventListener("pointerdown",R)}},[o]);const C=async w=>{m(null),x(!0),h(null);try{const R=`/api/instances/${encodeURIComponent(n.instanceId)}${w==="signOut"?"/auth/sign-out":""}`,{instances:j}=await M(R,w==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(j)?r({type:"instances",instances:j}):await c().catch(()=>{})}catch(R){h(R instanceof Error?R.message:String(R))}finally{x(!1)}},N="ui-menu-row w-full text-left disabled:cursor-not-allowed disabled:opacity-50";return e.jsxs("div",{ref:b,className:"relative flex items-center gap-1",children:[f&&e.jsx("button",{type:"button",disabled:p||k>0,onClick:()=>m("remove"),title:k>0?t("accounts.inUse",{count:String(k)}):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(w=>!w),disabled:p,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:Me(n)}),className:"flex size-8 items-center justify-center rounded-lg text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:p?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(fc,{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]",bc),children:[e.jsx("button",{type:"button",role:"menuitem",className:O(N,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),y&&e.jsx("button",{type:"button",role:"menuitem",className:O(N,"text-ink"),onClick:()=>{d(!1),m("signOut")},children:t("accounts.signOut")}),f&&k>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(k)})})]}),g&&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:g}),e.jsx($e,{open:u==="signOut",title:t("accounts.signOutTitle",{name:Me(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>m(null),onConfirm:()=>{C("signOut")}}),e.jsx($e,{open:u==="remove",title:t("accounts.removeTitle",{name:Me(n)}),body:t(Cs[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>m(null),onConfirm:()=>{C("remove")}})]})}function bu({instance:s,onDone:n}){const{dispatch:a}=$(),[i,r]=l.useState(Me(s)),[c,o]=l.useState(!1),[d,u]=l.useState(null),m=async()=>{const p=i.trim();if(!p||p===Me(s))return n();o(!0),u(null);try{const{instances:x}=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:p})});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:p=>{p.preventDefault(),m()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:p=>r(p.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:p=>{p.key==="Escape"&&(p.stopPropagation(),n())},className:"min-w-0 flex-1 rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:c?e.jsx(V,{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 yu({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=Ss(n),u=n.snapshot.account,m=n.snapshot.authenticationUnavailableReason,p=m&&d!=="signedIn"?m: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(fe,{size:13}):e.jsx("span",{className:O("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(bu,{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:Me(n),children:Me(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:p,children:p})]}),d!=="signedIn"&&d!=="unavailable"&&!m&&!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(fu,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(nl,{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(al,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(il,{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(rl,{instanceId:n.instanceId,welcome:!1})})]})}function mi({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=$(),[d,u]=l.useState(!1),[m,p]=l.useState(""),[x,g]=l.useState(""),[h,b]=l.useState(!1),[y,f]=l.useState(null),k=async()=>{if(!(h||!m.trim())){b(!0),f(null);try{const C={displayName:m.trim(),...a,...i&&x.trim()?{configDir:x.trim()}:{}},N=await M(n,{method:"POST",body:JSON.stringify(C)});Array.isArray(N.instances)&&o({type:"instances",instances:N.instances}),u(!1),p(""),g(""),typeof N.instanceId=="string"&&c(N.instanceId)}catch(C){f(C instanceof Error?C.message:String(C))}finally{b(!1)}}};return d?e.jsxs("form",{"data-add-account":n,className:"space-y-2.5 rounded-xl border border-hairline/50 bg-app p-3",onSubmit:C=>{C.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:m,onChange:C=>p(C.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:h,"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=>g(C.target.value),placeholder:"~/.claude-work",maxLength:4096,spellCheck:!1,disabled:h,"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),f(null)},disabled:h,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:h||!m.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:[h&&e.jsx(V,{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(Ne,{size:14}),s]})}function vu({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(p=>p.snapshot.state==="available"),u=n.find(p=>p.policy)?.policy,m=l.useId();return e.jsxs(xt,{instance:o,summary:hu(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(p=>e.jsx(yu,{group:s,instance:p,signingIn:r===p.instanceId,onSignIn:()=>c(p.instanceId),onSignInDone:()=>c(x=>x===p.instanceId?null:x)},p.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(mi,{label:t(Cs[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?m:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:m,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(jt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(ba,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(ya,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const ju={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},ot=O(Pe,"font-sans"),ku={name:"",url:"",token:"",model:""},Nu=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:""});function bn({instance:s,engine:n,onDone:a}){const{dispatch:i}=$(),r=ju[n],[c,o]=l.useState(s?Nu(s):ku),[d,u]=l.useState(!1),[m,p]=l.useState(null),x=b=>({value:c[b],onChange:y=>o(f=>({...f,[b]:y.target.value})),spellCheck:!1,disabled:d}),g=!!(c.name.trim()&&(c.url.trim()||n==="codex")&&(s||c.token.trim())),h=async()=>{if(d||!g)return;u(!0),p(null);const b={displayName:c.name.trim(),baseUrl:c.url.trim()||r.url,...c.token.trim()?{token:c.token.trim()}:{},...c.model.trim()?{model:c.model.trim()}:{}};try{const y=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await M(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(y.instances)&&i({type:"instances",instances:y.instances}),a()}catch(y){p(y instanceof Error&&y.message?y.message:t("claudeEndpoints.failed"))}finally{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(),h()},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:ot})]}),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(ot,"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(ot,"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(ot,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),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||!g,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(V,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function wu({instance:s,onEdit:n}){const{state:a,dispatch:i}=$(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,m]=l.useState(null),p=a.bots.filter(h=>h.modelSelection.instanceId===s.instanceId||h.fallback?.some(b=>b.instanceId===s.instanceId)||h.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeEndpoint??s.codexEndpoint,g=async()=>{c(!1),d(!0),m(null);try{const h=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(h.instances)&&i({type:"instances",instances:h.instances})}catch(h){m(h instanceof Error?h.message:String(h))}finally{d(!1)}};return e.jsxs("li",{"data-claude-endpoint":s.claudeEndpoint?s.instanceId:void 0,"data-codex-endpoint":s.codexEndpoint?s.instanceId:void 0,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:x?.baseUrl,children:x?.baseUrl})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeEndpoints.edit")}),e.jsx("button",{type:"button",disabled:o||p>0,onClick:()=>c(!0),title:p>0?t("accounts.inUse",{count:String(p)}):t("accounts.remove"),"aria-label":t("claudeEndpoints.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u}),e.jsx($e,{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:()=>{g()}})]})}function pi({engine:s}){const{state:n}=$(),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(bn,{engine:s,instance:c,onDone:()=>r(null)})},c.instanceId):e.jsx(wu,{instance:c,onEdit:()=>r(c.instanceId)},c.instanceId))}),i==="new"?e.jsx(bn,{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(Ne,{size:14}),t("claudeEndpoints.add")]})]})}function Kt(){return e.jsx(pi,{engine:"claude"})}function Ht(){return e.jsx(pi,{engine:"codex"})}const Ye=O(Pe,"font-sans"),Su={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"},yn=["opusModel","sonnetModel","haikuModel","smallFastModel"],Cu={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},Eu=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??""}},vn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function jn({instance:s,onDone:n}){const{dispatch:a}=$(),[i,r]=l.useState(s?Eu(s):Cu),[c,o]=l.useState(!1),[d,u]=l.useState(null),m=g=>({value:i[g],onChange:h=>r(b=>({...b,[g]:h.target.value})),spellCheck:!1,disabled:c}),p=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),x=async()=>{if(c||!p)return;o(!0),u(null);const g={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(yn.map(h=>[h,i[h].trim()]))};try{const h=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(g)}):await M("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(g)});Array.isArray(h.instances)&&a({type:"instances",instances:h.instances}),n()}catch(h){u(h instanceof Error&&h.message?h.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:g=>{g.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",{...m("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:Ye})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...m("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:O(Ye,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...m("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:O(Ye,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...m("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:O(Ye,"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:yn.map(g=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(vn[g]),e.jsx("input",{...m(g),maxLength:160,placeholder:Su[g],"aria-label":t(vn[g]),className:O(Ye,"font-mono")})]},g))})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!p,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[c&&e.jsx(V,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function Au({instance:s,onEdit:n}){const{state:a,dispatch:i}=$(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,m]=l.useState(null),p=a.bots.filter(h=>h.modelSelection.instanceId===s.instanceId||h.fallback?.some(b=>b.instanceId===s.instanceId)||h.tasks?.some(b=>b.modelSelection?.instanceId===s.instanceId)).length,x=s.claudeBedrock,g=async()=>{c(!1),d(!0),m(null);try{const h=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(h.instances)&&i({type:"instances",instances:h.instances})}catch(h){m(h instanceof Error?h.message:String(h))}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(va,{preset:"aws",size:16,className:"shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:t("claudeBedrock.rowSubtitle",{profile:x?.awsProfile??"",region:x?.awsRegion??""})})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeBedrock.edit")}),e.jsx("button",{type:"button",disabled:o||p>0,onClick:()=>c(!0),title:p>0?t("accounts.inUse",{count:String(p)}):t("accounts.remove"),"aria-label":t("claudeBedrock.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u}),e.jsx($e,{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:()=>{g()}})]})}function $t(){const{state:s}=$(),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(Au,{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(Ne,{size:14}),t("claudeBedrock.add")]})]})}function kn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Iu({instance:s,initial:n={kind:"idle"}}){const[a,i]=l.useState(n),[r,c]=l.useState(null),o=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,d=async()=>{c(null),i({kind:"scanning"});try{const p=await M(o);i(p.folders>0?{kind:"found",bytes:p.bytes,complete:p.complete}:{kind:"none"})}catch(p){c(p instanceof Error?p.message:String(p)),i({kind:"idle"})}},u=async()=>{c(null),i({kind:"deleting"});try{const p=await M(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:p.freedBytes,remaining:p.remaining})}catch(p){c(p instanceof Error?p.message:String(p)),i({kind:"idle"})}},m=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(yc,{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"||m)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:m,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:[m&&e.jsx(V,{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:kn(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:kn(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 Wt=[60,120,180,360,720];function xi(){const{state:s,dispatch:n}=$(),[a,i]=l.useState(!1),[r,c]=l.useState(""),o=l.useRef(!1),d=s.config?.cacheKeepWarm;if(!d)return null;const u=async p=>{if(!o.current){o.current=!0,i(!0),c("");try{const x=await M("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:p.enabled,windowMinutes:p.windowMinutes}})});n({type:"configStatus",config:x})}catch(x){c(x instanceof Error?x.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},m=Wt.includes(d.windowMinutes)?[...Wt]:[...Wt,d.windowMinutes].sort((p,x)=>p-x);return e.jsxs(J,{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(xe,{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(me,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:p=>{u({...d,windowMinutes:Number(p.target.value)})},children:m.map(p=>e.jsx("option",{value:p,children:t("settings.keepWarm.hours",{hours:Number((p/60).toFixed(2))})},p))})]}),a&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}function Pu({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[u,m]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[p,x]=l.useState(!1),[g,h]=l.useState(null),[b,y]=l.useState(!1),[f,k]=l.useState(null),C=l.useRef(!1);l.useEffect(()=>{C.current||(C.current=!0,M(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:v})=>{c(v),s.cli&&(v.includes(s.cli)?d(s.cli):m(s.cli))}).catch(()=>c(v=>v??[])))},[n,s.cli]);const N=u.trim()||o,w=N!==(s.cli??""),R=p||b;l.useEffect(()=>{h(null)},[N]);const j=()=>{if(R||!N||!w)return;y(!0),k(null);const v=N;M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:v})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(E=>k(E.message)).finally(()=>y(!1))},B=()=>{R||!N||!w||(x(!0),k(null),M("/api/cli-test",{method:"POST",body:JSON.stringify({cli:N,driver:s.driverKind})}).then(v=>{h(v),v.ok&&j()}).catch(v=>k(v.message)).finally(()=>x(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[r!==null&&r.length>0&&e.jsxs(me,{className:"w-full font-mono",value:u.trim()?"":o,onChange:v=>{d(v.target.value),m("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:R,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(v=>e.jsx("option",{value:v,children:v},v))]}),e.jsx("input",{type:"text",value:u,onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),!(!N||!w)&&B())},placeholder:r?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:R,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"}),g&&!g.ok&&g.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(Re,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:g.message})})]}),g?.ok&&g.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:g.version})}),f&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:R,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")}),g&&!g.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>h(null),disabled:R,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:R,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(V,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:B,disabled:R||!N||!w,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:R?e.jsx(V,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{size:13}),t("common.save")]})})]})]})}function gi({instance:s}){const{refreshInstances:n}=$(),[a,i]=l.useState(!1),r=Mc(a),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[m,p]=l.useState(null),[x,g]=l.useState(null),h=l.useRef(null);l.useEffect(()=>{h.current!==null&&h.current!==s.cli&&i(!1),h.current=s.cli??null},[s.cli]);const b=()=>{c||d||(o(!0),g(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>g(k.message)).finally(()=>o(!1)))},y=()=>{c||d||(o(!0),g(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>g(k.message)).finally(()=>o(!1)))},f=()=>{c||d||(u(!0),p(null),g(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:k})=>{p(k),await Promise.resolve(n()).catch(()=>{})}).catch(k=>g(k.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:f,disabled:c||d,className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[d?e.jsx(V,{size:12,className:"animate-spin"}):e.jsx(Ce,{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(k=>!k),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")})]}),m&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:m})}),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(Pu,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function Nn({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=$(),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[m,p]=l.useState(null),x=n==="remove",g=x?a.bots.filter(y=>y.modelSelection.instanceId===s.instanceId).length:0,h=t(x?"accounts.remove":"accounts.signOut"),b=async()=>{o(!1),u(!0),p(null);try{const y=`/api/instances/${encodeURIComponent(s.instanceId)}${x?"":"/auth/sign-out"}`,{instances:f}=await M(y,{method:x?"DELETE":"POST"});Array.isArray(f)?i({type:"instances",instances:f}):await r()}catch(y){p(y instanceof Error?y.message:String(y))}finally{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||g>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(V,{size:13,className:"animate-spin"}):h}),g>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(g)})})]}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsx($e,{open:c,title:t(x?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(x?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:h,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{b()}})]})}function Ru({source:s}){const{state:n}=$(),[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(mi,{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(jt,{instance:r,unframed:!0})})]})}function Tu({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(xt,{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":Ie(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(xt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!Ie(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(xt,{instance:s,bare:n,children:[a,!Ie(s)&&e.jsx(jt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),Ie(s)&&e.jsx(ul,{instance:s,className:"mt-3"}),Ie(s)&&s.serverKind==="ollama"&&e.jsx(ml,{instance:s,className:"mt-3"}),Ie(s)&&e.jsx(pl,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(ba,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(ya,{warning:s.snapshot.warning,className:"mt-3"}),Ie(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(fe,{size:13}),t(xl[fa(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(fe,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Iu,{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(Ru,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(Nn,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(Nn,{instance:s,action:"remove"})]}),e.jsx(gi,{instance:s})]})}function Bu(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?dl(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function Lu({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(be,{label:t("settings.simple.ai.yours"),actions:e.jsx(ja,{}),children:e.jsx(ye,{children:o.map(u=>{const m=n(u),p=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(Xs,{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:Bu(u,m)})]})]}),e.jsx("button",{type:"button","aria-expanded":p,className:"ui-button ml-auto shrink-0",onClick:()=>c(p?null:u.instanceId),children:t(p?"common.done":m?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),p&&e.jsx("div",{className:"px-4 pb-3",children:a(u,!0)})]},u.instanceId)})})}),d.length>0&&e.jsx(kt,{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(Xs,{instance:u,size:14,subtle:!0})},u.instanceId))}),...i,children:e.jsx(ka,{instances:d,isReady:n,renderEngine:u=>a(u)})})]})}function Ou(){const{state:s,refreshInstances:n}=$(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let m=!0;return M("/api/instances/hidden").then(p=>{m&&i(Array.isArray(p?.instances)?p.instances:[])}).catch(()=>{}),()=>{m=!1}},[s.instances]),a.length===0)return null;const u=m=>{c(m),d(null),M(`/api/instances/${encodeURIComponent(m)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(p=>d(p.message)).finally(()=>c(null))};return e.jsxs("details",{"data-hidden-engines":!0,className:"px-4",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink",children:t("engines.hiddenTitle",{count:String(a.length)})}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.hiddenHint")}),e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:a.map(m=>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:m.displayName}),e.jsx("button",{type:"button","data-unhide-engine":m.instanceId,disabled:r!==null,onClick:()=>u(m.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===m.instanceId?t("engines.unhiding"):t("engines.unhide")})]},m.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function hi({simple:s=!1,more:n}){const{state:a}=$();l.useEffect(()=>ol,[]);const i=a.instances.filter(g=>g.readOnly||g.cli!==void 0||g.cliDefault!==void 0||g.snapshot.state==="unavailable"||cl(g)||g.claudeEndpoint!==void 0||g.claudeBedrock!==void 0||g.codexEndpoint!==void 0),r=new Map;for(const g of i){const h=_t(g);h&&r.set(h,[...r.get(h)??[],g])}const c=g=>{const h=_t(g);return h&&r.get(h)?.[0]===g?h:null},o=i.filter(g=>!_t(g)||c(g)),d=o.length>0&&o.every(g=>g.readOnly),u=!r.has("chatgpt")&&!d,m=!r.has("claude")&&!d,p=g=>{const h=c(g);return h?ui(r.get(h)):Ie(g)},x=(g,h=!1)=>{const b=c(g);return b?e.jsx(vu,{group:b,accounts:r.get(b),bare:h,advanced:e.jsxs(e.Fragment,{children:[b==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Kt,{}),e.jsx($t,{})]}):e.jsx(Ht,{}),e.jsx(gi,{instance:g})]})}):e.jsx(Tu,{instance:g,bare:h})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(Lu,{rows:o,isReady:p,renderEngine:x,more:n}),m&&e.jsxs("div",{className:"px-4",children:[e.jsx(Kt,{}),e.jsx($t,{})]}),u&&e.jsx("div",{className:"px-4",children:e.jsx(Ht,{})})]}):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(ja,{})]}),e.jsx(ka,{instances:o,isReady:p,renderEngine:x}),m&&e.jsxs("div",{className:"px-4",children:[e.jsx(Kt,{}),e.jsx($t,{})]}),u&&e.jsx("div",{className:"px-4",children:e.jsx(Ht,{})}),e.jsx(Ou,{}),e.jsx(xi,{})]})}const zu={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function ct(s,n){return[zu[s],{signal:n}]}function Es(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Mu({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:u}){return e.jsxs(J,{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(Na,{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(Ce,{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(Re,{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(V,{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(Re,{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(vc,{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((m,p)=>{const x=Vu(m),g=As(x),h=r===m.name,b=Is(m.name);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:m.orphaned?t("vm.vps.orphan",{id:b}):m.ownerName}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",m.inUse||x==="running"?"bg-success/15 text-success":x==="stopped"||x==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:g}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:m.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:m.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),m.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>u(m),disabled:i||m.inUse||r!==null,"aria-busy":h||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:[h?e.jsx(V,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("vm.vps.remove")]})]},`${m.vpsAlias??""}:${m.name}`)})]})]})}const Uu=[1e3,2e3,4e3];function Fu(s){return new Promise(n=>window.setTimeout(n,s))}const Du={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},_u={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 As(s){return t(_u[s])}function Ku(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function Hu(s){return As(Ku(s))}function $u(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 fi(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 Wu(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:fi(Array.isArray(s.instances)?s.instances:[],n,a)}function Gu(s){return["idle","ready","running"].includes(s.state)}function Vu(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 Is(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function qu(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:Es(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Ju(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:Es(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function Yu(s){const n=Is(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:Es(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function Gt(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function Xu({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:u}){return e.jsxs(J,{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(Na,{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(Ce,{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(V,{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(Re,{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(ms,{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((m,p)=>{const x=$u(m),g=As(x),h=i?.boxId===m.boxId,b=Gu(m),y=x==="removing";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:m.orphaned?t("vm.cloud.orphan"):t("vm.cloud.ofBot",{name:m.ownerName??""})}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",m.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:g})]}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:m.orphaned?t("vm.owner.gone"):t("vm.cloud.machineId",{id:m.name})}),m.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(m),disabled:a||m.inUse||i!==null||!b,"aria-busy":h&&i?.action==="sleep"?!0:void 0,title:b?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:g.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[h&&i?.action==="sleep"?e.jsx(V,{size:12,className:"animate-spin"}):e.jsx(jc,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>u(m),disabled:a||m.inUse||i!==null||y,"aria-busy":h&&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:[h&&i?.action==="delete"?e.jsx(V,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]})]},m.boxId)})})]})}function Qu({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d}){return e.jsxs(J,{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(Ce,{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(V,{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(Re,{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,m)=>{const p=Hu(u),x=i===u.botId,g=u.managed===!0;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:u.name}),e.jsx("span",{className:O("rounded-full px-2 py-0.5 text-[11px]",g?u.inUse||u.ready?"bg-success/15 text-success":u.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:p})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Du[u.destination])})}),!g&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),g&&u.problem&&!u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:Ka(u.problem)}),g&&u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),g&&e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null,"aria-busy":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(V,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),t("common.delete")]})]},u.botId)})})]})}function dt({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(fe,{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 _e({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(V,{size:13,className:"animate-spin"}),a]})}const bi=5,yi=1440,Zu=480;function em(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=bi&&a<=yi?a:null}function tm({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[m,p]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const x=async()=>{if(!c||m)return;const g=em(i);if(g===null){u(t("vm.idle.range"));return}p(!0);try{await a(g),r(String(g)),o(!1),u("")}catch(h){u(h instanceof Error?h.message:t("vm.idle.error"))}finally{p(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[12px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className: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:bi,max:yi,step:1,inputMode:"numeric",value:i,disabled:n||m,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:g=>{r(g.target.value),o(!0),u("")},onBlur:()=>{x()},onKeyDown:g=>{g.key==="Enter"&&g.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 vi(){const s=$().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,m]=l.useState(null),[p,x]=l.useState(!1),[g,h]=l.useState(0),[b,y]=l.useState([]),[f,k]=l.useState(2),[C,N]=l.useState(!1),[w,R]=l.useState(null),[j,B]=l.useState(null),[v,E]=l.useState(null),[A,_]=l.useState(0),[Z,ee]=l.useState([]),[Y,te]=l.useState(null),[ne,ie]=l.useState(!0),[P,L]=l.useState(null),[I,K]=l.useState(null),[Q,le]=l.useState(null),[ae,U]=l.useState(0),X=l.useRef([]),oe=l.useRef({}),[pe,ce]=l.useState([]),[se,he]=l.useState(null),[F,re]=l.useState([]),[T,S]=l.useState(!0),[H,ue]=l.useState(null),[W,je]=l.useState(null),[Ee,We]=l.useState(null),[Ge,Le]=l.useState(0),[ur,Oe]=l.useState(""),Ve=l.useCallback(async z=>{const D=await fetch(...ct("status",z)),G=await D.json().catch(()=>({}));if(!z?.aborted){if(!D.ok)throw new Error(G.error??t("vm.err.status",{code:D.status}));return a(G),m(null),G}},[]),Et=l.useCallback(async z=>{const D=await fetch(...ct("local-vms",z)),G=await D.json().catch(()=>({}));if(!D.ok)throw new Error(G.error??t("vm.err.inventory",{code:D.status}));const q=G;y(q.instances),k(q.maxInstances),B(q.available?null:Ka(q.problem)??t("vm.err.runtimeUnavailable")),R(null)},[]),qe=l.useCallback(async z=>{const D=await fetch(...ct("cloud",z)),G=await D.json().catch(()=>({}));if(!D.ok)throw new Error(G.error??t("vm.err.cloudInventory",{code:D.status}));const q=G,ge=Wu(q,X.current,oe.current);oe.current=ge.overrides,X.current=ge.instances,ee(ge.instances),te(q.configured===!0),K(q.available||!q.configured?null:q.problem??t("vm.err.cloudUnavailable")),L(null)},[]),At=l.useCallback(async z=>{const D=await fetch(...ct("vps",z)),G=await D.json().catch(()=>({}));if(!D.ok)throw new Error(G.error??t("vm.err.vpsInventory",{code:D.status}));const q=G;ce(Array.isArray(q.instances)?q.instances:[]),he(q.configured===!0),re(Array.isArray(q.vpsAliases)?q.vpsAliases:[]),je(q.available||!q.configured?null:q.problem??t("vm.err.vpsUnavailable")),ue(null)},[]);l.useEffect(()=>{if(s)return;let z=!0,D,G;const q=async()=>{G=new AbortController;try{await Ve(G.signal)}catch(ge){z&&!(ge instanceof DOMException&&ge.name==="AbortError")&&(a(null),m(ge instanceof Error?ge.message:String(ge)))}finally{z&&(r(!1),D=window.setTimeout(()=>{q()},5e3))}};return q(),()=>{z=!1,G?.abort(),D!==void 0&&window.clearTimeout(D)}},[s,Ve,g]),l.useEffect(()=>{if(n?.mode!=="per-bot"){y([]),N(!1),R(null),B(null);return}const z=new AbortController;return N(!0),Et(z.signal).catch(D=>{D instanceof DOMException&&D.name==="AbortError"||R(D instanceof Error?D.message:String(D))}).finally(()=>{z.signal.aborted||N(!1)}),()=>z.abort()},[A,Et,n?.mode]),l.useEffect(()=>{const z=new AbortController;return ie(!0),qe(z.signal).catch(D=>{D instanceof DOMException&&D.name==="AbortError"||K(D instanceof Error?D.message:String(D))}).finally(()=>{z.signal.aborted||ie(!1)}),()=>z.abort()},[ae,qe]),l.useEffect(()=>{const z=new AbortController;return S(!0),At(z.signal).catch(D=>{D instanceof DOMException&&D.name==="AbortError"||je(D instanceof Error?D.message:String(D))}).finally(()=>{z.signal.aborted||S(!1)}),()=>z.abort()},[At,Ge]);const It=async(z,D)=>{const G=await fetch(`/api/local-computer/${z}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:D}),q=await G.json().catch(()=>({})),ge={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!G.ok)throw new Error(q.error??t(ge[z]));return D.throwIfAborted(),a(q),q},Os=z=>window.ogb?.confirm?window.ogb.confirm(z):window.confirm(z),Ue=async z=>{if(c!==null||d.current)return;const D=new AbortController;d.current=D,o(z),m(null);try{if(z==="remove"&&!await Os(t("vm.confirm.deleteShared"))||z==="recreate"&&!await Os(t("vm.confirm.recreate")))return;let G;if(z==="recreate"?(await It("remove",D.signal),G=await It("run",D.signal)):G=await It(z,D.signal),(z==="run"||z==="start"||z==="recreate")&&(G=await Fc(G,async()=>await Ve(D.signal)??G,D.signal),!G.ready))throw new Error(G.problem??t("vm.err.start"));await Ve(),Oe(z==="remove"?t("vm.announce.deleted"):z==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(G){if(D.signal.aborted)return;m(G instanceof Error?G.message:String(G))}finally{d.current=null,D.signal.aborted||o(null)}},zs=async(z,D)=>{x(!0),m(null);try{const G=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:z,maxInstances:D}})}),q=await G.json().catch(()=>({}));if(!G.ok)throw new Error(q.error??t("vm.policyError"));a(ge=>ge&&{...ge,mode:z,max_instances:D}),await Ve()}catch(G){m(G instanceof Error?G.message:String(G))}finally{x(!1)}},mr=async z=>{const D=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:z}})}),G=await D.json().catch(()=>({}));if(!D.ok)throw new Error(G.error??t("vm.idle.error"));a(q=>q&&{...q,idle_timeout_ms:z*6e4})},pr=async z=>{if(!z.managed){R(t("vm.unmanagedError"));return}const D=Gt(qu(z),G=>window.confirm(G));if(D){E(z.botId),R(null);try{const G=await fetch(...D),q=await G.json().catch(()=>({}));if(!G.ok)throw new Error(q.error??t("vm.deleteError"));await Et(),Oe(t("vm.announce.deletedBot",{name:z.name}))}catch(G){R(G instanceof Error?G.message:String(G))}finally{E(null)}}},Ms=async(z,D)=>{const G=Gt(Ju(z,D),q=>window.confirm(q));if(G){le({boxId:D.boxId,action:z}),L(null),Oe("");try{const q=await fetch(...G),ge=await q.json().catch(()=>({}));if(!q.ok)throw new Error(ge.error??t(z==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const Tt=z==="delete"&&ge?.pending===!0;oe.current={...oe.current,[D.boxId]:z==="delete"?Tt?"deleting":"deleted":"sleeping"};const Bt=fi(X.current,X.current,oe.current);oe.current=Bt.overrides,X.current=Bt.instances,ee(Bt.instances);const Fe=D.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:D.ownerName??""});if(Oe(Tt?`${Fe}: ${t("vm.state.removing")}.`:t(z==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Fe})),Tt){for(const we of Uu){await Fu(we);try{await qe()}catch{}if(oe.current[D.boxId]!=="deleting"){Oe(t("vm.announce.cloudDeleted",{subject:Fe}));return}}const De={...oe.current};delete De[D.boxId],oe.current=De;const lt=X.current.map(we=>we.boxId===D.boxId?{...we,state:D.state}:we);X.current=lt,ee(lt);try{await qe(),X.current.some(we=>we.boxId===D.boxId)||Oe(t("vm.announce.cloudDeleted",{subject:Fe}))}catch(we){const gr=we instanceof Error?we.message:String(we);L(`${Fe}: ${t("vm.state.removing")}. ${gr}`)}return}try{await qe()}catch(De){const lt=De instanceof Error?De.message:String(De);L(t(z==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Fe,detail:lt}))}}catch(q){L(q instanceof Error?q.message:String(q))}finally{le(null)}}},xr=async z=>{const D=Is(z.name),G=Gt(Yu(z),q=>window.confirm(q));if(G){We(z.name),ue(null);try{const q=await fetch(...G),ge=await q.json().catch(()=>({}));if(!q.ok)throw new Error(ge.error??t("vm.vpsRemoveError"));await At(),Oe(t("vm.announce.vpsRemoved",{subject:z.orphaned?t("vm.announce.orphanVps",{id:D}):t("vm.confirm.ownedVps",{name:z.ownerName??""})}))}catch(q){ue(q instanceof Error?q.message:String(q))}finally{We(null)}}},Ae=n?.commands,rt=n?.ready===!0,Us=n?.container!=="missing",Fs=!!(Us&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ds=!i&&!n,_s=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),ke=n?.mode==="per-bot",Pt=ke&&n?.runtime==="container",Rt=ke?!!(n?.daemonUp&&n?.image&&!Pt):rt;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:ur}),e.jsx(Xu,{instances:Z,configured:Y,loading:ne,pending:Q,error:P,unavailableReason:I,onRefresh:()=>U(z=>z+1),onSleep:z=>{Ms("sleep",z)},onDelete:z=>{Ms("delete",z)}}),e.jsx(Mu,{instances:pe,configured:se,aliases:F,loading:T,removingName:Ee,error:H,unavailableReason:W,onRefresh:()=>Le(z=>z+1),onRemove:z=>{xr(z)}}),e.jsx(Uc,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(J,{title:t("vm.main.title"),subtitle:ke?t("vm.main.perBotSubtitle",{host:_s}):t("vm.main.sharedSubtitle",{host:_s}),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]",Rt?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(V,{size:12,className:"animate-spin"}):Rt?e.jsx(fe,{size:12}):e.jsx(gl,{size:9}),i?t("common.checking"):Ds?t("vm.main.statusUnavailable"):ke&&Rt?t("vm.main.readyPerBot"):Pt?t("vm.main.perBotUnsupported"):rt?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),h(z=>z+1),_(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(Ce,{size:12})," ",t("vm.main.recheck")]}),rt&&!ke&&e.jsxs("a",{href:n?.viewer_url??Ae?.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(it,{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(J,{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,D)=>e.jsx("button",{type:"button",disabled:!n||p,onClick:()=>{zs(z,n?.max_instances??2)},className:O("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",D>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))}),ke&&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(me,{size:"sm","aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||p,onChange:z=>{zs(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(tm,{minutes:n?Math.round(n.idle_timeout_ms/6e4):Zu,disabled:!n||p,onSave:mr}),p&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(V,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(J,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(dt,{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")}),Ae?.install?e.jsx(Xe,{command:Ae.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(dt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Ae?.runtimeStart?e.jsx(Xe,{command:Ae.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(dt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(_e,{action:"pull",pending:c,onClick:()=>{Ue("pull")},children:t("vm.setup.prepare")}),Ae?.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(Xe,{command:Ae.pull})})]})]}),e.jsxs(dt,{n:4,title:ke?t("vm.setup.step4PerBot"):Fs?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!ke&&rt,children:[ke?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Pt?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):Fs?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Re,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(_e,{action:"recreate",pending:c,onClick:()=>{Ue("recreate")},danger:!0,children:[e.jsx(hl,{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(_e,{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(V,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(_e,{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,Ae?.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(Xe,{command:Ae.run})})]})]})]})}),ke&&e.jsx(Qu,{instances:b,maxInstances:f||n?.max_instances||2,loading:C,deletingBotId:v,error:w,unavailableReason:j,onRefresh:()=>_(z=>z+1),onDelete:z=>{pr(z)}}),Ds&&e.jsx(J,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Re,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(J,{title:t("vm.safety.title"),subtitle:ke?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:[Us&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(_e,{action:"stop",pending:c,onClick:()=>{Ue("stop")},children:[e.jsx(fl,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(_e,{action:"remove",pending:c,onClick:()=>{Ue("remove")},danger:!0,children:[e.jsx(Se,{size:12})," ",ke?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.37.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function ji(s){return t("pairing.worksOnceUntil",{time:hr(s)})}function ns(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const sm="/api/team/phone-pairing",wn="/api/team/phones",nm=4e3;function am(s){return`${s.label} · ${s.email}`}function im({team:s,blocked:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(null),[u,m]=l.useState(!1),[p,x]=l.useState(null),[g,h]=l.useState(()=>Date.now()),b=N=>x(t("remote.serverPairing.error",{error:N instanceof Error?N.message:String(N)}));async function y(){try{const N=await M(wn);c(Array.isArray(N?.phones)?N.phones:[]),d(typeof N?.current=="string"?N.current:null)}catch(N){b(N)}}l.useEffect(()=>{y()},[]);const f=a?a.expiresAt<=g:!1;l.useEffect(()=>{if(!a)return;const N=setInterval(()=>h(Date.now()),15e3);return()=>clearInterval(N)},[a]),l.useEffect(()=>{if(!a||f)return;const N=setInterval(()=>{y()},nm);return()=>clearInterval(N)},[a,f]);async function k(){m(!0),x(null);try{i(await M(sm,{method:"POST",body:"{}"})),h(Date.now())}catch(N){b(N)}finally{m(!1)}}async function C(N){x(null);try{await M(`${wn}/${encodeURIComponent(N)}`,{method:"DELETE"})}catch(w){b(w)}await y()}return e.jsxs(J,{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:()=>{k()},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:f?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[a.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(wa,{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:ji(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(N=>e.jsxs("li",{"data-team-phone":N.id,className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[am(N),e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("remote.serverPairing.seen",{when:ns(N.lastSeenAt,g)}),N.id===o?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),N.id===o?null:e.jsx("button",{type:"button","data-team-phone-remove":!0,onClick:()=>{C(N.id)},className:"ui-button",children:t("teamPhone.remove")})]},N.id))})]}):null,p?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:p}):null]})}function rm({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 m(){const p=i.trim();if(!(c||p===s)){o(!0),u(null);try{const x=await M("/api/config",{method:"PATCH",body:JSON.stringify({computerName:p})});n(x.computerName??p)}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:p=>r(p.target.value),onBlur:()=>{m()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"w-full max-w-xs rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("p",{id:"computer-name-help",className:"text-[12px] leading-4 text-ink-secondary",children:t("remote.computerName.help")}),d?e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d}):null]})}function Ze(s){return Kc(s)}function lm(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function om(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}const cm="ui-button ui-button-primary",Sn="ui-button";function dm({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,m]=l.useState(s),[p,x]=l.useState(n),[g,h]=l.useState(null),[b,y]=l.useState("admin"),[f,k]=l.useState(null),[C,N]=l.useState([]),[w,R]=l.useState(null),[j,B]=l.useState(!1),[v,E]=l.useState("idle"),[A,_]=l.useState(null),[Z,ee]=l.useState(()=>Date.now()),Y=l.useRef(null),te=l.useRef(0);async function ne(){try{const U=await M("/api/auth/sessions");N(Array.isArray(U?.sessions)?U.sessions:[]),R(typeof U?.current=="string"?U.current:null)}catch(U){_(t("remote.serverPairing.error",{error:U instanceof Error?U.message:String(U)}))}}if(l.useEffect(()=>{Ha().then(U=>{m(U),Ze(U)&&ne(),(U.kind==="loopback"||U.kind==="session")&&M("/api/config").then(X=>{x($a(X).pairingCodes),Ze(U)&&h(typeof X?.computerName=="string"?X.computerName:"")}).catch(()=>{})})},[]),l.useEffect(()=>{i?te.current!==i&&_c(Y.current)&&(te.current=i):te.current=0},[i,u]),l.useEffect(()=>{if(!f)return;const U=setInterval(()=>ee(Date.now()),15e3);return()=>clearInterval(U)},[f]),r&&u?.kind==="session"&&u.team)return e.jsx("div",{ref:Y,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(im,{team:r,blocked:c})});if(!Ze(u))return lm(u)!=="chat-only"?null:e.jsx("div",{ref:Y,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(J,{title:t("remote.serverPairing.title"),subtitle:t(p?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(p?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const ie=f?f.expiresAt<=Z:!1,P=om(C,a);async function L(){B(!0),_(null),E("idle");try{const U=await M("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:b==="admin"||a?["admin","client"]:["client"]})});k(U),ee(Date.now())}catch(U){_(t("remote.serverPairing.error",{error:U instanceof Error?U.message:String(U)}))}finally{B(!1)}}async function I(U){_(null);try{await M(`/api/auth/sessions/${encodeURIComponent(U)}`,{method:"DELETE"}),await ne()}catch(X){_(t("remote.serverPairing.error",{error:X instanceof Error?X.message:String(X)}))}}async function K(){if(!f?.url)return;const U=await kc(f.url);U!=="empty"&&E(U)}const Q=p&&f?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:ie?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[f.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(wa,{value:f.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:f.code}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:ji(f.expiresAt)}),f.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:f.url}),e.jsx("button",{type:"button",onClick:()=>{K()},className:Sn,children:t(v==="copied"?"remote.serverPairing.copied":v==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[13px] text-ink-secondary",children:f.hint??t("remote.serverPairing.noLink")})]})]})}):null,le=U=>p&&!a&&g!==null?e.jsx(rm,{saved:g,onSaved:h,className:U}):null,ae=U=>t(U.scopes.includes("admin")?"remote.serverPairing.scope.admin":"remote.serverPairing.scope.client");return o?e.jsxs("div",{ref:Y,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(Sa,"flex flex-col"),children:[le("px-4 py-2.5"),e.jsx(de,{title:t("settings.simple.computer.pair"),subtitle:p?a?t("remote.serverPairing.cloudPersonal"):void 0:t("remote.serverPairing.portal"),children:p?e.jsxs("div",{className:"flex items-center gap-2",children:[a?null:e.jsxs(me,{variant:"ghost",value:b,"aria-label":t("remote.serverPairing.title"),onChange: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:()=>{L()},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,P.length===0?e.jsx("p",{className:"px-4 py-2.5 text-[13px] leading-[18px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):P.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:ns(U.lastSeenAt,Z)}),U.id===w?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),U.id===w?null:e.jsx("button",{type:"button",onClick:()=>{I(U.id)},className:"ui-button ml-auto shrink-0",children:t("remote.serverPairing.signOut")})]},U.id))]}),A?e.jsx("p",{className:"pl-4 text-[12px] leading-4 text-danger",children:A}):null]}):e.jsx("div",{ref:Y,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(J,{title:t("remote.serverPairing.title"),subtitle:t(p?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[p&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,le("mt-3"),p?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="admin",onChange:()=>y("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:b==="client",onChange:()=>y("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":d?"":void 0,onClick:()=>{L()},disabled:j,className:cm,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(p?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),P.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:P.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:ns(U.lastSeenAt,Z)}),U.id===w?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),U.id===w?null:e.jsx("button",{type:"button",onClick:()=>{I(U.id)},className:Sn,children:t("remote.serverPairing.signOut")})]},U.id))}),A?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:A}):null]})})}function um({profileEmail:s="",focusRequest:n=0,simple:a=!1}){return e.jsx(bl,{})}function mm(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 Cn(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 pm(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function En(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function xm(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 m=n.filter(x=>x.email?.toLowerCase()===u),p=a.find(x=>x.key===`user:${u}`);i.push({entry:u,role:d,isDomain:u.startsWith("@"),lastSeenAt:m.length?Math.max(...m.map(x=>x.lastSeenAt)):null,devices:m.length,turns:p?.turns??0,costUsd:p?.costUsd??null,...et(p?.estimatedUsd)&&p.estimatedUsd>0?{estimated:!0}:{}})};for(const o of s.admins)c(o,"admin");for(const o of s.members)c(o,"member");return i}function gm(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 hm(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 ki({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?"—":hm(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:et(d.costUsd)?`${d.estimated?"~":""}${tt(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(yl,{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 Ni({link:s}){const{state:n,copy:a}=vs(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(fe,{size:13,className:"text-success"}):n==="failed"?e.jsx(Be,{size:13,className:"text-danger"}):e.jsx(Fa,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function fm({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(J,{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(it,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(ki,{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 wi({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[u,m]=l.useState(null),[p,x]=l.useState(null),[g,h]=l.useState([]),[b,y]=l.useState(typeof window<"u"?window.location.origin:""),[f,k]=l.useState(null),[C,N]=l.useState(""),[w,R]=l.useState("member"),[j,B]=l.useState(null),[v,E]=l.useState(!1),[A,_]=l.useState(!1),[Z,ee]=l.useState(null),Y=l.useCallback(async()=>{_(!0),ee(null);try{const[L,I,K,Q,le]=await Promise.all([M("/api/config"),M("/api/auth/sessions").catch(()=>({sessions:[]})),M("/api/usage?groupBy=user").catch(()=>({groups:[]})),M("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(pe=>pe.ok?pe.json():null).catch(()=>null)]),ae={admins:Array.isArray(L?.signIn?.admins)?L.signIn.admins:[],members:Array.isArray(L?.signIn?.members)?L.signIn.members:[]},U=$a(L);m(U),x(ae);const X=Array.isArray(I?.sessions)?I.sessions:[],oe=Array.isArray(K?.groups)?K.groups:[];h(U.authority==="portal"?gm(X,oe):xm(ae,X,oe)),typeof Q?.publicUrl=="string"&&Q.publicUrl&&y(Q.publicUrl),k(le?.capabilities?.emailSignIn===!0?!0:le?!1:null)}catch(L){ee(L instanceof Error?L.message:String(L))}finally{_(!1)}},[]);l.useEffect(()=>{Ha().then(L=>{d(L),Ze(L)&&Y()})},[Y]);const te=async L=>{E(!0),ee(null);try{await M("/api/config",{method:"PUT",body:JSON.stringify({signIn:L})}),await Y()}catch(I){ee(I instanceof Error?I.message:String(I))}finally{E(!1)}},ne=async()=>{if(c(!0),!p||v)return;const L=mm(C);if(!L){ee(t("remote.signInAccess.invalid"));return}await te(Cn(p,L,w)),N(""),B(En(b,L))};if(!Ze(o))return null;const ie=u?.authority==="portal"?e.jsx(fm,{peopleUrl:u.peopleUrl,people:g}):null,P=e.jsxs(e.Fragment,{children:[f===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(u?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:L=>{L.preventDefault(),ne()},children:[e.jsx("input",{value:C,onChange:L=>N(L.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:v,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(me,{value:w,onChange:L=>R(L.target.value),"aria-label":t("people.colRole"),disabled:v,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:v||!C.trim(),className:"ui-button ui-button-primary",children:[v?e.jsx(V,{size:13,className:"animate-spin"}):e.jsx(Ne,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{Y()},disabled:A||v,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(Ce,{size:13,className:O(A&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),j&&e.jsx(Ni,{link:j}),Z&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:Z}),e.jsx("div",{className:"mt-4",children:e.jsx(ki,{people:g,busy:v,onRole:(L,I)=>{p&&te(Cn(p,L.entry,I))},onRemove:L=>{p&&te(pm(p,L.entry))},onLink:L=>B(En(b,L.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(ht,{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:ie??P})]}):ie??e.jsx(J,{title:t("people.title"),subtitle:t("people.subtitle"),children:P})}const Vt="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 bm({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(ps())}),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:qc(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:Jc(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:vl(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(js,{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:un(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:un(s.after?.[r])})]},r))]})]})]})})}function Si(){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,m]=l.useState(!1),[p,x]=l.useState(null),g=Gc(s),h=l.useCallback(async()=>{m(!0),x(null);try{const y=await M(`/api/admin-activity${g}`);i(y.entries),c(y.total),d(y.retentionDays)}catch(y){x(y instanceof Error?y.message:String(y))}finally{m(!1)}},[g]);l.useEffect(()=>{const y=window.setTimeout(()=>{h()},250);return()=>window.clearTimeout(y)},[h]);const b=y=>n(f=>({...f,...y}));return e.jsxs(J,{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(Vt,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(me,{value:s.what,onChange:y=>b({what:y.target.value}),children:Vc.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:Vt})]}),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:Vt})]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:u,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:u?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(Ce,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${g}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(bs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),p&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:p})}),!p&&a.length===0&&!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,f)=>e.jsx(bm,{entry:y},`${y.at}-${f}`))}),r>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(r)})})]})}const An=4,Ps="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",Rs="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",ym=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),Ci=(s,n)=>Nt(s)===n||Aa(wt(s),n)!=="none",Ei=(s,n)=>{const a=Ca(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},In=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function vm(){const{state:s}=$(),n=jl(),a=kl(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[u,m]=l.useState(null),[p,x]=l.useState(null),g=l.useRef(null),[h,b]=l.useState(null),[y,f]=l.useState(""),k=l.useCallback(()=>b(null),[]);if(l.useEffect(()=>{p||!g.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(v=>v.dataset.accessPerson===g.current)?.focus(),g.current=null)},[p]),!n||!a)return null;const C=n.people.filter(v=>v.role==="member").sort((v,E)=>v.name.localeCompare(E.name)),N=ym(s.bots),w=u?N.find(v=>v.id===u):void 0,R=p?C.find(v=>v.email===p):void 0,j=o.trim().toLowerCase(),B=async(v,E,A)=>{f("");const _=wt(v);try{await Qs(v.id,E),b({botId:v.id,before:_,after:E,text:A})}catch(Z){f(Z instanceof Error?Z.message:String(Z))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[R?e.jsx(wm,{person:R,bots:N.filter(v=>Ci(v,R.email)),team:n,teamName:a,apply:B,onBack:()=>{g.current=R.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(at,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value:o,"data-access-search":!0,"aria-label":t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),placeholder:t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),onChange:v=>d(v.target.value),onKeyDown:v=>{v.key==="Escape"&&o&&(v.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(v=>e.jsx("button",{type:"button","aria-pressed":r===v,"data-access-listing":v,onClick:()=>{c(v),d("")},className:O("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===v?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(v==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},v))})]}),r==="bot"?e.jsx(jm,{bots:N.filter(v=>!j||In(j,v.name,Ca(v,n)?.name,Nt(v)??void 0)),anyBots:N.length>0,team:n,onOpen:m}):e.jsx(Nm,{people:C.filter(v=>!j||In(j,v.name,v.email)),anyPeople:C.length>0,bots:N,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}),w&&e.jsx(Nl,{bot:w,teamName:a,onClose:()=>m(null),onChanged:v=>b({botId:w.id,...v})}),h&&e.jsx(wl,{text:h.text,onUndo:()=>Qs(h.botId,h.before),onDone:k},`${h.botId}:${h.text}:${JSON.stringify(h.after)}`)]})}function jm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Rs,children:s.map(r=>{const c=wt(r),o=Nt(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(Ps,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Ct,{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:Ei(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(km,{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 km({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>Cl(r,n)).join(", "),i=s.length-An;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,An).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(El,{person:Al(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 Nm({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Rs,children:s.map(r=>{const c=a.filter(o=>Ci(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(Ps,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Ea,{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 wm({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(fr,{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(Ea,{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:Rs,children:n.map(o=>e.jsx(Sm,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function Sm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=wt(s),o=Nt(s)===n.email,d=c.people[n.email],u=Aa(c,n.email);return e.jsxs("li",{className:Ps,"data-access-person-bot":s.id,children:[e.jsx(Ct,{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}):Ei(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,Sl(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 Cm(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 Em({domain:s,serverIpv4:n}){const a=Cm(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(Xe,{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 Am(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 Im({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:Am(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(it,{size:12})]})]})}function Pm(){const[s,n]=l.useState(null),[a,i]=l.useState(""),[r,c]=l.useState("loading"),[o,d]=l.useState(null),[u,m]=l.useState(null);l.useEffect(()=>{const x=new AbortController;return M("/api/settings/custom-domain",{signal:x.signal}).then(g=>{x.signal.aborted||(n(g),i(g.customDomain??""))}).catch(g=>{x.signal.aborted||d(g instanceof Error?g.message:t("settings.domain.failed"))}).finally(()=>{x.signal.aborted||c(null)}),()=>x.abort()},[]);const p=async x=>{c(x?"removing":"saving"),d(null),m(null);try{const g=await M("/api/settings/custom-domain",{method:x?"DELETE":"POST",...x?{}:{body:JSON.stringify({domain:a.trim()})}});n(g),i(g.customDomain??""),m(x?t("settings.domain.removed"):t("settings.domain.saved"))}catch(g){d(g instanceof Error?g.message:t("settings.domain.failed"))}finally{c(null)}};return e.jsx(J,{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(V,{size:14,className:"animate-spin"}),t("settings.domain.loading")]}),s&&!s.supported&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:x=>{x.preventDefault(),a.trim()&&!r&&p(!1)},className:"space-y-2",children:[e.jsx("label",{htmlFor:"custom-domain",className:"block text-[13px] font-medium text-ink",children:t("settings.domain.label")}),e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:r!==null,onChange:x=>{i(x.target.value),m(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(Em,{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(V,{size:14,className:"animate-spin"}):e.jsx(Il,{size:14}),r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{p(!0)},className:"rounded-lg bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:r==="removing"?t("settings.domain.removing"):t("settings.domain.remove")})]})]}),s.publicUrl&&e.jsxs("p",{className:"break-all text-[12px] text-ink-secondary",children:[t("settings.domain.current"),": ",e.jsx("span",{className:"text-ink",children:s.publicUrl})]}),s.customDomain&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")}),e.jsx(Im,{status:s})]}),u&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(fe,{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 Rm=Pl,as="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",is="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function Ai({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(St,{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(V,{size:13,className:"animate-spin"}),r]})]})]})}function Pn({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=l.useState(s?.name??""),[o,d]=l.useState(""),[u,m]=l.useState(s?.bots??"all"),[p,x]=l.useState(!1),[g,h]=l.useState(null),b=async y=>{if(y.preventDefault(),!p){x(!0),h(null);try{s?await Rl(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:o,bots:u}):await Tl(r.trim(),o,u),d(""),await i()}catch(f){h(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{x(!1)}}};return e.jsxs(Ai,{form:"secret-form",onSubmit:y=>{b(y)},onCancel:a,pending:p,error:g,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:is,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:Rm,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:y=>c(y.target.value),disabled:p,className:as}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:is,children:[t(s?"settings.vault.secret.valueKeep":"settings.vault.secret.value"),e.jsx("input",{name:"secretValue",type:"password",autoComplete:"new-password",spellCheck:!1,required:!s,value:o,placeholder:"••••••••",onChange:y=>d(y.target.value),disabled:p,className:as})]}),e.jsx(st,{value:u,onChange:m,bots:n,disabled:p})]})}function Tm({bots:s,onCancel:n,onSaved:a}){const[i,r]=l.useState(""),[c,o]=l.useState("all"),[d,u]=l.useState(!1),[m,p]=l.useState(null),[x,g]=l.useState(null),h=async b=>{if(b.preventDefault(),d)return;const y=Bl(i);if(!y.length){p(t("settings.vault.env.none"));return}u(!0),p(null),g(null);try{g(await Ll(y,c)),r("")}catch(f){p(f instanceof Error&&f.message?f.message:t("settings.vault.secret.saveError"))}finally{u(!1),await a().catch(()=>{})}};return e.jsxs(Ai,{form:"env-form",onSubmit:b=>{h(b)},onCancel:n,pending:d,error:m,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:is,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:`${as} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(st,{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 Rn={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",linked:"settings.logins.source.1password"},rs="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",Bm=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function Lm(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 Ii(){const{state:s,dispatch:n}=$(),a=vt(),i=s.bots.map(S=>({id:S.id,name:S.name})),[r,c]=l.useState(null),[o,d]=l.useState([]),[u,m]=l.useState({connected:!1}),[p,x]=l.useState(null),[g,h]=l.useState(""),[b,y]=l.useState("all"),[f,k]=l.useState(!1),[C,N]=l.useState(null),[w,R]=l.useState(""),[j,B]=l.useState("all"),[v,E]=l.useState(!1),[A,_]=l.useState(null),[Z,ee]=l.useState("all"),[Y,te]=l.useState(!1),[ne,ie]=l.useState(!1),[P,L]=l.useState(null),[I,K]=l.useState(!1),[Q,le]=l.useState([]),ae=async()=>{try{const S=await Ml();c(S.logins??[]),d(S.secrets??[]),m(S.onePassword??{connected:!1}),x(null)}catch(S){x(S instanceof Error&&S.message?S.message:t("settings.vault.loadError"))}};if(l.useEffect(()=>{a&&ae()},[a]),a===!1)return e.jsx(J,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const U=S=>{if(S==="all")return t("settings.logins.allBots");const H=S.flatMap(ue=>i.find(W=>W.id===ue)?.name??[]);return H.length?H.join(", "):t("settings.logins.noBots")},X=S=>S?t("settings.logins.used",{when:Dc(S)}):t("settings.logins.neverUsed"),oe=(S,H)=>{N(null),L(null),ie(!1),H&&(ee(H.bots),te(H.exactHost)),_(S)},pe=S=>{k(!1),_(null),L(null),N(S)},ce=async(S,H)=>{if(P!==S){L(S);return}K(!0),le([]);try{H==="login"?await _l(S):le(await Kl(S)),L(null),await ae()}catch(ue){x(ue instanceof Error&&ue.message?ue.message:t("settings.logins.deleteError"))}finally{K(!1)}},se=(S,H,ue,W)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx("button",{type:"button",className:rs,disabled:I,onClick:W,"aria-label":H==="login"?t("settings.logins.changeFor",{site:ue}):t("settings.vault.secret.changeFor",{name:ue}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:rs,disabled:I,onClick:()=>{ce(S,H)},"aria-label":P===S?t("settings.logins.deleteConfirm"):H==="login"?t("settings.logins.deleteFor",{site:ue}):t("settings.vault.secret.deleteFor",{name:ue}),children:[e.jsx(Se,{size:13}),P===S?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),he=Lm(r??[],o,b,g),F=r!==null&&r.length===0&&o.length===0,re=S=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":S.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(St,{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:S.site,children:S.site}),S.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(Ul,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:S.username||t("settings.logins.noUsername")}),Tn(S)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:Tn(S)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Rn[S.source]),U(S.bots),X(S.lastUsedAt)].join(" · ")}),en(S,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(en(S,s.bots))})})]}),S.source!=="1password"&&se(S.id,"login",S.site,()=>oe(S.id,S))]}),A===S.id&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(Zs,{username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>_(null),onSubmit:async H=>{await Fl(S.id,{password:H.password,totp:H.totp,removeTotp:ne,bots:Z,...Y===S.exactHost?{}:{exactHost:Y}}),_(null),await ae()},children:[S.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:ne,onChange:H=>ie(H.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(Bn,{checked:Y,onChange:te,label:t("settings.logins.exactHostFor",{hosts:S.hosts.join(", "),site:S.site})}),e.jsx(st,{value:Z,onChange:ee,bots:i})]})})]},S.id),T=S=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":S.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Ia,{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:S.name,children:S.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Rn[S.source]),U(S.bots),X(S.lastUsedAt)].join(" · ")})]}),S.source!=="linked"&&se(S.id,"secret",S.name,()=>oe(S.id))]}),A===S.id&&S.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx(Pn,{secret:S,bots:i,onCancel:()=>_(null),onSaved:async()=>{_(null),await ae()}})})]},S.id);return e.jsx(J,{title:t("settings.vault.title"),subtitle:t("settings.vault.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3","aria-busy":r===null||I,"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(at,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-vault-search":!0,type:"text",value:g,onChange:S=>h(S.target.value),autoComplete:"off",spellCheck:!1,placeholder:t("settings.vault.search"),"aria-label":t("settings.vault.search"),className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",className:"ui-button ui-button-md",disabled:r===null,"aria-expanded":f,onClick:()=>k(!f),onKeyDown:S=>{S.key==="Escape"&&k(!1)},children:[e.jsx(Ne,{size:14}),t("settings.vault.add"),e.jsx(ua,{size:13,"aria-hidden":"true"})]}),f&&e.jsx("div",{className:"absolute end-0 top-full z-10 mt-1 flex min-w-[11rem] flex-col rounded-lg border border-hairline/60 bg-menu p-1 shadow-lg","data-vault-add":!0,children:Bm.map(([S,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:()=>pe(S),children:t(H)},S))})]})]}),e.jsx(Ol,{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(Zs,{site:{value:w,onChange:R},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>N(null),onSubmit:async S=>{await zl(w,S,j,v),N(null),R(""),B("all"),E(!1),await ae()},children:[e.jsx(Bn,{checked:v,onChange:E,label:t("settings.logins.exactHost")}),e.jsx(st,{value:j,onChange:B,bots:i})]})}),C==="secret"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(Pn,{bots:i,onCancel:()=>N(null),onSaved:async()=>{N(null),await ae()}})}),C==="env"&&e.jsx("div",{className:"rounded-lg bg-inset/60 p-3",children:e.jsx(Tm,{bots:i,onCancel:()=>N(null),onSaved:ae})}),r===null&&!p&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.vault.loading")}),F&&!C&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.vault.empty")}),!F&&r!==null&&he.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary","data-vault-none":!0,children:t("settings.vault.noMatch")}),he.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/30","data-logins-list":!0,children:he.map(S=>S.kind==="login"?re(S.login):T(S.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(", ")})}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline/30 pt-3","data-vault-keys":!0,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.vault.keys.title")}),e.jsx("div",{className:"text-[12px] leading-snug text-ink-tertiary",children:t("settings.vault.keys.hint")})]}),e.jsx("button",{type:"button",className:"ui-button ui-button-md shrink-0",onClick:()=>n({type:"toggleAppSettings",open:!0,section:"connections"}),children:t("keys.row.open")})]}),e.jsx(zm,{status:u,disabled:r===null,bots:i,botNames:U,onChange:async S=>{m(S),await ae()}})]})})}function Tn(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 Bn({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 Om({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,o]=l.useState(!1),[d,u]=l.useState(s.bots),[m,p]=l.useState(!1),[x,g]=l.useState(null),h=async()=>{p(!0),g(null);try{await r(await Hl(s.id,d)),o(!1)}catch(b){g(b instanceof Error&&b.message?b.message:t("settings.logins.onePassword.error"))}finally{p(!1)}};return e.jsxs("li",{className:"flex flex-col gap-2 py-2","data-vault":s.title,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:s.title}),e.jsx("div",{className:"text-[12px] text-ink-tertiary",children:t("settings.logins.onePassword.vaultUse",{count:String(s.items),who:a(s.bots)})})]}),!c&&e.jsx("button",{type:"button",className:rs,disabled:i||m,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(st,{value:d,onChange:u,bots:n,disabled:m}),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:m,onClick:()=>o(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:m,onClick:()=>{h()},children:t("settings.logins.saveChange")})]})]})]})}function zm({status:s,disabled:n,bots:a,botNames:i,onChange:r}){const[c,o]=l.useState(""),[d,u]=l.useState(null),[m,p]=l.useState(null),x=async(h,b)=>{if(!d){u(h),p(null);try{await r(await b()),h==="connect"&&o("")}catch(y){p(y instanceof Error&&y.message?y.message:t("settings.logins.onePassword.error"))}finally{u(null)}}},g=h=>{h.preventDefault(),c.trim()&&x("connect",()=>Dl(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(h=>h.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(h=>e.jsx(Om,{vault:h,bots:a,botNames:i,disabled:n,onChange:r},h.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",$l)},children:[d==="refresh"?e.jsx(V,{size:13,className:"animate-spin"}):e.jsx(Ce,{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",Wl)},children:t("settings.logins.onePassword.disconnect")})]})]}):e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:g,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:h=>o(h.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(V,{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(St,{size:11,"aria-hidden":"true",className:"mt-[3px] shrink-0"})," ",t("settings.logins.onePassword.note")]}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m})]})}const qt="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 Ln(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Mm(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=br(n);return a.ok&&(a.code!==null||a.credential!==null)}function Um({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,m]=l.useState(""),[p,x]=l.useState(""),[g,h]=l.useState(""),[b,y]=l.useState(!1),[f,k]=l.useState(""),C=l.useRef(!1),N=!!i&&o==="server",w=l.useRef(!0),R=l.useCallback(()=>{a?.state().then(v=>{w.current&&c(v)}).catch(()=>{})},[a]);l.useEffect(()=>(w.current=!0,R(),()=>{w.current=!1}),[R]);const j=async()=>{if(!(C.current||!a&&!i)){C.current=!0,y(!0),k("");try{if(N&&i){if(!Mm(u))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(u.trim()),R()}else a&&(await a.pair(p,g),R())}catch(v){k(Ln(v))}finally{C.current=!1,y(!1)}}},B=async()=>{if(!(!a||C.current)){C.current=!0,y(!0),k("");try{await a.disconnect(),R()}catch(v){k(Ln(v))}finally{C.current=!1,y(!1)}}};return!a&&!i&&s||n&&!r.active?null:e.jsxs(J,{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(gt,{size:18,className:"mt-0.5 shrink-0 text-success"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:t("remote.client.connected",{name:r.serverName||t("remote.client.fallbackName")})}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:r.endpoint})]})]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.mode")}),e.jsx("p",{role:"status",className:"rounded-lg bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink","data-legacy-client-notice":"",children:t("remote.client.endsDec7")}),e.jsxs("button",{type:"button",disabled:b,onClick:()=>{B()},className:"flex w-fit items-center gap-2 rounded-lg border border-danger/30 px-3 py-2 text-[13px] text-danger hover:bg-danger/10 disabled:opacity-50",children:[b?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(hd,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:v=>{v.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(me,{value:o,disabled:b,onChange:v=>{d(v.target.value),k("")},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,N?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:v=>m(v.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:b,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:qt})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("remote.client.server.domainHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.companion.hint")}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.address"),e.jsx("input",{value:p,onChange:v=>x(v.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:b,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:qt})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.code"),e.jsx("input",{value:g,onChange:v=>h(v.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:b,inputMode:"numeric",autoComplete:"one-time-code",className:`${qt} max-w-40 font-mono tracking-[0.2em]`})]})]}),f?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:f}):null,e.jsxs("button",{type:"submit",disabled:b||(N?!u.trim():p.trim()===""||g.length!==6),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[b?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(gt,{size:14}),N?t("remote.client.server.connect"):t("remote.client.pair")]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:N?t("remote.client.server.switchNote"):t("remote.client.restartNote")})]}),r.active&&f?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:f}):null]})}const Fm={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 Dm({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(ps())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(Fm[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 _m({workspace:s,own:n=!1,onClose:a}){const{state:i}=$(),c=n||Pa(i.config)?window.ogb?.computerSharing:void 0,[o,d]=l.useState(null),[u,m]=l.useState([]),[p,x]=l.useState(!1),[g,h]=l.useState(!1),[b,y]=l.useState(!1),[f,k]=l.useState(""),[C,N]=l.useState(null),w=l.useRef(!1),R=l.useRef(!1),j=l.useRef(null),B=E=>{d(E),m(E.folders),x(E.terminal),h(E.computer)};l.useEffect(()=>{w.current=!0,j.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(_=>{w.current&&B(_)}).catch(()=>{w.current&&k(t("computerSharing.loadFailed"))});const E=()=>{c?.state(s.id).then(_=>{w.current&&d(_)}).catch(()=>{}),c?.activity?.(s.id).then(_=>{w.current&&N(_)}).catch(()=>{})};E();const A=setInterval(E,3e3);return()=>{w.current=!1,clearInterval(A)}},[c,s.id]);const v=async E=>{if(!R.current){R.current=!0,y(!0),k("");try{await E()}catch(A){w.current&&k(String(A?.message??A).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{R.current=!1,w.current&&y(!1)}}};return c?e.jsx("div",{ref:j,children:e.jsx(J,{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(Be,{size:16})})]}),e.jsx("p",{className:"text-ink-secondary",children:n?t("computerSharing.ownIntro",{name:s.name}):"Choose what this workspace’s bots can use. Shared files and screen content may be sent to its AI provider. Access stays on when you switch workspaces, until you stop sharing or close the desktop app."}),n&&o?.enabled&&e.jsxs("div",{"data-sharing-pause":!0,className:"flex items-center gap-3 rounded-lg bg-inset px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] text-ink-secondary",children:t(o.paused?"computerSharing.paused":"computerSharing.pauseHint")}),e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{await(o.paused?c.resume?.():c.pause?.());const E=await c.state(s.id);w.current&&d(E)})},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(E=>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:E.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:E.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:E.write,onChange:A=>m(_=>_.map(Z=>Z.id===E.id?{...Z,write:A.target.checked}:Z))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:E.name}),onClick:()=>m(A=>A.filter(_=>_.id!==E.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Be,{size:14})})]},E.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{v(async()=>{const E=await c.chooseFolder();w.current&&E&&m(A=>A.some(_=>_.path===E.path)?A:[...A,E])})},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(Gl,{size:14}),t("computerSharing.chooseFolder")]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.smallFiles")})]}),e.jsxs("fieldset",{disabled:b||!o,className:"flex flex-col gap-3 border-t border-hairline/40 pt-3 disabled:opacity-50",children:[e.jsx("legend",{className:"font-medium text-ink",children:t("computerSharing.broader")}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:p,onChange:E=>x(E.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.terminal"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.terminalHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:g,onChange:E=>h(E.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.control"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.controlHint")})]})]})]}),(f||o?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:f||o?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:b||!o||!u.length&&!p&&!g,onClick:()=>{v(async()=>{const E=await c.save(s.id,{folders:u,terminal:p,computer:g});w.current&&E&&B(E)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:t(o?.enabled?"computerSharing.save":"computerSharing.share")}),o?.enabled&&e.jsx("button",{type:"button",disabled:b,onClick:()=>{v(async()=>{const E=await c.revoke(s.id);w.current&&B(E)})},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(Dm,{entries:C})})]})})}):null}const Km={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},ut=s=>s.kind!=="local"&&!!s.origin&&!s.home&&!s.cloud&&!("team"in s&&s.team),Hm=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function $m(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 Wm({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=vs($m(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(Be,{size:13})})]})}function Gm({origin:s,name:n}){const{state:a,copy:i}=vs(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(fe,{size:14}):e.jsx(Fa,{size:14})})}function Vm({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:Hm(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 qm({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(xe,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function Jm({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:o,onComputerAccess:d,onShare:u=()=>{}}){const m=window.ogb?.environments,[p,x]=l.useState([]),[g,h]=l.useState([]),[b,y]=l.useState(null);l.useEffect(()=>{if(!m?.status)return;let w=!0;const R=()=>{m.status().then(B=>{w&&x(B)}).catch(()=>{})};R();const j=m.onStatus?.(R);return()=>{w=!1,j?.()}},[m,s]);const f=w=>p.find(R=>R.id===w),k=w=>y({address:w.origin,locked:!0,title:t("servers.pairAgainTitle",{name:w.name})}),C=w=>y({address:w.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),N=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(w=>w.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:N.map(w=>{const R=w.id===s.activeId,j=ut(w)?f(w.id):void 0,B=w.id==="local"?gt:ms,v=w.id==="local"?t("servers.localHint"):ut(w)?`${new URL(w.origin).host} · ${t(Km[yr(w.origin)])}`:w.home?t("servers.managed"):new URL(w.origin).host,E=i.find(_=>_.id===w.id),A=j?.behind===!0&&r!==null&&!g.includes(`${w.id}:${j.version}`);return e.jsxs("li",{"data-server-row":w.id,className:"py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[vr(w.color)?e.jsx(jr,{color:w.color,size:20}):e.jsx(B,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:w.name}),e.jsx("div",{"data-server-where":!0,className:"break-all text-[12px] text-ink-secondary",children:v}),e.jsx(Vm,{status:j,onTryNow:()=>{m?.retry?.(w.id)},onPairAgain:()=>k(w),onEdit:()=>C(w)})]}),R?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(fe,{size:13}),t("servers.current")]}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:w.name}),onClick:()=>c(w.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.switch")}),ut(w)&&j?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>k(w),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("servers.pairAgain")}),w.id!=="local"&&!w.home&&!w.cloud&&!E&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:w.name}),onClick:()=>d(w.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("servers.computerAccess")}),ut(w)&&e.jsx(Gm,{origin:w.origin,name:w.name}),w.id!=="local"&&!w.home&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.removeName",{name:w.name}),title:t("servers.removeName",{name:w.name}),onClick:()=>o(w.id),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]}),E&&e.jsx(qm,{name:w.name,share:E,busy:n,onShare:_=>u(w.id,_),onOpen:()=>d(w.id)}),A&&e.jsx(Wm,{name:w.name,status:j,appVersion:r,onHide:()=>h(_=>[..._,`${w.id}:${j.version}`])})]},w.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(Ne,{size:14}),t("connect.title")]}),b&&e.jsx(Nc,{focusKey:b.locked?"pair-again":"connect",onClose:()=>y(null),children:e.jsx(wc,{onBack:null,onConnected:()=>y(null),start:b})})]})}function On(){const s=window.ogb?.environments,{state:n}=$(),a=Pa(n.config)&&!!window.ogb?.computerSharing,i=window.ogb?.computerSharing,[r,c]=l.useState([]),[o,d]=l.useState(null),[u,m]=l.useState(!1),[p,x]=l.useState(""),[g,h]=l.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[b,y]=l.useState(""),[f,k]=l.useState(""),[C,N]=l.useState(null),[w,R]=l.useState(!1),[j,B]=l.useState(""),v=l.useRef(!1),E=l.useRef(0);l.useEffect(()=>{const P=++E.current;return s?.state().then(L=>{E.current===P&&d(L)}).catch(()=>{E.current===P&&x(t("servers.loadFailed"))}),()=>{E.current++}},[s]),l.useEffect(()=>{if(!i?.servers||!o)return;let P=!0;const L=()=>{i.servers().then(K=>{P&&c(K)}).catch(()=>{})};L();const I=setInterval(L,5e3);return()=>{P=!1,clearInterval(I)}},[i,o]);const A=(P,L)=>{_(async()=>{L?await i?.allow?.(P)&&h(P):await i?.revoke(P),i?.servers&&c(await i.servers())})};l.useEffect(()=>{const P=L=>{L&&h(L);const I=new URL(window.location.href);I.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${I.pathname}${I.search}${I.hash}`)};return P(),s?.onOpenSettings?.(P)},[s]);const _=async(P,L=x)=>{if(v.current||!s)return;v.current=!0,m(!0),x(""),B("");const I=E.current;try{if(await P()===!0)return;const K=await s.state();E.current===I&&d(K)}catch(K){E.current===I&&L(String(K?.message??K).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{v.current=!1,E.current===I&&m(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const Z=P=>window.ogb?.confirm?window.ogb.confirm(P):window.confirm(P),ee=o?.environments.find(P=>P.id===g),Y=ee?.origin&&!ee.home?{id:ee.id,name:ee.name,origin:ee.origin}:void 0,te=!!(Y&&r.some(P=>P.id===Y.id)),ne=o?.environments.filter(P=>P.kind==="local")??[],ie=ne.find(P=>P.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(J,{title:t("connectedWorkspaces.localTitle"),subtitle:t("connectedWorkspaces.localSubtitle"),children:[j&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:j}),ne.length>0&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:ne.map(P=>{const L=P.id===o.activeId;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(gt,{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:P.name}),e.jsxs("div",{className:"break-all text-[12px] text-ink-secondary",children:[P.dataDir,P.missing&&e.jsx("span",{className:"ml-2 rounded-md bg-inset px-1.5 py-0.5 text-[11px]",children:t("connectedWorkspaces.missing")})]})]}),L?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(fe,{size:13}),t("connectedWorkspaces.current")]}):e.jsx("button",{type:"button",disabled:u,"aria-label":t("connectedWorkspaces.switchTo",{name:P.name}),onClick:()=>{_(async()=>{if(!await Z(t("connectedWorkspaces.switchConfirm",{name:P.name})))return;const I=await s.switch(P.id);if(I&&I.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},B)},className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.switch")}),!L&&e.jsx("button",{type:"button",disabled:u,"aria-label":t("connectedWorkspaces.forgetName",{name:P.name}),title:t("connectedWorkspaces.forgetName",{name:P.name}),onClick:()=>{N(P.id),R(!1)},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:14})})]},P.id)})}),ie&&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:w,disabled:u,className:"mt-0.5",onChange:P=>R(P.target.checked)}),t("connectedWorkspaces.forgetPurge",{path:ie.dataDir??""})]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",disabled:u,onClick:()=>{_(async()=>{const P=w?await s.forget(ie.id,!0):await s.forget(ie.id);if(P&&P.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));N(null)},B)},className:"rounded-lg px-3 py-1.5 text-[12px] font-medium text-danger hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.forget")}),e.jsx("button",{type:"button",onClick:()=>N(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:P=>{P.preventDefault(),b.trim()&&_(async()=>{if(!(await s.create(b.trim(),f.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));y(""),k("")},B)},children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.name"),e.jsx("input",{required:!0,value:b,disabled:u,maxLength:60,onChange:P=>y(P.target.value),placeholder:t("connectedWorkspaces.environmentPlaceholder"),className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("connectedWorkspaces.dataFolder"),e.jsxs("span",{className:"flex gap-2",children:[e.jsx("input",{value:f,disabled:u,onChange:P=>k(P.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:()=>{_(async()=>{const P=await s.pickDir();P?.ok&&P.path&&k(P.path)},B)},className:"shrink-0 rounded-lg border border-hairline/40 px-3 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t("connectedWorkspaces.choose")})]})]}),e.jsxs("button",{type:"submit",disabled: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(V,{size:14,className:"animate-spin"}),t("connectedWorkspaces.create")]})]})]}),e.jsxs(J,{title:t("servers.yours.title"),subtitle:t("servers.yours.subtitle"),children:[o?e.jsx(Jm,{saved:o,busy:u,sharingOffered:a,ownServers:r,appVersion:window.ogb?.app?.version??null,onShare:A,onSwitch:P=>{_(async()=>(await s.switch(P),!0))},onForget:P=>{_(()=>s.forget(P))},onComputerAccess:h}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t(p?"servers.yours.loadFailed":"servers.yours.loading")}),o&&p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]}),(a||te)&&Y&&e.jsx(_m,{workspace:Y,own:te,onClose:()=>h(null)},Y.id)]})}const Ym={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function Xm({banner:s,canChange:n,subtitle:a}){const i=l.useRef(null),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=Vl(s),m=async g=>{c(!0),d(null);const h=await Promise.resolve().then(g).catch(()=>({ok:!1,problem:"failed"}));c(!1),h.ok||d(Ym[h.problem])},p=g=>{i.current&&(i.current.value=""),!(!g||!n)&&m(async()=>{const h=await Jl(g);return h.ok?Yl(h.blob):h})},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(de,{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:()=>{m(Xl)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:ql,hidden:!0,"data-place-picture-input":!0,onChange:g=>p(g.target.files?.[0])})]})})})}function Pi(){const s=Ql(),{state:n}=$(),a=vt()===!0,i=window.ogb?.app?.ownPage===!0,[r,c]=l.useState(null),[o,d]=l.useState(null),u=s?.change===null,m=x=>{!s||u||r||x===s.swatch||(c(x),d(null),Zl(x).then(g=>{c(null),d(g)}))},p=s?.reason==="member"||o==="refused"?t("placeLook.member"):s?.reason==="signed-out"?t("placeLook.signedOut"):o==="unsupported"?t("placeLook.unsupported"):null;return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{"data-place-look":s.change??"locked",children:e.jsx(de,{title:t("placeLook.sidebarColor"),subtitle:i?t("placeLook.sidebarColorSub"):t("placeLook.sub",{name:s.name}),message:o==="failed"?e.jsx("p",{role:"alert",className:"text-danger",children:t("placeLook.failed")}):p&&e.jsx("p",{className:"text-ink-secondary",children:p}),children:e.jsx(Sc,{value:r??s.swatch,onChange:m,label:i?t("placeLook.sidebarColor"):t("placeLook.aria",{name:s.name}),disabled:u,offset:"menu",none:!0})})}),e.jsx(Xm,{banner:n.config?.workspaceBanner??null,canChange:a,subtitle:t(i?"placeLook.sidebarPictureSub":"placeLook.sharedPictureSub")})]})}function Qm(){return e.jsx("div",{"data-sidebar-look":!0,"data-settings-look":"simple",className:Ra,children:e.jsx(ye,{children:e.jsx(Pi,{})})})}function Ri(){const{capabilities:s}=Da(),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(de,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(xe,{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:us()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}function Ti(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function Zm(s,n){return s.find(a=>Ti(a)&&a.instanceId.endsWith(`.${n}`))}function Ts(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function zn(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return Ts(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function ep(s,n){const a=n.filter(o=>Ti(o)&&Ts(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=eo(o);if(zn(o.modelSelection,n)||zn(d.modelSelection,n))continue;([o,d].some(m=>to(so(m),c(m.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(o)}return r}const tp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function sp({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=$(),[r,c]=l.useState(!1),[o,d]=l.useState(null),u=ep(n.bots,n.instances),m=u.target,p=g=>g.map(h=>h.name).join(", "),x=async()=>{if(!m||!u.bots.length||r)return;const g=u.bots,h={instanceId:m.instanceId,model:m.models.default};c(!0),d(null);for(const b of g)a({type:"setModel",botId:b.id,selection:h});try{const b=await Promise.all(g.map(f=>i(f.id).catch(()=>null))),y=g.filter((f,k)=>b[k]?.modelSelection.instanceId===h.instanceId);y.length&&d({name:m.displayName,bots:y.map(f=>f.name)})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(g=>e.jsxs("li",{className:"py-2 text-[13px]",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsx("span",{className:"text-ink",children:tp[g.id]??g.id}),e.jsx("span",{className:"text-ink-secondary",children:g.configured?t("organization.modelCount",{count:g.models.length}):t("organization.notConfigured")})]}),g.configured&&g.models.length>0&&e.jsx(np,{instance:Zm(n.instances,g.id),instances:n.instances})]},g.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(", ")})}),m&&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:p(u.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{x()},children:u.bots.length===1?t("organization.useCompanyOne",{name:m.displayName}):t("organization.useCompanyMany",{name:m.displayName,count:u.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),m&&u.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:p(u.needsAsk)})})]})}function np({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(Ts(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(fe,{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&&no(a)?e.jsx(jt,{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 ap={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},Mn="https://admin.limixbot.com",Un={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 ip(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(Un,a))?s.message:n.map(a=>t(Un[a])).join(" ")}function Bi(){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(""),[m,p]=l.useState(!1),x=l.useRef(!1),g=l.useRef(0),h=l.useRef(0),b=l.useRef(void 0),y=j=>{const B=b.current!==j.status;b.current=j.status,a(j),B&&u(""),j.status!=="connected"&&j.status!=="reauth-required"&&p(!1)};l.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const j=++g.current,B=h.current,v=A=>{g.current===j&&(h.current++,y(A))},E=s?.onState(v);return s?.state().then(A=>{h.current===B&&v(A)}).catch(()=>{g.current===j&&h.current===B&&u(t("organization.loadFailed"))}),()=>{g.current++,E?.()}},[s]);const f=async j=>{if(!s||x.current)return;x.current=!0,o(!0),u("");const B=g.current,v=h.current;try{const E=await j();g.current===B&&h.current===v&&y(E)}catch{g.current===B&&h.current===v&&u(t("organization.actionFailed"))}finally{x.current=!1,g.current===B&&o(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const k=n?.status==="connected"||n?.status==="reauth-required"||n?.status==="unavailable"||n?.status==="license-expired",C=n?.status==="license-expired"||n?.notice==="license-expired",N=n?.enrollment?.expiresAt??n?.expiresAt,w=typeof N=="number"&&Number.isFinite(N)?new Date(N):null,R=w&&Number.isFinite(w.getTime())?new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(w):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.additive")}),e.jsxs(J,{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:ip(n)}),C&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),n?.status==="signed-out"&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.signInHelp")}),e.jsx("button",{type:"button",disabled:c,onClick:()=>{f(()=>s.begin({portalOrigin:Mn}))},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()&&f(()=>s.begin({portalOrigin:i.trim()}))},children:[e.jsx("p",{children:t("organization.advancedHelp")}),e.jsxs("label",{className:"flex flex-col gap-1.5",children:[t("organization.address"),e.jsx("input",{type:"url",required:!0,value:i,disabled:c,onChange:j=>r(j.target.value),placeholder:Mn,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"ui-button w-fit",children:t("organization.customSignIn")})]})]})]}),n?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.browserConsent")}),n.enrollment&&e.jsxs("details",{className:"w-full text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.securityDetails")}),e.jsx("p",{className:"mt-2",children:t("organization.securityDetailsHelp")}),e.jsx("div",{className:"mt-3",children:t("organization.code")}),e.jsx("code",{dir:"ltr",className:"mt-1 block w-fit select-all rounded-lg bg-inset px-3 py-2 text-base tracking-widest text-ink",children:n.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.enrollment&&s.reopen&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),k&&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:ap[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(sp,{providers:n.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,m?e.jsxs("div",{role:"group","aria-label":t("organization.disconnectTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink",children:t("organization.disconnectWarning")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:c,className:"ui-button",onClick:()=>p(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button text-danger",onClick:()=>{f(()=>s.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:c,className:"ui-button",onClick:()=>p(!0),children:t("organization.disconnect")})]})]}),n?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),R&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:R})}),d&&n&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:d}),!n&&e.jsx("button",{type:"button",disabled:c,className:"ui-button mt-3",onClick:()=>{f(()=>s.refresh())},children:t("organization.refresh")})]})]})}const rp="https://cal.com/milind-soni-002qed/30min",lp=["feature","price","setup","broken","later","other"],op={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},Fn=2e3,ls=s=>new Intl.DateTimeFormat(Te(),{dateStyle:"medium"}).format(new Date(s)),cp=s=>s.endsAt??s.renewsAt;function Li(s){const n=cp(s);return s.trial?n?t("cloudCancel.endedTrial",{date:ls(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:ls(n)}):t("cloudCancel.endedPlanNoDate")}function dp(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 up(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:ls(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function Oi({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 m=()=>{o(!0),u(null),n.keep().then(p=>{p.outcome==="kept"?a?.():u(p.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:Li(s)}),e.jsx("button",{type:"button",className:"ui-button",disabled:c,onClick:m,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(mp,{renewal:i,actions:n,onClose:p=>{r(null),p&&a?.()}})]})}function mp({renewal:s,actions:n,onClose:a}){const[i,r]=l.useState(null),[c,o]=l.useState(""),[d,u]=l.useState(""),[m,p]=l.useState({step:"ask"}),[x,g]=l.useState(!1),[h,b]=l.useState(!1),y=l.useRef(!1),f=l.useRef(null),k=()=>{x||a(y.current)};l.useEffect(()=>{const v=document.activeElement instanceof HTMLElement?document.activeElement:null;return f.current?.querySelector("button[aria-pressed]")?.focus(),()=>{v?.isConnected&&v.focus()}},[]);const C=v=>{g(!0),b(!1),v().catch(()=>b(!0)).finally(()=>g(!1))},N=()=>C(async()=>{const v=i!==null||c.trim()!==""||d.trim()!=="",E=await n.cancel(v?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);E.outcome==="cancelled"?(y.current=!0,p({step:"done",renewal:E.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:E.surveyed})):E.outcome==="browser"?p({step:"browser"}):b(!0)}),w=()=>C(async()=>{const v=await n.keep();v.outcome==="kept"?(y.current=!0,a(!0)):v.outcome==="browser"?p({step:"browser"}):b(!0)}),R=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",B=h&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return Cc.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:v=>{v.target===v.currentTarget&&k()},children:e.jsxs("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":x,tabIndex:-1,"data-cloud-cancel-sheet":m.step,className:"flex max-h-[90vh] w-full max-w-[480px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel text-ink shadow-2xl outline-none",onKeyDown:v=>{if(v.key==="Escape"&&(v.stopPropagation(),k()),v.key==="Tab"){const E=f.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!E?.length)return;const A=E[0],_=E[E.length-1];v.shiftKey&&document.activeElement===A?(v.preventDefault(),_.focus()):!v.shiftKey&&document.activeElement===_&&(v.preventDefault(),A.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:R}),e.jsx("button",{type:"button","aria-label":t("cloudCancel.close"),disabled:x,onClick:k,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(Be,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[m.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:up(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:lp.map(v=>e.jsx("button",{type:"button","aria-pressed":i===v,onClick:()=>r(E=>E===v?null:v),className:O("ui-button ui-button-pill",i===v&&"border-accent bg-accent/10 font-medium"),children:t(op[v])},v))})]}),e.jsxs("label",{className:"mt-4 block text-[13px] text-ink",children:[t("cloudCancel.expected")," ",e.jsx("span",{className:"text-ink-secondary",children:t("cloudCancel.optional")}),e.jsx("textarea",{rows:2,maxLength:Fn,value:c,disabled:x,onChange:v=>o(v.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:Fn,value:d,disabled:x,onChange:v=>u(v.target.value),className:j})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:rp,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),B,e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:x,onClick:k,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:N,children:t(x?"cloudCancel.cancelling":s.trial?"cloudCancel.confirmTrial":"cloudCancel.confirmPlan")})]})]}),m.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:Li(m.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:dp(m.renewal)}),m.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),B,e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t("cloudCancel.changedMind")}),e.jsx("button",{type:"button",className:"ui-button",disabled:x,onClick:w,children:t(x?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:x,onClick:k,children:t("cloudCancel.done")})]})]}),m.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:k,children:t("cloudCancel.done")})})]})]})]})}),document.body)}function Dn({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(pp,{bridge:s,read:n,write:a}):null}function pp({bridge:s,read:n,write:a}){const[i,r]=l.useState(null),[c,o]=l.useState(!1),[d,u]=l.useState(!1),[m,p]=l.useState(null);if(l.useEffect(()=>{let h=!0;const b=()=>{n().then(f=>{h&&r(f)}).catch(()=>{})};b();const y=s.onNotice(b);return()=>{h=!1,y()}},[s,n]),!i?.shown)return null;const x=h=>{o(!1),u(!0),p(null),a(h).then(b=>r(b),b=>p(kr(b)??t("cloudAccount.keepHere.failed"))).finally(()=>u(!1))},g=()=>{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(xe,{checked:i.on||i.coming,disabled:d||i.coming,"aria-label":t("cloudAccount.keepHere.title"),onClick:g})]}),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")})]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:m})]})}function xp({label:s,suggest:n,className:a="ui-button"}){const{dispatch:i}=$();return e.jsx("button",{type:"button",className:a,onClick:()=>i({type:"showFiles",...n?{suggest:n}:{}}),children:s})}const gp={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},zi=s=>new Intl.DateTimeFormat(Te(),{timeStyle:"short"}).format(new Date(s)),hp=s=>new Intl.DateTimeFormat(Te(),{dateStyle:"medium"}).format(new Date(s));function Mi(s,n){if(!s&&!n)return null;const a=s?xs(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:Rr(n)})]})}function _n({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,m=s.status==="ready"&&!u,p=u?t(u.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):o??(c&&m?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:zi(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(gp[s.status]));return e.jsx(J,{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&&m?!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:m?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:p}),s.status==="provisioning"&&s.setup&&e.jsx(Hc,{step:s.setup.step}),m&&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&&ro()&&e.jsx(xp,{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 fp({ready:s,busy:n,failed:a,onUse:i}){return e.jsx(J,{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 bp(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 yp={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function vp(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(yp[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:hp(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 jp(s,n){const a=s.trial&&!s.renewal?.cancelled?xs(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 kp({bridge:s,onConnectPhone:n}){const[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[u,m]=l.useState(0);l.useEffect(()=>{let y=!0;return s.state().then(f=>{y&&i(f)}).catch(()=>{y&&d(!0)}),()=>{y=!1}},[s,u]);const p=s.cancel&&s.keep?{cancel:y=>s.cancel(y),keep:()=>s.keep()}:null;if(o)return e.jsx(J,{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=Ir(a?.tier),g=a?.home===!0,h=a?.status==="paid"?t(Pr(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(g?"cloudAccount.onCloudNoneHome":"cloudAccount.onCloudNone"):null,b=y=>{c(!1),y().catch(()=>c(!0))};return e.jsx(J,{title:t("settings.section.cloudAccount"),subtitle:t(g?"cloudAccount.onCloudHome":"cloudAccount.onCloud"),children:e.jsxs("div",{"data-cloud-plan":a?.status??"loading",className:"flex flex-col items-start gap-3",children:[h?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:h}):!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")}),Mi(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&&xs(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(io,{})]}),a?.renewal&&e.jsx(Oi,{renewal:a.renewal,actions:p,onChanged:()=>m(y=>y+1)}),r&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function Np({team:s}){return e.jsx(J,{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 wp({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}=Da().capabilities.host,[u,m]=l.useState(null),[p,x]=l.useState(!1),[g,h]=l.useState(!1),[b,y]=l.useState(!1),[f,k]=l.useState(!1),[C,N]=l.useState(!1),[w,R]=l.useState(!1),j=l.useRef(0),B=l.useRef(0),v=l.useRef(!1),E=l.useRef({request:0,arrived:!1,connected:!1});l.useEffect(()=>{const ce=++j.current,se=B.current,he=re=>{j.current===ce&&(B.current++,m(re),h(!1),re.status==="signed-out"&&y(!1))},F=o?.onState(he);return o?.state().then(re=>{B.current===se&&he(re)}).catch(()=>{j.current===ce&&B.current===se&&h(!0)}),()=>{j.current++,F?.()}},[o]);const A=async ce=>{if(!o||v.current)return;v.current=!0,x(!0),h(!1);const se=j.current,he=B.current;try{const F=await ce();j.current===se&&B.current===he&&m(F)}catch{j.current===se&&B.current===he&&h(!0)}finally{v.current=!1,j.current===se&&x(!1)}},_=()=>{o&&(N(!1),A(async()=>{try{return await o.connectHome()}catch{return N(!0),o.state()}}))},Z=ce=>{o?.openTeam&&(N(!1),A(async()=>{try{await o.openTeam(ce)}catch{N(!0)}return o.state()}))},ee=()=>{o&&(R(!1),A(async()=>{try{return await o.connectHomeForPhone()}catch{return R(!0),o.state()}}))};l.useEffect(()=>{if(s||(E.current.request=0),!o||!s||!u||v.current||(E.current.request!==s&&(E.current={request:s,arrived:!0,connected:!1}),u.status==="signed-out"&&u.message==="restoring"))return;const ce=bp(u,E.current);E.current.arrived=!1,ce==="sign-in"&&A(()=>o.begin()),ce==="connect"&&(E.current.connected=!0,_())},[o,s,u,p]);const[Y]=ao(o?window.ogb?.cloudSendPage:void 0),te=Y?.move?Nr(Y.move,"local"):null,ne=te&&te.kind!=="done"?te.text:null,ie=sd(!!u&&Ks(Hs(u)),u?.offer),P=o?.cancelPlan&&o.keepPlan?{cancel:ce=>o.cancelPlan(ce),keep:()=>o.keepPlan()}:null;if(!o){const ce=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return e.jsxs(e.Fragment,{children:[n&&a?e.jsx(Np,{team:a}):ce?e.jsx(kp,{bridge:ce,onConnectPhone:i}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")}),ce&&!a&&e.jsx(Dn,{bridge:window.ogb?.cloudSendPage})]})}const L=Hs(u),I=u&&["connected","unavailable","reauth-required"].includes(u.status),K=vp(u,L,d),Q=wr(L),le=Sr(u),ae=Cr(u),U=L.kind==="paid"?{status:"provisioning"}:void 0,X=le?ae?.machine??U:u?.status==="connected"?u.machine??U:void 0,oe=u?.status==="connecting"?u.enrollment:void 0;Er(ie);const pe=r&&Ks();return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.optional")}),e.jsxs(J,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.separate"),children:[u?.staging&&e.jsx(Ar,{className:"mb-3"}),(!u||L.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),K&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:K}),(L.kind==="signed-out"||L.kind==="removed")&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[pe,e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>c?c():void A(()=>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")}),oe&&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:oe.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:zi(oe.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{A(()=>o.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{A(()=>o.cancel())},children:t("organization.cancel")})]})]}),I&&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":L.kind,className:"text-[15px] font-medium text-ink",children:[Q,L.kind==="paid"&&L.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),u.status==="connected"&&Mi(u.trial,u.credit),L.kind==="free"&&pe,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[L.kind==="reauth"?e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{A(()=>o.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[!(L.kind==="free"&&pe)&&e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{A(()=>o.openDashboard())},children:L.kind==="free"?t("cloudAccount.dashboard"):jp(u,L)}),e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>{A(()=>o.refresh())},children:t("organization.refresh")})]}),!b&&e.jsx("button",{type:"button",disabled:p,className:"ui-button",onClick:()=>y(!0),children:t("cloudAccount.signOut")})]}),u.status==="connected"&&u.renewal&&e.jsx(Oi,{renewal:u.renewal,actions:P}),L.kind==="free"&&!b&&e.jsxs("p",{className:"text-[12px] text-ink-secondary",children:[t(window.ogb?.accounts?"cloudAccount.otherEmailOrTeam":"cloudAccount.otherEmail")," ",e.jsx("button",{type:"button","data-cloud-other-email":!0,disabled:p,className:"underline hover:text-ink",onClick:()=>window.ogb?.accounts?k(!0):y(!0),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),f&&e.jsx(Ec,{adding:"",onClose:()=>k(!1)}),b&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.signoutTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.signoutHelp")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:p,className:"ui-button",onClick:()=>y(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:p,className:"ui-button text-danger",onClick:()=>{A(()=>o.signOut())},children:t("cloudAccount.signOut")})]})]})]}),g&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!u&&e.jsx("button",{type:"button",disabled:p,className:"ui-button mt-3",onClick:()=>{A(()=>o.state())},children:t("organization.refresh")})]}),X&&_n(le?{machine:X,busy:p,failed:C,onConnect:()=>{ae&&Z(ae.id)},team:{name:ae?.name??null}}:{machine:X,busy:p,failed:C,onConnect:_,trial:!!u?.trial,waking:u?.waking===!0,moving:ne}),I&&L.kind==="paid"&&!le&&fp({ready:X?.status==="ready",busy:p,failed:w,onUse:ee}),e.jsx(Dn,{bridge:window.ogb?.cloudSendPage})]})}function Kn(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Te(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function Ui(s){return t("planUsage.spendAmounts",{used:Kn(s.usedMinor,s.currency,s.exponent),limit:Kn(s.limitMinor,s.currency,s.exponent)})}function Fi(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 Sp(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 Cp(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function Hn(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function bt(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 Ep(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:bt({name:a[1]})}):n}function mt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?Fi(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",Cp(o)),style:{width:`${Math.min(100,Math.max(0,o))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function Di(){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),m=l.useCallback(async(p=!1)=>{i(!0),c("");try{const x=await M(p?"/api/plan-usage?refresh=1":"/api/plan-usage");n(x),d(Date.now())}catch(x){c(x instanceof Error&&x.message?x.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return l.useEffect(()=>{m(!1)},[m]),l.useEffect(()=>{const p=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(p)},[]),l.useEffect(()=>{if(!s)return;const p=Sp(s,o,u.current);if(p.length!==0){for(const x of p)u.current.add(x);m(!0)}},[s,o,m]),{report:s,loading:a,error:r,now:o,load:m}}function Ap(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 Ip(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 Pp(){const{report:s,now:n}=Di();if(!s)return null;const a=Ip(s),i=a?null:Ap(s);if(i){const d=bt(i.provider),u=Math.round(Math.min(100,Math.max(0,i.budget.usedPercent)));return e.jsx(tn,{kind:"plan",title:t("settings.simple.billing.monthlySpend",{provider:d}),percent:u,label:`${d}: ${t("planUsage.used",{used:u})}`,note:i.budget.spend?Ui(i.budget.spend):null})}if(!a)return e.jsx("section",{"data-usage-summary":"own-ai",className:O(Sa,"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=Fi(a.provider.weekly.resetsAt,n),o=bt(a.provider);return e.jsx(tn,{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 Rp(){const{report:s,loading:n,error:a,now:i,load:r}=Di();return e.jsxs(J,{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(V,{size:14,className:"animate-spin"}):e.jsx(Ce,{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:bt(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(mt,{label:t("planUsage.fiveHour"),window:c.fiveHour,now:i}),e.jsx(mt,{label:t("planUsage.weekly"),window:c.weekly,now:i}),c.extra.map((o,d)=>e.jsx(mt,{label:Hn(o.label),now:i,usedHeadline:!!o.spend,detail:o.spend?Ui(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(mt,{label:Hn(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:Ep(c)})]},c.id))})]})}function $n(s,n){return s?.edition?.features?.includes(n)===!0}function Tp(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function Bp({budget:s}){const{state:n,dispatch:a}=$(),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,m]=l.useState(!1),[p,x]=l.useState(null);l.useEffect(()=>{c(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),d(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const g=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}m(!0),x(null);try{const f=await M("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:b,warnAtPercent:y}})});a({type:"configStatus",config:f})}catch(f){x(f instanceof Error?f.message:String(f))}finally{m(!1)}},h=Tp(s);return e.jsxs(J,{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(h==="danger"?"text-danger":h==="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:tt(s.spentUsd),cap:tt(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",h==="danger"?"bg-danger":h==="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(),g()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.monthly"),e.jsx("input",{value:r,onChange: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(V,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.budget.hint")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}function Wn(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 Lp(){const{state:s,dispatch:n}=$(),a=s.config?.billing,[i,r]=l.useState(a?.currency??"USD"),[c,o]=l.useState(Wn(a?.prices)),[d,u]=l.useState(!1),[m,p]=l.useState(null);l.useEffect(()=>{r(a?.currency??"USD"),o(Wn(a?.prices))},[a]);const x=(b,y)=>o(f=>f.map((k,C)=>C===b?{...k,...y}:k)),g=async()=>{if(d)return;const b={};for(const y of c){const f=y.key.trim();if(!f)continue;const k=Number(y.input),C=Number(y.output),N=y.cached.trim()===""?void 0:Number(y.cached);if(!Number.isFinite(k)||!Number.isFinite(C)||k<0||C<0||N!==void 0&&(!Number.isFinite(N)||N<0)){p(t("usage.prices.invalid",{model:f}));return}b[f]={inputPerMillion:k,outputPerMillion:C,...N===void 0?{}:{cachedInputPerMillion:N}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){p(t("usage.prices.currencyInvalid"));return}u(!0),p(null);try{const y=await M("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:b}})});n({type:"configStatus",config:y})}catch(y){p(y instanceof Error?y.message:String(y))}finally{u(!1)}},h="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(J,{title:t("usage.prices.title"),subtitle:t("usage.prices.subtitle"),children:[e.jsx("div",{className:"mb-3 flex items-center gap-2 text-[12px] text-ink-secondary",children:e.jsxs("label",{className:"flex items-center gap-2",children:[t("usage.prices.currency"),e.jsx("input",{value:i,onChange:b=>r(b.target.value),maxLength:3,"aria-label":t("usage.prices.currency"),disabled:d,className:"w-16 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] uppercase text-ink focus:outline-none disabled:opacity-50"})]})}),e.jsxs("div",{className:"grid grid-cols-[1fr_5rem_5rem_5rem_auto] items-center gap-x-2 gap-y-1.5 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("usage.prices.colModel")}),e.jsx("span",{children:t("usage.prices.colInput")}),e.jsx("span",{children:t("usage.prices.colOutput")}),e.jsx("span",{children:t("usage.prices.colCached")}),e.jsx("span",{}),c.map((b,y)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:b.key,onChange:f=>x(y,{key:f.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:O(h,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:b.input,onChange:f=>x(y,{input:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:h}),e.jsx("input",{value:b.output,onChange:f=>x(y,{output:f.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:h}),e.jsx("input",{value:b.cached,onChange:f=>x(y,{cached:f.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:h}),e.jsx("button",{type:"button",onClick:()=>o(f=>f.filter((k,C)=>C!==y)),"aria-label":t("usage.prices.remove"),disabled:d,className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Se,{size:13})})]},y))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>o(b=>[...b,{key:"",input:"",output:"",cached:""}]),disabled:d,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx(Ne,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{g()},disabled:d,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[d&&e.jsx(V,{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")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Op({budget:s}){const{state:n}=$(),a=$n(n.config,"budgets"),i=$n(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(Bp,{budget:s}),i&&e.jsx(Lp,{})]})}const zp=["model","user","department","day","engine","routine"],Gn={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"},Mp={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},Up=2e3;function Fp(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 Vn(s,n,a){const[i,r]=l.useState(null);return l.useEffect(()=>{let c=!0;return M(`/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 qn({groupBy:s,groups:n}){const{state:a}=$(),i=[...n].sort((c,o)=>Je(o)-Je(c)).slice(0,6),r=Math.max(...i.map(Je),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(Ct,{bot:o,state:"idle",size:18,animated:!1}),e.jsx("span",{className:"truncate",children:s==="model"?bo(c.label,a.instances):Fp(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,Je(c)/r*100)}%`}})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[yo(Je(c)),et(c.costUsd)&&c.costUsd>0&&` · ${Ta(c.costUsd)}`]})]},c.key)})})}function Dp({range:s,version:n,onBudget:a}){const[i,r]=l.useState("model"),c=Vn(s,"bot",n),o=Vn(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(Gn.bot)}),c?e.jsx(qn,{groupBy:"bot",groups:c.groups}):e.jsx(V,{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:zp.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(Gn[d])},d))}),o?.groupBy===i?e.jsx(qn,{groupBy:i,groups:o.groups}):e.jsx(V,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}function _p(s){return new Date(s).toLocaleString(Tr(Te()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Kp({root:s,onOpen:n}){const{state:a}=$(),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(Ct,{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:[_p(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(ho,{}),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:fo(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:Ta(s.costUsd)}),e.jsx(js,{size:14,className:"text-ink-tertiary"})]})]})})}function _i(){const[s,n]=l.useState("month"),a=l.useMemo(()=>lo(s),[s]),[i,r]=l.useState(null),[c,o]=l.useState(null),[d,u]=l.useState(0),[m,p]=l.useState(null),[x,g]=l.useState(null),h=l.useRef(null);l.useEffect(()=>{let f=!0;return sn(a).then(k=>{f&&(r(k),o(null))}).catch(k=>{f&&o(k instanceof Error?k.message:String(k))}),()=>{f=!1}},[a,d]),l.useEffect(()=>oo({onFrame:f=>{if(f.kind!=="runtime"||h.current)return;const k=f.event?.type;k!=="turn.started"&&k!=="turn.completed"||(h.current=setTimeout(()=>{h.current=null,u(C=>C+1)},Up))},onMissedFrames:()=>u(f=>f+1)}),[]),l.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const b=()=>{i?.next&&sn(a,i.next).then(f=>r(k=>k?{...f,roots:[...k.roots,...f.roots]}:f))},y=i?.roots.some(f=>!f.timed);return e.jsxs("div",{className:"flex flex-col gap-4","data-testid":"usage-page",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink-secondary",children:t("usage.page.subtitle")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{size:"sm",value:s,onChange:f=>{n(f.target.value),g(null)},"aria-label":t("usage.history.period"),children:co.map(f=>e.jsx("option",{value:f,children:t(Mp[f])},f))}),e.jsxs("a",{href:uo(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(bs,{size:13}),t("usage.history.export")]})]})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:c}),x?e.jsx(mo,{id:x.id,at:x.at,actions:e.jsxs("button",{type:"button",onClick:()=>g(null),className:"flex shrink-0 items-center gap-1 rounded-lg px-2 py-1 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(po,{size:13}),t("trace.back")]})}):e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"overflow-hidden rounded-2xl border border-hairline/50 bg-card","data-testid":"usage-totals",children:i?e.jsx(xo,{items:go(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(V,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(Dp,{range:a,version:d,onBudget:p}),e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-2","aria-label":t("usage.page.runs"),children:[e.jsxs("div",{className:"px-3 pb-1 pt-3",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.runs")}),e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t("usage.page.runsHint")})]}),i&&!i.roots.length&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:t("usage.page.runsEmpty")}),e.jsx("ul",{className:"mt-1 flex flex-col",children:i?.roots.map(f=>e.jsx(Kp,{root:f,onOpen:()=>g({id:f.id,at:f.startedAt})},f.id))}),i?.next!==void 0&&e.jsx("button",{type:"button",onClick:b,className:"m-2 rounded-lg px-3 py-1.5 text-[13px] text-accent hover:bg-raised/50",children:t("usage.page.more")}),y&&e.jsx("p",{className:"px-3 pb-3 pt-1 text-[12px] text-ink-tertiary",children:t("usage.page.untimedNote")})]})]}),e.jsx(Rp,{}),e.jsx(Op,{budget:m})]})}function Hp(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 Ki({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(ps())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function $p(){const{state:s}=$(),[n,a]=l.useState([]),[i,r]=l.useState(!0),[c,o]=l.useState(""),[d,u]=l.useState(""),[m,p]=l.useState(null),[x,g]=l.useState(null),[h,b]=l.useState(""),[y,f]=l.useState(""),[k,C]=l.useState(!1),[N,w]=l.useState(""),[R,j]=l.useState(""),B=l.useRef(!1),v=s.bots.filter(I=>!I.hidden),E=l.useMemo(()=>[...new Set(n.flatMap(I=>I.tags))].sort((I,K)=>I.localeCompare(K)),[n]),A=Hp(n,d,m),_=async I=>{try{const K=await fetch("/api/skills-library"),Q=await K.json();if(!K.ok)throw new Error(Q.error??t("skills.library.loadError"));if(I?.())return;a(Q.skills??[]),o("")}catch(K){I?.()||o(K instanceof Error?K.message:t("skills.library.loadError"))}finally{I?.()||r(!1)}};l.useEffect(()=>{let I=!1;return r(!0),_(()=>I),()=>{I=!0}},[]);const Z=async(I,K,Q)=>{if(B.current)return;B.current=!0;const le=`${K}:${I}`;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 X=(U.skills??[]).filter(se=>se.assignedBots.some(he=>he.id===I)).map(se=>se.name),oe=Q?X.filter(se=>se!==K):[...new Set([...X,K])],pe=await fetch(`/api/bots/${encodeURIComponent(I)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:oe})}),ce=await pe.json();if(!pe.ok)throw new Error(ce.error??t("skills.error.assignments"));await _()}catch(ae){o(ae instanceof Error?ae.message:t("skills.error.assignments"))}finally{B.current=!1,b("")}},ee=async I=>{R&&await Z(R,I.name,!1)},Y=async(I,K)=>{await Z(K,I.name,!0)},te=async(I,K=!1)=>{if(!B.current){if(!I.enabled&&!K)return ie(I,!0);B.current=!0,b(I.name),o("");try{const Q=await fetch(`/api/skills-library/${encodeURIComponent(I.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!I.enabled})}),le=await Q.json();if(!Q.ok)throw new Error(le.error??t("skills.error.update"));K&&g(null),await _()}catch(Q){o(Q instanceof Error?Q.message:t("skills.error.update"))}finally{B.current=!1,b("")}}},ne=async I=>{if(!B.current){B.current=!0,b(I.name),o("");try{const K=await fetch(`/api/skills-library/${encodeURIComponent(I.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({everyBot:!I.everyBot})}),Q=await K.json();if(!K.ok)throw new Error(Q.error??"Could not update this skill.");await _()}catch(K){o(K instanceof Error?K.message:"Could not update this skill.")}finally{B.current=!1,b("")}}},ie=async(I,K=!1)=>{o("");try{const Q=await fetch(`/api/skills-library/${encodeURIComponent(I.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"));g({skill:I,text:le.text,review:K})}catch(Q){o(Q instanceof Error?Q.message:t("skills.error.load"))}},P=async()=>{const I=y.trim();if(I){C(!0),o(""),w("");try{const K=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:I})}),Q=await K.json();if(!K.ok)throw new Error(Q.error??t("skills.error.import"));w(t("skills.library.imported",{name:Q.skill?.name??""})),f(""),await _()}catch(K){o(K instanceof Error?K.message:t("skills.error.import"))}finally{C(!1)}}},L="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(J,{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(at,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:L,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:d,onChange:I=>u(I.target.value)})]}),E.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>p(null),className:m===null?"rounded-full bg-control px-2.5 py-1 text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),E.map(I=>e.jsx("button",{type:"button",onClick:()=>p(m===I?null:I),className:m===I?"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:I},I))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):A.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:A.map(I=>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:()=>{ie(I)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:I.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:I.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:I.description})]}),e.jsx(xe,{checked:I.enabled,"aria-label":I.enabled?t("skills.library.disable",{skill:I.name}):t("skills.library.enable",{skill:I.name}),disabled:!!(h||k),onClick:()=>{te(I)}})]}),e.jsx(Ki,{skill:I}),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(xe,{checked:I.everyBot,"aria-label":t("skills.library.everyBot"),disabled:!!(h||k),onClick:()=>{ne(I)}})]}),I.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:I.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:I.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):I.assignedBots.map(K=>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:K.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:K.name}),title:t("skills.library.removeAssignment",{bot:K.name}),disabled:!!(h||k),onClick:()=>{Y(I,K.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(Be,{size:11})})]},K.id))}),v.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs(me,{size:"sm","aria-label":t("skills.library.assignLabel"),value:R,disabled:!!(h||k),onChange:K=>j(K.target.value),className:"max-w-45",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),v.map(K=>e.jsx("option",{value:K.id,children:K.name},K.id))]}),e.jsx("button",{type:"button",disabled:!R||!!(h||k),onClick:()=>{ee(I)},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")})]})]},I.name))}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}),e.jsx(J,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:I=>{I.preventDefault(),P()},children:[e.jsx("textarea",{className:`${L} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:y,onChange:I=>f(I.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:N}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:k||!!h||!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:k?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),x&&e.jsx(_a,{modal:!0,children:e.jsx(Wp,{viewing:x,error:c,working:!!h,onClose:()=>{h||g(null)},onEnable:()=>{te(x.skill,!0)}})})]})}function Wp({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=l.useRef(null);return Ac(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(Ki,{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 Gp(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 Jn({config:s}){const n=Gp(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(Re,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function Hi(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Vp=()=>M("/api/fleet");function qp({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:[et(i.usage.costUsd)?tt(i.usage.costUsd):"—",et(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",tt(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 Jp({domain:s,onCreated:n,disabled:a}){const[i,r]=l.useState(""),[c,o]=l.useState(""),[d,u]=l.useState(""),[m,p]=l.useState(""),[x,g]=l.useState(""),[h,b]=l.useState(!1),[y,f]=l.useState(null),k=async()=>{if(!h){b(!0),f(null);try{const N={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(R=>R.trim()).filter(Boolean),...m.trim()?{cap:Number(m)}:{},...x.trim()?{anthropicKey:x.trim()}:{}},w=await M("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(N)});r(""),o(""),u(""),p(""),g(""),n(w.log??[],{slug:N.slug,admin:N.admins[0]})}catch(N){f(N instanceof Error?N.message:String(N))}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:N=>{N.preventDefault(),k()},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:N=>r(N.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||h,"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:N=>o(N.target.value),type:"email",required:!0,disabled:a||h,"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:N=>u(N.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||h,"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:m,onChange:N=>p(N.target.value),inputMode:"decimal",placeholder:"50",disabled:a||h,"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:N=>g(N.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||h,"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||h,className:"ui-button ui-button-primary",children:[h?e.jsx(V,{size:13,className:"animate-spin"}):e.jsx(Ne,{size:13}),h?t("workspaces.creating"):t("workspaces.create")]})})]})}function Yp({slug:s,onDone:n}){const[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),[u,m]=l.useState(null),p=async x=>{if(!o){d(x),m(null);try{const g=await M(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:x,email:a.trim(),chatOnly:r})});i(""),n(g.log??[])}catch(g){m(g instanceof Error?g.message:String(g))}finally{d(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:t("workspaces.usersTitle",{slug:s})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:a,onChange:x=>i(x.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:o!==null,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:x=>c(x.target.checked),disabled:o!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{p("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:o==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{p("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:o==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function Xp({load:s=Vp}){const{state:n}=$(),[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[u,m]=l.useState(null),[p,x]=l.useState([]),[g,h]=l.useState(null),[b,y]=l.useState(null),[f,k]=l.useState(!1),[C,N]=l.useState(null),w=l.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(v){c(v instanceof Error?v.message:String(v))}finally{d(!1)}},[s]);l.useEffect(()=>{w()},[w]);const R=async(v,E)=>{if(E==="users"){h(A=>A===v?null:v);return}if(E==="delete"){y({slug:v,keepData:!1});return}m(v),c(null);try{const A=await M(`/api/fleet/workspaces/${encodeURIComponent(v)}/${E}`,{method:"POST"});x(A.log??[]),await w()}catch(A){c(A instanceof Error?A.message:String(A))}finally{m(null)}},j=async()=>{if(!b)return;const{slug:v,keepData:E}=b;y(null),m(v),c(null);try{const A=await M(`/api/fleet/workspaces/${encodeURIComponent(v)}`,{method:"DELETE",body:JSON.stringify({keepData:E})});x(A.log??[]),await w()}catch(A){c(A instanceof Error?A.message:String(A))}finally{m(null)}},B=async()=>{m("*"),c(null);try{const v=await M("/api/fleet/upgrade",{method:"POST"});x(v.log??[t("workspaces.upgraded")]),await w()}catch(v){c(v instanceof Error?v.message:String(v))}finally{m(null)}};return Hi(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(J,{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:()=>{w()},disabled:o||u!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(Ce,{size:12,className:O(o&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>k(v=>!v),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(Ne,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{B()},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")})]}),f&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(Jp,{domain:a.domain,disabled:u!==null,onCreated:(v,E)=>{k(!1),x(v),N(`https://${E.slug}.${a.domain}/pair?email=${encodeURIComponent(E.admin)}`),w()}})}),C&&e.jsx("div",{className:"mb-4",children:e.jsx(Ni,{link:C})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(qp,{fleet:a,onAct:(v,E)=>{R(v,E)},busy:u}):o?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(V,{size:14,className:"animate-spin"}),t("common.checking")]}):null,g&&e.jsx(Yp,{slug:g,onDone:v=>{x(v),w()}}),p.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[12px] text-ink-secondary",children:p.join(`
|
|
11
|
+
`)})]}),e.jsx($e,{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:v=>y({...b,keepData:v.target.checked})}),t("workspaces.keepData")]})]}):null}const Yn=[{choice:"system",label:"settings.theme.system"},{choice:$s.light,label:"settings.theme.light"},{choice:$s.dark,label:"settings.theme.dark"}];function Bs(){return l.useSyncExternalStore(Lr,Ws,Ws)}function $i({simple:s=!1}){const n=Bs(),a=Yn.some(i=>i.choice===n)?void 0:gs.find(i=>i.id===n)?.name;return e.jsx(de,{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:Yn.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Br(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 Qp({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 Zp={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function ex({festival:s}){const n=Pc(),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:Zp[s].map(i=>e.jsx(Rc,{color:i,bodyId:Tc[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(xe,{checked:n,"aria-label":a,onClick:()=>Bc(!n)})]})}function Wi(){const s=ma(Bs());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:gs.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{zr(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(Qp,{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:Or(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(fe,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),Ic(s)&&e.jsx(ex,{festival:s})]})}function tx(){const[s,n]=l.useState(Mr);return e.jsx(de,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Fr(i),n(i)},children:Ur.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function sx(){const[s,n]=l.useState(Dr);return e.jsx(de,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=Gs.find(r=>r===a.target.value);i&&(_r(i),n(i))},children:Gs.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function nx(){const s=vo();return e.jsx(de,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(me,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>ko(No(n.target.value)),children:jo.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function Gi(){const{state:s,dispatch:n}=$(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[m,p]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||x.current)return;const h=Co(i);if(!h.ok){u(t("settings.roomTurns.range"));return}x.current=!0,p(!0);try{const b=await M("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:h.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,p(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:So,max:wo,step:1,inputMode:"numeric",value:i,disabled:m,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:h=>{r(h.target.value),o(!0),u("")},onBlur:()=>{g()},onKeyDown:h=>{h.key==="Enter"&&h.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 ax=10,Vi=1,qi=60,Xn="Enter a whole number from 1 to 60.";function ix(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:Xn};const a=Number(n);return a<Vi||a>qi?{ok:!1,error:Xn}:{ok:!0,minutes:a}}function Qn(s){return s?.mcp?.callTimeoutMinutes??ax}function Ji(){const{state:s,dispatch:n}=$(),a=Qn(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,u]=l.useState(""),[m,p]=l.useState(!1),x=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||x.current)return;const h=ix(i);if(!h.ok){u(t("settings.mcpCalls.range"));return}x.current=!0,p(!0);try{const b=await M("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:h.minutes}})});n({type:"configStatus",config:b}),r(String(Qn(b))),o(!1),u("")}catch(b){u(b instanceof Error?b.message:t("settings.mcpCalls.error"))}finally{x.current=!1,p(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:Vi,max:qi,step:1,inputMode:"numeric",value:i,disabled:m,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:h=>{r(h.target.value),o(!0),u("")},onBlur:()=>{g()},onKeyDown:h=>{h.key==="Enter"&&h.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 Yi(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(m,p)=>{a={value:m,status:p};for(const x of o)x()},u=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const m=a.value;await n(m),i=a.value!==m}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(m){return o.add(m),()=>{o.delete(m)}},confirm(m){!i&&!r&&m!==a.value&&d(m,"idle")},edit(m){i=!0,d(m,"idle"),clearTimeout(c),c=setTimeout(()=>{u()},600)},flush:u}}const Zn=new WeakMap;function rx(){const{state:s,dispatch:n}=$(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=Zn.get(n);if(!r){const m={current:i};r={team:m,controller:Yi(a,async p=>{const x=m.current?await ys({aboutMe:p}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:p}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:x?.aboutMe??p}})})},Zn.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(Eo,{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:m=>c.edit(m.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(lx,{onChanged:m=>{c.confirm(m),n({type:"profileSaved",profile:{aboutMe:m}})}}),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 lx({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let u=!1;return M("/api/profile/learned").then(m=>{u||a(m.learned)}).catch(()=>{}),()=>{u=!0}},[]);const d=async u=>{r(u),o(!1);try{const m=await M(`/api/profile/learned/${encodeURIComponent(u)}/remove`,{method:"POST"});a(m.learned),s(m.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 ea=new WeakMap;function ox(){const{state:s,dispatch:n}=$(),a=s.config?.everyBotRules;let i=ea.get(n);i||(i=Yi(a??"",async m=>{const p=await M("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:m}),timeoutMs:1e4});n({type:"configStatus",config:p})}),ea.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:m=>d(m.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 ta=64,sa=8192,pt=512;function cx(s){return Po(s)?s.size>Ro?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function dx(s,n){return s<ta||n<ta?"settings.profile.avatar.tooSmall":s>sa||n>sa?"settings.profile.avatar.tooLargeDimensions":null}async function Xi(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 ux(s,n){return Xi(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=pt,r.height=pt;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,pt,pt);const o=await new Promise((d,u)=>r.toBlob(m=>m?d(m):u(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function mx(){const{state:s,dispatch:n}=$(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,u]=l.useState(null),m=l.useRef(null),p=f=>{const k=m.current;k&&k.previewUrl!==f?.previewUrl&&URL.revokeObjectURL(k.previewUrl),m.current=f,u(f)};l.useEffect(()=>()=>{m.current&&URL.revokeObjectURL(m.current.previewUrl)},[]);const x=!!s.config?.team,g=async f=>{const k=x?await ys({avatarUrl:f}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:f}})})).profile;n({type:"profileSaved",profile:{avatarUrl:k?.avatarUrl}})},h=f=>{if(!f)return;o(null);const k=cx(f);if(k)return o(t(k));Xi(f,C=>({width:C.naturalWidth,height:C.naturalHeight})).then(({width:C,height:N})=>{const w=dx(C,N);if(w)return o(t(w));p({file:f,previewUrl:URL.createObjectURL(f),width:C,height:N,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},b=f=>{r(!0),o(null),ux(f.file,f.zoom).then(k=>Io(k)).then(k=>{const C=k?Lc(k.path):null;if(!C)throw new Error("avatar");return g(C)}).then(()=>p(null),()=>o(t("settings.profile.avatar.saveError"))).finally(()=>r(!1))},y=()=>{o(null),g("").catch(()=>o(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[d?e.jsx("div",{className:"flex w-full flex-col gap-2 rounded-lg border border-hairline/40 bg-inset p-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-16 shrink-0 overflow-hidden rounded-full bg-raised",children:e.jsx("img",{src:d.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${d.zoom})`}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("settings.profile.avatar.cropTitle")}),e.jsxs("div",{className:"text-[11px] text-ink-secondary",children:[d.width," × ",d.height,"px"]}),e.jsxs("label",{className:"mt-1 block text-[11px] text-ink-secondary",children:[t("settings.profile.avatar.zoom"),e.jsx("input",{"aria-label":t("settings.profile.avatar.zoom"),type:"range",min:"1",max:"2.5",step:"0.05",value:d.zoom,onChange:f=>p({...d,zoom:Number(f.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>p(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled:i,onClick:()=>b(d),children:t("settings.profile.avatar.save")})]})}):a?e.jsx("img",{src:a,alt:"",className:"size-12 rounded-full object-cover"}):e.jsx("div",{className:"size-12 rounded-full bg-raised"}),e.jsxs("label",{className:"cursor-pointer rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[i?t("settings.profile.avatar.uploading"):t("settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:i,onChange:f=>{const k=f.target.files?.[0];f.currentTarget.value="",h(k)}})]}),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 Qi(){const{state:s,dispatch:n}=$(),[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){ys({name:a.trim()}).then(m=>n({type:"profileSaved",profile:{name:m.name,email:m.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(m=>{if(!m.ok)throw new Error("Profile save failed");return m.json()}).then(m=>{m.profile&&n({type:"profileSaved",profile:{name:m.profile.name,email:m.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(mx,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:m=>i(m.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:m=>c(m.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:u}),e.jsx(rx,{}),e.jsx(ox,{})]})}function px({profile:s}){const[n,a]=l.useState(null),i=Ao(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(Ba,{size:20,"aria-hidden":"true"})})}function xx(){const{state:s}=$(),[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(px,{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(Qi,{})})]})}function Zi({row:s=!1}){const n=!!$().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 M("/api/me/away-emails",{timeoutMs:1e4}).then(m=>{u&&i(m.on)},()=>{}),()=>{u=!1}},[n]);const d=u=>{const m=a;i(u),c(!1),M("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:u}),timeoutMs:1e4}).then(p=>i(p.on),()=>{i(m),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(xe,{"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 er(){const{state:s,dispatch:n}=$(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=l.useState(null),[o,d]=l.useState(""),u=l.useRef(!1),m=async p=>{if(!(u.current||p===a)){u.current=!0,c(p),d("");try{const x=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:p}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.threads.error"))}finally{u.current=!1,c(null)}}};return e.jsxs(J,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx(me,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:p=>{m(Number(p.target.value))},children:Array.from({length:16},(p,x)=>x+1).map(p=>e.jsx("option",{value:p,children:p},p))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:i?t("settings.threads.starter"):t("settings.threads.helpHanded")}),r!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function tr(){const{state:s,dispatch:n}=$(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),u=l.useRef(!1),m=a??s.config?.automaticRecovery??{enabled:!1},p=s.instances.filter(f=>f.snapshot.state==="available"&&!f.policy),x=p.find(f=>f.instanceId===m.backup?.instanceId),g=x?.models.options.filter(f=>!f.orgBlocked&&!f.needsCliUpdate&&(x.snapshot.authenticated!==!1||f.custom))??[],h=g.some(f=>f.id===m.backup?.model),b=f=>{i(f),d("")},y=async()=>{if(!(!a||u.current||m.enabled&&!h)){u.current=!0,c(!0),d("");try{const f=await M("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:f}),i(null)}catch(f){d(f instanceof Error?f.message:t("settings.recovery.error"))}finally{u.current=!1,c(!1)}}};return e.jsxs(J,{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(xe,{id:"automatic-recovery-enabled",checked:m.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>b({...m,enabled:!m.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scopeHanded")}),e.jsx("p",{id:"automatic-recovery-own",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.ownBackups")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs(me,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:m.backup?.instanceId??"",disabled:r||!m.enabled,onChange:f=>b({enabled:m.enabled,...f.target.value?{backup:{instanceId:f.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),m.backup&&!x&&e.jsx("option",{value:m.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.instanceId})}),p.map(f=>e.jsx("option",{value:f.instanceId,disabled:!f.models.options.some(k=>f.snapshot.authenticated!==!1||k.custom),children:f.displayName},f.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs(me,{className:"mt-2 w-full",id:"automatic-recovery-model",value:m.backup?.model??"",disabled:r||!m.enabled||!x,onChange:f=>b({enabled:m.enabled,backup:{instanceId:x.instanceId,model:f.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),m.backup?.model&&!h&&e.jsx("option",{value:m.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.model})}),g.map(f=>e.jsx("option",{value:f.id,children:f.label},f.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),m.enabled&&!h&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||m.enabled&&!h,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 sr=1,nr=3650,gx=30,yt=1024*1024,os=256*1024,ar=4*1024*1024*1024,hx=50;function na(s){const n=Number(s);return Number.isInteger(n)&&n>=sr&&n<=nr?n:null}function aa(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*yt);return a>=os&&a<=ar&&a%os===0?a:null}function ia(s){const n=s/yt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function ir(){const{state:s,dispatch:n}=$(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=l.useState(null),[o,d]=l.useState(null),[u,m]=l.useState(null),[p,x]=l.useState(""),[g,h]=l.useState(null),b=l.useRef(!1),y=r??String(a===null?gx:a),f=o??(i===null?String(hx):ia(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&ia(i)===o&&d(null)},[i,o]);const k=async(j,B)=>{if(!b.current){b.current=!0,m(B),x(""),h(null);try{const v=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:j})});n({type:"configStatus",config:v})}catch(v){x(v instanceof Error?v.message:t("settings.threadCleanup.error"))}finally{b.current=!1,m(null)}}},C=j=>{if(!j){c(null),x(""),h(null),k({eventLogRetentionDays:null},"retention");return}const B=na(y);if(B===null){x(t("settings.threadCleanup.invalidRetention")),h("retention");return}k({eventLogRetentionDays:B},"retention")},N=j=>{if(!j){d(null),x(""),h(null),k({eventLogMaxBytes:null},"cap");return}const B=aa(f);if(B===null){x(t("settings.threadCleanup.invalidCap")),h("cap");return}k({eventLogMaxBytes:B},"cap")},w=()=>{if(a===null)return;const j=na(y);if(j===null){x(t("settings.threadCleanup.invalidRetention")),h("retention");return}if(j===a){c(null),x("");return}k({eventLogRetentionDays:j},"retention")},R=()=>{if(i===null)return;const j=aa(f);if(j===null){x(t("settings.threadCleanup.invalidCap")),h("cap");return}if(j===i){d(null),x("");return}k({eventLogMaxBytes:j},"cap")};return e.jsxs(J,{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 ${g==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:sr,max:nr,step:1,inputMode:"numeric",value:y,disabled:a===null||u!==null,"aria-invalid":g==="retention","aria-describedby":"thread-log-retention-help",onChange:j=>{c(j.target.value),x(""),h(null)},onBlur:w,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=>N(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 ${g==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:os/yt,max:ar/yt,step:.25,inputMode:"decimal",value:f,disabled:i===null||u!==null,"aria-invalid":g==="cap","aria-describedby":"thread-log-cap-help",onChange:j=>{d(j.target.value),x(""),h(null)},onBlur:R,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")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}const ra="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function fx(){const s=Kr(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=Vs,u=()=>{const m=Hr({name:n,url:i},window.location.origin);if(!m.ok){o(m.error);return}qs([...s,{id:$r(s),name:m.name,url:m.url}]),a(""),r(""),o("")};return e.jsx(J,{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(m=>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:m.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:m.url,children:m.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>qs(s.filter(p=>p.id!==m.id)),children:t("webPanels.settings.remove")})]},m.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:Js,disabled:d,"aria-invalid":c==="name",onChange:m=>{a(m.target.value),o("")},className:`${ra} 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:m=>{r(m.target.value),o("")},onKeyDown:m=>{m.key==="Enter"&&u()},className:`${ra} 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:Js})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:Vs}):t("webPanels.settings.help")})]})})}const Jt="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Ke=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Te(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},la=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function bx(){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=p=>{r.current===o&&(c.current++,i(p))},m=s?.onState(u);return s?.state().then(p=>{c.current===d&&u(p)}).catch(()=>{}),()=>{r.current++,m?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(yx,{bridge:n}):e.jsx(vx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function yx({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 m=++d.current,p=s.onState(x=>{m===d.current&&a(x.schedule??null)});return s.state().then(x=>{m===d.current&&a(x.schedule??null)}).catch(()=>{}),()=>{d.current++,p()}},[s]),!s.configureSchedule||!n?.enabled)return null;const u=async()=>{if(i||!s.configureSchedule)return;const m=d.current;r(!0),o("");try{const p=await s.configureSchedule({enabled:!1});m===d.current&&a(p.schedule??null)}catch{m===d.current&&o(t("companyBackup.scheduleFailed"))}finally{m===d.current&&r(!1)}};return e.jsx(J,{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(xe,{"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 vx({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[u,m]=l.useState(null),[p,x]=l.useState(""),[g,h]=l.useState(null),[b,y]=l.useState(""),[f,k]=l.useState(""),[C,N]=l.useState(null),[w,R]=l.useState(!1),j=l.useRef(0),B=l.useRef(0),v=l.useRef(0),E=l.useRef(void 0),A=l.useRef(!1),_=l.useRef(null),Z=async()=>{const F=j.current,re=++v.current,T=B.current;d(!0);try{await Promise.all([n.state().then(S=>{F===j.current&&re===v.current&&B.current===T&&i(S)}),n.list().then(S=>{F===j.current&&re===v.current&&c(S)})]),F===j.current&&re===v.current&&x("")}catch{F===j.current&&re===v.current&&x(t("companyBackup.loadFailed"))}finally{F===j.current&&re===v.current&&d(!1)}};l.useEffect(()=>{const F=++j.current,re=S=>{if(F!==j.current)return;B.current++,i(S);const H=S.lastBackupAt??S.schedule?.lastBackupAt;!S.busy&&!S.pendingRestore&&H&&H!==E.current&&(E.current=H,Z())},T=n.onState(re);return Z(),()=>{j.current++,v.current++,T()}},[n]),l.useEffect(()=>{const F=_.current;if(!(!g||!F))return F.showModal(),()=>{F.close()}},[g]);const ee=w||a?.pendingRestore===!0,Y=u!==null||!a||a.busy||ee,te=()=>{h(null),y(""),k(""),N(null)},ne=F=>{Y||A.current||(x(""),y(""),k(""),N(null),h(F))},ie=async(F,re)=>{if(Y||A.current)return;A.current=!0,m(F),x("");const T=j.current;try{await re(()=>T===j.current)}catch{T===j.current&&x(t(F==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{A.current=!1,T===j.current&&m(null)}},P=()=>{g?.kind==="create"&&ie("create",async F=>{await n.create({clientState:Bo()}),F()&&(te(),await Z())})},L=async F=>{if(!n.configureSchedule||A.current||!a||F&&(Y||g?.kind!=="schedule"||f!=="BACK UP THIS WORKSPACE DAILY"))return;A.current=!0,m("schedule"),x("");const re=j.current,T=B.current;k("");try{const S=await n.configureSchedule(F?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});re===j.current&&(B.current===T&&i(S),te())}catch{re===j.current&&x(t("companyBackup.scheduleFailed"))}finally{A.current=!1,re===j.current&&m(null)}},I=()=>{g?.kind!=="restore"||g.entry.passwordRequired!==!1&&(b.length<12||b.length>1024)||ie("prepare",async F=>{const re=b;y(""),N(null),k("");const T=await n.prepareRestore({id:g.entry.id,...g.entry.passwordRequired!==!1?{password:re}:{}});F()&&N(T)})},K=()=>{g?.kind!=="restore"||!C||f!=="REPLACE"||ie("restore",async F=>{const re=localStorage.getItem(an);if(re&&re!==C.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(an,C.id),await n.restore({id:C.id,confirmation:"REPLACE"}),F()&&(R(!0),te())})},Q=()=>{g?.kind!=="delete"||f!=="DELETE"||ie("delete",async F=>{await n.delete({id:g.entry.id,confirmation:"DELETE"}),F()&&(te(),await Z())})},le=async()=>{const F=j.current;try{await n.cancel()}catch{F===j.current&&x(t("companyBackup.actionFailed"))}},ae=r?.backups.filter(F=>F.status==="ready")??[],U=r?r.backups.length-ae.length:0,X=a?.progress,oe=p||a?.message,pe=(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"):X?t(`companyBackup.phase.${X.phase}`):t("companyBackup.working")}),X&&X.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:X.totalBytes,value:Math.min(X.bytesTransferred,X.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Ke(X.bytesTransferred),total:Ke(X.totalBytes)})})]}),a?.busy&&u!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{le()},children:t("companyBackup.cancelTransfer")})]}),ce=g?.kind==="restore"?t("companyBackup.restore"):g?.kind==="delete"?t("companyBackup.delete"):g?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),se=a?.schedule,he=F=>new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(F));return e.jsxs(J,{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&&se&&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(xe,{"aria-label":t("companyBackup.daily"),checked:se.enabled,disabled:u!==null||!a||!se.enabled&&Y,onClick:()=>se.enabled?void L(!1):ne({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${se.status}`)}),se.enabled&&se.nextBackupAt&&Number.isFinite(se.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:he(se.nextBackupAt)})}),se.lastBackupAt&&Number.isFinite(se.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:he(se.lastBackupAt)})}),se.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:se.message})]}),ee?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(nn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:Y,onClick:()=>ne({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:u!==null||a?.busy||ee||o,onClick:()=>{Z()},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:Ke(r.usedBytes),total:Ke(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(F=>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:la(F)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Ke(F.sizeBytes),F.appVersion?` · ${F.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:F.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:Y,onClick:()=>ne({kind:"restore",entry:F}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:Y,onClick:()=>ne({kind:"delete",entry:F}),children:t("companyBackup.delete")})]})]},F.id))})]}),!g&&pe,!g&&oe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:oe})]}),g&&e.jsx("dialog",{ref:_,"aria-labelledby":"company-backup-dialog-title",onKeyDown:F=>{(F.key==="Escape"||F.key==="Tab")&&F.stopPropagation()},onCancel:F=>{F.preventDefault(),u||te()},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:ce}),ee&&e.jsx(nn,{}),(g.kind==="restore"||g.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[la(g.entry)," · ",Ke(g.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:g.entry.id})]}),(g.kind==="create"||g.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:F=>{F.preventDefault(),g.kind==="schedule"?L(!0):P()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(g.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),g.kind==="schedule"?e.jsxs("details",{className:"text-[13px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer text-ink",children:t("companyBackup.included")}),e.jsx("p",{className:"mt-2",children:t("backup.excluded")}),e.jsx("p",{className:"mt-2",children:t("companyBackup.managedPrivacy")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("backup.excluded")}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedPrivacy")})]}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedEncryption")}),g.kind==="schedule"&&e.jsxs("label",{className:"flex items-start gap-2 text-[13px]",children:[e.jsx("input",{className:"mt-1 accent-accent",type:"checkbox",required:!0,disabled:Y,checked:f==="BACK UP THIS WORKSPACE DAILY",onChange:F=>k(F.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:Y||g.kind==="schedule"&&f!=="BACK UP THIS WORKSPACE DAILY",children:t(g.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),g.kind==="restore"&&(C?e.jsxs(e.Fragment,{children:[e.jsx(To,{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:Y,value:f,onChange:F=>k(F.target.value),className:Jt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:Y||f!=="REPLACE",onClick:K,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:F=>{F.preventDefault(),I()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),g.entry.passwordRequired!==!1&&e.jsxs("label",{className:"text-[13px]",children:[t("backup.importPassword"),e.jsx("input",{type:"password",autoComplete:"off",required:!0,minLength:12,maxLength:1024,disabled:Y,value:b,onChange:F=>y(F.target.value),className:Jt})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:Y||g.entry.passwordRequired!==!1&&(b.length<12||b.length>1024),children:t("backup.validate")})]})),g.kind==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-danger",children:t("companyBackup.deleteWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("companyBackup.confirmDelete"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:6,disabled:Y,value:f,onChange:F=>k(F.target.value),className:Jt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:Y||f!=="DELETE",onClick:Q,children:t("companyBackup.delete")})]}),pe,oe&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:oe}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:u!==null,onClick:te,children:t("companyBackup.cancel")})]})})]})}function jx({sources:s}){const n=[...new Set(s.map(a=>a==="claudeDesktop"?"claudeCode":a))];return e.jsx("span",{className:"mr-1.5 inline-flex items-center gap-1 align-[-1px]","aria-hidden":"true",children:n.map(a=>{switch(a){case"codex":return e.jsx(Go,{size:12},a);case"cursor":return e.jsx(Wo,{size:12},a);case"gemini":return e.jsx(va,{preset:"google",size:12},a);default:return e.jsx($o,{size:12},a)}})})}function oa({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(jx,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const rr="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 kx({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(V,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:m,notes:p,done:x}=Uo(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(fe,{size:12,strokeWidth:3}):e.jsx(Fo,{size:12,strokeWidth:2.5})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:m}),p.map(g=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:g},g))]})]})}else!n||Do(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(oa,{icon:e.jsx(La,{size:15}),label:t("onboarding.import.skills"),summary:_o(n),hint:t("onboarding.import.skillsHint"),sources:rn(n.skills),checked:a.skills,disabled:d,onChange:m=>c({...a,skills:m})}),n.tools.length>0&&e.jsx(oa,{icon:e.jsx(Ho,{size:15}),label:t("onboarding.import.tools"),summary:Ko(n),hint:t("onboarding.import.toolsHint"),sources:rn(n.tools),checked:a.tools,disabled:d,onChange:m=>c({...a,tools:m})})]}),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(rr,"mt-3"),children:[d&&e.jsx(V,{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 Nx({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,m]=l.useState(null);l.useEffect(()=>{if(!n)return;const x=new AbortController;return s.detect(x.signal).then(i,()=>i(null)),()=>x.abort()},[s,n]);const p=async()=>{if(!a||o==="working")return;const x={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!x.skills&&!x.tools)){d("working");try{const g=await s.apply(x);Oc("setup_import_applied",{skills:g.skills?.added.length??0,tools:g.tools?.added.length??0}),m(g),d("idle")}catch{d("failed")}}};return e.jsx(kx,{local:n,detection:a,chosen:r,status:o,result:u,onChoose:c,onBring:()=>{p()}})}function wx(){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(zo,{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(rr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(ua,{size:14,"aria-hidden":"true",className:O("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Mo,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function lr({client:s=Lo}){const{state:n}=$();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Nx,{client:s,local:Oo(n.config?.cloudHome===!0)}),e.jsx(wx,{})]})}function or({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(Sx,{simple:s}),e.jsx(Cx,{simple:s}),e.jsx(Ex,{simple:s})]})}const ca=()=>typeof Notification<"u"?Notification.permission:"default";function Sx({simple:s=!1}){const[n,a]=l.useState(ca),i=Vo();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(ca())};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 ln(!i);const o=await Qo();o&&(a(o),o==="granted"&&ln(!0))};return e.jsx(de,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(xe,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function Cx({simple:s=!1}){const n=qo();return e.jsx(de,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(xe,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Jo(!n)})})}function Ex({simple:s=!1}){const n=Yo();return e.jsx(de,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(xe,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>Xo(!n)})})}function cr(){const{state:s,dispatch:n}=$(),a=Zo(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!ec(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const u=await M("/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(de,{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(xe,{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 Ax=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],Ix=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function Px({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(be,{label:t("settings.group.account"),block:"general",children:e.jsxs(ye,{children:[s("general")&&e.jsx(xx,{}),s("general")&&e.jsx(Zi,{row:!0}),s("general")&&e.jsx(ti,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(wi,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(be,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(ye,{children:[e.jsx($i,{simple:!0}),e.jsx(Rx,{onLooks:a}),e.jsx(Pi,{}),e.jsx(Ma,{}),e.jsx(Ri,{}),e.jsx(Qa,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("settings.simple.group.typing"),children:e.jsxs(ye,{children:[e.jsx(Qt,{simple:!0}),e.jsx(Za,{simple:!0}),e.jsx(ei,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("notifications.title"),children:e.jsx(ye,{children:e.jsx(or,{simple:!0})})}),s("general")&&e.jsx(be,{label:t("settings.simple.group.system"),children:e.jsxs(ye,{children:[e.jsx(ri,{simple:!0}),e.jsx(Ua,{simple:!0}),e.jsx(li,{}),e.jsx(oi,{}),e.jsx(ii,{simple:!0})]})}),s("import")&&e.jsx(be,{label:t("settings.section.import"),block:"import",children:e.jsx(ve,{children:e.jsx(lr,{})})}),s("organization")&&e.jsx(be,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Bi,{})}),s("activity")&&e.jsx(be,{label:t("settings.section.activity"),block:"activity",children:e.jsx(Si,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(ye,{children:e.jsx(de,{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(ye,{children:e.jsx(Zt,{simple:!0})})})]})}function Rx({onLooks:s}){const n=Bs(),a=gs.find(r=>r.id===ma(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(de,{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 Tx({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(Wi,{})}),n&&e.jsx(ye,{children:e.jsx(Xa,{})})]})}function Bx({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(be,{block:"more-sections",children:e.jsx(ye,{children:s.map(({id:i,labelKey:r})=>e.jsx(de,{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(be,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(J,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(Gi,{})}),e.jsx(J,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(Ji,{})}),e.jsx(er,{}),e.jsx(tr,{}),e.jsx(ir,{}),e.jsx(xi,{}),e.jsx(ye,{children:e.jsx(cr,{})})]})})]})}function Lx({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(ve,{children:[e.jsx(hi,{simple:!0,more:n("ai-more")}),e.jsx(ye,{children:e.jsx(Ya,{simple:!0})})]})}),s("connections")&&e.jsx(ve,{children:e.jsx(kt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function Ox({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(be,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(ve,{children:e.jsx(vi,{})})}),s("companion")&&e.jsxs(be,{label:t(za()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(be,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(ye,{children:[e.jsx(Va,{}),e.jsx(qa,{})]}),e.jsx(Ja,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(Ii,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(kt,{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 zx({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=tc();return nd(),e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(sc,{usage:i,upgrade:r,children:c}):e.jsx(ve,{note:"settings.adminOnly.usage",children:e.jsx(Pp,{})})}),(i||s("usage"))&&e.jsxs(kt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(nc,{usage:i,upgrade:r}),s("usage")&&e.jsx(ve,{note:"settings.adminOnly.usage",children:e.jsx(_i,{})})]}),s("cloudAccount")&&e.jsxs(be,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(ad,{}),children:[e.jsx(ye,{children:e.jsx(ti,{place:"plan",usage:i,upgrade:r})}),e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const dr=()=>`${us()} ${ac()}`;function Mx(){const s=ic(!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(de,{title:dr(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function Ux({remoteActive:s}){return e.jsx(be,{block:"updates",children:e.jsxs(ye,{children:[window.ogb?.updater?e.jsx(Wa,{title:dr()}):e.jsx(Mx,{}),e.jsx(Oa,{}),!s&&e.jsx(Ga,{}),e.jsx(ci,{simple:!0})]})})}const da=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Ls=[{id:"general",group:"you",labelKey:"settings.section.general",icon:Ba,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",...Gd()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:dd,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:rc,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:xd,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:Ia,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:lc,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:oc,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:La,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:Lt,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:si,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:St,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:ms,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:Lt,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:rd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:cc,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:bs,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:ht,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:ht,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:md,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:Lt,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:dc,keywords:["early","preview","learn","skill","authoring"]}],Fx=[{id:"general",labelKey:"settings.section.general",icon:uc,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:ht,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:mc,sections:["engines","connections"],keywords:["new bots","defaults","effort"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:si,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:pc,sections:["usage","cloudAccount"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:od,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],cs=["backups","experimental","workspaces","skills","decisionModel","imageGeneration"],Dx={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function _x(s,n){const a=Fx.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=cs.includes(n)&&s.has(n)?Ls.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 Kx(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Ns(s,i)}function Hx(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=Ls.find(r=>r.id===a);return i?ds(i,n):!1})}function ds(s,n){return!n||s.id==="connections"&&Qe.some(a=>hs(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function $x(s){return s?Qe.filter(n=>hs(n,s)).slice(0,8):[]}const Wx=s=>s.uses?Xt(s.uses,s.id):Xt(s.id);function gg(){return e.jsx(_a,{modal:!0,children:e.jsx(Gx,{})})}function Gx(){const s=zc(),{state:n,dispatch:a}=$(),i=Wr(),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),m=l.useRef(i),[p,x]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>x("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>x("")),[]);const g=p.trim().toLowerCase(),h=vt(),b=za(),y=Ls.map(T=>T.id==="companion"?{...T,labelKey:b?"settings.section.phoneDevices":"settings.section.thisServer"}:T),k=y.filter(T=>!r||T.id==="companion"||T.id==="appearance"||T.id==="desktopWorkspaces").filter(T=>T.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(T=>T.id!=="organization"||!!window.ogb?.organization).filter(T=>T.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(T=>T.id!=="workspaces"||Hi(n.config)).filter(T=>T.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(T=>T.id!=="activity"||!window.ogb&&h===!0).filter(T=>T.id!=="botAccess"||!!n.config?.team&&h===!0).filter(T=>(T.id!=="skills"||on(n.config))&&(T.id!=="cloudAccount"||Gr)),C=k.filter(T=>ds(T,g)),N=new Set([...k.map(T=>T.id),...r?[]:["updates"]]),w=i?[]:_x(N,o),R=w.filter(T=>Hx(T,g)),j=w.find(T=>T.sections.includes(o)),B=i?y.find(T=>T.id===o)?.labelKey:j?.labelKey,v=i?C.some(T=>T.id===o)?void 0:C[0]?.id:j&&R.includes(j)?void 0:R[0]&&(R[0].sections.find(T=>C.some(S=>S.id===T))??R[0].sections[0]);l.useEffect(()=>{v&&a({type:"toggleAppSettings",open:!0,section:v})},[a,v]);const[E,A]=l.useState({}),_=xa();l.useEffect(()=>{_&&A(T=>T["ai-keys"]?T:{...T,"ai-keys":!0})},[_]);const Z=T=>{const S=g!==""||(E[T]??Dx[c]===T);return{id:T,open:S,onToggle:()=>A(H=>({...H,[T]:!S}))}},[ee,Y]=l.useState(null),te=ee?.for===c?ee.view:null,ne=(T,S=c)=>Y(T&&{view:T,for:S});l.useEffect(()=>{Y(T=>T?.for===c?T:null)},[c]);const[ie,P]=l.useState(null),L=i||Vr||!g?[]:Ax.filter(T=>t(T).toLowerCase().includes(g)),I=k.filter(T=>cs.includes(T.id)),K=r||!k.some(T=>T.id==="connections")?[]:$x(g),Q=T=>K.map(S=>e.jsx("button",{type:"button","data-settings-key-result":S.id,className:T,onClick:()=>{x(""),ne(null),a(Wx(S))},children:e.jsxs("span",{children:[t(S.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(xc(S).titleKey)]})]})},S.id)),le=j?.sections.indexOf(o)??0,ae=!i&&c==="remote"?"remote":o;l.useEffect(()=>{u.current&&Kx(u.current,ae,i?0:ae===o?le:1)},[i,ae,o,le]),l.useEffect(()=>{if(!ie)return;const T=u.current?.querySelector(`[data-settings-block="${ie}"]`);u.current&&T&&Ns(u.current,T),P(null)},[ie]),l.useEffect(()=>{const T=document.activeElement instanceof HTMLElement?document.activeElement:null,S=d.current,H=S?.querySelector("[data-settings-search]");m.current&&H?.checkVisibility()?H.focus():S?.focus();const ue=W=>{if(!s())return;if(!m.current&&S&&document.activeElement===S&&W.key.length===1&&!W.metaKey&&!W.ctrlKey&&!W.altKey&&H?.checkVisibility()){W.preventDefault(),H.focus(),x(Le=>Le+W.key);return}if(W.defaultPrevented||S&&[...S.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(Le=>Le.getClientRects().length))return;if(W.key==="Escape"){W.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(W.key!=="Tab"||!S)return;const je=Array.from(S.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(Le=>Le.checkVisibility());if(je.length===0){W.preventDefault(),S.focus();return}const Ee=je[0],We=je[je.length-1],Ge=document.activeElement;W.shiftKey&&(Ge===Ee||!S.contains(Ge))?(W.preventDefault(),We.focus()):!W.shiftKey&&Ge===We&&(W.preventDefault(),Ee.focus())};return window.addEventListener("keydown",ue),()=>{window.removeEventListener("keydown",ue),T?.focus()}},[a,s]);const U=T=>a({type:"toggleAppSettings",open:!0,section:T}),X=n.appSettingsPhonePairing,oe=$c(n.config?.cloudHome===!0)==="computer",pe={client:e.jsx(Um,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||b?null:e.jsx(Pm,{}),pairing:b?null:e.jsx(dm,{cloudHome:n.config?.cloudHome===!0,focusRequest:oe?0:X,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(um,{profileEmail:n.config?.profile?.email,focusRequest:X,simple:!i}):null},ce=T=>{switch(T){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(On,{}),pe.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Bi,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(wp,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>a(Wc()),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(Zt,{}),e.jsx(Ua,{}),e.jsx(li,{}),e.jsx(id,{}),e.jsx(hc,{}),e.jsxs(J,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(Qi,{}),e.jsx(Zi,{})]}),e.jsx(Qt,{}),e.jsx(ri,{}),e.jsx(td,{}),e.jsx(cr,{}),e.jsx(ii,{}),e.jsx(Oa,{}),e.jsx(Ya,{}),e.jsx(J,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(Gi,{})}),e.jsx(J,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(Ji,{})}),e.jsx(er,{}),e.jsx(tr,{}),e.jsx(ir,{}),e.jsx(oi,{}),e.jsx(fx,{}),!r&&e.jsx(Ga,{}),e.jsx(Wa,{}),e.jsx(ci,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx($i,{}),e.jsx(J,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(Wi,{})}),e.jsx(Qm,{}),r&&e.jsx(Zt,{}),r&&e.jsx(Qt,{}),e.jsx(tx,{}),e.jsx(sx,{}),e.jsx(Qa,{}),e.jsx(Za,{}),e.jsx(ei,{}),e.jsx(nx,{}),e.jsx(Ma,{}),e.jsx(Ri,{}),e.jsx(Xc,{}),e.jsx(Qc,{}),e.jsx(Zc,{}),e.jsx(or,{}),!r&&e.jsx(Xa,{}),e.jsx(ed,{})]});case"experimental":return e.jsx(Yc,{});case"connections":return e.jsx(ve,{children:e.jsx(Wd,{})});case"decisionModel":return e.jsx(ve,{children:e.jsx(su,{})});case"imageGeneration":return e.jsx(ve,{children:e.jsx(uu,{})});case"engines":return e.jsx(ve,{children:e.jsx(hi,{})});case"backups":return e.jsxs(ve,{children:[e.jsx(gc,{}),e.jsx(bx,{})]});case"import":return e.jsx(ve,{children:e.jsx(lr,{})});case"companion":return e.jsxs(e.Fragment,{children:[pe.companion,pe.pairing,pe.domain,window.ogb?.environments?null:pe.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(Va,{}),e.jsx(qa,{}),e.jsx(Ja,{}),e.jsx(ve,{children:e.jsx(vi,{})})]});case"logins":return e.jsx(Ii,{});case"usage":return e.jsx(ve,{note:"settings.adminOnly.usage",children:e.jsx(_i,{})});case"skills":return on(n.config)?e.jsx($p,{}):null;case"people":return e.jsx(wi,{});case"activity":return e.jsx(Si,{});case"botAccess":return e.jsx(vm,{});case"workspaces":return e.jsx(Xp,{});default:return null}},se=()=>{U("general"),ne("more","general")},he=T=>{const S=H=>T.sections.includes(H);switch(T.id){case"general":return te==="looks"?e.jsx(Tx,{toolCalls:!r,onBack:()=>{ne(null),P("appearance")}}):te==="more"?e.jsx(Bx,{sections:I,onOpen:H=>{ne(null),U(H)},onBack:()=>{ne(null),P("more")}}):e.jsx(Px,{has:S,peopleOpen:o==="people",onLooks:()=>ne("looks"),onMore:S("general")?()=>ne("more"):void 0});case"ai":return e.jsx(Lx,{has:S,disclose:Z,connections:ce("connections")});case"computer":return e.jsx(Ox,{has:S,remoteAccess:pe,servers:e.jsx(On,{}),disclose:Z});case"billing":return e.jsx(zx,{has:S,disclose:Z,cloudAccount:ce("cloudAccount")});case"updates":return e.jsx(Ux,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[cs.includes(T.sections[0])&&N.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:se,children:t("settings.simple.looks.back")})}),T.sections.map(H=>e.jsx("section",{"data-settings-block":H,className:"flex scroll-mt-4 flex-col gap-4",children:ce(H)},H))]})}},F=()=>a({type:"toggleAppSettings",open:!1}),re=(T,S)=>e.jsxs("div",{className:T,children:[e.jsx(at,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:p,onChange:H=>x(H.target.value),onKeyDown:H=>{H.key==="Escape"&&(H.stopPropagation(),p?x(""):F())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:S})]});if(!i){const T=j?.id==="general"?te:null,S="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=>{ne(null),U(W)},ue=g?[...I.filter(W=>ds(W,g)).map(W=>({key:W.id,labelKey:W.labelKey,open:()=>H(W.id)})),...(N.has("general")?Ix:[]).filter(W=>t(W).toLowerCase().includes(g)).map(W=>({key:W,labelKey:W,open:()=>{se(),P("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:dn(),onMouseDown:W=>W.target===W.currentTarget&&F(),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:[re("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"),R.length===0&&L.length===0&&ue.length===0&&K.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:p.trim()})}),R.map(W=>{const je=W.icon,Ee=W===j;return e.jsxs("button",{type:"button","data-settings-page":W.id,onClick:()=>H(W.sections[0]),"aria-current":Ee?"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",Ee?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(je,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:t(W.labelKey)})]},W.id)}),L.map(W=>e.jsx("button",{type:"button","data-settings-advanced-only":W,onClick:()=>{x(""),H("general"),P("advanced-mode")},className:S,children:e.jsxs("span",{children:[t(W)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},W)),ue.map(W=>e.jsx("button",{type:"button","data-settings-more-result":W.key,onClick:()=>{x(""),W.open()},className:S,children:e.jsxs("span",{children:[t(W.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},W.key)),Q(S)]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center gap-3 py-3 pl-4 pr-14 sm:pb-1.5 sm:pl-12 sm:pt-8",children:[e.jsx(me,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:j?.id??"",onChange:W=>{x("");const je=w.find(Ee=>Ee.id===W.target.value);je&&H(je.sections[0])},children:w.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:T==="looks"?t("settings.simple.page.looks"):T==="more"?t("settings.simple.more.title"):j?t(j.labelKey):null})]}),e.jsx("button",{type:"button",onClick:F,"aria-label":t("settings.close"),title:`${t("settings.close")} (${cn("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(Be,{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]",Ra,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(Jn,{config:n.config}),j?he(j):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:dn(),onMouseDown:T=>T.target===T.currentTarget&&F(),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")}),re("mb-2 mt-1 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-tertiary focus:outline-none"),C.length===0&&e.jsx("div",{className:"px-2.5 py-4 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:p.trim()})}),da.map(T=>{const S=C.filter(H=>H.group===T.id);return S.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${T.id}`,"data-settings-group":T.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${T.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(T.labelKey)}),S.map(({id:H,labelKey:ue,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(ue)]},H))]},T.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(me,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:T=>{x(""),U(T.target.value)},children:da.map(T=>{const S=k.filter(H=>H.group===T.id);return S.length===0?null:e.jsx("optgroup",{label:t(T.labelKey),children:S.map(({id:H,labelKey:ue})=>e.jsx("option",{value:H,children:t(ue)},H))},T.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:B?t(B):null}),e.jsx("button",{onClick:F,"aria-label":t("settings.close"),title:`${t("settings.close")} (${cn("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(Be,{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(Jn,{config:n.config}),ce(o)]})]})]})]})}export{Ls as SECTIONS,da as SETTINGS_GROUPS,Dx as SIMPLE_FOLDED,cs as SIMPLE_HIDDEN_SECTIONS,Fx as SIMPLE_PAGES,gg as SettingsModal,$x as keySearchResults,Wx as openKeyResult,Kx as revealSettingsBlock,ds as sectionMatches,_x as simpleSettingsPages};
|