kiki-agent 0.5.1 → 0.6.0
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/builtin/examples/custom-json.mjs +7 -1
- package/dist/builtin/rules/claude/entry.mjs +8 -7
- package/dist/builtin/rules/codex/entry.mjs +8 -7
- package/dist/builtin/rules/files.mjs +6 -1
- package/dist/builtin/rules/grok.mjs +2 -2
- package/dist/builtin/rules/opencode.mjs +2 -2
- package/dist/builtin/rules/pi.mjs +3 -3
- package/dist/cpu-worker.mjs +7964 -3067
- package/dist/docs/en/configuration/config-files.md +180 -23
- package/dist/docs/en/configuration/data-locations.md +7 -4
- package/dist/docs/en/configuration/env-vars.md +1 -1
- package/dist/docs/en/configuration/providers.md +65 -17
- package/dist/docs/en/customization/agent-profiles.md +2 -2
- package/dist/docs/en/customization/agents-and-subagents.md +77 -15
- package/dist/docs/en/customization/hooks.md +77 -21
- package/dist/docs/en/customization/personas.md +3 -3
- package/dist/docs/en/customization/plugins.md +157 -7
- package/dist/docs/en/customization/prompt-fields.md +7 -5
- package/dist/docs/en/customization/recipes.md +3 -3
- package/dist/docs/en/customization/skills.md +1 -1
- package/dist/docs/en/customization/skins.md +1 -1
- package/dist/docs/en/features/agent-workflows.md +1 -1
- package/dist/docs/en/features/daily.md +5 -3
- package/dist/docs/en/features/ecosystem.md +1 -1
- package/dist/docs/en/features/freedom.md +4 -4
- package/dist/docs/en/features/index.md +4 -3
- package/dist/docs/en/features/long-work.md +4 -2
- package/dist/docs/en/features/look.md +1 -1
- package/dist/docs/en/features/people.md +2 -2
- package/dist/docs/en/features/phone.md +1 -1
- package/dist/docs/en/features/spaces.md +38 -26
- package/dist/docs/en/features/workbench.md +2 -0
- package/dist/docs/en/getting-started/first-launch.md +11 -9
- package/dist/docs/en/getting-started/installation.md +65 -2
- package/dist/docs/en/getting-started/use-cases.md +2 -2
- package/dist/docs/en/guides/interaction.md +12 -10
- package/dist/docs/en/guides/interface.md +22 -12
- package/dist/docs/en/guides/memory.md +3 -3
- package/dist/docs/en/guides/sessions.md +8 -4
- package/dist/docs/en/guides/settings.md +53 -52
- package/dist/docs/en/index.md +9 -6
- package/dist/docs/en/reference/command.md +58 -11
- package/dist/docs/en/reference/keyboard.md +32 -15
- package/dist/docs/en/reference/model-vocabulary.md +5 -9
- package/dist/docs/en/reference/slash-commands.md +10 -4
- package/dist/docs/en/reference/tools.md +80 -44
- package/dist/docs/en/server/local-server.md +11 -5
- package/dist/docs/en/server/mcp.md +2 -2
- package/dist/docs/en/server/rest-api.md +185 -59
- package/dist/docs/en/server/script-tools.md +1 -1
- package/dist/docs/zh/configuration/config-files.md +180 -23
- package/dist/docs/zh/configuration/data-locations.md +7 -4
- package/dist/docs/zh/configuration/env-vars.md +1 -1
- package/dist/docs/zh/configuration/providers.md +65 -17
- package/dist/docs/zh/customization/agent-profiles.md +2 -2
- package/dist/docs/zh/customization/agents-and-subagents.md +77 -15
- package/dist/docs/zh/customization/hooks.md +78 -22
- package/dist/docs/zh/customization/personas.md +3 -3
- package/dist/docs/zh/customization/plugins.md +157 -7
- package/dist/docs/zh/customization/prompt-fields.md +7 -5
- package/dist/docs/zh/customization/recipes.md +3 -3
- package/dist/docs/zh/customization/skills.md +1 -1
- package/dist/docs/zh/customization/skins.md +1 -1
- package/dist/docs/zh/features/agent-workflows.md +1 -1
- package/dist/docs/zh/features/daily.md +5 -3
- package/dist/docs/zh/features/ecosystem.md +1 -1
- package/dist/docs/zh/features/freedom.md +4 -4
- package/dist/docs/zh/features/index.md +4 -3
- package/dist/docs/zh/features/long-work.md +4 -2
- package/dist/docs/zh/features/look.md +1 -1
- package/dist/docs/zh/features/people.md +2 -2
- package/dist/docs/zh/features/phone.md +1 -1
- package/dist/docs/zh/features/spaces.md +39 -27
- package/dist/docs/zh/features/workbench.md +2 -0
- package/dist/docs/zh/getting-started/first-launch.md +11 -9
- package/dist/docs/zh/getting-started/installation.md +65 -2
- package/dist/docs/zh/getting-started/use-cases.md +2 -2
- package/dist/docs/zh/guides/interaction.md +12 -10
- package/dist/docs/zh/guides/interface.md +22 -12
- package/dist/docs/zh/guides/memory.md +4 -4
- package/dist/docs/zh/guides/sessions.md +8 -4
- package/dist/docs/zh/guides/settings.md +54 -53
- package/dist/docs/zh/index.md +9 -6
- package/dist/docs/zh/reference/command.md +58 -11
- package/dist/docs/zh/reference/keyboard.md +32 -15
- package/dist/docs/zh/reference/model-vocabulary.md +5 -9
- package/dist/docs/zh/reference/slash-commands.md +10 -4
- package/dist/docs/zh/reference/tools.md +79 -43
- package/dist/docs/zh/server/local-server.md +11 -5
- package/dist/docs/zh/server/mcp.md +2 -2
- package/dist/docs/zh/server/rest-api.md +176 -52
- package/dist/docs/zh/server/script-tools.md +1 -1
- package/dist/external-harness/agy-cli-acp.mjs +3859 -857
- package/dist/external-harness/agy-hook-registration.mjs +72 -20
- package/dist/external-harness/agy-permission-hook.mjs +10 -1
- package/dist/history-navigation-worker.mjs +25565 -0
- package/dist/hostRunner.mjs +753 -7
- package/dist/mailbox-worker.mjs +158 -57
- package/dist/main.mjs +2 -2
- package/dist/memory-worker.mjs +240 -64
- package/dist/native/windows-process-helper.exe +0 -0
- package/dist/plugin-isolation-worker.mjs +57 -0
- package/dist/query-store-worker.mjs +766 -53
- package/dist/sqlite-indexer.mjs +6088 -294
- package/dist/sqlite-query-worker.mjs +5896 -234
- package/dist/usage-parser-worker.mjs +36 -0
- package/dist/usage-read-model-worker.mjs +135 -37
- package/dist/web/assets/App-DCxEkgD4.js +181 -0
- package/dist/web/assets/App-DCxEkgD4.js.br +0 -0
- package/dist/web/assets/App-DCxEkgD4.js.gz +0 -0
- package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js +1 -0
- package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js.br +0 -0
- package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js.gz +0 -0
- package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js +1 -0
- package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js.br +0 -0
- package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js.gz +0 -0
- package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js +15 -0
- package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js.br +0 -0
- package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js.gz +0 -0
- package/dist/web/assets/CodeEditor-BAdDaRcl.js +4 -0
- package/dist/web/assets/CodeEditor-BAdDaRcl.js.br +0 -0
- package/dist/web/assets/CodeEditor-BAdDaRcl.js.gz +0 -0
- package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js +2 -0
- package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js.br +0 -0
- package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js.gz +0 -0
- package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js +1 -0
- package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js.br +0 -0
- package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js.gz +0 -0
- package/dist/web/assets/ImageViewport-osmMzHUM.js +1 -0
- package/dist/web/assets/ImageViewport-osmMzHUM.js.br +0 -0
- package/dist/web/assets/ImageViewport-osmMzHUM.js.gz +0 -0
- package/dist/web/assets/ListParts-DL6n2vZD.js +1 -0
- package/dist/web/assets/ListParts-DL6n2vZD.js.br +0 -0
- package/dist/web/assets/ListParts-DL6n2vZD.js.gz +0 -0
- package/dist/web/assets/MediaLightbox-DfDTfyyo.js +1 -0
- package/dist/web/assets/MediaLightbox-DfDTfyyo.js.br +0 -0
- package/dist/web/assets/MediaLightbox-DfDTfyyo.js.gz +0 -0
- package/dist/web/assets/MemoryPage-C4VM8pO8.js +1 -0
- package/dist/web/assets/MemoryPage-C4VM8pO8.js.br +0 -0
- package/dist/web/assets/MemoryPage-C4VM8pO8.js.gz +0 -0
- package/dist/web/assets/Middleware-CQ3TZHhI.js +67 -0
- package/dist/web/assets/Middleware-CQ3TZHhI.js.br +0 -0
- package/dist/web/assets/Middleware-CQ3TZHhI.js.gz +0 -0
- package/dist/web/assets/MobileAppShell-CPW83S2x.js +23 -0
- package/dist/web/assets/MobileAppShell-CPW83S2x.js.br +0 -0
- package/dist/web/assets/MobileAppShell-CPW83S2x.js.gz +0 -0
- package/dist/web/assets/ModelConnectCard-CY1w-R_8.js +2 -0
- package/dist/web/assets/ModelConnectCard-CY1w-R_8.js.br +0 -0
- package/dist/web/assets/ModelConnectCard-CY1w-R_8.js.gz +0 -0
- package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js +1 -0
- package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js.br +0 -0
- package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js.gz +0 -0
- package/dist/web/assets/PersonasPage-CB5q8dUU.js +3 -0
- package/dist/web/assets/PersonasPage-CB5q8dUU.js.br +0 -0
- package/dist/web/assets/PersonasPage-CB5q8dUU.js.gz +0 -0
- package/dist/web/assets/PluginPanelHost-BNSzFpXj.js +1 -0
- package/dist/web/assets/PluginPanelHost-BNSzFpXj.js.br +0 -0
- package/dist/web/assets/PluginPanelHost-BNSzFpXj.js.gz +0 -0
- package/dist/web/assets/PreviewWorkspace-itdg7TxB.js +1 -0
- package/dist/web/assets/PreviewWorkspace-itdg7TxB.js.br +0 -0
- package/dist/web/assets/PreviewWorkspace-itdg7TxB.js.gz +0 -0
- package/dist/web/assets/RoomPage-DqICeoEq.js +1 -0
- package/dist/web/assets/RoomPage-DqICeoEq.js.br +0 -0
- package/dist/web/assets/RoomPage-DqICeoEq.js.gz +0 -0
- package/dist/web/assets/SecretField-DhvasDWA.js +1 -0
- package/dist/web/assets/SecretField-DhvasDWA.js.br +0 -0
- package/dist/web/assets/SecretField-DhvasDWA.js.gz +0 -0
- package/dist/web/assets/SectionCard-CDWn1QiO.js +1 -0
- package/dist/web/assets/SectionCard-CDWn1QiO.js.br +0 -0
- package/dist/web/assets/SectionCard-CDWn1QiO.js.gz +0 -0
- package/dist/web/assets/SettingsPage-BhaVVzpG.js +259 -0
- package/dist/web/assets/SettingsPage-BhaVVzpG.js.br +0 -0
- package/dist/web/assets/SettingsPage-BhaVVzpG.js.gz +0 -0
- package/dist/web/assets/ShellEntry-DNaOXNB7.js +2 -0
- package/dist/web/assets/ShellEntry-DNaOXNB7.js.br +0 -0
- package/dist/web/assets/ShellEntry-DNaOXNB7.js.gz +0 -0
- package/dist/web/assets/TasksPage-HHJ20hzK.js +1 -0
- package/dist/web/assets/TasksPage-HHJ20hzK.js.br +0 -0
- package/dist/web/assets/TasksPage-HHJ20hzK.js.gz +0 -0
- package/dist/web/assets/TerminalPanel-D7EDH4hR.js +9 -0
- package/dist/web/assets/TerminalPanel-D7EDH4hR.js.br +0 -0
- package/dist/web/assets/TerminalPanel-D7EDH4hR.js.gz +0 -0
- package/dist/web/assets/UsagePage-CyB5c-8F.js +1 -0
- package/dist/web/assets/UsagePage-CyB5c-8F.js.br +0 -0
- package/dist/web/assets/UsagePage-CyB5c-8F.js.gz +0 -0
- package/dist/web/assets/WorkPage-hiw_Nngy.js +1 -0
- package/dist/web/assets/WorkPage-hiw_Nngy.js.br +0 -0
- package/dist/web/assets/WorkPage-hiw_Nngy.js.gz +0 -0
- package/dist/web/assets/abap-BdImnpbu.js.br +0 -0
- package/dist/web/assets/abap-BdImnpbu.js.gz +0 -0
- package/dist/web/assets/actionscript-3-CoDkCxhg.js.br +0 -0
- package/dist/web/assets/actionscript-3-CoDkCxhg.js.gz +0 -0
- package/dist/web/assets/ada-bCR0ucgS.js.br +0 -0
- package/dist/web/assets/ada-bCR0ucgS.js.gz +0 -0
- package/dist/web/assets/androidBridge-DgaAG2Pi.js +1 -0
- package/dist/web/assets/androidBridge-DgaAG2Pi.js.br +0 -0
- package/dist/web/assets/androidBridge-DgaAG2Pi.js.gz +0 -0
- package/dist/web/assets/andromeeda-C4gqWexZ.js.br +0 -0
- package/dist/web/assets/andromeeda-C4gqWexZ.js.gz +0 -0
- package/dist/web/assets/angular-html-CU67Zn6k.js.br +0 -0
- package/dist/web/assets/angular-html-CU67Zn6k.js.gz +0 -0
- package/dist/web/assets/angular-ts-BwZT4LLn.js.br +0 -0
- package/dist/web/assets/angular-ts-BwZT4LLn.js.gz +0 -0
- package/dist/web/assets/apache-Pmp26Uib.js.br +0 -0
- package/dist/web/assets/apache-Pmp26Uib.js.gz +0 -0
- package/dist/web/assets/apex-D8_7TLub.js.br +0 -0
- package/dist/web/assets/apex-D8_7TLub.js.gz +0 -0
- package/dist/web/assets/apl-B4CMkyY2.js.br +0 -0
- package/dist/web/assets/apl-B4CMkyY2.js.gz +0 -0
- package/dist/web/assets/apl-dKokRX4l.js.br +0 -0
- package/dist/web/assets/apl-dKokRX4l.js.gz +0 -0
- package/dist/web/assets/applescript-Co6uUVPk.js.br +0 -0
- package/dist/web/assets/applescript-Co6uUVPk.js.gz +0 -0
- package/dist/web/assets/ara-BRHolxvo.js.br +0 -0
- package/dist/web/assets/ara-BRHolxvo.js.gz +0 -0
- package/dist/web/assets/arc-DoGfTGgR.js +1 -0
- package/dist/web/assets/arc-DoGfTGgR.js.br +0 -0
- package/dist/web/assets/arc-DoGfTGgR.js.gz +0 -0
- package/dist/web/assets/asciiarmor-Df11BRmG.js.br +0 -0
- package/dist/web/assets/asciiarmor-Df11BRmG.js.gz +0 -0
- package/dist/web/assets/asciidoc-Ve4PFQV2.js.br +0 -0
- package/dist/web/assets/asciidoc-Ve4PFQV2.js.gz +0 -0
- package/dist/web/assets/askKiki-CgAsWGRZ.js +2 -0
- package/dist/web/assets/askKiki-CgAsWGRZ.js.br +0 -0
- package/dist/web/assets/askKiki-CgAsWGRZ.js.gz +0 -0
- package/dist/web/assets/asm-D_Q5rh1f.js.br +0 -0
- package/dist/web/assets/asm-D_Q5rh1f.js.gz +0 -0
- package/dist/web/assets/asn1-EdZsLKOL.js.br +0 -0
- package/dist/web/assets/asn1-EdZsLKOL.js.gz +0 -0
- package/dist/web/assets/asterisk-B-8jnY81.js.br +0 -0
- package/dist/web/assets/asterisk-B-8jnY81.js.gz +0 -0
- package/dist/web/assets/astro-CbQHKStN.js.br +0 -0
- package/dist/web/assets/astro-CbQHKStN.js.gz +0 -0
- package/dist/web/assets/aurora-x-D-2ljcwZ.js.br +0 -0
- package/dist/web/assets/aurora-x-D-2ljcwZ.js.gz +0 -0
- package/dist/web/assets/awk-DMzUqQB5.js.br +0 -0
- package/dist/web/assets/awk-DMzUqQB5.js.gz +0 -0
- package/dist/web/assets/ayu-dark-DYE7WIF3.js.br +0 -0
- package/dist/web/assets/ayu-dark-DYE7WIF3.js.gz +0 -0
- package/dist/web/assets/ayu-light-BA47KaF1.js.br +0 -0
- package/dist/web/assets/ayu-light-BA47KaF1.js.gz +0 -0
- package/dist/web/assets/ayu-mirage-32ctXXKs.js.br +0 -0
- package/dist/web/assets/ayu-mirage-32ctXXKs.js.gz +0 -0
- package/dist/web/assets/ballerina-BFfxhgS-.js.br +0 -0
- package/dist/web/assets/ballerina-BFfxhgS-.js.gz +0 -0
- package/dist/web/assets/band-dPffDWoQ.js +1 -0
- package/dist/web/assets/band-dPffDWoQ.js.br +0 -0
- package/dist/web/assets/band-dPffDWoQ.js.gz +0 -0
- package/dist/web/assets/bat-BkioyH1T.js.br +0 -0
- package/dist/web/assets/bat-BkioyH1T.js.gz +0 -0
- package/dist/web/assets/beancount-k_qm7-4y.js.br +0 -0
- package/dist/web/assets/beancount-k_qm7-4y.js.gz +0 -0
- package/dist/web/assets/berry-uYugtg8r.js.br +0 -0
- package/dist/web/assets/berry-uYugtg8r.js.gz +0 -0
- package/dist/web/assets/bibtex-CHM0blh-.js.br +0 -0
- package/dist/web/assets/bibtex-CHM0blh-.js.gz +0 -0
- package/dist/web/assets/bicep-Bmn6On1c.js.br +0 -0
- package/dist/web/assets/bicep-Bmn6On1c.js.gz +0 -0
- package/dist/web/assets/bird2-DPOp833l.js.br +0 -0
- package/dist/web/assets/bird2-DPOp833l.js.gz +0 -0
- package/dist/web/assets/blade-D4QpJJKB.js.br +0 -0
- package/dist/web/assets/blade-D4QpJJKB.js.gz +0 -0
- package/dist/web/assets/brainfuck-C4LP7Hcl.js.br +0 -0
- package/dist/web/assets/brainfuck-C4LP7Hcl.js.gz +0 -0
- package/dist/web/assets/bsl-BO_Y6i37.js.br +0 -0
- package/dist/web/assets/bsl-BO_Y6i37.js.gz +0 -0
- package/dist/web/assets/c-BIGW1oBm.js.br +0 -0
- package/dist/web/assets/c-BIGW1oBm.js.gz +0 -0
- package/dist/web/assets/c3-eo99z4R2.js.br +0 -0
- package/dist/web/assets/c3-eo99z4R2.js.gz +0 -0
- package/dist/web/assets/cadence-Bv_4Rxtq.js.br +0 -0
- package/dist/web/assets/cadence-Bv_4Rxtq.js.gz +0 -0
- package/dist/web/assets/cairo-KRGpt6FW.js.br +0 -0
- package/dist/web/assets/cairo-KRGpt6FW.js.gz +0 -0
- package/dist/web/assets/catppuccin-frappe-DFWUc33u.js.br +0 -0
- package/dist/web/assets/catppuccin-frappe-DFWUc33u.js.gz +0 -0
- package/dist/web/assets/catppuccin-latte-C9dUb6Cb.js.br +0 -0
- package/dist/web/assets/catppuccin-latte-C9dUb6Cb.js.gz +0 -0
- package/dist/web/assets/catppuccin-macchiato-DQyhUUbL.js.br +0 -0
- package/dist/web/assets/catppuccin-macchiato-DQyhUUbL.js.gz +0 -0
- package/dist/web/assets/catppuccin-mocha-D87Tk5Gz.js.br +0 -0
- package/dist/web/assets/catppuccin-mocha-D87Tk5Gz.js.gz +0 -0
- package/dist/web/assets/channel-BwCaPRlV.js +1 -0
- package/dist/web/assets/channel-BwCaPRlV.js.br +0 -0
- package/dist/web/assets/channel-BwCaPRlV.js.gz +0 -0
- package/dist/web/assets/clarity-D53aC0YG.js.br +0 -0
- package/dist/web/assets/clarity-D53aC0YG.js.gz +0 -0
- package/dist/web/assets/client-cAizUM-b.js +7 -0
- package/dist/web/assets/client-cAizUM-b.js.br +0 -0
- package/dist/web/assets/client-cAizUM-b.js.gz +0 -0
- package/dist/web/assets/clike-B9uivgTg.js.br +0 -0
- package/dist/web/assets/clike-B9uivgTg.js.gz +0 -0
- package/dist/web/assets/clojure-BMjYHr_A.js.br +0 -0
- package/dist/web/assets/clojure-BMjYHr_A.js.gz +0 -0
- package/dist/web/assets/clojure-P80f7IUj.js.br +0 -0
- package/dist/web/assets/clojure-P80f7IUj.js.gz +0 -0
- package/dist/web/assets/clone-JiRK1kR-.js +1 -0
- package/dist/web/assets/clone-JiRK1kR-.js.br +0 -0
- package/dist/web/assets/clone-JiRK1kR-.js.gz +0 -0
- package/dist/web/assets/cmake-BQqOBYOt.js.br +0 -0
- package/dist/web/assets/cmake-BQqOBYOt.js.gz +0 -0
- package/dist/web/assets/cmake-D1j8_8rp.js.br +0 -0
- package/dist/web/assets/cmake-D1j8_8rp.js.gz +0 -0
- package/dist/web/assets/cobol-CWcv1MsR.js.br +0 -0
- package/dist/web/assets/cobol-CWcv1MsR.js.gz +0 -0
- package/dist/web/assets/cobol-nwyudZeR.js.br +0 -0
- package/dist/web/assets/cobol-nwyudZeR.js.gz +0 -0
- package/dist/web/assets/codeowners-Bp6g37R7.js.br +0 -0
- package/dist/web/assets/codeowners-Bp6g37R7.js.gz +0 -0
- package/dist/web/assets/codeql-DsOJ9woJ.js.br +0 -0
- package/dist/web/assets/codeql-DsOJ9woJ.js.gz +0 -0
- package/dist/web/assets/coffee-Ch7k5sss.js.br +0 -0
- package/dist/web/assets/coffee-Ch7k5sss.js.gz +0 -0
- package/dist/web/assets/coffeescript-S37ZYGWr.js.br +0 -0
- package/dist/web/assets/coffeescript-S37ZYGWr.js.gz +0 -0
- package/dist/web/assets/common-lisp-Cg-RD9OK.js.br +0 -0
- package/dist/web/assets/common-lisp-Cg-RD9OK.js.gz +0 -0
- package/dist/web/assets/commonlisp-DBKNyK5s.js.br +0 -0
- package/dist/web/assets/commonlisp-DBKNyK5s.js.gz +0 -0
- package/dist/web/assets/connection-5XKg4sL2.js +404 -0
- package/dist/web/assets/connection-5XKg4sL2.js.br +0 -0
- package/dist/web/assets/connection-5XKg4sL2.js.gz +0 -0
- package/dist/web/assets/controls-C3UrNiBn.js +1 -0
- package/dist/web/assets/controls-C3UrNiBn.js.br +0 -0
- package/dist/web/assets/controls-C3UrNiBn.js.gz +0 -0
- package/dist/web/assets/coq-DkFqJrB1.js.br +0 -0
- package/dist/web/assets/coq-DkFqJrB1.js.gz +0 -0
- package/dist/web/assets/cpp-CofmeUqb.js.br +0 -0
- package/dist/web/assets/cpp-CofmeUqb.js.gz +0 -0
- package/dist/web/assets/crystal-SjHAIU92.js.br +0 -0
- package/dist/web/assets/crystal-SjHAIU92.js.gz +0 -0
- package/dist/web/assets/crystal-tKQVLTB8.js.br +0 -0
- package/dist/web/assets/crystal-tKQVLTB8.js.gz +0 -0
- package/dist/web/assets/csharp-COcwbKMJ.js.br +0 -0
- package/dist/web/assets/csharp-COcwbKMJ.js.gz +0 -0
- package/dist/web/assets/css-BnMrqG3P.js.br +0 -0
- package/dist/web/assets/css-BnMrqG3P.js.gz +0 -0
- package/dist/web/assets/css-DPfMkruS.js.br +0 -0
- package/dist/web/assets/css-DPfMkruS.js.gz +0 -0
- package/dist/web/assets/csv-fuZLfV_i.js.br +0 -0
- package/dist/web/assets/csv-fuZLfV_i.js.gz +0 -0
- package/dist/web/assets/cue-D82EKSYY.js.br +0 -0
- package/dist/web/assets/cue-D82EKSYY.js.gz +0 -0
- package/dist/web/assets/cypher-COkxafJQ.js.br +0 -0
- package/dist/web/assets/cypher-COkxafJQ.js.gz +0 -0
- package/dist/web/assets/cypher-C_CwsFkJ.js.br +0 -0
- package/dist/web/assets/cypher-C_CwsFkJ.js.gz +0 -0
- package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js +1 -0
- package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js.br +0 -0
- package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js.gz +0 -0
- package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js +1 -0
- package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js.br +0 -0
- package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js.gz +0 -0
- package/dist/web/assets/cytoscape.esm-nFXppDBa.js.br +0 -0
- package/dist/web/assets/cytoscape.esm-nFXppDBa.js.gz +0 -0
- package/dist/web/assets/d-85-TOEBH.js.br +0 -0
- package/dist/web/assets/d-85-TOEBH.js.gz +0 -0
- package/dist/web/assets/d-pRatUO7H.js.br +0 -0
- package/dist/web/assets/d-pRatUO7H.js.gz +0 -0
- package/dist/web/assets/dark-plus-C3mMm8J8.js.br +0 -0
- package/dist/web/assets/dark-plus-C3mMm8J8.js.gz +0 -0
- package/dist/web/assets/dart-CF10PKvl.js.br +0 -0
- package/dist/web/assets/dart-CF10PKvl.js.gz +0 -0
- package/dist/web/assets/dax-CEL-wOlO.js.br +0 -0
- package/dist/web/assets/dax-CEL-wOlO.js.gz +0 -0
- package/dist/web/assets/{defaultLocale-DX6XiGOO.js → defaultLocale-5voVPcsN.js} +1 -1
- package/dist/web/assets/defaultLocale-5voVPcsN.js.br +0 -0
- package/dist/web/assets/defaultLocale-5voVPcsN.js.gz +0 -0
- package/dist/web/assets/desktop-BmXAJ9_W.js.br +0 -0
- package/dist/web/assets/desktop-BmXAJ9_W.js.gz +0 -0
- package/dist/web/assets/diff-D97Zzqfu.js.br +0 -0
- package/dist/web/assets/diff-D97Zzqfu.js.gz +0 -0
- package/dist/web/assets/diff-DbItnlRl.js.br +0 -0
- package/dist/web/assets/diff-DbItnlRl.js.gz +0 -0
- package/dist/web/assets/docker-BcOcwvcX.js.br +0 -0
- package/dist/web/assets/docker-BcOcwvcX.js.gz +0 -0
- package/dist/web/assets/dockerfile-BKs6k2Af.js.br +0 -0
- package/dist/web/assets/dockerfile-BKs6k2Af.js.gz +0 -0
- package/dist/web/assets/dotenv-Da5cRb03.js.br +0 -0
- package/dist/web/assets/dotenv-Da5cRb03.js.gz +0 -0
- package/dist/web/assets/dracula-BzJJZx-M.js.br +0 -0
- package/dist/web/assets/dracula-BzJJZx-M.js.gz +0 -0
- package/dist/web/assets/dracula-soft-BXkSAIEj.js.br +0 -0
- package/dist/web/assets/dracula-soft-BXkSAIEj.js.gz +0 -0
- package/dist/web/assets/dream-maker-BtqSS_iP.js.br +0 -0
- package/dist/web/assets/dream-maker-BtqSS_iP.js.gz +0 -0
- package/dist/web/assets/dtd-DF_7sFjM.js.br +0 -0
- package/dist/web/assets/dtd-DF_7sFjM.js.gz +0 -0
- package/dist/web/assets/duration-BNAPaH6N.js +1 -0
- package/dist/web/assets/duration-BNAPaH6N.js.br +0 -0
- package/dist/web/assets/duration-BNAPaH6N.js.gz +0 -0
- package/dist/web/assets/dylan-DwRh75JA.js.br +0 -0
- package/dist/web/assets/dylan-DwRh75JA.js.gz +0 -0
- package/dist/web/assets/ebnf-CDyGwa7X.js.br +0 -0
- package/dist/web/assets/ebnf-CDyGwa7X.js.gz +0 -0
- package/dist/web/assets/ecl-Cabwm37j.js.br +0 -0
- package/dist/web/assets/ecl-Cabwm37j.js.gz +0 -0
- package/dist/web/assets/edge-BkV0erSs.js.br +0 -0
- package/dist/web/assets/edge-BkV0erSs.js.gz +0 -0
- package/dist/web/assets/eiffel-CnydiIhH.js.br +0 -0
- package/dist/web/assets/eiffel-CnydiIhH.js.gz +0 -0
- package/dist/web/assets/elixir-CDX3lj18.js.br +0 -0
- package/dist/web/assets/elixir-CDX3lj18.js.gz +0 -0
- package/dist/web/assets/elm-DbKCFpqz.js.br +0 -0
- package/dist/web/assets/elm-DbKCFpqz.js.gz +0 -0
- package/dist/web/assets/elm-vLlmbW-K.js.br +0 -0
- package/dist/web/assets/elm-vLlmbW-K.js.gz +0 -0
- package/dist/web/assets/emacs-lisp-C9XAeP06.js.br +0 -0
- package/dist/web/assets/emacs-lisp-C9XAeP06.js.gz +0 -0
- package/dist/web/assets/erb-B12qg9BL.js.br +0 -0
- package/dist/web/assets/erb-B12qg9BL.js.gz +0 -0
- package/dist/web/assets/erlang-BNw1qcRV.js.br +0 -0
- package/dist/web/assets/erlang-BNw1qcRV.js.gz +0 -0
- package/dist/web/assets/erlang-DsQrWhSR.js.br +0 -0
- package/dist/web/assets/erlang-DsQrWhSR.js.gz +0 -0
- package/dist/web/assets/everforest-dark-BgDCqdQA.js.br +0 -0
- package/dist/web/assets/everforest-dark-BgDCqdQA.js.gz +0 -0
- package/dist/web/assets/everforest-light-C8M2exoo.js.br +0 -0
- package/dist/web/assets/everforest-light-C8M2exoo.js.gz +0 -0
- package/dist/web/assets/export-BlURphmw.js +2 -0
- package/dist/web/assets/export-BlURphmw.js.br +0 -0
- package/dist/web/assets/export-BlURphmw.js.gz +0 -0
- package/dist/web/assets/factor-kuTfRLto.js.br +0 -0
- package/dist/web/assets/factor-kuTfRLto.js.gz +0 -0
- package/dist/web/assets/fcl-Kvtd6kyn.js.br +0 -0
- package/dist/web/assets/fcl-Kvtd6kyn.js.gz +0 -0
- package/dist/web/assets/fennel-BYunw83y.js.br +0 -0
- package/dist/web/assets/fennel-BYunw83y.js.gz +0 -0
- package/dist/web/assets/fish-BvzEVeQv.js.br +0 -0
- package/dist/web/assets/fish-BvzEVeQv.js.gz +0 -0
- package/dist/web/assets/fluent-C4IJs8-o.js.br +0 -0
- package/dist/web/assets/fluent-C4IJs8-o.js.gz +0 -0
- package/dist/web/assets/forth-Ffai-XNe.js.br +0 -0
- package/dist/web/assets/forth-Ffai-XNe.js.gz +0 -0
- package/dist/web/assets/fortran-DYz_wnZ1.js.br +0 -0
- package/dist/web/assets/fortran-DYz_wnZ1.js.gz +0 -0
- package/dist/web/assets/fortran-fixed-form-CkoXwp7k.js.br +0 -0
- package/dist/web/assets/fortran-fixed-form-CkoXwp7k.js.gz +0 -0
- package/dist/web/assets/fortran-free-form-BxgE0vQu.js.br +0 -0
- package/dist/web/assets/fortran-free-form-BxgE0vQu.js.gz +0 -0
- package/dist/web/assets/fsharp-CXgrBDvD.js.br +0 -0
- package/dist/web/assets/fsharp-CXgrBDvD.js.gz +0 -0
- package/dist/web/assets/gas-Bneqetm1.js.br +0 -0
- package/dist/web/assets/gas-Bneqetm1.js.gz +0 -0
- package/dist/web/assets/gdresource-BOOCDP_w.js.br +0 -0
- package/dist/web/assets/gdresource-BOOCDP_w.js.gz +0 -0
- package/dist/web/assets/gdscript-C5YyOfLZ.js.br +0 -0
- package/dist/web/assets/gdscript-C5YyOfLZ.js.gz +0 -0
- package/dist/web/assets/gdshader-DkwncUOv.js.br +0 -0
- package/dist/web/assets/gdshader-DkwncUOv.js.gz +0 -0
- package/dist/web/assets/genie-D0YGMca9.js.br +0 -0
- package/dist/web/assets/genie-D0YGMca9.js.gz +0 -0
- package/dist/web/assets/gherkin-DyxjwDmM.js.br +0 -0
- package/dist/web/assets/gherkin-DyxjwDmM.js.gz +0 -0
- package/dist/web/assets/gherkin-heZmZLOM.js.br +0 -0
- package/dist/web/assets/gherkin-heZmZLOM.js.gz +0 -0
- package/dist/web/assets/git-commit-F4YmCXRG.js.br +0 -0
- package/dist/web/assets/git-commit-F4YmCXRG.js.gz +0 -0
- package/dist/web/assets/git-rebase-r7XF79zn.js.br +0 -0
- package/dist/web/assets/git-rebase-r7XF79zn.js.gz +0 -0
- package/dist/web/assets/github-dark-DHJKELXO.js.br +0 -0
- package/dist/web/assets/github-dark-DHJKELXO.js.gz +0 -0
- package/dist/web/assets/github-dark-default-Cuk6v7N8.js.br +0 -0
- package/dist/web/assets/github-dark-default-Cuk6v7N8.js.gz +0 -0
- package/dist/web/assets/github-dark-dimmed-DH5Ifo-i.js.br +0 -0
- package/dist/web/assets/github-dark-dimmed-DH5Ifo-i.js.gz +0 -0
- package/dist/web/assets/github-dark-high-contrast-E3gJ1_iC.js.br +0 -0
- package/dist/web/assets/github-dark-high-contrast-E3gJ1_iC.js.gz +0 -0
- package/dist/web/assets/github-light-DAi9KRSo.js.br +0 -0
- package/dist/web/assets/github-light-DAi9KRSo.js.gz +0 -0
- package/dist/web/assets/github-light-default-D7oLnXFd.js.br +0 -0
- package/dist/web/assets/github-light-default-D7oLnXFd.js.gz +0 -0
- package/dist/web/assets/github-light-high-contrast-BfjtVDDH.js.br +0 -0
- package/dist/web/assets/github-light-high-contrast-BfjtVDDH.js.gz +0 -0
- package/dist/web/assets/gleam-BspZqrRM.js.br +0 -0
- package/dist/web/assets/gleam-BspZqrRM.js.gz +0 -0
- package/dist/web/assets/glimmer-js-Rg0-pVw9.js.br +0 -0
- package/dist/web/assets/glimmer-js-Rg0-pVw9.js.gz +0 -0
- package/dist/web/assets/glimmer-ts-U6CK756n.js.br +0 -0
- package/dist/web/assets/glimmer-ts-U6CK756n.js.gz +0 -0
- package/dist/web/assets/glsl-DplSGwfg.js.br +0 -0
- package/dist/web/assets/glsl-DplSGwfg.js.gz +0 -0
- package/dist/web/assets/gn-n2N0HUVH.js.br +0 -0
- package/dist/web/assets/gn-n2N0HUVH.js.gz +0 -0
- package/dist/web/assets/gnuplot-DdkO51Og.js.br +0 -0
- package/dist/web/assets/gnuplot-DdkO51Og.js.gz +0 -0
- package/dist/web/assets/go-CxLEBnE3.js.br +0 -0
- package/dist/web/assets/go-CxLEBnE3.js.gz +0 -0
- package/dist/web/assets/graph--OzhPTMs.js.br +0 -0
- package/dist/web/assets/graph--OzhPTMs.js.gz +0 -0
- package/dist/web/assets/graphql-ChdNCCLP.js.br +0 -0
- package/dist/web/assets/graphql-ChdNCCLP.js.gz +0 -0
- package/dist/web/assets/groovy-D9Dt4D0W.js.br +0 -0
- package/dist/web/assets/groovy-D9Dt4D0W.js.gz +0 -0
- package/dist/web/assets/groovy-gcz8RCvz.js.br +0 -0
- package/dist/web/assets/groovy-gcz8RCvz.js.gz +0 -0
- package/dist/web/assets/gruvbox-dark-hard-CFHQjOhq.js.br +0 -0
- package/dist/web/assets/gruvbox-dark-hard-CFHQjOhq.js.gz +0 -0
- package/dist/web/assets/gruvbox-dark-medium-GsRaNv29.js.br +0 -0
- package/dist/web/assets/gruvbox-dark-medium-GsRaNv29.js.gz +0 -0
- package/dist/web/assets/gruvbox-dark-soft-CVdnzihN.js.br +0 -0
- package/dist/web/assets/gruvbox-dark-soft-CVdnzihN.js.gz +0 -0
- package/dist/web/assets/gruvbox-light-hard-CH1njM8p.js.br +0 -0
- package/dist/web/assets/gruvbox-light-hard-CH1njM8p.js.gz +0 -0
- package/dist/web/assets/gruvbox-light-medium-DRw_LuNl.js.br +0 -0
- package/dist/web/assets/gruvbox-light-medium-DRw_LuNl.js.gz +0 -0
- package/dist/web/assets/gruvbox-light-soft-hJgmCMqR.js.br +0 -0
- package/dist/web/assets/gruvbox-light-soft-hJgmCMqR.js.gz +0 -0
- package/dist/web/assets/hack-CaT9iCJl.js.br +0 -0
- package/dist/web/assets/hack-CaT9iCJl.js.gz +0 -0
- package/dist/web/assets/haml-B8DHNrY2.js.br +0 -0
- package/dist/web/assets/haml-B8DHNrY2.js.gz +0 -0
- package/dist/web/assets/handlebars-BL8al0AC.js.br +0 -0
- package/dist/web/assets/handlebars-BL8al0AC.js.gz +0 -0
- package/dist/web/assets/haskell-Cw1EW3IL.js.br +0 -0
- package/dist/web/assets/haskell-Cw1EW3IL.js.gz +0 -0
- package/dist/web/assets/haskell-Df6bDoY_.js.br +0 -0
- package/dist/web/assets/haskell-Df6bDoY_.js.gz +0 -0
- package/dist/web/assets/haxe-CzTSHFRz.js.br +0 -0
- package/dist/web/assets/haxe-CzTSHFRz.js.gz +0 -0
- package/dist/web/assets/haxe-H-WmDvRZ.js.br +0 -0
- package/dist/web/assets/haxe-H-WmDvRZ.js.gz +0 -0
- package/dist/web/assets/hcl-BWvSN4gD.js.br +0 -0
- package/dist/web/assets/hcl-BWvSN4gD.js.gz +0 -0
- package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js +1 -0
- package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js.br +0 -0
- package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js.gz +0 -0
- package/dist/web/assets/hjson-D5-asLiD.js.br +0 -0
- package/dist/web/assets/hjson-D5-asLiD.js.gz +0 -0
- package/dist/web/assets/hlsl-D3lLCCz7.js.br +0 -0
- package/dist/web/assets/hlsl-D3lLCCz7.js.gz +0 -0
- package/dist/web/assets/horizon-BUw7H-hv.js.br +0 -0
- package/dist/web/assets/horizon-BUw7H-hv.js.gz +0 -0
- package/dist/web/assets/horizon-bright-Cn-bp-IR.js.br +0 -0
- package/dist/web/assets/horizon-bright-Cn-bp-IR.js.gz +0 -0
- package/dist/web/assets/houston-DnULxvSX.js.br +0 -0
- package/dist/web/assets/houston-DnULxvSX.js.gz +0 -0
- package/dist/web/assets/html-GMplVEZG.js.br +0 -0
- package/dist/web/assets/html-GMplVEZG.js.gz +0 -0
- package/dist/web/assets/html-derivative-BFtXZ54Q.js.br +0 -0
- package/dist/web/assets/html-derivative-BFtXZ54Q.js.gz +0 -0
- package/dist/web/assets/http-DBlCnlav.js.br +0 -0
- package/dist/web/assets/http-DBlCnlav.js.gz +0 -0
- package/dist/web/assets/http-jrhK8wxY.js.br +0 -0
- package/dist/web/assets/http-jrhK8wxY.js.gz +0 -0
- package/dist/web/assets/hurl-irOxFIW8.js.br +0 -0
- package/dist/web/assets/hurl-irOxFIW8.js.gz +0 -0
- package/dist/web/assets/hxml-Bvhsp5Yf.js.br +0 -0
- package/dist/web/assets/hxml-Bvhsp5Yf.js.gz +0 -0
- package/dist/web/assets/hy-DFXneXwc.js.br +0 -0
- package/dist/web/assets/hy-DFXneXwc.js.gz +0 -0
- package/dist/web/assets/idl-BEugSyMb.js.br +0 -0
- package/dist/web/assets/idl-BEugSyMb.js.gz +0 -0
- package/dist/web/assets/imba-DGztddWO.js.br +0 -0
- package/dist/web/assets/imba-DGztddWO.js.gz +0 -0
- package/dist/web/assets/{index-DmwFFSkV.js → index-AtrTtxWl.js} +1 -1
- package/dist/web/assets/index-AtrTtxWl.js.br +0 -0
- package/dist/web/assets/index-AtrTtxWl.js.gz +0 -0
- package/dist/web/assets/index-BBEGEj83.js +1 -0
- package/dist/web/assets/index-BBEGEj83.js.br +0 -0
- package/dist/web/assets/index-BBEGEj83.js.gz +0 -0
- package/dist/web/assets/index-BDdIDEp4.js +1 -0
- package/dist/web/assets/index-BDdIDEp4.js.br +0 -0
- package/dist/web/assets/index-BDdIDEp4.js.gz +0 -0
- package/dist/web/assets/index-BIfumokk.js +1 -0
- package/dist/web/assets/index-BIfumokk.js.br +0 -0
- package/dist/web/assets/index-BIfumokk.js.gz +0 -0
- package/dist/web/assets/index-BLi2nTxe.js +206 -0
- package/dist/web/assets/index-BLi2nTxe.js.br +0 -0
- package/dist/web/assets/index-BLi2nTxe.js.gz +0 -0
- package/dist/web/assets/index-BNFiIuBC.js +1 -0
- package/dist/web/assets/index-BNFiIuBC.js.br +0 -0
- package/dist/web/assets/index-BNFiIuBC.js.gz +0 -0
- package/dist/web/assets/index-BOXDlCpS.js +1 -0
- package/dist/web/assets/index-BOXDlCpS.js.br +0 -0
- package/dist/web/assets/index-BOXDlCpS.js.gz +0 -0
- package/dist/web/assets/{index-CBvwNH_H.js → index-BPG2nU9y.js} +1 -1
- package/dist/web/assets/index-BPG2nU9y.js.br +0 -0
- package/dist/web/assets/index-BPG2nU9y.js.gz +0 -0
- package/dist/web/assets/index-BSVOVe3D.js +1 -0
- package/dist/web/assets/index-BSVOVe3D.js.br +0 -0
- package/dist/web/assets/index-BSVOVe3D.js.gz +0 -0
- package/dist/web/assets/{index-CPSWYh_R.js → index-BT8zjpNF.js} +5 -5
- package/dist/web/assets/index-BT8zjpNF.js.br +0 -0
- package/dist/web/assets/index-BT8zjpNF.js.gz +0 -0
- package/dist/web/assets/index-BTHoDcN1.js +7 -0
- package/dist/web/assets/index-BTHoDcN1.js.br +0 -0
- package/dist/web/assets/index-BTHoDcN1.js.gz +0 -0
- package/dist/web/assets/{index-DRo5Y_9p.js → index-BWFj-16K.js} +1 -1
- package/dist/web/assets/index-BWFj-16K.js.br +0 -0
- package/dist/web/assets/index-BWFj-16K.js.gz +0 -0
- package/dist/web/assets/index-BYkQjRc-.js +1 -0
- package/dist/web/assets/index-BYkQjRc-.js.br +0 -0
- package/dist/web/assets/index-BYkQjRc-.js.gz +0 -0
- package/dist/web/assets/{index-BxYCSNg_.js → index-BbmM2LEW.js} +2 -2
- package/dist/web/assets/index-BbmM2LEW.js.br +0 -0
- package/dist/web/assets/index-BbmM2LEW.js.gz +0 -0
- package/dist/web/assets/index-C6n6XERd.js +1 -0
- package/dist/web/assets/index-C6n6XERd.js.br +0 -0
- package/dist/web/assets/index-C6n6XERd.js.gz +0 -0
- package/dist/web/assets/index-C83WoUbd.js +1 -0
- package/dist/web/assets/index-C83WoUbd.js.br +0 -0
- package/dist/web/assets/index-C83WoUbd.js.gz +0 -0
- package/dist/web/assets/index-C8DDOUJx.css +1 -0
- package/dist/web/assets/index-C8DDOUJx.css.br +0 -0
- package/dist/web/assets/index-C8DDOUJx.css.gz +0 -0
- package/dist/web/assets/index-C9DdZFNJ.js +1 -0
- package/dist/web/assets/index-C9DdZFNJ.js.br +0 -0
- package/dist/web/assets/index-C9DdZFNJ.js.gz +0 -0
- package/dist/web/assets/index-CP99-KdF.js +1 -0
- package/dist/web/assets/index-CP99-KdF.js.br +0 -0
- package/dist/web/assets/index-CP99-KdF.js.gz +0 -0
- package/dist/web/assets/index-CVrtusX9.js +1 -0
- package/dist/web/assets/index-CVrtusX9.js.br +0 -0
- package/dist/web/assets/index-CVrtusX9.js.gz +0 -0
- package/dist/web/assets/{index-DfUpwUTM.js → index-ChTpz7dO.js} +2 -2
- package/dist/web/assets/index-ChTpz7dO.js.br +0 -0
- package/dist/web/assets/index-ChTpz7dO.js.gz +0 -0
- package/dist/web/assets/index-CjceQ8Nh.js +1 -0
- package/dist/web/assets/index-CjceQ8Nh.js.br +0 -0
- package/dist/web/assets/index-CjceQ8Nh.js.gz +0 -0
- package/dist/web/assets/{index-CjvqtF2I.js → index-CsKZwkF5.js} +1 -1
- package/dist/web/assets/index-CsKZwkF5.js.br +0 -0
- package/dist/web/assets/index-CsKZwkF5.js.gz +0 -0
- package/dist/web/assets/index-CvYzv8kf.js +1 -0
- package/dist/web/assets/index-CvYzv8kf.js.br +0 -0
- package/dist/web/assets/index-CvYzv8kf.js.gz +0 -0
- package/dist/web/assets/index-D2CHDVPg.js +1 -0
- package/dist/web/assets/index-D2CHDVPg.js.br +0 -0
- package/dist/web/assets/index-D2CHDVPg.js.gz +0 -0
- package/dist/web/assets/index-D4M-EXnj.js +1 -0
- package/dist/web/assets/index-D4M-EXnj.js.br +0 -0
- package/dist/web/assets/index-D4M-EXnj.js.gz +0 -0
- package/dist/web/assets/{index-BvRBCpc6.js → index-DHqpUC48.js} +2 -2
- package/dist/web/assets/index-DHqpUC48.js.br +0 -0
- package/dist/web/assets/index-DHqpUC48.js.gz +0 -0
- package/dist/web/assets/index-Da0Nrt28.js +1 -0
- package/dist/web/assets/index-Da0Nrt28.js.br +0 -0
- package/dist/web/assets/index-Da0Nrt28.js.gz +0 -0
- package/dist/web/assets/index-DyWRj5df.js +1 -0
- package/dist/web/assets/index-DyWRj5df.js.br +0 -0
- package/dist/web/assets/index-DyWRj5df.js.gz +0 -0
- package/dist/web/assets/{index-Dkbz748K.js → index-DyZAPivK.js} +4 -4
- package/dist/web/assets/index-DyZAPivK.js.br +0 -0
- package/dist/web/assets/index-DyZAPivK.js.gz +0 -0
- package/dist/web/assets/index-FqFCN7CT.js +13 -0
- package/dist/web/assets/index-FqFCN7CT.js.br +0 -0
- package/dist/web/assets/index-FqFCN7CT.js.gz +0 -0
- package/dist/web/assets/{index-Br3AlBrQ.js → index-L9ABPsXe.js} +1 -1
- package/dist/web/assets/index-L9ABPsXe.js.br +0 -0
- package/dist/web/assets/index-L9ABPsXe.js.gz +0 -0
- package/dist/web/assets/ini-BEwlwnbL.js.br +0 -0
- package/dist/web/assets/ini-BEwlwnbL.js.gz +0 -0
- package/dist/web/assets/init-Gi6I4Gst.js.br +0 -0
- package/dist/web/assets/init-Gi6I4Gst.js.gz +0 -0
- package/dist/web/assets/java-CylS5w8V.js.br +0 -0
- package/dist/web/assets/java-CylS5w8V.js.gz +0 -0
- package/dist/web/assets/javascript-iXu5QeM3.js.br +0 -0
- package/dist/web/assets/javascript-iXu5QeM3.js.gz +0 -0
- package/dist/web/assets/javascript-wDzz0qaB.js.br +0 -0
- package/dist/web/assets/javascript-wDzz0qaB.js.gz +0 -0
- package/dist/web/assets/jinja-4LBKfQ-Z.js.br +0 -0
- package/dist/web/assets/jinja-4LBKfQ-Z.js.gz +0 -0
- package/dist/web/assets/jison-wvAkD_A8.js.br +0 -0
- package/dist/web/assets/jison-wvAkD_A8.js.gz +0 -0
- package/dist/web/assets/json-Cp-IABpG.js.br +0 -0
- package/dist/web/assets/json-Cp-IABpG.js.gz +0 -0
- package/dist/web/assets/json-DQCdPPbD.js +1 -0
- package/dist/web/assets/json-DQCdPPbD.js.br +0 -0
- package/dist/web/assets/json-DQCdPPbD.js.gz +0 -0
- package/dist/web/assets/json5-C9tS-k6U.js.br +0 -0
- package/dist/web/assets/json5-C9tS-k6U.js.gz +0 -0
- package/dist/web/assets/jsonc-Des-eS-w.js.br +0 -0
- package/dist/web/assets/jsonc-Des-eS-w.js.gz +0 -0
- package/dist/web/assets/jsonl-DcaNXYhu.js.br +0 -0
- package/dist/web/assets/jsonl-DcaNXYhu.js.gz +0 -0
- package/dist/web/assets/jsonnet-DFQXde-d.js.br +0 -0
- package/dist/web/assets/jsonnet-DFQXde-d.js.gz +0 -0
- package/dist/web/assets/jssm-C2t-YnRu.js.br +0 -0
- package/dist/web/assets/jssm-C2t-YnRu.js.gz +0 -0
- package/dist/web/assets/jsx-g9-lgVsj.js.br +0 -0
- package/dist/web/assets/jsx-g9-lgVsj.js.gz +0 -0
- package/dist/web/assets/julia-CxzCAyBv.js.br +0 -0
- package/dist/web/assets/julia-CxzCAyBv.js.gz +0 -0
- package/dist/web/assets/julia-DuME0IfC.js.br +0 -0
- package/dist/web/assets/julia-DuME0IfC.js.gz +0 -0
- package/dist/web/assets/just-Cw27pwNe.js.br +0 -0
- package/dist/web/assets/just-Cw27pwNe.js.gz +0 -0
- package/dist/web/assets/kanagawa-dragon-CkXjmgJE.js.br +0 -0
- package/dist/web/assets/kanagawa-dragon-CkXjmgJE.js.gz +0 -0
- package/dist/web/assets/kanagawa-lotus-CfQXZHmo.js.br +0 -0
- package/dist/web/assets/kanagawa-lotus-CfQXZHmo.js.gz +0 -0
- package/dist/web/assets/kanagawa-wave-DWedfzmr.js.br +0 -0
- package/dist/web/assets/kanagawa-wave-DWedfzmr.js.gz +0 -0
- package/dist/web/assets/katex-HP8lGamR.js.br +0 -0
- package/dist/web/assets/katex-HP8lGamR.js.gz +0 -0
- package/dist/web/assets/kdl-DV7GczEv.js.br +0 -0
- package/dist/web/assets/kdl-DV7GczEv.js.gz +0 -0
- package/dist/web/assets/kotlin-BdnUsdx6.js.br +0 -0
- package/dist/web/assets/kotlin-BdnUsdx6.js.gz +0 -0
- package/dist/web/assets/kusto-DZf3V79B.js.br +0 -0
- package/dist/web/assets/kusto-DZf3V79B.js.gz +0 -0
- package/dist/web/assets/laserwave-DUszq2jm.js.br +0 -0
- package/dist/web/assets/laserwave-DUszq2jm.js.gz +0 -0
- package/dist/web/assets/latex-CWtU0Tv5.js.br +0 -0
- package/dist/web/assets/latex-CWtU0Tv5.js.gz +0 -0
- package/dist/web/assets/layout-SsrduOYp.js.br +0 -0
- package/dist/web/assets/layout-SsrduOYp.js.gz +0 -0
- package/dist/web/assets/layoutHooks-BzE4xDdh.js +1 -0
- package/dist/web/assets/layoutHooks-BzE4xDdh.js.br +0 -0
- package/dist/web/assets/layoutHooks-BzE4xDdh.js.gz +0 -0
- package/dist/web/assets/lean-BZvkOJ9d.js.br +0 -0
- package/dist/web/assets/lean-BZvkOJ9d.js.gz +0 -0
- package/dist/web/assets/less-B1dDrJ26.js.br +0 -0
- package/dist/web/assets/less-B1dDrJ26.js.gz +0 -0
- package/dist/web/assets/light-plus-B7mTdjB0.js.br +0 -0
- package/dist/web/assets/light-plus-B7mTdjB0.js.gz +0 -0
- package/dist/web/assets/linear-8XOvhBtb.js +1 -0
- package/dist/web/assets/linear-8XOvhBtb.js.br +0 -0
- package/dist/web/assets/linear-8XOvhBtb.js.gz +0 -0
- package/dist/web/assets/liquid-DYVedYrR.js.br +0 -0
- package/dist/web/assets/liquid-DYVedYrR.js.gz +0 -0
- package/dist/web/assets/livescript-BwQOo05w.js.br +0 -0
- package/dist/web/assets/livescript-BwQOo05w.js.gz +0 -0
- package/dist/web/assets/llvm-DjAJT7YJ.js.br +0 -0
- package/dist/web/assets/llvm-DjAJT7YJ.js.gz +0 -0
- package/dist/web/assets/log-2UxHyX5q.js.br +0 -0
- package/dist/web/assets/log-2UxHyX5q.js.gz +0 -0
- package/dist/web/assets/logo-BtOb2qkB.js.br +0 -0
- package/dist/web/assets/logo-BtOb2qkB.js.gz +0 -0
- package/dist/web/assets/lua-BaeVxFsk.js.br +0 -0
- package/dist/web/assets/lua-BaeVxFsk.js.gz +0 -0
- package/dist/web/assets/lua-VAEuO923.js.br +0 -0
- package/dist/web/assets/lua-VAEuO923.js.gz +0 -0
- package/dist/web/assets/luau-C-HG3fhB.js.br +0 -0
- package/dist/web/assets/luau-C-HG3fhB.js.gz +0 -0
- package/dist/web/assets/make-CHLpvVh8.js.br +0 -0
- package/dist/web/assets/make-CHLpvVh8.js.gz +0 -0
- package/dist/web/assets/markdown-Cvjx9yec.js.br +0 -0
- package/dist/web/assets/markdown-Cvjx9yec.js.gz +0 -0
- package/dist/web/assets/marko-CnJfTvn9.js.br +0 -0
- package/dist/web/assets/marko-CnJfTvn9.js.gz +0 -0
- package/dist/web/assets/material-theme-D5KoaKCx.js.br +0 -0
- package/dist/web/assets/material-theme-D5KoaKCx.js.gz +0 -0
- package/dist/web/assets/material-theme-darker-BfHTSMKl.js.br +0 -0
- package/dist/web/assets/material-theme-darker-BfHTSMKl.js.gz +0 -0
- package/dist/web/assets/material-theme-lighter-B0m2ddpp.js.br +0 -0
- package/dist/web/assets/material-theme-lighter-B0m2ddpp.js.gz +0 -0
- package/dist/web/assets/material-theme-ocean-CyktbL80.js.br +0 -0
- package/dist/web/assets/material-theme-ocean-CyktbL80.js.gz +0 -0
- package/dist/web/assets/material-theme-palenight-Csfq5Kiy.js.br +0 -0
- package/dist/web/assets/material-theme-palenight-Csfq5Kiy.js.gz +0 -0
- package/dist/web/assets/mathematica-DTrFuWx2.js.br +0 -0
- package/dist/web/assets/mathematica-DTrFuWx2.js.gz +0 -0
- package/dist/web/assets/matlab-D7o27uSR.js.br +0 -0
- package/dist/web/assets/matlab-D7o27uSR.js.gz +0 -0
- package/dist/web/assets/mbox-CNhZ1qSd.js.br +0 -0
- package/dist/web/assets/mbox-CNhZ1qSd.js.gz +0 -0
- package/dist/web/assets/mdc-BMNejdWA.js.br +0 -0
- package/dist/web/assets/mdc-BMNejdWA.js.gz +0 -0
- package/dist/web/assets/mdx-Cmh6b_Ma.js.br +0 -0
- package/dist/web/assets/mdx-Cmh6b_Ma.js.gz +0 -0
- package/dist/web/assets/memoryAuthority-B8YSN2MI.js +1 -0
- package/dist/web/assets/memoryAuthority-B8YSN2MI.js.br +0 -0
- package/dist/web/assets/memoryAuthority-B8YSN2MI.js.gz +0 -0
- package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css +1 -0
- package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css.br +0 -0
- package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css.gz +0 -0
- package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js +190 -0
- package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js.br +0 -0
- package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js.gz +0 -0
- package/dist/web/assets/mermaid-engine-AE7SfXFQ.js +2547 -0
- package/dist/web/assets/mermaid-engine-AE7SfXFQ.js.br +0 -0
- package/dist/web/assets/mermaid-engine-AE7SfXFQ.js.gz +0 -0
- package/dist/web/assets/mermaid-mWjccvbQ.js.br +0 -0
- package/dist/web/assets/mermaid-mWjccvbQ.js.gz +0 -0
- package/dist/web/assets/min-dark-CafNBF8u.js.br +0 -0
- package/dist/web/assets/min-dark-CafNBF8u.js.gz +0 -0
- package/dist/web/assets/min-light-CTRr51gU.js.br +0 -0
- package/dist/web/assets/min-light-CTRr51gU.js.gz +0 -0
- package/dist/web/assets/mipsasm-CKIfxQSi.js.br +0 -0
- package/dist/web/assets/mipsasm-CKIfxQSi.js.gz +0 -0
- package/dist/web/assets/mirc-CjQqDB4T.js.br +0 -0
- package/dist/web/assets/mirc-CjQqDB4T.js.gz +0 -0
- package/dist/web/assets/mllike-CXdrOF99.js.br +0 -0
- package/dist/web/assets/mllike-CXdrOF99.js.gz +0 -0
- package/dist/web/assets/modelica-Dc1JOy9r.js.br +0 -0
- package/dist/web/assets/modelica-Dc1JOy9r.js.gz +0 -0
- package/dist/web/assets/mojo-rZm6bMo-.js.br +0 -0
- package/dist/web/assets/mojo-rZm6bMo-.js.gz +0 -0
- package/dist/web/assets/monokai-D4h5O-jR.js.br +0 -0
- package/dist/web/assets/monokai-D4h5O-jR.js.gz +0 -0
- package/dist/web/assets/moonbit-_H4v1dQx.js.br +0 -0
- package/dist/web/assets/moonbit-_H4v1dQx.js.gz +0 -0
- package/dist/web/assets/move-IF9eRakj.js.br +0 -0
- package/dist/web/assets/move-IF9eRakj.js.gz +0 -0
- package/dist/web/assets/mscgen-BA5vi2Kp.js.br +0 -0
- package/dist/web/assets/mscgen-BA5vi2Kp.js.gz +0 -0
- package/dist/web/assets/mumps-BT43cFF4.js.br +0 -0
- package/dist/web/assets/mumps-BT43cFF4.js.gz +0 -0
- package/dist/web/assets/narrat-DRg8JJMk.js.br +0 -0
- package/dist/web/assets/narrat-DRg8JJMk.js.gz +0 -0
- package/dist/web/assets/nextflow-Zz6hmt5N.js.br +0 -0
- package/dist/web/assets/nextflow-Zz6hmt5N.js.gz +0 -0
- package/dist/web/assets/nextflow-groovy-BeH2EWoN.js.br +0 -0
- package/dist/web/assets/nextflow-groovy-BeH2EWoN.js.gz +0 -0
- package/dist/web/assets/nginx-BpAMiNFr.js.br +0 -0
- package/dist/web/assets/nginx-BpAMiNFr.js.gz +0 -0
- package/dist/web/assets/nginx-DdIZxoE0.js.br +0 -0
- package/dist/web/assets/nginx-DdIZxoE0.js.gz +0 -0
- package/dist/web/assets/night-owl-C39BiMTA.js.br +0 -0
- package/dist/web/assets/night-owl-C39BiMTA.js.gz +0 -0
- package/dist/web/assets/night-owl-light-CMTm3GFP.js.br +0 -0
- package/dist/web/assets/night-owl-light-CMTm3GFP.js.gz +0 -0
- package/dist/web/assets/nim-CVrawwO9.js.br +0 -0
- package/dist/web/assets/nim-CVrawwO9.js.gz +0 -0
- package/dist/web/assets/nix-CwoSXNpI.js.br +0 -0
- package/dist/web/assets/nix-CwoSXNpI.js.gz +0 -0
- package/dist/web/assets/nord-Ddv68eIx.js.br +0 -0
- package/dist/web/assets/nord-Ddv68eIx.js.gz +0 -0
- package/dist/web/assets/nsis-LdVXkNf5.js.br +0 -0
- package/dist/web/assets/nsis-LdVXkNf5.js.gz +0 -0
- package/dist/web/assets/ntriples-BfvgReVJ.js.br +0 -0
- package/dist/web/assets/ntriples-BfvgReVJ.js.gz +0 -0
- package/dist/web/assets/nushell-Cz2AlsmD.js.br +0 -0
- package/dist/web/assets/nushell-Cz2AlsmD.js.gz +0 -0
- package/dist/web/assets/objective-c-DXmwc3jG.js.br +0 -0
- package/dist/web/assets/objective-c-DXmwc3jG.js.gz +0 -0
- package/dist/web/assets/objective-cpp-CLxacb5B.js.br +0 -0
- package/dist/web/assets/objective-cpp-CLxacb5B.js.gz +0 -0
- package/dist/web/assets/ocaml-C0hk2d4L.js.br +0 -0
- package/dist/web/assets/ocaml-C0hk2d4L.js.gz +0 -0
- package/dist/web/assets/octave-Ck1zUtKM.js.br +0 -0
- package/dist/web/assets/octave-Ck1zUtKM.js.gz +0 -0
- package/dist/web/assets/odin-BBf5iR-q.js.br +0 -0
- package/dist/web/assets/odin-BBf5iR-q.js.gz +0 -0
- package/dist/web/assets/one-dark-pro-DVMEJ2y_.js.br +0 -0
- package/dist/web/assets/one-dark-pro-DVMEJ2y_.js.gz +0 -0
- package/dist/web/assets/one-light-C3Wv6jpd.js.br +0 -0
- package/dist/web/assets/one-light-C3Wv6jpd.js.gz +0 -0
- package/dist/web/assets/openscad-C4EeE6gA.js.br +0 -0
- package/dist/web/assets/openscad-C4EeE6gA.js.gz +0 -0
- package/dist/web/assets/ordinal-Cboi1Yqb.js.br +0 -0
- package/dist/web/assets/ordinal-Cboi1Yqb.js.gz +0 -0
- package/dist/web/assets/oz-BzwKVEFT.js.br +0 -0
- package/dist/web/assets/oz-BzwKVEFT.js.gz +0 -0
- package/dist/web/assets/packs-Bee69jWU.js +1 -0
- package/dist/web/assets/packs-Bee69jWU.js.br +0 -0
- package/dist/web/assets/packs-Bee69jWU.js.gz +0 -0
- package/dist/web/assets/pascal--L3eBynH.js.br +0 -0
- package/dist/web/assets/pascal--L3eBynH.js.gz +0 -0
- package/dist/web/assets/pascal-D93ZcfNL.js.br +0 -0
- package/dist/web/assets/pascal-D93ZcfNL.js.gz +0 -0
- package/dist/web/assets/pdf-CIFzrehN.js +13 -0
- package/dist/web/assets/pdf-CIFzrehN.js.br +0 -0
- package/dist/web/assets/pdf-CIFzrehN.js.gz +0 -0
- package/dist/web/assets/perl-C0TMdlhV.js.br +0 -0
- package/dist/web/assets/perl-C0TMdlhV.js.gz +0 -0
- package/dist/web/assets/perl-CdXCOZ3F.js.br +0 -0
- package/dist/web/assets/perl-CdXCOZ3F.js.gz +0 -0
- package/dist/web/assets/php-Dhbhpdrm.js.br +0 -0
- package/dist/web/assets/php-Dhbhpdrm.js.gz +0 -0
- package/dist/web/assets/pie-DJOJsNN1.js +1 -0
- package/dist/web/assets/pie-DJOJsNN1.js.br +0 -0
- package/dist/web/assets/pie-DJOJsNN1.js.gz +0 -0
- package/dist/web/assets/pig-CevX1Tat.js.br +0 -0
- package/dist/web/assets/pig-CevX1Tat.js.gz +0 -0
- package/dist/web/assets/pkl-u5AG7uiY.js.br +0 -0
- package/dist/web/assets/pkl-u5AG7uiY.js.gz +0 -0
- package/dist/web/assets/plastic-3e1v2bzS.js.br +0 -0
- package/dist/web/assets/plastic-3e1v2bzS.js.gz +0 -0
- package/dist/web/assets/plsql-ChMvpjG-.js.br +0 -0
- package/dist/web/assets/plsql-ChMvpjG-.js.gz +0 -0
- package/dist/web/assets/po-BTJTHyun.js.br +0 -0
- package/dist/web/assets/po-BTJTHyun.js.gz +0 -0
- package/dist/web/assets/poimandres-CS3Unz2-.js.br +0 -0
- package/dist/web/assets/poimandres-CS3Unz2-.js.gz +0 -0
- package/dist/web/assets/polar-C0HS_06l.js.br +0 -0
- package/dist/web/assets/polar-C0HS_06l.js.gz +0 -0
- package/dist/web/assets/postcss-CXtECtnM.js.br +0 -0
- package/dist/web/assets/postcss-CXtECtnM.js.gz +0 -0
- package/dist/web/assets/powerquery-CEu0bR-o.js.br +0 -0
- package/dist/web/assets/powerquery-CEu0bR-o.js.gz +0 -0
- package/dist/web/assets/powershell-CFHJl5sT.js.br +0 -0
- package/dist/web/assets/powershell-CFHJl5sT.js.gz +0 -0
- package/dist/web/assets/powershell-Dpen1YoG.js.br +0 -0
- package/dist/web/assets/powershell-Dpen1YoG.js.gz +0 -0
- package/dist/web/assets/prisma-Dd19v3D-.js.br +0 -0
- package/dist/web/assets/prisma-Dd19v3D-.js.gz +0 -0
- package/dist/web/assets/prolog-CbFg5uaA.js.br +0 -0
- package/dist/web/assets/prolog-CbFg5uaA.js.gz +0 -0
- package/dist/web/assets/properties-C78fOPTZ.js.br +0 -0
- package/dist/web/assets/properties-C78fOPTZ.js.gz +0 -0
- package/dist/web/assets/proto-C7zT0LnQ.js.br +0 -0
- package/dist/web/assets/proto-C7zT0LnQ.js.gz +0 -0
- package/dist/web/assets/protobuf-ChK-085T.js.br +0 -0
- package/dist/web/assets/protobuf-ChK-085T.js.gz +0 -0
- package/dist/web/assets/pug-CGlum2m_.js.br +0 -0
- package/dist/web/assets/pug-CGlum2m_.js.gz +0 -0
- package/dist/web/assets/pug-DeIclll2.js.br +0 -0
- package/dist/web/assets/pug-DeIclll2.js.gz +0 -0
- package/dist/web/assets/puppet-BMWR74SV.js.br +0 -0
- package/dist/web/assets/puppet-BMWR74SV.js.gz +0 -0
- package/dist/web/assets/puppet-DMA9R1ak.js.br +0 -0
- package/dist/web/assets/puppet-DMA9R1ak.js.gz +0 -0
- package/dist/web/assets/purescript-CklMAg4u.js.br +0 -0
- package/dist/web/assets/purescript-CklMAg4u.js.gz +0 -0
- package/dist/web/assets/python-B6aJPvgy.js.br +0 -0
- package/dist/web/assets/python-B6aJPvgy.js.gz +0 -0
- package/dist/web/assets/python-BuPzkPfP.js.br +0 -0
- package/dist/web/assets/python-BuPzkPfP.js.gz +0 -0
- package/dist/web/assets/q-pXgVlZs6.js.br +0 -0
- package/dist/web/assets/q-pXgVlZs6.js.gz +0 -0
- package/dist/web/assets/qml-3beO22l8.js.br +0 -0
- package/dist/web/assets/qml-3beO22l8.js.gz +0 -0
- package/dist/web/assets/qmldir-C8lEn-DE.js.br +0 -0
- package/dist/web/assets/qmldir-C8lEn-DE.js.gz +0 -0
- package/dist/web/assets/qss-IeuSbFQv.js.br +0 -0
- package/dist/web/assets/qss-IeuSbFQv.js.gz +0 -0
- package/dist/web/assets/r-B6wPVr8A.js.br +0 -0
- package/dist/web/assets/r-B6wPVr8A.js.gz +0 -0
- package/dist/web/assets/r-Dspwwk_N.js.br +0 -0
- package/dist/web/assets/r-Dspwwk_N.js.gz +0 -0
- package/dist/web/assets/racket-BqYA7rlc.js.br +0 -0
- package/dist/web/assets/racket-BqYA7rlc.js.gz +0 -0
- package/dist/web/assets/raku-DXvB9xmW.js.br +0 -0
- package/dist/web/assets/raku-DXvB9xmW.js.gz +0 -0
- package/dist/web/assets/razor-Uh8Bk_45.js.br +0 -0
- package/dist/web/assets/razor-Uh8Bk_45.js.gz +0 -0
- package/dist/web/assets/red-bN70gL4F.js.br +0 -0
- package/dist/web/assets/red-bN70gL4F.js.gz +0 -0
- package/dist/web/assets/reg-C-SQnVFl.js.br +0 -0
- package/dist/web/assets/reg-C-SQnVFl.js.gz +0 -0
- package/dist/web/assets/regexp-CDVJQ6XC.js.br +0 -0
- package/dist/web/assets/regexp-CDVJQ6XC.js.gz +0 -0
- package/dist/web/assets/rel-C3B-1QV4.js.br +0 -0
- package/dist/web/assets/rel-C3B-1QV4.js.gz +0 -0
- package/dist/web/assets/riscv-BM1_JUlF.js.br +0 -0
- package/dist/web/assets/riscv-BM1_JUlF.js.gz +0 -0
- package/dist/web/assets/ron-D8l8udqQ.js.br +0 -0
- package/dist/web/assets/ron-D8l8udqQ.js.gz +0 -0
- package/dist/web/assets/rose-pine-dawn-DHQR4-dF.js.br +0 -0
- package/dist/web/assets/rose-pine-dawn-DHQR4-dF.js.gz +0 -0
- package/dist/web/assets/rose-pine-moon-D4_iv3hh.js.br +0 -0
- package/dist/web/assets/rose-pine-moon-D4_iv3hh.js.gz +0 -0
- package/dist/web/assets/rose-pine-qdsjHGoJ.js.br +0 -0
- package/dist/web/assets/rose-pine-qdsjHGoJ.js.gz +0 -0
- package/dist/web/assets/rosmsg-BJDFO7_C.js.br +0 -0
- package/dist/web/assets/rosmsg-BJDFO7_C.js.gz +0 -0
- package/dist/web/assets/rpm-CTu-6PCP.js.br +0 -0
- package/dist/web/assets/rpm-CTu-6PCP.js.gz +0 -0
- package/dist/web/assets/rst-BrH8l1NY.js.br +0 -0
- package/dist/web/assets/rst-BrH8l1NY.js.gz +0 -0
- package/dist/web/assets/ruby-B2Rjki9n.js.br +0 -0
- package/dist/web/assets/ruby-B2Rjki9n.js.gz +0 -0
- package/dist/web/assets/ruby-Dw2BHqvy.js.br +0 -0
- package/dist/web/assets/ruby-Dw2BHqvy.js.gz +0 -0
- package/dist/web/assets/rust-B1yitclQ.js.br +0 -0
- package/dist/web/assets/rust-B1yitclQ.js.gz +0 -0
- package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js +1 -0
- package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js.br +0 -0
- package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js.gz +0 -0
- package/dist/web/assets/sas-B4kiWyti.js.br +0 -0
- package/dist/web/assets/sas-B4kiWyti.js.gz +0 -0
- package/dist/web/assets/sas-cz2c8ADy.js.br +0 -0
- package/dist/web/assets/sas-cz2c8ADy.js.gz +0 -0
- package/dist/web/assets/sass-Cj5Yp3dK.js.br +0 -0
- package/dist/web/assets/sass-Cj5Yp3dK.js.gz +0 -0
- package/dist/web/assets/scala-C151Ov-r.js.br +0 -0
- package/dist/web/assets/scala-C151Ov-r.js.gz +0 -0
- package/dist/web/assets/scheme-C41bIUwD.js.br +0 -0
- package/dist/web/assets/scheme-C41bIUwD.js.gz +0 -0
- package/dist/web/assets/scheme-C98Dy4si.js.br +0 -0
- package/dist/web/assets/scheme-C98Dy4si.js.gz +0 -0
- package/dist/web/assets/scss-OYdSNvt2.js.br +0 -0
- package/dist/web/assets/scss-OYdSNvt2.js.gz +0 -0
- package/dist/web/assets/sdbl-DVxCFoDh.js.br +0 -0
- package/dist/web/assets/sdbl-DVxCFoDh.js.gz +0 -0
- package/dist/web/assets/shaderlab-Dg9Lc6iA.js.br +0 -0
- package/dist/web/assets/shaderlab-Dg9Lc6iA.js.gz +0 -0
- package/dist/web/assets/shell-CjFT_Tl9.js.br +0 -0
- package/dist/web/assets/shell-CjFT_Tl9.js.gz +0 -0
- package/dist/web/assets/shellscript-Yzrsuije.js.br +0 -0
- package/dist/web/assets/shellscript-Yzrsuije.js.gz +0 -0
- package/dist/web/assets/shellsession-BADoaaVG.js.br +0 -0
- package/dist/web/assets/shellsession-BADoaaVG.js.gz +0 -0
- package/dist/web/assets/sieve-C3Gn_uJK.js.br +0 -0
- package/dist/web/assets/sieve-C3Gn_uJK.js.gz +0 -0
- package/dist/web/assets/simple-mode-GW_nhZxv.js.br +0 -0
- package/dist/web/assets/simple-mode-GW_nhZxv.js.gz +0 -0
- package/dist/web/assets/slack-dark-BthQWCQV.js.br +0 -0
- package/dist/web/assets/slack-dark-BthQWCQV.js.gz +0 -0
- package/dist/web/assets/slack-ochin-DqwNpetd.js.br +0 -0
- package/dist/web/assets/slack-ochin-DqwNpetd.js.gz +0 -0
- package/dist/web/assets/smalltalk-BERRCDM3.js.br +0 -0
- package/dist/web/assets/smalltalk-BERRCDM3.js.gz +0 -0
- package/dist/web/assets/smalltalk-CnHTOXQT.js.br +0 -0
- package/dist/web/assets/smalltalk-CnHTOXQT.js.gz +0 -0
- package/dist/web/assets/snazzy-light-Bw305WKR.js.br +0 -0
- package/dist/web/assets/snazzy-light-Bw305WKR.js.gz +0 -0
- package/dist/web/assets/solarized-dark-DXbdFlpD.js.br +0 -0
- package/dist/web/assets/solarized-dark-DXbdFlpD.js.gz +0 -0
- package/dist/web/assets/solarized-light-L9t79GZl.js.br +0 -0
- package/dist/web/assets/solarized-light-L9t79GZl.js.gz +0 -0
- package/dist/web/assets/solidity-rGO070M0.js.br +0 -0
- package/dist/web/assets/solidity-rGO070M0.js.gz +0 -0
- package/dist/web/assets/solr-DehyRSwq.js.br +0 -0
- package/dist/web/assets/solr-DehyRSwq.js.gz +0 -0
- package/dist/web/assets/soy-Brmx7dQM.js.br +0 -0
- package/dist/web/assets/soy-Brmx7dQM.js.gz +0 -0
- package/dist/web/assets/spaces-wH3o95f_.js +1 -0
- package/dist/web/assets/spaces-wH3o95f_.js.br +0 -0
- package/dist/web/assets/spaces-wH3o95f_.js.gz +0 -0
- package/dist/web/assets/sparql-DkYu6x3z.js.br +0 -0
- package/dist/web/assets/sparql-DkYu6x3z.js.gz +0 -0
- package/dist/web/assets/sparql-rVzFXLq3.js.br +0 -0
- package/dist/web/assets/sparql-rVzFXLq3.js.gz +0 -0
- package/dist/web/assets/splunk-BtCnVYZw.js.br +0 -0
- package/dist/web/assets/splunk-BtCnVYZw.js.gz +0 -0
- package/dist/web/assets/spreadsheet-BCZA_wO0.js.br +0 -0
- package/dist/web/assets/spreadsheet-BCZA_wO0.js.gz +0 -0
- package/dist/web/assets/sql-BLtJtn59.js.br +0 -0
- package/dist/web/assets/sql-BLtJtn59.js.gz +0 -0
- package/dist/web/assets/sql-D0XecflT.js.br +0 -0
- package/dist/web/assets/sql-D0XecflT.js.gz +0 -0
- package/dist/web/assets/ssh-config-_ykCGR6B.js.br +0 -0
- package/dist/web/assets/ssh-config-_ykCGR6B.js.gz +0 -0
- package/dist/web/assets/stata-BH5u7GGu.js.br +0 -0
- package/dist/web/assets/stata-BH5u7GGu.js.gz +0 -0
- package/dist/web/assets/stex-C3f8Ysf7.js.br +0 -0
- package/dist/web/assets/stex-C3f8Ysf7.js.gz +0 -0
- package/dist/web/assets/stylus-B533Al4x.js.br +0 -0
- package/dist/web/assets/stylus-B533Al4x.js.gz +0 -0
- package/dist/web/assets/stylus-BEDo0Tqx.js.br +0 -0
- package/dist/web/assets/stylus-BEDo0Tqx.js.gz +0 -0
- package/dist/web/assets/surrealql-Bq5Q-fJD.js.br +0 -0
- package/dist/web/assets/surrealql-Bq5Q-fJD.js.gz +0 -0
- package/dist/web/assets/svelte-C_ipcX3V.js.br +0 -0
- package/dist/web/assets/svelte-C_ipcX3V.js.gz +0 -0
- package/dist/web/assets/swift-BzpIVaGY.js.br +0 -0
- package/dist/web/assets/swift-BzpIVaGY.js.gz +0 -0
- package/dist/web/assets/swift-D82vCrfD.js.br +0 -0
- package/dist/web/assets/swift-D82vCrfD.js.gz +0 -0
- package/dist/web/assets/synthwave-84-CbfX1IO0.js.br +0 -0
- package/dist/web/assets/synthwave-84-CbfX1IO0.js.gz +0 -0
- package/dist/web/assets/system-verilog-CnnmHF94.js.br +0 -0
- package/dist/web/assets/system-verilog-CnnmHF94.js.gz +0 -0
- package/dist/web/assets/systemd-4A_iFExJ.js.br +0 -0
- package/dist/web/assets/systemd-4A_iFExJ.js.gz +0 -0
- package/dist/web/assets/talonscript-CkByrt1z.js.br +0 -0
- package/dist/web/assets/talonscript-CkByrt1z.js.gz +0 -0
- package/dist/web/assets/tasl-QIJgUcNo.js.br +0 -0
- package/dist/web/assets/tasl-QIJgUcNo.js.gz +0 -0
- package/dist/web/assets/tcl-DVfN8rqt.js.br +0 -0
- package/dist/web/assets/tcl-DVfN8rqt.js.gz +0 -0
- package/dist/web/assets/tcl-dwOrl1Do.js.br +0 -0
- package/dist/web/assets/tcl-dwOrl1Do.js.gz +0 -0
- package/dist/web/assets/templ-P3uqSqPl.js.br +0 -0
- package/dist/web/assets/templ-P3uqSqPl.js.gz +0 -0
- package/dist/web/assets/terraform-BETggiCN.js.br +0 -0
- package/dist/web/assets/terraform-BETggiCN.js.gz +0 -0
- package/dist/web/assets/tex-idrVyKtj.js.br +0 -0
- package/dist/web/assets/tex-idrVyKtj.js.gz +0 -0
- package/dist/web/assets/textile-CnDTJFAw.js.br +0 -0
- package/dist/web/assets/textile-CnDTJFAw.js.gz +0 -0
- package/dist/web/assets/theme-DVIt3W-5.js +1 -0
- package/dist/web/assets/theme-DVIt3W-5.js.br +0 -0
- package/dist/web/assets/theme-DVIt3W-5.js.gz +0 -0
- package/dist/web/assets/tiddlywiki-DO-Gjzrf.js.br +0 -0
- package/dist/web/assets/tiddlywiki-DO-Gjzrf.js.gz +0 -0
- package/dist/web/assets/tiki-DGYXhP31.js.br +0 -0
- package/dist/web/assets/tiki-DGYXhP31.js.gz +0 -0
- package/dist/web/assets/tokyo-night-hegEt444.js.br +0 -0
- package/dist/web/assets/tokyo-night-hegEt444.js.gz +0 -0
- package/dist/web/assets/toml-Bm5Em-hy.js.br +0 -0
- package/dist/web/assets/toml-Bm5Em-hy.js.gz +0 -0
- package/dist/web/assets/toml-vGWfd6FD.js.br +0 -0
- package/dist/web/assets/toml-vGWfd6FD.js.gz +0 -0
- package/dist/web/assets/troff-wAsdV37c.js.br +0 -0
- package/dist/web/assets/troff-wAsdV37c.js.gz +0 -0
- package/dist/web/assets/ts-tags-zn1MmPIZ.js.br +0 -0
- package/dist/web/assets/ts-tags-zn1MmPIZ.js.gz +0 -0
- package/dist/web/assets/tsv-B_m7g4N7.js.br +0 -0
- package/dist/web/assets/tsv-B_m7g4N7.js.gz +0 -0
- package/dist/web/assets/tsx-COt5Ahok.js.br +0 -0
- package/dist/web/assets/tsx-COt5Ahok.js.gz +0 -0
- package/dist/web/assets/ttcn-CfJYG6tj.js.br +0 -0
- package/dist/web/assets/ttcn-CfJYG6tj.js.gz +0 -0
- package/dist/web/assets/ttcn-cfg-B9xdYoR4.js.br +0 -0
- package/dist/web/assets/ttcn-cfg-B9xdYoR4.js.gz +0 -0
- package/dist/web/assets/turtle-B1tBg_DP.js.br +0 -0
- package/dist/web/assets/turtle-B1tBg_DP.js.gz +0 -0
- package/dist/web/assets/turtle-BsS91CYL.js.br +0 -0
- package/dist/web/assets/turtle-BsS91CYL.js.gz +0 -0
- package/dist/web/assets/twig-DNn4PbVi.js.br +0 -0
- package/dist/web/assets/twig-DNn4PbVi.js.gz +0 -0
- package/dist/web/assets/typescript-BPQ3VLAy.js.br +0 -0
- package/dist/web/assets/typescript-BPQ3VLAy.js.gz +0 -0
- package/dist/web/assets/typespec-BGHnOYBU.js.br +0 -0
- package/dist/web/assets/typespec-BGHnOYBU.js.gz +0 -0
- package/dist/web/assets/typst-DHCkPAjA.js.br +0 -0
- package/dist/web/assets/typst-DHCkPAjA.js.gz +0 -0
- package/dist/web/assets/uiZoom-CfR9h3Dy.js +1 -0
- package/dist/web/assets/uiZoom-CfR9h3Dy.js.br +0 -0
- package/dist/web/assets/uiZoom-CfR9h3Dy.js.gz +0 -0
- package/dist/web/assets/v-BcVCzyr7.js.br +0 -0
- package/dist/web/assets/v-BcVCzyr7.js.gz +0 -0
- package/dist/web/assets/v4-Dnyct6Ft.js +1 -0
- package/dist/web/assets/v4-Dnyct6Ft.js.br +0 -0
- package/dist/web/assets/v4-Dnyct6Ft.js.gz +0 -0
- package/dist/web/assets/vala-CsfeWuGM.js.br +0 -0
- package/dist/web/assets/vala-CsfeWuGM.js.gz +0 -0
- package/dist/web/assets/vb-CmGdzxic.js.br +0 -0
- package/dist/web/assets/vb-CmGdzxic.js.gz +0 -0
- package/dist/web/assets/vb-D17OF-Vu.js.br +0 -0
- package/dist/web/assets/vb-D17OF-Vu.js.gz +0 -0
- package/dist/web/assets/vbscript-BuJXcnF6.js.br +0 -0
- package/dist/web/assets/vbscript-BuJXcnF6.js.gz +0 -0
- package/dist/web/assets/velocity-D8B20fx6.js.br +0 -0
- package/dist/web/assets/velocity-D8B20fx6.js.gz +0 -0
- package/dist/web/assets/vendor-react-BqVzR-It.js +61 -0
- package/dist/web/assets/vendor-react-BqVzR-It.js.br +0 -0
- package/dist/web/assets/vendor-react-BqVzR-It.js.gz +0 -0
- package/dist/web/assets/venn.esm-D6tdiC58.js +7 -0
- package/dist/web/assets/venn.esm-D6tdiC58.js.br +0 -0
- package/dist/web/assets/venn.esm-D6tdiC58.js.gz +0 -0
- package/dist/web/assets/verilog-BQ8w6xss.js.br +0 -0
- package/dist/web/assets/verilog-BQ8w6xss.js.gz +0 -0
- package/dist/web/assets/verilog-C6RDOZhf.js.br +0 -0
- package/dist/web/assets/verilog-C6RDOZhf.js.gz +0 -0
- package/dist/web/assets/vesper-DU1UobuO.js.br +0 -0
- package/dist/web/assets/vesper-DU1UobuO.js.gz +0 -0
- package/dist/web/assets/vhdl-CeAyd5Ju.js.br +0 -0
- package/dist/web/assets/vhdl-CeAyd5Ju.js.gz +0 -0
- package/dist/web/assets/vhdl-lSbBsy5d.js.br +0 -0
- package/dist/web/assets/vhdl-lSbBsy5d.js.gz +0 -0
- package/dist/web/assets/viml-CJc9bBzg.js.br +0 -0
- package/dist/web/assets/viml-CJc9bBzg.js.gz +0 -0
- package/dist/web/assets/vitesse-black-Bkuqu6BP.js.br +0 -0
- package/dist/web/assets/vitesse-black-Bkuqu6BP.js.gz +0 -0
- package/dist/web/assets/vitesse-dark-D0r3Knsf.js.br +0 -0
- package/dist/web/assets/vitesse-dark-D0r3Knsf.js.gz +0 -0
- package/dist/web/assets/vitesse-light-CVO1_9PV.js.br +0 -0
- package/dist/web/assets/vitesse-light-CVO1_9PV.js.gz +0 -0
- package/dist/web/assets/vue-DN_0RTcg.js.br +0 -0
- package/dist/web/assets/vue-DN_0RTcg.js.gz +0 -0
- package/dist/web/assets/vue-html-AaS7Mt5G.js.br +0 -0
- package/dist/web/assets/vue-html-AaS7Mt5G.js.gz +0 -0
- package/dist/web/assets/vue-vine-CQOfvN7w.js.br +0 -0
- package/dist/web/assets/vue-vine-CQOfvN7w.js.gz +0 -0
- package/dist/web/assets/vyper-CDx5xZoG.js.br +0 -0
- package/dist/web/assets/vyper-CDx5xZoG.js.gz +0 -0
- package/dist/web/assets/{wardley-L42UT6IY-Bp3q2izt.js → wardley-L42UT6IY-CptWIPkK.js} +1 -1
- package/dist/web/assets/wardley-L42UT6IY-CptWIPkK.js.br +0 -0
- package/dist/web/assets/wardley-L42UT6IY-CptWIPkK.js.gz +0 -0
- package/dist/web/assets/wasm-CG6Dc4jp.js.br +0 -0
- package/dist/web/assets/wasm-CG6Dc4jp.js.gz +0 -0
- package/dist/web/assets/wasm-MzD3tlZU.js.br +0 -0
- package/dist/web/assets/wasm-MzD3tlZU.js.gz +0 -0
- package/dist/web/assets/webidl-ZXfAyPTL.js.br +0 -0
- package/dist/web/assets/webidl-ZXfAyPTL.js.gz +0 -0
- package/dist/web/assets/wenyan-BV7otONQ.js.br +0 -0
- package/dist/web/assets/wenyan-BV7otONQ.js.gz +0 -0
- package/dist/web/assets/wgsl-Dx-B1_4e.js.br +0 -0
- package/dist/web/assets/wgsl-Dx-B1_4e.js.gz +0 -0
- package/dist/web/assets/wikitext-BhOHFoWU.js.br +0 -0
- package/dist/web/assets/wikitext-BhOHFoWU.js.gz +0 -0
- package/dist/web/assets/wit-5i3qLPDT.js.br +0 -0
- package/dist/web/assets/wit-5i3qLPDT.js.gz +0 -0
- package/dist/web/assets/wolfram-lXgVvXCa.js.br +0 -0
- package/dist/web/assets/wolfram-lXgVvXCa.js.gz +0 -0
- package/dist/web/assets/xml-sdJ4AIDG.js.br +0 -0
- package/dist/web/assets/xml-sdJ4AIDG.js.gz +0 -0
- package/dist/web/assets/xquery-DzFWVndE.js.br +0 -0
- package/dist/web/assets/xquery-DzFWVndE.js.gz +0 -0
- package/dist/web/assets/xsl-CtQFsRM5.js.br +0 -0
- package/dist/web/assets/xsl-CtQFsRM5.js.gz +0 -0
- package/dist/web/assets/yacas-BJ4BC0dw.js.br +0 -0
- package/dist/web/assets/yacas-BJ4BC0dw.js.gz +0 -0
- package/dist/web/assets/yaml-Buea-lGh.js.br +0 -0
- package/dist/web/assets/yaml-Buea-lGh.js.gz +0 -0
- package/dist/web/assets/z80-Hz9HOZM7.js.br +0 -0
- package/dist/web/assets/z80-Hz9HOZM7.js.gz +0 -0
- package/dist/web/assets/zenscript-DVFEvuxE.js.br +0 -0
- package/dist/web/assets/zenscript-DVFEvuxE.js.gz +0 -0
- package/dist/web/assets/zig-VOosw3JB.js.br +0 -0
- package/dist/web/assets/zig-VOosw3JB.js.gz +0 -0
- package/dist/web/index.html +12 -17
- package/dist/web/index.html.br +0 -0
- package/dist/web/index.html.gz +0 -0
- package/dist/web/pdfjs/pdf.worker.min.mjs +1 -1
- package/dist/web/pdfjs/pdf.worker.min.mjs.br +0 -0
- package/dist/web/pdfjs/pdf.worker.min.mjs.gz +0 -0
- package/dist/web/theme-boot.js +20 -0
- package/dist/web/theme-boot.js.br +0 -0
- package/dist/web/theme-boot.js.gz +0 -0
- package/native/auth-native/index.cjs +6 -0
- package/native/auth-native/index.d.ts +14 -0
- package/native/auth-native/package.json +1 -2
- package/native/auth-native/prebuilds/darwin-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/darwin-x64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
- package/package.json +1 -1
- package/dist/web/assets/AppErrorBoundary-B5Fc4f6-.js +0 -1
- package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +0 -1
- package/dist/web/assets/arc-DGB9OVgQ.js +0 -1
- package/dist/web/assets/architectureDiagram-3BPJPVTR-glnQCMub.js +0 -36
- package/dist/web/assets/blockDiagram-GPEHLZMM-bM0tnGby.js +0 -132
- package/dist/web/assets/c4Diagram-AAUBKEIU-DMf_rTtt.js +0 -10
- package/dist/web/assets/channel-Cj8SKJ38.js +0 -1
- package/dist/web/assets/chunk-2J33WTMH-mTccJ3tW.js +0 -1
- package/dist/web/assets/chunk-4BX2VUAB-DhqPYMjY.js +0 -1
- package/dist/web/assets/chunk-55IACEB6-BujrYRoO.js +0 -1
- package/dist/web/assets/chunk-727SXJPM-ciMmSI4G.js +0 -206
- package/dist/web/assets/chunk-AQP2D5EJ-CZW9pKTc.js +0 -231
- package/dist/web/assets/chunk-FMBD7UC4-hdALNnnU.js +0 -15
- package/dist/web/assets/chunk-ND2GUHAM-CgKyqUdb.js +0 -1
- package/dist/web/assets/chunk-QZHKN3VN-B2mmUz_E.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +0 -1
- package/dist/web/assets/client-ClWQBErG.js +0 -3
- package/dist/web/assets/connection-C0J3BPgk.js +0 -1
- package/dist/web/assets/cose-bilkent-S5V4N54A-UV3uPjkK.js +0 -1
- package/dist/web/assets/dagre-BM42HDAG-Zjy-gQ6C.js +0 -4
- package/dist/web/assets/diagram-2AECGRRQ-DL-kilIf.js +0 -43
- package/dist/web/assets/diagram-5GNKFQAL-CjB_xR5B.js +0 -10
- package/dist/web/assets/diagram-KO2AKTUF-CjN4i3b9.js +0 -3
- package/dist/web/assets/diagram-LMA3HP47-CPCAMndo.js +0 -24
- package/dist/web/assets/diagram-OG6HWLK6-DVeBWBKd.js +0 -24
- package/dist/web/assets/erDiagram-TEJ5UH35-CHKzBHrr.js +0 -85
- package/dist/web/assets/export-CXoWon32.js +0 -2
- package/dist/web/assets/flowDiagram-I6XJVG4X-C5rQa2pq.js +0 -162
- package/dist/web/assets/ganttDiagram-6RSMTGT7-BrLjEsNJ.js +0 -292
- package/dist/web/assets/gitGraphDiagram-PVQCEYII-3DRR5VZj.js +0 -106
- package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +0 -1
- package/dist/web/assets/index-2Vx5mHRn.js +0 -1
- package/dist/web/assets/index-B1UXw2C9.js +0 -1
- package/dist/web/assets/index-BJxtlf4P.js +0 -309
- package/dist/web/assets/index-BY7jPurv.js +0 -1
- package/dist/web/assets/index-Bq79v-Sa.js +0 -1
- package/dist/web/assets/index-BqD3iTIl.js +0 -1
- package/dist/web/assets/index-C62wjCF_.js +0 -1
- package/dist/web/assets/index-CG9e6lgq.js +0 -1
- package/dist/web/assets/index-CS4xJLZV.js +0 -1
- package/dist/web/assets/index-CprdjRRk.js +0 -13
- package/dist/web/assets/index-CypTtrCB.js +0 -1
- package/dist/web/assets/index-DDJQGcUL.js +0 -1
- package/dist/web/assets/index-DLWzxUOO.js +0 -1
- package/dist/web/assets/index-DQxkxZmn.js +0 -7
- package/dist/web/assets/index-De_LkTZx.js +0 -1
- package/dist/web/assets/index-DpcWEDhW.js +0 -1
- package/dist/web/assets/index-Dqq1RDP4.js +0 -1
- package/dist/web/assets/index-H1uMvIoa.css +0 -1
- package/dist/web/assets/index-ICHWJ2SM.js +0 -1
- package/dist/web/assets/index-O5fSd569.js +0 -229
- package/dist/web/assets/index-odjtqLLS.js +0 -1
- package/dist/web/assets/index-v_yAQ0Am.js +0 -1
- package/dist/web/assets/infoDiagram-5YYISTIA-CCwV4Z0v.js +0 -2
- package/dist/web/assets/ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js +0 -70
- package/dist/web/assets/journeyDiagram-JHISSGLW-Dc6WqniQ.js +0 -139
- package/dist/web/assets/kanban-definition-UN3LZRKU-DVUqULOS.js +0 -89
- package/dist/web/assets/linear-d6rWsNOU.js +0 -1
- package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +0 -1
- package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +0 -642
- package/dist/web/assets/mindmap-definition-RKZ34NQL-_JHAkhHL.js +0 -96
- package/dist/web/assets/navViewState-DaCMIYWA.js +0 -1
- package/dist/web/assets/pdf-C-olXVQ4.js +0 -12
- package/dist/web/assets/pieDiagram-4H26LBE5-BlhlygGy.js +0 -30
- package/dist/web/assets/quadrantDiagram-W4KKPZXB-jn6R_C0S.js +0 -7
- package/dist/web/assets/requirementDiagram-4Y6WPE33-B9fXCHBr.js +0 -84
- package/dist/web/assets/sankeyDiagram-5OEKKPKP-fPJwIxkl.js +0 -40
- package/dist/web/assets/sequenceDiagram-3UESZ5HK-1v1DTNGt.js +0 -162
- package/dist/web/assets/spaces-CvL2DRZM.js +0 -1
- package/dist/web/assets/stateDiagram-AJRCARHV-CEc_PLov.js +0 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +0 -1
- package/dist/web/assets/theme-LRSmy8mD.js +0 -1
- package/dist/web/assets/timeline-definition-PNZ67QCA-CEjhuitj.js +0 -120
- package/dist/web/assets/vennDiagram-CIIHVFJN-CActt9h9.js +0 -34
- package/dist/web/assets/wardleyDiagram-YWT4CUSO-C_zutiQ2.js +0 -78
- package/dist/web/assets/xychartDiagram-2RQKCTM6-CRafvv33.js +0 -7
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import{r as x,j as e,b as no,a as Bt,L as _t,c as Et,u as uj}from"./vendor-react-BqVzR-It.js";import{ag as ao,ak as ps,gi as Nr,ah as pj,ae as Ms,ai as mj,af as xj,gj as Kf,gk as bn,gl as hj,gm as Da,gn as fj,go as bj,gp as gj,k as mt,$ as ss,gq as Fs,j as oe,p as aa,gr as vj,a6 as Uf,a8 as yj,a4 as Jo,h as Oe,u as je,s as io,f_ as ro,f$ as oo,d as Np,c as Sp,gs as kj,gt as jj,gu as Cp,A as _p,gv as wj,gw as Nj,gx as Ep,z as Tp,gy as Sj,gz as Cj,gA as _j,w as Mt,gB as ms,gC as Ej,gD as Tj,gE as Ij,ap as Pj,al as Aj,gF as $j,gG as Rj,gH as Lj,gI as Ip,gJ as Mj,r as gc,gK as Pp,gL as Hf,g as Oj,ad as zf,gM as Ap,gN as Dj,gO as Fj,gP as qj,a1 as Qf,gQ as Bj,gR as Gf,gS as Kj,ax as qs,gT as Uj,gU as Hj,gV as zj,gW as Qj,gX as Gj,gY as Wf,gZ as Wj,g_ as $p,g$ as vc,h0 as kd,h1 as jd,h2 as wd,ac as Vj,h3 as Vf,h4 as Yf,h5 as Jf,h6 as Yj,h7 as vn,h8 as Jj,h9 as Zf,ha as Zj,hb as Xj,hc as zi,hd as Zo,he as Rp,hf as Xf,hg as ew,hh as tw,hi as sw,hj as nw,hk as aw,hl as yc,hm as iw,hn as rw,ho as eb,ay as tb,hp as ow,hq as lw,hr as sb,hs as cw,ht as dw,aC as Nd,hu as Jn,hv as uw,hw as pw,hx as nb,hy as mw,hz as xw,b as Lp,fT as hw,g8 as fw,hA as bw,hB as gw,hC as vw,hD as yw,hE as Sd,hF as Cd,hG as Sr,hH as Cr,hI as ab,aB as _d,hJ as kw,au as ib,hK as An,hL as jw,hM as ww,hN as Nw,hO as rb,hP as Sw,hQ as Mp,hR as Op,hS as Js,hT as Dp,hU as Cw,hV as _w,hW as Ew,hX as Tw,hY as Iw,hZ as Pw,h_ as ob,h$ as Xo,i0 as Aw,aE as $w,i1 as Rw,i2 as Ed,i3 as Lw,i4 as Mw,i5 as Ow,i6 as Dw,i7 as Fw,i8 as qw,i9 as lb,ia as Bw,ib as Fp,ic as Kw,id as cb,t as qp,aA as db,ie as Uw,ig as el,ih as Hw,ii as zw,ij as Qw,ik as Gw,il as Ww,im as ub,io as Vw,ip as pb,iq as Yw,ir as mb,is as tl,it as Jw,iu as Zw,iv as Xw,iw as e0,ix as Td,iy as t0,iz as s0,iA as n0,iB as a0,iC as Ai,iD as i0,iE as r0,iF as xb,f as o0,a0 as l0,iG as c0,iH as d0,iI as u0,iJ as hb,M as Bp,aH as Kp,iK as p0,iL as m0,iM as x0,iN as h0,iO as f0,I as b0,aI as g0,iP as v0,iQ as y0}from"./index-BLi2nTxe.js";import{eu as Ze,aV as ge,ev as Id,by as et,C as Xe,ew as k0,ex as j0,ey as w0,ez as N0,eA as S0,bs as Je,eB as fb,eC as C0,eD as bb,eE as gb,eF as vb,eG as _0,eH as E0,eI as T0,eJ as yb,eK as is,eL as Ns,eM as _r,eN as I0,eO as Up,eP as P0,eQ as Er,eR as xa,eS as lo,eT as Bs,eU as A0,eV as sn,eW as $0,eX as Pd,eY as R0,eZ as kb,e_ as L0,e$ as Ad,f0 as Tr,f1 as ii,f2 as Ir,f3 as ft,f4 as jb,f5 as kc,f6 as M0,bz as nn,bw as co,f7 as jc,f8 as Cs,bW as Hp,f9 as zp,fa as Qp,bV as O0,fb as D0,fc as F0,fd as q0,fe as B0,ff as K0,fg as U0,fh as H0,fi as z0,fj as sl,fk as Q0,fl as G0,fm as W0,fn as nl,fo as V0,fp as Y0,fq as Gp,bQ as wb,bN as J0,bM as Z0,fr as wc,fs as X0,bR as eN,bT as tN,ft as sN,fu as nN,fv as Nb,fw as aN,fx as iN,s as Wp,fy as rN,fz as oN,fA as Vp,fB as lN,fC as Sb,fD as Cb,fE as yn,Q as $n,fF as cN,cD as _b,fG as Yp,fH as dN,fI as ha,fJ as uo,a_ as Nc,bY as At,dL as Eb,fK as $d,fL as uN,aZ as pN,fM as mN,dM as xN,fN as hN,fO as ia,fP as fN,aS as ra,fQ as fa,fR as Tb,a$ as bN,bq as Ib,fS as Pr,fT as Rd,fU as gN,fV as vN,fW as Jp,fX as Zp,fY as Sc,fZ as Cc,f_ as yN,f$ as po,g0 as ba,g1 as kN,g2 as jN,g3 as Xp,g4 as wN,g5 as Ld,g6 as _c,g7 as NN,bx as Rn,g8 as Pb,g9 as Ab,ga as SN,gb as CN,gc as _N,gd as EN,aU as TN,ge as IN,gf as $b,gg as PN,gh as AN,gi as $N,gj as Fa,gk as RN,gl as LN,gm as MN,gn as Ar,go as em,gp as $r,gq as ri,gr as ON,gs as gi,$ as Rb,a2 as Lb,u as Ks,gt as DN,gu as FN,gv as Mb,gw as Qi,gx as qN,gy as BN,dq as Ob,gz as Db,gA as Md,gB as ga,gC as KN,gD as UN,gE as HN,gF as tm,gG as zN,gH as QN,gI as sm,gJ as GN,gK as WN,gL as va,gM as VN,gN as YN,gO as Fb,gP as qb,cB as JN,bo as ZN,aR as Yt,gQ as al,gR as ya,gS as Od,gT as XN,gU as eS,gV as tS,gW as sS,cX as Dd,dr as nS,d6 as Bb,da as aS,dz as Kb,gX as iS,gY as Fd,cV as rS,aT as Ub,dn as $i,cP as nm,cC as oS,gZ as qd,g_ as Hb,g$ as lS,h0 as cS,h1 as Xn,h2 as Ec,h3 as il,h4 as cr,dp as $s,cS as Za,cL as jn,d1 as qa,dw as am,h5 as dS,h6 as oi,h7 as zb,h8 as vi,h9 as uS,ha as Qb,hb as pS,hc as mS,hd as xS,he as hS,hf as fS,hg as bS,hh as gS,hi as rl,hj as vS,hk as yS,hl as dr,hm as kS,hn as jS,br as wS,ho as NS,_ as SS,hp as Gb,hq as Gi,hr as im,hs as CS,dy as _S,ht as ES,dD as TS,dE as rm,dC as IS,hu as Wb,hv as PS,hw as AS,cA as $S,hx as RS,hy as LS,hz as MS,hA as OS,hB as DS,hC as FS,hD as qS,b9 as BS,hE as KS,hF as US,hG as Ba}from"./App-DCxEkgD4.js";import{hH as Bq}from"./App-DCxEkgD4.js";import{M as Vb,u as Yb,P as HS,a as zS,S as QS,W as GS,L as WS,s as VS,b as YS,p as JS,m as ZS,c as XS,d as e1,e as om,f as t1}from"./CapabilitiesPage-C4ggBXI7.js";import{u as D,f as mo,r as Nn,d as Bd}from"./index-C9DdZFNJ.js";import{k as s1,u as be,I as de,D as Rt,c as ka,A as xo,w as ho,y as Kd,r as fo,S as Us,d as ja,e as zs,B as Ud,C as li,E as n1,F as a1,G as lm,H as Ka,J as i1,K as Jb,L as r1,M as Zb,N as o1,O as Rr,a as Hd,z as l1,P as c1,Q as Xb,R as Tc,q as d1,s as u1,T as ls,U as p1,V as m1,W as x1,X as h1,Y as Wt,Z as f1,_ as eg,$ as b1,a0 as Ic,a1 as g1,a2 as v1,a3 as tg,a4 as y1,a5 as k1,a6 as j1,a7 as w1,a8 as N1}from"./connection-5XKg4sL2.js";import{T as Be,H as he,F as pe,j as ot,I as De,S as jt,u as Tt,a as Ln,e as Ft}from"./controls-C3UrNiBn.js";import{_ as Qe,S as Q,P as Ye,c as rs,C as He,I as Ce,l as Ea,Y as bo,Z as go,J as S1,K as C1,N as _1,O as E1,Q as T1,U as I1,b2 as P1,b3 as A1,b4 as $1,b5 as R1,V as L1,B as $e,a3 as it,a4 as lt,H as pt,e as Jt,b6 as zd,F as Sn,a7 as rt,D as Ht,as as Qs,T as Ot,b7 as sg,g as Ta,a as Ri,av as Qd,b8 as vo,b9 as M1,aw as Gt,ba as kt,bb as cm,bc as Gd,$ as xs,bd as un,be as O1,au as oa,bf as D1,b as F1,at as ng,u as dm,bg as ag,bh as ig,bi as wa,bj as q1,bk as B1,bl as K1,bm as U1,p as vt,bn as H1,bo as z1,M as Q1,bp as G1,bq as ol,br as W1,bs as Rs,bt as V1,bu as ea,bv as Y1,bw as J1,bx as Z1,by as X1}from"./mermaid-GHXKKRXX-DmcDxWiS.js";import{S as Me,c as Mn,d as Ia,a as eC}from"./SectionCard-CDWn1QiO.js";import{s as tC,v as rg,u as sC,B as nC,a as aC,g as iC,z as Lr,k as rC,D as Pc,i as um,m as oC,H as yo,I as yi,J as pm,K as lC,L as og,M as cC,N as Xa,O as Pa,P as Wd,Q as lg,S as mm,T as Vd,U as Yd,r as dC,p as uC,V as pC,W as Wi,X as mC,Y as xC,Z as hC,_ as fC,$ as bC,a0 as gC,a1 as vC,a2 as Jd}from"./theme-DVIt3W-5.js";import{d as Ac,g as yC,j as kC,w as xm,r as jC,h as wC}from"./export-BlURphmw.js";import{U as NC,V as SC,J as CC,b as _C,g as cg,f as EC,l as Zd,S as ki,R as TC,c as hm,k as dg,i as IC,h as PC,Q as AC,n as $C,y as $c,x as RC,v as LC,d as MC}from"./packs-Bee69jWU.js";import{u as ug,a as pg,A as mg}from"./askKiki-CgAsWGRZ.js";import{D as OC,E as DC,K as FC,F as qC,G as ko,H as Li,I as Na,J as jo,L as wo,M as BC,N as KC}from"./ExternalEnginesSection-Ci1_RIkB.js";import{a as Gs,e as Xd,d as Ct,c as _s,b as Hs,L as UC,R as HC}from"./ListParts-DL6n2vZD.js";import{o as zC,c as QC,a as Aa,S as fm,s as GC,h as Cn,i as Rc,b as eu,u as On,d as Mr,l as No,e as Lc,M as at,f as bm,g as WC,j as ll,k as cl}from"./spaces-wH3o95f_.js";import{u as So,a as tu}from"./layoutHooks-BzE4xDdh.js";import{C as VC,M as YC,H as JC}from"./ModelConnectCard-CY1w-R_8.js";import{K as Dt,S as Dn,a as ZC,b as XC,c as e_}from"./SecretField-DhvasDWA.js";import{A as su,l as xg,m as Or,n as t_}from"./client-cAizUM-b.js";import{C as s_}from"./CodeEditor-BAdDaRcl.js";import{h as n_,a as dl,s as a_}from"./androidBridge-DgaAG2Pi.js";import{a as i_}from"./memoryAuthority-B8YSN2MI.js";import"./NavScopeBoundary-7FLzmaAe.js";import"./uiZoom-CfR9h3Dy.js";import"./ShellEntry-DNaOXNB7.js";import"./PluginPanelHost-BNSzFpXj.js";const r_=/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/,o_=ao({name:Ms().min(1),license:Ms().min(1)}).strict(),l_=ao({id:ps("windows-mcp"),version:ps("0.8.8"),commit:Ms().length(40),python:Ms().min(1),wheelSha256:Ms().regex(/^[0-9a-f]{64}$/),wheelBytes:xj().int().positive(),distribution:ps("external-environment"),managedInstall:ps("withheld-until-gpl-acceptance"),bundled:ps(!1),autoStart:ps(!1),connection:ps(Nr),licenses:mj(o_).min(1),closureLock:Ms().min(1),note:Ms().min(1)}).strict(),c_=ao({result:pj(["mcp-configured","existing-mcp-config-reused"]),name:ps(Nr),connection:ps(Nr),started:ps(!1),bundled:ps(!1)}).strict(),d_="balanced";function u_(t){return t?.branch?.usagePreference??d_}function p_(t){return{branch:{usage_preference:t}}}function m_(t){return t?.branch?.enabled??!0}function x_(t){return{branch:{enabled:t}}}function h_(t){if(t===null||typeof t!="object")return!0;const s=t,n=s.browser_control;if(typeof n?.enabled=="boolean")return n.enabled;const a=s.experimental;return typeof a?.native_browser=="boolean"?a.native_browser:!0}function hg(t){if(t===null||typeof t!="object")return[];const n=t.tools,a=new Set;if(Array.isArray(n?.disabled))for(const i of n.disabled)typeof i=="string"&&a.add(i);if(Array.isArray(n?.disallowed_tools))for(const i of n.disallowed_tools)typeof i=="string"&&a.add(i);return[...a]}function fg(t){const s=hg(t);return s.includes("browser")||s.includes("browser__*")?!0:s.includes("BrowserConnections")&&s.includes("BrowserTabs")}function f_(t){if(fg(t))return!1;const s=hg(t);return s.includes("BrowserConnections")||s.includes("BrowserTabs")}function bg(t,s){if(t==="ego-lite")return"ego-lite";if(t==="codex-extension")return"codex-browser";if(t==="kimi-webbridge"||t==="webbridge-command"||s==="kimi-webbridge")return"kimi-webbridge";if(t==="agent-browser-profile"||t==="agent-browser-cdp")return"independent-browser"}function nu(t,s,n,a){if(t.enabled===!1)return!1;const i=bg(t.type,t.id);return i!==void 0&&a?.includes(i)===!0?!1:!s||n===void 0?!0:n.includes(t.id)}function gg(t,s,n,a){return t.filter(i=>nu(i,s,n,a)).length}const b_={unresolved:"unknown",host_locked:"off",off:"off",tool_denied:"attention",unknown:"unknown",no_connections:"attention",none_allowed:"attention",default_not_allowed:"attention",allowed:"ok"};function g_(t){const s=t.connections??[],n=gg(s,t.allowedBrowsersConfigured,t.allowedBrowsers,t.disabledSources),a=t.defaultBrowser===void 0||t.defaultBrowser===""?void 0:t.defaultBrowser,i=(()=>{if(t.unresolved===!0)return"unresolved";if(!t.enabled)return t.hostLocked===!0?"host_locked":"off";if(t.toolPolicyDenied)return"tool_denied";if(t.connections===void 0)return"unknown";if(s.length===0)return"no_connections";if(n===0)return"none_allowed";if(a!==void 0){const r=s.find(o=>o.id===a);if(r===void 0||!nu(r,t.allowedBrowsersConfigured,t.allowedBrowsers,t.disabledSources))return"default_not_allowed"}return"allowed"})();return{kind:i,tone:b_[i],allowedCount:n,defaultBrowser:a}}const v_="avoid";function y_(t){return t.computer_control?.usagePreference??v_}function k_(t){return{computer_control:{usage_preference:t}}}function j_(t){if(t===null||typeof t!="object")return!0;const n=t.computer_control;return typeof n?.enabled=="boolean"?n.enabled:!0}function w_(t){const s=t.computer_control?.connection;return typeof s=="string"&&s.trim().length>0?s.trim():void 0}function N_(t){return{computer_control:{connection:t}}}function vg(t){if(t===null||typeof t!="object")return[];const n=t.tools,a=new Set;if(Array.isArray(n?.disabled))for(const i of n.disabled)typeof i=="string"&&a.add(i);if(Array.isArray(n?.disallowed_tools))for(const i of n.disallowed_tools)typeof i=="string"&&a.add(i);return[...a]}function yg(t,s){const n=vg(t);if(s===void 0)return n.some(i=>i==="mcp__kiki-computer__*"||i==="kiki-computer"||i==="ComputerControl");const a=s===null||s.trim()===""?Kf:s.trim();return n.some(i=>i==="ComputerControl"||i===a||i===`mcp__${a}__*`)}const S_={unresolved:"unknown",host_locked:"off",off:"off",tool_denied:"attention",checking:"unknown",unknown:"unknown",unsupported:"attention",installing:"unknown",not_installed:"attention",partial:"attention",no_connection:"attention",connection_not_ready:"attention",ready:"ok"};function C_(t){const s=(()=>{if(t.unresolved===!0)return"unresolved";if(!t.enabled)return t.hostLocked===!0?"host_locked":"off";if(t.toolPolicyDenied)return"tool_denied";if(t.executor==="checking"||t.executor==="unknown")return t.executor;if(t.executor!=="external"){if(t.executor.installing)return"installing";if(t.executor.state==="unsupported")return"unsupported";if(t.executor.state==="not_installed")return"not_installed";if(t.executor.state==="partial")return"partial"}return t.hasConnection?t.activeConnectionReady?"ready":"connection_not_ready":"no_connection"})();return{kind:s,tone:S_[s]}}function __(t,s){if(yg(t,s))return!1;const n=vg(t);if(s===void 0)return n.some(r=>r.startsWith("mcp__kiki-computer__")||r.startsWith("ComputerControl__")||r==="mcp__kiki-computer");const a=s===null||s.trim()===""?Kf:s.trim(),i=`mcp__${a}__`;return n.some(r=>r.startsWith(i)||r===`mcp__${a}`)}class E_ extends Error{constructor(s){super(s.map(n=>`${n.path}: ${n.code} (${n.target})`).join("; ")),this.issues=s,this.name="NbSearchReferenceError"}}function T_(t){return t.includes("sync")?"sync":t.includes("async")?"async-only":"none"}function I_(t,s,n){return t.fetch.pipelines.filter(a=>a.input_kinds.includes(s)&&a.representations.includes(n))}function kg(t,s){const n=t?.defaults?.fetch_chain??[],a=t?.execution?.fetch?.quality;return{lanes:structuredClone(t?.lanes??{}),presets:structuredClone(t?.presets??{}),fileScopes:t?.fetch?.file_scopes===void 0||t.fetch.file_scopes===null?void 0:structuredClone(t.fetch.file_scopes),routing:t?.fetch?.routing===void 0?void 0:structuredClone(t.fetch.routing),fetchChains:["url","inline_text","inline_bytes","file"].flatMap(i=>["markdown","text"].map(r=>{const o=n.find(u=>u.input_kind===i&&(u.representation??"markdown")===r),l=s.fetch.chains.find(u=>u.input_kind===i&&(u.representation??"markdown")===r),c=s.inherited_configuration?.fetch_chains.find(u=>u.input_kind===i&&(u.representation??"markdown")===r),d=s.inherited_configuration===void 0?void 0:[...c?.pipelines??[]];return{inputKind:i,representation:r,pipelines:[...o?.pipelines??d??l?.pipelines??[]],inherited:o===void 0,inheritedPipelines:d}})),qualityMinContentChars:a?.min_content_chars===void 0?"":String(a.min_content_chars),qualityBlockedMarkers:a?.blocked_markers===void 0?void 0:[...a.blocked_markers]}}function Sa(t,s,n,a,i=!1){if(t.advanced===void 0)throw new Error("Advanced draft is not initialized.");const r=t.advanced.fetchChains.map(o=>o.inputKind===s&&o.representation===n?{...o,pipelines:[...i?o.inheritedPipelines??a:a],inherited:i}:o);return{...t,fetchChain:s==="url"&&n==="markdown"?[...r.find(o=>o.inputKind===s&&o.representation===n).pipelines]:t.fetchChain,fetchChainInherited:s==="url"&&n==="markdown"?i:t.fetchChainInherited,advanced:{...t.advanced,fetchChains:r}}}function ks(t,s,n){if(t.advanced===void 0)throw new Error("Advanced draft is not initialized.");const a={...t.advanced.lanes};return n===void 0?delete a[s]:a[s]=structuredClone({...a[s],...n,evidence_groups:n.evidence_groups}),{...t,advanced:{...t.advanced,lanes:a}}}function fn(t,s,n){if(t.advanced===void 0)throw new Error("Advanced draft is not initialized.");const a={...t.advanced.presets};return n===void 0?delete a[s]:a[s]=structuredClone({...a[s],...n}),{...t,advanced:{...t.advanced,presets:a}}}function P_(t,s,n){return[...(t.defaultSearchLane===""?n?.inherited_configuration===void 0?n?.search.default_lane:n.inherited_configuration.default_search_lane:t.defaultSearchLane)===s?["defaults.search_lane"]:[],...Object.entries({...n?.inherited_configuration?.presets,...t.advanced?.presets}).filter(([,i])=>i?.lanes.includes(s)).map(([i])=>`presets.${i}`),...(t.advanced?.fetchChains??[]).filter(i=>i.pipelines.includes(s)).map(i=>`defaults.fetch_chain.${i.inputKind}.${i.representation}`),...(t.advanced?.routing===null?[]:t.advanced?.routing?.rules??n?.inherited_configuration?.routing?.rules??[]).filter(i=>"pipelines"in i.action&&i.action.pipelines.includes(s)).map(i=>`fetch.routing.rules.${i.id}`)]}const A_={"zhihu.search":{provider_instance_id:"zhihu.default",operation_id:"search",latency:"fast",cost:"cheap",evidence_groups:["zhihu"]},"zhihu.global":{provider_instance_id:"zhihu.default",operation_id:"global",latency:"medium",cost:"cheap",evidence_groups:["zhihu-web"]},"zhihu.synthesis":{provider_instance_id:"zhihu.default",operation_id:"synthesis",latency:"medium",cost:"cheap"}};function $_(t,s){const n=t.providers.descriptors.find(u=>u.provider_id==="zhihu");if(n===void 0||n.query_operations.length===0)return[];const a=t.providers.instances.some(u=>u.provider_id==="zhihu"&&s.providers[u.id]?.isDeleted!==!0),i=Object.values(s.providers).some(u=>u.providerId==="zhihu"&&u.isDeleted!==!0);if(a||i)return[];const r=t.inherited_configuration?.lanes??{},o=s.advanced?.lanes??{},l=Object.keys(r).some(u=>u.startsWith("zhihu.")),c=Object.entries(o).some(([u,p])=>p!=null&&u.startsWith("zhihu.")),d=t.inherited_configuration===void 0&&Object.keys(t.configuration?.lanes??{}).some(u=>u.startsWith("zhihu."));return l||c||d?[]:["zhihu"]}function R_(t,s,n){if(t.advanced===void 0)throw new Error("Advanced draft is not initialized.");if(n!=="zhihu")throw new Error(`Unsupported opt-in provider: ${n}`);if(!s.providers.descriptors.some(r=>r.provider_id==="zhihu"))throw new Error("Unknown provider: zhihu");const a=s.providers.instances.some(r=>r.id==="zhihu.default"),i=t.credentialSlots?.["zhihu.default"];return{...t,providers:{...t.providers,"zhihu.default":{providerId:"zhihu",enabled:!0,baseUrl:"",credentialSlotId:"zhihu.default",credentialSlotExplicit:!0,optionsJson:"",isNew:!a,isDeleted:!1}},credentialSlots:{...t.credentialSlots,"zhihu.default":i&&i!==null?{...i}:{provider_id:"zhihu",env:"NB_SEARCH_ZHIHU_API_KEY"}},advanced:{...t.advanced,lanes:{...t.advanced.lanes,...structuredClone(A_)}}}}function L_(t,s,n,a,i){if(!s.providers.descriptors.some(o=>o.provider_id===n))throw new Error(`Unknown provider: ${n}`);if(a.trim()!==a||a.length===0||a.length>256||t.providers[a]!==void 0)throw new Error(`Duplicate or invalid instance ID: ${a}`);const r=s.providers.descriptors.find(o=>o.provider_id===n).activation.credential==="required";if(r&&(!i||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(i)))throw new Error("A new credentialed instance requires its own environment binding.");if(i&&Object.values(t.credentialSlots??{}).some(o=>o?.env===i))throw new Error("Credential environment binding is already used.");if(t.credentialSlots?.[a]!==void 0)throw new Error("Credential slot ID is already used.");return{...t,providers:{...t.providers,[a]:{providerId:n,enabled:!0,baseUrl:"",credentialSlotId:a,credentialSlotExplicit:r,optionsJson:"",isNew:!0}},credentialSlots:i?{...t.credentialSlots,[a]:{provider_id:n,env:i}}:t.credentialSlots}}function au(t,s,n){const a=s.advanced;if(a===void 0)return[];const i=[],r=(N,_,C)=>i.push({code:N,path:_,target:C}),o=kg(t,n),l=n.inherited_configuration?.lanes??{},c={...n.configuration?.lanes,...l,...o.lanes},d=new Set(Object.keys(t?.lanes??{}).filter(N=>(a.lanes[N]===void 0||a.lanes[N]===null)&&l[N]===void 0)),u=new Map(n.search.lanes.filter(N=>!d.has(N.id)).map(N=>[N.id,N.output.channel])),p=new Map(n.fetch.pipelines.filter(N=>!d.has(N.id)).map(N=>[N.id,N])),h={...n.configuration?.lanes,...l,...a.lanes},b=new Set(d);for(const N of Object.keys(t?.lanes??{}))a.lanes[N]===void 0&&l[N]===void 0&&delete h[N];for(const[N,_]of Object.entries(h)){if(_===null)continue;const C=c[N],S=C?.provider_instance_id!==_.provider_instance_id||C.operation_id!==_.operation_id,k=s.providers[_.provider_instance_id],j=k?.providerId??n.providers.instances.find(L=>L.id===_.provider_instance_id)?.provider_id,T=k?.isDeleted&&!n.inherited_configuration?.provider_instance_ids.includes(_.provider_instance_id);if((S||T)&&b.add(N),T||j===void 0){b.has(N)&&(r("instance",`lanes.${N}`,_.provider_instance_id),u.delete(N),p.delete(N));continue}const A=n.providers.descriptors.find(L=>L.provider_id===j);if(A===void 0&&!b.has(N))continue;const P=A?.query_operations.find(L=>L.operation_id===_.operation_id),R=A?.fetch_operations.find(L=>L.operation_id===_.operation_id);if(u.delete(N),p.delete(N),P!==void 0)u.set(N,P.output.channel);else if(R!==void 0){const L=n.fetch.pipelines.find(E=>E.id===N),I=R.input_kinds,$=R.representations;Array.isArray(I)&&Array.isArray($)?p.set(N,{input_kinds:I.filter(E=>typeof E=="string"),representations:$.filter(E=>typeof E=="string")}):L!==void 0&&!S&&p.set(N,L)}else b.has(N)&&r("operation",`lanes.${N}`,_.operation_id)}const m=s.defaultSearchLane||n.inherited_configuration?.default_search_lane,f=t?.defaults?.search_lane??n.inherited_configuration?.default_search_lane;m&&(m!==f||b.has(m))&&!u.has(m)&&r("lane","defaults.search_lane",m);const g={...n.inherited_configuration?.presets,...o.presets};for(const[N,_]of Object.entries({...n.inherited_configuration?.presets,...a.presets}))for(const C of _?.lanes??[])g[N]?.lanes.includes(C)&&!b.has(C)||(u.has(C)?u.get(C)!=="results"&&r("preset-results",`presets.${N}`,C):r("lane",`presets.${N}`,C));for(const N of a.fetchChains){const _=o.fetchChains.find(C=>C.inputKind===N.inputKind&&C.representation===N.representation);for(const C of N.pipelines){if(_?.pipelines.includes(C)&&!b.has(C))continue;const S=p.get(C),k=`defaults.fetch_chain.${N.inputKind}.${N.representation}`;S===void 0?r("pipeline",k,C):(!S.input_kinds.includes(N.inputKind)||!S.representations.includes(N.representation))&&r("pipeline-incompatible",k,C)}}const v=n.inherited_configuration?.routing,y=a.routing===null?{}:{...v,...a.routing},w=o.routing===null?[]:o.routing?.rules??v?.rules??[];for(const N of y.rules??[]){if(!("pipelines"in N.action))continue;const _=w.find(C=>C.id===N.id);for(const C of N.action.pipelines){if(JSON.stringify(N)===JSON.stringify(_)&&!b.has(C))continue;const S=p.get(C),k=`fetch.routing.rules.${N.id}`;S===void 0?r("pipeline",k,C):(!S.input_kinds.includes("url")||N.match.representation!==void 0&&!S.representations.includes(N.match.representation))&&r("pipeline-incompatible",k,C)}}return i}const ji=32;function Mc(t){return(t??"").split(",").map(s=>s.trim()).filter(s=>s!=="")}function gm(t){return t.join(",")}function M_(t){const s=new Set,n=new Set;let a=!1;for(const r of t){const o=r.trim();o===""?a=!0:s.has(o)?n.add(o):s.add(o)}const i=t.length>ji;return{valid:!i&&n.size===0&&!a,tooMany:i,duplicates:[...n],empty:a}}function jg(t,s){return s===""?{laneId:t.inherited_configuration===void 0?t.search.default_lane:t.inherited_configuration.default_search_lane,inherited:!0}:{laneId:s,inherited:!1}}function ht(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}function Dr(t){return Array.isArray(t)?t:[]}function ul(t){return typeof t=="string"?t:""}function O_(t){if(t.config_source?.availability==="unavailable"){const r={configured:!1,available:!1,issues:t.config_source.issues};return{search:r,fetch:r}}const s=t.search.default_lane,n=(()=>{if(s===void 0)return{configured:!1,available:!1,issues:["DEFAULT_NOT_CONFIGURED"]};const r=t.search.lanes.find(o=>o.id===s);return{configured:!0,available:r?.availability==="ready"&&r.execution_modes.includes("sync"),selection:s,issues:r?.issues.map(o=>o.code)??["LANE_NOT_REGISTERED"]}})(),a=t.fetch.chains.find(r=>r.input_kind==="url"&&r.representation==="markdown"),i=(()=>{if(a===void 0)return{configured:!1,available:!1,issues:["FETCH_DEFAULT_NOT_CONFIGURED"]};const r=a.pipelines.map(c=>t.fetch.pipelines.find(d=>d.id===c)),o=r.flatMap(c=>c?.issues.map(d=>d.code)??["LANE_NOT_REGISTERED"]),l=r.some(c=>c?.availability==="ready"&&c.execution_modes.includes("sync"));return{configured:!0,available:l,selection:a.pipelines.join(" -> "),issues:l?o:[...o,"FETCH_CHAIN_UNAVAILABLE"]}})();return{search:n,fetch:i}}const Fr="url",la="markdown";function us(t){return typeof t=="number"&&Number.isFinite(t)?String(t):""}function D_(t){const s=ht(t.fetch);return{maxProviderCalls:us(t.max_provider_calls),maxConcurrency:us(t.max_concurrency),retryCount:us(t.retry_count),searchTimeoutMs:us(t.search_timeout_ms),fetchTimeoutMs:us(t.fetch_timeout_ms),maxInlineBytes:us(t.max_inline_bytes),fetchMaxSourceBytes:us(s.max_source_bytes),fetchMaxResponseBytes:us(s.max_response_bytes),fetchMaxContentChars:us(s.max_content_chars),fetchMaxRedirects:us(s.max_redirects)}}function wg(t){return t==null?t:Object.fromEntries(Object.entries(t).map(([s,n])=>[s,n===null?null:{...n}]))}function F_(t,s,n,a){const i=t.providers[s].credentialSlotId,r={...t.credentialSlots},o=r[i];return a===""?delete r[i]:r[i]={provider_id:o?.provider_id??n,env:a},{...t,credentialSlots:Object.keys(r).length===0?void 0:r}}function Oc(t,s){const n=ht(t),a=ht(n.provider_instances),i=wg(t?.credential_slots),r=ht(n.defaults),o=r.search_lane,c=Dr(r.fetch_chain).map(h=>ht(h)).find(h=>h.input_kind===Fr&&(h.representation??la)===la),d=s.fetch.chains.find(h=>h.input_kind===Fr&&h.representation===la),u=new Map(s.providers.descriptors.map(h=>[h.provider_id,new Set(h.option_keys)])),p={};for(const h of s.providers.instances){const b=ht(a[h.id]),m=ul(b.credential_slot_id),f=m||h.credential.slot_id||h.id,g=u.get(h.provider_id)??new Set,v=Object.fromEntries(Object.entries(ht(b.options)).filter(([y])=>g.has(y)));p[h.id]={enabled:typeof b.enabled=="boolean"?b.enabled:h.enabled,baseUrl:ul(b.base_url),credentialSlotId:f,credentialSlotExplicit:m!=="",optionsJson:Object.keys(v).length>0?JSON.stringify(v,null,2):"",keyStrategy:b.key_strategy==="round-robin"||b.key_strategy==="priority"?b.key_strategy:void 0,balanceTtlMs:typeof b.balance_ttl_ms=="number"?us(b.balance_ttl_ms):void 0}}return{defaultSearchLane:typeof o=="string"?o:"",fetchChain:c!==void 0?Dr(c.pipelines).map(h=>ul(h)).filter(h=>h!==""):[...d?.pipelines??[]],fetchChainInherited:c===void 0,providers:p,credentialSlots:i,execution:D_(ht(n.execution)),advanced:kg(t,s)}}function Ng(t){const s=t.trim();if(s==="")return;const n=Number(s);if(!Number.isInteger(n)||n<0)throw new bn({key:"st.nbSearch.invalidNumber",params:{value:s}});return n}function ds(t,s,n){const a=Ng(n);a===void 0?delete t[s]:t[s]=a}function q_(t,s,n){const a=ht(t),i={...a},r=new Map(n.providers.descriptors.map(g=>[g.provider_id,new Set(g.option_keys)])),o=Oc(t,n),l={...ht(a.provider_instances)};let c=!1;for(const[g,v]of Object.entries(s.providers)){const y=n.providers.instances.find($=>$.id===g),w=o.providers[g]??{...v,isNew:!1};if(v.isDeleted){delete l[g],c=!0;continue}if(!v.isNew&&JSON.stringify(v)===JSON.stringify(w))continue;const N=v.providerId??y?.provider_id;if(N===void 0||(!y||v.optionsJson!==w.optionsJson)&&!r.has(N))throw new Error(`Unknown provider for instance: ${g}`);const _=y??{id:g,provider_id:N,enabled:!0},C=v.optionsJson.trim(),S=r.get(_.provider_id)??new Set;let k={};if(C!==""){let $;try{$=JSON.parse(C)}catch{throw new bn({key:"st.nbSearch.invalidOptions",params:{id:_.id}})}if($===null||typeof $!="object"||Array.isArray($))throw new bn({key:"st.nbSearch.invalidOptions",params:{id:_.id}});if(k=$,Object.keys(k).some(E=>!S.has(E)))throw new bn({key:"st.nbSearch.invalidOptions",params:{id:_.id}})}const j=Ng(v.balanceTtlMs??"");if(j!==void 0&&(j<6e4||j>864e5))throw new RangeError(`Provider balance TTL for ${_.id} must be between 60000 and 86400000 milliseconds.`);if(!(v.enabled!==w.enabled||v.baseUrl!==w.baseUrl||v.credentialSlotId!==w.credentialSlotId||v.credentialSlotExplicit!==w.credentialSlotExplicit||v.optionsJson!==w.optionsJson||v.keyStrategy!==w.keyStrategy||v.balanceTtlMs!==w.balanceTtlMs||v.isNew===!0))continue;c=!0;const A=ht(l[_.id]),R={...Object.fromEntries(Object.entries(ht(A.options)).filter(([$])=>!S.has($))),...k},L={...A,provider_id:_.provider_id,enabled:v.enabled,credential_slot_id:v.credentialSlotExplicit?v.credentialSlotId:void 0,base_url:v.baseUrl.trim()===""?void 0:v.baseUrl.trim(),key_strategy:v.keyStrategy,balance_ttl_ms:j,options:!v.isNew&&v.optionsJson===w.optionsJson?A.options:R};v.enabled===_.enabled&&L.base_url===void 0&&!v.credentialSlotExplicit&&L.key_strategy===void 0&&L.balance_ttl_ms===void 0&&Object.keys(ht(L.options)).length===0&&!v.isNew&&_.id===`${_.provider_id}.default`&&Object.keys(A).every($=>["provider_id","enabled","credential_slot_id","base_url","key_strategy","balance_ttl_ms","options"].includes($))?delete l[_.id]:l[_.id]=L}c&&(Object.keys(l).length>0?i.provider_instances=l:delete i.provider_instances),s.credentialSlots===void 0?delete i.credential_slots:i.credential_slots=wg(s.credentialSlots);const d={...ht(a.defaults)};s.defaultSearchLane===""?delete d.search_lane:d.search_lane=s.defaultSearchLane;const u=Dr(ht(a.defaults).fetch_chain).map(g=>ht(g)).filter(g=>!(g.input_kind===Fr&&(g.representation??la)===la));if(s.fetchChainInherited)u.length===0?delete d.fetch_chain:d.fetch_chain=u;else{if(s.fetchChain.length===0)throw new bn({key:"st.nbSearch.chainEmpty"});d.fetch_chain=[...u,{input_kind:Fr,representation:la,pipelines:[...s.fetchChain]}]}const p=s.advanced,h=o.advanced,b=(g,v)=>JSON.stringify(g)!==JSON.stringify(v);if(p!==void 0&&h!==void 0){if(b(p.lanes,h.lanes)||b(p.presets,h.presets)||b(p.fetchChains,h.fetchChains)||b(p.routing,h.routing)||s.defaultSearchLane!==o.defaultSearchLane||Object.values(s.providers).some(v=>v.isDeleted)){const v=au(t,s,n);if(v.length>0)throw new E_(v)}if(b(p.lanes,h.lanes)&&(Object.keys(p.lanes).length===0?delete i.lanes:i.lanes=structuredClone(p.lanes)),b(p.presets,h.presets)&&(Object.keys(p.presets).length===0?delete i.presets:i.presets=structuredClone(p.presets)),b(p.fetchChains,h.fetchChains)){const v=p.fetchChains.filter(y=>!y.inherited);if(v.some(y=>y.pipelines.length===0))throw new bn({key:"st.nbSearch.chainEmpty"});v.length===0?delete d.fetch_chain:d.fetch_chain=p.fetchChains.filter(y=>y.pipelines.length>0).map(y=>({...Dr(ht(a.defaults).fetch_chain).map(ht).find(N=>N.input_kind===y.inputKind&&(N.representation??"markdown")===y.representation),input_kind:y.inputKind,representation:y.representation,pipelines:[...y.pipelines]}))}if(b(p.fileScopes,h.fileScopes)||b(p.routing,h.routing)){const v={...ht(a.fetch)};b(p.fileScopes,h.fileScopes)&&(p.fileScopes===void 0?delete v.file_scopes:v.file_scopes=structuredClone(p.fileScopes)),b(p.routing,h.routing)&&(p.routing===void 0?delete v.routing:v.routing=structuredClone(p.routing)),Object.keys(v).length>0?i.fetch=v:delete i.fetch}}Object.keys(d).length>0?i.defaults=d:delete i.defaults;const m={...ht(a.execution)};ds(m,"max_provider_calls",s.execution.maxProviderCalls),ds(m,"max_concurrency",s.execution.maxConcurrency),ds(m,"retry_count",s.execution.retryCount),ds(m,"search_timeout_ms",s.execution.searchTimeoutMs),ds(m,"fetch_timeout_ms",s.execution.fetchTimeoutMs),ds(m,"max_inline_bytes",s.execution.maxInlineBytes);const f={...ht(m.fetch)};if(ds(f,"max_source_bytes",s.execution.fetchMaxSourceBytes),ds(f,"max_response_bytes",s.execution.fetchMaxResponseBytes),ds(f,"max_content_chars",s.execution.fetchMaxContentChars),ds(f,"max_redirects",s.execution.fetchMaxRedirects),p!==void 0&&h!==void 0&&(p.qualityMinContentChars!==h.qualityMinContentChars||b(p.qualityBlockedMarkers,h.qualityBlockedMarkers))){const g={...ht(f.quality)};ds(g,"min_content_chars",p.qualityMinContentChars),p.qualityBlockedMarkers===void 0?delete g.blocked_markers:g.blocked_markers=[...p.qualityBlockedMarkers],Object.keys(g).length>0?f.quality=g:delete f.quality}return Object.keys(f).length>0?m.fetch=f:delete m.fetch,Object.keys(m).length>0?i.execution=m:delete i.execution,{nb_search:i,replace_domains:["nb_search"]}}function vm(t,s){return JSON.stringify(t)!==JSON.stringify(s)}function B_(t,s,n){const a=s.trim().toLocaleLowerCase().split(/\s+/u).filter(Boolean);return t.filter(i=>{const r=[i.name,i.description,i.source,i.mcp_server_id??""].join(`
|
|
2
|
+
`).toLocaleLowerCase();return a.every(o=>r.includes(o))}).toSorted((i,r)=>i.name.localeCompare(r.name))}function qr(t){return{tools:t.tools===void 0?null:[...t.tools],disallowedTools:t.disallowed_tools===void 0?null:[...t.disallowed_tools]}}function Sg(t,s){const n=s.workspaceId??t.workspace_id??t.workspace_ids?.[0];if(!(n===void 0||t.source_file===void 0||!["user","workspace","extra"].includes(t.source)))return{scope:t.source==="workspace"?"project":t.source==="user"?"user":"extra",workspace_id:n,source_file:t.source_file}}function K_(t,s={}){const n=t.executor??"native",a=qr(t);return["tools","disallowed_tools"].map(i=>{const r=t.executor_fields?.[i];return{field:i,source:t.source,sourceFile:t.source_file,values:i==="tools"?a.tools:a.disallowedTools,editable:Sg(t,s)!==void 0,executor:n,applicability:n==="native"?"applied":r?.state??"unknown",reason:n==="native"?void 0:r?.reason}})}function ym(t,s){return t===null||s===null?t===s:t.length===s.length&&t.every((n,a)=>n===s[a])}function km(t){if(t===null)return null;const s=t.map(n=>n.trim());if(s.some(n=>n===""))throw new Error("Tool names must not be blank");return s}function U_(t,s,n={}){const a=qr(t),i=km(s.tools),r=km(s.disallowedTools),o=!ym(i,a.tools),l=!ym(r,a.disallowedTools);if(!o&&!l)return;const c=Sg(t,n);if(c===void 0)throw new Error("Profile has no writable file and workspace");return{...c,tools:o?i:void 0,disallowed_tools:l?r:void 0}}async function H_(t,s,n,a={}){const i=U_(s,n,a);if(i===void 0)return s;await t.updateNamedAgentProfile(s.name,i);const r=await t.listNamedAgentProfiles({workspace_id:i.workspace_id});if(!r.complete)throw new Error("Profile was saved but its catalog reload is incomplete");const o=r.items.find(l=>l.name===s.name&&l.source===s.source&&l.source_file===i.source_file);if(o===void 0)throw new Error("Profile was saved but its file is missing from the reloaded catalog");return o}const bs="kiki-cloudflare",z_="cloudflare";function jm(t){const s=t?.trim();return s!==void 0&&s.length>0?{sha256:s}:{}}function Q_(t){const s=t.rest?.plugins;if(s===void 0)throw new Error("External connection management requires an HTTP connection to Kiki.");const n=async(r,o={})=>(await s.panelBridge(bs,z_,{method:"plugin.call",action:r,args:o})).result,a=async()=>Da.parse(await n("status")),i=async r=>Da.parse(await n(r));return{async read(){if((await t.global.plugins.list()).find(c=>c.id===bs)===void 0)return{state:"not-installed",catalog:(await s.marketplace()).entries.find(d=>d.id===bs)};const o=await s.info(bs),l=o.originalSource??o.root;return o.state!=="ok"||!o.enabled?{state:o.state!=="ok"?"invalid":"disabled",source:l,version:o.version,errors:o.diagnostics.filter(c=>c.severity==="error").map(c=>c.message)}:{state:"available",source:l,version:o.version,status:await a()}},status:a,async previewInstall(r){const o=typeof r=="string"?r:r.source,l=typeof r=="string"?void 0:r.sha256,c=await s.preview({source:o,...jm(l)});if(c.id!==bs)throw new Error("The selected package is not the Cloudflare Tunnel plugin.");return c},async install(r){if(r.consent!==!0||r.plan.id!==bs)throw new Error("Review and approve the Cloudflare plugin installation first.");const o=await s.install({source:r.source,...jm(r.sha256),fingerprint:r.plan.fingerprint,consent:!0});if(o.id!==bs)throw new Error("The installed package is not the Cloudflare Tunnel plugin.");return await s.setEnabled(bs,!0),o},async enable(){return await s.setEnabled(bs,!0),a()},async installDependency(r){if(r!==!0)throw new Error("Choose Install to allow downloading cloudflared.");return await s.installPrerequisite(bs,{id:"cloudflared",consent:r}),a()},async configure(r){return Da.parse(await n("configure",{values:gj.parse(r)}))},start:()=>i("start"),stop:()=>i("stop"),login:()=>i("login"),cancelLogin:()=>i("cancelLogin"),async setAutoStart(r){return Da.parse(await n("configure",{values:{autoStart:r}}))},async tunnels(){return bj.parse(await n("tunnels"))},async accounts(){return fj.parse(await n("accounts"))},async selectTunnel(r){return Da.parse(await n("selectTunnel",{id:r}))},async setup(){return hj.parse(await n("setup"))}}}/**
|
|
3
|
+
* @license lucide-react v1.76.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/const Cg={name:"plug",size:24,node:[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]]};Cg.node;const G_=s1(Cg);function wm(){const t=mt(),{meta:s}=be(),{t:n}=D(),a="0.6.0",i=t.kind==="tauri",r=ss(),[o,l]=x.useState(r.updateChannel),[c,d]=x.useState(r.autoUpdate),[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=x.useState("idle"),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(!1),C=x.useRef(0),S=x.useRef(!1),k=x.useRef({autoUpdate:r.autoUpdate,updateChannel:r.updateChannel}),j=x.useRef({autoUpdate:0,updateChannel:0});x.useEffect(()=>()=>{C.current+=1},[]),x.useEffect(()=>{if(t.kind!=="tauri")return;let $=!0;return t.supportsDesktopUpdates().then(E=>{$&&p(E)},()=>{$&&p(!1)}),()=>{$=!1}},[t]);const T=()=>{if(t.kind!=="tauri"||u!==!0||S.current)return;const $=++C.current;f("checking"),v(null),j0(t,Date.now(),o).then(({result:E,persisted:M})=>{if(!($!==C.current||ss().updateChannel!==o)){if(M||w(n("st.about.updateDialog.persistFailed")),E.kind==="update"){b(E.update),v(null);return}b(null),v({tone:E.kind==="failed"?"error":"success",text:E.kind==="failed"?n("st.about.checkFailed"):n("st.about.upToDate")})}}).finally(()=>{$===C.current&&f("idle")})},A=()=>{h===null||S.current||(S.current=!0,_(!1),f("installing"),v(null),Promise.resolve().then(()=>h.install()).then(()=>{b(null),v({tone:"success",text:n("st.about.installedRestart")})}).catch(async $=>{if(w0($)){b(null),N0(),await S0(t);const E=ss();k.current={autoUpdate:E.autoUpdate,updateChannel:E.updateChannel},C.current+=1,l(E.updateChannel),d(E.autoUpdate)}v({tone:"error",text:n("st.about.installFailed")})}).finally(()=>{S.current=!1,f("idle")}))},P=($,E)=>{if(w(null),t.kind!=="tauri")return;const M=++j.current[$];k0(t,{[$]:E}).then(()=>{k.current[$]=E},async()=>{if(M!==j.current[$])return;const z=await t.readDesktopPrefs?.().catch(()=>null);if(M!==j.current[$])return;z?.[$]!==void 0&&(k.current[$]=z[$]);const H=k.current[$];Fs({[$]:H}),$==="autoUpdate"?d(k.current.autoUpdate):(C.current+=1,l(k.current.updateChannel),b(null),_(!1),S.current||f("idle")),w(n("st.about.prefsSaveFailed"))})},R=$=>{d($),Fs({autoUpdate:$}),P("autoUpdate",$)},L=[{label:n("st.about.desktopVersion"),value:a},{label:n("st.about.serverVersion"),value:s.server_version}],I=[...s.build_id!==void 0&&s.build_id!==""?[{label:n("st.about.serverBuild"),value:s.build_id.slice(0,12)}]:[],{label:n("st.about.serverId"),value:s.server_id},{label:n("st.about.backend"),value:s.backend??"v1"}];return e.jsxs(Me,{id:"st-card-about",title:n("st.about.title"),children:[e.jsxs(Ze,{children:[L.map($=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4","data-settings-field":!0,children:[e.jsx("span",{className:"text-[13px] text-ink",children:$.label}),e.jsx("span",{className:"break-all text-right font-mono text-[12px] text-ink",children:$.value})]},$.label)),i?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:n("st.about.channel"),help:o==="beta"?e.jsx("span",{className:"text-amber-ink",children:n("st.about.betaHint")}):void 0,children:e.jsx(Qe,{ariaLabel:n("st.about.channel"),value:o,disabled:u!==!0,onChange:$=>{C.current+=1,l($),b(null),_(!1),S.current||f("idle"),v(null),Fs({updateChannel:$}),P("updateChannel",$)},choices:[{value:"stable",label:n("st.about.stable")},{value:"beta",label:n("st.about.beta")}]})}),e.jsx(ge,{label:n("st.about.autoCheck"),help:n(c==="off"?"st.about.autoCheckOffHint":c==="install"?"st.about.autoCheckInstallHint":"st.about.autoCheckHint"),children:e.jsx(Be,{layout:"bare",label:n("st.about.autoCheck"),checked:c!=="off",disabled:u!==!0,onChange:$=>{R($?"notify":"off")}})}),e.jsx(Id,{when:c!=="off"&&u===!0,children:e.jsx(ge,{label:n("st.about.whenFound"),children:e.jsx(Qe,{ariaLabel:n("st.about.whenFound"),value:c==="off"?"notify":c,onChange:$=>{R($)},choices:[{value:"notify",label:n("st.about.autoUpdateNotify")},{value:"install",label:n("st.about.autoUpdateInstall")}]})})}),u===!1?e.jsx("div",{"data-settings-field":!0,children:e.jsx(he,{children:n("st.about.updatesUnavailable")})}):null,e.jsxs("div",{"data-settings-field":!0,className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:T,disabled:u!==!0||m!=="idle",className:Q,children:n(m==="checking"?"st.about.checking":"st.about.checkUpdate")}),h!==null?e.jsx("button",{type:"button",onClick:()=>{_(!0)},disabled:u!==!0||m!=="idle",className:Ye,children:m==="installing"?n("st.about.installing"):n("st.about.install",{version:h.version})}):null]}),h?.notes!==void 0&&h.notes!==""?e.jsx("div",{"data-settings-field":!0,children:e.jsx("p",{className:"whitespace-pre-wrap text-[11.5px] text-ink-soft",children:h.notes})}):null]}):null]}),e.jsx("div",{className:"mt-3",children:e.jsx(et,{summary:n("st.about.technical"),"data-about-technical":!0,children:e.jsx("dl",{className:"space-y-1 text-[12px]",children:I.map($=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsx("dt",{className:"shrink-0 text-ink-faint",children:$.label}),e.jsx("dd",{className:"break-all text-right font-mono text-[11.5px] text-ink-soft",children:$.value})]},$.label))})})}),e.jsxs("div",{className:"mt-3",children:[e.jsx(pe,{feedback:g}),y===null?null:e.jsx(pe,{feedback:{tone:"error",text:y}})]}),e.jsx(Xe,{open:N&&h!==null,overlayId:"confirm-about-install",title:h===null?"":n("st.about.install",{version:h.version}),body:h===null?void 0:n("st.about.installConfirm",{version:h.version}),confirmLabel:h===null?"":n("st.about.install",{version:h.version}),tone:"danger",busy:m==="installing",onConfirm:A,onCancel:()=>{_(!1)}})]})}function bt(){const{locale:t}=D(),[s,n]=x.useState(!1),[a,i]=x.useState(null),[r,o,l]=Je(),c=x.useRef(0),d=x.useCallback(async p=>{const h=++c.current;l(),n(!0),i(null);try{return await p(),h===c.current&&o(),!0}catch(b){return h===c.current&&(l(),i({tone:"error",text:oe(t,b)})),!1}finally{h===c.current&&n(!1)}},[l,t,o]),u=x.useCallback(()=>{i(null)},[]);return{saving:s,saved:r,error:a,run:d,clearError:u}}function Nm(){const t=mt(),{t:s,locale:n}=D(),a=bt(),[i,r]=x.useState(null),[o,l]=x.useState(null),[c,d]=x.useState(null),[u,p]=x.useState(null),[h,b]=x.useState(!1),[m,f]=x.useState(null),g=t.kind==="tauri";if(x.useEffect(()=>{if(t.kind!=="tauri")return;let _=!0;return t.desktopLogInfo().then(C=>{_&&(r(C),d(C.logLevel),p(C.logLevel))},C=>{_&&l({tone:"error",text:oe(n,C)})}),()=>{_=!1}},[t,n]),!g)return null;const v=_=>{t.kind==="tauri"&&(d(_),a.run(async()=>{await t.writeDesktopPrefs({logLevel:_}),Fs({logLevel:_})}).then(C=>{C||d(u)}))},y=()=>{t.kind==="tauri"&&(b(!0),f(null),t.openDesktopLogDirectory().catch(_=>{f({tone:"error",text:s("st.desktopLog.openFailed",{detail:oe(n,_)})})}).finally(()=>{b(!1)}))},w=()=>{i!==null&&rs(i.backendLogPath).then(()=>{f({tone:"success",text:s("st.desktopLog.copied")})},_=>{f({tone:"error",text:oe(n,_)})})},N=i!==null&&c!==null&&c!==i.logLevel&&i.appliesOnNextLaunch;return e.jsxs(Me,{id:"st-card-desktop-log",title:s("st.desktopLog.title"),scope:"app",children:[e.jsxs(Ze,{children:[i!==null?e.jsx(ge,{label:s("st.desktopLog.fileLabel"),help:s("st.desktopLog.rotation",{size:aa(i.maxBytes,{unit:"iec"}),count:i.backups}),layout:"stack",children:e.jsxs("div",{"data-desktop-log-path":!0,className:"flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"min-w-0 max-w-full flex-1 break-all rounded-md bg-ink/[0.04] px-3 py-1.5 font-mono text-[11.5px] text-ink-soft",children:i.backendLogPath}),e.jsxs("button",{type:"button",onClick:w,className:`${Q} inline-flex items-center gap-1.5`,"aria-label":s("st.desktopLog.copyAria"),children:[e.jsx(de,{name:"copy",size:12}),s("st.desktopLog.copy")]}),e.jsxs("button",{type:"button","data-desktop-log-open":!0,onClick:y,disabled:h,className:`${Q} inline-flex items-center gap-1.5`,children:[e.jsx(de,{name:"external",size:12}),s(h?"st.desktopLog.opening":"st.desktopLog.openFolder")]})]})}):null,c!==null?e.jsxs(ge,{label:s("st.desktopLog.levelLabel"),help:s("st.desktopLog.levelHint"),children:[e.jsx(ot,{saving:a.saving,saved:a.saved}),e.jsx(Qe,{ariaLabel:s("st.desktopLog.levelLabel"),dataAttr:"data-desktop-log-level",mono:!0,value:c,disabled:a.saving,onChange:v,choices:vj.map(_=>({value:_,label:_,hint:s(`st.desktopLog.level.${_}`)}))})]}):null,N?e.jsx("p",{"data-desktop-log-pending":!0,className:"text-[12px] text-amber-ink",children:s("st.desktopLog.pending",{current:i.logLevel,next:c})}):null]}),e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(pe,{feedback:m}),e.jsx(pe,{feedback:a.error??o})]})]})}function _g(t){const[s,n]=x.useState(null),a=t?.id,i=t?.kind;return x.useEffect(()=>{if(a===void 0||t===void 0)return;let r=!0,o=null;const l=()=>CC(t);return(i==="image"?NC(a,SC,l):l()).then(c=>{!r||c===null||(o=URL.createObjectURL(c),n(o))}),()=>{r=!1,o!==null&&URL.revokeObjectURL(o),n(null)}},[a,i]),s}const W_="image/png,image/jpeg,image/webp,image/avif,image/gif,video/mp4,video/webm";function Co(){return x.useSyncExternalStore(_C,cg,EC)}function V_(){return x.useSyncExternalStore(TC,hm,hm)}function Sm(t){const s=new Set;for(const n of[t.light,t.dark]){for(const a of n?.media??[])s.add(a.id);n?.poster!==void 0&&s.add(n.poster.id)}return s}function Dc(t,s,n){const a=Zd(t,s),i={...t,[a]:n},r=Sm(t),o=Sm(i);ki(i);for(const l of r)!o.has(l)&&l.startsWith("local-")&&dg(l)}function Hn({id:t,value:s,min:n,max:a,step:i,onChange:r,format:o}){return e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{id:t,type:"range",min:n,max:a,step:i,value:s,onChange:l=>{r(Number(l.target.value))},className:"w-40 accent-[var(--color-selected-ink)]","aria-valuetext":o(s)}),e.jsx("span",{className:"w-11 text-right text-[12px] text-ink-faint tabular-nums",children:o(s)})]})}const Vi=t=>`${Math.round(t*100)}%`,Cm=t=>`${t}px`;function Y_({value:t,onChange:s,labelledBy:n}){const{t:a}=D(),i=["topLeft","top","topRight","left","center","right","bottomLeft","bottom","bottomRight"],r=(o,l)=>{const c=i.indexOf(o),d=l==="ArrowRight"?1:l==="ArrowLeft"?-1:l==="ArrowDown"?3:l==="ArrowUp"?-3:0,u=i[c+d];return d===0||u===void 0?null:u};return e.jsx("div",{role:"radiogroup","aria-labelledby":n,className:"grid w-[76px] grid-cols-3 gap-0.5 rounded-md bg-ink/[0.04] p-0.5","data-bg-alignment":!0,children:i.map(o=>{const l=o===t;return e.jsx("button",{type:"button",role:"radio","aria-checked":l,"aria-label":a(`st.bg.alignment.${o}`),title:a(`st.bg.alignment.${o}`),tabIndex:l?0:-1,"data-bg-alignment-choice":o,onClick:()=>{s(o)},onKeyDown:c=>{const d=r(o,c.key);d!==null&&(c.preventDefault(),s(d),c.currentTarget.parentElement?.querySelector(`[data-bg-alignment-choice="${d}"]`)?.focus())},className:"flex h-6 items-center justify-center rounded-[4px] hover:bg-panel focus-visible:outline-2 focus-visible:outline-selected-ink",children:e.jsx("span",{className:`block rounded-full transition-all ${l?"h-2 w-2 bg-selected-ink":"h-1 w-1 bg-ink-faint"}`})},o)})})}function J_({slot:t}){const{t:s}=D(),n=t.poster??t.media[0],a=_g(n);return e.jsxs("span",{className:"relative flex h-12 w-20 shrink-0 items-center justify-center overflow-hidden rounded-md bg-canvas ring-1 ring-hairline","aria-hidden":!0,"data-bg-thumb":!0,children:[a===null?null:n.kind==="video"?e.jsx("video",{src:a,muted:!0,playsInline:!0,preload:"metadata",className:"h-full w-full object-cover"}):e.jsx("img",{src:a,alt:"",className:"h-full w-full object-cover"}),t.media[0].kind==="video"?e.jsx("span",{"data-bg-thumb-video":!0,className:"absolute right-1 bottom-1 rounded-[3px] bg-ink/70 px-1 text-[10px] leading-4 font-medium text-paper",children:s("st.pack.video")}):null]})}function _m({theme:t,slot:s,compact:n,onFeedback:a}){const{t:i}=D(),r=Co(),o=fb(),l=x.useRef(null),[c,d]=x.useState(""),[u,p]=x.useState(!1),h=x.useRef(0);x.useEffect(()=>()=>{h.current+=1},[t,o]);const b=async(g,v,y)=>{const w=await IC(g,v);if(!w.ok){a({tone:"error",text:w.reason==="size"?i("st.bg.rejectSize",{image:aa(Jo.imageBytes),video:aa(Jo.videoBytes)}):i(w.reason==="type"?"st.bg.rejectType":"st.bg.rejectContent")});return}if(h.current!==y)return!1;if(!await PC(g,w))return h.current===y&&a({tone:"error",text:i("st.bg.loadFailed")}),!1;if(h.current!==y)return!1;const N=await AC(g,w,v);if(h.current!==y)return await dg(N.id),!1;const _=cg(),C=_[Zd(_,t)],S=C!==null&&C.packId===void 0?C.look:Uf;Dc(_,t,{media:[N],interval:0,look:S});const k=[];return await $C()||k.push(i("st.bg.notPersistent")),w.kind==="video"&&g.size>Jo.videoWarnBytes&&k.push(i("st.bg.largeVideo",{size:aa(g.size)})),h.current===y&&a(k.length>0?{tone:"info",text:k.join(" ")}:null),!0},m=async g=>{const v=++h.current;p(!0),a(null);try{await b(g,g.name,v)}catch{h.current===v&&a({tone:"error",text:i("st.bg.loadFailed")})}finally{h.current===v&&p(!1)}},f=async()=>{const g=c.trim();if(g===""||u)return;const v=++h.current;p(!0),a(null);try{const{blob:y,name:w}=await C0(o,g);await b(y,w,v)&&d("")}catch(y){h.current===v&&a({tone:"error",text:y instanceof bb&&y.message==="unsupported"?i("st.bg.urlUnsupported"):i("st.bg.urlFailed",{reason:y instanceof Error?y.message:String(y)})})}finally{h.current===v&&p(!1)}};return e.jsxs("div",{className:"space-y-2","data-bg-picker":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s!==null?e.jsx(J_,{slot:s}):null,e.jsx("div",{className:"min-w-[8rem] flex-1",children:s!==null?e.jsx("p",{className:"truncate text-[13px] text-ink","data-bg-current":!0,title:s.media[0].name,children:s.media[0].name}):e.jsx("p",{className:"text-[13px] text-ink-soft",children:i("st.bg.none")})}),e.jsx("input",{ref:l,type:"file",accept:W_,className:"sr-only",tabIndex:-1,"aria-hidden":!0,"data-bg-file":!0,onChange:g=>{const v=g.target.files?.[0];g.target.value="",v!==void 0&&m(v)}}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:u,"data-bg-choose":!0,onClick:()=>{l.current?.click()},children:i(s===null?"st.bg.chooseFile":"st.bg.replaceFile")}),s!==null?e.jsx("button",{type:"button",className:Q,"data-bg-remove":!0,onClick:()=>{h.current+=1,p(!1),Dc(r,t,null),a(null)},children:i("st.bg.remove")}):null]})]}),n?null:e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:g=>{g.preventDefault(),f()},children:[e.jsx("label",{htmlFor:"bg-url",className:"text-[12px] text-ink-soft",children:i("st.bg.fromUrl")}),e.jsx("input",{id:"bg-url",type:"url",inputMode:"url",value:c,placeholder:i("st.bg.urlPlaceholder"),onChange:g=>{d(g.target.value)},className:`${Ce} min-w-0 max-w-[320px] flex-1`}),e.jsx("button",{type:"submit",className:Q,disabled:u||c.trim()==="",children:i(u?"st.bg.importing":"st.bg.useUrl")})]})]})}function Z_({theme:t,compact:s=!1}){const{t:n}=D(),a=Co(),i=V_(),[r,o]=x.useState(null),l=a[Zd(a,t)]??(a.linked?a.dark:null),c=l?.look??Uf,d=(m,f)=>{l!==null&&Dc(a,t,{...l,look:{...l.look,[m]:f}})},u=[];l!==null&&i.missing&&u.push(e.jsx("p",{role:"status",className:"text-[12px] text-amber-ink",children:n("st.bg.missing")},"missing")),l!==null&&i.heavyVideo&&u.push(e.jsx("p",{role:"status",className:"text-[12px] text-amber-ink",children:n("st.bg.heavyVideo")},"heavy")),l!==null&&i.paused!==null&&u.push(e.jsx("p",{role:"status",className:"text-[12px] text-ink-soft",children:n(i.paused==="motion"?"st.bg.pausedMotion":"st.bg.pausedPower")},"paused"));const p=e.jsx(ge,{label:n("st.bg.opacity"),htmlFor:s?"onboarding-bg-opacity":"bg-opacity",children:e.jsx(Hn,{id:s?"onboarding-bg-opacity":"bg-opacity",value:c.opacity,min:.1,max:1,step:.05,format:Vi,onChange:m=>{d("opacity",m)}})});if(s)return e.jsxs("div",{className:"space-y-2","data-bg-settings":"compact",children:[e.jsx(_m,{theme:t,slot:l,compact:!0,onFeedback:o}),l!==null?p:null,u,e.jsx(pe,{feedback:r})]});const h=a.assist&&i.textAlpha!==null&&i.surfaceAlpha!==null&&l!==null&&i.textAlpha>i.surfaceAlpha+.005,b=a.assist&&h?n("st.bg.surfaceRaised"):n("st.bg.surfaceHint");return e.jsxs("div",{className:"space-y-2","data-bg-settings":"full",children:[e.jsx(_m,{theme:t,slot:l,compact:!1,onFeedback:o}),e.jsx(pe,{feedback:r}),u,l?.packId!==void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:n("st.bg.fromPack",{name:l.packId})}):null,e.jsx(Be,{layout:"row",label:n("st.bg.perTheme"),checked:!a.linked,onChange:m=>{ki(m?{light:a.light??a.dark,dark:a.light??a.dark,linked:!1}:{light:a[t]??a.light??a.dark,dark:null,linked:!0})}}),a.linked?null:e.jsx("p",{className:"text-[12px] text-ink-faint",children:n("st.bg.perThemeHint",{theme:n(`st.appearance.theme.${t}`)})}),l!==null?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:n("st.bg.scope"),labelId:"bg-scope-label",help:c.scope==="sidebar"?n("st.bg.scopeHint"):void 0,children:e.jsx(He,{ariaLabelledBy:"bg-scope-label",dataAttr:"data-bg-scope",value:c.scope,onChange:m=>{d("scope",m)},choices:["window","main","sidebar"].map(m=>({value:m,label:n(`st.bg.scope.${m}`)}))})}),e.jsx(ge,{label:n("st.bg.fit"),labelId:"bg-fit-label",children:e.jsx(He,{ariaLabelledBy:"bg-fit-label",dataAttr:"data-bg-fit",value:c.fit,onChange:m=>{d("fit",m)},choices:["cover","contain","tile","center"].map(m=>({value:m,label:n(`st.bg.fit.${m}`)}))})}),p,e.jsx(ge,{label:n("st.bg.surface"),htmlFor:"bg-surface",help:b,children:e.jsx(Hn,{id:"bg-surface",value:c.surfaceOpacity,min:.3,max:1,step:.02,format:Vi,onChange:m=>{d("surfaceOpacity",m)}})}),e.jsxs("div",{className:"space-y-0.5","data-bg-assist":!0,children:[e.jsx(Be,{layout:"row",label:n("st.bg.assist"),checked:a.assist,onChange:m=>{ki({...a,assist:m})}}),e.jsx("p",{className:`text-[12px] leading-4 ${a.assist?"text-ink-faint":"text-amber-ink"}`,children:a.assist?n("st.bg.assistHint"):n("st.bg.assistOff")})]}),e.jsxs("details",{className:"group","data-bg-more":!0,children:[e.jsxs("summary",{className:"flex min-h-8 cursor-pointer list-none items-center gap-1.5 text-[13px] text-ink-soft select-none hover:text-ink",children:[e.jsx(de,{name:"chevron",size:12,className:"text-ink-faint transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none group-open:rotate-90"}),n("st.bg.more")]}),e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(ge,{label:n("st.bg.alignment"),labelId:"bg-alignment-label",children:e.jsx(Y_,{labelledBy:"bg-alignment-label",value:yj.includes(c.alignment)?c.alignment:"center",onChange:m=>{d("alignment",m)}})}),e.jsx(ge,{label:n("st.bg.blur"),htmlFor:"bg-blur",children:e.jsx(Hn,{id:"bg-blur",value:c.blur,min:0,max:40,step:1,format:Cm,onChange:m=>{d("blur",m)}})}),e.jsx(ge,{label:n("st.bg.brightness"),htmlFor:"bg-brightness",children:e.jsx(Hn,{id:"bg-brightness",value:c.brightness,min:.4,max:1.4,step:.05,format:Vi,onChange:m=>{d("brightness",m)}})}),e.jsx(ge,{label:n("st.bg.scrim"),htmlFor:"bg-scrim",help:n("st.bg.scrimHint"),children:e.jsx(Hn,{id:"bg-scrim",value:c.scrim,min:0,max:.9,step:.05,format:Vi,onChange:m=>{d("scrim",m)}})}),e.jsx(ge,{label:n("st.bg.surfaceBlur"),htmlFor:"bg-surface-blur",children:e.jsx(Hn,{id:"bg-surface-blur",value:c.surfaceBlur,min:0,max:32,step:1,format:Cm,onChange:m=>{d("surfaceBlur",m)}})})]})]})]}):null]})}function _o(){return x.useSyncExternalStore(tC,rg,sC)}const X_={light:um(Pc).variants.light.colors,dark:um(Pc).variants.dark.colors};function e2({skin:t,theme:s}){const n=t.variants[s]??t.variants[Ac(t)[0]??"light"],a=t.id===Pc||n!==void 0&&n.colors===void 0?X_[s]:n?.colors??{},i=[a.canvas,a.paper,a.panel,a.accent].map(r=>r??"transparent");return e.jsx("span",{"aria-hidden":!0,className:"flex h-9 shrink-0 self-center overflow-hidden rounded-[6px] ring-1 ring-hairline",children:i.map((r,o)=>e.jsx("span",{className:"h-full w-5",style:{backgroundColor:r}},o))})}function t2({theme:t,labelledBy:s}){const{t:n}=D(),a=gb({allDetails:!0}),i=_o(),r=vb({allDetails:!0}),o=x.useMemo(()=>[...nC.map(p=>({skin:p,source:"builtin"})),...a.data.skins.map(p=>({skin:p,source:"user"})),...r.data.packs.map(p=>$c(p.pack)).filter(p=>p!==null).map(p=>({skin:p,source:"pack"}))],[a.data.skins,r.data.packs]),l=(p,h)=>{if(p==="builtin")return n("st.skin.builtin");if(p==="pack")return n("st.skin.pack");const b=h===void 0?void 0:a.data.plugins[h];return b!==void 0?n("st.skin.plugin",{plugin:b.id}):n("st.skin.user")},c=aC(i.selection),d=c===null?[]:Ac(c),u=d.length===1&&d[0]!==t?n(d[0]==="dark"?"st.skin.activeDarkOnlyNotice":"st.skin.activeLightOnlyNotice"):null;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{className:"grid gap-1 sm:grid-cols-2","aria-labelledby":s,children:o.map(({skin:p,source:h})=>{const b=i.selection.source===h&&i.selection.id===p.id,m=Ac(p),f=m.length===1?n(m[0]==="dark"?"st.skin.darkOnly":"st.skin.lightOnly"):null,g=h==="builtin"?iC(p.id):void 0;return e.jsx("li",{className:"flex",children:e.jsxs("button",{type:"button","aria-pressed":b,"data-skin-choice":p.id,onClick:()=>{Lr({selection:{source:h,id:p.id??""}})},className:`flex w-full items-center gap-3 rounded-[10px] px-3 py-2.5 text-left transition-colors ${b?"bg-panel shadow-[var(--kiki-sheet-shadow)]":"hover:bg-ink/[0.04]"}`,children:[e.jsx(e2,{skin:p,theme:t}),e.jsx("span",{className:"min-w-0 flex-1",children:e.jsxs("span",{className:"flex flex-wrap items-baseline gap-x-1.5",children:[e.jsx("span",{className:`text-[13px] text-ink ${b?"font-medium":""}`,children:g!==void 0?n(g):p.name}),e.jsxs("span",{className:"text-[12px] text-ink-faint",children:[l(h,p.id),f!==null?` · ${f}`:""]})]})})]})},`${h}:${p.id}`)})}),u!==null?e.jsx("p",{role:"status",className:"text-[12px] text-ink-soft",children:u}):null,i.selection.source!=="builtin"&&c===null&&!a.isLoading&&!r.isLoading?e.jsx("p",{role:"status",className:"text-[12px] text-amber-ink",children:n("st.skin.missing")}):null]})}function s2(){const{t,tp:s}=D(),n=mt(),a=gb({allDetails:!0}),i=_o(),[r,o]=x.useState(""),[l,c]=x.useState(null),d=a.data.directory??rC(),u=async()=>{const{filename:p,json:h}=yC(i,r),b=new Blob([h],{type:"application/json"});try{if(await n.saveBlob?.(b,p)===!1)return;if(n.saveBlob===void 0){const f=URL.createObjectURL(b),g=document.createElement("a");g.href=f,g.download=p,g.click(),URL.revokeObjectURL(f)}c({tone:"success",text:t("st.skin.exportDone",{file:p})})}catch{c({tone:"error",text:t("st.skin.exportFailed")})}};return e.jsxs("div",{className:"space-y-5","data-skin-files":!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-ink",children:t("st.skin.folder")}),e.jsx("button",{type:"button",className:Q,onClick:a.refetch,children:t("st.skin.reload")})]}),a.data.unsupported?e.jsx(he,{children:t("st.skin.unsupported")}):e.jsxs(e.Fragment,{children:[d!==null?e.jsx("p",{className:"break-all font-mono text-[12px] text-ink-soft","data-skin-directory":!0,children:d}):null,e.jsxs(he,{children:[t("st.skin.folderHint"),n.kind==="browser"?` ${t("st.skin.remoteFolderHint")}`:""]}),a.data.skins.length===0?e.jsx(he,{children:t("st.skin.empty")}):null,a.data.skipped.length>0?e.jsx(et,{summary:s("st.skin.skipped",a.data.skipped.length),children:e.jsx("ul",{className:"space-y-0.5 font-mono text-[11px] text-ink-faint",children:a.data.skipped.map(p=>e.jsxs("li",{children:[p.file,": ",p.reason]},p.file))})}):null]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"skin-export-name",className:"block text-[13px] font-medium text-ink",children:t("st.skin.export")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"skin-export-name","aria-label":t("st.skin.exportName"),placeholder:t("st.skin.exportName"),value:r,onChange:p=>{o(p.target.value)},className:`${Ce} max-w-[240px]`}),e.jsx("button",{type:"button",className:Q,onClick:()=>void u(),children:t("st.skin.export")})]}),e.jsx(he,{children:t("st.skin.exportHint")}),e.jsx(pe,{feedback:l})]})]})}function n2({entry:t}){const s=t.pack.preview??t.pack.variants.light?.background?.poster??t.pack.variants.dark?.background?.poster,n=_g(s===void 0?void 0:{id:RC(t.pack.id,s),kind:"image",mime:"image/*",name:s,bytes:0}),a=t.pack.variants.light?.colors?.accent??t.pack.variants.dark?.colors?.accent;return e.jsxs("span",{"aria-hidden":!0,className:"relative block aspect-[16/10] w-full overflow-hidden rounded-[8px] bg-canvas ring-1 ring-hairline","data-pack-preview":!0,children:[n!==null?e.jsx("img",{src:n,alt:"",className:"h-full w-full object-cover"}):null,a!==void 0?e.jsx("span",{className:"absolute bottom-2 left-2 h-3 w-3 rounded-full ring-2 ring-paper",style:{backgroundColor:a}}):null]})}function a2(){const{t}=D(),s=mt(),n=fb(),a=Oe(),i=vb({allDetails:!0}),r=_o(),o=Co(),l=x.useRef(null),[c,d]=x.useState(null),[u,p]=x.useState(!1),[h,b]=x.useState(null),[m,f]=x.useState(null),g=C=>r.selection.source==="pack"&&r.selection.id===C||o.light?.packId===C||o.dark?.packId===C,v=()=>{a.invalidateQueries({queryKey:["appearance-packs"]})},y=C=>{$c(C.pack)!==null&&(oC(i.data.packs.map(k=>$c(k.pack)).filter(k=>k!==null)),Lr({selection:{source:"pack",id:C.pack.id}})),ki(LC(C.pack)),d(null)},w=async(C,S)=>{p(!0),d(null);try{const k=await _0(n,C,S);d({tone:"success",text:t(k.replaced?"st.pack.replaced":"st.pack.imported",{name:k.pack.name})}),v()}catch(k){if(k instanceof bb&&k.code===40919){const j=/"([^"]+)"/.exec(k.message)?.[1]??"";b({file:C,id:j});return}d({tone:"error",text:t("st.pack.importFailed",{reason:k instanceof Error?k.message:String(k)})})}finally{p(!1)}},N=async C=>{const S=`${C.pack.id}.kiki-pack.zip`;try{const k=await E0(n,C.pack.id);if(await s.saveBlob?.(k,S)===!1)return;if(s.saveBlob===void 0){const T=URL.createObjectURL(k),A=document.createElement("a");A.href=T,A.download=S,A.click(),URL.revokeObjectURL(T)}d({tone:"success",text:t("st.pack.exported",{file:S})})}catch(k){d({tone:"error",text:k instanceof Error?k.message:String(k)})}},_=async C=>{try{await T0(n,C.pack.id),(o.light?.packId===C.pack.id||o.dark?.packId===C.pack.id)&&ki({light:null,dark:null,linked:!0});const S=rg().selection;S.source==="pack"&&S.id===C.pack.id&&Lr({selection:{source:"builtin",id:"paper"}}),d({tone:"success",text:t("st.pack.deleted",{name:C.pack.name})}),v()}catch(S){d({tone:"error",text:S instanceof Error?S.message:String(S)})}};return i.data.unsupported?e.jsx(he,{children:t("st.pack.unsupported")}):e.jsxs("div",{className:"space-y-3","data-appearance-packs":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(he,{children:[t("st.pack.hint"),s.kind==="browser"?` ${t("st.pack.remoteHint")}`:""]}),e.jsx("input",{ref:l,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":!0,"data-pack-file":!0,onChange:C=>{const S=C.target.files?.[0];C.target.value="",S!==void 0&&w(S,!1)}}),e.jsx("button",{type:"button",className:Q,disabled:u,"data-pack-import":!0,onClick:()=>{l.current?.click()},children:t(u?"st.pack.importing":"st.pack.import")})]}),e.jsx(pe,{feedback:c}),i.data.packs.length===0&&!i.isLoading?e.jsx("p",{className:"text-[13px] text-ink-soft",children:t("st.pack.empty")}):null,e.jsx("ul",{className:"grid gap-3 sm:grid-cols-2",children:i.data.packs.map(C=>{const S=g(C.pack.id);return e.jsxs("li",{"data-pack":C.pack.id,className:`flex flex-col gap-2 rounded-[10px] p-2 ${S?"bg-panel shadow-[var(--kiki-sheet-shadow)]":""}`,children:[e.jsx(n2,{entry:C}),e.jsxs("div",{className:"min-w-0 px-1",children:[e.jsxs("p",{className:"flex flex-wrap items-baseline gap-x-1.5",children:[e.jsx("span",{className:"text-[13px] font-medium text-ink",children:C.pack.name}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:[C.summary.hasSkin?t("st.pack.colors"):null,C.summary.hasVideo?t("st.pack.video"):null,aa(C.summary.bytes)].filter(Boolean).join(" · ")})]}),C.pack.description!==void 0?e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[12px] leading-4 text-ink-soft",children:C.pack.description}):null,C.pack.author!==void 0||C.pack.license!==void 0?e.jsx("p",{className:"mt-0.5 truncate text-[12px] text-ink-faint",children:[C.pack.author,C.pack.license].filter(Boolean).join(" · ")}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-1 pb-1",children:[e.jsx("button",{type:"button",className:Q,"aria-pressed":S,disabled:S,"data-pack-use":C.pack.id,onClick:()=>{y(C)},children:t(S?"st.pack.inUse":"st.pack.use")}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1.5 text-[12px] text-ink-soft hover:text-ink",onClick:()=>void N(C),children:t("st.pack.export")}),e.jsx("button",{type:"button",className:"ml-auto rounded-md px-2 py-1.5 text-[12px] text-danger hover:bg-danger/5","data-pack-delete":C.pack.id,onClick:()=>{f(C)},children:t("st.pack.delete")})]})]},C.pack.id)})}),e.jsx(Xe,{open:h!==null,title:t("st.pack.exists",{id:h?.id??""}),confirmLabel:t("st.pack.replaceConfirm"),tone:"default",overlayId:"appearance-pack-replace",onConfirm:()=>{const C=h?.file;b(null),C!==void 0&&w(C,!0)},onCancel:()=>{b(null)}}),e.jsx(Xe,{open:m!==null,title:t("st.pack.deleteTitle",{name:m?.pack.name??""}),body:t("st.pack.deleteBody"),confirmLabel:t("st.pack.deleteConfirm"),overlayId:"appearance-pack-delete",onConfirm:()=>{const C=m;f(null),C!==null&&_(C)},onCancel:()=>{f(null)}})]})}const Em="mmmmmmmmmmlli10WQ@#永和九年",i2=["monospace","serif","sans-serif"],Tm=new Map;function r2(t){const s=t.trim();if(s==="")return"unknown";const n=Tm.get(s);if(n!==void 0)return n;let a=null;try{a=typeof document>"u"?null:document.createElement("canvas").getContext("2d")}catch{a=null}if(a===null)return"unknown";const i=`"${s.replace(/["\\]/g,"")}"`;let r=!1;for(const l of i2){a.font=`32px ${l}`;const c=a.measureText(Em).width;if(a.font=`32px ${i}, ${l}`,a.measureText(Em).width!==c){r=!0;break}}const o=r?"present":"missing";return Tm.set(s,o),o}const o2=/[^\p{L}\p{N} \-_.]/gu;function l2(t){return t.replace(o2,"").replace(/\s+/g," ").trimStart().slice(0,64)}function pl(t,s){return`'${t.trim()}', ${s}`}function ur(t){return(t.split(",",1)[0]??"").trim().replace(/^['"]|['"]$/g,"")}const ml="__custom",c2={sans:"text-[14px] leading-6",mono:"font-mono text-[13px] leading-6",prose:"text-[15.5px] leading-7"},d2={sans:"st.font.sample.sans",mono:"st.font.sample.mono",prose:"st.font.sample.prose"};function xl({role:t,label:s,help:n,note:a,presets:i,presetValue:r,custom:o,fallback:l,onPreset:c,onCustom:d}){const{t:u}=D(),p=x.useId(),[h,b]=x.useState(o!==void 0),[m,f]=x.useState(()=>o===void 0?"":ur(o)),g=x.useRef(m);g.current=m;const v=x.useRef(!1),y=x.useRef(null);x.useEffect(()=>{v.current||(o!==void 0?(b(!0),ur(o)!==g.current.trim()&&f(ur(o))):g.current.trim()!==""&&(b(!1),f("")))},[o]);const w=h||o!==void 0,N=m.trim(),_=N===""?"unknown":r2(N),C=k=>{if(k===ml){b(!0),N!==""&&d(pl(N,l));return}b(!1),f(""),d(void 0),c(k)},S=k=>{const j=l2(k);f(j),d(j.trim()===""?void 0:pl(j,l))};return e.jsxs("div",{"data-font-role":t,children:[e.jsxs(ge,{label:s,help:n,children:[a,e.jsx(Qe,{ariaLabel:s,dataAttr:"data-font-choice",value:w?ml:r,onChange:C,choices:[...i,{value:ml,label:u("st.font.custom")}]})]}),w?e.jsxs("div",{className:"mb-2 space-y-2 rounded-lg bg-ink/[0.03] p-3 sm:ml-auto sm:max-w-[26rem]","data-font-custom":!0,children:[e.jsx("label",{htmlFor:p,className:"block text-[12px] text-ink-soft",children:u("st.font.nameLabel")}),e.jsx("input",{id:p,ref:y,type:"text",value:v.current?y.current?.value??m:m,spellCheck:!1,autoComplete:"off",onCompositionStart:()=>{v.current=!0},onCompositionEnd:k=>{v.current=!1,S(k.currentTarget.value)},onChange:k=>{v.current?f(k.target.value):S(k.target.value)},placeholder:u(t==="mono"?"st.font.placeholderMono":"st.font.placeholder"),className:"h-8 w-full rounded-md border border-hairline bg-paper px-3 text-[13px] text-ink outline-none transition-colors duration-[var(--kiki-motion-quick)] placeholder:text-ink-faint focus:border-selected-ink"}),e.jsx("p",{"data-font-sample":!0,className:`truncate text-ink ${c2[t]}`,style:N===""?void 0:{fontFamily:pl(N,l)},children:u(d2[t])}),e.jsx("p",{"aria-live":"polite","data-font-presence":_,className:`min-h-4 text-[12px] leading-4 ${_==="missing"?"text-amber-ink":"text-ink-faint"}`,children:_==="missing"?u("st.font.missing",{name:N}):_==="present"?u("st.font.present",{name:N}):null})]}):null]})}const pn={follow:"follow",push:"push-to-main"},Im={follow:"st.spaces.change.followTitle",fixed:"st.spaces.change.fixedTitle","push-to-main":"st.spaces.change.pushTitle",edit:"st.spaces.change.editTitle",exclude:"st.spaces.change.fixedTitle"},u2={follow:"st.spaces.change.followBody",fixed:"st.spaces.change.fixedBody","push-to-main":"st.spaces.change.pushBody",edit:"st.spaces.change.editBody",exclude:"st.spaces.change.fixedBody"};function iu(t){const{client:s,identity:n}=t.target;return e.jsx(p2,{...t},`${yo(s)}|${n.serverId}|${n.homeId}`)}function p2({target:t,spaceName:s,canPush:n,request:a,onClose:i,onApplied:r}){const{client:o,identity:l}=t,c=l.homeId,d=x.useRef(!1),u=x.useRef(0);x.useEffect(()=>(d.current=!0,()=>{d.current=!1,u.current+=1}),[]);const{t:p,locale:h}=D(),[b,m]=x.useState(a.action),[f,g]=x.useState(null),[v,y]=x.useState(new Set),[w,N]=x.useState(!0),[_,C]=x.useState(!1),[S,k]=x.useState(!1),[j,T]=x.useState(null),[A,P]=x.useState(null),[R,L]=x.useState(0),I=x.useRef(a);I.current=a;const $=x.useRef(v);$.current=v;const E=x.useRef(o);E.current=o;const M=JSON.stringify({items:a.items,groups:a.groups,changes:a.changes}),z=x.useCallback(B=>{const le=I.current,re=$.current,ae=++u.current,ne=()=>d.current&&ae===u.current;N(!0),g(null),y(new Set),P(null),yi(E.current).preview(c,{action:B,items:le.items,groups:le.groups,changes:le.changes}).then(Ee=>{ne()&&(g(Ee),y(new Set(Ee.rows.filter(ie=>pm(ie)?B===pn.push?!ie.conflict&&re.has(ie.id):ie.selected:!1).map(ie=>ie.id))))}).catch(Ee=>{ne()&&P(Ee)}).finally(()=>{ne()&&N(!1)})},[c,M]);x.useEffect(()=>{z(b)},[z,b,R]);const H=f===null?null:lC(f),U=f===null?0:f.rows.filter(B=>!B.id.startsWith("group:")&&v.has(B.id)).length,X=f===null?0:f.rows.filter(B=>B.id.startsWith("group:")&&v.has(B.id)).length,q=f===null?0:f.rows.filter(B=>pm(B)).length,F=v.size>0&&!_,V=B=>{y(le=>{const re=new Set(le);return re.has(B)?re.delete(B):re.add(B),re})},se=async()=>{if(!(f===null||!F)){C(!0),T(null);try{const B=await yi(o).apply(c,{token:f.token,selected:[...v]});if(!d.current)return;r(B),i()}catch(B){d.current&&T({tone:"error",text:p("st.spaces.change.failed",{reason:oe(h,B)})})}finally{d.current&&C(!1)}}},Y=b===pn.push?p("st.spaces.change.pushConfirm"):U>0?p("st.spaces.change.apply",{count:U}):p("st.spaces.change.saveChoice"),O=B=>{const le=B.blocked_reason,re=v.has(B.id);return e.jsx("li",{children:e.jsxs("label",{"data-space-change-row":B.id,"data-space-change-state":le===void 0?re?"on":"off":"blocked",className:`flex items-start gap-3 py-2 ${le===void 0?"cursor-pointer":"cursor-not-allowed"}`,children:[e.jsx("input",{type:"checkbox",disabled:le!==void 0,checked:le===void 0&&re,onChange:()=>{V(B.id)},className:"mt-0.5 accent-[var(--color-selected-ink)]"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[13px] ${le===void 0?"text-ink":"text-ink-faint"}`,children:og(B.id,B.name,p)}),B.conflict?e.jsx("span",{className:"mt-0.5 block text-[12px] leading-4 text-amber-ink",children:p("st.spaces.change.mainChanged")}):null,le!==void 0?e.jsx("span",{className:"mt-0.5 block text-[12px] leading-4 text-ink-faint",children:cC(le,p)}):null,le===void 0&&B.selected&&!re?e.jsx("span",{className:"mt-0.5 block text-[12px] leading-4 text-ink-faint",children:p("st.spaces.change.kept")}):null]}),e.jsxs("span",{className:"grid shrink-0 grid-cols-[auto_minmax(0,8rem)] gap-x-2 text-[12px] leading-5",children:[e.jsx("span",{className:"text-ink-faint",children:b===pn.push?p("st.spaces.change.mainNow"):p("st.spaces.change.now")}),e.jsx("span",{className:"truncate text-right text-ink-soft",title:Xa(B.id,B.before,p),children:Xa(B.id,B.before,p)}),e.jsx("span",{className:"text-ink-faint",children:p("st.spaces.change.becomes")}),e.jsx("span",{className:"truncate text-right text-ink",title:Xa(B.id,B.after,p),children:Xa(B.id,B.after,p)})]})]})},B.id)};return e.jsx(Ea,{onClose:()=>{_||i()},ariaLabel:p(Im[b]),overlayId:"space-change-dialog",panelClassName:`${bo} ${go.md} max-h-[calc(100dvh-2rem)] overflow-y-auto`,children:e.jsxs("div",{"data-space-change-dialog":b,children:[e.jsx("h2",{className:"font-display text-[17px] font-semibold text-ink",children:p(Im[b])}),e.jsx("p",{className:"mt-1.5 text-[13px] leading-relaxed text-ink-soft",children:p(u2[b])}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-faint",children:s}),w?e.jsx("p",{className:"mt-4 text-[12px] text-ink-faint",children:p("st.spaces.change.loading")}):null,A!==null?e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(De,{error:A}),e.jsx("button",{type:"button",className:Q,onClick:()=>{L(B=>B+1)},children:p("st.spaces.change.reload")})]}):null,H!==null&&!w?e.jsxs(e.Fragment,{children:[q===0?e.jsx("p",{className:"mt-4 text-[12px] text-ink-faint","data-space-change-empty":!0,children:p("st.spaces.change.nothingToChange")}):null,e.jsx("ul",{className:"mt-3","data-space-change-rows":!0,"data-space-plan":f?.action,children:H.changed.map(O)}),H.same.length>0?e.jsxs("div",{className:"mt-2 pt-2",children:[e.jsxs("button",{type:"button","data-space-change-same-toggle":!0,"aria-expanded":S,className:"flex w-full items-center gap-1.5 rounded px-1 py-1 text-left text-[12px] text-ink-soft outline-none transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",onClick:()=>{k(B=>!B)},children:[e.jsx("span",{"aria-hidden":!0,className:`transition-transform ${S?"rotate-90":""}`,children:"›"}),p("st.spaces.change.same",{count:H.same.length})]}),S?e.jsx("ul",{"data-space-change-same-rows":!0,children:H.same.map(O)}):null]}):null,H.groups.length>0?e.jsx("div",{className:"mt-3 pt-2",children:e.jsx("ul",{"data-space-change-group-rows":!0,children:H.groups.map(B=>e.jsx("li",{children:e.jsxs("label",{"data-space-change-row":B.id,className:"flex cursor-pointer items-start gap-3 py-2",children:[e.jsx("input",{type:"checkbox",checked:v.has(B.id),onChange:()=>{V(B.id)},className:"mt-0.5 accent-[var(--color-selected-ink)]"}),e.jsx("span",{className:"min-w-0 flex-1 text-[13px] text-ink",children:p("st.spaces.change.futureItems")})]})},B.id))})}):null,b!==pn.push&&U===0&&X===0?e.jsx("p",{className:"mt-3 text-[12px] text-ink-faint",children:p("st.spaces.change.none")}):null]}):null,e.jsx("div",{className:"mt-3",children:e.jsx(pe,{feedback:j})}),e.jsxs("div",{className:"mt-5 flex flex-wrap items-center justify-between gap-x-4 gap-y-2",children:[e.jsx("div",{className:"min-w-0",children:b===pn.push?e.jsx("button",{type:"button","data-space-change-back":!0,className:Pm,onClick:()=>{m(pn.follow)},children:p("st.spaces.change.back")}):n&&q>0?e.jsx("button",{type:"button","data-space-change-push":!0,className:Pm,onClick:()=>{m(pn.push)},children:p("st.spaces.change.pushAction")}):null}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button","data-space-change-cancel":!0,className:Q,disabled:_,onClick:i,children:p("common.cancel")}),e.jsx("button",{type:"button","data-space-change-apply":!0,className:Ye,disabled:!F,onClick:()=>{se()},children:_?p("common.saving"):Y})]})]}),f?.restart_required===!0?e.jsx(he,{children:p("st.spaces.change.restart")}):null]})})}const Pm="rounded px-1 py-0.5 text-left text-[12px] font-medium text-ink-soft underline decoration-hairline-strong underline-offset-2 outline-none transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink";function $a({anchor:t,anchorElement:s,items:n,ariaLabel:a,onClose:i}){const r=x.useRef(null),o=x.useRef(i);o.current=i;const l=x.useMemo(()=>({getBoundingClientRect:()=>t}),[t]);return x.useLayoutEffect(()=>{r.current?.querySelector("button:not([disabled])")?.focus()},[]),x.useEffect(()=>{const c=S1("space-row-menu"),d=p=>{if(p.key==="Escape"){p.stopPropagation(),o.current();return}if(p.key!=="ArrowDown"&&p.key!=="ArrowUp")return;const h=[...r.current?.querySelectorAll("button:not([disabled])")??[]];if(h.length===0)return;p.preventDefault();const b=h.indexOf(document.activeElement),m=p.key==="ArrowDown"?(b+1)%h.length:(b-1+h.length)%h.length;h[m]?.focus()},u=p=>{(!(p.target instanceof Node)||!r.current?.contains(p.target))&&o.current()};return window.addEventListener("keydown",d,!0),window.addEventListener("pointerdown",u,!0),()=>{c(),window.removeEventListener("keydown",d,!0),window.removeEventListener("pointerdown",u,!0)}},[]),e.jsx(C1,{open:!0,modal:!1,onOpenChange:c=>{c||o.current()},children:e.jsx(_1,{children:e.jsx(E1,{anchor:l,side:"bottom",align:"end",sideOffset:4,collisionPadding:8,positionMethod:"fixed",style:{zIndex:L1(s??null)},children:e.jsx(T1,{ref:r,role:"menu","aria-label":a,"data-space-row-menu":!0,initialFocus:!1,finalFocus:!1,[$1]:R1(s??null),[P1]:A1(s??null),className:`anim-enter w-60 p-1 outline-none ${I1}`,children:n.map(c=>e.jsxs("div",{children:[c.separatorBefore===!0?e.jsx("div",{className:"mx-1 my-1 border-t border-hairline"}):null,e.jsxs("button",{type:"button",role:"menuitem","data-space-menu-item":c.key,disabled:c.blockedReason!==void 0,"aria-describedby":c.blockedReason!==void 0?`space-menu-${c.key}-why`:void 0,onClick:()=>{i(),c.run()},className:`flex min-h-9 w-full flex-col justify-center rounded-md px-3 py-1.5 text-left text-[13px] outline-none transition-colors hover:bg-paper focus-visible:bg-paper disabled:cursor-not-allowed disabled:hover:bg-transparent ${c.blockedReason!==void 0?"text-ink-faint":c.danger===!0?"text-danger":"text-ink"}`,children:[e.jsx("span",{children:c.label}),c.blockedReason!==void 0?e.jsx("span",{id:`space-menu-${c.key}-why`,className:"mt-0.5 text-[11.5px] leading-4 text-ink-faint",children:c.blockedReason}):null]})]},c.key))})})})})}function Xs(t){const{client:s,meta:n,connectionId:a}=be();if(typeof a=="string"&&a!=="")return null;const i=Pa(s,n);return e.jsx(m2,{target:i,...t},`${yo(s)}|${i?.identity.serverId??"unidentified"}|${i?.identity.homeId??"unidentified"}`)}function m2({item:t,label:s,target:n}){const{t:a,locale:i}=D(),r=Oe(),o=n?.client??null,l=n?.identity??null,c=l?.homeId??"unidentified",d=Wd(n),u=l?.serverId,p=[...Vd.detail(c),u??"unidentified"],[h,b]=x.useState(null),[m,f]=x.useState(null),[g,v]=x.useState(!1),[y,w]=x.useState(null),[N,_]=x.useState(!1),C=yb(),S=x.useRef(!1);x.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]),x.useEffect(()=>{if(!N)return;const z=setTimeout(()=>{_(!1)},2500);return()=>{clearTimeout(z)}},[N]);const k=je({queryKey:p,queryFn:async({signal:z})=>{if(l===null||o===null)throw new Error("Space server is unidentified");const H=await Yd(o,l);return z.throwIfAborted(),H},enabled:d&&l!==null,staleTime:1e4,retry:!1});if(!d&&l!==null)return null;if(k.isError||l===null)return e.jsxs("span",{"data-pref-origin":`${t}-unknown`,className:"flex flex-wrap items-center gap-1.5 text-[11.5px] text-ink-faint",children:[a("st.spaces.origin.unknown"),e.jsx("button",{type:"button",className:"rounded px-1 underline decoration-hairline-strong underline-offset-2 hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",onClick:()=>{k.refetch()},children:a("st.spaces.settingsRetry")})]});const j=lg(k.data,mm[t]);if(j===void 0)return null;const T=j.selection.mode==="fixed",A=a(T?j.selection.reason==="edited"?"st.spaces.origin.edited":"st.spaces.origin.fixed":"st.spaces.origin.follow"),P=C.writes[t],R=g||P?.state==="saving",L=P?.state==="error"?oe(i,P.error):void 0,I=t==="background"&&MC(),$=z=>{S.current&&(r.setQueryData(p,z),r.invalidateQueries({queryKey:p}))},E=async z=>{if(o===null||l===null)return;v(!0),w(null),_(!1);const H=mm[t];try{const U=yi(o),X=await U.preview(c,{action:z,items:[H]});if(!S.current)return;const q=X.rows.filter(se=>!se.id.startsWith("group:")),F=q.find(se=>se.blocked_reason!==void 0);if(F!==void 0||q.length===0){w(new Error(F?.blocked_reason??a("st.spaces.change.nothingToChange")));return}const V=q[0];if(q.length===1&&V.same_value&&!V.conflict){const se=await U.apply(c,{token:X.token,selected:[V.id]});if(!S.current)return;$(se.detail),_(!0);return}f({action:z,items:[H]})}catch(U){S.current&&w(U)}finally{S.current&&v(!1)}},M=[...T?[{key:"follow",label:a("st.spaces.origin.refollow"),run:()=>{E("follow")}}]:[{key:"fixed",label:a("st.spaces.origin.fixHere"),run:()=>{E("fixed")}}],{key:"push",label:a("st.spaces.origin.push"),separatorBefore:!0,blockedReason:j.can_push?void 0:a("st.spaces.blocked.notShareable"),run:()=>{E("push-to-main")}}];return e.jsxs("span",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5","data-pref-origin":`${t}-${T?"fixed":"follow"}`,children:[e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:A}),j.pending?e.jsx("span",{className:"text-[11.5px] text-amber-ink",children:a("st.spaces.origin.restart")}):null,R?e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:a("st.spaces.origin.saving")}):null,!R&&N?e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:a("st.spaces.origin.saved")}):null,L===void 0?null:e.jsxs("span",{role:"alert",className:"flex items-center gap-1 text-[11.5px] text-danger",children:[a("st.spaces.origin.unsaved"),e.jsx("span",{className:"text-ink-faint",children:L})]}),e.jsx("button",{type:"button","data-pref-origin-menu":t,"aria-haspopup":"menu","aria-label":a("st.spaces.origin.menuAria",{name:s}),disabled:g,className:"flex h-5 w-5 items-center justify-center rounded text-ink-faint outline-none transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50",onClick:z=>{b({anchor:z.currentTarget.getBoundingClientRect(),anchorElement:z.currentTarget})},children:e.jsx(de,{name:"more",size:12})}),I?e.jsxs("span",{className:"basis-full text-[11.5px] leading-4 text-ink-faint",children:[a("st.spaces.origin.deviceOnlyBackground")," ",e.jsx("a",{"data-pref-origin-packs":!0,href:"/settings/appearance",className:"rounded text-ink-soft underline decoration-hairline-strong underline-offset-2 outline-none transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:a("st.spaces.origin.backgroundPacks")})]}):null,y===null?null:e.jsx("span",{role:"alert",className:"basis-full text-[11.5px] leading-4 text-danger",children:oe(i,y)}),h===null?null:e.jsx($a,{anchor:h.anchor,anchorElement:h.anchorElement,items:M,ariaLabel:a("st.spaces.origin.menuAria",{name:s}),onClose:()=>{b(null)}}),m===null||n===null?null:e.jsx(iu,{target:n,spaceName:s,canPush:j.can_push,request:m,onClose:()=>{f(null)},onApplied:z=>{S.current&&($(z.detail),_(!0))}})]})}const Eg=[{value:"compact",rem:.22},{value:"default",rem:.25},{value:"roomy",rem:.29}],hl=12,Am=[{value:"",label:null},{value:"'Instrument Sans Variable', 'Instrument Sans', ui-sans-serif, system-ui, 'PingFang SC', 'Noto Sans SC', sans-serif",label:"Instrument Sans"},{value:"'Newsreader Variable', 'Newsreader', Georgia, 'Songti SC', 'Noto Serif SC', serif",label:"Newsreader"},{value:"'Space Grotesk', ui-sans-serif, system-ui, 'PingFang SC', 'Noto Sans SC', sans-serif",label:"Space Grotesk"},{value:"ui-sans-serif, system-ui, 'Segoe UI', 'PingFang SC', 'Noto Sans SC', sans-serif",label:"System sans"}],x2="ui-sans-serif, system-ui, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif",h2="ui-monospace, 'Cascadia Mono', Consolas, 'PingFang SC', 'Microsoft YaHei', monospace",f2="Georgia, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', serif";function $m(t,s){return t===void 0?{preset:"",custom:void 0}:s.some(n=>n.value===t)?{preset:t,custom:void 0}:{preset:"",custom:t}}const Rm=[{value:"",label:null},{value:"'JetBrains Mono', ui-monospace, Consolas, monospace",label:"JetBrains Mono"},{value:"ui-monospace, 'Cascadia Mono', Consolas, monospace",label:"System mono"}];function b2(t){return t===void 0?"default":Eg.reduce((s,n)=>Math.abs(n.rem-t)<Math.abs(s.rem-t)?n:s).value}function g2(){if(typeof document>"u")return"#c8401a";const t=getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim();return/^#[0-9a-fA-F]{6}$/.test(t)?t:"#c8401a"}function v2(t,s){if(s!==void 0||typeof document>"u")return null;const n=getComputedStyle(document.documentElement).getPropertyValue(t).trim();if(n==="")return null;const a=ur(n).replace(/ Variable$/,"");return a===""||a.startsWith("ui-")?null:a}const Lm="flex h-7 w-7 items-center justify-center rounded-[5px] text-ink-soft transition-colors hover:bg-panel hover:text-ink disabled:cursor-not-allowed disabled:text-ink-faint disabled:hover:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink";function fl({prefix:t,labelId:s,valueText:n,canStepOut:a,canStepIn:i,isModified:r,outAria:o,inAria:l,resetLabel:c,deviceBadge:d,onStepOut:u,onStepIn:p,onReset:h}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{role:"group","aria-labelledby":s,[`data-${t}-control`]:"",className:"inline-flex items-center gap-0.5 rounded-md bg-ink/[0.04] p-0.5",children:[e.jsx("button",{type:"button",[`data-${t}-out`]:"","aria-label":o,disabled:!a,onClick:u,className:Lm,children:e.jsx(de,{name:"dash",size:14})}),e.jsx("span",{[`data-${t}-value`]:"","aria-live":"polite",className:"min-w-[3.75rem] px-2 text-center text-[13px] font-medium tabular-nums text-ink select-none",children:n}),e.jsx("button",{type:"button",[`data-${t}-in`]:"","aria-label":l,disabled:!i,onClick:p,className:Lm,children:e.jsx(de,{name:"plus",size:14})})]}),r?e.jsx("button",{type:"button",[`data-${t}-reset`]:"",className:Q,onClick:h,children:c}):null,d!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:d}):null]})}function y2(){const{t}=D(),s=x.useSyncExternalStore(io,ro,oo),{client:n,meta:a,connectionId:i}=be(),r=typeof i=="string"&&i!=="",o=Pa(n,a),l=!r&&Wd(o)?"space":"app",c=l==="space",d=c?t("st.scope.device"):void 0,u=_o(),p=u.tweaks,[h,b]=x.useState(null),m=dC(s.theme,uC()),f=(S,k)=>{const{[S]:j,...T}=p;Lr({tweaks:k===void 0?T:{...T,[S]:k}}),b(null)},g=S=>{Mt(S),b(null)},v=Co(),y={theme:s.theme,motion:s.motion,proseFont:s.proseFont,proseFontSize:s.proseFontSize,codeFontSize:s.codeFontSize,chatWidth:s.chatWidth,uiZoom:s.uiZoom,skin:u,background:v},w=kC(y),N=$m(p.fontSans,Am),_=$m(p.fontMono,Rm),C=(S,k)=>{const j=v2(k,k==="--font-sans"?p.fontSans:p.fontMono);return S.filter(T=>T.value===""||j===null||T.label!==j).map(T=>({value:T.value,label:T.label??(j===null?t("st.skin.fontSkin"):t("st.skin.fontSkinNamed",{face:j}))}))};return e.jsxs("div",{className:"space-y-6","data-appearance-page":!0,"data-skin-settings":!0,children:[e.jsx(Me,{id:"st-card-appearance",title:t("st.appearance.colorTitle"),scope:l,actions:e.jsxs("div",{className:`flex-wrap items-center gap-x-3 gap-y-1 ${h===null&&w?"hidden":"flex"}`,"data-appearance-actions":!0,children:[h!==null?e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"status",className:"text-[12px] text-ink-soft",children:t("st.appearance.restored")}),e.jsx("button",{type:"button",className:"text-[12px] font-medium text-ink-soft underline-offset-2 hover:text-ink hover:underline",onClick:()=>{xm(h),b(null)},children:t("st.appearance.undo")})]}):null,w?null:e.jsx("button",{type:"button","data-appearance-restore":!0,className:Q,onClick:()=>{const S=jC();xm(wC(S)),b(S)},children:t("st.appearance.restoreDefaults")})]}),children:e.jsxs(Ze,{children:[e.jsxs(ge,{label:t("st.appearance.theme"),labelId:"theme-label",children:[e.jsx(Xs,{item:"theme",label:t("st.appearance.theme")}),e.jsx(He,{ariaLabelledBy:"theme-label",dataAttr:"data-theme-choice",value:s.theme,onChange:S=>{g({theme:S})},choices:["light","dark","system"].map(S=>({value:S,label:t(`st.appearance.theme.${S}`)}))})]}),e.jsxs("div",{className:"space-y-2 py-1","data-settings-field":!0,children:[e.jsx("span",{id:"skin-label",className:"block text-[13px] text-ink",children:t("st.skin.title")}),e.jsx(Xs,{item:"skin",label:t("st.skin.title")}),e.jsx(t2,{theme:m,labelledBy:"skin-label"})]})]})}),e.jsx(Me,{id:"st-card-appearance-layout",title:t("st.appearance.layoutTitle"),scope:l,children:e.jsxs(Ze,{children:[e.jsxs(ge,{label:t("st.skin.accent"),htmlFor:"skin-accent",help:t("st.skin.accentHint"),children:[e.jsx(Xs,{item:"tweaks",label:t("st.skin.accent")}),e.jsx("input",{id:"skin-accent",type:"color",value:p.accent??g2(),onChange:S=>{f("accent",S.target.value)},className:"h-8 w-12 cursor-pointer rounded-md border border-hairline bg-paper p-0.5"}),p.accent!==void 0?e.jsx("button",{type:"button",className:Q,onClick:()=>{f("accent",void 0)},children:t("st.skin.accentReset")}):null]}),e.jsxs(ge,{label:t("st.skin.radius"),htmlFor:"skin-radius",children:[e.jsx("input",{id:"skin-radius",type:"range",min:0,max:24,step:2,value:p.radius??hl,onChange:S=>{const k=Number(S.target.value);f("radius",k===hl?void 0:k)},className:"w-40 accent-[var(--color-selected-ink)]"}),e.jsxs("span",{className:"w-10 text-right text-[12px] text-ink-faint tabular-nums",children:[p.radius??hl,"px"]})]}),e.jsx(ge,{label:t("st.skin.density"),labelId:"skin-density-label",children:e.jsx(He,{ariaLabelledBy:"skin-density-label",value:b2(p.spacing),onChange:S=>{f("spacing",S==="default"?void 0:Eg.find(k=>k.value===S)?.rem)},choices:[{value:"compact",label:t("st.skin.densityCompact")},{value:"default",label:t("st.skin.densityDefault")},{value:"roomy",label:t("st.skin.densityRoomy")}]})}),e.jsxs(ge,{label:t("st.appearance.motion"),labelId:"motion-label",help:t("st.appearance.motionHint"),children:[e.jsx(He,{ariaLabelledBy:"motion-label",dataAttr:"data-motion-choice",value:s.motion,onChange:S=>{g({motion:S})},choices:["system","reduce","full"].map(S=>({value:S,label:t(`st.appearance.motion.${S}`)}))}),c?e.jsx("span",{className:"text-[12px] text-ink-faint",children:t("st.scope.device")}):null]})]})}),r?null:e.jsx(Me,{id:"st-card-appearance-background",title:t("st.bg.title"),scope:l,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{children:t("st.bg.hint")}),e.jsx(Xs,{item:"background",label:t("st.bg.title")}),e.jsx(Z_,{theme:m})]})}),e.jsx(Me,{id:"st-card-appearance-type",title:t("st.appearance.typeTitle"),scope:l,children:e.jsxs("div",{children:[e.jsxs(is,{title:t("st.appearance.scaleGroup"),children:[e.jsx(ge,{label:t("st.appearance.zoom"),labelId:"ui-zoom-label",help:t("st.appearance.zoomHint"),children:e.jsx(fl,{prefix:"ui-zoom",labelId:"ui-zoom-label",valueText:`${s.uiZoom}%`,canStepOut:s.uiZoom>jj,canStepIn:s.uiZoom<kj,isModified:s.uiZoom!==Sp,outAria:t("st.appearance.zoomOutAria"),inAria:t("st.appearance.zoomInAria"),resetLabel:t("st.appearance.zoomReset"),deviceBadge:d,onStepOut:()=>{g({uiZoom:Np(s.uiZoom,-1)})},onStepIn:()=>{g({uiZoom:Np(s.uiZoom,1)})},onReset:()=>{g({uiZoom:Sp})}})}),e.jsx(ge,{label:t("st.appearance.proseSize"),labelId:"prose-size-label",help:t("st.appearance.proseSizeHint"),children:e.jsx(fl,{prefix:"prose-size",labelId:"prose-size-label",valueText:`${s.proseFontSize}px`,canStepOut:s.proseFontSize>Nj,canStepIn:s.proseFontSize<wj,isModified:s.proseFontSize!==_p,outAria:t("st.appearance.proseSizeOutAria"),inAria:t("st.appearance.proseSizeInAria"),resetLabel:t("st.appearance.zoomReset"),deviceBadge:d,onStepOut:()=>{g({proseFontSize:Cp(s.proseFontSize,-1)})},onStepIn:()=>{g({proseFontSize:Cp(s.proseFontSize,1)})},onReset:()=>{g({proseFontSize:_p})}})}),e.jsx(ge,{label:t("st.appearance.codeSize"),labelId:"code-size-label",help:t("st.appearance.codeSizeHint"),children:e.jsx(fl,{prefix:"code-size",labelId:"code-size-label",valueText:`${s.codeFontSize}px`,canStepOut:s.codeFontSize>Cj,canStepIn:s.codeFontSize<Sj,isModified:s.codeFontSize!==Tp,outAria:t("st.appearance.codeSizeOutAria"),inAria:t("st.appearance.codeSizeInAria"),resetLabel:t("st.appearance.zoomReset"),deviceBadge:d,onStepOut:()=>{g({codeFontSize:Ep(s.codeFontSize,-1)})},onStepIn:()=>{g({codeFontSize:Ep(s.codeFontSize,1)})},onReset:()=>{g({codeFontSize:Tp})}})}),e.jsxs(ge,{label:t("st.appearance.chatWidth"),labelId:"chat-width-label",children:[e.jsx(He,{ariaLabelledBy:"chat-width-label",dataAttr:"data-chat-width-choice",value:s.chatWidth,onChange:S=>{g({chatWidth:S})},choices:_j.map(S=>({value:S,label:t(`st.appearance.chatWidth.${S}`)}))}),d!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:d}):null]})]}),e.jsxs(is,{title:t("st.appearance.fontGroup"),children:[e.jsx(xl,{role:"sans",label:t("st.skin.font"),presets:C(Am,"--font-sans"),presetValue:N.preset,custom:N.custom,fallback:x2,onPreset:S=>{f("fontSans",S===""?void 0:S)},onCustom:S=>{f("fontSans",S)}}),e.jsx(xl,{role:"prose",label:t("st.appearance.prose"),help:t("st.appearance.proseHint"),note:e.jsx(Xs,{item:"proseFont",label:t("st.appearance.prose")}),presets:[{value:"serif",label:t("st.appearance.prose.serif")},{value:"sans",label:t("st.appearance.prose.sans")}],presetValue:s.proseFont,custom:p.fontProse,fallback:f2,onPreset:S=>{g({proseFont:S==="sans"?"sans":"serif"})},onCustom:S=>{f("fontProse",S)}}),e.jsx(xl,{role:"mono",label:t("st.skin.fontMono"),presets:C(Rm,"--font-mono"),presetValue:_.preset,custom:_.custom,fallback:h2,onPreset:S=>{f("fontMono",S===""?void 0:S)},onCustom:S=>{f("fontMono",S)}})]})]})}),r?null:e.jsx(Me,{id:"st-card-skin-files",title:t("st.skin.filesTitle"),scope:l,children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(a2,{}),e.jsx("div",{className:"pt-5",children:e.jsx(s2,{})})]})})]})}const k2=["agent_idle","subagents_done","tasks_done"],j2={agent_idle:"timing.agentIdle",subagents_done:"timing.subagentsDone",tasks_done:"timing.tasksDone"},w2={agent_idle:"timing.hint.agentIdle",subagents_done:"timing.hint.subagentsDone",tasks_done:"timing.hint.tasksDone"},N2=["measured+estimated","measured","estimated"],S2={"measured+estimated":"st.communication.tokenStrategy.measuredEstimated",measured:"st.communication.tokenStrategy.measured",estimated:"st.communication.tokenStrategy.estimated"};function Ls(t,s){const{client:n}=be(),{locale:a}=D(),i=Oe(),r=je({queryKey:["config"],queryFn:()=>n.getConfig(),staleTime:6e4}),[o,l]=x.useState(null),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je();return x.useEffect(()=>{r.data!==void 0&&!c&&l(t(ms(r.data),r.data))},[r.data,c]),{value:o,apply:async f=>{const g=o;l(f),d(!0),p(null);try{const v=await n.patchConfig(s(f));i.setQueryData(["config"],v),l(t(ms(v),v)),b()}catch(v){l(g),p({tone:"error",text:oe(a,v)})}finally{d(!1)}},saving:c,error:u,saved:h,configQuery:r}}const C2=["conservative","balanced","proactive"],_2={conservative:"st.sessions.branchPreference.conservative",balanced:"st.sessions.branchPreference.balanced",proactive:"st.sessions.branchPreference.proactive"};function E2(){const{t}=D(),s=Ls((u,p)=>Ns(p,"thread")?.allowed??p.thread_communication?.enabled??!1,u=>Ej(u?null:!1)),n=Ls((u,p)=>Ns(p,"thread")?.default_on===!0,u=>({optional_capabilities:{defaults:{thread:u}}})),a=Ls((u,p)=>Ns(p,"branch")?.allowed??m_(p),u=>x_(u?null:!1)),i=Ls((u,p)=>Ns(p,"branch")?.default_on!==!1,u=>({optional_capabilities:{defaults:{branch:u}}})),r=Ls((u,p)=>u_(p),u=>p_(u)),o=Ls(u=>u.agentsNotifyParent,Tj),l=s.value===null||a.value===null||r.value===null||o.value===null,c=Ns(a.configQuery.data,"branch"),d=c?.host_locked===!0;return e.jsx(Me,{id:"st-card-agent-messaging",title:t("st.sessions.messagingTitle"),children:l?s.configQuery.isError?e.jsx(De,{error:s.configQuery.error}):e.jsx(he,{children:t("st.runtime.loading")}):e.jsxs(e.Fragment,{children:[e.jsxs(Ze,{children:[e.jsxs("div",{"data-agent-messaging":"thread",children:[e.jsx(ge,{label:t("st.communication.threadCommunication"),help:t("st.sessions.threadHint"),children:e.jsx(Be,{layout:"bare",label:t("st.communication.threadCommunication"),checked:s.value===!0,disabled:s.saving,onChange:u=>{s.apply(u)}})}),e.jsx(_r,{id:"thread",state:Ns(s.configQuery.data,"thread"),disabled:n.saving,onChange:u=>{n.apply(u)}}),e.jsx(pe,{feedback:s.error})]}),e.jsxs("div",{"data-agent-messaging":"branch",className:"space-y-2.5",children:[e.jsx(ge,{label:t("st.sessions.branchLabel"),help:t("st.sessions.branchHint"),children:e.jsx(Be,{layout:"bare",label:t("st.sessions.branchLabel"),checked:a.value===!0,disabled:a.saving||d,onChange:u=>{a.apply(u)}})}),e.jsx(_r,{id:"branch",state:c,disabled:i.saving,onChange:u=>{i.apply(u)}}),e.jsx(ge,{label:t("st.sessions.branchPreference"),children:e.jsx(He,{ariaLabel:t("st.sessions.branchPreference"),dataAttr:"data-branch-preference",value:r.value??"balanced",disabled:a.value!==!0||r.saving||d,choices:C2.map(u=>({value:u,label:t(_2[u])})),onChange:u=>{r.apply(u)}})}),e.jsx(pe,{feedback:a.error??r.error})]}),e.jsxs("div",{"data-agent-messaging":"notify",children:[e.jsx(ge,{label:t("st.communication.notifyParent"),help:t("st.sessions.notifyHint"),children:e.jsx(Be,{layout:"bare",label:t("st.communication.notifyParent"),checked:o.value===!0,disabled:o.saving,onChange:u=>{o.apply(u)}})}),e.jsx(pe,{feedback:o.error})]})]}),e.jsx(jt,{show:s.saved||n.saved||a.saved||i.saved||r.saved||o.saved})]})})}function T2(){const{t}=D(),s=Ls((i,r)=>r.agents?.delegation?.sub!==!1,i=>({agents:{delegation:{sub:i}}})),n=Ls((i,r)=>r.agents?.delegation?.independent!==!1,i=>({agents:{delegation:{independent:i}}})),a=s.value===null||n.value===null;return e.jsx(Me,{id:"st-card-handoff-notices",title:t("st.dev.engineParams.handoffTitle"),children:a?s.configQuery.isError?e.jsx(De,{error:s.configQuery.error}):e.jsx(he,{children:t("st.runtime.loading")}):e.jsxs(e.Fragment,{children:[e.jsxs(Ze,{children:[e.jsxs("div",{"data-agent-messaging":"delegation-sub",children:[e.jsx(ge,{label:t("st.sessions.delegationSub"),help:t("st.sessions.delegationSubHint"),children:e.jsx(Be,{layout:"bare",label:t("st.sessions.delegationSub"),checked:s.value===!0,disabled:s.saving,onChange:i=>{s.apply(i)}})}),e.jsx(pe,{feedback:s.error})]}),e.jsxs("div",{"data-agent-messaging":"delegation-independent",children:[e.jsx(ge,{label:t("st.sessions.delegationIndependent"),help:t("st.sessions.delegationIndependentHint"),children:e.jsx(Be,{layout:"bare",label:t("st.sessions.delegationIndependent"),checked:n.value===!0,disabled:n.saving,onChange:i=>{n.apply(i)}})}),e.jsx(pe,{feedback:n.error})]})]}),e.jsx(jt,{show:s.saved||n.saved})]})})}function I2(){const{t}=D(),s=Ls(n=>n.tokenCountingStrategy,Ij);return e.jsx(Me,{id:"st-card-token-counting",title:t("st.communication.tokenCountingTitle"),children:s.value===null?s.configQuery.isError?e.jsx(De,{error:s.configQuery.error}):e.jsx(he,{children:t("st.runtime.loading")}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs(ge,{label:t("st.communication.tokenCounting"),help:t("st.dev.tokenHint"),children:[e.jsx(Qe,{id:"token-counting-strategy",ariaLabel:t("st.communication.tokenCounting"),value:s.value,disabled:s.saving,onChange:n=>{s.apply(n)},choices:N2.map(n=>({value:n,label:t(S2[n]),hint:n}))}),e.jsx(jt,{show:s.saved})]}),e.jsx(pe,{feedback:s.error})]})})}function P2(){const{t}=D(),n=x.useSyncExternalStore(io,ro,oo).defaultAppendTiming;return e.jsx("div",{id:"st-card-append-timing",className:"scroll-mt-4",children:e.jsx(ge,{label:t("st.communication.appendTimingTitle"),labelId:"default-append-timing-label",help:t(w2[n]),detail:t("st.communication.appendTimingHint"),children:e.jsx(He,{ariaLabelledBy:"default-append-timing-label",dataAttr:"data-append-timing",value:n,onChange:a=>{Mt({defaultAppendTiming:a})},choices:k2.map(a=>({value:a,label:t(j2[a])}))})})})}const A2=new Set(["role_additional","product_name","reply_style_guide","os","windows_notes","shell","now","cwd","cwd_listing","agents_md","memory","persona","additional_dirs_info","additional_dirs_section","skills","skills_section","plugin_sections","base_prompt","parent_prompt","builtin_prompt","__proto__","constructor","prototype"]),$2=Ms().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).refine(t=>!A2.has(t),"Built-in prompt variable names are reserved."),R2=ao({variables:Pj().superRefine((t,s)=>{typeof t=="object"&&t!==null&&Object.hasOwn(t,"__proto__")&&s.addIssue({code:"custom",message:"Built-in prompt variable names are reserved."})}).pipe(Aj($2,Ms())).optional(),overrides:I0.optional()}).strict(),Tg=R2,ca=`${Ce} border-0 bg-ink/[0.035] font-normal focus-visible:ring-2 focus-visible:ring-selected-ink/40`;function Ca({value:t,onChange:s,children:n,disabled:a=!1,showCommon:i=!0}){const{t:r}=D();return e.jsxs("fieldset",{disabled:a,className:"min-w-0 space-y-5 disabled:opacity-60","data-prompt-identity-editor":!0,children:[i?e.jsxs("div",{className:"space-y-2","data-prompt-common":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:r("st.promptIdentity.common")}),n(t.common,o=>s({...t,common:o}),r("st.promptIdentity.common"))]}):null,["main","independent"].map(o=>{const l=t[o],c=r(`st.promptIdentity.${o}`);return e.jsxs("details",{"data-prompt-position":o,className:"group min-w-0",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-baseline justify-between gap-3 rounded py-1 text-[12px] outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsx("span",{className:"font-medium text-ink-soft",children:c}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-right text-ink-faint",children:[r(`st.promptIdentity.mode.${l.mode}`),e.jsx(de,{name:"chevron",size:12})]})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(He,{ariaLabel:c,value:l.mode,disabled:a,dataAttr:`data-prompt-branch-${o}`,onChange:d=>s(Up(t,o,d)),choices:["same","off","custom"].map(d=>({value:d,label:r(`st.promptIdentity.mode.${d}`)}))}),l.mode==="same"&&l.explicitSame?e.jsx("button",{type:"button",disabled:a,"data-prompt-clear-explicit":o,className:"block rounded py-1 text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40",onClick:()=>s(Up(t,o,"same")),children:r("st.promptIdentity.clearExplicitSame")}):null,l.mode==="custom"?e.jsxs("div",{className:"space-y-2","data-prompt-custom":o,children:[e.jsx("p",{className:"text-[11.5px] leading-5 text-ink-faint",children:r("st.promptIdentity.customHint")}),n(l.content,d=>s({...t,[o]:{...l,content:d}}),c)]}):l.mode==="off"?e.jsx("p",{className:"text-[11.5px] leading-5 text-ink-faint",children:r("st.promptIdentity.offHint")}):null]})]},o)})]})}function Eo({value:t,onChange:s,label:n}){const{t:a}=D();return e.jsxs("div",{className:"min-w-0 space-y-3","data-prompt-overrides-content":!0,children:[e.jsxs("label",{className:$e,children:[a("st.prompt.files"),e.jsx("textarea",{"aria-label":`${n}: ${a("st.prompt.files")}`,rows:2,spellCheck:!1,className:`${ca} mt-1 h-auto resize-y font-mono text-[12px] leading-5`,value:t.files,placeholder:a("st.promptIdentity.pathsPlaceholder"),onChange:i=>s({...t,files:i.target.value})})]}),t.fields.map((i,r)=>e.jsxs("div",{className:"space-y-1","data-identity-field-row":!0,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{className:`${ca} min-w-0 flex-1 font-mono text-[12px]`,value:i.name,"aria-label":`${n}: ${a("st.prompt.fieldName")}`,placeholder:a("st.prompt.fieldNamePlaceholder"),onChange:o=>s({...t,fields:t.fields.map((l,c)=>c===r?{...l,name:o.target.value}:l)})}),e.jsx("button",{type:"button",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded text-ink-faint hover:bg-ink/[0.04] focus-visible:ring-2 focus-visible:ring-selected-ink/40","aria-label":a("st.prompt.removeField",{name:i.name||String(r+1)}),onClick:()=>s({...t,fields:t.fields.filter((o,l)=>l!==r)}),children:e.jsx(de,{name:"close",size:12})})]}),e.jsx("textarea",{rows:3,className:`${ca} h-auto resize-y font-mono text-[12px] leading-5`,value:i.value,"aria-label":`${n}: ${a("st.prompt.fieldValue")}`,spellCheck:!1,onChange:o=>s({...t,fields:t.fields.map((l,c)=>c===r?{...l,value:o.target.value}:l)})})]},i.id)),e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5 border-0 focus-visible:ring-2 focus-visible:ring-selected-ink/40`,onClick:()=>s({...t,fields:[...t.fields,P0()]}),children:[e.jsx(de,{name:"plus",size:12}),a("st.prompt.addField")]})]})}function L2({value:t,onChange:s,label:n}){const{t:a}=D(),i=x.useId(),r=(l,c)=>s({...t,[l]:c}),o=l=>e.jsxs("label",{className:$e,children:[a(`st.promptIdentity.${l}`),e.jsx("textarea",{rows:2,spellCheck:!1,"aria-label":`${n}: ${a(`st.promptIdentity.${l}`)}`,className:`${ca} mt-1 h-auto resize-y font-mono text-[12px] leading-5`,value:t[l],placeholder:a("st.promptIdentity.pathsPlaceholder"),onChange:c=>r(l,c.target.value)})]});return e.jsxs("div",{className:"min-w-0 space-y-3","data-cognition-content":!0,children:[o("overlay"),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{id:`${i}-mode`,className:$e,children:a("st.promptIdentity.overlayMode")}),e.jsx(Qe,{value:t.overlayMode,onChange:l=>r("overlayMode",l),ariaLabel:`${n}: ${a("st.promptIdentity.overlayMode")}`,choices:["","append","prepend","wrap","persona","replace"].map(l=>({value:l,label:a(`st.promptIdentity.overlayMode.${l||"default"}`)}))})]}),e.jsxs("details",{className:"min-w-0","data-cognition-timing":!0,children:[e.jsx("summary",{className:"cursor-pointer py-1 text-[12px] text-ink-soft",children:a("st.promptIdentity.timing")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[o("steering"),o("anchor"),e.jsxs("div",{className:"grid gap-3 min-[768px]:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[a("st.promptIdentity.anchorSteps"),e.jsx("input",{className:`${ca} mt-1 font-mono`,inputMode:"numeric",value:t.anchorSteps,"aria-label":`${n}: ${a("st.promptIdentity.anchorSteps")}`,placeholder:"1",onChange:l=>r("anchorSteps",l.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:a("st.promptIdentity.anchorScope")}),e.jsx(Qe,{value:t.anchorScope,onChange:l=>r("anchorScope",l),ariaLabel:`${n}: ${a("st.promptIdentity.anchorScope")}`,choices:["","session","turn"].map(l=>({value:l,label:a(`st.promptIdentity.anchorScope.${l||"default"}`)}))})]})]})]})]})]})}function M2({value:t,onChange:s,label:n}){const{t:a}=D();return e.jsxs("div",{className:"min-w-0 space-y-2","data-model-prompt-content":!0,children:[e.jsx(Qe,{value:t.mode,onChange:i=>s({mode:i,prompt:i===""?"":t.prompt}),ariaLabel:`${n}: ${a("st.promptIdentity.bodyMode")}`,choices:["","append","prepend","wrap"].map(i=>({value:i,label:a(i===""?"st.promptIdentity.noBody":`st.promptIdentity.overlayMode.${i}`)}))}),e.jsx("textarea",{rows:4,spellCheck:!1,className:`${ca} h-auto resize-y font-mono text-[12px] leading-5`,"aria-label":`${n}: ${a("st.promptIdentity.body")}`,value:t.prompt,onChange:i=>s({prompt:i.target.value,mode:t.mode||"append"})})]})}const O2={files:[],variables:[],fields:[],identity:Er(void 0,sn)},D2=/^[a-z][a-z0-9_-]*(?:\.[a-z][a-z0-9_-]*)+$/;let Mm=0;function ci(t){return Mm+=1,`${t}-${Mm}`}function bl(t){const s=typeof t=="object"&&t!==null?t:{};return{identity:Er(s.overrides,sn),files:(s.overrides?.files??[]).filter(n=>typeof n=="string").map(n=>({id:ci("file"),value:n})),variables:Object.entries(s.variables??{}).filter(([,n])=>typeof n=="string").map(([n,a])=>({id:ci("variable"),name:n,value:a})),fields:Object.entries(s.overrides?.fields??{}).filter(([,n])=>typeof n=="string").map(([n,a])=>({id:ci("field"),name:n,value:a}))}}function Ig(t){return{variables:Object.fromEntries(t.variables.map(s=>[s.name.trim(),s.value])),overrides:{...A0(t.identity,Bs),files:t.files.map(s=>s.value.trim()),fields:Object.fromEntries(t.fields.map(s=>[s.name.trim(),s.value]))}}}function F2(t){return Tg.safeParse({variables:{[t]:""}}).success}function q2(t,s){const n={files:{},variables:{},fields:{},identity:{}},a=xa({...t.identity,common:{files:t.files.map(o=>o.value).join(`
|
|
8
|
+
`),fields:t.fields}},Bs,lo);a!==void 0&&(n.identity[0]=s(`st.promptIdentity.problem.${a}`));const i=(o,l,c)=>{const d=new Set;for(const[u,p]of o.entries()){const h=p.name.trim();h===""?l[u]=s("st.prompt.nameRequired"):(c==="variables"?!F2(h):!D2.test(h))?l[u]=s("st.prompt.nameInvalid"):d.has(h)?l[u]=s("st.prompt.duplicateName",{name:h}):d.add(h)}};i(t.variables,n.variables,"variables"),i(t.fields,n.fields,"fields");for(const[o,l]of t.files.entries())l.value.trim()===""&&(n.files[o]=s("st.prompt.fileRequired"));if(Object.values(n).some(o=>Object.keys(o).length>0))return n;const r=Tg.safeParse(Ig(t));if(!r.success)for(const o of r.error.issues){if(o.path[0]==="variables"&&typeof o.path[1]=="string"){const l=t.variables.findIndex(c=>c.name.trim()===o.path[1]);l>=0&&(n.variables[l]??=o.message)}if(o.path[0]==="overrides"&&o.path[1]==="fields"&&typeof o.path[2]=="string"){const l=t.fields.findIndex(c=>c.name.trim()===o.path[2]);l>=0&&(n.fields[l]??=o.message)}}return n}function gl(t){return Object.values(t).some(s=>Object.keys(s).length>0)}function B2(t){const s=Object.fromEntries(t.variables.map(n=>[n.name.trim(),n.value]));return Object.fromEntries(t.fields.map(n=>[n.name.trim(),n.value.replaceAll(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,i)=>s[i]??a)]))}function K2(){const{client:t}=be(),{t:s,tp:n,locale:a}=D(),i=Oe(),[r,o]=x.useState(O2),[l,c]=x.useState(!1),[d,u]=x.useState(!1),[p,h]=x.useState(null),[b,m]=Je(),f=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),g=f.data!==void 0,v=x.useMemo(()=>q2(r,s),[r,s]),y=x.useMemo(()=>gl(v)?null:B2(r),[r,v]);x.useEffect(()=>{f.data!==void 0&&!l&&o(bl(f.data.prompt))},[f.data,l]);const w=C=>{o(C),c(!0),h(null)},N=C=>({id:ci(C),name:"",value:""}),_=async()=>{if(gl(v)){h({tone:"error",text:s("st.prompt.invalid")});return}u(!0),h(null);try{const C=await t.patchConfig({prompt:Ig(r),replace_domains:["prompt"]});i.setQueryData(["config"],C),o(bl(C.prompt)),c(!1),m()}catch(C){h({tone:"error",text:oe(a,C)})}finally{u(!1)}};return e.jsx(Me,{id:"st-card-prompt-config",title:s("st.prompt.title"),children:e.jsxs("details",{"data-prompt-config":!0,children:[e.jsxs("summary",{className:"flex cursor-pointer flex-wrap items-center gap-2 text-[12px] text-ink-soft",children:[e.jsx("span",{children:s("st.prompt.expand")}),g?e.jsxs("span",{className:"ml-auto flex flex-wrap gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-hairline bg-panel px-1.5 py-px text-[11px] text-ink-faint",children:n("st.prompt.summaryVariables",r.variables.length)}),e.jsx("span",{className:"rounded-full border border-hairline bg-panel px-1.5 py-px text-[11px] text-ink-faint",children:n("st.prompt.summaryFields",r.fields.length)})]}):null]}),e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsx(he,{children:s("st.prompt.hint")}),e.jsxs("fieldset",{disabled:!g||d,className:"space-y-4 disabled:opacity-60",children:[e.jsxs("fieldset",{disabled:d,className:"space-y-2 disabled:opacity-60",children:[e.jsx("legend",{className:"text-[12px] font-medium text-ink",children:s("st.prompt.files")}),r.files.map((C,S)=>e.jsxs("div",{"data-prompt-file-row":C.id,className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("input",{className:Ce,value:C.value,placeholder:s("st.prompt.filePathPlaceholder"),"aria-label":s("st.prompt.filePath"),onChange:k=>{w({...r,files:r.files.map((j,T)=>T===S?{...j,value:k.target.value}:j)})}}),e.jsx("button",{type:"button",className:Q,"aria-label":s("st.prompt.removeFile",{name:C.value||String(S+1)}),onClick:()=>{w({...r,files:r.files.filter((k,j)=>j!==S)})},children:e.jsx(de,{name:"close",size:14})}),v.files[S]!==void 0?e.jsx("div",{className:"sm:col-span-2",children:e.jsx(it,{id:`prompt-file-issue-${C.id}`,text:v.files[S]})}):null]},C.id)),e.jsx("button",{type:"button",className:Q,onClick:()=>{w({...r,files:[...r.files,{id:ci("file"),value:""}]})},children:s("st.prompt.addFile")}),r.files.length===0?e.jsx(he,{children:s("st.prompt.emptyFiles")}):null]}),e.jsxs("fieldset",{disabled:d,className:"space-y-2 disabled:opacity-60",children:[e.jsx("legend",{className:"text-[12px] font-medium text-ink",children:s("st.prompt.variables")}),r.variables.map((C,S)=>e.jsxs("div",{"data-prompt-variable-row":C.id,className:"grid gap-2 sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)_auto]",children:[e.jsx("input",{className:Ce,value:C.name,placeholder:s("st.prompt.variableNamePlaceholder"),"aria-label":s("st.prompt.variableName"),"data-prompt-variable-name":!0,onChange:k=>{w({...r,variables:r.variables.map((j,T)=>T===S?{...j,name:k.target.value}:j)})}}),e.jsx("textarea",{className:`${Ce} min-h-16`,value:C.value,placeholder:s("st.prompt.variableValuePlaceholder"),"aria-label":s("st.prompt.variableValue"),onChange:k=>{w({...r,variables:r.variables.map((j,T)=>T===S?{...j,value:k.target.value}:j)})}}),e.jsx("button",{type:"button",className:Q,"aria-label":s("st.prompt.removeVariable",{name:C.name||String(S+1)}),onClick:()=>{w({...r,variables:r.variables.filter((k,j)=>j!==S)})},children:e.jsx(de,{name:"close",size:14})}),v.variables[S]!==void 0?e.jsx("div",{className:"sm:col-span-3",children:e.jsx(it,{id:`prompt-variable-issue-${C.id}`,text:v.variables[S]})}):null]},C.id)),e.jsx("button",{type:"button",className:Q,onClick:()=>{w({...r,variables:[...r.variables,N("variable")]})},children:s("st.prompt.addVariable")}),r.variables.length===0?e.jsx(he,{children:s("st.prompt.emptyVariables")}):null]}),e.jsxs("fieldset",{disabled:d,className:"space-y-2 disabled:opacity-60",children:[e.jsx("legend",{className:"text-[12px] font-medium text-ink",children:s("st.prompt.fields")}),r.fields.map((C,S)=>e.jsxs("div",{"data-prompt-field-row":C.id,className:"grid gap-2 sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)_auto]",children:[e.jsx("input",{className:Ce,value:C.name,placeholder:s("st.prompt.fieldNamePlaceholder"),"aria-label":s("st.prompt.fieldName"),onChange:k=>{w({...r,fields:r.fields.map((j,T)=>T===S?{...j,name:k.target.value}:j)})}}),e.jsx("textarea",{className:`${Ce} min-h-16`,value:C.value,placeholder:s("st.prompt.fieldValuePlaceholder"),"aria-label":s("st.prompt.fieldValue"),onChange:k=>{w({...r,fields:r.fields.map((j,T)=>T===S?{...j,value:k.target.value}:j)})}}),e.jsx("button",{type:"button",className:Q,"aria-label":s("st.prompt.removeField",{name:C.name||String(S+1)}),onClick:()=>{w({...r,fields:r.fields.filter((k,j)=>j!==S)})},children:e.jsx(de,{name:"close",size:14})}),v.fields[S]!==void 0?e.jsx("div",{className:"sm:col-span-3",children:e.jsx(it,{id:`prompt-field-issue-${C.id}`,text:v.fields[S]})}):null]},C.id)),e.jsx("button",{type:"button",className:Q,onClick:()=>{w({...r,fields:[...r.fields,N("field")]})},children:s("st.prompt.addField")}),r.fields.length===0?e.jsx(he,{children:s("st.prompt.emptyFields")}):null]}),e.jsx(Ca,{value:r.identity,showCommon:!1,disabled:!g||d,onChange:C=>w({...r,identity:C}),children:(C,S,k)=>e.jsx(Eo,{value:C,onChange:S,label:k})}),e.jsx(it,{id:"prompt-identity-issue",text:v.identity[0]??null})]}),e.jsx(et,{summary:s("st.prompt.preview"),"data-prompt-preview":!0,children:y===null?e.jsx("p",{role:"status",children:s("st.prompt.previewUnavailable")}):e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-ink",children:s("st.prompt.previewFields")}),Object.entries(y).length===0?e.jsx("p",{children:"—"}):Object.entries(y).map(([C,S])=>e.jsxs("pre",{className:"mt-1 whitespace-pre-wrap break-words font-mono",children:[C,": ",S]},C))]})}),e.jsx(lt,{id:"prompt-config",dirty:l,saving:d,saved:b,saveDisabled:!g||gl(v),saveLabel:s("st.prompt.save"),onSave:()=>void _(),onDiscard:()=>{o(bl(f.data?.prompt)),c(!1),h(null)}}),f.isError?e.jsx(De,{error:f.error}):null,e.jsx(pe,{feedback:p})]})]})})}function Pg({entry:t,profile:s,onRestored:n,onError:a}){const{client:i}=be(),{t:r}=D(),[o,l]=x.useState(!1),[c,d]=x.useState(!1),u=t.status==="removed",p=u||t.status==="custom"||t.status==="update-available",h=t.status==="custom"?"st.shipped.custom":t.status==="update-available"?"st.shipped.updateAvailable":u?"st.shipped.removed":"st.shipped.clean",b=u?"border-hairline bg-panel text-ink-faint":t.status==="clean"?"border-hairline text-ink-faint":t.status==="update-available"?"border-hairline text-accent-ink":"border-hairline text-ink-soft",m=async()=>{d(!0);try{n(await i.restoreShippedAgentProfile(t.template_id))}catch(v){a(v)}finally{d(!1)}},f=s?.pinned_model_alias,g=[];return u||g.push(r("st.shipped.restoreOverwrite")),f!==void 0&&f!==""&&g.push(r("st.shipped.restoreModelPin",{model:f})),e.jsxs(e.Fragment,{children:[e.jsxs("span",{"data-shipped-status":t.status,className:`rounded-full border px-2 py-0.5 font-mono text-[11px] ${b}`,children:[r("st.shipped.badge")," · ",r(h)]}),p?e.jsx("button",{type:"button","data-shipped-restore":t.template_id,className:Q,disabled:c,onClick:()=>{l(!0)},children:r("st.shipped.restore")}):null,o?e.jsx(Xe,{open:!0,overlayId:"confirm-shipped-restore",title:r("st.shipped.restoreTitle",{name:t.template_id}),body:r(u?"st.shipped.restoreRemovedBody":"st.shipped.restoreBody"),consequences:g,confirmLabel:r("st.shipped.restore"),tone:"danger",busy:c,onCancel:()=>{l(!1)},onConfirm:()=>{l(!1),m()}}):null]})}function U2(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=je({queryKey:["config"],queryFn:()=>t.getConfig()}),[i,r]=x.useState("2"),[o,l]=x.useState("16"),[c,d]=x.useState("0"),[u,p]=x.useState(!1),[h,b]=x.useState(!1),[m,f]=x.useState(),[g,v]=Je();x.useEffect(()=>{if(a.data===void 0||u)return;const _=Ip(a.data);r(String(_.timeoutMs/36e5)),l(String(_.maxDirectChildren)),d(String(_.maxTotalSubagents))},[a.data,u]);const y=async()=>{const _=Math.round(Number(i)*36e5),C=Number(o),S=Number(c);if([i,o,c].some(k=>k.trim()==="")||![_,C,S].every(k=>Number.isSafeInteger(k)&&k>=0)){f(s("st.subagentLimits.invalid"));return}b(!0),f(void 0);try{const k={subagent:{timeout_ms:_,max_direct_children:C,max_total_subagents:S}};n.setQueryData(["config"],await t.patchConfig(k)),await n.invalidateQueries({queryKey:["agentCapabilities"]}),p(!1),v()}catch(k){f(k instanceof Error?k.message:String(k))}finally{b(!1)}},w=()=>{if(a.data!==void 0){const _=Ip(a.data);r(String(_.timeoutMs/36e5)),l(String(_.maxDirectChildren)),d(String(_.maxTotalSubagents))}p(!1),f(void 0)},N=(_,C,S,k,j,T,A)=>e.jsx(ge,{label:C,htmlFor:_,help:S,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("input",{id:_,className:`${pt} h-8 w-24 text-right tabular-nums`,type:"number",min:"0",step:T,value:k,onChange:P=>{j(P.target.value),p(!0)}}),A!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:A}):null]})});return e.jsx(Me,{id:"st-card-subagent-limits",title:s("st.subagentLimits.title"),children:e.jsxs(Ze,{children:[e.jsx(he,{children:s("st.subagentLimits.lead")}),e.jsxs("fieldset",{disabled:h||a.isPending||a.isError,className:"mt-2 space-y-1",children:[N("subagent-limit-hours",s("st.subagentLimits.timeoutShort"),s("st.subagentLimits.timeoutHelp"),i,r,"any",s("st.subagentLimits.hoursUnit")),N("subagent-limit-direct",s("st.subagentLimits.directShort"),s("st.subagentLimits.directHelp"),o,l,"1"),N("subagent-limit-total",s("st.subagentLimits.totalShort"),s("st.subagentLimits.totalHelp"),c,d,"1")]}),e.jsx(lt,{id:"subagent-limits",dirty:u,saving:h,saved:g,saveLabel:s("st.boardStorage.save"),saveDisabled:a.isPending||a.isError,onSave:()=>{y()},onDiscard:w}),m||a.error?e.jsx(pe,{feedback:{tone:"error",text:m??a.error?.message??""}}):null]})})}function H2(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=je({queryKey:["config"],queryFn:()=>t.getConfig()}),i=bt(),r=$j(a.data),o=i.saving||a.isPending||a.isError,l=async c=>{await i.run(async()=>{const d=await t.patchConfig(Mj(c));n.setQueryData(["config"],d)})};return e.jsx(Me,{id:"st-card-subagent-agent-list-fields",title:s("st.agentListFields.label"),actions:e.jsxs(e.Fragment,{children:[e.jsx(ot,{saving:i.saving,saved:i.saved}),r.isCustom?e.jsx("button",{type:"button",disabled:o,"data-agent-list-fields-reset":!0,onClick:()=>{l(null)},className:"text-[12px] text-ink-soft transition-colors hover:text-ink disabled:opacity-50",children:s("st.agentListFields.reset")}):null]}),children:e.jsxs("div",{className:"space-y-3","data-agent-list-fields":!0,children:[e.jsx(he,{children:s("st.agentListFields.help")}),e.jsx("div",{role:"group","aria-label":s("st.agentListFields.label"),className:"flex flex-wrap items-center gap-1.5",children:Rj.map(c=>{const d=r.fields.includes(c);return e.jsxs("button",{type:"button","aria-pressed":d,disabled:o,"data-agent-list-field":c,onClick:()=>{l(Lj(r.fields,c))},className:`inline-flex h-7 items-center gap-1.5 rounded-md border px-2.5 text-[12px] transition-colors focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50 ${d?"border-hairline-strong bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"border-dashed border-hairline text-ink-faint hover:border-hairline-strong hover:text-ink"}`,children:[e.jsx("span",{className:`size-1.5 shrink-0 rounded-full ${d?"bg-selected-ink":"bg-ink/20"}`,"aria-hidden":"true"}),e.jsx("span",{children:s(`st.agentListFields.field.${c}`)}),e.jsx("code",{className:`font-mono text-[11px] ${d?"text-ink-soft":"text-ink-faint/80"}`,children:c})]},c)})}),a.isError?e.jsx(De,{error:a.error}):null,e.jsx(pe,{feedback:i.error})]})})}const vl="__strict__";function Om(t){const s=Ad(t);return s.can_spawn_subagents===!1?"st.profiles.dispatchCanSpawnOff":s.allowed_subagents===void 0?"st.profiles.dispatchNotDeclared":s.allowed_subagents.length===0?"st.profiles.dispatchAllowedEmpty":"st.profiles.dispatchCanSpawnOn"}function z2(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=bt(),i=a.saving,r=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),o=je({queryKey:["named-agent-profiles","global"],queryFn:()=>ii(t,{mode:"global"}),staleTime:15e3,refetchInterval:Tr}),l=r.data===void 0?void 0:$0(r.data),c=x.useMemo(()=>Pd(o.data?.items??[]),[o.data]),d=x.useMemo(()=>{const g=new Set;return c.filter(v=>!v.main&&!v.disabled).filter(v=>g.has(v.name)?!1:(g.add(v.name),!0)).toSorted((v,y)=>v.name.localeCompare(y.name))},[c]),u=l?.mode==="profile"?c.find(g=>g.name===l.name):void 0,p=l?.mode==="profile"&&l.name===R0,h=l===void 0?"":l.mode==="strict"?vl:l.name,b=x.useMemo(()=>{const g=d.map(y=>({value:y.name,label:y.name,description:y.description??y.when_to_use,hint:y.pinned_model_alias,badges:[{label:y.source},{label:s(Om(y))}]})),v=new Set(g.map(y=>y.value));return l?.mode==="profile"&&!v.has(l.name)&&g.push({value:l.name,label:l.name,description:u?.disabled?s("st.subagentDefault.disabledTarget",{name:l.name}):o.data===void 0||p?void 0:s("st.subagentDefault.unresolvable",{name:l.name}),badges:u===void 0?void 0:[{label:u.source}]}),[{value:vl,label:s("st.subagentDefault.strict"),description:s("st.subagentDefault.strictHint")},...g]},[d,l,o.data,u,s]),m=async g=>{const v=g===vl?{mode:"strict"}:{mode:"profile",name:g};await a.run(async()=>{const y=await t.patchConfig(L0(v));n.setQueryData(["config"],y)})},f=[];if(u!==void 0){const g=kb(u.source);f.push(g===void 0?u.source:s(g)),f.push(s(Om(u))),u.pinned_model_alias!==void 0&&u.pinned_model_alias!==""&&f.push(`${s("st.namedAgents.modelPin")} ${u.pinned_model_alias}`)}return e.jsx(Me,{id:"st-card-subagent-default-target",title:s("st.subagentDefault.title"),children:e.jsxs(Ze,{children:[e.jsx(he,{children:s("st.subagentDefault.hint")}),e.jsx("fieldset",{disabled:i||r.isPending,className:"disabled:opacity-60",children:e.jsx("div",{"data-subagent-default-target":!0,"data-value":h,children:e.jsxs(ge,{label:s("st.subagentDefault.label"),labelId:"subagent-default-label",children:[e.jsx(ot,{saving:a.saving,saved:a.saved}),e.jsx(Jt,{id:"subagent-default-profile-select",options:b,value:h,onChange:g=>{m(g)},ariaLabel:s("st.subagentDefault.label"),emptyText:s("st.namedAgents.loading"),buttonClassName:`${zd} max-w-64`})]})})}),l?.mode==="strict"?e.jsx(he,{children:s("st.subagentDefault.strictHint")}):null,l?.mode==="profile"&&!p&&o.data!==void 0&&u===void 0?e.jsx("div",{"data-subagent-default-status":"unresolvable",children:e.jsx(pe,{feedback:{tone:"error",text:s("st.subagentDefault.unresolvable",{name:l.name})}})}):null,u!==void 0?e.jsxs("div",{className:"space-y-1.5","data-subagent-default-status":"resolved",children:[e.jsx("p",{"data-subagent-default-summary":!0,className:"text-[11.5px] text-ink-faint",children:f.join(" · ")}),u.disabled?e.jsx("div",{"data-subagent-default-status":"disabled",children:e.jsx(pe,{feedback:{tone:"error",text:s("st.subagentDefault.disabledTarget",{name:u.name})}})}):null,u.pinned_model_alias===void 0||u.pinned_model_alias===""?e.jsx(he,{children:s("st.subagentDefault.noModelPin")}):null]}):null,r.isError?e.jsx(De,{error:r.error}):null,o.isError?e.jsx(De,{error:o.error}):null,e.jsx(pe,{feedback:a.error})]})})}function Q2(){const{t}=D(),[s,n]=x.useState(gc),a=r=>{n(o=>({...o,subagentPanelOpenMode:r})),Mt({subagentPanelOpenMode:r})},i=s.subagentPanelOpenMode??"tab";return e.jsx(Me,{id:"st-card-subagent-open-mode",title:t("st.subagentOpenMode.title"),children:e.jsxs(Ze,{children:[e.jsx(ge,{label:t("st.subagentOpenMode.label"),labelId:"subagent-open-mode-label",children:e.jsx(He,{ariaLabelledBy:"subagent-open-mode-label",dataAttr:"data-open-mode-choice",value:i,choices:["tab","fullscreen"].map(r=>({value:r,label:t(`st.subagentOpenMode.${r}`)})),onChange:a})}),e.jsx(he,{children:t("st.subagentOpenMode.hint")})]})})}const ta=(t,s)=>t.name===s.name&&t.source===s.source&&t.source_file===s.source_file;function Ag(t){return t.source_file??t.source}function Dm(t){return Ad(t).allowed_subagents??[]}const G2={tools:t=>t.tools!==void 0,disallowed_tools:t=>t.disallowed_tools!==void 0,service_tier:t=>t.service_tier!==void 0,request_params:t=>t.request_params!==void 0,thinking_effort:t=>t.thinking_effort!==void 0,pinned_model_alias:t=>t.pinned_model_alias!==void 0,auto_compact:t=>t.auto_compact!==void 0,allowed_subagents:t=>Ad(t).allowed_subagents!==void 0};function W2(t){return Object.entries(t.executor_fields??{}).filter(([s,n])=>n.state==="ignored"&&(G2[s]?.(t)??!1)).map(([s])=>s)}function V2(t,s){const n=[];t.restrict_models_to_menu===!0&&t.effective_model_aliases?.length===0&&n.push({kind:"modelMenuEmpty"});const{modelIds:a}=s;if(a!==void 0&&a.size>0&&!Ir(t.executor)){const c=d=>typeof d=="string"&&d!==""&&d!=="inherit"&&d!=="*"&&!a.has(d);c(t.pinned_model_alias)&&n.push({kind:"aliasMissing",field:"model_alias",alias:t.pinned_model_alias});for(const d of t.model_profiles??[])c(d.alias)&&n.push({kind:"aliasMissing",field:"model_profiles",alias:d.alias});for(const d of t.allowed_models??[])c(d)&&n.push({kind:"aliasMissing",field:"allowed_models",alias:d});for(const d of Dm(t))if(typeof d!="string")for(const u of[d.model_alias,...d.allowed_models??[]])c(u)&&n.push({kind:"aliasMissing",field:"lease",alias:u,via:d.name})}const i=new Set(s.profiles.map(c=>c.name));for(const c of Dm(t)){const d=typeof c=="string"?c:c.name,u=typeof c!="string"&&c.source!==void 0;d!=="*"&&!u&&!i.has(d)&&n.push({kind:"subagentMissing",name:d})}const r=s.profiles.filter(c=>c.name===t.name&&!ta(c,t)),o=s.effective?.find(c=>c.name===t.name);if(o!==void 0&&!ta(o,t))n.push({kind:"shadowedBy",winner:o});else{const c=[...o!==void 0?r.map(Ag):[],...t.shadowed_files??[]];c.length>0&&n.push({kind:"shadows",hidden:c})}s.shippedEntry!==void 0&&(s.shippedEntry.status==="custom"||s.shippedEntry.status==="update-available")&&n.push({kind:"builtinModified",status:s.shippedEntry.status}),s.overrideRelation?.kind==="overrides_builtin"&&n.push({kind:"overridesBuiltin"});const l=W2(t);return l.length>0&&n.push({kind:"executorIgnored",fields:l}),n}function wn(t){return t.kind==="overridesBuiltin"||t.kind==="builtinModified"||t.kind==="shadows"?"note":"warning"}function Y2({workspaceId:t,workspaceOptions:s,profiles:n,shipped:a,initialSource:i,onCreated:r,onCancel:o}){const{client:l}=be(),{t:c,locale:d}=D(),[u,p]=x.useState("copy"),h=i??n.find(re=>re.source==="builtin"&&!re.main)?.name??n.find(re=>!re.main)?.name??n[0]?.name??"",[b,m]=x.useState(h),[f,g]=x.useState("implementer"),[v,y]=x.useState(h===""?"":`${h}-copy`),[w,N]=x.useState("user"),[_,C]=x.useState(void 0),[S,k]=x.useState(""),[j,T]=x.useState(""),[A,P]=x.useState(!1),[R,L]=x.useState(null),[I,$]=x.useState(t),E=t??I,M=je({queryKey:["workspaces","catalog"],queryFn:()=>l.listWorkspaceCatalog(),enabled:t===void 0&&s===void 0,staleTime:6e4}),z=x.useMemo(()=>s!==void 0?s:(M.data?.items??[]).map(re=>({value:re.id,label:re.name??re.id,description:re.root})),[s,M.data]),H=v.trim(),U=n.some(re=>re.name===H),X=r_.test(H)&&!U,q=n.find(re=>re.name===b),F=_??(u==="copy"?q?.main===!0:!1),V=u!=="blank"||S.trim()!==""&&j.trim()!=="",se=E!==void 0&&X&&V&&(u!=="copy"||q!==void 0),Y=new Set(a.map(re=>re.template_id)),O=[...new Map(n.map(re=>[re.name,re])).values()].toSorted((re,ae)=>+(ae.source==="builtin")-+(re.source==="builtin")||re.name.localeCompare(ae.name)),B=async()=>{if(se){P(!0),L(null);try{const re={workspace_id:E,name:H,scope:w,template:u==="copy"?`duplicate:${b}`:u==="template"?f:"blank",..._!==void 0||u!=="copy"?{main:F}:{},...S.trim()!==""?{description:S.trim()}:{},...u==="blank"?{prompt:j}:{}};r(await l.createAgentProfile(re))}catch(re){L({tone:"error",text:oe(d,re)})}finally{P(!1)}}},le=(re,ae)=>e.jsxs("button",{type:"button","aria-pressed":u===re,"data-new-start":re,onClick:()=>p(re),className:`flex min-h-[4.5rem] flex-1 basis-[11rem] flex-col items-start gap-1 rounded-lg border px-3 py-2 text-left transition-colors ${u===re?"border-hairline-strong bg-panel shadow-[var(--kiki-sheet-shadow)]":"border-hairline hover:border-hairline-strong"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] font-medium text-ink",children:[e.jsx(de,{name:ae,size:12}),c(`st.profiles.start.${re}`)]}),e.jsx("span",{className:"text-[12px] leading-snug text-ink-faint",children:c(`st.profiles.start.${re}Hint`)})]},re);return e.jsxs("div",{"data-agent-create":!0,className:"min-w-0 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",role:"group","aria-label":c("st.agentManager.template"),children:[le("copy","agent"),le("template","notes"),le("blank","edit")]}),u==="copy"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"new-profile-source",className:"text-[12px] font-medium text-ink-soft",children:c("st.profiles.copyFrom")}),e.jsx(Jt,{id:"new-profile-source",value:b,ariaLabel:c("st.profiles.copyFrom"),buttonClassName:Sn,options:O.map(re=>({value:re.name,label:re.name,description:re.description,hint:re.pinned_model_alias,group:re.source==="builtin"||Y.has(re.name)?c("st.profiles.shipped"):c("st.profiles.yours")})),onChange:re=>{m(re),(v===""||v.endsWith("-copy"))&&y(`${re}-copy`)}}),e.jsx(he,{children:c("st.profiles.copyHint")})]}):null,u==="template"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{id:"new-profile-template",className:"text-[12px] font-medium text-ink-soft",children:c("st.agentManager.template")}),e.jsx("div",{children:e.jsx(He,{ariaLabelledBy:"new-profile-template",value:f,onChange:g,choices:[{value:"implementer",label:c("st.agentManager.implementer")},{value:"reviewer",label:c("st.agentManager.reviewer")}]})})]}):null,e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"new-profile-name",className:"text-[12px] font-medium text-ink-soft",children:c("st.agentManager.name")}),e.jsx("input",{id:"new-profile-name",className:`${Ce} font-mono text-[13px]`,value:v,spellCheck:!1,"aria-invalid":v!==""&&!X,"aria-describedby":"new-profile-name-issue",onChange:re=>y(re.target.value)}),v!==""&&!X?e.jsx("p",{id:"new-profile-name-issue",role:"alert",className:"text-[12px] text-danger",children:c(U?"st.profiles.nameTaken":"st.agentManager.nameRequired",{name:v})}):null]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{id:"new-profile-scope",className:"text-[12px] font-medium text-ink-soft",children:c("st.agentManager.scope")}),e.jsx("div",{children:e.jsx(He,{ariaLabelledBy:"new-profile-scope",value:w,onChange:N,choices:[{value:"user",label:c("st.agentManager.userScope")},{value:"project",label:c("st.agentManager.projectScope")}]})})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Be,{layout:"row",label:c("st.profiles.mainToggle"),checked:F,onChange:C}),e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:c(F?"st.profiles.mainOnHint":"st.profiles.mainOffHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{htmlFor:"new-profile-description",className:"text-[12px] font-medium text-ink-soft",children:[c("st.namedAgents.description"),u!=="blank"?e.jsxs("span",{className:"font-normal text-ink-faint",children:[" · ",c("st.profiles.optionalKeep")]}):null]}),e.jsx("textarea",{id:"new-profile-description",rows:2,className:`${Ce} text-[13px]`,value:S,placeholder:u==="copy"?q?.description:void 0,onChange:re=>k(re.target.value)})]}),u==="blank"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"new-profile-prompt",className:"text-[12px] font-medium text-ink-soft",children:c("st.profiles.prompt")}),e.jsx("textarea",{id:"new-profile-prompt",className:`${Ce} min-h-40 font-mono text-[12.5px] leading-relaxed`,value:j,placeholder:c("st.profiles.promptPlaceholder"),onChange:re=>T(re.target.value)})]}):null,t===void 0?e.jsxs("div",{className:"space-y-1.5","data-new-profile-workspace-picker":!0,children:[e.jsx("label",{htmlFor:"new-profile-workspace",className:"text-[12px] font-medium text-ink-soft",children:c("new.workspace")}),z.length>0?e.jsx(Jt,{id:"new-profile-workspace",value:E??"",ariaLabel:c("new.workspace"),buttonClassName:Sn,options:z,searchPlaceholder:c("new.workspace"),onChange:re=>$(re||void 0)}):e.jsx(he,{children:c("st.agentManager.noWorkspace")})]}):null,u==="blank"&&!V&&(S!==""||j!=="")?e.jsx(he,{children:c("st.agentManager.promptRequired")}):null,e.jsx(lt,{id:"agent-create",persistent:!0,saving:A,dirty:se||v!==""&&!v.endsWith("-copy")||S!==""||j!==""||_!==void 0||I!==void 0,saveLabel:c("st.agentManager.create"),saveDisabled:!se,onSave:()=>void B(),onDiscard:o}),e.jsx(pe,{feedback:R})]})}function ru({label:t,value:s,onChange:n,windowTokens:a,placeholder:i,hint:r,dataAttribute:o,labelClassName:l="block text-[12px] font-medium text-ink-soft",presets:c,presetsLabel:d,disabled:u=!1}){const{t:p}=D(),h=x.useId(),b=x.useId(),[m,f]=x.useState(s===void 0?"":ft(s)),[g,v]=x.useState(!1);x.useEffect(()=>{f(s===void 0?"":ft(s)),v(!1)},[s]);const y=()=>{if(m.trim()===""){v(!1),s!==void 0&&n(void 0);return}const w=kc(m),N=M0(w,a??0);if(N===null){v(!0);return}v(!1),f(ft(N)),N!==s&&n(N)};return e.jsxs("div",{className:"space-y-1","data-compact-point-field":o,children:[e.jsx("label",{htmlFor:h,className:l,children:t}),e.jsx("input",{id:h,inputMode:"decimal",spellCheck:!1,autoComplete:"off",disabled:u,className:`${pt} h-8 w-full max-w-[18rem] font-mono tabular-nums ${g?"border-danger":""}`,value:m,placeholder:i,"aria-invalid":g,"aria-describedby":g?b:void 0,onChange:w=>{f(w.target.value)},onBlur:y,onKeyDown:w=>{w.key==="Enter"&&!rt(w)&&(w.preventDefault(),y())}}),c!==void 0&&c.length>0?e.jsx("div",{className:"-ml-2",children:e.jsx(jb,{dataAttribute:o,label:d??t,values:c,current:s,disabled:u,onPick:w=>{v(!1),n(w===s?void 0:w)}})}):null,g?e.jsx("p",{id:b,role:"alert",className:"text-[12px] text-danger",children:p("st.compact.inputInvalid")}):r!==void 0?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint",children:r}):null]})}const J2={model_alias:"st.profiles.model",model_profiles:"st.profiles.modelProfiles",allowed_models:"st.profiles.allowedModels",lease:"st.profiles.subagents"};function $g({diagnostics:t,onOpenWinner:s,surface:n="detail",profile:a}){const{t:i,tp:r}=D();if(t.length===0)return null;const o=t.toSorted((c,d)=>+(wn(c)==="note")-+(wn(d)==="note")),l=c=>{switch(c.kind){case"aliasMissing":return n==="attention"&&c.field==="model_alias"&&c.via===void 0?i("st.agents.issue.missingModel",{model:c.alias}):c.via===void 0?i("st.profiles.diag.aliasMissing",{alias:c.alias,field:i(J2[c.field])}):i("st.profiles.diag.leaseAliasMissing",{alias:c.alias,name:c.via});case"subagentMissing":return i("st.profiles.diag.subagentMissing",{name:c.name});case"shadowedBy":return n==="attention"&&c.winner.source==="builtin"&&a!==void 0?i("st.agents.issue.shadowed",{name:a.name}):i("st.profiles.diag.shadowedBy",{file:Ag(c.winner)});case"shadows":return r("st.profiles.diag.shadowsList",c.hidden.length);case"builtinModified":return i(c.status==="update-available"?"st.profiles.diag.builtinUpdate":"st.profiles.diag.builtinModified");case"overridesBuiltin":return i("st.namedAgents.overridesBuiltin");case"modelMenuEmpty":return i("st.profiles.menuNoCandidates");case"executorIgnored":return i("st.profiles.diag.executorIgnored",{fields:c.fields.join(", ")})}};return e.jsx("ul",{className:"space-y-1","data-profile-diagnostics":!0,"aria-label":i("st.profiles.diagnostics"),children:o.map((c,d)=>{const u=wn(c)==="warning";return e.jsxs("li",{"data-profile-diagnostic":c.kind,className:`flex items-start gap-2 text-[12px] leading-5 ${u?"text-amber-ink":"text-ink-soft"}`,children:[e.jsx("span",{className:"mt-[3px] shrink-0",children:u?e.jsx(de,{name:"warning",size:12}):e.jsx(de,{name:"dot",size:12})}),e.jsxs("span",{className:"min-w-0 break-words",children:[l(c),c.kind==="shadowedBy"&&s!==void 0?e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",onClick:s,className:"underline decoration-current/40 underline-offset-2 hover:decoration-current",children:i("st.profiles.openWinner")})]}):null,c.kind==="shadows"?e.jsx("ul",{"data-shadowed-files":!0,className:"mt-0.5 space-y-0.5",children:c.hidden.map(p=>e.jsx("li",{"data-shadowed-file":p,className:"break-all font-mono text-[11.5px] leading-4 text-ink-faint",children:p},p))}):null]})]},d)})})}function Xt({label:t,htmlFor:s,hint:n,children:a,applicability:i,engine:r,dataField:o}){const{t:l}=D(),c=i?.state==="ignored";return e.jsxs("div",{className:`min-w-0 space-y-1.5 ${c?"opacity-70":""}`,"data-profile-field":o,"data-field-applicability":i?.state,children:[e.jsx("label",{htmlFor:s,className:"block text-[12px] font-medium text-ink-soft",children:t}),a,c?e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:i.reason??l("st.profiles.fieldIgnored",{engine:r??""})}):null,i?.state==="mapped"?e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:i.reason??l("st.profiles.fieldMapped",{engine:r??""})}):null,n!==void 0&&!c?e.jsx("div",{className:"text-[11.5px] leading-snug text-ink-faint",children:n}):null]})}function Br({id:t,value:s,onChange:n,models:a,allowInherit:i,disabled:r,missing:o,unsetLabel:l,unsetTrigger:c,ariaLabel:d}){const{t:u}=D();return e.jsx(nn,{id:t,value:s,disabled:r,models:a,allowInherit:i,missing:o,rawAliasTrigger:!0,unsetLabel:l??u("st.profiles.modelUnset"),unsetTrigger:c,ariaLabel:d??u("st.profiles.model"),searchPlaceholder:"provider/model",buttonClassName:`${Sn} font-mono ${o===!0?"border-amber-ink/50":""}`,onChange:n})}function ou({id:t,value:s,onChange:n,supported:a,disabled:i,allowUnset:r=!0,unsetLabel:o,unsetTrigger:l,ariaLabel:c}){const{t:d}=D(),u=co(a!==void 0&&a.length>0?a:jc),p=[...r?[{value:"",label:o??d("st.profiles.effortUnset")}]:[],...u.map(h=>({value:h,label:Cs(h,d)})),...s!==""&&!u.includes(s)?[{value:s,label:Cs(s,d),hint:d("st.profiles.effortUnsupported")}]:[]];return e.jsx(Jt,{id:t,value:s,disabled:i,options:p,hideFilter:!0,triggerLabel:s===""?l:void 0,ariaLabel:c??d("st.profiles.effort"),buttonClassName:Sn,onChange:n})}function Rg({id:t,values:s,onChange:n,models:a,disabled:i,addLabel:r,choices:o}){const{t:l}=D(),c=new Set(a.map(h=>h.id)),d=e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),r]}),u="inline-flex h-7 items-center rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",p=h=>{const b=h.trim();b!==""&&!s.includes(b)&&n([...s,b])};return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-alias-chips":t,children:[s.map(h=>{const b=a.length>0&&!c.has(h)&&h!=="*";return e.jsxs("span",{"data-alias-chip":h,"data-alias-missing":b?"true":void 0,title:b?l("st.profiles.aliasMissingTitle",{alias:h}):h,className:`inline-flex h-7 max-w-full items-center gap-1 rounded-md border pl-2 pr-0.5 font-mono text-[11.5px] ${b?"border-amber-ink/40 text-amber-ink":"border-hairline text-ink"}`,children:[b?e.jsx(de,{name:"warning",size:12}):null,e.jsx("span",{className:"min-w-0 truncate",children:h}),e.jsx("button",{type:"button",disabled:i,"aria-label":l("st.profiles.removeItem",{item:h}),onClick:()=>n(s.filter(m=>m!==h)),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-ink-faint hover:bg-ink/[0.06] hover:text-ink disabled:opacity-50",children:e.jsx(de,{name:"close",size:12})})]},h)}),o===void 0?e.jsx(nn,{id:`${t}-add`,value:"",models:a.filter(h=>!s.includes(h.id)),allowCustomValue:!0,customValueLabel:h=>h,disabled:i,ariaLabel:r,searchPlaceholder:"provider/model",hideChevron:!0,triggerLabel:d,buttonClassName:u,onChange:p}):e.jsx(Jt,{id:`${t}-add`,value:"",options:o.filter(h=>!s.includes(h.value)),allowCustomValue:!0,disabled:i,ariaLabel:r,searchPlaceholder:r,hideChevron:!0,triggerLabel:d,buttonClassName:u,onChange:p})]})}function Fm({title:t,summary:s,defaultOpen:n=!1,children:a,dataSection:i,count:r}){const o=x.useId();return e.jsxs("details",{open:n,"data-profile-section":i,className:"group [&[open]>summary_[data-chevron]]:rotate-90",children:[e.jsxs("summary",{"aria-controls":o,className:"flex min-h-11 cursor-pointer list-none items-center gap-2 py-2 outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/50 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{"data-chevron":!0,className:"flex shrink-0 text-ink-faint transition-transform duration-[var(--kiki-motion-quick)] motion-reduce:transition-none",children:e.jsx(de,{name:"chevron",size:12})}),e.jsx("span",{className:"text-[13px] font-medium text-ink",children:t}),r!==void 0&&r>0?e.jsx("span",{className:"rounded-[4px] bg-ink/[0.05] px-1.5 text-[11px] tabular-nums text-ink-soft",children:r}):null,s!==void 0?e.jsx("span",{className:"ml-auto min-w-0 truncate text-[12px] text-ink-faint",children:s}):null]}),e.jsx("div",{id:o,className:"space-y-4 pb-4 pl-5",children:a})]})}const Z2={"system.*":"st.executorPrompt.block.system","delegation.*":"st.executorPrompt.block.delegation"};function X2({value:t,onChange:s,engineId:n,engineLabel:a,catalog:i,profileBody:r,disabled:o,profileName:l,workspaceId:c,previewEnabled:d}){const{t:u}=D(),p=n!=="",h=Object.keys(t?.per_engine??{}),[b,m]=x.useState(()=>p&&h.includes(n)?n:""),f=[...new Set([...p?[n]:[],...h])],g=R=>i.find(L=>L.id===R)?.label??R,v=R=>i.find(L=>L.id===R)?.capabilities?.prompt_deliveries,y=b!==""&&!f.includes(b)?"":b,w=y===""?void 0:t?.per_engine?.[y],N=y!==""&&w!==void 0,_=y===""?t??{}:w??{},C=R=>{const L=t??{};if(y===""){s({...L,...R});return}s({...L,per_engine:{...L.per_engine,[y]:{...L.per_engine?.[y],...R}}})},S=()=>{const R=t??{};s({...R,per_engine:{...R.per_engine,[y]:{include:[...R.include??[]]}}})},k=()=>{const R=t??{},L=Object.fromEntries(Object.entries(R.per_engine??{}).filter(([E])=>E!==y)),{per_engine:I,...$}=R;s(Object.keys(L).length>0?{...$,per_engine:L}:$)},j=_.include??[],T=(R,L)=>{C({include:L?[...j.filter(I=>I!==R),R]:j.filter(I=>I!==R)})},A=y===""?p?v(n):void 0:v(y),P=y===""?a:g(y);return e.jsxs("div",{"data-executor-prompt":!0,className:"space-y-4",children:[p?null:e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:u("st.executorPrompt.nativeNote")}),f.length>0?e.jsx(Xt,{label:u("st.executorPrompt.scope"),dataField:"executorPromptScope",children:e.jsx(He,{ariaLabel:u("st.executorPrompt.scope"),value:y,disabled:!1,dataAttr:"data-executor-prompt-scope",onChange:R=>m(R),choices:[{value:"",label:u("st.executorPrompt.scopeAll")},...f.map(R=>({value:R,label:g(R)}))]})}):null,y!==""&&!N?e.jsxs("div",{"data-executor-prompt-inherit":!0,className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("p",{className:"text-[12px] text-ink-soft",children:u("st.executorPrompt.inherits",{engine:P})}),e.jsxs("button",{type:"button",disabled:o,"data-executor-prompt-add-override":!0,onClick:S,className:"inline-flex h-7 items-center gap-1 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:[e.jsx(de,{name:"plus",size:12}),u("st.executorPrompt.addOverride",{engine:P})]})]}):e.jsx(eE,{section:_,editingOverride:N,supported:A,scopeLabel:P,disabled:o,include:j,onToggle:T,onPatch:C,onRemove:k}),p?e.jsx(tE,{value:t,engineId:n,engineLabel:a,supported:v(n),steer:i.find(R=>R.id===n)?.capabilities?.steer,profileBody:r,profileName:l,workspaceId:c,previewEnabled:d}):e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:u("st.executorPrompt.pickEngine")})]})}function yl({checked:t,disabled:s,label:n,onChange:a,dataBlock:i,mono:r=!1}){return e.jsxs("label",{"data-executor-prompt-block":i,"data-checked":t?"true":void 0,className:`flex min-h-8 cursor-pointer items-center gap-2 rounded-md px-1.5 text-[12.5px] text-ink hover:bg-ink/[0.03] ${s?"cursor-not-allowed opacity-60":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 shrink-0 accent-[var(--color-selected-ink)]",checked:t,disabled:s,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:`min-w-0 truncate ${r?"font-mono text-[12px]":""}`,children:n})]})}function eE({section:t,editingOverride:s,supported:n,scopeLabel:a,disabled:i,include:r,onToggle:o,onPatch:l,onRemove:c}){const{t:d}=D(),[u,p]=x.useState(""),b=t.delivery??(s?"":n?.includes("replace")&&!n.includes("append")?"replace":n?.includes("append")?"append":"preamble"),m=r.filter(y=>!Hp.includes(y)&&!zp.includes(y)),f=Qp.test(u.trim()),g=()=>{const y=u.trim();!Qp.test(y)||r.includes(y)||(o(y,!0),p(""))},v=[...s?[{value:"",label:d("st.executorPrompt.deliveryInherit")}]:[],...O0.map(y=>({value:y,label:d(`st.executorPrompt.delivery.${y}`)}))];return e.jsxs(e.Fragment,{children:[e.jsx(Xt,{label:d("st.executorPrompt.delivery"),dataField:"executorPromptDelivery",hint:e.jsxs(e.Fragment,{children:[b!==""?e.jsx("span",{className:"block",children:d(`st.executorPrompt.deliveryHint.${b}`)}):null,n!==void 0?e.jsx("span",{"data-executor-prompt-supported":!0,className:"block",children:d("st.executorPrompt.supports",{engine:a,list:n.map(y=>d(`st.executorPrompt.delivery.${y}`)).join(", ")})}):null]}),children:e.jsx(He,{ariaLabel:d("st.executorPrompt.delivery"),value:b,disabled:i,dataAttr:"data-executor-prompt-delivery",onChange:y=>l({delivery:y===""?void 0:y}),choices:v})}),e.jsxs("fieldset",{className:"min-w-0 space-y-2","data-executor-prompt-include":!0,children:[e.jsx("legend",{className:"mb-1 text-[12px] font-medium text-ink-soft",children:d("st.executorPrompt.include")}),e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:d("st.executorPrompt.groupContext")}),e.jsx("div",{className:"grid grid-cols-1 gap-x-2 sm:grid-cols-2",children:Hp.map(y=>e.jsx(yl,{dataBlock:y,checked:r.includes(y),disabled:i,label:d(`st.executorPrompt.block.${y}`),onChange:w=>o(y,w)},y))}),e.jsx("p",{className:"pt-1 text-[11.5px] text-ink-faint",children:d("st.executorPrompt.groupFields")}),e.jsxs("div",{className:"grid grid-cols-1 gap-x-2 sm:grid-cols-2",children:[zp.map(y=>e.jsx(yl,{dataBlock:y,checked:r.includes(y),disabled:i,label:d(Z2[y]),onChange:w=>o(y,w)},y)),m.map(y=>e.jsx("div",{className:"sm:col-span-2",children:e.jsx(yl,{dataBlock:y,mono:!0,checked:!0,disabled:i,label:y,onChange:w=>o(y,w)})},y))]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 pt-1",children:[e.jsx("input",{"aria-label":d("st.executorPrompt.fieldId"),"data-executor-prompt-field-id":!0,value:u,disabled:i,placeholder:"system.<id>",spellCheck:!1,onChange:y=>p(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!rt(y)&&(y.preventDefault(),g())},"aria-invalid":u.trim()!==""&&!f,className:`${pt} min-w-0 flex-1 font-mono ${u.trim()!==""&&!f?"border-amber-ink/50":""}`}),e.jsxs("button",{type:"button",disabled:i||!f,onClick:g,className:"inline-flex h-8 shrink-0 items-center gap-1 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:[e.jsx(de,{name:"plus",size:12}),d("st.executorPrompt.addField")]})]}),u.trim()!==""&&!f?e.jsx("p",{className:"text-[11.5px] text-amber-ink",children:d("st.executorPrompt.fieldIdInvalid")}):null]}),e.jsx(Xt,{label:d("st.executorPrompt.body"),htmlFor:"executor-prompt-body",hint:d("st.executorPrompt.bodyHint"),dataField:"executorPromptBody",children:e.jsx("textarea",{id:"executor-prompt-body",rows:4,spellCheck:!1,disabled:i,value:t.body??"",onChange:y=>l({body:y.target.value===""?void 0:y.target.value}),className:`${Ce} min-h-20 font-mono text-[12px] leading-[1.6]`})}),e.jsx(Xt,{label:d("st.executorPrompt.append"),htmlFor:"executor-prompt-append",hint:d("st.executorPrompt.appendHint"),dataField:"executorPromptAppend",children:e.jsx("textarea",{id:"executor-prompt-append",rows:3,spellCheck:!1,disabled:i,value:t.append??"",onChange:y=>l({append:y.target.value===""?void 0:y.target.value}),className:`${Ce} min-h-16 font-mono text-[12px] leading-[1.6]`})}),s?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:d("st.executorPrompt.overrideNote")}),e.jsx("button",{type:"button",disabled:i,"data-executor-prompt-remove-override":!0,onClick:c,className:"h-7 shrink-0 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:d("st.executorPrompt.removeOverride",{engine:a})})]}):null]})}function qm(t){const s=t.trim().split(`
|
|
9
|
+
`),n=s.slice(0,4).join(`
|
|
10
|
+
`);return s.length>4||n.length>360?`${n.slice(0,360)}…`:n}function tE({value:t,engineId:s,engineLabel:n,supported:a,steer:i,profileBody:r,profileName:o,workspaceId:l,previewEnabled:c}){const{t:d}=D(),{client:u}=be(),[p,h]=x.useState(null);x.useEffect(()=>{let _=!1;if(h(null),!(!c||l===void 0||typeof u.previewExecutorPrompt!="function"))return(async()=>{try{const C=await u.previewExecutorPrompt(o,l,s);_||h({engine:s,data:C})}catch{_||h(null)}})(),()=>{_=!0}},[u,o,l,s,c]);const b=c&&p?.engine===s?p.data:null,m=D0(t,s),f=t?.per_engine?.[s]?.delivery??t?.delivery??(a?.includes("replace")&&!a.includes("append")?"replace":a?.includes("append")?"append":"preamble"),g=b?.delivery.actual??F0(f,a),v=b?.delivery.downgraded??f!==g,y=q0(m.include),w=m.body??r,N=b!==null?b.blocks.map(_=>({key:_.id,title:_.id==="body"?d("st.executorPrompt.previewBody"):_.id==="append"?d("st.executorPrompt.previewAppend"):`## ${_.id}`,text:_.text,mono:_.id!=="body"&&_.id!=="append"})):[{key:"body",title:m.body!==void 0?d("st.executorPrompt.previewOverride"):d("st.executorPrompt.previewBody"),text:w.trim()===""?void 0:qm(w),empty:w.trim()===""},...m.append!==void 0?[{key:"append",title:d("st.executorPrompt.previewAppend"),text:qm(m.append)}]:[],...y.context.map(_=>({key:_,title:`## ${_}`,mono:!0,pending:!0})),...y.fields.map(_=>({key:_,title:`## ${_}`,mono:!0,pending:!0}))];return e.jsxs("div",{"data-executor-prompt-preview":!0,"data-preview-engine":s,"data-preview-delivery":g,"data-preview-source":b===null?"plan":"server",className:"space-y-2 rounded-lg border border-hairline bg-paper px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:d("st.executorPrompt.preview",{engine:n})}),e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:d("st.executorPrompt.previewAs",{delivery:d(`st.executorPrompt.delivery.${g}`)})})]}),v?e.jsxs("p",{"data-executor-prompt-downgrade":!0,className:"flex gap-1.5 text-[11.5px] leading-snug text-amber-ink",children:[e.jsx(de,{name:"warning",size:12,className:"mt-px shrink-0"}),d("st.executorPrompt.downgrade",{engine:n,requested:d(`st.executorPrompt.delivery.${b?.delivery.requested??f}`),actual:d(`st.executorPrompt.delivery.${g}`)})]}):null,e.jsx("ol",{className:"space-y-1.5",children:N.map((_,C)=>e.jsxs("li",{"data-preview-part":_.key,className:"min-w-0 border-l-2 border-hairline pl-3",children:[e.jsxs("p",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 text-[11.5px]",children:[e.jsx("span",{className:"shrink-0 tabular-nums text-ink-faint",children:C+1}),e.jsx("span",{className:`min-w-0 break-all text-ink-soft ${_.mono===!0?"font-mono":"font-medium"}`,children:_.title}),_.pending===!0?e.jsxs("span",{className:"shrink-0 text-ink-faint",children:["· ",d("st.executorPrompt.previewResolved")]}):null]}),_.text!==void 0?e.jsx("pre",{className:`mt-0.5 whitespace-pre-wrap break-words font-mono text-[11.5px] leading-[1.55] text-ink-faint ${b===null?"line-clamp-4":"max-h-64 overflow-auto"}`,children:_.text}):null,_.empty===!0?e.jsx("p",{className:"mt-0.5 text-[11.5px] text-ink-faint",children:d("st.executorPrompt.previewEmptyBody")}):null]},_.key))}),b===null?e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:d("st.executorPrompt.previewNoText")}):null,i!==void 0?e.jsxs("p",{"data-executor-prompt-steer":!0,className:"pt-2 text-[11.5px] leading-snug text-ink-faint",children:[d("st.executorPrompt.steer",{mode:d(`st.executorPrompt.steerMode.${i}`)})," ",d("st.executorPrompt.steerLimit")]}):null]})}const Bm=["kiki_dispatch","kiki_wait","kiki_result"];function sE({names:t,more:s=0}){const{tp:n}=D();return e.jsxs("p",{className:"min-w-0 break-words font-mono text-[11px] leading-snug text-ink-faint",children:[t.join(" · "),s>0?e.jsxs("span",{className:"font-sans",children:[" · ",n("st.kikiContext.moreTools",s)]}):null]})}function kl({id:t,label:s,hint:n,tools:a,moreTools:i,checked:r,disabled:o,onChange:l,children:c}){return e.jsxs("li",{"data-kiki-capability":t,"data-on":r?"true":"false",className:"space-y-1",children:[e.jsx(Be,{layout:"row",label:s,checked:r,disabled:o,onChange:l}),e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:n}),a!==void 0?e.jsx(sE,{names:a,more:i}):null,c]})}const nE={SessionStart:"st.kikiContext.moment.SessionStart",UserPromptSubmit:"st.kikiContext.moment.UserPromptSubmit",PreCompact:"st.kikiContext.moment.PreCompact",Stop:"st.kikiContext.moment.Stop",PreInvocation:"st.kikiContext.moment.PreInvocation"};function aE({moment:t}){const{t:s}=D();return e.jsxs("li",{"data-hook-moment":t.event,"data-hook-effect":t.effect,className:"col-span-2 grid grid-cols-subgrid items-baseline text-[11.5px] leading-snug",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink-soft",children:t.event}),e.jsx("span",{className:t.effect==="prepare"?"text-ink-faint":"text-ink-soft",children:s(nE[t.event]??"st.kikiContext.moment.other")})]})}function iE({draft:t,baseline:s,engine:n,disabled:a,onChange:i}){const{t:r,tp:o}=D(),l=t.kikiContext??[],c=h=>l.includes(h),d=(h,b)=>i({allowKikiSubagents:t.allowKikiSubagents,kikiContext:B0(t.kikiContext,h,b,s.kikiContext)}),u=OC(t.executor),p=c("hooks");return e.jsxs("div",{"data-kiki-context":!0,className:"space-y-3",children:[e.jsxs("ul",{className:"space-y-3",children:[e.jsx(kl,{id:"subagents",label:r("st.profiles.kikiSubagents"),hint:r("st.profiles.kikiSubagentsHint",{engine:n}),tools:Bm,moreTools:DC().filter(h=>!Bm.includes(h)).length,checked:t.allowKikiSubagents,disabled:a,onChange:h=>i({allowKikiSubagents:h,kikiContext:t.kikiContext})}),FC.map(h=>e.jsx(kl,{id:h,label:r(`st.kikiContext.group.${h}`),hint:r(`st.kikiContext.hint.${h}`,{engine:n}),tools:qC(h),checked:c(h),disabled:a,onChange:b=>d(h,b)},h))]}),e.jsx("div",{className:"pt-3",children:e.jsx("ul",{children:e.jsxs(kl,{id:"hooks",label:r("st.kikiContext.group.hooks"),hint:r("st.kikiContext.hint.hooks",{engine:n}),checked:p,disabled:a||u.level==="unsupported"&&!p,onChange:h=>d("hooks",h),children:[e.jsxs("p",{"data-hook-support":u.level,className:"flex flex-wrap items-baseline gap-x-1.5 text-[11.5px] leading-snug",children:[e.jsx("span",{className:"text-ink-soft",children:n}),e.jsx("span",{className:u.level==="supported"?"font-medium text-ink":u.level==="untested"?"font-medium text-amber-ink":"text-ink-faint",children:r(`st.kikiContext.support.${u.level}`)}),u.level!=="supported"?e.jsxs("span",{className:"text-ink-faint",children:["· ",r(`st.kikiContext.supportHint.${u.level}`)]}):null]}),u.moments.length>0?e.jsx("ul",{"data-hook-moments":!0,"aria-label":r("st.kikiContext.momentsLabel"),className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5 pt-0.5",children:u.moments.map(h=>e.jsx(aE,{moment:h},h.event))}):null]})})}),e.jsxs("div",{"data-kiki-context-field":t.kikiContext===void 0?"absent":t.kikiContext.length===0?"empty":"list",className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 pt-2.5",children:[e.jsxs("p",{className:"min-w-0 text-[11.5px] leading-snug text-ink-faint",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink-soft",children:"kiki_context"})," ",t.kikiContext===void 0?r("st.kikiContext.fieldAbsent"):t.kikiContext.length===0?r("st.kikiContext.fieldEmpty"):o("st.kikiContext.fieldList",t.kikiContext.length)]}),t.kikiContext!==void 0?e.jsx("button",{type:"button","data-kiki-context-clear":!0,disabled:a,onClick:()=>i({allowKikiSubagents:t.allowKikiSubagents,kikiContext:void 0}),className:"h-7 shrink-0 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50",children:r("st.kikiContext.clear")}):null]})]})}function rE({values:t,onChange:s,models:n,disabled:a}){const{t:i}=D(),r=(l,c)=>s(t.map((d,u)=>u===l?{...d,...c}:d)),o=l=>n.find(c=>c.id===l)?.support_efforts;return e.jsxs("div",{className:"space-y-2","data-model-profiles-field":!0,children:[t.length>0?e.jsx("ul",{className:"divide-y divide-hairline rounded-lg border border-hairline",children:t.map((l,c)=>e.jsxs("li",{"data-model-profile-row":l.alias||c,className:"min-w-0 space-y-2 px-3 py-3",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_7rem_auto] items-center gap-2",children:[e.jsx(Br,{id:`mp-model-${c}`,value:l.alias,models:n,allowInherit:!1,disabled:a,ariaLabel:i("st.profiles.candidateModel"),missing:l.alias!==""&&n.length>0&&!n.some(d=>d.id===l.alias),onChange:d=>r(c,{alias:d})}),e.jsx(ou,{id:`mp-effort-${c}`,value:l.effort,supported:o(l.alias),disabled:a,onChange:d=>r(c,{effort:d})}),e.jsx("button",{type:"button",disabled:a,"aria-label":i("st.profiles.removeItem",{item:l.alias||i("st.profiles.candidateModel")}),onClick:()=>s(t.filter((d,u)=>u!==c)),className:"flex h-9 w-9 items-center justify-center rounded-md text-ink-faint hover:bg-ink/[0.05] hover:text-ink disabled:opacity-50",children:e.jsx(de,{name:"close",size:12})})]}),e.jsx("input",{id:`mp-when-${c}`,"aria-label":i("st.profiles.when"),className:`${Ce} text-[12.5px]`,value:l.when,disabled:a,placeholder:i("st.profiles.whenPlaceholder"),onChange:d=>r(c,{when:d.target.value})}),e.jsxs("details",{"data-model-profile-prompts":!0,children:[e.jsx("summary",{className:"cursor-pointer py-1 text-[12px] text-ink-soft",children:i("st.promptIdentity.bodyTitle")}),e.jsxs("div",{className:"pt-3",children:[e.jsx(Ca,{value:l.modelPrompt??Er(void 0,K0),disabled:a,onChange:d=>r(c,{modelPrompt:d}),children:(d,u,p)=>e.jsx(M2,{value:d,onChange:u,label:p})}),l.modelPrompt!==void 0?e.jsx(Km,{problem:xa(l.modelPrompt,H0,U0)}):null]})]}),e.jsxs("details",{"data-model-profile-overrides":!0,children:[e.jsx("summary",{className:"cursor-pointer py-1 text-[12px] text-ink-soft",children:i("st.promptIdentity.fieldsTitle")}),e.jsxs("div",{className:"pt-3",children:[e.jsx(Ca,{value:l.promptOverrides??Er(void 0,sn),disabled:a,onChange:d=>r(c,{promptOverrides:d}),children:(d,u,p)=>e.jsx(Eo,{value:d,onChange:u,label:p})}),l.promptOverrides!==void 0?e.jsx(Km,{problem:xa(l.promptOverrides,Bs,lo)}):null]})]})]},c))}):e.jsx("p",{className:"text-[12px] text-ink-faint",children:i("st.profiles.modelProfilesEmpty")}),e.jsxs("button",{type:"button",disabled:a,"data-model-profile-add":!0,onClick:()=>s([...t,{alias:"",when:"",effort:""}]),className:"inline-flex h-8 items-center gap-1 rounded-md px-2 text-[12.5px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:[e.jsx(de,{name:"plus",size:12}),i("st.profiles.addCandidate")]})]})}function Km({problem:t}){const{t:s}=D();return t===void 0?null:e.jsx("p",{role:"alert",className:"pt-2 text-[12px] leading-5 text-danger",children:s(`st.promptIdentity.problem.${t}`)})}function oE({value:t,pending:s=!1,error:n=!1,onRetry:a}){const{t:i}=D(),r=(o,l)=>o.length===0?e.jsx("span",{className:"text-ink-soft",children:i("st.profiles.menuEmpty")}):e.jsx("ul",{className:"space-y-1",children:o.map(c=>e.jsxs("li",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"break-all font-mono text-[11.5px] text-ink",children:c}),l&&c===t?.defaultAlias?e.jsx("span",{className:"text-[11px] text-ink-soft",children:i("st.profiles.menuDefault")}):null]},c))});return e.jsxs("div",{"data-model-menu-preview":!0,className:"space-y-2 border-y border-hairline py-3 text-[12px] leading-relaxed","aria-live":"polite","aria-busy":s,children:[t!==void 0?e.jsxs("dl",{className:"space-y-3",children:[e.jsxs("div",{"data-menu-declared":!0,children:[e.jsx("dt",{className:"mb-1 font-medium text-ink-soft",children:i("st.profiles.declaredMenu")}),e.jsx("dd",{children:r(t.declared,!0)})]}),e.jsxs("div",{"data-menu-effective":!0,children:[e.jsx("dt",{className:"mb-1 font-medium text-ink-soft",children:i("st.profiles.effectiveModels")}),e.jsx("dd",{children:s?e.jsx("span",{className:"text-ink-soft",children:i("st.profiles.menuPreviewPending")}):n?e.jsx("span",{className:"text-danger",children:i("st.profiles.menuPreviewError")}):t.effective===void 0?e.jsx("span",{className:"text-ink-soft",children:i("st.profiles.menuPreviewUnavailable")}):r(t.effective,!1)})]})]}):e.jsx("p",{className:n?"text-danger":"text-ink-soft",children:i(n?"st.profiles.menuPreviewError":s?"st.profiles.menuPreviewPending":"st.profiles.menuPreviewUnavailable")}),n&&a!==void 0?e.jsx("button",{type:"button",onClick:a,className:"min-h-9 px-1 text-ink underline underline-offset-2 focus-visible:outline-2 focus-visible:outline-selected-ink",children:i("common.retry")}):null,!s&&!n&&t?.effective?.length===0?e.jsx("p",{"data-menu-empty":!0,role:"alert",className:"text-danger",children:i("st.profiles.menuNoCandidates")}):null,!s&&!n&&(t?.added?.length??0)>0?e.jsx("p",{"data-menu-added":!0,className:"break-words text-ink",children:i("st.profiles.menuAdded",{models:t.added.join(", ")})}):null,!s&&!n&&(t?.removed?.length??0)>0?e.jsx("p",{"data-menu-removed":!0,className:"break-words font-medium text-amber-ink",children:i("st.profiles.menuRemoved",{models:t.removed.join(", ")})}):null,!s&&!n?t?.diagnostics?.map((o,l)=>e.jsx("p",{className:"break-words text-ink-soft",children:o},l)):null]})}function lE({checked:t,baselineChecked:s,disabled:n,onChange:a,preview:i,pending:r,error:o,onRetry:l}){const{t:c}=D();return e.jsxs("div",{"data-profile-field":"restrictModelsToMenu",className:"space-y-2",children:[e.jsx(Be,{layout:"row",label:c("st.profiles.restrictModelsToMenu"),checked:t,disabled:n,onChange:a}),t?e.jsx(oE,{value:i,pending:r,error:o,onRetry:l}):null,!t&&s?e.jsx("p",{"data-menu-disabled":!0,role:"status",className:"text-[12px] text-amber-ink",children:c("st.profiles.menuDisabled")}):null]})}const Um={allow:"st.profiles.ruleAllow",prefer:"st.profiles.rulePrefer",avoid:"st.profiles.ruleAvoid",block:"st.profiles.ruleBlock"},cE="sm:grid-cols-[5.5rem_repeat(4,minmax(0,1fr))]";function Hm({title:t,rows:s,action:n,dataRules:a}){const{t:i}=D(),r=["allow","prefer","avoid","block"],o=cE;return e.jsxs("section",{"data-model-rules":a,"aria-label":t,className:"min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex min-h-7 items-center justify-between gap-2",children:[e.jsx("h4",{className:"text-[13px] font-semibold text-ink",children:t}),n]}),e.jsxs("div",{className:"min-w-0 rounded-lg border border-hairline",children:[e.jsxs("div",{className:`hidden gap-x-4 border-b border-hairline px-3 py-1.5 text-[11.5px] text-ink-faint sm:grid ${o}`,"aria-hidden":!0,children:[e.jsx("span",{}),r.map(l=>e.jsx("span",{"data-rule-column":l,className:l==="block"||l==="allow"?"font-medium text-ink-soft":"text-ink-faint",children:i(Um[l])},l))]}),s.map((l,c)=>e.jsxs("div",{"data-rule-row":l.id,className:`grid min-w-0 grid-cols-1 gap-x-4 gap-y-2 px-3 py-2.5 ${o} ${c>0?"border-t border-hairline":""}`,children:[e.jsx("span",{className:"pt-1 text-[12px] font-medium text-ink-soft",children:l.label}),r.map(d=>{const u=l.cells[d];return u==null?e.jsx("span",{"aria-hidden":!0,className:"hidden h-7 items-center text-[12px] text-ink-faint/60 sm:inline-flex",children:"—"},d):e.jsxs("div",{"data-rule-cell":d,className:"min-w-0",children:[e.jsx("span",{className:"mb-1 block text-[11px] text-ink-faint sm:hidden",children:i(Um[d])}),u]},d)})]},l.id))]})]})}function zn({id:t,values:s,onChange:n,models:a,disabled:i,any:r=!1}){const{t:o}=D();return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r&&s.length===0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:o("st.profiles.ruleAny")}):null,e.jsx(Rg,{id:t,values:s,models:a,disabled:i,addLabel:o("st.profiles.addModel"),onChange:n})]})}function jl({values:t,onChange:s,disabled:n,dataAttr:a,any:i=!1,ordered:r=!1,label:o}){const{t:l}=D(),c=d=>r?[...t,d]:jc.filter(u=>u===d||t.includes(u));return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",role:"group","aria-label":o,children:[jc.map(d=>{const u=t.includes(d);return e.jsx("button",{type:"button","aria-pressed":u,disabled:n,[a]:d,onClick:()=>s(u?t.filter(p=>p!==d):c(d)),className:`h-7 rounded-md border px-1.5 text-[12px] transition-colors focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50 ${u?"border-hairline-strong bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"border-transparent text-ink-soft hover:bg-ink/[0.04] hover:text-ink"}`,children:Cs(d,l)},d)}),i&&t.length===0?e.jsx("span",{className:"pl-1 text-[11.5px] text-ink-faint",children:l("st.profiles.ruleAny")}):null]})}function dE(t,s){const n=t.model_profiles?.map(i=>({alias:i.alias}))??t.model_profiles,a=s!==void 0&&JSON.stringify(n??[])===JSON.stringify(s.model_profiles?.map(i=>({alias:i.alias}))??[]);return{pinned_model_alias:t.pinned_model_alias,restrict_models_to_menu:t.restrict_models_to_menu,model_profiles:a?void 0:n,allowed_models:t.allowed_models,deny_models:t.deny_models,executor:t.executor,main:t.main}}function uE(t,s,n){const{client:a}=be(),i=Object.values(s).some(d=>d!==void 0),r=n&&i,o=je({queryKey:["profile-model-menu-preview",t.workspace_id,t.source_file,t.name,s],queryFn:({signal:d})=>{const u=a.klient.rest?.agents;if(u===void 0)throw new Error("Model menu preview is unavailable");return u.previewModelMenu(t.name,{workspace_id:t.workspace_id,source_file:t.source_file,draft:s},{signal:d})},enabled:r&&t.workspace_id!==void 0,staleTime:0,retry:!1}),l=r?o.data:t;return{value:l?.declared_model_menu===void 0?void 0:{declared:l.declared_model_menu.aliases,defaultAlias:l.declared_model_menu.default_alias,effective:l.effective_model_aliases,added:r?o.data?.added_model_identities:void 0,removed:r?o.data?.removed_model_identities:void 0},pending:r&&o.isPending,error:r&&o.isError,ready:!r||o.isSuccess,retry:()=>{o.refetch()}}}function pE({profile:t,writable:s,onSaved:n,reloadToken:a}){const{client:i}=be(),{t:r,locale:o}=D(),[l,c]=x.useState(null),[d,u]=x.useState(null),[p,h]=x.useState(null),[b,m]=x.useState(!1),[f,g]=Je(),v=s&&l!==null&&d!==null&&l!==d;x.useEffect(()=>{if(t.source_file===void 0)return;let w=!1;return h(null),i.readHostFile(t.source_file).then(N=>{w||(c(N),u(N))}).catch(N=>{w||h(oe(o,N))}),()=>{w=!0}},[i,t.source_file,a,o]);const y=async()=>{if(!(!s||l===null||t.workspace_id===void 0)){m(!0),h(null);try{const w=await i.updateNamedAgentProfile(t.name,{scope:z0(t),workspace_id:t.workspace_id,source_file:t.source_file,raw_text:l});u(l),g(),n(w)}catch(w){h(oe(o,w))}finally{m(!1)}}};return t.source_file===void 0?e.jsxs("div",{"data-profile-raw":!0,className:"flex min-h-0 flex-1 flex-col gap-2",children:[e.jsx(he,{children:r("st.profiles.rawBuiltin")}),t.prompt!==void 0?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap rounded-lg border border-hairline bg-paper p-3 font-mono text-[12px] leading-relaxed text-ink-soft",children:t.prompt}):null]}):e.jsxs("div",{"data-profile-raw":!0,className:"flex min-h-0 flex-1 flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] text-ink-faint",children:r(s?"st.profiles.rawHint":"st.profiles.rawReadOnly")}),l===null&&p===null?e.jsx(he,{children:r("st.namedAgents.rawLoading")}):null,l!==null?e.jsx("textarea",{"aria-label":r("st.profiles.rawLabel",{file:t.source_file}),spellCheck:!1,readOnly:!s,value:l,onChange:w=>{c(w.target.value)},className:"min-h-[24rem] flex-1 resize-none rounded-lg border border-hairline bg-paper p-3 font-mono text-[12px] leading-relaxed text-ink outline-none focus:border-selected-ink"}):null,p!==null?e.jsx("div",{"data-raw-error":!0,className:"whitespace-pre-wrap",children:e.jsx(pe,{feedback:{tone:"error",text:p}})}):null,s?e.jsx(lt,{id:`agent-raw:${t.source_file}`,dirty:v,saving:b,saved:f,saveLabel:r("st.namedAgents.saveRaw"),onSave:()=>void y(),onDiscard:()=>{c(d),h(null)}}):null]})}function mE({draft:t,onChange:s,profiles:n,models:a,disabled:i,self:r}){const{t:o}=D(),l=t.subagentPolicy;return e.jsxs("div",{className:"space-y-8","data-subagents-field":!0,children:[e.jsx(xE,{policy:l,disabled:i,onChange:c=>s({subagentPolicy:{...l,canSpawnSubagents:c}})}),l.canSpawnSubagents===!1?null:e.jsxs("div",{className:"space-y-8","data-dispatch-lists":!0,children:[e.jsx(hE,{policy:l,onChange:s,profiles:n,models:a,disabled:i,self:r}),e.jsxs("div",{className:"grid min-w-0 gap-8 sm:grid-cols-2",children:[e.jsx(zm,{id:"preferred",list:l.preferredSubagents,policy:l,known:l.allowedSubagents?.map(c=>c.name),onChange:s,disabled:i,titleKey:"st.profiles.dispatchPreferred",addLabel:o("st.profiles.dispatchAddToPreferred")}),e.jsx(zm,{id:"deny",list:l.denySubagents,policy:l,known:l.allowedSubagents?.map(c=>c.name),onChange:s,disabled:i,titleKey:"st.profiles.dispatchDeny",addLabel:o("st.profiles.dispatchAddToDeny")})]})]})]})}function xE({policy:t,disabled:s,onChange:n}){const{t:a}=D(),i=t.canSpawnSubagents;return e.jsxs("div",{"data-dispatch-can-spawn":!0,"data-profile-field":"canSpawnSubagents","data-declared":i===void 0?"false":"true",className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1.5",children:[e.jsx("span",{className:"min-w-0 text-[13px] font-semibold text-ink",children:a("st.profiles.dispatchCanSpawn")}),e.jsx(He,{ariaLabel:a("st.profiles.dispatchCanSpawn"),value:i===void 0?"inherit":i?"on":"off",disabled:s,dataAttr:"data-dispatch-can-spawn-mode",onChange:r=>n(r==="inherit"?void 0:r==="on"),choices:[{value:"inherit",label:a("st.profiles.dispatchNotDeclared")},{value:"on",label:a("st.profiles.dispatchCanSpawnOn")},{value:"off",label:a("st.profiles.dispatchCanSpawnOff")}]})]}),i===!1?e.jsx("p",{className:"text-[12px] text-ink-faint",children:a("st.profiles.dispatchCanSpawnOffShort")}):null]})}function hE({policy:t,onChange:s,profiles:n,models:a,disabled:i,self:r}){const{t:o}=D(),[l,c]=x.useState(null),[d,u]=x.useState(null),p=t.allowedSubagents,h=p!==void 0,b=sl(p),m=(b?(p??[]).filter(S=>!Q0(S.name)):p)??[],f=new Map(n.map(S=>[S.name,S])),g=new Set((p??[]).map(S=>S.name)),v=new Set(t.denySubagents??[]),y=[...new Map(n.filter(S=>S.name!==r&&!g.has(S.name)).map(S=>[S.name,S])).values()].toSorted((S,k)=>Number(S.main)-Number(k.main)||S.name.localeCompare(k.name)),w=S=>s({subagentPolicy:{...t,allowedSubagents:b?[{name:W0,modelAlias:"",effort:""},...S]:S}}),N=(S,k)=>w(m.map((j,T)=>T===S?{...j,...k}:j)),_=(S,k)=>{if(S===k||k<0||k>=m.length)return;const j=[...m],[T]=j.splice(S,1);j.splice(k,0,T),w(j)},C=m.length-1;return e.jsxs("div",{className:"space-y-2.5","data-dispatch-allowed":!0,"data-declared":h?"true":"false",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("span",{className:"min-w-0 text-[13px] font-semibold text-ink",children:o("st.profiles.dispatchAllowed")}),e.jsx("span",{className:"flex-1"}),b?e.jsx("button",{type:"button","data-dispatch-allowed-narrow":!0,disabled:i,onClick:()=>s({subagentPolicy:{...t,allowedSubagents:m}}),className:Qm,children:o("st.profiles.dispatchNarrowToList")}):null,h?e.jsx("button",{type:"button","data-dispatch-allowed-clear":!0,disabled:i,onClick:()=>s({subagentPolicy:{...t,allowedSubagents:G0(p)}}),className:Qm,children:o("st.profiles.dispatchClearList")}):null]}),!h||sl(p)?e.jsx("p",{"data-dispatch-allowed-unset":!0,className:"text-[12px] text-ink-faint",children:o(sl(p)?"st.profiles.dispatchAllowedOpen":"st.profiles.dispatchAllowedUnset")}):p.length===0?e.jsx("p",{"data-dispatch-allowed-empty":!0,className:"text-[12px] text-ink-faint",children:o("st.profiles.dispatchAllowedEmpty")}):null,m.length>0?e.jsx("ol",{className:"divide-y divide-hairline rounded-lg border border-hairline","data-subagent-rows":!0,children:m.map((S,k)=>{const j=f.get(S.name),T=j===void 0&&S.source===void 0,A=j===void 0||(j.executor??"native")!=="native"?[]:a,P=j?.pinned_model_alias,R=j?.thinking_effort;return e.jsxs("li",{"data-subagent-row":S.name,draggable:!i,onDragStart:L=>{c(k),L.dataTransfer.effectAllowed="move",L.dataTransfer.setData("text/plain",S.name)},onDragOver:L=>{l!==null&&(L.preventDefault(),u(k))},onDrop:L=>{L.preventDefault(),l!==null&&_(l,k),c(null),u(null)},onDragEnd:()=>{c(null),u(null)},className:`grid min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-1 px-1.5 pb-2 pt-1 ${l===k?"opacity-50":""} ${d===k&&l!==null&&l!==k?"bg-ink/[0.04]":""}`,children:[e.jsx("span",{"aria-hidden":!0,className:`flex h-8 w-5 items-center justify-center text-ink-faint ${i?"":"cursor-grab active:cursor-grabbing"}`,children:e.jsx(de,{name:"grip",size:12})}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"w-4 shrink-0 text-right text-[11px] tabular-nums text-ink-faint",children:k+1}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[12.5px] text-ink",title:S.name,children:S.name}),j?.main===!0?e.jsx("span",{className:wl,title:o("st.profiles.rosterMainMemberHint"),children:o("st.agentManager.main")}):null,S.source!==void 0?e.jsx("span",{className:wl,title:S.source,children:o("st.profiles.scopedLease")}):null,v.has(S.name)?e.jsx("span",{className:wl,children:o("st.profiles.dispatchDeny")}):null,T?e.jsxs("span",{"data-subagent-missing":!0,className:"inline-flex shrink-0 items-center text-amber-ink",title:o("st.profiles.subagentMissing"),children:[e.jsx(de,{name:"warning",size:12}),e.jsx("span",{className:"sr-only",children:o("st.profiles.subagentMissing")})]}):null]}),e.jsxs("div",{className:"col-span-3 col-start-1 grid min-w-0 grid-cols-[minmax(0,1fr)_6.5rem] gap-2 pl-7",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(Br,{id:`lease-model-${S.name}`,value:S.modelAlias,models:A,allowInherit:!0,disabled:i,unsetLabel:o("st.profiles.leaseInherits",{value:P??o("st.profiles.modelUnset")}),unsetTrigger:e.jsx("span",{className:"truncate font-mono text-ink-soft",children:P??e.jsx("span",{className:"font-sans",children:o("st.profiles.modelUnset")})}),ariaLabel:`${S.name} · ${o("st.profiles.leaseModel")}`,missing:S.modelAlias!==""&&S.modelAlias!=="inherit"&&A.length>0&&!A.some(L=>L.id===S.modelAlias),onChange:L=>N(k,{modelAlias:L})})}),e.jsx(ou,{id:`lease-effort-${S.name}`,value:S.effort,disabled:i,unsetLabel:o("st.profiles.leaseInherits",{value:R!==void 0?Cs(R,o):o("st.profiles.effortUnset")}),unsetTrigger:e.jsx("span",{className:"truncate text-ink-soft",children:R!==void 0?Cs(R,o):o("st.profiles.effortUnset")}),ariaLabel:`${S.name} · ${o("st.profiles.leaseEffort")}`,onChange:L=>N(k,{effort:L})})]}),S.modelProfiles!==void 0?e.jsxs("div",{className:"col-span-3 min-w-0 space-y-1 pl-7 pt-2","data-lease-model-prompts":S.name,children:[e.jsx("p",{className:"text-[12px] text-ink-soft",children:o("st.promptIdentity.leaseTitle")}),e.jsx(He,{value:S.modelPrompts??"preserve",disabled:i,ariaLabel:`${S.name}: ${o("st.promptIdentity.leaseTitle")}`,onChange:L=>N(k,{modelPrompts:L}),choices:[{value:"preserve",label:o("st.promptIdentity.leasePreserve")},{value:"replace",label:o("st.promptIdentity.leaseReplace")}]})]}):null,e.jsxs("span",{className:"col-start-3 row-start-1 flex shrink-0 items-center",children:[e.jsx("button",{type:"button","data-subagent-up":S.name,disabled:i||k===0,"aria-label":o("st.profiles.moveUp",{item:S.name}),onClick:()=>_(k,k-1),className:Nl,children:e.jsx(de,{name:"arrowUp",size:12})}),e.jsx("button",{type:"button","data-subagent-down":S.name,disabled:i||k===C,"aria-label":o("st.profiles.moveDown",{item:S.name}),onClick:()=>_(k,k+1),className:Nl,children:e.jsx(de,{name:"arrowDown",size:12})}),e.jsx("button",{type:"button","data-subagent-remove":S.name,disabled:i,"aria-label":o("st.profiles.removeItem",{item:S.name}),onClick:()=>w(m.filter((L,I)=>I!==k)),className:Nl,children:e.jsx(de,{name:"close",size:12})})]})]},S.name)})}):null,e.jsx(Jt,{id:"dispatch-add-preset",value:"",disabled:i,hideChevron:!0,allowCustomValue:!0,options:y.map(S=>({value:S.name,label:S.name,description:S.description,hint:S.pinned_model_alias,group:S.main?o("st.agentManager.main"):o("st.agentManager.subagent")})),ariaLabel:o("st.profiles.dispatchAddToAllowed"),searchPlaceholder:o("st.profiles.searchAgents"),emptyText:o("st.profiles.noMoreAgents"),triggerLabel:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),o("st.profiles.dispatchAddToAllowed")]}),buttonClassName:"inline-flex h-8 items-center rounded-md px-2 text-[12.5px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",onChange:S=>{S!==""&&w([...m,{name:S,modelAlias:"",effort:""}])}})]})}function zm({id:t,list:s,policy:n,known:a,onChange:i,disabled:r,titleKey:o,addLabel:l}){const{t:c}=D(),d=new Set(a),u=p=>i({subagentPolicy:{...n,[t==="deny"?"denySubagents":"preferredSubagents"]:p}});return e.jsxs("div",{className:"min-w-0 space-y-2","data-dispatch-names":t,"data-declared":s===void 0?"false":"true",children:[e.jsxs("div",{className:"flex h-7 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 text-[13px] font-semibold text-ink",children:c(o)}),s!==void 0&&s.length>0?e.jsx("button",{type:"button","data-dispatch-clear":t,disabled:r,onClick:()=>u([]),className:"h-7 shrink-0 rounded-md px-2 text-[12px] text-ink-faint hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:c(t==="deny"?"st.profiles.dispatchClearDeny":"st.profiles.dispatchClearPreferred")}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[(s??[]).map((p,h)=>{const b=a!==void 0&&!d.has(p);return e.jsxs("span",{"data-dispatch-chip":t,"data-dispatch-name":p,title:b?c("st.profiles.dispatchCustomName"):p,className:`inline-flex h-7 max-w-full items-center gap-1 rounded-md border pl-2 pr-0.5 font-mono text-[11.5px] ${b?"border-hairline text-ink-soft":"border-hairline text-ink"}`,children:[t==="preferred"?e.jsx("span",{className:"w-3.5 shrink-0 text-right text-[10.5px] tabular-nums text-ink-faint",children:h+1}):null,e.jsx("span",{className:"min-w-0 truncate",children:p}),e.jsx("button",{type:"button",disabled:r,"aria-label":c("st.profiles.removeItem",{item:p}),onClick:()=>u((s??[]).filter(m=>m!==p)),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-ink-faint hover:bg-ink/[0.06] hover:text-ink disabled:opacity-50",children:e.jsx(de,{name:"close",size:12})})]},p)}),e.jsx(Jt,{id:`dispatch-add-${t}`,value:"",options:[],allowCustomValue:!0,disabled:r,hideFilter:!0,ariaLabel:l,searchPlaceholder:l,emptyText:c("st.profiles.noMoreAgents"),hideChevron:!0,triggerLabel:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),l]}),buttonClassName:`inline-flex h-7 items-center rounded-md px-2 ${(s??[]).length===0?"-ml-2":""} text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50`,onChange:p=>{const h=p.trim();h!==""&&!(s??[]).includes(h)&&u([...s??[],h])}})]})]})}const Qm="h-7 shrink-0 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",wl="shrink-0 rounded-[4px] bg-ink/[0.05] px-1.5 text-[11px] text-ink-soft",Nl="flex h-8 w-7 shrink-0 items-center justify-center rounded-md text-ink-faint hover:bg-ink/[0.05] hover:text-ink disabled:opacity-30 disabled:hover:bg-transparent",fE=["main","sub","independent"];function _n(t){const s=t.startsWith("sha256:")?t.slice(7):t;return s.length>12?s.slice(0,12):s}function Fc(t){return t.health==="ready"}function bE(t){const s=Object.keys(t),n=s.filter(a=>a!=="recipe.toml").toSorted();return s.includes("recipe.toml")?[...n,"recipe.toml"]:n}function Lg(t){return t.path===void 0?t.message:`${t.path}: ${t.message}`}function Mg({recipe:t,sourceFile:s,values:n,options:a,disabled:i=!1,onChange:r}){const{client:o}=be(),{t:l,locale:c}=D(),d=x.useId(),[u,p]=x.useState(!1),[h,b]=x.useState(null),m=t!==void 0&&t!=="off",f=s?.replaceAll("\\","/"),v=t!==void 0&&!/^(?:[a-z][a-z0-9+.-]*:|\/|~)/iu.test(t)&&(t.startsWith(".")||/[\\/]|\.toml$/iu.test(t))&&f!==void 0?`${f.slice(0,f.lastIndexOf("/")+1)}${t}`:t,y=je({queryKey:["recipe-options",v,n],queryFn:async()=>(n===void 0?await o.getRecipe(v):await o.getRecipe(v,n))??null,enabled:m&&a===void 0,retry:!1});if(!m)return null;const w=t,N=a??y.data?.resolved.options??[],_=a===void 0?y.data?.resolved.diagnostics??[]:[],C=_.map((S,k)=>e.jsx(pe,{feedback:{tone:"error",text:`${w}: ${Lg(S)}`}},`${S.code}-${k}`));return y.isError&&a===void 0?e.jsx(pe,{feedback:{tone:"error",text:`${w}: ${oe(c,y.error)}`}}):y.data===null&&a===void 0?e.jsx(pe,{feedback:{tone:"error",text:`${w}: ${l("st.recipe.dangling")}`}}):N.length===0?_.length===0?null:e.jsx("div",{"data-recipe-options-diagnostics":!0,children:C}):e.jsxs("fieldset",{className:"min-w-0",disabled:i||u,"data-recipe-options":!0,children:[e.jsx("legend",{className:"text-[13px] font-medium text-ink",children:l("st.recipe.options")}),e.jsx(Ze,{children:N.map(S=>e.jsx("div",{"data-recipe-option":S.id,children:e.jsx(ge,{label:S.name,htmlFor:`${d}-${S.id}`,help:S.description,children:e.jsx(Be,{id:`${d}-${S.id}`,layout:"bare",label:S.name,checked:n?.[S.id]??S.default,disabled:i||u,onChange:k=>{p(!0),b(null),Promise.resolve().then(()=>r({...n,[S.id]:k})).catch(j=>{b({tone:"error",text:oe(c,j)})}).finally(()=>{p(!1)})}})})},S.id))}),_.length===0?null:e.jsx("div",{"data-recipe-options-diagnostics":!0,children:C}),e.jsx(pe,{feedback:h})]})}const Gm=["identity","run","dispatch","tools","advanced"],gE={identity:"st.profiles.tab.identity",run:"st.profiles.tab.run",dispatch:"st.profiles.tab.dispatch",tools:"st.profiles.tab.tools",advanced:"st.profiles.tab.advanced",raw:"st.profiles.tab.raw"},vE={description:"identity",whenToUse:"identity",prompt:"identity",main:"identity",executor:"run",executorInstance:"run",allowKikiSubagents:"run",kikiContext:"run",modelAlias:"run",effort:"run",recipeOptions:"run",restrictModelsToMenu:"run",preferredModels:"run",discouragedModels:"run",preferredEfforts:"run",allowedModels:"run",denyModels:"run",allowedEfforts:"run",modelProfiles:"run",executorPrompt:"run",subagentPolicy:"dispatch",spawnConstraints:"dispatch",tools:"tools",disallowedTools:"tools",promptOverrides:"advanced",serviceTier:"advanced",autoCompact:"advanced",routeAliases:"advanced"},yE=["inherit","empty","list"],kE=["pinned_model_alias","thinking_effort","tools","disallowed_tools","service_tier","request_params","context_budget","auto_compact","max_completion_tokens"];function jE(t,s){return t[s]!==void 0}function wE(t){return t===null?0:+(t.delivery!==void 0)+(t.include?.length??0)+ +(t.body!==void 0)+ +(t.append!==void 0)+Object.keys(t.per_engine??{}).length}function Wm({id:t,label:s,field:n,onChange:a,disabled:i,deny:r,applicability:o,engine:l}){const{t:c}=D(),d=r?{inherit:"st.namedAgents.toolsModeInherit",empty:"st.namedAgents.disallowedToolsModeNone",list:"st.namedAgents.disallowedToolsModeDeny"}:{inherit:"st.namedAgents.toolsModeInherit",empty:"st.namedAgents.toolsModeDenyAll",list:"st.namedAgents.toolsModeList"};return e.jsxs(Xt,{label:s,applicability:o,engine:l,dataField:t,children:[e.jsx(He,{ariaLabel:s,value:n.mode,disabled:i,dataAttr:`data-tool-mode-${t.toLowerCase()}`,onChange:u=>a({...n,mode:u}),choices:yE.map(u=>({value:u,label:c(d[u])}))}),n.mode==="list"?e.jsx("textarea",{"aria-label":s,"data-tool-list":t,className:`${Ce} min-h-20 font-mono text-[12px]`,value:n.text,disabled:i,placeholder:c("st.namedAgents.toolsPlaceholder"),onChange:u=>a({...n,text:u.target.value})}):null]})}function Vm({title:t,children:s,dataBlock:n,action:a}){return e.jsxs("section",{"data-profile-block":n,className:"min-w-0 space-y-3",children:[e.jsxs("div",{className:"flex min-h-7 items-center justify-between gap-2",children:[e.jsx("h4",{className:"text-[13px] font-semibold text-ink",children:t}),a]}),s]})}function NE({profile:t,writable:s,profiles:n,models:a,diagnostics:i,shippedEntry:r,onSaved:o,onDeleted:l,onClose:c,onOpenWinner:d,onToggleEnabled:u,toggleSaving:p,onNewSession:h,newSessionBlocked:b,onDuplicate:m}){const{client:f}=be(),{t:g,tp:v,locale:y}=D(),w=Tt(),[N,_]=x.useState("identity"),C=x.useRef(new Map),[S,k]=x.useState(()=>nl(t)),[j,T]=x.useState(S),[A,P]=x.useState(!1),[R,L]=x.useState(!1),[I,$]=x.useState(!1),[E,M]=x.useState(null),[z,H]=Je(),[U,X]=x.useState(0),q=V0(S,j),F=q.length>0,V=new Set(q.map(ce=>vE[ce])),se=Y0(j),Y=uE(t,dE(Gp(t,S,j),t),j.restrictModelsToMenu);x.useEffect(()=>{if(F)return;const ce=nl(t);k(ce),T(ce)},[t]);const O=(ce,qe)=>T(st=>({...st,[ce]:qe})),B=wb(),le=je({queryKey:["config"],queryFn:()=>f.getConfig(),staleTime:6e4,retry:!1}),re=J0(le.data),ae=Z0(le.data),ne=Ir(j.executor),Ee=wc(j.executor,g("st.profiles.engineNative"),B),ie=ce=>j.executor===S.executor?t.executor_fields?.[ce]:void 0,me=kE.flatMap(ce=>{const qe=ie(ce);return qe?.state==="ignored"?[[ce,qe]]:[]}),fe=ne?[]:a,Ie=fe.find(ce=>ce.id===j.modelAlias.trim()),te=ce=>!ne&&ce!==""&&ce!=="inherit"&&a.length>0&&!a.some(qe=>qe.id===ce),ee=ce=>{const qe=nl(ce);k(qe),T(qe),o(ce)},K=async()=>{if(!(!s||!F||se.length>0||t.workspace_id===void 0)){P(!0),M(null);try{const ce=await f.updateNamedAgentProfile(t.name,Gp(t,S,j));ee(ce),X(qe=>qe+1),H()}catch(ce){M({tone:"error",text:oe(y,ce)})}finally{P(!1)}}},Z=!s||A||I,ue=s&&r===void 0&&(t.source==="user"||t.source==="workspace")&&t.workspace_id!==void 0&&t.source_file!==void 0&&!(t.source==="user"&&/(?:^|[\\/])SYSTEM\.md$/iu.test(t.source_file)),Te=async()=>{if(!(!ue||t.workspace_id===void 0)){$(!0),M(null);try{await f.deleteNamedAgentProfile(t.name,{workspace_id:t.workspace_id,scope:t.source==="workspace"?"project":"user",source_file:t.source_file}),L(!1),T(S),l?.()}catch(ce){L(!1),M({tone:"error",text:oe(y,ce)})}finally{$(!1)}}},Ne=se.length===0?null:g(`st.profiles.problem.${se[0]}`),J=x.useMemo(()=>X0(n,B,{overrides:re,display:ae,retain:[S.executor,j.executor]}),[n,B,re,ae,S.executor,j.executor]),_e=ce=>B.find(qe=>qe.id===ce)?.status,we=B.find(ce=>ce.id===j.executor)?.capabilities?.prompt_deliveries,G=j.executorPrompt?.per_engine?.[j.executor]?.delivery??j.executorPrompt?.delivery??(we?.includes("replace")&&!we.includes("append")?"replace":we?.includes("append")?"append":"preamble"),Le=j.spawnConstraints,Se=ce=>O("spawnConstraints",{...Le,...ce}),Fe=[...j.allowKikiSubagents?[g("st.kikiContext.short.subagents")]:[],...(j.kikiContext??[]).map(ce=>g(`st.kikiContext.short.${ce}`))],ye=Fe.length===0?g("st.kikiContext.summaryOff"):Fe.join(" · "),ze=F&&N!=="raw",Pe=[...Gm,"raw"],xe=ce=>{const qe=Pe.filter(Es=>Es!=="raw"||!ze),st=qe.indexOf(N),gt=ce.key==="ArrowRight"?qe[(st+1)%qe.length]:ce.key==="ArrowLeft"?qe[(st-1+qe.length)%qe.length]:ce.key==="Home"?qe[0]:ce.key==="End"?qe.at(-1):void 0;gt!==void 0&&(ce.preventDefault(),_(gt),C.current.get(gt)?.focus())},ke=e.jsxs("div",{className:"grid min-w-0 gap-8 @3xl:grid-cols-[minmax(0,1fr)_20rem]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5","data-profile-prompt":!0,children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("label",{htmlFor:"profile-prompt",className:"text-[12px] font-medium text-ink-soft",children:g("st.profiles.prompt")}),e.jsx("span",{className:"text-[11.5px] tabular-nums text-ink-faint",children:g("st.profiles.promptSize",{lines:j.prompt===""?0:j.prompt.split(`
|
|
11
|
+
`).length,chars:j.prompt.length})})]}),s?e.jsx("textarea",{id:"profile-prompt",value:j.prompt,disabled:A,spellCheck:!1,onChange:ce=>O("prompt",ce.target.value),placeholder:g("st.profiles.promptPlaceholder"),className:"min-h-[24rem] resize-y rounded-lg border border-hairline bg-paper px-4 py-3 font-mono text-[12.5px] leading-[1.65] text-ink outline-none placeholder:text-ink-faint focus:border-selected-ink lg:h-[calc(100vh-22rem)]"}):e.jsx("div",{id:"profile-prompt",className:"min-h-[16rem] overflow-auto whitespace-pre-wrap break-words rounded-lg border border-hairline bg-paper px-4 py-3 font-mono text-[12.5px] leading-[1.65] text-ink lg:max-h-[calc(100vh-22rem)]",children:j.prompt===""?e.jsx("span",{className:"font-sans text-ink-faint",children:g("st.profiles.promptEmpty")}):j.prompt}),ne?e.jsx("p",{"data-prompt-delivery":!0,className:"text-[11.5px] text-ink-faint",children:ie("prompt")?.reason??g("st.profiles.promptDelivery",{engine:Ee})}):null]}),e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsx(Xt,{label:g("st.namedAgents.description"),htmlFor:"profile-description",dataField:"description",children:e.jsx("textarea",{id:"profile-description",rows:2,className:`${Ce} text-[13px] leading-snug`,value:j.description,disabled:Z,onChange:ce=>O("description",ce.target.value)})}),e.jsx(Xt,{label:g("st.namedAgents.whenToUse"),htmlFor:"profile-when",dataField:"whenToUse",children:e.jsx("textarea",{id:"profile-when",rows:4,className:`${Ce} text-[13px] leading-snug`,value:j.whenToUse,disabled:Z,placeholder:g("st.profiles.whenToUsePlaceholder"),onChange:ce=>O("whenToUse",ce.target.value)})}),e.jsxs("div",{"data-profile-field":"main",className:"space-y-1 pt-4",children:[e.jsx(Be,{layout:"row",label:g("st.profiles.mainToggle"),checked:j.main,disabled:Z,onChange:ce=>O("main",ce)}),e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:g(j.main?"st.profiles.mainOnHint":"st.profiles.mainOffHint")})]})]})]}),W=e.jsx(Hm,{dataRules:"self",title:g("st.profiles.rulesSelf"),rows:[{id:"models",label:g("st.profiles.model"),cells:{allow:e.jsx("div",{"data-profile-field":"allowedModels",children:e.jsx(zn,{id:"allowed-models",any:!0,values:j.allowedModels,models:fe,disabled:Z,onChange:ce=>O("allowedModels",ce)})}),prefer:e.jsx("div",{"data-profile-field":"preferredModels",children:e.jsx(zn,{id:"preferred-models",values:j.preferredModels,models:fe,disabled:Z,onChange:ce=>O("preferredModels",ce)})}),avoid:e.jsx("div",{"data-profile-field":"discouragedModels",children:e.jsx(zn,{id:"discouraged-models",values:j.discouragedModels,models:fe,disabled:Z,onChange:ce=>O("discouragedModels",ce)})}),block:e.jsx("div",{"data-profile-field":"denyModels",children:e.jsx(zn,{id:"deny-models",values:j.denyModels,models:fe,disabled:Z,onChange:ce=>O("denyModels",ce)})})}},{id:"efforts",label:g("st.profiles.effort"),cells:{allow:e.jsx("div",{"data-profile-field":"allowedEfforts",children:e.jsx(jl,{label:`${g("st.profiles.effort")} · ${g("st.profiles.ruleAllow")}`,values:j.allowedEfforts,disabled:Z,dataAttr:"data-allowed-effort",onChange:ce=>O("allowedEfforts",ce)})}),prefer:e.jsx("div",{"data-profile-field":"preferredEfforts",children:e.jsx(jl,{ordered:!0,label:`${g("st.profiles.effort")} · ${g("st.profiles.rulePrefer")}`,values:j.preferredEfforts,disabled:Z,dataAttr:"data-preferred-effort",onChange:ce=>O("preferredEfforts",ce)})})}}]}),Re=e.jsxs("div",{className:"min-w-0 space-y-10",children:[e.jsxs(Vm,{title:g("st.profiles.blockRuns"),dataBlock:"runs",children:[e.jsxs("div",{className:"grid min-w-0 gap-4 sm:grid-cols-[minmax(0,14rem)_minmax(0,1fr)_9rem]",children:[e.jsx(Xt,{label:g("st.profiles.engine"),htmlFor:"profile-engine",dataField:"engine",hint:ne&&_e(j.executor)==="unavailable"?e.jsx("span",{className:"text-amber-ink",children:g("st.profiles.engineNotFound",{engine:Ee})}):ne&&j.executor!==S.executor?e.jsx("span",{"data-engine-fields-pending":!0,children:g("st.profiles.fieldsAfterSave",{engine:Ee})}):void 0,children:e.jsx(Jt,{id:"profile-engine",value:j.executor,disabled:Z,hideFilter:!0,allowCustomValue:!0,options:J.map(ce=>{const qe=_e(ce),st=B.find(gt=>gt.id===ce)?.version;return{value:ce,label:wc(ce,g("st.profiles.engineNative"),B),hint:ce===""?void 0:[ce,st,qe==="unavailable"?g("st.profiles.engineNotInstalled"):void 0].filter(Boolean).join(" · ")}}),ariaLabel:g("st.profiles.engine"),buttonClassName:Sn,onChange:ce=>T(qe=>({...qe,executor:ce,executorInstance:ce===qe.executor?qe.executorInstance:""}))})}),e.jsx(Xt,{label:g("st.profiles.model"),htmlFor:"profile-model",applicability:ie("pinned_model_alias"),engine:Ee,dataField:"model",hint:te(j.modelAlias.trim())?e.jsx("span",{className:"text-amber-ink",children:g("st.profiles.aliasMissingTitle",{alias:j.modelAlias.trim()})}):void 0,children:e.jsx(Br,{id:"profile-model",value:j.modelAlias,models:fe,allowInherit:!j.main,disabled:Z,missing:te(j.modelAlias.trim()),onChange:ce=>T(qe=>({...qe,modelAlias:ce,effort:!ne&&ce.trim()!==qe.modelAlias.trim()&&fe.find(st=>st.id===ce)?.support_efforts?.includes(qe.effort)!==!0?"":qe.effort}))})}),e.jsx(Xt,{label:g("st.profiles.effort"),htmlFor:"profile-effort",applicability:ie("thinking_effort"),engine:Ee,dataField:"effort",children:e.jsx(ou,{id:"profile-effort",value:j.effort,supported:Ie?.support_efforts,disabled:Z,onChange:ce=>O("effort",ce)})})]}),ne?e.jsx(Xt,{label:g("st.engines.schedule.label"),htmlFor:"profile-instance",dataField:"executorInstance",hint:g("st.engines.schedule.hint"),children:e.jsx(eN,{id:"profile-instance",executorId:j.executor,catalog:B,disabled:Z,value:tN(j.executorInstance)||void 0,onChange:ce=>O("executorInstance",ce===""?"":typeof ce=="string"?ce:`account:${ce.account_id}`)})}):null,e.jsx(Mg,{recipe:t.recipe,sourceFile:t.source_file,values:j.recipeOptions,disabled:Z||ne,onChange:ce=>O("recipeOptions",ce)}),ne&&me.length>0?e.jsxs("details",{"data-profile-section":"ignored-fields",className:"text-[12px]",children:[e.jsxs("summary",{className:"cursor-pointer select-none text-ink-soft hover:text-ink",children:[g("st.profiles.ignoredTitle",{engine:Ee})," · ",me.length]}),e.jsx("ul",{className:"mt-2 space-y-2 pl-3",children:me.map(([ce,qe])=>e.jsxs("li",{"data-ignored-field":ce,className:"min-w-0",children:[e.jsxs("p",{className:"flex min-w-0 items-baseline gap-2 text-[12.5px] text-ink-soft",children:[e.jsx("span",{className:"font-medium",children:g(`st.profiles.fieldName.${ce}`)}),jE(t,ce)?e.jsxs("span",{className:"text-[11px] text-ink-faint",children:["· ",g("st.profiles.fieldValueSet")]}):null]}),e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint",children:qe.reason??g("st.profiles.fieldIgnored",{engine:Ee})})]},ce))})]}):null]}),W,e.jsx(Vm,{title:g("st.profiles.modelProfiles"),dataBlock:"candidates",children:e.jsxs("div",{"data-profile-section":"model-profiles",className:"min-w-0 space-y-3",children:[e.jsx(rE,{values:j.modelProfiles,models:fe,disabled:Z,onChange:ce=>O("modelProfiles",ce)}),e.jsx(lE,{checked:j.restrictModelsToMenu,baselineChecked:S.restrictModelsToMenu,disabled:Z,onChange:ce=>O("restrictModelsToMenu",ce),preview:Y.value,pending:Y.pending,error:Y.error,onRetry:Y.retry})]})}),ne?e.jsxs("div",{className:"min-w-0 space-y-1",children:[sN(j)?e.jsx(Fm,{title:g("st.kikiContext.title"),dataSection:"kiki-context",defaultOpen:!0,count:Number(j.allowKikiSubagents)+(j.kikiContext?.length??0),summary:ye,children:e.jsx(iE,{draft:j,baseline:S,engine:Ee,disabled:Z,onChange:ce=>T(qe=>({...qe,...ce}))})}):null,e.jsx(Fm,{title:g("st.executorPrompt.title"),dataSection:"executor-prompt",defaultOpen:!0,count:wE(j.executorPrompt),summary:g(`st.executorPrompt.delivery.${G}`),children:e.jsx(X2,{value:j.executorPrompt,onChange:ce=>O("executorPrompt",ce),engineId:j.executor,engineLabel:Ee,catalog:B,profileBody:j.prompt,disabled:Z,profileName:t.name,workspaceId:t.workspace_id,previewEnabled:!F})})]}):null]}),Ae=e.jsx(Hm,{dataRules:"spawn",title:g("st.profiles.rulesSpawn"),action:nN(Le)?e.jsx("button",{type:"button","data-spawn-clear":!0,disabled:Z,onClick:()=>O("spawnConstraints",aN),className:"h-7 shrink-0 rounded-md px-2 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink disabled:opacity-50",children:g("st.profiles.spawnClear")}):void 0,rows:[{id:"models",label:g("st.profiles.model"),cells:{allow:e.jsx("div",{"data-profile-field":"spawnAllowedModels",children:e.jsx(zn,{id:"spawn-allowed-models",any:!0,values:Le.allowedModels,models:fe,disabled:Z,onChange:ce=>Se({allowedModels:ce})})}),block:e.jsx("div",{"data-profile-field":"spawnDenyModels",children:e.jsx(zn,{id:"spawn-deny-models",values:Le.denyModels,models:fe,disabled:Z,onChange:ce=>Se({denyModels:ce})})})}},{id:"efforts",label:g("st.profiles.effort"),cells:{allow:e.jsx("div",{"data-profile-field":"spawnAllowedEfforts",children:e.jsx(jl,{label:`${g("st.profiles.rulesSpawn")} · ${g("st.profiles.effort")}`,values:Le.allowedEfforts,disabled:Z,dataAttr:"data-spawn-effort",onChange:ce=>Se({allowedEfforts:ce})})})}},{id:"tools",label:g("st.profiles.tools"),cells:{block:e.jsx("div",{"data-profile-field":"spawnDisallowedTools",children:e.jsx("textarea",{id:"spawn-disallowed-tools","aria-label":`${g("st.profiles.rulesSpawn")} · ${g("st.profiles.ruleBlock")} · ${g("st.profiles.tools")}`,className:`${Ce} min-h-9 font-mono text-[12px]`,rows:1,value:Le.disallowedTools,disabled:Z,placeholder:g("st.namedAgents.toolsPlaceholder"),onChange:ce=>Se({disallowedTools:ce.target.value})})})}}]}),Ue=e.jsxs("div",{className:"min-w-0 space-y-10","data-profile-section":"subagents","data-field-applicability":ie("spawn_constraints")?.state,children:[e.jsx(mE,{draft:j,profiles:n,models:a,disabled:Z,self:t.name,onChange:ce=>T(qe=>({...qe,...ce}))}),ie("subagents")?.state==="ignored"?e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:ie("subagents")?.reason??g("st.profiles.fieldIgnored",{engine:Ee})}):null,j.subagentPolicy.canSpawnSubagents===!1?null:Ae]}),Ge=e.jsxs("div",{className:"grid min-w-0 max-w-[48rem] gap-8","data-profile-section":"tools",children:[e.jsx(Wm,{id:"tools",label:g("st.namedAgents.tools"),field:j.tools,disabled:Z,deny:!1,applicability:ie("tools"),engine:Ee,onChange:ce=>O("tools",ce)}),e.jsx(Wm,{id:"disallowedTools",label:g("st.namedAgents.disallowedTools"),field:j.disallowedTools,disabled:Z,deny:!0,applicability:ie("disallowed_tools"),engine:Ee,onChange:ce=>O("disallowedTools",ce)}),j.main?null:e.jsxs("button",{type:"button","data-profile-inspect-tools":!0,onClick:()=>{w(`/settings/agents?tab=dispatch&object=${encodeURIComponent(t.name)}#st-card-subagent-tool-defaults`)},className:"inline-flex w-fit items-center gap-1 text-[12px] text-ink-soft underline decoration-dotted underline-offset-2 transition-colors hover:text-ink",children:[g("st.profiles.inspectToolPermissions"),e.jsx(de,{name:"arrowRight",size:12})]})]}),Ke=e.jsxs("div",{className:"grid min-w-0 gap-10 @3xl:grid-cols-2","data-profile-section":"advanced",children:[e.jsxs("div",{className:"min-w-0 space-y-6",children:[e.jsx(Xt,{label:g("st.namedAgents.serviceTier"),applicability:ie("service_tier"),engine:Ee,dataField:"serviceTier",children:e.jsx(He,{ariaLabel:g("st.namedAgents.serviceTier"),value:j.serviceTier,disabled:Z,onChange:ce=>O("serviceTier",ce),choices:[{value:"",label:g("st.profiles.unsetShort")},...["auto","default","flex","priority"].map(ce=>({value:ce,label:ce}))]})}),e.jsx("div",{"data-profile-auto-compact":!0,children:e.jsx(ru,{dataAttribute:"profile",label:g("st.compact.profileLabel"),value:j.autoCompact,onChange:ce=>O("autoCompact",ce),windowTokens:Ie?.max_context_size,placeholder:g("st.compact.profilePlaceholder"),hint:t.context_budget!==void 0?g("st.compact.profileHintBudget",{tokens:ft(t.context_budget)}):g("st.compact.profileHint")})}),t.routes.map(ce=>e.jsx(Xt,{label:g("st.namedAgents.routeModel",{route:ce.id}),dataField:`route-${ce.id}`,children:e.jsx(Br,{id:`route-${ce.id}`,value:j.routeAliases[ce.id]??"",models:fe,allowInherit:!1,disabled:Z,onChange:qe=>O("routeAliases",{...j.routeAliases,[ce.id]:qe})})},ce.id))]}),e.jsxs("div",{className:"min-w-0 space-y-2","data-profile-section":"prompt-overrides",children:[e.jsx("h4",{className:"text-[13px] font-semibold text-ink",children:g("st.promptIdentity.fieldsTitle")}),e.jsx(Ca,{value:j.promptOverrides,disabled:Z,onChange:ce=>O("promptOverrides",ce),children:(ce,qe,st)=>e.jsx(Eo,{value:ce,onChange:qe,label:st})}),(()=>{const ce=xa(j.promptOverrides,Bs,lo);return ce===void 0?null:e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:g(`st.promptIdentity.problem.${ce}`)})})()]})]}),We={identity:ke,run:Re,dispatch:Ue,tools:Ge,advanced:Ke};return e.jsxs("div",{"data-agent-detail":t.name,"data-profile-editor":!0,className:"flex min-h-0 min-w-0 flex-col gap-5",children:[e.jsxs("header",{className:"flex flex-wrap items-start gap-x-4 gap-y-3",children:[e.jsx("div",{className:"basis-full md:hidden",children:e.jsx(ko,{label:g("st.profiles.team"),onClick:c,data:{"data-agent-back":""}})}),e.jsxs("div",{className:"min-w-0 flex-1 basis-[16rem]",children:[e.jsxs("h3",{"data-detail-heading":!0,tabIndex:-1,className:"flex flex-wrap items-center gap-x-2 gap-y-1 font-display text-[20px] leading-tight text-ink outline-none",children:[e.jsx("span",{className:"min-w-0 break-words",children:t.name}),e.jsx("span",{className:"rounded-[4px] bg-ink/[0.05] px-1.5 font-sans text-[11.5px] font-normal leading-[18px] text-ink-soft",children:g(j.main?"st.agentManager.main":"st.agentManager.subagent")}),ne?e.jsx("span",{className:"rounded-[4px] border border-hairline px-1.5 font-sans text-[11.5px] font-normal leading-[16px] text-ink-soft",children:Ee}):null]}),e.jsxs("p",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 text-[12px] text-ink-faint",children:[e.jsx("span",{"data-profile-origin":!0,children:t.source==="workspace"?g("st.profiles.tagProject"):Nb(g,t.source)}),t.source_file!==void 0?e.jsxs("span",{className:"min-w-0 truncate font-mono text-[11.5px]",title:t.source_file,children:["· ",t.source_file]}):null,s?null:e.jsxs("span",{children:["· ",g("st.agentManager.readOnlyShort")]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r!==void 0?e.jsx(Pg,{entry:r,profile:t,onRestored:()=>{o(t),H()},onError:ce=>M({tone:"error",text:oe(y,ce)})}):null,e.jsx(Be,{layout:"bare",label:g("st.namedAgents.enabled"),checked:!t.disabled,disabled:p,onChange:ce=>{u(ce).catch(qe=>M({tone:"error",text:oe(y,qe)}))}}),e.jsx("button",{type:"button",className:Q,onClick:m,children:g("st.profiles.duplicate")}),e.jsx("button",{type:"button",className:Q,disabled:b,onClick:h,children:g("st.namedAgents.newSession")}),ue?e.jsx("button",{type:"button","data-profile-delete":t.name,className:Ht,disabled:A||I,onClick:()=>{L(!0)},children:g("st.agents.delete")}):null,e.jsx("button",{type:"button",onClick:c,"aria-label":g("st.profiles.backToTeam"),title:g("st.profiles.backToTeam"),"data-detail-close":!0,className:"hidden h-8 w-8 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink md:flex",children:e.jsx(de,{name:"close",size:14})})]})]}),s?null:e.jsx("p",{"data-profile-readonly":!0,className:"text-[12.5px] text-ink-soft",children:t.source==="builtin"?e.jsxs(e.Fragment,{children:[g("st.agents.builtinHint")," ",e.jsx("button",{type:"button",onClick:m,className:"underline decoration-ink-faint underline-offset-2 hover:text-ink",children:g("st.profiles.duplicate")})]}):e.jsxs(e.Fragment,{children:[g("st.profiles.readOnlyExplain")," ",e.jsx("button",{type:"button",onClick:m,className:"underline decoration-ink-faint underline-offset-2 hover:text-ink",children:g("st.profiles.duplicateToEdit")})]})}),e.jsx($g,{diagnostics:i,onOpenWinner:d}),e.jsx("div",{role:"tablist","aria-label":g("st.profiles.editMode"),"data-profile-tabs":!0,className:"sticky top-[calc(-1*var(--settings-scroll-pt,0px))] z-10 md:-mx-1 flex min-w-0 shrink-0 gap-1 overflow-x-auto border-b border-hairline bg-canvas px-1",children:Pe.map(ce=>{const qe=ce===N,st=ce==="raw"&&ze;return e.jsxs("button",{type:"button",role:"tab",id:`profile-tab-${ce}`,"aria-selected":qe,"aria-controls":`profile-panel-${ce}`,tabIndex:qe?0:-1,disabled:st,title:st?g("st.profiles.rawAfterSave"):void 0,ref:gt=>{gt===null?C.current.delete(ce):C.current.set(ce,gt)},"data-profile-tab":ce,"data-profile-mode":ce==="raw"?"raw":ce==="identity"?"form":void 0,onClick:()=>_(ce),onKeyDown:xe,className:`-mb-px inline-flex min-h-10 shrink-0 items-center gap-1.5 whitespace-nowrap border-b-2 px-3 text-[13px] transition-colors focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:text-ink-faint/70 ${ce==="raw"?"ml-auto":""} ${qe?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:[g(gE[ce]),ce!=="raw"&&V.has(ce)?e.jsx("span",{"data-profile-tab-dirty":!0,"aria-label":g("st.profiles.tabUnsaved"),className:"h-1.5 w-1.5 rounded-full bg-accent"}):null]},ce)})}),Gm.map(ce=>e.jsx("div",{role:"tabpanel",id:`profile-panel-${ce}`,"aria-labelledby":`profile-tab-${ce}`,hidden:N!==ce,"data-profile-panel":ce,className:"min-w-0 pb-2",children:We[ce]},ce)),N==="raw"?e.jsx("div",{role:"tabpanel",id:"profile-panel-raw","aria-labelledby":"profile-tab-raw","data-profile-panel":"raw",children:e.jsx(pE,{profile:t,writable:s,reloadToken:U,onSaved:ee})}):null,s&&N!=="raw"?e.jsx("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] z-10 md:-mx-1 mt-auto border-t border-transparent bg-canvas/95 px-1 backdrop-blur-sm has-[[data-settings-draft]:not([hidden])]:border-hairline has-[[data-settings-draft]:not([hidden])]:pb-3",children:e.jsx(lt,{saved:z,id:`agent-detail:${t.source}:${t.source_file??""}:${t.name}`,dirty:F,saving:A,saveDisabled:se.length>0,onSave:()=>void K(),onDiscard:()=>{T(S),M(null)},extra:Ne!==null&&F?e.jsx("span",{role:"alert",className:"text-[12px] text-danger",children:Ne}):F&&(Y.value?.removed?.length??0)>0?e.jsx("span",{"data-menu-save-warning":!0,role:"status",className:"max-w-[36rem] break-words text-[12px] font-medium text-amber-ink",children:g("st.profiles.menuRemoved",{models:Y.value.removed.join(", ")})}):F?e.jsx("span",{className:"text-[12px] text-ink-faint",children:v("st.profiles.changedCount",q.length)}):void 0})}):null,e.jsx(pe,{feedback:E}),e.jsx(Xe,{open:R,title:g("st.agents.deleteTitle",{name:t.name}),body:g("st.agents.deleteBody"),consequences:t.source_file===void 0?void 0:[t.source_file],confirmLabel:g("st.agents.delete"),cancelLabel:g("common.cancel"),tone:"danger",busy:I,overlayId:`profile-delete-${t.name}`,onConfirm:()=>void Te(),onCancel:()=>{L(!1)}})]})}const SE=["main","subagent"],CE={main:"st.profiles.groupMain",subagent:"st.profiles.groupSubagents"},Kr=(t,s)=>t.name==="agent"&&t.main?s==="zh"?"Kiki(默认)":"Kiki":t.name,Ua="shrink-0 rounded-[4px] bg-ink/[0.05] px-1.5 text-[11px] leading-[18px] text-ink-soft",_E="shrink-0 rounded-[4px] border border-hairline px-1.5 text-[11px] leading-[16px] text-ink-soft";function EE({rows:t,models:s,defaultModelId:n,onOpen:a,onNew:i,newActions:r,loading:o=!1,hideEmpty:l=!1}){const{t:c,locale:d}=D(),u=x.useMemo(()=>new Map(s.map(k=>[k.id,k])),[s]),p=x.useMemo(()=>[{id:"order",label:c("st.list.sort.order"),compare:()=>0},{id:"name",label:c("st.list.sort.name"),compare:(k,j)=>k.profile.name.localeCompare(j.profile.name)}],[c]),h=x.useCallback(k=>k.key,[]),b=x.useCallback(k=>[k.profile.name,k.profile.description],[]),m=Qs({listId:"agent-profiles",items:t,keyOf:h,sorts:p,textOf:b}),f=k=>k.profile.main?"main":"subagent",g=SE.map(k=>({id:k,rows:m.visible.filter(j=>f(j)===k),total:t.filter(j=>f(j)===k).length})).filter(k=>k.rows.length>0),v=t.map(k=>({row:k,warnings:k.diagnostics.filter(j=>wn(j)==="warning")})).filter(k=>k.warnings.length>0),y=v.reduce((k,j)=>k+j.warnings.length,0),w=e.jsxs("button",{type:"button","data-profile-new":!0,onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1 rounded-md bg-accent px-3 text-[12.5px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink",children:[e.jsx(de,{name:"plus",size:12}),c("st.agentManager.new")]}),N=!o&&!m.narrowed&&t.length>0&&t.every(k=>k.profile.main);return e.jsxs("div",{className:"space-y-3","data-team-view":!0,children:[e.jsx(Gs,{view:m,total:t.length,searchLabel:c("st.profiles.search"),searchPlaceholder:c("st.profiles.search"),sorts:p,showDensity:!1,actions:e.jsxs(e.Fragment,{children:[w,r]})}),v.length>0?e.jsxs("section",{"data-team-warnings":!0,"aria-label":c("st.attention.count",{count:y}),className:"space-y-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-attention",children:c("st.attention.count",{count:y})}),e.jsx("ul",{className:"divide-y divide-hairline",children:v.map(({row:k,warnings:j})=>e.jsxs("li",{"data-team-attention":k.profile.name,className:"flex flex-wrap items-start gap-x-3 gap-y-1 py-1.5",children:[e.jsx("span",{className:"w-full shrink-0 truncate text-[13px] font-medium text-ink sm:w-32",children:Kr(k.profile,d)}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx($g,{diagnostics:j,surface:"attention",profile:k.profile})}),e.jsx("button",{type:"button","data-team-attention-open":k.profile.name,onClick:()=>a(k),className:`h-7 shrink-0 pointer-coarse:h-10 ${Ot}`,children:c("st.profiles.openThere")})]},k.key))})]}):null,o&&t.length===0?e.jsx(sg,{label:c("st.namedAgents.loading"),rows:2}):null,e.jsx("div",{"data-team-list":!0,children:g.map(k=>{const j=c(CE[k.id]);return e.jsx("div",{"data-team-group":k.id,children:e.jsx(Xd,{groupKey:k.id,label:j,count:k.rows.length,total:k.total,folded:m.isFolded(k.id),onToggle:()=>{m.toggleFold(k.id)},children:e.jsx(TE,{rows:k.rows,renderRow:S})})},k.id)})}),N?e.jsx(Ct,{kind:"none",title:c("st.agents.empty")}):null,m.visible.length===0&&!o&&!l?e.jsx(Ct,{kind:m.narrowed?"no-match":"none",title:c(m.narrowed?"st.profiles.teamNoMatch":"st.profiles.teamEmpty"),action:m.narrowed?void 0:w,onClear:m.narrowed?m.clear:void 0}):null]});function _(k,j){const T=k.pinned_model_alias??"";if(T==="inherit")return{text:c("st.namedAgents.followCallerModel"),warn:!1};if(T!==""){const P=u.get(T);return{text:P?.display_name??T,model:P,warn:j}}if(Ir(k.executor)||n===void 0||n==="")return{text:c("common.defaultUnknown"),warn:!1};const A=u.get(n);return{text:c("st.agents.row.model",{model:A?.display_name??n}),model:A,warn:!1}}function C(k,j){const T=k.thinking_effort??"";if(T!=="")return c("st.agents.row.thinking",{effort:Cs(T,c)});const A=j?.default_effort??"";if(A!=="")return c("st.agents.row.thinking",{effort:c("common.defaultWithValue",{value:Cs(A,c)})})}function S(k){const{profile:j}=k,T=Ir(j.executor),A=k.diagnostics.filter(z=>wn(z)==="warning"),P=k.diagnostics.some(z=>z.kind==="aliasMissing"&&z.field==="model_alias"),R=k.diagnostics.some(z=>z.kind==="shadowedBy"),L=j.source==="user"?void 0:j.source==="workspace"?c("st.profiles.tagProject"):Nb(c,j.source),I=R||j.disabled,$=_(j,P),E=C(j,$.model),M=!j.main&&!j.disabled&&!R;return e.jsx("li",{"data-team-row":j.name,"data-team-source":j.source,className:`border-b border-hairline ${I?"text-ink-faint":""}`,children:e.jsxs("button",{type:"button",onClick:()=>a(k),"data-team-open":j.name,"data-detail-trigger":j.name,className:"group flex min-h-11 w-full min-w-0 flex-col items-start justify-center gap-0.5 rounded-md px-1 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/50",children:[e.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[e.jsx(de,{name:iN({profile:j.name,executor:j.executor,main:j.main,description:j.description}),size:14,className:`shrink-0 ${I?"text-ink-faint":"text-ink-soft"}`}),e.jsx("span",{className:`min-w-0 shrink truncate text-[13px] font-medium group-hover:underline group-hover:decoration-ink-faint group-hover:underline-offset-2 ${R?"line-through decoration-ink-faint/60":I?"":"text-ink"}`,children:Kr(j,d)}),A.length>0?e.jsxs("span",{"data-team-warning":!0,className:"shrink-0 text-amber-ink",children:[e.jsx(de,{name:"warning",size:12}),e.jsx("span",{className:"sr-only",children:c("st.attention.count",{count:A.length})})]}):null,T?e.jsx("span",{"data-team-engine":!0,className:_E,children:k.engineLabel??j.executor}):null,L!==void 0?e.jsx("span",{"data-team-tag":"source",className:Ua,children:L}):null,k.shipped&&j.source!=="builtin"?e.jsx("span",{"data-team-tag":"shipped",className:Ua,children:c("st.profiles.shippedCopy")}):null,!k.writable&&j.source!=="builtin"?e.jsx("span",{"data-team-tag":"readonly",className:Ua,children:c("st.agentManager.readOnlyShort")}):null,R?e.jsx("span",{"data-team-tag":"shadowed",className:Ua,children:c("st.profiles.tagInactive")}):null,j.disabled?e.jsx("span",{"data-team-tag":"disabled",className:Ua,children:c("st.namedAgents.disabledBadge")}):null,j.description!==void 0&&j.description!==""?e.jsx("span",{className:"hidden min-w-0 flex-1 truncate text-[12px] text-ink-faint sm:inline",children:j.description}):null]}),e.jsxs("span",{"data-team-effective":!0,className:"flex min-w-0 max-w-full flex-wrap items-center gap-x-1.5 text-[12px] text-ink-soft",children:[e.jsxs("span",{"data-team-model":!0,className:`inline-flex min-w-0 items-center gap-1 ${$.warn?"text-amber-ink":""}`,children:[$.warn?e.jsx(de,{name:"warning",size:12}):null,e.jsx("span",{className:"min-w-0 truncate",children:$.text})]}),E!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"text-ink-faint",children:"·"}),e.jsx("span",{"data-team-effort":!0,children:E})]}):null,M?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"text-ink-faint",children:"·"}),e.jsx("span",{"data-team-dispatchable":!0,children:c("st.agents.row.dispatchable")})]}):null]})]})},k.key)}}function TE({rows:t,renderRow:s}){const n=Ta(),[a,i]=x.useState(null),r=x.useCallback(c=>{i(c)},[]),o=t.length>n.catalogVirtualizeThreshold,l=Ri({count:o?t.length:0,getScrollElement:()=>a,estimateSize:()=>58,getItemKey:c=>t[c]?.key??c,overscan:n.virtualOverscan,initialRect:{width:640,height:480},observeElementRect:(c,d)=>{const u=c.scrollElement;if(u===null)return;const p=()=>{const b=u.getBoundingClientRect(),m=Math.round(b.height||u.clientHeight),f=Math.round(b.width||u.clientWidth);m>0&&d({width:f,height:m})};if(p(),typeof ResizeObserver>"u")return;const h=new ResizeObserver(p);return h.observe(u),()=>{h.disconnect()}},measureElement:c=>{const d=Math.round(c.getBoundingClientRect().height);return d>0?d:58},useFlushSync:!1});return o?e.jsx("div",{ref:r,className:"max-h-[min(520px,65vh)] overflow-y-auto border-t border-hairline","data-team-virtual":!0,children:e.jsx("ul",{style:{height:l.getTotalSize(),position:"relative"},children:l.getVirtualItems().map(c=>{const d=t[c.index];return d===void 0?null:e.jsx("div",{"data-index":c.index,ref:l.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${c.start}px)`},children:s(d)},c.key)})})}):e.jsx("ul",{className:"border-t border-hairline",children:t.map(s)})}const Ym=t=>`${t.source}:${t.source_file??""}:${t.name}`,Ur="agent",Jm="workspace",IE=2;function PE(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=Ln(),r=Tt(),[o,l]=x.useState(),c=Li(Ur),[d,u]=x.useState(null),[p,h]=x.useState(null),[b,m]=x.useState(!1),[f,g]=x.useState(null),[v,y]=x.useState(null),{ask:w,busy:N}=ug(),_=pg(),C=je({queryKey:["workspaces","catalog"],queryFn:()=>t.listWorkspaceCatalog(),staleTime:3e4}),[S,k]=no(),T=S.get(Jm)??void 0??(o!==void 0&&(C.data?.items??[]).some(xe=>xe.id===o)?o:void 0)??Wp(C.data?.items??[])[0]?.id,A=je({queryKey:["named-agent-profiles",T??"global"],queryFn:()=>ii(t,T?{mode:"workspace",workspaceId:T}:{mode:"global"}),enabled:!C.isPending,staleTime:15e3,refetchInterval:Tr}),P=T===void 0?{mode:"disabled"}:{mode:"workspace",workspaceId:T,effective:!0},R=je({queryKey:rN(P),queryFn:()=>ii(t,P),enabled:T!==void 0,staleTime:15e3,refetchInterval:Tr}),L=je({queryKey:["shipped-agent-profiles"],queryFn:()=>t.listShippedAgentProfiles(),staleTime:15e3,retry:!1}),I=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),$=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:6e4}),E=$.data?.items??[],M=wb(),z=x.useMemo(()=>Pd(A.data?.items??[]),[A.data]),H=L.data?.items??[],U=R.data?.items,X=x.useMemo(()=>{const xe=U??[];return new Map(oN(z.filter(ke=>ke.source==="builtin"||xe.some(W=>ta(W,ke)))))},[z,U]),q=x.useMemo(()=>$.data===void 0?void 0:new Set(E.map(xe=>xe.id)),[$.data]),F=x.useMemo(()=>z.filter(xe=>X.get(xe)?.kind!=="overridden").map(xe=>{const ke=Vp(xe,H);return{key:Ym(xe),profile:xe,writable:lN(xe),shipped:ke!==void 0||xe.source==="builtin",engineLabel:wc(xe.executor,s("st.profiles.engineNative"),M),diagnostics:V2(xe,{profiles:z,effective:U,modelIds:q,shippedEntry:ke,overrideRelation:X.get(xe)})}}).toSorted((xe,ke)=>Number(ke.profile.name==="agent"&&ke.profile.main)-Number(xe.profile.name==="agent"&&xe.profile.main)||Number(ke.profile.main)-Number(xe.profile.main)||xe.profile.name.localeCompare(ke.profile.name)),[z,H,U,q,X,s,M]),V=()=>{yn(a),a.invalidateQueries({queryKey:["shipped-agent-profiles"]})},se=x.useMemo(()=>{const xe=new Map;for(const ke of F)xe.set(ke.profile.name,(xe.get(ke.profile.name)??0)+1);return xe},[F]),Y=xe=>(se.get(xe.profile.name)??0)===1?xe.profile.name:xe.key,O=c.selected===null?void 0:F.find(xe=>Y(xe)===c.selected)??F.find(xe=>xe.key===c.selected),B=C.data?.items??[],le=x.useMemo(()=>Wp(B.filter(xe=>xe.id!==T)),[B,T]),re=c.selected!==null&&!c.selected.includes(":")&&O===void 0&&A.isSuccess&&!A.data.items.some(xe=>xe.name===c.selected)?c.selected:null,ae=je({queryKey:["named-agent-profiles","elsewhere",T??"global",re,le.map(xe=>xe.id).join(",")],enabled:re!==null&&le.length>0,staleTime:3e4,queryFn:async({signal:xe})=>{if(re===null)return null;for(const Ue of le)if(a.getQueryData(["named-agent-profiles",Ue.id])?.items.some(Ke=>Ke.name===re))return Ue.id;let ke=0,W=null;const Re=async()=>{for(;W===null&&!xe.aborted;){const Ue=ke++;if(Ue>=le.length)return;const Ge=le[Ue];try{const Ke=await a.fetchQuery({queryKey:["named-agent-profiles",Ge.id],queryFn:()=>ii(t,{mode:"workspace",workspaceId:Ge.id}),staleTime:3e4});if(W===null&&Ke.items.some(We=>We.name===re)){W=Ge.id;return}}catch{}}},Ae=Math.min(IE,le.length);return await Promise.all(Array.from({length:Ae},()=>Re())),W}}),ne=x.useMemo(()=>{if(!(re===null||!ae.data))return le.find(xe=>xe.id===ae.data)},[re,ae.data,le]),Ee=O!==void 0&&c.selected===O.profile.name?c.selected:null,ie=(xe,ke)=>{xe!==T&&(l(xe),k(W=>{const Re=new URLSearchParams(W);return Re.set(Jm,xe),ke||Re.delete(Ur),Re},{replace:!0}))},me=xe=>{c.open(Y(xe))},fe=()=>{if(i?.confirmDiscard===void 0){u(null);return}i.confirmDiscard("agent-create",()=>u(null))};x.useEffect(()=>{if(p===null||d!==null||i?.dirty===!0)return;const xe=F.find(ke=>ke.key===p);xe!==void 0&&(h(null),me(xe))},[p,d,i?.dirty,F]);const Ie=async(xe,ke)=>{m(!0);try{const W=await t.patchConfig(cN(I.data??{},xe,ke));a.setQueryData(["config"],W),await yn(a)}finally{m(!1)}},te=async(xe,ke)=>{const W=xe.trim();if(W!==""){m(!0),y(null);try{const Re=I.data?.disabled_named_profiles??[],Ae=ke?Re.filter(Ge=>Ge!==W):[...new Set([...Re,W])],Ue=await t.patchConfig({disabled_named_profiles:Ae});a.setQueryData(["config"],Ue),await yn(a),g("")}catch(Re){y({tone:"error",text:oe(n,Re)})}finally{m(!1)}}},ee=x.useMemo(()=>(C.data?.items??[]).map(xe=>{const ke=xe.root.replace(/[/]+$/,"").split(/[/]/).pop(),W=xe.name!==void 0&&xe.name!==""?xe.name:ke!==""&&ke!==void 0?ke:xe.id;return{value:xe.id,label:W,hint:xe.root,title:xe.root}}),[C.data]),K=x.useMemo(()=>(I.data?.disabled_named_profiles??[]).filter(xe=>!z.some(ke=>ke.name===xe)),[I.data,z]),Z=H.filter(xe=>xe.managed&&xe.status==="removed"),ue=T!==void 0||_.resolved,Te=ee.length>0?e.jsx(Jt,{id:"agents-workspace-select",options:ee,value:T??"",ariaLabel:s("new.workspace"),buttonClassName:zd,triggerLabel:e.jsxs("span",{className:"min-w-0 text-ink-soft",children:[s("st.profiles.project")," ",e.jsx("span",{className:"inline-block max-w-56 truncate align-bottom text-ink",children:ee.find(xe=>xe.value===T)?.label})]}),onChange:xe=>{ie(xe,Ee!==null)}}):null,Ne=e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex min-h-8 flex-wrap items-center justify-between gap-2","data-agents-scope":!0,children:Te??e.jsx("span",{})}),e.jsx(EE,{rows:F,models:E,defaultModelId:I.data?.default_model,newActions:e.jsx(mg,{label:s("st.agentManager.askKiki"),labelAria:s("st.agentManager.askKikiAria"),busy:N,disabled:!ue,testId:"data-agent-ask-kiki",onAsk:()=>{w({skill:"kiki-profile",promptKey:"st.agentManager.askKiki.prompt",context:T===void 0?void 0:s("st.agentManager.askKiki.context",{target:ee.find(xe=>xe.value===T)?.label??T}),location:T===void 0?_.location:{kind:"workspace",workspaceId:T}})}}),onOpen:me,onNew:()=>u({}),loading:A.isPending,hideEmpty:A.isError}),Z.length>0?e.jsx("div",{className:"space-y-1","data-shipped-removed-list":!0,children:Z.map(xe=>e.jsxs("div",{"data-shipped-removed":xe.template_id,className:"flex flex-wrap items-center justify-between gap-2 rounded-md px-1 py-1.5",children:[e.jsxs("span",{className:"text-[13px] text-ink-faint",children:[e.jsx("span",{className:"font-mono",children:xe.template_id}),xe.description!==void 0?` · ${xe.description}`:""]}),e.jsx(Pg,{entry:xe,onRestored:()=>{V(),y({tone:"success",text:s("st.shipped.restored")})},onError:ke=>y({tone:"error",text:oe(n,ke)})})]},xe.template_id))}):null,A.isError?e.jsx("div",{"data-agents-load-failed":!0,children:e.jsx(Qd,{message:s("st.agents.loadFailed",{detail:oe(n,A.error)}),retrying:A.isFetching,onRetry:()=>{A.refetch()}})}):null,R.isError?e.jsx(De,{error:R.error}):null,I.isError?e.jsx(De,{error:I.error}):null,!ue&&C.isError?e.jsx(De,{error:C.error}):null,e.jsxs(et,{summary:s("st.agentManager.disabledByName"),"data-disabled-by-name-fold":!0,className:"pt-3 text-[11px] text-ink-soft",children:[e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("input",{className:`${Ce} font-mono`,value:f??"",placeholder:"profile-name","aria-label":s("st.agentManager.disabledByName"),onChange:xe=>{g(xe.target.value)},onKeyDown:xe=>{rt(xe)||xe.key==="Enter"&&te(f??"",!1)}}),e.jsx("button",{type:"button",className:Q,"data-disabled-by-name-add":!0,disabled:b||(f??"").trim()==="",onClick:()=>{te(f??"",!1)},children:s("st.agentManager.disableByName")})]}),K.length>0?e.jsx("ul",{className:"space-y-1",children:K.map(xe=>e.jsxs("li",{"data-disabled-by-name":xe,className:"flex items-center justify-between gap-2 text-[12px] text-ink-soft",children:[e.jsx("span",{className:"font-mono",children:xe}),e.jsx("button",{type:"button",className:Q,disabled:b,onClick:()=>{te(xe,!0)},children:s("st.agentManager.enableByName",{name:xe})})]},xe))}):null]}),e.jsx(pe,{feedback:v})]}),J=x.useMemo(()=>["main","subagent"].map(xe=>({kind:xe,rows:F.filter(ke=>xe==="main"===ke.profile.main)})).filter(xe=>xe.rows.length>0),[F]),_e=Ta(),[we,G]=x.useState(null),Le=x.useCallback(xe=>{G(xe)},[]),Se=x.useMemo(()=>{const xe=[];for(const ke of J){xe.push({kind:"group",key:`g:${ke.kind}`,label:s(ke.kind==="main"?"st.profiles.groupMain":"st.profiles.groupSubagents"),count:ke.rows.length});for(const W of ke.rows)xe.push({kind:"row",key:`r:${W.key}`,row:W})}return xe},[J,s]),Fe=O!==void 0&&F.length>_e.catalogVirtualizeThreshold,ye=Ri({count:Fe?Se.length:0,getScrollElement:()=>we,estimateSize:xe=>Se[xe]?.kind==="group"?28:34,getItemKey:xe=>Se[xe]?.key??xe,overscan:_e.virtualOverscan,initialRect:{width:240,height:560},observeElementRect:(xe,ke)=>{const W=xe.scrollElement;if(W===null)return;const Re=()=>{const Ue=W.getBoundingClientRect(),Ge=Math.round(Ue.height||W.clientHeight),Ke=Math.round(Ue.width||W.clientWidth);Ge>0&&ke({width:Ke,height:Ge})};if(Re(),typeof ResizeObserver>"u")return;const Ae=new ResizeObserver(Re);return Ae.observe(W),()=>{Ae.disconnect()}},measureElement:xe=>{const ke=Math.round(xe.getBoundingClientRect().height);return ke>0?ke:34},useFlushSync:!1}),ze=Fe?e.jsx("div",{ref:Le,"data-agent-rail":!0,className:"max-h-[calc(100dvh-10rem)] overflow-y-auto",children:e.jsx("div",{style:{height:ye.getTotalSize(),position:"relative"},children:ye.getVirtualItems().map(xe=>{const ke=Se[xe.index];return ke===void 0?null:e.jsx("div",{"data-index":xe.index,ref:ye.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${xe.start}px)`},children:ke.kind==="group"?e.jsxs("p",{className:"flex items-baseline justify-between gap-2 px-2 pt-2 pb-1 text-[11px] font-medium text-ink-faint",children:[e.jsx("span",{className:"truncate",children:ke.label}),e.jsx("span",{className:"shrink-0 tabular-nums",children:ke.count})]}):e.jsx(Na,{itemKey:ke.row.profile.name,label:Kr(ke.row.profile,n),current:ke.row===O,muted:ke.row.profile.disabled||ke.row.diagnostics.some(W=>W.kind==="shadowedBy"),trailing:ke.row.diagnostics.some(W=>wn(W)==="warning")?e.jsx(de,{name:"warning",size:12,className:"shrink-0 text-amber-ink"}):void 0,onSelect:()=>me(ke.row)})},xe.key)})})}):e.jsx("div",{"data-agent-rail":!0,children:J.map(xe=>e.jsx(jo,{count:xe.rows.length,label:s(xe.kind==="main"?"st.profiles.groupMain":"st.profiles.groupSubagents"),children:xe.rows.map(ke=>e.jsx(Na,{itemKey:ke.profile.name,label:Kr(ke.profile,n),current:ke===O,muted:ke.profile.disabled||ke.diagnostics.some(W=>W.kind==="shadowedBy"),trailing:ke.diagnostics.some(W=>wn(W)==="warning")?e.jsx(de,{name:"warning",size:12,className:"shrink-0 text-amber-ink"}):void 0,onSelect:()=>me(ke)},ke.key))},xe.kind))}),Pe=O===void 0?null:e.jsx(NE,{profile:O.profile,writable:O.writable,profiles:z,models:E,diagnostics:O.diagnostics,shippedEntry:Vp(O.profile,H),onSaved:V,onDeleted:()=>{yn(a),a.invalidateQueries({queryKey:["shipped-agent-profiles"]}),a.invalidateQueries({queryKey:["config"]}),c.close(),y({tone:"success",text:s("st.agents.deleted")})},onClose:c.close,onOpenWinner:(()=>{const xe=U?.find(W=>W.name===O.profile.name&&!ta(W,O.profile)),ke=xe===void 0?void 0:F.find(W=>ta(W.profile,xe));return ke===void 0?void 0:()=>me(ke)})(),onToggleEnabled:xe=>Ie(O.profile,xe),toggleSaving:b||I.isLoading,newSessionBlocked:Cb(O.profile,X.get(O.profile))||U!==void 0&&!U.some(xe=>ta(xe,O.profile)),onNewSession:()=>{r(Sb(O.profile,T))},onDuplicate:()=>u({source:O.profile.name})},O.key);return e.jsxs(Me,{id:"st-card-main-agents",title:s("st.agentManager.title"),children:[e.jsx(wo,{selected:O===void 0?null:O.profile.name,label:s("st.profiles.team"),data:{"data-agents-split":""},list:Ne,rail:ze,detail:Pe}),c.selected!==null&&O===void 0&&!A.isLoading?ne!==void 0?e.jsxs("p",{"data-agent-elsewhere":!0,className:"flex flex-wrap items-center gap-x-1.5 text-[13px] text-ink-faint",children:[s("st.profiles.inOtherWorkspace",{name:c.selected,workspace:ne.name??ne.root}),e.jsx("button",{type:"button","data-agent-elsewhere-open":!0,className:Ot,onClick:()=>{ie(ne.id,!0)},children:s("st.profiles.openThere")})]}):e.jsx("p",{"data-agent-missing":!0,className:"text-[13px] text-ink-soft",children:s("st.profiles.notFound")}):null,d!==null?e.jsx($n,{title:s("st.agentManager.new"),overlayId:"agent-create-panel",width:"lg",onClose:fe,data:{"data-agent-create-panel":""},children:e.jsx(Y2,{workspaceId:T,workspaceOptions:ee,profiles:z,shipped:H,initialSource:d.source,onCancel:fe,onCreated:xe=>{V(),u(null),h(Ym(xe)),y({tone:"success",text:s("st.agentManager.created")})}})}):null]})}function AE(t){const s=Pp(Pp(t).subagent);return{serverAllowedTools:Hf(s.allowedTools)}}function $E(t){return{subagent:{allowed_tools:Hf(t)}}}var Sl={},Cl,Zm;function To(){if(Zm)return Cl;Zm=1;const t="\\\\/",s=`[^${t}]`,n=0,a="\\.",i="\\+",r="\\?",o="\\/",l="(?=.)",c="[^/]",d=`(?:${o}|$)`,u=`(?:^|${o})`,p=`${a}{1,2}${d}`,h=`(?!${a})`,b=`(?!${u}${p})`,m=`(?!${a}{0,1}${d})`,f=`(?!${p})`,g=`[^.${o}]`,v=`${c}*?`,w={DOT_LITERAL:a,PLUS_LITERAL:i,QMARK_LITERAL:r,SLASH_LITERAL:o,ONE_CHAR:l,QMARK:c,END_ANCHOR:d,DOTS_SLASH:p,NO_DOT:h,NO_DOTS:b,NO_DOT_SLASH:m,NO_DOTS_SLASH:f,QMARK_NO_DOT:g,STAR:v,START_ANCHOR:u,SEP:"/"},N={...w,SLASH_LITERAL:`[${t}]`,QMARK:s,STAR:`${s}*?`,DOTS_SLASH:`${a}{1,2}(?:[${t}]|$)`,NO_DOT:`(?!${a})`,NO_DOTS:`(?!(?:^|[${t}])${a}{1,2}(?:[${t}]|$))`,NO_DOT_SLASH:`(?!${a}{0,1}(?:[${t}]|$))`,NO_DOTS_SLASH:`(?!${a}{1,2}(?:[${t}]|$))`,QMARK_NO_DOT:`[^.${t}]`,START_ANCHOR:`(?:^|[${t}])`,END_ANCHOR:`(?:[${t}]|$)`,SEP:"\\"},_={__proto__:null,alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};return Cl={DEFAULT_MAX_EXTGLOB_RECURSION:n,MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:_,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(C){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${C.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(C){return C===!0?N:w}},Cl}var Xm;function Io(){return Xm||(Xm=1,(function(t){const{REGEX_BACKSLASH:s,REGEX_REMOVE_BACKSLASH:n,REGEX_SPECIAL_CHARS:a,REGEX_SPECIAL_CHARS_GLOBAL:i}=To();t.isObject=r=>r!==null&&typeof r=="object"&&!Array.isArray(r),t.hasRegexChars=r=>a.test(r),t.isRegexChar=r=>r.length===1&&t.hasRegexChars(r),t.escapeRegex=r=>r.replace(i,"\\$1"),t.toPosixSlashes=r=>r.replace(s,"/"),t.isWindows=()=>{if(typeof navigator<"u"&&navigator.platform){const r=navigator.platform.toLowerCase();return r==="win32"||r==="windows"}return typeof process<"u"&&process.platform?process.platform==="win32":!1},t.removeBackslashes=r=>r.replace(n,o=>o==="\\"?"":o),t.escapeLast=(r,o,l)=>{const c=r.lastIndexOf(o,l);return c===-1?r:r[c-1]==="\\"?t.escapeLast(r,o,c-1):`${r.slice(0,c)}\\${r.slice(c)}`},t.removePrefix=(r,o={})=>{let l=r;return l.startsWith("./")&&(l=l.slice(2),o.prefix="./"),l},t.wrapOutput=(r,o={},l={})=>{const c=l.contains?"":"^",d=l.contains?"":"$";let u=`${c}(?:${r})${d}`;return o.negated===!0&&(u=`(?:^(?!${u}).*$)`),u},t.basename=(r,{windows:o}={})=>{const l=r.split(o?/[\\/]/:"/"),c=l[l.length-1];return c===""?l[l.length-2]:c}})(Sl)),Sl}var _l,ex;function RE(){if(ex)return _l;ex=1;const t=Io(),{CHAR_ASTERISK:s,CHAR_AT:n,CHAR_BACKWARD_SLASH:a,CHAR_COMMA:i,CHAR_DOT:r,CHAR_EXCLAMATION_MARK:o,CHAR_FORWARD_SLASH:l,CHAR_LEFT_CURLY_BRACE:c,CHAR_LEFT_PARENTHESES:d,CHAR_LEFT_SQUARE_BRACKET:u,CHAR_PLUS:p,CHAR_QUESTION_MARK:h,CHAR_RIGHT_CURLY_BRACE:b,CHAR_RIGHT_PARENTHESES:m,CHAR_RIGHT_SQUARE_BRACKET:f}=To(),g=w=>w===l||w===a,v=w=>{w.isPrefix!==!0&&(w.depth=w.isGlobstar?1/0:1)};return _l=(w,N)=>{const _=N||{},C=w.length-1,S=_.parts===!0||_.scanToEnd===!0,k=[],j=[],T=[];let A=w,P=-1,R=0,L=0,I=!1,$=!1,E=!1,M=!1,z=!1,H=!1,U=!1,X=!1,q=!1,F=!1,V=0,se,Y,O={value:"",depth:0,isGlob:!1};const B=()=>P>=C,le=()=>A.charCodeAt(P+1),re=()=>(se=Y,A.charCodeAt(++P));for(;P<C;){Y=re();let me;if(Y===a){U=O.backslashes=!0,Y=re(),Y===c&&(H=!0);continue}if(H===!0||Y===c){for(V++;B()!==!0&&(Y=re());){if(Y===a){U=O.backslashes=!0,re();continue}if(Y===c){V++;continue}if(H!==!0&&Y===r&&(Y=re())===r){if(I=O.isBrace=!0,E=O.isGlob=!0,F=!0,S===!0)continue;break}if(H!==!0&&Y===i){if(I=O.isBrace=!0,E=O.isGlob=!0,F=!0,S===!0)continue;break}if(Y===b&&(V--,V===0)){H=!1,I=O.isBrace=!0,F=!0;break}}if(S===!0)continue;break}if(Y===l){if(k.push(P),j.push(O),O={value:"",depth:0,isGlob:!1},F===!0)continue;if(se===r&&P===R+1){R+=2;continue}L=P+1;continue}if(_.noext!==!0&&(Y===p||Y===n||Y===s||Y===h||Y===o)===!0&&le()===d){if(E=O.isGlob=!0,M=O.isExtglob=!0,F=!0,Y===o&&P===R&&(q=!0),S===!0){for(;B()!==!0&&(Y=re());){if(Y===a){U=O.backslashes=!0,Y=re();continue}if(Y===m){E=O.isGlob=!0,F=!0;break}}continue}break}if(Y===s){if(se===s&&(z=O.isGlobstar=!0),E=O.isGlob=!0,F=!0,S===!0)continue;break}if(Y===h){if(E=O.isGlob=!0,F=!0,S===!0)continue;break}if(Y===u){for(;B()!==!0&&(me=re());){if(me===a){U=O.backslashes=!0,re();continue}if(me===f){$=O.isBracket=!0,E=O.isGlob=!0,F=!0;break}}if(S===!0)continue;break}if(_.nonegate!==!0&&Y===o&&P===R){X=O.negated=!0,R++;continue}if(_.noparen!==!0&&Y===d){if(E=O.isGlob=!0,S===!0){for(;B()!==!0&&(Y=re());){if(Y===d){U=O.backslashes=!0,Y=re();continue}if(Y===m){F=!0;break}}continue}break}if(E===!0){if(F=!0,S===!0)continue;break}}_.noext===!0&&(M=!1,E=!1);let ae=A,ne="",Ee="";R>0&&(ne=A.slice(0,R),A=A.slice(R),L-=R),ae&&E===!0&&L>0?(ae=A.slice(0,L),Ee=A.slice(L)):E===!0?(ae="",Ee=A):ae=A,ae&&ae!==""&&ae!=="/"&&ae!==A&&g(ae.charCodeAt(ae.length-1))&&(ae=ae.slice(0,-1)),_.unescape===!0&&(Ee&&(Ee=t.removeBackslashes(Ee)),ae&&U===!0&&(ae=t.removeBackslashes(ae)));const ie={prefix:ne,input:w,start:R,base:ae,glob:Ee,isBrace:I,isBracket:$,isGlob:E,isExtglob:M,isGlobstar:z,negated:X,negatedExtglob:q};if(_.tokens===!0&&(ie.maxDepth=0,g(Y)||j.push(O),ie.tokens=j),_.parts===!0||_.tokens===!0){let me;for(let fe=0;fe<k.length;fe++){const Ie=me?me+1:R,te=k[fe],ee=w.slice(Ie,te);_.tokens&&(fe===0&&R!==0?(j[fe].isPrefix=!0,j[fe].value=ne):j[fe].value=ee,v(j[fe]),ie.maxDepth+=j[fe].depth),(fe!==0||ee!=="")&&T.push(ee),me=te}if(me&&me+1<w.length){const fe=w.slice(me+1);T.push(fe),_.tokens&&(j[j.length-1].value=fe,v(j[j.length-1]),ie.maxDepth+=j[j.length-1].depth)}ie.slashes=k,ie.parts=T}return ie},_l}var El,tx;function LE(){if(tx)return El;tx=1;const t=To(),s=Io(),{MAX_LENGTH:n,POSIX_REGEX_SOURCE:a,REGEX_NON_SPECIAL_CHARS:i,REGEX_SPECIAL_CHARS_BACKREF:r,REPLACEMENTS:o}=t,l=(y,w)=>{if(typeof w.expandRange=="function")return w.expandRange(...y,w);y.sort();const N=`[${y.join("-")}]`;try{new RegExp(N)}catch{return y.map(C=>s.escapeRegex(C)).join("..")}return N},c=(y,w)=>`Missing ${y}: "${w}" - use "\\\\${w}" to match literal characters`,d=y=>{const w=[];let N=0,_=0,C=0,S="",k=!1;for(const j of y){if(k===!0){S+=j,k=!1;continue}if(j==="\\"){S+=j,k=!0;continue}if(j==='"'){C=C===1?0:1,S+=j;continue}if(C===0){if(j==="[")N++;else if(j==="]"&&N>0)N--;else if(N===0){if(j==="(")_++;else if(j===")"&&_>0)_--;else if(j==="|"&&_===0){w.push(S),S="";continue}}}S+=j}return w.push(S),w},u=y=>{let w=!1;for(const N of y){if(w===!0){w=!1;continue}if(N==="\\"){w=!0;continue}if(/[?*+@!()[\]{}]/.test(N))return!1}return!0},p=y=>{let w=y.trim(),N=!0;for(;N===!0;)N=!1,/^@\([^\\()[\]{}|]+\)$/.test(w)&&(w=w.slice(2,-1),N=!0);if(u(w))return w.replace(/\\(.)/g,"$1")},h=y=>{const w=y.map(p).filter(Boolean);for(let N=0;N<w.length;N++)for(let _=N+1;_<w.length;_++){const C=w[N],S=w[_],k=C[0];if(!(!k||C!==k.repeat(C.length)||S!==k.repeat(S.length))&&(C===S||C.startsWith(S)||S.startsWith(C)))return!0}return!1},b=(y,w=!0)=>{if(y[0]!=="+"&&y[0]!=="*"||y[1]!=="(")return;let N=0,_=0,C=0,S=!1;for(let k=1;k<y.length;k++){const j=y[k];if(S===!0){S=!1;continue}if(j==="\\"){S=!0;continue}if(j==='"'){C=C===1?0:1;continue}if(C!==1){if(j==="["){N++;continue}if(j==="]"&&N>0){N--;continue}if(!(N>0)){if(j==="("){_++;continue}if(j===")"&&(_--,_===0))return w===!0&&k!==y.length-1?void 0:{type:y[0],body:y.slice(2,k),end:k}}}}},m=y=>{let w=0;const N=[];for(;w<y.length;){const C=b(y.slice(w),!1);if(!C||C.type!=="*")return;const S=d(C.body).map(j=>j.trim());if(S.length!==1)return;const k=p(S[0]);if(!k||k.length!==1)return;N.push(k),w+=C.end+1}return N.length<1?void 0:`${N.length===1?s.escapeRegex(N[0]):`[${N.map(C=>s.escapeRegex(C)).join("")}]`}*`},f=y=>{let w=0,N=y.trim(),_=b(N);for(;_;)w++,N=_.body.trim(),_=b(N);return w},g=(y,w)=>{if(w.maxExtglobRecursion===!1)return{risky:!1};const N=typeof w.maxExtglobRecursion=="number"?w.maxExtglobRecursion:t.DEFAULT_MAX_EXTGLOB_RECURSION,_=d(y).map(C=>C.trim());if(_.length>1&&(_.some(C=>C==="")||_.some(C=>/^[*?]+$/.test(C))||h(_)))return{risky:!0};for(const C of _){const S=m(C);if(S)return{risky:!0,safeOutput:S};if(f(C)>N)return{risky:!0}}return{risky:!1}},v=(y,w)=>{if(typeof y!="string")throw new TypeError("Expected a string");y=o[y]||y;const N={...w},_=typeof N.maxLength=="number"?Math.min(n,N.maxLength):n;let C=y.length;if(C>_)throw new SyntaxError(`Input length: ${C}, exceeds maximum allowed length: ${_}`);const S={type:"bos",value:"",output:N.prepend||""},k=[S],j=N.capture?"":"?:",T=t.globChars(N.windows),A=t.extglobChars(T),{DOT_LITERAL:P,PLUS_LITERAL:R,SLASH_LITERAL:L,ONE_CHAR:I,DOTS_SLASH:$,NO_DOT:E,NO_DOT_SLASH:M,NO_DOTS_SLASH:z,QMARK:H,QMARK_NO_DOT:U,STAR:X,START_ANCHOR:q}=T,F=J=>`(${j}(?:(?!${q}${J.dot?$:P}).)*?)`,V=N.dot?"":E,se=N.dot?H:U;let Y=N.bash===!0?F(N):X;N.capture&&(Y=`(${Y})`),typeof N.noext=="boolean"&&(N.noextglob=N.noext);const O={input:y,index:-1,start:0,dot:N.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:k};y=s.removePrefix(y,O),C=y.length;const B=[],le=[],re=[];let ae=S,ne;const Ee=()=>O.index===C-1,ie=O.peek=(J=1)=>y[O.index+J],me=O.advance=()=>y[++O.index]||"",fe=()=>y.slice(O.index+1),Ie=(J="",_e=0)=>{O.consumed+=J,O.index+=_e},te=J=>{O.output+=J.output!=null?J.output:J.value,Ie(J.value)},ee=()=>{let J=1;for(;ie()==="!"&&(ie(2)!=="("||ie(3)==="?");)me(),O.start++,J++;return J%2===0?!1:(O.negated=!0,O.start++,!0)},K=J=>{O[J]++,re.push(J)},Z=J=>{O[J]--,re.pop()},ue=J=>{if(ae.type==="globstar"){const _e=O.braces>0&&(J.type==="comma"||J.type==="brace"),we=J.extglob===!0||B.length&&(J.type==="pipe"||J.type==="paren");J.type!=="slash"&&J.type!=="paren"&&!_e&&!we&&(O.output=O.output.slice(0,-ae.output.length),ae.type="star",ae.value="*",ae.output=Y,O.output+=ae.output)}if(B.length&&J.type!=="paren"&&(B[B.length-1].inner+=J.value),(J.value||J.output)&&te(J),ae&&ae.type==="text"&&J.type==="text"){ae.output=(ae.output||ae.value)+J.value,ae.value+=J.value;return}J.prev=ae,k.push(J),ae=J},Te=(J,_e)=>{const we={...A[_e],conditions:1,inner:""};we.prev=ae,we.parens=O.parens,we.output=O.output,we.startIndex=O.index,we.tokensIndex=k.length;const G=(N.capture?"(":"")+we.open;K("parens"),ue({type:J,value:_e,output:O.output?"":I}),ue({type:"paren",extglob:!0,value:me(),output:G}),B.push(we)},Ne=J=>{const _e=y.slice(J.startIndex,O.index+1),we=y.slice(J.startIndex+2,O.index),G=g(we,N);if((J.type==="plus"||J.type==="star")&&G.risky){const Fe=G.safeOutput?(J.output?"":I)+(N.capture?`(${G.safeOutput})`:G.safeOutput):void 0,ye=k[J.tokensIndex];ye.type="text",ye.value=_e,ye.output=Fe||s.escapeRegex(_e);for(let ze=J.tokensIndex+1;ze<k.length;ze++)k[ze].value="",k[ze].output="",delete k[ze].suffix;O.output=J.output+ye.output,O.backtrack=!0,ue({type:"paren",extglob:!0,value:ne,output:""}),Z("parens");return}let Le=J.close+(N.capture?")":""),Se;if(J.type==="negate"){let Fe=Y;if(J.inner&&J.inner.length>1&&J.inner.includes("/")&&(Fe=F(N)),(Fe!==Y||Ee()||/^\)+$/.test(fe()))&&(Le=J.close=`)$))${Fe}`),J.inner.includes("*")&&(Se=fe())&&/^\.[^\\/.]+$/.test(Se)){const ye=v(Se,{...w,fastpaths:!1}).output;Le=J.close=`)${ye})${Fe})`}J.prev.type==="bos"&&(O.negatedExtglob=!0)}ue({type:"paren",extglob:!0,value:ne,output:Le}),Z("parens")};if(N.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(y)){let J=!1,_e=y.replace(r,(we,G,Le,Se,Fe,ye)=>Se==="\\"?(J=!0,we):Se==="?"?G?G+Se+(Fe?H.repeat(Fe.length):""):ye===0?se+(Fe?H.repeat(Fe.length):""):H.repeat(Le.length):Se==="."?P.repeat(Le.length):Se==="*"?G?G+Se+(Fe?Y:""):Y:G?we:`\\${we}`);return J===!0&&(N.unescape===!0?_e=_e.replace(/\\/g,""):_e=_e.replace(/\\+/g,we=>we.length%2===0?"\\\\":we?"\\":"")),_e===y&&N.contains===!0?(O.output=y,O):(O.output=s.wrapOutput(_e,O,w),O)}for(;!Ee();){if(ne=me(),ne==="\0")continue;if(ne==="\\"){const we=ie();if(we==="/"&&N.bash!==!0||we==="."||we===";")continue;if(!we){ne+="\\",ue({type:"text",value:ne});continue}const G=/^\\+/.exec(fe());let Le=0;if(G&&G[0].length>2&&(Le=G[0].length,O.index+=Le,Le%2!==0&&(ne+="\\")),N.unescape===!0?ne=me():ne+=me(),O.brackets===0){ue({type:"text",value:ne});continue}}if(O.brackets>0&&(ne!=="]"||ae.value==="["||ae.value==="[^")){if(N.posix!==!1&&ne===":"){const we=ae.value.slice(1);if(we.includes("[")&&(ae.posix=!0,we.includes(":"))){const G=ae.value.lastIndexOf("["),Le=ae.value.slice(0,G),Se=ae.value.slice(G+2),Fe=a[Se];if(Fe){ae.value=Le+Fe,O.backtrack=!0,me(),!S.output&&k.indexOf(ae)===1&&(S.output=I);continue}}}(ne==="["&&ie()!==":"||ne==="-"&&ie()==="]")&&(ne=`\\${ne}`),ne==="]"&&(ae.value==="["||ae.value==="[^")&&(ne=`\\${ne}`),N.posix===!0&&ne==="!"&&ae.value==="["&&(ne="^"),ae.value+=ne,te({value:ne});continue}if(O.quotes===1&&ne!=='"'){ne=s.escapeRegex(ne),ae.value+=ne,te({value:ne});continue}if(ne==='"'){O.quotes=O.quotes===1?0:1,N.keepQuotes===!0&&ue({type:"text",value:ne});continue}if(ne==="("){K("parens"),ue({type:"paren",value:ne});continue}if(ne===")"){if(O.parens===0&&N.strictBrackets===!0)throw new SyntaxError(c("opening","("));const we=B[B.length-1];if(we&&O.parens===we.parens+1){Ne(B.pop());continue}ue({type:"paren",value:ne,output:O.parens?")":"\\)"}),Z("parens");continue}if(ne==="["){if(N.nobracket===!0||!fe().includes("]")){if(N.nobracket!==!0&&N.strictBrackets===!0)throw new SyntaxError(c("closing","]"));ne=`\\${ne}`}else K("brackets");ue({type:"bracket",value:ne});continue}if(ne==="]"){if(N.nobracket===!0||ae&&ae.type==="bracket"&&ae.value.length===1){ue({type:"text",value:ne,output:`\\${ne}`});continue}if(O.brackets===0){if(N.strictBrackets===!0)throw new SyntaxError(c("opening","["));ue({type:"text",value:ne,output:`\\${ne}`});continue}Z("brackets");const we=ae.value.slice(1);if(ae.posix!==!0&&we[0]==="^"&&!we.includes("/")&&(ne=`/${ne}`),ae.value+=ne,te({value:ne}),N.literalBrackets===!1||s.hasRegexChars(we))continue;const G=s.escapeRegex(ae.value);if(O.output=O.output.slice(0,-ae.value.length),N.literalBrackets===!0){O.output+=G,ae.value=G;continue}ae.value=`(${j}${G}|${ae.value})`,O.output+=ae.value;continue}if(ne==="{"&&N.nobrace!==!0){K("braces");const we={type:"brace",value:ne,output:"(",outputIndex:O.output.length,tokensIndex:O.tokens.length};le.push(we),ue(we);continue}if(ne==="}"){const we=le[le.length-1];if(N.nobrace===!0||!we){ue({type:"text",value:ne,output:ne});continue}let G=")";if(we.dots===!0){const Le=k.slice(),Se=[];for(let Fe=Le.length-1;Fe>=0&&(k.pop(),Le[Fe].type!=="brace");Fe--)Le[Fe].type!=="dots"&&Se.unshift(Le[Fe].value);G=l(Se,N),O.backtrack=!0}if(we.comma!==!0&&we.dots!==!0){const Le=O.output.slice(0,we.outputIndex),Se=O.tokens.slice(we.tokensIndex);we.value=we.output="\\{",ne=G="\\}",O.output=Le;for(const Fe of Se)O.output+=Fe.output||Fe.value}ue({type:"brace",value:ne,output:G}),Z("braces"),le.pop();continue}if(ne==="|"){B.length>0&&B[B.length-1].conditions++,ue({type:"text",value:ne});continue}if(ne===","){let we=ne;const G=le[le.length-1];G&&re[re.length-1]==="braces"&&(G.comma=!0,we="|"),ue({type:"comma",value:ne,output:we});continue}if(ne==="/"){if(ae.type==="dot"&&O.index===O.start+1){O.start=O.index+1,O.consumed="",O.output="",k.pop(),ae=S;continue}ue({type:"slash",value:ne,output:L});continue}if(ne==="."){if(O.braces>0&&ae.type==="dot"){ae.value==="."&&(ae.output=P);const we=le[le.length-1];ae.type="dots",ae.output+=ne,ae.value+=ne,we.dots=!0;continue}if(O.braces+O.parens===0&&ae.type!=="bos"&&ae.type!=="slash"){ue({type:"text",value:ne,output:P});continue}ue({type:"dot",value:ne,output:P});continue}if(ne==="?"){if(!(ae&&ae.value==="(")&&N.noextglob!==!0&&ie()==="("&&ie(2)!=="?"){Te("qmark",ne);continue}if(ae&&ae.type==="paren"){const G=ie();let Le=ne;(ae.value==="("&&!/[!=<:]/.test(G)||G==="<"&&!/<([!=]|\w+>)/.test(fe()))&&(Le=`\\${ne}`),ue({type:"text",value:ne,output:Le});continue}if(N.dot!==!0&&(ae.type==="slash"||ae.type==="bos")){ue({type:"qmark",value:ne,output:U});continue}ue({type:"qmark",value:ne,output:H});continue}if(ne==="!"){if(N.noextglob!==!0&&ie()==="("&&(ie(2)!=="?"||!/[!=<:]/.test(ie(3)))){Te("negate",ne);continue}if(N.nonegate!==!0&&O.index===0){ee();continue}}if(ne==="+"){if(N.noextglob!==!0&&ie()==="("&&ie(2)!=="?"){Te("plus",ne);continue}if(ae&&ae.value==="("||N.regex===!1){ue({type:"plus",value:ne,output:R});continue}if(ae&&(ae.type==="bracket"||ae.type==="paren"||ae.type==="brace")||O.parens>0){ue({type:"plus",value:ne});continue}ue({type:"plus",value:R});continue}if(ne==="@"){if(N.noextglob!==!0&&ie()==="("&&ie(2)!=="?"){ue({type:"at",extglob:!0,value:ne,output:""});continue}ue({type:"text",value:ne});continue}if(ne!=="*"){(ne==="$"||ne==="^")&&(ne=`\\${ne}`);const we=i.exec(fe());we&&(ne+=we[0],O.index+=we[0].length),ue({type:"text",value:ne});continue}if(ae&&(ae.type==="globstar"||ae.star===!0)){ae.type="star",ae.star=!0,ae.value+=ne,ae.output=Y,O.backtrack=!0,O.globstar=!0,Ie(ne);continue}let J=fe();if(N.noextglob!==!0&&/^\([^?]/.test(J)){Te("star",ne);continue}if(ae.type==="star"){if(N.noglobstar===!0){Ie(ne);continue}const we=ae.prev,G=we.prev,Le=we.type==="slash"||we.type==="bos",Se=G&&(G.type==="star"||G.type==="globstar");if(N.bash===!0&&(!Le||J[0]&&J[0]!=="/")){ue({type:"star",value:ne,output:""});continue}const Fe=O.braces>0&&(we.type==="comma"||we.type==="brace"),ye=B.length&&(we.type==="pipe"||we.type==="paren");if(!Le&&we.type!=="paren"&&!Fe&&!ye){ue({type:"star",value:ne,output:""});continue}for(;J.slice(0,3)==="/**";){const ze=y[O.index+4];if(ze&&ze!=="/")break;J=J.slice(3),Ie("/**",3)}if(we.type==="bos"&&Ee()){ae.type="globstar",ae.value+=ne,ae.output=F(N),O.output=ae.output,O.globstar=!0,Ie(ne);continue}if(we.type==="slash"&&we.prev.type!=="bos"&&!Se&&Ee()){O.output=O.output.slice(0,-(we.output+ae.output).length),we.output=`(?:${we.output}`,ae.type="globstar",ae.output=F(N)+(N.strictSlashes?")":"|$)"),ae.value+=ne,O.globstar=!0,O.output+=we.output+ae.output,Ie(ne);continue}if(we.type==="slash"&&we.prev.type!=="bos"&&J[0]==="/"){const ze=J[1]!==void 0?"|$":"";O.output=O.output.slice(0,-(we.output+ae.output).length),we.output=`(?:${we.output}`,ae.type="globstar",ae.output=`${F(N)}${L}|${L}${ze})`,ae.value+=ne,O.output+=we.output+ae.output,O.globstar=!0,Ie(ne+me()),ue({type:"slash",value:"/",output:""});continue}if(we.type==="bos"&&J[0]==="/"){ae.type="globstar",ae.value+=ne,ae.output=`(?:^|${L}|${F(N)}${L})`,O.output=ae.output,O.globstar=!0,Ie(ne+me()),ue({type:"slash",value:"/",output:""});continue}O.output=O.output.slice(0,-ae.output.length),ae.type="globstar",ae.output=F(N),ae.value+=ne,O.output+=ae.output,O.globstar=!0,Ie(ne);continue}const _e={type:"star",value:ne,output:Y};if(N.bash===!0){_e.output=".*?",(ae.type==="bos"||ae.type==="slash")&&(_e.output=V+_e.output),ue(_e);continue}if(ae&&(ae.type==="bracket"||ae.type==="paren")&&N.regex===!0){_e.output=ne,ue(_e);continue}(O.index===O.start||ae.type==="slash"||ae.type==="dot")&&(ae.type==="dot"?(O.output+=M,ae.output+=M):N.dot===!0?(O.output+=z,ae.output+=z):(O.output+=V,ae.output+=V),ie()!=="*"&&(O.output+=I,ae.output+=I)),ue(_e)}for(;O.brackets>0;){if(N.strictBrackets===!0)throw new SyntaxError(c("closing","]"));O.output=s.escapeLast(O.output,"["),Z("brackets")}for(;O.parens>0;){if(N.strictBrackets===!0)throw new SyntaxError(c("closing",")"));O.output=s.escapeLast(O.output,"("),Z("parens")}for(;O.braces>0;){if(N.strictBrackets===!0)throw new SyntaxError(c("closing","}"));O.output=s.escapeLast(O.output,"{"),Z("braces")}if(N.strictSlashes!==!0&&(ae.type==="star"||ae.type==="bracket")&&ue({type:"maybe_slash",value:"",output:`${L}?`}),O.backtrack===!0){O.output="";for(const J of O.tokens)O.output+=J.output!=null?J.output:J.value,J.suffix&&(O.output+=J.suffix)}return O};return v.fastpaths=(y,w)=>{const N={...w},_=typeof N.maxLength=="number"?Math.min(n,N.maxLength):n,C=y.length;if(C>_)throw new SyntaxError(`Input length: ${C}, exceeds maximum allowed length: ${_}`);y=o[y]||y;const{DOT_LITERAL:S,SLASH_LITERAL:k,ONE_CHAR:j,DOTS_SLASH:T,NO_DOT:A,NO_DOTS:P,NO_DOTS_SLASH:R,STAR:L,START_ANCHOR:I}=t.globChars(N.windows),$=N.dot?P:A,E=N.dot?R:A,M=N.capture?"":"?:",z={negated:!1,prefix:""};let H=N.bash===!0?".*?":L;N.capture&&(H=`(${H})`);const U=V=>V.noglobstar===!0?H:`(${M}(?:(?!${I}${V.dot?T:S}).)*?)`,X=V=>{switch(V){case"*":return`${$}${j}${H}`;case".*":return`${S}${j}${H}`;case"*.*":return`${$}${H}${S}${j}${H}`;case"*/*":return`${$}${H}${k}${j}${E}${H}`;case"**":return $+U(N);case"**/*":return`(?:${$}${U(N)}${k})?${E}${j}${H}`;case"**/*.*":return`(?:${$}${U(N)}${k})?${E}${H}${S}${j}${H}`;case"**/.*":return`(?:${$}${U(N)}${k})?${S}${j}${H}`;default:{const se=/^(.*?)\.(\w+)$/.exec(V);if(!se)return;const Y=X(se[1]);return Y?Y+S+se[2]:void 0}}},q=s.removePrefix(y,z);let F=X(q);return F&&N.strictSlashes!==!0&&(F+=`${k}?`),F},El=v,El}var Tl,sx;function ME(){if(sx)return Tl;sx=1;const t=RE(),s=LE(),n=Io(),a=To(),i=o=>o&&typeof o=="object"&&!Array.isArray(o),r=(o,l,c=!1)=>{if(Array.isArray(o)){const g=o.map(y=>r(y,l,c));return y=>{for(const w of g){const N=w(y);if(N)return N}return!1}}const d=i(o)&&o.tokens&&o.input;if(o===""||typeof o!="string"&&!d)throw new TypeError("Expected pattern to be a non-empty string");const u=l||{},p=u.windows,h=d?r.compileRe(o,l):r.makeRe(o,l,!1,!0),b=h.state;delete h.state;let m=()=>!1;if(u.ignore){const g={...l,ignore:null,onMatch:null,onResult:null};m=r(u.ignore,g,c)}const f=(g,v=!1)=>{const{isMatch:y,match:w,output:N}=r.test(g,h,l,{glob:o,posix:p}),_={glob:o,state:b,regex:h,posix:p,input:g,output:N,match:w,isMatch:y};return typeof u.onResult=="function"&&u.onResult(_),y===!1?(_.isMatch=!1,v?_:!1):m(g)?(typeof u.onIgnore=="function"&&u.onIgnore(_),_.isMatch=!1,v?_:!1):(typeof u.onMatch=="function"&&u.onMatch(_),v?_:!0)};return c&&(f.state=b),f};return r.test=(o,l,c,{glob:d,posix:u}={})=>{if(typeof o!="string")throw new TypeError("Expected input to be a string");if(o==="")return{isMatch:!1,output:""};const p=c||{},h=p.format||(u?n.toPosixSlashes:null);let b=o===d,m=b&&h?h(o):o;return b===!1&&(m=h?h(o):o,b=m===d),(b===!1||p.capture===!0)&&(p.matchBase===!0||p.basename===!0?b=r.matchBase(o,l,c,u):b=l.exec(m)),{isMatch:!!b,match:b,output:m}},r.matchBase=(o,l,c)=>(l instanceof RegExp?l:r.makeRe(l,c)).test(n.basename(o)),r.isMatch=(o,l,c)=>r(l,c)(o),r.parse=(o,l)=>Array.isArray(o)?o.map(c=>r.parse(c,l)):s(o,{...l,fastpaths:!1}),r.scan=(o,l)=>t(o,l),r.compileRe=(o,l,c=!1,d=!1)=>{if(c===!0)return o.output;const u=l||{},p=u.contains?"":"^",h=u.contains?"":"$";let b=`${p}(?:${o.output})${h}`;o&&o.negated===!0&&(b=`^(?!${b}).*$`);const m=r.toRegex(b,l);return d===!0&&(m.state=o),m},r.makeRe=(o,l={},c=!1,d=!1)=>{if(!o||typeof o!="string")throw new TypeError("Expected a non-empty string");let u={negated:!1,fastpaths:!0};return l.fastpaths!==!1&&(o[0]==="."||o[0]==="*")&&(u.output=s.fastpaths(o,l)),u.output||(u=s(o,l)),r.compileRe(u,l,c,d)},r.toRegex=(o,l)=>{try{const c=l||{};return new RegExp(o,c.flags||(c.nocase?"i":""))}catch(c){if(l&&l.debug===!0)throw c;return/$^/}},r.constants=a,Tl=r,Tl}var Il,nx;function OE(){if(nx)return Il;nx=1;const t=ME(),s=Io();function n(a,i,r=!1){return i&&(i.windows===null||i.windows===void 0)&&(i={...i,windows:s.isWindows()}),t(a,i,r)}return Object.assign(n,t),Il=n,Il}var DE=OE();const qc=Oj(DE),Og={Cron:["CronCreate","CronList","CronDelete"],Goal:["CreateGoal","GetGoal","SetGoalBudget","UpdateGoal"]};function wi(t){return Og[t]??[]}function Ni(t){for(const[s,n]of Object.entries(Og))if(n.includes(t))return s}function Dg(t){return t.startsWith("mcp__")}function Fg(t){return t.startsWith("plugin__")}function lu(t){return/^browser__(?:agent_browser_[a-z0-9_]+|codex_[a-z0-9_]+)$/.test(t)}function cu(t){return t==="browser__ego_run"}function FE(t,s){return t!==void 0&&t.includes("browser__*")&&(lu(s)||cu(s))}function Si(t,s,n="builtin"){return t!==void 0&&(n==="builtin"&&t.includes("browser__*")&&lu(s)||t.includes(s)||Ni(s)!==void 0&&t.includes(Ni(s))||wi(s).some(a=>t.includes(a)))}function Bc(t,s){return FE(t,s)||t.includes(s)||Ni(s)!==void 0&&t.includes(Ni(s))||wi(s).length>0&&wi(s).every(n=>t.includes(n))}function qE(t,s,n){const a=[t.tools,...t.toolAllowPolicies??[]].filter(i=>i!==void 0);for(const i of a)if(!(i.includes("*")||(n==="mcp"?i.filter(o=>Dg(o)).some(o=>qc.isMatch(s,o)):n==="plugin"&&i.filter(o=>Fg(o)).some(o=>qc.isMatch(s,o))||Si(i,s,n))))return!1;return!0}function BE(t){return t!==void 0&&Bc(t,"browser__ego_run")}function KE(t){const s=[t.tools,...t.toolAllowPolicies??[]].filter(n=>n!==void 0);return s.some(n=>n.includes("browser__ego_run"))?s.every(n=>n.includes("*")||n.includes("browser__ego_run")):!1}function pr(t,s,n="builtin"){return n==="builtin"&&cu(s)?BE(t.disallowedTools)?!1:KE(t)?!0:pr(t,"Bash","builtin"):qE(t,s,n)?t.disallowedTools===void 0?!0:n!=="mcp"&&n!=="plugin"?!Bc(t.disallowedTools,s):!(n==="mcp"?t.disallowedTools.filter(i=>Dg(i)):t.disallowedTools.filter(i=>Fg(i))).some(i=>qc.isMatch(s,i))&&(n!=="plugin"||!Bc(t.disallowedTools,s)):!1}const UE=["AskUserQuestion","Cron","CronCreate","CronDelete","CronList","EnterPlanMode","ExitPlanMode","ThreadCreate","ThreadList","ThreadRead","ThreadWait"],HE=["MemoryWrite","ThreadSend","SendMessage","Goal","CreateGoal","GetGoal","SetGoalBudget","UpdateGoal"];function ax(t,s="builtin"){return s!=="builtin"?"allowed":HE.includes(t)?"main-only":t==="BrowserConnections"||t==="BrowserTabs"||lu(t)||cu(t)||UE.includes(t)?"opt-in":"allowed"}const Ut="__default__";function qg(t){return t==="builtin"||t==="mcp"?t:"plugin"}function Bg(t){const s=qg(t.source),n=ax(t.name,s);if(n==="main-only"||s!=="builtin")return n;const a=wi(t.name);return a.length>0&&a.every(i=>ax(i,"builtin")==="main-only")?"main-only":n}const Hr="*";function du(t){const s=t===null?[]:t.filter(a=>a!==Hr),n=t!==null&&t.includes(Hr);return{allowlist:t===null||n?void 0:s,names:s,unrestricted:t===null||n,wildcard:n}}function zr(t,s){return Si(t.names,s)}function Kc(t,s){return Si([...t],s)}function zE(t,s,n){return n?Si(t,s)?t:[...new Set([...t,s])]:t.filter(a=>!Kg(a,s))}function Kg(t,s){return t===s?!0:wi(s).includes(t)?Ni(t)===s:!1}function Ug(t,s,n){const a=du(t);if(n)return zr(a,s)?t??[]:a.unrestricted?[Hr,...a.names,s]:[...a.names,s];if(!zr(a,s))return t??[];const i=a.names.filter(r=>!Kg(r,s));return a.unrestricted&&t===null?[]:a.wildcard?[Hr,...i]:i}function QE(t,s){const n=du(t);return t===null||zr(n,s)?t:Ug(t,s,!0)}function ix(t,s){const n=Bg(t);return n==="main-only"?{status:"fixed",reason:"main-only",action:null}:n!=="opt-in"?{status:"allowed",reason:"default-allowed",action:null}:Kc(s,t.name)?{status:"allowed",reason:"server-opt-in",action:"opt-in"}:{status:"blocked",reason:"opt-in-off",action:"opt-in"}}function rx(t,s,n){if(!n.native)return{status:"fixed",reason:"executor",action:null};const a=Bg(t);if(a==="main-only")return{status:"fixed",reason:"main-only",action:null};const i=qg(t.source),r=du(s.tools),o=r.allowlist,l=o!==void 0&&pr({tools:o},t.name,i),c=zr(r,t.name),d=s.disallowedTools,u=d!==null&&!pr({disallowedTools:d},t.name,i);if(u){const b=d.includes(t.name)&&pr({tools:o,disallowedTools:d.filter(m=>m!==t.name)},t.name,i);return{status:"blocked",reason:"profile-denied",action:n.editable?b?"allow":"editor":null}}return o!==void 0&&!l?{status:"blocked",reason:"profile-allowlist",action:n.editable?"allow":null}:a==="opt-in"&&!u?c?{status:"allowed",reason:"profile-explicit",inheritAllows:!0,action:n.editable?"opt-in":null}:Kc(n.serverAllowed,t.name)?{status:"allowed",reason:"server-opt-in",inheritAllows:!0,action:null}:{status:"blocked",reason:"opt-in-off",inheritAllows:!1,action:n.editable?"opt-in":null}:l?{status:"allowed",reason:c?"profile-explicit":"profile-pattern",action:n.editable?"deny":null}:{status:"inherit",inheritAllows:a==="opt-in"?Kc(n.serverAllowed,t.name):!0,reason:"inherit",action:n.editable?"deny":null}}const ox=["builtin","plugin","mcp","skill"];function GE(t){return[...t].toSorted((s,n)=>ox.indexOf(s.source)-ox.indexOf(n.source)||s.name.localeCompare(n.name))}function Pl(t,s){return t===null||s===null?t===s:t.length===s.length&&t.every((n,a)=>n===s[a])}function WE(t){return t.description.split(`
|
|
12
|
+
`,1)[0]?.trim()??""}const lx="subagent-tool-draft";function VE(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=je({queryKey:["config","web-capability"],queryFn:()=>t.getConfig(),enabled:typeof t.getConfig=="function"&&typeof t.patchConfig=="function",staleTime:3e4}),i=Ns(a.data,"web");if(i===void 0)return null;const r=o=>{t.patchConfig(o).then(l=>{n.setQueryData(["config","web-capability"],l)})};return e.jsxs("div",{"data-web-capability":!0,className:"space-y-2 border-b border-hairline pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-[13px] text-ink",children:s("cap.web")}),e.jsx("button",{type:"button",role:"switch","aria-checked":i.allowed,"data-web-allow":!0,disabled:i.host_locked,onClick:()=>{r({optional_capabilities:{web_allowed:i.allowed?!1:null}})},className:"min-h-6 rounded px-2 text-[12px] text-ink-soft disabled:opacity-40",children:s(i.allowed?"cap.choice.on":"cap.choice.off")})]}),e.jsx(_r,{id:"web",state:i,onChange:o=>{r({optional_capabilities:{defaults:{web:o}}})}})]})}function YE(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=Tt(),r=Ln(),[o,l]=x.useState(()=>{if(typeof window>"u")return Ut;const Z=new URLSearchParams(window.location.search).get("object");return Z!==null&&Z!==""?Z:Ut}),[c,d]=x.useState(null),[u,p]=x.useState(""),[h,b]=x.useState(null),[m,f]=x.useState("list"),[g,v]=x.useState(!1),[y,w]=x.useState(null),[N,_]=Je(),C=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),S=je({queryKey:["named-agent-profiles","global"],queryFn:()=>ii(t,{mode:"global"}),staleTime:15e3,refetchInterval:Tr}),k=je({queryKey:["tools","global"],queryFn:()=>t.listTools(),staleTime:3e4}),j=x.useMemo(()=>{const Z=Pd(S.data?.items??[]);return JE(Z.filter(ue=>!ue.main&&!ue.disabled)).toSorted((ue,Te)=>ue.name.localeCompare(Te.name))},[S.data]),T=x.useMemo(()=>AE(C.data).serverAllowedTools,[C.data]),A=c!==null&&c.kind==="rule"?c.allowedTools:T,P=c!==null&&c.kind==="profile"?j.find(Z=>mn(Z)===mn(c.target))??c.target:null,R=c===null||c.kind==="rule"?null:qr(P??c.target),L=c===null?!1:c.kind==="rule"?!Pl(c.allowedTools,T):R===null||!Pl(c.profile.tools,R.tools)||!Pl(c.profile.disallowedTools,R.disallowedTools),I=o===Ut?void 0:j.find(Z=>mn(Z)===o)??j.find(Z=>Z.name===o);x.useEffect(()=>{if(o!==Ut&&I!==void 0){const Z=mn(I);Z!==o&&l(Z)}},[o,I]);const $=x.useMemo(()=>I===void 0?[]:K_(I),[I]),E=$.some(Z=>Z.editable),M=(I?.executor??"native")==="native",z=x.useMemo(()=>I===void 0?null:qr(I),[I]),H=c!==null&&c.kind==="profile"&&c.object===o,U=H?c.profile:z,X=k.data?.tools,q=x.useMemo(()=>X===void 0?[]:GE(B_(X,u)),[X,u]),F=x.useMemo(()=>{if(o===Ut){const Ne=new Set(A),J=c!==null&&c.kind==="rule"?new Set(T):null;return q.map(_e=>{const we=ix(_e,Ne),G=J!==null&&ix(_e,J).status!==we.status;return{tool:_e,state:we,changed:G}})}const Z=new Set(T),ue=U??{tools:null,disallowedTools:null},Te=H?R??{tools:null,disallowedTools:null}:null;return q.map(Ne=>{const J=rx(Ne,ue,{editable:E,native:M,serverAllowed:Z}),_e=Te!==null&&rx(Ne,Te,{editable:E,native:M,serverAllowed:Z}).status!==J.status;return{tool:Ne,state:J,changed:_e}})},[q,o,A,T,U,H,R,E,M,c]),V=x.useMemo(()=>F.filter(Z=>Z.changed).length,[F]),se=F.find(Z=>Z.tool.name===h),Y=q.length,O=X?.length??0,B=(Z,ue)=>{d({kind:"rule",allowedTools:zE(A,Z,ue)}),w(null)},le=(Z,ue)=>{if(I===void 0||U===null)return;const Te=U,Ne=ue?{tools:QE(Te.tools,Z),disallowedTools:Te.disallowedTools?.filter(J=>J!==Z)??null}:{tools:Te.tools,disallowedTools:[...new Set([...Te.disallowedTools??[],Z])]};d({kind:"profile",object:mn(I),target:I,profile:Ne}),w(null)},re=(Z,ue)=>{I===void 0||U===null||(d({kind:"profile",object:mn(I),target:I,profile:{...U,tools:Ug(U.tools,Z,ue)}}),w(null))},ae=async()=>{if(c!==null){v(!0),w(null);try{if(c.kind==="rule"){const Z=await t.patchConfig($E([...c.allowedTools]));a.setQueryData(["config"],Z)}else{const Z=await H_(t,c.target,c.profile);a.setQueryData(["named-agent-profiles","global"],ue=>ue===void 0?ue:{...ue,items:ue.items.map(Te=>Te.name===Z.name&&Te.source===Z.source&&Te.source_file===Z.source_file?Z:Te)}),await yn(a)}_()}catch(Z){w({tone:"error",text:oe(n,Z)})}finally{v(!1)}}},ne=()=>{d(null),w(null)},Ee=()=>{if(I===void 0)return;const Z=new URLSearchParams(window.location.search);Z.set(Ur,I.name),i(`/settings/agents?${Z.toString()}`)},ie=Z=>{const ue=()=>{l(Z),b(null),f("list"),w(null)};if(!L){ue();return}if(r?.confirmDiscard===void 0){d(null),ue();return}r.confirmDiscard(lx,()=>{d(null),ue()})},me=[{value:Ut,label:s("st.subagentTools.objectDefault"),hint:s("st.subagentTools.objectDefaultHint"),group:s("st.subagentTools.objectGroupDefault")},...j.map(Z=>({value:mn(Z),label:Z.name,hint:Z.source_file??Z.workspace_id??s("st.subagentTools.objectSourceBuiltin",{source:Z.source}),title:`${Z.name} · ${Z.source_file??s("st.subagentTools.objectSourceBuiltin",{source:Z.source})}`,group:s("st.subagentTools.objectGroupProfiles")}))],fe=k.isPending||o===Ut&&C.isPending,Ie=k.isError||o===Ut&&C.isError,te=u.trim()==="",ee=e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{"data-tool-list":!0,className:"space-y-0.5",children:F.map(({tool:Z,state:ue,changed:Te})=>e.jsx(eT,{tool:Z,state:ue,changed:Te,selected:Z.name===h,onSelect:()=>{b(Z.name),f("detail")},onRuleOptIn:B,onProfileTool:le,onProfileOptIn:re,onEdit:Ee,profileName:o===Ut?void 0:I?.name},Z.name))}),F.length===0&&!te?e.jsxs("div",{className:"space-y-2 px-2 py-1",children:[e.jsx("p",{"data-subagent-tools-empty":!0,className:"text-[12px] leading-snug text-ink-faint",children:s("st.subagentTools.noMatches",{query:u.trim()})}),e.jsx("button",{type:"button","data-subagent-tools-clear":!0,className:"h-7 rounded-md px-2 text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{p("")},children:s("st.subagentTools.clearSearch")})]}):null]}),K=(()=>{if(se!==void 0){const Z=$.find(Te=>Te.field==="tools"),ue=Z===void 0||Z.executor==="native"?void 0:Z.reason??s(Z.applicability==="mapped"?"st.profiles.fieldMapped":Z.applicability==="ignored"?"st.subagentTools.applicabilityIgnored":"st.subagentTools.applicabilityUnknown",{engine:Z.executor});return e.jsx(tT,{tool:se.tool,state:se.state,objectName:o===Ut?s("st.subagentTools.objectDefault"):I?.name??o,profileName:I===void 0?void 0:I.name,executor:I?.executor??"",executorNote:ue,onRuleOptIn:B,onProfileTool:le,onProfileOptIn:re,onEdit:Ee})}return o===Ut?e.jsx(sT,{allowedTools:T,pending:L&&c!==null&&c.kind==="rule",rowCount:O,mainOnlyCount:F.filter(Z=>Z.state.reason==="main-only").length,configurableCount:F.filter(Z=>Z.state.action==="opt-in").length,onReset:()=>{d({kind:"rule",allowedTools:[]}),w(null)}}):I===void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.subagentTools.profileMissing")}):e.jsx(nT,{profile:I,fields:$,editable:E,native:M,onEdit:Ee,onNewSession:()=>{i(Sb(I))},sessionBlocked:Cb(I)})})();return e.jsx(Me,{id:"st-card-subagent-tool-defaults",title:s("st.subagentTools.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:s("st.subagentTools.hint")}),e.jsx(VE,{}),e.jsxs("fieldset",{disabled:g,className:"min-w-0 space-y-3 disabled:opacity-60",children:[e.jsxs("div",{className:"space-y-1","data-subagent-tools-object-row":!0,children:[e.jsx(ge,{label:s("st.subagentTools.objectLabel"),labelId:"subagent-tools-object-label",children:e.jsx(Qe,{id:"subagent-tools-object",dataAttr:"data-subagent-tools-object",ariaLabel:s("st.subagentTools.objectLabel"),value:o,choices:me,emptyText:o===Ut?void 0:o,onChange:ie})}),e.jsx("button",{type:"button","data-subagent-tools-object-source":!0,title:s("st.subagentTools.objectDetailOpen"),"aria-label":s("st.subagentTools.objectDetailOpen"),onClick:()=>{b(null),f("detail")},className:"block max-w-[62ch] break-all text-left font-mono text-[11.5px] leading-[17px] text-ink-faint transition-colors hover:text-ink-soft focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink sm:truncate",children:ZE(s,I,o)})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("label",{className:"relative flex h-8 min-w-0 items-center",children:[e.jsx(de,{name:"search",size:14,className:"pointer-events-none absolute left-2.5 text-ink-faint"}),e.jsx("input",{type:"search","data-subagent-tools-search":!0,"aria-label":s("st.subagentTools.searchLabel"),placeholder:s("st.subagentTools.searchPlaceholder"),value:u,onChange:Z=>{p(Z.target.value)},className:"h-8 w-full min-w-0 rounded-md bg-ink/[0.04] pl-8 pr-20 text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint hover:bg-ink/[0.06] focus:bg-panel focus:shadow-[inset_0_0_0_1px_var(--color-hairline-strong)] [&::-webkit-search-cancel-button]:hidden"}),e.jsx("span",{"data-subagent-tools-count":!0,className:"pointer-events-none absolute right-2.5 text-[12px] tabular-nums text-ink-faint",children:u.trim()===""?s("st.list.count",{total:O}):s("st.list.countOf",{shown:Y,total:O})})]})}),fe?e.jsx("p",{role:"status",className:"text-[12.5px] text-ink-faint",children:s("st.subagentTools.catalogLoading")}):null,Ie||!fe&&O===0?e.jsxs("div",{className:"space-y-2",children:[k.isError?e.jsx(De,{error:k.error}):null,!Ie&&O===0?e.jsxs("p",{"data-subagent-tools-empty":!0,className:"max-w-[62ch] text-[12px] leading-snug text-ink-soft",children:[s("st.subagentTools.catalogEmptyTitle")," ",s("st.subagentTools.catalogEmptyBody")]}):null,o===Ut&&C.isError?e.jsx(De,{error:C.error}):null,e.jsx("button",{type:"button",className:Q,"data-subagent-tools-retry":!0,onClick:()=>{k.refetch(),o===Ut&&C.refetch()},children:s("st.subagentTools.catalogRetry")})]}):null,fe||Ie||O===0?null:e.jsx(vo,{narrowPane:m,columns:"md:grid-cols-[minmax(0,9fr)_minmax(0,7fr)]",list:ee,detail:e.jsxs("div",{className:"space-y-4",children:[e.jsx("button",{type:"button","data-subagent-tools-back":!0,className:`${Q} md:hidden`,onClick:()=>{f("list")},children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"arrowLeft",size:12}),s("st.subagentTools.backToList")]})}),K]})}),S.isError?e.jsx(De,{error:S.error}):null]}),c!==null?e.jsx(lt,{id:lx,persistent:!0,dirty:L,saving:g,saved:N,saveLabel:s(c.kind==="rule"?"st.subagentTools.saveRule":"st.subagentTools.saveProfile"),onSave:()=>{ae()},onDiscard:ne,extra:V>0?e.jsxs("span",{"data-subagent-tools-pending":!0,className:"flex items-center gap-1.5 text-[12px] text-ink-faint",children:[e.jsx("span",{"aria-hidden":!0,className:"inline-block h-1.5 w-1.5 rounded-full bg-accent"}),s("st.subagentTools.pendingChanges",{count:V})]}):void 0}):null,e.jsx(pe,{feedback:y})]})})}function mn(t){return`${t.name}
|
|
13
|
+
${t.source}
|
|
14
|
+
${t.source_file??""}
|
|
15
|
+
${t.workspace_id??""}`}function JE(t){const s=new Set;return t.filter(a=>{const i=`${a.name}
|
|
16
|
+
${a.source}
|
|
17
|
+
${a.source_file??""}
|
|
18
|
+
${a.workspace_id??""}`;return s.has(i)?!1:(s.add(i),!0)}).toSorted((a,i)=>Number(a.main===!0||a.disabled)-Number(i.main===!0||i.disabled))}function ZE(t,s,n){if(n===Ut||s===void 0)return t("st.subagentTools.objectDefaultHint");const a=s.workspace_ids?.[0]??s.workspace_id,i=kb(s.source),r=i===void 0?s.source:t(i),o=[s.source_file===void 0?t("st.subagentTools.objectSourceBuiltin",{source:r}):t("st.subagentTools.objectSource",{source:r,file:s.source_file})];return a!==void 0&&o.push(t("st.subagentTools.objectWorkspace",{id:a})),s.executor!==void 0&&s.executor!=="native"&&o.push(t("st.subagentTools.objectExecutor",{executor:s.executor})),o.join(" · ")}function Hg(t,s){return s.status==="allowed"?t("st.subagentTools.statusAllowed"):s.status==="blocked"?t("st.subagentTools.statusBlocked"):s.status==="inherit"?t("st.subagentTools.statusInherit"):t("st.subagentTools.statusFixed")}function cx(t,s){switch(s.reason){case"default-allowed":return t("st.subagentTools.reasonDefaultAllowed");case"server-opt-in":return t("st.subagentTools.reasonServerOptIn");case"opt-in-off":return t("st.subagentTools.reasonOptInOff");case"profile-explicit":return t("st.subagentTools.reasonProfileExplicit");case"profile-pattern":return t("st.subagentTools.reasonProfilePattern");case"profile-denied":return t("st.subagentTools.reasonProfileDenied");case"profile-allowlist":return t("st.subagentTools.reasonProfileAllowlist");case"inherit":return t("st.subagentTools.reasonInheritBase",{base:t(s.inheritAllows===!1?"st.subagentTools.statusBlocked":"st.subagentTools.statusAllowed")});case"main-only":return t("st.subagentTools.reasonMainOnly");case"executor":return t("st.subagentTools.reasonExecutor")}}function XE(t,s,n,a){const i=t(n.inheritAllows===!1?"st.subagentTools.statusBlocked":"st.subagentTools.statusAllowed");switch(n.reason){case"default-allowed":return t("st.subagentTools.detailDefaultAllowed",{name:s});case"server-opt-in":return t("st.subagentTools.detailServerOptIn",{name:s});case"opt-in-off":return t("st.subagentTools.detailOptInOff",{name:s});case"profile-explicit":return t("st.subagentTools.detailProfileExplicit",{name:s});case"profile-pattern":return t("st.subagentTools.detailProfilePattern",{name:s});case"profile-denied":return t("st.subagentTools.detailProfileDenied",{name:s});case"profile-allowlist":return t("st.subagentTools.detailProfileAllowlist",{name:s});case"inherit":return t("st.subagentTools.detailInherit",{name:s,base:i});case"main-only":return t("st.subagentTools.detailMainOnly",{name:s});case"executor":return t("st.subagentTools.detailExecutor",{name:s,executor:a})}}function eT({tool:t,state:s,changed:n,selected:a,onSelect:i,onRuleOptIn:r,onProfileTool:o,onProfileOptIn:l,onEdit:c,profileName:d}){const{t:u}=D(),p=WE(t),h=d===void 0,b=u(h?"st.subagentTools.actionOptInAria":"st.subagentTools.actionProfileOptInAria",{name:t.name});return e.jsxs("li",{"data-tool-row":t.name,className:"flex items-start gap-1.5",children:[e.jsxs("button",{type:"button","aria-current":a?"true":void 0,onClick:i,title:cx(u,s),className:"row-interactive min-w-0 flex-1 px-2 py-1.5 text-left",children:[e.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-[12.5px] text-ink",title:t.name,children:_b(t.name)}),t.source==="builtin"?null:e.jsx("span",{className:"shrink-0 text-[11px] text-ink-faint",children:u(`st.subagentTools.sourceTag.${t.source}`)}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5 text-[11.5px] text-ink-soft",children:[n?e.jsx("span",{role:"img","aria-label":u("st.subagentTools.changedMark"),title:u("st.subagentTools.changedMark"),"data-tool-changed":t.name,className:"inline-block h-1.5 w-1.5 rounded-full bg-accent"}):null,Hg(u,s)]})]}),e.jsx("span",{className:"mt-0.5 block line-clamp-2 text-[11.5px] leading-[16px] text-ink-faint",children:p===""?cx(u,s):p})]}),s.action==="opt-in"?e.jsx("input",{type:"checkbox","data-server-allow":h?t.name:void 0,"data-profile-opt-in":h?void 0:t.name,checked:s.status==="allowed","aria-label":b,className:"mt-2 shrink-0",onChange:m=>{const f=m.target.checked;h?r(t.name,f):l(t.name,f)}}):null,s.action==="allow"&&d!==void 0?e.jsx("button",{type:"button","data-tool-allow":t.name,className:"h-7 shrink-0 self-center rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{o(t.name,!0)},children:u("st.subagentTools.actionAllow")}):null,s.action==="deny"&&d!==void 0?e.jsx("button",{type:"button","data-tool-deny":t.name,className:"h-7 shrink-0 self-center rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{o(t.name,!1)},children:u("st.subagentTools.actionDeny")}):null,s.action==="editor"&&d!==void 0?e.jsx("button",{type:"button","data-tool-editor":t.name,title:u("st.subagentTools.actionEditorAria",{name:t.name}),"aria-label":u("st.subagentTools.actionEditorAria",{name:t.name}),className:"h-7 shrink-0 self-center rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:c,children:u("st.subagentTools.actionEditor")}):null]})}function tT({tool:t,state:s,objectName:n,profileName:a,executor:i,executorNote:r,onRuleOptIn:o,onProfileTool:l,onProfileOptIn:c,onEdit:d}){const{t:u}=D(),p=t.description.trim(),h=a===void 0;return e.jsxs("div",{className:"space-y-3","data-tool-detail":t.name,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"break-all font-mono text-[13px] text-ink",children:t.name}),e.jsxs("p",{className:"mt-0.5 text-[11.5px] text-ink-faint",children:[u(`cap.tools.${t.source}`),t.mcp_server_id===void 0?"":` · ${u("st.subagentTools.toolServer",{id:t.mcp_server_id})}`]})]}),p===""?null:e.jsx("p",{className:"max-w-[72ch] whitespace-pre-line text-[12.5px] leading-5 text-ink-soft",children:p}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{"data-tool-state":s.reason,className:"text-[12.5px] text-ink",children:[n," · ",Hg(u,s)]}),e.jsx("p",{className:"max-w-[72ch] text-[12px] leading-[18px] text-ink-soft",children:XE(u,t.name,s,i)}),r===void 0?null:e.jsx("p",{"data-tool-executor-note":!0,className:"max-w-[72ch] text-[11.5px] leading-[18px] text-ink-faint",children:r})]}),s.action==="opt-in"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-[12.5px] text-ink",children:[e.jsx("input",{type:"checkbox","data-tool-detail-opt-in":t.name,checked:s.status==="allowed","aria-label":u(h?"st.subagentTools.actionOptInAria":"st.subagentTools.actionProfileOptInAria",{name:t.name}),onChange:b=>{const m=b.target.checked;h?o(t.name,m):c(t.name,m)}}),e.jsx("span",{children:u(h?"st.subagentTools.actionOptInAria":"st.subagentTools.actionProfileOptInAria",{name:t.name})})]}),h?null:e.jsx(he,{children:u("st.subagentTools.profileOptInScopeHint")})]}):null,s.action==="allow"&&a!==void 0?e.jsx("button",{type:"button",className:Q,"data-tool-detail-allow":t.name,onClick:()=>{l(t.name,!0)},children:u("st.subagentTools.detailAllow",{name:t.name})}):null,s.action==="deny"&&a!==void 0?e.jsx("button",{type:"button",className:Q,"data-tool-detail-deny":t.name,onClick:()=>{l(t.name,!1)},children:u("st.subagentTools.detailDeny",{name:t.name})}):null,s.action==="editor"&&a!==void 0?e.jsx("button",{type:"button",className:Q,"data-tool-detail-editor":t.name,onClick:d,children:u("st.subagentTools.editToolLists")}):null]})}function sT({allowedTools:t,pending:s,rowCount:n,mainOnlyCount:a,configurableCount:i,onReset:r}){const{t:o}=D();return e.jsxs("div",{className:"space-y-3","data-subagent-tools-rule-detail":!0,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[13px] text-ink",children:o("st.subagentTools.objectDefault")}),e.jsx("p",{className:"mt-0.5 max-w-[72ch] text-[12px] leading-[18px] text-ink-faint",children:o("st.subagentTools.objectDefaultDescription")})]}),e.jsx("p",{className:"text-[12px] text-ink-soft",children:o("st.subagentTools.summary",{configurable:i,mainOnly:a,total:n})}),s?e.jsx(he,{children:o("st.subagentTools.rulePending")}):null,e.jsxs(et,{summary:o("st.subagentTools.ruleConfigKeyLabel"),children:[e.jsx("p",{className:"font-mono text-[11px] leading-5 text-ink-soft",children:"[subagent].allowed_tools"}),e.jsx("p",{className:"font-mono text-[11px] leading-5 text-ink",children:t.length===0?o("st.subagentTools.ruleValuesEmpty"):t.join(", ")})]}),t.length===0?null:e.jsx("button",{type:"button",className:Q,"data-subagent-tools-reset":!0,onClick:r,children:o("st.subagentTools.reset")}),e.jsx(he,{children:o("st.subagentTools.detailRuleNote")})]})}function nT({profile:t,fields:s,editable:n,native:a,onEdit:i,onNewSession:r,sessionBlocked:o}){const{t:l}=D(),c=t.description??t.when_to_use;return e.jsxs("div",{className:"space-y-3","data-subagent-tools-profile-detail":t.name,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[13px] text-ink",children:t.name}),c===void 0||c===""?null:e.jsx("p",{className:"mt-0.5 max-w-[72ch] text-[12px] leading-[18px] text-ink-faint",children:c})]}),s.map(d=>e.jsxs(et,{summary:l(d.field==="tools"?"st.subagentTools.listsTools":"st.subagentTools.listsDisallowedTools"),children:[e.jsx("p",{className:"font-mono text-[11px] leading-5 text-ink",children:d.values===null?l("st.subagentTools.valuesUnset"):d.values.length===0?l(d.field==="tools"?"st.subagentTools.valuesEmptyTools":"st.subagentTools.valuesEmptyDeny"):d.values.join(", ")}),d.applicability==="ignored"||d.applicability==="unknown"?e.jsx("p",{className:"text-[11px] leading-5 text-ink-faint",children:d.reason??l(d.applicability==="ignored"?"st.subagentTools.applicabilityIgnored":"st.subagentTools.applicabilityUnknown",{engine:d.executor})}):null]},d.field)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?e.jsx("button",{type:"button",className:Q,"data-subagent-tools-edit-lists":!0,onClick:i,children:l("st.subagentTools.editToolLists")}):null,e.jsx("button",{type:"button",className:Q,"data-subagent-tools-new-session":!0,disabled:o,onClick:r,children:l("st.subagentTools.newSession",{name:t.name})})]}),n?null:e.jsx(he,{children:l("st.subagentTools.unwritableProfile")}),a?null:e.jsx(he,{children:l("st.subagentTools.detailExecutorFieldOff",{executor:t.executor??""})}),e.jsx(he,{children:l("st.subagentTools.sessionCapabilityHint")})]})}const dx={denyModels:""};function aT(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(dx),[o,l]=x.useState(dx),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),f=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:6e4}),g=x.useMemo(()=>i.denyModels.split(/\r?\n/).map(w=>w.trim()).filter(Boolean),[i.denyModels]);x.useEffect(()=>{if(m.data!==void 0){const w=Yp(m.data);r(w),l(w)}},[m.data]);const v=i.denyModels!==o.denyModels,y=async()=>{d(!0),p(null);try{const w=await t.patchConfig(dN(i));a.setQueryData(["config"],w),await yn(a);const N=Yp(w);r(N),l(N),b()}catch(w){p({tone:"error",text:oe(n,w)})}finally{d(!1)}};return e.jsx(Me,{id:"st-card-subagents",title:s("st.subagents.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{children:s("st.subagents.hint")}),e.jsx("fieldset",{disabled:m.isLoading||c,className:"space-y-4 disabled:opacity-60",children:e.jsxs("div",{children:[e.jsx("span",{className:"block text-[11px] font-medium text-ink-soft mb-1.5",children:s("st.subagents.denyModels")}),e.jsx(Rg,{id:"subagent-deny-models",values:g,models:f.data?.items??[],disabled:m.isLoading||c,addLabel:s("st.profiles.addModel"),onChange:w=>{r(N=>({...N,denyModels:w.join(`
|
|
19
|
+
`)}))}})]})}),e.jsx(lt,{saved:h,id:"subagent-model-governance",dirty:v,saving:c||m.isLoading,saveLabel:s("st.subagents.save"),onSave:()=>void y(),onDiscard:()=>{r(o),p(null)}}),m.isError?e.jsx(De,{error:m.error}):null,e.jsx(pe,{feedback:u})]})})}const iT=new Set(["#st-card-subagents","#st-card-prompt-config"]);function rT(){return e.jsxs("div",{className:"space-y-4",children:[e.jsx(z2,{}),e.jsx(U2,{}),e.jsx(E2,{}),e.jsx(Q2,{}),e.jsx(YE,{})]})}function ux(){const{t}=D(),{hash:s,search:n}=Bt(),a=new URLSearchParams(n),i=a.has(Ur),r=a.get("tab"),o=iT.has(s),[l,c]=x.useState(o),d=x.useRef(null);return x.useEffect(()=>{o&&c(!0)},[o]),x.useEffect(()=>{i||r!=="dispatch"||s!==""||d.current!==null&&typeof d.current.scrollIntoView=="function"&&d.current.scrollIntoView({behavior:zf()?"auto":"smooth",block:"start"})},[i,r,s]),e.jsxs("div",{className:"space-y-6","data-agents-page":!0,children:[e.jsx(PE,{}),i?null:e.jsxs(e.Fragment,{children:[e.jsxs("section",{ref:d,"data-agents-dispatch":!0,className:"space-y-3",children:[e.jsx("h2",{className:"text-[13px] font-semibold tracking-tight text-ink",children:t("st.agents.dispatch.title")}),e.jsx(rT,{})]}),e.jsxs("details",{className:"group","data-agents-advanced":!0,open:l,onToggle:u=>{c(u.currentTarget.open)},children:[e.jsxs("summary",{className:"flex min-h-8 w-fit cursor-pointer list-none items-center gap-1.5 rounded-md px-1 text-[12.5px] font-medium text-ink-soft hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11 [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"text-ink-soft transition-transform group-open:rotate-90"}),t("st.agents.advanced.fold")]}),l?e.jsxs("div",{className:"space-y-4 pt-3",children:[e.jsx(aT,{}),e.jsx(K2,{})]}):null]})]})]})}const px=new WeakMap;function Po(t,s,n){const a=Symbol();let i=px.get(s);i===void 0&&(i={latest:a,tail:Promise.resolve()},px.set(s,i)),i.latest=a;const r=i,o=()=>r.latest===a,l=async d=>{o()&&(await s.cancelQueries({queryKey:["config"]}),o()&&(s.setQueryData(["config"],d),Mt({defaultModel:d.default_model})))},c=r.tail.then(async()=>{if(!o())return!1;try{await t.setDefaultModel(n.id);const d=await t.patchConfig({default_model:n.id,default_provider:n.provider_id});return await l(d),await s.invalidateQueries({queryKey:["config"]}),await s.invalidateQueries({queryKey:["models"]}),o()}catch(d){if(!o())return!1;try{await l(await t.getConfig())}catch{o()&&await s.invalidateQueries({queryKey:["config"]})}if(o()&&await s.invalidateQueries({queryKey:["models"]}),!o())return!1;throw d}});return r.tail=c.then(()=>{},()=>{}),{completed:c,isCurrent:o}}function zg(t){const{client:s,meta:n}=be(),a=Pa(s,n);return e.jsx(oT,{...t},`${yo(s)}|${a?.identity.serverId??"unidentified"}|${a?.identity.homeId??"unidentified"}`)}function oT({config:t,domain:s,keyPath:n=[],label:a}){const{client:i,meta:r}=be(),{t:o}=D(),l=Oe(),c=Pa(i,r),d=c?.identity??null,u=d?.homeId??"unidentified",p=u!=="main",h=d?.serverId,b=[...Vd.detail(u),h??"unidentified"],[m,f]=x.useState(!1),g=pC(s,n),v=je({queryKey:b,queryFn:async({signal:C})=>{if(d===null)throw new Error("Space server is unidentified");const S=await Yd(i,d);return C.throwIfAborted(),S},enabled:p&&d!==null,staleTime:1e4,retry:!1});if(!p)return null;const y=zC(QC(t),s,n.join("."));if(y===void 0||y==="default"||y==="memory")return null;if(y==="env")return e.jsx("span",{"data-origin":"env",className:"text-[11.5px] text-ink-faint",children:o("st.origin.env")});if(y==="base")return e.jsx("span",{"data-origin":"base",className:"text-[11.5px] text-ink-faint",children:o("st.origin.inherited")});const w=e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[4px] bg-ink/[0.05] px-1.5 text-[11px] leading-4 font-medium text-ink-soft",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-ink-faint"}),o("st.origin.local")]});if((v.data===void 0?void 0:lg(v.data,g))===void 0){const C=v.isError||d===null;return e.jsxs("span",{"data-origin":"home","data-origin-unavailable":g,className:"inline-flex flex-wrap items-center gap-1.5",children:[w,e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:o(C?"st.spaces.origin.unknown":v.data===void 0?"st.spaces.origin.reading":"st.spaces.origin.notListed")}),v.isError?e.jsx("button",{type:"button",className:"rounded px-1 text-[11.5px] text-ink-soft underline decoration-hairline-strong underline-offset-2 transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",onClick:()=>{v.refetch()},children:o("st.spaces.origin.retry")}):null]})}const _=C=>{l.setQueryData(b,C.detail),l.invalidateQueries({queryKey:b}),l.invalidateQueries({queryKey:["config"]})};return e.jsxs("span",{"data-origin":"home",className:"inline-flex flex-wrap items-center gap-1.5",children:[w,e.jsx("button",{type:"button","data-origin-restore":g,disabled:m,"aria-label":o("st.origin.restoreAria",{name:a}),onClick:()=>{f(!0)},className:"rounded px-1 text-[11.5px] text-ink-soft underline decoration-hairline-strong underline-offset-2 transition-colors hover:text-ink disabled:opacity-50",children:o("st.origin.restore")}),m&&c!==null?e.jsx(iu,{target:c,spaceName:a,canPush:!1,request:{action:"follow",items:[g]},onClose:()=>{f(!1)},onApplied:_}):null]})}function Uc(t,s){if(t.plugin!==void 0)return t.plugin.readiness==="auth_required"||t.plugin.readiness==="degraded";if(ha(t)){const a=t.api_key_env!==void 0&&!t.has_api_key,i=(t.default_model??"")==="";return t.status==="error"||a||i}const n=s===void 0&&!uo(t.base_url)&&!t.has_api_key&&t.api_key_env===void 0;return t.status==="error"||t.status==="unconfigured"||n||s!==void 0&&s.signed_in&&s.connection_state==="reconnect_required"}function lT({tab:t}={}){const{client:s}=be(),{t:n,tp:a,locale:i}=D(),r=Oe(),[o,l]=x.useState(!1),[c,d]=x.useState(null),[u,p]=Je(),[h,b]=x.useState(!1),m=je({queryKey:["config"],queryFn:()=>s.getConfig(),staleTime:6e4}),f=je({queryKey:["models"],queryFn:()=>s.listModels(),staleTime:1e4}),g=je({queryKey:["providers"],queryFn:()=>s.listProviders(),staleTime:1e4,enabled:typeof s.listProviders=="function"}),v=je({queryKey:Nc,queryFn:()=>s.listOAuthMethods(),staleTime:1e4,enabled:typeof s.listOAuthMethods=="function"}),y=g.isLoading&&typeof s.listProviders=="function";x.useEffect(()=>{if(!y){b(!1);return}const E=setTimeout(()=>{b(!0)},M1);return()=>{clearTimeout(E)}},[y]);const w=f.data?.items??[],N=m.data,_=N?.default_model??"",C=w.find(E=>E.id===_),S=v.data??[],k=x.useMemo(()=>(g.data?.items??[]).filter(E=>!ha(E)),[g.data]),j=x.useMemo(()=>k.filter(E=>Uc(E,S.find(M=>M.provider===E.id))).length,[k,S]),T=async E=>{const M=w.find(H=>H.id===E);if(M===void 0)return;l(!0),d(null);const z=Po(s,r,M);try{await z.completed&&p()}catch(H){z.isCurrent()&&d({tone:"error",text:oe(i,H)})}finally{l(!1)}},A=g.isSuccess,P=A&&k.length===0&&w.length===0,R=C!==void 0?C.display_name??C.id:_!==""?_:n("common.defaultUnknown"),L=n("st.ai.status.default",{model:R}),I=i.startsWith("zh")?",":", ",$=A&&k.length>0?`${a("st.ai.status.count",k.length)}${j>0?`${I}${a("st.ai.status.attention",j)}`:""}`:null;return e.jsxs("div",{"data-default-model-bar":!0,"data-default-model-line":!0,"data-ai-status-card":!0,className:"border-b border-hairline pb-3",children:[P?e.jsx("p",{"data-ai-status-empty":!0,className:"text-[13px] leading-5 text-ink-soft",children:n("st.ai.status.empty")}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1.5",children:[e.jsx("p",{className:"min-w-0 text-[13.5px] font-medium text-ink","data-default-model-name":!0,children:L}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(jt,{show:u}),e.jsx(nn,{id:"st-default-model",models:w,value:_,allowCustomValue:!1,missing:!1,disabled:o||w.length===0,onChange:E=>{T(E)},ariaLabel:`${n("st.decision.change")} · ${L}`,searchPlaceholder:n("st.models.searchPlaceholder"),emptyText:n("st.models.noDefault"),align:"end",hideChevron:!0,triggerLabel:n("st.decision.change"),buttonClassName:`inline-flex min-h-7 items-center px-1 pointer-coarse:min-h-11 ${Ot}`})]})]}),y&&h?e.jsx("p",{role:"status","data-ai-status-loading":!0,className:"text-[12.5px] text-ink-faint",children:n("st.ai.status.loading")}):$!==null?e.jsx("p",{"data-ai-status-connections":!0,className:`text-[12.5px] ${j>0?"text-amber-ink":"text-ink-soft"}`,children:$}):null]}),e.jsx("div",{className:"pt-1 empty:hidden","data-default-origin":"new-session",children:e.jsx(zg,{config:N,domain:"default_model",keyPath:[],label:n("st.defaults.row.newSession")})}),e.jsx(pe,{feedback:c})]})}function ln({values:t,knownOptions:s,onChange:n,ariaLabel:a,addPlaceholder:i,removeLabel:r,disabled:o=!1}){const[l,c]=x.useState(""),d=h=>{n(t.includes(h)?t.filter(b=>b!==h):Ap([...t,h]))},u=()=>{const h=Ap([...t,l]);c(""),h.length!==t.length&&n(h)},p=t.filter(h=>!s.includes(h));return e.jsxs("div",{role:"group","aria-label":a,className:"flex flex-wrap items-center gap-1.5",children:[s.map(h=>{const b=t.includes(h);return e.jsxs("button",{type:"button",disabled:o,"aria-pressed":b,onClick:()=>{d(h)},className:`inline-flex h-6 items-center gap-1 rounded-full px-3 text-[12px] transition-colors duration-[var(--kiki-motion-quick)] disabled:cursor-not-allowed disabled:opacity-50 ${b?"bg-paper pl-2 font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"border border-dashed border-hairline-strong text-ink-soft hover:bg-ink/[0.04] hover:text-ink"}`,children:[b?e.jsx(de,{name:"check",size:12,className:"text-ink-soft"}):null,h]},h)}),p.map(h=>e.jsxs("span",{className:"inline-flex h-6 items-center gap-1 rounded-full bg-paper pr-1 pl-3 text-[12px] font-medium text-ink shadow-[var(--kiki-sheet-shadow)]",children:[h,e.jsx("button",{type:"button",disabled:o,"aria-label":r(h),onClick:()=>{d(h)},className:"flex h-4 w-4 items-center justify-center rounded text-ink-faint transition-colors hover:text-ink disabled:opacity-50",children:e.jsx(de,{name:"close",size:12})})]},h)),e.jsx("input",{type:"text",value:l,disabled:o,placeholder:i,"aria-label":a,className:"w-32 min-w-24 max-w-full flex-1 basis-32 sm:basis-40 rounded-full border border-dashed border-hairline bg-paper px-3 py-0.5 text-[11px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:opacity-50",onChange:h=>{c(h.target.value)},onKeyDown:h=>{rt(h)||(h.key==="Enter"||h.key===",")&&(h.preventDefault(),u())},onBlur:u})]})}const cT=new Set(["kimi-code"]),dT=.8,uT={minute:"st.quota.window.minute",hour:"st.quota.window.hour",day:"st.quota.window.day",week:"st.quota.window.week"};function pT({method:t}){return cT.has(t.id)?e.jsx(mT,{method:t}):e.jsx(hT,{method:t})}function Qg({method:t}){return e.jsxs("p",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"text-[12.5px] font-medium text-ink",children:t.label}),t.account.state==="known"?e.jsx("span",{className:"truncate font-mono text-[11px] text-ink-faint",title:t.account.id,children:At(t.account.id)}):null]})}function Gg(t,s){if(t===void 0)return null;const n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleString(s==="zh"?"zh-CN":"en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function mT({method:t}){const{client:s}=be(),{t:n,locale:a}=D(),i=je({queryKey:["oauth-usage",t.provider],queryFn:()=>s.getManagedUsage(t.provider),staleTime:6e4}),r=i.data,o=r?.kind==="ok"?[...r.summary!==null?[r.summary]:[],...r.limits]:[];return e.jsxs("section",{"data-quota-account":t.id,className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Qg,{method:t})}),e.jsx("button",{type:"button",className:Q,disabled:i.isFetching,onClick:()=>void i.refetch(),children:i.isFetching?n("st.quota.refreshing"):n("st.quota.refresh")})]}),i.isLoading?e.jsx(he,{children:n("st.quota.loading")}):null,i.isError?e.jsx(pe,{feedback:{tone:"error",text:n("st.quota.failed",{detail:oe(a,i.error)})}}):null,r?.kind==="error"?e.jsx(pe,{feedback:{tone:"error",text:n("st.quota.failed",{detail:r.message})}}):null,r?.kind==="ok"&&o.length===0?e.jsx(he,{children:n("st.quota.none")}):null,o.length>0?e.jsx("ul",{className:"space-y-3",children:o.map((l,c)=>e.jsx(xT,{row:l,first:c===0&&r?.kind==="ok"&&r.summary!==null},`${l.name??"row"}-${c}`))}):null,r?.kind==="ok"&&r.extra_usage!==null?e.jsxs("p",{"data-quota-balance":!0,className:"text-[12px] text-ink-soft",children:[n("st.quota.balance",{amount:Al(r.extra_usage.balance_cents,r.extra_usage.currency,a)}),r.extra_usage.monthly_charge_limit_enabled?` · ${n("st.quota.monthly",{used:Al(r.extra_usage.monthly_used_cents,r.extra_usage.currency,a),limit:Al(r.extra_usage.monthly_charge_limit_cents,r.extra_usage.currency,a)})}`:""]}):null,e.jsxs("p",{className:"text-[11px] leading-4 text-ink-faint",children:[n("st.quota.intro")," ",e.jsx(_t,{to:"/usage?panel=history",className:"text-selected-ink underline-offset-2 hover:underline",children:n("st.quota.usageLink")})]})]})}function Al(t,s,n){try{return new Intl.NumberFormat(n==="zh"?"zh-CN":"en-US",{style:"currency",currency:s}).format(t/100)}catch{return`${(t/100).toFixed(2)} ${s}`}}function xT({row:t,first:s}){const{t:n,locale:a}=D(),i=t.limit>0?Math.min(1,Math.max(0,t.used/t.limit)):null,r=i!==null&&i>=dT,o=i!==null&&i>=1,l=t.name??n(s?"st.quota.summary":"st.quota.limit"),c=t.window===void 0?null:n(uT[t.window.unit],{n:t.window.duration}),d=Gg(t.reset_at,a),u=i===null?null:Math.round(i*100),p=u===null?null:Math.max(0,100-u);return e.jsxs("li",{"data-quota-row":!0,"data-quota-near":r?"true":void 0,className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-[12px]",children:[e.jsx("span",{className:"font-medium text-ink",children:l}),c!==null?e.jsx("span",{className:"font-mono text-[10.5px] text-ink-faint",children:c}):null,e.jsxs("span",{className:"ml-auto tabular-nums text-ink-soft",children:[t.limit>0?n("st.quota.usedOf",{used:t.used.toLocaleString(),limit:t.limit.toLocaleString()}):n("st.quota.usedOnly",{used:t.used.toLocaleString()}),p!==null?e.jsx("span",{className:`ml-2 font-medium ${o?"text-danger":r?"text-amber-ink":"text-ink"}`,children:n("st.quota.remainingPercent",{n:p})}):null]})]}),p!==null?e.jsx("div",{role:"progressbar","aria-label":l,"aria-valuemin":0,"aria-valuemax":t.limit,"aria-valuenow":Math.max(0,t.limit-Math.min(t.used,t.limit)),className:"h-1.5 overflow-hidden rounded-full bg-ink/[0.07]",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-200 ${o?"bg-danger":r?"bg-amber-rule":"bg-ink/60"}`,style:{width:`${p}%`}})}):null,d!==null?e.jsx("p",{className:"text-[11px] text-ink-faint",children:n("st.quota.resetsAt",{when:d})}):null]})}function hT({method:t}){const{t:s,locale:n}=D(),a=t.quota,i=a.state==="known"?Gg(a.reset_at,n):null;return e.jsxs("section",{"data-quota-account":t.id,className:"space-y-1",children:[e.jsx(Qg,{method:t}),a.state==="known"?e.jsxs("p",{className:"text-[12px] text-ink-soft",children:[e.jsx("span",{children:a.label}),e.jsx("span",{className:"ml-2 font-medium tabular-nums text-ink",children:a.unit==="percent"?s("st.quota.remainingPercent",{n:a.remaining}):s("st.quota.remainingCount",{n:a.remaining.toLocaleString()})}),i!==null?e.jsx("span",{className:"ml-2 text-ink-faint",children:s("st.quota.resetsAt",{when:i})}):null]}):e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.quota.unknown")})]})}function fT({method:t,onChanged:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=Eb(s),[o,l]=x.useState(!1),[c,d]=x.useState(null),u=r.active===t.provider,p=u?r.snapshot:null,h=u&&r.showing,b=$d(t,h&&p!==null?p.status:void 0),m=h?null:uN(b),f=r.busy===t.provider,g=t.auth_source?.kind==="local_original",v=async()=>{l(!0),d(null);try{await n.logoutOAuth({provider:t.id}),await s()}catch(y){d({tone:"error",text:oe(i,y)})}finally{l(!1)}};return e.jsxs("div",{"data-connection-account-panel":t.id,className:"space-y-3 rounded-lg border border-hairline bg-panel/50 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] text-ink-faint",children:a("st.account.connectionLabel")}),b.state==="connected"&&g?null:b.state==="connected"?e.jsx("button",{type:"button","data-connection-sign-out":!0,className:Q,disabled:o,onClick:()=>{v()},children:a(o?"st.auth.working":"st.connections.signOut")}):b.state==="waiting"?e.jsx("span",{className:"text-[12px] text-ink-faint",children:a("st.account.inProgress")}):e.jsx("button",{type:"button","data-connection-sign-in":!0,className:Q,disabled:f,onClick:()=>{r.start(t)},children:f?a("st.auth.working"):b.state==="signIn"?a("st.account.signIn"):a("st.account.signInAgain")})]}),m!==null?e.jsx("p",{"data-connection-account-detail":b.state,className:"text-[12px] leading-4 text-ink-soft",children:a(m)}):null,b.state==="connected"?e.jsx(pT,{method:t}):null,pN(t)?e.jsx(mN,{method:t,onChanged:s}):null,h&&p!==null?e.jsx(xN,{snapshot:p,label:t.label,cancelling:r.cancelling,onCancel:()=>{r.cancel()},onDismiss:()=>{r.dismiss(p.flow_id)}}):null,r.feedback!==null&&r.feedback.provider===t.provider?e.jsx(pe,{feedback:r.feedback.value}):null,e.jsx(pe,{feedback:c})]})}function bT(t,s,n){const a=qj(t);return a===void 0||s.some(i=>i.id===a)?[]:[{value:t,label:n("st.requestIdentity.option.custom",{label:a})}]}function Ao({value:t,onChange:s,label:n,inheritLabel:a,hint:i,issue:r=null,customProfiles:o=[],overridesOnly:l=!1}){const{t:c}=D(),d=t.requestIdentityChoice==="inherit",u=!d||l,p=b=>{s({requestIdentityChoice:b,requestIdentityOverridesJson:b==="inherit"?"":t.requestIdentityOverridesJson})},h=b=>{const m=d?b.trim()===""?"inherit":"custom_overrides":t.requestIdentityChoice;s({requestIdentityChoice:m,requestIdentityOverridesJson:b})};return e.jsxs("div",{className:"space-y-3",children:[l?null:e.jsxs("div",{children:[e.jsxs("div",{className:"space-y-1 text-[11px] font-medium text-ink-soft",children:[e.jsx("span",{className:"block",children:n}),e.jsx(Qe,{variant:"form",dataAttr:"data-request-identity-choice",ariaLabel:n,value:t.requestIdentityChoice,onChange:p,choices:[...Dj.map(b=>({value:b,label:b==="inherit"?a:c(`st.requestIdentity.option.${b}`)})),...o.map(b=>({value:Fj(b.id),label:c("st.requestIdentity.option.custom",{label:b.label})})),...bT(t.requestIdentityChoice,o,c)]})]}),i===void 0?null:e.jsx(he,{children:i})]}),u?e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[11px] font-medium text-ink-soft",children:[c("st.requestIdentity.overrides"),e.jsx("textarea",{className:`${Ce} mt-1 min-h-24 font-mono ${r!==null?"border-danger":""}`,"aria-invalid":r!==null,"data-request-identity-overrides":!0,spellCheck:!1,value:t.requestIdentityOverridesJson,onChange:b=>{h(b.target.value)},placeholder:c("st.requestIdentity.overridesPlaceholder")})]}),r!==null?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r}):null,e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-start justify-between gap-2",children:[e.jsx(he,{children:c(d?"st.requestIdentity.overridesStartHint":t.requestIdentityChoice==="custom_overrides"?"st.requestIdentity.overridesRequiredHint":"st.requestIdentity.overridesOptionalHint")}),d?null:e.jsx("button",{type:"button",className:Q,onClick:()=>{p("inherit")},children:c("st.requestIdentity.clearLayer")})]})]}):null]})}const ns=["request-identity"];function uu(){const{client:t}=be(),s=je({queryKey:ns,queryFn:()=>t.requestIdentity.get(),staleTime:3e4});return x.useMemo(()=>(s.data?.profiles??[]).filter(n=>!n.builtin).map(({id:n,label:a})=>({id:n,label:a})),[s.data])}const gT=["openai","anthropic","gemini","deepseek","openrouter","ollama"],vT={openai:"st.presets.protocolHint.openai",openai_responses:"st.presets.protocolHint.openai_responses",anthropic:"st.presets.protocolHint.anthropic","google-genai":"st.presets.protocolHint.google-genai",vertexai:"st.presets.protocolHint.vertexai"},Yi="group flex w-full min-w-0 items-center gap-3 px-3 py-2 text-left outline-none transition-colors hover:bg-ink/[0.04] focus-visible:bg-ink/[0.04] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 pointer-coarse:min-h-11";function xn(t){return t.toLowerCase().replace(/[\s_-]/g,"")}function yT({onPick:t,onPickDecision:s,dense:n=!1}){const{t:a}=D(),[i,r]=x.useState(""),o=xn(i.trim()),l=x.useMemo(()=>o===""?[]:hN.filter(p=>xn(p.id).includes(o)||xn(p.label).includes(o)||xn(p.baseUrl).includes(o)),[o]),c=x.useMemo(()=>o===""||s===void 0?[]:ia.filter(p=>{const h=a(`st.decision.preset.${p.id}`);return xn(p.id).includes(o)||xn(h).includes(o)||xn(p.baseUrl).includes(o)}),[o,s,a]),d=gT.flatMap(p=>{const h=fN(p);return h===void 0?[]:[h]}),u=l.length>0||c.length>0;return e.jsxs("div",{className:"space-y-3","data-preset-grid":!0,children:[e.jsx("input",{type:"search",className:Ce,"aria-label":a("st.presets.searchAria"),placeholder:a("st.presets.searchPlaceholder"),value:i,onChange:p=>{r(p.target.value)}}),u?e.jsxs("section",{"aria-label":a("st.presets.matches"),"data-preset-results":!0,children:[e.jsx("p",{className:"mb-1.5 text-[12px] font-medium text-ink-soft",children:a("st.presets.matches")}),e.jsxs("ul",{className:"divide-y divide-hairline overflow-hidden rounded-lg border border-hairline bg-paper",children:[l.map(p=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-provider-template":p.id,onClick:()=>{t(p)},className:Yi,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-ink",children:p.label}),e.jsxs("span",{className:"block truncate text-[12px] text-ink-faint",children:[ra(p.type)," · ",fa(p.baseUrl)]})]}),e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint group-hover:text-ink"})]})},p.id)),c.map(p=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-decision-template":p.id,onClick:()=>{s?.(p.id)},className:Yi,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-ink",children:a(`st.decision.preset.${p.id}`)}),e.jsx("span",{className:"block truncate text-[12px] text-ink-faint",children:a(`st.decision.presetHint.${p.id}`)})]}),e.jsx("span",{className:"hidden shrink-0 font-mono text-[11px] text-ink-faint sm:inline",children:p.type}),e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint group-hover:text-ink"})]})},`decision-${p.id}`))]})]}):e.jsxs(e.Fragment,{children:[o!==""?e.jsx("p",{className:"text-[12px] text-ink-faint",children:a("st.presets.empty",{query:i.trim()})}):null,e.jsxs("section",{"aria-label":a("st.presets.protocols"),children:[e.jsx("p",{className:"mb-1.5 text-[12px] font-medium text-ink-soft",children:a("st.presets.protocols")}),e.jsx("ul",{className:"divide-y divide-hairline overflow-hidden rounded-lg border border-hairline bg-paper",children:Tb.map(p=>{const h=vT[p];return e.jsx("li",{children:e.jsxs("button",{type:"button","data-provider-protocol":p,onClick:()=>{t(null,p)},className:Yi,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-ink",title:ra(p),children:ra(p)}),h!==void 0?e.jsx("span",{className:"block text-[12px] leading-4 text-ink-faint",children:a(h)}):null]}),e.jsx("span",{className:"hidden shrink-0 font-mono text-[11px] text-ink-faint sm:inline",children:p}),e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint group-hover:text-ink"})]})},p)})})]}),s!==void 0&&!n&&o===""?e.jsxs("section",{"aria-label":a("st.decision.presetsGroup"),"data-decision-presets":!0,children:[e.jsx("p",{className:"mb-1.5 text-[12px] font-medium text-ink-soft",children:a("st.decision.presetsGroup")}),e.jsx("ul",{className:"divide-y divide-hairline overflow-hidden rounded-lg border border-hairline bg-paper",children:ia.map(p=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-decision-template":p.id,onClick:()=>{s(p.id)},className:Yi,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-ink",children:a(`st.decision.preset.${p.id}`)}),e.jsx("span",{className:"block text-[12px] leading-4 text-ink-faint",children:a(`st.decision.presetHint.${p.id}`)})]}),e.jsx("span",{className:"hidden shrink-0 font-mono text-[11px] text-ink-faint sm:inline",children:p.type}),e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint group-hover:text-ink"})]})},p.id))})]}):null,!n&&o===""?e.jsxs("section",{"aria-label":a("st.presets.shortcuts"),className:"flex flex-wrap items-center gap-x-1 gap-y-1.5",children:[e.jsx("span",{className:"mr-1 text-[12px] text-ink-faint",children:a("st.presets.shortcuts")}),d.map(p=>e.jsx("button",{type:"button","data-provider-template":p.id,onClick:()=>{t(p)},className:"h-7 rounded-md px-2 text-[12px] text-ink-soft outline-none transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:h-10",children:p.label},p.id))]}):null]})]})}const kT="flex min-w-0 flex-1 items-start gap-2 rounded-lg px-3 py-2 text-left outline-none transition-colors duration-[var(--kiki-motion-quick)] focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:min-h-11";function jT({onPickApi:t,onPickDecision:s,onAccountChanged:n,onImported:a,configuredIds:i,dense:r=!1,initialMethod:o="api"}){const{t:l}=D(),[c,d]=x.useState(o),[u,p]=x.useState(r?"manual":"directory"),h=[{id:"account",title:l("st.connect.accountTitle"),body:l("st.connect.accountBody")},{id:"api",title:l("st.connect.apiTitle"),body:l("st.connect.apiBody")}],b=[{id:"directory",label:l("st.connect.sourceDirectory")},{id:"manual",label:l("st.connect.sourceManual")}];return e.jsxs("div",{className:"space-y-4","data-connection-method-picker":!0,"data-connection-method":c,children:[e.jsx("div",{role:"radiogroup","aria-label":l("st.connect.methodAria"),className:"flex flex-col gap-0.5 rounded-[10px] bg-ink/[0.04] p-0.5 sm:flex-row",children:h.map(m=>{const f=m.id===c;return e.jsxs("button",{type:"button",role:"radio","aria-checked":f,"data-connection-choice":m.id,onClick:()=>{d(m.id)},className:`${kT} ${f?"bg-paper shadow-[var(--kiki-sheet-shadow)]":"hover:bg-ink/[0.04]"}`,children:[e.jsx("span",{"aria-hidden":!0,className:`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border ${f?"border-ink bg-ink text-paper":"border-hairline-strong"}`,children:f?e.jsx(de,{name:"check",size:12}):null}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block text-[13px] ${f?"font-medium text-ink":"text-ink-soft"}`,children:m.title}),e.jsx("span",{className:"mt-0.5 block text-[12px] leading-4 text-ink-faint",children:m.body})]})]},m.id)})}),c==="account"?e.jsx(bN,{compact:r,onChanged:n,configuredProviderIds:i}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{role:"tablist","aria-label":l("st.connect.serviceAria"),"data-connection-source":u,className:"flex gap-1 border-b border-hairline",children:b.map(m=>e.jsx("button",{type:"button",role:"tab","aria-selected":u===m.id,"data-connection-source-choice":m.id,onClick:()=>{p(m.id)},className:`-mb-px min-h-8 border-b-2 px-3 py-1.5 text-[12px] transition-colors ${u===m.id?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:m.label},m.id))}),u==="directory"?e.jsx(VC,{configuredIds:i??new Set,onImported:async()=>{await a?.()}}):e.jsx(yT,{dense:r,onPick:t,onPickDecision:s})]})]})}let Wg=0;const Ji=t=>(t??[]).map(s=>({id:++Wg,stored:!0,name:s,value:Dt,removed:!1}));function mx(t,s){const n={};for(const a of t){const i=a.name.trim();if(a.stored&&a.removed){n[i]=null;continue}a.value.mode==="set"&&i!==""&&(n[i]=a.value.value)}for(const a of s)t.some(i=>i.stored&&i.name===a)||(n[a]=null);return Object.keys(n).length===0?void 0:n}function xx(t){return t.some(s=>s.removed||s.value.mode==="set"||!s.stored&&s.name.trim()!=="")}function hx({kind:t,entries:s,onChange:n,disabled:a,issueId:i}){const{t:r}=D(),o=x.useRef(null);x.useEffect(()=>{o.current!==null&&(document.querySelector(`[data-named-entry="${o.current}"]`)?.focus(),o.current=null)});const l=(d,u)=>{n(s.map(p=>p.id===d?{...p,...u}:p))},c=r(t==="header"?"st.providerExtras.headers":"st.providerExtras.env");return e.jsxs("div",{className:"space-y-2","data-provider-named":t,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:$e,children:c}),e.jsx("button",{type:"button",className:Q,disabled:a,onClick:()=>{const d=++Wg;o.current=d,n([...s,{id:d,stored:!1,name:"",value:Dt,removed:!1}])},children:r(t==="header"?"st.providerExtras.addHeader":"st.providerExtras.addEnv")})]}),e.jsx(he,{children:r(t==="header"?"st.providerExtras.headersHelp":"st.providerExtras.envHelp")}),s.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:r("st.providerExtras.none")}):null,e.jsx("ul",{className:"space-y-3",children:s.map(d=>e.jsxs("li",{"data-provider-named-entry":d.name||"new",className:`grid gap-2 sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)_auto] sm:items-start ${d.removed?"opacity-60":""}`,children:[d.stored?e.jsx("span",{className:"flex h-8 items-center truncate font-mono text-[12px] text-ink",title:d.name,children:d.name}):e.jsxs("div",{children:[e.jsx("input",{"data-named-entry":d.id,className:`${Ce} font-mono ${i===d.id?"border-danger":""}`,value:d.name,disabled:a,"aria-invalid":i===d.id,"aria-label":r("st.providerExtras.nameAria",{label:c}),placeholder:t==="header"?"X-Header-Name":"VARIABLE_NAME",onChange:u=>{l(d.id,{name:u.target.value})}}),i===d.id?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r("st.providerExtras.nameRequired")}):null]}),d.removed?e.jsx("p",{className:"flex h-8 items-center text-[12px] text-amber-ink",children:r("st.providerExtras.removePending")}):e.jsx(Dn,{label:r("st.providerExtras.valueLabel",{name:d.name||c}),labelHidden:!0,source:d.stored?"kiki":"none",clearable:!1,draft:d.value,disabled:a,sourceText:r(d.stored?"st.providerExtras.stored":"st.providerExtras.notStored"),placeholder:r(d.stored?"st.providerExtras.replacePlaceholder":"st.providerExtras.valuePlaceholder"),onChange:u=>{l(d.id,{value:u})}}),e.jsx("button",{type:"button",className:`${Q} h-8`,disabled:a,"aria-label":r(d.removed?"st.providerExtras.undoRemove":"st.providerExtras.remove",{name:d.name||c}),onClick:()=>{d.stored?l(d.id,{removed:!d.removed,value:Dt}):n(s.filter(u=>u.id!==d.id))},children:d.removed?r("st.secret.undoClear"):e.jsx(de,{name:"close",size:14})})]},d.id))})]})}function wT({providerId:t,onSaved:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=Oe(),o=je({queryKey:["provider-entity",t],queryFn:()=>n.getProviderEntity(t)}),l=o.data,[c,d]=x.useState("inherit"),[u,p]=x.useState([]),[h,b]=x.useState([]),[m,f]=x.useState(""),[g,v]=x.useState(!1),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=Je(),k=l?.model_source??"inherit",j=l!==void 0&&(c!==k||xx(u)||xx(h));Ft(`provider-extras:${t}`,j);const T=()=>{l!==void 0&&(d(l.model_source??"inherit"),p(Ji(l.custom_header_keys)),b(Ji(l.env_keys)),f(l.revision),w(null))};if(x.useEffect(()=>{l===void 0||j||g||l.revision===m||T()},[l,j,g,m]),o.isError)return e.jsx(De,{error:o.error});if(l===void 0)return e.jsx(he,{children:a("st.runtime.loading")});const A=async()=>{const P=[...u,...h].find(R=>!R.stored&&R.name.trim()===""&&R.value.mode==="set");if(P!==void 0){w(P.id);return}v(!0),_(null);try{const R=mx(u,l.custom_header_keys??[]),L=mx(h,l.env_keys??[]);await n.updateProvider(t,{base_revision:m,...c!==k?{model_source:c==="inherit"?null:c}:{},...R===void 0?{}:{custom_headers:R},...L===void 0?{}:{env:L}});const I=await o.refetch();I.data!==void 0&&(d(I.data.model_source??"inherit"),p(Ji(I.data.custom_header_keys)),b(Ji(I.data.env_keys)),f(I.data.revision)),await r.invalidateQueries({queryKey:["providers"]}),await s?.(),S()}catch(R){_({tone:"error",text:oe(i,R)})}finally{v(!1)}};return e.jsxs("div",{className:"space-y-4 rounded-lg border border-hairline bg-panel/50 p-3","data-provider-extras":t,children:[e.jsx("p",{className:"text-[11px] font-semibold text-ink-soft",children:a("st.providerExtras.title")}),e.jsxs("div",{className:"max-w-sm",children:[e.jsx("span",{className:$e,children:a("st.providerExtras.modelSource")}),e.jsx("div",{className:"mt-1",children:e.jsx(Qe,{variant:"form",ariaLabel:a("st.providerExtras.modelSource"),dataAttr:"data-provider-model-source",value:c,disabled:g,onChange:d,choices:[{value:"inherit",label:a("st.providerExtras.sourceInherit")},{value:"static",label:a("st.providerExtras.sourceStatic"),hint:a("st.providerExtras.sourceStaticHint")},{value:"discover",label:a("st.providerExtras.sourceDiscover"),hint:a("st.providerExtras.sourceDiscoverHint")},{value:"oauth-catalog",label:a("st.providerExtras.sourceOauth"),hint:a("st.providerExtras.sourceOauthHint")}]})})]}),e.jsx(hx,{kind:"header",entries:u,onChange:P=>{p(P),w(null)},disabled:g,issueId:y}),e.jsx(hx,{kind:"env",entries:h,onChange:P=>{b(P),w(null)},disabled:g,issueId:y}),l.oauth!==void 0?e.jsx("p",{className:"text-[12px] text-ink-soft","data-provider-oauth":l.oauth.storage,children:a("st.providerExtras.oauth",{storage:a(l.oauth.storage==="keyring"?"st.providerExtras.storageKeyring":"st.providerExtras.storageFile"),state:a(l.oauth.signed_in?"st.providerExtras.signedIn":"st.providerExtras.signedOut")})}):null,e.jsx(lt,{saved:C,id:`provider-extras-${t}`,dirty:j,saving:g,onSave:()=>void A(),onDiscard:()=>{T(),_(null)}}),e.jsx(pe,{feedback:N})]})}const NT="flex h-8 w-full min-w-0 items-center justify-between gap-1.5 rounded-md bg-ink/[0.04] px-3 text-left text-[13px] text-ink outline-none transition-colors hover:bg-ink/[0.07] focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-not-allowed disabled:text-ink-faint",fx=Ot,Vg=t=>({queryKey:["providers"],queryFn:()=>t.listProviders(),staleTime:6e4});function ST(t,s,n,a){if(t.kind==="model")return n(t.model)??t.model;const i=s?.find(c=>c.id===t.connection),r=i===void 0?null:Rd(i,t.protocol),l=t.model??r?.defaultModel??(t.protocol===void 0?void 0:a?.(t.protocol)??t.protocol);return l===void 0||l===""?t.connection:`${t.connection} · ${l}`}function CT({id:t,consumer:s,value:n,onChange:a,disabled:i,ariaLabel:r}){const{client:o}=be(),{t:l}=D(),c=je(Vg(o)),d=je({queryKey:["models"],queryFn:()=>o.listModels(),staleTime:6e4}),u=yN(),p=c.data?.items,h=d.data?.items??[],b=Pr(n),m=b!==""&&n!==void 0&&p!==void 0&&!d.isPending&&!(n.kind==="connection"?p.some(y=>y.id===n.connection&&Rd(y,n.protocol)!==null):h.some(y=>y.id===n.model)),f=x.useMemo(()=>{const y=[];for(const _ of p??[]){if(ha(_)){const j=po(_)??"system_one",T=Xp(s,j),A=fa(_.effective_base_url??_.base_url),P=j==="system_one"&&A==="api.typesafe.ai",R=_.api_key_env!==void 0&&!_.has_api_key,L=(_.default_model??"")==="",I=_.status==="error"?l("st.connections.statusError"):R?l("st.decision.status.envMissing",{name:_.api_key_env??""}):l(L?"st.decision.status.needsModel":"st.decision.status.ready"),$=P?`${l("st.decision.preset.jev")} · ${I}`:I;y.push({value:`connection:${_.id}`,label:_.id,hint:[A,_.default_model].filter(Boolean).join(" · ")||void 0,description:T?$:l("st.decision.picker.pairScoreOnly"),badges:[{label:l(`st.decision.protocol.${j}`)}],group:l("st.decision.picker.groupDecision"),disabled:!T,keywords:`${_.id} ${P?"Jev TypeSafe":""} ${j} ${_.base_url??""} ${_.default_model??""}`});continue}const C=_.decision_capabilities;if(C===void 0)continue;const S=fa(_.effective_base_url??_.base_url),k=_.api_key_env!==void 0&&!_.has_api_key;for(const j of ba){const T=C[j];if(T===void 0)continue;const A=Xp(s,j),P=(T.model??"")==="",R=_.status==="error"?l("st.connections.statusError"):k?l("st.decision.status.envMissing",{name:_.api_key_env??""}):l(P?"st.decision.status.needsModel":"st.decision.status.ready");y.push({value:`connection:${_.id}#${j}`,label:_.id,hint:[S,T.model].filter(Boolean).join(" · ")||void 0,description:A?R:l("st.decision.picker.pairScoreOnly"),badges:[{label:l(`st.decision.protocol.${j}`)}],group:l("st.decision.picker.groupDecision"),disabled:!A,keywords:`${_.id} ${j} ${_.base_url??""} ${T.model??""}`})}}const w=kN(h,l,{groupLabel:u}).map(_=>({..._,value:`model:${_.value}`,group:`${l("st.decision.picker.groupChat")} · ${_.group??""}`})),N=[{value:"",label:l("st.decision.picker.none")},...y,...w];return b!==""&&n!==void 0&&p!==void 0&&!d.isPending&&!N.some(_=>_.value===b)&&N.splice(1,0,{value:b,label:l("st.decision.picker.missing",{id:n.kind==="connection"?n.connection:n.model})}),N},[p,h,s,l,u,n,b,d.isPending]),g=y=>h.find(w=>w.id===y)?.display_name,v=y=>l(`st.decision.protocol.${y}`);return e.jsx(nn,{id:t,value:Pr(n),options:f,allowCustomValue:!1,ariaLabel:r,searchPlaceholder:l("st.decision.picker.search"),emptyText:l("st.decision.picker.none"),align:"end",placement:"auto",disabled:i,buttonClassName:NT,triggerLabel:n===void 0?void 0:m?l("st.decision.picker.missing",{id:n.kind==="connection"?n.connection:n.model}):ST(n,p,g,v),onChange:y=>{a(y===""?null:jN(y,n))}})}function Yg(t){const{t:s}=D(),[n,a]=x.useState(null),i=t?.source===void 0&&t?.backend==="jev";return(t?.apiKeySource??(t?.hasApiKey===!0?"kiki":"none"))==="kiki"?e.jsx(IT,{source:t?.source,onMoved:a}):i?e.jsx(TT,{keyEnv:t?.apiKeyEnv}):n!==null?e.jsx("p",{role:"status",className:"text-[12px] text-success",children:s("st.reviewer.moveDone",{id:n})}):null}function _T(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),i=Ib(),r=a.data?.permission?.reviewer,o=Yg(r),l=i.data?.advisor,c=[{consumer:"reviewer",label:s("st.decision.row.reviewer"),help:s("st.decision.row.reviewerHelp"),unset:s("st.decision.row.reviewerUnset"),source:r?.source,status:r?.source_status,legacy:r?.source!==void 0?void 0:r?.backend==="jev"?s("st.decision.row.reviewerLegacy"):r?.model!==void 0?s("st.reviewer.legacyModel",{model:r.model}):void 0,loading:a.isPending,error:a.error,write:async d=>{n.setQueryData(["config"],await t.patchConfig({permission:{reviewer:{source:d}}}))},extra:o},{consumer:"memory",label:s("st.decision.row.memory"),help:s("st.decision.row.memoryHelp"),unset:s("st.decision.row.memoryUnset"),source:l?.source,status:i.data?.advisor_status?.source_status,legacy:l?.source===void 0&&l?.selector!==void 0?s("st.decision.row.memoryLegacy",{model:l.selector.model}):void 0,loading:i.query.isPending,error:i.query.error,retry:()=>{i.query.refetch()},write:async d=>{await i.save.mutateAsync({advisor:d===null&&l?.selector!==void 0?{source:d,selector:null}:{source:d}})}}];return e.jsx("div",{className:"divide-y divide-hairline","data-decision-judges":!0,children:c.map(d=>e.jsx(pu,{...d,scope:"defaults"},d.consumer))})}function pu({consumer:t,label:s,help:n,unset:a,source:i,status:r,legacy:o,loading:l,error:c,retry:d,write:u,extra:p,scope:h="card"}){const{client:b}=be(),{t:m,locale:f}=D(),g=Tt(),v=je(Vg(b)),[y,w]=x.useState(!1),[N,_]=x.useState(null),[C,S]=Je(),k=i?.kind==="connection"?i:void 0,j=k===void 0?void 0:Pr(k),T=k===void 0?void 0:v.data?.items.find(se=>se.id===k.connection),P=(T===void 0||k===void 0?null:Rd(T,k.protocol))?.defaultModel,R=k?.model??"",[L,I]=x.useState(null),$=L!==null&&L.target===j?L.value:R,E=se=>{j!==void 0&&I({target:j,value:se})},M=k!==void 0&&$.trim()!==R;Ft(`decision-judge:${h}:${t}`,M);const[z,H]=x.useState(null),U=gN(t,i,r,v.data?.items),X=async se=>{if(!y&&!(se!==null&&Jp(se,i))&&!(se===null&&i===void 0&&o===void 0)){w(!0),_(null);try{await u(se),(se===null||se.kind!=="connection"||Pr(se)!==j)&&I(null),S()}catch(Y){_({tone:"error",text:m("st.decision.saveFailed",{detail:oe(f,Y)})})}finally{w(!1)}}},q=h==="defaults"?`st-decision-${t}`:`st-decision-${h}-${t}`,F=ET(U,i,m),V=h==="defaults"?{"data-decision-judge":t}:{"data-decision-field":t};return e.jsxs("div",{...V,"data-decision-problem":U??void 0,className:`grid gap-x-6 gap-y-1.5 sm:grid-cols-[minmax(0,1fr)_minmax(0,18rem)] sm:items-start ${h==="defaults"?"py-3 first:pt-0":"py-1"}`,children:[e.jsxs("div",{className:"min-w-0 sm:pt-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:q,className:"text-[13px] text-ink",children:s}),e.jsx(ot,{saving:y,saved:C})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:i===void 0?o??a:n}),U!==null?e.jsxs("div",{role:"alert",className:"mt-1 space-y-0.5",children:[e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:m(vN[U])}),F!==void 0?e.jsx("button",{type:"button","data-decision-fix":!0,className:fx,onClick:()=>{g(F.route)},children:F.label}):null]}):null,c!=null?e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 text-[12px] text-ink-faint","data-decision-read-error":!0,children:[e.jsx("span",{children:oe(f,c)}),d!==void 0?e.jsx("button",{type:"button",className:fx,onClick:d,children:m("common.retry")}):null]}):null,e.jsx(pe,{feedback:N}),p!=null?e.jsx("div",{className:"mt-2",children:p}):null]}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx(CT,{id:q,consumer:t,value:i,ariaLabel:s,disabled:y||l,onChange:se=>{if(M&&!(se!==null&&Jp(se,i))){H({next:se});return}X(se)}}),k!==void 0?e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:`${q}-model`,className:"block text-[12px] text-ink-soft",children:m("st.decision.row.modelOverride")}),e.jsx("input",{id:`${q}-model`,"data-decision-judge-model":!0,className:`${Ce} font-mono`,value:$,placeholder:P===void 0||P===""?"":m("st.decision.row.modelDefault",{model:P}),spellCheck:!1,autoComplete:"off",disabled:y,onChange:se=>{E(se.target.value)},onKeyDown:se=>{rt(se)||se.key==="Enter"&&M&&(se.preventDefault(),X(Zp(k,$)))}}),e.jsx(lt,{id:`decision-judge-${h}-${t}`,dirty:M,saving:y,saveLabel:m("st.decision.row.saveModel"),onSave:()=>{X(Zp(k,$))},onDiscard:()=>{I(null)}})]}):null]}),e.jsx(Xe,{open:z!==null,overlayId:`decision-judge-switch:${h}:${t}`,title:m("st.dirty.leaveTitle"),body:m("st.decision.row.switchBody"),confirmLabel:m("st.decision.row.switchConfirm"),cancelLabel:m("st.dirty.stay"),onConfirm:()=>{const se=z?.next??null;H(null),I(null),X(se)},onCancel:()=>{H(null)}})]})}function ET(t,s,n){if(t==="missing_connection"||t==="pair_score_reviewer")return{label:n("st.decision.fix.addService"),route:Sc};if(t==="not_decision"&&s?.kind==="connection")return{label:n("st.decision.fix.openConnection"),route:Cc(s.connection)};if(t==="not_decision")return{label:n("st.decision.fix.addService"),route:Sc};if((t==="auth"||t==="protocol"||t==="missing_model"||t==="unconfigured")&&s?.kind==="connection")return{label:n("st.decision.fix.openConnection"),route:Cc(s.connection)}}function TT({keyEnv:t}){const{t:s}=D(),n=Tt();return e.jsxs("div",{"data-reviewer-legacy":"env",className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-soft",children:s("st.reviewer.legacyEnv",{name:t??"TYPESAFE_API_KEY"})}),e.jsx("button",{type:"button","data-reviewer-add-jev":!0,className:Q,onClick:()=>{n(Sc)},children:s("st.reviewer.addJev")})]})}function IT({source:t,onMoved:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=Oe(),o=je({queryKey:["providers"],queryFn:()=>n.listProviders(),staleTime:6e4}),l=new Set((o.data?.items??[]).map(S=>S.id)),[c,d]=x.useState(null),u=t?.kind==="connection"&&l.has(t.connection)?t.connection:void 0,p=c?.connection??u,[h,b]=x.useState(""),[m,f]=x.useState(!1),[g,v]=x.useState(!1),[y,w]=x.useState(null);x.useEffect(()=>{if(!(m||!o.isSuccess)){if(p!==void 0){b(p);return}if(!l.has("typesafe")){b("typesafe");return}for(let S=2;;S++)if(!l.has(`typesafe-${S}`)){b(`typesafe-${S}`);break}}},[o.isSuccess,o.data,p,m]);const N=h.trim(),_=N===""||N===p?null:Qf.safeParse(N).success?l.has(N)?a("st.decision.idTaken"):null:a("st.decision.idInvalid"),C=async()=>{if(!(g||N===""||_!==null)){v(!0),w(null);try{const S=await n.moveReviewerKey(N);await Promise.all([r.invalidateQueries({queryKey:["config"]}),r.invalidateQueries({queryKey:["providers"]})]),f(!1),S.state==="complete"?(d(null),s(S.connection)):(d(S),w({tone:"error",text:a("st.reviewer.movePartial")}))}catch(S){w({tone:"error",text:a("st.reviewer.moveFailed",{detail:oe(i,S)})})}finally{v(!1)}}};return e.jsxs("div",{"data-reviewer-legacy":"key","data-reviewer-move":c?.state??"idle",className:"space-y-2",children:[e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-soft",children:a(t===void 0?"st.reviewer.legacyKey":"st.reviewer.legacyKeyLeft")}),e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-[12px] text-ink-soft",children:a("st.reviewer.moveId")}),e.jsx("input",{"data-reviewer-move-id":!0,className:`${Gt} w-48 font-mono`,value:h,disabled:g,spellCheck:!1,autoComplete:"off","aria-invalid":_!==null,"aria-describedby":_===null?void 0:"reviewer-move-id-issue",onChange:S=>{b(S.target.value),f(!0),w(null)}})]}),e.jsx("button",{type:"button","data-reviewer-move-key":!0,className:Q,disabled:g||N===""||_!==null||!o.isSuccess,onClick:()=>void C(),children:a(g?"st.reviewer.moving":c!==null?"common.retry":"st.reviewer.moveKey")})]}),e.jsx(it,{id:"reviewer-move-id-issue",text:_}),e.jsx(pe,{feedback:y})]})}const mu=/^[A-Za-z_][A-Za-z0-9_]*$/,Jg=["baseUrl","defaultModel","endpoint","keyEnv"];function Zi(t){return{baseUrl:t.base_url??"",defaultModel:t.default_model??"",endpoint:t.decision_endpoint??"",keyEnv:t.api_key_env??""}}const $l=(t,s)=>Jg.every(n=>t[n]===s[n]);function bx(t,s,n){const a={...t},i=[];for(const r of Jg)t[r]===s[r]?a[r]=n[r]:n[r]!==s[r]&&n[r]!==t[r]&&i.push(r);return{draft:a,conflicts:i}}function Zg(t){try{const s=new URL(t.trim());return s.protocol!=="http:"&&s.protocol!=="https:"?"invalid":s.username!==""||s.password!==""?"credentials":null}catch{return"invalid"}}const PT={baseUrl:"st.decision.baseUrl",defaultModel:"st.decision.model",endpoint:"st.decision.endpoint",keyEnv:"st.decision.keyEnv"},AT=t=>t!==null&&typeof t=="object"&&"code"in t&&t.code===40941,Xg={invalid:"st.decision.endpointInvalid",origin:"st.decision.endpointOrigin",credentials:"st.decision.endpointCredentials"};function $T(t){const s=po(t);return s==="openai_decisions"?"openai_decisions":s==="pair_score"?"pair_score":fa(t.effective_base_url??t.base_url)==="api.typesafe.ai"?"jev":"system_one"}function gx(t,s){if(!s.has(t))return t;for(let n=2;;n++)if(!s.has(`${t}-${n}`))return`${t}-${n}`}function ev({idPrefix:t,draft:s,onChange:n,keyDraft:a,onKeyChange:i,keySource:r,keyEnv:o,keyHint:l,reveal:c,protocol:d}){const{t:u}=D(),p=s.baseUrl.trim()===""?null:Zg(s.baseUrl),h=p===null?null:u(p==="credentials"?"st.decision.endpointCredentials":"st.decision.baseUrlInvalid"),b=h===null&&s.baseUrl.trim()!==""?Ld(s.baseUrl,s.endpoint):null,m=s.keyEnv.trim()!==""&&!mu.test(s.keyEnv.trim())?u("st.decision.keyEnvInvalid"):null,f=_c(s.baseUrl,d);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs(ge,{label:u("st.decision.baseUrl"),htmlFor:`${t}-base`,layout:"stack",children:[e.jsx("input",{id:`${t}-base`,"data-decision-base-url":!0,className:`${Ce} max-w-xl font-mono`,value:s.baseUrl,placeholder:"https://",spellCheck:!1,autoComplete:"off","aria-invalid":h!==null,onChange:g=>{n({...s,baseUrl:g.target.value})}}),e.jsx(it,{id:`${t}-base-issue`,text:h})]}),e.jsx("div",{className:"max-w-xl",children:e.jsx(Dn,{id:`${t}-key`,label:u("st.decision.key"),source:r,envName:o,draft:a,onChange:i,reveal:c,hint:l})}),e.jsx(ge,{label:u("st.decision.model"),htmlFor:`${t}-model`,layout:"stack",help:u("st.decision.modelHint"),children:e.jsx("input",{id:`${t}-model`,"data-decision-model":!0,className:`${Ce} max-w-sm font-mono`,value:s.defaultModel,spellCheck:!1,autoComplete:"off",onChange:g=>{n({...s,defaultModel:g.target.value})}})}),e.jsx(et,{summary:u("st.advanced.disclosure"),"data-decision-advanced":!0,open:s.endpoint.trim()!==""||void 0,children:e.jsxs("div",{className:"space-y-3 pt-1 text-[13px] text-ink",children:[e.jsxs(ge,{label:u("st.decision.keyEnv"),htmlFor:`${t}-key-env`,layout:"stack",help:u("st.decision.keyEnvFieldHint"),children:[e.jsx("input",{id:`${t}-key-env`,"data-decision-key-env":!0,className:`${Ce} max-w-xs font-mono`,value:s.keyEnv,placeholder:"YOUR_API_KEY",spellCheck:!1,autoComplete:"off","aria-invalid":m!==null,onChange:g=>{n({...s,keyEnv:g.target.value})}}),e.jsx(it,{id:`${t}-key-env-issue`,text:m})]}),e.jsxs(ge,{label:u("st.decision.endpoint"),htmlFor:`${t}-endpoint`,layout:"stack",help:f===null||b!==null?void 0:u("st.decision.endpointHint",{origin:f.origin,path:f.pathname}),children:[e.jsx("input",{id:`${t}-endpoint`,"data-decision-endpoint":!0,className:`${Ce} max-w-xl font-mono`,value:s.endpoint,placeholder:f?.pathname??"/",spellCheck:!1,autoComplete:"off","aria-invalid":b!==null,onChange:g=>{n({...s,endpoint:g.target.value})}}),b!==null?e.jsx("p",{"data-decision-endpoint-issue":b,role:"alert",className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:u(Xg[b],{origin:f?.origin??s.baseUrl})}):null]})]})})]})}function Hc(t){return Zg(t.baseUrl)===null&&Ld(t.baseUrl,t.endpoint)===null&&(t.keyEnv.trim()===""||mu.test(t.keyEnv.trim()))}function RT({configuredIds:t,initialPreset:s="openai_decisions",onCancel:n,onCreated:a}){const{client:i}=be(),{t:r,locale:o}=D(),l=x.useId(),[c,d]=x.useState(s),u=ia.find(R=>R.id===c),[p,h]=x.useState(()=>gx(u.suggestedId,t)),[b,m]=x.useState(!1),[f,g]=x.useState({baseUrl:u.baseUrl,defaultModel:u.defaultModel,endpoint:"",keyEnv:u.apiKeyEnv??""}),[v,y]=x.useState(Dt),[w,N]=x.useState(!1),[_,C]=x.useState(null);Ft("decision-connection:new",!0);const S=R=>{const L=ia.find(I=>I.id===R);d(R),g({baseUrl:L.baseUrl,defaultModel:L.defaultModel,endpoint:"",keyEnv:L.apiKeyEnv??""}),b||h(gx(L.suggestedId,t)),C(null)},k=p.trim(),j=k===""?null:Qf.safeParse(k).success?t.has(k)?r("st.decision.idTaken"):null:r("st.decision.idInvalid"),T=v.mode==="set"?v.value.trim():"",A=k!==""&&j===null&&Hc(f)&&!w,P=async()=>{if(A){N(!0),C(null);try{await i.createProvider({id:k,type:u.type,base_url:f.baseUrl.trim(),api_key:T===""?void 0:T,api_key_env:T===""&&f.keyEnv.trim()||void 0,default_model:f.defaultModel.trim()||void 0,decision_endpoint:f.endpoint.trim()||void 0}),await a()}catch(R){C({tone:"error",text:oe(o,R)}),N(!1)}}};return e.jsxs("div",{"data-decision-new":!0,id:"decision-connection-add",className:"space-y-4 rounded-lg border border-hairline bg-paper p-4",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:r("st.decision.addTitle")}),e.jsxs("fieldset",{disabled:w,className:"min-w-0 space-y-3 disabled:opacity-60",children:[e.jsx(ge,{label:r("st.decision.kind"),labelId:`${l}-kind`,layout:"stack",help:r(`st.decision.presetHint.${c}`),children:e.jsx(He,{ariaLabelledBy:`${l}-kind`,dataAttr:"data-decision-preset",value:c,onChange:S,choices:ia.map(R=>({value:R.id,label:r(`st.decision.preset.${R.id}`)}))})}),e.jsxs(ge,{label:r("st.decision.id"),htmlFor:`${l}-id`,layout:"stack",children:[e.jsx("input",{id:`${l}-id`,"data-decision-id":!0,className:`${Ce} max-w-xs font-mono`,value:p,spellCheck:!1,autoComplete:"off","aria-invalid":j!==null,onChange:R=>{h(R.target.value),m(!0)}}),e.jsx(it,{id:`${l}-id-issue`,text:j})]}),e.jsx(ev,{idPrefix:l,draft:f,onChange:R=>{g(R),C(null)},keyDraft:v,onKeyChange:y,keySource:"none",protocol:u.type,keyHint:f.keyEnv.trim()!==""&&mu.test(f.keyEnv.trim())?r("st.decision.keyEnvHint",{name:f.keyEnv.trim()}):r("st.decision.keyNone")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button","data-decision-create":!0,className:Ye,disabled:!A,onClick:()=>void P(),children:r(w?"common.saving":"st.decision.create")}),e.jsx("button",{type:"button",className:Q,disabled:w,onClick:n,children:r("common.cancel")})]}),e.jsx(pe,{feedback:_})]})}function LT({provider:t,density:s="comfortable",defaultOpen:n=!1,openFocusKeySignal:a=0,onChanged:i}){const{client:r}=be(),{t:o,locale:l}=D(),c=So(),d=x.useRef(null),u=x.useId(),p=po(t)??"system_one",h=ia.find(Se=>Se.id===$T(t)),b=Zi(t),[m,f]=x.useState(b),[g,v]=x.useState(b),[y,w]=x.useState(),[N,_]=x.useState(null),[C,S]=x.useState(Dt),[k,j]=x.useState(!1),[T,A]=x.useState(null),[P,R]=Je(),[L,I]=x.useState(!1),[$,E]=x.useState(!1),[M,z]=x.useState(),[H,U]=x.useState(()=>n||a>0),X=!$l(g,m)||C.mode!=="keep",q=H||n||a>0||X;Ft(`decision-connection:${t.id}`,X);const F=JSON.stringify(b),[V,se]=x.useState(F);x.useEffect(()=>{F===V||X||k||(se(F),!$l(b,m)&&(f(b),v(b),w(void 0),_(null)))},[F,V,X,k]);const[Y,O]=x.useState(0),[B,le]=x.useState(!1),re=x.useRef({draft:g,baseline:m});re.current={draft:g,baseline:m};const ae=JSON.stringify(m);x.useEffect(()=>{if(!q||y!==void 0)return;let Se=!0;return le(!1),r.getProviderEntity(t.id).then(Fe=>{if(!Se)return;const ye=Zi(Fe),{draft:ze,baseline:Pe}=re.current;if(w(Fe.revision),le(!1),$l(ye,Pe))return;const xe=bx(ze,Pe,ye);f(ye),v(xe.draft),xe.conflicts.length>0&&(_({fields:xe.conflicts,saved:ye}),A({tone:"error",text:o("st.decision.conflict")}))}).catch(Fe=>{Se&&(le(!0),A({tone:"error",text:oe(l,Fe)}))}),()=>{Se=!1}},[q,ae,y,Y,t.id]),x.useEffect(()=>{n&&(U(!0),d.current!==null&&(d.current.open=!0))},[n]),x.useEffect(()=>{if(a===0)return;U(!0);const Se=d.current;if(Se===null)return;Se.open=!0,requestAnimationFrame(()=>{const ye=Se.querySelector("[data-secret-field] [data-secret-edit]");if(ye!==null&&!ye.disabled){ye.click();return}Se.querySelector("[data-secret-field] input")?.focus()})},[a]);const[ne,Ee]=x.useState(0),ie=t.api_key_env!==void 0?"environment":t.has_api_key?"kiki":"none",me=x.useCallback(async()=>(await r.revealSecret({kind:"provider_api_key",provider_id:t.id})).value,[r,t.id,t.has_api_key,t.api_key_env,ne]),fe=wN(t),Ie=t.api_key_env!==void 0&&!t.has_api_key,te=(t.default_model??"")==="",ee=M?.result!==void 0&&!M.result.ok,K=ee?"error":Ie||te?"setup":t.status==="error"?"error":"ok",Z=ee&&M.result?.reason==="auth"?o("st.decision.reason.auth"):K==="error"?o("st.connections.statusError"):Ie?o("st.decision.status.envMissing",{name:t.api_key_env??""}):o(te?"st.decision.status.needsModel":"st.decision.status.ready"),ue=Ie?o("st.decision.keyEnvMissing",{name:t.api_key_env??""}):ie==="none"?o("st.decision.keyNone"):void 0,Te=async()=>{if(!(!X||!Hc(g)||y===void 0)){j(!0),A(null);try{const Se=C.mode==="set"?C.value.trim():"",Fe=Pe=>g[Pe]!==m[Pe],ye=await r.updateProvider(t.id,{base_revision:y,base_url:Fe("baseUrl")?g.baseUrl.trim():void 0,default_model:Fe("defaultModel")?g.defaultModel.trim()||null:void 0,decision_endpoint:Fe("endpoint")?g.endpoint.trim()||null:void 0,api_key_env:Fe("keyEnv")?g.keyEnv.trim()||null:void 0,api_key:C.mode==="clear"?"":Se!==""?Se:void 0}),ze=Zi(ye);f(ze),v(ze),w(ye.revision),_(null),S(Dt),Ee(Pe=>Pe+1),z(void 0),await i(),R()}catch(Se){if(AT(Se))try{const Fe=await r.getProviderEntity(t.id),ye=Zi(Fe),ze=bx(g,m,ye);f(ye),v(ze.draft),w(Fe.revision),_(ze.conflicts.length===0?null:{fields:ze.conflicts,saved:ye}),A({tone:"error",text:o("st.decision.conflict")}),i()}catch(Fe){A({tone:"error",text:oe(l,Fe)})}else A({tone:"error",text:oe(l,Se)})}finally{j(!1)}}},Ne=async()=>{if(!(fe===void 0||$)){E(!0);try{z({result:await r.probeDecisionSource({kind:"connection",connection:t.id},fe)})}catch(Se){z({error:Se})}finally{E(!1)}}},J=async()=>{j(!0),A(null);try{await r.deleteProviderEntity(t.id),await i()}catch(Se){A({tone:"error",text:oe(l,Se)}),j(!1)}},_e=$?e.jsx("span",{children:o("st.decision.testing")}):M?.error!==void 0?e.jsx("span",{className:"text-danger",children:o("st.decision.testFailed",{reason:oe(l,M.error)})}):M?.result===void 0?null:M.result.ok?e.jsx("span",{className:"text-success",children:o("st.decision.testOk",{ms:Math.round(M.result.duration_ms)})}):e.jsx("span",{className:"text-danger",children:o("st.decision.testFailed",{reason:o(`st.decision.reason.${M.result.reason??"unavailable"}`)})}),we=h.id==="jev"?o("st.decision.preset.jev"):t.id,G=fa(t.effective_base_url??t.base_url),Le=e.jsxs("span",{"data-connection-status":K,"data-decision-status":K,className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${K==="error"?"text-danger":K==="setup"?"text-amber-ink":"text-ink-soft"}`,children:[K==="error"||K==="setup"?e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${K==="error"?"bg-danger":"bg-amber-rule"}`}):null,e.jsx("span",{children:Z})]});return e.jsxs("details",{ref:d,"data-connection-row":t.id,"data-decision-row":t.id,"data-connection-kind":"decision","data-connection-health":K,"data-decision-health":K,className:"group/provider [&[open]]:bg-paper",open:n||void 0,onToggle:Se=>{U(Se.currentTarget.open)},children:[e.jsxs("summary",{style:{minHeight:_s[s]},className:`flex cursor-pointer list-none items-center gap-3 px-3 outline-none transition-colors hover:bg-ink/[0.03] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden ${s==="compact"?"py-1":"py-2"}`,children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-ink/[0.05] text-ink-soft",children:e.jsx(de,{name:"gate",size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:`flex min-w-0 items-baseline ${c?"justify-between gap-2":"gap-2"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:we}),we!==t.id?e.jsx("span",{className:"hidden truncate font-mono text-[11px] text-ink-faint sm:inline",children:t.id}):null,e.jsx("span",{"data-decision-badge":!0,className:"shrink-0 rounded border border-hairline px-1.5 py-0.5 text-[11px] font-medium leading-none text-ink-soft",children:o("st.decision.badge")})]}),c?Le:null]}),s==="compact"?null:e.jsxs("span",{className:"block truncate text-[12px] text-ink-faint",children:[o(`st.decision.protocol.${p}`),G===void 0?"":` · ${G}`,t.default_model===void 0||t.default_model===""?"":` · ${t.default_model}`]})]}),X?e.jsx("span",{className:"shrink-0 text-[11px] font-medium text-amber-ink",children:o("st.dirty.badge")}):null,c?null:Le,e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open/provider:rotate-90"})]}),q?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 px-3 pb-4 pt-1 sm:pl-[3.25rem]",children:[fe!==void 0?e.jsxs("div",{"data-decision-test":!0,className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("button",{type:"button","data-decision-test-button":!0,className:Q,disabled:$||k||X,"aria-busy":$,onClick:()=>void Ne(),children:o($?"st.decision.testing":"st.decision.test")}),e.jsx("p",{"data-decision-test-result":M?.result===void 0&&M?.error===void 0?"none":M.result?.ok===!0?"ok":"error","aria-live":"polite",className:"min-w-0 break-all text-[12px] leading-4 text-ink-faint",children:_e})]}):null,e.jsx("fieldset",{disabled:k,className:"min-w-0 disabled:opacity-60",children:e.jsx(ev,{idPrefix:u,draft:g,onChange:Se=>{v(Se),A(null)},keyDraft:C,onKeyChange:S,keySource:ie,keyEnv:t.api_key_env,reveal:t.has_api_key?me:void 0,keyHint:ue,protocol:p})}),e.jsx(lt,{id:`decision-connection-${t.id}`,dirty:X,saving:k,saved:P,saveDisabled:!Hc(g)||y===void 0,saveLabel:o("st.decision.save"),onSave:()=>void Te(),onDiscard:()=>{v(m),S(Dt),A(null),_(null)}}),e.jsx(pe,{feedback:T}),B&&y===void 0?e.jsx("div",{children:e.jsx("button",{type:"button","data-decision-revision-retry":!0,className:Q,onClick:()=>{A(null),O(Se=>Se+1)},children:o("common.retry")})}):null,N!==null?e.jsx("p",{"data-decision-conflict":N.fields.join(" "),role:"alert",className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:o("st.decision.conflictFields",{fields:N.fields.map(Se=>o(PT[Se])).join(", "),saved:N.fields.map(Se=>N.saved[Se]||"—").join(", ")})}):null,e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-decision-remove":!0,className:Ht,disabled:k,onClick:()=>{I(!0)},children:o("st.decision.remove")})})]}),e.jsx(Xe,{open:L,title:o("st.decision.removeTitle",{id:t.id}),body:o("st.decision.removeBody"),confirmLabel:o("st.decision.removeConfirm"),busy:k,onConfirm:()=>{I(!1),J()},onCancel:()=>{I(!1)}})]}):null]})}function Xi(t){return{openai_decisions:{enabled:t?.openai_decisions!==void 0,model:t?.openai_decisions?.model??"",endpoint:t?.openai_decisions?.endpoint??""},system_one:{enabled:t?.system_one!==void 0,model:t?.system_one?.model??"",endpoint:t?.system_one?.endpoint??""},pair_score:{enabled:t?.pair_score!==void 0,model:t?.pair_score?.model??"",endpoint:t?.pair_score?.endpoint??""}}}function xu(t,s){return t.enabled===s.enabled&&t.model.trim()===s.model.trim()&&t.endpoint.trim()===s.endpoint.trim()}function MT(t,s){return ba.every(n=>xu(t[n],s[n]))}function OT(t,s){const n={};for(const a of ba){const i=t[a],r=s[a];if(!xu(i,r)){if(!i.enabled){n[a]=null;continue}n[a]={model:i.model.trim()||null,endpoint:i.endpoint.trim()||null}}}return Object.keys(n).length===0?null:n}function DT({provider:t,onSaved:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=Oe(),o=x.useId(),l=je({queryKey:["provider-entity",t.id],queryFn:()=>n.getProviderEntity(t.id),staleTime:3e4}),c=l.data,d=c?.decision_capabilities??t.decision_capabilities,[u,p]=x.useState(()=>Xi(d)),[h,b]=x.useState(()=>Xi(d)),[m,f]=x.useState(""),[g,v]=x.useState(!1),[y,w]=x.useState(null),[N,_]=Je(),[C,S]=x.useState(null),[k,j]=x.useState({}),T=!MT(u,h);Ft(`provider-decision-capabilities:${t.id}`,T),x.useEffect(()=>{if(c===void 0||T||g||c.revision===m)return;const E=Xi(c.decision_capabilities);p(E),b(E),f(c.revision)},[c,T,g,m]);const A=c?.effective_base_url??c?.base_url??t.effective_base_url??t.base_url,P={};for(const E of ba){const M=u[E];if(!M.enabled||A===void 0||A.trim()==="")continue;const z=Ld(A,M.endpoint);z!==null&&(P[E]=z)}const R=Object.keys(P).length>0,L=(E,M)=>{p(z=>({...z,[E]:{...z[E],...M}})),w(null)},I=async()=>{const E=OT(u,h);if(!(E===null||R||m==="")){v(!0),w(null);try{const M=await n.updateProvider(t.id,{base_revision:m,decision_capabilities:E}),z=Xi(M.decision_capabilities);p(z),b(z),f(M.revision),j({}),await Promise.all([l.refetch(),r.invalidateQueries({queryKey:["providers"]}),r.invalidateQueries({queryKey:["config"]})]),await s?.(),_()}catch(M){w({tone:"error",text:oe(i,M)})}finally{v(!1)}}},$=async E=>{const M=h[E];if(!M.enabled||C!==null)return;const z=_c(A,E,M.endpoint),H=NN(t.id,z);if(H!==void 0){S(E);try{const U=await n.probeDecisionSource({kind:"connection",connection:t.id,protocol:E},H);j(X=>({...X,[E]:{result:U}}))}catch(U){j(X=>({...X,[E]:{error:U}}))}finally{S(null)}}};return l.isError?e.jsx(De,{error:l.error}):e.jsxs("div",{className:"space-y-3","data-provider-decision-capabilities":t.id,children:[e.jsx("div",{className:"divide-y divide-hairline rounded-lg border border-hairline bg-panel/50 px-3",children:ba.map(E=>{const M=u[E],z=h[E],H=!xu(M,z),U=a(`st.decision.protocol.${E}`),X=_c(A,E),q=P[E]??null,F=k[E],V=C===E,se=z.enabled&&!H&&X!==null&&!g&&C===null,Y=V?e.jsx("span",{children:a("st.decision.testing")}):F?.error!==void 0?e.jsx("span",{className:"text-danger",children:a("st.decision.testFailed",{reason:oe(i,F.error)})}):F?.result===void 0?H?e.jsx("span",{children:a("st.decision.capabilities.unsavedHint")}):null:F.result.ok?e.jsx("span",{className:"text-success",children:a("st.decision.testOk",{ms:Math.round(F.result.duration_ms)})}):e.jsx("span",{className:"text-danger",children:a("st.decision.testFailed",{reason:a(`st.decision.reason.${F.result.reason??"unavailable"}`)})});return e.jsxs("div",{"data-decision-capability":E,className:"space-y-2.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:U}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:a(`st.decision.presetHint.${E==="system_one"?"system_one":E==="pair_score"?"pair_score":"openai_decisions"}`)})]}),e.jsx(Be,{id:`${o}-${E}-toggle`,layout:"bare",label:a("st.decision.capabilities.enableAria",{protocol:U,provider:t.id}),checked:M.enabled,disabled:g||m==="",onChange:O=>{L(E,{enabled:O})}})]}),M.enabled?e.jsxs("div",{className:"space-y-2.5 pl-0.5 pt-0.5",children:[e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:`${o}-${E}-model`,className:"block text-[12px] text-ink-soft",children:a("st.decision.model")}),e.jsx("input",{id:`${o}-${E}-model`,"data-decision-capability-model":E,className:`${Ce} font-mono`,value:M.model,disabled:g,spellCheck:!1,autoComplete:"off",onChange:O=>{L(E,{model:O.target.value})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:`${o}-${E}-endpoint`,className:"block text-[12px] text-ink-soft",children:a("st.decision.endpoint")}),e.jsx("input",{id:`${o}-${E}-endpoint`,"data-decision-capability-endpoint":E,className:`${Ce} font-mono`,value:M.endpoint,placeholder:X?.pathname??"/",disabled:g,spellCheck:!1,autoComplete:"off","aria-invalid":q!==null,onChange:O=>{L(E,{endpoint:O.target.value})}})]})]}),q!==null?e.jsx("p",{"data-decision-capability-endpoint-issue":q,role:"alert",className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:a(Xg[q],{origin:X?.origin??A??""})}):null,X!==null?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("button",{type:"button","data-decision-capability-test":E,className:Q,disabled:!se,"aria-busy":V,onClick:()=>{$(E)},children:a(V?"st.decision.testing":"st.decision.test")}),e.jsx("p",{"data-decision-capability-test-result":F?.result===void 0&&F?.error===void 0?"none":F.result?.ok===!0?"ok":"error","aria-live":"polite",className:"min-w-0 break-all text-[12px] leading-4 text-ink-faint",children:Y})]}):null]}):null]},E)})}),e.jsx(lt,{id:`provider-decision-capabilities-${t.id}`,dirty:T,saving:g,saved:N,saveDisabled:R||m==="",onSave:()=>void I(),onDiscard:()=>{p(h),w(null)}}),e.jsx(pe,{feedback:y})]})}const FT=Bj.options,Rl={openai:"st.modelProtocol.openai",openai_responses:"st.modelProtocol.openai_responses",anthropic:"st.modelProtocol.anthropic","google-genai":"st.modelProtocol.google-genai"};function zc(t){return t??"inherit"}function tv(t,s){return t===s?{}:{protocol:t==="inherit"?null:t}}function sv(t){return t==="inherit"?{}:{protocol:t}}function qT(t,s){return t.models===void 0?t:{...t,models:t.models.map((n,a)=>{const i=s[a]??"inherit";return i==="inherit"?n:{...n,protocol:i}})}}function kn(t,s){const n=(t??[]).slice(0,s);for(;n.length<s;)n.push("inherit");return n}const BT={model:"st.modelProtocol.source.model",provider:"st.modelProtocol.source.provider",vendor:"st.modelProtocol.source.vendor",plugin:"st.modelProtocol.source.provider"},vx={model:"st.modelProtocol.origin.model",provider:"st.modelProtocol.origin.provider",env:"st.modelProtocol.origin.env",vendor:"st.modelProtocol.origin.vendor",none:"st.modelProtocol.origin.none"},KT=/^[A-Z][A-Z0-9_]*$/;function yx(t,s,n){return s!=="env"||n===void 0||!KT.test(n)?t:`${t} (${n})`}function hu({model:t,value:s,resolved:n,source:a,endpointSource:i,authSource:r,endpointEnv:o,authEnv:l,onChange:c,disabled:d=!1}){const{t:u}=D(),h=[{value:"inherit",label:n===void 0?u("st.modelProtocol.inherit"):u("st.modelProtocol.inheritResolved",{format:u(Rl[n])})},...FT.map(f=>({value:f,label:u(Rl[f]),hint:f}))],b=s==="inherit"?n:s,m=s==="inherit"?a:"model";return e.jsxs("div",{className:"min-w-0 space-y-1","data-model-protocol-field":s,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:$e,children:u("st.modelProtocol.label")}),b!==void 0&&m!==void 0?e.jsx(Rn,{children:e.jsxs("span",{"data-effective-protocol":!0,children:[u("st.modelProtocol.effective",{format:u(Rl[b]),source:u(BT[m])}),i!==void 0||r!==void 0?` · ${u("st.modelProtocol.bindingOrigins",{endpoint:yx(u(vx[i??"none"]),i??"none",o),credential:yx(u(vx[r??"none"]),r??"none",l)})}`:""]})}):null]}),e.jsx(Qe,{variant:"form",choices:h,value:s,onChange:c,ariaLabel:u("st.modelProtocol.aria",{model:t}),disabled:d,dataAttr:"data-model-protocol"})]})}function UT(t){return{remoteId:t.remote_id,name:t.display_name,maxContextSize:t.max_context_size,capabilities:t.capabilities??[],supportEfforts:t.support_efforts??[],protocol:t.protocol,effectiveProtocol:t.effective_protocol==="plugin"?void 0:t.effective_protocol,protocolSource:t.protocol_source==="plugin"?void 0:t.protocol_source,endpointSource:t.endpoint_source,authSource:t.auth_source,endpointEnv:t.endpoint_env,authEnv:t.auth_env,source:"configured"}}function HT(t){return{remoteId:t.id,name:t.name,maxContextSize:t.max_context_size,capabilities:t.capabilities??[],supportEfforts:t.support_efforts??[],source:"directory"}}function zT(t){return{remoteId:t.remote_id,name:t.display_name,maxContextSize:t.max_context_size??0,capabilities:t.capabilities??[],supportEfforts:t.support_efforts??[],source:"discovered"}}function kx(t){return{remoteId:t.remoteId,name:t.displayName===""?void 0:t.displayName,maxContextSize:t.maxContextSize,capabilities:t.capabilities,supportEfforts:t.supportEfforts,source:"draft"}}function nv(...t){const s=new Map;for(const n of t)for(const a of n){const i=s.get(a.remoteId);s.set(a.remoteId,i===void 0?a:{...i,name:i.name??a.name,maxContextSize:i.maxContextSize>0?i.maxContextSize:a.maxContextSize,capabilities:i.capabilities.length>0?i.capabilities:a.capabilities,supportEfforts:i.supportEfforts.length>0?i.supportEfforts:a.supportEfforts})}return[...s.values()]}function QT(){return{id:"",type:"openai",baseUrl:"",defaultModel:"",apiKey:"",clearApiKey:!1,requestIdentityChoice:"inherit",requestIdentityOverridesJson:"",imageAcceptedTypes:null,imageConvertUnsupported:null,models:[av()]}}function av(){return{id:"",remoteId:"",maxContextSize:25e4,displayName:"",capabilities:[...kd],supportEfforts:[...vc],requestIdentityChoice:"inherit",requestIdentityOverridesJson:"",imageAcceptedTypes:null,imageConvertUnsupported:null}}function jx({direction:t,label:s,disabled:n,onStep:a}){return e.jsx("button",{type:"button","aria-label":s,disabled:n,onClick:()=>{a(t)},className:"flex w-7 items-center justify-center rounded-md border border-hairline bg-paper text-[13px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:t===1?"+":"−"})}const wx=[{id:"tokens",factor:1,label:"tok"},{id:"K",factor:1e3,label:"K"},{id:"M",factor:1e6,label:"M"}];function GT(t){return t>=1e6&&t%1e6===0?"M":t>=1e3&&t%1e3===0?"K":"tokens"}function fu({value:t,onChange:s,ariaLabel:n}){const{t:a}=D(),[i,r]=x.useState(()=>GT(t)),o=wx.find(d=>d.id===i)?.factor??1,l=Math.round(t/o*1e3)/1e3,c=d=>{Number.isFinite(d)&&s(Math.max(1,Math.round(d*o)))};return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(jx,{direction:-1,label:a("st.stepper.decrease"),onStep:()=>{c(l-1)}}),e.jsx("input",{type:"number",min:0,step:"any","aria-label":n,className:`${pt} w-24 text-right`,value:l,onChange:d=>{c(Number(d.target.value))}}),e.jsx(jx,{direction:1,label:a("st.stepper.increase"),onStep:()=>{c(l+1)}}),e.jsx("div",{role:"group","aria-label":a("st.stepper.unitAria"),"data-context-unit":!0,className:"ml-1 inline-flex items-center gap-0.5 rounded-md bg-ink/[0.04] p-0.5",children:wx.map(d=>{const u=d.id===i;return e.jsx("button",{type:"button","aria-pressed":u,"data-context-unit-choice":d.id,onClick:()=>{r(d.id)},className:`h-6 min-w-7 rounded-[5px] px-1.5 font-mono text-[11px] outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:h-9 ${u?"bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"text-ink-soft hover:text-ink"}`,children:d.label},d.id)})})]})}function bu({value:t,onChange:s,inheritLabel:n}){const{t:a}=D(),i=t.imageAcceptedTypes===null?"inherit":"custom";return e.jsxs("div",{className:"space-y-2 rounded-lg border border-hairline bg-panel/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:a("st.images.title")}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[9rem_minmax(0,1fr)] sm:items-center",children:[e.jsx("span",{className:"text-[11px] font-medium text-ink-soft",children:a("st.images.acceptedTypes")}),e.jsx(Qe,{variant:"form",dataAttr:"data-image-accepted-mode",ariaLabel:a("st.images.acceptedTypesModeAria"),value:i,onChange:r=>{s({...t,imageAcceptedTypes:r==="inherit"?null:[...$p]})},choices:[{value:"inherit",label:n},{value:"custom",label:a("st.images.custom")}]})]}),t.imageAcceptedTypes===null?null:e.jsx(ln,{values:t.imageAcceptedTypes,knownOptions:$p,onChange:r=>{s({...t,imageAcceptedTypes:r})},ariaLabel:a("st.images.acceptedTypesAria"),addPlaceholder:a("st.images.addMime"),removeLabel:r=>a("st.images.removeMimeAria",{mime:r})}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[9rem_minmax(0,1fr)] sm:items-center",children:[e.jsx("span",{className:"text-[11px] font-medium text-ink-soft",children:a("st.images.convertUnsupported")}),e.jsx(Qe,{variant:"form",dataAttr:"data-image-conversion",ariaLabel:a("st.images.convertUnsupportedAria"),value:t.imageConvertUnsupported??"",onChange:r=>{s({...t,imageConvertUnsupported:r===""?null:r})},choices:[{value:"",label:n},...["off","auto","png","jpeg"].map(r=>({value:r,label:a(`st.images.convert.${r}`)}))]})]})]})}function js({id:t,summary:s,label:n,children:a,defaultOpen:i=!1}){const{t:r}=D(),[o,l]=x.useState(i);return e.jsxs("div",{"data-advanced":t,"data-open":o?"true":void 0,className:"border-t border-hairline pt-2",children:[e.jsxs("button",{type:"button","aria-expanded":o,"aria-controls":`advanced-${t}`,onClick:()=>{l(c=>!c)},className:"-ml-1 flex min-h-7 w-full items-center gap-1.5 rounded-md px-1 text-left outline-none transition-colors hover:bg-ink/[0.04] focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsx(Rt,{open:o,className:"text-ink-soft"}),e.jsx("span",{className:"text-[12px] font-medium text-ink-soft",children:n??r("st.advanced.disclosure")}),s!==void 0&&!o?e.jsx("span",{className:"min-w-0 truncate text-[12px] text-ink-faint",children:s}):null]}),e.jsx("div",{id:`advanced-${t}`,hidden:!o,className:"space-y-4 pt-3",children:a})]})}const WT=[{capability:"thinking",key:"st.models.capReasoning"},{capability:"image_in",key:"st.models.capVision"},{capability:"tool_use",key:"st.models.capTools"}];function gu({capabilities:t}){const{t:s}=D(),n=WT.filter(a=>t?.includes(a.capability)===!0||a.capability==="thinking"&&t?.includes("always_thinking")===!0);return n.length===0?null:e.jsx("span",{"data-capability-marks":!0,className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-ink-faint",children:n.map((a,i)=>e.jsxs("span",{"data-capability":a.capability,children:[i>0?e.jsx("span",{"aria-hidden":!0,className:"mr-1.5",children:"·"}):null,s(a.key)]},a.capability))})}function Nx({model:t,index:s,isDefault:n,canRemove:a,catalogByRemoteId:i,catalogOptions:r,protocol:o,onProtocolChange:l,onChange:c,onRemove:d,onSetDefault:u}){const{t:p}=D(),h=uu(),[b,m]=x.useState(t.remoteId===""),f=s+1,g=t.requestIdentityChoice==="inherit"?"inherit":t.requestIdentityChoice.startsWith("profile:")?"custom":t.requestIdentityChoice,v=t.id||t.remoteId,y=i.get(t.remoteId),w=t.remoteId!==""&&t.id===""&&(y?.source==="discovered"||y?.source==="directory"),N=y?.source==="configured"&&y.protocol===void 0?y.effectiveProtocol:void 0,_=C=>{const S=i.get(C);if(S===void 0){c({remoteId:C});return}c({remoteId:C,displayName:S.name??"",maxContextSize:S.maxContextSize>0?S.maxContextSize:t.maxContextSize,capabilities:[...S.capabilities],supportEfforts:[...S.supportEfforts]})};return e.jsxs("div",{className:"rounded-lg border border-hairline bg-panel p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button","aria-label":p("st.providers.defaultStarAria",{model:v||"…"}),title:p("st.providers.defaultStarTitle"),disabled:t.remoteId==="",onClick:u,className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors disabled:cursor-not-allowed disabled:opacity-30 ${n?"text-ink":"text-ink-faint hover:text-ink"}`,children:e.jsx(de,{name:n?"starFilled":"star"})}),e.jsxs("button",{type:"button","aria-label":p("st.providers.modelExpandAria",{n:f}),"aria-expanded":b,onClick:()=>{m(C=>!C)},className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx("span",{className:`truncate text-[13px] ${t.remoteId===""?"text-ink-faint":"font-medium text-ink"}`,children:t.remoteId===""?"model-id":t.displayName||t.remoteId}),t.remoteId!==""?(()=>{const C=[...(t.displayName||t.remoteId)!==t.remoteId?[t.remoteId]:[],...t.id!==""&&t.id!==t.remoteId?[t.id]:[]];return C.length>0?e.jsx("span",{className:"hidden min-w-0 shrink truncate font-mono text-[11px] text-ink-faint sm:inline",children:C.join(" · ")}):null})():null,e.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-ink-faint",children:mo(t.maxContextSize)}),e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(gu,{capabilities:t.capabilities})}),g!=="inherit"?e.jsx("span",{className:"hidden shrink-0 text-[11px] text-ink-faint sm:inline",children:p(`st.providers.requestIdentityBadge.${g}`)}):null,e.jsx(Rt,{open:b,className:"ml-auto text-ink-faint"})]}),e.jsx("button",{type:"button",disabled:!a,"aria-label":p("st.providers.removeModel"),onClick:d,className:`${Q} shrink-0 px-2 text-danger`,children:e.jsx(de,{name:"close",size:12})})]}),b?e.jsxs("div",{className:"mt-3 space-y-2 border-t border-hairline pt-3",children:[t.id!==""?e.jsx("p",{className:"truncate font-mono text-[11px] text-ink-faint",children:t.id}):null,e.jsxs("div",{className:"grid items-start gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(Jt,{id:`provider-model-${s}-id`,options:r,value:t.remoteId,onChange:_,ariaLabel:p("st.providers.modelIdAria",{n:f}),allowCustomValue:!0,customValueLabel:C=>p("st.providers.useCustomModel",{id:C}),searchPlaceholder:p("st.providers.modelSearchPlaceholder"),emptyText:p("st.providers.catalogEmpty"),buttonClassName:`${Ce} flex items-center justify-between gap-2 text-left font-mono`,panelClassName:"w-[min(30rem,calc(100vw-48px))] max-h-[min(var(--available-height,360px),360px)]"}),w?e.jsx("p",{"data-model-suggestion":!0,className:"text-[11px] font-medium text-accent-ink",children:p("st.providers.catalogSuggestionNote")}):null]}),e.jsx("input",{className:Ce,"aria-label":p("st.providers.modelNameAria",{n:f}),value:t.displayName,onChange:C=>{c({displayName:C.target.value})},placeholder:p("st.providers.displayNamePlaceholder")})]}),e.jsx(hu,{model:v||String(f),value:o,resolved:N,source:N===void 0?void 0:y?.protocolSource,endpointSource:y?.source==="configured"?y.endpointSource:void 0,authSource:y?.source==="configured"?y.authSource:void 0,endpointEnv:y?.source==="configured"?y.endpointEnv:void 0,authEnv:y?.source==="configured"?y.authEnv:void 0,onChange:l}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:p("st.compact.windowLabel")}),e.jsx(fu,{value:t.maxContextSize,onChange:C=>{c({maxContextSize:C})},ariaLabel:p("st.providers.modelContextAria",{n:f})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:p("st.chips.efforts")}),e.jsx(ln,{values:t.supportEfforts,knownOptions:jd,onChange:C=>{c({supportEfforts:C})},ariaLabel:p("st.providers.modelEffortsAria",{n:f}),addPlaceholder:p("st.chips.addPlaceholder"),removeLabel:C=>p("st.chips.removeAria",{value:C})})]}),e.jsxs("div",{className:"space-y-1","data-draft-model-capabilities":t.id,children:[e.jsx("p",{className:$e,children:p("st.chips.capabilities")}),e.jsx(ln,{values:t.capabilities,knownOptions:wd,onChange:C=>{c({capabilities:C})},ariaLabel:p("st.providers.modelCapsAria",{n:f}),addPlaceholder:p("st.chips.addPlaceholder"),removeLabel:C=>p("st.chips.removeAria",{value:C})})]}),e.jsxs(js,{id:`draft-model-${s}`,summary:p("st.models.draftAdvancedSummary"),children:[e.jsx(bu,{value:t,onChange:C=>{c(C)},inheritLabel:p("st.images.inheritProvider")}),e.jsx(Ao,{value:t,onChange:C=>{c(C)},label:p("st.models.requestIdentity"),inheritLabel:p("st.requestIdentity.inheritProvider"),customProfiles:h})]})]}):null]})}function VT(t,s,n){return t.clearApiKey?{mode:"clear"}:t.apiKey===s&&!n?{mode:"keep"}:{mode:"set",value:t.apiKey}}function YT(t,s,n){return s.mode==="clear"?{...t,apiKey:n,clearApiKey:!0}:{...t,apiKey:s.mode==="set"?s.value:n,clearApiKey:!1}}function iv({draft:t,onChange:s,hasStoredKey:n,baselineApiKey:a="",apiKeyEnv:i,managed:r=!1,idLocked:o=!1,refreshProviderId:l,baselineBaseUrl:c,baselineType:d,catalogModels:u=[],modelProtocols:p,onModelProtocolsChange:h,onRefreshed:b,fieldIssue:m=null,decisionCapabilitiesExtra:f,advancedExtra:g,revealKey:v,storedModels:y}){const{t:w,locale:N}=D(),{client:_}=be(),C=uu(),S=m?.field==="id"?qs(N,m.issue):null,k=m?.field==="baseUrl"?qs(N,m.issue):null,[j,T]=x.useState(!1),[A,P]=x.useState(null),[R,L]=x.useState(!1);x.useEffect(()=>{L(!1)},[a,n,i,v]);const I=Oe(),[$,E]=x.useState([]);x.useEffect(()=>{E([])},[t.baseUrl,t.apiKey,t.type]);const M=x.useMemo(()=>nv(u,$,t.models.filter(ie=>ie.remoteId!=="").map(kx)),[u,$,t.models]),z=x.useMemo(()=>{const ie=new Map;for(let me=0;me<M.length;me+=1){const fe=M[me];ie.set(fe.remoteId,fe)}return ie},[M]),H=x.useMemo(()=>M.map(ie=>({value:ie.remoteId,label:ie.remoteId,description:ie.name,keywords:ie.name,group:ie.source==="configured"?w("st.providers.catalogGroupConfigured"):ie.source==="draft"?w("st.providers.catalogGroupDraft"):w("st.providers.catalogGroupSuggested"),badges:[...ie.source==="directory"||ie.source==="discovered"?[{label:ie.source==="discovered"?w("st.providers.catalogFromProvider"):w("st.providers.catalogFromDirectory"),accent:!0}]:[],...ie.maxContextSize>0?[{label:mo(ie.maxContextSize)}]:[],...ie.capabilities.slice(0,2).map(me=>({label:me})),...ie.supportEfforts.length>0?[{label:w("st.providers.catalogEfforts",{count:ie.supportEfforts.length})}]:[]]})),[M,w]),U=x.useMemo(()=>{const ie=[{value:"",label:w("st.auth.none")}];let me=t.defaultModel==="";for(let fe=0;fe<t.models.length;fe+=1){const Ie=t.models[fe],te=Ie.id||Ie.remoteId;te===t.defaultModel&&(me=!0),Ie.remoteId!==""&&ie.push({value:te,label:Ie.displayName||te,hint:Ie.displayName!==""?Ie.remoteId:void 0})}return!me&&t.defaultModel!==""&&ie.splice(1,0,{value:t.defaultModel,label:t.defaultModel}),ie},[t.defaultModel,t.models,w]),X=x.useMemo(()=>{const ie=[];for(let me=0;me<t.models.length;me+=1){const fe=t.models[me];y!==void 0&&fe.id!==""||ie.push({model:fe,index:me})}return ie},[t.models,y]),q=Ta(),[F,V]=x.useState(null),se=x.useCallback(ie=>{V(ie)},[]),Y=X.length>q.catalogVirtualizeThreshold,O=Ri({count:Y?X.length:0,getScrollElement:()=>F,estimateSize:()=>56,getItemKey:ie=>{const me=X[ie];return me===void 0?ie:me.model.id||`new-${me.index}`},overscan:q.virtualOverscan,initialRect:{width:640,height:480},observeElementRect:(ie,me)=>{const fe=ie.scrollElement;if(fe===null)return;const Ie=()=>{const ee=fe.getBoundingClientRect(),K=Math.round(ee.height||fe.clientHeight),Z=Math.round(ee.width||fe.clientWidth);K>0&&me({width:Z,height:K})};if(Ie(),typeof ResizeObserver>"u")return;const te=new ResizeObserver(Ie);return te.observe(fe),()=>{te.disconnect()}},measureElement:ie=>{const me=Math.round(ie.getBoundingClientRect().height);return me>0?me:56},useFlushSync:!1}),B=(ie,me)=>{s({...t,models:t.models.map((fe,Ie)=>Ie===ie?{...fe,...me}:fe)})},le=async()=>{T(!0),P(null);try{if(l!==void 0){if(c!==void 0&&t.baseUrl!==c||d!==void 0&&t.type!==d){P({tone:"info",text:w("st.fetchModels.unsavedTarget")});return}const me=!t.clearApiKey&&t.apiKey!==a&&t.apiKey!==""?t.apiKey:void 0,fe=await _.refreshProvider(l,me);await I.invalidateQueries({queryKey:["discovered-models"]});const Ie=fe.failed.find(K=>K.provider===l);if(Ie!==void 0)throw new Error(Ie.reason);const te=fe.changed.find(K=>K.provider_id===l);if(te!==void 0){await b?.(),P({tone:"success",text:w("st.fetchModels.serverChanged",{added:te.added,removed:te.removed})});return}const ee=fe.discovered?.find(K=>K.provider_id===l);if(ee!==void 0){P({tone:"success",text:ee.models.length===0?w("st.fetchModels.noNewSuggestions"):w("st.fetchModels.suggestions",{count:ee.models.length})});return}P(fe.unchanged.includes(l)?{tone:"success",text:w("st.fetchModels.serverUnchanged")}:{tone:"error",text:w("st.fetchModels.serverUnsupported")});return}const ie=await _.probeProviderDraft({type:t.type,baseUrl:t.baseUrl,apiKey:t.apiKey});E(ie.map(me=>({...kx(me),source:"discovered"}))),P({tone:"success",text:w("st.fetchModels.suggestions",{count:ie.length})})}catch(ie){P({tone:"error",text:ie instanceof TypeError?w("st.fetchModels.networkError"):oe(N,ie)})}finally{T(!1)}},re=(o||r?CN:Tb).filter(ie=>Uj.includes(ie)),ae=re.includes(t.type)?re:[t.type,...re],ne=x.useId(),Ee=o||r?`${ne}-base-url`:"provider-field-base-url";return e.jsxs("div",{className:"space-y-4",children:[r?null:e.jsxs(e.Fragment,{children:[o?null:e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"provider-field-id",className:$e,children:w("st.providers.idLabel")}),e.jsx("input",{id:"provider-field-id",className:`${Ce} mt-1 ${S!==null?"border-danger/60":""}`,value:t.id,"aria-invalid":S!==null||void 0,"aria-describedby":S!==null?"provider-field-id-issue":void 0,placeholder:"my-provider",onChange:ie=>{s({...t,id:ie.target.value})}}),e.jsx(it,{id:"provider-field-id-issue",text:S})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:Ee,className:$e,children:w("st.providers.baseUrl")}),e.jsx("input",{id:Ee,className:`${Ce} mt-1 ${k!==null?"border-danger/60":""}`,value:t.baseUrl,"aria-invalid":k!==null||void 0,"aria-describedby":k!==null?"provider-field-base-url-issue":void 0,onChange:ie=>{s(o?{...t,baseUrl:ie.target.value}:_N(t,ie.target.value))},placeholder:"https://api.example.com/v1"}),e.jsx(it,{id:"provider-field-base-url-issue",text:k})]}),e.jsx("div",{children:e.jsx(Dn,{label:w("st.providers.apiKey"),source:i!==void 0?"environment":n?"kiki":"none",envName:i,draft:VT(t,a,R),onChange:ie=>{L(ie.mode==="set"),s(YT(t,ie,a))},reveal:v,placeholder:n||i!==void 0?void 0:w("st.providers.keyNew")})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3","data-connection-test":!0,children:[e.jsx("button",{type:"button",className:Q,disabled:j,onClick:()=>void le(),children:w(j?"st.fetchModels.working":"st.fetchModels.button")}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(pe,{feedback:A})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("p",{className:$e,children:[w("st.providers.models"),e.jsx("span",{className:"ml-1.5 font-normal text-ink-faint",children:t.models.filter(ie=>ie.remoteId!=="").length})]}),e.jsx("button",{type:"button",className:Q,onClick:()=>{s({...t,models:[...t.models,av()]}),h(kn(p,t.models.length+1))},children:w("st.providers.addModel")})]}),o?e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:w("st.models.providerDefault")}),e.jsx(Qe,{variant:"form",dataAttr:"data-provider-default-model",ariaLabel:w("st.models.providerDefault"),value:t.defaultModel,onChange:ie=>{s({...t,defaultModel:ie})},choices:U})]}):null,y,y!==void 0&&t.models.some(ie=>ie.id==="")?e.jsx("p",{className:`${$e} pt-2`,"data-provider-new-models":!0,children:w("st.providerModels.newRows")}):null,Y?e.jsx("div",{ref:se,"data-provider-draft-models-virtual":!0,className:"max-h-[min(520px,65vh)] overflow-y-auto pr-0.5",children:e.jsx("div",{style:{height:O.getTotalSize(),position:"relative"},children:O.getVirtualItems().map(ie=>{const me=X[ie.index];if(me===void 0)return null;const{model:fe,index:Ie}=me;return e.jsx("div",{"data-index":ie.index,ref:O.measureElement,className:"pb-2",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${ie.start}px)`},children:e.jsx(Nx,{model:fe,index:Ie,isDefault:fe.remoteId!==""&&(fe.id===t.defaultModel||fe.remoteId===t.defaultModel),canRemove:!0,catalogByRemoteId:z,catalogOptions:H,protocol:p[Ie]??"inherit",onProtocolChange:te=>{h(p.map((ee,K)=>K===Ie?te:ee))},onChange:te=>{B(Ie,te)},onRemove:()=>{const te=t.models.filter((K,Z)=>Z!==Ie),ee=te[0];s({...t,models:te,defaultModel:fe.id===t.defaultModel||fe.remoteId===t.defaultModel?ee===void 0?"":ee.id||ee.remoteId:t.defaultModel}),h(kn(p.filter((K,Z)=>Z!==Ie),te.length))},onSetDefault:()=>{s({...t,defaultModel:fe.id||fe.remoteId})}})},ie.key)})})}):X.map(({model:ie,index:me})=>e.jsx(Nx,{model:ie,index:me,isDefault:ie.remoteId!==""&&(ie.id===t.defaultModel||ie.remoteId===t.defaultModel),canRemove:!0,catalogByRemoteId:z,catalogOptions:H,protocol:p[me]??"inherit",onProtocolChange:fe=>{h(p.map((Ie,te)=>te===me?fe:Ie))},onChange:fe=>{B(me,fe)},onRemove:()=>{const fe=t.models.filter((te,ee)=>ee!==me),Ie=fe[0];s({...t,models:fe,defaultModel:ie.id===t.defaultModel||ie.remoteId===t.defaultModel?Ie===void 0?"":Ie.id||Ie.remoteId:t.defaultModel}),h(kn(p.filter((te,ee)=>ee!==me),fe.length))},onSetDefault:()=>{s({...t,defaultModel:ie.id||ie.remoteId})}},ie.id||`new-${me}`))]}),f,e.jsxs(js,{id:`provider-${t.id||"new"}`,label:w("st.providers.advancedProtocol"),summary:w("st.providers.advancedSummary"),children:[r?null:e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:w("st.providers.protocol")}),e.jsx("div",{className:"mt-1",children:e.jsx(Jt,{id:o?`${ne}-protocol`:"provider-field-protocol",ariaLabel:w("st.providers.protocol"),value:t.type,hideFilter:!0,options:ae.map(ie=>({value:ie,label:ra(ie),hint:ie})),onChange:ie=>{s({...t,type:ie})},buttonClassName:Sn})})]}),e.jsx(Ao,{value:t,onChange:ie=>{s({...t,...ie})},label:w("st.providers.requestIdentity"),inheritLabel:w("st.requestIdentity.inheritGlobal"),customProfiles:C}),e.jsx(bu,{value:t,onChange:ie=>{s({...t,...ie})},inheritLabel:w("st.images.inheritBuiltin")}),g]})]})}const Qc=["provider-health"];function JT(t,s,n){const a=t.unit==="percent"?n("st.connections.quotaPercent",{n:Math.round(t.remaining)}):n("st.connections.quotaCount",{n:t.remaining.toLocaleString(s==="zh"?"zh-CN":"en-US")});return n("st.connections.quotaLine",{label:t.label,amount:a})}function ZT(t){if(t?.error_code==="model_not_configured")return"st.connections.fixNoModel";const s=t?.http_status;return s===401||s===403?"st.connections.fixAuth":s===404?"st.connections.fixNotFound":s===429?"st.connections.fixRateLimit":s!==void 0&&s>=500?"st.connections.fixServer":t?.error_code==="model_unavailable"?"st.connections.fixModel":"st.connections.errorFix"}function XT({provider:t,models:s,managed:n=!1,modelCount:a,onSaved:i,accountLabel:r,accountMethod:o,density:l="comfortable",modelList:c,defaultOpen:d=!1,openFocusKeySignal:u=0}){const{t:p,locale:h,time:b}=D(),m=So(),f=x.useRef(null),{client:g}=be(),v=Oe(),y=x.useMemo(()=>Kj(t,s),[t,s]),w=x.useMemo(()=>{const Ae=y?.models??[],Ue=new Map(s.map(We=>[We.id,We])),Ge=Ae.map(We=>We.id===""?"inherit":zc(Ue.get(We.id)?.protocol)),Ke=new Map;return Ae.forEach((We,ce)=>{We.id!==""&&Ke.set(We.id,Ge[ce]??"inherit")}),{choices:Ge,baselines:Ke}},[y,s]),[N,_]=x.useState(y),[C,S]=x.useState(y),[k,j]=x.useState(y),[T,A]=x.useState(w.choices),[P,R]=x.useState(w.baselines),[L,I]=x.useState([]),[$,E]=x.useState(!1),[M,z]=x.useState(null),[H,U]=x.useState(null),[X,q]=x.useState(()=>!!d||(u??0)>0||c===void 0),[F,V]=x.useState(null),[se,Y]=x.useState(0),O=x.useCallback(async()=>(await g.revealSecret({kind:"provider_api_key",provider_id:t.id})).value,[g,t.id,t.has_api_key,t.api_key_env,F?.provider,se]),B=je({queryKey:["discovered-models"],queryFn:()=>g.listDiscoveredModels()}),le=je({queryKey:Qc,queryFn:()=>g.listProviderHealth(),enabled:typeof g.listProviderHealth=="function",staleTime:3e4,retry:!1}),[re,ae]=x.useState(!1),[ne,Ee]=x.useState(),ie=x.useMemo(()=>nv(s.filter(Ae=>Ae.provider_id===t.id).map(UT),(B.data?.items.find(Ae=>Ae.provider_id===t.id)?.models??[]).map(zT),L.map(HT)),[L,B.data,s,t.id]),me=N!==null&&N.models.some((Ae,Ue)=>Ae.id!==""&&(T[Ue]??"inherit")!==(P.get(Ae.id)??"inherit")),fe=N!==null&&C!==null&&Gf(N,C)||me;x.useEffect(()=>{y===k||fe||$||(_(y),S(y),j(y),A(w.choices),R(w.baselines))},[y,k,fe,$,w]),x.useEffect(()=>{(d||(u??0)>0)&&q(!0)},[d,u]),x.useEffect(()=>{const Ae=f.current;if(Ae===null||typeof MutationObserver>"u")return;Ae.open&&q(!0);const Ue=new MutationObserver(()=>{q(Ae.open)});return Ue.observe(Ae,{attributes:!0,attributeFilter:["open"]}),()=>{Ue.disconnect()}},[]),x.useEffect(()=>{if(!X)return;let Ae=!0;return I([]),g.getCatalogProvider(t.id).then(Ue=>{Ae&&I(Ue.models)}).catch(()=>{Ae&&I([])}),()=>{Ae=!1}},[X,t.id]);const Ie=c===void 0;x.useEffect(()=>{if(!X)return;let Ae=!0;return V(null),Promise.all([g.getProviderEntity(t.id),Ie?Promise.all((k?.models??[]).filter(Ue=>Ue.id!=="").map(async Ue=>[Ue.id,(await g.getModel(Ue.id)).revision])):Promise.resolve([])]).then(([Ue,Ge])=>{Ae&&V({provider:Ue.revision,models:new Map(Ge)})}).catch(Ue=>{Ae&&z({tone:"error",text:oe(h,Ue)})}),()=>{Ae=!1}},[X,Ie,k,t.id]),Ft(`provider:${t.id}`,fe),x.useEffect(()=>{if(u===0)return;q(!0);const Ae=f.current;if(Ae===null)return;Ae.open=!0,requestAnimationFrame(()=>{const Ge=Ae.querySelector("[data-secret-field] [data-secret-edit]");if(Ge!==null&&!Ge.disabled){Ge.click();return}Ae.querySelector("[data-secret-field] input")?.focus()})},[u]);const te=async()=>{E(!0),z(null);try{await g.deleteProviderEntity(t.id),await i()}catch(Ae){z({tone:"error",text:oe(h,Ae)}),E(!1)}};if(N===null||C===null)return e.jsxs("div",{"data-connection-row":t.id,className:"space-y-2 rounded-xl border border-hairline bg-paper p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[13px] font-semibold text-ink",children:r??t.id}),e.jsx("button",{type:"button","data-provider-remove":t.id,className:Ht,disabled:$,onClick:()=>{U("remove")},children:p("st.danger.removeProvider")})]}),e.jsx(he,{children:p("st.providers.cannotRewrite")}),e.jsx(pe,{feedback:M}),e.jsx(Xe,{open:H==="remove",title:p("st.confirm.removeTitle",{id:r??t.id}),body:p(n?"st.providers.removeOAuthBody":"st.confirm.removeBody"),consequences:n?[p("st.confirm.removeC1",{id:t.id}),p("st.providers.removeOAuthReaddC2")]:[p("st.confirm.removeC1",{id:t.id}),p("st.confirm.removeC2")],confirmLabel:p("st.confirm.removeAction"),busy:$,onConfirm:()=>{U(null),te()},onCancel:()=>{U(null)}})]});const ee=async Ae=>{const Ue={...N,...Ae},Ge=Qj(Ue,C);if(Ge!==null){z({tone:"error",text:qs(h,Ge)});return}if(F===null)return;E(!0),z(null);let Ke=!1;try{let We=Ue,ce=C;const qe=new Map(F.models),st=new Map(P);for(const[ct,wt]of Ue.models.entries()){if(wt.id!=="")continue;const Lt=await g.createModel({...Gj(t.id,wt),...sv(T[ct]??"inherit")});Ke=!0,qe.set(Lt.id,Lt.revision),st.set(Lt.id,T[ct]??"inherit");const Zt={...wt,id:Lt.id};We={...We,models:We.models.map((Ws,qn)=>qn===ct?Zt:Ws)},ce={...ce,models:[...ce.models,Zt]},_(We),S(ce),R(new Map(st)),V({provider:F.provider,models:qe})}for(const[ct,wt]of We.models.entries()){const Lt=ce.models.find(Bn=>Bn.id===wt.id);if(Lt===void 0)continue;const Zt=Wf(wt,Lt),Ws=tv(T[ct]??"inherit",st.get(wt.id)??"inherit");if(Zt===null&&!("protocol"in Ws))continue;const qn=qe.get(wt.id);if(qn===void 0)throw new Error(`Missing revision for model ${wt.id}`);const Kt=await g.updateModel(wt.id,{...Zt,...Ws,base_revision:qn});Ke=!0,qe.set(wt.id,Kt.revision),st.set(wt.id,T[ct]??"inherit"),ce={...ce,models:ce.models.map(Bn=>Bn.id===wt.id?wt:Bn)},S(ce),R(new Map(st)),V({provider:F.provider,models:qe})}for(const ct of ce.models){if(We.models.some(Zt=>Zt.id===ct.id)||ct.id==="")continue;const Lt=qe.get(ct.id);if(Lt===void 0)throw new Error(`Missing revision for model ${ct.id}`);await g.deleteModel(ct.id,{baseRevision:Lt}),Ke=!0,qe.delete(ct.id),st.delete(ct.id),ce={...ce,models:ce.models.filter(Zt=>Zt.id!==ct.id)},S(ce),R(new Map(st)),V({provider:F.provider,models:qe})}const gt=Wj(We,ce);if(gt!==null){const ct=await g.updateProvider(t.id,{...gt,base_revision:F.provider});Ke=!0,v.setQueryData(["provider-entity",t.id],ct),V({provider:ct.revision,models:qe})}const Es={...We,apiKey:"",clearApiKey:!1};_(Es),S(Es),Y(ct=>ct+1),await i(),z({tone:"success",text:p("st.providers.savedEcho",{id:t.id})})}catch(We){z({tone:"error",text:oe(h,We)}),Ke&&await i().catch(()=>{})}finally{E(!1)}},K=n?"account":uo(t.base_url)?"local":"api",Z=Pb(t.base_url),ue=fa(t.base_url),Te=B.data?.items.find(Ae=>Ae.provider_id===t.id)?.failure_reason,Ne=a??s.filter(Ae=>Ae.provider_id===t.id).length,J=ne??le.data?.items.find(Ae=>Ae.provider_id===t.id),_e=K==="api"&&!t.has_api_key&&t.api_key_env===void 0,we=t.status==="unconfigured"||_e?"setup":J!==void 0?J.ok?"ok":"error":t.status==="error"||Te!==void 0?"error":"ok",G=p(we==="error"?"st.connections.statusError":we==="setup"?_e?"st.connections.statusNeedsKey":"st.connections.statusSetup":"st.connections.statusOk"),Le=o===void 0?null:$d(o,void 0),Se=we==="error"||Le?.state==="failed"?"error":we==="setup"||Le?.state==="signIn"||Le?.state==="reconnect"?"setup":"ok",Fe=Le===null?G:p(Ab(Le)),ye=J===void 0?void 0:b.relativeTime(new Date(J.checked_at).toISOString()),ze=o?.account.state==="known"?o.account.id:void 0,Pe=o?.signed_in===!0&&o.quota.state==="known"?o.quota:void 0,xe=Pe===void 0?void 0:JT(Pe,h,p),ke=async()=>{if(!re){ae(!0);try{const Ae=await g.testProviderConnection(t.id);Ee(Ae),v.setQueryData(Qc,Ue=>({items:[...(Ue?.items??[]).filter(Ge=>Ge.provider_id!==t.id),Ae]}))}catch(Ae){Ee(void 0),z({tone:"error",text:oe(h,Ae)})}finally{ae(!1)}}},W=e.jsxs("span",{"data-connection-status":Se,title:ye===void 0?void 0:p("st.connections.testedAgo",{time:ye}),className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${Se==="error"?"text-danger":Se==="setup"?"text-amber-ink":"text-ink-soft"}`,children:[Se==="error"||Se==="setup"?e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${Se==="error"?"bg-danger":"bg-amber-rule"}`}):null,e.jsx("span",{children:Fe})]}),Re=X||fe||H!==null;return e.jsxs("details",{ref:f,"data-connection-row":t.id,"data-connection-kind":K,"data-connection-health":Se,className:"group/provider [&[open]]:bg-paper",open:d||void 0,onToggle:Ae=>{q(Ae.currentTarget.open)},children:[e.jsxs("summary",{style:{minHeight:_s[l]},className:`flex cursor-pointer list-none items-center gap-3 px-3 outline-none transition-colors hover:bg-ink/[0.03] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden ${l==="compact"?"py-1":"py-2"}`,children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-ink/[0.05] text-ink-soft",children:e.jsx(de,{name:K==="account"?"agent":K==="local"?"system":"web",size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:`flex min-w-0 items-baseline ${m?"justify-between gap-2":"gap-2"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:r??Z??t.id}),r!==void 0||Z!==void 0?e.jsx("span",{className:"hidden truncate font-mono text-[11px] text-ink-faint sm:inline",children:t.id}):null]}),m?W:null]}),l==="compact"?null:e.jsxs("span",{className:"block truncate text-[12px] text-ink-faint",children:[p(`st.connections.kind.${K}`),!m&&ze!==void 0?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-connection-account":!0,title:ze,className:"text-ink-soft",children:At(ze)})]}):null,!m&&ue!==void 0&&K!=="account"?` · ${ue}`:""," · ",p("st.connections.modelCount",{count:Ne}),!m&&xe!==void 0?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-connection-quota":Pe?.unit,className:"tabular-nums text-ink-soft",title:Pe?.reset_at===void 0?void 0:p("st.connections.quotaResets",{time:b.absoluteTime(Pe.reset_at)??Pe.reset_at}),children:xe})]}):null]})]}),fe?e.jsx("span",{className:"shrink-0 text-[11px] font-medium text-amber-ink",children:p("st.dirty.badge")}):null,m?null:W,e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open/provider:rotate-90"})]}),Re?e.jsxs("div",{className:"space-y-4 px-3 pb-4 pt-1 sm:pl-[3.25rem]",children:[we==="error"?e.jsxs("div",{role:"alert","data-connection-error":!0,className:"rounded-md border border-danger/30 bg-danger/5 px-3 py-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-danger",children:p(J!==void 0?"st.connections.testFailedTitle":"st.connections.errorTitle")}),e.jsx("p",{className:"mt-0.5 break-words text-[12px] leading-4 text-ink-soft",children:J!==void 0?J.error??p("st.connections.errorGeneric"):Te??p("st.connections.errorGeneric")}),e.jsx("p",{className:"mt-1 text-[12px] leading-4 text-ink-faint",children:p(ZT(J))})]}):null,we!=="setup"?e.jsxs("div",{"data-connection-health-test":!0,className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsxs("button",{type:"button","data-connection-test-button":!0,className:`${Q} inline-flex items-center gap-1.5`,disabled:re||$,"aria-busy":re,onClick:()=>void ke(),children:[re?e.jsx("span",{"aria-hidden":!0,className:"h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent motion-reduce:animate-none"}):null,p(re?"st.connections.testing":"st.connections.test")]}),e.jsx("p",{"data-connection-last-test":J===void 0?"none":J.ok?"ok":"error","aria-live":"polite",className:"min-w-0 text-[12px] leading-4 text-ink-faint",children:re?p("st.connections.testingHint"):J===void 0?p("st.connections.neverTested"):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:J.ok?"text-success":"text-danger",children:J.ok?p("st.connections.testOk"):p("st.connections.testFailed")})," · ",ye," · ",e.jsx("span",{className:"tabular-nums",children:b.formatDuration(J.duration_ms)}),J.model_id!==void 0?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"font-mono text-[11.5px]",children:J.model_id})]}):null]})})]}):null,o!==void 0?e.jsx(fT,{method:o,onChanged:i}):null,e.jsx("fieldset",{disabled:$,className:"min-w-0 disabled:opacity-60",children:e.jsx(iv,{draft:N,onChange:_,hasStoredKey:t.has_api_key,baselineApiKey:C.apiKey,baselineBaseUrl:C.baseUrl,baselineType:C.type,apiKeyEnv:t.api_key_env,revealKey:t.has_api_key||t.api_key_env!==void 0?O:void 0,managed:n,idLocked:!0,refreshProviderId:t.id,catalogModels:ie,modelProtocols:T,onModelProtocolsChange:A,onRefreshed:i,storedModels:c??null,decisionCapabilitiesExtra:e.jsx(js,{id:`provider-decisions-${t.id}`,label:p("st.decision.capabilities.title"),summary:p("st.decision.capabilities.summary"),defaultOpen:ba.some(Ae=>t.decision_capabilities?.[Ae]!==void 0),children:e.jsx(DT,{provider:t,onSaved:i})}),advancedExtra:e.jsxs(e.Fragment,{children:[e.jsx(rv,{scope:"provider",id:t.id,onSaved:i}),e.jsx(wT,{providerId:t.id,onSaved:i})]})})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Ye,disabled:$||F===null||!fe,onClick:()=>void ee(),children:p($?"common.saving":"st.providers.save")}),fe?e.jsx("span",{className:"text-[12px] text-ink-faint",children:p("st.tools.unsaved")}):null,e.jsx("span",{className:"ml-auto flex flex-wrap items-center gap-2",children:e.jsx("button",{type:"button","data-provider-remove":t.id,className:Ht,disabled:$,onClick:()=>{U("remove")},children:p("st.danger.removeProvider")})})]}),e.jsx(pe,{feedback:M})]}):null,e.jsx(Xe,{open:H==="remove",title:p("st.confirm.removeTitle",{id:r??t.id}),body:p(n?"st.providers.removeOAuthBody":"st.confirm.removeBody"),consequences:n?[o?.auth_source?.kind==="local_original"?p("st.providers.removeOAuthOriginalC1",{id:r??t.id}):Le?.connected?p("st.providers.removeOAuthSignedInC1",{id:r??t.id}):p("st.confirm.removeC1",{id:t.id}),p("st.providers.removeOAuthReaddC2")]:[p("st.confirm.removeC1",{id:t.id}),p("st.confirm.removeC2")],confirmLabel:p("st.confirm.removeAction"),busy:$,onConfirm:()=>{U(null),te()},onCancel:()=>{U(null)}})]})}const eI=["temperature","top_p","max_completion_tokens","thinking_effort","service_tier"];function tI(t,s){return(s?{temperature:"温度",top_p:"Top P",max_completion_tokens:"最大生成 token",thinking_effort:"思考模式 / 档位",service_tier:"服务档位"}:{temperature:"Temperature",top_p:"Top P",max_completion_tokens:"Max generated tokens",thinking_effort:"Thinking mode / effort",service_tier:"Service tier"})[t]}function sI(t,s){return t===void 0?"—":typeof t=="object"?s?"API 默认":"API default":String(t)}function rv({scope:t,id:s,onSaved:n,keys:a}){const i=a??eI,{client:r}=be(),{locale:o}=D(),l=o.startsWith("zh"),c=Oe(),d=je({queryKey:["generation-entity",t,s],queryFn:()=>t==="model"?r.getModel(s):r.getProviderEntity(s)}),u=d.data,p=u===void 0?void 0:t==="model"?u.parameters:u.defaults,h=u!==void 0&&"effective_parameters"in u?u.effective_parameters:void 0,b=u!==void 0&&"parameter_sources"in u?u.parameter_sources:void 0,m=u!==void 0&&"support_efforts"in u?u.support_efforts:void 0,f=u!==void 0&&"capabilities"in u?u.capabilities?.includes("always_thinking")===!0:!1,[g,v]=x.useState({}),[y,w]=x.useState({}),[N,_]=x.useState(""),[C,S]=x.useState(!1),[k,j]=x.useState(null),T=i.some(R=>JSON.stringify(g[R])!==JSON.stringify(y[R]));Ft(`generation:${t}:${s}`,T),x.useEffect(()=>{if(u===void 0||T||C||u.revision===N)return;const R=p??{};v(R),w(R),_(u.revision)},[u,p,T,C,N]);const A=(R,L)=>{v(I=>({...I,[R]:L})),j(null)},P=async()=>{const R={};for(const L of i)JSON.stringify(g[L])!==JSON.stringify(y[L])&&(R[L]=g[L]??null);if(Object.keys(R).length!==0){S(!0),j(null);try{if(t==="model"){if(i.includes("thinking_effort")&&g.thinking_effort==="off"&&f)throw new Error(l?"该模型声明强制思考,不能选择关闭。":"This model requires thinking; Off is unavailable.");await r.updateModel(s,{base_revision:N,parameters:R})}else{const L=await r.updateProvider(s,{base_revision:N,defaults:R});c.setQueryData(["provider-entity",s],L)}w(g),await Promise.all([d.refetch(),c.invalidateQueries({queryKey:["models"]}),c.invalidateQueries({queryKey:["providers"]}),c.invalidateQueries({queryKey:["model-entity"]})]),await n?.(),j({tone:"success",text:l?"已保存。下一次请求生效;角色上限仍可收紧。":"Saved for future requests; profile limits may still reduce the budget."})}catch(L){j({tone:"error",text:oe(o,L)})}finally{S(!1)}}};return d.isError?e.jsx(pe,{feedback:{tone:"error",text:oe(o,d.error)}}):u===void 0||N===""?e.jsx(he,{children:l?"正在读取参数…":"Loading parameters…"}):e.jsxs("div",{className:"space-y-3 rounded-lg border border-hairline bg-panel/50 p-3","data-generation-editor":`${t}:${s}`,children:[e.jsx("p",{className:"text-[11px] font-semibold text-ink-soft",children:t==="provider"?l?"供应商默认请求参数":"Provider request defaults":l?"此模型的请求参数":"Model request parameters"}),i.map(R=>{const L=g[R],I=L===void 0?"inherit":typeof L=="object"?"api_default":"custom",$=tI(R,l),E=R==="temperature"||R==="top_p"||R==="service_tier";return e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[9rem_8rem_minmax(0,1fr)] sm:items-center",children:[e.jsx("label",{className:"text-[11px] font-medium text-ink-soft",htmlFor:`${t}-${s}-${R}`,children:$}),e.jsx(Qe,{variant:"form",dataAttr:"data-param-mode",ariaLabel:`${$} ${l?"模式":"mode"}`,value:I,disabled:C,onChange:M=>{A(R,M==="inherit"?void 0:M==="api_default"?{kind:"api_default"}:R==="thinking_effort"?"on":R==="service_tier"?"auto":R==="max_completion_tokens"?8192:0)},choices:[{value:"inherit",label:l?"继承 / 未设置":"Inherit / unset"},{value:"custom",label:l?"自定义":"Custom"},...E?[{value:"api_default",label:l?"API 默认(不发送)":"API default (omit)"}]:[]]}),e.jsxs("div",{children:[I==="custom"&&R==="service_tier"?e.jsx(Qe,{id:`${t}-${s}-${R}`,variant:"form",mono:!0,dataAttr:"data-service-tier",ariaLabel:$,value:typeof L=="string"?L:"auto",disabled:C,onChange:M=>{A(R,M)},choices:["auto","default","flex","priority"].map(M=>({value:M,label:M}))}):I==="custom"&&R==="thinking_effort"?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Qe,{variant:"form",className:"w-auto",dataAttr:"data-thinking-choice",ariaLabel:l?"思考选择":"Thinking choice",value:L==="on"||L==="off"?L:"effort",disabled:C,onChange:M=>{A(R,M==="effort"?m?.[0]??"high":M)},choices:[{value:"on",label:l?"自动":"Auto"},...f?[]:[{value:"off",label:l?"关闭":"Off"}],{value:"effort",label:l?"指定档位":"Specific effort"}]}),L!=="on"&&L!=="off"?e.jsx("input",{id:`${t}-${s}-${R}`,className:pt,value:typeof L=="string"?L:"",disabled:C,list:m?.length?`${t}-${s}-efforts`:void 0,onChange:M=>{A(R,M.target.value)}}):null,m?.length?e.jsx("datalist",{id:`${t}-${s}-efforts`,children:m.map(M=>e.jsx("option",{value:M},M))}):null]}):I==="custom"?e.jsx("input",{id:`${t}-${s}-${R}`,className:pt,type:"number",min:R==="max_completion_tokens"?1:0,max:R==="top_p"?1:void 0,step:R==="max_completion_tokens"?1:"any",value:typeof L=="number"?L:0,disabled:C,onChange:M=>{A(R,Number(M.target.value))}}):null,t==="model"?e.jsxs("p",{className:"text-[11px] text-ink-faint",children:[l?"生效":"Effective",": ",sI(h?.[R],l)," · ",b?.[R]??(l?"适配器 / API 默认":"adapter / API default")]}):null]})]},R)}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:Ye,disabled:!T||C,onClick:()=>void P(),children:C?l?"保存中…":"Saving…":l?"保存参数":"Save parameters"}),T?e.jsx("button",{type:"button",className:Q,disabled:C,onClick:()=>{v(y),j(null)},children:l?"放弃修改":"Discard changes"}):null]}),e.jsx(pe,{feedback:k})]})}function nI({onSaved:t,onAccountChanged:s,onImported:n,initialMethod:a="api",initialDecisionPreset:i,configuredIds:r}){const{t:o,locale:l}=D(),{client:c}=be(),d=x.useMemo(QT,[]),[u,p]=x.useState(i===void 0?"template":"decision"),[h,b]=x.useState(i??"openai_decisions"),[m,f]=x.useState(d),[g,v]=x.useState(()=>kn(void 0,d.models.length)),[y,w]=x.useState(!1),[N,_]=x.useState(null),[C,S]=x.useState(null),k=u==="form"&&(Gf(m,d)||g.some(I=>I!=="inherit"));Ft("new-provider",k);const j=I=>{(C?.field==="id"&&I.id!==m.id||C?.field==="baseUrl"&&I.baseUrl!==m.baseUrl)&&S(null),f(I)},[T,A]=x.useState(null),P=(I,$)=>{const E=SN(I,$);A(I),f(E),v(kn(void 0,E.models.length)),_(null),S(null),p("form")},R=I=>{b(I),_(null),S(null),p("decision")},L=async()=>{const I={...m,defaultModel:m.defaultModel||(m.models[0]?.id??m.models[0]?.remoteId??"")},$=EN(I,{requireBaseUrl:TN(I.type)});if(S($),$!==null){_(null),document.getElementById($.field==="id"?"provider-field-id":"provider-field-base-url")?.focus();return}const E=Hj(I);if(E!==null){_({tone:"error",text:qs(l,E)});return}w(!0),_(null);try{const M=await c.createProvider(qT(zj(I),g));f(d),v(kn(void 0,d.models.length)),p("template"),await t(),_({tone:"success",text:o("st.providers.createdEcho",{id:M.id})})}catch(M){_({tone:"error",text:oe(l,M)})}finally{w(!1)}};return u==="template"?e.jsxs("div",{className:"space-y-3",children:[e.jsx(jT,{initialMethod:a,onPickApi:P,onPickDecision:R,onAccountChanged:s??t,onImported:n,configuredIds:r??new Set}),e.jsx(pe,{feedback:N})]}):u==="decision"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:e.jsxs("button",{type:"button",onClick:()=>{_(null),p("template")},className:"-ml-1 inline-flex h-7 items-center gap-1 rounded-md px-1 text-[12px] font-medium text-ink-soft transition-colors hover:text-ink",children:[e.jsx(de,{name:"arrowLeft",size:12}),o("st.wizard.back")]})}),e.jsx(RT,{initialPreset:h,configuredIds:r??new Set,onCancel:()=>{p("template")},onCreated:t},h)]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("button",{type:"button",onClick:()=>{f(d),v(kn(void 0,d.models.length)),_(null),S(null),p("template")},className:"-ml-1 inline-flex h-7 items-center gap-1 rounded-md px-1 text-[12px] font-medium text-ink-soft transition-colors hover:text-ink",children:[e.jsx(de,{name:"arrowLeft",size:12}),o("st.wizard.back")]}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:T===null?ra(m.type):`${T.label} · ${ra(T.type)}`})]}),T?.keyOptional===!0?e.jsx(he,{children:o("st.presets.localHint")}):null,T?.consoleUrl!==void 0?e.jsxs("p",{"data-preset-key-console":!0,className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint",children:[o("st.presets.keyConsole",{url:T.consoleUrl.replace(/^https?:\/\//,"")})," ",e.jsxs("a",{href:T.consoleUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-0.5 text-accent-ink hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsx(de,{name:"external",size:12}),T.label]})]}):null,e.jsx(iv,{draft:m,onChange:j,hasStoredKey:!1,fieldIssue:C,modelProtocols:g,onModelProtocolsChange:v}),e.jsx("button",{type:"button",className:Ye,disabled:y,onClick:()=>void L(),children:o(y?"st.providers.creating":"st.providers.create")}),e.jsx(pe,{feedback:N})]})}function aI(t,s,n){return Math.min(t,s??t,n??t)}function ov(t){let s=t.overrides;if(typeof s=="string")try{s=s.trim()===""?void 0:JSON.parse(s)}catch{return{valid:!1}}if(s!==void 0&&(s===null||typeof s!="object"||Array.isArray(s)))return{valid:!1};const n={};for(const[l,c]of Object.entries(s??{}))n[l.replaceAll(/_([a-z])/g,(d,u)=>u.toUpperCase())]=c;for(const l of["maxContextSize","maxInputSize","contextBudget","autoCompact"]){const c=n[l];if(c!==void 0&&(typeof c!="number"||!Number.isSafeInteger(c)||c<=0))return{valid:!1}}const a=n.maxContextSize??t.windowTokens,i=n.maxInputSize??t.inputTokens,r=n.contextBudget??t.contextBudget,o=n.autoCompact??t.autoCompact;return{valid:!0,windowTokens:a,inputTokens:i,contextBudget:r,usableTokens:aI(a,i,r),autoCompact:o,autoCompactOverridden:n.autoCompact!==void 0}}function vu(t,s=5e4){const n=t-s,a=Math.min(n,64e3);return{floor:a,ceil:n,locked:t<=0||n<=a}}function yu(t){if(t===null||typeof t!="object"||Array.isArray(t))return{};const s=t,n=(l,c)=>s[l]??s[c],a=n("autoCompact","auto_compact"),i=n("compactionTriggerRatio","compaction_trigger_ratio"),r=n("compactionSoftContextSize","compaction_soft_context_size"),o=n("reservedContextSize","reserved_context_size");return{autoCompact:typeof a=="string"?a:void 0,compactionTriggerRatio:typeof i=="number"?i:void 0,compactionSoftContextSize:typeof r=="number"&&r>0?r:void 0,reservedContextSize:typeof o=="number"?o:void 0}}function lv(t,s,n){const{ceil:a,floor:i}=vu(t,n);return Math.max(i,Math.min(s,a))}function iI(t){const s=/^(\d+(?:\.\d+)?)%$/.exec(t.trim());if(s===null)return t;const n=Math.round(Number(s[1])*10)/10;return`${Number.isInteger(n)?n.toFixed(0):n.toFixed(1)}%`}function ku(t,s){if(t<=0)return{tokens:0,from:"legacy"};const n=s.reservedContextSize??5e4;if(s.autoCompact!==void 0){const i=Number(s.autoCompact.replace("%",""));return{tokens:lv(t,Math.round(t*i/100),n),from:"global",percent:iI(s.autoCompact)}}let a=t*(s.compactionTriggerRatio??.85);return n>0&&n<t&&(a=Math.min(a,t-n)),s.compactionSoftContextSize!==void 0&&(a=Math.min(a,s.compactionSoftContextSize)),{tokens:a,from:"legacy"}}function cv(t,s,n){return t<=0?0:s===void 0?ku(t,n).tokens:lv(t,s,n.reservedContextSize??5e4)}const rI="repeating-linear-gradient(135deg, var(--color-hairline-strong) 0 1.5px, transparent 1.5px 4px)";function dv({label:t,dataAttribute:s,usable:n,bounds:a,reserved:i,value:r,title:o,reason:l,pinned:c=!1,onChange:d}){const{t:u}=D(),p=x.useId(),h=a!==void 0&&Number.isFinite(n)&&n>0&&Number.isFinite(a.ceil)&&a.ceil>0?a:void 0,b=h!==void 0&&!h.locked&&!c,m=r!==void 0&&Number.isFinite(r)&&r>=0?r:void 0,f=h===void 0?void 0:Math.min(h.ceil,Math.max(h.floor,m??h.floor)),g=w=>`${Math.min(100,Math.max(0,w/n*100))}%`,v=m===void 0||h===void 0?"":PN(m,n),y=Math.max(Fa,Math.round(n*.05/Fa)*Fa);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2","data-compact-track":s,children:[e.jsxs("div",{className:"relative h-6 min-w-0 flex-1 pointer-coarse:h-11",children:[e.jsx("div",{"aria-hidden":!0,className:"absolute inset-x-0 top-1/2 h-1.5 -translate-y-1/2 overflow-hidden rounded-full bg-hairline",children:h===void 0||f===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-ink/[0.06]",style:{width:g(h.floor)}}),e.jsx("div",{"data-compact-track-fill":!0,className:"absolute inset-y-0 left-0 bg-ink/[0.12]",style:{width:g(f)}}),e.jsx("div",{"data-compact-track-reserve":!0,className:"absolute inset-y-0 right-0 bg-canvas",style:{width:g(i),backgroundImage:rI}})]})}),h===void 0||f===void 0?null:e.jsx("input",{type:"range","data-compact-slider":!0,"aria-label":t,"aria-valuetext":u("st.compact.trackValue",{tokens:ft(f),limit:ft(n)}),"aria-describedby":b?void 0:p,min:h.floor,max:h.ceil,step:1,value:f,disabled:!b,onChange:w=>{d(AN(Number(w.target.value),h))},onKeyDown:w=>{let N;w.key==="PageUp"&&(N=f+y),w.key==="PageDown"&&(N=f-y),(w.key==="ArrowRight"||w.key==="ArrowUp")&&(N=f+Fa),(w.key==="ArrowLeft"||w.key==="ArrowDown")&&(N=f-Fa),w.key==="Home"&&(N=h.floor),w.key==="End"&&(N=h.ceil),N!==void 0&&(w.preventDefault(),d(Math.min(h.ceil,Math.max(h.floor,N))))},className:"peer absolute inset-y-0 z-10 m-0 cursor-ew-resize appearance-none bg-transparent opacity-0 disabled:cursor-default [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:appearance-none",style:{left:`calc(${g(h.floor)} - 8px)`,width:`calc(${g(h.ceil-h.floor)} + 16px)`}}),f===void 0?null:e.jsx("span",{"aria-hidden":!0,"data-compact-thumb":!0,className:`pointer-events-none absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2 ring-paper transition-shadow duration-[var(--kiki-motion-quick)] peer-hover:shadow-[0_0_0_4px_rgb(var(--kiki-shadow-ink)/0.08)] peer-focus-visible:shadow-[0_0_0_3px_var(--color-paper),0_0_0_5px_var(--color-selected-ink)] ${b?"bg-ink":"bg-ink-faint"}`,style:{left:g(f)}})]}),e.jsxs("span",{"data-compact-track-value":!0,title:o,className:`flex shrink-0 items-baseline gap-1 font-mono text-[12px] tabular-nums ${m===void 0?"text-ink-faint":r===void 0?"text-ink-soft":"text-ink"}`,children:[e.jsx("span",{children:m===void 0?"—":ft(m)}),v===""?null:e.jsx("span",{className:"text-ink-faint",children:v})]})]}),b?null:e.jsx("p",{id:p,"data-compact-track-reason":!0,className:"text-[12px] leading-4 text-ink-faint",children:l})]})}function oI({modelId:t,windowTokens:s,inputTokens:n,contextBudget:a,overrides:i,onWindowChange:r,autoCompact:o,onAutoCompactChange:l,loopControl:c,hideCompaction:d=!1}){const{t:u}=D(),p=yu(c),h=p.reservedContextSize??5e4,b=ov({windowTokens:s,inputTokens:n,contextBudget:a,autoCompact:o,overrides:i}),m=b.valid?b.usableTokens:0,f=b.valid?vu(m,h):void 0,g=b.valid&&m>0?ku(m,p):void 0,v=g!==void 0&&Number.isFinite(g.tokens)&&g.tokens>0?g.tokens:void 0,y=g===void 0||v===void 0?"":g.from==="global"?u("st.compact.inheritGlobal",{tokens:ft(v),percent:g.percent??""}):u("st.compact.inheritLegacy",{tokens:ft(v)}),w=b.valid&&b.autoCompactOverridden&&b.autoCompact!==void 0,N=b.valid&&m>0?cv(m,w?b.autoCompact:o,p):void 0,_=N!==void 0&&Number.isFinite(N)&&N>0?N:void 0,C=!w&&o!==void 0&&f!==void 0&&o>f.ceil,S=f===void 0||f.locked,k=b.valid?w?u("st.compact.trackOverridden"):m<=0?u("st.compact.trackNeedsWindow"):u("st.compact.trackLocked"):u("st.compact.trackOverridesInvalid"),j=w?u("st.compact.trackOverridden"):o===void 0?y:C?u("st.compact.pointClampHint",{tokens:ft(f?.ceil??0)}):ft(_??o);return e.jsxs("div",{"data-model-context-fields":!0,className:"space-y-3 pt-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:u("st.compact.windowLabel")}),e.jsx(fu,{value:s,onChange:r,ariaLabel:u("st.models.contextAria",{model:t})}),e.jsx("div",{className:"-ml-2",children:e.jsx(jb,{dataAttribute:`window:${t}`,label:u("st.compact.windowPresets"),values:$N,current:s,onPick:r})}),n!==void 0&&b.valid?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint",children:u("st.compact.windowInputHint",{tokens:ft(m)})}):null]}),d===!0?null:e.jsxs("div",{children:[e.jsx(ru,{dataAttribute:`model:${t}`,label:u("st.compact.pointLabel"),value:o,onChange:l,windowTokens:m,placeholder:y,presets:f===void 0?void 0:$b(m,f.ceil,f.floor),presetsLabel:u("context.compact.presetsLabel"),hint:S?void 0:C?u("st.compact.pointClampHint",{tokens:ft(f.ceil)}):u("st.compact.pointHint")}),e.jsx(dv,{label:u("st.compact.trackLabel"),dataAttribute:`model:${t}`,usable:m,bounds:f,reserved:h,value:_,title:j,reason:k,pinned:w,onChange:l})]})]})}const lI=/^(?:100(?:\.0+)?|[1-9]?\d(?:\.\d+)?)$/;function cI(t){const{t:s}=D(),n=yu(t.loopControl),a=n.reservedContextSize??5e4,i=ov({windowTokens:t.windowTokens,inputTokens:t.inputTokens,contextBudget:t.contextBudget,autoCompact:t.autoCompact,overrides:t.overrides}),r=i.valid?i.usableTokens:0,o=i.valid?vu(r,a):void 0,l=i.valid&&r>0?ku(r,n):void 0,c=l!==void 0&&Number.isFinite(l.tokens)&&l.tokens>0?l.tokens:void 0,d=l===void 0||c===void 0?"":l.from==="global"?s("st.compact.inheritGlobal",{tokens:ft(c),percent:l.percent??""}):s("st.compact.inheritLegacy",{tokens:ft(c)}),u=i.valid&&i.autoCompactOverridden&&i.autoCompact!==void 0,p=i.valid&&r>0?cv(r,u?i.autoCompact:t.autoCompact,n):void 0,h=p!==void 0&&Number.isFinite(p)&&p>0?p:void 0,b=!u&&t.autoCompact!==void 0&&o!==void 0&&t.autoCompact>o.ceil,m=o===void 0||o.locked;return{usable:r,reserved:a,bounds:o,inheritedTokens:c,inheritedLabel:d,overridden:u,trackValue:h,trackTitle:u?s("st.compact.trackOverridden"):t.autoCompact===void 0?d:b?s("st.compact.pointClampHint",{tokens:ft(o?.ceil??0)}):ft(h??t.autoCompact),trackReason:i.valid?u?s("st.compact.trackOverridden"):r<=0?s("st.compact.trackNeedsWindow"):s("st.compact.trackLocked"):s("st.compact.trackOverridesInvalid"),overCeil:b,presets:o===void 0?void 0:$b(r,o.ceil,o.floor),presetsLabel:s("context.compact.presetsLabel"),hint:m?void 0:b?s("st.compact.pointClampHint",{tokens:ft(o.ceil)}):s("st.compact.pointHint")}}function dI(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=Je(),o=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),l=o.data?.loop_control,c=yu(l),d=c.compactionTriggerRatio,u=c.autoCompact?.replace("%",""),p=u!==void 0?IN(c.autoCompact).replace("%",""):String(Math.round((d??.85)*100)),[h,b]=x.useState(p),[m,f]=x.useState(""),[g,v]=x.useState(!1),[y,w]=x.useState(null);x.useEffect(()=>{b(p)},[p]),x.useEffect(()=>{f(c.reservedContextSize===void 0?"":ft(c.reservedContextSize))},[c.reservedContextSize]);const N=async j=>{v(!0),w(null);try{const T=await t.patchConfig({loop_control:j,replace_domains:["loop_control"]});a.setQueryData(["config"],T),a.invalidateQueries({queryKey:["autoCompact"]}),r()}catch(T){w({tone:"error",text:oe(n,T)})}finally{v(!1)}},_=()=>{const j=l!==null&&typeof l=="object"&&!Array.isArray(l)?{...l}:{};for(const T of["compactionTriggerRatio","compaction_trigger_ratio","compactionSoftContextSize","compaction_soft_context_size","autoCompact","auto_compact"])delete j[T];return j},C=()=>{const j=h.trim().replace("%","");if(!lI.test(j)||Number(j)<=0){w({tone:"error",text:s("st.compact.globalInvalid")}),b(p);return}u!==void 0&&Number(j)===Number(u)||N({..._(),autoCompact:`${j}%`})},S=()=>{const j=m.trim().toLowerCase(),T=c.reservedContextSize;if(j===""){if(T===void 0)return;const L={...l};delete L.reservedContextSize,delete L.reserved_context_size,N(L);return}const A=/^(\d+(?:\.\d+)?)(k)?$/.exec(j.replaceAll(",","")),P=A===null?NaN:Math.round(Number(A[1])*(A[2]==="k"?1e3:1));if(!Number.isSafeInteger(P)||P<0){w({tone:"error",text:s("st.compact.inputInvalid")});return}if(P===T)return;const R={...l!==null&&typeof l=="object"?l:{}};delete R.reserved_context_size,N({...R,reservedContextSize:P})},k=u===void 0&&(d!==void 0||c.compactionSoftContextSize!==void 0);return e.jsx(Me,{id:"st-card-auto-compact",title:s("st.compact.globalTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ze,{children:e.jsxs(ge,{label:s("st.compact.globalLabel"),htmlFor:"st-auto-compact-percent",help:k?s("st.compact.globalLegacyHint",{percent:String(Math.round((d??.85)*100))}):s("st.compact.globalHint"),children:[e.jsx(jt,{show:i}),e.jsx("input",{id:"st-auto-compact-percent","data-global-auto-compact":!0,inputMode:"decimal",className:`${pt} h-8 w-20 text-right font-mono tabular-nums`,value:h,disabled:g||o.data===void 0,onChange:j=>{b(j.target.value)},onBlur:C,onKeyDown:j=>{j.key==="Enter"&&!rt(j)&&(j.preventDefault(),C())}}),e.jsx("span",{"aria-hidden":!0,className:"text-[12px] text-ink-faint",children:"%"})]})}),e.jsx(et,{summary:s("st.compact.advanced"),"data-auto-compact-advanced":!0,children:e.jsx(Ze,{children:e.jsxs(ge,{label:s("st.compact.reserveLabel"),htmlFor:"st-auto-compact-reserve",help:s("st.compact.reserveHint"),children:[e.jsx("input",{id:"st-auto-compact-reserve",inputMode:"decimal",className:`${pt} h-8 w-24 text-right font-mono tabular-nums`,value:m,placeholder:"50k",disabled:g||o.data===void 0,onChange:j=>{f(j.target.value)},onBlur:S,onKeyDown:j=>{j.key==="Enter"&&!rt(j)&&(j.preventDefault(),S())}}),e.jsx("span",{"aria-hidden":!0,className:"text-[12px] text-ink-faint",children:"tokens"})]})})}),o.isError?e.jsx(De,{error:o.error}):null,e.jsx(pe,{feedback:y})]})})}function uI(t){if(t===null||typeof t!="object"||Array.isArray(t))return{};const s=t,n=(o,l)=>s[o]??s[l],a=n("maxStepsPerTurn","max_steps_per_turn"),i=n("maxAttemptsPerStep","max_attempts_per_step"),r=n("subagentContextStrategy","subagent_context_strategy");return{maxSteps:typeof a=="number"?a:void 0,maxAttempts:typeof i=="number"?i:void 0,subagentStrategy:r==="summarize"||r==="auto"||r==="fresh"?r:void 0}}const pI=/^\d+$/;function mI(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=bt(),i=bt(),r=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4});if(r.data===void 0)return e.jsx(Me,{id:"st-card-loop-limits",title:s("st.loopLimits.title"),children:r.isError?e.jsx(De,{error:r.error}):e.jsx(he,{children:s("st.runtime.loading")})});const o=uI(r.data.loop_control),l=d=>async()=>{const u=await t.patchConfig({loop_control:d});n.setQueryData(["config"],u)},c=d=>d===""||pI.test(d)?null:s("st.loopLimits.wholeNumber");return e.jsx(Me,{id:"st-card-loop-limits",title:s("st.loopLimits.title"),effect:"newSessions",children:e.jsxs(Ze,{children:[e.jsxs(ge,{label:s("st.loopLimits.maxSteps"),help:s("st.loopLimits.maxStepsHelp"),children:[e.jsx(ot,{saving:a.saving,saved:a.saved}),e.jsx(kt,{ariaLabel:s("st.loopLimits.maxSteps"),dataAttr:"data-loop-max-steps",className:"w-24",inputMode:"numeric",placeholder:s("st.loopLimits.unlimited"),value:o.maxSteps===void 0||o.maxSteps===0?"":String(o.maxSteps),validate:c,disabled:a.saving,onCommit:d=>void a.run(l({max_steps_per_turn:d===""?0:Number(d)}))})]}),e.jsx(pe,{feedback:a.error}),e.jsxs(ge,{label:s("st.loopLimits.subagentStrategy"),help:s("st.loopLimits.subagentStrategyHelp"),children:[e.jsx(ot,{saving:i.saving,saved:i.saved}),e.jsx(Qe,{id:"loop-subagent-strategy",ariaLabel:s("st.loopLimits.subagentStrategy"),dataAttr:"data-loop-subagent-strategy",value:o.subagentStrategy??"summarize",disabled:i.saving,choices:["summarize","auto","fresh"].map(d=>({value:d,label:s(`context.strategy.option.${d}`),hint:s(`context.strategy.hint.${d}`)})),onChange:d=>void i.run(l({subagent_context_strategy:d}))})]}),e.jsx(pe,{feedback:i.error})]})})}let uv=0;function mr(t){return typeof t=="number"?String(t):""}function Sx(t){return typeof t=="number"&&Number.isInteger(t)&&t>=1?t:void 0}function Cx(t){if(!Array.isArray(t))return;const s=t.filter(n=>typeof n=="string");return s.length===t.length?s:void 0}function Ll(t){const s=t.retry??{},n=Array.isArray(s.policies)?s.policies:[],a=s.retryPartialResponses??s.retry_partial_responses;return{maxAttempts:mr(s.maxAttempts??s.max_attempts),maxRetryAfterMs:Sx(s.maxRetryAfterMs??s.max_retry_after_ms),retryPartialResponses:typeof a=="boolean"?a:!0,policies:n.map(i=>({id:++uv,match:typeof i.match=="string"?i.match:"",models:Cx(i.models),providers:Cx(i.providers),maxAttempts:mr(i.maxAttempts??i.max_attempts),backoff:mr(i.backoff),maxRetryAfterMs:Sx(i.maxRetryAfterMs??i.max_retry_after_ms),retry:i.retry!==!1}))}}function xI(t){const s=t.loop_control??{};return mr(s.maxAttemptsPerStep??s.max_attempts_per_step)}function hI(t,s){const n=(o,l,c)=>{if(o.trim()==="")return;const d=Number(o.trim());return!Number.isInteger(d)||d<l?{key:c,text:s(l===0?"st.retry.issueBackoff":"st.retry.issueAttempts")}:d},a=o=>typeof o=="object"&&o!==null,i=n(t.maxAttempts,1,"max");if(a(i))return{issue:i};const r=[];for(const o of t.policies){const l=o.match.trim();if(l==="")return{issue:{key:`match-${o.id}`,text:s("st.retry.issueMatch")}};try{new RegExp(l)}catch{return{issue:{key:`match-${o.id}`,text:s("st.retry.issuePattern")}}}const c=n(o.maxAttempts,1,`attempts-${o.id}`);if(a(c))return{issue:c};const d=n(o.backoff,0,`backoff-${o.id}`);if(a(d))return{issue:d};r.push({match:l,models:o.models,providers:o.providers,...c===void 0?{}:{max_attempts:c},...d===void 0?{}:{backoff:d},...o.maxRetryAfterMs===void 0?{}:{max_retry_after_ms:o.maxRetryAfterMs},retry:o.retry})}return{patch:{retry:{...i===void 0?{}:{max_attempts:i},...t.maxRetryAfterMs===void 0?{}:{max_retry_after_ms:t.maxRetryAfterMs},retry_partial_responses:t.retryPartialResponses,...r.length===0?{}:{policies:r}},replace_domains:["retry"]}}}function Ml({children:t}){return e.jsx("span",{className:"text-[12px] text-ink-faint",children:t})}function fI(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),[r,o]=x.useState(null),[l,c]=x.useState(!1),[d,u]=x.useState(!1),[p,h]=x.useState(null),[b,m]=x.useState(null),[f,g]=Je(),v=x.useRef(null);if(x.useEffect(()=>{i.data!==void 0&&!l&&o(Ll(i.data))},[i.data,l]),x.useEffect(()=>{v.current!==null&&(document.getElementById(`retry-match-${v.current}`)?.focus(),v.current=null)}),r===null||i.data===void 0)return e.jsx(Me,{id:"st-card-retry",title:s("st.retry.title"),children:i.isError?e.jsx(De,{error:i.error}):e.jsx(he,{children:s("st.runtime.loading")})});const y=xI(i.data),w=j=>{o(j),c(!0),h(null)},N=(j,T)=>{w({...r,policies:r.policies.map(A=>A.id===j?{...A,...T}:A)})},_=(j,T)=>{const A=[...r.policies],[P]=A.splice(j,1);A.splice(j+T,0,P),w({...r,policies:A})},C=async()=>{const j=hI(r,s);if(j.patch===void 0){h(j.issue??null);return}u(!0),m(null);try{const T=await t.patchConfig(j.patch);a.setQueryData(["config"],T),o(Ll(T)),c(!1),g()}catch(T){m({tone:"error",text:oe(n,T)})}finally{u(!1)}},S=j=>p?.key===j?p.text:null,k=(j,T="w-20",A="text-right")=>`h-8 ${T} rounded-md border border-hairline bg-paper px-2 ${A} font-mono text-[12.5px] text-ink outline-none transition-colors hover:border-hairline-strong focus:border-selected-ink disabled:opacity-60 ${p?.key===j?"border-danger":""}`;return e.jsx(Me,{id:"st-card-retry",title:s("st.retry.title"),effect:"newSessions",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{children:s("st.retry.hint")}),e.jsxs("fieldset",{disabled:d,className:"min-w-0 space-y-4 disabled:opacity-60",children:[e.jsxs(Ze,{children:[e.jsx(ge,{label:s("st.retry.maxAttempts"),htmlFor:"retry-max-attempts",help:s("st.retry.maxAttemptsHelp"),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{id:"retry-max-attempts",className:k("max"),inputMode:"numeric",placeholder:y===""?"5":y,value:r.maxAttempts,"aria-invalid":p?.key==="max",onChange:j=>{w({...r,maxAttempts:j.target.value})}}),e.jsx(Ml,{children:s("st.retry.attemptsUnit")})]})}),e.jsx("div",{"data-retry-partial-responses":!0,children:e.jsx(ge,{label:s("st.retry.partialResponses"),help:s("st.retry.partialResponsesHint"),children:e.jsx(Be,{layout:"bare",label:s("st.retry.partialResponses"),checked:r.retryPartialResponses,onChange:j=>{w({...r,retryPartialResponses:j})}})})})]}),S("max")!==null?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:S("max")}):null,e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:$e,children:s("st.retry.policies")}),e.jsx("button",{type:"button",className:Q,onClick:()=>{const j=++uv;v.current=j,w({...r,policies:[...r.policies,{id:j,match:"",maxAttempts:"",backoff:"",retry:!0}]})},children:s("st.retry.addPolicy")})]}),r.policies.length===0?e.jsx(he,{children:s("st.retry.empty")}):null,e.jsx("ol",{"data-retry-policies":!0,className:"divide-y divide-hairline rounded-lg border border-hairline [&>:empty]:hidden",children:r.policies.map((j,T)=>e.jsxs("li",{"data-retry-policy":T,className:"space-y-1 px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Be,{layout:"row",label:s("st.retry.policyEnabled"),checked:j.retry,onChange:A=>{N(j.id,{retry:A})}}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",className:Q,disabled:T===0,"aria-label":s("st.retry.moveUp",{n:T+1}),onClick:()=>{_(T,-1)},children:e.jsx(de,{name:"arrowUp",size:14})}),e.jsx("button",{type:"button",className:Q,disabled:T===r.policies.length-1,"aria-label":s("st.retry.moveDown",{n:T+1}),onClick:()=>{_(T,1)},children:e.jsx(de,{name:"arrowDown",size:14})}),e.jsx("button",{type:"button",className:Q,"aria-label":s("st.retry.removePolicy",{n:T+1}),onClick:()=>{w({...r,policies:r.policies.filter(A=>A.id!==j.id)})},children:e.jsx(de,{name:"close",size:14})})]})]}),e.jsx(ge,{label:s("st.retry.match"),htmlFor:`retry-match-${j.id}`,children:e.jsx("input",{id:`retry-match-${j.id}`,className:k(`match-${j.id}`,"w-full max-w-64","text-left"),value:j.match,placeholder:"^provider\\.rate_limit$","aria-invalid":p?.key===`match-${j.id}`,onChange:A=>{N(j.id,{match:A.target.value})}})}),e.jsx(ge,{label:s("st.retry.policyAttempts"),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{className:k(`attempts-${j.id}`),inputMode:"numeric",value:j.maxAttempts,"aria-label":s("st.retry.policyAttempts"),"aria-invalid":p?.key===`attempts-${j.id}`,onChange:A=>{N(j.id,{maxAttempts:A.target.value})}}),e.jsx(Ml,{children:s("st.retry.attemptsUnit")})]})}),e.jsx(ge,{label:s("st.retry.backoff"),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{className:k(`backoff-${j.id}`),inputMode:"numeric",value:j.backoff,"aria-label":s("st.retry.backoff"),"aria-invalid":p?.key===`backoff-${j.id}`,onChange:A=>{N(j.id,{backoff:A.target.value})}}),e.jsx(Ml,{children:s("st.residency.msUnit")})]})}),[`match-${j.id}`,`attempts-${j.id}`,`backoff-${j.id}`].map(A=>S(A)!==null?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:S(A)},A):null)]},j.id))})]})]}),e.jsx(lt,{saved:f,id:"retry",dirty:l,saving:d,onSave:()=>void C(),onDiscard:()=>{i.data!==void 0&&o(Ll(i.data)),c(!1),h(null),m(null)}}),e.jsx(pe,{feedback:b})]})})}const _x=["direct","compact","fresh"],Ol={direct:"st.modelSwitch.mode.direct",compact:"st.modelSwitch.mode.compact",fresh:"st.modelSwitch.mode.fresh"};function bI(t){return t.confirm===void 0?"inherit":t.confirm?"ask":"skip"}function en(t){return t===void 0?"":t.join(", ")}function sa(t){const s=t.split(/[,,]/u).map(n=>n.trim()).filter(n=>n!=="");return s.length===0?void 0:s}function gI(t,s){return t.length!==s.length?!1:t.every((n,a)=>{const i=s[a];return n.id===i.id&&n.enabled===i.enabled&&n.mode===i.mode&&n.confirm===i.confirm&&en(n.fromModels)===en(i.fromModels)&&en(n.toModels)===en(i.toModels)})}function Ex(t){return{id:t.id,from:en(t.fromModels),to:en(t.toModels),mode:t.mode,ask:bI(t),enabled:t.enabled}}function Tx(t){return{id:t.id,enabled:t.enabled,fromModels:sa(t.from),toModels:sa(t.to),mode:t.mode,confirm:t.ask==="inherit"?void 0:t.ask==="ask"}}function Ix(t){return(t??[]).some(s=>/[\s[\]{}"'\\]/u.test(s)||s==="")}function vI(){const{t,locale:s}=D(),{client:n}=be(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>n.getConfig(),staleTime:6e4}),r=je({queryKey:["models"],queryFn:()=>n.listModels(),staleTime:6e4}),o=x.useMemo(()=>RN(i.data?.model_switch),[i.data]),[l,c]=x.useState(o.rules),[d,u]=x.useState(o.rules),[p,h]=x.useState(void 0),[b,m]=x.useState(void 0),[f,g]=x.useState(null),[v,y]=x.useState(!1),w=!gI(l,d),N=x.useRef(w);N.current=w,x.useEffect(()=>{N.current||(c(o.rules),u(o.rules))},[o.rules]);const _=x.useCallback(async E=>{const M=await n.patchConfig({model_switch:E});a.setQueryData(["config"],M)},[n,a]),C=E=>{g(null),_({default_mode:E}).then(()=>{g({tone:"info",text:t("st.modelSwitch.saved")})}).catch(M=>{g({tone:"error",text:oe(s,M)})})},S=E=>{g(null),_({confirm:E}).then(()=>{g({tone:"info",text:t("st.modelSwitch.saved")})}).catch(M=>{g({tone:"error",text:oe(s,M)})})},k=async()=>{y(!0),g(null);try{await _({rules:MN({...o,rules:l}).rules}),u(l),m(void 0)}catch(E){g({tone:"error",text:oe(s,E)})}finally{y(!1)}},j=E=>{const M=l.find(z=>z.id===E);M!==void 0&&(h(E),m(Ex(M)))},T=E=>{m(E),c(M=>M.map(z=>z.id===E.id?Tx(E):z))},A=()=>{const E=`rule-${Vj().slice(0,8)}`,M=Tx({id:E,from:"",to:"",mode:o.defaultMode,ask:"inherit",enabled:!0});c(z=>[...z,M]),h(E),m(Ex(M))},P=E=>{c(M=>M.filter(z=>z.id!==E)),p===E&&(h(void 0),m(void 0))},R=(E,M)=>{const z=E+M;c(H=>{if(z<0||z>=H.length)return H;const U=[...H],[X]=U.splice(E,1);return U.splice(z,0,X),U})},L=r.data?.items,I=E=>{if(E===void 0)return t("st.modelSwitch.ruleAny");if(L===void 0)return;const M=L.filter(H=>E.some(U=>LN(U,H.id)));if(M.length===0)return t("st.modelSwitch.previewNone");const z=M.slice(0,4).map(H=>H.id).join(", ");return M.length>4?`${z} +${M.length-4}`:z},$="flex min-h-8 items-center gap-2 rounded-md px-1.5 text-left text-[12px] transition-colors";return e.jsx(Me,{id:"st-card-model-switch",title:t("st.modelSwitch.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Ze,{children:[e.jsx(ge,{label:t("st.modelSwitch.defaultMode"),help:t("st.modelSwitch.defaultModeHint"),children:e.jsx(He,{ariaLabel:t("st.modelSwitch.defaultMode"),value:o.defaultMode,dataAttr:"data-model-switch-default-mode",choices:_x.map(E=>({value:E,label:t(Ol[E])})),onChange:E=>{C(E)}})}),e.jsx(ge,{label:t("st.modelSwitch.confirm"),help:t("st.modelSwitch.confirmHint"),children:e.jsx(Be,{layout:"bare",label:t("st.modelSwitch.confirm"),checked:o.confirm,onChange:E=>{S(E)}})})]}),e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:t("st.modelSwitch.rulesTitle")}),e.jsx("button",{type:"button","data-model-switch-rule-add":!0,className:`${Q} h-7 px-2 text-[12px]`,onClick:A,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),t("st.modelSwitch.ruleAdd")]})})]}),e.jsx("p",{className:"mt-1 text-[12px] leading-snug text-ink-faint",children:t("st.modelSwitch.rulesHint")}),l.length===0?e.jsx("p",{"data-model-switch-rules-empty":!0,className:"mt-2 text-[12px] text-ink-faint",children:t("st.modelSwitch.ruleEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-0.5","data-model-switch-rules":!0,children:l.map((E,M)=>{const z=E.id===p,H=`${E.fromModels===void 0?t("st.modelSwitch.ruleAny"):en(E.fromModels)} → ${E.toModels===void 0?t("st.modelSwitch.ruleAny"):en(E.toModels)}`;return e.jsxs("li",{"data-model-switch-rule":E.id,className:`${$} ${z?"bg-ink/[0.05]":"hover:bg-ink/[0.03]"}`,children:[e.jsx("button",{type:"button","data-model-switch-rule-open":E.id,onClick:()=>{j(E.id)},className:"min-w-0 flex-1 truncate text-left text-ink",title:H,children:e.jsx("span",{className:E.enabled?void 0:"text-ink-faint line-through",children:H})}),e.jsx("span",{className:"shrink-0 text-ink-faint",children:t(Ol[E.mode])}),e.jsx("span",{className:"shrink-0 text-ink-faint",children:E.confirm===void 0?t("st.modelSwitch.ask.inherit"):E.confirm?t("st.modelSwitch.ask.ask"):t("st.modelSwitch.ask.skip")}),e.jsxs("span",{className:"flex shrink-0 items-center",children:[e.jsx("button",{type:"button","aria-label":t("st.modelSwitch.ruleMoveUp"),disabled:M===0,onClick:()=>{R(M,-1)},className:"h-6 w-6 rounded text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink disabled:opacity-30 focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none",children:e.jsx(de,{name:"arrowUp",size:12,className:"mx-auto"})}),e.jsx("button",{type:"button","aria-label":t("st.modelSwitch.ruleMoveDown"),disabled:M===l.length-1,onClick:()=>{R(M,1)},className:"h-6 w-6 rounded text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink disabled:opacity-30 focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none",children:e.jsx(de,{name:"arrowDown",size:12,className:"mx-auto"})}),e.jsx("button",{type:"button","data-model-switch-rule-remove":E.id,"aria-label":t("st.modelSwitch.ruleDelete"),onClick:()=>{P(E.id)},className:"h-6 w-6 rounded text-ink-faint transition-colors hover:bg-danger/10 hover:text-danger focus-visible:ring-2 focus-visible:ring-danger/40 focus-visible:outline-none",children:e.jsx(de,{name:"close",size:12,className:"mx-auto"})})]})]},E.id)})}),b!==void 0?e.jsxs("div",{"data-model-switch-rule-editor":b.id,className:"mt-3 space-y-3 pt-3",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("label",{className:"min-w-40 flex-1",children:[e.jsx("span",{className:$e,children:t("st.modelSwitch.ruleFrom")}),e.jsx("input",{type:"text",value:b.from,placeholder:t("st.modelSwitch.ruleAny"),onChange:E=>{T({...b,from:E.target.value})},className:`${Ce} mt-1 h-7 text-[12px]`})]}),e.jsxs("label",{className:"min-w-40 flex-1",children:[e.jsx("span",{className:$e,children:t("st.modelSwitch.ruleTo")}),e.jsx("input",{type:"text",value:b.to,placeholder:t("st.modelSwitch.ruleAny"),onChange:E=>{T({...b,to:E.target.value})},className:`${Ce} mt-1 h-7 text-[12px]`})]})]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:t("st.modelSwitch.rulePatternsHint")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:$e,children:t("st.modelSwitch.ruleMode")}),e.jsx(He,{ariaLabel:t("st.modelSwitch.ruleMode"),value:b.mode,dataAttr:"data-model-switch-rule-mode",choices:_x.map(E=>({value:E,label:t(Ol[E])})),onChange:E=>{T({...b,mode:E})}})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:$e,children:t("st.modelSwitch.ruleAsk")}),e.jsx(Qe,{ariaLabel:t("st.modelSwitch.ruleAsk"),variant:"form",value:b.ask,dataAttr:"data-model-switch-rule-ask",choices:[{value:"inherit",label:t("st.modelSwitch.ask.inherit")},{value:"ask",label:t("st.modelSwitch.ask.ask")},{value:"skip",label:t("st.modelSwitch.ask.skip")}],onChange:E=>{T({...b,ask:E})}})]}),e.jsx(Be,{layout:"row",label:t("st.modelSwitch.ruleEnabled"),checked:b.enabled,onChange:E=>{T({...b,enabled:E})}})]}),L!==void 0?e.jsxs("div",{"data-model-switch-rule-preview":!0,className:"space-y-0.5 text-[12px] leading-snug",children:[e.jsxs("p",{className:"text-ink-faint",children:[t("st.modelSwitch.previewFrom")," ",I(sa(b.from))]}),e.jsxs("p",{className:"text-ink-faint",children:[t("st.modelSwitch.previewTo")," ",I(sa(b.to))]})]}):null,Ix(sa(b.from))||Ix(sa(b.to))?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:t("st.modelSwitch.rulePatternInvalid")}):null]}):null,e.jsx(lt,{id:"model-switch-rules",dirty:w,saving:v,saveLabel:t("st.modelSwitch.ruleSave"),onSave:()=>{k()},onDiscard:()=>{c(d),h(void 0),m(void 0),g(null)}})]}),e.jsx(pe,{feedback:f}),i.error!==null&&i.error!==void 0?e.jsx(De,{error:i.error}):null]})})}const Px=t=>t===void 0?"":JSON.stringify(t,null,2);function Ax(t){return{aliases:[...t.aliases??[]],maxInputSize:t.max_input_size===void 0?"":String(t.max_input_size),maxOutputSize:t.max_output_size===void 0?"":String(t.max_output_size),contextBudget:t.context_budget===void 0?"":String(t.context_budget),offEffort:t.off_effort??"",reasoningKey:t.reasoning_key??"",adaptiveThinking:t.adaptive_thinking===void 0?"inherit":t.adaptive_thinking?"on":"off",requestParams:Px(t.request_params),cognition:Ar(t.cognition,ri),promptOverrides:Ar(t.prompt_overrides,sn),overrides:Px(t.overrides)}}function yI(t,s){const n=a=>({...a,cognition:$r(a.cognition,gi),promptOverrides:$r(a.promptOverrides,Bs)});return JSON.stringify(n(t))===JSON.stringify(n(s))}class xr extends Error{constructor(s,n){super(`${s}: ${n}`),this.field=s,this.key=n}}function kI(t,s){const n={},a=(o,l)=>{const c=t[o].trim();if(c!==s[o].trim()){if(c===""){n[l]=null;return}if(!/^\d+$/.test(c)||Number(c)<1)throw new xr(o,"count");n[l]=Number(c)}},i=(o,l)=>{const c=t[o].trim();c!==s[o].trim()&&(n[l]=c===""?null:c)},r=(o,l)=>{const c=h=>o==="cognition"?$r(h.cognition,gi):o==="promptOverrides"?$r(h.promptOverrides,Bs):h[o],d=c(t).trim();if(d===c(s).trim())return;const u=o==="cognition"&&!t.cognition.rawActive?xa(t.cognition.value,gi,ON):o==="promptOverrides"&&!t.promptOverrides.rawActive?xa(t.promptOverrides.value,Bs,lo):void 0;if(u!==void 0)throw new bn({key:`st.promptIdentity.problem.${u}`});if(d===""){n[l]=null;return}let p;try{p=JSON.parse(d)}catch{throw new xr(o,"json")}if(typeof p!="object"||p===null||Array.isArray(p))throw new xr(o,"object");o==="cognition"&&Vf.parse(p),o==="promptOverrides"&&Yf.parse(p),n[l]=Object.keys(p).length===0?null:p};return JSON.stringify(t.aliases)!==JSON.stringify(s.aliases)&&(n.aliases=t.aliases.length===0?null:t.aliases),a("maxInputSize","max_input_size"),a("maxOutputSize","max_output_size"),a("contextBudget","context_budget"),i("offEffort","off_effort"),i("reasoningKey","reasoning_key"),t.adaptiveThinking!==s.adaptiveThinking&&(n.adaptive_thinking=t.adaptiveThinking==="inherit"?null:t.adaptiveThinking==="on"),r("requestParams","request_params"),r("cognition","cognition"),r("promptOverrides","prompt_overrides"),r("overrides","overrides"),n}const jI=[{field:"requestParams",label:"st.modelEngine.requestParams",help:"st.modelEngine.requestParamsHelp"},{field:"overrides",label:"st.modelEngine.overrides",help:"st.modelEngine.overridesHelp"}];function $x({modelId:t,value:s,onChange:n,issue:a,part:i="engine",disabled:r=!1}){const{t:o}=D(),l=(m,f)=>{n({...s,[m]:f})},c=m=>{let f;try{f=s[m].raw.trim()===""?{}:JSON.parse(s[m].raw)}catch{return{error:o("st.modelEngine.issueJson")}}const g=(m==="cognition"?Vf:Yf).safeParse(f);return g.success?{value:g.data}:{error:g.error.issues[0]?.message??o("st.modelEngine.issueObject")}},d=m=>{if(!s[m].rawActive)return null;const f=c(m);return e.jsxs("div",{className:"pt-2",children:[e.jsx("button",{type:"button",disabled:f.error!==void 0,className:"rounded px-2 py-1 text-[12px] text-ink-soft hover:bg-ink/[0.04] focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:opacity-50",onClick:()=>{f.error===void 0&&(m==="cognition"?l(m,Ar(f.value,ri)):l(m,Ar(f.value,sn)))},children:o("st.profiles.modeForm")}),f.error!==void 0?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:f.error}):null]})},u=m=>a?.field===m?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] font-normal text-danger",children:a.text}):null,p=m=>a?.field===m?"border-danger":"",h=(m,f)=>e.jsxs("label",{className:$e,children:[f,e.jsx("input",{className:`${Ce} mt-1 font-mono font-normal ${p(m)}`,inputMode:"numeric",value:s[m],"aria-invalid":a?.field===m,"data-model-engine":m,placeholder:o("st.modelEngine.unset"),onChange:g=>{l(m,g.target.value)}}),u(m)]}),b=(m,f)=>e.jsxs("label",{className:$e,children:[f,e.jsx("input",{className:`${Ce} mt-1 font-mono font-normal`,value:s[m],placeholder:o("st.modelEngine.unset"),"data-model-engine":m,onChange:g=>{l(m,g.target.value)}})]});return i==="prompts"?e.jsxs("fieldset",{disabled:r,className:"min-w-0 space-y-1 disabled:opacity-60","data-model-prompt-structure":t,children:[e.jsxs("details",{"data-model-cognition-editor":!0,className:"pt-2",children:[e.jsx("summary",{className:"cursor-pointer py-1 text-[13px] font-medium text-ink",children:o("st.promptIdentity.cognitionTitle")}),e.jsxs("div",{className:"space-y-4 pt-3",children:[s.cognition.rawActive?null:e.jsx(Ca,{value:s.cognition.value,onChange:m=>l("cognition",em(s.cognition,m,gi)),children:(m,f,g)=>e.jsx(L2,{value:m,onChange:f,label:g})}),e.jsxs("details",{"data-prompt-json":"cognition",children:[e.jsx("summary",{className:"cursor-pointer text-[11.5px] text-ink-faint",children:o("st.promptIdentity.raw")}),e.jsx("textarea",{rows:6,spellCheck:!1,"data-model-engine":"cognition","aria-label":o("st.promptIdentity.cognitionTitle"),className:`${Ce} mt-2 h-auto border-0 bg-ink/[0.035] font-mono text-[12px] leading-5`,value:s.cognition.raw,onChange:m=>l("cognition",{...s.cognition,raw:m.target.value,rawActive:!0})}),d("cognition")]}),u("cognition")]})]}),e.jsxs("details",{"data-model-overrides-editor":!0,className:"pt-2",children:[e.jsx("summary",{className:"cursor-pointer py-1 text-[13px] font-medium text-ink",children:o("st.promptIdentity.fieldsTitle")}),e.jsxs("div",{className:"space-y-4 pt-3",children:[s.promptOverrides.rawActive?null:e.jsx(Ca,{value:s.promptOverrides.value,onChange:m=>l("promptOverrides",em(s.promptOverrides,m,Bs)),children:(m,f,g)=>e.jsx(Eo,{value:m,onChange:f,label:g})}),e.jsxs("details",{"data-prompt-json":"promptOverrides",children:[e.jsx("summary",{className:"cursor-pointer text-[11.5px] text-ink-faint",children:o("st.promptIdentity.raw")}),e.jsx("textarea",{rows:6,spellCheck:!1,"data-model-engine":"promptOverrides","aria-label":o("st.promptIdentity.fieldsTitle"),className:`${Ce} mt-2 h-auto border-0 bg-ink/[0.035] font-mono text-[12px] leading-5`,value:s.promptOverrides.raw,onChange:m=>l("promptOverrides",{...s.promptOverrides,raw:m.target.value,rawActive:!0})}),d("promptOverrides")]}),u("promptOverrides")]})]})]}):e.jsxs("fieldset",{disabled:r,className:"min-w-0 space-y-4 disabled:opacity-60","data-model-engine-fields":t,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:o("st.modelEngine.aliases")}),e.jsx(ln,{values:s.aliases,knownOptions:[],onChange:m=>{l("aliases",m)},ariaLabel:o("st.modelEngine.aliasesAria",{model:t}),addPlaceholder:o("st.chips.addPlaceholder"),removeLabel:m=>o("st.chips.removeAria",{value:m})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[h("maxInputSize",o("st.modelEngine.maxInput")),h("maxOutputSize",o("st.modelEngine.maxOutput"))]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[b("offEffort",o("st.modelEngine.offEffort")),b("reasoningKey",o("st.modelEngine.reasoningKey")),e.jsxs("div",{className:$e,children:[o("st.modelEngine.adaptive"),e.jsx("div",{className:"mt-1 font-normal",children:e.jsx(Qe,{variant:"form",ariaLabel:o("st.modelEngine.adaptive"),dataAttr:"data-model-engine-adaptive",value:s.adaptiveThinking,onChange:m=>{l("adaptiveThinking",m)},choices:[{value:"inherit",label:o("st.modelEngine.adaptiveInherit")},{value:"on",label:o("st.modelEngine.adaptiveOn")},{value:"off",label:o("st.modelEngine.adaptiveOff")}]})})]})]}),jI.map(({field:m,label:f,help:g})=>e.jsxs("label",{className:`${$e} block`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[o(f),e.jsx(Rn,{children:o(g)})]}),e.jsx("textarea",{rows:3,spellCheck:!1,"data-model-engine":m,"aria-invalid":a?.field===m,className:`${Ce} mt-1 h-auto py-1.5 font-mono text-[12px] font-normal leading-5 ${p(m)}`,value:s[m],onChange:v=>{l(m,v.target.value)}}),u(m)]},m))]})}const an=["main","independent"],ju=["thinking_effort","service_tier","auto_compact","context_budget","max_completion_tokens"],wu=new Set(["auto_compact","context_budget","max_completion_tokens"]),pv=wu,Nu=["auto","default","flex","priority"],Su={thinking_effort:"thinkingEffort",auto_compact:"autoCompact",context_budget:"contextBudget",max_completion_tokens:"maxCompletionTokens"},En={thinkingEffort:void 0,tier:"inherit",autoCompact:void 0,contextBudget:void 0,maxCompletionTokens:void 0},wI=t=>typeof t=="object"&&t!==null&&t.kind==="api_default";function NI(t){return t===void 0?"inherit":wI(t)?"not_sent":typeof t!="string"?"inherit":Nu.includes(t)?t:"inherit"}const er=t=>t===void 0?void 0:String(t);function Rx(t,s){const n=t.usage?.[s];return{thinkingEffort:er(n?.thinking_effort),tier:NI(n?.service_tier),autoCompact:er(n?.auto_compact),contextBudget:er(n?.context_budget),maxCompletionTokens:er(n?.max_completion_tokens)}}function Ss(t,s){return s==="service_tier"?t.tier==="inherit"?"":t.tier:t[Su[s]]??""}function Lx(t,s,n){return{...t,[Su[s]]:n}}function SI(t){return t==="service_tier"?{tier:"inherit"}:{[Su[t]]:void 0}}function mv(t,s){return ju.every(n=>Ss(t,n)===Ss(s,n))}function Mx(t,s){return an.every(n=>mv(t[n]??En,s[n]??En))}function CI(t){for(const s of ju){if(!wu.has(s))continue;const n=Ss(t,s);if(n==="")continue;const a=Number(n);if(!/^\d+$/.test(n.trim())||!Number.isSafeInteger(a)||a<1)return s}}function _I(t,s){const n={},a=(i,r)=>{Ss(t,i)!==Ss(s,i)&&(r===void 0||r===""?n[i]=null:n[i]=wu.has(i)?Number(r):r)};return Ss(t,"service_tier")!==Ss(s,"service_tier")&&(n.service_tier=t.tier==="inherit"?null:t.tier==="not_sent"?{kind:"api_default"}:t.tier),a("thinking_effort",t.thinkingEffort),a("auto_compact",t.autoCompact),a("context_budget",t.contextBudget),a("max_completion_tokens",t.maxCompletionTokens),Object.keys(n).length===0?null:n}function EI(t,s){const n={};for(const a of an){const i=t[a]??En,r=s[a]??En,o=_I(i,r);o!==null?n[a]=o:mv(i,r)||(n[a]=null)}return Object.keys(n).length===0?{}:{usage:n}}function TI(t,s){return t.usage_effective?.[s]}function II(t,s,n){return t.usage_sources?.[s]?.[n]}const PI={thinking_effort:"st.usagePolicy.thinkingEffort",service_tier:"st.usagePolicy.serviceTier",auto_compact:"st.usagePolicy.autoCompact",context_budget:"st.usagePolicy.contextBudget",max_completion_tokens:"st.usagePolicy.maxCompletionTokens"},xv={main:"st.modelScope.main",independent:"st.modelScope.independent"},AI=["thinking_effort","service_tier","max_completion_tokens","context_budget","auto_compact"];function $I({modelId:t,view:s,efforts:n,onSharedChange:a,onChange:i,sharedIssue:r=null,compactionControl:o,compactionTrack:l,disabled:c=!1}){return e.jsx("div",{"data-main-usage-policy":t,className:"grid min-w-0 gap-x-5 gap-y-4 sm:grid-cols-2","data-usage-fields":!0,children:AI.map(d=>e.jsx("div",{className:d==="auto_compact"?"min-w-0 sm:col-span-2":"min-w-0",children:e.jsx(RI,{field:d,modelId:t,view:s,efforts:n,disabled:c,onSharedChange:a,onChange:i,sharedIssue:r?.field===d?r.text:void 0,sharedControl:d==="auto_compact"?o:void 0,below:d==="auto_compact"?l:void 0})},d))})}function RI({field:t,modelId:s,view:n,efforts:a,onSharedChange:i,onChange:r,sharedIssue:o,sharedControl:l,below:c,disabled:d}){const{t:u}=D(),p=u(PI[t]),h=`usage-${s}-${t}`,b=n.shared[t],m=an.filter(N=>Ss(n.draft[N]??En,t)!==""),f=n.issue!==null&&n.issue.field===t,g=Rb(),{setOpen:v}=g;x.useEffect(()=>{f&&v(!0)},[f,v]);const y=g.open,w=m.length===0&&!y;return e.jsxs("div",{"data-usage-row":t,className:"group min-w-0 space-y-1.5",children:[e.jsxs("div",{className:"flex min-h-6 items-center justify-between gap-2",children:[e.jsx("label",{htmlFor:l===void 0?h:void 0,className:"text-[12px] font-medium text-ink-soft",children:p}),e.jsxs("button",{type:"button","data-usage-identity-toggle":t,"data-usage-toggle-quiet":w?"":void 0,...g.triggerProps,className:`inline-flex h-6 shrink-0 items-center gap-1 rounded px-1.5 text-[11.5px] transition-[color,background-color,opacity] focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:h-9 ${m.length>0?"bg-selected-ink/10 font-medium text-selected-ink hover:bg-selected-ink/15":"text-ink-faint hover:bg-ink/[0.04] hover:text-ink"} ${w?"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100":""}`,children:[e.jsx("span",{"data-usage-override-marker":m.length>0?m.join(" "):void 0,children:m.length>0?m.map(N=>u(xv[N])).join(" · "):u("st.usagePolicy.perAgent")}),e.jsx("svg",{"aria-hidden":!0,viewBox:"0 0 12 12",className:`size-2.5 transition-transform ${y?"rotate-180":""}`,children:e.jsx("path",{d:"M3 4.5 6 7.5 9 4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})]})]}),e.jsx("div",{"data-usage-shared":t,className:"min-w-0",children:l??e.jsx(LI,{field:t,id:h,label:p,value:b,efforts:a,disabled:d,invalid:o!==void 0,onSharedChange:i})}),o===void 0?null:e.jsx("p",{role:"alert",className:"text-[12px] text-danger","data-usage-shared-issue":t,children:o}),c,e.jsxs(Lb,{...g.popoverProps,label:u("st.usagePolicy.perAgentTitle",{field:p}),align:"end",widthClassName:"w-[22rem]",data:{"data-usage-identities":t},children:[e.jsx("p",{className:"mb-2 text-[12px] font-medium text-ink-soft",children:u("st.usagePolicy.perAgentTitle",{field:p})}),e.jsx("div",{className:"space-y-2",children:an.map(N=>e.jsx(MI,{field:t,position:N,modelId:s,label:p,view:n,efforts:a,disabled:d,onChange:r},N))})]})]})}function LI({field:t,id:s,label:n,value:a,efforts:i,disabled:r,invalid:o,onSharedChange:l}){const{t:c}=D();return t==="service_tier"?e.jsx(Qe,{id:s,variant:"form",mono:!0,dataAttr:"data-usage-value",ariaLabel:n,disabled:r,value:a===""?"unset":a,onChange:d=>{l({[t]:d==="unset"?"":d})},choices:[{value:"unset",label:c("st.usagePolicy.unset")},...Nu.map(d=>({value:d,label:d}))]}):t==="thinking_effort"?e.jsx(Qe,{id:s,variant:"form",dataAttr:"data-usage-value",ariaLabel:n,disabled:r,value:a===""?"unset":a,onChange:d=>{l({[t]:d==="unset"?"":d})},choices:[{value:"unset",label:c("st.usagePolicy.unset")},...hv(i,a,c),{value:"off",label:c("st.usagePolicy.off")}]}):e.jsx(fv,{id:s,field:t,label:n,value:a,invalid:o,placeholder:c("st.usagePolicy.unset"),disabled:r,onCommit:d=>{l({[t]:d})}})}function MI({field:t,position:s,modelId:n,label:a,view:i,efforts:r,disabled:o,onChange:l}){const{t:c}=D(),d=i.draft[s]??En,u=T=>{l({...i.draft,[s]:T})},p=Ss(d,t),h=p!=="",b=i.shared[t],m=`usage-${n}-${s}-${t}`,f=c(xv[s]),g=`${f} · ${a}`,v=OI(t,d,c),y=i.resolved[s]?.[t],w=i.dirty?v:y?.value!==void 0&&y.value!==""?y.value:v,N=i.dirty?void 0:y?.source,_=h&&w!==""&&w!==v,C=i.issue!==null&&i.issue.field===t&&i.issue.position===s,S=b===""?c("st.usagePolicy.unset"):Ox(t,t==="thinking_effort"?Cs(b,c):b),k=c("st.usagePolicy.inheritValue",{value:S});let j;return t==="service_tier"?j=e.jsx(Qe,{id:m,variant:"form",mono:!0,dataAttr:"data-usage-value",ariaLabel:g,disabled:o,value:d.tier,onChange:T=>{u({...d,tier:T})},choices:[{value:"inherit",label:k},{value:"not_sent",label:c("st.usagePolicy.omit")},...Nu.map(T=>({value:T,label:T}))]}):t==="thinking_effort"?j=e.jsx(Qe,{id:m,variant:"form",dataAttr:"data-usage-value",ariaLabel:g,disabled:o,value:p===""?"inherit":p,onChange:T=>{u(Lx(d,t,T==="inherit"?"":T))},choices:[{value:"inherit",label:k},...hv(r,p==="off"?"":p,c),{value:"off",label:c("st.usagePolicy.off")}]}):j=e.jsx(fv,{id:m,field:t,label:g,value:p,invalid:C,placeholder:k,disabled:o,onCommit:T=>{u(Lx(d,t,T))}}),e.jsxs("div",{"data-usage-position":s,className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-[12px] text-ink-soft",title:f,children:f}),e.jsx("div",{className:"min-w-0 flex-1",children:j}),h?e.jsx("button",{type:"button","data-usage-restore":t,disabled:o,title:c("st.usagePolicy.restoreInherit"),"aria-label":`${c("st.usagePolicy.restoreInherit")} · ${g}`,className:"shrink-0 rounded px-1.5 py-1 text-[11.5px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-not-allowed disabled:text-ink-faint disabled:no-underline",onClick:()=>{o||u({...d,...SI(t)})},children:c("st.usagePolicy.restoreShort")}):null]}),_?e.jsxs("p",{className:"flex items-center gap-1.5 ps-[5.5rem] text-[11.5px] text-ink-faint",children:[e.jsx("span",{children:c("st.usagePolicy.effectiveShort")}),e.jsx("span",{className:"tabular-nums text-ink-soft","data-usage-effective":t,children:Ox(t,w)}),N===void 0?null:e.jsx(Rn,{children:e.jsx("span",{className:"break-all font-mono text-[11px]","data-usage-source":t,children:N})})]}):null,C?e.jsx("p",{role:"alert",className:"ps-[5.5rem] text-[12px] text-danger","data-usage-issue":t,children:c("st.usagePolicy.issueCount")}):null]})}function hv(t,s,n){const a=t.filter(i=>i!=="off");return s!==""&&s!=="off"&&!a.includes(s)&&a.push(s),a.map(i=>({value:i,label:i==="off"?n("st.usagePolicy.off"):Cs(i,n)}))}function Ox(t,s){if(!pv.has(t))return s;const n=Number(s);return s!==""&&Number.isFinite(n)?ft(n):s}function fv({id:t,field:s,label:n,value:a,invalid:i,placeholder:r,onCommit:o,disabled:l=!1}){const c=pv.has(s),d=c&&a!==""&&/^\d+$/.test(a.trim())?ft(Number(a)):a,[u,p]=x.useState(d),[h,b]=x.useState(!1);return x.useEffect(()=>{l&&b(!1)},[l]),x.useEffect(()=>{(!h||l)&&p(d)},[d,h,l]),e.jsx("input",{id:t,"data-usage-value":s,"aria-label":n,"aria-invalid":i,disabled:l,className:`${pt} h-8 w-full ${i?"border-danger":""} ${c?"font-mono tabular-nums":""}`,inputMode:c?"decimal":void 0,spellCheck:!1,autoComplete:"off",value:u,placeholder:r,onChange:m=>{const f=m.target.value;if(b(!0),p(f),!c){o(f);return}const g=kc(f);o(g.kind==="tokens"?String(g.tokens):f)},onFocus:()=>b(!0),onBlur:()=>{b(!1);const m=c?kc(u):null;p(m?.kind==="tokens"?ft(m.tokens):u)}})}function OI(t,s,n){const a=Ss(s,t);return a===""?"":a==="not_sent"?n("st.usagePolicy.omit"):t==="thinking_effort"&&a==="off"?n("st.usagePolicy.off"):a}const DI=["shared","main","independent"],FI={shared:"st.modelScope.all",main:"st.modelScope.main",independent:"st.modelScope.independent"},qI=["main","independent"];function BI({scope:t,customized:s,onScopeChange:n}){const{t:a}=D();return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2","data-model-edit-scope":t,"data-model-edit-scope-switch":!0,children:[e.jsx("span",{id:"model-scope-label",className:"text-[12px] font-medium text-ink-soft",children:a("st.modelScope.appliesTo")}),e.jsx("div",{role:"radiogroup","aria-labelledby":"model-scope-label",className:"inline-flex max-w-full flex-wrap items-center gap-0.5 rounded-md bg-ink/[0.04] p-0.5",children:DI.map(i=>{const r=i===t,o=s.has(i);return e.jsxs("button",{type:"button",role:"radio","aria-checked":r,"data-model-scope-choice":i,"data-model-scope-customized":o?"":void 0,onClick:()=>{r||n(i)},className:`inline-flex h-7 items-center gap-1.5 rounded-[5px] px-3 text-[12.5px] transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:h-9 ${r?"bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"text-ink-soft hover:text-ink"}`,children:[a(FI[i]),o?e.jsx("span",{"aria-hidden":!0,className:"size-1.5 rounded-full bg-selected-ink"}):null,o?e.jsx("span",{className:"sr-only",children:a("st.modelScope.customized")}):null]},i)})}),t!=="shared"&&s.has(t)?e.jsx("span",{className:"text-[11.5px] text-selected-ink","data-model-scope-summary":!0,children:a("st.modelScope.customized")}):null]})}const bv=["recipes"],gv=["recipe-markets"],KI=t=>["recipe",t];function $o(){const{client:t}=be();return je({queryKey:bv,queryFn:()=>t.listRecipes(),retry:!1})}function UI(t){const{client:s}=be();return je({queryKey:KI(t??""),queryFn:()=>s.getRecipe(t??""),enabled:t!==null&&t!=="",retry:!1})}function vv(){const{client:t}=be();return je({queryKey:gv,queryFn:()=>t.listRecipeMarkets(),retry:!1})}function yt(t,s={}){const n=Oe();return Ks({mutationFn:a=>t(a),onSuccess:async(a,i)=>{await n.invalidateQueries({queryKey:bv}),await n.invalidateQueries({queryKey:gv}),s.invalidateRecipeDetail!==!1&&await n.invalidateQueries({queryKey:["recipe"]}),await n.invalidateQueries({queryKey:["models"]}),await n.invalidateQueries({queryKey:["model-entity"]}),await n.invalidateQueries({queryKey:["config"]}),s.alsoModelId!==void 0&&await n.invalidateQueries({queryKey:["model-entity",s.alsoModelId]}),s.onSuccess?.(a,i)},onError:a=>{s.onError?.(a)}})}function Qr(t){return Jf.includes(t)?`st.hooks.event.${t}`:void 0}const HI="recipe-hook-consent-required";function Ro(t){return t.hooks?.consent_required===!0}function zI(t){return t instanceof su?typeof t.details=="object"&&t.details!==null&&t.details.code===HI:!1}function QI(t){return t instanceof su?typeof t.details=="object"&&t.details!==null&&t.details.path==="expected_revision":!1}function GI(t){const s=new Map;for(const n of t){const a=s.get(n.event);a===void 0?s.set(n.event,[n]):a.push(n)}return[...s].map(([n,a])=>({event:n,scripts:a}))}function WI(t){const s=new Map;for(const n of t)for(const a of n.files){const i=s.get(a.path);i===void 0?s.set(a.path,{path:a.path,bytes:a.bytes,count:1}):i.count+=1}return[...s.values()].toSorted((n,a)=>n.path.localeCompare(a.path))}function VI(t){return t<1024?`${t} B`:`${(t/1024).toFixed(t<10*1024?1:0)} kB`}function Cu(t){return Ro(t)?{consent:!0}:{}}/*!
|
|
20
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
21
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
22
|
+
*
|
|
23
|
+
* Redistribution and use in source and binary forms, with or without
|
|
24
|
+
* modification, are permitted provided that the following conditions are met:
|
|
25
|
+
*
|
|
26
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
27
|
+
* list of conditions and the following disclaimer.
|
|
28
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
29
|
+
* this list of conditions and the following disclaimer in the
|
|
30
|
+
* documentation and/or other materials provided with the distribution.
|
|
31
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
32
|
+
* may be used to endorse or promote products derived from this software without
|
|
33
|
+
* specific prior written permission.
|
|
34
|
+
*
|
|
35
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
36
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
37
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
38
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
39
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
40
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
41
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
42
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
43
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
44
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
45
|
+
*/function YI(t,s){let n=t.slice(0,s).split(/\r?\n/);return[n.length,n.pop().length+1]}function JI(t,s,n){let a=t.split(/\r?\n/),i="",r=(Math.log10(s+1)|0)+1;for(let o=s-1;o<=s+1;o++){let l=a[o-1];l&&(i+=o.toString().padEnd(r," "),i+=": ",i+=l,i+=`
|
|
46
|
+
`,o===s&&(i+=" ".repeat(r+n+2),i+=`^
|
|
47
|
+
`))}return i}class tt extends Error{line;column;codeblock;constructor(s,n){const[a,i]=YI(n.toml,n.ptr),r=JI(n.toml,a,i);super(`Invalid TOML document: ${s}
|
|
48
|
+
|
|
49
|
+
${r}`,n),this.line=a,this.column=i,this.codeblock=r}static x(s,n,a){throw new tt(s,{toml:n.s,ptr:a??n.p})}}/*!
|
|
50
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
51
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
52
|
+
*
|
|
53
|
+
* Redistribution and use in source and binary forms, with or without
|
|
54
|
+
* modification, are permitted provided that the following conditions are met:
|
|
55
|
+
*
|
|
56
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
57
|
+
* list of conditions and the following disclaimer.
|
|
58
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
59
|
+
* this list of conditions and the following disclaimer in the
|
|
60
|
+
* documentation and/or other materials provided with the distribution.
|
|
61
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
62
|
+
* may be used to endorse or promote products derived from this software without
|
|
63
|
+
* specific prior written permission.
|
|
64
|
+
*
|
|
65
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
66
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
67
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
68
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
69
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
70
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
71
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
72
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
73
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
74
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
75
|
+
*/function yv(t){let s=t.p,n=t.s.charCodeAt(t.p++),a=n,i=n===39,r=n===t.s.charCodeAt(t.p)&&n===t.s.charCodeAt(t.p+1);r&&((n=t.s.charCodeAt(t.p+=2))===10?t.p++:n===13&&t.s.charCodeAt(t.p+1)===10&&(t.p+=2));let o="",l=t.p,c=0;for(;t.p<t.s.length;t.p++)if(n=t.s.charCodeAt(t.p),r&&(n===10||n===13&&t.s.charCodeAt(t.p+1)===10))c=c&&3;else if(n<32&&n!==9||n===127)tt.x("control characters are not allowed in strings",t);else if((!c||c===3)&&n===a&&(!r||t.s.charCodeAt(t.p+1)===a&&t.s.charCodeAt(t.p+2)===a)){if(r&&(t.s.charCodeAt(t.p+3)===a&&t.p++,t.s.charCodeAt(t.p+3)===a&&t.p++),!c){let d=t.s.slice(l,t.p);o=o?o+d:d}return t.p+=r?3:1,o}else if(!c)!i&&n===92&&(o+=t.s.slice(l,l=t.p),c=1);else if(c===1)if(n===120||n===117||n===85){let d=t.p++-1,u=0,p=n===120?2:n===117?4:8;for(let h=0;h<p;h++,t.p++){let b=t.s.charCodeAt(t.p),m=b>=48&&b<=57?b-48:b>=65&&b<=70?b-65+10:b>=97&&b<=102?b-97+10:-1;m<0&&tt.x("invalid non-hex character in unicode escape",t),u=u<<4|m}(u<0||u>1114111||u>=55296&&u<=57343)&&tt.x("invalid unicode escape",t,d),o+=String.fromCodePoint(u),l=t.p--,c=0}else r&&(n===32||n===9)?c=2:(n===98?o+="\b":n===116?o+=" ":n===110?o+=`
|
|
76
|
+
`:n===102?o+="\f":n===114?o+="\r":n===101?o+="\x1B":n===34?o+='"':n===92?o+="\\":tt.x("unrecognised escape sequence",t),l=t.p+1,c=0);else n!==32&&n!==9&&(c===2&&tt.x("invalid escape: only line-ending whitespace may be escaped",t,l),c=!i&&n===92?1:0,l=t.p);tt.x("unfinished string",t,s)}/*!
|
|
77
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
78
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
79
|
+
*
|
|
80
|
+
* Redistribution and use in source and binary forms, with or without
|
|
81
|
+
* modification, are permitted provided that the following conditions are met:
|
|
82
|
+
*
|
|
83
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
84
|
+
* list of conditions and the following disclaimer.
|
|
85
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
86
|
+
* this list of conditions and the following disclaimer in the
|
|
87
|
+
* documentation and/or other materials provided with the distribution.
|
|
88
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
89
|
+
* may be used to endorse or promote products derived from this software without
|
|
90
|
+
* specific prior written permission.
|
|
91
|
+
*
|
|
92
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
93
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
94
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
95
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
96
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
97
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
98
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
99
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
100
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
101
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
102
|
+
*/let ZI=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;class na extends Date{#t=!1;#s=!1;#e=null;constructor(s,n,a){let i=!0,r=!0,o="Z",l;if(typeof s=="string")if(n)e:{if(n<3){if(+s.slice(11,13)>23){s="";break e}n===2?(o=null,s+="Z"):(l=s.charCodeAt(s.length-1))!==90&&l!==122&&(o=s.slice(s.length-6)),a&&(s=s.slice(0,10)+"T"+s.slice(11))}else n===4&&(s=+s.slice(0,2)>23?"":`0000-01-01T${s}Z`);i=n!==4,r=n!==3}else{let c=s.match(ZI);c?(c[1]||(i=!1,s=`0000-01-01T${s}`),r=!!c[2],r&&s[10]===" "&&(s=s.replace(" ","T")),c[2]&&+c[2]>23?s="":(o=c[3]||null,!o&&r&&(s+="Z"))):s=""}super(s),isNaN(this.getTime())||(this.#t=i,this.#s=r,this.#e=o)}isDateTime(){return this.#t&&this.#s}isLocal(){return!this.#t||!this.#s||!this.#e}isDate(){return this.#t&&!this.#s}isTime(){return this.#s&&!this.#t}isValid(){return this.#t||this.#s}toISOString(){let s=super.toISOString();if(this.isDate())return s.slice(0,10);if(this.isTime())return s.slice(11,23);if(this.#e===null)return s.slice(0,-1);if(this.#e==="Z"||this.#e==="z")return s;let n=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return n=this.#e[0]==="-"?n:-n,new Date(this.getTime()-n*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(s,n="Z"){let a=new na(s);return a.#e=n,a}static wrapAsLocalDateTime(s){let n=new na(s);return n.#e=null,n}static wrapAsLocalDate(s){let n=new na(s);return n.#s=!1,n.#e=null,n}static wrapAsLocalTime(s){let n=new na(s);return n.#t=!1,n.#e=null,n}}/*!
|
|
103
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
104
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
105
|
+
*
|
|
106
|
+
* Redistribution and use in source and binary forms, with or without
|
|
107
|
+
* modification, are permitted provided that the following conditions are met:
|
|
108
|
+
*
|
|
109
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
110
|
+
* list of conditions and the following disclaimer.
|
|
111
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
112
|
+
* this list of conditions and the following disclaimer in the
|
|
113
|
+
* documentation and/or other materials provided with the distribution.
|
|
114
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
115
|
+
* may be used to endorse or promote products derived from this software without
|
|
116
|
+
* specific prior written permission.
|
|
117
|
+
*
|
|
118
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
119
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
120
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
121
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
122
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
123
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
124
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
125
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
126
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
127
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
128
|
+
*/function es(t,s=10){return s===16?t>47&&t<58||t>64&&t<71||t>96&&t<103:t>47&&t<48+s}function Gc(t,s){return t===32||t===9||t===10||t===13||s&&(t===s||t===44)||t===35}function _u(t,s){let n=t.p,a=t.s.charCodeAt(t.p);if(a===91||a===123){t.d--||tt.x("document contains excessively nested structures. aborting.",t);let i=a===91?nP(t):sP(t);return t.d++,i}return a===34||a===39?yv(t):a===116?((t.s.charCodeAt(++t.p)!==114||t.s.charCodeAt(++t.p)!==117||t.s.charCodeAt(++t.p)!==101)&&tt.x("invalid value",t,n),t.p++,!0):a===102?((t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==108||t.s.charCodeAt(++t.p)!==115||t.s.charCodeAt(++t.p)!==101)&&tt.x("invalid value",t,n),t.p++,!1):a===43||a===45?Gr(t,t.p,t.s.charCodeAt(++t.p),44-a,s):t.s.charCodeAt(t.p+4)===45&&t.s.charCodeAt(t.p+7)===45?XI(t,a,s):t.s.charCodeAt(t.p+2)===58?eP(t,a,s):Gr(t,t.p,a,0,s)}function Gr(t,s,n,a,i){let r=n,o=0,l=!1;if(r===105)return(t.s.charCodeAt(++t.p)!==110||t.s.charCodeAt(++t.p)!==102)&&tt.x("invalid value",t,s),t.p++,(a||1)/0;if(r===110)return(t.s.charCodeAt(++t.p)!==97||t.s.charCodeAt(++t.p)!==110)&&tt.x("invalid value",t,s),t.p++,NaN;if(r===48){if(++t.p>=t.s.length||Gc(r=t.s.charCodeAt(t.p),i))return t.bi===!0?0n:0;if(!a){if(r===120)return Dl(t,s,16,i);if(r===98)return Dl(t,s,2,i);if(r===111)return Dl(t,s,8,i)}r===46?o=2:r===101||r===69?o=4:tt.x("illegal leading zero",t,s)}else es(r)||tt.x("invalid value",t,s);for(;++t.p<t.s.length&&(r=t.s.charCodeAt(t.p),!Gc(r,i));)o||(o=1),r===95?(o&1||tt.x("illegal underscore",t),o+=11,l=!0):o===1&&r===46?o=2:(o===1||o===3)&&(r===101||r===69)?o=4:o===4&&(r===43||r===45)?o=6:es(r)?o>9?o-=11:o&1||o++:tt.x("illegal character in numeric literal",t);if(!o){let d=(n-48)*(a||1);return t.bi===!0?BigInt(d):d}o&1||tt.x("unfinished numeric value",t,s);let c=t.s.slice(s,t.p);return l&&(c=c.replaceAll("_","")),o>1?parseFloat(c):kv(t,c,10,s)}function Dl(t,s,n,a){let i,r=1;for(;++t.p<t.s.length&&(i=t.s.charCodeAt(t.p),!Gc(i,a));)i===95?(r&1&&tt.x("illegal underscore",t),r=3):es(i,n)?r&1&&r--:tt.x("illegal character in numeric literal",t);r&1&&tt.x("unfinished numeric value",t);let o=t.s.slice(s+2,t.p);return r&&(o=o.replaceAll("_","")),kv(t,o,n,s)}function kv(t,s,n,a){if(t.bi!==!0)e:{let i=parseInt(s,n);if(!Number.isSafeInteger(i)){if(t.bi)break e;tt.x("integer value cannot be represented losslessly",t,a)}return i}return BigInt(n===10?s:(n===2?"0b":n===8?"0o":"0x")+s)}function XI(t,s,n){let a=t.p++,i;if(!es(s)||!es(t.s.charCodeAt(t.p++))||!es(t.s.charCodeAt(t.p++))||!es(t.s.charCodeAt(t.p++)))return Gr(t,t.p=a,s,0,n);if(t.p+=5,es(t.s.charCodeAt(t.p++))||tt.x("invalid date-time: date part is malformed",t,a),t.p>=t.s.length||((s=t.s.charCodeAt(t.p))!==32||(i=!0,!es(t.s.charCodeAt(t.p+1))))&&s!==84&&s!==116){let o=t.s.slice(a,t.p);return ei(t,o,3,!1,a)}if(t.s.charCodeAt(t.p+=3)!==58&&tt.x("invalid date-time: time part is malformed",t,a),t.s.charCodeAt(t.p+=3)===58&&(t.p+=3),t.s.charCodeAt(t.p)===46)for(;es(t.s.charCodeAt(++t.p)););if(s=t.s.charCodeAt(t.p)){if(s===90||s===122){let o=t.s.slice(a,++t.p);return ei(t,o,1,i,a,"[+00:00]")}if(s===43||s===45){let o=t.s.slice(a,t.p+=6);return ei(t,o,1,i,a,!t.ld&&"["+t.s.slice(t.p-6,t.p)+"]")}}let r=t.s.slice(a,t.p);return ei(t,r,2,i,a)}function eP(t,s,n){let a=t.p;if(!es(s)||!es(t.s.charCodeAt(++t.p)))return Gr(t,--t.p,s,0,n);if(t.s.charCodeAt(t.p+=4)===58&&(t.p+=3),t.s.charCodeAt(t.p)===46)for(;es(t.s.charCodeAt(++t.p)););let i=t.s.slice(a,t.p);return ei(t,i,4,!1,a)}function ei(t,s,n,a,i,r){if(t.ld){let o=new na(s,n,a);return o.isValid()||tt.x("invalid date",t,i),o}try{switch(r&&(s+=r),n){case 1:return Temporal.ZonedDateTime.from(s);case 2:return Temporal.PlainDateTime.from(s);case 3:return Temporal.PlainDate.from(s);case 4:return Temporal.PlainTime.from(s)}}catch(o){tt.x(o instanceof Error?o.message:""+o,t,i)}}/*!
|
|
129
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
130
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
131
|
+
*
|
|
132
|
+
* Redistribution and use in source and binary forms, with or without
|
|
133
|
+
* modification, are permitted provided that the following conditions are met:
|
|
134
|
+
*
|
|
135
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
136
|
+
* list of conditions and the following disclaimer.
|
|
137
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
138
|
+
* this list of conditions and the following disclaimer in the
|
|
139
|
+
* documentation and/or other materials provided with the distribution.
|
|
140
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
141
|
+
* may be used to endorse or promote products derived from this software without
|
|
142
|
+
* specific prior written permission.
|
|
143
|
+
*
|
|
144
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
145
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
146
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
147
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
148
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
149
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
150
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
151
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
152
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
153
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
154
|
+
*/function tP(t){for(;t.p<t.s.length;t.p++){let s=t.s.charCodeAt(t.p);if(s===10)break;if(s===13&&t.s.charCodeAt(t.p+1)===10){t.p++;break}(s<32&&s!==9||s===127)&&tt.x("control characters are not allowed in comments",t)}}function Ds(t,s,n){let a;for(;t.p<t.s.length;){for(;t.p<t.s.length&&((a=t.s.charCodeAt(t.p))===32||a===9||!s&&(a===10||a===13&&t.s.charCodeAt(t.p+1)===10));)t.p++;if(n||a!==35)break;tP(t)}}/*!
|
|
155
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
156
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
157
|
+
*
|
|
158
|
+
* Redistribution and use in source and binary forms, with or without
|
|
159
|
+
* modification, are permitted provided that the following conditions are met:
|
|
160
|
+
*
|
|
161
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
162
|
+
* list of conditions and the following disclaimer.
|
|
163
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
164
|
+
* this list of conditions and the following disclaimer in the
|
|
165
|
+
* documentation and/or other materials provided with the distribution.
|
|
166
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
167
|
+
* may be used to endorse or promote products derived from this software without
|
|
168
|
+
* specific prior written permission.
|
|
169
|
+
*
|
|
170
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
171
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
172
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
173
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
174
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
175
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
176
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
177
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
178
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
179
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
180
|
+
*/function Wc(t,s=61){let n,a=0,i=[],r,o=t.s.charCodeAt(n=t.p);do{if(o===s)return a||tt.x("unexpected end of key",t),a===1&&i.push(t.s.slice(r,t.p)),t.p++,i;o===46?(a||tt.x("illegal empty bare key",t),a===1&&i.push(t.s.slice(r,t.p)),a=0):!a&&(o===34||o===39)?(o===t.s.charCodeAt(t.p+1)&&o===t.s.charCodeAt(t.p+2)&&tt.x("illegal quoted key: multiline strings are not allowed",t),i.push(yv(t)),a=2,t.p--):o===32||o===9?a===1&&(i.push(t.s.slice(r,t.p)),a=2):a===2||o<48&&o!==45||o>57&&o<65||o>90&&o<97&&o!==95||o>122?tt.x("illegal character in key",t):a||(a=1,r=t.p)}while(o=t.s.charCodeAt(++t.p));tt.x("incomplete key-value: cannot find end of key",t,n)}function sP(t){let s=t.p++,n=Object.create(null),a=new Set,i;for(;t.p<t.s.length;){if(Ds(t),(i=t.s.charCodeAt(t.p))===125)return t.p++,n;let r,o=n,l=!1,c=t.p,d=Wc(t);for(let p=0;p<d.length;p++){p&&(o=l?o[r]:o[r]=Object.create(null)),r=d[p],(l=Object.hasOwn(o,r))&&(typeof o[r]!="object"||a.has(o[r]))&&tt.x("trying to redefine an already defined value",t,c);let h=r==="__proto__";if(t.uk&&(h||r==="constructor")){o=t.uk!==1&&tt.x("document contains an unsafe property",t,c);break}!l&&h&&Object.defineProperty(o,r,{enumerable:!0,configurable:!0,writable:!0})}l&&tt.x("trying to redefine an already defined value",t,c),Ds(t,!0,!0);let u=_u(t,125);if(o&&typeof(o[r]=u)=="object"&&a.add(u),Ds(t),(i=t.s.charCodeAt(t.p++))===125)return n;i!==44&&tt.x("expected comma or end of structure",t,t.p-1)}tt.x("unfinished table",t,s)}function nP(t){let s=t.p++,n=[],a;for(;t.p<t.s.length;){if(Ds(t),(a=t.s.charCodeAt(t.p))===93)return t.p++,n;if(n.push(_u(t,93)),Ds(t),(a=t.s.charCodeAt(t.p++))===93)return n;a!==44&&tt.x("expected comma or end of structure",t,t.p-1)}tt.x("unfinished array",t,s)}/*!
|
|
181
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
182
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
183
|
+
*
|
|
184
|
+
* Redistribution and use in source and binary forms, with or without
|
|
185
|
+
* modification, are permitted provided that the following conditions are met:
|
|
186
|
+
*
|
|
187
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
188
|
+
* list of conditions and the following disclaimer.
|
|
189
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
190
|
+
* this list of conditions and the following disclaimer in the
|
|
191
|
+
* documentation and/or other materials provided with the distribution.
|
|
192
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
193
|
+
* may be used to endorse or promote products derived from this software without
|
|
194
|
+
* specific prior written permission.
|
|
195
|
+
*
|
|
196
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
197
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
198
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
199
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
200
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
201
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
202
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
203
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
204
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
205
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
206
|
+
*/function Dx(t,s,n,a,i){let r=n,o=a,l,c=!1,d;for(let u=0;u<s.length;u++){if(u){if(r=c?r[l]:r[l]=Object.create(null),o=(d=o[l]).c,i===0&&(d.t===1||d.t===2))return null;if(d.t===2){let p=r.length-1;r=r[p],o=o[p].c}}if(l=s[u],(c=Object.hasOwn(r,l))&&o[l]?.t===0&&o[l]?.d)return null;if(!c){let p=l==="__proto__";if(t.uk&&(p||l==="constructor"))return!1;p&&(Object.defineProperty(r,l,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,l,{enumerable:!0,configurable:!0,writable:!0})),o[l]={t:u<s.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(d=o[l],d.t!==i&&!(i===1&&d.t===3)||(i===2&&(d.d||(d.d=!0,r[l]=[]),r[l].push(r=Object.create(null)),d.c[d.i++]=d={t:1,d:!1,i:0,c:Object.create(null)}),d.d))return null;if(d.d=!0,i===1)r=c?r[l]:r[l]=Object.create(null);else if(i===0&&c)return null;return[l,r,d.c]}function Fx(t,s,n){(s===null||t.uk===2)&&tt.x(s===null?"trying to redefine an already defined table or value":"document contains an unsafe property",t,n)}function aP(t,s={}){let n={s:t,p:0,d:s.maxDepth??1e3,bi:s.integersAsBigInt??!1,ld:s.useLegacyDate??!0,uk:s.unsafeKeyBehaviour==="throw"?2:s.unsafeKeyBehaviour==="drop"?1:0},a=Object.create(null),i=Object.create(null),r,o=!1,l=a,c=i;for(t.charCodeAt(0)===65279&&n.p++,Ds(n);n.p<t.length;){if(t.charCodeAt(n.p)===91){let d=t.charCodeAt(++n.p)===91;r=n.p+=+d,o=!1;let u=Wc(n,93);d&&(t.charCodeAt(n.p)!==93&&tt.x("expected end of table array declaration",n),n.p++);let p=Dx(n,u,a,i,d?2:1);p?(c=p[2],l=p[1]):(Fx(n,p,r),o=!0)}else{r=n.p;let d=Wc(n),u=Dx(n,d,l,c,0);!u&&!o&&Fx(n,u,r),Ds(n,!0,!0);let p=_u(n,void 0);u&&!o&&(u[1][u[0]]=p)}Ds(n,!0),n.p<t.length&&(r=t.charCodeAt(n.p))!==10&&(r!==13||t.charCodeAt(n.p+1)!==10)&&tt.x("each key-value declaration must be followed by an end-of-line",n),Ds(n)}return a}/*!
|
|
207
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
208
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
209
|
+
*
|
|
210
|
+
* Redistribution and use in source and binary forms, with or without
|
|
211
|
+
* modification, are permitted provided that the following conditions are met:
|
|
212
|
+
*
|
|
213
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
214
|
+
* list of conditions and the following disclaimer.
|
|
215
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
216
|
+
* this list of conditions and the following disclaimer in the
|
|
217
|
+
* documentation and/or other materials provided with the distribution.
|
|
218
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
219
|
+
* may be used to endorse or promote products derived from this software without
|
|
220
|
+
* specific prior written permission.
|
|
221
|
+
*
|
|
222
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
223
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
224
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
225
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
226
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
227
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
228
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
229
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
230
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
231
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
232
|
+
*/let iP=/^[a-z0-9-_]+$/i,jv=!!"".isWellFormed;function Mi(t){let s=typeof t;if(s==="object"){if(Array.isArray(t))return"array";if(typeof t.getUTCDate=="function"&&t instanceof Date)return"date";if(globalThis.Temporal){if(t.until){if(t instanceof Temporal.ZonedDateTime)return"temporal/tz+uc";if(t instanceof Temporal.PlainDateTime||t instanceof Temporal.PlainDate)return"temporal/uc";if(t instanceof Temporal.PlainTime||t instanceof Temporal.Instant)return"temporal";if(t instanceof Temporal.PlainYearMonth)return"temporal/x"}else if(t.toPlainDate&&t instanceof Temporal.PlainMonthDay||t.negated&&t instanceof Temporal.Duration)return"temporal/x"}}return s}function rP(t){for(let s=0;s<t.length;s++)if(Mi(t[s])!=="object")return!1;return t.length!=0}function wv(t){return JSON.stringify(t).replaceAll("","\\u007f")}function oP(t){return wv(jv?t.toWellFormed():t)}function Nv(t){if(iP.test(t))return t;if(jv&&!t.isWellFormed())throw new RangeError("key contains illegal lone surrogates");return wv(t)}function Eu(t,s,n,a,i){if(n===0)throw new Error("Could not stringify the object: maximum object depth exceeded");switch(s){case"number":if(isNaN(t))return"nan";if(t===1/0)return"inf";if(t===-1/0)return"-inf";if(Number.isInteger(t)&&(a||!Number.isSafeInteger(t)))return t.toFixed(1);case"bigint":case"boolean":case"temporal":return t.toString();case"string":return oP(t);case"date":if(isNaN(t.getTime()))throw new TypeError("cannot serialize invalid date");return t.toISOString();case"object":return lP(t,n,a,i);case"array":return cP(t,n,a,i);case"temporal/tz+uc":if(i){let r=t.timeZoneId,o=r.charCodeAt(0);if(o!==43&&o!==45&&(o!==85&&o!==71&&o!==90&&o!==69||r!=="UTC"&&r!=="UCT"&&r!=="Universal"&&r!=="Zulu"&&!r.startsWith("GMT")&&r!=="Greenwich"&&!r.startsWith("Etc/")))throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode")}case"temporal/uc":if(i&&t.calendarId!=="iso8601")throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");return t.toString({calendarName:"never",timeZoneName:"never"});case"temporal/x":throw new TypeError("Unsupported "+t[Symbol.toStringTag])}}function lP(t,s,n,a){let i=Object.keys(t);if(i.length===0)return"{}";let r="{ ";for(let o=0;o<i.length;o++){let l=i[o];o&&(r+=", "),r+=Nv(l)+" = "+Eu(t[l],Mi(t[l]),s-1,n,a)}return r+" }"}function cP(t,s,n,a){if(t.length===0)return"[]";let i="[ ";for(let r=0;r<t.length;r++){if(r&&(i+=", "),t[r]===null||t[r]===void 0)throw new TypeError("arrays cannot contain null or undefined values");i+=Eu(t[r],Mi(t[r]),s-1,n,a)}return i+" ]"}function dP(t,s,n,a,i){if(n===0)throw new Error("Could not stringify the object: maximum object depth exceeded");let r="";for(let o=0;o<t.length;o++)r+=`${r&&`
|
|
233
|
+
`}[[${s}]]
|
|
234
|
+
`,r+=Tu(0,t[o],s,n,a,i);return r}function Tu(t,s,n,a,i,r){if(a===0)throw new Error("Could not stringify the object: maximum object depth exceeded");let o="",l="",c=Object.keys(s);for(let d=0;d<c.length;d++){let u=c[d];if(s[u]!==null&&s[u]!==void 0){let p=Mi(s[u]);if(p==="symbol"||p==="function")throw new TypeError(`cannot serialize values of type '${p}'`);let h=Nv(u);if(p==="array"&&rP(s[u]))l+=(l&&`
|
|
235
|
+
`)+dP(s[u],n?`${n}.${h}`:h,a-1,i,r);else if(p==="object"){let b=n?`${n}.${h}`:h;l+=(l&&`
|
|
236
|
+
`)+Tu(b,s[u],b,a-1,i,r)}else o+=h,o+=" = ",o+=Eu(s[u],p,a,i,r),o+=`
|
|
237
|
+
`}}return t&&(o||!l)&&(o=o?`[${t}]
|
|
238
|
+
${o}`:`[${t}]`),o&&l?`${o}
|
|
239
|
+
${l}`:o||l}function uP(t,{maxDepth:s=1e3,numbersAsFloat:n=!1,strictTemporal:a=!1}={}){if(Mi(t)!=="object")throw new TypeError("stringify can only be called with an object");let i=Tu(0,t,"",s,n,a);return i[i.length-1]!==`
|
|
240
|
+
`?i+`
|
|
241
|
+
`:i}const Qn="recipe.toml",Pt=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);class rn extends Error{constructor(s,n){super(n===void 0?s:`${n}: ${s}`),this.detail=s,this.path=n,this.name="RecipeManifestError"}}function Fl(t){try{const s=aP(t);if(!Pt(s))throw new rn("Expected a table at the top level");return s}catch(s){throw s instanceof rn?s:new rn(s instanceof Error?s.message:String(s))}}function pP(t){const s=Pt(t.prompts)?t.prompts:void 0,n=r=>{if(!Pt(r))return;const o={},l=(c,d)=>{if(c==="off")return{kind:"off"};if(typeof c=="string")throw new rn("Expected a table, an array or off",d);if(Array.isArray(c))return{kind:"segments",parts:c.map((u,p)=>fP(u,`${d}[${p}]`))};if(Pt(c)){if(typeof c.text=="string")return{kind:"inline",text:c.text};if(typeof c.file=="string")return{kind:"file",file:c.file}}};if(r.system!==void 0&&(o.system=l(r.system,"system")),r.steering!==void 0&&(o.steering=l(r.steering,"steering")),r.parent_steering!==void 0&&(o.parent_steering=l(r.parent_steering,"parent_steering")),r.anchor!==void 0&&(o.anchor=l(r.anchor,"anchor")),Pt(r.fields)){const c={};for(const[d,u]of Object.entries(r.fields))(u===!1||typeof u=="string")&&(c[d]=u);o.fields=c}return typeof r.steering_on_turn=="boolean"&&(o.steering_on_turn=r.steering_on_turn),typeof r.steering_on_input=="boolean"&&(o.steering_on_input=r.steering_on_input),typeof r.steering_interval_steps=="number"&&(o.steering_interval_steps=r.steering_interval_steps),Pt(r.steering_sources)&&(o.steering_sources=bP(r.steering_sources,l)),o},a=(r,o)=>{if(r==="same"||r==="off")return r;if(r===void 0)return;const l=n(r);if(l===void 0)throw new rn("Expected a table, same or off",o);return l},i=t.model;return{id:typeof t.id=="string"?t.id:void 0,name:typeof t.name=="string"?t.name:void 0,version:typeof t.version=="string"?t.version:void 0,description:typeof t.description=="string"?t.description:void 0,extends:Pt(t.extends)?{source:typeof t.extends.source=="string"?t.extends.source:void 0,revision:typeof t.extends.revision=="string"?t.extends.revision:void 0}:void 0,model:i==="off"?"off":Pt(i)?i:void 0,prompts:n(s),main:a(s?.main,"prompts.main"),independent:a(s?.independent,"prompts.independent"),hooks:mP(t.hooks)}}function mP(t){if(t==="off")return"off";if(Array.isArray(t))return t.filter(Pt).map(s=>({event:typeof s.event=="string"?s.event:void 0,command:typeof s.command=="string"?s.command:void 0,matcher:typeof s.matcher=="string"?s.matcher:void 0,timeout:typeof s.timeout=="number"?s.timeout:void 0,root:typeof s.root=="string"?s.root:void 0,files:Array.isArray(s.files)?s.files.filter(n=>typeof n=="string"):void 0}))}function xP(t){const s=new Set,n=a=>{if(!(a===void 0||a==="same"||a==="off")){for(const i of[a.system,a.steering,a.parent_steering,a.anchor])Kx(s,i);for(const i of Object.values(a.steering_sources??{}))Kx(s,i.steering)}};if(n(t.prompts),n(t.main),n(t.independent),Array.isArray(t.hooks))for(const a of t.hooks)for(const i of a.files??[])s.add(a.root===void 0?i:`${a.root}/${i}`);return[...s].toSorted()}function hP(t,s,n,a){const i=Sv(t),{root:r,group:o}=Cv(i);return o[n]=_v(a),i.prompts=r,i}function Sv(t){return{...t,prompts:Pt(t.prompts)?{...t.prompts}:t.prompts}}function Cv(t,s){const n=Pt(t.prompts)?{...t.prompts}:{};return{root:n,group:n}}function qx(t){return uP(t)}function Bx(t,s){return t.trim()!==s.trim()}function _v(t){switch(t.kind){case"off":return"off";case"inline":return{text:t.text};case"file":return{file:t.file};case"segments":return t.parts.map(s=>s.kind==="inline"?{text:s.text??""}:{file:s.file??""})}}function Kx(t,s){if(s?.kind==="file"&&t.add(s.file),s?.kind==="segments")for(const n of s.parts)n.kind==="file"&&n.file!==void 0&&t.add(n.file)}function fP(t,s){if(!Pt(t))throw new rn("Expected a segment table",s);if(typeof t.text=="string")return{kind:"inline",text:t.text};if(typeof t.file=="string")return{kind:"file",file:t.file};throw new rn("A segment needs text or file",s)}function bP(t,s){const n={};for(const[a,i]of Object.entries(t)){if(!Pt(i))continue;const r=i,o=r.mode;if(o!=="off"&&o!=="inherit"&&o!=="custom")continue;const l=Pt(r.custom)?r.custom:{},c=s(l.steering,`steering_sources.${a}.steering`);n[a]={mode:o,...c!==void 0?{steering:c}:{},...typeof l.steering_on_turn=="boolean"?{steering_on_turn:l.steering_on_turn}:{},...typeof l.steering_on_input=="boolean"?{steering_on_input:l.steering_on_input}:{},...typeof l.steering_interval_steps=="number"?{steering_interval_steps:l.steering_interval_steps}:{}}}return n}function gP(t,s,n,a){const i=Sv(t),{root:r,group:o}=Cv(i),l=Pt(o.steering_sources)?{...o.steering_sources}:{},c={mode:a.mode},d=Pt(l[n])?l[n]:void 0,p={...Pt(d?.custom)?d.custom:{}};return a.steering!==void 0&&(p.steering=_v(a.steering)),a.steering_on_turn!==void 0&&(p.steering_on_turn=a.steering_on_turn),a.steering_on_input!==void 0&&(p.steering_on_input=a.steering_on_input),a.steering_interval_steps!==void 0&&(p.steering_interval_steps=a.steering_interval_steps),Object.keys(p).length>0&&(c.custom=p),l[n]=c,o.steering_sources=l,i.prompts=r,i}const vP=["overlay","steering","anchor"];function yP(t){return t==="shared"?"common":t}function Ev(t,s,n){if(t===void 0)return;const a=t.branches[yP(s)];if(a===void 0||a.selection==="off")return;const i=a.slots[n];if(i!==void 0)return{slot:n,source:i.source,text:i.text??"",files:i.files??[],writable:i.writable,sourceReadOnly:i.source_read_only,error:i.error}}function kP(t,s,n,a){const i=t.cognition===void 0||t.cognition===null?{}:{...t.cognition};if(s==="shared")return a===void 0?delete i[n]:i[n]={text:a},{cognition:i};const r=hr(t,s);return a===void 0?delete r[n]:r[n]={text:a},i[s]=r,{cognition:i}}function hr(t,s){const n=t.cognition??{},a=s==="shared"?void 0:n[s];if(a==="off")return{};if(typeof a=="object"&&a!==null&&!Array.isArray(a))return{...a};const{main:i,independent:r,...o}=n;return o}function Tv(t){return t?.text??""}const Iv=["common","main","independent"],Oi=Yj;function Pv(t){return t==="shared"?"common":t}const Tn={text:"",cadence:{onTurn:!0,onInput:!0,intervalSteps:"0"}},jP=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{},wP=t=>t==="off"||t==="inherit"||t==="custom";function NP(t){if(typeof t=="string")return t;if(typeof t=="object"&&t!==null&&!Array.isArray(t)){const s=t.text;if(typeof s=="string")return s}return""}const SP=(t,s)=>{const n=s?.cadence??Tn.cadence,a=t.steering_interval_steps;return{onTurn:typeof t.steering_on_turn=="boolean"?t.steering_on_turn:n.onTurn,onInput:typeof t.steering_on_input=="boolean"?t.steering_on_input:n.onInput,intervalSteps:typeof a=="number"?String(a):n.intervalSteps}};function CP(t){if(typeof t!="object"||t===null)return{mode:"off",custom:Tn};const s=t,n=s.custom,a=typeof n=="object"&&n!==null&&!Array.isArray(n)?n:void 0;return{mode:wP(s.mode)?s.mode:"off",custom:a===void 0?Tn:{text:NP(a.steering),cadence:SP(a,void 0)}}}function ql(t){const s=jP(t),n={};for(const a of Oi)n[a]=a in s?CP(s[a]):{mode:"off",custom:Tn};return n}function Ux(t){return{common:ql(hr(t,"shared").steering_sources),main:ql(hr(t,"main").steering_sources),independent:ql(hr(t,"independent").steering_sources)}}function Hx(t,s){return t===null||s===null?t===s:JSON.stringify(t)===JSON.stringify(s)}function _P(t,s){return JSON.stringify(t)===JSON.stringify(s)}function EP(t,s,n){return t?.[s][n]??{mode:"off",custom:Tn}}function TP(t,s){return s===t.mode?t:{mode:s,custom:t.custom}}function IP(t,s){return{...t,custom:{...t.custom,text:s}}}function PP(t,s){return{...t,custom:{...t.custom,cadence:s}}}function Av(t){if(t.trim()==="")return"empty";if(!/^\d+$/.test(t.trim()))return"count";const s=Number(t);if(!Number.isSafeInteger(s))return"count"}function AP(t,s){const n=s??{mode:"off",custom:Tn},a={};return t.custom.text!==n.custom.text&&(a.steering={text:t.custom.text}),t.custom.cadence.onTurn!==n.custom.cadence.onTurn&&(a.steering_on_turn=t.custom.cadence.onTurn),t.custom.cadence.onInput!==n.custom.cadence.onInput&&(a.steering_on_input=t.custom.cadence.onInput),t.custom.cadence.intervalSteps!==n.custom.cadence.intervalSteps&&(a.steering_interval_steps=Number(t.custom.cadence.intervalSteps)),t.mode===n.mode?Object.keys(a).length===0?void 0:{mode:t.mode,custom:a}:Object.keys(a).length===0?{mode:t.mode}:{mode:t.mode,custom:a}}function $P(t,s){const n={};for(const a of Oi){const i=AP(t[a]??{mode:"off",custom:Tn},s[a]);i!==void 0&&(n[a]=i)}return Object.keys(n).length===0?void 0:n}function RP(t,s){const n={};for(const a of Iv){if(_P(t[a],s[a]))continue;const i=$P(t[a],s[a]);i!==void 0&&(n[a]=i)}return Object.keys(n).length===0?void 0:n}function LP({scripts:t}){const{t:s}=D(),n=WI(t);return n.length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-hook-files":"none",children:s("st.recipeHook.filesNone")}):e.jsxs("div",{className:"space-y-1 pt-0.5","data-recipe-hook-files":!0,children:[e.jsx("p",{className:"text-[11px] text-ink-faint",children:s("st.recipeHook.resources")}),e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline",children:n.map(a=>e.jsxs("li",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5 py-1.5","data-recipe-hook-file":a.path,children:[e.jsx("span",{className:"min-w-0 break-all font-mono text-[11.5px] text-ink-soft",children:a.path}),e.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-ink-faint",children:[VI(a.bytes),a.count>1?` · ${s("st.recipeHook.fileUsedBy",{count:String(a.count)})}`:""]})]},a.path))})]})}function MP({script:t,index:s}){const{t:n}=D();return e.jsxs("li",{className:"space-y-1","data-recipe-hook-script":s,children:[e.jsx("code",{className:"block overflow-x-auto whitespace-pre-wrap break-words rounded-md bg-ink/[0.04] px-2.5 py-2 font-mono text-[12px] leading-5 text-ink",children:t.command}),e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-0.5",children:[e.jsx("span",{className:"min-w-0 break-all text-[11.5px] text-ink-soft","data-recipe-hook-source":!0,children:t.source}),t.matcher===void 0?null:e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-hook-matcher":!0,children:n("st.recipeHook.matcher",{matcher:t.matcher})}),t.timeout===void 0?null:e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-hook-timeout":!0,children:n("st.recipeHook.timeout",{seconds:String(t.timeout)})})]})]})}function $v({hooks:t,headingLevel:s="h4"}){const{t:n}=D();if(t===void 0||t.scripts.length===0)return null;const a=s,i=GI(t.scripts);return e.jsxs("section",{className:"space-y-2.5","data-recipe-hooks":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx(a,{className:"text-[13px] font-medium text-ink",children:n("st.recipeHook.title")}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-hook-count":!0,children:n("st.recipeHook.scriptCount",{count:String(t.scripts.length)})})]}),i.map(r=>e.jsxs("div",{className:"space-y-2","data-recipe-hook-event":r.event,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:Qr(r.event)===void 0?r.event:n(Qr(r.event))}),e.jsx("ul",{className:"space-y-2.5",children:r.scripts.map((o,l)=>e.jsx(MP,{script:o,index:l},`${r.event}-${l}`))})]},r.event)),e.jsx(LP,{scripts:t.scripts})]})}function Iu({hooks:t,name:s}){const{t:n}=D();return e.jsxs("div",{className:"mt-3 space-y-3","data-recipe-hook-consent":!0,children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink","data-recipe-hook-consent-lead":!0,children:n("st.recipeHook.consentLead",{name:s})}),e.jsx("p",{className:"text-[12.5px] leading-relaxed text-ink-soft","data-recipe-hook-consent-power":!0,children:n("st.recipeHook.consentPower")}),e.jsx($v,{hooks:t,headingLevel:"h5"}),e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-hook-consent-once":!0,children:n("st.recipeHook.consentOnce")})]})}function zx(t,s){return Object.keys(t).length===Object.keys(s).length&&Object.keys(t).every(n=>Object.hasOwn(s,n)&&t[n]===s[n])}function Qx(t,s,n){const a={...t};for(const i of new Set([...Object.keys(s),...Object.keys(n)]))Object.hasOwn(n,i)===Object.hasOwn(s,i)&&n[i]===s[i]||(Object.hasOwn(n,i)?a[i]=n[i]:delete a[i]);return a}const OP=[{slot:"system",label:"st.recipe.slot.system"},{slot:"steering",label:"st.recipe.slot.steering"},{slot:"parent_steering",label:"st.recipe.slot.parent_steering"}];function Rv({detail:t,onApplied:s,onBack:n,onDirtyChange:a}){const{t:i,locale:r}=D(),{client:o}=be(),l=Oe(),[c,d]=x.useState(()=>({...t.files})),u=x.useRef(c);u.current=c;const[p,h]=x.useState(()=>({...t.files})),[b,m]=x.useState(0),[f,g]=x.useState("prompt"),[v,y]=x.useState(null),[w,N]=x.useState(null),[_,C]=x.useState(!1),[S,k]=x.useState(null),j=c[Qn]??"",T=!zx(c,p);x.useEffect(()=>{a?.(T)},[T,a]);const A=`recipe-author:${t.summary.installation_id}`;Ft(A,T);const P=Ln(),[R,L]=x.useState(!1),I=()=>{if(P?.confirmDiscard!==void 0){P.confirmDiscard(A,n);return}if(T){L(!0);return}n()};let $,E;try{$=pP(Fl(j))}catch(K){E=K instanceof rn?K.message:String(K)}x.useEffect(()=>{N(E??null)},[E]);const[M,z]=x.useState(null),[H,U]=x.useState(null),[X,q]=x.useState(null),[F,V]=x.useState(!1),[se,Y]=x.useState(null),O=x.useRef(null),B=(K,Z)=>{const ue=Qx(K.files,Z,u.current);d(ue),h({...K.files}),m(Te=>Te+1),U(null),q(null),k(null),y({tone:"success",text:i("st.recipe.savedNewBinding")}),l.setQueryData(["recipe",K.summary.installation_id],K),O.current=null,s(K,!zx(ue,K.files))},le=yt(K=>o.getRecipe(K),{invalidateRecipeDetail:!1,onSuccess:(K,Z)=>{if(K===void 0){U(Z);return}const ue=O.current;ue!==null&&B(K,ue.files)},onError:K=>{U(O.current.installation_id),q(oe(r,K))}}),re=yt(K=>o.getRecipe(K),{invalidateRecipeDetail:!1,onSuccess:K=>{if(K===void 0){Y(i("st.recipe.conflictGone"));return}d(Qx(K.files,p,u.current)),h({...K.files}),m(Z=>Z+1),V(!1),Y(null),y({tone:"success",text:i("st.recipe.conflictRebased")}),l.setQueryData(["recipe",K.summary.installation_id],K)},onError:K=>{Y(oe(r,K))}}),ae=yt(K=>(O.current=K,o.saveLocalRecipe(K)),{invalidateRecipeDetail:!1,onSuccess:(K,Z)=>{z(null),B(K,Z.files)},onError:K=>{if(zI(K)){k(null),ne.mutate(O.current);return}if(O.current=null,U(null),QI(K)){V(!0);return}y({tone:"error",text:i("st.recipe.saveFailed",{detail:oe(r,K)})})}}),ne=yt(K=>o.previewRecipe({source:{locator:`installation:${K.installation_id}`},installation_id:K.installation_id,expected_revision:K.expected_revision,files:K.files}),{invalidateRecipeDetail:!1,onSuccess:K=>{k(null),Ro(K)?z(K):Ee.mutate({preview:K})},onError:K=>{U(null),k(i("st.recipe.previewFailed",{detail:oe(r,K)}))}}),Ee=yt(K=>o.installRecipe({preview_id:K.preview.preview_id,...Cu(K.preview)}),{invalidateRecipeDetail:!1,onSuccess:K=>{z(null),k(null),le.mutateAsync(K.installation_id).catch(()=>{})},onError:K=>{U(null),k(i("st.recipe.saveFailed",{detail:oe(r,K)}))}}),ie=ae.isPending||ne.isPending||Ee.isPending||le.isPending||re.isPending,fe=ie||(M!==null||H!==null||F),Ie=(K,Z,ue)=>{if(E!==void 0)return;const Te=hP(Fl(j),K,Z,ue),Ne=qx(Te);d(J=>({...J,[Qn]:Ne})),C(Bx(j,Ne))},te=(K,Z)=>{d(ue=>({...ue,[K]:Z}))},ee=(K,Z)=>{if(E!==void 0)return;const ue=gP(Fl(j),"prompts",K,Z),Te=qx(ue);d(Ne=>({...Ne,[Qn]:Te})),C(Bx(j,Te))};return e.jsxs("div",{className:"min-w-0 space-y-5","data-recipe-author":t.summary.installation_id,children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h3",{className:"font-display text-[28px] leading-9 tracking-tight text-ink","data-recipe-author-name":!0,children:t.summary.name}),e.jsxs("p",{className:"font-mono text-[11.5px] text-ink-faint",children:[t.summary.version," · ",_n(t.resolved.revision)]}),e.jsxs("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-author-status":!0,children:[t.editable?i("st.recipe.localPackage"):i("st.recipe.packageReadOnly"),$?.extends?.source===void 0?null:` · ${i("st.recipe.basedOn",{source:$.extends.source})}`]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 border-b border-hairline",role:"tablist","data-recipe-author-tabs":!0,children:[["prompt","st.recipe.authorTabPrompt"],["source","st.recipe.authorTabSource"]].map(([K,Z])=>e.jsx("button",{type:"button",role:"tab","aria-selected":f===K,"data-recipe-author-tab":K,className:`-mb-px border-b-2 px-2 py-1.5 text-[12px] outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${f===K?"border-accent text-ink":"border-transparent text-ink-faint hover:text-ink-soft"}`,onClick:()=>{g(K)},children:i(Z)},K))}),f==="prompt"?e.jsx("div",{className:"min-w-0 space-y-5","data-recipe-author-prompt":!0,children:E!==void 0?e.jsxs("div",{className:"space-y-2 rounded-md bg-danger/5 px-3 py-2","data-recipe-manifest-error":!0,children:[e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:i("st.recipe.manifestInvalid",{detail:E})}),e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-goto-source":!0,onClick:()=>{g("source")},children:i("st.recipe.fixInSource")})]}):e.jsxs(e.Fragment,{children:[OP.map(({slot:K,label:Z})=>e.jsx(zP,{slot:K,label:i(Z),declaration:$,files:c,onInline:ue=>{Ie("prompts",K,{kind:"inline",text:ue})},onSegments:ue=>{Ie("prompts",K,{kind:"segments",parts:ue})},onFile:(ue,Te)=>{te(ue,Te)}},K)),e.jsx(FP,{declaration:$,files:c,onChange:ee,onInline:(K,Z)=>{const ue=$?.prompts?.steering_sources?.[K];ee(K,{...ue,mode:"custom",steering:{kind:"inline",text:Z}})},onSegments:(K,Z)=>{const ue=$?.prompts?.steering_sources?.[K];ee(K,{...ue,mode:"custom",steering:{kind:"segments",parts:Z}})},onFile:(K,Z,ue)=>{if(ue!==void 0){te(Z,ue);return}const Te=$?.prompts?.steering_sources?.[K];ee(K,{...Te,mode:"custom",steering:{kind:"file",file:Z}})},onOff:K=>{const Z=$?.prompts?.steering_sources?.[K];ee(K,{...Z,mode:"custom",steering:{kind:"off"}})}})]})}):e.jsxs("div",{className:"min-w-0 space-y-2","data-recipe-author-source":!0,children:[$?.hooks===void 0?null:e.jsx(DP,{hooks:$.hooks}),e.jsx(s_,{path:`${t.summary.manifest_id}/${Qn}`,value:j,generation:b,readOnly:!1,ariaLabel:Qn,onChange:K=>{d(Z=>({...Z,[Qn]:K})),C(!1)}}),xP($??{prompts:{}}).map(K=>e.jsxs("div",{className:"space-y-1","data-recipe-author-file":K,children:[e.jsx("p",{className:"font-mono text-[11.5px] text-ink-faint",children:K}),e.jsx("textarea",{rows:6,spellCheck:!1,"aria-label":K,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:c[K]??"",onChange:Z=>{te(K,Z.target.value)}})]},K)),w!==null&&E===void 0?e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:w}):null]}),_?e.jsx("div",{className:"space-y-1.5 rounded-md bg-ink/[0.03] px-3 py-2","data-recipe-reformat-notice":!0,children:e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:i("st.recipe.reformatNotice")})}):null,t.used_by.length===0?null:e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-author-used-by":!0,children:i("st.recipe.savedForModels",{models:t.used_by.join(", ")})}),e.jsx(pe,{feedback:v}),S!==null?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger","data-recipe-author-failure":!0,children:S}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-3",children:[e.jsx("button",{type:"button",disabled:!T||fe||E!==void 0,className:"rounded-md bg-accent px-3 py-1.5 text-[12px] font-medium text-on-accent transition-colors hover:bg-accent-deep disabled:cursor-not-allowed disabled:bg-hairline disabled:text-ink-faint","data-recipe-save-package":!0,onClick:()=>{k(null),ae.mutate({installation_id:t.summary.installation_id,expected_revision:t.summary.revision,files:{...c}})},children:i(ie?"common.saving":"st.recipe.savePackage")}),e.jsx("button",{type:"button",className:"rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink","data-recipe-author-back":!0,onClick:I,children:i("st.recipe.back")}),T?e.jsx("span",{className:"text-[12px] text-ink-faint",children:i("st.draft.unsaved")}):null]}),F?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-recipe-author-conflict":!0,children:[e.jsxs("p",{className:"text-[12px] leading-5 text-amber-ink",role:"alert",children:[i("st.recipe.conflictBody"),se===null?"":` ${se}`]}),e.jsx("button",{type:"button",disabled:re.isPending,className:"rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50","data-recipe-conflict-reload":!0,onClick:()=>{Y(null),re.mutate(t.summary.installation_id)},children:i("st.recipe.conflictReload")})]}):null,H===null?null:e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-recipe-author-readback":!0,children:[e.jsxs("p",{className:"text-[12px] leading-5 text-ink-soft",role:"status",children:[i("st.recipeHook.savedReadbackFailed"),X===null?"":` ${i("st.recipeHook.reloadSavedFailed",{detail:X})}`]}),e.jsx("button",{type:"button",disabled:le.isPending,className:"rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50","data-recipe-reload-saved":!0,onClick:()=>{le.mutate(H)},children:i("st.recipeHook.retryLoadSaved")})]}),e.jsx(Xe,{open:R,overlayId:`recipe-author-discard:${t.summary.installation_id}`,title:i("st.dirty.leaveTitle"),body:i("st.dirty.leaveBody"),confirmLabel:i("st.dirty.leaveConfirm"),cancelLabel:i("st.dirty.stay"),onConfirm:()=>{L(!1),n()},onCancel:()=>{L(!1)}}),e.jsx(Xe,{open:M!==null,stacked:!0,overlayId:"recipe-author-hook-scripts",title:i("st.recipeHook.consentTitle"),confirmLabel:i("st.recipe.savePackage"),cancelLabel:i("st.dirty.stay"),tone:"default",busy:Ee.isPending,onCancel:()=>{z(null)},onConfirm:()=>{const K=M;K!==null&&Ee.mutate({preview:K})},children:M?.hooks===void 0?null:e.jsx(Iu,{hooks:M.hooks,name:M.summary.name})})]})}function DP({hooks:t}){const{t:s}=D();return t==="off"?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-author-hooks":"off",children:s("st.recipeHook.dropped")}):t.length===0?null:e.jsxs("div",{className:"space-y-1.5 rounded-md bg-ink/[0.03] px-3 py-2","data-recipe-author-hooks":!0,children:[e.jsx("p",{className:"text-[11.5px] font-medium text-ink-soft",children:s("st.recipeHook.declared")}),e.jsx("ul",{className:"space-y-1.5",children:t.map((n,a)=>e.jsxs("li",{className:"space-y-0.5","data-recipe-author-hook":a,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-0.5",children:[e.jsx("span",{className:"text-[12px] text-ink-soft",children:n.event===void 0||Qr(n.event)===void 0?n.event??s("st.recipeHook.eventUndeclared"):s(Qr(n.event))}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-author-hook-root":!0,children:n.root===void 0?s("st.recipeHook.rootDefault"):s("st.recipeHook.root",{root:n.root})})]}),e.jsx("code",{className:"block overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11.5px] leading-5 text-ink",children:n.command??""})]},a))})]})}function FP({declaration:t,files:s,onChange:n,onInline:a,onSegments:i,onFile:r,onOff:o}){const{t:l}=D(),[c,d]=x.useState(!1),u=t?.prompts?.steering_sources??{};return e.jsxs("section",{className:"space-y-2 pt-4","data-recipe-steer-sources":!0,children:[e.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>{d(!c)},className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1 text-left outline-none transition-colors hover:bg-ink/[0.04] focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsx(Rt,{open:c,className:"text-ink-soft"}),e.jsx("span",{className:"text-[12px] font-medium text-ink-soft",children:l("st.recipe.steerSources")}),!c&&Object.keys(u).length>0?e.jsx("span",{className:"truncate text-[12px] text-ink-faint",children:l("st.recipe.steerSourcesCount",{count:String(Object.keys(u).length)})}):null]}),c?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-steer-hint":!0,children:l("st.recipe.steerSourcesHint")}),e.jsx("ul",{className:"divide-y divide-hairline",children:Oi.map(p=>e.jsx("li",{"data-recipe-steer-source":p,className:"py-2 first:pt-1",children:e.jsx(UP,{source:p,declaration:u[p],files:s,onMode:h=>{n(p,{...u[p],mode:h})},onInline:h=>{a(p,h)},onSegments:h=>{i(p,h)},onFile:(h,b)=>{r(p,h,b)},onOff:()=>{o(p)}})},p))})]}):null]})}function qP(t){return t===void 0?"inline":t.kind==="segments"?"segments":t.kind}function BP(t,s){return s===void 0?t("st.recipe.inheritsSlot"):s.kind==="file"?t("st.recipe.fileKind"):s.kind==="off"?t("st.recipe.slotOffKind"):s.kind==="segments"?t("st.recipe.segmentCount",{count:String(s.parts.length)}):t("st.recipe.inlineKind")}const KP=["off","inherit","custom"];function UP({source:t,declaration:s,files:n,onMode:a,onInline:i,onSegments:r,onFile:o,onOff:l}){const{t:c}=D(),d=s?.mode??"off",u=s?.steering,p=c(`st.steerSource.${t}`),h=()=>e.jsxs("label",{className:"flex flex-wrap items-center gap-1.5 text-[11.5px] text-ink-soft",children:[e.jsx("span",{className:"text-ink-faint",children:c("st.recipe.slotFrom")}),e.jsx(Qe,{id:`recipe-steer-shape-${t}`,ariaLabel:c("st.recipe.slotFrom"),dataAttr:"data-recipe-steer-shape",value:qP(u),choices:[{value:"inline",label:c("st.recipe.inlineKind")},{value:"file",label:c("st.recipe.fileKind")},{value:"segments",label:c("st.recipe.segmentCount",{count:"2"})},{value:"off",label:c("st.recipe.slotOffKind")}],onChange:b=>{b==="file"?o(""):b==="segments"?r([{kind:"inline",text:""},{kind:"inline",text:""}]):b==="off"?l():i("")}})]});return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5",children:[e.jsx("span",{className:"text-[13px] leading-5 text-ink","data-recipe-steer-label":t,children:p}),e.jsx(He,{ariaLabel:c("st.steerSource.modeAria",{source:p}),value:d,dataAttr:"data-recipe-steer-mode",onChange:a,choices:KP.map(b=>({value:b,label:c(HP[b])}))})]}),d!=="custom"?null:e.jsxs("div",{className:"space-y-2","data-recipe-steer-editor":t,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-soft","data-recipe-steer-shape-kind":t,children:BP(c,u)}),h()]}),u?.kind==="off"?e.jsxs("div",{className:"space-y-2","data-recipe-steer-prose-off":t,children:[e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:c("st.recipe.steerSourceProseOff")}),e.jsx("button",{type:"button",className:"w-fit text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-steer-restore":t,onClick:()=>{i("")},children:c("st.recipe.steerSourceRestore")})]}):u?.kind==="file"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:c("st.recipe.slotFile")}),e.jsx("input",{className:`${pt} font-mono`,"aria-label":c("st.recipe.slotFile"),"data-recipe-steer-file":t,value:u.file,onChange:b=>{o(b.target.value)},placeholder:"reminders/thread.md"})]}),e.jsx("textarea",{rows:5,spellCheck:!1,"aria-label":`${p}: ${u.file}`,"data-recipe-steer-file-body":t,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:n[u.file]??"",onChange:b=>{o(u.file,b.target.value)}})]}):u?.kind==="segments"?e.jsx("div",{className:"space-y-2.5","data-recipe-steer-segments":t,children:u.parts.map((b,m)=>{const f=b.kind==="file"?b.file??"":c("st.recipe.inlineKind");return e.jsxs("div",{className:"space-y-1.5","data-recipe-steer-segment":m,"data-recipe-segment-kind":b.kind,children:[e.jsxs("p",{className:"break-all font-mono text-[11px] text-ink-faint",children:[m+1," · ",f]}),e.jsx("textarea",{rows:4,spellCheck:!1,"aria-label":`${p} ${m+1}: ${f}`,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:b.kind==="file"?n[b.file??""]??"":b.text??"",onChange:g=>{b.kind==="file"?o(b.file??"",g.target.value):r(u.parts.map((v,y)=>y===m?{...v,text:g.target.value}:v))}})]},m)})}):e.jsx("textarea",{rows:5,spellCheck:!1,"aria-label":p,"data-recipe-steer-prose":t,placeholder:c("st.recipe.slotProseEmpty"),className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:u?.kind==="inline"?u.text:"",onChange:b=>{i(b.target.value)}})]})]})}const HP={off:"st.steerSource.modeOff",inherit:"st.steerSource.modeInherit",custom:"st.steerSource.modeCustom"};function zP({slot:t,label:s,declaration:n,files:a,onInline:i,onSegments:r,onFile:o}){const{t:l}=D(),c=n?.prompts?.[t];return c?.kind==="off"?e.jsxs("div",{className:"space-y-2","data-recipe-prose-slot":t,children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:s}),e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-prose-off":!0,children:l("st.recipe.slotOff")}),e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-prose-restore":t,onClick:()=>{i("")},children:l("st.recipe.restoreSlot")})]}):c?.kind==="file"?e.jsxs("div",{className:"space-y-1.5","data-recipe-prose-slot":t,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:s}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:c.file})]}),e.jsx("textarea",{rows:8,spellCheck:!1,"aria-label":`${s}: ${c.file}`,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:a[c.file]??"",onChange:d=>{o(c.file,d.target.value)}})]}):c===void 0?e.jsxs("div",{className:"space-y-1.5","data-recipe-prose-slot":t,children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:s}),e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-prose-inherited":!0,children:l("st.recipe.inheritsSlot")}),e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-prose-declare":t,onClick:()=>{i("")},children:l("st.recipe.declareHere")})]}):c.kind==="segments"?e.jsxs("div",{className:"space-y-3","data-recipe-prose-slot":t,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:s}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-prose-kind":t,children:l("st.recipe.segmentCount",{count:String(c.parts.length)})})]}),c.parts.map((d,u)=>{const p=d.kind==="file"?d.file??"":l("st.recipe.inlineKind");return e.jsxs("div",{className:"space-y-1.5","data-recipe-prose-segment":u,"data-recipe-segment-kind":d.kind,children:[e.jsxs("p",{className:"break-all font-mono text-[11px] text-ink-faint",children:[u+1," · ",p]}),e.jsx("textarea",{rows:4,spellCheck:!1,"aria-label":`${s} ${u+1}: ${p}`,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:d.kind==="file"?a[d.file??""]??"":d.text??"",onChange:h=>{d.kind==="file"?o(d.file??"",h.target.value):r(c.parts.map((b,m)=>m===u?{...b,text:h.target.value}:b))}})]},u)})]}):e.jsxs("div",{className:"space-y-1.5","data-recipe-prose-slot":t,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:s}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-recipe-prose-kind":t,children:l("st.recipe.inlineKind")})]}),e.jsx("textarea",{rows:8,spellCheck:!1,"aria-label":s,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,value:c.text,onChange:d=>{i(d.target.value)}})]})}function Lv({onFork:t}){const{t:s}=D();return e.jsxs("div",{className:"min-w-0 space-y-3","data-recipe-fork-choice":!0,children:[e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:s("st.recipe.forkChoiceHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink transition-colors hover:border-hairline-strong","data-recipe-fork-copy":!0,onClick:()=>{t("copy")},children:s("st.recipe.forkCopy")}),e.jsx("button",{type:"button",className:"rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink","data-recipe-fork-extend":!0,onClick:()=>{t("extend")},children:s("st.recipe.forkExtend")})]})]})}var qt=Uint8Array,as=Uint16Array,Pu=Int32Array,Au=new qt([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),$u=new qt([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Gx=new qt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Mv=function(t,s){for(var n=new as(31),a=0;a<31;++a)n[a]=s+=1<<t[a-1];for(var i=new Pu(n[30]),a=1;a<30;++a)for(var r=n[a];r<n[a+1];++r)i[r]=r-n[a]<<5|a;return{b:n,r:i}},Ov=Mv(Au,2),QP=Ov.b,Vc=Ov.r;QP[28]=258,Vc[258]=28;var GP=Mv($u,0),Wx=GP.r,Yc=new as(32768);for(var ut=0;ut<32768;++ut){var Vs=(ut&43690)>>1|(ut&21845)<<1;Vs=(Vs&52428)>>2|(Vs&13107)<<2,Vs=(Vs&61680)>>4|(Vs&3855)<<4,Yc[ut]=((Vs&65280)>>8|(Vs&255)<<8)>>1}var di=(function(t,s,n){for(var a=t.length,i=0,r=new as(s);i<a;++i)t[i]&&++r[t[i]-1];var o=new as(s);for(i=1;i<s;++i)o[i]=o[i-1]+r[i-1]<<1;var l;if(n){l=new as(1<<s);var c=15-s;for(i=0;i<a;++i)if(t[i])for(var d=i<<4|t[i],u=s-t[i],p=o[t[i]-1]++<<u,h=p|(1<<u)-1;p<=h;++p)l[Yc[p]>>c]=d}else for(l=new as(a),i=0;i<a;++i)t[i]&&(l[i]=Yc[o[t[i]-1]++]>>15-t[i]);return l}),In=new qt(288);for(var ut=0;ut<144;++ut)In[ut]=8;for(var ut=144;ut<256;++ut)In[ut]=9;for(var ut=256;ut<280;++ut)In[ut]=7;for(var ut=280;ut<288;++ut)In[ut]=8;var Wr=new qt(32);for(var ut=0;ut<32;++ut)Wr[ut]=5;var WP=di(In,9,0),VP=di(Wr,5,0),Dv=function(t){return(t+7)/8|0},Fv=function(t,s,n){return(n==null||n>t.length)&&(n=t.length),new qt(t.subarray(s,n))},YP=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Lo=function(t,s,n){var a=new Error(s||YP[t]);if(a.code=t,Error.captureStackTrace&&Error.captureStackTrace(a,Lo),!n)throw a;return a},Ts=function(t,s,n){n<<=s&7;var a=s/8|0;t[a]|=n,t[a+1]|=n>>8},Ha=function(t,s,n){n<<=s&7;var a=s/8|0;t[a]|=n,t[a+1]|=n>>8,t[a+2]|=n>>16},Bl=function(t,s){for(var n=[],a=0;a<t.length;++a)t[a]&&n.push({s:a,f:t[a]});var i=n.length,r=n.slice();if(!i)return{t:Bv,l:0};if(i==1){var o=new qt(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(_,C){return _.f-C.f}),n.push({s:-1,f:25001});var l=n[0],c=n[1],d=0,u=1,p=2;for(n[0]={s:-1,f:l.f+c.f,l,r:c};u!=i-1;)l=n[n[d].f<n[p].f?d++:p++],c=n[d!=u&&n[d].f<n[p].f?d++:p++],n[u++]={s:-1,f:l.f+c.f,l,r:c};for(var h=r[0].s,a=1;a<i;++a)r[a].s>h&&(h=r[a].s);var b=new as(h+1),m=Jc(n[u-1],b,0);if(m>s){var a=0,f=0,g=m-s,v=1<<g;for(r.sort(function(C,S){return b[S.s]-b[C.s]||C.f-S.f});a<i;++a){var y=r[a].s;if(b[y]>s)f+=v-(1<<m-b[y]),b[y]=s;else break}for(f>>=g;f>0;){var w=r[a].s;b[w]<s?f-=1<<s-b[w]++-1:++a}for(;a>=0&&f;--a){var N=r[a].s;b[N]==s&&(--b[N],++f)}m=s}return{t:new qt(b),l:m}},Jc=function(t,s,n){return t.s==-1?Math.max(Jc(t.l,s,n+1),Jc(t.r,s,n+1)):s[t.s]=n},Vx=function(t){for(var s=t.length;s&&!t[--s];);for(var n=new as(++s),a=0,i=t[0],r=1,o=function(c){n[a++]=c},l=1;l<=s;++l)if(t[l]==i&&l!=s)++r;else{if(!i&&r>2){for(;r>138;r-=138)o(32754);r>2&&(o(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(o(i),--r;r>6;r-=6)o(8304);r>2&&(o(r-3<<5|8208),r=0)}for(;r--;)o(i);r=1,i=t[l]}return{c:n.subarray(0,a),n:s}},za=function(t,s){for(var n=0,a=0;a<s.length;++a)n+=t[a]*s[a];return n},qv=function(t,s,n){var a=n.length,i=Dv(s+2);t[i]=a&255,t[i+1]=a>>8,t[i+2]=t[i]^255,t[i+3]=t[i+1]^255;for(var r=0;r<a;++r)t[i+r+4]=n[r];return(i+4+a)*8},Yx=function(t,s,n,a,i,r,o,l,c,d,u){Ts(s,u++,n),++i[256];for(var p=Bl(i,15),h=p.t,b=p.l,m=Bl(r,15),f=m.t,g=m.l,v=Vx(h),y=v.c,w=v.n,N=Vx(f),_=N.c,C=N.n,S=new as(19),k=0;k<y.length;++k)++S[y[k]&31];for(var k=0;k<_.length;++k)++S[_[k]&31];for(var j=Bl(S,7),T=j.t,A=j.l,P=19;P>4&&!T[Gx[P-1]];--P);var R=d+5<<3,L=za(i,In)+za(r,Wr)+o,I=za(i,h)+za(r,f)+o+14+3*P+za(S,T)+2*S[16]+3*S[17]+7*S[18];if(c>=0&&R<=L&&R<=I)return qv(s,u,t.subarray(c,c+d));var $,E,M,z;if(Ts(s,u,1+(I<L)),u+=2,I<L){$=di(h,b,0),E=h,M=di(f,g,0),z=f;var H=di(T,A,0);Ts(s,u,w-257),Ts(s,u+5,C-1),Ts(s,u+10,P-4),u+=14;for(var k=0;k<P;++k)Ts(s,u+3*k,T[Gx[k]]);u+=3*P;for(var U=[y,_],X=0;X<2;++X)for(var q=U[X],k=0;k<q.length;++k){var F=q[k]&31;Ts(s,u,H[F]),u+=T[F],F>15&&(Ts(s,u,q[k]>>5&127),u+=q[k]>>12)}}else $=WP,E=In,M=VP,z=Wr;for(var k=0;k<l;++k){var V=a[k];if(V>255){var F=V>>18&31;Ha(s,u,$[F+257]),u+=E[F+257],F>7&&(Ts(s,u,V>>23&31),u+=Au[F]);var se=V&31;Ha(s,u,M[se]),u+=z[se],se>3&&(Ha(s,u,V>>5&8191),u+=$u[se])}else Ha(s,u,$[V]),u+=E[V]}return Ha(s,u,$[256]),u+E[256]},JP=new Pu([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Bv=new qt(0),ZP=function(t,s,n,a,i,r){var o=r.z||t.length,l=new qt(a+o+5*(1+Math.ceil(o/7e3))+i),c=l.subarray(a,l.length-i),d=r.l,u=(r.r||0)&7;if(s){u&&(c[0]=r.r>>3);for(var p=JP[s-1],h=p>>13,b=p&8191,m=(1<<n)-1,f=r.p||new as(32768),g=r.h||new as(m+1),v=Math.ceil(n/3),y=2*v,w=function(Ee){return(t[Ee]^t[Ee+1]<<v^t[Ee+2]<<y)&m},N=new Pu(25e3),_=new as(288),C=new as(32),S=0,k=0,j=r.i||0,T=0,A=r.w||0,P=0;j+2<o;++j){var R=w(j),L=j&32767,I=g[R];if(f[L]=I,g[R]=L,A<=j){var $=o-j;if((S>7e3||T>24576)&&($>423||!d)){u=Yx(t,c,0,N,_,C,k,T,P,j-P,u),T=S=k=0,P=j;for(var E=0;E<286;++E)_[E]=0;for(var E=0;E<30;++E)C[E]=0}var M=2,z=0,H=b,U=L-I&32767;if($>2&&R==w(j-U))for(var X=Math.min(h,$)-1,q=Math.min(32767,j),F=Math.min(258,$);U<=q&&--H&&L!=I;){if(t[j+M]==t[j+M-U]){for(var V=0;V<F&&t[j+V]==t[j+V-U];++V);if(V>M){if(M=V,z=U,V>X)break;for(var se=Math.min(U,V-2),Y=0,E=0;E<se;++E){var O=j-U+E&32767,B=f[O],le=O-B&32767;le>Y&&(Y=le,I=O)}}}L=I,I=f[L],U+=L-I&32767}if(z){N[T++]=268435456|Vc[M]<<18|Wx[z];var re=Vc[M]&31,ae=Wx[z]&31;k+=Au[re]+$u[ae],++_[257+re],++C[ae],A=j+M,++S}else N[T++]=t[j],++_[t[j]]}}for(j=Math.max(j,A);j<o;++j)N[T++]=t[j],++_[t[j]];u=Yx(t,c,d,N,_,C,k,T,P,j-P,u),d||(r.r=u&7|c[u/8|0]<<3,u-=7,r.h=g,r.p=f,r.i=j,r.w=A)}else{for(var j=r.w||0;j<o+d;j+=65535){var ne=j+65535;ne>=o&&(c[u/8|0]=d,ne=o),u=qv(c,u+1,t.subarray(j,ne))}r.i=o}return Fv(l,0,a+Dv(u)+i)},XP=(function(){for(var t=new Int32Array(256),s=0;s<256;++s){for(var n=s,a=9;--a;)n=(n&1&&-306674912)^n>>>1;t[s]=n}return t})(),eA=function(){var t=-1;return{p:function(s){for(var n=t,a=0;a<s.length;++a)n=XP[n&255^s[a]]^n>>>8;t=n},d:function(){return~t}}},tA=function(t,s,n,a,i){if(!i&&(i={l:1},s.dictionary)){var r=s.dictionary.subarray(-32768),o=new qt(r.length+t.length);o.set(r),o.set(t,r.length),t=o,i.w=r.length}return ZP(t,s.level==null?6:s.level,s.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+s.mem,n,a,i)},Kv=function(t,s){var n={};for(var a in t)n[a]=t[a];for(var a in s)n[a]=s[a];return n},It=function(t,s,n){for(;n;++s)t[s]=n,n>>>=8};function sA(t,s){return tA(t,s||{},0,0)}var Uv=function(t,s,n,a){for(var i in t){var r=t[i],o=s+i,l=a;Array.isArray(r)&&(l=Kv(a,r[1]),r=r[0]),r instanceof qt?n[o]=[r,l]:(n[o+="/"]=[new qt(0),l],Uv(r,o,n,a))}},Jx=typeof TextEncoder<"u"&&new TextEncoder,nA=typeof TextDecoder<"u"&&new TextDecoder,aA=0;try{nA.decode(Bv,{stream:!0}),aA=1}catch{}function Zx(t,s){var n;if(Jx)return Jx.encode(t);for(var a=t.length,i=new qt(t.length+(t.length>>1)),r=0,o=function(d){i[r++]=d},n=0;n<a;++n){if(r+5>i.length){var l=new qt(r+8+(a-n<<1));l.set(i),i=l}var c=t.charCodeAt(n);c<128||s?o(c):c<2048?(o(192|c>>6),o(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|t.charCodeAt(++n)&1023,o(240|c>>18),o(128|c>>12&63),o(128|c>>6&63),o(128|c&63)):(o(224|c>>12),o(128|c>>6&63),o(128|c&63))}return Fv(i,0,r)}var Zc=function(t){var s=0;if(t)for(var n in t){var a=t[n].length;a>65535&&Lo(9),s+=a+4}return s},Xx=function(t,s,n,a,i,r,o,l){var c=a.length,d=n.extra,u=l&&l.length,p=Zc(d);It(t,s,o!=null?33639248:67324752),s+=4,o!=null&&(t[s++]=20,t[s++]=n.os),t[s]=20,s+=2,t[s++]=n.flag<<1|(r<0&&8),t[s++]=i&&8,t[s++]=n.compression&255,t[s++]=n.compression>>8;var h=new Date(n.mtime==null?Date.now():n.mtime),b=h.getFullYear()-1980;if((b<0||b>119)&&Lo(10),It(t,s,b<<25|h.getMonth()+1<<21|h.getDate()<<16|h.getHours()<<11|h.getMinutes()<<5|h.getSeconds()>>1),s+=4,r!=-1&&(It(t,s,n.crc),It(t,s+4,r<0?-r-2:r),It(t,s+8,n.size)),It(t,s+12,c),It(t,s+14,p),s+=16,o!=null&&(It(t,s,u),It(t,s+6,n.attrs),It(t,s+10,o),s+=14),t.set(a,s),s+=c,p)for(var m in d){var f=d[m],g=f.length;It(t,s,+m),It(t,s+2,g),t.set(f,s+4),s+=4+g}return u&&(t.set(l,s),s+=u),s},iA=function(t,s,n,a,i){It(t,s,101010256),It(t,s+8,n),It(t,s+10,n),It(t,s+12,a),It(t,s+16,i)};function rA(t,s){s||(s={});var n={},a=[];Uv(t,"",n,s);var i=0,r=0;for(var o in n){var l=n[o],c=l[0],d=l[1],u=d.level==0?0:8,p=Zx(o),h=p.length,b=d.comment,m=b&&Zx(b),f=m&&m.length,g=Zc(d.extra);h>65535&&Lo(11);var v=u?sA(c,d):c,y=v.length,w=eA();w.p(c),a.push(Kv(d,{size:c.length,crc:w.d(),c:v,f:p,m,u:h!=o.length||m&&b.length!=f,o:i,compression:u})),i+=30+h+g+y,r+=76+2*(h+g)+(f||0)+y}for(var N=new qt(r+22),_=i,C=r-i,S=0;S<a.length;++S){var p=a[S];Xx(N,p.o,p,p.f,p.u,p.c.length);var k=30+p.f.length+Zc(p.extra);N.set(p.c,p.o+k),Xx(N,i,p,p.f,p.u,p.c.length,p.o,p.m),i+=16+k+(p.m?p.m.length:0)}return iA(N,i,a.length,C,_),N}function oA(t){const n=[t.name,t.version].filter(a=>typeof a=="string"&&a.trim()!=="").join("-").replaceAll(/[^\w.-]+/gu,"-").replaceAll(/^[-.]+/gu,"").replaceAll(/[-.]+$/gu,"");return`${n===""?"recipe":n}.zip`}function lA(t){const s=new TextEncoder,n={};for(const[a,i]of Object.entries(t))n[a]=s.encode(i);return rA(n,{level:0})}function cA(t,s){const n=new Blob([t],{type:"application/zip"}),a=URL.createObjectURL(n),i=document.createElement("a");i.href=a,i.download=s,i.rel="noopener",document.body.append(i),i.click(),i.remove(),setTimeout(()=>{URL.revokeObjectURL(a)},0)}const dA="rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50";function uA({installationId:t,name:s}){const{t:n,locale:a}=D(),{client:i}=be(),[r,o]=x.useState(!1),[l,c]=x.useState(null);return e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",className:dA,disabled:r,"data-recipe-download-zip":t,onClick:()=>{o(!0),c(null),i.exportRecipe(t).then(d=>{cA(lA(d.files),oA({name:d.name===""?s:d.name,version:d.revision.replace(/^sha256:/u,"").slice(0,8)}))}).catch(d=>{c(n("st.recipe.exportFailed",{detail:oe(a,d)}))}).finally(()=>{o(!1)})},children:n(r?"st.recipe.exporting":"st.recipe.downloadZip")}),l!==null?e.jsx("p",{role:"alert",className:"w-full text-[12px] leading-5 text-danger","data-recipe-export-error":!0,children:l}):null]})}const eh=[{id:"system",key:"st.recipe.slot.system"},{id:"steering",key:"st.recipe.slot.steering"},{id:"parent_steering",key:"st.recipe.slot.parent_steering"}];function Hv({detail:t,initialPosition:s="main"}){const{t:n}=D(),[a,i]=x.useState(s),r=t.resolved.branches[a==="sub"?"sub":a],o=Object.keys(t.resolved.model).toSorted(),l=c=>t.resolved.origins.filter(d=>d.position===(a==="sub"?"sub":a)&&d.slot===c);return e.jsxs("div",{className:"min-w-0 space-y-6","data-recipe-package":t.summary.installation_id,children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h3",{className:"font-display text-[28px] leading-9 tracking-tight text-ink","data-recipe-package-name":!0,children:t.summary.name}),e.jsxs("p",{className:"font-mono text-[11.5px] text-ink-faint","data-recipe-package-version":!0,children:[t.summary.version," · ",_n(t.resolved.revision)," ·"," ",t.summary.update_mode==="follow"?n("st.recipe.modeFollow"):n("st.recipe.modePinned")]}),t.summary.description!==void 0?e.jsx("p",{className:"pt-1 text-[13px] leading-6 text-ink-soft",children:t.summary.description}):null]}),t.summary.last_error!==void 0?e.jsx("p",{role:"status",className:"text-[12px] leading-5 text-amber-ink","data-recipe-package-stale":!0,children:n("st.recipe.updateFailedStillUsing",{version:t.summary.version,reason:Lg(t.summary.last_error)})}):null,t.summary.health==="unavailable"?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger","data-recipe-package-unavailable":!0,children:n("st.recipe.packageUnavailable")}):null,e.jsxs("section",{className:"space-y-2","data-recipe-effects":!0,children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:n("st.recipe.effects")}),e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:n("st.recipe.promptsReplaced")}),o.length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint",children:n("st.recipe.noParameterOverrides")}):e.jsx("dl",{className:"divide-y divide-hairline border-y border-hairline","data-recipe-model-overrides":!0,children:o.map(c=>{const d=t.resolved.model_origins[c];return e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-0.5 py-2","data-recipe-model-leaf":c,children:[e.jsx("dt",{className:"min-w-0 break-all font-mono text-[11.5px] text-ink-faint",children:c}),e.jsx("dd",{className:"min-w-0 flex-1 break-words text-right font-mono text-[12px] text-ink",children:mA(t.resolved.model[c])}),d===void 0?null:e.jsxs("p",{className:"w-full text-[11px] text-ink-faint",children:[d.manifest_id," ",d.version,d.file===void 0?"":` · ${d.file}`]})]},c)})})]}),e.jsxs("section",{className:"space-y-3","data-recipe-content":!0,children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:n("st.recipe.promptContent")}),e.jsx(He,{ariaLabel:n("st.recipe.readAs"),value:a,dataAttr:"data-recipe-read-position",onChange:i,choices:fE.map(c=>({value:c,label:n(c==="main"?"st.modelScope.main":c==="sub"?"st.recipe.position.subShared":"st.modelScope.independent")}))}),a==="sub"?e.jsx(he,{children:n("st.recipe.sharedIsSubHint")}):null,eh.map(({id:c,key:d})=>{const u=r[c];return u===void 0||u===""?null:e.jsxs("div",{className:"space-y-1.5","data-recipe-slot":c,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("h5",{className:"text-[12px] font-medium text-ink-soft",children:n(d)}),l(c).length===0?null:e.jsx("span",{className:"text-[11px] text-ink-faint","data-recipe-slot-origins":c,children:l(c).map(p=>p.file??`${p.manifest_id} ${p.version}`).join(" · ")})]}),e.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap rounded-md bg-ink/[0.035] px-3 py-2 font-mono text-[12px] leading-5 text-ink-soft",children:u})]},c)}),r.anchor===void 0?null:e.jsxs("div",{className:"space-y-1.5","data-recipe-slot":"anchor",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("h5",{className:"text-[12px] font-medium text-ink-soft",children:n("st.recipe.slot.anchor")}),e.jsx("span",{className:"text-[11px] text-ink-faint",children:n("st.recipe.anchorWindow",{steps:r.anchor.steps,scope:n(`st.recipe.scope.${r.anchor.scope}`)})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md bg-ink/[0.035] px-3 py-2 font-mono text-[12px] leading-5 text-ink-soft",children:r.anchor.content})]}),e.jsx(pA,{branch:r}),Object.keys(r.fields).length===0?null:e.jsxs("div",{className:"space-y-2","data-recipe-slot":"fields",children:[e.jsx("h5",{className:"text-[12px] font-medium text-ink-soft",children:n("st.recipe.slotFields")}),e.jsx("dl",{className:"divide-y divide-hairline border-y border-hairline",children:Object.entries(r.fields).toSorted(([c],[d])=>c.localeCompare(d)).map(([c,d])=>e.jsxs("div",{className:"space-y-0.5 py-2",children:[e.jsx("dt",{className:"break-all font-mono text-[11.5px] text-ink-faint",children:c}),e.jsx("dd",{className:"break-words text-[12px] leading-5 text-ink-soft",children:d})]},c))})]}),eh.every(({id:c})=>r[c]===void 0||r[c]==="")&&r.anchor===void 0&&Object.keys(r.fields).length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-no-prompts":!0,children:n("st.recipe.noPromptForIdentity")}):null]}),e.jsxs("section",{className:"space-y-2","data-recipe-source":!0,children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:n("st.recipe.sourceAndVersion")}),e.jsxs("dl",{className:"space-y-1.5",children:[e.jsx(Qa,{label:n("st.recipe.sourceLabel"),value:t.summary.source.locator,mono:!0,selectable:!0}),t.summary.source.sha256===void 0?null:e.jsx(Qa,{label:n("st.recipe.sha256"),value:t.summary.source.sha256,mono:!0,selectable:!0}),e.jsx(Qa,{label:n("st.recipe.revisionFull"),value:t.resolved.revision,mono:!0,selectable:!0}),t.summary.copied_from===void 0?null:e.jsx(Qa,{label:n("st.recipe.copiedFrom"),value:t.summary.copied_from}),t.resolved.dependencies.length===0?null:e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"text-[11.5px] text-ink-faint",children:n("st.recipe.parentChain")}),e.jsx("dd",{className:"space-y-0.5",children:t.resolved.dependencies.map(c=>e.jsxs("p",{className:"break-all font-mono text-[11px] text-ink-soft",children:[c.manifest_id," ",c.version," · ",c.source.locator]},c.source.locator))})]}),t.used_by.length===0?null:e.jsx(Qa,{label:n("st.recipe.usedBy"),value:t.used_by.join(", "),mono:!0,selectable:!0})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:n("st.recipe.packageFiles")}),e.jsx("p",{className:"break-all font-mono text-[11px] text-ink-soft",children:bE(t.files).join(" · ")})]}),t.history.length===0?null:e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:n("st.recipe.history")}),e.jsx("ul",{className:"space-y-0.5","data-recipe-history":!0,children:t.history.map(c=>e.jsx("li",{className:"break-all font-mono text-[11px] text-ink-soft",children:_n(c)},c))})]})]})]})}function pA({branch:t}){const{t:s}=D();return e.jsxs("div",{className:"space-y-1.5","data-recipe-cadence":!0,children:[e.jsx("h5",{className:"text-[12px] font-medium text-ink-soft",children:s("st.modelPrompt.cadence")}),e.jsxs("dl",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:"text-[12px] text-ink-faint",children:s("st.modelPrompt.cadenceTurn")}),e.jsx("dd",{className:"text-[12px] text-ink",children:th(t.steering_on_turn,!0)})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:"text-[12px] text-ink-faint",children:s("st.modelPrompt.cadenceInput")}),e.jsx("dd",{className:"text-[12px] text-ink",children:th(t.steering_on_input,!0)})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:"text-[12px] text-ink-faint",children:s("st.modelPrompt.cadenceInterval")}),e.jsx("dd",{className:"font-mono text-[12px] text-ink",children:t.steering_interval_steps??0})]})]})]})}function Qa({label:t,value:s,mono:n=!1,selectable:a=!1}){return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("dt",{className:"text-[11.5px] text-ink-faint",children:t}),e.jsx("dd",{className:`break-all text-[12px] leading-5 text-ink-soft ${n?"font-mono":""} ${a?"select-text":""}`,children:s})]})}function mA(t){return t===!1?"false":t===!0?"true":t===null?"null":typeof t=="string"?t:typeof t=="number"||typeof t=="bigint"?String(t):Array.isArray(t)?`[${t.length}]`:JSON.stringify(t)}function th(t,s){return t===void 0?String(s):t?"on":"off"}const sh="rounded-md bg-accent px-3 py-1.5 text-[12px] font-medium text-on-accent transition-colors hover:bg-accent-deep disabled:cursor-not-allowed disabled:bg-hairline disabled:text-ink-faint",nh="rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50";function zv({onInstalled:t,onApply:s,onFeedback:n}){const{t:a,locale:i}=D(),[r,o]=x.useState(""),[l,c]=x.useState(""),[d,u]=x.useState(null),[p,h]=x.useState(null),{client:b}=be(),m=n??h,f=yt(async _=>b.previewRecipe({source:{locator:_.locator,sha256:_.sha256}}),{onSuccess:u,onError:_=>{u(null),m({tone:"error",text:a("st.recipe.previewFailed",{detail:oe(i,_)})})}}),g=yt(async _=>b.installRecipe({preview_id:_.preview.preview_id,...Cu(_.preview)}),{onSuccess:(_,C)=>{m(null),u(null),t(_.installation_id),C.applyAfterInstall&&s!==void 0&&s(_.installation_id)},onError:_=>{m({tone:"error",text:a("st.recipe.installFailed",{detail:oe(i,_)})})}}),v=l.trim(),y=v!==""&&!/^[0-9a-fA-F]{64}$/u.test(v),w=d?.hooks,N=d!==null&&Ro(d);return e.jsxs("form",{className:"min-w-0 space-y-3","data-recipe-import":!0,onSubmit:_=>{_.preventDefault()},children:[e.jsxs("label",{className:$e,children:[a("st.recipe.source"),e.jsx("input",{className:pt+" mt-1 w-full font-mono",value:r,"data-recipe-import-locator":!0,placeholder:"https://example.com/recipes/clear-work/recipe.toml",onChange:_=>{o(_.target.value),u(null)}})]}),e.jsxs("label",{className:$e,children:[a("st.recipe.sha256"),e.jsx("input",{className:pt+" mt-1 w-full font-mono",value:l,"data-recipe-import-sha":!0,spellCheck:!1,autoComplete:"off","aria-invalid":y,placeholder:a("st.recipe.sha256Optional"),onChange:_=>{c(_.target.value),u(null)}}),y?e.jsx("span",{className:"mt-1 block text-[12px] font-normal leading-4 text-ink-faint",children:a("cap.source.shaInvalid")}):null]}),e.jsx(he,{children:a("st.recipe.sourceHelp")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx("button",{type:"button",className:nh,disabled:f.isPending||r.trim()===""||y,"data-recipe-preview":!0,onClick:()=>{f.mutate({locator:r.trim(),sha256:v===""?void 0:v.toLowerCase()})},children:a(f.isPending?"st.recipe.preparing":"st.recipe.previewRecipe")})}),d!==null?e.jsxs("div",{className:"space-y-2 pt-3","data-recipe-preview":!0,children:[e.jsx("p",{className:"font-display text-[15px] text-ink",children:d.summary.name}),e.jsxs("p",{className:"font-mono text-[11px] text-ink-faint",children:[d.summary.version," · ",_n(d.resolved.revision)]}),d.summary.description!==void 0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:d.summary.description}):null,N&&w!==void 0?e.jsx(Iu,{hooks:w,name:d.summary.name}):w===void 0||w.scripts.length===0?null:e.jsx($v,{hooks:w}),d.diagnostics.length===0?null:e.jsx("ul",{className:"space-y-1","data-recipe-preview-diagnostics":!0,children:d.diagnostics.map((_,C)=>e.jsx("li",{className:"text-[12px] leading-5 text-amber-ink",children:_.path===void 0?_.message:`${_.path}: ${_.message}`},C))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s===void 0?null:e.jsx("button",{type:"button",className:sh,disabled:g.isPending,"data-recipe-install-apply":!0,onClick:()=>{g.mutate({preview:d,applyAfterInstall:!0})},children:a("st.recipe.installAndApply")}),e.jsx("button",{type:"button",className:s===void 0?sh:nh,disabled:g.isPending,"data-recipe-install-only":!0,onClick:()=>{g.mutate({preview:d,applyAfterInstall:!1})},children:a("st.recipe.installOnly")})]})]}):null,n===void 0&&p!==null?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:p.text}):null]})}function xA({modelId:t,modelName:s,appliedId:n,onApply:a,onClose:i,onCustomize:r,onShowManual:o}){const{t:l,locale:c}=D(),[d,u]=x.useState("installed"),[p,h]=x.useState(""),[b,m]=x.useState(null),[f,g]=x.useState("list"),v=x.useRef(null);x.useEffect(()=>{f==="detail"&&v.current?.scrollIntoView({block:"nearest"})},[f,b]);const y=x.useRef(null);x.useEffect(()=>{v.current?.focus({preventScroll:!0})},[]),x.useEffect(()=>{if(f!=="detail")return;(y.current?.querySelector("button:not([disabled]), input:not([disabled]), [href], textarea:not([disabled])")??y.current)?.focus({preventScroll:!0})},[f,b]);const w=$o(),N=w.data??[],_=p.trim().toLowerCase(),C=_===""?N:N.filter($=>`${$.name} ${$.manifest_id} ${$.source.locator}`.toLowerCase().includes(_)),S=b===null?void 0:N.find($=>$.installation_id===b),k=fA(b),[j,T]=x.useState(null),[A,P]=x.useState(!1),R=async $=>{P(!0),T(null);try{await a($)}catch(E){T({tone:"error",text:l("st.recipe.applyFailed",{detail:oe(c,E)})})}finally{P(!1)}},L=e.jsxs("div",{className:"min-w-0 space-y-3","data-recipe-studio-list":!0,children:[e.jsx("div",{className:"flex flex-wrap gap-1 border-b border-hairline",role:"tablist","data-recipe-studio-tabs":!0,children:[["installed","st.recipe.tabInstalled"],["market","st.recipe.tabMarket"],["import","st.recipe.tabImport"]].map(([$,E])=>e.jsx("button",{type:"button",role:"tab","aria-selected":d===$,"data-recipe-studio-tab":$,className:`-mb-px border-b-2 px-2 py-1.5 text-[12px] outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${d===$?"border-accent text-ink":"border-transparent text-ink-faint hover:text-ink-soft"}`,onClick:()=>{u($)},children:l(E)},$))}),d==="installed"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:$e,children:[e.jsx("span",{className:"sr-only",children:l("st.recipe.search")}),e.jsx("input",{className:`${pt} w-full`,value:p,"data-recipe-studio-search":!0,placeholder:l("st.recipe.searchPlaceholder"),onChange:$=>{h($.target.value)}})]}),w.isError?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:l("st.recipe.listFailed",{detail:oe(c,w.error)})}):C.length===0?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint",children:l(N.length===0?"st.recipe.noneInstalled":"st.recipe.searchEmpty")}),N.length===0?e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-studio-goto-import":!0,onClick:()=>{u("import")},children:l("st.recipe.fromUrlAdd")}):e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-studio-clear-search":!0,onClick:()=>{h("")},children:l("st.recipe.clearSearch")})]}):e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline","data-recipe-studio-list-rows":!0,children:C.map($=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-recipe-studio-row":$.installation_id,"aria-current":$.installation_id===b,className:`flex w-full min-w-0 flex-col items-start gap-0.5 px-2 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${$.installation_id===b?"bg-ink/[0.05]":"hover:bg-ink/[0.03]"}`,onClick:()=>{m($.installation_id),g("detail")},children:[e.jsxs("span",{className:"flex w-full min-w-0 items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:$.name}),$.installation_id===n?e.jsx("span",{className:"shrink-0 text-[11px] text-selected-ink","data-recipe-in-use":!0,children:l("st.recipe.inUse")}):null]}),e.jsxs("span",{className:"w-full truncate font-mono text-[11px] text-ink-faint",children:[$.version," · ",_n($.revision),Fc($)?"":` · ${l("st.recipe.unavailable")}`]})]})},$.installation_id))})]}):null,d==="market"?e.jsx(bA,{onPicked:$=>{m($),g("detail")}}):null,d==="import"?e.jsx(zv,{onInstalled:$=>{m($),g("detail")},onApply:R}):null]}),I=S===void 0?null:e.jsxs("div",{className:"min-w-0 space-y-4","data-recipe-studio-detail":S.installation_id,ref:y,tabIndex:-1,children:[e.jsx("button",{type:"button",className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 md:hidden","data-recipe-studio-back":!0,onClick:()=>{g("list")},children:l("st.recipe.backToList")}),k.data===void 0?k.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:oe(c,k.error)}),e.jsx("button",{type:"button",className:ti,disabled:k.isFetching,onClick:()=>{k.refetch()},children:l("common.retry")})]}):e.jsx("p",{role:"status",className:"text-[12px] text-ink-faint",children:l("st.recipe.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(Hv,{detail:k.data}),e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex flex-wrap items-center gap-2 border-t border-hairline bg-panel px-1 py-3",children:[S.installation_id===n?e.jsx("span",{className:"text-[12px] text-ink-soft","data-recipe-already-applied":!0,children:l("st.recipe.alreadyApplied")}):e.jsx("button",{type:"button",className:hA,disabled:A||!Fc(S),"data-recipe-apply":S.installation_id,onClick:()=>{R(S.installation_id)},children:l(A?"st.recipe.applying":"st.recipe.applyToModel",{model:s})}),e.jsx("button",{type:"button",className:ti,"data-recipe-customize":S.installation_id,onClick:()=>{r(S.installation_id)},children:l(k.data.editable?"st.recipe.editPackage":"st.recipe.customizePackage")}),e.jsx("button",{type:"button",className:ti,"data-recipe-restore-manual":!0,onClick:()=>{o()},children:l("st.recipe.restoreManual")}),e.jsx(uA,{installationId:S.installation_id,name:S.name})]}),e.jsx(pe,{feedback:j})]})]});return e.jsxs("div",{className:"min-w-0 space-y-4","data-recipe-studio":t,ref:v,tabIndex:-1,children:[e.jsx(vo,{narrowPane:f,columns:"md:grid-cols-[minmax(240px,0.8fr)_minmax(0,2fr)]",list:L,detail:I??e.jsx("div",{className:"min-w-0",children:e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint",children:l("st.recipe.pickHint")})})}),e.jsx("button",{type:"button",className:ti,"data-recipe-studio-close":!0,onClick:i,children:l("common.close")})]})}const hA="rounded-md bg-accent px-3 py-1.5 text-[12px] font-medium text-on-accent transition-colors hover:bg-accent-deep disabled:cursor-not-allowed disabled:bg-hairline disabled:text-ink-faint",ti="rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50";function fA(t){const{client:s}=be();return je({queryKey:["recipe",t??""],queryFn:()=>s.getRecipe(t??""),enabled:t!==null&&t!=="",retry:!1})}function bA({onPicked:t}){const{t:s,locale:n}=D(),a=vv(),i=a.data??[],[r,o]=x.useState(null),l=i.find(p=>p.id===r)??i[0],[c,d]=x.useState(null),u=gA(d,n,t);return a.isError?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:s("st.recipe.marketFailed",{detail:oe(n,a.error)})}):i.length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-no-markets":!0,children:s("st.recipe.noMarkets")}):e.jsxs("div",{className:"min-w-0 space-y-2","data-recipe-market":!0,children:[i.length>1?e.jsx("div",{className:"flex flex-wrap gap-1.5","data-recipe-market-tabs":!0,children:i.map(p=>e.jsx("button",{type:"button","aria-pressed":l?.id===p.id,"data-recipe-market-tab":p.id,className:`rounded-md px-2 py-1 text-[12px] outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${l?.id===p.id?"bg-ink/[0.07] text-ink":"text-ink-soft hover:bg-ink/[0.04]"}`,onClick:()=>{o(p.id),d(null)},children:p.name},p.id))}):null,l?.offline===!0?e.jsx("p",{className:"text-[12px] leading-5 text-amber-ink","data-recipe-market-offline":!0,children:s("st.recipe.marketOffline",{name:l.name})}):null,l?.catalog===void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.recipe.marketNoCatalog")}):l.catalog.recipes.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.recipe.marketEmpty")}):e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline","data-recipe-market-list":!0,children:l.catalog.recipes.map(p=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3 py-2",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] text-ink",children:p.displayName}),e.jsx("span",{className:"block truncate text-[11px] text-ink-faint",children:p.version})]}),e.jsx("button",{type:"button",className:ti,disabled:u.install.isPending||u.previewAndInstall.isPending,"data-recipe-market-install":p.id,onClick:()=>{u.previewAndInstall.mutate({locator:p.source,sha256:p.sha256})},children:s("st.recipe.installOnly")})]},p.id))}),e.jsx(Xe,{open:u.awaitingConsent!==null,stacked:!0,overlayId:"recipe-market-hook-consent",title:s("st.recipeHook.consentTitle"),confirmLabel:s("st.recipe.installOnly"),cancelLabel:s("st.recipeHook.cancelInstall"),tone:"default",busy:u.install.isPending,onCancel:()=>{u.setAwaitingConsent(null)},onConfirm:()=>{const p=u.awaitingConsent;p!==null&&u.install.mutate({preview:p})},children:u.awaitingConsent?.hooks===void 0?null:e.jsx(Iu,{hooks:u.awaitingConsent.hooks,name:u.awaitingConsent.summary.name})}),c!==null?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:c}):null]})}function gA(t,s,n){const{t:a}=D(),{client:i}=be(),[r,o]=x.useState(null),l=yt(async d=>i.installRecipe({preview_id:d.preview.preview_id,...Cu(d.preview)}),{onSuccess:d=>{o(null),t(null),n(d.installation_id)},onError:d=>{o(null),t(a("st.recipe.installFailed",{detail:oe(s,d)}))}});return{previewAndInstall:yt(async d=>i.previewRecipe({source:{locator:d.locator,sha256:d.sha256}}),{onSuccess:d=>{t(null),Ro(d)?o(d):l.mutate({preview:d})},onError:d=>{t(a("st.recipe.installFailed",{detail:oe(s,d)}))}}),install:l,awaitingConsent:r,setAwaitingConsent:o}}const da="rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50";function vA({modelId:t,modelName:s,onCommitRecipe:n,appliedId:a,disabled:i=!1,onDraftChange:r}){const{t:o,locale:l}=D(),[c,d]=x.useState({kind:"summary"}),[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=x.useState(!1);x.useEffect(()=>{r?.(m)},[m,r]);const g=$o(),y=(g.data??[]).find(C=>C.installation_id===a),w=a!==void 0&&y===void 0&&!g.isPending,N=yt(C=>n(C),{alsoModelId:t,onSuccess:()=>{d({kind:"summary"}),b({tone:"success",text:o("st.recipe.applied")})},onError:C=>{b({tone:"error",text:o("st.recipe.applyFailed",{detail:oe(l,C)})})}}),_=yt(C=>n(null),{alsoModelId:t,onSuccess:()=>{d({kind:"summary"}),b({tone:"success",text:o("st.recipe.cleared")})},onError:C=>{b({tone:"error",text:o("st.recipe.applyFailed",{detail:oe(l,C)})})}});return c.kind==="studio"?e.jsx(xA,{modelId:t,modelName:s,appliedId:a,onApply:async C=>{await N.mutateAsync(C)},onClose:()=>{d({kind:"summary"})},onCustomize:C=>{d({kind:"fork",installationId:C})},onShowManual:()=>{_.mutate(void 0)}}):c.kind==="author"||c.kind==="fork"?e.jsx(yA,{installationId:c.installationId,onSaved:C=>{d({kind:"summary"}),p(C),f(!1)},onBack:()=>{d({kind:"summary"}),f(!1)},onDirtyChange:f,onFeedback:b}):e.jsxs("div",{className:"min-w-0 space-y-3","data-model-recipe":t,children:[a===void 0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-state-manual":!0,children:o("st.recipe.manualNotice")}):w?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-amber-ink","data-recipe-state-dangling":!0,children:o("st.recipe.dangling")}):y===void 0?null:e.jsxs("div",{className:"space-y-1","data-recipe-state-bound":!0,children:[e.jsx("p",{className:"font-display text-[18px] leading-7 text-ink","data-recipe-bound-name":!0,children:y.name}),e.jsxs("p",{className:"font-mono text-[11.5px] text-ink-faint","data-recipe-bound-version":!0,children:[y.version," · ",_n(y.revision)," ·"," ",y.update_mode==="follow"?o("st.recipe.modeFollow"):o("st.recipe.modePinned")]}),y.description===void 0?null:e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft",children:y.description}),y.update_available===!0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-update-available":!0,children:o("st.recipe.updateForNewBinding")}):null,y.last_error!==void 0?e.jsx("p",{className:"text-[12px] leading-5 text-amber-ink","data-recipe-update-error":!0,children:o("st.recipe.updateFailedStillUsing",{version:y.version,reason:y.last_error.message})}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:da,disabled:i||N.isPending,"data-recipe-open-studio":!0,onClick:()=>{b(null),d({kind:"studio"})},children:o(a===void 0?"st.recipe.choose":"st.recipe.changeRecipe")}),a===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:da,disabled:i,"data-recipe-open-package":!0,onClick:()=>{b(null),d({kind:"author",installationId:a})},children:o("st.recipe.viewRecipe")}),e.jsx("button",{type:"button",className:da,disabled:i||_.isPending,"data-recipe-restore":!0,onClick:()=>{_.mutate(void 0)},children:o("st.recipe.restoreManual")})]}),e.jsx(_t,{to:a===void 0?vn():vn(a),className:"text-[12px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipe-open-library":!0,children:o("st.recipe.openInLibrary")})]}),e.jsx(pe,{feedback:h}),u===null?null:e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-recipe-fork-note":!0,children:o("st.recipe.forkNotBound")})]})}function yA({installationId:t,onSaved:s,onBack:n,onDirtyChange:a,onFeedback:i}){const{t:r,locale:o}=D(),{client:l}=be(),[c,d]=x.useState(null),p=kA(c??t),b=yt(f=>l.forkRecipe({installation_id:t,mode:f,id:`${p.data?.summary.manifest_id??"recipe"}-local`,name:`${p.data?.summary.name??"Recipe"} (${f})`}),{onSuccess:f=>{d(f.summary.installation_id)},onError:f=>{i({tone:"error",text:r("st.recipe.forkFailed",{detail:oe(o,f)})})}});if(p.data===void 0)return e.jsxs("div",{className:"min-w-0 space-y-3","data-recipe-author-route":t,children:[p.isError?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:oe(o,p.error)}):e.jsx("p",{role:"status",className:"text-[12px] text-ink-faint",children:r("st.recipe.loading")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.isError?e.jsx("button",{type:"button",className:da,disabled:p.isFetching,onClick:()=>{p.refetch()},children:r("common.retry")}):null,e.jsx("button",{type:"button",className:da,onClick:n,children:r("st.recipe.back")})]})]});const m=p.data;return!m.editable&&c===null?e.jsxs("div",{className:"min-w-0 space-y-4","data-recipe-author-route":t,children:[e.jsx(Lv,{onFork:f=>{b.mutate(f)}}),e.jsx("button",{type:"button",className:da,onClick:n,children:r("st.recipe.back")})]}):e.jsx(Rv,{detail:m,onApplied:(f,g)=>{g||s(f.summary.installation_id)},onBack:n,onDirtyChange:a})}function kA(t){const{client:s}=be();return je({queryKey:["recipe",t],queryFn:()=>s.getRecipe(t),retry:!1})}const jA={overlay:"st.modelPrompt.system",steering:"st.modelPrompt.steer",anchor:"st.modelPrompt.anchor"};function wA(t,s){return s?.source==="files"?NA[t]:jA[t]}const NA={overlay:"st.modelPrompt.systemFile",steering:"st.modelPrompt.steerFile",anchor:"st.modelPrompt.anchorFile"};function SA({modelId:t,bodies:s,scope:n,branchSelection:a,draft:i,onDraftChange:r,disabled:o=!1}){const{t:l}=D();return a==="off"?e.jsx("div",{className:"min-w-0 space-y-3","data-model-prompt-bodies":n,children:e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-prompt-bodies-off":!0,children:l("st.modelPrompt.identityOff")})}):e.jsxs("div",{className:"min-w-0 space-y-4","data-model-prompt-bodies":n,"data-model":t,children:[n!=="shared"&&a==="common"?e.jsx(he,{children:e.jsx("span",{"data-prompt-identity-inherited":!0,children:l("st.modelPrompt.identityInherited")})}):null,vP.map(c=>{const d=Ev(s,n,c);return e.jsx(CA,{slot:c,label:l(wA(c,d)),view:d,text:i[c]??Tv(d),disabled:o,onChange:u=>{r(c,u)}},c)}),s===void 0?e.jsx(he,{children:l("st.modelPrompt.bodiesUnavailable")}):null]})}function CA({slot:t,label:s,view:n,text:a,onChange:i,disabled:r}){const{t:o}=D(),[l,c]=x.useState(!1);if(n?.error!==void 0)return e.jsxs("div",{className:"space-y-1.5","data-prompt-body":t,"data-prompt-body-source":"error",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:s}),e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:n.error}),n.files.length===0?null:e.jsx("p",{className:"break-all font-mono text-[11px] text-ink-faint",children:n.files.map(u=>u.path).join(`
|
|
242
|
+
`)})]});const d=n===void 0||n.writable;return e.jsxs("div",{className:"space-y-1.5","data-prompt-body":t,"data-prompt-body-source":n?.source??"unset",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:s}),n===void 0||n.source!=="files"?null:e.jsx("span",{className:"font-mono text-[11px] text-ink-faint","data-prompt-body-origin":t,children:n.files.map(u=>u.path).join(", ")})]}),d?e.jsx(e.Fragment,{children:e.jsx("textarea",{rows:8,spellCheck:!1,disabled:r,"aria-label":s,placeholder:n?.source==="unset"||n===void 0?o("st.modelPrompt.emptySlot"):void 0,className:`${pt} h-auto w-full resize-y font-mono text-[12px] leading-5`,"data-prompt-body-editor":t,value:a,onChange:u=>{i(u.target.value)}})}):e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-md bg-ink/[0.035] px-3 py-2 font-mono text-[12px] leading-5 text-ink-soft select-text","data-prompt-body-readonly":t,children:n?.text??""}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("button",{type:"button",className:"text-[11.5px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-prompt-body-expand":t,onClick:()=>{c(!l)},children:o(l?"st.modelPrompt.hideFiles":"st.modelPrompt.showFiles",{count:String(n?.files.length??0)})}),l?e.jsx("ul",{className:"space-y-1.5","data-prompt-body-files":t,children:(n?.files??[]).map(u=>e.jsxs("li",{className:"space-y-0.5",children:[e.jsx("p",{className:"break-all font-mono text-[11px] text-ink-faint",children:u.path}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded bg-ink/[0.03] px-2 py-1.5 font-mono text-[11px] leading-4 text-ink-soft select-text",children:u.text})]},u.path))}):null]})]})]})}const on=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{},tr=(t,s)=>t===void 0?{kind:"absent"}:t==="same"?{kind:"same"}:t==="off"?{kind:"off"}:{kind:"custom",content:s(t)};function sr(t){const s=on(t.cognition),n=on(t.prompt_overrides);return{cognition:{common:ri(s),main:tr(s.main,ri),independent:tr(s.independent,ri)},fields:{common:sn(n),main:tr(n.main,sn),independent:tr(n.independent,sn)}}}function ah(t,s){return JSON.stringify(t)===JSON.stringify(s)}function _A(t,s,n){const a={};return ih(s.cognition,n.cognition)||(a.cognition=rh(on(t.cognition),s.cognition,n.cognition,gi)),ih(s.fields,n.fields)||(a.prompt_overrides=rh(on(t.prompt_overrides),s.fields,n.fields,Bs)),a}const ih=(t,s)=>JSON.stringify(t)===JSON.stringify(s);function rh(t,s,n,a){const i=oh(t,a(s.common),a(n.common));for(const r of["main","independent"]){const o=s[r],l=n[r];JSON.stringify(o)!==JSON.stringify(l)&&(o.kind==="absent"?delete i[r]:o.kind==="same"||o.kind==="off"?i[r]=o.kind:i[r]=l.kind==="custom"?oh(on(t[r]),a(o.content),a(l.content)):EA(a(o.content)))}return i}const EA=t=>Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0));function oh(t,s,n){const a={...t};for(const i of new Set([...Object.keys(n),...Object.keys(s)]))if(JSON.stringify(s[i])!==JSON.stringify(n[i]))if(i==="fields"){const r={...on(t[i])},o=on(n[i]),l=on(s[i]);for(const c of new Set([...Object.keys(o),...Object.keys(l)]))l[c]!==o[c]&&(l[c]===void 0?delete r[c]:r[c]=l[c]);Object.keys(r).length===0?delete a[i]:a[i]=r}else s[i]===void 0?delete a[i]:a[i]=s[i];return a}function lh(t,s){if(t==="shared"||s===null)return"common";const n=s.cognition[t];return n.kind==="off"?"off":n.kind==="custom"?"custom":"common"}const Xc={thread:"st.steerSource.thread",room:"st.steerSource.room",agent:"st.steerSource.agent",task:"st.steerSource.task",cron:"st.steerSource.cron",hook:"st.steerSource.hook",automation:"st.steerSource.automation",skill:"st.steerSource.skill",external:"st.steerSource.external"},TA=["off","inherit","custom"],IA={off:"st.steerSource.modeOff",inherit:"st.steerSource.modeInherit",custom:"st.steerSource.modeCustom"};function Qv(t,s,n){return t?.branches?.[s]?.steering_sources?.[n]}function PA(t,s,n,a){if(t.custom.text.trim()!=="")return!0;const i=Qv(n,s,a);return i?.source==="files"&&(i.text??"").trim()!==""}function AA({bodies:t,scope:s,draft:n,onDraftChange:a,branchOff:i=!1,identityInheritsShared:r=!1,disabled:o=!1}){const{t:l}=D(),c=Pv(s);return e.jsxs("div",{className:"min-w-0 space-y-3","data-steer-sources":c,"data-model-steer-sources":!0,children:[i?e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-steer-branch-off":!0,children:l("st.steerSource.branchOff")}):null,r?e.jsx("p",{className:"text-[12px] leading-5 text-ink-soft","data-steer-identity-inherited":!0,children:l("st.steerSource.identityInherited")}):null,e.jsx("ul",{className:"min-w-0 divide-y divide-hairline","data-steer-source-rows":!0,children:Oi.map(d=>e.jsx("li",{"data-steer-source":d,children:e.jsx($A,{source:d,steerScope:c,bodies:t,draft:n?.[c]?.[d],disabled:o,onDraftChange:a})},d))})]})}function $A({source:t,steerScope:s,bodies:n,draft:a,disabled:i,onDraftChange:r}){const{t:o}=D(),l=a??{mode:"off",custom:{text:"",cadence:{onTurn:!0,onInput:!0,intervalSteps:"0"}}};return e.jsxs("div",{className:"py-2 first:pt-0.5 last:pb-0.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-[13px] leading-5 text-ink","data-steer-source-label":t,children:o(Xc[t])}),l.mode==="custom"&&!PA(l,s,n,t)?e.jsx("span",{className:"truncate text-[11.5px] leading-4 text-ink-faint","data-steer-source-state":t,children:o("st.steerSource.stateEmpty")}):null]}),e.jsx(He,{ariaLabel:o("st.steerSource.modeAria",{source:o(Xc[t])}),value:l.mode,disabled:i,dataAttr:"data-steer-mode",onChange:c=>{r(t,TP(l,c))},choices:TA.map(c=>({value:c,label:o(IA[c])}))})]}),l.mode==="custom"?e.jsxs("div",{className:"mt-2.5 space-y-3 rounded-md bg-ink/[0.025] px-3 py-3","data-steer-source-editor":t,children:[e.jsx(RA,{source:t,steerScope:s,bodies:n,text:l.custom.text,disabled:i,onChange:c=>{r(t,IP(l,c))}}),e.jsx(LA,{source:t,cadence:l.custom.cadence,disabled:i,onChange:c=>{r(t,PP(l,c))}})]}):null]})}function RA({source:t,steerScope:s,bodies:n,text:a,disabled:i,onChange:r}){const{t:o}=D(),[l,c]=x.useState(!1),d=o(Xc[t]),u=Qv(n,s,t);return u!==void 0&&u.source==="files"?e.jsxs("div",{className:"space-y-1.5","data-steer-body":t,"data-steer-body-source":"files",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:o("st.steerSource.body")}),e.jsx("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap rounded-md bg-ink/[0.035] px-3 py-2 font-mono text-[12px] leading-5 text-ink-soft select-text","data-steer-body-readonly":t,children:u.text??""}),e.jsx("button",{type:"button",className:"text-[11.5px] text-ink-soft underline decoration-ink/20 underline-offset-4 hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-steer-body-files":t,onClick:()=>{c(!l)},children:o(l?"st.steerSource.hideFile":"st.steerSource.showFile")}),l?e.jsx("p",{className:"break-all font-mono text-[11px] text-ink-faint",children:(u.files??[]).map(p=>p.path).join(", ")}):null,u.error!==void 0?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:u.error}):null]}):e.jsxs("div",{className:"space-y-1.5","data-steer-body":t,"data-steer-body-source":u?.source??"unset",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:o("st.steerSource.body")}),e.jsx("textarea",{rows:5,spellCheck:!1,disabled:i,"aria-label":d,placeholder:o("st.steerSource.emptyBody"),className:"h-auto w-full resize-y rounded-md border border-hairline-strong bg-panel px-2.5 py-2 font-mono text-[12px] leading-5 text-ink outline-none transition-colors placeholder:text-ink-faint focus-visible:border-selected-ink/45 disabled:cursor-not-allowed disabled:opacity-60","data-steer-body-editor":t,value:a,onChange:p=>{r(p.target.value)}})]})}function LA({source:t,cadence:s,disabled:n,onChange:a}){const{t:i}=D(),r=Av(s.intervalSteps);return e.jsxs("div",{className:"space-y-1.5","data-steer-cadence":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:i("st.modelPrompt.cadence")}),e.jsx(Be,{id:`steer-cadence-turn-${t}`,label:i("st.modelPrompt.cadenceTurn"),checked:s.onTurn,disabled:n,onChange:o=>{a({...s,onTurn:o})}}),e.jsx(Be,{id:`steer-cadence-input-${t}`,label:i("st.modelPrompt.cadenceInput"),checked:s.onInput,disabled:n,onChange:o=>{a({...s,onInput:o})}}),e.jsxs("label",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:[e.jsx("span",{className:"text-[12px] text-ink",children:i("st.modelPrompt.cadenceInterval")}),e.jsxs("span",{className:"flex items-baseline gap-1.5",children:[e.jsx("input",{type:"number",min:0,step:1,disabled:n,"aria-label":i("st.modelPrompt.cadenceInterval"),"data-steer-cadence-interval":t,value:s.intervalSteps,onChange:o=>{a({...s,intervalSteps:o.target.value})},className:"w-16 rounded-md border border-hairline-strong bg-panel px-2 py-1 text-right font-mono text-[12px] text-ink outline-none transition-colors focus-visible:border-selected-ink/45 disabled:cursor-not-allowed disabled:opacity-60"}),e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:i("st.steerSource.steps")})]})]}),r!==void 0?e.jsx("p",{role:"alert",className:"text-[11.5px] leading-4 text-danger","data-steer-cadence-issue":!0,children:i(r==="empty"?"st.steerSource.cadenceEmpty":"st.steerSource.cadenceCount")}):null]})}const Vr={enabled:"inherit",maxPerUserRound:"",maxPerWindow:"",windowMs:""},Gv=6e4,MA=.01,OA=1440,Wv=[{key:"maxPerUserRound",draftKey:"maxPerUserRound",wire:"max_per_user_round",label:"st.questionGuard.perRound",help:"st.questionGuard.perRoundHelp",min:1,max:1e3,minutes:!1,pattern:/^\d+$/},{key:"maxPerWindow",draftKey:"maxPerWindow",wire:"max_per_window",label:"st.questionGuard.perWindow",help:"st.questionGuard.perWindowHelp",min:1,max:1e3,minutes:!1,pattern:/^\d+$/},{key:"windowMinutes",draftKey:"windowMs",wire:"window_ms",label:"st.questionGuard.window",help:"st.questionGuard.windowHelp",min:MA,max:OA,minutes:!0,pattern:/^\d+(\.\d{1,2})?$/}];function Vv(t){const s=t/Gv;return Number.isInteger(s)?String(s):String(Number(s.toFixed(2)))}function DA(t){return Math.round(Number(t.trim())*Gv)}function Ru(t,s){const n=s.trim();if(!t.pattern.test(n))return;const a=Number(n);if(!(a<t.min||a>t.max))return t.minutes?DA(n):a}function Yv(t,s){const n=s.trim();return n===""?"":t.minutes?Vv(Number(n)):n}function ch(t){return Jj(Zf(t,void 0))}function dh(t){return Xj(t)}function ed(t,s){return t.enabled===s.enabled&&t.maxPerUserRound===s.maxPerUserRound&&t.maxPerWindow===s.maxPerWindow&&t.windowMs===s.windowMs}function Jv(t,s,n){const a=n.trim(),i=a===""?"":String(Ru(s,a)??a);return{...t,[s.draftKey]:i}}function FA(t,s){return{...t,[s.draftKey]:""}}function Zv(t,s){for(const n of Wv){const a=Yv(n,t[n.draftKey]).trim();if(t[n.draftKey].trim()!==""&&Ru(n,a)===void 0)return{field:n,text:s(n)}}return null}function Lu(t,s){return Zf(t,{askUserQuestionGuard:Zj(s)})}function qA(t,s,n){if(n[t.draftKey].trim()!=="")return;const a=Lu(s,n);if(t.wire==="window_ms")return{source:s?.windowMs===void 0?"default":"global",text:Vv(a.windowMs)};const i=t.draftKey;return{source:s?.[i]===void 0?"default":"global",text:String(a[i])}}function Mu(t,s){return t(s.minutes?"st.questionGuard.windowRange":"st.questionGuard.range",{min:s.min,max:s.max})}function BA({field:t,draft:s,inherited:n,disabled:a,saving:i,onCommit:r,onClear:o}){const{t:l}=D(),c=n?.(t),d=s[t.draftKey].trim()!=="";return e.jsx(ge,{label:l(t.label),help:c===void 0?l(t.help):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-1",children:[e.jsx(kt,{className:"w-20",inputMode:t.minutes?"decimal":"numeric",ariaLabel:l(t.label),dataAttr:`data-question-guard-${t.wire.replaceAll("_","-")}`,value:Yv(t,s[t.draftKey]),placeholder:c?.text,disabled:a,validate:u=>u.trim()===""||Ru(t,u)!==void 0?null:Mu(l,t),onCommit:u=>{r(t,u)}}),t.minutes?e.jsx("span",{className:"text-[12px] text-ink-faint",children:l("st.questionGuard.minutesUnit")}):null,o!==void 0&&d?e.jsx("button",{type:"button",className:"rounded px-1 py-0.5 text-[12px] text-ink-soft underline decoration-dotted underline-offset-2 transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-60",disabled:a||i,"data-question-guard-clear":t.wire,onClick:()=>{o(t)},children:l("st.questionGuard.useInherited")}):null,c!==void 0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-question-guard-inherited":t.wire,children:c.source==="global"?l("st.questionGuard.fromGlobal",{value:c.text}):l("st.questionGuard.fromDefault",{value:c.text})}):null]})})}function Xv({scope:t,draft:s,enabled:n,disabled:a=!1,saving:i=!1,saved:r=!1,inherited:o,onEnabledChange:l,onNumberCommit:c,onNumberClear:d}){const{t:u}=D();return e.jsxs("fieldset",{disabled:a,className:"min-w-0 space-y-1 disabled:opacity-60","data-question-guard":t,children:[e.jsxs(ge,{label:u("st.questionGuard.enableLabel"),help:u("st.questionGuard.enableHelp"),detail:u("st.questionGuard.enableDetail"),children:[e.jsx(ot,{saving:i,saved:r}),t==="model"?e.jsx(Qe,{ariaLabel:u("st.questionGuard.enableLabel"),dataAttr:"data-question-guard-enabled",value:s.enabled,disabled:a,onChange:l,choices:[{value:"inherit",label:u("st.questionGuard.inherit")},{value:"on",label:u("st.questionGuard.on")},{value:"off",label:u("st.questionGuard.off")}]}):e.jsx(Be,{id:`question-guard-enabled-${t}`,layout:"bare",label:u("st.questionGuard.enableLabel"),checked:n,disabled:a||i,onChange:p=>{l(p?"on":"off")}})]}),e.jsx(Id,{when:n,children:e.jsx("div",{className:"space-y-0.5",children:Wv.map(p=>e.jsx(BA,{field:p,draft:s,disabled:a,saving:i,inherited:o,onCommit:c,onClear:d},p.key))})})]})}const ey=[];function KA(t,s){return t.requestIdentityChoice===s.requestIdentityChoice&&t.requestIdentityOverridesJson===s.requestIdentityOverridesJson}function UA(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(()=>zi(void 0)),[o,l]=x.useState(()=>zi(void 0)),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=Je(),g=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),v=uu(),y=!KA(i,o);x.useEffect(()=>{if(g.data===void 0||y)return;const N=zi(g.data.request_identity);r(N),l(N)},[g.data,y]);const w=async()=>{let N;try{N=ew(i)}catch(_){b(oe(n,_));return}d(!0),p(null);try{const _=await t.patchConfig({request_identity:N??null});a.setQueryData(["config"],_),a.invalidateQueries({queryKey:ns});const C=zi(_.request_identity);r(C),l(C),f()}catch(_){p({tone:"error",text:oe(n,_)})}finally{d(!1)}};return e.jsxs(Me,{id:"st-card-request-identity",title:s("st.requestIdentity.defaultTitle"),children:[e.jsx(Ao,{value:i,onChange:N=>{r(N),b(null)},label:s("st.requestIdentity.defaultLabel"),inheritLabel:s("st.requestIdentity.inheritBuiltin"),hint:s("st.requestIdentity.defaultHint"),issue:h,customProfiles:v}),g.isError?e.jsx(De,{error:g.error}):null,e.jsx(lt,{id:"global-request-identity",dirty:y,saving:c,saved:m,saveDisabled:h!==null,onSave:()=>void w(),onDiscard:()=>{r(o),b(null),p(null)}}),e.jsx(pe,{feedback:u})]})}function ty(){const{client:t}=be(),{t:s}=D(),a=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}).data;return x.useMemo(()=>{const i=new Map,r=(o,l)=>{o===void 0||o===""||i.set(o,[...i.get(o)??[],l])};return r(a?.default_model,s("st.defaults.row.newSession")),r(a?.session_title?.model,s("st.defaults.row.title")),r(a?.fast_model,s("st.defaults.row.fast")),r(a?.subagent?.defaultModel,s("st.defaults.row.subagent")),i},[a,s])}const Ou="model";function HA({providerId:t,models:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=Oe(),o=Li(Ou),[l,c]=x.useState(!1),[d,u]=x.useState(null),[p,h]=Je(),[b,m]=x.useState(""),f=x.useDeferredValue(b),g=Ta(),y=je({queryKey:["config"],queryFn:()=>n.getConfig(),staleTime:6e4}).data?.default_model,w=ty(),N=x.useMemo(()=>s.filter(j=>j.provider_id===t).toSorted((j,T)=>+(T.id===y)-+(j.id===y)||(j.display_name??j.id).localeCompare(T.display_name??T.id)),[s,t,y]),_=N.length>g.catalogVirtualizeThreshold,C=x.useMemo(()=>_?N.map(j=>`${j.display_name??""}\0${j.id}\0${j.remote_id}`.toLowerCase()):[],[_,N]),S=x.useMemo(()=>{const j=f.trim().toLowerCase();if(!_||j==="")return N;const T=[];for(let A=0;A<N.length;A+=1)C[A].includes(j)&&T.push(N[A]);return T},[_,N,C,f]),k=async j=>{c(!0),u(null);const T=Po(n,r,j);try{await T.completed&&h()}catch(A){T.isCurrent()&&u({tone:"error",text:oe(i,A)})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-2","data-provider-models":t,children:[_?e.jsxs("div",{className:"relative flex h-8 items-center",children:[e.jsx(de,{name:"search",size:14,className:"pointer-events-none absolute left-2.5 text-ink-faint"}),e.jsx("input",{type:"search","data-provider-models-search":t,"aria-label":a("st.models.searchPlaceholder"),placeholder:a("st.models.searchPlaceholder"),value:b,onChange:j=>{m(j.target.value)},className:"h-8 w-full min-w-0 rounded-md bg-ink/[0.04] pr-20 pl-8 text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint hover:bg-ink/[0.06] focus:bg-panel focus:shadow-[inset_0_0_0_1px_var(--color-hairline-strong)] [&::-webkit-search-cancel-button]:hidden"}),e.jsx("span",{className:"pointer-events-none absolute right-2.5 text-[12px] text-ink-faint tabular-nums",children:b.trim()===""?N.length:`${S.length} / ${N.length}`})]}):null,S.length>0?e.jsx("div",{className:_?"max-h-[min(480px,60vh)] overflow-y-auto":void 0,"data-provider-models-scroll":_?"":void 0,children:e.jsx(Hs,{items:S,keyOf:j=>j.id,density:"comfortable",label:a("st.providerModels.title"),renderRow:j=>e.jsx(i$,{item:j,density:"comfortable",isDefault:j.id===y,roles:w.get(j.id),attention:!1,busy:l,open:j.id===o.selected,onSetDefault:()=>void k(j),onOpen:()=>{o.open(j.id)}})})}):N.length>0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint","data-provider-models-no-match":!0,children:a("select.noMatches",{query:b.trim()})}):e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint","data-provider-models-empty":!0,children:a("st.providerModels.empty")}),e.jsx(jt,{show:p}),e.jsx(pe,{feedback:d})]})}function zA({list:t,models:s,providers:n,ready:a,providerLabel:i,onChanged:r}){const{client:o}=be(),{t:l}=D(),c=Oe(),d=Li(Ou),[u,p]=x.useState(!1),b=je({queryKey:["config"],queryFn:()=>o.getConfig(),staleTime:6e4}).data?.default_model,m=ty(),f=x.useMemo(()=>new Set(n.filter(L=>L.plugin!==void 0).map(L=>L.id)),[n]),g=x.useMemo(()=>s.filter(L=>L.protocol_source!=="plugin"&&L.effective_protocol!=="plugin"&&!f.has(L.provider_id)),[s,f]),v=d.selected===null?void 0:g.find(L=>L.id===d.selected);x.useEffect(()=>{a&&d.selected!==null&&v===void 0&&d.close()},[a,d.selected,v,d.close]);const y=x.useMemo(()=>{const L=new Map;for(const I of g){const $=L.get(I.provider_id);$!==void 0?$.push(I):L.set(I.provider_id,[I])}return[...L.entries()].map(([I,$])=>({id:I,models:$.toSorted((E,M)=>(E.display_name??E.id).localeCompare(M.display_name??M.id))}))},[g]),w=x.useMemo(()=>v===void 0?void 0:n.find(L=>L.id===v.provider_id)?.images?.accepted_types,[n,v?.provider_id]),N=async L=>{p(!0);try{await Po(o,c,L).completed}catch{}finally{p(!1)}},_=Ta(),[C,S]=x.useState(null),k=x.useCallback(L=>{S(L)},[]),j=x.useMemo(()=>{const L=[];for(const I of y){L.push({kind:"group",key:`g:${I.id}`,label:i?.(I.id)??I.id,count:I.models.length});for(const $ of I.models)L.push({kind:"model",key:`m:${$.id}`,model:$})}return L},[y,i]),T=d.selected!==null&&s.length>_.catalogVirtualizeThreshold,A=Ri({count:T?j.length:0,getScrollElement:()=>C,estimateSize:L=>j[L]?.kind==="group"?28:34,getItemKey:L=>j[L]?.key??L,overscan:_.virtualOverscan,initialRect:{width:240,height:560},observeElementRect:(L,I)=>{const $=L.scrollElement;if($===null)return;const E=()=>{const z=$.getBoundingClientRect(),H=Math.round(z.height||$.clientHeight),U=Math.round(z.width||$.clientWidth);H>0&&I({width:U,height:H})};if(E(),typeof ResizeObserver>"u")return;const M=new ResizeObserver(E);return M.observe($),()=>{M.disconnect()}},measureElement:L=>{const I=Math.round(L.getBoundingClientRect().height);return I>0?I:34},useFlushSync:!1}),P=T?e.jsx("div",{ref:k,"data-model-rail":!0,className:"max-h-[calc(100dvh-10rem)] overflow-y-auto",children:e.jsx("div",{style:{height:A.getTotalSize(),position:"relative"},children:A.getVirtualItems().map(L=>{const I=j[L.index];return I===void 0?null:e.jsx("div",{"data-index":L.index,ref:A.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${L.start}px)`},children:I.kind==="group"?e.jsxs("p",{className:"flex items-baseline justify-between gap-2 px-2 pt-2 pb-1 text-[11px] font-medium text-ink-faint",children:[e.jsx("span",{className:"truncate",children:I.label}),e.jsx("span",{className:"shrink-0 tabular-nums",children:I.count})]}):e.jsx(Na,{itemKey:I.model.id,label:I.model.display_name??I.model.id,current:I.model.id===v?.id,trailing:I.model.id===b?e.jsx(de,{name:"starFilled",size:12,className:"shrink-0 text-ink-soft"}):void 0,onSelect:()=>{d.open(I.model.id)}})},L.key)})})}):e.jsx("div",{"data-model-rail":!0,children:y.map(L=>e.jsx(jo,{label:i?.(L.id)??L.id,count:L.models.length,children:L.models.map(I=>e.jsx(Na,{itemKey:I.id,label:I.display_name??I.id,current:I.id===v?.id,trailing:I.id===b?e.jsx(de,{name:"starFilled",size:12,className:"shrink-0 text-ink-soft"}):void 0,onSelect:()=>{d.open(I.id)}},I.id))},L.id))}),R=v===void 0?null:e.jsxs("div",{"data-model-detail":v.id,className:"flex min-w-0 flex-col gap-4",children:[e.jsxs("header",{className:"flex flex-wrap items-start gap-x-3 gap-y-2",children:[e.jsx("div",{className:"basis-full md:hidden",children:e.jsx(ko,{label:l("st.providerModels.title"),onClick:d.close})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{"data-detail-heading":!0,tabIndex:-1,className:"truncate font-display text-[20px] leading-tight text-ink outline-none",children:v.display_name??v.id}),e.jsx("p",{className:"mt-1 truncate font-mono text-[11.5px] text-ink-faint",children:v.id})]}),e.jsx("button",{type:"button",onClick:d.close,"aria-label":l("common.close"),title:l("common.close"),"data-detail-close":!0,className:"hidden h-8 w-8 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink md:flex",children:e.jsx(de,{name:"close",size:14})})]}),e.jsx("div",{"data-model-row-editor":v.id,className:"flex min-w-0 flex-col",children:e.jsx(r$,{item:v,inheritedImageTypes:w,isDefault:v.id===b,defaultBusy:u,roles:m.get(v.id),onSetDefault:()=>void N(v),onSaved:r,onClose:d.close,onRemoved:d.close},v.id)})]});return e.jsx(wo,{selected:v?.id??null,label:l("st.providerModels.title"),list:t,rail:P,detail:R,data:{"data-model-split":""}})}const Kl="flex h-8 w-full min-w-0 items-center justify-between gap-1.5 rounded-md bg-ink/[0.04] px-3 text-left text-[13px] text-ink outline-none transition-colors hover:bg-ink/[0.07] focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-not-allowed disabled:text-ink-faint";function QA(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(null),[c,d]=Je(),u=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),h=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:6e4}).data?.items??ey,b=u.data?.session_title?.model??"",m=u.data?.subagent?.defaultModel??"",f=u.data?.fast_model??"",g=async(N,_)=>{if(_!==(N==="subagent"?m:f)){r(N),l(null);try{N==="subagent"?await t.setSubagentDefaultModel(_):await t.setFastModel(_),a.setQueryData(["config"],await t.getConfig()),d()}catch(C){l({tone:"error",text:oe(n,C)})}finally{r(null)}}},v=async N=>{if(N!==b){r("title"),l(null);try{a.setQueryData(["config"],await t.patchConfig(Xf(N))),d()}catch(_){l({tone:"error",text:oe(n,_)})}finally{r(null)}}},y=[{id:"session-title",origin:{domain:"session_title",keyPath:["model"]},label:s("st.defaults.row.title"),help:s(b===""?"st.defaults.row.titleUnset":"st.defaults.row.titleHelp"),picker:e.jsx(nn,{id:"st-default-title-model",models:h,value:b,unsetLabel:s("st.sessionTitleModel.noneDefault"),unsetDescription:s("st.sessionTitleModel.noneDesc"),onChange:N=>void v(N),ariaLabel:s("st.defaults.row.title"),searchPlaceholder:s("st.models.searchPlaceholder"),emptyText:s("st.sessionTitleModel.noneDefault"),allowCustomValue:!0,disabled:i!==null,buttonClassName:Kl})},{id:"fast",origin:{domain:"fast_model",keyPath:[]},label:s("st.defaults.row.fast"),help:s("st.defaults.row.fastHelp"),picker:e.jsx(nn,{id:"st-default-fast-model",models:h,value:f,unsetLabel:s("st.defaults.row.fastUnset"),onChange:N=>void g("fast",N),ariaLabel:s("st.defaults.row.fast"),searchPlaceholder:s("st.models.searchPlaceholder"),emptyText:s("st.defaults.row.fastUnset"),allowCustomValue:!0,disabled:i!==null,buttonClassName:Kl})},{id:"subagent",origin:{domain:"subagent",keyPath:["defaultModel"]},label:s("st.defaults.row.subagent"),help:s("st.defaults.row.subagentHelp"),picker:e.jsx(nn,{id:"st-default-subagent-model",models:h,value:m,unsetLabel:s("st.defaults.row.subagentUnset"),onChange:N=>void g("subagent",N),ariaLabel:s("st.defaults.row.subagent"),searchPlaceholder:s("st.models.searchPlaceholder"),emptyText:s("st.defaults.row.subagentUnset"),allowCustomValue:!0,disabled:i!==null,buttonClassName:Kl})}],w={"session-title":"st-default-title-model",fast:"st-default-fast-model",subagent:"st-default-subagent-model"};return e.jsx(Me,{id:"st-card-global-defaults",title:s("st.defaults.globalTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{children:s("st.defaults.globalHint")}),e.jsx("span",{className:"ml-auto",children:e.jsx(jt,{show:c})})]}),e.jsx("div",{className:"divide-y divide-hairline",children:y.map(N=>e.jsxs("div",{"data-default-row":N.id,className:"grid gap-x-6 gap-y-1.5 py-3 first:pt-0 sm:grid-cols-[minmax(0,1fr)_minmax(0,18rem)] sm:items-center",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:w[N.id],className:"text-[13px] text-ink",children:N.label}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:N.help}),e.jsx("div",{className:"pt-1 empty:hidden","data-default-origin":N.id,children:e.jsx(zg,{config:u.data,domain:N.origin.domain,keyPath:N.origin.keyPath,label:N.label})})]}),e.jsx("div",{className:"min-w-0",children:N.picker})]},N.id))}),u.isError?e.jsx(De,{error:u.error}):null,e.jsx(pe,{feedback:o})]})})}function GA(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(!1),[o,l]=x.useState(!0),[c,d]=x.useState(""),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:6e4}),f=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),g=f.data?.default_model,v=x.useMemo(()=>(m.data?.items??ey).find(C=>C.id===g),[m.data,g]),y=x.useMemo(()=>v?.support_efforts===void 0?[]:co(v.support_efforts).map(C=>({value:C,label:Cs(C,s)})),[v?.support_efforts,s]),w=cm(f.data?.thinking),N=x.useCallback(()=>{const C=w?.effort;l(w?.enabled!==!1),d(typeof C=="string"?C:v?.default_effort??"")},[v?.default_effort,w]);x.useEffect(()=>{N()},[N]);const _=async(C,S)=>{if(l(C),d(S),C&&S.trim()===""){p({tone:"error",text:s("st.thinking.emptyError")}),N();return}r(!0),p(null);try{const k=await t.patchConfig({thinking:{enabled:C,effort:S.trim()||void 0}});a.setQueryData(["config"],k);const j=cm(k.thinking),T=j?.enabled!==!1,A=typeof j?.effort=="string"?j.effort:S.trim();l(T),d(A),Mt({defaultEffort:A||void 0}),b()}catch(k){p({tone:"error",text:oe(n,k)}),N()}finally{r(!1)}};return e.jsx(Me,{id:"st-card-thinking",title:s("st.thinking.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(Be,{label:s("st.thinking.enable"),checked:o,disabled:i,onChange:C=>void _(C,c)}),y.length>0?e.jsx(He,{ariaLabel:s("st.thinking.title"),value:c,disabled:!o||i,onChange:C=>void _(o,C),choices:y}):e.jsx("input",{"aria-label":s("st.thinking.title"),className:`${pt} w-32`,value:c,disabled:!o||i,onChange:C=>{d(C.target.value)},onBlur:()=>void _(o,c),onKeyDown:C=>{rt(C)||C.key==="Enter"&&_(o,c)},placeholder:s("st.thinking.placeholder")}),e.jsx(jt,{show:h})]}),e.jsx(he,{children:s("st.thinking.hint")}),e.jsx(pe,{feedback:u}),e.jsx(VA,{stored:typeof w?.keep=="string"?w.keep:void 0})]})})}const WA=new Set(["0","false","no","off","none","null"]);function VA({stored:t}){const{client:s}=be(),{t:n}=D(),a=Oe(),i=bt(),r=t===void 0?"all":WA.has(t.trim().toLowerCase())?"none":t,o=x.useMemo(()=>[{value:"all",label:n("st.thinking.keepAll")},{value:"none",label:n("st.thinking.keepNone")},...r!=="all"&&r!=="none"?[{value:r,label:r}]:[]],[r,n]);return e.jsxs(e.Fragment,{children:[e.jsxs(ge,{label:n("st.thinking.keep"),help:n("st.thinking.keepHelp"),children:[e.jsx(ot,{saving:i.saving,saved:i.saved}),e.jsx(Qe,{id:"thinking-keep",ariaLabel:n("st.thinking.keep"),value:r,dataAttr:"data-thinking-keep",disabled:i.saving,choices:o,onChange:l=>{i.run(async()=>{const c=await s.patchConfig({thinking:{keep:l}});a.setQueryData(["config"],c)})}})]}),e.jsx(pe,{feedback:i.error})]})}function YA(t){return[...new Set(t??kd)]}function td(t){return[...co([...t])]}function JA(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(!1),[o,l]=x.useState(null),[c,d]=x.useState(""),[u,p]=x.useState(""),[h,b]=x.useState(25e4),[m,f]=x.useState([...kd]),[g,v]=x.useState([...vc]),[y,w]=x.useState("inherit"),N=je({queryKey:["discovered-models"],queryFn:()=>t.listDiscoveredModels(),staleTime:3e4}),_=x.useMemo(()=>(N.data?.items??[]).flatMap(A=>A.models.map(P=>({value:JSON.stringify([A.provider_id,P.remote_id]),providerId:A.provider_id,model:P}))),[N.data]),C=x.useMemo(()=>new Map(_.map(A=>[A.value,A])),[_]),S=x.useMemo(()=>{const A=[{label:s("st.providers.catalogGroupSuggested"),accent:!0}];return _.map(P=>({value:P.value,label:P.model.remote_id,description:P.model.display_name,group:P.providerId,badges:A}))},[_,s]),k=C.get(c);Ft("discovered-model-draft",k!==void 0);const j=async()=>{r(!0),l(null);try{const A=await t.refreshAllProviders();await a.invalidateQueries({queryKey:["discovered-models"]}),A.changed.length>0&&await Promise.all(["models","providers","config"].map(R=>a.invalidateQueries({queryKey:[R]})));const P=A.discovered?.reduce((R,L)=>R+L.models.length,0)??0;l(A.failed.length>0?{tone:"error",text:s("st.catalogRefresh.failed",{providers:A.failed.map(R=>R.provider).join(", ")})}:{tone:"success",text:P>0?s("st.catalogRefresh.fetched",{count:P,providers:A.discovered?.length??0}):s("st.catalogRefresh.fetchedNone")})}catch(A){l({tone:"error",text:oe(n,A)})}finally{r(!1)}},T=async()=>{if(k!==void 0){r(!0),l(null);try{await t.createModel({id:u.trim()||void 0,provider_id:k.providerId,remote_id:k.model.remote_id,display_name:k.model.display_name,max_context_size:h,capabilities:m,support_efforts:g,...sv(y)}),d(""),await Promise.all(["models","providers","discovered-models"].map(A=>a.invalidateQueries({queryKey:[A]}))),l({tone:"success",text:s("st.models.paramsSaved",{model:u||k.model.remote_id})})}catch(A){l({tone:"error",text:oe(n,A)})}finally{r(!1)}}};return e.jsx(Me,{id:"st-card-catalog-refresh",title:s("st.catalogRefresh.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:s("st.catalogRefresh.hint")}),e.jsx("button",{type:"button",className:Q,disabled:i,onClick:()=>void j(),children:s(i?"st.catalogRefresh.fetching":"st.catalogRefresh.getModels")}),e.jsx(Jt,{value:c,options:S,onChange:A=>{d(A);const P=C.get(A);p(P===void 0?"":`${P.providerId}/${P.model.remote_id}`),b(P?.model.max_context_size??25e4),f(YA(P?.model.capabilities)),v(P?.model.support_efforts!==void 0&&P.model.support_efforts.length>0?td(P.model.support_efforts):[...vc]),w("inherit")},ariaLabel:s("st.providers.catalogGroupSuggested"),searchPlaceholder:s("st.providers.modelSearchPlaceholder"),emptyText:s("st.catalogRefresh.empty"),disabled:i}),k!==void 0?e.jsxs("div",{className:"space-y-3 pt-3","data-catalog-refresh-form":!0,children:[e.jsx(he,{children:s("st.catalogRefresh.saveHint")}),e.jsxs("label",{className:$e,children:[s("st.catalogRefresh.alias"),e.jsx("input",{className:`${Ce} mt-1 font-normal`,value:u,disabled:i,onChange:A=>{p(A.target.value)}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:s("st.compact.windowLabel")}),e.jsx(fu,{value:h,onChange:b,ariaLabel:s("st.models.contextAria",{model:k.model.remote_id})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:s("st.chips.efforts")}),e.jsx(ln,{values:g,knownOptions:jd,onChange:A=>{v(td(A))},ariaLabel:s("st.models.effortsAria",{model:k.model.remote_id}),addPlaceholder:s("st.chips.addPlaceholder"),removeLabel:A=>s("st.chips.removeAria",{value:A}),disabled:i})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:$e,children:s("st.chips.capabilities")}),e.jsx(ln,{values:m,knownOptions:wd,onChange:f,ariaLabel:s("st.models.capsAria",{model:k.model.remote_id}),addPlaceholder:s("st.chips.addPlaceholder"),removeLabel:A=>s("st.chips.removeAria",{value:A}),disabled:i})]}),e.jsx(hu,{model:k.model.remote_id,value:y,onChange:w,disabled:i}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:Ye,disabled:i,onClick:()=>void T(),children:s("common.save")}),e.jsx("button",{type:"button",className:Q,disabled:i,onClick:()=>{d("")},children:s("common.cancel")})]})]}):null,(N.data?.items??[]).map(A=>e.jsxs("p",{className:`text-[12px] ${A.failure_reason===void 0?"text-ink-faint":"text-danger"}`,children:[A.provider_id," · ",s("st.catalogRefresh.suggestedCount",{count:A.models.length}),A.fetched_at===null?"":` · ${new Date(A.fetched_at).toLocaleString(n)}`,A.failure_reason===void 0?"":` · ${s("st.catalogRefresh.lastFailure",{reason:A.failure_reason})}`]},A.provider_id)),N.isError?e.jsx(De,{error:N.error}):null,e.jsx(pe,{feedback:o})]})})}const ZA={invalid_model:"st.modelMigration.reasonInvalidModel",invalid_parameters:"st.modelMigration.reasonInvalidParameters",invalid_value:"st.modelMigration.reasonInvalidValue",differs:"st.modelMigration.reasonDiffers",ambiguous:"st.modelMigration.reasonAmbiguous",default_effort:"st.modelMigration.reasonDefaultEffort",max_output_size:"st.modelMigration.reasonMaxOutputSize"};function XA(){const{client:t}=be(),{t:s}=D(),n=Oe(),[a,i]=x.useState(null),[r,o]=x.useState(null),[l,c]=x.useState(null),[d,u]=x.useState(null),[p,h]=x.useState(null),b=x.useRef(!1),m=async()=>{o("preview"),i(null);try{i(await t.previewModelGenerationMigration()),h(null)}catch{h({tone:"error",text:s("st.modelMigration.failed")})}finally{o(null)}},f=async()=>{if(a===null||d===null||b.current)return;const g=d;b.current=!0,u(null),o(g.type),c(g.type==="restore"?g.backupKey:null);try{g.type==="apply"?(await t.applyModelGenerationMigration(a.revision),h({tone:"success",text:s("st.modelMigration.applied",{count:a.changes.length})}),i(null)):(await t.restoreModelGenerationMigration(g.backupKey,a.revision),h({tone:"success",text:s("st.modelMigration.restored")}),i(null)),await Promise.all([n.invalidateQueries({queryKey:["config"]}),n.invalidateQueries({queryKey:["models"]}),n.invalidateQueries({queryKey:["providers"]}),n.invalidateQueries({queryKey:["generation-entity"]})])}catch(v){i(null);const y=v!==null&&typeof v=="object"&&"code"in v&&v.code===40941;h({tone:"error",text:s(y?"st.modelMigration.conflict":"st.modelMigration.failed")})}finally{b.current=!1,c(null),o(null)}};return e.jsxs(Me,{id:"st-card-model-migration",title:s("st.modelMigration.title"),children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:s("st.modelMigration.hint")}),e.jsx("button",{type:"button",className:Q,disabled:r!==null,onClick:()=>void m(),children:s(r==="preview"?"st.modelMigration.previewing":"st.modelMigration.preview")}),a!==null?e.jsxs(e.Fragment,{children:[a.changes.length===0?e.jsx(he,{children:s("st.modelMigration.noChanges")}):e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-ink",children:s("st.modelMigration.changesTitle")}),e.jsxs("ul",{className:"mt-1 list-disc space-y-1 pl-5 text-xs text-ink-soft",children:[a.changes.slice(0,60).map(({model_id:g,fields:v})=>e.jsx("li",{children:s("st.modelMigration.changeRow",{model:g,fields:v.join(", ")})},g)),a.changes.length>60?e.jsxs("li",{className:"list-none text-ink-faint",children:["+",a.changes.length-60]}):null]}),e.jsx("button",{type:"button",className:`${Ye} mt-2`,disabled:r!==null,onClick:()=>{u({type:"apply"})},children:s(r==="apply"?"st.modelMigration.applying":"st.modelMigration.apply")})]}),a.needs_review.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-ink",children:s("st.modelMigration.needsReviewTitle")}),e.jsxs("ul",{className:"mt-1 list-disc space-y-1 pl-5 text-xs text-ink-soft",children:[a.needs_review.slice(0,60).map(({model_id:g,code:v,field:y},w)=>e.jsx("li",{children:s("st.modelMigration.needsReviewRow",{model:g,reason:s(ZA[v],{field:y??""})})},`${g}-${v}-${w}`)),a.needs_review.length>60?e.jsxs("li",{className:"list-none text-ink-faint",children:["+",a.needs_review.length-60]}):null]})]}):null,a.backups.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-ink",children:s("st.modelMigration.backupListTitle")}),e.jsx("ul",{className:"mt-1 space-y-2",children:a.backups.map(g=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-xs text-ink-soft",children:[e.jsx("code",{className:"break-all",children:g}),e.jsx("button",{type:"button",className:Q,disabled:r!==null,onClick:()=>{u({type:"restore",backupKey:g})},children:s(l===g?"st.modelMigration.restoring":"st.modelMigration.restore")})]},g))})]}):null]}):null,p!==null?e.jsx(pe,{feedback:p}):null]}),e.jsx(Xe,{open:d!==null,title:s(d?.type==="restore"?"st.modelMigration.restoreConfirmTitle":"st.modelMigration.applyConfirmTitle"),body:s(d?.type==="restore"?"st.modelMigration.restoreConfirmBody":"st.modelMigration.applyConfirmBody"),consequences:d?.type==="restore"?[d.backupKey]:a?.changes.map(({model_id:g,fields:v})=>s("st.modelMigration.changeRow",{model:g,fields:v.join(", ")})),confirmLabel:s(d?.type==="restore"?"st.modelMigration.restoreConfirmAction":"st.modelMigration.applyConfirmAction"),onConfirm:()=>void f(),onCancel:()=>{u(null)}})]})}const e$=new Set(["#st-card-catalog-refresh","#st-card-model-migration"]);function t$(){const{t}=D(),{hash:s}=Bt(),n=e$.has(s),[a,i]=x.useState(n);return x.useEffect(()=>{n&&i(!0)},[n,s]),e.jsxs("details",{className:"group pt-4","data-models-maintenance":!0,open:a,onToggle:r=>{i(r.currentTarget.open)},children:[e.jsxs("summary",{className:"flex min-h-8 w-fit cursor-pointer list-none items-center gap-1.5 rounded-md px-1 text-[12px] font-medium text-ink-soft hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"text-ink-soft transition-transform group-open:rotate-90"}),t("st.models.maintenance")]}),a?e.jsxs("div",{className:"space-y-6 pt-4",children:[e.jsx(JA,{}),e.jsx(XA,{})]}):null]})}function s$(){const{t}=D(),{snapshot:s}=DN();return e.jsx(Me,{id:"st-card-concurrency",title:t("usage.governance.limitsTitle"),children:e.jsx(FN,{rules:s?.rules??[],showHeading:!1})})}function n$(){const{t}=D();return e.jsx(Me,{id:"st-card-decision-judges",title:t("st.decision.judgesTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:t("st.decision.judgesHint")}),e.jsx(_T,{})]})})}function sy(){return e.jsxs("div",{className:"space-y-6",children:[e.jsx(QA,{}),e.jsx(n$,{}),e.jsx(vI,{}),e.jsx(GA,{}),e.jsx(dI,{}),e.jsx(mI,{}),e.jsx(fI,{}),e.jsx(I2,{}),e.jsx(s$,{})]})}const a$={"model.remote_id_missing":"st.models.issue.remoteIdMissing","model.provider_missing":"st.models.issue.providerMissing","model.endpoint_missing":"st.models.issue.endpointMissing","model.max_context_size_missing":"st.models.issue.contextMissing","model.protocol_unresolved":"st.models.issue.protocolUnresolved","model.request_identity_invalid":"st.models.issue.requestIdentityInvalid","model.override_routing_rejected":"st.models.issue.overrideRouting","recipe-selected":"st.models.issue.recipeSelected","recipe-unavailable":"st.models.issue.recipeUnavailable"};function i$({item:t,density:s,isDefault:n,roles:a,attention:i,busy:r,open:o,onSetDefault:l,onOpen:c}){const{t:d}=D(),u=s==="compact";return e.jsxs("div",{"data-model-row":t.id,"data-default":n?"true":void 0,"data-open":o?"":void 0,style:{minHeight:_s[s]},className:`flex h-full items-center gap-1 pr-2 pl-1 transition-colors ${o?"bg-paper shadow-[inset_0_0_0_1px_var(--color-hairline-strong)]":"hover:bg-ink/[0.02]"}`,children:[e.jsx("button",{type:"button",onClick:l,disabled:r||n,"aria-label":d("st.models.starAria",{model:t.id}),title:d(n?"st.models.starredTitle":"st.models.unstarredTitle"),"aria-pressed":n,className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-default pointer-coarse:h-11 pointer-coarse:w-11 ${n?"text-ink":"text-ink-faint hover:bg-ink/[0.04] hover:text-ink"}`,children:e.jsx(de,{name:n?"starFilled":"star",size:14})}),e.jsxs("button",{type:"button","aria-label":d("st.models.editAria",{model:t.id}),"aria-expanded":o,"data-detail-trigger":t.id,title:d("st.models.editTitle"),onClick:c,className:"flex min-h-8 min-w-0 flex-1 items-center gap-3 self-stretch rounded-md pr-1 text-left outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsxs("span",{className:`min-w-0 flex-1 ${u?"flex items-baseline gap-2":""}`,children:[e.jsxs("span",{className:`flex min-w-0 items-center gap-2 ${u?"shrink":""}`,children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:t.display_name??t.id}),n?e.jsx("span",{"data-default-badge":!0,className:"inline-flex shrink-0 items-center rounded bg-selected-ink/10 px-1.5 py-0.5 text-[11px] font-medium text-selected-ink",children:d("st.models.default")}):null,i?e.jsx("span",{className:"shrink-0 text-attention",title:d("st.models.providerAttention"),children:e.jsx(de,{name:"warning",size:12})}):null]}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] leading-4 text-ink-faint",children:[e.jsx("span",{className:"truncate font-mono text-[11px]",children:t.remote_id}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"shrink-0 tabular-nums",children:mo(t.max_context_size)}),a!==void 0&&!u?e.jsxs("span",{className:"hidden min-w-0 truncate text-ink-soft sm:inline",children:["· ",d("st.models.inUseAs",{roles:a.join("、")})]}):null]})]}),e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(gu,{capabilities:t.capabilities})}),e.jsx(de,{name:"chevron",size:12,className:"shrink-0 text-ink-faint"})]})]})}function r$({item:t,inheritedImageTypes:s,isDefault:n=!1,defaultBusy:a=!1,roles:i,onSetDefault:r,onSaved:o,onClose:l,onRemoved:c}){const{t:d,locale:u}=D(),{client:p}=be(),h=Oe(),b=je({queryKey:["model-entity",t.id],queryFn:()=>p.getModel(t.id)}),m=b.data,[f,g]=x.useState(null),[v,y]=x.useState(null),[w,N]=x.useState(!1),[_,C]=x.useState(null),[S,k]=Je(),[j,T]=x.useState(!1),[A,P]=x.useState(!1),[R,L]=x.useState(void 0),[I,$]=x.useState(void 0),[E,M]=x.useState(null),[z,H]=x.useState(null),[U,X]=x.useState(null),[q,F]=x.useState(null),[V,se]=x.useState(null),[Y,O]=x.useState(null),[B,le]=x.useState("shared"),[re,ae]=x.useState(null),[ne,Ee]=x.useState(null),ie=re!==null&&ne!==null&&!ah(re,ne);x.useEffect(()=>{if(m===void 0||ie)return;const ve=sr(m);(ne===null||!ah(ve,ne))&&(ae(ve),Ee(ve))},[m,ie,ne]);const[me,fe]=x.useState(null),[Ie,te]=x.useState(null),[ee,K]=x.useState(void 0),Z=me!==null&&Ie!==null&&!Hx(me,Ie),[ue,Te]=x.useState("basics");x.useEffect(()=>{if(m===void 0||Z)return;const ve=Ux(m);(Ie===null||!Hx(ve,Ie))&&(fe(ve),te(ve))},[m,Z,Ie]);const Ne=x.useCallback((ve,Ve)=>{const nt=Pv(B);fe(dt=>dt===null||dt[nt][ve]===void 0?dt:{...dt,[nt]:{...dt[nt],[ve]:Ve}})},[B]),[J,_e]=x.useState({}),[we,G]=x.useState({}),Le=(ve,Ve)=>`${ve}:${Ve}`,Se=Object.keys(we).length>0,Fe=x.useMemo(()=>{const ve={},Ve=`${B}:`;for(const[nt,dt]of Object.entries(J))nt.startsWith(Ve)&&(ve[nt.slice(Ve.length)]=dt);return ve},[J,B]),ye=x.useMemo(()=>new Set(re===null?[]:qI.filter(ve=>re.cognition[ve].kind==="custom"||re.cognition[ve].kind==="off"||re.fields[ve].kind==="custom"||re.fields[ve].kind==="off")),[re]),[ze,Pe]=x.useState({}),[xe,ke]=x.useState({}),[W,Re]=x.useState(Vr),[Ae,Ue]=x.useState(Vr),Ge=je({queryKey:["config"],queryFn:()=>p.getConfig(),staleTime:6e4}),Ke=Ge.data?.interaction?.askUserQuestionGuard,[We,ce]=x.useState("inherit"),[qe,st]=x.useState("inherit"),gt=We!==qe;x.useEffect(()=>{if(m===void 0||gt)return;const ve=zc(m.protocol);ce(ve),st(ve)},[m,gt]);const Es=je({queryKey:["discovered-models"],queryFn:()=>p.listDiscoveredModels(),staleTime:3e4});x.useEffect(()=>{if(m===void 0||f!==null&&v!==null&&!Zo(f,v))return;const ve=Rp(m);f!==null&&Zo(f,ve)||(g(ve),y(ve))},[m,f,v]);const ct=R!==I;x.useEffect(()=>{m===void 0||ct||(L(m.auto_compact),$(m.auto_compact))},[m,ct]);const wt=E!==null&&z!==null&&!yI(E,z);x.useEffect(()=>{if(m===void 0||wt)return;const ve=Ax(m);M(ve),H(ve)},[m,wt]);const Lt=q!==null&&V!==null&&!Mx(q,V),Zt=JSON.stringify(ze)!==JSON.stringify(xe),Ws=!ed(W,Ae);x.useEffect(()=>{if(m===void 0||Zt)return;const ve=m.parameters??{};Pe(ve),ke(ve)},[m,Zt]),x.useEffect(()=>{if(m===void 0||Ws)return;const ve=dh(m.behavior);ed(ve,Ae)||(Re(ve),Ue(ve))},[m,Ws,Ae]),x.useEffect(()=>{if(m===void 0||Lt)return;const ve={};for(const nt of an)ve[nt]=Rx(m,nt);const Ve=ve;V!==null&&Mx(Ve,V)||(F(Ve),se(Ve))},[m,Lt,V]);const qn=E!==null&&/^\d+$/.test(E.contextBudget.trim())?Number(E.contextBudget.trim()):void 0,Kt=cI({windowTokens:f?.maxContextSize??0,inputTokens:E!==null&&/^\d+$/.test(E.maxInputSize.trim())?Number(E.maxInputSize.trim()):void 0,contextBudget:qn,overrides:E?.overrides,autoCompact:R,loopControl:Ge.data?.loop_control}),[Bn,Gk]=x.useState(!1),Uo=f!==null&&v!==null&&!Zo(f,v)||ct||wt||Lt||Zt||Ws||ie||Se||Z||gt,Zu=Uo||Bn;Ft(`catalog-model:${t.id}`,Zu);const Ki=x.useMemo(()=>{if(m===void 0)return{options:[],ids:new Set};const ve=new Set,Ve=[];for(const nt of Es.data?.items??[])if(nt.provider_id===m.provider_id)for(const dt of nt.models)ve.add(dt.remote_id),Ve.push({value:dt.remote_id,label:dt.remote_id,description:dt.display_name,keywords:dt.display_name});return{options:Ve,ids:ve}},[Es.data,m?.provider_id]),Wk=x.useMemo(()=>{const ve=f?.remoteId??"";return ve.trim()===""||Ki.ids.has(ve)?Ki.options:[{value:ve,label:ve},...Ki.options]},[f?.remoteId,Ki]),Vk=x.useMemo(()=>f===null?[]:co([...f.supportEfforts]),[f?.supportEfforts]),Xu=x.useMemo(()=>m===void 0||q===null||E===null?null:l$(m,q,Lt,Y,R,E,ze),[m,q,Lt,Y,R,E,ze]),Yk=x.useMemo(()=>[{value:"inherit",label:d("context.strategy.reset")},...["auto","summarize","fresh"].map(ve=>({value:ve,label:d(`context.strategy.option.${ve}`),hint:d(`context.strategy.hint.${ve}`)}))],[d]),Jk=x.useCallback(ve=>{if(ve.auto_compact!==void 0&&L(ve.auto_compact===""?void 0:Number(ve.auto_compact)),ve.context_budget!==void 0&&(M(Ve=>Ve===null?null:{...Ve,contextBudget:ve.context_budget}),X(null)),ve.thinking_effort!==void 0&&Pe(Ve=>({...Ve,thinking_effort:ve.thinking_effort===""?void 0:ve.thinking_effort})),ve.service_tier!==void 0&&Pe(Ve=>({...Ve,service_tier:ve.service_tier===""?void 0:ve.service_tier})),ve.max_completion_tokens!==void 0){const Ve=ve.max_completion_tokens;Pe(nt=>({...nt,max_completion_tokens:Ve===""?void 0:Number(Ve)}))}O(null)},[]),ep=m?.cognition_bodies,Zk=x.useCallback((ve,Ve)=>{const nt=Le(B,ve),dt=Tv(Ev(ep,B,ve));_e(Nt=>Nt[nt]===Ve?Nt:{...Nt,[nt]:Ve}),G(Nt=>{if(Ve===dt){if(!(nt in Nt))return Nt;const fs={...Nt};return delete fs[nt],fs}return Nt[nt]===Ve?Nt:{...Nt,[nt]:Ve}})},[B,ep]),tp=x.useRef(async()=>{}),Ho=x.useCallback((ve,Ve)=>tp.current(ve,Ve),[]),Xk=x.useMemo(()=>{if(m===void 0||E===null)return null;const ve=lh(B,re);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(js,{id:`model-steer-${m.id}`,label:d("st.steerSource.disclosure"),summary:d("st.steerSource.summary"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(AA,{bodies:m.cognition_bodies,scope:B,draft:me,branchOff:ve==="off",identityInheritsShared:B!=="shared"&&ve==="common",onDraftChange:Ne,disabled:w}),ee!==void 0?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger","data-steer-source-issue":!0,children:d("st.steerSource.cadenceCount")}):null]})}),e.jsx(js,{id:`model-prompt-structure-${m.id}`,label:d("st.modelEditor.group.promptStructure"),defaultOpen:U?.field==="cognition"||U?.field==="promptOverrides",children:e.jsx($x,{part:"prompts",modelId:m.id,value:E,issue:U,disabled:w,onChange:Ve=>{M(Ve),X(null)}})})]})},[m?.id,m?.cognition_bodies,B,re,me,ee,Ne,E,U,w,d]),sp=f===null?"":f.displayName.trim()===""?m?.id??"":f.displayName.trim(),zo=m?.issues.some(ve=>ve.code==="recipe-selected")??!1,ej=x.useMemo(()=>m===void 0?null:e.jsxs(e.Fragment,{children:[zo?e.jsx("p",{className:"rounded-md bg-selected-ink/[0.07] px-3 py-2 text-[12px] leading-5 text-selected-ink","data-model-recipe-issue":!0,children:d("st.models.issue.recipeSelected")}):null,e.jsx(vA,{modelId:m.id,modelName:sp,onCommitRecipe:Ho,appliedId:m.recipe,disabled:w,onDraftChange:Gk}),e.jsx(Mg,{recipe:m.recipe,values:m.recipe_options,options:m.recipe_model_binding?.options,disabled:w,onChange:ve=>Ho(m.recipe,ve)})]}),[m?.id,m?.recipe,m?.recipe_options,m?.recipe_model_binding?.options,sp,zo,Ho,w,d]),np=f!==null,Qo=f?.requestIdentityChoice??"inherit",ap=f?.requestIdentityOverridesJson??"",ip=f?.imageAcceptedTypes??null,rp=f?.imageConvertUnsupported??null,tj=x.useMemo(()=>{if(m===void 0||!np)return null;const ve={requestIdentityChoice:Qo,requestIdentityOverridesJson:ap},Ve={imageAcceptedTypes:ip,imageConvertUnsupported:rp};return e.jsxs(e.Fragment,{children:[e.jsx(js,{id:`model-${m.id}`,label:d("st.modelEditor.group.requestIdentity"),defaultOpen:Qo!=="inherit",children:e.jsx(Ao,{value:ve,onChange:nt=>{g(dt=>dt===null?null:{...dt,...nt})},label:d("st.models.requestIdentity"),inheritLabel:d("st.requestIdentity.inheritProvider")})}),e.jsx(js,{id:`model-images-${m.id}`,label:d("st.modelEditor.group.images"),children:e.jsx(bu,{value:Ve,onChange:nt=>{g(dt=>dt===null?null:{...dt,...nt})},inheritLabel:d("st.images.inheritProvider")})})]})},[m?.id,np,Qo,ap,ip,rp,d]),sj=x.useMemo(()=>m===void 0||E===null?null:e.jsxs(e.Fragment,{children:[e.jsx(js,{id:`model-sampling-${m.id}`,label:d("st.modelEditor.group.sampling"),children:e.jsx(rv,{scope:"model",id:m.id,onSaved:o,keys:["temperature","top_p"]})}),e.jsx(js,{id:`model-engine-${m.id}`,label:d("st.modelEditor.group.engine"),defaultOpen:U!==null&&U.field!=="contextBudget"&&U.field!=="cognition"&&U.field!=="promptOverrides",children:e.jsx($x,{modelId:m.id,value:E,issue:U,disabled:w,onChange:ve=>{M(ve),X(null)}})}),e.jsx(js,{id:`model-guard-${m.id}`,label:d("st.modelEditor.group.questionGuard"),children:e.jsx("div",{"data-model-behavior":m.id,children:e.jsx(Xv,{scope:"model",draft:W,enabled:Lu(Ke,W).enabled,disabled:w,inherited:ve=>qA(ve,Ke,W),onEnabledChange:ve=>{Re(Ve=>({...Ve,enabled:ve}))},onNumberCommit:(ve,Ve)=>{Re(nt=>Jv(nt,ve,Ve))},onNumberClear:ve=>{Re(Ve=>FA(Ve,ve))}})})})]}),[m?.id,E,U,W,Ke,w,o,d]);if(b.isError)return e.jsx(De,{error:b.error});if(m===void 0||f===null||v===null||E===null||z===null)return e.jsx(he,{children:d("st.models.loading")});const nj=Kt.hint===d("st.compact.pointHint")?void 0:Kt.hint,aj=e.jsx(dv,{label:d("st.compact.trackLabel"),dataAttribute:`model:${m.id}`,usable:Kt.usable,bounds:Kt.bounds,reserved:Kt.reserved,value:Kt.trackValue,title:Kt.trackTitle,reason:Kt.trackReason,pinned:Kt.overridden,onChange:ve=>{w||L(ve)}}),op=async(ve,Ve)=>{const nt=Nt=>{if(C({tone:"error",text:Nt}),ve!==void 0)throw new Error(Nt)};if(f.remoteId.trim()===""){nt(qs(u,{key:"val.modelIdEmpty"}));return}const dt=tw(f,s);if(dt!==null){nt(qs(u,dt));return}N(!0),C(null);try{const Nt=sw(f);if(Nt!==null){nt(qs(u,Nt));return}let fs;try{fs=kI(E,z)}catch(xt){if(!(xt instanceof xr))throw xt;const Un=d(xt.key==="count"?"st.modelEngine.issueCount":xt.key==="json"?"st.modelEngine.issueJson":"st.modelEngine.issueObject");if(X({field:xt.field,text:Un}),ve!==void 0)throw new Error(Un,{cause:xt});return}X(null);const Hi=q===null?void 0:an.map(xt=>({position:xt,field:CI(q[xt]??En)})).find(xt=>xt.field!==void 0);if(O(Hi?.field===void 0?null:{position:Hi.position,field:Hi.field}),Hi?.field!==void 0){if(ve!==void 0)throw new Error(d("st.usagePolicy.issueCount"));return}const cp=q===null||V===null?{}:EI(q,V),Wo=o$(ze,xe),dp=Zv(W,xt=>Mu(d,xt));if(dp!==null){if(ve!==void 0)throw new Error(dp.text);return}const Vo=nw(W,Ae),up=me===null||Ie===null?void 0:Oi.find(xt=>Iv.some(Un=>{const Oa=EP(me,Un,xt);return Oa.mode==="custom"&&Av(Oa.custom.cadence.intervalSteps)!==void 0}));if(K(up),up!==void 0){if(ve!==void 0)throw new Error(d("st.steerSource.cadenceCount"));return}const pp=Wf(f,v),lj=tv(We,qe);if(pp===null&&!ct&&Object.keys(fs).length===0&&Object.keys(cp).length===0&&Wo===null&&Vo===void 0&&!ie&&!Se&&!Z&&!gt&&ve===void 0)return;const mp={...m,cognition:fs.cognition===void 0?m.cognition:fs.cognition??void 0,prompt_overrides:fs.prompt_overrides===void 0?m.prompt_overrides:fs.prompt_overrides??void 0},xp=_A(mp,re??sr(m),ne??sr(m));let Yo=xp.cognition??mp.cognition;for(const[xt,Un]of Object.entries(we)){const Oa=xt.indexOf(":"),cj=xt.slice(0,Oa),dj=xt.slice(Oa+1);Yo=kP({...m,cognition:Yo},cj,dj,Un).cognition}const Ma={...pp,...ct?{auto_compact:R??null}:{},...fs,...cp,...xp,...Wo===null?{}:{parameters:Wo},...Vo===void 0?{}:{behavior:Vo},...lj};Se&&(Ma.cognition=Yo),ve!==void 0&&(Ma.recipe=ve),Ve!==void 0&&(Ma.recipe_options=Ve);const hp=me===null||Ie===null?void 0:RP(me,Ie);hp!==void 0&&(Ma.steering_sources_patch=hp);const cs=await p.updateModel(m.id,{...Ma,base_revision:m.revision}),fp=Rp(cs),bp=Ax(cs),gp=sr(cs),vp=Object.fromEntries(an.map(xt=>[xt,Rx(cs,xt)])),yp=cs.parameters??{},kp=dh(cs.behavior);g(fp),y(fp),L(cs.auto_compact),$(cs.auto_compact),M(bp),H(bp),ae(gp),Ee(gp),F(vp),se(vp),Pe(yp),ke(yp),Re(kp),Ue(kp),_e({}),G({});const jp=Ux(cs);fe(jp),te(jp),K(void 0);const wp=zc(cs.protocol);ce(wp),st(wp),h.setQueryData(["model-entity",t.id],cs),await o(),await b.refetch(),k()}catch(Nt){if(C({tone:"error",text:oe(u,Nt)}),ve!==void 0)throw Nt}finally{N(!1)}},ij=async()=>{P(!0),C(null);try{await p.deleteModel(m.id,{baseRevision:m.revision}),T(!1),h.removeQueries({queryKey:["model-entity",t.id]}),await o(),c?.()}catch(ve){T(!1),C({tone:"error",text:oe(u,ve)})}finally{P(!1)}},rj=()=>{g(v),L(I),M(z),X(null),V!==null&&F(V),O(null),ne!==null&&ae(ne),_e({}),G({}),Ie!==null&&fe(Ie),K(void 0),Pe(xe),Re(Ae),ce(qe),C(null)};tp.current=op;const oj=qe==="inherit"&&m.effective_protocol!=="plugin"?m.effective_protocol:void 0,Go=ve=>`model-editor-${ve}-${m.id}`,lp=m.issues.filter(ve=>ve.code!=="recipe-selected"),hs=[{id:"basics",label:d("st.modelEditor.tab.basics")},{id:"prompts",label:d("st.modelEditor.tab.prompts")},{id:"recipe",label:d("st.modelEditor.tab.recipe"),badge:m.recipe===void 0?void 0:d("st.modelEditor.recipeOn")},{id:"advanced",label:d("st.modelEditor.tab.advanced")}],Kn=ve=>`model-editor-tab-${ve}-${m.id}`,La=ve=>`model-editor-panel-${ve}-${m.id}`,Ui=ve=>{Te(ve),document.getElementById(Kn(ve))?.focus()};return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-6","data-model-editor-layout":!0,children:[e.jsx("div",{className:"sticky top-[calc(-1*var(--settings-scroll-pt,0px))] z-10 border-b border-hairline bg-canvas pt-1",children:e.jsx("div",{role:"tablist","aria-label":d("st.modelEditor.navAria"),className:"-mb-px flex items-end gap-4 overflow-x-auto",onKeyDown:ve=>{const Ve=hs.findIndex(nt=>nt.id===ue);ve.key==="ArrowRight"&&(ve.preventDefault(),Ui(hs[(Ve+1)%hs.length].id)),ve.key==="ArrowLeft"&&(ve.preventDefault(),Ui(hs[(Ve-1+hs.length)%hs.length].id)),ve.key==="Home"&&(ve.preventDefault(),Ui(hs[0].id)),ve.key==="End"&&(ve.preventDefault(),Ui(hs[hs.length-1].id))},children:hs.map(ve=>{const Ve=ue===ve.id;return e.jsxs("button",{id:Kn(ve.id),type:"button",role:"tab","aria-selected":Ve,"aria-controls":La(ve.id),tabIndex:Ve?0:-1,"data-model-editor-tab":ve.id,onClick:()=>{Te(ve.id)},className:`inline-flex h-9 shrink-0 items-center gap-1.5 border-b-2 px-0.5 text-[13px] outline-none transition-colors focus-visible:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${Ve?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:[ve.label,ve.badge===void 0?null:e.jsx("span",{"data-model-editor-tab-badge":ve.id,className:"rounded bg-selected-ink/10 px-1.5 py-px text-[10.5px] font-medium text-selected-ink",children:ve.badge})]},ve.id)})})}),lp.length>0?e.jsx("ul",{role:"status","data-model-issues":!0,className:"space-y-0.5 rounded-md bg-amber-card px-3 py-2 text-[12px] leading-5 text-amber-ink",children:lp.map((ve,Ve)=>{const nt=a$[ve.code],dt=nt===void 0?`${ve.path}: ${ve.message}`:ve.code==="model.override_routing_rejected"?d(nt,{fields:ve.message}):d(nt);return e.jsx("li",{"data-model-issue":ve.code,children:dt},`${ve.code}-${Ve}`)})}):null,e.jsxs("div",{id:La("basics"),role:"tabpanel","aria-labelledby":Kn("basics"),hidden:ue!=="basics",className:"space-y-8",children:[e.jsx(Ul,{id:Go("basics"),title:d("st.modelEditor.section.model"),aside:e.jsx("div",{"data-model-default-control":t.id,"data-is-default":n?"true":"false",className:"flex items-center",children:n?e.jsxs("span",{"data-default-badge":!0,className:"inline-flex items-center gap-1 rounded bg-selected-ink/10 px-1.5 py-0.5 text-[11.5px] font-medium text-selected-ink",children:[e.jsx(de,{name:"starFilled",size:12}),d("st.models.currentDefault")]}):r!==void 0?e.jsxs("button",{type:"button","data-set-default-button":!0,disabled:a,onClick:r,className:"inline-flex h-7 items-center gap-1 rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-not-allowed disabled:text-ink-faint pointer-coarse:h-9",children:[e.jsx(de,{name:"star",size:12}),d("st.models.unstarredTitle")]}):null}),children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1","data-model-remote-id":m.id,children:[e.jsx("p",{className:$e,children:d("st.models.remoteIdLabel")}),e.jsx(Jt,{options:Wk,value:f.remoteId,onChange:ve=>{g({...f,remoteId:ve})},ariaLabel:d("st.models.remoteIdAria",{model:m.id}),allowCustomValue:!0,customValueLabel:ve=>d("st.providers.useCustomModel",{id:ve}),searchPlaceholder:d("st.providers.modelSearchPlaceholder"),emptyText:d("st.providers.catalogEmpty"),disabled:w,buttonClassName:`${Ce} flex items-center justify-between gap-2 text-left font-mono`}),e.jsx("input",{type:"text",className:"sr-only","aria-label":d("st.models.remoteIdAria",{model:m.id}),value:f.remoteId,onChange:ve=>{g({...f,remoteId:ve.target.value})}})]}),e.jsxs("label",{className:`${$e} min-w-0`,children:[d("st.models.displayNameLabel"),e.jsx("input",{className:`${Ce} mt-1 font-normal`,"aria-label":d("st.models.displayNameAria",{model:m.id}),value:f.displayName,onChange:ve=>{g({...f,displayName:ve.target.value})},placeholder:m.remote_id})]}),e.jsxs("label",{className:`${$e} min-w-0 sm:col-span-2`,"data-model-pricing-model":m.id,children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[d("usage.pricing.billingModel"),e.jsx(Rn,{children:d("st.models.pricingModelHelp")})]}),e.jsx("input",{className:`${Ce} mt-1 font-mono font-normal`,"aria-label":d("st.models.pricingModelAria",{model:m.id}),value:f.pricingModel??"",spellCheck:!1,placeholder:d("st.models.pricingModelPlaceholder"),disabled:w,onChange:ve=>{g({...f,pricingModel:ve.target.value})}})]}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("p",{className:$e,children:d("st.modelEditor.provider")}),e.jsx("p",{className:"flex h-8 min-w-0 items-center rounded-md bg-ink/[0.03] px-3 font-mono text-[12.5px] text-ink-soft",title:m.provider_id,children:e.jsx("span",{className:"truncate",children:m.provider_id})})]}),e.jsx(hu,{model:m.id,value:We,resolved:oj,source:qe==="inherit"?m.protocol_source:void 0,endpointSource:m.endpoint_source,authSource:m.auth_source,endpointEnv:m.endpoint_env,authEnv:m.auth_env,onChange:ce,disabled:w})]})}),e.jsxs(Ul,{id:Go("usage"),title:d("st.modelEditor.section.usage"),children:[Xu!==null?e.jsx($I,{modelId:m.id,view:Xu,efforts:Vk,onSharedChange:Jk,onChange:ve=>{F(ve),O(null)},sharedIssue:U?.field==="contextBudget"?{field:"context_budget",text:U.text}:null,compactionTrack:aj,compactionControl:e.jsx(ru,{dataAttribute:`model:${m.id}`,labelClassName:"sr-only",label:d("st.compact.pointLabel"),value:R,onChange:L,disabled:w,windowTokens:Kt.usable,placeholder:Kt.inheritedLabel,presets:Kt.presets,presetsLabel:Kt.presetsLabel,hint:nj}),disabled:w}):null,e.jsxs("div",{className:"space-y-1.5","data-model-context-strategy":m.id,children:[e.jsx("label",{htmlFor:`model-context-strategy-${m.id}`,className:"text-[12px] font-medium text-ink-soft",children:d("context.strategy.title")}),e.jsx(Qe,{id:`model-context-strategy-${m.id}`,variant:"form",ariaLabel:d("st.models.contextStrategyAria",{model:m.id}),dataAttr:"data-model-context-strategy-select",value:f.contextStrategy??"inherit",disabled:w,choices:Yk,onChange:ve=>{g({...f,contextStrategy:ve==="inherit"?void 0:ve})}})]})]}),e.jsxs(Ul,{id:Go("capabilities"),title:d("st.modelEditor.section.capabilities"),children:[e.jsx(oI,{modelId:m.id,windowTokens:f.maxContextSize,inputTokens:/^\d+$/.test(E.maxInputSize.trim())?Number(E.maxInputSize.trim()):void 0,contextBudget:/^\d+$/.test(E.contextBudget.trim())?Number(E.contextBudget.trim()):void 0,overrides:E.overrides,onWindowChange:ve=>{g({...f,maxContextSize:ve})},autoCompact:R,onAutoCompactChange:L,loopControl:Ge.data?.loop_control,hideCompaction:!0}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:$e,children:d("st.chips.efforts")}),e.jsx(ln,{values:f.supportEfforts,knownOptions:jd,onChange:ve=>{g({...f,supportEfforts:td(ve)})},ariaLabel:d("st.models.effortsAria",{model:m.id}),addPlaceholder:d("st.chips.addPlaceholder"),removeLabel:ve=>d("st.chips.removeAria",{value:ve})})]}),e.jsxs("div",{className:"space-y-1.5","data-model-capabilities":m.id,children:[e.jsx("p",{className:$e,children:d("st.chips.capabilities")}),e.jsx(ln,{values:f.capabilities,knownOptions:wd,onChange:ve=>{g({...f,capabilities:ve})},ariaLabel:d("st.models.capsAria",{model:m.id}),addPlaceholder:d("st.chips.addPlaceholder"),removeLabel:ve=>d("st.chips.removeAria",{value:ve})})]})]})]}),e.jsxs("div",{id:La("prompts"),role:"tabpanel","aria-labelledby":Kn("prompts"),hidden:ue!=="prompts",className:"space-y-6",children:[e.jsx(BI,{scope:B,customized:ye,onScopeChange:le}),zo?e.jsx("p",{className:"text-[12px] text-selected-ink","data-prompts-recipe-note":!0,children:d("st.models.issue.recipeSelected")}):null,e.jsx(SA,{modelId:m.id,bodies:m.cognition_bodies,scope:B,branchSelection:lh(B,re),draft:Fe,onDraftChange:Zk,disabled:w}),Xk]}),e.jsx("div",{id:La("recipe"),role:"tabpanel","aria-labelledby":Kn("recipe"),hidden:ue!=="recipe",className:"space-y-4",children:ej}),e.jsxs("div",{id:La("advanced"),role:"tabpanel","aria-labelledby":Kn("advanced"),hidden:ue!=="advanced",className:"space-y-1","data-model-advanced-groups":!0,children:[tj,sj]}),e.jsxs("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] z-10 mt-auto flex flex-wrap items-center gap-2 border-t border-hairline bg-canvas/95 py-3 backdrop-blur-sm","data-model-editor-actions":!0,children:[e.jsx("button",{type:"button",className:Ye,disabled:w||!Uo,onClick:()=>void op(),children:d(w?"common.saving":"common.save")}),e.jsx("button",{type:"button",className:Q,disabled:w||!Uo,onClick:rj,"data-model-editor-discard":!0,children:d("st.advanced.discard")}),e.jsx("button",{type:"button",className:Q,disabled:w,onClick:l,children:d("common.close")}),Zu?e.jsx("span",{role:"status",className:"text-[12px] text-ink-faint",children:d("st.draft.unsaved")}):e.jsx(jt,{show:S}),c!==void 0?e.jsx("button",{type:"button",className:`${Ht} ml-auto`,"data-model-remove":m.id,disabled:w||A,onClick:()=>{T(!0)},children:d("st.providerModels.remove")}):null,e.jsx("div",{className:"basis-full empty:hidden",children:e.jsx(pe,{feedback:_})})]}),e.jsx(Xe,{open:j,stacked:!0,overlayId:`catalog-model-remove:${m.id}`,title:d("st.providerModels.removeTitle",{model:m.display_name??m.id}),body:d("st.providerModels.removeBody"),consequences:[...i!==void 0&&i.length>0?[d("st.providerModels.removeDefault",{model:m.id,roles:i.join(u==="zh"?"、":", ")})]:[],d("st.providerModels.removeSessions")],confirmLabel:d("st.providerModels.remove"),busy:A,onConfirm:()=>void ij(),onCancel:()=>{T(!1)}})]})}function Ul({id:t,title:s,aside:n,children:a}){const i=`${t}-title`;return e.jsxs("section",{id:t,"aria-labelledby":i,className:"min-w-0 space-y-4","data-model-editor-section":t,children:[e.jsxs("header",{className:"flex min-h-7 flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[e.jsx("h3",{id:i,className:"text-[13px] font-semibold text-ink",children:s}),n]}),a]})}function o$(t,s){const n={};for(const a of["thinking_effort","service_tier","max_completion_tokens"])JSON.stringify(t[a])!==JSON.stringify(s[a])&&(n[a]=t[a]??null);return Object.keys(n).length===0?null:n}function l$(t,s,n,a,i,r,o){const l=u=>/^\d+$/.test(u.trim())?Number(u.trim()):void 0,c={thinking_effort:o.thinking_effort??"",service_tier:o.service_tier===void 0?typeof t.service_tier=="string"?t.service_tier:"":typeof o.service_tier=="string"?o.service_tier:"",auto_compact:String(i??t.auto_compact??""),context_budget:l(r.contextBudget)===void 0?"":String(l(r.contextBudget)),max_completion_tokens:o.max_completion_tokens===void 0?"":String(o.max_completion_tokens)},d={};for(const u of an){const p=TI(t,u)??{};d[u]=Object.fromEntries(ju.map(h=>{const b=p[h],m=b===void 0||typeof b=="object"?"":String(b);return[h,{value:m,source:II(t,u,h)}]}))}return{draft:s,shared:c,resolved:d,issue:a,dirty:n}}function ny(t){const s=`/settings/plugins?plugin=${encodeURIComponent(t.plugin_id)}`;return t.panel_id!==void 0&&t.panel_id.length>0?`${s}&panel=${encodeURIComponent(t.panel_id)}`:s}const c$={ready:"st.connections.plugin.ready",auth_required:"st.connections.plugin.authRequired",degraded:"st.connections.plugin.degraded",initializing:"st.connections.plugin.initializing"};function d$(t){switch(t){case"ready":return"text-ink-soft";case"auth_required":return"text-amber-ink";case"degraded":return"text-danger";case"initializing":return"text-ink-faint"}}function u$({item:t,density:s,isDefault:n,busy:a,onSetDefault:i}){const{t:r}=D(),o=s==="compact",l=t.effective_capabilities??t.capabilities,c=t.support_efforts;return e.jsxs("div",{"data-model-row":t.id,"data-plugin-model-row":t.id,"data-default":n?"true":void 0,style:{minHeight:_s[s]},className:"flex h-full items-center gap-1 pr-2 pl-1",children:[e.jsx("button",{type:"button",onClick:i,disabled:a||n,"aria-label":r("st.models.starAria",{model:t.id}),title:r(n?"st.models.starredTitle":"st.models.unstarredTitle"),"aria-pressed":n,className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40 disabled:cursor-default pointer-coarse:h-11 pointer-coarse:w-11 ${n?"text-ink":"text-ink-faint hover:bg-ink/[0.04] hover:text-ink"}`,children:e.jsx(de,{name:n?"starFilled":"star",size:14})}),e.jsxs("div",{className:"flex min-h-8 min-w-0 flex-1 items-center gap-3 pr-1",children:[e.jsxs("span",{className:`min-w-0 flex-1 ${o?"flex items-baseline gap-2":""}`,children:[e.jsxs("span",{className:`flex min-w-0 items-center gap-2 ${o?"shrink":""}`,children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:t.display_name??t.id}),n?e.jsx("span",{"data-default-badge":!0,className:"inline-flex shrink-0 items-center rounded bg-selected-ink/10 px-1.5 py-0.5 text-[11px] font-medium text-selected-ink",children:r("st.models.default")}):null]}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12px] leading-4 text-ink-faint",children:[e.jsx("span",{className:"truncate font-mono text-[11px]",children:t.remote_id??t.id}),t.max_context_size!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"shrink-0 tabular-nums",children:mo(t.max_context_size)})]}):null,c!==void 0&&c.length>0&&!o?e.jsxs("span",{className:"hidden min-w-0 truncate font-mono text-[11px] sm:inline",children:["· ",c.join("/")]}):null]})]}),l!==void 0&&l.length>0?e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(gu,{capabilities:l})}):null]})]})}function p$({providerId:t,models:s,density:n}){const{client:a}=be(),{t:i,locale:r}=D(),o=Oe(),[l,c]=x.useState(!1),[d,u]=x.useState(null),[p,h]=Je(),m=je({queryKey:["config"],queryFn:()=>a.getConfig(),staleTime:6e4}).data?.default_model,f=x.useMemo(()=>s.filter(v=>v.provider_id===t).toSorted((v,y)=>+(y.id===m)-+(v.id===m)||(v.display_name??v.id).localeCompare(y.display_name??y.id)),[s,t,m]),g=async v=>{c(!0),u(null);const y=Po(a,o,v);try{await y.completed&&h()}catch(w){y.isCurrent()&&u({tone:"error",text:oe(r,w)})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-2","data-provider-models":t,children:[e.jsx(Hs,{items:f,keyOf:v=>v.id,density:n,label:i("st.providerModels.title"),renderRow:v=>e.jsx(u$,{item:v,density:n,isDefault:v.id===m,busy:l,onSetDefault:()=>void g(v)})}),e.jsx(jt,{show:p}),e.jsx(pe,{feedback:d})]})}function m$({provider:t,plugin:s,models:n,defaultOpen:a=!1,density:i="comfortable"}){const{t:r}=D(),o=So(),[l,c]=x.useState(a);x.useEffect(()=>{a&&c(!0)},[a]);const d=t.label??t.id,u=n.length>0?n.length:s.model_count,p=r(c$[s.readiness]),h=s.readiness==="auth_required"?r("st.connections.plugin.signIn"):r("st.connections.plugin.manage"),b=s.panel_id!==void 0&&s.panel_id.length>0,m=s.readiness==="auth_required"||s.readiness==="degraded",f=e.jsxs("span",{"data-plugin-provider-status":s.readiness,className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${d$(s.readiness)}`,children:[m?e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${s.readiness==="degraded"?"bg-danger":"bg-amber-rule"}`}):null,e.jsx("span",{children:p})]}),g=b?e.jsx(_t,{to:ny(s),"data-plugin-provider-action":t.id,onClick:v=>{v.stopPropagation()},className:`${Q} inline-flex h-7 shrink-0 items-center px-2.5 text-[12px] pointer-coarse:min-h-11`,children:h}):null;return e.jsxs("details",{open:l,onToggle:v=>{c(v.currentTarget.open)},"data-connection-row":t.id,"data-connection-kind":"plugin","data-plugin-provider-row":t.id,"data-plugin-provider-readiness":s.readiness,className:"group/provider [&[open]]:bg-paper",children:[e.jsxs("summary",{style:{minHeight:_s[i]},className:`flex cursor-pointer list-none items-center gap-3 px-3 outline-none transition-colors hover:bg-ink/[0.03] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden ${i==="compact"?"py-1":"py-2"}`,children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-ink/[0.05] text-ink-soft",children:e.jsx(G_,{size:14,strokeWidth:1.75})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:`flex min-w-0 items-baseline ${o?"justify-between gap-2":"gap-2"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:d}),t.label!==void 0&&t.label!==t.id?e.jsx("span",{className:"hidden truncate font-mono text-[11px] text-ink-faint sm:inline",children:t.id}):null]}),o?f:null]}),i==="compact"?null:e.jsxs("span",{className:"block truncate text-[12px] text-ink-faint",children:[r("st.connections.kind.plugin"),!o&&s.account_summary?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-plugin-provider-account":!0,className:"text-ink-soft",children:s.account_summary})]}):null," · ",e.jsx("span",{className:"tabular-nums",children:r("st.connections.modelCount",{count:u})}),!o&&s.status_text?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-plugin-provider-detail":!0,children:s.status_text})]}):null]})]}),o?null:f,o?null:g,e.jsx(Rt,{open:l,className:"shrink-0 text-ink-faint"})]}),e.jsxs("div",{className:"space-y-3 px-3 pb-4 pt-1 sm:pl-[3.25rem]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-[12px] text-ink-faint",children:[e.jsxs("span",{className:"min-w-0",children:[r("st.connections.plugin.providedBy"),e.jsx(_t,{to:`/settings/plugins?plugin=${encodeURIComponent(s.plugin_id)}`,className:"font-mono text-ink-soft hover:text-ink hover:underline",children:s.plugin_id}),o&&s.account_summary?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-plugin-provider-account":!0,className:"text-ink-soft",children:s.account_summary})]}):null,o&&s.status_text?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{"data-plugin-provider-detail":!0,children:s.status_text})]}):null]}),o?g:null]}),n.length>0?e.jsx(p$,{providerId:t.id,models:n,density:i}):e.jsx("p",{className:"text-[12px] text-ink-faint",children:s.readiness==="auth_required"?r("st.connections.plugin.emptyAuthRequired"):r("st.connections.plugin.emptyReady")})]})]})}const Hl=["api","account","plugin","local","decision"],nr=[];function ay(){const{client:t}=be(),{t:s,locale:n}=D(),{hash:a,search:i}=Bt(),r=new URLSearchParams(i),o=r.get(Ou),l=r.get("engine"),c=r.get(Mb),d=Oe(),[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=x.useState(null),g=je({queryKey:["providers"],queryFn:()=>t.listProviders(),staleTime:1e4}),v=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:1e4}),y=je({queryKey:Nc,queryFn:()=>t.listOAuthMethods(),staleTime:1e4}),w=x.useCallback(async()=>{await Promise.all([d.invalidateQueries({queryKey:["providers"]}),d.invalidateQueries({queryKey:["models"]}),d.invalidateQueries({queryKey:["generation-entity"]}),d.invalidateQueries({queryKey:["provider-entity"]}),d.invalidateQueries({queryKey:["auth"]}),d.invalidateQueries({queryKey:["config"]}),d.invalidateQueries({queryKey:Nc}),d.invalidateQueries({queryKey:Qc})])},[d]),N=Eb(w),_=g.data?.items??[],C=_,S=x.useMemo(()=>_.filter(J=>!ha(J)),[_]),k=x.useMemo(()=>new Set(_.map(J=>J.id)),[_]),j=x.useMemo(()=>new Set(S.map(J=>J.id)),[S]),T=y.data??[],A=x.useMemo(()=>new Set(T.map(J=>J.provider)),[T]),P=x.useMemo(()=>{const J=new Map;for(const _e of T)J.set(_e.provider,_e);return J},[T]),R=x.useCallback(J=>P.get(J),[P]),L=x.useMemo(()=>{const J=new Map,_e=v.data?.items??nr;for(let we=0;we<_e.length;we+=1){const G=_e[we],Le=J.get(G.provider_id);Le!==void 0?Le.push(G):J.set(G.provider_id,[G])}return J},[v.data]),I=J=>L.get(J)?.length??0,$=g.isSuccess&&C.length===0,E=x.useMemo(()=>C.filter(J=>Uc(J,R(J.id))),[C,R]),M=x.useCallback(J=>J.id,[]),z=x.useCallback(J=>[J.id,J.label,J.plugin?.plugin_id,R(J.id)?.label,J.base_url,J.default_model,po(J),...(L.get(J.id)??nr).flatMap(_e=>[_e.id,_e.remote_id,_e.display_name])],[R,L]),H=x.useMemo(()=>[...Hl.map(J=>({id:J,label:s(`st.connections.kind.${J}`),test:_e=>Qi(_e,A)===J})),{id:"attention",label:s("st.connections.filter.attention"),tone:"attention",test:J=>Uc(J,R(J.id))}],[s,A,R]),U=x.useMemo(()=>[{id:"kind",label:s("st.list.sort.order"),compare:(J,_e)=>Hl.indexOf(Qi(J,A))-Hl.indexOf(Qi(_e,A))||J.id.localeCompare(_e.id)},{id:"name",label:s("st.list.sort.name"),compare:(J,_e)=>J.id.localeCompare(_e.id)}],[s,A]),X=Qs({listId:"connections",items:C,keyOf:M,textOf:z,filters:H,sorts:U}),q=J=>{if(J.plugin!==void 0){const Le=L.get(J.id)??nr,Se=o!==null&&Le.some(Fe=>Fe.id===o);return e.jsx(m$,{provider:J,plugin:J.plugin,models:Le,defaultOpen:Se||m===J.id,density:X.density})}if(ha(J))return e.jsx(LT,{provider:J,density:X.density,defaultOpen:c===J.id||m===J.id,openFocusKeySignal:h?.providerId===J.id?h.nonce:0,onChanged:w});const _e=R(J.id),we=L.get(J.id)??nr,G=o!==null&&we.some(Le=>Le.id===o);return e.jsx(XT,{provider:J,models:we,defaultOpen:G||c===J.id||m===J.id,openFocusKeySignal:h?.providerId===J.id?h.nonce:0,modelList:e.jsx(HA,{providerId:J.id,models:we}),managed:A.has(J.id),modelCount:we.length,onSaved:w,accountLabel:_e?.label,accountMethod:_e,density:X.density})},[F,V]=x.useState(!1),[se,Y]=x.useState(!1),[O,B]=x.useState(null),le=a==="#decision-connection-add",ne=F||$||(a==="#st-card-auth"||a==="#st-card-providers-add"||le)&&O!==a,Ee=()=>{V(!1),Y(!1),B(a)},ie=()=>{Y(!1),V(!0),p(null)},me=a==="#st-card-engines"||l!==null,[fe,Ie]=x.useState(me);x.useEffect(()=>{me&&Ie(!0)},[me]);const te=x.useContext(Mn);x.useEffect(()=>{ne&&a==="#st-card-auth"&&te?.("st-card-auth"),ne&&(a==="#st-card-providers-add"||le)&&te?.("st-card-providers-add")},[ne,a,le,te]);const ee=se||le&&O!==a?e.jsx(nI,{initialMethod:"api",initialDecisionPreset:le&&O!==a?"openai_decisions":void 0,configuredIds:k,onSaved:async()=>{await w(),Ee()},onImported:w,onAccountChanged:w},le&&O!==a?"decision-add":"custom"):e.jsx(YC,{surface:"settings",initialLane:a==="#st-card-auth"?"account":null,configuredProviderIds:j,onConnected:async()=>{await w(),$||Ee()},onOpenCustomForm:()=>{Y(!0)}},a==="#st-card-auth"?"account":"lanes"),K=!$&&!ne?e.jsxs("button",{type:"button","data-add-connection":!0,className:`${Q} inline-flex items-center gap-1.5`,onClick:ie,children:[e.jsx(de,{name:"plus",size:12}),s("st.connections.add")]}):void 0,Z=J=>[...document.querySelectorAll("[data-connection-row]")].find(_e=>_e.dataset.connectionRow===J)??null,ue=J=>{X.narrowed&&!X.visible.some(_e=>_e.id===J)&&X.clear(),f(J),b(_e=>({providerId:J,nonce:(_e?.nonce??0)+1})),requestAnimationFrame(()=>{Z(J)?.scrollIntoView?.({block:"nearest"})})},Te=J=>{X.narrowed&&!X.visible.some(_e=>_e.id===J)&&X.clear(),f(J),requestAnimationFrame(()=>{const _e=Z(J);_e!==null&&(_e.open=!0,_e.scrollIntoView?.({block:"nearest"}))})},Ne=e.jsxs("div",{className:"space-y-6",children:[E.length>0?e.jsxs("section",{"data-connections-attention":!0,"aria-label":s("st.nav.needsAttention"),className:"space-y-1.5",children:[e.jsx("p",{className:"text-[14px] font-[550] text-amber-ink",children:s("st.nav.needsAttention")}),e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline",children:E.map(J=>{const _e=R(J.id),we=J.plugin,G=Qi(J,A),Le=I(J.id)||we?.model_count||0,Se=G==="decision",Fe=Se&&J.api_key_env!==void 0&&!J.has_api_key,ye=Se&&(J.default_model??"")==="",ze=we===void 0&&G==="api"&&!uo(J.base_url)&&!J.has_api_key&&J.api_key_env===void 0,Pe=_e===void 0?null:$d(_e,void 0),xe=we!==void 0?we.readiness==="auth_required"?s("st.connections.plugin.authRequired"):we.status_text??s("st.connections.statusError"):Pe!==null?s(Ab(Pe)):J.status==="error"?s("st.connections.statusError"):Fe?s("st.decision.status.envMissing",{name:J.api_key_env??""}):s(ye?"st.decision.status.needsModel":ze?"st.connections.statusNeedsKey":"st.connections.statusSetup"),ke=J.label??_e?.label??(Se?J.id:Pb(J.base_url)??J.id);return e.jsxs("li",{"data-attention-row":J.id,className:"flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"text-[13px] font-medium text-ink",children:ke}),e.jsxs("span",{className:"ml-2 text-[12px] text-ink-faint",children:[s(`st.connections.kind.${G}`),Se?"":` · ${s("st.connections.modelCount",{count:Le})}`]})]}),e.jsx("span",{className:`shrink-0 text-[12px] ${J.status==="error"?"text-danger":"text-amber-ink"}`,children:xe}),we!==void 0?e.jsx(_t,{to:ny(we),"data-attention-fix":J.id,className:`inline-flex min-h-7 shrink-0 items-center px-1 pointer-coarse:min-h-10 ${Ot}`,children:we.readiness==="auth_required"?s("st.connections.plugin.signIn"):s("st.connections.plugin.manage")}):ze?e.jsx("button",{type:"button","data-attention-fix":J.id,className:`min-h-7 shrink-0 px-1 pointer-coarse:min-h-10 ${Ot}`,onClick:()=>{ue(J.id)},children:s("st.ai.fix.key")}):_e!==void 0&&(Pe?.state==="signIn"||Pe?.state==="reconnect")?e.jsx("button",{type:"button","data-attention-fix":J.id,disabled:N.busy!==null,className:`min-h-7 shrink-0 px-1 pointer-coarse:min-h-10 ${Ot}`,onClick:()=>{Te(J.id),N.start(_e)},children:Pe.state==="signIn"?s("st.account.signIn"):s("st.account.signInAgain")}):e.jsx("button",{type:"button","data-attention-fix":J.id,className:`min-h-7 shrink-0 px-1 pointer-coarse:min-h-10 ${Ot}`,onClick:()=>{Te(J.id)},children:s("st.profiles.openThere")})]},J.id)})})]}):null,$?e.jsx("div",{id:"st-card-providers","data-providers-zone":"connections",children:e.jsx("div",{id:a==="#st-card-auth"?"st-card-auth":"st-card-providers-add",children:ee})}):e.jsx("div",{"data-providers-zone":"connections",children:e.jsx(Me,{id:"st-card-providers",title:s("st.ai.tab.connections"),actions:K,children:e.jsxs("div",{className:"space-y-3",children:[C.length>0?e.jsx(Gs,{view:X,total:C.length,filters:H,sorts:U,searchLabel:s("st.connections.search"),searchPlaceholder:s("st.connections.searchPlaceholder")}):null,C.length>0&&X.visible.length===0?e.jsx(Ct,{kind:"no-match",title:s("st.connections.noMatchTitle"),body:X.query.trim()!==""?s("st.connections.noMatches",{query:X.query.trim()}):void 0,onClear:X.clear}):null,X.visible.length>0?e.jsx("div",{"data-connection-list":!0,children:e.jsx(Hs,{items:X.visible,keyOf:M,density:X.density,label:s("st.ai.tab.connections"),renderRow:q})}):null,g.isLoading?e.jsx(sg,{label:s("st.ai.status.loading"),rows:2}):null,[g,v].filter(J=>J.isError).map((J,_e)=>e.jsx("div",{"data-providers-read-error":!0,children:e.jsx(Qd,{message:s("st.ai.listFailed",{detail:oe(n,J.error)}),retrying:J.isFetching,onRetry:()=>{J.refetch()}})},_e)),e.jsx(pe,{feedback:u})]})})}),e.jsxs("details",{className:"group","data-providers-zone":"harnesses","data-engines-fold":!0,open:fe,onToggle:J=>{Ie(J.currentTarget.open)},children:[e.jsxs("summary",{className:"flex min-h-8 w-fit cursor-pointer list-none items-center gap-1.5 rounded-md px-1 text-[12.5px] font-medium text-ink-soft hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11 [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"text-ink-soft transition-transform group-open:rotate-90"}),s("st.ai.engines.fold")]}),fe?e.jsx("div",{className:"pt-3",children:e.jsxs(Me,{id:"st-card-engines",title:s("st.providers.localConnectionsTitle"),actions:e.jsx(KC,{}),children:[e.jsx(BC,{}),e.jsx("div",{className:"mt-4",children:e.jsxs(_t,{to:"/settings/external-clients","data-external-clients-entry":!0,title:s("st.engines.externalClientsEntryHint"),className:"-ml-1.5 inline-flex min-h-8 min-w-0 max-w-full items-center gap-1.5 rounded-md px-1.5 text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsx(de,{name:"external",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 truncate",children:s("st.engines.externalClientsEntry")}),e.jsx(de,{name:"chevron",size:12,className:"shrink-0 text-ink-faint"})]})})]})}):null]}),e.jsx(t$,{})]});return e.jsxs(e.Fragment,{children:[e.jsx(zA,{list:Ne,models:v.data?.items??[],providers:_,ready:v.isSuccess,onChanged:w,providerLabel:J=>R(J)?.label??J}),ne&&!$?e.jsx($n,{title:s("st.connections.addTitle"),overlayId:"settings-add-connection",onClose:Ee,width:"lg",data:{"data-add-connection-panel":""},children:e.jsx("div",{id:a==="#st-card-auth"?"st-card-auth":"st-card-providers-add",children:ee})}):null]})}const ts="rounded-md border border-hairline bg-paper px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink disabled:cursor-not-allowed disabled:opacity-50";function x$({recipeId:t,initialEdit:s=!1}){const n=Et(),a=()=>{n(vn())};return t===null?e.jsx(h$,{onOpen:i=>{n(vn(i))}}):e.jsx(v$,{installationId:t,initialEdit:s,onOpenLibrary:a,onEdit:i=>{n(vn(i,"edit"))},onForked:i=>{n(vn(i,"edit"),{replace:!0})},onRemoved:a},t)}function h$({onOpen:t}){const{t:s,locale:n}=D(),{client:a}=be(),i=$o(),r=i.data??[],[o,l]=x.useState(null),[c,d]=x.useState(null),u=yt(()=>a.checkRecipeUpdates(),{onSuccess:m=>{const f=m.filter(g=>g.update_available===!0).length;l({tone:"success",text:s("st.recipes.checked",{count:m.length,updates:f})})},onError:m=>{l({tone:"error",text:s("st.recipe.updateFailed",{detail:oe(n,m)})})}}),p=yt(m=>a.updateRecipe({installation_id:m.summary.installation_id,expected_revision:m.summary.revision,update_mode:m.mode}),{onSuccess:()=>{l({tone:"success",text:s("st.recipe.updatedShort")})},onError:m=>{l({tone:"error",text:s("st.recipe.updateFailed",{detail:oe(n,m)})})}}),h=yt(m=>a.updateRecipe({installation_id:m.installation_id,expected_revision:m.revision}),{onSuccess:()=>{l({tone:"success",text:s("st.recipe.updatedShort")})},onError:m=>{l({tone:"error",text:s("st.recipe.updateFailed",{detail:oe(n,m)})})}}),b=yt(m=>a.removeRecipe({installation_id:m.installation_id,expected_revision:m.revision,disable_models:!0}),{onSuccess:()=>{d(null)},onError:m=>{d(null),l({tone:"error",text:s("st.recipe.removeFailed",{detail:oe(n,m)})})}});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(Me,{id:"st-card-recipes-library",title:s("st.recipes.libraryTitle"),actions:e.jsx("button",{type:"button",className:ts,disabled:u.isPending||i.isError,"data-recipes-check-updates":!0,onClick:()=>{l(null),u.mutate(void 0)},children:s("st.recipes.checkUpdates")}),children:[i.isError?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:s("st.recipe.listFailed",{detail:oe(n,i.error)})}),e.jsx("button",{type:"button",className:ts,disabled:i.isFetching,"data-recipes-list-retry":!0,onClick:()=>{i.refetch()},children:s("st.recipe.retryLoad")})]}):i.isPending?e.jsx("p",{role:"status",className:"text-[12px] text-ink-faint",children:s("st.recipe.loading")}):r.length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipes-empty":!0,children:s("st.recipe.noneInstalled")}):e.jsx(f$,{installed:r,busy:p.isPending||h.isPending||b.isPending,onOpen:t,onSetMode:(m,f)=>{l(null),p.mutate({summary:m,mode:f})},onUpdate:m=>{l(null),h.mutate(m)},onRemove:m=>{l(null),d(m)}}),e.jsx(pe,{feedback:o})]}),e.jsx(Xe,{open:c!==null,stacked:!0,overlayId:"recipe-row-remove-confirm",title:s("st.recipe.removeConfirmTitle",{name:c?.name??""}),body:s("st.recipe.removeConfirmBody"),consequences:c===null||(c.used_by?.length??0)===0?void 0:[s("st.recipes.usedBy",{models:c.used_by.join(", ")})],confirmLabel:s("st.recipe.removeConfirmAction"),cancelLabel:s("common.cancel"),tone:"danger",busy:b.isPending,onCancel:()=>{d(null)},onConfirm:()=>{c!==null&&b.mutate(c)}}),e.jsx(b$,{}),e.jsx(g$,{})]})}function f$({installed:t,busy:s,onOpen:n,onSetMode:a,onUpdate:i,onRemove:r}){const o=Ta(),[l,c]=x.useState(null),d=x.useCallback(h=>{c(h)},[]),u=t.length>o.catalogVirtualizeThreshold,p=Ri({count:u?t.length:0,getScrollElement:()=>l,estimateSize:()=>68,getItemKey:h=>t[h]?.installation_id??h,overscan:o.virtualOverscan,initialRect:{width:640,height:480},observeElementRect:(h,b)=>{const m=h.scrollElement;if(m===null)return;const f=()=>{const v=m.getBoundingClientRect(),y=Math.round(v.height||m.clientHeight),w=Math.round(v.width||m.clientWidth);y>0&&b({width:w,height:y})};if(f(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(f);return g.observe(m),()=>{g.disconnect()}},measureElement:h=>{const b=Math.round(h.getBoundingClientRect().height);return b>0?b:68},useFlushSync:!1});return u?e.jsx("div",{ref:d,className:"max-h-[min(520px,65vh)] overflow-y-auto border-y border-hairline","data-recipes-list":!0,children:e.jsx("ul",{style:{height:p.getTotalSize(),position:"relative"},children:p.getVirtualItems().map(h=>{const b=t[h.index];return b===void 0?null:e.jsx("div",{"data-index":h.index,ref:p.measureElement,className:"border-b border-hairline last:border-b-0",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${h.start}px)`},children:e.jsx(uh,{summary:b,busy:s,onOpen:n,onSetMode:m=>{a(b,m)},onUpdate:()=>{i(b)},onRemove:()=>{r(b)}})},h.key)})})}):e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline","data-recipes-list":!0,children:t.map(h=>e.jsx(uh,{summary:h,busy:s,onOpen:n,onSetMode:b=>{a(h,b)},onUpdate:()=>{i(h)},onRemove:()=>{r(h)}},h.installation_id))})}function uh({summary:t,busy:s,onOpen:n,onSetMode:a,onUpdate:i,onRemove:r}){const{t:o}=D(),l=Fc(t);return e.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1.5 py-2.5","data-recipes-row":t.installation_id,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{type:"button",className:"block max-w-full truncate text-left text-[13px] text-ink underline decoration-ink/20 underline-offset-4 outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40","data-recipes-open":t.installation_id,onClick:()=>{n(t.installation_id)},children:t.name}),e.jsxs("p",{className:"truncate font-mono text-[11px] text-ink-faint",children:[t.version," · ",_n(t.revision),l?"":` · ${o("st.recipe.unavailable")}`]}),t.used_by!==void 0&&t.used_by.length>0?e.jsx("p",{className:"truncate text-[11px] text-ink-faint","data-recipes-used-by":t.installation_id,children:o("st.recipes.usedBy",{models:t.used_by.join(", ")})}):null,t.last_error!==void 0?e.jsx("p",{className:"text-[11.5px] leading-5 text-amber-ink","data-recipes-row-error":t.installation_id,children:o("st.recipe.updateFailedStillUsing",{version:t.version,reason:t.last_error.message})}):null]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[l?null:e.jsx("button",{type:"button",className:ts,disabled:s,"data-recipes-remove":t.installation_id,onClick:r,children:o("st.recipe.remove")}),t.update_available===!0?e.jsx("button",{type:"button",className:ts,disabled:s,"data-recipes-update":t.installation_id,onClick:i,children:o("st.recipe.update")}):null,e.jsx(Qe,{ariaLabel:o("st.recipe.updateModeAria",{name:t.name}),variant:"form",className:"w-auto px-2.5 py-1 text-[12px]",triggerData:{"data-recipes-update-mode":t.installation_id},value:t.update_mode,disabled:s,onChange:c=>{a(c==="follow"?"follow":"pinned")},choices:[{value:"follow",label:o("st.recipe.modeFollow")},{value:"pinned",label:o("st.recipe.modePinned")}]})]})]})}function b$(){const{t}=D(),s=Et(),[n,a]=x.useState(null);return e.jsxs(Me,{id:"st-card-recipe-import",title:t("st.recipes.installFrom"),children:[e.jsx(zv,{onInstalled:i=>{s(vn(i))},onFeedback:a}),e.jsx(pe,{feedback:n})]})}function g$(){const{t,locale:s}=D(),{client:n}=be(),a=vv(),i=a.data??[],[r,o]=x.useState(null),[l,c]=x.useState(""),[d,u]=x.useState(""),p=yt(m=>i.some(f=>f.id===m.id)?n.updateRecipeMarket(m):n.addRecipeMarket(m),{onSuccess:()=>{o({tone:"success",text:t("st.recipe.marketSaved")})},onError:m=>{o({tone:"error",text:t("st.recipe.marketAddFailed",{detail:oe(s,m)})})}}),h=yt(m=>n.removeRecipeMarket(m),{onSuccess:()=>{o({tone:"success",text:t("st.recipe.marketSaved")})},onError:m=>{o({tone:"error",text:t("st.recipe.marketAddFailed",{detail:oe(s,m)})})}}),b=()=>{const m=d.trim();if(m==="")return;const f=m.replace(/^https?:\/\//u,"").replaceAll(/[^a-z0-9]+/giu,"-").replaceAll(/^-|-$/g,"").toLowerCase();p.mutate({id:f===""?`market-${i.length+1}`:f,name:l.trim()===""?m:l.trim(),url:m,enabled:!0,offline:!1}),c(""),u("")};return e.jsxs(Me,{id:"st-card-recipe-markets",title:t("st.recipe.market"),children:[a.isError?e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:t("st.recipe.marketFailed",{detail:oe(s,a.error)})}):e.jsxs("div",{className:"space-y-3","data-recipe-market-manager":!0,children:[i.length===0?e.jsx("p",{className:"text-[12px] leading-5 text-ink-faint","data-recipe-no-markets":!0,children:t("st.recipe.noMarkets")}):e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline","data-recipe-market-rows":!0,children:i.map(m=>e.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1.5 py-2","data-recipe-market-row":m.id,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] text-ink",children:m.name}),e.jsx("p",{className:"truncate font-mono text-[11px] text-ink-faint",children:m.url}),m.offline?e.jsx("p",{className:"text-[11.5px] leading-5 text-amber-ink",children:t("st.recipe.marketOffline",{name:m.name})}):null]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-soft",children:[e.jsx("input",{type:"checkbox",checked:m.enabled,disabled:p.isPending,"data-recipe-market-enabled":m.id,onChange:f=>{p.mutate({...m,enabled:f.target.checked})}}),t("st.recipe.marketEnabled")]}),e.jsx("button",{type:"button",className:ts,disabled:h.isPending,"data-recipe-market-remove":m.id,onClick:()=>{h.mutate(m.id)},children:t("st.recipe.marketRemove")})]})]},m.id))}),e.jsxs("div",{className:"space-y-2","data-recipe-market-add":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:t("st.recipe.marketAdd")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{className:`${pt} min-w-0 flex-1`,value:l,placeholder:t("st.recipe.marketName"),"data-recipe-market-add-name":!0,onChange:m=>{c(m.target.value)}}),e.jsx("input",{className:`${pt} min-w-0 flex-[2] font-mono`,value:d,placeholder:"https://example.com/recipes/catalog.json","data-recipe-market-add-url":!0,onChange:m=>{u(m.target.value)}}),e.jsx("button",{type:"button",className:ts,disabled:p.isPending||d.trim()==="","data-recipe-market-add-submit":!0,onClick:b,children:t("st.recipe.marketAdd")})]}),e.jsx(he,{children:t("st.recipe.marketAddHint")})]})]}),e.jsx(pe,{feedback:r})]})}function v$({installationId:t,initialEdit:s,onOpenLibrary:n,onEdit:a,onForked:i,onRemoved:r}){const{t:o,locale:l}=D(),{client:c}=be(),[d,u]=x.useState(null),h=UI(d??t),m=$o().data?.find(k=>k.installation_id===t),[f,g]=x.useState(s),[v,y]=x.useState(null),[w,N]=x.useState(!1),_=yt(k=>c.forkRecipe({installation_id:t,mode:k,id:`${h.data?.summary.manifest_id??"recipe"}-local`,name:`${h.data?.summary.name??"Recipe"} (${k})`}),{onSuccess:k=>{u(k.summary.installation_id),i(k.summary.installation_id)},onError:k=>{y({tone:"error",text:o("st.recipe.forkFailed",{detail:oe(l,k)})})}}),C=yt(()=>c.removeRecipe({installation_id:t,expected_revision:h.data?.summary.revision??m?.revision,disable_models:!0}),{onSuccess:()=>{N(!1),r()},onError:k=>{N(!1),y({tone:"error",text:o("st.recipe.removeFailed",{detail:oe(l,k)})})}});if(h.data===void 0){const k=m?.name??t,j=m?.used_by??[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("button",{type:"button",className:ts,"data-recipe-open-library":!0,onClick:n,children:o("st.recipe.backToList")}),h.isError?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-recipe-load-failed":!0,children:[e.jsx("p",{role:"alert",className:"text-[12px] leading-5 text-danger",children:o("st.recipe.loadFailed",{detail:oe(l,h.error)})}),e.jsx("button",{type:"button",className:ts,disabled:h.isFetching,"data-recipe-load-retry":!0,onClick:()=>{h.refetch()},children:o("st.recipe.retryLoad")}),e.jsx("button",{type:"button",className:ts,disabled:C.isPending,"data-recipe-remove":t,onClick:()=>{y(null),N(!0)},children:o("st.recipe.remove")})]}):e.jsx("p",{role:"status",className:"text-[12px] text-ink-faint",children:o(h.isSuccess?"st.recipe.conflictGone":"st.recipe.loading")}),e.jsx(Xe,{open:w,stacked:!0,overlayId:"recipe-remove-confirm",title:o("st.recipe.removeConfirmTitle",{name:k}),body:o("st.recipe.removeConfirmBody"),consequences:j.length===0?void 0:[o("st.recipes.usedBy",{models:j.join(", ")})],confirmLabel:o("st.recipe.removeConfirmAction"),cancelLabel:o("common.cancel"),tone:"danger",busy:C.isPending,onCancel:()=>{N(!1)},onConfirm:()=>{C.mutate(void 0)}}),e.jsx(pe,{feedback:v})]})}const S=h.data;return f?!S.editable&&d===null?e.jsxs("div",{className:"space-y-4","data-recipe-fork-gate":t,children:[e.jsx("button",{type:"button",className:ts,onClick:()=>{g(!1)},children:o("st.recipe.back")}),e.jsx(Lv,{onFork:k=>{_.mutate(k)}}),e.jsx(pe,{feedback:v})]}):e.jsx(Rv,{detail:S,onApplied:()=>{},onBack:()=>{g(!1)}}):e.jsxs("div",{className:"space-y-5","data-recipe-package-page":t,children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:ts,"data-recipe-open-library":!0,onClick:n,children:o("st.recipe.backToList")})}),e.jsx(Hv,{detail:S}),e.jsxs("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] z-10 flex flex-wrap items-center gap-2 border-t border-hairline bg-canvas/95 py-3 backdrop-blur-sm",children:[e.jsx("button",{type:"button",className:ts,"data-recipe-edit":t,onClick:()=>{g(!0),a(t)},children:o(S.editable?"st.recipe.editPackage":"st.recipe.customizePackage")}),e.jsx("button",{type:"button",className:ts,"data-recipe-remove":t,onClick:()=>{N(!0)},children:o("st.recipe.remove")})]}),e.jsx(Xe,{open:w,stacked:!0,overlayId:"recipe-remove-confirm",title:o("st.recipe.removeConfirmTitle",{name:S.summary.name}),body:o("st.recipe.removeConfirmBody"),consequences:S.used_by.length===0?void 0:[o("st.recipes.usedBy",{models:S.used_by.join(", ")})],confirmLabel:o("st.recipe.removeConfirmAction"),cancelLabel:o("common.cancel"),tone:"danger",busy:C.isPending,onCancel:()=>{N(!1)},onConfirm:()=>{C.mutate(void 0)}}),e.jsx(pe,{feedback:v})]})}const y$="#st-card-recipes-library";function k$({resolvedTab:t}={}){const{t:s}=D(),n=Tt(),a=Et(),{search:i,hash:r}=Bt(),o=new URLSearchParams(i),l=o.get("tab"),c=eb(l??t)??yc,d=c==="recipes"&&r!==y$?aw(i):null,u=d!==null&&o.get("view")==="edit";x.useEffect(()=>{if(l!=="models")return;const h=new URLSearchParams(i);h.set("tab",yc),a(`/settings/ai?${h.toString()}${r}`,{replace:!0})},[l,i,r,a]),x.useEffect(()=>{if(r!=="#st-card-decision-connections")return;const h=new URLSearchParams(i).get(Mb);a(h!==null&&h!==""?Cc(h):qN,{replace:!0})},[i,r,a]);const p=h=>{if(h===c)return;const b=new URLSearchParams(i);h!=="recipes"&&(b.delete("recipe"),b.delete("view")),b.set("tab",h),n(`/settings/ai?${b.toString()}`)};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(lT,{tab:c}),e.jsx(Gd,{tabs:iw,current:c,ariaLabel:s("st.section.ai"),dataAttr:"data-ai-tab",labelOf:h=>s(rw(h)),onSelect:p}),c==="defaults"?e.jsx(sy,{}):c==="recipes"?e.jsx(x$,{recipeId:d,initialEdit:u}):e.jsx(ay,{})]})}let ph=0;function iy(){return ph+=1,`entry-${ph}`}function mh(t){return t.map(s=>({id:iy(),value:s}))}function j$(t){return t.map(s=>s.value)}function Ga(t,s){return t.length===s.length&&t.every((n,a)=>n===s[a])}function xh({label:t,values:s,onChange:n,placeholder:a}){const{t:i}=D(),[r,o]=x.useState(()=>mh(s)),l=x.useRef(s);s!==l.current&&(l.current=s,(s.length!==r.length||s.some((d,u)=>d!==r[u]?.value))&&o(mh(s)));const c=d=>{const u=j$(d);l.current=u,o(d),n(u)};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[11px] font-medium text-ink-soft",children:t}),e.jsx("button",{type:"button",className:Q,onClick:()=>{c([...r,{id:iy(),value:""}])},children:i("st.agentIdentity.addEntry")})]}),r.map((d,u)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:`${Ce} font-mono`,value:d.value,placeholder:a,"aria-label":`${t} ${u+1}`,onChange:p=>{c(r.map(h=>h===d?{...h,value:p.target.value}:h))}}),e.jsx("button",{type:"button",className:Q,"aria-label":i("st.agentIdentity.removeEntry",{n:u+1}),onClick:()=>{c(r.filter(p=>p!==d))},children:e.jsx(de,{name:"close",size:14})})]},d.id)),r.length===0?e.jsx(he,{children:i("st.agentIdentity.listEmpty")}):null]})}function w$(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(null),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),f=x.useRef(void 0);if(x.useEffect(()=>{if(m.data===void 0||m.data===f.current||c)return;f.current=m.data;const N=ms(m.data),_={identityName:N.identityName,identitySlug:N.identitySlug,advertiseAsKimiCode:N.advertiseAsKimiCode,extraAgentDirs:N.extraAgentDirs,disabledNamedProfiles:N.disabledNamedProfiles,skipBuiltinProfileInstallation:N.skipBuiltinProfileInstallation};r(i===null||o===null?_:{identityName:i.identityName===o.identityName?_.identityName:i.identityName,identitySlug:i.identitySlug===o.identitySlug?_.identitySlug:i.identitySlug,advertiseAsKimiCode:i.advertiseAsKimiCode===o.advertiseAsKimiCode?_.advertiseAsKimiCode:i.advertiseAsKimiCode,extraAgentDirs:Ga(i.extraAgentDirs,o.extraAgentDirs)?_.extraAgentDirs:i.extraAgentDirs,disabledNamedProfiles:Ga(i.disabledNamedProfiles,o.disabledNamedProfiles)?_.disabledNamedProfiles:i.disabledNamedProfiles,skipBuiltinProfileInstallation:Ga(i.skipBuiltinProfileInstallation,o.skipBuiltinProfileInstallation)?_.skipBuiltinProfileInstallation:i.skipBuiltinProfileInstallation}),l(_)},[m.data,i,o,c]),i===null||o===null)return e.jsx(Me,{id:"st-card-agent-runtime",title:s("st.agentIdentity.title"),children:m.isError?e.jsx(De,{error:m.error}):e.jsx(he,{children:s("st.runtime.loading")})});const g=N=>{r(N)},v={identityName:i.identityName!==o.identityName,identitySlug:i.identitySlug!==o.identitySlug,advertiseAsKimiCode:i.advertiseAsKimiCode!==o.advertiseAsKimiCode,extraAgentDirs:!Ga(i.extraAgentDirs,o.extraAgentDirs),skipBuiltinProfileInstallation:!Ga(i.skipBuiltinProfileInstallation,o.skipBuiltinProfileInstallation)},y=Object.values(v).some(Boolean),w=async()=>{d(!0),p(null);try{const N=v.identityName||v.identitySlug||v.advertiseAsKimiCode,_=await t.patchConfig(BN(i,v));a.setQueryData(["config"],_),await yn(a);const C=ms(_),S={identityName:C.identityName,identitySlug:C.identitySlug,advertiseAsKimiCode:C.advertiseAsKimiCode,extraAgentDirs:C.extraAgentDirs,disabledNamedProfiles:C.disabledNamedProfiles,skipBuiltinProfileInstallation:C.skipBuiltinProfileInstallation};r(S),l(S),N&&tb(["identity"]),b()}catch(N){p({tone:"error",text:oe(n,N)})}finally{d(!1)}};return e.jsx(Me,{id:"st-card-agent-runtime",title:s("st.agentIdentity.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{children:s("st.agentIdentity.hint")}),e.jsxs("fieldset",{disabled:c,className:"min-w-0 space-y-4 disabled:opacity-60",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"text-[11px] font-medium text-ink-soft",children:[s("st.agentIdentity.identityName"),e.jsx("input",{className:`${Ce} mt-1`,value:i.identityName,onChange:N=>{g({...i,identityName:N.target.value})}})]}),e.jsxs("label",{className:"text-[11px] font-medium text-ink-soft",children:[s("st.agentIdentity.identitySlug"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:i.identitySlug,onChange:N=>{g({...i,identitySlug:N.target.value})}})]})]}),e.jsx(ge,{label:s("st.agentIdentity.advertiseAsKimiCode"),help:s("st.agentIdentity.advertiseAsKimiCodeHint"),children:e.jsx(Be,{layout:"bare",label:s("st.agentIdentity.advertiseAsKimiCode"),checked:i.advertiseAsKimiCode,onChange:N=>{g({...i,advertiseAsKimiCode:N})}})}),e.jsx(xh,{label:s("st.agentIdentity.extraAgentDirs"),values:i.extraAgentDirs,placeholder:"C:\\agents",onChange:N=>{g({...i,extraAgentDirs:N})}}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(xh,{label:s("st.agentIdentity.skipBuiltin"),values:i.skipBuiltinProfileInstallation,placeholder:"builtin-name",onChange:N=>{g({...i,skipBuiltinProfileInstallation:N})}}),e.jsx(he,{children:s("st.agentIdentity.skipBuiltinHint")})]})]}),e.jsx(lt,{saved:h,id:"agent-identity",dirty:y,saving:c,onSave:()=>void w(),onDiscard:()=>{r(o),p(null)}}),m.isError?e.jsx(De,{error:m.error}):null,e.jsx(pe,{feedback:u})]})})}const zl={workspaceIdleTtlS:"300",imageMaxEdgePx:"2000",imageReadByteBudget:"262144"};function N$(t){const s=t.trim();if(s==="")return"";const n=Number(s);return Number.isFinite(n)?String(n/1e3):t}function S$(t){const s=t.trim();if(s==="")return"";const n=Number(s);return Number.isFinite(n)?String(Math.round(n*1e3)):t}function Ql({label:t,id:s,detail:n,unit:a,value:i,disabled:r,onChange:o}){return e.jsx(ge,{label:t,htmlFor:s,detail:n,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{id:s,className:"h-8 w-24 rounded-md border border-hairline bg-paper px-2 text-right font-mono text-[12.5px] text-ink outline-none transition-colors hover:border-hairline-strong focus:border-selected-ink",inputMode:"numeric",value:i,disabled:r,onChange:l=>{o(l.target.value)}}),a!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:a}):null]})})}function C$(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(null),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),f=i!==null&&o!==null&&(i.workspaceIdleTtlMs!==o.workspaceIdleTtlMs||i.imageMaxEdgePx!==o.imageMaxEdgePx||i.imageReadByteBudget!==o.imageReadByteBudget),g=y=>{const w=ms(y);return{workspaceIdleTtlMs:w.workspaceIdleTtlMs,imageMaxEdgePx:w.imageMaxEdgePx,imageReadByteBudget:w.imageReadByteBudget}};if(x.useEffect(()=>{if(m.data===void 0||f)return;const y=g(m.data);r(y),l(y)},[m.data,f]),i===null||o===null)return e.jsx(Me,{id:"st-card-resource-limits",title:s("st.resourceLimits.title"),children:m.isError?e.jsx(De,{error:m.error}):e.jsx(he,{children:s("st.runtime.loading")})});const v=async()=>{let y;try{y=ow(i)}catch(w){p({tone:"error",text:oe(n,w)});return}d(!0),p(null);try{const w=await t.patchConfig(y);a.setQueryData(["config"],w);const N=g(w);r(N),l(N),b()}catch(w){p({tone:"error",text:oe(n,w)})}finally{d(!1)}};return e.jsx(Me,{id:"st-card-resource-limits",title:s("st.resourceLimits.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs(Ze,{children:[e.jsx(Ql,{label:s("st.resourceLimits.workspaceIdle"),id:"resource-limits-workspace-idle",detail:s("st.resourceLimits.workspaceIdleDetail",{seconds:zl.workspaceIdleTtlS}),unit:s("st.residency.secondsUnit"),value:N$(i.workspaceIdleTtlMs),disabled:c,onChange:y=>{r({...i,workspaceIdleTtlMs:S$(y)})}}),e.jsx(Ql,{label:s("st.resourceLimits.imageMaxEdge"),id:"resource-limits-image-max-edge",detail:s("st.resourceLimits.imageMaxEdgeDetail",{px:zl.imageMaxEdgePx}),unit:s("st.resourceLimits.pxUnit"),value:i.imageMaxEdgePx,disabled:c,onChange:y=>{r({...i,imageMaxEdgePx:y})}}),e.jsx(Ql,{label:s("st.resourceLimits.imageBudget"),id:"resource-limits-image-budget",detail:s("st.resourceLimits.imageBudgetDetail",{bytes:zl.imageReadByteBudget}),unit:s("st.resourceLimits.bytesUnit"),value:i.imageReadByteBudget,disabled:c,onChange:y=>{r({...i,imageReadByteBudget:y})}})]}),e.jsx(lt,{saved:h,id:"resource-limits",dirty:f,saving:c,onSave:()=>void v(),onDiscard:()=>{if(m.data!==void 0){const y=g(m.data);r(y),l(y)}p(null)}}),m.isError?e.jsx(De,{error:m.error}):null,e.jsx(pe,{feedback:u})]})})}const _$=[{key:"maxLiveSessions",wire:"max_live_sessions",label:"st.residency.maxLive",seconds:!1,min:1,max:64,fallback:8},{key:"idleTtlMs",wire:"idle_ttl_ms",label:"st.residency.idleTtl",seconds:!0,min:0,max:864e5,fallback:6e5},{key:"minIdleMs",wire:"min_idle_ms",label:"st.residency.minIdle",seconds:!0,min:0,max:864e5,fallback:6e4},{key:"sweepIntervalMs",wire:"sweep_interval_ms",label:"st.residency.sweep",seconds:!0,min:1e3,max:3e5,fallback:3e4},{key:"maxConcurrentRestores",wire:"max_concurrent_restores",label:"st.residency.concurrentRestores",seconds:!1,min:1,max:4,fallback:1},{key:"maxQueuedRestores",wire:"max_queued_restores",label:"st.residency.queuedRestores",seconds:!1,min:0,max:64,fallback:8}];function E$({field:t,stored:s}){const{client:n}=be(),{t:a}=D(),i=Oe(),r=bt(),o=t.seconds?1e3:1,l=String((s??t.fallback)/o),c=t.min/o,d=t.max/o;return e.jsxs(ge,{label:a(t.label),detail:a("st.residency.default",{value:t.fallback/o}),children:[e.jsx(ot,{saving:r.saving,saved:r.saved}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{ariaLabel:a(t.label),dataAttr:`data-residency-${t.wire.replaceAll("_","-")}`,className:"w-20",inputMode:"numeric",value:l,disabled:r.saving,validate:u=>{const p=Number(u);return u!==""&&Number.isInteger(p)&&p>=c&&p<=d?null:a("st.residency.range",{min:c,max:d})},onCommit:u=>void r.run(async()=>{const p=await n.patchConfig({session_residency:{[t.wire]:Number(u)*o}});i.setQueryData(["config"],p)})}),t.seconds?e.jsx("span",{className:"text-[12px] text-ink-faint",children:a("st.residency.secondsUnit")}):null]}),e.jsx(pe,{feedback:r.error})]})}function T$(){const{client:t}=be(),{t:s}=D(),n=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4});if(n.data===void 0)return e.jsx(Me,{id:"st-card-session-residency",title:s("st.residency.title"),children:n.isError?e.jsx(De,{error:n.error}):e.jsx(he,{children:s("st.runtime.loading")})});const a=n.data.session_residency??{};return e.jsxs(Me,{id:"st-card-session-residency",title:s("st.residency.title"),children:[e.jsx(he,{children:s("st.residency.hint")}),e.jsx(Ze,{children:_$.map(i=>e.jsx(E$,{field:i,stored:a[i.key]},i.key))})]})}function cn(t,s){return t===void 0?s:{...t,...s,default_permission_mode:s.default_permission_mode??t.default_permission_mode,default_plan_mode:s.default_plan_mode??t.default_plan_mode,plan:s.plan===void 0?t.plan:t.plan===void 0?s.plan:{...t.plan,...s.plan}}}const I$=6e4,P$=5;function ry(){const{client:t}=be(),s=Oe(),n=bt(),a=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),i=a.data,r=l=>n.run(async()=>{const c=await t.patchConfig(l),d=cn(s.getQueryData(["config"])??i,c);return s.setQueryData(["config"],d),d}),o=n.saving||a.isPending||a.isError;return{config:i,configQuery:a,save:n,patch:r,locked:o,queryClient:s}}function A$(){const{t}=D(),{config:s,configQuery:n,save:a,patch:i,locked:r,queryClient:o}=ry(),l=s?.default_plan_mode===!0,c=async d=>{if(await i({default_plan_mode:d})){const u=o.getQueryData(["config"]);Mt({defaultPlanMode:u?.default_plan_mode===!0})}};return e.jsx(Me,{id:"st-card-defaults",title:t("st.sessions.card.newSessions"),effect:"newSessions",children:e.jsxs("div",{"data-plan-settings":!0,className:"space-y-2",children:[e.jsx(Ze,{children:e.jsx(ge,{label:t("st.sessions.plan.label"),help:t("st.defaults.planModeHint"),children:e.jsx(Be,{layout:"bare",label:t("st.sessions.plan.label"),checked:l,disabled:r,onChange:d=>void c(d)})})}),e.jsx(ot,{saving:a.saving,saved:a.saved}),n.isError?e.jsx(De,{error:n.error}):null,e.jsx(pe,{feedback:a.error})]})})}function $$(){const{t}=D(),{config:s,configQuery:n,save:a,patch:i,locked:r}=ry(),o=s?.plan?.gate==="gated",l=String((s?.plan?.enterApprovalTimeoutMs??I$)/1e3),c=d=>{const u=Number(d);return d!==""&&Number.isFinite(u)&&u>=P$?null:t("st.defaults.planGateTimeoutInvalid")};return e.jsxs("div",{"data-plan-gate":!0,className:"contents",children:[e.jsxs(ge,{label:t("st.defaults.planGate"),help:t("st.defaults.planGateHint"),children:[e.jsx(ot,{saving:a.saving,saved:a.saved}),e.jsx(Be,{layout:"bare",label:t("st.defaults.planGate"),checked:o,disabled:r,onChange:d=>void i({plan:{gate:d?"gated":"free"}})})]}),e.jsx(Id,{when:o,children:e.jsx(ge,{label:t("st.defaults.planGateTimeout"),htmlFor:"plan-gate-timeout",help:t("st.defaults.planGateTimeoutHint"),children:e.jsx(kt,{id:"plan-gate-timeout",className:"w-24 text-right",inputMode:"numeric",disabled:r,value:l,validate:c,onCommit:d=>{i({plan:{enter_approval_timeout_ms:Math.round(Number(d)*1e3)}})}})})}),n.isError?e.jsx(De,{error:n.error}):null,e.jsx(pe,{feedback:a.error})]})}function R$(t){const s=t?.prompt;return{source:t?.prompt_source??(s===void 0||s===""?"default":"custom"),defaultPrompt:t?.default_prompt,customPrompt:s===void 0||s===""?void 0:s}}function L$(t,s){return t!==(s??"")}function M$({disabled:t=!1}){const{client:s}=be(),{t:n,locale:a}=D(),i=Oe(),r=je({queryKey:["config"],queryFn:()=>s.getConfig(),staleTime:6e4}),[o,l]=x.useState(null),[c,d]=x.useState(!1),[u,p]=x.useState(!1),[h,b]=x.useState(null),m=x.useId(),f=r.data?.session_title,g=R$(f),v=g.customPrompt??"",y=o!==null&&L$(o,v),w=o!==null&&o.trim()==="";x.useEffect(()=>{r.data!==void 0&&!y&&l(v)},[r.data,v,y]);const N=async(S,k)=>{p(!0),b(null);try{const j=await s.getConfig(),T=await s.patchConfig(lw(S));return i.setQueryData(["config"],cn(j,T)),l(S??""),b(k===null?null:{tone:"success",text:k}),!0}catch(j){return b({tone:"error",text:oe(a,j)}),!1}finally{p(!1)}},_=async()=>{const S=g.customPrompt;!await N(null,null)||S===void 0||xs({text:n("st.sessionTitlePrompt.restoredUndo"),undoFailedText:n("toast.undoFailed"),undo:async()=>{await N(S,null)}})},C=r.data!==void 0;return e.jsxs("div",{className:"space-y-2 py-1","data-session-title-prompt":!0,"data-prompt-source":g.source,children:[e.jsx("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:e.jsxs("span",{className:"text-[13px] text-ink",children:[n("st.sessionTitlePrompt.source"),e.jsx("span",{className:"text-ink-faint",children:" · "}),g.source==="custom"?n("st.sessionTitlePrompt.sourceCustom"):n("st.sessionTitlePrompt.sourceDefault")]})}),g.defaultPrompt===void 0?e.jsx(he,{children:n("st.sessionTitlePrompt.defaultUnavailable")}):null,g.defaultPrompt!==void 0?e.jsxs("figure",{className:"space-y-1 rounded-lg border border-hairline bg-hairline/20 p-3",children:[e.jsxs("figcaption",{className:"flex items-center gap-2 text-[11px] font-medium text-ink-soft",children:[n("st.sessionTitlePrompt.defaultTitle"),e.jsx("button",{type:"button","data-session-title-prompt-toggle-default":!0,className:"font-normal text-ink-faint underline-offset-2 transition-colors hover:text-ink hover:underline focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none","aria-expanded":c,onClick:()=>{d(S=>!S)},children:n(c?"st.sessionTitlePrompt.collapse":"st.sessionTitlePrompt.expand")})]}),c?e.jsx("p",{className:"max-w-[68ch] whitespace-pre-wrap break-words text-[12px] leading-relaxed text-ink-soft",children:g.defaultPrompt}):null]}):null,e.jsxs(e.Fragment,{children:[e.jsx("label",{htmlFor:"session-title-prompt",className:"block text-[13px] text-ink",children:n("st.sessionTitlePrompt.customLabel")}),e.jsx("textarea",{id:"session-title-prompt","data-session-title-prompt-input":!0,className:`${Ce} min-h-32 resize-y font-mono leading-relaxed`,value:o??"",disabled:!C||u||t,spellCheck:!1,placeholder:n("st.sessionTitlePrompt.customPlaceholder"),"aria-describedby":m,onChange:S=>{l(S.target.value),b(null)}}),e.jsx(he,{children:n(w&&y?"st.sessionTitlePrompt.blank":"st.sessionTitlePrompt.customHelp")}),e.jsx(it,{id:m,text:h?.tone==="error"?h.text:null}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1","data-settings-actions":!0,children:[e.jsx("button",{type:"button","data-session-title-prompt-save":!0,className:`${Ye} inline-flex h-8 items-center gap-1.5`,disabled:!C||!y||u||t,onClick:()=>{N(w?null:o,n("st.sessionTitlePrompt.saved"))},children:n("st.sessionTitlePrompt.save")}),g.source==="custom"?e.jsxs("button",{type:"button","data-session-title-prompt-restore":!0,className:`${Q} inline-flex h-8 items-center gap-1.5`,disabled:!C||u||t,onClick:()=>{_()},children:[e.jsx(de,{name:"arrowLeft",size:12}),n("st.sessionTitlePrompt.restore")]}):null]})]}),h?.tone==="success"?e.jsx(pe,{feedback:h}):null]})}function ui({label:t,value:s,onChange:n,placeholder:a,hint:i,detail:r}){const o=x.useId(),l=x.useId();return e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("label",{htmlFor:o,className:$e,children:t}),r!=null?e.jsx(Rn,{children:r}):null]}),e.jsx("input",{id:o,className:`${Ce} mt-1 font-mono font-normal`,inputMode:"numeric",value:s,placeholder:a,"aria-describedby":i===void 0?void 0:l,onChange:c=>{n(c.target.value)}}),i===void 0?null:e.jsx("p",{id:l,className:"mt-1 max-w-[62ch] text-[12px] font-normal leading-snug text-ink-faint",children:i})]})}function hh({title:t,hint:s,children:n}){return e.jsxs("section",{className:"space-y-3 pt-3 first:pt-0",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[12px] font-semibold text-ink",children:t}),s!==void 0?e.jsx("p",{className:"mt-0.5 text-[12px] leading-snug text-ink-faint",children:s}):null]}),n]})}const Zs={bashTaskTimeoutS:"600",killGracePeriodMs:"5000",printWaitCeilingS:"2147483",printMaxTurns:"100000"};function O$({label:t,id:s,value:n,placeholder:a,detail:i,unit:r,disabled:o,onChange:l}){return e.jsx(ge,{label:t,htmlFor:s,detail:i,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{id:s,className:"h-8 w-24 rounded-md border border-hairline bg-paper px-2 text-right font-mono text-[12.5px] text-ink outline-none transition-colors hover:border-hairline-strong focus:border-selected-ink disabled:opacity-60",inputMode:"numeric",value:n,placeholder:a,disabled:o,onChange:c=>{l(c.target.value)}}),r!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:r}):null]})})}const D$=["exit","drain","steer"],F$={exit:"st.taskPolicy.printMode.exit",drain:"st.taskPolicy.printMode.drain",steer:"st.taskPolicy.printMode.steer"},q$={exit:"st.taskPolicy.printMode.exitHint",drain:"st.taskPolicy.printMode.drainHint",steer:"st.taskPolicy.printMode.steerHint"};function B$({value:t,onChange:s}){const{t:n}=D();return e.jsxs("fieldset",{className:"min-w-0 space-y-1.5","data-task-print-mode":t,children:[e.jsx("legend",{className:$e,children:n("st.taskPolicy.printMode")}),D$.map(a=>{const i=a===t;return e.jsxs("label",{"data-task-print-mode-choice":a,className:`flex cursor-pointer items-start gap-2 rounded-lg p-2.5 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-selected-ink/50 ${i?"bg-panel shadow-[var(--kiki-sheet-shadow)]":"bg-ink/[0.03] hover:bg-ink/[0.05]"}`,children:[e.jsx("input",{type:"radio",name:"task-print-mode",className:"mt-0.5 accent-[var(--color-selected-ink)]",checked:i,onChange:()=>{i||s(a)}}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex flex-wrap items-baseline gap-1",children:[e.jsx("span",{className:"text-[13px] font-medium text-ink",children:n(F$[a])}),e.jsx("span",{"aria-hidden":!0,className:"text-[11px] text-ink-faint",children:"·"}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:a})]}),e.jsx("span",{className:"mt-0.5 block text-[12px] leading-snug text-ink-faint",children:n(q$[a])})]})]},a)})]})}function oy(){const{client:t}=be(),{t:s}=D(),n=Oe(),a=bt(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),[r,o]=x.useState({});if(i.data===void 0)return e.jsx(Me,{id:"st-card-background-work",title:s("st.sessions.card.background"),children:i.isError?e.jsx(De,{error:i.error}):e.jsx(he,{children:s("st.runtime.loading")})});const l={...ms(i.data).task,...r},c=u=>{o(u),a.run(async()=>{const p=n.getQueryData(["config"])??i.data,h=await t.patchConfig(sb({...ms(p).task,...u}));n.setQueryData(["config"],h)}).finally(()=>{o({})})},d=u=>u===""||/^\d+$/.test(u)?null:s("val.runtimeNonNegative",{field:s("st.taskPolicy.bashTimeout")});return e.jsx(Me,{id:"st-card-background-work",title:s("st.sessions.card.background"),children:e.jsxs("div",{className:"space-y-2","data-background-work":!0,children:[e.jsxs(Ze,{children:[e.jsx(ge,{label:s("st.taskPolicy.bashTimeout"),htmlFor:"task-bash-timeout",help:s("st.taskPolicy.bashTimeoutHint"),detail:s("st.taskPolicy.bashTimeoutDetail",{seconds:Zs.bashTaskTimeoutS}),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{id:"task-bash-timeout",className:"w-24 text-right",inputMode:"numeric",value:l.bashTaskTimeoutS,placeholder:Zs.bashTaskTimeoutS,disabled:a.saving,validate:d,onCommit:u=>{c({bashTaskTimeoutS:u})}}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:s("st.residency.secondsUnit")})]})}),e.jsx(ge,{label:s("st.taskPolicy.autoBackground"),help:s("st.taskPolicy.autoBackgroundHelp"),children:e.jsx(Be,{layout:"bare",label:s("st.taskPolicy.autoBackground"),checked:l.bashAutoBackgroundOnTimeout,disabled:a.saving,onChange:u=>{c({bashAutoBackgroundOnTimeout:u})}})}),e.jsx(ge,{label:s("st.taskPolicy.keepAlive"),help:s("st.taskPolicy.keepAliveHelp"),children:e.jsx(Be,{layout:"bare",label:s("st.taskPolicy.keepAlive"),checked:l.keepAliveOnExit,disabled:a.saving,onChange:u=>{c({keepAliveOnExit:u})}})})]}),e.jsx(ot,{saving:a.saving,saved:a.saved}),e.jsx(pe,{feedback:a.error})]})})}function ly(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(!1),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4});if(x.useEffect(()=>{m.data!==void 0&&!o&&r(ms(m.data).task)},[m.data,o]),i===null)return e.jsx(Me,{id:"st-card-task-policy",title:s("st.taskPolicy.title"),children:m.isError?e.jsx(De,{error:m.error}):e.jsx(he,{children:s("st.runtime.loading")})});const f=v=>{r(y=>y===null?y:{...y,...v}),l(!0)},g=async()=>{let v;try{v=sb(i)}catch(y){p({tone:"error",text:oe(n,y)});return}d(!0),p(null);try{const y=await t.patchConfig(v);a.setQueryData(["config"],y),r(ms(y).task),l(!1),b()}catch(y){p({tone:"error",text:oe(n,y)})}finally{d(!1)}};return e.jsx(Me,{id:"st-card-task-policy",title:s("st.taskPolicy.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("fieldset",{disabled:c,className:"min-w-0 disabled:opacity-60",children:[e.jsxs(Ze,{children:[e.jsx(O$,{label:s("st.taskPolicy.maxRunningTasks"),id:"task-max-running",value:i.maxRunningTasks,placeholder:s("st.loopLimits.unlimited"),detail:s("st.taskPolicy.maxRunningTasksDetail"),disabled:c,onChange:v=>{f({maxRunningTasks:v})}}),e.jsx(ge,{label:s("st.taskPolicy.fileToolHints"),help:s("st.taskPolicy.fileToolHintsHelp"),children:e.jsx(Be,{layout:"bare",label:s("st.taskPolicy.fileToolHints"),checked:i.bashFileToolHints,onChange:v=>{f({bashFileToolHints:v})}})})]}),e.jsx(et,{summary:s("st.taskPolicy.advanced"),"data-task-policy-advanced":!0,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(hh,{title:s("st.taskPolicy.cliGroup"),hint:s("st.taskPolicy.cliGroupHint"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(ui,{label:s("st.taskPolicy.printWait"),value:i.printWaitCeilingS,placeholder:Zs.printWaitCeilingS,hint:s("st.taskPolicy.printWaitHint"),detail:s("st.taskPolicy.printWaitDetail",{seconds:Zs.printWaitCeilingS}),onChange:v=>{f({printWaitCeilingS:v})}}),e.jsx(ui,{label:s("st.taskPolicy.printTurns"),value:i.printMaxTurns,placeholder:Zs.printMaxTurns,hint:s("st.taskPolicy.printTurnsHint"),detail:s("st.taskPolicy.printTurnsDetail",{turns:Zs.printMaxTurns}),onChange:v=>{f({printMaxTurns:v})}})]}),e.jsx(B$,{value:i.printBackgroundMode,onChange:v=>{f({printBackgroundMode:v})}})]})}),e.jsx(hh,{title:s("st.taskPolicy.terminationGroup"),hint:s("st.taskPolicy.terminationGroupHint"),children:e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsx(ui,{label:s("st.taskPolicy.killGrace"),value:i.killGracePeriodMs,placeholder:Zs.killGracePeriodMs,hint:s("st.taskPolicy.killGraceHint"),detail:s("st.taskPolicy.killGraceDetail",{ms:Zs.killGracePeriodMs}),onChange:v=>{f({killGracePeriodMs:v})}})})})]})})]}),e.jsx(lt,{saved:h,id:"task-policy",dirty:o,saving:c,onSave:()=>void g(),onDiscard:()=>{m.data!==void 0&&r(ms(m.data).task),l(!1),p(null)}}),m.isError?e.jsx(De,{error:m.error}):null,e.jsx(pe,{feedback:u})]})})}function K$(){const{client:t}=be(),{t:s}=D(),[n,a]=x.useState(null),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4});x.useEffect(()=>{i.data!==void 0&&a(ms(i.data).cron)},[i.data]);const r=o=>s(o?"st.cron.on":"st.cron.off");return e.jsx(Me,{id:"st-card-cron",title:s("st.cron.title"),scope:"readOnly",children:e.jsx("div",{className:"space-y-3",children:n===null?i.isError?e.jsx(De,{error:i.error}):e.jsx(he,{children:s("st.runtime.loading")}):e.jsxs("dl",{className:"grid gap-x-6 sm:grid-cols-2","data-settings-diagnostics":!0,children:[e.jsx(un,{label:s("st.cron.debug"),value:r(n.debug)}),e.jsx(un,{label:s("st.cron.noJitter"),value:r(n.noJitter)}),e.jsx(un,{label:s("st.cron.noStale"),value:r(n.noStale)}),e.jsx(un,{label:s("st.cron.disabled"),value:r(n.disabled)}),e.jsx(un,{label:s("st.cron.manualTick"),value:r(n.manualTick)}),e.jsx(un,{label:s("st.cron.clock"),value:n.clock.trim()===""?s("st.cron.unset"):n.clock}),e.jsx(un,{label:s("st.cron.poll"),value:n.pollIntervalMs.trim()===""?s("st.cron.unset"):U$(n.pollIntervalMs)})]})})})}function U$(t){const s=t.trim();return s===""||!Number.isFinite(Number(s))?t:String(Number(s)/1e3)}function H$(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),[r,o]=x.useState("background"),[l,c]=x.useState(!1),[d,u]=x.useState(null),[p,h]=Je(),b=i.data?.interaction?.askUserQuestionGuard,[m,f]=x.useState(Vr),[g,v]=x.useState(Vr),y=bt();x.useEffect(()=>{i.data!==void 0&&!l&&o(i.data.interaction?.askUserQuestion??"background")},[i.data,l]),x.useEffect(()=>{if(i.data===void 0)return;const C=ch(b);ed(C,g)||(f(C),v(C))},[i.data,b,g]);const w=async C=>{const S=r;o(C),c(!0),u(null);try{const k=await t.patchConfig({interaction:{ask_user_question:C}}),j=cn(a.getQueryData(["config"])??i.data,k);a.setQueryData(["config"],j),o(j.interaction?.askUserQuestion??C),h()}catch(k){o(S),u({tone:"error",text:oe(n,k)})}finally{c(!1)}},N=C=>{if(Zv(C,j=>Mu(s,j))!==null)return;const k=dw(C,g);if(k===void 0){f(C),v(C);return}y.run(async()=>{const j=await t.patchConfig({interaction:k}),T=cn(a.getQueryData(["config"])??i.data,j);a.setQueryData(["config"],T);const A=ch(T.interaction?.askUserQuestionGuard);f(A),v(A)})},_=Lu(b,m);return e.jsxs(Me,{id:"st-card-questions",title:s("st.sessions.card.questions"),children:[e.jsxs("div",{"data-question-behavior":!0,children:[e.jsx(Ze,{children:e.jsxs(ge,{label:s("st.sessions.ask.label"),labelId:"question-behavior-label",detail:s("st.sessions.questionsHint"),children:[e.jsx(He,{ariaLabelledBy:"question-behavior-label",value:r,disabled:l||i.data===void 0,onChange:C=>void w(C),choices:[{value:"background",label:s("st.sessions.ask.continue")},{value:"blocking",label:s("st.sessions.ask.wait")}]}),e.jsx(jt,{show:p})]})}),e.jsx(pe,{feedback:d}),i.isError?e.jsx(De,{error:i.error}):null]}),e.jsxs(is,{title:s("st.questionGuard.title"),children:[e.jsx(Xv,{scope:"global",draft:m,enabled:_.enabled,saving:y.saving,saved:y.saved,disabled:i.data===void 0,onEnabledChange:C=>{N({...m,enabled:C})},onNumberCommit:(C,S)=>{N(Jv(m,C,S))}}),e.jsx(pe,{feedback:y.error})]})]})}const sd=cw,z$={first_user_message:"st.sessions.titleMoment.firstUserMessage",first_turn_completed:"st.sessions.titleMoment.firstTurnCompleted",context_compacted:"st.sessions.titleMoment.contextCompacted"};function cy(t){return t===void 0?["first_turn_completed"]:sd.filter(s=>t.includes(s))}function dy(){const{client:t}=be(),{locale:s}=D(),n=Oe(),[a,i]=x.useState(!1),[r,o]=x.useState({}),[l,c]=x.useState(null),[d,u]=Je();return{write:async(h,b)=>{o(b),i(!0),c(null);try{const m=await t.getConfig(),f=await t.patchConfig(h(m));n.setQueryData(["config"],cn(m,f)),await n.invalidateQueries({queryKey:["meta"]}),u()}catch(m){c({tone:"error",text:oe(s,m)})}finally{o({}),i(!1)}},saving:a,pending:r,feedback:l,saved:d}}function Q$(){const{client:t}=be(),{t:s}=D(),n=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),a=je({queryKey:["meta"],queryFn:()=>t.meta(),staleTime:15e3}),i=je({queryKey:["models"],queryFn:()=>t.listModels(),staleTime:6e4}),{write:r,saving:o,pending:l,feedback:c,saved:d}=dy(),u=n.data?.experimental?.auto_session_title,p=a.data?.experimental_flags?.auto_session_title,h=l.enabled??u??p??!1,b=l.model??n.data?.session_title?.model??"",m=h&&p===!1&&l.enabled===void 0&&u===!0,f=b.trim()!=="",g=cy(n.data?.session_title?.triggers),y=(i.data?.items??[]).find(S=>S.id===b)?.display_name??b,w=S=>r(k=>({experimental:{...k.experimental,auto_session_title:S},replace_domains:["experimental"]}),{enabled:S}),N=S=>r(()=>Xf(S),{model:S}),_=f&&g.includes("first_turn_completed")?s("st.sessions.title.help",{model:y}):void 0,C=n.data===void 0;return e.jsx(Me,{id:"st-card-session-title",title:s("st.sessions.card.titles"),children:e.jsxs("div",{className:"space-y-1","data-session-titles":!0,children:[C?n.isError?e.jsx(De,{error:n.error}):e.jsx(he,{children:s("st.runtime.loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-settings-field":!0,className:"py-1",children:[e.jsx(ge,{label:s("st.sessions.titleModel"),htmlFor:"session-title-model",detail:s(f?"st.sessionTitleModel.fallbackDetail":"st.sessionTitleModel.noneDetail"),children:e.jsx(nn,{id:"session-title-model",models:i.data?.items??[],disabled:o,value:b,allowCustomValue:!0,customValueLabel:S=>S,unsetLabel:s("st.sessionTitleModel.noneDefault"),unsetDescription:s("st.sessionTitleModel.noneDesc"),searchPlaceholder:s("st.sessionTitleModel.placeholder"),ariaLabel:s("st.sessions.titleModel"),emptyText:s("st.sessionTitleModel.noneDefault"),align:"end",placement:"auto",buttonClassName:`${zd} w-full sm:w-64`,onChange:S=>{S!==b&&N(S)}})}),f?null:e.jsx(he,{children:s("st.sessionTitleModel.unconfigured")})]}),e.jsxs("div",{"data-settings-field":!0,className:"space-y-0.5 py-1",children:[e.jsx(ge,{label:s("st.sessions.titlesToggle"),help:_,children:e.jsx(Be,{layout:"bare",label:s("st.sessions.titlesToggle"),checked:h,disabled:o,onChange:S=>void w(S)})}),m?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-amber-ink","data-session-titles-forced":!0,children:s("st.sessions.titlesServerOff")}):null]}),e.jsx(jt,{show:d})]}),e.jsx(pe,{feedback:c})]})})}function G$(){const{client:t}=be(),{t:s}=D(),n=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),{write:a,saving:i,pending:r,feedback:o,saved:l}=dy(),c=r.triggers??cy(n.data?.session_title?.triggers),d=(u,p)=>{const h=p?sd.filter(b=>b===u||c.includes(b)):c.filter(b=>b!==u);return a(()=>({session_title:{triggers:h}}),{triggers:h})};return e.jsx(Me,{id:"st-card-session-title-engine",title:s("st.sessions.titlesTitle"),children:e.jsx("div",{className:"space-y-1","data-session-title-engine":!0,children:n.data===void 0?n.isError?e.jsx(De,{error:n.error}):e.jsx(he,{children:s("st.runtime.loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("fieldset",{disabled:i,className:"space-y-1","data-session-title-moments":!0,children:[e.jsx("legend",{className:"mb-0.5 pt-1 text-[13px] text-ink",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s("st.sessions.titleMoments"),e.jsx(Rn,{children:s("st.sessions.titleMomentsHelp")})]})}),e.jsx("div",{className:"space-y-0.5 pt-0.5",children:sd.map(u=>e.jsxs("label",{"data-title-moment":u,className:"flex min-h-7 items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--color-selected-ink)]",checked:c.includes(u),onChange:p=>{d(u,p.target.checked)}}),s(z$[u])]},u))})]}),e.jsx(jt,{show:l}),e.jsx(pe,{feedback:o}),e.jsx("div",{className:"mt-4",children:e.jsx(M$,{disabled:i})})]})})})}const Gl="st-card-import-history",uy=`h-8 shrink-0 pointer-coarse:h-10 ${Ot}`;function W$(){const{client:t,scopeId:s}=be(),{t:n}=D(),a=Et(),i=x.useContext(Ia),r=x.useContext(Mn),o=Ob(t,s).enabled===!0;return x.useEffect(()=>{o&&r?.(Gl)},[o,r]),o?e.jsx("div",{id:"st-card-import-history","data-settings-card":Gl,className:`scroll-mt-4 ${i===Gl?"settings-card-flash":""}`,children:e.jsx(ge,{label:n("st.sessions.importRow"),help:n("st.sessions.importRowHint"),children:e.jsx("button",{type:"button","data-settings-open-import":!0,className:uy,onClick:()=>{a(Nd())},children:n("cap.import.open")})})}):null}const fh=100;function V$(){const{client:t,scopeId:s}=be(),n=je({queryKey:["archived-sessions",s,{count:fh}],queryFn:()=>t.listSessions({archived_only:!0,page_size:fh}),staleTime:15e3,retry:!1});return n.data===void 0||n.data.has_more?{known:!1,count:0}:{known:!0,count:n.data.items.length}}function Y$(){const{t,tp:s}=D(),n=Et(),a=V$(),i=a.known&&a.count===0,r=a.known?i?t("st.sessions.archive.none"):s("st.sessions.archive.count",a.count):t("st.sessions.archivedRow");return e.jsx(Me,{id:"st-card-archived",title:t("st.sessions.card.archive"),children:e.jsxs(Ze,{children:[e.jsx("div",{"data-settings-archive-row":a.known?String(a.count):"unknown",children:e.jsx(ge,{label:r,help:i?void 0:t("st.sessions.archivedRowHint"),children:i?null:e.jsx("button",{type:"button","data-settings-open-archived":!0,className:uy,onClick:()=>{n("/archived")},children:t("st.sessions.archive.view")})})}),e.jsx(W$,{})]})})}function J$(){return e.jsxs("div",{className:"space-y-6","data-sessions-page":!0,children:[e.jsx(A$,{}),e.jsx(Q$,{}),e.jsx(H$,{}),e.jsx(oy,{}),e.jsx(Y$,{})]})}function Z$(){const{t}=D();return e.jsxs("div",{className:"space-y-6","data-engine-parameters":!0,children:[e.jsx("p",{className:"max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:t("st.dev.engineParams.intro")}),e.jsxs("section",{className:"space-y-6","data-engine-group":"sessions","aria-label":t("st.section.sessions"),children:[e.jsx("h2",{className:"text-[12px] font-medium text-ink-faint",children:t("st.section.sessions")}),e.jsx(ly,{}),e.jsx(T$,{}),e.jsx(C$,{}),e.jsx(G$,{})]}),e.jsxs("section",{className:"space-y-6","data-engine-group":"agents","aria-label":t("st.section.agents"),children:[e.jsx("h2",{className:"text-[12px] font-medium text-ink-faint",children:t("st.section.agents")}),e.jsx(T2,{}),e.jsx(H2,{}),e.jsx(w$,{})]})]})}function si(t){return Array.isArray(t)?{shape:"legacy",rules:t}:{shape:"v2",config:t}}function py(t){return t.shape==="legacy"?[...t.rules]:t.config}function X$(t){return si(Jn(t))}function bh(t){return JSON.stringify(py(t),null,2)}function fr(t,s,n,a){return t.flatMap(i=>{if(i.code==="invalid_union"&&i.path[0]==="action"&&(a==="inject"||a==="observe"||a==="compact")){const o=a==="inject"?0:a==="observe"?1:2;return fr(i.errors[o]??[],[...s,"action"],n)}return(i.code==="unrecognized_keys"?i.keys.map(o=>[...i.path,o]):[i.path]).map(o=>({path:[...s,...o].join("."),message:i.message,ref:n,field:o.toReversed().find(c=>typeof c=="string")??(n===null?String(s[0]??"hooks"):"rule")}))})}function eR(t){const s=[],n=t.shape==="legacy"?t.rules:t.config.legacy;if(Array.isArray(n)&&n.forEach((a,i)=>{const r=uw.safeParse(a);r.success||s.push(...fr(r.error.issues,t.shape==="legacy"?[i]:["legacy",i],{kind:"legacy",index:i}))}),t.shape==="v2"){const a=t.config,i=pw.safeParse({...a,rules:Array.isArray(a.rules)?[]:a.rules,legacy:Array.isArray(a.legacy)?[]:a.legacy});i.success||s.push(...fr(i.error.issues,[],null)),Array.isArray(a.rules)&&a.rules.forEach((r,o)=>{const l=nb.safeParse(r);l.success||s.push(...fr(l.error.issues,["rules",o],{kind:"declarative",id:r.id},r.action?.type))})}return s}function tR(t){return mw(py(t))}function my(t){return t.shape==="legacy"?t.rules:t.config.legacy}function xy(t,s){return t.shape==="legacy"?{...t,rules:s}:{...t,config:{...t.config,legacy:s}}}function sR(t,s,n){return xy(t,my(t).map((a,i)=>i===s?{...a,...n}:a))}function gh(t,s){return xy(t,my(t).filter((n,a)=>a!==s))}function dn(t){if(t.shape!=="v2")throw new Error("not a v2 draft");return t.config}function nR(t){let s=1;for(;t.includes(`rule-${s}`);)s++;return{...nb.parse({id:`rule-${s}`,event:"prompt.submit",action:{type:"inject",text:"draft"}}),action:{type:"inject",text:""}}}function vh(t){const s=dn(t),n=nR(s.rules.map(a=>a.id));return{draft:{shape:"v2",config:{...s,rules:[...s.rules,n]}},ref:{kind:"declarative",id:n.id}}}function aR(t,s,n){const a=dn(t);return{shape:"v2",config:{...a,rules:a.rules.map(i=>i.id===s?{...i,...n}:i)}}}function iR(t,s,n){const a=dn(t);return{shape:"v2",config:{...a,rules:a.rules.map((i,r)=>r===s?{...i,...n}:i)}}}function rR(t,s){const n=dn(t),a=n.rules[s];return{shape:"v2",config:{...n,rules:n.rules.filter((i,r)=>r!==s),disabled:a===void 0?n.disabled:n.disabled.filter(i=>i!==a.id)}}}function yh(t){return t.shape==="v2"?t:{shape:"v2",config:{schemaVersion:2,enabled:!0,disabled:[],files:[],rules:[],legacy:[...t.rules]}}}function hy(t){return t.shape==="v2"&&t.config.rules.length===0&&t.config.files.length===0&&t.config.disabled.length===0}function oR(t){if(!hy(t))throw new Error("cannot flatten draft with declarative rules, files or disabled ids to legacy");return{shape:"legacy",rules:dn(t).legacy}}function lR(t,s){return{shape:"v2",config:{...dn(t),enabled:s}}}function cR(t,s){return{shape:"v2",config:{...dn(t),files:[...s]}}}function dR(t,s){return{shape:"v2",config:{...dn(t),disabled:[...s]}}}function Wl(t){return t.join(`
|
|
243
|
+
`)}function Vl(t){return[...new Set(t.split(/\r?\n/).map(s=>s.trim()).filter(s=>s!==""))]}function kh(t){if(t===void 0)return"";const s=[];for(const[n,a]of Object.entries(t)){const i=Array.isArray(a)?a:[a];for(const r of i)s.push(`${n} = ${r}`)}return s.join(`
|
|
244
|
+
`)}function uR(t){const s=new Map;for(const a of t.split(/\r?\n/)){const i=a.trim();if(i==="")continue;const r=i.indexOf("="),o=(r<0?i:i.slice(0,r)).trim(),l=r<0?"":i.slice(r+1).trim();if(o==="")continue;const c=s.get(o)??[];c.includes(l)||c.push(l),s.set(o,c)}if(s.size===0)return;const n={};for(const[a,i]of s.entries())n[a]=i.length===1?i[0]:i;return n}const Yl=new Set(["step.before","step.after"]),jh=new Set(["prompt.submit","step.before"]),nd=new Set(["tool.before","tool.after"]),fy=["models","profiles","routes","executors","tools","channels","originKinds"],wh=["promptMatches","promptNotMatches"],Nh=["toolInputMatches","toolInputNotMatches"],ad={agentRoles:["root","subagent"],statuses:["success","error","cancelled","denied"],sources:["user","task","mailbox","steering"],outcomes:["completed","cancelled","failed","blocked"]};function pR(t,s,n){return fy.filter(a=>(s[a]?.length??0)>0||n.some(i=>i.field===a)?!0:a==="tools"?nd.has(t):a==="channels"||a==="originKinds"?t==="prompt.submit":!0)}function mR(t,s,n){return Object.keys(ad).filter(a=>(s[a]?.length??0)>0||n.some(i=>i.field===a)?!0:a==="statuses"?t==="tool.after":a==="sources"?t==="prompt.submit":a==="outcomes"?t==="step.after"||t==="turn.after":!0)}function Qt(t,s){return t.find(n=>n.field===s)?.message??null}function zt({field:t,issues:s}){const n=Qt(s,t);return n===null?null:e.jsx("p",{role:"alert","data-hook-issue":t,className:"mt-1 text-[12px] leading-4 text-danger",children:n})}function xR({values:t,options:s,onChange:n,ariaLabel:a}){return e.jsx("div",{role:"group","aria-label":a,className:"inline-flex max-w-full flex-wrap items-center gap-0.5 rounded-md bg-ink/[0.04] p-0.5",children:s.map(({value:i,label:r})=>{const o=t.includes(i);return e.jsx("button",{type:"button","aria-pressed":o,onClick:()=>n(o?t.filter(l=>l!==i):[...t,i]),className:`h-7 rounded-[5px] px-3 text-[13px] transition-colors ${o?"bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"text-ink-soft hover:text-ink"}`,children:r},i)})})}function hR(t){return t.promptRegex!==void 0&&t.promptRegex!==""||(t.promptMatches?.length??0)>0||(t.promptNotMatches?.length??0)>0}function fR(t){return t.toolInputRegex!==void 0&&t.toolInputRegex!==""||(t.toolInputMatches?.length??0)>0||(t.toolInputNotMatches?.length??0)>0||t.toolArgMatches!==void 0&&Object.keys(t.toolArgMatches).length>0}function bR(t){return Object.values(t).some(s=>Array.isArray(s)||typeof s=="string"?s.length>0:typeof s=="object"&&s!==null?Object.keys(s).length>0:!1)}function gR({rule:t,issues:s,onChange:n,onRemove:a,onConvertToCommand:i}){const{t:r}=D(),o=x.useId(),l=t.action.type==="inject"?t.action:null,c=t.action.type==="compact"?t.action:null,[d,u]=x.useState(l?.text??""),[p,h]=x.useState(l?.textFile??""),[b,m]=x.useState(()=>kh(t.match.toolArgMatches)),[f,g]=x.useState(()=>bR(t.match)),v=Yl.has(t.event),y=hR(t.match),w=fR(t.match),N=xw.map(I=>{const $=l!==null&&!jh.has(I),E=c!==null&&!Yl.has(I),M=t.cadence!==void 0&&!Yl.has(I),z=y&&I!=="prompt.submit",H=w&&!nd.has(I),U=$||E||M||z||H,X=$?r("st.hooks.eventInjectOnly"):E?r("st.hooks.eventCompactOnly"):M?r("st.hooks.eventCadenceOnly"):z?r("st.hooks.eventPromptMatchOnly"):H?r("st.hooks.eventToolMatchOnly"):void 0;return{value:I,label:r(`st.hooks.v2event.${I}`),disabled:U,hint:X}}),_=I=>{if(I===t.action.type)return;if(I==="observe"){n({action:{type:"observe"}});return}const $=p!==""&&d===""?{type:"inject",textFile:p}:{type:"inject",text:d};n(jh.has(t.event)?{action:$}:{action:$,event:"prompt.submit"})},C=I=>{l!==null&&n(I==="text"?{action:{type:"inject",text:d}}:{action:{type:"inject",textFile:p}})},S=I=>{if(I){const $={everyCompletedSteps:1,counterScope:"agent",partitionBy:"model"};n(v?{cadence:$}:{cadence:$,event:"step.before"})}else n({cadence:void 0})},k=(I,$)=>{const E={...t.match};$.length===0?delete E[I]:E[I]=[...$],n({match:E})},j=(I,$)=>{const E={...t.match},M=$.trim();M===""?delete E[I]:E[I]=M,n({match:E})},T=I=>{m(I);const $={...t.match},E=uR(I);E===void 0?delete $.toolArgMatches:$.toolArgMatches=E,n({match:$})},A=t.event==="prompt.submit"||y||s.some(I=>I.field==="promptRegex"||I.field==="promptMatches"||I.field==="promptNotMatches"),P=nd.has(t.event)||w||s.some(I=>I.field==="toolInputRegex"||I.field==="toolInputMatches"||I.field==="toolInputNotMatches"||I.field==="toolArgMatches"),R=[];t.match.promptRegex&&R.push(r("st.hooks.match.promptRegex"));for(const I of wh)(t.match[I]?.length??0)>0&&R.push(r(`st.hooks.match.${I}`));t.match.toolInputRegex&&R.push(r("st.hooks.match.toolInputRegex"));for(const I of Nh)(t.match[I]?.length??0)>0&&R.push(r(`st.hooks.match.${I}`));t.match.toolArgMatches&&Object.keys(t.match.toolArgMatches).length>0&&R.push(r("st.hooks.match.toolArgMatches"));for(const I of fy)(t.match[I]?.length??0)>0&&R.push(r(`st.hooks.match.${I}`));for(const I of Object.keys(ad))(t.match[I]?.length??0)>0&&R.push(r(`st.hooks.match.${I}`));const L=c!==null?[{value:"inject",label:r("st.hooks.action.inject")},{value:"observe",label:r("st.hooks.action.observe")},{value:"compact",label:r("st.hooks.action.compact")}]:[{value:"inject",label:r("st.hooks.action.inject")},{value:"observe",label:r("st.hooks.action.observe")}];return e.jsxs("div",{className:"space-y-4","data-hook-editor":"declarative",children:[e.jsxs(Ze,{children:[e.jsxs(ge,{label:r("st.hooks.ruleId"),htmlFor:`${o}-id`,children:[e.jsx(Be,{layout:"inline",label:r("st.hooks.ruleEnabled"),checked:t.enabled,onChange:I=>n({enabled:I})}),e.jsx("input",{id:`${o}-id`,className:"w-56 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:bg-hairline/20 disabled:text-ink-faint",value:t.id,autoComplete:"off",spellCheck:!1,"aria-invalid":Qt(s,"id")!==null,onChange:I=>n({id:I.target.value})})]}),e.jsx(zt,{field:"id",issues:s}),i!==void 0?e.jsx(ge,{label:r("st.hooks.kind"),help:r("st.hooks.kind.declarativeHint"),children:e.jsx(He,{ariaLabel:r("st.hooks.kind"),dataAttr:"data-hook-kind",value:"declarative",onChange:I=>{I==="command"&&i()},choices:[{value:"declarative",label:r("st.hooks.kind.declarative")},{value:"command",label:r("st.hooks.kind.command")}]})}):null,e.jsx(ge,{label:r("st.hooks.event"),children:e.jsx(Jt,{options:N,value:t.event,ariaLabel:r("st.hooks.event"),onChange:I=>n({event:I}),hideFilter:!0,placement:"auto",buttonClassName:Sn})}),e.jsx(zt,{field:"event",issues:s}),e.jsx(ge,{label:r("st.hooks.action"),layout:"stack",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{ariaLabel:r("st.hooks.action"),dataAttr:"data-hook-action",value:t.action.type,onChange:I=>{I!=="compact"&&_(I)},choices:L}),t.action.type==="observe"?e.jsx(he,{children:r("st.hooks.observeHint")}):t.action.type==="compact"?e.jsx(he,{children:r("st.hooks.compactHint")}):e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(He,{ariaLabel:r("st.hooks.injectText"),dataAttr:"data-hook-inject-source",value:l?.textFile!==void 0?"file":"text",onChange:I=>C(I),choices:[{value:"text",label:r("st.hooks.injectSource.text")},{value:"file",label:r("st.hooks.injectSource.file")}]}),l?.textFile!==void 0?e.jsxs("div",{className:"grid gap-1",children:[e.jsx("input",{className:`${Ce} font-mono`,value:l.textFile,"aria-label":r("st.hooks.injectFile"),autoComplete:"off",spellCheck:!1,"aria-invalid":Qt(s,"textFile")!==null,onChange:I=>{h(I.target.value),n({action:{type:"inject",textFile:I.target.value}})}}),e.jsx(zt,{field:"textFile",issues:s}),e.jsx(he,{children:r("st.hooks.injectFileHint")})]}):e.jsxs("div",{className:"grid gap-1",children:[e.jsx("textarea",{className:`${Ce} min-h-24`,value:l?.text??"","aria-label":r("st.hooks.injectText"),"aria-invalid":Qt(s,"text")!==null,onChange:I=>{u(I.target.value),n({action:{type:"inject",text:I.target.value}})}}),e.jsx(zt,{field:"text",issues:s})]})]})]})}),e.jsx(ge,{label:r("st.hooks.priority"),htmlFor:`${o}-priority`,help:r("st.hooks.priorityHint"),children:e.jsx("input",{id:`${o}-priority`,type:"number",step:1,className:"w-24 rounded-lg border border-hairline bg-paper px-3 py-2 text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:bg-hairline/20 disabled:text-ink-faint",value:t.priority,"aria-invalid":Qt(s,"priority")!==null,onChange:I=>n({priority:Number(I.target.value)})})}),e.jsx(zt,{field:"priority",issues:s}),v?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:r("st.hooks.cadenceEnable"),children:e.jsx(Be,{layout:"bare",label:r("st.hooks.cadenceEnable"),checked:t.cadence!==void 0,onChange:I=>S(I)})}),t.cadence!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:r("st.hooks.cadenceEvery"),htmlFor:`${o}-cadence`,children:e.jsx("input",{id:`${o}-cadence`,type:"number",min:1,step:1,className:"w-24 rounded-lg border border-hairline bg-paper px-3 py-2 text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:bg-hairline/20 disabled:text-ink-faint",value:t.cadence.everyCompletedSteps,"aria-invalid":Qt(s,"everyCompletedSteps")!==null,onChange:I=>n({cadence:{...t.cadence,everyCompletedSteps:Number(I.target.value)}})})}),e.jsx(zt,{field:"everyCompletedSteps",issues:s}),e.jsx(ge,{label:r("st.hooks.cadenceScope"),children:e.jsx(He,{ariaLabel:r("st.hooks.cadenceScope"),dataAttr:"data-hook-cadence-scope",value:t.cadence.counterScope,onChange:I=>n({cadence:{...t.cadence,counterScope:I}}),choices:[{value:"agent",label:r("st.hooks.cadenceScope.agent")},{value:"turn",label:r("st.hooks.cadenceScope.turn")}]})}),e.jsx(zt,{field:"cadence",issues:s})]}):null]}):null]}),e.jsxs("div",{"data-hook-field":"match",children:[e.jsxs("button",{type:"button","aria-expanded":f,onClick:()=>g(!f),className:"flex min-h-7 w-full items-center justify-between gap-3 text-left focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsx("span",{className:"text-[13px] font-medium text-ink",children:r("st.hooks.matchTitle")}),e.jsx("span",{className:"min-w-0 truncate text-[12px] text-ink-faint",children:R.length===0?r("st.hooks.matchEmpty"):R.join(" · ")})]}),f?e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(he,{children:r("st.hooks.matchLine")}),A?e.jsxs(e.Fragment,{children:[t.match.promptRegex!==void 0||Qt(s,"promptRegex")!==null?e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-promptRegex`,className:$e,children:r("st.hooks.match.promptRegex")}),e.jsx("input",{id:`${o}-match-promptRegex`,className:`${Ce} font-mono`,value:t.match.promptRegex??"",autoComplete:"off",spellCheck:!1,"aria-invalid":Qt(s,"promptRegex")!==null,onChange:I=>j("promptRegex",I.target.value)}),e.jsx(zt,{field:"promptRegex",issues:s})]}):null,wh.map(I=>e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-${I}`,className:$e,children:r(`st.hooks.match.${I}`)}),e.jsx("textarea",{id:`${o}-match-${I}`,rows:2,className:`${Ce} font-mono`,value:Wl(t.match[I]??[]),"aria-invalid":Qt(s,I)!==null,onChange:$=>k(I,Vl($.target.value))}),e.jsx(zt,{field:I,issues:s})]},I))]}):null,P?e.jsxs(e.Fragment,{children:[t.match.toolInputRegex!==void 0||Qt(s,"toolInputRegex")!==null?e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-toolInputRegex`,className:$e,children:r("st.hooks.match.toolInputRegex")}),e.jsx("input",{id:`${o}-match-toolInputRegex`,className:`${Ce} font-mono`,value:t.match.toolInputRegex??"",autoComplete:"off",spellCheck:!1,"aria-invalid":Qt(s,"toolInputRegex")!==null,onChange:I=>j("toolInputRegex",I.target.value)}),e.jsx(zt,{field:"toolInputRegex",issues:s})]}):null,Nh.map(I=>e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-${I}`,className:$e,children:r(`st.hooks.match.${I}`)}),e.jsx("textarea",{id:`${o}-match-${I}`,rows:2,className:`${Ce} font-mono`,value:Wl(t.match[I]??[]),"aria-invalid":Qt(s,I)!==null,onChange:$=>k(I,Vl($.target.value))}),e.jsx(zt,{field:I,issues:s})]},I)),e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-toolArgMatches`,className:$e,children:r("st.hooks.match.toolArgMatches")}),e.jsx("textarea",{id:`${o}-match-toolArgMatches`,rows:2,className:`${Ce} font-mono`,value:b,placeholder:"run_in_background = true","aria-invalid":Qt(s,"toolArgMatches")!==null,onChange:I=>T(I.target.value),onBlur:()=>m(kh(t.match.toolArgMatches))}),e.jsx(zt,{field:"toolArgMatches",issues:s})]})]}):null,pR(t.event,t.match,s).map(I=>e.jsxs("div",{className:"grid gap-1",children:[e.jsx("label",{htmlFor:`${o}-match-${I}`,className:$e,children:r(`st.hooks.match.${I}`)}),e.jsx("textarea",{id:`${o}-match-${I}`,rows:2,className:`${Ce} font-mono`,value:Wl(t.match[I]??[]),"aria-invalid":Qt(s,I)!==null,onChange:$=>k(I,Vl($.target.value))}),e.jsx(zt,{field:I,issues:s})]},I)),mR(t.event,t.match,s).map(I=>e.jsxs("div",{className:"grid gap-1",children:[e.jsx("span",{className:$e,children:r(`st.hooks.match.${I}`)}),e.jsx(xR,{values:t.match[I]??[],options:ad[I].map($=>({value:$,label:r(`st.hooks.matchValue.${$}`)})),ariaLabel:r(`st.hooks.match.${I}`),onChange:$=>k(I,$)}),e.jsx(zt,{field:I,issues:s})]},I))]}):null]}),e.jsx("div",{children:e.jsx("button",{type:"button",className:Ht,"aria-label":r("st.hooks.removeRule",{rule:t.id}),onClick:a,children:r("st.hooks.remove")})})]})}function ar(t,s){return t.find(n=>n.field===s)?.message??null}function vR({rule:t,ruleLabel:s,issues:n,onChange:a,onRemove:i,onConvertToDeclarative:r}){const{t:o}=D(),l=x.useId(),c=ar(n,"command"),d=ar(n,"event"),u=ar(n,"matcher"),p=ar(n,"timeout");return e.jsxs("div",{className:"space-y-3","data-hook-editor":"legacy",children:[e.jsxs(Ze,{children:[r!==void 0?e.jsx(ge,{label:o("st.hooks.kind"),help:o("st.hooks.kind.commandHint"),children:e.jsx(He,{ariaLabel:o("st.hooks.kind"),dataAttr:"data-hook-kind",value:"command",onChange:h=>{h==="declarative"&&r()},choices:[{value:"declarative",label:o("st.hooks.kind.declarative")},{value:"command",label:o("st.hooks.kind.command")}]})}):null,e.jsxs(ge,{label:o("st.hooks.event"),children:[e.jsx(Qe,{variant:"form",dataAttr:"data-hook-event",ariaLabel:o("st.hooks.event"),value:t.event,onChange:h=>a({event:h}),choices:Jf.map(h=>({value:h,label:o(`st.hooks.event.${h}`)}))}),d!==null?e.jsx("p",{role:"alert","data-hook-issue":"event",className:"mt-1 text-[12px] leading-4 text-danger",children:d}):null]}),e.jsxs(ge,{label:o("st.hooks.command"),layout:"stack",help:c!==null?void 0:o("st.hooks.commandHint"),children:[e.jsx("textarea",{id:`${l}-command`,className:`${Ce} min-h-16 font-mono`,value:t.command,"aria-invalid":c!==null,onChange:h=>a({command:h.target.value})}),c!==null?e.jsx("p",{role:"alert","data-hook-issue":"command",className:"mt-1 text-[12px] leading-4 text-danger",children:c}):null]}),e.jsxs(ge,{label:o("st.hooks.matcher"),htmlFor:`${l}-matcher`,help:o("st.hooks.matchHint"),children:[e.jsx("input",{id:`${l}-matcher`,className:Ce,value:t.matcher??"","aria-invalid":u!==null,onChange:h=>a({matcher:h.target.value===""?void 0:h.target.value})}),u!==null?e.jsx("p",{role:"alert","data-hook-issue":"matcher",className:"mt-1 text-[12px] leading-4 text-danger",children:u}):null]}),e.jsxs(ge,{label:o("st.hooks.timeout"),htmlFor:`${l}-timeout`,children:[e.jsx("input",{id:`${l}-timeout`,type:"number",min:1,max:600,step:1,placeholder:"30",className:"w-24 rounded-lg border border-hairline bg-paper px-3 py-2 text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:bg-hairline/20 disabled:text-ink-faint",value:t.timeout??"","aria-invalid":p!==null,onChange:h=>a({timeout:h.target.value===""?void 0:Number(h.target.value)})}),p!==null?e.jsx("p",{role:"alert","data-hook-issue":"timeout",className:"mt-1 text-[12px] leading-4 text-danger",children:p}):null]})]}),e.jsx("div",{children:e.jsx("button",{type:"button",className:Ht,"aria-label":o("st.hooks.removeRule",{rule:s}),onClick:i,children:o("st.hooks.remove")})})]})}function Sh({items:t,onChange:s,addLabel:n,placeholder:a,dataAttr:i}){const{t:r}=D(),[o,l]=x.useState(""),c=()=>{const d=o.trim();d===""||t.includes(d)||(s([...t,d]),l(""))};return e.jsxs("div",{className:"space-y-1.5",...i!==void 0?{[i]:""}:{},children:[t.length>0?e.jsx("ul",{className:"divide-y divide-hairline",children:t.map(d=>e.jsxs("li",{className:"flex items-center gap-2 py-1",children:[e.jsx("span",{className:"min-w-0 flex-1 break-all font-mono text-[12px] text-ink",children:d}),e.jsx("button",{type:"button","aria-label":`${r("common.remove")} ${d}`,onClick:()=>s(t.filter(u=>u!==d)),className:"inline-flex min-h-7 shrink-0 items-center text-[12px] text-ink-faint transition-colors hover:text-danger focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:r("common.remove")})]},d))}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:`${Ce} font-mono`,value:o,"aria-label":n,placeholder:a,autoComplete:"off",spellCheck:!1,onChange:d=>l(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!rt(d)&&(d.preventDefault(),c())}}),e.jsx("button",{type:"button",className:`${Q} shrink-0`,disabled:o.trim()===""||t.includes(o.trim()),onClick:c,children:n})]})]})}function ni(t,s){return t===null?!1:t.kind==="declarative"&&s.kind==="declarative"?t.id===s.id:t.kind==="legacy"&&s.kind==="legacy"&&t.index===s.index}function Ch(t){return t.kind==="declarative"?`declarative:${t.id}`:`legacy:${t.index}`}function _h(t,s){return t.filter(n=>n.ref!==null&&ni(n.ref,s))}function yR(t,s){const n=s(by(t)),a=t.declarative!==void 0?s(`st.hooks.action.${t.declarative.action.type}`):s("st.hooks.kind.command");return`${n} · ${a}`}function by(t){return t.declarative!==void 0?`st.hooks.v2event.${t.event}`:`st.hooks.event.${t.event}`}const ir=["session.start","SessionStart","SessionEnd","prompt.submit","UserPromptSubmit","UserPromptQueued","TurnStarted","turn.after","turn.stopping","Stop","StopFailure","Interrupt","step.before","step.after","tool.before","PreToolUse","tool.after","PostToolUse","PostToolUseFailure","PermissionRequest","PermissionResult","SubagentStart","SubagentStop","TaskStarted","PreCompact","PostCompact","SessionHeartbeat","Notification"];function kR(t,s){const n=t.shape==="v2"?t.config.rules.map((i,r)=>({ref:{kind:"declarative",id:i.id},rowKey:s[r]??`declarative-idx:${r}`,declarativeIndex:r,event:i.event,declarative:i})):[],a=(t.shape==="legacy"?t.rules:t.config.legacy).map((i,r)=>({ref:{kind:"legacy",index:r},rowKey:`legacy:${r}`,event:i.event,legacy:i}));return[...n,...a]}function jR(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(""),[c,d]=x.useState("form"),[u,p]=x.useState(null),[h,b]=x.useState(null),m=x.useRef(1),f=x.useRef([]),[g,v]=x.useState("list"),[y,w]=x.useState([]),[N,_]=x.useState(!1),[C,S]=x.useState(!1),[k,j]=x.useState(null),[T,A]=Je(),{ask:P,busy:R}=ug(),L=pg(),I=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),$=i?.shape==="v2"?i.config.rules.length:0;for(;f.current.length<$;)f.current.push(`decl-${m.current++}`);f.current.length>$&&(f.current.length=$);const E=[...f.current],M=x.useMemo(()=>i===null?[]:kR(i,E),[i,E.join(",")]);x.useEffect(()=>{if(I.data===void 0||N)return;const te=JSON.stringify(I.data.hooks??[],null,2);l(te);try{r(si(Jn(te)))}catch{r(null),d("json")}},[I.data,N]);const z=te=>{r(te),_(!0),w([]),j(null)},H=(te,ee)=>{if(p(te),te===null)b(null);else if(ee!==void 0)b(ee);else if(te.kind==="declarative"&&i?.shape==="v2"){const K=i.config.rules.findIndex(Z=>Z.id===te.id);b(K>=0?f.current[K]??null:null)}else b(Ch(te));v(te===null?"list":"detail")};x.useEffect(()=>{i===null||M.length===0||h!==null&&M.some(te=>te.rowKey===h)||u!==null&&M.some(te=>ni(te.ref,u))||(p(M[0].ref),b(M[0].rowKey))},[i,M,u,h]);const U=()=>{if(i===null)return;const te=vh(i.shape==="v2"?i:yh(i)),ee=`decl-${m.current++}`;f.current=[...f.current,ee],z(te.draft),H(te.ref,ee)},X=te=>{if(i===null||i.shape!=="v2"||i.config.rules[te]===void 0)return;const K={event:"PreToolUse",command:""},Z=i.config,ue=Z.legacy.length;f.current=f.current.filter((Te,Ne)=>Ne!==te),z({shape:"v2",config:{...Z,rules:Z.rules.filter((Te,Ne)=>Ne!==te),legacy:[...Z.legacy,K]}}),H({kind:"legacy",index:ue},`legacy:${ue}`)},q=te=>{if(i===null)return;const ee=i.shape==="v2"?i:yh(i);if((i.shape==="legacy"?i.rules:i.config.legacy)[te]===void 0)return;const ue=vh(ee),Te=`decl-${m.current++}`;f.current=[...f.current,Te],z(gh(ue.draft,te)),H(ue.ref,Te)},F=(te,ee)=>{if(i!==null){if(te.kind==="declarative"){const K=ee??(i.shape==="v2"?i.config.rules.findIndex(Z=>Z.id===te.id):-1);if(K<0)return;f.current=f.current.filter((Z,ue)=>ue!==K),z(rR(i,K)),b(null);return}z(gh(i,te.index)),b(null)}},V=()=>{try{const te=JSON.parse(o);l(JSON.stringify(te,null,2)),j(null)}catch(te){j({tone:"error",text:oe(n,te)})}},se=()=>{const te=JSON.stringify(I.data?.hooks??[],null,2);l(te);try{r(si(Jn(te)))}catch{r(null)}H(null),_(!1),j(null),w([])},Y=()=>{if(c==="form"){i!==null&&l(bh(i)),d("json"),j(null);return}try{r(X$(o)),d("form"),w([]),j(null)}catch(te){j({tone:"error",text:oe(n,te)})}},O=async()=>{let te;if(c==="json")try{te={hooks:Jn(o)}}catch(ee){j({tone:"error",text:oe(n,ee)});return}else{if(i===null)return;const ee=eR(i);if(ee.length>0){const K=ee[0];w(ee),K.ref!==null&&H(K.ref),j({tone:"error",text:s("st.hooks.configInvalid",{field:K.path,message:K.message})});return}try{te=tR(i)}catch(K){j({tone:"error",text:oe(n,K)});return}}S(!0),j(null);try{const ee=await t.patchConfig(te);a.setQueryData(["config"],ee);const K=si(Jn(JSON.stringify(ee.hooks??[])));r(K),l(bh(K)),_(!1),w([]),A()}catch(ee){j({tone:"error",text:oe(n,ee)})}finally{S(!1)}},B=()=>{const te=JSON.stringify(I.data?.hooks??[],null,2);l(te);try{r(si(Jn(te))),d("form")}catch{r(null),d("json")}p(null),b(null),w([]),_(!1),j(null)},le=i===null?[]:i.shape==="legacy"?i.rules:i.config.legacy,re=M.length===0,ae=te=>i===null||i.shape!=="v2"?!1:i.config.rules.find(K=>K.id===te)?.enabled===!1||!i.config.enabled||i.config.disabled.includes("*")||i.config.disabled.includes(`user/${te}`),ne=(te,ee,K)=>{const Z=te.declarative!==void 0?te.declarative.id:te.legacy!==void 0?te.legacy.command.trim()===""?s("st.hooks.commandEmpty"):te.legacy.command:"";return e.jsxs("li",{className:"flex min-w-0 items-center gap-2 pr-1",children:[e.jsxs("button",{type:"button","data-hooks-rule":Ch(te.ref),"aria-current":(h!==null?h===te.rowKey:ni(u,te.ref))?"true":void 0,onClick:()=>H(te.ref,te.rowKey),className:`flex min-w-0 flex-1 flex-col items-start gap-0.5 rounded-md py-1.5 pr-1 pl-3 text-left transition-colors focus-visible:outline-2 focus-visible:outline-selected-ink ${(h!==null?h===te.rowKey:ni(u,te.ref))?"bg-ink/[0.06]":"hover:bg-ink/[0.04]"}`,children:[e.jsxs("span",{className:"flex max-w-full items-center gap-1.5",children:[K?e.jsx("span",{className:"shrink-0 text-[11px] text-danger",role:"img","aria-label":s("st.hooks.rowIssue"),children:"●"}):null,e.jsx("span",{className:`truncate text-[13px] ${te.legacy!==void 0?"font-mono text-[12px]":""} text-ink`,children:Z}),ee?e.jsx("span",{className:"shrink-0 rounded-sm bg-ink/[0.06] px-1 text-[10.5px] leading-4 text-ink-faint",children:s("st.hooks.ruleDisabled")}):null]}),e.jsx("span",{className:"max-w-full truncate text-[11px] text-ink-faint",children:yR(te,s)})]}),te.declarative!==void 0&&i!==null&&i.shape==="v2"?e.jsx("span",{className:"shrink-0","data-hooks-row-switch":te.declarative.id,children:e.jsx(Be,{layout:"bare",label:s("st.hooks.ruleRowToggle",{id:te.declarative.id}),checked:te.declarative.enabled,onChange:ue=>z(aR(i,te.declarative.id,{enabled:ue}))})}):null]},te.rowKey)},Ee=[];{const te=[...M].sort((ee,K)=>{const Z=ir.indexOf(ee.event),ue=ir.indexOf(K.event);return(Z===-1?ir.length:Z)-(ue===-1?ir.length:ue)});for(const ee of te){const K=s(by(ee)),Z=Ee.find(ue=>ue.key===K);Z!==void 0?Z.items.push(ee):Ee.push({key:K,items:[ee]})}}const ie=Ee.length>1,me=e.jsx("nav",{"aria-label":s("st.hooks.title"),className:"space-y-3",children:Ee.map(te=>e.jsxs("section",{"aria-label":ie?te.key:s("st.hooks.title"),children:[ie?e.jsx("p",{className:"flex h-8 items-center px-1 text-[12px] font-medium text-section-ink",children:te.key}):null,e.jsx("ul",{className:"space-y-0.5",children:te.items.map(ee=>ne(ee,ee.declarative!==void 0&&ae(ee.declarative.id),y.some(K=>K.ref!==null&&ni(K.ref,ee.ref))))})]},te.key))}),fe=(()=>{if(i===null||u===null)return re?null:e.jsx(he,{children:s("st.hooks.selectRule")});if(u.kind==="declarative"){const ee=i.shape==="v2"?(()=>{const ue=h===null?-1:E.indexOf(h);return ue>=0?ue:i.config.rules.findIndex(Te=>Te.id===u.id)})():-1,K=i.shape==="v2"&&ee>=0?i.config.rules[ee]:void 0;if(K===void 0)return e.jsx(he,{children:s("st.hooks.selectRule")});const Z=E[ee]??`declarative-idx:${ee}`;return e.jsx(gR,{rule:K,issues:_h(y,{kind:"declarative",id:K.id}),onChange:ue=>{i.shape==="v2"&&(z(iR(i,ee,ue)),ue.id!==void 0&&ue.id!==K.id&&(p({kind:"declarative",id:ue.id}),b(Z)))},onRemove:()=>F({kind:"declarative",id:K.id},ee),onConvertToCommand:()=>X(ee)},Z)}const te=le[u.index];return te===void 0?e.jsx(he,{children:s("st.hooks.selectRule")}):e.jsx(vR,{rule:te,ruleLabel:String(u.index+1),issues:_h(y,u),onChange:ee=>z(sR(i,u.index,ee)),onRemove:()=>F(u),onConvertToDeclarative:()=>q(u.index)},u.index)})(),Ie=e.jsx(mg,{label:s("st.hooks.askKiki"),labelAria:s("st.hooks.askKikiAria"),busy:R,disabled:!L.resolved,testId:"data-hooks-ask-kiki",onAsk:()=>{P({skill:"kiki-hooks",promptKey:"st.hooks.askKiki.prompt",location:L.location})}});return e.jsx(Me,{id:"st-card-hooks",title:s("st.hooks.title"),actions:c==="form"&&!re?e.jsxs(e.Fragment,{children:[Ie,e.jsx("button",{type:"button",className:Q,"data-hooks-add":!0,disabled:C||I.data===void 0,onClick:U,children:s("st.hooks.addRule")})]}):void 0,children:e.jsxs("div",{className:"space-y-3",children:[I.isLoading?e.jsx(he,{children:s("st.runtime.loading")}):null,I.isError?e.jsx(De,{error:I.error}):null,e.jsxs("fieldset",{disabled:C||I.data===void 0,className:"min-w-0 space-y-3",children:[c==="json"?e.jsx("textarea",{className:`${Ce} min-h-64 font-mono`,value:o,"aria-label":s("st.hooks.aria"),spellCheck:!1,onChange:te=>{l(te.target.value),_(!0),j(null)}}):e.jsxs(e.Fragment,{children:[re?e.jsxs("div",{className:"space-y-2.5 py-2","data-hooks-empty":!0,children:[e.jsx(he,{children:s("st.hooks.empty")}),e.jsx(he,{children:s("st.hooks.emptyBody")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,"data-hooks-add":!0,disabled:C||I.data===void 0,onClick:U,children:s("st.hooks.addRule")}),Ie]})]}):e.jsx(vo,{narrowPane:g,list:me,detail:fe===null?null:e.jsxs("div",{className:"space-y-4",children:[e.jsx("button",{type:"button",className:`${Q} md:hidden`,onClick:()=>v("list"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"arrowLeft",size:12}),s("st.hooks.title")]})}),fe]})}),c==="form"?e.jsxs("details",{"data-hooks-sources":!0,open:i!==null&&i.shape==="v2"&&(i.config.files.length>0||i.config.disabled.length>0)?!0:void 0,className:"group pt-3",children:[e.jsxs("summary",{className:"inline-flex min-h-7 cursor-pointer select-none items-center gap-1 text-[12px] font-medium text-ink-soft hover:text-ink pointer-coarse:min-h-11",children:[e.jsx(de,{name:"chevron",size:12,className:"text-ink-faint transition-transform group-open:rotate-90 motion-reduce:transition-none"}),s("st.advanced.disclosure")]}),e.jsxs("div",{className:"mt-2 space-y-3",children:[i!==null&&i.shape==="v2"?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:s("st.hooks.v2Enabled"),help:s("st.hooks.v2EnabledHint"),children:e.jsx(Be,{id:"hooks-v2-enabled",layout:"bare",label:s("st.hooks.v2Enabled"),checked:i.config.enabled,onChange:te=>z(lR(i,te))})}),e.jsx(is,{title:s("st.hooks.filesTitle"),help:s("st.hooks.filesHint"),children:e.jsx(Sh,{items:i.config.files,onChange:te=>z(cR(i,te)),addLabel:s("st.hooks.filesAdd"),placeholder:"hooks/extra.toml",dataAttr:"data-hooks-files"})}),e.jsx(is,{title:s("st.hooks.disabledTitle"),help:s("st.hooks.disabledHint"),children:e.jsx(Sh,{items:i.config.disabled,onChange:te=>z(dR(i,te)),addLabel:s("st.hooks.disabledAdd"),placeholder:"user/focus",dataAttr:"data-hooks-disabled"})}),hy(i)&&i.config.legacy.length>0?e.jsx("button",{type:"button","data-hooks-flatten-legacy":!0,onClick:()=>z(oR(i)),className:"inline-flex min-h-7 items-center text-[12px] font-medium text-selected-ink hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:s("st.hooks.flatten")}):null]}):null,e.jsx("div",{children:e.jsx("button",{type:"button","data-hooks-json-toggle":!0,onClick:Y,className:"inline-flex min-h-7 items-center text-[12px] font-medium text-selected-ink hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:s("st.hooks.advanced")})})]})]}):null]}),c==="json"?e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",className:Q,"data-hooks-format-json":!0,onClick:V,children:s("st.hooks.formatJson")}),e.jsx("button",{type:"button",className:Q,"data-hooks-reset-json":!0,onClick:se,disabled:!N&&o===JSON.stringify(I.data?.hooks??[],null,2),children:s("st.hooks.resetJson")}),e.jsx("button",{type:"button","data-hooks-json-toggle":!0,onClick:Y,className:"ml-auto inline-flex min-h-7 items-center text-[12px] font-medium text-selected-ink hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:s("st.hooks.form")})]}):null,e.jsx(lt,{saved:T,id:"hooks",dirty:N,saving:C,saveLabel:s("st.hooks.save"),onSave:()=>void O(),onDiscard:B})]}),e.jsx(pe,{feedback:k})]})})}const wR=50;function NR(){const{client:t}=be();return je({queryKey:["sessions","restart-confirm"],queryFn:()=>t.listSessions({page_size:wR}),staleTime:1e4,select:n=>n.busy_count??(n.has_more?void 0:n.items.filter(a=>a.busy).length)}).data}function Eh(){const t=Tt(),{search:s}=Bt();return x.useEffect(()=>{new URLSearchParams(s).get("tab")==="external"&&t("/settings/connection-services#st-card-conn-external",{replace:!0})},[s,t]),e.jsx("div",{className:"space-y-4",children:e.jsx(SR,{})})}function SR(){const t=mt(),{config:s,meta:n,wsStatus:a,socket:i,scopeId:r,sshLabel:o,connectionId:l,spaceKey:c,localClient:d,connectionSource:u,activateLocal:p,disconnect:h,applyConnection:b}=be(),{t:m,locale:f}=D(),g=Oe(),v=Db({includeLocalMachine:!0}),y=t.kind==="tauri",w=r.startsWith("ssh:"),N=(typeof l=="string"&&l!==""?l:null)??ka(Aa()?.homeId??"")??(typeof c=="string"?ka(c):null),_=N!==null,C=xo(_?d??null:null),S=_?(C.data??[]).find(Ke=>Ke.id===N):void 0,k=u==="app-shell",j=Lp(),T=j?null:hw(),[A,P]=x.useState(!1),[R,L]=x.useState(!1),[I,$]=x.useState(null),[E,M]=x.useState(null),[z,H]=x.useState(!1),[U,X]=x.useState(!1),[q,F]=x.useState(!1),V=NR(),Y=x.useSyncExternalStore(xg,Or,Or).filter(Ke=>Ke.kind==="close").length,[O,B]=x.useState(()=>gc().requestTimeoutSeconds),[le,re]=Je(),[ae,ne]=x.useState(()=>gc().readingTimeoutSeconds),[Ee,ie]=Je(),[me,fe]=x.useState(s.url),[Ie,te]=x.useState(null),[ee,K]=x.useState(Dt);x.useEffect(()=>{fe(s.url),te(null),K(Dt),F(!1)},[s.url,s.token]);const Z=k?"":s.token.trim(),ue=ee.mode==="set"?ee.value.trim():ee.mode==="clear"?"":Z,Te=k?ee.mode==="set"&&ue!==""||ee.mode==="clear":ue!==s.token.trim(),Ne=me.trim()!==s.url.trim()||Te,J=!w&&!_&&!k&&!j&&!y;Ft("connection-endpoint",Ne&&J);const _e=()=>{if(!Ne)return;const Ke=me.trim();if(!fw(Ke)){te(m("st.conn.urlInvalid"));return}if(te(null),F(!1),k&&ee.mode!=="set"){b({url:Ke,token:""});return}b({url:Ke,token:ue})},we=()=>{fe(s.url),te(null),K(Dt),F(!1)},G=x.useCallback(async()=>s.token,[s.token]),Le=Ke=>{Mt({requestTimeoutSeconds:Ke}),B(Ke),re()},Se=Ke=>{const We=vw(Ke===""?Number.NaN:Number(Ke));return We===null?null:qs(f,We)},Fe=async()=>{if(!w){P(!0),M(null);try{await t.restartServer?.(),gw(),i?.nudge(),await g.invalidateQueries(),M({tone:"success",text:m("st.conn.restarted")})}catch(Ke){M({tone:"error",text:oe(f,Ke)})}finally{P(!1)}}},ye=async()=>{if(!(N===null||d===null)){L(!0),$(null);try{await Kd(d).retry(N),await g.invalidateQueries({queryKey:fo.all})}catch(Ke){const We=ga(Ke instanceof Error?Ke.message:"");$({tone:"error",text:We===null?oe(f,Ke):m(We)})}finally{L(!1)}}},ze=a==="open"?"bg-success":a==="connecting"?"bg-amber-ink status-dot-busy":"bg-danger",Pe=a==="open"?"text-success":a==="connecting"?"text-amber-ink":"text-danger",xe=v.localMachineName,ke=y?xe!==void 0?m("st.conn.hopThisComputerSuffix",{computer:xe}):m("st.conn.hopThisComputerOnly"):xe??m("st.conn.hopServerFallback"),W=m("st.conn.hopArrow",{from:m("st.conn.hopThisDevice"),to:ke}),Re=xe??m(y?"st.conn.hopThisComputerOnly":"st.conn.hopServerFallback"),Ae=m("st.conn.hopArrow",{from:Re,to:v.spaceName}),Ue=S===void 0?void 0:ho(S.endpoint),Ge=S?.lastConnectedAt===void 0?void 0:Nn(new Date(S.lastConnectedAt).toISOString(),f);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Me,{id:"st-card-conn-server",title:m("st.conn.connectedTitle"),children:[w?e.jsxs("div",{className:"space-y-1.5 text-[12.5px] text-ink",children:[e.jsxs("p",{className:"font-medium",children:[m("connect.remoteScope")," · ",o]}),e.jsx("p",{className:"text-ink-soft",children:m("connect.sshRemoteSettings")}),e.jsx("button",{type:"button",onClick:p,className:`${Q} mt-1`,children:m("connect.switchLocal")})]}):null,e.jsxs(Ze,{children:[q?null:e.jsx("div",{"data-conn-segment":"local",className:"contents",children:e.jsxs(ge,{label:e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"font-medium text-ink","data-conn-hop-heading":"local",children:W}),e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-[12px]","data-conn-ws-status":a,children:[e.jsx("span",{"aria-hidden":!0,className:`inline-block h-2 w-2 shrink-0 rounded-full ${ze}`}),e.jsx("span",{className:`font-medium ${Pe}`,children:m(`st.conn.ws.${a}`)}),e.jsx("span",{className:"break-all font-mono text-ink-soft","data-conn-url":!0,children:s.url.trim()||(typeof window<"u"?window.location.origin:"")})]})]}),help:e.jsxs("span",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5",children:[e.jsxs("span",{children:[m("st.conn.version")," ",e.jsx("span",{className:"font-mono",children:n.server_version})]}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsxs("span",{children:[m("st.conn.backend")," ",e.jsx("span",{className:"font-mono",children:n.backend??"v1"})]}),e.jsx("span",{"aria-hidden":!0,children:"·"}),Y>0?e.jsx("a",{href:"#st-card-conn-log","data-conn-drops-link":!0,onClick:Ke=>{Ke.preventDefault(),document.getElementById("st-card-conn-log")?.scrollIntoView({behavior:"smooth",block:"start"})},className:"underline decoration-hairline underline-offset-2 hover:text-ink",children:m("st.conn.dropsSinceStart",{closes:Y})}):e.jsx("span",{children:m("st.conn.dropsSinceStart",{closes:0})}),J&&s.token.trim()===""?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{"data-conn-no-token":!0,children:m("st.conn.noToken")})]}):null]}),children:[e.jsx("button",{type:"button","data-conn-reconnect":!0,onClick:()=>{i?.nudge()},className:a!=="open"?Ye:Q,children:m("st.conn.reconnect")}),J?e.jsx("button",{type:"button","data-conn-edit":!0,onClick:()=>{F(!0)},className:Q,children:m("st.secret.edit")}):null,T!==null?e.jsx("a",{href:T,"data-conn-app-shell":!0,className:Q,children:m("connect.switchComputer")}):null]})}),J&&q?e.jsxs("form",{className:"space-y-4",onSubmit:Ke=>{Ke.preventDefault(),_e()},children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"st-conn-url",className:"block text-[13px] font-medium text-ink",children:m("connect.serverUrl")}),e.jsx("input",{id:"st-conn-url",className:`${Ce} font-mono`,value:me,"aria-invalid":Ie!==null||void 0,onChange:Ke=>{fe(Ke.target.value),Ie!==null&&te(null)},spellCheck:!1}),Ie!==null?e.jsx("p",{role:"alert","data-conn-url-error":!0,className:"text-[12px] text-danger",children:Ie}):null]}),e.jsx(Dn,{id:"st-conn-token",label:m("connect.token"),source:s.token===""||k?"none":"kiki",sourceText:m("st.conn.tokenHint"),clearable:!1,draft:ee,onChange:K,reveal:s.token===""||k?void 0:G}),e.jsx(lt,{id:"connection-endpoint",dirty:Ne,persistent:!0,saveLabel:m("st.conn.apply"),onSave:_e,onDiscard:we,extra:Ne?void 0:e.jsx("button",{type:"button","data-conn-edit-cancel":!0,className:Q,onClick:we,children:m("common.cancel")})}),Ne?e.jsx(he,{children:m("st.conn.applyHint")}):null]}):null,_?e.jsx("div",{"data-conn-segment":"remote",className:"contents",children:e.jsx(ge,{label:e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"font-medium text-ink","data-conn-hop-heading":"remote",children:Ae}),e.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-[12px]",children:[S!==void 0?e.jsx(Md,{state:S.state}):null,Ue!==void 0?e.jsx("span",{className:"break-all font-mono text-ink-soft","data-conn-remote-url":!0,children:Ue}):null]})]}),help:Ge!==void 0||I!==null?e.jsxs("span",{className:"flex flex-col gap-1",children:[Ge!==void 0?e.jsx("span",{"data-conn-remote-last-connected":!0,children:m("st.remote.lastConnected",{time:Ge})}):null,I!==null?e.jsx("span",{className:"text-danger",children:I.text}):null]}):void 0,children:e.jsx("button",{type:"button","data-conn-remote-retry":!0,disabled:R||d===null,onClick:()=>{ye()},className:Q,children:m("st.remote.retry")})})}):null,e.jsxs("div",{id:"st-card-conn-timeout",className:"contents",children:[e.jsxs(ge,{label:m("st.conn.timeoutLabel"),htmlFor:"st-conn-request-timeout",help:m("st.conn.timeoutRowHelp"),children:[e.jsx(jt,{show:le}),e.jsx(kt,{id:"st-conn-request-timeout",className:"w-24 text-right",inputMode:"numeric",value:String(O),validate:Se,onCommit:Ke=>{Le(Number(Ke))}}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:m("st.conn.timeoutUnit")})]}),e.jsxs(ge,{label:m("st.conn.readingTimeoutLabel"),htmlFor:"st-conn-reading-timeout",help:m("st.conn.readingTimeoutRowHelp"),children:[e.jsx(jt,{show:Ee}),e.jsx(kt,{id:"st-conn-reading-timeout",className:"w-24 text-right",inputMode:"numeric",value:String(ae),validate:Ke=>{const We=bw(Ke===""?Number.NaN:Number(Ke));return We===null?null:qs(f,We)},onCommit:Ke=>{const We=Number(Ke);Mt({readingTimeoutSeconds:We}),ne(We),ie()}}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:m("st.conn.timeoutUnit")})]})]}),e.jsx("div",{id:"st-card-conn-disconnect",className:"contents",children:e.jsx(ge,{label:m("sidebar.disconnect"),help:m(w?"connect.sshDisconnectBody":"st.conn.disconnectBody"),children:e.jsx("button",{type:"button","data-conn-disconnect":!0,className:Ht,onClick:()=>{if(w){X(!0);return}const Ke={url:s.url,token:s.token};h(),xs({text:m("st.conn.disconnectedUndo"),undoFailedText:m("toast.undoFailed"),undo:()=>{b(Ke)}})},children:m("sidebar.disconnect")})})})]})]}),e.jsx(CR,{}),!w&&(Lp()||n_())?e.jsx(_R,{}):null,!w&&y&&t.restartServer!==void 0?e.jsxs(Me,{id:"st-card-conn-owned",title:m("st.conn.ownedTitle"),children:[e.jsx(Ze,{children:e.jsx(ge,{label:m("st.conn.restart"),help:V!==void 0&&V>0?m("st.conn.busySessions",{count:V}):m("st.conn.ownedBody"),children:e.jsx("button",{type:"button","data-conn-restart":!0,className:Q,disabled:A,onClick:()=>{H(!0)},children:m(A?"st.conn.restarting":"st.conn.restart")})})}),e.jsx(pe,{feedback:E})]}):null,e.jsx(Xe,{open:U,overlayId:"confirm-conn-disconnect",title:m("st.conn.disconnectConfirmTitle"),body:m("connect.sshDisconnectBody"),confirmLabel:m("connect.switchLocal"),tone:"danger",onConfirm:()=>{X(!1),h()},onCancel:()=>{X(!1)}}),e.jsx(Xe,{open:z&&!w,overlayId:"confirm-conn-restart",title:m("st.restart.confirmTitle"),body:V!==void 0&&V>0?m("st.restart.confirmBodyActive",{count:V}):m("st.restart.confirmBodyIdle"),confirmLabel:m("st.conn.restart"),tone:"danger",onConfirm:()=>{H(!1),Fe()},onCancel:()=>{H(!1)}})]})}function CR(){const{t}=D(),s=x.useSyncExternalStore(xg,Or,Or),[n,a]=x.useState(null),i=s.filter(l=>l.kind==="close").length,r=s.filter(l=>l.kind==="timer_gap").length,o=async()=>{try{await rs(t_(s)),a({tone:"success",text:t("st.conn.logCopied")})}catch(l){a({tone:"error",text:t("st.conn.logCopyFailed",{reason:l instanceof Error?l.message:String(l)})})}};return e.jsx(Me,{id:"st-card-conn-log",title:t("st.conn.logTitle"),scope:"app",aside:t("st.conn.logBody"),children:e.jsxs("div",{"data-conn-log":!0,children:[e.jsx(Ze,{children:e.jsx(ge,{label:i===0?t("st.conn.logEmpty"):t("st.conn.logSummary",{closes:i,gaps:r,total:s.length}),children:e.jsx("button",{type:"button",className:Q,"data-conn-log-copy":!0,disabled:s.length===0,onClick:()=>{o()},children:t("st.conn.logCopy")})})}),e.jsx(pe,{feedback:n})]})})}function _R(){const{t}=D(),[s,n]=x.useState(null),[a,i]=x.useState(null),r=x.useCallback(async()=>{const c=await dl.capabilities();c!==null&&n(c)},[]);x.useEffect(()=>{r();const c=a_(u=>{u.type==="permissions"&&(i(null),n(p=>p===null?{permissions:{accessibility:u.permissions.accessibility===!0,overlay:u.permissions.overlay===!0,notifications:u.permissions.notifications??!0,battery:u.permissions.battery===!0,oemAutostart:u.permissions.oemAutostart}}:{...p,permissions:{...p.permissions,...u.permissions}}))}),d=()=>{document.visibilityState==="visible"&&r()};return document.addEventListener("visibilitychange",d),()=>{c(),document.removeEventListener("visibilitychange",d)}},[r]);const o=async c=>{i(null);try{await c()}catch(d){i({tone:"error",text:d instanceof Error?d.message:String(d)})}},l=[{id:"accessibility",label:t("st.conn.androidAccessibility"),ready:s?.permissions.accessibility===!0,permission:"accessibility"},{id:"overlay",label:t("st.conn.androidOverlay"),ready:s?.permissions.overlay===!0,permission:"overlay"},{id:"battery",label:t("st.conn.androidBattery"),ready:s?.permissions.battery===!0,permission:"battery"}];return e.jsx(Me,{id:"st-card-conn-android",title:t("st.conn.androidTitle"),scope:"app",actions:e.jsx("button",{type:"button",className:Q,"data-android-open-settings":!0,onClick:()=>{o(()=>dl.openPhoneSettings())},children:t("st.conn.androidMore")}),children:e.jsxs("div",{"data-android-permissions":!0,children:[e.jsx(Ze,{children:l.map(c=>e.jsx(ge,{label:c.label,children:c.ready?e.jsxs("span",{"data-android-perm-ready":c.id,className:"inline-flex items-center gap-1.5 text-[12px] text-ink-faint",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-success"}),t("st.conn.androidOn")]}):e.jsx("button",{type:"button",className:Q,"data-android-perm-enable":c.id,onClick:()=>{o(()=>dl.openPermission(c.permission))},children:t("st.conn.androidEnable")})},c.id))}),e.jsx(pe,{feedback:a})]})})}function ER(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState("{}"),[o,l]=x.useState(!1),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=Je(),m=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),f=y=>JSON.stringify({permission:y.permission??{},loop_control:y.loop_control??{},background:y.background??{}},null,2);x.useEffect(()=>{const y=m.data;y===void 0||o||r(f(y))},[m.data,o]);const g=()=>{m.data!==void 0&&r(f(m.data)),l(!1),p(null)},v=async()=>{let y;try{y=yw(i)}catch(w){p({tone:"error",text:oe(n,w)});return}d(!0),p(null);try{const w=await t.patchConfig(y);a.setQueryData(["config"],w),r(f(w)),l(!1),b()}catch(w){p({tone:"error",text:oe(n,w)})}finally{d(!1)}};return e.jsx(Me,{id:"st-card-advanced",title:s("st.advanced.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:s("st.advanced.hint")}),e.jsxs("details",{"data-advanced-json":!0,open:o?!0:void 0,className:"group",children:[e.jsxs("summary",{className:"inline-flex min-h-7 cursor-pointer select-none items-center gap-1 text-[12px] font-medium text-ink-soft hover:text-ink pointer-coarse:min-h-11",children:[e.jsx(de,{name:"chevron",size:12,className:"text-ink-faint transition-transform group-open:rotate-90 motion-reduce:transition-none"}),s("st.advanced.disclosure")]}),e.jsxs("div",{className:"mt-2 space-y-3",children:[e.jsx("textarea",{className:`${Ce} min-h-64 font-mono`,value:i,onChange:y=>{r(y.target.value),l(!0),p(null)},"aria-label":s("st.advanced.aria")}),e.jsx(lt,{saved:h,id:"advanced-json",dirty:o,saving:c,saveLabel:s("st.advanced.save"),onSave:()=>void v(),onDiscard:g})]})]}),e.jsx(pe,{feedback:u})]})})}const TR={now:"st.exp.effect.now",newSessions:"st.exp.effect.newSessions",restart:"st.exp.effect.restart"};function Du(t=!0){const{client:s}=be(),n=je({queryKey:["config"],queryFn:()=>s.getConfig(),staleTime:6e4,enabled:t}),a=je({queryKey:["meta"],queryFn:()=>s.meta(),staleTime:15e3,enabled:t});return{rows:KN(a.data??{},n.data??{}),effective:a.data?.experimental_flags??{},loading:t&&(n.isLoading||a.isLoading),error:n.error??a.error,ready:n.data!==void 0&&a.data!==void 0}}function gy({id:t,override:s,effective:n}){const{client:a}=be(),{t:i,locale:r}=D(),o=Oe(),[l,c]=x.useState(!1),[d,u]=x.useState(null),[p,h]=Je(),[b,m]=x.useState(null),f=Cd(t),g=i(f?.labelKey??"st.exp.unknown.name"),y=b??(s===void 0?"default":s?"on":"off"),w=b===null&&s!==void 0&&n!==void 0&&n!==s,N=async _=>{m(_),c(!0),u(null);try{const C=await a.getConfig(),S={...C.experimental};_==="default"?delete S[t]:S[t]=_==="on";const k=await a.patchConfig({experimental:S,replace_domains:["experimental"]});o.setQueryData(["config"],cn(C,k)),await o.invalidateQueries({queryKey:["meta"]});const j=o.getQueryData(["meta"]);f?.effect==="restart"&&(_==="on"||_==="default"&&j?.experimental_flags?.[t]===!0)&&tb([t]),h()}catch(C){u(oe(r,C))}finally{m(null),c(!1)}};return e.jsx(ge,{label:g,labelId:`experimental-flag-${t}-label`,help:e.jsxs(e.Fragment,{children:[i(f?.descriptionKey??"st.exp.unknown.desc")," ",e.jsx("span",{"data-experimental-effect":f?.effect??"now",children:i(TR[f?.effect??"now"])})]}),children:e.jsxs("span",{className:"flex shrink-0 flex-wrap items-center gap-2",title:i("st.exp.flagId",{id:t}),children:[e.jsx("span",{"data-experimental-tag":!0,className:"rounded-[4px] bg-ink/[0.05] px-1.5 py-px text-[11px] font-medium leading-4 text-ink-soft",children:i("st.exp.tag")}),e.jsx(jt,{show:p}),e.jsx(He,{ariaLabel:i("st.exp.choiceLabel",{feature:g}),value:y,disabled:l,dataAttr:"data-experimental-choice",onChange:_=>void N(_),choices:[{value:"default",label:i(s===void 0&&n!==void 0?n?"st.exp.choice.defaultOn":"st.exp.choice.defaultOff":"st.exp.choice.default")},{value:"on",label:i("st.exp.choice.on")},{value:"off",label:i("st.exp.choice.off")}]}),w?e.jsx("span",{className:"basis-full text-right text-[12px] leading-snug text-amber-ink","data-experimental-env":!0,children:i("st.exp.envOverride")}):null,d!==null?e.jsx("span",{role:"alert",className:"basis-full text-right text-[12px] leading-snug text-danger",children:d}):null]})})}function IR({section:t}){const{t:s}=D(),{rows:n,effective:a,loading:i,error:r}=Du(),o=n.filter(d=>Sd(d.id)===t&&Cd(d.id)?.cardId===void 0);if(r!=null)return e.jsx(Me,{id:Sr(t),title:s("st.exp.rowsTitle"),children:e.jsx(De,{error:r})});if(i||o.length===0)return null;const l=d=>{const u=Cr.findIndex(p=>p.id===d);return u===-1?Cr.length:u},c=o.toSorted((d,u)=>l(d.id)-l(u.id)||d.id.localeCompare(u.id));return e.jsx(Me,{id:Sr(t),title:s("st.exp.rowsTitle"),children:e.jsx(Ze,{"data-experimental-rows":t,children:c.map(d=>e.jsx("div",{"data-experimental-row":d.id,children:e.jsx(gy,{id:d.id,override:d.override,effective:a[d.id]})},d.id))})})}function vy(){const{t}=D(),{search:s}=Bt(),{rows:n,loading:a,error:i}=Du(),r=ab(t),o=(()=>{const d=new URLSearchParams(s);d.delete("tab");const u=d.toString();return u===""?"":`?${u}`})(),l=d=>{const u=Cr.findIndex(p=>p.id===d);return u===-1?Cr.length:u},c=n.toSorted((d,u)=>l(d.id)-l(u.id)||d.id.localeCompare(u.id));return e.jsxs(Me,{id:"st-card-labs",title:t("st.labs.indexTitle"),children:[a?e.jsx(he,{children:t("st.runtime.loading")}):null,i!=null?e.jsx(De,{error:i}):null,!a&&c.length===0&&i==null?e.jsx(he,{children:t("st.labs.empty")}):null,e.jsx("ul",{className:"divide-y divide-hairline","data-labs-index":!0,children:c.map(d=>{const u=Cd(d.id),p=Sd(d.id),h=u?.cardId??Sr(p),b=r[p]??p;return e.jsxs("li",{"data-labs-entry":d.id,className:"flex min-h-9 items-center gap-x-4 py-1 first:pt-0 last:pb-0",children:[u===void 0?e.jsx("p",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink","data-labs-unknown":!0,children:d.id}):e.jsxs("p",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",title:d.id,children:[t(u.labelKey),e.jsx("span",{className:"ml-2 hidden font-mono text-[11px] text-ink-faint sm:inline",children:d.id})]}),e.jsx(_t,{to:`/settings/${p}${o}#${h}`,"data-labs-link":p,"aria-label":t("st.labs.openIn",{page:b}),className:"inline-flex min-h-8 shrink-0 items-center rounded-md px-1 text-[13px] font-medium text-selected-ink hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:b})]},d.id)})})]})}function Th(){return e.jsxs(e.Fragment,{children:[e.jsx(K$,{}),e.jsx(ER,{}),e.jsx(vy,{})]})}const yy=x.createContext(()=>{}),ky=x.createContext(()=>{});function Gn(t){return t===null?"null":t===void 0?"":String(t)}function Ih(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(""),[o,l]=x.useState(""),[c,d]=x.useState(!1),[u,p]=x.useState(!1),[h,b]=x.useState(null),[m,f]=Je(),g=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4});x.useEffect(()=>{const y=g.data;y===void 0||c||(r(Gn(y.mcp?.startupTimeoutMs)),l(Gn(y.mcp?.toolTimeoutMs)))},[g.data,c]);const v=async()=>{let y;try{y=kw(i,o)}catch(w){b({tone:"error",text:oe(n,w)});return}p(!0),b(null);try{const w=await t.patchConfig(y);a.setQueryData(["config"],w),r(Gn(w.mcp?.startupTimeoutMs)),l(Gn(w.mcp?.toolTimeoutMs)),d(!1),await a.invalidateQueries({queryKey:["mcp-servers"]}),f()}catch(w){b({tone:"error",text:oe(n,w)})}finally{p(!1)}};return e.jsx(Me,{id:"st-card-mcp-timeouts",title:s("st.mcp.timeoutsTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:s("st.mcp.timeoutsHint")}),e.jsxs("fieldset",{disabled:u,className:"grid gap-3 sm:grid-cols-2 disabled:opacity-60",children:[e.jsx(ui,{label:s("st.runtime.mcpStartupTimeout"),value:i,hint:s("st.mcp.startupTimeoutHint"),detail:s("st.mcp.startupTimeoutDetail"),onChange:y=>{r(y),d(!0)}}),e.jsx(ui,{label:s("st.runtime.mcpToolTimeout"),value:o,hint:s("st.mcp.toolTimeoutHint"),detail:s("st.mcp.toolTimeoutDetail"),onChange:y=>{l(y),d(!0)}})]}),e.jsx(lt,{saved:m,id:"mcp-timeouts",dirty:c,saving:u,onSave:()=>void v(),onDiscard:()=>{r(Gn(g.data?.mcp?.startupTimeoutMs)),l(Gn(g.data?.mcp?.toolTimeoutMs)),d(!1),b(null)}}),g.isError?e.jsx(De,{error:g.error}):null,e.jsx(pe,{feedback:h})]})})}function jy(){const{t}=D(),[s]=no(),n=s.get("workspace")??"";return n!==""?e.jsxs("div",{className:"space-y-6",children:[e.jsx(AR,{workspaceId:n}),e.jsx(Ih,{})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(Me,{id:"st-card-mcp",title:t("st.mcp.title"),children:e.jsx(PR,{})}),e.jsx(Ih,{})]})}function PR(){const{client:t,klient:s}=be(),{t:n,locale:a}=D(),i=Oe(),[r,o]=x.useState(null),l=je({queryKey:["mcp-managed-servers",""],queryFn:()=>s.global.mcp.list({}),staleTime:6e4}),c=je({queryKey:["mcp-servers"],queryFn:()=>t.listMcpServers(),staleTime:15e3,refetchInterval:h=>h.state.data?.servers.some(b=>b.status==="connecting")===!0?2e3:!1}),d=je({queryKey:["tools","global"],queryFn:()=>t.listTools(),staleTime:3e4,retry:!1}),u=new Map;for(const h of d.data?.tools??[]){if(h.source!=="mcp"||h.mcp_server_id===void 0)continue;const b=u.get(h.mcp_server_id)??[];b.push(_b(h.name)),u.set(h.mcp_server_id,b)}const p=async h=>{o(null);try{await t.restartMcpServer(h),o({tone:"success",text:n("st.mcp.restartRequested")}),await i.invalidateQueries({queryKey:["mcp-servers"]})}catch(b){o({tone:"error",text:oe(a,b)})}};return e.jsxs("div",{"data-mcp-global":!0,children:[e.jsx(Vb,{cwd:"",entries:l.data??[],loading:l.isLoading,error:l.error,onEcho:h=>{i.setQueryData(["mcp-managed-servers",""],h)},runtime:{servers:c.data?.servers??[],toolsByServer:u,onRestart:p}}),e.jsx(pe,{feedback:r})]})}function AR({workspaceId:t}){const{t:s}=D(),{client:n,klient:a}=be(),i=Oe(),r=x.useContext(yy),o=je({queryKey:["workspaces","catalog"],queryFn:()=>n.listWorkspaceCatalog(),staleTime:3e4}),l=o.data?.items.find(d=>d.id===t),c=je({queryKey:["mcp-managed-servers",l?.root??""],queryFn:()=>a.global.mcp.list({cwd:l.root}),enabled:l!==void 0,staleTime:6e4});return x.useEffect(()=>(r(l?.name??null),()=>{r(null)}),[r,l?.name]),o.isPending?e.jsxs("p",{role:"status","data-mcp-workspace-loading":!0,className:"flex items-center gap-2 text-[13px] text-ink-faint",children:[e.jsx(Us,{label:s("cap.loading")}),s("cap.loading")]}):o.isError?e.jsxs("div",{className:"space-y-2","data-mcp-workspace-error":!0,children:[e.jsx(De,{error:o.error}),e.jsx("button",{type:"button",className:"min-h-8 rounded-md bg-ink/[0.06] px-3 text-[13px] text-ink hover:bg-ink/[0.1]",onClick:()=>{o.refetch()},children:s("common.retry")})]}):l===void 0?e.jsxs("div",{className:"space-y-3 py-2","data-mcp-workspace-missing":!0,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-[18px] leading-6 text-ink",children:s("st.workspaces.detail.missingTitle")}),e.jsx("p",{className:"mt-1 max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:s("st.workspaces.detail.missingBody")})]}),e.jsx(_t,{to:_d(),className:"inline-flex min-h-8 items-center rounded-md px-3 text-[13px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink","data-mcp-workspace-back":!0,children:s("st.workspaces.title")})]}):e.jsxs(Me,{id:"st-card-mcp",title:s("st.mcp.title"),scope:"workspace",children:[e.jsx("p",{className:"min-w-0 truncate text-[12.5px] leading-5 text-ink-soft","data-mcp-workspace-name":!0,children:l.name}),e.jsx("p",{className:"min-w-0 truncate font-mono text-[12px] text-ink-faint","data-mcp-workspace-root":!0,title:l.root,children:l.root}),e.jsx("div",{className:"mt-3",children:e.jsx(Vb,{cwd:l.root,entries:c.data??[],loading:c.isLoading,error:c.error,onEcho:d=>{i.setQueryData(["mcp-managed-servers",l.root],d)}})})]})}function $R(){const{t}=D(),s=Tt(),n=Bt(),{workspace:a}=Yb(),[i,r]=x.useState({view:"installed"}),o=l=>{if(n.pathname.startsWith("/settings/extensions")){const c=new URLSearchParams(n.search);c.set("plugin",l),s(`/settings/extensions?${c.toString()}`);return}s(An(l))};return e.jsx(Me,{id:"st-card-plugins",title:t("st.plugins.installedTitle"),children:e.jsx(HS,{route:i,onRoute:r,workspaceRoot:a?.root,sessionId:ib()??void 0,onOpenSettings:o,onOpenPanel:(l,c)=>{s(`/capabilities?plugin=${encodeURIComponent(l)}&panel=${encodeURIComponent(`${l}:${c}`)}`)},onOpenImportHistory:({source:l,sourcePlugin:c})=>{s(`${Nd()}?source=${encodeURIComponent(l)}&sourcePlugin=${encodeURIComponent(c)}`)},inSettings:!0})})}function id({pluginId:t}){const s=Bt(),n=Tt();if(t===null)return e.jsx($R,{});const a=s.pathname.startsWith("/settings/extensions")?()=>{const i=new URLSearchParams(s.search);i.delete("plugin");const r=i.toString();n(r===""?"/settings/extensions":`/settings/extensions?${r}`)}:void 0;return e.jsx(zS,{pluginId:t,onBack:a})}function wy(){const{t}=D(),s=Tt(),{workspaces:n,workspaceId:a,setWorkspaceId:i,query:r}=Yb();return e.jsx(Me,{id:"st-card-caps",title:t("st.skills.catalogTitle"),actions:n.length>0?e.jsx(GS,{id:"settings-skills-workspace",workspaces:n,value:a,onChange:i}):void 0,children:r.isPending?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status","data-capability-workspaces-loading":!0,children:t("cap.loadingWorkspaces")}):r.isError?e.jsxs("div",{className:"space-y-3","data-capability-workspaces-error":!0,children:[e.jsx("p",{className:"text-[13px] text-danger",role:"alert",children:t("cap.workspacesFailed")}),e.jsx("button",{type:"button",onClick:()=>{r.refetch()},disabled:r.isFetching,className:"min-h-8 rounded-md bg-ink/[0.06] px-3 text-[13px] text-ink hover:bg-ink/[0.1] disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-selected-ink",children:t("common.retry")})]}):e.jsx(QS,{workspaceId:a,inSettings:!0,onOpenPlugin:o=>{s(`/settings/extensions?plugin=${encodeURIComponent(o)}`)}})})}function RR({pluginId:t}){const{t:s}=D(),n=Tt(),{search:a}=Bt(),i=new URLSearchParams(a).get("tab"),r=Nw(i)??rb;if(t!==null)return e.jsx(id,{pluginId:t});const o=l=>{if(l===r)return;const c=new URLSearchParams(a);c.set("tab",l),c.delete("plugin"),n(`/settings/extensions?${c.toString()}`)};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{role:"tablist","aria-label":s("st.section.extensions"),className:"flex flex-wrap gap-1 border-b border-hairline",children:jw.map(l=>{const c=l===r;return e.jsx("button",{type:"button",role:"tab","aria-selected":c,"data-extensions-tab":l,onClick:()=>{o(l)},className:`-mb-px min-h-9 border-b-2 px-3 py-1.5 text-[13px] transition-colors ${c?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:s(ww(l))},l)})}),e.jsx("div",{className:"[&_#st-card-plugins>div:first-child]:sr-only [&_#st-card-caps>div:first-child>h2]:sr-only",children:r==="skills"?e.jsx(wy,{}):r==="mcp"?e.jsx(jy,{}):e.jsx(id,{pluginId:null})})]})}function LR({slot:t}){const{t:s,locale:n}=D(),a=tm(t.title,n),i=t.subtitle===void 0?void 0:tm(t.subtitle,n),r=`st-card-plugin-slot-${t.pluginId}-${t.id}`;return e.jsx(Me,{id:r,title:a,aside:i,actions:e.jsxs(_t,{to:An(t.pluginId),"data-plugin-settings-slot-link":`${t.pluginId}:${t.id}`,className:WS,children:[s("pluginSlot.openSettings"),e.jsx(de,{name:"arrowRight",size:14})]})})}function MR({slots:t,workspaceId:s}){const n=UN({workspaceId:s}),a=HN(t??n.slots);return a.length===0?null:e.jsx(e.Fragment,{children:a.map(i=>e.jsx(LR,{slot:i},`${i.pluginId}:${i.id}`))})}const Ph=["external-clients"],Ah=["external-clients","authorizations"],OR=["external-clients","sessions"],Mo=x.createContext([]),DR={active:"st.xc.statusActive",paused:"st.xc.statusPaused",revoked:"st.xc.statusRevoked"},Ny=["workspace","global"],FR=["current","connection","workspace"];function Jl(t,s){return t.includes(s)?t.filter(n=>n!==s):[...t,s]}function Sy({value:t,label:s,wrap:n=!1}){const{t:a}=D(),[i,r]=x.useState(!1);return e.jsxs("div",{"data-xc-copy":!0,className:"flex min-w-0 max-w-full items-center gap-1 rounded-md border border-hairline bg-paper pl-2",children:[e.jsx("code",{className:`min-w-0 font-mono text-[11.5px] text-ink ${n?"break-all py-1.5 leading-4":"truncate py-1.5"}`,title:t,children:t}),e.jsx("button",{type:"button","data-xc-copy-button":!0,"aria-label":s,onClick:()=>{rs(t).then(()=>{r(!0),setTimeout(()=>{r(!1)},1500)})},className:"inline-flex h-8 min-w-8 shrink-0 items-center justify-center rounded-r-md px-1.5 text-[11.5px] text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink",children:i?a("st.xc.localCopied"):e.jsx(de,{name:"notes",size:12})})]})}function Wn({label:t,children:s,fact:n}){return e.jsxs("div",{"data-xc-fact":n,className:"grid min-w-0 gap-x-4 gap-y-0.5 sm:grid-cols-[9rem_minmax(0,1fr)]",children:[e.jsx("dt",{className:"text-[12px] text-ink-faint",children:t}),e.jsx("dd",{className:"min-w-0 text-[12.5px] leading-5 text-ink",children:s})]})}function Oo({label:t,hint:s,htmlFor:n,children:a}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-[12px] text-ink-soft",htmlFor:n,children:t}),a,s!==void 0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:s}):null]})}function Zl({label:t,children:s}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"block text-[12px] text-ink-soft",children:t}),s]})}function Cy(t){return t.length===va.length&&va.every(s=>t.includes(s))}function pi(t){if(t===void 0)return{name:"",mode:"manual",tools:va,toolPreset:"default",allowCommands:!1,memoryScopes:["workspace"],historyScope:"current"};const s=[...t.tools];return{name:t.name,mode:t.mode,tools:s,toolPreset:Cy(s)?"default":"custom",allowCommands:t.allowCommands,memoryScopes:t.memoryScopes.filter(n=>Ny.includes(n)),historyScope:t.historyScope}}function rd(t,s){const n={},a=t.name.trim();(s===void 0||a!==s.name)&&(n.name=a),(s===void 0||t.mode!==s.mode)&&(n.mode=t.mode),t.allowCommands!==(s?.allowCommands??!1)&&(n.allowCommands=t.allowCommands),(s===void 0||t.historyScope!==s.historyScope)&&(n.historyScope=t.historyScope);const i=t.toolPreset==="default"?va:[...t.tools];return(s===void 0||!Yr([...i].toSorted(),[...s.tools].toSorted()))&&(n.tools=[...i]),(s===void 0||!Yr([...t.memoryScopes].toSorted(),[...s.memoryScopes].toSorted()))&&(n.memoryScopes=[...t.memoryScopes]),n}const qR=["workspace","mode","allowCommands","historyScope"];function Yr(t,s){return t.length===s.length&&t.every(n=>s.includes(n))}function BR(t,s){return s.enabled===!1&&t.status==="active"||s.enabled===!0&&t.status==="paused"?"pause":qR.some(a=>s[a]!==void 0&&s[a]!==t[a])||s.tools!==void 0&&!Yr([...s.tools].toSorted(),[...t.tools].toSorted())||s.memoryScopes!==void 0&&!Yr([...s.memoryScopes].toSorted(),[...t.memoryScopes].toSorted())?"access":"none"}function Fu(t,s){return!t.allowCommands&&t.toolPreset==="custom"&&s.some(n=>n.tools.some(a=>a.requiresCommands&&t.tools.includes(a.name)))}function _y({draft:t,onChange:s,disabled:n,idPrefix:a}){const{t:i}=D(),r=x.useContext(Mo),o=t.toolPreset==="custom";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Zl,{label:i("st.xc.mode"),children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:VN.map(l=>{const c=t.mode===l.id;return e.jsx("button",{type:"button","data-xc-mode":l.id,disabled:n,"aria-pressed":c,title:i(l.hintKey),onClick:()=>{s({...t,mode:l.id})},className:`min-h-7 rounded-md border px-2.5 text-[12px] transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${c?"border-hairline-strong bg-paper font-medium text-ink":"border-hairline text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:i(l.labelKey)},l.id)})}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:i("st.xc.modeHint")})]}),e.jsxs(Zl,{label:i("st.xc.tools"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button","data-xc-tools":"default",disabled:n,"aria-pressed":t.toolPreset==="default",onClick:()=>{s({...t,toolPreset:"default",tools:va})},className:`min-h-7 rounded-md border px-2.5 text-[12px] transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${t.toolPreset==="default"?"border-hairline-strong bg-paper font-medium text-ink":"border-hairline text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:i("st.xc.toolsAll")}),e.jsx("button",{type:"button","data-xc-tools":"custom",disabled:n,"aria-pressed":o,onClick:()=>{s({...t,toolPreset:"custom"})},className:`min-h-7 rounded-md border px-2.5 text-[12px] transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${o?"border-hairline-strong bg-paper font-medium text-ink":"border-hairline text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:i("st.xc.toolsCustom")})]}),o?e.jsxs("div",{"data-xc-tool-list":!0,className:"space-y-1 pt-1",children:[va.map(l=>e.jsxs("label",{className:"flex min-h-7 cursor-pointer items-center gap-2 text-[12.5px] text-ink",children:[e.jsx("input",{type:"checkbox","data-xc-tool":l,checked:t.tools.includes(l),disabled:n,onChange:()=>{s({...t,tools:Jl(t.tools,l)})},className:"h-3.5 w-3.5 cursor-pointer accent-[var(--color-ink)]"}),e.jsx("span",{className:"font-mono text-[11.5px]",children:l})]},l)),r.map(l=>e.jsxs("fieldset",{"data-xc-plugin":l.pluginId,className:"min-w-0 space-y-1 border-t border-hairline pt-2 mt-2",children:[e.jsx("legend",{className:"px-1 text-[12px] font-medium text-ink-soft",children:l.displayName}),l.tools.map(c=>e.jsxs("label",{className:"flex min-h-7 cursor-pointer items-start gap-2 py-1 text-[12.5px] text-ink",children:[e.jsx("input",{type:"checkbox","data-xc-tool":c.name,checked:t.tools.includes(c.name),disabled:n,onChange:()=>{s({...t,tools:Jl(t.tools,c.name)})},className:"mt-0.5 h-3.5 w-3.5 shrink-0 cursor-pointer accent-[var(--color-ink)]"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"break-all font-mono text-[11.5px]",children:c.name}),c.requiresCommands?e.jsx("span",{className:`block text-[12px] leading-4 ${t.allowCommands?"text-ink-faint":"text-amber-ink"}`,children:i("st.xc.pluginCommandsRequired")}):null]})]},c.name))]},l.pluginId)),t.tools.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:i("st.xc.toolsNone")}):null]}):null,e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:i("st.xc.toolsHint")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Be,{id:`${a}-commands`,layout:"row",disabled:n,checked:t.allowCommands,onChange:l=>{s({...t,allowCommands:l})},label:i("st.xc.commands")}),e.jsx("p",{"data-xc-commands-hint":!0,className:`text-[12px] leading-4 ${t.allowCommands?"text-amber-ink":"text-ink-faint"}`,children:i("st.xc.commandsHint")}),Fu(t,r)?e.jsxs("div",{"data-xc-commands-required":!0,role:"alert",className:"space-y-2 border-l-2 border-amber-rule py-1 pl-3",children:[e.jsx("p",{className:"text-[12px] leading-4 text-amber-ink",children:i("st.xc.pluginCommandsBlocked")}),e.jsx("button",{type:"button","data-xc-enable-commands":!0,className:Q,disabled:n,onClick:()=>{s({...t,allowCommands:!0})},children:i("st.xc.enableCommands")})]}):null]}),e.jsxs(Zl,{label:i("st.xc.memory"),children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:Ny.map(l=>e.jsxs("label",{className:"flex min-h-7 cursor-pointer items-center gap-2 text-[12.5px] text-ink",children:[e.jsx("input",{type:"checkbox","data-xc-memory":l,disabled:n,checked:t.memoryScopes.includes(l),onChange:()=>{s({...t,memoryScopes:Jl(t.memoryScopes,l)})},className:"h-3.5 w-3.5 cursor-pointer accent-[var(--color-ink)]"}),e.jsx("span",{children:i(`st.xc.memory.${l}`)})]},l))}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:i("st.xc.memoryHint")})]}),e.jsx(Oo,{label:i("st.xc.history"),hint:i("st.xc.historyHint"),htmlFor:`${a}-history`,children:e.jsx(Qe,{id:`${a}-history`,variant:"form",className:"sm:w-auto sm:min-w-[16rem]",ariaLabel:i("st.xc.history"),triggerData:{"data-xc-history":""},value:t.historyScope,disabled:n,onChange:l=>{s({...t,historyScope:l})},choices:FR.map(l=>({value:l,label:i(`st.xc.history.${l}`)}))})})]})}function KR({connectionId:t,api:s}){const{t:n,locale:a}=D(),i=je({queryKey:["external-clients","stdio",t],queryFn:()=>s.stdio(t),staleTime:6e4,retry:!1}),r=i.data===void 0?void 0:[i.data.command,...i.data.args].join(" ");return e.jsxs("div",{"data-xc-local":!0,className:"space-y-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:n("st.xc.localTitle")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:n("st.xc.localHint")}),r!==void 0?e.jsxs("div",{className:"space-y-1.5","data-xc-local-config":!0,children:[e.jsx("p",{className:"text-[12px] text-ink-faint",children:n("st.xc.localConfig")}),e.jsx(Sy,{value:r,label:n("st.xc.localCopy"),wrap:!0}),e.jsxs("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:[n("st.xc.localConfigHint")," ",n("st.xc.localFits")," ",e.jsx("span",{className:"text-ink-soft",children:n("st.xc.localToolNote")})]})]}):null,i.isLoading?e.jsx(he,{children:n("st.xc.loading")}):null,i.isError?e.jsx("p",{"data-xc-local-error":!0,className:"text-[12px] leading-4 text-danger",children:n("st.xc.error.stdio",{reason:oe(a,i.error)})}):null]})}function UR({listener:t}){const{t:s}=D(),n=t?.mcpUrl??t?.publicUrl;return e.jsxs("div",{"data-xc-remote":!0,className:"space-y-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:s("st.xc.remoteTitle")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:s("st.xc.remoteHint")}),n!==void 0&&n!==""?e.jsxs("div",{className:"space-y-1.5","data-xc-remote-url":!0,children:[e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.xc.remoteUrl")}),e.jsx(Sy,{value:n,label:s("st.xc.remoteCopy"),wrap:!0}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:s("st.xc.localFits")})]}):e.jsx("p",{"data-xc-remote-missing":!0,className:"text-[12px] leading-4 text-ink-faint",children:s("st.xc.remoteUrlMissing")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:s("st.xc.remoteAddServer")}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("a",{"data-xc-remote-help":!0,href:"https://developers.openai.com/api/docs/guides/custom-mcp-server",target:"_blank",rel:"noreferrer noopener",className:"inline-flex min-h-7 items-center gap-1 text-[12px] font-medium text-selected-ink underline-offset-2 hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink",children:[s("st.xc.remoteHelp"),e.jsx(de,{name:"arrowUpRight",size:12})]}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:s("st.xc.remoteHelpNote")})]})]})}const HR={off:"st.xc.readiness.off",bound:"st.xc.readiness.bound",reachable:"st.xc.readiness.reachable",unreachable:"st.xc.readiness.unreachable",failed:"st.xc.readiness.failed"};function zR({listener:t,api:s,onChanged:n}){const{t:a,locale:i}=D(),[r,o]=x.useState(t.publicUrl??""),[l,c]=x.useState(!1),[d,u]=x.useState(null);x.useEffect(()=>{o(t.publicUrl??"")},[t.publicUrl]);const p=WN(t),h=async m=>{c(!0),u(null);try{await s.configureListener(m),u({tone:"success",text:a("st.xc.saved")}),n()}catch(f){u({tone:"error",text:a("st.xc.error.listener",{reason:oe(i,f)})})}finally{c(!1)}},b=()=>{const m=r.trim();if(m!==""&&!m.startsWith("https://")){u({tone:"error",text:a("st.xc.publicUrlInvalid")});return}h({enabled:t.enabled,publicUrl:m===""?void 0:m})};return e.jsxs("div",{"data-xc-listener":!0,"data-xc-readiness":p,className:"space-y-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:a("st.xc.listenerTitle")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:a("st.xc.listenerHint")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx(Be,{id:"xc-listener-toggle",layout:"row",disabled:l,checked:t.enabled,onChange:m=>{h({enabled:m})},label:t.enabled?a("st.xc.listenerOn"):a("st.xc.listenerOff")}),e.jsxs("p",{"data-xc-listener-state-label":!0,className:"text-[12px] text-ink-faint",children:[a(HR[p]),t.origin!==void 0&&t.state==="listening"?e.jsx("span",{className:"ml-1.5 font-mono text-[11.5px]",children:t.origin}):null]})]}),t.state==="error"&&t.error!==void 0?e.jsx("p",{"data-xc-listener-error":!0,className:"text-[12px] leading-4 text-danger",children:t.error}):null,e.jsx(Oo,{label:a("st.xc.publicUrl"),hint:a("st.xc.publicUrlHint"),htmlFor:"xc-public-url",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"xc-public-url","data-xc-public-url":!0,className:`${Ce} min-w-0 flex-1 font-mono text-[11.5px]`,value:r,spellCheck:!1,disabled:l,placeholder:"https://",onChange:m=>{o(m.target.value)}}),e.jsx("button",{type:"button","data-xc-public-url-save":!0,className:Q,disabled:l,"aria-busy":l,onClick:b,children:a("common.save")})]})}),e.jsx(pe,{feedback:d})]})}const QR={"tools:read":"st.xc.scope.toolsRead","tools:write":"st.xc.scope.toolsWrite","history:read":"st.xc.scope.historyRead"};function GR(t,s){const n=QR[t];return n===void 0?t:s(n)}function WR({requests:t,api:s,onChanged:n}){const{t:a,locale:i}=D(),[r,o]=x.useState(null),[l,c]=x.useState(null),d=async(u,p)=>{o(u.id),c(null);try{await s.respondAuthorization(u.id,{connectionId:u.clientId,approved:p}),n()}catch(h){c({tone:"error",text:a("st.xc.error.respond",{reason:oe(i,h)})})}finally{o(null)}};return e.jsxs("div",{"data-xc-authorizations":!0,className:"space-y-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:a("st.xc.authTitle")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:a("st.xc.authHint")}),t.map(u=>e.jsxs("div",{"data-xc-authorization":u.id,className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 pt-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] font-medium text-ink",children:u.clientName??u.clientId}),u.scopes.length>0?e.jsx("p",{className:"truncate text-[11.5px] text-ink-faint","data-xc-auth-scopes":!0,children:u.scopes.map(p=>GR(p,a)).join(" · ")}):null]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button","data-xc-auth-approve":!0,className:Q,disabled:r!==null,"aria-busy":r===u.id,onClick:()=>{d(u,!0)},children:a("st.xc.authApprove")}),e.jsx("button",{type:"button","data-xc-auth-deny":!0,disabled:r!==null,className:"min-h-8 rounded-md px-2.5 text-[12px] text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink disabled:opacity-50",onClick:()=>{d(u,!1)},children:a("st.xc.authDeny")})]})]},u.id)),e.jsx(pe,{feedback:l})]})}function VR({connection:t,api:s,onChanged:n}){const{t:a,locale:i,time:r}=D(),o=Et(),l=x.useContext(Mo),[c,d]=x.useState(()=>pi(t)),u=Fu(c,l),[p,h]=x.useState(null),[b,m]=x.useState(!1),[f,g]=x.useState(!1),[v,y]=x.useState(null),[w,N]=x.useState(!1),_=t.status==="revoked",C=t.status==="paused",S=QN(t.mode),k=[t.name,t.mode,t.status,t.tools.join(","),String(t.allowCommands),t.historyScope,t.memoryScopes.join(",")].join(" "),[j,T]=x.useState(k);j!==k&&(T(k),d(pi(t)),N(!1));const A=async(E=!1)=>{if(u)return;if(c.name.trim()===""){h({tone:"error",text:a("st.xc.nameRequired")});return}if(c.toolPreset==="custom"&&c.tools.length===0){h({tone:"error",text:a("st.xc.toolsNoneHint")});return}const M=BR(t,rd(c,t));if(!E&&(M==="pause"||M==="access")){y({kind:"access",action:"save"});return}m(!0),h(null);try{await s.update(t.id,rd(c,t)),N(!1),y(null),h({tone:"success",text:a("st.xc.saved")}),n()}catch(z){h({tone:"error",text:a("st.xc.error.save",{reason:oe(i,z)})})}finally{m(!1)}},P=async E=>{m(!0),h(null);try{await s.update(t.id,{enabled:E}),E?h({tone:"success",text:a("st.xc.statusActive")}):xs({text:a("st.xc.pausedToast",{name:t.name}),undoFailedText:a("toast.undoFailed"),undo:async()=>{await s.update(t.id,{enabled:!0}),n()}}),n()}catch(M){h({tone:"error",text:a(E?"st.xc.error.resume":"st.xc.error.pause",{reason:oe(i,M)})})}finally{m(!1)}},R=async()=>{m(!0);try{await s.revoke(t.id),n()}catch(E){h({tone:"error",text:a("st.xc.error.revoke",{reason:oe(i,E)})})}finally{m(!1),g(!1)}},L=je({queryKey:[...OR,t.id],queryFn:()=>s.sessions(t.id),staleTime:3e4,retry:!1}),I=L.data?.sessions??[],$=[t.workspace,S===void 0?t.mode:a(S.labelKey)].filter(Boolean).join(" · ");return e.jsxs("details",{"data-xc-row":t.id,"data-xc-status":t.status,className:"group/xc border-b border-hairline last:border-b-0 [&[open]]:bg-paper",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center gap-3 px-3 py-2 outline-none transition-colors hover:bg-ink/[0.03] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-ink/[0.05] text-ink-soft",children:e.jsx(de,{name:"external",size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"flex min-w-0 items-baseline gap-2",children:e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:t.name})}),e.jsx("span",{"data-xc-summary":!0,className:"block truncate text-[12px] text-ink-faint",children:$})]}),e.jsxs("span",{"data-xc-status-label":!0,className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${_?"text-danger":C?"text-amber-ink":"text-ink-faint"}`,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${_?"bg-danger":C?"bg-amber-rule":"bg-success"}`}),e.jsx("span",{children:a(DR[t.status])})]}),e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open/xc:rotate-90"})]}),e.jsxs("div",{className:"space-y-4 px-3 pb-4 pt-1 sm:pl-[3.25rem]",children:[C?e.jsx("p",{"data-xc-paused":!0,className:"text-[12px] leading-4 text-amber-ink",children:a("st.xc.pausedBody")}):null,_?e.jsx("p",{"data-xc-revoked":!0,className:"text-[12px] leading-4 text-danger",children:a("st.xc.revokedBody")}):null,w?e.jsxs("div",{"data-xc-editor":!0,className:"space-y-3",children:[e.jsx(Oo,{label:a("st.xc.name"),hint:a("st.xc.nameHint"),htmlFor:`xc-name-${t.id}`,children:e.jsx("input",{id:`xc-name-${t.id}`,"data-xc-name":!0,className:Ce,value:c.name,disabled:b,placeholder:a("st.xc.namePlaceholder"),onChange:E=>{d({...c,name:E.target.value})}})}),e.jsx(_y,{idPrefix:`xc-${t.id}`,draft:c,disabled:b,onChange:d}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button","data-xc-save":!0,className:Q,disabled:b||u,"aria-busy":b,onClick:()=>{A()},children:a("common.save")}),e.jsx("button",{type:"button","data-xc-cancel":!0,disabled:b,className:"min-h-8 rounded-md px-2.5 text-[12px] text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink disabled:opacity-50",onClick:()=>{d(pi(t)),N(!1)},children:a("common.cancel")})]}),e.jsx(pe,{feedback:p})]}):e.jsxs(e.Fragment,{children:[e.jsxs("dl",{className:"space-y-2",children:[t.workspace?e.jsx(Wn,{label:a("st.xc.workspace"),fact:"workspace",children:e.jsx("span",{className:"font-mono text-ink",children:t.workspace})}):null,e.jsx(Wn,{label:a("st.xc.mode"),fact:"mode",children:S===void 0?t.mode:a(S.labelKey)}),e.jsx(Wn,{label:a("st.xc.tools"),fact:"tools",children:t.tools.length===0?e.jsx("span",{className:"text-ink-faint",children:a("st.xc.toolsNone")}):e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"text-ink",children:a(Cy(t.tools)?"st.xc.toolsAll":"st.xc.toolsCount",{count:t.tools.length})}),e.jsx("span",{className:"block truncate font-mono text-[11px] text-ink-faint",title:t.tools.join(" · "),children:t.tools.join(" · ")})]})}),e.jsx(Wn,{label:a("st.xc.commands"),fact:"commands",children:e.jsx("span",{className:t.allowCommands?"text-amber-ink":"text-ink-faint",children:t.allowCommands?a("st.xc.commandsOn"):a("st.xc.off")})}),e.jsx(Wn,{label:a("st.xc.history"),fact:"history",children:a(`st.xc.history.${t.historyScope}`)}),e.jsx(Wn,{label:a("st.xc.updated"),fact:"updated",children:e.jsx("span",{className:"text-ink-faint",children:r.relativeTime(sm(t.updatedAt))})})]}),e.jsx(KR,{connectionId:t.id,api:s}),e.jsxs("div",{className:"space-y-1 pt-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:a("st.xc.sessions")}),L.isLoading?e.jsx(he,{children:a("st.xc.loading")}):null,L.isError?e.jsx("p",{"data-xc-sessions-error":!0,className:"text-[12px] leading-4 text-danger",children:a("st.xc.error.sessions",{reason:oe(i,L.error)})}):null,!L.isLoading&&I.length===0?e.jsx("p",{"data-xc-sessions-empty":!0,className:"text-[12px] leading-4 text-ink-faint",children:a("st.xc.sessionsEmpty")}):null,I.length>0?e.jsx("ul",{"data-xc-sessions":!0,className:"space-y-0.5",children:I.map(E=>e.jsx("li",{"data-xc-session":E.sessionId,className:"flex min-w-0 items-center gap-2",children:e.jsxs("button",{type:"button","data-xc-session-open":!0,onClick:()=>{o(GN(E.sessionId))},className:"-ml-1.5 flex min-h-7 min-w-0 flex-1 items-center gap-1.5 rounded-md px-1.5 text-left text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsx(de,{name:"thread",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 truncate",children:r.relativeTime(sm(E.updatedAt))}),e.jsx("span",{className:"shrink-0 text-[11.5px] text-ink-faint",children:a(`st.xc.sessionStatus.${E.status}`)})]})},E.sessionId))}):null]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 pt-3",children:_?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-xc-edit":!0,className:Q,disabled:b,onClick:()=>{N(!0),h(null)},children:a("st.xc.detail")}),C?e.jsx("button",{type:"button","data-xc-resume":!0,className:Q,disabled:b,"aria-busy":b,onClick:()=>{P(!0)},children:a("st.xc.resume")}):e.jsx("button",{type:"button","data-xc-pause":!0,className:Q,disabled:b,"aria-busy":b,onClick:()=>{P(!1)},children:a("st.xc.pause")}),e.jsx("button",{type:"button","data-xc-revoke":!0,disabled:b,className:"min-h-8 rounded-md border border-danger/40 bg-paper px-3 py-1.5 text-[12px] text-danger transition-colors hover:bg-danger/5 disabled:opacity-50",onClick:()=>{g(!0)},children:a("st.xc.revoke")})]})}),e.jsx(pe,{feedback:p})]}),e.jsx(Xe,{open:f,title:a("st.xc.revokeConfirmTitle",{name:t.name}),body:a("st.xc.revokeConfirmBody",{name:t.name}),confirmLabel:a("st.xc.revokeConfirm"),tone:"danger",busy:b,onConfirm:()=>{R()},onCancel:()=>{g(!1)}}),e.jsx(Xe,{open:v!==null,title:a("st.xc.policyConfirmTitle",{name:t.name}),body:a("st.xc.policyConfirmBody",{name:t.name}),confirmLabel:a("st.xc.policyConfirm"),tone:"danger",busy:b,onConfirm:()=>{A(!0)},onCancel:()=>{y(null)}})]})]})}function YR({api:t,onCreated:s}){const{t:n,locale:a}=D(),i=x.useContext(Mo),[r,o]=x.useState("local"),[l,c]=x.useState(()=>pi(void 0)),d=Fu(l,i),[u,p]=x.useState(!1),[h,b]=x.useState(null),m=async()=>{if(!d){if(l.name.trim()===""){b({tone:"error",text:n("st.xc.nameRequired")});return}if(l.toolPreset==="custom"&&l.tools.length===0){b({tone:"error",text:n("st.xc.toolsNoneHint")});return}p(!0),b(null);try{await t.create({...rd(l,void 0),name:l.name.trim()}),c(pi(void 0)),s()}catch(f){b({tone:"error",text:n("st.xc.error.create",{reason:oe(a,f)})})}finally{p(!1)}}};return e.jsxs("div",{"data-xc-create":!0,className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button","data-xc-access":"local","aria-pressed":r==="local",onClick:()=>{o("local")},className:`min-h-7 rounded-md border px-2.5 text-[12px] transition-colors ${r==="local"?"border-hairline-strong bg-paper font-medium text-ink":"border-hairline text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:n("st.xc.addLocal")}),e.jsx("button",{type:"button","data-xc-access":"remote","aria-pressed":r==="remote",onClick:()=>{o("remote")},className:`min-h-7 rounded-md border px-2.5 text-[12px] transition-colors ${r==="remote"?"border-hairline-strong bg-paper font-medium text-ink":"border-hairline text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:n("st.xc.addRemote")})]}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:n(r==="local"?"st.xc.localHint":"st.xc.remoteHint")}),e.jsx(Oo,{label:n("st.xc.name"),hint:n("st.xc.nameHint"),htmlFor:"xc-new-name",children:e.jsx("input",{id:"xc-new-name","data-xc-new-name":!0,className:Ce,value:l.name,disabled:u,placeholder:n("st.xc.namePlaceholder"),onChange:f=>{c({...l,name:f.target.value})}})}),e.jsx(_y,{idPrefix:"xc-new",draft:l,disabled:u,onChange:c}),e.jsx("button",{type:"button","data-xc-create-submit":!0,className:Q,disabled:u||d,"aria-busy":u,onClick:()=>{m()},children:n("st.xc.add")}),e.jsx(pe,{feedback:h})]})}function JR(){const{t,locale:s}=D(),{client:n,localClient:a,connectionId:i,connectionSource:r}=be(),o=typeof i=="string"&&i!==""||zs(r),l=o?a:n,c=x.useMemo(()=>l===null?void 0:zN(l.klient),[l]),d=Oe(),[u,p]=x.useState(!1),h=je({queryKey:Ph,queryFn:()=>c.list(),staleTime:15e3,retry:!1,enabled:c!==void 0}),b=je({queryKey:Ah,queryFn:()=>c.authorizations(),staleTime:1e4,retry:!1,enabled:c!==void 0}),m=x.useCallback(()=>{d.invalidateQueries({queryKey:Ph}),d.invalidateQueries({queryKey:Ah})},[d]),f=h.data?.connections??[],g=h.data?.listener,v=b.data?.authorizations??[],y=h.isSuccess&&f.length===0;return e.jsx(Mo,{value:h.data?.toolCatalog??[],children:e.jsx(Me,{id:"st-card-external-clients",title:t("st.section.externalClients"),children:e.jsxs("div",{"data-external-clients":!0,className:"space-y-3",children:[l===null?e.jsx(he,{children:t("st.remote.controlUnavailable")}):c===void 0?e.jsx("div",{role:"alert","data-xc-unsupported":!0,className:"rounded-md border border-danger/30 bg-danger/5 px-3 py-2",children:e.jsx("p",{className:"text-[12px] leading-4 text-ink-soft",children:t("st.xc.unsupported")})}):null,h.isError?ja(h.error)?e.jsx(he,{children:t("st.remote.controlUnavailable")}):e.jsx("div",{role:"alert","data-xc-load-error":!0,className:"rounded-md border border-danger/30 bg-danger/5 px-3 py-2",children:e.jsx("p",{className:"text-[12px] leading-4 text-ink-soft",children:t("st.xc.error.load",{reason:oe(s,h.error)})})}):null,h.isLoading?e.jsx(he,{children:t("st.xc.loading")}):null,f.length>0?e.jsx("div",{"data-xc-list":!0,className:"overflow-hidden rounded-lg border border-hairline bg-panel",children:f.map(w=>e.jsx(VR,{connection:w,api:c,onChanged:m},w.id))}):null,y?e.jsx("div",{"data-xc-empty":!0,children:e.jsx(Ct,{kind:"none",title:t("st.xc.emptyListTitle"),body:t("st.xc.emptyListBody"),action:u?void 0:e.jsx("button",{type:"button","data-xc-add":!0,className:Q,onClick:()=>{p(!0)},children:t("st.xc.add")})})}):null,f.length>0&&!u?e.jsx("button",{type:"button","data-xc-add":!0,className:Q,onClick:()=>{p(!0)},children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(de,{name:"plus",size:12}),t("st.xc.add")]})}):null,u&&c!==void 0?e.jsxs("div",{"data-xc-create-panel":!0,className:"space-y-3 pt-4",children:[e.jsx(YR,{api:c,onCreated:()=>{p(!1),m()}}),e.jsx("button",{type:"button","data-xc-create-cancel":!0,className:"min-h-8 rounded-md px-2.5 text-[12px] text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{p(!1)},children:t("common.cancel")})]}):null,v.length>0&&c!==void 0?e.jsx("div",{className:"pt-4",children:e.jsx(WR,{requests:v,api:c,onChanged:m})}):null,g!==void 0&&c!==void 0?e.jsx("div",{className:"pt-4",children:e.jsxs("details",{"data-xc-access-details":!0,className:"group/xc-access",children:[e.jsxs("summary",{className:"flex min-h-8 cursor-pointer list-none items-center gap-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"transition-transform group-open/xc-access:rotate-90"}),t("st.xc.accessTitle")]}),e.jsxs("div",{className:"mt-2 space-y-3",children:[e.jsx(zR,{listener:g,api:c,onChanged:m}),e.jsx("div",{className:"pt-3",children:e.jsx(UR,{listener:g})})]})]})}):null,o?null:e.jsx(JC,{})]})})})}const ZR="inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none disabled:cursor-not-allowed disabled:text-ink-faint disabled:hover:bg-transparent pointer-coarse:h-10",XR="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-40 pointer-coarse:h-10 pointer-coarse:w-10";function e5(){const{client:t,localClient:s,connectionId:n,connectionSource:a}=be(),r=typeof n=="string"&&n!==""||zs(a)?s:t,{t:o,locale:l}=D(),[c,d]=x.useState(null),[u,p]=x.useState(null),[h,b]=x.useState(!0),[m,f]=x.useState(null),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(""),[k,j]=x.useState(),[T,A]=x.useState(!1),[P,R]=x.useState(null),[L,I]=x.useState(!1);x.useEffect(()=>{if(r===null){d(null),p(null),b(!1);return}try{const B=Q_(r.klient);d(B)}catch(B){f(oe(l,B)),b(!1)}},[r,l]);const $=x.useCallback(async()=>{if(c){b(!0),f(null);try{const B=await c.read();p(B)}catch(B){f(oe(l,B))}finally{b(!1)}}},[c,l]);x.useEffect(()=>{c&&$()},[c,$]);const E=async()=>{if(c){v("refresh"),w(null);try{const B=await c.status();p(le=>le&&le.state==="available"?{...le,status:B}:le),w({tone:"success",text:o("st.conn.ext.refreshed")})}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},M=async()=>{if(!(!c||!u||u.state!=="not-installed")){v("preview"),w(null);try{const B=u.catalog?.source?.trim()??"";if(B.length===0)throw new Error(o("st.conn.ext.catalogMissing"));const le=u.catalog?.sha256,re=await c.previewInstall({source:B,sha256:le});_(re),S(B),j(le),A(!0)}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},z=async()=>{if(!(!c||!N)){A(!1),v("install"),w(null);try{await c.install({source:C,sha256:k,plan:N,consent:!0}),w({tone:"success",text:o("st.conn.ext.installed")}),await $()}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null),_(null)}}},H=async()=>{if(c){v("enable"),w(null);try{await c.enable(),await $()}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},U=async()=>{if(c){v("dep"),w(null);try{const B=await c.installDependency(!0);p(le=>le&&le.state==="available"?{...le,status:B}:le),w({tone:"success",text:o("st.conn.ext.depInstalled")})}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},X=async B=>{if(c){v("service"),w(null);try{const le=B?await c.stop():await c.start();p(re=>re&&re.state==="available"?{...re,status:le}:re)}catch(le){w({tone:"error",text:oe(l,le)})}finally{v(null)}}},q=async B=>{if(c){v("autoStart"),w(null);try{const le=await c.setAutoStart(!B);p(re=>re&&re.state==="available"?{...re,status:le}:re)}catch(le){w({tone:"error",text:oe(l,le)})}finally{v(null)}}},F=async()=>{if(c){v("login"),w(null);try{const B=await c.login();p(le=>le&&le.state==="available"?{...le,status:B}:le)}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},V=async()=>{if(c){v("cancelLogin"),w(null);try{const B=await c.cancelLogin();p(le=>le&&le.state==="available"?{...le,status:B}:le)}catch(B){w({tone:"error",text:oe(l,B)})}finally{v(null)}}},se=async()=>{if(c){I(!0);try{const B=await c.tunnels();R(B.items)}catch(B){w({tone:"error",text:oe(l,B)})}finally{I(!1)}}},Y=async B=>{if(c){v(`select-${B}`),w(null);try{const le=await c.selectTunnel(B);p(re=>re&&re.state==="available"?{...re,status:le}:re),w({tone:"success",text:o("st.conn.ext.tunnelSelected")})}catch(le){w({tone:"error",text:oe(l,le)})}finally{v(null)}}},O=async B=>{try{await rs(B),w({tone:"success",text:o("st.conn.ext.copied")})}catch(le){w({tone:"error",text:oe(l,le)})}};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Me,{id:"st-card-conn-external",title:o("st.conn.ext.title"),children:e.jsxs("div",{className:"space-y-4","data-conn-external":!0,children:[e.jsx("p",{className:"text-[12.5px] text-ink-soft",children:o("st.conn.ext.intro")}),r===null?e.jsx(he,{children:o("st.remote.controlUnavailable")}):h?e.jsx(he,{children:o("st.spaces.loading")}):m?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{role:"alert",className:"max-w-[62ch] text-[12.5px] leading-snug text-danger",children:m}),e.jsx("div",{children:e.jsx("button",{type:"button",onClick:()=>{$()},className:ZR,children:o("st.conn.ext.retry")})})]}):u?.state==="not-installed"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-snug text-ink-soft",children:o("st.conn.ext.notInstalled")}),e.jsx("div",{children:e.jsx("button",{type:"button",onClick:()=>{M()},disabled:g!==null,className:Q,"data-conn-ext-install":!0,children:o(g==="preview"?"st.conn.ext.installing":"st.conn.ext.installPlugin")})})]}):u?.state==="disabled"||u?.state==="invalid"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-snug text-ink-soft",children:o("st.conn.ext.disabled")}),u.errors.length>0?e.jsx("ul",{className:"list-disc pl-4 text-[12px] text-danger",children:u.errors.map((B,le)=>e.jsx("li",{children:B},le))}):null,e.jsx("div",{children:e.jsx("button",{type:"button",onClick:()=>{H()},disabled:g!==null,className:Q,"data-conn-ext-enable":!0,children:o("st.conn.ext.enablePlugin")})})]}):u?.state==="available"?e.jsx(t5,{status:u.status,version:u.version,busy:g,loadingTunnels:L,tunnelsList:P,onRefresh:()=>{E()},onInstallDep:()=>{U()},onToggleService:B=>{X(B)},onToggleAutoStart:B=>{q(B)},onLogin:()=>{F()},onCancelLogin:()=>{V()},onLoadTunnels:()=>{se()},onSelectTunnel:B=>{Y(B)},onCopyUrl:B=>{O(B)}}):null,e.jsx(pe,{feedback:y})]})}),e.jsx(Xe,{open:T,overlayId:"confirm-conn-ext-install",title:o("st.conn.ext.installConfirmTitle"),body:N?`${N.id}${N.version===void 0?"":` (${N.version})`}
|
|
245
|
+
${o("st.conn.ext.installConfirmBody",{id:N.id,fingerprint:YN(N.fingerprint,6,6)})}`:o("st.conn.ext.installPlugin"),confirmLabel:o("st.conn.ext.installPlugin"),tone:"default",onConfirm:()=>{z()},onCancel:()=>{A(!1),_(null),j(void 0)}})]})}function t5({status:t,version:s,busy:n,loadingTunnels:a,tunnelsList:i,onRefresh:r,onInstallDep:o,onToggleService:l,onToggleAutoStart:c,onLogin:d,onCancelLogin:u,onLoadTunnels:p,onSelectTunnel:h,onCopyUrl:b}){const{t:m}=D(),f=t.service.state==="running",g=t.dependency.state==="missing",v=t.configuration.publicUrl;return e.jsxs("div",{className:"space-y-4","data-conn-ext-available":!0,children:[g?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-amber-ink/20 bg-amber-ink/[0.04] px-3 py-2 text-[12.5px]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-amber-ink",children:m("st.conn.ext.depMissing")}),e.jsx("p",{className:"text-[12px] text-ink-soft",children:m("st.conn.ext.depMissingHint")})]}),e.jsx("button",{type:"button",onClick:o,disabled:n!==null,className:Q,"data-conn-ext-dep-install":!0,children:m(n==="dep"?"st.conn.ext.installing":"st.conn.ext.installDep")})]}):null,e.jsxs(Ze,{children:[e.jsx("div",{children:e.jsxs(ge,{label:m("st.conn.ext.service"),help:s!==void 0?m("st.conn.ext.versionLine",{version:s}):void 0,children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[13px]",children:[e.jsx("span",{"aria-hidden":!0,className:`inline-block h-2 w-2 rounded-full ${f?"bg-success":t.service.state==="starting"?"bg-amber-ink":"bg-ink-faint"}`}),e.jsx("span",{className:f?"font-medium text-success":"text-ink","data-conn-ext-service-state":!0,children:m(`st.conn.ext.state.${t.service.state}`)||t.service.state})]}),e.jsx("button",{type:"button",onClick:()=>l(f),disabled:n!==null||g,className:Q,"data-conn-ext-service-toggle":!0,children:m(n==="service"?f?"st.conn.ext.stopping":"st.conn.ext.starting":f?"st.conn.ext.stop":"st.conn.ext.start")}),e.jsx("button",{type:"button",onClick:r,disabled:n!==null,className:XR,title:m("st.conn.ext.refresh"),"aria-label":m("st.conn.ext.refresh"),"data-conn-ext-refresh":!0,children:e.jsx(de,{name:"refresh",size:14})})]})}),e.jsx("div",{children:e.jsx(ge,{label:m("st.conn.ext.autoStart"),help:m("st.conn.ext.autoStartHint"),htmlFor:"conn-ext-auto-start",children:e.jsx(Be,{id:"conn-ext-auto-start",layout:"bare",label:m("st.conn.ext.autoStart"),checked:t.configuration.autoStart,disabled:n!==null,onChange:()=>c(t.configuration.autoStart)})})}),e.jsx("div",{children:t.login.state==="pending"?e.jsx(ge,{label:m("st.conn.ext.loginTitle"),layout:"stack",children:e.jsxs("div",{className:"space-y-2","data-conn-ext-login-pending":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-amber-ink",children:m("st.conn.ext.loginPending")}),t.login.url?e.jsx("a",{href:t.login.url,target:"_blank",rel:"noreferrer noopener",className:"block break-all text-[12px] text-ink underline",children:t.login.url}):null,e.jsx("div",{children:e.jsx("button",{type:"button",onClick:u,disabled:n!==null,className:Q,children:m("st.conn.ext.cancelLogin")})})]})}):e.jsx(ge,{label:m("st.conn.ext.loginTitle"),help:t.account.certificate?m("st.conn.ext.loggedIn"):m("st.conn.ext.notLoggedIn"),children:e.jsx("button",{type:"button",onClick:d,disabled:n!==null||g,className:Q,"data-conn-ext-login":!0,children:m(n==="login"?"st.conn.ext.loggingIn":"st.conn.ext.login")})})}),v!==void 0&&v!==""?e.jsx("div",{children:e.jsx(ge,{label:m("st.conn.ext.publicUrl"),layout:"stack",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2","data-conn-ext-url":!0,children:[e.jsx("code",{className:"min-w-0 flex-1 break-all rounded-md bg-ink/[0.04] px-2 py-1.5 font-mono text-[11.5px] leading-[1.55] text-ink-soft",children:v}),e.jsx("button",{type:"button",onClick:()=>b(v),className:Q,"data-conn-ext-copy-url":!0,children:m("connect.copyLink")})]})})}):null,e.jsxs("div",{children:[e.jsxs(ge,{label:m("st.conn.ext.tunnel"),children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink-soft","data-conn-ext-current-tunnel":!0,children:t.configuration.tunnelId??m("st.conn.ext.noTunnelSelected")}),e.jsx("button",{type:"button",onClick:p,disabled:a,className:Q,"data-conn-ext-list-tunnels":!0,children:m(a?"selection.loading":"st.conn.ext.listTunnels")})]}),i&&i.length>0?e.jsx("div",{className:"mt-1 divide-y divide-hairline","data-conn-ext-tunnels":!0,children:i.map(y=>e.jsxs("div",{className:"flex items-center justify-between gap-2 py-1.5 text-[12px]",children:[e.jsxs("div",{className:"min-w-0 pr-2",children:[e.jsx("p",{className:"truncate font-medium text-ink",children:y.name}),e.jsx("p",{className:"truncate font-mono text-[11px] text-ink-faint",children:y.id})]}),e.jsx("button",{type:"button",onClick:()=>h(y.id),disabled:n!==null||y.id===t.configuration.tunnelId,className:Q,children:y.id===t.configuration.tunnelId?m("st.conn.ext.selected"):m("st.conn.ext.useTunnel")})]},y.id))}):i&&i.length===0?e.jsx("p",{className:"mt-1 text-[12px] text-ink-faint",children:m("st.conn.ext.tunnelsEmpty")}):null]})]})]})}function Di({name:t,subtitle:s,marks:n,control:a,open:i,onToggle:r,bodyId:o,expandLabel:l,data:c,children:d}){return e.jsxs("div",{...c,"data-open":i?"true":void 0,className:"rounded-lg transition-colors",children:[e.jsxs("div",{className:`flex min-h-[52px] items-center gap-2 rounded-lg px-1 py-1.5 transition-colors ${i?"bg-ink/[0.03]":""}`,children:[e.jsx("button",{type:"button","aria-expanded":i,"aria-controls":o,"aria-label":l,onClick:r,className:"group/row flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1 text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13.5px] font-medium text-ink","data-row-name":!0,children:t}),n]}),s==null?null:e.jsx("span",{className:"mt-0.5 flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-[12px] text-ink-faint",children:s})]})}),a!==void 0?e.jsx("div",{className:"flex shrink-0 items-center gap-2 pl-1",children:a}):null]}),e.jsx("div",{id:o,hidden:!i,"data-row-body":!0,className:"px-2 pb-4 pt-3",children:d})]})}const $h={read:"st.remote.threadMessages.op.read",send:"st.remote.threadMessages.op.send",wait:"st.remote.threadMessages.op.wait",wake:"st.remote.threadMessages.op.wake",create:"st.remote.threadMessages.op.create",tools:"st.remote.threadMessages.op.tools"},Xl=["read","send","wait","wake","create","tools"];function s5(t,s){try{return new Intl.DateTimeFormat(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"short",day:"numeric"}).format(new Date(t))}catch{return new Date(t).toISOString().slice(0,10)}}function Ey({client:t,subject:s,onClose:n}){const{t:a,locale:i}=D(),r=Oe(),o=s.kind==="outbound"?s.record.label:s.grant.label,l=Ud(t),c=typeof t.listWorkspaceCatalog=="function"||typeof t.listWorkspaces=="function",d=je({queryKey:[...li.localWorkspaces(),t.baseUrl??null],queryFn:async()=>typeof t.listWorkspaceCatalog=="function"?(await t.listWorkspaceCatalog()).items:typeof t.listWorkspaces=="function"?(await t.listWorkspaces()).items:[],enabled:c,staleTime:3e4}),[u,p]=x.useState(null),[h,b]=x.useState(!1),[m,f]=x.useState(null),[g,v]=x.useState(null),y=l.data===void 0?[]:s.kind==="outbound"?n1(s.record,l.data):a1(s.grant,l.data),w=new Map;for(const R of d.data??[])w.set(R.id,R.name);const N=()=>{r.invalidateQueries({queryKey:li.all})},_=(R,L)=>{r.setQueryData([...li.status(),t.baseUrl??null],R),N(),f({tone:"success",text:L})},C=R=>{const L=ga(R instanceof Error?R.message:"");f({tone:"error",text:L===null?oe(i,R):a(L)})},S=()=>{s.kind==="outbound"&&(b(!0),f(null),Ka(t).syncConnection(s.record.id,{borrowTools:!0}).then(R=>{r.invalidateQueries({queryKey:fo.all}),_(R,a("st.remote.threadMessages.synced"))}).catch(C).finally(()=>{b(!1)}))},k=R=>{const L=!R.enabled;p(R.id),f(null),Ka(t).setEnabled(R.direction,R.id,L).then(I=>{_(I,a(L?"st.remote.threadMessages.turnedOn":"st.remote.threadMessages.turnedOff"))}).catch(C).finally(()=>{p(null)})},j=(R,L)=>{p(R.id),f(null),Ka(t).setBorrowTools(R.id,L).then(I=>{_(I,a(L?"st.remote.threadMessages.borrowToolsOn":"st.remote.threadMessages.borrowToolsOff"))}).catch(C).finally(()=>{p(null)})},T=(R,L)=>{const I=new Set(R.operations);if(I.has(L)){if(I.size<=1)return;I.delete(L)}else I.add(L);const $=Xl.filter(E=>I.has(E));$.length!==0&&(p(R.id),f(null),Ka(t).setOperations(R.id,$).then(E=>{_(E,a("st.remote.threadMessages.operationsUpdated"))}).catch(C).finally(()=>{p(null)}))},A=R=>{v(null),p(R.id),f(null),Ka(t).revoke(R.direction,R.id).then(L=>{_(L,a("st.remote.threadMessages.revoked"))}).catch(C).finally(()=>{p(null)})},P=R=>R.direction==="outbound"?a("st.remote.threadMessages.dirOutgoing",{space:o}):a("st.remote.threadMessages.dirIncoming",{space:o});return e.jsxs(e.Fragment,{children:[e.jsx($n,{title:a("st.remote.threadMessages.title"),description:a("st.remote.threadMessages.description",{name:o}),overlayId:"thread-messages-panel",onClose:n,data:{"data-thread-messages-panel":s.kind==="outbound"?s.record.id:s.grant.id},footer:e.jsx("button",{type:"button",className:Q,onClick:n,"data-thread-messages-close":!0,children:a("common.close")}),children:e.jsxs("div",{className:"space-y-4",children:[l.isLoading?e.jsx(he,{children:a("st.remote.loading")}):null,l.isError?e.jsx("p",{className:"text-[13px] text-amber-ink",role:"alert","data-thread-messages-error":!0,children:a("st.remote.threadMessages.loadError")}):null,l.isSuccess&&y.length===0?e.jsxs("div",{className:"space-y-3","data-thread-messages-empty":!0,children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:a("st.remote.threadMessages.empty",{name:o})}),s.kind==="outbound"?e.jsx("button",{type:"button",className:Ye,disabled:h||u!==null,"data-thread-messages-sync":!0,onClick:()=>{S()},children:a(h?"st.remote.threadMessages.syncing":"st.remote.threadMessages.syncAction")}):null]}):null,y.length>0?e.jsx("div",{className:"space-y-3","data-thread-messages-list":!0,children:y.map(R=>{const L=R.localScope.workspaceId==="*"?a("st.remote.threadMessages.scopeAllWorkspaces"):w.get(R.localScope.workspaceId)??lm(R.localScope.workspaceId)??a("st.remote.threadMessages.scopeUnknownLocal"),I=R.remoteScope.workspaceId==="*"?a("st.remote.threadMessages.scopeAllWorkspaces"):lm(R.remoteScope.workspaceId)??a("st.remote.threadMessages.scopeRemoteWorkspace"),$=R.localScope.sessionId!==void 0?a("st.remote.threadMessages.scopeOneThread"):a("st.remote.threadMessages.scopeAllThreads"),E=R.remoteScope.sessionId!==void 0?a("st.remote.threadMessages.scopeOneThread"):a("st.remote.threadMessages.scopeAllThreads"),M=new Set(R.operations),z=Xl.filter(F=>M.has(F)),H=R.operations.includes("wake"),U=R.direction==="outbound"&&R.operations.includes("tools"),X=R.expired?{label:a("st.remote.threadMessages.stateExpired"),dot:"bg-attention",text:"text-amber-ink"}:R.enabled?{label:a("st.remote.threadMessages.stateOn"),dot:"bg-success",text:"text-ink-soft"}:{label:a("st.remote.threadMessages.stateOff"),dot:"bg-ink-faint/50",text:"text-ink-faint"},q=u===R.id;return e.jsxs("section",{"data-thread-message-entry":R.id,"data-thread-message-direction":R.direction,className:"space-y-2.5 rounded-lg border border-hairline bg-ink/[0.02] px-3.5 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-[13.5px] font-medium text-ink","data-thread-message-heading":!0,children:P(R)}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[11.5px] ${X.text}`,"data-thread-message-state":!0,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${X.dot}`}),X.label]})]}),e.jsxs("dl",{className:"space-y-1.5 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.remote.threadMessages.scopeLocalLabel")}),e.jsxs("dd",{className:"text-ink-soft","data-thread-message-local-scope":!0,children:[e.jsx("span",{className:"font-medium text-ink",children:L}),e.jsx("span",{className:"text-ink-faint",children:` · ${$}`})]})]}),e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.remote.threadMessages.scopeRemoteLabel",{space:o})}),e.jsxs("dd",{className:"text-ink-soft","data-thread-message-remote-scope":!0,children:[e.jsx("span",{className:"font-medium text-ink",children:I}),e.jsx("span",{className:"text-ink-faint",children:` · ${E}`})]})]}),R.direction==="inbound"?e.jsxs("div",{className:"space-y-1.5 pt-0.5",children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.remote.threadMessages.operationsLabel")}),e.jsx("dd",{className:"flex flex-wrap gap-1.5","data-thread-message-operations":!0,children:Xl.map(F=>{const V=M.has(F),se=V&&R.operations.length<=1;return e.jsxs("button",{type:"button","data-bridge-op-toggle":`${R.id}:${F}`,"aria-pressed":V,disabled:q||R.expired||se,onClick:()=>{T(R,F)},className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11.5px] transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${V?"border-selected-ink/40 bg-selected font-medium text-selected-ink":"border-hairline bg-paper text-ink-faint hover:border-hairline-strong hover:text-ink-soft"}`,children:[V?e.jsx(de,{name:"check",size:12,className:"shrink-0"}):null,e.jsx("span",{children:a($h[F])})]},F)})})]}):e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.remote.threadMessages.operationsLabel")}),e.jsx("dd",{className:"text-ink","data-thread-message-operations":!0,children:z.map(F=>a($h[F])).join(" · ")})]})]}),U?e.jsxs("label",{className:`flex items-center gap-2 pt-0.5 text-[12px] ${q||R.expired?"cursor-not-allowed text-ink-faint opacity-60":"cursor-pointer text-ink"}`,htmlFor:`bridge-borrow-tools-${R.id}`,children:[e.jsx("input",{id:`bridge-borrow-tools-${R.id}`,type:"checkbox","data-bridge-borrow-tools":R.id,checked:R.borrowTools??!0,disabled:q||R.expired,onChange:F=>{j(R,F.target.checked)},className:"h-3.5 w-3.5 shrink-0 rounded border-hairline-strong accent-selected-ink"}),e.jsx("span",{children:a("st.remote.threadMessages.borrowToolsLabel")})]}):null,H?null:e.jsx("p",{className:"text-[11.5px] leading-snug text-ink-faint","data-thread-message-no-wake":!0,children:a("st.remote.threadMessages.noWakeNote")}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-t border-hairline pt-2.5",children:[e.jsx("span",{className:"text-[11.5px] text-ink-faint tabular-nums","data-thread-message-expiry":!0,children:a("st.remote.threadMessages.expiresOn",{date:s5(R.grant.expiresAt,i)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:q||R.expired,"data-thread-message-toggle":R.id,onClick:()=>{k(R)},children:R.enabled?a("st.remote.threadMessages.turnOff"):a("st.remote.threadMessages.turnOn")}),e.jsx("button",{type:"button",className:O1,disabled:q,"data-thread-message-revoke":R.id,onClick:()=>{v(R)},children:a("st.remote.threadMessages.revokeMenu")})]})]})]},`${R.direction}:${R.id}`)})}):null,e.jsx(pe,{feedback:m})]})}),g!==null?e.jsx(Xe,{open:!0,stacked:!0,overlayId:"thread-message-revoke",tone:"danger",title:a("st.remote.threadMessages.revokeTitle"),body:a("st.remote.threadMessages.revokeBody",{direction:P(g),name:o}),confirmLabel:a("st.remote.threadMessages.revokeConfirm"),onCancel:()=>{v(null)},onConfirm:()=>{A(g)}}):null]})}const n5={approved:{dot:"bg-success",text:"text-ink-soft"},invited:{dot:"bg-attention",text:"text-attention"},revoked:{dot:"bg-hairline-strong",text:"text-ink-faint"}},a5=720*60*60*1e3;function i5(t,s){return t.status==="approved"&&t.activeLeases===0&&s-(t.lastConnectedAt??t.createdAt)>=a5}function r5({grant:t,gateEnabled:s,threadFact:n,bridgesAvailable:a,onOpenThreadMessages:i,onRevoke:r}){const{t:o,locale:l}=D(),[c,d]=x.useState(!1),u=x.useRef(null),[p,h]=x.useState(null),b=n5[t.status],m=i5(t,Date.now()),f=s&&t.status==="approved"&&t.purpose==="gui",g=[{key:"thread-messages",label:o("st.remote.threadMessages.menu"),blockedReason:a?void 0:o("st.remote.controlUnavailable"),run:i},{key:"revoke",label:o("st.inbound.revoke"),danger:!0,separatorBefore:!0,blockedReason:t.status==="revoked"?o("st.inbound.status.revoked"):void 0,run:r}];return e.jsx(Di,{data:{"data-inbound-grant":t.id,"data-inbound-status":t.status},open:c,onToggle:()=>{d(v=>!v)},bodyId:`inbound-grant-body-${t.id}`,expandLabel:o("st.browser.menu.openRow",{name:t.label}),name:t.label,marks:e.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${b.text}`,"data-inbound-status-chip":t.status,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${b.dot}`}),o(`st.inbound.status.${t.status}`),m?e.jsx("span",{className:"ml-1 shrink-0 rounded-full bg-amber-rule/10 px-1.5 py-0.5 text-[10.5px] font-medium text-amber-ink","data-inbound-stale":"true",children:o("st.inbound.stale")}):null]}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-inbound-openable":f?"yes":"no",children:o(f?"st.inbound.canOpen":"st.inbound.cantOpen")}),n!==null?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:n==="unreadable"?"text-amber-ink":void 0,"data-inbound-thread-messages":n,children:o(Zb(n))})]}):null,e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsxs("span",{"data-inbound-activity":!0,children:[t.lastConnectedAt===void 0?o("st.inbound.neverConnected"):o("st.remote.lastConnected",{time:Nn(new Date(t.lastConnectedAt).toISOString(),l)}),t.activeLeases>0?` · ${o("st.inbound.active",{count:t.activeLeases})}`:""]})]}),control:e.jsxs(e.Fragment,{children:[m?e.jsx("button",{type:"button","data-inbound-quick-revoke":t.id,onClick:r,className:"h-7 shrink-0 rounded-md px-2 text-[11.5px] font-medium text-amber-ink transition-colors hover:bg-amber-rule/10 hover:text-ink",children:o("st.inbound.revokeConfirm")}):null,e.jsx("button",{ref:u,type:"button","data-inbound-grant-menu":t.id,"aria-label":o("st.browser.menu.open",{name:t.label}),"aria-haspopup":"menu","aria-expanded":p!==null,onClick:()=>{h(u.current?.getBoundingClientRect()??null)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.04] hover:text-ink",children:e.jsx(de,{name:"more",size:14})}),p!==null?e.jsx($a,{anchor:p,anchorElement:u.current,items:g,ariaLabel:o("st.browser.menu.open",{name:t.label}),onClose:()=>{h(null)}}):null]}),children:e.jsx("p",{className:"text-[12px] text-ink-faint","data-inbound-grant-details":!0,children:o("st.inbound.addedAt",{time:Nn(new Date(t.createdAt).toISOString(),l)})})})}function o5({identity:t}){const{t:s}=D(),[n,a]=x.useState(!1),[i,r]=x.useState(null),o=async()=>{r(null);try{await rs(o1(t)),a(!0),window.setTimeout(()=>{a(!1)},1600)}catch(l){r(l instanceof Error?l.message:String(l))}};return e.jsxs("div",{className:"pt-1","data-remote-self-identity":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3","data-copy-field":"self",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] text-ink",id:"remote-self-identity-label",children:s("st.remote.identityTitle")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-faint",children:s("st.remote.identityBody")})]}),e.jsxs("button",{type:"button",className:`${Q} shrink-0`,"data-copy-action":!0,"aria-describedby":"remote-self-identity-label",onClick:()=>{o()},children:[e.jsx(de,{name:"copy",size:12,className:"mr-1 inline-block align-[-1px]"}),s(n?"st.remote.identityCopied":"st.remote.identityCopy")]})]}),i!==null?e.jsx("p",{className:"mt-1.5 text-[12px] text-danger",role:"alert",children:s("st.remote.copyFailed",{reason:i})}):null]})}function l5(){const t=mt(),{client:s,localClient:n,connectionId:a,sshLabel:i,connectionSource:r}=be(),{t:o,locale:l}=D(),c=Et(),d=Oe(),u=!!a||!!i||zs(r),p=t.kind==="tauri"?n:n??(u?null:s),h=i1(p),b=Ud(p),m=Jb(p),f=p===null?null:Kd(p),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(!1),C=()=>{d.invalidateQueries({queryKey:fo.all}),d.invalidateQueries({queryKey:li.all})},S=h.data?.grants??[],k=h.data?.enabled??!1,j=h.data?.configuredEnabled??!1,T=A=>{f!==null&&(_(!0),w(null),f.setInbound(A).then(()=>{C()}).catch(P=>{const R=ga(P instanceof Error?P.message:"");w({tone:"error",text:R===null?oe(l,P):o(R)})}).finally(()=>{_(!1)}))};return e.jsxs(Me,{id:"st-card-inbound-connections",title:o("st.inbound.title"),scope:"server",actions:e.jsxs("button",{type:"button","data-inbound-invite":!0,className:`${Ye} inline-flex items-center gap-1`,disabled:f===null||h.data?.unavailableReason==="dangerous_auth_bypass",title:h.data?.unavailableReason==="dangerous_auth_bypass"?o("st.inbound.devRuntime"):void 0,onClick:()=>{v({kind:"invite"})},children:[e.jsx(de,{name:"plus",size:12}),o("st.inbound.invite")]}),children:[e.jsxs("div",{className:"space-y-4","data-inbound-connections":!0,children:[p===null?e.jsx(he,{children:o("st.remote.controlUnavailable")}):null,h.isError?e.jsx(De,{error:h.error}):null,h.data!==void 0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5","data-inbound-gate":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx("p",{className:"mr-auto text-[13px] text-ink",children:o("st.inbound.gate")}),e.jsx(Be,{id:"inbound-connections-enabled",layout:"bare",label:o("st.inbound.gate"),checked:k,disabled:N||h.data.unavailableReason==="dangerous_auth_bypass",dataAttr:"data-inbound-gate-switch",onChange:A=>{T(A)}})]}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint",children:o("st.inbound.gateHint")}),h.data.unavailableReason==="dangerous_auth_bypass"?e.jsx("p",{className:"text-[12px] leading-snug text-amber-ink","data-inbound-dev-runtime":!0,children:o("st.inbound.devRuntime")}):j!==k?e.jsx("p",{className:"text-[12px] leading-snug text-amber-ink","data-inbound-configured":!0,children:o("st.inbound.configuredOnly")}):null]}),k&&S.length===0?e.jsx("p",{className:"text-[13px] text-ink-soft","data-inbound-empty":!0,children:o("st.inbound.emptyLine")}):S.length>0?e.jsx("div",{"aria-label":o("st.inbound.listTitle"),"data-inbound-list":!0,children:S.map(A=>{const P=!m||b.isLoading?m?null:"unreadable":b.isError||b.data===void 0?"unreadable":r1(A,b.data);return e.jsx(r5,{grant:A,gateEnabled:k,threadFact:P,bridgesAvailable:m,onOpenThreadMessages:()=>{v({kind:"thread-messages",grant:A})},onRevoke:()=>{v({kind:"revoke",grantId:A.id,name:A.label})}},A.id)})}):null,e.jsxs("p",{className:"text-[12.5px] text-ink-faint","data-inbound-outbound-note":!0,children:[o("st.inbound.outboundNotePrefix"),e.jsx("button",{type:"button","data-inbound-open-spaces":!0,className:"text-ink-soft underline decoration-hairline-strong underline-offset-2 hover:text-ink",onClick:()=>{c("/settings/spaces")},children:o("st.inbound.outboundNoteLink")}),o("st.inbound.outboundNoteSuffix")]}),e.jsx(et,{summary:o("st.computer.advanced"),"data-inbound-advanced-fold":!0,children:e.jsx(o5,{identity:h.data.identity})})]}):null,e.jsx(pe,{feedback:y})]}),g?.kind==="invite"&&p!==null?e.jsx(Fb,{client:p,direction:"inbound",onClose:()=>{v(null)},onInvited:C}):null,g?.kind==="thread-messages"&&p!==null?e.jsx(Ey,{client:p,subject:{kind:"inbound",grant:g.grant},onClose:()=>{v(null)}}):null,g?.kind==="revoke"&&f!==null?e.jsx(Xe,{open:!0,overlayId:"inbound-revoke-confirm",tone:"danger",title:o("st.inbound.revokeTitle",{name:g.name}),body:o("st.inbound.revokeBody",{name:g.name}),confirmLabel:o("st.inbound.revokeConfirm"),onCancel:()=>{v(null)},onConfirm:()=>{const A=g.grantId,P=g.name;v(null),_(!0),f.revoke(A).then(()=>{w({tone:"success",text:o("st.inbound.revoked",{name:P})}),C()}).catch(R=>{const L=ga(R instanceof Error?R.message:"");w({tone:"error",text:L===null?oe(l,R):o(L)})}).finally(()=>{_(!1)})}}):null]})}function c5({client:t}){const{t:s,locale:n}=D(),a=Oe(),i=Cw(t),[r,o]=x.useState(!1),[l,c]=x.useState(null),d=()=>{t!==null&&(o(!0),c(null),Js(t).logout().then(()=>{c({tone:"success",text:s("st.web.signedOut")}),a.invalidateQueries({queryKey:Iw.session()})}).catch(u=>{c({tone:"error",text:oe(n,u)})}).finally(()=>{o(!1)}))};return e.jsx(Me,{id:"st-card-web-access",title:s("st.web.title"),scope:"readOnly",aside:s("st.web.hint"),children:e.jsxs("div",{className:"space-y-2.5","data-web-access-guest":!0,children:[i.isError?e.jsx(De,{error:i.error}):null,i.data?.authenticated===!0&&i.data.session!==null?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[13px] text-ink","data-web-access-guest-session":!0,children:[s("st.web.signedInAs",{name:i.data.session.label}),i.data.session.expiresAt!==void 0?e.jsxs("span",{className:"text-ink-faint",children:[" · ",s("st.web.expires",{duration:Bd(new Date(i.data.session.expiresAt).toISOString(),n)})]}):null]}),e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:s("st.web.lastUsed",{time:Nn(new Date(i.data.session.lastUsedAt).toISOString(),n)})}),e.jsx("div",{children:e.jsx("button",{type:"button","data-web-access-sign-out":!0,className:Q,disabled:r,onClick:d,children:s(r?"st.web.signingOut":"st.web.revoke")})})]}):i.isLoading?e.jsx(he,{children:s("st.spaces.loading")}):e.jsx("p",{className:"text-[13px] text-ink","data-web-access-guest-none":!0,children:s("st.web.signedInNone")}),e.jsx(pe,{feedback:l})]})})}function d5(){const t=mt(),{client:s,localClient:n,connectionId:a,sshLabel:i,connectionSource:r}=be(),{t:o,locale:l}=D(),c=Oe(),d=r==="web-cookie",u=!!a||!!i||zs(r),p=t.kind==="tauri"?n:n??(u?null:s),h=Sw(p),b=xo(p),[m,f]=x.useState(null),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(!1),[k,j]=x.useState(Mp),[T,A]=x.useState(!1),[P,R]=x.useState([]),[L,I]=x.useState(!1),$=()=>{c.invalidateQueries({queryKey:["web-access"]})},E=h.data,M=(b.data??[]).filter(Rr);x.useEffect(()=>{E===void 0||T||j(Op(E))},[E,T]),x.useEffect(()=>{E===void 0||L||R(E.sharedConnectionIds??[])},[E,L]);const z=async(V,se,Y)=>{if(p!==null){f(V),w(null);try{w(Y(await se()))}catch(O){w({tone:"error",text:oe(l,O)})}finally{f(null),$()}}},H=(V,se)=>z(V==="temporary"?"temporary":"persistent",()=>Js(p).enable(Dp(V,se??Mp)),()=>(A(!1),{tone:"success",text:o("st.web.opened")})),U=()=>{E!==void 0&&H(E.mode??"persistent",k)},X=(V,se)=>{I(!0),R(Y=>se?Y.includes(V)?Y:[...Y,V]:Y.filter(O=>O!==V))},q=()=>{if(p===null)return;const V=new Set(M.map(Y=>Y.id)),se=P.filter(Y=>V.size===0||V.has(Y));z("shared",()=>Js(p).setSharedConnections(se),Y=>(R(Y.sharedConnectionIds??[]),I(!1),{tone:"success",text:o("st.web.sharedSaved")}))},F=()=>{p!==null&&(f("link"),w(null),Js(p).issueLink().then(V=>{_(V),w({tone:"success",text:o("st.web.linkIssued")})}).catch(V=>{w({tone:"error",text:oe(l,V)})}).finally(()=>{f(null),$()}))};return d?e.jsx(c5,{client:p}):e.jsxs(Me,{id:"st-card-web-access",title:o("st.web.title"),scope:"server",aside:o("st.web.hint"),children:[e.jsxs("div",{className:"space-y-3","data-web-access":!0,children:[p===null?e.jsx(he,{children:o("st.remote.controlUnavailable")}):null,h.isError?ja(h.error)?e.jsx(he,{children:o("st.remote.controlUnavailable")}):e.jsx(De,{error:h.error}):null,E!==void 0?E.enabled?e.jsx(u5,{state:E,busy:m,details:C,onToggleDetails:()=>{S(V=>!V)},onNewLink:F,onTurnOff:()=>{v({kind:"off"})},onRevoke:V=>{v({kind:"revoke",id:V.id,label:V.label})},onRevokeAll:()=>{v({kind:"revokeAll"})},address:e.jsx(Rh,{open:C,onToggle:()=>{S(V=>!V)},state:E,draft:k,onDraft:V=>{j(V),A(!0)},onApply:U,applying:m!==null})}):e.jsx(p5,{mode:E.mode,busy:m==="temporary"||m==="persistent",onEnable:V=>{H(V)},onToggleDetails:()=>{S(V=>!V)},details:C,state:E,address:e.jsx(Rh,{open:C,onToggle:()=>{S(V=>!V)},state:E,draft:k,onDraft:V=>{j(V),A(!0)},onApply:U,applying:m!==null})}):h.isLoading?e.jsx(he,{children:o("st.spaces.loading")}):null,E!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(h5,{records:M,selectedIds:P,savedIds:E.sharedConnectionIds??[],busy:m!==null,saving:m==="shared",onToggle:X,onSave:q}),e.jsx("div",{"data-web-access-powers":!0,children:e.jsx(he,{children:o("st.web.powers")})})]}):null,e.jsx(pe,{feedback:y})]}),N!==null?e.jsx(f5,{link:N,onClose:()=>{_(null)}}):null,g?.kind==="off"&&p!==null?(()=>{const V=E;return v(null),z("off",()=>Js(p).disable(),()=>({tone:"success",text:o("st.web.turnedOff")})).then(()=>{if(V===void 0)return;const se=V.mode??"persistent",Y=Op(V);xs({text:o("st.web.turnedOff"),undoFailedText:o("toast.undoFailed"),undo:async()=>{await Js(p).enable(Dp(se,Y)),$()}})}),null})():null,g?.kind==="revoke"&&p!==null?e.jsx(Xe,{open:!0,overlayId:"web-access-revoke-confirm",tone:"danger",title:o("st.web.revokeTitle",{name:g.label}),body:o("st.web.revokeBody"),confirmLabel:o("st.web.revoke"),onCancel:()=>{v(null)},onConfirm:()=>{const V=g.id;v(null),z("revoke",()=>Js(p).revoke(V),()=>({tone:"success",text:o("st.web.revoked",{name:o("st.web.signedIn")})}))}}):null,g?.kind==="revokeAll"&&p!==null?e.jsx(Xe,{open:!0,overlayId:"web-access-revoke-all-confirm",tone:"danger",title:o("st.web.revokeAllTitle"),body:o("st.web.revokeAllBody"),confirmLabel:o("st.web.revokeAll"),onCancel:()=>{v(null)},onConfirm:()=>{v(null),z("revoke",()=>Js(p).revoke(),()=>({tone:"success",text:o("st.web.revokeAllDone")}))}}):null]})}function u5({state:t,busy:s,onNewLink:n,onTurnOff:a,onRevoke:i,onRevokeAll:r,address:o}){const{t:l,locale:c}=D(),[d,u]=x.useState(!1),p=t.mode==="temporary"&&t.expiresAt!==null;return e.jsxs("div",{className:"space-y-2.5","data-web-access-open":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[13px] text-ink","data-web-access-status":t.mode,children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-success"}),t.mode==="temporary"?l("st.web.temporary"):l("st.web.persistent"),p?e.jsxs("span",{className:"text-ink-faint",children:["· ",l("st.web.expires",{duration:Bd(new Date(t.expiresAt).toISOString(),c)})]}):null]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button","data-web-access-new-link":!0,className:Q,disabled:s!==null,onClick:n,children:[e.jsx(de,{name:"copy",size:12,className:"mr-1 inline-block align-[-1px]"}),l(s==="link"?"st.web.issuing":"st.web.newLink")]}),t.url!==null?e.jsxs(oa,{"data-web-access-open-link":!0,href:t.url,onOpenFailed:()=>{u(!0)},className:`${Q} no-underline`,children:[e.jsx(de,{name:"external",size:12,className:"mr-1 inline-block align-[-1px]"}),l("st.web.openHere")]}):null,e.jsx("button",{type:"button","data-web-access-off":!0,className:Q,disabled:s!==null,onClick:a,children:l(s==="off"?"st.web.turningOff":"st.web.turnOff")})]})]}),t.insecure?e.jsx("p",{className:"text-[12px] leading-snug text-amber-ink","data-web-access-insecure":!0,children:l("st.web.insecureLive")}):null,d&&t.url!==null?e.jsxs("p",{role:"alert","data-web-access-open-failed":!0,className:"text-[12px] leading-snug text-danger",children:[l("st.web.openFailed")," ",e.jsx("span",{className:"font-mono text-[11px] break-all",children:t.url})]}):null,o,e.jsx(m5,{state:t,onRevoke:i,onRevokeAll:r,busy:s})]})}function p5({state:t,busy:s,onEnable:n,address:a}){const{t:i}=D();return e.jsxs("div",{className:"space-y-2.5","data-web-access-closed":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("p",{className:"text-[13px] text-ink","data-web-access-status":"off",children:i("st.web.off")}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button","data-web-access-start-temporary":!0,className:Q,disabled:s,onClick:()=>{n("temporary")},children:i("st.web.startTemporary")}),e.jsx("button",{type:"button","data-web-access-start-persistent":!0,className:Ye,disabled:s,onClick:()=>{n("persistent")},children:i("st.web.startPersistent")})]})]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-web-access-mode-hint":!0,children:i(t.mode==="persistent"?"st.web.modePersistent":"st.web.modeTemporary")}),a]})}function Rh({open:t,onToggle:s,state:n,draft:a,onDraft:i,onApply:r,applying:o}){const{t:l}=D(),c=_w(n),d=Ew(a),u=d===null?null:l(d),p=Tw(a)||a.publicUrl.trim()!==""&&a.publicUrl.trim().toLowerCase().startsWith("http://"),h=b=>{i({...a,...b})};return e.jsxs("div",{children:[e.jsxs("button",{type:"button","data-web-access-details-toggle":!0,"aria-expanded":t,"aria-controls":"web-access-details",onClick:s,className:"inline-flex items-center gap-1.5 rounded-md py-1 text-[12px] text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsx(Rt,{open:t,className:"text-current"}),l(t?"st.web.hideDetails":"st.web.showDetails")]}),e.jsxs("div",{id:"web-access-details",hidden:!t,className:"space-y-3 pt-2",children:[c===null?e.jsx(he,{children:l("st.web.addressPending")}):e.jsx(qb,{id:"web-access-address",dataAttr:"web-access-address",label:l("st.web.reachableHere"),value:c,copyLabel:l("st.web.linkCopy"),copiedLabel:l("st.web.linkCopied"),hint:l("st.web.addressHint")}),n.insecure?e.jsx("p",{className:"text-[12px] leading-snug text-amber-ink","data-web-access-insecure-hint":!0,children:l("st.web.insecureHint")}):null,e.jsxs("div",{className:"space-y-2.5 pt-3","data-web-access-address-form":!0,children:[e.jsx(ge,{label:l("st.web.hostField"),htmlFor:"web-access-host",layout:"stack",help:l("st.web.hostHint"),children:e.jsx("input",{id:"web-access-host","data-web-access-host":!0,className:Ce,inputMode:"url",spellCheck:!1,placeholder:l("st.web.hostPlaceholder"),value:a.host,onChange:b=>{h({host:b.target.value})}})}),e.jsx(ge,{label:l("st.web.portField"),htmlFor:"web-access-port",layout:"stack",children:e.jsx("input",{id:"web-access-port","data-web-access-port":!0,className:Ce,inputMode:"numeric",spellCheck:!1,placeholder:l("st.web.portPlaceholder"),value:a.port,onChange:b=>{h({port:b.target.value})}})}),e.jsx(ge,{label:l("st.web.publicUrlField"),htmlFor:"web-access-public-url",layout:"stack",help:l("st.web.publicUrlHint"),children:e.jsx("input",{id:"web-access-public-url","data-web-access-public-url":!0,className:Ce,spellCheck:!1,placeholder:l("st.web.publicUrlPlaceholder"),value:a.publicUrl,onChange:b=>{h({publicUrl:b.target.value})}})}),p?e.jsxs("div",{"data-web-access-insecure-option":!0,children:[e.jsx(Be,{id:"web-access-insecure",layout:"row",label:l("st.web.insecureNoTls"),checked:a.insecureNoTls,onChange:b=>{h({insecureNoTls:b})}}),e.jsx("p",{className:"mt-1 max-w-[62ch] text-[12px] leading-snug text-amber-ink",children:l("st.web.insecureHint")})]}):null,u!==null?e.jsx("p",{className:"text-[12px] text-danger",role:"alert","data-web-access-address-problem":!0,children:u}):null,e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx("button",{type:"button","data-web-access-apply-address":!0,className:Q,disabled:!n.enabled||o||d!==null,onClick:r,children:l(o?"st.web.enabling":"st.web.applyAddress")})})]})]})]})}function m5({state:t,onRevoke:s,onRevokeAll:n,busy:a}){const{t:i,locale:r}=D(),o=t.sessions;return e.jsxs("div",{className:"pt-1","data-web-access-browsers":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("p",{className:"text-[12.5px] font-medium text-ink",children:i("st.web.signedIn")}),o.length>0?e.jsx("button",{type:"button","data-web-access-revoke-all":!0,className:"text-[12px] text-ink-soft underline decoration-dotted underline-offset-2 transition-colors hover:text-ink",disabled:a!==null,onClick:n,children:i("st.web.revokeAll")}):null]}),o.length===0?e.jsx("p",{className:"mt-1 text-[12px] text-ink-faint","data-web-access-browsers-empty":!0,children:i("st.web.signedInNone")}):e.jsx("div",{role:"list","aria-label":i("st.web.signedIn"),className:"mt-1.5 space-y-1",children:o.map(l=>e.jsxs("div",{role:"listitem","data-web-access-session":l.id,className:"flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md bg-ink/[0.03] px-2.5 py-1.5",children:[e.jsx(de,{name:"web",size:12,className:"shrink-0 text-ink-faint"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[12.5px] text-ink",title:l.label,children:l.label}),e.jsx("p",{className:"text-[11.5px] text-ink-faint",children:i("st.web.lastUsed",{time:Nn(new Date(l.lastUsedAt).toISOString(),r)})})]}),e.jsx("button",{type:"button","data-web-access-revoke":l.id,className:Q,disabled:a!==null,onClick:()=>{s(l)},children:i("st.web.revoke")})]},l.id))})]})}function x5(t,s){if(t.length!==s.length)return!1;const n=new Set(s);return t.every(a=>n.has(a))}function h5({records:t,selectedIds:s,savedIds:n,busy:a,saving:i,onToggle:r,onSave:o}){const{t:l}=D(),c=!x5(s,n);return e.jsxs("div",{className:"space-y-2 pt-1","data-web-access-shared-connections":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[12.5px] font-medium text-ink",children:l("st.web.sharedTitle")}),e.jsx("p",{className:"mt-0.5 max-w-[62ch] text-[12px] leading-snug text-ink-faint",children:l("st.web.sharedHint")})]}),t.length>0||n.length>0?e.jsx("button",{type:"button","data-web-access-save-shared":!0,className:Q,disabled:a||!c,onClick:o,children:l(i?"st.web.sharedSaving":"st.web.sharedSave")}):null]}),t.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint","data-web-access-shared-empty":!0,children:l("st.web.sharedEmpty")}):e.jsx("div",{role:"list","aria-label":l("st.web.sharedTitle"),className:"space-y-1",children:t.map(d=>{const u=s.includes(d.id);return e.jsxs("label",{role:"listitem","data-web-access-shared-row":d.id,className:"flex cursor-pointer flex-wrap items-center gap-x-3 gap-y-1 rounded-md bg-ink/[0.03] px-2.5 py-1.5 transition-colors hover:bg-ink/[0.05]",children:[e.jsx("input",{type:"checkbox","data-web-access-share-connection":d.id,checked:u,disabled:a,onChange:p=>{r(d.id,p.target.checked)},className:"h-3.5 w-3.5 shrink-0 rounded border-hairline-strong accent-accent"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 truncate text-[12.5px] font-medium text-ink",title:d.label,children:d.label}),e.jsx(Md,{state:d.state,className:"text-[11px]"})]}),e.jsx("p",{className:"truncate font-mono text-[11px] text-ink-faint",title:d.endpoint,children:ho(d.endpoint)})]})]},d.id)})})]})}function f5({link:t,onClose:s}){const{t:n,locale:a}=D(),i=x.useRef(t.expiresAt);return e.jsx(Ea,{onClose:s,overlayId:"web-access-link-dialog",ariaLabel:n("st.web.linkTitle"),panelClassName:`${bo} ${go.md} max-h-[calc(100dvh-2rem)] overflow-y-auto`,children:e.jsxs("div",{className:"space-y-4","data-web-access-link":!0,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[14px] font-medium text-ink",children:n("st.web.linkTitle")}),e.jsx("p",{className:"mt-1 max-w-[62ch] text-[12.5px] leading-snug text-ink-soft",children:n("st.web.linkBody")})]}),e.jsx(qb,{id:"web-access-link-value",dataAttr:"web-access-link",label:n("st.web.linkLabel"),value:t.url,copyLabel:n("st.web.linkCopy"),copiedLabel:n("st.web.linkCopied"),hint:n("st.web.linkOnce")}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-web-access-link-done":!0,className:Ye,onClick:s,children:n("st.web.linkDone")})}),e.jsx("p",{className:"text-[11.5px] text-ink-faint","data-web-access-link-expires":!0,children:n("st.web.linkExpires",{duration:Bd(new Date(i.current).toISOString(),a)})})]})})}function ec(){const{t}=D(),s=Tt(),{pathname:n,search:a}=Bt(),i=Pw(new URLSearchParams(a).get("tab"))??ob,r=x.useRef(null),o=(c,d=!1)=>{if(d&&r.current?.querySelector(`[data-access-tab="${c}"]`)?.focus(),c===i)return;const u=new URLSearchParams(a);u.set("tab",c),s(`${n}?${u.toString()}`)},l=(c,d)=>{const u=Xo.length-1,p=c.key==="ArrowRight"?d===u?0:d+1:c.key==="ArrowLeft"?d===0?u:d-1:c.key==="Home"?0:c.key==="End"?u:null;p!==null&&(c.preventDefault(),o(Xo[p],!0))};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{ref:r,role:"tablist","aria-label":t("st.section.externalAccess"),className:"flex flex-wrap gap-1 border-b border-hairline",children:Xo.map((c,d)=>{const u=c===i;return e.jsx("button",{id:`access-tab-${c}`,type:"button",role:"tab","aria-selected":u,"aria-controls":"access-tab-panel",tabIndex:u?0:-1,"data-access-tab":c,onClick:()=>{o(c)},onKeyDown:p=>{l(p,d)},className:`-mb-px min-h-9 border-b-2 px-3 py-1.5 text-[13px] transition-colors outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:min-h-11 ${u?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:t(Aw(c))},c)})}),e.jsx("div",{id:"access-tab-panel",role:"tabpanel","aria-labelledby":`access-tab-${i}`,"data-access-panel":i,className:"space-y-6",children:i==="kiki"?e.jsx(l5,{}):i==="clients"?e.jsx(JR,{}):e.jsxs(e.Fragment,{children:[e.jsx(d5,{}),e.jsx(e5,{})]})})]})}function b5(){const{t}=D(),s=Et();return e.jsx(Me,{id:"st-card-settings-transfer",title:t("st.settingsTransfer.title"),scope:"app",children:e.jsx(Ze,{children:e.jsx(ge,{label:t("st.portable.title"),help:t("st.settingsTransfer.description"),children:e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5`,"data-settings-transfer-open":!0,onClick:()=>{s("/settings/subscriptions#st-card-portable-spaces")},children:[e.jsx("span",{children:t("st.settingsTransfer.openSpaces")}),e.jsx(de,{name:"arrowRight",size:12})]})})})})}function g5(){const t=mt(),{t:s,locale:n,setLocale:a}=D(),i=Hd()?.connectionId,r=typeof i=="string"&&i!=="",o=x.useSyncExternalStore(io,ro,oo),[l,c]=x.useState(ss),[d,u]=x.useState(!1),p=t.kind==="tauri",h=tu(),b=So();x.useEffect(()=>{t.kind==="tauri"&&t.readDesktopPrefs().then(f=>{f!==null&&(c(f),Fs(f))})},[t]);const m=f=>{const g={...l,...f};c(g),Fs(g),t.kind==="tauri"&&t.writeDesktopPrefs(g)};return e.jsxs(e.Fragment,{children:[e.jsx(Me,{id:"st-card-language",title:s("st.language.regionTitle"),children:e.jsx(Ze,{children:e.jsx(ge,{label:s("st.language.title"),labelId:"language-label",children:e.jsx(He,{ariaLabelledBy:"language-label",dataAttr:"data-locale-choice",value:n,onChange:a,choices:[{value:"en",label:"English"},{value:"zh",label:"中文"}]})})})}),e.jsx(Me,{id:"st-card-composer",title:s("st.composer.title"),scope:"app",children:e.jsxs(Ze,{children:[h?null:e.jsx(ge,{label:s("st.composer.sendShortcut"),labelId:"send-shortcut-label",help:e.jsx("span",{"data-send-shortcut-help":o.sendShortcut,children:s(o.sendShortcut==="cmd-enter"?"st.composer.shortcutCmdEnterHint":"st.composer.shortcutEnterHint")}),children:e.jsx(Qe,{id:"send-shortcut-select",ariaLabel:s("st.composer.sendShortcut"),value:o.sendShortcut,onChange:f=>{Mt({sendShortcut:f})},choices:[{value:"enter",label:s("st.composer.shortcutEnter")},{value:"cmd-enter",label:s("st.composer.shortcutCmdEnter")}]})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(P2,{}),e.jsx(Xs,{item:"defaultAppendTiming",label:s("st.communication.appendTimingTitle")})]}),e.jsxs(ge,{label:s("st.composer.persistDrafts"),help:s("st.composer.persistDraftsHint"),children:[e.jsx("button",{type:"button",className:Q,"data-composer-clear-drafts":!0,onClick:()=>u(!0),children:s("st.composer.clearDrafts")}),e.jsx(Be,{layout:"bare",label:s("st.composer.persistDrafts"),checked:o.draftPersistence,onChange:f=>{Mt({draftPersistence:f})}})]})]})}),e.jsx(Me,{id:"st-card-ui-behavior",title:s("st.uiBehavior.title"),scope:"app",children:e.jsxs(Ze,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(ge,{label:s("st.transcript.foldSteps"),help:s("st.transcript.foldStepsHint"),children:e.jsx(Be,{layout:"bare",label:s("st.transcript.foldSteps"),checked:o.foldSteps,onChange:f=>{Mt({foldSteps:f})}})}),e.jsx(Xs,{item:"foldSteps",label:s("st.transcript.foldSteps")})]}),e.jsx("div",{"data-setting-rail-open":!0,children:e.jsx(ge,{label:s("st.layout.railOpenByDefault"),help:s("st.layout.railOpenByDefaultHint"),children:e.jsx(Be,{layout:"bare",label:s("st.layout.railOpenByDefault"),checked:o.railOpenByDefault,onChange:f=>{Mt({railOpenByDefault:f}),$w({railOpen:f})}})})}),b?e.jsx("div",{"data-setting-phone-terminal":!0,children:e.jsx(ge,{label:s("st.layout.phoneTerminal"),help:s("st.layout.phoneTerminalHint"),children:e.jsx(Be,{layout:"bare",label:s("st.layout.phoneTerminal"),checked:o.showTerminalOnPhone,onChange:f=>{Mt({showTerminalOnPhone:f})}})})}):null,e.jsxs("div",{"data-setting-worktree-confirm":!0,className:"space-y-1",children:[e.jsx(ge,{label:s("st.composer.worktreeConfirm"),help:s("st.composer.worktreeConfirmHint"),children:e.jsx(Be,{layout:"bare",label:s("st.composer.worktreeConfirm"),checked:!o.worktreeSkipConfirm,onChange:f=>{Mt({worktreeSkipConfirm:!f})}})}),e.jsx(Xs,{item:"worktreeSkipConfirm",label:s("st.composer.worktreeConfirm")})]})]})}),p?e.jsx(Me,{id:"st-card-desktop",title:s("st.desktop.title"),effect:"desktop",scope:"app",children:e.jsx(Ze,{children:e.jsx(ge,{label:s("st.desktop.closeQuestion"),labelId:"desktop-close-label",help:s(l.closeToTray?"st.desktop.trayDesc":"st.desktop.quitDesc"),children:e.jsx(He,{ariaLabelledBy:"desktop-close-label",dataAttr:"data-desktop-close-choice",value:l.closeToTray?"tray":"quit",onChange:f=>{m({closeToTray:f==="tray"})},choices:[{value:"tray",label:s("st.desktop.tray")},{value:"quit",label:s("st.desktop.quit")}]})})})}):null,r?null:e.jsx(b5,{}),d?e.jsx(Xe,{open:!0,overlayId:"confirm-clear-drafts",title:s("st.composer.clearDraftsConfirmTitle"),body:s("st.composer.clearDraftsConfirmBody"),confirmLabel:s("st.composer.clearDrafts"),tone:"danger",onCancel:()=>{u(!1)},onConfirm:()=>{D1(),u(!1)}}):null]})}const v5={muted:"text-ink-soft",ok:"text-ink",caution:"text-amber-ink",danger:"text-danger"};function y5({workspaceId:t,config:s}){const{client:n}=be(),{t:a,locale:i}=D(),r=je({queryKey:["memory-advisor-runtime-sessions",t??null],queryFn:()=>n.listSessions({workspace_id:t,page_size:20,exclude_empty:!0}),staleTime:15e3}),o=r.data?.items??[],[l,c]=x.useState(),d=o.some(g=>g.id===l)?l:o[0]?.id,[u,p]=x.useState("main"),h=Ks({mutationFn:async g=>({...g,status:await n.getMemoryAdvisorStatus(g.sessionId,g.agentId),at:new Date().toISOString()})}),b=u.trim()===""?"main":u.trim(),m=h.data!==void 0&&h.data.sessionId===d&&h.data.agentId===b?h.data:void 0,f=h.isError&&h.variables?.sessionId===d&&h.variables.agentId===b?h.error:void 0;return e.jsxs("div",{"data-memory-advisor-runtime":!0,className:"space-y-1 pt-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:a("memory.advisor.runtime")}),e.jsx(he,{children:a("memory.advisor.runtimeHint")}),r.isError&&o.length===0?e.jsxs("p",{"data-memory-advisor-runtime-sessions-error":!0,className:"flex flex-wrap items-center gap-x-2 py-1 text-[12px] text-danger",children:[e.jsx("span",{children:oe(i,r.error)}),e.jsx("button",{type:"button","data-memory-advisor-runtime-sessions-retry":!0,className:Ot,onClick:()=>{r.refetch()},children:a("common.retry")})]}):o.length===0&&!r.isPending?e.jsx("p",{"data-memory-advisor-runtime-empty":!0,className:"py-1 text-[12px] text-ink-faint",children:a("memory.advisor.runtimeNoSessions")}):d!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(ge,{label:a("memory.advisor.runtimeSession"),children:e.jsx(Qe,{id:"memory-advisor-runtime-session",dataAttr:"data-memory-advisor-runtime-session",ariaLabel:a("memory.advisor.runtimeSession"),className:"max-w-64",value:d,onChange:c,choices:o.map(g=>({value:g.id,label:g.title.trim()===""?a("sidebar.untitled"):g.title,hint:g.busy?a("memory.advisor.runtimeBusy"):void 0}))})}),e.jsxs(ge,{label:a("memory.advisor.runtimeAgent"),htmlFor:"memory-advisor-runtime-agent",children:[e.jsx("input",{id:"memory-advisor-runtime-agent","data-memory-advisor-runtime-agent":!0,className:"h-8 w-28 rounded-md border border-hairline bg-paper px-3 font-mono text-[12px] text-ink outline-none transition-colors hover:border-hairline-strong focus:border-selected-ink",value:u,spellCheck:!1,autoComplete:"off",onChange:g=>{p(g.target.value)}}),e.jsx("button",{type:"button","data-memory-advisor-runtime-read":!0,className:Q,disabled:h.isPending,onClick:()=>{h.mutate({sessionId:d,agentId:b})},children:h.isPending?a("memory.advisor.runtimeReading"):a("memory.advisor.runtimeRead")})]})]}):null,f!==void 0?e.jsx(pe,{feedback:{tone:"error",text:a("memory.advisor.runtimeFailed",{detail:oe(i,f)})}}):null,m!==void 0?e.jsx(k5,{read:m,config:s}):null]})}function k5({read:t,config:s}){const{t:n}=D(),a=t.status;if(a===null)return e.jsx("p",{"data-memory-advisor-runtime-result":"none",role:"status",className:"py-1 text-[12px] leading-snug text-ink-soft",children:n("memory.advisor.runtimeNone")});const i=Rw(s,a),r=Ed(a.reason),o=[[n("memory.advisor.runtimeCalls"),a.logical_calls],[n("memory.advisor.runtimeRequests"),a.requests],[n("memory.advisor.runtimeRetries"),a.retries],[n("memory.advisor.runtimeRecommended"),a.recommended_count??0],[n("memory.advisor.runtimeDisplaced"),a.displaced_ids.length],[n("memory.advisor.runtimeUnjudged"),a.unjudged_count]];return a.enumeration!==void 0&&o.push([n("memory.advisor.runtimeCoverage"),n(`memory.advisor.coverage.${a.enumeration}`)]),e.jsxs("div",{"data-memory-advisor-runtime-result":a.state,role:"status",className:"space-y-1.5 pt-1",children:[e.jsxs("p",{className:`text-[13px] ${v5[i.tone]}`,children:[n(`memory.advisor.state.${a.state}`),r!==void 0?e.jsx("span",{"data-memory-advisor-runtime-reason":!0,className:"ml-2 text-[12px]",children:n(r)}):null]}),e.jsx("dl",{className:"grid max-w-md grid-cols-2 gap-x-6 gap-y-1 text-[12px] sm:grid-cols-3",children:o.map(([l,c])=>e.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-2",children:[e.jsx("dt",{className:"truncate text-ink-faint",children:l}),e.jsx("dd",{className:"font-mono tabular-nums text-ink",children:c})]},l))}),e.jsxs("p",{className:"text-[11px] text-ink-faint",children:[n("memory.advisor.runtimeReadAt")," ",e.jsx(F1,{at:t.at})]})]})}const j5={first_step_wait_ms:"ms",timeout_ms:"ms",max_calls_per_turn:void 0,max_full_units:void 0,judge_input_tokens:"tokens",candidate_chars:"chars",catalog_page_items:void 0,max_catalog_pages:void 0};function w5({workspaceId:t,advisor:s}){const{t:n}=D(),[a,i]=Je(),[r,o]=x.useState(),l=s.data?.advisor,c=s.data?.advisor_status,d=c?.destination,u=(m,f)=>{s.save.isPending||(o(m),s.save.mutateAsync(f).then(()=>{i()},()=>{}))},p=m=>r===m?e.jsx(ot,{saving:s.save.isPending,saved:a&&!s.save.isError}):null,h=s.query.isPending||s.save.isPending,b=(c?.source_status?.protocol??l?.selector?.protocol)==="pair_score";return e.jsxs("div",{className:"min-w-0 space-y-1 text-[13px] text-ink","data-memory-advisor-tuning":!0,children:[e.jsxs(ge,{label:n("memory.advisor.mode"),labelId:"memory-advisor-mode-label",help:n(l?.mode==="select"?"memory.advisor.modeHint.select":"memory.advisor.modeHint.rank"),children:[p("mode"),e.jsx(He,{ariaLabelledBy:"memory-advisor-mode-label",dataAttr:"data-memory-advisor-mode",value:l?.mode==="select"?"select":"rank",disabled:h,onChange:m=>{u("mode",{advisor:{mode:m}})},choices:[{value:"rank",label:n("memory.advisor.mode.rank")},{value:"select",label:n("memory.advisor.mode.select"),disabled:b}]})]}),e.jsxs(ge,{label:n("memory.advisor.children"),htmlFor:"memory-advisor-children",help:n("memory.advisor.childrenHint"),children:[p("children"),e.jsx(Be,{id:"memory-advisor-children",layout:"bare",label:n("memory.advisor.children"),checked:l?.apply_to_children??Lw.apply_to_children,disabled:h,onChange:m=>{u("children",{advisor:{apply_to_children:m}})}})]}),Mw.map(m=>{const f=Ow[m],g=j5[m],v=Dw(m,l,c),y=m==="first_step_wait_ms";return e.jsxs(ge,{label:n(`memory.advisor.field.${m}`),htmlFor:`memory-advisor-${m}`,detail:n("memory.advisor.fieldDefault",{value:v.fallback}),children:[p(m),y&&!v.explicit?e.jsx("span",{"data-memory-advisor-wait-default":!0,className:"text-[12px] text-ink-faint",children:n("agentPanel.default")}):null,y&&v.explicit&&l!==void 0?e.jsx("button",{type:"button","data-memory-advisor-wait-reset":!0,disabled:h,className:"text-[12px] font-medium text-ink-soft underline-offset-2 hover:text-ink hover:underline disabled:cursor-not-allowed disabled:opacity-50",onClick:()=>{u(m,{advisor:{first_step_wait_ms:null}})},children:n("composer.modelResetDefault")}):null,e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{id:`memory-advisor-${m}`,dataAttr:`data-memory-advisor-${m.replaceAll("_","-")}`,className:"w-24 text-right",inputMode:"numeric",disabled:h,value:String(v.value),validate:w=>Fw(m,w)===null?n("memory.advisor.fieldInvalid",{min:f.min,max:f.max}):null,onCommit:w=>{u(m,{advisor:{[m]:Number(w)}})}}),g!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:n(`st.residency.${g==="ms"?"msUnit":g==="tokens"?"tokensUnit":"charsUnit"}`)}):null]})]},m)}),d!==void 0?e.jsxs("dl",{"data-memory-advisor-destination-row":!0,className:"grid grid-cols-[auto_1fr] items-baseline gap-x-4 py-1 text-[13px]",children:[e.jsx("dt",{className:"text-ink-soft",children:n("memory.advisor.destination")}),e.jsx("dd",{"data-memory-advisor-destination":!0,className:"min-w-0 break-all font-mono text-[12px] text-ink",children:d})]}):null,e.jsx(y5,{workspaceId:t,config:l})]})}const N5="text-[12px] text-ink-faint transition-colors hover:text-danger hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50 disabled:no-underline";function S5(){const{client:t}=be(),{t:s,locale:n}=D(),[a]=no(),i=a.get("workspace")??void 0,r=Ib(i),[o,l]=Je(),[c,d]=x.useState(),u=r.data,p=u?.advisor,h=u?.advisor_status,b=r.view,m=(A,P)=>r.save.isPending?Promise.resolve(!1):(d(A),r.save.mutateAsync(P).then(()=>(l(),!0),()=>!1)),f=A=>c===A?e.jsx(ot,{saving:r.save.isPending,saved:o&&!r.save.isError}):null,g=r.query.isPending||r.save.isPending,v=Ks({mutationFn:A=>t.probeMemoryAdvisor(A)}),y=h?.source_status?.model??h?.model,w=h?.source_status?.protocol??h?.protocol??p?.selector?.protocol;x.useEffect(()=>{v.reset()},[h?.destination,y,w,p?.mode]);const N=h?.destination,_=u?.effective_enabled!==!1&&u?.budget===0,C=!_&&(h?.state==="disabled"||u?.effective_enabled===!1),S=_&&b.kind==="problem"&&h?.state==="disabled"?s("memory.advisor.state.budgetZero"):s(b.stateKey),k=Ed(h?.reason),j=r.query.isError?{tone:"error",text:s("memory.advisor.loadFailed",{detail:oe(n,r.query.error)})}:r.save.isError?{tone:"error",text:s("memory.advisor.saveFailed",{detail:oe(n,r.save.error)})}:null,T=b.tone==="ok"?"ok":b.tone==="danger"?"error":b.tone==="caution"?"waiting":"off";return e.jsx(Me,{id:"st-card-memory-advisor",title:s("memory.advisor.title"),actions:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[f("switch"),e.jsx(Be,{id:"memory-advisor-enabled",layout:"bare",label:s("memory.advisor.switch"),checked:b.on,disabled:g,onChange:A=>{m("switch",qw(A,p))}})]}),children:e.jsxs("div",{className:"min-w-0 space-y-5","data-memory-advisor-settings":!0,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{"data-memory-advisor-status":b.kind,role:"status",className:"flex items-center gap-2 text-[13px] text-ink",children:[T==="off"?null:e.jsx("span",{"aria-hidden":!0,className:"inline-flex",children:e.jsx(JN,{state:T,label:""})}),e.jsx("span",{children:S})]}),C?e.jsx("p",{"data-memory-advisor-memory-off":!0,className:"max-w-[62ch] text-[12px] leading-snug text-amber-ink",children:s("memory.advisor.memoryOff")}):_?e.jsx("p",{"data-memory-advisor-budget-zero":!0,className:"max-w-[62ch] text-[12px] leading-snug text-amber-ink",children:s("memory.advisor.budgetZero")}):b.kind==="problem"&&k!==void 0?e.jsx("p",{"data-memory-advisor-reason":!0,className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:s(k)}):e.jsx(he,{children:s("memory.advisor.switchHint")})]}),e.jsx(is,{title:s("memory.advisor.selectorGroup"),children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(pu,{consumer:"memory",scope:"card",label:s("st.decision.row.memory"),help:s("st.decision.sourceHint"),unset:s("st.decision.row.memoryUnset"),source:p?.source,status:h?.source_status,legacy:p?.source===void 0&&p?.selector!==void 0?s("st.decision.row.memoryLegacy",{model:p.selector.model}):void 0,loading:r.query.isPending,error:r.query.error,retry:()=>{r.query.refetch()},write:async A=>{await r.save.mutateAsync({advisor:A===null&&p?.selector!==void 0?{source:A,selector:null}:{source:A}})}}),N!==void 0||p!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1",children:[N!==void 0?e.jsx("button",{type:"button","data-memory-advisor-test":!0,className:Ot,disabled:v.isPending,onClick:()=>{v.mutate(N)},children:v.isPending?s("memory.advisor.testing"):s("memory.advisor.test")}):null,p!==void 0?e.jsx("button",{type:"button","data-memory-advisor-remove":!0,className:N5,disabled:g,onClick:()=>{const A=p;m("remove",{advisor:null}).then(P=>{P&&xs({text:s("memory.advisor.removedUndo"),undoFailedText:s("toast.undoFailed"),undo:async()=>{await r.save.mutateAsync({advisor:A})}})})},children:s("memory.advisor.remove")}):null]}):null,e.jsx(C5,{result:v.data,error:v.error,pending:v.isPending})]})}),e.jsx(et,{summary:s("memory.advisor.advanced"),"data-memory-advisor-advanced":!0,children:e.jsx(w5,{workspaceId:i,advisor:r})}),e.jsx(pe,{feedback:j})]})})}function C5({result:t,error:s,pending:n}){const{t:a,locale:i}=D(),r=Ed(t?.status.reason),o=n?null:s!=null?{tone:"error",text:a("memory.advisor.testFailed",{reason:oe(i,s)})}:t===void 0?null:t.ok?{tone:"success",text:[a("memory.advisor.testOk",{ms:Math.round(t.duration_ms)}),t.usage_known&&t.input_tokens!==void 0?a("memory.advisor.testTokens",{input:t.input_tokens,output:t.output_tokens??0}):""].filter(l=>l!=="").join(" ")}:{tone:"error",text:a("memory.advisor.testFailed",{reason:a(r===void 0?`memory.advisor.state.${t.status.state}`:r)})};return e.jsx("div",{"data-memory-advisor-probe":!0,children:e.jsx(pe,{feedback:o})})}const od=["memory-settings"],_5=["memory-workspace-settings"];function E5(){const{client:t}=be(),{t:s,locale:n}=D(),a=Tt(),i=Oe(),[r,o]=Je(),[l,c]=x.useState(),d=je({queryKey:od,queryFn:()=>t.getMemorySettings(),staleTime:15e3}),u=je({queryKey:["config","memory-default"],queryFn:()=>t.getConfig(),enabled:typeof t.getConfig=="function",staleTime:3e4}),p=Ns(u.data,"memory"),h=Ks({mutationFn:v=>t.patchMemorySettings(v),onSuccess:async(v,y)=>{i.setQueryData(od,v),y.enabled!==void 0&&i.setQueryData(["config","memory-default"],w=>{const N=w?.optional_capabilities?.memory;return w?.optional_capabilities===void 0||N===void 0?w:{...w,optional_capabilities:{...w.optional_capabilities,memory:{...N,allowed:v.enabled}}}}),await Promise.all([i.invalidateQueries({queryKey:_5}),ZN(i)]),o()}}),b=h.variables===void 0?void 0:Object.keys(h.variables)[0],m=v=>b===v?e.jsx(ot,{saving:h.isPending,saved:r&&!h.isError}):null,f=d.isPending||h.isPending,g=d.isError?{tone:"error",text:s("st.memory.loadFailed",{detail:oe(n,d.error)})}:h.isError?{tone:"error",text:s("st.memory.saveFailed",{detail:oe(n,h.error)})}:l!==void 0?{tone:"error",text:s("st.memory.saveFailed",{detail:oe(n,l)})}:null;return e.jsx(Me,{id:"st-card-memory",title:s("st.memory.title"),actions:e.jsx("button",{type:"button","data-memory-settings-link":!0,className:Q,onClick:()=>{a("/memory")},children:s("st.memory.open")}),children:e.jsxs("div",{className:"min-w-0 space-y-2","data-memory-settings":!0,children:[e.jsxs(Ze,{children:[e.jsx("div",{children:e.jsxs(ge,{label:s("memory.toggle"),htmlFor:"memory-enabled",help:s("st.memory.hint"),children:[m("enabled"),e.jsx(Be,{id:"memory-enabled",layout:"bare",label:s("memory.toggle"),checked:p?.allowed??d.data?.enabled===!0,disabled:f||p?.host_locked===!0,onChange:v=>{h.mutate({enabled:v})}})]})}),e.jsxs(ge,{label:s("st.memory.approval"),labelId:"memory-approval-label",children:[m("approval"),e.jsx(Qe,{id:"memory-approval",dataAttr:"data-memory-approval",ariaLabel:s("st.memory.approval"),value:d.data?.approval??"auto",disabled:f,onChange:v=>{h.mutate({approval:v})},choices:[{value:"auto",label:s("st.memory.approval.auto"),hint:s("st.memory.approvalHint.auto")},{value:"review",label:s("st.memory.approval.review"),hint:s("st.memory.approvalHint.review")},{value:"off",label:s("st.memory.approval.off"),hint:s("st.memory.approvalHint.off")}]})]}),e.jsxs(et,{summary:s("st.memory.advanced"),"data-memory-advanced":!0,children:[e.jsx(_r,{id:"memory",state:p,disabled:f,labelKey:"cap.defaultOn.newWorkspaces",onChange:v=>{c(void 0),t.patchConfig({optional_capabilities:{defaults:{memory:v}}}).then(y=>{i.setQueryData(["config","memory-default"],y),o()}).catch(y=>{c(y)})}}),e.jsxs(ge,{label:s("st.memory.budget"),htmlFor:"memory-budget",help:s("st.memory.budgetHint"),children:[m("budget"),e.jsx(kt,{id:"memory-budget",dataAttr:"data-memory-budget",className:"w-24 text-right",inputMode:"numeric",value:d.data===void 0?"":String(d.data.budget),disabled:f,validate:v=>/^\d+$/.test(v)&&Number(v)<=4e3?null:s("st.memory.budgetInvalid"),onCommit:v=>{h.mutate({budget:Number(v)})}})]})]})]}),e.jsx(pe,{feedback:g})]})})}function T5(){const{client:t}=be(),{t:s,locale:n}=D(),a=je({queryKey:["workspaces","catalog"],queryFn:()=>t.listWorkspaceCatalog(),staleTime:3e4}),i=je({queryKey:od,queryFn:()=>t.getMemorySettings(),staleTime:15e3}),r=i.data===void 0?[]:Object.entries(i.data.workspaces).map(([l,c])=>({id:l,enabled:c,name:a.data?.items.find(d=>d.id===l)?.name??l})),o=a.isError||i.isError?{tone:"error",text:s("st.memory.loadFailed",{detail:oe(n,a.error??i.error)})}:null;return e.jsx(Me,{id:"st-card-memory-workspaces",title:s("st.memory.workspaces"),scope:"workspace",children:e.jsxs("div",{className:"space-y-2","data-memory-workspace-settings":!0,children:[e.jsx(he,{children:s("st.memory.workspaceExceptionsHint")}),i.isPending?e.jsx(he,{children:s("cap.loading")}):r.length===0?e.jsx("p",{"data-memory-exceptions-empty":!0,className:"text-[13px] text-ink-faint",children:s("st.memory.workspaceExceptionsEmpty")}):e.jsx("ul",{"data-memory-exceptions":!0,className:"divide-y divide-hairline rounded-lg border border-hairline bg-paper",children:r.map(l=>e.jsx("li",{children:e.jsxs(_t,{to:`${lb(l.id)}#st-card-workspace-memory`,"data-memory-exception-open":l.id,"aria-label":s("st.memory.workspaceExceptionOpen",{name:l.name}),className:"flex min-h-9 w-full items-center gap-2 px-3 py-1.5 text-left text-[13px] text-ink transition-colors hover:bg-ink/[0.03] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink pointer-coarse:min-h-11",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:l.name}),e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint",children:s(l.enabled?"memory.ws.on":"memory.ws.off")}),e.jsx(de,{name:"chevron",size:12,className:"shrink-0 text-ink-faint"})]})},l.id))}),e.jsx(pe,{feedback:o})]})})}function I5(){const{t}=D(),s=i_();if(s.kind==="migrating"){const n=s.state?.migration?.phase==="failed";return e.jsxs("div",{className:"space-y-2 py-2","data-memory-settings-upgrading":n?"failed":"running",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:t(n?"memory.upgrade.title.failed":"memory.upgrade.title.running")}),e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-5 text-ink-soft",children:t(n?"memory.upgrade.failedLead":"memory.upgrade.runningLead")}),e.jsx(_t,{to:"/memory",className:"inline-block text-[12.5px] text-selected-ink hover:underline","data-memory-settings-open-upgrade":!0,children:t("st.memory.openUpgrade")})]})}return e.jsxs("div",{className:"space-y-4",children:[e.jsx(E5,{}),e.jsx(S5,{}),e.jsx(T5,{})]})}const vs=["overview","search","fetch","advanced"];function P5(t){if(vs.includes(t))return t;if(t==="providers")return"search"}function Ty(t){return t.configured?t.available?"ready":"unavailable":"unconfigured"}function Iy(t){return t.configured?t.available?t.issues.length>0?"degraded":"ready":"unavailable":"unconfigured"}const Lh={"st-card-search-status":"overview","st-card-search-fetch":"fetch","st-card-search-providers":"search","st-card-search-source":"advanced","st-card-search-execution":"advanced","st-card-search-index":"advanced","st-card-search-diagnostics":"advanced","st-card-exp-search":"advanced"},A5={LOCAL_CONFIG_NOT_FOUND:"st.nbSearch.source.issue.LOCAL_CONFIG_NOT_FOUND",LOCAL_CONFIG_UNREADABLE:"st.nbSearch.source.issue.LOCAL_CONFIG_UNREADABLE",LOCAL_CONFIG_BUSY:"st.nbSearch.source.issue.LOCAL_CONFIG_BUSY",LOCAL_CONFIG_CHANGED:"st.nbSearch.source.issue.LOCAL_CONFIG_CHANGED",LOCAL_CONFIG_RESOLVER_MISMATCH:"st.nbSearch.source.issue.LOCAL_CONFIG_RESOLVER_MISMATCH",LOCAL_CREDENTIALS_INVALID:"st.nbSearch.source.issue.LOCAL_CREDENTIALS_INVALID",LOCAL_CREDENTIALS_UNREADABLE:"st.nbSearch.source.issue.LOCAL_CREDENTIALS_UNREADABLE",LOCAL_CREDENTIALS_TIMEOUT:"st.nbSearch.source.issue.LOCAL_CREDENTIALS_TIMEOUT",LOCAL_CREDENTIALS_UNSAFE:"st.nbSearch.source.issue.LOCAL_CREDENTIALS_UNSAFE",LOCAL_CREDENTIAL_CONFIG_OVERRIDE:"st.nbSearch.source.issue.LOCAL_CREDENTIAL_CONFIG_OVERRIDE",LOCAL_CREDENTIAL_BINDING_MISMATCH:"st.nbSearch.source.issue.LOCAL_CREDENTIAL_BINDING_MISMATCH",EFFECTIVE_CONFIG_INVALID:"st.nbSearch.source.issue.EFFECTIVE_CONFIG_INVALID",ISOLATED_STORAGE_UNAVAILABLE:"st.nbSearch.source.issue.ISOLATED_STORAGE_UNAVAILABLE",LOCAL_CONFIG_INVALID_IGNORED:"st.nbSearch.source.issue.LOCAL_CONFIG_INVALID_IGNORED"};function $5(t){return A5[t]}const R5={CREDENTIAL_NOT_CONFIGURED:"st.nbSearch.issue.CREDENTIAL_NOT_CONFIGURED",PROVIDER_DISABLED:"st.nbSearch.issue.PROVIDER_DISABLED",ENDPOINT_NOT_CONFIGURED:"st.nbSearch.issue.ENDPOINT_NOT_CONFIGURED",RATE_LIMIT_UNAUTHENTICATED:"st.nbSearch.issue.RATE_LIMIT_UNAUTHENTICATED",LANE_NOT_CONFIGURED:"st.nbSearch.issue.LANE_NOT_CONFIGURED",LANE_NOT_REGISTERED:"st.nbSearch.issue.LANE_NOT_REGISTERED",DEFAULT_NOT_CONFIGURED:"st.nbSearch.issue.DEFAULT_NOT_CONFIGURED",FETCH_CHAIN_UNAVAILABLE:"st.nbSearch.issue.FETCH_CHAIN_UNAVAILABLE",FETCH_DEFAULT_NOT_CONFIGURED:"st.nbSearch.issue.FETCH_DEFAULT_NOT_CONFIGURED"};function L5(t){return R5[t]}const M5={fast:"st.nbSearch.latency.fast",medium:"st.nbSearch.latency.medium",slow:"st.nbSearch.latency.slow"},O5={free:"st.nbSearch.cost.free",cheap:"st.nbSearch.cost.cheap",expensive:"st.nbSearch.cost.expensive"};function Ci(t){return M5[t]}function _i(t){return O5[t]}const D5={brave:"st.nbSearch.provider.brave","browser-render":"st.nbSearch.provider.browser-render",context7:"st.nbSearch.provider.context7","direct-http":"st.nbSearch.provider.direct-http",duckduckgo:"st.nbSearch.provider.duckduckgo",exa:"st.nbSearch.provider.exa",firecrawl:"st.nbSearch.provider.firecrawl",github:"st.nbSearch.provider.github",grok:"st.nbSearch.provider.grok","grok-multi-agent":"st.nbSearch.provider.grok-multi-agent","jina-reader":"st.nbSearch.provider.jina-reader","openai-compatible":"st.nbSearch.provider.openai-compatible",parallel:"st.nbSearch.provider.parallel",searxng:"st.nbSearch.provider.searxng",tavily:"st.nbSearch.provider.tavily",wayback:"st.nbSearch.provider.wayback",zhihu:"st.nbSearch.provider.zhihu",zhipu:"st.nbSearch.provider.zhipu"};function Pn(t){return D5[t]}const F5={brave:"https://brave.com/search/api/",exa:"https://dashboard.exa.ai/api-keys",firecrawl:"https://www.firecrawl.dev/app/api-keys","jina-reader":"https://jina.ai/api-dashboard",tavily:"https://app.tavily.com/home",zhihu:"https://developer.zhihu.com"};function q5(t){return F5[t]}const B5={search:"st.nbSearch.operation.search",documents:"st.nbSearch.operation.documents"},K5={"zhihu.search":"st.nbSearch.lane.zhihu.search","zhihu.global":"st.nbSearch.lane.zhihu.global","zhihu.synthesis":"st.nbSearch.lane.zhihu.synthesis"};function Ei(t,s,n,a){const i=a===void 0?void 0:K5[`${a}.${n}`];if(i!==void 0)return t(i);if(s?.output.channel==="results")return t("st.nbSearch.operation.search");const r=B5[n];return r===void 0?n:t(r)}function mi(t,s){return t.toLowerCase().split(/[\s·-]+/).includes(s.toLowerCase())?t:`${t} ${s}`.trim()}function U5(t,s,n,a){const i=s.search.lanes.find(c=>c.id===a),r=n[a];if(r===void 0)return null;const o=t(Pn(r.provider_id)??"st.nbSearch.providerFallback"),l=Ei(t,i,r.operation_id,r.provider_id);return{id:a,title:mi(o,l),subtitle:l,latency:i?.latency,cost:i?.cost}}function H5(t,s,n,a){const i=s.fetch.pipelines.find(c=>c.id===a),o=n[a]?.provider_id??i?.stages[0]?.id;if(o===void 0)return null;const l=t(Pn(o)??"st.nbSearch.providerFallback");return{id:a,title:l,subtitle:t("st.nbSearch.role.fetchShort"),latency:i?.latency,cost:i?.cost}}function z5(t,s,n){const a=new Map;for(const i of Object.keys(n))if(s.search.lanes.some(r=>r.id===i)){const r=U5(t,s,n,i);r!==null&&a.set(r.id,r)}for(const i of s.fetch.pipelines){if(a.has(i.id))continue;const r=H5(t,s,n,i.id);r!==null&&a.set(r.id,r)}return[...a.values()].toSorted((i,r)=>i.title.localeCompare(r.title))}function Q5(t,s,n){return s?t.credential.requirement!=="none"&&!t.credential.configured?"needsKey":t.availability==="ready"?"configured":"failed":"off"}function G5({activeTab:t,onSelectTab:s,attentionCount:n=0,dirty:a=!1}){const{t:i,tp:r}=D(),o=x.useRef(null),l=(u,p)=>{if(u.key==="ArrowRight"){u.preventDefault();const h=(p+1)%vs.length;s(vs[h]),c(h)}else if(u.key==="ArrowLeft"){u.preventDefault();const h=(p-1+vs.length)%vs.length;s(vs[h]),c(h)}else if(u.key==="Home")u.preventDefault(),s(vs[0]),c(0);else if(u.key==="End"){u.preventDefault();const h=vs.length-1;s(vs[h]),c(h)}},c=u=>{o.current?.querySelectorAll('[role="tab"]')?.[u]?.focus()},d=u=>{switch(u){case"overview":return"st.nbSearch.tab.overview";case"search":return"st.nbSearch.tab.search";case"fetch":return"st.nbSearch.tab.fetch";case"advanced":return"st.nbSearch.tab.advanced"}};return e.jsx("div",{ref:o,role:"tablist","aria-label":i("st.nbSearch.statusTitle"),className:"flex flex-wrap items-center gap-1 border-b border-hairline pb-px text-[12.5px]",children:vs.map((u,p)=>{const h=u===t;return e.jsxs("button",{id:`nb-search-tab-${u}`,type:"button",role:"tab","aria-selected":h,"aria-controls":`nb-search-panel-${u}`,tabIndex:h?0:-1,"data-nb-search-tab":u,onClick:()=>{s(u)},onKeyDown:b=>{l(b,p)},className:`relative -mb-px flex items-center gap-1.5 border-b-2 px-3 py-2 text-left transition-colors outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 rounded-t-md ${h?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:border-hairline hover:text-ink"}`,children:[e.jsx("span",{children:i(d(u))}),u==="search"&&n>0?e.jsx("span",{className:"text-[11px] font-medium tabular-nums text-amber-ink",title:r("st.nbSearch.tabBar.attention",n),children:n}):null,h&&a?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-ink-soft",title:i("st.tools.unsaved")}):null]},u)})})}function Py(t){return t.advanced?.lanes??{}}function br(t){const s={},n=[t.inherited_configuration?.lanes,t.configuration?.lanes];for(const a of n)for(const[i,r]of Object.entries(a??{})){if(r==null)continue;const o=W5(t,r.provider_instance_id)??r.provider_instance_id;s[i]={provider_id:o,operation_id:r.operation_id}}return s}function W5(t,s){return t.providers.instances.find(n=>n.id===s)?.provider_id}function Do(t,s){const n={},a=i=>{for(const[r,o]of Object.entries(i??{})){if(o===void 0)continue;const l=V5(t,s,o.provider_instance_id);n[r]={provider_id:l??o.provider_instance_id,operation_id:o.operation_id}}};return a(t.inherited_configuration?.lanes),a(t.configuration?.lanes),a(Py(s)),n}function V5(t,s,n){return s.providers[n]?.providerId??t.providers.instances.find(a=>a.id===n)?.provider_id}function Ay(t,s,n,a){const i=t[a];if(i!==void 0)return i.provider_id;if(n==="pipeline")return s.fetch.pipelines.find(r=>r.id===a)?.stages[0]?.id}function qu(t,s,n,a,i){const r=Ay(n,t,a,i);if(r===void 0)return null;const o=t.providers.descriptors.find(g=>g.provider_id===r),c=(a==="lane"?Y5(t,s,i):void 0)?.provider_instance_id,d=t.providers.instances.filter(g=>g.provider_id===r),u=c===void 0?d[0]:d.find(g=>g.id===c),p=c??u?.id,b=(p===void 0?void 0:s.providers[p])?.enabled??u?.enabled??!0,m=o?.activation.credential??u?.credential.requirement??"required",f=o?.activation.endpoint??u?.endpoint.requirement??"none";return{providerId:r,instanceId:u?.id??c,enabled:b,credentialRequirement:m,needsEndpoint:f==="required"||f==="optional",hasOptions:(o?.option_keys.length??0)>0}}function Y5(t,s,n){return Py(s)[n]??t.configuration?.lanes[n]??t.inherited_configuration?.lanes[n]??void 0}const os={inputKind:"url",representation:"markdown"};function Ra(t,s,n,a){const i=s.advanced?.fetchChains.find(o=>o.inputKind===n&&o.representation===a);return i!==void 0?{pipelines:i.pipelines,inherited:i.inherited}:{pipelines:(t.inherited_configuration?.fetch_chains??t.fetch.chains).find(o=>o.input_kind===n&&o.representation===a)?.pipelines??[],inherited:!0}}function J5(t,s,n,a,i){const r=Ay(n,t,a,i);return r===void 0?void 0:t.providers.instances.filter(l=>l.provider_id===r)[0]}function Z5(t,s,n,a){const i=t.providers[s];return{...t,providers:{...t.providers,[s]:{providerId:n,enabled:a,baseUrl:i?.baseUrl??"",credentialSlotId:i?.credentialSlotId??s,credentialSlotExplicit:i?.credentialSlotExplicit??!1,optionsJson:i?.optionsJson??"",isNew:i?.isNew??!1,isDeleted:!1}}}}function $y(t,s){return{...t,defaultSearchLane:s}}function X5(t){return{...t,defaultSearchLane:""}}function eL(t,s){const n=t.advanced;if(n===void 0)return t;const a={...n.lanes,[s]:void 0};return{...t,advanced:{...n,lanes:a}}}function Bu(t,s,n,a){let i=t;const r=a.length>0?a:[os];for(const o of r){const l=i.advanced?.fetchChains.find(u=>u.inputKind===o.inputKind&&u.representation===o.representation),c=Ra(s,i,o.inputKind,o.representation),d=l?.pipelines??c.pipelines;d.includes(n)?i=Sa(i,o.inputKind,o.representation,d,!1):i=Sa(i,o.inputKind,o.representation,[...d,n],!1)}return i}function tL(t,s,n,a,i){{const r=qu(s,t,Do(s,t),"lane",a)?.instanceId,o=s.inherited_configuration?.lanes,l=r!==void 0&&(s.inherited_configuration!==void 0?s.inherited_configuration.provider_instance_ids.includes(r):o?.[a]!==void 0),c=new Set([a]);let d=ks(t,a,void 0);if(r!==void 0&&!l)for(const[h,b]of Object.entries(d.advanced?.lanes??{}))b?.provider_instance_id===r&&o?.[h]===void 0&&(c.add(h),d=ks(d,h,void 0));const u={...s.inherited_configuration?.lanes??(l?s.configuration?.lanes:void 0),...d.advanced?.lanes},p=Object.entries(u).some(([h,b])=>!c.has(h)&&b?.provider_instance_id===r);if(r!==void 0&&!p&&d.providers[r]!==void 0){const h=d.providers[r].credentialSlotId,b=s.providers.instances.some(g=>g.id===r),m={...d.providers};b?m[r]={...m[r],isDeleted:!0,isNew:!1}:delete m[r];let f=d.credentialSlots;if(!l&&f?.[h]!==void 0&&!Object.entries(m).some(([v,y])=>v!==r&&!y.isDeleted&&y.credentialSlotId===h)){const v={...f};delete v[h],f=Object.keys(v).length===0?void 0:v}d={...d,defaultSearchLane:c.has(d.defaultSearchLane)?"":d.defaultSearchLane,providers:m,credentialSlots:f}}return d}}function ld(t,s,n,a,i,r){const{pipelines:o}=Ra(s,t,n,a),l=o.indexOf(i),c=l+r;if(l<0||c<0||c>=o.length)return t;const d=[...o];return[d[l],d[c]]=[d[c],d[l]],Sa(t,n,a,d,!1)}function Ry(t,s,n,a,i){const{pipelines:r}=Ra(s,t,n,a),o=r.filter(l=>l!==i);return o.length===r.length?t:Sa(t,n,a,o,!1)}function Ly(t,s,n,a){const{pipelines:i}=Ra(t,s,n,a);return I_(t,n,a).find(r=>!i.includes(r.id))?.id}const sL={LANE_NOT_CONFIGURED:"st.nbSearch.issue.fetch.LANE_NOT_CONFIGURED"};function My({issues:t,context:s="search"}){const{t:n}=D();return t.length===0?null:e.jsx("ul",{className:"mt-1 space-y-1",children:t.map(a=>{const i=$5(a),r=L5(a),o=i??(s==="fetch"?sL[a]:void 0)??r;return o!==void 0?e.jsx("li",{className:"text-[11px] leading-relaxed text-danger",title:a,children:n(o)},a):e.jsx("li",{className:"font-mono text-[11px] text-danger",children:a},a)})})}const nL={ready:"border-success/40 bg-success/10 text-success",degraded:"border-amber-rule/60 bg-amber-card text-amber-ink",unconfigured:"border-hairline bg-paper text-ink-faint",unavailable:"border-danger/40 bg-danger/5 text-danger"};function aL({state:t}){const{t:s}=D(),n=t==="ready"?"st.nbSearch.stateReady":t==="degraded"?"st.nbSearch.stateDegraded":t==="unconfigured"?"st.nbSearch.stateUnconfigured":"st.nbSearch.stateUnavailable";return e.jsx("span",{className:`rounded-full border px-1.5 py-px text-[11px] font-medium ${nL[t]}`,children:s(n)})}function Jr({label:t,desc:s,state:n,readiness:a,selectionLabel:i,issueContext:r="search",action:o}){const{t:l}=D();return e.jsxs("div",{className:"rounded-lg border border-hairline bg-paper px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] font-semibold text-ink",children:t}),e.jsx(aL,{state:n}),o!=null?e.jsx("span",{className:"ml-auto shrink-0",children:o}):null]}),s!==void 0?e.jsx("p",{className:"mt-0.5 text-[11px] text-ink-faint",children:s}):null,a.selection!==void 0?e.jsx("p",{className:"mt-1 text-[11px] text-ink-soft",children:l("st.nbSearch.currentSelection",{selection:a.selection.split(/\s*(?:→|->)\s*/).map(c=>i?.(c)??c).join(" → ")})}):null,e.jsx(My,{issues:a.issues,context:r})]})}function iL({capabilities:t,readiness:s,onNavigateToSearch:n,onNavigateToFetch:a}){const{t:i}=D(),r=br(t),o=p=>{const h=r[p];if(h!==void 0){const f=Pn(h.provider_id),g=f===void 0?h.provider_id:i(f),v=t.search.lanes.find(y=>y.id===p);return v!==void 0?mi(g,Ei(i,v,h.operation_id,h.provider_id)):g}const m=t.fetch.pipelines.find(f=>f.id===p)?.stages[0]?.id;if(m!==void 0){const f=Pn(m);return f===void 0?m:i(f)}return p},l=Ty(s.search),c=Iy(s.fetch),d=l==="degraded"||l==="unavailable"?e.jsx("button",{type:"button",onClick:n,className:"text-[11px] font-medium text-selected-ink hover:underline","data-nb-search-goto-search":!0,children:i("st.nbSearch.gotoServices")}):null,u=c==="degraded"||c==="unavailable"?e.jsx("button",{type:"button",onClick:a,className:"text-[11px] font-medium text-selected-ink hover:underline","data-nb-search-goto-fetch":!0,children:i("st.nbSearch.gotoFetch")}):null;return e.jsx(Me,{id:"st-card-search-status",title:i("st.nbSearch.statusTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(Jr,{label:i("st.nbSearch.webSearch"),desc:i("st.nbSearch.webSearchDesc"),state:l,readiness:s.search,selectionLabel:o,action:d}),e.jsx(Jr,{label:i("st.nbSearch.fetchUrl"),desc:i("st.nbSearch.fetchUrlDesc"),state:c,readiness:s.fetch,selectionLabel:o,issueContext:"fetch",action:u})]}),s.search.configured?null:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-amber-rule/60 bg-amber-card p-3 text-[11.5px] text-amber-ink",children:[e.jsx("p",{className:"min-w-0 flex-1",children:i("st.nbSearch.failClosedNote")}),e.jsx("button",{type:"button",onClick:n,className:`${Q} text-[11px] font-medium shrink-0`,"data-nb-search-goto-search-unconfigured":!0,children:i("st.nbSearch.gotoServices")})]})]})})}const rL={mode:"keep"};function oL(t){if(t.mode==="keep")return;if(t.mode==="clear")return null;const s=Mc(gm(t.keys));return s.length===0?void 0:gm(s)}function Oy(t,s){if(s.mode!=="set")return null;const n=M_(s.keys);return n.empty?t("st.nbSearch.keys.emptyKey"):n.tooMany?t("st.nbSearch.keys.tooMany",{count:s.keys.length,max:ji,extra:s.keys.length-ji}):n.duplicates.length>0?t("st.nbSearch.keys.duplicate"):null}function lL(t){const{t:s}=D(),n=Oy(s,t);return{ok:n===null,message:n}}const Vn=`${Q} min-h-8 pointer-coarse:min-h-11`,Wa=`${e_} h-7 w-7 pointer-coarse:h-11 pointer-coarse:w-11`;function cL({instanceId:t,source:s,envName:n,draft:a,onChange:i,read:r,disabled:o=!1,focusToken:l=0}){const{t:c}=D(),[d,u]=x.useState(null),[p,h]=x.useState(!1),[b,m]=x.useState(!1),[f,g]=x.useState(""),[v,y]=x.useState(new Set),[w,N]=x.useState(null),_=x.useRef(0),C=x.useRef(void 0),S=x.useRef(null);x.useEffect(()=>{l>0&&S.current?.focus()},[l]);const k=lL(a);x.useEffect(()=>{_.current++,C.current=void 0,u(null),h(!1),g(""),y(new Set),m(!1)},[t,s,n]),x.useEffect(()=>{a.mode==="keep"&&(_.current++,C.current=void 0,u(null),y(new Set),m(!1))},[a.mode]),x.useEffect(()=>{if(w===null)return;const q=setTimeout(()=>{N(null)},1600);return()=>{clearTimeout(q)}},[w]);const j=s!=="none",T=a.mode==="set",A=T?a.keys:d??[],P=T||d!==null,R=x.useCallback(async()=>{const q=++_.current;m(!0),h(!1);try{const F=await r(t,!0);if(_.current!==q)return;const V={version:F.version,binding:F.binding_version};C.current=V,u(F.value===void 0?[]:Mc(F.value)),a.mode!=="keep"&&i({...a,base:V})}catch{_.current===q&&h(!0)}finally{_.current===q&&m(!1)}},[t,r,a,i]),L=async q=>{const F=++_.current;m(!0),h(!1);try{let V=C.current;if(V===void 0){const se=await r(t,!1);if(_.current!==F)return;V={version:se.version,binding:se.binding_version},C.current=V}i(q==="set"?{mode:q,keys:d??[],base:V}:{mode:q,base:V})}catch{_.current===F&&h(!0)}finally{_.current===F&&m(!1)}},I=q=>{i({mode:"set",keys:q,base:a.mode==="set"?a.base:C.current})},$=()=>{const q=Mc(f);if(q.length===0)return;const F=T?a.keys:d??[],V=q.map((se,Y)=>F.length+Y);I([...F,...q]),y(se=>new Set([...se,...V])),g("")},E=q=>{const F=[...A];F.splice(q,1),I(F)},M=(q,F)=>{if(F<0||F>=A.length)return;const V=[...A],se=V[q];se!==void 0&&(V.splice(q,1),V.splice(F,0,se),I(V))},z=q=>{y(F=>{const V=new Set(F);return V.has(q)?V.delete(q):V.add(q),V})},H=(q,F)=>{rs(F).then(()=>{N(q)},()=>{N(null)})},U=A.length<ji,X=c("st.nbSearch.keys.count",{count:A.length,max:ji});return e.jsxs("div",{className:"min-w-0 space-y-2","data-nb-search-keys":t,"data-keys-mode":a.mode,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:[e.jsx("span",{className:"text-[13px] text-ink",children:c("st.nbSearch.keys.label")}),P?e.jsx("span",{className:"text-[12px] tabular-nums text-ink-faint","data-keys-count":!0,children:X}):null]}),e.jsxs("p",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-[12px] leading-snug",children:[e.jsx(ZC,{source:s,envName:n}),a.mode==="clear"?e.jsxs("span",{className:"text-amber-ink",children:["· ",c("st.secret.clearPending")]}):null,T?e.jsxs("span",{className:"text-ink-faint",children:["· ",c("st.nbSearch.keys.editingHint")]}):null,dL(A,T)?e.jsxs("span",{className:"text-ink-faint",children:["· ",c("st.nbSearch.keys.orderHint")]}):null,p?e.jsxs("span",{role:"alert",className:"text-danger",children:["· ",c("st.nbSearch.keys.showFailed")]}):null]}),P?A.length===0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:c("st.nbSearch.keys.empty")}):e.jsx("ul",{className:"min-w-0 space-y-0",role:"list",children:A.map((q,F)=>e.jsxs("li",{"data-key-row":F,className:"flex min-w-0 items-center gap-2 py-1 pl-1 pr-1",children:[e.jsx("span",{"aria-hidden":!0,className:"w-5 shrink-0 text-[11px] tabular-nums text-ink-faint",children:F+1}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[12px] ${v.has(F)?"select-all text-ink":"tracking-[0.12em] text-ink-soft"}`,"data-key-value":v.has(F)?"visible":"masked",children:v.has(F)?q:XC}),e.jsxs("span",{className:"flex shrink-0 items-center",children:[T&&A.length>1?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Wa,disabled:o||b||F===0,"aria-label":c("st.nbSearch.keys.moveUp",{n:F+1}),title:c("st.nbSearch.keys.moveUp",{n:F+1}),"data-key-up":F,onClick:()=>{M(F,F-1)},children:e.jsx(de,{name:"arrowUp",size:12})}),e.jsx("button",{type:"button",className:Wa,disabled:o||b||F===A.length-1,"aria-label":c("st.nbSearch.keys.moveDown",{n:F+1}),title:c("st.nbSearch.keys.moveDown",{n:F+1}),"data-key-down":F,onClick:()=>{M(F,F+1)},children:e.jsx(de,{name:"arrowDown",size:12})})]}):null,e.jsx("button",{type:"button",className:Wa,disabled:o||b,"aria-pressed":v.has(F),"aria-label":c(v.has(F)?"st.nbSearch.keys.hide":"st.nbSearch.keys.reveal",{n:F+1}),title:c(v.has(F)?"st.nbSearch.keys.hide":"st.nbSearch.keys.reveal",{n:F+1}),"data-key-reveal":F,onClick:()=>{z(F)},children:e.jsx(de,{name:v.has(F)?"eyeOff":"eye",size:12})}),e.jsx("button",{type:"button",className:Wa,disabled:o||b,"aria-label":c("st.secret.copyLabel",{label:c("st.nbSearch.keys.label")}),title:c("st.secret.copyLabel",{label:c("st.nbSearch.keys.label")}),"data-key-copy":F,onClick:()=>{H(F,q)},children:e.jsx(de,{name:w===F?"check":"copy",size:12,className:w===F?"text-success":""})}),T?e.jsx("button",{type:"button",className:`${Wa} hover:text-danger`,disabled:o||b,"aria-label":c("st.nbSearch.keys.remove",{n:F+1}),title:c("st.nbSearch.keys.remove",{n:F+1}),"data-key-remove":F,onClick:()=>{E(F)},children:e.jsx(de,{name:"close",size:12})}):null]})]},F))}):null,k.message!==null?e.jsx(it,{id:`${t}-keys-issue`,text:k.message}):null,T?e.jsx("button",{type:"button",className:Vn,disabled:o||b,"data-key-show":!0,onClick:()=>{R()},children:c(b?"st.nbSearch.keys.loading":"st.nbSearch.keys.show")}):null,T||!j?U?e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("input",{ref:S,type:"password",autoComplete:"off",spellCheck:!1,"data-1p-ignore":!0,"data-lpignore":"true",disabled:o||b,value:f,"aria-label":c("st.nbSearch.keys.placeholder"),placeholder:c("st.nbSearch.keys.placeholder"),"data-key-input":!0,className:`${Ce} min-w-0 flex-1 font-mono placeholder:font-sans placeholder:text-ink-faint`,onChange:q=>{g(q.target.value)},onKeyDown:q=>{q.key==="Enter"&&(q.preventDefault(),$())}}),e.jsx("button",{type:"button",className:Vn,disabled:o||b||f.trim()==="","data-key-add":!0,onClick:$,children:c("st.nbSearch.keys.add")})]}):null:e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Vn,disabled:o||b,"data-key-show":!0,onClick:()=>{R()},children:c(b?"st.nbSearch.keys.loading":"st.nbSearch.keys.show")}),e.jsx("button",{type:"button",className:Vn,disabled:o||b,"data-key-replace":!0,onClick:()=>{L("set")},children:c("st.nbSearch.keys.replace")}),s==="kiki"?e.jsx("button",{type:"button",className:Vn,disabled:o||b,"data-key-clear":!0,onClick:()=>{L("clear")},children:c("st.secret.clear")}):null]}),a.mode==="clear"?e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-amber-ink",children:c("st.secret.clearPending")}),e.jsx("button",{type:"button",className:Vn,disabled:o||b,"data-key-undo":!0,onClick:()=>{i(rL)},children:c("st.secret.undoClear")})]}):null]})}function dL(t,s){return s&&t.length>1}function uL(t,s,n){const a=new Date(t);if(Number.isNaN(a.getTime()))return{time:t,timezone:s};try{return{time:new Intl.DateTimeFormat(n,{dateStyle:"medium",timeStyle:"short",timeZone:s}).format(a),timezone:s}}catch{return{time:new Intl.DateTimeFormat(n,{dateStyle:"medium",timeStyle:"short",timeZone:"UTC"}).format(a),timezone:"UTC"}}}const Mh={unknown:"st.nbSearch.keyUsage.stateUnknown",ready:"st.nbSearch.keyUsage.stateReady",cooldown:"st.nbSearch.keyUsage.stateCooldown",invalid:"st.nbSearch.keyUsage.stateInvalid",exhausted:"st.nbSearch.keyUsage.stateExhausted"},Oh={unknown:"text-ink-faint",ready:"text-ink-soft",cooldown:"text-amber-ink",invalid:"text-danger",exhausted:"text-danger"};function pL({instanceId:t,readUsage:s}){const{t:n,time:a,locale:i}=D(),[r,o]=x.useState(null),[l,c]=x.useState(!1),[d,u]=x.useState(null),p=async f=>{c(!0),u(null);try{o(await s(f))}catch(g){u(g)}finally{c(!1)}},h=f=>new Intl.NumberFormat(i).format(f),b=f=>{const g=f.usage;if(g===void 0||(g.meters?.length??0)>0)return;const v=g.scope==="team"?n("st.nbSearch.keyUsage.scopeTeam"):n("st.nbSearch.keyUsage.scopeKey"),y=[];if(g.remaining!==null?y.push(n("st.nbSearch.keyUsage.remaining",{n:h(g.remaining)})):g.used!==null&&y.push(n("st.nbSearch.keyUsage.used",{n:h(g.used)})),g.limit!==null&&y.push(n("st.nbSearch.keyUsage.limit",{n:h(g.limit)})),y.length!==0)return n("st.nbSearch.keyUsage.usageLine",{scope:v,numbers:y.join(" · ")})},m=f=>(f.usage?.meters??[]).map(v=>{const y=[];v.remaining!==null?y.push(n("st.nbSearch.keyUsage.remaining",{n:h(v.remaining)})):v.used!==null&&y.push(n("st.nbSearch.keyUsage.used",{n:h(v.used)})),v.limit!==null&&y.push(n("st.nbSearch.keyUsage.limit",{n:h(v.limit)}));const w=v.unit==="credits"?n("st.nbSearch.keyUsage.unit.credits"):n("st.nbSearch.keyUsage.unit.requests"),N=y.length===0?n("st.nbSearch.keyUsage.usageNone"):`${y.join(" · ")} ${w}`,_=v.reset_at===void 0?void 0:v.reset_timezone===void 0?n("st.nbSearch.keyUsage.resetAt",{time:a.absoluteTime(v.reset_at)??v.reset_at}):n("st.nbSearch.keyUsage.resetAtTimezone",uL(v.reset_at,v.reset_timezone,i));return{id:v.id,label:v.label??v.id,value:N,reset:_}});return e.jsxs("div",{className:"space-y-2","data-nb-search-key-usage":t,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:l,"data-nb-search-key-usage-load":!0,onClick:()=>{p(!1)},children:n(r===null?"st.nbSearch.keyUsage.check":"st.nbSearch.keyUsage.recheck")}),r===null?null:e.jsx("button",{type:"button",className:Q,disabled:l,"data-nb-search-key-usage-refresh":!0,onClick:()=>{p(!0)},children:n("st.nbSearch.keyUsage.refresh")}),l?e.jsx("span",{className:"text-[12px] text-ink-faint",children:n("st.nbSearch.keyUsage.reading")}):null]}),r===null&&!l&&d===null?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-key-usage-idle":!0,children:n("st.nbSearch.keyUsage.idle")}):null,d!==null&&!l?e.jsxs(e.Fragment,{children:[e.jsx(pe,{feedback:{tone:"error",text:n("st.nbSearch.keyUsage.failed")}}),e.jsx("span",{"data-nb-search-key-usage-error":!0,children:e.jsx(De,{error:d})})]}):null,r!==null&&!l?e.jsxs("div",{className:"space-y-2","data-nb-search-key-usage-result":!0,children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:r.balance_supported?n("st.nbSearch.keyUsage.balanceSupported"):n("st.nbSearch.keyUsage.balanceUnsupported")}),e.jsx("ul",{className:"space-y-0","data-nb-search-key-usage-keys":!0,children:r.keys.map(f=>{const g=m(f);if(g.length>0)return e.jsxs("li",{className:"py-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:n("st.nbSearch.keyUsage.keyIndex",{n:String(f.key_index)})}),e.jsx("span",{className:`text-[13px] ${Oh[f.state]}`,"data-nb-search-key-state":f.state,children:n(Mh[f.state])}),f.state==="cooldown"&&f.cooldown_until!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:n("st.nbSearch.keyUsage.cooldownUntil",{time:a.timeUntil(f.cooldown_until)})}):null,f.usage?.scope==="team"?e.jsx("span",{className:"ml-auto text-[11px] text-ink-faint",children:n("st.nbSearch.keyUsage.scopeTeam")}):null]}),e.jsx("div",{className:"mt-1 divide-y divide-hairline/50 border-t border-hairline/60 pt-0.5",children:g.map(y=>e.jsxs("div",{"data-nb-search-key-usage-meter":y.id,className:"space-y-0.5 py-1 text-[12px]",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsx("span",{className:"text-ink",children:y.label}),e.jsx("span",{className:"ml-auto text-right tabular-nums text-ink-soft",children:y.value})]}),y.reset!==void 0?e.jsx("p",{className:"text-right text-[11px] tabular-nums text-ink-faint",children:y.reset}):null]},`${f.key_index}:${y.id}`))})]},f.key_index);const v=b(f);return e.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 py-1.5",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:n("st.nbSearch.keyUsage.keyIndex",{n:String(f.key_index)})}),e.jsx("span",{className:`text-[13px] ${Oh[f.state]}`,"data-nb-search-key-state":f.state,children:n(Mh[f.state])}),f.state==="cooldown"&&f.cooldown_until!==void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:n("st.nbSearch.keyUsage.cooldownUntil",{time:a.timeUntil(f.cooldown_until)})}):null,e.jsx("span",{className:"ml-auto flex flex-col items-end text-right text-[12px] text-ink-soft",children:v!==void 0?e.jsx("span",{"data-nb-search-key-usage-meter":"legacy",children:v}):f.usage_error==="invalid_response"?n("st.nbSearch.keyUsage.usageInvalidResponse"):f.usage_error==="unavailable"?n("st.nbSearch.keyUsage.usageUnavailable"):n("st.nbSearch.keyUsage.usageNone")})]},f.key_index)})}),r.keys.length===0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-key-usage-empty":!0,children:n("st.nbSearch.keyUsage.noKeys")}):null,e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.keyUsage.footnote")})]}):null]})}const mL=6e4,xL=864e5;function hL(t,s){const n=s.trim();if(n==="")return null;const a=Number(n);return!Number.isInteger(a)||a<mL||a>xL?t("st.nbSearch.service.balanceTtlInvalid"):null}function fL(t,s){const n=s.trim();return n===""||/^https?:\/\//i.test(n)?null:t("st.nbSearch.providers.baseUrlInvalid")}function bL(t,s){const n=s.trim();if(n==="")return null;try{const a=JSON.parse(n);return a!==null&&typeof a=="object"&&!Array.isArray(a)?null:t("st.nbSearch.providers.optionsInvalid")}catch{return t("st.nbSearch.providers.optionsInvalid")}}function gL(t,s,n){const a=t.providers.instances.find(o=>o.id===n);if(a!==void 0){const o=t.providers.descriptors.find(c=>c.provider_id===a.provider_id),l=s.providers[n];return{providerId:a.provider_id,instanceId:n,enabled:l?.enabled??a.enabled,credentialRequirement:o?.activation.credential??a.credential.requirement,needsEndpoint:(o?.activation.endpoint??a.endpoint.requirement)!=="none",hasOptions:(o?.option_keys.length??0)>0}}const i=s.providers[n];if(i===void 0||i.isDeleted===!0||i.providerId===void 0)return null;const r=t.providers.descriptors.find(o=>o.provider_id===i.providerId);return{providerId:i.providerId,instanceId:n,enabled:i.enabled,credentialRequirement:r?.activation.credential??"required",needsEndpoint:(r?.activation.endpoint??"none")!=="none",hasOptions:(r?.option_keys.length??0)>0}}function vL(t,s){return t!==null&&!t.enabled?{key:"off",className:"text-ink-faint"}:t!==null&&t.credentialRequirement!=="none"&&(s===void 0||!s.credential.configured)?{key:"needsKey",className:"text-amber-ink"}:s!==void 0&&s.availability!=="ready"?{key:"unavailable",className:"text-ink-faint"}:{key:"ready",className:"text-ink-soft"}}function cd({card:t,kind:s,instanceId:n,capabilities:a,draft:i,onChange:r,keyDraft:o,onKeyDraftChange:l,readCredential:c,readKeyUsage:d,saving:u,defaultState:p="none",onMakeDefault:h,chain:b,onRemoveService:m,removeTitle:f,children:g,defaultOpen:v=!1,open:y,onOpenChange:w}){const{t:N}=D(),_=x.useMemo(()=>Do(a,i),[a,i]),C=x.useMemo(()=>s==="instance"?gL(a,i,n??""):qu(a,i,_,s,t.id),[a,i,_,s,t.id,n]),S=a.providers.instances.find(Te=>Te.id===C?.instanceId),[k,j]=x.useState(v),T=y??k,A=Te=>{const Ne=typeof Te=="function"?Te(T):Te;j(Ne),w?.(Ne)},P=C?.instanceId,R=P===void 0?void 0:i.providers[P],L=i.credentialSlots??{},I=R===void 0?"":L[R.credentialSlotId]?.env??"",[$,E]=x.useState({source:"none"}),M=P,z=S===void 0&&R?.isNew===!0,H=o.mode==="keep";x.useEffect(()=>{if(M===void 0||C?.credentialRequirement==="none"||z||!H){(M===void 0||C?.credentialRequirement==="none"||z)&&E({source:"none"});return}let Te=!0;return E({source:"none"}),c(M,!1).then(Ne=>{Te&&E({source:Ne.source==="managed"?"kiki":Ne.source,envName:Ne.env_name})},()=>{}),()=>{Te=!1}},[M,C?.credentialRequirement,z,H,S?.credential.configured,S?.credential.slot_id,a.revision,c]);const U=vL(C,S),[X,q]=x.useState(!1),[F,V]=x.useState(!1),[se,Y]=x.useState(0),O=x.useMemo(()=>fL(N,R?.baseUrl??""),[N,R?.baseUrl]),B=x.useMemo(()=>hL(N,R?.balanceTtlMs??""),[N,R?.balanceTtlMs]),le=x.useMemo(()=>bL(N,R?.optionsJson??""),[N,R?.optionsJson]),re=I.trim(),ae=F&&re!==""&&!/^[A-Za-z_][A-Za-z0-9_]*$/.test(re)?N("st.nbSearch.service.credentialEnvInvalid"):null,ne=C===null?"":`NB_SEARCH_${C.providerId.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`,Ee=Te=>{if(P===void 0||C===null)return;const Ne=i.providers[P]??{providerId:C.providerId,enabled:!0,baseUrl:"",credentialSlotId:P,credentialSlotExplicit:!1,optionsJson:"",isNew:!0,isDeleted:!1};r({...i,providers:{...i.providers,[P]:{...Ne,...Te,isDeleted:!1}}})},ie=R?.keyStrategy??"default",me=t.latency===void 0?void 0:Ci(t.latency),fe=t.cost===void 0?void 0:_i(t.cost),Ie=[me===void 0?t.latency:N(me),fe===void 0?t.cost:N(fe)].filter(Te=>Te!==void 0),te=h!==void 0&&p==="none",ee=te||m!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1","data-nb-search-service-footer":!0,children:[te?e.jsx("button",{type:"button",className:"text-[12px] font-medium text-selected-ink transition-colors hover:underline disabled:cursor-not-allowed disabled:opacity-50",disabled:u,"data-nb-search-service-make-default":t.id,onClick:h,children:N("st.nbSearch.services.makeDefault")}):null,m!==void 0?e.jsx("button",{type:"button",className:"text-[12px] font-medium text-danger transition-colors hover:underline disabled:cursor-not-allowed disabled:opacity-50",disabled:u,"data-nb-search-service-remove":!0,onClick:()=>{q(!0)},children:N("st.nbSearch.services.removeService")}):null]}):null,K=C!==null&&C.credentialRequirement!=="none"?q5(C.providerId):void 0,Z=T?e.jsxs("div",{className:"space-y-3","data-nb-search-service-body":t.id,children:[K!==void 0?e.jsxs("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-key-guide":!0,children:[N("st.nbSearch.service.keyGuide")," ",e.jsx(oa,{href:K,className:"font-medium text-selected-ink hover:underline",children:N("st.nbSearch.service.keyGuideLink")})]}):null,C!==null&&P!==void 0&&C.credentialRequirement!=="none"?e.jsx("div",{className:"space-y-2",children:e.jsx(cL,{instanceId:P,source:$.source,envName:re===""?$.envName:re,draft:o,onChange:l,read:c,disabled:u,focusToken:se})}):null,C!==null&&P!==void 0?e.jsx(et,{summary:N("st.nbSearch.service.advancedSummary"),"data-nb-search-service-advanced":!0,children:e.jsxs("div",{className:"space-y-3",children:[C.credentialRequirement!=="none"?e.jsx("div",{"data-nb-search-credential-env-section":!0,children:e.jsxs(ge,{layout:"stack",label:N("st.nbSearch.credentialEnvLabel"),htmlFor:`${P}-cred-env`,help:N("st.nbSearch.service.credentialEnvHint"),children:[e.jsx("input",{id:`${P}-cred-env`,className:"w-full rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:font-sans placeholder:text-ink-faint focus:border-selected-ink disabled:cursor-not-allowed disabled:opacity-50",value:I,placeholder:ne,spellCheck:!1,autoComplete:"off",disabled:u,"data-nb-search-credential-env":!0,"aria-invalid":ae!==null,onChange:Te=>{V(!0),r(F_(i,P,C.providerId,Te.target.value))}}),e.jsx(it,{id:`${P}-cred-env-issue`,text:ae})]})}):null,C.credentialRequirement!=="none"?e.jsx(pL,{instanceId:P,readUsage:Te=>d(P,Te)}):null,C.needsEndpoint?e.jsxs(ge,{layout:"stack",label:N("st.nbSearch.baseUrlLabel"),htmlFor:`${P}-base-url`,help:O===null?N("st.nbSearch.service.baseUrlHint"):void 0,children:[e.jsx("input",{id:`${P}-base-url`,className:"w-full rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:font-sans placeholder:text-ink-faint focus:border-selected-ink disabled:cursor-not-allowed disabled:opacity-50",value:R?.baseUrl??"",placeholder:N("st.nbSearch.service.baseUrlDefault"),spellCheck:!1,autoComplete:"off",disabled:u,"data-nb-search-base-url":!0,"aria-invalid":O!==null,onChange:Te=>{Ee({baseUrl:Te.target.value})}}),e.jsx(it,{id:`${P}-base-url-issue`,text:O})]}):null,e.jsx(ge,{label:N("st.nbSearch.service.keyStrategy"),layout:"row",help:N("st.nbSearch.service.keyStrategyHint"),children:e.jsx(Qe,{ariaLabel:N("st.nbSearch.service.keyStrategy"),dataAttr:"data-nb-search-key-strategy",value:ie,disabled:u,choices:[{value:"default",label:N("st.nbSearch.service.keyStrategyInherit")},{value:"round-robin",label:N("st.nbSearch.service.keyStrategyRoundRobin")},{value:"priority",label:N("st.nbSearch.service.keyStrategyPriority")}],onChange:Te=>{Ee({keyStrategy:Te==="default"?void 0:Te})}})}),e.jsxs(ge,{label:N("st.nbSearch.service.balanceTtl"),htmlFor:`${P}-balance-ttl`,help:N("st.nbSearch.service.balanceTtlHint"),children:[e.jsx("input",{id:`${P}-balance-ttl`,className:"w-full rounded-lg border border-hairline bg-paper px-3 py-2 text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-selected-ink disabled:cursor-not-allowed disabled:opacity-50",inputMode:"numeric",value:R?.balanceTtlMs??"",placeholder:"60000",spellCheck:!1,autoComplete:"off",disabled:u,"data-nb-search-balance-ttl":!0,"aria-invalid":B!==null,onChange:Te=>{Ee({balanceTtlMs:Te.target.value})}}),e.jsx(it,{id:`${P}-balance-ttl-issue`,text:B})]}),C.hasOptions?e.jsxs("label",{className:"block text-[12px] font-medium text-ink-soft","data-nb-search-options":!0,children:[N("st.nbSearch.optionsLabel"),e.jsx("textarea",{className:"mt-1 min-h-16 w-full rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:font-sans placeholder:text-ink-faint focus:border-selected-ink disabled:cursor-not-allowed disabled:opacity-50",value:R?.optionsJson??"",placeholder:"{}",spellCheck:!1,disabled:u,"data-nb-search-options-json":!0,onChange:Te=>{Ee({optionsJson:Te.target.value})}}),e.jsx(it,{id:`${P}-options-issue`,text:le})]}):null]})}):null,C!==null&&C.credentialRequirement==="none"?e.jsx(he,{children:N("st.nbSearch.service.keylessHint")}):null,g,ee]}):null,ue=`nb-search-service-body-${t.id.replace(/[^A-Za-z0-9_-]+/g,"-")}`;return e.jsxs(e.Fragment,{children:[e.jsx(Di,{data:{"data-nb-search-service-card":t.id,"data-nb-search-service-kind":s},open:T,onToggle:()=>{A(Te=>!Te)},bodyId:ue,expandLabel:T?N("st.nbSearch.custom.close"):N("st.nbSearch.services.openService",{name:t.title}),name:t.title,marks:e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[p==="default"?e.jsx("span",{"data-nb-search-service-default":!0,children:e.jsx(Yt,{tone:"accent",children:N("st.nbSearch.services.defaultBadge")})}):null,p==="inherit"?e.jsx("span",{className:"text-[11px] text-ink-faint","data-nb-search-service-inherit":!0,children:N("st.nbSearch.services.inheritBadge")}):null]}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"shrink-0",children:t.subtitle}),Ie.map(Te=>e.jsxs("span",{className:"shrink-0",children:[e.jsx("span",{"aria-hidden":!0,children:"· "}),Te]},Te)),e.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1.5 ${U.className}`,"data-nb-search-service-state":U.key,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${U.key==="needsKey"?"bg-amber-rule":U.key==="ready"?"bg-ink-soft":"bg-hairline-strong"}`}),N(U.key==="ready"?"st.nbSearch.services.stateReady":U.key==="needsKey"?"st.nbSearch.services.stateNeedsKey":"st.nbSearch.services.stateUnavailable")]})]}),control:e.jsxs(e.Fragment,{children:[b!==void 0?e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.04] hover:text-ink disabled:cursor-not-allowed disabled:opacity-40","aria-label":N("st.nbSearch.movePipelineUp",{n:b.position+1}),title:N("st.nbSearch.movePipelineUp",{n:b.position+1}),disabled:u||b.position===0,"data-nb-search-fetch-up":!0,onClick:()=>{b.onMove(-1)},children:e.jsx("span",{"aria-hidden":!0,className:"text-[11px]",children:"↑"})}),e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.04] hover:text-ink disabled:cursor-not-allowed disabled:opacity-40","aria-label":N("st.nbSearch.movePipelineDown",{n:b.position+1}),title:N("st.nbSearch.movePipelineDown",{n:b.position+1}),disabled:u||b.position===b.length-1,"data-nb-search-fetch-down":!0,onClick:()=>{b.onMove(1)},children:e.jsx("span",{"aria-hidden":!0,className:"text-[11px]",children:"↓"})}),e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.04] hover:text-danger disabled:cursor-not-allowed disabled:opacity-40","aria-label":N("st.nbSearch.removePipeline",{n:b.position+1}),title:N("st.nbSearch.removePipeline",{n:b.position+1}),disabled:u||b.length===1,"data-nb-search-fetch-remove":!0,onClick:b.onRemove,children:e.jsx("span",{"aria-hidden":!0,className:"text-[12px]",children:"×"})})]}):null,U.key==="needsKey"?e.jsx("button",{type:"button",className:Ot,disabled:u,"data-nb-search-add-key":t.id,onClick:()=>{A(!0),Y(Te=>Te+1)},children:N("st.ai.fix.key")}):null,C!==null&&P!==void 0?e.jsx("span",{"data-nb-search-service-enabled":t.id,className:"contents",children:e.jsx(Be,{layout:"bare",label:N("st.nbSearch.service.enabledLabel"),checked:C.enabled,disabled:u,onChange:Te=>{r(Z5(i,P,C.providerId,Te))}})}):null]}),children:Z}),m!==void 0?e.jsx(Xe,{open:X,overlayId:`nb-search-remove-${t.id}`,title:f??N("st.nbSearch.services.removeServiceTitle",{name:t.title}),body:N("st.nbSearch.services.removeServiceBody"),confirmLabel:N("st.nbSearch.services.removeService"),onCancel:()=>{q(!1)},onConfirm:()=>{q(!1),m()}}):null]})}const Dy={url:"st.nbSearch.fetch.input.url",inline_text:"st.nbSearch.fetch.input.inlineText",inline_bytes:"st.nbSearch.fetch.input.inlineBytes",file:"st.nbSearch.fetch.input.file"},Fy={markdown:"st.nbSearch.fetch.representation.markdown",text:"st.nbSearch.fetch.representation.text"};function qy(t,s){return s===void 0?t?"localUnconfirmed":"unknown":t?s?"override":"local":"source"}function By(t){return{canRemoveLocal:t==="local"||t==="localUnconfirmed",canRestoreSource:t==="override",canRename:t!=="override"}}function Ky(t,s){return t===void 0?void 0:t[s]!==void 0}function Zr(t,s,n){const a=s.advanced?.lanes[n]??void 0;return{profile:a??t.configuration?.lanes[n]??t.inherited_configuration?.lanes[n],source:qy(a!==void 0,Ky(t.inherited_configuration?.lanes,n))}}function Uy(t,s,n){const a=s.advanced?.presets[n]??void 0;return{source:qy(a!==void 0,Ky(t.inherited_configuration?.presets,n))}}function Dh(t){return t==="localUnconfirmed"?"st.nbSearch.custom.badgeLocalSetting":t==="unknown"?"st.nbSearch.custom.badgeOriginUnknown":t==="local"?"st.nbSearch.custom.badgeLocal":"st.nbSearch.custom.badgeSource"}function Ti(t,s){const n=Pn(s);return n===void 0?s:t(n)}function xi(t,s,n){return s.providers[n]?.providerId??t.providers.instances.find(a=>a.id===n)?.provider_id}function yL(t,s){const n=new Set(t.providers.instances.map(a=>a.id));for(const[a,i]of Object.entries(s.providers))i.isNew===!0&&i.isDeleted!==!0&&n.add(a);return[...n].filter(a=>s.providers[a]?.isDeleted!==!0).toSorted((a,i)=>a.localeCompare(i))}function Fh(t,s){const n=t.providers.descriptors.find(a=>a.provider_id===s);return n===void 0?[]:[...n.query_operations.map(a=>({operationId:a.operation_id,channel:a.output.channel})),...n.fetch_operations.map(a=>({operationId:a.operation_id,channel:"fetch"}))].toSorted((a,i)=>a.operationId.localeCompare(i.operationId))}function kL(t){return t.search.lanes.filter(s=>s.output.channel==="results").map(s=>s.id).toSorted((s,n)=>s.localeCompare(n))}function jL(t,s){return t!=="ready"||s==="none"?"st.nbSearch.lanes.unavailable":s==="sync"?"st.nbSearch.lanes.syncSupported":"st.nbSearch.lanes.asyncOnly"}function Hy(t,s){switch(s.code){case"instance":return t("st.nbSearch.advanced.issue.instance",{target:s.target});case"operation":return t("st.nbSearch.advanced.issue.operation",{target:s.target});case"lane":return t("st.nbSearch.advanced.issue.lane",{target:s.target});case"preset-results":return t("st.nbSearch.advanced.issue.presetResults",{target:s.target});case"pipeline":return t("st.nbSearch.advanced.issue.pipeline",{target:s.target});case"pipeline-incompatible":return t("st.nbSearch.advanced.issue.pipelineIncompatible",{target:s.target});default:return t("st.nbSearch.advanced.issue.unknown")}}function wL(t,s){if(s==="defaults.search_lane")return t("st.nbSearch.custom.reference.defaultLane");if(s.startsWith("presets."))return t("st.nbSearch.custom.reference.preset",{id:s.slice(8)});if(s.startsWith("lanes."))return t("st.nbSearch.custom.reference.lane",{lane:s.slice(6)});if(s.startsWith("fetch.routing.rules."))return t("st.nbSearch.custom.reference.routeRule",{id:s.slice(20)});const n=/^defaults\.fetch_chain\.([^.]+)\.([^.]+)$/.exec(s);if(n!==null){const a=n[1],i=n[2],r=Dy[a],o=Fy[i];return t("st.nbSearch.custom.reference.chain",{input:r===void 0?a:t(r),representation:o===void 0?i:t(o)})}return s}function NL(t,s){const n=s.advanced?.routing,a=t.fetch.routing,i=a??{enabled:!0,builtin_enabled:!0,package:{id:"",version:"",maintainer:"",summary:""},builtin_rules:[],disabled_builtin_rules:[],rules:[]},r=t.inherited_configuration,o=r===void 0?i:{...i,enabled:r.routing?.enabled!==!1,builtin_enabled:r.routing?.builtin_enabled!==!1,disabled_builtin_rules:[...r.routing?.disabled_builtin_rules??[]],rules:[...r.routing?.rules??[]]};return n===void 0?{mode:"inherited",reported:a!==void 0,effective:o}:n===null?{mode:"cleared",reported:a!==void 0,effective:{...i,enabled:!0,builtin_enabled:!0,disabled_builtin_rules:[],rules:[]}}:{mode:"custom",reported:a!==void 0,effective:{...i,enabled:n.enabled??o.enabled,builtin_enabled:n.builtin_enabled??o.builtin_enabled,disabled_builtin_rules:[...n.disabled_builtin_rules??o.disabled_builtin_rules],rules:[...n.rules??o.rules]}}}function SL(t,s){return t.effective.enabled&&t.effective.builtin_enabled&&!t.effective.disabled_builtin_rules.includes(s)}const CL=["fast","medium","slow"],_L=["free","cheap","expensive"];function EL({binding:t,laneId:s,saving:n=!1,onRename:a,onClose:i}){const{t:r}=D(),o=t.capabilities,l=Zr(o,t.draft,s),c=By(l.source),u=t.draft.advanced?.lanes[s]??void 0??l.profile,p=l.source!=="source",h=x.useMemo(()=>yL(o,t.draft),[o,t.draft]),b=u?.provider_instance_id??h[0]??"",m=xi(o,t.draft,b),f=x.useMemo(()=>Fh(o,m),[o,m]),g=u?.operation_id??f[0]?.operationId??"",v=x.useMemo(()=>au(t.config,t.draft,o).filter(M=>M.path===`lanes.${s}`),[t.config,t.draft,o,s]),[y,w]=x.useState(s),[N,_]=x.useState(null),[C,S]=x.useState((u?.evidence_groups??[]).join(", ")),k=P_(t.draft,s,o),j=x.useRef(t);j.current=t;const T=M=>{const z=M.evidence_groups??u?.evidence_groups;return{provider_instance_id:M.provider_instance_id??b,operation_id:M.operation_id??g,latency:M.latency??u?.latency??"medium",cost:M.cost??u?.cost??"cheap",...z!==void 0&&z.length>0?{evidence_groups:[...z]}:{}}},A=M=>{j.current.onChange(ks(j.current.draft,s,T(M)))},P=()=>{l.profile!==void 0&&j.current.onChange(ks(j.current.draft,s,l.profile))},R=()=>{j.current.onChange(ks(j.current.draft,s,void 0))},L=()=>{const M=y.trim();if(M===s)return;if(M===""||M.length>256){_(r("st.nbSearch.custom.lane.idInvalid"));return}if(j.current.draft.advanced?.lanes[M]!==void 0||o.search.lanes.some(H=>H.id===M)){_(r("st.nbSearch.custom.lane.idTaken"));return}_(null);const z=ks(j.current.draft,s,void 0);j.current.onChange(ks(z,M,T({}))),a?.(M)},I=()=>{const M=C.split(",").map(z=>z.trim()).filter(z=>z!=="");if(M.some(z=>z.length>128)||M.length>32){S((u?.evidence_groups??[]).join(", "));return}A({evidence_groups:M})},$=()=>{const M=ks(j.current.draft,s,void 0);j.current.onChange(M),i(),xs({text:r("st.nbSearch.custom.lane.removed",{lane:s}),undoFailedText:r("toast.undoFailed"),undo:()=>{j.current.onChange(ks(j.current.draft,s,T({})))}})},E=(M,z,H,U)=>e.jsxs("label",{className:$e,children:[M,e.jsx("div",{className:"mt-1",children:e.jsx(Qe,{variant:"form",value:z,choices:H,ariaLabel:M,disabled:n||!p,onChange:U})})]});return e.jsxs("div",{className:"space-y-3 border-l-2 border-hairline pl-3","data-nb-search-lane-editor":s,"data-nb-search-lane-source":l.source,children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-lane-origin":!0,children:l.source==="source"?r("st.nbSearch.custom.lane.originSource"):l.source==="override"?r("st.nbSearch.custom.lane.originOverride"):l.source==="localUnconfirmed"?r("st.nbSearch.custom.lane.originLocalSetting"):l.source==="unknown"?r("st.nbSearch.custom.lane.originUnknown"):r("st.nbSearch.custom.lane.originLocal")}),p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[r("st.nbSearch.custom.lane.idLabel"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:y,disabled:n,readOnly:!c.canRename,spellCheck:!1,autoComplete:"off","aria-label":r("st.nbSearch.custom.lane.idLabel"),"data-nb-search-lane-id":!0,onChange:M=>{w(M.target.value),N!==null&&_(null)},onBlur:L,onKeyDown:M=>{rt(M)||(M.key==="Enter"?(M.preventDefault(),L()):M.key==="Escape"&&(w(s),_(null)))}}),e.jsx(it,{id:`${s}-id-issue`,text:N}),N===null?e.jsx("span",{className:"mt-1 block font-normal text-[11px] leading-relaxed text-ink-faint",children:r("st.nbSearch.custom.lane.idHint")}):null]}),E(r("st.nbSearch.custom.lane.instance"),b,h.map(M=>({value:M,label:Ti(r,xi(o,t.draft,M)??M),hint:M})),M=>{const z=xi(o,t.draft,M),H=Fh(o,z)[0]?.operationId??g;A({provider_instance_id:M,operation_id:H})}),E(r("st.nbSearch.custom.lane.operation"),g,f.map(M=>({value:M.operationId,label:M.operationId,hint:M.channel})),M=>{A({operation_id:M})}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[E(r("st.nbSearch.custom.lane.latency"),u?.latency??"medium",CL.map(M=>({value:M,label:r(Ci(M))})),M=>{A({latency:M})}),E(r("st.nbSearch.custom.lane.cost"),u?.cost??"cheap",_L.map(M=>({value:M,label:r(_i(M))})),M=>{A({cost:M})})]})]}),e.jsxs(et,{summary:r("st.nbSearch.custom.lane.evidence"),children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12px] text-ink-soft",children:r("st.nbSearch.custom.lane.evidenceLabel")}),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:C,disabled:n,spellCheck:!1,autoComplete:"off","aria-label":r("st.nbSearch.custom.lane.evidenceLabel"),"data-nb-search-lane-evidence":!0,onChange:M=>{S(M.target.value)},onBlur:I,onKeyDown:M=>{rt(M)||M.key==="Enter"&&(M.preventDefault(),I())}})]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:r("st.nbSearch.custom.lane.evidenceHint")})]})]}):e.jsxs("dl",{className:"space-y-1 text-[12px]","data-nb-search-lane-readonly":!0,children:[e.jsx(tc,{label:r("st.nbSearch.custom.lane.instance"),value:b===""?r("st.nbSearch.custom.lane.unknown"):b}),e.jsx(tc,{label:r("st.nbSearch.custom.lane.operation"),value:g===""?r("st.nbSearch.custom.lane.unknown"):g}),e.jsx(tc,{label:r("st.nbSearch.custom.lane.tier"),value:u===void 0?r("st.nbSearch.custom.lane.unknown"):`${r(Ci(u.latency))} · ${r(_i(u.cost))}`})]}),v.map(M=>e.jsxs("p",{role:"alert","data-nb-search-lane-issue":!0,className:"text-[12px] leading-4 text-danger",children:[Hy(r,M),e.jsxs("span",{className:"ml-1 font-mono text-[11px] text-ink-faint",children:[M.code," · ",M.path," · ",M.target]})]},`${M.code}:${M.path}:${M.target}`)),c.canRemoveLocal&&k.length>0?e.jsxs("div",{className:"space-y-1","data-nb-search-lane-references":!0,children:[e.jsx("p",{className:"text-[12px] leading-4 text-amber-ink",children:r("st.nbSearch.custom.removeReferenced")}),e.jsx("ul",{className:"space-y-1",children:k.map(M=>e.jsxs("li",{className:"text-[12px] text-ink",children:[wL(r,M),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-ink-faint",children:M})]},M))})]}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[p?null:e.jsx("button",{type:"button",className:Q,disabled:n||l.profile===void 0,"data-nb-search-lane-override":!0,onClick:P,children:r("st.nbSearch.custom.lane.override")}),c.canRestoreSource?e.jsx("button",{type:"button",className:Q,disabled:n,"data-nb-search-lane-restore":!0,onClick:R,children:r("st.nbSearch.custom.lane.restore")}):null,c.canRemoveLocal?e.jsx("button",{type:"button",className:Ht,disabled:n,"data-nb-search-lane-remove":!0,onClick:$,children:r("st.nbSearch.custom.lane.remove")}):null,e.jsx("button",{type:"button",className:`${Q} ml-auto`,onClick:i,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"collapse",size:12}),r("st.nbSearch.custom.close")]})})]})]})}function tc({label:t,value:s}){return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("dt",{className:"text-ink-soft",children:t}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-[11px] text-ink",children:s})]})}function TL({binding:t,presetId:s,saving:n=!1,onRename:a,onClose:i}){const{t:r}=D(),o=t.capabilities,l=t.draft.advanced?.presets[s]??void 0,c=o.search.presets.find(k=>k.name===s),d=Uy(o,t.draft,s).source,u=By(d),p=d!=="source",h=l?.lanes??c?.lanes??[],b=x.useMemo(()=>kL(o).map(k=>{const j=Zr(o,t.draft,k),T=j.profile===void 0?void 0:xi(o,t.draft,j.profile.provider_instance_id);return{value:k,label:j.profile===void 0?k:`${Ti(r,T??k)} · ${j.profile.operation_id}`,hint:k}}),[o,t.draft,r]),m=x.useMemo(()=>au(t.config,t.draft,o).filter(k=>k.path===`presets.${s}`),[t.config,t.draft,o,s]),[f,g]=x.useState(s),[v,y]=x.useState(null),w=k=>{t.onChange(fn(t.draft,s,{lanes:[...k]}))},N=()=>{c!==void 0&&t.onChange(fn(t.draft,s,{lanes:[...c.lanes]}))},_=()=>{t.onChange(fn(t.draft,s,void 0))},C=()=>{t.onChange(fn(t.draft,s,void 0)),i()},S=()=>{const k=f.trim();if(k===s)return;if(k===""||k.length>256){y(r("st.nbSearch.custom.preset.idInvalid"));return}if(t.draft.advanced?.presets[k]!==void 0||o.search.presets.some(T=>T.name===k)){y(r("st.nbSearch.custom.preset.idTaken"));return}y(null);const j=fn(t.draft,s,void 0);t.onChange(fn(j,k,{lanes:[...h]})),a?.(k)};return e.jsxs("div",{className:"space-y-3 border-l-2 border-hairline pl-3","data-nb-search-preset-editor":s,"data-nb-search-preset-source":d,children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-preset-origin":!0,children:r(d==="source"?"st.nbSearch.custom.preset.originSource":d==="override"?"st.nbSearch.custom.preset.originOverride":d==="localUnconfirmed"?"st.nbSearch.custom.preset.originLocalSetting":d==="unknown"?"st.nbSearch.custom.preset.originUnknown":"st.nbSearch.custom.preset.originLocal")}),p?e.jsxs("label",{className:$e,children:[r("st.nbSearch.custom.preset.idLabel"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:f,disabled:n,readOnly:!u.canRename,spellCheck:!1,autoComplete:"off","aria-label":r("st.nbSearch.custom.preset.idLabel"),"data-nb-search-preset-id":!0,onChange:k=>{g(k.target.value),v!==null&&y(null)},onBlur:S,onKeyDown:k=>{rt(k)||(k.key==="Enter"?(k.preventDefault(),S()):k.key==="Escape"&&(g(s),y(null)))}}),e.jsx(it,{id:`${s}-name-issue`,text:v}),v===null?e.jsx("span",{className:"mt-1 block font-normal text-[11px] leading-relaxed text-ink-faint",children:r("st.nbSearch.custom.preset.idHint")}):null]}):null,e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:r("st.nbSearch.custom.preset.lanes")}),e.jsx("ol",{className:"space-y-0","data-nb-search-preset-lanes":!0,children:h.map((k,j)=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[e.jsx("span",{className:"w-5 shrink-0 text-center font-mono text-[11px] text-ink-faint",children:j+1}),e.jsx("div",{className:"min-w-0 flex-1",children:p&&!n?e.jsx(Qe,{variant:"form",mono:!0,value:k,choices:b.some(T=>T.value===k)?b:[{value:k,label:k},...b],ariaLabel:`${r("st.nbSearch.custom.preset.lanes")} ${j+1}`,dataAttr:"data-nb-search-preset-lane",onChange:T=>{const A=[...h];A[j]=T,w(A)}}):e.jsx("span",{className:"block min-w-0 break-all font-mono text-[11px] text-ink",children:k})}),p?e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(sc,{label:r("st.nbSearch.custom.moveUp",{n:j+1}),icon:"arrowDown",flip:!0,disabled:n||j===0,onClick:()=>{const T=[...h];[T[j-1],T[j]]=[T[j],T[j-1]],w(T)}}),e.jsx(sc,{label:r("st.nbSearch.custom.moveDown",{n:j+1}),icon:"arrowDown",disabled:n||j===h.length-1,onClick:()=>{const T=[...h];[T[j],T[j+1]]=[T[j+1],T[j]],w(T)}}),e.jsx(sc,{label:r("st.nbSearch.custom.removeRow",{n:j+1}),icon:"close",tone:"danger",disabled:n||h.length===1,onClick:()=>{w(h.filter((T,A)=>A!==j))}})]}):null]},`${j}:${k}`))}),p?e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:n||b.every(k=>h.includes(k.value)),"data-nb-search-preset-add-lane":!0,onClick:()=>{const k=b.find(j=>!h.includes(j.value));k!==void 0&&w([...h,k.value])},children:[e.jsx(de,{name:"plus",size:12}),r("st.nbSearch.custom.preset.addLane")]}):null,e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:h.length===1?r("st.nbSearch.custom.preset.minLane"):r("st.nbSearch.custom.preset.laneHint")})]}),m.map(k=>e.jsxs("p",{role:"alert","data-nb-search-preset-issue":!0,className:"text-[12px] leading-4 text-danger",children:[Hy(r,k),e.jsxs("span",{className:"ml-1 font-mono text-[11px] text-ink-faint",children:[k.code," · ",k.path," · ",k.target]})]},`${k.code}:${k.target}`)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[p?null:e.jsx("button",{type:"button",className:Q,disabled:n,"data-nb-search-preset-override":!0,onClick:N,children:r("st.nbSearch.custom.preset.override")}),u.canRestoreSource?e.jsx("button",{type:"button",className:Q,disabled:n,"data-nb-search-preset-restore":!0,onClick:_,children:r("st.nbSearch.custom.preset.restore")}):null,u.canRemoveLocal?e.jsx("button",{type:"button",className:Ht,disabled:n,"data-nb-search-preset-remove":!0,onClick:C,children:r("st.nbSearch.custom.preset.remove")}):null,e.jsx("button",{type:"button",className:`${Q} ml-auto`,onClick:i,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"collapse",size:12}),r("st.nbSearch.custom.close")]})})]})]})}function sc({label:t,icon:s,onClick:n,disabled:a,flip:i=!1,tone:r="plain"}){return e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1 ${r==="danger"?"text-danger hover:border-danger/40":""}`,"aria-label":t,title:t,disabled:a,onClick:n,children:e.jsx(de,{name:s,size:12,className:i?"rotate-180":void 0})})}const IL=/^[A-Za-z_][A-Za-z0-9_]*$/;function nc(t){const s=t.replaceAll(/[^A-Za-z0-9]+/g,"_").replaceAll(/^_+|_+$/g,"").toUpperCase();return s===""?"":`NB_SEARCH_${s}_API_KEY`}function PL(t,s){const n=`${t}.custom`;if(s.providers[n]===void 0)return n;for(let a=2;a<100;a+=1){const i=`${t}.custom-${a}`;if(s.providers[i]===void 0)return i}return`${t}.custom`}function AL({capabilities:t,draft:s,saving:n=!1,onCancel:a,onCreated:i}){const{t:r}=D(),[o,l]=x.useState(null),[c,d]=x.useState(""),[u,p]=x.useState(""),[h,b]=x.useState(null),m=x.useMemo(()=>t.providers.descriptors.map(T=>({descriptor:T,label:Ti(r,T.provider_id)})),[t.providers.descriptors,r]),f=Qs({listId:"nb-search-provider-types",items:m,keyOf:T=>T.descriptor.provider_id,textOf:T=>[T.label,T.descriptor.provider_id]}),g=T=>{const A=PL(T.provider_id,s);l(T.provider_id),d(A),p(T.activation.credential==="required"?nc(A):""),b(null)},v=m.find(T=>T.descriptor.provider_id===o)?.descriptor,y=v?.activation.credential==="required",w=c,N=c.trim(),_=v===void 0?null:N===""?r("st.nbSearch.custom.instance.idEmpty"):N!==w||N.length>256?r("st.nbSearch.custom.instance.idInvalid"):s.providers[N]!==void 0?r("st.nbSearch.custom.instance.idTaken"):null,C=u.trim(),S=y?C===""?r("st.nbSearch.custom.instance.envRequired"):IL.test(C)?null:r("st.nbSearch.service.credentialEnvInvalid"):null,k=_!==null||S!==null||v===void 0,j=()=>{if(!(v===void 0||k))try{const T=L_(s,t,v.provider_id,N,C===""?void 0:C);i(T,N)}catch(T){b(T instanceof Error?T.message:String(T))}};return e.jsx("div",{className:"space-y-3","data-nb-search-instance-editor":!0,children:v===void 0?e.jsxs(e.Fragment,{children:[e.jsx(he,{children:r("st.nbSearch.custom.instance.pickHint")}),e.jsx(Gs,{view:f,total:m.length,searchLabel:r("st.nbSearch.custom.instance.pickLabel"),searchPlaceholder:r("st.nbSearch.custom.instance.pickPlaceholder"),showDensity:!1}),m.length===0?e.jsx(Ct,{kind:"none",title:r("st.nbSearch.custom.instance.noProviders")}):f.visible.length===0?e.jsx(Ct,{kind:"no-match",title:r("st.nbSearch.services.noMatch",{query:f.query.trim()}),onClear:f.clear}):e.jsx("ul",{className:"space-y-0.5","data-nb-search-provider-options":!0,children:f.visible.map(T=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-nb-search-provider-option":T.descriptor.provider_id,disabled:n,onClick:()=>{g(T.descriptor)},className:"row-interactive flex w-full min-w-0 flex-col items-start gap-0.5 py-1.5 pl-3 pr-2 text-left",children:[e.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:T.label}),e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint",children:T.descriptor.activation.credential==="none"?r("st.nbSearch.services.keyless"):r("st.nbSearch.services.needsKey")})]}),e.jsx("span",{className:"max-w-full truncate font-mono text-[11px] text-ink-faint",children:T.descriptor.provider_id})]})},T.descriptor.provider_id))}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",className:Q,onClick:a,children:r("st.nbSearch.custom.cancel")})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[e.jsx("span",{className:"text-[13px] text-ink",children:Pn(v.provider_id)===void 0?v.provider_id:Ti(r,v.provider_id)}),e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:v.provider_id}),e.jsx("button",{type:"button",className:"ml-auto text-[12px] text-ink-soft transition-colors hover:text-ink",disabled:n,"data-nb-search-instance-change-provider":!0,onClick:()=>{l(null),b(null)},children:r("st.nbSearch.custom.instance.changeProvider")})]}),e.jsxs("label",{className:$e,children:[r("st.nbSearch.custom.instance.idLabel"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:c,disabled:n,spellCheck:!1,autoComplete:"off","aria-label":r("st.nbSearch.custom.instance.idLabel"),"data-nb-search-instance-id":!0,onChange:T=>{const A=T.target.value;d(A),b(null),y&&u===nc(c)&&p(nc(A))}}),e.jsx(it,{id:"nb-search-instance-id-issue",text:_}),_===null?e.jsx("span",{className:"mt-1 block font-normal text-[11px] leading-relaxed text-ink-faint",children:r("st.nbSearch.custom.instance.idHint")}):null]}),y?e.jsxs(et,{summary:r("st.nbSearch.custom.instance.envSection"),children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12px] text-ink-soft",children:r("st.nbSearch.custom.instance.envLabel")}),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:u,disabled:n,spellCheck:!1,autoComplete:"off","aria-label":r("st.nbSearch.custom.instance.envLabel"),"data-nb-search-instance-env":!0,onChange:T=>{p(T.target.value),b(null)}})]}),e.jsx(it,{id:"nb-search-instance-env-issue",text:S}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:r("st.nbSearch.custom.instance.envHint")})]}):null,h!==null?e.jsxs("p",{role:"alert","data-nb-search-instance-issue":!0,className:"text-[12px] leading-4 text-danger",children:[r("st.nbSearch.custom.instance.failed"),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-ink-faint",children:h})]}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Ye,disabled:n||k,"data-nb-search-instance-create":!0,onClick:j,children:r("st.nbSearch.custom.instance.create")}),e.jsx("button",{type:"button",className:Q,disabled:n,onClick:a,children:r("st.nbSearch.custom.cancel")}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-[12px] text-ink-faint",children:[e.jsx(de,{name:"settings",size:12}),r("st.nbSearch.custom.instance.keysLater")]})]})]})})}function $L(t,s){return t.search.lanes.find(n=>s.advanced?.lanes[n.id]===void 0)?.id??t.search.lanes[0]?.id??""}function RL({binding:t,saving:s=!1}){const{t:n,tp:a}=D(),[i,r]=x.useState(null),o=t.capabilities,l=t.draft,c=x.useMemo(()=>jg(o,l.defaultSearchLane),[o,l.defaultSearchLane]),d=l.defaultSearchLane===""?c.laneId:l.defaultSearchLane,u=l.defaultSearchLane==="",p=x.useMemo(()=>{const v=new Map(o.search.lanes.map(y=>[y.id,{id:y.id}]));for(const[y,w]of Object.entries(l.advanced?.lanes??{}))w===null||v.has(y)||v.set(y,{id:y});return[...v.values()]},[o.search.lanes,l]),h=x.useMemo(()=>{const v=new Map;for(const y of o.search.presets)v.set(y.name,{id:y.name,lanes:y.lanes});for(const[y,w]of Object.entries(l.advanced?.presets??{}))w!==null&&v.set(y,{id:y,lanes:w.lanes});return[...v.values()]},[o.search.presets,l]),b=()=>{const v="custom.search";let y=v;for(let _=2;l.advanced?.lanes[y]!==void 0;_+=1)y=`${v}-${_}`;const w=$L(o,l),N=Zr(o,l,w);t.onChange(ks(l,y,N.profile??{provider_instance_id:"",operation_id:"",latency:"medium",cost:"cheap"})),r(`lane:${y}`)},[m,f]=x.useState(!1),g=()=>{const v="preset";let y=v;for(let N=2;l.advanced?.presets[y]!==void 0;N+=1)y=`${v}-${N}`;const w=o.search.lanes.find(N=>N.output.channel==="results")?.id;w!==void 0&&(t.onChange(fn(l,y,{lanes:[w]})),r(`preset:${y}`))};return e.jsxs("div",{className:"space-y-4","data-nb-search-composer":!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:n("st.nbSearch.composer.methodsTitle")}),e.jsxs("span",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s,"data-nb-search-lane-add":!0,onClick:()=>{f(!1),b()},children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.custom.lane.add")]}),e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s,"aria-expanded":m,"data-nb-search-new-instance":!0,onClick:()=>{f(v=>!v)},children:[e.jsx(de,{name:m?"close":"plus",size:12}),n(m?"st.nbSearch.custom.close":"st.nbSearch.custom.instance.add")]})]})]}),m?e.jsx(AL,{capabilities:o,draft:l,saving:s,onCancel:()=>{f(!1)},onCreated:v=>{t.onChange(v),f(!1)}}):null,e.jsx("ul",{className:"space-y-0","data-nb-search-lane-rows":!0,children:p.map(v=>{const y=o.search.lanes.find(T=>T.id===v.id),w=Zr(o,l,v.id),N=i===`lane:${v.id}`,_=y===void 0?"none":T_(y.execution_modes),C=y!==void 0&&y.availability==="ready"&&_==="sync",S=d===v.id,k=w.profile===void 0?void 0:xi(o,l,w.profile.provider_instance_id)??w.profile.provider_instance_id,j=w.profile===void 0||k===void 0?v.id:`${Ti(n,k)} · ${Ei(n,y,w.profile.operation_id,k)}`;return e.jsxs("li",{"data-nb-search-lane-row":v.id,"data-nb-search-lane-origin":w.source,children:[e.jsxs("div",{className:"flex items-start gap-1 py-2 pl-1 pr-1",children:[e.jsxs("button",{type:"button","aria-expanded":N,"data-nb-search-lane-edit":v.id,onClick:()=>{r(N?null:`lane:${v.id}`)},className:"flex min-w-0 flex-1 items-baseline gap-2 rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsxs("span",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:"min-w-0 break-words text-[13px] text-ink",children:j}),e.jsx("span",{className:`shrink-0 text-[12px] ${C?"text-ink-soft":"text-ink-faint"}`,children:n(y===void 0?"st.nbSearch.custom.lane.pending":jL(y.availability,_))}),S?e.jsx("span",{className:"shrink-0 rounded-full bg-panel px-1.5 py-px text-[11px] font-medium text-ink shadow-[var(--kiki-sheet-shadow)]","data-nb-search-lane-default":!0,children:n(u?"st.nbSearch.services.inheritBadge":"st.nbSearch.services.defaultBadge")}):null,e.jsx("span",{className:"text-[11px] text-ink-faint","data-nb-search-lane-source-badge":w.source,children:n(Dh(w.source))}),w.source==="override"?e.jsx("span",{className:"text-[11px] text-ink-soft","data-nb-search-lane-overridden":!0,children:n("st.nbSearch.custom.lane.badgeOverridden")}):null]})}),e.jsx(de,{name:"chevron",size:12,className:`mt-1 shrink-0 text-ink-faint transition-transform ${N?"rotate-90":""}`})]}),S?null:e.jsx("button",{type:"button",className:`${Q} mt-0.5 shrink-0 px-2 py-0.5 text-[11px]`,disabled:s,"data-nb-search-lane-make-default":v.id,onClick:()=>{t.onChange($y(l,v.id))},children:n("st.nbSearch.services.makeDefault")})]}),N?e.jsx("div",{className:"pb-3 pl-4 pr-2",children:e.jsx(EL,{binding:t,laneId:v.id,saving:s,onRename:T=>{r(`lane:${T}`)},onClose:()=>{r(null)}})}):null]},v.id)})})]}),e.jsxs("div",{className:"space-y-2","data-nb-search-presets":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:n("st.nbSearch.custom.preset.group")}),e.jsx(he,{children:n("st.nbSearch.custom.preset.groupHint")})]}),e.jsxs("button",{type:"button",className:`${Q} shrink-0 inline-flex items-center gap-1`,disabled:s,"data-nb-search-preset-add":!0,onClick:g,children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.custom.preset.add")]})]}),h.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:n("st.nbSearch.custom.preset.empty")}):e.jsx("ul",{className:"space-y-0","data-nb-search-preset-rows":!0,children:h.map(v=>{const y=i===`preset:${v.id}`,w=Uy(o,l,v.id).source;return e.jsxs("li",{"data-nb-search-preset-row":v.id,"data-nb-search-preset-origin":w,children:[e.jsxs("div",{className:"flex items-start gap-1 py-2 pl-1 pr-1",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start gap-0.5 rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40","aria-expanded":y,"data-nb-search-preset-open":v.id,onClick:()=>{r(y?null:`preset:${v.id}`)},children:[e.jsxs("span",{className:"flex w-full min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:"min-w-0 break-words text-[13px] text-ink",children:v.id}),e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint","data-nb-search-preset-source-badge":w,children:n(Dh(w))})]}),e.jsx("span",{className:"block max-w-full truncate font-mono text-[11px] text-ink-faint",children:v.lanes.join(" → ")})]}),e.jsx("span",{className:"shrink-0 pt-0.5 text-[12px] text-ink-faint",children:a("st.nbSearch.custom.preset.laneCount",v.lanes.length)})]}),y?e.jsx("div",{className:"pb-3 pl-4 pr-2",children:e.jsx(TL,{binding:t,presetId:v.id,saving:s,onRename:N=>{r(`preset:${N}`)},onClose:()=>{r(null)}})}):null]},v.id)})})]})]})}function LL({capabilities:t,saving:s=!1,advanced:n,keyDrafts:a,onKeyDraftChange:i,readCredential:r,readKeyUsage:o}){const{t:l}=D(),c=n.draft,d=x.useMemo(()=>Do(t,c),[t,c]),u=U=>qu(t,c,d,"lane",U.id)?.instanceId,p=n.config,[h,b]=x.useState(!1),m=U=>{const X=Pn(U);return X===void 0?U:l(X)},[f,g]=x.useState(()=>c.defaultSearchLane===""||Object.keys(c.advanced?.presets??{}).length>0),v=c.advanced?.lanes??{},y=x.useMemo(()=>{const U=br(t),X=new Map(t.providers.descriptors.map(se=>[se.provider_id,se.provider_id])),q=new Set,F=t.search.lanes.flatMap(se=>{const Y=d[se.id]??U[se.id];if(Y===void 0)return[];const O=X.get(Y.provider_id);if(O===void 0)return[];const B=t.providers.descriptors.find(re=>re.provider_id===O);if(B===void 0||B.query_operations.length===0)return[];q.add(se.id);const le=Ei(l,se,Y.operation_id,Y.provider_id);return[{id:se.id,title:mi(m(O),le),subtitle:le,operationId:Y.operation_id,providerId:O,latency:se.latency,cost:se.cost}]}),V=Object.entries(v).flatMap(([se,Y])=>{if(Y==null||q.has(se))return[];const O=X.get(d[se]?.provider_id??"");if(O===void 0)return[];const B=t.providers.descriptors.find(ae=>ae.provider_id===O),le=B?.query_operations.find(ae=>ae.operation_id===Y.operation_id);if(B===void 0||le===void 0)return[];const re=Ei(l,{output:le.output},Y.operation_id,O);return[{id:se,title:mi(m(O),re),subtitle:re,operationId:Y.operation_id,providerId:O,latency:Y.latency,cost:Y.cost}]});return[...F,...V]},[t,v,d,l]),w=x.useMemo(()=>{const U=br(t),X=new Map(t.providers.descriptors.map(V=>[V.provider_id,V.provider_id])),q=$_(t,c).map(V=>({id:V,title:m(V),subtitle:l("st.nbSearch.operation.search"),providerId:V})),F=t.fetch.pipelines.flatMap(V=>{if(y.some(O=>O.id===V.id))return[];const se=U[V.id],Y=se!==void 0?X.get(se.provider_id):X.get(V.stages[0]?.id??"");return Y===void 0?[]:[{id:V.id,title:m(Y),subtitle:l("st.nbSearch.role.fetchShort"),operationId:se?.operation_id,providerId:Y,latency:V.latency,cost:V.cost}]});return[...y,...q,...F]},[t,c,y,l]),N=new Set(Object.entries(c.providers).filter(([,U])=>U.isDeleted===!0).map(([U])=>U)),_=new Set([...Object.keys(p?.provider_instances??{}).filter(U=>!N.has(U)),...Object.entries(c.providers).filter(([,U])=>U.isDeleted!==!0&&U.isNew===!0).map(([U])=>U)]),C=x.useMemo(()=>{const U=t.inherited_configuration?.lanes,X=new Set([...Object.keys(p?.provider_instances??{}),...t.configuration?.provider_instance_ids??[]].filter(q=>!N.has(q)));return y.filter(q=>{const F=u(q);return Object.prototype.hasOwnProperty.call(v,q.id)||U?.[q.id]!==void 0||U===void 0&&t.configuration?.lanes[q.id]!==void 0||F!==void 0&&(X.has(F)||_.has(F))})},[y,v,t,p,_,N,d]),S=x.useMemo(()=>w.filter(U=>!C.some(X=>X.id===U.id)),[w,C]),k=x.useMemo(()=>{const U=new Set([..._,...(t.configuration?.provider_instance_ids??[]).filter(V=>!N.has(V))]),X=new Set(C.map(u)),q=[],F=(V,se)=>{const Y=t.providers.descriptors.find(ne=>ne.provider_id===se),O=br(t),B=t.fetch.pipelines.find(ne=>{const Ee=O[ne.id];return((Ee===void 0?void 0:t.providers.descriptors.some(fe=>fe.provider_id===Ee.provider_id)?Ee.provider_id:void 0)??ne.stages[0]?.id)===se});if((Y?.fetch_operations.length??0)>0||B!==void 0)return;const re=(Y?.query_operations.length??0)>0,ae=l(re?"st.nbSearch.operation.search":"st.nbSearch.role.service");q.push({id:`instance:${V}`,title:re?mi(m(se),ae):m(se),subtitle:ae})};for(const V of t.providers.instances)U.has(V.id)&&(X.has(V.id)||F(V.id,V.provider_id));for(const[V,se]of Object.entries(c.providers))se.isNew!==!0||se.isDeleted===!0||se.providerId===void 0||t.providers.instances.some(Y=>Y.id===V)||X.has(V)||F(V,se.providerId);return q},[p,t,C,c.providers,d,m,l]),[j,T]=x.useState(null),[A,P]=x.useState([]),R=new Set(Object.entries(a).filter(([,U])=>U.mode!=="keep").map(([U])=>U)),L=new Set([...C.filter(U=>{const X=u(U);return X!==void 0&&R.has(X)}).map(U=>U.id),...k.filter(U=>R.has(U.id.slice(9))).map(U=>U.id)]),I=(U,X)=>{X?(P(q=>{const F=new Set(q.filter(V=>L.has(V)));return j!==null&&j!==U&&L.has(j)&&F.add(j),[...F]}),T(U)):(j===U&&T(null),P(q=>q.filter(F=>F!==U&&L.has(F))))},$=U=>j===U||A.includes(U)&&L.has(U),E=x.useMemo(()=>jg(t,c.defaultSearchLane),[t,c.defaultSearchLane]),M=c.defaultSearchLane===""?E.laneId:c.defaultSearchLane,z=c.defaultSearchLane===""&&E.laneId!==void 0,H=Qs({listId:"nb-search-service-directory",items:S,keyOf:U=>U.id,textOf:U=>[U.title,U.subtitle,U.id]});return e.jsx(Me,{id:"st-card-search-providers",title:l("st.nbSearch.providersTitle"),actions:h?e.jsx("button",{type:"button",className:`${Q} shrink-0`,"aria-expanded":h,"data-nb-search-add-service":!0,onClick:()=>{b(!1)},children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"close",size:12}),l("st.nbSearch.services.cancelAdd")]})}):C.length+k.length>0?e.jsx("button",{type:"button",className:`${Q} shrink-0`,"aria-expanded":h,"data-nb-search-add-service":!0,onClick:()=>{b(!0)},children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),l("st.nbSearch.services.add")]})}):void 0,children:e.jsxs("div",{className:"space-y-4","data-nb-search-services-tab":!0,children:[h?e.jsxs("div",{className:"space-y-2","data-nb-search-directory":!0,children:[e.jsx(he,{children:l("st.nbSearch.services.directoryHint")}),e.jsx(Gs,{view:H,total:S.length,searchLabel:l("st.nbSearch.services.directoryTitle"),searchPlaceholder:l("st.nbSearch.services.searchPlaceholder"),showDensity:!1}),S.length===0?e.jsx(Ct,{kind:"none",title:l("st.nbSearch.services.directoryEmpty")}):H.visible.length===0?e.jsx(Ct,{kind:"no-match",title:l("st.nbSearch.services.noMatch",{query:H.query.trim()}),onClear:H.clear}):e.jsx("ul",{className:"space-y-0.5",children:H.visible.map(U=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-nb-search-directory-row":U.id,disabled:s,onClick:()=>{const X=U.providerId===U.id&&t.providers.descriptors.some(F=>F.provider_id===U.id),q=t.fetch.pipelines.some(F=>F.id===U.id);n.onChange(X?R_(c,t,U.id):q?Bu(c,t,U.id,[]):eL(c,U.id)),b(!1)},className:"row-interactive flex w-full min-w-0 items-center gap-2 py-1.5 pl-3 pr-2 text-left",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:U.title}),e.jsx("span",{className:"shrink-0 text-[12px] font-medium text-ink-soft",children:l("st.nbSearch.services.addOne")})]})},U.id))})]}):null,C.length+k.length===0?e.jsx(Ct,{kind:"none",title:l("st.nbSearch.services.emptyTitle"),body:l("st.nbSearch.services.emptyBody"),action:e.jsx("button",{type:"button",className:Ye,"data-nb-search-add-service-empty":!0,onClick:()=>{b(!0)},children:l("st.nbSearch.services.emptyAction")})}):e.jsxs("div",{className:"divide-y divide-hairline rounded-lg border border-hairline","data-nb-search-service-cards":!0,children:[C.map(U=>e.jsx(cd,{card:U,kind:"lane",capabilities:t,draft:c,onChange:n.onChange,keyDraft:a[u(U)??""]??{mode:"keep"},onKeyDraftChange:X=>{const q=u(U);q!==void 0&&i(q,X)},readCredential:r,readKeyUsage:o,saving:s,open:$(U.id),onOpenChange:X=>{I(U.id,X)},defaultState:M===U.id?z?"inherit":"default":"none",onMakeDefault:M===U.id?void 0:()=>{n.onChange($y(c,U.id))},onRemoveService:()=>{const X=u(U),q=tL(c,t,"lane",U.id);n.onChange(q),X!==void 0&&(q.providers[X]===void 0||q.providers[X]?.isDeleted===!0)&&i(X,{mode:"keep"})},removeTitle:l("st.nbSearch.services.removeServiceTitle",{name:U.title})},U.id)),k.map(U=>{const X=U.id.slice(9);return e.jsx(cd,{card:U,kind:"instance",instanceId:X,capabilities:t,draft:c,onChange:n.onChange,keyDraft:a[X]??{mode:"keep"},onKeyDraftChange:q=>{i(X,q)},readCredential:r,readKeyUsage:o,saving:s,open:$(U.id),onOpenChange:q=>{I(U.id,q)}},U.id)})]}),c.defaultSearchLane!==""?e.jsx("div",{className:"flex flex-wrap items-center gap-2 px-1",children:e.jsx("button",{type:"button",className:Q,disabled:s,"data-nb-search-clear-default":!0,onClick:()=>{n.onChange(X5(c))},children:l("st.nbSearch.services.followSourceDefault")})}):null,e.jsx(et,{summary:l("st.nbSearch.services.advancedMethods"),"data-nb-search-methods":!0,open:f,onToggle:U=>{g(U.target.open)},children:e.jsx(RL,{binding:n,saving:s})})]})})}const ML=256,OL=64,ac="any";function ic({n:t}){return e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-hairline/50 font-mono text-[11px] font-semibold text-ink",children:t})}function qh(t){return"pipelines"in t.action?"pipelines":"default"}const DL={"direct.fetch":"st.nbSearch.pipeline.direct-fetch"};function FL(t,s){const n=DL[s];return n===void 0?s:t(n)}function Bh(t,s,n){return"pipelines"in s.action?s.action.pipelines.map(a=>FL(t,a)).join(" → "):n}function qL({binding:t,saving:s=!1}){const{t:n}=D(),a=t.draft.advanced,i=t.capabilities,r=NL(i,t.draft),[o,l]=x.useState(""),[c,d]=x.useState(!1),[u,p]=x.useState(""),[h,b]=x.useState(""),m=x.useRef(1),f=x.useRef([]),g=x.useMemo(()=>new Map(i.fetch.pipelines.map(q=>[q.id,q])),[i.fetch.pipelines]),v=x.useMemo(()=>i.fetch.pipelines.filter(q=>q.input_kinds.includes("url")),[i.fetch.pipelines]),y=a?.fetchChains.find(q=>q.inputKind==="url"&&q.representation==="markdown")?.pipelines??t.draft.fetchChain,w=x.useMemo(()=>{const q=o.trim();if(a===void 0||q==="")return null;try{return Bw({url:q,representation:"markdown",execution:"sync"},r.effective,y)}catch{return null}},[a,o,r,y]);if(a===void 0)return null;const N=a.routing,_=N===void 0?"inherited":N===null?"cleared":"custom",C=N??void 0,S=r.effective.rules;for(;f.current.length<S.length;)f.current.push(`route-row-${m.current++}`);f.current.length>S.length&&(f.current.length=S.length);const k=[...f.current],j=r.effective.builtin_enabled,T=r.effective.enabled,A=q=>{t.onChange({...t.draft,advanced:{...a,routing:q}})},P=()=>({enabled:r.effective.enabled,builtin_enabled:r.effective.builtin_enabled,...r.effective.disabled_builtin_rules.length>0?{disabled_builtin_rules:[...r.effective.disabled_builtin_rules]}:{},rules:r.effective.rules.map(q=>structuredClone(q))}),R=q=>{A(q==="inherited"?void 0:q==="cleared"?null:P())},L=q=>{const F=C??P();A({...F,...q})},I=q=>{L({rules:[...q]})},$=(q,F)=>{I(S.map((V,se)=>se===q?F:V))},E=(q,F)=>{const V=q+F;if(V<0||V>=S.length)return;const se=[...S];[se[q],se[V]]=[se[V],se[q]];const Y=[...f.current];[Y[q],Y[V]]=[Y[V],Y[q]],f.current=Y,I(se)},M=q=>{f.current=f.current.filter((F,V)=>V!==q),I(S.filter((F,V)=>V!==q))},z=(q,F)=>{F.length===0||F.length>OL||$(q,{...S[q],action:{pipelines:[...F]}})},H=()=>{const q=u.trim(),F=h.trim();q===""||F===""||S.some(V=>V.id===q)||(f.current.push(`route-row-${m.current++}`),I([...S,{id:q,match:{origin:F},action:{pipelines:["direct.fetch"]}}]),p(""),b(""),d(!1))},U=u.trim()===""||h.trim()===""||S.some(q=>q.id===u.trim()),X=u.trim()!==""&&S.some(q=>q.id===u.trim());return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("span",{className:"text-[13px] text-ink","data-nb-search-routing-mode":_,children:n(_==="inherited"?"st.nbSearch.routing.modeInherited":_==="cleared"?"st.nbSearch.routing.modeCleared":"st.nbSearch.routing.modeCustom")}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n(_==="inherited"?"st.nbSearch.routing.modeInheritedHint":_==="cleared"?"st.nbSearch.routing.modeClearedHint":"st.nbSearch.routing.modeCustomHint")})]}),e.jsx(He,{value:_,ariaLabel:n("st.nbSearch.routing.mode"),dataAttr:"data-nb-search-routing-mode-choice",disabled:s,choices:[{value:"inherited",label:n("st.nbSearch.advanced.inheritSource")},{value:"custom",label:n("st.nbSearch.advanced.customValue")},{value:"cleared",label:n("st.nbSearch.routing.modeClearedShort")}],onChange:R})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-hairline p-3","data-nb-search-routing-builtin":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:n("st.nbSearch.routing.builtinTitle")}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-routing-package":!0,children:r.reported?n("st.nbSearch.routing.packageMeta",{id:r.effective.package.id,version:r.effective.package.version,maintainer:r.effective.package.maintainer}):n("st.nbSearch.routing.packageUnreported")}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.routing.builtinHint")})]}),e.jsx(He,{value:j?"on":"off",ariaLabel:n("st.nbSearch.routing.builtinTitle"),dataAttr:"data-nb-search-routing-builtin-switch",disabled:s||_==="inherited",choices:[{value:"on",label:n("st.nbSearch.routing.builtinOn")},{value:"off",label:n("st.nbSearch.routing.builtinOff")}],onChange:q=>{L({builtin_enabled:q==="on"})}})]}),r.effective.builtin_rules.length===0?null:e.jsx("ul",{className:"space-y-0","data-nb-search-routing-builtin-rules":!0,children:r.effective.builtin_rules.map(q=>{const F=SL(r,q.id);return e.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5 py-1.5","data-nb-search-routing-builtin-rule":q.id,"data-nb-search-routing-builtin-rule-active":F?"true":"false",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[11px] text-ink",children:q.id}),e.jsx("span",{className:"block break-all font-mono text-[11px] leading-relaxed text-ink-faint",children:q.match.origin})]}),e.jsx("span",{className:"shrink-0 font-mono text-[11px] text-ink-soft",children:Bh(n,q,n("st.nbSearch.routing.builtinDefaultChain"))}),e.jsx("span",{className:`shrink-0 text-[12px] ${F?"text-ink-soft":"text-ink-faint"}`,children:n(F?"st.nbSearch.routing.builtinActive":"st.nbSearch.routing.builtinDisabled")})]},q.id)})}),r.effective.disabled_builtin_rules.length===0?null:e.jsxs("div",{className:"space-y-1.5","data-nb-search-routing-builtin-disabled":!0,children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.routing.builtinDisabledHint",{ids:r.effective.disabled_builtin_rules.join(", ")})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.effective.disabled_builtin_rules.map(q=>e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1 px-2 py-0.5 font-mono text-[11px]`,disabled:s,"data-nb-search-routing-builtin-reenable":q,"aria-label":n("st.nbSearch.routing.enableRule",{id:q}),onClick:()=>{const F=r.effective.disabled_builtin_rules.filter(V=>V!==q);L({disabled_builtin_rules:F})},children:[e.jsx("span",{children:q}),e.jsx(de,{name:"close",size:12})]},q))})]})]}),e.jsxs("div",{className:"space-y-2","data-nb-search-routing-rules":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-soft",children:n("st.nbSearch.routing.userTitle")}),_==="custom"&&S.length<ML?e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s||c,"data-nb-search-routing-add":!0,onClick:()=>{p(`my-rule-${S.length+1}`),b(""),d(!0)},children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.routing.addRule")]}):null]}),S.length===0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-routing-rules-empty":!0,children:n("st.nbSearch.routing.rulesNone")}):e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.routing.orderHint")}),_==="custom"?e.jsxs("fieldset",{disabled:s,className:"space-y-3 disabled:opacity-60",children:[e.jsx("ol",{className:"space-y-3","data-nb-search-routing-rules-list":!0,children:S.map((q,F)=>{const V="pipelines"in q.action?q.action.pipelines:[],se=q.enabled===!1,Y=V.filter(O=>!v.some(B=>B.id===O));return e.jsxs("li",{className:"space-y-2 rounded-lg border border-hairline p-3","data-nb-search-routing-rule":q.id,"data-nb-search-routing-rule-enabled":se?"false":"true",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ic,{n:F+1}),e.jsxs("label",{className:"min-w-0 flex-1 basis-40",children:[e.jsx("span",{className:"sr-only",children:n("st.nbSearch.routing.ruleId",{n:F+1})}),e.jsx("input",{className:`${Ce} font-mono`,value:q.id,spellCheck:!1,autoComplete:"off",placeholder:n("st.nbSearch.routing.ruleIdPlaceholder"),"aria-label":n("st.nbSearch.routing.ruleId",{n:F+1}),"data-nb-search-routing-rule-id":!0,onChange:O=>{$(F,{...q,id:O.target.value})}})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1`,"data-nb-search-routing-rule-up":!0,"aria-label":n("st.nbSearch.routing.moveRuleUp",{n:F+1}),title:n("st.nbSearch.routing.moveRuleUp",{n:F+1}),disabled:F===0,onClick:()=>{E(F,-1)},children:e.jsx(de,{name:"arrowDown",size:12,className:"rotate-180"})}),e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1`,"data-nb-search-routing-rule-down":!0,"aria-label":n("st.nbSearch.routing.moveRuleDown",{n:F+1}),title:n("st.nbSearch.routing.moveRuleDown",{n:F+1}),disabled:F===S.length-1,onClick:()=>{E(F,1)},children:e.jsx(de,{name:"arrowDown",size:12})}),e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1`,"data-nb-search-routing-rule-toggle":!0,"aria-pressed":!se,"aria-label":n(se?"st.nbSearch.routing.enableRule":"st.nbSearch.routing.disableRule",{id:q.id}),title:n(se?"st.nbSearch.routing.enableRule":"st.nbSearch.routing.disableRule",{id:q.id}),onClick:()=>{$(F,{...q,enabled:!se})},children:se?e.jsx(de,{name:"dash",size:12}):e.jsx(de,{name:"check",size:12})}),e.jsx("button",{type:"button",className:`${Q} shrink-0 px-1.5 py-1 text-danger hover:border-danger/40`,"data-nb-search-routing-rule-remove":!0,"aria-label":n("st.nbSearch.routing.removeRule",{id:q.id}),title:n("st.nbSearch.routing.removeRule",{id:q.id}),onClick:()=>{M(F)},children:e.jsx(de,{name:"close",size:12})})]})]}),se?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.routing.ruleDisabledHint")}):null,e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.origin"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:q.match.origin,spellCheck:!1,autoComplete:"off",placeholder:"https://example.com","aria-label":n("st.nbSearch.routing.origin",{n:F+1}),"data-nb-search-routing-rule-origin":!0,onChange:O=>{$(F,{...q,match:{...q.match,origin:O.target.value}})}})]}),e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.pathGlobs"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:(q.match.path_globs??[]).join(", "),spellCheck:!1,autoComplete:"off",placeholder:"/reference/**, /api/**","aria-label":n("st.nbSearch.routing.pathGlobs",{n:F+1}),"data-nb-search-routing-rule-globs":!0,onChange:O=>{const B=O.target.value.split(",").map(le=>le.trim()).filter(le=>le!=="");$(F,{...q,match:{...q.match,path_globs:B.length===0?void 0:B}})}})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[n("st.nbSearch.fetch.representation"),e.jsx("span",{className:"mt-1 block font-normal",children:e.jsx(Qe,{variant:"form",value:q.match.representation??ac,ariaLabel:n("st.nbSearch.routing.representation",{n:F+1}),dataAttr:"data-nb-search-routing-rule-representation",choices:[{value:ac,label:n("st.nbSearch.routing.representationAny")},{value:"markdown",label:n("st.nbSearch.fetch.representation.markdown")},{value:"text",label:n("st.nbSearch.fetch.representation.text")}],onChange:O=>{$(F,{...q,match:{...q.match,representation:O===ac?void 0:O}})}})})]}),e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.action",{n:F+1}),e.jsx("span",{className:"mt-1 block font-normal",children:e.jsx(He,{value:qh(q),ariaLabel:n("st.nbSearch.routing.action",{n:F+1}),dataAttr:"data-nb-search-routing-rule-action",choices:[{value:"pipelines",label:n("st.nbSearch.routing.actionPipelines")},{value:"default",label:n("st.nbSearch.routing.actionDefaultShort")}],onChange:O=>{O==="default"?$(F,{...q,action:{use:"default"}}):z(F,V.length===0?["direct.fetch"]:V)}})})]})]}),qh(q)==="default"?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-routing-rule-default":!0,children:n("st.nbSearch.routing.actionDefaultHint")}):e.jsxs("div",{className:"space-y-1","data-nb-search-routing-rule-pipelines":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:n("st.nbSearch.routing.pipelines")}),V.map((O,B)=>{const le=g.get(O);return e.jsxs("div",{className:"flex items-center gap-2","data-nb-search-routing-pipeline":O,children:[e.jsx(ic,{n:B+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Qe,{variant:"form",mono:!0,value:O,ariaLabel:n("st.nbSearch.routing.pipelineStep",{n:B+1}),dataAttr:"data-nb-search-routing-pipeline-step",choices:[...le===void 0?[{value:O,label:O,hint:n("st.nbSearch.custom.pipelineUnknown")}]:[],...v.map(re=>({value:re.id,label:re.id,hint:`${_i(re.cost)===void 0?re.cost:n(_i(re.cost))} · ${Ci(re.latency)===void 0?re.latency:n(Ci(re.latency))}`}))],onChange:re=>{const ae=[...V];ae[B]=re,z(F,ae)}})}),e.jsx("button",{type:"button",className:`${Q} shrink-0 px-1.5 py-1 text-danger hover:border-danger/40`,"data-nb-search-routing-pipeline-remove":!0,"aria-label":n("st.nbSearch.routing.removePipelineStep",{n:B+1}),title:n("st.nbSearch.routing.removePipelineStep",{n:B+1}),disabled:V.length===1,onClick:()=>{z(F,V.filter((re,ae)=>ae!==B))},children:e.jsx(de,{name:"close",size:12})})]},`${B}:${O}`)}),e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,"data-nb-search-routing-pipeline-add":!0,disabled:v.every(O=>V.includes(O.id)),onClick:()=>{const O=v.find(B=>!V.includes(B.id));O!==void 0&&z(F,[...V,O.id])},children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.addPipeline")]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.routing.pipelinesHint")})]}),Y.length===0?null:e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger","data-nb-search-routing-pipeline-issue":!0,children:n("st.nbSearch.routing.pipelineUnknownNamed",{ids:Y.join(", ")})})]},k[F])})}),c?e.jsxs("div",{className:"space-y-2 rounded-lg border border-hairline p-3","data-nb-search-routing-new":!0,children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.newRuleId"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:u,autoFocus:!0,spellCheck:!1,autoComplete:"off","aria-label":n("st.nbSearch.routing.newRuleId"),"data-nb-search-routing-new-id":!0,onChange:q=>{p(q.target.value)},onKeyDown:q=>{rt(q)||(q.key==="Enter"&&(q.preventDefault(),H()),q.key==="Escape"&&d(!1))}})]}),e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.origin"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:h,spellCheck:!1,autoComplete:"off",placeholder:"https://example.com","aria-label":n("st.nbSearch.routing.origin"),"data-nb-search-routing-new-origin":!0,onChange:q=>{b(q.target.value)},onKeyDown:q=>{rt(q)||(q.key==="Enter"&&(q.preventDefault(),H()),q.key==="Escape"&&d(!1))}})]})]}),X?e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger","data-nb-search-routing-new-issue":!0,children:n("st.nbSearch.routing.duplicateId")}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:U,"data-nb-search-routing-new-save":!0,onClick:H,children:n("st.nbSearch.routing.addRule")}),e.jsx("button",{type:"button",className:Q,"data-nb-search-routing-new-cancel":!0,onClick:()=>{d(!1)},children:n("st.nbSearch.routing.cancel")})]})]}):null]}):e.jsx("ol",{className:"space-y-0","data-nb-search-routing-rules-readonly":!0,children:S.map((q,F)=>e.jsxs("li",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5 py-2",children:[e.jsx(ic,{n:F+1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[11px] text-ink",children:q.id}),e.jsxs("span",{className:"block break-all font-mono text-[11px] leading-relaxed text-ink-faint",children:[q.match.origin,(q.match.path_globs??[]).length>0?` ${(q.match.path_globs??[]).join(" ")}`:""]})]}),e.jsx("span",{className:"shrink-0 font-mono text-[11px] text-ink-soft",children:Bh(n,q,n("st.nbSearch.routing.actionDefault"))})]},`${F}:${q.id}`))}),_==="custom"&&S.some(q=>q.id.trim()===""||q.match.origin.trim()==="")?e.jsx("p",{role:"alert","data-nb-search-routing-issue":!0,className:"text-[12px] leading-4 text-danger",children:n("st.nbSearch.routing.incomplete")}):null]}),e.jsxs("div",{className:"space-y-2 pt-3",children:[e.jsxs("label",{className:$e,children:[n("st.nbSearch.routing.previewTitle"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:o,spellCheck:!1,autoComplete:"off",placeholder:"https://example.com/page","aria-label":n("st.nbSearch.routing.previewTitle"),"data-nb-search-routing-preview-input":!0,onChange:q=>{l(q.target.value)}})]}),w===null?null:e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-routing-preview-result":w.origin,children:w.origin==="user"?n("st.nbSearch.routing.previewMatched",{origin:n("st.nbSearch.routing.originUser"),rule:w.rule_id??"",pipelines:w.pipelines.join(" → ")}):w.origin==="builtin"?n("st.nbSearch.routing.previewMatched",{origin:n("st.nbSearch.routing.originBuiltin"),rule:w.rule_id??"",pipelines:w.pipelines.join(" → ")}):n("st.nbSearch.routing.previewDefault",{pipelines:w.pipelines.join(" → ")})})]}),e.jsxs(et,{summary:n("st.nbSearch.routing.advancedTitle"),children:[e.jsx("p",{"data-nb-search-routing-precedence":!0,children:n("st.nbSearch.routing.precedence")}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-1",children:[e.jsx("p",{"data-nb-search-routing-enabled":T?"true":"false",children:n(T?"st.nbSearch.routing.routingOn":"st.nbSearch.routing.routingOff")}),e.jsx("span",{"data-nb-search-routing-toggle":!0,children:e.jsx(Be,{layout:"bare",label:n("st.nbSearch.routing.title"),checked:T,disabled:s,onChange:q=>{L({enabled:q})}})})]})]})]})}const BL=["markdown","text"];function KL({capabilities:t,saving:s=!1,advanced:n,keyDrafts:a,onKeyDraftChange:i,readCredential:r,readKeyUsage:o}){const{t:l}=D(),c=n.draft,d=x.useMemo(()=>Do(t,c),[t,c]),u=x.useMemo(()=>new Map(z5(l,t,d).map(m=>[m.id,m])),[l,t,d]),p=Ra(t,c,os.inputKind,os.representation),h=m=>{const f=u.get(m);return f!==void 0?f:{id:m,title:m,subtitle:l("st.nbSearch.role.fetchShort")}},b=Ly(t,c,os.inputKind,os.representation);return e.jsx("div",{className:"space-y-4",children:e.jsx(Me,{id:"st-card-search-fetch",title:l("st.nbSearch.fetch.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{children:l("st.nbSearch.fetch.pageHint")}),p.pipelines.length===0?e.jsx(Ct,{kind:"none",title:l("st.nbSearch.chainEmpty")}):e.jsx("div",{className:"divide-y divide-hairline rounded-lg border border-hairline","data-nb-search-fetch-chain":!0,children:p.pipelines.map((m,f)=>{const g=J5(t,c,d,"pipeline",m);return e.jsx(cd,{card:h(m),kind:"pipeline",capabilities:t,draft:c,onChange:n.onChange,keyDraft:g===void 0?{mode:"keep"}:a[g.id]??{mode:"keep"},onKeyDraftChange:v=>{g!==void 0&&i(g.id,v)},readCredential:r,readKeyUsage:o,saving:s,chain:{position:f,length:p.pipelines.length,onMove:v=>{n.onChange(ld(c,t,os.inputKind,os.representation,m,v))},onRemove:()=>{n.onChange(Ry(c,t,os.inputKind,os.representation,m))}}},`${f}:${m}`)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s||b===void 0,"data-nb-search-fetch-add":!0,onClick:()=>{b!==void 0&&n.onChange(Bu(c,t,b,[os]))},children:[e.jsx(de,{name:"plus",size:12}),l("st.nbSearch.addPipeline")]}),p.inherited?null:e.jsx("button",{type:"button",className:Q,disabled:s,"data-nb-search-fetch-restore":!0,onClick:()=>{n.onChange(Sa(c,os.inputKind,os.representation,p.pipelines,!0))},children:l("st.nbSearch.custom.chain.restoreSourceOrder")}),p.inherited?e.jsx("span",{className:"text-[12px] text-ink-faint","data-nb-search-fetch-inherited":!0,children:l("st.nbSearch.custom.chain.pairSource")}):null]}),e.jsx(UL,{capabilities:t,binding:n,saving:s,cards:u}),e.jsxs(is,{title:l("st.nbSearch.routing.title"),help:l("st.nbSearch.routing.help"),children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-chain-role":!0,children:l("st.nbSearch.routing.chainRoleHint")}),e.jsx("fieldset",{disabled:s,className:"space-y-3 disabled:opacity-60",children:e.jsx(qL,{binding:n,saving:s})})]})]})})})}function UL({capabilities:t,binding:s,saving:n,cards:a}){const{t:i,tp:r}=D(),[o,l]=x.useState({inputKind:"inline_text",representation:"markdown"}),c=s.draft,d=Ra(t,c,o.inputKind,o.representation),u=Ly(t,c,o.inputKind,o.representation);return e.jsx(et,{summary:i("st.nbSearch.fetch.otherPairs"),"data-nb-search-fetch-other-pairs":!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2","data-nb-search-fetch-combo":!0,children:[e.jsxs("label",{className:"block text-[12px] font-medium text-ink-soft",children:[i("st.nbSearch.fetch.inputKind"),e.jsx("span",{className:"mt-1 block font-normal",children:e.jsx(Qe,{variant:"form",value:o.inputKind,ariaLabel:i("st.nbSearch.fetch.inputKind"),disabled:n,dataAttr:"data-nb-search-fetch-input",choices:t.fetch.inputs.map(p=>({value:p.kind,label:i(Dy[p.kind]),hint:p.enabled?void 0:i("st.nbSearch.fetch.inputDisabled")})),onChange:p=>{l(h=>({...h,inputKind:p}))}})})]}),e.jsxs("label",{className:"block text-[12px] font-medium text-ink-soft",children:[i("st.nbSearch.fetch.representation"),e.jsx("span",{className:"mt-1 block font-normal",children:e.jsx(Qe,{variant:"form",value:o.representation,ariaLabel:i("st.nbSearch.fetch.representation"),disabled:n,dataAttr:"data-nb-search-fetch-representation",choices:BL.map(p=>({value:p,label:i(Fy[p])})),onChange:p=>{l(h=>({...h,representation:p}))}})})]})]}),d.pipelines.length===0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:i("st.nbSearch.custom.noCompatiblePipeline")}):e.jsx("ol",{className:"space-y-2","data-nb-search-fetch-other-chain":!0,children:d.pipelines.map((p,h)=>e.jsxs("li",{className:"flex items-center gap-2 rounded-lg border border-hairline px-3 py-2",children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-hairline/50 font-mono text-[11px] font-semibold text-ink",children:h+1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:a.get(p)?.title??p}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1`,"aria-label":i("st.nbSearch.movePipelineUp",{n:h+1}),title:i("st.nbSearch.movePipelineUp",{n:h+1}),disabled:n||h===0,onClick:()=>{s.onChange(ld(c,t,o.inputKind,o.representation,p,-1))},children:e.jsx(de,{name:"arrowDown",size:12,className:"rotate-180"})}),e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1`,"aria-label":i("st.nbSearch.movePipelineDown",{n:h+1}),title:i("st.nbSearch.movePipelineDown",{n:h+1}),disabled:n||h===d.pipelines.length-1,onClick:()=>{s.onChange(ld(c,t,o.inputKind,o.representation,p,1))},children:e.jsx(de,{name:"arrowDown",size:12})}),e.jsx("button",{type:"button",className:`${Q} px-1.5 py-1 text-danger hover:border-danger/40`,"aria-label":i("st.nbSearch.removePipeline",{n:h+1}),title:i("st.nbSearch.removePipeline",{n:h+1}),disabled:n||d.pipelines.length===1,onClick:()=>{s.onChange(Ry(c,t,o.inputKind,o.representation,p))},children:e.jsx(de,{name:"close",size:12})})]})]},`${h}:${p}`))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:n||u===void 0,"data-nb-search-fetch-add-other":!0,onClick:()=>{u!==void 0&&s.onChange(Bu(c,t,u,[o]))},children:[e.jsx(de,{name:"plus",size:12}),i("st.nbSearch.addPipeline")]}),d.inherited?e.jsx("span",{className:"text-[12px] text-ink-faint",children:i("st.nbSearch.custom.chain.pairSource")}):e.jsx("button",{type:"button",className:Q,disabled:n,"data-nb-search-fetch-restore-pair":!0,onClick:()=>{s.onChange(Sa(c,o.inputKind,o.representation,d.pipelines,!0))},children:i("st.nbSearch.custom.chain.restoreSourceOrder")})]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:r("st.nbSearch.custom.chain.snapshot",(c.advanced?.fetchChains??[]).filter(p=>!p.inherited).length)})]})})}const Kh={present:"border-success/40 bg-success/10 text-success",missing:"border-amber-rule/60 bg-amber-card text-amber-ink",ignored:"border-hairline bg-paper text-ink-faint",unreadable:"border-danger/40 bg-danger/5 text-danger",invalid:"border-danger/40 bg-danger/5 text-danger",rejected:"border-danger/40 bg-danger/5 text-danger",unknown:"border-hairline bg-paper text-ink-faint"},HL={present:"st.nbSearch.source.credentialsPresent",missing:"st.nbSearch.source.credentialsMissing",ignored:"st.nbSearch.source.credentialsIgnored",unreadable:"st.nbSearch.source.credentialsUnreadable",invalid:"st.nbSearch.source.credentialsInvalid",rejected:"st.nbSearch.source.credentialsRejected",unknown:"st.nbSearch.source.credentialsUnknown"};function zL({capabilities:t,reuseLocalConfig:s,savedReuseLocalConfig:n,onToggleReuseLocal:a,saving:i=!1}){const{t:r}=D(),o=t.config_source,l=o?.local_config??"unknown",c=l==="present"?"st.nbSearch.source.localPresent":l==="missing"?"st.nbSearch.source.localMissing":l==="unreadable"?"st.nbSearch.source.localUnreadable":l==="invalid"?"st.nbSearch.source.localInvalid":l==="ignored"?"st.nbSearch.source.localIgnored":"st.nbSearch.source.localUnknown",d=s!==n,u=o?.layers,p=o?.local_credentials??"unknown",h=HL[p]??"st.nbSearch.source.credentialsUnknown",b=o?.credential_source==="environment+local+managed"?"st.nbSearch.source.credentialEnvironmentLocalManaged":o?.credential_source==="environment+managed"?"st.nbSearch.source.credentialEnvironmentManaged":o?.credential_source==="environment+local"?"st.nbSearch.source.credentialEnvironmentLocal":o?.credential_source==="environment"?"st.nbSearch.source.credentialEnvironment":void 0;return e.jsx(Me,{id:"st-card-search-source",title:r("st.nbSearch.source.title"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:r("st.nbSearch.source.hint")}),e.jsx(ge,{label:r("st.nbSearch.source.reuseLocalLabel"),htmlFor:"nb-search-reuse-local",help:r("st.nbSearch.source.reuseLocalDesc"),children:e.jsx(Be,{id:"nb-search-reuse-local",layout:"bare",label:r("st.nbSearch.source.reuseLocalLabel"),checked:s,disabled:i,onChange:a})}),d?e.jsx("p",{role:"status",className:"text-[12px] text-amber-ink",children:r("st.nbSearch.source.draftHint")}):null,s?e.jsx(he,{children:r("st.nbSearch.source.credentialsHint")}):null,e.jsxs("div",{className:"space-y-1.5 pt-1 text-[11px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-ink-soft",children:r("st.nbSearch.source.localConfigStatus")}),e.jsx("span",{className:`inline-block rounded px-1.5 py-px text-[11px] font-medium border ${Kh[l]??"border-hairline bg-paper text-ink-faint"}`,children:r(c)})]}),o!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-ink-soft",children:r("st.nbSearch.source.credentialsStatus")}),e.jsx("span",{className:`inline-block rounded px-1.5 py-px text-[11px] font-medium border ${Kh[p]??"border-hairline bg-paper text-ink-faint"}`,children:r(h)}),b!==void 0?e.jsxs("span",{className:"text-ink-faint",children:["· ",r(b)]}):null]}):null]}),e.jsx(et,{summary:r("st.nbSearch.source.technicalDetails"),"data-technical-details":!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium text-ink-soft",children:[r("st.nbSearch.source.daemonHost"),":"]})," ",e.jsx("span",{className:"font-mono text-ink",children:r("st.nbSearch.source.daemonHostLocal")})]}),u!==void 0?e.jsxs("div",{className:"pt-1",children:[e.jsx("span",{className:"block font-medium text-ink-soft mb-1.5",children:r("st.nbSearch.source.activeLayers")}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 font-mono text-[11px]",children:u.map((m,f)=>{const g=m==="defaults"?"st.nbSearch.source.layerDefaults":m==="local"?"st.nbSearch.source.layerLocal":m==="environment"?"st.nbSearch.source.layerEnvironment":"st.nbSearch.source.layerKiki";return e.jsxs("div",{className:"flex items-center gap-1.5",children:[f>0?e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint"}):null,e.jsxs("span",{className:"rounded bg-paper border border-hairline px-2 py-1 text-ink",children:[f+1,". ",r(g)]})]},m)})})]}):null,o!==void 0&&o.issues.length>0?e.jsx("div",{children:e.jsx(My,{issues:o.issues})}):null]})})]})})}function QL({binding:t,saving:s=!1}){const{t:n}=D(),a=t.capabilities,i=t.draft.advanced,r=i?.fileScopes,o=x.useMemo(()=>a.configuration?.file_scopes??a.inherited_configuration?.file_scopes??[],[a.configuration,a.inherited_configuration]),l=r??[],c=h=>{i!==void 0&&t.onChange({...t.draft,advanced:{...i,fileScopes:h===void 0?void 0:[...h]}})},d=(h,b)=>{c(l.map((m,f)=>f===h?{...m,...b}:m))},u=r===void 0?"inherit":l.length===0?"none":"custom",p=u==="inherit"?n("st.nbSearch.fileScope.stateInherit",{count:String(o.length)}):u==="none"?n("st.nbSearch.fileScope.stateNone"):n("st.nbSearch.fileScope.stateCustom",{count:String(l.length)});return e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-filescope-state":u,children:p}),u==="inherit"&&o.length>0?e.jsx("ul",{className:"space-y-0","data-nb-search-filescope-inherited":!0,children:o.map(h=>e.jsxs("li",{className:"flex flex-wrap items-baseline gap-x-2 py-1.5",children:[e.jsx("span",{className:"font-mono text-[11px] text-ink",children:h.id}),e.jsx("span",{className:"min-w-0 break-all font-mono text-[11px] text-ink-faint",children:h.root}),h.media_types!==void 0?e.jsx("span",{className:"text-[12px] text-ink-soft",children:h.media_types.join(", ")}):null]},h.id))}):null,u==="custom"?e.jsx("ul",{className:"space-y-0","data-nb-search-filescope-rows":!0,children:l.map((h,b)=>e.jsxs("li",{className:"flex items-start gap-2 py-2",children:[e.jsxs("div",{className:"grid min-w-0 flex-1 gap-2 sm:grid-cols-[minmax(0,0.8fr)_minmax(0,1.4fr)_minmax(0,1fr)]",children:[e.jsxs("label",{className:$e,children:[n("st.nbSearch.fileScope.id"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:h.id,disabled:s,spellCheck:!1,autoComplete:"off","aria-label":`${n("st.nbSearch.fileScope.id")} ${b+1}`,"data-nb-search-filescope-id":!0,onChange:m=>{d(b,{id:m.target.value})}})]}),e.jsxs("label",{className:$e,children:[n("st.nbSearch.fileScope.root"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:h.root,disabled:s,spellCheck:!1,autoComplete:"off",placeholder:n("st.nbSearch.fileScope.rootPlaceholder"),"aria-label":`${n("st.nbSearch.fileScope.root")} ${b+1}`,"data-nb-search-filescope-root":!0,onChange:m=>{d(b,{root:m.target.value})}})]}),e.jsxs("label",{className:$e,children:[n("st.nbSearch.fileScope.mediaTypes"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:(h.media_types??[]).join(", "),disabled:s,spellCheck:!1,autoComplete:"off",placeholder:"text/plain","aria-label":`${n("st.nbSearch.fileScope.mediaTypes")} ${b+1}`,"data-nb-search-filescope-media":!0,onChange:m=>{const f=m.target.value.split(",").map(g=>g.trim()).filter(g=>g!=="");d(b,{media_types:f.length===0?void 0:f})}})]})]}),e.jsx("button",{type:"button",className:`${Q} mt-5 shrink-0 px-1.5 py-1 text-danger hover:border-danger/40`,"aria-label":n("st.nbSearch.fileScope.removeScope",{n:b+1}),title:n("st.nbSearch.fileScope.removeScope",{n:b+1}),disabled:s,"data-nb-search-filescope-remove":!0,onClick:()=>{c(l.filter((m,f)=>f!==b))},children:e.jsx(de,{name:"close",size:12})})]},`${b}:${h.id}`))}):null,(u==="custom"?l:[]).some(h=>h.id.trim()===""||h.root.trim()==="")?e.jsx("p",{role:"alert","data-nb-search-filescope-issue":!0,className:"text-[12px] leading-4 text-danger",children:n("st.nbSearch.fileScope.incomplete")}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s,"data-nb-search-filescope-add":!0,onClick:()=>{const h=[...l,{id:"",root:""}];c(h)},children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.fileScope.add")]}),r!==void 0?e.jsx("button",{type:"button",className:Q,disabled:s,"data-nb-search-filescope-restore":!0,onClick:()=>{c(void 0)},children:n("st.nbSearch.advanced.restoreInherited")}):null,u!=="none"?e.jsx("button",{type:"button",className:Q,disabled:s,"data-nb-search-filescope-clear":!0,onClick:()=>{c([])},children:n("st.nbSearch.fileScope.clear")}):null]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.fileScope.hint")})]})}const rc=64,GL=1e7;function WL({binding:t,saving:s=!1}){const{t:n}=D(),a=t.draft.advanced,[i,r]=x.useState(""),[o,l]=x.useState(!1);if(a===void 0)return null;const c=a.qualityBlockedMarkers,d=c===void 0?"inherit":"custom",u=a.qualityMinContentChars.trim(),p=Number(u),h=u!==""&&(!Number.isInteger(p)||p<0||p>GL),b=g=>{t.onChange({...t.draft,advanced:{...a,qualityMinContentChars:g}})},m=g=>{t.onChange({...t.draft,advanced:{...a,qualityBlockedMarkers:g===void 0?void 0:[...g]}})},f=g=>{const v=g.trim();if(r(""),v===""||v.length>256)return;const y=c??[];y.includes(v)||y.length>=rc||m([...y,v])};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"block text-[12px] font-medium text-ink-soft",children:[n("st.nbSearch.quality.minContentChars"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,inputMode:"numeric",value:a.qualityMinContentChars,disabled:s,placeholder:n("st.nbSearch.advanced.valueInherited"),"aria-label":n("st.nbSearch.quality.minContentChars"),"data-nb-search-quality-min":!0,onChange:g=>{b(g.target.value)}}),h?e.jsx("p",{role:"alert","data-nb-search-quality-issue":!0,className:"mt-1 font-normal text-[12px] leading-4 text-danger",children:n("st.nbSearch.invalidNumber",{value:u})}):e.jsx("span",{className:"mt-1 block font-normal text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.quality.minContentCharsHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-soft",children:n("st.nbSearch.quality.markers")}),e.jsx(He,{value:d,ariaLabel:n("st.nbSearch.quality.markers"),dataAttr:"data-nb-search-quality-mode",disabled:s,choices:[{value:"inherit",label:n("st.nbSearch.advanced.inheritSource")},{value:"custom",label:n("st.nbSearch.advanced.customValue")}],onChange:g=>{g==="inherit"?m(void 0):c===void 0&&m([])}})]}),d==="inherit"?e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-quality-state":"inherit",children:n("st.nbSearch.quality.markersInherit")}):e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"space-y-0","data-nb-search-quality-markers":!0,children:(c??[]).map((g,v)=>e.jsxs("li",{className:"flex items-center gap-2 py-1",children:[e.jsx("span",{className:"min-w-0 flex-1 break-all font-mono text-[11px] text-ink",children:g}),e.jsx("button",{type:"button",className:`${Q} shrink-0 px-1.5 py-1 text-danger hover:border-danger/40`,"aria-label":n("st.nbSearch.quality.removeMarker",{marker:g}),title:n("st.nbSearch.quality.removeMarker",{marker:g}),disabled:s,"data-nb-search-quality-remove":!0,onClick:()=>{m((c??[]).filter((y,w)=>w!==v))},children:e.jsx(de,{name:"close",size:12})})]},`${v}:${g}`))}),(c??[]).length===0?e.jsx("p",{className:"text-[12px] leading-snug text-ink-soft","data-nb-search-quality-state":"none",children:n("st.nbSearch.quality.markersNone")}):null,o?e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("input",{className:`${Ce} font-mono`,value:i,autoFocus:!0,spellCheck:!1,autoComplete:"off",placeholder:n("st.nbSearch.quality.markerPlaceholder"),"aria-label":n("st.nbSearch.quality.addMarker"),"data-nb-search-quality-new":!0,onChange:g=>{r(g.target.value)},onBlur:()=>{f(i),l(!1)},onKeyDown:g=>{rt(g)||(g.key==="Enter"?(g.preventDefault(),f(i),l(!1)):g.key==="Escape"&&(r(""),l(!1)))}})}):e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1`,disabled:s||(c??[]).length>=rc,"data-nb-search-quality-add":!0,onClick:()=>{l(!0)},children:[e.jsx(de,{name:"plus",size:12}),n("st.nbSearch.quality.addMarker")]}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint",children:n("st.nbSearch.quality.markersHint",{max:String(rc)})})]})]})]})}function gs({label:t,hint:s,value:n,onChange:a}){const{t:i}=D(),r=n.trim(),o=Number(r),l=r!==""&&(!Number.isInteger(o)||o<0);return e.jsxs(ge,{label:t,help:l?void 0:s,children:[e.jsx("input",{className:"w-24 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent disabled:cursor-not-allowed disabled:bg-hairline/20 disabled:text-ink-faint",inputMode:"numeric",value:n,onChange:c=>{a(c.target.value)}}),l?e.jsx("p",{role:"alert","data-field-issue":!0,className:"basis-full text-[12px] leading-4 text-danger",children:i("st.nbSearch.invalidNumber",{value:r})}):null]})}function Va({title:t,children:s}){return e.jsx(is,{title:t,children:s})}function VL({execution:t,testRun:s,onUpdateExecution:n,onRunCheck:a,onCancelCheck:i,saving:r=!1,advanced:o}){const{t:l}=D();return e.jsxs(e.Fragment,{children:[e.jsx(Me,{id:"st-card-search-execution",title:l("st.nbSearch.executionTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:l("st.nbSearch.executionHint")}),e.jsxs("fieldset",{disabled:r,className:"space-y-3 disabled:opacity-60",children:[e.jsxs(Va,{title:l("st.nbSearch.groupBudgets"),children:[e.jsx(gs,{label:l("st.nbSearch.maxProviderCalls"),hint:l("st.nbSearch.maxProviderCallsHint"),value:t.maxProviderCalls,onChange:c=>{n({maxProviderCalls:c})}}),e.jsx(gs,{label:l("st.nbSearch.maxConcurrency"),hint:l("st.nbSearch.maxConcurrencyHint"),value:t.maxConcurrency,onChange:c=>{n({maxConcurrency:c})}}),e.jsx(gs,{label:l("st.nbSearch.retryCount"),hint:l("st.nbSearch.retryCountHint"),value:t.retryCount,onChange:c=>{n({retryCount:c})}})]}),e.jsxs(Va,{title:l("st.nbSearch.groupTimeouts"),children:[e.jsx(gs,{label:l("st.nbSearch.searchTimeout"),hint:l("st.nbSearch.searchTimeoutHint"),value:t.searchTimeoutMs,onChange:c=>{n({searchTimeoutMs:c})}}),e.jsx(gs,{label:l("st.nbSearch.fetchTimeout"),hint:l("st.nbSearch.fetchTimeoutHint"),value:t.fetchTimeoutMs,onChange:c=>{n({fetchTimeoutMs:c})}})]}),e.jsxs(Va,{title:l("st.nbSearch.groupFetchLimits"),children:[e.jsx(gs,{label:l("st.nbSearch.maxInlineBytes"),hint:l("st.nbSearch.maxInlineBytesHint"),value:t.maxInlineBytes,onChange:c=>{n({maxInlineBytes:c})}}),e.jsx(gs,{label:l("st.nbSearch.maxSourceBytes"),hint:l("st.nbSearch.maxSourceBytesHint"),value:t.fetchMaxSourceBytes,onChange:c=>{n({fetchMaxSourceBytes:c})}}),e.jsx(gs,{label:l("st.nbSearch.maxResponseBytes"),hint:l("st.nbSearch.maxResponseBytesHint"),value:t.fetchMaxResponseBytes,onChange:c=>{n({fetchMaxResponseBytes:c})}}),e.jsx(gs,{label:l("st.nbSearch.maxContentChars"),hint:l("st.nbSearch.maxContentCharsHint"),value:t.fetchMaxContentChars,onChange:c=>{n({fetchMaxContentChars:c})}}),e.jsx(gs,{label:l("st.nbSearch.maxRedirects"),hint:l("st.nbSearch.maxRedirectsHint"),value:t.fetchMaxRedirects,onChange:c=>{n({fetchMaxRedirects:c})}})]}),o===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx(Va,{title:l("st.nbSearch.fileScope.title"),children:e.jsx(QL,{binding:o,saving:r})}),e.jsx(Va,{title:l("st.nbSearch.quality.title"),children:e.jsx(WL,{binding:o,saving:r})})]})]})]})}),e.jsx(Me,{id:"st-card-search-diagnostics",title:l("st.nbSearch.diagnosticsTitle"),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{children:l("st.nbSearch.diagnosticsHint")}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.status==="running"?e.jsx("button",{type:"button",className:Q,onClick:i,children:l("st.nbSearch.cancel")}):e.jsx("button",{type:"button",className:Q,onClick:a,children:l("st.nbSearch.runCheck")}),s.status==="running"?e.jsx("span",{className:"text-[11px] text-ink-faint",children:l("st.nbSearch.running")}):null]}),s.status==="ok"?e.jsxs("div",{className:"space-y-2 mt-2",children:[e.jsx("p",{className:"font-mono text-[11px] text-ink-faint",children:l("st.nbSearch.lastChecked",{revision:s.result.revision})}),e.jsx("p",{className:"text-[12px] leading-snug text-ink-faint","data-nb-search-check-scope":!0,children:l("st.nbSearch.advanced.checkScope")}),e.jsx(Jr,{label:l("st.nbSearch.webSearch"),state:Ty(s.result.search),readiness:s.result.search}),e.jsx(Jr,{label:l("st.nbSearch.fetchUrl"),state:Iy(s.result.fetch),readiness:s.result.fetch})]}):null,s.status==="error"?e.jsx(pe,{feedback:{tone:"error",text:`${l("st.nbSearch.checkFailed")}: ${s.message}`}}):null,s.status==="cancelled"?e.jsx(pe,{feedback:{tone:"info",text:l("st.nbSearch.cancelled")}}):null]})})]})}const Uh=["search-index-state"];function YL(t){return t!==null&&typeof t=="object"&&"code"in t&&t.code===40401}const JL=new Set(["disabled","runtime_disabled"]);function ZL(){const{t}=D(),{client:s}=be(),n=Oe(),[a,i]=x.useState(!1),[r,o]=x.useState(null),l=je({queryKey:Uh,queryFn:async()=>(await s.searchIndexStatus()).index_state,staleTime:1e4,refetchInterval:!1}),c=l.data,d=async()=>{i(!0),o(null);try{await s.retrySearchIndexer(),o({tone:"success",text:t("st.searchIndex.retried")}),await Promise.all([n.invalidateQueries({queryKey:Uh}),n.invalidateQueries({queryKey:["global-search"]})])}catch(m){o({tone:"error",text:t("st.searchIndex.retryFailed",{reason:m instanceof Error?m.message:String(m)})})}finally{i(!1)}},u=c===void 0?void 0:{indexed:c.indexed_sessions,total:c.total_sessions},p=c===void 0&&l.isError&&YL(l.error),h=p?t("st.searchIndex.notBuilt"):c===void 0?l.isError?t("st.searchIndex.checkFailed",{reason:l.error instanceof Error?l.error.message:String(l.error)}):t("st.searchIndex.checking"):c.state==="unavailable"?t(`sidebar.results.unavailable.${c.reason??"generic"}`):c.state==="building"?t("st.searchIndex.building",u):c.state==="readonly"?t("st.searchIndex.readonly",u):t("st.searchIndex.ready",u),b=c?.state==="unavailable"&&!JL.has(c.reason);return e.jsx(Me,{id:"st-card-search-index",title:t("st.searchIndex.title"),children:e.jsxs("div",{className:"space-y-3","data-search-index-status":c?.state??(p?"not-built":l.isError?"error":"checking"),"data-search-index-reason":c?.reason,children:[e.jsx("p",{role:"status",className:`text-[12.5px] ${c?.state==="unavailable"||l.isError&&!p?"text-danger":"text-ink-soft"}`,children:h}),c?.state==="building"?e.jsx(XL,{indexed:c.indexed_sessions,total:c.total_sessions,label:t("st.searchIndex.title")}):null,b?e.jsx("button",{type:"button",className:Q,"data-search-index-retry":!0,disabled:a,onClick:()=>{d()},children:t(a?"st.searchIndex.retrying":"st.searchIndex.retry")}):l.isError&&!p?e.jsx("button",{type:"button",className:Q,"data-search-index-recheck":!0,onClick:()=>{l.refetch()},children:t("common.retry")}):null,e.jsx(pe,{feedback:r})]})})}function XL({indexed:t,total:s,label:n}){const a=Math.max(s,1),i=Math.min(Math.max(t,0),a);return e.jsx("div",{role:"progressbar","aria-label":n,"aria-valuemin":0,"aria-valuemax":a,"aria-valuenow":i,"data-search-index-progress":!0,className:"h-1.5 w-full max-w-[28rem] overflow-hidden rounded-full bg-hairline",children:e.jsx("div",{className:"h-full rounded-full bg-ink-soft transition-[width] duration-[var(--kiki-motion-quick)] motion-reduce:transition-none",style:{width:`${i/a*100}%`}})})}function eM({dirty:t,saving:s,feedback:n,onSave:a,onDiscard:i}){const{t:r}=D();return t?e.jsxs("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] z-10 mt-2 flex flex-wrap items-center gap-2 border-t border-hairline bg-canvas/95 py-3 backdrop-blur-sm","data-search-action-bar":!0,children:[e.jsx("span",{role:"status",className:"shrink-0 text-[12px] text-ink-faint","data-dirty-indicator":!0,children:r("st.draft.unsaved")}),e.jsx(pe,{feedback:n}),e.jsxs("div",{className:"ml-auto flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:s,onClick:i,children:r("st.nbSearch.action.discard")}),e.jsx("button",{type:"button",className:Ye,disabled:s,onClick:a,children:r(s?"common.saving":"st.nbSearch.save")})]})]}):n===null?null:e.jsx("div",{className:"mt-2 pt-3","data-search-action-bar":!0,children:e.jsx(pe,{feedback:n})})}function tM(t,s){const n=s.replace(/^#/,"");if(n&&Lh[n])return Lh[n];const i=new URLSearchParams(t).get("tab");if(i!==null){const r=P5(i);if(r!==void 0)return r}return"overview"}function oc(){const{client:t}=be(),s=x.useCallback((ie,me)=>t.readNbSearchCredential(ie,me),[t]),n=x.useCallback((ie,me)=>t.readNbSearchKeyUsage(ie,me),[t]),a=x.useCallback((ie,me,fe,Ie)=>t.writeNbSearchCredential(ie,me,fe,Ie),[t]),{t:i,tp:r,locale:o}=D(),l=Oe(),c=Bt(),d=Et(),[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=x.useState({}),[g,v]=x.useState(!1),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(null),[k,j]=x.useState(!1),[T,A]=x.useState({status:"idle"}),P=x.useRef(null),R=x.useRef(new Map),L=x.useCallback(async()=>{const ie=await t.getNbSearchCapabilities();return S(null),C!==null&&(w(me=>me?.tone==="info"?null:me),p(me=>me===null?me:{...me,capabilities:ie})),ie},[t,C]),I=x.useMemo(()=>tM(c.search,c.hash),[c.search,c.hash]),$=ie=>{if(ie===I)return;const me=new URLSearchParams(c.search);me.set("tab",ie),d(`/settings/search?${me.toString()}`)},E=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),M=je({queryKey:["nb-search-capabilities"],queryFn:L,staleTime:3e4}),z=x.useMemo(()=>{if(M.data===void 0||E.data===void 0)return null;const ie=E.data.nb_search_source?.reuse_local_config??M.data.config_source?.reuse_local_config??!0;return{config:E.data.nb_search,sourceConfig:E.data.nb_search_source,capabilities:M.data,draft:{nbSearch:Oc(E.data.nb_search,M.data),reuseLocalConfig:ie}}},[E.data,M.data]);x.useEffect(()=>{u!==null||z===null||N!==null||(p(z),b(z.draft))},[u,z,N]);const H=u?.capabilities,U=x.useMemo(()=>Object.entries(m).filter(([,ie])=>ie.mode!=="keep"),[m]),X=x.useMemo(()=>{if(h===null||u===null)return U.length>0;const ie=vm(u.draft.nbSearch,h.nbSearch),me=u.draft.reuseLocalConfig!==h.reuseLocalConfig;return ie||me||U.length>0},[h,u,U.length]);Ft("nb-search",X),Ft("nb-search-keys",U.length>0);const q=async()=>{j(!0);try{const ie=await L();l.setQueryData(["nb-search-capabilities"],ie),p(me=>me===null?me:{...me,capabilities:ie}),_(null)}catch(ie){u===null?_(ie):S(ie)}finally{j(!1)}};if(h===null||u===null||H===void 0)return e.jsx(Me,{id:"st-card-search-status",title:i("st.nbSearch.statusTitle"),children:N!==null?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"rounded-md border border-amber-rule/60 bg-amber-card px-3 py-1.5 text-[11px] text-amber-ink",children:[i("st.nbSearch.savedStatusFailed"),U.length>0?e.jsx("span",{className:"mt-1 block",children:r("st.nbSearch.savedStatusFailedPendingKeys",U.length)}):null]}),e.jsx(De,{error:N}),e.jsx("button",{type:"button",className:Q,disabled:k,onClick:()=>{q()},children:i("common.retry")})]}):E.isError?e.jsx(De,{error:E.error}):M.isError?e.jsx(De,{error:M.error}):e.jsx(he,{children:i("st.nbSearch.loading")})});const F=O_(H),V=ie=>{b(me=>me===null?me:{...me,nbSearch:{...me.nbSearch,execution:{...me.nbSearch.execution,...ie}}})},se=ie=>{b(me=>me===null?me:{...me,nbSearch:ie})},Y={capabilities:H,draft:h.nbSearch,config:u.config,onChange:se},O=ie=>{b(me=>me===null?me:{...me,reuseLocalConfig:ie})},B=()=>{u&&(b(u.draft),f({}),R.current.clear(),w(null))},le=(ie,me)=>{const fe=m[ie];(me.mode==="keep"||fe?.mode!=="keep"&&me.base!==fe?.base)&&R.current.delete(ie),f(Ie=>{const te={...Ie};return me.mode==="keep"?delete te[ie]:te[ie]=me,te})},re=async()=>{const ie=vm(u.draft.nbSearch,h.nbSearch),me=u.draft.reuseLocalConfig!==h.reuseLocalConfig,fe=Object.entries(m).filter(([,te])=>te.mode!=="keep");if(!ie&&!me&&fe.length===0)return;for(const[,te]of fe){const ee=Oy(i,te);if(ee!==null){w({tone:"error",text:ee}),$("search");return}}let Ie=null;if(ie){let te;try{te=q_(u.config,h.nbSearch,H)}catch(ee){w({tone:"error",text:oe(o,ee)});return}Ie={...te,...me?{nb_search_source:{reuse_local_config:h.reuseLocalConfig}}:{},replace_domains:me?["nb_search","nb_search_source"]:["nb_search"]}}else me&&(Ie={nb_search_source:{reuse_local_config:h.reuseLocalConfig},replace_domains:["nb_search_source"]});v(!0),w(null);try{const te=new Map;if(Ie!==null)for(const[_e,we]of fe){if(we.mode==="keep"||we.base===void 0)continue;const G=await s(_e,!1);G.binding_version===we.base.binding&&te.set(_e,G.binding_version)}const ee=Ie===null?{nb_search:u.config,nb_search_source:u.sourceConfig}:await t.patchConfig(Ie);if(Ie!==null){l.setQueryData(["config"],ee);for(const[_e,we]of te)R.current.set(_e,we)}let K;try{K=await L()}catch(_e){p(null),b(null),_(_e);return}const Z=new Set,ue=[],Te=i("st.nbSearch.keys.conflict");for(const[_e,we]of fe)try{if(we.mode==="keep")continue;const G=oL(we);if(G===void 0)continue;let Le=we.base;const Se=R.current.get(_e);if(Le===void 0||Se!==void 0){const ye=await s(_e,!1);(Le===void 0||Se===Le.binding&&ye.binding_version!==Le.binding)&&(Le={version:ye.version,binding:ye.binding_version}),R.current.delete(_e)}const Fe=Le;f(ye=>ye[_e]!==we?ye:{...ye,[_e]:{...we,base:Fe}}),await a(_e,G,Fe.version,Fe.binding),Z.add(_e)}catch(G){const Le=G!==null&&typeof G=="object"&&"code"in G&&G.code===40941;ue.push(Le?Te:oe(o,G))}let Ne=!1;if(Z.size>0)try{K=await L()}catch(_e){Ne=!0,S(_e)}Ne||l.setQueryData(["nb-search-capabilities"],K);const J={nbSearch:Oc(ee.nb_search,K),reuseLocalConfig:ee.nb_search_source?.reuse_local_config??K.config_source?.reuse_local_config??h.reuseLocalConfig};if(p({config:ee.nb_search,sourceConfig:ee.nb_search_source,capabilities:K,draft:J}),b(J),f(_e=>Object.fromEntries(Object.entries(_e).filter(([we])=>!Z.has(we)))),ue.length>0){const _e=[...new Set(ue)];w({tone:"error",text:_e.length===1&&_e[0]===Te?Te:`${i("st.nbSearch.keys.saveFailed")} ${_e.join(" ")}`})}else w(Ne?{tone:"info",text:i("st.nbSearch.statusRefreshStale")}:{tone:"success",text:i("st.nbSearch.saved")})}catch(te){w({tone:"error",text:oe(o,te)})}finally{v(!1)}},ae=async()=>{const ie=new AbortController;P.current=ie,A({status:"running"});try{const me=await t.testNbSearch(ie.signal);A({status:"ok",result:me})}catch(me){ie.signal.aborted?A({status:"cancelled"}):A({status:"error",message:oe(o,me)})}finally{P.current=null}},ne=()=>{P.current?.abort()},Ee=H.providers.instances.filter(ie=>{const me=h.nbSearch.providers[ie.id];if(me?.isDeleted===!0)return!1;const fe=Q5(ie,me?.enabled??ie.enabled);return fe==="needsKey"||fe==="failed"}).length;return e.jsxs("div",{className:"space-y-4",children:[C!==null?e.jsxs("div",{className:"rounded-md border border-amber-rule/60 bg-amber-card px-3 py-1.5 text-[11px] text-amber-ink","data-nb-search-status-stale":!0,children:[e.jsx("p",{children:i("st.nbSearch.statusRefreshStale")}),e.jsx("button",{type:"button",className:`${Q} mt-1`,disabled:k||g,onClick:()=>{q()},children:i("common.retry")})]}):null,e.jsx(G5,{activeTab:I,onSelectTab:$,attentionCount:Ee,dirty:X}),e.jsx("div",{id:"nb-search-panel-overview",role:"tabpanel","aria-labelledby":"nb-search-tab-overview",className:I==="overview"?"space-y-4":"hidden",children:e.jsx(iL,{capabilities:H,readiness:F,onNavigateToSearch:()=>{$("search")},onNavigateToFetch:()=>{$("fetch")}})}),e.jsx("div",{id:"nb-search-panel-search",role:"tabpanel","aria-labelledby":"nb-search-tab-search",className:I==="search"?"space-y-4":"hidden",children:e.jsx(LL,{capabilities:H,saving:g,advanced:Y,keyDrafts:m,onKeyDraftChange:le,readCredential:s,readKeyUsage:n})}),e.jsx("div",{id:"nb-search-panel-fetch",role:"tabpanel","aria-labelledby":"nb-search-tab-fetch",className:I==="fetch"?"space-y-4":"hidden",children:e.jsx(KL,{capabilities:H,saving:g,advanced:Y,keyDrafts:m,onKeyDraftChange:le,readCredential:s,readKeyUsage:n})}),e.jsx("div",{id:"nb-search-panel-advanced",role:"tabpanel","aria-labelledby":"nb-search-tab-advanced",className:I==="advanced"?"space-y-4":"hidden",children:I==="advanced"?e.jsxs(e.Fragment,{children:[e.jsx(zL,{capabilities:H,reuseLocalConfig:h.reuseLocalConfig,savedReuseLocalConfig:u.draft.reuseLocalConfig,onToggleReuseLocal:O,saving:g}),e.jsx(ZL,{}),e.jsx(VL,{execution:h.nbSearch.execution,testRun:T,onUpdateExecution:V,onRunCheck:()=>{ae()},onCancelCheck:ne,saving:g,advanced:Y})]}):null}),e.jsx(eM,{dirty:X,saving:g,feedback:y,onSave:()=>{re()},onDiscard:B})]})}const zy=["openai_responses","anthropic","openai"],sM=["codex_compatible","claude_code_compatible","grok_build_compatible","opencode_compatible","kimi_code"],Qy=["codex_cli","claude_code","grok_cli","opencode_cli"],lc="example-model",_a="min-w-0 break-all font-mono text-[12px] leading-5 text-ink";function nM(){const{client:t}=be();return je({queryKey:ns,queryFn:()=>t.requestIdentity.get(),staleTime:1e4})}function Gy(t){return{label:t.label,description:t.description,base_preset:t.base_preset,track:t.track,version:t.version,user_agent:t.user_agent,headers:t.headers.map(s=>({...s})),params:t.params.map(s=>({...s}))}}function Hh(t){return t==="claude_code_compatible"?"anthropic":"openai_responses"}function aM(t){return t===void 0?"":JSON.stringify(t,null,2)}function cc(t){return{draft:Gy(t),overridesJson:aM(t.overrides)}}function gr(t,s){return JSON.stringify(t.draft)!==JSON.stringify(s.draft)||t.overridesJson!==s.overridesJson}function Wy(t){const s=t.trim();if(s==="")return;const n=JSON.parse(s);if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("overrides must be an object");return n}function iM(t,s){try{return{...t,overrides:Wy(s)}}catch{return t}}function Zn(t,s){return new Date(s).toLocaleString(t,{dateStyle:"medium",timeStyle:"short"})}function rM(t,s,n){if(s==="fixed")return t("st.identity.versionMode.fixed");if(s==="kiki")return t("st.identity.versionMode.kiki");const a=s.startsWith("track:")?s.slice(6):s,i=n===null?"":t(`st.identity.track.${n}`);return t("st.identity.versionFromTrack",{track:i,origin:t(`st.identity.origin.${a}`)})}function oM(t,s){const n=t.headers.map(a=>({...a}));if(t.version.mode!=="track")return n;for(const a of s?.current.headers??[]){const i=n.findIndex(r=>r.name.toLowerCase()===a.name.toLowerCase());i===-1?n.push({...a}):n[i]={...a}}return n}function zh(){const{t}=D(),s=nM();if(s.isError&&s.data===void 0)return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] text-ink",children:t("st.identity.loadFailed")}),e.jsx(De,{error:s.error})]});const n=s.data;return e.jsxs("div",{className:"space-y-6",children:[e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-snug text-ink-soft",children:t("st.identity.purpose")}),s.isError?e.jsx(De,{error:s.error}):null,e.jsx(UA,{}),e.jsx(lM,{catalog:n}),e.jsx(pM,{catalog:n}),e.jsx(hM,{catalog:n}),e.jsx(fM,{catalog:n})]})}function lM({catalog:t}){const{t:s,locale:n}=D(),{client:a}=be(),i=Oe(),r=x.useMemo(()=>t?.profiles??[],[t?.profiles]),[o,l]=x.useState("codex"),[c,d]=x.useState("list"),[u,p]=x.useState(null),[h,b]=x.useState({}),m=Object.keys(h).length>0;Ft("identity-profiles",Object.keys(h).length>0);const f=r.find(P=>P.id===o)??r[0],g=f===void 0?void 0:cc(f),v=f===void 0||g===void 0?void 0:h[f.id]??{...g,issue:null,overridesIssue:null};x.useEffect(()=>{!m||t===void 0||b(P=>{const R=Object.fromEntries(Object.entries(P).filter(([L,I])=>{const $=r.find(E=>E.id===L);return $!==void 0&&gr(I,cc($))}));return Object.keys(R).length===Object.keys(P).length?P:R})},[t,r,m]);const y=P=>{b(R=>{if(R[P]===void 0)return R;const L={...R};return delete L[P],L})},w=(P,R)=>{b(L=>{const I=i.getQueryData(ns)?.profiles.find(z=>z.id===P);if(I===void 0)return L;const $=cc(I),E={...L[P]??{...$,issue:null,overridesIssue:null},...R},M={...L};return gr(E,$)?M[P]=E:delete M[P],M})},N=(P,R,L)=>{i.setQueryData(ns,R),b(I=>{const $=I[P];if($===void 0||gr($,L))return I;const E={...I};return delete E[P],E}),i.invalidateQueries({queryKey:[...ns,"preview"]})},_=async P=>{p(null);try{const R=await a.requestIdentity.duplicateProfile(P.id,s("st.identity.copyLabel",{label:P.label}));i.setQueryData(ns,R);const L=R.profiles.filter(I=>!I.builtin).at(-1);L!==void 0&&l(L.id)}catch(R){p({tone:"error",text:oe(n,R)})}},C=P=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-identity-row":P.id,"aria-current":P.id===f?.id?"true":void 0,onClick:()=>{l(P.id),d("detail")},className:"row-interactive flex w-full min-w-0 flex-col items-start gap-0.5 py-1.5 pl-3 pr-2 text-left",children:[e.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:P.label}),h[P.id]===void 0?null:e.jsx("span",{className:"shrink-0 text-[11px] text-ink-soft","data-identity-unsaved":!0,children:s("st.identity.rowUnsaved")})]}),j.density==="compact"?null:e.jsx("span",{className:"max-w-full truncate font-mono text-[11px] text-ink-faint",children:P.id})]})},P.id),j=Qs({listId:"identity-profiles",items:r,keyOf:P=>P.id,textOf:P=>[P.label,P.id]}),T=x.useMemo(()=>ng(r,j.visible,P=>[P.builtin?{key:"builtin",label:s("st.identity.builtinGroup")}:{key:"custom",label:s("st.identity.customGroup")}],["builtin","custom"]),[r,j.visible,s]),A=e.jsxs("nav",{"aria-label":s("st.identity.listTitle"),className:"space-y-2",children:[e.jsx(Gs,{view:j,total:r.length,searchLabel:s("st.identity.search"),searchPlaceholder:s("st.identity.searchPlaceholder")}),r.length>0&&j.visible.length===0?e.jsx(Ct,{kind:"no-match",title:s("st.identity.noMatchTitle"),body:j.query.trim()!==""?s("st.identity.noMatches",{query:j.query.trim()}):void 0,onClear:j.clear}):T.map(P=>e.jsx(Xd,{groupKey:P.key,label:P.label,count:P.items.length,total:P.total,folded:j.isFolded(P.key),onToggle:()=>{j.toggleFold(P.key)},children:P.key==="custom"&&P.items.length===0&&!j.narrowed?e.jsx("p",{className:"px-3 text-[12px] leading-snug text-ink-faint",children:s("st.identity.customEmpty")}):e.jsx("ul",{className:"space-y-0.5",children:P.items.map(C)})},P.key))]});return e.jsx(Me,{id:"st-card-identity-profiles",title:s("st.identity.listTitle"),children:t===void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.identity.loading")}):e.jsx(vo,{narrowPane:c,list:A,detail:f===void 0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsx("button",{type:"button","data-identity-back":!0,className:`${Q} md:hidden`,onClick:()=>{d("list")},children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"arrowLeft",size:12}),s("st.identity.listTitle")]})}),f.builtin?e.jsx(dM,{profile:f,catalog:t,onDuplicate:()=>void _(f)},f.id):g===void 0||v===void 0?null:e.jsx(uM,{profile:f,catalog:t,edit:v,baseline:g,onPatch:P=>{w(f.id,P)},onDiscard:()=>{y(f.id)},onSaved:(P,R)=>{N(f.id,P,R)},onDuplicate:()=>void _(f),onDeleted:()=>{y(f.id),l(f.duplicated_from??"codex")}},f.id),e.jsx(pe,{feedback:u})]})})})}function Xr(t,s){return s===null?void 0:t.tracks.find(n=>n.id===s)}function cM(t,s,n){if(s.version.mode==="fixed")return`${s.version.value} · ${t("st.identity.versionMode.fixed")}`;if(s.version.mode==="kiki")return t("st.identity.versionMode.kiki");const a=Xr(n,s.track);return a===void 0?"":`${a.current.version} · ${t(`st.identity.track.${a.id}`)}`}function dM({profile:t,catalog:s,onDuplicate:n}){const{t:a}=D(),i=Gy(t),r=Xr(s,t.track),o=t.version.mode==="track"&&r?.current.user_agent!==void 0?r.current.user_agent:t.user_agent,l=oM(t,r);return e.jsxs("div",{className:"space-y-4","data-identity-detail":t.id,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t.label}),e.jsx(he,{children:a("st.identity.readOnly")})]}),t.base_preset==="none"?null:e.jsx("button",{type:"button",className:Q,"data-identity-duplicate":!0,onClick:n,children:a("st.identity.duplicate")})]}),e.jsxs("dl",{className:"grid grid-cols-[minmax(96px,auto)_minmax(0,1fr)] gap-x-4 gap-y-2 text-[13px]",children:[e.jsx("dt",{className:"text-ink-soft",children:a("st.identity.baseLabel")}),e.jsx("dd",{className:"text-ink",children:a(`st.requestIdentity.option.${t.base_preset}`)}),e.jsx("dt",{className:"text-ink-soft",children:a("st.identity.versionLabel")}),e.jsx("dd",{className:"text-ink",children:cM(a,i,s)}),e.jsx("dt",{className:"text-ink-soft",children:a("st.identity.userAgentLabel")}),e.jsx("dd",{className:o===""?"text-ink-faint":_a,children:o===""?a("st.identity.nativeUserAgent"):o}),l.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-soft",children:a("st.identity.headersLabel")}),e.jsx("dd",{className:"space-y-0.5",children:l.map(c=>e.jsxs("div",{className:_a,children:[e.jsxs("span",{className:"text-ink-soft",children:[c.name,":"]})," ",c.value]},c.name))})]}):null]}),e.jsx(Vy,{profileId:t.id,basePreset:t.base_preset,track:t.track})]})}function uM({profile:t,catalog:s,edit:n,baseline:a,onPatch:i,onDiscard:r,onSaved:o,onDuplicate:l,onDeleted:c}){const{t:d,locale:u}=D(),{client:p}=be(),h=Oe(),{draft:b,overridesJson:m,issue:f,overridesIssue:g}=n,[v,y]=x.useState(!1),[w,N]=x.useState(!1),[_,C]=x.useState(!1),[S,k]=x.useState(null),[j,T]=Je(),A=gr(n,a),P=E=>{i({draft:{...b,...E},issue:null})},R=Xr(s,b.track),L=async()=>{let E;try{E=Wy(m)}catch{i({overridesIssue:d("st.identity.overridesInvalid")});return}y(!0),k(null),i({issue:null,overridesIssue:null});try{const M={...b,version:b.version.mode==="fixed"?{mode:"fixed",value:b.version.value.trim()}:b.version};await p.requestIdentity.updateProfile(t.id,{...M,overrides:E});const z=await p.requestIdentity.get();o(z,n),T()}catch(M){i({issue:oe(u,M)})}finally{y(!1)}},I=async()=>{C(!0);try{const E=await p.requestIdentity.deleteProfile(t.id);h.setQueryData(ns,E),N(!1),c()}catch(E){N(!1),k({tone:"error",text:oe(u,E)})}finally{C(!1)}},$=b.version.mode;return e.jsxs("div",{className:"space-y-4","data-identity-detail":t.id,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:b.label.trim()===""?t.label:b.label}),e.jsxs("p",{className:"font-mono text-[11px] text-ink-faint",children:[t.id,t.duplicated_from===void 0?"":` ← ${t.duplicated_from}`]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:Q,onClick:l,children:d("st.identity.duplicate")}),e.jsx("button",{type:"button",className:Ht,onClick:()=>{N(!0)},children:d("st.identity.delete")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:$e,children:[d("st.identity.nameLabel"),e.jsx("input",{className:`${Ce} mt-1`,value:b.label,maxLength:64,"data-identity-label":!0,onChange:E=>{P({label:E.target.value})}})]}),e.jsxs("div",{children:[e.jsx("span",{className:$e,children:d("st.identity.baseLabel")}),e.jsx("div",{className:"mt-1",children:e.jsx(Qe,{variant:"form",ariaLabel:d("st.identity.baseLabel"),value:b.base_preset,dataAttr:"data-identity-base",choices:sM.map(E=>({value:E,label:d(`st.requestIdentity.option.${E}`)})),onChange:E=>{P({base_preset:E})}})})]})]}),e.jsx(he,{children:d("st.identity.baseHelp")}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:$e,id:`identity-version-${t.id}`,children:d("st.identity.versionLabel")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(He,{ariaLabelledBy:`identity-version-${t.id}`,dataAttr:"data-identity-version-mode",value:$,choices:[{value:"track",label:d("st.identity.versionMode.track")},{value:"fixed",label:d("st.identity.versionMode.fixed")},{value:"kiki",label:d("st.identity.versionMode.kiki")}],onChange:E=>{P(E==="fixed"?{version:{mode:E,value:R?.current.version??"1.0.0"}}:E==="track"?{version:{mode:E},track:b.track??"codex_cli"}:{version:{mode:E}})}}),$==="track"?e.jsx(Qe,{ariaLabel:d("st.identity.trackLabel"),value:b.track??"codex_cli",choices:Qy.map(E=>({value:E,label:`${d(`st.identity.track.${E}`)} · ${Xr(s,E)?.current.version??""}`})),onChange:E=>{P({track:E})}}):null,b.version.mode==="fixed"?e.jsx("input",{className:`${Gt} h-8 w-36 py-0 font-mono`,"aria-label":d("st.identity.versionFixedAria"),"data-identity-version":!0,value:b.version.value,spellCheck:!1,onChange:E=>{P({version:{mode:"fixed",value:E.target.value}})}}):null]}),e.jsx(he,{children:d("st.identity.versionHelp")})]}),e.jsxs("label",{className:`${$e} block`,children:[d("st.identity.userAgentLabel"),e.jsx("input",{className:`${Ce} mt-1 font-mono`,value:b.user_agent,spellCheck:!1,"data-identity-user-agent":!0,onChange:E=>{P({user_agent:E.target.value})}})]}),e.jsx(he,{children:d("st.identity.userAgentHelp")}),e.jsx(Qh,{kind:"header",rows:b.headers,onChange:E=>{P({headers:E})}}),e.jsx(Qh,{kind:"param",rows:b.params,onChange:E=>{P({params:E})}}),e.jsx(et,{summary:d("st.identity.placeholders"),children:e.jsx("p",{className:"mt-1 font-mono text-[11px] leading-5 text-ink-soft",children:d("st.identity.placeholdersList")})}),e.jsx(et,{summary:d("st.identity.overridesLabel"),"data-identity-overrides-details":!0,open:a.overridesJson!==""||m!==""||g!==null?!0:void 0,children:e.jsxs("div",{className:"mt-2 space-y-1.5",children:[e.jsx(he,{children:d("st.identity.overridesHelp")}),e.jsx("textarea",{className:`${Ce} min-h-[96px] font-mono ${g===null?"":"border-danger"}`,"aria-label":d("st.identity.overridesLabel"),"aria-invalid":g!==null,spellCheck:!1,"data-identity-overrides":!0,value:m,placeholder:`{
|
|
246
|
+
"lineage": { "thread_identity": "none" }
|
|
247
|
+
}`,onChange:E=>{i({overridesJson:E.target.value,overridesIssue:null,issue:null})}}),g!==null?e.jsx("p",{role:"alert","data-field-issue":!0,className:"text-[12px] leading-4 text-danger",children:g}):null]})}),f!==null?e.jsx("p",{role:"alert","data-field-issue":!0,className:"text-[12px] leading-4 text-danger",children:f}):null,e.jsx(lt,{id:`identity-${t.id}`,dirty:A,saving:v,saved:j,saveDisabled:b.label.trim()==="",onSave:()=>void L(),onDiscard:r}),e.jsx(pe,{feedback:S}),e.jsx(Vy,{profileId:t.id,basePreset:b.base_preset,track:b.track,draft:A?iM(b,m):void 0}),e.jsx(Xe,{open:w,busy:_,title:d("st.identity.deleteTitle",{label:t.label}),body:d("st.identity.deleteBody"),confirmLabel:d("st.identity.delete"),onConfirm:()=>void I(),onCancel:()=>{N(!1)}})]})}function Qh({kind:t,rows:s,onChange:n}){const{t:a}=D(),i=a(t==="header"?"st.identity.headersLabel":"st.identity.paramsLabel"),r=(o,l)=>{n(s.map((c,d)=>d===o?{...c,...l}:c))};return e.jsxs("fieldset",{className:"space-y-1.5","data-identity-pairs":t,children:[e.jsx("legend",{className:$e,children:i}),s.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:a("st.identity.none")}):e.jsx("div",{className:"space-y-1.5",children:s.map((o,l)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-1.5",children:[e.jsx("input",{className:`${Ce} font-mono`,value:o.name,spellCheck:!1,"aria-label":a(t==="header"?"st.identity.headerName":"st.identity.paramName"),onChange:c=>{r(l,{name:c.target.value})}}),e.jsx("input",{className:`${Ce} font-mono`,value:String(o.value),spellCheck:!1,"aria-label":a(t==="header"?"st.identity.headerValue":"st.identity.paramValue"),placeholder:t==="header"?a("st.identity.removedPlaceholder"):void 0,onChange:c=>{r(l,{value:c.target.value})}}),e.jsx("button",{type:"button",className:"flex h-8 w-8 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink","aria-label":a("st.identity.removeRow",{name:o.name||i}),onClick:()=>{n(s.filter((c,d)=>d!==l))},children:e.jsx(de,{name:"close",size:14})})]},l))}),e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx(he,{children:a(t==="header"?"st.identity.headersHelp":"st.identity.paramsHelp")}),e.jsx("button",{type:"button",className:Q,onClick:()=>{n([...s,{name:"",value:""}])},children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(de,{name:"plus",size:12}),a(t==="header"?"st.identity.addHeader":"st.identity.addParam")]})})]})]})}function Vy({profileId:t,basePreset:s,track:n,draft:a}){const{t:i}=D(),{client:r}=be(),[o,l]=x.useState(Hh(s));x.useEffect(()=>{l(Hh(s))},[s]);const c=a===void 0?null:JSON.stringify(a),[d,u]=x.useState(c);x.useEffect(()=>{const g=setTimeout(()=>{u(c)},300);return()=>{clearTimeout(g)}},[c]);const p=je({queryKey:[...ns,"preview",t,o,d],queryFn:()=>r.requestIdentity.preview(d===null?{profile:t,protocol:o,model:lc}:{draft:JSON.parse(d),protocol:o,model:lc}),placeholderData:g=>g}),h=p.data,b=h===void 0?[]:Object.entries(h.params),m=h?.headers.find(g=>g.name.toLowerCase()==="user-agent"),f=h===void 0?0:h.headers.length+b.length;return e.jsxs("section",{"aria-labelledby":`identity-preview-${t}`,className:"space-y-2 pt-4","data-identity-preview":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h4",{id:`identity-preview-${t}`,className:"text-[13px] font-medium text-ink",children:i(a===void 0?"st.identity.previewTitle":"st.identity.previewTitleDraft")}),e.jsx(He,{ariaLabel:i("st.identity.previewProtocol"),value:o,dataAttr:"data-identity-preview-protocol",choices:zy.map(g=>({value:g,label:i(`st.identity.protocol.${g}`)})),onChange:l})]}),p.isError?e.jsx(De,{error:p.error}):null,h===void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:i("st.identity.previewLoading")}):h.error!==void 0?e.jsx("p",{role:"alert","data-preview-error":!0,className:"text-[12px] leading-5 text-danger",children:i("st.identity.previewUnsupported",{error:h.error})}):e.jsxs("div",{className:"space-y-2","aria-busy":p.isFetching,children:[e.jsxs("dl",{className:"grid grid-cols-[minmax(72px,auto)_minmax(0,1fr)] gap-x-4 gap-y-1.5 text-[13px]",children:[e.jsx("dt",{className:"text-ink-soft",children:i("st.identity.userAgentLabel")}),e.jsx("dd",{children:m===void 0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:i(h.suppressed_user_agent?"st.identity.suppressedUa":"st.identity.none")}):e.jsx("span",{className:_a,children:m.value})}),e.jsx("dt",{className:"text-ink-soft",children:i("st.identity.versionLabel")}),e.jsx("dd",{className:"text-[12px] leading-5 text-ink-soft","data-preview-version":!0,children:i("st.identity.previewVersion",{version:h.version,origin:rM(i,h.version_origin,n),protocol:i(`st.identity.protocol.${o}`),model:lc})})]}),f===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:i("st.identity.noHeaders")}):e.jsx(et,{"data-preview-details":!0,className:"text-[12px] text-ink-soft",summary:i("st.identity.previewHeaders",{count:f}),children:e.jsx("table",{className:"w-full table-fixed border-collapse text-left",children:e.jsxs("tbody",{children:[h.headers.map(g=>e.jsx(hi,{name:g.name,value:g.value,attr:{"data-preview-header":g.name},note:e.jsxs(e.Fragment,{children:[i(g.origin==="profile"?"st.identity.fromProfile":"st.identity.fromLineage"),g.kind==="per_request"?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{title:i("st.identity.perRequestHelp"),children:i("st.identity.perRequest")})]}):null]})},`h:${g.name}`)),b.length>0?e.jsx("tr",{children:e.jsx("th",{scope:"rowgroup",colSpan:2,className:"pb-1 pt-3 text-left text-[12px] font-medium text-ink-soft",children:i("st.identity.paramsLabel")})}):null,b.map(([g,v])=>e.jsx(hi,{name:g,value:String(v),attr:{"data-preview-param":g}},`p:${g}`))]})})}),a===void 0?null:e.jsx(he,{children:i("st.identity.previewUnsaved")})]})]})}function hi({name:t,value:s,note:n,attr:a}){return e.jsxs("tr",{className:"border-t border-hairline/70 align-top first:border-t-0",...a,children:[e.jsx("th",{scope:"row",className:"w-[36%] py-1.5 pr-3 font-mono text-[12px] font-normal leading-5 text-ink-soft",children:e.jsx("span",{className:"break-all",children:t})}),e.jsxs("td",{className:"py-1.5",children:[e.jsx("span",{className:`block select-all ${_a}`,children:s}),n===void 0?null:e.jsx("span",{className:"text-[11px] text-ink-faint",children:n})]})]})}function pM({catalog:t}){const{t:s}=D();return e.jsxs(Me,{id:"st-card-identity-tracks",title:s("st.identity.tracksTitle"),children:[e.jsx("div",{className:"mb-3",children:e.jsx(he,{children:s("st.identity.tracksHint")})}),t===void 0?null:e.jsx("div",{className:"divide-y divide-hairline",children:t.tracks.map(n=>e.jsx(mM,{track:n},n.id))}),t===void 0?null:e.jsx(xM,{url:t.manifest_url})]})}function mM({track:t}){const{t:s,locale:n}=D(),{client:a}=be(),i=Oe(),[r,o]=x.useState(null),[l,c]=x.useState(null),d=async(m,f)=>{o(m),c(null);try{i.setQueryData(ns,await f()),i.invalidateQueries({queryKey:[...ns,"preview"]})}catch(g){c({tone:"error",text:oe(n,g)})}finally{o(null)}},u=m=>s(`st.identity.origin.${m}`),p=m=>d(`check:${m}`,()=>a.requestIdentity.checkTrack(t.id,m)),h=t.history[0],b=t.last_check;return e.jsxs("div",{className:"space-y-2 py-3 first:pt-0","data-identity-track":t.id,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-6 gap-y-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[13px] text-ink",children:[s(`st.identity.track.${t.id}`)," ",e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",children:t.npm_package})]}),e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-mono text-[15px] tabular-nums text-ink","data-track-current":!0,children:t.current.version}),e.jsxs("span",{className:"text-[12px] text-ink-faint",children:[s("st.identity.trackSourceLine",{origin:u(t.current.origin),at:Zn(n,t.current.at)}),t.current.source_detail!==void 0&&t.current.origin!=="builtin"?` · ${t.current.source_detail}`:""]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,"data-track-check":"npm",disabled:r!==null,onClick:()=>void p("npm"),children:s(r==="check:npm"?"st.identity.checking":"st.identity.checkNpm")}),e.jsx("button",{type:"button",className:Q,"data-track-check":"local_cli",disabled:r!==null,onClick:()=>void p("local_cli"),children:s(r==="check:local_cli"?"st.identity.checking":"st.identity.checkLocal")}),e.jsx(Be,{label:s("st.identity.pin"),checked:t.pinned,disabled:r!==null,onChange:m=>void d("pin",()=>a.requestIdentity.pinTrack(t.id,m))})]})]}),t.candidate!==null?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md bg-attention-soft/60 px-3 py-2","data-track-candidate":!0,role:"status",children:[e.jsxs("span",{className:"mr-auto min-w-0 text-[13px] text-ink",children:[e.jsx("span",{className:"font-medium text-attention",children:s("st.identity.candidate",{version:t.candidate.version,origin:u(t.candidate.origin)})}),e.jsxs("span",{className:"ml-2 text-[12px] text-ink-faint",children:[Zn(n,t.candidate.at),t.candidate.source_detail===void 0?"":` · ${t.candidate.source_detail}`]}),t.candidate.user_agent!==void 0?e.jsxs("span",{className:`block ${_a}`,children:["User-Agent: ",t.candidate.user_agent]}):null,(t.candidate.headers??[]).map(m=>e.jsxs("span",{className:`block ${_a}`,children:[m.name,": ",m.value]},m.name))]}),e.jsx("button",{type:"button",className:Q,"data-track-apply":!0,disabled:r!==null||t.pinned,onClick:()=>void d("apply",()=>a.requestIdentity.applyTrack(t.id,t.candidate.version)),children:s("st.identity.apply",{version:t.candidate.version})}),e.jsx("button",{type:"button",className:Q,disabled:r!==null,onClick:()=>void d("dismiss",()=>a.requestIdentity.trackAction(t.id,"dismiss")),children:s("st.identity.dismiss")})]}):null,b!==null&&t.candidate===null?e.jsx("p",{className:`text-[12px] ${b.ok?"text-ink-faint":"text-danger"}`,role:b.ok?void 0:"alert",children:b.ok?s("st.identity.lastCheckOk",{at:Zn(n,b.at),version:b.version??t.current.version}):s("st.identity.lastCheckFailed",{at:Zn(n,b.at),error:b.error??""})}):null,t.pinned?e.jsx(he,{children:s("st.identity.pinnedNote")}):null,h===void 0&&t.current.origin==="builtin"?null:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h!==void 0?e.jsx("button",{type:"button",className:Q,disabled:r!==null||t.pinned,"data-track-rollback":!0,onClick:()=>void d("rollback",()=>a.requestIdentity.trackAction(t.id,"rollback")),children:s("st.identity.rollback",{version:h.version})}):null,t.current.origin!=="builtin"?e.jsx("button",{type:"button",className:Q,disabled:r!==null||t.pinned,"data-track-reset":!0,onClick:()=>void d("reset",()=>a.requestIdentity.trackAction(t.id,"reset")),children:s("st.identity.reset")}):null,t.history.length>0?e.jsx(et,{summary:s("st.identity.history"),children:e.jsx("ul",{className:"space-y-0.5",children:t.history.map((m,f)=>e.jsxs("li",{className:"font-mono text-[11px]",children:[m.version," ",e.jsxs("span",{className:"font-sans text-ink-faint",children:["· ",u(m.origin)," · ",Zn(n,m.at),m.source_detail!==void 0&&m.origin!=="builtin"?` · ${m.source_detail}`:""]})]},`${m.version}-${String(f)}`))})}):null]}),e.jsx(pe,{feedback:l})]})}function xM({url:t}){const{t:s,locale:n}=D(),{client:a}=be(),i=Oe(),r=bt(),[o,l]=x.useState(null),[c,d]=x.useState(!1),u=async()=>{d(!0),l(null);try{let p;for(const h of Qy)p=await a.requestIdentity.checkTrack(h,"manifest");p!==void 0&&i.setQueryData(ns,p)}catch(p){l({tone:"error",text:oe(n,p)})}finally{d(!1)}};return e.jsxs("div",{className:"mt-4 pt-4",children:[e.jsx(ge,{label:s("st.identity.manifestLabel"),help:s("st.identity.manifestHelp"),layout:"stack",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-2",children:[e.jsx(kt,{value:t??"",className:"w-[min(100%,28rem)] font-mono",ariaLabel:s("st.identity.manifestLabel"),placeholder:"https://example.com/request-identity.json",validate:p=>p===""||p.startsWith("https://")?null:s("st.identity.manifestHttps"),onCommit:p=>void r.run(async()=>{i.setQueryData(ns,await a.requestIdentity.setManifestUrl(p===""?null:p))})}),e.jsx(ot,{saving:r.saving,saved:r.saved}),e.jsx("button",{type:"button",className:Q,disabled:t===null||c,onClick:()=>void u(),children:s(c?"st.identity.checking":"st.identity.checkManifest")})]})}),e.jsx(pe,{feedback:r.error}),e.jsx(pe,{feedback:o})]})}function hM({catalog:t}){const{t:s}=D(),n=Tt(),a=o=>t?.profiles.find(l=>l.id===o)?.label??o??"—",i=o=>o.authored===void 0?s("st.identity.usageInherit"):o.authored.profile!==void 0?a(o.authored.profile):o.authored.preset!==void 0?s(`st.requestIdentity.option.${o.authored.preset}`):s("st.requestIdentity.option.custom_overrides"),r=t?.usage??[];return e.jsxs(Me,{id:"st-card-identity-usage",title:s("st.identity.usageTitle"),children:[r.length===0?null:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[520px] table-fixed border-collapse text-left text-[13px]",children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-[34%]"}),e.jsx("col",{className:"w-[30%]"}),e.jsx("col",{})]}),e.jsx("thead",{children:e.jsxs("tr",{className:"text-[12px] text-ink-soft",children:[e.jsx("th",{scope:"col",className:"pb-1.5 pr-4 font-medium",children:s("st.identity.usageLayer")}),e.jsx("th",{scope:"col",className:"pb-1.5 pr-4 font-medium",children:s("st.identity.usageSetting")}),e.jsx("th",{scope:"col",className:"pb-1.5 font-medium",children:s("st.identity.usageEffective")})]})}),e.jsx("tbody",{children:r.map(o=>e.jsxs("tr",{className:"border-t border-hairline align-top","data-identity-usage":o.scope,children:[e.jsxs("td",{className:"py-1.5 pr-4",children:[e.jsx("span",{className:o.scope==="model"?"block pl-4 text-ink":"block text-ink",children:o.scope==="global"?s("st.identity.usageGlobal"):o.label}),o.scope==="model"&&o.provider_id!==void 0?e.jsx("span",{className:"block truncate pl-4 font-mono text-[11px] text-ink-faint",title:o.provider_id,children:o.provider_id}):null]}),e.jsx("td",{className:`py-1.5 pr-4 ${o.authored===void 0?"text-ink-faint":"text-ink"}`,children:i(o)}),e.jsx("td",{className:"py-1.5",children:o.error!==void 0?e.jsx("span",{className:"text-danger",role:"alert",children:o.error}):e.jsx("span",{className:"text-ink",children:a(o.effective_profile)})})]},`${o.scope}:${o.provider_id??""}:${o.model_id??""}`))})]})}),e.jsx("div",{className:"pt-3",children:e.jsx("button",{type:"button",className:Q,onClick:()=>{n("/settings/ai?tab=providers")},children:s("st.identity.usageEdit")})})]})}function fM({catalog:t}){const{t:s,locale:n}=D(),a=t?.observations??[],i=r=>zy.includes(r)?s(`st.identity.protocol.${r}`):r;return e.jsx(Me,{id:"st-card-identity-recent",title:s("st.identity.recentTitle"),scope:"readOnly",children:a.length===0?e.jsx(he,{children:s("st.identity.recentEmpty")}):e.jsxs("div",{className:"space-y-3",children:[a.slice(0,5).map((r,o)=>e.jsxs("details",{open:o===0,"data-identity-observation":!0,children:[e.jsxs("summary",{className:"flex cursor-pointer select-none flex-wrap items-baseline gap-x-2 text-[13px] text-ink",children:[e.jsx("span",{className:"font-medium",children:t?.profiles.find(l=>l.id===r.profile)?.label??r.profile}),e.jsxs("span",{className:"text-[12px] text-ink-faint",children:[s("st.identity.recentMeta",{provider:r.provider_id,model:r.model,at:Zn(n,r.at)})," · ",i(r.protocol)]})]}),e.jsx("table",{className:"mt-1.5 w-full table-fixed border-collapse text-left",children:e.jsxs("tbody",{children:[r.headers.map(l=>e.jsx(hi,{name:l.name,value:l.value,attr:{"data-observed-header":l.name}},`h:${l.name}`)),Object.entries(r.params).map(([l,c])=>e.jsx(hi,{name:l,value:String(c),attr:{"data-observed-param":l}},`p:${l}`)),r.cache_key===void 0?null:e.jsx(hi,{name:s("st.identity.cacheKey"),value:r.cache_key,attr:{"data-observed-param":"cache_key"}})]})}),r.suppressed_user_agent?e.jsx(he,{children:s("st.identity.suppressedUa")}):null]},`${r.at}-${String(o)}`)),a.length>5?e.jsx(he,{children:s("st.identity.recentMore",{count:a.length-5})}):null]})})}const bM=[{kind:"approval",labelKey:"st.away.approval"},{kind:"question",labelKey:"st.away.question"},{kind:"completed",labelKey:"st.away.completed"},{kind:"failed",labelKey:"st.away.failed"}];function Gh(){const t=mt(),{t:s}=D(),n=x.useSyncExternalStore(io,ro,oo),[a,i]=x.useState(()=>ss().notifications),r=t.notify!==void 0,[o,l]=x.useState(()=>t.kind==="browser"&&r?Fp():void 0);x.useEffect(()=>{if(!r){l(void 0);return}let d=!0;const u=()=>{if(t.kind==="tauri"){Kw().then(p=>{d&&l(p)}).catch(()=>{d&&l(void 0)});return}t.kind==="browser"&&l(Fp())};return u(),window.addEventListener("focus",u),document.addEventListener("visibilitychange",u),()=>{d=!1,window.removeEventListener("focus",u),document.removeEventListener("visibilitychange",u)}},[t.kind,r]),x.useEffect(()=>{t.kind==="tauri"&&t.readDesktopPrefs().then(d=>{d!==null&&i(d.notifications)})},[t]);const c=d=>{i(d),Fs({notifications:d}),t.kind==="tauri"&&t.writeDesktopPrefs({notifications:d})};return e.jsx(Me,{id:"st-card-notify-away",title:s("st.away.title"),scope:"app",aside:r?void 0:s("st.away.browserHint"),children:r?e.jsxs("div",{className:"min-w-0 space-y-4","data-notify-away":!0,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ze,{children:e.jsx(ge,{label:s("st.away.enabled"),htmlFor:"notify-away-enabled",help:s("st.away.hint"),children:e.jsx(Be,{id:"notify-away-enabled",layout:"bare",label:s("st.away.enabled"),checked:a,onChange:c})})}),o!==void 0?e.jsx("p",{"data-notify-os-permission":o,className:`text-[12px] leading-snug ${o==="denied"?"text-amber-ink":"text-ink-soft"}`,children:s(`st.notifications.osPermission.${o}`)}):null]}),a?e.jsxs("fieldset",{"data-notify-away-kinds":!0,className:"min-w-0 space-y-1",children:[e.jsx("legend",{className:"px-0 pb-1 text-[13px] font-medium text-ink",children:s("st.away.kindsLabel")}),e.jsx(Ze,{children:bM.map(({kind:d,labelKey:u})=>e.jsx("div",{"data-notify-away-kind":d,children:e.jsx(ge,{label:s(u),help:d==="completed"?s("st.away.completedHint"):void 0,children:e.jsx(Be,{layout:"bare",label:s(u),checked:n.awayNotifications[d],onChange:p=>{Mt({awayNotifications:{...n.awayNotifications,[d]:p}})}})})},d))})]}):null]}):null})}const Yy=new Set(["script"]),gM={telegram:"st.notify.provider.telegram",wecom_webhook:"st.notify.provider.wecom_webhook",discord_webhook:"st.notify.provider.discord_webhook",slack_webhook:"st.notify.provider.slack_webhook",dingtalk_webhook:"st.notify.provider.dingtalk_webhook",feishu_webhook:"st.notify.provider.feishu_webhook",http:"st.notify.provider.http",windows_toast:"st.notify.provider.windows_toast",smtp:"st.notify.provider.smtp",matrix:"st.notify.provider.matrix",script:"st.notify.provider.script"},vM={"telegram.token_slot":"st.notify.field.botToken","wecom_webhook.key_slot":"st.notify.field.webhookKey","discord_webhook.webhook_id":"st.notify.field.webhookId","discord_webhook.token_slot":"st.notify.field.webhookToken","slack_webhook.path_slot":"st.notify.field.webhookPath","dingtalk_webhook.token_slot":"st.notify.field.webhookToken","dingtalk_webhook.secret_slot":"st.notify.field.signingSecret","dingtalk_webhook.keyword":"st.notify.field.keyword","feishu_webhook.token_slot":"st.notify.field.webhookToken","feishu_webhook.secret_slot":"st.notify.field.signingSecret","http.endpoint":"st.notify.field.endpoint","http.format":"st.notify.field.format","http.auth_slot":"st.notify.field.bearerToken","http.path_slot":"st.notify.field.privatePath","http.private_grant":"st.notify.field.privateGrant","telegram.chat_id":"st.notify.field.chatId","telegram.message_thread_id":"st.notify.field.topicId"},yM={telegram:"st.notify.guide.telegram",wecom_webhook:"st.notify.guide.wecom_webhook",dingtalk_webhook:"st.notify.guide.dingtalk_webhook",feishu_webhook:"st.notify.guide.feishu_webhook",discord_webhook:"st.notify.guide.discord_webhook",slack_webhook:"st.notify.guide.slack_webhook",http:"st.notify.guide.http"};function eo(t){return yM[t]}function Fo(t,s){const n=gM[s];return n===void 0?s:t(n)}function Os(t,s,n){const a=vM[`${s}.${n.key}`];return a===void 0?n.label:t(a)}function kM(t){return t.can_send&&t.status!=="dependency_missing"&&!Yy.has(t.id)}function Ku(t){return t==="desktop_host_unavailable"?"st.notify.reason.desktop_host_unavailable":t==="adapter_not_installed"?"st.notify.reason.adapter_not_installed":"st.notify.reason.unknown"}const jM={auth:"st.notify.error.auth",forbidden:"st.notify.error.forbidden",not_found:"st.notify.error.not_found",rate_limited:"st.notify.error.rate_limited",transient:"st.notify.error.transient",too_long:"st.notify.error.too_long",bad_format:"st.notify.error.bad_format",dependency_missing:"st.notify.error.dependency_missing",configuration:"st.notify.error.configuration",protocol:"st.notify.error.protocol",unknown:"st.notify.error.unknown"};function dd(t){return jM[t??"unknown"]??"st.notify.error.unknown"}function Uu(t,s,n,a){if(n===void 0||n.status==="dependency_missing")return"dependency";const i=t.health??s?.health??"unknown";return i==="unauthorized"?"unauthorized":i==="connection_failed"?"connection":s!==void 0&&wM(s,n,a)?"noCredential":i==="ok"?"ok":"idle"}function wM(t,s,n){return s.instance_fields.some(a=>{if(a.kind!=="secret"||!a.required)return!1;const i=t.options[a.key];return typeof i!="string"||n[i]?.configured!==!0})}function Wh(t,s){const n=new Set(s);for(let a=1;;a++){const i=`${t}-${a}`;if(!n.has(i))return i}}function NM(t,s){return`${t}.${s}`}function SM(t){return`KIKI_NOTIFY_${t.toUpperCase().replace(/[^A-Z0-9]+/gu,"_")}`.slice(0,128)}function Jy(t,s,n){const a=NM(s,n);return{provider_id:t,provider_instance_id:s,purpose:n,env:SM(a)}}function vr(t,s){return Object.fromEntries(Object.entries(t.credential_slots).filter(([,n])=>n.provider_instance_id===s).map(([n,{configured:a,...i}])=>[n,i]))}function Zy(t,s){return Object.entries(t.channels).filter(([,n])=>n.provider_instance_id===s).map(([n])=>n)}function fi(){return`r${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`}function ud(t){const s=t.trim();if(s==="")return{ok:!0,value:void 0};try{const n=JSON.parse(s);return n!==null&&typeof n=="object"&&!Array.isArray(n)?{ok:!0,value:n}:{ok:!1}}catch{return{ok:!1}}}function Vh(t,s){return t.find(n=>s?n.status==="failed"||n.status==="unknown"||n.status==="expired":n.status==="accepted_by_provider")}function Xy(t){return Object.entries(t.channels).toSorted(([s],[n])=>s.localeCompare(n))}const ek="block min-h-[5.5rem] w-full resize-y rounded-lg border bg-paper px-3 py-2 font-mono text-[12px] leading-5 text-ink outline-none transition-colors placeholder:font-sans placeholder:text-ink-faint focus:border-selected-ink disabled:cursor-not-allowed disabled:bg-hairline/20";function Yh(t){return t==null?"":JSON.stringify(t,null,2)}function CM({id:t,label:s,value:n,disabled:a,onCommit:i}){const{t:r}=D(),o=Yh(n),[l,c]=x.useState(o),[d,u]=x.useState(null),p=x.useId();x.useEffect(()=>{c(o),u(null)},[o]);const h=()=>{const b=ud(l);if(!b.ok){u(r("st.notify.jsonInvalid"));return}u(null),Yh(b.value)!==o&&i(b.value)};return e.jsxs("div",{className:"min-w-0",children:[e.jsx("textarea",{id:t,"aria-label":s,value:l,disabled:a,spellCheck:!1,autoComplete:"off","aria-invalid":d!==null,"aria-describedby":d!==null?p:void 0,className:`${ek} ${d!==null?"border-danger":"border-hairline hover:border-hairline-strong"}`,onChange:b=>{c(b.target.value),d!==null&&u(null)},onBlur:h,onKeyDown:b=>{b.key==="Escape"&&(c(o),u(null))}}),e.jsx(it,{id:p,text:d})]})}const pd=["notifications","settings"],_M=["notifications","providers"],tk=["notifications","deliveries"];function sk(t=!0){const{client:s}=be(),n=je({queryKey:pd,queryFn:()=>s.notifications.getSettings(),staleTime:15e3,enabled:t}),a=je({queryKey:_M,queryFn:()=>s.notifications.listProviders(),staleTime:6e4,enabled:t}),i=je({queryKey:tk,queryFn:()=>s.notifications.listDeliveries(),staleTime:15e3,enabled:t});return{settings:n,providers:a,deliveries:i}}function Fi(){const{client:t}=be(),s=Oe(),n=o=>{s.setQueryData(pd,o)},a=()=>s.invalidateQueries({queryKey:pd}),i=()=>s.invalidateQueries({queryKey:tk}),r=async o=>(await t.revealSecret({kind:"notification_credential",slot_id:o})).value;return{api:t.notifications,apply:n,refresh:a,refreshDeliveries:i,reveal:r}}function EM({settings:t,provider:s,onDone:n}){const{t:a,locale:i}=D(),{api:r,apply:o,refresh:l}=Fi(),c=x.useId(),[d,u]=x.useState(""),[p,h]=x.useState({}),[b,m]=x.useState({}),[f,g]=x.useState({}),[v,y]=x.useState(!1),[w,N]=x.useState(null),_=Fo(a,s.id),C=s.instance_fields,S=d!==""||Object.values(p).some($=>$!=="")||Object.values(b).some($=>$.mode==="set"),k=($,E)=>`${$}.${E}`,j=($,E)=>{h(M=>({...M,[$]:E})),g(({[$]:M,...z})=>z)},T=()=>{const $={};for(const E of C){const M=k("i",E.key),z=E.kind==="secret"?b[M]?.mode==="set"?b[M].value.trim():"":(p[M]??"").trim();E.required&&z===""&&($[M]=a("st.notify.fieldRequired",{field:Os(a,s.id,E)})),E.kind==="json"&&!ud(z).ok&&($[M]=a("st.notify.jsonInvalid")),E.kind==="number"&&z!==""&&!/^-?\d+$/u.test(z)&&($[M]=a("st.notify.fieldRequired",{field:Os(a,s.id,E)}))}for(const E of s.target_fields){const M=k("t",E.key),z=(p[M]??"").trim();(E.required&&z===""||E.kind==="number"&&z!==""&&!/^-?\d+$/u.test(z))&&($[M]=a("st.notify.fieldRequired",{field:Os(a,s.id,E)}))}return $},A=async()=>{const $=T();if(g($),!(Object.keys($).length>0)){y(!0),N(null);try{const E=Wh(s.id.replace(/_/gu,"-"),Object.keys(t.provider_instances)),M={},z=vr(t,E),H=[];for(const q of C){const F=k("i",q.key);if(q.kind==="secret"){const se=b[F];if(se?.mode!=="set"||se.value.trim()==="")continue;const Y=Jy(s.id,E,q.purpose??q.key),O=`${E}.${q.purpose??q.key}`;z[O]=Y,M[q.key]=O,H.push([O,se.value.trim()]);continue}const V=(p[F]??"").trim();V!==""&&(M[q.key]=q.kind==="number"?Number(V):q.kind==="json"?ud(V).value:V)}o(await r.upsertInstance(E,{provider_id:s.id,enabled:!0,revision:fi(),options:M},z));for(const[q,F]of H)await r.setCredential(q,F);const U={};for(const q of s.target_fields){const F=(p[k("t",q.key)]??"").trim();F!==""&&(U[q.key]=q.kind==="number"?Number(F):F)}const X=Wh(s.id.replace(/_/gu,"-"),Object.keys(t.channels));o(await r.upsertChannel(X,{provider_instance_id:E,enabled:!0,revision:fi(),target:U,directions:["send"],scenes:{work_complete:!0,question_pending:!0},...d.trim()===""?{}:{label:d.trim()}})),await l(),n(X)}catch(E){N({tone:"error",text:a("st.notify.addFailed",{detail:oe(i,E)})}),await l()}finally{y(!1)}}},P=($,E,M,z)=>e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("label",{htmlFor:`${c}-${$}`,className:$e,children:E}),e.jsx("input",{id:`${c}-${$}`,className:`${Ce} font-mono ${f[$]!==void 0?"border-danger":""}`,value:p[$]??"",inputMode:z?"numeric":void 0,spellCheck:!1,autoComplete:"off","aria-invalid":f[$]!==void 0,"aria-describedby":f[$]!==void 0?`${c}-${$}-issue`:void 0,onChange:H=>{j($,H.target.value)}}),e.jsx(it,{id:`${c}-${$}-issue`,text:f[$]??null})]},$),R=$=>$.required?Os(a,s.id,$):`${Os(a,s.id,$)} · ${a("st.notify.optional")}`,L=C.filter($=>$.kind!=="json"),I=C.filter($=>$.kind==="json");return e.jsxs("div",{className:"space-y-4","data-notify-add":s.id,children:[eo(s.id)!==void 0?e.jsx("p",{className:"text-[12.5px] leading-5 text-ink-soft","data-notify-guide":s.id,children:a(eo(s.id))}):null,e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("label",{htmlFor:`${c}-label`,className:$e,children:`${a("st.notify.name")} · ${a("st.notify.optional")}`}),e.jsx("input",{id:`${c}-label`,className:Ce,value:d,placeholder:_,autoComplete:"off",onChange:$=>{u($.target.value)}})]}),L.map($=>{const E=k("i",$.key);if($.kind==="secret")return e.jsxs("div",{className:"min-w-0 sm:col-span-2",children:[e.jsx(Dn,{id:`${c}-${E}`,label:R($),source:"none",draft:b[E]??Dt,disabled:v,onChange:M=>{m(z=>({...z,[E]:M})),g(({[E]:z,...H})=>H)}}),e.jsx(it,{id:`${c}-${E}-issue`,text:f[E]??null})]},E);if($.kind==="select"){const M=$.options??[];return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("span",{className:$e,children:R($)}),e.jsx(Qe,{variant:"form",mono:!0,ariaLabel:R($),value:p[E]??M[0]??"",disabled:v,choices:M.map(z=>({value:z,label:z})),onChange:z=>{j(E,z)}})]},E)}return P(E,R($),!0,$.kind==="number")}),s.target_fields.map($=>P(k("t",$.key),R($),!0,$.kind==="number"))]}),I.length>0?e.jsx(et,{summary:a("st.notify.advanced"),children:I.map($=>{const E=k("i",$.key);return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:`${c}-${E}`,className:$e,children:R($)}),e.jsx("textarea",{id:`${c}-${E}`,className:`${ek} ${f[E]!==void 0?"border-danger":"border-hairline"}`,value:p[E]??"",spellCheck:!1,placeholder:'{"host": "10.0.0.5"}',"aria-invalid":f[E]!==void 0,onChange:M=>{j(E,M.target.value)}}),e.jsx(it,{id:`${c}-${E}-issue`,text:f[E]??null})]},E)})}):null,e.jsx(pe,{feedback:w}),e.jsx(lt,{id:"notify-add",persistent:!0,dirty:S||C.length===0&&s.target_fields.length===0,saving:v,saveLabel:a("st.notify.add"),onSave:()=>void A(),onDiscard:()=>{n(null)}})]})}const to=["wechat","telegram","feishu","qq","discord","slack","matrix","wecom","dingtalk","http","email","windows","other","plugin"],qo={wechat:"st.channels.brand.wechat",telegram:"st.channels.brand.telegram",feishu:"st.channels.brand.feishu",qq:"st.channels.brand.qq",discord:"st.channels.brand.discord",slack:"st.channels.brand.slack",matrix:"st.channels.brand.matrix",wecom:"st.channels.brand.wecom",dingtalk:"st.channels.brand.dingtalk",http:"st.channels.brand.http",email:"st.channels.brand.email",windows:"st.channels.brand.windows",other:"st.channels.brand.other",plugin:"st.channels.brand.plugin"},TM={telegram:"telegram",feishu_webhook:"feishu",discord_webhook:"discord",slack_webhook:"slack",matrix:"matrix",wecom_webhook:"wecom",dingtalk_webhook:"dingtalk",http:"http",smtp:"email",windows_toast:"windows"},IM={wechat_bridge:"wechat",telegram:"telegram",feishu_app:"feishu",onebot_v11:"qq",discord:"discord",slack:"slack",matrix:"matrix"},PM={telegram:"telegram",feishu:"feishu",qq:"qq"};function Hu(t){return t.startsWith("plugin:kiki-qq/")?"qq":IM[t]??"plugin"}function zu(t){return TM[t]??"other"}function AM(t,s,n){const a=new Map,i=(r,o)=>{a.set(r,[...a.get(r)??[],o])};i("wechat",{route:{kind:"im",mode:"wechat"}}),i("qq",{route:{kind:"im",mode:"plugin",pluginId:"kiki-qq"}});for(const r of to){const o=PM[r];o!==void 0&&i(r,{route:{kind:"im",mode:"paste",paste:o}})}for(const r of["discord","slack","matrix"])t?.platforms.some(l=>l.provider_kind===r)===!0?i(r,{route:{kind:"im",mode:"setup",provider:r}}):(s||t===void 0)&&i(r,{route:{kind:"im",mode:"setup",provider:r},unavailable:"setupCatalog"});for(const r of n){if(Yy.has(r.id))continue;const o=zu(r.id),l={kind:"push",providerId:r.id};kM(r)?i(o,{route:l}):r.status==="dependency_missing"&&i(o,{route:l,unavailable:"dependency",reason:r.status_reason})}return i("other",{route:{kind:"im",mode:"paste",paste:"raw"}}),to.flatMap(r=>{const o=a.get(r);return o===void 0?[]:[{id:r,routes:o.toSorted((l,c)=>Jh(l.route)-Jh(c.route))}]})}function Jh(t){return t.kind==="im"?0:1}function yr(t){return t.kind==="push"?`push:${t.providerId}`:t.mode==="plugin"?`im:plugin:${t.pluginId}`:t.mode==="wechat"?"im:wechat":t.mode==="setup"?`im:${t.provider}`:`im:paste:${t.paste}`}function $M(t){return t.routes.some(s=>s.unavailable===void 0)}function dc(t){return t.routes.filter(s=>s.unavailable===void 0).length>1}function RM(t,s){const n=a=>(s[a]??"").trim();switch(t){case"telegram":return n("token");case"feishu":return`app_id: ${n("appId")}
|
|
248
|
+
app_secret: ${n("appSecret")}`;case"qq":return[`onebot: ${n("endpoint")}`,n("accessToken")===""?"":`access_token: ${n("accessToken")}`].filter(Boolean).join(`
|
|
249
|
+
`);case"raw":return(s.text??"").trim()}}const LM={telegram:[{key:"token",secret:!0,required:!0}],feishu:[{key:"appId",secret:!1,required:!0},{key:"appSecret",secret:!0,required:!0}],qq:[{key:"endpoint",secret:!1,required:!0},{key:"accessToken",secret:!0,required:!1}],raw:[{key:"text",secret:!1,required:!0}]},$t=["im-sessions"],MM={bot_token:"st.im.setup.field.bot_token",app_token:"st.im.setup.field.app_token",homeserver:"st.im.setup.field.homeserver",access_token:"st.im.setup.field.access_token"},Zh={image:"message.media.image",file:"message.media.file",audio:"message.media.audio",voice:"message.media.voice",video:"message.media.video"};function OM(t){return t==="discord"||t==="slack"||t==="matrix"}function nk(t,s){const n=[t.chat_id.trim(),t.sender_id.trim()],a=al(t.chat_title,n),i=al(t.sender_name,n),r=a??i??At(t.chat_id),o=a!==void 0?i:i===void 0&&t.sender_id.trim()!==""&&t.sender_id.trim()!==t.chat_id.trim()?At(t.sender_id):void 0,l=t.topic_id!=="0"?al(t.topic_title,[t.topic_id.trim()])||`${s("st.im.topicId")} ${At(t.topic_id)}`:void 0;return[r,o,l].filter(Boolean).join(" · ")}function md(t){return t.startsWith("persona:")?{kind:"persona",persona_id:t.slice(8)}:{kind:"session",session_id:t.slice(8)}}function ak(t){return t.pending_reanchor?"unassigned":t.persona_id!==void 0?`persona:${t.persona_id}`:t.session_id!==void 0?`session:${t.session_id}`:"unassigned"}function DM(t,s,n){if(s.pending_reanchor)return n("st.im.pendingReanchor");if(s.persona_id!==void 0){const a=t?.personas.find(i=>i.id===s.persona_id)?.name;return a===void 0?At(s.persona_id):`${n("st.im.kindPersona")} · ${a}`}if(s.session_id!==void 0){const a=t?.sessions.find(r=>r.id===s.session_id)?.title?.trim(),i=ya(s.session_id,a);return a!==void 0&&a!==""&&a!==s.session_id?`${n("st.im.kindSession")} · ${i}`:i}return n("st.im.pendingReanchor")}function FM(t,s,n){const a=[...(t?.personas??[]).map(o=>({value:`persona:${o.id}`,label:`${n("st.im.kindPersona")} · ${o.name}`})),...(t?.sessions??[]).map(o=>({value:`session:${o.id}`,label:`${n("st.im.kindSession")} · ${ya(o.id,o.title)}`}))],i=ak(s),r=s.pending_reanchor?n("st.im.pendingReanchor"):s.persona_id!==void 0?At(s.persona_id):s.session_id!==void 0?Od(s.session_id):n("st.im.pendingReanchor");return a.some(o=>o.value===i)||a.unshift({value:i,label:r}),a}function qM(t,s){const n=cb.safeParse(t);return n.success?s(`st.im.provider.${n.data}`):t}function ik(t,s){const n=Hu(t.provider_kind),a=n==="plugin"?qM(t.provider_kind,s):s(qo[n]),i=t.label?.trim()??"";return i===""||BM(t.provider_kind,n).has(i.toLowerCase())?a:i}function BM(t,s){const n=new Set([t.toLowerCase()]),a=cb.safeParse(t);for(const i of["en","zh"])s!=="plugin"&&n.add(qp(i,qo[s]).toLowerCase()),a.success&&n.add(qp(i,`st.im.provider.${a.data}`).toLowerCase());return n}function Qu(t){const s=t.connection;return s==="auth_expired"?"auth_expired":t.listening?s==="starting"?"starting":s==="reconnecting"?"reconnecting":s==="stopped"||t.adapter==="stopped"||t.adapter==="missing"?"stopped":"listening":"paused"}const KM={listening:"st.im.stateListening",starting:"st.im.stateStarting",reconnecting:"st.im.stateReconnecting",auth_expired:"st.im.stateAuthExpired",stopped:"st.im.stateListenerStopped",paused:"st.channels.state.paused"};function rk(t,s){const n=Qu(t);return s>0||n==="auth_expired"||n==="stopped"||(t.inbound_diagnostics?.length??0)>0||t.conflict!==void 0}function ok(t,s){return s!==void 0?s.capabilities.edit_text:t==="telegram"||t==="feishu_app"||t==="discord"||t==="slack"||t==="matrix"}function UM(t){return t==="wait"?"st.im.wechatWaiting":t==="scaned"||t==="scaned_but_redirect"?"st.im.wechatScanned":t==="expired"?"st.im.wechatExpired":t==="need_verifycode"?"st.im.wechatVerify":t==="verify_code_blocked"?"st.im.wechatBlocked":t==="binded_redirect"?"st.im.wechatBound":t==="cancelled"?"st.im.wechatCancel":"st.im.error"}function lk(t){return t?.personas[0]!==void 0?`persona:${t.personas[0].id}`:t?.sessions[0]!==void 0?`session:${t.sessions[0].id}`:""}function HM(){const t=typeof window>"u"?"":new URLSearchParams(window.location.search).get("target")??"";return/^(persona|session):.+/u.test(t)?t:""}function zM(){const{client:t,connectionSource:s}=be(),n=zs(s),a=je({queryKey:$t,queryFn:()=>t.imSessions.snapshot(),enabled:!n,retry:(o,l)=>!ja(l)&&o<2,placeholderData:o=>o,refetchInterval:o=>!ja(o.state.error)&&o.state.data?.instances.some(l=>l.listening)===!0?2e3:!1}),i=je({queryKey:[...$t,"catalog"],queryFn:()=>t.imSessions.catalog(),enabled:a.data!==void 0}),r=je({queryKey:[...$t,"setup-catalog"],queryFn:()=>t.imSessions.setupCatalog(),enabled:a.data!==void 0&&typeof t.imSessions.setupCatalog=="function",staleTime:6e4});return{snapshot:a,catalog:i,setupCatalog:r}}function Fn(){const{t}=D(),s=Oe(),[n,a]=x.useState(!1),[i,r]=x.useState();return{saving:n,error:i,run:async l=>{a(!0),r(void 0);try{const c=await l();return c!==void 0&&s.setQueryData($t,c),!0}catch(c){const d=c instanceof Error?c.message:"";if(XN(c)){const u=eS(c);r(u?.previous_session_id?`${t("st.im.rebind.title")}: ${t("st.im.occupiedBy")} ${u.previous_session_title??u.previous_session_id}`:t("st.im.error"))}else d.includes("unsupported_wechat_group")?r(t("st.im.wechatDirectOnly")):d.includes("topic_scope_unavailable")?r(t("st.im.error.topicScopeUnavailable")):d.includes("group_binding_scope_required")?r(t("st.im.error.groupBindingScopeRequired")):d.includes("direction_unsupported")||d.includes("input_unsupported")||d.includes("output_unsupported")?r(t("st.im.error.directionUnsupported")):r(Gu(t,d));return!1}finally{a(!1)}},clear:()=>{r(void 0)}}}function Gu(t,s){return s===""?t("st.im.error"):s==="missing"?t("st.channels.error.missing"):s==="unauthorized"?t("st.channels.error.unauthorized"):s==="setup_failed"?t("st.channels.error.setupFailed"):s}function qi(){const{t}=D(),{client:s}=be();return x.useCallback(async n=>{const a=await s.imSessions.check(n);if(!a.ok)throw new Error(a.conflict==="webhook"?t("st.im.webhook"):Gu(t,a.detail??""));return s.imSessions.listen(n,!0)},[s,t])}function ck(t){const{t:s}=D(),{client:n}=be(),a=Oe(),[i,r]=x.useState(),[o,l]=x.useState(),[c,d]=x.useState(),[u,p]=x.useState(""),[h,b]=x.useState(),[m,f]=x.useState(!1),g=i!==void 0&&(c===void 0||c==="wait"||c==="scaned"||c==="scaned_but_redirect"),v=x.useCallback(C=>{d(C.status),C.status==="confirmed"&&(r(void 0),a.invalidateQueries({queryKey:$t}),t(C.provider_instance_id))},[t,a]);x.useEffect(()=>{if(!g||i===void 0)return;let C=!1;const k=setInterval(()=>{n.imSessions.pollWechatQr(i).then(j=>{C||v(j)}).catch(j=>{if(C)return;const T=j instanceof Error?j.message:"";T==="wechat_login_cancelled"||T==="unknown_login"||b(T.length>0?T:s("st.im.error"))})},1500);return()=>{C=!0,clearInterval(k)}},[n,i,g,v,s]);const y=x.useCallback(()=>{b(void 0),p(""),l(void 0),d(void 0),f(!0),n.imSessions.startWechatQr().then(C=>{r(C.login_id),l(C.image),d("wait")}).catch(()=>{b(s("st.channels.wechat.startFailed"))}).finally(()=>{f(!1)})},[n,s]),w=()=>{const C=i;r(void 0),l(void 0),d("cancelled"),C!==void 0&&n.imSessions.cancelWechatQr(C)},N=()=>{i!==void 0&&n.imSessions.pollWechatQr(i,u.trim()).then(v).catch(C=>{b(C instanceof Error?C.message:s("st.im.error"))})},_=x.useCallback(()=>{i===void 0&&(d(void 0),l(void 0),b(void 0))},[i]);return{loginId:i,image:o,status:c,verifyCode:u,error:h,requesting:m,active:i!==void 0,setVerifyCode:p,start:y,cancel:w,submitCode:N,reset:_}}function dk({platform:t,instanceId:s,savedInstanceId:n,onSaved:a,onCheckAndListen:i,busy:r}){const{t:o}=D(),{client:l}=be(),[c,d]=x.useState({}),[u,p]=x.useState(!1),[h,b]=x.useState(),[m,f]=x.useState(),[g,v]=x.useState(""),[y,w]=x.useState(""),[N,_]=x.useState(""),[C,S]=x.useState(""),[k,j]=x.useState(""),[T,A]=x.useState("http://127.0.0.1/slack-callback"),[P,R]=x.useState(),[L,I]=x.useState(""),[$,E]=x.useState(""),[M,z]=x.useState("token"),[H,U]=x.useState(""),[X,q]=x.useState(),[F,V]=x.useState(""),[se,Y]=x.useState(""),[O,B]=x.useState("http://127.0.0.1/matrix-callback"),[le,re]=x.useState(""),[ae,ne]=x.useState(),[Ee,ie]=x.useState(""),[me,fe]=x.useState("");x.useEffect(()=>{d(K=>t.provider_kind==="matrix"&&X?.homeserver!==void 0?{homeserver:X.homeserver}:Object.keys(K).length===0?K:{}),b(void 0),f(void 0),j(""),R(void 0),I(""),E(""),Y(""),ne(void 0),ie(""),fe("")},[s,X?.homeserver,t.provider_kind]);const Ie=async K=>{p(!0),b(void 0);try{const Z=await l.imSessions.setup(K);Z.kind==="saved"?(d(ue=>{const Te={};for(const Ne of t.fields)!Ne.secret&&ue[Ne.key]!==void 0&&(Te[Ne.key]=ue[Ne.key]);return Te}),j(""),R(void 0),I(""),E(""),Y(""),ne(void 0),ie(""),fe(""),await a(Z.result)):Z.kind==="link"?(f(Z.url),K.action==="slack_oauth_begin"?R(Z.attempt_id):K.action==="matrix_sso_begin"&&(ne(Z.attempt_id),Z.callback_uri!==void 0&&ie(Z.callback_uri))):Z.kind==="discovery"&&(q({homeserver:Z.homeserver,login_types:Z.login_types,sso:Z.sso}),d(ue=>({...ue,homeserver:Z.homeserver})))}catch(Z){b(Gu(o,Z instanceof Error?Z.message:""))}finally{p(!1)}},te=t.fields.every(K=>!K.required||(c[K.key]?.trim()??"").length>0),ee=n??s;return e.jsxs("div",{className:"space-y-3","data-im-platform-setup":t.provider_kind,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-[12px] text-ink-soft",children:[t.provider_kind==="matrix"&&!t.capabilities.encrypted_rooms?e.jsx("span",{className:"text-amber-ink","data-im-cap-matrix-unencrypted":!0,children:o("st.im.cap.matrixUnencrypted")}):e.jsx("span",{}),e.jsx("a",{href:t.portal_url,target:"_blank",rel:"noreferrer","data-im-setup-portal":t.provider_kind,className:"underline-offset-2 hover:text-ink hover:underline",children:o("st.im.setup.portalLink")})]}),t.provider_kind==="discord"&&t.methods.includes("oauth_install")?e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] sm:items-end","data-im-discord-install":!0,children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.discord.appId")}),e.jsx("input",{"data-im-discord-app-id":!0,value:g,placeholder:"123456789012345678",className:`${Ce} font-mono`,onChange:K=>{v(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.discord.guildId")}),e.jsx("input",{"data-im-discord-guild-id":!0,value:y,className:`${Ce} font-mono`,onChange:K=>{w(K.target.value)}})]}),e.jsx("button",{type:"button",className:Q,"data-im-discord-install-btn":!0,disabled:u||!/^\d{1,22}$/u.test(g.trim()),onClick:()=>{const K=y.trim();Ie({action:"discord_install",application_id:g.trim(),...K===""?{}:{guild_id:K}})},children:o("st.im.setup.discord.installLink")})]}):null,t.provider_kind==="slack"?e.jsxs("div",{className:"space-y-3","data-im-slack-helpers":!0,children:[t.methods.includes("manifest")?e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"min-w-[12rem] flex-1 space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.appName")}),e.jsx("input",{"data-im-slack-app-name":!0,value:N,placeholder:"Kiki",className:Ce,onChange:K=>{_(K.target.value)}})]}),e.jsx("button",{type:"button",className:Q,"data-im-slack-manifest-btn":!0,disabled:u,onClick:()=>{const K=N.trim();Ie({action:"slack_manifest",...K===""?{}:{name:K}})},children:o("st.im.setup.slack.manifestLink")})]}):null,t.methods.includes("oauth_install")?e.jsx(et,{summary:o("st.im.setup.slack.oauthToggle"),"data-im-slack-oauth":!0,children:e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.clientId")}),e.jsx("input",{"data-im-slack-client-id":!0,value:C,className:`${Ce} font-mono`,onChange:K=>{S(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.redirectUri")}),e.jsx("input",{"data-im-slack-redirect-uri":!0,value:T,className:`${Ce} font-mono`,onChange:K=>{A(K.target.value)}})]})]}),e.jsx("button",{type:"button",className:Q,"data-im-slack-oauth-begin":!0,disabled:u||C.trim()===""||T.trim()==="",onClick:()=>{Ie({action:"slack_oauth_begin",client_id:C.trim(),redirect_uri:T.trim(),...s===void 0?{}:{instance_id:s}})},children:o("st.im.setup.slack.oauthBegin")}),P!==void 0?e.jsxs("div",{className:"space-y-2 pt-2","data-im-slack-oauth-complete-form":!0,children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.clientSecret")}),e.jsx("input",{type:"password","data-im-slack-client-secret":!0,value:k,className:`${Ce} font-mono`,onChange:K=>{j(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.field.app_token")}),e.jsx("input",{type:"password","data-im-slack-oauth-app-token":!0,value:c.app_token??"",className:`${Ce} font-mono`,onChange:K=>{d(Z=>({...Z,app_token:K.target.value}))}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.code")}),e.jsx("input",{"data-im-slack-oauth-code":!0,value:L,className:`${Ce} font-mono`,onChange:K=>{I(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.slack.state")}),e.jsx("input",{"data-im-slack-oauth-state":!0,value:$,className:`${Ce} font-mono`,onChange:K=>{E(K.target.value)}})]})]}),e.jsx("button",{type:"button",className:Ye,"data-im-slack-oauth-complete":!0,disabled:u||k.trim()===""||(c.app_token?.trim()??"")===""||L.trim()===""||$.trim()==="",onClick:()=>{Ie({action:"slack_oauth_complete",attempt_id:P,state:$.trim(),code:L.trim(),client_secret:k.trim(),app_token:c.app_token.trim()})},children:o("st.im.setup.slack.oauthComplete")})]}):null]})}):null]}):null,t.provider_kind==="matrix"?e.jsxs("div",{className:"space-y-3","data-im-matrix-helpers":!0,children:[t.methods.includes("discovery")?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"min-w-[14rem] flex-1 space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.server")}),e.jsx("input",{"data-im-matrix-server":!0,value:H,placeholder:"@bot:example.org / matrix.org",className:`${Ce} font-mono`,onChange:K=>{U(K.target.value)}})]}),e.jsx("button",{type:"button",className:Q,"data-im-matrix-discover-btn":!0,disabled:u||H.trim()==="",onClick:()=>{Ie({action:"matrix_discover",server:H.trim()})},children:o("st.im.setup.matrix.discover")})]}),X!==void 0?e.jsx("p",{className:"font-mono text-[12px] text-ink-soft","data-im-matrix-discovery-result":!0,children:o("st.im.setup.matrix.discovered",{homeserver:X.homeserver,flows:X.login_types.join(", ")})}):null]}):null,e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.authMethod")}),e.jsx(He,{ariaLabel:o("st.im.setup.matrix.authMethod"),value:M,onChange:z,dataAttr:"data-im-matrix-method",choices:[{value:"token",label:o("st.im.setup.matrix.methodToken")},...t.methods.includes("password")?[{value:"password",label:o("st.im.setup.matrix.methodPassword")}]:[],...t.methods.includes("sso")?[{value:"sso",label:o("st.im.setup.matrix.methodSso")}]:[]]})]}),M==="password"?e.jsxs("div",{className:"space-y-2","data-im-matrix-password-form":!0,children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.field.homeserver")}),e.jsx("input",{"data-im-matrix-field":"homeserver",value:c.homeserver??"",placeholder:"https://matrix.example.org",className:`${Ce} font-mono`,onChange:K=>{d(Z=>({...Z,homeserver:K.target.value}))}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.user")}),e.jsx("input",{"data-im-matrix-user":!0,value:F,className:`${Ce} font-mono`,onChange:K=>{V(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.password")}),e.jsx("input",{type:"password","data-im-matrix-password":!0,value:se,className:Ce,onChange:K=>{Y(K.target.value)}})]})]}),e.jsx("button",{type:"button",className:Ye,"data-im-matrix-password-submit":!0,disabled:u||(c.homeserver?.trim()??"")===""||F.trim()===""||se==="",onClick:()=>{Ie({action:"matrix_password",homeserver:c.homeserver.trim(),user:F.trim(),password:se,...s===void 0?{}:{instance_id:s}})},children:o("st.im.setup.matrix.passwordSubmit")})]}):null,M==="sso"?e.jsxs("div",{className:"space-y-2","data-im-matrix-sso-form":!0,children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.field.homeserver")}),e.jsx("input",{"data-im-matrix-field":"homeserver",value:c.homeserver??"",placeholder:"https://matrix.example.org",className:`${Ce} font-mono`,onChange:K=>{d(Z=>({...Z,homeserver:K.target.value}))}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.redirectUri")}),e.jsx("input",{"data-im-matrix-redirect-uri":!0,value:O,className:`${Ce} font-mono`,onChange:K=>{B(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.idpId")}),e.jsx("input",{"data-im-matrix-idp-id":!0,value:le,className:`${Ce} font-mono`,onChange:K=>{re(K.target.value)}})]})]}),e.jsx("button",{type:"button",className:Q,"data-im-matrix-sso-begin":!0,disabled:u||(c.homeserver?.trim()??"")===""||O.trim()==="",onClick:()=>{const K=le.trim();Ie({action:"matrix_sso_begin",homeserver:c.homeserver.trim(),redirect_uri:O.trim(),...K===""?{}:{idp_id:K},...s===void 0?{}:{instance_id:s}})},children:o("st.im.setup.matrix.ssoBegin")}),ae!==void 0?e.jsxs("div",{className:"space-y-2 pt-2","data-im-matrix-sso-complete-form":!0,children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.callbackUri")}),e.jsx("input",{"data-im-matrix-callback-uri":!0,value:Ee,className:`${Ce} font-mono`,onChange:K=>{ie(K.target.value)}})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:o("st.im.setup.matrix.loginToken")}),e.jsx("input",{type:"password","data-im-matrix-login-token":!0,value:me,className:`${Ce} font-mono`,onChange:K=>{fe(K.target.value)}})]})]}),e.jsx("button",{type:"button",className:Ye,"data-im-matrix-sso-complete":!0,disabled:u||Ee.trim()===""||me.trim()==="",onClick:()=>{Ie({action:"matrix_sso_complete",attempt_id:ae,callback_uri:Ee.trim(),login_token:me.trim()})},children:o("st.im.setup.matrix.ssoComplete")})]}):null]}):null]}):null,m!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-im-setup-link":!0,children:[e.jsx("input",{readOnly:!0,value:m,"aria-label":o("st.im.setup.generatedLink"),className:`${Ce} min-w-0 flex-1 font-mono`,"data-im-setup-link-input":!0}),e.jsx("a",{href:m,target:"_blank",rel:"noreferrer",className:Q,"data-im-setup-link-open":!0,children:o("st.im.setup.openLink")})]}):null,t.provider_kind!=="matrix"||M==="token"?e.jsxs("div",{className:"space-y-3","data-im-setup-token-fields":!0,children:[e.jsx("div",{className:`grid gap-2 ${t.fields.length>1?"sm:grid-cols-2":""}`,children:t.fields.map(K=>{const Z=MM[K.key];return e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:$e,children:Z===void 0?K.label:o(Z)}),e.jsx("input",{type:K.secret?"password":"text","data-im-setup-field":K.key,value:c[K.key]??"",spellCheck:!1,autoComplete:"off",className:`${Ce} font-mono`,onChange:ue=>{const Te=ue.target.value;d(Ne=>({...Ne,[K.key]:Te}))}})]},K.key)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Ye,"data-im-setup-save":!0,disabled:u||r||!te,onClick:()=>{const K={};for(const Z of t.fields){const ue=c[Z.key]?.trim()??"";ue!==""&&(K[Z.key]=ue)}Ie({action:"save",provider_kind:t.provider_kind,...s===void 0?{}:{instance_id:s},fields:K})},children:o("st.im.setup.saveSlot")}),ee!==void 0&&ee!==""?e.jsx("button",{type:"button",className:Q,"data-im-check":!0,disabled:u||r,onClick:()=>{i(ee)},children:o("st.im.check")}):null]})]}):ee!==void 0&&ee!==""?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx("button",{type:"button",className:Q,"data-im-check":!0,disabled:u||r,onClick:()=>{i(ee)},children:o("st.im.check")})}):null,n!==void 0?e.jsx("p",{className:"text-[13px] text-success","data-im-setup-saved-notice":!0,children:o("st.im.setup.savedNotice")}):null,e.jsx(pe,{feedback:h===void 0?null:{tone:"error",text:h}})]})}function uk({qr:t}){const{t:s}=D(),{start:n}=t,a=!t.active&&!t.requesting&&t.status===void 0&&t.error===void 0;x.useEffect(()=>{a&&n()},[a,n]);const i=t.status==="expired"||t.status==="verify_code_blocked"||t.status==="cancelled"||t.error!==void 0&&!t.active;return e.jsxs("div",{className:"flex flex-col items-center gap-3 py-2 text-center","data-im-wechat":!0,children:[e.jsx("div",{className:"flex h-52 w-52 items-center justify-center rounded-xl border border-hairline bg-paper p-3 shadow-[var(--kiki-sheet-shadow)]",children:t.image!==void 0&&t.status!=="cancelled"&&!i?e.jsx(QM,{image:t.image}):e.jsx(de,{name:i?"refresh":"dot",size:16,className:i?"text-ink-faint":"text-ink-faint status-dot-busy"})}),e.jsx("p",{className:"min-h-5 text-[13px] text-ink-soft","data-im-wechat-status":!0,children:t.status!==void 0&&t.status!=="confirmed"?s(UM(t.status)):t.active?s("st.im.wechatWaiting"):t.error===void 0?s("st.channels.wechat.preparing"):null}),t.status==="need_verifycode"?e.jsxs("div",{className:"flex w-full max-w-xs items-center gap-2",children:[e.jsx("input",{"data-im-wechat-verify":!0,value:t.verifyCode,className:Ce,"aria-label":s("st.im.wechatVerify"),onChange:r=>{t.setVerifyCode(r.target.value)}}),e.jsx("button",{type:"button",className:Ye,"data-im-wechat-verify-submit":!0,disabled:t.verifyCode.trim()==="",onClick:t.submitCode,children:s("st.channels.wechat.verify")})]}):null,t.error!==void 0?e.jsx(pe,{feedback:{tone:"error",text:t.error}}):null,e.jsxs("div",{className:"flex flex-wrap justify-center gap-2",children:[i?e.jsx("button",{type:"button",className:Q,"data-im-wechat-retry":!0,onClick:t.start,children:s("st.channels.wechat.newCode")}):null,t.active?e.jsx("button",{type:"button",className:Q,"data-im-wechat-cancel":!0,onClick:t.cancel,children:s("st.im.wechatCancel")}):null]})]})}function QM({image:t}){const s=t.startsWith("data:image")?t:tS(t);return s===void 0?e.jsx("input",{readOnly:!0,"data-im-wechat-code":!0,value:t,className:Ce,"aria-label":"QR"}):e.jsx("img",{alt:"",src:s,"data-im-wechat-image":!0,className:"h-full w-full"})}const Xh={token:"st.channels.field.botToken",appId:"st.channels.field.appId",appSecret:"st.channels.field.appSecret",endpoint:"st.channels.field.onebotEndpoint",accessToken:"st.channels.field.accessToken",text:"st.im.paste"},GM={telegram:{steps:["st.channels.steps.telegram.1","st.channels.steps.telegram.2","st.channels.steps.telegram.3"],link:{href:"https://t.me/BotFather",label:"st.channels.steps.telegram.link"}},feishu:{steps:["st.channels.steps.feishu.1","st.channels.steps.feishu.2","st.channels.steps.feishu.3"],link:{href:"https://open.feishu.cn/app",label:"st.channels.steps.feishu.link"}},qq:{steps:["st.channels.steps.onebot.1","st.channels.steps.onebot.2"],link:{href:"https://napneko.github.io/",label:"st.channels.steps.onebot.link"}},raw:{steps:["st.channels.steps.raw.1"]}},WM={token:"123456789:AA…",endpoint:"ws://127.0.0.1:3001"};function pk({kind:t,instanceId:s,onConnected:n}){const{t:a}=D(),{client:i}=be(),r=Oe(),o=Fn(),l=qi(),c=x.useId(),[d,u]=x.useState({}),[p,h]=x.useState(),b=LM[t],m=b.every(v=>!v.required||(d[v.key]??"").trim()!==""),f=()=>{o.run(async()=>{const v=await i.imSessions.paste(RM(t,d),s);h(v),u({}),await r.invalidateQueries({queryKey:$t});const y=await l(v.provider_instance_id);return n(v.provider_instance_id),y})},g=GM[t];return e.jsxs("div",{className:"space-y-4","data-im-paste-panel":t,children:[s===void 0?e.jsx(sS,{data:{"data-im-paste-guide":t},steps:g.steps.map(v=>a(v)),link:g.link===void 0?void 0:{href:g.link.href,label:a(g.link.label)}}):null,b.map(v=>{const y=`${c}-${v.key}`;return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:y,className:$e,children:v.required?a(Xh[v.key]):`${a(Xh[v.key])} · ${a("st.notify.optional")}`}),t==="raw"?e.jsx("textarea",{id:y,"data-im-paste":!0,value:d[v.key]??"",rows:4,spellCheck:!1,placeholder:a("st.im.pastePlaceholder"),className:`${Ce} font-mono`,onChange:w=>{u(N=>({...N,[v.key]:w.target.value}))}}):e.jsx("input",{id:y,"data-im-paste-field":v.key,type:v.secret?"password":"text",value:d[v.key]??"",spellCheck:!1,autoComplete:"off",placeholder:WM[v.key],className:`${Ce} font-mono`,onChange:w=>{u(N=>({...N,[v.key]:w.target.value}))}})]},v.key)}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx("button",{type:"button",className:Ye,"data-im-check":!0,disabled:o.saving||!m,onClick:f,children:a(o.saving?"st.channels.connecting":"st.channels.connect")})}),p!==void 0&&p.ignored_keys.length>0?e.jsxs("p",{className:"text-[12px] text-ink-soft","data-im-ignored":!0,children:[a("st.im.ignored"),": ",p.ignored_keys.join(", ")]}):null,e.jsx(pe,{feedback:o.error===void 0?null:{tone:"error",text:o.error}})]})}const Yn="kiki-qq";function VM(){const{t}=D(),{client:s}=be(),n=Dd(),a=nS(),i=Bb(),[r,o]=x.useState(null),[l,c]=x.useState(!1),[d,u]=x.useState(null),p=n.data?.plugins.find(m=>m.id===Yn),h=aS(p?.enabled===!0&&p.state==="ok"?Yn:void 0);if(n.isPending)return e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:t("cap.loading")});if(p===void 0){const m=a.data?.entries.find(f=>f.id===Yn);return e.jsxs("div",{className:"space-y-3","data-im-qq-plugin":"missing",children:[e.jsx("p",{className:"text-[13px] leading-5 text-ink-soft",children:t("st.channels.qq.needPlugin")}),m!==void 0?e.jsx("button",{type:"button",className:Ye,"data-im-qq-install":!0,onClick:()=>{o({source:m.source,sha256:m.sha256,displayName:m.displayName,icon:m.icon,entry:m})},children:t("st.channels.qq.install")}):a.isPending?null:e.jsxs("div",{className:"space-y-2","data-im-qq-unlisted":!0,children:[e.jsx("p",{className:"text-[12.5px] leading-5 text-ink-faint",children:t("st.channels.qq.notListed")}),e.jsx(_t,{to:db(),className:Q,children:t("st.channels.qq.openExtensions")})]}),r!==null?e.jsx(Kb,{request:r,onClose:()=>{o(null)},onInstalled:()=>{o(null),i()}}):null]})}if(!p.enabled){const m=async()=>{c(!0),u(null);try{await s.setPluginState(Yn,{enabled:!0,defaultEnabled:JS(p)}),await i()}catch(f){u(f instanceof Error?f.message:String(f))}finally{c(!1)}};return e.jsxs("div",{className:"space-y-3","data-im-qq-plugin":"disabled",children:[e.jsx("p",{className:"text-[13px] leading-5 text-ink-soft",children:t("st.channels.qq.disabledHint")}),e.jsx("button",{type:"button",className:Ye,disabled:l,"data-im-qq-enable":!0,onClick:()=>{m()},children:t("st.channels.qq.enable")}),e.jsx(pe,{feedback:d===null?null:{tone:"error",text:d}})]})}const b=VS(h.data?.manifest);return p.state!=="ok"||h.isSuccess&&b===void 0||h.isError?e.jsxs("div",{className:"space-y-3","data-im-qq-plugin":"unavailable",children:[e.jsx("p",{className:"text-[13px] leading-5 text-ink-soft",children:t("st.channels.qq.notReady")}),e.jsx(_t,{to:An(Yn),className:Q,children:t("st.channels.qq.openPlugin")})]}):b===void 0?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:t("cap.loading")}):e.jsx("div",{"data-im-qq-plugin":"ready",children:e.jsx(YS,{pluginId:Yn,panelId:b.id,label:b.label})})}const YM={wechat:"WX",telegram:"TG",feishu:"FS",qq:"QQ",discord:"DC",slack:"SL",matrix:"MX",wecom:"WC",dingtalk:"DT",http:"{ }",email:"@",windows:"",other:"…",plugin:"P"};function mk({brand:t,twoWay:s,size:n="md"}){const a=n==="lg"?"h-10 w-10 rounded-[10px] text-[12.5px]":"h-8 w-8 rounded-[8px] text-[11px]";return e.jsx("span",{"aria-hidden":!0,"data-channel-mark":t,className:`flex shrink-0 items-center justify-center font-semibold tracking-[0.02em] ${a} ${s?"bg-selected text-selected-ink":"bg-ink/[0.05] text-ink-soft ring-1 ring-inset ring-hairline"}`,children:t==="windows"?e.jsx(de,{name:"bell",size:14}):YM[t]})}function xd({twoWay:t}){const{t:s}=D();return e.jsx("span",{"data-channel-capability":t?"two-way":"alerts",className:`shrink-0 rounded-[4px] px-1.5 py-px text-[11px] leading-4 ${t?"bg-selected/70 text-selected-ink":"border border-hairline text-ink-faint"}`,children:s(t?"st.channels.cap.twoWay":"st.channels.cap.alerts")})}const JM={ok:"bg-success",busy:"bg-amber-ink status-dot-busy",idle:"bg-ink/[0.25]",warn:"bg-amber-rule",error:"bg-danger"},ZM={ok:"text-ink-soft",busy:"text-amber-ink",idle:"text-ink-faint",warn:"text-amber-ink",error:"text-danger"};function ua({tone:t,children:s,data:n}){return e.jsxs("span",{...n,className:`inline-flex shrink-0 items-center gap-1.5 ${ZM[t]}`,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${JM[t]}`}),s]})}function xk({brand:t,twoWay:s,name:n,status:a,meta:i,control:r,open:o,onToggle:l,bodyId:c,expandLabel:d,children:u,data:p}){return e.jsxs("div",{...p,"data-open":o?"true":void 0,children:[e.jsxs("div",{className:`flex min-h-[60px] items-center gap-2 px-3 py-2 transition-colors ${o?"bg-ink/[0.03]":""}`,children:[e.jsxs("button",{type:"button","aria-expanded":o,"aria-controls":c,"aria-label":d,onClick:l,className:"group/row -my-1 -ml-1 flex min-h-11 min-w-0 flex-1 items-center gap-3 rounded-md px-1 py-1 text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:[e.jsx(mk,{brand:t,twoWay:s}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13.5px] font-medium text-ink","data-channel-name":!0,children:n}),e.jsx(xd,{twoWay:s})]}),e.jsxs("span",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-[12px]",children:[a,i!=null?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"text-ink-faint",children:"·"}),e.jsx("span",{className:"min-w-0 truncate text-ink-faint",children:i})]}):null]})]})]}),r!==void 0?e.jsx("div",{className:"flex shrink-0 items-center gap-2 pl-1",children:r}):null]}),e.jsx("div",{id:c,hidden:!o,"data-channel-body":!0,className:"space-y-5 px-4 pb-5 pt-4 sm:pl-[60px] sm:pr-5",children:u})]})}function XM(t){return t.kind==="im"&&t.mode==="plugin"?"st.channels.qq.official":t.kind==="im"&&t.mode==="paste"&&t.paste==="qq"?"st.channels.qq.onebot":t.kind==="im"?"st.channels.route.twoWay":"st.channels.route.alerts"}function eO(t){return t.kind==="push"?t.providerId==="telegram"?"st.channels.route.alertsBotHint":"st.channels.route.alertsHint":t.mode==="plugin"?"st.channels.qq.officialHint":t.mode==="paste"&&t.paste==="qq"?"st.channels.qq.onebotHint":"st.channels.route.twoWayHint"}function tO({settings:t,providers:s,setupCatalog:n,setupFailed:a,onRetrySetup:i,qr:r,onClose:o,onAdded:l}){const{t:c}=D(),d=x.useMemo(()=>AM(n,a,s),[n,a,s]),[u,p]=x.useState(null),[h,b]=x.useState(null),m=d.find(y=>y.id===u),f=m?.routes.filter(y=>y.unavailable===void 0)??[],g=m===void 0?void 0:f.find(y=>yr(y.route)===h)??(f.length===1||!dc(m)?f[0]:void 0),v=()=>{g?.route.kind==="im"&&g.route.mode==="wechat"&&r.active?r.cancel():r.reset(),h!==null&&m!==void 0&&dc(m)||p(null),b(null)};return e.jsx($n,{title:m===void 0?c("st.channels.add"):c("st.channels.addBrand",{brand:c(qo[m.id])}),overlayId:"settings-add-channel",width:"lg",onClose:o,data:{"data-channel-add":m===void 0?"pick":m.id},back:m===void 0?void 0:{label:c("st.channels.backAria"),onClick:v,data:{"data-channel-back":""}},stepKey:m===void 0?"pick":m.id,children:e.jsx("div",{id:"st-card-notify-add",className:"space-y-5","data-im-connect-drawer":!0,children:m===void 0?e.jsx(sO,{brands:d,setupFailed:a,onRetrySetup:i,onPick:y=>{r.reset(),p(y),b(null)}}):e.jsxs(e.Fragment,{children:[dc(m)?e.jsx(nO,{brand:m,value:g===void 0?null:yr(g.route),onChange:y=>{r.reset(),b(y)}}):null,g!==void 0?e.jsx(aO,{option:g,settings:t,providers:s,setupCatalog:n,qr:r,onAdded:l,onCancel:o},yr(g.route)):null]})})})}function sO({brands:t,setupFailed:s,onRetrySetup:n,onPick:a}){const{t:i}=D();return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3","data-channel-brands":!0,children:t.map(r=>{const o=$M(r),l=r.routes.some(u=>u.route.kind==="im"&&u.unavailable===void 0),c=r.routes.some(u=>u.route.kind==="push"&&u.unavailable===void 0),d=r.routes.find(u=>u.unavailable!==void 0);return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!o,onClick:()=>{a(r.id)},"data-channel-brand":r.id,"data-unavailable":o?void 0:"true",className:"flex h-full min-h-[92px] w-full flex-col items-start gap-2.5 rounded-lg border border-hairline bg-panel p-3 text-left transition-[border-color,box-shadow] hover:border-hairline-strong hover:shadow-[var(--kiki-sheet-shadow)] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:bg-transparent disabled:hover:border-hairline disabled:hover:shadow-none",children:[e.jsxs("span",{className:"flex w-full items-center gap-2.5",children:[e.jsx("span",{className:o?"":"opacity-45",children:e.jsx(mk,{brand:r.id,twoWay:l})}),e.jsx("span",{className:`min-w-0 truncate text-[13px] font-medium ${o?"text-ink":"text-ink-faint"}`,children:i(qo[r.id])})]}),e.jsx("span",{className:"flex flex-wrap gap-1",children:o?e.jsxs(e.Fragment,{children:[l?e.jsx(xd,{twoWay:!0}):null,c?e.jsx(xd,{twoWay:!1}):null]}):e.jsx("span",{className:"text-[11.5px] leading-4 text-ink-faint","data-notify-unavailable-provider":d?.route.kind==="push"?d.route.providerId:r.id,children:d?.unavailable==="setupCatalog"?i("st.channels.unavailable.setup"):i(Ku(d?.reason))})})]})},r.id)})}),s?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-im-setup-catalog-error":!0,children:[e.jsx(pe,{feedback:{tone:"error",text:i("st.im.setup.catalogError")}}),e.jsx("button",{type:"button",className:Q,"data-im-setup-catalog-retry":!0,onClick:n,children:i("st.im.retry")})]}):null]})}function nO({brand:t,value:s,onChange:n}){const{t:a}=D();return e.jsx("div",{role:"radiogroup","aria-label":a("st.channels.routeAria"),className:"grid gap-2 sm:grid-cols-2","data-channel-routes":!0,children:t.routes.map(i=>{const r=yr(i.route),o=r===s,l=i.unavailable!==void 0;return e.jsxs("button",{type:"button",role:"radio","aria-checked":o,disabled:l,"data-channel-route":r,onClick:()=>{n(r)},className:`flex flex-col items-start gap-1.5 rounded-lg border p-3 text-left transition-colors focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-50 ${o?"border-selected-ink/50 bg-selected/40":"border-hairline bg-panel hover:border-hairline-strong"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:`flex h-3.5 w-3.5 items-center justify-center rounded-full border ${o?"border-selected-ink":"border-hairline-strong"}`,children:o?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-selected-ink"}):null}),e.jsx("span",{className:"text-[13px] font-medium text-ink",children:a(XM(i.route))})]}),e.jsx("span",{className:"pl-[22px] text-[12px] leading-4 text-ink-faint",children:i.unavailable==="setupCatalog"?a("st.channels.unavailable.setup"):i.unavailable==="dependency"?a(Ku(i.reason)):a(eO(i.route))})]},r)})})}function aO({option:t,settings:s,providers:n,setupCatalog:a,qr:i,onAdded:r,onCancel:o}){const{t:l}=D(),c=Oe(),d=Fn(),u=qi(),[p,h]=x.useState(),{route:b}=t;if(b.kind==="push"){const f=n.find(g=>g.id===b.providerId);return f===void 0||s===void 0?e.jsx("p",{className:"text-[13px] text-ink-soft",children:l("st.notify.loadFailed",{detail:""})}):e.jsx(EM,{settings:s,provider:f,onDone:g=>{g===null?o():r(`push:${g}`)}})}if(b.mode==="wechat")return e.jsxs("div",{className:"space-y-3","data-im-setup-route":"wechat",children:[e.jsx("p",{className:"text-center text-[13px] text-ink-soft",children:l("st.channels.wechat.scanHint")}),e.jsx(uk,{qr:i})]});if(b.mode==="plugin")return e.jsx(VM,{});if(b.mode==="paste")return e.jsx(pk,{kind:b.paste,onConnected:f=>{r(`im:${f}`)}});const m=a?.platforms.find(f=>f.provider_kind===b.provider);return m===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx(dk,{platform:m,savedInstanceId:p,busy:d.saving,onSaved:async f=>{h(f.provider_instance_id),await c.invalidateQueries({queryKey:$t})},onCheckAndListen:f=>{d.run(async()=>{const g=await u(f);return r(`im:${f}`),g})}}),e.jsx(pe,{feedback:d.error===void 0?null:{tone:"error",text:d.error}})]})}function iO({label:t,configured:s,optional:n,disabled:a,reveal:i,onCommit:r}){const{t:o}=D(),[l,c]=x.useState(Dt),[d,u]=x.useState(!1),p=x.useCallback(async h=>{if(h.mode==="keep")return;const b=h.mode==="clear"?null:h.value.trim();if(b==="")return;u(!0);const m=await r(b);u(!1),m&&c(Dt)},[r]);return e.jsx("div",{"data-notify-secret":t,onBlur:h=>{h.currentTarget.contains(h.relatedTarget)||l.mode==="set"&&p(l)},onKeyDown:h=>{rt(h)||(h.key==="Enter"&&l.mode==="set"&&(h.preventDefault(),p(l)),h.key==="Escape"&&l.mode==="set"&&c(Dt))},children:e.jsx(Dn,{label:n?`${t} · ${o("st.notify.optional")}`:t,source:s?"kiki":"none",draft:l,onChange:h=>{c(h),h.mode==="clear"&&p(h)},reveal:s?i:void 0,clearable:s,disabled:a||d})})}function rO({channelId:t,channel:s,instanceId:n,instance:a,provider:i,settings:r,save:o,pending:l,setPending:c}){const{t:d,tp:u}=D(),{api:p,apply:h,refresh:b,reveal:m}=Fi(),f=Zy(r,n).length-1,g=k=>l===k?e.jsx(ot,{saving:o.saving,saved:o.saved}):null,{health:v,...y}=a,w=(k,j,T=vr(r,n))=>(c(k),o.run(async()=>{h(await p.upsertInstance(n,{...y,options:j,revision:fi()},T))})),N=(k,j)=>{c(k);const{health:T,...A}=s;o.run(async()=>{h(await p.upsertChannel(t,{...A,target:j,revision:fi()}))})},_=async(k,j)=>{const T=a.options[k.key],A=typeof T=="string"?T:void 0;if(j===null&&!k.required&&A!==void 0){const{[k.key]:P,...R}=a.options,{[A]:L,...I}=vr(r,n);return w(k.key,R,I)}return c(k.key),o.run(async()=>{let P=A;if(P===void 0){const R=Jy(a.provider_id,n,k.purpose??k.key);P=`${n}.${k.purpose??k.key}`,h(await p.upsertInstance(n,{...y,options:{...a.options,[k.key]:P},revision:fi()},{...vr(r,n),[P]:R}))}await p.setCredential(P,j),await b()})},C=i.instance_fields.filter(k=>k.kind!=="json"),S=i.instance_fields.filter(k=>k.kind==="json");return e.jsxs(e.Fragment,{children:[C.length>0||S.length>0?e.jsxs(is,{title:d("st.notify.connection"),help:f>0?u("st.notify.connectionShared",f,{n:f}):void 0,children:[C.map(k=>{const j=Os(d,i.id,k),T=a.options[k.key],A=`notify-${t}-${k.key}`;if(k.kind==="secret"){const P=typeof T=="string"?T:void 0;return e.jsx("div",{className:"py-1",children:e.jsx(iO,{label:j,optional:!k.required,configured:P!==void 0&&r.credential_slots[P]?.configured===!0,disabled:o.saving,reveal:()=>m(P??""),onCommit:R=>_(k,R)})},k.key)}return k.kind==="select"?e.jsxs(ge,{label:j,children:[g(k.key),e.jsx(Qe,{id:A,ariaLabel:j,mono:!0,value:typeof T=="string"?T:"",disabled:o.saving,choices:(k.options??[]).map(P=>({value:P,label:P})),onChange:P=>{w(k.key,{...a.options,[k.key]:P})}})]},k.key):e.jsxs(ge,{label:k.required?j:`${j} · ${d("st.notify.optional")}`,htmlFor:A,children:[g(k.key),e.jsx(kt,{id:A,className:k.kind==="number"?"w-28 text-right":"w-64 font-mono",value:typeof T=="string"||typeof T=="number"||typeof T=="boolean"?String(T):"",disabled:o.saving,inputMode:k.kind==="number"?"numeric":void 0,validate:P=>k.required&&P===""?d("st.notify.fieldRequired",{field:j}):null,onCommit:P=>{const{[k.key]:R,...L}=a.options;w(k.key,P===""?L:{...L,[k.key]:k.kind==="number"?Number(P):P})}})]},k.key)}),S.length>0?e.jsx(et,{summary:d("st.notify.advanced"),"data-notify-advanced":!0,children:S.map(k=>e.jsxs("div",{className:"space-y-1 pb-1",children:[e.jsx("label",{htmlFor:`notify-${t}-${k.key}`,className:"block text-[12px] text-ink",children:Os(d,i.id,k)}),e.jsx(CM,{id:`notify-${t}-${k.key}`,label:Os(d,i.id,k),value:a.options[k.key],disabled:o.saving,onCommit:j=>{const{[k.key]:T,...A}=a.options;w(k.key,j===void 0?A:{...A,[k.key]:j})}}),k.key==="private_grant"?e.jsx("p",{className:"text-[11px] text-ink-faint",children:d("st.notify.field.privateGrantHint")}):null,g(k.key)]},k.key))}):null]}):null,i.target_fields.length>0?e.jsx(is,{title:d("st.notify.sendTo"),children:i.target_fields.map(k=>{const j=Os(d,i.id,k),T=s.target[k.key],A=`notify-${t}-target-${k.key}`;return e.jsxs(ge,{label:k.required?j:`${j} · ${d("st.notify.optional")}`,htmlFor:A,children:[g(`target.${k.key}`),e.jsx(kt,{id:A,className:k.kind==="number"?"w-28 text-right":"w-48 font-mono",value:typeof T=="string"||typeof T=="number"||typeof T=="boolean"?String(T):"",disabled:o.saving,inputMode:k.kind==="number"?"numeric":void 0,validate:P=>k.required&&P===""?d("st.notify.fieldRequired",{field:j}):k.kind==="number"&&P!==""&&!/^-?\d+$/u.test(P)?d("st.notify.fieldRequired",{field:j}):null,onCommit:P=>{const{[k.key]:R,...L}=s.target;N(`target.${k.key}`,P===""?L:{...L,[k.key]:k.kind==="number"?Number(P):P})}})]},k.key)})}):null]})}const oO={dependency:"st.notify.state.dependency",unauthorized:"st.notify.state.unauthorized",connection:"st.notify.state.connection",noCredential:"st.notify.state.noCredential",ok:"st.notify.state.ok",idle:"st.channels.state.ready"},lO={dependency:"warn",unauthorized:"error",connection:"error",noCredential:"warn",ok:"ok",idle:"idle"};function cO({state:t,enabled:s,paused:n}){const{t:a}=D(),i=t!=="ok"&&t!=="idle";return!i&&!s?e.jsx(ua,{tone:"idle",data:{"data-notify-state":t},children:a("st.notify.filter.disabled")}):!i&&n?e.jsx(ua,{tone:"idle",data:{"data-notify-state":t},children:a("st.notify.pausedShort")}):e.jsx(ua,{tone:lO[t],data:{"data-notify-state":t},children:a(oO[t])})}const ef=new Set(["failed","unknown","expired"]);function dO({deliveries:t}){const{t:s,time:n}=D();return e.jsx(et,{summary:`${s("st.notify.deliveries")} · ${t.length}`,"data-notify-deliveries":!0,children:t.length===0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s("st.notify.deliveriesEmpty")}):e.jsx("ol",{className:"max-h-56 space-y-0.5 overflow-y-auto",children:t.slice(0,20).map(a=>e.jsxs("li",{"data-notify-delivery":a.status,className:"flex flex-wrap items-baseline gap-x-3 text-[12px] leading-5",children:[e.jsx("time",{dateTime:a.created_at,title:n.absoluteTime(a.created_at),className:"w-24 shrink-0 tabular-nums text-ink-faint",children:n.relativeTime(a.created_at)}),e.jsx("span",{className:ef.has(a.status)?"text-danger":"text-ink",children:s(`st.notify.delivery.${a.status}`)}),ef.has(a.status)&&a.result!==null?e.jsx("span",{className:"text-ink-soft",children:s(dd(a.result.error_kind))}):null,a.attempt>1?e.jsx("span",{className:"text-ink-faint",children:s("st.notify.attempt",{n:a.attempt})}):null]},a.delivery_id))})})}function uO({channelId:t,channel:s,settings:n,provider:a,deliveries:i,open:r,onToggle:o}){const{t:l,time:c}=D(),{api:d,apply:u,refresh:p,refreshDeliveries:h}=Fi(),b=bt(),[m,f]=x.useState(null),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(!1),[C,S]=x.useState(!1),k=s.provider_instance_id,j=n.provider_instances[k],T=j?.provider_id??"",A=Fo(l,T),P=s.label??j?.label??A,R=Uu(s,j,a,n.credential_slots),L=R==="dependency",I=Vh(i,!1),$=Vh(i,!0),E=$!==void 0&&(I===void 0||$.created_at>I.created_at)?$:void 0,M=`notify-channel-${t}`,z=Y=>m===Y?e.jsx(ot,{saving:b.saving,saved:b.saved}):null,{health:H,...U}=s,X=(Y,O)=>{f(Y),b.run(async()=>{u(await d.upsertChannel(t,{...U,...O}))})},q=async()=>{v("check"),w(null);try{const Y=await d.checkCredential(k),O={provider:A};w(Y.result==="ok"?{tone:"success",text:l("st.notify.check.ok",O)}:Y.result==="requires_test_send"?{tone:"info",text:l("st.notify.check.requiresTest",O)}:{tone:"error",text:l(Y.health==="unauthorized"?"st.notify.check.unauthorized":"st.notify.check.connection",O)}),await p()}catch(Y){w({tone:"error",text:Y instanceof Error?Y.message:String(Y)})}finally{v(null)}},F=async()=>{v("test"),w(null);try{const Y=await d.sendTest(t);w(Y.status==="accepted_by_provider"?{tone:"success",text:l("st.notify.test.accepted",{provider:A})}:Y.status==="failed"||Y.status==="unknown"||Y.status==="expired"?{tone:"error",text:l("st.notify.test.failed",{reason:l(dd(Y.result?.error_kind))})}:{tone:"info",text:l("st.notify.test.queued")}),await Promise.all([p(),h()])}catch(Y){w({tone:"error",text:Y instanceof Error?Y.message:String(Y)})}finally{v(null)}},V=Zy(n,k).length<=1,se=async()=>{S(!0);const Y=await b.run(async()=>{u(V?await d.deleteInstance(k):await d.deleteChannel(t))});S(!1),Y&&_(!1)};return e.jsxs(xk,{data:{"data-notify-channel":t,"data-channel-row":`push:${t}`},brand:zu(T),twoWay:!1,name:P,status:e.jsx(cO,{state:R,enabled:s.enabled,paused:!n.global.enabled}),meta:P!==A?A:void 0,open:r,onToggle:o,bodyId:M,expandLabel:l("st.notify.expandAria",{name:P}),control:e.jsxs(e.Fragment,{children:[z("enabled"),e.jsx(Be,{layout:"bare",label:l("st.notify.channelToggle",{name:P}),checked:s.enabled&&!L,disabled:b.saving||L,onChange:Y=>{X("enabled",{enabled:Y})}})]}),children:[L?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-amber-ink","data-notify-dependency":!0,children:l(Ku(a?.status_reason))}):null,eo(T)!==void 0&&(R==="noCredential"||R==="unauthorized")?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-5 text-ink-soft","data-notify-guide":T,children:l(eo(T))}):null,e.jsxs(ge,{label:l("st.notify.name"),htmlFor:`${M}-label`,children:[z("label"),e.jsx(kt,{id:`${M}-label`,className:"w-56",value:s.label??"",placeholder:A,disabled:b.saving,onCommit:Y=>{const{label:O,...B}=U;f("label"),b.run(async()=>{u(await d.upsertChannel(t,Y===""?B:{...B,label:Y}))})}})]}),j!==void 0&&a!==void 0&&!L?e.jsx(rO,{channelId:t,channel:s,instanceId:k,instance:j,provider:a,settings:n,save:b,pending:m,setPending:f}):null,e.jsx(pe,{feedback:b.error}),L?null:e.jsxs(is,{title:l("st.notify.checkSection"),children:[e.jsxs(iS,{children:[e.jsx("button",{type:"button","data-notify-check":!0,className:Q,disabled:g!==null||b.saving,onClick:()=>void q(),children:l(g==="check"?"st.notify.checking":"st.notify.check")}),e.jsx("button",{type:"button","data-notify-test":!0,className:Q,disabled:g!==null||b.saving||!s.enabled||!n.global.enabled,onClick:()=>void F(),children:l(g==="test"?"st.notify.testing":"st.notify.test")})]}),e.jsx("div",{"data-notify-result":!0,children:e.jsx(pe,{feedback:y})})]}),e.jsxs(is,{title:l("st.notify.activity"),children:[e.jsxs("dl",{className:"grid gap-x-6 gap-y-1 text-[12px] sm:grid-cols-[6rem_minmax(0,1fr)]","data-notify-activity":!0,children:[e.jsx("dt",{className:"text-ink-soft",children:l("st.notify.lastSent")}),e.jsx("dd",{className:"text-ink",children:I===void 0?e.jsx("span",{className:"text-ink-faint",children:l("st.notify.never")}):c.relativeTime(I.created_at)}),E!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-soft",children:l("st.notify.lastError")}),e.jsxs("dd",{className:"text-danger",children:[c.relativeTime(E.created_at)," · ",l(dd(E.result?.error_kind))]})]}):null]}),e.jsx(dO,{deliveries:i})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-notify-remove":!0,className:Ht,disabled:b.saving,onClick:()=>{_(!0)},children:l("st.notify.remove")})}),e.jsx(Xe,{open:N,title:l("st.notify.removeTitle",{name:P}),body:l("st.notify.removeBody"),consequences:[l(V?"st.notify.removeConnection":"st.notify.removeKeepConnection")],confirmLabel:l("st.notify.remove"),busy:C,overlayId:"notify-remove",onConfirm:()=>void se(),onCancel:()=>{_(!1)}})]})}function hk({ariaLabel:t,value:s,onChange:n,disabled:a=!1,allowDefault:i=!0,dataAttr:r}){const{t:o}=D(),l=[...i?[{value:"default",label:o("st.im.coalesce.followDefault")}]:[],{value:"0",label:o("st.im.coalesce.off")},{value:"2000",label:o("st.im.coalesce.2s")},{value:"3000",label:o("st.im.coalesce.3s")},{value:"5000",label:o("st.im.coalesce.5s")}],c=s==null?i?"default":"0":String(s);return e.jsx(He,{ariaLabel:t,value:c,disabled:a,dataAttr:r,choices:l,onChange:d=>{n(d==="default"?null:Number(d))}})}const tf={sender:1,topic:2,chat:3};function Bi(t){if(t===void 0)return!1;const s=t.trim();return s.length>0&&s!=="0"}function uc(t){if(!t)return[];const s=new Set,n=[];for(const a of t){const i=a.trim();!Bi(i)||s.has(i)||(s.add(i),n.push(i))}return n}function fk(t,s,n){const a=new Map,i=r=>{if(r.chat_id!==t.chat_id||!Bi(r.sender_id))return;const o=r.sender_id.trim(),l=r.sender_name?.trim(),c=a.get(o);(!c||!c.senderName&&l)&&a.set(o,l?{senderId:o,senderName:l}:{senderId:o})};if(i(t),n){for(const r of n.discoveries)r.provider_instance_id===s&&i(r.identity);for(const r of n.bindings)r.provider_instance_id===s&&i(r.identity);for(const r of n.strangers??[])r.provider_instance_id===s&&i(r.identity)}return[...a.values()]}function pO(t){return t==="telegram"?"st.im.wake.senderIdHint.telegram":t==="feishu_app"?"st.im.wake.senderIdHint.feishu_app":t==="onebot_v11"?"st.im.wake.senderIdHint.onebot_v11":t==="discord"?"st.im.wake.senderIdHint.discord":t==="slack"?"st.im.wake.senderIdHint.slack":t==="matrix"?"st.im.wake.senderIdHint.matrix":"st.im.wake.senderIdHint.default"}function mO(t,s=!1){return[{value:"sender",label:t("st.im.groupScope.sender")},{value:"topic",label:t("st.im.groupScope.topic"),disabled:s},{value:"chat",label:t("st.im.groupScope.chat")}]}function xO(t,s){const n=[{value:"mention",label:t("st.im.wake.mention")},{value:"always",label:t("st.im.wake.always")},{value:"senders",label:t("st.im.wake.senders")}];return s==="mention_or_reply"?n.unshift({value:"mention_or_reply",label:t("st.im.wake.mention_or_reply")}):s==="manual"&&n.push({value:"manual",label:t("st.im.wake.manual")}),n}function bk({providerKind:t,scope:s,wake:n,prefixes:a,senders:i,knownMembers:r=[],topicDisabled:o=!1,showWake:l=!1,disabled:c,prefix:d,onScope:u,onWake:p,onPrefixes:h,onSenders:b}){const{t:m}=D(),f=x.useId(),g=x.useId(),[v,y]=x.useState(""),w=(a??[]).join(", "),N=uc(i),_=s!=="sender"||l,C=new Map(r.map(j=>[j.senderId,j.senderName])),S=r.filter(j=>!N.includes(j.senderId)),k=()=>{if(!b)return;const j=v.split(/[\s,,]+/u).map(A=>A.trim()).filter(Bi);if(j.length===0)return;const T=uc([...N,...j]);y(""),T.join(",")!==N.join(",")&&b(T)};return e.jsxs("div",{className:"space-y-3","data-im-group-options":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-x-6 gap-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.groupScope")}),e.jsx(He,{ariaLabel:m("st.im.groupScope"),value:s,disabled:c,dataAttr:`${d}-scope`,choices:mO(m,o),onChange:u})]}),_?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.groupPolicy")}),e.jsx(He,{ariaLabel:m("st.im.groupPolicy"),value:n,disabled:c,dataAttr:`${d}-wake`,choices:xO(m,n),onChange:p})]}):null]}),_&&(n==="mention"||n==="mention_or_reply")&&h?e.jsxs("div",{className:"space-y-1 max-w-sm",children:[e.jsx("label",{className:"text-[13px] text-ink-soft block",htmlFor:f,children:m("st.im.wake.prefixes")}),e.jsx("input",{id:f,type:"text",defaultValue:w,placeholder:m("st.im.wake.prefixesPlaceholder"),disabled:c,className:`${Ce} text-[13px]`,"data-im-prefixes":d,onBlur:j=>{const T=j.currentTarget.value.split(",").map(A=>A.trim()).filter(Boolean);T.join(",")!==(a??[]).join(",")&&h(T)},onKeyDown:j=>{rt(j)||j.key==="Enter"&&j.currentTarget.blur()}},w)]}):null,_&&n==="senders"&&b?e.jsxs("div",{className:"space-y-2.5 max-w-lg rounded-lg border border-hairline bg-paper/60 p-3","data-im-group-senders":d,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[12.5px] font-medium text-ink-soft",children:m("st.im.wake.sendersLabel")}),N.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5","data-im-sender-chips":d,children:N.map(j=>{const T=C.get(j);return e.jsxs("span",{"data-im-sender-chip":j,className:"inline-flex items-center gap-1.5 rounded-md border border-hairline-strong bg-panel px-2 py-0.5 text-[12px] text-ink",children:[T?e.jsx("span",{className:"font-medium",children:T}):null,e.jsx("span",{className:"font-mono text-[11.5px] text-ink-soft",title:j,children:At(j)}),e.jsx("button",{type:"button",disabled:c,"data-im-sender-remove":j,"aria-label":m("st.im.wake.senderRemove",{id:T?`${T} (${j})`:j}),onClick:()=>{b(N.filter(A=>A!==j))},className:"ml-0.5 rounded px-1 text-ink-faint transition-colors hover:bg-ink/[0.06] hover:text-ink disabled:opacity-50",children:"×"})]},j)})}):e.jsx("p",{className:"text-[12px] text-amber-ink","data-im-senders-empty":d,children:m("st.im.wake.sendersEmpty")})]}),S.length>0?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[12px] text-ink-faint",children:m("st.im.wake.sendersKnown")}),e.jsx("div",{className:"flex flex-wrap gap-1.5","data-im-sender-candidates":d,children:S.map(j=>e.jsxs("button",{type:"button",disabled:c,"data-im-sender-pick":j.senderId,onClick:()=>{b(uc([...N,j.senderId]))},className:"inline-flex items-center gap-1 rounded-md border border-dashed border-hairline-strong bg-panel px-2 py-0.5 text-[12px] text-ink-soft transition-colors hover:border-selected-ink/50 hover:text-ink disabled:opacity-50",children:[e.jsx("span",{children:"+"}),j.senderName?e.jsx("span",{children:j.senderName}):null,e.jsx("span",{className:"font-mono text-[11px] text-ink-faint",title:j.senderId,children:At(j.senderId)})]},j.senderId))})]}):null,e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{id:g,type:"text",value:v,placeholder:m("st.im.wake.senderInputPlaceholder"),"aria-label":m("st.im.wake.senderInputPlaceholder"),disabled:c,className:`${Ce} min-w-0 flex-1 font-mono text-[12.5px]`,"data-im-sender-input":d,onChange:j=>{y(j.target.value)},onKeyDown:j=>{rt(j)||j.key==="Enter"&&(j.preventDefault(),k())}}),e.jsx("button",{type:"button",disabled:c||v.trim().length===0,"data-im-sender-add":d,onClick:k,className:Q,children:m("st.im.wake.senderAdd")})]}),e.jsx("p",{className:"text-[11.5px] text-ink-faint","data-im-sender-hint":t,children:m(pO(t))})]})]}):null]})}function hO({binding:t,snapshot:s,policy:n,catalog:a,setupPlatform:i,inbound:r=!0,expanded:o,onToggle:l}){const{t:c}=D(),{client:d}=be(),u=Fn(),[p,h]=x.useState(!1),b=Rb(),[m,f]=x.useState(""),[g,v]=x.useState(!1),[y,w]=x.useState(null),N=t.identity.chat_kind==="group"&&t.provider_kind!=="wechat_bridge",_=t.identity.topic_id==="0"||i?.capabilities.threads===!1,C=t.binding_scope??"sender",S=t.group_policy?.wake??"mention",k=N?fk(t.identity,t.provider_instance_id,s):[],j=je({queryKey:[...$t,"session-search",m.trim()],queryFn:async()=>(await d.listSessions({q:m.trim(),page_size:20})).items,enabled:o&&m.trim()!==""}),T=je({queryKey:[...$t,"target-channels",t.session_id],queryFn:()=>d.imSessions.channelViews(t.session_id),enabled:o&&t.session_id!==void 0&&typeof d.imSessions.channelViews=="function"}),A=t.session_id!==void 0&&!(a?.sessions.some(F=>F.id===t.session_id)??!1)?[t.session_id]:[],P=Fd(A,d),R=t.session_id!==void 0?P(t.session_id).title:void 0,L=a===void 0?void 0:{...a,sessions:[...new Map([...a.sessions,...t.session_id!==void 0&&R!==void 0?[{id:t.session_id,title:R}]:[],...(j.data??[]).map(F=>({id:F.id,title:F.title?.trim()||F.id}))].map(F=>[F.id,F])).values()]},I=nk(t.identity,c),$=t.enabled&&!t.pending_reanchor&&Uw({allowed:n.allowed,defaultEnabled:n.default_enabled,sessionEnabled:t.session_enabled}),E=!n.allowed||!t.enabled||t.pending_reanchor,M=F=>{w(null),u.run(()=>d.imSessions.updateBinding(t.id,F))},z=ak(t),H=T.data?.channels.find(F=>F.id===`im:${t.id}`),U=F=>{if(F===z||u.saving)return;const V=z;(async()=>await u.run(()=>d.imSessions.updateBinding(t.id,{target:md(F),rebind:!0}))&&xs({text:c("st.im.rebind.transferred"),undoFailedText:c("toast.undoFailed"),undo:async()=>{await d.imSessions.updateBinding(t.id,{target:md(V),rebind:!0})}}))()},X=F=>{if(F!==C){if(tf[F]>tf[C]&&F!=="sender"){const V=C,se=t.group_policy;(async()=>await u.run(()=>d.imSessions.updateBinding(t.id,{binding_scope:F,group_policy:se??{wake:"mention"},rebind:!0}))&&xs({text:c("st.im.scopeExpand.expanded"),undoFailedText:c("toast.undoFailed"),undo:async()=>{await d.imSessions.updateBinding(t.id,se===void 0?{binding_scope:V,group_policy:{wake:"mention"}}:{binding_scope:V,group_policy:se})}}))();return}M({binding_scope:F})}},q=async()=>{if(!(g||typeof d.imSessions.testBinding!="function")){v(!0),w(null);try{const F=await d.imSessions.testBinding(t.id);if(F.status==="delivered")w({tone:"success",text:c("st.im.testBinding.delivered")});else if(F.status==="unknown")w({tone:"info",text:c("st.im.testBinding.unknown")});else if(F.status==="partial"){const V=F.detail??(F.message_ids.length>0?c("st.im.testBinding.partial"):c("st.im.error"));w({tone:"info",text:V})}else{const V=F.detail==="binding_disabled"?c("st.im.testBinding.failed.binding_disabled"):F.detail==="channel_not_connected"?c("st.im.testBinding.failed.channel_not_connected"):c("st.im.testBinding.failed",{detail:F.detail??c("st.im.error")});w({tone:"error",text:V})}}catch(F){const V=F instanceof Error&&F.message.length>0?F.message:c("st.im.error");w({tone:"error",text:c("st.im.testBinding.failed",{detail:V})})}finally{v(!1)}}};return e.jsxs("div",{"data-im-binding":t.id,"data-open":o?"true":void 0,"aria-busy":u.saving||g,children:[e.jsxs("div",{className:`flex min-h-11 items-center gap-2 py-1.5 transition-colors ${o?"bg-ink/[0.03] rounded-lg":""}`,children:[e.jsx("button",{type:"button","data-im-binding-options-toggle":t.id,"aria-expanded":o,"aria-controls":`im-binding-editor-${t.id}`,"aria-label":c("st.notify.expandAria",{name:I}),onClick:l,className:"group/row flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1 text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-selected-ink/40",children:e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] font-medium text-ink","data-im-binding-identity":!0,children:I}),t.enabled?null:e.jsx("span",{className:"shrink-0 rounded-[4px] border border-hairline px-1.5 py-px text-[11px] leading-4 text-ink-faint",children:c("st.im.disabled")})]}),e.jsxs("span",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-[12px]",children:[e.jsx(ua,{tone:E?t.pending_reanchor?"warn":"idle":$?"ok":"idle",children:c(E?t.pending_reanchor?"st.im.pendingReanchor":n.allowed?"st.im.railOffBinding":"st.im.railOffAllowed":$?"st.im.on":"st.im.off")}),e.jsx("span",{"aria-hidden":!0,className:"text-ink-faint",children:"·"}),e.jsx("span",{className:"min-w-0 truncate text-ink-faint",children:DM(L,t,c)})]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 pl-1",children:[e.jsxs("button",{type:"button",role:"switch","aria-checked":$,"aria-label":`${I}: ${c("st.im.sessionSwitch")}`,className:"inline-flex min-h-8 items-center gap-2 rounded-md px-2 py-1 text-[13px] text-ink transition-colors hover:bg-ink/[0.04] disabled:cursor-not-allowed disabled:opacity-50","data-im-session-switch":t.id,disabled:u.saving||E,onClick:()=>{M({session_enabled:!$})},children:[e.jsx("span",{"aria-hidden":!0,className:`relative inline-flex h-[18px] w-8 shrink-0 items-center rounded-full ring-1 transition-colors ${$?"bg-selected ring-selected-ink/45":"bg-hairline ring-hairline-strong"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full transition-transform ${$?"translate-x-[16px] bg-selected-ink":"translate-x-[3px] bg-ink-faint"}`})}),e.jsxs("span",{className:"sr-only",children:[c("st.im.sessionSwitch"),": ",c($?"st.im.on":"st.im.off")]})]}),e.jsx("button",{type:"button","data-im-binding-menu":t.id,...b.triggerProps,"aria-label":c("st.im.bindingMenuAria",{name:I}),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:e.jsx(de,{name:"more",size:14})})]})]}),E?e.jsx("p",{className:"sr-only","data-im-binding-blocked":!0,children:c(t.pending_reanchor?"st.im.pendingReanchor":n.allowed?"st.im.railOffBinding":"st.im.railOffAllowed")}):null,y!==null?e.jsx("div",{className:"py-1","data-im-test-binding-result":t.id,children:e.jsx(pe,{feedback:y})}):null,e.jsx(Lb,{...b.popoverProps,role:"menu",align:"end",widthClassName:"w-44",label:c("st.im.bindingMenuAria",{name:I}),data:{"data-im-binding-menu-panel":t.id},children:e.jsxs("div",{className:"-m-1.5 flex flex-col p-1",children:[e.jsx("button",{type:"button",role:"menuitem","data-im-test-binding":t.id,disabled:u.saving||g,onClick:()=>{b.setOpen(!1),q()},className:"flex min-h-9 w-full items-center rounded-md px-3 py-1.5 text-left text-[13px] text-ink outline-none transition-colors hover:bg-paper focus-visible:bg-paper disabled:cursor-not-allowed disabled:opacity-50",children:c(g?"st.im.testingBinding":"st.im.testBinding")}),e.jsx("button",{type:"button",role:"menuitem","data-im-remove":t.id,onClick:()=>{b.setOpen(!1),h(!0),o||l()},className:"flex min-h-9 w-full items-center rounded-md px-3 py-1.5 text-left text-[13px] text-danger outline-none transition-colors hover:bg-paper focus-visible:bg-paper",children:c("st.im.unbind")})]})}),e.jsxs("div",{id:`im-binding-editor-${t.id}`,hidden:!o,"data-im-binding-details":t.id,className:"space-y-4 pl-1 pb-3 pt-2",children:[e.jsxs("div",{className:"max-w-md space-y-1.5",children:[e.jsx("span",{className:$e,children:c("st.im.target")}),e.jsx(Qe,{id:`im-binding-target-${t.id}`,variant:"form",ariaLabel:`${I}: ${c("st.im.target")}`,value:z,choices:FM(L,t,c),emptyText:t.session_id?ya(t.session_id,R):void 0,disabled:u.saving,onChange:U,dataAttr:"data-im-binding-target"}),e.jsx("input",{type:"search","data-im-binding-target-search":!0,value:m,"aria-label":c("st.im.searchTarget"),placeholder:c("st.im.searchTarget"),className:Ce,onChange:F=>{f(F.target.value)}}),j.isError?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:c("st.im.searchError")}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:"text-[13px] text-ink-soft",children:c("st.im.sessionSwitch")}),e.jsx(He,{ariaLabel:`${I}: ${c("st.im.sessionSwitch")}`,value:t.session_enabled===void 0?"default":t.session_enabled?"on":"off",disabled:u.saving||t.pending_reanchor,dataAttr:"data-im-binding-policy",choices:[{value:"default",label:c("st.im.followDefault")},{value:"on",label:c("st.im.on")},{value:"off",label:c("st.im.off")}],onChange:F=>{M({session_enabled:F==="default"?null:F==="on"})}})]}),N&&r?e.jsx(bk,{providerKind:t.provider_kind,scope:C,wake:S,prefixes:t.group_policy?.prefixes,senders:t.group_policy?.senders,knownMembers:k,showWake:t.group_policy!==void 0,topicDisabled:_,disabled:u.saving,prefix:"data-im-binding",onScope:X,onWake:F=>{const V=F==="senders"&&t.group_policy?.senders===void 0&&Bi(t.identity.sender_id)?[t.identity.sender_id.trim()]:t.group_policy?.senders;M({group_policy:{...t.group_policy,wake:F,...V!==void 0?{senders:V}:{}}})},onPrefixes:F=>{F.join(",")!==(t.group_policy?.prefixes??[]).join(",")&&M({group_policy:{...t.group_policy,wake:S,prefixes:F}})},onSenders:F=>{M({group_policy:{...t.group_policy,wake:S,senders:F}})}}):null,e.jsx(yk,{kind:t.provider_kind,setupPlatform:i,capabilities:H?.capabilities,busy:t.busy,reply:t.reply,actions:t.mobile_interactions,coalesceWindow:t.coalesce_window_ms,disabled:u.saving,prefix:"data-im-binding",coalesceAttr:"data-im-binding-coalesce",onBusy:F=>{M({busy:F})},onReply:F=>{M({reply:F})},onActions:F=>{M({mobile_interactions:F})},onCoalesceWindow:F=>{M({coalesce_window_ms:F})}}),e.jsxs(et,{summary:c("st.section.advanced"),"data-im-binding-advanced":t.id,children:[e.jsx(gk,{identity:t.identity}),e.jsx("button",{type:"button",className:Q,"data-im-enabled":t.id,disabled:u.saving,onClick:()=>{M({enabled:!t.enabled})},children:c(t.enabled?"st.im.disable":"st.im.enable")})]}),p?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-ink-soft",children:c("st.im.removeConfirm",{name:I})}),e.jsx("button",{type:"button",className:Ht,"data-im-remove-confirm":t.id,disabled:u.saving,onClick:()=>{u.run(()=>d.imSessions.removeBinding(t.id))},children:c("st.im.unbind")}),e.jsx("button",{type:"button",className:Q,onClick:()=>{h(!1)},children:c("common.cancel")})]}):null,e.jsx(pe,{feedback:u.error===void 0?null:{tone:"error",text:u.error}})]})]})}function gk({identity:t}){const{t:s}=D(),n=t.sender_id.trim()===""||t.sender_id.trim()===t.chat_id.trim(),a=[{label:s("st.im.chatId"),value:t.chat_id},...n?[]:[{label:s("st.im.senderId"),value:t.sender_id}],...t.topic_id!=="0"?[{label:s("st.im.topicId"),value:t.topic_id}]:[]];return e.jsx("p",{"data-im-identity-ids":!0,className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:a.map((i,r)=>e.jsxs("span",{className:"inline-flex min-w-0 items-baseline gap-1",children:[r>0?e.jsx("span",{"aria-hidden":!0,className:"text-ink-faint",children:"·"}):null,e.jsxs("span",{children:[i.label,":"]}),e.jsx("button",{type:"button","data-im-copy-id":i.value,title:s("st.channels.copyHint",{value:i.value}),onClick:()=>{rs(i.value)},className:"min-w-0 break-all font-mono text-[11.5px] text-ink-soft underline decoration-dotted decoration-ink-faint/60 underline-offset-2 transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:At(i.value)})]},i.label))})}function fO({discovery:t,snapshot:s,catalog:n,setupPlatform:a,initialTarget:i,inbound:r=!0}){const{t:o}=D(),{client:l}=be(),c=Oe(),d=Fn(),[u,p]=x.useState(i),[h,b]=x.useState(!1),[m,f]=x.useState(!1),[g,v]=x.useState("immediate"),[y,w]=x.useState("final"),[N,_]=x.useState(!0),[C,S]=x.useState(null),k=t.identity.chat_kind==="group"&&t.provider_kind!=="wechat_bridge",j=t.identity.topic_id==="0"||a?.capabilities.threads===!1,[T,A]=x.useState("sender"),[P,R]=x.useState("mention"),[L,I]=x.useState([]),[$,E]=x.useState(()=>Bi(t.identity.sender_id)?[t.identity.sender_id.trim()]:[]),M=k?fk(t.identity,t.provider_instance_id,s):[];x.useEffect(()=>{i!==""&&p(i)},[i]);const z=t.provider_kind==="wechat_bridge"&&(t.identity.chat_kind==="group"||t.identity.topic_id!=="0"),H=u||lk(n);return e.jsxs("div",{"data-im-discovery":t.id,className:"space-y-3 rounded-lg border border-amber-rule/40 bg-amber-card p-3.5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11.5px] font-medium text-amber-ink",children:o("st.im.discovery")}),e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-0.5",children:[e.jsx("p",{className:"break-words text-[14px] font-medium text-ink",children:nk(t.identity,o)}),t.preview!==""?e.jsxs("p",{className:"min-w-0 truncate text-[13px] text-ink-soft",title:t.preview,children:["“",t.preview,"”"]}):null]}),e.jsx(gk,{identity:t.identity})]}),z?e.jsx("p",{"data-im-unsupported":!0,className:"text-[13px] leading-5 text-ink-soft",children:o("st.im.wechatDirectOnly")}):e.jsx(vk,{id:`im-target-${t.id}`,value:H,onChange:p,catalog:n,disabled:d.saving}),!z&&H.startsWith("persona:")?e.jsxs("label",{className:"flex min-h-8 items-center gap-2 text-[13px] text-ink-soft",children:[e.jsx("input",{type:"checkbox","data-im-also-home":!0,checked:h,disabled:d.saving,onChange:U=>{b(U.target.checked)}}),o("st.im.alsoHome")]}):null,k&&r?e.jsx(bk,{providerKind:t.provider_kind,scope:T,wake:P,prefixes:L,senders:$,knownMembers:M,topicDisabled:j,disabled:d.saving,prefix:"data-im-discovery",onScope:A,onWake:R,onPrefixes:I,onSenders:E}):null,m?e.jsx(yk,{kind:t.provider_kind,setupPlatform:a,busy:g,reply:y,actions:N,coalesceWindow:C,disabled:d.saving,prefix:"data-im",coalesceAttr:"data-im-discovery-coalesce",onBusy:v,onReply:w,onActions:_,onCoalesceWindow:S}):null,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:Ye,"data-im-confirm":t.id,disabled:z||H.length<=8||n===void 0||d.saving,onClick:()=>{d.run(async()=>{const U={target:md(H),busy:g,reply:ok(t.provider_kind,a)?y:"final",mobile_interactions:N,also_home:H.startsWith("persona:")&&h,coalesce_window_ms:C};k&&r&&T!=="sender"&&(U.binding_scope=T,U.group_policy={wake:P,prefixes:L.length>0?L:void 0,...P==="senders"?{senders:$}:{}});const X=await l.imSessions.confirm(t.id,U);return c.invalidateQueries({queryKey:[...$t,"catalog"]}),X})},children:o("st.im.confirm")}),e.jsx("button",{type:"button",className:Q,"data-im-dismiss":t.id,disabled:d.saving,onClick:()=>{d.run(()=>l.imSessions.dismiss(t.id))},children:o("st.im.dismiss")}),z?null:e.jsx("button",{type:"button",className:Q,"data-im-advanced-toggle":!0,"aria-expanded":m,onClick:()=>{f(U=>!U)},children:o("st.im.advancedOptions")})]}),e.jsx(pe,{feedback:d.error===void 0?null:{tone:"error",text:d.error}})]})}function vk({id:t,value:s,onChange:n,catalog:a,disabled:i,attrPrefix:r="data-im-target"}){const{t:o}=D(),{client:l}=be(),[c,d]=x.useState(""),u=s.startsWith("session:")?"session":"persona",p=c.trim(),h=je({queryKey:[...$t,"session-search",p],queryFn:async()=>(await l.listSessions({q:p,page_size:20})).items,enabled:p!==""&&u==="session"}),b=s.startsWith("session:")&&s.length>8?s.slice(8):void 0,m=Fd(b!==void 0?[b]:[],l),f=[...(a?.personas??[]).map(v=>({value:`persona:${v.id}`,label:`${o("st.im.kindPersona")} · ${v.name}`})),...[...new Map([...a?.sessions??[],...(h.data??[]).map(v=>({id:v.id,title:v.title?.trim()||v.id}))].map(v=>[v.id,v])).values()].map(v=>({value:`session:${v.id}`,label:`${o("st.im.kindSession")} · ${ya(v.id,v.title)}`}))];if(s.length>8&&!f.some(v=>v.value===s)){const v=s.slice(8),y=b!==void 0?ya(b,m(b).title):At(v);f.unshift({value:s,label:y})}const g=f.filter(v=>v.value===s||v.value.startsWith(`${u}:`)&&v.label.toLowerCase().includes(p.toLowerCase()));return e.jsxs("div",{className:"space-y-2",[`${r}-editor`]:t,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(He,{ariaLabel:o("st.im.target"),value:u,disabled:i,dataAttr:`${r}-kind`,choices:[{value:"persona",label:o("st.im.kindPersona")},{value:"session",label:o("st.im.kindSession")}],onChange:v=>{d(""),n(f.find(y=>y.value.startsWith(`${v}:`))?.value??`${v}:`)}}),u==="session"||f.length>6?e.jsx("input",{type:"search",value:c,[`${r}-search`]:"",placeholder:o("st.im.searchTarget"),"aria-label":o("st.im.searchTarget"),className:`${Ce} min-w-0 flex-1`,onChange:v=>{d(v.target.value)}}):null]}),e.jsx(Qe,{id:t,variant:"form",ariaLabel:o("st.im.target"),value:s,choices:g,onChange:n,disabled:i||g.length===0,emptyText:o("st.im.noTargetsYet"),dataAttr:r}),h.isError?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:o("st.im.searchError")}):null]})}function yk({kind:t,setupPlatform:s,capabilities:n,busy:a,reply:i,actions:r,coalesceWindow:o,disabled:l,prefix:c,coalesceAttr:d,onBusy:u,onReply:p,onActions:h,onCoalesceWindow:b}){const{t:m}=D(),f=(n??[]).map(g=>g.kind).filter(g=>g!=="text").map(g=>Zh[g]!==void 0?m(Zh[g]):g);return e.jsxs("div",{className:"space-y-2","data-im-bind-advanced":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-x-6 gap-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.busy")}),e.jsx(He,{ariaLabel:m("st.im.busy"),value:a,onChange:u,disabled:l,dataAttr:`${c}-busy`,choices:[{value:"immediate",label:m("st.im.immediate")},{value:"queue",label:m("st.im.queue")},{value:"steer",label:m("st.im.steer")}]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.text")}),e.jsx(bO,{kind:t,setupPlatform:s,value:i,onChange:p,disabled:l,dataAttr:`${c}-text`})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.actions")}),e.jsx(He,{ariaLabel:m("st.im.actions"),value:r?"on":"off",disabled:l,dataAttr:`${c}-actions`,onChange:g=>{h(g==="on")},choices:[{value:"on",label:m("st.im.on")},{value:"off",label:m("st.im.off")}]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:m("st.im.coalesce.binding")}),e.jsx(hk,{ariaLabel:m("st.im.coalesce.binding"),value:o,disabled:l,dataAttr:d,onChange:b})]})]}),f.length>0?e.jsx("p",{className:"text-[12px] text-ink-soft","data-im-binding-media":!0,children:m("st.im.cap.outboundMedia",{kinds:f.join(" / ")})}):null]})}function bO({kind:t,setupPlatform:s,value:n,onChange:a,disabled:i,dataAttr:r}){const{t:o}=D();return ok(t,s)?e.jsx(He,{ariaLabel:o("st.im.text"),value:n,onChange:a,disabled:i,dataAttr:r,choices:[{value:"final",label:o("st.im.final")},{value:"edit",label:o("st.im.edit")}]}):e.jsx("p",{className:"flex h-7 items-center text-[13px] text-ink","data-im-text-fixed":t,children:o("st.im.final")})}const gO={listening:"ok",starting:"busy",reconnecting:"busy",auth_expired:"warn",stopped:"error",paused:"idle"};function vO({account:t,data:s,catalog:n,setupPlatform:a,initialTarget:i,preselectedTarget:r,onPreselectTarget:o,open:l,onToggle:c}){const{t:d}=D(),{client:u}=be(),p=Oe(),h=Fn(),b=qi(),m=s.bindings.filter(H=>H.provider_instance_id===t.id),f=s.discoveries.filter(H=>H.provider_instance_id===t.id),g=Qu(t),[v,y]=x.useState(!1),[w,N]=x.useState(!1),[_,C]=x.useState(!1),[S,k]=x.useState(null);x.useEffect(()=>{l||k(null)},[l]);const j=ik(t,d),T=Hu(t.provider_kind),A=t.provider_kind.startsWith("plugin:kiki-qq/")||t.id.startsWith("plugin:kiki-qq/"),P=`im-account-${t.id.replace(/[^A-Za-z0-9_-]/gu,"-")}`,R=t.adapter!=="missing",L=H=>{h.run(()=>H?b(t.id):u.imSessions.listen(t.id,!1))},I=async()=>{C(!0);const H=await h.run(()=>u.imSessions.removeInstance(t.id));C(!1),H&&N(!1)},$=()=>{p.invalidateQueries({queryKey:$t})},E=r??(i||lk(n)),M=f.length>0?e.jsx(ua,{tone:"warn",data:{"data-im-instance-state":g,"data-im-connection":t.connection},children:d("st.channels.newMessages",{count:f.length})}):e.jsx(ua,{tone:gO[g],data:{"data-im-instance-state":g,"data-im-connection":t.connection},children:d(KM[g])}),z=m.length===0?d("st.channels.noConversations"):m.length===1?d("st.channels.conversationCount.one"):d("st.channels.conversationCount",{count:m.length});return e.jsxs(xk,{data:{"data-im-account":t.id,"data-im-instance-row":t.id,"data-channel-row":`im:${t.id}`},brand:T,twoWay:!0,name:j,status:M,meta:z,open:l,onToggle:c,bodyId:P,expandLabel:d("st.notify.expandAria",{name:j}),control:R?e.jsx("span",{"data-im-listen":t.id,className:"contents",children:e.jsx(Be,{layout:"bare",label:d("st.channels.listenToggle",{name:j}),checked:t.listening,disabled:h.saving,onChange:L})}):void 0,children:[e.jsx("h3",{className:"sr-only",children:j}),e.jsx(yO,{account:t,state:g,qqPlugin:A,busy:h.saving,onRetry:()=>{h.run(()=>b(t.id))},onReauthorize:()=>{y(!0)}}),e.jsx(pe,{feedback:h.error===void 0?null:{tone:"error",text:h.error}}),v&&!A?e.jsx("div",{className:"rounded-lg border border-hairline bg-panel p-4","data-im-connect-drawer":!0,"data-im-instance":t.id,children:e.jsx(kO,{account:t,setupPlatform:a,onDone:()=>{y(!1)}})}):null,g==="auth_expired"&&m.length===0&&f.length===0?null:e.jsxs("section",{className:"space-y-3","data-im-conversations":t.id,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:d("st.channels.conversations")}),t.listening?e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink","data-im-refresh-discovery":!0,onClick:$,children:d("st.im.refreshDiscovery")}):null]}),f.length>0?e.jsx("div",{className:"space-y-2.5","data-im-discoveries":t.id,children:f.map(H=>e.jsx(fO,{discovery:H,snapshot:s,catalog:n,setupPlatform:a,initialTarget:r??i,inbound:t.inbound!==!1},H.id))}):null,m.length>0?e.jsx("div",{"data-im-bindings-list":!0,className:"divide-y divide-hairline rounded-lg border border-hairline bg-panel px-3",children:m.map(H=>e.jsx(hO,{binding:H,snapshot:s,policy:s.policy,catalog:n,setupPlatform:a,inbound:t.inbound!==!1,expanded:S===H.id,onToggle:()=>{k(U=>U===H.id?null:H.id)}},H.id))}):null,g==="auth_expired"?null:e.jsxs("div",{"data-im-bind-flow":t.id,className:"space-y-3 rounded-lg border border-dashed border-hairline-strong px-3.5 py-3",children:[e.jsx("p",{className:"text-[12.5px] leading-5 text-ink-soft","data-im-awaiting-discovery":!0,children:d(t.listening?t.provider_kind==="wechat_bridge"?"st.channels.addConversation.wechat":"st.channels.addConversation":"st.channels.addConversation.paused")}),!t.listening&&R?e.jsx("button",{type:"button","data-im-bind-listen":!0,className:Ye,disabled:h.saving,onClick:()=>{L(!0)},children:d("st.im.startListenNow")}):null,t.listening&&f.length===0&&m.length===0&&n!==void 0?e.jsxs("div",{className:"max-w-md space-y-1.5","data-im-preselect-flow":t.id,children:[e.jsx("span",{className:$e,children:d("st.channels.preselect")}),e.jsx(vk,{id:`im-preselect-${t.id}`,value:E,onChange:o,catalog:n,disabled:h.saving,attrPrefix:"data-im-preselect"})]}):null]})]}),e.jsx(et,{summary:d("st.section.advanced"),"data-im-account-advanced":t.id,children:e.jsxs("div",{className:"space-y-3","data-im-account-settings":t.id,children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"min-w-0 break-all font-mono text-[12px] text-ink-soft","data-im-adapter":t.adapter,title:t.account_id??t.id,children:At(t.account_id??t.id)}),e.jsx("button",{type:"button","data-im-copy-account":!0,className:"rounded px-1.5 py-0.5 text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{rs(t.account_id??t.id)},children:d("st.channels.copy")})]}),A?e.jsx(_t,{to:An("kiki-qq"),className:"text-selected-ink hover:underline","data-im-plugin-settings":"kiki-qq",children:d("st.im.configureAccount")}):g==="auth_expired"&&!v?null:e.jsx("button",{type:"button",className:"text-selected-ink hover:underline","data-im-reauthorize":t.id,"aria-expanded":v,onClick:()=>{y(H=>!H)},children:d(v?"st.im.closeBindFlow":"st.im.reauthorize")})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-im-remove-account":t.id,className:Ht,disabled:h.saving,onClick:()=>{N(!0)},children:d("st.im.remove")})}),e.jsx(Xe,{open:w,title:d("st.im.removeAccountTitle",{name:j}),body:d("st.im.removeAccountBody"),consequences:m.length===0?void 0:[d("st.im.removeAccountBindings",{count:m.length})],confirmLabel:d("st.im.remove"),cancelLabel:d("common.cancel"),tone:"danger",busy:_,overlayId:`im-account-remove-${P}`,onConfirm:()=>void I(),onCancel:()=>{N(!1)}})]})}function yO({account:t,state:s,qqPlugin:n,busy:a,onRetry:i,onReauthorize:r}){const{t:o}=D();if(s==="auth_expired")return e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[13px] leading-5","data-im-problems":t.id,children:[e.jsx("p",{className:"min-w-0 flex-1 text-amber-ink","data-im-connection-detail":!0,children:o("st.im.authExpiredHint")}),n?e.jsx(_t,{to:An("kiki-qq"),className:Q,"data-im-reauthorize-now":t.id,children:o("st.im.reauthorize")}):e.jsx("button",{type:"button",className:Q,"data-im-reauthorize-now":t.id,onClick:r,children:o("st.im.reauthorize")}),(t.inbound_diagnostics?.length??0)>0?e.jsx("div",{className:"basis-full",children:e.jsx(sf,{diagnostics:t.inbound_diagnostics})}):null]});const l=[t.connection_detail!==void 0?e.jsx(jO,{detail:t.connection_detail},"detail"):null,(t.inbound_diagnostics?.length??0)>0?e.jsx(sf,{diagnostics:t.inbound_diagnostics},"inbound"):null,t.conflict==="webhook"?e.jsx("p",{"data-im-webhook":!0,className:"text-amber-ink",children:o("st.im.webhook")},"webhook"):null,t.adapter==="missing"?e.jsx("p",{"data-im-missing":!0,className:"text-ink-soft",children:o("st.im.missing")},"missing"):null].filter(Boolean),c=s==="stopped"&&t.listening?e.jsx("button",{type:"button",className:Ye,"data-im-retry-connection":t.id,disabled:a||t.adapter==="missing",onClick:i,children:o("st.im.retryConnection")}):null;return l.length===0&&c===null?null:e.jsxs("div",{className:"space-y-2 rounded-lg bg-amber-card/60 px-3.5 py-3 text-[13px] leading-5","data-im-problems":t.id,children:[l,c]})}function kO({account:t,setupPlatform:s,onDone:n}){const a=Fn(),i=qi(),[r,o]=x.useState(),l=Oe(),c=u=>{u!==void 0&&a.run(async()=>{const p=await i(u);return n(),p})},d=ck(c);return t.provider_kind==="wechat_bridge"?e.jsxs(e.Fragment,{children:[e.jsx(uk,{qr:d}),e.jsx(pe,{feedback:a.error===void 0?null:{tone:"error",text:a.error}})]}):OM(t.provider_kind)&&s!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(dk,{platform:s,instanceId:t.id,savedInstanceId:r,busy:a.saving,onSaved:async u=>{o(u.provider_instance_id),await l.invalidateQueries({queryKey:$t})},onCheckAndListen:c}),e.jsx(pe,{feedback:a.error===void 0?null:{tone:"error",text:a.error}})]}):e.jsx(pk,{kind:"raw",instanceId:t.id,onConnected:()=>{n()}})}function sf({diagnostics:t}){const{t:s}=D();return e.jsxs("details",{"data-im-inbound-diagnostics":!0,className:"text-amber-ink",children:[e.jsx("summary",{className:"w-fit cursor-pointer rounded focus-visible:outline-2 focus-visible:outline-selected-ink",children:s("st.im.inboundFailureCount",{count:t.length})}),e.jsx("ul",{className:"mt-1 max-h-64 space-y-2 overflow-y-auto pl-4",children:t.map(n=>e.jsxs("li",{"data-im-inbound-code":n.code,children:[e.jsx("p",{children:s(`st.im.inboundFailure.${n.code}`)}),e.jsxs("p",{className:"break-all font-mono text-[11px] text-ink-soft",children:[e.jsx("span",{title:n.source_id,children:At(n.source_id)})," · ",e.jsx("time",{dateTime:n.at,children:new Date(n.at).toLocaleString()})]})]},`${n.source_id}:${n.code}`))})]})}function jO({detail:t}){const{t:s}=D(),n=[t.http_status===void 0?void 0:`HTTP ${t.http_status}`,t.ret===void 0?void 0:`ret ${t.ret}`,t.errcode===void 0?void 0:`errcode ${t.errcode}`].filter(Boolean);return n.length===0&&t.failure_count===void 0&&t.retry_in_ms===void 0?e.jsx("p",{"data-im-connection-detail":!0,className:"text-amber-ink",children:s(`st.im.failure.${t.code}`)}):e.jsxs("details",{"data-im-connection-detail":!0,className:"text-amber-ink",children:[e.jsx("summary",{className:"w-fit cursor-pointer rounded focus-visible:outline-2 focus-visible:outline-selected-ink",children:s(`st.im.failure.${t.code}`)}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-1 pl-4 font-mono text-[12px] text-ink-soft",children:[n.length>0?e.jsx("span",{children:n.join(" · ")}):null,t.failure_count!==void 0?e.jsx("span",{children:s("st.im.failureCount",{count:t.failure_count})}):null,t.retry_in_ms!==void 0?e.jsx("span",{children:s("st.im.retryDelay",{seconds:Math.ceil(t.retry_in_ms/1e3)})}):null]})]})}function wO(t){return t===void 0||Object.keys(t).length===0?"":JSON.stringify(t)}function NO({policy:t}){const{t:s}=D(),{client:n,scopeId:a}=be(),i=Oe(),r=Fn(),[o,l]=x.useState(null),[c,d]=x.useState(null),u=je({queryKey:["config",a],queryFn:()=>n.getConfig(),staleTime:3e4}),p=rS(n),h=I=>{r.run(()=>n.imSessions.patchPolicy(I))},m=(Dd().data?.plugins??[]).flatMap(I=>(I.asrProviders??[]).map($=>({id:`${I.id}/${$.id}`,label:$.label,description:$.description,connectionSetting:$.connectionSetting}))),f=u.data?.send_message,g=f?.voiceMode??"none",v=t.asr_mode??"auto",y=t.asr_provider??"",w=f?.ttsProvider??"",N=f?.ttsVoice??"",_=f?.ttsModel??"",C=f?.ttsLanguage??"",S=f?.ttsFormat??"",k=f?.ttsSampleRateHz!==void 0?String(f.ttsSampleRateHz):"",j=wO(f?.ttsOptions),T=r.saving||u.isLoading,A=(p.data??[]).filter(I=>!I.removed).flatMap(I=>I.definitions.filter($=>$.kinds.includes("tts")).map($=>({id:`${I.pluginId}/${$.id}`,label:`${I.label} (${I.pluginId}/${$.id})`,shortLabel:I.label}))),P=I=>{r.run(async()=>{const $=await n.patchConfig({send_message:I});i.setQueryData(["config",a],$),await i.invalidateQueries({queryKey:["config"]})})},R=[{value:"none",label:s("st.im.tts.mode.none")},{value:"append",label:s("st.im.tts.mode.append")},{value:"only",label:s("st.im.tts.mode.only")}],L=C.length>0||S.length>0||k.length>0||j.length>0;return e.jsxs("details",{className:"group rounded-lg","data-im-rules":!0,children:[e.jsxs("summary",{className:"flex min-h-10 w-fit cursor-pointer list-none items-center gap-1.5 rounded-md px-1 text-[12.5px] text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open:rotate-90"}),s("st.channels.rules"),t.allowed?null:e.jsxs("span",{className:"text-amber-ink",children:["· ",s("st.channels.twoWayOff")]})]}),e.jsxs("div",{className:"mt-2 space-y-1 rounded-lg border border-hairline bg-panel px-4 py-3",children:[e.jsx(ge,{label:s("st.im.allowed"),htmlFor:"im-allowed",children:e.jsx(Be,{id:"im-allowed",layout:"bare",label:s("st.im.allowed"),checked:t.allowed,disabled:r.saving,onChange:I=>{h({allowed:I})}})}),e.jsx(ge,{label:s("st.im.default"),htmlFor:"im-default",children:e.jsx(Be,{id:"im-default",layout:"bare",label:s("st.im.default"),checked:t.default_enabled,disabled:r.saving,onChange:I=>{h({default_enabled:I})}})}),e.jsx(ge,{label:s("st.im.allowBorrowing"),htmlFor:"im-allow-borrowing",children:e.jsx(Be,{id:"im-allow-borrowing",layout:"bare",label:s("st.im.allowBorrowing"),checked:t.allow_channel_borrowing??!1,disabled:r.saving,onChange:I=>{h({allow_channel_borrowing:I})}})}),e.jsx(ge,{label:s("st.im.defaultSendMessage"),htmlFor:"im-default-send-message",children:e.jsx(Be,{id:"im-default-send-message",layout:"bare",label:s("st.im.defaultSendMessage"),checked:u.data?.optional_capabilities?.send_message?.default_on??!1,disabled:T,onChange:I=>{r.run(async()=>{const $=await n.patchConfig({optional_capabilities:{defaults:{send_message:I}}});i.setQueryData(["config",a],$),await i.invalidateQueries({queryKey:["config"]})})}})}),e.jsxs("div",{className:"space-y-2 border-t border-hairline pt-2","data-im-media-rules":!0,children:[e.jsx(ge,{label:s("st.im.coalesce.window"),labelId:"im-coalesce-window-label",help:s("st.im.coalesce.globalHint"),children:e.jsx(hk,{ariaLabel:s("st.im.coalesce.window"),value:t.coalesce_window_ms,allowDefault:!1,disabled:r.saving,dataAttr:"data-im-coalesce-global",onChange:I=>{h({coalesce_window_ms:I??0})}})}),e.jsx(ge,{label:s("st.im.asr.mode"),labelId:"im-asr-mode-label",help:s("st.im.asr.modeHint"),children:e.jsx(He,{ariaLabel:s("st.im.asr.mode"),value:v,disabled:r.saving,dataAttr:"data-im-asr-mode",choices:[{value:"auto",label:s("st.im.asr.mode.auto")},{value:"off",label:s("st.im.asr.mode.wavOnly")}],onChange:I=>{h({asr_mode:I})}})}),e.jsx(ge,{label:s("st.im.asr.provider"),htmlFor:"im-asr-provider",children:e.jsxs("div",{className:"flex w-full flex-col items-start gap-1.5 sm:w-auto sm:items-end",children:[e.jsx("input",{id:"im-asr-provider",type:"text",list:m.length>0?"im-asr-provider-options":void 0,defaultValue:y,placeholder:s("st.im.asr.providerPlaceholder"),disabled:r.saving,"data-im-asr-provider":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==y&&h({asr_provider:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`asr-provider:${y}`),m.length>0?e.jsxs(e.Fragment,{children:[e.jsx("datalist",{id:"im-asr-provider-options",children:m.map(I=>e.jsx("option",{value:I.id,children:I.label},I.id))}),e.jsxs("div",{className:"flex flex-wrap justify-start gap-1 sm:justify-end","data-im-asr-provider-suggestions":!0,children:[e.jsx("button",{type:"button",disabled:r.saving,"data-im-asr-provider-option":"","aria-pressed":y==="",onClick:()=>{y!==""&&h({asr_provider:null})},className:`rounded-md border px-2 py-0.5 text-[11px] transition-colors ${y===""?"border-selected-border bg-selected text-selected-ink font-medium":"border-hairline bg-paper text-ink-soft hover:bg-panel hover:text-ink"}`,children:s("st.im.asr.providerDefault")}),m.map(I=>{const $=y===I.id,E=I.connectionSetting===void 0?void 0:s("st.im.asr.connectionSetting",{setting:I.connectionSetting}),M=I.description===void 0?E:E===void 0?I.description:`${I.description}
|
|
250
|
+
${E}`;return e.jsx("button",{type:"button",disabled:r.saving,"data-im-asr-provider-option":I.id,"aria-pressed":$,title:M,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] transition-colors ${$?"border-selected-border bg-selected text-selected-ink font-medium":"border-hairline bg-paper text-ink-soft hover:bg-panel hover:text-ink"}`,onClick:()=>{$||h({asr_provider:I.id})},children:I.label},I.id)})]})]}):null]})})]}),e.jsxs("div",{className:"space-y-1 border-t border-hairline pt-2","data-im-tts-rules":!0,children:[e.jsx(ge,{label:s("st.im.tts.mode"),labelId:"im-tts-mode-label",help:s("st.im.tts.modeHint"),children:e.jsx(He,{ariaLabel:s("st.im.tts.mode"),value:g,disabled:T,dataAttr:"data-im-tts-mode",choices:R,onChange:I=>{P({voice_mode:I})}})}),e.jsx(ge,{label:s("st.im.tts.provider"),htmlFor:"im-tts-provider",children:e.jsxs("div",{className:"flex w-full flex-col items-start gap-1.5 sm:w-auto sm:items-end",children:[e.jsx("input",{id:"im-tts-provider",type:"text",list:A.length>0?"im-tts-provider-options":void 0,defaultValue:w,placeholder:s("st.im.tts.providerPlaceholder"),disabled:T,"data-im-tts-provider":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==w&&P({tts_provider:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`provider:${w}`),A.length>0?e.jsxs(e.Fragment,{children:[e.jsx("datalist",{id:"im-tts-provider-options",children:A.map(I=>e.jsx("option",{value:I.id,children:I.label},I.id))}),e.jsxs("div",{className:"flex flex-wrap justify-start gap-1 sm:justify-end","data-im-tts-provider-suggestions":!0,children:[e.jsx("button",{type:"button",disabled:T,"data-im-tts-provider-option":"","aria-pressed":w==="",onClick:()=>{w!==""&&P({tts_provider:null})},className:`rounded-md border px-2 py-0.5 text-[11px] transition-colors ${w===""?"border-selected-border bg-selected text-selected-ink font-medium":"border-hairline bg-paper text-ink-soft hover:bg-panel hover:text-ink"}`,children:s("st.im.tts.providerDefault")}),A.map(I=>{const $=w===I.id;return e.jsx("button",{type:"button",disabled:T,"data-im-tts-provider-option":I.id,"aria-pressed":$,onClick:()=>{$||P({tts_provider:I.id})},className:`rounded-md border px-2 py-0.5 font-mono text-[11px] transition-colors ${$?"border-selected-border bg-selected text-selected-ink font-medium":"border-hairline bg-paper text-ink-soft hover:bg-panel hover:text-ink"}`,children:I.shortLabel},I.id)})]})]}):null]})}),e.jsx(ge,{label:s("st.im.tts.voice"),htmlFor:"im-tts-voice",children:e.jsx("input",{id:"im-tts-voice",type:"text",defaultValue:N,placeholder:s("st.im.tts.voicePlaceholder"),disabled:T,"data-im-tts-voice":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==N&&P({tts_voice:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`voice:${N}`)}),e.jsx(ge,{label:s("st.im.tts.model"),htmlFor:"im-tts-model",children:e.jsx("input",{id:"im-tts-model",type:"text",defaultValue:_,placeholder:s("st.im.tts.modelPlaceholder"),disabled:T,"data-im-tts-model":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==_&&P({tts_model:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`model:${_}`)}),e.jsxs("details",{className:"group/more pt-1","data-im-tts-more":!0,open:L||void 0,children:[e.jsxs("summary",{className:"flex min-h-8 w-fit cursor-pointer list-none items-center gap-1.5 rounded-md px-1 text-[12px] text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink [&::-webkit-details-marker]:hidden",children:[e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open/more:rotate-90"}),s("st.im.tts.more")]}),e.jsxs("div",{className:"mt-1 space-y-1 border-l border-hairline pl-3",children:[e.jsx(ge,{label:s("st.im.tts.language"),htmlFor:"im-tts-language",children:e.jsx("input",{id:"im-tts-language",type:"text",defaultValue:C,placeholder:s("st.im.tts.languagePlaceholder"),disabled:T,"data-im-tts-language":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==C&&P({tts_language:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`language:${C}`)}),e.jsx(ge,{label:s("st.im.tts.format"),htmlFor:"im-tts-format",children:e.jsx("input",{id:"im-tts-format",type:"text",defaultValue:S,placeholder:s("st.im.tts.formatPlaceholder"),disabled:T,"data-im-tts-format":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();$!==S&&P({tts_format:$===""?null:$})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`format:${S}`)}),e.jsx(ge,{label:s("st.im.tts.sampleRate"),htmlFor:"im-tts-sample-rate",children:e.jsx("input",{id:"im-tts-sample-rate",type:"text",inputMode:"numeric",defaultValue:k,placeholder:s("st.im.tts.sampleRatePlaceholder"),disabled:T,"data-im-tts-sample-rate":!0,className:`w-full sm:w-64 ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();if($===""){l(null),k!==""&&P({tts_sample_rate_hz:null});return}const E=Number($);if(!Number.isInteger(E)||E<=0){l(s("st.im.tts.sampleRateInvalid"));return}l(null),String(E)!==k&&P({tts_sample_rate_hz:E})},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`sampleRate:${k}`)}),e.jsx(ge,{label:s("st.im.tts.options"),htmlFor:"im-tts-options",children:e.jsx("input",{id:"im-tts-options",type:"text",defaultValue:j,placeholder:s("st.im.tts.optionsPlaceholder"),disabled:T,"data-im-tts-options":!0,className:`w-full sm:w-64 font-mono ${Gt}`,onBlur:I=>{const $=I.currentTarget.value.trim();if($===""){d(null),j!==""&&P({tts_options:null});return}try{const E=JSON.parse($);if(typeof E!="object"||E===null||Array.isArray(E)){d(s("st.im.tts.optionsInvalid"));return}d(null),JSON.stringify(E)!==j&&P({tts_options:E})}catch{d(s("st.im.tts.optionsInvalid"))}},onKeyDown:I=>{rt(I)||I.key==="Enter"&&I.currentTarget.blur()}},`options:${j}`)}),o!==null?e.jsx(pe,{feedback:{tone:"error",text:o}}):null,c!==null?e.jsx(pe,{feedback:{tone:"error",text:c}}):null]})]})]}),e.jsx(pe,{feedback:r.error===void 0?null:{tone:"error",text:r.error}})]})]})}const kk=new Set(["dependency","unauthorized","connection","noCredential"]),SO=6;function CO(t,s,n){return t.provider_kind!=="telegram"||t.listening||n===void 0||s.bindings.some(a=>a.provider_instance_id===t.id)||s.discoveries.some(a=>a.provider_instance_id===t.id)?!1:Object.values(n.channels).some(a=>a.provider_instance_id===t.id)}function _O({adding:t,setAdding:s}){const{t:n,locale:a}=D(),{client:i}=be(),r=Oe(),o=x.useContext(Mn),{snapshot:l,catalog:c,setupCatalog:d}=zM(),{settings:u,providers:p,deliveries:h}=sk(),b=qi(),[m,f]=x.useState(null),[g,v]=x.useState({}),[y,w]=x.useState(),N=x.useMemo(HM,[]),_=l.data,C=u.data,S=x.useMemo(()=>p.data??[],[p.data]);x.useEffect(()=>{o?.("st-card-im-session")},[o]);const k=x.useCallback(H=>{s(!1),H!==void 0&&(f(`im:${H}`),(async()=>{try{const U=await i.imSessions.snapshot();r.setQueryData($t,U);const X=U.instances.find(q=>q.id===H&&q.provider_kind==="wechat_bridge");if(X===void 0||Qu(X)==="listening")return;r.setQueryData($t,await b(X.id))}catch(U){w(U instanceof Error&&U.message!==""?U.message:n("st.im.error"))}})())},[i,r,s,b,n]),j=ck(k),T=x.useMemo(()=>{const H=new Map;for(const U of h.data??[])H.set(U.channel_id,[...H.get(U.channel_id)??[],U]);return H},[h.data]),A=x.useCallback(H=>S.find(U=>U.id===C?.provider_instances[H.provider_instance_id]?.provider_id),[S,C]),P=x.useMemo(()=>{const H=[];if(_!==void 0){const U=[..._.instances];for(const X of[..._.bindings,..._.discoveries])U.some(q=>q.id===X.provider_instance_id)||U.push({id:X.provider_instance_id,provider_kind:X.provider_kind,account_id:X.account_id,configured:!1,listening:!1,adapter:"missing"});for(const X of U){if(CO(X,_,C))continue;const q=_.discoveries.filter(F=>F.provider_instance_id===X.id).length;H.push({kind:"im",key:`im:${X.id}`,account:X,name:ik(X,n),rank:to.indexOf(Hu(X.provider_kind)),attention:rk(X,q)})}}if(C!==void 0)for(const[U,X]of Xy(C)){const q=C.provider_instances[X.provider_instance_id],F=Uu(X,q,A(X),C.credential_slots);H.push({kind:"push",key:`push:${U}`,id:U,channel:X,name:X.label??q?.label??Fo(n,q?.provider_id??""),rank:to.indexOf(zu(q?.provider_id??"")),attention:kk.has(F)})}return H.toSorted((U,X)=>(U.kind===X.kind?0:U.kind==="im"?-1:1)||U.rank-X.rank||U.name.localeCompare(X.name))},[_,C,A,n]),R=x.useCallback(H=>H.key,[]),L=x.useCallback(H=>[H.name,H.kind==="im"?H.account.account_id:A(H.channel)?.id],[A]),I=x.useMemo(()=>[{id:"two-way",label:n("st.channels.cap.twoWay"),test:H=>H.kind==="im"},{id:"alerts",label:n("st.channels.cap.alerts"),test:H=>H.kind==="push"},{id:"attention",label:n("st.notify.filter.attention"),tone:"attention",test:H=>H.attention}],[n]),$=Qs({listId:"notify-channels",items:P,keyOf:R,textOf:L,filters:I}),E=_===void 0&&!l.isError&&C===void 0&&!u.isError,M=u.isError||p.isError,z=e.jsxs("button",{type:"button","data-notify-add-open":!0,"data-im-connect-toggle":!0,className:`${Ye} inline-flex items-center gap-1.5`,"aria-expanded":t,onClick:()=>{s(!0)},children:[e.jsx(de,{name:"plus",size:12}),n("st.channels.add")]});return e.jsxs(Me,{id:"st-card-notify-channels",title:n("st.channels.title"),actions:P.length>0?z:void 0,children:[e.jsxs("div",{id:"st-card-im-session",className:"min-w-0 space-y-4 scroll-mt-4","data-im-session":!0,children:[l.isError?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(pe,{feedback:{tone:"error",text:n("st.im.loadError")}}),e.jsx("button",{type:"button",className:Q,"data-im-retry":!0,onClick:()=>{l.refetch()},children:n("st.im.retry")})]}):null,M?e.jsx(pe,{feedback:{tone:"error",text:n("st.notify.loadFailed",{detail:oe(a,u.error??p.error)})}}):null,c.isError?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-im-catalog-error":!0,children:[e.jsx(pe,{feedback:{tone:"error",text:n("st.im.catalogError")}}),e.jsx("button",{type:"button",className:Q,onClick:()=>{c.refetch()},children:n("st.im.retry")})]}):null,y!==void 0?e.jsx(pe,{feedback:{tone:"error",text:y}}):null,C!==void 0&&!C.global.enabled&&P.some(H=>H.kind==="push")?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-amber-ink","data-notify-paused-banner":!0,children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-amber-rule"}),n("st.channels.alertsPaused")]}):null,E?e.jsx("div",{"data-im-loading":!0,"data-notify-loading":!0,"aria-busy":"true",className:"min-h-40"}):P.length===0?l.isError?null:e.jsx("div",{"data-notify-empty":!0,"data-im-empty":!0,children:e.jsx(Ct,{kind:"none",title:n("st.channels.emptyTitle"),body:n("st.channels.emptyBody"),action:z})}):e.jsxs(e.Fragment,{children:[P.length>SO?e.jsx(Gs,{view:$,total:P.length,filters:I,showDensity:!1,searchLabel:n("st.notify.search"),searchPlaceholder:n("st.notify.searchPlaceholder")}):null,$.visible.length===0?e.jsx(Ct,{kind:"no-match",title:n("st.notify.noMatchTitle"),body:$.query.trim()!==""?n("st.notify.noMatches",{query:$.query.trim()}):void 0,onClear:$.clear}):e.jsx("div",{"data-notify-channels":!0,"data-im-accounts":!0,children:e.jsx(Hs,{items:$.visible,keyOf:R,density:"comfortable",label:n("st.channels.title"),renderRow:H=>H.kind==="im"&&_!==void 0?e.jsx(vO,{account:H.account,data:_,catalog:c.data,setupPlatform:d.data?.platforms.find(U=>U.provider_kind===H.account.provider_kind),initialTarget:N,preselectedTarget:g[H.account.id],onPreselectTarget:U=>{v(X=>({...X,[H.account.id]:U}))},open:m===H.key,onToggle:()=>{f(U=>U===H.key?null:H.key)}}):H.kind==="push"&&C!==void 0?e.jsx(uO,{channelId:H.id,channel:H.channel,settings:C,provider:A(H.channel),deliveries:T.get(H.id)??[],open:m===H.key,onToggle:()=>{f(U=>U===H.key?null:H.key)}}):null})})]}),_!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx(NO,{policy:_.policy}),_.strangers.length>0||_.voice_fallbacks>0?e.jsxs("p",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-ink-faint",children:[_.strangers.length>0?e.jsxs("span",{"data-im-strangers":!0,children:[n("st.im.strangers"),": ",_.strangers.reduce((H,U)=>H+U.count,0)]}):null,_.voice_fallbacks>0?e.jsxs("span",{"data-im-voice":!0,children:[n("st.im.voice"),": ",_.voice_fallbacks]}):null]}):null]}):null]}),t?e.jsx(tO,{settings:C,providers:S,setupCatalog:d.data,setupFailed:d.isError,onRetrySetup:()=>{d.refetch()},qr:j,onClose:()=>{s(!1)},onAdded:H=>{s(!1),f(H),r.invalidateQueries({queryKey:$t})}}):null]})}const nf=/^([01][0-9]|2[0-3]):[0-5][0-9]$/u,EO={start:"22:00",end:"08:00"};function hd(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function TO(t){const s=typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):[];return[...new Set([t,hd(),"UTC",...s])]}function IO({global:t,part:s="all"}){const{t:n}=D(),a=mt(),{api:i,apply:r}=Fi(),o=bt(),[l,c]=x.useState(null),[d,u]=x.useState(()=>ss().closeToTray),p=a.kind==="tauri";x.useEffect(()=>{a.kind==="tauri"&&a.readDesktopPrefs().then(v=>{v!==null&&u(v.closeToTray)})},[a]);const h=(v,y)=>{c(v),o.run(async()=>{r(await i.updateSettings(y))})},b=v=>l===v?e.jsx(ot,{saving:o.saving,saved:o.saved}):null,m=t.quiet_hours,f=m?.time_zone??hd(),g=p?d?"st.notify.runtime.tray":"st.notify.runtime.quit":"st.notify.runtime.browser";return s==="master"?e.jsxs("div",{className:"min-w-0 space-y-1.5 border-b border-hairline pb-4","data-notify-master":!0,children:[e.jsxs(ge,{label:n("st.notify.enabled"),htmlFor:"notify-enabled",help:n("st.notify.enabledHint"),children:[b("enabled"),e.jsx(Be,{id:"notify-enabled",layout:"bare",label:n("st.notify.enabled"),checked:t.enabled,disabled:o.saving,onChange:v=>{h("enabled",{...t,enabled:v})}})]}),t.enabled?null:e.jsx("p",{className:"text-[12px] text-ink-soft","data-notify-paused-banner":!0,children:n("st.notify.paused")}),e.jsx(pe,{feedback:o.error})]}):e.jsx(Me,{id:"st-card-notify-rules",title:n("st.notify.rulesTitle"),children:e.jsxs("div",{className:"min-w-0 space-y-3","data-notify-rules":!0,children:[e.jsxs(Ze,{children:[s==="all"?e.jsxs(ge,{label:n("st.notify.enabled"),htmlFor:"notify-enabled",help:n("st.notify.enabledHint"),children:[b("enabled"),e.jsx(Be,{id:"notify-enabled",layout:"bare",label:n("st.notify.enabled"),checked:t.enabled,disabled:o.saving,onChange:v=>{h("enabled",{...t,enabled:v})}})]}):null,t.enabled?e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ge,{label:n("st.notify.quiet"),htmlFor:"notify-quiet",help:n("st.notify.quietHint"),children:[b("quiet"),e.jsx(Be,{id:"notify-quiet",layout:"bare",label:n("st.notify.quiet"),checked:m!==void 0,disabled:o.saving,onChange:v=>{const{quiet_hours:y,...w}=t;h("quiet",v?{...w,quiet_hours:{...EO,time_zone:hd()}}:w)}})]}),m!==void 0?e.jsxs("div",{className:"flex flex-wrap items-start gap-x-4 gap-y-2 pb-1 pl-3","data-notify-quiet":!0,children:[e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-soft",children:[n("st.notify.quietFrom"),e.jsx(kt,{dataAttr:"data-notify-quiet-start",className:"w-[4.5rem] text-center",inputMode:"numeric",value:m.start,ariaLabel:`${n("st.notify.quiet")} ${n("st.notify.quietFrom")}`,disabled:o.saving,validate:v=>nf.test(v)?null:n("st.notify.timeInvalid"),onCommit:v=>{h("quiet-range",{...t,quiet_hours:{...m,start:v}})}})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-soft",children:[n("st.notify.quietTo"),e.jsx(kt,{dataAttr:"data-notify-quiet-end",className:"w-[4.5rem] text-center",inputMode:"numeric",value:m.end,ariaLabel:`${n("st.notify.quiet")} ${n("st.notify.quietTo")}`,disabled:o.saving,validate:v=>nf.test(v)?null:n("st.notify.timeInvalid"),onCommit:v=>{h("quiet-range",{...t,quiet_hours:{...m,end:v}})}})]}),e.jsxs("span",{className:"flex items-center gap-2 text-[12px] text-ink-soft",children:[n("st.notify.quietZone"),e.jsx(Qe,{id:"notify-quiet-zone",ariaLabel:n("st.notify.quietZone"),value:f,mono:!0,disabled:o.saving,choices:TO(f).map(v=>({value:v,label:v})),onChange:v=>{h("quiet-range",{...t,quiet_hours:{...m,time_zone:v}})}})]}),b("quiet-range")]}):null]}):null,t.enabled?e.jsxs(ge,{label:n("st.notify.viewing"),htmlFor:"notify-viewing",help:n("st.notify.viewingHint"),children:[b("viewing"),e.jsx(Be,{id:"notify-viewing",layout:"bare",label:n("st.notify.viewing"),checked:t.suppress_viewing_session,disabled:o.saving,onChange:v=>{h("viewing",{...t,suppress_viewing_session:v})}})]}):null,t.enabled?e.jsxs(ge,{label:n("st.notify.minWork"),htmlFor:"notify-min-work",help:n("st.notify.minWorkHint"),children:[b("minWork"),e.jsx(kt,{id:"notify-min-work",dataAttr:"data-notify-min-work",className:"w-20 text-right",inputMode:"numeric",value:String(Math.round(t.min_work_ms/1e3)),disabled:o.saving,validate:v=>/^\d+$/u.test(v)&&Number(v)<=86400?null:n("st.notify.minWorkInvalid"),onCommit:v=>{h("minWork",{...t,min_work_ms:Number(v)*1e3})}}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:n("st.notify.seconds")})]}):null]}),s==="all"?e.jsx(pe,{feedback:o.error}):null,e.jsxs("dl",{className:"grid gap-x-6 gap-y-2 pt-2 sm:grid-cols-[8rem_minmax(0,1fr)]","data-notify-facts":!0,children:[e.jsx("dt",{className:"text-[12px] text-ink-soft",children:n("st.notify.privacyLabel")}),e.jsx("dd",{children:e.jsx(he,{children:n("st.notify.privacy")})}),e.jsx("dt",{className:"text-[12px] text-ink-soft",children:n("st.notify.runtimeLabel")}),e.jsx("dd",{"data-notify-runtime":p?d?"tray":"quit":"browser",children:e.jsx(he,{children:n(g)})})]})]})})}const af=["work_complete","question_pending"];function PO({settings:t}){const{t:s}=D(),{api:n,apply:a}=Fi(),i=bt(),[r,o]=x.useState(null),l=Xy(t),c=u=>{const p=t.provider_instances[u.provider_instance_id];return u.label??p?.label??Fo(s,p?.provider_id??"")},d=(u,p,h,b)=>{o(`${u}.${h}`);const{health:m,...f}=p;i.run(async()=>{a(await n.upsertChannel(u,{...f,scenes:{...p.scenes,[h]:b}}))})};return e.jsx(Me,{id:"st-card-notify-scenes",title:s("st.notify.matrixTitle"),children:l.length===0?e.jsx("p",{className:"text-[13px] text-ink-soft","data-notify-matrix-empty":!0,children:s("st.notify.matrixEmpty")}):e.jsxs("div",{className:`min-w-0 ${t.global.enabled?"":"opacity-60"}`,children:[e.jsxs("table",{className:"w-full table-fixed border-collapse text-[13px]","data-notify-matrix":!0,children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-hairline text-left text-[12px] text-ink-soft",children:[e.jsx("th",{scope:"col",className:"py-2 pr-3 font-normal",children:s("st.notify.matrixChannel")}),af.map(u=>e.jsx("th",{scope:"col",className:"w-[30%] px-2 py-2 text-center font-normal leading-4 max-sm:w-[34%]",children:s(`st.notify.scene.${u}`)},u))]})}),e.jsx("tbody",{children:l.map(([u,p])=>e.jsxs("tr",{"data-notify-matrix-row":u,className:"border-b border-hairline last:border-b-0",children:[e.jsx("th",{scope:"row",className:"py-1.5 pr-3 text-left font-normal",children:e.jsx("span",{className:`block truncate ${p.enabled?"text-ink":"text-ink-faint"}`,children:c(p)})}),af.map(h=>e.jsx("td",{className:"px-2 py-1.5 text-center",children:e.jsxs("label",{className:"inline-flex min-h-10 min-w-10 cursor-pointer items-center justify-center gap-1.5",children:[e.jsx("input",{type:"checkbox","data-notify-scene":h,"data-notify-scene-channel":u,className:"h-4 w-4 accent-[var(--color-selected-ink)]","aria-label":s("st.notify.matrixCell",{channel:c(p),scene:s(`st.notify.scene.${h}`)}),checked:p.scenes[h],disabled:i.saving,onChange:b=>{d(u,p,h,b.target.checked)}}),r===`${u}.${h}`?e.jsx(ot,{saving:i.saving,saved:i.saved}):null]})},h))]},u))})]}),e.jsx(pe,{feedback:i.error})]})})}const rf="st-card-notify-add",ys=["accounts","rules","device"],AO={im:"accounts",channels:"accounts",away:"device"};function jk(t){if(t!==null)return ys.find(s=>s===t)??AO[t]}const tn={"st-card-im-session":"accounts","st-card-notify-channels":"accounts","st-card-notify-add":"accounts","st-card-notify-rules":"rules","st-card-notify-scenes":"rules","st-card-notify-away":"device"};function $O(t,s,n){const a=s.replace(/^#/,"");return a!==""&&tn[a]!==void 0?tn[a]:n!==null&&tn[n]!==void 0?tn[n]:jk(new URLSearchParams(t).get("tab"))??"accounts"}function RO(t){switch(t){case"accounts":return"st.notify.tab.accounts";case"rules":return"st.notify.tab.rules";case"device":return"st.notify.tab.device"}}function LO(){const{t,locale:s}=D(),n=Hd(),a=n?.connectionId,i=typeof a=="string"&&a!==""||zs(n?.connectionSource),r=Oe(),{settings:o,providers:l}=sk(!i),{hash:c,search:d}=Bt(),u=x.useContext(Ia),p=c===`#${rf}`||u===rf,[h,b]=x.useState(p),[m,f]=x.useState(()=>$O(d,c,u)),g=x.useRef(null);x.useEffect(()=>{const P=c.replace(/^#/,"");if(P!==""&&tn[P]!==void 0){f(tn[P]);return}if(u!==null&&tn[u]!==void 0){f(tn[u]);return}const R=jk(new URLSearchParams(d).get("tab"));R!==void 0&&f(R)},[c,u,d]),x.useEffect(()=>{p&&b(!0)},[p]);const v=o.data,y=r.getQueryData($t),w=y!==void 0&&y.instances.some(P=>rk(P,y.discoveries.filter(R=>R.provider_instance_id===P.id).length)),N=v!==void 0&&!v.global.enabled,_=l.data??[],C=v!==void 0&&Object.values(v.channels).some(P=>kk.has(Uu(P,v.provider_instances[P.provider_instance_id],_.find(R=>R.id===v.provider_instances[P.provider_instance_id]?.provider_id),v.credential_slots))),S=(P,R)=>e.jsx("div",{id:`notify-panel-${P}`,role:"tabpanel","aria-labelledby":`notify-tab-${P}`,className:m===P?"space-y-5":"hidden",children:R}),k=P=>{g.current?.querySelectorAll('[role="tab"]')?.[P]?.focus()},j=(P,R)=>{if(P.key==="ArrowRight"){P.preventDefault();const L=(R+1)%ys.length;f(ys[L]),k(L)}else if(P.key==="ArrowLeft"){P.preventDefault();const L=(R-1+ys.length)%ys.length;f(ys[L]),k(L)}else if(P.key==="Home")P.preventDefault(),f(ys[0]),k(0);else if(P.key==="End"){P.preventDefault();const L=ys.length-1;f(ys[L]),k(L)}},T=e.jsx("div",{ref:g,role:"tablist","aria-label":t("st.section.notifications"),className:"flex flex-wrap items-center gap-1 border-b border-hairline pb-px text-[12.5px]",children:ys.map((P,R)=>{const L=P===m;return e.jsxs("button",{id:`notify-tab-${P}`,type:"button",role:"tab","aria-selected":L,"aria-controls":`notify-panel-${P}`,tabIndex:L?0:-1,"data-notify-tab":P,onClick:()=>{f(P)},onKeyDown:I=>{j(I,R)},className:`relative -mb-px flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-left transition-colors outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 ${L?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:border-hairline hover:text-ink"}`,children:[e.jsx("span",{children:t(RO(P))}),P==="accounts"&&(w||C)?e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-amber-ink","data-notify-tab-attention":"accounts"}):null,P==="rules"&&N?e.jsx("span",{className:"text-[11px] font-normal text-ink-faint","data-notify-tab-paused":!0,children:t("st.notify.pausedShort")}):null]},P)})}),A=o.isError||l.isError?e.jsx(pe,{feedback:{tone:"error",text:t("st.notify.loadFailed",{detail:oe(s,o.error??l.error)})}}):v===void 0||l.data===void 0?e.jsx("div",{"data-notify-loading":!0,"aria-busy":"true",className:"min-h-40"}):null;return i?e.jsx("div",{className:"space-y-5",children:e.jsx(Gh,{})}):e.jsxs("div",{className:"space-y-5",children:[T,S("accounts",e.jsx(_O,{adding:h,setAdding:b})),S("rules",A??(v===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx(IO,{global:v.global}),e.jsx(PO,{settings:v})]}))),S("device",e.jsx(Gh,{}))]})}function MO(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),[i,r]=x.useState(null),[o,l]=x.useState(!1),[c,d]=x.useState("profile"),[u,p]=x.useState(!1),[h,b]=x.useState(""),[m,f]=x.useState(!1),[g,v]=x.useState(null),[y,w]=Je(),N=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),_=je({queryKey:["tools"],queryFn:()=>t.listTools(),staleTime:6e4});x.useEffect(()=>{if(N.data!==void 0&&!o){const E=el(N.data);r(E),d(E.toolsEnabled.length>0?"allowlist":"profile")}},[N.data,o]);const C=x.useMemo(()=>[...new Set([..._.data?.tools.map(M=>M.name)??[],...i?.toolsEnabled??[],...i?.toolsDisabled??[],...i?.toolsRestored??[]])].toSorted((M,z)=>M.localeCompare(z)),[i?.toolsDisabled,i?.toolsEnabled,i?.toolsRestored,_.data?.tools]),S=c==="allowlist"&&i?.toolsEnabled.length===0,k=i!==null&&(i.toolsEnabled.length>0||i.toolsDisabled.length>0||(i.toolsRestored?.length??0)>0),j=i!==null&&c==="profile"&&!k&&!o&&!u,T=x.useMemo(()=>C.filter(E=>E.toLowerCase().includes(h.toLowerCase())),[h,C]),A=x.useMemo(()=>new Map((_.data?.tools??[]).map(E=>[E.name,E])),[_.data?.tools]),P=x.useMemo(()=>T.filter(E=>A.get(E)?.active!==!1),[A,T]),R=x.useMemo(()=>T.filter(E=>A.get(E)?.active===!1),[A,T]),L=E=>{r(E),l(!0),v(null)},I=async()=>{if(!(i===null||S)){f(!0),v(null);try{const E=await t.patchConfig(Qw(i));a.setQueryData(["config"],E),r(el(E)),l(!1),await a.invalidateQueries({queryKey:["tools"]}),w()}catch(E){v({tone:"error",text:oe(n,E)})}finally{f(!1)}}},$=E=>{const M=A.get(E);return e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-2 border-b border-hairline py-2",children:[e.jsxs("div",{className:"min-w-0","data-tool-row":E,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("p",{className:"break-all text-[13px] font-medium text-ink",children:E}),M!==void 0&&M.description.trim()!==""?e.jsx(Rn,{children:M.description}):null]}),M===void 0?e.jsx("p",{"data-tool-state":"config-only",className:"text-[11px] text-ink-faint",children:s("st.tools.configOnly")}):null]}),e.jsx(Qe,{dataAttr:"data-tool-policy",ariaLabel:s("st.tools.policyAria",{name:E}),value:i===null?"inherited":zw(i,E),onChange:z=>{i!==null&&L(Hw(i,E,z,c))},choices:[{value:"inherited",label:s(c==="profile"?"st.tools.inherited":"st.tools.excluded")},...c==="allowlist"||M?.active===!1||i?.toolsRestored?.includes(E)===!0?[{value:"enabled",label:s("st.tools.enabled")}]:[],{value:"disabled",label:s("st.tools.disabled")}]})]},E)};return e.jsx(Me,{id:"st-card-tools",title:s("st.tools.title"),children:e.jsx("div",{className:"space-y-3",children:i===null?N.isError?e.jsx(De,{error:N.error}):e.jsx(he,{children:s("st.runtime.loading")}):j?e.jsxs("div",{"data-tools-all-follow":!0,className:"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2",children:[e.jsx("p",{className:"text-[13px] leading-5 text-ink",children:s("st.permissions.tools.allFollow")}),e.jsx("button",{type:"button","data-tools-adjust":!0,className:`min-h-7 shrink-0 pointer-coarse:min-h-10 ${Ot}`,onClick:()=>{p(!0)},children:s("st.permissions.tools.adjust")})]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{children:s("st.tools.policyHint")}),e.jsxs("fieldset",{disabled:m,className:"min-w-0 space-y-3",children:[e.jsx(ge,{label:s("st.tools.mode"),help:s(c==="profile"?"st.tools.profileImpact":"st.tools.allowlistImpact"),children:e.jsx(Qe,{dataAttr:"data-tool-mode",ariaLabel:s("st.tools.mode"),value:c,onChange:E=>{d(E),L({...i,toolsEnabled:E==="profile"?[]:i.toolsEnabled})},choices:[{value:"profile",label:s("st.tools.followAgent")},{value:"allowlist",label:s("st.tools.allowlist")}]})}),S?e.jsx(pe,{feedback:{tone:"error",text:s("st.tools.emptyAllowlist")}}):null,e.jsx("input",{type:"search",className:Ce,"aria-label":s("st.tools.search"),placeholder:s("st.tools.search"),value:h,onChange:E=>b(E.target.value)}),e.jsxs("div",{className:"max-h-[28rem] overflow-y-auto",children:[P.map($),R.length>0?e.jsxs("div",{className:P.length>0?"pt-3":void 0,children:[e.jsx("p",{"data-tools-unavailable-heading":!0,className:"border-b border-hairline pb-1.5 text-[12px] font-medium text-ink-soft",children:s("st.permissions.tools.unavailable",{count:R.length})}),R.map($)]}):null]}),T.length===0&&!_.isLoading?e.jsx(he,{children:s("st.tools.noMatches")}):null,_.isLoading?e.jsx(he,{children:s("st.tools.loading")}):null,_.isError?e.jsx(De,{error:_.error}):null,e.jsx(lt,{saved:y,id:"tool-policy",dirty:o,saving:m,saveDisabled:S,saveLabel:s("st.tools.savePolicy"),onSave:()=>void I(),onDiscard:()=>{if(N.data!==void 0){const E=el(N.data);r(E),d(E.toolsEnabled.length>0?"allowlist":"profile")}l(!1),v(null)}}),e.jsx(pe,{feedback:g})]})]})})})}const of={decision:"ask",pattern:"",scope:"user",reason:""},OO=["allow","deny","ask"];function lf(t){return{decision:t.decision,pattern:t.pattern,scope:t.scope,reason:t.reason??""}}function DO(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),r=i.data?.permission?.rules??[],o=x.useMemo(()=>r.map((R,L)=>({rule:R,index:L})),[r]),l=x.useCallback(R=>`${R.index}:${R.rule.pattern}:${R.rule.decision}`,[]),c=x.useCallback(R=>[R.rule.pattern,R.rule.reason],[]),d=x.useMemo(()=>OO.map(R=>({id:R,label:s(`st.perm.decision.${R}`),test:L=>L.rule.decision===R})),[s]),u=Qs({listId:"permission-rules",items:o,keyOf:l,textOf:c,filters:d}),[p,h]=x.useState(null),[b,m]=x.useState(!1),[f,g]=x.useState(null),[v,y]=Je(),w=p?.index===null?of:r[p?.index??-1],N=p!==null&&JSON.stringify(p.draft)!==JSON.stringify(w&&lf(w)),_=p===null||Gw.shape.pattern.safeParse(p.draft.pattern).success,C=!_&&p!==null&&p.draft.pattern!=="";Ft("permission-rule",N);const S=async R=>{m(!0),g(null);try{const L=await t.patchConfig({permission:{rules:R}}),I=a.getQueryData(["config"])??i.data;return a.setQueryData(["config"],{...I,...L,permission:L.permission??{...I?.permission,rules:R}}),y(),!0}catch(L){return g({tone:"error",text:oe(n,L)}),!1}finally{m(!1)}},k=async()=>{if(p===null||!N||!_||b)return;const{index:R,draft:L}=p,I={decision:L.decision,scope:L.scope,pattern:L.pattern.trim(),reason:L.reason||void 0},$=[...r];R===null?$.push(I):$[R]=I,await S($)&&h(null)},j=async R=>{b||await S(r.filter((L,I)=>I!==R))&&h(null)},T=async(R,L)=>{if(b)return;const I=[...r];[I[R],I[R+L]]=[I[R+L],I[R]],await S(I)&&h(null)},A=R=>{h(L=>L===null?null:{...L,draft:{...L.draft,...R}}),g(null)},P=e.jsx("button",{type:"button",className:Q,disabled:b||!i.data||p!==null,onClick:()=>{h({index:null,draft:{...of}}),g(null)},children:s("st.perm.add")});return e.jsx(Me,{id:"st-card-permission-rules",title:s("st.perm.rulesTitle"),actions:r.length>0?P:void 0,children:e.jsxs("div",{className:"space-y-3","data-permission-rules":!0,children:[i.isLoading?e.jsx(he,{children:s("st.perm.loading")}):r.length===0?p===null?e.jsx(Ct,{kind:"none",title:s("st.perm.rulesEmpty"),action:P}):null:e.jsxs(e.Fragment,{children:[e.jsx(Gs,{view:u,total:o.length,filters:d,searchLabel:s("st.perm.search"),searchPlaceholder:s("st.perm.searchPlaceholder")}),u.visible.length===0?e.jsx(Ct,{kind:"no-match",title:s("st.perm.noMatchTitle"),body:u.query.trim()!==""?s("st.perm.noMatches",{query:u.query.trim()}):void 0,onClear:u.clear}):e.jsx(Hs,{items:u.visible,keyOf:l,density:u.density,label:s("st.perm.rulesTitle"),renderRow:({rule:R,index:L})=>{const I=b||p!==null||u.narrowed;return e.jsxs("div",{"data-permission-rule-row":R.pattern,children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-[13px]",style:{minHeight:_s[u.density]},children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5 text-ink",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-[12px]",title:R.pattern,children:R.pattern}),e.jsx(de,{name:"arrowRight",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"shrink-0",children:s(`st.perm.decision.${R.decision}`)})]}),e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint",children:s(`st.perm.scope.${R.scope}`)}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",className:Q,disabled:I||L===0,title:u.narrowed?s("st.perm.reorderNarrowed"):void 0,"aria-label":s("st.perm.moveUp"),onClick:()=>void T(L,-1),children:e.jsx(de,{name:"arrowUp",size:14})}),e.jsx("button",{type:"button",className:Q,disabled:I||L===r.length-1,title:u.narrowed?s("st.perm.reorderNarrowed"):void 0,"aria-label":s("st.perm.moveDown"),onClick:()=>void T(L,1),children:e.jsx(de,{name:"arrowDown",size:14})}),e.jsx("button",{type:"button",className:Q,disabled:b||p!==null,onClick:()=>{h({index:L,draft:lf(R)}),g(null)},children:s("st.perm.edit")}),e.jsx("button",{type:"button",className:Q,disabled:b||p!==null,"aria-label":`${s("st.perm.delete")} ${R.pattern}`,onClick:()=>void j(L),children:s("st.perm.delete")})]})]}),p?.index===L?e.jsx(cf,{editing:p,dirty:N,saving:b,patternIssue:C,feedback:f,onUpdate:A,onSave:()=>void k(),onCancel:()=>{h(null),g(null)}}):null]})}})]}),e.jsx(ot,{saving:b,saved:v}),p!==null&&p.index===null?e.jsx(cf,{editing:p,dirty:N,saving:b,patternIssue:C,feedback:f,onUpdate:A,onSave:()=>void k(),onCancel:()=>{h(null),g(null)}}):null,i.isError?e.jsx(De,{error:i.error}):null,p===null?e.jsx(pe,{feedback:f}):null,e.jsx(et,{summary:s("st.advanced.disclosure"),"data-permission-rules-advanced":!0,children:e.jsx(he,{children:s("st.perm.rulesHint")})})]})})}function cf({editing:t,dirty:s,saving:n,patternIssue:a,feedback:i,onUpdate:r,onSave:o,onCancel:l}){const{t:c}=D(),d=t.draft.pattern.trim()==="";return e.jsx(Ub,{open:!0,lazy:!0,className:"mt-1 bg-transparent p-0 pl-3",children:e.jsxs("div",{className:"space-y-3 py-1","data-permission-rule-editor":!0,children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:c("st.perm.pattern")}),e.jsx("input",{"data-autofocus":!0,className:Ce,value:t.draft.pattern,onChange:u=>r({pattern:u.target.value}),"aria-invalid":a,"aria-describedby":a?"permission-rule-pattern-error":void 0,placeholder:"Bash(rm -rf*)"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:c("st.perm.decision")}),e.jsx(Qe,{variant:"form",ariaLabel:c("st.perm.decision"),value:t.draft.decision,onChange:u=>r({decision:u}),choices:["allow","deny","ask"].map(u=>({value:u,label:c(`st.perm.decision.${u}`)}))})]})]}),e.jsx(it,{id:"permission-rule-pattern-error",text:a?c("st.perm.invalidPattern"):null}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:c("st.perm.scope")}),e.jsx(Qe,{variant:"form",ariaLabel:c("st.perm.scope"),value:t.draft.scope,onChange:u=>r({scope:u}),choices:["user","project","turn-override","session-runtime"].map(u=>({value:u,label:c(`st.perm.scope.${u}`)}))})]}),e.jsxs("label",{className:"space-y-1",children:[e.jsx("span",{className:$e,children:c("st.perm.reason")}),e.jsx("input",{className:Ce,value:t.draft.reason,onChange:u=>r({reason:u.target.value})})]})]}),t.draft.scope==="session-runtime"?e.jsx(he,{children:c("st.perm.sessionScopeHint")}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1","data-settings-draft":"permission-rule","data-dirty":s?"true":void 0,children:[e.jsx("button",{type:"button",className:Ye,disabled:!s||n||a||d,onClick:o,children:n?c("common.saving"):t.index===null?c("st.perm.add"):c("common.save")}),e.jsx("button",{type:"button","data-settings-discard":"permission-rule",className:Q,disabled:n,onClick:l,children:c("common.cancel")})]}),e.jsx(pe,{feedback:i})]})})}const so=["policy_compliance","no_secret_egress","no_irreversible_damage","no_outward_effect","prompt_injection_absent"],bi={timeoutS:"8",allowThreshold:"0.5",denyThreshold:"0.5",categories:[...so]};function FO(t){return Number.isInteger(t/1e3)?String(t/1e3):(t/1e3).toFixed(1)}function df(t){return{timeoutS:t?.timeoutMs===void 0?bi.timeoutS:FO(t.timeoutMs),allowThreshold:String(t?.allowThreshold??bi.allowThreshold),denyThreshold:String(t?.denyThreshold??bi.denyThreshold),categories:t?.categories!==void 0?so.filter(s=>t.categories.includes(s)):[...so]}}function wk(t){const s=Number(t);return!Number.isFinite(s)||s<0?null:Math.round(s*1e3)}function pc(t){const s=wk(t.timeoutS),n=Number(t.allowThreshold),a=Number(t.denyThreshold);return s!==null&&Number.isInteger(s)&&s>=100&&s<=3e4&&n>=.5&&n<=1&&a>=.5&&a<=1&&t.categories.length>0}function qO(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),[r,o]=x.useState(bi),[l,c]=x.useState(bi),[d,u]=x.useState(!1),[p,h]=x.useState(null),[b,m]=Je(),f=JSON.stringify(l)!==JSON.stringify(r),g=i.data?.permission?.reviewer;x.useEffect(()=>{if(!i.data||f)return;const _=df(i.data.permission?.reviewer);o(_),c(_)},[i.data,f]);const v=_=>{c(C=>({...C,..._})),h(null)},y=async()=>{if(!(!pc(l)||!f)){u(!0),h(null);try{const _=await t.patchConfig({permission:{reviewer:{timeout_ms:wk(l.timeoutS),allow_threshold:Number(l.allowThreshold),deny_threshold:Number(l.denyThreshold),categories:l.categories}}});a.setQueryData(["config"],_);const C=df(_.permission?.reviewer);o(C),c(C),m()}catch(_){h({tone:"error",text:oe(n,_)})}finally{u(!1)}}},w=Yg(g),N=g?.source!==void 0?void 0:g?.backend==="jev"?s("st.decision.row.reviewerLegacy"):g?.model!==void 0?s("st.reviewer.legacyModel",{model:g.model}):void 0;return e.jsx(Me,{id:"st-card-reviewer",title:s("st.reviewer.title"),children:e.jsxs("div",{className:"space-y-3","data-reviewer-settings":!0,children:[e.jsx(he,{children:s("st.reviewer.hint")}),e.jsx(pu,{consumer:"reviewer",scope:"card",label:s("st.decision.row.reviewer"),help:s("st.decision.sourceHint"),unset:s("st.decision.row.reviewerUnset"),source:g?.source,status:g?.source_status,legacy:N,loading:i.isPending,error:i.error,write:async _=>{a.setQueryData(["config"],await t.patchConfig({permission:{reviewer:{source:_}}}))},extra:w}),e.jsx("fieldset",{disabled:d||i.isLoading,className:"space-y-4 disabled:opacity-60",children:e.jsxs(et,{summary:s("st.advanced.disclosure"),"data-reviewer-advanced":!0,className:"space-y-4 text-[13px] text-ink",children:[e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-3",children:[e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:s("st.reviewer.timeoutS")}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("input",{type:"number",className:`${Ce} w-full text-[13px] tabular-nums`,value:l.timeoutS,min:.1,max:30,step:.1,onChange:_=>v({timeoutS:_.target.value})}),e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint",children:s("st.reviewer.secondsUnit")})]})]}),["allowThreshold","denyThreshold"].map(_=>e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:s(`st.reviewer.${_}`)}),e.jsx("input",{type:"number",className:`${Ce} text-[13px] tabular-nums`,value:l[_],min:.5,max:1,step:.01,onChange:C=>v({[_]:C.target.value})})]},_))]}),e.jsx(he,{children:s("st.reviewer.thresholdHint")}),e.jsxs("fieldset",{className:"space-y-1",children:[e.jsx("legend",{className:"mb-1.5 text-[13px] font-medium text-ink",children:s("st.reviewer.categories")}),so.map(_=>e.jsxs("label",{className:"flex min-h-7 cursor-pointer items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--color-selected-ink)]",checked:l.categories.includes(_),onChange:C=>v({categories:C.target.checked?[...l.categories,_]:l.categories.filter(S=>S!==_)})}),s(`st.reviewer.category.${_}`)]},_))]})]})}),e.jsx(lt,{saved:b,id:"permission-reviewer",dirty:f,saving:d,saveDisabled:!pc(l),onSave:()=>void y(),onDiscard:()=>{c(r),h(null)}}),f&&!pc(l)?e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:s("st.reviewer.invalid")}):null,i.isError?e.jsx(De,{error:i.error}):null,e.jsx(pe,{feedback:p})]})})}const BO=["manual","auto","review","yolo"];function uf(t){return t==="manual"||t==="auto"||t==="review"||t==="yolo"}function KO(){const{client:t}=be(),{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4}),[r,o]=x.useState("auto"),[l,c]=x.useState("default"),[d,u]=x.useState(!1),[p,h]=x.useState(null),[b,m]=Je();x.useEffect(()=>{const v=i.data?.default_permission_mode;!d&&uf(v)&&o(v),d||c(i.data?.permission?.dangerousBash??"default")},[i.data,d]);const f=async v=>{const y=r;o(v),u(!0),h(null);try{const w=await t.patchConfig({default_permission_mode:v}),N=cn(a.getQueryData(["config"])??i.data,w);a.setQueryData(["config"],N);const _=N.default_permission_mode;uf(_)&&(o(_),Mt({defaultPermissionMode:_})),m()}catch(w){o(y),h({tone:"error",text:oe(n,w)})}finally{u(!1)}},g=async v=>{const y=l;c(v),u(!0),h(null);try{const w=await t.patchConfig({permission:{dangerous_bash:v}}),N=a.getQueryData(["config"])??i.data;a.setQueryData(["config"],{...cn(N,w),permission:w.permission??N?.permission}),m()}catch(w){c(y),h({tone:"error",text:oe(n,w)})}finally{u(!1)}};return e.jsxs(Me,{id:"st-card-permission-defaults",title:s("st.perm.defaultTitle"),effect:"newSessions",children:[e.jsxs(Ze,{children:[e.jsx(ge,{label:s("st.defaults.permissionMode"),labelId:"permission-default-mode-label",help:e.jsx("span",{"data-permission-mode-hint":!0,className:r==="yolo"?"text-amber-ink":void 0,children:s(`st.defaults.permission.${r}Hint`)}),children:e.jsxs("div",{className:"flex min-w-0 max-w-[calc(100vw-2rem)] flex-wrap items-center gap-2",children:[e.jsx(jt,{show:b}),e.jsx(He,{ariaLabelledBy:"permission-default-mode-label",value:r,disabled:d||i.data===void 0,onChange:v=>void f(v),choices:BO.map(v=>({value:v,label:s(`st.defaults.permission.${v}`),caution:v==="yolo"}))})]})}),e.jsx(ge,{label:s("st.perm.dangerousBash"),labelId:"permission-dangerous-bash-label",help:s("st.perm.dangerousBashHint"),children:e.jsx("div",{className:"min-w-0 max-w-[calc(100vw-2rem)]",children:e.jsx(He,{ariaLabelledBy:"permission-dangerous-bash-label",value:l,disabled:d||i.data===void 0,onChange:v=>void g(v),choices:["default","on","off"].map(v=>({value:v,label:v==="default"?s("st.permissions.dangerBash.followMode",{effect:s(r==="yolo"?"st.perm.dangerousBash.off":"st.perm.dangerousBash.on")}):s(`st.perm.dangerousBash.${v}`)}))})})}),e.jsx($$,{})]}),e.jsxs("div",{className:"pt-2",children:[e.jsx(pe,{feedback:p}),i.isError?e.jsx(De,{error:i.error}):null]})]})}function UO(){return e.jsxs(e.Fragment,{children:[e.jsx(KO,{}),e.jsx(DO,{}),e.jsx(qO,{}),e.jsx(MO,{})]})}const gn=new Set(["connecting","ready","running","stopping","unconfirmed"]),Nk=new Set(["connecting","ready","running","stopping"]),pf="codex-browser";function Sk(t,s){return t.find(n=>n.type==="codex-extension"&&(n.browserId===s||n.browserId===void 0&&n.id===s))}function HO(t,s){if(Sk(t,s)!==void 0)return;const n=t.find(a=>a.id===pf);if(n===void 0||n.type==="codex-extension"&&(n.browserId===void 0||n.browserId===s))return pf;if(ub.safeParse(s).success&&t.every(a=>a.id!==s))return s}const Vt={all:["browser"],connections:t=>["browser","connections",t],presets:t=>["browser","setup",t],tabs:(t,s,n)=>["browser","tabs",t,s,n],catalog:(t,s,n,a)=>["browser","catalog",t,s,n,a]};function St(t){const s=t.klient.rest;if(s===void 0)throw new Error("Browser connection management needs an HTTP connection to the server.");return s.browser}function zO(t){if(t===null||typeof t!="object")return;const s=Ww.safeParse(t.details);return s.success?s.data:void 0}function QO(t){return t?.code==="browser.disabled"&&t.reason==="feature_disabled"}const fd="0.38.2",bd="kiki-no-replay-r1 kiki-stdio-r1";function Wu(t){if(t.state==="preparing")return"preparing";if(t.state==="connected")return"connected";if(t.state==="ready")return"ready";if(t.state==="external_only")return"external";if(t.state==="unsupported"||t.supported===!1&&t.controlSurface!=="external-app")return"unsupported";const s=Vu(t);return t.reason==="feature_forced_off"||s?.reason==="feature_forced_off"?"forced-off":t.state==="failed"?"failed":t.state==="needs_user_action"||t.state==="not_prepared"?"needs-action":"blocked"}function Vu(t){return t.steps.find(s=>s.state!=="ready"&&s.state!=="running"&&s.state!=="warning")}function Ck(t){return t.steps.find(s=>s.state==="running")}function GO(t){return t.steps.find(s=>s.state==="warning")}function Ys(t,s){return t.actions.find(n=>n.id===s)}function gd(t){if(t===void 0||t==="")return;const s=/^[a-z][a-z0-9+.-]*:\/\/(.+)$/i.exec(t);return s===null?t:s[1]}function pa(t,s){if(s===void 0)return;const n=new Date(s);return Number.isNaN(n.getTime())?s:n.toLocaleString(t,{dateStyle:"medium",timeStyle:"short"})}const WO={ok:"bg-success",attention:"bg-amber-rule",off:"bg-hairline-strong",unknown:"bg-ink-faint"};function VO({kind:t,tone:s,text:n,detail:a,action:i,attr:r}){return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsxs("p",{role:"status",className:"flex min-w-0 items-baseline gap-2 text-[13px] leading-5",[r]:t,"data-verdict-tone":s,children:[e.jsx("span",{"aria-hidden":!0,className:`relative top-[-1px] inline-block h-1.5 w-1.5 shrink-0 rounded-full ${WO[s]}`}),e.jsxs("span",{className:s==="off"?"text-ink-soft":"text-ink",children:[n,a===void 0?null:e.jsx("span",{className:"text-ink-soft",children:` · ${a}`})]})]}),i]})}function mf({id:t,attr:s,label:n,checked:a,disabled:i,onChange:r}){return e.jsx("button",{type:"button",id:t,role:"switch","aria-checked":a,"aria-label":n,disabled:i,[s]:"",onClick:()=>{r(!a)},className:`relative inline-flex h-[18px] w-8 shrink-0 items-center rounded-full ring-1 transition-colors duration-[var(--kiki-motion-quick)] ${a?"bg-selected ring-selected-ink/45":"bg-hairline ring-hairline-strong"} ${i?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full transition-transform duration-[var(--kiki-motion-quick)] motion-reduce:transition-none ${a?"translate-x-[16px] bg-selected-ink":"translate-x-[3px] bg-ink-faint"}`})})}function _k({title:t,verdict:s,enabled:n,onEnabledChange:a,enabledLockedReason:i,saving:r,saved:o,defaultOn:l,onDefaultOnChange:c,defaultOnSaving:d,primaryAction:u,attrs:p,children:h}){const{t:b}=D(),m=r===!0||i!==void 0,f=l?.locked===!0||d===!0;return e.jsxs("div",{className:"space-y-2.5",[p.enabled]:n?"true":"false",children:[e.jsxs(ge,{label:t,labelId:"capability-header-label",help:e.jsx(VO,{attr:p.verdict,kind:s.kind,tone:s.tone,text:s.text,detail:s.detail,action:u??s.action}),children:[e.jsx(ot,{saving:r===!0,saved:o===!0}),i===void 0?null:e.jsx("span",{className:"text-[12px] text-ink-faint","data-capability-locked-reason":!0,children:i}),e.jsx(mf,{id:`${p.enabledSwitch.replace(/^data-/,"")}-switch`,attr:p.enabledSwitch,label:t,checked:n,disabled:m,onChange:a})]}),h,n&&l!==void 0&&c!==void 0?e.jsxs("div",{className:"flex items-center gap-2",...p.defaultOn===void 0?{}:{[p.defaultOn]:""},children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:`text-[12.5px] ${f?"text-ink-faint":"text-ink-soft"}`,children:b("cap.switch.defaultOn")}),e.jsx(mf,{id:`${p.enabledSwitch.replace(/^data-/,"")}-default-on`,attr:"data-capability-default-switch",label:b("cap.switch.defaultOn"),checked:l.checked,disabled:f,onChange:c})]}),e.jsx(ot,{saving:d===!0,saved:!1})]}):null]})}const Ek="kiki-computer",Tk=["ControlStatus","DisplayInventory","Screenshot","Snapshot","Click","Type","Scroll","Move","Shortcut","Wait","WaitFor","App"],YO=new Set(Tk);function Ii(t){return["computer-control-mcp",t]}function Bo(t){return t.split(/[\\/]/).at(-1)??""}function mc(t,s){const n=t.indexOf(s);if(!(n<0))return t[n+1]}function JO(t){return t===void 0||t.transport!=="stdio"||!/^cua-driver(?:\.exe)?$/i.test(Bo(t.command))?!1:t.args?.includes("mcp")===!0}function Ik(t){if(t===void 0||t.transport!=="stdio")return!1;const s=t.args??[];for(let a=0;a<s.length-1;a+=1)if(s[a]==="-m"&&s[a+1]==="windows_mcp")return!0;const n=Bo(t.command).toLowerCase();return(n==="windows-mcp"||n==="windows-mcp.exe")&&s[0]==="serve"}function ma(t){if(!(t===void 0||t.transport!=="stdio")){if(JO(t))return"cua";if(Ik(t))return"windows-mcp"}}function Yu(t){return ma(t)!==void 0}function ZO(t){if(t===void 0||t.transport!=="stdio"||!Ik(t)||t.executor==="kaos")return!1;const s=Bo(t.command).toLowerCase();if(s==="uv"||s==="uv.exe"||s==="uvx"||s==="uvx.exe")return!1;const n=t.args??[];if(n.includes("install")||n.includes("auth"))return!1;const a=n.indexOf("serve");if(a<0||!(s==="windows-mcp"||s==="windows-mcp.exe")&&n[a-1]!=="windows_mcp"||mc(n,"--transport")!=="stdio")return!1;const r=mc(n,"--config");if(r===void 0||r.startsWith("-"))return!1;const o=mc(n,"--tools");if(o===void 0)return!1;const l=o.split(",").map(d=>d.trim()).filter(d=>d.length>0);if(l.length!==YO.size)return!1;const c=new Set(l);return c.size===l.length&&Tk.every(d=>c.has(d))}function Pk(t){if(!ZO(t)||t===void 0||t.transport!=="stdio")return"not_ready";const s=t.computerServeReady;if(typeof s=="boolean")return s?"ready":"not_ready";const n=Rk(t,"env");if(n!==void 0)return n.ANONYMIZED_TELEMETRY==="false"?"ready":"not_ready";const a=$k(t,"envKeys");return a!==void 0&&!a.includes("ANONYMIZED_TELEMETRY")?"not_ready":"unverified"}function Ya(t,s){const n=i=>i.replace(/\\/g,"/").toLowerCase(),a=n(t.trim());return s!==void 0&&s.trim()!==""?a===n(s.trim()):a.includes("/capabilities/kiki-computer/")}function Ak(t){return Yu(t.config)||t.config.transport==="stdio"&&(t.name===Ek||t.name===Nr)}function XO(t){return t==="darwin"?["mcp","--direct"]:["mcp"]}function $k(t,s){const n=t[s];return Array.isArray(n)?n:void 0}function Rk(t,s){if(s in t)return t[s]}function ai(t){const s=t.config.transport==="stdio"?t.config:void 0;return{original:t,name:t.name,command:s?.command??"",args:(s?.args??[]).join(`
|
|
251
|
+
`),enabled:s?.enabled!==!1,executor:s?.executor??"local",startupTimeoutMs:s?.startupTimeoutMs===void 0?"":String(s.startupTimeoutMs),toolTimeoutMs:s?.toolTimeoutMs===void 0?"":String(s.toolTimeoutMs),envRows:t.mutable&&s!==void 0?ZS($k(s,"envKeys"),Rk(s,"env")):[]}}function eD(t,s){return{name:Ek,command:s??"",args:XO(t).join(`
|
|
252
|
+
`),enabled:!0,executor:"local",startupTimeoutMs:"",toolTimeoutMs:"",envRows:[]}}function xf(t){return t.original===void 0}function tD(t){return t.original===void 0||JSON.stringify(t)!==JSON.stringify(ai(t.original))}function hf(t,s){const n=t.trim();if(n==="")return;const a=Number(n);if(!Number.isSafeInteger(a)||a<1)throw new Error(s);return a}function ff(t,s,n){const a=t.name.trim(),i=XS({original:t.original,transport:"stdio",command:t.command,args:t.args,env:s,url:"",headers:"",bearerTokenEnvVar:""});if(i.transport!=="stdio")throw new Error("st.computer.notStdio");const r=t.original?.config;return{...i,name:a,args:i.args===void 0?void 0:[...i.args],enabledTools:i.enabledTools===void 0?void 0:[...i.enabledTools],disabledTools:i.disabledTools===void 0?void 0:[...i.disabledTools],enabled:t.enabled,executor:t.executor,runtime_id:t.executor==="kaos"&&r?.transport==="stdio"?r.runtime_id:void 0,startupTimeoutMs:hf(t.startupTimeoutMs,n),toolTimeoutMs:hf(t.toolTimeoutMs,n)}}function sD(t){if(!(t===void 0||t===""))return t==="win32"?"Windows":t==="darwin"?"macOS":t==="linux"?"Linux":t}function kr(t){return t.transport!=="stdio"?t.url:[Bo(t.command),...t.args??[]].join(" ").trim()}function bf(t){return t.plugin===void 0?void 0:`/capabilities?tab=plugins&plugin=${encodeURIComponent(t.plugin.id)}`}function Is(t){return`${t.source}:${t.name}`}const Lk=x.createContext(null);function nD(){const{t}=D(),s=x.useContext(Lk);return e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5`,"data-computer-add-heading":!0,onClick:()=>{s?.()},children:[e.jsx(de,{name:"plus",size:12}),t("st.computer.add")]})}function aD({platform:t,planBinary:s,summary:n,footer:a}){const{client:i,klient:r,scopeId:o}=be(),{t:l,locale:c}=D(),d=Oe(),u=Ln(),p=je({queryKey:Ii(o),queryFn:()=>r.global.mcp.list(),staleTime:3e4}),h=(p.data??[]).filter(te=>Ak(te)),[b,m]=x.useState(null),[f,g]=x.useState(null),[v,y]=x.useState(!1),[w,N]=x.useState(!1),[_,C]=x.useState(!1),[S,k]=x.useState(null),[j,T]=x.useState(!1),[A,P]=x.useState(!1),[R,L]=x.useState(null),[I,$]=x.useState(null),[E,M]=Je(),z=f!==null&&tD(f),H=`computer-control:${o}:${f?.original===void 0?"new":Is(f.original)}`,U=f?.original===void 0?null:Is(f.original),X=U!==null&&p.isSuccess&&!h.some(te=>Is(te)===U);x.useEffect(()=>{X&&!z&&g(null)},[X,z]);const q=te=>{g(te),y(!1),m(te?.original===void 0?null:Is(te.original)),k(null),L(null),$(null)},F=te=>{if(z&&f!==null&&u?.confirmDiscard!==void 0){u.confirmDiscard(H,()=>{q(te)});return}q(te)},V=f?.original?.mutable===!0?async te=>(await i.revealSecret({kind:"mcp_env",server:f.original.name,key:te})).value:void 0,se=te=>{const ee=te instanceof Error?te.message:"";$({tone:"error",text:ee.startsWith("st.")?l(ee):oe(c,te)})},Y=(te,ee)=>{d.setQueryData(Ii(o),te);const K=te.find(Z=>Z.name===ee&&Z.source==="global"&&Z.mutable);K!==void 0&&(g(ai(K)),m(Is(K)))},O=async()=>{if(f===null)return;const te=f.name.trim();if(te===""){$({tone:"error",text:l("st.mcp.nameRequired")});return}N(!0),$(null),k(null);try{const ee=await om(f.envRows,V??(async()=>{})),K=ff(f,ee,"st.computer.timeoutInvalid"),Z=f.original,ue=Z!==void 0&&Z.name!==te;let Te=Z===void 0||ue?await r.global.mcp.add({server:K}):await r.global.mcp.update({server:K});ue&&Z!==void 0&&(Te=await r.global.mcp.remove({name:Z.name})),Y(Te,te),M(),await d.invalidateQueries({queryKey:["mcp-servers"]})}catch(ee){se(ee)}finally{N(!1)}},B=async()=>{if(f===null)return;if(f.name.trim()===""){$({tone:"error",text:l("st.mcp.nameRequired")});return}C(!0),$(null),k(null);try{const ee=await om(f.envRows,V??(async()=>{})),K=ff(f,ee,"st.computer.timeoutInvalid");k(await r.global.mcp.test({server:K}))}catch(ee){se(ee)}finally{C(!1)}},le=async()=>{const te=f?.original;if(P(!1),te!==void 0){T(!0),$(null),L(null);try{const ee=await r.global.mcp.stop({name:te.name});L(ee);const K=await p.refetch();if(K.data!==void 0){const Z=K.data.find(ue=>Is(ue)===Is(te));Z!==void 0&&g(ai(Z))}await d.invalidateQueries({queryKey:["mcp-servers"]})}catch(ee){se(ee)}finally{T(!1)}}},re=f?.original!==void 0&&!f.original.mutable,ne=(f?.original!==void 0?ma(f.original.config):void 0)==="windows-mcp"&&f?.original!==void 0?Pk(f.original.config):void 0,Ee=ne!==void 0&&ne!=="ready",ie=ne==="unverified",me=()=>f===null?null:e.jsxs("div",{className:"min-w-0 space-y-4","data-computer-detail":f.original?.name??"new",children:[Ee?e.jsx("p",{className:"text-[12px] text-amber-ink","data-computer-windows-mcp-not-ready":!0,children:l(ie?"st.computer.windowsMcp.unverified":"st.computer.windowsMcp.notServeReady")}):null,f.original!==void 0||s!==void 0?null:e.jsxs("ol",{className:"max-w-[62ch] list-decimal space-y-0.5 pl-4 text-[12px] leading-[18px] text-ink-soft marker:text-ink-faint","data-computer-mcp-steps":!0,children:[e.jsx("li",{children:l("st.computer.mcpSteps.1")}),e.jsx("li",{children:l("st.computer.mcpSteps.2")})]}),e.jsxs("fieldset",{disabled:w||j||re,className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:"computer-name",children:l("st.computer.fieldName")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{id:"computer-name",className:`${Ce} min-w-0 flex-1 font-mono`,"data-computer-name-input":!0,value:f.name,spellCheck:!1,autoComplete:"off",onChange:te=>{g({...f,name:te.target.value})}}),e.jsx("span",{className:"shrink-0",children:e.jsx(Be,{label:l("st.computer.fieldEnabled"),checked:f.enabled,disabled:w||re,onChange:te=>{g({...f,enabled:te})}})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:"computer-command",children:l("st.computer.fieldCommand")}),e.jsx("input",{id:"computer-command",className:`${Ce} font-mono`,"data-computer-command-input":!0,value:f.command,spellCheck:!1,autoComplete:"off",placeholder:l("st.computer.commandPlaceholder"),onChange:te=>{g({...f,command:te.target.value})}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:"computer-args",children:l("st.computer.fieldArgs")}),e.jsx("textarea",{id:"computer-args",className:`${Ce} min-h-20 font-mono`,"data-computer-args-input":!0,value:f.args,spellCheck:!1,onChange:te=>{g({...f,args:te.target.value})}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,id:"computer-executor-label",children:l("st.computer.fieldExecutor")}),e.jsx(Qe,{id:"computer-executor",variant:"form",ariaLabel:l("st.computer.fieldExecutor"),value:f.executor,dataAttr:"data-computer-executor",choices:[{value:"local",label:l("st.computer.executor.local")},{value:"kaos",label:l("st.computer.executor.kaos")}],onChange:te=>{g({...f,executor:te})}})]}),e.jsx(et,{summary:l("st.computer.advanced"),"data-computer-advanced":!0,children:e.jsxs("div",{className:"space-y-3 text-[12px] text-ink-soft",children:[e.jsx(e1,{kind:"env",rows:f.envRows,reveal:V,onChange:te=>{g({...f,envRows:te})}}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"space-y-1.5",children:[e.jsx("span",{className:$e,children:l("st.computer.startupTimeout")}),e.jsx("input",{className:`${Ce} font-mono`,inputMode:"numeric","data-computer-startup-timeout":!0,value:f.startupTimeoutMs,onChange:te=>{g({...f,startupTimeoutMs:te.target.value})}})]}),e.jsxs("label",{className:"space-y-1.5",children:[e.jsx("span",{className:$e,children:l("st.computer.toolTimeout")}),e.jsx("input",{className:`${Ce} font-mono`,inputMode:"numeric","data-computer-tool-timeout":!0,value:f.toolTimeoutMs,onChange:te=>{g({...f,toolTimeoutMs:te.target.value})}})]})]}),e.jsxs("dl",{className:"grid grid-cols-[minmax(0,8rem)_minmax(0,1fr)] gap-x-4 gap-y-1",children:[e.jsx("dt",{className:"text-ink-faint",children:l("st.mcp.transport")}),e.jsx("dd",{className:"font-mono",children:"stdio"}),e.jsx("dt",{className:"text-ink-faint",children:l("st.mcp.origin")}),e.jsx("dd",{className:"min-w-0 break-all font-mono","data-computer-source":!0,title:f.original?.origin,children:f.original===void 0?l("st.computer.sourceNew"):f.original.origin}),f.original===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:l("st.computer.sourceField")}),e.jsx("dd",{className:"font-mono",children:f.original.source})]})]}),f.original!==void 0&&bf(f.original)!==void 0?e.jsx(_t,{to:bf(f.original),className:"inline-block text-[12px] font-medium text-selected-ink hover:underline","data-computer-plugin-link":!0,children:l("st.plugins.manageLink")}):null]})})]}),re?e.jsx(he,{children:l("st.computer.readOnly")}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,"data-computer-test-btn":!0,disabled:_||w||f.name.trim()==="",onClick:()=>{B()},children:l(_?"st.computer.testing":"st.computer.testButton")}),f.original!==void 0&&Yu(f.original.config)?e.jsx("button",{type:"button",className:Ht,"data-computer-stop-btn":!0,disabled:j||w,onClick:()=>{P(!0)},children:l(j?"st.computer.stopping":"st.computer.stopButton")}):null]}),S!==null?e.jsxs("div",{className:"space-y-1","data-computer-test-result":S.success?"ok":"error",children:[e.jsx("p",{role:"status",className:`text-[12px] ${S.success?"text-ink-soft":"text-danger"}`,children:S.success?l("st.computer.testOk"):l("st.computer.testFailed")}),e.jsx("pre",{className:"max-h-40 overflow-auto border-l-2 border-hairline-strong pl-2 font-mono text-[11px] leading-4 whitespace-pre-wrap text-ink-soft",children:S.output})]}):null,R!==null?e.jsxs("div",{className:"space-y-1","data-computer-stop-result":R.state,children:[e.jsx("p",{role:"status",className:"text-[12px] text-ink-soft",children:l(R.state==="stopped"?"st.computer.stop.stopped":R.state==="idle"?"st.computer.stop.idle":"st.computer.stop.unconfirmed")}),e.jsx("pre",{className:"max-h-40 overflow-auto border-l-2 border-hairline-strong pl-2 font-mono text-[11px] leading-4 whitespace-pre-wrap text-ink-soft","data-computer-stop-output":!0,children:R.output})]}):null,e.jsx(pe,{feedback:I}),re?null:e.jsx(lt,{id:H,dirty:z,saving:w,saveLabel:xf(f)?l("st.computer.create"):void 0,persistent:xf(f),saved:E,onSave:()=>{O()},onDiscard:()=>{q(f.original===void 0?null:ai(f.original))}})]}),fe=e.jsxs("div",{"aria-label":l("st.computer.connectionsTitle"),className:"min-w-0",children:[p.isLoading?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:l("st.computer.loading")}):null,p.isError?e.jsx(De,{error:p.error}):null,p.isSuccess&&h.length===0?e.jsx("p",{className:"py-1 text-[13px] text-ink-soft","data-computer-empty":!0,children:l("st.computer.empty")}):null,h.length>0?e.jsx("div",{className:"divide-y divide-hairline/70","data-computer-list":!0,children:h.map(te=>{const ee=ma(te.config),K=b===Is(te);return e.jsx(Di,{data:{"data-computer-connection":te.name,"data-computer-connection-kind":ee},open:K,onToggle:()=>{F(K?null:ai(te))},bodyId:`computer-row-body-${te.source}-${te.name}`,expandLabel:l("st.computer.menu.openRow",{name:te.name}),name:te.name,marks:e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[ee===void 0?null:e.jsx(Yt,{children:l(ee==="windows-mcp"?"st.computer.kind.windowsMcp":"st.computer.kind.cua")}),te.mutable?null:e.jsx(Yt,{children:te.plugin!==void 0?l("st.mcp.fromPlugin",{name:te.plugin.name}):l("st.mcp.readOnly")})]}),subtitle:e.jsx("span",{className:"max-w-full truncate font-mono text-[11px] text-ink-faint",title:kr(te.config),children:kr(te.config)}),children:K&&f!==null?me():null},Is(te))})}):null]}),Ie=f?.original===void 0?[]:[kr(f.original.config),f.original.mutable?l("st.computer.stop.disables"):l("st.computer.stop.readOnly")];return e.jsx(Lk.Provider,{value:()=>{y(!0)},children:e.jsxs("div",{className:"min-w-0 space-y-3","data-computer-connections":!0,"data-computer-view":v?"add":"list",children:[v?e.jsxs("div",{className:"min-w-0 space-y-4","data-computer-add-view":!0,children:[e.jsxs("button",{type:"button","data-computer-back":!0,className:"inline-flex items-center gap-1 rounded text-[12px] text-ink-soft transition-colors hover:text-ink focus-visible:underline",onClick:()=>{y(!1)},children:[e.jsx(de,{name:"arrowLeft",size:12}),l("st.computer.connectionsTitle")]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5`,"data-computer-new":!0,onClick:()=>{F(eD(t,s))},children:[e.jsx(de,{name:"plus",size:12}),l("st.computer.setupEntry")]}),a]})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"hidden","data-computer-add":!0,"aria-hidden":"true",tabIndex:-1,disabled:w||j,onClick:()=>{y(!0)}}),n,fe]}),f!==null&&!v&&b===null?me():null,e.jsx(Xe,{open:A,overlayId:"confirm-computer-stop",title:l("st.computer.stop.confirmTitle",{name:f?.original?.name??""}),body:l("st.computer.stop.confirmBody"),consequences:Ie,confirmLabel:l("st.computer.stopButton"),busy:j,onCancel:()=>{P(!1)},onConfirm:()=>{le()}})]})})}function iD(t){const{client:s,scopeId:n}=be(),{locale:a}=D(),i=Oe(),r=t.data!==void 0?y_(t.data):"avoid",o=t.data?.computer_control?.usagePreferenceSource??"default",l=o==="env"||o==="memory",[c,d]=x.useState(null),[u,p]=x.useState(!1),[h,b]=x.useState(null),[m,f]=Je(),[g,v]=x.useState(0),y=x.useRef(0),w=x.useRef(0),N=x.useRef(new Map);x.useEffect(()=>(y.current+=1,d(null),p(!1),b(null),()=>{y.current+=1}),[n]);const _=m&&g===y.current,C=c??r,S=async T=>{const A=n,P=y.current,R=++w.current;N.current.set(A,R);const L=()=>N.current.get(A)===R,I=()=>L()&&y.current===P;p(!0),b(null);try{const $=["config",A],E=i.getQueryState($)?.dataUpdateCount??0,M=await s.patchConfig(k_(T));return!L()||(i.getQueryState($)?.dataUpdateCount??0)!==E?void 0:(i.setQueryData($,M),I()&&(d(null),v(P),f()),M)}catch($){I()&&(d(null),b({tone:"error",text:oe(a,$)}));return}finally{I()&&p(!1)}};return{activePreference:C,preferenceSource:o,isOverriddenByHigherSource:l,preferenceSaving:u,preferenceFeedback:h,isPreferenceSaved:_,choosePreference:T=>{l||u||T===C||(d(T),S(T))},resetToInherited:async()=>{l||u||await S(null)}}}const xc="kiki-computer",hc={default:"st.computer.source.default",preset:"st.computer.source.preset",base:"st.computer.source.base",home:"st.computer.source.home",env:"st.computer.source.env",memory:"st.computer.source.memory"},gf={binary:"st.computer.step.binary",mcp:"st.computer.step.mcp","desktop-access":"st.computer.step.desktopAccess",permissions:"st.computer.step.permissions",runtime:"st.computer.step.runtime"},rD={not_installed:"st.computer.state.notInstalled",partial:"st.computer.state.partial",ready:"st.computer.state.installed",unsupported:"st.computer.state.unsupported"},oD={unresolved:"st.computer.verdict.unresolved",host_locked:"st.computer.verdict.hostLocked",off:"st.computer.verdict.off",tool_denied:"st.computer.toolPolicyDenied",checking:"st.computer.state.detecting",unknown:"st.computer.verdict.unknown",unsupported:"st.computer.verdict.unsupported",installing:"st.computer.installing",not_installed:"st.computer.verdict.notInstalled",partial:"st.computer.verdict.partial",no_connection:"st.computer.verdict.noConnection",connection_not_ready:"st.computer.verdict.connectionNotReady"};function lD(){const{client:t,klient:s,scopeId:n,sshLabel:a}=be(),{t:i,locale:r}=D(),o=Oe(),l=x.useContext(Mn);x.useEffect(()=>{l?.("st-card-computer-machine"),l?.("st-card-computer-setup")},[l]);const c=je({queryKey:["computer-control-env",n],queryFn:()=>s.global.env(),staleTime:1/0}),d=je({queryKey:["capability",xc,n],queryFn:()=>t.getCapability(xc),refetchInterval:G=>G.state.data?.install.running===!0?1e3:!1}),u=je({queryKey:["config",n],queryFn:()=>t.getConfig(),staleTime:6e4}),p=je({queryKey:Ii(n),queryFn:()=>s.global.mcp.list(),staleTime:3e4}),h=u.data!==void 0?w_(u.data):void 0,b=u.data?.computer_control?.connectionSource??"default",m=b==="env"||b==="memory",f=bt(),g=Ns(u.data,"computer"),v=g?.allowed??j_(u.data),y=g?.host_locked===!0,w=yg(u.data,h??null),N=__(u.data,h??null),_=bt(),C=bt(),S=G=>{const Le=u.data?.computer_control?.enabled===!1&&u.data.computer_control.enabledSource==="default";_.run(async()=>{await t.setComputerControlEnabled(G?Le?!0:null:!1),await o.invalidateQueries({queryKey:["config",n]})})},k=G=>{f.run(async()=>{const Le=await t.patchConfig(N_(G===""?null:G));o.setQueryData(["config",n],Le)})},j=x.useMemo(()=>(p.data??[]).filter(G=>Ak(G)),[p.data]),T=x.useMemo(()=>j.filter(G=>ma(G.config)==="cua"),[j]),A=x.useMemo(()=>T.filter(G=>G.config.enabled!==!1),[T]),P=x.useMemo(()=>h!==void 0?j.find(G=>G.name===h):A[0]??T[0],[T,A,j,h]),R=P!==void 0?ma(P.config):void 0,L=R==="windows-mcp"&&P!==void 0?Pk(P.config):void 0,I=L!==void 0&&L!=="ready",$=L==="unverified",E=P!==void 0&&P.config.enabled!==!1,M=P!==void 0&&E&&(R==="cua"||L==="ready"),z=d.data?.plan?.destination,H=x.useMemo(()=>h!==void 0?R==="windows-mcp"?!0:R==="cua"&&P?.config.transport==="stdio"?!Ya(P.config.command,z):!0:(A.length>0?A:T).some(Le=>Le.config.transport==="stdio"&&!Ya(Le.config.command,z)),[P,R,T,A,z,h]),U=x.useMemo(()=>{if(h!==void 0)return R==="cua"&&P?.config.transport==="stdio"&&Ya(P.config.command,z);const G=A.length>0?A:T;return G.length===0||G.some(Le=>Le.config.transport==="stdio"&&Ya(Le.config.command,z))},[P,R,T,A,z,h]),X=iD(u),q=[{value:"avoid",label:i("st.computer.preference.avoid")},{value:"prefer",label:i("st.computer.preference.prefer")}],F=x.useMemo(()=>{const G=[{value:"",label:i("st.computer.activeConnectionDefault"),hint:i("st.computer.activeConnectionDefaultHint")}],Le=new Set([""]);for(const Se of j){if(!Yu(Se.config)&&Se.name!==h||Le.has(Se.name))continue;Le.add(Se.name);const Fe=ma(Se.config),ye=Fe==="windows-mcp"?i("st.computer.kind.windowsMcp"):Fe==="cua"?i("st.computer.kind.cua"):void 0;G.push({value:Se.name,label:ye===void 0?Se.name:`${Se.name} · ${ye}`,hint:kr(Se.config)})}return h!==void 0&&!Le.has(h)&&G.push({value:h,label:h}),G},[j,h,i]),[V,se]=x.useState(!1),[Y,O]=x.useState(!1),[B,le]=x.useState(!1),[re,ae]=x.useState(null),ne=d.data,Ee=c.data?.platform,ie=[sD(Ee),c.data?.arch].filter(G=>G!==void 0&&G!=="").join(" · "),me=c.isSuccess?ie===""?i("st.computer.machineUnknown"):ie:"",fe=G=>{ae({tone:"error",text:oe(r,G)})},Ie=async()=>{se(!0),ae(null);try{await Promise.all([u.refetch(),d.refetch(),p.refetch()])}catch(G){fe(G)}finally{se(!1)}},te=async G=>{const Le=G.plan?.artifact.sha256;if(le(!1),Le!==void 0){O(!0),ae(null);try{const Se=await t.installCapability(G.id,Le);o.setQueryData(["capability",xc,n],Se),await o.invalidateQueries({queryKey:Ii(n)}),ae({tone:"success",text:i("st.computer.installDone",{version:G.plan?.artifact.version??""})})}catch(Se){fe(Se)}finally{O(!1)}}},ee=ne?.install.error,K=ne?.steps.some(G=>G.optional===!0&&G.state!=="ok")===!0,Z=ne!==void 0&&ne.state!=="ready"&&!ne.install.running&&ne.plan!==void 0,ue=u.isPending||p.isPending?"checking":u.isError&&u.data===void 0||p.isError?"unknown":R==="windows-mcp"||h!==void 0&&R!=="cua"||H&&!U?"external":d.isPending?"checking":d.isError||ne===void 0?"unknown":ne.state!=="ready"&&!ne.install.running&&!Y&&H?"external":{state:ne.state,installing:ne.install.running||Y},Te=C_({enabled:v,hostLocked:y,unresolved:g?.unresolved,toolPolicyDenied:w,executor:ue,hasConnection:P!==void 0,activeConnectionReady:M}),Ne=(()=>{if(Te.kind==="ready"){const G=ue==="external"||ne?.state!=="ready"||h===void 0&&A.some(Se=>Se.config.transport==="stdio"&&!Ya(Se.config.command,z));if(h===void 0&&A.length>1)return i(G?"st.computer.verdict.readyConfiguredSet":"st.computer.verdict.readySet",{names:A.map(Se=>Se.name).join(", ")});const Le=h??P?.name??i("st.computer.activeConnectionDefault");return i(G?"st.computer.verdict.readyConfigured":"st.computer.verdict.ready",{name:Le})}return Te.kind==="connection_not_ready"&&$?i("st.computer.verdict.connectionUnverified",{name:h??P?.name??"kiki-windows-mcp"}):i(oD[Te.kind])})(),J=Te.kind==="unknown"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Q,"data-computer-retry":!0,onClick:()=>{Ie()},children:i("common.retry")}),Z?e.jsx("button",{type:"button",className:Ye,"data-computer-install-btn":!0,disabled:Y,onClick:()=>{le(!0)},children:i(Y?"st.computer.installing":ee===void 0?"st.computer.installButton":"st.computer.retryInstall")}):null]}):(Te.kind==="not_installed"||Te.kind==="partial")&&Z?e.jsx("button",{type:"button",className:Ye,"data-computer-install-btn":!0,disabled:Y,onClick:()=>{le(!0)},children:i(Y?"st.computer.installing":ee===void 0?"st.computer.installButton":"st.computer.retryInstall")}):null,we=j.length>0||h!==void 0?e.jsxs("div",{className:"space-y-1.5","data-computer-active-connection-row":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2 text-[12px] text-ink-soft",children:[e.jsx("span",{id:"computer-active-connection-label",children:i("st.computer.activeConnectionLabel")}),e.jsx(Qe,{id:"computer-active-connection",ariaLabel:i("st.computer.activeConnectionLabel"),dataAttr:"data-computer-active-connection",value:h??"",choices:F,disabled:f.saving||u.isLoading||m,onChange:k,variant:"row",mono:!0}),m?e.jsx("span",{className:"inline-flex items-center rounded bg-ink/[0.05] px-1.5 py-0.5 text-[11px] text-ink-soft","data-computer-connection-source":b,children:i("st.computer.sourceTag",{source:i(hc[b]??"st.computer.source.default")})}):null,e.jsx(ot,{saving:f.saving,saved:f.saved})]}),R==="windows-mcp"?e.jsx("p",{className:"text-[12px] text-ink-soft","data-computer-active-windows-mcp-hint":!0,children:i("st.computer.windowsMcp.foregroundHint")}):null,I?e.jsx("p",{className:"text-[12px] text-amber-ink","data-computer-active-windows-mcp-not-ready":!0,children:i($?"st.computer.windowsMcp.unverified":"st.computer.windowsMcp.notServeReady")}):null,e.jsx(pe,{feedback:f.error})]}):null;return e.jsxs("div",{className:"space-y-6","data-settings-computer-control":!0,children:[e.jsx(Me,{id:"st-card-computer-enabled",title:"",children:e.jsxs(_k,{title:i("st.computer.enabledLabel"),verdict:{kind:Te.kind,tone:Te.tone,text:Ne,action:J??void 0},enabled:v,onEnabledChange:S,enabledLockedReason:y?i("st.computer.verdict.hostLocked"):void 0,saving:_.saving,saved:_.saved,defaultOn:g===void 0?void 0:{checked:g.default_on,locked:g.unresolved||g.host_locked},onDefaultOnChange:G=>{C.run(async()=>{await t.patchConfig({optional_capabilities:{defaults:{computer:G}}}),await o.invalidateQueries({queryKey:["config",n]})})},defaultOnSaving:C.saving,attrs:{enabled:"data-computer-control-enabled",verdict:"data-computer-verdict",enabledSwitch:"data-computer-enabled-switch",defaultOn:"data-capability-default-computer"},children:[N?e.jsx("p",{className:"text-[12px] text-amber-ink","data-computer-toolpolicy-partial":!0,children:i("st.computer.toolPolicyPartial")}):null,e.jsx(pe,{feedback:_.error??C.error})]})}),e.jsxs(Me,{id:"st-card-computer-mcp",title:i("st.computer.connectionsTitle"),actions:e.jsx(nD,{}),children:[e.jsx(aD,{platform:Ee,planBinary:ne?.plan?.destination,summary:we,footer:Ee==="win32"?e.jsx(cD,{scopeId:n}):null}),e.jsx(et,{summary:i("st.computer.advanced"),"data-computer-advanced-fold":!0,children:e.jsxs("div",{className:"space-y-6 pt-1",children:[e.jsxs("div",{className:"space-y-2",id:"st-card-computer-machine","data-settings-card":"st-card-computer-machine",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",id:"st-card-computer-setup","data-settings-card":"st-card-computer-setup",children:[e.jsx("span",{className:"text-ink-soft",id:"computer-machine-label",children:a??i("st.computer.machineLabel")}),e.jsx("span",{className:"font-mono text-ink","data-computer-platform":!0,"aria-labelledby":"computer-machine-label",children:me}),e.jsx("span",{className:"text-ink-faint","data-computer-bundled-executor-label":!0,children:i("st.computer.bundledExecutorLabel")}),d.isPending?e.jsx("span",{className:"text-ink-faint",role:"status","data-computer-state":"detecting",children:i("st.computer.state.detecting")}):d.isError||ne===void 0?e.jsx("span",{className:"text-danger","data-computer-state":"failed",children:i("st.computer.state.failed")}):e.jsxs("span",{className:"text-ink-soft","data-computer-state":ne.state,children:[i(rD[ne.state]),ne.version===void 0?null:e.jsx("span",{className:"font-mono text-ink-faint","data-computer-version":!0,children:` v${ne.version}`})]}),e.jsx("button",{type:"button",className:`${Q} ml-auto`,"data-computer-check-btn":!0,disabled:V,onClick:()=>{Ie()},children:i(V?"st.computer.checking":"st.computer.recheckButton")})]}),d.isError?e.jsx(De,{error:d.error}):null,c.isError?e.jsx(De,{error:c.error}):null,ne!==void 0&&ne.install.running?e.jsxs("p",{className:"flex items-center gap-2 text-[12px] leading-4 text-ink-faint",role:"status","data-computer-installing":!0,children:[e.jsx("span",{className:"status-dot-busy inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-ink-soft"}),ne.install.step??i("st.computer.installing"),ne.install.percent===void 0?null:` · ${Math.round(ne.install.percent)}%`]}):null,ee!==void 0?e.jsx(pe,{feedback:{tone:"error",text:ee}}):null,e.jsx(pe,{feedback:re}),ne?.state==="ready"&&Ee==="darwin"?e.jsx(he,{children:i("st.computer.macPermissions")}):null,ne!==void 0?e.jsxs(et,{summary:i("st.computer.details"),"data-computer-steps":!0,children:[e.jsx("ul",{className:"space-y-1",children:ne.steps.map(G=>e.jsxs("li",{className:"text-[11px] text-ink-soft","data-computer-step":G.id,"data-computer-step-kind":G.optional===!0?"optional":"required",children:[gf[G.id]===void 0?G.id:i(gf[G.id])," · ",G.optional===!0?`${i("st.plugins.optional")} · `:"",i(`st.plugins.runtimeStepState.${G.state}`),G.detail===void 0?"":` · ${G.detail}`]},G.id))}),ne.install.note===void 0?null:e.jsx("p",{className:"text-[11px] text-ink-soft","data-computer-install-note":!0,children:ne.install.note}),ne.state==="ready"?e.jsx("p",{children:i("st.computer.installedHint")}):null,ne.state==="ready"&&K?e.jsx("p",{children:i("st.computer.optionalUnverified")}):null,e.jsx("p",{children:a===null?i("st.computer.machineHint"):i("st.computer.machineHintSsh",{label:a})})]}):null]}),e.jsx("div",{id:"st-card-computer-preference","data-settings-card":"st-card-computer-preference",children:u.isPending&&u.data===void 0?e.jsxs("p",{className:"flex items-center gap-2 text-[12px] leading-4 text-ink-faint",role:"status","data-computer-preference-state":"loading",children:[e.jsx("span",{className:"status-dot-busy inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-ink-soft"}),i("st.computer.preferenceLoading")]}):u.isError&&u.data===void 0?e.jsxs("div",{className:"space-y-2","data-computer-preference-state":"failed",children:[e.jsx("p",{className:"text-[12px] text-danger",role:"alert",children:i("st.computer.preferenceLoadFailed")}),e.jsx(De,{error:u.error}),e.jsx("button",{type:"button",className:Q,"data-computer-preference-retry":!0,onClick:()=>{u.refetch()},children:i("common.retry")})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{children:e.jsx(ge,{label:i("st.computer.preferenceLabel"),labelId:"computer-preference-label",help:i("st.computer.preferenceHint"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(He,{choices:q,value:X.activePreference,onChange:X.choosePreference,disabled:X.isOverriddenByHigherSource||X.preferenceSaving,ariaLabelledBy:"computer-preference-label",dataAttr:"data-computer-preference-choice"}),X.preferenceSource!=="default"?e.jsx("span",{className:"inline-flex items-center rounded bg-ink/[0.05] px-1.5 py-0.5 text-[11px] text-ink-soft","data-computer-preference-source":X.preferenceSource,children:i("st.computer.sourceTag",{source:i(hc[X.preferenceSource]??"st.computer.source.default")})}):null,X.preferenceSource==="home"&&!X.isOverriddenByHigherSource?e.jsx("button",{type:"button",className:Q,"data-computer-preference-reset":!0,disabled:X.preferenceSaving,onClick:()=>{X.resetToInherited()},children:i("st.computer.restoreInherit")}):null,e.jsx(ot,{saving:X.preferenceSaving,saved:X.isPreferenceSaved})]})})}),X.isOverriddenByHigherSource?e.jsx("p",{className:"text-[12px] text-ink-soft","data-computer-preference-override-notice":!0,children:i("st.computer.sourceOverridden",{source:i(hc[X.preferenceSource]??"st.computer.source.default")})}):null,u.isError&&u.data!==void 0?e.jsx(De,{error:u.error}):null,e.jsx(pe,{feedback:X.preferenceFeedback})]})})]})})]}),B&&ne?.plan!==void 0?e.jsx(Xe,{open:!0,overlayId:"confirm-computer-install",title:i("st.computer.installConfirmTitle"),body:i("st.computer.installConfirmBody"),consequences:[`v${ne.plan.artifact.version} · ${ne.plan.artifact.url}`,`SHA-256 ${ne.plan.artifact.sha256}`,ne.plan.destination,ne.plan.note],confirmLabel:i("st.computer.installButton"),tone:"default",busy:Y,onCancel:()=>{le(!1)},onConfirm:()=>{te(ne)}}):null]})}function cD({scopeId:t}){const{client:s}=be(),{t:n,locale:a}=D(),i=Oe(),r=s,[o,l]=x.useState(!1),[c,d]=x.useState(""),[u,p]=x.useState(""),[h,b]=x.useState(!1),[m,f]=x.useState(null),g=je({queryKey:["computer-windows-mcp",t],queryFn:async()=>l_.parse(await r.memoryRequest("GET","/computer/windows-mcp")),enabled:o&&typeof r.memoryRequest=="function",staleTime:6e4}),v=async()=>{if(typeof r.memoryRequest!="function")return;const y=c.trim(),w=u.trim();if(!(y===""||w===""||h)){b(!0),f(null);try{const N=c_.parse(await r.memoryRequest("POST","/computer/windows-mcp/register",{body:{python:y,configPath:w,version:"0.8.8"}}));await i.invalidateQueries({queryKey:Ii(t)}),await i.invalidateQueries({queryKey:["mcp-servers"]}),f({tone:"success",text:n(N.result==="existing-mcp-config-reused"?"st.computer.windowsMcp.reused":"st.computer.windowsMcp.registered",{name:N.name})})}catch(N){f({tone:"error",text:oe(a,N)})}finally{b(!1)}}};return e.jsxs("details",{className:"text-[12px] text-ink-soft","data-computer-windows-mcp-register":!0,open:o||void 0,children:[e.jsxs("summary",{className:"-ml-1 inline-flex min-h-7 cursor-pointer list-none select-none items-center gap-1 rounded px-1 font-medium text-ink-soft outline-none transition-colors hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden",onClick:y=>{y.preventDefault(),l(w=>!w)},children:[e.jsx(de,{name:"chevron",size:12,className:`shrink-0 text-ink-faint transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${o?"rotate-90":""}`}),n("st.computer.windowsMcp.registerSummary")]}),e.jsx("div",{className:"mt-1.5 space-y-1.5 leading-relaxed",children:e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsx(he,{children:n("st.computer.windowsMcp.registerHint")}),g.data!==void 0?e.jsxs("p",{className:"font-mono text-[11px] text-ink-faint","data-computer-windows-mcp-plan":!0,children:["Windows-MCP v",g.data.version," · Python ",g.data.python," · ",g.data.licenses.map(y=>`${y.name} (${y.license})`).join(", ")]}):null,e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:"computer-windows-mcp-python",children:n("st.computer.windowsMcp.pythonLabel")}),e.jsx("input",{id:"computer-windows-mcp-python",className:`${Ce} font-mono`,"data-computer-windows-mcp-python":!0,value:c,spellCheck:!1,autoComplete:"off",placeholder:n("st.computer.windowsMcp.pythonPlaceholder"),disabled:h,onChange:y=>{d(y.target.value)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:"computer-windows-mcp-config",children:n("st.computer.windowsMcp.configLabel")}),e.jsx("input",{id:"computer-windows-mcp-config",className:`${Ce} font-mono`,"data-computer-windows-mcp-config":!0,value:u,spellCheck:!1,autoComplete:"off",placeholder:n("st.computer.windowsMcp.configPlaceholder"),disabled:h,onChange:y=>{p(y.target.value)}})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx("button",{type:"button",className:Q,"data-computer-windows-mcp-submit":!0,disabled:h||c.trim()===""||u.trim()==="",onClick:()=>{v()},children:n(h?"st.computer.windowsMcp.registering":"st.computer.windowsMcp.registerButton")})}),e.jsx(pe,{feedback:m})]})})]})}const dD={idle:"st.browser.state.idle",connecting:"st.browser.state.connecting",ready:"st.browser.state.ready",running:"st.browser.state.running",stopping:"st.browser.state.stopping",disconnected:"st.browser.state.disconnected",failed:"st.browser.state.failed",unconfirmed:"st.browser.state.unconfirmed",requires_action:"st.browser.status.requires_action",unsupported:"st.browser.status.unsupported",disabled:"st.browser.state.disabled"};function uD(t,s){const n=dD[s];return n===void 0?s:t(n)}function pD(t){return t==="failed"?"text-danger":t==="unconfirmed"?"text-amber-ink":t==="ready"||t==="running"?"text-ink-soft":"text-ink-faint"}function mD(t){return t==="failed"?"bg-danger":t==="unconfirmed"?"bg-amber-rule":t==="ready"||t==="running"?"bg-ink-soft":t==="connecting"||t==="stopping"?"status-dot-busy bg-ink-soft":"bg-hairline-strong"}function Mk({state:t,compact:s=!1}){const{t:n}=D();return e.jsxs("span",{"data-browser-state":t,className:`inline-flex shrink-0 items-center gap-1.5 text-[12px] ${pD(t)}`,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${mD(t)}`}),e.jsx("span",{className:s?"sr-only":"",children:uD(n,t)})]})}function xD(){const{t}=D();return e.jsxs("div",{className:"space-y-1.5","data-browser-other":!0,children:[e.jsx("p",{className:"max-w-[62ch] text-[12px] text-ink-faint",children:t("st.browser.otherHint")}),e.jsx(_t,{to:"/settings/plugins",className:"inline-block text-[12px] text-selected-ink hover:underline","data-browser-webbridge-link":!0,children:t("st.browser.other.webbridge.action")})]})}function hD({id:t,type:s,status:n}){const{t:a,locale:i}=D(),{client:r,scopeId:o}=be(),[l,c]=x.useState(!1),[d,u]=x.useState(!1),[p,h]=x.useState(!1),[b,m]=x.useState(""),f=pa(i,n.checkedAt),g=gn.has(n.state),v=je({queryKey:Vt.tabs(o,t,n.generation),queryFn:()=>St(r).tabs(t),enabled:l&&g,staleTime:5e3}),y=je({queryKey:Vt.catalog(o,t,n.generation,p),queryFn:()=>St(r).catalog(t,{includeSchema:p}),enabled:l&&d,staleTime:6e4}),w=y.data?.capabilities??[],N=b.trim().toLowerCase(),_=N===""?[]:w.filter(k=>`${k.name} ${k.description} ${k.group}`.toLowerCase().includes(N)),C=new Map;for(const k of w)C.set(k.group,(C.get(k.group)??0)+1);const S=25;return e.jsxs(et,{summary:a("st.browser.runtimeTitle"),"data-browser-runtime-tree":!0,onToggle:k=>{c(k.currentTarget.open)},children:[e.jsxs("dl",{className:"grid grid-cols-[minmax(0,7rem)_minmax(0,1fr)] gap-x-4 gap-y-1",children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.executionHost")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft","data-browser-execution-host":!0,children:n.executionHost}),e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.ownership")}),e.jsx("dd",{className:"text-ink-soft","data-browser-ownership":n.ownership??"unknown",children:s==="kimi-webbridge"||s==="webbridge-command"?a("st.browser.ownership.webbridge"):n.ownership===void 0?a("st.browser.ownership.unknown"):n.ownership==="managed-profile"?a("st.browser.ownership.managedProfile"):a("st.browser.ownership.externalBrowser")}),n.runtimeSession===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.runtimeSession")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft","data-browser-runtime-session":!0,children:n.runtimeSession})]}),n.profilePath===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.resolvedProfile")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft","data-browser-resolved-profile":!0,children:n.profilePath})]}),e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.generation")}),e.jsx("dd",{className:"text-ink-soft tabular-nums","data-browser-generation":!0,children:n.generation}),e.jsx("dt",{className:"text-ink-faint",children:a(s==="kimi-webbridge"||s==="webbridge-command"?"st.browser.detail.bridgeVersion":"st.browser.detail.driverVersion")}),e.jsxs("dd",{className:"text-ink-soft","data-browser-driver-version":!0,children:[n.driverVersion??a("st.browser.detail.driverUnknown"),s==="kimi-webbridge"||s==="webbridge-command"?null:e.jsxs("span",{className:"text-ink-faint",children:[" · ",a("st.browser.detail.driverRequirement",{version:fd,markers:bd})]})]}),e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.checkedAt")}),e.jsx("dd",{className:"text-ink-soft",children:f??a("st.browser.detail.checkedNever")}),n.currentCall===void 0?null:e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:a("st.browser.detail.currentCall")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft","data-browser-current-call":!0,title:`${n.currentCall.tool} · ${n.currentCall.sessionId} · ${n.currentCall.agentId}${n.currentCall.tab===void 0?"":` · ${n.currentCall.tab}`}`,children:`${n.currentCall.tool} · ${Od(n.currentCall.sessionId)} · ${At(n.currentCall.agentId)}${n.currentCall.tab===void 0?"":` · ${At(n.currentCall.tab)}`}`})]})]}),e.jsxs("div",{className:"space-y-1","data-browser-tabs-section":!0,children:[e.jsxs("p",{className:"flex items-baseline gap-x-2 font-medium",children:[a("st.browser.tabs.title"),l&&v.data!==void 0?e.jsx("span",{className:"font-mono text-[11px] tabular-nums text-ink-faint","data-browser-tabs-count":!0,children:v.data.tabs.length}):null]}),g?null:e.jsx("p",{className:"max-w-[62ch]","data-browser-tabs-notlive":!0,children:a("st.browser.tabs.notLive")}),g&&v.isPending?e.jsx("p",{role:"status",children:a("st.browser.tabs.loading")}):null,g&&v.isError?e.jsx(De,{error:v.error}):null,g&&v.data!==void 0&&v.data.tabs.length===0?e.jsx("p",{className:"max-w-[62ch]","data-browser-tabs-empty":!0,children:a("st.browser.tabs.empty")}):null,g&&v.data!==void 0&&v.data.tabs.length>0?e.jsx("ul",{className:"space-y-1","data-browser-tabs":!0,children:v.data.tabs.map(k=>e.jsxs("li",{"data-browser-tab":k.tabId,className:"min-w-0",children:[e.jsxs("span",{className:"flex min-w-0 items-baseline gap-x-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink-soft",title:k.title??k.url??k.targetId,children:k.title??k.url??a("st.browser.tabs.untitled")}),k.active===!0?e.jsx(Yt,{tone:"accent",children:a("st.browser.tabs.active")}):null,k.label===void 0?null:e.jsx(Yt,{children:k.label})]}),e.jsx("span",{className:"block truncate font-mono text-[11px] text-ink-faint",title:k.targetId,children:At(k.targetId)})]},k.tabId))}):null]}),e.jsxs("div",{className:"space-y-1.5","data-browser-catalog-section":!0,children:[e.jsx("p",{className:"font-medium",children:a("st.browser.catalog.title")}),d?null:e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"max-w-[62ch]",children:a(s==="kimi-webbridge"||s==="webbridge-command"?"st.browser.catalog.readHintWebbridge":g?"st.browser.catalog.readHint":"st.browser.catalog.readHintIdle")}),e.jsx("button",{type:"button",className:Q,"data-browser-catalog-read":!0,onClick:()=>{u(!0)},children:a("st.browser.catalog.read")})]}),d&&y.isPending?e.jsx("p",{role:"status",children:a("st.browser.catalog.loading")}):null,d&&y.isError?e.jsx(De,{error:y.error}):null,d&&y.data!==void 0?e.jsxs("div",{className:"space-y-1.5","data-browser-catalog":!0,children:[e.jsxs("p",{className:"text-ink-soft",children:[e.jsx("span",{className:"font-mono tabular-nums text-ink","data-browser-catalog-count":!0,children:y.data.backendToolCount})," ",a("st.browser.catalog.backendCount"),e.jsxs("span",{className:"text-ink-faint",children:[" · ",a("st.browser.catalog.isolation"),i==="zh"?":":": ",e.jsx("span",{"data-browser-catalog-isolation":!0,title:y.data.contextIsolation,children:bD(a,y.data.contextIsolation)})]})]}),w.length===0?e.jsx("p",{"data-browser-catalog-empty":!0,children:a("st.browser.catalog.empty")}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:`${Ce} max-w-[22rem]`,value:b,spellCheck:!1,autoComplete:"off","aria-label":a("st.browser.catalog.searchLabel"),placeholder:a("st.browser.catalog.searchPlaceholder"),"data-browser-catalog-search":!0,onChange:k=>{m(k.target.value)}}),N===""?e.jsx("ul",{className:"flex flex-wrap gap-1.5","data-browser-catalog-groups":!0,children:[...C].toSorted((k,j)=>j[1]-k[1]||k[0].localeCompare(j[0])).map(([k,j])=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-browser-catalog-group":k,className:"inline-flex items-baseline gap-1.5 rounded-md px-2 py-0.5 text-[12px] text-ink-soft hover:bg-ink/[0.05] hover:text-ink",onClick:()=>{m(k)},children:[vf(a,k),e.jsx("span",{className:"font-mono tabular-nums text-[11px] text-ink-faint",children:j})]})},k))}):null,N!==""&&_.length===0?e.jsx("p",{"data-browser-catalog-nomatch":!0,children:a("st.browser.catalog.noMatch")}):null,_.length>0?e.jsx("ul",{className:"space-y-1.5","data-browser-catalog-hits":!0,children:_.slice(0,S).map(k=>e.jsxs("li",{"data-browser-capability":k.name,className:"min-w-0",children:[e.jsxs("p",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"break-all font-mono text-[12px] text-ink",children:k.name}),e.jsx(Yt,{children:vf(a,k.group)}),e.jsx("span",{className:"text-[11px] text-ink-faint",children:fD(a,k.surface)})]}),e.jsx("p",{className:"max-w-[62ch] text-ink-soft",children:k.description}),k.inputSchema===void 0?null:e.jsxs("details",{"data-browser-catalog-schema":k.name,children:[e.jsx("summary",{className:"cursor-pointer select-none text-[11px] text-ink-faint hover:text-ink",children:a("st.browser.catalog.schema")}),e.jsx("pre",{className:"mt-1 max-h-40 overflow-auto whitespace-pre-wrap break-all rounded-sm bg-ink/[0.03] p-2 font-mono text-[11px] text-ink-soft",children:JSON.stringify(k.inputSchema,null,2)})]})]},k.name))}):null,_.length>S?e.jsx("p",{className:"text-ink-faint",children:a("st.browser.catalog.more",{count:_.length-S})}):null,e.jsx("div",{"data-browser-catalog-schema-option":!0,children:e.jsx(Be,{label:a("st.browser.catalog.withSchemas"),checked:p,onChange:k=>{h(k)}})})]})]}):null]})]})}function vf(t,s){const n=vD[s];return n===void 0?s:t(n)}function fD(t,s){const n=yD[s];return n===void 0?s:t(n)}function bD(t,s){const n=gD[s];return n===void 0?s:t(n)}const gD={"opaque-context-through-window":"st.browser.catalog.isolation.window","official-extension-tab-ids":"st.browser.catalog.isolation.officialTabs","main-frame-only":"st.browser.catalog.isolation.mainFrame"},vD={page:"st.browser.group.page",network:"st.browser.group.network",state:"st.browser.group.state",debug:"st.browser.group.debug",input:"st.browser.group.input",react:"st.browser.group.react"},yD={operation:"st.browser.surface.operation",lifecycle:"st.browser.surface.lifecycle",administrative:"st.browser.surface.administrative"},Pi={"kimi-webbridge":"st.browser.sourceName.kimi-webbridge","independent-browser":"st.browser.sourceName.independent-browser","codex-browser":"st.browser.sourceName.codex-browser","ego-lite":"st.browser.sourceName.ego-lite"};function Ko(){const{client:t,scopeId:s}=be(),n=Oe(),a=je({queryKey:["config",s],queryFn:()=>t.getConfig(),staleTime:3e4}),i=je({queryKey:Vt.connections(s),queryFn:()=>St(t).list(),staleTime:1e4}),r=i.data,o=a.data?.browser_control,l=r?.connections??[],c=i.data?.defaultBrowser??"",d=r?.allowedBrowsers??o?.allowedBrowsers,u=r?.allowedBrowsersConfigured===!0||o?.allowedBrowsersConfigured===!0,p=r?.disabledSources??o?.disabledSources??[],h=fg(a.data),b=f_(a.data),m=k=>bg(k.type,k.id),f=k=>k===void 0||!p.includes(k),g=k=>k===void 0||k.enabled===!1?!1:u&&d!==void 0?d.includes(k.id):!0,v=k=>nu(k,u,d,p),y=gg(l,u,d,p),w=async()=>{await n.invalidateQueries({queryKey:Vt.connections(s)}),await n.invalidateQueries({queryKey:Vt.presets(s)}),await n.invalidateQueries({queryKey:["config",s]})},N=async(k,j,T)=>{const A=St(t);k.type==="agent-browser-profile"?await A.upsert(k.id,{type:"agent-browser-profile",name:k.name,enabled:j,profilePath:k.profilePath,executablePath:k.executablePath,headed:k.headed,driverPath:k.driverPath}):k.type==="agent-browser-cdp"?await A.upsert(k.id,{type:"agent-browser-cdp",name:k.name,enabled:j,endpoint:{action:"keep"},driverPath:k.driverPath}):k.type==="kimi-webbridge"?await A.upsert(k.id,{type:"kimi-webbridge",name:k.name,enabled:j,driverPath:k.driverPath}):k.type==="codex-extension"?await A.upsert(k.id,{type:"codex-extension",name:k.name,enabled:j,runtimeRoot:k.runtimeRoot??"",browserId:k.browserId??T??k.id}):k.type==="ego-lite"&&await A.upsert(k.id,{type:"ego-lite",name:k.name,enabled:j,...k.cliPath!==void 0?{cliPath:k.cliPath}:{},...k.profileId!==void 0?{profileId:k.profileId}:{},...k.serverName!==void 0?{serverName:k.serverName}:{}})};return{configQuery:a,connectionsQuery:i,connections:l,defaultBrowser:c,disabledSources:p,toolPolicyDenied:h,toolPolicyPartial:b,allowedConfigured:u,allowedBrowsers:d,sourceOf:m,sourceEnabled:f,isChosen:g,isEffective:v,effectiveCount:y,writeAllowed:async(k,j,T={})=>{const A=new Set(l.map(I=>I.id));T.justCreated===!0&&A.add(k);const P=(u&&d!==void 0?[...d]:l.filter(I=>I.enabled).map(I=>I.id)).filter(I=>A.has(I)),R=j?[...new Set([...P,k])]:P.filter(I=>I!==k);await t.patchConfig({browser_control:{allowed_browsers:R}});const L=l.find(I=>I.id===k);L!==void 0&&L.enabled!==j&&await N(L,j,T.fallbackBrowserId),await w()},writeDefault:async(k,j)=>{await St(t).setDefault(j?void 0:k),await n.invalidateQueries({queryKey:Vt.connections(s)})},writeSourceEnabled:async(k,j)=>{if(j){const T=p.filter(A=>A!==k);await t.patchConfig({browser_control:{disabled_sources:T}})}else{const T=u&&d!==void 0?[...d]:l.filter(P=>P.enabled).map(P=>P.id),A=[...new Set([...p,k])];await t.patchConfig({browser_control:{disabled_sources:A,...u?{}:{allowed_browsers:T}}})}await w()},invalidate:w}}function yf({children:t}){return e.jsxs("p",{className:"anim-enter flex items-center gap-2 text-[12px] leading-4 text-ink-faint",children:[e.jsx("span",{className:"status-dot-busy inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-ink-soft"}),t]})}function kD(t,s){const n=t instanceof Error?t.message:String(t);return/approval/i.test(n)&&/not_?found|40401/i.test(n)?!0:oe(s,t)===oe(s,new Error("approval.not_found"))}function jD({error:t,onRetry:s}){const{t:n,locale:a}=D();return kD(t,a)?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2","data-webbridge-approval-expired":!0,children:[e.jsx("p",{className:"text-[12px] text-ink-soft",children:n("st.webbridge.approvalExpired")}),e.jsx("button",{type:"button",className:Q,"data-plugins-retry":!0,onClick:s,children:n("st.webbridge.reconnect")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:t}),e.jsx("button",{type:"button",className:Q,"data-plugins-retry":!0,onClick:s,children:n("common.retry")})]})}const wD={"daemon-binary":"st.plugins.runtimeStep.daemon-binary",daemon:"st.plugins.runtimeStep.daemon",skill:"st.plugins.runtimeStep.skill",extension:"st.plugins.runtimeStep.extension",detect:"st.plugins.runtimeStep.detect"};function ND(t){if(t===void 0||t==="")return!1;try{const s=new URL(t);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}}function vd(){const{client:t}=be(),{t:s,locale:n}=D(),[a,i]=x.useState(null),[r,o]=x.useState(null),[l,c]=x.useState(!1),d=x.useContext(Ia),u=x.useContext(Mn);x.useEffect(()=>{u?.("st-card-webbridge")},[u]);const p=je({queryKey:["capability","kimi-webbridge"],queryFn:()=>t.getCapability("kimi-webbridge"),refetchInterval:w=>w.state.data?.install.running?1e3:!1}),h=p.data,b=async w=>{const N=w.plan?.artifact.sha256;if(N!==void 0){i(null),c(!0),o(null);try{await t.installCapability("kimi-webbridge",N),await p.refetch(),o({tone:"info",text:s("st.plugins.runtimeStarted")})}catch(_){o({tone:"error",text:oe(n,_)})}finally{c(!1)}}},m=h?.steps??[],f=m.filter(w=>w.optional!==!0&&w.state!=="ok"),g=m.some(w=>(w.id==="daemon"||w.id==="skill")&&(w.state==="missing"||w.state==="failed")),v=m.some(w=>w.state==="failed"),y=h!==void 0&&h.state!=="unsupported"&&(h.state==="not_installed"||g||v);return e.jsxs("div",{id:"st-card-webbridge","data-settings-card":"st-card-webbridge","data-webbridge-readiness":!0,className:`mt-2.5 scroll-mt-4 space-y-2 text-[12px] ${d==="st-card-webbridge"?"settings-card-flash":""}`,children:[p.isPending?e.jsx(yf,{children:s("st.plugins.loading")}):p.isError?e.jsx(jD,{error:p.error,onRetry:()=>{p.refetch()}}):h!==void 0?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsxs("p",{className:"text-ink-soft",children:[e.jsx("span",{className:"text-ink",children:s("st.plugins.runtimeTitle")}),e.jsx("span",{"data-webbridge-state":h.state,children:` · ${s(`st.plugins.runtimeState.${h.state}`)}`}),h.state==="partial"&&f.length>0?e.jsx("span",{className:"text-ink-faint","data-webbridge-blocking":!0,children:` · ${s("st.plugins.runtimeState.partialHint",{items:f.map(w=>s(wD[w.id]??"st.plugins.runtimeStep.detect")).join("、")})}`}):null]}),h.install.running?e.jsx(yf,{children:h.install.step??s("st.plugins.runtimeStarted")}):null,h.install.error?e.jsx(pe,{feedback:{tone:"error",text:h.install.error}}):null,e.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,onClick:()=>{p.refetch()},"data-webbridge-check":!0,children:s("st.plugins.checkHealth")}),h.plan!==void 0&&y?e.jsx("button",{type:"button",className:Q,"data-webbridge-prepare":!0,disabled:l||h.install.running,onClick:()=>{i(h)},children:h.install.error||m.some(w=>w.state==="failed")?s("st.plugins.retryRuntime"):s("st.plugins.prepareRuntime")}):null,ND(h.plan?.browserExtensionUrl)?e.jsx(oa,{className:"inline-block text-[12px] text-selected-ink hover:underline",href:h.plan.browserExtensionUrl,"data-webbridge-extension":!0,children:s("st.plugins.browserExtension")}):null]})]}):null,e.jsx(pe,{feedback:r}),a?.plan!==void 0?e.jsx(Xe,{open:!0,overlayId:"confirm-webbridge-runtime",title:s("st.plugins.runtimeConfirmTitle"),body:s("st.plugins.runtimeConfirmBody"),consequences:[`${a.plan.artifact.version} · ${a.plan.artifact.url}`,`SHA-256 ${a.plan.artifact.sha256}`,a.plan.destination],confirmLabel:s("st.plugins.prepareRuntime"),onCancel:()=>{i(null)},onConfirm:()=>{b(a)}}):null]})}const Ok={preparing:{text:"st.browser.route.preparing",dot:"status-dot-busy bg-ink-soft"},"needs-action":{text:"st.browser.route.needsAction",dot:"bg-hairline-strong"},ready:{text:"st.browser.route.ready",dot:"bg-selected-ink"},connected:{text:"st.browser.route.connected",dot:"bg-success"},unsupported:{text:"st.browser.route.unsupported",dot:"bg-ink-soft"},failed:{text:"st.browser.route.failed",dot:"bg-danger"},"forced-off":{text:"st.browser.route.forcedOff",dot:"bg-danger"},blocked:{text:"st.browser.route.blocked",dot:"bg-danger"},external:{text:"st.browser.route.external",dot:"bg-ink-soft"}},SD={chrome:"st.browser.store.chrome",edge:"st.browser.store.edge",documentation:"st.browser.store.docs"},CD={"daemon-binary":"st.browser.step.daemonBinary",daemon:"st.browser.step.daemon",skill:"st.browser.step.skill",plugin:"st.browser.step.plugin",extension:"st.browser.step.extension",detect:"st.browser.step.detect",compatibility:"st.browser.step.compatibility",feature:"st.browser.step.feature","desktop-app":"st.browser.step.desktopApp",driver:"st.browser.step.driver",chrome:"st.browser.step.chrome",install:"st.browser.step.install"},_D={feature_disabled:"st.browser.reason.featureDisabled",version_mismatch:"st.browser.reason.versionMismatch",external_app_required:"st.browser.reason.externalApp",connection_conflict:"st.browser.reason.connectionConflict",connection_disabled:"st.browser.reason.connectionDisabled",extension_not_connected:"st.browser.reason.extensionNotConnected",artifact_missing:"st.browser.reason.artifactMissing",artifact_mismatch:"st.browser.reason.artifactMismatch",mismatch:"st.browser.reason.artifactMismatch",choose_connection:"st.browser.reason.chooseConnection",approval_unproven:"st.browser.reason.approvalUnproven",pipe_discovery_failed:"st.browser.reason.pipeDiscoveryFailed",ego_installed:"st.browser.reason.egoInstalled",ego_onboarding:"st.browser.reason.egoOnboarding",ego_choose_cli:"st.browser.reason.egoChooseCli",ego_ready:"st.browser.reason.egoReady",disk_updated:"st.browser.route.done.updateDisk",disk_updated_running_unchanged:"st.browser.route.done.updateRunningUnchanged"};function ED(t){return t.state==="preparing"?"st.browser.setup.detecting":t.state==="connected"?"st.browser.reason.egoAdmitted":t.reason==="ego_onboarding"?"st.browser.reason.egoOnboarding":t.reason==="ego_installed"?"st.browser.reason.egoInstalled":t.reason==="ego_choose_cli"?"st.browser.reason.egoChooseCli":t.reason==="ego_ready"||t.state==="ready"?"st.browser.reason.egoReady":t.state==="failed"?"st.browser.reason.egoFailed":"st.browser.reason.egoMissing"}function TD(t){return t.state==="preparing"||t.state==="failed"||t.error!==void 0||Ck(t)!==void 0?!0:Wu(t)==="connected"?!1:Vu(t)!==void 0||(t.candidates??[]).length>0}function Dk({preset:t,open:s,onOpenChange:n,bare:a=!1,children:i}){const{t:r,locale:o}=D(),{client:l,scopeId:c}=be(),d=Oe(),u=Ko(),[p,h]=x.useState(null),[b,m]=x.useState(null),[f,g]=x.useState(!1),[v,y]=x.useState(t.browserId??""),[w,N]=x.useState("");x.useEffect(()=>{y(t.browserId??"")},[t.browserId]),x.useEffect(()=>{N(G=>t.cliPaths!==void 0&&t.cliPaths.includes(G)?G:"")},[t.cliPaths]);const{connections:_}=u,C=t.preset in Pi?r(Pi[t.preset]):t.displayName,S=u.sourceEnabled(t.preset),k=_.filter(G=>u.sourceOf(G)===t.preset),j=k.filter(G=>u.isEffective(G)).length,T=x.useMemo(()=>{if(!S)return[];const G=[];for(const Le of t.candidates??[])(t.preset==="codex-browser"?Sk(_,Le.browserId):_.find(Fe=>Fe.id===t.connectionId&&t.browserId===Le.browserId))===void 0&&G.push({id:Le.browserId,browserId:Le.browserId,label:Le.browserId});return t.preset==="ego-lite"&&(t.state==="ready"||t.state==="connected")&&k.length===0&&G.push({id:"ego-lite",browserId:"ego-lite",label:r("st.browser.sourceName.ego-lite")}),G},[t,_,k.length,S,r]),A=async G=>{m("source"),h(null);try{await u.writeSourceEnabled(t.preset,G)}catch(Le){h({tone:"error",text:oe(o,Le)})}finally{m(null)}},P=async G=>{m("allow"),h(null);try{let Le,Se=!1;if(t.preset==="ego-lite"){const Fe=await St(l).connectPreset("ego-lite",{});if(Fe.state!=="ready"&&Fe.state!=="connected"||Fe.error!==void 0){h({tone:"error",text:Fe.error??r("st.browser.reason.egoFailed")});return}Le=Fe.connectionId??"ego-lite"}else if(t.preset==="codex-browser"){const Fe=HO(_,G.browserId);if(Fe===void 0){h({tone:"error",text:r("st.browser.reason.connectionConflict")});return}const ye=await St(l).connectPreset(t.preset,{connectionId:Fe,browserId:G.browserId}),ze=ye.reason==="connection_conflict"||ye.reason==="connection_disabled"||ye.reason==="choose_connection";if(Se=ye.state==="needs_user_action"&&ye.reason==="approval_unproven",!((ye.state==="ready"||ye.state==="connected"||Se)&&!ze&&ye.error===void 0&&ye.connectionId!==void 0)){h({tone:"error",text:ye.error??(ye.reason==="connection_conflict"?r("st.browser.reason.connectionConflict"):r("st.browser.outcome.connectIncomplete"))});return}Le=ye.connectionId}else{h({tone:"error",text:r("st.browser.reason.chooseConnection")});return}if(Le===void 0)return;await u.writeAllowed(Le,!0,{fallbackBrowserId:G.browserId,justCreated:!0}),Se&&h({tone:"info",text:r("st.browser.route.done.savedApprovalUnproven")})}catch(Le){h({tone:"error",text:oe(o,Le)})}finally{m(null)}},R=async()=>{for(const G of T)await P(G)},[L,I]=x.useState(!1),$=Wu(t),E=Ok[$],M=Ys(t,"prepare"),z=Ys(t,"connect"),H=Ys(t,"cancel"),U=Ys(t,"open"),X=Ys(t,"update"),q=Ys(t,"shortcut"),F=Ys(t,"install_extension"),V=Ys(t,"open_instructions"),se=Ck(t),Y=Vu(t),O=t.controlSurface==="external-app",B=t.preset==="ego-lite"||!O,le=G=>r(CD[G]??"st.browser.step.install"),re=G=>{if(G.reason===void 0)return;const Le=_D[G.reason];return Le!==void 0?r(Le):G.reason},ae=se!==void 0,ne=Y!==void 0&&Y.state==="missing",Ee=t.steps.some(G=>G.state==="failed")||t.state==="failed"||t.error!==void 0,ie=Y!==void 0&&Y.id==="feature"&&!ne&&!Ee&&Y.reason!=="feature_forced_off",me=Y!==void 0&&Y.reason==="feature_forced_off",fe=ne||Ee||ie,Ie=Y!==void 0&&(Y.state==="user_action"||Y.id==="feature"),te=!O&&!me&&$!=="connected"&&(ne||Ie||Y!==void 0&&Y.state==="failed"),ee=!O&&!ae&&!ne&&!Ee&&!ie&&!me&&$!=="connected"&&!te,K=GO(t),Z=t.steps.some(G=>G.reason==="version_mismatch")||K?.reason==="version_mismatch",ue=F,Te=V?.url,Ne=()=>d.invalidateQueries({queryKey:Vt.presets(c)}),J=async G=>{m(G),h(null);try{const Le=St(l);let Se;if(G==="prepare")Se=await Le.prepare(t.preset,{consent:!0});else if(G==="connect"){const ye=t.cliPaths!==void 0&&t.cliPaths.length>0?{cliPath:w}:t.candidates!==void 0?{connectionId:t.connectionId??(t.preset==="codex-browser"?"codex-browser":void 0),browserId:v||void 0}:{};Se=await Le.connectPreset(t.preset,ye)}else G==="open"?Se=await Le.openPreset(t.preset,{}):G==="update"?Se=await Le.updatePreset(t.preset,{}):G==="shortcut"?Se=await Le.createShortcut(t.preset,{}):Se=await Le.cancelSetup(t.preset);if(g(!1),await Ne(),(t.preset==="independent-browser"||t.preset==="codex-browser"||t.preset==="ego-lite")&&(G==="connect"||G==="open")&&await d.invalidateQueries({queryKey:Vt.connections(c)}),G==="connect"&&t.preset==="ego-lite"&&(Se?.reason==="ego_choose_cli"||Se?.reason==="ego_onboarding"||Se?.reason==="ego_installed"||Se?.reason==="ego_ready"||Se?.state==="ready"||Se?.state==="connected")){h(null);return}if(Se?.state==="failed"||Se?.error!==void 0){h({tone:"error",text:Se?.error??r("st.browser.route.failed")});return}if(Se?.reason==="connection_disabled"){h({tone:"error",text:Se?.error??r("st.browser.reason.connectionDisabled")});return}if(G==="open"&&Se?.state!=="connected"&&Se?.state!=="ready"){h({tone:"error",text:Se?.error??r("st.browser.route.openFailed")});return}if(G==="connect"){if(Se?.reason==="approval_unproven"&&(Se.state==="needs_user_action"||Se.state==="ready")){h({tone:"info",text:r("st.browser.route.done.savedApprovalUnproven")});return}if(Se?.state!=="connected"&&Se?.state!=="ready"){h({tone:"error",text:Se?.error??r("st.browser.outcome.connectIncomplete")});return}if(Se?.state==="connected"){h(null);return}}if(G==="update"){Se?.reason==="disk_updated_running_unchanged"?h({tone:"info",text:r("st.browser.route.done.updateRunningUnchanged")}):Se?.reason==="disk_updated"?h({tone:"info",text:r("st.browser.route.done.updateDisk")}):h({tone:"info",text:r("st.browser.route.done.update")});return}h({tone:"info",text:r(`st.browser.route.done.${G}`)})}catch(Le){h({tone:"error",text:oe(o,Le)})}finally{m(null)}},_e=e.jsx(Xe,{open:f,overlayId:`confirm-browser-prepare-${t.preset}`,title:r("st.browser.route.confirmTitle",{name:C}),body:r("st.browser.route.confirmBody"),consequences:[r("st.browser.route.consequenceHost",{host:t.executionHost}),...t.skill===void 0?[]:[r("st.browser.route.consequencePlugin",{name:t.skill})],...t.steps.some(G=>G.id==="feature")?[r("st.browser.route.consequenceFeature")]:[],...t.connectionId===void 0?[]:[r("st.browser.route.consequenceConnection",{name:t.connectionId})]],confirmLabel:r("st.browser.route.prepare"),onCancel:()=>{g(!1)},onConfirm:()=>{J("prepare")}}),we=e.jsx(e.Fragment,{children:S?e.jsxs(e.Fragment,{children:[t.preset==="ego-lite"?e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-5 text-ink-soft","data-browser-route-ego-next":!0,children:r(ED(t))}):e.jsx("p",{className:"max-w-[62ch] text-[12.5px] leading-5 text-ink-soft",children:r(`st.browser.route.blurb.${t.preset}`)}),t.preset!=="ego-lite"&&t.preset!=="independent-browser"&&$!=="connected"?e.jsxs("ol",{className:"mt-2 max-w-[62ch] list-decimal space-y-0.5 pl-4 text-[12px] leading-[18px] text-ink-soft marker:text-ink-faint","data-browser-route-steps":t.preset,children:[t.preset==="kimi-webbridge"?e.jsxs(e.Fragment,{children:[e.jsx("li",{children:r("st.browser.route.steps.webbridge.1")}),e.jsx("li",{children:r("st.browser.route.steps.webbridge.2")})]}):t.preset==="codex-browser"?e.jsxs(e.Fragment,{children:[e.jsx("li",{children:r("st.browser.route.steps.codex.1")}),e.jsx("li",{children:r("st.browser.route.steps.codex.2")})]}):null,Te===void 0?null:e.jsx("li",{children:e.jsx(oa,{className:"text-selected-ink hover:underline",href:Te,"data-browser-route-steps-link":!0,children:r("st.browser.route.steps.link")})})]}):null,T.length>0?e.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center gap-x-3 gap-y-2","data-browser-source-items":t.preset,children:[e.jsxs("p",{className:"text-[12.5px] text-ink-soft","data-browser-found-summary":!0,children:[r("st.browser.found.summary",{count:T.length,name:C})," · ",e.jsx("span",{className:"text-ink-faint",children:r("st.browser.found.notSaved")})]}),e.jsx("button",{type:"button",className:Q,"data-browser-allow-all":!0,disabled:b!==null||u.toolPolicyDenied,onClick:()=>{R()},children:r(b==="allow"?"st.browser.found.allowing":"st.browser.found.allowAll")})]}):null,i,ae?e.jsxs("p",{role:"status",className:"mt-2 flex items-baseline gap-2 text-[12px] text-ink-soft","data-browser-route-progress":se.id,children:[e.jsx("span",{children:r("st.browser.route.installing",{step:le(se.id)})}),se.percent===void 0?null:e.jsxs("span",{className:"font-mono tabular-nums text-ink-faint",children:[Math.round(se.percent),"%"]})]}):null,te?e.jsxs("p",{className:"mt-2 max-w-[62ch] text-[12px] leading-[18px] text-ink-soft","data-browser-route-blocker":Y.id,children:[r("st.browser.route.blocking",{step:le(Y.id)}),re(Y)===void 0?"":` ${re(Y)}`]}):null,me?e.jsxs("p",{className:"mt-2 max-w-[62ch] text-[12px] leading-[18px] text-danger","data-browser-route-forced-off":!0,children:[r("st.browser.reason.forcedOff",{step:le(Y.id)}),Y.detail===void 0?null:e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:"text-ink-soft underline underline-offset-2","data-browser-route-forced-off-cause":!0,onClick:()=>{I(!0)},children:r("st.browser.reason.forcedOffCause")})]})]}):null,ee?e.jsx("p",{className:"mt-2 max-w-[62ch] text-[12px] leading-[18px] text-ink-faint","data-browser-route-settled":!0,children:r("st.browser.route.alreadyInstalled")}):null,K===void 0?null:e.jsxs("p",{className:"mt-2.5 max-w-[62ch] border-l-2 border-amber-ink/45 pl-2.5 text-[12px] leading-[18px] text-amber-ink","data-browser-route-warning":K.id,children:[r("st.browser.route.warning",{step:le(K.id)}),re(K)===void 0?"":` ${re(K)}`]}),t.error===void 0?null:e.jsx("p",{role:"alert",className:"mt-2 max-w-[72ch] break-words text-[12px] leading-[18px] text-danger","data-browser-route-error":!0,children:t.error}),t.candidates!==void 0&&t.candidates.length===0?e.jsx("div",{className:"mt-2.5 space-y-1.5","data-browser-candidates-region":!0,children:e.jsx("p",{className:"text-[12px] leading-[18px] text-ink-soft","data-browser-candidates-empty":!0,children:r("st.browser.candidates.empty")})}):null,t.cliPaths!==void 0&&t.cliPaths.length>0?e.jsx("div",{className:"mt-2.5 space-y-1.5","data-browser-cli-paths":!0,children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:"ego-cli-select",className:"text-[12px] font-medium text-ink-soft shrink-0",children:r("st.browser.fieldCliPath")}),e.jsx("div",{className:"min-w-0 max-w-full flex-1 sm:min-w-[240px] sm:flex-none",children:e.jsx(Qe,{id:"ego-cli-select",ariaLabel:r("st.browser.fieldCliPath"),dataAttr:"data-browser-cli-select",choices:t.cliPaths.map(G=>({value:G,label:G})),value:w,emptyText:r("st.browser.route.egoCliPlaceholder"),onChange:G=>{N(G)},disabled:b!==null,variant:"row",mono:!0})})]})}):null,e.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center gap-x-2 gap-y-2",children:[!B||M===void 0||b!==null||ae||$==="connected"||!fe?null:e.jsx("button",{type:"button",className:ie||U!==void 0&&$==="ready"?Q:Ye,"data-browser-route-prepare":!0,disabled:b!==null,onClick:()=>{g(!0)},children:r(b==="prepare"?"st.browser.route.preparing":ie?"st.browser.route.turnOn":"st.browser.route.prepare")}),!B||U===void 0||$!=="ready"&&$!=="connected"&&t.state!=="failed"&&t.error===void 0||b!==null?null:e.jsx("button",{type:"button",className:Ye,"data-browser-route-open":!0,disabled:b!==null,onClick:()=>{J("open")},children:r(b==="open"?"st.browser.route.opening":"st.browser.route.open")}),!B||z===void 0||t.candidates!==void 0||$!=="ready"&&t.state!=="needs_user_action"&&t.state!=="failed"&&t.error===void 0||b!==null?null:e.jsx("button",{type:"button",className:U!==void 0||t.preset==="ego-lite"?Q:Ye,"data-browser-route-connect":!0,disabled:b!==null||t.cliPaths!==void 0&&t.cliPaths.length>0&&w==="",onClick:()=>{J("connect")},children:b==="connect"?r("st.browser.route.connecting"):t.preset==="ego-lite"?r("st.browser.route.checkEgo"):r("st.browser.route.connect")}),Z&&X!==void 0?e.jsx("button",{type:"button",className:Q,"data-browser-route-update":!0,disabled:b!==null,onClick:()=>{J("update")},children:r(b==="update"?"st.browser.route.updating":"st.browser.route.update")}):null,$==="connected"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-success","data-browser-route-connected":!0,children:[e.jsx(de,{name:"check",size:12}),r("st.browser.route.connectedAt",{at:pa(o,t.checkedAt)??r("st.browser.route.connectedNow")})]}):null,H===void 0||b!==null?null:e.jsx("button",{type:"button",className:Q,"data-browser-route-cancel":!0,onClick:()=>{J("cancel")},children:r("st.browser.route.cancel")}),ue?.url===void 0?null:e.jsxs(oa,{className:`${Q} inline-flex items-center gap-1.5`,href:ue.url,"data-browser-route-extension":ue.target??"chrome",children:[e.jsx(de,{name:"external",size:12}),r("st.browser.route.addExtension",{store:r(SD[ue.target??""]??"st.browser.store.chrome")})]}),Te===void 0?null:e.jsx(oa,{className:"inline-flex items-center gap-1 text-[12px] text-selected-ink hover:underline",href:Te,"data-browser-route-instructions":!0,children:t.preset==="ego-lite"?r("st.browser.route.downloadEgo"):r("st.browser.route.instructions")})]}),t.checkedAt===void 0?null:e.jsx("p",{className:"mt-2 text-[11px] text-ink-faint","data-browser-route-checked":!0,children:r("st.browser.route.checkedAt",{at:pa(o,t.checkedAt)??""})}),e.jsx(pe,{feedback:p}),T.length>0||X!==void 0||q!==void 0||t.steps.some(G=>G.detail!==void 0)?e.jsx("div",{className:"mt-2.5",children:e.jsx(et,{summary:r("st.browser.route.advanced"),"data-browser-route-advanced":!0,"data-browser-route-diagnostics":!0,open:L||void 0,onToggle:G=>{I(G.currentTarget.open)},children:e.jsxs("div",{className:"space-y-2 pt-1",children:[T.length===0?null:e.jsx("ul",{className:"space-y-1","data-browser-found-picks":!0,children:T.map(G=>e.jsx("li",{children:e.jsxs("label",{className:"flex min-w-0 cursor-pointer items-center gap-2.5 text-[12px]",children:[e.jsx("input",{type:"checkbox",className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-hairline-strong text-selected-ink focus:ring-0","data-browser-allow-checkbox":G.id,"aria-label":r("st.browser.found.allow",{name:G.label}),checked:!1,disabled:b!==null||u.toolPolicyDenied,onChange:()=>{P(G)}}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink-soft","data-browser-identity":G.browserId,title:G.browserId,children:G.label}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-faint",children:r("st.browser.found.notSaved")})]})},G.id))}),t.steps.every(G=>G.detail===void 0)?null:e.jsxs(e.Fragment,{children:[e.jsx("dl",{className:"space-y-1.5","data-browser-route-diagnostics":!0,children:t.steps.map(G=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,9rem)_minmax(0,1fr)] gap-x-3 gap-y-0.5",children:[e.jsx("dt",{className:"text-ink-faint",children:le(G.id)}),e.jsxs("dd",{className:"min-w-0 text-ink-soft",children:[r(`st.browser.stepState.${G.state}`),G.reason===void 0?"":` · ${G.reason}`,G.detail===void 0?"":e.jsx("span",{className:"block text-ink-faint",children:G.detail})]})]},G.id))}),e.jsx("p",{className:"font-mono text-ink-faint break-all","data-browser-route-source":!0,children:t.sourceUrl}),e.jsxs("p",{className:"text-ink-faint",children:[r("st.browser.route.hostLine")," ",e.jsx("span",{className:"font-mono break-all",children:t.executionHost})]})]}),X===void 0&&q===void 0?null:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X===void 0||Z?null:e.jsx("button",{type:"button",className:Q,"data-browser-route-update":!0,disabled:b!==null,onClick:()=>{J("update")},children:r(b==="update"?"st.browser.route.updating":"st.browser.route.update")}),q===void 0?null:e.jsx("button",{type:"button",className:Q,"data-browser-route-shortcut":!0,disabled:b!==null,onClick:()=>{J("shortcut")},children:r(b==="shortcut"?"st.browser.route.creatingShortcut":"st.browser.route.shortcut")}),q===void 0?null:e.jsx("p",{className:"basis-full text-[11px] text-ink-faint",children:t.executionHost==="local"||t.executionHost==="127.0.0.1"||t.executionHost==="localhost"?r("st.browser.route.shortcutHostLocal"):r("st.browser.route.shortcutHostRemote",{host:t.executionHost})})]})]})})}):null]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-1 text-[12px] text-ink-faint","data-browser-source-disabled-hint":t.preset,children:r("st.browser.source.disabledHint")}),e.jsx(pe,{feedback:p})]})});return a?e.jsxs("div",{"data-browser-route":t.preset,"data-browser-route-state":S?$:"disabled","data-browser-source-enabled":S?"true":"false",className:"min-w-0",children:[S?we:e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[12.5px] text-ink-soft","data-browser-source-disabled-hint":t.preset,children:r("st.browser.source.disabledHint")}),e.jsx("button",{type:"button",className:Q,"data-browser-source-enable":t.preset,disabled:b!==null,onClick:()=>{A(!0)},children:r("st.browser.source.enable",{name:C})}),e.jsx(pe,{feedback:p})]}),_e]}):e.jsx("li",{children:e.jsxs(Di,{data:{"data-browser-route":t.preset,"data-browser-route-state":S?$:"disabled","data-browser-source-enabled":S?"true":"false"},open:s,onToggle:()=>{n(!s)},bodyId:`browser-route-body-${t.preset}`,expandLabel:r("st.browser.menu.openRow",{name:C}),name:C,marks:e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[k.length===0?null:e.jsx("span",{className:"text-[12px] tabular-nums text-ink-faint","data-browser-allowed-count":t.preset,children:r("st.browser.source.allowedOf",{allowed:S?j:0,total:k.length})}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-ink-soft","data-browser-route-readiness":$,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${S?E.dot:"bg-hairline-strong"}`}),r(S?E.text:"st.browser.source.disabled")]})]}),subtitle:S?void 0:r("st.browser.source.disabledHint"),control:e.jsx(Be,{layout:"bare",label:r("st.browser.source.enable",{name:C}),checked:S,disabled:b!==null,dataAttr:"data-browser-source-switch",dataAttrValue:t.preset,onChange:G=>{A(G)}}),children:[e.jsx("span",{"data-browser-route-select":!0,className:"sr-only",children:C}),we,_e]})})}function ID(){const{client:t,scopeId:s,sshLabel:n}=be(),{t:a}=D(),i=x.useContext(Ia),r=je({queryKey:Vt.presets(s),queryFn:()=>St(t).setupPresets(),staleTime:5e3,refetchOnWindowFocus:!0,refetchInterval:p=>p.state.data?.presets.some(h=>h.state==="preparing")===!0?1500:!1}),o=r.data?.presets??[],l=o.find(p=>TD(p))?.preset??null,[c,d]=x.useState(l);x.useEffect(()=>{d(p=>p??l)},[l]),x.useEffect(()=>{i==="st-card-webbridge"&&o.some(p=>p.preset==="kimi-webbridge")&&d("kimi-webbridge")},[i,o]);const u=o.some(p=>p.preset==="kimi-webbridge");return e.jsxs("div",{className:"space-y-3","data-browser-setup":!0,children:[n===null?null:e.jsx(he,{children:a("st.browser.setup.hostSsh",{label:n})}),r.isPending?e.jsx("p",{role:"status",className:"text-[12px] text-ink-faint",children:a("st.browser.setup.detecting")}):r.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:r.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{r.refetch()},children:a("common.retry")})]}):o.length===0?e.jsx(he,{children:a("st.browser.route.none")}):e.jsx("ul",{className:"divide-y divide-hairline","data-browser-routes":!0,children:o.map((p,h)=>e.jsx(Dk,{preset:p,open:c===p.preset,onOpenChange:b=>{d(b?p.preset:null)},children:p.preset==="kimi-webbridge"?e.jsx(vd,{}):null},`${p.preset}-${h}`))}),u?null:e.jsx(vd,{})]})}const rr=["kimi-webbridge","independent-browser","codex-browser","ego-lite"],PD={"kimi-webbridge":"st.browser.pick.kimi-webbridge","independent-browser":"st.browser.pick.independent-browser","codex-browser":"st.browser.pick.codex-browser","ego-lite":"st.browser.pick.ego-lite"};function kf(t,s){return s.preset in Pi?t(Pi[s.preset]):s.displayName}function AD({onClose:t,manualForm:s,onManual:n}){const{t:a}=D(),{client:i,scopeId:r}=be(),o=Ko(),[l,c]=x.useState({kind:"pick"}),d=je({queryKey:Vt.presets(r),queryFn:()=>St(i).setupPresets(),staleTime:5e3,refetchOnWindowFocus:!0,refetchInterval:b=>b.state.data?.presets.some(m=>m.state==="preparing")===!0?1500:!1}),u=[...d.data?.presets??[]].sort((b,m)=>{const f=rr.indexOf(b.preset),g=rr.indexOf(m.preset);return(f===-1?rr.length:f)-(g===-1?rr.length:g)}),p=l.kind==="route"?u.find(b=>b.preset===l.preset):void 0,h=l.kind==="manual"?a("st.browser.addManual"):p!==void 0?kf(a,p):a("st.browser.add");return e.jsx($n,{title:h,overlayId:"settings-add-browser",width:"lg",onClose:t,data:{"data-browser-add-panel":l.kind==="route"?l.preset:l.kind},back:l.kind==="pick"?void 0:{label:a("st.browser.add"),onClick:()=>{c({kind:"pick"})},data:{"data-browser-back":""}},stepKey:l.kind==="route"?l.preset:l.kind,children:e.jsx("div",{className:"min-w-0 space-y-5","data-browser-add-view":l.kind,children:l.kind==="pick"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-soft",children:a("st.browser.pick.lead")}),d.isPending?e.jsx("p",{role:"status",className:"text-[12.5px] text-ink-faint",children:a("st.browser.setup.detecting")}):d.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:d.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{d.refetch()},children:a("common.retry")})]}):null,e.jsxs("ul",{className:"divide-y divide-hairline border-y border-hairline","data-browser-pick-list":!0,children:[u.map(b=>{const m=Wu(b),f=o.sourceEnabled(b.preset),g=Ok[m],v=PD[b.preset];return e.jsx("li",{children:e.jsxs("button",{type:"button","data-browser-pick":b.preset,onClick:()=>{c({kind:"route",preset:b.preset})},className:"group flex w-full items-center gap-3 px-1 py-3.5 text-left transition-colors hover:bg-ink/[0.025] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-medium text-ink",children:kf(a,b)}),v===void 0?null:e.jsx("span",{className:"mt-0.5 block text-[12.5px] leading-5 text-ink-soft",children:a(v)})]}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[12px] text-ink-faint","data-browser-pick-state":f?m:"disabled",children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${f?g.dot:"bg-hairline-strong"}`}),a(f?g.text:"st.browser.source.disabled")]}),e.jsx(de,{name:"chevron",size:14,className:"shrink-0 text-ink-faint transition-colors group-hover:text-ink-soft"})]})},b.preset)}),e.jsx("li",{children:e.jsxs("button",{type:"button","data-browser-add-manual":!0,onClick:()=>{n(),c({kind:"manual"})},className:"group flex w-full items-center gap-3 px-1 py-3.5 text-left transition-colors hover:bg-ink/[0.025] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-medium text-ink",children:a("st.browser.addManual")}),e.jsx("span",{className:"mt-0.5 block text-[12.5px] leading-5 text-ink-soft",children:a("st.browser.addManualHint")})]}),e.jsx(de,{name:"chevron",size:14,className:"shrink-0 text-ink-faint transition-colors group-hover:text-ink-soft"})]})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(he,{children:a("st.browser.modelNotice")}),e.jsx(xD,{})]})]}):l.kind==="manual"?s:p===void 0?e.jsx("p",{role:"status",className:"text-[12.5px] text-ink-faint",children:a("st.browser.setup.detecting")}):e.jsx(Dk,{preset:p,open:!0,onOpenChange:()=>{},bare:!0,children:p.preset==="kimi-webbridge"?e.jsx(vd,{}):null})})})}function $D(){return{id:"",original:void 0,name:"",enabled:!0,type:"agent-browser-profile",driverPath:"",profilePath:"",executablePath:"",headed:!1,endpoint:Dt,cliPath:"",profileId:"",serverName:""}}function jr(t){return{id:t.id,original:t,name:t.name,enabled:t.enabled,type:t.type,driverPath:t.driverPath??"",profilePath:t.profilePath??"",executablePath:t.executablePath??"",headed:t.headed===!0,endpoint:Dt,cliPath:t.cliPath??"",profileId:t.profileId??"",serverName:t.serverName??""}}function As(t){return t.original===void 0}function RD(t){return t.original===void 0||JSON.stringify(t)!==JSON.stringify(jr(t.original))}function or(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function LD(t,s){const n={};if(As(t)){const r=t.id.trim();r===""?n.id="st.browser.idRequired":ub.safeParse(r).success?s.includes(r)&&(n.id="st.browser.idTaken"):n.id="st.browser.idInvalid"}const a=t.name.trim();a===""?n.name="st.browser.nameRequired":a.length>256&&(n.name="st.browser.nameTooLong");const i=t.driverPath.trim();if(i!==""&&!or(i)&&(n.driverPath="st.browser.pathInvalid"),t.type==="agent-browser-profile"){const r=t.profilePath.trim(),o=t.executablePath.trim();r!==""&&!or(r)&&(n.profilePath="st.browser.pathInvalid"),o!==""&&!or(o)&&(n.executablePath="st.browser.pathInvalid")}else if(t.type==="agent-browser-cdp"&&(t.endpoint.mode==="clear"||t.endpoint.mode==="set"&&t.endpoint.value.trim()===""))n.endpoint="st.browser.endpointRequired";else if(t.type==="agent-browser-cdp"&&t.endpoint.mode==="keep"&&t.original?.type!=="agent-browser-cdp")n.endpoint="st.browser.endpointRequired";else if(t.type==="ego-lite"){const r=t.cliPath.trim();r!==""&&!or(r)&&(n.cliPath="st.browser.pathInvalid"),(t.profileId.trim().length>256||t.serverName.trim().length>256)&&(n.name=n.name??"st.browser.nameTooLong")}return n}function MD(t){return Object.values(t).some(s=>s!==void 0)}function OD(t){return t.mode==="set"?{action:"set",value:t.value.trim()}:{action:"keep"}}function DD(t){const s=t.name.trim(),n=t.driverPath.trim(),a=n===""?void 0:n;if(t.type==="codex-extension"){if(t.original?.runtimeRoot===void 0||t.original.browserId===void 0)throw new Error("st.browser.invalid");return{type:"codex-extension",name:s,enabled:t.enabled,runtimeRoot:t.original.runtimeRoot,browserId:t.original.browserId}}if(t.type==="agent-browser-profile"){const i=t.profilePath.trim(),r=t.executablePath.trim();return{name:s,enabled:t.enabled,driverPath:a,type:"agent-browser-profile",profilePath:i===""?void 0:i,executablePath:r===""?void 0:r,headed:t.headed?!0:void 0}}if(t.type==="ego-lite"){const i=t.cliPath.trim(),r=t.profileId.trim(),o=t.serverName.trim();return{type:"ego-lite",name:s,enabled:t.enabled,...i===""?{}:{cliPath:i},...r===""?{}:{profileId:r},...o===""?{}:{serverName:o}}}return t.type==="kimi-webbridge"?{name:s,enabled:t.enabled,driverPath:a,type:"kimi-webbridge"}:t.type==="webbridge-command"?{name:s,enabled:t.enabled,type:"webbridge-command"}:{name:s,enabled:t.enabled,driverPath:a,type:"agent-browser-cdp",endpoint:OD(t.endpoint)}}function FD(t){const s=Vw.safeParse(t);if(!s.success)throw new Error("st.browser.invalid");return s.data}function qD({onOpen:t}){const{t:s}=D();return e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5`,"data-browser-add":!0,"data-browser-add-heading":!0,onClick:t,children:[e.jsx(de,{name:"plus",size:12}),s("st.browser.add")]})}const BD="native_browser",yd=Sd(BD),jf=pb(yd),KD=`/settings/${yd}${jf===void 0?"":`?tab=${jf}`}#${Sr(yd)}`;function UD(t,s){return t(s==="ego-lite"?"st.browser.type.ego-lite":s==="kimi-webbridge"||s==="webbridge-command"?"st.browser.type.kimi-webbridge":s==="codex-extension"?"st.browser.type.codex-extension":s==="agent-browser-cdp"?"st.browser.type.cdp":"st.browser.type.profile")}function HD(t,s){return s?.type==="codex-extension"?[{value:"codex-extension",label:t("st.browser.type.codexExtensionLong"),hint:t("st.browser.type.codexExtensionHint")}]:s?.type==="ego-lite"?[{value:"ego-lite",label:t("st.browser.type.egoLiteLong"),hint:t("st.browser.type.egoLiteHint")}]:s?.type==="kimi-webbridge"?[{value:"kimi-webbridge",label:t("st.browser.type.kimi-webbridge"),hint:t("st.browser.type.webbridgeHint")}]:s?.type==="webbridge-command"?[{value:"webbridge-command",label:t("st.browser.type.kimi-webbridge"),hint:t("st.browser.type.webbridgeHint")}]:[{value:"agent-browser-profile",label:t("st.browser.type.profileLong"),hint:t("st.browser.type.profileHint")},{value:"agent-browser-cdp",label:t("st.browser.type.cdpLong"),hint:t("st.browser.type.cdpHint")},{value:"kimi-webbridge",label:t("st.browser.type.kimi-webbridge"),hint:t("st.browser.type.webbridgeHint")}]}function Fk(t,s){return s==="ego-lite"?{check:t("st.browser.checkEgo"),checkHint:t("st.browser.checkHintEgo"),connect:t("st.browser.connectEgo")}:s==="kimi-webbridge"||s==="webbridge-command"?{check:t("st.browser.checkWebbridge"),checkHint:t("st.browser.checkHintWebbridge"),connect:t("st.browser.connectWebbridge")}:s==="agent-browser-cdp"?{check:t("st.browser.checkCdp"),checkHint:t("st.browser.checkHintCdp"),connect:t("st.browser.connectCdp")}:{check:t("st.browser.checkProfile"),checkHint:t("st.browser.checkHintProfile"),connect:t("st.browser.connectProfile")}}function zD(t){return t==="agent-browser-cdp"?"st.browser.deleteConsequenceCdp":t==="ego-lite"?"st.browser.deleteConsequenceEgo":t==="kimi-webbridge"||t==="webbridge-command"?"st.browser.deleteConsequenceWebbridge":"st.browser.deleteConsequenceProfile"}function wf(t,s){return s.type==="codex-extension"?s.browserId??t("st.browser.location.unknown"):s.type==="ego-lite"?s.cliPath??t("st.browser.type.ego-lite"):s.type==="agent-browser-profile"?t("st.browser.location.server"):s.type==="kimi-webbridge"||s.type==="webbridge-command"?t("st.browser.location.webbridge"):gd(s.endpointDisplay)??t("st.browser.location.unknown")}function Ps({id:t,label:s,value:n,onChange:a,issue:i,hint:r,placeholder:o,mono:l=!1,dataAttr:c}){const d=`${t}-issue`;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:$e,htmlFor:t,children:s}),e.jsx("input",{id:t,className:`${Ce} ${l?"font-mono":""} ${i===null?"":"border-danger"}`,value:n,spellCheck:!1,autoComplete:"off",placeholder:o,"aria-invalid":i!==null,"aria-describedby":i===null?void 0:d,[c]:"",onChange:u=>{a(u.target.value)}}),e.jsx(it,{id:d,text:i}),r===void 0?null:e.jsx(he,{children:r})]})}function QD({row:t,card:s}){const{t:n}=D(),{allowance:a,codexPending:i}=s,r=a.sourceOf(t),o=a.sourceEnabled(r),l=a.isChosen(t),c=s.defaultBrowser!==""&&s.defaultBrowser===t.id,d=t.type==="codex-extension"&&i.has(t.browserId??t.id),u=s.selectedId===t.id,p=x.useRef(null),[h,b]=x.useState(null),m=gn.has(t.status.state),f=t.enabled!==!1&&!s.busyAction,g=Fk(n,t.type),v=[{key:"default",label:n(c?"st.browser.menu.clearDefault":"st.browser.menu.setDefault"),run:()=>{c?s.onClearDefault(t):s.onSetDefault(t)}},{key:"check",label:g.check,blockedReason:f?void 0:n("st.browser.menu.runBlocked"),run:()=>{s.onCheck(t)}},m?{key:"disconnect",label:n("st.browser.disconnect"),blockedReason:f?void 0:n("st.browser.menu.runBlocked"),run:()=>{s.onDisconnect(t)}}:{key:"connect",label:g.connect,blockedReason:!f||Nk.has(t.status.state)?n("st.browser.menu.runBlocked"):void 0,run:()=>{s.onConnect(t)}},{key:"delete",label:n("st.browser.delete"),danger:!0,separatorBefore:!0,run:()=>{s.onDelete(t)}}];return e.jsx(Di,{data:{"data-browser-row":t.id,"data-browser-row-allowed":a.isEffective(t)?"true":"false","data-browser-source-off":r!==void 0&&!o?"true":void 0},open:u,onToggle:()=>{s.onToggleRow(t)},bodyId:`browser-row-body-${t.id}`,expandLabel:n("st.browser.menu.openRow",{name:t.name}),name:t.name,marks:e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[t.status.currentCall===void 0?null:e.jsx(Yt,{tone:"accent",children:n("st.browser.currentControl")}),d?e.jsx("span",{"data-browser-status-tag":"auth_unknown",children:e.jsx(Yt,{tone:"warn",children:n("st.browser.status.authUnknown")})}):null,e.jsx(Mk,{state:t.enabled?t.status.state:"disabled"}),c?e.jsx("span",{"data-browser-default-tag":t.id,children:e.jsx(Yt,{tone:"accent",children:n("st.browser.defaultActive")})}):null]}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"shrink-0","data-browser-row-type":t.type,children:UD(n,t.type)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"min-w-0 max-w-full truncate",title:wf(n,t),"data-browser-identity":t.type==="codex-extension"?t.browserId??t.id:void 0,children:wf(n,t)}),r===void 0||o?null:e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"shrink-0 text-amber-ink","data-browser-source-tag":r,children:n("st.browser.row.sourceOff",{source:s.sourceName(r)})})]})]}),control:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-browser-allow-switch":t.id,className:"contents",children:e.jsx(Be,{layout:"bare",label:n("st.browser.row.allow",{name:t.name}),checked:l,disabled:s.rowBusy||!o,onChange:y=>{s.onToggleAllowed(t,y)}})}),e.jsx("button",{ref:p,type:"button","data-browser-row-menu-button":t.id,"aria-label":n("st.browser.menu.open",{name:t.name}),"aria-haspopup":"menu","aria-expanded":h!==null,onClick:()=>{b(p.current?.getBoundingClientRect()??null)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.04] hover:text-ink",children:e.jsx(de,{name:"more",size:14})}),h!==null?e.jsx($a,{anchor:h,anchorElement:p.current,items:v,ariaLabel:n("st.browser.menu.open",{name:t.name}),onClose:()=>{b(null)}}):null]}),children:u?s.renderDetail():null})}function GD({adding:t,onAddingChange:s}){const{client:n,scopeId:a}=be(),{t:i,locale:r}=D(),o=Oe(),l=Et(),c=Ln(),d=Ko(),u=d.connectionsQuery,p=d.connections,h=d.defaultBrowser,m=je({queryKey:Vt.presets(a),queryFn:()=>St(n).setupPresets(),staleTime:5e3}).data?.presets??[],f=new Set(m.filter(ye=>ye.preset==="codex-browser"&&ye.reason==="approval_unproven"&&ye.browserId!==void 0).map(ye=>ye.browserId)),g=ye=>i(Pi[ye]),[v,y]=x.useState(!1),[w,N]=x.useState(null),_=async ye=>{y(!0),N(null);try{await ye()}catch(ze){N({tone:"error",text:oe(r,ze)})}finally{y(!1)}},C=(ye,ze)=>_(()=>d.writeAllowed(ye.id,ze,{fallbackBrowserId:ye.browserId})),[S,k]=x.useState(null),[j,T]=x.useState(!1),[A,P]=x.useState(!1),[R,L]=x.useState(null),[I,$]=x.useState(!1),[E,M]=x.useState(null),[z,H]=x.useState("form"),[U,X]=x.useState(!1),[q,F]=x.useState(null),[V,se]=Je(),[Y,O]=x.useState(null),B=S!==null&&RD(S),le=`browser-control:${a}:${S?.original?.id??"new"}`,re=S===null?{}:LD(S,p.map(ye=>ye.id)),ae=S?.original?.id,ne=ae===void 0?void 0:p.find(ye=>ye.id===ae),Ee=ne?.status,ie=ne?.enabled??S?.enabled??!0,me=ae!==void 0&&u.isSuccess&&ne===void 0;x.useEffect(()=>{me&&!B&&k(null)},[me,B]);const fe=ye=>{k(ye),M(null),H("form"),X(!1),F(null),T(!1)},Ie=ye=>{if(B&&S!==null&&c?.confirmDiscard!==void 0){c.confirmDiscard(le,()=>{fe(ye)});return}fe(ye)},te=ye=>{const ze=ye instanceof Error?ye.message:"",Pe=QO(zO(ye));if(X(Pe),Pe){M({tone:"error",text:i("st.browser.flagOff")});return}M({tone:"error",text:ze.startsWith("st.")?i(ze):oe(r,ye)})},ee=()=>o.invalidateQueries({queryKey:Vt.connections(a)}),K=async()=>{if(S!==null){if(MD(re)){T(!0);return}P(!0),M(null),H("form"),X(!1);try{const ye=FD(DD(As(S)?S:{...S,enabled:ie})),ze=S.original?.id??S.id.trim(),Pe=await St(n).upsert(ze,ye);await ee(),k(jr(Pe.connection)),F(null),se(),As(S)&&s(!1)}catch(ye){te(ye)}finally{P(!1)}}},Z=async()=>{const ye=Y;if(ye!==null){$(!0),M(null),H("form");try{await St(n).remove(ye.id),O(null),S?.original?.id===ye.id&&fe(null),await ee(),M({tone:"success",text:i("st.browser.deleted",{name:ye.name})})}catch(ze){O(null),te(ze)}finally{$(!1)}}},ue=async(ye,ze)=>{L(ye),M(null),H("runtime"),X(!1),F(null);try{const Pe=await ze();F({action:ye,status:Pe}),await ee()}catch(Pe){te(Pe)}finally{L(null)}},Te=Ee?.currentCall,Ne=Fk(i,S?.type??"agent-browser-profile"),J=(ye,ze)=>i(ze==="kimi-webbridge"||ze==="webbridge-command"?"st.browser.disconnectMeaningWebbridge":ye==="external-browser"?"st.browser.disconnectMeaningExternal":ye==="managed-profile"?"st.browser.disconnectMeaningManaged":"st.browser.disconnectMeaningUnknown"),_e=(ye,ze)=>{const Pe=re[ye];return Pe!==void 0&&(j||ze)?i(Pe):null},we=()=>S===null?null:e.jsxs("div",{className:"min-w-0 space-y-4","data-browser-detail":S.original?.id??"new",children:[As(S)||Ee===void 0?null:e.jsxs("div",{className:"space-y-2","data-browser-runtime":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx(Mk,{state:ie?Ee.state:"disabled"}),Ee.driverVersion===void 0?null:e.jsx("span",{className:"text-[11px] text-ink-faint","data-browser-driver-line":!0,children:i("st.browser.driverLine",{version:Ee.driverVersion})}),e.jsx("span",{className:"min-w-0 break-all text-[11px] text-ink-faint","data-browser-execution-host":!0,children:S.type==="agent-browser-cdp"?gd(S.original?.endpointDisplay)??i("st.browser.location.unknown"):Ee.executionHost}),Ee.checkedAt===void 0?null:e.jsx("span",{className:"text-[11px] text-ink-faint",children:i("st.browser.checkedAt",{at:pa(r,Ee.checkedAt)??""})}),e.jsxs("span",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",className:Q,"data-browser-check":!0,disabled:R!==null||A||B||!ie,title:Ne.checkHint,onClick:()=>{ue("check",()=>St(n).check(S.id))},children:R==="check"?i("st.browser.checking"):Ne.check}),e.jsx("button",{type:"button",className:Q,"data-browser-connect":!0,disabled:R!==null||A||B||!ie||Nk.has(Ee.state),onClick:()=>{ue("connect",()=>St(n).connect(S.id))},children:R==="connect"?i("st.browser.connecting"):Ne.connect}),gn.has(Ee.state)?e.jsx("button",{type:"button",className:Q,"data-browser-disconnect":!0,disabled:R!==null||A||I,title:i("st.browser.disconnectHint"),onClick:()=>{ue("disconnect",()=>St(n).disconnect(S.id))},children:i(R==="disconnect"?"st.browser.disconnecting":"st.browser.disconnect")}):null]})]}),q===null?null:e.jsxs("div",{className:"space-y-1.5","data-browser-outcome":`${q.action}:${q.status.state}`,children:[e.jsxs("p",{role:"status",className:`text-[12px] ${q.status.state==="failed"||q.status.state==="unconfirmed"?"text-danger":"text-ink-soft"}`,children:[VD(i,q.action,q.status,S.type),pa(r,q.status.checkedAt)===void 0?"":` · ${pa(r,q.status.checkedAt)}`]}),q.action!=="disconnect"||q.status.error!==void 0?null:e.jsx("p",{className:"max-w-[62ch] text-[12px] text-ink-faint",children:J(q.status.ownership,S.type)}),q.status.error===void 0||q.status.error===Ee.error?null:e.jsx("p",{className:"max-w-[72ch] break-words text-[12px] text-danger",children:q.status.error})]}),Ee.error===void 0?null:e.jsx("p",{role:"alert","data-browser-error":!0,className:"max-w-[72ch] break-words text-[12px] leading-[18px] text-danger",children:Ee.error}),Te===void 0?null:e.jsx("p",{className:"text-[12px] text-ink-soft","data-browser-caller":!0,children:i("st.browser.callerLine",{session:Te.sessionId,agent:Te.agentId,tool:Te.tool})}),Ee.state==="unconfirmed"?e.jsx(he,{children:i("st.browser.state.unconfirmedHint")}):null,ie?null:e.jsx(he,{children:i("st.browser.disabledHint")}),B?e.jsx(he,{children:i("st.browser.dirtyRuntimeHint")}):null,gn.has(Ee.state)?e.jsx(he,{children:J(Ee.ownership,S.type)}):null,B||gn.has(Ee.state)?null:e.jsx(he,{children:Ne.checkHint}),B&&gn.has(Ee.state)?e.jsx(he,{children:i("st.browser.saveEndsSession")}):null,e.jsx(hD,{id:S.id,type:S.type,status:Ee}),z==="runtime"?e.jsx(pe,{feedback:E}):null,U?e.jsx("button",{type:"button",className:Q,"data-browser-open-flag":!0,onClick:()=>{l(KD)},children:i("st.browser.flagOffAction")}):null]}),e.jsxs("fieldset",{disabled:A||I,className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[As(S)?e.jsx(Ps,{id:"browser-id",label:i("st.browser.fieldId"),mono:!0,placeholder:"research",dataAttr:"data-browser-id-input",value:S.id,issue:_e("id",S.id.trim()!==""),hint:i("st.browser.fieldIdHint"),onChange:ye=>{k({...S,id:ye})}}):null,e.jsx(Ps,{id:"browser-name",label:i("st.browser.fieldName"),dataAttr:"data-browser-name-input",value:S.name,issue:_e("name",S.name.trim()!==""),onChange:ye=>{k({...S,name:ye})}}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:$e,id:"browser-type-label",children:i("st.browser.fieldType")}),e.jsx(Qe,{id:"browser-type",variant:"form",ariaLabel:i("st.browser.fieldType"),value:S.type,dataAttr:"data-browser-type",choices:HD(i,S.original),onChange:ye=>{k({...S,type:ye})}})]})]}),S.original!==void 0&&S.original.type!==S.type?e.jsx(he,{children:i("st.browser.typeChangeHint")}):null,S.type==="codex-extension"?e.jsxs("dl",{className:"space-y-2 text-[12px]","data-browser-official-binding":!0,children:[e.jsx("dt",{className:$e,children:i("st.browser.runtimeRoot")}),e.jsx("dd",{className:"break-all font-mono text-ink-soft",children:S.original?.runtimeRoot}),e.jsx("dt",{className:$e,children:i("st.browser.browserId")}),e.jsx("dd",{className:"break-all font-mono text-ink-soft",children:S.original?.browserId})]}):S.type==="ego-lite"?e.jsx(et,{summary:i("st.browser.advanced"),"data-browser-advanced":!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ps,{id:"browser-cli-path",label:i("st.browser.fieldCliPath"),mono:!0,dataAttr:"data-browser-cli-input",value:S.cliPath,issue:_e("cliPath",S.cliPath.trim()!==""),hint:i("st.browser.fieldCliPathHint"),onChange:ye=>{k({...S,cliPath:ye})}}),e.jsx(Ps,{id:"browser-profile-id",label:i("st.browser.fieldProfileId"),dataAttr:"data-browser-profile-id-input",value:S.profileId,issue:null,hint:i("st.browser.fieldProfileIdHint"),onChange:ye=>{k({...S,profileId:ye})}}),e.jsx(Ps,{id:"browser-server-name",label:i("st.browser.fieldServerName"),dataAttr:"data-browser-server-name-input",value:S.serverName,issue:null,hint:i("st.browser.fieldServerNameHint"),onChange:ye=>{k({...S,serverName:ye})}})]})}):S.type==="agent-browser-profile"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1","data-browser-headed":!0,children:[e.jsx(Be,{label:i("st.browser.fieldHeaded"),checked:S.headed,onChange:ye=>{k({...S,headed:ye})}}),e.jsx(he,{children:i("st.browser.fieldHeadedHint")})]}),e.jsx(Ps,{id:"browser-profile-path",label:i("st.browser.fieldProfilePath"),mono:!0,dataAttr:"data-browser-profile-input",value:S.profilePath,issue:_e("profilePath",S.profilePath.trim()!==""),placeholder:i("st.browser.profilePlaceholder"),hint:i("st.browser.fieldProfilePathHint"),onChange:ye=>{k({...S,profilePath:ye})}}),e.jsx(et,{summary:i("st.browser.advanced"),"data-browser-advanced":!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ps,{id:"browser-executable-path",label:i("st.browser.fieldExecutablePath"),mono:!0,dataAttr:"data-browser-executable-input",value:S.executablePath,issue:_e("executablePath",S.executablePath.trim()!==""),hint:i("st.browser.fieldExecutablePathHint"),onChange:ye=>{k({...S,executablePath:ye})}}),e.jsx(Ps,{id:"browser-driver-path",label:i("st.browser.fieldDriverPath"),mono:!0,dataAttr:"data-browser-driver-input",value:S.driverPath,issue:_e("driverPath",S.driverPath.trim()!==""),placeholder:i("st.browser.driverPlaceholder"),hint:i("st.browser.fieldDriverPathHint",{version:fd,markers:bd}),onChange:ye=>{k({...S,driverPath:ye})}})]})})]}):S.type==="kimi-webbridge"||S.type==="webbridge-command"?e.jsx("div",{"data-browser-bridge":!0,children:e.jsx(he,{children:i("st.browser.bridgeHint")})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("ol",{className:"max-w-[62ch] list-decimal space-y-0.5 pl-4 text-[12px] leading-[18px] text-ink-soft marker:text-ink-faint","data-browser-cdp-steps":!0,children:[e.jsx("li",{children:i("st.browser.cdpSteps.1")}),e.jsx("li",{children:i("st.browser.cdpSteps.2")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Dn,{label:i("st.browser.fieldEndpoint"),source:S.original?.endpointConfigured===!0?"kiki":"none",draft:S.endpoint,clearable:!1,reveal:S.original===void 0?void 0:async()=>(await n.revealSecret({kind:"browser_endpoint",browser_id:S.original.id})).value,onChange:ye=>{k({...S,endpoint:ye})},sourceText:S.original?.endpointConfigured===!0?i("st.browser.endpointSource"):void 0,hint:i("st.browser.fieldEndpointHint")}),S.original?.endpointDisplay===void 0?null:e.jsx("p",{className:"font-mono text-[11px] text-ink-faint","data-browser-endpoint-host":!0,children:i("st.browser.endpointHostLine",{host:gd(S.original.endpointDisplay)??S.original.endpointDisplay})}),e.jsx(it,{id:"browser-endpoint-issue",text:_e("endpoint",S.endpoint.mode==="set")})]}),e.jsx(et,{summary:i("st.browser.advanced"),"data-browser-advanced":!0,children:e.jsx(Ps,{id:"browser-driver-path",label:i("st.browser.fieldDriverPath"),mono:!0,dataAttr:"data-browser-driver-input",value:S.driverPath,issue:_e("driverPath",S.driverPath.trim()!==""),placeholder:i("st.browser.driverPlaceholder"),hint:i("st.browser.fieldDriverPathHint",{version:fd,markers:bd}),onChange:ye=>{k({...S,driverPath:ye})}})})]})]}),z==="form"||As(S)?e.jsx(pe,{feedback:E}):null,e.jsx(lt,{id:le,dirty:B,saving:A,saved:V,saveLabel:As(S)?i("st.browser.create"):i("st.browser.save"),persistent:As(S),onSave:()=>{K()},onDiscard:()=>{fe(S.original===void 0?null:jr(S.original))}})]}),G={allowance:d,codexPending:f,defaultBrowser:h,selectedId:ae,rowBusy:v,busyAction:R,sourceName:g,onToggleRow:ye=>{ae===ye.id?Ie(null):Ie(jr(ye))},onToggleAllowed:(ye,ze)=>{C(ye,ze)},onSetDefault:ye=>{_(()=>d.writeDefault(ye.id,!1))},onClearDefault:ye=>{_(()=>d.writeDefault(ye.id,!0))},onCheck:ye=>{ue("check",()=>St(n).check(ye.id))},onConnect:ye=>{ue("connect",()=>St(n).connect(ye.id))},onDisconnect:ye=>{ue("disconnect",()=>St(n).disconnect(ye.id))},onDelete:ye=>{O(ye)},renderDetail:we},Le=u.isSuccess&&p.length===0,Se=S!==null&&As(S),Fe=()=>{const ye=()=>{Se&&fe(null),s(!1)};if(Se&&B&&c?.confirmDiscard!==void 0){c.confirmDiscard(le,ye);return}ye()};return e.jsxs("div",{className:"min-w-0","data-browser-connections":!0,"data-browser-view":t?"add":"list",children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("div",{"aria-label":i("st.browser.connectionsTitle"),className:"min-w-0",children:[u.isLoading?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:i("st.browser.loading")}):null,u.isError?e.jsx(De,{error:u.error}):null,Le?e.jsxs("div",{"data-browser-empty":!0,className:"space-y-2.5 py-2",children:[e.jsx("p",{className:"text-[13px] text-ink",children:i("st.browser.emptyTitle")}),e.jsx(he,{children:i("st.browser.emptyBody")}),e.jsx("button",{type:"button",className:Ye,"data-browser-add":!0,"data-browser-empty-add":!0,onClick:()=>{s(!0)},children:i("st.browser.add")})]}):null,p.length>0?e.jsx("div",{className:"divide-y divide-hairline/70","data-browser-list":!0,children:p.map(ye=>e.jsx(QD,{row:ye,card:G},ye.id))}):null,e.jsx(pe,{feedback:w})]}),Se?null:e.jsx(pe,{feedback:E}),e.jsx(WD,{})]}),t?e.jsx(AD,{onClose:Fe,onManual:()=>{Se||fe($D())},manualForm:Se?we():null}):null,Y!==null?e.jsx(Xe,{open:!0,overlayId:"confirm-browser-delete",busy:I,title:i("st.browser.deleteTitle",{name:Y.name}),body:i("st.browser.deleteBody"),consequences:[i(zD(Y.type)),...gn.has(Y.status.state)?[i("st.browser.deleteEndsSession")]:[],...h===Y.id?[i("st.browser.deleteDefault")]:[]],confirmLabel:i("st.browser.delete"),onCancel:()=>{O(null)},onConfirm:()=>{Z()}}):null]})}function WD(){const{t}=D(),s=x.useContext(Ia),n=x.useContext(Mn),[a,i]=x.useState(!1);return x.useEffect(()=>{n?.("st-card-browser-setup"),n?.("st-card-webbridge")},[n]),x.useEffect(()=>{(s==="st-card-browser-setup"||s==="st-card-webbridge")&&i(!0)},[s]),e.jsx("div",{id:"st-card-browser-setup","data-settings-card":"st-card-browser-setup",className:`scroll-mt-4 pt-3 ${s==="st-card-browser-setup"?"settings-card-flash":""}`,children:e.jsx(et,{summary:t("st.browser.setup.title"),"data-browser-sources":!0,open:a||void 0,onToggle:r=>{i(r.currentTarget.open)},children:a?e.jsx("div",{className:"pt-2",children:e.jsx(ID,{})}):null})})}function VD(t,s,n,a){if(n.state==="failed")return t("st.browser.outcome.failed");if(n.state==="unconfirmed")return t("st.browser.outcome.unconfirmed");if(s==="check"){const i=n.driverVersion??t("st.browser.detail.driverUnknown");return t(a==="kimi-webbridge"?"st.browser.outcome.checkOkWebbridge":"st.browser.outcome.checkOk",{version:i})}return s==="connect"?n.state==="ready"?t("st.browser.outcome.connected"):t("st.browser.outcome.connectIncomplete"):n.state==="disconnected"?t("st.browser.outcome.disconnected"):t("st.browser.outcome.disconnectIncomplete")}function YD({enabled:t}){const{client:s,scopeId:n}=be(),{t:a}=D(),i=Oe(),r=bt(),[o,l]=x.useState(!1),c=ib(),d=Fd(c!==void 0?[c]:[],s),u=["browser-tool-policy",n,c],p=je({queryKey:u,enabled:c!==void 0&&t,retry:!1,queryFn:async()=>{const v=s.klient.session(c).agent("main"),[y,w,N]=await Promise.all([v.inspectToolPolicy(),v.isToolEnabled("BrowserConnections"),v.isToolEnabled("BrowserTabs")]);return{policy:y,connections:w,tabs:N}}});if(!t||c===void 0)return null;if(p.isError)return e.jsx("p",{className:"text-[12px] text-ink-soft","data-browser-toolpolicy-unavailable":!0,children:a("st.browser.sessionPolicyUnavailable")});if(p.data===void 0)return null;const{policy:h,connections:b,tabs:m}=p.data,f=h.canRefresh&&h.revision!==void 0&&JSON.stringify(h.activeTools)!==JSON.stringify(h.currentTools);if(!f&&b&&m)return null;const g=()=>{const v=h.revision;v!==void 0&&r.run(async()=>{await s.klient.session(c).agent("main").refreshToolPolicy(v),l(!1),await i.invalidateQueries({queryKey:u})})};return e.jsxs("div",{className:"space-y-2","data-browser-session-tool-policy":!0,children:[e.jsx("p",{className:"text-[12px] text-amber-ink",children:a(f?"st.browser.sessionPolicyPending":"st.browser.sessionPolicyRestricted")}),f?e.jsx("button",{type:"button",className:Q,disabled:r.saving,"data-browser-refresh-tool-policy":!0,onClick:()=>{l(!0)},children:a("st.browser.refreshToolPolicy")}):null,e.jsx(pe,{feedback:r.error}),e.jsx(Xe,{open:o,title:a("st.browser.refreshToolPolicy"),body:a("st.browser.refreshToolPolicyBody"),tone:"default",busy:r.saving,confirmLabel:a("st.browser.refreshToolPolicy"),onConfirm:g,onCancel:()=>{l(!1)},children:e.jsx("p",{className:"break-all font-mono text-[11px] text-ink-soft",title:c,children:ya(c,d(c).title)})})]})}function Nf({initialTab:t}={}){const{t:s}=D(),n=Et(),{search:a,hash:i}=Bt(),r=new URLSearchParams(a),o=Yw(r.get("tab")),[l,c]=x.useState(t??o??mb),d=o??l,u=l===d?l:d,p=x.useRef(null),h=(m,f=!1)=>{f&&p.current?.querySelector(`[data-browser-control-tab="${m}"]`)?.focus(),m!==u&&(c(m),r.set("tab",m),n(`/settings/browser-control?${r.toString()}${i}`))};x.useEffect(()=>{o!==void 0&&o!==l&&c(o)},[o,l]),x.useEffect(()=>{const m=i.replace(/^#/,"");if(m===""||o!==void 0)return;const f=Zw(m);f===void 0||f===u||h(f)},[i,a]);const b=(m,f)=>{const g=tl.length-1,v=m.key==="ArrowRight"?f===g?0:f+1:m.key==="ArrowLeft"?f===0?g:f-1:m.key==="Home"?0:m.key==="End"?g:null;v!==null&&(m.preventDefault(),h(tl[v],!0))};return e.jsxs("div",{className:"space-y-6","data-settings-browser-control":!0,children:[e.jsx("div",{ref:p,role:"tablist","aria-label":s("st.section.browserControl"),className:"flex flex-wrap gap-1 border-b border-hairline",children:tl.map((m,f)=>{const g=m===u;return e.jsx("button",{id:`browser-control-tab-${m}`,type:"button",role:"tab","aria-selected":g,"aria-controls":"browser-control-tab-panel",tabIndex:g?0:-1,"data-browser-control-tab":m,onClick:()=>{h(m)},onKeyDown:v=>{b(v,f)},className:`-mb-px min-h-9 border-b-2 px-3 py-1.5 text-[13px] transition-colors outline-none focus-visible:ring-2 focus-visible:ring-selected-ink/40 pointer-coarse:min-h-11 ${g?"border-ink font-medium text-ink":"border-transparent text-ink-soft hover:text-ink"}`,children:s(Jw(m))},m)})}),e.jsx("div",{id:"browser-control-tab-panel",role:"tabpanel","aria-labelledby":`browser-control-tab-${u}`,"data-browser-control-panel":u,className:"space-y-6",children:u==="computer"?e.jsx(lD,{}):e.jsx(ZD,{})})]})}function JD(t,s,n){switch(s.kind){case"unresolved":return{text:t("st.browser.verdict.unresolved")};case"host_locked":return{text:t("st.browser.verdict.hostLocked")};case"off":return{text:t("st.browser.verdict.off")};case"tool_denied":return{text:t("st.browser.toolPolicyDenied")};case"unknown":return{text:t("st.browser.verdict.unknown")};case"no_connections":return{text:t("st.browser.verdict.noConnections")};case"none_allowed":return{text:t("st.browser.verdict.noneAllowed")};case"default_not_allowed":return{text:t("st.browser.defaultNotAllowed",{name:n??s.defaultBrowser??""})};case"allowed":return{text:t("st.browser.verdict.allowed",{count:s.allowedCount}),detail:n===void 0?t("st.browser.verdict.noDefault"):t("st.browser.verdict.default",{name:n})}}}function ZD(){const{client:t,scopeId:s}=be(),{t:n}=D(),a=Oe(),i=bt(),r=bt(),o=Ko(),[l,c]=x.useState(!1),d=je({queryKey:["config",s],queryFn:()=>t.getConfig(),staleTime:3e4}),u=Ns(d.data,"browser"),p=u?.allowed??h_(d.data),h=u?.host_locked===!0,{connectionsQuery:b}=o,m=g_({enabled:p,hostLocked:h,unresolved:u?.unresolved,toolPolicyDenied:o.toolPolicyDenied,connections:b.isSuccess?o.connections:void 0,allowedBrowsersConfigured:o.allowedConfigured,allowedBrowsers:o.allowedBrowsers,disabledSources:o.disabledSources,defaultBrowser:o.defaultBrowser}),f=m.defaultBrowser===void 0?void 0:o.connections.find(N=>N.id===m.defaultBrowser)?.name??m.defaultBrowser,g=d.isPending||b.isPending&&p,{text:v,detail:y}=g?{text:n("st.browser.loading"),detail:void 0}:JD(n,m,f),w=N=>{const _=d.data?.browser_control?.enabled===!1&&d.data.browser_control.enabledSource==="default";i.run(async()=>{await t.setBrowserControlEnabled(N?_?!0:null:!1),await a.invalidateQueries({queryKey:["config",s]}),await a.invalidateQueries({queryKey:Vt.connections(s)}),await a.invalidateQueries({queryKey:Vt.presets(s)})})};return e.jsxs(e.Fragment,{children:[e.jsx(Me,{id:"st-card-browser-enabled",title:"",children:e.jsxs(_k,{title:n("st.browser.enabledLabel"),verdict:{kind:g?"loading":m.kind,tone:g?"unknown":m.tone,text:v,detail:y},enabled:p,onEnabledChange:w,enabledLockedReason:h?n("st.browser.verdict.hostLocked"):void 0,saving:i.saving,saved:i.saved,defaultOn:u===void 0?void 0:{checked:u.default_on,locked:u.unresolved||u.host_locked},onDefaultOnChange:N=>{r.run(async()=>{await t.patchConfig({optional_capabilities:{defaults:{browser:N}}}),await a.invalidateQueries({queryKey:["config",s]})})},defaultOnSaving:r.saving,attrs:{enabled:"data-browser-control-enabled",verdict:"data-browser-verdict",enabledSwitch:"data-browser-enabled-switch",defaultOn:"data-capability-default-browser"},children:[o.toolPolicyPartial&&m.kind==="allowed"?e.jsx("p",{className:"text-[12px] text-amber-ink","data-browser-toolpolicy-partial":!0,children:n("st.browser.toolPolicyPartial")}):null,e.jsx(pe,{feedback:i.error??r.error})]})}),e.jsxs(Me,{id:"st-card-browser-connections",title:n("st.browser.connectionsTitle"),actions:o.connections.length>0?e.jsx(qD,{onOpen:()=>{c(!0)}}):void 0,children:[e.jsx(GD,{adding:l,onAddingChange:c}),e.jsx(et,{summary:n("st.browser.advanced"),"data-browser-advanced-fold":!0,children:e.jsx("div",{className:"space-y-4 pt-1",children:e.jsx(YD,{enabled:p})})})]})]})}const qk=Xw;class XD extends x.Component{state={error:null,resetKey:this.props.resetKey,copied:!1,copyError:null};static getDerivedStateFromError(s){return{error:s instanceof Error?s:new Error(String(s)),copied:!1,copyError:null}}static getDerivedStateFromProps(s,n){return s.resetKey===n.resetKey?null:{error:null,resetKey:s.resetKey,copied:!1,copyError:null}}componentDidCatch(s,n){console.error("[settings:pane-error]",s,n.componentStack)}render(){const{error:s,copied:n,copyError:a,resetKey:i}=this.state;if(s===null)return this.props.children;const r=s.message.trim()||s.name;return e.jsxs("section",{role:"alert","data-settings-pane-error":!0,className:"space-y-3 py-2",children:[e.jsx("h2",{className:"font-display text-[18px] leading-6 text-ink",children:this.props.title}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-md border border-danger/30 bg-danger/5 px-3 py-2 font-mono text-[12px] leading-relaxed text-danger",children:r}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button","data-settings-pane-retry":!0,className:Q,onClick:()=>{this.setState({error:null,copied:!1,copyError:null})},children:this.props.retryLabel}),e.jsx("button",{type:"button","data-settings-pane-copy":!0,"data-copied":n?"true":void 0,className:Q,onClick:()=>{this.setState({copied:!1,copyError:null}),rs(r).then(()=>{this.setState(o=>o.error===s&&o.resetKey===i?{copied:!0,copyError:null}:null)},o=>{this.setState(l=>l.error===s&&l.resetKey===i?{copied:!1,copyError:this.props.copyErrorText(o instanceof Error?o.message:String(o))}:null)})},children:n?this.props.copiedLabel:this.props.copyLabel})]}),a!==null?e.jsx("p",{role:"status","data-settings-pane-copy-error":!0,className:"text-[12px] text-danger",children:a}):null]})}}function eF({resetKey:t,children:s}){const{t:n}=D();return e.jsx(XD,{resetKey:t,title:n("app.unexpectedError"),retryLabel:n("common.retry"),copyLabel:n("contextMenu.copy"),copiedLabel:n("cb.copied"),copyErrorText:a=>n("st.remote.copyFailed",{reason:a}),children:s})}const Sf=50;function tF({archiveId:t,onClose:s}){const{t:n,tp:a,locale:i}=D(),{client:r,scopeId:o}=be(),l=$i(r),[c,d]=x.useState([]),[u,p]=x.useState(!1),[h,b]=x.useState(null),[m,f]=x.useState(!1),g=je({queryKey:["plugin-import","read",o,t,"first"],queryFn:async()=>l.read({archiveId:t,limit:Sf}),staleTime:6e4,retry:!1}),v=g.data?.archive,y=`${o}::${t}`,w=x.useRef(y);w.current=y,x.useEffect(()=>{d([]),b(null),p(!1)},[y]);const N=async()=>{if(C==null||u)return;const j=y,T=C;p(!0),b(null);try{const A=await l.read({archiveId:t,cursor:T,limit:Sf});if(w.current!==j)return;d(P=>[...P,A])}catch(A){if(w.current!==j)return;b(oe(i,A))}finally{w.current===j&&p(!1)}},_=g.data===void 0?[]:[...g.data.records,...c.flatMap(j=>j.records)],C=g.data===void 0?void 0:c.length>0?c.at(-1).cursor:g.data.cursor,S=g.isSuccess&&C===null,k=v===void 0?n("cap.import.archiveLoading"):v.title!==""?v.title:n("cap.import.untitled");return e.jsxs(Ea,{onClose:s,ariaLabel:k,overlayId:"plugin-import-archive",panelClassName:`${bo} ${go.lg} flex h-[min(86dvh,720px)] flex-col !p-0`,overlayData:{"data-plugin-import-archive-dialog":t},children:[e.jsxs("header",{className:"flex shrink-0 items-start gap-3 px-5 pt-4 pb-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h2",{className:"truncate font-display text-[18px] font-semibold tracking-tight text-ink",title:k,children:k}),e.jsx("p",{className:"text-[12.5px] leading-5 text-ink-soft",children:n("cap.import.archiveIntro")})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":n("common.close"),className:"-mr-2 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink pointer-coarse:h-11 pointer-coarse:w-11",children:e.jsx(de,{name:"close",size:16})})]}),v!==void 0?e.jsxs("div",{className:"shrink-0 border-b border-hairline bg-ink/[0.02] px-5 py-3",children:[e.jsx(nm,{items:[{label:n("cap.import.archiveSource"),value:`${v.sourceId} · ${v.externalId}`,mono:!0},{label:n("cap.import.archiveHome"),value:`${v.sourceHome} → ${v.targetHome}`,mono:!0},{label:n("cap.import.archiveStatus"),value:n(v.status==="preserved"?"cap.import.probe.preserved":"cap.import.probe.partial")},...v.losses.length>0?[{label:n("cap.import.archiveLosses"),value:e.jsx("ul",{className:"space-y-0.5",children:v.losses.map(j=>e.jsxs("li",{className:"flex min-w-0 items-baseline gap-1.5",children:[e.jsx("span",{className:"shrink-0 tabular-nums text-ink-faint",children:j.count}),e.jsx("span",{className:"min-w-0",children:j.detail||j.code})]},j.code))})}]:[]]}),e.jsx("div",{className:"mt-1",children:e.jsx(oS,{label:n("cap.import.archiveDetails"),open:m,onToggle:()=>{f(j=>!j)},dataAttrs:{"data-plugin-import-archive-details":""},children:e.jsx(nm,{items:[{label:n("cap.import.archiveRevision"),value:v.revision,mono:!0},{label:n("cap.import.archiveFormat"),value:v.formatVersion,mono:!0},{label:n("cap.import.archiveSize"),value:qd(a,v.records,v.pages)}]})})})]}):null,e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-3","data-plugin-import-archive-body":!0,children:[g.isPending?e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-faint",role:"status",children:[e.jsx(Us,{label:n("cap.import.archiveLoading")}),n("cap.import.archiveLoading")]}):null,g.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:g.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{g.refetch()},children:n("common.retry")})]}):null,g.isSuccess&&_.length===0?e.jsx("p",{className:"text-[13px] text-ink-soft",children:n("cap.import.archiveEmpty")}):null,e.jsx("ol",{className:"space-y-3",children:_.map((j,T)=>e.jsxs("li",{"data-plugin-import-archive-record":j.role,className:"min-w-0 space-y-0.5",children:[e.jsxs("p",{className:"text-[11.5px] font-medium text-ink-faint",children:[n(Hb(j.role)),j.toolName!==void 0?e.jsxs("span",{className:"font-mono",children:[" · ",j.toolName]}):null]}),j.text!==void 0&&j.text!==""?e.jsx("p",{className:`break-words whitespace-pre-wrap text-[13px] leading-[1.55] ${j.role==="user"?"text-ink":"text-ink-soft"}`,children:j.text}):null]},`${j.id}-${j.part}-${T}`))}),h!==null?e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:h}):null]}),e.jsxs("footer",{"data-plugin-import-archive-footer":!0,className:"flex shrink-0 items-center gap-2 border-t border-hairline px-5 py-3",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] leading-4 text-ink-faint",children:n(S?"cap.import.archiveComplete":"cap.import.archiveMoreHint")}),C!=null?e.jsxs("button",{type:"button",className:Q,disabled:u,onClick:()=>{N()},"data-plugin-import-archive-more":!0,children:[u?e.jsx(Us,{label:n("cap.import.archiveLoading"),size:12}):null,n("cap.import.loadMore")]}):null,e.jsx("button",{type:"button",className:Q,onClick:s,children:n("common.close")})]})]})}const Cf=900,_f=50;function sF({initialSourceId:t,initialSourcePluginId:s,onOpenPlugin:n,onOpenSession:a,onBack:i}){const{t:r,locale:o}=D(),{client:l,scopeId:c,meta:d,sshLabel:u,connectionId:p}=be(),h=Oe(),b=mt(),m=p!==null,f=$i(l),{enabled:g,loading:v}=Ob(l,c),[y,w]=x.useState("native"),[N,_]=x.useState(""),C=y==="native"?{kind:"native-session",workDir:N.trim()}:{kind:"archive"},k=(y==="archive"||!m)&&lS(C),[j,T]=x.useState(()=>t===void 0?void 0:s===void 0?cS(t):Xn(s,t)),[A,P]=x.useState(""),[R,L]=x.useState(void 0),[I,$]=x.useState(null),[E,M]=x.useState(!1),[z,H]=x.useState(null),[U,X]=x.useState(null),q=x.useRef(null),F=I!==null&&Ec(I.destination)===Ec(C)?I:null;x.useEffect(()=>{F!==null&&q.current?.scrollIntoView?.({block:"nearest",behavior:"smooth"})},[F?.id]);const V=g===!0,se=je({queryKey:$s.sources(c),queryFn:async()=>f.sources(),enabled:V,staleTime:6e4,retry:!1}),Y=x.useMemo(()=>se.data??[],[se.data]),O=(j===void 0?void 0:Y.find(G=>il(j,G.pluginId,G.id)))??Y.at(0),B=Dd().data?.plugins,le=O!==void 0&&(B===void 0||B.some(G=>G.id===O.pluginId)),[re,ae]=x.useState(null),ne=G=>G.some(cr)?Cf:!1,Ee=dm({queryKey:$s.jobs(c),queryFn:async({pageParam:G})=>f.jobs({limit:_f,...G===void 0?{}:{cursor:G}}),initialPageParam:void 0,getNextPageParam:G=>G.cursor??void 0,enabled:V,staleTime:5e3,retry:!1,refetchInterval:G=>ne(If(G.state.data))}),ie=je({queryKey:[...$s.job(c,re??"")],queryFn:()=>f.job(re),enabled:V&&re!==null,staleTime:Cf,retry:!1,refetchInterval:G=>ne([G.state.data].filter(Le=>Le!==void 0))}),me=dm({queryKey:$s.archives(c,""),queryFn:async({pageParam:G})=>f.archives({limit:_f,...G===void 0?{}:{cursor:G}}),initialPageParam:void 0,getNextPageParam:G=>G.cursor??void 0,enabled:V,staleTime:1e4,retry:!1}),fe=x.useMemo(()=>Tf([...If(Ee.data),...ie.data===void 0?[]:[ie.data]],G=>G.id),[Ee.data,ie.data]),Ie=x.useMemo(()=>Tf(nF(me.data),G=>G.id),[me.data]),te=O===void 0?void 0:Xn(O.pluginId,O.id);x.useEffect(()=>{P(""),L(void 0),$(null),H(null)},[te]);const ee=()=>h.invalidateQueries({queryKey:$s.all}),K=x.useMemo(()=>fe.filter(G=>!cr(G)).map(G=>G.id).join(","),[fe]);x.useEffect(()=>{K!==""&&h.invalidateQueries({queryKey:$s.archives(c,"")})},[K,h,c]);const Z=ie.data===void 0||cr(ie.data);x.useEffect(()=>{re===null||Z||h.invalidateQueries({queryKey:$s.job(c,re)})},[re,Z,h,c]);const ue=I?.targetHome??fe.find(G=>G.targetHome!=="")?.targetHome??Ie.find(G=>G.targetHome!=="")?.targetHome,Te=u??d.server_id,Ne=A.trim();x.useEffect(()=>{L(void 0),$(null),H(null)},[Ne]),x.useEffect(()=>{$(null),H(null)},[y,N]);const J=async()=>{if(!(I===null||E)){M(!0),H(null);try{const G=await f.start({previewId:I.id,acknowledge:!0});$(null),L(void 0),ae(G.id),await ee()}catch(G){H(oe(o,G))}finally{M(!1)}}},_e=async()=>{if(b.pickDirectory!==void 0)try{const G=await b.pickDirectory();typeof G=="string"&&(P(G),H(null))}catch(G){H(oe(o,G))}},we=async()=>{if(b.pickDirectory!==void 0)try{const G=await b.pickDirectory();typeof G=="string"&&(_(G),H(null))}catch(G){H(oe(o,G))}};return v?e.jsxs("p",{className:"py-3 text-[13px] text-ink-faint",role:"status",children:[e.jsx(Us,{label:r("cap.loading")})," ",r("cap.import.loading")]}):g!==!0?e.jsx("div",{"data-cap-import-disabled":!0,className:"space-y-3",children:e.jsx(Za,{title:r("cap.import.unavailableTitle"),body:r("cap.import.unavailableBody")})}):e.jsxs("div",{className:"min-w-0 space-y-8","data-plugin-import-view":O?.id??"none",children:[i!==void 0?e.jsxs("button",{type:"button",className:`${jn} -ml-3`,onClick:i,"data-plugin-import-back":!0,children:[e.jsx(de,{name:"arrowLeft",size:14}),r("cap.detail.back")]}):null,e.jsxs("header",{className:"space-y-1",children:[e.jsx("h1",{className:"font-display text-[20px] leading-7 text-ink",children:r("cap.import.title")}),e.jsx("p",{className:"max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:r("cap.import.intro")})]}),e.jsx(qa,{id:"plugin-import-destination",title:r("cap.import.destinationTitle"),children:m?e.jsxs("div",{className:"min-w-0","data-plugin-import-destination-readonly":!0,children:[e.jsx(am,{value:"archive",ariaLabel:r("cap.import.destinationAria"),dataAttribute:"data-plugin-import-destination",options:[{value:"archive",label:r("cap.import.destinationArchive")}],onChange:()=>{}}),e.jsx("p",{className:"mt-2 max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:r("cap.import.destinationRemoteBody")})]}):e.jsxs("div",{className:"min-w-0 space-y-3 pt-1",children:[e.jsx(am,{value:y,ariaLabel:r("cap.import.destinationAria"),dataAttribute:"data-plugin-import-destination",options:[{value:"native",label:r("cap.import.destinationSession")},{value:"archive",label:r("cap.import.destinationArchive")}],onChange:G=>{w(G)}}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:r(y==="native"?"cap.import.destinationSessionHint":"cap.import.destinationArchiveHint")}),y==="native"?e.jsx(iF,{value:N,onChange:_,onPick:b.pickDirectory===void 0?void 0:()=>{we()},pickLabel:r("cap.import.pickWorkDir")}):null]})}),e.jsx(qa,{id:"plugin-import-source",title:r("cap.import.sourceTitle"),count:Y.length,aside:O!==void 0&&le?e.jsx("button",{type:"button",className:jn,onClick:()=>{n?.(O.pluginId)},"data-plugin-import-open-plugin":O.pluginId,children:r("cap.import.manageSource")}):void 0,children:se.isPending?e.jsx("p",{className:"py-2 text-[13px] text-ink-faint",role:"status",children:r("cap.import.loadingSources")}):se.isError?e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx(De,{error:se.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{se.refetch()},children:r("common.retry")})]}):Y.length===0?e.jsx("div",{className:"py-2","data-plugin-import-no-sources":!0,children:e.jsx(Za,{title:r("cap.import.noSourcesTitle"),body:r("cap.import.noSourcesBody")})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"flex w-fit min-w-0 max-w-full flex-wrap items-center gap-0.5 rounded-[9px] bg-ink/[0.04] p-0.5",role:"tablist","aria-label":r("cap.import.sourceAria"),children:Y.map(G=>e.jsx("button",{type:"button",role:"tab","aria-selected":il(te,G.pluginId,G.id),"data-plugin-import-source":`${G.pluginId}:${G.id}`,onClick:()=>{T(Xn(G.pluginId,G.id))},className:`inline-flex min-h-7 items-center rounded-[7px] px-3 text-[13px] whitespace-nowrap transition-colors duration-[var(--kiki-motion-quick)] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-selected-ink pointer-coarse:min-h-10 ${il(te,G.pluginId,G.id)?"bg-paper font-medium text-ink shadow-[var(--kiki-sheet-shadow)]":"text-ink-soft hover:text-ink"}`,children:G.label},Xn(G.pluginId,G.id)))})}),O!==void 0?e.jsx("p",{className:"mt-2 text-[12px] leading-4 text-ink-faint",children:r("cap.import.sourceFormat",{format:O.formatVersion})}):null,O!==void 0&&O.id==="custom"?e.jsx("div",{className:"mt-3","data-plugin-import-custom-settings":!0,children:e.jsx(t1,{pluginId:O.pluginId})}):null]})}),O!==void 0?e.jsx(qa,{id:"plugin-import-pick",title:r("cap.import.pickTitle"),children:e.jsx("div",{className:"min-w-0 space-y-4 pt-1",children:m?e.jsxs("div",{className:"min-w-0","data-plugin-import-readonly":!0,children:[e.jsx(Pf,{targetHome:ue,targetLabel:Te,remote:!0}),e.jsx("p",{className:"mt-2 max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:r("cap.import.readonlyBody")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 min-[720px]:grid-cols-2",children:[e.jsx(aF,{id:"plugin-import-home",label:r("cap.import.homeLabel"),hint:r("cap.import.homeHint"),value:Ne,onChange:P,onPick:b.pickDirectory===void 0?void 0:()=>{_e()},pickLabel:r("cap.import.pickHome"),placeholder:"C:\\Users\\you\\.claude",dataAttr:"data-plugin-import-home"}),e.jsx(Pf,{targetHome:ue,targetLabel:Te,remote:!1})]}),Ne===""?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:r("cap.import.homeRequired")}):e.jsx(rF,{pluginId:O.pluginId,sourceId:O.id,home:Ne,destination:k?C:void 0,selected:R,previewOpen:F!==null,onSelect:G=>{L(G?.externalId),$(null),H(null)},onPreview:$}),e.jsx(pe,{feedback:z===null?null:{tone:"error",text:z}})]})})}):null,F!==null&&O!==void 0?e.jsx("div",{ref:q,className:"scroll-mt-4",children:e.jsx(lF,{preview:F,targetLabel:Te,starting:E,onCancel:()=>{$(null)},onStart:()=>{J()}})}):null,e.jsx(qa,{id:"plugin-import-jobs",title:r("cap.import.jobsTitle"),count:fe.length,children:e.jsxs("div",{className:"pt-1","data-plugin-import-jobs-section":!0,children:[Ee.isPending?e.jsx("p",{className:"py-2 text-[13px] text-ink-faint",role:"status",children:r("cap.import.loadingJobs")}):Ee.isError?e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx(De,{error:Ee.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{Ee.refetch()},children:r("common.retry")})]}):fe.length===0?e.jsx("div",{className:"py-2","data-plugin-import-no-jobs":!0,children:e.jsx(Za,{title:r("cap.import.noJobsTitle"),body:r("cap.import.noJobsBody")})}):e.jsxs("ul",{className:"divide-y divide-hairline","data-plugin-import-jobs":!0,children:[fe.map(G=>e.jsx(dF,{job:G,remote:m,onOpenArchive:X,onOpenSession:a,onChanged:()=>{ee()}},G.id))," "]}),e.jsx(Ef,{cursor:Ee.hasNextPage?"more":null,moreLabel:r("cap.import.moreJobs",{count:fe.length}),onMore:()=>{Ee.fetchNextPage()}})]})}),e.jsx(qa,{id:"plugin-import-archives",title:r("cap.import.archivesTitle"),count:Ie.length,children:e.jsxs("div",{className:"pt-1","data-plugin-import-archives-section":!0,children:[me.isPending?e.jsx("p",{className:"py-2 text-[13px] text-ink-faint",role:"status",children:r("cap.import.loadingArchives")}):me.isError?e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx(De,{error:me.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{me.refetch()},children:r("common.retry")})]}):Ie.length===0?e.jsx("div",{className:"py-2","data-plugin-import-no-archives":!0,children:e.jsx(Za,{title:r("cap.import.noArchivesTitle"),body:r("cap.import.noArchivesBody")})}):e.jsx("ul",{className:"divide-y divide-hairline","data-plugin-import-archives":!0,children:Ie.map(G=>e.jsx(uF,{archive:G,onOpen:()=>{X(G.id)}},G.id))}),e.jsx(Ef,{cursor:me.hasNextPage?"more":null,moreLabel:r("cap.import.moreArchives",{count:Ie.length}),onMore:()=>{me.fetchNextPage()}})]})}),U!==null?e.jsx(tF,{archiveId:U,onClose:()=>{X(null)}}):null]})}function Ef({cursor:t,moreLabel:s,onMore:n}){const{t:a}=D();return t==null?null:e.jsxs("button",{type:"button",className:`${jn} -ml-3 mt-1`,"data-plugin-import-more":!0,onClick:n,children:[s,e.jsx(de,{name:"chevron",size:12,className:"rotate-90"}),e.jsx("span",{className:"sr-only",children:a("cap.import.loadMore")})]})}function Tf(t,s){const n=new Set,a=[];for(const i of t){const r=s(i);n.has(r)||(n.add(r),a.push(i))}return a}function If(t){return t?.pages.flatMap(s=>s.items)??[]}function nF(t){return t?.pages.flatMap(s=>s.items)??[]}function aF({id:t,label:s,hint:n,value:a,onChange:i,onPick:r,pickLabel:o,placeholder:l,dataAttr:c}){const{t:d}=D();return e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:t,className:"block text-[12px] font-medium text-ink-soft",children:s}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:t,[c]:"",value:a,spellCheck:!1,autoComplete:"off",placeholder:l,onChange:u=>{i(u.target.value)},className:"min-w-0 flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent"}),r!==void 0?e.jsx("button",{type:"button",className:`${Q} shrink-0`,onClick:r,"data-plugin-import-pick-home":!0,children:o}):null]}),e.jsx("p",{className:"mt-1 text-[12px] leading-4 text-ink-faint",children:n}),e.jsx("p",{className:"sr-only",children:d("cap.import.homeAria")})]})}function iF({value:t,onChange:s,onPick:n,pickLabel:a}){const{t:i}=D(),{client:r}=be(),l=je({queryKey:["workspaces","catalog"],queryFn:()=>r.listWorkspaceCatalog(),staleTime:3e4,retry:!1}).data?.items??[],c=t.trim();return e.jsxs("div",{className:"min-w-0","data-plugin-import-workdir":c===""?"unset":c,children:[e.jsx("label",{htmlFor:"plugin-import-workdir",className:"block text-[12px] font-medium text-ink-soft",children:i("cap.import.workDirLabel")}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:"plugin-import-workdir","data-plugin-import-workdir-input":!0,value:t,spellCheck:!1,autoComplete:"off",placeholder:l[0]?.root??"C:\\code\\my-project",onChange:d=>{s(d.target.value)},className:"min-w-0 flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[12px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent"}),n!==void 0?e.jsx("button",{type:"button",className:`${Q} shrink-0`,onClick:n,"data-plugin-import-pick-workdir":!0,children:a}):null]}),l.length>0?e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[12px] text-ink-faint",children:i("cap.import.workDirKnown")}),l.map(d=>{const u=d.root===c;return e.jsxs("button",{type:"button","aria-pressed":u,"data-plugin-import-workdir-option":d.root,onClick:()=>{s(d.root)},className:`inline-flex min-h-7 max-w-[46ch] items-center gap-1.5 rounded-md border px-2 text-[12px] transition-colors focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-selected-ink ${u?"border-accent bg-paper text-ink":"border-hairline text-ink-soft hover:bg-ink/[0.05] hover:text-ink"}`,children:[e.jsx(de,{name:"folder",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 truncate",children:d.name||dS(d.root)})]},d.id)})]}):null,c===""?e.jsx("p",{className:"mt-1.5 text-[12px] leading-4 text-ink-faint","data-plugin-import-workdir-required":!0,children:i("cap.import.workDirRequired")}):e.jsx("p",{className:"mt-1.5 text-[12px] leading-4 text-ink-faint",children:i("cap.import.workDirHint")})]})}function Pf({targetHome:t,targetLabel:s,remote:n}){const{t:a}=D();return e.jsxs("div",{className:"min-w-0","data-plugin-import-target":t??"unknown",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:a("cap.import.targetLabel")}),e.jsxs("div",{className:"mt-1.5 flex min-h-[34px] items-center gap-2 rounded-lg border border-hairline bg-ink/[0.03] px-3 py-1.5",children:[e.jsx(de,{name:"folder",size:14,className:"shrink-0 text-ink-faint"}),t===void 0?e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-ink-faint",children:a("cap.import.targetUnknown")}):e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-ink",title:`${s} · ${t}`,children:e.jsx("span",{className:"block truncate font-mono",children:t})}),e.jsx(Yt,{tone:n?"accent":"faint",children:a(n?"cap.import.targetRemote":"cap.import.targetLocal")})]}),e.jsx("p",{className:"mt-1 text-[12px] leading-4 text-ink-faint",children:a("cap.import.targetHint")})]})}function rF({pluginId:t,sourceId:s,home:n,destination:a,selected:i,previewOpen:r,onSelect:o,onPreview:l}){const{t:c}=D(),{client:d,scopeId:u}=be(),p=$i(d),[h,b]=x.useState(0),[m,f]=x.useState([]),[g,v]=x.useState(null);x.useEffect(()=>{b(0),f([]),v(null)},[n,s]);const y=je({queryKey:$s.discovery(u,t,s,`${n}#${m.join(">")}`),queryFn:async()=>p.discover({pluginId:t,sourceId:s,home:n,...h===0?{}:{cursor:m.at(-1)}}),enabled:n!=="",staleTime:3e4,retry:!1}),w=y.data?.entries??[],N=y.data?.cursor,_=N!=null;return e.jsxs("div",{className:"min-w-0","data-plugin-import-discovery":Xn(t,s),children:[e.jsxs("div",{className:"flex min-h-8 items-center gap-2",children:[e.jsx("h3",{className:"text-[12px] font-medium text-ink-soft",children:c("cap.import.filesTitle")}),w.length>0?e.jsx("span",{className:"text-[12px] tabular-nums text-ink-faint",children:w.length}):null,e.jsxs("span",{className:"ms-auto flex items-center gap-1",children:[h>0?e.jsx("button",{type:"button",className:jn,"data-plugin-import-first-page":!0,onClick:()=>{b(0),f([]),v(null)},children:c("cap.import.firstPage")}):null,_?e.jsx("button",{type:"button",className:jn,"data-plugin-import-next-page":!0,onClick:()=>{f(C=>[...C,N]),b(C=>C+1),v(null)},children:c("cap.import.nextPage")}):null,y.isFetching?e.jsx(Us,{label:c("cap.import.loadingFiles"),size:12}):null]})]}),g!==null?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g}):null,y.isPending?e.jsx("p",{className:"py-2 text-[13px] text-ink-faint",role:"status",children:c("cap.import.loadingFiles")}):y.isError?e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx(De,{error:y.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{y.refetch()},children:c("common.retry")})]}):r?e.jsx("ul",{className:"mt-1 divide-y divide-hairline border-y border-hairline",children:w.filter(C=>C.externalId===i).map(C=>e.jsxs("li",{"data-plugin-import-file":C.externalId,"aria-current":"true",className:"flex min-h-11 min-w-0 items-center gap-3 rounded-md bg-paper px-2 py-1.5 shadow-[var(--kiki-sheet-shadow)]",children:[e.jsx(de,{name:"file",size:14,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:C.title||oi(C.externalId)})]},C.externalId))}):w.length===0?e.jsx("div",{className:"py-2","data-plugin-import-no-files":!0,children:e.jsx(Za,{title:c("cap.import.noFilesTitle"),body:c("cap.import.noFilesBody",{home:zb(n)})})}):e.jsx("ul",{className:"mt-1 divide-y divide-hairline border-y border-hairline",children:w.map(C=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-plugin-import-file":C.externalId,"aria-current":i===C.externalId?"true":void 0,onClick:()=>{o(C)},className:`flex w-full min-h-11 min-w-0 items-center gap-3 rounded-md px-2 py-1.5 text-left transition-colors focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-selected-ink ${i===C.externalId?"bg-paper shadow-[var(--kiki-sheet-shadow)]":"hover:bg-ink/[0.04]"}`,children:[e.jsx(de,{name:"file",size:14,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:C.title||oi(C.externalId)}),C.title!==""?e.jsx("span",{className:"hidden min-w-0 max-w-[45%] truncate font-mono text-[11px] text-ink-faint min-[560px]:block",title:C.externalId,children:oi(C.externalId)}):null]})},C.externalId))}),i!==void 0?e.jsx(oF,{pluginId:t,sourceId:s,home:n,destination:a,externalId:i,onPreview:l}):null,i!==void 0&&r?e.jsxs("button",{type:"button",className:`${jn} -ml-3 mt-1`,"data-plugin-import-change-file":!0,onClick:()=>{o(void 0),l(null)},children:[e.jsx(de,{name:"arrowLeft",size:14,className:"text-ink-faint"}),c("cap.import.changeFile")]}):null]})}function oF({pluginId:t,sourceId:s,home:n,destination:a,externalId:i,onPreview:r}){const{t:o}=D(),{client:l,scopeId:c}=be(),d=$i(l),u=je({queryKey:$s.preview(c,`${Xn(t,s)}:${n}:${i}`,Ec(a)),queryFn:async()=>d.preview({pluginId:t,sourceId:s,home:n,externalId:i,...a===void 0?{}:{destination:a}}),enabled:a!==void 0,staleTime:0,retry:!1});return x.useEffect(()=>{u.data!==void 0&&r(u.data)},[u.data,r]),u.isError?e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx(De,{error:u.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{u.refetch()},children:o("common.retry")})]}):u.isPending?e.jsxs("p",{className:"mt-2 flex items-center gap-2 text-[12px] text-ink-faint",role:"status","data-plugin-import-preview-loading":!0,children:[e.jsx(Us,{label:o("cap.import.previewLoading"),size:12}),o("cap.import.previewLoading")]}):null}function lF({preview:t,targetLabel:s,starting:n,onCancel:a,onStart:i}){const{t:r}=D(),o=t.losses.length>0?t.losses:t.probe.losses,l=vi(o),c=uS(t.destination),d=Qb(t.destination);return e.jsxs("section",{id:"plugin-import-preview","data-plugin-import-preview":t.id,"data-plugin-import-coverage":t.coverage,"data-plugin-import-probe":t.probe.status,"data-plugin-import-preview-kind":c?"native-session":"archive",className:"anim-enter min-w-0 space-y-3 rounded-xl border border-hairline bg-panel p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-x-3 gap-y-1",children:[e.jsx("h2",{className:"w-full min-w-0 text-[14px] font-medium leading-5 text-ink min-[560px]:w-auto min-[560px]:flex-1",children:t.probe.title||r("cap.import.untitled")}),e.jsx(Yt,{tone:t.probe.status==="preserved"?"success":t.probe.status==="partial"?"warn":"danger",children:r(pS(t.probe.status))}),e.jsx(Yt,{children:t.coverage==="sample"?r("cap.import.coverageSample"):r("cap.import.coverageComplete")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint","data-plugin-import-preview-where":!0,children:c?r("cap.import.previewSessionTarget",{dir:d??""}):r("cap.import.previewTarget",{home:t.targetHome,server:s})}),c?t.existingSessionId!==null&&t.existingSessionId!==void 0?e.jsx("p",{className:"text-[12px] leading-4 text-amber-ink","data-plugin-import-existing-session":!0,children:r("cap.import.alreadyImportedSession",{dir:d??""})}):null:t.existingArchiveId!==null?e.jsx("p",{className:"text-[12px] leading-4 text-amber-ink","data-plugin-import-existing":!0,children:r("cap.import.alreadyImported",{revision:mS(t.existingRevision)})}):null,l>0?e.jsxs("div",{"data-plugin-import-losses":!0,className:"space-y-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-soft",children:r("cap.import.lossesTitle",{count:l})}),e.jsx("ul",{className:"space-y-0.5",children:o.map(u=>e.jsxs("li",{"data-plugin-import-loss":u.code,className:"flex min-w-0 items-baseline gap-2 text-[12px] leading-4 text-ink-soft",children:[e.jsx("span",{className:"shrink-0 tabular-nums text-ink-faint",children:u.count}),e.jsx("span",{className:"min-w-0 flex-1",children:u.detail||u.code})]},u.code))})]}):e.jsx("p",{className:"text-[12px] leading-4 text-ink-soft","data-plugin-import-no-losses":!0,children:r("cap.import.noLosses")}),e.jsx(cF,{preview:t}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-3",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] leading-4 text-ink-faint","data-plugin-import-preview-note":!0,children:r(c?"cap.import.previewSessionNote":"cap.import.previewNote")}),e.jsx("button",{type:"button",className:Q,disabled:n,onClick:a,children:r("common.cancel")}),e.jsxs("button",{type:"button",className:Ye,disabled:n,"data-plugin-import-start":!0,onClick:i,"aria-busy":n,children:[n?e.jsx(Us,{label:r("cap.import.starting"),size:12}):null,r(n?"cap.import.starting":c?"cap.import.startSession":"cap.import.start")]})]})]})}function cF({preview:t}){const{t:s}=D(),[n,a]=x.useState(!1),i=t.records;return e.jsxs("div",{className:"min-w-0","data-plugin-import-sample":!0,children:[e.jsxs("button",{type:"button",className:"flex min-h-8 items-center gap-1.5 rounded-md px-1 text-[12px] font-medium text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink","aria-expanded":n,"data-plugin-import-sample-toggle":!0,onClick:()=>{a(r=>!r)},children:[e.jsx("span",{"aria-hidden":!0,className:`flex text-ink-faint transition-transform duration-[var(--kiki-motion-quick)] motion-reduce:transition-none ${n?"rotate-90":""}`,children:e.jsx(de,{name:"chevron",size:12})}),s("cap.import.sampleTitle",{count:i.length})]}),n?e.jsxs("ol",{className:"mt-1 space-y-2 border-l border-hairline pl-3",children:[i.map((r,o)=>e.jsxs("li",{className:"min-w-0 space-y-0.5",children:[e.jsxs("p",{className:"text-[11.5px] font-medium text-ink-faint",children:[s(Hb(r.role)),r.toolName!==void 0?e.jsxs("span",{className:"font-mono",children:[" · ",r.toolName]}):null]}),r.text!==void 0&&r.text!==""?e.jsx("p",{className:"line-clamp-3 break-words whitespace-pre-wrap text-[12.5px] leading-[1.5] text-ink-soft",children:r.text}):null]},`${r.id}-${r.part}-${o}`)),i.length===0?e.jsx("li",{className:"text-[12px] text-ink-faint",children:s("cap.import.sampleEmpty")}):null]}):null]})}function dF({job:t,remote:s,onOpenArchive:n,onOpenSession:a,onChanged:i}){const{t:r,tp:o,locale:l}=D(),{client:c}=be(),d=$i(c),[u,p]=x.useState(!1),[h,b]=x.useState(null),m=xS(t),f=cr(t),g=hS.has(t.status),v=fS(t),y=Qb(t.destination),w=async N=>{p(!0),b(null);try{N==="cancel"?await d.cancel(t.id):await d.resume(t.id),i()}catch(_){b(oe(l,_))}finally{p(!1)}};return e.jsxs("li",{className:"min-w-0 py-2.5","data-plugin-import-job":t.id,"data-plugin-import-job-state":t.status,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-ink",children:t.title||r("cap.import.untitled")}),e.jsx(Yt,{tone:t.status==="completed"?"success":t.status==="failed"?"danger":g?"warn":f?"accent":"faint",children:r(bS(t.status))})]}),e.jsxs("p",{className:"mt-0.5 min-w-0 truncate font-mono text-[11px] text-ink-faint",title:`${t.selection.externalId}
|
|
253
|
+
${t.sourceHome} → ${y??t.targetHome}`,children:[e.jsxs("span",{className:"min-[720px]:hidden",children:[oi(t.selection.externalId)," · "]}),zb(t.sourceHome)," → ",y??t.targetHome]}),f?e.jsxs("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:[e.jsx("div",{role:"progressbar","aria-label":r("cap.import.progress",{title:t.title}),"aria-valuemin":0,"aria-valuemax":m?.total??0,"aria-valuenow":m?.value??0,"data-plugin-import-progress":!0,"data-indeterminate":m?.ratio===void 0?"true":void 0,className:"h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-hairline",children:e.jsx("div",{className:`h-full rounded-full bg-ink-soft transition-[width] duration-[var(--kiki-motion-quick)] motion-reduce:transition-none ${m?.ratio===void 0?"w-1/3 animate-pulse":""}`,style:m?.ratio===void 0?void 0:{width:`${Math.round(m.ratio*100)}%`}})}),e.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-ink-faint",children:m?.ratio===void 0?r("cap.import.readingBytes",{count:m?.value??t.bytesRead}):r("cap.import.readingPercent",{percent:Math.round(m.ratio*100)})})]}):null,t.status==="failed"&&t.error!==null?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] leading-4 text-danger","data-plugin-import-job-error":!0,children:t.error}):null,h!==null?e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:h}):null,e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[f&&!s?e.jsx("button",{type:"button",className:Q,disabled:u,onClick:()=>{w("cancel")},"data-plugin-import-cancel":t.id,children:r("cap.import.cancel")}):null,g&&!s?e.jsx("button",{type:"button",className:Q,disabled:u,onClick:()=>{w("resume")},"data-plugin-import-resume":t.id,children:r("cap.import.resume")}):null,v!==void 0&&a!==void 0?e.jsx("button",{type:"button",className:Ye,"data-plugin-import-open-session":v,onClick:()=>{a(v)},children:r("cap.import.openSession")}):null,t.archiveId!==null?e.jsx("button",{type:"button",className:jn,"data-plugin-import-open":t.archiveId,onClick:()=>{n(t.archiveId)},children:r("cap.import.openArchive")}):null,vi(t.losses)>0?e.jsx("span",{className:"text-[11px] text-ink-faint",children:r("cap.import.jobLosses",{count:vi(t.losses)})}):null,e.jsx("span",{className:"ms-auto text-[11px] tabular-nums text-ink-faint",children:qd(o,t.records,t.pages)})]})]})}function uF({archive:t,onOpen:s}){const{t:n,tp:a}=D();return e.jsxs("li",{className:"min-w-0 py-2.5","data-plugin-import-archive":t.id,"data-plugin-import-archive-state":t.status,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 truncate rounded-sm py-0.5 text-left text-[13px] font-medium text-ink transition-colors hover:text-selected-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink","data-plugin-import-archive-open":t.id,onClick:s,children:t.title||n("cap.import.untitled")}),e.jsx(Yt,{tone:t.status==="preserved"?"success":"warn",children:n(gS(t.status))})]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 flex-wrap items-baseline gap-x-2 text-[11px] text-ink-faint",children:[e.jsxs("span",{className:"min-w-0 truncate font-mono",title:`${t.sourceId} · ${t.externalId}`,children:[t.sourceId," · ",oi(t.externalId)]}),e.jsx("span",{className:"shrink-0 tabular-nums",children:qd(a,t.records,t.pages)}),vi(t.losses)>0?e.jsx("span",{className:"shrink-0",children:n("cap.import.jobLosses",{count:vi(t.losses)})}):null]})]})}function pF(){const{t}=D(),s=Et(),[n]=no(),a=n.get("source")??void 0,i=n.get("sourcePlugin")??void 0;return e.jsxs("div",{className:"space-y-4","data-sessions-import-page":Nd(),children:[e.jsx(sF,{initialSourceId:a===""?void 0:a,initialSourcePluginId:i===""?void 0:i,onOpenPlugin:r=>{s(An(r))},onOpenSession:r=>{s(`/s/${r}`)},onBack:()=>{s(e0())}}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:()=>{s(db())},className:"text-[12px] text-ink-faint transition-colors hover:text-ink","data-sessions-import-plugins":!0,children:t("st.sessions.importBrowsePlugins")})})]})}const mF=["windows","macos","linux"],Ja={windows:"Windows",macos:"macOS",linux:"Linux"},xF=["global","session","composer","approval","terminal"],hF={global:"shortcuts.group.global",session:"shortcuts.group.session",composer:"st.shortcuts.group.composer",approval:"shortcuts.group.approvals",terminal:"shortcuts.group.terminal"},fF={shortcuts:"st.shortcuts.action.panelGlobal","shortcuts-help":"st.shortcuts.action.panelOutsideFields"},bF={"next-session":"shortcuts.runningThreadsNote","previous-session":"shortcuts.runningThreadsNote",shortcuts:"st.shortcuts.note.anywhere","shortcuts-help":"st.shortcuts.note.outsideFields",approve:"st.shortcuts.note.outsideFields",reject:"st.shortcuts.note.outsideFields"};function gF(t,s,n,a){const i=a0.parse(structuredClone(t));return i.overrides[s]={...i.overrides[s],[n]:[...a]},i}function vF(t,s,n,a,i){const r=wa(n,a).join("+"),o=t.filter(d=>d.actions.includes(s));if(o.find(d=>d.kind==="reserved")!==void 0)return i("st.shortcuts.conflictReserved",{keys:r});const c=o.find(d=>d.kind==="duplicate"&&d.actions.length===2);if(c!==void 0){const d=c.actions.find(p=>p!==s)??s,u=Td.find(p=>p.id===d)?.labelKey;return i("st.shortcuts.conflictUsed",{keys:r,action:u===void 0?d:i(u)})}return o.length>0?i("st.shortcuts.conflictSelf",{keys:r}):null}function yF(t){if(!(t instanceof su))return[];const s=t.details;if(s===null||typeof s!="object"||!("conflicts"in s))return[];const n=n0.array().safeParse(s.conflicts);return n.success?n.data:[]}function kF(t,s,n,a){const i=t.filter(c=>c.actions.includes(s)),r=i.find(c=>c.platform===n)??i[0];if(r===void 0)return null;if(r.kind==="reserved")return a("st.shortcuts.conflictReserved",{keys:r.key});const o=r.actions.find(c=>c!==s);if(o===void 0)return a("st.shortcuts.conflictSelf",{keys:r.key});const l=Td.find(c=>c.id===o)?.labelKey;return a("st.shortcuts.conflictUsed",{keys:r.key,action:l===void 0?o:a(l)})}function jF(){const{client:t,localClient:s,connectionId:n,connectionSource:a}=be(),i=typeof n=="string"&&n!=="",r=i?s:t,o=!i&&zs(a)&&s===null,{t:l,locale:c}=D(),u=mt().kind==="tauri",p=Oe(),h=x.useMemo(ag,[]),[b,m]=x.useState(h),[f,g]=x.useState(null),[v,y]=x.useState(null),[w,N]=x.useState(!1),[_,C]=Je(),[S,k]=x.useState(null),[j,T]=x.useState([]),A=je({queryKey:[...rl,b],queryFn:()=>r.readShortcuts(b),enabled:r!==null,staleTime:6e4,retry:!1}),P=se=>{p.setQueryData([...rl,b],se),p.invalidateQueries({queryKey:rl,predicate:Y=>Y.queryKey[1]!==b}),U1(se.preferences)},R=async(se,Y)=>{N(!0),k(null);try{return P(await se()),T([]),C(),!0}catch(O){const B=yF(O);T(B);const le=Y===void 0?null:kF(B,Y.action,b,l);return Y!==void 0&&le!==null?(y({action:Y.action,text:le}),!1):(y(null),k({tone:"error",text:oe(c,O)}),!1)}finally{N(!1)}},L=A.data,I=L?.preferences,$=L?.bindings,E=async(se,Y,O)=>{if(I===void 0||r===null)return;const B=gF(I,b,se,Y),le=s0(B,b),re=O===void 0?null:vF(le,se,O,b,l);if(re!==null||le.some(ae=>ae.actions.includes(se))){y({action:se,text:re??l("st.shortcuts.conflictGeneric")});return}y(null),await R(()=>r.writeShortcuts(b,B),{action:se})},M=(se,Y)=>{g(null);const O=$?.[se.action]??[];if(O.some((le,re)=>re!==se.index&&q1(le,Y))){y({action:se.action,text:l("st.shortcuts.conflictSelf",{keys:wa(Y,b).join("+")})});return}const B=[...O];B.splice(se.index,se.index<O.length?1:0,Y),E(se.action,B,Y)},z=(se,Y)=>{const O=($?.[se]??[]).filter((B,le)=>le!==Y);E(se,O)},H=se=>{r!==null&&(y(null),R(()=>r.resetShortcuts(b,{platform:b,action:se}),{action:se}))},U=()=>{if(y(null),I===void 0||r===null)return;const se=I;R(()=>r.resetShortcuts(b,{platform:b})).then(Y=>{Y&&xs({text:l("st.shortcuts.resetDone",{name:Ja[b]}),undoFailedText:l("toast.undoFailed"),undo:async()=>{await R(()=>r.writeShortcuts(b,se))}})})},X=se=>I?.overrides[b]?.[se]!==void 0,q=Object.keys(I?.overrides[b]??{}).length>0,F=[...L?.conflicts??[],...j],V=xF.map(se=>({context:se,definitions:Td.filter(Y=>Y.context===se)})).filter(se=>se.definitions.length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Me,{id:"st-card-shortcuts",title:l("st.shortcuts.title"),scope:"server",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsx("p",{className:"mr-auto max-w-[52ch] text-[13px] leading-5 text-ink-soft",children:l("st.shortcuts.intro")}),e.jsx(ot,{saving:w,saved:_}),e.jsx(He,{ariaLabel:l("st.shortcuts.platform"),dataAttr:"data-shortcut-platform",value:b,onChange:se=>{m(se),g(null),y(null),k(null)},choices:mF.map(se=>({value:se,label:se===h?l("st.shortcuts.platformThis",{name:Ja[se]}):Ja[se]}))})]}),b!==h?e.jsx("p",{"data-shortcut-other-platform":!0,className:"text-[12px] text-ink-faint",children:l("st.shortcuts.otherPlatform",{name:Ja[b]})}):null,r===null||o?e.jsx(he,{children:l("st.remote.controlUnavailable")}):null,r!==null&&A.isLoading?e.jsx(he,{children:l("st.shortcuts.loading")}):null,r!==null&&A.isError?ja(A.error)?e.jsx(he,{children:l("st.remote.controlUnavailable")}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(De,{error:A.error}),e.jsx(he,{children:l("st.shortcuts.loadFailed")})]}):null,$!==void 0?V.map(se=>e.jsxs("div",{"data-shortcut-group":se.context,children:[e.jsx("p",{className:"pb-1 text-[12px] font-medium text-section-ink",children:l(hF[se.context])}),e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline",children:se.definitions.map(Y=>e.jsx(wF,{definition:Y,platform:b,chords:$[Y.id]??[],overridden:X(Y.id),desktop:u,readOnly:o,busy:w,recordingIndex:f?.action===Y.id?f.index:null,issue:v?.action===Y.id?v.text:null,serverConflict:F.some(O=>O.actions.includes(Y.id)),onRecord:O=>{o||(y(null),k(null),g({action:Y.id,index:O}))},onRecorded:O=>{f!==null&&!o&&M(f,O)},onCancel:()=>{g(null)},onRemove:O=>{o||z(Y.id,O)},onReset:()=>{o||H(Y.id)}},Y.id))})]},se.context)):null,e.jsx(pe,{feedback:S}),$!==void 0&&!o?e.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[e.jsx("button",{type:"button","data-shortcut-reset-all":!0,className:Q,disabled:w||!q,onClick:U,children:l("st.shortcuts.resetAll",{name:Ja[b]})}),q?null:e.jsx("span",{className:"text-[12px] text-ink-faint",children:l("st.shortcuts.allDefault")})]}):null]})}),e.jsx(NF,{platform:b,desktop:u})]})}function Bk({keys:t}){return e.jsx("span",{className:"inline-flex items-center gap-0.5",children:t.map((s,n)=>e.jsx("kbd",{className:"min-w-[1.4rem] rounded-[4px] border border-hairline bg-paper px-1.5 py-px text-center font-mono text-[11px] font-medium text-ink shadow-[0_1px_0_var(--color-hairline-strong)]",children:s},`${s}-${n}`))})}function wF({definition:t,platform:s,chords:n,overridden:a,desktop:i,readOnly:r=!1,busy:o,recordingIndex:l,issue:c,serverConflict:d,onRecord:u,onRecorded:p,onCancel:h,onRemove:b,onReset:m}){const{t:f}=D(),g=f(fF[t.id]??t.labelKey),v=bF[t.id],y=`shortcut-issue-${t.id}`,w=!r&&n.length<4&&l===null;return e.jsxs("li",{"data-shortcut-row":t.id,"data-shortcut-overridden":a?"true":"false",className:"flex flex-col gap-2 py-2 sm:flex-row sm:items-start sm:justify-between sm:gap-6",children:[e.jsxs("div",{className:"min-w-0 sm:pt-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[13px] text-ink",children:[e.jsx("span",{children:g}),a?e.jsxs("span",{"data-shortcut-custom":!0,className:"inline-flex items-center gap-1 text-[11.5px] text-selected-ink",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-selected-ink"}),f("st.shortcuts.custom")]}):null,(t.desktopOnly||n.some(ig))&&!i?e.jsx("span",{className:"text-[11.5px] text-ink-faint",children:f("shortcuts.desktopOnly")}):null]}),v!==void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:f(v)}):null,d&&c===null?e.jsx("p",{className:"text-[12px] text-amber-ink",children:f("st.shortcuts.savedConflict")}):null,c!==null?e.jsx("p",{id:y,role:"alert","data-shortcut-issue":!0,className:"mt-0.5 text-[12px] text-danger",children:c}):null]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-1.5 sm:justify-end",children:[n.length===0&&l===null?e.jsx("span",{"data-shortcut-disabled":!0,className:"text-[12px] text-ink-faint",children:f("st.shortcuts.disabled")}):null,n.map((N,_)=>l===_?e.jsx(Af,{platform:s,desktop:i,describedBy:c===null?void 0:y,onRecorded:p,onCancel:h,onDisable:()=>{h(),b(_)}},`rec-${_}`):e.jsx("button",{type:"button","data-shortcut-chord":_,disabled:r||o||l!==null,"aria-label":f("st.shortcuts.changeAria",{action:g,keys:wa(N,s).join("+")}),onClick:()=>{u(_)},className:"inline-flex min-h-8 items-center rounded-md px-1.5 transition-colors hover:bg-ink/[0.05] focus-visible:outline-2 focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-60 pointer-coarse:min-h-11",children:e.jsx(Bk,{keys:wa(N,s)})},`${N.key}-${N.modifier}-${_}`)),l!==null&&l>=n.length?e.jsx(Af,{platform:s,desktop:i,describedBy:c===null?void 0:y,onRecorded:p,onCancel:h}):null,w?e.jsx("button",{type:"button","data-shortcut-add":!0,disabled:o,"aria-label":f("st.shortcuts.addAria",{action:g}),title:f("st.shortcuts.add"),onClick:()=>{u(n.length)},className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink disabled:opacity-50 pointer-coarse:h-11 pointer-coarse:w-11",children:e.jsx("span",{"aria-hidden":!0,className:"text-[15px] leading-none",children:"+"})}):null,a&&!r?e.jsx("button",{type:"button","data-shortcut-reset":!0,disabled:o||l!==null,onClick:m,"aria-label":f("st.shortcuts.resetAria",{action:g}),className:"h-8 rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink disabled:opacity-50 pointer-coarse:h-11",children:f("st.shortcuts.reset")}):null]})]})}function Af({platform:t,desktop:s,describedBy:n,onRecorded:a,onCancel:i,onDisable:r}){const{t:o}=D(),l=x.useRef(null),[c,d]=x.useState(null),[u,p]=x.useState(!1);return x.useEffect(()=>{const h=B1();return l.current?.focus(),h},[]),e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsxs("button",{ref:l,type:"button","data-shortcut-recording":!0,"aria-describedby":n,"aria-label":o("st.shortcuts.recordingAria"),onBlur:i,onKeyDown:h=>{if(h.nativeEvent.isComposing)return;const b=!h.ctrlKey&&!h.metaKey&&!h.altKey&&!h.shiftKey;if(h.key==="Tab"){!b&&!s&&(h.preventDefault(),d(null),p(!0));return}if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"&&b){i();return}if((h.key==="Backspace"||h.key==="Delete")&&b&&r!==void 0){r();return}const m=K1(h,t);if(m.kind!=="pending"){if(m.kind==="unsupported"){d(m.key);return}if(!s&&ig(m.chord)){d(null),p(!0);return}a(m.chord)}},className:"inline-flex min-h-8 min-w-[9rem] items-center justify-center gap-1.5 rounded-md bg-selected px-3 text-[12px] font-medium text-selected-ink outline-2 outline-selected-ink/60 [outline-style:solid] pointer-coarse:min-h-11",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 animate-pulse rounded-full bg-selected-ink motion-reduce:animate-none"}),o("st.shortcuts.recording")]}),e.jsx("span",{className:"text-[11px] text-ink-faint",children:c!==null?o("st.shortcuts.unsupported",{key:c}):o(r!==void 0?"st.shortcuts.recordHintClear":"st.shortcuts.recordHint")}),u?e.jsx("span",{"data-shortcut-browser-warning":!0,role:"status",className:"max-w-[16rem] text-right text-[11px] leading-tight text-amber-ink/90",children:o("st.shortcuts.browserReservedWarning")}):null]})}function NF({platform:t,desktop:s}){const{t:n}=D(),a=new Set,i=t0.filter(r=>"managedBy"in r&&r.managedBy!=="sendShortcut"&&(s||!r.desktopOnly)).map(r=>({id:r.id,labelKey:r.labelKey,chords:[...r.defaults]})).filter(r=>{const o=`${r.labelKey}:${r.chords.map(l=>wa(l,t).join("+")).join(",")}`;return a.has(o)?!1:(a.add(o),!0)});return e.jsxs(Me,{id:"st-card-shortcuts-fixed",title:n("st.shortcuts.fixedTitle"),scope:"app",children:[e.jsx("p",{className:"mb-3 max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:n("st.shortcuts.fixedHint")}),e.jsx("ul",{className:"divide-y divide-hairline border-y border-hairline",children:i.map(r=>e.jsxs("li",{"data-shortcut-fixed":r.id,className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{className:"min-w-0 text-[12.5px] text-ink-soft",children:n(r.labelKey)}),e.jsx("span",{className:"flex shrink-0 items-center gap-1.5",children:r.chords.map((o,l)=>e.jsx(Bk,{keys:wa(o,t)},l))})]},r.id))})]})}const SF=new Set(["device","connection"]),Kk=Ai.filter(t=>t.kind==="group"&&SF.has(t.id));function CF(t){const s=xb(t);return Kk.some(n=>n.kind==="group"&&(n.sections.includes(t)||n.sections.includes(s)))}function Uk(t){return t!=="shortcuts"}const _F=6e4;function EF(t){return ha(t)||t.enabled===!1?null:t.status==="error"?"st.connections.statusError":t.status!=="unconfigured"?null:t.oauth!==void 0?"st.account.state.signIn":!t.has_api_key&&t.api_key_env===void 0&&!uo(t.base_url)?"st.connections.statusNeedsKey":"st.connections.statusSetup"}function TF(t){return t.state==="error"||t.hasErrors}function IF(t=!1){const s=Hd()?.client,a={enabled:s!==void 0&&!t,staleTime:_F,refetchOnWindowFocus:!1,refetchOnReconnect:!1},i=je({queryKey:["providers"],queryFn:()=>s.listProviders(),...a}),r=je({queryKey:vS.installed,queryFn:()=>s.listPlugins(),...a}),o=i.status==="success"?i.data.items:void 0,l=r.status==="success"?r.data.plugins:void 0;return x.useMemo(()=>[...(o??[]).flatMap(c=>{const d=EF(c);return d===null?[]:[{key:`connection:${c.id}`,section:"ai",object:c.id,problemKey:d,target:"ai?tab=providers#st-card-providers"}]}),...(l??[]).filter(TF).map(c=>({key:`plugin:${c.id}`,section:"extensions",object:c.displayName,problemKey:"st.plugins.error",target:An(c.id).replace(/^\/settings\//u,"")}))],[o,l])}function Ju({focusToken:t,onSearchHit:s,className:n="",idle:a,navTree:i=Ai,onDismiss:r,floatingResults:o=!1}){const{t:l}=D(),[c,d]=x.useState(""),u=x.useRef(null),p=tu(),h=x.useMemo(()=>{const f=new Set(i.flatMap(v=>v.kind==="group"?v.sections:[v.section])),g=i0(ab(l),l,i).filter(v=>f.has(v.section));return p?g.filter(v=>Uk(v.section)):g},[l,i,p]),b=x.useMemo(()=>r0(h,c),[h,c]),m=c.trim()!=="";return x.useEffect(()=>{if(t===null)return;const f=u.current;f===null||f.offsetParent===null||(f.focus(),f.select())},[t]),e.jsxs("div",{className:o?n:`relative ${n}`.trim(),children:[o?null:e.jsx(de,{name:"search",size:12,className:"pointer-events-none absolute left-2.5 top-2 text-ink-faint pointer-coarse:top-4"}),e.jsx("input",{ref:u,type:"search","data-settings-search":!0,"aria-label":l("st.search.aria"),placeholder:l("st.search.placeholder"),value:c,onChange:f=>{d(f.target.value)},onKeyDown:f=>{rt(f)||(f.key==="Escape"?(f.stopPropagation(),d(""),f.currentTarget.blur(),r?.()):f.key==="Enter"&&b.length>0&&(f.preventDefault(),s(b[0]),d("")))},className:`h-7 w-full rounded-md bg-ink/[0.04] ${o?"px-3":"pl-8 pr-2.5"} text-[12.5px] text-ink outline-none transition-colors placeholder:text-ink-faint hover:bg-ink/[0.06] focus:bg-panel focus:shadow-[inset_0_0_0_1px_var(--color-hairline-strong)] pointer-coarse:h-11 pointer-coarse:text-[15px]`}),m?e.jsxs("div",{role:"listbox","aria-label":l("st.search.aria"),"data-settings-search-results":!0,className:o?"absolute inset-x-0 top-full z-20 flex max-h-[min(60vh,28rem)] flex-col gap-0.5 overflow-y-auto overscroll-y-contain border-b border-hairline bg-canvas px-3 py-2 shadow-[var(--kiki-sheet-shadow)]":"mt-2 flex flex-col gap-0.5",children:[b.map(f=>e.jsxs("button",{type:"button",role:"option","aria-selected":"false",onClick:()=>{s(f),d("")},className:"w-full rounded-md px-2 py-1.5 text-left transition-colors hover:bg-ink/[0.04] pointer-coarse:min-h-11",children:[e.jsx("span",{className:"block truncate text-[13px] text-ink",children:f.title}),e.jsxs("span",{className:"block truncate text-[12px] leading-4 text-ink-faint",children:[f.groupLabel!==""?e.jsxs(e.Fragment,{children:[f.groupLabel,e.jsx(de,{name:"chevron",size:12,className:"mx-0.5 inline-block align-[-2px]"})]}):null,f.sectionLabel]})]},f.cardId)),b.length===0?e.jsx("p",{className:"px-2 py-1.5 text-[12px] text-ink-faint",children:l("st.search.empty",{query:c.trim()})}):null]}):a??null]})}function PF({active:t,activeTab:s,onNavigate:n,onAfterNavigate:a,tree:i=Ai,showAttention:r=!1,remoteNotice:o}){const{t:l}=D(),c=tu(),d=IF(o!==void 0),u=f=>qk.find(g=>g.id===f)?.labelKey,p=t!==null?xb(t):null,h=x.useMemo(()=>new Set(d.map(f=>f.section)),[d]),b=f=>{const g=u(f);if(g===void 0||c&&!Uk(f)&&f!==t)return null;const v=f===t||f===p;return e.jsxs("button",{type:"button","data-settings-nav-leaf":f,"aria-current":v?"page":void 0,onClick:()=>{n(f),a?.()},className:`row-interactive flex h-7 items-center gap-2 px-2.5 text-left text-[13px] pointer-coarse:h-11 pointer-coarse:px-3 pointer-coarse:text-[15px] ${v?"font-medium text-ink":"text-ink-soft hover:text-ink"}`,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:l(g)}),h.has(f)?e.jsx("span",{"data-settings-nav-attention":f,className:"shrink-0 text-[11.5px] font-normal text-attention pointer-coarse:text-[12px]",children:l("st.nav.leafAttention")}):null]},f)},m=i.filter(f=>f.kind==="group"&&f.sections.length>0);return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2.5 pointer-coarse:mt-4 pointer-coarse:gap-4","data-settings-nav-tree":!0,children:[r&&d.length>0?e.jsxs("div",{"data-settings-attention":!0,children:[e.jsx("p",{className:"flex h-[22px] items-center px-2.5 text-[11px] font-medium text-attention pointer-coarse:h-7 pointer-coarse:text-[12px]",children:l("st.nav.needsAttention")}),e.jsx("div",{className:"flex flex-col gap-0 pointer-coarse:gap-0.5",children:d.map(f=>{const g=u(f.section);return e.jsxs("button",{type:"button","data-settings-attention-row":f.key,onClick:()=>{n(f.target),a?.()},className:"row-interactive flex h-7 items-center gap-2 px-2.5 text-left text-[13px] text-ink pointer-coarse:h-11 pointer-coarse:px-3 pointer-coarse:text-[15px]",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:l("st.nav.attentionRow",{section:g===void 0?f.section:l(g),object:f.object,problem:l(f.problemKey)})}),e.jsx(de,{name:"chevron",size:12,className:"shrink-0 text-ink-faint"})]},f.key)})})]}):null,m.map(f=>e.jsxs("div",{"data-settings-nav-group":f.id,children:[e.jsx("p",{className:"flex h-[22px] items-center px-2.5 text-[11px] font-medium text-ink-faint pointer-coarse:h-7 pointer-coarse:text-[12px]",children:l(f.labelKey)}),e.jsx("div",{className:"flex flex-col gap-0 pointer-coarse:gap-0.5",children:f.sections.map(g=>b(g))})]},f.id)),o!==void 0?e.jsx("p",{"data-settings-remote-nav-note":!0,className:"border-t border-hairline px-2 pt-3 text-[12px] leading-[1.45] text-ink-faint",children:o}):null]})}function $f({active:t,activeTab:s,searchFocusToken:n,onNavigate:a,onSearchHit:i,showAttention:r=!1,navTree:o=Ai,remoteNotice:l}){const{t:c}=D(),d=x.useRef(null),u=x.useRef(null),[p,h]=x.useState(!1);return x.useEffect(()=>{const b=d.current;if(b===null)return;const m=()=>{const g=b.scrollHeight>b.clientHeight+2,v=b.scrollHeight-b.scrollTop-b.clientHeight;h(g&&v>2)};m(),b.addEventListener("scroll",m,{passive:!0}),window.addEventListener("resize",m);const f=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return f?.observe(b),u.current!==null&&f?.observe(u.current),()=>{b.removeEventListener("scroll",m),window.removeEventListener("resize",m),f?.disconnect()}},[o,r,l]),e.jsxs("nav",{"aria-label":c("st.nav.browse"),className:"relative flex h-full w-full flex-col lg:w-[232px]",children:[e.jsx("div",{ref:d,"data-settings-nav-scroll":!0,className:"flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-y-contain scroll-pb-8 scroll-pt-2 px-3 pb-3 pt-2.5",children:e.jsx("div",{ref:u,children:e.jsx(Ju,{focusToken:n,onSearchHit:i,navTree:o,idle:e.jsx(PF,{active:t,activeTab:s,onNavigate:a,tree:o,showAttention:r,remoteNotice:l})})})}),p?e.jsx("div",{"aria-hidden":"true","data-settings-nav-more-below":!0,className:"pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-paper via-paper/85 to-transparent"}):null]})}const AF={config:!0,credentials:"shared",agents:!0,instructions:!0,skills:!0,mcp:!0,appearance:!0,plugins:!1,generic_roots:!0},$F=[{key:"credentials",labelKey:"st.spaces.inh.credentials"}],RF=[{key:"config",labelKey:"st.spaces.inh.config"},{key:"agents",labelKey:"st.spaces.inh.agents"},{key:"instructions",labelKey:"st.spaces.inh.instructions"},{key:"skills",labelKey:"st.spaces.inh.skills"},{key:"mcp",labelKey:"st.spaces.inh.mcp"},{key:"appearance",labelKey:"st.spaces.inh.appearance"},{key:"plugins",labelKey:"st.spaces.inh.plugins"},{key:"generic_roots",labelKey:"st.spaces.inh.genericRoots"}];function Rf(t,s){return t==="credentials"?[{value:"shared",label:s("st.spaces.choice.shared")},{value:"isolated",label:s("st.spaces.choice.isolated")}]:t==="instructions"?[{value:"true",label:s("st.spaces.choice.inherit")},{value:"stack",label:s("st.spaces.choice.stack")},{value:"false",label:s("st.spaces.choice.none")}]:t==="generic_roots"?[{value:"true",label:s("st.spaces.choice.visible")},{value:"false",label:s("st.spaces.choice.hidden")}]:[{value:"true",label:s("st.spaces.choice.inherit")},{value:"false",label:s("st.spaces.choice.none")}]}function Lf(t){return String(t)}function Mf(t,s){return t==="credentials"?s:t==="instructions"&&s==="stack"?"stack":s==="true"}function LF({client:t,mainPath:s,canOpen:n,mode:a,onClose:i,onDone:r}){const{t:o}=D(),[l,c]=x.useState(a),d=o(l==="create"?"st.spaces.createTitle":"st.spaces.attachTitle");return e.jsx($n,{title:d,description:l==="attach"?o("st.spaces.attachBody"):void 0,overlayId:"space-form-panel",width:"lg",onClose:i,data:{"data-space-form-panel":l},back:l==="attach"?{label:o("st.spaces.createTitle"),onClick:()=>{c("create")}}:void 0,stepKey:l,footer:null,children:l==="create"?e.jsx(MF,{client:t,mainPath:s,canOpen:n,onClose:i,onDone:r}):e.jsx(OF,{client:t,onClose:i,onDone:u=>{r(u,!1,!0)}})})}function MF({client:t,mainPath:s,canOpen:n,layout:a="panel",title:i,onBusyChange:r,onClose:o,onDone:l}){const{client:c}=be(),d=t??c,u=mt(),{t:p,locale:h}=D(),b=x.useId(),m=x.useId(),f=x.useId(),g=x.useId(),v=x.useId(),[y,w]=x.useState(""),[N,_]=x.useState(fm[0]),[C,S]=x.useState(""),[k,j]=x.useState(!1),[T,A]=x.useState(AF),[P,R]=x.useState({name:null,path:null}),[L,I]=x.useState(!1),[$,E]=x.useState(null);x.useEffect(()=>{r?.(L)},[L,r]);const M=GC(s,y),z=k?C:M,[H,U]=x.useState(null),X=H?.path===z.trim()?H.state:void 0,q=X==="space",F=Cn(d);x.useEffect(()=>{const B=z.trim();if(!Rc(B))return;let le=!0;const re=setTimeout(()=>{F.inspect({path:B}).then(({state:ae})=>{le&&U({path:B,state:ae})}).catch(()=>{le&&U(null)})},200);return()=>{le=!1,clearTimeout(re)}},[F,z]);const V=()=>{const B={name:!q&&y.trim()===""?p("st.spaces.nameRequired"):null,path:Rc(z)?null:p("st.spaces.pathRequired")};R(B),!(B.name!==null||B.path!==null||L)&&(I(!0),E(null),F.create({name:y.trim()||void 0,color:N,path:z.trim(),inherit:T}).then(le=>{l(le,n,q)}).catch(le=>{I(!1),E({tone:"error",text:oe(h,le)})}))},se=async()=>{if(u.pickDirectory!==void 0)try{const B=await u.pickDirectory();B!==null&&(S(B),j(!0),E(null))}catch(B){E({tone:"error",text:oe(h,B)})}},Y=p(L?"common.saving":q?n?"st.spaces.attachAndOpen":"st.spaces.attachConfirm":n?"st.spaces.createAndOpen":"st.spaces.create"),O=e.jsxs(e.Fragment,{children:[i!==void 0?e.jsx("h2",{className:"font-display text-[18px] font-semibold text-ink",children:i}):null,e.jsxs("fieldset",{disabled:q,className:`${i!==void 0?"mt-4 ":""}grid gap-4 sm:grid-cols-[minmax(0,1fr)_auto] ${q?"opacity-50":""}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:b,className:$e,children:p("st.spaces.name")}),e.jsx("input",{id:b,"data-autofocus":!0,"data-space-name":!0,value:y,maxLength:80,autoComplete:"off","aria-invalid":P.name!==null,"aria-describedby":P.name!==null?f:void 0,onChange:B=>{w(B.target.value),R(le=>({...le,name:null}))},className:`${Ce} mt-1.5 text-[13px]`}),e.jsx(it,{id:f,text:P.name})]}),e.jsxs("fieldset",{className:"min-w-0",children:[e.jsx("legend",{className:$e,children:p("st.spaces.color")}),e.jsx("div",{className:"mt-1.5 flex h-[34px] items-center gap-1",role:"radiogroup","aria-label":p("st.spaces.color"),children:fm.map((B,le)=>e.jsx("button",{type:"button",role:"radio","aria-checked":N===B,"data-space-color":B,"aria-label":p("st.spaces.colorOption",{n:le+1}),onClick:()=>{_(B)},className:`flex h-7 w-7 items-center justify-center rounded-full outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-selected-ink/60 ${N===B?"ring-2 ring-ink/70 ring-offset-2 ring-offset-panel":""}`,children:e.jsx("span",{"aria-hidden":!0,className:"h-4 w-4 rounded-full",style:{backgroundColor:B}})},B))})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{htmlFor:m,className:$e,children:p("st.spaces.location")}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:m,"data-space-path":!0,value:z,spellCheck:!1,autoComplete:"off","aria-invalid":P.path!==null,"aria-describedby":P.path!==null?g:void 0,onChange:B=>{S(B.target.value),j(!0),R(le=>({...le,path:null}))},className:`${Ce} min-w-0 flex-1 font-mono text-[12px]`}),u.pickDirectory!==void 0?e.jsx("button",{type:"button","data-space-browse":!0,className:Q,onClick:()=>{se()},children:p("st.spaces.browse")}):null]}),e.jsx(it,{id:g,text:P.path}),X==="nonempty"||q?e.jsx("p",{role:"status","data-space-location-note":!0,className:"mt-2 text-[12px] leading-relaxed text-ink-soft",children:p(q?"st.spaces.locationExistingSpace":"st.spaces.locationHasContent")}):null]}),e.jsxs("fieldset",{disabled:q,className:`mt-5 pt-4 ${q?"opacity-50":""}`,"data-space-inherit":!0,children:[e.jsx("legend",{className:"sr-only",children:p("st.spaces.inheritHeading")}),e.jsx("p",{"aria-hidden":!0,className:"text-[13px] font-medium text-ink",children:p("st.spaces.inheritHeading")}),e.jsx("div",{className:"mt-2 divide-y divide-hairline",children:$F.map(B=>{const le=`${m}-inh-${B.key}`;return e.jsxs("div",{"data-space-inherit-row":B.key,className:"flex flex-col gap-1.5 py-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[e.jsx("span",{id:le,className:"text-[13px] text-ink",children:p(B.labelKey)}),e.jsx(He,{ariaLabelledBy:le,dataAttr:`data-space-inherit-${B.key}`,value:Lf(T[B.key]),choices:Rf(B.key,p),onChange:re=>{A(ae=>({...ae,[B.key]:Mf(B.key,re)}))}})]},B.key)})}),e.jsx(et,{summary:p("st.spaces.inheritMore"),"data-space-inherit-more":!0,className:"mt-1",children:e.jsx("div",{className:"divide-y divide-hairline",children:RF.map(B=>{const le=`${m}-inh-${B.key}`;return e.jsxs("div",{"data-space-inherit-row":B.key,className:"flex flex-col gap-1.5 py-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[e.jsx("span",{id:le,className:"text-[13px] text-ink",children:p(B.labelKey)}),e.jsx(He,{ariaLabelledBy:le,dataAttr:`data-space-inherit-${B.key}`,value:Lf(T[B.key]),choices:Rf(B.key,p),onChange:re=>{A(ae=>({...ae,[B.key]:Mf(B.key,re)}))}})]},B.key)})})})]}),e.jsx("div",{className:"mt-4",children:e.jsx(pe,{feedback:$})})]});return a==="dialog"?e.jsxs("form",{"data-space-create":!0,onSubmit:B=>{B.preventDefault(),V()},children:[O,e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:L,onClick:o,children:p("common.cancel")}),e.jsx("button",{type:"submit","data-space-create-submit":!0,className:Ye,disabled:L,children:Y})]})]}):e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx("form",{id:v,"data-space-create":!0,className:"min-w-0 flex-1",onSubmit:B=>{B.preventDefault(),V()},children:O}),e.jsxs("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] -mx-5 -mb-4 mt-4 flex justify-end gap-2 border-t border-hairline bg-panel px-5 py-3",children:[e.jsx("button",{type:"button",className:Q,disabled:L,onClick:o,children:p("common.cancel")}),e.jsx("button",{type:"submit",form:v,"data-space-create-submit":!0,className:Ye,disabled:L,children:Y})]})]})}function OF({client:t,onClose:s,onDone:n}){const{client:a}=be(),i=t??a,r=mt(),{t:o,locale:l}=D(),c=x.useId(),d=x.useId(),u=x.useId(),[p,h]=x.useState(""),[b,m]=x.useState(null),[f,g]=x.useState(!1),[v,y]=x.useState(null),w=()=>{if(!Rc(p)){m(o("st.spaces.pathRequired"));return}g(!0),y(null),Cn(i).attach({path:p.trim()}).then(n).catch(N=>{g(!1),y({tone:"error",text:oe(l,N)})})};return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsxs("form",{id:u,"data-space-attach":!0,className:"min-w-0 flex-1",onSubmit:N=>{N.preventDefault(),w()},children:[e.jsx("label",{htmlFor:c,className:$e,children:o("st.spaces.location")}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:c,"data-autofocus":!0,"data-space-attach-path":!0,value:p,spellCheck:!1,autoComplete:"off","aria-invalid":b!==null,"aria-describedby":b!==null?d:void 0,onChange:N=>{h(N.target.value),m(null)},className:`${Ce} min-w-0 flex-1 font-mono text-[12px]`}),r.pickDirectory!==void 0?e.jsx("button",{type:"button",className:Q,onClick:()=>{r.pickDirectory?.().then(N=>{N!==null&&(h(N),m(null),y(null))}).catch(N=>{y({tone:"error",text:oe(l,N)})})},children:o("st.spaces.browse")}):null]}),e.jsx(it,{id:d,text:b}),e.jsx("div",{className:"mt-3",children:e.jsx(pe,{feedback:v})})]}),e.jsxs("div",{className:"sticky bottom-[calc(-1*var(--settings-scroll-pb,0px))] -mx-5 -mb-4 mt-4 flex justify-end gap-2 border-t border-hairline bg-panel px-5 py-3",children:[e.jsx("button",{type:"button",className:Q,disabled:f,onClick:s,children:o("common.cancel")}),e.jsx("button",{type:"submit",form:u,"data-space-attach-submit":!0,className:Ye,disabled:f,children:o(f?"common.saving":"st.spaces.attachConfirm")})]})]})}function DF({client:t,space:s,onClose:n,onDeleted:a}){const{client:i}=be(),r=t??i,{t:o,locale:l}=D(),c=x.useId(),[d,u]=x.useState(""),[p,h]=x.useState(!1),[b,m]=x.useState(null),f=d===s.name,g=()=>{!f||p||(h(!0),m(null),Cn(r).erase(s.id,{confirm_name:d}).then(a).catch(v=>{h(!1),m({tone:"error",text:oe(l,v)})}))};return e.jsx(Xe,{open:!0,overlayId:"space-delete-dialog",title:o("st.spaces.deleteTitle",{name:s.name}),body:o("st.spaces.deleteBody"),confirmLabel:o("st.spaces.deleteConfirm"),tone:"danger",busy:p,confirmDisabled:!f,confirmData:{"data-space-delete-confirm":""},onCancel:n,onConfirm:g,children:e.jsxs("form",{"data-space-delete":s.id,onSubmit:v=>{v.preventDefault(),g()},children:[e.jsx("p",{"data-space-delete-path":!0,className:"mt-2 break-all rounded-md bg-danger/[0.06] px-3 py-2 font-mono text-[12px] text-ink",children:s.path}),e.jsx("p",{className:"mt-2 text-[12.5px] text-ink-soft",children:o("st.spaces.deleteKeepHint")}),e.jsx("label",{htmlFor:c,className:`${$e} mt-4`,children:o("st.spaces.deleteTypeLabel",{name:s.name})}),e.jsx("input",{id:c,"data-space-delete-input":!0,value:d,autoComplete:"off",spellCheck:!1,onChange:v=>{u(v.target.value)},className:`${Ce} mt-1.5 text-[13px]`}),b!==null?e.jsx("div",{className:"mt-3",children:e.jsx(pe,{feedback:b})}):null]})})}const lr=t=>`${t.workspaceId??""}\0${t.hostId}`;function FF({client:t,space:s,onClose:n,onDone:a}){const{client:i}=be(),r=t??i,{t:o,tp:l,locale:c}=D(),d=s.credentials_shared!==!1,u=d?"isolated":"shared",[p,h]=x.useState(new Set),[b,m]=x.useState(!1),[f,g]=x.useState(null),v=je({queryKey:eu.sshCandidates(s.id,r),queryFn:()=>Cn(r).sshCopyCandidates(s.id),enabled:d,staleTime:0}),y=v.data?.hosts??[],w=y.length>0&&y.every(S=>p.has(lr(S))),N=S=>{h(k=>{const j=new Set(k);return j.has(S)?j.delete(S):j.add(S),j})},_=()=>{if(b)return;const S=y.filter(k=>p.has(lr(k))).map(k=>k.workspaceId===void 0?{hostId:k.hostId}:{hostId:k.hostId,workspaceId:k.workspaceId});m(!0),g(null),Cn(r).update(s.id,{inherit:{credentials:u},...u==="isolated"&&S.length>0?{copy_ssh_credentials:{hosts:S}}:{}}).then(a).catch(k=>{m(!1),g({tone:"error",text:oe(c,k)})})},C=S=>o(S==="password"?"st.spaces.kind.password":"st.spaces.kind.passphrase");return e.jsx(Xe,{open:!0,overlayId:"space-credentials-dialog",title:o("st.spaces.credDialogTitle",{name:s.name}),tone:"default",busy:b,confirmLabel:o(u==="isolated"?"st.spaces.credSwitchToIsolated":"st.spaces.credSwitchToShared"),confirmData:{"data-space-credentials-confirm":""},onCancel:n,onConfirm:_,children:e.jsxs("div",{"data-space-credentials":s.id,"data-space-credentials-target":u,className:"max-h-[55dvh] overflow-y-auto",children:[e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2","aria-hidden":!0,children:["shared","isolated"].map(S=>{const k=S===u;return e.jsxs("div",{"data-space-credentials-mode":S,className:`rounded-lg p-3 ${k?"bg-panel shadow-[var(--kiki-sheet-shadow)] ring-1 ring-selected-ink/40":"bg-ink/[0.03]"}`,children:[e.jsx("p",{className:`text-[13px] font-medium ${k?"text-ink":"text-ink-soft"}`,children:o(S==="shared"?"st.spaces.credShared":"st.spaces.credIsolated")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-faint",children:o(S==="shared"?"st.spaces.credSharedDesc":"st.spaces.credIsolatedDesc")})]},S)})}),u==="isolated"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-4 text-[13px] leading-relaxed text-ink-soft",children:o("st.spaces.credToIsolatedNote",{name:s.name})}),e.jsxs("fieldset",{className:"mt-4 pt-3","data-space-copy-ssh":!0,children:[e.jsx("legend",{className:"sr-only",children:o("st.spaces.copySsh",{name:s.name})}),e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("p",{"aria-hidden":!0,className:"text-[13px] font-medium text-ink",children:o("st.spaces.copySsh",{name:s.name})}),y.length>1?e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-[12px] text-ink-soft",children:[e.jsx("input",{type:"checkbox","data-space-copy-ssh-all":!0,checked:w,className:"accent-[var(--color-selected-ink)]",onChange:()=>{h(w?new Set:new Set(y.map(lr)))}}),o("st.spaces.copySshAll")]}):null]}),e.jsx(he,{children:o("st.spaces.copySshHint")}),v.isLoading?e.jsx("p",{className:"mt-2 text-[12px] text-ink-faint",children:o("st.spaces.copySshLoading")}):null,v.isError?e.jsx("div",{className:"mt-2",children:e.jsx(pe,{feedback:{tone:"error",text:oe(c,v.error)}})}):null,v.isSuccess&&y.length===0?e.jsx("p",{className:"mt-2 text-[12px] text-ink-faint","data-space-copy-ssh-empty":!0,children:o("st.spaces.copySshNone")}):null,y.length>0?e.jsx("ul",{className:"mt-2 divide-y divide-hairline rounded-lg border border-hairline bg-paper",children:y.map(S=>{const k=lr(S);return e.jsx("li",{children:e.jsxs("label",{className:"flex min-h-11 cursor-pointer items-center gap-2 px-3 py-2",children:[e.jsx("input",{type:"checkbox","data-space-copy-ssh-host":S.hostId,checked:p.has(k),onChange:()=>{N(k)},className:"shrink-0 accent-[var(--color-selected-ink)]"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] text-ink",children:S.name}),S.workspaceId!==void 0||S.name!==S.hostId?e.jsxs("span",{className:"block truncate font-mono text-[11px] text-ink-faint",children:[S.hostId,S.workspaceId!==void 0?` · ${S.workspaceId}`:""]}):null]}),e.jsx("span",{className:"shrink-0 text-[11.5px] text-ink-faint",children:S.credential_kinds.map(C).join(" · ")})]})},k)})}):null]})]}):e.jsx("p",{className:"mt-4 text-[13px] leading-relaxed text-ink-soft","data-space-credentials-shared-note":!0,children:o("st.spaces.credToSharedNote",{name:s.name})}),e.jsx("div",{className:"mt-3",children:e.jsx(pe,{feedback:f})}),u==="isolated"&&p.size>0?e.jsx("p",{className:"mt-2 text-[12px] text-ink-faint",children:l("st.spaces.copyCount",p.size)}):null]})})}function qF({client:t,onEnterMain:s}={}){const{client:n}=be(),a=t??n,i=mt(),{t:r,tp:o,locale:l}=D(),d=On(a).data?.find(N=>N.id===Mr()),u=d?.credentials_shared!==!1,[p,h]=x.useState(!1),[b,m]=x.useState(!1),[f,g]=x.useState(null),[v,y]=x.useState(!1),w=No(ss().windowMode);return e.jsxs(Me,{id:"st-card-space-credentials",title:r("st.spaces.credTitle"),scope:"server",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{"data-space-cred-current":u?"shared":"isolated",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:r(u?"st.spaces.credShared":"st.spaces.credIsolated")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-faint",children:r(u?"st.spaces.credSharedDesc":"st.spaces.credIsolatedDesc")})]}),e.jsx(he,{children:r("st.spaces.credChangeFromMain")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[u?e.jsx("button",{type:"button","data-space-copy-here":!0,className:Q,onClick:()=>{h(!0)},children:r("st.spaces.copySshHere")}):null,i.kind==="tauri"?e.jsx("button",{type:"button","data-space-go-main":!0,className:Q,onClick:()=>{Promise.resolve(s!==void 0?s():Lc(i,at,w)).catch(N=>{N instanceof Error&&N.name==="AbortError"||g({tone:"error",text:oe(l,N)})})},children:r("st.spaces.switchToMain")}):null,i.kind==="tauri"?e.jsx("button",{type:"button","data-space-restart":!0,className:Q,disabled:v,onClick:()=>{m(!0)},children:r("st.spaces.restartSpace")}):null]}),i.kind==="tauri"?e.jsx(he,{children:r("st.spaces.restartHint")}):null,e.jsx(pe,{feedback:f})]}),p?e.jsx(BF,{client:a,onClose:()=>{h(!1)},onCopied:N=>{h(!1),g({tone:"success",text:o("st.spaces.copiedSsh",N)})}}):null,b?e.jsx(Xe,{open:!0,overlayId:"space-restart-confirm",tone:"default",title:r("st.spaces.restartConfirmTitle",{name:d?.name??""}),body:r("st.spaces.restartConfirmBody"),confirmLabel:r("st.spaces.restartSpace"),onCancel:()=>{m(!1)},onConfirm:()=>{m(!1),y(!0),i.kind==="tauri"&&i.restartServer().catch(N=>{g({tone:"error",text:oe(l,N)})}).finally(()=>{y(!1)})}}):null]})}function BF({client:t,onClose:s,onCopied:n}){const{t:a,locale:i}=D(),r=je({queryKey:eu.sshHosts(t),queryFn:()=>bm(t).list(),select:m=>m.hosts.filter(f=>f.source==="kiki")}),[o,l]=x.useState(new Set),[c,d]=x.useState(!1),[u,p]=x.useState(null),h=r.data??[],b=()=>{d(!0),p(null),bm(t).copySharedCredentialsToIsolated({hosts:[...o].map(m=>({hostId:m}))}).then(m=>{n(m.hosts.reduce((f,g)=>f+g.copied,0))}).catch(m=>{d(!1),p({tone:"error",text:oe(i,m)})})};return e.jsx(Ea,{onClose:()=>{c||s()},ariaLabel:a("st.spaces.copySshHereTitle"),overlayId:"space-copy-ssh-here",children:e.jsxs("div",{"data-space-copy-here-dialog":!0,children:[e.jsx("h2",{className:"font-display text-[18px] font-semibold text-ink",children:a("st.spaces.copySshHereTitle")}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:a("st.spaces.copySshHereBody")}),r.isError?e.jsx("div",{className:"mt-3",children:e.jsx(De,{error:r.error})}):null,r.isSuccess&&h.length===0?e.jsx("p",{className:"mt-3 text-[12px] text-ink-faint",children:a("st.spaces.copySshNoHosts")}):null,h.length>0?e.jsx("ul",{className:"mt-3 divide-y divide-hairline rounded-lg border border-hairline bg-paper",children:h.map(m=>e.jsx("li",{children:e.jsxs("label",{className:"flex min-h-11 cursor-pointer items-center gap-2 px-3 py-2",children:[e.jsx("input",{type:"checkbox","data-space-copy-here-host":m.id,checked:o.has(m.id),className:"accent-[var(--color-selected-ink)]",onChange:()=>{l(f=>{const g=new Set(f);return g.has(m.id)?g.delete(m.id):g.add(m.id),g})}}),e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",title:m.id,children:At(m.id)})]})},m.id))}):null,e.jsx("div",{className:"mt-3",children:e.jsx(pe,{feedback:u})}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:Q,disabled:c,onClick:s,children:a("common.cancel")}),e.jsx("button",{type:"button","data-space-copy-here-confirm":!0,className:Ye,disabled:c||o.size===0,onClick:b,children:a("st.spaces.copySshHereConfirm")})]})]})})}function Hk(t){const s=t.target===null?"unidentified":`${yo(t.target.client)}|${t.target.identity.serverId}|${t.target.identity.homeId}`;return e.jsx(KF,{...t},s)}function KF({target:t,name:s,onDetailChange:n}){const{client:a,meta:i}=be(),{t:r,tp:o,locale:l}=D(),c=Oe(),d=yb(),u=t?.client??null,p=t?.identity??null,h=p?.serverId,b=p?.homeId??"unidentified",m=Pa(a,i),f=t!==null&&m!==null&&u===a&&Wi(t.identity)===Wi(m.identity),g=f&&d.identity!==null&&p!==null&&Wi(d.identity)===Wi(p),v=[...Vd.detail(b),h??"unidentified"],[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(!1),k=x.useRef(!1);x.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]);const j=je({queryKey:v,queryFn:async({signal:$})=>{if(u===null||p===null)throw new Error("Space server is unidentified");const E=f?await Yd(u,p):await yi(u).detail(b);return $.throwIfAborted(),k.current&&n?.(E),E},enabled:t!==null,staleTime:1e4,retry:!1}),T=j.data,A=$=>T===void 0?null:e.jsxs("div",{"data-space-group":$,className:"grid grid-cols-[1fr_auto] items-baseline gap-x-4 gap-y-0.5 py-1.5 sm:grid-cols-[10.5rem_1fr_auto]",children:[e.jsx("span",{className:"text-[13px] text-ink",children:r(bC($))}),e.jsx("span",{"data-space-group-summary":$,className:"col-span-2 col-start-1 row-start-2 text-[12px] leading-4 text-ink-soft sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:truncate sm:text-right",children:gC(T,$,r)}),T.primary?null:e.jsx("button",{type:"button","data-space-change":$,className:fc,onClick:()=>{_(null),w({domain:$,action:"follow"})},children:r("st.spaces.change")})]},$),P=async()=>{if(!(T?.undo_id===void 0||C||u===null||p===null)){S(!0),_(null);try{const E=await yi(u).undo(b,T.undo_id);if(!k.current)return;c.setQueryData(v,E.detail),_({tone:"success",text:r("st.spaces.undone")})}catch($){k.current&&_({tone:"error",text:oe(l,$)})}finally{k.current&&S(!1)}}},R=async()=>{if(!g||p===null||u===null||C)return;S(!0),_(null);const $=await yS(u,p);if(k.current){if(S(!1),$){c.invalidateQueries({queryKey:v}),_({tone:"success",text:r("st.spaces.device.used")});return}_({tone:"error",text:r("st.spaces.device.failed")})}};if(j.isLoading)return e.jsx("p",{className:"py-2 text-[12px] text-ink-faint","data-space-settings-loading":!0,children:r("st.spaces.settingsLoading")});if(j.isError||T===void 0)return e.jsxs("div",{className:"space-y-2 py-2","data-space-settings-failed":!0,children:[t===null?e.jsx("p",{className:"text-[12px] text-ink-faint",children:r("st.spaces.origin.unknown")}):e.jsx(De,{error:j.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{t===null?c.invalidateQueries({queryKey:["space-settings","meta"]}):j.refetch()},children:r("st.spaces.settingsRetry")})]});const L=mC(T),I=T.items.filter($=>$.pending);return e.jsxs("div",{className:"space-y-7","data-space-settings":b,children:[e.jsx("div",{"data-space-groups":!0,children:xC.map(A)}),e.jsxs("div",{className:"space-y-0.5","data-space-resource-sources":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-faint",children:r("st.spaces.resourceSources")}),e.jsx("p",{className:"pb-1 text-[12px] leading-4 text-ink-faint",children:r("st.spaces.resourceSourcesHint")}),A(vC)]}),e.jsxs("div",{className:"space-y-1","data-space-own-choices":!0,children:[e.jsx("p",{className:"text-[12px] font-medium text-ink-faint",children:r("st.spaces.ownChoices")}),L.length===0?e.jsx("p",{className:"text-[12.5px] text-ink-faint","data-space-own-empty":!0,children:r("st.spaces.ownChoicesEmpty")}):e.jsx("div",{children:L.map($=>{const E=hC($.id),M=og($.id,$.name,r);return e.jsxs("div",{"data-space-own-item":$.id,className:"grid grid-cols-[1fr_auto] items-baseline gap-x-4 gap-y-0.5 py-1 sm:grid-cols-[10.5rem_1fr_auto]",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",title:M,children:M}),e.jsx("span",{className:"col-span-2 col-start-1 row-start-2 text-[12px] leading-4 text-ink-soft sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:truncate sm:text-right",children:Xa($.id,$.effective,r)}),E===void 0?null:e.jsx("a",{"data-space-own-open":$.id,className:fc,href:E,children:r("st.spaces.ownOpen")})]},$.id)})})]}),T.primary?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:r("st.spaces.mainNote")}):null,I.length>0?e.jsxs("p",{className:"text-[12px] leading-4 text-amber-ink","data-space-pending-note":!0,children:[o("st.spaces.pending",I.length)," · ",r("st.spaces.pendingNote")]}):null,T.undo_id===void 0?null:e.jsx("button",{type:"button","data-space-undo":!0,disabled:C,className:fc,onClick:()=>{P()},children:r("st.spaces.undoLast")}),g&&d.deviceConflict?e.jsxs("div",{className:"space-y-2 pt-4","data-space-device-conflict":!0,children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:r("st.spaces.device.title")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-soft",children:r("st.spaces.device.body")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button","data-space-device-keep":!0,className:Q,onClick:()=>{g&&p!==null&&fC(p)},children:r("st.spaces.device.keep")}),e.jsx("button",{type:"button","data-space-device-use":!0,className:Ye,disabled:C,onClick:()=>{R()},children:r("st.spaces.device.use")})]})]}):null,e.jsx(pe,{feedback:N}),y===null||t===null?null:e.jsx(iu,{target:t,spaceName:s,canPush:!T.primary,request:{action:y.action,groups:[y.domain]},onClose:()=>{w(null)},onApplied:$=>{k.current&&(c.setQueryData(v,$.detail),_({tone:"success",text:r("st.spaces.applied",{count:$.applied.length})}))}})]})}const fc="shrink-0 rounded px-1 py-0.5 text-[12px] font-medium text-ink-soft outline-none transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink";function UF(t){return t instanceof DOMException&&t.name==="AbortError"}function HF(){const{connectionId:t}=be(),{t:s}=D();return x.useCallback((n,a,i)=>{if(n===t)return Promise.resolve();const r=l1(n),o=o0(i?.inPlace?{...r,inPlace:!0}:r);return i?.inPlace||o.catch(l=>{UF(l)||vt({tone:"error",text:s("sidebar.space.remoteFailed",{name:a})})}),o},[t,s])}function zF(){const t=mt(),{client:s,localClient:n,connectionId:a,sshLabel:i,connectionSource:r}=be(),{t:o,locale:l}=D(),c=Oe(),d=!!a||!!i||zs(r),u=t.kind==="tauri"?n:n??(d?null:s),p=xo(u),h=Ud(u),b=Jb(u),m=Jd(u),[f,g]=x.useState(null),[v,y]=x.useState(null),[w,N]=x.useState(null),[_,C]=x.useState(null),S=p.data??[],k=u===null?null:Kd(u),j=HF(),T=()=>{c.invalidateQueries({queryKey:fo.all}),c.invalidateQueries({queryKey:li.all})},A=(E,M,z)=>{k!==null&&(C(E.id),N(null),M(k).then(()=>{N(z),T()}).catch(H=>{const U=ga(H instanceof Error?H.message:"");N({tone:"error",text:U===null?oe(l,H):o(U)})}).finally(()=>{C(null)}))},P=m?.identity.homeId,R=On(P!==void 0&&P!==at?u:null),L=P===void 0?void 0:P===at?o("st.spaces.main"):R.data?.find(E=>E.id===P)?.name,I=L!==void 0?o("st.remote.outboundTitleFrom",{space:L}):o("st.remote.outboundTitle"),$=u===null?o("st.remote.controlUnavailable"):L===void 0?o("st.remote.configuresNoHome",{origin:ho(u.baseUrl)}):void 0;return e.jsxs(Me,{id:"st-card-remote-connections",title:I,scope:"server",aside:$===void 0?void 0:e.jsx("span",{"data-remote-source":!0,children:$}),actions:u===null?void 0:e.jsxs("button",{type:"button","data-remote-add":!0,className:`${Q} inline-flex items-center gap-1`,onClick:()=>{g({kind:"add"})},children:[e.jsx(de,{name:"plus",size:12}),o("st.remote.add")]}),children:[e.jsxs("div",{className:"space-y-4","data-remote-connections":!0,children:[p.isLoading?e.jsx(he,{children:o("st.remote.loading")}):null,p.isError?ja(p.error)?e.jsx(he,{children:o("st.remote.controlUnavailable")}):e.jsx(De,{error:p.error}):null,p.isSuccess&&S.length===0?e.jsx("p",{className:"text-[13px] text-ink-soft","data-remote-empty":!0,children:o("st.remote.emptyLine")}):null,S.length>0?e.jsx("div",{role:"list","aria-label":o("st.remote.outboundTitle"),className:"space-y-1.5","data-remote-list":!0,children:S.map(E=>{const M=!b||h.isLoading?b?null:"unreadable":h.isError||h.data===void 0?"unreadable":c1(E,h.data);return e.jsx(QF,{record:E,busy:_===E.id,threadFact:M,onEnter:()=>{j(E.id,E.label)},onVerifyFingerprint:k===null?void 0:()=>{A(E,z=>z.verifyFingerprint(E.id),{tone:"success",text:o("st.remote.fingerprintVerified",{name:E.label})})},onMenu:(z,H)=>{y({record:E,anchor:z,anchorElement:H})}},E.id)})}):null,e.jsx(pe,{feedback:w})]}),v!==null?e.jsx($a,{anchor:v.anchor,anchorElement:v.anchorElement,ariaLabel:o("st.remote.menuAria",{name:v.record.label}),onClose:()=>{y(null)},items:[{key:"thread-messages",label:o("st.remote.threadMessages.menu"),blockedReason:b?void 0:o("st.remote.controlUnavailable"),run:()=>{g({kind:"thread-messages",record:v.record})}},...Rr(v.record)?[{key:"retry",label:o("st.remote.retry"),blockedReason:v.record.enabled?void 0:o("st.remote.blocked.disabled"),run:()=>{A(v.record,E=>E.retry(v.record.id),{tone:"success",text:o("st.remote.retried",{name:v.record.label})})}},{key:"toggle",label:v.record.enabled?o("st.remote.disable"):o("st.remote.enable"),run:()=>{const E=!v.record.enabled;A(v.record,M=>M.setEnabled(v.record.id,E),{tone:"success",text:o(E?"st.remote.enabled":"st.remote.disabled",{name:v.record.label})})}}]:[],{key:"remove",label:o("st.remote.removeMenu"),danger:!0,separatorBefore:!0,run:()=>{g({kind:"remove",record:v.record})}}]}):null,f?.kind==="thread-messages"&&u!==null?e.jsx(Ey,{client:u,subject:{kind:"outbound",record:f.record},onClose:()=>{g(null)}}):null,f?.kind==="add"&&u!==null?e.jsx(Fb,{client:u,direction:"outbound",onClose:()=>{g(null)},onPaired:E=>{g(null),T(),vt({tone:"success",text:E.fingerprintToVerify===void 0?o("st.remote.added",{name:E.label}):o("st.remote.addedWithFingerprint",{name:E.label,fingerprint:Tc(E.fingerprintToVerify,16,8)}),durationMs:H1,action:Xb(E)?{label:o("st.remote.enter"),run:()=>{j(E.id,E.label)}}:void 0})}}):null,f?.kind==="remove"&&u!==null?e.jsx(Xe,{open:!0,overlayId:"remote-connection-remove",tone:"danger",title:o("st.remote.removeTitle",{name:f.record.label}),body:o("st.remote.removeBody",{name:f.record.label}),confirmLabel:o("st.remote.removeConfirm"),onCancel:()=>{g(null)},onConfirm:()=>{const E=f.record;g(null),A(E,M=>M.remove(E.id),{tone:"success",text:o("st.remote.removed",{name:E.label})})}}):null]})}function QF({record:t,busy:s,threadFact:n,onEnter:a,onVerifyFingerprint:i,onMenu:r}){const{t:o,tp:l,locale:c}=D(),d=d1(t),u=Rr(t)&&t.enabled,p=Xb(t),h=d!==null&&d.stale&&d.asOf!==void 0?o("st.remote.asOf",{time:Nn(new Date(d.asOf).toISOString(),c)}):void 0,b=t.lastError===void 0?null:ga(t.lastError),m=d!==null&&(d.busy>0||d.needsYou>0),f=u1(d?.platform),g=t.state==="online"?d?.rttMs??t.rttMs:void 0,v=d?.borrowableTools;return e.jsxs("div",{role:"listitem","data-remote-connection":t.id,"data-remote-purpose":t.purposes.join("+"),"data-remote-stale":d!==null&&d.stale?"":void 0,className:"flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg bg-ink/[0.03] px-3 py-2",children:[e.jsx(de,{name:"web",size:14,className:"shrink-0 text-ink-faint"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:"min-w-0 max-w-full truncate text-[13px] font-medium text-ink",title:t.label,children:t.label}),e.jsx(Md,{state:t.state,staleLabel:h})]}),e.jsxs("p",{className:"mt-0.5 truncate font-mono text-[11px] text-ink-faint","data-remote-address":!0,title:t.endpoint,children:[ho(t.endpoint),t.lastConnectedAt!==void 0?` · ${Nn(new Date(t.lastConnectedAt).toISOString(),c)}`:""]}),t.fingerprintToVerify!==void 0?e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-ink-faint","data-remote-fingerprint-to-verify":!0,title:t.fingerprintToVerify,children:[e.jsxs("span",{className:"shrink-0",children:[o("st.remote.fingerprintToVerify"),":"]}),e.jsx("span",{className:"whitespace-nowrap font-mono text-ink-soft",children:Tc(t.fingerprintToVerify,16,8)}),i!==void 0?e.jsx("button",{type:"button","data-remote-verify-fingerprint":t.id,disabled:s,onClick:i,className:"rounded px-1.5 py-0.5 text-[11px] font-medium text-ink underline decoration-hairline-strong underline-offset-2 hover:text-accent disabled:opacity-50",children:o("st.remote.verifyFingerprint")}):null]}):null,t.pinnedFingerprint!==void 0?e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-1 gap-y-0.5 text-[11px] text-ink-faint","data-remote-pinned-fingerprint":!0,title:t.pinnedFingerprint,children:[e.jsxs("span",{className:"shrink-0",children:[o("st.remote.pinnedFingerprint"),":"]}),e.jsx("span",{className:"whitespace-nowrap font-mono text-ink-soft",children:Tc(t.pinnedFingerprint,16,8)})]}):null,e.jsx("div",{className:"mt-0.5 overflow-hidden",children:e.jsxs("p",{className:"flex flex-wrap items-center gap-x-3.5 gap-y-0.5 text-[11.5px] text-ink-faint","data-remote-facts":!0,children:[f!==void 0?e.jsx("span",{className:"shrink-0 rounded-full bg-ink/[0.06] px-1.5 text-[11px] leading-[18px] text-ink-soft","data-remote-platform":d?.platform,children:f}):null,g!==void 0?e.jsxs("span",{className:"relative inline-flex items-center tabular-nums before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']","data-remote-rtt":!0,children:[g," ms"]}):null,v!==void 0&&v>0?e.jsx("span",{className:"relative inline-flex items-center tabular-nums before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']","data-remote-tools":!0,children:l("st.remote.borrowableTools",v)}):null,e.jsx("span",{className:"relative inline-flex items-center before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']","data-remote-openable":u?"yes":"no",children:o(u?"st.remote.canOpen":"st.remote.cantOpen")}),n!==null?e.jsx("span",{className:`relative inline-flex items-center before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']${n==="unreadable"?" text-amber-ink":""}`,"data-remote-thread-messages":n,children:o(Zb(n))}):null,m?e.jsxs("span",{className:"contents","data-remote-summary":!0,children:[d.busy>0?e.jsx("span",{className:"relative inline-flex items-center tabular-nums before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']",children:o("st.remote.busy",{count:d.busy})}):null,d.needsYou>0?e.jsx("span",{className:"relative inline-flex items-center tabular-nums text-attention before:pointer-events-none before:absolute before:-left-2 before:text-ink-faint before:content-['·']",children:o("st.remote.needsYou",{count:d.needsYou})}):null]}):null]})}),Rr(t)?null:e.jsx("p",{className:"mt-0.5 text-[11px] text-ink-faint","data-remote-bridge-only":!0,children:o("st.remote.bridgeOnly")}),b!==null&&t.state!=="online"?e.jsx("p",{className:"mt-0.5 truncate text-[11.5px] text-amber-ink","data-remote-error":!0,title:t.lastError,children:o(b)}):null]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[p?e.jsx("button",{type:"button","data-remote-enter":t.id,className:Q,disabled:s,onClick:a,children:o("st.remote.enter")}):null,e.jsx("button",{type:"button","data-remote-menu":t.id,"aria-haspopup":"menu",disabled:s,"aria-label":o("st.remote.menuAria",{name:t.label}),className:"flex h-8 w-8 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",onClick:y=>{r(y.currentTarget.getBoundingClientRect(),y.currentTarget)},children:e.jsx(de,{name:"more",size:14})})]})]})}function GF(){const{client:t,localClient:s,meta:n,connectionId:a,sshLabel:i}=be(),r=mt(),{t:o}=D(),l=typeof a=="string"&&a!=="",c=l||!!i,d=r.kind==="tauri"?s:s??(c?null:t),u=Jd(d,d===t?n:void 0),p=Aa(),h=p!==null&&!p.homeId.startsWith("remote:")?p:null,b=!l&&h!==null,m=VF(d),f=No(ss().windowMode),g=On(d),v=u?.identity.homeId??h?.homeId??at,y=v===at?o("st.spaces.main"):h?.name??g.data?.find(_=>_.id===v)?.name??o("sidebar.space.unnamed"),w=Et(),N=x.useCallback(_=>{w(`/settings/subscriptions?exportSpace=${encodeURIComponent(_)}`)},[w]);return e.jsxs(e.Fragment,{children:[c?e.jsx("p",{className:"text-[13px] text-ink-soft","data-spaces-remote-scope-banner":!0,children:o("st.spaces.remoteScopeBanner",{space:y})}):null,d===null?e.jsx(he,{children:o("st.spaces.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(JF,{sub:b,client:d,target:u,openLocalSpace:m,onExportSpace:N}),e.jsx(zF,{}),b?e.jsx(qF,{client:d,onEnterMain:()=>m(at,f)}):null,b?e.jsx(WF,{target:u}):null]}),e.jsx(YF,{sub:b})]})}function WF({target:t}){const s=Aa(),n=Mr();if(n.startsWith("remote:"))return null;const a=t===null?null:{...t,identity:{...t.identity,homeId:n}};return e.jsx("section",{id:"st-card-space-overrides",className:"pt-6","data-space-settings-section":!0,children:e.jsx(Hk,{target:a,name:s?.name??n})})}function VF(t){const{sshLabel:s,scopeAdapter:n}=be(),a=mt(),i=Ln(),r=Tt(),o=x.useRef(t);return o.current=t,(l,c)=>{if(c==="switch")return t===null||t!==o.current?Promise.reject(new DOMException("The local space connection changed.","AbortError")):Lc(a,l,c);const d=s!==null?l0(Mr(),"local")??"/new":void 0,u=async(p=new AbortController().signal)=>{if(t===null||t!==o.current)throw new DOMException("The local space connection changed.","AbortError");let h;try{if(d!==void 0&&(h=await n.prepare({homeId:Mr(),scopeId:"local"},p),await h.validate(d,p)),p.throwIfAborted(),t!==o.current)throw new DOMException("The local space connection changed.","AbortError");await Lc(a,l,c),p.throwIfAborted(),await h?.commit()}catch(b){throw await h?.dispose(),b}};return i?.runAction!==void 0?i.runAction(u,d):u().then(()=>{d!==void 0&&r(d)})}}function YF({sub:t}){const s=mt(),{t:n}=D(),[a,i]=x.useState(ss),r=s.kind==="tauri",[o]=x.useState(()=>No(ss().windowMode));x.useEffect(()=>{s.kind==="tauri"&&s.readDesktopPrefs().then(d=>{d!==null&&(Fs(d),i(ss()))})},[s]);const l=d=>{Fs({windowMode:d}),i(ss()),s.kind==="tauri"&&s.writeDesktopPrefs({windowMode:d})};if(!r)return null;const c=t?n("st.spaces.windowSubHint"):void 0;return e.jsx(Me,{id:"st-card-space-window",title:n("st.spaces.windowCardTitle"),scope:"app",aside:c,children:t?null:e.jsxs(Ze,{"data-space-window-mode":a.windowMode,"data-testid":"space-window-box",children:[e.jsx(ge,{label:n("st.spaces.windowTitle"),labelId:"space-window-label",help:n(a.windowMode==="switch"?"st.spaces.windowSwitchDesc":"st.spaces.windowWindowsDesc"),children:e.jsx(He,{ariaLabelledBy:"space-window-label",dataAttr:"data-space-window-choice",value:a.windowMode,onChange:l,choices:[{value:"switch",label:n("st.spaces.windowSwitch")},{value:"windows",label:n("st.spaces.windowWindows")}]})}),e.jsx("p",{className:"text-[12px] text-ink-faint","data-space-window-note":!0,children:a.windowMode!==o?e.jsx("span",{className:"font-medium text-amber-ink",children:n("st.spaces.windowPending")}):n("st.spaces.windowNextLaunch")})]})})}function JF({sub:t,client:s,target:n,openLocalSpace:a,onExportSpace:i}){const r=mt(),{connectionId:o,sshLabel:l}=be(),c=typeof o=="string"&&o!==""||!!l,{t:d,tp:u,locale:p}=D(),h=Oe(),b=On(s),m=WC(r),f=Li("space"),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(null),[k,j]=x.useState(null),[T,A]=x.useState(null),P=r.kind==="tauri",R=ag()==="windows",L=No(ss().windowMode),I=Bt(),$=Et(),E=P&&!t&&new URLSearchParams(I.search).get("new")==="1";x.useEffect(()=>{E&&(v({kind:"create"}),$(I.pathname,{replace:!0}))},[E,$,I.pathname]);const M=b.data??[],z=M.find(ee=>ee.id===at),H=M.filter(ee=>ee.id!==at),U=x.useMemo(()=>[...z===void 0?[]:[z],...H],[z,H]),X=()=>{h.invalidateQueries({queryKey:eu.all})},q=f.selected===null?void 0:U.find(ee=>ee.id===f.selected),F=x.useCallback(ee=>ee.id===at?d("st.spaces.main"):ee.name,[d]),V=x.useCallback(ee=>ee.id,[]),se=x.useCallback(ee=>[F(ee),ee.path],[F]),Y=x.useMemo(()=>[{id:"running",label:d("st.spaces.filter.running"),test:ee=>ll(ee.id,m.data)==="hot"},{id:"pending",label:d("st.spaces.filter.pending"),test:ee=>(cl(ee.id,m.data)?.pendingCount??0)>0},{id:"isolated",label:d("st.spaces.filter.isolated"),test:ee=>ee.credentials_shared===!1}],[d,m.data]),O=x.useMemo(()=>[{id:"order",label:d("st.list.sort.order"),compare:()=>0},{id:"name",label:d("st.list.sort.name"),compare:(ee,K)=>+(K.id===at)-+(ee.id===at)||F(ee).localeCompare(F(K))}],[d,F]),B=Qs({listId:"spaces",items:U,keyOf:V,textOf:se,filters:Y,sorts:O}),le=ee=>{A(ee.id),S(null),Promise.resolve(a(ee.id,L)).catch(K=>{K instanceof Error&&K.name==="AbortError"||S({tone:"error",text:oe(p,K)})}).finally(()=>{A(null)})},re=ee=>{if(!(!P||r.createSpaceShortcut===void 0)){if(!R){S({tone:"error",text:d("st.spaces.shortcutWindowsOnly")});return}S(null),r.createSpaceShortcut(ee.id).then(K=>{S({tone:"success",text:d("st.spaces.shortcutCreated",{path:K.path})}),vt({tone:"success",text:d("st.spaces.shortcutCreated",{path:K.path})})}).catch(K=>{const Z=typeof K=="object"&&K!==null?K:null,ue=typeof Z?.code=="string"?Z.code:void 0,Te=typeof Z?.message=="string"?Z.message:void 0;ue==="shortcut_exists"?(S({tone:"info",text:d("st.spaces.shortcutExists")}),vt({tone:"info",text:d("st.spaces.shortcutExists")})):S(ue==="unsupported_platform"?{tone:"error",text:d("st.spaces.shortcutWindowsOnly")}:ue==="invalid_space"?{tone:"error",text:d("st.spaces.shortcutInvalidSpace")}:ue==="desktop_unavailable"?{tone:"error",text:d("st.spaces.shortcutDesktopUnavailable")}:ue==="executable_unavailable"?{tone:"error",text:d("st.spaces.shortcutExecutableUnavailable")}:ue==="shortcut_failed"?{tone:"error",text:d("st.spaces.shortcutFailed",{detail:Te||oe(p,K)})}:{tone:"error",text:oe(p,K)})})}},ae=ee=>{const K=ll(ee.id,m.data);if(K==="current")return d("st.spaces.deleteDisabledCurrent");if((cl(ee.id,m.data)?.busyCount??0)>0)return d("st.spaces.deleteDisabledBusy");if(K==="hot")return d("st.spaces.deleteDisabledOpen")},ne=ee=>{S(null),Cn(s).remove(ee.id).then(()=>{X(),xs({text:d("st.spaces.removedUndo",{name:ee.name}),undoFailedText:d("toast.undoFailed"),undo:async()=>{await Cn(s).attach({path:ee.path}),X()}})}).catch(K=>{S({tone:"error",text:oe(p,K)})})},Ee=ee=>{const K=ee.id===at;return[{key:"settings",label:d("st.spaces.settingsMenu"),run:()=>{f.open(ee.id)}},{key:"export",label:d("st.spaces.exportMenu"),run:()=>{i(ee.id)}},...r.revealPath!==void 0?[{key:"reveal",label:d("st.spaces.reveal"),separatorBefore:!0,run:()=>{r.revealPath?.(ee.path).catch(()=>{})}}]:[],...K?[]:[{key:"credentials",label:d("st.spaces.credentials"),run:()=>{w({kind:"credentials",space:ee})}}],...P&&r.createSpaceShortcut!==void 0?[{key:"shortcut",label:d("st.spaces.createShortcut"),blockedReason:R?void 0:d("st.spaces.shortcutWindowsOnly"),run:()=>{re(ee)}}]:[],...P&&!K&&r.restartSpace!==void 0?[{key:"restart",label:d("st.spaces.restartSpace"),run:()=>{S(null),r.restartSpace?.(ee.id).then(()=>{j(null),X()}).catch(Z=>{S({tone:"error",text:oe(p,Z)})})}}]:[],...K?[]:[{key:"remove",label:d("st.spaces.removeFromList"),separatorBefore:!0,run:()=>{ne(ee)}},{key:"delete",label:d("st.spaces.delete"),danger:!0,blockedReason:ae(ee),run:()=>{w({kind:"delete",space:ee})}}]]},ie=(ee,K)=>{w(null),X();const Z=[d(K.space.credentials_shared?"st.spaces.credDoneShared":"st.spaces.credDoneIsolated",{name:ee.name})];K.copied_ssh_entries>0&&Z.push(u("st.spaces.copiedSsh",K.copied_ssh_entries)),K.retained_isolated_ssh_entries!==void 0&&K.retained_isolated_ssh_entries>0&&Z.push(u("st.spaces.retainedSsh",K.retained_isolated_ssh_entries)),S({tone:"success",text:Z.join(" ")}),j(K.restart_required?{id:ee.id,text:d("st.spaces.restartRequired",{name:ee.name})}:null)},me=ee=>{const K=ll(ee.id,m.data),Z=c&&K==="current"?"hot":K,ue=L==="switch"?cl(ee.id,m.data)?.pendingCount??0:0,Te=ee.id===at,Ne=F(ee),J=B.density==="compact";return e.jsxs("div",{"data-space-row":ee.id,"data-space-state":Z,style:{minHeight:_s[B.density]},className:"flex items-center gap-3 px-3 py-1.5",children:[e.jsx(dr,{color:Te?"var(--color-ink-faint)":ee.color}),J?e.jsxs("div",{className:"flex min-w-0 flex-1 items-baseline gap-x-2",children:[P?e.jsx("button",{type:"button","data-detail-trigger":ee.id,onClick:()=>{f.open(ee.id)},title:Ne,className:"min-w-0 shrink truncate rounded text-left text-[13px] font-medium text-ink transition-colors hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink",children:Ne}):e.jsx("span",{className:"min-w-0 shrink truncate text-[13px] font-medium text-ink",title:Ne,children:Ne}),Te?null:e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint","data-space-cred":ee.credentials_shared===!1?"isolated":"shared",children:d(ee.credentials_shared===!1?"st.spaces.credIsolatedShort":"st.spaces.credSharedShort")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11.5px] text-ink-faint",title:ee.path,children:ee.path})]}):e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-baseline gap-x-2",children:[P?e.jsx("button",{type:"button","data-detail-trigger":ee.id,onClick:()=>{f.open(ee.id)},title:Ne,className:"min-w-0 shrink truncate rounded text-left text-[13px] font-medium text-ink transition-colors hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink",children:Ne}):e.jsx("span",{className:"min-w-0 shrink truncate text-[13px] font-medium text-ink",title:Ne,children:Ne}),Te?null:e.jsx("span",{className:"shrink-0 text-[12px] text-ink-faint","data-space-cred":ee.credentials_shared===!1?"isolated":"shared",children:d(ee.credentials_shared===!1?"st.spaces.credIsolatedShort":"st.spaces.credSharedShort")})]}),e.jsx("p",{className:"truncate text-[11.5px] text-ink-faint",title:ee.path,children:ee.path}),k?.id===ee.id?e.jsx("p",{className:"text-[12px] font-medium text-amber-ink","data-space-restart-note":!0,children:k.text}):null]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[ue>0&&Z!=="current"?e.jsx("span",{"data-space-pending":!0,className:"rounded-full bg-attention-soft px-1.5 text-[11.5px] font-medium tabular-nums text-attention",children:u("st.spaces.pending",ue)}):null,Z==="current"?e.jsx("span",{className:"text-[12px] font-medium text-ink-soft","data-space-current":!0,children:d("st.spaces.current")}):P?e.jsxs(e.Fragment,{children:[L==="switch"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[12px] text-ink-faint","data-space-run":Z,children:[e.jsx("span",{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-full ${Z==="hot"?"bg-success":"border border-ink-faint/70"}`}),d(Z==="hot"?"st.spaces.running":"st.spaces.notStarted")]}):null,e.jsx("button",{type:"button","data-space-enter":ee.id,disabled:T!==null,className:Q,onClick:()=>{le(ee)},children:T===ee.id?d("sidebar.space.starting",{name:Ne}):d(L==="switch"?"st.spaces.switch":"st.spaces.open")})]}):null,P&&!t?e.jsx("button",{type:"button","data-space-menu":ee.id,"aria-haspopup":"menu","aria-label":d("st.spaces.menuAria",{name:ee.name}),className:"flex h-8 w-8 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",onClick:_e=>{_({space:ee,anchor:_e.currentTarget.getBoundingClientRect(),anchorElement:_e.currentTarget})},children:e.jsx(de,{name:"more",size:14})}):null]})]})},fe=e.jsxs("div",{className:"space-y-3","data-space-list":!0,children:[t?e.jsx(he,{children:d("st.spaces.subManageHint")}):null,b.isLoading?e.jsx(he,{children:d("st.spaces.loading")}):null,b.isError?e.jsx(De,{error:b.error}):null,M.length>0?e.jsxs(e.Fragment,{children:[U.length<8?null:e.jsx(Gs,{view:B,total:U.length,filters:Y,sorts:O,searchLabel:d("st.spaces.search"),searchPlaceholder:d("st.spaces.searchPlaceholder")}),B.visible.length===0?e.jsx(Ct,{kind:"no-match",title:d("st.spaces.noMatchTitle"),body:B.query.trim()!==""?d("st.spaces.noMatches",{query:B.query.trim()}):void 0,onClear:B.clear}):e.jsx(Hs,{items:B.visible,keyOf:V,density:B.density,label:d("st.spaces.listTitle"),renderRow:me})]}):null,b.isSuccess&&H.length===0?e.jsx("div",{"data-space-empty":!0,children:e.jsx(Ct,{kind:"none",title:d("st.spaces.emptyTitle"),body:d("st.spaces.emptyBody")})}):null,e.jsx(pe,{feedback:C})]}),Ie=e.jsx(jo,{label:d("st.spaces.listTitle"),count:U.length,children:U.map(ee=>e.jsx(Na,{itemKey:ee.id,label:F(ee),hint:ee.path,current:ee.id===q?.id,trailing:e.jsx(dr,{color:ee.id===at?"var(--color-ink-faint)":ee.color,size:6}),onSelect:()=>{f.open(ee.id)}},ee.id))}),te=q===void 0?null:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"md:hidden",children:e.jsx(ko,{label:d("st.spaces.listTitle"),onClick:f.close,data:{"data-space-detail-back":""}})}),e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{"data-detail-heading":!0,tabIndex:-1,className:"flex min-w-0 items-center gap-2 font-display text-[18px] font-semibold text-ink outline-none",children:[e.jsx(dr,{color:q.id===at?"var(--color-ink-faint)":q.color}),e.jsx("span",{className:"min-w-0 break-words",children:F(q)})]}),e.jsx("p",{className:"mt-0.5 truncate text-[12px] text-ink-faint",title:q.path,children:q.path})]}),e.jsx("button",{type:"button",onClick:f.close,"aria-label":d("common.close"),title:d("common.close"),"data-detail-close":!0,className:"hidden h-8 w-8 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink md:flex",children:e.jsx(de,{name:"close",size:14})})]}),e.jsx(Hk,{target:n===null?null:{...n,identity:{...n.identity,homeId:q.id}},name:F(q)})]});return e.jsxs(Me,{id:"st-card-spaces",title:d("st.spaces.listTitle"),scope:"server",actions:P&&!t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button","data-space-new":!0,className:`${Q} inline-flex items-center gap-1`,onClick:()=>{v({kind:"create"})},children:[e.jsx(de,{name:"plus",size:12}),d("st.spaces.new")]}),e.jsx("button",{type:"button","data-space-attach-open":!0,className:Q,onClick:()=>{v({kind:"attach"})},children:d("st.spaces.attach")})]}):void 0,children:[e.jsx(wo,{selected:q?.id??null,label:d("st.spaces.listTitle"),data:{"data-spaces-split":""},list:fe,rail:Ie,detail:te}),N!==null?e.jsx($a,{anchor:N.anchor,anchorElement:N.anchorElement,items:Ee(N.space),onClose:()=>{_(null)},ariaLabel:d("st.spaces.menuAria",{name:N.space.name})}):null,g!==null?e.jsx(LF,{client:s,mainPath:z?.path??"",canOpen:P,mode:g.kind,onClose:()=>{v(null)},onDone:(ee,K,Z)=>{v(null),X(),vt({tone:"success",text:d(Z?"st.spaces.attached":"st.spaces.created",{name:ee.name})}),K&&le(ee)}}):null,y?.kind==="delete"?e.jsx(DF,{client:s,space:y.space,onClose:()=>{w(null)},onDeleted:()=>{const ee=y.space.name;w(null),X(),S({tone:"success",text:d("st.spaces.deleted",{name:ee})})}}):null,y?.kind==="credentials"?e.jsx(FF,{client:s,space:y.space,onClose:()=>{w(null)},onDone:ee=>{ie(y.space,ee)}}):null]})}function ZF({client:t,token:s,spaces:n,portableSources:a,deviceRecipient:i,mainPath:r,intent:o,initialSource:l,initialMode:c,onClose:d,onDone:u}){const p=mt(),{t:h,locale:b}=D(),m=x.useId(),f=x.useId(),g=x.useId(),v=x.useId(),y=x.useId(),w=x.useId(),N=x.useId(),_=x.useMemo(()=>{const ke=n.map(Re=>{const Ae=Re.id===at?h("st.spaces.main"):Re.name;return{value:`live:${Re.id}`,label:Ae,endpoint:{kind:"live",spaceId:Re.id},slugSeed:Re.id===at?"main-space":Re.name}}),W=a.map(Re=>({value:`source:${Re.id}`,label:Re.label,endpoint:Re.endpoint,slugSeed:Re.label}));return ke.length===0&&ke.push({value:`live:${at}`,label:h("st.spaces.main"),endpoint:{kind:"live",spaceId:at},slugSeed:"main-space"}),[...ke,...W]},[n,a,h]),C=x.useMemo(()=>{if(l!==void 0){const ke=ls(l),W=_.find(Re=>ls(Re.endpoint)===ke);if(W!==void 0)return W.value}return _[0]?.value??`live:${at}`},[l,_]),[S,k]=x.useState(C),[j,T]=x.useState(c??"full"),[A,P]=x.useState("dir"),[R,L]=x.useState(!1),[I,$]=x.useState("sealed"),[E,M]=x.useState("x25519"),[z,H]=x.useState("x25519"),[U,X]=x.useState("none"),[q,F]=x.useState(""),[V,se]=x.useState(""),[Y,O]=x.useState(i??""),[B,le]=x.useState(""),[re,ae]=x.useState(!1),[ne,Ee]=x.useState(()=>new Set(p1)),[ie,me]=x.useState("none"),[fe,Ie]=x.useState(null),[te,ee]=x.useState(null),[K,Z]=x.useState(!1),[ue,Te]=x.useState(null),Ne=_.find(ke=>ke.value===S)??_[0],J=m1(r,j==="overlay"?`${Ne.slugSeed}-overlay`:Ne.slugSeed,A),_e=re?B:J,we=A==="age"&&z==="passphrase"||A==="dir"&&I==="sealed"&&E==="passphrase",G=A==="age"&&z==="x25519"||A==="dir"&&I==="sealed"&&E==="x25519",Le=Ne.endpoint.kind!=="live",Se=ke=>{Ee(W=>{const Re=new Set(W);return Re.has(ke)?Re.delete(ke):Re.add(ke),Re})},Fe=async()=>{if(p.pickDirectory!==void 0)try{const ke=await p.pickDirectory();ke!==null&&(le(ke),ae(!0),Ie(null),Te(null))}catch(ke){Te({tone:"error",text:oe(b,ke)})}},ye=()=>{const ke=Y.split(/[\r\n,]+/u).map(W=>W.trim()).filter(W=>W!=="");return A==="dir"?I==="sealed"?E==="passphrase"?{secretMode:"sealed",encryption:{mode:"passphrase",passphrase:q.trim()}}:{secretMode:"sealed",encryption:{mode:"x25519",recipients:ke.length>0?ke:void 0}}:{secretMode:I}:A==="age"?z==="passphrase"?{secretMode:"sealed",encryption:{mode:"passphrase",passphrase:q.trim()}}:z==="x25519"?{secretMode:"sealed",encryption:{mode:"x25519",recipients:ke.length>0?ke:void 0}}:{secretMode:"none",encryption:{mode:"x25519",recipients:ke.length>0?ke:void 0}}:{secretMode:U}},ze=async()=>{if(K)return;const ke=_e.trim(),W=ke===""?h("st.portable.exportDestRequired"):null,Re=we&&q.trim()===""?h("st.portable.passphraseRequired"):null;if(Ie(W),ee(Re),W!==null||Re!==null)return;const{secretMode:Ae,encryption:Ue}=ye(),Ge=ne.has("memories"),Ke=ie==="recent5",We=h1(ne,{includeCredentials:Ae!=="none",includeSessions:Ke}),ce=Le&&V.trim()!==""?{passphrase:V.trim()}:void 0;Z(!0),Te(null);try{const qe=Wt(t),st=o==="fork"?await qe.fork({source:Ne.endpoint,destination:ke,format:A,overlay:j==="overlay",secretMode:Ae,encryption:Ue,domains:We.length>0?We:void 0,includeMemories:Ge,sourceUnlock:ce}):await qe.exportSpace({source:Ne.endpoint,destination:ke,format:A,spaceMode:j,secretMode:Ae,encryption:Ue,domains:We.length>0?We:void 0,sessions:Ke?{mode:"recent",count:5}:{mode:"none"},includeMemories:Ge,gitInit:A==="dir"?R:!1,sourceUnlock:ce});u(st)}catch(qe){Z(!1),Te({tone:"error",text:oe(b,qe)})}},Pe=h(o==="fork"?"st.portable.forkTitle":"st.portable.exportTitle"),xe=h(K?"st.portable.exporting":o==="fork"?"st.portable.forkSubmit":"st.portable.exportSubmit");return e.jsx($n,{title:Pe,overlayId:"portable-export-panel",width:"lg",onClose:()=>{K||d()},data:{"data-portable-export-panel":o},footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Q,disabled:K,onClick:d,children:h("common.cancel")}),e.jsx("span",{className:"ml-auto"}),e.jsx("button",{type:"submit",form:m,"data-portable-export-submit":!0,className:Ye,disabled:K||ne.size===0,children:xe})]}),children:e.jsxs("form",{id:m,className:"space-y-5",onSubmit:ke=>{ke.preventDefault(),ze()},children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:`${m}-source`,className:$e,children:h("st.portable.exportSource")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Qe,{id:`${m}-source`,variant:"form",ariaLabel:h("st.portable.exportSource"),dataAttr:"data-portable-export-source",value:S,onChange:k,choices:_.map(ke=>({value:ke.value,label:ke.label}))})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{id:`${m}-mode`,className:$e,children:h("st.portable.exportMode")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(He,{ariaLabelledBy:`${m}-mode`,dataAttr:"data-portable-export-mode",value:j,onChange:T,choices:[{value:"full",label:h("st.portable.exportModeFull")},{value:"overlay",label:h("st.portable.exportModeOverlay")}]})})]})]}),Le?e.jsxs("div",{children:[e.jsx("label",{htmlFor:N,className:$e,children:h("st.portable.sourceUnlockLabel")}),e.jsx("input",{id:N,type:"password","data-portable-source-unlock":!0,value:V,placeholder:h("st.portable.passphrasePlaceholder"),autoComplete:"off",onChange:ke=>{se(ke.target.value)},className:`${Ce} mt-1.5`})]}):null,e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{id:`${m}-format`,className:$e,children:h("st.portable.exportFormat")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(He,{ariaLabelledBy:`${m}-format`,dataAttr:"data-portable-export-format",value:A,onChange:ke=>{P(ke),ee(null)},choices:[{value:"dir",label:h("st.portable.exportFormatDir")},{value:"age",label:h("st.portable.exportFormatAge")},{value:"tgz",label:h("st.portable.exportFormatTgz")}]})})]}),A==="dir"&&o==="export"?e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1","data-portable-git-init":!0,children:[e.jsx("span",{className:"text-[13px] text-ink",children:h("st.portable.exportGitInit")}),e.jsx(Be,{layout:"bare",label:h("st.portable.exportGitInit"),checked:R,onChange:L})]}):null]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{id:`${m}-secret`,className:$e,children:h("st.portable.secretLabel")}),e.jsx("div",{className:"mt-1.5",children:A==="dir"?e.jsx(He,{ariaLabelledBy:`${m}-secret`,dataAttr:"data-portable-secret-policy",value:I,onChange:$,choices:[{value:"sealed",label:h("st.portable.secret.dirSealed")},{value:"plain",label:h("st.portable.secret.dirPlain")},{value:"none",label:h("st.portable.secret.none")}]}):A==="age"?e.jsx(He,{ariaLabelledBy:`${m}-secret`,dataAttr:"data-portable-secret-policy",value:z,onChange:ke=>{H(ke),ee(null)},choices:[{value:"x25519",label:h("st.portable.secret.ageX25519")},{value:"passphrase",label:h("st.portable.secret.agePassphrase")},{value:"none",label:h("st.portable.secret.noneShort")}]}):e.jsx(He,{ariaLabelledBy:`${m}-secret`,dataAttr:"data-portable-secret-policy",value:U,onChange:X,choices:[{value:"none",label:h("st.portable.secret.noneShort")},{value:"plain",label:h("st.portable.secret.dirPlain")}]})})]}),A==="dir"&&I==="sealed"?e.jsxs("div",{children:[e.jsx("span",{id:`${m}-dir-seal-enc`,className:$e,children:h("st.portable.dirSealEncLabel")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(He,{ariaLabelledBy:`${m}-dir-seal-enc`,dataAttr:"data-portable-dir-seal-enc",value:E,onChange:ke=>{M(ke),ee(null)},choices:[{value:"x25519",label:h("st.portable.enc.x25519")},{value:"passphrase",label:h("st.portable.enc.passphrase")}]})})]}):null,we?e.jsxs("div",{children:[e.jsx("label",{htmlFor:v,className:$e,children:h("st.portable.passphraseLabel")}),e.jsx("input",{id:v,type:"password","data-portable-export-passphrase":!0,value:q,placeholder:h("st.portable.passphrasePlaceholder"),autoComplete:"new-password","aria-invalid":te!==null,"aria-describedby":te!==null?y:void 0,onChange:ke=>{F(ke.target.value),ee(null)},className:`${Ce} mt-1.5`}),e.jsx(it,{id:y,text:te})]}):null,G?e.jsxs("div",{children:[e.jsx("label",{htmlFor:w,className:$e,children:h("st.portable.recipientsLabel")}),e.jsx("textarea",{id:w,rows:2,"data-portable-export-recipients":!0,value:Y,placeholder:h("st.portable.recipientsPlaceholder"),spellCheck:!1,onChange:ke=>{O(ke.target.value)},className:`${Ce} mt-1.5 font-mono text-[12px]`})]}):null]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:f,className:$e,children:h("st.portable.exportDest")}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:f,"data-portable-export-dest":!0,value:_e,spellCheck:!1,autoComplete:"off","aria-invalid":fe!==null,"aria-describedby":fe!==null?g:void 0,onChange:ke=>{le(ke.target.value),ae(!0),Ie(null)},className:`${Ce} min-w-0 flex-1 font-mono text-[12px]`}),A==="dir"&&p.pickDirectory!==void 0?e.jsx("button",{type:"button",className:Q,onClick:()=>{Fe()},children:h("st.spaces.browse")}):null]}),e.jsx(it,{id:g,text:fe})]}),e.jsxs("fieldset",{className:"space-y-2.5",children:[e.jsx("legend",{className:$e,children:h("st.portable.domainsLabel")}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2","data-portable-domain-checklist":!0,children:x1.map(ke=>{const W=ne.has(ke.id);return e.jsxs("label",{className:`flex cursor-pointer items-center gap-2.5 rounded-md border px-3 py-2 text-[13px] transition-colors ${W?"border-selected-ink/40 bg-selected-ink/[0.04] text-ink":"border-hairline bg-paper text-ink-soft hover:border-hairline-strong hover:text-ink"}`,children:[e.jsx("input",{type:"checkbox","data-portable-domain":ke.id,checked:W,onChange:()=>{Se(ke.id)},className:"accent-[var(--color-selected-ink)]"}),e.jsx("span",{className:"min-w-0 truncate",children:h(ke.labelKey)})]},ke.id)})})]}),o==="export"?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-1",children:[e.jsx("span",{id:`${m}-sessions`,className:"text-[13px] text-ink",children:h("st.portable.sessionsLabel")}),e.jsx(He,{ariaLabelledBy:`${m}-sessions`,dataAttr:"data-portable-sessions-choice",value:ie,onChange:me,choices:[{value:"none",label:h("st.portable.sessionsNone")},{value:"recent5",label:h("st.portable.sessionsRecent5")}]})]}):null,e.jsx(pe,{feedback:ue})]})})}function XF({client:t,token:s,source:n,action:a,deviceRecipient:i,onClose:r,onDone:o}){const l=mt(),{t:c,locale:d}=D(),u=x.useId(),p=x.useId(),h=x.useId(),b=x.useId(),m=n.endpoint.kind==="dir"||n.endpoint.kind==="archive"?n.endpoint.path:"",[f,g]=x.useState(()=>f1(m,a)),[v,y]=x.useState("x25519"),[w,N]=x.useState(""),[_,C]=x.useState(null),[S,k]=x.useState(null),[j,T]=x.useState(!1),[A,P]=x.useState(null),R=a==="pack"&&v==="passphrase"||a==="unpack"&&(n.format==="age"||n.encryptionMode==="passphrase"||n.secretMode==="sealed"),L=async()=>{if(j)return;const $=f.trim(),E=$===""?c("st.portable.exportDestRequired"):null,M=a==="pack"&&v==="passphrase"&&w.trim()===""?c("st.portable.passphraseRequired"):null;if(C(E),k(M),!(E!==null||M!==null)){T(!0),P(null);try{const z=Wt(t),H=a==="pack"?v==="passphrase"?{mode:"passphrase",passphrase:w.trim()}:{mode:"x25519",recipients:i!==void 0?[i]:void 0}:void 0,U=a==="pack"?await z.pack({action:"pack",sourcePath:m,destinationPath:$,format:"age",encryption:H}):await z.unpack({action:"unpack",sourcePath:m,destinationPath:$,unlock:w.trim()!==""?{passphrase:w.trim()}:void 0});o(U)}catch(z){T(!1),P({tone:"error",text:oe(d,z)})}}},I=c(a==="pack"?"st.portable.packTitle":"st.portable.unpackTitle");return e.jsx(Ea,{onClose:()=>{j||r()},ariaLabel:I,overlayId:"portable-pack-dialog",panelClassName:`${bo} ${go.md}`,children:e.jsxs("form",{"data-portable-pack-dialog":a,className:"space-y-4",onSubmit:$=>{$.preventDefault(),L()},children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-[17px] font-semibold text-ink",children:I}),e.jsx("p",{className:"mt-0.5 truncate font-mono text-[11.5px] text-ink-faint",title:m,children:m})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:u,className:$e,children:c("st.portable.exportDest")}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{id:u,"data-autofocus":!0,"data-portable-pack-dest":!0,value:f,spellCheck:!1,autoComplete:"off","aria-invalid":_!==null,"aria-describedby":_!==null?p:void 0,onChange:$=>{g($.target.value),C(null)},className:`${Ce} min-w-0 flex-1 font-mono text-[12px]`}),a==="unpack"&&l.pickDirectory!==void 0?e.jsx("button",{type:"button",className:Q,onClick:()=>{l.pickDirectory?.().then($=>{$!==null&&(g($),C(null),P(null))}).catch($=>{P({tone:"error",text:oe(d,$)})})},children:c("st.spaces.browse")}):null]}),e.jsx(it,{id:p,text:_})]}),a==="pack"?e.jsxs("div",{children:[e.jsx("span",{id:`${u}-enc`,className:$e,children:c("st.portable.secretLabel")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(He,{ariaLabelledBy:`${u}-enc`,dataAttr:"data-portable-pack-enc",value:v,onChange:$=>{y($),k(null)},choices:[{value:"x25519",label:c("st.portable.enc.x25519")},{value:"passphrase",label:c("st.portable.enc.passphrase")}]})})]}):null,R?e.jsxs("div",{children:[e.jsx("label",{htmlFor:h,className:$e,children:c(a==="unpack"&&n.encryptionMode!=="passphrase"?"st.portable.passphraseOptionalLabel":"st.portable.passphraseLabel")}),e.jsx("input",{id:h,type:"password","data-portable-pack-passphrase":!0,value:w,placeholder:c("st.portable.passphrasePlaceholder"),autoComplete:"off","aria-invalid":S!==null,"aria-describedby":S!==null?b:void 0,onChange:$=>{N($.target.value),k(null)},className:`${Ce} mt-1.5`}),e.jsx(it,{id:b,text:S})]}):null,e.jsx(pe,{feedback:A}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{type:"button",className:Q,disabled:j,onClick:r,children:c("common.cancel")}),e.jsx("button",{type:"submit","data-portable-pack-submit":!0,className:Ye,disabled:j,children:c(j?"common.saving":a==="pack"?"st.portable.packAction":"st.portable.unpackAction")})]})]})})}function e3({client:t,token:s,source:n,inspect:a,deviceRecipient:i,portableSources:r,unlock:o,onRekeyed:l}){const{t:c,locale:d}=D(),u=x.useId(),p=x.useId(),h=x.useId(),b=x.useMemo(()=>r.filter(H=>H.id!==n.id),[r,n.id]),[m,f]=x.useState(""),[g,v]=x.useState((a?.encryptionMode??n.encryptionMode)==="passphrase"?"passphrase":"x25519"),y=a?.recipients.join(`
|
|
254
|
+
`)??"",[w,N]=x.useState(()=>y!==""?y:i??"");x.useEffect(()=>{y!==""?N(y):i!==void 0&&N(i)},[y,i]);const[_,C]=x.useState(""),[S,k]=x.useState(null),[j,T]=x.useState(!1),[A,P]=x.useState(null),R=b.find(H=>H.id===m),L=x.useMemo(()=>eg({source:n.endpoint,overlay:R?.endpoint}),[n.endpoint,R?.endpoint]),I=n.endpoint.kind==="archive"||n.endpoint.kind==="dir"?n.endpoint.path:null,$=I!==null&&(n.format==="age"||n.secretMode==="sealed"),E=async()=>{if(i!==void 0)try{await rs(i),vt({tone:"success",text:c("st.portable.deviceKeyCopied")})}catch(H){P({tone:"error",text:oe(d,H)})}},M=async()=>{try{await rs(L),vt({tone:"success",text:c("st.portable.colabCopied")})}catch(H){P({tone:"error",text:oe(d,H)})}},z=async()=>{if(I===null||j)return;if(g==="passphrase"&&_.trim()===""){k(c("st.portable.passphraseRequired"));return}const H=w.split(/[\r\n,]+/u).map(q=>q.trim()).filter(q=>q!==""),U=_.trim(),X=g==="passphrase"?{mode:"passphrase",passphrase:U}:{mode:"x25519",recipients:H.length>0?H:void 0};T(!0),P(null);try{const q=await Wt(t).rekey({target:I,unlock:o,encryption:X});C(""),P({tone:"success",text:c("st.portable.rekeyDone")}),l(q,g==="passphrase"?{passphrase:U}:void 0)}catch(q){P({tone:"error",text:oe(d,q)})}finally{T(!1)}};return e.jsxs("div",{className:"space-y-6","data-portable-colab-tab":!0,children:[e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h4",{className:"text-[13px] font-medium text-ink",children:c("st.portable.colabTitle")}),b.length>0?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-ink-faint",children:c("st.portable.colabOverlay")}),e.jsx(Qe,{ariaLabel:c("st.portable.colabOverlay"),dataAttr:"data-portable-colab-overlay",value:m,onChange:f,choices:[{value:"",label:c("st.portable.colabOverlayNone")},...b.map(H=>({value:H.id,label:H.label}))]})]}):null]}),e.jsx("pre",{"data-portable-colab-command":!0,className:"overflow-x-auto whitespace-pre rounded-lg border border-hairline bg-paper px-3.5 py-3 font-mono text-[12px] leading-5 text-ink",children:e.jsx("code",{children:L})}),e.jsx("div",{children:e.jsxs("button",{type:"button","data-portable-copy-colab":!0,className:`${Ye} inline-flex items-center gap-1.5`,onClick:()=>{M()},children:[e.jsx(de,{name:"copy",size:12}),c("st.portable.colabCopy")]})})]}),i!==void 0?e.jsxs("div",{className:"space-y-2 border-t border-hairline pt-5",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:c("st.portable.deviceKeyLabel")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("code",{"data-portable-device-recipient":!0,className:"min-w-0 flex-1 truncate rounded-md border border-hairline bg-paper px-3 py-1.5 font-mono text-[12px] text-ink-soft",title:i,children:i}),e.jsxs("button",{type:"button","data-portable-copy-recipient":!0,className:`${Q} inline-flex items-center gap-1.5`,onClick:()=>{E()},children:[e.jsx(de,{name:"copy",size:12}),c("st.portable.deviceKeyCopy")]})]})]}):null,$?e.jsxs("div",{className:"space-y-3 border-t border-hairline pt-5","data-portable-rekey-section":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:c("st.portable.rekeyTitle")}),e.jsx(He,{ariaLabel:c("st.portable.rekeyTitle"),dataAttr:"data-portable-rekey-mode",value:g,onChange:H=>{v(H),k(null)},choices:[{value:"x25519",label:c("st.portable.enc.x25519")},{value:"passphrase",label:c("st.portable.enc.passphrase")}]})]}),g==="x25519"?e.jsxs("div",{children:[e.jsx("label",{htmlFor:u,className:$e,children:c("st.portable.recipientsLabel")}),e.jsx("textarea",{id:u,rows:2,"data-portable-rekey-recipients":!0,value:w,placeholder:c("st.portable.recipientsPlaceholder"),spellCheck:!1,onChange:H=>{N(H.target.value)},className:`${Ce} mt-1.5 font-mono text-[12px]`})]}):e.jsxs("div",{children:[e.jsx("label",{htmlFor:p,className:$e,children:c("st.portable.passphraseLabel")}),e.jsx("input",{id:p,type:"password","data-portable-rekey-passphrase":!0,value:_,autoComplete:"new-password",placeholder:c("st.portable.passphrasePlaceholder"),"aria-invalid":S!==null,"aria-describedby":S!==null?h:void 0,onChange:H=>{C(H.target.value),k(null)},className:`${Ce} mt-1.5`}),e.jsx(it,{id:h,text:S})]}),e.jsx("div",{children:e.jsx("button",{type:"button","data-portable-rekey-submit":!0,className:Q,disabled:j,onClick:()=>{z()},children:c(j?"common.saving":"st.portable.rekeySubmit")})})]}):null,e.jsx(pe,{feedback:A})]})}function Of({size:t=14,className:s=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:s,children:[e.jsx("path",{d:"M3 5.5h10M10.5 3 13 5.5 10.5 8"}),e.jsx("path",{d:"M13 10.5H3M5.5 8 3 10.5 5.5 13"})]})}const t3={added:"st.portable.diff.added",modified:"st.portable.diff.modified",deleted:"st.portable.diff.deleted",only_left:"st.portable.diff.onlyLeft",only_right:"st.portable.diff.onlyRight",conflict:"st.portable.diff.conflict"};function s3({client:t,token:s,source:n,spaces:a,portableSources:i,initialMode:r="sync",initialRightEndpoint:o,sourceUnlock:l,onApplied:c}){const{t:d,locale:u}=D(),p=x.useMemo(()=>{const Pe=a.map(ke=>({value:`live:${ke.id}`,label:ke.id===at?d("st.spaces.main"):ke.name,endpoint:{kind:"live",spaceId:ke.id}}));Pe.length===0&&Pe.push({value:`live:${at}`,label:d("st.spaces.main"),endpoint:{kind:"live",spaceId:at}});const xe=i.map(ke=>({value:`source:${ke.id}`,label:ke.label,endpoint:ke.endpoint}));return[...Pe,...xe]},[a,i,d]),h=x.useMemo(()=>{if(o!==void 0){const Pe=ls(o),xe=p.find(ke=>ls(ke.endpoint)===Pe);if(xe!==void 0)return xe.value}return`live:${at}`},[p,o]),[b,m]=x.useState(`source:${n.id}`),[f,g]=x.useState(h),[v,y]=x.useState(r),[w,N]=x.useState({}),[_,C]=x.useState(""),[S,k]=x.useState(""),[j,T]=x.useState(null),[A,P]=x.useState(new Set),[R,L]=x.useState({}),[I,$]=x.useState(!1),[E,M]=x.useState(!1),[z,H]=x.useState(!1),[U,X]=x.useState(null),[q,F]=x.useState(null),[V,se]=x.useState(0),Y=x.useRef(0),O=p.find(Pe=>Pe.value===b)??{value:`source:${n.id}`,label:n.label,endpoint:n.endpoint},B=p.find(Pe=>Pe.value===f)??p[0],le=ls(O.endpoint)===ls(B.endpoint),re=ls(O.endpoint),ae=ls(B.endpoint),ne=ls(n.endpoint),Ee=i.find(Pe=>ls(Pe.endpoint)===re),ie=i.find(Pe=>ls(Pe.endpoint)===ae),me=w[re]??(re===ne?l:void 0),fe=w[ae]??(ae===ne?l:void 0),Ie=O.endpoint.kind!=="live"&&(Ee?.encryptionMode==="passphrase"&&me===void 0||U!==null),te=B.endpoint.kind!=="live"&&(ie?.encryptionMode==="passphrase"&&fe===void 0||U!==null),ee=O.endpoint.kind==="url",K=B.endpoint.kind==="url",Z=(ee||K)&&v==="sync"?"merge":v,ue=K||ee,Te=x.useCallback(()=>{if(le||K){T(null),X(null),M(!1);return}const Pe=++Y.current,xe=new AbortController;return M(!0),X(null),F(null),Wt(t).preview({mode:Z,sources:[O.endpoint],target:B.endpoint,sourceUnlocks:me!==void 0?[me]:void 0,targetUnlock:fe},{signal:xe.signal}).then(ke=>{if(Pe!==Y.current)return;T(ke),P(new Set(ke.rows.filter(Re=>Re.change!=="unchanged"&&Re.blockedReason===void 0&&Re.selected).map(Re=>Re.id)));const W={};for(const Re of ke.rows)Re.change==="conflict"&&(W[Re.id]="left");L(W)}).catch(ke=>{Pe===Y.current&&(ke instanceof DOMException&&ke.name==="AbortError"||(T(null),X(ke)))}).finally(()=>{Pe===Y.current&&M(!1)}),()=>{xe.abort()}},[t,Z,K,O.endpoint,B.endpoint,le,me,fe]);x.useEffect(()=>{const Pe=Te();return()=>{Pe?.()}},[Te,V]);const Ne=x.useMemo(()=>(j?.rows??[]).filter(Pe=>Pe.change!=="unchanged"),[j]),J=x.useMemo(()=>(j?.rows??[]).filter(Pe=>Pe.change==="unchanged"),[j]),_e=Math.max(j?.unchangedCount??0,J.length),we=Pe=>{P(xe=>{const ke=new Set(xe);return ke.has(Pe)?ke.delete(Pe):ke.add(Pe),ke})},G=(Pe,xe)=>{L(ke=>({...ke,[Pe]:xe})),P(ke=>{const W=new Set(ke);return W.add(Pe),W})},Le=()=>{m(f),g(b)},Se=async()=>{if(j===null||z||A.size===0||ue)return;H(!0),F(null);const Pe={};for(const xe of Ne)xe.change==="conflict"&&(Pe[xe.id]=A.has(xe.id)?R[xe.id]??"left":"skip");try{const xe=await Wt(t).apply({previewToken:j.previewToken,selectedIds:[...A],resolutions:Object.keys(Pe).length>0?Pe:void 0,createBackup:!0});F({tone:"success",text:d(xe.restartRequired?"st.portable.applyDoneRestart":"st.portable.applyDone",{count:xe.appliedIds.length})}),c(xe),se(ke=>ke+1)}catch(xe){F({tone:"error",text:oe(u,xe)})}finally{H(!1)}},Fe=p.map(Pe=>({value:Pe.value,label:Pe.label})),ye=Pe=>{const xe=Pe.blockedReason!==void 0,ke=Pe.change==="unchanged",W=!xe&&A.has(Pe.id),Re=Pe.change==="conflict",Ae=R[Pe.id]??"left";return e.jsx("li",{className:"border-b border-hairline last:border-b-0",children:e.jsxs("div",{"data-portable-diff-row":Pe.id,"data-portable-diff-change":Pe.change,className:"flex flex-wrap items-start gap-x-3 gap-y-2 py-2.5 sm:flex-nowrap",children:[ke?e.jsx("span",{className:"mt-1 inline-block h-3.5 w-3.5 shrink-0","aria-hidden":!0}):e.jsx("input",{type:"checkbox","aria-label":Pe.label,"data-portable-diff-check":Pe.id,disabled:xe||z,checked:W,onChange:()=>{we(Pe.id)},className:"mt-0.5 shrink-0 accent-[var(--color-selected-ink)]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{className:`text-[13px] ${xe||ke?"text-ink-faint":"text-ink"}`,children:Pe.label}),Pe.change!=="unchanged"?e.jsx("span",{className:`rounded px-1.5 py-px text-[11px] font-medium ${Re?"bg-amber-card text-amber-ink":Pe.change==="deleted"?"bg-danger/[0.08] text-danger":"bg-ink/[0.05] text-ink-soft"}`,children:d(t3[Pe.change])}):null,Pe.masked?e.jsx(de,{name:"lock",size:12,className:"text-ink-faint"}):null]}),e.jsx("p",{className:"truncate font-mono text-[11.5px] text-ink-faint",title:Pe.path,children:Pe.path}),xe?e.jsx("p",{className:"mt-0.5 text-[12px] leading-4 text-ink-faint","data-portable-diff-blocked":Pe.id,children:Pe.blockedReason}):null,Re&&!xe?e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5","data-portable-conflict-resolve":Pe.id,children:[e.jsx("button",{type:"button","data-portable-conflict-side":"left","aria-pressed":Ae==="left",disabled:z,onClick:()=>{G(Pe.id,"left")},className:`rounded px-2 py-0.5 text-[11.5px] transition-colors ${Ae==="left"?"bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)] ring-1 ring-hairline-strong":"bg-ink/[0.04] text-ink-soft hover:text-ink"}`,children:d("st.portable.conflictKeepLeft")}),e.jsx("button",{type:"button","data-portable-conflict-side":"right","aria-pressed":Ae==="right",disabled:z,onClick:()=>{G(Pe.id,"right")},className:`rounded px-2 py-0.5 text-[11.5px] transition-colors ${Ae==="right"?"bg-panel font-medium text-ink shadow-[var(--kiki-sheet-shadow)] ring-1 ring-hairline-strong":"bg-ink/[0.04] text-ink-soft hover:text-ink"}`,children:d("st.portable.conflictKeepRight")})]}):null]}),e.jsxs("div",{className:"ml-auto flex max-w-[16rem] shrink-0 items-center gap-1.5 text-[12px] text-ink-soft","data-portable-diff-direction":Re?"conflict":Pe.direction==="to_left"||Pe.change==="only_right"?"to_left":Pe.direction==="both"?"both":"to_right",children:[e.jsx("span",{className:`truncate ${Re?"text-ink":"text-ink-faint"}`,title:Pe.beforeSummary??void 0,children:Pe.beforeSummary??"—"}),Re||Pe.direction==="both"?e.jsx(Of,{size:12,className:Re?"shrink-0 text-amber-ink":"shrink-0 text-ink-faint"}):Pe.direction==="to_left"||Pe.change==="only_right"?e.jsx(de,{name:"arrowLeft",size:12,className:"shrink-0 text-ink-faint"}):e.jsx(de,{name:"arrowRight",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"truncate text-ink",title:Pe.afterSummary??void 0,children:Pe.afterSummary??"—"})]})]})},Pe.id)},ze=z?d("st.portable.applying"):v==="sync"?d("st.portable.syncConfirm",{count:A.size}):d("st.portable.applyConfirm",{count:A.size});return e.jsxs("div",{className:"space-y-5","data-portable-compare-tab":!0,children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] sm:items-end",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:$e,children:d("st.portable.compareLeft")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Qe,{variant:"form",ariaLabel:d("st.portable.compareLeft"),dataAttr:"data-portable-left-endpoint",value:b,onChange:m,choices:Fe})})]}),e.jsx("button",{type:"button","data-portable-swap-endpoints":!0,"aria-label":d("st.portable.compareSwap"),title:d("st.portable.compareSwap"),onClick:Le,className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-hairline bg-paper text-ink-soft transition-colors hover:border-hairline-strong hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:e.jsx(Of,{size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:$e,children:d("st.portable.compareRight")}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Qe,{variant:"form",ariaLabel:d("st.portable.compareRight"),dataAttr:"data-portable-right-endpoint",value:f,onChange:g,choices:Fe})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(He,{ariaLabel:d("st.portable.compareMode"),dataAttr:"data-portable-op-mode",value:Z,onChange:y,choices:[{value:"sync",label:d("st.portable.compareModeSync"),disabled:ee||K},{value:"merge",label:d("st.portable.compareModeMerge")},{value:"override",label:d("st.portable.compareModeOverride")}]}),e.jsx("button",{type:"button","data-portable-compare-refresh":!0,className:Q,disabled:E||z||le||K,onClick:()=>{se(Pe=>Pe+1)},children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(de,{name:"refresh",size:12}),d("st.portable.compareRefresh")]})})]}),ue?e.jsx("p",{className:"text-[12.5px] text-amber-ink","data-portable-url-compare-notice":!0,children:d("st.portable.center.urlReadOnlyCompareNotice")}):null,le?e.jsx("p",{className:"text-[13px] text-ink-faint",children:d("st.portable.compareSameEndpoint")}):null,E?e.jsx("p",{className:"text-[12.5px] text-ink-faint","data-portable-compare-loading":!0,children:d("st.portable.compareLoading")}):null,U!==null?e.jsx("div",{className:"space-y-2",children:e.jsx(De,{error:U})}):null,(Ie||te)&&!le?e.jsxs("div",{className:"space-y-2 rounded-lg border border-hairline bg-paper/60 px-3 py-2.5","data-portable-compare-unlock":!0,children:[Ie?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:Pe=>{Pe.preventDefault(),_.trim()!==""&&(N(xe=>({...xe,[re]:{passphrase:_.trim()}})),C(""))},children:[e.jsx("input",{type:"password","data-portable-compare-unlock-left":!0,"aria-label":d("st.portable.compareUnlockLeft"),value:_,placeholder:`${d("st.portable.compareUnlockLeft")} (${O.label})`,onChange:Pe=>{C(Pe.target.value)},className:`${Gt} min-w-0 flex-1`}),e.jsx("button",{type:"submit","data-portable-compare-unlock-left-submit":!0,className:Q,children:d("st.portable.unlockAction")})]}):null,te?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:Pe=>{Pe.preventDefault(),S.trim()!==""&&(N(xe=>({...xe,[ae]:{passphrase:S.trim()}})),k(""))},children:[e.jsx("input",{type:"password","data-portable-compare-unlock-right":!0,"aria-label":d("st.portable.compareUnlockRight"),value:S,placeholder:`${d("st.portable.compareUnlockRight")} (${B.label})`,onChange:Pe=>{k(Pe.target.value)},className:`${Gt} min-w-0 flex-1`}),e.jsx("button",{type:"submit","data-portable-compare-unlock-right-submit":!0,className:Q,children:d("st.portable.unlockAction")})]}):null]}):null,j!==null&&!E?e.jsxs("div",{className:"space-y-3","data-portable-diff-list":!0,children:[Ne.length===0?e.jsx("p",{className:"text-[13px] text-ink-soft","data-portable-compare-empty":!0,children:d("st.portable.compareEmpty")}):e.jsx("ul",{className:"divide-y divide-hairline border-t border-b border-hairline",children:Ne.map(ye)}),_e>0?e.jsxs("div",{children:[e.jsxs("button",{type:"button","data-portable-unchanged-toggle":!0,"aria-expanded":I,onClick:()=>{$(Pe=>!Pe)},className:"inline-flex items-center gap-1.5 rounded px-1 py-1 text-[12px] text-ink-soft transition-colors hover:text-ink",children:[e.jsx(Rt,{open:I}),e.jsx("span",{children:d("st.portable.compareUnchanged",{count:_e})})]}),I&&J.length>0?e.jsx("ul",{className:"mt-1 border-t border-hairline","data-portable-unchanged-rows":!0,children:J.map(ye)}):null]}):null,j.dependencyErrors.length>0?e.jsx("ul",{className:"space-y-1 text-[12px] text-amber-ink",children:j.dependencyErrors.map(Pe=>e.jsx("li",{children:Pe},Pe))}):null,Ne.length>0&&!ue?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-1",children:[A.size===0?e.jsx("span",{className:"text-[12px] text-ink-faint",children:d("st.portable.applyEmpty")}):e.jsx("span",{}),e.jsx("button",{type:"button","data-portable-apply-submit":!0,className:Ye,disabled:z||A.size===0,onClick:()=>{Se()},children:ze})]}):null]}):null,e.jsx(pe,{feedback:q})]})}function n3({client:t,token:s,source:n,spaces:a,portableSources:i,deviceRecipient:r,tab:o,compareMode:l,compareRightEndpoint:c,onTabChange:d,onClose:u,onFork:p,onPackUnpack:h,onMutated:b}){const{t:m,locale:f}=D(),g=Oe(),[v,y]=x.useState(""),[w,N]=x.useState(void 0),[_,C]=x.useState(0),[S,k]=x.useState(new Set(["config"])),[j,T]=x.useState(null),[A,P]=x.useState(""),[R,L]=x.useState(null),[I,$]=x.useState(null),E=b1(t,{endpoint:n.endpoint,unlock:w},{unlockNonce:_,enabled:o==="contents"||o==="colab"}),M=E.data,z=x.useMemo(()=>{const O=new Map;for(const B of M?.items??[]){const le=O.get(B.domain)??[];le.push(B),O.set(B.domain,le)}return O},[M?.items]),H=O=>{k(B=>{const le=new Set(B);return le.has(O)?le.delete(O):le.add(O),le})},U=n.endpoint.kind==="git"||n.endpoint.kind==="url",X=(O,B)=>{const le=B?.updateUnlock?B.nextUnlock:w,re=B?.updateUnlock?_+1:_;B?.updateUnlock&&(N(le),C(re));const ae=`${re}:${le?.passphrase?"pw":""}:${le?.identity?"id":""}`;g.setQueryData(tg.inspect(t,n.endpoint,ae),O),b()},q=async O=>{if(!(R!==null||U)){L(O.id),$(null);try{const B=await Wt(t).mutate({target:n.endpoint,unlock:w,actions:[{op:"set",key:O.path,value:v1(A,O.scalarValue)}]});T(null),X(B.inspect),$(B.changed?{tone:"success",text:m("st.portable.editSaved")}:{tone:"error",text:m("st.portable.mutateUnchanged")})}catch(B){$({tone:"error",text:oe(f,B)})}finally{L(null)}}},F=async O=>{if(!(R!==null||U)){L(O.id),$(null);try{const B=O.bytes===void 0?{op:"unset",key:O.id,recordOverlayUnset:M?.spaceMode==="overlay"}:{op:"rm",paths:[O.path]},le=await Wt(t).mutate({target:n.endpoint,unlock:w,actions:[B]});X(le.inspect),$(le.changed?{tone:"success",text:m("st.portable.removeItemDone")}:{tone:"error",text:m("st.portable.mutateUnchanged")})}catch(B){$({tone:"error",text:oe(f,B)})}finally{L(null)}}},V=n.endpoint.kind==="dir"&&n.format==="dir",se=n.endpoint.kind==="archive"&&(n.format==="age"||n.format==="tgz"),Y=Ic(n.endpoint,n.gitBranch);return e.jsxs("div",{className:"space-y-4","data-portable-detail":n.id,children:[e.jsx("div",{className:"md:hidden",children:e.jsx(ko,{label:m("st.portable.title"),onClick:u,data:{"data-portable-detail-back":""}})}),e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{"data-detail-heading":!0,tabIndex:-1,className:"flex min-w-0 items-center gap-2 font-display text-[18px] font-semibold text-ink outline-none",children:[e.jsx(de,{name:n.endpoint.kind==="url"?"web":n.endpoint.kind==="git"?"branch":n.format==="age"?"lock":"folder",size:16,className:"text-ink-soft"}),e.jsx("span",{className:"min-w-0 break-words",children:n.label})]}),e.jsx("p",{className:"mt-0.5 truncate font-mono text-[11.5px] text-ink-faint",title:Y,children:Y})]}),e.jsx("button",{type:"button",onClick:u,"aria-label":m("common.close"),title:m("common.close"),"data-detail-close":!0,className:"hidden h-8 w-8 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink md:flex",children:e.jsx(de,{name:"close",size:14})})]}),e.jsx(Gd,{tabs:["contents","compare","colab"],current:o,ariaLabel:n.label,dataAttr:"data-portable-tab",labelOf:O=>m(O==="contents"?"st.portable.tab.contents":O==="compare"?"st.portable.tab.compare":"st.portable.tab.colab"),onSelect:d}),o==="contents"?e.jsxs("div",{className:"space-y-4","data-portable-contents-tab":!0,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[se?e.jsx("button",{type:"button","data-portable-unpack-trigger":!0,className:Q,onClick:()=>{h(n,"unpack")},children:m("st.portable.unpackAction")}):null,V?e.jsx("button",{type:"button","data-portable-pack-trigger":!0,className:Q,onClick:()=>{h(n,"pack")},children:m("st.portable.packAction")}):null,e.jsx("button",{type:"button","data-portable-detail-fork":!0,className:Q,onClick:()=>{p(n)},children:m("st.portable.forkMenu")})]}),E.isLoading?e.jsx("p",{className:"py-2 text-[12.5px] text-ink-faint","data-portable-inspect-loading":!0,children:m("st.portable.inspectLoading")}):null,E.isError?e.jsxs("div",{className:"space-y-3","data-portable-inspect-error":!0,children:[e.jsx(De,{error:E.error}),n.format==="age"||n.encryptionMode==="passphrase"?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:O=>{O.preventDefault(),v.trim()!==""&&(N({passphrase:v.trim()}),C(B=>B+1))},children:[e.jsx("input",{type:"password","data-portable-unlock-input":!0,value:v,placeholder:m("st.portable.unlockHint"),onChange:O=>{y(O.target.value)},className:`${Gt} w-64`}),e.jsx("button",{type:"submit","data-portable-unlock-submit":!0,className:Q,children:m("st.portable.unlockAction")})]}):e.jsx("button",{type:"button",className:Q,onClick:()=>{E.refetch()},children:m("common.retry")})]}):null,M!==void 0?M.domains.length===0?e.jsx("p",{className:"text-[13px] text-ink-faint",children:m("st.portable.inspectEmpty")}):e.jsx("div",{className:"divide-y divide-hairline border-t border-b border-hairline","data-portable-domain-list":!0,children:M.domains.map(({domain:O,count:B})=>{const le=z.get(O)??[],re=S.has(O);return e.jsxs("div",{"data-portable-domain-row":O,children:[e.jsxs("button",{type:"button","aria-expanded":re,onClick:()=>{H(O)},className:"flex w-full items-baseline justify-between gap-4 py-2.5 text-left outline-none transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[13px] font-medium text-ink",children:[e.jsx(Rt,{open:re}),e.jsx("span",{children:m(g1[O])})]}),e.jsx("span",{className:"text-right text-[12px] tabular-nums text-ink-soft",children:m("st.portable.itemCount",{count:B})})]}),re&&le.length>0?e.jsx("ul",{className:"mb-2 space-y-1 pl-5",children:le.map(ae=>{const ne=j===ae.id,Ee=ae.scalarValue!==void 0;return e.jsxs("li",{"data-portable-item-row":ae.id,className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 py-1 text-[12.5px]",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-ink",children:[e.jsx("span",{children:ae.label}),ae.masked?e.jsx(de,{name:"lock",size:12,className:"text-ink-faint"}):null]}),e.jsx("span",{className:"ml-2 font-mono text-[11px] text-ink-faint",children:ae.path})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:ne?e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:ie=>{ie.preventDefault(),q(ae)},children:[e.jsx("input",{"data-portable-item-edit-input":ae.id,value:A,onChange:ie=>{P(ie.target.value)},className:`${Gt} w-40 py-1 font-mono text-[11.5px]`}),e.jsx("button",{type:"submit","data-portable-item-edit-save":ae.id,disabled:R!==null,className:Ot,children:m("common.save")}),e.jsx("button",{type:"button",className:"text-[12px] text-ink-faint hover:text-ink",onClick:()=>{T(null)},children:m("common.cancel")})]}):e.jsxs(e.Fragment,{children:[ae.summary!==void 0?e.jsx("span",{className:"max-w-[14rem] truncate font-mono text-[11.5px] text-ink-soft",title:ae.summary,children:ae.summary}):ae.bytes!==void 0?e.jsx("span",{className:"text-[11.5px] tabular-nums text-ink-faint",children:aa(ae.bytes)}):null,!U&&Ee&&!ae.masked?e.jsx("button",{type:"button","data-portable-item-edit":ae.id,disabled:R!==null,className:Ot,onClick:()=>{T(ae.id),P(ae.scalarValue===null?"null":String(ae.scalarValue))},children:m("st.portable.editItem")}):null,U?null:e.jsx("button",{type:"button","data-portable-item-remove":ae.id,disabled:R!==null,className:"text-[12px] text-ink-faint transition-colors hover:text-danger disabled:opacity-50",onClick:()=>{F(ae)},children:m("st.portable.removeItem")})]})})]},ae.id)})}):null]},O)})}):null,M?.excluded&&M.excluded.length>0?e.jsx("ul",{className:"space-y-1 text-[12px] text-ink-soft","data-portable-excluded-list":!0,children:M.excluded.map(O=>e.jsxs("li",{"data-portable-excluded-item":O.id,className:"flex flex-wrap gap-x-2",children:[e.jsx("span",{className:"font-mono text-ink",children:O.path}),e.jsx("span",{className:"text-ink-faint",children:O.reason})]},O.id))}):null,e.jsx(pe,{feedback:I})]}):null,o==="compare"?e.jsx(s3,{client:t,token:s,source:n,spaces:a,portableSources:i,initialMode:n.endpoint.kind==="url"?"merge":l,initialRightEndpoint:c,sourceUnlock:w,onApplied:()=>{E.refetch(),b()}},`${n.id}:${l??(n.endpoint.kind==="url"?"merge":"sync")}:${c===void 0?"main":ls(c)}`):null,o==="colab"?e.jsx(e3,{client:t,token:s,source:n,inspect:M,deviceRecipient:r,portableSources:i,unlock:w,onRekeyed:(O,B)=>{X(O,{nextUnlock:B,updateUnlock:!0})}}):null]})}function a3({open:t,client:s,source:n,onCancel:a,onRemoved:i}){const{t:r,locale:o}=D(),l=x.useId(),[c,d]=x.useState(!1),[u,p]=x.useState(null),[h,b]=x.useState(!1),[m,f]=x.useState(!1),[g,v]=x.useState(null),[y,w]=x.useState(!1),N=x.useCallback(()=>{const j=new AbortController;return b(!0),v(null),w(!1),Wt(s).previewRemoveSource(n.id,{signal:j.signal}).then(T=>{j.signal.aborted||p(T)}).catch(T=>{j.signal.aborted||(p(null),v(T))}).finally(()=>{j.signal.aborted||b(!1)}),()=>{j.abort()}},[s,n.id]);x.useEffect(()=>{if(t)return d(!1),N()},[t,N]);const _=async()=>{if(!(m||u===null||y)){f(!0),v(null);try{const j=await Wt(s).removeReviewedSource(n.id,{previewToken:u.previewToken,purgeManaged:c,impactDigest:u.impactDigest,createBackup:!0});i(j,c)}catch(j){v(j),(y1(j)||k1(j))&&w(!0),f(!1)}}},C=u?.impact,S=u?.managedCount??n.managedIds?.length??0,k=C?.deletedIds.length??0;return e.jsx(Xe,{open:t,stacked:!0,overlayId:"portable-remove-subscription-dialog",title:r("st.portable.center.removeTitle",{name:n.label}),tone:c?"danger":"default",busy:m,confirmDisabled:h||u===null||y,confirmLabel:c?r("st.portable.center.removeConfirmPurge",{count:k}):r("st.portable.center.removeConfirmDetach"),confirmData:{"data-portable-remove-confirm":c?"purge":"detach"},onConfirm:()=>{_()},onCancel:a,children:e.jsxs("div",{className:"mt-4 space-y-3","data-portable-remove-dialog":n.id,children:[h?e.jsx("p",{className:"text-[12.5px] text-ink-soft","data-portable-remove-loading":!0,children:r("st.portable.center.removeLoading")}):null,g!==null?e.jsxs("div",{className:"space-y-2","data-portable-remove-error":!0,children:[e.jsx(De,{error:g}),y||u===null?e.jsx("button",{type:"button","data-portable-remove-refresh":!0,className:Q,onClick:()=>{N()},children:r("st.portable.center.refreshPreview")}):null]}):null,e.jsxs("fieldset",{className:"divide-y divide-hairline border-t border-b border-hairline",disabled:h||m,children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 py-3 pointer-coarse:min-h-11",children:[e.jsx("input",{type:"radio",name:l,value:"detach","data-portable-remove-choice":"detach",checked:!c,onChange:()=>{d(!1)},className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--color-selected-ink)]"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:r("st.portable.center.removeDetachTitle")}),e.jsx("span",{className:"block text-[12px] text-ink-soft",children:r("st.portable.center.removeDetachDesc",{count:S})})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 py-3 pointer-coarse:min-h-11",children:[e.jsx("input",{type:"radio",name:l,value:"purge","data-portable-remove-choice":"purge",checked:c,onChange:()=>{d(!0)},className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--color-danger)]"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:r("st.portable.center.removePurgeTitle")}),e.jsx("span",{className:"block text-[12px] text-ink-soft",children:r("st.portable.center.removePurgeDesc")}),C!==void 0?e.jsxs("ul",{className:"space-y-0.5 pt-1 text-[12px] text-ink-soft","data-portable-remove-impact":!0,children:[e.jsx("li",{className:"font-medium text-ink",children:r("st.portable.center.impactDeleted",{count:C.deletedIds.length})}),C.preservedLocalIds.length>0?e.jsx("li",{children:r("st.portable.center.impactPreservedLocal",{count:C.preservedLocalIds.length})}):null,C.handedOffIds.length>0?e.jsx("li",{children:r("st.portable.center.impactHandedOff",{count:C.handedOffIds.length})}):null,C.preservedDependencyIds.length>0?e.jsx("li",{children:r("st.portable.center.impactPreservedDep",{count:C.preservedDependencyIds.length})}):null,C.pendingReconcileIds.length>0?e.jsx("li",{className:"text-amber-ink",children:r("st.portable.center.impactPending",{count:C.pendingReconcileIds.length})}):null,e.jsx("li",{className:"text-ink-faint",children:r("st.portable.center.removeBackupNote")})]}):null]})]})]}),g!==null&&typeof g=="string"?e.jsx("p",{className:"text-[12px] text-danger-ink",children:oe(o,g)}):null]})})}const i3="anim-enter w-full max-w-[460px] rounded-xl bg-paper p-6 text-ink outline-none max-md:max-w-none max-md:rounded-b-none max-md:pb-[calc(1.5rem+var(--kiki-safe-bottom-inset))]";function r3(t,s){if(t===void 0)return null;const n=Date.parse(t);if(!Number.isFinite(n))return null;const a=Math.max(0,Math.round((Date.now()-n)/1e3));if(a<60)return s.startsWith("zh")?"刚刚":"just now";const i=Math.round(a/60);if(i<60)return s.startsWith("zh")?`${i} 分钟前`:`${i}m ago`;const r=Math.round(i/60);if(r<24)return s.startsWith("zh")?`${r} 小时前`:`${r}h ago`;const o=Math.round(r/24);return s.startsWith("zh")?`${o} 天前`:`${o}d ago`}function Df(t){return t.syncPolicy==="auto"||t.syncPolicy==="manual"?t.syncPolicy:t.autoSync===!1?"manual":"auto"}function o3({client:t,spaces:s,mainPath:n,externalExportRequest:a,onClearExternalExport:i,initialSubscribeIntent:r,initialSubscribeUrl:o,onClearInitialSubscribe:l}){const c=mt(),{t:d,locale:u}=D(),p=Oe(),h=Li("portable"),b=j1(t),[m,f]=x.useState(null),[g,v]=x.useState(null),[y,w]=x.useState(null),[N,_]=x.useState(null),[C,S]=x.useState(""),[k,j]=x.useState(!1),[T,A]=x.useState(null),[P,R]=x.useState(null),[L,I]=x.useState(!1),[$,E]=x.useState(!1),[M,z]=x.useState(null),[H,U]=x.useState(null),[X,q]=x.useState(null),[F,V]=x.useState("contents"),[se,Y]=x.useState({mode:"sync"}),[O,B]=x.useState(null),le=x.useRef(null);x.useEffect(()=>{B(null)},[t]),x.useEffect(()=>{a!=null&&(f(a),i?.())},[a,i]),x.useEffect(()=>{r!=null?(v({kind:"new",initialIntent:r}),l?.()):o!=null&&o.trim()!==""&&(v({kind:"new",initialIntent:{id:`prop-url-${o}`,url:o.trim(),origin:"query"}}),l?.())},[r,o,l]),x.useEffect(()=>{if(!(c.onFileDrop===void 0||g!==null))return c.onFileDrop(W=>{const Re=le.current;if(Re!==null){if(W.position!==void 0){const Ae=Re.getBoundingClientRect();if(!(W.position.x>=Ae.left&&W.position.x<=Ae.right&&W.position.y>=Ae.top&&W.position.y<=Ae.bottom))return}if(W.paths.length!==1||!w1(W.paths[0]??"")){B({tone:"error",text:d("st.portable.center.dropInvalid")});return}B(null),v({kind:"new",initialArchivePath:W.paths[0],initialTab:"archive"})}})},[c,g,d]);const re=b.data?.items??[],ae=b.data?.orderRevision??"0",ne=b.data?.deviceRecipient,Ee=x.useMemo(()=>{const W=re.filter(Ae=>Ae.endpoint.kind==="url").slice().sort((Ae,Ue)=>(Ae.priority??Number.MAX_SAFE_INTEGER)-(Ue.priority??Number.MAX_SAFE_INTEGER)),Re=re.filter(Ae=>Ae.endpoint.kind!=="url");return[...W,...Re]},[re]),ie=x.useMemo(()=>{const W=new Map;for(const Re of Ee){if(Re.endpoint.kind!=="url")continue;const Ae=Re.linkedSpaceId??at,Ue=W.get(Ae)??[];Ue.push(Re),W.set(Ae,Ue)}return W},[Ee]),me=x.useMemo(()=>Ee.filter(W=>W.endpoint.kind==="url"&&W.enabled),[Ee]),fe=h.selected===null?void 0:Ee.find(W=>W.id===h.selected),Ie=x.useCallback(()=>{p.invalidateQueries({queryKey:tg.all})},[p]),te=(W,Re,Ae)=>{V(Re),Ae!==void 0&&Y(Ae),h.open(W.id)},ee=W=>{B(null),Wt(t).removeSource(W.id).then(()=>{h.selected===W.id&&h.close(),Ie(),vt({tone:"success",text:d("st.portable.removeSourceDone",{name:W.label})})}).catch(Re=>{B({tone:"error",text:oe(u,Re)})})},K=W=>{const Re=eg({source:W.endpoint});rs(Re).then(()=>{vt({tone:"success",text:d("st.portable.colabCopied")})}).catch(Ae=>{B({tone:"error",text:oe(u,Ae)})})},Z=W=>{T===null&&(A(W.id),B(null),Wt(t).syncSubscription(W.id,{force:!1,createBackup:!0},{view:"center-v1"}).then(Re=>{if(Ie(),Re.kind==="subscription")if(Re.status==="error"){const Ae=d("st.portable.syncError",{error:Re.error??"Unknown error"});B({tone:"error",text:Ae}),vt({tone:"error",text:Ae})}else if(Re.status==="not_modified"){const Ae=d("st.portable.syncNotModified",{name:W.label});B({tone:"info",text:Ae}),vt({tone:"info",text:Ae})}else{const Ae=Re.appliedIds.length+Re.deletedIds.length,Ue=d("st.portable.syncUpdated",{name:W.label,count:Ae});B({tone:"success",text:Ue}),vt({tone:"success",text:Ue})}}).catch(Re=>{B({tone:"error",text:oe(u,Re)})}).finally(()=>{A(null)}))},ue=async(W,Re)=>{if(P===null){R(W.id),B(null);try{if(await Wt(t).patchSource(W.id,{expectedRevision:W.revision,...Re}),Ie(),Re.label!==void 0){const Ae=d("st.portable.center.renameSaved",{name:Re.label});B({tone:"success",text:Ae}),vt({tone:"success",text:Ae})}}catch(Ae){B({tone:"error",text:oe(u,Ae)})}finally{R(null)}}},Te=async(W,Re)=>{if($)return;const Ae=W.linkedSpaceId??at,Ue=ie.get(Ae)??[],Ge=Ue.findIndex(ce=>ce.id===W.id);if(Ge<0||Re<0||Re>=Ue.length||Ge===Re)return;const Ke=Ue.map(ce=>ce.id),[We]=Ke.splice(Ge,1);Ke.splice(Re,0,We),E(!0),B(null);try{await Wt(t).reorderSources({spaceId:Ae,orderedIds:Ke,expectedOrderRevision:ae}),Ie(),vt({tone:"success",text:d("st.portable.center.priorityUpdated")})}catch(ce){B({tone:"error",text:oe(u,ce)})}finally{E(!1)}},Ne=async()=>{if(L||me.length<2)return;I(!0),B(null);let W=0,Re=0,Ae=0;const Ue=Wt(t);for(const Ke of me)try{(await Ue.previewSource(Ke.id,{})).items.some(qe=>qe.selected&&(qe.status==="will_write"||qe.status==="new_scope"||qe.status==="removed_impact"))?W+=1:Re+=1}catch{Ae+=1}I(!1),Ie();const Ge=d("st.portable.center.checkAllDone",{total:me.length,updated:W,current:Re,failed:Ae});B({tone:Ae>0?"error":"info",text:Ge}),vt({tone:Ae>0?"error":"info",text:Ge})},J=W=>W===void 0||W===at?d("st.spaces.main"):s.find(Re=>Re.id===W)?.name??W,_e=W=>{const Re=W.selection;if(Re===void 0)return d("st.portable.center.scopeAll");const Ae=W.managedIds?.length??0;return d("st.portable.center.scopeSummary",{scopes:Re.enabledScopes.length,items:Ae})},we=W=>W.endpoint.kind==="url"?d("st.portable.badge.url"):W.spaceMode==="overlay"?d("st.portable.badge.overlay"):W.endpoint.kind==="git"?d("st.portable.badge.git"):W.format==="age"?".kiki.age":W.format==="tgz"?d("st.portable.badge.tgz"):d("st.portable.badge.dir"),G=W=>W.secretMode==="none"?d("st.portable.badge.secretNone"):W.secretMode==="plain"?d("st.portable.badge.secretPlain"):W.secretMode==="sealed"||W.format==="age"||W.encryptionMode!==void 0&&W.encryptionMode!=="none"?d("st.portable.badge.secretEncrypted"):d("st.portable.badge.secretNone"),Le=W=>{if(W.endpoint.kind==="url"){const Ge=Df(W),Ke=W.linkedSpaceId??at,We=ie.get(Ke)??[],ce=We.findIndex(gt=>gt.id===W.id),qe=We.length>1,st=W.encryptionMode==="passphrase";return[{key:"edit-selection",label:d("st.portable.center.editSelection"),run:()=>{v({kind:"edit-selection",source:W})}},{key:"check-updates",label:d("st.portable.center.checkUpdates"),run:()=>{v({kind:"update-review",source:W})}},{key:"toggle-policy",label:d(Ge==="auto"?"st.portable.center.switchToManual":"st.portable.center.switchToAuto"),blockedReason:Ge==="manual"&&st?d("st.portable.center.switchToAutoBlockedPassphrase"):void 0,run:()=>{ue(W,{syncPolicy:Ge==="auto"?"manual":"auto"})}},{key:"rename",label:d("st.portable.center.rename"),run:()=>{_(W),S(W.label)}},...qe?[{key:"move-up",label:d("st.portable.center.moveUp"),separatorBefore:!0,blockedReason:ce<=0?d("st.portable.center.moveUpBlocked"):void 0,run:()=>{Te(W,ce-1)}},{key:"move-down",label:d("st.portable.center.moveDown"),blockedReason:ce>=We.length-1?d("st.portable.center.moveDownBlocked"):void 0,run:()=>{Te(W,ce+1)}}]:[],{key:"compare",label:d("st.portable.compare"),separatorBefore:!0,run:()=>{te(W,"compare",{mode:"merge"})}},{key:"fork",label:d("st.portable.forkMenu"),run:()=>{f({intent:"fork",source:W.endpoint,mode:"full"})}},{key:"copy-colab",label:d("st.portable.copyColabMenu"),run:()=>{K(W)}},{key:"unsubscribe",label:d("st.portable.center.unsubscribe"),danger:!0,separatorBefore:!0,run:()=>{w(W)}}]}const Ae=W.endpoint.kind==="dir"&&W.format==="dir",Ue=W.endpoint.kind==="archive"&&(W.format==="age"||W.format==="tgz");return[{key:"fork",label:d("st.portable.forkMenu"),run:()=>{f({intent:"fork",source:W.endpoint,mode:"full"})}},...Ae?[{key:"pack",label:d("st.portable.packAction"),run:()=>{U({source:W,action:"pack"})}}]:[],...Ue?[{key:"unpack",label:d("st.portable.unpackAction"),run:()=>{U({source:W,action:"unpack"})}}]:[],{key:"copy-colab",label:d("st.portable.copyColabMenu"),run:()=>{K(W)}},{key:"remove",label:d("st.portable.removeSource"),danger:!0,separatorBefore:!0,run:()=>{ee(W)}}]},Se=W=>{const Re=Ic(W.endpoint,W.gitBranch),Ae=Df(W),Ue=W.linkedSpaceId??at,Ge=ie.get(Ue)??[],Ke=Ge.findIndex(st=>st.id===W.id),We=Ge.length>1,ce=r3(W.lastSyncedAt??W.lastCheckedAt,u),qe=ce===null?d("st.portable.center.neverSynced"):W.lastSyncedAt!==void 0?d("st.portable.center.lastSynced",{time:ce}):d("st.portable.center.lastChecked",{time:ce});return e.jsxs("div",{"data-portable-source-row":W.id,"data-portable-source-kind":"url","data-portable-source-policy":Ae,"data-portable-source-enabled":W.enabled?"true":"false",draggable:We&&!$,onDragStart:()=>{z(W.id)},onDragOver:st=>{M!==null&&M!==W.id&&st.preventDefault()},onDrop:st=>{st.preventDefault();const gt=Ge.find(Es=>Es.id===M);z(null),gt!==void 0&&Ke>=0&&Te(gt,Ke)},onDragEnd:()=>{z(null)},style:{minHeight:_s.comfortable},className:"flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2.5 sm:flex-nowrap",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[We?e.jsxs("span",{"data-portable-priority-rank":W.id,className:"w-5 text-right font-mono text-[11px] tabular-nums text-ink-faint",title:d("st.portable.center.moveUp"),children:["#",Ke+1]}):e.jsx(de,{name:"web",size:14,className:"text-ink-faint"}),e.jsx(Be,{layout:"bare",label:`${W.label} (${d(W.enabled?"st.portable.center.pause":"st.portable.center.resume")})`,checked:W.enabled,disabled:P!==null,onChange:st=>{ue(W,{enabled:st})}})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("button",{type:"button","data-detail-trigger":W.id,onClick:()=>{te(W,"contents")},title:W.label,className:`min-w-0 shrink truncate rounded text-left text-[13px] font-medium transition-colors hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink pointer-coarse:inline-flex pointer-coarse:min-h-11 pointer-coarse:items-center ${W.enabled?"text-ink":"text-ink-faint"}`,children:W.label}),e.jsx("span",{className:"shrink-0 text-[11.5px] text-ink-soft","data-portable-policy-label":W.id,children:W.enabled?d(Ae==="auto"?"st.portable.center.policyAuto":"st.portable.center.policyManual"):d("st.portable.center.paused")}),e.jsxs("span",{className:"shrink-0 text-[11.5px] text-ink-faint","data-portable-scope-summary":W.id,children:["· ",_e(W)]}),s.length>1?e.jsxs("span",{className:"shrink-0 text-[11.5px] text-ink-faint",children:["· ",J(W.linkedSpaceId)]}):null,W.availableNewScopes.length>0?e.jsxs("span",{className:"shrink-0 text-[11.5px] font-medium text-amber-ink","data-portable-new-scopes":W.id,children:["· ",d("st.portable.center.newScopesBadge",{count:W.availableNewScopes.length})]}):null,W.needsReconcile?e.jsxs("span",{className:"shrink-0 text-[11.5px] font-medium text-amber-ink","data-portable-needs-reconcile":W.id,children:["· ",d("st.portable.center.needsReconcile")]}):null]}),e.jsxs("p",{className:"truncate text-[11.5px] text-ink-faint",children:[e.jsx("span",{className:"font-mono",title:Re,children:Re})," · ",e.jsx("span",{children:qe})]}),W.lastSyncError?e.jsx("p",{className:"truncate text-[11.5px] text-danger-ink","data-portable-sync-error":W.id,children:d("st.portable.syncError",{error:W.lastSyncError})}):null]}),e.jsxs("div",{className:"flex w-full shrink-0 items-center justify-end gap-1.5 sm:ml-auto sm:w-auto",children:[W.enabled?Ae==="manual"||W.needsReconcile?e.jsx("button",{type:"button","data-portable-check-updates":W.id,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{v({kind:"update-review",source:W})},children:d("st.portable.center.checkUpdates")}):e.jsx("button",{type:"button","data-portable-sync-now":W.id,disabled:T!==null,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{Z(W)},children:T===W.id?d("st.portable.syncing"):d("st.portable.syncNow")}):e.jsx("button",{type:"button","data-portable-resume":W.id,disabled:P!==null,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{ue(W,{enabled:!0})},children:d("st.portable.center.resume")}),e.jsx("button",{type:"button","data-portable-menu":W.id,"aria-haspopup":"menu","aria-label":d("st.portable.menuAria",{name:W.label}),className:"flex h-8 w-8 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:h-11 pointer-coarse:w-11",onClick:st=>{q({source:W,anchor:st.currentTarget.getBoundingClientRect(),anchorElement:st.currentTarget})},children:e.jsx(de,{name:"more",size:14})})]})]})},Fe=W=>{const Re=Ic(W.endpoint,W.gitBranch),Ae=W.endpoint.kind==="git"?"branch":W.format==="age"?"lock":"folder",Ue=W.secretMode==="plain";return e.jsxs("div",{"data-portable-source-row":W.id,"data-portable-source-kind":W.endpoint.kind,style:{minHeight:_s.comfortable},className:"flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2 sm:flex-nowrap",children:[e.jsx(de,{name:Ae,size:14,className:"text-ink-faint"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("button",{type:"button","data-detail-trigger":W.id,onClick:()=>{te(W,"contents")},title:W.label,className:"min-w-0 shrink truncate rounded text-left text-[13px] font-medium text-ink transition-colors hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink",children:W.label}),e.jsx("span",{"data-portable-kind-badge":W.id,className:"shrink-0 text-[11.5px] text-ink-soft",children:we(W)}),e.jsxs("span",{"data-portable-secret-badge":W.id,className:`shrink-0 text-[11.5px] ${Ue?"font-medium text-amber-ink":"text-ink-faint"}`,children:["· ",G(W)]})]}),e.jsx("p",{className:"truncate font-mono text-[11.5px] text-ink-faint",title:Re,children:Re})]}),e.jsxs("div",{className:"flex w-full shrink-0 items-center justify-end gap-1.5 sm:ml-auto sm:w-auto",children:[e.jsx("button",{type:"button","data-portable-compare":W.id,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{te(W,"compare",{mode:"sync"})},children:d("st.portable.compare")}),e.jsx("button",{type:"button","data-portable-apply":W.id,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{te(W,"compare",{mode:"merge",right:{kind:"live",spaceId:at}})},children:d("st.portable.apply")}),e.jsx("button",{type:"button","data-portable-menu":W.id,"aria-haspopup":"menu","aria-label":d("st.portable.menuAria",{name:W.label}),className:"flex h-8 w-8 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink pointer-coarse:h-11 pointer-coarse:w-11",onClick:Ge=>{q({source:W,anchor:Ge.currentTarget.getBoundingClientRect(),anchorElement:Ge.currentTarget})},children:e.jsx(de,{name:"more",size:14})})]})]})},ye=W=>{const Re=m?.intent==="fork";f(null),Ie();const Ae=Re?d("st.portable.forkDone",{path:W.destination}):d("st.portable.exportDone",{count:W.totalItems,path:W.destination}),Ue=W.excluded?.length?` (${W.excluded.map(Ke=>`${Ke.path}: ${Ke.reason}`).join("; ")})`:"",Ge=`${Ae}${Ue}`;B({tone:"success",text:Ge}),vt({tone:"success",text:Ge})},ze=W=>{v(null),Ie();let Re;if(W.kind==="linked")Re=d("st.portable.linkDone",{name:W.record.label});else if(W.kind==="patch")Re=d("st.portable.center.updateSaved",{name:W.result.source.label});else if(W.commit.kind==="once"){const Ae=W.commit.appliedIds.length+W.commit.deletedIds.length;Re=d("st.portable.center.importOnceDone",{count:Ae})}else{const Ae=W.commit.appliedIds.length+W.commit.deletedIds.length;Re=W.commit.status==="not_modified"?d("st.portable.syncNotModified",{name:W.commit.source.label}):d("st.portable.subscribeDone",{name:W.commit.source.label,count:Ae})}B({tone:"success",text:Re}),vt({tone:"success",text:Re})},Pe=e.jsxs("div",{ref:le,className:"space-y-3","data-portable-sources-list":!0,children:[b.isLoading?e.jsx(he,{children:d("st.portable.loading")}):null,b.isError?e.jsxs("div",{className:"space-y-2","data-portable-sources-error":!0,children:[N1(b.error)?e.jsx("p",{className:"text-[13px] text-ink-soft","data-portable-unsupported-host":!0,children:d("st.portable.center.unsupportedHost")}):e.jsx(De,{error:b.error}),e.jsx("button",{type:"button","data-portable-sources-retry":!0,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{b.refetch()},children:d("common.retry")})]}):null,Ee.length>0?e.jsx(Hs,{items:Ee,keyOf:W=>W.id,density:"comfortable",label:d("st.portable.title"),renderRow:W=>W.endpoint.kind==="url"?Se(W):Fe(W)}):b.isSuccess?e.jsx("p",{className:"text-[13px] text-ink-soft","data-portable-empty":!0,children:d("st.portable.center.emptyHint")}):null,e.jsx(pe,{feedback:O})]}),xe=e.jsx(jo,{label:d("st.portable.title"),count:Ee.length,children:Ee.map(W=>e.jsx(Na,{itemKey:W.id,label:W.label,hint:we(W),current:W.id===fe?.id,onSelect:()=>{te(W,F)}},W.id))}),ke=fe===void 0?null:e.jsx(n3,{client:t,source:fe,spaces:s,portableSources:Ee,deviceRecipient:ne,tab:F,compareMode:se.mode,compareRightEndpoint:se.right,onTabChange:V,onClose:h.close,onFork:W=>{f({intent:"fork",source:W.endpoint,mode:"full"})},onPackUnpack:(W,Re)=>{U({source:W,action:Re})},onMutated:Ie},fe.id);return e.jsxs(Me,{id:"st-card-portable-spaces",title:d("st.portable.title"),scope:"server",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[me.length>=2?e.jsx("button",{type:"button","data-portable-check-all":!0,disabled:L,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{Ne()},children:d(L?"st.portable.center.checkingAll":"st.portable.center.checkAllUpdates")}):null,e.jsx("button",{type:"button","data-portable-export-open":!0,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{f({intent:"export",source:{kind:"live",spaceId:at}})},children:d("st.portable.export")}),e.jsx("button",{type:"button","data-portable-subscribe-open":!0,"data-portable-link-open":!0,className:`${Ye} pointer-coarse:min-h-11`,onClick:()=>{v({kind:"new"})},children:d("st.portable.addOrImport")})]}),children:[e.jsx(wo,{selected:fe?.id??null,label:d("st.portable.title"),data:{"data-portable-split":""},list:Pe,rail:xe,detail:ke}),X!==null?e.jsx($a,{anchor:X.anchor,anchorElement:X.anchorElement,items:Le(X.source),onClose:()=>{q(null)},ariaLabel:d("st.portable.menuAria",{name:X.source.label})}):null,m!==null?e.jsx(ZF,{client:t,spaces:s,portableSources:Ee,deviceRecipient:ne,mainPath:n,intent:m.intent,initialSource:m.source,initialMode:m.mode,onClose:()=>{f(null)},onDone:ye}):null,g!==null?e.jsx(kS,{client:t,spaces:s,mode:g,onClose:()=>{v(null)},onDone:ze}):null,y!==null?e.jsx(a3,{open:!0,client:t,source:y,onCancel:()=>{w(null)},onRemoved:(W,Re)=>{const Ae=y.label,Ue=y.id;w(null),h.selected===Ue&&h.close(),Ie();const Ge=Re?d("st.portable.center.removeDonePurge",{name:Ae,deleted:W.impact.deletedIds.length,preserved:W.impact.preservedLocalIds.length+W.impact.preservedDependencyIds.length}):d("st.portable.center.removeDoneDetach",{name:Ae});B({tone:"success",text:Ge}),vt({tone:"success",text:Ge})}}):null,N!==null?e.jsx(Ea,{stacked:!0,ariaLabel:d("st.portable.center.renameTitle"),overlayId:"portable-rename-dialog",overlayClassName:z1,panelClassName:i3,dismissible:!k,onClose:()=>{k||_(null)},children:e.jsxs("form",{className:"space-y-4","data-portable-rename-dialog":N.id,onSubmit:W=>{W.preventDefault();const Re=C.trim();!Re||k||(j(!0),ue(N,{label:Re}).finally(()=>{j(!1),_(null)}))},children:[e.jsx("h3",{className:"font-display text-[18px] font-semibold text-ink",children:d("st.portable.center.renameTitle")}),e.jsx("input",{"data-autofocus":!0,"data-portable-rename-input":!0,value:C,maxLength:120,onChange:W=>{S(W.target.value)},className:Ce}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",disabled:k,className:`${Q} pointer-coarse:min-h-11`,onClick:()=>{_(null)},children:d("common.cancel")}),e.jsx("button",{type:"submit","data-portable-rename-submit":!0,disabled:k||C.trim()==="",className:`${Ye} pointer-coarse:min-h-11`,children:d(k?"common.saving":"common.save")})]})]})}):null,H!==null?e.jsx(XF,{client:t,source:H.source,action:H.action,deviceRecipient:ne,onClose:()=>{U(null)},onDone:W=>{const Re=H.action==="pack";U(null),Ie();const Ae=d(Re?"st.portable.packDone":"st.portable.unpackDone",{path:W.destination});B({tone:"success",text:Ae}),vt({tone:"success",text:Ae})}}):null]})}function l3(){const{client:t,localClient:s,meta:n,connectionId:a,sshLabel:i}=be(),r=mt(),{t:o}=D(),l=Bt(),c=Et(),u=typeof a=="string"&&a!==""||!!i,p=r.kind==="tauri"?s:s??(u?null:t),h=Jd(p,p===t?n:void 0),b=Aa(),m=b!==null&&!b.homeId.startsWith("remote:")?b:null,f=On(p),g=h?.identity.homeId??m?.homeId??at,v=g===at?o("st.spaces.main"):m?.name??f.data?.find(C=>C.id===g)?.name??o("sidebar.space.unnamed"),y=f.data?.find(C=>C.id===at)?.path??"",[w,N]=x.useState(null),_=x.useCallback(()=>{N(null)},[]);return x.useEffect(()=>{const C=new URLSearchParams(l.search),S=C.get("exportSpace");if(S===null||S.trim()==="")return;N({intent:"export",source:{kind:"live",spaceId:S.trim()}}),C.delete("exportSpace");const k=C.toString(),j=`${l.pathname}${k===""?"":`?${k}`}${l.hash}`;c(j,{replace:!0})},[l.hash,l.pathname,l.search,c]),e.jsxs(e.Fragment,{children:[u?e.jsx("p",{className:"text-[13px] text-ink-soft","data-subscriptions-remote-scope-banner":!0,children:o("st.spaces.remoteScopeBanner",{space:v})}):null,p===null?e.jsx(he,{children:o("st.spaces.loading")}):e.jsx(o3,{client:p,spaces:f.data??[],mainPath:y,externalExportRequest:w,onClearExternalExport:_})]})}function c3(){return e.jsxs(e.Fragment,{children:[e.jsx(oy,{}),e.jsx(ly,{})]})}function d3({section:t,onSearchHit:s}){const{t:n}=D();return e.jsxs("div",{"data-settings-unknown":!0,className:"mx-auto max-w-[760px] px-4 py-10 lg:px-8",children:[e.jsx("h2",{className:"font-display text-[15px] font-semibold tracking-tight text-ink",children:n("st.unknown.title")}),e.jsx("p",{className:"mt-1 max-w-[480px] text-[12.5px] leading-relaxed text-ink-soft",children:n("st.unknown.body",{section:t})}),e.jsx(Ju,{focusToken:null,onSearchHit:s,className:"mt-4 max-w-[360px]"})]})}const u3=/^[a-z0-9][a-z0-9/-]*\/$/;function zk(){const{client:t}=be();return je({queryKey:["config"],queryFn:()=>t.getConfig(),staleTime:6e4,select:s=>s.worktree})}function Qk(){const{client:t}=be(),s=Oe();return async n=>{const a=await t.patchConfig({worktree:n});s.setQueryData(["config"],a)}}function hn({label:t,help:s,children:n}){const a=bt();return e.jsxs(e.Fragment,{children:[e.jsxs(ge,{label:t,help:s,children:[e.jsx(ot,{saving:a.saving,saved:a.saved}),n(a)]}),e.jsx(pe,{feedback:a.error})]})}function p3({stored:t}){const{t:s}=D(),n=Qk(),a=bt(),i=t.join(`
|
|
255
|
+
`),[r,o]=x.useState(i);x.useEffect(()=>{o(i)},[i]);const l=()=>{const c=[...new Set(r.split(`
|
|
256
|
+
`).map(d=>d.trim()).filter(d=>d!==""))];if(c.join(`
|
|
257
|
+
`)===i){o(i);return}a.run(()=>n({cleanup:{disposable_ignored:c}}))};return e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("label",{className:"text-[13px] text-ink",htmlFor:"worktree-disposable-ignored",children:s("st.worktreePolicy.disposable")}),e.jsx(ot,{saving:a.saving,saved:a.saved})]}),e.jsx(he,{children:s("st.worktreePolicy.disposableHelp")}),e.jsx("textarea",{id:"worktree-disposable-ignored","data-worktree-disposable":!0,rows:4,spellCheck:!1,disabled:a.saving,className:`${Ce} h-auto py-1.5 font-mono text-[12px] leading-5`,value:r,onChange:c=>{o(c.target.value)},onBlur:l,onKeyDown:c=>{c.key==="Escape"&&o(i)}}),e.jsx(pe,{feedback:a.error})]})}function m3(){const{t}=D(),s=zk(),n=Qk();if(s.isError)return e.jsx(De,{error:s.error});const a=s.data;return a===void 0?s.isLoading?e.jsx(he,{children:t("st.runtime.loading")}):null:e.jsx("div",{"data-worktree-policy":!0,children:e.jsxs(is,{title:t("st.worktreePolicy.title"),children:[e.jsx(hn,{label:t("st.worktreePolicy.enabled"),help:t("st.worktreePolicy.enabledHelp"),children:i=>e.jsx(Be,{layout:"bare",label:t("st.worktreePolicy.enabled"),checked:a.enabled,disabled:i.saving,onChange:r=>void i.run(()=>n({enabled:r}))})}),e.jsx(hn,{label:t("st.worktreePolicy.base"),help:t("st.worktreePolicy.baseHelp"),children:i=>e.jsx(He,{ariaLabel:t("st.worktreePolicy.base"),dataAttr:"data-worktree-base",value:a.defaultBase,disabled:i.saving,onChange:r=>void i.run(()=>n({default_base:r})),choices:[{value:"head",label:t("st.worktreePolicy.baseHead")},{value:"fresh",label:t("st.worktreePolicy.baseFresh")}]})}),e.jsx(hn,{label:t("st.worktreePolicy.prefix"),help:t("st.worktreePolicy.prefixHelp"),children:i=>e.jsx(kt,{ariaLabel:t("st.worktreePolicy.prefix"),dataAttr:"data-worktree-prefix",className:"w-36 font-mono",value:a.branchPrefix,disabled:i.saving,validate:r=>u3.test(r)?null:t("st.worktreePolicy.prefixInvalid"),onCommit:r=>void i.run(()=>n({branch_prefix:r}))})}),e.jsx(hn,{label:t("st.worktreePolicy.autoCleanup"),help:t("st.worktreePolicy.autoCleanupHelp"),children:i=>e.jsx(Be,{layout:"bare",label:t("st.worktreePolicy.autoCleanup"),checked:a.cleanup.auto,disabled:i.saving,onChange:r=>void i.run(()=>n({cleanup:{auto:r}}))})}),e.jsx(hn,{label:t("st.worktreePolicy.afterDays"),help:t("st.worktreePolicy.afterDaysHelp"),children:i=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{ariaLabel:t("st.worktreePolicy.afterDays"),dataAttr:"data-worktree-after-days",className:"w-16",inputMode:"numeric",value:String(a.cleanup.afterDays),disabled:i.saving,validate:r=>/^\d+$/.test(r)&&Number(r)>=1?null:t("st.worktreePolicy.daysInvalid"),onCommit:r=>void i.run(()=>n({cleanup:{after_days:Number(r)}}))}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:t("st.worktreePolicy.daysUnit")})]})}),e.jsx(et,{summary:t("st.worktreePolicy.advanced"),children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(hn,{label:t("st.worktreePolicy.root"),help:t("st.worktreePolicy.rootHelp"),children:i=>e.jsx(kt,{ariaLabel:t("st.worktreePolicy.root"),dataAttr:"data-worktree-root",className:"w-72 max-w-full font-mono",value:a.root,placeholder:t("st.worktreePolicy.rootDefault"),disabled:i.saving,validate:r=>r===""||/^(?:[A-Za-z]:[\\/]|[\\/])/.test(r)?null:t("st.worktreePolicy.rootInvalid"),onCommit:r=>void i.run(()=>n({root:r}))})}),e.jsx(hn,{label:t("st.worktreePolicy.gitTimeout"),help:t("st.worktreePolicy.gitTimeoutHelp"),children:i=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(kt,{ariaLabel:t("st.worktreePolicy.gitTimeout"),dataAttr:"data-worktree-git-timeout",className:"w-20",inputMode:"numeric",value:String(a.gitTimeoutMs/1e3),disabled:i.saving,validate:r=>/^\d+$/.test(r)&&Number(r)>=1&&Number(r)<=600?null:t("st.worktreePolicy.timeoutInvalid"),onCommit:r=>void i.run(()=>n({git_timeout_ms:Number(r)*1e3}))}),e.jsx("span",{className:"text-[12px] text-ink-faint",children:t("st.residency.secondsUnit")})]})}),e.jsx(p3,{stored:a.cleanup.disposableIgnored})]})})]})})}const x3=2,h3="inline-flex h-8 shrink-0 items-center rounded-md px-2.5 text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-45 disabled:hover:bg-transparent disabled:hover:text-ink-soft pointer-coarse:h-11 pointer-coarse:px-3",f3="inline-flex h-8 shrink-0 items-center rounded-md px-2.5 text-[12.5px] text-ink-soft transition-colors hover:bg-danger/10 hover:text-danger focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-45 disabled:hover:bg-transparent disabled:hover:text-ink-soft pointer-coarse:h-11 pointer-coarse:px-3";function b3(t){let s=0;const n=[];return async a=>{s>=t&&await new Promise(i=>{n.push(i)}),s+=1;try{return await a()}finally{s-=1,n.shift()?.()}}}function g3(){const{client:t}=be(),{t:s,tp:n,locale:a}=D(),i=Oe(),r=t.klient.rest!==void 0,o=zk().data?.cleanup.afterDays??7,l=je({queryKey:im.list(),queryFn:()=>Gi(t).list(),enabled:r,staleTime:1e4,refetchOnWindowFocus:!0}),c=x.useMemo(()=>jS(l.data?.worktrees??[]),[l.data]),d=x.useMemo(()=>[...new Set(c.map(E=>E.owner.sessionId))],[c]),u=x.useMemo(()=>b3(x3),[t]),p=wS({queries:d.map(E=>({queryKey:["worktrees","owner-session",E],queryFn:()=>u(()=>t.getSession(E)),enabled:r,staleTime:1e4,retry:!1}))}),h=new Map(d.map((E,M)=>[E,{session:p[M]?.data,settled:p[M]?.isPending===!1}])),[b,m]=x.useState(new Map),[f,g]=x.useState(null),[v,y]=x.useState(null),[w,N]=x.useState(null),[_,C]=x.useState(!1),[S,k]=x.useState(null),[j,T]=x.useState(!1),A=()=>{i.invalidateQueries({queryKey:im.all})},P=(E,M)=>{m(z=>new Map(z).set(E,M))},R=E=>{g(E.id),N(null),Gi(t).inspect(E.id).then(M=>{P(E.id,M)}).catch(M=>{N({tone:"error",text:oe(a,M)})}).finally(()=>{g(null)})},L=()=>{C(!0),N(null),Gi(t).gc(!0).then(({candidates:E})=>{const M=E.filter(H=>H.outcome==="removed").length,z=E.length-M;M>0?k({removable:M,kept:z}):N({tone:"info",text:z===0?s("st.worktrees.cleanupNone"):n("st.worktrees.cleanupOnlyKept",z)})}).catch(E=>{N({tone:"error",text:oe(a,E)})}).finally(()=>{C(!1)})},I=()=>{k(null),C(!0),Gi(t).gc(!1).then(({candidates:E})=>{const M=E.filter(z=>z.outcome==="removed").length;N({tone:"success",text:s("st.worktrees.cleanupResult",{removed:M,kept:E.length-M})}),A()}).catch(E=>{N({tone:"error",text:oe(a,E)})}).finally(()=>{C(!1)})},$=(E,M)=>{y(null),N(M==="removed"?{tone:"success",text:s("st.worktrees.removed",{branch:E.branch})}:{tone:"error",text:s("st.worktrees.notRemoved",{branch:E.branch,reason:s(Gb(M))}),path:E.path}),A()};return r?e.jsxs(Me,{id:"st-card-worktrees",title:s("st.worktrees.title"),children:[e.jsxs("div",{className:"space-y-2.5",children:[l.isLoading?e.jsx(he,{children:s("st.worktrees.loading")}):null,l.isError?e.jsx(De,{error:l.error}):null,l.isSuccess&&c.length===0?e.jsx("p",{"data-worktrees-empty":!0,className:"py-1 text-[12.5px] leading-relaxed text-ink-faint",children:s("st.worktrees.empty")}):null,c.length>0?e.jsx("ul",{"data-worktree-list":!0,className:"divide-y divide-hairline border-y border-hairline",children:c.map(E=>e.jsx(j3,{record:E,owner:h.get(E.owner.sessionId),inspection:b.get(E.id)??E.lastInspection,checking:f===E.id,onCheck:()=>{R(E)},onRemove:()=>{N(null),y(E)}},E.id))}):null,w!==null?e.jsx(v3,{notice:w}):null,c.length>0?e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("button",{type:"button","data-worktrees-cleanup":!0,disabled:_||!l.isSuccess,onClick:L,className:"inline-flex h-8 shrink-0 items-center rounded-md bg-ink/[0.05] px-3 text-[12.5px] font-medium text-ink transition-colors hover:bg-ink/[0.09] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-50 pointer-coarse:h-11",children:s(_?"st.worktrees.cleanupChecking":"st.worktrees.cleanup")}),e.jsxs("button",{type:"button","data-worktrees-help-toggle":!0,"aria-expanded":j,"aria-controls":"worktrees-help-panel",onClick:()=>{T(E=>!E)},className:"inline-flex h-8 items-center gap-1 rounded-md px-1.5 text-[12px] font-medium text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink pointer-coarse:h-11",children:[e.jsx(de,{name:"chevron",size:12,className:`shrink-0 text-ink-faint transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${j?"rotate-90":""}`}),e.jsx("span",{children:s("st.help.label")})]})]}),j?e.jsxs("div",{id:"worktrees-help-panel","data-worktrees-help-body":!0,className:"max-w-[60ch] space-y-1.5 border-l-2 border-hairline pl-3 text-[12px] leading-relaxed text-ink-soft",children:[e.jsx("p",{children:s("st.worktrees.cleanupRule",{days:o})}),e.jsx("p",{className:"text-ink-faint",children:s("st.worktrees.hint")})]}):null]}):null,e.jsx("div",{className:"pt-4",children:e.jsx(m3,{})})]}),v!==null?e.jsx(NS,{record:v,onClose:()=>{y(null)},onInspected:E=>{P(v.id,E)},onDone:E=>{$(v,E)}}):null,S!==null?e.jsx(Xe,{open:!0,overlayId:"confirm-worktree-cleanup",title:s("st.worktrees.cleanupConfirmTitle"),body:n("st.worktrees.cleanupConfirmBody",S.removable),consequences:S.kept>0?[n("st.worktrees.cleanupKeepCount",S.kept)]:void 0,confirmLabel:s("st.worktrees.cleanup"),tone:"danger",onCancel:()=>{k(null)},onConfirm:I}):null]}):null}function v3({notice:t}){const{t:s}=D(),n=t.tone==="error"?"border-danger bg-danger/5 text-danger":t.tone==="success"?"border-success bg-success/5 text-success":"border-hairline-strong bg-ink/[0.03] text-ink-soft";return e.jsxs("div",{"data-worktree-notice":t.tone,role:t.tone==="error"?"alert":"status",className:`rounded-r-md border-l-2 px-3 py-2 text-[12px] leading-snug ${n}`,children:[e.jsx("p",{children:t.text}),t.tone==="error"&&t.path!==void 0?e.jsx("p",{"data-worktree-kept-path":!0,className:"mt-1 font-mono text-[11px] break-all text-ink-soft",children:s("st.worktrees.keptAt",{path:t.path})}):null]})}function y3(t,s,n,a){return n.state==="remove_failed"?{text:t("st.worktrees.state.failed"),tone:"danger"}:n.state==="creating"?{text:t("st.worktrees.state.creating"),tone:"faint"}:n.state==="removing"?{text:t("st.worktrees.state.removing"),tone:"faint"}:n.state==="orphaned"?{text:t("st.worktrees.state.orphaned"),tone:"faint"}:a!==void 0&&a.archived!==!0?{text:t("st.worktrees.state.inUse"),tone:"active"}:a!==void 0?{text:t("st.worktrees.state.archived",{time:s.relativeTime(a.archived_at??a.updated_at)}),tone:"faint"}:{text:t("st.worktrees.state.ready"),tone:"faint"}}function k3({inspection:t}){const{t:s,tp:n}=D();if(t===void 0)return e.jsx("span",{className:"text-ink-faint",children:s("st.worktrees.notChecked")});if(t.failed)return e.jsx("span",{className:"text-amber-ink",children:s("st.worktrees.checkFailed")});const a=[];if(t.dirtyFiles>0&&a.push(n("st.worktrees.dirty",t.dirtyFiles)),t.unpushedCommits>0&&a.push(n("st.worktrees.unpushed",t.unpushedCommits)),a.length===0&&t.ignoredNonDisposable.length===0)return e.jsx("span",{"data-worktree-changes":"clean",className:"text-ink-faint",children:s("st.worktrees.clean")});const i=t.ignoredNonDisposable,r=[...a,...i.length>0?[s("st.worktrees.ignored",{names:i.slice(0,5).join(", ")})]:[]],o=[...a,...i.length>0?[s("st.worktrees.ignoredShort",{names:i.slice(0,2).join(", ")})]:[]];return e.jsx("span",{"data-worktree-changes":"dirty",title:r.join(`
|
|
258
|
+
`),className:"font-medium text-amber-ink",children:o.join(", ")})}function j3({record:t,owner:s,inspection:n,checking:a,onCheck:i,onRemove:r}){const{t:o,time:l}=D(),c=Tt(),d=s?.session,u=y3(o,l,t,d),p=d!==void 0&&d.archived!==!0,h=s?.settled!==!0,b=t.state==="creating"||t.state==="removing",m=SS(d?.title||o("sidebar.untitled")),f=d===void 0?void 0:m,g=p||h||b,v=u.tone==="danger"?"rounded-full bg-danger/10 px-2 py-0.5 text-[11px] font-medium leading-4 text-danger":u.tone==="active"?"rounded-full bg-selected-ink/[0.09] px-2 py-0.5 text-[11px] font-medium leading-4 text-selected-ink":"text-[11.5px] tabular-nums text-ink-faint",y=`worktree-in-use-${t.id}`;return e.jsxs("li",{"data-worktree-row":t.id,"data-worktree-state":t.state,className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 px-2.5 py-2.5 transition-colors hover:bg-ink/[0.02]",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsxs("p",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",title:`${t.branch}
|
|
259
|
+
${t.repo.sourceRoot} @ ${t.base.ref}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[13px] text-ink",children:[e.jsx(de,{name:"branch",size:12,className:"shrink-0 text-ink-faint"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[12.5px]",children:t.branch})]}),e.jsx("span",{"data-worktree-state-label":!0,className:`shrink-0 ${v}`,children:u.text})]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-x-1.5 text-[12px] leading-5 text-ink-faint",children:[f!==void 0?e.jsx("button",{type:"button","data-worktree-session":!0,onClick:()=>{c(`/s/${d.id}`)},"aria-label":o("st.worktrees.openSessionAria",{title:f}),className:"min-w-0 max-w-[45%] shrink-[3] truncate rounded-sm text-ink-soft underline-offset-2 hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-selected-ink",children:f}):h?null:e.jsxs("span",{"data-worktree-session-missing":!0,title:t.owner.sessionId,className:"shrink-0",children:[o("st.worktrees.sessionMissing"),t.owner.sessionId?` (${Od(t.owner.sessionId)})`:""]}),f!==void 0||!h?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{className:"min-w-0 shrink truncate",children:e.jsx(k3,{inspection:n})}),e.jsx("span",{"aria-hidden":!0,className:"hidden sm:inline",children:"·"}),e.jsx("span",{className:"hidden min-w-0 shrink-[2] truncate sm:inline",title:t.repo.sourceRoot,children:c0(t.repo.sourceRoot)})]}),t.state==="remove_failed"?e.jsxs("div",{"data-worktree-kept-path":!0,className:"mt-1.5 border-l-2 border-danger/60 pl-2",children:[t.removal!==void 0?e.jsx("p",{className:"text-[12px] leading-5 text-danger",children:o(Gb(t.removal.outcome))}):null,e.jsx("p",{className:"font-mono text-[11px] leading-4 break-all text-ink-soft",children:o("st.worktrees.keptAt",{path:t.path})})]}):null]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button","data-worktree-check":!0,disabled:a||b,onClick:i,"aria-label":o("st.worktrees.checkAria",{branch:t.branch}),className:h3,children:o(a?"st.worktrees.checking":"st.worktrees.check")}),e.jsx("span",{title:p?o("st.worktrees.removeInUse"):void 0,className:"inline-flex",children:e.jsx("button",{type:"button","data-worktree-remove":!0,disabled:g,onClick:r,"aria-label":o("st.worktrees.removeAria",{branch:t.branch}),"aria-describedby":p?y:void 0,className:f3,children:o("st.worktrees.remove")})}),p?e.jsx("span",{id:y,"data-worktree-in-use":!0,className:"sr-only",children:o("st.worktrees.removeInUse")}):null]})]})}const wr=t=>["plugin-usage",{workspace_id:t}],w3=t=>["workspace-trust",t],Ff=t=>["memory-workspace-settings",t],N3=t=>["agent-profiles",{workspace_id:t}],S3=t=>["mcp-managed-servers",t],C3=t=>["workspace-skills",t];function _3({workspaceId:t}){const{client:s}=be(),{t:n,locale:a}=D(),i=Et(),r=Oe(),o=je({queryKey:["workspaces","catalog"],queryFn:()=>s.listWorkspaceCatalog(),staleTime:3e4}),l=x.useMemo(()=>o.data?.items.find(L=>L.id===t),[o.data,t]),c=je({queryKey:["workspace-details",t],queryFn:()=>s.getWorkspaceDetails(t),enabled:l!==void 0,staleTime:3e4,retry:!1}),[d,u]=x.useState(null),[p,h]=x.useState(null),b=x.useContext(ky),m=Ks({mutationFn:L=>s.renameWorkspaceCatalog(t,L),onSuccess:L=>{u(null),h({tone:"success",text:n("st.workspaces.detail.renamed",{name:L.name})}),r.invalidateQueries({queryKey:["workspaces"]})},onError:L=>{h({tone:"error",text:oe(a,L)})}}),f=Ks({mutationFn:L=>s.setWorkspacePinnedCatalog(t,L),onSuccess:()=>{r.invalidateQueries({queryKey:["workspaces"]})},onError:L=>{h({tone:"error",text:oe(a,L)})}}),g=R3(t),v=A3(t),y=O3(t),[w,N]=x.useState(null),[_,C]=x.useState(!1),[S,k]=x.useState(!1),j=e.jsxs("button",{type:"button",onClick:()=>{i(_d())},className:"-ml-1 inline-flex min-h-8 items-center gap-1 rounded-md px-1 text-[13px] text-ink-soft transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink","data-workspace-detail-back":!0,children:[e.jsx(de,{name:"arrowLeft",size:14}),n("st.workspaces.detail.back")]});x.useEffect(()=>(l!==void 0&&b(l.name),()=>{b(null)}),[b,l?.name]);const T=x.useRef(null);if(x.useEffect(()=>{d!==null&&T.current?.select()},[d!==null]),o.isPending)return e.jsx("p",{className:"py-3 text-[13px] text-ink-faint",role:"status","data-workspace-detail-loading":!0,children:n("cap.loading")});if(o.isError)return e.jsxs("div",{className:"space-y-2","data-workspace-detail-error":!0,children:[e.jsx(De,{error:o.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{o.refetch()},children:n("common.retry")})]});if(l===void 0)return e.jsx(D3,{});const A=d??l.name,P=A.trim()!==""&&A.trim()!==l.name,R=L=>{N({...L,scope:{kind:"workspace",target:{workspace_id:l.id},name:l.name}})};return e.jsxs("div",{className:"space-y-6","data-workspace-detail":l.id,children:[j,e.jsxs(Me,{id:"st-card-workspace-detail",title:l.name,scope:"workspace",children:[e.jsx("p",{className:"min-w-0 truncate font-mono text-[12px] text-ink-faint","data-workspace-detail-root":!0,title:l.root,children:l.root}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-faint","data-workspace-detail-stats":!0,children:c.isError?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:n("st.workspaces.detail.statsFailed")}),e.jsx("button",{type:"button",className:Q,onClick:()=>{c.refetch()},children:n("common.retry")})]}):e.jsxs("p",{role:c.isPending?"status":void 0,children:[n("st.list.sort.sessions")," · ",c.data===void 0?n("cap.loading"):c.data.session_count]})}),e.jsx("div",{className:"mt-4",children:e.jsxs(Ze,{children:[d===null?e.jsx(ge,{label:n("st.workspaces.renameTitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{"data-workspace-detail-name":!0,className:"text-[13px] text-ink",children:l.name}),e.jsx("button",{type:"button",className:Q,"data-workspace-detail-rename":!0,onClick:()=>{u(l.name)},children:n("st.workspaces.rename")})]})}):e.jsx(ge,{label:n("st.workspaces.renameTitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{ref:T,"data-workspace-detail-name-input":!0,"aria-label":n("st.workspaces.renameTitle"),className:"min-w-0 max-w-[42ch] flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 text-[13px] text-ink outline-none focus:border-selected-ink",value:A,maxLength:100,onChange:L=>{u(L.currentTarget.value)},onKeyDown:L=>{rt(L)||(L.key==="Enter"&&P&&!m.isPending&&m.mutate(A.trim()),L.key==="Escape"&&u(null))}}),e.jsx("button",{type:"button",className:Ye,disabled:!P||m.isPending,"data-workspace-detail-rename-save":!0,onClick:()=>{m.mutate(A.trim())},children:m.isPending?n("common.saving"):n("common.save")}),e.jsx("button",{type:"button",className:Q,"data-workspace-detail-rename-cancel":!0,disabled:m.isPending,onClick:()=>{u(null)},children:n("common.cancel")})]})}),e.jsx(ge,{label:n("st.workspaces.pin"),children:e.jsx(Be,{layout:"bare",label:l.pinned?n("st.workspaces.unpin"):n("st.workspaces.pin"),checked:l.pinned,disabled:f.isPending,onChange:L=>{f.mutate(L)}})})]})}),p!==null?e.jsx("div",{className:"mt-2",children:e.jsx(pe,{feedback:p})}):null]}),e.jsx(E3,{workspace:l,onInstall:R,onAddFromSource:()=>{C(!0)},onBrowse:()=>{k(!0)}}),e.jsx($3,{workspace:l,read:v}),e.jsx(L3,{workspace:l,memory:g}),e.jsx(M3,{workspace:l,profiles:y}),S?e.jsx(CS,{title:n("st.workspaces.detail.browseTitle"),body:n("st.workspaces.detail.browseBody"),onClose:()=>{k(!1)},onPick:L=>{k(!1),R({source:L.source,sha256:L.sha256,displayName:L.displayName,icon:L.icon,entry:L})}}):null,_?e.jsx(_S,{onClose:()=>{C(!1)},onPreview:L=>{C(!1),R(L)}}):null,w!==null?e.jsx(Kb,{request:w,onClose:()=>{N(null)},onInstalled:()=>{r.invalidateQueries({queryKey:wr(l.id)})}}):null]})}function E3({workspace:t,onInstall:s,onAddFromSource:n,onBrowse:a}){const{t:i,locale:r}=D(),{client:o}=be(),l=Oe(),c=Bb(),d=x.useMemo(()=>({workspace_id:t.id}),[t.id]),[u,p]=x.useState({}),[h,b]=x.useState({}),m=je({queryKey:wr(t.id),queryFn:()=>o.getPluginUsage(d),staleTime:5e3,retry:!1}),f=Ks({mutationFn:_=>o.setPluginUsage({target:d,plugin_id:_.pluginId,override:_.override}),onMutate:_=>{const{override:C}=_;p(C==="inherit"?({[_.pluginId]:S,...k})=>k:S=>({...S,[_.pluginId]:C})),b(({[_.pluginId]:S,...k})=>k)},onSuccess:_=>{if(p({}),b({}),TS(_,rm(m.data)))return;const C=l.getQueryData(wr(t.id));(C===void 0||!IS(C.revision,_.revision))&&l.setQueryData(wr(t.id),_),c()},onError:(_,C)=>{p(({[C.pluginId]:S,...k})=>k),b(S=>({...S,[C.pluginId]:oe(r,_)}))}}),g=(_,C)=>{f.mutateAsync({pluginId:_,override:C}).catch(()=>{})},v=(_,C)=>{MS(_)!==void 0&&C!==_.effective&&g(_.id,C?"on":"off")},y=rm(m.data),w=m.data?.plugins??[],N=Wb(m.error);return e.jsxs(Me,{id:"st-card-workspace-plugins",title:i("st.workspaces.detail.plugins"),scope:"workspace",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[12px] text-ink-faint","data-workspace-plugins-scope":!0,title:y?.root,children:y===void 0?i("st.workspaces.detail.pluginsScopePending"):i("st.workspaces.detail.pluginsScope",{name:y.name})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",className:"rounded text-[12px] text-ink-faint transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink","data-workspace-plugins-browse":"",onClick:a,children:i("rail.plugins.browse")}),e.jsx("button",{type:"button",className:"rounded text-[12px] text-ink-faint transition-colors hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink","data-workspace-plugins-add-source":"",onClick:n,children:i("rail.plugins.addSource")})]})]}),N?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint","data-workspace-plugins-unsupported":"",children:i("st.workspaces.detail.pluginsUnsupported")}):m.isPending?e.jsxs("p",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink-faint",role:"status",children:[e.jsx(Us,{label:i("cap.loading")}),i("rail.plugins.loading")]}):m.isError?e.jsxs("div",{className:"mt-3 space-y-2","data-workspace-plugins-error":!0,children:[e.jsx(De,{error:m.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{m.refetch()},children:i("common.retry")})]}):w.length===0?e.jsx("p",{className:"mt-3 text-[13px] leading-relaxed text-ink-faint","data-workspace-plugins-empty":!0,children:i("st.workspaces.detail.pluginsEmpty")}):e.jsx("ul",{className:"mt-2","data-workspace-plugins-list":!0,children:w.map(_=>e.jsx(P3,{item:_,pending:u[_.id],failure:h[_.id],busy:f.isPending&&f.variables?.pluginId===_.id,onToggle:v,onRestore:C=>{g(C.id,"inherit")},onInstall:s},_.id))})]})}const T3={session:"rail.plugins.source.session",workspace:"rail.plugins.source.workspace",global:"rail.plugins.source.global",home:"rail.plugins.source.home"},I3={home_disabled:"rail.plugins.reason.homeOff",invalid_plugin:"rail.plugins.reason.invalid",workspace_disabled:"rail.plugins.reason.workspaceOff",session_disabled:"rail.plugins.reason.sessionOff",global_disabled:"rail.plugins.reason.globalOff"};function P3({item:t,pending:s,failure:n,busy:a,onToggle:i,onRestore:r,onInstall:o}){const{t:l}=D(),c=s===void 0?t.effective:s==="on",d=PS(t),u=s===void 0?AS(t):"workspace";return e.jsxs("li",{className:"flex min-w-0 items-center gap-3 border-b border-hairline py-2.5 last:border-b-0","data-workspace-plugin":t.id,"data-override":s??t.override,"data-effective":String(c),children:[e.jsx($S,{icon:t.icon,kind:"plugin",size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"min-w-0 truncate text-[13px] font-medium text-ink",title:t.displayName,children:t.displayName}),e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-[12px] leading-4 text-ink-faint",children:[d.kind==="blocked"?e.jsx("span",{"data-workspace-plugin-reason":d.reason,children:l(I3[d.reason])}):e.jsx("span",{"data-workspace-plugin-source":u,children:l(T3[u])}),t.app_service?e.jsx("span",{"data-workspace-plugin-app-service":"",title:l("rail.plugins.appServiceHint"),children:l("rail.plugins.appService")}):null,RS(t)&&!LS(t)?e.jsx("button",{type:"button",className:"rounded underline decoration-dotted underline-offset-2 transition-colors hover:text-ink","data-workspace-plugin-restore":"",onClick:()=>{r(t)},children:l("rail.plugins.restore")}):null,a?e.jsx(Us,{label:l("rail.plugins.saving")}):null,n!==void 0?e.jsx("span",{role:"alert",className:"text-danger","data-workspace-plugin-error":!0,children:n}):null]})]}),e.jsx(Be,{label:l("st.workspaces.detail.pluginToggle",{name:t.displayName}),layout:"bare",checked:c,disabled:a||d.kind==="blocked",onChange:p=>{i(t,p)}}),t.state==="error"?e.jsx("button",{type:"button",className:"shrink-0 rounded text-[12px] text-ink-faint transition-colors hover:text-ink","data-workspace-plugin-reinstall":t.id,onClick:()=>{o({source:t.id,displayName:t.displayName,...t.icon!==void 0?{icon:t.icon}:{}})},children:l("common.retry")}):null]})}function A3(t){const{client:s}=be(),n=je({queryKey:w3(t),queryFn:()=>s.getWorkspaceTrust(t),retry:!1}),a=Ks({mutationFn:i=>s.setWorkspaceTrust(t,i)});return{read:n,write:a}}function $3({workspace:t,read:s}){const{t:n,locale:a}=D(),[i,r]=x.useState(null),o=s.read.data?.trusted===!0,l=Wb(s.read.error),c=async d=>{r(null);try{await s.write.mutateAsync(d),r({tone:"success",text:n(d?"st.workspaces.detail.trustGranted":"st.workspaces.detail.trustRemoved")})}catch(u){r({tone:"error",text:oe(a,u)})}};return e.jsxs(Me,{id:"st-card-workspace-trust",title:n("st.workspaces.detail.trust"),scope:"workspace",children:[l?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-snug text-ink-faint","data-workspace-trust-unsupported":"",children:n("st.workspaces.detail.trustUnsupported")}):s.read.isPending?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:n("cap.loading")}):s.read.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:s.read.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{s.read.refetch()},children:n("common.retry")})]}):e.jsx(Ze,{children:e.jsx(ge,{label:n("st.workspaces.detail.trustToggleLabel"),help:n("st.workspaces.detail.trustHelp"),children:e.jsx(Be,{id:"workspace-trust-toggle",layout:"bare",label:n("st.workspaces.detail.trustToggleLabel"),checked:o,disabled:s.write.isPending,onChange:d=>{c(d)}})})}),i!==null?e.jsx("div",{className:"mt-2",children:e.jsx(pe,{feedback:i})}):null]})}function R3(t){const{client:s}=be(),n=Oe(),a=je({queryKey:Ff(t),queryFn:()=>s.getWorkspaceMemorySettings(t),retry:!1}),i=Ks({mutationFn:r=>s.patchWorkspaceMemorySettings(t,r),onSuccess:async()=>{await Promise.all([n.invalidateQueries({queryKey:Ff(t)}),n.invalidateQueries({queryKey:ES})])}});return{read:a,write:i}}function L3({workspace:t,memory:s}){const{t:n,locale:a}=D(),[i,r]=Je(),[o,l]=x.useState(null),c=s.read.data?.enabled===null||s.read.data===void 0?"inherit":String(s.read.data.enabled),d=async p=>{l(null);try{await s.write.mutateAsync(p==="inherit"?null:p==="true"),r()}catch(h){l({tone:"error",text:oe(a,h)})}},u=s.read.data===void 0?void 0:n(s.read.data.effective_enabled?"st.memory.enabled":"st.memory.disabled");return e.jsxs(Me,{id:"st-card-workspace-memory",title:n("st.memory.workspaces"),scope:"workspace",children:[s.read.isPending?e.jsx("p",{className:"text-[13px] text-ink-faint",role:"status",children:n("cap.loading")}):s.read.isError?e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{error:s.read.error}),e.jsx("button",{type:"button",className:Q,onClick:()=>{s.read.refetch()},children:n("common.retry")})]}):e.jsxs(ge,{label:n("memory.ws.label"),help:u===void 0?n("st.memory.workspaceHelp"):n("st.memory.workspaceEffectiveInline",{state:u}),children:[e.jsx(jt,{show:i&&!s.write.isPending}),e.jsx(Qe,{dataAttr:"data-workspace-memory-override",ariaLabel:n("memory.ws.label"),value:c,disabled:s.write.isPending,onChange:p=>{d(p)},choices:[{value:"inherit",label:n("st.workspaces.detail.inherit")},{value:"true",label:n("st.memory.enabled")},{value:"false",label:n("st.memory.disabled")}]})]}),o!==null?e.jsx("div",{className:"mt-2",children:e.jsx(pe,{feedback:o})}):null]})}function M3({workspace:t,profiles:s}){const{t:n}=D(),{client:a,klient:i}=be(),r=je({queryKey:S3(t.root),queryFn:()=>i.global.mcp.list({cwd:t.root}),staleTime:6e4,retry:!1}),o=je({queryKey:C3(t.id),queryFn:()=>a.listWorkspaceSkills(t.id),staleTime:3e4,retry:!1}),l=s.data?.items.length;return e.jsx(Me,{id:"st-card-workspace-resources",title:n("st.workspaces.detail.resources"),scope:"workspace",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(bc,{label:n("st.workspaces.detail.profiles"),detail:l===void 0?void 0:n("st.workspaces.detail.count",{count:l}),to:`/settings/agents?workspace=${encodeURIComponent(t.id)}`,dataAttr:"data-workspace-profiles-link"}),e.jsx(bc,{label:n("st.workspaces.detail.mcp"),detail:r.isPending?n("cap.loading"):r.isError?n("st.workspaces.detail.unreadable"):n("st.workspaces.detail.count",{count:r.data?.length??0}),to:`/settings/mcp?workspace=${encodeURIComponent(t.id)}`,dataAttr:"data-workspace-mcp-link"}),e.jsx(bc,{label:n("st.workspaces.detail.skills"),detail:o.isPending?n("cap.loading"):o.isError?n("st.workspaces.detail.unreadable"):n("st.workspaces.detail.count",{count:o.data?.skills.length??0}),to:`/capabilities?tab=skills&workspace=${encodeURIComponent(t.id)}`,dataAttr:"data-workspace-skills-link"})]})})}function bc({label:t,detail:s,to:n,dataAttr:a}){const{t:i}=D();return e.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-b border-hairline py-2 last:border-b-0",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] text-ink",children:t}),s!==void 0?e.jsx("p",{className:"text-[12px] text-ink-faint",children:s}):null]}),e.jsxs(_t,{to:n,"aria-label":i("st.workspaces.detail.openResource",{name:t}),className:"inline-flex min-h-8 shrink-0 items-center gap-1 rounded-md px-2 text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-selected-ink",[a]:"",children:[t,e.jsx(de,{name:"arrowRight",size:12,className:"text-ink-faint"})]})]})}function O3(t){const{client:s}=be();return je({queryKey:N3(t),queryFn:()=>s.listNamedAgentProfiles({workspace_id:t}),staleTime:3e4,retry:!1})}function D3(){const{t}=D(),s=Et();return e.jsxs("div",{className:"space-y-4 py-2","data-workspace-detail-missing":!0,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-[18px] leading-6 text-ink",children:t("st.workspaces.detail.missingTitle")}),e.jsx("p",{className:"mt-1 max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:t("st.workspaces.detail.missingBody")})]}),e.jsx("button",{type:"button",className:Q,"data-workspace-detail-back":!0,onClick:()=>{s(_d())},children:t("st.workspaces.title")})]})}function F3({workspaceId:t}){return t!=null&&t!==""?e.jsx(_3,{workspaceId:t}):e.jsx(q3,{})}function q3(){const{client:t,scopeId:s,sshLabel:n,activateLocal:a}=be(),{t:i,locale:r}=D(),o=Tt(),l=Oe(),c=je({queryKey:["workspaces","catalog"],queryFn:()=>t.listWorkspaceCatalog(),staleTime:3e4}),[d,u]=x.useState(null),[p,h]=x.useState(null),[b,m]=x.useState(null),[f,g]=x.useState(null),[v,y]=x.useState(null),[w,N]=x.useState(!1),_=x.useMemo(()=>c.data?.items??[],[c.data]);x.useEffect(()=>{_.length===0&&N(!1)},[_.length]);const C=()=>{l.invalidateQueries({queryKey:["workspaces"]})},S=T=>{l.setQueryData(["workspaces","catalog"],A=>A===void 0?A:{items:A.items.map(P=>P.id===T.id?T:P)}),u(null),C()},k=T=>{y(T.id),g(null),t.setWorkspacePinnedCatalog(T.id,!T.pinned).then(A=>{l.setQueryData(["workspaces","catalog"],P=>P===void 0?P:{items:P.items.map(R=>R.id===A.id?A:R)}),C()}).catch(A=>{g({tone:"error",text:oe(r,A)})}).finally(()=>{y(null)})},j=(T,A)=>{y("bulk"),g(null),Promise.all(T.filter(P=>P.pinned!==A).map(P=>t.setWorkspacePinnedCatalog(P.id,A))).then(C).catch(P=>{g({tone:"error",text:oe(r,P)})}).finally(()=>{y(null)})};return e.jsxs(e.Fragment,{children:[e.jsxs(Me,{id:"st-card-workspaces",title:i("st.workspaces.title"),aside:n===null?i("connect.localScope"):`${i("connect.remoteScope")} · ${n}`,actions:_.length>0?e.jsx("button",{type:"button","data-list-select":!0,"data-workspaces-select":!0,"aria-pressed":w,onClick:()=>{N(T=>!T)},className:`h-7 shrink-0 px-1.5 pointer-coarse:h-11 ${Ot}`,children:i(w?"common.cancel":"st.workspaces.select")}):void 0,children:[e.jsxs("div",{className:"space-y-2",children:[s.startsWith("ssh:")?e.jsx("button",{type:"button",onClick:a,className:Q,children:i("connect.switchLocal")}):null,_.length>0?e.jsx(H3,{items:_,selecting:w,onSelectingChange:N,pinBusy:v,onPin:k,onBulkPin:j,renamingId:d,onRename:T=>{u(T.id)},onRenameDone:S,onRenameCancel:()=>{u(null)},onRemove:h,onBulkRemove:m,onNewSession:T=>{o(`/new?workspace=${encodeURIComponent(T.id)}`)},onOpenDetail:T=>{o(lb(T.id))}}):null,e.jsx(W3,{items:_}),!c.isLoading&&!c.isError&&_.length===0?e.jsx(Ct,{kind:"none",title:i("st.workspaces.emptyTitle"),body:i("st.workspaces.emptyBody"),action:e.jsx("button",{type:"button",className:Q,onClick:()=>{o("/new?workspace=new")},children:i("st.workspaces.emptyAction")})}):null,c.isLoading?e.jsx(he,{children:i("st.workspaces.loading")}):null,c.isError?e.jsx(De,{error:c.error}):null,f!==null?e.jsx(pe,{feedback:f}):null]}),p!==null?e.jsx(Xe,{open:!0,overlayId:"confirm-workspace-remove",title:i("st.workspaces.removeTitle",{name:p.name}),body:i("st.workspaces.removeBody"),confirmLabel:i("st.workspaces.remove"),tone:"danger",onCancel:()=>h(null),onConfirm:()=>{const T=p;h(null),g(null),t.removeWorkspace(T.id).then(C).catch(A=>{g({tone:"error",text:oe(r,A)})})}}):null,b!==null?e.jsx(Xe,{open:!0,overlayId:"confirm-workspace-bulk-remove",title:i("st.workspaces.bulkRemoveTitle",{count:b.length}),body:i("st.workspaces.bulkRemoveBody"),confirmLabel:i("st.workspaces.bulkRemoveConfirm",{count:b.length}),tone:"danger",onCancel:()=>m(null),onConfirm:()=>{const T=b;m(null),g(null),Promise.all(T.map(A=>t.removeWorkspace(A.id))).then(C).catch(A=>{C(),g({tone:"error",text:oe(r,A)})})}}):null]}),e.jsx(g3,{})]})}const B3=10080*60*1e3,K3=(t,s)=>Date.parse(s.last_opened_at)-Date.parse(t.last_opened_at);function U3(t){const s=t.name.trim(),n=l=>/^[0-9a-f]{7,}$/i.test(l)||/^[0-9a-f-]{16,}$/i.test(l)&&/[0-9]/.test(l);if(!n(s))return s;const a=t.root.replaceAll("\\","/").split("/").filter(l=>l!==""),i=a.at(-1)??s,r=a.slice(0,-1).reverse().find(l=>!n(l)&&!/^releases?$/i.test(l)),o=`${i.slice(0,7)}…`;return r===void 0?o:`${r} · ${o}`}function H3({items:t,selecting:s,onSelectingChange:n,pinBusy:a,onPin:i,onBulkPin:r,renamingId:o,onRename:l,onRenameDone:c,onRenameCancel:d,onRemove:u,onBulkRemove:p,onNewSession:h,onOpenDetail:b}){const{t:m}=D(),f=x.useMemo(()=>[{id:"pinned",label:m("st.workspaces.filter.pinned"),test:T=>T.pinned}],[m]),g=x.useMemo(()=>[{id:"recent",label:m("st.list.sort.recent"),compare:K3},{id:"name",label:m("st.list.sort.name"),compare:(T,A)=>T.name.localeCompare(A.name)}],[m]),v=x.useCallback(T=>T.id,[]),y=x.useCallback(T=>[T.name,T.root],[]),w=Qs({listId:"workspaces",items:t,keyOf:v,textOf:y,filters:f,sorts:g});x.useEffect(()=>{!s&&w.selected.size>0&&w.setSelected(new Set)},[s]);const[N]=x.useState(()=>Date.now()),_=x.useMemo(()=>{if(w.sort!=="recent")return[{key:"all",label:"",items:w.visible,total:t.length}];const T=A=>[A.pinned?{key:"pinned",label:m("st.workspaces.group.pinned")}:N-Date.parse(A.last_opened_at)<B3?{key:"recent",label:m("st.workspaces.group.recent")}:{key:"older",label:m("st.workspaces.group.older")}];return ng(t,w.visible,T,["pinned","recent","older"]).filter(A=>A.items.length>0)},[w.sort,w.visible,t,N,m]),C=t.filter(T=>w.selected.has(T.id)),S=C.length>0&&C.every(T=>T.pinned),k=w.visible.length>0&&w.visible.every(T=>w.selected.has(T.id)),j=T=>e.jsx(Q3,{workspace:T,density:w.density,selecting:s,checked:w.selected.has(T.id),onCheck:()=>{w.toggleSelected(T.id)},pinBusy:a===T.id||a==="bulk",renaming:o===T.id,onPin:()=>{i(T)},onRename:()=>{l(T)},onRenameDone:c,onRenameCancel:d,onRemove:()=>{u(T)},onNewSession:()=>{h(T)},onOpenDetail:()=>{b(T)}});return e.jsxs("div",{"data-workspace-list":!0,className:"space-y-2",children:[e.jsx(Gs,{view:w,total:t.length,filters:f,sorts:g,searchLabel:m("st.workspaces.search"),searchPlaceholder:m("st.workspaces.searchPlaceholder")}),e.jsxs(UC,{active:s,count:C.length,onClear:()=>{w.setSelected(new Set),n(!1)},children:[e.jsx("label",{className:"flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-md px-1.5 text-[12px] text-ink-soft hover:bg-ink/[0.04] hover:text-ink pointer-coarse:h-9",title:m("st.list.selectAll"),children:e.jsx("input",{type:"checkbox",checked:k,"aria-label":m("st.list.selectAll"),onChange:()=>{w.setSelected(k?new Set:new Set(w.visible.map(v)))},className:"h-3.5 w-3.5 cursor-pointer accent-[var(--color-ink)]"})}),e.jsx("button",{type:"button","data-bulk-pin":!0,disabled:a!==null||C.length===0,className:Q,onClick:()=>{r(C,!S)},children:m(S?"st.workspaces.bulkUnpin":"st.workspaces.bulkPin")}),e.jsx("button",{type:"button","data-bulk-remove":!0,disabled:C.length===0,className:"rounded-md border border-danger/40 bg-paper px-3 py-1.5 text-[12px] text-danger transition-colors hover:bg-danger/5 disabled:cursor-not-allowed disabled:opacity-50",onClick:()=>{p(C)},children:m("st.workspaces.bulkRemove")})]}),w.visible.length===0?e.jsx(Ct,{kind:"no-match",title:m("st.workspaces.noMatchTitle"),body:w.query.trim()===""?void 0:m("st.workspaces.noMatches",{query:w.query.trim()}),onClear:w.clear}):_.length===1&&_[0].key==="all"?e.jsx(Hs,{items:w.visible,keyOf:v,density:w.density,renderRow:j,label:m("st.workspaces.title")}):_.map(T=>e.jsx(Xd,{groupKey:T.key,label:T.label,count:T.items.length,total:T.total,folded:w.isFolded(T.key),onToggle:()=>{w.toggleFold(T.key)},children:e.jsx(Hs,{items:T.items,keyOf:v,density:w.density,renderRow:j,label:T.label})},T.key))]})}const z3="flex h-8 w-8 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:text-ink-faint pointer-coarse:h-11 pointer-coarse:w-11";function Q3({workspace:t,density:s,selecting:n,checked:a,onCheck:i,pinBusy:r,renaming:o,onPin:l,onRename:c,onRenameDone:d,onRenameCancel:u,onRemove:p,onNewSession:h,onOpenDetail:b}){const{client:m}=be(),{t:f,time:g}=D(),[v,y]=x.useState(null),N=je({queryKey:["workspace-trust",t.id],queryFn:()=>m.getWorkspaceTrust(t.id),staleTime:3e4}).data?.trusted===!0,_=U3(t),C=s==="compact",S=f("st.workspaces.lastOpened",{time:g.relativeTime(t.last_opened_at)});return e.jsxs("div",{"data-workspace-row":t.id,"data-selected":a?"":void 0,style:{minHeight:_s[s]},className:`group/row transition-colors ${a?"bg-ink/[0.035]":"hover:bg-ink/[0.02]"}`,children:[e.jsxs("div",{className:"flex h-full items-center gap-1 pr-1.5 pl-3",children:[n?e.jsx(HC,{checked:a,onChange:i,label:f("st.list.selectRow",{name:_})}):null,e.jsxs("div",{className:"min-w-0 flex-1 py-1",children:[e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("button",{type:"button","data-workspace-open":t.id,"aria-label":f("st.workspaces.detail.open",{name:_}),title:t.root,onClick:b,className:"min-w-0 shrink truncate rounded text-left text-[13px] font-medium text-ink transition-colors hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-selected-ink",children:_}),N?e.jsx("span",{"data-workspace-trust-badge":t.id,className:"inline-flex shrink-0 items-center rounded bg-ink/[0.08] px-1.5 py-0.5 text-[10.5px] font-medium leading-none text-ink",title:f("st.workspaces.trustHint"),children:f("st.workspaces.trusted")}):null,C?e.jsx("p",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-ink-faint",title:t.root,children:t.root}):null]}),C?null:e.jsxs("p",{className:"flex min-w-0 items-baseline gap-2 text-[12px] leading-4 text-ink-faint",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-[11px]",title:t.root,children:t.root}),e.jsx("span",{"aria-hidden":!0,className:"hidden shrink-0 sm:inline",children:"·"}),e.jsx("span",{className:"hidden shrink-0 sm:inline",children:S})]})]}),C?e.jsx("span",{className:"hidden shrink-0 text-[12px] text-ink-faint tabular-nums sm:inline",children:g.relativeTime(t.last_opened_at)}):null,e.jsx("button",{type:"button",onClick:h,className:"h-8 shrink-0 rounded-md px-2.5 text-[12.5px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink pointer-coarse:h-11",children:f("st.workspaces.newSession")}),e.jsx("button",{type:"button","data-workspace-more":t.id,"aria-haspopup":"menu","aria-expanded":v!==null,"aria-label":f("st.workspaces.more",{name:t.name}),title:f("st.workspaces.more",{name:t.name}),onClick:k=>{const j=k.currentTarget.getBoundingClientRect();y(v===null?{x:j.right-208,y:j.bottom+4}:null)},className:`${z3} text-ink-faint`,children:e.jsx(de,{name:"more",size:14})}),v!==null?e.jsx(Q1,{x:v.x,y:v.y,ariaLabel:f("st.workspaces.more",{name:t.name}),overlayId:`workspace-menu:${t.id}`,dataAttribute:"data-workspace-menu",onClose:()=>{y(null)},entries:[{key:"pin",label:t.pinned?f("st.workspaces.unpin"):f("st.workspaces.pin"),disabled:r,run:l},{key:"rename",label:f("st.workspaces.rename"),run:c},{separator:!0},{key:"remove",label:`${f("st.workspaces.remove")}…`,danger:!0,run:p}]}):null]}),e.jsx(Ub,{open:o,lazy:!0,className:"mx-1 mb-1",children:e.jsx(G3,{workspace:t,onDone:d,onCancel:u})})]})}function G3({workspace:t,onDone:s,onCancel:n}){const{client:a}=be(),{t:i}=D(),[r,o]=x.useState(t.name),[l,c]=x.useState(!1),[d,u]=x.useState(null),p=()=>{const h=r.trim();h===""||h.length>100||l||(c(!0),u(null),a.renameWorkspaceCatalog(t.id,h).then(s).catch(b=>{c(!1),u(b instanceof Error?b.message:String(b))}))};return e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-workspace-rename":t.id,children:[e.jsx("input",{"data-autofocus":!0,"aria-label":i("st.workspaces.renameTitle"),className:"min-w-0 max-w-[42ch] flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 text-[13px] text-ink outline-none focus:border-selected-ink",value:r,maxLength:100,onChange:h=>{o(h.target.value)},onKeyDown:h=>{rt(h)||(h.key==="Enter"&&p(),h.key==="Escape"&&(h.preventDefault(),n()))}}),e.jsx("button",{type:"button",disabled:l||r.trim()===""||r.trim()===t.name,onClick:p,className:Ye,children:i(l?"common.saving":"common.save")}),e.jsx("button",{type:"button",onClick:n,className:Q,children:i("common.cancel")}),d!==null?e.jsx(pe,{feedback:{tone:"error",text:d}}):null]})}function W3({items:t}){const{tp:s}=D(),n=Oe(),[a,i]=x.useState("");if(x.useEffect(()=>{const o=()=>{const l=t.filter(c=>n.getQueryState(["workspace-trust",c.id])?.status==="error").map(c=>c.id).join("");i(c=>c===l?c:l)};return o(),n.getQueryCache().subscribe(o)},[t,n]),a==="")return null;const r=a.split("").length;return e.jsx("div",{"data-workspace-trust-failure":!0,children:e.jsx(Qd,{message:s("st.workspaces.trustReadFailed",r),onRetry:()=>{n.invalidateQueries({predicate:o=>o.queryKey[0]==="workspace-trust"&&o.state.status==="error"})}})})}const ws="inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[12px] text-ink-soft transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none disabled:cursor-not-allowed disabled:text-ink-faint disabled:hover:bg-transparent pointer-coarse:h-10",V3="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-ink-faint transition-colors hover:bg-ink/[0.05] hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-selected-ink disabled:cursor-not-allowed disabled:opacity-40 pointer-coarse:h-10 pointer-coarse:w-10";function qf(){const{client:t,localClient:s,connectionId:n,connectionSource:a}=be(),i=typeof n=="string"&&n!==""||zs(a),r=i?s:t,{t:o}=D(),l=G1(r,i?"local-control":void 0);return r===null?e.jsx(Me,{id:"st-card-ssh-hosts",title:o("st.ssh.hostsTitle"),children:e.jsx(he,{children:o("st.remote.controlUnavailable")})}):l.loading?e.jsx(Me,{id:"st-card-ssh-hosts",title:o("st.ssh.hostsTitle"),children:e.jsx(he,{children:o("st.ssh.loading")})}):l.enabled!==!0?e.jsx(Y3,{readOnly:i}):e.jsx(J3,{client:r})}function Y3({readOnly:t=!1}){const{t:s}=D(),{rows:n,effective:a,loading:i}=Du(!t),r=n.find(o=>o.id===ol);return e.jsx(Me,{id:"st-card-ssh-hosts",title:s("st.ssh.hostsTitle"),children:e.jsxs("div",{"data-ssh-flag-off":!0,className:"space-y-3",children:[e.jsx("p",{className:"max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:s("st.ssh.flagOff")}),t?null:i?e.jsx(he,{children:s("st.ssh.loading")}):e.jsx(Ze,{children:e.jsx(gy,{id:ol,override:r?.override,effective:a[ol]})})]})})}function J3({client:t}){const{t:s,locale:n}=D(),a=Oe(),i=W1(t),r=je({queryKey:ea.discovered(),queryFn:async()=>(await Rs(t).discover()).hosts,staleTime:3e4}),o=i.data?.hosts??[],l=i.data?.statuses??{},c=A=>l[A],[d,u]=x.useState(null),[p,h]=x.useState(null),b=On(t).data?.find(A=>A.id===at)?.path??"",[m,f]=x.useState(null),[g,v]=x.useState(null),[y,w]=x.useState(null),N=o.filter(A=>A.source==="kiki"),_=r.data??[],C=new Set(N.filter(A=>_.some(P=>P.id===A.id)).map(A=>A.id)),S=i.isSuccess&&o.length===0,k=async()=>{await a.invalidateQueries({queryKey:ea.all})},j=async(A,P,R)=>{v(A.id),w(null);try{await P(),w({id:A.id,feedback:{tone:"success",text:R}}),await k()}catch(L){w({id:A.id,feedback:{tone:"error",text:oe(n,L)}})}finally{v(null)}},T=async A=>{const P={name:A.name,hostname:A.hostname,user:A.user,port:A.port,identityFile:A.identityFile,roots:A.roots,description:A.description,agentAccess:A.agentAccess};v(A.id),w(null);try{await Rs(t).writeBack(A.id),await k(),xs({text:s("st.ssh.writtenBack",{alias:A.id}),undoFailedText:s("toast.undoFailed"),undo:async()=>{await Rs(t).upsert(A.id,P),await k()}})}catch(R){w({id:A.id,feedback:{tone:"error",text:oe(n,R)}})}finally{v(null)}};return e.jsxs(e.Fragment,{children:[e.jsx(Me,{id:"st-card-ssh-hosts",title:s("st.ssh.hostsTitle"),children:e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-x-3 gap-y-2",children:e.jsxs("button",{type:"button","data-ssh-add-host":!0,className:`${Q} inline-flex items-center gap-1.5`,onClick:()=>{u({kind:"create"})},children:[e.jsx(de,{name:"plus",size:12}),s("st.ssh.addHost")]})}),i.isLoading?e.jsx(he,{children:s("st.ssh.loading")}):null,i.isError?e.jsx(De,{error:i.error}):null,S?e.jsxs("div",{"data-ssh-empty":!0,className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-ink",children:s("st.ssh.emptyTitle")}),e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:s("st.ssh.emptyBody")}),e.jsxs("button",{type:"button",className:`${Q} inline-flex items-center gap-1.5`,onClick:()=>{u({kind:"create"})},children:[e.jsx(de,{name:"plus",size:12}),s("st.ssh.addHost")]})]}):null,o.length>0?e.jsx(Z3,{client:t,hosts:o,statusFor:c,busy:g,feedbackFor:A=>y?.id===A?y.feedback:null,overridden:C,onEdit:A=>{u({kind:"edit",host:A})},onRemoteSpace:A=>{h({profileId:A.id})},onDelete:A=>{f({kind:"delete",host:A})},onWriteBack:A=>{T(A)},onOverride:A=>{u({kind:"override",host:A})},onDisconnect:A=>void j(A,()=>Rs(t).disconnect(A.id),s("st.ssh.disconnected"))}):null,r.isError?e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:s("st.ssh.discoverFailed",{detail:oe(n,r.error)})}):null]})}),e.jsx(aq,{client:t}),p!==null?e.jsx(OS,{client:t,profiles:o,defaultHome:b,initialProfileId:p.profileId,onClose:()=>{h(null)},onAdded:A=>{h(null),vt({tone:"success",text:s("st.ssh.remoteAdded",{name:A.label})})}}):null,d!==null?e.jsx(DS,{mode:d,onClose:()=>{u(null)},onSubmit:async(A,P)=>{await Rs(t).upsert(A,P),await k(),u(null)}}):null,e.jsx(Xe,{open:m?.kind==="delete",title:s("st.ssh.deleteTitle",{name:m?.host.name??""}),body:s("st.ssh.deleteBody"),confirmLabel:s("st.ssh.deleteConfirm"),overlayId:"ssh-delete-host",busy:g!==null,onCancel:()=>{f(null)},onConfirm:()=>{const A=m.host;f(null),j(A,()=>Rs(t).remove(A.id),s("st.ssh.deleted",{name:A.name}))}})]})}function Z3({client:t,hosts:s,statusFor:n,busy:a,feedbackFor:i,overridden:r,onEdit:o,onRemoteSpace:l,onDelete:c,onWriteBack:d,onOverride:u,onDisconnect:p}){return e.jsx("div",{className:"overflow-hidden rounded-lg border border-hairline bg-panel",children:s.map(h=>e.jsx(X3,{client:t,host:h,status:n(h.id),busy:a===h.id,feedback:i(h.id),overridesConfig:r.has(h.id),onEdit:h.source==="kiki"?o:void 0,onRemoteSpace:h.source==="kiki"?l:void 0,onDelete:h.source==="kiki"?c:void 0,onWriteBack:h.source==="kiki"?d:void 0,onOverride:h.source==="ssh-config"?u:void 0,onDisconnect:p},h.id))})}function X3({client:t,host:s,status:n,busy:a,feedback:i,overridesConfig:r,onEdit:o,onRemoteSpace:l,onDelete:c,onWriteBack:d,onOverride:u,onDisconnect:p}){const{t:h}=D(),b=x.useId(),[m,f]=x.useState(!1),g=Y1(n),v=J1(s),y=s.source==="ssh-config",w=v??(y?h("st.ssh.row.fromConfig"):h("st.ssh.row.aliasOnly",{alias:s.id})),N=y&&v!==void 0,_=g==="ready"||g==="connecting",C=Z1(s);return e.jsxs("details",{"data-ssh-host-row":s.id,"data-ssh-source":s.source,className:"group/ssh border-b border-hairline last:border-b-0 [&[open]]:bg-paper",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center gap-3 px-3 py-2 outline-none transition-colors hover:bg-ink/[0.03] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-selected-ink/40 [&::-webkit-details-marker]:hidden",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:s.name}),s.name!==s.id?e.jsx("span",{className:"hidden truncate font-mono text-[12px] text-ink-faint sm:inline",children:s.id}):null]}),e.jsx("span",{className:`block truncate text-[12px] leading-4 text-ink-faint ${v!==void 0?"font-mono":""}`,children:w})]}),N?e.jsx("span",{className:"hidden shrink-0 text-[12px] text-ink-faint sm:inline","data-ssh-source-tag":!0,children:h("st.ssh.row.fromConfig")}):null,s.agentAccess==="hidden"?e.jsx("span",{className:"hidden shrink-0 text-[12px] text-ink-faint sm:inline",children:h("st.ssh.row.hidden")}):null,r?e.jsx("span",{className:"hidden shrink-0 text-[12px] text-ink-faint sm:inline",children:h("st.ssh.row.overrides")}):null,g!==void 0?e.jsx(FS,{state:g}):null,e.jsx(Rt,{open:!1,className:"text-ink-faint transition-transform group-open/ssh:rotate-90"})]}),e.jsxs("div",{className:"space-y-3 px-3 pb-3 pt-1",children:[e.jsxs("dl",{className:"grid grid-cols-[7.5rem_minmax(0,1fr)] gap-x-3 gap-y-1.5 text-[12px] leading-4",children:[e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.source")}),e.jsx("dd",{className:"min-w-0 text-ink-soft",children:h(y?"st.ssh.detail.sourceConfig":"st.ssh.detail.sourceKiki")}),e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.target")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft",children:v??h("st.ssh.detail.targetFromConfig",{alias:s.id})}),s.identityFile!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.identity")}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink-soft",children:s.identityFile})]}):null,e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.roots")}),e.jsx("dd",{className:"min-w-0",children:s.roots!==void 0&&s.roots.length>0?s.roots.map(S=>e.jsx("span",{className:"block break-all font-mono text-ink-soft",children:S},S)):e.jsx("span",{className:"font-sans text-ink-faint",children:h("st.ssh.detail.rootsDefault")})}),e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.agent")}),e.jsx("dd",{className:"min-w-0 text-ink-soft",children:s.agentAccess==="hidden"?h("st.ssh.detail.agentHidden"):h("st.ssh.detail.agentOffered")}),s.description!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.description")}),e.jsx("dd",{className:"min-w-0 text-ink-soft",children:s.description})]}):null,e.jsx("dt",{className:"text-ink-faint",children:h("st.ssh.detail.hostKey")}),e.jsxs("dd",{"data-ssh-host-key":!0,className:"min-w-0 text-ink-soft",children:[e.jsx("span",{className:"block",children:h("st.ssh.detail.hostKeyPolicy")}),e.jsxs("button",{type:"button","data-ssh-host-keys-toggle":!0,"aria-expanded":m,"aria-controls":b,className:`${ws} -ml-2 mt-0.5`,onClick:()=>{f(!m)},children:[e.jsx(de,{name:m?"eyeOff":"eye",size:12}),h(m?"st.ssh.hostKeys.hide":"st.ssh.hostKeys.view")]})]})]}),m?e.jsx(nq,{client:t,host:s,regionId:b}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-1 pt-1",children:[o!==void 0?e.jsxs("button",{type:"button","data-ssh-edit":!0,className:ws,disabled:a,onClick:()=>{o(s)},children:[e.jsx(de,{name:"edit",size:12}),h("st.ssh.edit")]}):null,l!==void 0?e.jsxs("button",{type:"button","data-ssh-as-remote-space":s.id,className:ws,disabled:a,onClick:()=>{l(s)},children:[e.jsx(de,{name:"external",size:12}),h("st.ssh.asRemoteSpace")]}):null,u!==void 0?e.jsxs("button",{type:"button","data-ssh-override":!0,className:ws,disabled:a,onClick:()=>{u(s)},children:[e.jsx(de,{name:"plus",size:12}),h("st.ssh.saveAsKiki")]}):null,d!==void 0?e.jsxs("button",{type:"button","data-ssh-write-back":!0,className:ws,disabled:a||!C||r,title:r?h("st.ssh.writeBackExists"):C?void 0:h("st.ssh.writeBackNeedsTarget"),onClick:()=>{d(s)},children:[e.jsx(de,{name:"file",size:12}),h("st.ssh.writeBack")]}):null,_?e.jsx("button",{type:"button","data-ssh-disconnect":!0,className:ws,disabled:a,onClick:()=>{p(s)},children:h("st.ssh.disconnect")}):null,c!==void 0?e.jsx("button",{type:"button","data-ssh-delete":!0,className:`${ws} ml-auto hover:bg-danger/[0.06] hover:text-danger`,disabled:a,onClick:()=>{c(s)},children:h("st.ssh.delete")}):null]}),d!==void 0&&!C?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:h("st.ssh.writeBackNeedsTarget")}):null,y?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:h("st.ssh.configReadOnly")}):null,e.jsx(pe,{feedback:i})]})]})}const eq={revoked:"st.ssh.hostKeys.status.revoked",unsupported:"st.ssh.hostKeys.status.unsupported",invalid:"st.ssh.hostKeys.status.invalid"},tq={read:"st.ssh.hostKeys.file.read",missing:"st.ssh.hostKeys.file.missing",unavailable:"st.ssh.hostKeys.file.unavailable"},Bf="ambiguous-known-hosts-paths";function sq(t){if(t.status==="revoked")return"st.ssh.hostKeys.reason.revoked";if(t.status==="invalid")return t.reason==="invalid-public-key"?"st.ssh.hostKeys.reason.invalidKey":void 0;if(t.status==="unsupported")return t.reason==="unsupported-marker:@cert-authority"?"st.ssh.hostKeys.reason.certAuthority":void 0}function nq({client:t,host:s,regionId:n}){const{t:a,locale:i}=D(),r=X1(t,s.id,!0),o=r.data,[l,c]=x.useState(null),[d,u]=x.useState(!1);x.useEffect(()=>{if(l===null)return;const v=setTimeout(()=>{c(null)},1600);return()=>{clearTimeout(v)}},[l]);const p=async v=>{u(!1);try{await rs(v),c(v)}catch{u(!0)}},h=o?.records??[],b=o?.files??[],m=b.some(v=>v.state==="unavailable"&&v.reason===Bf),f=o!==void 0&&(o.state==="unrecorded"||m)?b:b.filter(v=>v.state!=="read"),g=f.length>0?e.jsx("div",{"data-ssh-host-key-files":!0,className:"space-y-0.5",children:f.map(v=>e.jsxs("p",{"data-ssh-host-key-file":!0,"data-file-state":v.state,className:"flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-[12px] leading-4 text-ink-faint",children:[e.jsx("span",{className:"min-w-0 break-all font-mono",children:v.path}),e.jsxs("span",{children:["· ",a(tq[v.state])]}),v.reason!==void 0&&v.reason!==Bf?e.jsxs("span",{children:["· ",v.reason]}):null]},v.path))}):null;return e.jsx("section",{id:n,"data-ssh-host-keys":!0,"data-state":o?.state??(r.isError?"error":"loading"),className:"space-y-2 border-t border-hairline pt-3",children:r.isError?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{role:"alert",className:"max-w-[62ch] text-[12px] leading-4 text-danger",children:a("st.ssh.hostKeys.readFailed",{detail:oe(i,r.error)})}),e.jsx("button",{type:"button","data-ssh-host-keys-retry":!0,className:ws,disabled:r.isFetching,onClick:()=>{r.refetch()},children:a("common.retry")})]}):o===void 0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:a("st.ssh.hostKeys.reading")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5",children:[e.jsx("span",{"data-ssh-host-key-label":!0,className:"min-w-0 break-all font-mono text-[12px] text-ink",children:o.label}),e.jsx("button",{type:"button","data-ssh-host-keys-refresh":!0,className:`${ws} ml-auto`,disabled:r.isFetching,onClick:()=>{r.refetch()},children:a("st.ssh.hostKeys.refresh")})]}),o.state==="unrecorded"?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:a("st.ssh.hostKeys.unrecorded")}):m?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:a("st.ssh.hostKeys.ambiguous")}):h.length>0?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-faint",children:a("st.ssh.hostKeys.localNote")}):e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:a("st.ssh.hostKeys.unavailable")}),h.length>0?e.jsx("ul",{"data-ssh-host-key-records":!0,className:"space-y-2",children:h.map((v,y)=>{const w=sq(v);return e.jsxs("li",{"data-ssh-host-key-record":!0,"data-status":v.status,className:"border-t border-hairline pt-2 first:border-t-0 first:pt-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-mono text-[12px] text-ink",children:v.algorithm}),v.status!=="recorded"?e.jsx("span",{className:v.status==="unsupported"?"text-[12px] text-amber-ink":"text-[12px] text-danger",children:a(eq[v.status])}):null]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{"data-ssh-host-key-fingerprint":!0,className:"min-w-0 flex-1 select-all break-all font-mono text-[11px] leading-4 text-ink-soft",children:v.fingerprint??a("st.ssh.hostKeys.noFingerprint")}),v.fingerprint!==void 0?e.jsx("button",{type:"button","data-ssh-host-key-copy":!0,"aria-label":a("st.ssh.hostKeys.copy",{algorithm:v.algorithm}),title:a("st.ssh.hostKeys.copy",{algorithm:v.algorithm}),className:V3,onClick:()=>void p(v.fingerprint),children:e.jsx(de,{name:l===v.fingerprint?"check":"copy",size:12,className:l===v.fingerprint?"text-success":""})}):null]}),e.jsxs("p",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-[12px] leading-4 text-ink-faint",children:[e.jsxs("span",{className:"min-w-0 break-all font-mono",children:[v.file,":",v.line]}),e.jsxs("span",{children:["· ",v.hostPattern]})]}),w!==void 0?e.jsx("p",{className:"max-w-[62ch] text-[12px] leading-4 text-ink-soft",children:a(w)}):v.reason!==void 0?e.jsx("p",{className:"max-w-[62ch] break-all font-mono text-[12px] leading-4 text-ink-faint",children:v.reason}):null]},`${v.file}:${v.line}:${y}`)})}):null,g,d?e.jsx("p",{role:"alert",className:"max-w-[62ch] text-[12px] leading-4 text-danger",children:a("st.ssh.hostKeys.copyFailed")}):null,e.jsx("p",{role:"status",className:"sr-only",children:l===null?"":a("st.ssh.hostKeys.copied")})]})})}function aq({client:t}){const{t:s,locale:n}=D(),a=Oe(),i=je({queryKey:ea.approval(),queryFn:()=>Rs(t).connectionApproval(),staleTime:3e4}),r=V1(t),[o,l]=x.useState(void 0),c=o??r.data?.enabled,d=r.data?.source,[u,p]=x.useState(null),[h,b]=x.useState(null),[m,f]=x.useState(null),[g,v]=Je(),[y,w]=Je(),[N,_]=x.useState(void 0),C=N??(i.data===void 0?!1:!i.data.enabled),S=async j=>{l(j),p("sync"),b(null);try{const T=await Rs(t).setConfigSync(j);a.setQueryData(ea.configSync(),T),await a.invalidateQueries({queryKey:ea.hosts()}),v()}catch(T){b({tone:"error",text:oe(n,T)})}finally{l(void 0),p(null)}},k=async j=>{_(j),p("approval"),f(null);try{const T=await Rs(t).setConnectionApproval(!j);a.setQueryData(ea.approval(),T),w()}catch(T){f({tone:"error",text:oe(n,T)})}finally{_(void 0),p(null)}};return e.jsx(Me,{id:"st-card-ssh-connection",title:s("st.ssh.connectionTitle"),children:e.jsxs(Ze,{children:[e.jsxs("div",{"data-ssh-sync":!0,"data-ssh-sync-source":d??"unknown",children:[c!==void 0?e.jsxs(ge,{label:s("st.ssh.syncToggle"),help:s("st.ssh.syncHint"),children:[e.jsx(jt,{show:g}),e.jsx(Be,{layout:"bare",label:s("st.ssh.syncToggle"),checked:c,disabled:u==="sync",onChange:j=>void S(j)})]}):e.jsxs("div",{"data-settings-field":!0,className:"space-y-1",children:[e.jsx("p",{className:"flex min-h-7 items-center text-[13px] text-ink",children:s("st.ssh.syncToggle")}),r.isError?e.jsxs("div",{className:"space-y-1 py-0.5",children:[e.jsx("p",{role:"alert",className:"max-w-[62ch] text-[12px] leading-snug text-danger",children:s("st.ssh.syncReadFailed")}),e.jsx("button",{type:"button","data-ssh-sync-retry":!0,className:ws,disabled:r.isFetching,onClick:()=>{r.refetch()},children:s("common.retry")})]}):e.jsx("p",{className:"text-[12px] leading-4 text-ink-faint",children:s("st.ssh.syncReading")})]}),e.jsx(pe,{feedback:h})]}),e.jsxs("div",{"data-ssh-approval":!0,children:[i.isError?e.jsx(De,{error:i.error}):e.jsxs(ge,{label:s("st.ssh.approvalToggle"),help:s("st.ssh.approvalHint"),children:[e.jsx(jt,{show:y}),e.jsx(Be,{layout:"bare",label:s("st.ssh.approvalToggle"),checked:C,disabled:i.data===void 0||u==="approval",onChange:j=>void k(j)})]}),e.jsx(pe,{feedback:m})]})]})})}const iq=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," "]),rq={plugins:"#st-card-plugins",extensions:"#st-card-plugins",workspaces:"#st-card-workspaces",ai:"#st-card-recipes-library"},oq="(min-width: 1024px)";function lq(){const{config:t,sshLabel:s}=be();if(s!==null)return s;const n=t.url.trim();if(n==="")return null;try{const a=new URL(n);return["127.0.0.1","localhost","[::1]","::1"].includes(a.hostname)||a.host===window.location.host?null:a.host}catch{return n}}function cq({section:t,workspaceName:s,remoteAddress:n,dirty:a,hidePurpose:i}){const{t:r}=D(),o=y0[t];if(o===void 0)return null;const l=i===!0?void 0:o.purposeKey,c=n!==null&&!hb(t),d=c||s!==null||a;return l===void 0&&!d?null:e.jsxs("div",{className:"space-y-2 pb-6",children:[l!==void 0?e.jsx("p",{"data-settings-intro":!0,className:"max-w-[62ch] text-[13px] leading-5 text-ink-soft",children:r(l)}):null,d?e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-[12px] text-ink-faint","data-settings-page-status":!0,children:[c?e.jsx("span",{"data-settings-remote-line":!0,title:r("st.storage.remoteTitle",{address:n}),children:r("st.storage.pageServerRemote")}):null,s!==null?e.jsxs("span",{"data-settings-storage-workspace":!0,children:[c?"· ":"",r("st.storage.workspace",{name:s})]}):null,a?e.jsxs("span",{role:"status","data-settings-unsaved":!0,className:"inline-flex items-center gap-1.5 font-medium text-accent-ink",children:[e.jsx("span",{"aria-hidden":!0,className:"inline-block h-1.5 w-1.5 rounded-full bg-accent"}),r("st.storage.unsaved")]}):null]}):null]})}function dq(){const{t}=D(),{localClient:s,connectionId:n,spaceKey:a}=be(),i=Aa(),r=(typeof n=="string"&&n!==""?n:null)??(i===null?null:ka(i.homeId))??(typeof a=="string"?ka(a):null),o=xo(r===null?null:s??null),l=On(i!==null&&r===null&&i.name===void 0?s??null:null),c=US(i!==null&&r===null?s??null:null);if(i===null&&r===null)return null;const d=r===null?void 0:o.data?.find(m=>m.id===r),u=r!==null?Ba(d?.label):Ba(i?.name)??Ba(l.data?.find(m=>m.id===i?.homeId)?.name),p=r!==null?Ba(d?.target?.hostId):Ba(c.data?.targetLabel),h=p!==void 0&&p!==u?p:void 0,b=u===void 0?t("st.spaces.bandUnnamed"):h!==void 0?t("st.spaces.bandWithComputer",{name:u,computer:h}):t("st.spaces.band",{name:u});return e.jsxs("p",{"data-settings-space-band":!0,className:"mb-5 flex items-center gap-2 border-l-2 py-0.5 pl-3 text-[12px] text-ink-soft",style:{borderColor:i?.color??"var(--color-hairline-strong)"},children:[e.jsx(dr,{color:i?.color,size:7}),e.jsx("span",{className:"min-w-0 truncate",children:b})]})}function Dq({onToggleSidebar:t}){const s=uj(),n=(s["*"]??s.section)?.replace(/\/+$/,""),a=n===""?void 0:n,{t:i}=D(),r=Tt(),o=Et(),l=Ln()?.dirty===!0,c=lq(),{client:d,meta:u,connectionId:p,spaceKey:h}=be(),b=typeof p=="string"&&p!==""||ka(Aa()?.homeId??"")!==null||typeof h=="string"&&ka(h)!==null,m=Db({enabled:b}),f=Wd(Pa(d,u)),g=b?Kk:Ai,v=b?m.spaceName!==i("sidebar.space.unnamed")?i("st.spaces.remoteSettingsNote",{space:m.spaceName}):i("st.spaces.remoteSettingsNoteUnnamed"):void 0,[y,w]=x.useState(null),[N,_]=x.useState(null),{hash:C,search:S,state:k,key:j}=Bt(),T=d0(a,C,S),A=a==="sessions/import",P=A?"sessions":T.status==="ok"?T.section:null,R=(a===void 0||a==="")&&T.status==="ok"&&T.cardId===void 0,L=P===null?"server":u0(P)&&f?"space":hb(P)?"app":"server",[I,$]=x.useState(null),[E,M]=x.useState(null);x.useEffect(()=>{$(null)},[P]);const z=x.useRef(null);x.useEffect(()=>{const Ne=Bp();if(!Ne||!z.current)return;const J=Kp(Ne.visitId),_e=z.current;_e.scrollTop=J?.scrollTop??0;const we=()=>{b0(Ne.visitId,{scrollTop:_e.scrollTop}),g0(Ne.visitId,"[data-settings-scroll]",_e.scrollTop)};return _e.addEventListener("scroll",we,{passive:!0}),()=>{_e.removeEventListener("scroll",we)}},[P,j]),x.useEffect(()=>{if(A||T.status!=="ok")return;const Ne=new URLSearchParams(S),J=T.section!==a&&!(a===void 0&&T.section==="general"),_e=T.tab!==void 0&&Ne.get("tab")!==T.tab,we=T.cardId!==void 0?`#${T.cardId}`:C;if(!J&&!_e&&!(we!==C))return;T.tab!==void 0&&Ne.set("tab",T.tab);const Le=Ne.toString();o(`/settings/${T.section}${Le===""?"":`?${Le}`}${we}`,{replace:!0})},[T,a,S,C,o]);const H=k?.focusSearch===!0?j:null,[U,X]=x.useState(null);x.useEffect(()=>{X(null)},[P,j]),x.useEffect(()=>{if(H===null||R||P===null)return;typeof window.matchMedia=="function"&&window.matchMedia(oq).matches||X(H)},[H]),x.useEffect(()=>{const Ne=C.replace(/^#/,"");if(!Ne.startsWith("st-card-"))return;const J=Bp();J!==null&&Kp(J.visitId)?.scrollTop!==void 0||P!==null&&w({cardId:Ne,section:P,locationKey:j,nonce:Date.now()})},[C,P,j]);const q=x.useCallback(Ne=>{if(y===null||y.cardId!==Ne||y.section!==P||y.locationKey!==j)return;w(null),_({cardId:Ne,nonce:y.nonce});const J=document.querySelector(`#${CSS.escape(Ne)}`);J!==null&&typeof J.scrollIntoView=="function"&&J.scrollIntoView({behavior:zf()?"auto":"smooth",block:"start"})},[y,P,j]);x.useEffect(()=>{if(N===null)return;const Ne=setTimeout(()=>{_(null)},2e3);return()=>{clearTimeout(Ne)}},[N]),x.useEffect(()=>{if(y===null)return;const Ne=()=>{w(null)},J=_e=>{iq.has(_e.key)&&Ne()};return window.addEventListener("wheel",Ne,{passive:!0,once:!0}),window.addEventListener("touchstart",Ne,{passive:!0,once:!0}),window.addEventListener("keydown",J),()=>{window.removeEventListener("wheel",Ne),window.removeEventListener("touchstart",Ne),window.removeEventListener("keydown",J)}},[y]),x.useEffect(()=>{w(Ne=>Ne!==null&&(Ne.section!==P||Ne.locationKey!==j)?null:Ne)},[P,j]),x.useEffect(()=>{if(!l)return;const Ne=J=>{J.preventDefault()};return window.addEventListener("beforeunload",Ne),()=>{window.removeEventListener("beforeunload",Ne)}},[l]);const F=x.useCallback(Ne=>{r(`/settings/${Ne}`)},[r]),V=Ne=>{w(null);const J=Ne.tab===void 0?Ne.section:`${Ne.section}?tab=${Ne.tab}`;F(`${J}#${Ne.cardId}`)},se=Ne=>{if(Ne.section===P&&(Ne.tab===void 0||Ne.tab===ie)){w({cardId:Ne.cardId,section:Ne.section,locationKey:j,nonce:Date.now()});return}V(Ne)},Y=P===null?void 0:qk.find(Ne=>Ne.id===P)?.labelKey,O=P!==null&&rq[P]===C,B=(P==="plugins"||P==="extensions")&&!O?p0(S):null,le=P==="workspaces"&&!O?m0(S):null,re=new URLSearchParams(S).get("tab"),ae=re??(T.status==="ok"?T.tab:void 0),ne=P==="ai"?eb(ae)??yc:null,Ee=v0(ae)??x0,ie=P==="developer"?Ee:P==="ai"?ne:P==="extensions"?re??rb:P==="browser-control"?re??mb:P==="connection-services"?re??ob:P==="search"?re??"overview":null,me=(Ne,J,_e=[])=>{const we=new URLSearchParams(S);for(const G of _e)we.delete(G);we.set("tab",J),r(`/settings/${Ne}?${we.toString()}`)},fe=b&&P!==null&&!CF(P),Ie=P===null?null:fe?e.jsx("p",{"data-settings-remote-only-notice":!0,className:"text-[13px] leading-5 text-ink-soft",children:v}):A?e.jsx(pF,{}):P==="general"?e.jsx(g5,{}):P==="appearance"?e.jsx(y2,{}):P==="shortcuts"?e.jsx(jF,{}):P==="connection"?e.jsx(Eh,{}):P==="ai"?e.jsx(k$,{resolvedTab:ne??void 0}):P==="providers"?e.jsx(ay,{}):P==="models"?e.jsx(sy,{}):P==="connection-services"?e.jsx(ec,{}):P==="identity"?e.jsx(zh,{}):P==="agents"?e.jsx(ux,{}):P==="subagents"?e.jsx(ux,{}):P==="sessions"?e.jsx(J$,{}):P==="notifications"?e.jsx(LO,{}):P==="memory"?e.jsx(I5,{}):P==="permissions"?e.jsx(UO,{}):P==="tasks"?e.jsx(c3,{}):P==="skills"?e.jsx(wy,{}):P==="mcp"?e.jsx(jy,{}):P==="external-clients"?e.jsx(ec,{}):P==="plugins"?e.jsx(id,{pluginId:B}):P==="browser-control"||P==="computer-control"?e.jsx(Nf,{}):P==="search"?e.jsx(oc,{}):P==="hooks"?e.jsx(jR,{}):P==="subscriptions"?e.jsx(l3,{}):P==="spaces"?e.jsx(GF,{}):P==="workspaces"?e.jsx(F3,{workspaceId:le},le??"catalog"):P==="ssh"?e.jsx(qf,{}):P==="developer"?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Gd,{tabs:h0,current:Ee,ariaLabel:i("st.section.developer"),dataAttr:"data-developer-tab",labelOf:Ne=>i(f0(Ne)),onSelect:Ne=>{me("developer",Ne)}}),Ee==="engine"?e.jsx(Z$,{}):Ee==="identity"?e.jsx(zh,{}):e.jsx(Th,{})]}):P==="labs"?e.jsx(vy,{}):P==="extensions"?e.jsx(RR,{pluginId:B}):P==="environment-tools"?ie==="search"?e.jsx(oc,{}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(oc,{}),e.jsx(Nf,{})]}):P==="remote"?e.jsxs("div",{className:"space-y-6",children:[e.jsx(Eh,{}),e.jsx(qf,{}),e.jsx(ec,{})]}):P==="system"?e.jsxs("div",{className:"space-y-6",children:[e.jsx(Th,{}),e.jsx(wm,{}),e.jsx(Nm,{})]}):e.jsxs(e.Fragment,{children:[e.jsx(wm,{}),e.jsx(Nm,{})]}),te=P===null?void 0:pb(P),ee=!b&&!fe&&!A&&P!==null&&P!=="labs"&&B===null&&(te===void 0||ie===te),K=E??(Y===void 0?void 0:i(Y)),Z=qS().plugins,ue=B===null?void 0:Z.find(Ne=>Ne.id===B)?.displayName??B,{sidebarOpen:Te}=BS();return e.jsx(Mn.Provider,{value:q,children:e.jsx(Ia.Provider,{value:N?.cardId??null,children:e.jsx(yy.Provider,{value:$,children:e.jsxs(ky.Provider,{value:M,children:[e.jsxs("header",{className:"relative flex h-12 shrink-0 items-center gap-2 px-4 lg:px-6",children:[e.jsx("button",{type:"button",onClick:t,"aria-label":i("sv.openMenuAria"),"aria-expanded":Te,"aria-controls":"app-sidebar",className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink md:hidden",children:e.jsx(de,{name:"menu",size:16})}),e.jsx(KS,{}),U!==null?e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 lg:hidden","data-settings-header-search":!0,children:[e.jsx(Ju,{className:"min-w-0 flex-1",focusToken:U,onSearchHit:Ne=>{X(null),se(Ne)},onDismiss:()=>{X(null)},navTree:g,floatingResults:!0}),e.jsx("button",{type:"button","data-settings-search-close":!0,"aria-label":i("common.close"),onClick:()=>{X(null)},className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink",children:e.jsx(de,{name:"close",size:16})})]}):null,e.jsxs("h1",{className:`${U!==null?"max-lg:hidden ":""}flex min-w-0 flex-1 items-baseline gap-1.5 truncate font-display text-[15px] font-semibold tracking-tight text-ink`,children:[e.jsx("span",{className:K===void 0?"":R?"lg:font-normal lg:text-ink-faint":"font-normal text-ink-faint",children:i("st.title")}),K!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:`font-normal text-ink-faint${R?" hidden lg:inline":""}`,children:"/"}),e.jsx("span",{"data-settings-page-title":!0,className:`truncate${R?" hidden lg:inline":""}`,children:K})]}):null,ue!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"font-normal text-ink-faint",children:"/"}),e.jsx("span",{"data-settings-plugin-title":!0,className:"truncate font-normal text-ink-faint",children:ue})]}):null]}),P!==null&&!R&&U===null?e.jsx("button",{type:"button","data-settings-search-open":!0,"aria-label":i("st.search.aria"),onClick:()=>{X(String(Date.now()))},className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-ink-soft transition-colors hover:bg-ink/[0.04] hover:text-ink lg:hidden",children:e.jsx(de,{name:"search",size:16})}):null]}),e.jsxs("main",{className:"flex min-h-0 flex-1 border-t border-hairline",children:[e.jsx("div",{className:"hidden shrink-0 border-r border-hairline lg:block",children:e.jsx($f,{active:P,activeTab:ie,searchFocusToken:H,onNavigate:F,onSearchHit:se,navTree:g,remoteNotice:v})}),R?e.jsx("div",{"data-settings-index":!0,className:"flex min-w-0 flex-1 lg:hidden",children:e.jsx($f,{active:null,activeTab:null,searchFocusToken:H,onNavigate:F,onSearchHit:V,showAttention:!0,navTree:g,remoteNotice:v})}):null,e.jsx("div",{className:`${R?"hidden lg:flex":"flex"} min-w-0 flex-1 flex-col`,children:P===null?e.jsx("div",{"data-settings-scroll":!0,className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(d3,{section:a??"",onSearchHit:se})}):e.jsx("div",{ref:z,"data-settings-scroll":!0,className:"relative min-h-0 flex-1 overflow-y-auto px-4 pb-[var(--settings-scroll-pb)] pt-[var(--settings-scroll-pt)] [--settings-scroll-pb:4rem] [--settings-scroll-pt:1.5rem] has-[[data-detail-split=open]]:[--settings-scroll-pb:0px] lg:px-10 lg:[--settings-scroll-pt:2rem]",children:e.jsxs("div",{className:"mx-auto max-w-[720px] transition-[max-width] duration-[var(--kiki-motion-base)] ease-[var(--kiki-ease-out)] has-[[data-detail-split=open]]:max-w-[1180px]",children:[e.jsx(dq,{}),fe?null:e.jsx(cq,{section:P,workspaceName:I,remoteAddress:c,dirty:l,hidePurpose:B!==null||A}),e.jsx(eC.Provider,{value:L,children:e.jsx(eF,{resetKey:`${P}\0${S}\0${j}`,children:e.jsxs("div",{className:"space-y-6",children:[Ie,!fe&&(P==="plugins"||P==="extensions")&&B===null?e.jsx(MR,{workspaceId:le??void 0}):null,ee?e.jsx(IR,{section:P}):null]})})})]})})})]})]})})})})}export{Dq as SettingsPage,XS as mcpConfigFromDraft,Bq as parseNamedAgentTools};
|