openmausbot 0.1.98 → 0.1.99
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-H6D3SD39.js → ActivityPanel-CgUgtumZ.js} +1 -1
- package/dist/assets/BotSettingsDialog-lJj6oiir.js +7 -0
- package/dist/assets/{CloudBackendPicker-iezpJFpF.js → CloudBackendPicker-C5-_arUz.js} +1 -1
- package/dist/assets/{ComputerPanel-DZPj-IWu.js → ComputerPanel-euJ2CSlH.js} +1 -1
- package/dist/assets/{DesktopViewer-utONms1p.js → DesktopViewer-XCln1Pn_.js} +1 -1
- package/dist/assets/InspectorPanel-DKYyQZlo.js +5 -0
- package/dist/assets/{KeyboardShortcutsModal-gk9mvHj_.js → KeyboardShortcutsModal-DkkZWZRI.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-DLIvd2kC.js → LocalVmWorkspace-Cwt3_XSx.js} +1 -1
- package/dist/assets/{MacLocalControl-bJv8yiPB.js → MacLocalControl-B28RbdCS.js} +1 -1
- package/dist/assets/NewBotDialog-dMWDs5xm.js +2 -0
- package/dist/assets/RemoteAgentSettingsPanel-B5KWXnqH.js +1 -0
- package/dist/assets/RoutinesPage-DOosRYDK.js +1 -0
- package/dist/assets/{RoutinesSection-Dny9ra-c.js → RoutinesSection-uOfOTfkB.js} +1 -1
- package/dist/assets/{SettingsModal-gC6XJJmt.js → SettingsModal-BTGkFbj1.js} +3 -3
- package/dist/assets/{TeamMapPage-B6fuu4r_.js → TeamMapPage-DqNdJn96.js} +1 -1
- package/dist/assets/{TriggersPanel-j0qTP2CO.js → TriggersPanel-c6xkG9mi.js} +1 -1
- package/dist/assets/{VisibilitySection-DT0FqPvu.js → VisibilitySection-DD4ffIR5.js} +1 -1
- package/dist/assets/WebhooksPanel-Cz17K-_O.js +3 -0
- package/dist/assets/{abnfDiagram-O67JEVCF-BsjcFX0-.js → abnfDiagram-O67JEVCF-CX6tDpkg.js} +1 -1
- package/dist/assets/{activity-BxOkayvD.js → activity-BAVWO0Zj.js} +1 -1
- package/dist/assets/{arc-CJNA94c6.js → arc-h45-9NFk.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-dz2ud7lP.js → architectureDiagram-NJMV4G6O-CgLFXbg6.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-ChBEALoR.js → blockDiagram-BEXU5L5S-DGDFFc9M.js} +1 -1
- package/dist/assets/{brain-CFZ7PEXc.js → brain-CeCdoTb2.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-KZNRKDQe.js → c4Diagram-YGBWAQC7-B9aklAUj.js} +1 -1
- package/dist/assets/channel-TsOXCiPg.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-BLLwmCET.js → chunk-2Q5K7J3B-BC0KmWsM.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-CQxyreBZ.js → chunk-3FUC2YCW-BbDFHsJ1.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-D6sFMW0u.js → chunk-5VM5RSS4-DtGbsjOM.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-BaZ1YgLF.js → chunk-GTNCS2PH-VMghMcEl.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-CcalphmC.js → chunk-GWA4HPMP-BP_JyGWQ.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CSk8R3ve.js → chunk-JWPE2WC7-CYFyzgAU.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-CTmLjA57.js → chunk-NETBCI7D-DBNa_kqm.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-CM9Z77Ne.js → chunk-WEXAMYUT-BKEeM7CJ.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-B1fxpMS2.js → chunk-XXDRQBXY-C__m3ZXl.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-DCCyoLpj.js → classDiagram-v2-NBCMYWYE-CBUrTSAX.js} +1 -1
- package/dist/assets/core-6lvx-ypA.js +12 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-KyImBKvE.js → cose-bilkent-JH36ORCC-GRfL-1Vb.js} +1 -1
- package/dist/assets/cpp-DddhVWhK.js +1 -0
- package/dist/assets/{cynefin-OW5HDTMX-fsZc6MGa.js → cynefin-OW5HDTMX-LopwGUjm.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-CGmHsShB.js → cynefinDiagram-VND7K2PF-DSB8ZRNS.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-Dah1h-CH.js → dagre-6A5THRUB-DL3Kgdfk.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BIu71OyV.js → diagram-22UHCM2B-DIxN34BM.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-gxhUB_Mu.js → diagram-3UASUU5V-CJnSvXaI.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-CBhusUBn.js → diagram-ATOU4E4O-C-XF-lO8.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-BdPrc86x.js → diagram-CDSNMT55-Df2yZPi_.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-Clp110R_.js → diagram-MLGK6HIB-BBs9oZFs.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-DJKfbugw.js → diagram-MPIPVDR6-CEbK11mM.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-DnsltoBu.js → ebnfDiagram-ZINNZB2B-BNq6Yv3C.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-jWdq6gqH.js → elk-276RUBZZ-CFbQ2bGm.js} +1 -1
- package/dist/assets/engine-javascript-D5Xfc425.js +141 -0
- package/dist/assets/{erDiagram-OPXOYQCR-DArPVf8u.js → erDiagram-OPXOYQCR-Bz8vmjN4.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-D2HZ-2f7.js → flowDiagram-KWPJA3E3-cQUfEYrx.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP--o0KIxEo.js → ganttDiagram-FUAMR5RP-BY8n9tbI.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-CsoXr2D7.js → gitGraphDiagram-X574FWY7-KduSOMDN.js} +1 -1
- package/dist/assets/{image-plus-BbVjGHin.js → image-plus-DNIWU160.js} +1 -1
- package/dist/assets/{index-C3NqfdVU.js → index-C8xb62XS.js} +205 -205
- package/dist/assets/{index-BrPW5HDO.css → index-DbN_Hfjs.css} +1 -1
- package/dist/assets/{infoDiagram-VRGFBTTK-g-6lNp7r.js → infoDiagram-VRGFBTTK-xBKgUkpL.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-B1d6qVTV.js → ishikawaDiagram-OU5B5YK6-_ei09tAJ.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-BTPuiU6T.js → journeyDiagram-ZHPQQLJL-Fp49MkSp.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-bDDuRJvP.js → kanban-definition-PNTS6WVX-CY9lLm7V.js} +1 -1
- package/dist/assets/{linear-BVVKbEMy.js → linear-D2ai4eM2.js} +1 -1
- package/dist/assets/{mermaid.core-JJdoKyKB.js → mermaid.core-DP6qPqu1.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-B4aE3T0q.js → mindmap-definition-NLK3R4M7-g1ynEw_d.js} +1 -1
- package/dist/assets/{page-visible-BBo_Zm8g.js → page-visible-BZn8304W.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-DFKQWpR7.js → pegDiagram-GJSIUBJH-Bt4ObsZj.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-Iv7OKVJi.js → pieDiagram-5QR66LMP-CeLld8bY.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-U2YnfwBk.js → quadrantDiagram-O4NWA36T-D4WWZw3x.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-CuPy6RqM.js → railroadDiagram-XR7U4H2S-D95P5NqU.js} +1 -1
- package/dist/assets/{remote-desktop-panel-BNEj7tUx.js → remote-desktop-panel-DOIMmT4T.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-bMI5AK7T.js → requirementDiagram-PLB6GJNP-D12p3RhR.js} +1 -1
- package/dist/assets/ruby-Ct1eTYOr.js +1 -0
- package/dist/assets/{sankeyDiagram-IPEJSGJF-BKcFE2WQ.js → sankeyDiagram-IPEJSGJF-Co26Dwcs.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-Bn9q88kl.js → sequenceDiagram-PO4LG4MO-y5YxaDKt.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-Cvmdq9HD.js → sizeCapture-INFHLROL-D49hZ8U5.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-JJQYw3eQ.js → stateDiagram-v2-GCMORJYK-C0sylr-r.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-BkSCBEwp.js → swimlanes-2SLR337P-DmRWsDIs.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-DzhbBHtd.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-DsaM4GHr.js → timeline-definition-EJHVYXUP-DVmHYs3w.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-3FOwLq7B.js → usecaseDiagram-POWQR4AR-BQ1q0VV6.js} +1 -1
- package/dist/assets/{user-DcZBnAuv.js → user-B9lohN4n.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-DyNjJsKt.js → vennDiagram-UO4OBE2U-C_cnfST0.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-Y4ZMcnBC.js → wardleyDiagram-VNRHLVJA-Bb3BSu12.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-BXZpg955.js → xychartDiagram-PMCCYNJV-CcwEuuEi.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/drivers/agents-proxy.js +10 -9
- package/dist-server/index.js +1474 -807
- package/dist-server/openmausbot.js +248 -152
- package/dist-server/pair-cli.js +248 -152
- package/dist-server/server/activity.js +2 -0
- package/dist-server/server/checkpoints.js +55 -39
- package/dist-server/server/direct-apply.js +20 -0
- package/dist-server/server/drivers/agents-call.js +1 -1
- package/dist-server/server/drivers/agents-catalog.js +11 -8
- package/dist-server/server/drivers/codex.js +147 -24
- package/dist-server/server/drivers/device-auth.js +5 -4
- package/dist-server/server/drivers/openai-chat.js +5 -4
- package/dist-server/server/harness/registry.js +63 -45
- package/dist-server/server/index.js +203 -23
- package/dist-server/server/mcp-oauth.js +125 -47
- package/dist-server/server/message-file.js +95 -3
- package/dist-server/server/model-requests.js +55 -4
- package/dist-server/server/profile-requests.js +80 -4
- package/dist-server/server/request-auth.js +1 -0
- package/dist-server/server/routes/undo.js +17 -0
- package/dist-server/server/routine-requests.js +210 -6
- package/dist-server/server/setup-mode.js +1 -1
- package/dist-server/server/skill-learn.js +2 -2
- package/dist-server/server/skills.js +30 -0
- package/dist-server/server/system-prompt.js +1 -1
- package/dist-server/server/turn-continuation.js +13 -18
- package/dist-server/server/workspace-backup.js +6 -1
- package/dist-server/workspace-backup.worker.js +1 -1
- package/package.json +1 -1
- package/skills/create-verification-skill/SKILL.md +9 -8
- package/skills/create-verification-skill/manifest.json +1 -1
- package/dist/assets/BotSettingsDialog-Dqz_AiBZ.js +0 -7
- package/dist/assets/InspectorPanel-OVaBVrzC.js +0 -5
- package/dist/assets/NewBotDialog-1qGOAdUM.js +0 -2
- package/dist/assets/RemoteAgentSettingsPanel-DqKr0HkO.js +0 -1
- package/dist/assets/RoutinesPage-BM2D4qGi.js +0 -1
- package/dist/assets/WebhooksPanel--YQyCjKO.js +0 -3
- package/dist/assets/abap-BdImnpbu.js +0 -1
- package/dist/assets/actionscript-3-B3316cI-.js +0 -1
- package/dist/assets/ada-bCR0ucgS.js +0 -1
- package/dist/assets/ahk-CsyLZFj1.js +0 -1
- package/dist/assets/ahk2-8Zs4aa1G.js +0 -1
- package/dist/assets/andromeeda-C4gqWexZ.js +0 -1
- package/dist/assets/angular-html-DA-rfuFy.js +0 -1
- package/dist/assets/angular-ts-BrjP3tb8.js +0 -1
- package/dist/assets/apache-Pmp26Uib.js +0 -1
- package/dist/assets/apex-DhZFqWV2.js +0 -1
- package/dist/assets/apl-CORt7UWP.js +0 -1
- package/dist/assets/applescript-Co6uUVPk.js +0 -1
- package/dist/assets/ara-BRHolxvo.js +0 -1
- package/dist/assets/asciidoc-CSVQ5wI8.js +0 -1
- package/dist/assets/asm-D_Q5rh1f.js +0 -1
- package/dist/assets/astro-HNnZUWAn.js +0 -1
- package/dist/assets/aurora-x-D-2ljcwZ.js +0 -1
- package/dist/assets/awk-DMzUqQB5.js +0 -1
- package/dist/assets/ayu-dark-DYE7WIF3.js +0 -1
- package/dist/assets/ayu-light-BA47KaF1.js +0 -1
- package/dist/assets/ayu-mirage-32ctXXKs.js +0 -1
- package/dist/assets/ballerina-BFfxhgS-.js +0 -1
- package/dist/assets/bat-CickPsom.js +0 -1
- package/dist/assets/beancount-k_qm7-4y.js +0 -1
- package/dist/assets/berry-uYugtg8r.js +0 -1
- package/dist/assets/bibtex-CHM0blh-.js +0 -1
- package/dist/assets/bicep-Bmn6On1c.js +0 -1
- package/dist/assets/bird2-Bx8U0n9b.js +0 -1
- package/dist/assets/blade-2xfisSek.js +0 -1
- package/dist/assets/bsl-DlhNcFeZ.js +0 -1
- package/dist/assets/c3-Dp5svz6Z.js +0 -1
- package/dist/assets/cadence-Bv_4Rxtq.js +0 -1
- package/dist/assets/cairo-KRGpt6FW.js +0 -1
- package/dist/assets/catppuccin-frappe-CZL1YF0i.js +0 -1
- package/dist/assets/catppuccin-latte-DH-8KZSZ.js +0 -1
- package/dist/assets/catppuccin-macchiato-B7yYVSCf.js +0 -1
- package/dist/assets/catppuccin-mocha-Ct7hS0mc.js +0 -1
- package/dist/assets/channel-WhFyujhZ.js +0 -1
- package/dist/assets/chapel-DTp_pixX.js +0 -1
- package/dist/assets/clarity-Dn5IMItf.js +0 -1
- package/dist/assets/clojure-P80f7IUj.js +0 -1
- package/dist/assets/cmake-D1j8_8rp.js +0 -1
- package/dist/assets/cobol-nBiQ_Alo.js +0 -1
- package/dist/assets/codeowners-Bp6g37R7.js +0 -1
- package/dist/assets/codeql-DsOJ9woJ.js +0 -1
- package/dist/assets/coffee-Ch7k5sss.js +0 -1
- package/dist/assets/common-lisp-Cg-RD9OK.js +0 -1
- package/dist/assets/coq-C7JzOVbR.js +0 -1
- package/dist/assets/cpp-BMRokrvK.js +0 -1
- package/dist/assets/crystal-DGywbUpC.js +0 -1
- package/dist/assets/csv-fuZLfV_i.js +0 -1
- package/dist/assets/cue-D82EKSYY.js +0 -1
- package/dist/assets/cypher-COkxafJQ.js +0 -1
- package/dist/assets/d-85-TOEBH.js +0 -1
- package/dist/assets/dark-plus-C3mMm8J8.js +0 -1
- package/dist/assets/dax-CEL-wOlO.js +0 -1
- package/dist/assets/desktop-BmXAJ9_W.js +0 -1
- package/dist/assets/dotenv-Da5cRb03.js +0 -1
- package/dist/assets/dracula-BzJJZx-M.js +0 -1
- package/dist/assets/dracula-soft-BXkSAIEj.js +0 -1
- package/dist/assets/dream-maker-BtqSS_iP.js +0 -1
- package/dist/assets/edge-FbVlp4U3.js +0 -1
- package/dist/assets/elixir-CkH2-t6x.js +0 -1
- package/dist/assets/elm-DbKCFpqz.js +0 -1
- package/dist/assets/emacs-lisp-C_m_b--Z.js +0 -1
- package/dist/assets/erb-DXfck5VN.js +0 -1
- package/dist/assets/erlang-DsQrWhSR.js +0 -1
- package/dist/assets/everforest-dark-BgDCqdQA.js +0 -1
- package/dist/assets/everforest-light-C8M2exoo.js +0 -1
- package/dist/assets/fennel-BYunw83y.js +0 -1
- package/dist/assets/fluent-C4IJs8-o.js +0 -1
- package/dist/assets/fortran-fixed-form-CkoXwp7k.js +0 -1
- package/dist/assets/fortran-free-form-BxgE0vQu.js +0 -1
- package/dist/assets/fsharp-CXgrBDvD.js +0 -1
- package/dist/assets/gdresource-TyuKm33G.js +0 -1
- package/dist/assets/gdscript-DqcFQ5yU.js +0 -1
- package/dist/assets/gdshader-DkwncUOv.js +0 -1
- package/dist/assets/genie-D0YGMca9.js +0 -1
- package/dist/assets/gherkin-DyxjwDmM.js +0 -1
- package/dist/assets/git-commit-F4YmCXRG.js +0 -1
- package/dist/assets/git-rebase-r7XF79zn.js +0 -1
- package/dist/assets/github-dark-DHJKELXO.js +0 -1
- package/dist/assets/github-dark-dimmed-DH5Ifo-i.js +0 -1
- package/dist/assets/github-dark-high-contrast-E3gJ1_iC.js +0 -1
- package/dist/assets/github-light-DAi9KRSo.js +0 -1
- package/dist/assets/github-light-high-contrast-BfjtVDDH.js +0 -1
- package/dist/assets/gleam-BspZqrRM.js +0 -1
- package/dist/assets/glimmer-js-ByusRIyA.js +0 -1
- package/dist/assets/glimmer-ts-BfAWNZQY.js +0 -1
- package/dist/assets/glsl-DplSGwfg.js +0 -1
- package/dist/assets/gn-n2N0HUVH.js +0 -1
- package/dist/assets/gnuplot-DdkO51Og.js +0 -1
- package/dist/assets/groovy-gcz8RCvz.js +0 -1
- package/dist/assets/gruvbox-dark-hard-CFHQjOhq.js +0 -1
- package/dist/assets/gruvbox-dark-medium-GsRaNv29.js +0 -1
- package/dist/assets/gruvbox-dark-soft-CVdnzihN.js +0 -1
- package/dist/assets/gruvbox-light-hard-CH1njM8p.js +0 -1
- package/dist/assets/gruvbox-light-medium-DRw_LuNl.js +0 -1
- package/dist/assets/gruvbox-light-soft-hJgmCMqR.js +0 -1
- package/dist/assets/hack-BWmVpMyf.js +0 -1
- package/dist/assets/haml-D5jkg6IW.js +0 -1
- package/dist/assets/handlebars-BpdQsYii.js +0 -1
- package/dist/assets/haskell-Df6bDoY_.js +0 -1
- package/dist/assets/haxe-CfZj7gIn.js +0 -1
- package/dist/assets/hcl-BWvSN4gD.js +0 -1
- package/dist/assets/hjson-D5-asLiD.js +0 -1
- package/dist/assets/hlsl-D3lLCCz7.js +0 -1
- package/dist/assets/horizon-BUw7H-hv.js +0 -1
- package/dist/assets/horizon-bright-CUuTKBJd.js +0 -1
- package/dist/assets/houston-DnULxvSX.js +0 -1
- package/dist/assets/html-derivative-DlHx6ybY.js +0 -1
- package/dist/assets/http-jrhK8wxY.js +0 -1
- package/dist/assets/hurl-irOxFIW8.js +0 -1
- package/dist/assets/hxml-2-FPmUDs.js +0 -1
- package/dist/assets/hy-DFXneXwc.js +0 -1
- package/dist/assets/imba-DGztddWO.js +0 -1
- package/dist/assets/index-CJTp9JEp.js +0 -153
- package/dist/assets/ini-BEwlwnbL.js +0 -1
- package/dist/assets/jinja-f2NsQr07.js +0 -1
- package/dist/assets/jison-wvAkD_A8.js +0 -1
- package/dist/assets/jsonl-DcaNXYhu.js +0 -1
- package/dist/assets/jsonnet-DFQXde-d.js +0 -1
- package/dist/assets/jssm-C2t-YnRu.js +0 -1
- package/dist/assets/julia-5Bft2YPA.js +0 -1
- package/dist/assets/just-Cwhn7H3k.js +0 -1
- package/dist/assets/kanagawa-dragon-BuwD2xS4.js +0 -1
- package/dist/assets/kanagawa-lotus-C3DzagqV.js +0 -1
- package/dist/assets/kanagawa-wave-DFGoQZhC.js +0 -1
- package/dist/assets/kdl-DV7GczEv.js +0 -1
- package/dist/assets/kusto-wEQ09or8.js +0 -1
- package/dist/assets/laserwave-DUszq2jm.js +0 -1
- package/dist/assets/latex-D5pSuvFb.js +0 -1
- package/dist/assets/lean-BZvkOJ9d.js +0 -1
- package/dist/assets/light-plus-B7mTdjB0.js +0 -1
- package/dist/assets/liquid-C0sCDyMI.js +0 -1
- package/dist/assets/llvm-BZoOZj88.js +0 -1
- package/dist/assets/log-2UxHyX5q.js +0 -1
- package/dist/assets/logo-BtOb2qkB.js +0 -1
- package/dist/assets/luau-BnpPk5vE.js +0 -1
- package/dist/assets/marko-DjSrsDqO.js +0 -1
- package/dist/assets/material-theme-D5KoaKCx.js +0 -1
- package/dist/assets/material-theme-darker-BfHTSMKl.js +0 -1
- package/dist/assets/material-theme-lighter-B0m2ddpp.js +0 -1
- package/dist/assets/material-theme-ocean-CyktbL80.js +0 -1
- package/dist/assets/material-theme-palenight-Csfq5Kiy.js +0 -1
- package/dist/assets/matlab-D7o27uSR.js +0 -1
- package/dist/assets/mdc-D1_yUvq7.js +0 -1
- package/dist/assets/mermaid-CQcHuHx7.js +0 -1
- package/dist/assets/min-dark-CafNBF8u.js +0 -1
- package/dist/assets/min-light-CTRr51gU.js +0 -1
- package/dist/assets/mipsasm-CKIfxQSi.js +0 -1
- package/dist/assets/mojo-DJz3ZmWd.js +0 -1
- package/dist/assets/monokai-BRVnQi9A.js +0 -1
- package/dist/assets/moonbit-CHtswR0a.js +0 -1
- package/dist/assets/move-el3G9tDJ.js +0 -1
- package/dist/assets/narrat-DRg8JJMk.js +0 -1
- package/dist/assets/nextflow-C-mBbutL.js +0 -1
- package/dist/assets/nextflow-groovy-vE_lwT2v.js +0 -1
- package/dist/assets/nginx-BpAMiNFr.js +0 -1
- package/dist/assets/night-owl-C39BiMTA.js +0 -1
- package/dist/assets/night-owl-light-CMTm3GFP.js +0 -1
- package/dist/assets/nim-BIad80T-.js +0 -1
- package/dist/assets/nix-CwoSXNpI.js +0 -1
- package/dist/assets/nord-Ddv68eIx.js +0 -1
- package/dist/assets/nsis-BlV79W_Q.js +0 -1
- package/dist/assets/nushell-D3jzshHO.js +0 -1
- package/dist/assets/objective-c-DXmwc3jG.js +0 -1
- package/dist/assets/objective-cpp-CLxacb5B.js +0 -1
- package/dist/assets/ocaml-C0hk2d4L.js +0 -1
- package/dist/assets/odin-BBf5iR-q.js +0 -1
- package/dist/assets/one-dark-pro-DVMEJ2y_.js +0 -1
- package/dist/assets/one-light-C3Wv6jpd.js +0 -1
- package/dist/assets/openscad-C4EeE6gA.js +0 -1
- package/dist/assets/org-DM6o9KBp.js +0 -1
- package/dist/assets/pascal-D93ZcfNL.js +0 -1
- package/dist/assets/perl-B9cMNwum.js +0 -1
- package/dist/assets/pkl-u5AG7uiY.js +0 -1
- package/dist/assets/plastic-3e1v2bzS.js +0 -1
- package/dist/assets/plsql-ChMvpjG-.js +0 -1
- package/dist/assets/po-BTJTHyun.js +0 -1
- package/dist/assets/poimandres-CS3Unz2-.js +0 -1
- package/dist/assets/polar-C0HS_06l.js +0 -1
- package/dist/assets/postcss-CXtECtnM.js +0 -1
- package/dist/assets/powerquery-CEu0bR-o.js +0 -1
- package/dist/assets/prisma-Vru482bI.js +0 -1
- package/dist/assets/prolog-CbFg5uaA.js +0 -1
- package/dist/assets/pug-DKIMFp6K.js +0 -1
- package/dist/assets/puppet-BMWR74SV.js +0 -1
- package/dist/assets/purescript-CklMAg4u.js +0 -1
- package/dist/assets/qml-3beO22l8.js +0 -1
- package/dist/assets/qmldir-C8lEn-DE.js +0 -1
- package/dist/assets/qss-IeuSbFQv.js +0 -1
- package/dist/assets/racket-BqYA7rlc.js +0 -1
- package/dist/assets/raku-DXvB9xmW.js +0 -1
- package/dist/assets/razor-BjBPvh-w.js +0 -1
- package/dist/assets/rbs-CpoqiR4B.js +0 -1
- package/dist/assets/red-hvxz__6c.js +0 -1
- package/dist/assets/reg-C-SQnVFl.js +0 -1
- package/dist/assets/regexp-CDVJQ6XC.js +0 -1
- package/dist/assets/rel-C3B-1QV4.js +0 -1
- package/dist/assets/riscv-BM1_JUlF.js +0 -1
- package/dist/assets/ron-D8l8udqQ.js +0 -1
- package/dist/assets/rose-pine-5qJOZa0Y.js +0 -1
- package/dist/assets/rose-pine-dawn-zx0QlTCp.js +0 -1
- package/dist/assets/rose-pine-moon-C9pEdX9L.js +0 -1
- package/dist/assets/rosmsg-BJDFO7_C.js +0 -1
- package/dist/assets/rst-bs7f0vWN.js +0 -1
- package/dist/assets/ruby-C0TQ7zu5.js +0 -1
- package/dist/assets/sas-DEy46yEz.js +0 -1
- package/dist/assets/scala-CqE71os6.js +0 -1
- package/dist/assets/scheme-C98Dy4si.js +0 -1
- package/dist/assets/sdbl-DVxCFoDh.js +0 -1
- package/dist/assets/shaderlab-Dg9Lc6iA.js +0 -1
- package/dist/assets/shellsession-BADoaaVG.js +0 -1
- package/dist/assets/slack-dark-BthQWCQV.js +0 -1
- package/dist/assets/slack-ochin-DqwNpetd.js +0 -1
- package/dist/assets/smalltalk-BOQMe2GC.js +0 -1
- package/dist/assets/smithy-cds9vsN8.js +0 -1
- package/dist/assets/snazzy-light-Bw305WKR.js +0 -1
- package/dist/assets/solarized-dark-CpvCGNkr.js +0 -1
- package/dist/assets/solarized-light-Dlz6yCKv.js +0 -1
- package/dist/assets/solidity-DijEV5ha.js +0 -1
- package/dist/assets/soy-8wufbnw4.js +0 -1
- package/dist/assets/sparql-rVzFXLq3.js +0 -1
- package/dist/assets/splunk-BtCnVYZw.js +0 -1
- package/dist/assets/ssh-config-_ykCGR6B.js +0 -1
- package/dist/assets/stata-DI20mbqo.js +0 -1
- package/dist/assets/stylus-BEDo0Tqx.js +0 -1
- package/dist/assets/surrealql-Cjom0U5J.js +0 -1
- package/dist/assets/svelte-Cy7k_4gC.js +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-CmTirbVT.js +0 -8
- package/dist/assets/synthwave-84-CbfX1IO0.js +0 -1
- package/dist/assets/system-verilog-0hqHdDBg.js +0 -1
- package/dist/assets/systemd-4A_iFExJ.js +0 -1
- package/dist/assets/talonscript-CkByrt1z.js +0 -1
- package/dist/assets/tasl-QIJgUcNo.js +0 -1
- package/dist/assets/tcl-dwOrl1Do.js +0 -1
- package/dist/assets/templ-DhtptRzy.js +0 -1
- package/dist/assets/terraform-BETggiCN.js +0 -1
- package/dist/assets/tex-D96PA37w.js +0 -1
- package/dist/assets/tokyo-night-hegEt444.js +0 -1
- package/dist/assets/ts-tags-D351s5mN.js +0 -1
- package/dist/assets/tsv-B_m7g4N7.js +0 -1
- package/dist/assets/turtle-BsS91CYL.js +0 -1
- package/dist/assets/twig-27uCiNez.js +0 -1
- package/dist/assets/typespec-CAFt9gP4.js +0 -1
- package/dist/assets/typst-BUadGCkm.js +0 -1
- package/dist/assets/v-BGw2Nkan.js +0 -1
- package/dist/assets/vala-CsfeWuGM.js +0 -1
- package/dist/assets/vb-Cu-pLBUe.js +0 -1
- package/dist/assets/verilog-nZwndyjY.js +0 -1
- package/dist/assets/vesper-DRje8inN.js +0 -1
- package/dist/assets/vhdl-CeAyd5Ju.js +0 -1
- package/dist/assets/viml-CJc9bBzg.js +0 -1
- package/dist/assets/vitesse-black-Bkuqu6BP.js +0 -1
- package/dist/assets/vitesse-dark-D0r3Knsf.js +0 -1
- package/dist/assets/vitesse-light-CVO1_9PV.js +0 -1
- package/dist/assets/vue-BqiEGhQt.js +0 -1
- package/dist/assets/vue-html-AaS7Mt5G.js +0 -1
- package/dist/assets/vue-vine-BoDAl6tE.js +0 -1
- package/dist/assets/vyper-CDx5xZoG.js +0 -1
- package/dist/assets/wasm-CG6Dc4jp.js +0 -1
- package/dist/assets/wenyan-BV7otONQ.js +0 -1
- package/dist/assets/wgsl-Dx-B1_4e.js +0 -1
- package/dist/assets/wikitext-BhOHFoWU.js +0 -1
- package/dist/assets/wit-5i3qLPDT.js +0 -1
- package/dist/assets/wolfram-lXgVvXCa.js +0 -1
- package/dist/assets/xsl-CtQFsRM5.js +0 -1
- package/dist/assets/zenscript-DVFEvuxE.js +0 -1
- package/dist/assets/zig-VOosw3JB.js +0 -1
- /package/dist/assets/{shellscript-Yzrsuije.js → bash-Yzrsuije.js} +0 -0
- /package/dist/assets/{docker-BcOcwvcX.js → dockerfile-BcOcwvcX.js} +0 -0
- /package/dist/assets/{make-CHLpvVh8.js → makefile-CHLpvVh8.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{k as Ne,u as K,r,j as e,t,cg as te,q as Y,ch as L,c as _,d as H,o as oe,E as Ze,g as U,aH as sn,aT as ds,P as De,R as xe,ci as Re,aK as Ge,cj as nn,ck as an,cl as rn,cm as ln,aq as on,cn as At,co as $e,cp as us,cq as cn,cr as dn,cs as un,ct as It,cu as xn,a7 as pn,N as ke,a3 as mn,bc as gn,T as we,v as mt,cv as hn,cw as xs,cx as fn,cy as Ye,cz as bn,ae as Pt,cA as yn,b9 as vn,cB as jn,cC as Rt,cD as kn,as as ps,cE as ms,cF as Nn,at as wn,x as Sn,aZ as le,a_ as ue,p as Cn,cG as gs,a8 as En,au as An,w as ut,cH as hs,X as Ue,cI as fs,cJ as bs,bf as In,cK as Pn,bF as Rn,cL as Bn,cM as Te,av as Dn,cN as Tn,cO as zn,cP as Mn,cQ as ys,aV as vs,aW as je,aX as Be,aU as On,cR as Un,B as Ln,aY as Bt,a$ as _n,S as js,cS as Fn,cT as $n,cU as Kn,cV as Hn,cW as Vn,cX as Wn,ar as qn,cY as Dt,cZ as Jn,c_ as Gn,c$ as Tt,b7 as ks,ah as Yn,d0 as Xn,d1 as Qn,Z as Zn,aE as ea,bW as ot,M as Ns,d2 as ta,aD as sa,d3 as na,bY as zt,d4 as aa,n as ia,aO as ra,d5 as la,d6 as oa,d7 as ca,d8 as da,bo as ws,bn as ua,bb as xa,bX as pa,by as ma,d9 as ga,da as ha,db as fa,dc as ba,dd as ya,de as va,df as ja,dg as ka,dh as Na,di as wa,dj as Sa,dk as Ca,dl as Ea,dm as Aa,dn as Ia,dp as Pa,dq as Ra,dr as Ba,ds as Da,dt as Ta,du as za,dv as Ma,dw as Oa,dx as Ua,dy as La,dz as _a,dA as Fa,dB as $a,dC as Ka,dD as Ha,dE as Va}from"./index-C3NqfdVU.js";import{a as Wa,M as qa,w as Ja,A as me,b as Ga,O as Ya,V as Xa,c as Qa,B as Za}from"./MacLocalControl-bJv8yiPB.js";import{a as ei,A as ti,w as si,d as ni,b as Mt}from"./activity-BxOkayvD.js";import{b as ai}from"./RoutinesPage-BM2D4qGi.js";import{DefaultBotSettings as ii}from"./NewBotDialog-1qGOAdUM.js";import{U as xt,C as ri}from"./user-DcZBnAuv.js";import"./WebhooksPanel--YQyCjKO.js";import"./VisibilitySection-DT0FqPvu.js";import"./image-plus-BbVjGHin.js";import"./CloudBackendPicker-iezpJFpF.js";const li=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]],oi=Ne("circle-user",li);const ci=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],di=Ne("hard-drive",ci);const ui=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ss=Ne("palette",ui);const xi=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],pi=Ne("scroll-text",xi);const mi=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],gi=Ne("server",mi);const hi=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],fi=Ne("terminal",hi);const bi=[["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"}]],yi=Ne("unplug",bi),vi="https://typesafe.ai",ji={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"},Ot={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"};function ki(s,n=!1){if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Ot[s.reason])return t(Ot[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const a=ji[s.reason];return a?t(a):t("decider.error.other")}const Ni=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function wi(){const{state:s,dispatch:n}=K(),a=s.config?.decider,i=a?.configured??!1,o=i&&a?.included===!0,l=i&&!o,d=a?.enabled??!1,u=a?.jobs.roomRouting??!0,[c,x]=r.useState(""),[m,g]=r.useState(!1),[p,y]=r.useState(!1),[k,N]=r.useState(!1),[v,j]=r.useState(null),[E,w]=r.useState(null),D=c.trim(),I=!D&&l,f=A=>n({type:"configStatus",config:A}),b=async A=>{if(!p){y(!0),j(null);try{f(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:A})}))}catch(P){j(P instanceof Error?P.message:String(P))}finally{y(!1)}}},h=async()=>{if(!(m||!D&&!l)){g(!0),j(null),w(null);try{const A=window.ogb?.setCredential?await window.ogb.setCredential("jevApiKey",D):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{key:D}})});f(A),x("")}catch(A){j(A instanceof Error?A.message:String(A))}finally{g(!1)}}},C=async()=>{if(k||m||!D&&!i)return;N(!0),w(null),j(null);const A=!D&&o;try{const P=await U("/api/decider/test",{method:"POST",body:JSON.stringify(D?{key:D}:{})});w(P.ok?{ok:!0,text:t("decider.test.ok",{ms:String(P.latencyMs)})}:{ok:!1,text:ki(P,A)})}catch(P){w({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("div",{children:e.jsx(te,{title:t("decider.master"),subtitle:i?void 0:t("decider.masterNeedsKey"),children:e.jsx(Y,{"data-testid":"decider-master","aria-label":t("decider.master"),checked:d,disabled:!i||p||!s.config,onClick:()=>{b({enabled:!d})},className:"cursor-pointer"})})}),e.jsxs(L,{title:t("decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:_("size-1.5 rounded-full",i?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:i?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):i?t("decider.status.connected"):t("decider.status.notConnected")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:c,onChange:A=>{w(null),j(null),x(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void h(),disabled:m,placeholder:l?t("keys.replace"):t("decider.key.placeholder"),"aria-label":t("decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{h()},disabled:m||!D&&!l,title:I?t("keys.removeKey"):t("common.save"),className:_("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",I?"text-danger":"text-ink"),children:m?e.jsx(H,{size:13,className:"animate-spin"}):I?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{C()},disabled:k||m||!D&&!i,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:k?t("keys.testing"):t("keys.test")})]}),v&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:v}),E&&e.jsx("p",{role:"status",className:_("mt-1 text-[12px]",E.ok?"text-success":"text-danger"),children:E.text}),e.jsxs("a",{href:vi,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.key.getKey"),e.jsx(Ze,{size:11,"aria-hidden":"true"})]})]}),e.jsx(L,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(Y,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:d&&u,disabled:!d||p,onClick:()=>{b({jobs:{roomRouting:!u}})},className:"cursor-pointer"})]}),Ni.map(A=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(A)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},A))]})})]})}const Cs=["openai","anthropic","google","azure","aws","xai","deepseek","meta","mistral","qwen","moonshot","cohere","openrouter"],Es=128*1024,fe=1024,As=["image/png","image/jpeg","image/webp"],Si={openai:"OpenAI",anthropic:"Anthropic",google:"Google Gemini",azure:"Microsoft Azure",aws:"Amazon Bedrock (AWS)",xai:"xAI",deepseek:"DeepSeek",meta:"Meta",mistral:"Mistral AI",qwen:"Qwen",moonshot:"Moonshot AI",cohere:"Cohere",openrouter:"OpenRouter"};function Ci(s){const n=s.endsWith("==")?2:s.endsWith("=")?1:0;return Math.floor(s.length*3/4)-n}function Ei(s,n){const a=c=>s[c]*256+s[c+1],i=c=>s[c]+s[c+1]*256,o=c=>s[c]+s[c+1]*256+s[c+2]*65536,l=c=>s[c]+s[c+1]*256+s[c+2]*65536+s[c+3]*16777216,d=c=>s[c]*16777216+s[c+1]*65536+s[c+2]*256+s[c+3];if(n==="image/png")return s.length<33||s.slice(0,8).join(",")!=="137,80,78,71,13,10,26,10"||String.fromCharCode(...s.slice(12,16))!=="IHDR"||s.slice(-8).join(",")!=="73,69,78,68,174,66,96,130"?null:{width:d(16),height:d(20)};if(n==="image/jpeg"){if(s.length<12||s[0]!==255||s[1]!==216||s.at(-2)!==255||s.at(-1)!==217)return null;for(let c=2;c+8<s.length;){if(s[c]!==255){c+=1;continue}const x=s[c+1];if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(x))return{height:a(c+5),width:a(c+7)};if(x===216||x===217||x===1||x>=208&&x<=215){c+=2;continue}const m=a(c+2);if(m<2)return null;c+=m+2}return null}if(s.length<30||String.fromCharCode(...s.slice(0,4))!=="RIFF"||String.fromCharCode(...s.slice(8,12))!=="WEBP"||l(4)+8!==s.length)return null;const u=String.fromCharCode(...s.slice(12,16));if(u==="VP8X")return{width:o(24)+1,height:o(27)+1};if(u==="VP8L"&&s[20]===47){const c=s[21]|s[22]<<8|s[23]<<16|s[24]<<24;return{width:(c&16383)+1,height:(c>>>14&16383)+1}}return u==="VP8 "&&s[23]===157&&s[24]===1&&s[25]===42?{width:i(26)&16383,height:i(28)&16383}:null}function Ai(s){if(s.kind==="preset")return Cs.includes(s.preset)?null:"Choose a supported provider icon.";const n=/^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/]+={0,2})$/.exec(s.dataUrl);if(!n)return"Upload a PNG, JPEG, or WebP image.";const a=Ci(n[2]);if(a>Es)return"Provider icons must be 128 KB or smaller.";let i;try{i=atob(n[2])}catch{return"The uploaded image is not valid base64."}if(i.length!==a)return"The uploaded image is not valid base64.";const o=Uint8Array.from(i,d=>d.charCodeAt(0)),l=Ei(o,n[1]);return l?l.width<1||l.height<1||l.width>fe||l.height>fe||l.width*l.height>fe**2?`Provider icons must be at most ${fe} × ${fe} pixels.`:null:"The uploaded image is incomplete or does not match its file type."}function Ii(s){return new Promise((n,a)=>{const i=new Image;i.onerror=()=>a(new Error(t("engines.icon.decodeError"))),i.onload=()=>n({width:i.naturalWidth,height:i.naturalHeight}),i.src=s})}async function Pi(s,n=Ii){if(!As.includes(s.type))throw new Error(t("engines.icon.formatError"));if(s.size>Es)throw new Error(t("engines.icon.sizeError"));const a=new Uint8Array(await s.arrayBuffer());let i="";for(let u=0;u<a.length;u+=8192)i+=String.fromCharCode(...a.subarray(u,u+8192));const o={kind:"custom",dataUrl:`data:${s.type};base64,${btoa(i)}`};if(Ai(o))throw new Error(t("engines.icon.invalidError",{dimension:fe}));const d=await n(o.dataUrl);if(d.width<1||d.height<1||d.width>fe||d.height>fe)throw new Error(t("engines.icon.dimensionError",{dimension:fe}));return o}function Ri({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(null),d=r.useRef(!1),u=async m=>{if(!d.current){d.current=!0,i(!0),l(null);try{const g=typeof m=="function"?await m():m;await U(`/api/instances/${encodeURIComponent(s.instanceId)}/icon`,{method:"PATCH",body:JSON.stringify({icon:g})}),await n()}catch(g){l(g instanceof Error?g.message:String(g))}finally{d.current=!1,i(!1)}}},c=m=>{const g=m.currentTarget,p=g.files?.[0];p&&u(()=>Pi(p)).finally(()=>{g.value=""})},x=s.icon?.kind==="preset"?s.icon.preset:s.icon?.kind==="custom"?"custom":"default";return e.jsxs("section",{"aria-label":t("engines.icon.label"),className:"mb-3 rounded-xl border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-xl border border-hairline/30 bg-panel",children:e.jsx(sn,{instance:s,size:24})}),e.jsxs("label",{className:"min-w-40 flex-1 text-[12px] font-medium text-ink",children:[t("engines.icon.label"),e.jsxs("select",{"aria-label":t("engines.icon.selectAria",{name:s.displayName}),value:x,disabled:a,onChange:m=>{m.target.value==="default"?u(null):m.target.value!=="custom"&&u({kind:"preset",preset:m.target.value})},className:"mt-1 block w-full rounded-lg border border-hairline/40 bg-inset px-2.5 py-2 text-[12px] text-ink focus:border-accent/60 focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"default",children:t("engines.icon.default")}),s.icon?.kind==="custom"&&e.jsx("option",{value:"custom",children:t("engines.icon.custom")}),Cs.map(m=>e.jsx("option",{value:m,children:Si[m]},m))]})]}),a&&e.jsx(H,{size:15,"aria-label":t("engines.icon.saving"),className:"animate-spin text-ink-secondary"}),s.icon&&e.jsxs("button",{type:"button",disabled:a,onClick:()=>{u(null)},className:"inline-flex items-center gap-1 rounded-lg px-2 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:[e.jsx(ds,{size:13,"aria-hidden":"true"}),t("engines.icon.reset")]})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-ink-secondary",children:t("engines.icon.help")}),e.jsx("input",{type:"file",accept:As.join(","),disabled:a,onChange:c,"aria-label":t("engines.icon.uploadAria",{name:s.displayName}),className:"mt-2 block w-full text-[11px] text-ink-secondary file:mr-2 file:rounded-lg file:border-0 file:bg-control file:px-2.5 file:py-1.5 file:text-[11px] file:font-medium file:text-ink hover:file:bg-raised-hover disabled:opacity-50"}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Is({instance:s,onSaved:n,onCancel:a}){const{refreshInstances:i}=K(),[o,l]=r.useState(s?.displayName??""),[d,u]=r.useState(s?.claudeAccount?.configDir??""),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=!s||o.trim()!==s.displayName||d.trim()!==s.claudeAccount?.configDir,y=!!(s?.claudeAccount?.configDir&&!d.trim()),k=async()=>{if(!(c||!o.trim()||!p||y)){x(!0),g(null);try{await U(s?`/api/instances/${encodeURIComponent(s.instanceId)}`:"/api/instances/claude-accounts",{method:s?"PATCH":"POST",body:JSON.stringify({displayName:o.trim(),...d.trim()?{configDir:d.trim()}:{}})}),await i().catch(()=>{}),n()}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}}};return e.jsxs("form",{className:"flex min-w-0 flex-col gap-3",onSubmit:N=>{N.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:o,onChange:N=>l(N.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-ink-secondary hover:text-ink",children:t("engines.account.advanced")}),e.jsxs("label",{className:"mt-2 flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.configDir"),e.jsx("input",{value:d,onChange:N=>u(N.target.value),placeholder:t(s?"engines.account.defaultDir":"engines.account.configDirPlaceholder"),maxLength:4096,spellCheck:!1,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.configDirHint")}),s&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.changeDirHint")})]}),!s&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("engines.account.addHint")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex justify-end gap-2",children:[a&&e.jsx("button",{type:"button",onClick:a,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!o.trim()||!p||y,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),s?t("common.save"):t("engines.account.add")]})]})]})}function Bi(){const[s,n]=r.useState(!1);return s?e.jsx("div",{className:"rounded-xl border border-hairline/40 p-3",children:e.jsx(Is,{onSaved:()=>n(!1),onCancel:()=>n(!1)})}):e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-fit 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",children:[e.jsx(De,{size:13}),t("engines.account.add")]})}function Di({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(!1),[c,x]=r.useState(!1),[m,g]=r.useState(!1),[p,y]=r.useState(null),k=s.claudeAccount;if(!k)return null;const N=n.bots.filter(h=>h.modelSelection.instanceId===s.instanceId).length,v=N>0,j=s.snapshot.authenticated===!0,E=s.snapshot.account?.method==="api-key",w=j&&s.authentication?.signOut===!0&&!E,D=j?E?t("engines.account.apiKey"):[s.snapshot.account?.email,s.snapshot.account?.organization].filter(Boolean).join(" · "):"",I=async()=>{if(!(o||m)){l(!0),y(null);try{await i()}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},f=async()=>{if(u(!1),!(o||m||k.isDefault||v)){l(!0),y(null);try{await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"}),await i().catch(()=>{})}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},b=async()=>{if(x(!1),!(o||m||!w)){g(!0),y(null);try{const{instances:h}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:h})}catch(h){y(h instanceof Error?h.message:String(h))}finally{g(!1)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:_("min-w-0 break-words",j?"text-success":"text-ink-secondary"),children:[j?t("engines.account.connected"):s.snapshot.authenticated===!1?t("model.signInRequired"):t("engines.account.unknown"),D&&` · ${D}`]}),k.isDefault&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:t("engines.account.default")}),e.jsxs("button",{type:"button",onClick:()=>{I()},disabled:o||m,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o&&"animate-spin")}),t("engines.account.check")]})]}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:t("engines.account.signInHint")}),k.signInShell==="powershell"&&e.jsx("p",{className:"text-ink-secondary",children:t("engines.account.powershell")}),e.jsx(Re,{command:k.signInCommand,copyLabel:t("engineSetup.copyCommand")}),e.jsx("fieldset",{disabled:o||m,className:"min-w-0",children:e.jsx(Is,{instance:s,onSaved:()=>{}},`${s.displayName}:${k.configDir}`)}),w&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!0),disabled:o||m,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:m?t("engines.account.signingOut"):t("engines.account.signOut")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.signOutHint")}),v&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.signOutAssigned",{count:String(N)})})]}),!k.isDefault&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o||m||v,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:t("engines.account.remove")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t(v?"engines.account.assigned":"engines.account.removeHint")})]})]})]}),p&&e.jsx("p",{role:"alert",className:"text-danger",children:p}),e.jsx(Ge,{open:d,title:t("engines.account.removeTitle",{name:s.displayName}),body:t("engines.account.removeHint"),confirmLabel:t("engines.account.remove"),tone:"neutral",onCancel:()=>u(!1),onConfirm:()=>{f()}}),e.jsx(Ge,{open:c,title:t("engines.account.signOutTitle",{name:s.displayName}),body:t("engines.account.signOutHint"),confirmLabel:t("engines.account.signOut"),onCancel:()=>x(!1),onConfirm:()=>{b()}})]})}function Ti(){const{dispatch:s}=K(),[n,a]=r.useState(!1),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(null),x=async()=>{if(!(l||!i.trim())){d(!0),c(null);try{const{instances:m}=await U("/api/instances/chatgpt-accounts",{method:"POST",body:JSON.stringify({displayName:i.trim()})});s({type:"instances",instances:m}),a(!1),o("")}catch(m){c(m instanceof Error?m.message:String(m))}finally{d(!1)}}};return n?e.jsxs("form",{className:"min-w-0 space-y-3 rounded-xl border border-hairline/40 p-3",onSubmit:m=>{m.preventDefault(),x()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:i,onChange:m=>o(m.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:l,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("engineSetup.chatgpt.addAccountHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a(!1),disabled:l,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:l||!i.trim(),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[l&&e.jsx(H,{size:13,className:"animate-spin"}),t("engineSetup.chatgpt.addAccount")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex w-fit 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",children:[e.jsx(De,{size:13}),t("engineSetup.chatgpt.addAccount")]})}function zi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),m=s.snapshot.account?.email,g=s.authentication?.signOut===!0,p=s.snapshot.chatgptPlan===!0,y=t(p?"engineSetup.chatgpt.signOutHint":"engineSetup.device.signOutHint"),k=n.bots.filter(j=>j.modelSelection.instanceId===s.instanceId).length,N=async()=>{if(!o){l("check"),x(null);try{await i()}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}},v=async()=>{if(u(!1),!(o||!g)){l("signOut"),x(null);try{const{instances:j}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 break-words text-success",children:[e.jsx(oe,{size:13,className:"shrink-0"}),t(p?"engineSetup.chatgpt.connectedAccount":"engineSetup.device.connectedAccount"),m&&e.jsxs("span",{className:"text-ink-secondary",children:["· ",m]})]}),e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:o!==null,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o==="check"&&"animate-spin")}),t("engines.account.check")]})]}),p&&e.jsx(nn,{instanceId:s.instanceId},s.instanceId),g&&e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:y}),k>0&&e.jsx("p",{className:"leading-relaxed text-warning",children:t(p?"engineSetup.chatgpt.signOutAssigned":"engineSetup.device.signOutAssigned",{count:String(k)})}),e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o!==null,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:o==="signOut"?t("engineSetup.device.signingOut"):t("engineSetup.device.signOut")})]})]}),c&&e.jsx("p",{role:"alert",className:"text-danger",children:c}),e.jsx(Ge,{open:d,title:t("engineSetup.device.signOutTitle"),body:y,confirmLabel:t("engineSetup.device.signOut"),onCancel:()=>u(!1),onConfirm:()=>{v()}})]})}function Ut(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Mi({instance:s,initial:n={kind:"idle"}}){const[a,i]=r.useState(n),[o,l]=r.useState(null),d=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,u=async()=>{l(null),i({kind:"scanning"});try{const m=await U(d);i(m.folders>0?{kind:"found",bytes:m.bytes,complete:m.complete}:{kind:"none"})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},c=async()=>{l(null),i({kind:"deleting"});try{const m=await U(`${d}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:m.freedBytes,remaining:m.remaining})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},x=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(di,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||x)&&e.jsxs("button",{type:"button",onClick:()=>{u()},disabled:x,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Ut(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{c()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Ut(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Oi({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[o,l]=r.useState(s.cliCandidates??null),[d,u]=r.useState(""),[c,x]=r.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[m,g]=r.useState(!1),[p,y]=r.useState(null),[k,N]=r.useState(!1),[v,j]=r.useState(null),E=r.useRef(!1);r.useEffect(()=>{E.current||(E.current=!0,U(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:h})=>{l(h),s.cli&&(h.includes(s.cli)?u(s.cli):x(s.cli))}).catch(()=>l(h=>h??[])))},[n,s.cli]);const w=c.trim()||d,D=w!==(s.cli??""),I=m||k;r.useEffect(()=>{y(null)},[w]);const f=()=>{if(I||!w||!D)return;N(!0),j(null);const h=w;U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:h})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(C=>j(C.message)).finally(()=>N(!1))},b=()=>{I||!w||!D||(g(!0),j(null),U("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(h=>{y(h),h.ok&&f()}).catch(h=>j(h.message)).finally(()=>g(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[o!==null&&o.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:c.trim()?"":d,onChange:h=>{u(h.target.value),x("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,className:"w-full appearance-none rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),o.map(h=>e.jsx("option",{value:h,children:h},h))]}),e.jsx(pn,{size:13,className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"})]}),e.jsx("input",{type:"text",value:c,onChange:h=>x(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),!(!w||!D)&&b())},placeholder:o?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:I,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),p&&!p.ok&&p.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(ke,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:p.message})})]}),p?.ok&&p.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:p.version})}),v&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:v}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),p&&!p.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y(null),disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>f(),disabled:I,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:k?e.jsx(H,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:b,disabled:I||!w||!D,className:_("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:I?e.jsx(H,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})})]})]})}function Ui({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),o=on(a),[l,d]=r.useState(!1),[u,c]=r.useState(!1),[x,m]=r.useState(null),[g,p]=r.useState(null),y=r.useRef(null);r.useEffect(()=>{y.current!==null&&y.current!==s.cli&&i(!1),y.current=s.cli??null},[s.cli]);const k=()=>{l||u||(d(!0),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>p(j.message)).finally(()=>d(!1)))},N=()=>{l||u||(c(!0),m(null),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{m(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>p(j.message)).finally(()=>c(!1)))},v=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.readOnly?e.jsxs(At,{instance:s,children:[v,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!$e(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(At,{instance:s,children:[v,e.jsx(Ri,{instance:s}),!$e(s)&&e.jsx(us,{instance:s,intent:s.access==="custom"?"inject":"cloud",unframed:!0}),$e(s)&&e.jsx(cn,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(dn,{update:s.snapshot.update,instance:s,className:"mt-3"}),s.snapshot.warning&&e.jsx(un,{warning:s.snapshot.warning,className:"mt-3"}),s.claudeAccount&&e.jsx(Di,{instance:s}),$e(s)&&s.snapshot.authenticated===!0&&((s.authentication?.method==="device-code"||s.authentication?.method==="browser-pkce")&&It(s.driverKind)==="codex"?e.jsx(zi,{instance:s}):s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t(xn[It(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&!s.claudeAccount&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Mi,{instance:s}),e.jsxs("details",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[11.5px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:N,disabled:l||u,className:"flex shrink-0 items-center gap-1 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[u?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(xe,{size:12}),u?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:k,disabled:l||u,className:"shrink-0 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:l?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:u,"aria-expanded":a,className:_("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),x&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:x})}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g}),o.shown&&e.jsx("div",{className:o.className,...o.exitProps,children:e.jsx(Oi,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})]})}function Li(){const{state:s}=K(),n=s.instances.filter(a=>a.readOnly||a.cli!==void 0||a.cliDefault!==void 0||a.snapshot.state==="unavailable"||an(a));return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(rn,{})]}),e.jsx(ln,{instances:n,renderEngine:a=>e.jsx(Ui,{instance:a})}),e.jsxs("div",{className:"space-y-3 border-t border-hairline/40 pt-4",children:[e.jsx(Bi,{}),s.instances.some(a=>a.snapshot.chatgptPlan&&!a.readOnly&&!a.snapshot.authenticationUnavailableReason)&&e.jsx(Ti,{})]})]})}const _i=[1e3,2e3,4e3];function Fi(s){return new Promise(n=>window.setTimeout(n,s))}const $i={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Ki={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 gt(s){return t(Ki[s])}function Hi(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function Vi(s){return gt(Hi(s))}function Wi(s){return s.inUse?"in-use":s.state==="removing"?"removing":["archived","stopped"].includes(s.state)?"sleeping":["archiving","stopping"].includes(s.state)?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning","starting"].includes(s.state)?"starting":"attention"}function Ps(s,n,a){const i={...a},o=new Set(s.map(d=>d.boxId)),l=s.flatMap(d=>{const u=a[d.boxId];return u==="deleted"?[]:u==="deleting"?[{...d,state:"removing"}]:u!=="sleeping"?[d]:["archived","stopped"].includes(d.state)?(delete i[d.boxId],[d]):[{...d,state:"archived"}]});for(const d of n)a[d.boxId]!=="sleeping"||o.has(d.boxId)||l.push({...d,state:"archived"});for(const[d,u]of Object.entries(a))(u==="deleted"||u==="deleting")&&!o.has(d)&&delete i[d];return{instances:l,overrides:i}}function qi(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ps(Array.isArray(s.instances)?s.instances:[],n,a)}function Ji(s){return["idle","ready","running"].includes(s.state)}function Gi(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 ht(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}const Yi={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function Ke(s,n){return[Yi[s],{signal:n}]}function ft(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Xi(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:ft(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Qi(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:ft(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function Zi(s){const n=ht(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:ft(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name})}}function ct(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function er({instances:s,configured:n,sshAlias:a,loading:i,removingName:o,error:l,unavailableReason:d,onRefresh:u,onRemove:c}){return e.jsxs(L,{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??t("vm.vps.configuredFallback")}):n===!1?t("vm.vps.needsAlias"):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:u,disabled:i||o!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(i&&"animate-spin")})," ",t("vm.refresh")]})]}),l&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:l}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):d?t("vm.vps.unavailable",{reason:d}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":i||o!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children: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(H,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):d?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",d]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(gi,{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((x,m)=>{const g=Gi(x),p=gt(g),y=o===x.name,k=ht(x.name);return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.vps.orphan",{id:k}):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="stopped"||g==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:i||x.inUse||o!==null,"aria-busy":y||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:[y?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("vm.vps.remove")]})]},x.name)})})]})}function tr({instances:s,configured:n,loading:a,pending:i,error:o,unavailableReason:l,onRefresh:d,onSleep:u,onDelete:c}){return e.jsxs(L,{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?t("vm.cloud.needsKey"):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):l?t("vm.cloud.unavailable",{reason:l}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{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(mt,{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((x,m)=>{const g=Wi(x),p=gt(g),y=i?.boxId===x.boxId,k=Ji(x),N=g==="removing";return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.cloud.orphan"):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="sleeping"||g==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsxs("div",{className:"mt-1 break-all text-[11.5px] text-ink-secondary",children:[x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",x.name]}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] 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:()=>u(x),disabled:a||x.inUse||i!==null||!k,"aria-busy":y&&i?.action==="sleep"?!0:void 0,title:k?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:p.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:[y&&i?.action==="sleep"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(qa,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:a||x.inUse||i!==null||N,"aria-busy":y&&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:[y&&i?.action==="delete"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]})]},x.boxId)})})]})}function sr({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:o,unavailableReason:l,onRefresh:d,onDelete:u}){return e.jsxs(L,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:l?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):l?t("vm.perBot.unavailable",{reason:l}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((c,x)=>{const m=Vi(c),g=i===c.botId,p=c.managed===!0;return e.jsxs("div",{className:_("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-[13.5px] font-medium text-ink",children:c.name}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",p?c.inUse||c.ready?"bg-success/15 text-success":c.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:m})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t($i[c.destination])})}),!p&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:t("vm.perBot.unmanaged")}),p&&c.problem&&!c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:c.problem}),p&&c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),p&&e.jsxs("button",{type:"button",onClick:()=>u(c),disabled:a||c.inUse||i!==null,"aria-busy":g||void 0,title:c.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:c.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:[g?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]},c.botId)})})]})}function He({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:_("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(oe,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:_("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function Ie({action:s,pending:n,children:a,onClick:i,danger:o=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:_("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[12.5px] font-medium disabled:opacity-50",o?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(H,{size:13,className:"animate-spin"}),a]})}const Rs=5,Bs=1440,nr=480;function ar(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Rs&&a<=Bs?a:null}function ir({minutes:s,disabled:n,onSave:a}){const[i,o]=r.useState(String(s)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1);r.useEffect(()=>{l||o(String(s))},[s,l]);const g=async()=>{if(!l||x)return;const p=ar(i);if(p===null){c(t("vm.idle.range"));return}m(!0);try{await a(p),o(String(p)),d(!1),c("")}catch(y){c(y instanceof Error?y.message:t("vm.idle.error"))}finally{m(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[11.5px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:_("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",u?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Rs,max:Bs,step:1,inputMode:"numeric",value:i,disabled:n||x,"aria-invalid":!!u,"aria-describedby":u?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:p=>{o(p.target.value),d(!0),c("")},onBlur:()=>{g()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[12.5px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),u?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:u}):null]})}function Lt(){const s=K().state.config?.cloudHome===!0,[n,a]=r.useState(null),[i,o]=r.useState(!0),[l,d]=r.useState(null),u=r.useRef(null);r.useEffect(()=>()=>u.current?.abort(),[]);const[c,x]=r.useState(null),[m,g]=r.useState(!1),[p,y]=r.useState(0),[k,N]=r.useState([]),[v,j]=r.useState(2),[E,w]=r.useState(!1),[D,I]=r.useState(null),[f,b]=r.useState(null),[h,C]=r.useState(null),[A,P]=r.useState(0),[V,J]=r.useState([]),[$,W]=r.useState(null),[z,G]=r.useState(!0),[ne,R]=r.useState(null),[F,q]=r.useState(null),[ce,pe]=r.useState(null),[be,ye]=r.useState(0),X=r.useRef([]),se=r.useRef({}),[Se,ge]=r.useState([]),[ee,Le]=r.useState(null),[T,Q]=r.useState(null),[ie,ae]=r.useState(!0),[ze,et]=r.useState(null),[qs,yt]=r.useState(null),[Js,vt]=r.useState(null),[Gs,Ys]=r.useState(0),[Xs,ve]=r.useState(""),Me=r.useCallback(async S=>{const B=await fetch(...Ke("status",S)),M=await B.json().catch(()=>({}));if(!S?.aborted){if(!B.ok)throw new Error(M.error??t("vm.err.status",{code:B.status}));return a(M),x(null),M}},[]),tt=r.useCallback(async S=>{const B=await fetch(...Ke("local-vms",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.inventory",{code:B.status}));const O=M;N(O.instances),j(O.maxInstances),b(O.available?null:O.problem??t("vm.err.runtimeUnavailable")),I(null)},[]),Oe=r.useCallback(async S=>{const B=await fetch(...Ke("cloud",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.cloudInventory",{code:B.status}));const O=M,Z=qi(O,X.current,se.current);se.current=Z.overrides,X.current=Z.instances,J(Z.instances),W(O.configured===!0),q(O.available||!O.configured?null:O.problem??t("vm.err.cloudUnavailable")),R(null)},[]),st=r.useCallback(async S=>{const B=await fetch(...Ke("vps",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.vpsInventory",{code:B.status}));const O=M;ge(Array.isArray(O.instances)?O.instances:[]),Le(O.configured===!0),Q(typeof O.sshAlias=="string"?O.sshAlias:null),yt(O.available||!O.configured?null:O.problem??t("vm.err.vpsUnavailable")),et(null)},[]);r.useEffect(()=>{if(s)return;let S=!0,B,M;const O=async()=>{M=new AbortController;try{await Me(M.signal)}catch(Z){S&&!(Z instanceof DOMException&&Z.name==="AbortError")&&(a(null),x(Z instanceof Error?Z.message:String(Z)))}finally{S&&(o(!1),B=window.setTimeout(()=>{O()},5e3))}};return O(),()=>{S=!1,M?.abort(),B!==void 0&&window.clearTimeout(B)}},[s,Me,p]),r.useEffect(()=>{if(n?.mode!=="per-bot"){N([]),w(!1),I(null),b(null);return}const S=new AbortController;return w(!0),tt(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||I(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||w(!1)}),()=>S.abort()},[A,tt,n?.mode]),r.useEffect(()=>{const S=new AbortController;return G(!0),Oe(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||q(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||G(!1)}),()=>S.abort()},[be,Oe]),r.useEffect(()=>{const S=new AbortController;return ae(!0),st(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||yt(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||ae(!1)}),()=>S.abort()},[st,Gs]);const nt=async(S,B)=>{const M=await fetch(`/api/local-computer/${S}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:B}),O=await M.json().catch(()=>({})),Z={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!M.ok)throw new Error(O.error??t(Z[S]));return B.throwIfAborted(),a(O),O},jt=S=>window.ogb?.confirm?window.ogb.confirm(S):window.confirm(S),Ce=async S=>{if(l!==null||u.current)return;const B=new AbortController;u.current=B,d(S),x(null);try{if(S==="remove"&&!await jt(t("vm.confirm.deleteShared"))||S==="recreate"&&!await jt(t("vm.confirm.recreate")))return;let M;if(S==="recreate"?(await nt("remove",B.signal),M=await nt("run",B.signal)):M=await nt(S,B.signal),(S==="run"||S==="start"||S==="recreate")&&(M=await Ja(M,async()=>await Me(B.signal)??M,B.signal),!M.ready))throw new Error(M.problem??t("vm.err.start"));await Me(),ve(S==="remove"?t("vm.announce.deleted"):S==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(M){if(B.signal.aborted)return;x(M instanceof Error?M.message:String(M))}finally{u.current=null,B.signal.aborted||d(null)}},kt=async(S,B)=>{g(!0),x(null);try{const M=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:S,maxInstances:B}})}),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.policyError"));a(Z=>Z&&{...Z,mode:S,max_instances:B}),await Me()}catch(M){x(M instanceof Error?M.message:String(M))}finally{g(!1)}},Qs=async S=>{const B=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:S}})}),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.idle.error"));a(O=>O&&{...O,idle_timeout_ms:S*6e4})},Zs=async S=>{if(!S.managed){I(t("vm.unmanagedError"));return}const B=ct(Xi(S),M=>window.confirm(M));if(B){C(S.botId),I(null);try{const M=await fetch(...B),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.deleteError"));await tt(),ve(t("vm.announce.deletedBot",{name:S.name}))}catch(M){I(M instanceof Error?M.message:String(M))}finally{C(null)}}},Nt=async(S,B)=>{const M=ct(Qi(S,B),O=>window.confirm(O));if(M){pe({boxId:B.boxId,action:S}),R(null),ve("");try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t(S==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const rt=S==="delete"&&Z?.pending===!0;se.current={...se.current,[B.boxId]:S==="delete"?rt?"deleting":"deleted":"sleeping"};const lt=Ps(X.current,X.current,se.current);se.current=lt.overrides,X.current=lt.instances,J(lt.instances);const Ee=B.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:B.ownerName??""});if(ve(rt?`${Ee}: ${t("vm.state.removing")}.`:t(S==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ee})),rt){for(const de of _i){await Fi(de);try{await Oe()}catch{}if(se.current[B.boxId]!=="deleting"){ve(t("vm.announce.cloudDeleted",{subject:Ee}));return}}const Ae={...se.current};delete Ae[B.boxId],se.current=Ae;const Fe=X.current.map(de=>de.boxId===B.boxId?{...de,state:B.state}:de);X.current=Fe,J(Fe);try{await Oe(),X.current.some(de=>de.boxId===B.boxId)||ve(t("vm.announce.cloudDeleted",{subject:Ee}))}catch(de){const tn=de instanceof Error?de.message:String(de);R(`${Ee}: ${t("vm.state.removing")}. ${tn}`)}return}try{await Oe()}catch(Ae){const Fe=Ae instanceof Error?Ae.message:String(Ae);R(t(S==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ee,detail:Fe}))}}catch(O){R(O instanceof Error?O.message:String(O))}finally{pe(null)}}},en=async S=>{const B=ht(S.name),M=ct(Zi(S),O=>window.confirm(O));if(M){vt(S.name),et(null);try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t("vm.vpsRemoveError"));await st(),ve(t("vm.announce.vpsRemoved",{subject:S.orphaned?t("vm.announce.orphanVps",{id:B}):t("vm.confirm.ownedVps",{name:S.ownerName??""})}))}catch(O){et(O instanceof Error?O.message:String(O))}finally{vt(null)}}},he=n?.commands,_e=n?.ready===!0,wt=n?.container!=="missing",St=!!(wt&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ct=!i&&!n,Et=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),re=n?.mode==="per-bot",at=re&&n?.runtime==="container",it=re?!!(n?.daemonUp&&n?.image&&!at):_e;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Xs}),e.jsx(tr,{instances:V,configured:$,loading:z,pending:ce,error:ne,unavailableReason:F,onRefresh:()=>ye(S=>S+1),onSleep:S=>{Nt("sleep",S)},onDelete:S=>{Nt("delete",S)}}),e.jsx(er,{instances:Se,configured:ee,sshAlias:T,loading:ie,removingName:Js,error:ze,unavailableReason:qs,onRefresh:()=>Ys(S=>S+1),onRemove:S=>{en(S)}}),e.jsx(Wa,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{title:t("vm.main.title"),subtitle:re?t("vm.main.perBotSubtitle",{host:Et}):t("vm.main.sharedSubtitle",{host:Et}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:_("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12.5px]",it?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(H,{size:12,className:"animate-spin"}):it?e.jsx(oe,{size:12}):e.jsx(mn,{size:9}),i?t("common.checking"):Ct?t("vm.main.statusUnavailable"):re&&it?t("vm.main.readyPerBot"):at?t("vm.main.perBotUnsupported"):_e?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{o(!0),y(S=>S+1),P(S=>S+1)},disabled:i||l!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12})," ",t("vm.main.recheck")]}),_e&&!re&&e.jsxs("a",{href:n?.viewer_url??he?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink hover:bg-control",children:[e.jsx(Ze,{size:12})," ",t("vm.main.watch")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c})]}),e.jsxs(L,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((S,B)=>e.jsx("button",{type:"button",disabled:!n||m,onClick:()=>{kt(S,n?.max_instances??2)},className:_("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",B>0&&"border-l border-hairline/40",n?.mode===S?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:S==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},S))}),re&&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-[11.5px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx("select",{"aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||m,onChange:S=>{kt(n?.mode??"shared",Number(S.target.value))},className:"rounded-lg border border-hairline/40 bg-control px-2.5 py-1.5 text-[13px] text-ink disabled:opacity-50",children:[1,2,3,4,5,6,7,8].map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsx(ir,{minutes:n?Math.round(n.idle_timeout_ms/6e4):nr,disabled:!n||m,onSave:Qs}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(H,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(L,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(He,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),he?.install?e.jsx(Re,{command:he.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(He,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?he?.runtimeStart?e.jsx(Re,{command:he.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(He,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ie,{action:"pull",pending:l,onClick:()=>{Ce("pull")},children:t("vm.setup.prepare")}),he?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.pull})})]})]}),e.jsxs(He,{n:4,title:re?t("vm.setup.step4PerBot"):St?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!re&&_e,children:[re?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:at?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):St?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ie,{action:"recreate",pending:l,onClick:()=>{Ce("recreate")},danger:!0,children:[e.jsx(ds,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ie,{action:"start",pending:l,onClick:()=>{Ce("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{action:"run",pending:l,onClick:()=>{Ce("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,he?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.run})})]})]})]})}),re&&e.jsx(sr,{instances:k,maxInstances:v||n?.max_instances||2,loading:E,deletingBotId:h,error:D,unavailableReason:f,onRefresh:()=>P(S=>S+1),onDelete:S=>{Zs(S)}}),Ct&&e.jsx(L,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(L,{title:t("vm.safety.title"),subtitle:re?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[wt&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ie,{action:"stop",pending:l,onClick:()=>{Ce("stop")},children:[e.jsx(gn,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ie,{action:"remove",pending:l,onClick:()=>{Ce("remove")},danger:!0,children:[e.jsx(we,{size:12})," ",re?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.20.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function rr(s,n){return s.error?{kind:"error",title:t("remote.status.attention"),detail:s.error}:n&&s.tailnetName?{kind:"ready",title:t("remote.tailscale.ready",{name:s.tailnetName}),detail:t("remote.tailscale.readyDetail")}:s.tailscale?{kind:"magicdns",title:t("remote.tailscale.magicDns"),detail:t("remote.tailscale.magicDnsDetail")}:s.enabled?{kind:"unavailable",title:t("remote.tailscale.notConnected"),detail:t("remote.tailscale.notConnectedDetail")}:{kind:"unchecked",title:t("remote.tailscale.already"),detail:t("remote.tailscale.alreadyDetail")}}function lr(s){return s.tailscaleFallback?{title:t("remote.pairing.tailscale.title"),subtitle:t("remote.pairing.tailscale.subtitle")}:s.localFallback?{title:t("remote.pairing.wifi.title"),subtitle:t("remote.pairing.wifi.subtitle")}:{title:t("remote.pairing.https.title"),subtitle:t("remote.pairing.https.subtitle")}}function or(s){if(s.error)return{label:t("remote.status.attention"),good:!1};if(!s.enabled)return{label:t("remote.status.off"),good:!1};const n=s.devices.length;return n?{label:`${n} ${n===1?"device":"devices"} paired`,good:!0}:null}const cr=s=>{const n=Math.round((Date.now()-s)/1e3);if(n<90)return t("remote.time.justNow");const a=Math.round(n/60);if(a<60)return t("remote.time.minutes",{count:a});const i=Math.round(a/60);return i<24?t("remote.time.hours",{count:i}):t("remote.time.days",{count:Math.round(i/24)})},dr=s=>{try{return new URL(s).host}catch{return s}};function ur({profileEmail:s="",focusRequest:n=0}){const a=hn(s),i=a.state,o=r.useRef(null),l=r.useRef(0),d=!!i;r.useEffect(()=>{n?l.current!==n&&xs(o.current)&&(l.current=n):l.current=0},[n,d]);const u=K().state.config?.managedPolicy,c=u?.remoteAccess===!1?t("policy.remoteBlocked",{organization:u.organizationName}):null,x=u?.remoteAccess===!1?t("policy.managedBy",{organization:u.organizationName}):null;if(!fn())return e.jsx(L,{title:t("remote.desktopOnly.title",{app:Ye().name}),subtitle:t("remote.desktopOnly.subtitle")});if(!i)return e.jsx(L,{title:t("remote.title"),subtitle:t("remote.checking"),children:e.jsx(H,{size:15,className:"animate-spin text-ink-secondary"})});const m=i.devices.length,g=or(i),p=bn(a.account,a.accountError),y=lr(a),k=rr(i,a.tailscaleAvailable),N=i.endpoints?.find(j=>j.kind==="hosted"),v=[i.tailnetName?{label:"Tailscale",value:`${i.tailnetName}:${i.port}`}:null,i.lan?{label:t("remote.connection.wifi"),value:`${i.lan}:${i.port}`}:null,i.discovery?.name?{label:t("remote.connection.discovery"),value:`${i.discovery.name}:${i.port}`}:null,...(i.addresses??[]).filter(j=>j!==i.lan&&j!==i.tailscale).map((j,E)=>({label:t("remote.connection.localRoute",{index:E+1}),value:`${j}:${i.port}`}))].filter(j=>!!j);return e.jsxs("div",{className:"flex flex-col gap-4",children:[c&&e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink-secondary",children:c}),e.jsx("div",{ref:o,tabIndex:-1,"data-phone-pairing":"computer",className:"scroll-mt-4 rounded-xl ring-1 ring-accent/40 focus:outline-none",children:e.jsxs(L,{title:y.title,subtitle:y.subtitle,children:[(g||m>0&&a.hostedReady)&&e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[g&&e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-2.5 py-1 text-[11.5px] ${g.good?"bg-success/10 text-success":"bg-control text-ink-secondary"}`,children:[e.jsx("span",{className:`size-1.5 rounded-full ${g.good?"bg-success":"bg-ink-secondary/50"}`}),g.label]}),m>0&&a.hostedReady&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx(Pt,{size:13,className:"text-accent"})," ",t("remote.worksAway")]})]}),e.jsx(yn,{controller:a,variant:"settings"})]})}),e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-card",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-3.5 text-[13px] font-medium text-ink",children:t("remote.advanced")}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-hairline/30 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.toggleDetail")})]}),e.jsx(Y,{checked:i.enabled,"aria-label":t("remote.title"),disabled:a.busy||!!c&&!i.enabled,onClick:()=>{a.act(j=>i.enabled?j.stop():j.start())}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.devices.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:m?t("remote.devices.subtitle",{app:Ye().name}):t("remote.devices.empty")}),e.jsx("div",{className:"mt-3",children:m>0&&e.jsx("ul",{className:"flex flex-col gap-2",children:i.devices.map(j=>e.jsxs("li",{className:"rounded-xl bg-inset px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(vn,{size:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13.5px] font-medium text-ink",children:j.name}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("remote.devices.lastSeen",{when:cr(j.lastSeenAt)})})]}),e.jsx("button",{disabled:a.busy,onClick:()=>{a.act(E=>E.revoke(j.id))},"aria-label":t("remote.devices.remove",{name:j.name}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-40",children:e.jsx(we,{size:14})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowView")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowViewDetail")})]}),e.jsx(Y,{checked:j.cloudDesktopAccess,"aria-label":t("remote.devices.viewAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(E=>E.cloudDesktop(j.id,!j.cloudDesktopAccess))}})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowBrowser")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowBrowserDetail")})]}),e.jsx(Y,{checked:j.browserControlAccess===!0,"aria-label":t("remote.devices.browserAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(E=>E.browserControl(j.id,!j.browserControlAccess))}})]})]},j.id))})})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.tailscale.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.tailscaleCard.subtitle")}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"rounded-xl bg-inset px-3 py-3","aria-live":"polite",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Pt,{size:16,className:`mt-0.5 shrink-0 ${k.kind==="ready"?"text-success":"text-ink-secondary"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:k.title}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:k.detail})]})]})}),k.kind==="ready"?e.jsx("button",{disabled:a.busy||a.accountBusy||!!x,title:x??void 0,onClick:()=>{a.useTailscale(),window.requestAnimationFrame(()=>{o.current?.scrollIntoView({block:"start"}),o.current?.focus({preventScroll:!0})})},className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.pairOverTailscale")}):e.jsx("button",{disabled:a.busy||a.accountBusy||!!x&&!i.enabled,title:x??void 0,onClick:a.refreshTailscale,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.busy?t("common.checking"):x&&!i.enabled?x:i.enabled?t("remote.checkAgain"):t("remote.turnOnAndCheck")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.keepAwake")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.keepAwakeDetail")})]}),e.jsx(Y,{checked:i.keepAwake,"aria-label":t("remote.keepAwakeAria"),disabled:a.busy||!i.enabled,onClick:()=>{a.act(j=>j.keepAwake(!i.keepAwake))}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(mt,{size:15,className:"mt-0.5 shrink-0 text-accent"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.account.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:a.account?.status==="ready"?t("remote.account.signedIn",{email:a.account.email??t("remote.account.yourAccount")}):a.account?.status==="connecting"?t("remote.account.connecting"):a.account?.status==="error"?a.account.message??t("remote.account.error"):t("remote.account.idle")})]})]}),(a.account?.status==="ready"||a.account?.status==="connecting"||a.account?.status==="error")&&e.jsxs("button",{disabled:a.accountBusy,onClick:()=>{a.accountAct(j=>j.signOut())},className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[11.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(jn,{size:12})," ",t("remote.account.signOut")]})]}),a.account?.status==="error"&&e.jsx("button",{disabled:a.accountBusy,onClick:a.retryAccount,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.accountBusy?t("remote.account.retrying"):t("remote.account.retry")}),p&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:p})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.connection.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] text-ink-secondary",children:t("remote.connection.detail")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[N&&e.jsx(Rt,{label:t("remote.connection.secureRoute"),value:dr(N.url)}),v.map(j=>e.jsx(Rt,{...j},`${j.label}:${j.value}`)),!N&&v.length===0&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("remote.connection.none")})]})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(kn,{size:15,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.wifi.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.wifi.detail")})]})]}),e.jsx("button",{disabled:a.busy||a.accountBusy,onClick:a.useLocal,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.wifi.pair")})]}),i.enabled&&!N&&!i.tailscale&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.localOnly")}),(a.error||i.error)&&e.jsx("div",{className:"text-[12px] text-danger",children:a.error??i.error})]})]})]})}function Xe(s){return wn(s)}function xr(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function pr(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}function mr(s,n=Date.now()){return Math.max(0,Math.ceil((s-n)/6e4))}function gr(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const hr="rounded-md bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-50",_t="rounded-md border border-hairline/50 px-3 py-1.5 text-[13px] text-ink hover:bg-control";function fr({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0}){const[o,l]=r.useState(s),[d,u]=r.useState(n),[c,x]=r.useState("admin"),[m,g]=r.useState(null),[p,y]=r.useState([]),[k,N]=r.useState(null),[v,j]=r.useState(!1),[E,w]=r.useState(!1),[D,I]=r.useState(null),[f,b]=r.useState(()=>Date.now()),h=r.useRef(null),C=r.useRef(0);async function A(){try{const z=await U("/api/auth/sessions");y(Array.isArray(z?.sessions)?z.sessions:[]),N(typeof z?.current=="string"?z.current:null)}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}}if(r.useEffect(()=>{ps().then(z=>{l(z),Xe(z)&&A(),(z.kind==="loopback"||z.kind==="session")&&U("/api/config").then(G=>u(ms(G).pairingCodes)).catch(()=>{})})},[]),r.useEffect(()=>{i?C.current!==i&&xs(h.current)&&(C.current=i):C.current=0},[i,o]),r.useEffect(()=>{if(!m)return;const z=setInterval(()=>b(Date.now()),15e3);return()=>clearInterval(z)},[m]),!Xe(o))return xr(o)!=="chat-only"?null:e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(d?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const P=m?m.expiresAt<=f:!1,V=pr(p,a);async function J(){j(!0),I(null),w(!1);try{const z=await U("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:c==="admin"||a?["admin","client"]:["client"]})});g(z),b(Date.now())}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}finally{j(!1)}}async function $(z){I(null);try{await U(`/api/auth/sessions/${encodeURIComponent(z)}`,{method:"DELETE"}),await A()}catch(G){I(t("remote.serverPairing.error",{error:G instanceof Error?G.message:String(G)}))}}async function W(){if(m?.url)try{await navigator.clipboard.writeText(m.url),w(!0)}catch{w(!1)}}return e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[d&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,d?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="admin",onChange:()=>x("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="client",onChange:()=>x("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{J()},disabled:v,className:hr,children:v?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),d&&m?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:P?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[m.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Nn,{value:m.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:m.code}),e.jsx("div",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.expires",{minutes:mr(m.expiresAt,f)})}),m.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:m.url}),e.jsx("button",{type:"button",onClick:()=>{W()},className:_t,children:E?t("remote.serverPairing.copied"):t("remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[12.5px] text-ink-secondary",children:m.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(d?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),V.length===0?e.jsx("p",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:V.map(z=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[z.label,z.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:gr(z.lastSeenAt,f)}),z.id===k?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),z.id===k?null:e.jsx("button",{type:"button",onClick:()=>{$(z.id)},className:_t,children:t("remote.serverPairing.signOut")})]},z.id))}),D?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:D}):null]})})}function br(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 Ft(s,n,a){const i=s.admins.filter(l=>l!==n),o=s.members.filter(l=>l!==n);return a==="admin"?{admins:[...i,n],members:o}:{admins:i,members:[...o,n]}}function yr(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $t(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function vr(s,n,a){const i=[],o=new Set,l=(d,u)=>{const c=d.trim().toLowerCase();if(!c||o.has(c))return;o.add(c);const x=n.filter(g=>g.email?.toLowerCase()===c),m=a.find(g=>g.key===`user:${c}`);i.push({entry:c,role:u,isDomain:c.startsWith("@"),lastSeenAt:x.length?Math.max(...x.map(g=>g.lastSeenAt)):null,devices:x.length,turns:m?.turns??0,costUsd:m?.costUsd??null,...le(m?.estimatedUsd)&&m.estimatedUsd>0?{estimated:!0}:{}})};for(const d of s.admins)l(d,"admin");for(const d of s.members)l(d,"member");return i}function jr(s,n){const a=new Map;for(const i of s){const o=i.email?.trim().toLowerCase();o&&a.set(o,[...a.get(o)??[],i])}return[...a.entries()].map(([i,o])=>{const l=n.find(d=>d.key===`user:${i}`);return{entry:i,role:o.some(d=>d.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...o.map(d=>d.lastSeenAt)),devices:o.length,turns:l?.turns??0,costUsd:l?.costUsd??null}}).sort((i,o)=>i.role===o.role?i.entry.localeCompare(o.entry):i.role==="admin"?-1:1)}function kr(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 Ds({people:s,busy:n,onRole:a,onRemove:i,onLink:o,readOnly:l=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(l?"people.portal.empty":"people.empty")});const d="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(d,"border-b border-hairline/40 pb-2 text-[11.5px] 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(u=>e.jsxs("div",{className:_(d,"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:u.isDomain?t("people.everyoneAt",{domain:u.entry.slice(1)}):u.entry}),u.devices>0&&e.jsx("span",{className:"block text-[11.5px] text-ink-secondary",children:t("people.devices",{count:String(u.devices)})})]}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px] font-medium",u.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:u.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:u.isDomain?"—":kr(u.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(u.turns)}),children:le(u.costUsd)?`${u.estimated?"~":""}${ue(u.costUsd)}`:"—"}),l?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:()=>o(u),"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(Cn,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(u,u.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:u.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(u),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},u.entry))]})}function Ts({link:s}){const[n,a]=r.useState(!1);r.useEffect(()=>{if(!n)return;const o=window.setTimeout(()=>a(!1),2e3);return()=>window.clearTimeout(o)},[n]);const i=async()=>{try{await navigator.clipboard.writeText(s),a(!0)}catch{}};return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[12.5px]",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:()=>{i()},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?e.jsx(oe,{size:13,className:"text-success"}):e.jsx(Sn,{size:13}),n?t("people.copied"):t("people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Nr({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(L,{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(Ze,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function wr(){const[s,n]=r.useState(null),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState([]),[c,x]=r.useState(typeof window<"u"?window.location.origin:""),[m,g]=r.useState(null),[p,y]=r.useState(""),[k,N]=r.useState("member"),[v,j]=r.useState(null),[E,w]=r.useState(!1),[D,I]=r.useState(!1),[f,b]=r.useState(null),h=r.useCallback(async()=>{I(!0),b(null);try{const[P,V,J,$,W]=await Promise.all([U("/api/config"),U("/api/auth/sessions").catch(()=>({sessions:[]})),U("/api/usage?groupBy=user").catch(()=>({groups:[]})),U("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(F=>F.ok?F.json():null).catch(()=>null)]),z={admins:Array.isArray(P?.signIn?.admins)?P.signIn.admins:[],members:Array.isArray(P?.signIn?.members)?P.signIn.members:[]},G=ms(P);i(G),l(z);const ne=Array.isArray(V?.sessions)?V.sessions:[],R=Array.isArray(J?.groups)?J.groups:[];u(G.authority==="portal"?jr(ne,R):vr(z,ne,R)),typeof $?.publicUrl=="string"&&$.publicUrl&&x($.publicUrl),g(W?.capabilities?.emailSignIn===!0?!0:W?!1:null)}catch(P){b(P instanceof Error?P.message:String(P))}finally{I(!1)}},[]);r.useEffect(()=>{ps().then(P=>{n(P),Xe(P)&&h()})},[h]);const C=async P=>{w(!0),b(null);try{await U("/api/config",{method:"PUT",body:JSON.stringify({signIn:P})}),await h()}catch(V){b(V instanceof Error?V.message:String(V))}finally{w(!1)}},A=async()=>{if(!o||E)return;const P=br(p);if(!P){b(t("remote.signInAccess.invalid"));return}await C(Ft(o,P,k)),y(""),j($t(c,P))};return Xe(s)?a?.authority==="portal"?e.jsx(Nr,{peopleUrl:a.peopleUrl,people:d}):e.jsxs(L,{title:t("people.title"),subtitle:t("people.subtitle"),children:[m===!1&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[12.5px] text-ink-secondary",children:t(a?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:P=>{P.preventDefault(),A()},children:[e.jsx("input",{value:p,onChange:P=>y(P.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:E,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("select",{value:k,onChange:P=>N(P.target.value),"aria-label":t("people.colRole"),disabled:E,className:"rounded-lg border border-hairline/40 bg-inset px-2 py-2 text-[12.5px] text-ink focus:outline-none",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:E||!p.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[E?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(De,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:D||E,"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(xe,{size:13,className:_(D&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Ts,{link:v}),f&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:f}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:d,busy:E,onRole:(P,V)=>{o&&C(Ft(o,P.entry,V))},onRemove:P=>{o&&C(yr(o,P.entry))},onLink:P=>j($t(c,P.entry))})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.note")})]}):null}const Ve="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 Sr({entry:s}){const[n,a]=r.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()}),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:si(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:ni(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:s.summary}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(En,{size:12,className:_("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(o=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.before?.[o])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.after?.[o])})]},o))]})]})]})})}function Cr(){const[s,n]=r.useState({who:"",what:"all",from:"",to:""}),[a,i]=r.useState([]),[o,l]=r.useState(0),[d,u]=r.useState(null),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=ei(s),y=r.useCallback(async()=>{x(!0),g(null);try{const N=await U(`/api/admin-activity${p}`);i(N.entries),l(N.total),u(N.retentionDays)}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}},[p]);r.useEffect(()=>{const N=window.setTimeout(()=>{y()},250);return()=>window.clearTimeout(N)},[y]);const k=N=>n(v=>({...v,...N}));return e.jsxs(L,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(d??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:N=>k({who:N.target.value}),placeholder:t("activity.whoPlaceholder"),className:_(Ve,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx("select",{value:s.what,onChange:N=>k({what:N.target.value}),className:Ve,children:ti.map(N=>e.jsx("option",{value:N,children:t(`activity.what.${N}`)},N))})]}),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:N=>k({from:N.target.value}),className:Ve})]}),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:N=>k({to:N.target.value}),className:Ve})]}),e.jsx("button",{type:"button",onClick:()=>{y()},disabled:c,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:c?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${p}`,download:!0,className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12.5px] font-medium text-ink hover:bg-control/70",children:[e.jsx(gs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:t("activity.error",{message:m})}),!m&&a.length===0&&!c&&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((N,v)=>e.jsx(Sr,{entry:N},`${N.at}-${v}`))}),o>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(o)})})]})}function Er(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(o=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(o))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Ar({domain:s,serverIpv4:n}){const a=Er(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([o,l])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0",children:l?e.jsx(Re,{command:l,copyLabel:t("settings.domain.copyField",{field:o})},l):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},o))}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Ir(s){return`bots.example.com {
|
|
1
|
+
import{m as Ne,u as K,r,j as e,t,cj as te,v as Y,ck as L,c as _,d as H,p as oe,E as Ze,g as U,aJ as sn,aW as ds,P as Te,R as xe,cl as Re,aM as Ge,cm as nn,cn as an,co as rn,cp as ln,as as on,cq as At,cr as $e,cs as us,ct as cn,cu as dn,cv as un,cw as It,cx as xn,a9 as pn,O as ke,a4 as mn,bf as gn,T as we,w as mt,cy as hn,cz as xs,cA as fn,cB as Ye,cC as bn,ag as Pt,cD as yn,bc as vn,cE as jn,cF as Rt,cG as kn,au as ps,cH as ms,cI as Nn,av as wn,a6 as Sn,cJ as Cn,X as De,y as En,b0 as le,b1 as ue,q as An,cK as gs,aa as In,aw as Pn,x as ut,cL as hs,cM as fs,cN as bs,bi as Rn,cO as Bn,bI as Dn,cP as Tn,cQ as ze,ax as zn,cR as Mn,cS as On,cT as Un,cU as ys,aY as vs,aZ as je,a_ as Be,aX as Ln,cV as _n,B as Fn,a$ as Bt,b2 as $n,S as js,cW as Kn,cX as Hn,cY as Vn,cZ as Wn,c_ as qn,c$ as Jn,at as Gn,d0 as Dt,d1 as Yn,d2 as Xn,d3 as Tt,ba as ks,aj as Qn,d4 as Zn,d5 as ea,Z as ta,aG as sa,bZ as ot,M as Ns,d6 as na,aF as aa,d7 as ia,b$ as zt,d8 as ra,o as la,aQ as oa,d9 as ca,da,db as ua,dc as xa,br as ws,bq as pa,be as ma,b_ as ga,bB as ha,dd as fa,de as ba,df as ya,dg as va,dh as ja,di as ka,dj as Na,dk as wa,dl as Sa,dm as Ca,dn as Ea,dp as Aa,dq as Ia,dr as Pa,ds as Ra,dt as Ba,du as Da,dv as Ta,dw as za,dx as Ma,dy as Oa,dz as Ua,dA as La,dB as _a,dC as Fa,dD as $a,dE as Ka,dF as Ha,dG as Va,dH as Wa,dI as qa}from"./index-C8xb62XS.js";import{a as Ja,M as Ga,w as Ya,A as me,b as Xa,O as Qa,V as Za,c as ei,B as ti}from"./MacLocalControl-B28RbdCS.js";import{a as si,A as ni,w as ai,d as ii,b as Mt}from"./activity-BAVWO0Zj.js";import{b as ri}from"./RoutinesPage-DOosRYDK.js";import{DefaultBotSettings as li}from"./NewBotDialog-dMWDs5xm.js";import{U as xt,C as oi}from"./user-B9lohN4n.js";import"./WebhooksPanel-Cz17K-_O.js";import"./VisibilitySection-DD4ffIR5.js";import"./image-plus-DNIWU160.js";import"./CloudBackendPicker-C5-_arUz.js";const ci=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]],di=Ne("circle-user",ci);const ui=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],xi=Ne("hard-drive",ui);const pi=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ss=Ne("palette",pi);const mi=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],gi=Ne("scroll-text",mi);const hi=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],fi=Ne("server",hi);const bi=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],yi=Ne("terminal",bi);const vi=[["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"}]],ji=Ne("unplug",vi),ki="https://typesafe.ai",Ni={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"},Ot={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"};function wi(s,n=!1){if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Ot[s.reason])return t(Ot[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const a=Ni[s.reason];return a?t(a):t("decider.error.other")}const Si=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Ci(){const{state:s,dispatch:n}=K(),a=s.config?.decider,i=a?.configured??!1,o=i&&a?.included===!0,l=i&&!o,d=a?.enabled??!1,u=a?.jobs.roomRouting??!0,[c,x]=r.useState(""),[m,g]=r.useState(!1),[p,y]=r.useState(!1),[k,N]=r.useState(!1),[v,j]=r.useState(null),[C,w]=r.useState(null),D=c.trim(),I=!D&&l,f=A=>n({type:"configStatus",config:A}),b=async A=>{if(!p){y(!0),j(null);try{f(await U("/api/config",{method:"PUT",body:JSON.stringify({decider:A})}))}catch(P){j(P instanceof Error?P.message:String(P))}finally{y(!1)}}},h=async()=>{if(!(m||!D&&!l)){g(!0),j(null),w(null);try{const A=window.ogb?.setCredential?await window.ogb.setCredential("jevApiKey",D):await U("/api/config",{method:"PUT",body:JSON.stringify({decider:{key:D}})});f(A),x("")}catch(A){j(A instanceof Error?A.message:String(A))}finally{g(!1)}}},E=async()=>{if(k||m||!D&&!i)return;N(!0),w(null),j(null);const A=!D&&o;try{const P=await U("/api/decider/test",{method:"POST",body:JSON.stringify(D?{key:D}:{})});w(P.ok?{ok:!0,text:t("decider.test.ok",{ms:String(P.latencyMs)})}:{ok:!1,text:wi(P,A)})}catch(P){w({ok:!1,text:P instanceof Error?P.message:String(P)})}finally{N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("div",{children:e.jsx(te,{title:t("decider.master"),subtitle:i?void 0:t("decider.masterNeedsKey"),children:e.jsx(Y,{"data-testid":"decider-master","aria-label":t("decider.master"),checked:d,disabled:!i||p||!s.config,onClick:()=>{b({enabled:!d})},className:"cursor-pointer"})})}),e.jsxs(L,{title:t("decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:_("size-1.5 rounded-full",i?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:i?"text-success":void 0,children:o?t("keys.includedWithCloudPro"):i?t("decider.status.connected"):t("decider.status.notConnected")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:c,onChange:A=>{w(null),j(null),x(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void h(),disabled:m,placeholder:l?t("keys.replace"):t("decider.key.placeholder"),"aria-label":t("decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{h()},disabled:m||!D&&!l,title:I?t("keys.removeKey"):t("common.save"),className:_("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",I?"text-danger":"text-ink"),children:m?e.jsx(H,{size:13,className:"animate-spin"}):I?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{E()},disabled:k||m||!D&&!i,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:k?t("keys.testing"):t("keys.test")})]}),v&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:v}),C&&e.jsx("p",{role:"status",className:_("mt-1 text-[12px]",C.ok?"text-success":"text-danger"),children:C.text}),e.jsxs("a",{href:ki,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.key.getKey"),e.jsx(Ze,{size:11,"aria-hidden":"true"})]})]}),e.jsx(L,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(Y,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:d&&u,disabled:!d||p,onClick:()=>{b({jobs:{roomRouting:!u}})},className:"cursor-pointer"})]}),Si.map(A=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(A)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},A))]})})]})}const Cs=["openai","anthropic","google","azure","aws","xai","deepseek","meta","mistral","qwen","moonshot","cohere","openrouter"],Es=128*1024,fe=1024,As=["image/png","image/jpeg","image/webp"],Ei={openai:"OpenAI",anthropic:"Anthropic",google:"Google Gemini",azure:"Microsoft Azure",aws:"Amazon Bedrock (AWS)",xai:"xAI",deepseek:"DeepSeek",meta:"Meta",mistral:"Mistral AI",qwen:"Qwen",moonshot:"Moonshot AI",cohere:"Cohere",openrouter:"OpenRouter"};function Ai(s){const n=s.endsWith("==")?2:s.endsWith("=")?1:0;return Math.floor(s.length*3/4)-n}function Ii(s,n){const a=c=>s[c]*256+s[c+1],i=c=>s[c]+s[c+1]*256,o=c=>s[c]+s[c+1]*256+s[c+2]*65536,l=c=>s[c]+s[c+1]*256+s[c+2]*65536+s[c+3]*16777216,d=c=>s[c]*16777216+s[c+1]*65536+s[c+2]*256+s[c+3];if(n==="image/png")return s.length<33||s.slice(0,8).join(",")!=="137,80,78,71,13,10,26,10"||String.fromCharCode(...s.slice(12,16))!=="IHDR"||s.slice(-8).join(",")!=="73,69,78,68,174,66,96,130"?null:{width:d(16),height:d(20)};if(n==="image/jpeg"){if(s.length<12||s[0]!==255||s[1]!==216||s.at(-2)!==255||s.at(-1)!==217)return null;for(let c=2;c+8<s.length;){if(s[c]!==255){c+=1;continue}const x=s[c+1];if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(x))return{height:a(c+5),width:a(c+7)};if(x===216||x===217||x===1||x>=208&&x<=215){c+=2;continue}const m=a(c+2);if(m<2)return null;c+=m+2}return null}if(s.length<30||String.fromCharCode(...s.slice(0,4))!=="RIFF"||String.fromCharCode(...s.slice(8,12))!=="WEBP"||l(4)+8!==s.length)return null;const u=String.fromCharCode(...s.slice(12,16));if(u==="VP8X")return{width:o(24)+1,height:o(27)+1};if(u==="VP8L"&&s[20]===47){const c=s[21]|s[22]<<8|s[23]<<16|s[24]<<24;return{width:(c&16383)+1,height:(c>>>14&16383)+1}}return u==="VP8 "&&s[23]===157&&s[24]===1&&s[25]===42?{width:i(26)&16383,height:i(28)&16383}:null}function Pi(s){if(s.kind==="preset")return Cs.includes(s.preset)?null:"Choose a supported provider icon.";const n=/^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/]+={0,2})$/.exec(s.dataUrl);if(!n)return"Upload a PNG, JPEG, or WebP image.";const a=Ai(n[2]);if(a>Es)return"Provider icons must be 128 KB or smaller.";let i;try{i=atob(n[2])}catch{return"The uploaded image is not valid base64."}if(i.length!==a)return"The uploaded image is not valid base64.";const o=Uint8Array.from(i,d=>d.charCodeAt(0)),l=Ii(o,n[1]);return l?l.width<1||l.height<1||l.width>fe||l.height>fe||l.width*l.height>fe**2?`Provider icons must be at most ${fe} × ${fe} pixels.`:null:"The uploaded image is incomplete or does not match its file type."}function Ri(s){return new Promise((n,a)=>{const i=new Image;i.onerror=()=>a(new Error(t("engines.icon.decodeError"))),i.onload=()=>n({width:i.naturalWidth,height:i.naturalHeight}),i.src=s})}async function Bi(s,n=Ri){if(!As.includes(s.type))throw new Error(t("engines.icon.formatError"));if(s.size>Es)throw new Error(t("engines.icon.sizeError"));const a=new Uint8Array(await s.arrayBuffer());let i="";for(let u=0;u<a.length;u+=8192)i+=String.fromCharCode(...a.subarray(u,u+8192));const o={kind:"custom",dataUrl:`data:${s.type};base64,${btoa(i)}`};if(Pi(o))throw new Error(t("engines.icon.invalidError",{dimension:fe}));const d=await n(o.dataUrl);if(d.width<1||d.height<1||d.width>fe||d.height>fe)throw new Error(t("engines.icon.dimensionError",{dimension:fe}));return o}function Di({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(null),d=r.useRef(!1),u=async m=>{if(!d.current){d.current=!0,i(!0),l(null);try{const g=typeof m=="function"?await m():m;await U(`/api/instances/${encodeURIComponent(s.instanceId)}/icon`,{method:"PATCH",body:JSON.stringify({icon:g})}),await n()}catch(g){l(g instanceof Error?g.message:String(g))}finally{d.current=!1,i(!1)}}},c=m=>{const g=m.currentTarget,p=g.files?.[0];p&&u(()=>Bi(p)).finally(()=>{g.value=""})},x=s.icon?.kind==="preset"?s.icon.preset:s.icon?.kind==="custom"?"custom":"default";return e.jsxs("section",{"aria-label":t("engines.icon.label"),className:"mb-3 rounded-xl border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-xl border border-hairline/30 bg-panel",children:e.jsx(sn,{instance:s,size:24})}),e.jsxs("label",{className:"min-w-40 flex-1 text-[12px] font-medium text-ink",children:[t("engines.icon.label"),e.jsxs("select",{"aria-label":t("engines.icon.selectAria",{name:s.displayName}),value:x,disabled:a,onChange:m=>{m.target.value==="default"?u(null):m.target.value!=="custom"&&u({kind:"preset",preset:m.target.value})},className:"mt-1 block w-full rounded-lg border border-hairline/40 bg-inset px-2.5 py-2 text-[12px] text-ink focus:border-accent/60 focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"default",children:t("engines.icon.default")}),s.icon?.kind==="custom"&&e.jsx("option",{value:"custom",children:t("engines.icon.custom")}),Cs.map(m=>e.jsx("option",{value:m,children:Ei[m]},m))]})]}),a&&e.jsx(H,{size:15,"aria-label":t("engines.icon.saving"),className:"animate-spin text-ink-secondary"}),s.icon&&e.jsxs("button",{type:"button",disabled:a,onClick:()=>{u(null)},className:"inline-flex items-center gap-1 rounded-lg px-2 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:[e.jsx(ds,{size:13,"aria-hidden":"true"}),t("engines.icon.reset")]})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-ink-secondary",children:t("engines.icon.help")}),e.jsx("input",{type:"file",accept:As.join(","),disabled:a,onChange:c,"aria-label":t("engines.icon.uploadAria",{name:s.displayName}),className:"mt-2 block w-full text-[11px] text-ink-secondary file:mr-2 file:rounded-lg file:border-0 file:bg-control file:px-2.5 file:py-1.5 file:text-[11px] file:font-medium file:text-ink hover:file:bg-raised-hover disabled:opacity-50"}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Is({instance:s,onSaved:n,onCancel:a}){const{refreshInstances:i}=K(),[o,l]=r.useState(s?.displayName??""),[d,u]=r.useState(s?.claudeAccount?.configDir??""),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=!s||o.trim()!==s.displayName||d.trim()!==s.claudeAccount?.configDir,y=!!(s?.claudeAccount?.configDir&&!d.trim()),k=async()=>{if(!(c||!o.trim()||!p||y)){x(!0),g(null);try{await U(s?`/api/instances/${encodeURIComponent(s.instanceId)}`:"/api/instances/claude-accounts",{method:s?"PATCH":"POST",body:JSON.stringify({displayName:o.trim(),...d.trim()?{configDir:d.trim()}:{}})}),await i().catch(()=>{}),n()}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}}};return e.jsxs("form",{className:"flex min-w-0 flex-col gap-3",onSubmit:N=>{N.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:o,onChange:N=>l(N.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-ink-secondary hover:text-ink",children:t("engines.account.advanced")}),e.jsxs("label",{className:"mt-2 flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.configDir"),e.jsx("input",{value:d,onChange:N=>u(N.target.value),placeholder:t(s?"engines.account.defaultDir":"engines.account.configDirPlaceholder"),maxLength:4096,spellCheck:!1,disabled:c,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50"})]}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.configDirHint")}),s&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.changeDirHint")})]}),!s&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("engines.account.addHint")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex justify-end gap-2",children:[a&&e.jsx("button",{type:"button",onClick:a,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!o.trim()||!p||y,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),s?t("common.save"):t("engines.account.add")]})]})]})}function Ti(){const[s,n]=r.useState(!1);return s?e.jsx("div",{className:"rounded-xl border border-hairline/40 p-3",children:e.jsx(Is,{onSaved:()=>n(!1),onCancel:()=>n(!1)})}):e.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-fit 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",children:[e.jsx(Te,{size:13}),t("engines.account.add")]})}function zi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(!1),[c,x]=r.useState(!1),[m,g]=r.useState(!1),[p,y]=r.useState(null),k=s.claudeAccount;if(!k)return null;const N=n.bots.filter(h=>h.modelSelection.instanceId===s.instanceId).length,v=N>0,j=s.snapshot.authenticated===!0,C=s.snapshot.account?.method==="api-key",w=j&&s.authentication?.signOut===!0&&!C,D=j?C?t("engines.account.apiKey"):[s.snapshot.account?.email,s.snapshot.account?.organization].filter(Boolean).join(" · "):"",I=async()=>{if(!(o||m)){l(!0),y(null);try{await i()}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},f=async()=>{if(u(!1),!(o||m||k.isDefault||v)){l(!0),y(null);try{await U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"}),await i().catch(()=>{})}catch(h){y(h instanceof Error?h.message:String(h))}finally{l(!1)}}},b=async()=>{if(x(!1),!(o||m||!w)){g(!0),y(null);try{const{instances:h}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:h})}catch(h){y(h instanceof Error?h.message:String(h))}finally{g(!1)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:_("min-w-0 break-words",j?"text-success":"text-ink-secondary"),children:[j?t("engines.account.connected"):s.snapshot.authenticated===!1?t("model.signInRequired"):t("engines.account.unknown"),D&&` · ${D}`]}),k.isDefault&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:t("engines.account.default")}),e.jsxs("button",{type:"button",onClick:()=>{I()},disabled:o||m,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o&&"animate-spin")}),t("engines.account.check")]})]}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:t("engines.account.signInHint")}),k.signInShell==="powershell"&&e.jsx("p",{className:"text-ink-secondary",children:t("engines.account.powershell")}),e.jsx(Re,{command:k.signInCommand,copyLabel:t("engineSetup.copyCommand")}),e.jsx("fieldset",{disabled:o||m,className:"min-w-0",children:e.jsx(Is,{instance:s,onSaved:()=>{}},`${s.displayName}:${k.configDir}`)}),w&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>x(!0),disabled:o||m,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:m?t("engines.account.signingOut"):t("engines.account.signOut")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t("engines.account.signOutHint")}),v&&e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-warning",children:t("engines.account.signOutAssigned",{count:String(N)})})]}),!k.isDefault&&e.jsxs("div",{className:"border-t border-hairline/40 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o||m||v,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:t("engines.account.remove")}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:t(v?"engines.account.assigned":"engines.account.removeHint")})]})]})]}),p&&e.jsx("p",{role:"alert",className:"text-danger",children:p}),e.jsx(Ge,{open:d,title:t("engines.account.removeTitle",{name:s.displayName}),body:t("engines.account.removeHint"),confirmLabel:t("engines.account.remove"),tone:"neutral",onCancel:()=>u(!1),onConfirm:()=>{f()}}),e.jsx(Ge,{open:c,title:t("engines.account.signOutTitle",{name:s.displayName}),body:t("engines.account.signOutHint"),confirmLabel:t("engines.account.signOut"),onCancel:()=>x(!1),onConfirm:()=>{b()}})]})}function Mi(){const{dispatch:s}=K(),[n,a]=r.useState(!1),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(null),x=async()=>{if(!(l||!i.trim())){d(!0),c(null);try{const{instances:m}=await U("/api/instances/chatgpt-accounts",{method:"POST",body:JSON.stringify({displayName:i.trim()})});s({type:"instances",instances:m}),a(!1),o("")}catch(m){c(m instanceof Error?m.message:String(m))}finally{d(!1)}}};return n?e.jsxs("form",{className:"min-w-0 space-y-3 rounded-xl border border-hairline/40 p-3",onSubmit:m=>{m.preventDefault(),x()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("engines.account.name"),e.jsx("input",{value:i,onChange:m=>o(m.target.value),placeholder:t("engines.account.namePlaceholder"),maxLength:80,required:!0,disabled:l,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("engineSetup.chatgpt.addAccountHint")}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a(!1),disabled:l,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:l||!i.trim(),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[l&&e.jsx(H,{size:13,className:"animate-spin"}),t("engineSetup.chatgpt.addAccount")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex w-fit 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",children:[e.jsx(Te,{size:13}),t("engineSetup.chatgpt.addAccount")]})}function Oi({instance:s}){const{state:n,dispatch:a,refreshInstances:i}=K(),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),m=s.snapshot.account?.email,g=s.authentication?.signOut===!0,p=s.snapshot.chatgptPlan===!0,y=t(p?"engineSetup.chatgpt.signOutHint":"engineSetup.device.signOutHint"),k=n.bots.filter(j=>j.modelSelection.instanceId===s.instanceId).length,N=async()=>{if(!o){l("check"),x(null);try{await i()}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}},v=async()=>{if(u(!1),!(o||!g)){l("signOut"),x(null);try{const{instances:j}=await U(`/api/instances/${encodeURIComponent(s.instanceId)}/auth/sign-out`,{method:"POST"});a({type:"instances",instances:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{l(null)}}};return e.jsxs("div",{className:"mt-2 space-y-2 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 break-words text-success",children:[e.jsx(oe,{size:13,className:"shrink-0"}),t(p?"engineSetup.chatgpt.connectedAccount":"engineSetup.device.connectedAccount"),m&&e.jsxs("span",{className:"text-ink-secondary",children:["· ",m]})]}),e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:o!==null,className:"flex items-center gap-1 text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(o==="check"&&"animate-spin")}),t("engines.account.check")]})]}),p&&e.jsx(nn,{instanceId:s.instanceId},s.instanceId),g&&e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-ink-secondary hover:text-ink",children:t("engines.account.manage")}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"leading-relaxed text-ink-secondary",children:y}),k>0&&e.jsx("p",{className:"leading-relaxed text-warning",children:t(p?"engineSetup.chatgpt.signOutAssigned":"engineSetup.device.signOutAssigned",{count:String(k)})}),e.jsx("button",{type:"button",onClick:()=>u(!0),disabled:o!==null,className:"text-danger hover:underline disabled:no-underline disabled:opacity-50",children:o==="signOut"?t("engineSetup.device.signingOut"):t("engineSetup.device.signOut")})]})]}),c&&e.jsx("p",{role:"alert",className:"text-danger",children:c}),e.jsx(Ge,{open:d,title:t("engineSetup.device.signOutTitle"),body:y,confirmLabel:t("engineSetup.device.signOut"),onCancel:()=>u(!1),onConfirm:()=>{v()}})]})}function Ut(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function Ui({instance:s,initial:n={kind:"idle"}}){const[a,i]=r.useState(n),[o,l]=r.useState(null),d=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,u=async()=>{l(null),i({kind:"scanning"});try{const m=await U(d);i(m.folders>0?{kind:"found",bytes:m.bytes,complete:m.complete}:{kind:"none"})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},c=async()=>{l(null),i({kind:"deleting"});try{const m=await U(`${d}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:m.freedBytes,remaining:m.remaining})}catch(m){l(m instanceof Error?m.message:String(m)),i({kind:"idle"})}},x=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xi,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||x)&&e.jsxs("button",{type:"button",onClick:()=>{u()},disabled:x,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Ut(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{c()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Ut(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function Li({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[o,l]=r.useState(s.cliCandidates??null),[d,u]=r.useState(""),[c,x]=r.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[m,g]=r.useState(!1),[p,y]=r.useState(null),[k,N]=r.useState(!1),[v,j]=r.useState(null),C=r.useRef(!1);r.useEffect(()=>{C.current||(C.current=!0,U(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:h})=>{l(h),s.cli&&(h.includes(s.cli)?u(s.cli):x(s.cli))}).catch(()=>l(h=>h??[])))},[n,s.cli]);const w=c.trim()||d,D=w!==(s.cli??""),I=m||k;r.useEffect(()=>{y(null)},[w]);const f=()=>{if(I||!w||!D)return;N(!0),j(null);const h=w;U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:h})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(E=>j(E.message)).finally(()=>N(!1))},b=()=>{I||!w||!D||(g(!0),j(null),U("/api/cli-test",{method:"POST",body:JSON.stringify({cli:w,driver:s.driverKind})}).then(h=>{y(h),h.ok&&f()}).catch(h=>j(h.message)).finally(()=>g(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[o!==null&&o.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:c.trim()?"":d,onChange:h=>{u(h.target.value),x("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:I,className:"w-full appearance-none rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 font-mono text-[12px] text-ink focus:outline-none disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),o.map(h=>e.jsx("option",{value:h,children:h},h))]}),e.jsx(pn,{size:13,className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"})]}),e.jsx("input",{type:"text",value:c,onChange:h=>x(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),!(!w||!D)&&b())},placeholder:o?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:I,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),p&&!p.ok&&p.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(ke,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:p.message})})]}),p?.ok&&p.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:p.version})}),v&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:v}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),p&&!p.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y(null),disabled:I,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>f(),disabled:I,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:k?e.jsx(H,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:b,disabled:I||!w||!D,className:_("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:I?e.jsx(H,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{size:13}),t("common.save")]})})]})]})}function _i({instance:s}){const{refreshInstances:n}=K(),[a,i]=r.useState(!1),o=on(a),[l,d]=r.useState(!1),[u,c]=r.useState(!1),[x,m]=r.useState(null),[g,p]=r.useState(null),y=r.useRef(null);r.useEffect(()=>{y.current!==null&&y.current!==s.cli&&i(!1),y.current=s.cli??null},[s.cli]);const k=()=>{l||u||(d(!0),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(j=>p(j.message)).finally(()=>d(!1)))},N=()=>{l||u||(c(!0),m(null),p(null),U(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:j})=>{m(j),await Promise.resolve(n()).catch(()=>{})}).catch(j=>p(j.message)).finally(()=>c(!1)))},v=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.readOnly?e.jsxs(At,{instance:s,children:[v,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!$e(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(At,{instance:s,children:[v,e.jsx(Di,{instance:s}),!$e(s)&&e.jsx(us,{instance:s,intent:s.access==="custom"?"inject":"cloud",unframed:!0}),$e(s)&&e.jsx(cn,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(dn,{update:s.snapshot.update,instance:s,className:"mt-3"}),s.snapshot.warning&&e.jsx(un,{warning:s.snapshot.warning,className:"mt-3"}),s.claudeAccount&&e.jsx(zi,{instance:s}),$e(s)&&s.snapshot.authenticated===!0&&((s.authentication?.method==="device-code"||s.authentication?.method==="browser-pkce")&&It(s.driverKind)==="codex"?e.jsx(Oi,{instance:s}):s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t(xn[It(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&!s.claudeAccount&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(oe,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(Ui,{instance:s}),e.jsxs("details",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[11.5px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:N,disabled:l||u,className:"flex shrink-0 items-center gap-1 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[u?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(xe,{size:12}),u?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:k,disabled:l||u,className:"shrink-0 text-[11.5px] text-ink-secondary hover:text-ink disabled:opacity-50",children:l?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{onClick:()=>i(j=>!j),disabled:u,"aria-expanded":a,className:_("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),x&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:x})}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g}),o.shown&&e.jsx("div",{className:o.className,...o.exitProps,children:e.jsx(Li,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})]})}function Fi(){const{state:s}=K(),n=s.instances.filter(a=>a.readOnly||a.cli!==void 0||a.cliDefault!==void 0||a.snapshot.state==="unavailable"||an(a));return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(rn,{})]}),e.jsx(ln,{instances:n,renderEngine:a=>e.jsx(_i,{instance:a})}),e.jsxs("div",{className:"space-y-3 border-t border-hairline/40 pt-4",children:[e.jsx(Ti,{}),s.instances.some(a=>a.snapshot.chatgptPlan&&!a.readOnly&&!a.snapshot.authenticationUnavailableReason)&&e.jsx(Mi,{})]})]})}const $i=[1e3,2e3,4e3];function Ki(s){return new Promise(n=>window.setTimeout(n,s))}const Hi={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Vi={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 gt(s){return t(Vi[s])}function Wi(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function qi(s){return gt(Wi(s))}function Ji(s){return s.inUse?"in-use":s.state==="removing"?"removing":["archived","stopped"].includes(s.state)?"sleeping":["archiving","stopping"].includes(s.state)?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning","starting"].includes(s.state)?"starting":"attention"}function Ps(s,n,a){const i={...a},o=new Set(s.map(d=>d.boxId)),l=s.flatMap(d=>{const u=a[d.boxId];return u==="deleted"?[]:u==="deleting"?[{...d,state:"removing"}]:u!=="sleeping"?[d]:["archived","stopped"].includes(d.state)?(delete i[d.boxId],[d]):[{...d,state:"archived"}]});for(const d of n)a[d.boxId]!=="sleeping"||o.has(d.boxId)||l.push({...d,state:"archived"});for(const[d,u]of Object.entries(a))(u==="deleted"||u==="deleting")&&!o.has(d)&&delete i[d];return{instances:l,overrides:i}}function Gi(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Ps(Array.isArray(s.instances)?s.instances:[],n,a)}function Yi(s){return["idle","ready","running"].includes(s.state)}function Xi(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 ht(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}const Qi={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function Ke(s,n){return[Qi[s],{signal:n}]}function ft(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Zi(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:ft(`/api/bots/${s.botId}/local-computer/remove`,{})}}function er(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:ft(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function tr(s){const n=ht(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:ft(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name})}}function ct(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function sr({instances:s,configured:n,sshAlias:a,loading:i,removingName:o,error:l,unavailableReason:d,onRefresh:u,onRemove:c}){return e.jsxs(L,{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??t("vm.vps.configuredFallback")}):n===!1?t("vm.vps.needsAlias"):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:u,disabled:i||o!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(i&&"animate-spin")})," ",t("vm.refresh")]})]}),l&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:l}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):d?t("vm.vps.unavailable",{reason:d}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":i||o!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children: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(H,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):d?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",d]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(fi,{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((x,m)=>{const g=Xi(x),p=gt(g),y=o===x.name,k=ht(x.name);return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.vps.orphan",{id:k}):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="stopped"||g==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:i||x.inUse||o!==null,"aria-busy":y||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:[y?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("vm.vps.remove")]})]},x.name)})})]})}function nr({instances:s,configured:n,loading:a,pending:i,error:o,unavailableReason:l,onRefresh:d,onSleep:u,onDelete:c}){return e.jsxs(L,{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?t("vm.cloud.needsKey"):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):l?t("vm.cloud.unavailable",{reason:l}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{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(mt,{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((x,m)=>{const g=Ji(x),p=gt(g),y=i?.boxId===x.boxId,k=Yi(x),N=g==="removing";return e.jsxs("div",{className:_("flex items-start justify-between gap-3 px-3 py-3",m>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium text-ink",children:x.orphaned?t("vm.cloud.orphan"):x.ownerName}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",x.inUse||g==="running"?"bg-success/15 text-success":g==="sleeping"||g==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:p})]}),e.jsxs("div",{className:"mt-1 break-all text-[11.5px] text-ink-secondary",children:[x.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",x.name]}),x.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] 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:()=>u(x),disabled:a||x.inUse||i!==null||!k,"aria-busy":y&&i?.action==="sleep"?!0:void 0,title:k?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:p.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:[y&&i?.action==="sleep"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ga,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>c(x),disabled:a||x.inUse||i!==null||N,"aria-busy":y&&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:[y&&i?.action==="delete"?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]})]},x.boxId)})})]})}function ar({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:o,unavailableReason:l,onRefresh:d,onDelete:u}){return e.jsxs(L,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:l?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12,className:_(a&&"animate-spin")})," ",t("vm.refresh")]})]}),o&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:o}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):l?t("vm.perBot.unavailable",{reason:l}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):l?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:14,className:"shrink-0 text-warning"})," ",l]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((c,x)=>{const m=qi(c),g=i===c.botId,p=c.managed===!0;return e.jsxs("div",{className:_("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-[13.5px] font-medium text-ink",children:c.name}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px]",p?c.inUse||c.ready?"bg-success/15 text-success":c.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:m})]}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Hi[c.destination])})}),!p&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:t("vm.perBot.unmanaged")}),p&&c.problem&&!c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-warning",children:c.problem}),p&&c.inUse&&e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),p&&e.jsxs("button",{type:"button",onClick:()=>u(c),disabled:a||c.inUse||i!==null,"aria-busy":g||void 0,title:c.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:c.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:[g?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12}),t("common.delete")]})]},c.botId)})})]})}function He({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:_("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(oe,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:_("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function Ie({action:s,pending:n,children:a,onClick:i,danger:o=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:_("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[12.5px] font-medium disabled:opacity-50",o?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(H,{size:13,className:"animate-spin"}),a]})}const Rs=5,Bs=1440,ir=480;function rr(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Rs&&a<=Bs?a:null}function lr({minutes:s,disabled:n,onSave:a}){const[i,o]=r.useState(String(s)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1);r.useEffect(()=>{l||o(String(s))},[s,l]);const g=async()=>{if(!l||x)return;const p=rr(i);if(p===null){c(t("vm.idle.range"));return}m(!0);try{await a(p),o(String(p)),d(!1),c("")}catch(y){c(y instanceof Error?y.message:t("vm.idle.error"))}finally{m(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[11.5px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:_("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",u?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Rs,max:Bs,step:1,inputMode:"numeric",value:i,disabled:n||x,"aria-invalid":!!u,"aria-describedby":u?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:p=>{o(p.target.value),d(!0),c("")},onBlur:()=>{g()},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[12.5px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),u?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:u}):null]})}function Lt(){const s=K().state.config?.cloudHome===!0,[n,a]=r.useState(null),[i,o]=r.useState(!0),[l,d]=r.useState(null),u=r.useRef(null);r.useEffect(()=>()=>u.current?.abort(),[]);const[c,x]=r.useState(null),[m,g]=r.useState(!1),[p,y]=r.useState(0),[k,N]=r.useState([]),[v,j]=r.useState(2),[C,w]=r.useState(!1),[D,I]=r.useState(null),[f,b]=r.useState(null),[h,E]=r.useState(null),[A,P]=r.useState(0),[V,J]=r.useState([]),[$,W]=r.useState(null),[z,G]=r.useState(!0),[ne,R]=r.useState(null),[F,q]=r.useState(null),[ce,pe]=r.useState(null),[be,ye]=r.useState(0),X=r.useRef([]),se=r.useRef({}),[Se,ge]=r.useState([]),[ee,Le]=r.useState(null),[T,Q]=r.useState(null),[ie,ae]=r.useState(!0),[Me,et]=r.useState(null),[qs,yt]=r.useState(null),[Js,vt]=r.useState(null),[Gs,Ys]=r.useState(0),[Xs,ve]=r.useState(""),Oe=r.useCallback(async S=>{const B=await fetch(...Ke("status",S)),M=await B.json().catch(()=>({}));if(!S?.aborted){if(!B.ok)throw new Error(M.error??t("vm.err.status",{code:B.status}));return a(M),x(null),M}},[]),tt=r.useCallback(async S=>{const B=await fetch(...Ke("local-vms",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.inventory",{code:B.status}));const O=M;N(O.instances),j(O.maxInstances),b(O.available?null:O.problem??t("vm.err.runtimeUnavailable")),I(null)},[]),Ue=r.useCallback(async S=>{const B=await fetch(...Ke("cloud",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.cloudInventory",{code:B.status}));const O=M,Z=Gi(O,X.current,se.current);se.current=Z.overrides,X.current=Z.instances,J(Z.instances),W(O.configured===!0),q(O.available||!O.configured?null:O.problem??t("vm.err.cloudUnavailable")),R(null)},[]),st=r.useCallback(async S=>{const B=await fetch(...Ke("vps",S)),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.err.vpsInventory",{code:B.status}));const O=M;ge(Array.isArray(O.instances)?O.instances:[]),Le(O.configured===!0),Q(typeof O.sshAlias=="string"?O.sshAlias:null),yt(O.available||!O.configured?null:O.problem??t("vm.err.vpsUnavailable")),et(null)},[]);r.useEffect(()=>{if(s)return;let S=!0,B,M;const O=async()=>{M=new AbortController;try{await Oe(M.signal)}catch(Z){S&&!(Z instanceof DOMException&&Z.name==="AbortError")&&(a(null),x(Z instanceof Error?Z.message:String(Z)))}finally{S&&(o(!1),B=window.setTimeout(()=>{O()},5e3))}};return O(),()=>{S=!1,M?.abort(),B!==void 0&&window.clearTimeout(B)}},[s,Oe,p]),r.useEffect(()=>{if(n?.mode!=="per-bot"){N([]),w(!1),I(null),b(null);return}const S=new AbortController;return w(!0),tt(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||I(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||w(!1)}),()=>S.abort()},[A,tt,n?.mode]),r.useEffect(()=>{const S=new AbortController;return G(!0),Ue(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||q(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||G(!1)}),()=>S.abort()},[be,Ue]),r.useEffect(()=>{const S=new AbortController;return ae(!0),st(S.signal).catch(B=>{B instanceof DOMException&&B.name==="AbortError"||yt(B instanceof Error?B.message:String(B))}).finally(()=>{S.signal.aborted||ae(!1)}),()=>S.abort()},[st,Gs]);const nt=async(S,B)=>{const M=await fetch(`/api/local-computer/${S}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:B}),O=await M.json().catch(()=>({})),Z={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!M.ok)throw new Error(O.error??t(Z[S]));return B.throwIfAborted(),a(O),O},jt=S=>window.ogb?.confirm?window.ogb.confirm(S):window.confirm(S),Ce=async S=>{if(l!==null||u.current)return;const B=new AbortController;u.current=B,d(S),x(null);try{if(S==="remove"&&!await jt(t("vm.confirm.deleteShared"))||S==="recreate"&&!await jt(t("vm.confirm.recreate")))return;let M;if(S==="recreate"?(await nt("remove",B.signal),M=await nt("run",B.signal)):M=await nt(S,B.signal),(S==="run"||S==="start"||S==="recreate")&&(M=await Ya(M,async()=>await Oe(B.signal)??M,B.signal),!M.ready))throw new Error(M.problem??t("vm.err.start"));await Oe(),ve(S==="remove"?t("vm.announce.deleted"):S==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(M){if(B.signal.aborted)return;x(M instanceof Error?M.message:String(M))}finally{u.current=null,B.signal.aborted||d(null)}},kt=async(S,B)=>{g(!0),x(null);try{const M=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:S,maxInstances:B}})}),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.policyError"));a(Z=>Z&&{...Z,mode:S,max_instances:B}),await Oe()}catch(M){x(M instanceof Error?M.message:String(M))}finally{g(!1)}},Qs=async S=>{const B=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:S}})}),M=await B.json().catch(()=>({}));if(!B.ok)throw new Error(M.error??t("vm.idle.error"));a(O=>O&&{...O,idle_timeout_ms:S*6e4})},Zs=async S=>{if(!S.managed){I(t("vm.unmanagedError"));return}const B=ct(Zi(S),M=>window.confirm(M));if(B){E(S.botId),I(null);try{const M=await fetch(...B),O=await M.json().catch(()=>({}));if(!M.ok)throw new Error(O.error??t("vm.deleteError"));await tt(),ve(t("vm.announce.deletedBot",{name:S.name}))}catch(M){I(M instanceof Error?M.message:String(M))}finally{E(null)}}},Nt=async(S,B)=>{const M=ct(er(S,B),O=>window.confirm(O));if(M){pe({boxId:B.boxId,action:S}),R(null),ve("");try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t(S==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const rt=S==="delete"&&Z?.pending===!0;se.current={...se.current,[B.boxId]:S==="delete"?rt?"deleting":"deleted":"sleeping"};const lt=Ps(X.current,X.current,se.current);se.current=lt.overrides,X.current=lt.instances,J(lt.instances);const Ee=B.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:B.ownerName??""});if(ve(rt?`${Ee}: ${t("vm.state.removing")}.`:t(S==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ee})),rt){for(const de of $i){await Ki(de);try{await Ue()}catch{}if(se.current[B.boxId]!=="deleting"){ve(t("vm.announce.cloudDeleted",{subject:Ee}));return}}const Ae={...se.current};delete Ae[B.boxId],se.current=Ae;const Fe=X.current.map(de=>de.boxId===B.boxId?{...de,state:B.state}:de);X.current=Fe,J(Fe);try{await Ue(),X.current.some(de=>de.boxId===B.boxId)||ve(t("vm.announce.cloudDeleted",{subject:Ee}))}catch(de){const tn=de instanceof Error?de.message:String(de);R(`${Ee}: ${t("vm.state.removing")}. ${tn}`)}return}try{await Ue()}catch(Ae){const Fe=Ae instanceof Error?Ae.message:String(Ae);R(t(S==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ee,detail:Fe}))}}catch(O){R(O instanceof Error?O.message:String(O))}finally{pe(null)}}},en=async S=>{const B=ht(S.name),M=ct(tr(S),O=>window.confirm(O));if(M){vt(S.name),et(null);try{const O=await fetch(...M),Z=await O.json().catch(()=>({}));if(!O.ok)throw new Error(Z.error??t("vm.vpsRemoveError"));await st(),ve(t("vm.announce.vpsRemoved",{subject:S.orphaned?t("vm.announce.orphanVps",{id:B}):t("vm.confirm.ownedVps",{name:S.ownerName??""})}))}catch(O){et(O instanceof Error?O.message:String(O))}finally{vt(null)}}},he=n?.commands,_e=n?.ready===!0,wt=n?.container!=="missing",St=!!(wt&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Ct=!i&&!n,Et=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),re=n?.mode==="per-bot",at=re&&n?.runtime==="container",it=re?!!(n?.daemonUp&&n?.image&&!at):_e;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Xs}),e.jsx(nr,{instances:V,configured:$,loading:z,pending:ce,error:ne,unavailableReason:F,onRefresh:()=>ye(S=>S+1),onSleep:S=>{Nt("sleep",S)},onDelete:S=>{Nt("delete",S)}}),e.jsx(sr,{instances:Se,configured:ee,sshAlias:T,loading:ie,removingName:Js,error:Me,unavailableReason:qs,onRefresh:()=>Ys(S=>S+1),onRemove:S=>{en(S)}}),e.jsx(Ja,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(L,{title:t("vm.main.title"),subtitle:re?t("vm.main.perBotSubtitle",{host:Et}):t("vm.main.sharedSubtitle",{host:Et}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:_("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12.5px]",it?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(H,{size:12,className:"animate-spin"}):it?e.jsx(oe,{size:12}):e.jsx(mn,{size:9}),i?t("common.checking"):Ct?t("vm.main.statusUnavailable"):re&&it?t("vm.main.readyPerBot"):at?t("vm.main.perBotUnsupported"):_e?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{o(!0),y(S=>S+1),P(S=>S+1)},disabled:i||l!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(xe,{size:12})," ",t("vm.main.recheck")]}),_e&&!re&&e.jsxs("a",{href:n?.viewer_url??he?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12.5px] text-ink hover:bg-control",children:[e.jsx(Ze,{size:12})," ",t("vm.main.watch")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c})]}),e.jsxs(L,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((S,B)=>e.jsx("button",{type:"button",disabled:!n||m,onClick:()=>{kt(S,n?.max_instances??2)},className:_("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",B>0&&"border-l border-hairline/40",n?.mode===S?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:S==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},S))}),re&&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-[11.5px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx("select",{"aria-label":t("vm.isolation.maxAria"),value:n?.max_instances??2,disabled:!n||m,onChange:S=>{kt(n?.mode??"shared",Number(S.target.value))},className:"rounded-lg border border-hairline/40 bg-control px-2.5 py-1.5 text-[13px] text-ink disabled:opacity-50",children:[1,2,3,4,5,6,7,8].map(S=>e.jsx("option",{value:S,children:S},S))})]}),e.jsx(lr,{minutes:n?Math.round(n.idle_timeout_ms/6e4):ir,disabled:!n||m,onSave:Qs}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(H,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(L,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(He,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),he?.install?e.jsx(Re,{command:he.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(He,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?he?.runtimeStart?e.jsx(Re,{command:he.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(He,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(Ie,{action:"pull",pending:l,onClick:()=>{Ce("pull")},children:t("vm.setup.prepare")}),he?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.pull})})]})]}),e.jsxs(He,{n:4,title:re?t("vm.setup.step4PerBot"):St?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!re&&_e,children:[re?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:at?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):St?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(Ie,{action:"recreate",pending:l,onClick:()=>{Ce("recreate")},danger:!0,children:[e.jsx(ds,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(Ie,{action:"start",pending:l,onClick:()=>{Ce("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{action:"run",pending:l,onClick:()=>{Ce("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,he?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(Re,{command:he.run})})]})]})]})}),re&&e.jsx(ar,{instances:k,maxInstances:v||n?.max_instances||2,loading:C,deletingBotId:h,error:D,unavailableReason:f,onRefresh:()=>P(S=>S+1),onDelete:S=>{Zs(S)}}),Ct&&e.jsx(L,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(ke,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(L,{title:t("vm.safety.title"),subtitle:re?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[wt&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(Ie,{action:"stop",pending:l,onClick:()=>{Ce("stop")},children:[e.jsx(gn,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(Ie,{action:"remove",pending:l,onClick:()=>{Ce("remove")},danger:!0,children:[e.jsx(we,{size:12})," ",re?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.20.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function or(s,n){return s.error?{kind:"error",title:t("remote.status.attention"),detail:s.error}:n&&s.tailnetName?{kind:"ready",title:t("remote.tailscale.ready",{name:s.tailnetName}),detail:t("remote.tailscale.readyDetail")}:s.tailscale?{kind:"magicdns",title:t("remote.tailscale.magicDns"),detail:t("remote.tailscale.magicDnsDetail")}:s.enabled?{kind:"unavailable",title:t("remote.tailscale.notConnected"),detail:t("remote.tailscale.notConnectedDetail")}:{kind:"unchecked",title:t("remote.tailscale.already"),detail:t("remote.tailscale.alreadyDetail")}}function cr(s){return s.tailscaleFallback?{title:t("remote.pairing.tailscale.title"),subtitle:t("remote.pairing.tailscale.subtitle")}:s.localFallback?{title:t("remote.pairing.wifi.title"),subtitle:t("remote.pairing.wifi.subtitle")}:{title:t("remote.pairing.https.title"),subtitle:t("remote.pairing.https.subtitle")}}function dr(s){if(s.error)return{label:t("remote.status.attention"),good:!1};if(!s.enabled)return{label:t("remote.status.off"),good:!1};const n=s.devices.length;return n?{label:`${n} ${n===1?"device":"devices"} paired`,good:!0}:null}const ur=s=>{const n=Math.round((Date.now()-s)/1e3);if(n<90)return t("remote.time.justNow");const a=Math.round(n/60);if(a<60)return t("remote.time.minutes",{count:a});const i=Math.round(a/60);return i<24?t("remote.time.hours",{count:i}):t("remote.time.days",{count:Math.round(i/24)})},xr=s=>{try{return new URL(s).host}catch{return s}};function pr({profileEmail:s="",focusRequest:n=0}){const a=hn(s),i=a.state,o=r.useRef(null),l=r.useRef(0),d=!!i;r.useEffect(()=>{n?l.current!==n&&xs(o.current)&&(l.current=n):l.current=0},[n,d]);const u=K().state.config?.managedPolicy,c=u?.remoteAccess===!1?t("policy.remoteBlocked",{organization:u.organizationName}):null,x=u?.remoteAccess===!1?t("policy.managedBy",{organization:u.organizationName}):null;if(!fn())return e.jsx(L,{title:t("remote.desktopOnly.title",{app:Ye().name}),subtitle:t("remote.desktopOnly.subtitle")});if(!i)return e.jsx(L,{title:t("remote.title"),subtitle:t("remote.checking"),children:e.jsx(H,{size:15,className:"animate-spin text-ink-secondary"})});const m=i.devices.length,g=dr(i),p=bn(a.account,a.accountError),y=cr(a),k=or(i,a.tailscaleAvailable),N=i.endpoints?.find(j=>j.kind==="hosted"),v=[i.tailnetName?{label:"Tailscale",value:`${i.tailnetName}:${i.port}`}:null,i.lan?{label:t("remote.connection.wifi"),value:`${i.lan}:${i.port}`}:null,i.discovery?.name?{label:t("remote.connection.discovery"),value:`${i.discovery.name}:${i.port}`}:null,...(i.addresses??[]).filter(j=>j!==i.lan&&j!==i.tailscale).map((j,C)=>({label:t("remote.connection.localRoute",{index:C+1}),value:`${j}:${i.port}`}))].filter(j=>!!j);return e.jsxs("div",{className:"flex flex-col gap-4",children:[c&&e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink-secondary",children:c}),e.jsx("div",{ref:o,tabIndex:-1,"data-phone-pairing":"computer",className:"scroll-mt-4 rounded-xl ring-1 ring-accent/40 focus:outline-none",children:e.jsxs(L,{title:y.title,subtitle:y.subtitle,children:[(g||m>0&&a.hostedReady)&&e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[g&&e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-2.5 py-1 text-[11.5px] ${g.good?"bg-success/10 text-success":"bg-control text-ink-secondary"}`,children:[e.jsx("span",{className:`size-1.5 rounded-full ${g.good?"bg-success":"bg-ink-secondary/50"}`}),g.label]}),m>0&&a.hostedReady&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx(Pt,{size:13,className:"text-accent"})," ",t("remote.worksAway")]})]}),e.jsx(yn,{controller:a,variant:"settings"})]})}),e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-card",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-3.5 text-[13px] font-medium text-ink",children:t("remote.advanced")}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-hairline/30 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.toggleDetail")})]}),e.jsx(Y,{checked:i.enabled,"aria-label":t("remote.title"),disabled:a.busy||!!c&&!i.enabled,onClick:()=>{a.act(j=>i.enabled?j.stop():j.start())}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.devices.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:m?t("remote.devices.subtitle",{app:Ye().name}):t("remote.devices.empty")}),e.jsx("div",{className:"mt-3",children:m>0&&e.jsx("ul",{className:"flex flex-col gap-2",children:i.devices.map(j=>e.jsxs("li",{className:"rounded-xl bg-inset px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(vn,{size:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13.5px] font-medium text-ink",children:j.name}),e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:t("remote.devices.lastSeen",{when:ur(j.lastSeenAt)})})]}),e.jsx("button",{disabled:a.busy,onClick:()=>{a.act(C=>C.revoke(j.id))},"aria-label":t("remote.devices.remove",{name:j.name}),className:"shrink-0 rounded p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-40",children:e.jsx(we,{size:14})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowView")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowViewDetail")})]}),e.jsx(Y,{checked:j.cloudDesktopAccess,"aria-label":t("remote.devices.viewAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.cloudDesktop(j.id,!j.cloudDesktopAccess))}})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 border-t border-hairline/30 pt-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] text-ink",children:t("remote.devices.allowBrowser")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:t("remote.devices.allowBrowserDetail")})]}),e.jsx(Y,{checked:j.browserControlAccess===!0,"aria-label":t("remote.devices.browserAria",{name:j.name}),disabled:a.busy,onClick:()=>{a.act(C=>C.browserControl(j.id,!j.browserControlAccess))}})]})]},j.id))})})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.tailscale.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.tailscaleCard.subtitle")}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"rounded-xl bg-inset px-3 py-3","aria-live":"polite",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Pt,{size:16,className:`mt-0.5 shrink-0 ${k.kind==="ready"?"text-success":"text-ink-secondary"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:k.title}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:k.detail})]})]})}),k.kind==="ready"?e.jsx("button",{disabled:a.busy||a.accountBusy||!!x,title:x??void 0,onClick:()=>{a.useTailscale(),window.requestAnimationFrame(()=>{o.current?.scrollIntoView({block:"start"}),o.current?.focus({preventScroll:!0})})},className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.pairOverTailscale")}):e.jsx("button",{disabled:a.busy||a.accountBusy||!!x&&!i.enabled,title:x??void 0,onClick:a.refreshTailscale,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.busy?t("common.checking"):x&&!i.enabled?x:i.enabled?t("remote.checkAgain"):t("remote.turnOnAndCheck")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.keepAwake")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.keepAwakeDetail")})]}),e.jsx(Y,{checked:i.keepAwake,"aria-label":t("remote.keepAwakeAria"),disabled:a.busy||!i.enabled,onClick:()=>{a.act(j=>j.keepAwake(!i.keepAwake))}})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx(mt,{size:15,className:"mt-0.5 shrink-0 text-accent"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.account.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:a.account?.status==="ready"?t("remote.account.signedIn",{email:a.account.email??t("remote.account.yourAccount")}):a.account?.status==="connecting"?t("remote.account.connecting"):a.account?.status==="error"?a.account.message??t("remote.account.error"):t("remote.account.idle")})]})]}),(a.account?.status==="ready"||a.account?.status==="connecting"||a.account?.status==="error")&&e.jsxs("button",{disabled:a.accountBusy,onClick:()=>{a.accountAct(j=>j.signOut())},className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[11.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(jn,{size:12})," ",t("remote.account.signOut")]})]}),a.account?.status==="error"&&e.jsx("button",{disabled:a.accountBusy,onClick:a.retryAccount,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:a.accountBusy?t("remote.account.retrying"):t("remote.account.retry")}),p&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:p})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.connection.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] text-ink-secondary",children:t("remote.connection.detail")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[N&&e.jsx(Rt,{label:t("remote.connection.secureRoute"),value:xr(N.url)}),v.map(j=>e.jsx(Rt,{...j},`${j.label}:${j.value}`)),!N&&v.length===0&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("remote.connection.none")})]})]}),e.jsxs("div",{className:"border-t border-hairline/30 pt-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(kn,{size:15,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("remote.pairing.wifi.title")}),e.jsx("div",{className:"mt-0.5 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.wifi.detail")})]})]}),e.jsx("button",{disabled:a.busy||a.accountBusy,onClick:a.useLocal,className:"mt-3 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-40",children:t("remote.wifi.pair")})]}),i.enabled&&!N&&!i.tailscale&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.localOnly")}),(a.error||i.error)&&e.jsx("div",{className:"text-[12px] text-danger",children:a.error??i.error})]})]})]})}function Xe(s){return wn(s)}function mr(s){return s?.kind==="session"&&!s.scopes.includes("admin")?"chat-only":null}function gr(s,n){return n?s.filter(a=>a.scopes.includes("admin")):s}function hr(s,n=Date.now()){return Math.max(0,Math.ceil((s-n)/6e4))}function fr(s,n=Date.now()){const a=Math.max(0,Math.floor((n-s)/6e4));return a<1?t("remote.serverPairing.justNow"):a<60?t("remote.serverPairing.minutesAgo",{minutes:a}):a<1440?t("remote.serverPairing.hoursAgo",{hours:Math.round(a/60)}):t("remote.serverPairing.daysAgo",{days:Math.round(a/1440)})}const br="rounded-md bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink disabled:opacity-50",_t="rounded-md border border-hairline/50 px-3 py-1.5 text-[13px] text-ink hover:bg-control";function yr({initialSession:s=null,initialPairingCodes:n=!0,cloudHome:a=!1,focusRequest:i=0}){const[o,l]=r.useState(s),[d,u]=r.useState(n),[c,x]=r.useState("admin"),[m,g]=r.useState(null),[p,y]=r.useState([]),[k,N]=r.useState(null),[v,j]=r.useState(!1),[C,w]=r.useState("idle"),[D,I]=r.useState(null),[f,b]=r.useState(()=>Date.now()),h=r.useRef(null),E=r.useRef(0);async function A(){try{const z=await U("/api/auth/sessions");y(Array.isArray(z?.sessions)?z.sessions:[]),N(typeof z?.current=="string"?z.current:null)}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}}if(r.useEffect(()=>{ps().then(z=>{l(z),Xe(z)&&A(),(z.kind==="loopback"||z.kind==="session")&&U("/api/config").then(G=>u(ms(G).pairingCodes)).catch(()=>{})})},[]),r.useEffect(()=>{i?E.current!==i&&xs(h.current)&&(E.current=i):E.current=0},[i,o]),r.useEffect(()=>{if(!m)return;const z=setInterval(()=>b(Date.now()),15e3);return()=>clearInterval(z)},[m]),!Xe(o))return mr(o)!=="chat-only"?null:e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsx(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:e.jsx("p",{"data-server-pairing-chat-only":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t(d?"remote.serverPairing.chatOnly":"remote.serverPairing.portalChatOnly")})})});const P=m?m.expiresAt<=f:!1,V=gr(p,a);async function J(){j(!0),I(null),w("idle");try{const z=await U("/api/auth/pairing",{method:"POST",body:JSON.stringify({scopes:c==="admin"||a?["admin","client"]:["client"]})});g(z),b(Date.now())}catch(z){I(t("remote.serverPairing.error",{error:z instanceof Error?z.message:String(z)}))}finally{j(!1)}}async function $(z){I(null);try{await U(`/api/auth/sessions/${encodeURIComponent(z)}`,{method:"DELETE"}),await A()}catch(G){I(t("remote.serverPairing.error",{error:G instanceof Error?G.message:String(G)}))}}async function W(){if(!m?.url)return;const z=await Sn(m.url);z!=="empty"&&w(z)}return e.jsx("div",{ref:h,tabIndex:-1,"data-phone-pairing":"server",className:"scroll-mt-4 rounded-xl focus:outline-none",children:e.jsxs(L,{title:t("remote.serverPairing.title"),subtitle:t(d?"remote.serverPairing.subtitle":"remote.serverPairing.portalSubtitle"),children:[d&&a?e.jsx("p",{"data-server-pairing-personal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.cloudPersonal")}):null,d?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[a?null:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="admin",onChange:()=>x("admin")}),t("remote.serverPairing.scope.admin")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[13px] text-ink",children:[e.jsx("input",{type:"radio",name:"server-pairing-scope",checked:c==="client",onChange:()=>x("client")}),t("remote.serverPairing.scope.client")]})]}),e.jsx("button",{type:"button","data-phone-pairing-action":!0,onClick:()=>{J()},disabled:v,className:br,children:v?t("remote.serverPairing.creating"):t("remote.serverPairing.create")})]}):e.jsx("p",{"data-server-pairing-portal":!0,className:"mt-3 text-[13px] text-ink-secondary",children:t("remote.serverPairing.portal")}),d&&m?e.jsx("div",{className:"mt-4 rounded-lg border border-hairline/40 bg-inset p-4",children:P?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.serverPairing.expired")}):e.jsxs("div",{className:"flex flex-wrap items-start gap-5",children:[m.url?e.jsx("div",{className:"rounded-md bg-white p-2",children:e.jsx(Nn,{value:m.url,size:160,level:"M",bgColor:"#ffffff",fgColor:"#111111"})}):null,e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("div",{className:"font-mono text-[18px] tracking-[0.14em] text-ink",children:m.code}),e.jsx("div",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.expires",{minutes:hr(m.expiresAt,f)})}),m.url?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"break-all text-[12px] text-ink-secondary",children:m.url}),e.jsx("button",{type:"button",onClick:()=>{W()},className:_t,children:t(C==="copied"?"remote.serverPairing.copied":C==="failed"?"common.copyFailed":"remote.serverPairing.copyLink")})]}):e.jsx("p",{className:"mt-3 text-[12.5px] text-ink-secondary",children:m.hint??t("remote.serverPairing.noLink")})]})]})}):null,e.jsx("div",{className:"mt-5 text-[13px] font-medium text-ink",children:t(d?"remote.serverPairing.devices":"remote.serverPairing.portalDevices")}),V.length===0?e.jsx("p",{className:"mt-1 text-[12.5px] text-ink-secondary",children:t("remote.serverPairing.noDevices")}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline/40",children:V.map(z=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 py-2 text-[13px]",children:[e.jsxs("span",{className:"text-ink",children:[z.label,z.email?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.email]}):null,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",z.scopes.includes("admin")?t("remote.serverPairing.scope.admin"):t("remote.serverPairing.scope.client")," · ",t("remote.serverPairing.seen",{when:fr(z.lastSeenAt,f)}),z.id===k?` · ${t("remote.serverPairing.thisBrowser")}`:""]})]}),z.id===k?null:e.jsx("button",{type:"button",onClick:()=>{$(z.id)},className:_t,children:t("remote.serverPairing.signOut")})]},z.id))}),D?e.jsx("p",{className:"mt-3 text-[13px] text-danger",children:D}):null]})})}function vr(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 Ft(s,n,a){const i=s.admins.filter(l=>l!==n),o=s.members.filter(l=>l!==n);return a==="admin"?{admins:[...i,n],members:o}:{admins:i,members:[...o,n]}}function jr(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $t(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function kr(s,n,a){const i=[],o=new Set,l=(d,u)=>{const c=d.trim().toLowerCase();if(!c||o.has(c))return;o.add(c);const x=n.filter(g=>g.email?.toLowerCase()===c),m=a.find(g=>g.key===`user:${c}`);i.push({entry:c,role:u,isDomain:c.startsWith("@"),lastSeenAt:x.length?Math.max(...x.map(g=>g.lastSeenAt)):null,devices:x.length,turns:m?.turns??0,costUsd:m?.costUsd??null,...le(m?.estimatedUsd)&&m.estimatedUsd>0?{estimated:!0}:{}})};for(const d of s.admins)l(d,"admin");for(const d of s.members)l(d,"member");return i}function Nr(s,n){const a=new Map;for(const i of s){const o=i.email?.trim().toLowerCase();o&&a.set(o,[...a.get(o)??[],i])}return[...a.entries()].map(([i,o])=>{const l=n.find(d=>d.key===`user:${i}`);return{entry:i,role:o.some(d=>d.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...o.map(d=>d.lastSeenAt)),devices:o.length,turns:l?.turns??0,costUsd:l?.costUsd??null}}).sort((i,o)=>i.role===o.role?i.entry.localeCompare(o.entry):i.role==="admin"?-1:1)}function wr(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 Ds({people:s,busy:n,onRole:a,onRemove:i,onLink:o,readOnly:l=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(l?"people.portal.empty":"people.empty")});const d="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(d,"border-b border-hairline/40 pb-2 text-[11.5px] 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(u=>e.jsxs("div",{className:_(d,"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:u.isDomain?t("people.everyoneAt",{domain:u.entry.slice(1)}):u.entry}),u.devices>0&&e.jsx("span",{className:"block text-[11.5px] text-ink-secondary",children:t("people.devices",{count:String(u.devices)})})]}),e.jsx("span",{className:_("rounded-full px-2 py-0.5 text-[11px] font-medium",u.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:u.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:u.isDomain?"—":wr(u.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(u.turns)}),children:le(u.costUsd)?`${u.estimated?"~":""}${ue(u.costUsd)}`:"—"}),l?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:()=>o(u),"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(An,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(u,u.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:u.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(u),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},u.entry))]})}function Ts({link:s}){const{state:n,copy:a}=Cn(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[12.5px]",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(oe,{size:13,className:"text-success"}):n==="failed"?e.jsx(De,{size:13,className:"text-danger"}):e.jsx(En,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Sr({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(L,{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(Ze,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Cr(){const[s,n]=r.useState(null),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState([]),[c,x]=r.useState(typeof window<"u"?window.location.origin:""),[m,g]=r.useState(null),[p,y]=r.useState(""),[k,N]=r.useState("member"),[v,j]=r.useState(null),[C,w]=r.useState(!1),[D,I]=r.useState(!1),[f,b]=r.useState(null),h=r.useCallback(async()=>{I(!0),b(null);try{const[P,V,J,$,W]=await Promise.all([U("/api/config"),U("/api/auth/sessions").catch(()=>({sessions:[]})),U("/api/usage?groupBy=user").catch(()=>({groups:[]})),U("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(F=>F.ok?F.json():null).catch(()=>null)]),z={admins:Array.isArray(P?.signIn?.admins)?P.signIn.admins:[],members:Array.isArray(P?.signIn?.members)?P.signIn.members:[]},G=ms(P);i(G),l(z);const ne=Array.isArray(V?.sessions)?V.sessions:[],R=Array.isArray(J?.groups)?J.groups:[];u(G.authority==="portal"?Nr(ne,R):kr(z,ne,R)),typeof $?.publicUrl=="string"&&$.publicUrl&&x($.publicUrl),g(W?.capabilities?.emailSignIn===!0?!0:W?!1:null)}catch(P){b(P instanceof Error?P.message:String(P))}finally{I(!1)}},[]);r.useEffect(()=>{ps().then(P=>{n(P),Xe(P)&&h()})},[h]);const E=async P=>{w(!0),b(null);try{await U("/api/config",{method:"PUT",body:JSON.stringify({signIn:P})}),await h()}catch(V){b(V instanceof Error?V.message:String(V))}finally{w(!1)}},A=async()=>{if(!o||C)return;const P=vr(p);if(!P){b(t("remote.signInAccess.invalid"));return}await E(Ft(o,P,k)),y(""),j($t(c,P))};return Xe(s)?a?.authority==="portal"?e.jsx(Sr,{peopleUrl:a.peopleUrl,people:d}):e.jsxs(L,{title:t("people.title"),subtitle:t("people.subtitle"),children:[m===!1&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[12.5px] text-ink-secondary",children:t(a?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:P=>{P.preventDefault(),A()},children:[e.jsx("input",{value:p,onChange:P=>y(P.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:C,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("select",{value:k,onChange:P=>N(P.target.value),"aria-label":t("people.colRole"),disabled:C,className:"rounded-lg border border-hairline/40 bg-inset px-2 py-2 text-[12.5px] text-ink focus:outline-none",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:C||!p.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[C?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(Te,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:D||C,"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(xe,{size:13,className:_(D&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Ts,{link:v}),f&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:f}),e.jsx("div",{className:"mt-4",children:e.jsx(Ds,{people:d,busy:C,onRole:(P,V)=>{o&&E(Ft(o,P.entry,V))},onRemove:P=>{o&&E(jr(o,P.entry))},onLink:P=>j($t(c,P.entry))})}),e.jsx("p",{className:"mt-3 text-[11.5px] leading-relaxed text-ink-secondary",children:t("people.note")})]}):null}const Ve="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 Er({entry:s}){const[n,a]=r.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()}),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:ai(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:ii(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:s.summary}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(In,{size:12,className:_("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(o=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.before?.[o])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:Mt(s.after?.[o])})]},o))]})]})]})})}function Ar(){const[s,n]=r.useState({who:"",what:"all",from:"",to:""}),[a,i]=r.useState([]),[o,l]=r.useState(0),[d,u]=r.useState(null),[c,x]=r.useState(!1),[m,g]=r.useState(null),p=si(s),y=r.useCallback(async()=>{x(!0),g(null);try{const N=await U(`/api/admin-activity${p}`);i(N.entries),l(N.total),u(N.retentionDays)}catch(N){g(N instanceof Error?N.message:String(N))}finally{x(!1)}},[p]);r.useEffect(()=>{const N=window.setTimeout(()=>{y()},250);return()=>window.clearTimeout(N)},[y]);const k=N=>n(v=>({...v,...N}));return e.jsxs(L,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(d??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:N=>k({who:N.target.value}),placeholder:t("activity.whoPlaceholder"),className:_(Ve,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx("select",{value:s.what,onChange:N=>k({what:N.target.value}),className:Ve,children:ni.map(N=>e.jsx("option",{value:N,children:t(`activity.what.${N}`)},N))})]}),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:N=>k({from:N.target.value}),className:Ve})]}),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:N=>k({to:N.target.value}),className:Ve})]}),e.jsx("button",{type:"button",onClick:()=>{y()},disabled:c,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:c?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${p}`,download:!0,className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12.5px] font-medium text-ink hover:bg-control/70",children:[e.jsx(gs,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),m&&e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:t("activity.error",{message:m})}),!m&&a.length===0&&!c&&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((N,v)=>e.jsx(Er,{entry:N},`${N.at}-${v}`))}),o>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(o)})})]})}function Ir(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(o=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(o))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Pr({domain:s,serverIpv4:n}){const a=Ir(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([o,l])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:o}),e.jsx("dd",{className:"min-w-0",children:l?e.jsx(Re,{command:l,copyLabel:t("settings.domain.copyField",{field:o})},l):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},o))}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Rr(s){return`bots.example.com {
|
|
2
2
|
handle /hooks/* {
|
|
3
3
|
reverse_proxy 127.0.0.1:${s.webhookPort}
|
|
4
4
|
}
|
|
@@ -7,5 +7,5 @@ import{k as Ne,u as K,r,j as e,t,cg as te,q as Y,ch as L,c as _,d as H,o as oe,E
|
|
|
7
7
|
flush_interval -1
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
}`}function Pr({status:s}){return e.jsxs("details",{className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:t("settings.domain.guide")}),e.jsxs("ol",{className:"mt-3 list-decimal space-y-3 pl-4 leading-relaxed",children:[e.jsx("li",{children:t("settings.domain.dns")}),e.jsxs("li",{children:[t("settings.domain.proxy"),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-md bg-app p-3 text-[11px] leading-relaxed text-ink",children:e.jsx("code",{children:Ir(s)})}),e.jsx("p",{className:"mt-2",children:t("settings.domain.proxyHint")})]}),e.jsx("li",{children:t("settings.domain.verifyHint")})]}),e.jsx("p",{className:"mt-3 text-warning",children:t("settings.domain.loopbackWarning")}),!s.serverIpv4&&e.jsx("p",{className:"mt-3",children:t("settings.domain.ipAdminHint")}),e.jsx("p",{className:"mt-3",children:t("settings.domain.scope")}),e.jsxs("a",{className:"mt-3 inline-flex items-center gap-1.5 text-accent hover:underline",href:"https://github.com/milind-soni/OpenMausBot/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings",target:"_blank",rel:"noopener noreferrer",children:[t("settings.domain.fullGuide")," ",e.jsx(Ze,{size:12})]})]})}function Rr(){const[s,n]=r.useState(null),[a,i]=r.useState(""),[o,l]=r.useState("loading"),[d,u]=r.useState(null),[c,x]=r.useState(null);r.useEffect(()=>{const g=new AbortController;return U("/api/settings/custom-domain",{signal:g.signal}).then(p=>{g.signal.aborted||(n(p),i(p.customDomain??""))}).catch(p=>{g.signal.aborted||u(p instanceof Error?p.message:t("settings.domain.failed"))}).finally(()=>{g.signal.aborted||l(null)}),()=>g.abort()},[]);const m=async g=>{l(g?"removing":"saving"),u(null),x(null);try{const p=await U("/api/settings/custom-domain",{method:g?"DELETE":"POST",...g?{}:{body:JSON.stringify({domain:a.trim()})}});n(p),i(p.customDomain??""),x(g?t("settings.domain.removed"):t("settings.domain.saved"))}catch(p){u(p instanceof Error?p.message:t("settings.domain.failed"))}finally{l(null)}};return e.jsx(L,{title:t("settings.domain.title"),subtitle:t("settings.domain.subtitle"),children:e.jsxs("div",{className:"space-y-3","data-custom-domain-settings":!0,children:[o==="loading"&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("settings.domain.loading")]}),s&&!s.supported&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:g=>{g.preventDefault(),a.trim()&&!o&&m(!1)},className:"space-y-2",children:[e.jsx("label",{htmlFor:"custom-domain",className:"block text-[13px] font-medium text-ink",children:t("settings.domain.label")}),e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:o!==null,onChange:g=>{i(g.target.value),x(null),u(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx(Ar,{domain:a,serverIpv4:s.serverIpv4}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.httpsNeeded")}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs("button",{type:"submit",disabled:!a.trim()||o!==null,className:"inline-flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[o==="saving"?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(An,{size:14}),o==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:o!==null,onClick:()=>{m(!0)},className:"rounded-lg bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:o==="removing"?t("settings.domain.removing"):t("settings.domain.remove")})]})]}),s.publicUrl&&e.jsxs("p",{className:"break-all text-[11.5px] text-ink-secondary",children:[t("settings.domain.current"),": ",e.jsx("span",{className:"text-ink",children:s.publicUrl})]}),s.customDomain&&e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")}),e.jsx(Pr,{status:s})]}),c&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(oe,{size:14,className:"mt-0.5 shrink-0"}),c]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] leading-relaxed text-danger",children:d})]})})}const We="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 Kt(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Br(s){const n=s.trim();if(!/^https:\/\//i.test(n)||/[\s\\]/.test(n))return!1;try{const a=new URL(n),i=/(?:^|[#&])code=([^&]+)/.exec(a.hash)?.[1];return a.protocol==="https:"&&!a.username&&!a.password&&!a.search&&(a.pathname==="/pair"||a.pathname==="/pair/")&&!!(i&&decodeURIComponent(i).trim())}catch{return!1}}function Dr(){const s=window.ogb?.remoteClient,n=window.ogb?.environments,[a,i]=r.useState({active:s?.active===!0}),[o,l]=r.useState(n?"server":"companion"),[d,u]=r.useState(""),[c,x]=r.useState(""),[m,g]=r.useState(""),[p,y]=r.useState(!1),[k,N]=r.useState(""),v=r.useRef(!1),j=!!n&&o==="server",E=r.useRef(!0),w=r.useCallback(()=>{s?.state().then(f=>{E.current&&i(f)}).catch(()=>{})},[s]);r.useEffect(()=>(E.current=!0,w(),()=>{E.current=!1}),[w]);const D=async()=>{if(!(v.current||!s&&!n)){v.current=!0,y(!0),N("");try{if(j&&n){if(!Br(d))throw new Error(t("remote.client.server.invalidLink"));await n.addFromLink(d.trim()),w()}else s&&(await s.pair(c,m),w())}catch(f){N(Kt(f))}finally{v.current=!1,y(!1)}}},I=async()=>{if(!(!s||v.current)){v.current=!0,y(!0),N("");try{await s.disconnect(),w()}catch(f){N(Kt(f))}finally{v.current=!1,y(!1)}}};return e.jsxs(L,{title:a.active?t("remote.client.active"):t("remote.client.idle"),subtitle:t("remote.client.subtitle"),children:[!s&&!n?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.client.desktopOnly")}):a.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(ut,{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:a.serverName||t("remote.client.fallbackName")})}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:a.endpoint})]})]}),e.jsx("p",{className:"text-[12.5px] leading-relaxed text-ink-secondary",children:t("remote.client.mode")}),e.jsxs("button",{type:"button",disabled:p,onClick:()=>{I()},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:[p?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(yi,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:f=>{f.preventDefault(),D()},children:[n&&s?e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.connectionType"),e.jsxs("select",{value:o,disabled:p,onChange:f=>{l(f.target.value),N("")},className:We,children:[e.jsx("option",{value:"server",children:t("remote.client.server.option")}),e.jsx("option",{value:"companion",children:t("remote.client.companion.option")})]})]}):null,j?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[12.5px] leading-relaxed text-ink-secondary",children:t("remote.client.server.hint")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx openmausbot pair --client"}),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:d,onChange:f=>u(f.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:p,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:We})]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.client.server.domainHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[12.5px] 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:c,onChange:f=>x(f.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:p,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:We})]}),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:m,onChange:f=>g(f.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:p,inputMode:"numeric",autoComplete:"one-time-code",className:`${We} max-w-40 font-mono tracking-[0.2em]`})]})]}),k?e.jsx("p",{role:"alert",className:"text-[12.5px] text-danger",children:k}):null,e.jsxs("button",{type:"submit",disabled:p||(j?!d.trim():c.trim()===""||m.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:[p?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ut,{size:14}),j?t("remote.client.server.connect"):t("remote.client.pair")]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:j?t("remote.client.server.switchNote"):t("remote.client.restartNote")})]}),a.active&&k?e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:k}):null]})}const Tr={list_files:"lending.action.listFiles",read_file:"lending.action.readFile",write_file:"lending.action.writeFile",run_command:"lending.action.runCommand",computer_tools:"lending.action.screenTools",computer_call:"lending.action.screen",invalid:"lending.action.invalid"};function zs({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()}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(Tr[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 zr({workspace:s,onClose:n}){const{state:a}=K(),o=hs(a.config)?window.ogb?.computerSharing:void 0,[l,d]=r.useState(null),[u,c]=r.useState([]),[x,m]=r.useState(!1),[g,p]=r.useState(!1),[y,k]=r.useState(!1),[N,v]=r.useState(""),[j,E]=r.useState(null),w=r.useRef(!1),D=r.useRef(!1),I=r.useRef(null),f=h=>{d(h),c(h.folders),m(h.terminal),p(h.computer)};r.useEffect(()=>{w.current=!0,I.current?.scrollIntoView({block:"start"}),o?.state(s.id).then(A=>{w.current&&f(A)}).catch(()=>{w.current&&v("Could not load computer access. Reopen this page to try again.")});const h=()=>{o?.state(s.id).then(A=>{w.current&&d(A)}).catch(()=>{}),o?.activity?.(s.id).then(A=>{w.current&&E(A)}).catch(()=>{})};h();const C=setInterval(h,3e3);return()=>{w.current=!1,clearInterval(C)}},[o,s.id]);const b=async h=>{if(!D.current){D.current=!0,k(!0),v("");try{await h()}catch(C){w.current&&v(String(C?.message??C).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{D.current=!1,w.current&&k(!1)}}};return o?e.jsx("div",{ref:I,children:e.jsx(L,{title:`Computer access · ${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?"Sharing while this desktop is open":"Waiting for the workspace to connect":"Not shared":"Loading access…"}),e.jsx("button",{type:"button","aria-label":"Close computer access",onClick:n,className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Ue,{size:16})})]}),e.jsx("p",{className:"text-ink-secondary",children:"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."}),e.jsxs("fieldset",{disabled:y||!l,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:"Shared folders"}),u.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"No folders shared. New folders are read-only by default."}),u.map(h=>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:h.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:h.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:h.write,onChange:C=>c(A=>A.map(P=>P.id===h.id?{...P,write:C.target.checked}:P))}),"Allow edits"]}),e.jsx("button",{type:"button","aria-label":`Remove ${h.name}`,onClick:()=>c(C=>C.filter(A=>A.id!==h.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Ue,{size:14})})]},h.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{b(async()=>{const h=await o.chooseFolder();w.current&&h&&c(C=>C.some(A=>A.path===h.path)?C:[...C,h])})},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(fs,{size:14}),"Choose folder"]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"Small files only (256 KB). Folder access does not follow links or delete files."})]}),e.jsxs("fieldset",{disabled:y||!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:"Broader access · optional"}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:x,onChange:h=>m(h.target.checked)}),e.jsxs("span",{className:"text-ink",children:["Unrestricted terminal",e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:"Run commands as you. This can access or delete files anywhere you can, including credentials—not just the folders above."})]})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:g,onChange:h=>p(h.target.checked)}),e.jsxs("span",{className:"text-ink",children:["Computer control",e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:"View your screen and operate your signed-in apps, outside the shared folders. Requires local computer control and OS permissions."})]})]})]}),(N||l?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:N||l?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:y||!l||!u.length&&!x&&!g,onClick:()=>{b(async()=>{const h=await o.save(s.id,{folders:u,terminal:x,computer:g});w.current&&h&&f(h)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:l?.enabled?"Save access":"Share selected access"}),l?.enabled&&e.jsx("button",{type:"button",disabled:y,onClick:()=>{b(async()=>{const h=await o.revoke(s.id);w.current&&f(h)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:"Stop sharing"})]}),l?.enabled&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"Stopping blocks new requests and cancels running work where possible. An action already sent to an app may still finish."}),e.jsx("div",{className:"border-t border-hairline/40 pt-3",children:e.jsx(zs,{entries:j})})]})})}):null}function Mr(){const s=window.ogb?.environments,{state:n}=K(),a=hs(n.config)&&!!window.ogb?.computerSharing,[i,o]=r.useState(null),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(!1),[g,p]=r.useState(""),[y,k]=r.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),N=!!window.ogb?.cloudMove&&!window.ogb?.remoteClient?.active,[v,j]=r.useState(()=>new URLSearchParams(window.location?.search??"").get("copy-to")),E=r.useRef(!1),w=r.useRef(0);r.useEffect(()=>{const f=++w.current;return s?.state().then(b=>{w.current===f&&o(b)}).catch(()=>{w.current===f&&p("Could not load saved servers. Please reopen this page.")}),()=>{w.current++}},[s]),r.useEffect(()=>{const f=(b,h)=>{b&&(h==="copy"?j:k)(b);const C=new URL(window.location.href);C.searchParams.delete("share-computer"),C.searchParams.delete("copy-to"),window.history.replaceState(null,"",`${C.pathname}${C.search}${C.hash}`)};return f(),s?.onOpenSettings?.(f)},[s]);const D=async f=>{if(E.current||!s)return;E.current=!0,m(!0),p("");const b=w.current;try{if(await f()===!0)return;const h=await s.state();w.current===b&&o(h)}catch(h){w.current===b&&p(String(h?.message??h).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{E.current=!1,w.current===b&&m(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:"Manage server connections in the desktop app."});const I=i?.environments.find(f=>f.id===y);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:"One desktop app, wherever your bots live. Switching servers does not move or replace your bots, conversations, or provider accounts."}),e.jsx(L,{title:"Your servers",subtitle:"Saved on this computer. Your hosted bots keep running when you switch away.",children:i?e.jsx("ul",{className:"divide-y divide-hairline/40",children:[{id:"local",name:"This computer",origin:""},...i.environments].map(f=>{const b=f.id===i.activeId,h=f.id==="local"?ut:mt;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(h,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:f.name}),e.jsx("div",{className:"break-all text-[12px] text-ink-secondary",children:f.origin||"Local bots and conversations"})]}),b?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(oe,{size:13}),"Current"]}):e.jsx("button",{type:"button",disabled:x,"aria-label":`Switch to ${f.name}`,onClick:()=>{D(async()=>(await s.switch(f.id),!0))},className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:"Switch"}),f.id!=="local"&&N&&e.jsx("button",{type:"button",disabled:x,"aria-label":`${t("cloudMove.here")}: ${f.name}`,onClick:()=>j(f.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("cloudMove.here")}),f.id!=="local"&&a&&e.jsx("button",{type:"button",disabled:x,"aria-label":`Computer access for ${f.name}`,onClick:()=>k(f.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:"Computer access"}),f.id!=="local"&&e.jsx("button",{type:"button",disabled:x,"aria-label":`Forget ${f.name}`,title:`Forget ${f.name}`,onClick:()=>{D(()=>s.forget(f.id))},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(we,{size:14})})]},f.id)})}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:g?"Saved servers could not be loaded.":"Loading servers…"})}),N&&v&&i?.environments.some(f=>f.id===v)&&e.jsx(bs,{destination:v,onClose:()=>j(null)},v),a&&I&&e.jsx(zr,{workspace:I,onClose:()=>k(null)},I.id),e.jsx(L,{title:"Connect to a server",subtitle:"Already running OpenMausBot on a VPS, server, or another computer? Connect it here.",children:e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:f=>{f.preventDefault(),l.trim()&&D(()=>s.addFromLink(l.trim(),u.trim()))},children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:["Server address or pairing link",e.jsx("input",{required:!0,value:l,disabled:x,onChange:f=>d(f.target.value),placeholder:"https://bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:["Name (optional)",e.jsx("input",{value:u,disabled:x,maxLength:60,onChange:f=>c(f.target.value),placeholder:"My server",className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:"Paste a pairing link from your server’s Settings → Remote access, or enter its address and sign in there. Your desktop stays connected afterward."}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:"Need a pairing code?"}),e.jsx("p",{className:"mt-2",children:"Run this on the server and copy the link it prints:"}),e.jsx("code",{className:"mt-1 block select-all break-words rounded-md bg-inset px-2 py-2 text-ink",children:'npx openmausbot pair --label "My desktop"'})]}),g&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:g}),e.jsxs("button",{type:"submit",disabled:x||!l.trim(),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:14,className:"animate-spin"}),"Connect"]})]})})]})}function Ms(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function Or(s,n){return s.find(a=>Ms(a)&&a.instanceId.endsWith(`.${n}`))}function bt(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function Ht(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return bt(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function Ur(s,n){const a=n.filter(d=>Ms(d)&&bt(d)),i=a.find(d=>d.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const o={target:i,bots:[],needsAsk:[]},l=d=>n.find(u=>u.instanceId===d)?.driverKind;for(const d of s){if(d.hidden)continue;const u=In(d);if(Ht(d.modelSelection,n)||Ht(u.modelSelection,n))continue;([d,u].some(x=>Pn(Rn(x),l(x.modelSelection.instanceId),i.driverKind))?o.needsAsk:o.bots).push(d)}return o}const Lr={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function _r({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(null),c=Ur(n.bots,n.instances),x=c.target,m=p=>p.map(y=>y.name).join(", "),g=async()=>{if(!x||!c.bots.length||o)return;const p=c.bots,y={instanceId:x.instanceId,model:x.models.default};l(!0),u(null);for(const k of p)a({type:"setModel",botId:k.id,selection:y});try{const k=await Promise.all(p.map(v=>i(v.id).catch(()=>null))),N=p.filter((v,j)=>k[j]?.modelSelection.instanceId===y.instanceId);N.length&&u({name:x.displayName,bots:N.map(v=>v.name)})}finally{l(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(p=>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:Lr[p.id]??p.id}),e.jsx("span",{className:"text-ink-secondary",children:p.configured?t("organization.modelCount",{count:p.models.length}):t("organization.notConfigured")})]}),p.configured&&p.models.length>0&&e.jsx(Fr,{instance:Or(n.instances,p.id),instances:n.instances})]},p.id))}),d&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:d.name,names:d.bots.join(", ")})}),x&&c.bots.length>0&&e.jsxs("div",{"data-company-switch":!0,className:"flex flex-col items-start gap-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"break-words text-[13px] text-ink",children:t("organization.useCompanyBots",{names:m(c.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:o,onClick:()=>{g()},children:c.bots.length===1?t("organization.useCompanyOne",{name:x.displayName}):t("organization.useCompanyMany",{name:x.displayName,count:c.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),x&&c.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:m(c.needsAsk)})})]})}function Fr({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(bt(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(oe,{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&&Bn(a)?e.jsx(us,{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 $r={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},Vt="https://admin.openmausbot.com";function Kr(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[n,a]=r.useState(null),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1),p=r.useRef(0),y=r.useRef(0),k=r.useRef(void 0),N=f=>{const b=k.current!==f.status;k.current=f.status,a(f),b&&c(""),f.status!=="connected"&&f.status!=="reauth-required"&&m(!1)};r.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const f=++p.current,b=y.current,h=A=>{p.current===f&&(y.current++,N(A))},C=s?.onState(h);return s?.state().then(A=>{y.current===b&&h(A)}).catch(()=>{p.current===f&&y.current===b&&c(t("organization.loadFailed"))}),()=>{p.current++,C?.()}},[s]);const v=async f=>{if(!s||g.current)return;g.current=!0,d(!0),c("");const b=p.current,h=y.current;try{const C=await f();p.current===b&&y.current===h&&N(C)}catch{p.current===b&&y.current===h&&c(t("organization.actionFailed"))}finally{g.current=!1,p.current===b&&d(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const j=n?.status==="connected"||n?.status==="reauth-required"||n?.status==="unavailable"||n?.status==="license-expired",E=n?.status==="license-expired"||n?.notice==="license-expired",w=n?.enrollment?.expiresAt??n?.expiresAt,D=typeof w=="number"&&Number.isFinite(w)?new Date(w):null,I=D&&Number.isFinite(D.getTime())?new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(D):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.additive")}),e.jsxs(L,{title:t("settings.section.organization"),subtitle:t("organization.privacy"),children:[!n&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:u||t("organization.loading")}),n?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:n.message}),E&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),n?.status==="signed-out"&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.signInHelp")}),e.jsx("button",{type:"button",disabled:l,onClick:()=>{v(()=>s.begin({portalOrigin:Vt}))},className:"w-fit rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:l?t("organization.working"):t("organization.signIn")}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.advanced")}),e.jsxs("form",{className:"mt-2 flex flex-col gap-2",onSubmit:f=>{f.preventDefault(),i.trim()&&v(()=>s.begin({portalOrigin:i.trim()}))},children:[e.jsx("p",{children:t("organization.advancedHelp")}),e.jsxs("label",{className:"flex flex-col gap-1.5",children:[t("organization.address"),e.jsx("input",{type:"url",required:!0,value:i,disabled:l,onChange:f=>o(f.target.value),placeholder:Vt,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("button",{type:"submit",disabled:l||!i.trim(),className:"ui-button w-fit",children:t("organization.customSignIn")})]})]})]}),n?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.browserConsent")}),n.enrollment&&e.jsxs("details",{className:"w-full text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.securityDetails")}),e.jsx("p",{className:"mt-2",children:t("organization.securityDetailsHelp")}),e.jsx("div",{className:"mt-3",children:t("organization.code")}),e.jsx("code",{dir:"ltr",className:"mt-1 block w-fit select-all rounded-lg bg-inset px-3 py-2 text-base tracking-widest text-ink",children:n.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.enrollment&&s.reopen&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[n.branding?.logo&&e.jsx("img",{src:n.branding.logo,alt:"Organization logo",className:"mb-2 size-12 rounded-lg object-contain"}),e.jsx("div",{className:"break-words text-[15px] font-medium text-ink",children:n.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:n.email})]}),n.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):n.status==="license-expired"?e.jsx(e.Fragment,{children:n.providers?.some(f=>f.configured&&f.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:n.providers.filter(f=>f.configured&&f.models.length>0).map(f=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:$r[f.id]??f.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},f.id))})}):n.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),n.providers?.some(f=>f.configured&&f.models.length>0)?e.jsx(_r,{providers:n.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:()=>{v(()=>s.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>m(!0),children:t("organization.disconnect")})]})]}),n?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),I&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:I})}),u&&n&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u}),!n&&e.jsx("button",{type:"button",disabled:l,className:"ui-button mt-3",onClick:()=>{v(()=>s.refresh())},children:t("organization.refresh")})]})]})}const Wt={"connect-first":"lending.status.connectFirst","not-cloud":"lending.status.notCloud",waiting:"lending.status.waiting",paused:"lending.status.paused","signed-out":"lending.status.signedOut","account-changed":"lending.status.accountChanged","machine-changed":"lending.status.machineChanged"};function Hr(s,n){const a=s?.state;return a?.enabled?a.busy?"lending.status.busy":a.connected?"lending.status.lent":Wt[a.problem??""]??"lending.status.starting":n?"lending.status.chooseSomething":a?.problem&&a.problem!=="paused"?Wt[a.problem]??null:null}function Vr({bridge:s}){const[n,a]=r.useState(null),[i,o]=r.useState(!1),[l,d]=r.useState([]),[u,c]=r.useState(!1),[x,m]=r.useState(!1),[g,p]=r.useState(!1),y=r.useRef(!1),k=r.useRef(!1),N=f=>{k.current&&(a(f),!y.current&&f.state&&(d(f.state.folders),c(f.state.screen)))};r.useEffect(()=>{k.current=!0;const f=()=>{s.state().then(N).catch(()=>{})};f();const b=setInterval(f,3e3);return()=>{k.current=!1,clearInterval(b)}},[s]);const v=async f=>{if(!y.current){y.current=!0,m(!0),p(!1);try{const b=await f();y.current=!1,N(b)}catch{k.current&&p(!0)}finally{y.current=!1,k.current&&m(!1)}}},j=(f,b)=>{d(f),c(b),v(()=>f.length||b?s.save({folders:f,screen:b}):s.stop())},E=n?.state?.enabled===!0,w=E||i,D=()=>{if(w){o(!1),v(()=>s.stop());return}o(!0),(l.length||u)&&j(l,u)};if(!n?.available)return null;const I=Hr(n,w);return e.jsxs("div",{"data-cloud-lending":E?"on":"off",className:"mt-2 flex w-full flex-col gap-3 border-t border-hairline/40 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:t("lending.title")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("lending.explain")})]}),e.jsx(Y,{checked:w,disabled:x,"aria-label":t("lending.title"),onClick:D})]}),I&&e.jsx("p",{role:"status",className:`text-[13px] ${E&&n.state?.busy?"font-medium text-ink":"text-ink-secondary"}`,children:t(I)}),w&&e.jsxs(e.Fragment,{children:[e.jsxs("fieldset",{disabled:x,className:"flex flex-col gap-2 disabled:opacity-60",children:[e.jsx("legend",{className:"mb-1 text-[13px] font-medium text-ink",children:t("lending.folders")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.foldersHelp")}),l.map(f=>e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border border-hairline/40 p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] text-ink",children:f.name}),e.jsx("p",{dir:"ltr",className:"break-all text-[11px] text-ink-secondary",children:f.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:f.write,onChange:b=>j(l.map(h=>h.id===f.id?{...h,write:b.target.checked}:h),u)}),t("lending.canEdit")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:f.name}),onClick:()=>j(l.filter(b=>b.id!==f.id),u),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Ue,{size:14})})]},f.id)),e.jsxs("button",{type:"button",disabled:l.length>=20,onClick:()=>{v(async()=>{const f=await s.chooseFolder(),b=f&&!l.some(h=>h.path===f.path)?[...l,f]:l;return b!==l?(d(b),s.save({folders:b,screen:u})):s.state()})},className:"ui-button flex w-fit items-center gap-2",children:[e.jsx(fs,{size:14}),t("lending.addFolder")]})]}),e.jsxs("fieldset",{disabled:x,className:"flex flex-col gap-1 disabled:opacity-60",children:[e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:u,disabled:!u&&!n.screenAvailable,onChange:f=>j(l,f.target.checked)}),e.jsxs("span",{className:"text-[13px] text-ink",children:[t("lending.screen"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("lending.screenHelp")})]})]}),!n.screenAvailable&&e.jsx("p",{className:"ms-6 text-[12px] text-ink-secondary",children:t("lending.screenUnavailable")})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.ownConversations")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.stopHelp")})]}),g&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("lending.failed")}),(w||(n.activity?.length??0)>0)&&e.jsx(zs,{entries:n.activity??[]})]})}const Wr={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},qt=[["reserving","cloudHome.step.reserving"],["storage","cloudHome.step.storage"],["starting","cloudHome.step.starting"],["checking","cloudHome.step.checking"]],Os=s=>new Intl.DateTimeFormat(Te(),{timeStyle:"short"}).format(new Date(s)),qr=s=>new Intl.DateTimeFormat(Te(),{dateStyle:"medium"}).format(new Date(s));function Jr(s){if(!s.setup)return null;const n=qt.findIndex(([a])=>a===s.setup.step);return e.jsx("ol",{"data-cloud-setup":s.setup.step,className:"flex flex-col gap-1 text-[13px]",children:qt.map(([a,i],o)=>e.jsx("li",{"aria-current":o===n?"step":void 0,className:o===n?"font-medium text-ink":o<n?"text-ink-secondary line-through decoration-ink-secondary/40":"text-ink-secondary",children:t(i)},a))})}function Gr({machine:s,busy:n,failed:a,onConnect:i,lending:o}){const l=s.status==="ready",d=s.status==="failed"&&s.retryAt?t("cloudHome.failedRetry",{time:Os(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):t(Wr[s.status]);return e.jsx(L,{title:t("cloudHome.title"),children:e.jsxs("div",{"data-cloud-home":s.status,className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:s.status==="ready"?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:d}),s.status==="provisioning"&&Jr(s),l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudHome.connect")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudHome.connectHelp")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudHome.connectFailed")}),o&&e.jsx(Vr,{bridge:o})]})})}function Yr({ready:s,busy:n,failed:a,onUse:i}){return e.jsx(L,{title:t("cloudPhone.title"),subtitle:t("cloudPhone.subtitle"),children:e.jsxs("div",{"data-cloud-phone":s?"open":"steps",className:"flex flex-col items-start gap-3",children:[s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudPhone.action")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudPhone.help")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudPhone.failed")}),(!s||a)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(s?"cloudPhone.stepsIntro":"cloudPhone.notReady")}),e.jsxs("ol",{className:"list-decimal ps-5 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("li",{children:t("cloudPhone.step1")}),e.jsx("li",{children:t("cloudPhone.step2")})]})]})]})})}function Xr(s,n){return n.arrived&&s.status==="signed-out"&&s.message!=="restoring"?"sign-in":!n.connected&&s.status==="connected"&&s.machine?.status==="ready"?"connect":null}const Qr={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function Zr(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(Qr[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:qr(n.paidAt)}):t("cloudAccount.purchaseNoteNoDate"):n.kind==="attention"&&!s.machine?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 el(s,n){return n.kind==="free"?t("cloudAccount.upgrade"):n.kind==="paid"||n.kind==="unverified"&&n.label?t("cloudAccount.manage"):s.machine?.status==="payment-problem"?t("cloudAccount.updatePayment"):t("cloudAccount.dashboard")}function tl({bridge:s,onConnectPhone:n}){const[a,i]=r.useState(null),[o,l]=r.useState(!1),[d,u]=r.useState(!1);if(r.useEffect(()=>{let g=!0;return s.state().then(p=>{g&&i(p)}).catch(()=>{g&&u(!0)}),()=>{g=!1}},[s]),d)return e.jsx(L,{title:t("settings.section.cloudAccount"),children:e.jsx("p",{"data-cloud-plan":"elsewhere",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudNone")})});const c=Mn(a?.tier),x=a?.status==="paid"?t("cloudAccount.pro",{plan:c}):a?.status==="attention"?t("cloudAccount.inactive",{plan:a.tier?c:"OpenMausBot Cloud"}):a?.status==="checking"?t("cloudAccount.lastPlan",{plan:c}):a?.status==="signin"?a.tier?t("cloudAccount.planName",{plan:c}):null:a?t("cloudAccount.onCloudNone"):null,m=g=>{l(!1),g().catch(()=>l(!0))};return e.jsx(L,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.onCloud"),children:e.jsxs("div",{"data-cloud-plan":a?.status??"loading",className:"flex flex-col items-start gap-3",children:[x?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:x}):!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),a?.status==="signin"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudSignIn")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(()=>s.manage()),children:t("cloudAccount.manageInBrowser")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(()=>s.useThisComputer()),children:t("cloudAccount.useThisComputer")}),a&&n&&e.jsx("button",{type:"button",className:"ui-button",onClick:n,children:t("cloudPhone.action")})]}),o&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function sl({linkRequest:s=0,cloudHome:n=!1,onConnectPhone:a}={}){const i=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:o}=Dn().capabilities.host,[l,d]=r.useState(null),[u,c]=r.useState(!1),[x,m]=r.useState(!1),[g,p]=r.useState(!1),[y,k]=r.useState(!1),[N,v]=r.useState(!1),j=r.useRef(0),E=r.useRef(0),w=r.useRef(!1),D=r.useRef({request:0,arrived:!1,connected:!1});r.useEffect(()=>{const $=++j.current,W=E.current,z=ne=>{j.current===$&&(E.current++,d(ne),m(!1),ne.status==="signed-out"&&p(!1))},G=i?.onState(z);return i?.state().then(ne=>{E.current===W&&z(ne)}).catch(()=>{j.current===$&&E.current===W&&m(!0)}),()=>{j.current++,G?.()}},[i]);const I=async $=>{if(!i||w.current)return;w.current=!0,c(!0),m(!1);const W=j.current,z=E.current;try{const G=await $();j.current===W&&E.current===z&&d(G)}catch{j.current===W&&E.current===z&&m(!0)}finally{w.current=!1,j.current===W&&c(!1)}},f=()=>{i&&(k(!1),I(async()=>{try{return await i.connectHome()}catch{return k(!0),i.state()}}))},b=()=>{i&&(v(!1),I(async()=>{try{return await i.connectHomeForPhone()}catch{return v(!0),i.state()}}))};if(r.useEffect(()=>{if(s||(D.current.request=0),!i||!s||!l||w.current||(D.current.request!==s&&(D.current={request:s,arrived:!0,connected:!1}),l.status==="signed-out"&&l.message==="restoring"))return;const $=Xr(l,D.current);D.current.arrived=!1,$==="sign-in"&&I(()=>i.begin()),$==="connect"&&(D.current.connected=!0,f())},[i,s,l,u]),!i){const $=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return $?e.jsx(tl,{bridge:$,onConnectPhone:a}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")})}const h=Tn(l),C=l&&["connected","unavailable","reauth-required"].includes(l.status),A=Zr(l,h,o),P=zn(h),V=l?.status==="connected"?l.machine??(h.kind==="paid"?{status:"provisioning"}:void 0):void 0,J=l?.status==="connecting"?l.enrollment:void 0;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.optional")}),e.jsxs(L,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.separate"),children:[(!l||h.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),A&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:A}),h.kind==="signed-out"&&e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.begin())},children:t("cloudAccount.signIn")}),l?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.browser")}),J&&e.jsxs("div",{"data-cloud-code":!0,className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.codeCheck")}),e.jsx("code",{dir:"ltr",className:"select-all text-[18px] font-semibold tracking-widest text-ink",children:J.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:Os(J.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.cancel())},children:t("organization.cancel")})]})]}),C&&e.jsxs("div",{className:"flex flex-col gap-3",children:[l.account&&e.jsx("p",{className:"break-all text-[14px] text-ink",children:l.account.email}),P&&e.jsxs("p",{role:"status","data-cloud-plan":h.kind,className:"text-[15px] font-medium text-ink",children:[P,h.kind==="paid"&&h.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),h.kind==="free"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.purchaseHelp")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[h.kind==="reauth"?e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.openDashboard())},children:el(l,h)}),e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.refresh())},children:t("organization.refresh")})]}),!g&&e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>p(!0),children:t("cloudAccount.signOut")})]}),h.kind==="free"&&!g&&e.jsxs("p",{className:"text-[12px] text-ink-secondary",children:[t("cloudAccount.otherEmail")," ",e.jsx("button",{type:"button",disabled:u,className:"underline hover:text-ink",onClick:()=>p(!0),children:t("cloudAccount.useOtherEmail")})]}),g&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.signoutTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.signoutHelp")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:u,className:"ui-button",onClick:()=>p(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:u,className:"ui-button text-danger",onClick:()=>{I(()=>i.signOut())},children:t("cloudAccount.signOut")})]})]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!l&&e.jsx("button",{type:"button",disabled:u,className:"ui-button mt-3",onClick:()=>{I(()=>i.state())},children:t("organization.refresh")})]}),V&&Gr({machine:V,busy:u,failed:y,onConnect:f,lending:i.lending}),C&&h.kind==="paid"&&Yr({ready:V?.status==="ready",busy:u,failed:N,onUse:b}),V?.status==="ready"&&e.jsx(bs,{destination:"cloud"})]})}function Jt(s,n){return s?.edition?.features?.includes(n)===!0}function nl(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function al({budget:s}){const{state:n,dispatch:a}=K(),i=n.config?.budgets??{},[o,l]=r.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[d,u]=r.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[c,x]=r.useState(!1),[m,g]=r.useState(null);r.useEffect(()=>{l(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),u(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const p=async()=>{if(c)return;const k=o.trim()===""?0:Number(o),N=Number(d);if(!Number.isFinite(k)||k<0||!Number.isInteger(N)||N<1||N>100){g(t("usage.budget.invalid"));return}x(!0),g(null);try{const v=await U("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:k,warnAtPercent:N}})});a({type:"configStatus",config:v})}catch(v){g(v instanceof Error?v.message:String(v))}finally{x(!1)}},y=nl(s);return e.jsxs(L,{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:_(y==="danger"?"text-danger":y==="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:ue(s.spentUsd),cap:ue(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:_("h-full rounded-full",y==="danger"?"bg-danger":y==="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:k=>{k.preventDefault(),p()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.monthly"),e.jsx("input",{value:o,onChange:k=>l(k.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:c,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:d,onChange:k=>u(k.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:c,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:c,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[12.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("usage.budget.hint")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Gt(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 il(){const{state:s,dispatch:n}=K(),a=s.config?.billing,[i,o]=r.useState(a?.currency??"USD"),[l,d]=r.useState(Gt(a?.prices)),[u,c]=r.useState(!1),[x,m]=r.useState(null);r.useEffect(()=>{o(a?.currency??"USD"),d(Gt(a?.prices))},[a]);const g=(k,N)=>d(v=>v.map((j,E)=>E===k?{...j,...N}:j)),p=async()=>{if(u)return;const k={};for(const N of l){const v=N.key.trim();if(!v)continue;const j=Number(N.input),E=Number(N.output),w=N.cached.trim()===""?void 0:Number(N.cached);if(!Number.isFinite(j)||!Number.isFinite(E)||j<0||E<0||w!==void 0&&(!Number.isFinite(w)||w<0)){m(t("usage.prices.invalid",{model:v}));return}k[v]={inputPerMillion:j,outputPerMillion:E,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){m(t("usage.prices.currencyInvalid"));return}c(!0),m(null);try{const N=await U("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:k}})});n({type:"configStatus",config:N})}catch(N){m(N instanceof Error?N.message:String(N))}finally{c(!1)}},y="w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] tabular-nums text-ink focus:outline-none disabled:opacity-50";return e.jsxs(L,{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:k=>o(k.target.value),maxLength:3,"aria-label":t("usage.prices.currency"),disabled:u,className:"w-16 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] 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-[11.5px] 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",{}),l.map((k,N)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:k.key,onChange:v=>g(N,{key:v.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:u,className:_(y,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:k.input,onChange:v=>g(N,{input:v.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:u,className:y}),e.jsx("input",{value:k.output,onChange:v=>g(N,{output:v.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:u,className:y}),e.jsx("input",{value:k.cached,onChange:v=>g(N,{cached:v.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:u,className:y}),e.jsx("button",{type:"button",onClick:()=>d(v=>v.filter((j,E)=>E!==N)),"aria-label":t("usage.prices.remove"),disabled:u,className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(we,{size:13})})]},N))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>d(k=>[...k,{key:"",input:"",output:"",cached:""}]),disabled:u,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(De,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{p()},disabled:u,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[u&&e.jsx(H,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("usage.prices.hint")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}function rl({budget:s}){const{state:n}=K(),a=Jt(n.config,"budgets"),i=Jt(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(al,{budget:s}),i&&e.jsx(il,{})]})}const ll=["bot","model","user","day","engine","routine"];function Yt(s,n=new Date){const a=l=>l.toISOString().slice(0,10),i=n.getUTCFullYear(),o=n.getUTCMonth();return s==="month"?{from:a(new Date(Date.UTC(i,o,1))),to:a(n)}:s==="lastMonth"?{from:a(new Date(Date.UTC(i,o-1,1))),to:a(new Date(Date.UTC(i,o,0)))}:{from:a(new Date(n.getTime()-696*60*6e4)),to:a(n)}}function ol(s,n){return s==="routine"?n.key==="manual"?t("usage.history.notRoutine"):n.label: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 cl(s){return`/api/usage.csv?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}`}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"};function Xt({group:s,strong:n=!1}){if(!le(s.costUsd))return e.jsx("span",{className:_("text-right tabular-nums",n?"":"text-ink-secondary"),children:"—"});const a=le(s.estimatedUsd)&&s.estimatedUsd>0;return e.jsxs("span",{className:_("text-right tabular-nums",n?"":"text-ink"),title:a?t("usage.history.estimatedPart",{amount:ue(s.estimatedUsd)}):void 0,children:[a&&e.jsx("span",{className:"text-ink-secondary",children:"~"}),ue(s.costUsd),s.unpriced>0&&e.jsx("span",{className:"text-ink-secondary",children:"*"})]})}function dl({summary:s}){if(s.groups.length===0)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("usage.history.empty")});const n=!!s.billing,a=ys(s.total),i=n?"grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-5":"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5",o=l=>le(l)?ue(l):"—";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(i,"border-b border-hairline/40 pb-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t(Us[s.groupBy])}),e.jsx("span",{className:"text-right",children:t("usage.colTurns")}),e.jsx("span",{className:"text-right",children:vs(s.total)}),e.jsx("span",{className:"text-right",children:t("usage.colCost")}),n&&e.jsx("span",{className:"text-right",children:t("usage.history.colBillable")})]}),s.groups.map(l=>e.jsxs("div",{className:_(i,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsx("span",{className:"truncate text-ink",title:l.label,children:ol(s.groupBy,l)}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:l.turns}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("usage.history.tokenSplit",{input:je(l.input),output:je(l.output),cached:je(l.cachedInput)}),children:je(Be(l))}),e.jsx(Xt,{group:l}),n&&e.jsx("span",{className:"text-right tabular-nums text-ink",children:o(l.billableUsd)})]},l.key)),e.jsxs("div",{className:_(i,"pt-2.5 text-[13px] font-medium text-ink"),children:[e.jsx("span",{children:t("usage.history.total")}),e.jsx("span",{className:"text-right tabular-nums",children:s.total.turns}),e.jsx("span",{className:"text-right tabular-nums",children:je(Be(s.total))}),e.jsx(Xt,{group:s.total,strong:!0}),n&&e.jsx("span",{className:"text-right tabular-nums",children:o(s.total.billableUsd)})]}),a&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:a}),le(s.total.estimatedUsd)&&s.total.estimatedUsd>0&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.history.estimated",{amount:ue(s.total.estimatedUsd)})}),s.total.unpriced>0&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.history.unpriced",{count:String(s.total.unpriced)})})]})}async function ul(s,n){return U(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}`)}function xl({load:s=ul}){const[n,a]=r.useState("month"),[i,o]=r.useState("bot"),[l,d]=r.useState(null),[u,c]=r.useState(null),[x,m]=r.useState(!1),g=Yt(n);return r.useEffect(()=>{let p=!0;return m(!0),c(null),s(Yt(n),i).then(y=>{p&&d(y)}).catch(y=>{p&&c(y instanceof Error?y.message:String(y))}).finally(()=>{p&&m(!1)}),()=>{p=!1}},[n,i,s]),e.jsxs(e.Fragment,{children:[e.jsx(rl,{budget:l?.budget??null}),e.jsxs(L,{title:t("usage.history.title"),subtitle:t("usage.history.subtitle"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("select",{value:n,onChange:p=>a(p.target.value),"aria-label":t("usage.history.period"),className:"rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] text-ink focus:outline-none",children:[e.jsx("option",{value:"month",children:t("usage.history.thisMonth")}),e.jsx("option",{value:"lastMonth",children:t("usage.history.lastMonth")}),e.jsx("option",{value:"days30",children:t("usage.history.last30Days")})]}),e.jsx("div",{role:"tablist","aria-label":t("usage.history.groupBy"),className:"flex flex-wrap gap-1",children:ll.map(p=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===p,onClick:()=>o(p),className:_("rounded-lg px-2.5 py-1 text-[12px]",i===p?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink"),children:t(Us[p])},p))}),e.jsxs("a",{href:cl(g),download:!0,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(gs,{size:13}),t("usage.history.export")]})]}),u&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:u}),x&&!l?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("common.checking")]}):l?e.jsx(dl,{summary:l}):null]})]})}function pl(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 o=Math.floor(i/1440),l=Math.floor(i%1440/60),d=i%60;return o>0?l>0?`${o}d ${l}h`:`${o}d`:l>0?d>0?`${l}h ${d}m`:`${l}h`:`${d}m`}function ml(s,n,a){const i=[];for(const o of s.providers){if(!o.ok)continue;const l=[o.fiveHour.available?o.fiveHour.resetsAt:null,o.weekly.available?o.weekly.resetsAt:null,...o.extra.map(d=>d.resetsAt),...(o.models??[]).flatMap(d=>d.windows.map(u=>u.resetsAt))];for(const d of l){if(!d||a.has(d)||i.includes(d))continue;const u=Date.parse(d);Number.isFinite(u)&&u<=n&&i.push(d)}}return i}function gl(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function Qt(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s}function qe({label:s,window:n,now:a,usedHeadline:i=!1}){const o=n.available?pl(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}),o&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("planUsage.resetsIn",{when:o})})]}),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:_("h-full rounded-full",gl(l)),style:{width:`${Math.min(100,Math.max(0,l))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function hl(){const[s,n]=r.useState(null),[a,i]=r.useState(!0),[o,l]=r.useState(""),[d,u]=r.useState(()=>Date.now()),c=r.useRef(new Set),x=r.useCallback(async(m=!1)=>{i(!0),l("");try{const g=await U(m?"/api/plan-usage?refresh=1":"/api/plan-usage");n(g),u(Date.now())}catch(g){l(g instanceof Error&&g.message?g.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return r.useEffect(()=>{x(!1)},[x]),r.useEffect(()=>{const m=window.setInterval(()=>u(Date.now()),3e4);return()=>window.clearInterval(m)},[]),r.useEffect(()=>{if(!s)return;const m=ml(s,d,c.current);if(m.length!==0){for(const g of m)c.current.add(g);x(!0)}},[s,d,x]),e.jsxs(L,{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:()=>{x(!0)},disabled:a,"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:a?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})})}),a&&!s&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("planUsage.loading")}),o&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-danger",children:o}),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(m=>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:m.name}),m.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:m.plan})]}),m.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{label:t("planUsage.fiveHour"),window:m.fiveHour,now:d}),e.jsx(qe,{label:t("planUsage.weekly"),window:m.weekly,now:d}),m.extra.map((g,p)=>e.jsx(qe,{label:Qt(g.label),now:d,window:{available:!0,remainingPercent:g.remainingPercent,usedPercent:g.usedPercent,resetsAt:g.resetsAt}},`${g.label}-${p}`)),(m.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")}),(m.models??[]).map(g=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:g.name}),g.windows.map((p,y)=>e.jsx(qe,{label:Qt(p.label),now:d,usedHeadline:!0,window:{available:!0,remainingPercent:p.remainingPercent,usedPercent:p.usedPercent,resetsAt:p.resetsAt}},`${g.name}-${p.label}-${y}`))]},g.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:m.error})]},m.id))})]})}function fl(){const{state:s}=K(),n=s.bots.filter(l=>!l.hidden).map(l=>{const d=On(l),u=s.instances.find(c=>c.instanceId===l.modelSelection.instanceId);return{bot:l,usage:d,billing:u?.snapshot.billing}}).filter(l=>l.usage.turns>0).sort((l,d)=>{const u=c=>le(c)?c:Number.NEGATIVE_INFINITY;return u(d.usage.costUsd)-u(l.usage.costUsd)||Be(d.usage)-Be(l.usage)}),a=Un(n.map(l=>l.usage)),i=new Set(n.map(l=>l.billing)),o=ys(a);return e.jsxs(e.Fragment,{children:[e.jsx(hl,{}),e.jsx(L,{title:t("usage.title"),subtitle:t("usage.subtitle"),children:n.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("usage.empty")}):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-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("usage.colBot")}),e.jsx("span",{className:"text-right",children:t("usage.colTurns")}),e.jsx("span",{className:"text-right",children:vs(a)}),e.jsx("span",{className:"text-right",children:t("usage.colCost")})]}),n.map(({bot:l,usage:d})=>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:"flex min-w-0 items-center gap-2 text-ink",children:[e.jsx(Ln,{bot:l,state:"idle",size:22,animated:!1}),e.jsx("span",{className:"truncate",children:l.name})]}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:d.turns}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:Bt(d),children:je(Be(d))}),e.jsx("span",{className:"text-right tabular-nums text-ink",children:le(d.costUsd)?ue(d.costUsd):e.jsx("span",{className:"text-ink-secondary",children:"—"})})]},l.id)),e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5 pt-2.5 text-[13px] font-medium text-ink",children:[e.jsx("span",{children:t("usage.allBots")}),e.jsx("span",{className:"text-right tabular-nums",children:a.turns}),e.jsx("span",{className:"text-right tabular-nums",title:Bt(a),children:je(Be(a))}),e.jsx("span",{className:"text-right tabular-nums",children:le(a.costUsd)?ue(a.costUsd):"—"})]}),o&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:o}),le(a.costUsd)&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.costLine",{caption:i.size===1?_n([...i][0]):t("usage.costMixed")})})]})}),e.jsx(xl,{})]})}function bl(s,n,a){const i=n.trim().toLowerCase();return s.filter(o=>a&&!o.tags.includes(a)?!1:i?[o.name,o.description,o.source].some(l=>l.toLowerCase().includes(i)):!0)}function Ls({skill:s}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10.5px] text-ink-secondary",children:[e.jsxs("span",{className:"truncate",title:s.source,children:["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()})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function yl(){const{state:s}=K(),[n,a]=r.useState([]),[i,o]=r.useState(!0),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(null),[g,p]=r.useState(null),[y,k]=r.useState(""),[N,v]=r.useState(""),[j,E]=r.useState(!1),[w,D]=r.useState(""),[I,f]=r.useState(""),b=r.useRef(!1),h=s.bots.filter(R=>!R.hidden),C=r.useMemo(()=>[...new Set(n.flatMap(R=>R.tags))].sort((R,F)=>R.localeCompare(F)),[n]),A=bl(n,u,x),P=async R=>{try{const F=await fetch("/api/skills-library"),q=await F.json();if(!F.ok)throw new Error(q.error??t("skills.library.loadError"));if(R?.())return;a(q.skills??[]),d("")}catch(F){R?.()||d(F instanceof Error?F.message:t("skills.library.loadError"))}finally{R?.()||o(!1)}};r.useEffect(()=>{let R=!1;return o(!0),P(()=>R),()=>{R=!0}},[]);const V=async(R,F,q)=>{if(b.current)return;b.current=!0;const ce=`${F}:${R}`;k(ce),d("");try{const pe=await fetch("/api/skills-library"),be=await pe.json();if(!pe.ok)throw new Error(be.error??t("skills.library.loadError"));const ye=(be.skills??[]).filter(ge=>ge.assignedBots.some(ee=>ee.id===R)).map(ge=>ge.name),X=q?ye.filter(ge=>ge!==F):[...new Set([...ye,F])],se=await fetch(`/api/bots/${encodeURIComponent(R)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:X})}),Se=await se.json();if(!se.ok)throw new Error(Se.error??"Could not update assignments.");await P()}catch(pe){d(pe instanceof Error?pe.message:"Could not update assignments.")}finally{b.current=!1,k("")}},J=async R=>{I&&await V(I,R.name,!1)},$=async(R,F)=>{await V(F,R.name,!0)},W=async(R,F=!1)=>{if(!b.current){if(!R.enabled&&!F)return z(R,!0);b.current=!0,k(R.name),d("");try{const q=await fetch(`/api/skills-library/${encodeURIComponent(R.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!R.enabled})}),ce=await q.json();if(!q.ok)throw new Error(ce.error??"Could not update this skill.");F&&p(null),await P()}catch(q){d(q instanceof Error?q.message:"Could not update this skill.")}finally{b.current=!1,k("")}}},z=async(R,F=!1)=>{d("");try{const q=await fetch(`/api/skills-library/${encodeURIComponent(R.name)}`),ce=await q.json();if(!q.ok)throw new Error(ce.error??"Could not load this skill.");if(!ce.text)throw new Error("The skill contents are unavailable; import it again.");p({skill:R,text:ce.text,review:F})}catch(q){d(q instanceof Error?q.message:"Could not load this skill.")}},G=async()=>{const R=N.trim();if(R){E(!0),d(""),D("");try{const F=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:R})}),q=await F.json();if(!F.ok)throw new Error(q.error??"Could not import that skill.");D(t("skills.library.imported",{name:q.skill?.name??""})),v(""),await P()}catch(F){d(F instanceof Error?F.message:"Could not import that skill.")}finally{E(!1)}}},ne="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(L,{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(js,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:ne,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:u,onChange:R=>c(R.target.value)})]}),C.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>m(null),className:x===null?"rounded-full bg-control px-2.5 py-1 text-[11.5px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[11.5px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),C.map(R=>e.jsx("button",{type:"button",onClick:()=>m(x===R?null:R),className:x===R?"rounded-full bg-control px-2.5 py-1 font-mono text-[11.5px] font-medium text-ink":"rounded-full px-2.5 py-1 font-mono text-[11.5px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:R},R))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):A.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:n.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:A.map(R=>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:()=>{z(R)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:R.name}),children:[e.jsx("div",{className:"truncate font-mono text-[12.5px] text-ink",children:R.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[11.5px] text-ink-secondary",children:R.description})]}),e.jsx(Y,{checked:R.enabled,"aria-label":R.enabled?t("skills.library.disable",{skill:R.name}):t("skills.library.enable",{skill:R.name}),disabled:!!(y||j),onClick:()=>{W(R)}})]}),e.jsx(Ls,{skill:R}),R.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[10.5px] text-warning",children:R.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:R.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):R.assignedBots.map(F=>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:F.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:F.name}),title:t("skills.library.removeAssignment",{bot:F.name}),disabled:!!(y||j),onClick:()=>{$(R,F.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(Ue,{size:11})})]},F.id))}),h.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs("select",{"aria-label":t("skills.library.assignLabel"),value:I,disabled:!!(y||j),onChange:F=>f(F.target.value),className:"max-w-45 truncate rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[11.5px] text-ink",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),h.map(F=>e.jsx("option",{value:F.id,children:F.name},F.id))]}),e.jsx("button",{type:"button",disabled:!I||!!(y||j),onClick:()=>{J(R)},className:"rounded-lg bg-control px-2.5 py-1 text-[11.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:t("skills.library.assign")})]})]},R.name))}),l&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l})]})}),e.jsx(L,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:R=>{R.preventDefault(),G()},children:[e.jsx("textarea",{className:`${ne} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:N,onChange:R=>v(R.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:j||!!y||!N.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:j?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),g&&e.jsx(vl,{viewing:g,error:l,working:!!y,onClose:()=>{y||p(null)},onEnable:()=>{W(g.skill,!0)}})]})}function vl({viewing:s,error:n,working:a,onClose:i,onEnable:o}){const l=r.useRef(null);return ai(l,i),e.jsx("div",{ref:l,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?`Review ${s.skill.name} before enabling`: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(Ls,{skill:s.skill}),s.skill.warnings.length>0&&e.jsx("div",{className:"mt-2 text-[11.5px] 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:o,className:"mt-4 self-end rounded-lg bg-accent px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-40",children:"Enable reviewed skill"})]})})}function jl(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 kl({config:s}){const n=jl(s);return n?e.jsxs("div",{role:"status",className:_("flex items-start gap-2 rounded-xl border px-3 py-2.5 text-[12.5px] leading-relaxed",n.tone==="danger"?"border-danger/40 bg-danger/10 text-danger":"border-warning/40 bg-warning/10 text-warning"),children:[e.jsx(ke,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function _s(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Nl=()=>U("/api/fleet");function wl({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-[11.5px] 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 o=i.status==="suspended",l=i.status==="running"||o,d=i.status==="provisioning"?t("workspaces.provisioning"):i.status==="error"?t("workspaces.error"):i.status==="retained"?t("workspaces.retained"):o?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}),!l&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("workspaces.recoveryHint")})]}),e.jsx("span",{className:_("text-right",o||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:d}),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:[le(i.usage.costUsd)?ue(i.usage.costUsd):"—",le(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ue(i.usage.billableUsd)]})]}),e.jsx("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:l&&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,o?"resume":"suspend"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:o?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 Sl({domain:s,onCreated:n,disabled:a}){const[i,o]=r.useState(""),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(""),[g,p]=r.useState(""),[y,k]=r.useState(!1),[N,v]=r.useState(null),j=async()=>{if(!y){k(!0),v(null);try{const w={slug:i.trim().toLowerCase(),admins:[l.trim()],members:u.split(/[,\s]+/).map(I=>I.trim()).filter(Boolean),...x.trim()?{cap:Number(x)}:{},...g.trim()?{anthropicKey:g.trim()}:{}},D=await U("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});o(""),d(""),c(""),m(""),p(""),n(D.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){v(w instanceof Error?w.message:String(w))}finally{k(!1)}}},E="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50";return e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:w=>{w.preventDefault(),j()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:w=>o(w.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||y,"aria-label":t("workspaces.name"),className:E}),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:l,onChange:w=>d(w.target.value),type:"email",required:!0,disabled:a||y,"aria-label":t("workspaces.adminEmail"),className:E})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.members"),e.jsx("input",{value:u,onChange:w=>c(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||y,"aria-label":t("workspaces.members"),className:E})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:x,onChange:w=>m(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||y,"aria-label":t("workspaces.cap"),className:E})]}),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:g,onChange:w=>p(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||y,"aria-label":t("workspaces.anthropicKey"),className:E})]})]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),N&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:N}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||y,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[y?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(De,{size:13}),y?t("workspaces.creating"):t("workspaces.create")]})})]})}function Cl({slug:s,onDone:n}){const[a,i]=r.useState(""),[o,l]=r.useState(!1),[d,u]=r.useState(null),[c,x]=r.useState(null),m=async g=>{if(!d){u(g),x(null);try{const p=await U(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:g,email:a.trim(),chatOnly:o})});i(""),n(p.log??[])}catch(p){x(p instanceof Error?p.message:String(p))}finally{u(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[12.5px] 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:g=>i(g.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:d!==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:o,onChange:g=>l(g.target.checked),disabled:d!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:d!==null||!a.trim(),onClick:()=>{m("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:d==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:d!==null||!a.trim(),onClick:()=>{m("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:d==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),c&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}function El({load:s=Nl}){const{state:n}=K(),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),[m,g]=r.useState([]),[p,y]=r.useState(null),[k,N]=r.useState(null),[v,j]=r.useState(!1),[E,w]=r.useState(null),D=r.useCallback(async()=>{u(!0),l(null);try{i(await s())}catch(h){l(h instanceof Error?h.message:String(h))}finally{u(!1)}},[s]);r.useEffect(()=>{D()},[D]);const I=async(h,C)=>{if(C==="users"){y(A=>A===h?null:h);return}if(C==="delete"){N({slug:h,keepData:!1});return}x(h),l(null);try{const A=await U(`/api/fleet/workspaces/${encodeURIComponent(h)}/${C}`,{method:"POST"});g(A.log??[]),await D()}catch(A){l(A instanceof Error?A.message:String(A))}finally{x(null)}},f=async()=>{if(!k)return;const{slug:h,keepData:C}=k;N(null),x(h),l(null);try{const A=await U(`/api/fleet/workspaces/${encodeURIComponent(h)}`,{method:"DELETE",body:JSON.stringify({keepData:C})});g(A.log??[]),await D()}catch(A){l(A instanceof Error?A.message:String(A))}finally{x(null)}},b=async()=>{x("*"),l(null);try{const h=await U("/api/fleet/upgrade",{method:"POST"});g(h.log??[t("workspaces.upgraded")]),await D()}catch(h){l(h instanceof Error?h.message:String(h))}finally{x(null)}};return _s(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(L,{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:()=>{D()},disabled:d||c!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(d&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>j(h=>!h),disabled:c!==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(De,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{b()},disabled:c!==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:c==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),v&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(Sl,{domain:a.domain,disabled:c!==null,onCreated:(h,C)=>{j(!1),g(h),w(`https://${C.slug}.${a.domain}/pair?email=${encodeURIComponent(C.admin)}`),D()}})}),E&&e.jsx("div",{className:"mb-4",children:e.jsx(Ts,{link:E})}),o&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:o}),a?e.jsx(wl,{fleet:a,onAct:(h,C)=>{I(h,C)},busy:c}):d?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("common.checking")]}):null,p&&e.jsx(Cl,{slug:p,onDone:h=>{g(h),D()}}),m.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[11.5px] text-ink-secondary",children:m.join(`
|
|
11
|
-
`)})]}),e.jsx(Ge,{open:k!==null,title:t("workspaces.deleteTitle",{slug:k?.slug??""}),body:t(k?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>N(null),onConfirm:()=>{f()}}),k&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:k.keepData,onChange:h=>N({...k,keepData:h.target.checked})}),t("workspaces.keepData")]})]}):null}function Al({skin:s}){return e.jsxs("div",{"data-skin":s,"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 Il(){const[s,n]=r.useState(()=>document.documentElement.dataset.skin||Fn());return e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:$n.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Kn(a.id),n(a.id)},"aria-pressed":i,className:_("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(Al,{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:a.tagline})]}),i&&e.jsx(oe,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},a.id)})})}function Pl(){const{state:s,dispatch:n}=K(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,o]=r.useState(String(a)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1);r.useEffect(()=>{l||o(String(a))},[a,l]);const p=async()=>{if(!l||g.current)return;const y=Wn(i);if(!y.ok){c(t("settings.roomTurns.range"));return}g.current=!0,m(!0);try{const k=await U("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:y.minutes}})});n({type:"configStatus",config:k}),o(String(k.rooms.turnTimeoutMinutes)),d(!1),c("")}catch(k){c(k instanceof Error?k.message:t("settings.roomTurns.error"))}finally{g.current=!1,m(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${u?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:Vn,max:Hn,step:1,inputMode:"numeric",value:i,disabled:x,"aria-invalid":!!u,"aria-describedby":u?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:y=>{o(y.target.value),d(!0),c("")},onBlur:()=>{p()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),u?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:u}):null]})}const Rl=10,Fs=1,$s=60,Zt="Enter a whole number from 1 to 60.";function Bl(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:Zt};const a=Number(n);return a<Fs||a>$s?{ok:!1,error:Zt}:{ok:!0,minutes:a}}function es(s){return s?.mcp?.callTimeoutMinutes??Rl}function Dl(){const{state:s,dispatch:n}=K(),a=es(s.config),[i,o]=r.useState(String(a)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1);r.useEffect(()=>{l||o(String(a))},[a,l]);const p=async()=>{if(!l||g.current)return;const y=Bl(i);if(!y.ok){c(t("settings.mcpCalls.range"));return}g.current=!0,m(!0);try{const k=await U("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:y.minutes}})});n({type:"configStatus",config:k}),o(String(es(k))),d(!1),c("")}catch(k){c(k instanceof Error?k.message:t("settings.mcpCalls.error"))}finally{g.current=!1,m(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${u?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:Fs,max:$s,step:1,inputMode:"numeric",value:i,disabled:x,"aria-invalid":!!u,"aria-describedby":u?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:y=>{o(y.target.value),d(!0),c("")},onBlur:()=>{p()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),u?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:u}):null]})}function Tl(s,n){let a={value:s,status:"idle"},i=!1,o,l;const d=new Set,u=(x,m)=>{a={value:x,status:m};for(const g of d)g()},c=()=>(clearTimeout(l),o||(i?(u(a.value,"saving"),o=(async()=>{try{for(;i;){const x=a.value;await n(x),i=a.value!==x}u(a.value,"saved")}catch{u(a.value,"error")}})().finally(()=>{o=void 0}),o):Promise.resolve()));return{getSnapshot:()=>a,subscribe(x){return d.add(x),()=>{d.delete(x)}},confirm(x){!i&&!o&&x!==a.value&&u(x,"idle")},edit(x){i=!0,u(x,"idle"),clearTimeout(l),l=setTimeout(()=>{c()},600)},flush:c}}const ts=new WeakMap;function zl(){const{state:s,dispatch:n}=K(),a=s.config?.profile?.aboutMe??"";let i=ts.get(n);i||(i=Tl(a,async u=>{const c=await U("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:u}}),timeoutMs:1e4});n({type:"profileSaved",profile:{aboutMe:c.profile?.aboutMe??u}})}),ts.set(n,i));const{value:o,status:l}=r.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{flush:d}=i;return r.useEffect(()=>{i.confirm(a)},[i,a]),r.useEffect(()=>()=>{d()},[d]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(qn,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:24e3,onChange:u=>i.edit(u.target.value),onBlur:()=>{d()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Ml,{onChanged:u=>{i.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[l==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),l==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),l==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{d()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Ml({onChanged:s}){const[n,a]=r.useState([]),[i,o]=r.useState(null),[l,d]=r.useState(!1);r.useEffect(()=>{let c=!1;return U("/api/profile/learned").then(x=>{c||a(x.learned)}).catch(()=>{}),()=>{c=!0}},[]);const u=async c=>{o(c),d(!1);try{const x=await U(`/api/profile/learned/${encodeURIComponent(c)}/remove`,{method:"POST"});a(x.learned),s(x.aboutMe)}catch{d(!0)}finally{o(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(c=>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:[c.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:c.botName})})]}),e.jsx("button",{type:"button",disabled:i===c.id,onClick:()=>{u(c.id)},className:"rounded-md px-2 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},c.id))}),l&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}function Ol(){const{state:s,dispatch:n}=K(),a=s.config?.threads?.maxConcurrentPerBot??3,[i,o]=r.useState(null),[l,d]=r.useState(""),u=r.useRef(!1),c=async x=>{if(!(u.current||x===a)){u.current=!0,o(x),d("");try{const m=await U("/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,o(null)}}};return e.jsxs(L,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx("select",{id:"thread-concurrency",value:i??a,disabled:i!==null,"aria-describedby":"thread-concurrency-help",onChange:x=>{c(Number(x.target.value))},className:"mt-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:Array.from({length:10},(x,m)=>m+1).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threads.help")}),i!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),l&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l})]})}function Ul(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(null),[o,l]=r.useState(!1),[d,u]=r.useState(""),c=r.useRef(!1),x=a??s.config?.automaticRecovery??{enabled:!1},m=s.instances.filter(v=>v.snapshot.state==="available"&&!v.policy),g=m.find(v=>v.instanceId===x.backup?.instanceId),p=g?.models.options.filter(v=>g.snapshot.authenticated!==!1||v.custom)??[],y=p.some(v=>v.id===x.backup?.model),k=v=>{i(v),u("")},N=async()=>{if(!(!a||c.current||x.enabled&&!y)){c.current=!0,l(!0),u("");try{const v=await U("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:v}),i(null)}catch(v){u(v instanceof Error?v.message:t("settings.recovery.error"))}finally{c.current=!1,l(!1)}}};return e.jsxs(L,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(Y,{id:"automatic-recovery-enabled",checked:x.enabled,disabled:o||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope",onClick:()=>k({...x,enabled:!x.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scope")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs("select",{id:"automatic-recovery-engine",value:x.backup?.instanceId??"",disabled:o||!x.enabled,onChange:v=>k({enabled:x.enabled,...v.target.value?{backup:{instanceId:v.target.value,model:""}}:{}}),className:"mt-2 w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),x.backup&&!g&&e.jsx("option",{value:x.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:x.backup.instanceId})}),m.map(v=>e.jsx("option",{value:v.instanceId,disabled:!v.models.options.some(j=>v.snapshot.authenticated!==!1||j.custom),children:v.displayName},v.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs("select",{id:"automatic-recovery-model",value:x.backup?.model??"",disabled:o||!x.enabled||!g,onChange:v=>k({enabled:x.enabled,backup:{instanceId:g.instanceId,model:v.target.value}}),className:"mt-2 w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),x.backup?.model&&!y&&e.jsx("option",{value:x.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:x.backup.model})}),p.map(v=>e.jsx("option",{value:v.id,children:v.label},v.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),x.enabled&&!y&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||o||x.enabled&&!y,onClick:()=>{N()},className:"mt-3 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:o?t("settings.threads.saving"):t("common.save")}),o&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),d&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:d})]})}const Ks=1,Hs=3650,Ll=30,Qe=1024*1024,pt=256*1024,Vs=4*1024*1024*1024,_l=50;function ss(s){const n=Number(s);return Number.isInteger(n)&&n>=Ks&&n<=Hs?n:null}function ns(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Qe);return a>=pt&&a<=Vs&&a%pt===0?a:null}function as(s){const n=s/Qe;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function Fl(){const{state:s,dispatch:n}=K(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[o,l]=r.useState(null),[d,u]=r.useState(null),[c,x]=r.useState(null),[m,g]=r.useState(""),[p,y]=r.useState(null),k=r.useRef(!1),N=o??String(a===null?Ll:a),v=d??(i===null?String(_l):as(i));r.useEffect(()=>{o!==null&&a!==null&&String(a)===o&&l(null)},[a,o]),r.useEffect(()=>{d!==null&&i!==null&&as(i)===d&&u(null)},[i,d]);const j=async(f,b)=>{if(!k.current){k.current=!0,x(b),g(""),y(null);try{const h=await U("/api/config",{method:"PATCH",body:JSON.stringify({threads:f})});n({type:"configStatus",config:h})}catch(h){g(h instanceof Error?h.message:t("settings.threadCleanup.error"))}finally{k.current=!1,x(null)}}},E=f=>{if(!f){l(null),g(""),y(null),j({eventLogRetentionDays:null},"retention");return}const b=ss(N);if(b===null){g(t("settings.threadCleanup.invalidRetention")),y("retention");return}j({eventLogRetentionDays:b},"retention")},w=f=>{if(!f){u(null),g(""),y(null),j({eventLogMaxBytes:null},"cap");return}const b=ns(v);if(b===null){g(t("settings.threadCleanup.invalidCap")),y("cap");return}j({eventLogMaxBytes:b},"cap")},D=()=>{if(a===null)return;const f=ss(N);if(f===null){g(t("settings.threadCleanup.invalidRetention")),y("retention");return}if(f===a){l(null),g("");return}j({eventLogRetentionDays:f},"retention")},I=()=>{if(i===null)return;const f=ns(v);if(f===null){g(t("settings.threadCleanup.invalidCap")),y("cap");return}if(f===i){u(null),g("");return}j({eventLogMaxBytes:f},"cap")};return e.jsxs(L,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:c!==null,onChange:f=>E(f.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${p==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:Ks,max:Hs,step:1,inputMode:"numeric",value:N,disabled:a===null||c!==null,"aria-invalid":p==="retention","aria-describedby":"thread-log-retention-help",onChange:f=>{l(f.target.value),g(""),y(null)},onBlur:D,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:c!==null,onChange:f=>w(f.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${p==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:pt/Qe,max:Vs/Qe,step:.25,inputMode:"decimal",value:v,disabled:i===null||c!==null,"aria-invalid":p==="cap","aria-describedby":"thread-log-cap-help",onChange:f=>{u(f.target.value),g(""),y(null)},onBlur:I,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),c!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}const dt="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Pe=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Te(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},is=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function $l(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=r.useState(null),o=r.useRef(0),l=r.useRef(0);return r.useEffect(()=>{const d=++o.current,u=l.current;i(null);const c=m=>{o.current===d&&(l.current++,i(m))},x=s?.onState(c);return s?.state().then(m=>{l.current===u&&c(m)}).catch(()=>{}),()=>{o.current++,x?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Kl,{bridge:n}):e.jsx(Hl,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Kl({bridge:s}){const[n,a]=r.useState(null),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=r.useRef(0);if(r.useEffect(()=>{const x=++u.current,m=s.onState(g=>{x===u.current&&a(g.schedule??null)});return s.state().then(g=>{x===u.current&&a(g.schedule??null)}).catch(()=>{}),()=>{u.current++,m()}},[s]),!s.configureSchedule||!n?.enabled)return null;const c=async()=>{if(i||!s.configureSchedule)return;const x=u.current;o(!0),d("");try{const m=await s.configureSchedule({enabled:!1});x===u.current&&a(m.schedule??null)}catch{x===u.current&&d(t("companyBackup.scheduleFailed"))}finally{x===u.current&&o(!1)}};return e.jsx(L,{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(Y,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{c()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),l&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:l})]})})}function Hl({connection:s,bridge:n}){const[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),[m,g]=r.useState(""),[p,y]=r.useState(null),[k,N]=r.useState(""),[v,j]=r.useState(""),[E,w]=r.useState(null),[D,I]=r.useState(!1),f=r.useRef(0),b=r.useRef(0),h=r.useRef(0),C=r.useRef(void 0),A=r.useRef(!1),P=r.useRef(null),V=async()=>{const T=f.current,Q=++h.current,ie=b.current;u(!0);try{await Promise.all([n.state().then(ae=>{T===f.current&&Q===h.current&&b.current===ie&&i(ae)}),n.list().then(ae=>{T===f.current&&Q===h.current&&l(ae)})]),T===f.current&&Q===h.current&&g("")}catch{T===f.current&&Q===h.current&&g(t("companyBackup.loadFailed"))}finally{T===f.current&&Q===h.current&&u(!1)}};r.useEffect(()=>{const T=++f.current,Q=ae=>{if(T!==f.current)return;b.current++,i(ae);const ze=ae.lastBackupAt??ae.schedule?.lastBackupAt;!ae.busy&&!ae.pendingRestore&&ze&&ze!==C.current&&(C.current=ze,V())},ie=n.onState(Q);return V(),()=>{f.current++,h.current++,ie()}},[n]),r.useEffect(()=>{const T=P.current;if(!(!p||!T))return T.showModal(),()=>{T.close()}},[p]);const J=D||a?.pendingRestore===!0,$=c!==null||!a||a.busy||J,W=()=>{y(null),N(""),j(""),w(null)},z=T=>{$||A.current||(g(""),N(""),j(""),w(null),y(T))},G=async(T,Q)=>{if($||A.current)return;A.current=!0,x(T),g("");const ie=f.current;try{await Q(()=>ie===f.current)}catch{ie===f.current&&g(t(T==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{A.current=!1,ie===f.current&&x(null)}},ne=()=>{p?.kind==="create"&&G("create",async T=>{await n.create({clientState:Gn()}),T()&&(W(),await V())})},R=async T=>{if(!n.configureSchedule||A.current||!a||T&&($||p?.kind!=="schedule"||v!=="BACK UP THIS WORKSPACE DAILY"))return;A.current=!0,x("schedule"),g("");const Q=f.current,ie=b.current;j("");try{const ae=await n.configureSchedule(T?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});Q===f.current&&(b.current===ie&&i(ae),W())}catch{Q===f.current&&g(t("companyBackup.scheduleFailed"))}finally{A.current=!1,Q===f.current&&x(null)}},F=()=>{p?.kind!=="restore"||p.entry.passwordRequired!==!1&&(k.length<12||k.length>1024)||G("prepare",async T=>{const Q=k;N(""),w(null),j("");const ie=await n.prepareRestore({id:p.entry.id,...p.entry.passwordRequired!==!1?{password:Q}:{}});T()&&w(ie)})},q=()=>{p?.kind!=="restore"||!E||v!=="REPLACE"||G("restore",async T=>{const Q=localStorage.getItem(Tt);if(Q&&Q!==E.id)throw new Error("An earlier restore needs recovery first.");localStorage.setItem(Tt,E.id),await n.restore({id:E.id,confirmation:"REPLACE"}),T()&&(I(!0),W())})},ce=()=>{p?.kind!=="delete"||v!=="DELETE"||G("delete",async T=>{await n.delete({id:p.entry.id,confirmation:"DELETE"}),T()&&(W(),await V())})},pe=async()=>{const T=f.current;try{await n.cancel()}catch{T===f.current&&g(t("companyBackup.actionFailed"))}},be=o?.backups.filter(T=>T.status==="ready")??[],ye=o?o.backups.length-be.length:0,X=a?.progress,se=m||a?.message,Se=(a?.busy||c)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:c==="restore"?t("backup.restoring"):X?t(`companyBackup.phase.${X.phase}`):t("companyBackup.working")}),X&&X.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:X.totalBytes,value:Math.min(X.bytesTransferred,X.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Pe(X.bytesTransferred),total:Pe(X.totalBytes)})})]}),a?.busy&&c!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{pe()},children:t("companyBackup.cancelTransfer")})]}),ge=p?.kind==="restore"?t("companyBackup.restore"):p?.kind==="delete"?t("companyBackup.delete"):p?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ee=a?.schedule,Le=T=>new Intl.DateTimeFormat(Te(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(T));return e.jsxs(L,{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&&ee&&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(Y,{"aria-label":t("companyBackup.daily"),checked:ee.enabled,disabled:c!==null||!a||!ee.enabled&&$,onClick:()=>ee.enabled?void R(!1):z({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ee.status}`)}),ee.enabled&&ee.nextBackupAt&&Number.isFinite(ee.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:Le(ee.nextBackupAt)})}),ee.lastBackupAt&&Number.isFinite(ee.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:Le(ee.lastBackupAt)})}),ee.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ee.message})]}),J?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(Dt,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:$,onClick:()=>z({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:c!==null||a?.busy||J||d,onClick:()=>{V()},children:t("companyBackup.refresh")})]}),d&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),o&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:Pe(o.usedBytes),total:Pe(o.limits.ownerQuotaBytes),count:o.limits.retainedSnapshots})}),ye>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:ye})}),o&&be.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:be.map(T=>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:is(T)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Pe(T.sizeBytes),T.appVersion?` · ${T.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:T.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:$,onClick:()=>z({kind:"restore",entry:T}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$,onClick:()=>z({kind:"delete",entry:T}),children:t("companyBackup.delete")})]})]},T.id))})]}),!p&&Se,!p&&se&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:se})]}),p&&e.jsx("dialog",{ref:P,"aria-labelledby":"company-backup-dialog-title",onKeyDown:T=>{(T.key==="Escape"||T.key==="Tab")&&T.stopPropagation()},onCancel:T=>{T.preventDefault(),c||W()},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:ge}),J&&e.jsx(Dt,{}),(p.kind==="restore"||p.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[is(p.entry)," · ",Pe(p.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:p.entry.id})]}),(p.kind==="create"||p.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:T=>{T.preventDefault(),p.kind==="schedule"?R(!0):ne()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(p.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),p.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")}),p.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:$,checked:v==="BACK UP THIS WORKSPACE DAILY",onChange:T=>j(T.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:$||p.kind==="schedule"&&v!=="BACK UP THIS WORKSPACE DAILY",children:t(p.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),p.kind==="restore"&&(E?e.jsxs(e.Fragment,{children:[e.jsx(Jn,{summary:E.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:$,value:v,onChange:T=>j(T.target.value),className:dt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$||v!=="REPLACE",onClick:q,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:T=>{T.preventDefault(),F()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),p.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:$,value:k,onChange:T=>N(T.target.value),className:dt})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:$||p.entry.passwordRequired!==!1&&(k.length<12||k.length>1024),children:t("backup.validate")})]})),p.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:$,value:v,onChange:T=>j(T.target.value),className:dt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$||v!=="DELETE",onClick:ce,children:t("companyBackup.delete")})]}),Se,se&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:se}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:c!==null,onClick:W,children:t("companyBackup.cancel")})]})})]})}const rs=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Je=[{id:"general",group:"you",labelKey:"settings.section.general",icon:xt,keywords:["profile","name","email","about me","about","suggestions","suggested","memory","analytics","updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule"]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ss,keywords:["skin","theme","appearance","tools","tool calls","threads","show threads","hide threads","sidebar","density","compact","comfortable","avatars","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Xn,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:fi,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:Qn,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","vps","router","openrouter","base url","openai","anthropic","groq","opencode","provider"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:Zn,keywords:["decision","jev","typesafe","routing","auto","rooms","who answers"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:ea,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:ot,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:Ns,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:xt,keywords:["cloud","account","personal","sign in","pro","subscription","billing"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:ot,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:ri,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:ta,keywords:["export","import","restore","full backup","password","recovery"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:sa,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:pi,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:ot,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:na,keywords:["early","preview","learn","skill","authoring"]}],Vl=[{id:"general",labelKey:"settings.section.general",icon:xt,sections:["general"]},{id:"appearance",labelKey:"settings.section.appearance",icon:Ss,sections:["appearance"]},{id:"ai",labelKey:"settings.group.ai",icon:ra,sections:["engines","connections","decisionModel"]},{id:"computers",labelKey:"settings.group.computers",icon:Ns,sections:["companion","desktopWorkspaces","computer"]},{id:"account",labelKey:"settings.group.account",icon:oi,sections:["cloudAccount","organization","people","activity"]}],Wl=["usage","backups","experimental","workspaces","skills"];function ql(s,n){const a=new Set(s.map(l=>l.id)),i=Vl.map(l=>({...l,sections:l.sections.filter(d=>a.has(d))})).filter(l=>l.sections.length>0),o=Wl.includes(n)?s.find(l=>l.id===n):void 0;return o&&i.push({id:o.id,labelKey:o.labelKey,icon:o.icon,sections:[o.id]}),i}function Jl(s,n,a){if(a<=0){s.scrollTop=0;return}s.querySelector(`[data-settings-block="${n}"]`)?.scrollIntoView?.({block:"start"})}function Gl(s,n){return!n||t(s.labelKey).toLowerCase().includes(n)?!0:s.sections.some(a=>{const i=Je.find(o=>o.id===a);return i?Ws(i,n):!1})}function Ws(s,n){return n?[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n)):!0}function Yl(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(s.config?.profile?.name??""),[o,l]=r.useState(s.config?.profile?.email??"");r.useEffect(()=>{i(s.config?.profile?.name??""),l(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const d=()=>{fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:o.trim().toLowerCase()}})}).then(c=>{if(!c.ok)throw new Error("Profile save failed");return c.json()}).then(c=>{c.profile&&n({type:"profileSaved",profile:{name:c.profile.name,email:c.profile.email}})}).catch(()=>{})},u="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:c=>i(c.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:u}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:o,onChange:c=>l(c.target.value),onBlur:d,placeholder:"you@example.com",className:u}),e.jsx(zl,{})]})}function Xl(){const s=$a(),n=window.ogb?.updater;if(!s||!n)return null;const a=s.status==="checking"?t("settings.updates.checking"):s.status==="downloading"?s.percent==null?t("settings.updates.startingDownload"):t("settings.updates.downloading",{percent:Math.round(s.percent)}):s.status==="preparing"?t("settings.updates.preparing"):s.status==="downloaded"?s.installMode==="handoff"?t("settings.updates.readyInstall",{app:Ye().name,version:s.version??""}):t("settings.updates.ready",{app:Ye().name,version:s.version??""}):s.status==="installing"?s.message||(s.installMode==="handoff"?t("settings.updates.openingTerminal"):t("settings.updates.restarting")):s.status==="handed-off"?t("settings.updates.handedOff"):s.status==="error"?t("settings.updates.failed",{message:s.message??t("settings.updates.unknownError")}):t("settings.updates.latest");return e.jsx(te,{title:t("settings.updates.title"),subtitle:a,children:e.jsx("button",{onClick:()=>{if(s.status==="downloaded")return void n.install();n.check()},disabled:s.status==="checking"||s.status==="downloading"||s.status==="preparing"||s.status==="installing"||s.retryable===!1,className:"ui-button",children:s.retryable===!1?t("settings.updates.quitReopen"):s.status==="downloaded"?s.installMode==="handoff"?t("settings.updates.install"):t("settings.updates.restart"):s.status==="preparing"?t("settings.updates.preparingShort"):s.status==="installing"?s.installMode==="handoff"?t("settings.updates.opening"):t("settings.updates.restartingShort"):t("settings.updates.check")})})}function Ql(){const{state:s,dispatch:n}=K(),a=s.config?.newBots?.effort??"",[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async c=>{if(!i){o(!0),d("");try{const x=await U("/api/config",{method:"PATCH",body:JSON.stringify({newBots:{effort:Ka(c)?c:null}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.newBotEffort.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.newBotEffort.title"),subtitle:t("settings.newBotEffort.subtitle"),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsxs("select",{value:a,disabled:i,"aria-label":t("settings.newBotEffort.aria"),onChange:c=>{u(c.target.value)},className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus disabled:cursor-wait disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.newBotEffort.default")}),Oa.map(c=>e.jsx("option",{value:c,children:Ua(c)},c))]})})}function Zl(){const[s,n]=r.useState(La);return e.jsx(te,{title:t("settings.analytics.title"),subtitle:t("settings.analytics.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.analytics.aria"),onClick:()=>{const a=!s;_a(a),n(a)}})})}function eo(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(!1);return e.jsxs("div",{children:[e.jsx("button",{disabled:a,onClick:()=>{i(!0),l(!1),U("/api/config",{method:"PUT",body:JSON.stringify({onboarding:{...s.config?.onboarding?.completedAt?{}:Va().onboarding,hintsSeen:Ha(s.config?.onboarding)}}),signal:AbortSignal.timeout(1e4)}).then(d=>{n({type:"configStatus",config:d}),n({type:"toggleTour",open:!0})}).catch(()=>l(!0)).finally(()=>i(!1))},className:"ui-button",children:t("settings.welcome.appTour")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[13px] text-danger",children:t("onboarding.tour.error")})]})}function to(){const{dispatch:s}=K();return e.jsx(te,{title:t("settings.welcome.title"),subtitle:t("settings.welcome.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(eo,{}),e.jsx("button",{onClick:()=>s({type:"toggleWelcome",open:!0}),className:"ui-button",children:t("settings.welcome.replay")})]})})}function so(){const{state:s}=K(),n=Da(Ta(),s.config?.language);return e.jsx(te,{title:t("settings.language.title"),subtitle:t("settings.language.subtitle"),children:e.jsxs("select",{value:n,"aria-label":t("settings.language.aria"),onChange:a=>Ma(a.target.value),className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus disabled:cursor-wait disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.language.system")}),za.map(({code:a,label:i})=>e.jsx("option",{value:a,children:i},a))]})})}function no(){const s=Aa();return e.jsx(te,{title:t("settings.notificationSounds.title"),subtitle:t("settings.notificationSounds.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Ia(!s)})})}function ao(){const[s,n]=r.useState(ga);return e.jsx(te,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx("select",{value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;fa(i),n(i)},className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus",children:ha.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function ls(){const s=ks();return e.jsx(te,{title:t("settings.advancedMode.title"),subtitle:t("settings.advancedMode.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.advancedMode.title"),onClick:()=>ma(!s)})})}function io(){const s=ka();return e.jsx(te,{title:t("settings.threadDisplay.title"),subtitle:t("settings.threadDisplay.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.threadDisplay.show"),onClick:()=>Na(!s)})})}function ro(){const s=wa();return e.jsx(te,{title:t("settings.pinnedCircles.title"),subtitle:t("settings.pinnedCircles.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.pinnedCircles.title"),onClick:()=>Sa(!s)})})}const lo={comfortable:"sidebar.density.comfortable",compact:"sidebar.density.compact",icons:"sidebar.density.iconsOnly"};function oo(){const s=ba();return e.jsx(te,{title:t("sidebar.density.title"),subtitle:t("settings.sidebarDensity.subtitle"),children:e.jsx("select",{value:s,"aria-label":t("sidebar.density.chooseAria"),onChange:n=>va(ja(n.target.value)),className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus",children:ya.map(n=>e.jsx("option",{value:n,children:t(lo[n])},n))})})}function co(){const s=Ra();return e.jsx(te,{title:t("settings.runCard.title"),subtitle:t("settings.runCard.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.runCard.show"),onClick:()=>Ba(!s)})})}function uo(){const s=Ca();return e.jsx(te,{title:t("settings.universalPins.title"),subtitle:t("settings.universalPins.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.universalPins.title"),onClick:()=>Ea(!s)})})}function xo(){const{state:s,dispatch:n}=K(),a=Fa(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async()=>{if(!i){o(!0),d("");try{const c=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{routinesInConversation:!a}})});n({type:"configStatus",config:c})}catch(c){d(c instanceof Error?c.message:t("settings.routinesInConversation.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.routinesInConversation.title"),subtitle:t("settings.routinesInConversation.subtitle"),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.routinesInConversation.aria"),disabled:i,onClick:()=>{u()},className:"disabled:cursor-wait disabled:opacity-50"})})}function po(){const{state:s,dispatch:n}=K(),a=Pa(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async()=>{if(!i){o(!0),d("");try{const c=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{showToolCalls:!a}})});n({type:"configStatus",config:c})}catch(c){d(c instanceof Error?c.message:t("settings.toolCalls.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.toolCalls.title"),subtitle:e.jsxs(e.Fragment,{children:[t("settings.toolCalls.subtitle")," ",t("settings.toolCalls.detail")]}),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.toolCalls.aria"),disabled:i,onClick:()=>{u()},className:"disabled:cursor-wait disabled:opacity-50"})})}function mo(){const{state:s,dispatch:n}=K(),a=pa(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async c=>{if(!i){o(!0),d("");try{const x=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{skillAuthoring:c}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.experimental.error"))}finally{o(!1)}}};return e.jsxs(L,{title:t("settings.experimental.title"),subtitle:t("settings.experimental.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:t("settings.experimental.skillAuthoring")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.experimental.skillAuthoringDetail")})]}),e.jsx(Y,{checked:a,"aria-label":t("settings.experimental.skillAuthoringAria"),disabled:i,onClick:()=>{u(!a)},className:"disabled:cursor-wait disabled:opacity-50"})]}),l?e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l}):null]})}function os(){const{state:s,dispatch:n}=K(),a=ws(s.config),i=ua(s.config),o=s.config?.browserEngine?.installable===!0,l=window.ogb?.platform==="win32"&&!i&&!o,[d,u]=r.useState(!1),[c,x]=r.useState(""),m=async g=>{if(!d){u(!0),x("");try{const p=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{browser:g}})});n({type:"configStatus",config:p})}catch(p){x(p instanceof Error?p.message:t("settings.experimental.error"))}finally{u(!1)}}};return e.jsx("div",{"data-built-in-browser":!0,className:"rounded-xl bg-card px-4",children:e.jsx(te,{title:t("settings.experimental.browserAria"),subtitle:i?a?t("settings.experimental.browserOn"):t("settings.experimental.browserOff"):l?t("settings.experimental.browserWindows"):xa(s.config),message:c?e.jsx("p",{role:"alert",className:"text-danger",children:c}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.experimental.browserAria"),disabled:d||!a&&!i&&!o,onClick:()=>{m(!a)},className:"disabled:cursor-wait disabled:opacity-50"})})})}function cs(){const{state:s}=K(),n=s.config?.browserProfiles??[];return!ws(s.config)&&n.length===0?null:e.jsx(L,{title:t("settings.profiles.title"),subtitle:t("settings.profiles.sharedSubtitle"),children:e.jsx(Za,{})})}function go(){const[s,n]=r.useState(!1),[a,i]=r.useState(null),o=async()=>{if(!(!window.ogb?.exportDiagnostics||s)){n(!0),i(null);try{const l=await window.ogb.exportDiagnostics();l&&i({kind:"success",message:t("settings.diagnostics.saved",{path:l})})}catch(l){i({kind:"error",message:l instanceof Error?l.message:String(l)})}finally{n(!1)}}};return e.jsx(te,{title:t("settings.diagnostics.title"),subtitle:t("settings.diagnostics.subtitle"),message:a?e.jsx("p",{role:a.kind==="error"?"alert":"status",className:_("break-all",a.kind==="error"?"text-danger":"text-success"),children:a.message}):null,children:e.jsx("button",{onClick:()=>{o()},disabled:s,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:s?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})})}function Co(){const{state:s,dispatch:n}=K(),a=ks(),i=window.ogb?.remoteClient?.active===!0,o=i&&!["appearance","desktopWorkspaces"].includes(s.appSettingsSection)||s.appSettingsSection==="remote"?"companion":s.appSettingsSection,l=r.useRef(null),d=r.useRef(null),[u,c]=r.useState("");r.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>c("")),[]),r.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>c("")),[]);const x=u.trim().toLowerCase(),m=Yn(),p=Je.filter(b=>!i||b.id==="companion"||b.id==="appearance"||b.id==="desktopWorkspaces").filter(b=>b.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(b=>b.id!=="organization"||!!window.ogb?.organization).filter(b=>b.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&s.config?.cloudHome===!0)).filter(b=>b.id!=="workspaces"||_s(s.config)).filter(b=>b.id!=="people"||!window.ogb&&s.config?.cloudHome!==!0).filter(b=>b.id!=="activity"||!window.ogb&&m===!0).filter(b=>b.id!=="skills"||zt(s.config)),y=p.filter(b=>Ws(b,x)),k=a?[]:ql(p,o),N=k.filter(b=>Gl(b,x)),v=k.find(b=>b.sections.includes(o)),j=a?Je.find(b=>b.id===o)?.labelKey:v?.labelKey,E=a?y.some(b=>b.id===o)?void 0:y[0]?.id:v&&N.includes(v)?void 0:N[0]&&(N[0].sections.find(b=>y.some(h=>h.id===b))??N[0].sections[0]);r.useEffect(()=>{E&&n({type:"toggleAppSettings",open:!0,section:E})},[n,E]);const w=v?.sections.indexOf(o)??0;r.useEffect(()=>{d.current&&Jl(d.current,o,a?0:w)},[a,o,w]),r.useEffect(()=>{const b=document.activeElement instanceof HTMLElement?document.activeElement:null,h=l.current,C=h?.querySelector("[data-settings-search]");C?.checkVisibility()?C.focus():h?.focus();const A=P=>{if(P.defaultPrevented||h&&[...h.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(z=>z.getClientRects().length))return;if(P.key==="Escape"){P.preventDefault(),n({type:"toggleAppSettings",open:!1});return}if(P.key!=="Tab"||!h)return;const V=Array.from(h.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(z=>z.checkVisibility());if(V.length===0){P.preventDefault(),h.focus();return}const J=V[0],$=V[V.length-1],W=document.activeElement;P.shiftKey&&(W===J||!h.contains(W))?(P.preventDefault(),$.focus()):!P.shiftKey&&W===$&&(P.preventDefault(),J.focus())};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A),b?.focus()}},[n]);const D=b=>n({type:"toggleAppSettings",open:!0,section:b}),I=b=>{switch(b){case"desktopWorkspaces":return e.jsx(Mr,{});case"organization":return window.ogb?.organization&&!i?e.jsx(Kr,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&s.config?.cloudHome===!0)&&!i?e.jsx(sl,{linkRequest:s.appSettingsCloudLink,cloudHome:s.config?.cloudHome===!0,onConnectPhone:()=>n(da())}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-2xl border border-accent-border/40 bg-raised-hover/40 px-1",children:e.jsx(ls,{})}),e.jsx(ca,{}),e.jsx(L,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:e.jsx(Yl,{})}),e.jsxs("div",{children:[e.jsx(so,{}),e.jsx(Ql,{}),e.jsx(Zl,{}),e.jsx(ii,{})]}),e.jsx(L,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(Pl,{})}),e.jsx(L,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(Dl,{})}),e.jsx(Ol,{}),!i&&e.jsx(xo,{}),e.jsx(Ul,{}),e.jsx(Fl,{}),e.jsxs("div",{children:[!i&&e.jsx(to,{}),e.jsx(Xl,{}),e.jsx(go,{})]})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(Il,{})}),e.jsxs("div",{children:[i&&e.jsx(ls,{}),e.jsx(ao,{}),e.jsx(oo,{}),a&&e.jsx(io,{}),e.jsx(ro,{}),e.jsx(uo,{}),e.jsx(no,{}),!i&&e.jsx(po,{}),e.jsx(co,{})]})]});case"experimental":return e.jsx(mo,{});case"connections":return e.jsx(L,{title:t("settings.connections.title"),subtitle:t("settings.connections.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[s.config?.composio.mode==="managed"?e.jsx("div",{className:"rounded-lg border border-success/25 bg-success/10 px-3 py-2 text-[13px] text-success",children:t("settings.connections.ready")}):null,e.jsx("div",{className:"text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:t("keys.providers.title")}),e.jsx("p",{className:"-mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("keys.providers.subtitle")}),e.jsx(me,{section:"openai",testProvider:"openai"}),e.jsx(me,{section:"anthropic",testProvider:"anthropic"}),e.jsx(Ga,{}),e.jsx(me,{section:"xai",testProvider:"xai"}),e.jsx(me,{section:"openrouter",testProvider:"openrouter"}),e.jsx(me,{section:"mistral",testProvider:"mistral"}),e.jsx(me,{section:"cerebras",testProvider:"cerebras"}),e.jsxs("details",{"data-api-keys-other":!0,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",open:!!s.config?.openaiCompat?.configured,children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink-secondary",children:t("keys.other.title")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-4",children:[e.jsx(me,{section:"openaiCompat",testProvider:"openaiCompat"}),e.jsx(Ya,{})]})]}),e.jsx("div",{className:"pt-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:t("keys.integrations.title")}),e.jsx(me,{section:"box"}),e.jsx(Xa,{}),e.jsx(me,{section:"opencodeGo"}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"-mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((h,C)=>C===0?[h]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},C),h])}),e.jsx(Qa,{}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink-secondary",children:t("settings.connections.selfHost")}),e.jsx("div",{className:"mt-3",children:e.jsx(me,{section:"composio"})})]})]})});case"decisionModel":return e.jsx(wi,{});case"engines":return e.jsx(Li,{});case"backups":return e.jsxs(e.Fragment,{children:[e.jsx(oa,{}),e.jsx($l,{})]});case"companion":{const h=s.appSettingsPhonePairing,C=la(s.config?.cloudHome===!0)==="computer";return e.jsxs(e.Fragment,{children:[e.jsx(Dr,{}),!i&&e.jsx(Rr,{}),e.jsx(fr,{cloudHome:s.config?.cloudHome===!0,focusRequest:C?0:h}),!i&&e.jsx(ur,{profileEmail:s.config?.profile?.email,focusRequest:C?h:0})]})}case"computer":return a?e.jsxs(e.Fragment,{children:[e.jsx(os,{}),e.jsx(cs,{}),e.jsx(Lt,{})]}):e.jsx(Lt,{});case"usage":return e.jsx(fl,{});case"skills":return zt(s.config)?e.jsx(yl,{}):null;case"people":return e.jsx(wr,{});case"activity":return e.jsx(Cr,{});case"workspaces":return e.jsx(El,{});default:return null}},f=b=>e.jsx("h3",{className:"px-1 text-[13px] font-semibold uppercase tracking-[0.06em] text-ink-secondary",children:t(b)});return e.jsxs("div",{className:"glass-popup-frame",style:ia(),onMouseDown:b=>b.target===b.currentTarget&&n({type:"toggleAppSettings",open:!1}),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:l,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-[24px] outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),e.jsxs("div",{className:"mb-2 mt-1 flex min-h-8 shrink-0 items-center gap-2 rounded-lg border border-transparent bg-control/70 px-2.5 py-2 focus-within:border-focus",children:[e.jsx(js,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:u,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),u?c(""):n({type:"toggleAppSettings",open:!1}))},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),(a?y.length===0:N.length===0)&&e.jsx("div",{className:"px-2.5 py-4 text-[12.5px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:u.trim()})}),a?rs.map(b=>{const h=y.filter(C=>C.group===b.id);return h.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${b.id}`,"data-settings-group":b.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${b.id}`,className:"px-2.5 pb-1 pt-2 text-[11px] font-medium uppercase tracking-[0.08em] text-ink-tertiary",children:t(b.labelKey)}),h.map(({id:C,labelKey:A,icon:P})=>e.jsxs("button",{"data-settings-section":C,onClick:()=>D(C),"aria-current":o===C?"page":void 0,className:_("flex min-h-9 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors motion-reduce:transition-none",o===C?"bg-control text-ink":"text-ink-secondary hover:bg-control/50 hover:text-ink"),children:[e.jsx(P,{size:15,className:"shrink-0"}),t(A)]},C))]},b.id)}):e.jsx("div",{className:"flex flex-col gap-0.5 pb-2",children:N.map(b=>{const h=b.icon,C=b===v;return e.jsxs("button",{"data-settings-page":b.id,onClick:()=>D(b.sections[0]),"aria-current":C?"page":void 0,className:_("flex min-h-9 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors motion-reduce:transition-none",C?"bg-control text-ink":"text-ink-secondary hover:bg-control/50 hover:text-ink"),children:[e.jsx(h,{size:15,className:"shrink-0"}),t(b.labelKey)]},b.id)})})]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:px-5",children:[a?e.jsx("select",{"aria-label":t("settings.title"),value:o,onChange:b=>{c(""),D(b.target.value)},className:"min-w-0 rounded-lg bg-control px-3 py-2 text-[14px] text-ink sm:hidden",children:rs.map(b=>{const h=p.filter(C=>C.group===b.id);return h.length===0?null:e.jsx("optgroup",{label:t(b.labelKey),children:h.map(({id:C,labelKey:A})=>e.jsx("option",{value:C,children:t(A)},C))},b.id)})}):e.jsx("select",{"aria-label":t("settings.title"),value:v?.id??"",onChange:b=>{c("");const h=k.find(C=>C.id===b.target.value);h&&D(h.sections[0])},className:"min-w-0 rounded-lg bg-control px-3 py-2 text-[14px] text-ink sm:hidden",children:k.map(b=>e.jsx("option",{value:b.id,children:t(b.labelKey)},b.id))}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:j?t(j):null}),e.jsx("button",{onClick:()=>n({type:"toggleAppSettings",open:!1}),"aria-label":t("settings.close"),title:`${t("settings.close")} (${aa("close-panel")})`,className:"ui-icon-button shrink-0",children:e.jsx(Ue,{size:18})})]}),e.jsxs("div",{ref:d,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(kl,{config:s.config}),a?I(o):v?v.sections.map(b=>{const h=v.sections.length>1,C=Je.find(A=>A.id===b)?.labelKey;return e.jsxs("section",{"data-settings-block":b,className:"flex scroll-mt-2 flex-col gap-4",children:[h&&C?f(C):null,I(b),b==="computer"&&e.jsxs("div",{"data-settings-block":"browser",className:"flex flex-col gap-4 pt-2",children:[f("settings.experimental.browser"),e.jsx(os,{}),e.jsx(cs,{})]})]},b)}):null]})]})]})]})}export{Je as SECTIONS,rs as SETTINGS_GROUPS,Wl as SIMPLE_HIDDEN_SECTIONS,Vl as SIMPLE_PAGES,Co as SettingsModal,Xl as UpdatesRow,Jl as revealSettingsBlock,Ws as sectionMatches,ql as simpleSettingsPages};
|
|
10
|
+
}`}function Br({status:s}){return e.jsxs("details",{className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:t("settings.domain.guide")}),e.jsxs("ol",{className:"mt-3 list-decimal space-y-3 pl-4 leading-relaxed",children:[e.jsx("li",{children:t("settings.domain.dns")}),e.jsxs("li",{children:[t("settings.domain.proxy"),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-md bg-app p-3 text-[11px] leading-relaxed text-ink",children:e.jsx("code",{children:Rr(s)})}),e.jsx("p",{className:"mt-2",children:t("settings.domain.proxyHint")})]}),e.jsx("li",{children:t("settings.domain.verifyHint")})]}),e.jsx("p",{className:"mt-3 text-warning",children:t("settings.domain.loopbackWarning")}),!s.serverIpv4&&e.jsx("p",{className:"mt-3",children:t("settings.domain.ipAdminHint")}),e.jsx("p",{className:"mt-3",children:t("settings.domain.scope")}),e.jsxs("a",{className:"mt-3 inline-flex items-center gap-1.5 text-accent hover:underline",href:"https://github.com/milind-soni/OpenMausBot/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings",target:"_blank",rel:"noopener noreferrer",children:[t("settings.domain.fullGuide")," ",e.jsx(Ze,{size:12})]})]})}function Dr(){const[s,n]=r.useState(null),[a,i]=r.useState(""),[o,l]=r.useState("loading"),[d,u]=r.useState(null),[c,x]=r.useState(null);r.useEffect(()=>{const g=new AbortController;return U("/api/settings/custom-domain",{signal:g.signal}).then(p=>{g.signal.aborted||(n(p),i(p.customDomain??""))}).catch(p=>{g.signal.aborted||u(p instanceof Error?p.message:t("settings.domain.failed"))}).finally(()=>{g.signal.aborted||l(null)}),()=>g.abort()},[]);const m=async g=>{l(g?"removing":"saving"),u(null),x(null);try{const p=await U("/api/settings/custom-domain",{method:g?"DELETE":"POST",...g?{}:{body:JSON.stringify({domain:a.trim()})}});n(p),i(p.customDomain??""),x(g?t("settings.domain.removed"):t("settings.domain.saved"))}catch(p){u(p instanceof Error?p.message:t("settings.domain.failed"))}finally{l(null)}};return e.jsx(L,{title:t("settings.domain.title"),subtitle:t("settings.domain.subtitle"),children:e.jsxs("div",{className:"space-y-3","data-custom-domain-settings":!0,children:[o==="loading"&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("settings.domain.loading")]}),s&&!s.supported&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:g=>{g.preventDefault(),a.trim()&&!o&&m(!1)},className:"space-y-2",children:[e.jsx("label",{htmlFor:"custom-domain",className:"block text-[13px] font-medium text-ink",children:t("settings.domain.label")}),e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:o!==null,onChange:g=>{i(g.target.value),x(null),u(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx(Pr,{domain:a,serverIpv4:s.serverIpv4}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("settings.domain.httpsNeeded")}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs("button",{type:"submit",disabled:!a.trim()||o!==null,className:"inline-flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[o==="saving"?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(Pn,{size:14}),o==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")]}),s.customDomain&&e.jsx("button",{type:"button",disabled:o!==null,onClick:()=>{m(!0)},className:"rounded-lg bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:o==="removing"?t("settings.domain.removing"):t("settings.domain.remove")})]})]}),s.publicUrl&&e.jsxs("p",{className:"break-all text-[11.5px] text-ink-secondary",children:[t("settings.domain.current"),": ",e.jsx("span",{className:"text-ink",children:s.publicUrl})]}),s.customDomain&&e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")}),e.jsx(Br,{status:s})]}),c&&e.jsxs("p",{role:"status",className:"flex items-start gap-1.5 text-[12px] leading-relaxed text-success",children:[e.jsx(oe,{size:14,className:"mt-0.5 shrink-0"}),c]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] leading-relaxed text-danger",children:d})]})})}const We="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 Kt(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Tr(s){const n=s.trim();if(!/^https:\/\//i.test(n)||/[\s\\]/.test(n))return!1;try{const a=new URL(n),i=/(?:^|[#&])code=([^&]+)/.exec(a.hash)?.[1];return a.protocol==="https:"&&!a.username&&!a.password&&!a.search&&(a.pathname==="/pair"||a.pathname==="/pair/")&&!!(i&&decodeURIComponent(i).trim())}catch{return!1}}function zr(){const s=window.ogb?.remoteClient,n=window.ogb?.environments,[a,i]=r.useState({active:s?.active===!0}),[o,l]=r.useState(n?"server":"companion"),[d,u]=r.useState(""),[c,x]=r.useState(""),[m,g]=r.useState(""),[p,y]=r.useState(!1),[k,N]=r.useState(""),v=r.useRef(!1),j=!!n&&o==="server",C=r.useRef(!0),w=r.useCallback(()=>{s?.state().then(f=>{C.current&&i(f)}).catch(()=>{})},[s]);r.useEffect(()=>(C.current=!0,w(),()=>{C.current=!1}),[w]);const D=async()=>{if(!(v.current||!s&&!n)){v.current=!0,y(!0),N("");try{if(j&&n){if(!Tr(d))throw new Error(t("remote.client.server.invalidLink"));await n.addFromLink(d.trim()),w()}else s&&(await s.pair(c,m),w())}catch(f){N(Kt(f))}finally{v.current=!1,y(!1)}}},I=async()=>{if(!(!s||v.current)){v.current=!0,y(!0),N("");try{await s.disconnect(),w()}catch(f){N(Kt(f))}finally{v.current=!1,y(!1)}}};return e.jsxs(L,{title:a.active?t("remote.client.active"):t("remote.client.idle"),subtitle:t("remote.client.subtitle"),children:[!s&&!n?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.client.desktopOnly")}):a.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(ut,{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:a.serverName||t("remote.client.fallbackName")})}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:a.endpoint})]})]}),e.jsx("p",{className:"text-[12.5px] leading-relaxed text-ink-secondary",children:t("remote.client.mode")}),e.jsxs("button",{type:"button",disabled:p,onClick:()=>{I()},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:[p?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ji,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:f=>{f.preventDefault(),D()},children:[n&&s?e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.connectionType"),e.jsxs("select",{value:o,disabled:p,onChange:f=>{l(f.target.value),N("")},className:We,children:[e.jsx("option",{value:"server",children:t("remote.client.server.option")}),e.jsx("option",{value:"companion",children:t("remote.client.companion.option")})]})]}):null,j?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[12.5px] leading-relaxed text-ink-secondary",children:t("remote.client.server.hint")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx openmausbot pair --client"}),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:d,onChange:f=>u(f.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:p,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:We})]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("remote.client.server.domainHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[12.5px] 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:c,onChange:f=>x(f.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:p,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:We})]}),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:m,onChange:f=>g(f.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:p,inputMode:"numeric",autoComplete:"one-time-code",className:`${We} max-w-40 font-mono tracking-[0.2em]`})]})]}),k?e.jsx("p",{role:"alert",className:"text-[12.5px] text-danger",children:k}):null,e.jsxs("button",{type:"submit",disabled:p||(j?!d.trim():c.trim()===""||m.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:[p?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ut,{size:14}),j?t("remote.client.server.connect"):t("remote.client.pair")]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:j?t("remote.client.server.switchNote"):t("remote.client.restartNote")})]}),a.active&&k?e.jsx("p",{role:"alert",className:"mt-3 text-[12.5px] text-danger",children:k}):null]})}const Mr={list_files:"lending.action.listFiles",read_file:"lending.action.readFile",write_file:"lending.action.writeFile",run_command:"lending.action.runCommand",computer_tools:"lending.action.screenTools",computer_call:"lending.action.screen",invalid:"lending.action.invalid"};function zs({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()}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(Mr[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 Or({workspace:s,onClose:n}){const{state:a}=K(),o=hs(a.config)?window.ogb?.computerSharing:void 0,[l,d]=r.useState(null),[u,c]=r.useState([]),[x,m]=r.useState(!1),[g,p]=r.useState(!1),[y,k]=r.useState(!1),[N,v]=r.useState(""),[j,C]=r.useState(null),w=r.useRef(!1),D=r.useRef(!1),I=r.useRef(null),f=h=>{d(h),c(h.folders),m(h.terminal),p(h.computer)};r.useEffect(()=>{w.current=!0,I.current?.scrollIntoView({block:"start"}),o?.state(s.id).then(A=>{w.current&&f(A)}).catch(()=>{w.current&&v("Could not load computer access. Reopen this page to try again.")});const h=()=>{o?.state(s.id).then(A=>{w.current&&d(A)}).catch(()=>{}),o?.activity?.(s.id).then(A=>{w.current&&C(A)}).catch(()=>{})};h();const E=setInterval(h,3e3);return()=>{w.current=!1,clearInterval(E)}},[o,s.id]);const b=async h=>{if(!D.current){D.current=!0,k(!0),v("");try{await h()}catch(E){w.current&&v(String(E?.message??E).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{D.current=!1,w.current&&k(!1)}}};return o?e.jsx("div",{ref:I,children:e.jsx(L,{title:`Computer access · ${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?"Sharing while this desktop is open":"Waiting for the workspace to connect":"Not shared":"Loading access…"}),e.jsx("button",{type:"button","aria-label":"Close computer access",onClick:n,className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(De,{size:16})})]}),e.jsx("p",{className:"text-ink-secondary",children:"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."}),e.jsxs("fieldset",{disabled:y||!l,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:"Shared folders"}),u.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"No folders shared. New folders are read-only by default."}),u.map(h=>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:h.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:h.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:h.write,onChange:E=>c(A=>A.map(P=>P.id===h.id?{...P,write:E.target.checked}:P))}),"Allow edits"]}),e.jsx("button",{type:"button","aria-label":`Remove ${h.name}`,onClick:()=>c(E=>E.filter(A=>A.id!==h.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(De,{size:14})})]},h.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{b(async()=>{const h=await o.chooseFolder();w.current&&h&&c(E=>E.some(A=>A.path===h.path)?E:[...E,h])})},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(fs,{size:14}),"Choose folder"]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"Small files only (256 KB). Folder access does not follow links or delete files."})]}),e.jsxs("fieldset",{disabled:y||!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:"Broader access · optional"}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:x,onChange:h=>m(h.target.checked)}),e.jsxs("span",{className:"text-ink",children:["Unrestricted terminal",e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:"Run commands as you. This can access or delete files anywhere you can, including credentials—not just the folders above."})]})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:g,onChange:h=>p(h.target.checked)}),e.jsxs("span",{className:"text-ink",children:["Computer control",e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:"View your screen and operate your signed-in apps, outside the shared folders. Requires local computer control and OS permissions."})]})]})]}),(N||l?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:N||l?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:y||!l||!u.length&&!x&&!g,onClick:()=>{b(async()=>{const h=await o.save(s.id,{folders:u,terminal:x,computer:g});w.current&&h&&f(h)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:l?.enabled?"Save access":"Share selected access"}),l?.enabled&&e.jsx("button",{type:"button",disabled:y,onClick:()=>{b(async()=>{const h=await o.revoke(s.id);w.current&&f(h)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:"Stop sharing"})]}),l?.enabled&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:"Stopping blocks new requests and cancels running work where possible. An action already sent to an app may still finish."}),e.jsx("div",{className:"border-t border-hairline/40 pt-3",children:e.jsx(zs,{entries:j})})]})})}):null}function Ur(){const s=window.ogb?.environments,{state:n}=K(),a=hs(n.config)&&!!window.ogb?.computerSharing,[i,o]=r.useState(null),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(!1),[g,p]=r.useState(""),[y,k]=r.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),N=!!window.ogb?.cloudMove&&!window.ogb?.remoteClient?.active,[v,j]=r.useState(()=>new URLSearchParams(window.location?.search??"").get("copy-to")),C=r.useRef(!1),w=r.useRef(0);r.useEffect(()=>{const f=++w.current;return s?.state().then(b=>{w.current===f&&o(b)}).catch(()=>{w.current===f&&p("Could not load saved servers. Please reopen this page.")}),()=>{w.current++}},[s]),r.useEffect(()=>{const f=(b,h)=>{b&&(h==="copy"?j:k)(b);const E=new URL(window.location.href);E.searchParams.delete("share-computer"),E.searchParams.delete("copy-to"),window.history.replaceState(null,"",`${E.pathname}${E.search}${E.hash}`)};return f(),s?.onOpenSettings?.(f)},[s]);const D=async f=>{if(C.current||!s)return;C.current=!0,m(!0),p("");const b=w.current;try{if(await f()===!0)return;const h=await s.state();w.current===b&&o(h)}catch(h){w.current===b&&p(String(h?.message??h).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{C.current=!1,w.current===b&&m(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:"Manage server connections in the desktop app."});const I=i?.environments.find(f=>f.id===y);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:"One desktop app, wherever your bots live. Switching servers does not move or replace your bots, conversations, or provider accounts."}),e.jsx(L,{title:"Your servers",subtitle:"Saved on this computer. Your hosted bots keep running when you switch away.",children:i?e.jsx("ul",{className:"divide-y divide-hairline/40",children:[{id:"local",name:"This computer",origin:""},...i.environments].map(f=>{const b=f.id===i.activeId,h=f.id==="local"?ut:mt;return e.jsxs("li",{className:"flex items-center gap-3 py-3",children:[e.jsx(h,{size:18,className:"shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:f.name}),e.jsx("div",{className:"break-all text-[12px] text-ink-secondary",children:f.origin||"Local bots and conversations"})]}),b?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(oe,{size:13}),"Current"]}):e.jsx("button",{type:"button",disabled:x,"aria-label":`Switch to ${f.name}`,onClick:()=>{D(async()=>(await s.switch(f.id),!0))},className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:"Switch"}),f.id!=="local"&&N&&e.jsx("button",{type:"button",disabled:x,"aria-label":`${t("cloudMove.here")}: ${f.name}`,onClick:()=>j(f.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:t("cloudMove.here")}),f.id!=="local"&&a&&e.jsx("button",{type:"button",disabled:x,"aria-label":`Computer access for ${f.name}`,onClick:()=>k(f.id),className:"rounded-md px-2 py-1.5 text-[12px] text-ink hover:bg-control",children:"Computer access"}),f.id!=="local"&&e.jsx("button",{type:"button",disabled:x,"aria-label":`Forget ${f.name}`,title:`Forget ${f.name}`,onClick:()=>{D(()=>s.forget(f.id))},className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(we,{size:14})})]},f.id)})}):e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:g?"Saved servers could not be loaded.":"Loading servers…"})}),N&&v&&i?.environments.some(f=>f.id===v)&&e.jsx(bs,{destination:v,onClose:()=>j(null)},v),a&&I&&e.jsx(Or,{workspace:I,onClose:()=>k(null)},I.id),e.jsx(L,{title:"Connect to a server",subtitle:"Already running OpenMausBot on a VPS, server, or another computer? Connect it here.",children:e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:f=>{f.preventDefault(),l.trim()&&D(()=>s.addFromLink(l.trim(),u.trim()))},children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:["Server address or pairing link",e.jsx("input",{required:!0,value:l,disabled:x,onChange:f=>d(f.target.value),placeholder:"https://bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:["Name (optional)",e.jsx("input",{value:u,disabled:x,maxLength:60,onChange:f=>c(f.target.value),placeholder:"My server",className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:"Paste a pairing link from your server’s Settings → Remote access, or enter its address and sign in there. Your desktop stays connected afterward."}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:"Need a pairing code?"}),e.jsx("p",{className:"mt-2",children:"Run this on the server and copy the link it prints:"}),e.jsx("code",{className:"mt-1 block select-all break-words rounded-md bg-inset px-2 py-2 text-ink",children:'npx openmausbot pair --label "My desktop"'})]}),g&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:g}),e.jsxs("button",{type:"submit",disabled:x||!l.trim(),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-50",children:[x&&e.jsx(H,{size:14,className:"animate-spin"}),"Connect"]})]})})]})}function Ms(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function Lr(s,n){return s.find(a=>Ms(a)&&a.instanceId.endsWith(`.${n}`))}function bt(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function Ht(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return bt(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function _r(s,n){const a=n.filter(d=>Ms(d)&&bt(d)),i=a.find(d=>d.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const o={target:i,bots:[],needsAsk:[]},l=d=>n.find(u=>u.instanceId===d)?.driverKind;for(const d of s){if(d.hidden)continue;const u=Rn(d);if(Ht(d.modelSelection,n)||Ht(u.modelSelection,n))continue;([d,u].some(x=>Bn(Dn(x),l(x.modelSelection.instanceId),i.driverKind))?o.needsAsk:o.bots).push(d)}return o}const Fr={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function $r({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=K(),[o,l]=r.useState(!1),[d,u]=r.useState(null),c=_r(n.bots,n.instances),x=c.target,m=p=>p.map(y=>y.name).join(", "),g=async()=>{if(!x||!c.bots.length||o)return;const p=c.bots,y={instanceId:x.instanceId,model:x.models.default};l(!0),u(null);for(const k of p)a({type:"setModel",botId:k.id,selection:y});try{const k=await Promise.all(p.map(v=>i(v.id).catch(()=>null))),N=p.filter((v,j)=>k[j]?.modelSelection.instanceId===y.instanceId);N.length&&u({name:x.displayName,bots:N.map(v=>v.name)})}finally{l(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(p=>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:Fr[p.id]??p.id}),e.jsx("span",{className:"text-ink-secondary",children:p.configured?t("organization.modelCount",{count:p.models.length}):t("organization.notConfigured")})]}),p.configured&&p.models.length>0&&e.jsx(Kr,{instance:Lr(n.instances,p.id),instances:n.instances})]},p.id))}),d&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:d.name,names:d.bots.join(", ")})}),x&&c.bots.length>0&&e.jsxs("div",{"data-company-switch":!0,className:"flex flex-col items-start gap-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"break-words text-[13px] text-ink",children:t("organization.useCompanyBots",{names:m(c.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:o,onClick:()=>{g()},children:c.bots.length===1?t("organization.useCompanyOne",{name:x.displayName}):t("organization.useCompanyMany",{name:x.displayName,count:c.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),x&&c.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:m(c.needsAsk)})})]})}function Kr({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(bt(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(oe,{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&&Tn(a)?e.jsx(us,{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 Hr={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},Vt="https://admin.openmausbot.com";function Vr(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[n,a]=r.useState(null),[i,o]=r.useState(""),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1),p=r.useRef(0),y=r.useRef(0),k=r.useRef(void 0),N=f=>{const b=k.current!==f.status;k.current=f.status,a(f),b&&c(""),f.status!=="connected"&&f.status!=="reauth-required"&&m(!1)};r.useEffect(()=>{s?.settingsOpened?.().catch(()=>{});const f=++p.current,b=y.current,h=A=>{p.current===f&&(y.current++,N(A))},E=s?.onState(h);return s?.state().then(A=>{y.current===b&&h(A)}).catch(()=>{p.current===f&&y.current===b&&c(t("organization.loadFailed"))}),()=>{p.current++,E?.()}},[s]);const v=async f=>{if(!s||g.current)return;g.current=!0,d(!0),c("");const b=p.current,h=y.current;try{const E=await f();p.current===b&&y.current===h&&N(E)}catch{p.current===b&&y.current===h&&c(t("organization.actionFailed"))}finally{g.current=!1,p.current===b&&d(!1)}};if(!s)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const j=n?.status==="connected"||n?.status==="reauth-required"||n?.status==="unavailable"||n?.status==="license-expired",C=n?.status==="license-expired"||n?.notice==="license-expired",w=n?.enrollment?.expiresAt??n?.expiresAt,D=typeof w=="number"&&Number.isFinite(w)?new Date(w):null,I=D&&Number.isFinite(D.getTime())?new Intl.DateTimeFormat(ze(),{dateStyle:"medium",timeStyle:"short"}).format(D):null;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.additive")}),e.jsxs(L,{title:t("settings.section.organization"),subtitle:t("organization.privacy"),children:[!n&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:u||t("organization.loading")}),n?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:n.message}),C&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),n?.status==="signed-out"&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.signInHelp")}),e.jsx("button",{type:"button",disabled:l,onClick:()=>{v(()=>s.begin({portalOrigin:Vt}))},className:"w-fit rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:l?t("organization.working"):t("organization.signIn")}),e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.advanced")}),e.jsxs("form",{className:"mt-2 flex flex-col gap-2",onSubmit:f=>{f.preventDefault(),i.trim()&&v(()=>s.begin({portalOrigin:i.trim()}))},children:[e.jsx("p",{children:t("organization.advancedHelp")}),e.jsxs("label",{className:"flex flex-col gap-1.5",children:[t("organization.address"),e.jsx("input",{type:"url",required:!0,value:i,disabled:l,onChange:f=>o(f.target.value),placeholder:Vt,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink outline-none focus:border-accent/50"})]}),e.jsx("button",{type:"submit",disabled:l||!i.trim(),className:"ui-button w-fit",children:t("organization.customSignIn")})]})]})]}),n?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.browserConsent")}),n.enrollment&&e.jsxs("details",{className:"w-full text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.securityDetails")}),e.jsx("p",{className:"mt-2",children:t("organization.securityDetailsHelp")}),e.jsx("div",{className:"mt-3",children:t("organization.code")}),e.jsx("code",{dir:"ltr",className:"mt-1 block w-fit select-all rounded-lg bg-inset px-3 py-2 text-base tracking-widest text-ink",children:n.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.enrollment&&s.reopen&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.cancelEnrollment())},children:t("organization.cancel")})]})]}),j&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[n.branding?.logo&&e.jsx("img",{src:n.branding.logo,alt:"Organization logo",className:"mb-2 size-12 rounded-lg object-contain"}),e.jsx("div",{className:"break-words text-[15px] font-medium text-ink",children:n.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:n.email})]}),n.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):n.status==="license-expired"?e.jsx(e.Fragment,{children:n.providers?.some(f=>f.configured&&f.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:n.providers.filter(f=>f.configured&&f.models.length>0).map(f=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:Hr[f.id]??f.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},f.id))})}):n.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),n.providers?.some(f=>f.configured&&f.models.length>0)?e.jsx($r,{providers:n.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:()=>{v(()=>s.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{v(()=>s.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>m(!0),children:t("organization.disconnect")})]})]}),n?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),I&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:I})}),u&&n&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u}),!n&&e.jsx("button",{type:"button",disabled:l,className:"ui-button mt-3",onClick:()=>{v(()=>s.refresh())},children:t("organization.refresh")})]})]})}const Wt={"connect-first":"lending.status.connectFirst","not-cloud":"lending.status.notCloud",waiting:"lending.status.waiting",paused:"lending.status.paused","signed-out":"lending.status.signedOut","account-changed":"lending.status.accountChanged","machine-changed":"lending.status.machineChanged"};function Wr(s,n){const a=s?.state;return a?.enabled?a.busy?"lending.status.busy":a.connected?"lending.status.lent":Wt[a.problem??""]??"lending.status.starting":n?"lending.status.chooseSomething":a?.problem&&a.problem!=="paused"?Wt[a.problem]??null:null}function qr({bridge:s}){const[n,a]=r.useState(null),[i,o]=r.useState(!1),[l,d]=r.useState([]),[u,c]=r.useState(!1),[x,m]=r.useState(!1),[g,p]=r.useState(!1),y=r.useRef(!1),k=r.useRef(!1),N=f=>{k.current&&(a(f),!y.current&&f.state&&(d(f.state.folders),c(f.state.screen)))};r.useEffect(()=>{k.current=!0;const f=()=>{s.state().then(N).catch(()=>{})};f();const b=setInterval(f,3e3);return()=>{k.current=!1,clearInterval(b)}},[s]);const v=async f=>{if(!y.current){y.current=!0,m(!0),p(!1);try{const b=await f();y.current=!1,N(b)}catch{k.current&&p(!0)}finally{y.current=!1,k.current&&m(!1)}}},j=(f,b)=>{d(f),c(b),v(()=>f.length||b?s.save({folders:f,screen:b}):s.stop())},C=n?.state?.enabled===!0,w=C||i,D=()=>{if(w){o(!1),v(()=>s.stop());return}o(!0),(l.length||u)&&j(l,u)};if(!n?.available)return null;const I=Wr(n,w);return e.jsxs("div",{"data-cloud-lending":C?"on":"off",className:"mt-2 flex w-full flex-col gap-3 border-t border-hairline/40 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:t("lending.title")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("lending.explain")})]}),e.jsx(Y,{checked:w,disabled:x,"aria-label":t("lending.title"),onClick:D})]}),I&&e.jsx("p",{role:"status",className:`text-[13px] ${C&&n.state?.busy?"font-medium text-ink":"text-ink-secondary"}`,children:t(I)}),w&&e.jsxs(e.Fragment,{children:[e.jsxs("fieldset",{disabled:x,className:"flex flex-col gap-2 disabled:opacity-60",children:[e.jsx("legend",{className:"mb-1 text-[13px] font-medium text-ink",children:t("lending.folders")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.foldersHelp")}),l.map(f=>e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border border-hairline/40 p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] text-ink",children:f.name}),e.jsx("p",{dir:"ltr",className:"break-all text-[11px] text-ink-secondary",children:f.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:f.write,onChange:b=>j(l.map(h=>h.id===f.id?{...h,write:b.target.checked}:h),u)}),t("lending.canEdit")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:f.name}),onClick:()=>j(l.filter(b=>b.id!==f.id),u),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(De,{size:14})})]},f.id)),e.jsxs("button",{type:"button",disabled:l.length>=20,onClick:()=>{v(async()=>{const f=await s.chooseFolder(),b=f&&!l.some(h=>h.path===f.path)?[...l,f]:l;return b!==l?(d(b),s.save({folders:b,screen:u})):s.state()})},className:"ui-button flex w-fit items-center gap-2",children:[e.jsx(fs,{size:14}),t("lending.addFolder")]})]}),e.jsxs("fieldset",{disabled:x,className:"flex flex-col gap-1 disabled:opacity-60",children:[e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:u,disabled:!u&&!n.screenAvailable,onChange:f=>j(l,f.target.checked)}),e.jsxs("span",{className:"text-[13px] text-ink",children:[t("lending.screen"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("lending.screenHelp")})]})]}),!n.screenAvailable&&e.jsx("p",{className:"ms-6 text-[12px] text-ink-secondary",children:t("lending.screenUnavailable")})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.ownConversations")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.stopHelp")})]}),g&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("lending.failed")}),(w||(n.activity?.length??0)>0)&&e.jsx(zs,{entries:n.activity??[]})]})}const Jr={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},qt=[["reserving","cloudHome.step.reserving"],["storage","cloudHome.step.storage"],["starting","cloudHome.step.starting"],["checking","cloudHome.step.checking"]],Os=s=>new Intl.DateTimeFormat(ze(),{timeStyle:"short"}).format(new Date(s)),Gr=s=>new Intl.DateTimeFormat(ze(),{dateStyle:"medium"}).format(new Date(s));function Yr(s){if(!s.setup)return null;const n=qt.findIndex(([a])=>a===s.setup.step);return e.jsx("ol",{"data-cloud-setup":s.setup.step,className:"flex flex-col gap-1 text-[13px]",children:qt.map(([a,i],o)=>e.jsx("li",{"aria-current":o===n?"step":void 0,className:o===n?"font-medium text-ink":o<n?"text-ink-secondary line-through decoration-ink-secondary/40":"text-ink-secondary",children:t(i)},a))})}function Xr({machine:s,busy:n,failed:a,onConnect:i,lending:o}){const l=s.status==="ready",d=s.status==="failed"&&s.retryAt?t("cloudHome.failedRetry",{time:Os(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):t(Jr[s.status]);return e.jsx(L,{title:t("cloudHome.title"),children:e.jsxs("div",{"data-cloud-home":s.status,className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:s.status==="ready"?"text-[14px] text-ink":"text-[13px] text-ink-secondary",children:d}),s.status==="provisioning"&&Yr(s),l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudHome.connect")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudHome.connectHelp")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudHome.connectFailed")}),o&&e.jsx(qr,{bridge:o})]})})}function Qr({ready:s,busy:n,failed:a,onUse:i}){return e.jsx(L,{title:t("cloudPhone.title"),subtitle:t("cloudPhone.subtitle"),children:e.jsxs("div",{"data-cloud-phone":s?"open":"steps",className:"flex flex-col items-start gap-3",children:[s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:n,className:"ui-button",onClick:i,children:t("cloudPhone.action")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudPhone.help")})]}),a&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudPhone.failed")}),(!s||a)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(s?"cloudPhone.stepsIntro":"cloudPhone.notReady")}),e.jsxs("ol",{className:"list-decimal ps-5 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("li",{children:t("cloudPhone.step1")}),e.jsx("li",{children:t("cloudPhone.step2")})]})]})]})})}function Zr(s,n){return n.arrived&&s.status==="signed-out"&&s.message!=="restoring"?"sign-in":!n.connected&&s.status==="connected"&&s.machine?.status==="ready"?"connect":null}const el={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function tl(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(el[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:Gr(n.paidAt)}):t("cloudAccount.purchaseNoteNoDate"):n.kind==="attention"&&!s.machine?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 sl(s,n){return n.kind==="free"?t("cloudAccount.upgrade"):n.kind==="paid"||n.kind==="unverified"&&n.label?t("cloudAccount.manage"):s.machine?.status==="payment-problem"?t("cloudAccount.updatePayment"):t("cloudAccount.dashboard")}function nl({bridge:s,onConnectPhone:n}){const[a,i]=r.useState(null),[o,l]=r.useState(!1),[d,u]=r.useState(!1);if(r.useEffect(()=>{let g=!0;return s.state().then(p=>{g&&i(p)}).catch(()=>{g&&u(!0)}),()=>{g=!1}},[s]),d)return e.jsx(L,{title:t("settings.section.cloudAccount"),children:e.jsx("p",{"data-cloud-plan":"elsewhere",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudNone")})});const c=Un(a?.tier),x=a?.status==="paid"?t("cloudAccount.pro",{plan:c}):a?.status==="attention"?t("cloudAccount.inactive",{plan:a.tier?c:"OpenMausBot Cloud"}):a?.status==="checking"?t("cloudAccount.lastPlan",{plan:c}):a?.status==="signin"?a.tier?t("cloudAccount.planName",{plan:c}):null:a?t("cloudAccount.onCloudNone"):null,m=g=>{l(!1),g().catch(()=>l(!0))};return e.jsx(L,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.onCloud"),children:e.jsxs("div",{"data-cloud-plan":a?.status??"loading",className:"flex flex-col items-start gap-3",children:[x?e.jsx("p",{role:"status",className:"text-[15px] font-medium text-ink",children:x}):!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),a?.status==="signin"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.onCloudSignIn")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(()=>s.manage()),children:t("cloudAccount.manageInBrowser")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(()=>s.useThisComputer()),children:t("cloudAccount.useThisComputer")}),a&&n&&e.jsx("button",{type:"button",className:"ui-button",onClick:n,children:t("cloudPhone.action")})]}),o&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:t("cloudAccount.actionFailed")})]})})}function al({linkRequest:s=0,cloudHome:n=!1,onConnectPhone:a}={}){const i=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:o}=zn().capabilities.host,[l,d]=r.useState(null),[u,c]=r.useState(!1),[x,m]=r.useState(!1),[g,p]=r.useState(!1),[y,k]=r.useState(!1),[N,v]=r.useState(!1),j=r.useRef(0),C=r.useRef(0),w=r.useRef(!1),D=r.useRef({request:0,arrived:!1,connected:!1});r.useEffect(()=>{const $=++j.current,W=C.current,z=ne=>{j.current===$&&(C.current++,d(ne),m(!1),ne.status==="signed-out"&&p(!1))},G=i?.onState(z);return i?.state().then(ne=>{C.current===W&&z(ne)}).catch(()=>{j.current===$&&C.current===W&&m(!0)}),()=>{j.current++,G?.()}},[i]);const I=async $=>{if(!i||w.current)return;w.current=!0,c(!0),m(!1);const W=j.current,z=C.current;try{const G=await $();j.current===W&&C.current===z&&d(G)}catch{j.current===W&&C.current===z&&m(!0)}finally{w.current=!1,j.current===W&&c(!1)}},f=()=>{i&&(k(!1),I(async()=>{try{return await i.connectHome()}catch{return k(!0),i.state()}}))},b=()=>{i&&(v(!1),I(async()=>{try{return await i.connectHomeForPhone()}catch{return v(!0),i.state()}}))};if(r.useEffect(()=>{if(s||(D.current.request=0),!i||!s||!l||w.current||(D.current.request!==s&&(D.current={request:s,arrived:!0,connected:!1}),l.status==="signed-out"&&l.message==="restoring"))return;const $=Zr(l,D.current);D.current.arrived=!1,$==="sign-in"&&I(()=>i.begin()),$==="connect"&&(D.current.connected=!0,f())},[i,s,l,u]),!i){const $=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return $?e.jsx(nl,{bridge:$,onConnectPhone:a}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")})}const h=Mn(l),E=l&&["connected","unavailable","reauth-required"].includes(l.status),A=tl(l,h,o),P=On(h),V=l?.status==="connected"?l.machine??(h.kind==="paid"?{status:"provisioning"}:void 0):void 0,J=l?.status==="connecting"?l.enrollment:void 0;return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("cloudAccount.optional")}),e.jsxs(L,{title:t("settings.section.cloudAccount"),subtitle:t("cloudAccount.separate"),children:[(!l||h.kind==="unknown")&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.loading")}),A&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:A}),h.kind==="signed-out"&&e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.begin())},children:t("cloudAccount.signIn")}),l?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("cloudAccount.browser")}),J&&e.jsxs("div",{"data-cloud-code":!0,className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.codeCheck")}),e.jsx("code",{dir:"ltr",className:"select-all text-[18px] font-semibold tracking-widest text-ink",children:J.userCode}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("cloudAccount.codeUntil",{time:Os(J.expiresAt)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.cancel())},children:t("organization.cancel")})]})]}),E&&e.jsxs("div",{className:"flex flex-col gap-3",children:[l.account&&e.jsx("p",{className:"break-all text-[14px] text-ink",children:l.account.email}),P&&e.jsxs("p",{role:"status","data-cloud-plan":h.kind,className:"text-[15px] font-medium text-ink",children:[P,h.kind==="paid"&&h.checking&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:t("cloudAccount.checking")})]}),h.kind==="free"&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.purchaseHelp")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[h.kind==="reauth"?e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.signInAgain())},children:t("cloudAccount.signInAgain")}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.openDashboard())},children:sl(l,h)}),e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>{I(()=>i.refresh())},children:t("organization.refresh")})]}),!g&&e.jsx("button",{type:"button",disabled:u,className:"ui-button",onClick:()=>p(!0),children:t("cloudAccount.signOut")})]}),h.kind==="free"&&!g&&e.jsxs("p",{className:"text-[12px] text-ink-secondary",children:[t("cloudAccount.otherEmail")," ",e.jsx("button",{type:"button",disabled:u,className:"underline hover:text-ink",onClick:()=>p(!0),children:t("cloudAccount.useOtherEmail")})]}),g&&e.jsxs("div",{role:"group","aria-label":t("cloudAccount.signoutTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("cloudAccount.signoutHelp")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:u,className:"ui-button",onClick:()=>p(!1),children:t("cloudAccount.keep")}),e.jsx("button",{type:"button",disabled:u,className:"ui-button text-danger",onClick:()=>{I(()=>i.signOut())},children:t("cloudAccount.signOut")})]})]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudAccount.actionFailed")}),!l&&e.jsx("button",{type:"button",disabled:u,className:"ui-button mt-3",onClick:()=>{I(()=>i.state())},children:t("organization.refresh")})]}),V&&Xr({machine:V,busy:u,failed:y,onConnect:f,lending:i.lending}),E&&h.kind==="paid"&&Qr({ready:V?.status==="ready",busy:u,failed:N,onUse:b}),V?.status==="ready"&&e.jsx(bs,{destination:"cloud"})]})}function Jt(s,n){return s?.edition?.features?.includes(n)===!0}function il(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function rl({budget:s}){const{state:n,dispatch:a}=K(),i=n.config?.budgets??{},[o,l]=r.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[d,u]=r.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[c,x]=r.useState(!1),[m,g]=r.useState(null);r.useEffect(()=>{l(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),u(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const p=async()=>{if(c)return;const k=o.trim()===""?0:Number(o),N=Number(d);if(!Number.isFinite(k)||k<0||!Number.isInteger(N)||N<1||N>100){g(t("usage.budget.invalid"));return}x(!0),g(null);try{const v=await U("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:k,warnAtPercent:N}})});a({type:"configStatus",config:v})}catch(v){g(v instanceof Error?v.message:String(v))}finally{x(!1)}},y=il(s);return e.jsxs(L,{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:_(y==="danger"?"text-danger":y==="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:ue(s.spentUsd),cap:ue(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:_("h-full rounded-full",y==="danger"?"bg-danger":y==="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:k=>{k.preventDefault(),p()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.monthly"),e.jsx("input",{value:o,onChange:k=>l(k.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:c,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:d,onChange:k=>u(k.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:c,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:c,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[12.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[c&&e.jsx(H,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("usage.budget.hint")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function Gt(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 ll(){const{state:s,dispatch:n}=K(),a=s.config?.billing,[i,o]=r.useState(a?.currency??"USD"),[l,d]=r.useState(Gt(a?.prices)),[u,c]=r.useState(!1),[x,m]=r.useState(null);r.useEffect(()=>{o(a?.currency??"USD"),d(Gt(a?.prices))},[a]);const g=(k,N)=>d(v=>v.map((j,C)=>C===k?{...j,...N}:j)),p=async()=>{if(u)return;const k={};for(const N of l){const v=N.key.trim();if(!v)continue;const j=Number(N.input),C=Number(N.output),w=N.cached.trim()===""?void 0:Number(N.cached);if(!Number.isFinite(j)||!Number.isFinite(C)||j<0||C<0||w!==void 0&&(!Number.isFinite(w)||w<0)){m(t("usage.prices.invalid",{model:v}));return}k[v]={inputPerMillion:j,outputPerMillion:C,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){m(t("usage.prices.currencyInvalid"));return}c(!0),m(null);try{const N=await U("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:k}})});n({type:"configStatus",config:N})}catch(N){m(N instanceof Error?N.message:String(N))}finally{c(!1)}},y="w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] tabular-nums text-ink focus:outline-none disabled:opacity-50";return e.jsxs(L,{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:k=>o(k.target.value),maxLength:3,"aria-label":t("usage.prices.currency"),disabled:u,className:"w-16 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] 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-[11.5px] 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",{}),l.map((k,N)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:k.key,onChange:v=>g(N,{key:v.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:u,className:_(y,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:k.input,onChange:v=>g(N,{input:v.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:u,className:y}),e.jsx("input",{value:k.output,onChange:v=>g(N,{output:v.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:u,className:y}),e.jsx("input",{value:k.cached,onChange:v=>g(N,{cached:v.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:u,className:y}),e.jsx("button",{type:"button",onClick:()=>d(v=>v.filter((j,C)=>C!==N)),"aria-label":t("usage.prices.remove"),disabled:u,className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(we,{size:13})})]},N))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>d(k=>[...k,{key:"",input:"",output:"",cached:""}]),disabled:u,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(Te,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{p()},disabled:u,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[12.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[u&&e.jsx(H,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("usage.prices.hint")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}function ol({budget:s}){const{state:n}=K(),a=Jt(n.config,"budgets"),i=Jt(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(rl,{budget:s}),i&&e.jsx(ll,{})]})}const cl=["bot","model","user","day","engine","routine"];function Yt(s,n=new Date){const a=l=>l.toISOString().slice(0,10),i=n.getUTCFullYear(),o=n.getUTCMonth();return s==="month"?{from:a(new Date(Date.UTC(i,o,1))),to:a(n)}:s==="lastMonth"?{from:a(new Date(Date.UTC(i,o-1,1))),to:a(new Date(Date.UTC(i,o,0)))}:{from:a(new Date(n.getTime()-696*60*6e4)),to:a(n)}}function dl(s,n){return s==="routine"?n.key==="manual"?t("usage.history.notRoutine"):n.label: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 ul(s){return`/api/usage.csv?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}`}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"};function Xt({group:s,strong:n=!1}){if(!le(s.costUsd))return e.jsx("span",{className:_("text-right tabular-nums",n?"":"text-ink-secondary"),children:"—"});const a=le(s.estimatedUsd)&&s.estimatedUsd>0;return e.jsxs("span",{className:_("text-right tabular-nums",n?"":"text-ink"),title:a?t("usage.history.estimatedPart",{amount:ue(s.estimatedUsd)}):void 0,children:[a&&e.jsx("span",{className:"text-ink-secondary",children:"~"}),ue(s.costUsd),s.unpriced>0&&e.jsx("span",{className:"text-ink-secondary",children:"*"})]})}function xl({summary:s}){if(s.groups.length===0)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("usage.history.empty")});const n=!!s.billing,a=ys(s.total),i=n?"grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-5":"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5",o=l=>le(l)?ue(l):"—";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:_(i,"border-b border-hairline/40 pb-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t(Us[s.groupBy])}),e.jsx("span",{className:"text-right",children:t("usage.colTurns")}),e.jsx("span",{className:"text-right",children:vs(s.total)}),e.jsx("span",{className:"text-right",children:t("usage.colCost")}),n&&e.jsx("span",{className:"text-right",children:t("usage.history.colBillable")})]}),s.groups.map(l=>e.jsxs("div",{className:_(i,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsx("span",{className:"truncate text-ink",title:l.label,children:dl(s.groupBy,l)}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:l.turns}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("usage.history.tokenSplit",{input:je(l.input),output:je(l.output),cached:je(l.cachedInput)}),children:je(Be(l))}),e.jsx(Xt,{group:l}),n&&e.jsx("span",{className:"text-right tabular-nums text-ink",children:o(l.billableUsd)})]},l.key)),e.jsxs("div",{className:_(i,"pt-2.5 text-[13px] font-medium text-ink"),children:[e.jsx("span",{children:t("usage.history.total")}),e.jsx("span",{className:"text-right tabular-nums",children:s.total.turns}),e.jsx("span",{className:"text-right tabular-nums",children:je(Be(s.total))}),e.jsx(Xt,{group:s.total,strong:!0}),n&&e.jsx("span",{className:"text-right tabular-nums",children:o(s.total.billableUsd)})]}),a&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:a}),le(s.total.estimatedUsd)&&s.total.estimatedUsd>0&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.history.estimated",{amount:ue(s.total.estimatedUsd)})}),s.total.unpriced>0&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.history.unpriced",{count:String(s.total.unpriced)})})]})}async function pl(s,n){return U(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}`)}function ml({load:s=pl}){const[n,a]=r.useState("month"),[i,o]=r.useState("bot"),[l,d]=r.useState(null),[u,c]=r.useState(null),[x,m]=r.useState(!1),g=Yt(n);return r.useEffect(()=>{let p=!0;return m(!0),c(null),s(Yt(n),i).then(y=>{p&&d(y)}).catch(y=>{p&&c(y instanceof Error?y.message:String(y))}).finally(()=>{p&&m(!1)}),()=>{p=!1}},[n,i,s]),e.jsxs(e.Fragment,{children:[e.jsx(ol,{budget:l?.budget??null}),e.jsxs(L,{title:t("usage.history.title"),subtitle:t("usage.history.subtitle"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("select",{value:n,onChange:p=>a(p.target.value),"aria-label":t("usage.history.period"),className:"rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[12.5px] text-ink focus:outline-none",children:[e.jsx("option",{value:"month",children:t("usage.history.thisMonth")}),e.jsx("option",{value:"lastMonth",children:t("usage.history.lastMonth")}),e.jsx("option",{value:"days30",children:t("usage.history.last30Days")})]}),e.jsx("div",{role:"tablist","aria-label":t("usage.history.groupBy"),className:"flex flex-wrap gap-1",children:cl.map(p=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===p,onClick:()=>o(p),className:_("rounded-lg px-2.5 py-1 text-[12px]",i===p?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink"),children:t(Us[p])},p))}),e.jsxs("a",{href:ul(g),download:!0,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx(gs,{size:13}),t("usage.history.export")]})]}),u&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:u}),x&&!l?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("common.checking")]}):l?e.jsx(xl,{summary:l}):null]})]})}function gl(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 o=Math.floor(i/1440),l=Math.floor(i%1440/60),d=i%60;return o>0?l>0?`${o}d ${l}h`:`${o}d`:l>0?d>0?`${l}h ${d}m`:`${l}h`:`${d}m`}function hl(s,n,a){const i=[];for(const o of s.providers){if(!o.ok)continue;const l=[o.fiveHour.available?o.fiveHour.resetsAt:null,o.weekly.available?o.weekly.resetsAt:null,...o.extra.map(d=>d.resetsAt),...(o.models??[]).flatMap(d=>d.windows.map(u=>u.resetsAt))];for(const d of l){if(!d||a.has(d)||i.includes(d))continue;const u=Date.parse(d);Number.isFinite(u)&&u<=n&&i.push(d)}}return i}function fl(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function Qt(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s}function qe({label:s,window:n,now:a,usedHeadline:i=!1}){const o=n.available?gl(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}),o&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("planUsage.resetsIn",{when:o})})]}),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:_("h-full rounded-full",fl(l)),style:{width:`${Math.min(100,Math.max(0,l))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function bl(){const[s,n]=r.useState(null),[a,i]=r.useState(!0),[o,l]=r.useState(""),[d,u]=r.useState(()=>Date.now()),c=r.useRef(new Set),x=r.useCallback(async(m=!1)=>{i(!0),l("");try{const g=await U(m?"/api/plan-usage?refresh=1":"/api/plan-usage");n(g),u(Date.now())}catch(g){l(g instanceof Error&&g.message?g.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return r.useEffect(()=>{x(!1)},[x]),r.useEffect(()=>{const m=window.setInterval(()=>u(Date.now()),3e4);return()=>window.clearInterval(m)},[]),r.useEffect(()=>{if(!s)return;const m=hl(s,d,c.current);if(m.length!==0){for(const g of m)c.current.add(g);x(!0)}},[s,d,x]),e.jsxs(L,{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:()=>{x(!0)},disabled:a,"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:a?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(xe,{size:14})})}),a&&!s&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("planUsage.loading")}),o&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-danger",children:o}),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(m=>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:m.name}),m.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:m.plan})]}),m.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{label:t("planUsage.fiveHour"),window:m.fiveHour,now:d}),e.jsx(qe,{label:t("planUsage.weekly"),window:m.weekly,now:d}),m.extra.map((g,p)=>e.jsx(qe,{label:Qt(g.label),now:d,window:{available:!0,remainingPercent:g.remainingPercent,usedPercent:g.usedPercent,resetsAt:g.resetsAt}},`${g.label}-${p}`)),(m.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")}),(m.models??[]).map(g=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:g.name}),g.windows.map((p,y)=>e.jsx(qe,{label:Qt(p.label),now:d,usedHeadline:!0,window:{available:!0,remainingPercent:p.remainingPercent,usedPercent:p.usedPercent,resetsAt:p.resetsAt}},`${g.name}-${p.label}-${y}`))]},g.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:m.error})]},m.id))})]})}function yl(){const{state:s}=K(),n=s.bots.filter(l=>!l.hidden).map(l=>{const d=Ln(l),u=s.instances.find(c=>c.instanceId===l.modelSelection.instanceId);return{bot:l,usage:d,billing:u?.snapshot.billing}}).filter(l=>l.usage.turns>0).sort((l,d)=>{const u=c=>le(c)?c:Number.NEGATIVE_INFINITY;return u(d.usage.costUsd)-u(l.usage.costUsd)||Be(d.usage)-Be(l.usage)}),a=_n(n.map(l=>l.usage)),i=new Set(n.map(l=>l.billing)),o=ys(a);return e.jsxs(e.Fragment,{children:[e.jsx(bl,{}),e.jsx(L,{title:t("usage.title"),subtitle:t("usage.subtitle"),children:n.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("usage.empty")}):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-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("usage.colBot")}),e.jsx("span",{className:"text-right",children:t("usage.colTurns")}),e.jsx("span",{className:"text-right",children:vs(a)}),e.jsx("span",{className:"text-right",children:t("usage.colCost")})]}),n.map(({bot:l,usage:d})=>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:"flex min-w-0 items-center gap-2 text-ink",children:[e.jsx(Fn,{bot:l,state:"idle",size:22,animated:!1}),e.jsx("span",{className:"truncate",children:l.name})]}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:d.turns}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:Bt(d),children:je(Be(d))}),e.jsx("span",{className:"text-right tabular-nums text-ink",children:le(d.costUsd)?ue(d.costUsd):e.jsx("span",{className:"text-ink-secondary",children:"—"})})]},l.id)),e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5 pt-2.5 text-[13px] font-medium text-ink",children:[e.jsx("span",{children:t("usage.allBots")}),e.jsx("span",{className:"text-right tabular-nums",children:a.turns}),e.jsx("span",{className:"text-right tabular-nums",title:Bt(a),children:je(Be(a))}),e.jsx("span",{className:"text-right tabular-nums",children:le(a.costUsd)?ue(a.costUsd):"—"})]}),o&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:o}),le(a.costUsd)&&e.jsx("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.costLine",{caption:i.size===1?$n([...i][0]):t("usage.costMixed")})})]})}),e.jsx(ml,{})]})}function vl(s,n,a){const i=n.trim().toLowerCase();return s.filter(o=>a&&!o.tags.includes(a)?!1:i?[o.name,o.description,o.source].some(l=>l.toLowerCase().includes(i)):!0)}function Ls({skill:s}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10.5px] text-ink-secondary",children:[e.jsxs("span",{className:"truncate",title:s.source,children:["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()})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function jl(){const{state:s}=K(),[n,a]=r.useState([]),[i,o]=r.useState(!0),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(null),[g,p]=r.useState(null),[y,k]=r.useState(""),[N,v]=r.useState(""),[j,C]=r.useState(!1),[w,D]=r.useState(""),[I,f]=r.useState(""),b=r.useRef(!1),h=s.bots.filter(R=>!R.hidden),E=r.useMemo(()=>[...new Set(n.flatMap(R=>R.tags))].sort((R,F)=>R.localeCompare(F)),[n]),A=vl(n,u,x),P=async R=>{try{const F=await fetch("/api/skills-library"),q=await F.json();if(!F.ok)throw new Error(q.error??t("skills.library.loadError"));if(R?.())return;a(q.skills??[]),d("")}catch(F){R?.()||d(F instanceof Error?F.message:t("skills.library.loadError"))}finally{R?.()||o(!1)}};r.useEffect(()=>{let R=!1;return o(!0),P(()=>R),()=>{R=!0}},[]);const V=async(R,F,q)=>{if(b.current)return;b.current=!0;const ce=`${F}:${R}`;k(ce),d("");try{const pe=await fetch("/api/skills-library"),be=await pe.json();if(!pe.ok)throw new Error(be.error??t("skills.library.loadError"));const ye=(be.skills??[]).filter(ge=>ge.assignedBots.some(ee=>ee.id===R)).map(ge=>ge.name),X=q?ye.filter(ge=>ge!==F):[...new Set([...ye,F])],se=await fetch(`/api/bots/${encodeURIComponent(R)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:X})}),Se=await se.json();if(!se.ok)throw new Error(Se.error??"Could not update assignments.");await P()}catch(pe){d(pe instanceof Error?pe.message:"Could not update assignments.")}finally{b.current=!1,k("")}},J=async R=>{I&&await V(I,R.name,!1)},$=async(R,F)=>{await V(F,R.name,!0)},W=async(R,F=!1)=>{if(!b.current){if(!R.enabled&&!F)return z(R,!0);b.current=!0,k(R.name),d("");try{const q=await fetch(`/api/skills-library/${encodeURIComponent(R.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!R.enabled})}),ce=await q.json();if(!q.ok)throw new Error(ce.error??"Could not update this skill.");F&&p(null),await P()}catch(q){d(q instanceof Error?q.message:"Could not update this skill.")}finally{b.current=!1,k("")}}},z=async(R,F=!1)=>{d("");try{const q=await fetch(`/api/skills-library/${encodeURIComponent(R.name)}`),ce=await q.json();if(!q.ok)throw new Error(ce.error??"Could not load this skill.");if(!ce.text)throw new Error("The skill contents are unavailable; import it again.");p({skill:R,text:ce.text,review:F})}catch(q){d(q instanceof Error?q.message:"Could not load this skill.")}},G=async()=>{const R=N.trim();if(R){C(!0),d(""),D("");try{const F=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:R})}),q=await F.json();if(!F.ok)throw new Error(q.error??"Could not import that skill.");D(t("skills.library.imported",{name:q.skill?.name??""})),v(""),await P()}catch(F){d(F instanceof Error?F.message:"Could not import that skill.")}finally{C(!1)}}},ne="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(L,{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(js,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:ne,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:u,onChange:R=>c(R.target.value)})]}),E.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>m(null),className:x===null?"rounded-full bg-control px-2.5 py-1 text-[11.5px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[11.5px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),E.map(R=>e.jsx("button",{type:"button",onClick:()=>m(x===R?null:R),className:x===R?"rounded-full bg-control px-2.5 py-1 font-mono text-[11.5px] font-medium text-ink":"rounded-full px-2.5 py-1 font-mono text-[11.5px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:R},R))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):A.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:n.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:A.map(R=>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:()=>{z(R)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:R.name}),children:[e.jsx("div",{className:"truncate font-mono text-[12.5px] text-ink",children:R.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[11.5px] text-ink-secondary",children:R.description})]}),e.jsx(Y,{checked:R.enabled,"aria-label":R.enabled?t("skills.library.disable",{skill:R.name}):t("skills.library.enable",{skill:R.name}),disabled:!!(y||j),onClick:()=>{W(R)}})]}),e.jsx(Ls,{skill:R}),R.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[10.5px] text-warning",children:R.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:R.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):R.assignedBots.map(F=>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:F.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:F.name}),title:t("skills.library.removeAssignment",{bot:F.name}),disabled:!!(y||j),onClick:()=>{$(R,F.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(De,{size:11})})]},F.id))}),h.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs("select",{"aria-label":t("skills.library.assignLabel"),value:I,disabled:!!(y||j),onChange:F=>f(F.target.value),className:"max-w-45 truncate rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[11.5px] text-ink",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),h.map(F=>e.jsx("option",{value:F.id,children:F.name},F.id))]}),e.jsx("button",{type:"button",disabled:!I||!!(y||j),onClick:()=>{J(R)},className:"rounded-lg bg-control px-2.5 py-1 text-[11.5px] text-ink hover:bg-raised-hover disabled:opacity-50",children:t("skills.library.assign")})]})]},R.name))}),l&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l})]})}),e.jsx(L,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:R=>{R.preventDefault(),G()},children:[e.jsx("textarea",{className:`${ne} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:N,onChange:R=>v(R.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:j||!!y||!N.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:j?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),g&&e.jsx(kl,{viewing:g,error:l,working:!!y,onClose:()=>{y||p(null)},onEnable:()=>{W(g.skill,!0)}})]})}function kl({viewing:s,error:n,working:a,onClose:i,onEnable:o}){const l=r.useRef(null);return ri(l,i),e.jsx("div",{ref:l,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?`Review ${s.skill.name} before enabling`: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(Ls,{skill:s.skill}),s.skill.warnings.length>0&&e.jsx("div",{className:"mt-2 text-[11.5px] 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:o,className:"mt-4 self-end rounded-lg bg-accent px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-40",children:"Enable reviewed skill"})]})})}function Nl(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 wl({config:s}){const n=Nl(s);return n?e.jsxs("div",{role:"status",className:_("flex items-start gap-2 rounded-xl border px-3 py-2.5 text-[12.5px] leading-relaxed",n.tone==="danger"?"border-danger/40 bg-danger/10 text-danger":"border-warning/40 bg-warning/10 text-warning"),children:[e.jsx(ke,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function _s(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Sl=()=>U("/api/fleet");function Cl({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-[11.5px] 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 o=i.status==="suspended",l=i.status==="running"||o,d=i.status==="provisioning"?t("workspaces.provisioning"):i.status==="error"?t("workspaces.error"):i.status==="retained"?t("workspaces.retained"):o?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}),!l&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("workspaces.recoveryHint")})]}),e.jsx("span",{className:_("text-right",o||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:d}),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:[le(i.usage.costUsd)?ue(i.usage.costUsd):"—",le(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ue(i.usage.billableUsd)]})]}),e.jsx("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:l&&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,o?"resume":"suspend"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:o?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 El({domain:s,onCreated:n,disabled:a}){const[i,o]=r.useState(""),[l,d]=r.useState(""),[u,c]=r.useState(""),[x,m]=r.useState(""),[g,p]=r.useState(""),[y,k]=r.useState(!1),[N,v]=r.useState(null),j=async()=>{if(!y){k(!0),v(null);try{const w={slug:i.trim().toLowerCase(),admins:[l.trim()],members:u.split(/[,\s]+/).map(I=>I.trim()).filter(Boolean),...x.trim()?{cap:Number(x)}:{},...g.trim()?{anthropicKey:g.trim()}:{}},D=await U("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});o(""),d(""),c(""),m(""),p(""),n(D.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){v(w instanceof Error?w.message:String(w))}finally{k(!1)}}},C="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50";return e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:w=>{w.preventDefault(),j()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:w=>o(w.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||y,"aria-label":t("workspaces.name"),className:C}),e.jsxs("span",{className:"whitespace-nowrap text-[12px] text-ink-secondary",children:[".",s]})]})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.adminEmail"),e.jsx("input",{value:l,onChange:w=>d(w.target.value),type:"email",required:!0,disabled:a||y,"aria-label":t("workspaces.adminEmail"),className:C})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.members"),e.jsx("input",{value:u,onChange:w=>c(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||y,"aria-label":t("workspaces.members"),className:C})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:x,onChange:w=>m(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||y,"aria-label":t("workspaces.cap"),className:C})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary sm:col-span-2",children:[t("workspaces.anthropicKey"),e.jsx("input",{value:g,onChange:w=>p(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||y,"aria-label":t("workspaces.anthropicKey"),className:C})]})]}),e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),N&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:N}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||y,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-60",children:[y?e.jsx(H,{size:13,className:"animate-spin"}):e.jsx(Te,{size:13}),y?t("workspaces.creating"):t("workspaces.create")]})})]})}function Al({slug:s,onDone:n}){const[a,i]=r.useState(""),[o,l]=r.useState(!1),[d,u]=r.useState(null),[c,x]=r.useState(null),m=async g=>{if(!d){u(g),x(null);try{const p=await U(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:g,email:a.trim(),chatOnly:o})});i(""),n(p.log??[])}catch(p){x(p instanceof Error?p.message:String(p))}finally{u(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[12.5px] 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:g=>i(g.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:d!==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:o,onChange:g=>l(g.target.checked),disabled:d!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:d!==null||!a.trim(),onClick:()=>{m("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:d==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:d!==null||!a.trim(),onClick:()=>{m("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:d==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),c&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}function Il({load:s=Sl}){const{state:n}=K(),[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),[m,g]=r.useState([]),[p,y]=r.useState(null),[k,N]=r.useState(null),[v,j]=r.useState(!1),[C,w]=r.useState(null),D=r.useCallback(async()=>{u(!0),l(null);try{i(await s())}catch(h){l(h instanceof Error?h.message:String(h))}finally{u(!1)}},[s]);r.useEffect(()=>{D()},[D]);const I=async(h,E)=>{if(E==="users"){y(A=>A===h?null:h);return}if(E==="delete"){N({slug:h,keepData:!1});return}x(h),l(null);try{const A=await U(`/api/fleet/workspaces/${encodeURIComponent(h)}/${E}`,{method:"POST"});g(A.log??[]),await D()}catch(A){l(A instanceof Error?A.message:String(A))}finally{x(null)}},f=async()=>{if(!k)return;const{slug:h,keepData:E}=k;N(null),x(h),l(null);try{const A=await U(`/api/fleet/workspaces/${encodeURIComponent(h)}`,{method:"DELETE",body:JSON.stringify({keepData:E})});g(A.log??[]),await D()}catch(A){l(A instanceof Error?A.message:String(A))}finally{x(null)}},b=async()=>{x("*"),l(null);try{const h=await U("/api/fleet/upgrade",{method:"POST"});g(h.log??[t("workspaces.upgraded")]),await D()}catch(h){l(h instanceof Error?h.message:String(h))}finally{x(null)}};return _s(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(L,{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:()=>{D()},disabled:d||c!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(xe,{size:12,className:_(d&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>j(h=>!h),disabled:c!==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(Te,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{b()},disabled:c!==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:c==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),v&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(El,{domain:a.domain,disabled:c!==null,onCreated:(h,E)=>{j(!1),g(h),w(`https://${E.slug}.${a.domain}/pair?email=${encodeURIComponent(E.admin)}`),D()}})}),C&&e.jsx("div",{className:"mb-4",children:e.jsx(Ts,{link:C})}),o&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:o}),a?e.jsx(Cl,{fleet:a,onAct:(h,E)=>{I(h,E)},busy:c}):d?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(H,{size:14,className:"animate-spin"}),t("common.checking")]}):null,p&&e.jsx(Al,{slug:p,onDone:h=>{g(h),D()}}),m.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[11.5px] text-ink-secondary",children:m.join(`
|
|
11
|
+
`)})]}),e.jsx(Ge,{open:k!==null,title:t("workspaces.deleteTitle",{slug:k?.slug??""}),body:t(k?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>N(null),onConfirm:()=>{f()}}),k&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:k.keepData,onChange:h=>N({...k,keepData:h.target.checked})}),t("workspaces.keepData")]})]}):null}function Pl({skin:s}){return e.jsxs("div",{"data-skin":s,"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 Rl(){const[s,n]=r.useState(()=>document.documentElement.dataset.skin||Kn());return e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:Hn.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Vn(a.id),n(a.id)},"aria-pressed":i,className:_("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(Pl,{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:a.tagline})]}),i&&e.jsx(oe,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},a.id)})})}function Bl(){const{state:s,dispatch:n}=K(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,o]=r.useState(String(a)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1);r.useEffect(()=>{l||o(String(a))},[a,l]);const p=async()=>{if(!l||g.current)return;const y=Jn(i);if(!y.ok){c(t("settings.roomTurns.range"));return}g.current=!0,m(!0);try{const k=await U("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:y.minutes}})});n({type:"configStatus",config:k}),o(String(k.rooms.turnTimeoutMinutes)),d(!1),c("")}catch(k){c(k instanceof Error?k.message:t("settings.roomTurns.error"))}finally{g.current=!1,m(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${u?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:qn,max:Wn,step:1,inputMode:"numeric",value:i,disabled:x,"aria-invalid":!!u,"aria-describedby":u?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:y=>{o(y.target.value),d(!0),c("")},onBlur:()=>{p()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),u?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:u}):null]})}const Dl=10,Fs=1,$s=60,Zt="Enter a whole number from 1 to 60.";function Tl(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:Zt};const a=Number(n);return a<Fs||a>$s?{ok:!1,error:Zt}:{ok:!0,minutes:a}}function es(s){return s?.mcp?.callTimeoutMinutes??Dl}function zl(){const{state:s,dispatch:n}=K(),a=es(s.config),[i,o]=r.useState(String(a)),[l,d]=r.useState(!1),[u,c]=r.useState(""),[x,m]=r.useState(!1),g=r.useRef(!1);r.useEffect(()=>{l||o(String(a))},[a,l]);const p=async()=>{if(!l||g.current)return;const y=Tl(i);if(!y.ok){c(t("settings.mcpCalls.range"));return}g.current=!0,m(!0);try{const k=await U("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:y.minutes}})});n({type:"configStatus",config:k}),o(String(es(k))),d(!1),c("")}catch(k){c(k instanceof Error?k.message:t("settings.mcpCalls.error"))}finally{g.current=!1,m(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${u?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:Fs,max:$s,step:1,inputMode:"numeric",value:i,disabled:x,"aria-invalid":!!u,"aria-describedby":u?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:y=>{o(y.target.value),d(!0),c("")},onBlur:()=>{p()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),u?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:u}):null]})}function Ml(s,n){let a={value:s,status:"idle"},i=!1,o,l;const d=new Set,u=(x,m)=>{a={value:x,status:m};for(const g of d)g()},c=()=>(clearTimeout(l),o||(i?(u(a.value,"saving"),o=(async()=>{try{for(;i;){const x=a.value;await n(x),i=a.value!==x}u(a.value,"saved")}catch{u(a.value,"error")}})().finally(()=>{o=void 0}),o):Promise.resolve()));return{getSnapshot:()=>a,subscribe(x){return d.add(x),()=>{d.delete(x)}},confirm(x){!i&&!o&&x!==a.value&&u(x,"idle")},edit(x){i=!0,u(x,"idle"),clearTimeout(l),l=setTimeout(()=>{c()},600)},flush:c}}const ts=new WeakMap;function Ol(){const{state:s,dispatch:n}=K(),a=s.config?.profile?.aboutMe??"";let i=ts.get(n);i||(i=Ml(a,async u=>{const c=await U("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:u}}),timeoutMs:1e4});n({type:"profileSaved",profile:{aboutMe:c.profile?.aboutMe??u}})}),ts.set(n,i));const{value:o,status:l}=r.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{flush:d}=i;return r.useEffect(()=>{i.confirm(a)},[i,a]),r.useEffect(()=>()=>{d()},[d]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(Gn,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:24e3,onChange:u=>i.edit(u.target.value),onBlur:()=>{d()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Ul,{onChanged:u=>{i.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[l==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),l==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),l==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{d()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Ul({onChanged:s}){const[n,a]=r.useState([]),[i,o]=r.useState(null),[l,d]=r.useState(!1);r.useEffect(()=>{let c=!1;return U("/api/profile/learned").then(x=>{c||a(x.learned)}).catch(()=>{}),()=>{c=!0}},[]);const u=async c=>{o(c),d(!1);try{const x=await U(`/api/profile/learned/${encodeURIComponent(c)}/remove`,{method:"POST"});a(x.learned),s(x.aboutMe)}catch{d(!0)}finally{o(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(c=>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:[c.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:c.botName})})]}),e.jsx("button",{type:"button",disabled:i===c.id,onClick:()=>{u(c.id)},className:"rounded-md px-2 py-1 text-[12.5px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},c.id))}),l&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}function Ll(){const{state:s,dispatch:n}=K(),a=s.config?.threads?.maxConcurrentPerBot??3,[i,o]=r.useState(null),[l,d]=r.useState(""),u=r.useRef(!1),c=async x=>{if(!(u.current||x===a)){u.current=!0,o(x),d("");try{const m=await U("/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,o(null)}}};return e.jsxs(L,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx("select",{id:"thread-concurrency",value:i??a,disabled:i!==null,"aria-describedby":"thread-concurrency-help",onChange:x=>{c(Number(x.target.value))},className:"mt-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:Array.from({length:10},(x,m)=>m+1).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threads.help")}),i!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),l&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l})]})}function _l(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(null),[o,l]=r.useState(!1),[d,u]=r.useState(""),c=r.useRef(!1),x=a??s.config?.automaticRecovery??{enabled:!1},m=s.instances.filter(v=>v.snapshot.state==="available"&&!v.policy),g=m.find(v=>v.instanceId===x.backup?.instanceId),p=g?.models.options.filter(v=>g.snapshot.authenticated!==!1||v.custom)??[],y=p.some(v=>v.id===x.backup?.model),k=v=>{i(v),u("")},N=async()=>{if(!(!a||c.current||x.enabled&&!y)){c.current=!0,l(!0),u("");try{const v=await U("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:v}),i(null)}catch(v){u(v instanceof Error?v.message:t("settings.recovery.error"))}finally{c.current=!1,l(!1)}}};return e.jsxs(L,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(Y,{id:"automatic-recovery-enabled",checked:x.enabled,disabled:o||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope",onClick:()=>k({...x,enabled:!x.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scope")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs("select",{id:"automatic-recovery-engine",value:x.backup?.instanceId??"",disabled:o||!x.enabled,onChange:v=>k({enabled:x.enabled,...v.target.value?{backup:{instanceId:v.target.value,model:""}}:{}}),className:"mt-2 w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),x.backup&&!g&&e.jsx("option",{value:x.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:x.backup.instanceId})}),m.map(v=>e.jsx("option",{value:v.instanceId,disabled:!v.models.options.some(j=>v.snapshot.authenticated!==!1||j.custom),children:v.displayName},v.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs("select",{id:"automatic-recovery-model",value:x.backup?.model??"",disabled:o||!x.enabled||!g,onChange:v=>k({enabled:x.enabled,backup:{instanceId:g.instanceId,model:v.target.value}}),className:"mt-2 w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),x.backup?.model&&!y&&e.jsx("option",{value:x.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:x.backup.model})}),p.map(v=>e.jsx("option",{value:v.id,children:v.label},v.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),x.enabled&&!y&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||o||x.enabled&&!y,onClick:()=>{N()},className:"mt-3 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:o?t("settings.threads.saving"):t("common.save")}),o&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),d&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:d})]})}const Ks=1,Hs=3650,Fl=30,Qe=1024*1024,pt=256*1024,Vs=4*1024*1024*1024,$l=50;function ss(s){const n=Number(s);return Number.isInteger(n)&&n>=Ks&&n<=Hs?n:null}function ns(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Qe);return a>=pt&&a<=Vs&&a%pt===0?a:null}function as(s){const n=s/Qe;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function Kl(){const{state:s,dispatch:n}=K(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[o,l]=r.useState(null),[d,u]=r.useState(null),[c,x]=r.useState(null),[m,g]=r.useState(""),[p,y]=r.useState(null),k=r.useRef(!1),N=o??String(a===null?Fl:a),v=d??(i===null?String($l):as(i));r.useEffect(()=>{o!==null&&a!==null&&String(a)===o&&l(null)},[a,o]),r.useEffect(()=>{d!==null&&i!==null&&as(i)===d&&u(null)},[i,d]);const j=async(f,b)=>{if(!k.current){k.current=!0,x(b),g(""),y(null);try{const h=await U("/api/config",{method:"PATCH",body:JSON.stringify({threads:f})});n({type:"configStatus",config:h})}catch(h){g(h instanceof Error?h.message:t("settings.threadCleanup.error"))}finally{k.current=!1,x(null)}}},C=f=>{if(!f){l(null),g(""),y(null),j({eventLogRetentionDays:null},"retention");return}const b=ss(N);if(b===null){g(t("settings.threadCleanup.invalidRetention")),y("retention");return}j({eventLogRetentionDays:b},"retention")},w=f=>{if(!f){u(null),g(""),y(null),j({eventLogMaxBytes:null},"cap");return}const b=ns(v);if(b===null){g(t("settings.threadCleanup.invalidCap")),y("cap");return}j({eventLogMaxBytes:b},"cap")},D=()=>{if(a===null)return;const f=ss(N);if(f===null){g(t("settings.threadCleanup.invalidRetention")),y("retention");return}if(f===a){l(null),g("");return}j({eventLogRetentionDays:f},"retention")},I=()=>{if(i===null)return;const f=ns(v);if(f===null){g(t("settings.threadCleanup.invalidCap")),y("cap");return}if(f===i){u(null),g("");return}j({eventLogMaxBytes:f},"cap")};return e.jsxs(L,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:c!==null,onChange:f=>C(f.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${p==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:Ks,max:Hs,step:1,inputMode:"numeric",value:N,disabled:a===null||c!==null,"aria-invalid":p==="retention","aria-describedby":"thread-log-retention-help",onChange:f=>{l(f.target.value),g(""),y(null)},onBlur:D,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:c!==null,onChange:f=>w(f.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${p==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:pt/Qe,max:Vs/Qe,step:.25,inputMode:"decimal",value:v,disabled:i===null||c!==null,"aria-invalid":p==="cap","aria-describedby":"thread-log-cap-help",onChange:f=>{u(f.target.value),g(""),y(null)},onBlur:I,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),c!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}const dt="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Pe=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(ze(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},is=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(ze(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Hl(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=r.useState(null),o=r.useRef(0),l=r.useRef(0);return r.useEffect(()=>{const d=++o.current,u=l.current;i(null);const c=m=>{o.current===d&&(l.current++,i(m))},x=s?.onState(c);return s?.state().then(m=>{l.current===u&&c(m)}).catch(()=>{}),()=>{o.current++,x?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Vl,{bridge:n}):e.jsx(Wl,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Vl({bridge:s}){const[n,a]=r.useState(null),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=r.useRef(0);if(r.useEffect(()=>{const x=++u.current,m=s.onState(g=>{x===u.current&&a(g.schedule??null)});return s.state().then(g=>{x===u.current&&a(g.schedule??null)}).catch(()=>{}),()=>{u.current++,m()}},[s]),!s.configureSchedule||!n?.enabled)return null;const c=async()=>{if(i||!s.configureSchedule)return;const x=u.current;o(!0),d("");try{const m=await s.configureSchedule({enabled:!1});x===u.current&&a(m.schedule??null)}catch{x===u.current&&d(t("companyBackup.scheduleFailed"))}finally{x===u.current&&o(!1)}};return e.jsx(L,{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(Y,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{c()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),l&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:l})]})})}function Wl({connection:s,bridge:n}){const[a,i]=r.useState(null),[o,l]=r.useState(null),[d,u]=r.useState(!1),[c,x]=r.useState(null),[m,g]=r.useState(""),[p,y]=r.useState(null),[k,N]=r.useState(""),[v,j]=r.useState(""),[C,w]=r.useState(null),[D,I]=r.useState(!1),f=r.useRef(0),b=r.useRef(0),h=r.useRef(0),E=r.useRef(void 0),A=r.useRef(!1),P=r.useRef(null),V=async()=>{const T=f.current,Q=++h.current,ie=b.current;u(!0);try{await Promise.all([n.state().then(ae=>{T===f.current&&Q===h.current&&b.current===ie&&i(ae)}),n.list().then(ae=>{T===f.current&&Q===h.current&&l(ae)})]),T===f.current&&Q===h.current&&g("")}catch{T===f.current&&Q===h.current&&g(t("companyBackup.loadFailed"))}finally{T===f.current&&Q===h.current&&u(!1)}};r.useEffect(()=>{const T=++f.current,Q=ae=>{if(T!==f.current)return;b.current++,i(ae);const Me=ae.lastBackupAt??ae.schedule?.lastBackupAt;!ae.busy&&!ae.pendingRestore&&Me&&Me!==E.current&&(E.current=Me,V())},ie=n.onState(Q);return V(),()=>{f.current++,h.current++,ie()}},[n]),r.useEffect(()=>{const T=P.current;if(!(!p||!T))return T.showModal(),()=>{T.close()}},[p]);const J=D||a?.pendingRestore===!0,$=c!==null||!a||a.busy||J,W=()=>{y(null),N(""),j(""),w(null)},z=T=>{$||A.current||(g(""),N(""),j(""),w(null),y(T))},G=async(T,Q)=>{if($||A.current)return;A.current=!0,x(T),g("");const ie=f.current;try{await Q(()=>ie===f.current)}catch{ie===f.current&&g(t(T==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{A.current=!1,ie===f.current&&x(null)}},ne=()=>{p?.kind==="create"&&G("create",async T=>{await n.create({clientState:Xn()}),T()&&(W(),await V())})},R=async T=>{if(!n.configureSchedule||A.current||!a||T&&($||p?.kind!=="schedule"||v!=="BACK UP THIS WORKSPACE DAILY"))return;A.current=!0,x("schedule"),g("");const Q=f.current,ie=b.current;j("");try{const ae=await n.configureSchedule(T?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});Q===f.current&&(b.current===ie&&i(ae),W())}catch{Q===f.current&&g(t("companyBackup.scheduleFailed"))}finally{A.current=!1,Q===f.current&&x(null)}},F=()=>{p?.kind!=="restore"||p.entry.passwordRequired!==!1&&(k.length<12||k.length>1024)||G("prepare",async T=>{const Q=k;N(""),w(null),j("");const ie=await n.prepareRestore({id:p.entry.id,...p.entry.passwordRequired!==!1?{password:Q}:{}});T()&&w(ie)})},q=()=>{p?.kind!=="restore"||!C||v!=="REPLACE"||G("restore",async T=>{const Q=localStorage.getItem(Tt);if(Q&&Q!==C.id)throw new Error("An earlier restore needs recovery first.");localStorage.setItem(Tt,C.id),await n.restore({id:C.id,confirmation:"REPLACE"}),T()&&(I(!0),W())})},ce=()=>{p?.kind!=="delete"||v!=="DELETE"||G("delete",async T=>{await n.delete({id:p.entry.id,confirmation:"DELETE"}),T()&&(W(),await V())})},pe=async()=>{const T=f.current;try{await n.cancel()}catch{T===f.current&&g(t("companyBackup.actionFailed"))}},be=o?.backups.filter(T=>T.status==="ready")??[],ye=o?o.backups.length-be.length:0,X=a?.progress,se=m||a?.message,Se=(a?.busy||c)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:c==="restore"?t("backup.restoring"):X?t(`companyBackup.phase.${X.phase}`):t("companyBackup.working")}),X&&X.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:X.totalBytes,value:Math.min(X.bytesTransferred,X.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Pe(X.bytesTransferred),total:Pe(X.totalBytes)})})]}),a?.busy&&c!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{pe()},children:t("companyBackup.cancelTransfer")})]}),ge=p?.kind==="restore"?t("companyBackup.restore"):p?.kind==="delete"?t("companyBackup.delete"):p?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ee=a?.schedule,Le=T=>new Intl.DateTimeFormat(ze(),{dateStyle:"medium",timeStyle:"short"}).format(new Date(T));return e.jsxs(L,{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&&ee&&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(Y,{"aria-label":t("companyBackup.daily"),checked:ee.enabled,disabled:c!==null||!a||!ee.enabled&&$,onClick:()=>ee.enabled?void R(!1):z({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ee.status}`)}),ee.enabled&&ee.nextBackupAt&&Number.isFinite(ee.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:Le(ee.nextBackupAt)})}),ee.lastBackupAt&&Number.isFinite(ee.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:Le(ee.lastBackupAt)})}),ee.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ee.message})]}),J?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(Dt,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:$,onClick:()=>z({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:c!==null||a?.busy||J||d,onClick:()=>{V()},children:t("companyBackup.refresh")})]}),d&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),o&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:Pe(o.usedBytes),total:Pe(o.limits.ownerQuotaBytes),count:o.limits.retainedSnapshots})}),ye>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:ye})}),o&&be.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:be.map(T=>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:is(T)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Pe(T.sizeBytes),T.appVersion?` · ${T.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:T.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:$,onClick:()=>z({kind:"restore",entry:T}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$,onClick:()=>z({kind:"delete",entry:T}),children:t("companyBackup.delete")})]})]},T.id))})]}),!p&&Se,!p&&se&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:se})]}),p&&e.jsx("dialog",{ref:P,"aria-labelledby":"company-backup-dialog-title",onKeyDown:T=>{(T.key==="Escape"||T.key==="Tab")&&T.stopPropagation()},onCancel:T=>{T.preventDefault(),c||W()},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:ge}),J&&e.jsx(Dt,{}),(p.kind==="restore"||p.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[is(p.entry)," · ",Pe(p.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:p.entry.id})]}),(p.kind==="create"||p.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:T=>{T.preventDefault(),p.kind==="schedule"?R(!0):ne()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(p.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),p.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")}),p.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:$,checked:v==="BACK UP THIS WORKSPACE DAILY",onChange:T=>j(T.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:$||p.kind==="schedule"&&v!=="BACK UP THIS WORKSPACE DAILY",children:t(p.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),p.kind==="restore"&&(C?e.jsxs(e.Fragment,{children:[e.jsx(Yn,{summary:C.summary}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.replaceWarning")}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.trustWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("backup.confirmReplace"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:7,disabled:$,value:v,onChange:T=>j(T.target.value),className:dt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$||v!=="REPLACE",onClick:q,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:T=>{T.preventDefault(),F()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),p.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:$,value:k,onChange:T=>N(T.target.value),className:dt})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:$||p.entry.passwordRequired!==!1&&(k.length<12||k.length>1024),children:t("backup.validate")})]})),p.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:$,value:v,onChange:T=>j(T.target.value),className:dt})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:$||v!=="DELETE",onClick:ce,children:t("companyBackup.delete")})]}),Se,se&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:se}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:c!==null,onClick:W,children:t("companyBackup.cancel")})]})})]})}const rs=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Je=[{id:"general",group:"you",labelKey:"settings.section.general",icon:xt,keywords:["profile","name","email","about me","about","suggestions","suggested","memory","analytics","updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule"]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ss,keywords:["skin","theme","appearance","tools","tool calls","threads","show threads","hide threads","sidebar","density","compact","comfortable","avatars","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Zn,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:yi,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:ea,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","vps","router","openrouter","base url","openai","anthropic","groq","opencode","provider"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:ta,keywords:["decision","jev","typesafe","routing","auto","rooms","who answers"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:sa,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:ot,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:Ns,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:xt,keywords:["cloud","account","personal","sign in","pro","subscription","billing"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:ot,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:oi,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:na,keywords:["export","import","restore","full backup","password","recovery"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:aa,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:gi,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:ot,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:ia,keywords:["early","preview","learn","skill","authoring"]}],ql=[{id:"general",labelKey:"settings.section.general",icon:xt,sections:["general"]},{id:"appearance",labelKey:"settings.section.appearance",icon:Ss,sections:["appearance"]},{id:"ai",labelKey:"settings.group.ai",icon:oa,sections:["engines","connections","decisionModel"]},{id:"computers",labelKey:"settings.group.computers",icon:Ns,sections:["companion","desktopWorkspaces","computer"]},{id:"account",labelKey:"settings.group.account",icon:di,sections:["cloudAccount","organization","people","activity"]}],Jl=["usage","backups","experimental","workspaces","skills"];function Gl(s,n){const a=new Set(s.map(l=>l.id)),i=ql.map(l=>({...l,sections:l.sections.filter(d=>a.has(d))})).filter(l=>l.sections.length>0),o=Jl.includes(n)?s.find(l=>l.id===n):void 0;return o&&i.push({id:o.id,labelKey:o.labelKey,icon:o.icon,sections:[o.id]}),i}function Yl(s,n,a){if(a<=0){s.scrollTop=0;return}s.querySelector(`[data-settings-block="${n}"]`)?.scrollIntoView?.({block:"start"})}function Xl(s,n){return!n||t(s.labelKey).toLowerCase().includes(n)?!0:s.sections.some(a=>{const i=Je.find(o=>o.id===a);return i?Ws(i,n):!1})}function Ws(s,n){return n?[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n)):!0}function Ql(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(s.config?.profile?.name??""),[o,l]=r.useState(s.config?.profile?.email??"");r.useEffect(()=>{i(s.config?.profile?.name??""),l(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const d=()=>{fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:o.trim().toLowerCase()}})}).then(c=>{if(!c.ok)throw new Error("Profile save failed");return c.json()}).then(c=>{c.profile&&n({type:"profileSaved",profile:{name:c.profile.name,email:c.profile.email}})}).catch(()=>{})},u="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:c=>i(c.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:u}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:o,onChange:c=>l(c.target.value),onBlur:d,placeholder:"you@example.com",className:u}),e.jsx(Ol,{})]})}function Zl(){const s=Ha(),n=window.ogb?.updater;if(!s||!n)return null;const a=s.status==="checking"?t("settings.updates.checking"):s.status==="downloading"?s.percent==null?t("settings.updates.startingDownload"):t("settings.updates.downloading",{percent:Math.round(s.percent)}):s.status==="preparing"?t("settings.updates.preparing"):s.status==="downloaded"?s.installMode==="handoff"?t("settings.updates.readyInstall",{app:Ye().name,version:s.version??""}):t("settings.updates.ready",{app:Ye().name,version:s.version??""}):s.status==="installing"?s.message||(s.installMode==="handoff"?t("settings.updates.openingTerminal"):t("settings.updates.restarting")):s.status==="handed-off"?t("settings.updates.handedOff"):s.status==="error"?t("settings.updates.failed",{message:s.message??t("settings.updates.unknownError")}):t("settings.updates.latest");return e.jsx(te,{title:t("settings.updates.title"),subtitle:a,children:e.jsx("button",{onClick:()=>{if(s.status==="downloaded")return void n.install();n.check()},disabled:s.status==="checking"||s.status==="downloading"||s.status==="preparing"||s.status==="installing"||s.retryable===!1,className:"ui-button",children:s.retryable===!1?t("settings.updates.quitReopen"):s.status==="downloaded"?s.installMode==="handoff"?t("settings.updates.install"):t("settings.updates.restart"):s.status==="preparing"?t("settings.updates.preparingShort"):s.status==="installing"?s.installMode==="handoff"?t("settings.updates.opening"):t("settings.updates.restartingShort"):t("settings.updates.check")})})}function eo(){const{state:s,dispatch:n}=K(),a=s.config?.newBots?.effort??"",[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async c=>{if(!i){o(!0),d("");try{const x=await U("/api/config",{method:"PATCH",body:JSON.stringify({newBots:{effort:Va(c)?c:null}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.newBotEffort.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.newBotEffort.title"),subtitle:t("settings.newBotEffort.subtitle"),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsxs("select",{value:a,disabled:i,"aria-label":t("settings.newBotEffort.aria"),onChange:c=>{u(c.target.value)},className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus disabled:cursor-wait disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.newBotEffort.default")}),La.map(c=>e.jsx("option",{value:c,children:_a(c)},c))]})})}function to(){const[s,n]=r.useState(Fa);return e.jsx(te,{title:t("settings.analytics.title"),subtitle:t("settings.analytics.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.analytics.aria"),onClick:()=>{const a=!s;$a(a),n(a)}})})}function so(){const{state:s,dispatch:n}=K(),[a,i]=r.useState(!1),[o,l]=r.useState(!1);return e.jsxs("div",{children:[e.jsx("button",{disabled:a,onClick:()=>{i(!0),l(!1),U("/api/config",{method:"PUT",body:JSON.stringify({onboarding:{...s.config?.onboarding?.completedAt?{}:qa().onboarding,hintsSeen:Wa(s.config?.onboarding)}}),signal:AbortSignal.timeout(1e4)}).then(d=>{n({type:"configStatus",config:d}),n({type:"toggleTour",open:!0})}).catch(()=>l(!0)).finally(()=>i(!1))},className:"ui-button",children:t("settings.welcome.appTour")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[13px] text-danger",children:t("onboarding.tour.error")})]})}function no(){const{dispatch:s}=K();return e.jsx(te,{title:t("settings.welcome.title"),subtitle:t("settings.welcome.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(so,{}),e.jsx("button",{onClick:()=>s({type:"toggleWelcome",open:!0}),className:"ui-button",children:t("settings.welcome.replay")})]})})}function ao(){const{state:s}=K(),n=za(Ma(),s.config?.language);return e.jsx(te,{title:t("settings.language.title"),subtitle:t("settings.language.subtitle"),children:e.jsxs("select",{value:n,"aria-label":t("settings.language.aria"),onChange:a=>Ua(a.target.value),className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus disabled:cursor-wait disabled:opacity-50",children:[e.jsx("option",{value:"",children:t("settings.language.system")}),Oa.map(({code:a,label:i})=>e.jsx("option",{value:a,children:i},a))]})})}function io(){const s=Pa();return e.jsx(te,{title:t("settings.notificationSounds.title"),subtitle:t("settings.notificationSounds.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Ra(!s)})})}function ro(){const[s,n]=r.useState(fa);return e.jsx(te,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx("select",{value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;ya(i),n(i)},className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus",children:ba.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function ls(){const s=ks();return e.jsx(te,{title:t("settings.advancedMode.title"),subtitle:t("settings.advancedMode.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.advancedMode.title"),onClick:()=>ha(!s)})})}function lo(){const s=wa();return e.jsx(te,{title:t("settings.threadDisplay.title"),subtitle:t("settings.threadDisplay.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.threadDisplay.show"),onClick:()=>Sa(!s)})})}function oo(){const s=Ca();return e.jsx(te,{title:t("settings.pinnedCircles.title"),subtitle:t("settings.pinnedCircles.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.pinnedCircles.title"),onClick:()=>Ea(!s)})})}const co={comfortable:"sidebar.density.comfortable",compact:"sidebar.density.compact",icons:"sidebar.density.iconsOnly"};function uo(){const s=va();return e.jsx(te,{title:t("sidebar.density.title"),subtitle:t("settings.sidebarDensity.subtitle"),children:e.jsx("select",{value:s,"aria-label":t("sidebar.density.chooseAria"),onChange:n=>ka(Na(n.target.value)),className:"min-h-8 w-full max-w-[240px] rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink focus:border-focus",children:ja.map(n=>e.jsx("option",{value:n,children:t(co[n])},n))})})}function xo(){const s=Da();return e.jsx(te,{title:t("settings.runCard.title"),subtitle:t("settings.runCard.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.runCard.show"),onClick:()=>Ta(!s)})})}function po(){const s=Aa();return e.jsx(te,{title:t("settings.universalPins.title"),subtitle:t("settings.universalPins.subtitle"),children:e.jsx(Y,{checked:s,"aria-label":t("settings.universalPins.title"),onClick:()=>Ia(!s)})})}function mo(){const{state:s,dispatch:n}=K(),a=Ka(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async()=>{if(!i){o(!0),d("");try{const c=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{routinesInConversation:!a}})});n({type:"configStatus",config:c})}catch(c){d(c instanceof Error?c.message:t("settings.routinesInConversation.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.routinesInConversation.title"),subtitle:t("settings.routinesInConversation.subtitle"),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.routinesInConversation.aria"),disabled:i,onClick:()=>{u()},className:"disabled:cursor-wait disabled:opacity-50"})})}function go(){const{state:s,dispatch:n}=K(),a=Ba(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async()=>{if(!i){o(!0),d("");try{const c=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{showToolCalls:!a}})});n({type:"configStatus",config:c})}catch(c){d(c instanceof Error?c.message:t("settings.toolCalls.error"))}finally{o(!1)}}};return e.jsx(te,{title:t("settings.toolCalls.title"),subtitle:e.jsxs(e.Fragment,{children:[t("settings.toolCalls.subtitle")," ",t("settings.toolCalls.detail")]}),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.toolCalls.aria"),disabled:i,onClick:()=>{u()},className:"disabled:cursor-wait disabled:opacity-50"})})}function ho(){const{state:s,dispatch:n}=K(),a=ga(s.config),[i,o]=r.useState(!1),[l,d]=r.useState(""),u=async c=>{if(!i){o(!0),d("");try{const x=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{skillAuthoring:c}})});n({type:"configStatus",config:x})}catch(x){d(x instanceof Error?x.message:t("settings.experimental.error"))}finally{o(!1)}}};return e.jsxs(L,{title:t("settings.experimental.title"),subtitle:t("settings.experimental.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:t("settings.experimental.skillAuthoring")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.experimental.skillAuthoringDetail")})]}),e.jsx(Y,{checked:a,"aria-label":t("settings.experimental.skillAuthoringAria"),disabled:i,onClick:()=>{u(!a)},className:"disabled:cursor-wait disabled:opacity-50"})]}),l?e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:l}):null]})}function os(){const{state:s,dispatch:n}=K(),a=ws(s.config),i=pa(s.config),o=s.config?.browserEngine?.installable===!0,l=window.ogb?.platform==="win32"&&!i&&!o,[d,u]=r.useState(!1),[c,x]=r.useState(""),m=async g=>{if(!d){u(!0),x("");try{const p=await U("/api/config",{method:"PATCH",body:JSON.stringify({features:{browser:g}})});n({type:"configStatus",config:p})}catch(p){x(p instanceof Error?p.message:t("settings.experimental.error"))}finally{u(!1)}}};return e.jsx("div",{"data-built-in-browser":!0,className:"rounded-xl bg-card px-4",children:e.jsx(te,{title:t("settings.experimental.browserAria"),subtitle:i?a?t("settings.experimental.browserOn"):t("settings.experimental.browserOff"):l?t("settings.experimental.browserWindows"):ma(s.config),message:c?e.jsx("p",{role:"alert",className:"text-danger",children:c}):null,children:e.jsx(Y,{checked:a,"aria-label":t("settings.experimental.browserAria"),disabled:d||!a&&!i&&!o,onClick:()=>{m(!a)},className:"disabled:cursor-wait disabled:opacity-50"})})})}function cs(){const{state:s}=K(),n=s.config?.browserProfiles??[];return!ws(s.config)&&n.length===0?null:e.jsx(L,{title:t("settings.profiles.title"),subtitle:t("settings.profiles.sharedSubtitle"),children:e.jsx(ti,{})})}function fo(){const[s,n]=r.useState(!1),[a,i]=r.useState(null),o=async()=>{if(!(!window.ogb?.exportDiagnostics||s)){n(!0),i(null);try{const l=await window.ogb.exportDiagnostics();l&&i({kind:"success",message:t("settings.diagnostics.saved",{path:l})})}catch(l){i({kind:"error",message:l instanceof Error?l.message:String(l)})}finally{n(!1)}}};return e.jsx(te,{title:t("settings.diagnostics.title"),subtitle:t("settings.diagnostics.subtitle"),message:a?e.jsx("p",{role:a.kind==="error"?"alert":"status",className:_("break-all",a.kind==="error"?"text-danger":"text-success"),children:a.message}):null,children:e.jsx("button",{onClick:()=>{o()},disabled:s,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:s?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})})}function Ao(){const{state:s,dispatch:n}=K(),a=ks(),i=window.ogb?.remoteClient?.active===!0,o=i&&!["appearance","desktopWorkspaces"].includes(s.appSettingsSection)||s.appSettingsSection==="remote"?"companion":s.appSettingsSection,l=r.useRef(null),d=r.useRef(null),[u,c]=r.useState("");r.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>c("")),[]),r.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>c("")),[]);const x=u.trim().toLowerCase(),m=Qn(),p=Je.filter(b=>!i||b.id==="companion"||b.id==="appearance"||b.id==="desktopWorkspaces").filter(b=>b.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(b=>b.id!=="organization"||!!window.ogb?.organization).filter(b=>b.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&s.config?.cloudHome===!0)).filter(b=>b.id!=="workspaces"||_s(s.config)).filter(b=>b.id!=="people"||!window.ogb&&s.config?.cloudHome!==!0).filter(b=>b.id!=="activity"||!window.ogb&&m===!0).filter(b=>b.id!=="skills"||zt(s.config)),y=p.filter(b=>Ws(b,x)),k=a?[]:Gl(p,o),N=k.filter(b=>Xl(b,x)),v=k.find(b=>b.sections.includes(o)),j=a?Je.find(b=>b.id===o)?.labelKey:v?.labelKey,C=a?y.some(b=>b.id===o)?void 0:y[0]?.id:v&&N.includes(v)?void 0:N[0]&&(N[0].sections.find(b=>y.some(h=>h.id===b))??N[0].sections[0]);r.useEffect(()=>{C&&n({type:"toggleAppSettings",open:!0,section:C})},[n,C]);const w=v?.sections.indexOf(o)??0;r.useEffect(()=>{d.current&&Yl(d.current,o,a?0:w)},[a,o,w]),r.useEffect(()=>{const b=document.activeElement instanceof HTMLElement?document.activeElement:null,h=l.current,E=h?.querySelector("[data-settings-search]");E?.checkVisibility()?E.focus():h?.focus();const A=P=>{if(P.defaultPrevented||h&&[...h.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(z=>z.getClientRects().length))return;if(P.key==="Escape"){P.preventDefault(),n({type:"toggleAppSettings",open:!1});return}if(P.key!=="Tab"||!h)return;const V=Array.from(h.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(z=>z.checkVisibility());if(V.length===0){P.preventDefault(),h.focus();return}const J=V[0],$=V[V.length-1],W=document.activeElement;P.shiftKey&&(W===J||!h.contains(W))?(P.preventDefault(),$.focus()):!P.shiftKey&&W===$&&(P.preventDefault(),J.focus())};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A),b?.focus()}},[n]);const D=b=>n({type:"toggleAppSettings",open:!0,section:b}),I=b=>{switch(b){case"desktopWorkspaces":return e.jsx(Ur,{});case"organization":return window.ogb?.organization&&!i?e.jsx(Vr,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&s.config?.cloudHome===!0)&&!i?e.jsx(al,{linkRequest:s.appSettingsCloudLink,cloudHome:s.config?.cloudHome===!0,onConnectPhone:()=>n(xa())}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-2xl border border-accent-border/40 bg-raised-hover/40 px-1",children:e.jsx(ls,{})}),e.jsx(ua,{}),e.jsx(L,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:e.jsx(Ql,{})}),e.jsxs("div",{children:[e.jsx(ao,{}),e.jsx(eo,{}),e.jsx(to,{}),e.jsx(li,{})]}),e.jsx(L,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(Bl,{})}),e.jsx(L,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(zl,{})}),e.jsx(Ll,{}),!i&&e.jsx(mo,{}),e.jsx(_l,{}),e.jsx(Kl,{}),e.jsxs("div",{children:[!i&&e.jsx(no,{}),e.jsx(Zl,{}),e.jsx(fo,{})]})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(Rl,{})}),e.jsxs("div",{children:[i&&e.jsx(ls,{}),e.jsx(ro,{}),e.jsx(uo,{}),a&&e.jsx(lo,{}),e.jsx(oo,{}),e.jsx(po,{}),e.jsx(io,{}),!i&&e.jsx(go,{}),e.jsx(xo,{})]})]});case"experimental":return e.jsx(ho,{});case"connections":return e.jsx(L,{title:t("settings.connections.title"),subtitle:t("settings.connections.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[s.config?.composio.mode==="managed"?e.jsx("div",{className:"rounded-lg border border-success/25 bg-success/10 px-3 py-2 text-[13px] text-success",children:t("settings.connections.ready")}):null,e.jsx("div",{className:"text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:t("keys.providers.title")}),e.jsx("p",{className:"-mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("keys.providers.subtitle")}),e.jsx(me,{section:"openai",testProvider:"openai"}),e.jsx(me,{section:"anthropic",testProvider:"anthropic"}),e.jsx(Xa,{}),e.jsx(me,{section:"xai",testProvider:"xai"}),e.jsx(me,{section:"openrouter",testProvider:"openrouter"}),e.jsx(me,{section:"mistral",testProvider:"mistral"}),e.jsx(me,{section:"cerebras",testProvider:"cerebras"}),e.jsxs("details",{"data-api-keys-other":!0,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",open:!!s.config?.openaiCompat?.configured,children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink-secondary",children:t("keys.other.title")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-4",children:[e.jsx(me,{section:"openaiCompat",testProvider:"openaiCompat"}),e.jsx(Qa,{})]})]}),e.jsx("div",{className:"pt-2 text-[11.5px] font-medium uppercase tracking-wide text-ink-secondary",children:t("keys.integrations.title")}),e.jsx(me,{section:"box"}),e.jsx(Za,{}),e.jsx(me,{section:"opencodeGo"}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"-mt-2 text-[11.5px] leading-relaxed text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((h,E)=>E===0?[h]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},E),h])}),e.jsx(ei,{}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink-secondary",children:t("settings.connections.selfHost")}),e.jsx("div",{className:"mt-3",children:e.jsx(me,{section:"composio"})})]})]})});case"decisionModel":return e.jsx(Ci,{});case"engines":return e.jsx(Fi,{});case"backups":return e.jsxs(e.Fragment,{children:[e.jsx(da,{}),e.jsx(Hl,{})]});case"companion":{const h=s.appSettingsPhonePairing,E=ca(s.config?.cloudHome===!0)==="computer";return e.jsxs(e.Fragment,{children:[e.jsx(zr,{}),!i&&e.jsx(Dr,{}),e.jsx(yr,{cloudHome:s.config?.cloudHome===!0,focusRequest:E?0:h}),!i&&e.jsx(pr,{profileEmail:s.config?.profile?.email,focusRequest:E?h:0})]})}case"computer":return a?e.jsxs(e.Fragment,{children:[e.jsx(os,{}),e.jsx(cs,{}),e.jsx(Lt,{})]}):e.jsx(Lt,{});case"usage":return e.jsx(yl,{});case"skills":return zt(s.config)?e.jsx(jl,{}):null;case"people":return e.jsx(Cr,{});case"activity":return e.jsx(Ar,{});case"workspaces":return e.jsx(Il,{});default:return null}},f=b=>e.jsx("h3",{className:"px-1 text-[13px] font-semibold uppercase tracking-[0.06em] text-ink-secondary",children:t(b)});return e.jsxs("div",{className:"glass-popup-frame",style:la(),onMouseDown:b=>b.target===b.currentTarget&&n({type:"toggleAppSettings",open:!1}),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:l,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-[24px] outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),e.jsxs("div",{className:"mb-2 mt-1 flex min-h-8 shrink-0 items-center gap-2 rounded-lg border border-transparent bg-control/70 px-2.5 py-2 focus-within:border-focus",children:[e.jsx(js,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:u,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),u?c(""):n({type:"toggleAppSettings",open:!1}))},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),(a?y.length===0:N.length===0)&&e.jsx("div",{className:"px-2.5 py-4 text-[12.5px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:u.trim()})}),a?rs.map(b=>{const h=y.filter(E=>E.group===b.id);return h.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${b.id}`,"data-settings-group":b.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${b.id}`,className:"px-2.5 pb-1 pt-2 text-[11px] font-medium uppercase tracking-[0.08em] text-ink-tertiary",children:t(b.labelKey)}),h.map(({id:E,labelKey:A,icon:P})=>e.jsxs("button",{"data-settings-section":E,onClick:()=>D(E),"aria-current":o===E?"page":void 0,className:_("flex min-h-9 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors motion-reduce:transition-none",o===E?"bg-control text-ink":"text-ink-secondary hover:bg-control/50 hover:text-ink"),children:[e.jsx(P,{size:15,className:"shrink-0"}),t(A)]},E))]},b.id)}):e.jsx("div",{className:"flex flex-col gap-0.5 pb-2",children:N.map(b=>{const h=b.icon,E=b===v;return e.jsxs("button",{"data-settings-page":b.id,onClick:()=>D(b.sections[0]),"aria-current":E?"page":void 0,className:_("flex min-h-9 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors motion-reduce:transition-none",E?"bg-control text-ink":"text-ink-secondary hover:bg-control/50 hover:text-ink"),children:[e.jsx(h,{size:15,className:"shrink-0"}),t(b.labelKey)]},b.id)})})]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:px-5",children:[a?e.jsx("select",{"aria-label":t("settings.title"),value:o,onChange:b=>{c(""),D(b.target.value)},className:"min-w-0 rounded-lg bg-control px-3 py-2 text-[14px] text-ink sm:hidden",children:rs.map(b=>{const h=p.filter(E=>E.group===b.id);return h.length===0?null:e.jsx("optgroup",{label:t(b.labelKey),children:h.map(({id:E,labelKey:A})=>e.jsx("option",{value:E,children:t(A)},E))},b.id)})}):e.jsx("select",{"aria-label":t("settings.title"),value:v?.id??"",onChange:b=>{c("");const h=k.find(E=>E.id===b.target.value);h&&D(h.sections[0])},className:"min-w-0 rounded-lg bg-control px-3 py-2 text-[14px] text-ink sm:hidden",children:k.map(b=>e.jsx("option",{value:b.id,children:t(b.labelKey)},b.id))}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:j?t(j):null}),e.jsx("button",{onClick:()=>n({type:"toggleAppSettings",open:!1}),"aria-label":t("settings.close"),title:`${t("settings.close")} (${ra("close-panel")})`,className:"ui-icon-button shrink-0",children:e.jsx(De,{size:18})})]}),e.jsxs("div",{ref:d,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(wl,{config:s.config}),a?I(o):v?v.sections.map(b=>{const h=v.sections.length>1,E=Je.find(A=>A.id===b)?.labelKey;return e.jsxs("section",{"data-settings-block":b,className:"flex scroll-mt-2 flex-col gap-4",children:[h&&E?f(E):null,I(b),b==="computer"&&e.jsxs("div",{"data-settings-block":"browser",className:"flex flex-col gap-4 pt-2",children:[f("settings.experimental.browser"),e.jsx(os,{}),e.jsx(cs,{})]})]},b)}):null]})]})]})]})}export{Je as SECTIONS,rs as SETTINGS_GROUPS,Jl as SIMPLE_HIDDEN_SECTIONS,ql as SIMPLE_PAGES,Ao as SettingsModal,Zl as UpdatesRow,Yl as revealSettingsBlock,Ws as sectionMatches,Gl as simpleSettingsPages};
|