@seira-bot/seira 0.1.180 → 0.1.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{ActivityPanel-DpipGqnm.js → ActivityPanel-tZLxRHYi.js} +1 -1
- package/dist/assets/{AnnouncementsPage-GCXia4xK.js → AnnouncementsPage-BrGYAaS0.js} +1 -1
- package/dist/assets/{App-BIllYA_e.js → App-h8WTNY4l.js} +136 -136
- package/dist/assets/{AppEventEditor-DYdUkpiM.js → AppEventEditor-CLpZ2lyb.js} +1 -1
- package/dist/assets/{BotSettingsDialog-DxRMUwAP.js → BotSettingsDialog-COjDhP9V.js} +1 -1
- package/dist/assets/{BrowserPanel-Cu_GqDA1.js → BrowserPanel-D_kPeSZ3.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-CL3TIl73.js → BrowserProfilesManager-haN8RgPf.js} +1 -1
- package/dist/assets/{CloudAddDialog-DUk6i4df.js → CloudAddDialog-vwGwJIYN.js} +1 -1
- package/dist/assets/{ComputerFilesPane-HvpeAXhL.js → ComputerFilesPane-DJu1k1Ap.js} +1 -1
- package/dist/assets/{ComputerPanel-CozzFQeF.js → ComputerPanel-D9bTedHq.js} +2 -2
- package/dist/assets/{DataPanel-DGqcWB1O.js → DataPanel-CsuS_ybT.js} +1 -1
- package/dist/assets/{DesktopViewer-BoBSIDfB.js → DesktopViewer-YvIV04Lf.js} +1 -1
- package/dist/assets/{EnginesSettings-D643-yZk.js → EnginesSettings-C27xDaBN.js} +1 -1
- package/dist/assets/{FilesView-b5DFlMDt.js → FilesView-Dsxj73nW.js} +1 -1
- package/dist/assets/{GrokMoveDialog-gGTLfrGg.js → GrokMoveDialog-DEgRQW9G.js} +1 -1
- package/dist/assets/{ImportDialog-Bu5X6qOF.js → ImportDialog-DLVTgN-h.js} +1 -1
- package/dist/assets/{InspectorPanel-DU7_iwQR.js → InspectorPanel-gvFj5wfe.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-Wxnn1d66.js → KeyboardShortcutsModal-aF0vhD29.js} +1 -1
- package/dist/assets/{LiveDesktop-D9PC-iAT.js → LiveDesktop-Bca91cEb.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-0YxB-I-X.js → LocalVmWorkspace-CVLDY3ws.js} +1 -1
- package/dist/assets/{MacLocalControl-DoEGcs3V.js → MacLocalControl-BeNWQ9oY.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-CAlARwd0.js → MarkdownFilePreview-CYw3CQ3T.js} +1 -1
- package/dist/assets/{MenuMotion-DfjnHTCi.js → MenuMotion-CHp-hB40.js} +1 -1
- package/dist/assets/{NewBotDialog-D3i7j_KP.js → NewBotDialog-BxeQktoI.js} +1 -1
- package/dist/assets/{PhoneAppDialog-OeXLO0Wb.js → PhoneAppDialog-CIlw_m5U.js} +1 -1
- package/dist/assets/{PlacesRail-3RaNlpug.js → PlacesRail-Df-jNTHn.js} +1 -1
- package/dist/assets/PluginsPanel-CMqZcDkC.js +8 -0
- package/dist/assets/{ProIntroduction-B3phUWnc.js → ProIntroduction-D8hWm9R5.js} +1 -1
- package/dist/assets/{PublishedAppsPage-BXWDYkhG.js → PublishedAppsPage-BMn3C64O.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-vgrEf5B7.js → RemoteAgentSettingsPanel-B7QJizjx.js} +1 -1
- package/dist/assets/{RoomPanel-BmXypXPv.js → RoomPanel-CyWZ4kkq.js} +1 -1
- package/dist/assets/RoutinesPage-B9kKyfFp.js +2 -0
- package/dist/assets/{ServerPairingCard-c2fKq1gh.js → ServerPairingCard-D21dP5Bc.js} +1 -1
- package/dist/assets/SettingsModal-afRPXeYI.js +2 -0
- package/dist/assets/{ShareDepartmentDialog-CJITsmAd.js → ShareDepartmentDialog-CwErWDth.js} +1 -1
- package/dist/assets/{SignedInSites-B2pCMdic.js → SignedInSites-CFyvOLSc.js} +1 -1
- package/dist/assets/{TeamFilesPage-B10cdbwa.js → TeamFilesPage-BvhXs2O5.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-CRmTfBOI.js → TeamLibraryPanel-Dm8wjNB4.js} +1 -1
- package/dist/assets/{TeamMapPage-BoTNppEy.js → TeamMapPage-jCSzFPvB.js} +1 -1
- package/dist/assets/{ToolPageShell-BPd_nyJ8.js → ToolPageShell-DKZUregg.js} +1 -1
- package/dist/assets/{TriggersPage-DDxtJMT4.js → TriggersPage-wSB6z1cp.js} +1 -1
- package/dist/assets/{VisibilitySection-Cd3TZvS_.js → VisibilitySection-CFr6fOzq.js} +1 -1
- package/dist/assets/{WebhookTrigger-AJduidiC.js → WebhookTrigger-BJN-V-bx.js} +1 -1
- package/dist/assets/{WorksOnGrid-DHo10o0j.js → WorksOnGrid-B3wYro9M.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-DnIZyeSK.js → abnfDiagram-YUKMZFIV-DRhWKTiz.js} +1 -1
- package/dist/assets/{activity-DrX2_Hm9.js → activity-l0oTqbd6.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-DHdulT2e.js → architectureDiagram-47P4ROYG-C_qnTvJF.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-BGReDH4k.js → blockDiagram-E7TT5TSB-DzLSloVY.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-BV9zDZsL.js → c4Diagram-CRA5TL53-BzVViHCA.js} +1 -1
- package/dist/assets/{calendar-days-Ddhxf1PV.js → calendar-days-DFd3GKf_.js} +1 -1
- package/dist/assets/channel-B2D6cAE5.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DAj16syq.js → chunk-2Q5K7J3B-hR-bQJHo.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CMyoXW_3.js → chunk-5VM5RSS4-BWmBW1XC.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW--z54G8Jv.js → chunk-7TKQ45FW-DuUk7RXl.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-CPPbUHIj.js → chunk-AW2ZBBNX-Madgl1uv.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-pKEz9wbK.js → chunk-FVRAUYC3-WSgsvIGA.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-DIOqwx2X.js → chunk-HTAEGDNF-CfoPR2yG.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-BW474-Li.js → chunk-JWPE2WC7-tLRHdBom.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-DjAEB-Df.js → chunk-KQW6MTUR-BqwuNuVY.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-CMZz2xNV.js → chunk-XXDRQBXY-BOeb8xE4.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-7GYDWs2n.js → classDiagram-v2-K4WV4PDN-CFeH5trZ.js} +1 -1
- package/dist/assets/{core-Dq4LUz6X.js → core-CnInZb-o.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Dy2zOVu3.js → cose-bilkent-JH36ORCC-BEg68hhI.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-C7I3qmqf.js → cynefin-EF2NZ3EQ-B_Xq3hQ3.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-CsPcUXHD.js → cynefinDiagram-3GCD6N5R-DN1o2ihW.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-DxvGlifm.js → dagre-W4DXFKR2-BFf83-nP.js} +1 -1
- package/dist/assets/{de-CrlnmnfQ.js → de-BpsYkrLY.js} +1 -1
- package/dist/assets/{desktop-connection-Df-k5QBM.js → desktop-connection-CU6jsy2e.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-Qz2-e2_u.js → diagram-2UJZ2QOL-_qwbS5JH.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-D1u4ioUX.js → diagram-OVF4WLC6-9sq9EfiF.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-DZiCtcMI.js → diagram-PFPMY2P6-Ow1v5ZhK.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-DmVn9h1H.js → diagram-UMYRVEAY-DDTBFPls.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-CJK2ajcB.js → diagram-YEKJPTXX-D1zZ8KqI.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-NoYT_JX9.js → diagram-ZIFT7M5P-C_vZWUw8.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-BooF3Pem.js → ebnfDiagram-VR2GEFS7-D_1GvBDx.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-4Ai0igvq.js → elk-IJKZMXRS-CV-PzspH.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-CdhhzqVX.js → erDiagram-O2IAPWRE-CnKVd0av.js} +1 -1
- package/dist/assets/{es-BIPy8tP9.js → es-COLCGADa.js} +1 -1
- package/dist/assets/{file-up-Bs5NWcjw.js → file-up-Bjx5Vcmk.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-SeyZJAiT.js → flowDiagram-OXPTDLAJ-CGJh171P.js} +1 -1
- package/dist/assets/{fr-CCbXz1Dc.js → fr-CJ1x1iRl.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-rmA_SJlC.js → ganttDiagram-R7TSEDQI-CygoACFs.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-Coc2oeHo.js → gitGraphDiagram-XJZIOB7I-ByxErzHV.js} +1 -1
- package/dist/assets/{hi-DmCL9a_Y.js → hi-BC0iO7jD.js} +1 -1
- package/dist/assets/{index-uiyAwyX1.js → index-BRfvYRb5.js} +1 -1
- package/dist/assets/{index-D69O3YiA.js → index-DQZxP2c4.js} +2 -2
- package/dist/assets/{index-C1PEx1tc.js → index-DtDQrExn.js} +3 -3
- package/dist/assets/{infoDiagram-5W2HQ5XZ-DScYPtht.js → infoDiagram-5W2HQ5XZ-BlzjfTwq.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-Cf7mJB_l.js → ishikawaDiagram-K3B6WC7H-2rf_4lR_.js} +1 -1
- package/dist/assets/{it-BWkdcVfm.js → it-BIwsqdpz.js} +2 -2
- package/dist/assets/{ja-BaOL6cSA.js → ja-BJYXkO5E.js} +2 -2
- package/dist/assets/{journeyDiagram-COXZFDF6-Dtmolw3A.js → journeyDiagram-COXZFDF6-mGgPoETt.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-CSL1-s5L.js → kanban-definition-P3RFRI5V-j2hU8Bw4.js} +1 -1
- package/dist/assets/{kit-Cjq8TV0N.js → kit-qjammJR4.js} +1 -1
- package/dist/assets/{ko-ebMBLBXv.js → ko-7QtaPFvf.js} +2 -2
- package/dist/assets/{livekit-KT4NEVZO-B3DA1PsD.js → livekit-KT4NEVZO-DbFoU2r9.js} +1 -1
- package/dist/assets/{mcp-servers-DoMFsds6.js → mcp-servers-Tb2cnkiM.js} +1 -1
- package/dist/assets/{memory-BR-ujoQY.js → memory-BNaMRI5v.js} +1 -1
- package/dist/assets/{mermaid.core-BK1qxlD4.js → mermaid.core-B1mlFiOp.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-Cb7ESZ0y.js → mindmap-definition-LZFPQGKD-C7XLkIzZ.js} +1 -1
- package/dist/assets/{minimize-msM7mbil.js → minimize-Dga3UCb8.js} +1 -1
- package/dist/assets/{monitor-DpsqT1_R.js → monitor-DMPjQDZP.js} +1 -1
- package/dist/assets/{org-library-alRyzCTE.js → org-library-IKFXm7D6.js} +1 -1
- package/dist/assets/{package-format-BFXbXHk8.js → package-format-COujx3jP.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-CqmJQKhe.js → pegDiagram-BGZESJAR-BS2zKH6g.js} +1 -1
- package/dist/assets/{phones-J7mYR-fY.js → phones-CINpTjZv.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-w_QuumOv.js → pieDiagram-CAPJLFHJ-DVAuLXem.js} +1 -1
- package/dist/assets/{pl-CSbinyb5.js → pl-CLa2ta1_.js} +2 -2
- package/dist/assets/{pt-br-BkWykL5e.js → pt-br-8RQzCbpg.js} +3 -3
- package/dist/assets/{quadrantDiagram-GDMTTRAM-248q9C3h.js → quadrantDiagram-GDMTTRAM-H7QRxmHt.js} +1 -1
- package/dist/assets/{rail-DRr_33Fe.js → rail-DNpLzOxa.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-BLzQ_5t7.js → railroadDiagram-SM67HX2B-dq6Rokc9.js} +1 -1
- package/dist/assets/{remote-desktop-panel-BPK6Q0O6.js → remote-desktop-panel-Cxv6Qt3x.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-Bgi1TLdN.js → requirementDiagram-X7JNWC4A-BeWeL_-r.js} +1 -1
- package/dist/assets/{ru-DD01Hb1S.js → ru-CIdzvRVZ.js} +2 -2
- package/dist/assets/{sankeyDiagram-UM26HJRW-CrZgn-Cf.js → sankeyDiagram-UM26HJRW-BmJ-9lt-.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-gAwq1ZfG.js → sequenceDiagram-ZO4K6R2Y-Uuh1hEOh.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BlXmG_DJ.js → sizeCapture-INFHLROL-mKDf6lys.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-CEFB1Iaq.js → stateDiagram-v2-TBUQTH76-BaEihzov.js} +1 -1
- package/dist/assets/{styles-DOJOOIp4.js → styles-3g-ZPS7M.js} +5 -5
- package/dist/assets/styles-CsrDURJH.css +1 -0
- package/dist/assets/{swimlanes-N4OXWK64-BtJmWAOz.js → swimlanes-N4OXWK64-CpP-NKGz.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-C50Dm6LQ.js +8 -0
- package/dist/assets/{template-add-BcTS64TG.js → template-add-CHwGLPet.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-BZ270zxf.js → timeline-definition-YOQAKGHF-Ca3rjetv.js} +1 -1
- package/dist/assets/{tr-Bw35A32w.js → tr-BhclavHM.js} +1 -1
- package/dist/assets/{uk-DsPsCgp4.js → uk-Or5wmf6s.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-D5yZb3KQ.js → usecaseDiagram-VIAY4XPW-BuuYl689.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-OFx2qTzp.js → vennDiagram-BLWOH2XV-C__pWnnE.js} +1 -1
- package/dist/assets/{vi-DhPdzwW-.js → vi-CYbGVqh-.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-DzSmrVKa.js → wardleyDiagram-YMQ3BMBF-yWcEHD-N.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-UP1H1u5V.js → xychartDiagram-TAQBALBS-CvcdOA7A.js} +1 -1
- package/dist/assets/{zh-CzC3CUQA.js → zh-iptM1e_T.js} +2 -2
- package/dist/assets/{zh-tw-DeXHnAvy.js → zh-tw-BaO1c--E.js} +2 -2
- package/dist/index.html +3 -3
- package/dist/rail.html +5 -5
- package/dist-server/container-mcp.js +18 -17
- package/dist-server/index.js +1136 -1114
- package/dist-server/openmausbot.js +182 -180
- package/dist-server/package.json +1 -1
- package/dist-server/pair-cli.js +182 -180
- package/dist-server/server/ai-pool.js +72 -0
- package/dist-server/server/cloud-connected-apps.js +33 -16
- package/dist-server/server/composio-broker-access.js +1 -1
- package/dist-server/server/composio.js +3 -2
- package/dist-server/server/config.js +5 -7
- package/dist-server/server/connector-auth-config-hint.js +5 -0
- package/dist-server/server/drivers/claude.js +14 -11
- package/dist-server/server/flatpak-host.js +5 -2
- package/dist-server/server/host/ai-pool.js +109 -0
- package/dist-server/server/host/app-suggestions.js +2 -1
- package/dist-server/server/host/limit-takeover.js +11 -4
- package/dist-server/server/index.js +33 -26
- package/dist-server/server/limit-failover.js +3 -0
- package/dist-server/server/model-selection-schema.js +9 -0
- package/dist-server/server/routes/ai-pool-patch.js +24 -0
- package/dist-server/server/routes/config.js +8 -1
- package/dist-server/server/routine-dispatch.js +21 -0
- package/dist-server/server/routines.js +4 -18
- package/dist-server/server/tailscale.js +16 -6
- package/dist-server/server/workspace-backup-http.js +2 -2
- package/dist-server/shared/limit-backup.js +1 -1
- package/dist-server/shared/settings-places.js +1 -0
- package/dist-server/shared/toolkit-card.js +1 -0
- package/dist-server/vps-container-mcp.js +18 -17
- package/dist-server/workspace-backup.worker.js +18 -17
- package/package.json +1 -1
- package/dist/assets/PluginsPanel-B5Q70eO8.js +0 -8
- package/dist/assets/RoutinesPage-CLXohizn.js +0 -2
- package/dist/assets/SettingsModal-BlX9XoBu.js +0 -2
- package/dist/assets/channel-DZM5KU--.js +0 -1
- package/dist/assets/styles-9UFSdSaJ.css +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-pBTtzroP.js +0 -8
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as cl,r as o,j as e,a as z,t,w as He,X as Oe,y as Ks,aC as Ni,aD as dl,aX as ul,ar as Mt,aJ as $t,d as Yt,aY as Si,q as ke,ae as pl,L as at,aZ as ml,b as Ee,a_ as xl,g as En,a$ as gl,aE as hl,b0 as fl,b1 as bl,b2 as vl,b3 as Ci,ah as yl,b4 as An,Y as jl,b5 as Ws,b6 as kl,b7 as wl,b8 as Nl,b9 as Sl,ba as Cl,aH as El,bb as Pn,aG as Al,I as Pl,bc as Tl,H as Il,bd as Ll,be as Rl,bf as Bl,bg as Ol,A as Fl,B as Ul,bh as Ml,bi as Dl,bj as zl,bk as _l,i as Gs,aL as Hl,bl as ft,bm as $l,bn as Tn,bo as In,bp as Ln,bq as Kl,br as Wl,bs as Gl,az as Rn,F as ql,aw as Vl,G as Bn,aA as Ei,e as On,bt as Fn,o as Ps,bu as Jl,C as Ai,an as qs,ad as Yl,bv as Pi,S as Ti,bw as Xl,v as Ii}from"./styles-3g-ZPS7M.js";import{L as ce,P as Ke,j as Xt,C as Vs,k as Ql,X as Zl,Y as Li,r as eo,c as Ri,A as to,Z as so,R as no,O as ao,B as Qt,F as Bi,v as io,_ as ro,$ as Un,b as lo,f as Oi,a as oo,g as co}from"./PlacesRail-Df-jNTHn.js";import{al as $e,g as D,ew as uo,y as de,bG as po,ev as xe,gk as it,gl as rt,hC as mo,u as _,C as Fi,au as kt,fP as Js,hD as Ts,aI as L,hE as Ys,hF as Xs,hG as Ui,hH as xo,hI as go,hJ as Qs,hK as ho,S as ie,hL as Dt,hM as fo,bb as Zs,hN as Mi,hO as Is,hP as Di,b4 as Y,b5 as J,hQ as Je,hR as Mn,hS as bo,hT as vo,hU as yo,hV as jo,hW as ko,hX as wo,hY as ms,hZ as zi,h as je,h_ as No,c as Dn,dX as So,h$ as Co,em as Eo,i0 as Ao,c8 as Po,et as ze,cq as wt,b9 as fe,b7 as he,i1 as To,i2 as Io,i3 as Lo,i4 as Ro,i5 as Bo,i6 as Oo,i7 as Fo,i8 as Uo,i9 as Mo,e4 as Zt,e3 as Do,dM as zo,ia as Nt,e2 as _o,fO as en,ib as Ho,ic as $o,id as Ko,ie as Re,ig as zn,ih as _n,ii as Wo,ij as Go,ik as _i,il as qo,im as Vo,io as Jo,ip as Yo,iq as Xo,ir as Qo,is as Zo,e as Hi,it as Hn,iu as ec,iv as tc,iw as sc,ix as nc,iy as ac,iz as ic,iA as $n,iB as rc,iC as lc,gC as oc,iD as cc,iE as $i,a4 as dc,b6 as Se,iF as es,iG as uc,iH as pc,iI as mc,iJ as xc,iK as gc,iL as Kn,g4 as hc,b8 as St,b0 as Ae,iM as fc,iN as bc,a8 as Ki,r as vc,at as Wi,g5 as yc,iO as ts,iP as Gi,iQ as jc,iR as kc,iS as Wn,iT as qi,iU as ss,iV as Vi,iW as wc,iX as Nc,iY as Gn,iZ as Sc,i_ as Cc,i$ as qn,j0 as Ec,bZ as Vn,ck as Ls,j1 as Jn,j2 as Yn,j3 as Ac,j4 as Pc,j5 as Tc,j6 as Xn,j7 as Ic,dm as Lc,j8 as Rc,j9 as Bc,ja as Oc,cj as Fc,jb as Uc,jc as Mc,jd as Ji,je as Yi,jf as Dc,T as We,gh as ns,l as zc,jg as Qn,z as Zn,jh as Xi,ji as ea,jj as ta,jk as _c,jl as Hc,gi as nt,jm as as,jn as $c,jo as Kc,jp as Wc,jq as Gc,jr as lt,dL as Qi,js as qc,jt as Vc,ju as Jc,jv as Yc,jw as xs,jx as Xc,jy as Qc,jz as Zc,gE as ed,jA as sa,jB as td,jC as sd,dP as nd,jD as na,jE as ad,jF as id,dK as rd,jG as ld,jH as od,jI as cd,jJ as dd,jK as ud,jL as pd,jM as md,gO as xd,cw as Ye,el as Rs,eX as gd,fY as Zi,jN as er,jO as Bs,af as hd,dQ as fd,jP as bd,jQ as vd,jR as yd,jS as jd,jT as kd,jU as wd,jV as tr,jW as Nd,jX as sr,jY as tn,i as Sd,jZ as Cd,j_ as Ed,j$ as Ad,k0 as Pd,k1 as Td,k2 as Id,k3 as Ld,k4 as sn,a9 as Rd,cN as Bd,ci as Ve,e_ as ot,k5 as Od,eY as Fd,eZ as Ud,k6 as ht,k7 as mt,k8 as Md,k9 as nr,ka as ar,kb as nn,kc as Dd,ed as aa,kd as ir,ke as rr,kf as lr,kg as zd,kh as _d,ki as Hd,kj as $d,A as Kd,kk as Wd,kl as Gd,km as qd,kn as Vd,f5 as Jd,ko as Yd,kp as or,gq as Xd,kq as Qd,kr as Zd,ks as eu,kt as tu,ku as ia,kv as su,fi as nu,kw as au}from"./App-h8WTNY4l.js";import{r as iu,C as ru,s as cr,b as lu,c as ou,w as cu,d as du,T as uu,l as an,e as ra,f as la,g as pu,h as dr}from"./index-DtDQrExn.js";import{c as oa,b as Lt,S as rn,P as mu,a as xu,d as gu,e as ca}from"./ServerPairingCard-D21dP5Bc.js";import"./phones-CINpTjZv.js";import{R as bt,C as Ct,i as ur}from"./MenuMotion-CHp-hB40.js";import{P as hu}from"./ProIntroduction-D8hWm9R5.js";import{B as fu}from"./BrowserProfilesManager-haN8RgPf.js";import{r as pr}from"./memory-BNaMRI5v.js";import{c as bu,A as da,w as vu,d as yu,e as ua}from"./activity-l0oTqbd6.js";import{A as vt,C as ju,E as ku}from"./EnginesSettings-C27xDaBN.js";import{M as wu,w as Nu}from"./MacLocalControl-BeNWQ9oY.js";import{DefaultBotSettings as Su}from"./NewBotDialog-BxeQktoI.js";import"./placement-BKtVnQht.js";import"./monitor-DMPjQDZP.js";import"./SignedInSites-CFyvOLSc.js";import"./VisibilitySection-CFr6fOzq.js";import"./org-library-IKFXm7D6.js";import"./package-format-COujx3jP.js";import"./mcp-servers-Tb2cnkiM.js";import"./WorksOnGrid-B3wYro9M.js";import"./RoutinesPage-B9kKyfFp.js";import"./remote-desktop-CsSfkXSy.js";const Cu=[["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"}]],Eu=cl("unplug",Cu);function Au(s,n){const a=s&&!window.ogb?.remoteClient?.active?window.ogb?.cloudAccount:void 0,[i,r]=o.useState(null),c=a?.offer?JSON.stringify(n??null):null;return o.useEffect(()=>{if(c===null||!a?.offer)return;let l=!0;return a.offer().then(d=>{l&&r(d)},()=>{}),()=>{l=!1}},[a,c]),a?.offer?i:null}function Pu(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 Tu({config:s}){const n=Pu(s);return n?e.jsxs("div",{role:"status",className:z("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($e,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function Iu(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 pa(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 Lu(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function ma(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function Ru(s,n,a){const i=[],r=new Set,c=(l,d)=>{const u=l.trim().toLowerCase();if(!u||r.has(u))return;r.add(u);const p=n.filter(m=>m.email?.toLowerCase()===u),x=a.find(m=>m.key===`user:${u}`);i.push({entry:u,role:d,isDomain:u.startsWith("@"),lastSeenAt:p.length?Math.max(...p.map(m=>m.lastSeenAt)):null,devices:p.length,turns:x?.turns??0,costUsd:x?.costUsd??null,...it(x?.estimatedUsd)&&x.estimatedUsd>0?{estimated:!0}:{}})};for(const l of s.admins)c(l,"admin");for(const l of s.members)c(l,"member");return i}function Bu(s,n){const a=new Map;for(const i of s){const r=i.email?.trim().toLowerCase();r&&a.set(r,[...a.get(r)??[],i])}return[...a.entries()].map(([i,r])=>{const c=n.find(l=>l.key===`user:${i}`);return{entry:i,role:r.some(l=>l.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(l=>l.lastSeenAt)),devices:r.length,turns:c?.turns??0,costUsd:c?.costUsd??null}}).sort((i,r)=>i.role===r.role?i.entry.localeCompare(r.entry):i.role==="admin"?-1:1)}function Ou(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 mr({people:s,busy:n,onRole:a,onRemove:i,onLink:r,readOnly:c=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c?"people.portal.empty":"people.empty")});const l="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:z(l,"border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(d=>e.jsxs("div",{className:z(l,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:d.isDomain?t("people.everyoneAt",{domain:d.entry.slice(1)}):d.entry}),d.devices>0&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("people.devices",{count:String(d.devices)})})]}),e.jsx("span",{className:z("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?"—":Ou(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:it(d.costUsd)?`${d.estimated?"~":""}${rt(d.costUsd)}`:"—"}),c?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>r(d),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(mo,{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 xr({link:s}){const{state:n,copy:a}=Xt(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(He,{size:13,className:"text-success"}):n==="failed"?e.jsx(Oe,{size:13,className:"text-danger"}):e.jsx(Vs,{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 Fu({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(xe,{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(Ql,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(mr,{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 Uu({simple:s=!1,startOpen:n=!1}){const[a,i]=o.useState(n),[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(null),[g,f]=o.useState([]),[h,j]=o.useState(typeof window<"u"?window.location.origin:""),[b,y]=o.useState(null),[v,w]=o.useState(""),[N,C]=o.useState("member"),[T,F]=o.useState(null),[k,S]=o.useState(!1),[P,E]=o.useState(!1),[A,V]=o.useState(null),R=o.useCallback(async()=>{E(!0),V(null);try{const[X,B,W,G,oe]=await Promise.all([D("/api/config"),D("/api/auth/sessions").catch(()=>({sessions:[]})),D("/api/usage?groupBy=user").catch(()=>({groups:[]})),D("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(O=>O.ok?O.json():null).catch(()=>null)]),M={admins:Array.isArray(X?.signIn?.admins)?X.signIn.admins:[],members:Array.isArray(X?.signIn?.members)?X.signIn.members:[]},$=uo(X);p($),m(M);const Z=Array.isArray(B?.sessions)?B.sessions:[],ee=Array.isArray(W?.groups)?W.groups:[];f($.authority==="portal"?Bu(Z,ee):Ru(M,Z,ee)),typeof G?.publicUrl=="string"&&G.publicUrl&&j(G.publicUrl),y(oe?.capabilities?.emailSignIn===!0?!0:oe?!1:null)}catch(X){V(X instanceof Error?X.message:String(X))}finally{E(!1)}},[]);o.useEffect(()=>{iu().then(X=>{d(X),oa(X)&&R()})},[R]);const K=async X=>{S(!0),V(null);try{await D("/api/config",{method:"PUT",body:JSON.stringify({signIn:X})}),await R()}catch(B){V(B instanceof Error?B.message:String(B))}finally{S(!1)}},te=async()=>{if(c(!0),!x||k)return;const X=Iu(v);if(!X){V(t("remote.signInAccess.invalid"));return}await K(pa(x,X,N)),w(""),F(ma(h,X))};if(!oa(l))return null;const ue=u?.authority==="portal"?e.jsx(Fu,{peopleUrl:u.peopleUrl,people:g}):null,ae=e.jsxs(e.Fragment,{children:[b===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(u?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:X=>{X.preventDefault(),te()},children:[e.jsx("input",{value:v,onChange:X=>w(X.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:k,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(de,{value:N,onChange:X=>C(X.target.value),"aria-label":t("people.colRole"),disabled:k,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:k||!v.trim(),className:"ui-button ui-button-primary",children:[k?e.jsx(ce,{size:13,className:"animate-spin"}):e.jsx(Ke,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:P||k,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(bt,{size:13,className:z(P&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),T&&e.jsx(xr,{link:T}),A&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:A}),e.jsx("div",{className:"mt-4",children:e.jsx(mr,{people:g,busy:k,onRole:(X,B)=>{x&&K(pa(x,X.entry,B))},onRemove:X=>{x&&K(Lu(x,X.entry))},onLink:X=>F(ma(h,X.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(po,{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:ue??ae})]}):ue??e.jsx(xe,{title:t("people.title"),subtitle:t("people.subtitle"),children:ae})}function gr(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Mu=()=>D("/api/fleet");function Du({fleet:s,onAct:n,busy:a}){return s.workspaces.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("workspaces.empty",{domain:s.domain})}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] gap-x-5 border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("workspaces.colWorkspace")}),e.jsx("span",{className:"text-right",children:t("workspaces.colState")}),e.jsx("span",{className:"text-right",children:t("workspaces.colMonth")}),e.jsx("span",{})]}),s.workspaces.map(i=>{const r=i.status==="suspended",c=i.status==="running"||r,l=i.status==="provisioning"?t("workspaces.provisioning"):i.status==="error"?t("workspaces.error"):i.status==="retained"?t("workspaces.retained"):r?t("workspaces.suspended"):i.live==="active"?t("workspaces.running"):i.live;return e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5 border-b border-hairline/20 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:i.slug}),e.jsx("a",{href:`https://${i.host}`,target:"_blank",rel:"noreferrer",className:"block truncate text-[12px] text-accent hover:underline",children:i.host}),!c&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("workspaces.recoveryHint")})]}),e.jsx("span",{className:z("text-right",r||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:l}),e.jsxs("span",{className:"text-right tabular-nums text-ink",title:i.usage.turns===null?void 0:t("workspaces.turns",{turns:String(i.usage.turns)}),children:[it(i.usage.costUsd)?rt(i.usage.costUsd):"—",it(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",rt(i.usage.billableUsd)]})]}),e.jsx("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"users"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:t("workspaces.users")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,r?"resume":"suspend"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:r?t("workspaces.resume"):t("workspaces.suspend")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"delete"),className:"text-danger hover:underline disabled:opacity-50",children:t("workspaces.delete")})]})})]},i.slug)})]})}function zu({domain:s,onCreated:n,disabled:a}){const[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(""),[m,g]=o.useState(""),[f,h]=o.useState(!1),[j,b]=o.useState(null),y=async()=>{if(!f){h(!0),b(null);try{const w={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(C=>C.trim()).filter(Boolean),...p.trim()?{cap:Number(p)}:{},...m.trim()?{anthropicKey:m.trim()}:{}},N=await D("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});r(""),l(""),u(""),x(""),g(""),n(N.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){b(w instanceof Error?w.message:String(w))}finally{h(!1)}}},v="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50";return e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:w=>{w.preventDefault(),y()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:w=>r(w.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||f,"aria-label":t("workspaces.name"),className:v}),e.jsxs("span",{className:"whitespace-nowrap text-[12px] text-ink-secondary",children:[".",s]})]})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.adminEmail"),e.jsx("input",{value:c,onChange:w=>l(w.target.value),type:"email",required:!0,disabled:a||f,"aria-label":t("workspaces.adminEmail"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.members"),e.jsx("input",{value:d,onChange:w=>u(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||f,"aria-label":t("workspaces.members"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:p,onChange:w=>x(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||f,"aria-label":t("workspaces.cap"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary sm:col-span-2",children:[t("workspaces.anthropicKey"),e.jsx("input",{value:m,onChange:w=>g(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||f,"aria-label":t("workspaces.anthropicKey"),className:v})]})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),j&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:j}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||f,className:"ui-button ui-button-primary",children:[f?e.jsx(ce,{size:13,className:"animate-spin"}):e.jsx(Ke,{size:13}),f?t("workspaces.creating"):t("workspaces.create")]})})]})}function _u({slug:s,onDone:n}){const[a,i]=o.useState(""),[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),x=async m=>{if(!l){d(m),p(null);try{const g=await D(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:m,email:a.trim(),chatOnly:r})});i(""),n(g.log??[])}catch(g){p(g instanceof Error?g.message:String(g))}finally{d(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:t("workspaces.usersTitle",{slug:s})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:a,onChange:m=>i(m.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:l!==null,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:m=>c(m.target.checked),disabled:l!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:l!==null||!a.trim(),onClick:()=>{x("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:l==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:l!==null||!a.trim(),onClick:()=>{x("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:l==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function Hu({load:s=Mu}){const{state:n}=_(),[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(null),[x,m]=o.useState([]),[g,f]=o.useState(null),[h,j]=o.useState(null),[b,y]=o.useState(!1),[v,w]=o.useState(null),N=o.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(k){c(k instanceof Error?k.message:String(k))}finally{d(!1)}},[s]);o.useEffect(()=>{N()},[N]);const C=async(k,S)=>{if(S==="users"){f(P=>P===k?null:k);return}if(S==="delete"){j({slug:k,keepData:!1});return}p(k),c(null);try{const P=await D(`/api/fleet/workspaces/${encodeURIComponent(k)}/${S}`,{method:"POST"});m(P.log??[]),await N()}catch(P){c(P instanceof Error?P.message:String(P))}finally{p(null)}},T=async()=>{if(!h)return;const{slug:k,keepData:S}=h;j(null),p(k),c(null);try{const P=await D(`/api/fleet/workspaces/${encodeURIComponent(k)}`,{method:"DELETE",body:JSON.stringify({keepData:S})});m(P.log??[]),await N()}catch(P){c(P instanceof Error?P.message:String(P))}finally{p(null)}},F=async()=>{p("*"),c(null);try{const k=await D("/api/fleet/upgrade",{method:"POST"});m(k.log??[t("workspaces.upgraded")]),await N()}catch(k){c(k instanceof Error?k.message:String(k))}finally{p(null)}};return gr(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(xe,{title:t("workspaces.title"),subtitle:t("workspaces.subtitle"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:l||u!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(bt,{size:12,className:z(l&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>y(k=>!k),disabled:u!==null,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx(Ke,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{F()},disabled:u!==null||!a?.workspaces.length,className:"rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:u==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),b&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(zu,{domain:a.domain,disabled:u!==null,onCreated:(k,S)=>{y(!1),m(k),w(`https://${S.slug}.${a.domain}/pair?email=${encodeURIComponent(S.admin)}`),N()}})}),v&&e.jsx("div",{className:"mb-4",children:e.jsx(xr,{link:v})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(Du,{fleet:a,onAct:(k,S)=>{C(k,S)},busy:u}):l?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ce,{size:14,className:"animate-spin"}),t("common.checking")]}):null,g&&e.jsx(_u,{slug:g,onDone:k=>{m(k),N()}}),x.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[12px] text-ink-secondary",children:x.join(`
|
|
2
|
+
`)})]}),e.jsx(Fi,{open:h!==null,title:t("workspaces.deleteTitle",{slug:h?.slug??""}),body:t(h?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>j(null),onConfirm:()=>{T()}}),h&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:h.keepData,onChange:k=>j({...h,keepData:k.target.checked})}),t("workspaces.keepData")]})]}):null}function $u(){const{state:s}=_(),n=Ks(),a=kt()===!0,i=Ni(),r=Ku(),c=typeof window>"u"?void 0:window.ogb,l=c?.remoteClient?.active===!0,d=s.config?.cloudHome===!0,u=!!s.config?.team,p=!!c;return{desktop:p,here:Ts(),home:Ts()||!!c?.home,cloud:d,team:u,client:l,admin:a,places:r>1||!c?.environments&&dl(i),plan:p?!!(c?.cloudAccount||c?.cloudPlan&&d):d&&!u&&a,organization:!!c?.organization&&!l,environments:!!c?.environments,installations:gr(s.config),skills:Js(s.config),advanced:n}}function Ku(){const[s,n]=o.useState(0);return o.useEffect(()=>{const a=window.ogb?.remoteClient?.active?void 0:window.ogb?.environments;if(!a)return;let i=!0;return a.state().then(r=>{i&&n(r?.environments?.length??0)}).catch(()=>{}),()=>{i=!1}},[]),s}function Et(s){const{places:n}=Ni(),[a,i]=o.useState([]),r=typeof window>"u"||window.ogb?.remoteClient?.active?void 0:window.ogb?.environments;o.useEffect(()=>{if(!r||n.length>0)return;let d=!0;return r.state().then(u=>{!d||!u||i(u.environments.filter(p=>p.id!==u.activeId).map(p=>({key:p.id,name:p.kind==="local"&&!p.dataDir?t("rail.thisComputer"):p.name,kind:p.kind==="remote"?"cloud":"computer",color:p.color??null,open:()=>{r.switch(p.id)}})))}).catch(()=>{}),()=>{d=!1}},[r,n.length]);const c=typeof window>"u"?void 0:window.ogb?.workspaces?.open;if(n.length>0)return n.filter(d=>!d.active).map(d=>({key:d.id,name:d.name,kind:d.kind,color:d.color??null,open:()=>{c?.(d.id)}}));const l=typeof window>"u"||window.ogb?.remoteClient?.active?void 0:window.ogb?.rail?.openComputer;return a.length===0&&l&&!Ts()?[{key:"computer",name:t("rail.thisComputer"),kind:"computer",color:null,open:()=>{l(s).catch(()=>{})}}]:a}const Kt=(s=ul())=>t("settings.overview.version",{version:s}),ln=o.createContext(null);function Ne(){const s=o.useContext(ln);if(!s)throw new Error("useSettingsShell outside Settings");return s}function At(){const s=o.useContext(ln)?.page,a=Et(s).find(i=>i.kind==="computer");return{name:a?.name??t("rail.thisComputer"),open:a?.open??null}}function Wu({reason:s}){const n=At();return e.jsxs(e.Fragment,{children:[s??t("settings.inert.fromHere",{place:n.name}),n.open&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",onClick:n.open,children:t("settings.inert.switchHere",{place:n.name})})]})]})}function ct({title:s,subtitle:n,control:a,reason:i}){const r=At(),c=i??t("settings.inert.fromHere",{place:r.name});return e.jsx(L,{title:s,subtitle:n,inert:e.jsx(Wu,{reason:i}),inertText:c,children:a??null})}const Gu="relative flex h-8 w-full shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2 text-left text-[13px] leading-5 text-ink transition-colors motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus";function De({place:s,size:n}){if(pl(s.color))return e.jsx(Li,{place:{kind:s.kind==="server"?"cloud":s.kind,name:s.name,color:s.color,...s.named?{named:!0}:{}},size:n});const a=n<=14?10:n<=20?12:14;return e.jsx("span",{"aria-hidden":"true","data-place-badge":s.kind,className:"grid shrink-0 place-items-center bg-ink/[0.06] font-semibold leading-none text-ink-secondary shadow-[inset_0_0_0_0.5px_var(--settings-edge)]",style:{width:n,height:n,borderRadius:Math.round(n*.3),fontSize:Math.max(7,Math.round(n*.4))},children:s.kind==="computer"&&!s.named?e.jsx(at,{size:a,strokeWidth:1.75}):ml(s.name)})}function hr({size:s}){return e.jsxs("span",{className:"relative shrink-0",style:{width:s,height:s},children:[e.jsx("img",{src:"/app-icon.svg",alt:"",width:s,height:s,className:"rounded-[6px]",style:{width:s,height:s}}),e.jsx("span",{"aria-hidden":"true",className:"absolute inset-0 rounded-[6px] shadow-[inset_0_0_0_0.5px_var(--settings-edge)]"})]})}function Wt({size:s}){const{profile:n}=Xs();return e.jsx(Zl,{initials:Mi(n),avatarUrl:n?.avatarUrl,size:s,fontSize:Math.round(s*.42),className:"bg-ink/[0.08]"})}function qu(s){const{state:n}=_();if(Qs()?.status==="downloaded"&&s.kind==="computer")return t("sidebar.update.readyShort");if(s.kind==="computer"){const i=n.bots.length;return i===0?t("settings.place.botsNone"):i===1?t("settings.place.botsOne"):t("settings.place.botsMany",{count:i})}return s.kind==="server"?t("settings.place.running"):t("settings.place.alwaysOn")}function Vu(s){const n=Qs();return s?n?.status==="downloaded"?t("settings.app.updateReadyLine",{version:$t()}):t("settings.app.upToDateLine",{version:$t()}):t("settings.scope.browser")}function on(s,n,a){return s==="place"?n.name:s==="account"?t("settings.page.account"):a?t("settings.page.app"):t("settings.page.browser")}function xt(s,n,a){return s.id==="overview"?n.name:s.id==="account"||s.id==="app"?on(s.owner,n,a):t(s.labelKey)}function Ju({page:s,current:n,badge:a,name:i,line:r,onOpen:c,narrow:l}){return e.jsxs("button",{type:"button","data-settings-page":s,"data-settings-section":s,"data-settings-identity":"","aria-current":n?"page":void 0,onClick:c,className:z("flex w-full shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2 py-1 text-left",l?"h-12":"h-11"," transition-colors motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",n?"bg-menu-active":"hover:bg-menu-hover"),children:[e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-[6px]",children:a}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-[14px] font-medium leading-[18px] text-ink",children:i}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:r})]}),l&&e.jsx(Ct,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary rtl:-scale-x-100"})]})}function Yu({page:s,label:n,current:a,dot:i,onOpen:r}){const c=s.icon;return e.jsxs("button",{type:"button","data-settings-page":s.id,"data-settings-section":s.id,"aria-current":a?"page":void 0,onClick:r,className:z(Gu,a?"bg-menu-active font-medium":"hover:bg-menu-hover"),children:[e.jsx("span",{className:"flex w-6 shrink-0 justify-center",children:c&&e.jsx(c,{size:16,strokeWidth:1.75,"aria-hidden":"true",className:a?"text-ink":"text-ink-secondary"})}),e.jsxs("span",{className:"grid min-w-0 flex-1 grid-cols-[minmax(0,1fr)] overflow-hidden",title:n,children:[e.jsx("span",{className:"min-w-0 overflow-hidden text-ellipsis whitespace-nowrap [grid-area:1/1]",children:n}),e.jsx("span",{"aria-hidden":"true",className:"invisible h-0 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap font-medium [grid-area:1/1]",children:n})]}),i&&e.jsx("span",{"aria-hidden":"true",className:z("size-1.5 shrink-0 rounded-full",i==="success"?"bg-success":"bg-warning")})]})}function Xu({query:s,onQuery:n,onClose:a,onFirst:i}){return e.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 rounded-lg border-[0.5px] border-(--settings-edge) px-2 focus-within:border-ink/25",children:[e.jsx(Yt,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary"}),e.jsx("input",{"data-settings-search":!0,value:s,onChange:r=>n(r.target.value),onKeyDown:r=>{if(r.key==="ArrowDown"){r.preventDefault(),i();return}r.key==="Escape"&&(r.stopPropagation(),s?n(""):a())},placeholder:t("settings.searchAria"),"aria-label":t("settings.searchAria"),className:"h-full w-full min-w-0 text-ellipsis bg-transparent text-[13px] leading-5 text-ink outline-none placeholder:text-ink-tertiary"}),s?e.jsx("button",{type:"button","aria-label":t("settings.search.clear"),onClick:()=>n(""),className:"flex size-4 shrink-0 cursor-pointer items-center justify-center text-ink-tertiary hover:text-ink",children:e.jsx(Oe,{size:12,"aria-hidden":"true"})}):e.jsx("kbd",{"aria-hidden":"true",className:"flex size-4 shrink-0 items-center justify-center rounded-[4px] border-[0.5px] border-(--settings-edge) font-sans text-[11px] font-medium leading-4 text-ink-tertiary",children:"/"})]})}function Qu(s){if(!["ArrowDown","ArrowUp","Home","End"].includes(s.key))return;const n=[...s.currentTarget.querySelectorAll("button[data-settings-page], button[data-settings-hit]")],a=n.indexOf(document.activeElement);if(a<0&&s.key!=="Home"&&s.key!=="End")return;s.preventDefault();const i=s.key==="Home"?0:s.key==="End"?n.length-1:s.key==="ArrowDown"?Math.min(n.length-1,a+1):Math.max(0,a-1);n[i]?.focus()}function Zu({ctx:s,place:n,pages:a,current:i,query:r,hits:c,keyHits:l,onKey:d,onQuery:u,onOpen:p,onHit:x,onClose:m,narrow:g,onAdvanced:f=Mt}){const h=Ys(),{profile:j}=Xs(),b={...h,email:h.email??(h.plan?j?.email??null:null)},y=qu(n),v=Vu(s.desktop),w=Ui(!s.client),N=o.useRef(null),C=s.desktop&&!window.ogb?.cloudAccount&&!window.ogb?.cloudPlan,T={place:{badge:e.jsx(De,{place:n,size:24}),name:n.name,line:y,page:"overview"},account:{badge:e.jsx(Wt,{size:24}),name:t("settings.page.account"),line:xo(b,{browser:!s.desktop,place:n.name,openSource:C}),page:"account"},app:{badge:e.jsx(hr,{size:24}),name:s.desktop?t("settings.page.app"):t("settings.page.browser"),line:v,page:"app"}},F=S=>S==="phone"&&w.kind==="paired"&&w.connected?"success":S==="phone"&&w.kind==="attention"?"warning":null,k=r.trim()!=="";return e.jsxs("nav",{"aria-label":t("settings.title"),className:z("flex min-h-0 flex-col",g?"flex-1":"w-[220px] shrink-0 shadow-[inset_-0.5px_0_0_var(--settings-edge)]"),children:[e.jsx("div",{className:z("shrink-0",g?"px-4 pb-2":"p-3 pb-0"),children:e.jsx(Xu,{query:r,onQuery:u,onClose:m,onFirst:()=>N.current?.querySelector("button[data-settings-hit], button[data-settings-page]")?.focus()})}),e.jsx("div",{ref:N,onKeyDown:Qu,className:z("settings-scroll flex min-h-0 flex-1 flex-col overflow-y-auto",g?"px-2 pb-4 pt-1":"px-3 pb-3 pt-3"),children:k?e.jsx(tp,{ctx:s,place:n,hits:c,keyHits:l,onKey:d,query:r,onHit:x}):go.map((S,P)=>{const E=a.filter(V=>V.owner===S&&V.id!==T[S].page),A=T[S];return e.jsxs("div",{role:"group","aria-label":A.name,"data-settings-group":S,className:z("flex flex-col gap-0.5",P>0&&"mt-4"),children:[e.jsx(Ju,{page:A.page,current:i===A.page,badge:A.badge,name:A.name,line:A.line,narrow:g,onOpen:()=>p(A.page)}),e.jsx("div",{className:"mt-0.5 flex flex-col gap-0.5",children:E.map(V=>g?e.jsxs("button",{type:"button","data-settings-page":V.id,"data-settings-section":V.id,onClick:()=>p(V.id),className:"flex h-11 w-full cursor-pointer items-center gap-2 rounded-lg px-2 text-left text-[14px] leading-5 text-ink hover:bg-menu-hover",children:[e.jsx("span",{className:"flex w-6 shrink-0 justify-center",children:V.icon&&e.jsx(V.icon,{size:16,strokeWidth:1.75,"aria-hidden":"true",className:"text-ink-secondary"})}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t(V.labelKey)}),F(V.id)&&e.jsx("span",{"aria-hidden":"true",className:z("size-1.5 rounded-full",F(V.id)==="success"?"bg-success":"bg-warning")}),e.jsx(Ct,{size:14,"aria-hidden":"true",className:"text-ink-tertiary rtl:-scale-x-100"})]},V.id):e.jsx(Yu,{page:V,label:t(V.labelKey),current:i===V.id,dot:F(V.id),onOpen:()=>p(V.id)},V.id))})]},S)})}),e.jsx(ep,{narrow:g,onChange:f})]})}function ep({narrow:s,onChange:n}){const a=Ks();return e.jsxs("div",{"data-settings-block":"advanced-mode",title:t("settings.advancedMode.tooltip"),className:z("flex h-12 shrink-0 items-center justify-between gap-3 shadow-[inset_0_0.5px_0_var(--settings-edge)]",s?"px-4":"px-5"),children:[e.jsx("span",{id:"settings-advanced-mode",className:"text-[13px] leading-5 text-ink",children:t("settings.advancedMode.title")}),e.jsx(ie,{checked:a,"aria-labelledby":"settings-advanced-mode","data-settings-advanced-switch":"",onClick:()=>n(!a)})]})}function tp({ctx:s,place:n,hits:a,keyHits:i,onKey:r,query:c,onHit:l}){const d=a.filter(p=>!p.elsewhere).slice(0,8),u=a.filter(p=>p.elsewhere).slice(0,8);return d.length===0&&u.length===0&&i.length===0?e.jsxs("div",{"data-settings-no-match":"",className:"flex flex-col items-center gap-1 px-2 py-6 text-center",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:c.trim()})}),e.jsx("a",{href:Si,target:"_blank",rel:"noreferrer",className:"text-[12px] leading-4 text-accent-text hover:underline",children:t("settings.search.helpCenter")})]}):e.jsxs("div",{className:"flex flex-col gap-0.5","data-settings-results":"",children:[d.map(p=>e.jsx(xa,{ctx:s,place:n,hit:p,query:c,onHit:l},`h:${p.entry.id}`)),i.map(p=>e.jsxs("button",{type:"button","data-settings-key-result":p.id,onClick:()=>r(p),className:"flex w-full cursor-pointer flex-col rounded-lg px-2 py-1.5 text-left hover:bg-menu-hover focus-visible:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"truncate text-[13px] leading-5 text-ink",children:fr(t(p.labelKey),c)}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:[n.name,t("settings.group.ai"),t(ho(p).titleKey)].join(" › ")})]},`k:${p.id}`)),u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-2 pb-1 pt-3 text-[12px] leading-4 text-ink-secondary",children:t("settings.search.otherPlaces")}),u.map(p=>e.jsx(xa,{ctx:s,place:n,hit:p,query:c,onHit:l},`e:${p.entry.id}`))]})]})}function fr(s,n){const a=s.toLocaleLowerCase().indexOf(n.trim().toLocaleLowerCase());if(a<0||!n.trim())return s;const i=a+n.trim().length;return e.jsxs(e.Fragment,{children:[s.slice(0,a),e.jsx("span",{className:"font-medium",children:s.slice(a,i)}),s.slice(i)]})}function cn(s,n,a){return s.entry.id==="page:overview"?n.name:s.entry.id==="page:account"?t("settings.page.account"):s.entry.id==="page:app"?a?t("settings.page.app"):t("settings.page.browser"):t(s.entry.macLabelKey&&ur()?s.entry.macLabelKey:s.entry.labelKey,{app:ke(),helper:""})}function xa({ctx:s,place:n,hit:a,query:i,onHit:r}){const c=a.entry,l=cn(a,n,s.desktop),d=sp(a,n,s),u=yr(a,n,s),p=c.jump?null:Dt(c.page).icon,x=a.advanced&&!s.advanced;return e.jsxs("button",{type:"button","data-settings-hit":c.id,onClick:()=>r(a),title:u?`${l} · ${u}`:l,className:"flex w-full cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-left hover:bg-menu-hover focus-visible:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"flex h-5 w-6 shrink-0 items-center justify-center text-ink-secondary",children:p&&e.jsx(p,{size:16,strokeWidth:1.75,"aria-hidden":"true"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{"data-settings-hit-title":"",className:"line-clamp-2 text-[13px] leading-5 text-ink [overflow-wrap:anywhere]",children:fr(l,i)}),(d||x)&&e.jsxs("span",{"data-settings-hit-location":"",className:"flex min-w-0 items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[d&&e.jsxs("span",{className:"flex min-w-0 flex-[0_1_auto] overflow-hidden whitespace-nowrap",children:[e.jsx("span",{className:"min-w-[1.5em] shrink-[100] overflow-hidden text-ellipsis",children:d.owner}),d.page&&e.jsx("span",{className:"min-w-0 shrink overflow-hidden text-ellipsis",children:` › ${d.page}`})]}),x&&e.jsx("span",{className:"flex flex-none",children:e.jsx(fo,{children:t("settings.simple.advanced")})})]})]}),c.jump&&e.jsx(Zs,{size:12,"aria-hidden":"true",className:"mt-1 shrink-0 text-ink-tertiary"})]})}const br={overview:"place",phone:"place",ai:"place",bots:"place",desktops:"place",vault:"place",usage:"place",transfer:"place",data:"place",people:"place",installations:"place",account:"account",plan:"account",app:"app",general:"app",appearance:"app"},vr={phone:"settings.section.phoneDevices",ai:"settings.group.ai",bots:"settings.page.bots",desktops:"settings.page.desktops",vault:"settings.section.vault",usage:"settings.page.spending",transfer:"settings.page.importExport",data:"settings.page.data",people:"settings.section.people",installations:"settings.section.workspaces",plan:"settings.page.plan",general:"settings.section.general",appearance:"settings.section.appearance"};function sp(s,n,a){const i=s.entry;if(i.jump)return{owner:yr(s,n,a)};if(i.id.startsWith("page:")&&(i.page==="overview"||i.page==="account"||i.page==="app"))return null;const r=br[i.page],c=s.elsewhere?t("rail.thisComputer"):r==="place"?n.name:on(r,n,a.desktop),l=vr[i.page];return{owner:c,...l&&!i.id.startsWith("page:")?{page:t(l)}:{}}}function yr(s,n,a){const i=s.entry;if(i.jump==="apps")return t("settings.search.opensApps");if(i.jump==="bot")return t("settings.search.onEachBot");if(i.jump==="automations")return t("settings.search.opensAutomations");if(i.jump==="shortcuts")return t("settings.search.opensShortcuts");const r=br[i.page],c=s.elsewhere?t("rail.thisComputer"):r==="place"?n.name:on(r,n,a.desktop),l=vr[i.page],d=[c];l&&!i.id.startsWith("page:")&&d.push(t(l));const u=cn(s,n,a.desktop);return i.sectionKey&&t(i.sectionKey)!==u&&d.push(t(i.sectionKey)),i.id.startsWith("page:")&&(i.page==="overview"||i.page==="account"||i.page==="app")?"":d.join(" › ")}const np="https://cal.com/milind-soni-002qed/30min",ap=["feature","price","setup","broken","later","other"],ip={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},ga=2e3,Os=s=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium"}).format(new Date(s)),rp=s=>s.endsAt??s.renewsAt;function dn(s){const n=rp(s);return s.trial?n?t("cloudCancel.endedTrial",{date:Os(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:Os(n)}):t("cloudCancel.endedPlanNoDate")}function lp(s){const n=s.team?t("cloudCancel.teamStops",{team:s.team}):t("cloudCancel.stops"),a=s.keptDays;if(a===null)return n;const i=a<=0?t("cloudCancel.keptNone"):Number.isInteger(a)?a===1?t("cloudCancel.keptDay"):t("cloudCancel.keptDays",{days:a}):t("cloudCancel.keptHours",{hours:Math.max(1,Math.round(a*24))});return`${n} ${i}`}function op(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:Os(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function cp({renewal:s,actions:n,onClose:a}){const[i,r]=o.useState(null),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState({step:"ask"}),[m,g]=o.useState(!1),[f,h]=o.useState(!1),j=o.useRef(!1),b=o.useRef(null),y=()=>{m||a(j.current)};o.useEffect(()=>{const k=document.activeElement instanceof HTMLElement?document.activeElement:null;return b.current?.querySelector("button[aria-pressed]")?.focus(),()=>{k?.isConnected&&k.focus()}},[]);const v=k=>{g(!0),h(!1),k().catch(()=>h(!0)).finally(()=>g(!1))},w=()=>v(async()=>{const k=i!==null||c.trim()!==""||d.trim()!=="",S=await n.cancel(k?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);S.outcome==="cancelled"?(j.current=!0,x({step:"done",renewal:S.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:S.surveyed})):S.outcome==="browser"?x({step:"browser"}):h(!0)}),N=()=>v(async()=>{const k=await n.keep();k.outcome==="kept"?(j.current=!0,a(!0)):k.outcome==="browser"?x({step:"browser"}):h(!0)}),C=t(s.trial?"cloudCancel.titleTrial":"cloudCancel.titlePlan"),T="mt-1.5 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-60",F=f&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return eo.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:k=>{k.target===k.currentTarget&&y()},children:e.jsxs("div",{ref:b,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":m,tabIndex:-1,"data-cloud-cancel-sheet":p.step,className:"flex max-h-[90vh] w-full max-w-[480px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel text-ink shadow-2xl outline-none",onKeyDown:k=>{if(k.key==="Escape"&&(k.stopPropagation(),y()),k.key==="Tab"){const S=b.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!S?.length)return;const P=S[0],E=S[S.length-1];k.shiftKey&&document.activeElement===P?(k.preventDefault(),E.focus()):!k.shiftKey&&document.activeElement===E&&(k.preventDefault(),P.focus())}},children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-6 pb-1 pt-5",children:[e.jsx("h2",{id:"cloud-cancel-title",className:"text-[17px] font-semibold",children:C}),e.jsx("button",{type:"button","aria-label":t("cloudCancel.close"),disabled:m,onClick:y,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(Oe,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[p.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:op(s)}),e.jsxs("fieldset",{className:"mt-4",disabled:m,children:[e.jsx("legend",{className:"text-[14px] font-medium text-ink",children:t("cloudCancel.question")}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-2",children:ap.map(k=>e.jsx("button",{type:"button","aria-pressed":i===k,onClick:()=>r(S=>S===k?null:k),className:z("ui-button ui-button-pill",i===k&&"border-accent bg-accent/10 font-medium"),children:t(ip[k])},k))})]}),e.jsxs("label",{className:"mt-4 block text-[13px] text-ink",children:[t("cloudCancel.expected")," ",e.jsx("span",{className:"text-ink-secondary",children:t("cloudCancel.optional")}),e.jsx("textarea",{rows:2,maxLength:ga,value:c,disabled:m,onChange:k=>l(k.target.value),className:T})]}),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:ga,value:d,disabled:m,onChange:k=>u(k.target.value),className:T})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:np,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),F,e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:m,onClick:y,children:t("cloudCancel.keep")}),e.jsx("button",{type:"button","data-cloud-cancel-confirm":!0,className:"ui-button border-transparent bg-danger text-white hover:brightness-110",disabled:m,onClick:w,children:t(m?"cloudCancel.cancelling":s.trial?"cloudCancel.confirmTrial":"cloudCancel.confirmPlan")})]})]}),p.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:dn(p.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:lp(p.renewal)}),p.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),F,e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t("cloudCancel.changedMind")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m,onClick:N,children:t(m?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:m,onClick:y,children:t("cloudCancel.done")})]})]}),p.step==="browser"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink",children:t("cloudCancel.browser")}),e.jsx("div",{className:"mt-5 flex justify-end",children:e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:y,children:t("cloudCancel.done")})})]})]})]})}),document.body)}const jr=s=>new Intl.DateTimeFormat(Ee(),{month:"short",day:"numeric"}).format(new Date(s));function kr(s,n,a=!1){const i=a?t("settings.plan.trialName",{plan:s}):s,r=n?.cancelled?n.endsAt??n.renewsAt:null;return r?t("settings.plan.ends",{plan:i,date:jr(r)}):i}function dp({usage:s,upgrade:n}){return e.jsx(Y,{label:t("settings.plan.thisWeek"),block:"this-week",footnote:ko(s),actions:n?e.jsx(jo,{usage:s,upgrade:n,secondary:!0}):void 0,children:e.jsx(J,{children:s.meters.map(a=>e.jsxs("div",{"data-plan-meter":a.kind,className:"flex flex-col gap-2 px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-6",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:Mn(a.kind)}),e.jsxs("span",{className:"shrink-0 text-[13px] leading-5 tabular-nums text-ink-secondary",children:[bo(a)," · ",vo(a),"%"]})]}),e.jsx(yo,{meter:a,label:Mn(a.kind),compact:!0})]},a.kind))})})}function wr({renewal:s,actions:n,onChanged:a}){const[i,r]=o.useState(!1);return s.cancelled?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"cancel",className:"contents",children:e.jsx(L,{title:t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan"),children:e.jsx("button",{type:"button","data-cloud-cancel":"renewing","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>r(!0),"aria-label":t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan"),children:t("settings.plan.cancelAction")})})}),i&&e.jsx(cp,{renewal:s,actions:n,onClose:c=>{r(!1),c&&a?.()}})]})}function Nr(s){if(!(!s||s.cancelled||!s.renewsAt))return t(s.trial?"settings.plan.trialEnds":"settings.plan.renews",{date:jr(s.renewsAt)})}function Sr({actions:s,onChanged:n}){const[a,i]=o.useState(!1),[r,c]=o.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button ui-button-primary","data-cloud-cancel":"cancelled",disabled:a,onClick:()=>{i(!0),c(null),s.keep().then(l=>{l.outcome==="kept"?n?.():c(t(l.outcome==="browser"?"cloudCancel.browser":"cloudCancel.failed"))},()=>c(t("cloudCancel.failed"))).finally(()=>i(!1))},children:t(a?"cloudCancel.keeping":"cloudCancel.keep")}),r&&e.jsx("span",{className:"sr-only",role:"status",children:r})]})}function Cr({title:s,subtitle:n,message:a,primary:i,usage:r,upgrade:c,links:l,extra:d,cancel:u,footnote:p}){return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.simple.billing.plan"),block:"plan",footnote:p,children:e.jsxs(J,{children:[e.jsx(L,{title:s,subtitle:n,message:a||void 0,children:i??null}),e.jsx(hu,{}),l,d,u]})}),r&&r.meters.length>0&&e.jsx(dp,{usage:r,upgrade:c})]})}function up({place:s}){const[n,a]=o.useState(void 0);return o.useEffect(()=>{let i=!0;return Is(Di("week")).then(r=>{i&&a(r.totals.costUsd)}).catch(()=>{i&&a(void 0)}),()=>{i=!1}},[]),e.jsx("div",{"data-plan-spent":"",className:"contents",children:e.jsx(L,{title:t("settings.plan.spent",{place:s}),children:n===void 0?null:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:pp(n)})})})}function pp(s){return s==null||!Number.isFinite(s)||s<=0?t("settings.plan.spentNothing"):t("settings.plan.spentWeek",{cost:Je(s)})}function ha({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 mp={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},Er=s=>new Intl.DateTimeFormat(Ee(),{timeStyle:"short"}).format(new Date(s)),xp=s=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium"}).format(new Date(s));function Gt(s,n){if(!s&&!n)return null;const a=s?Ws(s):null;return e.jsxs("div",{"data-cloud-trial":s?.state??"none",className:"flex flex-col gap-1",children:[a&&e.jsx("p",{className:"text-[13px] font-medium text-ink",children:a.title}),a&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:a.body}),n&&e.jsx("p",{"data-cloud-credit":n.state,className:"text-[13px] leading-relaxed text-ink-secondary",children:kl(n)})]})}function fa({machine:s,busy:n,failed:a,onConnect:i,trial:r=!1,waking:c=!1,moving:l=null,team:d=null}){const u=s.status==="ready"?s.unreachable:void 0,p=s.status==="ready"&&!u,x=u?t(u.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):l??(c&&p?t("cloudHome.waking"):d?.name&&s.status==="ready"?t("cloudHome.team.ready",{name:d.name}):s.status==="ready"&&s.power?.sleeps?t("cloudHome.readySleeps"):r&&(s.status==="stopped"||s.status==="payment-problem")?t("cloudHome.stoppedTrial"):s.status==="failed"&&s.retryAt?t("cloudHome.failedRetry",{time:Er(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(mp[s.status])),m=d?.name?t("cloudBuy.setup.open",{name:d.name}):t("settings.plan.openCloud",{place:t("cloudSetup.myCloud")});return p&&!l?e.jsxs("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-waking":c?!0:void 0,className:"contents",children:[e.jsx(je,{title:m,subtitle:d?.name?t("cloudHome.team.ready",{name:d.name}):t("settings.plan.cloudReadyLine"),value:t(c?"settings.plan.cloudWaking":"settings.plan.cloudReady"),external:!0,onClick:()=>{n||i()},data:{"data-plan-open-cloud":""}}),!d&&Dn()&&e.jsx("p",{className:"px-4 pb-3",children:e.jsx(ha,{label:t("cloudHome.filesLink"),className:"text-[12px] leading-4 text-accent-text hover:underline"})}),a&&e.jsx("p",{role:"alert",className:"px-4 pb-3 text-[12px] leading-4 text-danger",children:t("cloudHome.connectFailed")})]}):e.jsx("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-unreachable":u?.cause,"data-cloud-waking":c&&p?!0:void 0,"data-cloud-moving":l&&!u?!0:void 0,children:e.jsx(L,{title:d?d.name??t("cloudHome.team.title"):t("cloudSetup.myCloud"),subtitle:e.jsx("p",{role:"status",children:x}),message:e.jsxs(e.Fragment,{children:[s.status==="provisioning"&&s.setup&&e.jsx(ru,{step:s.setup.step}),p&&!d&&Dn()&&e.jsx(ha,{label:t("cloudHome.filesLink"),className:"text-[12px] leading-4 text-accent-text hover:underline"}),a&&!u&&e.jsx("p",{role:"alert",className:"text-danger",children:t("cloudHome.connectFailed")})]}),children:null})})}function gp(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 hp={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function fp(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(hp[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:xp(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 bp(s,n){const a=s.trial&&!s.renewal?.cancelled?Ws(s.trial).action:null;return a?a.label:n.kind==="paid"||n.kind==="unverified"&&n.label?t("cloudAccount.manage"):s.machine?.status==="payment-problem"?t("cloudAccount.updatePayment"):t("cloudAccount.dashboard")}function vp({bridge:s,usage:n=null,upgrade:a,extra:i}){const[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(!1),[x,m]=o.useState(0);o.useEffect(()=>{let v=!0;return s.state().then(w=>{v&&c(w)}).catch(()=>{v&&p(!0)}),()=>{v=!1}},[s,x]);const g=s.cancel&&s.keep?{cancel:v=>s.cancel(v),keep:()=>s.keep()}:null;if(u)return e.jsx(Y,{label:t("settings.simple.billing.plan"),block:"plan",children:e.jsx(J,{children:e.jsx("div",{"data-cloud-plan":"elsewhere",className:"contents",children:e.jsx(L,{title:t("cloudAccount.onCloudNone"),children:null})})})});const f=jl(r?.tier),h=r?.renewal?.cancelled===!0,j=r?.status==="paid"?kr(f,r.renewal,Ci(r.trial)):r?.status==="attention"?t("cloudAccount.inactive",{plan:r.tier?f:t("settings.simple.billing.plan")}):r?.status==="checking"?t("cloudAccount.lastPlan",{plan:f}):r?.status==="signin"&&r.tier?t("cloudAccount.planName",{plan:f}):r?t(r.home===!0?"cloudAccount.onCloudNoneHome":"cloudAccount.onCloudNone"):t("cloudAccount.loading"),b=v=>{d(!1),v().catch(()=>d(!0))},y=r?.status==="signin"&&s.signIn?e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>b(()=>s.signIn()),children:t("cloudAccount.signInAgain")}):h&&g?e.jsx(Sr,{actions:g,onChanged:()=>m(v=>v+1)}):r?e.jsx("button",{type:"button",className:"ui-button ui-button-primary","data-plan-manage":"",onClick:()=>b(()=>s.manage()),children:r.trial&&!r.renewal?.cancelled&&Ws(r.trial).action?.label||t("settings.plan.manage")}):null;return e.jsx("div",{"data-cloud-plan":r?.status??"loading",className:"contents",children:Cr({title:j,primary:y,usage:n,upgrade:a,extra:i,subtitle:r?.status==="signin"?t("cloudAccount.onCloudSignIn"):h&&r?.renewal?dn(r.renewal):Nr(r?.renewal),message:Gt(r?.trial,r?.credit)||l?e.jsxs(e.Fragment,{children:[Gt(r?.trial,r?.credit),l&&e.jsx("p",{role:"alert",className:"text-danger",children:t("cloudAccount.actionFailed")})]}):void 0,cancel:r?.renewal&&g?e.jsx(wr,{renewal:r.renewal,actions:g,onChanged:()=>m(v=>v+1)}):void 0})})}function yp({team:s,admin:n,owner:a=!1}){const i=n||a?An(s,"invite"):null,r=a?An(s,"seats"):null,c=a?"cloudAccount.teamPeopleOwner":n?"cloudAccount.teamPeopleAdmin":"cloudAccount.teamPeopleAsk";return e.jsx(xe,{title:t("cloudAccount.teamPeopleTitle"),children:e.jsxs("div",{"data-cloud-plan":"team",className:"flex flex-col items-start gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c,{team:s.name})}),i&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("a",{className:"ui-button",href:i,target:"_blank",rel:"noreferrer","data-team-invite":"",children:t("cloudAccount.teamPeopleInvite")}),r&&e.jsx("a",{className:"ui-button",href:r,target:"_blank",rel:"noreferrer","data-team-seats":"",children:t("cloudAccount.teamPeopleSeats")})]})]})})}function Ar({linkRequest:s=0,cloudHome:n=!1,teamHome:a,onAddCloud:i,onSignIn:r,part:c="plan",advanced:l=!0,usage:d=null,upgrade:u,extra:p,avatar:x}={}){const m=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:g}=Ri().capabilities.host,[f,h]=o.useState(null),[j,b]=o.useState(!1),[y,v]=o.useState(!1),[w,N]=o.useState(!1),[C,T]=o.useState(!1),[F,k]=o.useState(!1),[S]=o.useState(!1),P=o.useRef(0),E=o.useRef(0),A=o.useRef(!1),V=o.useRef({request:0,arrived:!1,connected:!1});o.useEffect(()=>{const pe=++P.current,Pe=E.current,Te=Ie=>{P.current===pe&&(E.current++,h(Ie),v(!1),Ie.status==="signed-out"&&N(!1))},Fe=m?.onState(Te);return m?.state().then(Ie=>{E.current===Pe&&Te(Ie)}).catch(()=>{P.current===pe&&E.current===Pe&&v(!0)}),()=>{P.current++,Fe?.()}},[m]);const R=async pe=>{if(!m||A.current)return;A.current=!0,b(!0),v(!1);const Pe=P.current,Te=E.current;try{const Fe=await pe();P.current===Pe&&E.current===Te&&h(Fe)}catch{P.current===Pe&&E.current===Te&&v(!0)}finally{A.current=!1,P.current===Pe&&b(!1)}},K=()=>{m&&(k(!1),R(async()=>{try{return await m.connectHome()}catch{return k(!0),m.state()}}))},te=pe=>{m?.openTeam&&(k(!1),R(async()=>{try{await m.openTeam(pe)}catch{k(!0)}return m.state()}))};o.useEffect(()=>{if(s||(V.current.request=0),!m||!s||!f||A.current||(V.current.request!==s&&(V.current={request:s,arrived:!0,connected:!1}),f.status==="signed-out"&&f.message==="restoring"))return;const pe=gp(f,V.current);V.current.arrived=!1,pe==="sign-in"&&R(()=>m.begin()),pe==="connect"&&(V.current.connected=!0,K())},[m,s,f,j]);const[ue]=wo(m?window.ogb?.cloudSendPage:void 0),ae=ue?.move?xl(ue.move,"local"):null,X=ae&&ae.kind!=="done"?ae.text:null,B=Au(!!f&&ms(En(f)),f?.offer),W=m?.cancelPlan&&m.keepPlan?{cancel:pe=>m.cancelPlan(pe),keep:()=>m.keepPlan()}:null;if(!m){const pe=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return c!=="plan"||n&&a?null:pe?e.jsx(vp,{bridge:pe,usage:d,upgrade:u,extra:p}):e.jsx("p",{className:"px-4 text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")})}const G=En(f),oe=f&&["connected","unavailable","reauth-required"].includes(f.status),M=fp(f,G,g),$=gl(G),Z=hl(f),ee=fl(f),O=G.kind==="paid"?{status:"provisioning"}:void 0,re=Z?ee?.machine??O:f?.status==="connected"?f.machine??O:void 0,ne=f?.status==="connecting"?f.enrollment:void 0,me=bl(B),q=G.kind==="signed-out"||G.kind==="removed",ge=t(vl(B)!==null?"cloudIntro.start":"cloudAccount.upgrade"),be=y&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:t("cloudAccount.actionFailed")});if(c==="account"){const pe=e.jsx("span",{"aria-hidden":"true"});return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{label:t("settings.account.mausbot",{app:ke()}),block:"mausbot-account",children:[e.jsxs(J,{icons:!0,children:[(!f||G.kind==="unknown")&&e.jsx(L,{title:t("cloudAccount.loading"),leading:x??pe,children:!f&&e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.state())},children:t("organization.refresh")})}),q&&e.jsx(L,{title:t("settings.account.signInTitle",{app:ke()}),subtitle:t("settings.account.signInBody"),message:M&&e.jsx("p",{role:"status",children:M}),leading:x??pe,children:e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-account-sign-in":"",onClick:()=>r?r():void R(()=>m.begin()),children:t("settings.account.signIn")})}),f?.status==="connecting"&&e.jsxs(L,{title:t("cloudAccount.browser"),leading:x??pe,subtitle:ne?`${t("cloudAccount.codeCheck")} ${t("cloudAccount.codeUntil",{time:Er(ne.expiresAt)})}`:void 0,message:ne&&e.jsx("code",{"data-cloud-code":!0,dir:"ltr",className:"select-all text-[20px] font-medium leading-7 tracking-[0.08em] text-ink",children:ne.userCode}),children:[e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:j,className:"settings-quiet cursor-pointer",onClick:()=>{R(()=>m.cancel())},children:t("organization.cancel")})]}),oe&&e.jsx(L,{title:f.account?.email??t("settings.account.signedIn"),leading:x??pe,subtitle:M?e.jsx("p",{role:"status",children:M}):t("settings.account.signedIn"),children:G.kind==="reauth"?e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.signInAgain())},children:t("cloudAccount.signInAgain")}):l&&e.jsx("button",{type:"button",disabled:j,className:"settings-quiet cursor-pointer",onClick:()=>{R(()=>m.refresh())},children:t("organization.refresh")})}),oe&&e.jsx("div",{"data-settings-block":"sign-out",className:"contents",children:e.jsx(L,{title:t("settings.account.signOut",{app:ke()}),leading:pe,children:e.jsx("button",{type:"button",disabled:j,"data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>N("sign-out"),children:t("settings.account.signOutShort")})})})]}),oe&&G.kind==="free"&&!w&&e.jsxs("p",{className:"px-4 text-[12px] leading-4 text-ink-secondary",children:[t(window.ogb?.accounts?"cloudAccount.otherEmailOrTeam":"cloudAccount.otherEmail")," ",e.jsx("button",{type:"button","data-cloud-other-email":!0,disabled:j,className:"cursor-pointer text-accent-text hover:underline",onClick:()=>window.ogb?.accounts?T(!0):N("other-email"),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),be]}),C&&e.jsx(to,{adding:"",onClose:()=>T(!1)}),w&&e.jsx(zi,{here:t("rail.thisComputer"),cloud:w==="sign-out"&&G.kind==="paid"?t("cloudSetup.myCloud"):null,onConfirm:()=>R(()=>m.signOut()),onClose:()=>N(!1)})]})}if(c==="sign-out")return null;const we=f?.status==="connected"&&f.renewal?.cancelled===!0,Be=q||G.kind==="free"&&ms(G)?i&&ms(G)&&e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-plan-add":"",onClick:i,children:ge}):G.kind==="reauth"?e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary",onClick:()=>{R(()=>m.signInAgain())},children:t("cloudAccount.signInAgain")}):we&&W?e.jsx(Sr,{actions:W,onChanged:()=>{R(()=>m.state())}}):oe&&e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-plan-manage":"",onClick:()=>{R(()=>m.openDashboard())},children:G.kind==="free"?t("cloudAccount.dashboard"):bp(f,G)}),Xe=!f||G.kind==="unknown"?t("cloudAccount.loading"):G.kind==="signed-out"?t("cloudAccount.free"):G.kind==="paid"&&f.status==="connected"?kr(G.label,f.renewal,Ci(f.trial)):$??t("settings.simple.billing.plan");return e.jsxs(e.Fragment,{children:[Cr({title:Xe,primary:Be||void 0,usage:d,upgrade:u,extra:p,footnote:me,subtitle:G.kind==="signed-out"?No()?t("settings.plan.offer"):void 0:we&&f?.status==="connected"&&f.renewal?dn(f.renewal):G.kind==="paid"&&G.checking?t("cloudAccount.checking"):M??(f?.status==="connected"?Nr(f.renewal):void 0),message:oe&&(f.staging||f.status==="connected"&&Gt(f.trial,f.credit))?e.jsxs(e.Fragment,{children:[f.staging&&e.jsx(yl,{className:"mb-1"}),f.status==="connected"?Gt(f.trial,f.credit):null]}):void 0,links:e.jsxs(e.Fragment,{children:[q&&e.jsx(je,{title:t("settings.plan.haveOne"),onClick:()=>r?r():void R(()=>m.begin())}),re&&fa(Z?{machine:re,busy:j,failed:F,onConnect:()=>{ee&&te(ee.id)},team:{name:ee?.name??null}}:{machine:re,busy:j,failed:F,onConnect:K,trial:!!f?.trial,waking:f?.waking===!0,moving:X})]}),cancel:oe&&f.status==="connected"&&f.renewal&&W?e.jsx(wr,{renewal:f.renewal,actions:W,onChanged:()=>{R(()=>m.state())}}):void 0}),be,S&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:t("cloudPhone.failed")})]})}function Pr(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function jp(s,n){return s.find(a=>Pr(a)&&a.instanceId.endsWith(`.${n}`))}function un(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function ba(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return un(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function kp(s,n){const a=n.filter(l=>Pr(l)&&un(l)),i=a.find(l=>l.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const r={target:i,bots:[],needsAsk:[]},c=l=>n.find(d=>d.instanceId===l)?.driverKind;for(const l of s){if(l.hidden)continue;const d=So(l);if(ba(l.modelSelection,n)||ba(d.modelSelection,n))continue;([l,d].some(p=>Co(Eo(p),c(p.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(l)}return r}const wp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function Np({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=_(),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=kp(n.bots,n.instances),p=u.target,x=g=>g.map(f=>f.name).join(", "),m=async()=>{if(!p||!u.bots.length||r)return;const g=u.bots,f={instanceId:p.instanceId,model:p.models.default};c(!0),d(null);for(const h of g)a({type:"setModel",botId:h.id,selection:f});try{const h=await Promise.all(g.map(b=>i(b.id).catch(()=>null))),j=g.filter((b,y)=>h[y]?.modelSelection.instanceId===f.instanceId);j.length&&d({name:p.displayName,bots:j.map(b=>b.name)})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(g=>e.jsxs("li",{className:"py-2 text-[13px]",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsx("span",{className:"text-ink",children:wp[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(Sp,{instance:jp(n.instances,g.id),instances:n.instances})]},g.id))}),l&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:l.name,names:l.bots.join(", ")})}),p&&u.bots.length>0&&e.jsxs("div",{"data-company-switch":!0,className:"flex flex-col items-start gap-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"break-words text-[13px] text-ink",children:t("organization.useCompanyBots",{names:x(u.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{m()},children:u.bots.length===1?t("organization.useCompanyOne",{name:p.displayName}):t("organization.useCompanyMany",{name:p.displayName,count:u.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),p&&u.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:x(u.needsAsk)})})]})}function Sp({instance:s,instances:n}){if(!s)return null;if(s.policy)return e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s.policy.reason});if(un(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(He,{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&&Ao(a)?e.jsx(Po,{instance:a,intent:"inject",className:"mt-2",description:t("organization.engineInstallHelp",{engine:a.displayName})}):e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s.snapshot.reason??t("organization.engineUnavailable")})}const Cp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},va="https://admin.openmausbot.com",ya={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 ja(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(ya,a))?s.message:n.map(a=>t(ya[a])).join(" ")}function Ep({simple:s=!1}={}){const n=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[a,i]=o.useState(null),[r,c]=o.useState(""),[l,d]=o.useState(!1),[u,p]=o.useState(""),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(!1),b=o.useRef(!1),y=o.useRef(0),v=o.useRef(0),w=o.useRef(void 0),N=E=>{const A=w.current!==E.status;w.current=E.status,i(E),A&&p(""),E.status!=="connected"&&E.status!=="reauth-required"&&m(!1)};o.useEffect(()=>{n?.settingsOpened?.().catch(()=>{});const E=++y.current,A=v.current,V=K=>{y.current===E&&(v.current++,N(K))},R=n?.onState(V);return n?.state().then(K=>{v.current===A&&V(K)}).catch(()=>{y.current===E&&v.current===A&&p(t("organization.loadFailed"))}),()=>{y.current++,R?.()}},[n]);const C=async E=>{if(!n||b.current)return;b.current=!0,d(!0),p("");const A=y.current,V=v.current;try{const R=await E();y.current===A&&v.current===V&&N(R)}catch{y.current===A&&v.current===V&&p(t("organization.actionFailed"))}finally{b.current=!1,y.current===A&&d(!1)}};if(!n)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const T=a?.status==="connected"||a?.status==="reauth-required"||a?.status==="unavailable"||a?.status==="license-expired",F=a?.status==="license-expired"||a?.notice==="license-expired",k=a?.enrollment?.expiresAt??a?.expiresAt,S=typeof k=="number"&&Number.isFinite(k)?new Date(k):null,P=S&&Number.isFinite(S.getTime())?new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(S):null;return a?.status==="signed-out"&&s?e.jsx("div",{"data-settings-rows":"",hidden:!0}):a?.status==="signed-out"?e.jsxs(J,{children:[e.jsx(L,{title:t("organization.signIn"),subtitle:e.jsxs(e.Fragment,{children:[t("organization.signInShort")," ",e.jsx(ze,{onClick:()=>f(E=>!E)})]}),message:e.jsxs(e.Fragment,{children:[g&&e.jsxs("span",{"data-organization-more":"",className:"block",children:[t("organization.additive")," ",t("organization.privacy")," ",t("cloudAccount.separate")]}),a.message&&e.jsx("span",{role:"status",className:"block",children:ja(a)}),F&&e.jsx("span",{role:"alert",className:"block text-ink",children:t("organization.licenseExpired")}),u&&e.jsx("span",{role:"alert",className:"block text-danger",children:u})]}),children:e.jsx("button",{type:"button",disabled:l,className:"ui-button","data-organization-sign-in":"",onClick:()=>{C(()=>n.begin({portalOrigin:va}))},children:l?t("organization.working"):t("organization.useWorkSignIn")})}),e.jsx(wt,{id:"organization-address",title:t("organization.customTitle"),open:h,onToggle:()=>j(E=>!E),children:e.jsxs("form",{className:"flex flex-col gap-2 px-4 py-3",onSubmit:E=>{E.preventDefault(),r.trim()&&C(()=>n.begin({portalOrigin:r.trim()}))},children:[e.jsx(fe,{label:t("organization.address"),hint:t("organization.advancedHelp"),children:e.jsx("input",{type:"url",required:!0,value:r,disabled:l,onChange:E=>c(E.target.value),placeholder:va,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:he})}),e.jsx("button",{type:"submit",disabled:l||!r.trim(),className:"ui-button self-end",children:t("organization.customSignIn")})]})})]}):e.jsx(e.Fragment,{children:e.jsxs(xe,{children:[!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:u||t("organization.loading")}),a?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:ja(a)}),F&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),a?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.browserConsent")}),a.enrollment&&e.jsxs("details",{className:"w-full text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.securityDetails")}),e.jsx("p",{className:"mt-2",children:t("organization.securityDetailsHelp")}),e.jsx("div",{className:"mt-3",children:t("organization.code")}),e.jsx("code",{dir:"ltr",className:"mt-1 block w-fit select-all rounded-lg bg-inset px-3 py-2 text-base tracking-widest text-ink",children:a.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.enrollment&&n.reopen&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.cancelEnrollment())},children:t("organization.cancel")})]})]}),T&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[a.branding?.logo&&e.jsx("img",{src:a.branding.logo,alt:t("organization.logo"),className:"mb-2 size-12 rounded-lg object-contain"}),e.jsx("div",{className:"break-words text-[15px] font-medium text-ink",children:a.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:a.email})]}),a.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):a.status==="license-expired"?e.jsx(e.Fragment,{children:a.providers?.some(E=>E.configured&&E.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:a.providers.filter(E=>E.configured&&E.models.length>0).map(E=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:Cp[E.id]??E.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},E.id))})}):a.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),a.providers?.some(E=>E.configured&&E.models.length>0)?e.jsx(Np,{providers:a.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,x?e.jsxs("div",{role:"group","aria-label":t("organization.disconnectTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink",children:t("organization.disconnectWarning")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:l,className:"ui-button",onClick:()=>m(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button text-danger",onClick:()=>{C(()=>n.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>m(!0),children:t("organization.disconnect")})]})]}),a?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),P&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:P})}),u&&a&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u}),!a&&e.jsx("button",{type:"button",disabled:l,className:"ui-button mt-3",onClick:()=>{C(()=>n.refresh())},children:t("organization.refresh")})]})})}function Ap(){const s=To(),[n,a]=o.useState(!1),[i,r]=o.useState(!1);if(!s?.available||!s.on&&s.here!=="computer")return null;const c=()=>{a(!0),r(!1),Io(!s.on).catch(()=>r(!0)).finally(()=>a(!1))};return e.jsx(Y,{block:"together",children:e.jsx(J,{children:e.jsx("div",{"data-places-together":s.on?"on":"off",className:"contents",children:e.jsx(L,{title:t("together.switch.title"),tag:t("settings.early.tag"),subtitle:t("together.switch.line"),message:i?e.jsx("span",{role:"alert",className:"block text-danger",children:t("together.switch.failed")}):void 0,children:e.jsx(ie,{checked:s.on,disabled:n,"aria-label":t("together.switch.title"),onClick:c})})})})})}function Pp(){const{ctx:s,place:n,go:a}=Ne(),{state:i,dispatch:r}=_(),{profile:c,session:l}=Xs(),d=Ys(),u=At(),[p,x]=o.useState(!1),m=s.client?void 0:window.ogb?.cloudAccount,g=s.desktop&&!s.client&&!s.here&&!s.home&&!m,f=d.email??(d.plan?c?.email??null:null),h=window.ogb?.accountSheet,j=e.jsx(De,{place:{kind:"computer",name:u.name,color:null},size:14});return e.jsxs(e.Fragment,{children:[e.jsx(Y,{block:"you",children:e.jsx(J,{children:g&&u.open?e.jsx(je,{title:t("settings.account.nameRow"),badge:j,value:t("settings.account.onPlace",{place:u.name}),external:!0,onClick:u.open,data:{"data-account-name-row":""}}):e.jsx(je,{title:t("settings.account.nameRow"),badge:e.jsx(De,{place:n,size:14}),value:Ro(c),onClick:()=>a("bots","about-you"),data:{"data-account-name-row":""}})})}),m&&e.jsx(Ar,{part:"account",advanced:s.advanced,linkRequest:i.appSettingsCloudLink,avatar:e.jsx(Wt,{size:32}),onSignIn:()=>r({type:"openCloudAdd",source:"app_settings",signIn:!0})}),g&&e.jsx(Y,{label:t("settings.account.mausbot",{app:ke()}),block:"mausbot-account",children:e.jsxs(J,{icons:!0,children:[e.jsx(L,{title:f??t("settings.account.signedIn"),leading:e.jsx(Wt,{size:32}),subtitle:d.signedIn===!1?t("settings.account.notSignedIn"):t("settings.account.signedIn"),children:null}),h&&e.jsx(je,{title:t("accounts.manage"),leading:e.jsx("span",{"aria-hidden":"true"}),onClick:()=>{h.open().catch(()=>{})},data:{"data-account-manage":""}}),u.open&&e.jsx(je,{title:t("settings.account.fromHere",{place:u.name}),leading:e.jsx("span",{"aria-hidden":"true"}),external:!0,onClick:u.open,data:{"data-account-elsewhere":""}})]})}),!s.desktop&&e.jsxs(Y,{block:"mausbot-account",children:[e.jsxs(J,{children:[e.jsx(L,{title:t("settings.account.signedInTo",{place:n.name}),subtitle:c?.email,children:null}),l?.kind==="session"&&e.jsx(L,{title:t("settings.account.signOutBrowser"),children:e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>x(!0),children:t("settings.account.signOutShort")})})]}),p&&e.jsx(zi,{browser:!0,here:n.name,onConfirm:()=>D("/api/auth/logout",{method:"POST"}).finally(()=>location.reload()),onClose:()=>x(!1)})]}),s.organization?e.jsx(Y,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Ep,{simple:!s.advanced})}):g&&s.advanced&&e.jsx(Y,{label:t("settings.section.organization"),block:"organization",children:e.jsx(J,{children:e.jsx(ct,{title:t("settings.account.orgSignIn"),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.account.signIn")})})})}),s.desktop&&!s.client&&window.ogb?.updatesConsent&&e.jsx(Y,{label:t("settings.account.emails",{app:ke()}),block:"emails",children:e.jsx(J,{children:e.jsx(Bo,{})})})]})}function Tp(){const{ctx:s,place:n}=Ne(),{state:a,dispatch:i}=_(),{usage:r,upgrade:c,dialog:l}=Lo();return s.desktop?e.jsxs(e.Fragment,{children:[e.jsx(Ar,{part:"plan",advanced:s.advanced,cloudHome:s.cloud,teamHome:a.config?.team,linkRequest:a.appSettingsCloudLink,usage:r,upgrade:c,extra:!s.advanced&&!s.client&&!(s.team&&!s.admin)&&(n.kind==="computer"||n.kind==="server")?e.jsx(up,{place:n.name}):void 0,onAddCloud:()=>i({type:"openCloudAdd",source:"app_settings"}),onSignIn:()=>i({type:"openCloudAdd",source:"app_settings",signIn:!0})}),e.jsx(Ap,{}),l]}):e.jsx(Y,{block:"plan",children:e.jsx(J,{children:e.jsx(L,{title:t("settings.plan.browserTitle"),subtitle:t("settings.plan.browserLine",{app:ke()}),children:e.jsxs("a",{className:"ui-button ui-button-primary inline-flex items-center gap-1",href:wl,target:"_blank",rel:"noreferrer",children:[t("settings.plan.openBilling"),e.jsx(Zs,{size:12,"aria-hidden":"true"})]})})})})}const Ip="https://github.com/seira-bot/seira/blob/main/docs/analytics.md";function Lp({simple:s=!1}){const[n,a]=o.useState(Nl);if(!Sl())return null;const i=e.jsxs(e.Fragment,{children:[t(s?"settings.simple.analytics":"settings.analytics.subtitle")," ",e.jsx("a",{href:Ip,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:t(s?"settings.simple.analyticsLink":"settings.analytics.link")})]});return e.jsx(L,{title:t("settings.analytics.title"),subtitle:i,children:e.jsx(ie,{checked:n,"aria-label":t("settings.analytics.aria"),onClick:()=>{const r=!n;Cl(r),a(r)}})})}function Rp(){const[s,n]=o.useState(Pl);return e.jsx(L,{title:t("settings.font.title"),subtitle:t("settings.font.line"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Il(i),n(i)},children:Tl.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Bp(){const[s,n]=o.useState(El);return e.jsx(L,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.line"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=Pn.find(r=>r===a.target.value);i&&(Al(i),n(i))},children:Pn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Op(){const s=Oo();return e.jsx(L,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>Uo(Mo(n.target.value)),children:Fo.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function Pt(){const{dispatch:s}=_(),[n,a]=o.useState(!1),[i,r]=o.useState("");return{saving:n,error:i,save:async l=>{if(!n){a(!0),r("");try{const d=await D("/api/config",{method:"PATCH",body:JSON.stringify(l)});s({type:"configStatus",config:d})}catch(d){r(d instanceof Error?d.message:t("settings.experimental.error"))}finally{a(!1)}}}}}function Fp(){const{state:s}=_(),n=Zt(s.config),a=Do(s.config),i=s.config?.browserEngine?.installable===!0,r=window.ogb?.platform==="win32"&&!a&&!i,{saving:c,error:l,save:d}=Pt();return e.jsx(L,{title:t("settings.browser.rowTitle"),subtitle:a?n?t("settings.ai.ready"):t("settings.browser.offShort"):r?t("settings.experimental.browserWindows"):i?n?t("settings.browser.installsFirst"):t("settings.browser.notInstalledShort"):zo(s.config),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(ie,{checked:n,"aria-label":t("settings.experimental.browserAria"),disabled:c||!n&&!a&&!i,onClick:()=>{d({features:{browser:!n}})},className:"disabled:cursor-wait disabled:opacity-50"})})}function Up(){const{state:s}=_(),n=kt(),a=s.config?.browserEngine?.serverSites,{saving:i,error:r,save:c}=Pt();return a===void 0||n!==!0||!Zt(s.config)?null:e.jsx(L,{title:t("settings.browser.localSites"),subtitle:t("settings.browser.localSitesPlain"),message:r?e.jsx("p",{role:"alert",className:"text-danger",children:r}):null,children:e.jsx(ie,{checked:a,"aria-label":t("settings.browser.serverSites"),disabled:i,onClick:()=>{c({browserEngine:{egress:{localNetwork:!a}}})},className:"disabled:cursor-wait disabled:opacity-50"})})}function Mp(){const{state:s}=_(),n=kt(),a=s.config?.team?s.config.browserEngine?.proxyEditable===!0:n===!0,i=s.config?.browserEngine?.proxyConfigured===!0,r=s.config?.browserEngine?.proxySaved===!0||i,[c,l]=o.useState(""),{saving:d,error:u,save:p}=Pt();return!a||!Zt(s.config)&&!r?null:e.jsx(L,{title:t("settings.browser.proxy"),subtitle:i?t("settings.browser.proxyConfigured"):r?t("settings.browser.proxyInactive"):t("settings.browser.proxyDetail"),message:u?e.jsx("p",{role:"alert",className:"text-danger",children:u}):null,children:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto",children:[e.jsx("input",{"aria-label":t("settings.browser.proxy"),autoComplete:"off",spellCheck:!1,placeholder:"socks5://127.0.0.1:1080",value:c,onChange:x=>l(x.target.value),className:"min-w-0 flex-1 rounded-lg border border-control bg-app px-3 py-2 text-[13px] text-ink sm:w-64 sm:flex-none"}),e.jsx("button",{type:"button",disabled:d||!c.trim(),onClick:()=>{p({browserEngine:{egress:{proxy:c.trim()}}})},className:"rounded-lg bg-control px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:t("settings.browser.proxySave")}),r?e.jsx("button",{type:"button",disabled:d,onClick:()=>{p({browserEngine:{egress:{proxy:""}}})},className:"rounded-lg bg-control px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:t("settings.browser.proxyClear")}):null]})})}function Dp(){const{state:s}=_(),n=s.config?.browserEngine?.engine==="chrome",{saving:a,error:i,save:r}=Pt();return e.jsx("div",{"data-testid":"new-browser-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.newBrowser"),tag:t("settings.early.tag"),subtitle:e.jsx(Nt,{short:t("settings.experimental.newBrowserShort"),long:t("settings.experimental.newBrowserDetail")}),message:i?e.jsx("span",{role:"alert",className:"text-danger",children:i}):void 0,children:e.jsx(ie,{checked:n,"aria-label":t("settings.experimental.newBrowserAria"),disabled:a,onClick:()=>{r({browserEngine:{engine:n?"agent-browser":"chrome"}})},className:"disabled:cursor-wait disabled:opacity-50"})})})}function zp(){const{state:s}=_(),n=_o(s.config),{saving:a,error:i,save:r}=Pt();return s.config?.features?.usbPhoneTakeover===void 0?null:e.jsx("div",{"data-testid":"usb-phone-takeover-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.usbPhoneTakeover"),tag:t("settings.early.tag"),subtitle:e.jsx(Nt,{short:t("settings.experimental.usbPhoneTakeoverShort"),long:t("settings.experimental.usbPhoneTakeoverDetail")}),message:i?e.jsx("span",{role:"alert",className:"text-danger",children:i}):void 0,children:e.jsx(ie,{checked:n,"aria-label":t("settings.experimental.usbPhoneTakeover"),disabled:a,onClick:()=>{r({features:{usbPhoneTakeover:!n}})},className:"disabled:cursor-wait disabled:opacity-50"})})})}function _p(){const{state:s,dispatch:n}=_(),a=en(s.config),i=Ho(s.config),r=$o(s.config),c=Ko(s.bots,s.instances),[l,d]=o.useState(String(r)),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(""),h=o.useRef(!1);o.useEffect(()=>{u||d(String(r))},[r,u]);const j=async y=>{if(h.current)return!1;h.current=!0,m(!0),f("");try{const v=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:y})});return n({type:"configStatus",config:v}),!0}catch(v){return f(v instanceof Error?v.message:t("settings.experimental.error")),!1}finally{h.current=!1,m(!1)}},b=async()=>{if(!u)return;const y=Wo(l);if(y===null){f(t("settings.experimental.skillReviewStepsRange",{min:_n,max:zn}));return}await j({skillReviewSteps:y})&&p(!1)};return e.jsxs("div",{"data-testid":"skill-review-settings",className:"contents",children:[e.jsx(L,{title:t("settings.experimental.skillReview"),tag:t("settings.early.tag"),subtitle:a?e.jsx(Nt,{short:t("settings.experimental.skillReviewShort"),long:t("settings.experimental.skillReviewDetail")}):t("settings.experimental.skillReviewNeedsAuthoring"),message:c.length?e.jsx(Hp,{engines:c}):!i&&g?e.jsx("span",{role:"alert",className:"text-danger",children:g}):void 0,children:e.jsx(ie,{checked:i,"aria-label":t("settings.experimental.skillReviewAria"),disabled:x||!a,onClick:()=>{j({skillReview:!i})}})}),i?e.jsxs(L,{title:t("settings.experimental.skillReviewStepsTitle"),message:g?e.jsx("span",{role:"alert",className:"text-danger",children:g}):void 0,children:[e.jsx("input",{id:"skill-review-steps",type:"number","aria-label":t("settings.experimental.skillReviewSteps"),min:_n,max:zn,step:1,inputMode:"numeric",value:l,disabled:x,"aria-invalid":!!g,onChange:y=>{d(y.target.value),p(!0),f("")},onBlur:()=>{b()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:Re}),e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("settings.experimental.skillReviewStepsUnit")})]}):null]})}function Hp({engines:s}){return s.length?e.jsx("span",{className:"block","data-testid":"skill-review-engine-note",children:t("settings.experimental.skillReviewNoEngine",{engines:s.join(", ")})}):null}const $p=[{value:"off",label:"settings.experimental.shareSkillsOff"},{value:"ask",label:"settings.experimental.shareSkillsAsk"},{value:"auto",label:"settings.experimental.shareSkillsAuto"}];function Kp(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState("");if(!Js(s.config))return null;const l=en(s.config),d=Go(s.config),u=async p=>{if(!(a||p===d)){i(!0),c("");try{const x=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:{shareLearnedSkills:p}})});n({type:"configStatus",config:x})}catch(x){c(x instanceof Error?x.message:t("settings.experimental.error"))}finally{i(!1)}}};return e.jsx("div",{"data-testid":"share-learned-skills-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.shareSkills"),tag:t("settings.early.tag"),subtitle:l?e.jsx(Nt,{short:t("settings.experimental.shareSkillsShort"),long:t("settings.experimental.shareSkillsDetail")}):t("settings.experimental.shareSkillsNeedsAuthoring"),message:r?e.jsx("span",{role:"alert",className:"text-danger",children:r}):void 0,children:e.jsx(_i,{value:d,label:t("settings.experimental.shareSkillsAria"),disabled:a||!l,onChange:p=>{u(p)},options:$p.map(p=>({value:p.value,label:t(p.label)}))})})})}function Wp(){return e.jsxs(e.Fragment,{children:[e.jsx(_p,{}),e.jsx(Kp,{})]})}function Gp({title:s=t("settings.updates.title")}){const n=Qs(),a=window.ogb?.updater;if(!n||!a)return null;if(n.managedByStore)return e.jsx(L,{title:s,subtitle:t("settings.updates.fromPackage"),children:null});const i=n.status==="checking"?t("settings.updates.checking"):n.status==="downloading"?n.percent==null?t("settings.updates.startingDownload"):t("settings.updates.downloading",{percent:Math.round(n.percent)}):n.status==="preparing"?t("settings.updates.preparing"):n.status==="downloaded"?n.installMode==="handoff"?t("settings.updates.readyInstall",{app:ke(),version:n.version??""}):t("settings.updates.ready",{app:ke(),version:n.version??""}):n.status==="installing"?$n(n)||(n.installMode==="handoff"?t("settings.updates.openingTerminal"):t("settings.updates.restarting")):n.status==="handed-off"?t("settings.updates.handedOff"):n.status==="error"?t("settings.updates.failed",{message:$n(n)??t("settings.updates.unknownError")}):t("settings.updates.latest");return e.jsx(L,{title:s,subtitle:i,children:e.jsx("button",{onClick:()=>{if(n.status==="downloaded")return void a.install();a.check()},disabled:n.status==="checking"||n.status==="downloading"||n.status==="preparing"||n.status==="installing"||n.retryable===!1,className:"ui-button",children:n.retryable===!1?t("settings.updates.quitReopen"):n.status==="downloaded"?n.installMode==="handoff"?t("settings.updates.install"):t("settings.updates.restart"):n.status==="preparing"?t("settings.updates.preparingShort"):n.status==="installing"?n.installMode==="handoff"?t("settings.updates.opening"):t("settings.updates.restartingShort"):t("settings.updates.check")})})}function qp(){const{state:s,dispatch:n}=_(),a=s.config?.newBots?.effort??"",[i,r]=o.useState(!1),[c,l]=o.useState("");return{current:a,saving:i,error:c,save:async u=>{if(!i){r(!0),l("");try{const p=await D("/api/config",{method:"PATCH",body:JSON.stringify({newBots:{effort:cc(u)?u:null}})});n({type:"configStatus",config:p})}catch(p){l(p instanceof Error?p.message:t("settings.newBotEffort.error"))}finally{r(!1)}}}}}function Vp({effort:s,className:n}){return e.jsxs(de,{size:"sm",className:n,value:s.current,disabled:s.saving,"aria-label":t("settings.newBotEffort.aria"),onChange:a=>{s.save(a.target.value)},children:[e.jsx("option",{value:"",children:t("settings.newBotEffort.default")}),lc.map(a=>e.jsx("option",{value:a,children:oc(a)},a))]})}function Jp(){const s=qp();return e.jsx(L,{title:t("settings.newBotEffort.title"),subtitle:t("settings.newBotEffort.short"),message:s.error?e.jsx("p",{role:"alert",className:"text-danger",children:s.error}):null,children:e.jsx(Vp,{effort:s,className:"w-full max-w-[240px]"})})}function Yp({label:s=t("settings.welcome.appTour")}){const{state:n,dispatch:a}=_(),[i,r]=o.useState(!1),[c,l]=o.useState(!1);return e.jsxs("div",{children:[e.jsx("button",{disabled:i,onClick:()=>{r(!0),l(!1),D("/api/config",{method:"PUT",body:JSON.stringify({onboarding:{...n.config?.onboarding?.completedAt?{}:so().onboarding,hintsSeen:rc(n.config?.onboarding)}}),signal:AbortSignal.timeout(1e4)}).then(d=>{a({type:"configStatus",config:d}),a({type:"toggleTour",open:!0})}).catch(()=>l(!0)).finally(()=>r(!1))},className:"ui-button",children:s}),c&&e.jsx("p",{role:"alert",className:"mt-2 text-[13px] text-danger",children:t("onboarding.tour.error")})]})}function Xp(){const{state:s,dispatch:n}=_();return s.config?.team?null:e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.welcome.appTour"),subtitle:t("settings.welcome.appTourLine"),children:e.jsx(Yp,{label:t("settings.welcome.replayShort")})}),e.jsx(L,{title:t("settings.welcome.replay"),subtitle:t("settings.welcome.subtitleShort"),children:e.jsx("button",{type:"button",onClick:()=>n({type:"toggleWelcome",open:!0}),className:"ui-button",children:t("settings.welcome.replayShort")})})]})}function Tr({simple:s=!1}){const{state:n}=_(),a=Fl(Ul(),n.config?.language);return e.jsx(L,{title:t("settings.language.title"),subtitle:zl()?t("settings.language.subtitleComplete"):s?Ee()==="en"?void 0:t("settings.simple.language.partial"):t("settings.language.subtitle"),children:e.jsxs(de,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:a,"aria-label":t("settings.language.aria"),onChange:i=>Dl(i.target.value),children:[e.jsx("option",{value:"",children:t(s?"settings.simple.language.system":"settings.language.system")}),Ml.map(({code:i,label:r})=>e.jsx("option",{value:i,children:r},i))]})})}function Qp({simple:s=!1}){const n=Hi();return e.jsx(L,{title:t("settings.sendKey.title"),subtitle:t(s?"settings.simple.sendKey":"settings.sendKey.subtitle",{key:Hn("mod-enter")}),children:e.jsx(de,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:n,"aria-label":t("settings.sendKey.title"),onChange:a=>ec(tc(a.target.value)),children:_l.map(a=>e.jsx("option",{value:a,children:Hn(a)},a))})})}function Zp({simple:s=!1}){const n=sc(),a=nc(Hi());return e.jsx(L,{title:t("settings.followUp.title"),subtitle:t(s?"settings.simple.followUp":"settings.followUp.subtitle",{key:a}),children:e.jsxs(de,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:n,"aria-label":t("settings.followUp.title"),onChange:i=>ac(ic(i.target.value)),children:[e.jsx("option",{value:"steer",children:t("settings.followUp.steer")}),e.jsx("option",{value:"queue",children:t("settings.followUp.queue")})]})})}function em({simple:s=!1}){const n=qo();return e.jsx(L,{title:t(s?"settings.userBubbles.simpleTitle":"settings.userBubbles.title"),subtitle:s?void 0:t("settings.userBubbles.subtitle"),children:e.jsx(ie,{checked:n,"aria-label":t("settings.userBubbles.aria"),onClick:()=>Vo(!n)})})}function tm(){const s=Bl();return e.jsx(L,{title:t("settings.threadDisplay.title"),subtitle:t("settings.threadDisplay.short"),children:e.jsx(ie,{checked:s,"aria-label":t("settings.threadDisplay.show"),onClick:()=>Ol(!s)})})}function sm(){const s=Yo();return e.jsx(L,{title:t("settings.pinnedCircles.title"),subtitle:t("settings.pinnedCircles.short"),children:e.jsx(ie,{checked:s,"aria-label":t("settings.pinnedCircles.title"),onClick:()=>Xo(!s)})})}function nm(){const s=Ll();return e.jsx(L,{title:t("settings.runCard.rowTitle"),subtitle:t("settings.runCard.line"),children:e.jsx(ie,{checked:s,"aria-label":t("settings.runCard.show"),onClick:()=>Rl(!s)})})}function am(){const s=Qo();return e.jsx(L,{title:t("settings.universalPins.title"),subtitle:t("settings.universalPins.subtitle"),children:e.jsx(ie,{checked:s,"aria-label":t("settings.universalPins.title"),onClick:()=>Zo(!s)})})}function im(){const{state:s,dispatch:n}=_(),a=Jo(s.config),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=async()=>{if(!i){r(!0),l("");try{const u=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:{showToolCalls:!a}})});n({type:"configStatus",config:u})}catch(u){l(u instanceof Error?u.message:t("settings.toolCalls.error"))}finally{r(!1)}}};return e.jsx(L,{title:t("settings.toolCalls.title"),subtitle:t("settings.toolCalls.short"),message:c?e.jsx("p",{role:"alert",className:"text-danger",children:c}):null,children:e.jsx(ie,{checked:a,"aria-label":t("settings.toolCalls.aria"),disabled:i,onClick:()=>{d()},className:"disabled:cursor-wait disabled:opacity-50"})})}function rm(){const{state:s,dispatch:n}=_(),a=en(s.config),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=async u=>{if(!i){r(!0),l("");try{const p=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:{skillAuthoring:u}})});n({type:"configStatus",config:p})}catch(p){l(p instanceof Error?p.message:t("settings.experimental.error"))}finally{r(!1)}}};return e.jsx(Y,{label:t("settings.experimental.title"),description:t("settings.experimental.short"),block:"early-features",children:e.jsxs(J,{children:[e.jsx(L,{title:t("settings.experimental.skillAuthoring"),tag:t("settings.early.tag"),subtitle:e.jsx(Nt,{short:t("settings.experimental.skillAuthoringShort"),long:t("settings.experimental.skillAuthoringDetail")}),message:c?e.jsx("span",{role:"alert",className:"text-danger",children:c}):void 0,children:e.jsx(ie,{checked:a,"aria-label":t("settings.experimental.skillAuthoringAria"),disabled:i,onClick:()=>{d(!a)},className:"disabled:cursor-wait disabled:opacity-50"})}),e.jsx(Wp,{}),e.jsx(zp,{})]})})}function lm(){const{state:s}=_(),n=s.config?.browserProfiles??[];return!Zt(s.config)&&n.length===0?null:e.jsx(fu,{})}const om={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 cm({entries:s}){return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"font-medium text-ink",children:t("lending.activity.title")}),s&&s.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.activity.empty")}),s&&s.length>0&&e.jsx("ul",{"aria-label":t("lending.activity.title"),className:"flex max-h-56 flex-col gap-1 overflow-y-auto text-[12px]",children:s.map((n,a)=>e.jsxs("li",{className:"flex flex-wrap gap-x-2 text-ink-secondary",children:[e.jsx("time",{dateTime:new Date(n.at).toISOString(),className:"shrink-0 tabular-nums",children:new Date(n.at).toLocaleString(Gs())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(om[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 dm({workspace:s,own:n=!1,onClose:a}){const{state:i}=_(),c=n||$i(i.config)?window.ogb?.computerSharing:void 0,[l,d]=o.useState(null),[u,p]=o.useState([]),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(!1),[b,y]=o.useState(""),[v,w]=o.useState(null),N=o.useRef(!1),C=o.useRef(!1),T=o.useRef(null),F=S=>{d(S),p(S.folders),m(S.terminal),f(S.computer)};o.useEffect(()=>{N.current=!0,T.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(E=>{N.current&&F(E)}).catch(()=>{N.current&&y(t("computerSharing.loadFailed"))});const S=()=>{c?.state(s.id).then(E=>{N.current&&d(E)}).catch(()=>{}),c?.activity?.(s.id).then(E=>{N.current&&w(E)}).catch(()=>{})};S();const P=setInterval(S,3e3);return()=>{N.current=!1,clearInterval(P)}},[c,s.id]);const k=async S=>{if(!C.current){C.current=!0,j(!0),y("");try{await S()}catch(P){N.current&&y(String(P?.message??P).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{C.current=!1,N.current&&j(!1)}}};return c?e.jsx("div",{ref:T,children:e.jsx(xe,{title:t("computerSharing.title",{name:s.name}),subtitle:s.origin,children:e.jsxs("div",{className:"flex flex-col gap-4 text-[13px]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{role:"status",className:"text-ink-secondary",children:l?l.enabled?l.connected?t("computerSharing.sharing"):"Waiting for the workspace to connect":t("computerSharing.notShared"):t("computerSharing.loading")}),e.jsx("button",{type:"button","aria-label":t("computerSharing.close"),onClick:a,className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Oe,{size:16})})]}),e.jsx("p",{className:"text-ink-secondary",children:n?t("computerSharing.ownIntro",{name:s.name}):"Choose what this workspace’s bots can use. Shared files and screen content may be sent to its AI provider. Access stays on when you switch workspaces, until you stop sharing or close the desktop app."}),n&&l?.enabled&&e.jsxs("div",{"data-sharing-pause":!0,className:"flex items-center gap-3 rounded-lg bg-inset px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] text-ink-secondary",children:t(l.paused?"computerSharing.paused":"computerSharing.pauseHint")}),e.jsx("button",{type:"button",disabled:h,onClick:()=>{k(async()=>{await(l.paused?c.resume?.():c.pause?.());const S=await c.state(s.id);N.current&&d(S)})},className:"shrink-0 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t(l.paused?"computerSharing.resume":"computerSharing.pause")})]}),e.jsxs("fieldset",{disabled:h||!l,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:t("computerSharing.folders")}),u.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.noFolders")}),u.map(S=>e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-ink",children:S.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:S.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:S.write,onChange:P=>p(E=>E.map(A=>A.id===S.id?{...A,write:P.target.checked}:A))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:S.name}),onClick:()=>p(P=>P.filter(E=>E.id!==S.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Oe,{size:14})})]},S.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{k(async()=>{const S=await c.chooseFolder();N.current&&S&&p(P=>P.some(E=>E.path===S.path)?P:[...P,S])})},className:"flex w-fit items-center gap-2 rounded-lg border border-hairline/40 px-3 py-2 text-ink hover:bg-control",children:[e.jsx(dc,{size:14}),t("computerSharing.chooseFolder")]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.smallFiles")})]}),e.jsxs("fieldset",{disabled:h||!l,className:"flex flex-col gap-3 border-t border-hairline/40 pt-3 disabled:opacity-50",children:[e.jsx("legend",{className:"font-medium text-ink",children:t("computerSharing.broader")}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:x,onChange:S=>m(S.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.terminal"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.terminalHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:g,onChange:S=>f(S.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.control"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.controlHint")})]})]})]}),(b||l?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:b||l?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:h||!l||!u.length&&!x&&!g,onClick:()=>{k(async()=>{const S=await c.save(s.id,{folders:u,terminal:x,computer:g});N.current&&S&&F(S)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:t(l?.enabled?"computerSharing.save":"computerSharing.share")}),l?.enabled&&e.jsx("button",{type:"button",disabled:h,onClick:()=>{k(async()=>{const S=await c.revoke(s.id);N.current&&F(S)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:t("computerSharing.stop")})]}),l?.enabled&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.stopHint")}),e.jsx("div",{className:"border-t border-hairline/40 pt-3",children:e.jsx(cm,{entries:v})})]})})}):null}const um={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},pm=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function mm(s,n){return s==="docker"?"git pull && ./update.sh":s==="podman-service"?"~/.local/share/openmausbot/update.sh":s==="global"?`npm install -g @seira-bot/seira@${n}`:s==="source"?"git pull && pnpm install":`npx @seira-bot/seira@${n} serve`}function xm({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=Xt(mm(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(Oe,{size:13})})]})}function gm({origin:s,name:n}){const{state:a,copy:i}=Xt(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(He,{size:14}):e.jsx(Vs,{size:14})})}function hm({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:pm(s.since)}):s.state==="signedOut"?t("servers.state.signedOut"):t("servers.state.insecure"),l=s.state==="signedOut"||s.state==="insecure";return e.jsxs("div",{"data-server-state":s.state,className:l||s.state==="cantReach"?"text-[12px] text-danger":"text-[12px] text-ink-secondary",children:[c,s.state==="cantReach"&&r(t("servers.tryNow"),n),s.state==="signedOut"&&r(t("servers.pairAgain"),a),s.state==="insecure"&&r(t("servers.editAddress"),i)]})}function fm({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(ie,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function bm({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:l,onComputerAccess:d,onShare:u=()=>{}}){const p=window.ogb?.environments,[x,m]=o.useState([]),[g,f]=o.useState([]),[h,j]=o.useState(null);o.useEffect(()=>{if(!p?.status)return;let N=!0;const C=()=>{p.status().then(F=>{N&&m(F)}).catch(()=>{})};C();const T=p.onStatus?.(C);return()=>{N=!1,T?.()}},[p,s]);const b=N=>x.find(C=>C.id===N),y=N=>j({address:N.origin,locked:!0,title:t("servers.pairAgainTitle",{name:N.name})}),v=N=>j({address:N.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),w=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(N=>N.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsxs(J,{icons:!0,children:[w.map(N=>{const C=N.id===s.activeId,T=Lt(N)?b(N.id):void 0,F=N.id==="local"?t("servers.localHint"):Lt(N)?`${new URL(N.origin).host} · ${t(um[Hl(N.origin)])}`:N.home?t("servers.managed"):new URL(N.origin).host,k=i.find(P=>P.id===N.id),S=T?.behind===!0&&r!==null&&!g.includes(`${N.id}:${T.version}`);return e.jsxs("div",{"data-server-row":N.id,className:"flex flex-col px-4 py-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center gap-3",children:[N.id==="local"?e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(at,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}):e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center",children:e.jsx(De,{place:{kind:N.home||N.cloud?"cloud":"server",name:N.name,color:N.color??null,named:!0},size:24})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-1.5 truncate text-[14px] leading-5 text-ink",children:N.name}),e.jsx("div",{"data-server-where":!0,className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:F}),e.jsx(hm,{status:T,onTryNow:()=>{p?.retry?.(N.id)},onPairAgain:()=>y(N),onEdit:()=>v(N)})]}),C?e.jsx("span",{className:"shrink-0 text-[13px] leading-5 text-ink-secondary",children:t("servers.current")}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:N.name}),onClick:()=>c(N.id),className:"ui-button shrink-0",children:t("servers.switch")}),Lt(N)&&T?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>y(N),className:"settings-quiet shrink-0 cursor-pointer",children:t("servers.pairAgain")}),N.id!=="local"&&!N.home&&!N.cloud&&!k&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:N.name}),onClick:()=>d(N.id),className:"settings-quiet shrink-0 cursor-pointer",children:t("servers.computerAccess")}),Lt(N)&&e.jsx(gm,{origin:N.origin,name:N.name}),N.id!=="local"&&!N.home&&e.jsx("button",{type:"button",disabled:n,"data-danger":"","aria-label":t("servers.removeName",{name:N.name}),title:t("servers.removeName",{name:N.name}),onClick:()=>l(N.id),className:"settings-quiet shrink-0 cursor-pointer",children:t("remote.devices.removeShort")})]}),k&&e.jsx("div",{className:"pl-11",children:e.jsx(fm,{name:N.name,share:k,busy:n,onShare:P=>u(N.id,P),onOpen:()=>d(N.id)})}),S&&e.jsx("div",{className:"pl-11",children:e.jsx(xm,{name:N.name,status:T,appVersion:r,onHide:()=>f(P=>[...P,`${N.id}:${T.version}`])})})]},N.id)}),e.jsx(je,{title:t("connect.title"),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(Ke,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),onClick:()=>{n||j({address:"",locked:!1,title:t("connect.title")})},data:{"data-server-connect":""}})]}),h&&e.jsx(no,{focusKey:h.locked?"pair-again":"connect",onClose:()=>j(null),children:e.jsx(ao,{onBack:null,onConnected:()=>j(null),start:h})})]})}function vm({label:s,description:n}={}){const a=Ks(),[i,r]=o.useState(!1),c=window.ogb?.environments,{state:l}=_(),d=$i(l.config)&&!!window.ogb?.computerSharing,u=window.ogb?.computerSharing,[p,x]=o.useState([]),[m,g]=o.useState(null),[f,h]=o.useState(!1),[j,b]=o.useState(""),[y,v]=o.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[w,N]=o.useState(""),[C,T]=o.useState(""),[F,k]=o.useState(null),[S,P]=o.useState(!1),[E,A]=o.useState(""),V=o.useRef(!1),R=o.useRef(0);o.useEffect(()=>{const M=++R.current;return c?.state().then($=>{R.current===M&&g($)}).catch(()=>{R.current===M&&b(t("servers.loadFailed"))}),()=>{R.current++}},[c]),o.useEffect(()=>{if(!u?.servers||!m)return;let M=!0;const $=()=>{u.servers().then(ee=>{M&&x(ee)}).catch(()=>{})};$();const Z=setInterval($,5e3);return()=>{M=!1,clearInterval(Z)}},[u,m]);const K=(M,$)=>{te(async()=>{$?await u?.allow?.(M)&&v(M):await u?.revoke(M),u?.servers&&x(await u.servers())})};o.useEffect(()=>{const M=$=>{$&&v($);const Z=new URL(window.location.href);Z.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${Z.pathname}${Z.search}${Z.hash}`)};return M(),c?.onOpenSettings?.(M)},[c]);const te=async(M,$=b)=>{if(V.current||!c)return;V.current=!0,h(!0),b(""),A("");const Z=R.current;try{if(await M()===!0)return;const ee=await c.state();R.current===Z&&g(ee)}catch(ee){R.current===Z&&$(String(ee?.message??ee).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{V.current=!1,R.current===Z&&h(!1)}};if(!c)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const ue=M=>window.ogb?.confirm?window.ogb.confirm(M):window.confirm(M),ae=m?.environments.find(M=>M.id===y),X=ae?.origin&&!ae.home?{id:ae.id,name:ae.name,origin:ae.origin}:void 0,B=!!(X&&p.some(M=>M.id===X.id)),W=m?.environments.filter(M=>M.kind==="local")??[],G=W.find(M=>M.id===F),oe=M=>M.dataDir?M.name:t("connectedWorkspaces.defaultName");return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{label:s,description:n,block:"your-computers",children:[m?e.jsx(bm,{saved:m,busy:f,sharingOffered:d,ownServers:p,appVersion:window.ogb?.app?.version??null,onShare:K,onSwitch:M=>{te(async()=>(await c.switch(M),!0))},onForget:M=>{te(()=>c.forget(M))},onComputerAccess:v}):e.jsx(J,{children:e.jsx(L,{title:t(j?"servers.yours.loadFailed":"servers.yours.loading"),children:null})}),m&&j&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:j})]}),a&&m?.packaged&&e.jsxs(Y,{label:t("connectedWorkspaces.localTitle"),description:t("connectedWorkspaces.localSubtitle"),block:"environments",children:[e.jsxs(J,{icons:!0,children:[W.map(M=>{const $=M.id===m.activeId,Z=G?.id===M.id;return e.jsxs(o.Fragment,{children:[e.jsx(L,{title:oe(M),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(at,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),subtitle:e.jsxs(e.Fragment,{children:[M.dataDir??t("connectedWorkspaces.mainFolder"),M.missing&&e.jsxs(e.Fragment,{children:[" · ",t("connectedWorkspaces.missing")]})]}),children:$?e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("connectedWorkspaces.current")}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:f,"aria-label":t("connectedWorkspaces.switchTo",{name:M.name}),className:"ui-button",onClick:()=>{te(async()=>{if(!await ue(t("connectedWorkspaces.switchConfirm",{name:M.name})))return;const ee=await c.switch(M.id);if(ee&&ee.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},A)},children:t("connectedWorkspaces.switch")}),!G&&e.jsx("button",{type:"button",disabled:f,"data-danger":"","aria-label":t("connectedWorkspaces.forgetName",{name:M.name}),className:"settings-quiet cursor-pointer",onClick:()=>{k(M.id),P(!1)},children:t("connectedWorkspaces.forget")})]})}),Z&&G&&e.jsxs("div",{"data-env-forget":"",className:"flex flex-col gap-2 py-3 pl-[60px] pr-4",children:[e.jsxs("span",{className:"flex items-center justify-between gap-6 text-[12px] leading-4 text-ink-secondary",children:[t("connectedWorkspaces.forgetPurge",{path:G.dataDir??""}),e.jsx(ie,{checked:S,disabled:f,"aria-label":t("connectedWorkspaces.forgetPurge",{path:G.dataDir??""}),onClick:()=>P(!S)})]}),e.jsxs("span",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k(null),className:"ui-button",children:t("connectedWorkspaces.cancel")}),e.jsx("button",{type:"button",disabled:f,"data-danger":"",onClick:()=>{te(async()=>{const ee=S?await c.forget(G.id,!0):await c.forget(G.id);if(ee&&ee.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));k(null)},A)},className:"ui-button !bg-danger !text-danger-ink",children:t("connectedWorkspaces.forget")})]})]})]},M.id)}),e.jsx(wt,{id:"new-environment",title:t("connectedWorkspaces.newEnvironment"),open:i,onToggle:()=>r(!i),leading:e.jsx("span",{"aria-hidden":"true",className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(Ke,{size:18,strokeWidth:1.75})}),children:e.jsxs("form",{className:"flex flex-col gap-3 py-3 pl-[60px] pr-4",onSubmit:M=>{M.preventDefault(),w.trim()&&te(async()=>{if(!(await c.create(w.trim(),C.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));N(""),T("")},A)},children:[e.jsx(fe,{label:t("connectedWorkspaces.name"),children:e.jsx("input",{required:!0,value:w,disabled:f,maxLength:60,onChange:M=>N(M.target.value),placeholder:t("connectedWorkspaces.environmentPlaceholder"),className:he})}),e.jsx(fe,{label:t("connectedWorkspaces.dataFolder"),children:e.jsxs("span",{className:"flex gap-2",children:[e.jsx("input",{value:C,disabled:f,onChange:M=>T(M.target.value),placeholder:t("connectedWorkspaces.defaultFolder"),className:he}),e.jsx("button",{type:"button",disabled:f,className:"ui-button shrink-0 self-center",onClick:()=>{te(async()=>{const M=await c.pickDir();M?.ok&&M.path&&T(M.path)},A)},children:t("connectedWorkspaces.choose")})]})}),e.jsxs("button",{type:"submit",disabled:f||!w.trim(),className:"ui-button gap-2 self-end",children:[f&&e.jsx(ce,{size:14,className:"animate-spin"}),t("connectedWorkspaces.create")]})]})})]}),E&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:E})]}),(d||B)&&X&&e.jsx(dm,{workspace:X,own:B,onClose:()=>v(null)},X.id)]})}const Ir=s=>({method:"PUT",body:JSON.stringify(s)}),qt=s=>s instanceof Error?s.message:String(s);function ym(){return o.useSyncExternalStore(cr,()=>cu()?.id??null,()=>null)}function jm(s,n){const a=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"application/json"}));Object.assign(document.createElement("a"),{href:a,download:s}).click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function km({id:s,act:n,onClose:a,onDelete:i}){const[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(!1);if(o.useEffect(()=>{D(`/api/themes/${s}`).then(g=>c(g.theme),g=>d(qt(g)))},[s]),!r)return e.jsx(Se,{children:l??t("settings.customThemes.loading")});const x=r.css?du(r.css):null,m=async()=>{p(!0);try{await D(`/api/themes/${s}`,Ir({theme:{...r,name:r.name.trim(),css:r.css||void 0}})),d(t("settings.customThemes.saved")),await an()}catch(g){d(qt(g))}finally{p(!1)}};return e.jsxs("div",{"data-settings-block":"theme-editor",className:"flex flex-col gap-3 px-4 py-3",children:[e.jsx(fe,{label:t("settings.customThemes.name"),children:e.jsx("input",{className:he,value:r.name,maxLength:60,onChange:g=>c({...r,name:g.target.value})})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:["canvas","accent"].map(g=>e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"color",className:"size-7 cursor-pointer rounded-md bg-transparent",value:r[g]??(g==="canvas"?"#121212":"#1084fe"),onChange:f=>c({...r,[g]:f.target.value})}),t(g==="canvas"?"settings.customThemes.canvas":"settings.customThemes.accent"),r[g]&&e.jsx("button",{type:"button",className:"text-[12px] text-accent-text hover:underline",onClick:()=>c({...r,[g]:void 0}),children:t("settings.customThemes.clear")})]},g))}),e.jsx(fe,{label:t("settings.customThemes.css"),hint:x??t("settings.customThemes.cssHint"),children:e.jsx("textarea",{className:`${he} h-64 resize-y py-2 font-mono text-[12px]`,spellCheck:!1,maxLength:uu.cssChars,"aria-label":t("settings.customThemes.css"),value:r.css??"",onChange:g=>c({...r,css:g.target.value})})}),e.jsxs(es,{status:l,children:[e.jsxs("div",{className:"mr-auto flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(()=>D(`/api/themes/${s}/duplicate`,{method:"POST",body:JSON.stringify({name:t("settings.customThemes.copyName",{name:r.name}).slice(0,60)})}))},children:t("settings.customThemes.duplicate")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(async()=>jm(`${s}.mausbot-theme.json`,await D(`/api/themes/${s}/export`)))},children:t("settings.customThemes.export")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm","data-danger":"",onClick:i,children:t("common.delete")})]}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:u||!!x||!r.name.trim(),onClick:()=>{m()},children:t("common.save")})]})]})}const wm=6;function Nm(s){const n=s.name??"";switch(s.kind){case"made":return t("settings.customThemes.historyMade",{name:n});case"edited":return t("settings.customThemes.historyEdited",{name:n});case"deleted":return t("settings.customThemes.historyDeleted",{name:n});case"wore":return t("settings.customThemes.historyWore",{name:n});case"skin":return t("settings.customThemes.historySkin",{name:ft.find(a=>a.id===n)?.name??n});case"default":return t("settings.customThemes.historyDefault");case"undid":return t("settings.customThemes.historyUndid")}}function Sm({items:s,act:n}){return s.length<2?null:e.jsx(Y,{label:t("settings.customThemes.history"),block:"theme-history",description:t("settings.customThemes.historyHint"),children:e.jsx(J,{children:s.slice(0,wm).map(a=>e.jsx(L,{title:Nm(a),subtitle:pr(Date.parse(a.at)),children:a.index===1?e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:t("settings.customThemes.historyNow")}):e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{n(async()=>{await D("/api/themes/history",{method:"POST",body:JSON.stringify({index:a.index})}),await an()})},children:t("settings.customThemes.restore")})},a.index))})})}function Cm(){const[s,n]=o.useState(null),[a,i]=o.useState(null),[r,c]=o.useState(null),l=o.useRef(null),d=ym(),[u,p]=o.useState([]),x=o.useCallback(()=>Promise.all([D("/api/themes").then(n,b=>c(qt(b))),D("/api/themes/history").then(b=>p(b.items),()=>p([]))]),[]);o.useEffect(()=>(x(),cr(()=>{x()})),[x]);const m=async b=>{c(null);try{await b()}catch(y){c(qt(y))}await x()},g=()=>m(async()=>{const b=`theme-${Date.now().toString(36)}`;await D(`/api/themes/${b}`,Ir({theme:{name:t("settings.customThemes.newName")}})),i(b)}),f=b=>b&&m(async()=>{let y;try{y=JSON.parse(await b.text())}catch{throw new Error(t("settings.customThemes.importFailed"))}await D("/api/themes/import",{method:"POST",body:JSON.stringify(y)})}),h=(b,y)=>m(async()=>{const v=await D(`/api/themes/${b}/export`);await D(`/api/themes/${b}`,{method:"DELETE"}),i(null),await an(),c(e.jsxs(e.Fragment,{children:[t("settings.customThemes.deleted",{name:y})," ",e.jsx("button",{type:"button",className:"text-accent-text hover:underline",onClick:()=>{m(()=>D("/api/themes/import",{method:"POST",body:JSON.stringify(v)}))},children:t("common.undo")})]}))}),j=ur()?"⌘⌥⇧R":"Ctrl+Alt+Shift+R";return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.customThemes.title"),block:"custom-themes",description:t("settings.customThemes.description"),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>l.current?.click(),children:t("settings.customThemes.import")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{g()},children:t("settings.customThemes.new")}),e.jsx("input",{ref:l,type:"file",accept:"application/json,.json",hidden:!0,onChange:b=>{f(b.target.files?.[0]),b.target.value=""}})]}),footnote:r,children:e.jsxs(J,{children:[lu()&&e.jsx(Se,{children:t("settings.customThemes.safe")}),s&&!s.themes.length&&e.jsx(Se,{children:t("settings.customThemes.empty")}),s?.themes.map(b=>a===b.id?e.jsx(km,{id:b.id,act:m,onClose:()=>{i(null),x()},onDelete:()=>{h(b.id,b.name)}},b.id):e.jsx(L,{title:b.name,subtitle:d===b.id?t("settings.customThemes.inUse"):b.assets.length?t("settings.customThemes.files",{count:b.assets.length}):void 0,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>i(b.id),children:t("settings.customThemes.edit")}),d===b.id?e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{m(()=>ra(null))},children:t("settings.customThemes.takeOff")}):e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>{m(()=>ra(b.id))},children:t("settings.customThemes.use")})]})},b.id)),e.jsx(L,{title:t("settings.customThemes.reset"),subtitle:t("settings.customThemes.resetHint",{keys:j}),children:e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{ou(),x()},children:t("settings.customThemes.reset")})})]})}),e.jsx(Sm,{items:u,act:m})]})}function Em({simple:s=!1}){const[n,a]=o.useState(!1),[i,r]=o.useState(null),[c,l]=o.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const x=await window.ogb.exportDiagnostics();x&&r({kind:"success",message:t("settings.diagnostics.saved",{path:x})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}finally{a(!1)}}},u=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const x=await window.ogb.openLogsFolder();l(x.folder),x.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:x.folder})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}}},p=!!window.ogb?.exportDiagnostics;return e.jsx(L,{title:t("settings.app.diagnostics"),subtitle:e.jsxs(e.Fragment,{children:[t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),p&&window.ogb?.openLogsFolder&&e.jsxs(e.Fragment,{children:[" ",e.jsx(ze,{label:t("settings.diagnostics.openLogs"),onClick:()=>{u()}})]})]}),message:c||i||!p?e.jsxs(e.Fragment,{children:[c&&i?.kind!=="error"&&e.jsx("p",{role:"status","data-logs-folder":!0,className:"break-all text-ink-secondary",children:t("settings.diagnostics.logsAt",{folder:c})}),i&&e.jsx("p",{role:i.kind==="error"?"alert":"status",className:z("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),!p&&e.jsx("p",{"data-logs-help":!0,className:"text-ink-secondary",children:t("settings.diagnostics.elsewhere")})]}):void 0,children:p&&e.jsx("button",{type:"button",onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})})}function Lr({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(Am,{simple:s}),e.jsx(Pm,{simple:s}),e.jsx(Tm,{simple:s})]})}const ka=()=>typeof Notification<"u"?Notification.permission:"default";function Am({simple:s=!1}){const[n,a]=o.useState(ka),i=uc();if(o.useEffect(()=>{const l=()=>{document.visibilityState==="visible"&&a(ka())};return window.addEventListener("focus",l),document.addEventListener("visibilitychange",l),()=>{window.removeEventListener("focus",l),document.removeEventListener("visibilitychange",l)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return Kn(!i);const l=await hc();l&&(a(l),l==="granted"&&Kn(!0))};return e.jsx(L,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(ie,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function Pm({simple:s=!1}){const n=pc();return e.jsx(L,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(ie,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>mc(!n)})})}function Tm({simple:s=!1}){const n=xc();return e.jsx(L,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(ie,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>gc(!n)})})}function Im({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=o.useState(null),[r,c]=o.useState(!1),[l,d]=o.useState(!1);if(o.useEffect(()=>{let p=!0;return n?.state().then(x=>{p&&i(x)}).catch(()=>{}),()=>{p=!1}},[n]),!n||!a)return null;if(a.startupApps)return e.jsx(L,{title:t("settings.openAtLogin.title"),subtitle:t("settings.openAtLogin.startupApps"),children:null});if(!a.available)return null;const u=p=>{c(!0),d(!1),n.set(p).then(i,()=>d(!0)).finally(()=>c(!1))};return e.jsx(L,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:l?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(ie,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>u(!a.on)})})}function Lm(){const s=$l(),[n,a]=o.useState(""),[i,r]=o.useState(""),[c,l]=o.useState(""),d=s.length>=Tn,[u,p]=o.useState(!1),x=()=>{const g=Kl({name:n,url:i},window.location.origin);return g.ok?(In([...s,{id:Wl(s),name:g.name,url:g.url}]),a(""),r(""),l(""),!0):(l(g.error),!1)},m=()=>{p(!1),a(""),r(""),l("")};return e.jsxs(Y,{label:t("webPanels.settings.title"),block:"pinned-panels",description:t("webPanels.settings.short"),actions:e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:()=>p(!0),children:t("webPanels.settings.addPage")}),footnote:d?t("webPanels.settings.full",{max:Tn}):t("webPanels.settings.help"),children:[e.jsxs(J,{children:[s.length===0&&e.jsx(Se,{children:t("webPanels.settings.empty")}),s.map(g=>e.jsx(L,{title:g.name,subtitle:e.jsx("span",{className:"block truncate",title:g.url,children:g.url??t("webPanels.settings.chatPage")}),children:e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>In(s.filter(f=>f.id!==g.id)),children:t("webPanels.settings.remove")})},g.id))]}),u&&e.jsxs(St,{title:t("webPanels.settings.addPage"),onClose:m,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:m,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:d,onClick:()=>{x()&&m()},children:t("webPanels.settings.add")})]}),children:[e.jsx(fe,{label:t("webPanels.settings.name"),children:e.jsx("input",{value:n,maxLength:Ln,"aria-invalid":c==="name",onChange:g=>{a(g.target.value),l("")},className:z(he,c==="name"&&"border-danger/60")})}),e.jsx(fe,{label:t("webPanels.settings.url"),children:e.jsx("input",{placeholder:"https://",type:"url",inputMode:"url",value:i,"aria-invalid":c==="url"||c==="self",onChange:g=>{r(g.target.value),l("")},onKeyDown:g=>{g.key==="Enter"&&x()&&m()},className:z(he,(c==="url"||c==="self")&&"border-danger/60")})}),c&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:Ln})})]})]})}const gs="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";function wa(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Rm(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=Gl(n);return a.ok&&(a.code!==null||a.credential!==null)}function Bm({hideWhenUnavailable:s=!1,legacyOnly:n=!1}){const a=window.ogb?.remoteClient,i=window.ogb?.environments,[r,c]=o.useState({active:a?.active===!0}),[l,d]=o.useState(i?"server":"companion"),[u,p]=o.useState(""),[x,m]=o.useState(""),[g,f]=o.useState(""),[h,j]=o.useState(!1),[b,y]=o.useState(""),v=o.useRef(!1),w=!!i&&l==="server",N=o.useRef(!0),C=o.useCallback(()=>{a?.state().then(k=>{N.current&&c(k)}).catch(()=>{})},[a]);o.useEffect(()=>(N.current=!0,C(),()=>{N.current=!1}),[C]);const T=async()=>{if(!(v.current||!a&&!i)){v.current=!0,j(!0),y("");try{if(w&&i){if(!Rm(u))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(u.trim()),C()}else a&&(await a.pair(x,g),C())}catch(k){y(wa(k))}finally{v.current=!1,j(!1)}}},F=async()=>{if(!(!a||v.current)){v.current=!0,j(!0),y("");try{await a.disconnect(),C()}catch(k){y(wa(k))}finally{v.current=!1,j(!1)}}};return!a&&!i&&s||n&&!r.active?null:e.jsxs(xe,{title:r.active?t("remote.client.active"):t("remote.client.idle"),subtitle:t("remote.client.subtitle"),children:[!a&&!i?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.client.desktopOnly")}):r.active?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-success/25 bg-success/10 px-3 py-3",children:[e.jsx(at,{size:18,className:"mt-0.5 shrink-0 text-success"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:t("remote.client.connected",{name:r.serverName||t("remote.client.fallbackName")})}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:r.endpoint})]})]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.mode")}),e.jsx("p",{role:"status",className:"rounded-lg bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink","data-legacy-client-notice":"",children:t("remote.client.endsDec7")}),e.jsxs("button",{type:"button",disabled:h,onClick:()=>{F()},className:"flex w-fit items-center gap-2 rounded-lg border border-danger/30 px-3 py-2 text-[13px] text-danger hover:bg-danger/10 disabled:opacity-50",children:[h?e.jsx(ce,{size:14,className:"animate-spin"}):e.jsx(Eu,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:k=>{k.preventDefault(),T()},children:[i&&a?e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.connectionType"),e.jsxs(de,{value:l,disabled:h,onChange:k=>{d(k.target.value),y("")},className:"w-full",children:[e.jsx("option",{value:"server",children:t("remote.client.server.option")}),e.jsx("option",{value:"companion",children:t("remote.client.companion.option")})]})]}):null,w?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.server.hint")}),e.jsxs("div",{"data-pair-access":"full",className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("remote.client.server.fullTitle")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx @seira-bot/seira pair"})]}),e.jsxs("div",{"data-pair-access":"client",className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("remote.client.server.clientTitle")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx @seira-bot/seira pair --client"}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("remote.client.server.clientNote")})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.server.pairingLink"),e.jsx("input",{value:u,onChange:k=>p(k.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:h,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:gs})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("remote.client.server.domainHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.companion.hint")}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.address"),e.jsx("input",{value:x,onChange:k=>m(k.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:h,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:gs})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.code"),e.jsx("input",{value:g,onChange:k=>f(k.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:h,inputMode:"numeric",autoComplete:"one-time-code",className:`${gs} max-w-40 font-mono tracking-[0.2em]`})]})]}),b?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:b}):null,e.jsxs("button",{type:"submit",disabled:h||(w?!u.trim():x.trim()===""||g.length!==6),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[h?e.jsx(ce,{size:14,className:"animate-spin"}):e.jsx(at,{size:14}),w?t("remote.client.server.connect"):t("remote.client.pair")]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:w?t("remote.client.server.switchNote"):t("remote.client.restartNote")})]}),r.active&&b?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:b}):null]})}const Na=[{choice:"system",label:"settings.theme.system"},{choice:Rn.light,label:"settings.theme.light"},{choice:Rn.dark,label:"settings.theme.dark"}];function pn(){return o.useSyncExternalStore(Vl,Bn,Bn)}function Om({simple:s=!1}){const n=pn(),a=Na.some(i=>i.choice===n)?void 0:ft.find(i=>i.id===n)?.name;return e.jsx(L,{title:t(s?"settings.theme.lightOrDark":"settings.theme.title"),subtitle:a?t("settings.theme.look",{name:a}):s?void 0:t("settings.theme.subtitle"),children:e.jsx("div",{role:"radiogroup","aria-label":t(s?"settings.theme.lightOrDark":"settings.theme.title"),className:s?"inline-flex h-7 rounded-full bg-ink/[0.06] p-0.5":"inline-flex rounded-full bg-inset p-0.5",children:Na.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>ql(i.choice),className:s?z("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"):z("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 Sa({skin:s}){return e.jsxs("div",{"data-skin":s,"data-skin-preview":"","aria-hidden":"true",className:"flex h-[78px] w-full overflow-hidden rounded-lg bg-app ring-1 ring-hairline/60",children:[e.jsxs("div",{className:"flex w-[11px] shrink-0 flex-col items-center gap-[3px] bg-panel pt-[5px]",children:[e.jsx("span",{className:"size-[5px] rounded-full bg-accent"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"flex w-[30px] shrink-0 flex-col gap-[3px] border-r border-hairline bg-panel p-[4px]",children:[e.jsxs("span",{className:"flex h-[9px] w-full items-center gap-[2px] rounded-sm bg-raised px-[2px]",children:[e.jsx("span",{className:"size-[4px] shrink-0 rounded-full bg-accent"}),e.jsx("span",{className:"h-[2px] flex-1 rounded-full bg-ink/50"})]}),e.jsx("span",{className:"h-[3px] w-[80%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[62%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[74%] rounded-full bg-ink-secondary/30"})]}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[4px] p-[6px]",children:[e.jsx("span",{className:"h-[13px] w-[62%] self-end rounded-md bg-bubble-user"}),e.jsxs("div",{className:"flex w-[88%] flex-col gap-[3px] rounded-md bg-card p-[4px]",children:[e.jsx("span",{className:"h-[2px] w-full rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[85%] rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[60%] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"mt-auto flex items-center gap-[4px]",children:[e.jsx("span",{className:"h-[11px] flex-1 rounded-full bg-inset ring-1 ring-hairline"}),e.jsx("span",{className:"flex size-[11px] items-center justify-center rounded-full bg-accent",children:e.jsx("span",{className:"h-[1.5px] w-[5px] rounded-full",style:{background:"var(--color-accent-ink)"}})})]})]})]})}function Fm(){const s=Ei(pn());return o.useContext(Ae)?e.jsx(e.Fragment,{children:e.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-4 sm:grid-cols-4",role:"radiogroup","aria-label":t("settings.theme.title"),children:ft.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",role:"radio","aria-checked":i,onClick:()=>{Fn(a.id),la()},title:On(`skins.tagline.${a.id}`,a.tagline),className:"group flex cursor-pointer flex-col gap-2 rounded-lg text-left focus-visible:outline-none",children:[e.jsxs("span",{className:z("relative block rounded-lg ring-offset-2 ring-offset-(--color-menu) [&>[data-skin-preview]]:h-20 [&>[data-skin-preview]]:ring-0","after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:shadow-[inset_0_0_0_0.5px_var(--settings-edge)] after:content-['']",i?"ring-2 ring-ink":"group-hover:ring-[0.5px] group-hover:ring-ink/25 group-focus-visible:ring-2 group-focus-visible:ring-focus"),children:[e.jsx(Sa,{skin:a.id}),i&&e.jsx("span",{"aria-hidden":"true","data-skin-check":"",className:"absolute -right-2 -top-2 flex size-4 items-center justify-center rounded-full bg-ink text-app",children:e.jsx(He,{size:12,strokeWidth:2.5})})]}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink",children:a.name})]},a.id)})})}):e.jsx(e.Fragment,{children:e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:ft.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Fn(a.id),la()},"aria-pressed":i,className:z("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",i?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Sa,{skin:a.id}),e.jsxs("div",{className:"flex items-start gap-1.5 px-0.5 pb-0.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:On(`skins.tagline.${a.id}`,a.tagline)})]}),i&&e.jsx(He,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},a.id)})})})}function Um(){const s=window.ogb?.talkShortcut,[n,a]=o.useState(null),[i,r]=o.useState(!1),[c,l]=o.useState(!1);if(o.useEffect(()=>{let m=!0;return s?.state().then(g=>{m&&a(g)}).catch(()=>{}),()=>{m=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(m=>m.id===n.key)?.label??"",u=m=>{r(!0),l(!1),s.set(m).then(a,()=>l(!0)).finally(()=>r(!1))},p=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,x=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(de,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:m=>u({key:m.target.value}),children:n.keys.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id))}),p&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:p})]});return e.jsx(L,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||p?x:null,children:e.jsx(ie,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>u({enabled:!n.enabled})})})}function Mm(){const{capabilities:s}=Ri(),n=typeof window>"u"?void 0:window.ogb?.windowFrame,[a,i]=o.useState(null);o.useEffect(()=>{if(!n)return;let d=!0;return n.state().then(u=>{d&&i(u)}).catch(()=>{}),()=>{d=!1}},[n]);const r=s.host?.platform;if(!n||!a||r!=="darwin"&&r!=="win32")return null;const c=window.ogb?.relaunch,l=()=>{n.set(!a.on).then(i).catch(()=>{})};return e.jsxs("div",{"data-window-frame-switch":!0,children:[e.jsx(L,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(ie,{checked:a.on,"aria-label":t("settings.windowFrame.title"),onClick:l})}),a.restart&&e.jsxs("div",{role:"status","data-window-frame-restart":!0,className:"flex flex-wrap items-center gap-x-3 gap-y-1 px-4 pb-3 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:t("settings.windowFrame.restart",{app:ke()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}const Dm=(s,n)=>n.desktop&&!n.client&&!n.here&&!n.home&&!s;function zm(){const{ctx:s}=Ne(),{dispatch:n}=_(),[a,i]=o.useState(!1),r=s.desktop&&!s.client,c=At(),l=Kt($t());return e.jsxs(e.Fragment,{children:[s.desktop&&e.jsx(Y,{label:t("settings.updates.title"),block:"updates",children:e.jsx(J,{children:window.ogb?.updater?e.jsx(Gp,{title:l}):s.home||s.client?e.jsx(L,{title:l,subtitle:t("settings.updates.fromPackage"),children:null}):e.jsx(ct,{title:l,reason:t("settings.inert.checkFromHere",{place:c.name}),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.updates.check")})})})}),!s.advanced&&e.jsx(Y,{label:t("settings.app.languageNotifications"),block:"typing",children:e.jsxs(J,{selectWidth:208,children:[e.jsx(Tr,{simple:!0}),e.jsx(Lr,{simple:!0})]})}),s.desktop&&s.advanced&&(window.ogb?.environments?e.jsx(vm,{label:t("settings.app.computers"),description:t("settings.app.computersLine")}):!s.client&&e.jsx(_m,{})),s.desktop&&s.advanced&&e.jsx(Bm,{hideWhenUnavailable:!0,legacyOnly:!0}),e.jsx(Y,{label:t("sidebar.menu.helpShort"),block:"help",children:e.jsxs(J,{children:[e.jsx(je,{title:t("sidebar.menu.help"),external:!0,onClick:()=>{Ps(Si)}}),s.advanced&&e.jsx(je,{title:t("sidebar.menu.feedback"),external:!0,onClick:()=>{Ps(Jl)}}),s.advanced&&e.jsx(je,{title:t("sidebar.menu.shortcuts"),onClick:()=>{n({type:"toggleAppSettings",open:!1}),n({type:"toggleShortcuts",open:!0})}}),s.advanced&&!s.client&&e.jsx(Xp,{}),r&&s.advanced&&(window.ogb?.exportDiagnostics?e.jsx(Em,{simple:!0}):e.jsx(ct,{title:t("settings.app.diagnostics"),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.diagnostics.export")})})),e.jsx("div",{"data-settings-block":"about",className:"contents",children:e.jsx(je,{title:t("settings.app.about",{app:ke()}),onClick:()=>i(!0)})})]})}),e.jsx(bc,{open:a,onClose:()=>i(!1)})]})}function _m(){const{place:s}=Ne(),n=Et("app"),a=window.ogb?.workspaces;return a?e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.app.computers"),description:t("settings.app.computersLine"),block:"your-computers",children:e.jsxs(J,{icons:!0,children:[e.jsx(L,{title:s.name,leading:e.jsx(De,{place:s,size:24}),subtitle:t("servers.managed"),children:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("servers.current")})}),n.map(i=>e.jsx(L,{title:i.name,leading:e.jsx(De,{place:{kind:i.kind==="computer"?"computer":"cloud",name:i.name,color:i.color},size:24}),subtitle:i.kind==="computer"?t("servers.localHint"):void 0,children:e.jsx("button",{type:"button",className:"ui-button","data-place-switch":i.key,onClick:i.open,children:t("servers.switch")})},i.key)),a.add&&e.jsx(je,{title:t("connect.title"),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(Ke,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),onClick:()=>{a.add?.("address")},data:{"data-server-connect":""}})]})}),e.jsx(Y,{label:t("connectedWorkspaces.localTitle"),block:"environments",children:e.jsx(J,{children:e.jsx(ct,{title:t("connectedWorkspaces.newEnvironment")})})})]}):null}function Hm(){const{ctx:s,place:n,go:a}=Ne();return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.simple.group.typing"),block:"typing",children:e.jsxs(J,{selectWidth:208,children:[e.jsx(Tr,{simple:!0}),e.jsx(Qp,{simple:!0}),e.jsx(Zp,{simple:!0}),window.ogb?.talkShortcut?e.jsx(Um,{}):Dm(window.ogb?.talkShortcut,s)&&s.cloud?e.jsx(ct,{title:t("settings.search.talk"),control:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("settings.general.talkOff")})}):null]})}),e.jsx(Y,{label:t("notifications.title"),block:"notifications",footnote:!s.client&&e.jsxs(e.Fragment,{children:[t("settings.general.awayEmails")," ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent-text hover:underline",onClick:()=>a("bots","about-you"),children:`${n.name} › ${t("settings.page.bots")}`})]}),children:e.jsx(J,{children:e.jsx(Lr,{simple:!0})})}),s.desktop&&!s.client&&e.jsx(Y,{label:t("settings.general.startup"),block:"startup",children:e.jsx(J,{children:window.ogb?.openAtLogin?e.jsx(Im,{simple:!0}):e.jsx(ct,{title:t("settings.openAtLogin.title"),control:e.jsx(ie,{checked:!1,tabIndex:-1,"aria-label":t("settings.openAtLogin.title")})})})}),e.jsx(Y,{label:t("settings.general.privacy"),block:"privacy",children:e.jsx(J,{children:e.jsx(Lp,{simple:!0})})})]})}function $m({open:s,onToggle:n}){const a=pn(),i=ft.find(r=>r.id===Ei(a))?.name;return e.jsx(L,{title:t("settings.theme.title"),subtitle:a==="system"?t("settings.simple.themes.followHint"):i,children:e.jsx("button",{type:"button",className:"ui-button","aria-expanded":s,"data-settings-themes":"",onClick:n,children:t(s?"settings.appearance.hideThemes":"settings.simple.themes.browse")})})}function Km(){const{ctx:s,place:n,go:a,anchor:i}=Ne(),[r,c]=o.useState(i==="themes");return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.appearance.look"),block:"look",children:e.jsxs(J,{children:[e.jsx(Om,{simple:!0}),e.jsx($m,{open:r,onToggle:()=>c(l=>!l)}),r&&e.jsx("div",{"data-settings-block":"themes",className:"p-4",children:e.jsx(Fm,{})}),e.jsx(em,{simple:!0}),!s.client&&e.jsx(je,{title:t("placeLook.sidebarColor"),value:n.name,badge:e.jsx(De,{place:n,size:14}),onClick:()=>a("overview","sidebar"),data:{"data-settings-door":"sidebar-color"}})]})}),e.jsx(Cm,{}),e.jsx(Y,{label:t("settings.appearance.chat"),block:"chat",children:e.jsxs(J,{children:[!s.client&&e.jsx(im,{}),s.advanced&&e.jsx(nm,{}),s.advanced&&e.jsx(Bp,{}),s.advanced&&e.jsx(Rp,{})]})}),s.advanced&&e.jsx(Y,{label:t("settings.appearance.layout"),block:"appearance",children:e.jsxs(J,{children:[e.jsx(fc,{}),e.jsx(Mm,{}),s.advanced&&e.jsx(tm,{}),s.advanced&&e.jsx(Op,{}),s.advanced&&e.jsx(sm,{}),s.advanced&&e.jsx(am,{})]})}),s.advanced&&e.jsx(Lm,{})]})}const hs="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function Ca({entry:s}){const[n,a]=o.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString(Gs())}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:vu(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:yu(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:vc(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(Ct,{size:12,className:z("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:ua(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:ua(s.after?.[r])})]},r))]})]})]})})}function Wm(){const[s,n]=o.useState({who:"",what:"all",from:"",to:""}),[a,i]=o.useState([]),[r,c]=o.useState(0),[l,d]=o.useState(null),[u,p]=o.useState(!1),[x,m]=o.useState(null),g=bu(s),f=o.useContext(Ae),h=o.useCallback(async()=>{p(!0),m(null);try{const b=await D(`/api/admin-activity${g}`);i(b.entries),c(b.total),d(b.retentionDays)}catch(b){m(b instanceof Error?b.message:String(b))}finally{p(!1)}},[g]);o.useEffect(()=>{const b=window.setTimeout(()=>{h()},250);return()=>window.clearTimeout(b)},[h]);const j=b=>n(y=>({...y,...b}));return f?e.jsxs(Y,{label:t("settings.section.activity"),block:"activity",footnote:t("activity.subtitle",{days:String(l??180)}),actions:e.jsx("a",{href:`/api/admin-activity.csv${g}`,download:!0,className:"ui-button ui-button-md rounded-full",children:t("activity.export")}),children:[e.jsxs(J,{children:[e.jsx(L,{title:t("activity.who"),children:e.jsx("input",{value:s.who,onChange:b=>j({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),"aria-label":t("activity.who"),className:z(Re,"w-[200px] text-left")})}),e.jsx(L,{title:t("activity.what"),children:e.jsx(de,{value:s.what,onChange:b=>j({what:b.target.value}),"aria-label":t("activity.what"),children:da.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})}),e.jsxs(L,{title:t("activity.dates"),children:[e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>j({from:b.target.value}),"aria-label":t("activity.from"),className:z(Re,"w-[140px] text-left")}),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>j({to:b.target.value}),"aria-label":t("activity.to"),className:z(Re,"w-[140px] text-left")})]}),e.jsx(es,{status:x?e.jsx("span",{role:"alert",className:"text-danger",children:t("activity.error",{message:x})}):r>a.length?t("activity.more",{shown:String(a.length),total:String(r)}):void 0,children:e.jsx("button",{type:"button",onClick:()=>{h()},disabled:u,className:"settings-quiet cursor-pointer",children:u?t("common.checking"):t("activity.refresh")})})]}),e.jsxs(J,{children:[!x&&a.length===0&&!u&&e.jsx(Se,{children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"flex flex-col px-4 py-1",children:a.map((b,y)=>e.jsx(Ca,{entry:b},`${b.at}-${y}`))})]})]}):e.jsxs(xe,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(l??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:b=>j({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),className:z(hs,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(de,{value:s.what,onChange:b=>j({what:b.target.value}),children:da.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>j({from:b.target.value}),className:hs})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>j({to:b.target.value}),className:hs})]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:u,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:u?e.jsx(ce,{size:14,className:"animate-spin"}):e.jsx(bt,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${g}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Ki,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:x})}),!x&&a.length===0&&!u&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((b,y)=>e.jsx(Ca,{entry:b},`${b.at}-${y}`))}),r>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(r)})})]})}const fs=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function Gm(){const[s,n]=o.useState(null),[a,i]=o.useState(!1),[r,c]=o.useState(!1),[l,d]=o.useState(null);if(o.useEffect(()=>{let p=!0;return D("/api/attachment-storage").then(x=>{p&&n(x)}).catch(()=>{}),()=>{p=!1}},[]),!s)return null;const u=async()=>{c(!0),d(null);try{const p=await D("/api/attachment-storage",{method:"POST"});n(p);const x=t("settings.attachments.cleared",{count:p.removed,freed:fs(p.freedBytes)});d(p.failed>0?{kind:"error",message:`${x} ${t("settings.attachments.failed",{count:p.failed})}`}:{kind:"success",message:x})}catch(p){d({kind:"error",message:p instanceof Error?p.message:String(p)})}finally{c(!1),i(!1)}};return e.jsx(L,{title:t("settings.attachments.title"),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-attachments-used":!0,className:"block",children:t("settings.attachments.used",{used:fs(s.usedBytes),max:fs(s.maxBytes)})}),a&&e.jsx("span",{className:"block",children:t("settings.attachments.confirmText")})]}),message:l&&e.jsx("p",{role:l.kind==="error"?"alert":"status",className:z(l.kind==="error"?"text-danger":"text-success"),children:l.message}),children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i(!1),disabled:r,className:"ui-button",children:t("settings.attachments.cancel")}),e.jsx("button",{type:"button",onClick:()=>{u()},disabled:r,className:"ui-button !bg-danger !text-danger-ink",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",title:t("settings.attachments.help"),onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}const mn="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",xn="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",qm=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),Rr=(s,n)=>ts(s)===n||Vi(ss(s),n)!=="none",Br=(s,n)=>{const a=Gi(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},Ea=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function Vm(){const{state:s}=_(),n=Wi(),a=yc(),i=o.useRef(null),[r,c]=o.useState("bot"),[l,d]=o.useState(""),[u,p]=o.useState(null),[x,m]=o.useState(null),g=o.useRef(null),[f,h]=o.useState(null),[j,b]=o.useState(""),y=o.useCallback(()=>h(null),[]);if(o.useEffect(()=>{x||!g.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(k=>k.dataset.accessPerson===g.current)?.focus(),g.current=null)},[x]),!n||!a)return null;const v=n.people.filter(k=>k.role==="member").sort((k,S)=>k.name.localeCompare(S.name)),w=qm(s.bots),N=u?w.find(k=>k.id===u):void 0,C=x?v.find(k=>k.email===x):void 0,T=l.trim().toLowerCase(),F=async(k,S,P)=>{b("");const E=ss(k);try{await Wn(k.id,S),h({botId:k.id,before:E,after:S,text:P})}catch(A){b(A instanceof Error?A.message:String(A))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[C?e.jsx(Xm,{person:C,bots:w.filter(k=>Rr(k,C.email)),team:n,teamName:a,apply:F,onBack:()=>{g.current=C.email,m(null)}}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"ps-4 text-[13px] leading-relaxed text-ink-secondary",children:t("botAccess.overview.introUse",{team:a})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[180px] flex-1",children:[e.jsx(Yt,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value:l,"data-access-search":!0,"aria-label":t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),placeholder:t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),onChange:k=>d(k.target.value),onKeyDown:k=>{k.key==="Escape"&&l&&(k.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(k=>e.jsx("button",{type:"button","aria-pressed":r===k,"data-access-listing":k,onClick:()=>{c(k),d("")},className:z("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===k?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(k==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},k))})]}),r==="bot"?e.jsx(Jm,{bots:w.filter(k=>!T||Ea(T,k.name,Gi(k,n)?.name,ts(k)??void 0)),anyBots:w.length>0,team:n,onOpen:p}):e.jsx(Ym,{people:v.filter(k=>!T||Ea(T,k.name,k.email)),anyPeople:v.length>0,bots:w,onOpen:m}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),j&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:j}),N&&e.jsx(jc,{bot:N,teamName:a,onClose:()=>p(null),onChanged:k=>h({botId:N.id,...k})}),f&&e.jsx(kc,{text:f.text,onUndo:()=>Wn(f.botId,f.before),onDone:y},`${f.botId}:${f.text}:${JSON.stringify(f.after)}`)]})}function Jm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:xn,children:s.map(r=>{const c=ss(r),l=ts(r);return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","aria-haspopup":"dialog","data-access-row":r.id,onClick:()=>i(r.id),className:z(mn,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Qt,{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:Br(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(wc,{entries:Object.keys(c.people).filter(d=>d!==l),team:a})]})},r.id)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBots")})}function Ym({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:xn,children:s.map(r=>{const c=a.filter(l=>Rr(l,r.email)).length;return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","data-access-person":r.email,onClick:()=>i(r.email),className:z(mn,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(qi,{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 Xm({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(Ai,{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(qi,{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:xn,children:n.map(l=>e.jsx(Qm,{bot:l,person:s,team:a,teamName:i,apply:r},l.id))})]})}function Qm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=ss(s),l=ts(s)===n.email,d=c.people[n.email],u=Vi(c,n.email);return e.jsxs("li",{className:mn,"data-access-person-bot":s.id,children:[e.jsx(Qt,{bot:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:!d&&!l&&u===c.everyone?t("botAccess.everyoneUse",{team:i}):Br(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:l?e.jsx("span",{className:"px-2",children:t("lookedAfter.owner")}):d?e.jsx("button",{type:"button","data-access-remove":s.id,"aria-label":t("botAccess.overview.removeFrom",{name:n.name,bot:s.name}),onClick:()=>{r(s,Nc(c,n.email,null),t("botAccess.overview.toastRemoved",{name:n.name,bot:s.name}))},className:"rounded-md px-2 py-1 hover:bg-ink/[0.06] hover:text-ink",children:t("botAccess.remove")}):null})]})}const bs="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",tt=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Ee(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},Aa=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Zm(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=o.useState(null),r=o.useRef(0),c=o.useRef(0);return o.useEffect(()=>{const l=++r.current,d=c.current;i(null);const u=x=>{r.current===l&&(c.current++,i(x))},p=s?.onState(u);return s?.state().then(x=>{c.current===d&&u(x)}).catch(()=>{}),()=>{r.current++,p?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(ex,{bridge:n}):e.jsx(tx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function ex({bridge:s}){const[n,a]=o.useState(null),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=o.useRef(0);if(o.useEffect(()=>{const p=++d.current,x=s.onState(m=>{p===d.current&&a(m.schedule??null)});return s.state().then(m=>{p===d.current&&a(m.schedule??null)}).catch(()=>{}),()=>{d.current++,x()}},[s]),!s.configureSchedule||!n?.enabled)return null;const u=async()=>{if(i||!s.configureSchedule)return;const p=d.current;r(!0),l("");try{const x=await s.configureSchedule({enabled:!1});p===d.current&&a(x.schedule??null)}catch{p===d.current&&l(t("companyBackup.scheduleFailed"))}finally{p===d.current&&r(!1)}};return e.jsx(xe,{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(ie,{"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 tx({connection:s,bridge:n}){const[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(null),[x,m]=o.useState(""),[g,f]=o.useState(null),[h,j]=o.useState(""),[b,y]=o.useState(""),[v,w]=o.useState(null),[N,C]=o.useState(!1),T=o.useRef(0),F=o.useRef(0),k=o.useRef(0),S=o.useRef(void 0),P=o.useRef(!1),E=o.useRef(null),A=async()=>{const q=T.current,ge=++k.current,be=F.current;d(!0);try{await Promise.all([n.state().then(we=>{q===T.current&&ge===k.current&&F.current===be&&i(we)}),n.list().then(we=>{q===T.current&&ge===k.current&&c(we)})]),q===T.current&&ge===k.current&&m("")}catch{q===T.current&&ge===k.current&&m(t("companyBackup.loadFailed"))}finally{q===T.current&&ge===k.current&&d(!1)}};o.useEffect(()=>{const q=++T.current,ge=we=>{if(q!==T.current)return;F.current++,i(we);const Be=we.lastBackupAt??we.schedule?.lastBackupAt;!we.busy&&!we.pendingRestore&&Be&&Be!==S.current&&(S.current=Be,A())},be=n.onState(ge);return A(),()=>{T.current++,k.current++,be()}},[n]),o.useEffect(()=>{const q=E.current;if(!(!g||!q))return q.showModal(),()=>{q.close()}},[g]);const V=N||a?.pendingRestore===!0,R=u!==null||!a||a.busy||V,K=()=>{f(null),j(""),y(""),w(null)},te=q=>{R||P.current||(m(""),j(""),y(""),w(null),f(q))},ue=async(q,ge)=>{if(R||P.current)return;P.current=!0,p(q),m("");const be=T.current;try{await ge(()=>be===T.current)}catch{be===T.current&&m(t(q==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{P.current=!1,be===T.current&&p(null)}},ae=()=>{g?.kind==="create"&&ue("create",async q=>{await n.create({clientState:Cc()}),q()&&(K(),await A())})},X=async q=>{if(!n.configureSchedule||P.current||!a||q&&(R||g?.kind!=="schedule"||b!=="BACK UP THIS WORKSPACE DAILY"))return;P.current=!0,p("schedule"),m("");const ge=T.current,be=F.current;y("");try{const we=await n.configureSchedule(q?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});ge===T.current&&(F.current===be&&i(we),K())}catch{ge===T.current&&m(t("companyBackup.scheduleFailed"))}finally{P.current=!1,ge===T.current&&p(null)}},B=()=>{g?.kind!=="restore"||g.entry.passwordRequired!==!1&&(h.length<12||h.length>1024)||ue("prepare",async q=>{const ge=h;j(""),w(null),y("");const be=await n.prepareRestore({id:g.entry.id,...g.entry.passwordRequired!==!1?{password:ge}:{}});q()&&w(be)})},W=()=>{g?.kind!=="restore"||!v||b!=="REPLACE"||ue("restore",async q=>{const ge=localStorage.getItem(qn);if(ge&&ge!==v.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(qn,v.id),await n.restore({id:v.id,confirmation:"REPLACE"}),q()&&(C(!0),K())})},G=()=>{g?.kind!=="delete"||b!=="DELETE"||ue("delete",async q=>{await n.delete({id:g.entry.id,confirmation:"DELETE"}),q()&&(K(),await A())})},oe=async()=>{const q=T.current;try{await n.cancel()}catch{q===T.current&&m(t("companyBackup.actionFailed"))}},M=r?.backups.filter(q=>q.status==="ready")??[],$=r?r.backups.length-M.length:0,Z=a?.progress,ee=x||a?.message,O=(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"):Z?t(`companyBackup.phase.${Z.phase}`):t("companyBackup.working")}),Z&&Z.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:Z.totalBytes,value:Math.min(Z.bytesTransferred,Z.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:tt(Z.bytesTransferred),total:tt(Z.totalBytes)})})]}),a?.busy&&u!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{oe()},children:t("companyBackup.cancelTransfer")})]}),re=g?.kind==="restore"?t("companyBackup.restore"):g?.kind==="delete"?t("companyBackup.delete"):g?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ne=a?.schedule,me=q=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(q));return e.jsxs(xe,{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&&ne&&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(ie,{"aria-label":t("companyBackup.daily"),checked:ne.enabled,disabled:u!==null||!a||!ne.enabled&&R,onClick:()=>ne.enabled?void X(!1):te({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ne.status}`)}),ne.enabled&&ne.nextBackupAt&&Number.isFinite(ne.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:me(ne.nextBackupAt)})}),ne.lastBackupAt&&Number.isFinite(ne.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:me(ne.lastBackupAt)})}),ne.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ne.message})]}),V?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(Gn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:R,onClick:()=>te({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:u!==null||a?.busy||V||l,onClick:()=>{A()},children:t("companyBackup.refresh")})]}),l&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),r&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:tt(r.usedBytes),total:tt(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),$>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:$})}),r&&M.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:M.map(q=>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:Aa(q)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[tt(q.sizeBytes),q.appVersion?` · ${q.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:q.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:R,onClick:()=>te({kind:"restore",entry:q}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R,onClick:()=>te({kind:"delete",entry:q}),children:t("companyBackup.delete")})]})]},q.id))})]}),!g&&O,!g&&ee&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:ee})]}),g&&e.jsx("dialog",{ref:E,"aria-labelledby":"company-backup-dialog-title",onKeyDown:q=>{(q.key==="Escape"||q.key==="Tab")&&q.stopPropagation()},onCancel:q=>{q.preventDefault(),u||K()},className:"fixed inset-0 m-auto max-h-[85dvh] w-[min(34rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-hairline/50 bg-app p-5 text-ink shadow-xl backdrop:bg-black/45",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h3",{id:"company-backup-dialog-title",className:"text-[16px] font-semibold",children:re}),V&&e.jsx(Gn,{}),(g.kind==="restore"||g.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[Aa(g.entry)," · ",tt(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:q=>{q.preventDefault(),g.kind==="schedule"?X(!0):ae()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(g.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),g.kind==="schedule"?e.jsxs("details",{className:"text-[13px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer text-ink",children:t("companyBackup.included")}),e.jsx("p",{className:"mt-2",children:t("backup.excluded")}),e.jsx("p",{className:"mt-2",children:t("companyBackup.managedPrivacy")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("backup.excluded")}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedPrivacy")})]}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedEncryption")}),g.kind==="schedule"&&e.jsxs("label",{className:"flex items-start gap-2 text-[13px]",children:[e.jsx("input",{className:"mt-1 accent-accent",type:"checkbox",required:!0,disabled:R,checked:b==="BACK UP THIS WORKSPACE DAILY",onChange:q=>y(q.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:R||g.kind==="schedule"&&b!=="BACK UP THIS WORKSPACE DAILY",children:t(g.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),g.kind==="restore"&&(v?e.jsxs(e.Fragment,{children:[e.jsx(Sc,{summary:v.summary}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.replaceWarning")}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.trustWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("backup.confirmReplace"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:7,disabled:R,value:b,onChange:q=>y(q.target.value),className:bs})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R||b!=="REPLACE",onClick:W,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:q=>{q.preventDefault(),B()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),g.entry.passwordRequired!==!1&&e.jsxs("label",{className:"text-[13px]",children:[t("backup.importPassword"),e.jsx("input",{type:"password",autoComplete:"off",required:!0,minLength:12,maxLength:1024,disabled:R,value:h,onChange:q=>j(q.target.value),className:bs})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:R||g.entry.passwordRequired!==!1&&(h.length<12||h.length>1024),children:t("backup.validate")})]})),g.kind==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-danger",children:t("companyBackup.deleteWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("companyBackup.confirmDelete"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:6,disabled:R,value:b,onChange:q=>y(q.target.value),className:bs})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R||b!=="DELETE",onClick:G,children:t("companyBackup.delete")})]}),O,ee&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:ee}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:u!==null,onClick:K,children:t("companyBackup.cancel")})]})})]})}function Pa({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(Mc,{size:12},a);case"cursor":return e.jsx(Uc,{size:12},a);case"gemini":return e.jsx(Fc,{preset:"google",size:12},a);default:return e.jsx(Oc,{size:12},a)}})})}function Ta({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:l,onChange:d}){return o.useContext(Ae)?e.jsxs("div",{className:"flex items-center gap-6 py-2",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] leading-5 text-ink",children:[e.jsx(Pa,{sources:r}),n]}),e.jsx("span",{className:"text-[12px] leading-4 text-ink-secondary",children:a})]}),e.jsx(ie,{checked:c,disabled:l,"aria-label":n,onClick:()=>d(!c)})]}):e.jsxs("label",{className:z("flex items-start gap-3 px-3.5 py-3 transition-colors",l?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:l,onChange:u=>d(u.target.checked),className:"mt-0.5 size-4 shrink-0 cursor-[inherit] accent-[var(--color-accent)]"}),e.jsx("span",{className:"mt-0.5 flex size-4 shrink-0 items-center justify-center text-ink-secondary",children:s}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"text-[13px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"mr-2 text-[14px] font-medium text-ink",children:n}),e.jsx(Pa,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const Or="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 sx({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:l,onRetry:d,onSkip:u}){const p=i==="working",x=o.useContext(Ae);if(x&&s&&(n===null||i==="failed"))return e.jsx("div",{"data-import-section":"apps",className:"contents",children:e.jsx(L,{title:t("settings.import.appsTitle"),subtitle:t("settings.import.appsShort"),message:e.jsxs("span",{role:"alert",className:"text-danger",children:[t(n===null?"settings.import.lookFailed":"settings.import.bringFailed"),d&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-import-retry":"",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",onClick:d,children:t("common.tryAgain")})]})]}),children:u&&e.jsx("button",{type:"button","data-import-skip":"",className:"settings-quiet cursor-pointer",onClick:u,children:t("settings.import.skip")})})});const m=x?"ui-button self-end gap-1.5":Or;let g;if(!s)g=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)g=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ce,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:f,notes:h,done:j}=Ac(r);g=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:z("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",j?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:j?e.jsx(He,{size:12,strokeWidth:3}):e.jsx(Pc,{size:12,strokeWidth:2.5})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:f}),h.map(b=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:b},b))]})]})}else!n||Tc(n)===0?g=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):g=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:x?"flex flex-col":"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(Ta,{icon:e.jsx(Lc,{size:15}),label:t("onboarding.import.skills"),summary:Ic(n),hint:t("onboarding.import.skillsHint"),sources:Xn(n.skills),checked:a.skills,disabled:p,onChange:f=>c({...a,skills:f})}),n.tools.length>0&&e.jsx(Ta,{icon:e.jsx(Bc,{size:15}),label:t("onboarding.import.tools"),summary:Rc(n),hint:t("onboarding.import.toolsHint"),sources:Xn(n.tools),checked:a.tools,disabled:p,onChange:f=>c({...a,tools:f})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:l,disabled:p||!(a.skills||a.tools),className:z(m,!x&&"mt-3"),children:[p&&e.jsx(ce,{size:14,className:"animate-spin"}),p?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return x&&!s?e.jsx("div",{"data-import-section":"apps",className:"contents",children:e.jsx(L,{title:t("settings.import.appsTitle"),subtitle:t("settings.import.appsShort"),inert:t("settings.import.appsLocalOnly"),inertText:t("settings.import.appsLocalOnly"),children:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.import.choose")})})}):x?e.jsxs("div",{"data-import-section":"apps",className:"flex flex-col gap-2 px-4 py-3",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.import.appsTitle")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.import.appsShort")})]}),g]}):e.jsxs("section",{"data-import-section":"apps",className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t("settings.import.appsTitle")}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.appsSubtitle")}),e.jsx("div",{className:"mt-4",children:g})]})}function Ia({client:s,local:n}){const[a,i]=o.useState(void 0),[r,c]=o.useState({skills:!0,tools:!0}),[l,d]=o.useState("idle"),[u,p]=o.useState(null),[x,m]=o.useState(0);o.useEffect(()=>{if(!n)return;const f=new AbortController;return i(void 0),s.detect(f.signal).then(i,()=>i(null)),()=>f.abort()},[s,n,x]);const g=async()=>{if(!a||l==="working")return;const f={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!f.skills&&!f.tools)){d("working");try{const h=await s.apply(f);Yl("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),p(h),d("idle")}catch{d("failed")}}};return e.jsx(sx,{local:n,detection:a,chosen:r,status:l,result:u,onChoose:c,onBring:()=>{g()},onRetry:()=>l==="failed"?void g():m(f=>f+1),onSkip:()=>l==="failed"?d("idle"):i({skills:[],tools:[]})})}function La(){const[s,n]=o.useState(!1),[a,i]=o.useState(!1);return o.useContext(Ae)?e.jsxs("div",{"data-import-section":"grok","data-settings-block":"grok-move",className:"flex flex-col",children:[e.jsx(L,{title:t("settings.import.grokTitle"),subtitle:t("settings.import.grokLine"),leading:e.jsx(Ls,{children:e.jsx(Jn,{size:18})}),children:e.jsx("button",{type:"button",className:"ui-button","data-grok-move-open":!0,"aria-expanded":a,onClick:()=>{n(!0),i(!a)},children:t(a?"common.close":"settings.import.moveAction")})}),s&&e.jsx("div",{className:a?"px-4 pb-3":"hidden",children:e.jsx(Yn,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]}):e.jsxs("section",{"data-import-section":"grok",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[15px] font-medium text-ink",children:[e.jsx(Jn,{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:z(Or,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(qs,{size:14,"aria-hidden":"true",className:z("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Yn,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function nx({client:s=Ec,children:n}){const{state:a}=_();return o.useContext(Ae)?e.jsxs(J,{children:[e.jsx(La,{}),e.jsx(Ia,{client:s,local:Vn(a.config?.cloudHome===!0)}),n]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(La,{}),e.jsx(Ia,{client:s,local:Vn(a.config?.cloudHome===!0)}),n]})}const Fr=1,Ur=3650,ax=30,Vt=1024*1024,Fs=256*1024,Mr=4*1024*1024*1024,ix=50;function Ra(s){const n=Number(s);return Number.isInteger(n)&&n>=Fr&&n<=Ur?n:null}function Ba(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Vt);return a>=Fs&&a<=Mr&&a%Fs===0?a:null}function Oa(s){const n=s/Vt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function rx(){const{state:s,dispatch:n}=_(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(""),[g,f]=o.useState(null),h=o.useRef(!1),j=r??String(a===null?ax:a),b=l??(i===null?String(ix):Oa(i));o.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),o.useEffect(()=>{l!==null&&i!==null&&Oa(i)===l&&d(null)},[i,l]);const y=async(k,S)=>{if(!h.current){h.current=!0,p(S),m(""),f(null);try{const P=await D("/api/config",{method:"PATCH",body:JSON.stringify({threads:k})});n({type:"configStatus",config:P})}catch(P){m(P instanceof Error?P.message:t("settings.threadCleanup.error")),f(S)}finally{h.current=!1,p(null)}}},v=k=>{if(!k){c(null),m(""),f(null),y({eventLogRetentionDays:null},"retention");return}const S=Ra(j);if(S===null){m(t("settings.threadCleanup.invalidRetention")),f("retention");return}y({eventLogRetentionDays:S},"retention")},w=k=>{if(!k){d(null),m(""),f(null),y({eventLogMaxBytes:null},"cap");return}const S=Ba(b);if(S===null){m(t("settings.threadCleanup.invalidCap")),f("cap");return}y({eventLogMaxBytes:S},"cap")},N=()=>{if(a===null)return;const k=Ra(j);if(k===null){m(t("settings.threadCleanup.invalidRetention")),f("retention");return}if(k===a){c(null),m("");return}y({eventLogRetentionDays:k},"retention")},C=()=>{if(i===null)return;const k=Ba(b);if(k===null){m(t("settings.threadCleanup.invalidCap")),f("cap");return}if(k===i){d(null),m("");return}y({eventLogMaxBytes:k},"cap")},T=k=>{const S=k==="retention";return e.jsxs("span",{className:"mt-1 flex items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:S?"thread-log-retention-days":"thread-log-cap-mib",type:"number",min:S?Fr:Fs/Vt,max:S?Ur:Mr/Vt,step:S?1:.25,inputMode:S?"numeric":"decimal",value:S?j:b,disabled:(S?a:i)===null||u!==null,"aria-invalid":g===k,"aria-label":t(S?"settings.threadCleanup.retention.enable":"settings.threadCleanup.cap.enable"),onChange:P=>{S?c(P.target.value):d(P.target.value),m(""),f(null)},onBlur:S?N:C,onKeyDown:P=>{P.key==="Enter"&&P.currentTarget.blur()},className:z(Re,g===k&&"border-danger/60")}),t(S?"settings.threadCleanup.retention.unit":"settings.threadCleanup.cap.unit")]})},F=k=>u===k?e.jsx("span",{role:"status",children:t("settings.threadCleanup.saving")}):x&&g===k?e.jsx("span",{role:"alert",className:"text-danger",children:x}):void 0;return e.jsx(Y,{label:t("settings.threadCleanup.title"),block:"cleanup",children:e.jsxs(J,{children:[e.jsx(L,{title:t("settings.threadCleanup.retention.title"),subtitle:a!==null?e.jsxs(e.Fragment,{children:[t("settings.threadCleanup.retention.short"),T("retention")]}):t("settings.threadCleanup.retention.plain"),message:F("retention"),children:e.jsx(ie,{id:"thread-log-retention-enabled",checked:a!==null,disabled:u!==null,"aria-label":t("settings.threadCleanup.retention.title"),onClick:()=>v(a===null)})}),e.jsx(L,{title:t("settings.threadCleanup.cap.title"),subtitle:i!==null?e.jsxs(e.Fragment,{children:[t("settings.threadCleanup.cap.short"),T("cap")]}):t("settings.threadCleanup.cap.plain"),message:F("cap"),children:e.jsx(ie,{id:"thread-log-cap-enabled",checked:i!==null,disabled:u!==null,"aria-label":t("settings.threadCleanup.cap.title"),onClick:()=>w(i===null)})})]})})}const zt=[{id:"anthropic",label:"Anthropic",color:"#D97757",pattern:/claude|anthropic|sonnet|opus|haiku/i},{id:"openai",label:"OpenAI",color:"#0C9A76",pattern:/(?:^|[-_/])gpt(?:\d|[-_.]|$)|openai|chatgpt|codex|^o[134](?:-|$)/i},{id:"xai",label:"xAI",color:"#7D8794",pattern:/grok|xai/i},{id:"deepseek",label:"DeepSeek",color:"#4C7DFF",pattern:/deepseek/i},{id:"google",label:"Google",color:"#9A6BE0",pattern:/gemini|google|gemma/i},{id:"qwen",label:"Qwen",color:"#D0634A",pattern:/qwen|tongyi|qwq/i},{id:"mistral",label:"Mistral",color:"#B88A12",pattern:/mistral|codestral|devstral|magistral|pixtral/i},{id:"meta",label:"Meta",color:"#D8578F",pattern:/llama|meta-|^meta$/i},{id:"kimi",label:"Kimi",color:"#1E93AA",pattern:/kimi|moonshot/i},{id:"zai",label:"Z.ai",color:"#7274F2",pattern:/glm|zhipu|z-ai|chatglm/i},{id:"minimax",label:"MiniMax",color:"#E05C7A",pattern:/minimax/i},{id:"cohere",label:"Cohere",color:"#B563D0",pattern:/command-r|cohere|(?:^|[-/])aya(?:[-/]|$)/i},{id:"perplexity",label:"Perplexity",color:"#2F97A6",pattern:/sonar|perplexity/i},{id:"amazon",label:"Amazon",color:"#C77C02",pattern:/nova|amazon|titan/i},{id:"microsoft",label:"Microsoft",color:"#2C90DE",pattern:/(?:^|[-/])phi|microsoft/i},{id:"nvidia",label:"NVIDIA",color:"#5E8C00",pattern:/nemotron|nvidia/i},{id:"opencode",label:"OpenCode",color:"#6F8B9A",pattern:/opencode|big-pickle|crouton|beam/i},{id:"nous",label:"Nous Research",color:"#8A6FD1",pattern:/hermes/i},{id:"cursor",label:"Cursor",color:"#74818C",pattern:/cursor|composer/i},{id:"factory",label:"Factory",color:"#7B8794",pattern:/droid/i},{id:"greenference",label:"Greenference",color:"#3F8F5F",pattern:/greenference/i},{id:"unknown",label:"Other",color:"#76828F",pattern:/(?!)/}];zt.map(s=>s.color);const lx=[[/claude|anthropic/i,"anthropic"],[/codex|openai/i,"openai"],[/grok|xai/i,"xai"],[/opencode/i,"opencode"],[/gemini|antigravity/i,"google"],[/qwen/i,"qwen"],[/kimi/i,"kimi"],[/mistral/i,"mistral"],[/deepseek/i,"deepseek"],[/copilot/i,"microsoft"],[/cursor/i,"cursor"],[/command/i,"cohere"],[/droid/i,"factory"],[/hermes/i,"nous"],[/greenference/i,"greenference"]],Fa=/^(?:opencode-go|opencode|zen|openrouter|vercel|groq|fireworks(?:-ai)?|together(?:_ai)?|deepinfra|cerebras|togetherai|ollama|lmstudio|local)\//,Ua=/^(?:anthropic|openai|google|meta-llama|meta|mistralai|deepseek|qwen|moonshotai|moonshot|x-ai|xai|z-ai|zhipu|minimax|cohere|perplexity|amazon|nvidia|nousresearch|microsoft|cursor|factory)\//;function Dr(s){if(!s.startsWith("model:"))return s;const n=s.slice(6),a=n.indexOf("/");return a===-1?n:n.slice(a+1)}function ox(s){if(!s.startsWith("model:"))return;const n=s.slice(6),a=n.indexOf("/");return a===-1?void 0:n.slice(0,a)}function zr(s){let n=s.trim().toLowerCase();for(Fa.test(n)&&(n=n.replace(Fa,""));Ua.test(n);)n=n.replace(Ua,"");return n.replace(/(?::|-)(?:free|beta|preview|latest)$/,"")}function _r(s){const n=zr(Dr(s)),a=zt.find(c=>c.id!=="unknown"&&c.pattern.test(n));if(a)return a;const i=ox(s),r=i&&lx.find(([c])=>c.test(i))?.[1];return zt.find(c=>c.id===r)??zt.find(c=>c.id==="unknown")}function cx(s){let n=2166136261;for(let a=0;a<s.length;a+=1){let i=s.charCodeAt(a);i=Math.imul(i,3432918353),i=i<<15|i>>>17,i=Math.imul(i,461845907),n^=i,n=n<<13|n>>>19,n=Math.imul(n,5)+3864292196>>>0}return n^=s.length,n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,n>>>0}const dx="shade428:",ut=[-7,-4.7,-2.3,0,2.3,4.7,7],Rt=[-.045,-.03,-.015,0,.015,.03,.045],vs=[.93,1,1.07],ux=["#ffffff","#3a322d"],px=3.05;function Ma(s){return ux.every(n=>Dc(s,n)>=px)}function mx(s,n){if(Ma(s))return s;const a=Ji(s);for(let i=0;i<=140;i+=1)for(const r of[-1,1]){const c=a.l+r*i*.002;if(c<.2||c>.95)continue;const l=Yi({...a,l:c});if(Ma(l))return l}return n}function xx(s,n){const a=Ji(n.color),i=cx(`${dx}${s}`)%(ut.length*Rt.length*vs.length),r=a.h+ut[i%ut.length],c=a.l+Rt[Math.floor(i/ut.length)%Rt.length],l=a.c*vs[Math.floor(i/(ut.length*Rt.length))%vs.length];return mx(Yi({l:c,c:l,h:r}),n.color)}function yt(s){const n=_r(s);return xx(zr(Dr(s))||s.toLowerCase(),n)}function Da(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Ee(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function gx(s){return t("planUsage.spendAmounts",{used:Da(s.usedMinor,s.currency,s.exponent),limit:Da(s.limitMinor,s.currency,s.exponent)})}function hx(s,n){if(!s)return null;const a=Date.parse(s);if(!Number.isFinite(a)||a<=n)return null;const i=Math.floor((a-n)/6e4);if(i<1)return"less than a minute";const r=Math.floor(i/1440),c=Math.floor(i%1440/60),l=i%60;return r>0?c>0?`${r}d ${c}h`:`${r}d`:c>0?l>0?`${c}h ${l}m`:`${c}h`:`${l}m`}function fx(s,n,a){const i=[];for(const r of s.providers){if(!r.ok)continue;const c=[r.fiveHour.available?r.fiveHour.resetsAt:null,r.weekly.available?r.weekly.resetsAt:null,...r.extra.map(l=>l.resetsAt),...(r.models??[]).flatMap(l=>l.windows.map(d=>d.resetsAt))];for(const l of c){if(!l||a.has(l)||i.includes(l))continue;const d=Date.parse(l);Number.isFinite(d)&&d<=n&&i.push(l)}}return i}function bx(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function za(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function Hr(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 vx(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:Hr({name:a[1]})}):n}function Bt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?hx(n.resetsAt,a):null,l=n.usedPercent??0,d=i?n.usedPercent==null?null:t("planUsage.used",{used:Math.round(n.usedPercent)}):n.remainingPercent==null?null:t("planUsage.left",{remaining:Math.round(n.remainingPercent)});return e.jsxs("div",{className:"grid grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-x-3 gap-y-1",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:s}),n.available&&d?e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 text-[13px] text-ink",children:[e.jsx("span",{className:"tabular-nums",children:d}),r&&e.jsx("span",{"data-plan-spend":!0,className:"text-[12px] tabular-nums text-ink-secondary",children:r}),c&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("planUsage.resetsIn",{when:c})})]}),e.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-inset",role:"meter","aria-label":s,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(Math.min(100,Math.max(0,l))),children:e.jsx("div",{className:z("h-full rounded-full",bx(l)),style:{width:`${Math.min(100,Math.max(0,l))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function yx(){const[s,n]=o.useState(null),[a,i]=o.useState(!0),[r,c]=o.useState(""),[l,d]=o.useState(()=>Date.now()),u=o.useRef(new Set),p=o.useCallback(async(x=!1)=>{i(!0),c("");try{const m=await D(x?"/api/plan-usage?refresh=1":"/api/plan-usage");n(m),d(Date.now())}catch(m){c(m instanceof Error&&m.message?m.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return o.useEffect(()=>{p(!1)},[p]),o.useEffect(()=>{const x=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(x)},[]),o.useEffect(()=>{if(!s)return;const x=fx(s,l,u.current);if(x.length!==0){for(const m of x)u.current.add(m);p(!0)}},[s,l,p]),{report:s,loading:a,error:r,now:l,load:p}}function _a(){const{report:s,loading:n,error:a,now:i,load:r}=yx();return o.useContext(Ae)&&(!s||s.providers.length===0)?e.jsx(Y,{label:t("settings.spending.aiLimits"),block:"plan-usage",actions:e.jsxs("button",{type:"button",onClick:()=>{r(!0)},disabled:n,className:"settings-quiet flex cursor-pointer items-center gap-1.5",children:[n?e.jsx(ce,{size:14,className:"animate-spin","aria-hidden":"true"}):e.jsx(bt,{size:14,"aria-hidden":"true"}),t("planUsage.refresh")]}),footnote:a?e.jsx("span",{role:"alert",className:"text-danger",children:a}):void 0,children:e.jsx(J,{children:e.jsx(Se,{children:n&&!s?t("planUsage.loading"):t("planUsage.emptyShort")})})}):e.jsxs(xe,{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(ce,{size:14,className:"animate-spin"}):e.jsx(bt,{size:14})})}),n&&!s&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("planUsage.loading")}),a&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-danger",children:a}),s&&s.providers.length===0&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("planUsage.empty")}),s&&s.providers.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:s.providers.map(l=>e.jsxs("div",{className:"border-t border-hairline/30 pt-3 first:border-t-0 first:pt-0",children:[e.jsxs("div",{className:"mb-2 flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:Hr(l)}),l.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:l.plan})]}),l.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Bt,{label:t("planUsage.fiveHour"),window:l.fiveHour,now:i}),e.jsx(Bt,{label:t("planUsage.weekly"),window:l.weekly,now:i}),l.extra.map((d,u)=>e.jsx(Bt,{label:za(d.label),now:i,usedHeadline:!!d.spend,detail:d.spend?gx(d.spend):void 0,window:{available:!0,remainingPercent:d.remainingPercent,usedPercent:d.usedPercent,resetsAt:d.resetsAt}},`${d.label}-${u}`)),(l.models??[]).length>0&&e.jsxs("div",{className:"mt-1 flex flex-col gap-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t("planUsage.byModel")}),(l.models??[]).map(d=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:d.name}),d.windows.map((u,p)=>e.jsx(Bt,{label:za(u.label),now:i,usedHeadline:!0,window:{available:!0,remainingPercent:u.remainingPercent,usedPercent:u.usedPercent,resetsAt:u.resetsAt}},`${d.name}-${u.label}-${p}`))]},d.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:vx(l)})]},l.id))})]})}function Ha(s,n){return s?.edition?.features?.includes(n)===!0}function jx(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function kx({budget:s}){const{state:n,dispatch:a}=_(),i=n.config?.budgets??{},[r,c]=o.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[l,d]=o.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[u,p]=o.useState(!1),[x,m]=o.useState(null);o.useEffect(()=>{c(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),d(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const g=async()=>{if(u)return;const h=r.trim()===""?0:Number(r),j=Number(l);if(!Number.isFinite(h)||h<0||!Number.isInteger(j)||j<1||j>100){m(t("usage.budget.invalid"));return}p(!0),m(null);try{const b=await D("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:h,warnAtPercent:j}})});a({type:"configStatus",config:b})}catch(b){m(b instanceof Error?b.message:String(b))}finally{p(!1)}},f=jx(s);return e.jsxs(xe,{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:z(f==="danger"?"text-danger":f==="warning"?"text-warning":"text-ink"),children:s.exceeded?t("usage.budget.reached"):s.warn?t("usage.budget.nearing"):t("usage.budget.within")}),e.jsx("span",{className:"tabular-nums text-ink-secondary",children:t("usage.budget.spent",{spent:rt(s.spentUsd),cap:rt(s.monthlyUsd),percent:String(s.percent)})})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-inset",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,s.percent),children:e.jsx("div",{className:z("h-full rounded-full",f==="danger"?"bg-danger":f==="warning"?"bg-warning":"bg-accent"),style:{width:`${Math.min(100,s.percent)}%`}})})]}):e.jsx("p",{className:"mb-4 text-[13px] text-ink-secondary",children:t("usage.budget.none")}),e.jsxs("form",{className:"flex flex-wrap items-end gap-3",onSubmit:h=>{h.preventDefault(),g()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.monthly"),e.jsx("input",{value:r,onChange:h=>c(h.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:u,className:"w-32 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.warnAt"),e.jsx("input",{value:l,onChange:h=>d(h.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:u,className:"w-20 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("button",{type:"submit",disabled:u,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[u&&e.jsx(ce,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.budget.hint")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}function $a(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 wx(){const{state:s,dispatch:n}=_(),a=s.config?.billing,[i,r]=o.useState(a?.currency??"USD"),[c,l]=o.useState($a(a?.prices)),[d,u]=o.useState(!1),[p,x]=o.useState(null);o.useEffect(()=>{r(a?.currency??"USD"),l($a(a?.prices))},[a]);const m=(h,j)=>l(b=>b.map((y,v)=>v===h?{...y,...j}:y)),g=async()=>{if(d)return;const h={};for(const j of c){const b=j.key.trim();if(!b)continue;const y=Number(j.input),v=Number(j.output),w=j.cached.trim()===""?void 0:Number(j.cached);if(!Number.isFinite(y)||!Number.isFinite(v)||y<0||v<0||w!==void 0&&(!Number.isFinite(w)||w<0)){x(t("usage.prices.invalid",{model:b}));return}h[b]={inputPerMillion:y,outputPerMillion:v,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){x(t("usage.prices.currencyInvalid"));return}u(!0),x(null);try{const j=await D("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:h}})});n({type:"configStatus",config:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{u(!1)}},f="w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50";return e.jsxs(xe,{title:t("usage.prices.title"),subtitle:t("usage.prices.subtitle"),children:[e.jsx("div",{className:"mb-3 flex items-center gap-2 text-[12px] text-ink-secondary",children:e.jsxs("label",{className:"flex items-center gap-2",children:[t("usage.prices.currency"),e.jsx("input",{value:i,onChange:h=>r(h.target.value),maxLength:3,"aria-label":t("usage.prices.currency"),disabled:d,className:"w-16 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] uppercase text-ink focus:outline-none disabled:opacity-50"})]})}),e.jsxs("div",{className:"grid grid-cols-[1fr_5rem_5rem_5rem_auto] items-center gap-x-2 gap-y-1.5 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("usage.prices.colModel")}),e.jsx("span",{children:t("usage.prices.colInput")}),e.jsx("span",{children:t("usage.prices.colOutput")}),e.jsx("span",{children:t("usage.prices.colCached")}),e.jsx("span",{}),c.map((h,j)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:h.key,onChange:b=>m(j,{key:b.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:z(f,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:h.input,onChange:b=>m(j,{input:b.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:f}),e.jsx("input",{value:h.output,onChange:b=>m(j,{output:b.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:f}),e.jsx("input",{value:h.cached,onChange:b=>m(j,{cached:b.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:f}),e.jsx("button",{type:"button",onClick:()=>l(b=>b.filter((y,v)=>v!==j)),"aria-label":t("usage.prices.remove"),disabled:d,className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(We,{size:13})})]},j))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>l(h=>[...h,{key:"",input:"",output:"",cached:""}]),disabled:d,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx(Ke,{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(ce,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.prices.hint")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}function Ka({budget:s}){const{state:n}=_(),a=Ha(n.config,"budgets"),i=Ha(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(kx,{budget:s}),i&&e.jsx(wx,{})]})}const gn=[{field:"dailyUsd",label:"usage.caps.dailyUsd",whole:!1},{field:"dailyTokens",label:"usage.caps.dailyTokens",whole:!0},{field:"monthlyUsd",label:"usage.caps.monthlyUsd",whole:!1},{field:"monthlyTokens",label:"usage.caps.monthlyTokens",whole:!0}],_t=s=>Object.fromEntries(gn.map(({field:n})=>[n,s?.[n]?String(s[n]):""]));function Wa(s){const n={};for(const{field:a,whole:i}of gn){const r=s[a].trim().replace(/,/g,"");if(r==="")continue;const c=Number(r);if(!Number.isFinite(c)||c<0||i&&!Number.isInteger(c))return null;c>0&&(n[a]=c)}return n}const Nx=s=>s.reached?"danger":s.warn?"warning":"quiet",Ga=(s,n)=>s.unit==="usd"?rt(n):t("usage.caps.tokens",{count:ns(Math.round(n))}),Sx=s=>new Date(s).toLocaleString(Pi(Ee()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});function Cx({cap:s,name:n}){const a=Nx(s);return e.jsxs("li",{"data-testid":"usage-cap","data-cap":s.id,children:[e.jsxs("div",{className:"mb-1 flex flex-wrap items-baseline justify-between gap-x-3 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:t(s.period==="day"?"usage.caps.useDay":"usage.caps.useMonth",{who:n})}),e.jsx("span",{className:"tabular-nums text-ink-secondary",children:t("usage.caps.used",{used:Ga(s,s.used),limit:Ga(s,s.limit),percent:String(s.percent)})})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-inset",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,s.percent),children:e.jsx("div",{className:z("h-full rounded-full",a==="danger"?"bg-danger":a==="warning"?"bg-warning":"bg-accent"),style:{width:`${Math.min(100,s.percent)}%`}})}),a!=="quiet"&&e.jsx("p",{className:z("mt-1 text-[12px]",a==="danger"?"text-danger":"text-warning"),children:s.reached?t("usage.caps.reached",{resets:Sx(s.resetsAt)}):t("usage.caps.nearing",{percent:String(s.percent)})})]})}const Ex="w-28 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50";function qa({who:s,draft:n,locked:a,disabled:i,onChange:r}){return e.jsx("div",{className:"flex flex-wrap items-end gap-2",children:gn.map(({field:c,label:l,whole:d})=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t(l),e.jsx("input",{value:n[c],onChange:u=>r(c,u.target.value),inputMode:d?"numeric":"decimal",placeholder:t("usage.caps.noCap"),"aria-label":`${s}: ${t(l)}`,disabled:i||a?.includes(c),className:Ex})]},c))})}function Va({view:s,onSaved:n}){return s?e.jsx(Px,{view:s,onSaved:n}):null}const Ja=s=>({...s.server,...s.env.values?.server});function Ax(s,n,a,i){const r={...a};for(const c of s.env.server){const l=s.server[c];l===void 0?delete r[c]:r[c]=l}return{stops:s.env.stops?s.savedStops??"unattended":n,server:r,bots:i}}const Ya=s=>Object.entries(s.bots).map(([n,a])=>({botId:n,draft:_t(a)}));function Px({view:s,onSaved:n}){const{state:a}=_(),[i,r]=o.useState(s.stops),[c,l]=o.useState(()=>_t(Ja(s))),[d,u]=o.useState(()=>Ya(s)),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=JSON.stringify([s.stops,s.server,s.bots,s.env]);o.useEffect(()=>{r(s.stops),l(_t(Ja(s))),u(Ya(s))},[f]);const h=y=>a.bots?.find(v=>v.id===y)?.name??t("usage.caps.goneBot"),j=(a.bots??[]).filter(y=>!y.hidden&&!d.some(v=>v.botId===y.id)),b=async()=>{if(p)return;const y=Wa(c),v=d.map(w=>[w.botId,Wa(w.draft)]);if(!y||v.some(([,w])=>!w)){g(t("usage.caps.invalid"));return}x(!0),g(null);try{await D("/api/usage/caps",{method:"PUT",body:JSON.stringify(Ax(s,i,y,Object.fromEntries(v)))}),n?.()}catch(w){g(w instanceof Error?w.message:String(w))}finally{x(!1)}};return e.jsxs(xe,{title:t("usage.caps.title"),subtitle:t("usage.caps.subtitle"),children:[s.caps.length?e.jsx("ul",{className:"mb-4 flex flex-col gap-3",children:s.caps.map(y=>e.jsx(Cx,{cap:y,name:y.scope==="server"?t("usage.caps.server"):h(y.botId)},y.id))}):e.jsx("p",{className:"mb-4 text-[13px] text-ink-secondary",children:t("usage.caps.none")}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:y=>{y.preventDefault(),b()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.caps.stops"),e.jsxs(de,{size:"sm",className:"w-full max-w-md",value:i,onChange:y=>r(y.target.value),disabled:p||s.env.stops,children:[e.jsx("option",{value:"unattended",children:t("usage.caps.stopsUnattended")}),e.jsx("option",{value:"everything",children:t("usage.caps.stopsEverything")})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[13px] text-ink",children:t("usage.caps.server")}),e.jsx(qa,{who:t("usage.caps.server"),draft:c,locked:s.env.server,disabled:p,onChange:(y,v)=>l(w=>({...w,[y]:v}))}),(s.env.server.length>0||s.env.stops)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("usage.caps.fromEnv")})]}),d.map(y=>e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[13px] text-ink",children:[h(y.botId),e.jsx("button",{type:"button",onClick:()=>u(v=>v.filter(w=>w.botId!==y.botId)),"aria-label":t("usage.caps.removeBot",{bot:h(y.botId)}),disabled:p,className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(We,{size:13})})]}),e.jsx(qa,{who:h(y.botId),draft:y.draft,disabled:p,onChange:(v,w)=>u(N=>N.map(C=>C.botId===y.botId?{...C,draft:{...C.draft,[v]:w}}:C))})]},y.botId)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[j.length>0&&e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(Ke,{size:13}),e.jsxs(de,{size:"sm",value:"",onChange:y=>{const v=y.target.value;v&&u(w=>[...w,{botId:v,draft:_t(void 0)}])},disabled:p,"aria-label":t("usage.caps.addBot"),children:[e.jsx("option",{value:"",children:t("usage.caps.addBot")}),j.map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]})]}),e.jsxs("button",{type:"submit",disabled:p,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[p&&e.jsx(ce,{size:13,className:"animate-spin"}),t("common.save")]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.caps.hint")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}const $r=["model","user","department","day","engine","routine"];function Xa({summary:s}){const n=s?.notBilled?.usd??0,a=s?.total?.unpriced??0;return!(n>0)&&!a?null:e.jsxs("div",{"data-testid":"usage-caveats",className:"flex flex-col gap-0.5 px-1 text-[12px] leading-5 text-ink-secondary",children:[n>0&&e.jsx("p",{children:t("usage.page.notBilled",{cost:Je(n)})}),a>0&&e.jsx("p",{children:t("usage.page.unpriced",{count:String(a)})})]})}const Us={bot:"usage.history.byBot",model:"usage.history.byModel",user:"usage.history.byUser",day:"usage.history.byDay",engine:"usage.history.byEngine",routine:"usage.history.byRoutine",department:"usage.history.byDepartment"},Qa={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},Tx=2e3;function Kr(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 _e(s){return s.barTokens??nt(s)}function Jt(s,n,a,i){const[r,c]=o.useState(null);return o.useEffect(()=>{let l=!0;return D(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}${i?`&splitBy=${i}`:""}`).then(d=>{l&&c(d)}).catch(()=>{l&&c(null)}),()=>{l=!1}},[s.from,s.to,n,i,a]),r}function Ix({group:s,width:n,color:a}){const{state:i}=_(),r=s.segments??[],c=r.reduce((l,d)=>l+_e(d),0);return r.length&&c>0?e.jsx("span",{className:"flex h-full",style:{width:`${n}%`},children:r.map(l=>{const d=_e(l),u=Math.round(d/c*100);return e.jsx("span",{className:"h-full","data-model-color":yt(l.key),style:{width:`${d/c*100}%`,backgroundColor:yt(l.key)},title:`${as(l.label,i.instances)} · ${ns(d)} · ${u}%`},l.key)})}):e.jsx("span",{"data-model-color":a,className:z("block h-full rounded-full",!a&&"bg-accent/70"),style:{width:`${n}%`,backgroundColor:a}})}function Za({groupBy:s,groups:n}){const{state:a}=_(),i=o.useContext(Ae),r=[...n].sort((l,d)=>_e(d)-_e(l)).slice(0,6),c=Math.max(...r.map(_e),0);return!r.length||c<=0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("usage.page.whereEmpty")}):e.jsx("ul",{className:"flex flex-col gap-2.5",children:r.map(l=>{const d=s==="bot"?a.bots.find(x=>`bot:${x.id}`===l.key):void 0,u=!i&&s==="model"?_r(l.key):void 0,p=u?yt(l.key):void 0;return e.jsxs("li",{className:"grid grid-cols-[minmax(0,9rem)_1fr_auto] items-center gap-3 text-[13px]",title:t("usage.page.turns",{count:String(l.turns)}),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2 text-ink",children:[d&&e.jsx(Qt,{bot:d,state:"idle",size:18,animated:!1}),u&&e.jsx("span",{"aria-hidden":"true",title:u.label,"data-model-color":p,className:"size-2 shrink-0 rounded-full",style:{backgroundColor:p}}),e.jsx("span",{className:"truncate",children:d?d.name:s==="model"?as(l.label,a.instances):Kr(s,l)})]}),e.jsx("span",{className:z("h-2 overflow-hidden rounded-full",i?"bg-ink/[0.08]":"bg-raised"),children:i?e.jsx("span",{className:"block h-full rounded-full bg-ink",style:{width:`${Math.max(2,_e(l)/c*100)}%`}}):e.jsx(Ix,{group:l,width:Math.max(2,_e(l)/c*100),color:p})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[ns(_e(l)),it(l.costUsd)&&l.costUsd>0&&` · ${Je(l.costUsd)}`]})]},l.key)})})}function Lx({groups:s}){const{state:n}=_(),a=new Map;for(const r of s)for(const c of r.segments??[]){const l=a.get(c.key);a.set(c.key,{label:c.label,tokens:(l?.tokens??0)+nt(c)})}const i=[...a.entries()].sort((r,c)=>c[1].tokens-r[1].tokens);return i.length<2?null:e.jsx("ul",{className:"mt-3 flex flex-wrap gap-x-3 gap-y-1",children:i.map(([r,c])=>e.jsxs("li",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-ink-secondary",children:[e.jsx("span",{"aria-hidden":"true","data-model-color":yt(r),className:"size-2 shrink-0 rounded-full",style:{backgroundColor:yt(r)}}),e.jsx("span",{className:"max-w-[9rem] truncate",children:as(c.label,n.instances)})]},r))})}function Rx({range:s,version:n,onSummary:a}){const[i,r]=o.useState("model"),c=o.useContext(Ae),l=Jt(s,"bot",n,"model"),d=Jt(s,i,n,i==="model"?void 0:"model");return o.useEffect(()=>{a(l)},[l,a]),c?null:e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-5","aria-label":t("usage.page.where"),children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.where")}),e.jsxs("div",{className:"mt-4 grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-3 text-[11px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t(Us.bot)}),l?e.jsxs(e.Fragment,{children:[e.jsx(Za,{groupBy:"bot",groups:l.groups}),e.jsx(Lx,{groups:l.groups})]}):e.jsx(ce,{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:$r.map(u=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===u,onClick:()=>r(u),className:z("rounded-md px-2 py-0.5 text-[11px] font-medium uppercase tracking-[0.06em]",i===u?"bg-accent/12 text-accent":"text-ink-secondary hover:bg-raised/60 hover:text-ink"),children:t(Us[u])},u))}),d?.groupBy===i?e.jsx(Za,{groupBy:i,groups:d.groups}):e.jsx(ce,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}const Bx=["bot",...$r];function Ox({range:s,version:n,onSummary:a}){const{state:i}=_(),[r,c]=o.useState("bot"),l=Jt(s,"bot",n),d=Jt(s,r,n);o.useEffect(()=>{a(l)},[l,a]);const u=d?.groupBy===r?[...d.groups].sort((p,x)=>nt(x)-nt(p)).filter(p=>nt(p)>0).slice(0,8):null;return e.jsx(Y,{label:t("usage.page.where"),block:"where",actions:e.jsx(de,{value:r,onChange:p=>c(p.target.value),"aria-label":t("usage.history.groupBy"),children:Bx.map(p=>e.jsx("option",{value:p,children:t(Us[p])},p))}),children:e.jsx(J,{children:u?u.length===0?e.jsxs(Se,{children:[e.jsx(Ti,{state:"sleep",size:48,className:"me-3"}),t("usage.page.whereEmpty")]}):u.map(p=>e.jsx(L,{title:r==="model"?as(p.label,i.instances):Kr(r,p),subtitle:t("usage.page.turns",{count:String(p.turns)}),children:e.jsxs("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:[ns(nt(p)),it(p.costUsd)&&p.costUsd>0?` · ${Je(p.costUsd)}`:""]})},p.key)):e.jsx(Se,{children:t("common.checking")})})})}function Fx(s){return new Date(s).toLocaleString(Pi(Ee()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function ei({root:s,onOpen:n}){const{state:a}=_(),i=$c(s,a.bots),r=s.bots.map(c=>Kc(a.bots,c.id,c.name)).join(", ");return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:n,className:"grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-xl px-3 py-2.5 text-left hover:bg-raised/50","data-testid":"usage-run",children:[e.jsx("span",{className:"flex w-[38px] shrink-0 -space-x-1.5 sm:w-[74px]",children:s.bots.slice(0,4).map((c,l)=>{const d=a.bots.find(u=>u.id===c.id);return d?e.jsx("span",{className:z("rounded-full ring-2 ring-card",l>1&&"hidden sm:block"),children:e.jsx(Qt,{bot:d,state:"idle",size:22,animated:!1})},c.id):e.jsx("span",{className:z("flex size-[22px] items-center justify-center rounded-full bg-raised text-[10px] font-semibold text-ink-secondary ring-2 ring-card",l>1&&"hidden sm:flex"),children:c.name.slice(0,1).toUpperCase()},c.id)})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[14px] text-ink",children:i}),e.jsxs("span",{className:"block truncate text-[12px] text-ink-tertiary",children:[Fx(s.startedAt)," · ",r]})]}),e.jsxs("span",{className:"flex items-center gap-3 text-[13px] tabular-nums text-ink-secondary",children:[s.running&&e.jsx(Wc,{}),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:Xi(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:Je(s.costUsd)}),e.jsx(Ct,{size:14,className:"text-ink-tertiary"})]})]})})}function Ux(){const s=o.useContext(Ae),[n,a]=o.useState("month"),i=o.useMemo(()=>Di(n),[n]),[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(0),[x,m]=o.useState(null),g=x?.budget??null,[f,h]=o.useState(null),j=o.useRef(null);o.useEffect(()=>{let v=!0;return Is(i).then(w=>{v&&(c(w),d(null))}).catch(w=>{v&&d(w instanceof Error?w.message:String(w))}),()=>{v=!1}},[i,u]),o.useEffect(()=>zc({onFrame:v=>{if(v.kind!=="runtime"||j.current)return;const w=v.event?.type;w!=="turn.started"&&w!=="turn.completed"||(j.current=setTimeout(()=>{j.current=null,p(N=>N+1)},Tx))},onMissedFrames:()=>p(v=>v+1)}),[]),o.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const b=()=>{r?.next&&Is(i,r.next).then(v=>c(w=>w?{...v,roots:[...w.roots,...v.roots]}:v))},y=r?.roots.some(v=>!v.timed);if(s){const v=r?.totals;return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"usage-page",children:[f?e.jsx(Qn,{id:f.id,at:f.at,actions:e.jsxs("button",{type:"button",onClick:()=>h(null),className:"settings-quiet flex shrink-0 cursor-pointer items-center gap-1",children:[e.jsx(Zn,{size:13}),t("trace.back")]})}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("usage.page.summary"),block:"totals",actions:e.jsx(de,{value:n,onChange:w=>{a(w.target.value),h(null)},"aria-label":t("usage.history.period"),children:ea.map(w=>e.jsx("option",{value:w,children:t(Qa[w])},w))}),footnote:l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):void 0,children:e.jsx(J,{children:e.jsx("div",{"data-testid":"usage-totals",className:"contents",children:v?e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("trace.stat.cost"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:v.costUsd?t("usage.page.estimated",{cost:Je(v.costUsd)}):Je(0)})}),e.jsx(L,{title:t("usage.page.runs"),children:e.jsxs("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:[String(r.roots.length),r.next!==void 0?"+":""]})}),e.jsx(L,{title:t("trace.stat.errors"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:String(v.errors)})}),e.jsx(L,{title:t("trace.stat.time"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:v.durationMs>0?Xi(Math.max(1e3,v.durationMs)):"—"})})]}):e.jsx(Se,{children:t("common.checking")})})})}),e.jsx(Xa,{summary:x}),e.jsx(Ox,{range:i,version:u,onSummary:m}),e.jsx(Y,{label:t("usage.page.runs"),block:"runs",footnote:y?t("usage.page.untimedNote"):void 0,actions:e.jsx("a",{href:ta(i),download:!0,className:"ui-button ui-button-md rounded-full",children:t("usage.history.export")}),children:e.jsxs(J,{children:[r&&!r.roots.length&&e.jsx(Se,{children:t("usage.page.runsEmpty")}),r?.roots.length?e.jsx("ul",{className:"flex flex-col p-1",children:r.roots.map(w=>e.jsx(ei,{root:w,onOpen:()=>h({id:w.id,at:w.startedAt})},w.id))}):null,r?.next!==void 0&&e.jsx("div",{className:"px-4 py-2",children:e.jsx("button",{type:"button",onClick:b,className:"settings-quiet cursor-pointer",children:t("usage.page.more")})})]})})]}),e.jsx(_a,{}),e.jsx(Va,{view:x?.caps,onSaved:()=>p(w=>w+1)}),e.jsx(Ka,{budget:g})]})}return e.jsxs("div",{className:"flex flex-col gap-4","data-testid":"usage-page",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink-secondary",children:t("usage.page.subtitle")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(de,{size:"sm",value:n,onChange:v=>{a(v.target.value),h(null)},"aria-label":t("usage.history.period"),children:ea.map(v=>e.jsx("option",{value:v,children:t(Qa[v])},v))}),e.jsxs("a",{href:ta(i),download:!0,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(Ki,{size:13}),t("usage.history.export")]})]})]}),l&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:l}),f?e.jsx(Qn,{id:f.id,at:f.at,actions:e.jsxs("button",{type:"button",onClick:()=>h(null),className:"flex shrink-0 items-center gap-1 rounded-lg px-2 py-1 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Zn,{size:13}),t("trace.back")]})}):e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"overflow-hidden rounded-2xl border border-hairline/50 bg-card","data-testid":"usage-totals",children:r?e.jsx(_c,{items:Hc(r.totals,t("trace.stat.time"))}):e.jsxs("div",{className:"flex items-center gap-2 p-5 text-[13px] text-ink-secondary",children:[e.jsx(ce,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(Xa,{summary:x}),e.jsx(Rx,{range:i,version:u,onSummary:m}),e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-2","aria-label":t("usage.page.runs"),children:[e.jsxs("div",{className:"px-3 pb-1 pt-3",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.runs")}),e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t("usage.page.runsHint")})]}),r&&!r.roots.length&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:t("usage.page.runsEmpty")}),e.jsx("ul",{className:"mt-1 flex flex-col",children:r?.roots.map(v=>e.jsx(ei,{root:v,onOpen:()=>h({id:v.id,at:v.startedAt})},v.id))}),r?.next!==void 0&&e.jsx("button",{type:"button",onClick:b,className:"m-2 rounded-lg px-3 py-1.5 text-[13px] text-accent hover:bg-raised/50",children:t("usage.page.more")}),y&&e.jsx("p",{className:"px-3 pb-3 pt-1 text-[12px] text-ink-tertiary",children:t("usage.page.untimedNote")})]})]}),e.jsx(_a,{}),e.jsx(Va,{view:x?.caps,onSaved:()=>p(v=>v+1)}),e.jsx(Ka,{budget:g})]})}const Mx=Gc,Ms="w-full min-w-0 rounded-lg border border-hairline/60 bg-inset px-3 py-1.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent disabled:opacity-60",Ds="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function Wr({onSubmit:s,onCancel:n,pending:a,error:i,submitLabel:r,children:c,form:l}){return e.jsxs("form",{onSubmit:s,className:"flex flex-col gap-2.5","aria-busy":a,[`data-${l}`]:"",children:[c,e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Qi,{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(ce,{size:13,className:"animate-spin"}),r]})]})]})}function ti({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=o.useState(s?.name??""),[l,d]=o.useState(""),[u,p]=o.useState(s?.bots??"all"),[x,m]=o.useState(!1),[g,f]=o.useState(null),h=async j=>{if(j.preventDefault(),!x){m(!0),f(null);try{s?await qc(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:l,bots:u}):await Vc(r.trim(),l,u),d(""),await i()}catch(b){f(b instanceof Error&&b.message?b.message:t("settings.vault.secret.saveError"))}finally{m(!1)}}};return e.jsxs(Wr,{form:"secret-form",onSubmit:j=>{h(j)},onCancel:a,pending:x,error:g,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:Ds,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:Mx,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:j=>c(j.target.value),disabled:x,className:Ms}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:Ds,children:[t(s?"settings.vault.secret.valueKeep":"settings.vault.secret.value"),e.jsx("input",{name:"secretValue",type:"password",autoComplete:"new-password",spellCheck:!1,required:!s,value:l,placeholder:"••••••••",onChange:j=>d(j.target.value),disabled:x,className:Ms})]}),e.jsx(lt,{value:u,onChange:p,bots:n,disabled:x})]})}function Dx({bots:s,onCancel:n,onSaved:a}){const[i,r]=o.useState(""),[c,l]=o.useState("all"),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(null),f=async h=>{if(h.preventDefault(),d)return;const j=Jc(i);if(!j.length){x(t("settings.vault.env.none"));return}u(!0),x(null),g(null);try{g(await Yc(j,c)),r("")}catch(b){x(b instanceof Error&&b.message?b.message:t("settings.vault.secret.saveError"))}finally{u(!1),await a().catch(()=>{})}};return e.jsxs(Wr,{form:"env-form",onSubmit:h=>{f(h)},onCancel:n,pending:d,error:p,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:Ds,children:[t("settings.vault.env.label"),e.jsx("textarea",{name:"envText",rows:5,autoComplete:"off",spellCheck:!1,autoFocus:!0,value:i,onChange:h=>r(h.target.value),disabled:d,placeholder:"STRIPE_SECRET_KEY=…",dir:"ltr",className:`${Ms} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(lt,{value:c,onChange:l,bots:s,disabled:d}),m!==null&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("settings.vault.env.done",{count:String(m)})})]})}const ys="self-hosted";function zx({status:s,disabled:n,team:a,onChange:i}){const[r,c]=o.useState(!1),[l,d]=o.useState(xs[0]),[u,p]=o.useState(""),[x,m]=o.useState(""),[g,f]=o.useState(""),[h,j]=o.useState(""),[b,y]=o.useState(null),[v,w]=o.useState(null),N=()=>{m(""),f(""),j("")},C=async(P,E)=>{if(!b){y(P),w(null);try{await i(await E()),P==="connect"&&(N(),c(!1))}catch(A){w(A instanceof Error&&A.message?A.message:t("settings.vault.bitwarden.error"))}finally{y(null)}}},T=l===ys?u.trim():l,F=!!(T&&x.trim()&&g.trim()&&h),k=P=>{P.preventDefault(),F&&C("connect",()=>Xc({serverUrl:T,clientId:x.trim(),clientSecret:g.trim(),password:h}))},S=s.connected?t("settings.vault.bitwarden.connected",{account:s.account??s.server??"Bitwarden",count:String(s.items??0)}):t("settings.vault.bitwarden.line");return e.jsxs("section",{className:"flex flex-col gap-2 px-4 py-3","aria-label":t("settings.vault.bitwarden.title"),"data-bitwarden":!0,children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.vault.bitwarden.title")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary","data-bitwarden-line":!0,children:S})]}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"settings-quiet cursor-pointer",disabled:n||b!==null,onClick:()=>{C("refresh",Qc)},children:t("settings.logins.onePassword.refresh")}),e.jsx("button",{type:"button",className:"ui-button",disabled:n||b!==null,"aria-label":t("settings.vault.bitwarden.disconnect"),onClick:()=>{C("disconnect",Zc)},children:t("settings.logins.onePassword.disconnect")})]}):e.jsx("button",{type:"button",className:"ui-button",disabled:n,onClick:()=>c(!0),children:t("settings.vault.bitwarden.connect")})]}),a&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-tertiary","data-bitwarden-team":!0,children:t("settings.vault.bitwarden.team")}),s.connected&&s.error&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:s.error}),v&&!r&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:v}),r&&!s.connected&&e.jsx(St,{title:t("settings.vault.bitwarden.connect"),onClose:()=>{N(),c(!1)},footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{N(),c(!1)},children:t("common.cancel")}),e.jsxs("button",{type:"submit",form:"bitwarden-connect",className:"ui-button ui-button-primary gap-1.5",disabled:n||b!==null||!F,children:[b==="connect"&&e.jsx(ce,{size:13,className:"animate-spin"}),t("settings.vault.bitwarden.connect")]})]}),children:e.jsxs("form",{id:"bitwarden-connect",className:"flex flex-col gap-3",onSubmit:k,children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary","data-bitwarden-guide":!0,children:t("settings.vault.bitwarden.guide")}),e.jsx(fe,{label:t("settings.vault.bitwarden.server"),children:e.jsxs(de,{name:"bitwardenServer",value:l,onChange:P=>d(P.target.value),disabled:b!==null,children:[e.jsx("option",{value:xs[0],children:"bitwarden.com"}),e.jsx("option",{value:xs[1],children:"bitwarden.eu"}),e.jsx("option",{value:ys,children:t("settings.vault.bitwarden.selfHosted")})]})}),l===ys&&e.jsx(fe,{label:t("settings.vault.bitwarden.address"),children:e.jsx("input",{name:"bitwardenServerUrl",type:"url",autoComplete:"off",spellCheck:!1,placeholder:"https://vault.example.com",maxLength:2048,value:u,onChange:P=>p(P.target.value),disabled:b!==null,className:he})}),e.jsx(fe,{label:"client_id",children:e.jsx("input",{name:"bitwardenClientId",type:"text",autoComplete:"off",spellCheck:!1,maxLength:200,value:x,onChange:P=>m(P.target.value),disabled:b!==null,className:he})}),e.jsx(fe,{label:"client_secret",children:e.jsx("input",{name:"bitwardenClientSecret",type:"password",autoComplete:"off",spellCheck:!1,maxLength:256,value:g,onChange:P=>f(P.target.value),disabled:b!==null,className:he})}),e.jsx(fe,{label:t("settings.vault.bitwarden.password"),hint:t("settings.vault.bitwarden.note"),children:e.jsx("input",{name:"bitwardenPassword",type:"password",autoComplete:"off",spellCheck:!1,maxLength:1024,value:h,onChange:P=>j(P.target.value),disabled:b!==null,className:he})}),v&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:v})]})})]})}const zs={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",bitwarden:"settings.logins.source.bitwarden",linked:"settings.logins.source.1password"},_x=s=>s.source==="linked"&&s.provider==="bitwarden"?zs.bitwarden:zs[s.source],Ht="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",Hx=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function $x(s,n,a,i){const r=i.trim().toLowerCase();return[...a==="secrets"?[]:s.map(l=>({kind:"login",key:[l.site,l.username,...l.hosts].join(" "),login:l})),...a==="logins"?[]:n.map(l=>({kind:"secret",key:l.name,secret:l}))].filter(l=>!r||l.key.toLowerCase().includes(r)).sort((l,d)=>l.key.localeCompare(d.key))}function Kx(){const{state:s,dispatch:n}=_(),a=kt(),i=a===!1&&!!s.config?.team,r=s.bots.map(I=>({id:I.id,name:I.name})),[c,l]=o.useState(null),[d,u]=o.useState([]),[p,x]=o.useState({connected:!1}),[m,g]=o.useState(null),[f,h]=o.useState(null),[j,b]=o.useState(""),[y,v]=o.useState("all"),[w,N]=o.useState(!1),[C,T]=o.useState(!1),[F,k]=o.useState(null),[S,P]=o.useState(""),[E,A]=o.useState("all"),[V,R]=o.useState(!1),[K,te]=o.useState(null),[ue,ae]=o.useState("all"),[X,B]=o.useState(!1),[W,G]=o.useState(""),[oe,M]=o.useState(!1),[$,Z]=o.useState(null),[ee,O]=o.useState(!1),[re,ne]=o.useState([]),me=async()=>{try{const I=await sd();l(I.logins??[]),u(I.secrets??[]),x(I.onePassword??{connected:!1}),g(I.bitwarden??null),h(null)}catch(I){h(I instanceof Error&&I.message?I.message:t("settings.vault.loadError"))}};if(o.useEffect(()=>{(a||i)&&me()},[a,i]),a===!1&&!i)return e.jsx(xe,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const q=I=>{if(I==="all")return t("settings.logins.allBots");const le=I.flatMap(ye=>r.find(Ge=>Ge.id===ye)?.name??[]);return le.length?le.join(", "):t("settings.logins.noBots")},ge=I=>I?t("settings.logins.used",{when:pr(I)}):t("settings.logins.neverUsed"),be=(I,le)=>{k(null),Z(null),M(!1),le&&(ae(le.bots),B(le.exactHost),G(le.hosts[0]??le.site)),te(I)},we=I=>{N(!1),te(null),Z(null),k(I)},Be=async(I,le)=>{if($!==I){Z(I);return}O(!0),ne([]);try{le==="login"?await od(I):ne(await cd(I)),Z(null),await me()}catch(ye){h(ye instanceof Error&&ye.message?ye.message:t("settings.logins.deleteError"))}finally{O(!1)}},Xe=(I,le,ye,Ge)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[!i&&e.jsx("button",{type:"button",className:Ht,disabled:ee,onClick:Ge,"aria-label":le==="login"?t("settings.logins.changeFor",{site:ye}):t("settings.vault.secret.changeFor",{name:ye}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:Ht,disabled:ee,onClick:()=>{Be(I,le)},"aria-label":$===I?t("settings.logins.deleteConfirm"):le==="login"?t("settings.logins.deleteFor",{site:ye}):t("settings.vault.secret.deleteFor",{name:ye}),children:[e.jsx(We,{size:13}),$===I?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),pe=(I,le)=>le&&!le.ownBots?t("settings.logins.onePassword.vaultChoice",{who:q(I)}):q(I),Pe=(I,le)=>!i&&K!==I&&e.jsx("button",{type:"button",className:Ht,disabled:ee,onClick:()=>be(I),"aria-label":t("settings.logins.onePassword.changeItem",{name:le}),children:t("settings.logins.change")}),Te=(I,le)=>e.jsx(Wx,{item:I,value:le,bots:r,onCancel:()=>te(null),onSaved:async()=>{te(null),await me()}}),Fe=$x(c??[],d,y,j),Ie=c!==null&&c.length===0&&d.length===0,rs=I=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":I.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Qi,{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:I.site,children:I.site}),I.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(nd,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:I.username||t("settings.logins.noUsername")}),si(I)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:si(I)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(zs[I.source]),pe(I.bots,I.onePassword),ge(I.lastUsedAt)].join(" · ")}),na(I,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:q(na(I,s.bots))})})]}),I.source!=="1password"&&I.source!=="bitwarden"&&Xe(I.id,"login",I.site,()=>be(I.id,I)),I.onePassword&&Pe(I.id,I.site)]}),K===I.id&&I.onePassword&&Te(I.onePassword,I.bots),K===I.id&&!I.onePassword&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(sa,{site:{value:W,onChange:G},username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>te(null),onSubmit:async le=>{const ye=ad(W);await id(I.id,{...ye&&I.hosts.includes(ye)?{}:{site:W},password:le.password,totp:le.totp,removeTotp:oe,bots:ue,...X===I.exactHost?{}:{exactHost:X}}),te(null),await me()},children:[I.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:le=>M(le.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(ni,{checked:X,onChange:B,label:t("settings.logins.exactHostFor",{hosts:I.hosts.join(", "),site:I.site})}),e.jsx(lt,{value:ue,onChange:ae,bots:r})]})})]},I.id),ls=I=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":I.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(rd,{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:I.name,children:I.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(_x(I)),pe(I.bots,I.source==="linked"?I.onePassword:void 0),ge(I.lastUsedAt)].join(" · ")})]}),I.source!=="linked"&&Xe(I.id,"secret",I.name,()=>be(I.id)),I.source==="linked"&&I.onePassword&&Pe(I.id,I.name)]}),K===I.id&&I.source==="linked"&&I.onePassword&&Te(I.onePassword,I.bots),K===I.id&&I.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx(ti,{secret:I,bots:r,onCancel:()=>te(null),onSaved:async()=>{te(null),await me()}})})]},I.id);return e.jsxs("div",{className:"flex flex-col gap-6","aria-busy":c===null||ee,"data-vault":!0,children:[e.jsxs(Y,{label:t("settings.vault.saved"),block:"saved-list",description:i?t("settings.vault.memberSubtitle"):s.config?.cloudHome===!0?e.jsx("span",{"data-logins-cloud-own":!0,children:t("settings.logins.cloudOwn")}):void 0,actions:i?void 0:e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",className:"ui-button gap-1",disabled:c===null,"aria-expanded":w,onClick:()=>N(!w),onKeyDown:I=>{I.key==="Escape"&&N(!1)},children:[t("settings.vault.add"),e.jsx(qs,{size:12,"aria-hidden":"true"})]}),w&&e.jsx("div",{className:"popover-surface absolute end-0 top-full z-10 mt-1 flex min-w-[11rem] flex-col rounded-[12px] p-1","data-vault-add":!0,"data-look":"popover",children:Hx.map(([I,le])=>e.jsx("button",{type:"button",className:"h-8 rounded-lg px-2 text-start text-[14px] leading-5 text-ink hover:bg-menu-hover",onClick:()=>we(I),children:t(le)},I))})]}),footnote:i?void 0:e.jsxs(e.Fragment,{children:[t("settings.vault.limitsShort")," ",e.jsx(ze,{onClick:()=>T(I=>!I)}),C&&e.jsx("span",{className:"mt-1 block",children:t("settings.logins.limits")})]}),children:[!Ie&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 px-4",children:[!i&&e.jsx(ed,{label:t("settings.vault.filter"),attr:"data-vault-filter",value:y,onChange:v,options:[{value:"all",label:t("settings.vault.filter.all")},{value:"logins",label:t("settings.vault.filter.logins")},{value:"secrets",label:t("settings.vault.filter.secrets")}]}),e.jsx("input",{"data-vault-search":!0,type:"text",value:j,onChange:I=>b(I.target.value),autoComplete:"off",spellCheck:!1,placeholder:t("settings.vault.search"),"aria-label":t("settings.vault.search"),className:`${he} ms-auto h-7 max-w-[200px]`})]}),e.jsxs(J,{children:[F==="login"&&e.jsx("div",{className:"p-4",children:e.jsxs(sa,{site:{value:S,onChange:P},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>k(null),onSubmit:async I=>{await td(S,I,E,V),k(null),P(""),A("all"),R(!1),await me()},children:[e.jsx(ni,{checked:V,onChange:R,label:t("settings.logins.exactHost")}),e.jsx(lt,{value:E,onChange:A,bots:r})]})}),F==="secret"&&e.jsx("div",{className:"p-4",children:e.jsx(ti,{bots:r,onCancel:()=>k(null),onSaved:async()=>{k(null),await me()}})}),F==="env"&&e.jsx("div",{className:"p-4",children:e.jsx(Dx,{bots:r,onCancel:()=>k(null),onSaved:me})}),c===null&&!f&&e.jsx(Se,{children:t("settings.vault.loading")}),Ie&&!F&&e.jsxs(Se,{children:[e.jsx(Ti,{state:"sleep",size:48,className:"me-3"}),t(i?"settings.vault.memberEmpty":"settings.vault.emptyShort")]}),!Ie&&c!==null&&Fe.length===0&&e.jsx("div",{"data-vault-none":!0,className:"contents",children:e.jsx(Se,{children:t("settings.vault.noMatch")})}),Fe.length>0&&e.jsx("ul",{className:"divide-y-[0.5px] divide-(--settings-edge) px-4","data-logins-list":!0,children:Fe.map(I=>I.kind==="login"?rs(I.login):ls(I.secret))})]}),re.length>0&&e.jsx("p",{role:"status",className:"px-4 text-[12px] leading-4 text-warning","data-vault-keys-off":!0,children:t("settings.vault.secret.keyOff",{servers:re.join(", ")})}),f&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:f})]}),!i&&e.jsx(Y,{label:t("settings.vault.elsewhere"),block:"vault-more",children:e.jsxs(J,{children:[e.jsx("div",{"data-vault-keys":!0,className:"contents",children:e.jsx(je,{title:t("settings.vault.keys.title"),subtitle:t("settings.vault.keys.hintShort",{app:ke()}),onClick:()=>n({type:"toggleAppSettings",open:!0,section:"connections"})})}),e.jsx(qx,{status:p,disabled:c===null,bots:r,botNames:q,team:!!s.config?.team,onChange:async I=>{x(I),await me()}}),m&&e.jsx(zx,{status:m,disabled:c===null,team:!!s.config?.team,onChange:async I=>{g(I),await me()}})]})})]})}function si(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 ni({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 Wx({item:s,value:n,bots:a,onCancel:i,onSaved:r}){const[c,l]=o.useState(n),[d,u]=o.useState(!1),[p,x]=o.useState(null),m=async g=>{u(!0),x(null);try{await ud(s.item,g),await r()}catch(f){x(f instanceof Error&&f.message?f.message:t("settings.logins.onePassword.error"))}finally{u(!1)}};return e.jsxs("div",{className:"ms-6 flex flex-col gap-2 rounded-lg bg-inset/60 p-3","data-onepassword-item":s.item,children:[e.jsx(lt,{value:c,onChange:l,bots:a,disabled:d}),e.jsx("p",{className:"text-[12px] text-ink-tertiary",children:t("settings.logins.onePassword.itemNote")}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[s.ownBots&&e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:d,onClick:()=>{m(null)},children:t("settings.logins.onePassword.useVaultChoice")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:d,onClick:i,children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:d,onClick:()=>{m(c)},children:t("settings.logins.saveChange")})]})]})}function Gx({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,l]=o.useState(!1),[d,u]=o.useState(s.bots),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=async()=>{x(!0),g(null);try{await r(await dd(s.id,d)),l(!1)}catch(h){g(h instanceof Error&&h.message?h.message:t("settings.logins.onePassword.error"))}finally{x(!1)}};return e.jsxs("li",{className:"flex flex-col gap-2 py-2","data-vault":s.title,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:s.title}),e.jsx("div",{className:"text-[12px] text-ink-tertiary",children:t("settings.logins.onePassword.vaultUse",{count:String(s.items),who:a(s.bots)})})]}),!c&&e.jsx("button",{type:"button",className:Ht,disabled:i||p,onClick:()=>{u(s.bots),l(!0)},"aria-label":t("settings.logins.onePassword.changeVault",{vault:s.title}),children:t("settings.logins.change")})]}),c&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg bg-inset/60 p-3",children:[e.jsx(lt,{value:d,onChange:u,bots:n,disabled:p}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:p,onClick:()=>l(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:p,onClick:()=>{f()},children:t("settings.logins.saveChange")})]})]})]})}function qx({status:s,disabled:n,bots:a,botNames:i,team:r,onChange:c}){const[l,d]=o.useState(""),[u,p]=o.useState(!1),[x,m]=o.useState(null),[g,f]=o.useState(null),h=async(b,y)=>{if(!x){m(b),f(null);try{await c(await y()),b==="connect"&&(d(""),p(!1))}catch(v){f(v instanceof Error&&v.message?v.message:t("settings.logins.onePassword.error"))}finally{m(null)}}},j=b=>{b.preventDefault(),l.trim()&&h("connect",()=>ld(l.trim()))};return e.jsxs("section",{className:"flex flex-col gap-2 px-4 py-3","aria-label":t("settings.vault.manager"),"data-onepassword":!0,children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.vault.connectManager")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:s.connected?t("settings.logins.onePassword.connected",{vaults:(s.vaults??[]).map(b=>b.title).join(", ")||"—",count:String(s.items??0)}):t("settings.vault.managerLine")})]}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"settings-quiet cursor-pointer",disabled:n||x!==null,onClick:()=>{h("refresh",pd)},children:t("settings.logins.onePassword.refresh")}),e.jsx("button",{type:"button",className:"ui-button",disabled:n||x!==null,onClick:()=>{h("disconnect",md)},children:t("settings.logins.onePassword.disconnect")})]}):e.jsx("button",{type:"button",className:"ui-button",disabled:n,onClick:()=>p(!0),children:t("settings.logins.onePassword.connect")})]}),r&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-tertiary","data-onepassword-team":!0,children:t("settings.logins.onePassword.team")}),s.connected&&s.error&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:s.error}),s.connected&&!!s.vaults?.length&&e.jsx("ul",{className:"divide-y-[0.5px] divide-(--settings-edge)","aria-label":t("settings.logins.onePassword.vaults"),children:s.vaults.map(b=>e.jsx(Gx,{vault:b,bots:a,botNames:i,disabled:n,onChange:c},b.id))}),g&&!u&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g}),u&&!s.connected&&e.jsx(St,{title:t("settings.vault.connectManager"),onClose:()=>p(!1),footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>p(!1),children:t("common.cancel")}),e.jsxs("button",{type:"submit",form:"onepassword-connect",className:"ui-button ui-button-primary gap-1.5",disabled:n||x!==null||!l.trim(),children:[x==="connect"&&e.jsx(ce,{size:13,className:"animate-spin"}),t("settings.logins.onePassword.connect")]})]}),children:e.jsxs("form",{id:"onepassword-connect",className:"flex flex-col gap-3",onSubmit:b=>{j(b)},children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.logins.onePassword.guide")}),r&&e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.logins.onePassword.team")}),e.jsx(fe,{label:t("settings.logins.onePassword.token"),hint:t("settings.logins.onePassword.note"),children:e.jsx("input",{name:"onePasswordToken",type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:l,onChange:b=>d(b.target.value),disabled:n||x!==null,className:he})}),g&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g})]})})]})}function Vx(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(null),[r,c]=o.useState(!1),[l,d]=o.useState(""),[u,p]=o.useState(!1),x=o.useRef(!1),m=a??s.config?.automaticRecovery??{enabled:!1},g=s.instances.filter(C=>C.snapshot.state==="available"&&!C.policy),f=C=>g.find(T=>T.instanceId===C.backup?.instanceId),h=C=>{const T=f(C);return T?.models.options.filter(F=>!F.orgBlocked&&!F.needsCliUpdate&&(T.snapshot.authenticated!==!1||F.custom))??[]},j=f(m),b=h(m),y=b.some(C=>C.id===m.backup?.model),v=async C=>{if(!x.current){x.current=!0,c(!0),d("");try{const T=await D("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:C.enabled,...C.backup?.model?{backup:C.backup}:{}}})});n({type:"configStatus",config:T}),i(null)}catch(T){d(T instanceof Error?T.message:t("settings.recovery.error"))}finally{x.current=!1,c(!1)}}},w=C=>{i(C),d(""),(!C.enabled||h(C).some(F=>F.id===C.backup?.model))&&v(C)},N=l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):r?e.jsx("span",{role:"status",children:t("settings.threads.saving")}):m.enabled&&!y?t("settings.recovery.required"):void 0;return e.jsxs(J,{selectWidth:200,children:[e.jsx(L,{title:t("settings.recovery.enable"),subtitle:e.jsxs("span",{id:"automatic-recovery-help",children:[t("settings.recovery.short")," ",e.jsx(ze,{onClick:()=>p(C=>!C)})]}),message:u||!m.enabled&&l?e.jsxs("span",{"data-recovery-more":"",className:"flex flex-col gap-1",children:[u&&e.jsxs(e.Fragment,{children:[e.jsx("span",{id:"automatic-recovery-scope",children:t("settings.recovery.help")}),e.jsx("span",{children:t("settings.recovery.scopeHanded")}),e.jsx("span",{id:"automatic-recovery-own",children:t("settings.recovery.ownBackups")}),e.jsx("span",{children:t("settings.recovery.charges")})]}),!m.enabled&&l&&e.jsx("span",{role:"alert",className:"text-danger",children:l})]}):void 0,children:e.jsx(ie,{id:"automatic-recovery-enabled",checked:m.enabled,disabled:r||!s.config,"aria-label":t("settings.recovery.enable"),"aria-describedby":"automatic-recovery-help",onClick:()=>w({...m,enabled:!m.enabled})})}),m.enabled&&e.jsx(L,{title:t("settings.recovery.engine"),children:e.jsxs(de,{id:"automatic-recovery-engine","aria-label":t("settings.recovery.engine"),value:m.backup?.instanceId??"",disabled:r,onChange:C=>w({enabled:m.enabled,...C.target.value?{backup:{instanceId:C.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),m.backup&&!j&&e.jsx("option",{value:m.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.instanceId})}),g.map(C=>e.jsx("option",{value:C.instanceId,disabled:!C.models.options.some(T=>C.snapshot.authenticated!==!1||T.custom),children:C.displayName},C.instanceId))]})}),m.enabled&&e.jsx(L,{title:t("settings.recovery.model"),message:N,children:e.jsxs(de,{id:"automatic-recovery-model","aria-label":t("settings.recovery.model"),value:m.backup?.model??"",disabled:r||!j,onChange:C=>w({enabled:m.enabled,backup:{instanceId:j.instanceId,model:C.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),m.backup?.model&&!y&&e.jsx("option",{value:m.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.model})}),b.map(C=>e.jsx("option",{value:C.id,children:C.label},C.id))]})})]})}const ai=10,Jx="90, 80, 70, 60, 50, 40, 30, 20, 10",Yx=10;function Xx(s){const n=s.split(/[\s,]+/).filter(Boolean);if(!n.length)return{};if(n.some(i=>!/^\d+$/.test(i)||Number(i)<1||Number(i)>99))return{error:"settings.pool.levelsNumbers"};const a=n.map(Number);return a.length>9?{error:"settings.pool.levelsCount"}:a.some((i,r)=>r>0&&i>=a[r-1])?{error:"settings.pool.levelsFalling"}:{levels:a}}function Qx(s,n){const a=s.trim();if(!a)return{};if(!/^\d+$/.test(a)||Number(a)>98)return{error:"settings.pool.floorNumber"};const i=Number(a);return i>=(n?.at(-1)??Yx)?{error:"settings.pool.floorLow"}:{floor:i}}function Zx(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(null),[r,c]=o.useState(!1),[l,d]=o.useState(""),[u,p]=o.useState(!1),x=o.useRef(!1),[m,g]=o.useState(null),[f,h]=o.useState(null),[j,b]=o.useState(!1),[y,v]=o.useState(""),w=s.config?.aiPool,N=a??w??{enabled:!1,mode:"even",members:[]},C=m??N.levels?.join(", ")??"",T=f??(N.floor===void 0?"":String(N.floor)),F=Xx(C),k=Qx(T,F.levels),S=s.instances.filter(O=>O.snapshot.state==="available"&&!O.policy),P=O=>S.find(re=>re.instanceId===O),E=O=>{const re=P(O);return re?.models.options.filter(ne=>!ne.orgBlocked&&!ne.needsCliUpdate&&(re.snapshot.authenticated!==!1||ne.custom))??[]},A=O=>P(O.instanceId)?.displayName??O.instanceId,V=O=>{const re=P(O.instanceId);return re?re.models.options.find(ne=>ne.id===O.model)?.label??O.model:t("settings.recovery.unavailable",{name:O.model})},R=new Set(N.members.map(O=>O.instanceId)),K=S.filter(O=>!R.has(O.instanceId)),te=E(y),ue=N.enabled&&N.members.length<2,ae=!F.error&&!k.error,X=async O=>{if(x.current)return;x.current=!0,c(!0),d("");const re=F.error?w?.levels:F.levels,ne=k.error?w?.floor:k.floor;try{const me=await D("/api/config",{method:"PUT",body:JSON.stringify({aiPool:{enabled:O.enabled,mode:O.mode,members:O.members,...re?{levels:re}:{},...ne!==void 0?{floor:ne}:{}}})});n({type:"configStatus",config:me}),i(null),g(null),h(null)}catch(me){d(me instanceof Error?me.message:t("settings.pool.error"))}finally{x.current=!1,c(!1)}},B=O=>{i(O),d(""),(!O.enabled||O.members.length>=2&&ae)&&X(O)},W=O=>B({...N,members:O}),G=(O,re)=>{const ne=[...N.members];[ne[O],ne[O+re]]=[ne[O+re],ne[O]],W(ne)},oe=l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):r?e.jsx("span",{role:"status",children:t("settings.threads.saving")}):ue?t("settings.pool.needTwo"):void 0,M=(O,re)=>re?e.jsx("span",{id:O,role:"alert",className:"text-danger",children:t(re)}):void 0,$=()=>{(m!==null||f!==null)&&B(N)},Z=O=>{O.key==="Enter"&&O.currentTarget.blur()},ee="settings-quiet cursor-pointer disabled:cursor-default disabled:opacity-40";return e.jsxs(J,{selectWidth:200,children:[e.jsx(L,{title:t("settings.pool.title"),subtitle:e.jsxs("span",{id:"ai-pool-help",children:[t("settings.pool.short")," ",e.jsx(ze,{onClick:()=>p(O=>!O)})]}),message:u||!N.enabled&&l?e.jsxs("span",{"data-ai-pool-more":"",className:"flex flex-col gap-1",children:[u&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:t("settings.pool.helpEven")}),e.jsx("span",{children:t("settings.pool.helpInOrder")}),e.jsx("span",{children:t("settings.pool.helpSamePlan")}),e.jsx("span",{children:t("settings.pool.helpPayPerUse")})]}),!N.enabled&&l&&e.jsx("span",{role:"alert",className:"text-danger",children:l})]}):void 0,children:e.jsx(ie,{id:"ai-pool-enabled",checked:N.enabled,disabled:r||!s.config,"aria-label":t("settings.pool.title"),"aria-describedby":"ai-pool-help",onClick:()=>B({...N,enabled:!N.enabled})})}),N.enabled&&e.jsx(L,{title:t("settings.pool.mode"),children:e.jsxs(de,{id:"ai-pool-mode","aria-label":t("settings.pool.mode"),value:N.mode,disabled:r,onChange:O=>B({...N,mode:O.target.value==="inOrder"?"inOrder":"even"}),children:[e.jsx("option",{value:"even",children:t("settings.pool.modeEven")}),e.jsx("option",{value:"inOrder",children:t("settings.pool.modeInOrder")})]})}),N.enabled&&N.members.map((O,re)=>e.jsxs(L,{title:A(O),subtitle:V(O),children:[e.jsx("button",{type:"button",className:ee,disabled:r||re===0,"aria-label":t("settings.pool.moveUp",{name:A(O)}),onClick:()=>G(re,-1),children:e.jsx(xd,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:ee,disabled:r||re===N.members.length-1,"aria-label":t("settings.pool.moveDown",{name:A(O)}),onClick:()=>G(re,1),children:e.jsx(qs,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:ee,disabled:r,"aria-label":t("settings.pool.remove",{name:A(O)}),onClick:()=>W(N.members.filter((ne,me)=>me!==re)),children:e.jsx(Oe,{size:14,"aria-hidden":"true"})})]},O.instanceId)),N.enabled&&N.members.length<ai&&K.length>0&&e.jsx(L,{title:t("settings.pool.add"),children:e.jsxs(de,{id:"ai-pool-add-engine","aria-label":t("settings.pool.add"),value:y,disabled:r,onChange:O=>v(O.target.value),children:[e.jsx("option",{value:"",children:t("settings.pool.chooseAi")}),K.map(O=>e.jsx("option",{value:O.instanceId,disabled:!O.models.options.some(re=>O.snapshot.authenticated!==!1||re.custom),children:O.displayName},O.instanceId))]})}),N.enabled&&y&&!R.has(y)&&e.jsx(L,{title:t("settings.pool.model"),children:e.jsxs(de,{id:"ai-pool-add-model","aria-label":t("settings.pool.model"),value:"",disabled:r,onChange:O=>{O.target.value&&(v(""),W([...N.members,{instanceId:y,model:O.target.value}]))},children:[e.jsx("option",{value:"",children:t("settings.pool.chooseModel")}),te.map(O=>e.jsx("option",{value:O.id,children:O.label},O.id))]})}),N.enabled&&N.members.length>=ai&&e.jsx("div",{className:"px-4 py-3 text-[12px] leading-4 text-ink-secondary",children:t("settings.pool.full")}),N.enabled&&oe&&e.jsx("div",{"data-ai-pool-status":"",className:"px-4 py-3 text-[12px] leading-4 text-ink-secondary",children:oe}),N.enabled&&e.jsxs(wt,{id:"ai-pool-more",title:t("settings.pool.more"),open:j,onToggle:()=>b(!j),children:[e.jsx(L,{title:t("settings.pool.levels"),subtitle:t("settings.pool.levelsLine"),message:M("ai-pool-levels-error",F.error),children:e.jsx("input",{id:"ai-pool-levels",type:"text",inputMode:"numeric",value:C,placeholder:Jx,disabled:r,"aria-label":t("settings.pool.levels"),"aria-invalid":!!F.error,"aria-describedby":F.error?"ai-pool-levels-error":void 0,onChange:O=>{g(O.target.value),d("")},onBlur:$,onKeyDown:Z,className:z(Re,"w-[200px] text-left",F.error&&"border-danger/60")})}),e.jsx(L,{title:t("settings.pool.floor"),subtitle:t("settings.pool.floorLine"),message:M("ai-pool-floor-error",k.error),children:e.jsx("input",{id:"ai-pool-floor",type:"number",min:0,max:98,step:1,inputMode:"numeric",value:T,placeholder:"0",disabled:r,"aria-label":t("settings.pool.floor"),"aria-invalid":!!k.error,"aria-describedby":k.error?"ai-pool-floor-error":void 0,onChange:O=>{h(O.target.value),d("")},onBlur:$,onKeyDown:Z,className:z(Re,k.error&&"border-danger/60")})})]})]})}function eg({row:s=!1}){const n=!!_().state.config?.team,[a,i]=o.useState(null),[r,c]=o.useState(!1),l=o.useId();o.useEffect(()=>{if(!n)return;let u=!0;return D("/api/me/away-emails",{timeoutMs:1e4}).then(p=>{u&&i(p.on)},()=>{}),()=>{u=!1}},[n]);const d=u=>{const p=a;i(u),c(!1),D("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:u}),timeoutMs:1e4}).then(x=>i(x.on),()=>{i(p),c(!0)})};return!n||a===null?null:e.jsxs("div",{className:s?"flex flex-col gap-1 px-4 py-[13px]":"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{id:l,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(ie,{"aria-labelledby":l,checked:a,onClick:()=>d(!a)})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.awayEmailsHelp")}),r&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.awayEmailsError")})]})}function tg({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(sg,{bridge:s,read:n,write:a}):null}function sg({bridge:s,read:n,write:a}){const[i,r]=o.useState(null),[c,l]=o.useState(!1),[d,u]=o.useState(!1),[p,x]=o.useState(null);if(o.useEffect(()=>{let f=!0;const h=()=>{n().then(b=>{f&&r(b)}).catch(()=>{})};h();const j=s.onNotice(h);return()=>{f=!1,j()}},[s,n]),!i?.shown)return null;const m=f=>{l(!1),u(!0),x(null),a(f).then(h=>r(h),h=>x(Xl(h)??t("cloudAccount.keepHere.failed"))).finally(()=>u(!1))},g=()=>{i.on?m(!1):i.moved?l(!0):m(!0)};return e.jsxs(Y,{label:t("settings.data.move",{place:t("cloudSetup.myCloud")}),block:"move",children:[e.jsx(J,{children:e.jsx("div",{"data-cloud-keep":i.coming?"coming":i.on?"on":"off",className:"contents",children:e.jsx(L,{title:t("cloudAccount.keepHere.title"),subtitle:t("cloudAccount.keepHere.line"),message:e.jsxs(e.Fragment,{children:[i.coming&&e.jsx("span",{role:"status",className:"block",children:t("cloudAccount.keepHere.coming")}),p&&e.jsx("span",{role:"alert",className:"block text-danger",children:p})]}),children:e.jsx(ie,{checked:i.on||i.coming,disabled:d||i.coming,"aria-label":t("cloudAccount.keepHere.title"),onClick:g})})})}),c&&e.jsxs(St,{title:t("cloudAccount.keepHere.confirmTitle"),onClose:()=>l(!1),children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("cloudAccount.keepHere.confirm")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button","data-autofocus":"",className:"ui-button",onClick:()=>l(!1),children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>m(!0),children:t("cloudAccount.keepHere.bringBack")})]})]})]})}function ng(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 ag({domain:s,serverIpv4:n}){const a=ng(s);if(!a)return e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"flex flex-col",children:i.map(([r,c])=>e.jsxs("div",{className:"grid min-h-7 grid-cols-[96px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] leading-4 text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(ig,{value:c,label:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.recordHint")})]})}function ig({value:s,label:n}){const{state:a,copy:i}=Xt(s);return e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("code",{className:"min-w-0 select-all truncate font-mono text-[12px] leading-4 text-ink",children:s}),e.jsx("button",{type:"button",onClick:i,"aria-label":a==="failed"?t("common.copyFailed"):n,className:"flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-ink-secondary hover:bg-menu-hover hover:text-ink focus-visible:outline-2 focus-visible:outline-focus",children:a==="copied"?e.jsx(He,{size:12,className:"text-success"}):e.jsx(Vs,{size:12})})]})}const rg="https://github.com/seira-bot/seira/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings";function lg(){const[s,n]=o.useState(null),[a,i]=o.useState(""),[r,c]=o.useState("loading"),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(!1);o.useEffect(()=>{const h=new AbortController;return D("/api/settings/custom-domain",{signal:h.signal}).then(j=>{h.signal.aborted||(n(j),i(j.customDomain??""))}).catch(j=>{h.signal.aborted||d(j instanceof Error?j.message:t("settings.domain.failed"))}).finally(()=>{h.signal.aborted||c(null)}),()=>h.abort()},[]);const g=async h=>{c(h?"removing":"saving"),d(null),p(null);try{const j=await D("/api/settings/custom-domain",{method:h?"DELETE":"POST",...h?{}:{body:JSON.stringify({domain:a.trim()})}});n(j),i(j.customDomain??""),p(h?t("settings.domain.removed"):t("settings.domain.saved"))}catch(j){d(j instanceof Error?j.message:t("settings.domain.failed"))}finally{c(null)}},f=!!s?.customDomain;return e.jsx(Y,{label:t("settings.domain.title"),block:"address",children:e.jsxs(J,{children:[r==="loading"&&e.jsx(rn,{}),s&&!s.supported&&e.jsx(Se,{children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.domain.label"),subtitle:f&&s.publicUrl?e.jsx("span",{className:"break-all",children:s.publicUrl}):e.jsxs(e.Fragment,{children:[t("settings.domain.rowLine")," ",e.jsx(ze,{href:rg})]}),message:!x&&u?e.jsx("span",{role:"status",children:u}):void 0,children:e.jsx("button",{type:"button",className:"ui-button","aria-expanded":x,"data-custom-domain-open":"",onClick:()=>m(!x),children:t(x?"common.close":f?"settings.domain.change":"settings.domain.verify")})}),x&&e.jsxs("form",{"data-custom-domain-settings":"",onSubmit:h=>{h.preventDefault(),a.trim()&&!r&&g(!1)},className:"flex flex-col gap-2 px-4 pb-4 pt-3",children:[e.jsx(fe,{label:t("settings.domain.title"),hint:l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):u?e.jsx("span",{role:"status",children:u}):t("settings.domain.httpsFirst"),children:e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:r!==null,onChange:h=>{i(h.target.value),p(null),d(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:he})}),e.jsx(ag,{domain:a,serverIpv4:s.serverIpv4}),e.jsxs("div",{className:"flex items-center justify-end gap-2","data-settings-form-foot":"",children:[s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{g(!0)},"data-danger":"",className:"settings-quiet mr-auto -ms-1.5 cursor-pointer",children:r==="removing"?t("settings.domain.removing"):t("settings.domain.remove")}),e.jsx("button",{type:"submit",disabled:!a.trim()||r!==null,className:"ui-button ui-button-md ui-button-primary rounded-full",children:r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")})]})]}),x&&s.customDomain&&e.jsx(Se,{children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")})]}),!s?.supported&&l&&e.jsx(Se,{children:e.jsx("span",{role:"alert",className:"text-danger",children:l})})]})})}const og="https://dash.cloudflare.com/profile/api-tokens",cg=/^[0-9a-f]{32}$/i;function dg({failureText:s}){const{state:n,dispatch:a}=_(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[l,d]=o.useState(null),[u,p]=o.useState(""),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(null),[b,y]=o.useState(null),v=(l??c).trim(),w=u.trim(),N=!w&&r&&l===null,C=l!==null&&v!==c,T=S=>a({type:"configStatus",config:S}),F=async()=>{if(!(x||!w&&!r&&!C)){if(w&&!cg.test(v))return j(t("decider.workersAi.needsAccount"));m(!0),j(null),y(null);try{(C||w&&!c)&&T(await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:v}})})),(w||N)&&T(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",w):await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:w}})})),p(""),d(null)}catch(S){j(S instanceof Error?S.message:String(S))}finally{m(!1)}}},k=async()=>{if(!(g||x||!w&&!r)){f(!0),y(null),j(null);try{const S=await D("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...w?{key:w,accountId:v}:{}})}),P=S.extraction?[t(S.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];y(S.ok?{ok:S.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(S.latencyMs)}),...P].join(" ")}:{ok:!1,text:s(S)})}catch(S){y({ok:!1,text:S instanceof Error?S.message:String(S)})}finally{f(!1)}}};return e.jsx(Y,{label:t("decider.workersAi.title"),description:t("decider.workersAi.detail"),block:"workers-ai",children:e.jsxs(J,{children:[e.jsxs("div",{className:"flex flex-col gap-3 px-4 pb-1 pt-3",children:[e.jsx(fe,{label:t("decider.workersAi.accountId"),children:e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:l??c,onChange:S=>{y(null),j(null),d(S.target.value)},disabled:x,placeholder:t("decider.workersAi.accountIdPlaceholder"),autoComplete:"off",spellCheck:!1,className:he})}),e.jsx(fe,{label:t("decider.workersAi.token"),children:e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:u,onChange:S=>{y(null),j(null),p(S.target.value)},onKeyDown:S=>S.key==="Enter"&&void F(),disabled:x,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),autoComplete:"off",spellCheck:!1,className:he})}),e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:e.jsx("a",{href:og,target:"_blank",rel:"noopener noreferrer",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",children:t("decider.workersAi.getKey")})})]}),e.jsxs(es,{status:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[r?e.jsx(Ye,{tone:"success"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),t(r?"decider.status.connected":"decider.status.notSetUpShort")]}),h&&e.jsx("span",{role:"alert",className:"text-danger",children:h}),b&&e.jsx("span",{role:"status",className:b.ok?"text-ink-secondary":"text-danger",children:b.text})]}),children:[e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{k()},disabled:g||x||!w&&!r,className:"ui-button ui-button-md cursor-pointer rounded-full",children:g?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{F()},disabled:x||!w&&!r&&!C,title:N?t("keys.removeKey"):t("common.save"),className:z("ui-button ui-button-md cursor-pointer rounded-full",N&&"!text-danger"),children:x?t("settings.threads.saving"):N?t("keys.clear"):t("common.save")})]})]})})}const ii=s=>s==="decisions"||s==="chat"?s:"systemone",ug={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},ri={jev:{credential:"jevApiKey",field:"key"},openrouter:{credential:"openrouterDeciderKey",field:"openrouterKey"},custom:{credential:"customDeciderKey",field:"customKey"}},pt={jev:{master:"decider.master",needsKey:"decider.masterNeedsKey",keyLabel:"decider.key.label",placeholder:"decider.key.placeholder"},openrouter:{master:"decider.openrouter.master",needsKey:"decider.masterNeedsKey.openrouter",keyLabel:"decider.openrouter.key.label",placeholder:"decider.openrouter.key.placeholder"},custom:{master:"decider.custom.master",needsKey:"decider.custom.masterNeedsKey",keyLabel:"decider.custom.key.label",placeholder:"decider.custom.key.placeholder"}},pg=1500,mg={recommended:"decider.model.recommended",more:"decider.model.more",chat:"decider.model.geminiChat"},is={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},li={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},xg={...is,rejected:"decider.openrouter.error.rejected",unreachable:"decider.openrouter.error.unreachable",timeout:"decider.openrouter.error.timeout",rate_limited:"decider.openrouter.error.rateLimited",overloaded:"decider.openrouter.error.overloaded",malformed:"decider.openrouter.error.malformed"},gg={...is,rejected:"decider.custom.error.rejected",unreachable:"decider.custom.error.unreachable",timeout:"decider.custom.error.timeout",rate_limited:"decider.custom.error.rateLimited",overloaded:"decider.custom.error.overloaded",malformed:"decider.custom.error.malformed",misconfigured:"decider.custom.error.misconfigured"},hg={...is,rejected:"decider.workersAi.error.rejected",unreachable:"decider.workersAi.error.unreachable",timeout:"decider.workersAi.error.timeout",rate_limited:"decider.workersAi.error.rateLimited",overloaded:"decider.workersAi.error.overloaded",malformed:"decider.workersAi.error.malformed"},js={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter",custom:"decider.status.byCustom",gemini:"decider.status.byGemini"};function fg(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(js[n.provider]??js.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(js[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function oi(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=hg[s.reason];return r?t(r):t("decider.error.other")}if(a==="custom"){if(s.reason==="http_error")return t("decider.custom.error.http",{status:String(s.status??"?")});const r=gg[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=xg[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&&li[s.reason])return t(li[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=is[s.reason];return i?t(i):t("decider.error.other")}const ci=s=>s==="openrouter"||s==="custom"?s:"jev";function di({saved:s,onSave:n,disabled:a,label:i,placeholder:r,testId:c}){const[l,d]=o.useState(s);o.useEffect(()=>d(s),[s]);const u=()=>{l.trim()!==s&&n(l.trim())};return e.jsx("input",{type:"text","data-testid":c,value:l,onChange:p=>d(p.target.value),onBlur:u,onKeyDown:p=>p.key==="Enter"&&u(),disabled:a,placeholder:r,"aria-label":i,autoComplete:"off",spellCheck:!1,className:z(he,"[width:var(--settings-select-width,200px)] max-w-full")})}function bg(){const{state:s,dispatch:n}=_(),a=s.config?.decider,i=ci(a?.chosen??a?.provider),r=i==="openrouter",c=i==="custom",l=a?.configured??!1,d=l&&a?.included===!0,u=l&&a?.keySource==="shared",p=r&&u,x=r&&a?.sharedKey===!0,m=l&&a?.provider==="gemini",g=l&&!d&&!u&&!m,f=a?.enabled??!1,h=a?.jobs.roomRouting??!0,[j,b]=o.useState(""),[y,v]=o.useState(!1),[w,N]=o.useState(!1),[C,T]=o.useState(!1),[F,k]=o.useState(null),[S,P]=o.useState(null),[E,A]=o.useState(null),[V,R]=o.useState(!1),K=j.trim(),te=!K&&g,ue=!r||d?null:u?"decider.openrouter.status.sharedHint":l?x?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",ae=$=>n({type:"configStatus",config:$}),X=async $=>{if(!w){N(!0),k(null);try{ae(await D("/api/config",{method:"PUT",body:JSON.stringify({decider:$})}))}catch(Z){k(Z instanceof Error?Z.message:String(Z))}finally{N(!1)}}};o.useEffect(()=>{if(!r||E)return;let $=!1;return D("/api/decider/models").then(Z=>{$||A(Z)},()=>{}),()=>{$=!0}},[r,E]);const B=$=>{b(""),P(null),X($)},W=async()=>{if(!(y||!K&&!g)){v(!0),k(null),P(null);try{const $=window.ogb?.setCredential?await window.ogb.setCredential(ri[i].credential,K):await D("/api/config",{method:"PUT",body:JSON.stringify({decider:{[ri[i].field]:K}})});ae($),b("")}catch($){k($ instanceof Error?$.message:String($))}finally{v(!1)}}},G=async()=>{if(C||y||!K&&!l)return;T(!0),P(null),k(null);const $=!K&&d,Z=!K&&u,ee=!K&&m;try{const O=await D("/api/decider/test",{method:"POST",body:JSON.stringify(K?{key:K}:{})});P(O.ok?{ok:!0,text:r||c||Z||ee?[t(ee?"decider.gemini.test.ok":c?"decider.custom.test.ok":Z?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(O.latencyMs)}),...O.latencyMs>pg?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(O.latencyMs)})}:{ok:!1,text:ee?t(O.reason==="rejected"?"decider.gemini.error.rejected":"decider.error.other"):oi(O,$,Z?"openrouter":i)})}catch(O){P({ok:!1,text:O instanceof Error?O.message:String(O)})}finally{T(!1)}},oe=t(pt[i].keyLabel),M=d?t("keys.includedWithCloudPro"):u?t("decider.openrouter.status.shared"):l?t(x?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected");return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{label:t("settings.ai.routing"),block:"routing",description:e.jsxs(e.Fragment,{children:[t("decider.introShort")," ",e.jsx(ze,{onClick:()=>R(!V)})]}),children:[V&&e.jsx("p",{"data-decider-more":"",className:"px-4 text-[12px] leading-4 text-ink-secondary",children:t("decider.intro")}),e.jsx(J,{children:e.jsx(L,{title:t(pt[i].master),subtitle:e.jsx("span",{role:"status","data-testid":"helpers-status",children:fg(s.config)}),message:l?void 0:t(pt[i].needsKey),children:e.jsx(ie,{"data-testid":"decider-master","aria-label":t(pt[i].master),checked:f,disabled:!l||w||!s.config,onClick:()=>{X({enabled:!f})},className:"cursor-pointer"})})})]}),e.jsx(dg,{failureText:$=>oi($,!1,"workersai")}),e.jsx(Y,{label:t("decider.provider.label"),block:"routing-key",children:e.jsxs(J,{selectWidth:200,children:[e.jsx(L,{title:t("decider.provider.title"),children:e.jsxs(de,{"data-testid":"decider-provider",value:i,onChange:$=>B({provider:ci($.target.value)}),disabled:w||!s.config,"aria-label":t("decider.provider.label"),children:[e.jsx("option",{value:"jev",children:t("decider.provider.jev")}),e.jsx("option",{value:"openrouter",children:t("decider.provider.openrouter")}),e.jsx("option",{value:"custom",children:t("decider.provider.custom")})]})}),c&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("decider.custom.baseUrl"),subtitle:t("decider.custom.baseUrlDetail"),children:e.jsx(di,{testId:"decider-custom-base-url",saved:a?.baseUrl??"",disabled:w,label:t("decider.custom.baseUrl"),placeholder:t("decider.custom.baseUrlPlaceholder"),onSave:$=>{X({customBaseUrl:$})}})}),e.jsx(L,{title:t("decider.custom.model"),children:e.jsx(di,{testId:"decider-custom-model",saved:a?.model??"",disabled:w,label:t("decider.custom.model"),placeholder:t("decider.custom.modelPlaceholder"),onSave:$=>{X({customModel:$})}})}),e.jsx(L,{title:t("decider.custom.api"),children:e.jsxs(de,{"data-testid":"decider-custom-api",value:ii(a?.api),onChange:$=>B({customApi:ii($.target.value)}),disabled:w,"aria-label":t("decider.custom.api"),children:[e.jsx("option",{value:"systemone",children:t("decider.custom.api.systemone")}),e.jsx("option",{value:"decisions",children:t("decider.custom.api.decisions")}),e.jsx("option",{value:"chat",children:t("decider.custom.api.chat")})]})})]}),r&&e.jsx(L,{title:t("decider.model.label"),subtitle:E?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(de,{"data-testid":"decider-model",value:a?.model??"",onChange:$=>B({openrouterModel:$.target.value,openrouterApi:E?.models.find(Z=>Z.id===$.target.value)?.api??"chat"}),disabled:w,"aria-label":t("decider.model.label"),children:[a?.model&&!E?.models.some($=>$.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more","chat"].map($=>{const Z=E?.models.filter(ee=>ee.group===$)??[];return Z.length>0&&e.jsx("optgroup",{label:t(mg[$]),children:Z.map(ee=>e.jsx("option",{value:ee.id,children:ee.name},ee.id))},$)})]})}),e.jsxs("div",{"data-decider-key":"",className:"flex flex-col gap-2 px-4 pb-1 pt-3",children:[e.jsx(fe,{label:oe,children:e.jsx("input",{type:"password",value:j,onChange:$=>{P(null),k(null),b($.target.value)},onKeyDown:$=>$.key==="Enter"&&void W(),disabled:y,placeholder:g?t("keys.replace"):t(p?"decider.openrouter.key.overridePlaceholder":pt[i].placeholder),"aria-label":oe,autoComplete:"off",spellCheck:!1,className:he})}),e.jsxs("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:[ue&&e.jsxs(e.Fragment,{children:[t(ue)," "]}),ue&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(Rs("openrouter")),className:"cursor-pointer text-accent-text hover:underline",children:t("decider.openrouter.key.manageLink")})," "]}),!p&&i!=="custom"&&e.jsx("a",{href:ug[i],target:"_blank",rel:"noopener noreferrer",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",children:t(r?"decider.openrouter.key.getKey":"decider.key.getKey")})]})]}),e.jsxs(es,{status:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[e.jsx(Ye,{tone:l?"success":null}),!l&&e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),M]}),F&&e.jsx("span",{role:"alert",className:"text-danger",children:F}),S&&e.jsx("span",{role:"status",className:S.ok?"text-ink-secondary":"text-danger",children:S.text})]}),children:[e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{G()},disabled:C||y||!K&&!l,className:"ui-button ui-button-md cursor-pointer rounded-full",children:C?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{W()},disabled:y||!K&&!g,title:te?t("keys.removeKey"):t("common.save"),className:z("ui-button ui-button-md cursor-pointer rounded-full",te&&"!text-danger"),children:y?t("settings.threads.saving"):te?t("keys.clear"):t("common.save")})]})]})}),e.jsx(Y,{label:t("decider.jobs.title"),block:"routing-jobs",children:e.jsx(J,{children:e.jsx(L,{title:t("decider.jobs.roomRouting"),subtitle:t("decider.jobs.roomRoutingDetail"),children:e.jsx(ie,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:f&&h,disabled:!f||w,onClick:()=>{X({jobs:{roomRouting:!h}})},className:"cursor-pointer"})})})})]})}function vg(){const s=!!_().state.config?.team,[n,a]=o.useState(null),[i,r]=o.useState(""),[c,l]=o.useState(!1),d=o.useId();if(o.useEffect(()=>{if(s)return;let p=!0;return D("/api/me",{timeoutMs:1e4}).then(x=>{!p||typeof x?.displayName!="string"||(a(x),r(x.displayName))},()=>{}),()=>{p=!1}},[s]),s||!n)return null;const u=()=>{i.trim()!==n.displayName&&(l(!1),D("/api/me",{method:"PUT",body:JSON.stringify({displayName:i}),timeoutMs:1e4}).then(p=>{a(p),r(p.displayName)},()=>l(!0)))};return e.jsxs("div",{className:"flex flex-col gap-1 px-4 py-[13px]",children:[e.jsx("label",{id:d,htmlFor:`${d}-input`,className:"text-[14px] text-ink",children:t("settings.profile.displayName")}),e.jsx("input",{id:`${d}-input`,"aria-labelledby":d,value:i,maxLength:60,placeholder:n.shownAs,onChange:p=>r(p.target.value),onBlur:u,className:he}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.displayNameHelp")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.displayNameError")})]})}const yg=["openai","xai","gemini","openrouter","custom"],jg=4,kg=["low","medium","high"];function wg(s){return s.provider==="openai"&&s.model.startsWith("gpt-image-2.6-")}const Gr={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},Ng={openai:[{id:"gpt-image-2.6-sunburst",name:"GPT Image 2.6 Sunburst"},{id:"gpt-image-2.6-flare",name:"GPT Image 2.6 Flare"},{id:"gpt-image-2",name:"GPT Image 2"},{id:"gpt-image-1",name:"GPT Image 1"},{id:"gpt-image-1-mini",name:"GPT Image 1 Mini"}],xai:[{id:"grok-imagine-image-2.0",name:"Grok Imagine Image 2.0"}],gemini:[{id:"gemini-2.5-flash-image",name:"Nano Banana (Gemini 2.5 Flash Image)"}],openrouter:[{id:"google/gemini-2.5-flash-image",name:"Google: Nano Banana (Gemini 2.5 Flash Image)"},{id:"google/gemini-3.1-flash-image",name:"Google: Nano Banana 2 (Gemini 3.1 Flash Image)"},{id:"google/gemini-3-pro-image",name:"Google: Nano Banana Pro (Gemini 3 Pro Image)"},{id:"openai/gpt-image-2",name:"OpenAI: GPT Image 2"},{id:"black-forest-labs/flux-3-image",name:"Black Forest Labs: FLUX 3 Image"},{id:"bytedance-seed/seedream-5-0-pro",name:"ByteDance Seed: Seedream 5.0 Pro"},{id:"x-ai/grok-imagine-image-2.0",name:"xAI: Grok Imagine Image 2.0"},{id:"qwen/qwen-image-3",name:"Qwen: Qwen Image 3"}],custom:[]};function Sg(s){const n="Use an HTTPS API base URL, or HTTP for a local router, without passwords, query parameters or fragments";let a;try{a=new URL(s.trim())}catch{throw new Error(n)}if(s.length>2048||a.username||a.password||a.search||a.hash)throw new Error(n);const i=a.hostname.toLowerCase(),r=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(i),c=i==="localhost"||i.endsWith(".localhost")||i.endsWith(".local")||i==="host.docker.internal"||i==="host.containers.internal"||i==="[::1]"||/^\[f[cd][0-9a-f]{2}:/.test(i)||r&&(Number(r[1])===127||Number(r[1])===10||Number(r[1])===192&&Number(r[2])===168||Number(r[1])===172&&Number(r[2])>=16&&Number(r[2])<=31);if(a.protocol!=="https:"&&!(a.protocol==="http:"&&c))throw new Error(n);if(r&&(Number(r[1])===0||Number(r[1])===169&&Number(r[2])===254))throw new Error(n);return a.pathname=a.pathname.replace(/\/+$/,"").replace(/\/images\/generations$/,""),a.toString().replace(/\/+$/,"")}const jt={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},Cg={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"}},Eg={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},ui={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},ks="\0other";function Ag(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 Pg(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 Tg(){const{state:s,dispatch:n}=_(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??Gr.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,l]=o.useState(!1),[d,u]=o.useState(null),[p,x]=o.useState(null),[m,g]=o.useState(!1),f=i.provider==="openrouter"||r?.provider==="openrouter";o.useEffect(()=>{if(!f||p)return;let v=!1;return D("/api/images/openrouter-models").then(w=>{v||x(Array.isArray(w?.models)?w:{source:"builtin",models:[]})},()=>{v||x({source:"builtin",models:[]})}),()=>{v=!0}},[f,p]);const h=async v=>{l(!0),u(null);try{const w=await D("/api/config",{method:"PUT",body:JSON.stringify(v)});n({type:"configStatus",config:w})}catch(w){u(w instanceof Error?w.message:String(w))}finally{l(!1)}},j=(v,w)=>{if(v==="fallback"&&w==="")return void h({imageGen:{fallback:null}});const N=w,C=v==="primary"&&r?.provider===N;h({imageGen:{[v]:{provider:N},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((v,w,N)=>N.indexOf(v)===w),y=a?.ready?i.configured?t("imageGen.status.ready",{provider:jt[i.provider]}):t("imageGen.status.backupOnly",{provider:jt[r.provider]}):t("imageGen.status.notReady");return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{label:t("settings.ai.images"),block:"images",description:e.jsxs(e.Fragment,{children:[t("imageGen.introShort")," ",e.jsx(ze,{onClick:()=>g(v=>!v)})]}),footnote:e.jsxs("span",{role:"status","data-testid":"image-gen-status",className:"inline-flex items-center",children:[a?.ready?e.jsx(Ye,{tone:i.configured?"success":"warning"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),y]}),children:[m&&e.jsx("p",{"data-image-gen-more":"",className:"px-4 text-[12px] leading-4 text-ink-secondary",children:t("imageGen.intro")}),e.jsxs(J,{selectWidth:200,children:[e.jsx(pi,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:p,disabled:c||!s.config,onProvider:j,onModel:v=>{h({imageGen:{primary:{provider:i.provider,model:v}}})}}),e.jsx(pi,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:p,disabled:c||!s.config,onProvider:j,onModel:v=>r&&void h({imageGen:{fallback:{provider:r.provider,model:v}}})}),e.jsx(L,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),message:d?e.jsx("span",{role:"alert",className:"text-danger",children:d}):void 0,children:e.jsx(de,{"data-testid":"image-gen-max",value:String(a?.maxPerTurn??jg),onChange:v=>{h({imageGen:{maxPerTurn:Number(v.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(v,w)=>w+1).map(v=>e.jsx("option",{value:v,children:v},v))})}),[i,r].some(v=>v&&wg(v))&&e.jsx(L,{title:t("imageGen.complexity.label"),subtitle:t("imageGen.complexity.help"),children:e.jsx(de,{"data-testid":"image-gen-complexity",value:a?.complexity??"high",onChange:v=>{h({imageGen:{complexity:v.target.value}})},disabled:c||!s.config,"aria-label":t("imageGen.complexity.label"),children:kg.map(v=>e.jsx("option",{value:v,children:t(`imageGen.complexity.${v}`)},v))})})]})]}),b.map(v=>e.jsx(Lg,{provider:v,status:a},v))]})}function pi({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:l,onProvider:d,onModel:u}){const p=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:p,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(de,{"data-testid":`image-gen-${s}`,value:n??"",onChange:x=>d(s,x.target.value),disabled:l,"aria-label":p,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),yg.filter(x=>x!==r).map(x=>e.jsx("option",{value:x,children:jt[x]},x))]})}),n&&e.jsx(Ig,{slot:s,slotLabel:p,provider:n,model:a,openrouterModels:c,disabled:l,onModel:u})]})}function Ig({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:l}){const[d,u]=o.useState(null),x=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??Ng[a].map(h=>({...h,group:"recommended"})),m=d!==null||x.length===0,g=()=>{d!==null&&(u(null),d.trim()&&d.trim()!==i&&l(d.trim()))},f=h=>{if(h===ks)return u(i);u(null),l(h)};return e.jsx(L,{title:t("decider.model.label"),subtitle:a==="openrouter"&&r?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[x.length>0&&e.jsxs(de,{"data-testid":`image-gen-${s}-model`,value:m?ks:i,onChange:h=>f(h.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[i&&!x.some(h=>h.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(h=>{const j=x.filter(b=>b.group===h);return j.length>0&&e.jsx("optgroup",{label:t(h==="recommended"?"decider.model.recommended":"decider.model.more"),children:j.map(b=>e.jsx("option",{value:b.id,children:b.name},b.id))},h)}),e.jsx("option",{value:ks,children:t("imageGen.model.other")})]}),m&&e.jsx("input",{value:d??i,onChange:h=>u(h.target.value),onBlur:g,onKeyDown:h=>h.key==="Enter"&&g(),disabled:c,placeholder:Gr[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:z(Re,"w-[200px] text-left")})]})})}function Lg({provider:s,status:n}){const{dispatch:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(null),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(!1),[f,h]=o.useState(null),j=s==="openrouter"?[n?.primary,n?.fallback].filter(E=>E?.provider===s).map(E=>E?.model).join(" "):"",b=f?.models===j?f:null,y=E=>h(E&&{...E,models:j}),v=Pg(n,s),w=s==="openai"||s==="gemini"||s==="custom"?Cg[s]:null,N=s==="xai"||s==="openrouter"?Eg[s]:null,C=c??n?.customUrl??"",T=async E=>{u(!0),x(null),y(null);try{a({type:"configStatus",config:await E()}),r(""),l(null)}catch(A){x(A instanceof Error?A.message:String(A))}finally{u(!1)}},F=E=>T(async()=>s==="xai"||s==="openrouter"?gd(s,E,!1):window.ogb?.setCredential&&w?window.ogb.setCredential(w.credential,E):D("/api/config",{method:"PUT",body:JSON.stringify(w.patch(E))})),k=()=>T(async()=>{const E=C.trim()?Sg(C.trim()):"";return D("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:E}})})}),S=async()=>{g(!0),y(null);try{y(Ag(s,await D("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(E){y({ok:!1,text:E instanceof Error?E.message:String(E)})}finally{g(!1)}},P=t(v?"imageGen.key.saved":s==="custom"?"imageGen.key.optional":"imageGen.key.missing");return e.jsx(Y,{label:jt[s],block:`images-${s}`,children:e.jsx(J,{children:e.jsxs("div",{className:"flex flex-col gap-2 px-4 pb-4 pt-3","data-image-key-form":"",children:[s==="custom"&&e.jsx(fe,{label:t("imageGen.custom.url"),children:e.jsx("input",{type:"url",value:C,onChange:E=>l(E.target.value),onKeyDown:E=>E.key==="Enter"&&void k(),onBlur:()=>c!==null&&void k(),disabled:d,placeholder:"http://127.0.0.1:4000/v1",autoComplete:"off",className:he})}),e.jsx(fe,{label:t("imageGen.key.label"),hint:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[v?e.jsx(Ye,{tone:"success"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),P]}),b&&e.jsx("span",{role:"status",className:b.ok?"text-ink-secondary":"text-danger",children:b.text}),p&&e.jsx("span",{role:"alert",className:"text-danger",children:p})]}),children:e.jsx("input",{type:"password",value:i,onChange:E=>r(E.target.value),onKeyDown:E=>E.key==="Enter"&&i.trim()&&void F(i.trim()),disabled:d,placeholder:v?t("keys.replace"):t("keys.row.pasteKey"),"aria-label":t((w??N).label),autoComplete:"off",spellCheck:!1,className:he})}),e.jsxs("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:[N?e.jsxs(e.Fragment,{children:[t(N.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent-text hover:underline",children:t("imageGen.key.manage")})," "]}):s==="custom"?e.jsx(e.Fragment,{children:t("imageGen.custom.help",{app:ke()})}):e.jsxs(e.Fragment,{children:[t("imageGen.key.line",{app:ke(),provider:jt[s]})," "]}),ui[s]&&e.jsx("a",{href:ui[s],target:"_blank",rel:"noreferrer",className:"text-accent-text hover:underline focus-visible:underline",children:t("imageGen.key.get")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2","data-settings-form-foot":"",children:[v&&e.jsx("button",{type:"button",onClick:()=>{F("")},disabled:d,"data-danger":"",className:"settings-quiet mr-auto -ms-1.5 cursor-pointer",children:t("keys.removeKey")}),v&&e.jsx("button",{type:"button",onClick:()=>{S()},disabled:m||d,className:"ui-button ui-button-md cursor-pointer rounded-full",children:m?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button",onClick:()=>{F(i.trim())},disabled:d||!i.trim(),className:"ui-button ui-button-md cursor-pointer rounded-full",children:d?t("settings.threads.saving"):t("common.save")})]})]})})})}const Rg={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function gt(s,n){return[Rg[s],{signal:n}]}function hn(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Bg({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:l,onRefresh:d,onRemove:u}){return e.jsxs(xe,{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(Zi,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsx("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"settings-quiet flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):l?t("vm.vps.unavailable",{reason:l}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!l)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[l&&s.length>0&&e.jsxs("div",{className:"flex items-center gap-2 border-b border-hairline/35 px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx($e,{size:14,className:"shrink-0 text-warning"})," ",l]}),i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ce,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):l&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx($e,{size:14,className:"shrink-0 text-warning"})," ",l]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Bi,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((p,x)=>{const m=Kg(p),g=fn(m),f=r===p.name,h=bn(p.name);return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.vps.orphan",{id:h}):p.ownerName}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",p.inUse||m==="running"?"bg-success/15 text-success":m==="stopped"||m==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:g}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:p.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:i||p.inUse||r!==null,"aria-busy":f||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f?e.jsx(ce,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("vm.vps.remove")]})]},`${p.vpsAlias??""}:${p.name}`)})]})]})}const Og=[1e3,2e3,4e3];function Fg(s){return new Promise(n=>window.setTimeout(n,s))}const Ug={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Mg={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 fn(s){return t(Mg[s])}function Dg(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function zg(s){return fn(Dg(s))}function _g(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 qr(s,n,a){const i={...a},r=new Set(s.map(l=>l.boxId)),c=s.flatMap(l=>{const d=a[l.boxId];return d==="deleted"?[]:d==="deleting"?[{...l,state:"removing"}]:d!=="sleeping"?[l]:l.state==="archived"?(delete i[l.boxId],[l]):[{...l,state:"archived"}]});for(const l of n)a[l.boxId]!=="sleeping"||r.has(l.boxId)||c.push({...l,state:"archived"});for(const[l,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(l)&&delete i[l];return{instances:c,overrides:i}}function Hg(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:qr(Array.isArray(s.instances)?s.instances:[],n,a)}function $g(s){return["idle","ready","running"].includes(s.state)}function Kg(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 bn(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function Wg(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:hn(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Gg(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:hn(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function qg(s){const n=bn(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:hn(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function ws(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function Vg({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:l,onSleep:d,onDelete:u}){return e.jsxs(xe,{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(Zi,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsx("button",{type:"button",onClick:l,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"settings-quiet -me-1.5 flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):c?t("vm.cloud.unavailable",{reason:c}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),!(n===!1&&!a&&!c)&&e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsx("div",{role:"status","aria-label":t("vm.cloud.checkingList"),className:"flex flex-col",children:e.jsx(rn,{})}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx($e,{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(Ii,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((p,x)=>{const m=_g(p),g=fn(m),f=i?.boxId===p.boxId,h=$g(p),j=m==="removing";return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.cloud.orphan"):p.ownerName}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",p.inUse||m==="running"?"bg-success/15 text-success":m==="sleeping"||m==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:g})]}),e.jsxs("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:[p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",p.name]}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!h,"aria-busy":f&&i?.action==="sleep"?!0:void 0,title:h?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:g.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="sleep"?e.jsx(ce,{size:12,className:"animate-spin"}):e.jsx(io,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:a||p.inUse||i!==null||j,"aria-busy":f&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="delete"?e.jsx(ce,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("common.delete")]})]})]},p.boxId)})})]})}function Jg({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:l,onDelete:d}){return e.jsxs(xe,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsx("button",{type:"button",onClick:l,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"settings-quiet flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):c?t("vm.perBot.unavailable",{reason:c}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsx("div",{role:"status","aria-label":t("vm.perBot.checkingList"),className:"flex flex-col",children:e.jsx(rn,{})}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx($e,{size:14,className:"shrink-0 text-warning"})," ",c]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((u,p)=>{const x=zg(u),m=i===u.botId,g=u.managed===!0;return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",p>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",g?u.inUse||u.ready?"bg-success/15 text-success":u.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:x})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Ug[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:er(u.problem)}),g&&u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),g&&e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null,"aria-busy":m||void 0,title:u.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:u.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[m?e.jsx(ce,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("common.delete")]})]},u.botId)})})]})}function Ot({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3","data-vm-step":s,children:[e.jsx("span",{className:"flex size-8 shrink-0 items-start justify-center pt-0.5",children:e.jsx("span",{"aria-hidden":"true",className:"flex size-5 items-center justify-center rounded-full bg-ink/[0.06] text-[12px] font-medium leading-4 text-ink-secondary",children:a?e.jsx(He,{size:12}):s})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:z("text-[14px] leading-5",a?"text-ink-secondary":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function st({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,"data-danger":r?"":void 0,className:z(r?"settings-quiet flex cursor-pointer items-center gap-1.5":"ui-button ui-button-md cursor-pointer rounded-full","disabled:opacity-50"),children:[n===s&&e.jsx(ce,{size:13,className:"animate-spin"}),a]})}const Vr=5,Jr=1440,Yg=480;function Xg(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Vr&&a<=Jr?a:null}function Qg({minutes:s,disabled:n,onSave:a}){const[i,r]=o.useState(String(s)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1);o.useEffect(()=>{c||r(String(s))},[s,c]);const m=async()=>{if(!c||p)return;const g=Xg(i);if(g===null){u(t("vm.idle.range"));return}x(!0);try{await a(g),r(String(g)),l(!1),u("")}catch(f){u(f instanceof Error?f.message:t("vm.idle.error"))}finally{x(!1)}};return e.jsxs("div",{className:"mt-3 flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[14px] leading-5 text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[13px] leading-[18px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Vr,max:Jr,step:1,inputMode:"numeric",value:i,disabled:n||p,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:g=>{r(g.target.value),l(!0),u("")},onBlur:()=>{m()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:z(Re,"w-16 bg-transparent",d&&"border-danger/60")}),e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"text-[12px] leading-4 text-danger",children:d}):null]})}function mi({label:s,command:n}){const[a,i]=o.useState(!1);return e.jsxs("div",{className:"flex w-full flex-col gap-2",children:[e.jsx("button",{type:"button","aria-expanded":a,className:"settings-quiet -ml-1.5 cursor-pointer self-start",onClick:()=>i(r=>!r),children:s}),a&&e.jsx(Bs,{command:n})]})}function Zg({perBot:s,path:n}){const[a,i]=o.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1 text-[13px] leading-[18px] text-ink-secondary",children:[e.jsxs("p",{children:[t(s?"vm.safety.perBotShort":"vm.safety.sharedShort",{path:n})," ",e.jsx(ze,{onClick:()=>i(r=>!r)})]}),a&&e.jsx("p",{className:"text-[12px] leading-4",children:t(s?"vm.safety.perBot":"vm.safety.shared",{path:n})})]})}function Yr({privateOnly:s=!1}){const n=_().state.config?.cloudHome===!0,[a,i]=o.useState(null),[r,c]=o.useState(!0),[l,d]=o.useState(null),u=o.useRef(null);o.useEffect(()=>()=>u.current?.abort(),[]);const[p,x]=o.useState(null),[m,g]=o.useState(!1),[f,h]=o.useState(0),[j,b]=o.useState([]),[y,v]=o.useState(2),[w,N]=o.useState(!1),[C,T]=o.useState(null),[F,k]=o.useState(null),[S,P]=o.useState(null),[E,A]=o.useState(0),[V,R]=o.useState([]),[K,te]=o.useState(null),[ue,ae]=o.useState(!0),[X,B]=o.useState(null),[W,G]=o.useState(null),[oe,M]=o.useState(null),[$,Z]=o.useState(0),ee=o.useRef([]),O=o.useRef({}),[re,ne]=o.useState([]),[me,q]=o.useState(null),[ge,be]=o.useState([]),[we,Be]=o.useState(!0),[Xe,pe]=o.useState(null),[Pe,Te]=o.useState(null),[Fe,Ie]=o.useState(null),[rs,ls]=o.useState(0),[I,le]=o.useState(""),ye=o.useCallback(async U=>{const H=await fetch(...gt("status",U)),Q=await H.json().catch(()=>({}));if(!U?.aborted){if(!H.ok)throw new Error(Q.error??t("vm.err.status",{code:H.status}));return i(Q),x(null),Q}},[]),Ge=o.useCallback(async U=>{const H=await fetch(...gt("local-vms",U)),Q=await H.json().catch(()=>({}));if(!H.ok)throw new Error(Q.error??t("vm.err.inventory",{code:H.status}));const se=Q;b(se.instances),v(se.maxInstances),k(se.available?null:er(se.problem)??t("vm.err.runtimeUnavailable")),T(null)},[]),dt=o.useCallback(async U=>{const H=await fetch(...gt("cloud",U)),Q=await H.json().catch(()=>({}));if(!H.ok)throw new Error(Q.error??t("vm.err.cloudInventory",{code:H.status}));const se=Q,ve=Hg(se,ee.current,O.current);O.current=ve.overrides,ee.current=ve.instances,R(ve.instances),te(se.configured===!0),G(se.available||!se.configured?null:se.problem??t("vm.err.cloudUnavailable")),B(null)},[]),os=o.useCallback(async U=>{const H=await fetch(...gt("vps",U)),Q=await H.json().catch(()=>({}));if(!H.ok)throw new Error(Q.error??t("vm.err.vpsInventory",{code:H.status}));const se=Q;ne(Array.isArray(se.instances)?se.instances:[]),q(se.configured===!0),be(Array.isArray(se.vpsAliases)?se.vpsAliases:[]),Te(se.available||!se.configured?null:se.problem??t("vm.err.vpsUnavailable")),pe(null)},[]);o.useEffect(()=>{if(n)return;let U=!0,H,Q;const se=async()=>{Q=new AbortController;try{await ye(Q.signal)}catch(ve){U&&!(ve instanceof DOMException&&ve.name==="AbortError")&&(i(null),x(ve instanceof Error?ve.message:String(ve)))}finally{U&&(c(!1),H=window.setTimeout(()=>{se()},5e3))}};return se(),()=>{U=!1,Q?.abort(),H!==void 0&&window.clearTimeout(H)}},[n,ye,f]),o.useEffect(()=>{if(a?.mode!=="per-bot"){b([]),N(!1),T(null),k(null);return}const U=new AbortController;return N(!0),Ge(U.signal).catch(H=>{H instanceof DOMException&&H.name==="AbortError"||T(H instanceof Error?H.message:String(H))}).finally(()=>{U.signal.aborted||N(!1)}),()=>U.abort()},[E,Ge,a?.mode]),o.useEffect(()=>{if(s)return;const U=new AbortController;return ae(!0),dt(U.signal).catch(H=>{H instanceof DOMException&&H.name==="AbortError"||G(H instanceof Error?H.message:String(H))}).finally(()=>{U.signal.aborted||ae(!1)}),()=>U.abort()},[$,s,dt]),o.useEffect(()=>{if(s)return;const U=new AbortController;return Be(!0),os(U.signal).catch(H=>{H instanceof DOMException&&H.name==="AbortError"||Te(H instanceof Error?H.message:String(H))}).finally(()=>{U.signal.aborted||Be(!1)}),()=>U.abort()},[s,os,rs]);const cs=async(U,H)=>{const Q=await fetch(`/api/local-computer/${U}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:H}),se=await Q.json().catch(()=>({})),ve={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!Q.ok)throw new Error(se.error??t(ve[U]));return H.throwIfAborted(),i(se),se},vn=U=>window.ogb?.confirm?window.ogb.confirm(U):window.confirm(U),Qe=async U=>{if(l!==null||u.current)return;const H=new AbortController;u.current=H,d(U),x(null);try{if(U==="remove"&&!await vn(t("vm.confirm.deleteShared"))||U==="recreate"&&!await vn(t("vm.confirm.recreate")))return;let Q;if(U==="recreate"?(await cs("remove",H.signal),Q=await cs("run",H.signal)):Q=await cs(U,H.signal),(U==="run"||U==="start"||U==="recreate")&&(Q=await Nu(Q,async()=>await ye(H.signal)??Q,H.signal),!Q.ready))throw new Error(Q.problem??t("vm.err.start"));await ye(),le(U==="remove"?t("vm.announce.deleted"):U==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(Q){if(H.signal.aborted)return;x(Q instanceof Error?Q.message:String(Q))}finally{u.current=null,H.signal.aborted||d(null)}},yn=async(U,H)=>{g(!0),x(null);try{const Q=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:U,maxInstances:H}})}),se=await Q.json().catch(()=>({}));if(!Q.ok)throw new Error(se.error??t("vm.policyError"));i(ve=>ve&&{...ve,mode:U,max_instances:H}),await ye()}catch(Q){x(Q instanceof Error?Q.message:String(Q))}finally{g(!1)}},il=async U=>{const H=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:U}})}),Q=await H.json().catch(()=>({}));if(!H.ok)throw new Error(Q.error??t("vm.idle.error"));i(se=>se&&{...se,idle_timeout_ms:U*6e4})},rl=async U=>{if(!U.managed){T(t("vm.unmanagedError"));return}const H=ws(Wg(U),Q=>window.confirm(Q));if(H){P(U.botId),T(null);try{const Q=await fetch(...H),se=await Q.json().catch(()=>({}));if(!Q.ok)throw new Error(se.error??t("vm.deleteError"));await Ge(),le(t("vm.announce.deletedBot",{name:U.name}))}catch(Q){T(Q instanceof Error?Q.message:String(Q))}finally{P(null)}}},jn=async(U,H)=>{const Q=ws(Gg(U,H),se=>window.confirm(se));if(Q){M({boxId:H.boxId,action:U}),B(null),le("");try{const se=await fetch(...Q),ve=await se.json().catch(()=>({}));if(!se.ok)throw new Error(ve.error??t(U==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const us=U==="delete"&&ve?.pending===!0;O.current={...O.current,[H.boxId]:U==="delete"?us?"deleting":"deleted":"sleeping"};const ps=qr(ee.current,ee.current,O.current);O.current=ps.overrides,ee.current=ps.instances,R(ps.instances);const Ze=H.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:H.ownerName??""});if(le(us?`${Ze}: ${t("vm.state.removing")}.`:t(U==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ze})),us){for(const Le of Og){await Fg(Le);try{await dt()}catch{}if(O.current[H.boxId]!=="deleting"){le(t("vm.announce.cloudDeleted",{subject:Ze}));return}}const et={...O.current};delete et[H.boxId],O.current=et;const It=ee.current.map(Le=>Le.boxId===H.boxId?{...Le,state:H.state}:Le);ee.current=It,R(It);try{await dt(),ee.current.some(Le=>Le.boxId===H.boxId)||le(t("vm.announce.cloudDeleted",{subject:Ze}))}catch(Le){const ol=Le instanceof Error?Le.message:String(Le);B(`${Ze}: ${t("vm.state.removing")}. ${ol}`)}return}try{await dt()}catch(et){const It=et instanceof Error?et.message:String(et);B(t(U==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ze,detail:It}))}}catch(se){B(se instanceof Error?se.message:String(se))}finally{M(null)}}},ll=async U=>{const H=bn(U.name),Q=ws(qg(U),se=>window.confirm(se));if(Q){Ie(U.name),pe(null);try{const se=await fetch(...Q),ve=await se.json().catch(()=>({}));if(!se.ok)throw new Error(ve.error??t("vm.vpsRemoveError"));await os(),le(t("vm.announce.vpsRemoved",{subject:U.orphaned?t("vm.announce.orphanVps",{id:H}):t("vm.confirm.ownedVps",{name:U.ownerName??""})}))}catch(se){pe(se instanceof Error?se.message:String(se))}finally{Ie(null)}}},Ue=a?.commands,Tt=a?.ready===!0,kn=a?.container!=="missing",wn=!!(kn&&(!a?.imageMatches||!a?.managed||a?.network==="unsafe"||a?.security==="unsafe"||a?.persistence==="unsafe")),Nn=!r&&!a,Sn=a?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ce=a?.mode==="per-bot",ds=Ce&&a?.runtime==="container",Cn=Ce?!!(a?.daemonUp&&a?.image&&!ds):Tt;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:I}),!s&&e.jsxs(e.Fragment,{children:[e.jsx(Vg,{instances:V,configured:K,loading:ue,pending:oe,error:X,unavailableReason:W,onRefresh:()=>Z(U=>U+1),onSleep:U=>{jn("sleep",U)},onDelete:U=>{jn("delete",U)}}),e.jsx(Bg,{instances:re,configured:me,aliases:ge,loading:we,removingName:Fe,error:Xe,unavailableReason:Pe,onRefresh:()=>ls(U=>U+1),onRemove:U=>{ll(U)}}),e.jsx(wu,{})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsxs(xe,{title:t("vm.main.title"),subtitle:Ce?t("vm.main.perBotSubtitle",{host:Sn}):t("vm.main.sharedSubtitle",{host:Sn}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:"mr-auto flex items-center text-[13px] leading-[18px] text-ink-secondary",children:[r?e.jsx(ce,{size:12,className:"mr-1.5 animate-spin"}):e.jsx(Ye,{tone:Cn?"success":null}),r?t("common.checking"):Nn?t("vm.main.statusUnavailable"):Ce&&Cn?t("vm.main.readyPerBot"):ds?t("vm.main.perBotUnsupported"):Tt?t("vm.main.ready"):a?.problem??t("vm.main.notReady")]}),e.jsx("button",{onClick:()=>{c(!0),h(U=>U+1),A(U=>U+1)},disabled:r||l!==null,className:"settings-quiet cursor-pointer last:-me-1.5 disabled:opacity-40",children:t("vm.main.recheck")}),Tt&&!Ce&&e.jsx("a",{href:a?.viewer_url??Ue?.view,target:"_blank",rel:"noreferrer",className:"settings-quiet cursor-pointer",children:t("vm.main.watch")})]}),p&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:p})]}),e.jsxs(xe,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_i,{label:t("vm.isolation.title"),value:a?.mode==="per-bot"?"per-bot":"shared",disabled:!a||m,onChange:U=>{a&&yn(U,a.max_instances??2)},options:[{value:"shared",label:t("vm.isolation.shared")},{value:"per-bot",label:t("vm.isolation.perBot")}]})}),Ce&&e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("vm.isolation.max")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx(de,{size:"sm","aria-label":t("vm.isolation.maxAria"),value:a?.max_instances??2,disabled:!a||m,onChange:U=>{yn(a?.mode??"shared",Number(U.target.value))},children:[1,2,3,4,5,6,7,8].map(U=>e.jsx("option",{value:U,children:U},U))})]}),e.jsx(Qg,{minutes:a?Math.round(a.idle_timeout_ms/6e4):Yg,disabled:!a||m,onSave:il}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(ce,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(xe,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(Ot,{n:1,title:t("vm.setup.step1"),done:!!a?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Ue?.install?e.jsx(Bs,{command:Ue.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(Ot,{n:2,title:a?.runtime&&!a.daemonUp?t("vm.setup.step2Open",{runtime:a.runtime}):t("vm.setup.step2"),done:!!a?.daemonUp,children:a?.runtime?Ue?.runtimeStart?e.jsx(Bs,{command:Ue.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(Ot,{n:3,title:t("vm.setup.step3"),done:!!a?.image,children:[a?.daemonUp&&e.jsx(st,{action:"pull",pending:l,onClick:()=>{Qe("pull")},children:t("vm.setup.prepare")}),Ue?.pull&&e.jsx(mi,{label:t("vm.setup.showPull"),command:Ue.pull})]}),e.jsxs(Ot,{n:4,title:Ce?t("vm.setup.step4PerBot"):wn?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!Ce&&Tt,children:[Ce?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:ds?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):wn?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx($e,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:a?.problem})]}),a?.image?e.jsxs(st,{action:"recreate",pending:l,onClick:()=>{Qe("recreate")},danger:!0,children:[e.jsx(hd,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):a?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(a.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(st,{action:"start",pending:l,onClick:()=>{Qe("start")},children:t("vm.setup.start")})]}):a?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ce,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):a?.image?e.jsxs(e.Fragment,{children:[e.jsx(st,{action:"run",pending:l,onClick:()=>{Qe("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Ue?.run&&e.jsx(mi,{label:t("vm.setup.showCommand"),command:Ue.run})]})]})}),Ce&&e.jsx(Jg,{instances:j,maxInstances:y||a?.max_instances||2,loading:w,deletingBotId:S,error:C,unavailableReason:F,onRefresh:()=>A(U=>U+1),onDelete:U=>{rl(U)}}),Nn&&e.jsx(xe,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx($e,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(xe,{title:t("vm.safety.title"),children:[e.jsx(Zg,{perBot:Ce,path:a?.workspace_guest_path??"/home/cua/workspace"}),kn&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a?.container==="running"&&e.jsxs(st,{action:"stop",pending:l,onClick:()=>{Qe("stop")},children:[e.jsx(fd,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(st,{action:"remove",pending:l,onClick:()=>{Qe("remove")},danger:!0,children:[e.jsx(We,{size:12})," ",Ce?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsx("div",{"data-vm-folder":"",className:"flex flex-col font-mono text-[12px] leading-4 text-ink-secondary",children:[...t("vm.safety.workspace",{path:a?.workspace_path??t("vm.safety.notCreated"),driver:a?.driver_version??"0.37.0",image:a?.image_ref??t("vm.safety.notPrepared")}).split(" · "),...a?.base_image_ref?[t("vm.safety.baseImage",{image:a.base_image_ref})]:[]].map(U=>{const H=U.indexOf(": "),Q=H<0?U:U.slice(H+2);return e.jsxs("span",{className:"block",children:[H<0?null:U.slice(0,H+2),e.jsx("span",{className:/[@:]sha256|^sha256|[0-9a-f]{24,}/.test(Q)?"[overflow-wrap:anywhere]":"break-words",children:Q})]},U)})})]})]})]})}const eh=10,Xr=1,Qr=60,xi="Enter a whole number from 1 to 60.";function th(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:xi};const a=Number(n);return a<Xr||a>Qr?{ok:!1,error:xi}:{ok:!0,minutes:a}}function gi(s){return s?.mcp?.callTimeoutMinutes??eh}function sh(){const{state:s,dispatch:n}=_(),a=gi(s.config),[i,r]=o.useState(String(a)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1),m=o.useRef(!1);o.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||m.current)return;const f=th(i);if(!f.ok){u(t("settings.mcpCalls.range"));return}m.current=!0,x(!0);try{const h=await D("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:h}),r(String(gi(h))),l(!1),u("")}catch(h){u(h instanceof Error?h.message:t("settings.mcpCalls.error"))}finally{m.current=!1,x(!1)}};return e.jsx(L,{title:t("settings.limits.toolTime"),subtitle:t("settings.limits.toolTimeLine"),message:d?e.jsx("span",{id:"mcp-call-timeout-error",role:"alert",className:"text-danger",children:d}):void 0,children:e.jsxs("span",{className:"flex w-[160px] items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:Xr,max:Qr,step:1,inputMode:"numeric",value:i,disabled:p,"aria-label":t("settings.limits.toolTime"),"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error":void 0,title:t("settings.mcpCalls.help"),onChange:f=>{r(f.target.value),l(!0),u("")},onBlur:()=>{g()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:z(Re,"w-auto min-w-0 flex-1",d&&"border-danger/60")}),t("settings.mcpCalls.minutes")]})})}const nh={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function ah({banner:s,canChange:n,subtitle:a}){const i=o.useRef(null),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=bd(s),p=async g=>{c(!0),d(null);const f=await Promise.resolve().then(g).catch(()=>({ok:!1,problem:"failed"}));c(!1),f.ok||d(nh[f.problem])},x=g=>{i.current&&(i.current.value=""),!(!g||!n)&&p(async()=>{const f=await yd(g);return f.ok?jd(f.blob):f})},m=l?e.jsx("p",{role:"alert",className:"text-danger",children:t(l)}):n?null:e.jsx("p",{className:"text-ink-secondary",children:t("placeLook.imageAdmins")});return e.jsx("div",{"data-place-picture":u?"set":"none",children:e.jsx(L,{title:t("placeLook.sidebarPicture"),subtitle:a,message:m,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[u&&e.jsx("img",{src:u,alt:t("placeLook.currentImage"),className:"h-8 w-14 rounded-md border border-ink/10 object-cover"}),e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>i.current?.click(),children:r?t("placeLook.imageSaving"):t(u?"placeLook.changeImage":"placeLook.useImage")}),u&&e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>{p(kd)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:vd,hidden:!0,"data-place-picture-input":!0,onChange:g=>x(g.target.files?.[0])})]})})})}function ih(){const s=wd(),n=tr(),{state:a}=_(),i=kt()===!0,r=window.ogb?.app?.ownPage===!0,[c,l]=o.useState(null),[d,u]=o.useState(null),p=s?.change===null,x=g=>{!s||p||c||g===(s.swatch??"slate")||(l(g),u(null),Nd(g).then(f=>{l(null),u(f)}))},m=s?.reason==="member"||d==="refused"?t("placeLook.member"):s?.reason==="signed-out"?t("placeLook.signedOut"):d==="unsupported"?t("placeLook.unsupported"):null;return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{"data-place-look":s.change??"locked",children:e.jsx(L,{title:t("placeLook.sidebarColor"),subtitle:t("placeLook.colorLine",{place:n.name}),message:d==="failed"?e.jsx("p",{role:"alert",className:"text-danger",children:t("placeLook.failed")}):m&&e.jsx("p",{className:"text-ink-secondary",children:m}),children:e.jsx(ro,{value:c??s.swatch,onChange:x,label:r?t("placeLook.sidebarColor"):t("placeLook.aria",{name:n.name}),disabled:p,offset:"menu",none:!0})})}),e.jsx(ah,{banner:a.config?.workspaceBanner??null,canChange:i,subtitle:t("placeLook.pictureLine")})]})}function Zr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const l=new Set,d=(p,x)=>{a={value:p,status:x};for(const m of l)m()},u=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const p=a.value;await n(p),i=a.value!==p}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(p){return l.add(p),()=>{l.delete(p)}},confirm(p){!i&&!r&&p!==a.value&&d(p,"idle")},edit(p){i=!0,d(p,"idle"),clearTimeout(c),c=setTimeout(()=>{u()},600)},flush:u}}const hi=new WeakMap;function rh(){const{state:s,dispatch:n}=_(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=hi.get(n);if(!r){const p={current:i};r={team:p,controller:Zr(a,async x=>{const m=p.current?await tn({aboutMe:x}):(await D("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:x}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:m?.aboutMe??x}})})},hi.set(n,r)}r.team.current=i;const c=r.controller,{value:l,status:d}=o.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:u}=c;return o.useEffect(()=>{c.confirm(a)},[c,a]),o.useEffect(()=>()=>{u()},[u]),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"profile-about-me",title:t("settings.profile.aboutMeHelp"),className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.profile.aboutMe")}),e.jsx("textarea",{id:"profile-about-me",value:l,rows:5,maxLength:i?4e3:24e3,onChange:p=>c.edit(p.target.value),onBlur:()=>{u()},placeholder:t("settings.profile.aboutMeHelp"),className:`min-h-[96px] w-full resize-none rounded-lg ${sr} bg-app px-2 py-1.5 text-[13px] leading-5 text-ink placeholder:text-ink-tertiary focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-focus`}),e.jsx(lh,{onChanged:p=>{c.confirm(p),n({type:"profileSaved",profile:{aboutMe:p}})}}),e.jsxs("div",{className:"text-[12px] leading-4 empty:hidden",role:"status",children:[d==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),d==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),d==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function lh({onChanged:s}){const[n,a]=o.useState([]),[i,r]=o.useState(null),[c,l]=o.useState(!1);o.useEffect(()=>{let u=!1;return D("/api/profile/learned").then(p=>{u||a(p.learned)}).catch(()=>{}),()=>{u=!0}},[]);const d=async u=>{r(u),l(!1);try{const p=await D(`/api/profile/learned/${encodeURIComponent(u)}/remove`,{method:"POST"});a(p.learned),s(p.aboutMe)}catch{l(!0)}finally{r(null)}};return n.length?e.jsxs("div",{className:"mt-1 rounded-lg border border-hairline/40 bg-inset p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.profile.learned.title")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-secondary",children:t("settings.profile.learned.hint")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-2",children:n.map(u=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[u.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:u.botName})})]}),e.jsx("button",{type:"button",disabled:i===u.id,onClick:()=>{d(u.id)},className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},u.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const fi=new WeakMap;function oh(){const{state:s,dispatch:n}=_(),a=s.config?.everyBotRules;let i=fi.get(n);i||(i=Zr(a??"",async p=>{const x=await D("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:p}),timeoutMs:1e4});n({type:"configStatus",config:x})}),fi.set(n,i));const{value:r,status:c}=o.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:l,edit:d,flush:u}=i;return o.useEffect(()=>{l(a??"")},[l,a]),o.useEffect(()=>()=>{u()},[u]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.profile.everyBotRules")}),e.jsx("textarea",{id:"profile-every-bot-rules",value:r,rows:4,maxLength:24e3,placeholder:t("settings.profile.everyBotRulesPlaceholder"),onChange:p=>d(p.target.value),onBlur:()=>{u()},className:`min-h-[96px] w-full resize-none rounded-lg ${sr} bg-app px-2 py-1.5 text-[13px] leading-5 text-ink placeholder:text-ink-tertiary focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-focus`}),e.jsxs("div",{className:"text-[12px] leading-4 empty:hidden",role:"status",children:[c==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),c==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),c==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const bi=64,vi=8192,Ft=512;function ch(s){return Cd(s)?s.size>Ed?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function dh(s,n){return s<bi||n<bi?"settings.profile.avatar.tooSmall":s>vi||n>vi?"settings.profile.avatar.tooLargeDimensions":null}async function el(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const l=new Image;l.onload=()=>r(l),l.onerror=()=>c(new Error("invalid-image")),l.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function uh(s,n){return el(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=Ft,r.height=Ft;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,Ft,Ft);const l=await new Promise((d,u)=>r.toBlob(p=>p?d(p):u(new Error("image-encode-failed")),"image/webp",.9));return new File([l],"profile-photo.webp",{type:"image/webp"})})}function ph({initials:s}){const{state:n,dispatch:a}=_(),i=n.config?.profile?.avatarUrl??"",[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),x=o.useRef(null),m=y=>{const v=x.current;v&&v.previewUrl!==y?.previewUrl&&URL.revokeObjectURL(v.previewUrl),x.current=y,p(y)};o.useEffect(()=>()=>{x.current&&URL.revokeObjectURL(x.current.previewUrl)},[]);const g=!!n.config?.team,f=async y=>{const v=g?await tn({avatarUrl:y}):(await D("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:y}})})).profile;a({type:"profileSaved",profile:{avatarUrl:v?.avatarUrl}})},h=y=>{if(!y)return;d(null);const v=ch(y);if(v)return d(t(v));el(y,w=>({width:w.naturalWidth,height:w.naturalHeight})).then(({width:w,height:N})=>{const C=dh(w,N);if(C)return d(t(C));m({file:y,previewUrl:URL.createObjectURL(y),width:w,height:N,zoom:1})},()=>d(t("settings.profile.avatar.invalidType")))},j=y=>{c(!0),d(null),uh(y.file,y.zoom).then(v=>Sd(v)).then(v=>{const w=v?lo(v.path):null;if(!w)throw new Error("avatar");return f(w)}).then(()=>m(null),()=>d(t("settings.profile.avatar.saveError"))).finally(()=>c(!1))},b=()=>{d(null),f("").catch(()=>d(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[u?e.jsx("div",{className:"flex w-full flex-col gap-2 rounded-lg border border-hairline/40 bg-inset p-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-16 shrink-0 overflow-hidden rounded-full bg-raised",children:e.jsx("img",{src:u.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${u.zoom})`}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("settings.profile.avatar.cropTitle")}),e.jsxs("div",{className:"text-[11px] text-ink-secondary",children:[u.width," × ",u.height,"px"]}),e.jsxs("label",{className:"mt-1 block text-[11px] text-ink-secondary",children:[t("settings.profile.avatar.zoom"),e.jsx("input",{"aria-label":t("settings.profile.avatar.zoom"),type:"range",min:"1",max:"2.5",step:"0.05",value:u.zoom,onChange:y=>m({...u,zoom:Number(y.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>m(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled:r,onClick:()=>j(u),children:t("settings.profile.avatar.save")})]})}):i?e.jsx("img",{...Un("person","picture"),src:i,alt:"",className:"size-10 rounded-full object-cover"}):e.jsx("span",{...Un("person","initials"),"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-ink/[0.08] text-[14px] font-medium leading-[18px] text-ink-secondary",children:s}),e.jsxs("label",{className:"ui-button ui-button-md cursor-pointer rounded-full",children:[r?t("settings.profile.avatar.uploading"):t(i?"settings.profile.avatar.change":"settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:r,onChange:y=>{const v=y.target.files?.[0];y.currentTarget.value="",h(v)}})]}),i&&!u&&e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:b,children:t("settings.profile.avatar.remove")})]}),l&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:l})]})}function mh(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(s.config?.profile?.name??""),[r,c]=o.useState(s.config?.profile?.email??"");o.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const l=!!s.config?.team,d=()=>{if(l){tn({name:a.trim()}).then(u=>n({type:"profileSaved",profile:{name:u.name,email:u.email}})).catch(()=>{});return}fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:r.trim().toLowerCase()}})}).then(u=>{if(!u.ok)throw new Error("Profile save failed");return u.json()}).then(u=>{u.profile&&n({type:"profileSaved",profile:{name:u.profile.name,email:u.profile.email}})}).catch(()=>{})};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ph,{initials:Mi({name:a,email:r})}),e.jsx(fe,{label:t("settings.profile.name"),children:e.jsx("input",{id:"profile-name","aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:he})}),e.jsx(fe,{label:t("phone.signIn.email"),children:e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:l?void 0:d,readOnly:l,placeholder:t("common.emailPlaceholder"),className:he})}),e.jsx(rh,{}),e.jsx(oh,{})]})}function xh(){const{state:s,dispatch:n}=_(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=o.useState(String(a)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1),m=o.useRef(!1);o.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||m.current)return;const f=Td(i);if(!f.ok){u(t("settings.roomTurns.range"));return}m.current=!0,x(!0);try{const h=await D("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:h}),r(String(h.rooms.turnTimeoutMinutes)),l(!1),u("")}catch(h){u(h instanceof Error?h.message:t("settings.roomTurns.error"))}finally{m.current=!1,x(!1)}};return e.jsx(L,{title:t("settings.limits.groupTurn"),subtitle:t("settings.limits.groupTurnLine"),message:d?e.jsx("span",{id:"room-turn-timeout-error",role:"alert",className:"text-danger",children:d}):void 0,children:e.jsxs("span",{className:"flex w-[160px] items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:Pd,max:Ad,step:1,inputMode:"numeric",value:i,disabled:p,"aria-label":t("settings.limits.groupTurn"),"aria-invalid":!!d,title:t("settings.roomTurns.help"),onChange:f=>{r(f.target.value),l(!0),u("")},onBlur:()=>{g()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:z(Re,"w-auto min-w-0 flex-1",d&&"border-danger/60")}),t("settings.roomTurns.minutes")]})})}function gh(){const{state:s,dispatch:n}=_(),a=Id(s.config),[i,r]=o.useState(!1),[c,l]=o.useState("");if(!Ld(s.config))return null;const d=async()=>{if(!i){r(!0),l("");try{const u=await D("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:u})}catch(u){l(u instanceof Error?u.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(L,{title:t("settings.savedSteps.title"),subtitle:t("settings.savedSteps.subtitle"),children:e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx(ie,{checked:a,disabled:i,"aria-label":t("settings.savedSteps.aria"),onClick:d}),c&&e.jsx("span",{role:"alert",className:"text-[12px] text-danger",children:c})]})})}const Ns=async s=>{const n=await fetch(...gt(s)).catch(()=>null);return n?.ok?await n.json().catch(()=>null):null};function hh(s,n){return s==="ready"?{tone:"success",text:t("settings.ai.ready")}:s==="attention"?{tone:"warning",text:t("settings.ai.attention")}:s==="setup"?{tone:null,text:t("settings.desktops.needsSetup")}:s==="elsewhere"?{tone:null,text:t("settings.account.onPlace",{place:n})}:{tone:null,text:t("settings.ai.notSetUp")}}function fh({status:s,onCheck:n,onClose:a}){const[i,r]=o.useState(!1),c=[{title:t("settings.desktops.step1"),done:!!s?.runtime},{title:t("settings.desktops.step2"),done:!!s?.daemonUp},{title:t("settings.desktops.step3"),done:!!s?.image}];return e.jsxs(St,{title:t("settings.desktops.setupTitle"),onClose:a,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button mr-auto",onClick:()=>r(l=>!l),children:t(i?"settings.desktops.hideDetails":"settings.desktops.details")}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.close")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:n,children:t("settings.desktops.checkAgain")})]}),children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.desktops.stepsLine",{app:ke()})}),e.jsx("ol",{className:"flex flex-col gap-2",children:c.map((l,d)=>e.jsxs("li",{"data-desktop-step":d+1,"data-done":l.done?"":void 0,className:"flex items-center gap-3 text-[14px] leading-5 text-ink",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-5 shrink-0 items-center justify-center rounded-full bg-ink/[0.06] text-[12px] font-medium leading-4 text-ink-secondary",children:l.done?"✓":d+1}),l.title]},l.title))}),i&&e.jsx("div",{"data-desktop-details":"",className:"max-h-[40vh] overflow-y-auto",children:e.jsx(Yr,{privateOnly:!0})})]})}function bh(){const{ctx:s,place:n,go:a}=Ne(),{state:i}=_(),r=i.config?.cloudHome===!0,[c,l]=o.useState(null),[d,u]=o.useState(null),[p,x]=o.useState(null),[m,g]=o.useState(!1),f=o.useCallback(()=>{r||Ns("status").then(l),Ns("cloud").then(u),Ns("vps").then(x)},[r]);o.useEffect(f,[f]);const h=Ys(),b=Et("desktops").find(T=>T.kind==="cloud"),y=!r&&h.paid&&!d?.configured,v=c?.ready?"ready":c?.runtime?"setup":"none",w=r||y?"elsewhere":d?.configured?d.available?"ready":"attention":"none",N=p?.configured?p.available?"ready":"attention":"none",C=(T,F,k,S,P,E)=>{const A=hh(T,y&&E==="cloud"?b?.name??t("cloudSetup.myCloud"):n.name);return T==="elsewhere"&&y&&E==="cloud"?e.jsx("div",{"data-desktop-kind":E,className:"contents",children:e.jsx(je,{title:F,leading:e.jsx(Ls,{children:S}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx(Ye,{tone:A.tone}),A.text," · ",k]}),external:!0,onClick:()=>b?.open(),data:{"data-desktop-elsewhere":""}})}):e.jsx("div",{"data-desktop-kind":E,className:"contents",children:e.jsx(L,{title:F,leading:e.jsx(Ls,{children:S}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx(Ye,{tone:A.tone}),A.text," · ",k]}),children:T!=="elsewhere"&&e.jsx("button",{type:"button",className:"ui-button",onClick:P,children:t(T==="ready"?"settings.simple.ai.manage":"settings.simple.ai.setUp")})})})};return e.jsxs(Y,{label:t("settings.desktops.kinds"),block:"desktops",children:[e.jsxs(J,{icons:!0,children:[C(w,t("settings.desktops.cloud"),t("settings.desktops.cloudLine"),e.jsx(Ii,{strokeWidth:1.75}),()=>a(s.plan&&!d?.configured?"plan":"ai",s.plan&&!d?.configured?void 0:"ai-keys"),"cloud"),!r&&C(v,t("settings.desktops.private"),t("settings.desktops.privateLine"),e.jsx(at,{strokeWidth:1.75}),()=>g(!0),"private"),(s.advanced||p?.configured)&&C(N,t("settings.desktops.servers"),t("settings.desktops.serversLine"),e.jsx(Bi,{strokeWidth:1.75}),()=>a("ai","ai-keys"),"servers")]}),m&&e.jsx(fh,{status:c,onCheck:f,onClose:()=>g(!1)})]})}function vh(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 tl({skill:s}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-ink-secondary",children:[e.jsx("span",{className:"truncate",title:s.source,children:t("skills.source",{source:s.source})}),e.jsx("span",{children:s.version?t("skills.library.version",{version:s.version}):t("skills.library.noVersion")}),e.jsx("span",{children:t("skills.library.importedAt",{date:new Date(s.importedAt).toLocaleDateString(Gs())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function yh(){const{state:s}=_(),[n,a]=o.useState([]),[i,r]=o.useState(!0),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(null),[m,g]=o.useState(null),[f,h]=o.useState(""),[j,b]=o.useState(""),[y,v]=o.useState(!1),[w,N]=o.useState(""),[C,T]=o.useState(""),F=o.useRef(!1),k=s.bots.filter(B=>!B.hidden),S=o.useMemo(()=>[...new Set(n.flatMap(B=>B.tags))].sort((B,W)=>B.localeCompare(W)),[n]),P=vh(n,d,p),E=async B=>{try{const W=await fetch("/api/skills-library"),G=await W.json();if(!W.ok)throw new Error(G.error??t("skills.library.loadError"));if(B?.())return;a(G.skills??[]),l("")}catch(W){B?.()||l(W instanceof Error?W.message:t("skills.library.loadError"))}finally{B?.()||r(!1)}};o.useEffect(()=>{let B=!1;return r(!0),E(()=>B),()=>{B=!0}},[]);const A=async(B,W,G)=>{if(F.current)return;F.current=!0;const oe=`${W}:${B}`;h(oe),l("");try{const M=await fetch("/api/skills-library"),$=await M.json();if(!M.ok)throw new Error($.error??t("skills.library.loadError"));const Z=($.skills??[]).filter(ne=>ne.assignedBots.some(me=>me.id===B)).map(ne=>ne.name),ee=G?Z.filter(ne=>ne!==W):[...new Set([...Z,W])],O=await fetch(`/api/bots/${encodeURIComponent(B)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:ee})}),re=await O.json();if(!O.ok)throw new Error(re.error??t("skills.error.assignments"));await E()}catch(M){l(M instanceof Error?M.message:t("skills.error.assignments"))}finally{F.current=!1,h("")}},V=async B=>{C&&await A(C,B.name,!1)},R=async(B,W)=>{await A(W,B.name,!0)},K=async(B,W=!1)=>{if(!F.current){if(!B.enabled&&!W)return ue(B,!0);F.current=!0,h(B.name),l("");try{const G=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!B.enabled})}),oe=await G.json();if(!G.ok)throw new Error(oe.error??t("skills.error.update"));W&&g(null),await E()}catch(G){l(G instanceof Error?G.message:t("skills.error.update"))}finally{F.current=!1,h("")}}},te=async B=>{if(!F.current){F.current=!0,h(B.name),l("");try{const W=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({everyBot:!B.everyBot})}),G=await W.json();if(!W.ok)throw new Error(G.error??"Could not update this skill.");await E()}catch(W){l(W instanceof Error?W.message:"Could not update this skill.")}finally{F.current=!1,h("")}}},ue=async(B,W=!1)=>{l("");try{const G=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`),oe=await G.json();if(!G.ok)throw new Error(oe.error??t("skills.error.load"));if(!oe.text)throw new Error(t("skills.error.contentsImport"));g({skill:B,text:oe.text,review:W})}catch(G){l(G instanceof Error?G.message:t("skills.error.load"))}},ae=async()=>{const B=j.trim();if(B){v(!0),l(""),N("");try{const W=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:B})}),G=await W.json();if(!W.ok)throw new Error(G.error??t("skills.error.import"));N(t("skills.library.imported",{name:G.skill?.name??""})),b(""),await E()}catch(W){l(W instanceof Error?W.message:t("skills.error.import"))}finally{v(!1)}}},X="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(xe,{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(Yt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:X,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:d,onChange:B=>u(B.target.value)})]}),S.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>x(null),className:p===null?"rounded-full bg-control px-2.5 py-1 text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),S.map(B=>e.jsx("button",{type:"button",onClick:()=>x(p===B?null:B),className:p===B?"rounded-full bg-control px-2.5 py-1 font-mono text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 font-mono text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:B},B))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):P.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:n.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:P.map(B=>e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{ue(B)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:B.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:B.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:B.description})]}),e.jsx(ie,{checked:B.enabled,"aria-label":B.enabled?t("skills.library.disable",{skill:B.name}):t("skills.library.enable",{skill:B.name}),disabled:!!(f||y),onClick:()=>{K(B)}})]}),e.jsx(tl,{skill:B}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3 rounded-lg bg-inset px-2.5 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("skills.library.everyBot")}),e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t("skills.library.everyBotHint")})]}),e.jsx(ie,{checked:B.everyBot,"aria-label":t("skills.library.everyBot"),disabled:!!(f||y),onClick:()=>{te(B)}})]}),B.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:B.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:B.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):B.assignedBots.map(W=>e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-control px-2 py-0.5",children:[e.jsx("span",{className:"max-w-40 truncate",children:W.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:W.name}),title:t("skills.library.removeAssignment",{bot:W.name}),disabled:!!(f||y),onClick:()=>{R(B,W.id)},className:"flex size-4 items-center justify-center rounded-full text-ink-secondary hover:bg-danger/10 hover:text-danger disabled:opacity-40",children:e.jsx(Oe,{size:11})})]},W.id))}),k.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs(de,{size:"sm","aria-label":t("skills.library.assignLabel"),value:C,disabled:!!(f||y),onChange:W=>T(W.target.value),className:"max-w-45",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),k.map(W=>e.jsx("option",{value:W.id,children:W.name},W.id))]}),e.jsx("button",{type:"button",disabled:!C||!!(f||y),onClick:()=>{V(B)},className:"rounded-lg bg-control px-2.5 py-1 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:t("skills.library.assign")})]})]},B.name))}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}),e.jsx(xe,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:B=>{B.preventDefault(),ae()},children:[e.jsx("textarea",{className:`${X} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:j,onChange:B=>b(B.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:w}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:y||!!f||!j.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:y?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),m&&e.jsx(Oi,{modal:!0,children:e.jsx(jh,{viewing:m,error:c,working:!!f,onClose:()=>{f||g(null)},onEnable:()=>{K(m.skill,!0)}})})]})}function jh({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=o.useRef(null);return oo(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(tl,{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 kh(){const{state:s,dispatch:n}=_(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=o.useState(null),[l,d]=o.useState(""),u=o.useRef(!1),p=async x=>{if(!(u.current||x===a)){u.current=!0,c(x),d("");try{const m=await D("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:x}})});n({type:"configStatus",config:m})}catch(m){d(m instanceof Error?m.message:t("settings.threads.error"))}finally{u.current=!1,c(null)}}};return e.jsx("div",{"data-settings-block":"parallel",className:"contents",children:e.jsx(L,{title:t("settings.threads.title"),subtitle:i?t("settings.threads.starterShort"):t("settings.threads.short"),message:r!==null?e.jsx("span",{role:"status",children:t("settings.threads.saving")}):l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):void 0,children:e.jsx(de,{id:"thread-concurrency","aria-label":t("settings.threads.label"),title:t("settings.threads.helpHanded"),value:r??a,disabled:r!==null||i,onChange:x=>{p(Number(x.target.value))},children:Array.from({length:16},(x,m)=>m+1).map(x=>e.jsx("option",{value:x,children:x},x))})})})}function sl(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState(null),l=s.config?.tts?.everyReply===!0,d=o.useContext(Ae),u=()=>{i(!0),c(null),D("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!l}})}).then(p=>n({type:"configStatus",config:p})).catch(p=>c(p.message)).finally(()=>i(!1))};return d?e.jsx("div",{"data-voice-every-reply":!0,className:"contents",children:e.jsx(L,{title:t("voice.everyReply"),subtitle:t("voice.everyReply.allHelp"),leading:e.jsx("span",{"aria-hidden":"true"}),message:r?e.jsx("span",{role:"alert",className:"text-danger",children:r}):void 0,children:e.jsx(ie,{checked:l,disabled:a,"aria-label":t("voice.everyReply"),onClick:u})})}):e.jsxs("div",{"data-voice-every-reply":!0,className:"flex items-center justify-between gap-4 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium leading-5 text-ink",children:t("voice.everyReply")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-4 text-ink-secondary",children:t("voice.everyReply.allHelp")}),r&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r})]}),e.jsx(ie,{checked:l,disabled:a,"aria-label":t("voice.everyReply"),onClick:u})]})}function Ss(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const Me=z(Ve,"font-sans"),wh=[5,10,20,30,60],yi="flex flex-col gap-1 text-[12px] leading-4 text-ink-secondary",Cs="ui-icon-button shrink-0 hover:text-ink",Es={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},_s={count:64,length:200},Nh=s=>s.length<=_s.count&&s.every(n=>n.length<=_s.length),Hs=(s,n)=>D(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function Sh(s,n){try{return!s||new URL(n.trim()).origin!==new URL(s).origin}catch{return!1}}function nl({server:s,disabled:n,onPick:a}){return e.jsxs(de,{size:"sm",className:"shrink-0",value:s.replyWaitMinutes??"",onChange:i=>a(i.target.value?Number(i.target.value):null),disabled:n,"aria-label":t("apiInstances.replyWaitFor",{name:s.displayName}),title:t("apiInstances.replyWaitHint"),children:[e.jsx("option",{value:"",children:t("apiInstances.replyWaitDefault")}),[...new Set([...wh,...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 Ch(){const{state:s,dispatch:n,refreshInstances:a}=_(),[i,r]=o.useState(!1),[c,l]=o.useState(null),d=s.instances.find(p=>p.instanceId==="openaiCompat"&&p.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const u=p=>{i||(r(!0),l(null),Hs(d.instanceId,{replyWaitMinutes:p}).then(async({instances:x})=>{Array.isArray(x)?n({type:"instances",instances:x}):await a({reportErrors:!0})}).catch(x=>l(x.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(nl,{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 Eh(){const{state:s}=_();return e.jsx(Ah,{servers:sn(s.instances)})}function Ah({servers:s}){const{dispatch:n,refreshInstances:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(""),[m,g]=o.useState(null),[f,h]=o.useState(null),[j,b]=o.useState(null),[y,v]=o.useState(""),[w,N]=o.useState(""),[C,T]=o.useState(""),[F,k]=o.useState(null),S=!!(i.trim()&&c.trim()&&d.trim()),P=(A,V,R,K)=>{m||(g(A),h(null),k(null),V().then(async({instances:te,warning:ue})=>{Array.isArray(te)?n({type:"instances",instances:te}):await a({reportErrors:!0}),R?.(!!ue)}).catch(te=>h({text:te.message||t("apiInstances.failed"),at:K})).finally(()=>g(null)))},E=()=>S&&P("add",()=>D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...Ss(p).length?{models:Ss(p)}:{}})}).then(A=>(ot("custom_endpoint","settings","unverified"),A),A=>{throw ot("custom_endpoint","settings","error"),A}),()=>{r(""),l(""),u(""),x("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] font-medium leading-[18px] text-ink",children:t("apiInstances.title")}),e.jsx("p",{className:"mb-2 text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.subtitle")}),s.length===0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.empty")}),s.map(A=>{const V=w.trim().replace(/\/+$/,""),R=V!==(A.url??""),K=R&&!C.trim()&&!A.placeholderKey&&Sh(A.url,V);return e.jsxs("div",{className:"py-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] leading-5 text-ink",children:A.displayName}),A.url&&e.jsx("div",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:A.url})]}),e.jsx(nl,{server:A,disabled:m!==null,onPick:te=>P("other",()=>Hs(A.instanceId,{replyWaitMinutes:te}))}),e.jsx("button",{type:"button",onClick:()=>{v((A.managedModels??[]).join(", ")),N(A.url??""),T(""),b(j===A.instanceId?null:A.instanceId),h(null),k(null)},disabled:m!==null,"aria-label":t("apiInstances.editServer",{name:A.displayName}),"aria-expanded":j===A.instanceId,title:t("apiInstances.editServer",{name:A.displayName}),className:Cs,children:e.jsx(Rd,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>P("other",()=>D(`/api/instances/${encodeURIComponent(A.instanceId)}/refresh-models`,{method:"POST"})),disabled:m!==null,"aria-label":t("apiInstances.refreshModels",{name:A.displayName}),title:t("apiInstances.refreshModels",{name:A.displayName}),className:Cs,children:e.jsx(Bd,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>P("other",()=>D(`/api/instances/${encodeURIComponent(A.instanceId)}`,{method:"DELETE"})),disabled:m!==null,"aria-label":t("apiInstances.remove",{name:A.displayName}),title:t("apiInstances.remove",{name:A.displayName}),className:`${Cs} hover:bg-danger/10 hover:text-danger`,children:e.jsx(We,{size:13,"aria-hidden":"true"})})]}),j===A.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsxs("label",{className:yi,children:[t("apiInstances.url"),e.jsx("input",{type:"url",value:w,onChange:te=>N(te.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.urlFor",{name:A.displayName}),spellCheck:!1,disabled:m!==null,className:Me})]}),e.jsxs("label",{className:yi,children:[t("apiInstances.key"),e.jsx("input",{type:"password",value:C,onChange:te=>T(te.target.value),placeholder:t("apiInstances.keepKey"),"aria-label":t("apiInstances.keyFor",{name:A.displayName}),autoComplete:"off",disabled:m!==null,className:Me})]}),K&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.newHostKey")}),e.jsx("input",{value:y,onChange:te=>v(te.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:A.displayName}),spellCheck:!1,disabled:m!==null,className:Me}),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 te=Ss(y);if(!Nh(te)){h({text:t("apiInstances.modelsLimit",_s),at:A.instanceId});return}const ue={models:te,...R?{url:V}:{},...C.trim()?{apiKey:C.trim()}:{}};P("other",()=>Hs(A.instanceId,ue),ae=>{T(""),ae?k(A.instanceId):b(null)},A.instanceId)},disabled:m!==null||K,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>{b(null),T("")},disabled:m!==null,className:"ui-button",children:t("common.cancel")})]}),f?.at===A.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:f.text}),F===A.instanceId&&e.jsx("p",{role:"status",className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsUnreadable")})]})]},A.instanceId)}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Es.name),l(Es.url)},disabled:m!==null,className:"ui-button self-end",children:t("apiInstances.geminiPreset")}),c.trim()===Es.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:A=>r(A.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:m!==null,className:Me}),e.jsx("input",{type:"url",value:c,onChange:A=>l(A.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:m!==null,className:Me}),e.jsx("input",{type:"password",value:d,onChange:A=>u(A.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:m!==null,className:Me}),e.jsx("input",{value:p,onChange:A=>x(A.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:m!==null,className:Me}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsx("button",{type:"button",onClick:E,disabled:m!==null||!S,className:"ui-button self-end",children:m==="add"?t("apiInstances.adding"):t("apiInstances.add")})]}),f&&!f.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:f.text})]})}const Ph="lm-studio";function Th(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 Ih({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=_(),r=sn(n.instances),[c,l]=o.useState("1234"),[d,u]=o.useState(""),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=Th(c),h=!!(f&&r.some(b=>b.url===f)),j=()=>{p||!f||h||(x(!0),g(null),D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:f,key:d.trim()||Ph,catalog:"lmstudio"})}).then(async b=>{ot("custom_endpoint","settings","unverified"),Array.isArray(b.instances)?a({type:"instances",instances:b.instances}):await i({reportErrors:!0}),u("")},b=>{ot("custom_endpoint","settings","error"),g(b instanceof Error&&b.message?b.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:z("text-[12px] leading-4 text-ink-secondary",s&&"mt-1"),children:t("lmStudio.desc")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[13px] font-medium leading-[18px] text-ink",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:b=>l(b.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:p,className:Me})]}),e.jsx("input",{type:"password",value:d,onChange:b=>u(b.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:p,className:Me}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),f&&e.jsx("p",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:f}),e.jsx("button",{type:"button",onClick:j,disabled:p||!f||h,className:"ui-button self-end",children:p?t("lmStudio.adding"):t("lmStudio.add")}),h&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),m&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:m})]})}const Lh="ollama",Rh="https://ollama.com/download",Bh=s=>`${s.replace(/\/+$/,"")}/v1`,Oh=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Fh({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=_(),[r,c]=o.useState(""),[l,d]=o.useState(null),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(null),h=o.useRef(0),j=o.useRef(!1),b=o.useCallback(C=>{const T=++h.current;p(!0),f(null),D(`/api/instances/ollama${C?`?url=${encodeURIComponent(C)}`:""}`).then(F=>{T===h.current&&d(F.status)}).catch(F=>{T===h.current&&(d(null),f(F.message||t("apiInstances.failed")))}).finally(()=>{T===h.current&&p(!1)})},[]);o.useEffect(()=>{!s||j.current||(j.current=!0,b(""))},[s,b]);const y=l?Bh(l.url):null,v=!!(y&&(sn(n.instances).some(C=>C.url===y)||Oh(n.config?.openaiCompat?.url,y))),w=!!(y&&!v&&!x&&!u&&(l?.state==="ready"||l?.state==="no-models")),N=()=>{!w||!y||(m(!0),f(null),D("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:y,key:Lh,catalog:"ollama"})}).then(async C=>{ot("custom_endpoint","settings","unverified"),Array.isArray(C.instances)?a({type:"instances",instances:C.instances}):await i({reportErrors:!0})},C=>{ot("custom_endpoint","settings","error"),f(C instanceof Error&&C.message?C.message:t("apiInstances.failed"))}).finally(()=>m(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:u?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(ce,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):l&&e.jsx(Od,{status:l})}),!u&&l?.state==="not-running"&&e.jsx("a",{href:Rh,target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-block text-[12px] font-medium text-accent-text hover:underline",children:t("ollama.download")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("input",{type:"url",value:r,onChange:C=>c(C.target.value),onKeyDown:C=>{C.key==="Enter"&&b(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:x,className:Ve}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:N,disabled:!w,className:"ui-button",children:x?t("ollama.adding"):t("ollama.add")}),e.jsx("button",{type:"button",onClick:()=>b(r.trim()),disabled:u||x,className:"settings-quiet cursor-pointer",children:t("common.checkAgain")})]}),v&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g})]})}function Uh(){const{state:s,dispatch:n}=_(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(null),f=d||p!==null,h=(y,v)=>D("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[y]:v}}})}).then(w=>n({type:"configStatus",config:w})),j=()=>{const y=i.trim().toUpperCase(),v=Fd(c);if(!(f||!y||!v)){if(!Ud(v)){g(t("keys.notAKey"));return}u(!0),g(null),h(y,v).then(()=>{r(""),l("")}).catch(w=>g(w.message)).finally(()=>u(!1))}},b=y=>{f||(x(y),g(null),h(y,"").catch(v=>g(v.message)).finally(()=>x(null)))};return e.jsxs("div",{"data-opencode-provider-keys":!0,className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.otherProviders.hint")}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((y,v)=>v===0?[y]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},v),y])}),a.map(y=>e.jsxs("div",{"data-opencode-provider-key":y,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:z(Ve,"block flex-1 truncate text-ink"),children:y}),e.jsx("button",{type:"button",onClick:()=>b(y),disabled:f,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:y}),className:"ui-button shrink-0",children:p===y?e.jsx(ce,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},y)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:y=>{g(null),r(y.target.value)},onKeyDown:y=>y.key==="Enter"&&j(),disabled:f,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:z(Ve,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:y=>{g(null),l(y.target.value)},onKeyDown:y=>y.key==="Enter"&&j(),disabled:f,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:z(Ve,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:j,disabled:f||!i.trim()||!c.trim(),className:"ui-button shrink-0",children:d?e.jsx(ce,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),m&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:m})]})}function Mh(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState(null);if(!s.config?.anthropic?.configured)return null;const l=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),D("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!l}})}).then(u=>n({type:"configStatus",config:u})).catch(u=>c(u.message)).finally(()=>i(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.anthropic.everyBot")}),e.jsx("div",{className:"text-[12px] leading-4 text-ink-secondary",children:l?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(ie,{checked:l,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),l&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx($e,{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 Dh(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(""),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=!!s.config?.vps?.configured,p=!a.trim()&&u;o.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const x=()=>{r||!a.trim()&&!u||(c(!0),d(null),D("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(m=>{n({type:"configStatus",config:m}),i(m.vps?.sshAlias??"")}).catch(m=>d(m.message)).finally(()=>c(!1)))};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[12px] leading-4 text-ink-secondary",children:[t("keys.vps.descBefore"),e.jsx("a",{href:"https://github.com/seira-bot/seira/blob/main/docs/byo-vps.md",target:"_blank",rel:"noopener noreferrer",className:"text-accent-text hover:underline",children:t("keys.vps.descLink")}),t("keys.vps.descAfter")]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.vps.anyMachine")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:m=>i(m.target.value),onKeyDown:m=>m.key==="Enter"&&x(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:z(Ve,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:x,disabled:r||!a.trim()&&!u||a.trim()===(s.config?.vps?.sshAlias??""),className:z("ui-button shrink-0",!p&&"ui-button-primary"),title:p?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(ce,{size:13,className:"animate-spin","aria-hidden":"true"}):p?t("keys.row.remove"):t("common.save")})]}),l&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:l})]})}function zh(){const{state:s,dispatch:n}=_(),a=s.config?.openaiCompat?.url??"",[i,r]=o.useState(a),[c,l]=o.useState(!1),[d,u]=o.useState(null),p=o.useRef(!1);o.useEffect(()=>{r(a)},[a]);const x=i.trim()!==a,m=()=>{p.current||!x||(p.current=!0,l(!0),u(null),D("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(g=>n({type:"configStatus",config:g})).catch(g=>u(g.message)).finally(()=>{p.current=!1,l(!1)}))};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.openaiCompat.url")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"url",value:i,onChange:g=>r(g.target.value),onBlur:m,onKeyDown:g=>g.key==="Enter"&&m(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:z(Ve,"pr-8")}),c&&e.jsx(ce,{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 _h="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",Hh=1600,$h={opencodeProviders:()=>e.jsx(Uh,{}),ollama:s=>e.jsx(Fh,{visible:s}),lmStudio:()=>e.jsx(Ih,{heading:!1}),vps:()=>e.jsx(Dh,{})},Kh={anthropic:()=>e.jsx(Mh,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(zh,{}),e.jsx(Ch,{}),e.jsx(Eh,{})]}),liveKey:()=>e.jsx(_d,{})};function $s(s,n){if(s.kind==="uses")return!1;const a=nn(s,n);return a.configured||a.included===!0}function Wh({entry:s,visible:n}){const{state:a}=_(),i=o.useId(),c=nn(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:ir,children:[e.jsx(rr,{entry:s,status:c,titleId:i}),e.jsx("div",{className:z("flex flex-col gap-2",lr),children:$h[s.id]?.(n)})]})}function Gh({entry:s}){const{state:n,dispatch:a}=_(),i=o.useId(),r=s.opens,c=nn(s,n.config),l=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:ir,children:[e.jsx(rr,{entry:s,status:l,titleId:i}),e.jsxs("div",{className:z("flex flex-col gap-2",lr),children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(zd,{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 al({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(aa,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(Wh,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(Gh,{entry:s}):e.jsx(aa,{id:s.id,children:Kh[s.id]?.()})}function qh({id:s,rows:n,open:a,onToggle:i}){const{state:r}=_(),c=ht.find(p=>p.id===s),l=o.useId(),d=o.useId(),u=n.filter(p=>$s(p,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":l,className:_h,children:[e.jsxs("button",{type:"button","aria-expanded":a,"aria-controls":d,onClick:i,className:"flex w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{id:l,className:"text-[14px] font-medium leading-5 text-ink",children:t(c.titleKey)}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c.purposeKey)})]}),u>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:u})}),e.jsx(Ct,{size:14,"aria-hidden":"true",className:z("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none",a&&"rotate-90")})]}),e.jsxs("div",{id:d,hidden:!a,className:"flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)",children:[n.map(p=>e.jsx(al,{entry:p,visible:a},p.id)),s==="voice"&&e.jsx(sl,{})]})]})}function Vh(s,n,a){const i=n.row?s?.querySelector(`[data-key-row="${n.row}"]`):s?.querySelector(`[data-keys-section="${a}"]`);if(!i||i.closest("[hidden]"))return!1;const r=pu(i);return r&&dr(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"),Hh)),!0}function Jh({bare:s=!1,exclude:n=[]}={}){const{state:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(()=>new Set(ht.filter(h=>h.id==="ai"||mt.some(j=>j.section===h.id&&$s(j,a.config))).map(h=>h.id))),d=o.useRef(null),u=Md(),p=i.trim().toLowerCase();o.useEffect(()=>{if(!u)return;const h=mt.find(v=>v.id===u.row)?.section??"ai";r(""),l(v=>v.has(h)?v:new Set([...v,h]));let j=0,b=0;const y=()=>{Vh(d.current,u,h)||++b>60?Dd(u):j=window.requestAnimationFrame(y)};return j=window.requestAnimationFrame(y),()=>window.cancelAnimationFrame(j)},[u]);const x=mt.filter(h=>nr(h,p,a.config)&&!ar(h.id,a.config)),m=u?mt.find(h=>h.id===u.row)?.section:void 0,g=ht.filter(h=>!n.includes(h.id)||h.id===m).flatMap(h=>{const j=x.filter(b=>b.section===h.id);return j.length>0?[{id:h.id,rows:j}]:[]}),f=h=>l(j=>{const b=new Set(j);return b.has(h)?b.delete(h):b.add(h),b});return s?e.jsx("div",{ref:d,"data-keys-page":"",children:e.jsx(J,{icons:!0,children:g.map(({id:h,rows:j})=>{const b=ht.find(v=>v.id===h),y=j.filter(v=>$s(v,a.config)).length;return e.jsx(wt,{id:`keys-${h}`,title:t(b.titleKey),subtitle:t(b.purposeKey),leading:e.jsx("span",{"aria-hidden":"true"}),value:y>0?t("keys.section.connected",{count:y}):void 0,open:c.has(h),onToggle:()=>f(h),children:e.jsxs("div",{"data-keys-section":h,className:"flex flex-col gap-0.5 py-1.5",children:[j.map(v=>e.jsx(al,{entry:v,visible:c.has(h)},v.id)),h==="voice"&&e.jsx(sl,{})]})},h)})})}):e.jsxs("div",{ref:d,"data-keys-page":!0,className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.connections.subtitle")}),e.jsxs("div",{className:"flex h-8 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(Yt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:i,onChange:h=>r(h.target.value),onKeyDown:h=>{h.key!=="Escape"||!i||(h.preventDefault(),h.stopPropagation(),r(""))},placeholder:t("keys.search.placeholder"),"aria-label":t("keys.search.aria"),autoComplete:"off",spellCheck:!1,className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),g.length===0?e.jsx("p",{"data-keys-empty":!0,className:"px-1 text-[13px] leading-[18px] text-ink-secondary",children:t("keys.search.none",{query:i.trim()})}):g.map(({id:h,rows:j})=>e.jsx(qh,{id:h,rows:j,open:p!==""||c.has(h),onToggle:()=>l(b=>{const y=new Set(b);return y.has(h)?y.delete(h):y.add(h),y})},h))]})}const As="/api/updates/server",Yh=4e3;function Xh(){const s=typeof window>"u"?void 0:window.ogb;return s?.app?.ownPage===!1&&s.appUpdate&&s.app.version?s.app.version:null}const ji=s=>s?.run?.outcome!=="requested"&&s?.run?.outcome!=="running";function Qh(){const{state:s}=_(),n=s.connected!==!1,[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(null),[h,j]=o.useState(null),b=o.useCallback(async()=>{const E=await $d(As,()=>D(As,{timeoutMs:2e4}),null);return c(E),E},[]),y=o.useCallback(async()=>{d(!0),p(!1);try{const E=await D("/api/updates/check",{timeoutMs:2e4});i(E),E.install!=="desktop"&&E.install!=="managed"&&await b().catch(()=>null)}catch{p(!0)}finally{d(!1)}},[b]);o.useEffect(()=>{y()},[y]);const v=x||!ji(r),[w,N]=o.useState(null),[C,T]=o.useState(()=>Date.now());o.useEffect(()=>{if(!v)return void N(null);N(A=>A??Date.now());const E=setInterval(()=>T(Date.now()),3e4);return()=>clearInterval(E)},[v]),o.useEffect(()=>{if(!v||!n)return;let E=!0;const A=()=>{b().then(R=>{E&&ji(R)&&y()}).catch(()=>{})};A();const V=setInterval(A,Yh);return()=>{E=!1,clearInterval(V)}},[v,n,b,y]);const F=o.useCallback(async()=>{m(!0),f(null);try{const E=await D(As,{method:"POST",body:"{}",timeoutMs:2e4});c(E.status)}catch(E){if(E instanceof Kd){const A=E.body;A?.status&&c(A.status),f(E.status===429?t("serverUpdate.reason.tooSoon"):E.status===409?null:t("serverUpdate.failed"))}else c(A=>A&&{...A,run:{outcome:"requested",from:A.current,at:Date.now()}})}finally{m(!1)}},[]),k=o.useCallback(async()=>{try{j(await window.ogb.appUpdate.request())}catch{j("failed")}},[]),S=w===null?0:Math.max(0,C-w),P=Wd({check:a,status:r,app:Xh(),checking:l,failed:u,pressed:x,appAnswer:h,waitedMs:S});return{check:a,status:r,view:g?{...P,note:g,noteTone:"danger"}:P,load:y,readStatus:b,updateServer:F,updateApp:k}}const Zh={check:"settings.updates.check","update-server":"serverUpdate.updateServer","update-app":"serverUpdate.updateApp",reload:"settings.simple.updates.reload"};function ef({title:s}){const n=Qh(),[a,i]=o.useState(!1),{view:r,check:c,status:l}=n,d=()=>{if(r.action==="check")return void n.load();if(r.action==="reload")return window.location.reload();if(r.action==="update-app")return void n.updateApp();r.action==="update-server"&&(n.readStatus().catch(()=>null),i(!0))},u=c?.available&&c.releaseUrl&&r.action!=="check"?c.releaseUrl:null;return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:s,subtitle:[r.label,r.subtitle].filter(Boolean).join(" "),message:r.note?e.jsx("span",{className:r.noteTone==="danger"?"text-danger":"text-ink-secondary",children:r.note}):void 0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>Ps(u),children:t("settings.simple.updates.seeRelease")}),r.action&&e.jsx("button",{type:"button",className:"ui-button",disabled:r.busy,onClick:d,children:t(Zh[r.action])})]})}),e.jsx(Fi,{open:a,title:t("serverUpdate.confirmTitle"),body:Hd(l?.activeTurns??0),confirmLabel:t("serverUpdate.updateServer"),onCancel:()=>i(!1),onConfirm:()=>{i(!1),n.updateServer()}})]})}function qe({anchor:s,also:n=[],children:a}){const{ctx:i,anchor:r}=Ne();return i.advanced?e.jsx(e.Fragment,{children:a}):r!==s&&!(r&&n.includes(r))?null:e.jsx(e.Fragment,{children:a})}const Ut="omb-settings-grouped-note",tf=30;function sf(){const[s,n]=o.useState(!1);return o.useEffect(()=>{try{const a=localStorage.getItem(Ut);if(a==="dismissed")return;const i=a?Number(a):null;if(i===null){if(!["omb-skin","omb-advanced-mode","omb-send-key"].some(c=>localStorage.getItem(c)!==null)){localStorage.setItem(Ut,"dismissed");return}localStorage.setItem(Ut,String(Date.now())),n(!0);return}n(Date.now()-i<tf*864e5)}catch{}},[]),[s,()=>{n(!1);try{localStorage.setItem(Ut,"dismissed")}catch{}}]}function nf(){const{ctx:s,place:n,go:a}=Ne(),{state:i,dispatch:r}=_(),[c,l]=sf(),d=Ui(!s.client),u=i.config?.team,p=Wi()?.me?.role==="owner",x=d.kind==="paired"||d.kind==="attention"?t("settings.glance.phonePaired",{count:d.count}):d.kind==="none"?t("settings.glance.notSetUp"):void 0,m=i.instances.filter(f=>f.snapshot.state==="available").length,g=af();return e.jsxs(e.Fragment,{children:[c&&e.jsx(J,{children:e.jsxs("div",{className:"flex min-h-11 items-center gap-6 py-2 pl-4 pr-2","data-settings-grouped-note":"",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[14px] leading-5 text-ink",children:t(s.desktop?"settings.overview.grouped":"settings.overview.groupedBrowser",{place:n.name})}),e.jsx("button",{type:"button","aria-label":t("settings.dismiss"),onClick:l,className:"flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-full text-ink-secondary hover:bg-menu-hover hover:text-ink focus-visible:outline-2 focus-visible:outline-focus",children:e.jsx(Oe,{size:14,"aria-hidden":"true"})})]})}),n.kind==="server"&&!s.client&&!window.ogb?.updater&&e.jsx(Y,{label:t("settings.updates.title"),block:"version",children:e.jsx(J,{children:e.jsx(ef,{title:Kt()})})}),e.jsx(Y,{label:t("settings.overview.glance"),block:"glance",children:e.jsxs(J,{children:[!s.client&&e.jsx(je,{title:t("settings.section.phoneDevices"),value:x,onClick:()=>a("phone"),data:{"data-glance":"phone"}}),!s.client&&e.jsx(je,{title:t("settings.group.ai"),onClick:()=>a("ai","providers"),data:{"data-glance":"ai"},value:s.admin?m>0?t("settings.glance.aiReady",{count:m}):t("settings.glance.aiStart"):t("settings.glance.aiAdmin")}),s.advanced&&e.jsx(je,{title:t("settings.glance.apps"),external:!0,value:g===null?void 0:g>0?t("settings.glance.appsConnected",{count:g}):t("settings.glance.appsNone"),onClick:()=>{r({type:"toggleAppSettings",open:!1}),r({type:"togglePlugins",open:!0})},data:{"data-glance":"apps"}})]})}),e.jsx(Y,{label:t("settings.overview.sidebar"),block:"sidebar",children:e.jsxs(J,{children:[e.jsx(ih,{}),e.jsx(Vd,{simple:!0})]})}),s.desktop&&s.cloud&&u&&u.cloudPage&&e.jsx("div",{"data-settings-block":"people-and-plan",children:e.jsx(yp,{team:u,admin:s.admin,owner:p})}),n.kind==="server"&&!s.client&&s.advanced&&e.jsx(lg,{})]})}function af(){const[s,n]=o.useState(null);return o.useEffect(()=>{let a=!0;return Jd().then(i=>{a&&n(Object.values(i.services).filter(r=>r.connected).length)}).catch(()=>{}),()=>{a=!1}},[]),s}function rf(){const{ctx:s,anchor:n}=Ne(),[a,i]=o.useState(!1),[r,c]=o.useState(s.advanced||n==="ai-keys"),l=s.advanced||r||n==="ai-keys",d=ht.filter(u=>u.id!=="ai").length;return e.jsx(e.Fragment,{children:e.jsxs(vt,{children:[e.jsx("div",{"data-settings-block":"providers",className:"flex scroll-mt-4 flex-col gap-6",children:e.jsx(ku,{simple:!0,more:{id:"ai-more",open:a,onToggle:()=>i(u=>!u)}})}),!s.advanced&&e.jsx(Y,{block:"ai-keys-fold",children:e.jsx(J,{children:e.jsx(wt,{id:"ai-other-services",title:t("settings.ai.otherServices"),value:String(d),open:l,onToggle:()=>c(!l)})})}),l&&e.jsx(Y,{label:s.advanced?t("settings.ai.otherServices"):void 0,block:"ai-keys",children:e.jsx(Jh,{bare:!0,exclude:n==="ai-keys"?[]:["ai"]})}),e.jsx(qe,{anchor:"backup-model",children:e.jsx(Y,{label:t("settings.ai.backupModel"),block:"backup-model",children:e.jsx(Vx,{})})}),e.jsx(qe,{anchor:"ai-pool",children:e.jsx(Y,{label:t("settings.ai.pool"),block:"ai-pool",children:e.jsx(Zx,{})})}),e.jsx(qe,{anchor:"routing",children:e.jsx(bg,{})}),e.jsx(qe,{anchor:"images",children:e.jsx(Tg,{})})]})})}function lf(){const{ctx:s}=Ne(),{state:n}=_(),a=(n.config?.pausedBots?.length??0)>0;return e.jsxs(e.Fragment,{children:[a&&e.jsx(Y,{block:"awake",children:e.jsx(J,{children:e.jsx(L,{title:t("settings.bots.awakeTitle"),subtitle:t("settings.bots.awakeLine"),children:e.jsx(qd,{})})})}),e.jsx(Y,{label:t("settings.bots.aboutYou"),block:"about-you",footnote:s.here||!s.desktop?t("settings.bots.aboutYouHome",{app:ke()}):void 0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(xe,{children:e.jsx(mh,{})}),e.jsxs(J,{children:[e.jsx(vg,{}),e.jsx(eg,{row:!0})]})]})}),e.jsx(Y,{label:t("settings.bots.newBots"),block:"new-bots",children:e.jsxs(J,{children:[e.jsx(Jp,{}),e.jsx(Su,{simple:!0})]})}),!(s.team&&!s.admin)&&e.jsx(qe,{anchor:"limits",also:["parallel","group-turns","tool-time","keep-warm"],children:e.jsx(Y,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs(J,{selectWidth:160,children:[e.jsx("div",{"data-settings-block":"group-turns",className:"contents",children:e.jsx(xh,{})}),e.jsx("div",{"data-settings-block":"tool-time",className:"contents",children:e.jsx(sh,{})}),e.jsx(kh,{}),e.jsx("div",{"data-settings-block":"keep-warm",className:"contents",children:e.jsx(ju,{})})]})})}),Js(n.config)&&e.jsx("div",{"data-settings-block":"skills",children:e.jsx(yh,{})}),e.jsx(qe,{anchor:"early",children:e.jsx("div",{"data-settings-block":"early",children:e.jsx(rm,{})})})]})}function of(){const{ctx:s,anchor:n}=Ne(),[a,i]=o.useState(n==="desktop-details");return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.desktops.browserSection"),block:"browser",children:e.jsxs(J,{children:[e.jsx(Fp,{}),e.jsx(Up,{}),e.jsx(Mp,{}),s.advanced&&e.jsx("div",{"data-settings-block":"new-browser",className:"contents",children:e.jsx(Dp,{})})]})}),e.jsx(vt,{children:e.jsx(bh,{})}),e.jsx(lm,{}),s.advanced&&e.jsx(vt,{children:e.jsx(Gd,{id:"desktop-details",block:"desktop-details",title:t("settings.desktops.detailsTitle"),subtitle:t("settings.desktops.detailsLine"),open:a,onToggle:()=>i(r=>!r),children:e.jsx("div",{className:"flex flex-col gap-6 px-4 py-4",children:e.jsx(Yr,{})})})}),e.jsx(qe,{anchor:"automation",children:e.jsx(Y,{label:t("settings.desktops.automation"),block:"automation",children:e.jsx(J,{children:e.jsx(gh,{})})})})]})}function cf(){const{ctx:s}=Ne();return!s.here||!window.ogb?.cloudSendPage?null:e.jsx(tg,{bridge:window.ogb.cloudSendPage})}function df(){return e.jsx("div",{"data-settings-block":"saved",className:"flex flex-col gap-6",children:e.jsx(Kx,{})})}function uf(){return e.jsx("div",{"data-settings-block":"summary",className:"flex flex-col gap-6",children:e.jsx(vt,{note:"settings.adminOnly.usage",children:e.jsx(Ux,{})})})}function pf(){return e.jsx(vt,{children:e.jsx(Yd,{layout:({importRow:s,exportRow:n})=>e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.data.bringIn"),block:"bring-in",children:e.jsx(nx,{children:s})}),e.jsxs(Y,{label:t("settings.data.takeOut"),block:"take-out",children:[e.jsx(J,{children:n}),e.jsx(Zm,{})]}),e.jsx(cf,{})]})})})}function mf(){const{ctx:s}=Ne();return e.jsxs(e.Fragment,{children:[e.jsx(Y,{label:t("settings.data.storage"),block:"storage",children:e.jsx(J,{children:e.jsx(Gm,{})})}),s.advanced&&e.jsx(rx,{}),!s.desktop&&s.admin&&e.jsx(Wm,{})]})}function xf(){const{ctx:s}=Ne();return e.jsxs(e.Fragment,{children:[!s.desktop&&!s.cloud&&e.jsx(Y,{label:t("settings.people.members"),block:"members",children:e.jsx(Uu,{})}),s.team&&e.jsx(Y,{label:t("settings.section.botAccess"),block:"bot-access",footnote:s.desktop?void 0:t("settings.people.activityIn"),children:e.jsx(Vm,{})})]})}function gf(){return e.jsx(Hu,{})}function hf(){const{cloud:s,bridge:n}=or(!0),a=Et(),[i,r]=o.useState(!1);if(s!=="ready"||!n)return null;const c=a.find(d=>d.kind==="cloud")??null,l=c?.name||t("cloudSetup.myCloud");return e.jsxs("div",{"data-settings-block":"pair-cloud",className:"flex flex-col gap-2",children:[e.jsx(J,{icons:!0,children:e.jsxs("button",{type:"button","data-pair-with-cloud":"",onClick:()=>{r(!1),n.connectHomeForPhone().catch(()=>r(!0))},className:"flex min-h-16 w-full cursor-pointer items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center",children:e.jsx(Li,{place:{kind:"cloud",name:l,color:c?.color??null},size:24})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("phone.pair.withPlace",{place:l})}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("phone.pair.withPlaceLine",{place:l})})]}),e.jsx(Zs,{size:12,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary"})]})}),i&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:t("cloudPhone.failed")})]})}function ff(){const{ctx:s}=Ne(),{cloud:n,bridge:a}=or(s.here),i=s.here&&n==="ready"&&!!a,r=Et("phone").filter(c=>!(i&&c.kind==="cloud"));return!s.desktop||s.client||r.length===0?null:e.jsx(Y,{label:t("settings.otherPlaces"),block:"other-places",children:e.jsx(J,{icons:!0,children:r.map(c=>e.jsx(je,{title:c.name,subtitle:t("phone.otherPlace.line",{place:c.name}),leading:e.jsx(De,{place:{kind:c.kind==="computer"?"computer":"cloud",name:c.name,color:c.color},size:24}),external:!0,onClick:c.open,data:{"data-other-place":c.key}},c.key))})})}function bf(){const{ctx:s,place:n}=Ne(),{state:a}=_(),i=a.appSettingsPhonePairing;return e.jsxs(e.Fragment,{children:[s.here?e.jsx(mu,{profileEmail:a.config?.profile?.email,focusRequest:i,simple:!s.advanced,placeName:n.name,top:e.jsx(hf,{})}):e.jsx(xu,{cloudHome:s.cloud,focusRequest:i,team:a.config?.team?.name,placeName:n.name,simple:!s.advanced,teamPhoneBlocked:a.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:a.config.managedPolicy.organizationName}):null}),e.jsx(ff,{})]})}const vf={overview:nf,phone:bf,ai:rf,bots:lf,desktops:of,vault:df,usage:uf,transfer:pf,data:mf,people:xf,installations:gf,account:Pp,plan:Tp,app:zm,general:Hm,appearance:Km};function yf({page:s}){const n=vf[s];return e.jsx(n,{})}const ki={bots:"settings.bots.intro",desktops:"settings.desktops.intro",vault:"settings.vault.intro",app:"settings.app.intro"};function jf(s){const[a="",i=""]=t("settings.scope.for",{place:""}).split("");return e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:"text-ink-secondary",children:a}),e.jsx("span",{className:"text-ink",children:s}),i&&e.jsx("span",{className:"text-ink-secondary",children:i})]})}function kf(s){return s.places&&s.desktop?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("settings.scope.everyPlace")]}):null}function wf(s){return s.kind==="computer"?`${Kt($t())} · ${t("settings.overview.updatesWithApp")}`:`${s.kind==="server"?t("settings.place.running"):t("settings.place.alwaysOn")} · ${Kt()}`}function Nf({page:s,ctx:n,place:a}){if(s.id==="overview")return e.jsxs("p",{"data-settings-scope":"",className:"flex items-center gap-1.5 text-[13px] leading-[18px] text-ink-secondary",children:[a.kind!=="computer"&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 shrink-0 rounded-full bg-success"}),wf(a)]});const i=s.owner==="place"?e.jsx(De,{place:a,size:14}):s.owner==="account"?e.jsx(Wt,{size:14}):e.jsx(hr,{size:14}),r=s.owner==="place"?jf(a.name):s.owner==="account"?n.desktop?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink",children:t("settings.scope.account",{app:ke()})}),kf(n)]}):e.jsx("span",{className:"text-ink-secondary",children:t("settings.scope.browserAccount",{place:a.name})}):n.desktop?e.jsx("span",{className:"text-ink",children:t("settings.scope.app",{app:ke()})}):e.jsx("span",{className:"text-ink-secondary",children:t("settings.scope.browser")});return e.jsxs("p",{"data-settings-scope":"",className:"flex min-w-0 items-center gap-1.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[4px]",children:i}),e.jsx("span",{className:"min-w-0 truncate",children:r})]})}function Sf({page:s,ctx:n,place:a,narrow:i,missing:r}){const c=s.id!=="app"?ki[s.id]:n.desktop?n.advanced?ki.app:"settings.app.introSimple":n.advanced?"settings.app.introBrowserAdvanced":"settings.app.introBrowser",l=s.id==="account"?t("settings.page.account"):xt(s,a,n.desktop);return e.jsxs("header",{"data-settings-header":"",className:z("flex flex-col gap-1 pb-5",i?"px-8 pt-1":"pl-4 pt-4"),children:[!i&&e.jsx("h2",{id:"settings-page-title",className:"truncate pr-12 text-[18px] font-semibold leading-6 tracking-[-0.01em] text-ink",children:l}),e.jsx(Nf,{page:s,ctx:n,place:a}),c&&e.jsx("p",{"data-settings-intro":c,className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c,{place:a.name,app:ke()})}),r&&e.jsx("p",{role:"status",className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.missingHere",{page:r,place:a.name})})]})}const Cf="(max-width: 767.98px)",Ef='button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])',wi="omb-settings-opened";function Af(){try{localStorage.getItem(wi)||localStorage.setItem(wi,String(Date.now()))}catch{}}function Pf(s,n){if(!s||!n)return;const a=s.querySelector(`[data-settings-block="${CSS.escape(n)}"]`);if(!a)return;const i=getComputedStyle(a).display==="contents"?a.firstElementChild??a:a,r=s.querySelector("[data-settings-header]");if(i!==a||a.matches("[data-setting-row], [data-setting-row] *")){const l=i.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,l-s.clientHeight/3),i.querySelector("input, select, textarea, button")?.focus({preventScroll:!0})}else dr(s,a,"start",(r?.offsetHeight??96)+8);i.setAttribute("data-settings-highlight",""),window.setTimeout(()=>i.removeAttribute("data-settings-highlight"),1200)}function Tf(){const s=co(),{state:n,dispatch:a}=_(),i=$u(),r=tr(),c=Xd(Cf,!1),l=Qd(n.appSettingsSection,i),[d,u]=o.useState(l.anchor??null),[p,x]=o.useState(n.appSettingsSection!=="overview"),[m,g]=o.useState(""),f=Zd(i),h=Dt(l.page),j=o.useRef(null),b=o.useRef(null);o.useEffect(()=>{u(l.anchor??null),x(R=>R||n.appSettingsSection!=="overview")},[n.appSettingsSection,l.anchor]),o.useEffect(()=>{const R=window.requestAnimationFrame(()=>{d?Pf(b.current,d):b.current&&(b.current.scrollTop=0)});return()=>window.cancelAnimationFrame(R)},[d,l.page]),o.useEffect(()=>{l.advanced&&Mt(!0)},[l.advanced]),o.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>g("")),[]),o.useEffect(Af,[]);const y=o.useMemo(()=>eu(m,i,R=>cn({entry:R},r,i.desktop),R=>xt(R,r,i.desktop)),[m,i,r]),v=o.useMemo(()=>i.client||!m.trim()?[]:mt.filter(R=>!ar(R.id,n.config)&&nr(R,m.trim().toLowerCase(),n.config)).slice(0,8),[i.client,m,n.config]),w=R=>{g(""),x(!0),a(R.uses?Rs(R.uses,R.id):Rs(R.id))},N=At(),C=()=>a({type:"toggleAppSettings",open:!1}),T=(R,K)=>{x(!0),R===l.page&&u(K??null),a({type:"toggleAppSettings",open:!0,section:R}),K&&window.setTimeout(()=>u(K),0)},F=R=>{const K=R.entry;if(K.jump==="apps"){C(),a({type:"togglePlugins",open:!0});return}if(K.jump==="automations"){C(),a({type:"showRoutines",view:"list"});return}if(K.jump==="shortcuts"){C(),a({type:"toggleShortcuts",open:!0});return}if(K.jump==="bot"){C();return}if(R.elsewhere){N.open?.();return}(R.advanced||au({page:K.page,anchor:K.anchor},i))&&Mt(!0),T(K.page,K.anchor)},k=R=>{!R&&!Dt(l.page).when({...i,advanced:!1})&&a({type:"toggleAppSettings",open:!0,section:"overview"}),Mt(R)};o.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null,K=j.current,te=K?.querySelector("[data-settings-search]");te?.checkVisibility()?te.focus({preventScroll:!0}):K?.focus();const ue=ae=>{if(!s()||!K||ae.defaultPrevented||[...K.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(M=>M.getClientRects().length))return;const X=K.querySelector("[data-settings-search]"),B=document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement?.isContentEditable;if(X&&(ae.key==="/"&&!B||ae.key.toLowerCase()==="f"&&(ae.metaKey||ae.ctrlKey))){ae.preventDefault(),X.focus(),X.select();return}if(ae.key==="Escape"){ae.preventDefault(),C();return}if(ae.key!=="Tab")return;const W=[...K.querySelectorAll(Ef)].filter(M=>M.checkVisibility());if(W.length===0){ae.preventDefault(),K.focus();return}const G=W[0],oe=W[W.length-1];ae.shiftKey&&(document.activeElement===G||!K.contains(document.activeElement))?(ae.preventDefault(),oe.focus()):!ae.shiftKey&&document.activeElement===oe&&(ae.preventDefault(),G.focus())};return window.addEventListener("keydown",ue),()=>{window.removeEventListener("keydown",ue),R?.focus()}},[a,s]);const S={ctx:i,place:r,page:l.page,anchor:d,go:T},P=l.missing?xt(Dt(l.missing),r,i.desktop):void 0,E=c&&!p,A=c&&typeof window<"u"&&window.innerWidth/2-16-(30+t("settings.title").length*7)<xt(h,r,i.desktop).length*9/2,V=e.jsx("button",{type:"button",onClick:C,"aria-label":t("settings.close"),title:`${t("settings.close")} (${tu("close-panel")})`,className:z("ui-icon-button z-20 size-8 shrink-0 cursor-pointer rounded-full text-ink-secondary hover:bg-menu-hover hover:text-ink",!c&&"absolute right-3 top-3"),children:e.jsx(Oe,{size:16,"aria-hidden":"true"})});return e.jsx(Ae.Provider,{value:!0,children:e.jsx(ln.Provider,{value:S,children:e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:{...nu(),"--settings-narrow-top":`${ia()===su?12:ia()}px`},onMouseDown:R=>R.target===R.currentTarget&&C(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:j,role:"dialog","data-look":"settings","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},"data-settings-page-open":l.page,"data-settings-advanced":i.advanced?"":void 0,className:"glass-surface glass-popup animate-pop-in relative flex flex-col overflow-hidden text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),c&&e.jsxs("div",{className:"flex shrink-0 flex-col",children:[e.jsx("span",{"aria-hidden":"true",className:"mx-auto mt-2 h-1 w-8 rounded-full bg-ink/15"}),e.jsxs("div",{className:"relative flex h-12 items-center justify-between gap-2 px-2",children:[E?e.jsx("h2",{className:"flex-1 px-2 text-[16px] font-semibold leading-[22px] text-ink",children:t("settings.title")}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","data-settings-back":"","aria-label":A?t("settings.backTo"):void 0,onClick:()=>{x(!1),g("")},className:z("flex h-8 shrink-0 cursor-pointer items-center gap-0.5 rounded-full text-[13px] font-medium leading-5 text-ink-secondary hover:bg-menu-hover hover:text-ink",A?"w-8 justify-center":"pl-1 pr-2"),children:[e.jsx(Ai,{size:16,"aria-hidden":"true",className:"rtl:-scale-x-100"}),!A&&t("settings.title")]}),e.jsx("h2",{className:z("pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 truncate text-center text-[16px] font-semibold leading-[22px] text-ink",A?"max-w-[calc(100%-96px)]":"max-w-[calc(100%-224px)]"),children:xt(h,r,i.desktop)})]}),V]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[(!c||E)&&e.jsx(Zu,{ctx:i,place:r,pages:f,current:c?null:l.page,query:m,hits:y,narrow:c,onQuery:g,onOpen:R=>T(R),onHit:F,keyHits:v,onKey:w,onClose:C,onAdvanced:k}),(!c||!E)&&e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[!c&&V,e.jsx("div",{ref:b,"data-settings-scroll":!0,"data-settings-content":"",className:z("settings-scroll min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]",c?"pb-12":"px-8 pb-12"),children:e.jsxs("div",{className:z("flex max-w-[640px] flex-col",c&&"max-w-none"),children:[e.jsx(Sf,{page:h,ctx:i,place:r,narrow:c,missing:P}),e.jsxs("div",{"data-settings-page-body":l.page,className:z("flex flex-col gap-6",c&&"px-4"),children:[e.jsx(Tu,{config:n.config}),h.owner==="place"&&n.config===null?n.error?e.jsx(gu,{place:r.name,onRetry:()=>{D("/api/config").then(R=>a({type:"configStatus",config:R})).catch(()=>{})}}):e.jsxs(e.Fragment,{children:[e.jsx(ca,{place:r.name}),e.jsx(ca,{place:r.name})]}):e.jsx(yf,{page:l.page})]},l.page)]})})]})]})]})]})})})}function tb(){return e.jsx(Oi,{modal:!0,children:e.jsx(Tf,{})})}export{tb as SettingsModal};
|