@aiworker/web 1.22.0 → 1.22.2
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/README.md +4 -4
- package/bin/cli.js +7 -4
- package/bin/cli.test.js +165 -73
- package/bin/lib/cli-api-target.js +2 -2
- package/bin/lib/cli-args.js +119 -119
- package/bin/lib/cli-lifecycle.js +9 -9
- package/bin/lib/cli-network.js +3 -3
- package/bin/lib/cli-paths.js +3 -3
- package/bin/lib/cli-ports.js +2 -2
- package/bin/lib/cli-process.js +4 -4
- package/bin/lib/cli-startup.js +64 -15
- package/bin/lib/cli-tunnel-profiles.js +1 -1
- package/bin/lib/cli-tunnel-utils.js +2 -2
- package/bin/lib/commands-connect-url.js +19 -19
- package/bin/lib/commands-lifecycle.js +27 -27
- package/bin/lib/commands-logs.js +5 -5
- package/bin/lib/commands-models.js +1 -1
- package/bin/lib/commands-projects.js +1 -1
- package/bin/lib/commands-schedule.js +1 -1
- package/bin/lib/commands-serve.js +29 -29
- package/bin/lib/commands-session.js +1 -1
- package/bin/lib/commands-startup.js +45 -10
- package/bin/lib/commands-status.js +1 -1
- package/bin/lib/commands-tunnel.js +40 -40
- package/bin/lib/commands-update.js +1 -1
- package/bin/lib/commands-update.test.js +6 -6
- package/dist/assets/{CodeMirrorCommentWidgets-B3u7UIcE.js → CodeMirrorCommentWidgets-CSICpWQD.js} +1 -1
- package/dist/assets/{DiffView-DluiRSla.js → DiffView-hDBKesA_.js} +3 -3
- package/dist/assets/DirtyBranchSwitchDialog-C22HdWj4.js +1 -0
- package/dist/assets/FilesView-CdWzeOp9.js +17 -0
- package/dist/assets/GitView-VQQkYuUw.js +6 -0
- package/dist/assets/{JsonTreeView-B0BdZEHG.js → JsonTreeView-6lrhwD3q.js} +1 -1
- package/dist/assets/LinearIssuesView-Ba6Q9569.js +1 -0
- package/dist/assets/{MarkdownImageGallery-ClOvuZxC.js → MarkdownImageGallery-Czv_mhvS.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +12 -0
- package/dist/assets/{OnboardingScreen-D2DG7K6b.js → OnboardingScreen-ChxQoAkx.js} +1 -1
- package/dist/assets/{PatchDiff-DvfqDql7.js → PatchDiff-BzcZPlOq.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B7m3f0d7.js → PierreDiffViewer-BchBtZlp.js} +2 -2
- package/dist/assets/PlanView-DyDt_nZ_.js +5 -0
- package/dist/assets/SettingsView-BKf5xBsP.js +28 -0
- package/dist/assets/{SettingsWindow-i45U1Cy1.js → SettingsWindow-DDQYaKWQ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BTwyh5OF.js → ToolOutputDialog-iYF8Y2bz.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-CdjbOVMM.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-DD8lDVej.js → VirtualizedFileDiff-fFFm2QgH.js} +1 -1
- package/dist/assets/{WalkthroughView-egQgxel3.js → WalkthroughView-DOeCsMju.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-BMIRgMHv.js → computeVirtualFileMetrics-CzgLum_K.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-C3fjDbdg.js → contextPanelEmbeddedChat-C0ZLAepL.js} +1 -1
- package/dist/assets/{de-C1P6X5Rs.js → de-B5JaA3SA.js} +6 -5
- package/dist/assets/{es-CDgaF1_t.js → es-EPIH88ii.js} +6 -5
- package/dist/assets/{fr-Bgxqvvz_.js → fr-CAMfxUdZ.js} +6 -5
- package/dist/assets/{index-CODwDsU_.js → index-Bl3LSbjn.js} +1 -1
- package/dist/assets/index-DF5kMP-i.js +39 -0
- package/dist/assets/index-Dl3xbAB_.css +1 -0
- package/dist/assets/{isDiffPlainText-BqayB8d3.js → isDiffPlainText-Dx-dB_8l.js} +1 -1
- package/dist/assets/{isFilePlainText-QfoiKJNY.js → isFilePlainText-CWFPwmnU.js} +1 -1
- package/dist/assets/{ja-BDRrEcNP.js → ja-CifOE1VN.js} +7 -6
- package/dist/assets/{ko-Ba8sQV79.js → ko-BBDyAyYQ.js} +7 -6
- package/dist/assets/{main-C5DVOxc6.js → main-DnBAoktx.js} +2 -2
- package/dist/assets/main-MhSaOZoB.js +930 -0
- package/dist/assets/{markdownCore-CZwzz5gw.js → markdownCore-BrBwOOMn.js} +2 -2
- package/dist/assets/{miniChat-DUJ4irZc.js → miniChat-BKyvLseN.js} +2 -2
- package/dist/assets/{mobile-CcaxB0n4.js → mobile-DKjeFgMN.js} +2 -2
- package/dist/assets/{patchFileDiff-yNfWXN4E.js → patchFileDiff-o8ms1me8.js} +1 -1
- package/dist/assets/pl-DgEHYfFM.js +16 -0
- package/dist/assets/{pt-BR-DIs6ElwV.js → pt-BR-DuWHojUw.js} +6 -5
- package/dist/assets/{renderElectronMiniChatApp-BcKLHXKe.js → renderElectronMiniChatApp-CDgBwwCS.js} +2 -2
- package/dist/assets/renderMobileApp-DJIKIK1r.js +25 -0
- package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +17 -0
- package/dist/assets/{scheduledTasksApi-DLW0mkQK.js → scheduledTasksApi-D8yamh1b.js} +1 -1
- package/dist/assets/{shikiHighlight-DYOWuY65.js → shikiHighlight-TEQCmzW8.js} +1 -1
- package/dist/assets/tr-D5m2yIWL.js +7 -0
- package/dist/assets/{uk-ZrCNjM7Y.js → uk-D_q60oog.js} +6 -5
- package/dist/assets/{useAppFontEffects-CjrntdL0.js → useAppFontEffects-D7sNpuL2.js} +161 -190
- package/dist/assets/useInlineCommentController-Brz_cLcQ.js +2 -0
- package/dist/assets/{useRootScrollLock-BHYPkrLv.js → useRootScrollLock-lXEnWlaU.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DFZik9R2.js → vendor-codemirror-language-data-Dp3KMRQG.js} +2 -2
- package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
- package/dist/assets/{web-components-Bhg83tjf.js → web-components-_mNEMjFY.js} +1 -1
- package/dist/assets/{zh-CN-iv_AV4EC.js → zh-CN-D8QvsVeg.js} +6 -5
- package/dist/assets/{zh-TW-CzEUk38j.js → zh-TW-B9t7rQQO.js} +6 -5
- package/dist/index.html +22 -22
- package/dist/mini-chat.html +7 -7
- package/dist/mobile.html +5 -5
- package/package.json +3 -3
- package/server/index.js +118 -85
- package/server/lib/agent-memory/actions.js +2 -2
- package/server/lib/agent-memory/feature-flag.js +1 -1
- package/server/lib/agent-memory/feature-flag.test.js +8 -8
- package/server/lib/agent-memory/routes.js +2 -2
- package/server/lib/agent-tool/runtime.js +37 -54
- package/server/lib/agent-tool/runtime.test.js +59 -59
- package/server/lib/browser-control/broker.js +3 -3
- package/server/lib/browser-control/broker.test.js +1 -1
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/client-auth/remote-clients.test.js +5 -5
- package/server/lib/context-obligatory/runtime.js +7 -7
- package/server/lib/context-obligatory/runtime.test.js +5 -5
- package/server/lib/dev-servers/parse.js +2 -2
- package/server/lib/dev-servers/parse.test.js +2 -2
- package/server/lib/dev-servers/routes.js +1 -1
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/client.js +1 -1
- package/server/lib/dev-tunnel/runtime.js +5 -5
- package/server/lib/dev-tunnel/tunnel.test.js +21 -1
- package/server/lib/dictation/local/model-catalog.js +1 -1
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/event-stream/directory-ws-bridge.js +1 -1
- package/server/lib/event-stream/global-ws-bridge.js +1 -1
- package/server/lib/event-stream/protocol.test.js +4 -4
- package/server/lib/event-stream/runtime.test.js +6 -6
- package/server/lib/fs/DOCUMENTATION.md +2 -0
- package/server/lib/fs/routes.js +37 -26
- package/server/lib/fs/routes.test.js +98 -21
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/identity-storage.js +1 -1
- package/server/lib/git/issue-2746-longpaths.test.js +4 -4
- package/server/lib/git/routes.js +17 -1
- package/server/lib/git/service.js +116 -26
- package/server/lib/git/service.test.js +174 -3
- package/server/lib/github/auth.js +8 -8
- package/server/lib/github/pr-status.js +1 -1
- package/server/lib/github/routes.js +2 -2
- package/server/lib/inherited-env.js +1 -1
- package/server/lib/inherited-env.test.js +2 -2
- package/server/lib/linear/auth.js +8 -8
- package/server/lib/linear/auth.test.js +24 -24
- package/server/lib/linear/issues.test.js +6 -6
- package/server/lib/linear/mapping.test.js +4 -4
- package/server/lib/linear/oauth.js +2 -2
- package/server/lib/linear/oauth.test.js +14 -14
- package/server/lib/linear/routes.js +5 -5
- package/server/lib/linear/routes.test.js +16 -16
- package/server/lib/linear/status-runtime.test.js +9 -9
- package/server/lib/linear/status.js +1 -1
- package/server/lib/linear/status.test.js +15 -15
- package/server/lib/linear/teams.test.js +4 -4
- package/server/lib/magic-prompts/routes.js +2 -2
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +158 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/notifications/apns-runtime.js +17 -17
- package/server/lib/notifications/apns-runtime.test.js +11 -11
- package/server/lib/notifications/emitter-runtime.js +1 -1
- package/server/lib/notifications/emitter-runtime.test.js +1 -1
- package/server/lib/notifications/push-runtime.js +7 -7
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +1 -1
- package/server/lib/openchamber-control/action-resolution.test.js +10 -10
- package/server/lib/openchamber-control/actions.js +24 -24
- package/server/lib/openchamber-control/error.js +4 -4
- package/server/lib/openchamber-control/routes.js +2 -2
- package/server/lib/openchamber-control/routes.test.js +5 -5
- package/server/lib/openchamber-control/screenshots.js +1 -1
- package/server/lib/openchamber-control/screenshots.test.js +1 -1
- package/server/lib/openchamber-control/service.js +50 -50
- package/server/lib/openchamber-control/service.test.js +5 -5
- package/server/lib/openchamber-sessions/routes.js +124 -22
- package/server/lib/openchamber-sessions/routes.test.js +99 -11
- package/server/lib/opencode/DOCUMENTATION.md +13 -5
- package/server/lib/opencode/auth.js +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +6 -6
- package/server/lib/opencode/cli-options.js +8 -8
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/core-routes.js +8 -7
- package/server/lib/opencode/core-routes.test.js +11 -11
- package/server/lib/opencode/env-config.js +5 -5
- package/server/lib/opencode/env-config.test.js +7 -7
- package/server/lib/opencode/env-runtime.js +10 -10
- package/server/lib/opencode/env-runtime.test.js +18 -18
- package/server/lib/opencode/feature-routes-runtime.js +17 -12
- package/server/lib/opencode/hmr-state-runtime.js +2 -2
- package/server/lib/opencode/hmr-state-runtime.test.js +1 -1
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/lifecycle.js +8 -8
- package/server/lib/opencode/lifecycle.test.js +4 -4
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/managed-process-registry.js +3 -3
- package/server/lib/opencode/mcp-oauth-callback.test.js +2 -2
- package/server/lib/opencode/openchamber-routes.js +15 -15
- package/server/lib/opencode/openchamber-routes.test.js +11 -11
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/plugins.test.js +1 -1
- package/server/lib/opencode/project-icon-routes.js +2 -2
- package/server/lib/opencode/project-icon-routes.test.js +1 -1
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/proxy.js +2 -2
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/restart-session-recovery.test.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +4 -4
- package/server/lib/opencode/routes.js +14 -14
- package/server/lib/opencode/server-startup-runtime.js +6 -6
- package/server/lib/opencode/session-runtime.js +3 -3
- package/server/lib/opencode/session-runtime.test.js +6 -6
- package/server/lib/opencode/settings-helpers.js +31 -3
- package/server/lib/opencode/settings-helpers.test.js +189 -12
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shared.js +5 -2
- package/server/lib/opencode/shared.test.js +7 -7
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/opencode/startup-performance.js +1 -1
- package/server/lib/opencode/startup-performance.test.js +6 -6
- package/server/lib/opencode/static-routes-runtime.js +8 -8
- package/server/lib/opencode/static-routes-runtime.test.js +7 -7
- package/server/lib/opencode/upgrade-capability.js +2 -2
- package/server/lib/opencode/upgrade-capability.test.js +3 -3
- package/server/lib/package-manager.js +17 -42
- package/server/lib/package-manager.test.js +19 -19
- package/server/lib/permission-auto-accept/runtime.js +1 -1
- package/server/lib/project-context/routes.js +1 -1
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/quota/DOCUMENTATION.md +9 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +4 -4
- package/server/lib/quota/credentials/store.test.js +8 -8
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/hyper.js +118 -0
- package/server/lib/quota/providers/hyper.test.js +126 -0
- package/server/lib/quota/providers/index.js +15 -0
- package/server/lib/quota/providers/ollama-cloud.js +1 -1
- package/server/lib/quota/providers/opencode-go.js +2 -1
- package/server/lib/quota/providers/opencode-go.test.js +9 -5
- package/server/lib/quota/providers/xai.js +1 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/host-client.js +1 -1
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/host-lock.js +1 -1
- package/server/lib/relay/service.js +5 -5
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +2 -2
- package/server/lib/scheduled-tasks/routes.js +5 -5
- package/server/lib/scheduled-tasks/service.js +25 -25
- package/server/lib/scheduled-tasks/service.test.js +1 -1
- package/server/lib/security/bind-host.js +4 -4
- package/server/lib/security/bind-host.test.js +1 -1
- package/server/lib/security/request-security.js +11 -5
- package/server/lib/security/request-security.test.js +14 -14
- package/server/lib/session-assist/runtime.js +10 -9
- package/server/lib/session-folders/routes.js +2 -2
- package/server/lib/session-folders/routes.test.js +8 -8
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/create.js +4 -2
- package/server/lib/session-goal/create.test.js +1 -1
- package/server/lib/session-goal/objectives.js +4 -4
- package/server/lib/session-goal/routes.js +1 -1
- package/server/lib/session-goal/runtime.js +88 -22
- package/server/lib/session-goal/runtime.test.js +428 -2
- package/server/lib/session-knowledge/runtime.js +11 -11
- package/server/lib/session-knowledge/runtime.test.js +5 -5
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/cache.test.js +2 -2
- package/server/lib/skills-catalog/disk-cache.js +5 -5
- package/server/lib/skills-catalog/github-meta.test.js +2 -2
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +9 -3
- package/server/lib/small-model/call.test.js +29 -6
- package/server/lib/small-model/index.js +8 -7
- package/server/lib/small-model/index.test.js +1 -1
- package/server/lib/small-model/resolve.js +1 -1
- package/server/lib/small-model/resolve.test.js +1 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +3 -22
- package/server/lib/system-prompt/runtime.test.js +3 -3
- package/server/lib/terminal/DOCUMENTATION.md +11 -7
- package/server/lib/terminal/runtime.js +180 -26
- package/server/lib/terminal/runtime.test.js +554 -27
- package/server/lib/terminal/shells.js +20 -3
- package/server/lib/terminal/shells.test.js +33 -2
- package/server/lib/tts/base-url.js +3 -3
- package/server/lib/tts/routes.test.js +20 -20
- package/server/lib/ui-auth/ui-auth.js +12 -9
- package/server/lib/ui-auth/ui-auth.test.js +19 -3
- package/server/lib/ui-auth/ui-passkeys.js +7 -7
- package/server/lib/walkthrough/index.js +1 -0
- package/server/lib/walkthrough/jobs.test.js +1 -1
- package/server/lib/walkthrough/language.test.js +1 -1
- package/server/lib/walkthrough/model-settings.js +3 -3
- package/server/lib/walkthrough/model-settings.test.js +1 -1
- package/server/lib/walkthrough/pull-request.test.js +5 -5
- package/server/lib/walkthrough/reproduce-2607.test.js +2 -2
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/server/lib/walkthrough/store.js +3 -3
- package/server/lib/walkthrough/store.test.js +1 -1
- package/server/opencode-proxy.test.js +2 -2
- package/server/proxy-headers.js +1 -1
- package/server/sse-routes.test.js +4 -4
- package/README.md.bak +0 -250
- package/bin/lib/DOCUMENTATION.md.bak +0 -163
- package/dist/assets/CommitSection-SGBCAW0w.js +0 -1
- package/dist/assets/FilesView-Bdq8ppva.js +0 -17
- package/dist/assets/GitView-Znn7VJcP.js +0 -6
- package/dist/assets/LinearIssuesView-jP-hXyac.js +0 -1
- package/dist/assets/MarkdownRendererImpl-Dt9mjTRN.js +0 -12
- package/dist/assets/PlanView-B0F3BtPZ.js +0 -5
- package/dist/assets/SettingsView-BBW-S-gh.js +0 -28
- package/dist/assets/ToolPartDiffPreview-CUNe28U1.js +0 -8
- package/dist/assets/index-C57jT0Sa.css +0 -1
- package/dist/assets/index-DW_E3rnL.js +0 -7
- package/dist/assets/main-Bv5Pkngh.js +0 -928
- package/dist/assets/pl-Dioz29BI.js +0 -15
- package/dist/assets/renderMobileApp-D9yQJy0L.js +0 -25
- package/dist/assets/runtimeEndpointReset-CjhvxLH0.js +0 -16
- package/dist/assets/tr-DFnMlPxY.js +0 -6
- package/dist/assets/useInlineCommentController-CDEuSlPH.js +0 -2
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/server/index.d.ts.bak +0 -39
- package/server/lib/agent-tool/DOCUMENTATION.md.bak +0 -119
- package/server/lib/browser-control/DOCUMENTATION.md.bak +0 -50
- package/server/lib/context-obligatory/DOCUMENTATION.md.bak +0 -19
- package/server/lib/dev-tunnel/DOCUMENTATION.md.bak +0 -57
- package/server/lib/dictation/DOCUMENTATION.md.bak +0 -100
- package/server/lib/event-stream/DOCUMENTATION.md.bak +0 -62
- package/server/lib/fs/DOCUMENTATION.md.bak +0 -47
- package/server/lib/git/DOCUMENTATION.md.bak +0 -193
- package/server/lib/github/DOCUMENTATION.md.bak +0 -183
- package/server/lib/linear/DOCUMENTATION.md.bak +0 -97
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md.bak +0 -91
- package/server/lib/markdown-image-grants/DOCUMENTATION.md.bak +0 -40
- package/server/lib/notifications/APNS.md.bak +0 -135
- package/server/lib/notifications/DOCUMENTATION.md.bak +0 -138
- package/server/lib/openchamber-control/DOCUMENTATION.md.bak +0 -64
- package/server/lib/opencode/DOCUMENTATION.md.bak +0 -431
- package/server/lib/opencode/managed-process-registry.d.ts.bak +0 -13
- package/server/lib/opencode/provider-env-aliases.d.ts.bak +0 -3
- package/server/lib/permission-auto-accept/DOCUMENTATION.md.bak +0 -34
- package/server/lib/project-context/DOCUMENTATION.md.bak +0 -160
- package/server/lib/quota/DOCUMENTATION.md.bak +0 -123
- package/server/lib/relay/DOCUMENTATION.md.bak +0 -100
- package/server/lib/scheduled-tasks/DOCUMENTATION.md.bak +0 -182
- package/server/lib/session-assist/DOCUMENTATION.md.bak +0 -66
- package/server/lib/session-goal/DOCUMENTATION.md.bak +0 -213
- package/server/lib/session-knowledge/DOCUMENTATION.md.bak +0 -89
- package/server/lib/skills-catalog/DOCUMENTATION.md.bak +0 -151
- package/server/lib/small-model/DOCUMENTATION.md.bak +0 -212
- package/server/lib/system-prompt/DOCUMENTATION.md.bak +0 -36
- package/server/lib/terminal/DOCUMENTATION.md.bak +0 -50
- package/server/lib/text/DOCUMENTATION.md.bak +0 -35
- package/server/lib/tts/DOCUMENTATION.md.bak +0 -147
- package/server/lib/tunnels/DOCUMENTATION.md.bak +0 -21
- package/server/lib/ui-auth/DOCUMENTATION.md.bak +0 -44
- package/server/lib/walkthrough/DOCUMENTATION.md.bak +0 -411
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{R as o,j as s,f as gt,r as qe}from"./vendor-react-BUCujlKS.js";import{f as it,B as H,I as R,o as Dn,b7 as wa,t as D,O as dc,fI as uc,es as _e,fJ as Et,b as Bs,h as ye,fK as pc,b3 as rn,b5 as on,fL as mc,b6 as ln,ej as Jn,fM as ml,fN as gc,fO as ha,fP as dn,c0 as Hs,bF as Kt,bG as zt,bH as _t,bI as $t,bJ as Vt,bK as ts,T as Je,fQ as $a,b2 as cn,e6 as rr,fR as fc,fS as Vn,eu as Jt,fT as Qs,l as Ze,eI as Lt,bT as It,bU as Pt,eF as Ft,bV as Rt,bW as At,bX as ot,fU as qt,bY as As,du as Ka,eH as En,eK as va,eJ as nn,fV as fs,dz as xs,fW as Cs,fX as hc,cn as ft,fY as gl,fZ as xc,f_ as Gn,f$ as fl,g0 as vc,g1 as ya,fi as Vs,g2 as xa,g3 as hl,g4 as yr,dv as xl,g5 as Wn,a6 as ba,a5 as Os,g6 as vl,g7 as Lr,ab as yc,e4 as yl,g as za,g8 as bc,g9 as Ys,e3 as wc,ga as jc,gb as kc,gc as br,a7 as wr,a8 as jr,a9 as bl,gd as fn,a1 as Ni,bg as kr,N as Nr,ge as Or,ao as Nc,bZ as Sc,cD as Cc,R as Ic,Q as Pc,S as Ac,W as wl,gf as Tc,gg as Ec,bQ as Dc,b_ as or,gh as jl,aa as vi,gi as kl,P as Bn,gj as Js,er as Fs,ec as Nl,a0 as Mc,n as Zt,d_ as Si,x as Sl,w as Rc,i as Lc,j as Oc,d$ as Fc,p as Kc,gk as zc,gl as Uc,gm as Fr,dA as Cl,gn as _c,go as Vi,gp as Kr,gq as $c,gr as Vc,gs as Bc,gt as Hc,dG as Ci,gu as hs,gv as Ps,gw as en,gx as tn,av as Tn,aw as ua,gy as An,eE as Nn,gz as Va,gA as zr,gB as pa,gC as ma,bC as Qn,gD as Gc,gE as Wc,gF as qc,gG as Jc,gH as Bi,gI as Ur,gJ as Qc,gK as Yc,gL as Xc,gM as Zc,gN as _r,y as ed,m as $r,cR as td,gO as sd,gP as Hi,gQ as Vr,e1 as nd,gR as Pi,gS as ad,gT as id,gU as rd,gV as od,gW as ld,gX as Gi,co as cd,bD as Il,gY as Pl,gZ as dd,aq as Sn,as as ud}from"./useAppFontEffects-D7sNpuL2.js";import{r as mt,u as le,G as cs,d3 as pd,d4 as Br,w as hn,az as xn,a0 as md,a8 as yt,o as an,z as as,L as Hr,cl as Gr,cs as Wr,S as Ia,p as gd,d5 as fd,j as hd,ck as fa,d6 as xd,aj as vd,cp as yd,d7 as bd,d8 as wd,s as jd,e as Ba,cq as kd,A as Ha,d9 as Al,Y as Nd,da as Sd,cV as Cd,X as Id,aJ as qr,aY as ii,aK as Pd,db as Ad,a7 as qn,dc as Td,v as Tl,dd as Jr,d2 as Qr,de as Yr,aH as Xr,df as Ed,dg as Dd,dh as Md,di as Rd,dj as Zr,b as Ld,aC as El,dk as Dl,dl as Od,dm as Fd,dn as Kd,dp as zd,dq as Ud,dr as _d,au as $d,i as Ml}from"./index-DF5kMP-i.js";import{u as Vd,U as eo,G as Yn,I as Xn,J as Zn,K as ea,d as Sr,A as Mn,F as Rn,E as Ln,a2 as Hn,Q as Bd,k as Is,a0 as Hd,a3 as Oa,a4 as Rl,L as Gd,M as Wd}from"./runtimeEndpointReset-CYJ9O_xX.js";import{u as Ks,c as Ll,d as qd,p as Jd}from"./vendor-zustand-BAGL70zf.js";import{o as Qd,s as to,c as Yd}from"./vendor-zod-CK21ihK-.js";import{s as Xd,p as Zd}from"./vendor-yaml-3778uTud.js";import{c as so,s as eu,C as no,P as tu}from"./shikiHighlight-TEQCmzW8.js";import{getResolvedShikiTheme as su}from"./appThemeRegistry-BK0dHKa6.js";import{E as ao}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Ol}from"./vendor-qrcode-DTJ12-WC.js";const io=()=>{const{t}=it(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const p=await mt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!p.ok)return;const m=await p.json().catch(()=>null);if(!m||i)return;const x=typeof m.port=="number"&&Number.isFinite(m.port)&&m.port>0?m.port:null,d=typeof m.tunnelUrl=="string"&&m.tunnelUrl.trim().length>0?m.tunnelUrl.trim():null;a({port:x,tunnelUrl:d})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.aiworker.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.aiworker.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(H,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Dn(i.url)},children:[s.jsx(R,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},ro="https://roweb.cn/roweb/openchamber",nu="https://discord.gg/ZYRSdnwwKA",oo="https://x.com/openchamber_dev",au=800,Fl=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=it(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,p]=o.useState(null),[m,x]=o.useState(null),d=Vd(Ks(C=>({info:C.info,checking:C.checking,available:C.available,error:C.error,downloading:C.downloading,downloaded:C.downloaded,progress:C.progress,runtimeType:C.runtimeType,checkForUpdates:C.checkForUpdates,downloadUpdate:C.downloadUpdate,restartToUpdate:C.restartToUpdate}))),{isMobile:y}=wa(),c=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await mt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.aiworkerVersion=="string"&&g.aiworkerVersion.trim().length>0?g.aiworkerVersion.trim():null;C||p(T)}catch{C||p(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await mt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.currentVersion=="string"&&g.currentVersion.trim().length>0?g.currentVersion.trim():null;C||x(T)}catch{C||x(null)}})(),()=>{C=!0}},[]);const N=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),N.current=!0;else if(i){const C=setTimeout(()=>{r(!1),N.current&&!d.available&&!d.error&&(D.success(e("settings.aiworker.about.toast.latestVersion")),N.current=!1)},au);return()=>clearTimeout(C)}},[e,d.checking,i,d.available,d.error]);const h=d.checking||i;return y?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(dc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${uc}`,children:"AiWorker"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:m||e("settings.aiworker.about.state.unknown")})})]}),s.jsx(io,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:()=>d.checkForUpdates(),disabled:h,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[h?s.jsx(R,{name:"loader",className:"size-4 animate-spin"}):s.jsx(R,{name:"refresh",className:"size-4"}),e(h?"settings.aiworker.about.state.checking":"settings.aiworker.about.actions.checkForUpdates")]}),!h&&d.available&&s.jsxs(H,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(R,{name:"download",className:"size-4"}),e("settings.aiworker.about.actions.updateToVersion",{version:d.info?.version||""})]})]}),d.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:d.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:ro,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(R,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:nu,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(R,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:oo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(R,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@aiworker_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(eo,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]}):s.jsxs(_e,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.aiworker.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.aiworker.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:m||e("settings.aiworker.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[d.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(R,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.aiworker.about.state.checking")})]}),!d.checking&&d.available&&s.jsxs(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(R,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.aiworker.about.actions.updateToVersion",{version:d.info?.version||""})]}),!d.checking&&!d.available&&!d.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.about.state.upToDate")}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>d.checkForUpdates(),disabled:d.checking,children:e("settings.aiworker.about.actions.checkForUpdates")})]})]}),d.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Et,children:e("settings.aiworker.about.field.instanceUrls")}),s.jsx(io,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:ro,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(R,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:oo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(R,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@aiworker_dev"})]})]})]}),s.jsx(eo,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]})},iu=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=gt.c(4),e=le(ru),a=Bs(ou),n=Bs(lu);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=iu(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function ru(t){return t.settingsProjectPath}function ou(t){return t.projects}function lu(t){return t.activeProjectId}const Kl=t=>t.trim(),Ga=t=>{const e=gt.c(40),{className:a}=t,{t:n}=it(),i=Bs(cu),r=Us(),l=le(du),p=cs();let m;e[0]!==i?(m=[...i].sort(uu),e[0]=i,e[1]=m):m=e[1];const x=m;let d;e:{if(x.length===0){d=null;break e}let _;e[2]!==r||e[3]!==x?(_=x.find(j=>j.path===r)??x[0],e[2]=r,e[3]=x,e[4]=_):_=e[4],d=_}const y=d;if(p||x.length===0)return null;let c;e[5]!==y||e[6]!==n?(c=y?.label&&y.label.trim().length>0?y.label:y?.path.split("/").filter(Boolean).pop()||y?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=y,e[6]=n,e[7]=c):c=e[7];const N=c;let h;e[8]!==N?(h=Kl(N),e[8]=N,e[9]=h):h=e[9];const C=h;let b;e[10]!==a?(b=ye(a),e[10]=a,e[11]=b):b=e[11];let S;e[12]!==n?(S=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=S):S=e[13];let g;e[14]!==n?(g=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=g):g=e[15];let T,M;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=ye("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),M=s.jsx(R,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=T,e[17]=M):(T=e[16],M=e[17]);let P;e[18]!==C?(P=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:C}),e[18]=C,e[19]=P):P=e[19];let k;e[20]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(R,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=k):k=e[20];let f;e[21]!==P||e[22]!==S||e[23]!==g?(f=s.jsx(rn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":S,title:g,className:T,children:[M,P,k]})}),e[21]=P,e[22]=S,e[23]=g,e[24]=f):f=e[24];const w=y?.id??"";let F;e[25]!==l||e[26]!==x?(F=_=>{if(!_)return;const j=x.find(V=>V.id===_);j&&l(j.path)},e[25]=l,e[26]=x,e[27]=F):F=e[27];let A;e[28]!==x?(A=x.map(pu),e[28]=x,e[29]=A):A=e[29];let I;e[30]!==w||e[31]!==F||e[32]!==A?(I=s.jsx(on,{align:"start",className:"w-auto",children:s.jsx(mc,{value:w,onValueChange:F,children:A})}),e[30]=w,e[31]=F,e[32]=A,e[33]=I):I=e[33];let E;e[34]!==f||e[35]!==I?(E=s.jsxs(ln,{children:[f,I]}),e[34]=f,e[35]=I,e[36]=E):E=e[36];let B;return e[37]!==E||e[38]!==b?(B=s.jsx("div",{className:b,children:E}),e[37]=E,e[38]=b,e[39]=B):B=e[39],B};function cu(t){return t.projects}function du(t){return t.setSettingsProjectPath}function uu(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function pu(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Kl(e);return s.jsx(pc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function mu(t,e){return`opencode:sidebar-group:${t}:${e}`}const lr=t=>{const e=gt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,p=r===void 0?!0:r;let m;e[0]!==a||e[1]!==i?(m=mu(i,a),e[0]=a,e[1]=i,e[2]=m):m=e[2];const x=m,d=o.useId();let y;e[3]!==p||e[4]!==x?(y=()=>{try{const I=localStorage.getItem(x);if(I!==null)return I==="true"}catch{}return p},e[3]=p,e[4]=x,e[5]=y):y=e[5];const[c,N]=qe.useState(y);let h,C;e[6]!==c||e[7]!==x?(h=()=>{try{localStorage.setItem(x,String(c))}catch{}},C=[x,c],e[6]=c,e[7]=x,e[8]=h,e[9]=C):(h=e[8],C=e[9]),qe.useEffect(h,C);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>N(gu),e[10]=b):b=e[10];let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=ye("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=S):S=e[11];const g=!c&&"-rotate-90";let T;e[12]!==g?(T=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=T):T=e[13];let M;e[14]!==T?(M=s.jsx(R,{name:"arrow-down-s",className:T}),e[14]=T,e[15]=M):M=e[15];let P;e[16]!==a?(P=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=P):P=e[17];let k;e[18]!==n?(k=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=k):k=e[19];let f;e[20]!==d||e[21]!==c||e[22]!==M||e[23]!==P||e[24]!==k?(f=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":c,"aria-controls":d,className:S,children:[M,P,k]}),e[20]=d,e[21]=c,e[22]=M,e[23]=P,e[24]=k,e[25]=f):f=e[25];const w=!c;let F;e[26]!==l||e[27]!==d||e[28]!==w?(F=s.jsx("div",{id:d,hidden:w,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=d,e[28]=w,e[29]=F):F=e[29];let A;return e[30]!==f||e[31]!==F?(A=s.jsxs("div",{children:[f,F]}),e[30]=f,e[31]=F,e[32]=A):A=e[32],A};function gu(t){return!t}const fu=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},hu=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},lo=t=>{const e=hu(fu(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},xu=({onItemSelect:t})=>{const{t:e}=it(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,p]=o.useState(null),[m,x]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState(null),{selectedAgentName:h,setSelectedAgent:C,setAgentDraft:b,createAgent:S,deleteAgent:g,loadAgents:T}=Jn(Ks(z=>({selectedAgentName:z.selectedAgentName,setSelectedAgent:z.setSelectedAgent,setAgentDraft:z.setAgentDraft,createAgent:z.createAgent,deleteAgent:z.deleteAgent,loadAgents:z.loadAgents}))),M=Us(),P=Jn(z=>ml(z,M));o.useEffect(()=>{T(M)},[T,M]);const k="bg-background",f=()=>{const z="new-agent";let re=z,$=1;for(;P.some(U=>U.name===re);)re=`${z}-${$}`,$++;b({name:re,scope:"user"}),C(re),t?.()},w=async z=>{if(ha(z)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}p(z),x("delete")},F=async z=>{ha(z)&&(p(z),x("reset"))},A=()=>{p(null),x(null)},I=async()=>{if(!(!l||!m)){y(!0);try{const z=await g(l.name,l.scope,M);z.ok?(z.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):z.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):m==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),A()):m==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(z){const re=z instanceof Error?z.message:"",$=/built-in|not deletable|not found/i.test(re);m==="delete"?D.error(e($?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}y(!1)}},E=z=>{const re=z.name;let $=1,U=`${re}-copy`;for(;P.some(X=>X.name===U);)$++,U=`${re}-copy-${$}`;const K=z,O=z.model?.providerID&&z.model?.modelID?`${z.model.providerID}/${z.model.modelID}`:null,Y=z;b({name:U,scope:K.scope||"user",description:z.description,model:O,variant:z.variant,temperature:z.temperature,top_p:z.topP,prompt:z.prompt,mode:z.mode,permission:lo(z.permission),disable:Y.disable}),C(U),t?.()},B=z=>{r(z.name),n(z)},_=async()=>{if(!a)return;const z=i.trim().replace(/\s+/g,"-");if(!z){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(z===a.name){n(null);return}if(P.some(K=>K.name===z)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const re=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,$=a,U=await S({name:z,description:a.description,model:re,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:lo(a.permission),disable:$.disable,scope:$.scope},M);if(U.ok){const K=await g(a.name,$.scope,M);K.ok?(U.requiresManualRestart||K.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:z})),C(z)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},j=z=>{switch(z){case"primary":return s.jsx(R,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(R,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(R,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},V=P.filter(z=>!gc(z)),q=V.filter(ha),L=V.filter(z=>!ha(z)),{groupedCustomAgents:Q,ungroupedCustomAgents:ne}=qe.useMemo(()=>{const z={},re=[];for(const U of L){const K=U;K.group?(z[K.group]||(z[K.group]=[]),z[K.group].push(U)):re.push(U)}return{groupedCustomAgents:Object.keys(z).sort((U,K)=>U.localeCompare(K)).map(U=>({name:U,agents:z[U]})),ungroupedCustomAgents:re}},[L]);return s.jsxs("div",{className:ye("flex h-full flex-col",k),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${dn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ga,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:V.length})}),s.jsx(H,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:f,children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:V.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[q.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),q.map(z=>s.jsx(Wi,{agent:z,isSelected:h===z.name,onSelect:()=>{C(z.name),t?.()},onReset:()=>F(z),onDuplicate:()=>E(z),getAgentModeIcon:j,isMenuOpen:c===z.name,onMenuOpenChange:re=>N(re?z.name:null)},z.name))]}),L.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),Q.map(({name:z,agents:re})=>s.jsx(lr,{label:z,count:re.length,storageKey:"agents",children:re.map($=>s.jsx(Wi,{agent:$,isSelected:h===$.name,onSelect:()=>{C($.name),t?.()},onRename:()=>B($),onDelete:()=>w($),onDuplicate:()=>E($),getAgentModeIcon:j,isMenuOpen:c===$.name,onMenuOpenChange:U=>N(U?$.name:null)},$.name))},z)),ne.map(z=>s.jsx(Wi,{agent:z,isSelected:h===z.name,onSelect:()=>{C(z.name),t?.()},onRename:()=>B(z),onDelete:()=>w(z),onDuplicate:()=>E(z),getAgentModeIcon:j,isMenuOpen:c===z.name,onMenuOpenChange:re=>N(re?z.name:null)},z.name))]})]})}),s.jsx(Kt,{open:l!==null&&m!==null,onOpenChange:z=>{!z&&!d&&A()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(m==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:m==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:A,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:I,disabled:d,children:e(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:z=>!z&&n(null),children:s.jsxs(zt,{children:[s.jsxs(_t,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Je,{value:i,onChange:z=>r(z.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:z=>{z.key==="Enter"&&_()}}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:_,children:e("settings.common.actions.rename")})]})]})})]})},Wi=t=>{const e=gt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:p,onDuplicate:m,getAgentModeIcon:x,isMenuOpen:d,onMenuOpenChange:y}=t,{t:c}=it(),N=a;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=$a(),e[0]=h):h=e[0];const C=h,[b,S]=o.useState(!1);let g;e[1]!==r||e[2]!==m||e[3]!==p||e[4]!==l||e[5]!==c?(g=re=>s.jsxs(s.Fragment,{children:[p&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),p()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(re,{onClick:$=>{$.stopPropagation(),m()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),r&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[1]=r,e[2]=m,e[3]=p,e[4]=l,e[5]=c,e[6]=g):g=e[6];const T=g,M=n?"bg-interactive-selection":"hover:bg-interactive-hover";let P;e[7]!==M?(P=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",M),e[7]=M,e[8]=P):P=e[8];let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=C?void 0:re=>{re.preventDefault(),S(!0)},e[9]=k):k=e[9];let f;e[10]!==P?(f=s.jsx("div",{className:P,onContextMenu:k}),e[10]=P,e[11]=f):f=e[11];let w;e[12]!==a.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=w):w=e[13];let F;e[14]!==a.mode||e[15]!==x?(F=x(a.mode),e[14]=a.mode,e[15]=x,e[16]=F):F=e[16];let A;e[17]!==a||e[18]!==N.scope||e[19]!==c?(A=(N.scope||ha(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ha(a)?c("settings.agents.sidebar.badge.system"):N.scope}),e[17]=a,e[18]=N.scope,e[19]=c,e[20]=A):A=e[20];let I;e[21]!==w||e[22]!==F||e[23]!==A?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,F,A]}),e[21]=w,e[22]=F,e[23]=A,e[24]=I):I=e[24];let E;e[25]!==a.description?(E=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=E):E=e[26];let B;e[27]!==i||e[28]!==I||e[29]!==E?(B=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[I,E]}),e[27]=i,e[28]=I,e[29]=E,e[30]=B):B=e[30];let _;e[31]!==y?(_=re=>{re&&S(!1),y(re)},e[31]=y,e[32]=_):_=e[32];let j;e[33]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=j):j=e[33];let V;e[34]!==T?(V=s.jsx(on,{align:"end",className:"w-fit min-w-20",children:T(cn)}),e[34]=T,e[35]=V):V=e[35];let q;e[36]!==d||e[37]!==_||e[38]!==V?(q=s.jsxs(ln,{open:d,onOpenChange:_,children:[j,V]}),e[36]=d,e[37]=_,e[38]=V,e[39]=q):q=e[39];let L;e[40]!==B||e[41]!==q?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[B,q]}),e[40]=B,e[41]=q,e[42]=L):L=e[42];let Q;e[43]!==L||e[44]!==f?(Q=s.jsx(Zn,{render:f,children:L}),e[43]=L,e[44]=f,e[45]=Q):Q=e[45];let ne;e[46]!==T?(ne=s.jsx(Yn,{className:"w-fit min-w-20",children:T(Xn)}),e[46]=T,e[47]=ne):ne=e[47];let z;return e[48]!==b||e[49]!==Q||e[50]!==ne?(z=s.jsxs(ea,{open:b,onOpenChange:S,children:[Q,ne]}),e[48]=b,e[49]=Q,e[50]=ne,e[51]=z):z=e[51],z},es=t=>{const e=gt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:p,description:m,headerEnd:x,showSaveStatus:d}=t,y=d===void 0?!1:d,c=r!=null||m!=null||x!=null||y,N=typeof r=="string"||typeof r=="number",h=l!=null||p!=null;let C;e[0]!==i?(C=ye("h-full",i),e[0]=i,e[1]=C):C=e[1];let b;e[2]!==n?(b=ye("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=b):b=e[3];let S;e[4]!==m||e[5]!==c||e[6]!==h||e[7]!==x||e[8]!==N||e[9]!==y||e[10]!==r||e[11]!==p||e[12]!==l?(S=c&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?N?h?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:ye(rr,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:p})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:rr,children:r}):r:null,m!=null?typeof m=="string"||typeof m=="number"?s.jsx("p",{className:fc,children:m}):m:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[x,y&&s.jsx(yu,{})]})]}),e[4]=m,e[5]=c,e[6]=h,e[7]=x,e[8]=N,e[9]=y,e[10]=r,e[11]=p,e[12]=l,e[13]=S):S=e[13];let g;e[14]!==a||e[15]!==b||e[16]!==S?(g=s.jsxs("div",{className:b,children:[S,a]}),e[14]=a,e[15]=b,e[16]=S,e[17]=g):g=e[17];let T;return e[18]!==C||e[19]!==g?(T=s.jsx(Hs,{outerClassName:C,className:"w-full @container",children:g}),e[18]=C,e[19]=g,e[20]=T):T=e[20],T},vu=500,yu=()=>{const t=gt.c(13),{t:e}=it(),a=o.useSyncExternalStore(pd,Br,Br),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),vu);return()=>clearTimeout(d)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let d;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(R,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let y;t[4]!==e?(y=e("settings.common.status.saveFailed"),t[4]=e,t[5]=y):y=t[5];let c;return t[6]!==y?(c=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[d,s.jsx("span",{children:y})]}),t[6]=y,t[7]=c):c=t[7],c}if(a!=="saving"||!n)return null;let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=p):p=t[8];let m;t[9]!==e?(m=e("settings.common.actions.saving"),t[9]=e,t[10]=m):m=t[10];let x;return t[11]!==m?(x=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[p,s.jsx("span",{children:m})]}),t[11]=m,t[12]=x):x=t[12],x},bu=["allow","ask","deny"],Fa=t=>t==="allow"||t==="ask"||t==="deny",cr=()=>({global:null,keys:{}}),wu=t=>{const e=cr();if(t==null)return e;if(typeof t=="string")return Fa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Fa(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Fa(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Fa(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},dr=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},ju=(t,e)=>JSON.stringify(dr(t))===JSON.stringify(dr(e)),Cn=t=>JSON.parse(JSON.stringify(t)),ku=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Nu=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),co=new Set(["write","patch","apply_patch","multiedit","invalid"]),Su=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Cu=({agent:t})=>{const{t:e}=it(),a=Jn(K=>K.updateAgent),[n,i]=o.useState(cr),[r,l]=o.useState(cr),[p,m]=o.useState(!0),[x,d]=o.useState(!1),[y,c]=o.useState(!1),[N,h]=o.useState({}),[C,b]=o.useState([]),[S,g]=o.useState(""),[T,M]=o.useState(0),P=t.name,k=Us();o.useEffect(()=>{let K=!1;return m(!0),d(!1),(async()=>{try{const O=k,Y=O?`?directory=${encodeURIComponent(O)}`:"",X=await mt(`/api/config/agents/${encodeURIComponent(P)}/config${Y}`,{headers:{"Cache-Control":"no-cache",...O?{"x-opencode-directory":O}:{}}});if(!X.ok)throw new Error(String(X.status));const ee=await X.json().catch(()=>null);if(K)return;const ge=wu(ee?.config?.permission);i(Cn(ge)),l(ge)}catch{K||d(!0)}finally{K||m(!1)}})(),()=>{K=!0}},[P,T,k]),o.useEffect(()=>{let K=!1;return(async()=>{try{const O=await hn.listToolIds({directory:k});!K&&Array.isArray(O)&&b(O.filter(Y=>typeof Y=="string"&&!co.has(Y)))}catch{}})(),()=>{K=!0}},[P,k]);const f=o.useMemo(()=>{const K=t.permission;if(!Array.isArray(K))return[];const O=[];for(const Y of K){if(!Y||typeof Y!="object")continue;const{permission:X,pattern:ee,action:ge}=Y;typeof X=="string"&&typeof ee=="string"&&Fa(ge)&&O.push({permission:X,pattern:ee,action:ge})}return O},[t]),w=o.useCallback(K=>{const O=f.find(X=>X.permission===K&&X.pattern==="*");if(O)return O.action;const Y=f.find(X=>X.permission==="*"&&X.pattern==="*");return Y?Y.action:null},[f]),F=o.useCallback(K=>{const O=r.keys[K]?.patterns??[],Y=new Set(O.map(X=>X.pattern));return f.filter(X=>X.permission===K&&X.pattern!=="*"&&!Y.has(X.pattern))},[f,r.keys]),A=o.useMemo(()=>{const K=new Set;for(const O of C)K.add(O);for(const O of ku)K.add(O);for(const O of Object.keys(r.keys))K.add(O);for(const O of co)K.delete(O);return Array.from(K).sort((O,Y)=>O.localeCompare(Y))},[C,r.keys]),I=o.useMemo(()=>!ju(r,n),[r,n]),E=K=>{l(O=>({...O,global:K}))},B=(K,O)=>{l(Y=>{const X=Cn(Y),ee=X.keys[K]??{action:null,patterns:[]};return ee.action=O,ee.action===null&&ee.patterns.length===0?delete X.keys[K]:X.keys[K]=ee,X})},_=(K,O,Y,X)=>{l(ee=>{const ge=Cn(ee),de=ge.keys[K]??{action:null,patterns:[]};return de.patterns[O]={pattern:Y,action:X},ge.keys[K]=de,ge})},j=K=>{l(O=>{const Y=Cn(O),X=Y.keys[K]??{action:null,patterns:[]};return X.patterns.push({pattern:"",action:"allow"}),Y.keys[K]=X,Y}),h(O=>({...O,[K]:!0}))},V=(K,O)=>{l(Y=>{const X=Cn(Y),ee=X.keys[K];return ee?(ee.patterns.splice(O,1),ee.action===null&&ee.patterns.length===0&&delete X.keys[K],X):Y})},q=()=>{const K=S.trim();!K||K==="*"||(l(O=>{if(O.keys[K])return O;const Y=Cn(O);return Y.keys[K]={action:"ask",patterns:[]},Y}),h(O=>({...O,[K]:!0})),g(""))},L=async()=>{c(!0);try{const K=dr(r),O=await a(P,{permission:K});O.ok?(i(Cn(r)),D.success(O.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):D.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{c(!1)}},Q=()=>{l(Cn(n))},ne=K=>e(K==="allow"?"settings.agents.page.permissionsEditor.action.allow":K==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),z=e("settings.agents.page.permissionsEditor.action.inherit"),re=e("settings.agents.page.permissionsEditor.action.default"),$=K=>[...K?[{value:"inherit",label:K}]:[],...bu.map(O=>({value:O,label:ne(O)}))],U=(K,O,Y,X=z)=>s.jsx(Qs,{value:K??"inherit",options:$(X),onChange:ee=>O(ee==="inherit"?null:ee),"aria-label":Y});return p?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Vn,children:e("common.loading")})}):x?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(H,{variant:"outline",size:"xs",onClick:()=>M(K=>K+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(_e,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:I?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Q,disabled:y,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{L()},disabled:y,children:e(y?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ne(w("*")??"allow")})})]}),U(r.global,E,e("settings.agents.page.permissionsEditor.defaultAria"),re)]}),s.jsx("div",{children:A.map(K=>{const O=r.keys[K]??{action:null,patterns:[]},Y=F(K),X=Nu.has(K)||O.patterns.length>0,ee=X||Y.length>0,ge=N[K]===!0,de=w(K);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:ee?()=>h(xe=>({...xe,[K]:!ge})):void 0,className:ye("flex min-w-0 items-center gap-1.5 text-left",!ee&&"cursor-default"),"aria-expanded":ee?ge:void 0,children:[s.jsx(R,{name:ge&&ee?"arrow-down-s":"arrow-right-s",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ee&&"opacity-0")}),s.jsx("span",{className:Et,children:Su(K)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:K}),O.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ne(de)})}),O.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(O.patterns.length)})})]}),U(O.action,xe=>B(K,xe),e("settings.agents.page.permissionsEditor.keyAria",{key:K}))]}),ge&&ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[O.patterns.map((xe,ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Je,{value:xe.pattern,onChange:te=>_(K,ae,te.target.value,xe.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Qs,{value:xe.action,options:$(),onChange:te=>_(K,ae,xe.pattern,te),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:K})}),s.jsx(H,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>V(K,ae),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]},ae)),X&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>j(K),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),Y.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Y.map(xe=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:xe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ne(xe.action)})]},`${xe.pattern}-${xe.action}`))]})]})]},K)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Je,{value:S,onChange:K=>g(K.target.value),onKeyDown:K=>{K.key==="Enter"&&(K.preventDefault(),q())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:q,disabled:!S.trim(),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Iu=(t,e)=>{const a=va(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},Pu=()=>{const{t}=it(),e=Ze(U=>U.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:p}=Jn(Ks(U=>({selectedAgentName:U.selectedAgentName,getAgentByName:U.getAgentByName,createAgent:U.createAgent,updateAgent:U.updateAgent,agentDraft:U.agentDraft,setAgentDraft:U.setAgentDraft}))),m=Us(),x=Jn(U=>ml(U,m)),d=a?n(a,m):null,y=!!(l&&l.name===a&&!d),[c,N]=o.useState(""),[h,C]=o.useState("user"),[b,S]=o.useState(""),[g,T]=o.useState("subagent"),[M,P]=o.useState(""),[k,f]=o.useState(""),[w,F]=o.useState(void 0),[A,I]=o.useState(void 0),[E,B]=o.useState(""),[_,j]=o.useState(!1),V=o.useRef(null),q=o.useMemo(()=>Iu(e,M),[M,e]),L=q.length>0,Q=k||"__default",ne=L,z=o.useMemo(()=>k&&!q.includes(k)?[k,...q]:q,[k,q]);o.useEffect(()=>{if(y&&l){const U=l.name||"",K=l.scope||"user",O=l.description||"",Y=l.mode||"subagent",X=l.model||"",ee=l.variant||"",ge=l.temperature??void 0,de=l.top_p??void 0,xe=l.prompt||"";N(U),C(K),S(O),T(Y),P(X),f(ee),F(ge),I(de),B(xe),V.current={draftName:U,draftScope:K,description:O,mode:Y,model:X,variant:ee,temperature:ge,topP:de,prompt:xe};return}if(d&&a===d.name){const U=d.description||"",K=d.mode||"subagent",O=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",Y=d.variant||"",X=d.temperature??void 0,ee=d.topP??void 0,ge=d.prompt||"";S(U),T(K),P(O),f(Y),F(X),I(ee),B(ge),V.current={draftName:"",draftScope:"user",description:U,mode:K,model:O,variant:Y,temperature:X,topP:ee,prompt:ge}}},[l,y,d,a]);const re=o.useMemo(()=>{const U=V.current;return U?!!(y&&(c!==U.draftName||h!==U.draftScope)||b!==U.description||g!==U.mode||M!==U.model||k!==U.variant||w!==U.temperature||A!==U.topP||E!==U.prompt):!1},[b,c,h,y,g,M,E,w,A,k]),$=async()=>{const U=y?c.trim().replace(/\s+/g,"-"):a?.trim();if(!U){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(y&&x.some(K=>K.name===U)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}j(!0);try{const K=M.trim(),O=k.trim(),Y=E.trim(),X={name:U,...b.trim()?{description:b.trim()}:{},mode:g,model:K===""?null:K,variant:O===""?null:O||void 0,temperature:w??null,top_p:A??null,prompt:Y||(y?void 0:null),...y&&h?{scope:h}:{}};let ee;y?(ee=await i(X,m),ee.ok&&p(null)):ee=await r(U,X,m),ee.ok?ee.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):ee.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(t(y?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):D.error(t(y?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(K){console.error("Error saving agent:",K);const O=K instanceof Error&&K.message?K.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(O)}finally{j(!1)}};return a?s.jsxs(es,{title:y?t("settings.agents.page.title.new"):a,description:t(y?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[y&&s.jsxs(Lt,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Je,{value:c,onChange:U=>N(U.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(It,{value:h,onValueChange:U=>C(U),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(qt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:b,onChange:U=>S(U.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(qt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Qs,{"aria-label":t("settings.agents.page.field.mode"),value:g,onChange:T,options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(_e,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Lt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ka,{providerId:va(M)?.providerId??"",modelId:va(M)?.modelId??"",onChange:(U,K)=>{P(U&&K?`${U}/${K}`:""),f("")},className:En})}),s.jsx(Lt,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:ne?s.jsxs(It,{value:Q,onValueChange:U=>f(U==="__default"?"":U),children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:U=>U==="__default"?t("chat.modelControls.default"):U})}),s.jsxs(At,{children:[s.jsx(ot,{value:"__default",children:t("chat.modelControls.default")}),z.map(U=>s.jsx(ot,{value:U,children:U},U))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Je,{value:k,onChange:U=>f(U.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!M&&!k,className:"h-8 w-40 rounded-md px-3"}),k&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>f(""),className:fs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Lt,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(xs,{value:w,fallbackValue:.7,onValueChange:F,onClear:()=>F(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Cs}),w!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(void 0),className:fs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Lt,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(xs,{value:A,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Cs}),A!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:fs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(_e,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:E,onChange:U=>B(U.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!y&&d&&s.jsx(Cu,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(H,{onClick:$,disabled:_||!re,size:"xs",className:"!font-normal",children:t(_?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},Au=Qd({content:to(),exists:Yd(),path:to().min(1).optional()}),zl=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Tu=t=>t.length>0&&!t.endsWith(`
|
|
2
|
+
`)?`${t}
|
|
3
|
+
`:t,ri={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Eu=(t,e)=>t==="custom"?e:vc(t),Du=t=>t==="custom"?"custom":gl(t)?t:"concise",uo={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},qi=async(t,e)=>{xn("saving");try{const a=await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await zl(a,e));xn("saved")}catch(a){throw xn("error"),a}},Mu=()=>{const{t}=it(),e=hc(),[a,n]=o.useState(""),[i,r]=o.useState("AGENTS.md"),[l,p]=o.useState(!1),[m,x]=o.useState(ri.responseStyleEnabled),[d,y]=o.useState(ri.responseStylePreset),[c,N]=o.useState(ri.responseStyleCustomInstructions),[h,C]=o.useState(!0),[b,S]=o.useState(!1),[g,T]=o.useState(!1),[M,P]=o.useState(""),[k,f]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const _=new AbortController;return(async()=>{try{const[V,q]=await Promise.all([mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:_.signal}),mt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:_.signal})]);let L=ri;if(V.ok){const Q=await V.json();L={...L,optimizeSystemPrompt:Q.optimizeSystemPrompt===!0,responseStyleEnabled:Q.responseStyleEnabled===!0,responseStylePreset:Du(Q.responseStylePreset),responseStyleCustomInstructions:typeof Q.responseStyleCustomInstructions=="string"?Q.responseStyleCustomInstructions:""},typeof Q.globalBehaviorPrompt=="string"&&(L={...L,prompt:Q.globalBehaviorPrompt})}if(q.ok){const Q=Au.parse(await q.json());if(_.signal.aborted)return;r(Q.path??"AGENTS.md"),L.prompt.trim()||(L={...L,prompt:Q.content})}n(L.prompt),p(L.optimizeSystemPrompt),f(L.optimizeSystemPrompt),x(L.responseStyleEnabled),y(L.responseStylePreset),N(L.responseStyleCustomInstructions),P(L.prompt),w.current={enabled:L.responseStyleEnabled,preset:L.responseStylePreset,custom:L.responseStyleCustomInstructions}}catch(V){V.name!=="AbortError"&&console.warn("Failed to load behavior settings:",V)}finally{C(!1)}})(),()=>_.abort()},[]),o.useEffect(()=>{if(h)return;const _=w.current;if(_&&_.enabled===m&&_.preset===d&&_.custom===c)return;const j={enabled:m,preset:d,custom:c},V=setTimeout(async()=>{try{await qi({responseStyleEnabled:j.enabled,responseStylePreset:j.preset,responseStyleCustomInstructions:j.custom},t("settings.behavior.page.toast.saveFailed")),w.current=j}catch(q){const L=q instanceof Error?q.message:t("settings.behavior.page.toast.saveFailed");D.error(L)}},400);return()=>clearTimeout(V)},[m,d,c,h,t]);const F=Eu(d,c),A=a!==M,I=l!==k,E=async()=>{S(!0);try{const _=Tu(a),j=await mt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:_})});if(!j.ok)throw new Error(await zl(j,t("settings.behavior.page.toast.saveFailed")));const V=await j.json().catch(()=>null),q=fl(V,"behavior",{id:"agents-md"});await qi({globalBehaviorPrompt:_},t("settings.behavior.page.toast.saveFailed")),n(_),P(_),D.success(t(q?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(_){console.error("Failed to save behavior:",_);const j=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");D.error(j)}finally{S(!1)}},B=async()=>{T(!0);try{await qi({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),f(l),Gn("behavior",{id:"optimize-system-prompt"}),D.success(t("settings.view.pendingRestart.saved"))}catch(_){const j=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");D.error(j)}finally{T(!1)}};return s.jsxs(es,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(_e,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(ft,{checked:l,onChange:p,disabled:h||g,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(H,{type:"button",size:"xs",onClick:()=>{B()},disabled:h||g||!I,className:"!font-normal",children:t(g?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:i})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(As,{value:a,onChange:_=>n(_.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:h,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(H,{onClick:E,disabled:b||!A||h,size:"xs",className:"!font-normal",children:t(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(ft,{checked:m,onChange:x,disabled:h,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Lt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(It,{value:d,onValueChange:_=>y(_),disabled:h||!m,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{children:_=>_==="custom"?t("settings.behavior.page.responseStyle.option.custom"):gl(_)?t(uo[_]):null})}),s.jsxs(At,{children:[xc.map(_=>s.jsx(ot,{value:_,children:t(uo[_])},_)),s.jsx(ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:F,onChange:_=>N(_.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:h||!m||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Ru=t=>{const e=gt.c(176),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(""),[m,x]=o.useState(null),[d,y]=o.useState(null),[c,N]=o.useState(!1),[h,C]=o.useState(null),{selectedCommandName:b,setSelectedCommand:S,setCommandDraft:g,createCommand:T,deleteCommand:M,loadCommands:P}=ya(Ks(Lu)),k=Us();let f;e[0]!==k?(f=ze=>hl(ze,k),e[0]=k,e[1]=f):f=e[1];const w=ya(f);let F;e[2]!==k?(F=ze=>yr(ze,k),e[2]=k,e[3]=F):F=e[3];const A=Vs(F),I=Vs(Ou);let E,B;e[4]!==P||e[5]!==I||e[6]!==k?(E=()=>{P(k),I(k)},B=[P,I,k],e[4]=P,e[5]=I,e[6]=k,e[7]=E,e[8]=B):(E=e[7],B=e[8]),o.useEffect(E,B);let _;e[9]!==A?(_=new Set(A.map(Fu)),e[9]=A,e[10]=_):_=e[10];const j=_;let V;if(e[11]!==w||e[12]!==j){let ze;e[14]!==j?(ze=jt=>!j.has(jt.name),e[14]=j,e[15]=ze):ze=e[15],V=w.filter(ze),e[11]=w,e[12]=j,e[13]=V}else V=e[13];const q=V;let L,Q;e[16]!==b||e[17]!==S||e[18]!==j?(L=()=>{b&&j.has(b)&&S(null)},Q=[b,S,j],e[16]=b,e[17]=S,e[18]=j,e[19]=L,e[20]=Q):(L=e[19],Q=e[20]),o.useEffect(L,Q);let ne;e[21]!==w||e[22]!==a||e[23]!==g||e[24]!==S?(ne=()=>{let ze="new-command",jt=1;for(;w.some(Ee=>Ee.name===ze);)ze=`new-command-${jt}`,jt++;g({name:ze,scope:"user"}),S(ze),a?.()},e[21]=w,e[22]=a,e[23]=g,e[24]=S,e[25]=ne):ne=e[25];const z=ne;let re;e[26]!==n?(re=async ze=>{if(xa(ze)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(ze),y("delete")},e[26]=n,e[27]=re):re=e[27];const $=re;let U;e[28]===Symbol.for("react.memo_cache_sentinel")?(U=async ze=>{xa(ze)&&(x(ze),y("reset"))},e[28]=U):U=e[28];const K=U;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{x(null),y(null)},e[29]=O):O=e[29];const Y=O;let X;e[30]!==m||e[31]!==d||e[32]!==M||e[33]!==k||e[34]!==n?(X=async()=>{if(!m||!d)return;N(!0),await M(m.name,k)?(d==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:m.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:m.name})),Y()):d==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),N(!1)},e[30]=m,e[31]=d,e[32]=M,e[33]=k,e[34]=n,e[35]=X):X=e[35];const ee=X;let ge;e[36]!==w||e[37]!==g||e[38]!==S?(ge=ze=>{const jt=ze.name;let Ee=1,wt=`${jt}-copy`;for(;w.some(J=>J.name===wt);)Ee++,wt=`${jt}-copy-${Ee}`;g({name:wt,scope:ze.scope||"user",description:ze.description,template:ze.template,agent:ze.agent,model:ze.model}),S(wt)},e[36]=w,e[37]=g,e[38]=S,e[39]=ge):ge=e[39];const de=ge;let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=ze=>{p(ze.name),r(ze)},e[40]=xe):xe=e[40];const ae=xe;let te;e[41]!==w||e[42]!==T||e[43]!==M||e[44]!==i||e[45]!==l||e[46]!==S||e[47]!==k||e[48]!==n?(te=async()=>{if(!i)return;const ze=l.trim().replace(/\s+/g,"-");if(!ze){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(ze===i.name){r(null);return}if(w.some(Ee=>Ee.name===ze)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await T({name:ze,description:i.description,template:i.template,agent:i.agent,model:i.model},k)?await M(i.name,k)?(D.success(`Command renamed to "${ze}"`),S(ze)):D.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):D.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=w,e[42]=T,e[43]=M,e[44]=i,e[45]=l,e[46]=S,e[47]=k,e[48]=n,e[49]=te):te=e[49];const ue=te;let Ie,Ne,Se,ve,Oe,Le;if(e[50]!==q||e[51]!==z||e[52]!==$||e[53]!==de||e[54]!==a||e[55]!==h||e[56]!==b||e[57]!==S||e[58]!==n){const ze=q.filter(xa),jt=q.filter(Ku);e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=ye("flex h-full flex-col","bg-background"),e[65]=Oe):Oe=e[65];let Ee;e[66]!==n?(Ee=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Ee):Ee=e[67];let wt;e[68]!==Ee?(wt=s.jsx("h2",{className:`${dn} mb-3`,children:Ee}),e[68]=Ee,e[69]=wt):wt=e[69];let J;e[70]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(Ga,{className:"mb-3"}),e[70]=J):J=e[70];let fe;e[71]!==q.length||e[72]!==n?(fe=n("settings.commands.sidebar.total",{count:q.length}),e[71]=q.length,e[72]=n,e[73]=fe):fe=e[73];let Fe;e[74]!==fe?(Fe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:fe}),e[74]=fe,e[75]=Fe):Fe=e[75];let De;e[76]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[76]=De):De=e[76];let lt;e[77]!==z?(lt=s.jsx(H,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:z,children:De}),e[77]=z,e[78]=lt):lt=e[78];let ct;e[79]!==Fe||e[80]!==lt?(ct=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Fe,lt]}),e[79]=Fe,e[80]=lt,e[81]=ct):ct=e[81],e[82]!==wt||e[83]!==ct?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,J,ct]}),e[82]=wt,e[83]=ct,e[84]=Le):Le=e[84],Ie=Hs,Ne="flex-1 min-h-0",Se="space-y-1 px-3 py-2",ve=q.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[ze.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...ze].sort(zu).map(Qe=>s.jsx(po,{command:Qe,isSelected:b===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onReset:()=>K(Qe),onDuplicate:()=>de(Qe),isMenuOpen:h===Qe.name,onMenuOpenChange:kt=>C(kt?Qe.name:null)},Qe.name))]}),jt.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...jt].sort(Uu).map(Qe=>s.jsx(po,{command:Qe,isSelected:b===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onRename:()=>ae(Qe),onDelete:()=>$(Qe),onDuplicate:()=>de(Qe),isMenuOpen:h===Qe.name,onMenuOpenChange:kt=>C(kt?Qe.name:null)},Qe.name))]})]}),e[50]=q,e[51]=z,e[52]=$,e[53]=de,e[54]=a,e[55]=h,e[56]=b,e[57]=S,e[58]=n,e[59]=Ie,e[60]=Ne,e[61]=Se,e[62]=ve,e[63]=Oe,e[64]=Le}else Ie=e[59],Ne=e[60],Se=e[61],ve=e[62],Oe=e[63],Le=e[64];let oe;e[85]!==Ie||e[86]!==Ne||e[87]!==Se||e[88]!==ve?(oe=s.jsx(Ie,{outerClassName:Ne,className:Se,children:ve}),e[85]=Ie,e[86]=Ne,e[87]=Se,e[88]=ve,e[89]=oe):oe=e[89];const he=m!==null&&d!==null;let Me;e[90]!==c?(Me=ze=>{!ze&&!c&&Y()},e[90]=c,e[91]=Me):Me=e[91];let $e;e[92]!==d||e[93]!==n?($e=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=$e):$e=e[94];let Ve;e[95]!==$e?(Ve=s.jsx($t,{children:$e}),e[95]=$e,e[96]=Ve):Ve=e[96];let We;e[97]!==m?.name||e[98]!==d||e[99]!==n?(We=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:m?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:m?.name??""}),e[97]=m?.name,e[98]=d,e[99]=n,e[100]=We):We=e[100];let se;e[101]!==We?(se=s.jsx(Vt,{children:We}),e[101]=We,e[102]=se):se=e[102];let ie;e[103]!==Ve||e[104]!==se?(ie=s.jsxs(_t,{children:[Ve,se]}),e[103]=Ve,e[104]=se,e[105]=ie):ie=e[105];let je;e[106]!==n?(je=n("settings.common.actions.cancel"),e[106]=n,e[107]=je):je=e[107];let be;e[108]!==c||e[109]!==je?(be=s.jsx(H,{size:"sm",variant:"ghost",onClick:Y,disabled:c,children:je}),e[108]=c,e[109]=je,e[110]=be):be=e[110];let Te;e[111]!==d||e[112]!==n?(Te=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=Te):Te=e[113];let Ue;e[114]!==ee||e[115]!==c||e[116]!==Te?(Ue=s.jsx(H,{size:"sm",onClick:ee,disabled:c,children:Te}),e[114]=ee,e[115]=c,e[116]=Te,e[117]=Ue):Ue=e[117];let Pe;e[118]!==be||e[119]!==Ue?(Pe=s.jsxs(ts,{children:[be,Ue]}),e[118]=be,e[119]=Ue,e[120]=Pe):Pe=e[120];let we;e[121]!==ie||e[122]!==Pe?(we=s.jsxs(zt,{className:"max-w-md",children:[ie,Pe]}),e[121]=ie,e[122]=Pe,e[123]=we):we=e[123];let Ge;e[124]!==he||e[125]!==Me||e[126]!==we?(Ge=s.jsx(Kt,{open:he,onOpenChange:Me,children:we}),e[124]=he,e[125]=Me,e[126]=we,e[127]=Ge):Ge=e[127];const pe=i!==null;let Ce;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ce=ze=>!ze&&r(null),e[128]=Ce):Ce=e[128];let Re;e[129]!==n?(Re=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Re):Re=e[130];let Ye;e[131]!==Re?(Ye=s.jsx($t,{children:Re}),e[131]=Re,e[132]=Ye):Ye=e[132];const W=i?.name??"";let ke;e[133]!==n||e[134]!==W?(ke=n("settings.commands.sidebar.renameDialog.description",{name:W}),e[133]=n,e[134]=W,e[135]=ke):ke=e[135];let Ae;e[136]!==ke?(Ae=s.jsx(Vt,{children:ke}),e[136]=ke,e[137]=Ae):Ae=e[137];let He;e[138]!==Ye||e[139]!==Ae?(He=s.jsxs(_t,{children:[Ye,Ae]}),e[138]=Ye,e[139]=Ae,e[140]=He):He=e[140];let at;e[141]===Symbol.for("react.memo_cache_sentinel")?(at=ze=>p(ze.target.value),e[141]=at):at=e[141];let nt;e[142]!==n?(nt=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=nt):nt=e[143];let dt;e[144]!==ue?(dt=ze=>{ze.key==="Enter"&&ue()},e[144]=ue,e[145]=dt):dt=e[145];let xt;e[146]!==l||e[147]!==nt||e[148]!==dt?(xt=s.jsx(Je,{value:l,onChange:at,placeholder:nt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:dt}),e[146]=l,e[147]=nt,e[148]=dt,e[149]=xt):xt=e[149];let G;e[150]===Symbol.for("react.memo_cache_sentinel")?(G=()=>r(null),e[150]=G):G=e[150];let Be;e[151]!==n?(Be=n("settings.common.actions.cancel"),e[151]=n,e[152]=Be):Be=e[152];let st;e[153]!==Be?(st=s.jsx(H,{size:"sm",variant:"ghost",onClick:G,children:Be}),e[153]=Be,e[154]=st):st=e[154];let rt;e[155]!==n?(rt=n("settings.common.actions.rename"),e[155]=n,e[156]=rt):rt=e[156];let ut;e[157]!==ue||e[158]!==rt?(ut=s.jsx(H,{size:"sm",onClick:ue,children:rt}),e[157]=ue,e[158]=rt,e[159]=ut):ut=e[159];let St;e[160]!==st||e[161]!==ut?(St=s.jsxs(ts,{children:[st,ut]}),e[160]=st,e[161]=ut,e[162]=St):St=e[162];let et;e[163]!==He||e[164]!==xt||e[165]!==St?(et=s.jsxs(zt,{children:[He,xt,St]}),e[163]=He,e[164]=xt,e[165]=St,e[166]=et):et=e[166];let Xe;e[167]!==pe||e[168]!==et?(Xe=s.jsx(Kt,{open:pe,onOpenChange:Ce,children:et}),e[167]=pe,e[168]=et,e[169]=Xe):Xe=e[169];let ht;return e[170]!==Oe||e[171]!==Le||e[172]!==oe||e[173]!==Ge||e[174]!==Xe?(ht=s.jsxs("div",{className:Oe,children:[Le,oe,Ge,Xe]}),e[170]=Oe,e[171]=Le,e[172]=oe,e[173]=Ge,e[174]=Xe,e[175]=ht):ht=e[175],ht},po=t=>{const e=gt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:p,onDuplicate:m,isMenuOpen:x,onMenuOpenChange:d}=t,{t:y}=it();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=$a(),e[0]=c):c=e[0];const N=c,[h,C]=o.useState(!1);let b;e[1]!==r||e[2]!==m||e[3]!==p||e[4]!==l||e[5]!==y?(b=Q=>s.jsxs(s.Fragment,{children:[p&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),p()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),y("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),m()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),y("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),y("settings.common.actions.reset")]}),r&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[1]=r,e[2]=m,e[3]=p,e[4]=l,e[5]=y,e[6]=b):b=e[6];const S=b,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let T;e[7]!==g?(T=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=T):T=e[8];let M;e[9]===Symbol.for("react.memo_cache_sentinel")?(M=N?void 0:Q=>{Q.preventDefault(),C(!0)},e[9]=M):M=e[9];let P;e[10]!==T?(P=s.jsx("div",{className:T,onContextMenu:M}),e[10]=T,e[11]=P):P=e[11];let k;e[12]!==a.name?(k=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=k):k=e[13];let f;e[14]!==a||e[15]!==y?(f=(a.scope||xa(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:xa(a)?y("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=y,e[16]=f):f=e[16];let w;e[17]!==k||e[18]!==f?(w=s.jsxs("div",{className:"flex items-center gap-2",children:[k,f]}),e[17]=k,e[18]=f,e[19]=w):w=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let A;e[22]!==i||e[23]!==F||e[24]!==w?(A=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[w,F]}),e[22]=i,e[23]=F,e[24]=w,e[25]=A):A=e[25];let I;e[26]!==d?(I=Q=>{Q&&C(!1),d(Q)},e[26]=d,e[27]=I):I=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=E):E=e[28];let B;e[29]!==S?(B=s.jsx(on,{align:"end",className:"w-fit min-w-20",children:S(cn)}),e[29]=S,e[30]=B):B=e[30];let _;e[31]!==x||e[32]!==I||e[33]!==B?(_=s.jsxs(ln,{open:x,onOpenChange:I,children:[E,B]}),e[31]=x,e[32]=I,e[33]=B,e[34]=_):_=e[34];let j;e[35]!==A||e[36]!==_?(j=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,_]}),e[35]=A,e[36]=_,e[37]=j):j=e[37];let V;e[38]!==j||e[39]!==P?(V=s.jsx(Zn,{render:P,children:j}),e[38]=j,e[39]=P,e[40]=V):V=e[40];let q;e[41]!==S?(q=s.jsx(Yn,{className:"w-fit min-w-20",children:S(Xn)}),e[41]=S,e[42]=q):q=e[42];let L;return e[43]!==h||e[44]!==V||e[45]!==q?(L=s.jsxs(ea,{open:h,onOpenChange:C,children:[V,q]}),e[43]=h,e[44]=V,e[45]=q,e[46]=L):L=e[46],L};function Lu(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Ou(t){return t.loadSkills}function Fu(t){return t.name}function Ku(t){return!xa(t)}function zu(t,e){return t.name.localeCompare(e.name)}function Uu(t,e){return t.name.localeCompare(e.name)}const _u=()=>{const{t}=it(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=ya(Ks(E=>({selectedCommandName:E.selectedCommandName,getCommandByName:E.getCommandByName,createCommand:E.createCommand,updateCommand:E.updateCommand,commandDraft:E.commandDraft,setCommandDraft:E.setCommandDraft}))),p=Us(),m=ya(E=>hl(E,p)),x=e?a(e,p):null,d=!!(r&&r.name===e&&!x),[y,c]=o.useState(""),[N,h]=o.useState("user"),[C,b]=o.useState(""),[S,g]=o.useState(""),[T,M]=o.useState(""),[P,k]=o.useState(""),[f,w]=o.useState(!1),F=o.useRef(null);o.useEffect(()=>{if(d&&r){const E=r.name||"",B=r.scope||"user",_=r.description||"",j=r.agent||"",V=r.model||"",q=r.template||"";c(E),h(B),b(_),g(j),M(V),k(q),F.current={draftName:E,draftScope:B,description:_,agent:j,model:V,template:q}}else if(x){const E=x.description||"",B=x.agent||"",_=x.model||"",j=x.template||"";b(E),g(B),M(_),k(j),F.current={draftName:"",draftScope:"user",description:E,agent:B,model:_,template:j}}},[x,d,e,m,r]);const A=o.useMemo(()=>{const E=F.current;return E?!!(d&&(y!==E.draftName||N!==E.draftScope)||C!==E.description||S!==E.agent||T!==E.model||P!==E.template):!1},[S,C,y,N,d,T,P]),I=async()=>{const E=d?y.trim().replace(/\s+/g,"-"):e?.trim();if(!E){D.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!P.trim()){D.error(t("settings.commands.page.toast.templateRequired"));return}if(d&&m.some(B=>B.name===E)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}w(!0);try{const B=S.trim(),_=T.trim(),j=P.trim(),V={name:E,description:C.trim()||void 0,agent:B===""?null:B,model:_===""?null:_,template:j,scope:d?N:void 0};let q;if(d?(q=await n(V,p),q&&l(null)):q=await i(E,V,p),q){const L=Wn.getState().changes.some(Q=>Q.scope==="commands"&&Q.id.startsWith(`commands:${E}:`));D.success(t(L?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(d?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(B){console.error("Error saving command:",B),D.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{w(!1)}};return e?s.jsxs(es,{title:d?t("settings.commands.page.title.new"):`/${e}`,description:t(d?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[d&&s.jsxs(Lt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Je,{value:y,onChange:E=>c(E.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(It,{value:N,onValueChange:E=>h(E),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(As,{value:C,onChange:E=>b(E.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(_e,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Lt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(xl,{agentName:S,onChange:E=>g(E),className:En})}),s.jsx(Lt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ka,{providerId:va(T)?.providerId??"",modelId:va(T)?.modelId??"",onChange:(E,B)=>{M(E&&B?`${E}/${B}`:"")},className:En})})]}),s.jsxs(_e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:P,onChange:E=>k(E.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:I,disabled:f||!A,size:"xs",className:"!font-normal",children:t(f?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},mo=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},go=t=>{const e=gt.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=ye("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},$u=t=>{const e=gt.c(124),{onItemSelect:a}=t,{t:n}=it(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:p,deleteMcp:m}=ba(Ks(Vu)),x=Us();let d;e[0]!==x?(d=W=>vl(W,x),e[0]=x,e[1]=d):d=e[1];const y=ba(d);let c;e[2]!==x?(c=W=>W.getStatusForDirectory(x),e[2]=x,e[3]=c):c=e[3];const N=Os(c),h=Os(Bu),C=Os(Hu),[b,S]=o.useState(null),[g,T]=o.useState(!1),[M,P]=o.useState(null),[k,f]=o.useState(null),[w,F]=o.useState(!1);let A;e[4]!==y?(A=y.filter(Gu),e[4]=y,e[5]=A):A=e[5];const I=A;let E;e[6]!==y?(E=y.filter(Wu),e[6]=y,e[7]=E):E=e[7];const B=E;let _,j;e[8]!==p||e[9]!==x?(_=()=>{p({directory:x})},j=[p,x],e[8]=p,e[9]=x,e[10]=_,e[11]=j):(_=e[10],j=e[11]),o.useEffect(_,j);let V;e[12]!==C||e[13]!==w||e[14]!==h||e[15]!==x?(V=()=>{if(w)return;F(!0);const W=new Promise(qu);Promise.all([h({directory:x,silent:!0}),W]).then(()=>{const ke=C(x);ke&&D.error(ke)}).finally(()=>{F(!1)})},e[12]=C,e[13]=w,e[14]=h,e[15]=x,e[16]=V):V=e[16];const q=V;let L;e[17]!==y||e[18]!==a||e[19]!==l||e[20]!==r?(L=()=>{let W="new-mcp-server",ke=1;for(;y.some(He=>He.name===W);)W=`new-mcp-server-${ke}`,ke++;l({name:W,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(W),a?.()},e[17]=y,e[18]=a,e[19]=l,e[20]=r,e[21]=L):L=e[21];const Q=L;let ne;e[22]!==m||e[23]!==b||e[24]!==x||e[25]!==n?(ne=async()=>{if(!b)return;T(!0);const W=await m(b.name,x);W.ok?W.reloadFailed?D.warning(W.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:W.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(W.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),S(null),T(!1)},e[22]=m,e[23]=b,e[24]=x,e[25]=n,e[26]=ne):ne=e[26];const z=ne;let re;e[27]!==n?(re=(W,ke)=>s.jsxs(ke,{onClick:Ae=>{Ae.stopPropagation(),S(W)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=re):re=e[28];const $=re;let U;e[29]===Symbol.for("react.memo_cache_sentinel")?(U=ye("flex h-full flex-col","bg-background"),e[29]=U):U=e[29];let K;e[30]!==n?(K=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=K):K=e[31];let O;e[32]!==K?(O=s.jsx("h2",{className:dn,children:K}),e[32]=K,e[33]=O):O=e[33];let Y;e[34]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=Y):Y=e[35];let X;e[36]!==n?(X=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=X):X=e[37];const ee=w&&"animate-spin";let ge;e[38]!==ee?(ge=ye("h-4 w-4",ee),e[38]=ee,e[39]=ge):ge=e[39];let de;e[40]!==ge?(de=s.jsx(R,{name:"refresh",className:ge}),e[40]=ge,e[41]=de):de=e[41];let xe;e[42]!==q||e[43]!==w||e[44]!==Y||e[45]!==X||e[46]!==de?(xe=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:w,onClick:q,"aria-label":Y,title:X,children:de}),e[42]=q,e[43]=w,e[44]=Y,e[45]=X,e[46]=de,e[47]=xe):xe=e[47];let ae;e[48]!==O||e[49]!==xe?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[O,xe]}),e[48]=O,e[49]=xe,e[50]=ae):ae=e[50];let te;e[51]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Ga,{className:"mb-3"}),e[51]=te):te=e[51];let ue;e[52]!==y.length||e[53]!==n?(ue=n("settings.mcp.sidebar.total",{count:y.length}),e[52]=y.length,e[53]=n,e[54]=ue):ue=e[54];let Ie;e[55]!==ue?(Ie=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ue}),e[55]=ue,e[56]=Ie):Ie=e[56];let Ne;e[57]!==n?(Ne=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Ne):Ne=e[58];let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Se):Se=e[59];let ve;e[60]!==Q||e[61]!==Ne?(ve=s.jsx(H,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:Ne,children:Se}),e[60]=Q,e[61]=Ne,e[62]=ve):ve=e[62];let Oe;e[63]!==Ie||e[64]!==ve?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ie,ve]}),e[63]=Ie,e[64]=ve,e[65]=Oe):Oe=e[65];let Le;e[66]!==ae||e[67]!==Oe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,te,Oe]}),e[66]=ae,e[67]=Oe,e[68]=Le):Le=e[68];let oe;e[69]!==y.length||e[70]!==N||e[71]!==a||e[72]!==M||e[73]!==I||e[74]!==$||e[75]!==k||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==B?(oe=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[I.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),I.map(W=>{const ke=N[W.name],Ae=mo(ke?.status),He=i===W.name,at=$a();return s.jsxs(ea,{open:k===W.name,onOpenChange:nt=>f(nt?W.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),f(W.name)}}),children:[s.jsxs("button",{onClick:()=>{r(W.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(go,{tone:Ae,enabled:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(ln,{open:M===W.name,onOpenChange:nt=>{nt&&f(null),P(nt?W.name:null)},children:[s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:$(W,cn)})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:$(W,Xn)})]},W.name)})]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.userServers")}),B.map(W=>{const ke=N[W.name],Ae=mo(ke?.status),He=i===W.name,at=$a();return s.jsxs(ea,{open:k===W.name,onOpenChange:nt=>f(nt?W.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),f(W.name)}}),children:[s.jsxs("button",{onClick:()=>{r(W.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(go,{tone:Ae,enabled:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(ln,{open:M===W.name,onOpenChange:nt=>{nt&&f(null),P(nt?W.name:null)},children:[s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:$(W,cn)})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:$(W,Xn)})]},W.name)})]})]})}),e[69]=y.length,e[70]=N,e[71]=a,e[72]=M,e[73]=I,e[74]=$,e[75]=k,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=B,e[81]=oe):oe=e[81];const he=b!==null;let Me;e[82]!==g?(Me=W=>{!W&&!g&&S(null)},e[82]=g,e[83]=Me):Me=e[83];let $e;e[84]!==n?($e=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=$e):$e=e[85];let Ve;e[86]!==$e?(Ve=s.jsx($t,{children:$e}),e[86]=$e,e[87]=Ve):Ve=e[87];const We=b?.name||"";let se;e[88]!==n||e[89]!==We?(se=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:We}),e[88]=n,e[89]=We,e[90]=se):se=e[90];let ie;e[91]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ie):ie=e[91];let je;e[92]!==se?(je=s.jsxs(Vt,{children:[se," ",ie,"."]}),e[92]=se,e[93]=je):je=e[93];let be;e[94]!==Ve||e[95]!==je?(be=s.jsxs(_t,{children:[Ve,je]}),e[94]=Ve,e[95]=je,e[96]=be):be=e[96];let Te;e[97]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>S(null),e[97]=Te):Te=e[97];let Ue;e[98]!==n?(Ue=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ue):Ue=e[99];let Pe;e[100]!==g||e[101]!==Ue?(Pe=s.jsx(H,{size:"sm",variant:"ghost",onClick:Te,disabled:g,children:Ue}),e[100]=g,e[101]=Ue,e[102]=Pe):Pe=e[102];let we;e[103]!==g||e[104]!==n?(we=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=we):we=e[105];let Ge;e[106]!==z||e[107]!==g||e[108]!==we?(Ge=s.jsx(H,{size:"sm",onClick:z,disabled:g,children:we}),e[106]=z,e[107]=g,e[108]=we,e[109]=Ge):Ge=e[109];let pe;e[110]!==Pe||e[111]!==Ge?(pe=s.jsxs(ts,{children:[Pe,Ge]}),e[110]=Pe,e[111]=Ge,e[112]=pe):pe=e[112];let Ce;e[113]!==be||e[114]!==pe?(Ce=s.jsxs(zt,{className:"max-w-md",children:[be,pe]}),e[113]=be,e[114]=pe,e[115]=Ce):Ce=e[115];let Re;e[116]!==he||e[117]!==Me||e[118]!==Ce?(Re=s.jsx(Kt,{open:he,onOpenChange:Me,children:Ce}),e[116]=he,e[117]=Me,e[118]=Ce,e[119]=Re):Re=e[119];let Ye;return e[120]!==Le||e[121]!==oe||e[122]!==Re?(Ye=s.jsxs("div",{className:U,children:[Le,oe,Re]}),e[120]=Le,e[121]=oe,e[122]=Re,e[123]=Ye):Ye=e[123],Ye};function Vu(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Bu(t){return t.refresh}function Hu(t){return t.getErrorForDirectory}function Gu(t){return t.scope==="project"}function Wu(t){return t.scope!=="project"}function qu(t){return setTimeout(t,500)}function sn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function oi(t,e,a){const n=Ju(a),i=typeof a.url=="string"?a.url.trim():"",r=fo(a,"env","environment"),l=fo(a,"headers"),p=Qu(a),m=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",x=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",d=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",c=Yu(a),N=Xu(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:p,oauthClientId:m,oauthClientSecret:x,oauthScope:d,oauthRedirectUri:y,timeout:c,enabled:N}}function Ju(t){const e=t.command,a=t.args;if(Pa(e)&&Pa(a))return[...e,...a];if(Pa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Pa(a)?[...n,...a]:n}return Pa(a)?a:[]}function fo(t,...e){for(const a of e){const n=t[a];if(!sn(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function Qu(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!sn(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function Yu(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function Xu(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Zu(t){const e=t.mcpServers;if(sn(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(sn(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&sn(i)});if(a.length===1){const n=a[0],i=t[n];if(Ul(i))return{name:n,entry:i}}return null}function Ul(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function ep(t,e){let a;try{const p=t.trim();if(!p)return Zs("No JSON content provided");a=JSON.parse(p)}catch(p){return Zs(p instanceof Error?`Invalid JSON: ${p.message}`:"Invalid JSON")}if(!sn(a))return Zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(sn(i)){const p=Object.keys(i);if(p.length===0)return Zs("mcpServers object is empty",a);if(p.length>1)return Zs("Paste one server at a time. Found "+p.length+" servers in mcpServers",a);const m=p[0],x=i[m];return sn(x)?oi(m,li(x),x):Zs("Server entry is not a valid object",a)}const r=n.mcp;if(sn(r)){const p=Object.keys(r);if(p.length===0)return Zs("mcp object is empty",a);if(p.length>1)return Zs("Paste one server at a time. Found "+p.length+" servers in mcp",a);const m=p[0],x=r[m];return sn(x)?oi(m,li(x),x):Zs("Server entry in mcp is not a valid object",a)}const l=Zu(n);if(l)return oi(l.name,li(l.entry),l.entry);if(Ul(n)){const p=li(n),m=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return oi(m,p,n)}return Zs("No recognizable MCP server configuration found in JSON",a)}function li(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function tp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function _l(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function sp(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:wc(a.searchParams),stateKey:yl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const np=t=>{const e=gt.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
|
|
4
|
+
`),e[0]=a,e[1]=l):l=e[1];const[p,m]=o.useState(l),x=o.useRef(a);let d,y;e[2]!==a?(d=()=>{JSON.stringify(x.current)!==JSON.stringify(a)&&(x.current=a,m(a.join(`
|
|
5
|
+
`)))},y=[a],e[2]=a,e[3]=d,e[4]=y):(d=e[3],y=e[4]),o.useEffect(d,y);let c;e[5]!==n||e[6]!==r?(c=k=>{const f=k.split(`
|
|
6
|
+
`).filter(up);if(r&&f.length===1&&/^https?:\/\/\S+$/i.test(f[0].trim())){r(f[0].trim());return}n(f)},e[5]=n,e[6]=r,e[7]=c):c=e[7];const N=c;let h;e[8]!==n?(h=k=>{const w=k.clipboardData.getData("text").trim();if(!w||w.includes(`
|
|
7
|
+
`)||!/\s/.test(w))return;const F=k.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;k.preventDefault();const A=_l(w);m(A.join(`
|
|
8
|
+
`)),n(A)},e[8]=n,e[9]=h):h=e[9];const C=h;let b;e[10]!==N?(b=k=>{m(k.target.value),N(k.target.value)},e[10]=N,e[11]=b):b=e[11];let S;e[12]!==N||e[13]!==p?(S=()=>{const k=p.split(`
|
|
9
|
+
`).map(pp).join(`
|
|
10
|
+
`);m(k),N(k)},e[12]=N,e[13]=p,e[14]=S):S=e[14];const g=Math.max(4,a.length+1);let T;e[15]!==C||e[16]!==b||e[17]!==S||e[18]!==g||e[19]!==p?(T=s.jsx(As,{onPaste:C,value:p,onChange:b,onBlur:S,placeholder:`npx
|
|
11
|
+
-y
|
|
12
|
+
@modelcontextprotocol/server-postgres
|
|
13
|
+
postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=b,e[17]=S,e[18]=g,e[19]=p,e[20]=T):T=e[20];let M;e[21]!==i||e[22]!==a?(M=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(mp)})})]}),e[21]=i,e[22]=a,e[23]=M):M=e[23];let P;return e[24]!==M||e[25]!==T?(P=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[T,M]}),e[24]=M,e[25]=T,e[26]=P):P=e[26],P},ap=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),ho=({value:t,onChange:e,keyTransform:a=ap,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:p,importSuccess:m,clipboardReadFailed:x,keyLabel:d,valueLabel:y,valuePlaceholder:c,hideValueTitle:N,showValueTitle:h,addVariable:C,plainTextWarning:b,removeVariableAria:S})=>{const[g,T]=o.useState(new Set),M=()=>e([...t,{key:"",value:""}]),P=A=>{e(t.filter((I,E)=>E!==A)),T(I=>{const E=new Set(I);return E.delete(A),E})},k=(A,I,E)=>{const B=[...t];B[A]={...B[A],[I]:E},e(B)},f=A=>{T(I=>{const E=new Set(I);return E.has(A)?E.delete(A):E.add(A),E})},w=async()=>{try{const A=await navigator.clipboard.readText(),I=[];for(const B of A.split(`
|
|
14
|
+
`)){const _=B.trim();if(!_||_.startsWith("#"))continue;const j=_.indexOf("=");if(j===-1)continue;const V=_.slice(0,j).trim();let q=_.slice(j+1).trim();(q.startsWith('"')&&q.endsWith('"')||q.startsWith("'")&&q.endsWith("'"))&&(q=q.slice(1,-1)),V&&I.push({key:V,value:q})}if(I.length===0){D.error(p);return}const E=[...t];for(const B of I){const _=E.findIndex(j=>j.key===B.key);_!==-1?E[_]=B:E.push(B)}e(E),D.success(m(I.length))}catch{D.error(x)}},F=t.some(A=>A.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:d}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:y})]}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:w,type:"button",title:l,children:[s.jsx(R,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((A,I)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:A.key,onChange:E=>k(I,"key",a(E.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Je,{type:g.has(I)?"text":"password",value:A.value,onChange:E=>k(I,"value",E.target.value),placeholder:c,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>f(I),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:g.has(I)?N:h,children:g.has(I)?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>P(I),"aria-label":S,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},I))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:M,type:"button",children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),C]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:b})]})},Ji=t=>{const e=gt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let p,m;if(e[0]!==i||e[1]!==a||e[2]!==l){m=Symbol.for("react.early_return_sentinel");e:{const c={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const N=ye("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let h;e[5]!==i||e[6]!==a?(h=i(a),e[5]=i,e[6]=a,e[7]=h):h=e[7],m=s.jsxs("span",{className:N,children:["● ",h]});break e}p=ye("typography-micro font-medium",c.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=p,e[4]=m}else p=e[3],m=e[4];if(m!==Symbol.for("react.early_return_sentinel"))return m;let x;e[8]!==i||e[9]!==a?(x=i(a),e[8]=i,e[9]=a,e[10]=x):x=e[10];let d;return e[11]!==p||e[12]!==x?(d=s.jsxs("span",{className:p,children:["● ",x]}),e[11]=p,e[12]=x,e[13]=d):d=e[13],d},ip=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},rp=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},op=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),lp=async t=>{const e=await mt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},Aa=async t=>{typeof t!="string"||!t.trim()||await mt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},ci=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},cp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},dp=()=>{const{t}=it(),e=o.useCallback((ce,pt)=>t(ce,pt),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:p,updateMcp:m,deleteMcp:x}=ba(Ks(ce=>({selectedMcpName:ce.selectedMcpName,mcpDraft:ce.mcpDraft,setMcpDraft:ce.setMcpDraft,setSelectedMcp:ce.setSelectedMcp,getMcpByName:ce.getMcpByName,createMcp:ce.createMcp,updateMcp:ce.updateMcp,deleteMcp:ce.deleteMcp}))),d=Us(),y=o.useMemo(()=>cs(),[]),c=Os(ce=>ce.getStatusForDirectory(d)),N=Os(ce=>ce.getDiagnosticForDirectory(d)),h=Os(ce=>ce.refresh),C=Os(ce=>ce.connect),b=Os(ce=>ce.disconnect),S=Os(ce=>ce.completeAuth),g=Os(ce=>ce.clearAuth),T=Os(ce=>ce.testConnection),M=Wn(ce=>ce.changes),P=ba(ce=>vl(ce,d)),k=a?l(a,d):null,f=!!(n&&n.name===a&&!k),[w,F]=o.useState(""),[A,I]=o.useState("user"),[E,B]=o.useState("local"),[_,j]=o.useState([]),[V,q]=o.useState(""),[L,Q]=o.useState([]),[ne,z]=o.useState([]),[re,$]=o.useState(!0),[U,K]=o.useState(""),[O,Y]=o.useState(""),[X,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(""),[te,ue]=o.useState(!0),[Ie,Ne]=o.useState(!1),[Se,ve]=o.useState(!1),[Oe,Le]=o.useState(!1),[oe,he]=o.useState(!1),[Me,$e]=o.useState(!1),[Ve,We]=o.useState(!1),[se,ie]=o.useState(!1),[je,be]=o.useState(!1),[Te,Ue]=o.useState(null),[Pe,we]=o.useState(null),[Ge,pe]=o.useState(""),[Ce,Re]=o.useState(!1),Ye=o.useRef(0),W=o.useRef(!1),[ke,Ae]=o.useState(!1),[He,at]=o.useState(!1),[nt,dt]=o.useState(""),[xt,G]=o.useState(null),Be=o.useMemo(()=>cp(a,d),[d,a]),st=o.useRef(Be),rt=o.useRef(null),ut=o.useCallback(()=>{Ue(null),we(null),pe(""),Re(!1),Ye.current=0,be(!1),$e(!1),We(!1),W.current=!1},[]),St=o.useCallback(()=>{dt(""),G(null),at(!0)},[]),et=o.useCallback(async()=>{try{const ce=await navigator.clipboard.readText();dt(ce),G(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Xe=o.useCallback(()=>{const ce=ep(nt,{fallbackName:w});if(!ce.ok){G(ce.error);return}const bt=tp(ce,{name:w,scope:A,type:E,command:_,url:V,environment:L,headers:ne,oauthEnabled:re,oauthClientId:U,oauthClientSecret:O,oauthScope:X,oauthRedirectUri:ge,timeout:xe,enabled:te},{isNewServer:f});F(bt.name),B(bt.type),j(bt.command??[]),q(bt.url??""),Q(bt.environment??[]),z(bt.headers??[]),$(bt.oauthEnabled??!1),K(bt.oauthClientId??""),Y(bt.oauthClientSecret??""),ee(bt.oauthScope??""),de(bt.oauthRedirectUri??""),ae(bt.timeout??""),ue(bt.enabled??!0),at(!1),dt(""),G(null),D.success(t("settings.mcp.page.toast.configImported"))},[nt,w,A,E,_,V,L,ne,re,U,O,X,ge,xe,te,f,t]);o.useEffect(()=>{if(f&&n){F(n.name),I(n.scope||"user"),B(n.type),j(n.command),q(n.url),Q(n.environment),z(n.headers),$(n.oauthEnabled),K(n.oauthClientId),Y(n.oauthClientSecret),ee(n.oauthScope),de(n.oauthRedirectUri),ae(n.timeout),ue(n.enabled),Ae(!1),rt.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(k){I(k.scope==="project"?"project":"user");const ce=Lr(k.environment),pt=k.type==="remote"?k:null,bt=Lr(pt?.headers),Qt=pt?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Bt=Qt!==!1,rs=k.type,bs=rs==="local"?k.command??[]:[],ss=rs==="remote"?k.url??"":"",Nt=typeof pt?.timeout=="number"&&Number.isFinite(pt.timeout)?String(pt.timeout):"";B(rs),j(bs),q(ss),Q(ce),z(bt),$(Bt),K(Bt?Yt?.clientId??"":""),Y(Bt?Yt?.clientSecret??"":""),ee(Bt?Yt?.scope??"":""),de(Bt?Yt?.redirectUri??"":""),ae(Nt),ue(k.enabled),Ae(!1),rt.current={mcpType:rs,command:bs,url:ss,envEntries:ce,headerEntries:bt,oauthEnabled:Bt,oauthClientId:Bt?Yt?.clientId??"":"",oauthClientSecret:Bt?Yt?.clientSecret??"":"",oauthScope:Bt?Yt?.scope??"":"",oauthRedirectUri:Bt?Yt?.redirectUri??"":"",timeout:Nt,enabled:k.enabled}}},[k,f,n]);const ht=o.useMemo(()=>{const ce=rt.current;return ce?E!==ce.mcpType||te!==ce.enabled||JSON.stringify(_)!==JSON.stringify(ce.command)||V!==ce.url||JSON.stringify(L)!==JSON.stringify(ce.envEntries)||JSON.stringify(ne)!==JSON.stringify(ce.headerEntries)||re!==ce.oauthEnabled||U!==ce.oauthClientId||O!==ce.oauthClientSecret||X!==ce.oauthScope||ge!==ce.oauthRedirectUri||xe!==ce.timeout:!1},[E,_,V,L,ne,re,U,O,X,ge,xe,te]),ze=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(R,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(R,{name:"global",className:"h-3.5 w-3.5"})}],[t]),jt=o.useCallback(ce=>{B("remote"),q(ce),j([])},[]),Ee=o.useCallback(ce=>{q(ce);const pt=ce.trim();pt&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(pt)&&/\s/.test(pt)&&(B("local"),j(_l(pt)),q(""))},[]),wt=async()=>{const ce=f?w.trim():a??"";if(!ce){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(f&&P.some(bt=>bt.name===ce)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(E==="local"&&_.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(E==="remote"&&!V.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const pt={name:ce,scope:A,type:E,command:_,url:V,environment:L,headers:ne,oauthEnabled:re,oauthClientId:U,oauthClientSecret:O,oauthScope:X,oauthRedirectUri:ge,timeout:xe,enabled:te};Ne(!0);try{const bt=f?await p(pt,d):await m(ce,pt,d);bt.ok?(await Aa(Pe),ut(),f&&(i(null),r(ce)),await h({directory:d,silent:!0}),bt.reloadFailed?D.warning(bt.message||t(f?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:bt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):bt.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(bt.message||t(f?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(bt){D.error(bt instanceof Error?bt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ne(!1)}},J=async()=>{if(!a)return;Le(!0);const ce=await x(a,d);ce.ok?(await Aa(Pe),ut(),ce.reloadFailed?D.warning(ce.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:ce.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(ce.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),ve(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Le(!1)},fe=async()=>{if(a){he(!0);try{if(c[a]?.status==="connected")await b(a,d),D.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,d),await h({directory:d,silent:!0});const pt=Os.getState().getStatusForDirectory(d)[a];pt?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):pt?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):pt?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):pt?.status==="failed"?D.error(pt.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await h({directory:d,silent:!0})}catch(ce){D.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionFailed"))}finally{he(!1)}}},Fe=o.useCallback(()=>f?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ht?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ht,f,t]),De=o.useCallback(async(ce=!1)=>{try{await h({directory:d,silent:ce})}catch(pt){ce||D.error(pt instanceof Error?pt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,h,t]);o.useEffect(()=>{De(!0)},[De]),o.useEffect(()=>{st.current=Be,he(!1),ie(!1),ut()},[ut,Be]);const lt=o.useCallback(async()=>{if(!a||E!=="remote"||!Fe())return;$e(!0);const ce=Be;let pt=null;try{const bt=Os.getState().getStatusForDirectory(d)[a]?.status;W.current=bt==="needs_auth"||bt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Bt,completion:rs}=await yc({name:a,directory:d});if(Bt){if(st.current!==ce)return;Ue(null),we(null),Re(!0),Ye.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),rs?.then(()=>{st.current===ce&&(Re(!1),Ye.current=0,W.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ss=>{st.current===ce&&(Re(!1),Ye.current=0,W.current=!1,D.error(ci(ss,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const bs=yl(new URL(Qt).searchParams);if(pt=bs,st.current!==ce||(Ue(Qt),we(bs??null),Re(!0),Ye.current=0,st.current!==ce))return;Yt?D.message(t(y?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(bt){await Aa(pt),st.current===ce&&D.error(ci(bt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{st.current===ce&&$e(!1)}},[d,y,E,Fe,Be,a,t,e]),ct=o.useCallback(async()=>{if(!a||!Fe())return;We(!0);const ce=Be;try{if(await g(a,d),st.current!==ce)return;Ue(null),we(null),pe(""),Re(!1),Ye.current=0,await Aa(Pe),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(pt){st.current===ce&&D.error(ci(pt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{st.current===ce&&We(!1)}},[Pe,g,d,Fe,Be,a,t,e]),Qe=o.useCallback(async()=>{if(!Te)return;if((await za(Te)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Te,t]),kt=o.useCallback(async()=>{const ce=sp(Ge);if(!ce.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const pt=ce.stateKey?await lp(ce.stateKey):null,bt=ce.context??pt,Qt=bt?.name??a,Yt=bt?.directory??d;if(!Qt){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!bt&&!Fe())return;be(!0);const Bt=Be;try{if(await S(Qt,ce.code,Yt),await Aa(ce.stateKey??Pe),st.current!==Bt)return;pe(""),Ue(null),we(null),Re(!1),Ye.current=0,D.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(rs){st.current===Bt&&D.error(ci(rs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{st.current===Bt&&be(!1)}},[Ge,Pe,S,d,Fe,Be,a,t,e]),vs=o.useCallback(async()=>{if(!(!a||!Fe())){if(!te){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ie(!0);try{const ce=await T(a,d),pt=ce.status?.status;ce.warning?D.warning(ce.warning):pt==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):pt==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):pt==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):pt==="failed"?D.error(ce.status?.error||ce.error||t("settings.mcp.page.toast.connectionTestFailed")):ce.error?D.error(ce.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(ce){D.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ie(!1)}}},[d,te,Fe,a,t,T]);if(o.useEffect(()=>{if(!Ce||!a)return;const ce=window.setInterval(()=>{(async()=>{Ye.current+=1,await h({directory:d,silent:!0});const pt=Os.getState().getStatusForDirectory(d)[a];if(pt){if(W.current&&pt.status!=="needs_auth"&&pt.status!=="needs_client_registration"){Re(!1),Ye.current=0,W.current=!1,Ue(null),pe(""),pt.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!W.current&&pt.status==="failed"){Re(!1),Ye.current=0,W.current=!1,D.error(pt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ye.current>=30&&(Re(!1),Ye.current=0,W.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(ce)}},[d,Ce,h,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Xt=c[a],Ls=a?N[a]:void 0,Gt=Xt??Ls,is=!f&&!Gt&&M.some(ce=>ce.scope==="mcp"&&ce.id.startsWith(`mcp:${a}:`)),Ht=Xt?.status==="connected",ys=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",ms=y||!a?null:bc(a),gs=async()=>{if(ms)try{await navigator.clipboard.writeText(ms),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ds=ip(Gt?.status,e,Gt&&"error"in Gt?Gt.error:void 0),Ts=ce=>{switch(ce){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return ce}};return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:f?t("settings.mcp.page.header.newServer"):a,titleAccessory:f?void 0:s.jsx(Ji,{status:is?"awaiting_restart":Gt?.status,enabled:te,getStatusLabel:Ts,variant:"pill"}),description:f?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(E==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!f&&!is?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{variant:Ht?"outline":"default",size:"xs",className:"!font-normal",onClick:fe,disabled:oe||!te,children:t(oe?"settings.mcp.page.actions.working":Ht?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),E==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:ys?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{lt()},disabled:Me||!te,children:t(Me?"settings.mcp.page.actions.starting":Ht?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ct()},disabled:Ve||!te,children:t(Ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Ht&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{vs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[is&&s.jsx(_e,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ji,{status:"awaiting_restart",enabled:te,getStatusLabel:Ts})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!f&&!is&&op(Gt?.status,Te,ys,Ce)&&s.jsx(_e,{divider:!1,children:s.jsxs("div",{className:ye("rounded-lg border p-3",rp(Gt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ji,{status:Gt?.status,enabled:te,getStatusLabel:Ts})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ds}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:A==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:d??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ht&&s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{vs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Gt?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(Ys,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),ms&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:ms}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{gs()},children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Je,{value:U,onChange:ce=>{K(ce.target.value),$(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(qt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Je,{type:"password",value:O,onChange:ce=>{Y(ce.target.value),$(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Te&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Te}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(Te)},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qe()},children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),y&&E==="remote"&&(ys||Ce||Te)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(Ys,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(As,{value:Ge,onChange:ce=>pe(ce.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:je,children:t(je?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ce&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(_e,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:f?s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:St,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(R,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[f&&s.jsxs(Lt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Je,{value:w,onChange:ce=>F(ce.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(It,{value:A,onValueChange:ce=>I(ce),children:[s.jsxs(Pt,{size:Ft,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(R,{name:A==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(A==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(ft,{checked:te,onChange:ue,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(_e,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Sr,{items:ze,activeId:E,onSelect:ce=>B(ce),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),E==="local"?s.jsx(np,{value:_,onChange:j,preview:ce=>t("settings.mcp.page.connection.previewArgs",{count:ce}),onDetectUrl:jt}):s.jsx(Je,{value:V,onChange:ce=>Ee(ce.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(E==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),E==="remote"&&s.jsx(_e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Mn,{open:ke,onOpenChange:Ae,children:[s.jsxs(Rn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",ne.length," ",t("settings.mcp.page.advanced.headers"),xe?` · ${xe}ms`:"",")"]})]}),ke?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Je,{type:"number",min:"1",step:"1",value:xe,onChange:ce=>ae(ce.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(Ys,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ne.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ne.length,")"]})]}),s.jsx(ho,{value:ne,onChange:z,keyTransform:ce=>ce.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(_e,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:L.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]}):null,settingsItem:"mcp.environment",children:L.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(ho,{value:L,onChange:Q,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(H,{onClick:wt,disabled:Ie||!ht&&!f,size:"xs",className:"!font-normal",children:t(Ie?"settings.common.actions.saving":f?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!f&&s.jsx(H,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ve(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:He,onOpenChange:ce=>{ce||(at(!1),dt(""),G(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Vt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:nt,onChange:ce=>{dt(ce.target.value),G(null)},placeholder:`{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"postgres": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),xt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:xt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:et,type:"button",children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"outline",onClick:()=>{at(!1),dt(""),G(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{onClick:Xe,disabled:!nt.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:Se,onOpenChange:ce=>{!ce&&!Oe&&ve(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Vt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"outline",onClick:()=>ve(!1),disabled:Oe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:J,disabled:Oe,children:t(Oe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function up(t){return t.trim().length>0}function pp(t){return t.trimEnd()}function mp(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const yi=()=>{try{const e=Bs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=hn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},gp=800,fp=5e3,hp="__default__",ur=new Map,Qi=new Map,xp=1500,$l=t=>t?.trim()||hp,vp=t=>{ur.delete($l(t))},ps=Ll()(qd(Jd((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=yi(),i=$l(n),r=Date.now(),l=ur.get(i)??0,p=e().entries.length>0||e().files.length>0;if(!a?.force&&p&&r-l<fp)return!0;const m=Qi.get(i);if(!a?.force&&m)return m;const x=(async()=>{t({isLoading:!0});try{const d=await mt(In("/api/config/plugins",n),{headers:Ta(n)});if(!d.ok)throw new Error("Failed to load plugins");const y=await bi(d);return t({entries:y.entries??[],files:y.files??[],isLoading:!1}),ur.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();Qi.set(i,x);try{return await x}finally{Qi.delete(i)}},loadRegistryInfo:async a=>{const n=bp(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=yi(),r={...e().registryInfo};for(const l of wp(n)){const p=await mt(yp(l,a?.force===!0,i),{headers:Ta(i)});if(!p.ok)throw new Error("Failed to load plugin registry info");const m=await bi(p);for(const x of m.results??[])r[x.spec]=x}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await ga("Creating plugin entry…",async i=>await mt(In("/api/config/plugins/entry",i),{method:"POST",headers:di(i),body:JSON.stringify(xo(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(p=>p.id===a)?.spec,r=n.spec??i,l=await ga("Updating plugin entry…",async p=>await mt(In(`/api/config/plugins/entry/${encodeURIComponent(a)}`,p),{method:"PATCH",headers:di(p),body:JSON.stringify(xo(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await ga("Deleting plugin entry…",async r=>await mt(In(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Ta(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=yi(),i=await mt(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ta(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await bi(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>ga("Creating plugin file…",async n=>await mt(In("/api/config/plugins/file",n),{method:"POST",headers:di(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>ga("Updating plugin file…",async i=>await mt(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:di(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await ga("Deleting plugin file…",async i=>await mt(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Ta(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:md(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function In(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function yp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function bp(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function wp(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>xp?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Ta(t){return t?{"x-opencode-directory":t}:void 0}function di(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function xo(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function ga(t,e,a,n){try{const i=yi(),r=await e(i),l=await bi(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return vp(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):fl(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(jc(t),await kc({message:l.message,delayMs:l.reloadDelayMs??gp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function bi(t){return await t.json()}const jp=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function kp(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const Np=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=it(),i=ps(j=>j.createEntry),r=ps(j=>j.createFile),[l,p]=o.useState("npm"),[m,x]=o.useState(""),[d,y]=o.useState(""),[c,N]=o.useState(""),[h,C]=o.useState(""),[b,S]=o.useState(a),[g,T]=o.useState(!1),M=o.useCallback(()=>{x(""),y(""),N(""),C(""),S(a)},[a]);o.useEffect(()=>{t&&(p("npm"),M())},[t,M]);const P=j=>{j!==l&&(p(j),M())},k=o.useMemo(()=>kp(d),[d]),f=!k.ok,w=l==="file"&&c.trim()!==""&&!jp.test(c.trim()),F=(l==="npm"||l==="path")&&m.trim()==="",A=l==="file"&&h.trim()==="",I=l==="file"&&c.trim()==="",E=g||f||l==="npm"&&F||l==="path"&&F||l==="file"&&(I||w||A),B=async()=>{if(!E){T(!0);try{let j;l==="file"?j=await r({fileName:c.trim(),content:h,scope:b}):j=await i({spec:m.trim(),options:k.ok?k.value:void 0,scope:b}),j.ok?(j.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(j.message||n("settings.plugins.toast.created")),j.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(j.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{T(!1)}}},_=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Kt,{open:t,onOpenChange:j=>{!j&&g||e(j)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Sr,{items:_,activeId:l,onSelect:j=>P(j),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(Je,{id:"plugin-spec",value:m,onChange:j=>x(j.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:g}),F&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(As,{id:"plugin-options",value:d,onChange:j=>y(j.target.value),rows:5,className:"font-mono",hasError:f,disabled:g}),f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(Je,{id:"plugin-filename",value:c,onChange:j=>N(j.target.value),placeholder:"my-plugin.ts","aria-invalid":w||void 0,disabled:g}),w&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(As,{id:"plugin-content",value:h,onChange:j=>C(j.target.value),rows:16,className:"font-mono",disabled:g})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(j=>{const V=b===j,q=n(j==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>S(j),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(br,{checked:V,onChange:()=>S(j),ariaLabel:q}),s.jsx("span",{className:ye("typography-ui-label font-normal",V?"text-foreground":"text-foreground/60"),children:q})]},j)})})]})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{B()},disabled:E,children:[g?s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Sp=t=>{const e=gt.c(33),{spec:a}=t;let n;e[0]!==a?(n=p=>p.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=ps(n),{t:r}=it();if(!i)return null;const l=Cp;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=p):p=e[2];let m;e[3]!==i.latestVersion?(m=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[p,i.latestVersion]}),e[3]=i.latestVersion,e[4]=m):m=e[4];let x;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==m?(x=l(m,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=m,e[9]=x):x=e[9],x}case"npm-missing-version":{let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=p):p=e[10];let m;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(m=l(p,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=m):m=e[14],m}case"npm-missing-package":{let p;e[15]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=p):p=e[15];let m;return e[16]!==i.name||e[17]!==r?(m=l(p,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=m):m=e[18],m}case"npm-malformed":{let p;e[19]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=p):p=e[19];let m;return e[20]!==r?(m=l(p,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=m):m=e[21],m}case"npm-network":{let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=p):p=e[22];let m;return e[23]!==r?(m=l(p,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=m):m=e[24],m}case"path-missing":{let p;e[25]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=p):p=e[25];let m;return e[26]!==i.absolutePath||e[27]!==r?(m=l(p,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=m):m=e[28],m}case"path-unreadable":{let p;e[29]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=p):p=e[29];let m;return e[30]!==i.absolutePath||e[31]!==r?(m=l(p,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=m):m=e[32],m}case"path-ok":return null;default:return null}};function Cp(t,e){return s.jsxs(wr,{children:[s.jsx(jr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(bl,{children:e})]})}const Vl=t=>{const e=gt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,p=l===void 0?"sidebar":l,m=cs(),x=o.useRef(null),[d,y]=o.useState(!1),[c,N]=o.useState(!1),h=p==="background"||m?"bg-background":"bg-sidebar",C=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const E=x.current;if(!E){y(!1),N(!1);return}if(!(E.scrollHeight>E.clientHeight+1)){y(!1),N(!1);return}y(E.scrollTop>1),N(E.scrollTop+E.clientHeight<E.scrollHeight-1)},e[0]=b):b=e[0];const S=b;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{S()},e[1]=g):g=e[1];let T;e[2]!==i?(T=[i,S],e[2]=i,e[3]=T):T=e[3],o.useEffect(g,T);let M,P;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const E=x.current;if(!E)return;const B=()=>S();return E.addEventListener("scroll",B,{passive:!0}),()=>E.removeEventListener("scroll",B)},P=[S],e[4]=M,e[5]=P):(M=e[4],P=e[5]),o.useEffect(M,P);let k;e[6]!==h||e[7]!==r?(k=ye("flex h-full flex-col",h,r),e[6]=h,e[7]=r,e[8]=k):k=e[8];let f;e[9]!==i?(f=s.jsx(Hs,{ref:x,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=f):f=e[10];let w;e[11]!==C||e[12]!==d?(w=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=d,e[13]=w):w=e[13];let F;e[14]!==C||e[15]!==c?(F=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=c,e[16]=F):F=e[16];let A;e[17]!==F||e[18]!==f||e[19]!==w?(A=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[f,w,F]}),e[17]=F,e[18]=f,e[19]=w,e[20]=A):A=e[20];let I;return e[21]!==n||e[22]!==a||e[23]!==A||e[24]!==k?(I=s.jsxs("div",{className:k,children:[a,A,n]}),e[21]=n,e[22]=a,e[23]=A,e[24]=k,e[25]=I):I=e[25],I},pr=t=>{const e=gt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:p,className:m}=t,x=i===void 0?!1:i,d=p&&p.length>0,y=x?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==m||e[1]!==y?(c=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",y,m),e[0]=m,e[1]=y,e[2]=c):c=e[2];let N;e[3]!==a?(N=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=N):N=e[4];let h;e[5]!==l||e[6]!==N?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,N]}),e[5]=l,e[6]=N,e[7]=h):h=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let b;e[10]!==r||e[11]!==h||e[12]!==C?(b=s.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[h,C]}),e[10]=r,e[11]=h,e[12]=C,e[13]=b):b=e[13];let S;e[14]!==p||e[15]!==d?(S=d&&s.jsxs(ln,{children:[s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:p.map(Ip)})]}),e[14]=p,e[15]=d,e[16]=S):S=e[16];let g;e[17]!==b||e[18]!==S?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,S]}),e[17]=b,e[18]=S,e[19]=g):g=e[19];let T;return e[20]!==c||e[21]!==g?(T=s.jsx("div",{className:c,children:g}),e[20]=c,e[21]=g,e[22]=T):T=e[22],T};function Ip(t){const e=t.icon;return s.jsxs(cn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(R,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Pp=t=>t.parsedKind==="npm"?"code-box":"folder",Ap=t=>{const e=gt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=it(),{entries:r,files:l,selectedId:p,setSelected:m,deleteEntry:x,deleteFile:d,loadPlugins:y}=ps(Ks(Tp)),c=ps(Ep),N=ps(Dp),h=ps(Mp),C=ps(Rp),[b,S]=o.useState(null),[g,T]=o.useState(!1),[M,P]=o.useState(!1);let k,f;e[0]!==y?(k=()=>{y()},f=[y],e[0]=y,e[1]=k,e[2]=f):(k=e[1],f=e[2]),o.useEffect(k,f);let w,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const et=()=>P(!0);return window.addEventListener("aiworker:settings-open-plugin-add",et),()=>window.removeEventListener("aiworker:settings-open-plugin-add",et)},F=[],e[3]=w,e[4]=F):(w=e[3],F=e[4]),o.useEffect(w,F);let A;if(e[5]!==r||e[6]!==c){A={userEntries:0,projectEntries:0};for(const et of r){const Xe=c[et.spec];Xe?.kind==="npm-ok"&&Xe.hasUpdate&&(et.scope==="user"?A.userEntries=A.userEntries+1:et.scope==="project"&&(A.projectEntries=A.projectEntries+1))}e[5]=r,e[6]=c,e[7]=A}else A=e[7];const I=A;let E;e[8]!==r?(E=r.filter(Lp),e[8]=r,e[9]=E):E=e[9];const B=E;let _;e[10]!==r?(_=r.filter(Op),e[10]=r,e[11]=_):_=e[11];const j=_;let V;e[12]!==l?(V=l.filter(Fp),e[12]=l,e[13]=V):V=e[13];const q=V;let L;e[14]!==l?(L=l.filter(Kp),e[14]=l,e[15]=L):L=e[15];const Q=L,ne=r.length+l.length,z=ne===0;let re;e[16]!==n?(re=()=>{n?n():P(!0)},e[16]=n,e[17]=re):re=e[17];const $=re;let U;e[18]!==a||e[19]!==m?(U=et=>{m(et),a?.()},e[18]=a,e[19]=m,e[20]=U):U=e[20];const K=U;let O;e[21]!==r||e[22]!==c||e[23]!==i||e[24]!==C?(O=async et=>{const Xe=r.find(Ee=>Ee.id===et);if(!Xe)return;const ht=c[Xe.spec];if(!ht||ht.kind!=="npm-ok"||!ht.hasUpdate||!ht.latestVersion)return;const ze=ht.latestVersion;(await C(et)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:ze})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=c,e[23]=i,e[24]=C,e[25]=O):O=e[25];const Y=O;let X;e[26]!==h||e[27]!==i?(X=async()=>{D.info(i("settings.plugins.toast.refreshing"));try{await h({force:!0})}catch{D.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=h,e[27]=i,e[28]=X):X=e[28];const ee=X;let ge;e[29]!==x||e[30]!==d||e[31]!==b||e[32]!==i?(ge=async()=>{if(!b)return;T(!0);const et=b.kind==="entry"?await x(b.id):await d(b.id);et.ok?D.success(et.message||i("settings.plugins.sidebar.toast.deleted",{name:b.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),S(null),T(!1)},e[29]=x,e[30]=d,e[31]=b,e[32]=i,e[33]=ge):ge=e[33];const de=ge;let xe;e[34]!==K||e[35]!==Y||e[36]!==c||e[37]!==p||e[38]!==i?(xe=et=>{const Xe=c[et.spec],ht=Xe?.kind==="npm-ok"&&Xe.hasUpdate&&!!Xe.latestVersion,ze=[];return ht&&ze.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Y(et.id)}}),ze.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"entry",id:et.id,label:et.spec})}),s.jsx(pr,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:et.spec}),s.jsx(Sp,{spec:et.spec})]}),metadata:et.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:p===et.id,onSelect:()=>K(et.id),icon:s.jsx(R,{name:Pp(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:ze},et.id)},e[34]=K,e[35]=Y,e[36]=c,e[37]=p,e[38]=i,e[39]=xe):xe=e[39];const ae=xe;let te;e[40]!==K||e[41]!==p||e[42]!==i?(te=et=>s.jsx(pr,{title:et.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:p===et.id,onSelect:()=>K(et.id),icon:s.jsx(R,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"file",id:et.id,label:et.fileName})}]},et.id),e[40]=K,e[41]=p,e[42]=i,e[43]=te):te=e[43];const ue=te;let Ie;e[44]!==i?(Ie=(et,Xe,ht)=>{const ze=ht===void 0?0:ht;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[et,ze>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(ze===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:ze})})]}),Xe]})},e[44]=i,e[45]=Ie):Ie=e[45];const Ne=Ie;let Se;e[46]!==i?(Se=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Se):Se=e[47];let ve;e[48]!==Se?(ve=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:dn,children:Se})}),e[48]=Se,e[49]=ve):ve=e[49];let Oe;e[50]!==i||e[51]!==ne?(Oe=i("settings.plugins.sidebar.total",{count:ne}),e[50]=i,e[51]=ne,e[52]=Oe):Oe=e[52];let Le;e[53]!==Oe?(Le=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Oe}),e[53]=Oe,e[54]=Le):Le=e[54];let oe;e[55]!==ee?(oe=()=>{ee()},e[55]=ee,e[56]=oe):oe=e[56];let he;e[57]!==i?(he=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=he):he=e[58];let Me;e[59]!==i?(Me=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Me):Me=e[60];const $e=N?"size-4 animate-spin":"size-4";let Ve;e[61]!==$e?(Ve=s.jsx(R,{name:"refresh",className:$e}),e[61]=$e,e[62]=Ve):Ve=e[62];let We;e[63]!==N||e[64]!==oe||e[65]!==he||e[66]!==Me||e[67]!==Ve?(We=s.jsx(H,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:oe,disabled:N,"aria-label":he,title:Me,children:Ve}),e[63]=N,e[64]=oe,e[65]=he,e[66]=Me,e[67]=Ve,e[68]=We):We=e[68];let se;e[69]!==i?(se=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=se):se=e[70];let ie;e[71]!==i?(ie=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=ie):ie=e[72];let je;e[73]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx(R,{name:"add",className:"size-4"}),e[73]=je):je=e[73];let be;e[74]!==$||e[75]!==se||e[76]!==ie?(be=s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:$,"aria-label":se,title:ie,children:je}),e[74]=$,e[75]=se,e[76]=ie,e[77]=be):be=e[77];let Te;e[78]!==We||e[79]!==be?(Te=s.jsxs("div",{className:"flex items-center gap-1",children:[We,be]}),e[78]=We,e[79]=be,e[80]=Te):Te=e[80];let Ue;e[81]!==Le||e[82]!==Te?(Ue=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Le,Te]}),e[81]=Le,e[82]=Te,e[83]=Ue):Ue=e[83];let Pe;e[84]!==ve||e[85]!==Ue?(Pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,Ue]}),e[84]=ve,e[85]=Ue,e[86]=Pe):Pe=e[86];let we;e[87]!==z||e[88]!==j||e[89]!==Q||e[90]!==ae||e[91]!==ue||e[92]!==Ne||e[93]!==i||e[94]!==I||e[95]!==B||e[96]!==q?(we=z?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[B.length>0&&Ne(i("settings.plugins.sidebar.group.userEntries"),B.map(ae),I.userEntries),q.length>0&&Ne(i("settings.plugins.sidebar.group.userFiles"),q.map(ue)),j.length>0&&Ne(i("settings.plugins.sidebar.group.projectEntries"),j.map(ae),I.projectEntries),Q.length>0&&Ne(i("settings.plugins.sidebar.group.projectFiles"),Q.map(ue))]}),e[87]=z,e[88]=j,e[89]=Q,e[90]=ae,e[91]=ue,e[92]=Ne,e[93]=i,e[94]=I,e[95]=B,e[96]=q,e[97]=we):we=e[97];let Ge;e[98]!==Pe||e[99]!==we?(Ge=s.jsx(Vl,{variant:"background",header:Pe,children:we}),e[98]=Pe,e[99]=we,e[100]=Ge):Ge=e[100];let pe;e[101]!==M?(pe=s.jsx(Np,{open:M,onOpenChange:P}),e[101]=M,e[102]=pe):pe=e[102];const Ce=b!==null;let Re;e[103]!==g?(Re=et=>{!et&&!g&&S(null)},e[103]=g,e[104]=Re):Re=e[104];let Ye;e[105]!==i?(Ye=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ye):Ye=e[106];let W;e[107]!==Ye?(W=s.jsx($t,{children:Ye}),e[107]=Ye,e[108]=W):W=e[108];const ke=b?.label??"";let Ae;e[109]!==i||e[110]!==ke?(Ae=i("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=i,e[110]=ke,e[111]=Ae):Ae=e[111];let He;e[112]!==Ae?(He=s.jsx(Vt,{children:Ae}),e[112]=Ae,e[113]=He):He=e[113];let at;e[114]!==W||e[115]!==He?(at=s.jsxs(_t,{children:[W,He]}),e[114]=W,e[115]=He,e[116]=at):at=e[116];let nt;e[117]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>S(null),e[117]=nt):nt=e[117];let dt;e[118]!==i?(dt=i("settings.common.actions.cancel"),e[118]=i,e[119]=dt):dt=e[119];let xt;e[120]!==g||e[121]!==dt?(xt=s.jsx(H,{size:"sm",variant:"ghost",onClick:nt,disabled:g,children:dt}),e[120]=g,e[121]=dt,e[122]=xt):xt=e[122];let G;e[123]!==g||e[124]!==i?(G=i(g?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=g,e[124]=i,e[125]=G):G=e[125];let Be;e[126]!==de||e[127]!==g||e[128]!==G?(Be=s.jsx(H,{size:"sm",variant:"destructive",onClick:de,disabled:g,children:G}),e[126]=de,e[127]=g,e[128]=G,e[129]=Be):Be=e[129];let st;e[130]!==xt||e[131]!==Be?(st=s.jsxs(ts,{children:[xt,Be]}),e[130]=xt,e[131]=Be,e[132]=st):st=e[132];let rt;e[133]!==at||e[134]!==st?(rt=s.jsxs(zt,{className:"max-w-md",children:[at,st]}),e[133]=at,e[134]=st,e[135]=rt):rt=e[135];let ut;e[136]!==Ce||e[137]!==Re||e[138]!==rt?(ut=s.jsx(Kt,{open:Ce,onOpenChange:Re,children:rt}),e[136]=Ce,e[137]=Re,e[138]=rt,e[139]=ut):ut=e[139];let St;return e[140]!==Ge||e[141]!==pe||e[142]!==ut?(St=s.jsxs(s.Fragment,{children:[Ge,pe,ut]}),e[140]=Ge,e[141]=pe,e[142]=ut,e[143]=St):St=e[143],St};function Tp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Ep(t){return t.registryInfo}function Dp(t){return t.isLoadingRegistry}function Mp(t){return t.loadRegistryInfo}function Rp(t){return t.updateToLatest}function Lp(t){return t.scope==="user"}function Op(t){return t.scope==="project"}function Fp(t){return t.scope==="user"}function Kp(t){return t.scope==="project"}const zp=({entryId:t,spec:e})=>{const{t:a}=it(),n=ps(y=>y.registryInfo[e]),i=ps(y=>y.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const y=n.latestVersion,c=n.currentVersion??"",N=async()=>{l(!0);try{(await i(t)).ok?D.success(a("settings.plugins.toast.updatedToLatest",{version:y})):D.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(R,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:c,latest:y})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{N()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:y})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(R,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const p=n.kind==="path-unreadable",m=p?"var(--status-warning)":"var(--status-error)",x=p?"alert":"error-warning",d=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(R,{name:x,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:m}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:m},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Up(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function Bl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function vo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Bl(t.options),fileName:"",content:""}}function yo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const bo=t=>{const e=gt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ye("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},_p=()=>{const{t}=it(),e=ps(b=>b.selectedId),a=ps(b=>b.entries),n=ps(b=>b.files),i=ps(b=>b.draft),r=ps(b=>b.setDraft),l=ps(b=>b.updateEntry),p=ps(b=>b.updateFile),m=ps(b=>b.readFile),x=o.useMemo(()=>e?a.find(b=>b.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(b=>b.id===e)??null:null,[n,e]),[y,c]=o.useState(!1),[N,h]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let b=!1;return x?(r(vo(x)),()=>{b=!0}):d?(h(!0),(async()=>{const S=await m(d.id);if(b)return;h(!1);const g=S?.content??"";C.current.set(d.id,g),r(yo(d,g))})(),()=>{b=!0}):(r(null),()=>{b=!0})},[x,d,m,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(x&&i&&i.mode==="entry"){const b=Up(i.optionsJson),S=b.ok,g=i.spec!==x.spec||i.optionsJson!==Bl(x.options),T=()=>{r(vo(x))},M=async()=>{if(!S)return;const P=i.spec.trim();if(!P){D.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const k=await l(x.id,{spec:P,options:b.value});k.ok?k.reloadFailed?D.warning(k.message||t("settings.plugins.toast.reloadFailed"),{description:k.warning}):k.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(k.message||t("settings.plugins.toast.updated")):D.error(k.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsxs(es,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(bo,{scope:x.scope,label:x.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(_e,{divider:!1,children:s.jsx(zp,{entryId:x.id,spec:x.spec})}),s.jsx(_e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Je,{value:i.spec,onChange:P=>r({...i,spec:P.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(_e,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(As,{value:i.optionsJson,onChange:P=>r({...i,optionsJson:P.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!S&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!S&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{M()},disabled:!g||!S||y,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:T,disabled:!g||y,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const b=C.current.get(d.id)??"",S=i.content!==b||i.fileName!==d.fileName,g=()=>{(async()=>{h(!0);const P=(await m(d.id))?.content??"";h(!1),C.current.set(d.id,P),r(yo(d,P))})()},T=async()=>{c(!0);try{const M=await p(d.id,{content:i.content});M.ok?(C.current.set(d.id,i.content),M.reloadFailed?D.warning(M.message||t("settings.plugins.toast.reloadFailed"),{description:M.warning}):M.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(M.message||t("settings.plugins.toast.updated"))):D.error(M.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsx(es,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(bo,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:d.fileName})]}),showSaveStatus:!1,children:s.jsxs(_e,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(As,{value:i.content,onChange:M=>r({...i,content:M.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:N}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{T()},disabled:!S||y||N,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:g,disabled:y||N,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(R,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},$p="<built-in>",Ua=t=>t?.path===$p,mr=t=>!!t&&!Ua(t)&&t.renamable===!0,Vp=t=>{const e=gt.c(157),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(""),[m,x]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState(null),{selectedSkillName:h,setSelectedSkill:C,setSkillDraft:b,deleteSkill:S,renameSkill:g,getSkillDetail:T}=Vs(Ks(Bp)),M=Us();let P;e[0]!==M?(P=Ee=>yr(Ee,M),e[0]=M,e[1]=P):P=e[1];const k=Vs(P),f=Vs(Hp);let w,F;e[2]!==f||e[3]!==M?(w=()=>{f(M)},F=[f,M],e[2]=f,e[3]=M,e[4]=w,e[5]=F):(w=e[4],F=e[5]),o.useEffect(w,F);let A;e[6]!==a||e[7]!==C||e[8]!==b||e[9]!==k?(A=()=>{let Ee="new-skill",wt=1;for(;k.some(J=>J.name===Ee);)Ee=`new-skill-${wt}`,wt++;b({name:Ee,scope:"user",source:"opencode",description:""}),C(Ee),a?.()},e[6]=a,e[7]=C,e[8]=b,e[9]=k,e[10]=A):A=e[10];const I=A;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=async Ee=>{Ua(Ee)||x(Ee)},e[11]=E):E=e[11];const B=E;let _;e[12]!==m||e[13]!==S||e[14]!==M||e[15]!==n?(_=async()=>{if(!m)return;if(Ua(m)){x(null);return}y(!0),await S(m.name,M)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:m.name})),x(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),y(!1)},e[12]=m,e[13]=S,e[14]=M,e[15]=n,e[16]=_):_=e[16];const j=_;let V;e[17]!==T||e[18]!==C||e[19]!==b||e[20]!==M||e[21]!==k||e[22]!==n?(V=async Ee=>{if(Ua(Ee))return;const wt=Ee.name;let J=1,fe=`${wt}-copy`;for(;k.some(De=>De.name===fe);)J++,fe=`${wt}-copy-${J}`;const Fe=await T(Ee.name,M);if(!Fe){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:fe,scope:Ee.scope||"user",source:Ee.source||"opencode",description:(Fe.sources.md.fields.includes("description"),""),instructions:""}),C(fe)},e[17]=T,e[18]=C,e[19]=b,e[20]=M,e[21]=k,e[22]=n,e[23]=V):V=e[23];const q=V;let L;e[24]===Symbol.for("react.memo_cache_sentinel")?(L=Ee=>{mr(Ee)&&(p(Ee.name),r(Ee))},e[24]=L):L=e[24];const Q=L;let ne;e[25]!==i||e[26]!==l||e[27]!==g||e[28]!==C||e[29]!==M||e[30]!==k||e[31]!==n?(ne=async()=>{if(!i)return;if(!mr(i)){r(null);return}const Ee=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ee){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Ee===i.name){r(null);return}if(k.some(J=>J.name===Ee)){D.error(n("settings.skills.page.toast.skillExists"));return}await g(i.name,Ee,M)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Ee})),C(Ee)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=g,e[28]=C,e[29]=M,e[30]=k,e[31]=n,e[32]=ne):ne=e[32];const z=ne;let re;e[33]!==k?(re=k.filter(Gp),e[33]=k,e[34]=re):re=e[34];const $=re;let U;e[35]!==k?(U=k.filter(Wp),e[35]=k,e[36]=U):U=e[36];const K=U;let O;e[37]===Symbol.for("react.memo_cache_sentinel")?(O=function(wt){const J={},fe=[];for(const De of wt)De.group?(J[De.group]||(J[De.group]=[]),J[De.group].push(De)):fe.push(De);const Fe=Object.keys(J).sort(qp).map(De=>({name:De,skills:[...J[De]].sort(Jp)}));return fe.sort(Qp),{sortedGroups:Fe,ungrouped:fe}},e[37]=O):O=e[37];const Y=O;let X;e[38]!==$?(X=Y($),e[38]=$,e[39]=X):X=e[39];const ee=X;let ge;e[40]!==K?(ge=Y(K),e[40]=K,e[41]=ge):ge=e[41];const de=ge;let xe;e[42]===Symbol.for("react.memo_cache_sentinel")?(xe=ye("flex h-full flex-col","bg-background"),e[42]=xe):xe=e[42];let ae;e[43]!==n?(ae=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ae):ae=e[44];let te;e[45]!==ae?(te=s.jsx("h2",{className:`${dn} mb-3`,children:ae}),e[45]=ae,e[46]=te):te=e[46];let ue;e[47]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(Ga,{className:"mb-3"}),e[47]=ue):ue=e[47];let Ie;e[48]!==k.length||e[49]!==n?(Ie=n("settings.skills.sidebar.total",{count:k.length}),e[48]=k.length,e[49]=n,e[50]=Ie):Ie=e[50];let Ne;e[51]!==Ie?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ie}),e[51]=Ie,e[52]=Ne):Ne=e[52];let Se;e[53]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Se):Se=e[53];let ve;e[54]!==I?(ve=s.jsx(H,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,children:Se}),e[54]=I,e[55]=ve):ve=e[55];let Oe;e[56]!==Ne||e[57]!==ve?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ne,ve]}),e[56]=Ne,e[57]=ve,e[58]=Oe):Oe=e[58];let Le;e[59]!==te||e[60]!==Oe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,ue,Oe]}),e[59]=te,e[60]=Oe,e[61]=Le):Le=e[61];let oe;e[62]!==ee||e[63]!==de||e[64]!==q||e[65]!==a||e[66]!==c||e[67]!==$||e[68]!==h||e[69]!==C||e[70]!==k.length||e[71]!==n||e[72]!==K?(oe=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:k.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),ee.sortedGroups.map(Ee=>{const{name:wt,skills:J}=Ee;return s.jsx(lr,{label:wt,count:J.length,storageKey:"project-skills",children:J.map(fe=>s.jsx(ui,{skill:fe,isSelected:h===fe.name,onSelect:()=>{C(fe.name),a?.()},onRename:()=>Q(fe),onDelete:()=>B(fe),onDuplicate:()=>q(fe),isMenuOpen:c===fe.name,onMenuOpenChange:Fe=>N(Fe?fe.name:null)},fe.name))},wt)}),ee.ungrouped.map(Ee=>s.jsx(ui,{skill:Ee,isSelected:h===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>B(Ee),onDuplicate:()=>q(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:wt=>N(wt?Ee.name:null)},Ee.name))]}),K.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Ee=>{const{name:wt,skills:J}=Ee;return s.jsx(lr,{label:wt,count:J.length,storageKey:"user-skills",children:J.map(fe=>s.jsx(ui,{skill:fe,isSelected:h===fe.name,onSelect:()=>{C(fe.name),a?.()},onRename:()=>Q(fe),onDelete:()=>B(fe),onDuplicate:()=>q(fe),isMenuOpen:c===fe.name,onMenuOpenChange:Fe=>N(Fe?fe.name:null)},fe.name))},wt)}),de.ungrouped.map(Ee=>s.jsx(ui,{skill:Ee,isSelected:h===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>B(Ee),onDuplicate:()=>q(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:wt=>N(wt?Ee.name:null)},Ee.name))]})]})}),e[62]=ee,e[63]=de,e[64]=q,e[65]=a,e[66]=c,e[67]=$,e[68]=h,e[69]=C,e[70]=k.length,e[71]=n,e[72]=K,e[73]=oe):oe=e[73];const he=m!==null;let Me;e[74]!==d?(Me=Ee=>{!Ee&&!d&&x(null)},e[74]=d,e[75]=Me):Me=e[75];let $e;e[76]!==n?($e=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=$e):$e=e[77];let Ve;e[78]!==$e?(Ve=s.jsx($t,{children:$e}),e[78]=$e,e[79]=Ve):Ve=e[79];const We=m?.name??"";let se;e[80]!==n||e[81]!==We?(se=n("settings.skills.sidebar.deleteDialog.description",{name:We}),e[80]=n,e[81]=We,e[82]=se):se=e[82];let ie;e[83]!==se?(ie=s.jsx(Vt,{children:se}),e[83]=se,e[84]=ie):ie=e[84];let je;e[85]!==Ve||e[86]!==ie?(je=s.jsxs(_t,{children:[Ve,ie]}),e[85]=Ve,e[86]=ie,e[87]=je):je=e[87];let be;e[88]===Symbol.for("react.memo_cache_sentinel")?(be=()=>x(null),e[88]=be):be=e[88];let Te;e[89]!==n?(Te=n("settings.common.actions.cancel"),e[89]=n,e[90]=Te):Te=e[90];let Ue;e[91]!==d||e[92]!==Te?(Ue=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:be,disabled:d,children:Te}),e[91]=d,e[92]=Te,e[93]=Ue):Ue=e[93];let Pe;e[94]!==n?(Pe=n("settings.common.actions.delete"),e[94]=n,e[95]=Pe):Pe=e[95];let we;e[96]!==j||e[97]!==d||e[98]!==Pe?(we=s.jsx(H,{size:"sm",onClick:j,disabled:d,children:Pe}),e[96]=j,e[97]=d,e[98]=Pe,e[99]=we):we=e[99];let Ge;e[100]!==Ue||e[101]!==we?(Ge=s.jsxs(ts,{children:[Ue,we]}),e[100]=Ue,e[101]=we,e[102]=Ge):Ge=e[102];let pe;e[103]!==je||e[104]!==Ge?(pe=s.jsxs(zt,{className:"max-w-md",children:[je,Ge]}),e[103]=je,e[104]=Ge,e[105]=pe):pe=e[105];let Ce;e[106]!==he||e[107]!==Me||e[108]!==pe?(Ce=s.jsx(Kt,{open:he,onOpenChange:Me,children:pe}),e[106]=he,e[107]=Me,e[108]=pe,e[109]=Ce):Ce=e[109];const Re=i!==null;let Ye;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ye=Ee=>!Ee&&r(null),e[110]=Ye):Ye=e[110];let W;e[111]!==n?(W=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=W):W=e[112];let ke;e[113]!==W?(ke=s.jsx($t,{children:W}),e[113]=W,e[114]=ke):ke=e[114];const Ae=i?.name??"";let He;e[115]!==n||e[116]!==Ae?(He=n("settings.skills.sidebar.renameDialog.description",{name:Ae}),e[115]=n,e[116]=Ae,e[117]=He):He=e[117];let at;e[118]!==He?(at=s.jsx(Vt,{children:He}),e[118]=He,e[119]=at):at=e[119];let nt;e[120]!==ke||e[121]!==at?(nt=s.jsxs(_t,{children:[ke,at]}),e[120]=ke,e[121]=at,e[122]=nt):nt=e[122];let dt;e[123]===Symbol.for("react.memo_cache_sentinel")?(dt=Ee=>p(Ee.target.value),e[123]=dt):dt=e[123];let xt;e[124]!==n?(xt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=xt):xt=e[125];let G;e[126]!==z?(G=Ee=>{Ee.key==="Enter"&&z()},e[126]=z,e[127]=G):G=e[127];let Be;e[128]!==l||e[129]!==xt||e[130]!==G?(Be=s.jsx(Je,{value:l,onChange:dt,placeholder:xt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:G}),e[128]=l,e[129]=xt,e[130]=G,e[131]=Be):Be=e[131];let st;e[132]===Symbol.for("react.memo_cache_sentinel")?(st=()=>r(null),e[132]=st):st=e[132];let rt;e[133]!==n?(rt=n("settings.common.actions.cancel"),e[133]=n,e[134]=rt):rt=e[134];let ut;e[135]!==rt?(ut=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:st,children:rt}),e[135]=rt,e[136]=ut):ut=e[136];let St;e[137]!==n?(St=n("settings.common.actions.rename"),e[137]=n,e[138]=St):St=e[138];let et;e[139]!==z||e[140]!==St?(et=s.jsx(H,{size:"sm",onClick:z,children:St}),e[139]=z,e[140]=St,e[141]=et):et=e[141];let Xe;e[142]!==ut||e[143]!==et?(Xe=s.jsxs(ts,{children:[ut,et]}),e[142]=ut,e[143]=et,e[144]=Xe):Xe=e[144];let ht;e[145]!==nt||e[146]!==Be||e[147]!==Xe?(ht=s.jsxs(zt,{children:[nt,Be,Xe]}),e[145]=nt,e[146]=Be,e[147]=Xe,e[148]=ht):ht=e[148];let ze;e[149]!==Re||e[150]!==ht?(ze=s.jsx(Kt,{open:Re,onOpenChange:Ye,children:ht}),e[149]=Re,e[150]=ht,e[151]=ze):ze=e[151];let jt;return e[152]!==Le||e[153]!==oe||e[154]!==Ce||e[155]!==ze?(jt=s.jsxs("div",{className:xe,children:[Le,oe,Ce,ze]}),e[152]=Le,e[153]=oe,e[154]=Ce,e[155]=ze,e[156]=jt):jt=e[156],jt},ui=t=>{const e=gt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:p,isMenuOpen:m,onMenuOpenChange:x}=t,{t:d}=it();let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=$a(),e[0]=y):y=e[0];const c=y;let N;e[1]!==a?(N=Ua(a),e[1]=a,e[2]=N):N=e[2];const h=N;let C;e[3]!==a?(C=mr(a),e[3]=a,e[4]=C):C=e[4];const b=C,[S,g]=o.useState(!1);let T;e[5]!==b||e[6]!==r||e[7]!==p||e[8]!==l||e[9]!==d?(T=q=>s.jsxs(s.Fragment,{children:[b?s.jsxs(q,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(q,{onClick:L=>{L.stopPropagation(),p()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(q,{onClick:L=>{L.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=b,e[6]=r,e[7]=p,e[8]=l,e[9]=d,e[10]=T):T=e[10];const M=T,P=!h&&S,k=n?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[11]!==k?(f=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",k),e[11]=k,e[12]=f):f=e[12];let w;e[13]!==h?(w=!c&&!h?q=>{q.preventDefault(),g(!0)}:void 0,e[13]=h,e[14]=w):w=e[14];let F;e[15]!==f||e[16]!==w?(F=s.jsx("div",{className:f,onContextMenu:w}),e[15]=f,e[16]=w,e[17]=F):F=e[17];let A;e[18]!==a.name?(A=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=A):A=e[19];let I;e[20]!==i||e[21]!==A?(I=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:A}),e[20]=i,e[21]=A,e[22]=I):I=e[22];let E;e[23]!==h||e[24]!==m||e[25]!==x||e[26]!==M?(E=h?null:s.jsxs(ln,{open:m,onOpenChange:q=>{q&&g(!1),x(q)},children:[s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:M(cn)})]}),e[23]=h,e[24]=m,e[25]=x,e[26]=M,e[27]=E):E=e[27];let B;e[28]!==I||e[29]!==E?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,E]}),e[28]=I,e[29]=E,e[30]=B):B=e[30];let _;e[31]!==B||e[32]!==F?(_=s.jsx(Zn,{render:F,children:B}),e[31]=B,e[32]=F,e[33]=_):_=e[33];let j;e[34]!==h||e[35]!==M?(j=h?null:s.jsx(Yn,{className:"w-fit min-w-20",children:M(Xn)}),e[34]=h,e[35]=M,e[36]=j):j=e[36];let V;return e[37]!==_||e[38]!==j||e[39]!==P?(V=s.jsxs(ea,{open:P,onOpenChange:g,children:[_,j]}),e[37]=_,e[38]=j,e[39]=P,e[40]=V):V=e[40],V};function Bp(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Hp(t){return t.loadSkills}function Gp(t){return t.scope==="project"}function Wp(t){return t.scope==="user"}function qp(t,e){return t.localeCompare(e)}function Jp(t,e){return t.name.localeCompare(e.name)}function Qp(t,e){return t.name.localeCompare(e.name)}const Yp=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Xp=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},Zp=async()=>{try{const t=an()?.settings;if(t)return(await t.load())?.settings||{};const e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},em=t=>{const e=gt.c(162),{open:a,onOpenChange:n}=t,{t:i}=it(),r=fn(tm),l=fn(sm),p=fn(nm),m=fn(am),x=fn(im),d=Hn(rm),y=Hn(om),[c,N]=o.useState(""),[h,C]=o.useState(""),[b,S]=o.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,M]=o.useState(g),[P,k]=o.useState(null),[f,w]=o.useState(!1);let F;e[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[1]=F):F=e[1];const[A,I]=o.useState(F),[E,B]=o.useState(null),_=o.useRef(0);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j=Xe=>{_.current=_.current+1,w(!1),k(null),Xe?.clearIdentity&&(I([]),B(null))},e[2]=j):j=e[2];const V=j;let q,L;e[3]!==y||e[4]!==a?(q=()=>{a&&(_.current=_.current+1,N(""),C(""),S(""),k(null),w(!1),I([]),B(null),y(),(async()=>{const Xe=await Zp(),ht=Array.isArray(Xe?.skillCatalogs)?Xe?.skillCatalogs:[];M(ht||[])})())},L=[a,y],e[3]=y,e[4]=a,e[5]=q,e[6]=L):(q=e[5],L=e[6]),o.useEffect(q,L);let Q;e[7]!==h?(Q=h.trim(),e[7]=h,e[8]=Q):Q=e[8];const ne=Q;let z;e[9]!==b?(z=b.trim(),e[9]=b,e[10]=z):z=e[10];const re=z;let $;if(e[11]!==T||e[12]!==ne||e[13]!==re){let Xe;e[15]!==ne||e[16]!==re?(Xe=ht=>{const ze=(ht.source||"").trim(),jt=(ht.subpath||"").trim();return ze===ne&&jt===re},e[15]=ne,e[16]=re,e[17]=Xe):Xe=e[17],$=T.some(Xe),e[11]=T,e[12]=ne,e[13]=re,e[14]=$}else $=e[14];const U=$;let K;e[18]!==d||e[19]!==E||e[20]!==c||e[21]!==r||e[22]!==h||e[23]!==b||e[24]!==i?(K=async()=>{const Xe=h.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}c.trim()||N(Xp(Xe)),w(!1),k(null);const ht=_.current+1;_.current=ht;const ze=await r({source:Xe,subpath:b.trim()||void 0,gitIdentityId:E||void 0});if(_.current!==ht)return;if(!ze.ok){if(ze.error?.kind==="authRequired"){if(cs()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ee=ze.error.identities||[];if(I(Ee),!E&&Ee.length>0){const wt=d&&d!=="global"&&Ee.some(J=>J.id===d)?d:Ee[0].id;B(wt)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(ze.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const jt=ze.items?.length||0;if(k(jt),jt===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}I([]),w(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:jt}))},e[18]=d,e[19]=E,e[20]=c,e[21]=r,e[22]=h,e[23]=b,e[24]=i,e[25]=K):K=e[25];const O=K;let Y;e[26]!==T||e[27]!==E||e[28]!==U||e[29]!==c||e[30]!==l||e[31]!==p||e[32]!==n||e[33]!==f||e[34]!==m||e[35]!==h||e[36]!==b||e[37]!==i?(Y=async()=>{const Xe=c.trim(),ht=h.trim(),ze=b.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ht){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!f){D.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(U){D.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const jt={id:Yp(),label:Xe,source:ht,...ze?{subpath:ze}:{},...E?{gitIdentityId:E}:{}},Ee=[...T,jt];try{await yt({skillCatalogs:Ee}),M(Ee),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await p(jt.id,{refresh:!0}),m(jt.id),n(!1)}catch(wt){const J=wt;D.error(J instanceof Error?J.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=T,e[27]=E,e[28]=U,e[29]=c,e[30]=l,e[31]=p,e[32]=n,e[33]=f,e[34]=m,e[35]=h,e[36]=b,e[37]=i,e[38]=Y):Y=e[38];const X=Y;let ee;e[39]!==i?(ee=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=ee):ee=e[40];let ge;e[41]!==ee?(ge=s.jsx($t,{children:ee}),e[41]=ee,e[42]=ge):ge=e[42];let de;e[43]!==i?(de=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=de):de=e[44];let xe;e[45]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=xe):xe=e[45];let ae;e[46]!==i?(ae=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ae):ae=e[47];let te;e[48]!==de||e[49]!==ae?(te=s.jsxs(Vt,{children:[de," ",xe,ae]}),e[48]=de,e[49]=ae,e[50]=te):te=e[50];let ue;e[51]!==ge||e[52]!==te?(ue=s.jsxs(_t,{children:[ge,te]}),e[51]=ge,e[52]=te,e[53]=ue):ue=e[53];let Ie;e[54]!==i?(Ie=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Ie):Ie=e[55];let Ne;e[56]!==Ie?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ie}),e[56]=Ie,e[57]=Ne):Ne=e[57];let Se;e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=Xe=>N(Xe.target.value),e[58]=Se):Se=e[58];let ve;e[59]!==i?(ve=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=ve):ve=e[60];let Oe;e[61]!==c||e[62]!==ve?(Oe=s.jsx(Je,{value:c,onChange:Se,placeholder:ve}),e[61]=c,e[62]=ve,e[63]=Oe):Oe=e[63];let Le;e[64]!==Ne||e[65]!==Oe?(Le=s.jsxs("div",{className:"space-y-2",children:[Ne,Oe]}),e[64]=Ne,e[65]=Oe,e[66]=Le):Le=e[66];let oe;e[67]!==i?(oe=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=oe):oe=e[68];let he;e[69]!==oe?(he=s.jsx("label",{className:"typography-ui-label text-foreground",children:oe}),e[69]=oe,e[70]=he):he=e[70];let Me;e[71]!==i?(Me=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Me):Me=e[72];let $e;e[73]!==Me?($e=s.jsx(Jt,{children:Me}),e[73]=Me,e[74]=$e):$e=e[74];let Ve;e[75]!==he||e[76]!==$e?(Ve=s.jsxs("div",{className:"flex items-center gap-1",children:[he,$e]}),e[75]=he,e[76]=$e,e[77]=Ve):Ve=e[77];let We;e[78]===Symbol.for("react.memo_cache_sentinel")?(We=Xe=>{C(Xe.target.value),V({clearIdentity:!0})},e[78]=We):We=e[78];let se;e[79]!==i?(se=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=se):se=e[80];let ie;e[81]!==h||e[82]!==se?(ie=s.jsx(Je,{value:h,onChange:We,placeholder:se}),e[81]=h,e[82]=se,e[83]=ie):ie=e[83];let je;e[84]!==Ve||e[85]!==ie?(je=s.jsxs("div",{className:"space-y-2",children:[Ve,ie]}),e[84]=Ve,e[85]=ie,e[86]=je):je=e[86];let be;e[87]!==i?(be=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=be):be=e[88];let Te;e[89]!==be?(Te=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[89]=be,e[90]=Te):Te=e[90];let Ue;e[91]===Symbol.for("react.memo_cache_sentinel")?(Ue=Xe=>{S(Xe.target.value),V({clearIdentity:!0})},e[91]=Ue):Ue=e[91];let Pe;e[92]!==i?(Pe=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Pe):Pe=e[93];let we;e[94]!==b||e[95]!==Pe?(we=s.jsx(Je,{value:b,onChange:Ue,placeholder:Pe}),e[94]=b,e[95]=Pe,e[96]=we):we=e[96];let Ge;e[97]!==Te||e[98]!==we?(Ge=s.jsxs("div",{className:"space-y-2",children:[Te,we]}),e[97]=Te,e[98]=we,e[99]=Ge):Ge=e[99];let pe;e[100]!==E||e[101]!==A||e[102]!==i?(pe=A.length>0&&!cs()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(Jt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(It,{value:E||"",onValueChange:Xe=>{B(Xe),V()},children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{children:A.find(Xe=>Xe.id===E)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:A.map(lm)})]})]}):null,e[100]=E,e[101]=A,e[102]=i,e[103]=pe):pe=e[103];let Ce;e[104]!==P||e[105]!==i?(Ce=P!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:P})}):null,e[104]=P,e[105]=i,e[106]=Ce):Ce=e[106];let Re;e[107]!==U||e[108]!==i?(Re=U?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=U,e[108]=i,e[109]=Re):Re=e[109];let Ye;e[110]!==Le||e[111]!==je||e[112]!==Ge||e[113]!==pe||e[114]!==Ce||e[115]!==Re?(Ye=s.jsxs("div",{className:"space-y-4",children:[Le,je,Ge,pe,Ce,Re]}),e[110]=Le,e[111]=je,e[112]=Ge,e[113]=pe,e[114]=Ce,e[115]=Re,e[116]=Ye):Ye=e[116];let W;e[117]!==n?(W=()=>n(!1),e[117]=n,e[118]=W):W=e[118];let ke;e[119]!==i?(ke=i("settings.common.actions.cancel"),e[119]=i,e[120]=ke):ke=e[120];let Ae;e[121]!==W||e[122]!==ke?(Ae=s.jsx(H,{size:"sm",variant:"ghost",onClick:W,children:ke}),e[121]=W,e[122]=ke,e[123]=Ae):Ae=e[123];let He;e[124]!==O?(He=()=>{O()},e[124]=O,e[125]=He):He=e[125];let at;e[126]!==x||e[127]!==h?(at=x||!h.trim(),e[126]=x,e[127]=h,e[128]=at):at=e[128];let nt;e[129]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(R,{name:"git-repository",className:"h-4 w-4"}),e[129]=nt):nt=e[129];let dt;e[130]!==x||e[131]!==i?(dt=i(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=x,e[131]=i,e[132]=dt):dt=e[132];let xt;e[133]!==He||e[134]!==at||e[135]!==dt?(xt=s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:He,disabled:at,children:[nt,dt]}),e[133]=He,e[134]=at,e[135]=dt,e[136]=xt):xt=e[136];let G;e[137]!==X?(G=()=>{X()},e[137]=X,e[138]=G):G=e[138];let Be;e[139]!==U||e[140]!==c||e[141]!==f||e[142]!==h?(Be=!f||U||!c.trim()||!h.trim(),e[139]=U,e[140]=c,e[141]=f,e[142]=h,e[143]=Be):Be=e[143];let st;e[144]!==i?(st=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=st):st=e[145];let rt;e[146]!==G||e[147]!==Be||e[148]!==st?(rt=s.jsx(H,{size:"sm",onClick:G,disabled:Be,children:st}),e[146]=G,e[147]=Be,e[148]=st,e[149]=rt):rt=e[149];let ut;e[150]!==Ae||e[151]!==xt||e[152]!==rt?(ut=s.jsxs(ts,{children:[Ae,xt,rt]}),e[150]=Ae,e[151]=xt,e[152]=rt,e[153]=ut):ut=e[153];let St;e[154]!==ue||e[155]!==Ye||e[156]!==ut?(St=s.jsxs(zt,{className:"max-w-xl",children:[ue,Ye,ut]}),e[154]=ue,e[155]=Ye,e[156]=ut,e[157]=St):St=e[157];let et;return e[158]!==n||e[159]!==a||e[160]!==St?(et=s.jsx(Kt,{open:a,onOpenChange:n,children:St}),e[158]=n,e[159]=a,e[160]=St,e[161]=et):et=e[161],et};function tm(t){return t.scanRepo}function sm(t){return t.loadCatalog}function nm(t){return t.loadSource}function am(t){return t.setSelectedSource}function im(t){return t.isScanning}function rm(t){return t.defaultGitIdentityId}function om(t){return t.loadDefaultGitIdentityId}function lm(t){return s.jsx(ot,{value:t.id,children:t.name},t.id)}const cm=t=>{const e=gt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=it();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={},e[0]=p):p=e[0];const[m,x]=o.useState(p);let d,y;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const X={};for(const ee of i)X[ee.skillName]="skip";x(X)},y=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=y):(d=e[3],y=e[4]),o.useEffect(d,y);let c;e[5]!==i?(c=X=>{const ee={};for(const ge of i)ee[ge.skillName]=X;x(ee)},e[5]=i,e[6]=c):c=e[6];const N=c;let h;e[7]!==i||e[8]!==m?(h=i.length>0&&i.every(X=>m[X.skillName]),e[7]=i,e[8]=m,e[9]=h):h=e[9];const C=h;let b;e[10]!==l?(b=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=b):b=e[11];let S;e[12]!==b?(S=s.jsx($t,{children:b}),e[12]=b,e[13]=S):S=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let T;e[16]!==g?(T=s.jsx(Vt,{children:g}),e[16]=g,e[17]=T):T=e[17];let M;e[18]!==S||e[19]!==T?(M=s.jsxs(_t,{children:[S,T]}),e[18]=S,e[19]=T,e[20]=M):M=e[20];let P;e[21]!==i.length||e[22]!==l?(P=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=P):P=e[23];let k;e[24]!==P?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[24]=P,e[25]=k):k=e[25];let f;e[26]!==N?(f=()=>N("skip"),e[26]=N,e[27]=f):f=e[27];let w;e[28]!==l?(w=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=w):w=e[29];let F;e[30]!==f||e[31]!==w?(F=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:f,children:w}),e[30]=f,e[31]=w,e[32]=F):F=e[32];let A;e[33]!==N?(A=()=>N("overwrite"),e[33]=N,e[34]=A):A=e[34];let I;e[35]!==l?(I=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=I):I=e[36];let E;e[37]!==A||e[38]!==I?(E=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:A,children:I}),e[37]=A,e[38]=I,e[39]=E):E=e[39];let B;e[40]!==F||e[41]!==E?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[F,E]}),e[40]=F,e[41]=E,e[42]=B):B=e[42];let _;e[43]!==k||e[44]!==B?(_=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,B]}),e[43]=k,e[44]=B,e[45]=_):_=e[45];let j;if(e[46]!==i||e[47]!==m||e[48]!==l){let X;e[50]!==m||e[51]!==l?(X=ee=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:ee.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ee.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ee.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(It,{value:m[ee.skillName]||"skip",onValueChange:ge=>x(de=>({...de,[ee.skillName]:ge})),children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(m[ee.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ee.skillName),e[50]=m,e[51]=l,e[52]=X):X=e[52],j=i.map(X),e[46]=i,e[47]=m,e[48]=l,e[49]=j}else j=e[49];let V;e[53]!==j?(V=s.jsx("div",{className:"space-y-2",children:j}),e[53]=j,e[54]=V):V=e[54];let q;e[55]!==_||e[56]!==V?(q=s.jsxs("div",{className:"space-y-3",children:[_,V]}),e[55]=_,e[56]=V,e[57]=q):q=e[57];let L;e[58]!==n?(L=()=>n(!1),e[58]=n,e[59]=L):L=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let ne;e[62]!==L||e[63]!==Q?(ne=s.jsx(H,{size:"sm",variant:"ghost",onClick:L,children:Q}),e[62]=L,e[63]=Q,e[64]=ne):ne=e[64];let z;e[65]!==m||e[66]!==r?(z=()=>r(m),e[65]=m,e[66]=r,e[67]=z):z=e[67];const re=!C;let $;e[68]!==l?($=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=$):$=e[69];let U;e[70]!==z||e[71]!==re||e[72]!==$?(U=s.jsx(H,{size:"sm",onClick:z,disabled:re,children:$}),e[70]=z,e[71]=re,e[72]=$,e[73]=U):U=e[73];let K;e[74]!==ne||e[75]!==U?(K=s.jsxs(ts,{children:[ne,U]}),e[74]=ne,e[75]=U,e[76]=K):K=e[76];let O;e[77]!==M||e[78]!==q||e[79]!==K?(O=s.jsxs(zt,{className:"max-w-2xl",children:[M,q,K]}),e[77]=M,e[78]=q,e[79]=K,e[80]=O):O=e[80];let Y;return e[81]!==n||e[82]!==a||e[83]!==O?(Y=s.jsx(Kt,{open:a,onOpenChange:n,children:O}),e[81]=n,e[82]=a,e[83]=O,e[84]=Y):Y=e[84],Y},Cr=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function _a(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Hl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Cr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const dm=t=>{const e=gt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=it(),l=fn(um),p=fn(pm),[m,x]=o.useState("user"),[d,y]=o.useState("opencode"),c=Bs(mm),N=Bs(gm),[h,C]=o.useState(null),[b,S]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,M]=o.useState(g),[P,k]=o.useState(null);let f,w;e[1]!==N||e[2]!==a?(f=()=>{a&&(x("user"),y("opencode"),C(N),S(!1),M([]),k(null))},w=[a,N],e[1]=N,e[2]=a,e[3]=f,e[4]=w):(f=e[3],w=e[4]),o.useEffect(f,w);let F;e[5]!==r?(F=we=>{switch(we){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=F):F=e[6];const A=F;let I;e[7]!==r?(I=we=>{switch(we){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=I):I=e[8];const E=I;let B;e:{if(c.length===0){B=null;break e}if(h&&c.some(we=>we.id===h)){B=h;break e}if(N&&c.some(we=>we.id===N)){B=N;break e}B=c[0]?.id??null}const _=B;let j;e:{if(m!=="project"){j=null;break e}const we=_;if(!we){j=null;break e}let Ge;if(e[9]!==we||e[10]!==c){let Ce;e[12]!==we?(Ce=Re=>Re.id===we,e[12]=we,e[13]=Ce):Ce=e[13],Ge=c.find(Ce),e[9]=we,e[10]=c,e[11]=Ge}else Ge=e[11];j=Ge?.path??null}const V=j;let q;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(q=async we=>{const Ge=await l({source:we.source,subpath:we.subpath,gitIdentityId:i?.gitIdentityId,scope:we.scope,targetSource:we.targetSource,selections:[{skillDir:we.skillDir}],conflictPolicy:"prompt",conflictDecisions:we.conflictDecisions},{directory:we.directoryOverride??null});if(Ge.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ge.error?.kind==="conflicts"){k({source:we.source,subpath:we.subpath,scope:we.scope,targetSource:we.targetSource,skillDir:we.skillDir,directoryOverride:we.directoryOverride??null}),M(Ge.error.conflicts),S(!0);return}if(Ge.error?.kind==="authRequired"){D.error(Ge.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error(Ge.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=q):q=e[18];const L=q;if(!i)return null;let Q;e[19]!==r?(Q=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=Q):Q=e[20];let ne;e[21]!==Q?(ne=s.jsx($t,{children:Q}),e[21]=Q,e[22]=ne):ne=e[22];let z;e[23]!==r?(z=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=z):z=e[24];let re;e[25]!==i.skillName?(re=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=re):re=e[26];let $;e[27]!==r?($=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=$):$=e[28];let U;e[29]!==z||e[30]!==re||e[31]!==$?(U=s.jsxs(Vt,{children:[z," ",re," ",$]}),e[29]=z,e[30]=re,e[31]=$,e[32]=U):U=e[32];let K;e[33]!==ne||e[34]!==U?(K=s.jsxs(_t,{children:[ne,U]}),e[33]=ne,e[34]=U,e[35]=K):K=e[35];let O;e[36]!==r?(O=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=O):O=e[37];let Y;e[38]!==O?(Y=s.jsx("span",{className:"typography-ui-label text-foreground",children:O}),e[38]=O,e[39]=Y):Y=e[39];let X;e[40]!==m||e[41]!==d?(X=_a(m,d),e[40]=m,e[41]=d,e[42]=X):X=e[42];let ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(ee=we=>{const Ge=Hl(we);x(Ge.scope),y(Ge.source==="agents"?"agents":"opencode")},e[43]=ee):ee=e[43];let ge;e[44]!==m?(ge=m==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=m,e[45]=ge):ge=e[45];let de;e[46]!==d?(de=d==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=de):de=e[47];let xe;e[48]!==A||e[49]!==m||e[50]!==d?(xe=A(_a(m,d)),e[48]=A,e[49]=m,e[50]=d,e[51]=xe):xe=e[51];let ae;e[52]!==xe?(ae=s.jsx("span",{children:xe}),e[52]=xe,e[53]=ae):ae=e[53];let te;e[54]!==ge||e[55]!==de||e[56]!==ae?(te=s.jsxs(Pt,{className:"w-fit gap-1.5",children:[ge,de,ae]}),e[54]=ge,e[55]=de,e[56]=ae,e[57]=te):te=e[57];let ue;e[58]!==E||e[59]!==A?(ue=Cr.map(we=>s.jsx(ot,{value:we.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[we.scope==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),we.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:A(we.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:E(we.value)})]})},we.value)),e[58]=E,e[59]=A,e[60]=ue):ue=e[60];let Ie;e[61]!==ue?(Ie=s.jsx(At,{align:"start",children:ue}),e[61]=ue,e[62]=Ie):Ie=e[62];let Ne;e[63]!==X||e[64]!==te||e[65]!==Ie?(Ne=s.jsxs(It,{value:X,onValueChange:ee,children:[te,Ie]}),e[63]=X,e[64]=te,e[65]=Ie,e[66]=Ne):Ne=e[66];let Se;e[67]!==Y||e[68]!==Ne?(Se=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Y,Ne]}),e[67]=Y,e[68]=Ne,e[69]=Se):Se=e[69];let ve;e[70]!==c||e[71]!==_||e[72]!==m||e[73]!==r?(ve=m==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(It,{value:_??"",onValueChange:we=>C(we),disabled:c.length===1,children:[s.jsx(Pt,{className:"w-fit",children:s.jsx(Rt,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:c.map(fm)})]})]}),e[70]=c,e[71]=_,e[72]=m,e[73]=r,e[74]=ve):ve=e[74];let Oe;e[75]!==i.warnings?(Oe=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Oe):Oe=e[76];let Le;e[77]!==Se||e[78]!==ve||e[79]!==Oe?(Le=s.jsxs("div",{className:"mt-2 space-y-3",children:[Se,ve,Oe]}),e[77]=Se,e[78]=ve,e[79]=Oe,e[80]=Le):Le=e[80];let oe;e[81]!==n?(oe=()=>n(!1),e[81]=n,e[82]=oe):oe=e[82];let he;e[83]!==r?(he=r("settings.common.actions.cancel"),e[83]=r,e[84]=he):he=e[84];let Me;e[85]!==oe||e[86]!==he?(Me=s.jsx(H,{size:"sm",variant:"ghost",onClick:oe,children:he}),e[85]=oe,e[86]=he,e[87]=Me):Me=e[87];const $e=p||!i.installable||m==="project"&&!V;let Ve;e[88]!==V||e[89]!==L||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==m||e[94]!==d?(Ve=()=>{L({source:i.repoSource,subpath:i.repoSubpath,scope:m,targetSource:d,skillDir:i.skillDir,directoryOverride:V})},e[88]=V,e[89]=L,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=m,e[94]=d,e[95]=Ve):Ve=e[95];let We;e[96]!==p||e[97]!==r?(We=r(p?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=p,e[97]=r,e[98]=We):We=e[98];let se;e[99]!==$e||e[100]!==Ve||e[101]!==We?(se=s.jsx(H,{size:"sm",disabled:$e,onClick:Ve,children:We}),e[99]=$e,e[100]=Ve,e[101]=We,e[102]=se):se=e[102];let ie;e[103]!==Me||e[104]!==se?(ie=s.jsxs(ts,{children:[Me,se]}),e[103]=Me,e[104]=se,e[105]=ie):ie=e[105];let je;e[106]!==K||e[107]!==Le||e[108]!==ie?(je=s.jsxs(zt,{className:"max-w-md",children:[K,Le,ie]}),e[106]=K,e[107]=Le,e[108]=ie,e[109]=je):je=e[109];let be;e[110]!==n||e[111]!==a||e[112]!==je?(be=s.jsx(Kt,{open:a,onOpenChange:n,children:je}),e[110]=n,e[111]=a,e[112]=je,e[113]=be):be=e[113];let Te;e[114]!==P||e[115]!==L?(Te=we=>{P&&(L({source:P.source,subpath:P.subpath,scope:P.scope,targetSource:P.targetSource,skillDir:P.skillDir,conflictDecisions:we,directoryOverride:P.directoryOverride??null}),S(!1))},e[114]=P,e[115]=L,e[116]=Te):Te=e[116];let Ue;e[117]!==T||e[118]!==b||e[119]!==Te?(Ue=s.jsx(cm,{open:b,onOpenChange:S,conflicts:T,onConfirm:Te}),e[117]=T,e[118]=b,e[119]=Te,e[120]=Ue):Ue=e[120];let Pe;return e[121]!==be||e[122]!==Ue?(Pe=s.jsxs(s.Fragment,{children:[be,Ue]}),e[121]=be,e[122]=Ue,e[123]=Pe):Pe=e[123],Pe};function um(t){return t.installSkills}function pm(t){return t.isInstalling}function mm(t){return t.projects}function gm(t){return t.activeProjectId}function fm(t){return s.jsx(ot,{value:t.id,children:t.label||t.path},t.id)}const hm=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,xm=t=>{const e=t.trim();return hm.test(e)?`https://github.com/${e}`:null},vm=t=>{const e=xm(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let pi=null;const ym=t=>{const e=kr();return(!pi||pi.locale!==e)&&(pi={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),pi.formatter.format(t)},bm=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},wm=async()=>{try{const t=an()?.settings;if(t)return(await t.load())?.settings||{};const e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},jm=t=>{const e=gt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:p}=t,m=a.stars??null;let x,d,y,c,N,h,C,b,S,g;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==m||e[8]!==p){const k=a.repoUpdatedAt?bm(a.repoUpdatedAt):null;b="button",S=l,g=n;const f=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==f?(d=ye("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",f),e[19]=f,e[20]=d):d=e[20],N="min-w-0 flex-1 block";let w;e[21]!==a.label?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=w):w=e[22];let F;e[23]!==i||e[24]!==r||e[25]!==p?(F=i?s.jsx(R,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=p,e[26]=F):F=e[26],e[27]!==w||e[28]!==F?(h=s.jsxs("span",{className:"flex items-center gap-2",children:[w,F]}),e[27]=w,e[28]=F,e[29]=h):h=e[29],e[30]!==a.source?(C=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=C):C=e[31],x="flex items-center gap-3 mt-1",e[32]!==m||e[33]!==p?(y=m!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:p("settings.skills.catalog.page.source.stars",{count:m}),children:[s.jsx(R,{name:"star",className:"h-3 w-3"}),ym(m)]}),e[32]=m,e[33]=p,e[34]=y):y=e[34],c=k&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:k.key==="common.relative.justNow"?p(k.key):p("settings.skills.catalog.page.source.updated",{time:p(k.key,{count:k.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=m,e[8]=p,e[9]=x,e[10]=d,e[11]=y,e[12]=c,e[13]=N,e[14]=h,e[15]=C,e[16]=b,e[17]=S,e[18]=g}else x=e[9],d=e[10],y=e[11],c=e[12],N=e[13],h=e[14],C=e[15],b=e[16],S=e[17],g=e[18];let T;e[35]!==x||e[36]!==y||e[37]!==c?(T=s.jsxs("span",{className:x,children:[y,c]}),e[35]=x,e[36]=y,e[37]=c,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==N||e[41]!==h||e[42]!==C?(M=s.jsxs("span",{className:N,children:[h,C,T]}),e[39]=T,e[40]=N,e[41]=h,e[42]=C,e[43]=M):M=e[43];let P;return e[44]!==d||e[45]!==M||e[46]!==b||e[47]!==S||e[48]!==g?(P=s.jsx("button",{type:b,onClick:S,"aria-pressed":g,className:d,children:M}),e[44]=d,e[45]=M,e[46]=b,e[47]=S,e[48]=g,e[49]=P):P=e[49],P},km=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=it(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:p,loadCatalog:m,loadSource:x,isLoadingCatalog:d,isLoadingSource:y,loadedSourceIds:c,lastCatalogError:N}=fn(Ks(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,loadedSourceIds:L.loadedSourceIds,lastCatalogError:L.lastCatalogError}))),[h,C]=o.useState(""),[b,S]=o.useState(!1),[g,T]=o.useState(!1),[M,P]=o.useState(null),[k,f]=o.useState(!1),[w,F]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{m()},[m]),o.useEffect(()=>{const L=i.filter(z=>!c[z.id]);if(L.length===0)return;let Q=!1;return(async()=>{for(const z of L){if(Q)return;await x(z.id)}})(),()=>{Q=!0}},[i,c,x]),o.useEffect(()=>{!l||c[l]||x(l)},[l,c,x]),o.useEffect(()=>{const L=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key.toLowerCase()==="k"&&(Q.preventDefault(),A.current?.focus())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[]);const I=h.trim().length>0,E=o.useMemo(()=>I?Ni(i.flatMap(L=>r[L.id]||[]),h,L=>[L.skillName,L.frontmatterName,L.description]):l?r[l]||[]:[],[i,r,l,h,I]),B=o.useMemo(()=>i.find(L=>L.id===l)||null,[i,l]),_=!!(l&&l.startsWith("custom:")),j=async()=>{if(!(!l||!_)){f(!0);try{const L=await wm(),ne=(Array.isArray(L?.skillCatalogs)?L?.skillCatalogs:[]).filter(z=>z.id!==l);await yt({skillCatalogs:ne}),await m({refresh:!0}),F(!1)}finally{f(!1)}}},V=I?n("settings.skills.catalog.page.list.searchTitle"):B?.label??"",q=!I&&l!==null&&!c[l]&&(y||d);return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Sr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(R,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{ref:A,value:h,onChange:L=>C(L.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ye("h-8 pl-8 w-full",h&&"pr-8")}),h&&s.jsx("button",{type:"button",onClick:()=>{C(""),A.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(R,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(_e,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(L=>s.jsx(jm,{source:L,isActive:L.id===l,isLoading:y&&!c[L.id],skillsCount:c[L.id]?(r[L.id]||[]).length:null,onSelect:()=>p(L.id),t:n},L.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>S(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(R,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),N&&s.jsx(_e,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:N.message})]})}),s.jsxs(_e,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:V}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:E.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!I?x(l,{refresh:!0}):m({refresh:!0})},disabled:d||y,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(R,{name:"refresh",className:ye("h-3.5 w-3.5",(d||y)&&"animate-spin")})}),_&&!I&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>F(!0),disabled:k,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),q||y&&E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(R,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.map(L=>{const Q=L.installed?.isInstalled,ne=L.installed?.scope,z=vm(L);return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:L.skillName}),Q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:ne||n("settings.skills.catalog.page.badge.unknown")})}),!L.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[z?s.jsxs("a",{href:z,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(R,{name:"github",className:"h-3 w-3 shrink-0"}),L.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:L.repoSource}),L.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:L.skillDir})]})]}),L.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:L.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[z&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(z,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"})}),Q?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:ne||""}),children:s.jsx(R,{name:"check",className:"h-4 w-4"})}):s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",disabled:!L.installable,onClick:()=>{P(L),T(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${L.sourceId}:${L.skillDir}`)})})]})]}),s.jsx(em,{open:b,onOpenChange:S}),s.jsx(dm,{open:g,onOpenChange:T,item:M}),s.jsx(Kt,{open:w,onOpenChange:L=>{k||F(L)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:k,children:n("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{j()},disabled:k,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Nm=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(km,{mode:"external",onModeChange:Tm,showModeTabs:!1}),t[0]=e):e=t[0],e},Sm="SKILL.md",Cm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",wi=(t,e)=>{const a=Xd({description:t}).trimEnd(),n=e.trimStart();return`---
|
|
22
|
+
${a}
|
|
23
|
+
---${n?`
|
|
24
|
+
|
|
25
|
+
${n}`:`
|
|
26
|
+
`}`},Im=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Gl=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=Zd(e[1]);if(Im(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Pm=(t,e)=>{const a=Gl(t);return wi(e,a.instructions)},Am=()=>{const{t}=it(),{currentTheme:e}=Nr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:p,setSkillDraft:m,setSelectedSkill:x}=Vs(Ks(pe=>({selectedSkillName:pe.selectedSkillName,getSkillByName:pe.getSkillByName,getSkillDetail:pe.getSkillDetail,createSkill:pe.createSkill,updateSkill:pe.updateSkill,skillDraft:pe.skillDraft,setSkillDraft:pe.setSkillDraft,setSelectedSkill:pe.setSelectedSkill}))),d=Us(),y=Vs(pe=>yr(pe,d)),c=a?n(a,d):null,N=!!(p&&p.name===a&&!c),h=!!(a&&!c&&!p),C=c?.path==="<built-in>";o.useEffect(()=>{h&&x(null)},[h,x]);const[b,S]=o.useState(""),[g,T]=o.useState("user"),[M,P]=o.useState("opencode"),[k,f]=o.useState(""),[w,F]=o.useState(""),[A,I]=o.useState(()=>wi("","")),[E,B]=o.useState("edit"),[_,j]=o.useState([]),[V,q]=o.useState([]),[L,Q]=o.useState(!1),[ne,z]=o.useState(!1),[re,$]=o.useState(""),[U,K]=o.useState(""),[O,Y]=o.useState(!1),[X,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(null),[te,ue]=o.useState(!1),[Ie,Ne]=o.useState(""),[Se,ve]=o.useState(null),[Oe,Le]=o.useState(!1),oe=N?b.trim()!==""||k.trim()!==""||w.trim()!==""||V.length>0:k!==re||w!==U,he=xe?ge!==Ie:X.trim()!=="",Me=o.useCallback(pe=>{switch(pe){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),$e=o.useCallback(pe=>{switch(pe){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(N&&p){const Ce=p.description||"",Re=p.instructions||"";S(p.name||""),T(p.scope||"user"),P(p.source==="agents"?"agents":"opencode"),f(Ce),F(Re),I(wi(Ce,Re)),$(""),K(""),j([]),q(p.pendingFiles||[])}else if(a&&c){z(!0);try{const Ce=await i(a,d);if(Ce){const Re=Ce.sources.md,Ye=Re.description||"",W=Re.instructions||"";f(Ye),F(W),I(wi(Ye,W)),$(Ye),K(W),j(Re.supportingFiles||[])}}catch(Ce){console.error("Failed to load skill details:",Ce)}finally{z(!1)}}})()},[c,N,a,d,y,p,i]);const Ve=le(pe=>pe.editorFontSize),We=o.useMemo(()=>{const pe=[so(e,{fontSize:Ve})],Ce=Or(Sm);return Ce&&pe.push(Ce),pe.push(ao.lineWrapping),pe},[e,Ve]),se=o.useMemo(()=>{const pe=X.trim()||"supporting-file.md",Ce=Nc(pe),Re=!!Ce&&Ce!=="markdown",Ye=[so(e,Re?{syntaxColors:!1,fontSize:Ve}:{fontSize:Ve})],W=Or(pe);return W&&Ye.push(W),Re&&Ce&&Ye.push(eu({language:Ce,themeName:e.metadata.id,theme:su(e)})),Ye.push(ao.lineWrapping),Ye},[e,X,Ve]),ie=o.useCallback(pe=>{f(pe),I(Ce=>Pm(Ce,pe))},[]),je=o.useCallback(pe=>{I(pe);const Ce=Gl(pe);f(Ce.description??""),F(Ce.instructions)},[]),be=async()=>{const pe=N?b.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!pe){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(pe)||pe.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(N&&y.some(Ce=>Ce.name===pe)){D.error(t("settings.skills.page.toast.skillExists"));return}Q(!0);try{const Ce={name:pe,description:k.trim(),instructions:w.trim()||void 0,scope:N?g:void 0,source:N?M:void 0,targetPath:N?void 0:c?.path,supportingFiles:N&&V.length>0?V:void 0};let Re;if(N?(Re=await r(Ce,d),Re&&(m(null),q([]),x(pe))):(Re=await l(pe,Ce,d),Re&&($(k.trim()),K(w.trim()))),Re){const Ye=Wn.getState().changes.some(W=>W.scope==="skills"&&W.id.startsWith(`skills:${pe}:`));D.success(t(Ye?"settings.view.pendingRestart.saved":N?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(N?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ce){console.error("Error saving skill:",Ce),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{Q(!1)}},Te=()=>{ae(null),ee(""),de(""),Ne(""),Y(!0)},Ue=async pe=>{if(ae(pe),ee(pe),N){const Re=V.find(Ye=>Ye.path===pe)?.content||"";de(Re),Ne(Re),Y(!0);return}if(a){ue(!0),Y(!0);try{const{readSupportingFile:Ce}=Vs.getState(),Re=await Ce(a,pe,d);de(Re||""),Ne(Re||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),Ne("")}finally{ue(!1)}}},Pe=async()=>{if(!X.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const pe=X.trim(),Ce=xe!==null;if(N){if(Ce)q(W=>W.map(ke=>ke.path===xe?{path:pe,content:ge}:ke)),D.success(t("settings.skills.page.toast.fileUpdated",{path:pe}));else{if(V.some(W=>W.path===pe)){D.error(t("settings.skills.page.toast.fileExists"));return}q(W=>[...W,{path:pe,content:ge}]),D.success(t("settings.skills.page.toast.fileAdded",{path:pe}))}Y(!1),ae(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Re}=Vs.getState();if(await Re(a,pe,ge,d)){D.success(Ce?t("settings.skills.page.toast.fileUpdated",{path:pe}):t("settings.skills.page.toast.fileCreated",{path:pe})),Y(!1),ae(null);const W=await i(a,d);W&&j(W.sources.md.supportingFiles||[])}else D.error(t(Ce?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},we=pe=>{if(N){q(Ce=>Ce.filter(Re=>Re.path!==pe)),D.success(t("settings.skills.page.toast.fileRemoved",{path:pe}));return}a&&ve(pe)},Ge=async()=>{if(!Se||!a)return;Le(!0);const{deleteSupportingFile:pe}=Vs.getState();if(await pe(a,Se,d)){D.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const Re=await i(a,d);Re&&j(Re.sources.md.supportingFiles||[]),ve(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Le(!1)};return!a&&!p||h?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):ne?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:N?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:Me(_a(c.scope,c.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[N&&s.jsxs(Lt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Je,{value:b,onChange:pe=>S(pe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(It,{value:_a(g,M),onValueChange:pe=>{const Ce=Hl(pe);T(Ce.scope),P(Ce.source==="agents"?"agents":"opencode")},children:[s.jsxs(Pt,{size:Ft,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),M==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(_a(g,M))})]}),s.jsx(At,{align:"start",children:Cr.map(pe=>s.jsx(ot,{value:pe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[pe.scope==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),pe.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(pe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:$e(pe.value)})]})},pe.value))})]})]}),s.jsx(qt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:k,onChange:pe=>ie(pe.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:C})})]}),s.jsx(_e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(tu,{currentMode:E==="preview"?"preview":"edit",onToggle:()=>B(pe=>pe==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Cm),children:E==="preview"?s.jsx(Hs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Sc,{content:A,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(no,{value:A,onChange:je,readOnly:C,extensions:We,className:"h-full",enableSearch:!0})})}),s.jsx(_e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Te,disabled:C,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const pe=N?V:_;return pe.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:pe.map(Ce=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ue(Ce.path),children:[s.jsx(R,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ce.path}),N&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!C&&s.jsx(H,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Re=>{Re.stopPropagation(),we(Ce.path)},children:s.jsx(R,{name:"delete-bin",className:"h-3 w-3"})})]},Ce.path))})})()}),s.jsx(_e,{children:s.jsx(H,{onClick:be,disabled:C||L||!oe,size:"xs",className:"!font-normal",children:t(L?"settings.common.actions.saving":N?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Kt,{open:Se!==null,onOpenChange:pe=>{!pe&&!Oe&&ve(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>ve(null),disabled:Oe,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:Ge,disabled:Oe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:O,onOpenChange:pe=>{Y(pe),pe||ae(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(_t,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(xe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(xe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),te?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Et,children:t("settings.skills.page.fileDialog.field.filePath")}),!xe&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Je,{value:X,onChange:pe=>ee(pe.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:xe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Et} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(no,{value:ge,onChange:de,extensions:se,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ts,{className:"mt-4",children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>{Y(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:Pe,disabled:te||!he,children:t(xe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},wo=t=>{const e=gt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(Nm,{}):s.jsx(Am,{}),e[0]=n,e[1]=i):i=e[1],i};function Tm(){}const Em=t=>{const e=gt.c(38),{onItemSelect:a}=t,{t:n}=it(),i=Bs(Dm),r=le(Mm),l=le(Rm),{currentTheme:p}=Nr();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=cs(),e[0]=m):m=e[0];const x=m,d=Lm;let y,c;e[1]!==i||e[2]!==r||e[3]!==l?(y=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(f=>f.id===r)||l(i[0].id)},c=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=y,e[5]=c):(y=e[4],c=e[5]),o.useEffect(y,c);let N;e[6]===Symbol.for("react.memo_cache_sentinel")?(N=ye("border-b px-3","pt-4 pb-3"),e[6]=N):N=e[6];let h;e[7]!==n?(h=n("settings.page.projects.title"),e[7]=n,e[8]=h):h=e[8];let C;e[9]!==h?(C=s.jsx("h2",{className:`${dn} mb-3`,children:h}),e[9]=h,e[10]=C):C=e[10];let b;e[11]!==i.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=b):b=e[13];let S;e[14]!==b?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=S):S=e[15];let g;e[16]!==n?(g=!x&&s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:d,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(R,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let T;e[18]!==S||e[19]!==g?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,g]}),e[18]=S,e[19]=g,e[20]=T):T=e[20];let M;e[21]!==T||e[22]!==C?(M=s.jsxs("div",{className:N,children:[C,T]}),e[21]=T,e[22]=C,e[23]=M):M=e[23];let P;if(e[24]!==p||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let f;e[30]!==p||e[31]!==a||e[32]!==r||e[33]!==l?(f=w=>{const F=w.id===r,A=w.icon?Ic[w.icon]:null,I=w.color?Pc[w.color]??null:null,E=A?s.jsx(R,{name:A,className:ye("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}):s.jsx(R,{name:"folder",className:ye("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}),B=w.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:w.iconBackground?{backgroundColor:w.iconBackground}:void 0,children:s.jsx(Ac,{project:w,options:{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground},className:"h-full w-full object-contain",fallback:E})}):E;return s.jsx(pr,{title:w.label||w.path,icon:B,selected:F,onSelect:()=>{l(w.id),a?.()}},w.id)},e[30]=p,e[31]=a,e[32]=r,e[33]=l,e[34]=f):f=e[34],P=i.map(f),e[24]=p,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=P}else P=e[29];let k;return e[35]!==M||e[36]!==P?(k=s.jsx(Vl,{variant:"background",header:M,children:P}),e[35]=M,e[36]=P,e[37]=k):k=e[37],k};function Dm(t){return t.projects}function Mm(t){return t.settingsProjectsSelectedId}function Rm(t){return t.setSettingsProjectsSelectedId}function Lm(){Cc.requestDirectoryDialog()}const Om=()=>{const t=gt.c(30),{t:e}=it(),a=Bs(Fm),n=Bs(Km),i=le(zm),r=le(Um);let l;e:{if(!i){l=null;break e}let b;t[0]!==a||t[1]!==i?(b=a.find(S=>S.id===i)??null,t[0]=a,t[1]=i,t[2]=b):b=t[2],l=b}const p=l;let m,x;t[3]!==a||t[4]!==i||t[5]!==r?(m=()=>{if(a.length===0){r(null);return}i&&a.some(b=>b.id===i)||r(a[0].id)},x=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=m,t[7]=x):(m=t[6],x=t[7]),o.useEffect(m,x);let d;t[8]!==p||t[9]!==n?(d=async b=>{p&&n(p.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultModel:b.defaultModel??null,defaultVariant:b.defaultVariant??null})},t[8]=p,t[9]=n,t[10]=d):d=t[10];const y=d;if(!p){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let S;t[13]!==e?(S=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=S):S=t[14];let g;t[15]!==S?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:S}),t[15]=S,t[16]=g):g=t[16];let T;return t[17]!==b||t[18]!==g?(T=s.jsx(es,{title:b,showSaveStatus:!0,children:g}),t[17]=b,t[18]=g,t[19]=T):T=t[19],T}let c;t[20]!==p.label||t[21]!==e?(c=p.label??e("settings.projects.page.title.default"),t[20]=p.label,t[21]=e,t[22]=c):c=t[22];const N=c;let h;t[23]!==y||t[24]!==p?(h=s.jsx(Bd,{project:p,onIdentitySave:y}),t[23]=y,t[24]=p,t[25]=h):h=t[25];let C;return t[26]!==N||t[27]!==p.path||t[28]!==h?(C=s.jsx(es,{title:N,description:p.path,showSaveStatus:!0,outerClassName:"bg-background",children:h}),t[26]=N,t[27]=p.path,t[28]=h,t[29]=C):C=t[29],C};function Fm(t){return t.projects}function Km(t){return t.updateProjectMeta}function zm(t){return t.settingsProjectsSelectedId}function Um(t){return t.setSettingsProjectsSelectedId}const ji=()=>Math.floor(2e4+Math.random()*3e4),_m=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},$m=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},jo=t=>{switch((t||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},ko=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingAiWorker";case"updating":return"settings.remoteInstances.page.phase.updatingAiWorker";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},Vm=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ir=t=>!!(t&&Vm.has(t)),No=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Ir(t)?"connecting":"idle",So=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Bm=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote aiworker port")?"externalPort":null:null},Co={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Hm=t=>t==="noRuntime"?Co.noRuntime:t==="noOpencode"?Co.noOpencode:null,Io=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ir(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Gm=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,Wm=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ji(),remoteHost:"127.0.0.1",remotePort:80}),qm=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",$s=t=>{const e=gt.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Jt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Et}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Jm=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},Po=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Qm=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Ym=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},gr=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),Xm=t=>t.trim().toLowerCase()==="authorization",Yi=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Xm(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Zm=t=>Object.entries(t||{}).map(([e,a])=>gr(e,a)),Wl=()=>{if(typeof window>"u")return null;const e=Ba()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},Ao=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},eg=async()=>{const t=fa(Ba())||window.location.origin;if(!as()||!Ha())return t;let e;try{e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await Al(),i=Wl();return!n||!i?t:`http://${n}:${i}`},mi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},tg=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},sg=()=>{const{t}=it(),e=le(v=>v.timeFormatPreference),{clientAuth:a}=wl(),n=as(),i=Is(v=>v.instances),r=Is(v=>v.statusesById),l=Is(v=>v.importCandidates),p=Is(v=>v.isLoading),m=Is(v=>v.isImportsLoading),x=Is(v=>v.isSaving),d=Is(v=>v.error),y=Is(v=>v.load),c=Is(v=>v.loadImports),N=Is(v=>v.refreshStatuses),h=Is(v=>v.upsertInstance),C=Is(v=>v.createFromCommand),b=Is(v=>v.removeInstance),S=Is(v=>v.connect),g=Is(v=>v.disconnect),T=Is(v=>v.retry),M=le(v=>v.settingsRemoteInstancesSelectedId),P=le(v=>v.setSettingsRemoteInstancesSelectedId),k=o.useMemo(()=>M&&i.find(v=>v.id===M)||null,[i,M]),[f,w]=o.useState(null),[F,A]=o.useState(!1),[I,E]=o.useState(!1),[B,_]=o.useState(null),[j,V]=o.useState([]),[q,L]=o.useState(null),[Q,ne]=o.useState(""),[z,re]=o.useState(!1),[$,U]=o.useState({}),[K,O]=o.useState(!1),[Y,X]=o.useState(!1),[ee,ge]=o.useState(()=>Date.now()),[de,xe]=o.useState([]),[ae,te]=o.useState({}),[ue,Ie]=o.useState("local"),[Ne,Se]=o.useState(!1),[ve,Oe]=o.useState(!1),[Le,oe]=o.useState(""),[he,Me]=o.useState(""),[$e,Ve]=o.useState(""),[We,se]=o.useState([]),[ie,je]=o.useState(""),[be,Te]=o.useState(null),[Ue,Pe]=o.useState(!1),[we,Ge]=o.useState(!1),[pe,Ce]=o.useState(null),[Re,Ye]=o.useState(""),[W,ke]=o.useState(""),[Ae,He]=o.useState(""),[at,nt]=o.useState([]),[dt,xt]=o.useState([]),[G,Be]=o.useState([]),[st,rt]=o.useState(!1),[ut,St]=o.useState(""),[et,Xe]=o.useState(null),[ht,ze]=o.useState(null),[jt,Ee]=o.useState(null),[wt,J]=o.useState(null),[fe,Fe]=o.useState(!1),[De,lt]=o.useState(!1),[ct,Qe]=o.useState("configure"),[kt,vs]=o.useState(!1),[Xt,Ls]=o.useState("relay"),[Gt,is]=o.useState(!0),[Ht,ys]=o.useState(null),ms=o.useMemo(()=>dt.filter(v=>!!v.revokedAt).length,[dt]),[gs,ds]=o.useState(!1),[Ts,ce]=o.useState("saved"),[pt,bt]=o.useState(""),[Qt,Yt]=o.useState(""),[Bt,rs]=o.useState(""),[bs,ss]=o.useState(!1);o.useEffect(()=>{y(),c()},[y,c]);const Nt=o.useCallback(async()=>{Se(!0),Te(null);try{const v=await Hr();xe(v.hosts||[]),Ie(v.defaultHostId||"local")}catch(v){Te(v instanceof Error?v.message:String(v))}finally{Se(!1)}},[]);o.useEffect(()=>{Nt()},[Nt]);const Tt=o.useCallback(async(v,Z=ue)=>{Oe(!0),Te(null);try{await Gr({hosts:v,defaultHostId:Z,initialHostChoiceCompleted:!0}),xe(v),Ie(Z)}catch(Ke){Te(Ke instanceof Error?Ke.message:String(Ke))}finally{Oe(!1)}},[ue]),Ut=o.useCallback(async()=>{const v=Wr(he);if(!v){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Z=v.persistedUrl,tt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Le.trim()||Ia(Z),url:Z,apiUrl:Z,...$e.trim()?{clientToken:$e.trim()}:{},...Yi(We)?{requestHeaders:Yi(We)}:{}};await Tt([tt,...de],ue),oe(""),Me(""),Ve(""),se([]),Pe(!1),v.redeemUrl&&mi(v.redeemUrl)},[ue,We,de,Le,$e,he,Tt,t]),Ot=o.useCallback(async()=>{const v=gd(ie);if(!v){Te(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const Z=await fd().catch(()=>""),Ke=JSON.stringify({pairingId:v.pairingId,secret:v.secret,clientLabel:v.label||"AiWorker Desktop",clientKind:"desktop",deviceName:"AiWorker Desktop",devicePlatform:$m(),...Z?{dedupeKey:`desktop:${Z}`}:{}}),tt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Ke},Dt=async Mt=>{if(!Mt.ok)return null;const Ms=await Mt.json().catch(()=>null);return(typeof Ms?.clientToken=="string"?Ms.clientToken.trim():"")||null},Ds=[...v.candidates].sort((Mt,Ms)=>(Mt.type==="relay"?1:0)-(Ms.type==="relay"?1:0));let js=null;for(const Mt of Ds){if(Mt.type==="relay"){const Un=hd({relayUrl:Mt.relayUrl,serverId:Mt.serverId,hostEncPubJwk:Mt.hostEncPubJwk,...Mt.grant?{grant:Mt.grant}:{}});try{const kn=await Un.fetch("/api/client-auth/pairing/redeem",tt),Ca=await Dt(kn);if(Ca){js={kind:"relay",relay:{relayUrl:Mt.relayUrl,serverId:Mt.serverId,hostEncPubJwk:Mt.hostEncPubJwk},token:Ca};break}}catch{}finally{Un.close()}continue}const Ms=fa(Mt.url);if(Ms)try{const Un=await fetch(`${Ms}/api/client-auth/pairing/redeem`,tt),kn=await Dt(Un);if(kn){js={kind:"direct",url:Ms,token:kn};break}}catch{}}if(!js){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const _s=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,ks=v.candidates.find(Mt=>Mt.type==="relay"),Ws=js.kind==="relay"?js.relay:ks?{relayUrl:ks.relayUrl,serverId:ks.serverId,hostEncPubJwk:ks.hostEncPubJwk}:void 0,Sa=v.candidates.filter(Mt=>Mt.type!=="relay").map(Mt=>fa(Mt.url)).find(Mt=>!!Mt),mn=js.kind==="direct"?js.url:Sa,{token:qs}=js,Ct=mn||(Ws?xd(Ws.serverId):null);if(!Ct){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Wt={url:Ct,apiUrl:mn||void 0,clientToken:qs,...Ws?{relay:Ws}:{}},zn=de.find(Mt=>Ws?Mt.relay?.serverId===Ws.serverId:!Mt.relay&&fa(Mt.apiUrl||Mt.url)===Ct);if(zn){const Mt=de.map(Ms=>Ms.id===zn.id?{...Ms,label:v.label||Ms.label,...Wt}:Ms);await Tt(Mt,ue)}else await Tt([{id:_s(),label:v.label||Ia(Ct),...Wt},...de],ue);je(""),Te(null),Ge(!1)},[ie,ue,de,Tt,t]),ns=o.useCallback(async v=>{const Z=de.filter(tt=>tt.id!==v);await Tt(Z,ue===v?"local":ue),pe===v&&Ce(null)},[ue,pe,de,Tt]),Es=o.useCallback(v=>{Ce(v.id),Ye(v.label),ke(v.apiUrl||v.url),He(v.clientToken||""),nt(Zm(v.requestHeaders)),Te(null)},[]),Wa=o.useCallback(async()=>{if(!pe)return;const v=Wr(W);if(!v){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Z=v.persistedUrl,Ke=de.map(tt=>tt.id===pe?{...tt,label:Re.trim()||Ia(Z),url:Z,apiUrl:Z,clientToken:Ae.trim()||void 0,requestHeaders:Yi(at)}:tt);await Tt(Ke,ue),Ce(null),v.redeemUrl&&mi(v.redeemUrl)},[ue,at,Re,Ae,W,pe,de,Tt,t]),Ti=o.useCallback(async()=>{const v=Qt.trim();if(!v){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const Z=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(Z,v,Bt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),P(Z),ds(!1),Yt(""),rs(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Ke){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ke instanceof Error?Ke.message:String(Ke)})}},[C,P,Qt,Bt,t]),qa=o.useCallback(()=>{bt(""),ce(l.length>0?"saved":"manual"),ds(!0)},[l.length]),Ei=o.useCallback(async v=>{await Tt(de,v)},[de,Tt]);o.useEffect(()=>{if(!n||de.length===0)return;let v=!1;return Promise.all(de.map(async Z=>{const Ke=()=>kd(Z.relay,{clientToken:Z.clientToken||null,requestHeaders:Z.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Z.relay&&!Z.apiUrl)return[Z.id,await Ke()];const tt=fa(vd(Z));if(!tt)return[Z.id,Z.relay?await Ke():{status:"unreachable",latencyMs:0}];const Dt=await yd(tt,{clientToken:Z.clientToken||null,requestHeaders:Z.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Dt.status==="unreachable"&&Z.relay){const Ds=await Ke();if(Ds.status==="ok")return[Z.id,Ds]}return[Z.id,Dt]})).then(Z=>{v||te(Object.fromEntries(Z))}),()=>{v=!0}},[de,n]);const zs=o.useCallback(async v=>{if(a){v?.silent||rt(!0),v?.silent||Xe(null);try{const[Z,Ke]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);xt(Z),Ke&&Be(Ke)}catch(Z){v?.silent||Xe(Z instanceof Error?Z.message:String(Z))}finally{v?.silent||rt(!1)}}},[a]),ja=o.useRef(!1);o.useEffect(()=>{if(!(!De||ct!=="result"||!jt)){if(G.some(v=>v.id===jt)){ja.current=!0;return}ja.current&&(Ee(null),lt(!1),dt.some(v=>v.pairingId===jt)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[De,ct,jt,G,dt,t]);const Ja=o.useCallback(async v=>{if(a)try{await a.cancelPairing(v),Be(Z=>Z.filter(Ke=>Ke.id!==v)),await zs({silent:!0})}catch(Z){Xe(Z instanceof Error?Z.message:String(Z))}},[a,zs]);o.useEffect(()=>{if(!a)return;zs();const v=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||zs({silent:!0})},5e3);return()=>window.clearInterval(v)},[a,zs]);const Qa=o.useCallback(async()=>{if(a?.getPairingTransports)try{const tt=await a.getPairingTransports();return{localUrl:tt.local,lanUrl:tt.lan,relayAvailable:tt.relayAvailable}}catch{}const v=Wl(),Z=v?`http://127.0.0.1:${v}`:Ao(window.location.origin)?window.location.origin:null;let Ke=null;try{const tt=fa(await eg());Ke=tt&&!Ao(tt)?tt:null}catch{}return{localUrl:Z,lanUrl:Ke,relayAvailable:!0}},[a]),Di=o.useCallback(async()=>{Xe(null),ze(null),J(null),Fe(!1),Ee(null),Qe("configure"),is(!0),lt(!0);const v=await Qa();ys(v),Ls(v.relayAvailable?"relay":v.lanUrl?"lan":"local")},[Qa]),Mi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Ht)){Xe(null),vs(!0);try{const v=ut.trim()||void 0;let Z,Ke,tt=!0;Xt==="local"?(Z=Ht.localUrl??void 0,Ke=!1):Xt==="lan"?(Z=Ht.lanUrl??void 0,Ke=Gt):Gt&&Ht.lanUrl?(Z=Ht.lanUrl,Ke=!0):(tt=!1,Ke=!0);const{pairing:Dt,server:Ds}=await a.createPairingSession({label:v,allowedClientKinds:["mobile","desktop"],serverUrl:Z,includeRelay:Ke,includeDirect:tt}),js=bd({pairingId:Dt.id,secret:Dt.secret,label:Ds.label,fingerprint:Dt.fingerprint??void 0,expiresAt:Dt.expiresAt,candidates:Ds.candidates}),_s=wd(js);ze(_s),J(await Ol.toDataURL(_s,{width:1024,margin:2,errorCorrectionLevel:"L"})),Fe(!1),ja.current=!1,Ee(Dt.id),Qe("result"),await zs({silent:!0})}catch(v){Xe(v instanceof Error?v.message:String(v))}finally{vs(!1)}}},[a,Ht,Xt,Gt,ut,zs]),Ya=o.useCallback(()=>{ht&&za(ht).then(v=>{v.ok&&(Fe(!0),window.setTimeout(()=>Fe(!1),2e3))})},[ht]),Ri=o.useCallback(async v=>{if(!a)return;const Z=v.clientKind==="desktop-local";Xe(null);try{if(await a.revokeClient(v.id),Z&&as()){const Ke=await Hr();await Gr({hosts:Ke.hosts,defaultHostId:Ke.defaultHostId,initialHostChoiceCompleted:Ke.initialHostChoiceCompleted,localClientToken:null}),xt(tt=>tt.map(Dt=>Dt.id===v.id?{...Dt,revokedAt:new Date().toISOString()}:Dt)),jd({apiBaseUrl:Ba(),clientToken:null,runtimeKey:"local"});return}await zs()}catch(Ke){Xe(Ke instanceof Error?Ke.message:String(Ke))}},[a,zs]),Li=o.useCallback(async()=>{if(a){Xe(null);try{await a.purgeRevokedClients(),await zs()}catch(v){Xe(v instanceof Error?v.message:String(v))}}},[a,zs]);o.useEffect(()=>{w(k)},[k]),o.useEffect(()=>{ss(!1)},[M]),o.useEffect(()=>{if(!M)return;const v=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||N()},2e3);return()=>{window.clearInterval(v)}},[N,M]),o.useEffect(()=>{let v=null,Z=Date.now();const Ke=()=>{const Dt=Date.now();Dt-Z>=1e3&&(ge(Dt),Z=Dt),v=requestAnimationFrame(Ke)};(typeof document>"u"||document.visibilityState==="visible")&&(v=requestAnimationFrame(Ke));const tt=()=>{document.visibilityState==="visible"&&v===null?v=requestAnimationFrame(Ke):document.visibilityState!=="visible"&&v!==null&&(cancelAnimationFrame(v),v=null)};return document.addEventListener("visibilitychange",tt),()=>{document.removeEventListener("visibilitychange",tt),v!==null&&cancelAnimationFrame(v)}},[]);const ws=M?r[M]:null,Gs=ws?.phase,sa=Gs==="ready",un=Gs==="degraded",vn=Ir(Gs),Xs=sa||(vn||un),Oi=ws?Math.max(0,ee-ws.updatedAtMs):0,na=un&&Oi>12e3,aa=No(Gs),On=aa==="error"?Bm(ws?.detail):null,ka=Hm(On),Fi=o.useMemo(()=>!f||!k?!1:JSON.stringify(f)!==JSON.stringify(k),[f,k]),os=o.useCallback(v=>{w(Z=>Z&&v(Z))},[]),Ki=o.useCallback(async()=>{if(!f)return;const v=tg(f);if(!v.sshCommand.trim()){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(v.remoteOpenchamber.mode==="external"&&!v.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(v.remoteOpenchamber.mode==="managed"&&v.remoteOpenchamber.bindHost==="0.0.0.0"&&!v.auth.aiworkerPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>yn.current?.focus(),0);return}if(!(v.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(v.auth.sshPassword?.enabled&&v.auth.sshPassword.value?.trim()&&v.auth.sshPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));v.auth.sshPassword.store=Z?"settings":"never",Z||(v.auth.sshPassword.value=void 0)}if(v.auth.aiworkerPassword?.enabled&&v.auth.aiworkerPassword.value?.trim()&&v.auth.aiworkerPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));v.auth.aiworkerPassword.store=Z?"settings":"never",Z||(v.auth.aiworkerPassword.value=void 0)}try{await h(v),D.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(Z){D.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:Z instanceof Error?Z.message:String(Z)})}}},[f,t,h]),ia=o.useCallback(async(v,Z)=>{const Ke=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Ke,`ssh ${Z}`,v),P(Ke),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(tt){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:tt instanceof Error?tt.message:String(tt)}),!1}},[C,P,t]),ra=o.useCallback(()=>{z||(L(null),ne(""))},[z]),zi=o.useCallback((v,Z)=>{if(ds(!1),Z){L(v),ne(qm(v));return}ia(v,v)},[ia]),Xa=o.useMemo(()=>Ni(l,pt,v=>[v.host,v.sshCommand]),[l,pt]),Ui=o.useCallback(v=>{const Z=(v||"").trim();if(!Z){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}mi(Z)},[t]),Fn=o.useCallback(async()=>{const v=q,Z=Q.trim();if(v){if(!Z){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}re(!0);try{await ia(v,Z)&&(L(null),ne(""))}finally{re(!1)}}},[ia,Q,q,t]),pn=o.useCallback(async()=>{if(k)try{await S(k.id);return}catch(v){if(!_m(v)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw v;const Ke={...k,localForward:{...k.localForward,preferredLocalPort:ji()}};await h(Ke),await S(Ke.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[S,k,t,h]),yn=o.useRef(null),oa=o.useRef(null),la=o.useCallback(async v=>{if(k){if(v==="localPort"){const Z={...k,localForward:{...k.localForward,preferredLocalPort:ji()}};try{await h(Z),await S(Z.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Ke){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Ke instanceof Error?Ke.message:String(Ke)})}return}ss(!0),window.setTimeout(()=>{if(v==="uiPassword"){yn.current?.focus();return}oa.current?.scrollIntoView({block:"center"})},0)}},[S,k,t,h]),me=o.useCallback(async v=>(await Tc(v,600)).map(Ke=>Ym(Ke)),[]),ls=o.useCallback(async()=>{if(f){A(!0),E(!0),_(null);try{const v=await me(f.id);V(v)}catch(v){V([]),_(v instanceof Error?v.message:String(v))}finally{E(!1)}}},[f,me]);o.useEffect(()=>{if(!F||!f)return;let v=!1;const Z=async()=>{try{const tt=await me(f.id);v||(V(tt),_(null))}catch(tt){v||_(tt instanceof Error?tt.message:String(tt))}};Z();const Ke=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Z()},1e3);return()=>{v=!0,window.clearInterval(Ke)}},[f,F,me]);const Kn=o.useMemo(()=>j.join(`
|
|
27
|
+
`),[j]),Za=o.useCallback(()=>{if(!Kn.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}za(Kn).then(v=>{v.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Kn,t]),ei=o.useCallback(async()=>{if(f)try{await Ec(f.id),V([]),D.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(v){D.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:v instanceof Error?v.message:String(v)})}},[f,t]),ti=o.useCallback(async()=>{if(!ws?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const v=ws.localUrl.trim();if(!v){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}mi(v)},[ws?.localUrl,t]),si=o.useCallback(()=>{if(!f)return;if(!Xs&&f.remoteOpenchamber.mode==="external"&&!f.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(!Xs&&f.remoteOpenchamber.mode==="managed"&&f.remoteOpenchamber.bindHost==="0.0.0.0"&&!f.auth.aiworkerPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>yn.current?.focus(),0);return}O(!0),(Xs?g(f.id):pn()).catch(Z=>{const Ke=Xs?sa?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t(Ke),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{O(!1)})},[Xs,pn,g,f,sa,t]),ni=o.useCallback(()=>{if(!f||vn)return;X(!0),(un?g(f.id).then(()=>pn()):T(f.id)).catch(Z=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{X(!1)})},[pn,g,f,vn,un,T,t]),_i=t(vn?"settings.remoteInstances.page.actions.connecting":un?na?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ca=!K&&!Y&&(Gs==="error"||Gs==="idle"||!Gs||un&&na)&&!vn,Na=t(sa?"settings.remoteInstances.sidebar.actions.disconnect":Xs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!f)return s.jsxs(es,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(_e,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Di()},children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[ms>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Li()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,st&&dt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):dt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[G.map(v=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:v.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),v.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ja(v.id)},children:t("settings.common.actions.cancel")})]},`pending-${v.id}`)),dt.map(v=>{const Z=v.clientKind==="desktop-local",Ke=v.lastUsedAt?Date.parse(v.lastUsedAt):Number.NaN,tt=!v.revokedAt&&(Z||Number.isFinite(Ke)&&Date.now()-Ke<9e4),Dt=v.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):tt?v.lastTransport==="relay"&&!Z?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Ke)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Dc(Ke,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",v.revokedAt?"bg-muted-foreground/20":tt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:v.label}),jo(v.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:jo(v.devicePlatform)}):null,Z?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:ye("typography-micro truncate",tt&&!v.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Dt})]})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ri(v)},disabled:!!v.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},v.id)})]})]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null]}):null,n?s.jsxs(_e,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ge(!0),disabled:ve,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe(!0),disabled:ve,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:Ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):de.map(v=>{const Z=ae[v.id],Ke=Z?Z.status==="ok"?"desktopHostSwitcher.status.connected":Z.status==="auth"?"desktopHostSwitcher.status.authRequired":Z.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":Z.status==="incompatible"?"desktopHostSwitcher.status.incompatible":Z.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",tt=Z?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",Z?tt?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ia(v.label)}),ue===v.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ye("typography-micro shrink-0",tt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Ke),tt&&typeof Z?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(Z.latencyMs))}):""]})]}),s.jsx("p",{className:ye("typography-micro text-muted-foreground truncate",v.apiUrl&&"font-mono"),children:v.relay&&!v.apiUrl?t("mobile.connect.relay.badge"):Ia(v.apiUrl||v.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ei(v.id)},disabled:ve||ue===v.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ue===v.id?s.jsx(R,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"star",className:"h-3.5 w-3.5"})}),v.relay&&!v.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Es(v),disabled:ve,children:[s.jsx(R,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ns(v.id)},disabled:ve,children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},v.id)})}),be?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:be}):null]}):null,n?s.jsx(Kt,{open:Ue,onOpenChange:Pe,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ut()},children:[s.jsx(Je,{className:"h-8",value:Le,onChange:v=>oe(v.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ve}),s.jsx(Je,{className:"h-8",value:he,onChange:v=>Me(v.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ve,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Je,{className:"h-8",value:$e,onChange:v=>Ve(v.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ve}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),We.map(v=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:v.name,onChange:Z=>se(Ke=>Ke.map(tt=>tt.id===v.id?{...tt,name:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ve}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:v.value,onChange:Z=>se(Ke=>Ke.map(tt=>tt.id===v.id?{...tt,value:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ve}),s.jsx("button",{type:"button",onClick:()=>se(Z=>Z.filter(Ke=>Ke.id!==v.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:ve,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},v.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(v=>[...v,gr()]),disabled:ve,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe(!1),disabled:ve,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:ve||!he.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Kt,{open:!!pe,onOpenChange:v=>{v||Ce(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Wa()},children:[s.jsx(Je,{className:"h-8",value:Re,onChange:v=>Ye(v.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ve}),s.jsx(Je,{className:"h-8",value:W,onChange:v=>ke(v.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ve,autoFocus:!0}),s.jsx(Je,{className:"h-8",value:Ae,onChange:v=>He(v.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ve}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),at.map(v=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:v.name,onChange:Z=>nt(Ke=>Ke.map(tt=>tt.id===v.id?{...tt,name:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ve}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:v.value,onChange:Z=>nt(Ke=>Ke.map(tt=>tt.id===v.id?{...tt,value:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ve}),s.jsx("button",{type:"button",onClick:()=>nt(Z=>Z.filter(Ke=>Ke.id!==v.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:ve,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},v.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>nt(v=>[...v,gr()]),disabled:ve,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(null),disabled:ve,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:ve,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Kt,{open:we,onOpenChange:Ge,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ot()},children:[s.jsx(Je,{className:"h-8",value:ie,onChange:v=>je(v.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:ve,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ge(!1),disabled:ve,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:ve||!ie.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:De,onOpenChange:lt,children:s.jsxs(zt,{className:ct==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),ct==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:v=>{v.preventDefault(),Mi()},children:[s.jsx(Je,{className:"h-8",value:ut,onChange:v=>St(v.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Ht?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Ht?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Ht?.localUrl}].map(v=>{const Z=Xt===v.key;return s.jsxs("div",{className:ye("flex items-start gap-2 py-0.5",v.available?"cursor-pointer":"opacity-45"),onClick:()=>{v.available&&Ls(v.key)},role:"presentation",children:[s.jsx(br,{checked:Z,disabled:!v.available,onChange:()=>Ls(v.key),ariaLabel:v.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ye("typography-ui-label font-normal",Z?"text-foreground":"text-foreground/70"),children:v.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:v.hint})]})]},v.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(or,{checked:Gt,onChange:is,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Xt==="relay"&&Ht?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(or,{checked:Gt,onChange:is,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lt(!1),disabled:kt,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:kt||!Ht,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ht?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:ht}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ya,children:[s.jsx(R,{name:fe?"check":"file-copy",className:ye("h-3.5 w-3.5",fe&&"text-[var(--status-success)]")}),t(fe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>lt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(_e,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:qa,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(v=>{const Z=r[v.id],Ke=v.nickname?.trim()||v.sshParsed?.destination||v.id,tt=Z?.phase,Dt=tt==="ready",Ds=No(tt),js=Ds==="error"?Z?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 py-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Io(tt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ke})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(So(Ds)),Ds==="connecting"?` · ${t(ko(tt))}`:"",Dt&&Z?.localUrl?` · ${Z.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Dt?s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ui(Z?.localUrl),children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Dt?g(v.id):S(v.id)).catch(ks=>D.error(t(Dt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:ks instanceof Error?ks.message:String(ks)}))},children:[Dt?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Dt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>P(v.id),children:[s.jsx(R,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(v.id).catch(ks=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ks instanceof Error?ks.message:String(ks)}))},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),js?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:js}):null]},v.id)})}):null,n?s.jsx(Kt,{open:gs,onOpenChange:ds,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Qs,{value:Ts,onChange:ce,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Ts==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Je,{className:"h-8",value:pt,onChange:v=>bt(v.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),m?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Xa.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:Xa.map(v=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-2.5 last:border-b-0",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[v.host,v.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:v.sshCommand})]}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zi(v.host,v.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${v.source}:${v.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Ti()},children:[s.jsx(Je,{className:"h-8",value:Bt,onChange:v=>rs(v.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:x}),s.jsx(Je,{className:"h-8",value:Qt,onChange:v=>Yt(v.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:x,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ds(!1),disabled:x,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:x||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!q,onOpenChange:v=>{v||ra()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Fn()},children:[s.jsx(Je,{value:Q,onChange:v=>ne(v.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ra,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const bn=f.remoteOpenchamber.mode==="managed",da=bn&&f.remoteOpenchamber.bindHost==="0.0.0.0",wn=da&&!f.auth.aiworkerPassword?.value?.trim(),jn=f.nickname?.trim()||f.sshParsed?.destination||f.id;return s.jsx(Kt,{open:!!f,onOpenChange:v=>{v||P(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${rr} truncate`,children:jn}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${Io(Gs)}`}),s.jsx("span",{className:"text-foreground",children:t(So(aa))}),aa==="connecting"?s.jsx("span",{children:t(ko(Gs))}):null,ws?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ws.localUrl}):null,na?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{type:"button",variant:Xs?"outline":"default",size:"xs",className:"!font-normal",onClick:si,disabled:K||Y,children:[Xs?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),Na]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ni,disabled:!ca,children:[s.jsx(R,{name:"refresh",className:`h-3.5 w-3.5 ${vn||un&&!na?"animate-spin":""}`}),_i]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ls()},children:[s.jsx(R,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(f.id).then(()=>{P(null),D.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(Z=>{D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Z instanceof Error?Z.message:String(Z)})})},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),aa==="error"&&ws?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:ws.detail}),ka?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(ka)}):null,On&&!ka?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{la(On)},children:t(On==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":On==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,ws?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:ws.localUrl})]}):null]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Je,{className:"h-7 md:max-w-xl",value:f.sshCommand,onChange:v=>os(Z=>({...Z,sshCommand:v.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Je,{className:"h-7 md:max-w-sm",value:f.nickname||"",onChange:v=>os(Z=>({...Z,nickname:v.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(It,{value:f.remoteOpenchamber.mode,onValueChange:v=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,mode:v==="external"?"external":"managed"}})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ot,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Mn,{open:bs,onOpenChange:ss,children:[s.jsxs(Rn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:jl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(R,{name:bs?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Ln,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:ye(Cs,"tabular-nums"),value:f.connectionTimeoutSec,onValueChange:v=>{os(Z=>({...Z,connectionTimeoutSec:Number.isFinite(v)?v:Z.connectionTimeoutSec}))}})]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",ref:oa,children:s.jsx($s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Cs,"tabular-nums"),value:f.remoteOpenchamber.preferredPort,onValueChange:v=>{os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,preferredPort:Number.isFinite(v)&&v>0?v:void 0}}))},onClear:()=>{os(v=>({...v,remoteOpenchamber:{...v.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),bn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(It,{value:f.remoteOpenchamber.installMethod,onValueChange:v=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,installMethod:v==="npm"||v==="bun"?v:"auto"}})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ot,{value:"bun",children:"bun"}),s.jsx(ot,{value:"npm",children:"npm"})]})]})]}):null,bn?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(vi,{checked:da,onCheckedChange:v=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,bindHost:v?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),da?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,bn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(vi,{checked:f.remoteOpenchamber.keepRunning,onCheckedChange:v=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,keepRunning:v}}))})})]}):null]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(It,{value:f.localForward.bindHost,onValueChange:v=>{v==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||os(Z=>({...Z,localForward:{...Z.localForward,bindHost:v==="localhost"||v==="0.0.0.0"?v:"127.0.0.1"}}))},children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[240px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ot,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ot,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Cs,"tabular-nums"),value:f.localForward.preferredLocalPort,onValueChange:v=>{os(Z=>({...Z,localForward:{...Z.localForward,preferredLocalPort:Number.isFinite(v)&&v>0?v:void 0}}))},onClear:()=>{os(v=>({...v,localForward:{...v.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>os(v=>({...v,localForward:{...v.localForward,preferredLocalPort:ji()}})),children:s.jsx(R,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${f.localForward.bindHost}:${f.localForward.preferredLocalPort||"auto"} → ${f.sshParsed?.destination||f.nickname||"remote"}:${f.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Je,{className:"h-7 md:max-w-sm",type:"password",value:f.auth.sshPassword?.value||"",onChange:v=>os(Z=>({...Z,auth:{...Z.auth,sshPassword:{enabled:v.target.value.trim().length>0,value:v.target.value,store:Z.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t(da?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(bn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Je,{className:ye("h-7 md:max-w-sm",wn&&"border-[var(--status-error)]"),type:"password",ref:yn,"aria-invalid":wn,value:f.auth.aiworkerPassword?.value||"",onChange:v=>os(Z=>({...Z,auth:{...Z.auth,aiworkerPassword:{enabled:v.target.value.trim().length>0,value:v.target.value,store:Z.auth.aiworkerPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),wn?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[f.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,f.portForwards.map((v,Z)=>{const Ke=Ct=>{os(Wt=>({...Wt,portForwards:Wt.portForwards.map((zn,Mt)=>Mt===Z?Ct(zn):zn)}))},tt=v.type==="remote"?"Local target":"Local listen",Dt=v.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Ds=v.type==="remote"?"Remote listen":"Remote target",js=v.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",_s=Po(v.localHost||"localhost",v.localPort),ks=Po(v.remoteHost||"localhost",v.remotePort),Ws=v.type==="local"&&typeof v.localPort=="number"&&v.localPort>0,Sa=Ws?`http://${Qm(v.localHost)}:${v.localPort}`:"",mn=!!$[v.id],qs=v.type==="local"?t("settings.remoteInstances.page.forwardType.local"):v.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Mn,{open:mn,onOpenChange:Ct=>{U(Wt=>({...Wt,[v.id]:Ct}))},className:`${Z>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Rn,{className:"flex items-center gap-2 group",children:[s.jsx(R,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${mn?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Gm(v)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:qs})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vi,{checked:v.enabled,onCheckedChange:Ct=>Ke(Wt=>({...Wt,enabled:Ct})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>os(Ct=>({...Ct,portForwards:Ct.portForwards.filter(Wt=>Wt.id!==v.id)})),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ln,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Jm(v.type))})]})})}),s.jsxs(It,{value:v.type,onValueChange:Ct=>Ke(Wt=>({...Wt,type:Ct==="dynamic"||Ct==="remote"?Ct:"local"})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ot,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:tt,hint:Dt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:v.localHost||"127.0.0.1",onChange:Ct=>Ke(Wt=>({...Wt,localHost:Ct.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Cs,"tabular-nums"),value:v.localPort,onValueChange:Ct=>{Ke(Wt=>({...Wt,localPort:Number.isFinite(Ct)&&Ct>0?Ct:void 0}))},onClear:()=>{Ke(Ct=>({...Ct,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),v.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:Ds,hint:js})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:v.remoteHost||"",onChange:Ct=>Ke(Wt=>({...Wt,remoteHost:Ct.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Cs,"tabular-nums"),value:v.remotePort,onValueChange:Ct=>{Ke(Wt=>({...Wt,remotePort:Number.isFinite(Ct)&&Ct>0?Ct:void 0}))},onClear:()=>{Ke(Ct=>({...Ct,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:v.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):v.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ks}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ks}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Ws?s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(Sa).then(Ct=>{Ct||D.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},v.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const v=Wm();os(Z=>({...Z,portForwards:[...Z.portForwards,v]})),U(Z=>({...Z,[v.id]:!0}))},children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ki()},disabled:!Fi||x,children:t("settings.common.actions.saveChanges")}),ws?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{za(ws.localUrl||"").then(v=>{v.ok&&D.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ti()},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,d?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:d}):null]})}),s.jsx(Kt,{open:F,onOpenChange:A,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:f?.nickname?.trim()||f?.sshParsed?.destination||f?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Za,disabled:I||!Kn.trim(),children:[s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ei()},disabled:I,children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),I?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):B?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:B}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:j.length>0?j.join(`
|
|
28
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!q,onOpenChange:v=>{v||ra()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:v=>{v.preventDefault(),Fn()},children:[s.jsx(Je,{value:Q,onChange:v=>ne(v.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ra,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.common.actions.create")})]})]})]})})]})})},ng="__add_provider__",ag=()=>{const t=hn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},ig=({onItemSelect:t})=>{const{t:e}=it(),a=Us(),n=Ze(h=>kl(h,a)),i=Ze(h=>h.selectedProviderId),r=Ze(h=>h.setSelectedProvider),l=Bs(h=>h.activeProjectId),[p,m]=o.useState({}),x=o.useMemo(()=>a||ag(),[l,a]),d=Ze(h=>h.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){m({});return}let h=!1;return(async()=>{const b=n.map(async S=>{try{const g=x?`?directory=${encodeURIComponent(x)}`:"",T=await mt(`/api/provider/${encodeURIComponent(S.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!T.ok)return;const M=await T.json().catch(()=>null),P=M?.sources??M?.data?.sources;if(!P||h)return;m(k=>({...k,[S.id]:P}))}catch{}});await Promise.all(b)})(),()=>{h=!0}},[x,n]);const y="bg-background",c=o.useMemo(()=>n.filter(h=>!!p[h.id]?.project?.exists),[n,p]),N=o.useMemo(()=>n.filter(h=>!p[h.id]?.project?.exists),[n,p]);return s.jsxs("div",{className:ye("flex h-full flex-col",y),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${dn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ga,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(ng),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[N.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),N.map(h=>s.jsx(To,{provider:h,selectedProviderId:i,onSelect:()=>{r(h.id),t?.()}},h.id))]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",N.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.map(h=>s.jsx(To,{provider:h,selectedProviderId:i,onSelect:()=>{r(h.id),t?.()}},h.id))]})]})})]})},To=t=>{const e=gt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,p=a.id,m=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==m?(x=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",m),e[0]=m,e[1]=x):x=e[1];let d;e[2]!==a.id?(d=s.jsx(Bn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const y=a.name||a.id;let c;e[4]!==y?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:y}),e[4]=y,e[5]=c):c=e[5];let N;e[6]!==r?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=N):N=e[7];let h;e[8]!==i||e[9]!==d||e[10]!==c||e[11]!==N?(h=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[d,c,N]}),e[8]=i,e[9]=d,e[10]=c,e[11]=N,e[12]=h):h=e[12];let C;return e[13]!==a.id||e[14]!==x||e[15]!==h?(C=s.jsx("div",{className:x,children:h},p),e[13]=a.id,e[14]=x,e[15]=h,e[16]=C):C=e[16],C},rg=t=>t,og=(t,e,a)=>t&&!e&&!a,Eo=t=>typeof t=="object"&&t!==null,ql=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},lg=t=>{if(!Eo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>Eo(i)));return e},Do=t=>t.length===0?!0:t.some(e=>ql(e)==="api"),Mo=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>ql(e)==="oauth"),cg=t=>t!=="claude-code",Ro=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,dg=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),ug=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Pr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},$n="__custom_provider__",pg=/^[a-z0-9][a-z0-9-_]*$/,Jl=/^https?:\/\//,mg=/^\{env:([^}]+)\}$/;let gg=0;const Ii=()=>`row-${gg++}`,Ar=()=>({row:Ii(),id:"",name:""}),Tr=()=>({row:Ii(),key:"",value:""}),fg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Ar()],headers:[Tr()]});function hg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function xg(t){const e=t.trim();if(!e)return{};const n=e.match(mg)?.[1]?.trim();return n?{env:n}:{key:e}}function vg(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Jl.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(Pr)).has(r.npm)})}function Lo(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&vg(t):!1}function Oo(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function yg(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(x=>typeof x[0]=="string"&&typeof x[1]=="string").map(([x,d])=>({row:Ii(),key:x,value:d})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([x,d])=>({id:x,name:d&&typeof d=="object"&&"name"in d&&typeof d.name=="string"?d.name:x})):[],l=r.length>0?r.map(x=>({row:Ii(),id:typeof x?.id=="string"?x.id:"",name:typeof x?.name=="string"?x.name:typeof x?.id=="string"?x.id:""})):[Ar()],p=Array.isArray(t.env)?t.env.find(x=>typeof x=="string"&&x.trim().length>0)?.trim():void 0,m=r.find(x=>"api"in x);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:hg(m?.api?.npm),baseURL:a,apiKey:p?`{env:${p}}`:"",models:l,headers:i.length>0?i:[Tr()]}}function bg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=xg(t.form.apiKey),l=t.disabledProviders??[],p=t.editingProviderID?.trim(),m=e?pg.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),x=a?void 0:t.t("settings.providers.page.custom.error.name.required"),d=n?Jl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),c=!!(i||r||p&&t.allowExistingAuth&&p===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),N=l.includes(e),C=m||!!(p&&p===e)?void 0:t.existingProviderIDs.has(e)&&!N?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,S=t.form.models.map(A=>{const I=A.id.trim(),E=I?b.has(I)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(I):t.t("settings.providers.page.custom.error.required"),B=A.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:E,name:B}}),g=S.every(A=>!A.id&&!A.name),T=Object.fromEntries(t.form.models.map(A=>[A.id.trim(),{name:A.name.trim()}])),M=new Set,P=t.form.headers.map(A=>{const I=A.key.trim(),E=A.value.trim();if(!I&&!E)return{};const B=I?M.has(I.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void M.add(I.toLowerCase()):t.t("settings.providers.page.custom.error.required"),_=E?void 0:t.t("settings.providers.page.custom.error.required");return{key:B,value:_}}),k=P.every(A=>!A.key&&!A.value),f=Object.fromEntries(t.form.headers.map(A=>({key:A.key.trim(),value:A.value.trim()})).filter(A=>A.key&&A.value).map(A=>[A.key,A.value])),w={providerID:m??C,name:x,baseURL:d,apiKey:c};return!m&&!C&&!x&&!d&&!c&&g&&k?{err:w,models:S,headers:P,result:{providerID:e,name:a,apiKey:r,config:{npm:Pr[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(f).length>0?{headers:f}:{}},models:T}}}:{err:w,models:S,headers:P}}function wg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function jg(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Fo=t=>{const e=gt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:p,authFailureHint:m,onSubmit:x,onCancel:d,onDisconnect:y}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const N=c,h=i===void 0?!1:i,C=r===void 0?"create":r,b=p===void 0?!1:p,S=m===void 0?null:m,{t:g}=it(),T=C==="edit";let M;e[2]!==l?(M=()=>l??fg(),e[2]=l,e[3]=M):M=e[3];const[P,k]=o.useState(M);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f={},e[4]=f):f=e[4];const[w,F]=o.useState(f);let A;e[5]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[5]=A):A=e[5];const[I,E]=o.useState(A);let B;e[6]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[6]=B):B=e[6];const[_,j]=o.useState(B),V=o.useRef(null);let q,L;e[7]!==l||e[8]!==T?(q=()=>{l&&(T&&V.current===l.providerID||(V.current=T?l.providerID:null,k(l),F({}),E([]),j([])))},L=[l,T],e[7]=l,e[8]=T,e[9]=q,e[10]=L):(q=e[9],L=e[10]),o.useEffect(q,L);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(Nt,Tt)=>{k(Ut=>({...Ut,[Nt]:Tt})),F(Ut=>({...Ut,[Nt]:void 0}))},e[11]=Q):Q=e[11];const ne=Q;let z;e[12]===Symbol.for("react.memo_cache_sentinel")?(z=(Nt,Tt,Ut)=>{k(Ot=>({...Ot,models:Ot.models.map((ns,Es)=>Es===Nt?{...ns,[Tt]:Ut}:ns)})),E(Ot=>{const ns=[...Ot];return ns[Nt]={...ns[Nt]??{},[Tt]:void 0},ns})},e[12]=z):z=e[12];const re=z;let $;e[13]===Symbol.for("react.memo_cache_sentinel")?($=(Nt,Tt,Ut)=>{k(Ot=>({...Ot,headers:Ot.headers.map((ns,Es)=>Es===Nt?{...ns,[Tt]:Ut}:ns)})),j(Ot=>{const ns=[...Ot];return ns[Nt]={...ns[Nt]??{},[Tt]:void 0},ns})},e[13]=$):$=e[13];const U=$;let K;e[14]!==b||e[15]!==h||e[16]!==N||e[17]!==a||e[18]!==P||e[19]!==T||e[20]!==x||e[21]!==g?(K=async Nt=>{if(Nt.preventDefault(),h)return;const Tt=bg({form:P,t:((Ut,Ot)=>g(Ut,Ot)),existingProviderIDs:a,disabledProviders:N,editingProviderID:T?P.providerID:void 0,allowExistingAuth:T&&b});F(Tt.err),E(Tt.models),j(Tt.headers),Tt.result&&await x(Tt.result)},e[14]=b,e[15]=h,e[16]=N,e[17]=a,e[18]=P,e[19]=T,e[20]=x,e[21]=g,e[22]=K):K=e[22];const O=K;let Y;e[23]!==T||e[24]!==g?(Y=g(T?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=T,e[24]=g,e[25]=Y):Y=e[25];let X;e[26]!==g?(X=g("settings.providers.page.custom.description"),e[26]=g,e[27]=X):X=e[27];let ee;e[28]!==X?(ee=s.jsx("p",{className:Vn,children:X}),e[28]=X,e[29]=ee):ee=e[29];let ge;e[30]!==S?(ge=S?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:S}):null,e[30]=S,e[31]=ge):ge=e[31];let de;e[32]!==g?(de=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=de):de=e[33];let xe;e[34]!==g?(xe=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=xe):xe=e[35];const ae=P.providerID;let te;e[36]===Symbol.for("react.memo_cache_sentinel")?(te=Nt=>ne("providerID",Nt.target.value),e[36]=te):te=e[36];let ue;e[37]!==g?(ue=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=ue):ue=e[38];const Ie=!T,Ne=T||h,Se=!!w.providerID;let ve;e[39]!==g?(ve=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=ve):ve=e[40];let Oe;e[41]!==P.providerID||e[42]!==ue||e[43]!==Ie||e[44]!==Ne||e[45]!==Se||e[46]!==ve?(Oe=s.jsx(Je,{value:ae,onChange:te,placeholder:ue,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Ie,disabled:Ne,"aria-invalid":Se,"aria-label":ve}),e[41]=P.providerID,e[42]=ue,e[43]=Ie,e[44]=Ne,e[45]=Se,e[46]=ve,e[47]=Oe):Oe=e[47];let Le;e[48]!==w.providerID?(Le=w.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.providerID}):null,e[48]=w.providerID,e[49]=Le):Le=e[49];let oe;e[50]!==de||e[51]!==xe||e[52]!==Oe||e[53]!==Le?(oe=s.jsxs(qt,{label:de,info:xe,children:[Oe,Le]}),e[50]=de,e[51]=xe,e[52]=Oe,e[53]=Le,e[54]=oe):oe=e[54];let he;e[55]!==g?(he=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=he):he=e[56];let Me;e[57]!==g?(Me=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=Me):Me=e[58];const $e=P.protocol;let Ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ve=Nt=>{Nt in Pr&&k(Tt=>({...Tt,protocol:Nt}))},e[59]=Ve):Ve=e[59];let We;e[60]!==g?(We=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=We):We=e[61];let se;e[62]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Rt,{}),e[62]=se):se=e[62];let ie;e[63]!==We?(ie=s.jsx(Pt,{"aria-label":We,className:"w-full",children:se}),e[63]=We,e[64]=ie):ie=e[64];let je;e[65]!==g?(je=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=je):je=e[66];let be;e[67]!==je?(be=s.jsx(ot,{value:"openai-chat",children:je}),e[67]=je,e[68]=be):be=e[68];let Te;e[69]!==g?(Te=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=Te):Te=e[70];let Ue;e[71]!==Te?(Ue=s.jsx(ot,{value:"openai-responses",children:Te}),e[71]=Te,e[72]=Ue):Ue=e[72];let Pe;e[73]!==g?(Pe=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=Pe):Pe=e[74];let we;e[75]!==Pe?(we=s.jsx(ot,{value:"anthropic-messages",children:Pe}),e[75]=Pe,e[76]=we):we=e[76];let Ge;e[77]!==be||e[78]!==Ue||e[79]!==we?(Ge=s.jsxs(At,{children:[be,Ue,we]}),e[77]=be,e[78]=Ue,e[79]=we,e[80]=Ge):Ge=e[80];let pe;e[81]!==h||e[82]!==P.protocol||e[83]!==ie||e[84]!==Ge?(pe=s.jsxs(It,{value:$e,onValueChange:Ve,disabled:h,children:[ie,Ge]}),e[81]=h,e[82]=P.protocol,e[83]=ie,e[84]=Ge,e[85]=pe):pe=e[85];let Ce;e[86]!==he||e[87]!==Me||e[88]!==pe?(Ce=s.jsx(qt,{label:he,info:Me,children:pe}),e[86]=he,e[87]=Me,e[88]=pe,e[89]=Ce):Ce=e[89];let Re;e[90]!==g?(Re=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=Re):Re=e[91];let Ye;e[92]!==g?(Ye=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=Ye):Ye=e[93];const W=P.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=Nt=>ne("name",Nt.target.value),e[94]=ke):ke=e[94];let Ae;e[95]!==g?(Ae=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=Ae):Ae=e[96];const He=!!w.name;let at;e[97]!==g?(at=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=at):at=e[98];let nt;e[99]!==P.name||e[100]!==Ae||e[101]!==He||e[102]!==at?(nt=s.jsx(Je,{value:W,onChange:ke,placeholder:Ae,className:"h-8 rounded-md px-3","aria-invalid":He,"aria-label":at}),e[99]=P.name,e[100]=Ae,e[101]=He,e[102]=at,e[103]=nt):nt=e[103];let dt;e[104]!==w.name?(dt=w.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.name}):null,e[104]=w.name,e[105]=dt):dt=e[105];let xt;e[106]!==Re||e[107]!==Ye||e[108]!==nt||e[109]!==dt?(xt=s.jsxs(qt,{label:Re,info:Ye,children:[nt,dt]}),e[106]=Re,e[107]=Ye,e[108]=nt,e[109]=dt,e[110]=xt):xt=e[110];let G;e[111]!==g?(G=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=G):G=e[112];let Be;e[113]!==g?(Be=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=Be):Be=e[114];const st=P.baseURL;let rt;e[115]===Symbol.for("react.memo_cache_sentinel")?(rt=Nt=>ne("baseURL",Nt.target.value),e[115]=rt):rt=e[115];let ut;e[116]!==g?(ut=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=ut):ut=e[117];const St=!!w.baseURL;let et;e[118]!==g?(et=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=et):et=e[119];let Xe;e[120]!==P.baseURL||e[121]!==ut||e[122]!==St||e[123]!==et?(Xe=s.jsx(Je,{value:st,onChange:rt,placeholder:ut,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":St,"aria-label":et}),e[120]=P.baseURL,e[121]=ut,e[122]=St,e[123]=et,e[124]=Xe):Xe=e[124];let ht;e[125]!==w.baseURL?(ht=w.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.baseURL}):null,e[125]=w.baseURL,e[126]=ht):ht=e[126];let ze;e[127]!==G||e[128]!==Be||e[129]!==Xe||e[130]!==ht?(ze=s.jsxs(qt,{label:G,info:Be,children:[Xe,ht]}),e[127]=G,e[128]=Be,e[129]=Xe,e[130]=ht,e[131]=ze):ze=e[131];let jt;e[132]!==g?(jt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=jt):jt=e[133];let Ee;e[134]!==b||e[135]!==T||e[136]!==g?(Ee=g(T&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=T,e[136]=g,e[137]=Ee):Ee=e[137];const wt=P.apiKey;let J;e[138]===Symbol.for("react.memo_cache_sentinel")?(J=Nt=>ne("apiKey",Nt.target.value),e[138]=J):J=e[138];let fe;e[139]!==b||e[140]!==T||e[141]!==g?(fe=g(T&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=T,e[141]=g,e[142]=fe):fe=e[142];const Fe=!!w.apiKey;let De;e[143]!==g?(De=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=De):De=e[144];let lt;e[145]!==P.apiKey||e[146]!==fe||e[147]!==Fe||e[148]!==De?(lt=s.jsx(Je,{type:"password",value:wt,onChange:J,placeholder:fe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Fe,"aria-label":De}),e[145]=P.apiKey,e[146]=fe,e[147]=Fe,e[148]=De,e[149]=lt):lt=e[149];let ct;e[150]!==w.apiKey?(ct=w.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.apiKey}):null,e[150]=w.apiKey,e[151]=ct):ct=e[151];let Qe;e[152]!==jt||e[153]!==Ee||e[154]!==lt||e[155]!==ct?(Qe=s.jsxs(qt,{label:jt,info:Ee,children:[lt,ct]}),e[152]=jt,e[153]=Ee,e[154]=lt,e[155]=ct,e[156]=Qe):Qe=e[156];let kt;e[157]!==Y||e[158]!==ee||e[159]!==ge||e[160]!==oe||e[161]!==Ce||e[162]!==xt||e[163]!==ze||e[164]!==Qe?(kt=s.jsxs(_e,{title:Y,divider:!1,settingsItem:"providers.custom",contentClassName:Js,children:[ee,ge,oe,Ce,xt,ze,Qe]}),e[157]=Y,e[158]=ee,e[159]=ge,e[160]=oe,e[161]=Ce,e[162]=xt,e[163]=ze,e[164]=Qe,e[165]=kt):kt=e[165];let vs;e[166]!==g?(vs=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=vs):vs=e[167];let Xt;if(e[168]!==P.models||e[169]!==I||e[170]!==g){let Nt;e[172]!==P.models.length||e[173]!==I||e[174]!==g?(Nt=(Tt,Ut)=>s.jsx("div",{className:`${Fs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(Je,{value:Tt.id,onChange:Ot=>re(Ut,"id",Ot.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),I[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(Je,{value:Tt.name,onChange:Ot=>re(Ut,"name",Ot.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),I[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Ut]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:fs,disabled:P.models.length<=1,onClick:()=>{P.models.length<=1||(k(Ot=>({...Ot,models:Ot.models.filter((ns,Es)=>Es!==Ut)})),E(Ot=>Ot.filter((ns,Es)=>Es!==Ut)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[172]=P.models.length,e[173]=I,e[174]=g,e[175]=Nt):Nt=e[175],Xt=P.models.map(Nt),e[168]=P.models,e[169]=I,e[170]=g,e[171]=Xt}else Xt=e[171];let Ls;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ls=()=>{k(kg),E(Ng)},e[176]=Ls):Ls=e[176];let Gt;e[177]!==g?(Gt=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=Gt):Gt=e[178];let is;e[179]!==Gt?(is=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ls,children:Gt}),e[179]=Gt,e[180]=is):is=e[180];let Ht;e[181]!==vs||e[182]!==Xt||e[183]!==is?(Ht=s.jsxs(_e,{title:vs,contentClassName:Js,children:[Xt,is]}),e[181]=vs,e[182]=Xt,e[183]=is,e[184]=Ht):Ht=e[184];let ys;e[185]!==g?(ys=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=ys):ys=e[186];let ms;e[187]!==g?(ms=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=ms):ms=e[188];let gs;e[189]!==ms?(gs=s.jsx("p",{className:Vn,children:ms}),e[189]=ms,e[190]=gs):gs=e[190];let ds;if(e[191]!==P.headers||e[192]!==_||e[193]!==g){let Nt;e[195]!==P.headers.length||e[196]!==_||e[197]!==g?(Nt=(Tt,Ut)=>s.jsx("div",{className:`${Fs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Je,{value:Tt.key,onChange:Ot=>U(Ut,"key",Ot.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),_[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Je,{value:Tt.value,onChange:Ot=>U(Ut,"value",Ot.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),_[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Ut]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:fs,disabled:P.headers.length<=1,onClick:()=>{P.headers.length<=1||(k(Ot=>({...Ot,headers:Ot.headers.filter((ns,Es)=>Es!==Ut)})),j(Ot=>Ot.filter((ns,Es)=>Es!==Ut)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[195]=P.headers.length,e[196]=_,e[197]=g,e[198]=Nt):Nt=e[198],ds=P.headers.map(Nt),e[191]=P.headers,e[192]=_,e[193]=g,e[194]=ds}else ds=e[194];let Ts;e[199]===Symbol.for("react.memo_cache_sentinel")?(Ts=()=>{k(Sg),j(Cg)},e[199]=Ts):Ts=e[199];let ce;e[200]!==g?(ce=g("settings.providers.page.custom.headers.add"),e[200]=g,e[201]=ce):ce=e[201];let pt;e[202]!==ce?(pt=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ts,children:ce}),e[202]=ce,e[203]=pt):pt=e[203];let bt;e[204]!==ys||e[205]!==gs||e[206]!==ds||e[207]!==pt?(bt=s.jsxs(_e,{title:ys,contentClassName:Js,children:[gs,ds,pt]}),e[204]=ys,e[205]=gs,e[206]=ds,e[207]=pt,e[208]=bt):bt=e[208];let Qt;e[209]!==h||e[210]!==d||e[211]!==g?(Qt=d?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:h,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=h,e[210]=d,e[211]=g,e[212]=Qt):Qt=e[212];let Yt;e[213]!==h||e[214]!==y||e[215]!==g?(Yt=y?s.jsx(H,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{y()},disabled:h,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=h,e[214]=y,e[215]=g,e[216]=Yt):Yt=e[216];let Bt;e[217]!==h||e[218]!==T||e[219]!==g?(Bt=g(h?"settings.providers.page.actions.saving":T?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=h,e[218]=T,e[219]=g,e[220]=Bt):Bt=e[220];let rs;e[221]!==h||e[222]!==Bt?(rs=s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:h,children:Bt}),e[221]=h,e[222]=Bt,e[223]=rs):rs=e[223];let bs;e[224]!==Qt||e[225]!==Yt||e[226]!==rs?(bs=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,rs]}),e[224]=Qt,e[225]=Yt,e[226]=rs,e[227]=bs):bs=e[227];let ss;return e[228]!==O||e[229]!==kt||e[230]!==Ht||e[231]!==bt||e[232]!==bs?(ss=s.jsxs("form",{onSubmit:O,className:"space-y-0",children:[kt,Ht,bt,bs]}),e[228]=O,e[229]=kt,e[230]=Ht,e[231]=bt,e[232]=bs,e[233]=ss):ss=e[233],ss};function kg(t){return{...t,models:[...t.models,Ar()]}}function Ng(t){return[...t,{}]}function Sg(t){return{...t,headers:[...t.headers,Tr()]}}function Cg(t){return[...t,{}]}const Ig=(t,e)=>!!e&&t!=="claude-code",Pg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,ta=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ss=t=>typeof t=="string"&&t.length>0?t:void 0,Ag=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ta(a))continue;const n=Ss(a.value);n!==void 0&&e.push({value:n,label:Ss(a.label)??n,...Ss(a.hint)?{hint:Ss(a.hint)}:{}})}return e},Tg=t=>{if(!ta(t))return;const e=Ss(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},Eg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ta(a))continue;const n=Ss(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?Ag(a.options):[];if(i==="select"&&r.length===0)continue;const l=Tg(a.when);e.push({type:i,key:n,message:Ss(a.message)??n,options:r,...Ss(a.placeholder)?{placeholder:Ss(a.placeholder)}:{},...l?{when:l}:{}})}return e},Dg=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},Er=(t,e)=>t.filter(a=>Dg(a,e)),Mg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Rg=(t,e)=>Er(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Lg=(t,e)=>{const a={};for(const n of Er(t,e))a[n.key]=(e[n.key]??"").trim();return a},Og=t=>{const e=ta(t)?t:{},a=ta(e.data)?e.data:e,n=Ss(a.url)??Ss(a.verification_uri_complete)??Ss(a.verification_uri),i=Ss(a.instructions)??Ss(a.message);if(!n&&!i)return null;const r=Ss(a.user_code)??Ss(a.userCode)??(i?Pg.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Ko=(t,e,a)=>{const n=ta(t)?t:{},i=ta(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return Ss(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Xi={phase:"idle"},zo=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=it(),[r,l]=o.useState(Xi),[p,m]=o.useState({}),[x,d]=o.useState(""),y=o.useRef(null);o.useEffect(()=>()=>y.current?.abort(),[]);const c=r.phase==="idle"?null:r.methodIndex,N=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,h=async(f,w,F)=>{const A=await za(f);if(A.ok){D.success(i(w));return}console.error("Failed to copy OAuth value:",A.error),D.error(i(F))},C=async(f,w)=>{const F=new AbortController;y.current?.abort(),y.current=F;try{const A=await hn.getSdkClient().provider.oauth.callback({providerID:t,method:f,...w?{code:w}:{}},{signal:F.signal});if(F.signal.aborted)return;if(A.error)throw A.error;l(Xi),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(A){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",A),l({phase:"failed",methodIndex:f,message:Ko(A,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{y.current===F&&(y.current=null)}},b=async(f,w)=>{l({phase:"authorizing",methodIndex:f});let F;try{const A=await hn.getSdkClient().provider.oauth.authorize({providerID:t,method:f,...Object.keys(w).length>0?{inputs:w}:{}});if(A.error)throw A.error;const I=Og(A.data);if(!I){l({phase:"failed",methodIndex:f,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}F=I}catch(A){console.error("Failed to start OAuth flow:",A),l({phase:"failed",methodIndex:f,message:Ko(A,i,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&Ig(t,F.url)&&Dn(F.url),F.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:f,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:f,authorization:F}),await C(f)},S=f=>{const w=Eg(f.prompts);if(w.length===0){b(f.index,{});return}m(Mg(w)),l({phase:"prompting",methodIndex:f.index,prompts:w,error:null})},g=()=>{if(r.phase!=="prompting")return;const f=Rg(r.prompts,p);if(f){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:f.message})});return}b(r.methodIndex,Lg(r.prompts,p))},T=()=>{if(r.phase!=="awaitingCode")return;const f=x.trim();f&&(l({...r,submitting:!0}),C(r.methodIndex,f))},M=()=>{y.current?.abort(),y.current=null,l(Xi)},P=f=>{const w=p[f.key]??"",F=A=>m(I=>({...I,[f.key]:A}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:f.message}),f.type==="select"?s.jsxs(It,{value:w,onValueChange:F,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{children:A=>f.options.find(I=>I.value===A)?.label??null})}),s.jsx(At,{children:f.options.map(A=>s.jsx(ot,{value:A.value,children:A.hint?`${A.label} · ${A.hint}`:A.label},A.value))})]}):s.jsx(Je,{value:w,onChange:A=>F(A.target.value),placeholder:f.placeholder,className:"max-w-[24rem] text-xs"})]},f.key)},k=f=>s.jsxs(s.Fragment,{children:[f.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:f.instructions}),f.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:f.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{h(f.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),f.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:f.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(f.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{h(f.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ye("space-y-4",n),children:e.map(f=>{const w=c===f.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:f.label}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>S(f),disabled:N,children:i("settings.providers.page.actions.connect")})]}),w&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Er(r.prompts,p).map(P),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{size:"xs",className:"!font-normal",onClick:g,children:i("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:M,children:i("settings.providers.page.actions.cancel")})]})]}),w&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(R,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),w&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[k(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(R,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:M,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),w&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[k(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:x,onChange:F=>d(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:T,disabled:r.submitting||x.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:M,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),w&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(f),children:i("settings.providers.page.actions.tryAgain")})]})]},f.index)})})},Uo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Fg=t=>new Intl.NumberFormat(kr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),_o=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Fg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ea="__add_provider__",Ql=t=>typeof t=="object"&&t!==null,$o=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Kg=t=>{if(typeof t=="string")return{id:t};if(!Ql(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},zg=t=>{let e=[];Array.isArray(t)?e=t:Ql(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>Kg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Ug=()=>{const{t}=it(),e=Us(),a=Ze(W=>kl(W,e)),n=Ze(W=>W.selectedProviderId),i=Ze(W=>W.setSelectedProvider),r=Ze(W=>W.getModelMetadata),l=le(W=>W.hiddenModels),p=le(W=>W.toggleHiddenModel),m=le(W=>W.hideAllModels),x=le(W=>W.showAllModels),[d,y]=o.useState({}),[c,N]=o.useState(!1),[h,C]=o.useState({}),[b,S]=o.useState(null),[g,T]=o.useState(""),[M,P]=o.useState([]),[k,f]=o.useState(!1),[w,F]=o.useState(null),[A,I]=o.useState(""),[E,B]=o.useState(""),[_,j]=o.useState(!1),[V,q]=o.useState({}),[L,Q]=o.useState(0),[ne,z]=o.useState(!1),[re,$]=o.useState(null),[U,K]=o.useState(null),[O,Y]=o.useState(null),[X,ee]=o.useState(null),[ge,de]=o.useState(null),[xe,ae]=o.useState(null),te=n===Ea,ue=te&&A===$n,Ie=!!(U&&n&&U===n&&!te);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let W=!0;return(async()=>{N(!0);try{const Ae=await hn.getSdkClient().provider.auth();if(Ae.error)throw new Error(`provider.auth failed: ${String(Ae.error)}`);if(!W)return;y(lg(Ae.data))}catch(Ae){if(!W)return;console.error("Failed to load provider auth methods:",Ae),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{W&&N(!1)}})(),()=>{W=!1}},[n,t]),o.useEffect(()=>{if(!rg(te))return;let W=!0;return(async()=>{f(!0),F(null);try{const Ae=await hn.getSdkClient().provider.list();if(Ae.error)throw new Error(`provider.list failed: ${String(Ae.error)}`);if(!W)return;P(zg(Ae.data))}catch(Ae){if(!W)return;console.error("Failed to load available providers:",Ae),F(t("settings.providers.page.state.unableToLoadProviderList"))}finally{W&&f(!1)}})(),()=>{W=!1}},[te,t]);const Ne=o.useMemo(()=>new Set(a.map(W=>W.id)),[a]),Se=o.useMemo(()=>M.filter(W=>!Ne.has(W.id)).sort((W,ke)=>{const Ae=(W.name||W.id).toLowerCase(),He=(ke.name||ke.id).toLowerCase();return Ae.localeCompare(He)}),[M,Ne]);o.useEffect(()=>{n===Ea&&A&&A!==$n&&!Se.some(W=>W.id===A)&&I("")},[n,A,Se]),o.useEffect(()=>{if(n===Ea){z(!0),$(null),K(null),Y(null),ee(null),de(null);return}z(!1),$(null),U&&U!==n&&(K(null),Y(null),ee(null),de(null))},[n,U]),o.useEffect(()=>{if(!n||n===Ea)return;const W=V[n];if(!W)return;const ke=a.find(at=>at.id===n),Ae=Ro({key:ke?.key,authSourceExists:W.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:Uo(ke)}),He=!!(ke&&Lo(ke,W));ug({hasCredentials:Ae,userDismissed:re===n,isEditableCustomProvider:He})&&z(!0)},[n,V,a,re]),o.useEffect(()=>{if(!n||n===Ea)return;let W=!1;return(async()=>{try{const Ae=e?`?directory=${encodeURIComponent(e)}`:"",He=await mt(`/api/provider/${encodeURIComponent(n)}/source${Ae}`,{method:"GET",headers:{Accept:"application/json"}}),at=await He.json().catch(()=>null);if(!He.ok)throw new Error(at?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const nt=at?.sources??at?.data?.sources;!W&&nt&&q(dt=>({...dt,[n]:nt}))}catch(Ae){W||console.error("Failed to load provider sources:",Ae)}})(),()=>{W=!0}},[n,L,e,t]);const ve=o.useCallback(()=>{Q(W=>W+1)},[]),Oe=o.useCallback(W=>{q(ke=>{const Ae=ke[W];return{...ke,[W]:{auth:{exists:!0,path:Ae?.auth.path??null},user:Ae?.user??{exists:!1,path:null},project:Ae?.project??{exists:!1,path:null},...Ae?.custom?{custom:Ae.custom}:{}}}}),$(null),z(!1),i(W),ve()},[ve,i]),Le=o.useCallback(async(W,ke)=>{try{return await Nl({scopes:[W],mode:"active"}),"reloaded"}catch(Ae){if(Ae?.requiresManualRestart===!0)return ke&&Gn(W,{id:ke}),"manual-restart";throw Ae}},[]),oe=a.find(W=>W.id===n),he=n?V[n]:void 0,Me=async W=>{const ke=h[W]?.trim()??"";if(!ke){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ae=`api:${W}`;S(Ae);try{if((await hn.getSdkClient().auth.set({providerID:W,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),C(at=>({...at,[W]:""})),await Le("providers",W),Oe(W)}catch(He){console.error("Failed to save API key:",He),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{S(null)}},$e=async W=>{const ke=`custom:${W.providerID}`;S(ke),ae(W.providerID),de(null);try{const Ae=wg(W);if(Ae&&(await hn.getSdkClient().auth.set(Ae)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const He=jg(W,{scope:U?X??Oo(V[U]):"user"}),at=await mt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(He)}),nt=await at.json().catch(()=>null);if(!at.ok)throw Ae&&de(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(nt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:W.name})),I(""),K(null),Y(null),ee(null),de(null),ae(null),await Le("providers",W.providerID),Oe(W.providerID)}catch(Ae){console.error("Failed to save custom provider:",Ae),D.error(Ae instanceof Error&&Ae.message?Ae.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{S(null)}},Ve=W=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(W+1)}),We=W=>{z(!1),cg(W)&&Gn("providers",{id:W}),Oe(W)},se=async W=>{const ke=`disconnect:${W}`;S(ke);try{const Ae=await mt(`/api/provider/${encodeURIComponent(W)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),He=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(He?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),await Le("providers",W),$(null),ve()}catch(Ae){console.error("Failed to disconnect provider:",Ae),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{S(null)}},ie=async W=>{W&&(await se(W),K(null),Y(null),ee(null),de(null),ae(null),I(""))};if(!te&&a.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(te)return s.jsxs(es,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(_e,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),k?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:w}):s.jsxs(ln,{open:_,onOpenChange:W=>{j(W),W||B("")},children:[s.jsx(rn,{asChild:!0,children:s.jsxs("button",{type:"button",className:En,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[A&&A!==$n?s.jsx(Bn,{providerId:A,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",A?"text-foreground":"text-muted-foreground"),children:A===$n?t("settings.providers.page.custom.optionLabel"):A?Se.find(W=>W.id===A)?.name||A:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(on,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:W=>W.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:W=>W.stopPropagation(),children:[s.jsx(R,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:E,onChange:W=>B(W.target.value),onKeyDown:W=>W.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Hs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const W=t("settings.providers.page.custom.optionLabel"),ke=Mc([W,"other","custom"],E),Ae=Ni(Se,E,He=>[He.name||He.id,He.id]);return Ae.length===0&&!ke?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[Ae.map(He=>s.jsxs(cn,{onSelect:()=>{I(He.id),j(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Bn,{providerId:He.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:He.name||He.id})]}),A===He.id&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},He.id)),ke?s.jsxs(cn,{onSelect:()=>{I($n),j(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(R,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:W})]}),A===$n&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},$n):null]})})()})]})]})]})}),ue?s.jsx(Fo,{mode:"create",existingProviderIDs:Ne,busy:b?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{I(""),de(null),ae(null)},onDisconnect:ge&&xe?()=>{ie(xe)}:void 0,onSubmit:$e}):A?s.jsx(_e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const W=d[A]??[],ke=$o(Mo(W),Ve),Ae=Do(W);return s.jsxs(s.Fragment,{children:[Ae?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Je,{type:"password",value:h[A]??"",onChange:He=>C(at=>({...at,[A]:He.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Me(A),disabled:b===`api:${A}`,children:b===`api:${A}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx(zo,{providerId:A,methods:ke,onConnected:()=>We(A),className:ye(Ae&&"border-t border-[var(--surface-subtle)] pt-2")},A):null]})})()})}):null]});if(!oe)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const je=Array.isArray(oe.models)?oe.models:[],be=d[oe.id]??[],Te=$o(Mo(be),Ve),Ue=Do(be),Pe=!!he,we=Pe&&Lo(oe,he),Ge=Ro({key:oe.key,authSourceExists:he?.auth.exists,optionsApiKey:oe.options?.apiKey??null,envDeclared:Uo(oe)}),pe=og(Pe,Ge,we),Ce=dg({modelCount:je.length,sourcesLoaded:Pe,hasCredentials:Ge,isEditableCustomProvider:we}),Re=!Ue&&Te.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Ye=Ni(je,g,W=>[typeof W?.name=="string"?W.name:"",typeof W?.id=="string"?W.id:""]);return Ie&&we&&O?s.jsx(es,{title:oe.name||oe.id,titleLeading:s.jsx(Bn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:s.jsx(Fo,{mode:"edit",existingProviderIDs:Ne,initialValues:O,allowExistingAuth:Ge||!Pe,busy:b?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{K(null),Y(null),ee(null),de(null),ae(null)},onDisconnect:()=>{ie(oe.id)},onSubmit:$e})}):s.jsxs(es,{title:oe.name||oe.id,titleLeading:s.jsx(Bn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:[s.jsx(_e,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[we?s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),Y(yg(oe)),ee(Oo(he)),K(oe.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=!ne;z(W),$(W?null:oe.id)},children:t(ne?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ne?c?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[Ue?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Jt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Je,{type:"password",value:h[oe.id]??"",onChange:W=>C(ke=>({...ke,[oe.id]:W.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Me(oe.id),disabled:b===`api:${oe.id}`,children:b===`api:${oe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Te.length>0&&s.jsx(zo,{providerId:oe.id,methods:Te,onConnected:()=>We(oe.id),className:ye(Ue&&"border-t border-[var(--surface-subtle)] pt-2")},oe.id)]}):pe?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Jt,{children:Re})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(_e,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:he&&(he.auth.exists||he.user.exists||he.project.exists||he.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[he.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,he.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,he.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,he.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>se(oe.id),disabled:b===`disconnect:${oe.id}`,children:b===`disconnect:${oe.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ce?s.jsxs(_e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",je.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=je.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);m(oe.id,W)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(oe.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(R,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{value:g,onChange:W=>T(W.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Ye.map(W=>{const ke=typeof W?.id=="string"?W.id:"",Ae=typeof W?.name=="string"?W.name:ke,He=ke?r(oe.id,ke):void 0,at=l.some(G=>G.providerID===oe.id&&G.modelID===ke),nt=_o(He?.limit?.context),dt=_o(He?.limit?.output),xt=[];return He?.tool_call&&xt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),He?.reasoning&&xt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),He?.attachment&&xt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",at&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ae}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(nt||dt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[nt?`${nt} ${t("settings.providers.page.models.tokenBadge.context")}`:"",nt&&dt?" · ":"",dt?`${dt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),xt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:xt.map(({key:G,icon:Be,label:st})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:st,"aria-label":st,children:s.jsx(R,{name:Be,className:"h-3 w-3"})},G))}),s.jsx("button",{type:"button",onClick:()=>p(oe.id,ke),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(at?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(at?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:at?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},_g=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},$g=t=>{const e=gt.c(75),{onItemSelect:a}=t,{t:n}=it(),i=Zt(Vg),r=Zt(Bg),l=Zt(Hg),p=Zt(Gg),m=Zt(Wg),x=Zt(qg),d=Zt(Jg),y=Zt(Qg);let c,N;e[0]!==y?(c=()=>{y()},N=[y],e[0]=y,e[1]=c,e[2]=N):(c=e[1],N=e[2]),o.useEffect(c,N);const h=Yg;let C;e[3]!==d?(C=ee=>{ee!=="usage"&&ee!=="remaining"||(d(ee),h({usageDisplayMode:ee}))},e[3]=d,e[4]=C):C=e[4];const b=C;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=ye("flex h-full flex-col","bg-background"),e[5]=S):S=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let T;e[8]!==g?(T=s.jsx("h2",{className:`${dn} mb-3`,children:g}),e[8]=g,e[9]=T):T=e[9];let M;e[10]!==n?(M=n("settings.usage.sidebar.total",{count:Si.length}),e[10]=n,e[11]=M):M=e[11];let P;e[12]!==M?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[12]=M,e[13]=P):P=e[13];let k;e[14]!==p?(k=()=>p(),e[14]=p,e[15]=k):k=e[15];let f;e[16]!==n?(f=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=f):f=e[17];let w;e[18]!==n?(w=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=w):w=e[19];const F=m&&"animate-spin";let A;e[20]!==F?(A=ye("h-3.5 w-3.5",F),e[20]=F,e[21]=A):A=e[21];let I;e[22]!==A?(I=s.jsx(R,{name:"refresh",className:A}),e[22]=A,e[23]=I):I=e[23];let E;e[24]!==m||e[25]!==f||e[26]!==w||e[27]!==I||e[28]!==k?(E=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:k,"aria-label":f,title:w,disabled:m,children:I})}),e[24]=m,e[25]=f,e[26]=w,e[27]=I,e[28]=k,e[29]=E):E=e[29];let B;e[30]!==E||e[31]!==P?(B=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,E]}),e[30]=E,e[31]=P,e[32]=B):B=e[32];let _;e[33]!==n?(_=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=_):_=e[34];let j;e[35]!==_?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[35]=_,e[36]=j):j=e[36];let V;e[37]!==n?(V=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=V):V=e[38];let q;e[39]!==V?(q=s.jsx(Pt,{className:"w-fit",children:s.jsx(Rt,{placeholder:V})}),e[39]=V,e[40]=q):q=e[40];let L;e[41]!==n?(L=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=L):L=e[42];let Q;e[43]!==L?(Q=s.jsx(ot,{value:"usage",children:L}),e[43]=L,e[44]=Q):Q=e[44];let ne;e[45]!==n?(ne=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ne):ne=e[46];let z;e[47]!==ne?(z=s.jsx(ot,{value:"remaining",children:ne}),e[47]=ne,e[48]=z):z=e[48];let re;e[49]!==Q||e[50]!==z?(re=s.jsxs(At,{children:[Q,z]}),e[49]=Q,e[50]=z,e[51]=re):re=e[51];let $;e[52]!==b||e[53]!==q||e[54]!==re||e[55]!==x?($=s.jsxs(It,{value:x,onValueChange:b,children:[q,re]}),e[52]=b,e[53]=q,e[54]=re,e[55]=x,e[56]=$):$=e[56];let U;e[57]!==j||e[58]!==$?(U=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[j,$]}),e[57]=j,e[58]=$,e[59]=U):U=e[59];let K;e[60]!==B||e[61]!==U||e[62]!==T?(K=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,B,U]}),e[60]=B,e[61]=U,e[62]=T,e[63]=K):K=e[63];let O;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(O=Si.map(ee=>{const ge=i.find(Ie=>Ie.providerId===ee.id),de=_g(ge?.usage),xe=Sl(de),ae=ee.id===r,te=ge?.configured??!1,ue=te?xe==="critical"?{backgroundColor:"var(--status-error)"}:xe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ee.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ue}),s.jsx(Bn,{providerId:ee.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:ee.name}),!te&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ee.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=O):O=e[69];let Y;e[70]!==O?(Y=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:O}),e[70]=O,e[71]=Y):Y=e[71];let X;return e[72]!==K||e[73]!==Y?(X=s.jsxs("div",{className:S,children:[K,Y]}),e[72]=K,e[73]=Y,e[74]=X):X=e[74],X};function Vg(t){return t.results}function Bg(t){return t.selectedProviderId}function Hg(t){return t.setSelectedProvider}function Gg(t){return t.fetchAllQuotas}function Wg(t){return t.isLoading}function qg(t){return t.displayMode}function Jg(t){return t.setDisplayMode}function Qg(t){return t.loadSettings}async function Yg(t){try{await yt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Xg=t=>{const e=gt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Rc(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,p=n??a;let m;e[2]!==p?(m=Sl(p),e[2]=p,e[3]=m):m=e[3];const x=m;let d;e[4]!==x?(d=x==="critical"?{backgroundColor:"var(--status-error)"}:x==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=x,e[5]=d):d=e[5];const y=d;let c;e[6]!==i?(c=ye("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=c):c=e[7];const N=`${l}%`;let h;e[8]!==y||e[9]!==N?(h={...y,width:N},e[8]=y,e[9]=N,e[10]=h):h=e[10];let C;e[11]!==l||e[12]!==h?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:h,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=h,e[13]=C):C=e[13];let b;return e[14]!==c||e[15]!==C?(b=s.jsx("div",{className:c,children:C}),e[14]=c,e[15]=C,e[16]=b):b=e[16],b},Zi=t=>{const e=gt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:p}=t,m=r===void 0?!1:r,x=l===void 0?!1:l,d=Zt(Zg),y=le(ef),c=d==="remaining"?n.remainingPercent:n.usedPercent,N=d==="remaining"?"remaining":"used";let h;e[0]!==c||e[1]!==n.valueLabel?(h=Lc(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=h):h=e[2];const C=h,b=n.resetAfterFormatted??n.resetAtFormatted;let S;e[3]!==b||e[4]!==y||e[5]!==n.resetAt?(S=Oc(n.resetAt,b,y),e[3]=b,e[4]=y,e[5]=n.resetAt,e[6]=S):S=e[6];const g=S;let T;e[7]!==a?(T=Fc(a),e[7]=a,e[8]=T):T=e[8];const M=T;let P;e[9]!==p||e[10]!==m||e[11]!==x?(P=m&&s.jsx(or,{checked:x,onChange:ne=>p?.(ne),ariaLabel:"Show in dropdown"}),e[9]=p,e[10]=m,e[11]=x,e[12]=P):P=e[12];let k;e[13]!==M?(k=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:M}),e[13]=M,e[14]=k):k=e[14];let f;e[15]!==i?(f=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=f):f=e[16];let w;e[17]!==k||e[18]!==f?(w=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[k,f]}),e[17]=k,e[18]=f,e[19]=w):w=e[19];let F;e[20]!==w||e[21]!==P?(F=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[P,w]}),e[20]=w,e[21]=P,e[22]=F):F=e[22];const A=C==="-"?"":C;let I;e[23]!==A?(I=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:A}),e[23]=A,e[24]=I):I=e[24];let E;e[25]!==F||e[26]!==I?(E=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,I]}),e[25]=F,e[26]=I,e[27]=E):E=e[27];let B;e[28]!==c||e[29]!==n.usedPercent?(B=s.jsx(Xg,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=c,e[29]=n.usedPercent,e[30]=B):B=e[30];const _=g?`Resets ${g}`:"";let j;e[31]!==_?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[31]=_,e[32]=j):j=e[32];let V;e[33]!==N?(V=s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),e[33]=N,e[34]=V):V=e[34];let q;e[35]!==j||e[36]!==V?(q=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[j,V]}),e[35]=j,e[36]=V,e[37]=q):q=e[37];let L;e[38]!==B||e[39]!==q?(L=s.jsxs("div",{className:"mt-2.5",children:[B,q]}),e[38]=B,e[39]=q,e[40]=L):L=e[40];let Q;return e[41]!==E||e[42]!==L?(Q=s.jsxs("div",{className:"py-3",children:[E,L]}),e[41]=E,e[42]=L,e[43]=Q):Q=e[43],Q};function Zg(t){return t.displayMode}function ef(t){return t.timeFormatPreference}const tf=`ssh exe.dev "ssh-key generate-api-key --label=aiworker --exp=30d --cmds='billing credits usage'"`,sf=({providerId:t,providerName:e})=>{const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState({}),[p,m]=o.useState(!1),x=`/api/quota/credentials/${t}`;o.useEffect(()=>{mt(x).then(async c=>{if(!c.ok)throw new Error;const N=await c.json();i(N),l({})}).catch(()=>i({configured:!1}))},[x]);const d=async(c,N,h)=>{m(!0);try{const C=await mt(c,{method:N,headers:h?{"Content-Type":"application/json"}:void 0,body:h?JSON.stringify(h):void 0}),b=await C.json().catch(()=>null);if(!C.ok)throw new Error(b?.error);b?.configured!==void 0&&i(b),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){D.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{m(!1)}},y=(c,N,h)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[N,s.jsx(Je,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[c]??"",onChange:C=>l(b=>({...b,[c]:C.target.value})),placeholder:n?.secretMasked??h})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:tf})]}),t==="ollama-cloud"&&y("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="exe-dev"&&y("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(H,{size:"xs",disabled:p,onClick:()=>d(x,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(H,{variant:"outline",size:"xs",disabled:p,onClick:()=>d(`${x}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:p,onClick:()=>d(`${x}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{variant:"destructive",size:"xs",disabled:p,onClick:()=>d(x,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Vo=(t,e)=>{if(!t)return"-";try{return Cl(t,e,{fallback:"-"})}catch{return"-"}},nf=()=>{const{t}=it(),e=le(j=>j.timeFormatPreference),a=Zt(j=>j.results),n=Zt(j=>j.selectedProviderId),i=Zt(j=>j.setSelectedProvider),r=Zt(j=>j.loadSettings),l=Zt(j=>j.fetchAllQuotas),p=Zt(j=>j.isLoading),m=Zt(j=>j.lastUpdated),x=Zt(j=>j.error),d=Zt(j=>j.dropdownProviderIds),y=Zt(j=>j.setDropdownProviderIds),c=Zt(j=>j.selectedModels),N=Zt(j=>j.toggleModelSelected),h=Zt(j=>j.applyDefaultSelections);Kc(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const j=a.find(V=>V.configured)?.providerId;i(j??Si[0]?.id??null)},[a,n,i]);const C=a.find(j=>j.providerId===n)??null,S=Si.find(j=>j.id===n)?.name??n??t("settings.usage.sidebar.title"),g=C?.usage,T=C?.configured&&!C.ok?C.error:null,M=n?d.includes(n):!1,P=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",k=o.useCallback(j=>{if(!n)return;const V=j?Array.from(new Set([...d,n])):d.filter(q=>q!==n);y(V),yt({usageDropdownProviders:V})},[d,n,y]),f=o.useMemo(()=>g?.models?Object.entries(g.models).map(([j,V])=>({name:j,windows:V})).filter(j=>Object.keys(j.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&f.length>0&&h(n,f.map(j=>j.name))},[n,f,h]);const w=o.useMemo(()=>!n||f.length===0?new Map:zc(f,j=>j.name,n),[f,n]),F=o.useMemo(()=>{if(!n)return[];const j=_c(n);return Uc(j)},[n]),[A,I]=o.useState(()=>({})),E=o.useCallback(j=>{I(V=>({...V,[j]:!V[j]}))},[]),B=o.useCallback(j=>{if(!n)return;N(n,j);const V=c[n]??[],L=V.includes(j)?V.filter(ne=>ne!==j):[...V,j],Q={...c,[n]:L};yt({usageSelectedModels:Q})},[n,c,N]),_=n?c[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:S}),titleLeading:s.jsx(Bn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:p?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:Vo(m,e)}):t("settings.usage.page.header.lastUpdated",{time:Vo(m,e)}),showSaveStatus:!0,children:[s.jsx(_e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(ft,{checked:M,onChange:k,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(x||T)&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x??T})]}),C&&!C.configured&&!P&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(sf,{providerId:n,providerName:S}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(_e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([j,V])=>s.jsx(Zi,{title:j,window:V},j))})}),f.length>0&&s.jsxs(_e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[F.map(j=>{const V=w.get(j.id)??[];if(V.length===0)return null;const q=A[j.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Mn,{open:!q,onOpenChange:()=>E(j.id),children:[s.jsxs(Rn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:j.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",V.length,")"]})]}),q?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:V.map(L=>{const Q=Object.entries(L.windows.windows);if(Q.length===0)return null;const[ne,z]=Q[0],re=_.includes(L.name);return s.jsx(Zi,{title:ne,subtitle:Fr(L.name),window:z,showToggle:!0,toggleEnabled:re,onToggle:()=>B(L.name)},L.name)})})})]})},j.id)}),(()=>{const j=w.get(null)??[];if(j.length===0)return null;const V=A.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Mn,{open:!V,onOpenChange:()=>E("other"),children:[s.jsxs(Rn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",j.length,")"]})]}),V?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:j.map(q=>{const L=Object.entries(q.windows.windows);if(L.length===0)return null;const[Q,ne]=L[0],z=_.includes(q.name);return s.jsx(Zi,{title:Q,subtitle:Fr(q.name),window:ne,showToggle:!0,toggleEnabled:z,onToggle:()=>B(q.name)},q.name)})})})]})})})()]}),C?.configured&&g&&Object.keys(g.windows??{}).length===0&&f.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},af="git.commit.generate",fr=Ll(t=>({selectedPromptId:af,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),rf=t=>{const e=gt.c(24),{onItemSelect:a}=t,{t:n}=it(),i=fr(of),r=fr(lf);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=p):p=e[1];let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=m):m=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=x):x=e[3];let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=[l,p,m,x,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=d):d=e[4];const y=d;let c;e[5]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=c):c=e[6];let N;e[7]!==c?(N=s.jsx("h2",{className:dn,children:c}),e[7]=c,e[8]=N):N=e[8];let h;e[9]!==n?(h=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=h):h=e[10];let C;e[11]!==h?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:h}),e[11]=h,e[12]=C):C=e[12];let b;e[13]!==N||e[14]!==C?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,C]}),e[13]=N,e[14]=C,e[15]=b):b=e[15];let S;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(S=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:y.map(T=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(T.groupKey)}),T.items.map(M=>{const P=i===M.id;return s.jsx("button",{type:"button",onClick:()=>{r(M.id),a?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",P?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(M.titleKey)})},M.id)})]},T.groupKey))}),e[16]=a,e[17]=i,e[18]=r,e[19]=n,e[20]=S):S=e[20];let g;return e[21]!==b||e[22]!==S?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,S]}),e[21]=b,e[22]=S,e[23]=g):g=e[23],g};function of(t){return t.selectedPromptId}function lf(t){return t.setSelectedPromptId}const Bo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Ho=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),er=t=>t.endsWith(".visible"),cf=()=>{const{t}=it(),e=o.useCallback(k=>t(k),[t]),a=fr(k=>k.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[p,m]=o.useState({}),[x,d]=o.useState({}),[y,c]=o.useState({}),[N,h]=o.useState(!1);o.useEffect(()=>{let k=!0;return(async()=>{i(!0);try{const w=await Hc();if(!k)return;l(w)}catch(w){console.warn("Failed to load magic prompts:",w),D.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{k&&i(!1)}})(),()=>{k=!1}},[t]);const C=Bo[a]??Bo["git.commit.generate"],b=o.useCallback(k=>Ho(r,k)?r[k]:Vi(k),[r]),S=o.useCallback(k=>p[k]??b(k),[p,b]),g=o.useCallback((k,f)=>{m(w=>w[k]===f?w:{...w,[k]:f})},[]),T=o.useCallback(async k=>{const f=S(k);if(er(k)&&f.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(w=>({...w,[k]:!0}));try{const w=f===Vi(k)?await Kr(k):await $c(k,f);l(w.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(w){const F=w instanceof Error?w.message:String(w);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{d(w=>({...w,[k]:!1}))}},[S,t]),M=o.useCallback(async k=>{c(f=>({...f,[k]:!0}));try{const f=await Kr(k);l(f.overrides),m(w=>({...w,[k]:Vi(k)})),D.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(f){const w=f instanceof Error?f.message:String(f);D.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:w})}finally{c(f=>({...f,[k]:!1}))}},[t]),P=o.useCallback(async()=>{h(!0);try{const k=await Vc();l(k.overrides),m({}),D.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(k){const f=k instanceof Error?k.message:String(k);D.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:f})}finally{h(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(es,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{P()},disabled:N||Object.keys(r).length===0,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((k,f)=>{const w=Bc(k.id),F=b(k.id),A=S(k.id),I=Ho(r,k.id),E=A!==F,B=er(k.id)&&A.trim().length===0,_=x[k.id]===!0,j=y[k.id]===!0;return s.jsxs(_e,{title:e(k.titleKey),info:w.description,description:w.placeholders&&w.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${w.placeholders.map(V=>`{{${V.key}}}`).join(", ")}`:void 0,divider:f>0,settingsItem:er(k.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:A,onChange:V=>g(k.id,V.target.value),className:"min-h-[220px] font-mono text-sm"}),B&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(E?"settings.magicPrompts.page.status.unsavedChanges":I?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"outline",size:"sm",onClick:()=>{M(k.id)},disabled:!I||_||j,children:t(j?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{T(k.id)},disabled:!E||_||j||B,children:t(_?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},k.id)})})},df=t=>{const e=gt.c(89),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(null),[m,x]=o.useState(null),{selectedSnippetName:d,snippets:y,setSelectedSnippet:c,setSnippetDraft:N,deleteSnippet:h,loadSnippets:C}=Ci(Ks(uf));let b,S;e[0]!==C?(b=()=>{C()},S=[C],e[0]=C,e[1]=b,e[2]=S):(b=e[1],S=e[2]),o.useEffect(b,S);let g;e[3]!==a||e[4]!==c||e[5]!==N||e[6]!==y?(g=async()=>{const Ne=new Set(y.map(pf));let Se="new-snippet",ve=1;for(;Ne.has(Se);)Se=`new-snippet-${ve++}`;N({name:Se,scope:"global"}),c(Se),a?.()},e[3]=a,e[4]=c,e[5]=N,e[6]=y,e[7]=g):g=e[7];const T=g;let M;e[8]!==i||e[9]!==h||e[10]!==n?(M=async()=>{if(!i)return;await h(i.name)?(D.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):D.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=h,e[10]=n,e[11]=M):M=e[11];const P=M;let k;e[12]!==y?(k=[...y].sort(mf),e[12]=y,e[13]=k):k=e[13];const f=k;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=ye("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let A;e[17]!==F?(A=s.jsx("h2",{className:`${dn} mb-3`,children:F}),e[17]=F,e[18]=A):A=e[18];let I;e[19]!==y.length||e[20]!==n?(I=n("settings.snippets.sidebar.total",{count:y.length}),e[19]=y.length,e[20]=n,e[21]=I):I=e[21];let E;e[22]!==I?(E=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[22]=I,e[23]=E):E=e[23];let B;e[24]!==n?(B=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=B):B=e[25];let _;e[26]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[26]=_):_=e[26];let j;e[27]!==T||e[28]!==B?(j=s.jsx(H,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:T,"aria-label":B,children:_}),e[27]=T,e[28]=B,e[29]=j):j=e[29];let V;e[30]!==E||e[31]!==j?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,j]}),e[30]=E,e[31]=j,e[32]=V):V=e[32];let q;e[33]!==V||e[34]!==A?(q=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,V]}),e[33]=V,e[34]=A,e[35]=q):q=e[35];let L;if(e[36]!==a||e[37]!==l||e[38]!==m||e[39]!==d||e[40]!==c||e[41]!==f||e[42]!==n){let Ne;e[44]!==a||e[45]!==l||e[46]!==m||e[47]!==d||e[48]!==c||e[49]!==n?(Ne=Se=>s.jsxs(ea,{open:m===Se.name,onOpenChange:ve=>x(ve?Se.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===Se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ve=>{ve.preventDefault(),x(Se.name)}}),children:[s.jsxs("button",{onClick:()=>{c(Se.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",Se.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${Se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Se.description||Se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(ln,{open:l===Se.name,onOpenChange:ve=>{ve&&x(null),p(ve?Se.name:null)},children:[s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":n("settings.snippets.sidebar.actions.more",{name:Se.name}),children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:s.jsxs(cn,{onClick:ve=>{ve.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:s.jsxs(Xn,{onClick:ve=>{ve.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Se.source}:${Se.filePath}`),e[44]=a,e[45]=l,e[46]=m,e[47]=d,e[48]=c,e[49]=n,e[50]=Ne):Ne=e[50],L=f.map(Ne),e[36]=a,e[37]=l,e[38]=m,e[39]=d,e[40]=c,e[41]=f,e[42]=n,e[43]=L}else L=e[43];let Q;e[51]!==L?(Q=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:L}),e[51]=L,e[52]=Q):Q=e[52];const ne=i!==null;let z;e[53]===Symbol.for("react.memo_cache_sentinel")?(z=Ne=>{Ne||r(null)},e[53]=z):z=e[53];let re;e[54]!==n?(re=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=re):re=e[55];let $;e[56]!==re?($=s.jsx($t,{children:re}),e[56]=re,e[57]=$):$=e[57];const U=i?.name??"";let K;e[58]!==n||e[59]!==U?(K=n("settings.snippets.sidebar.dialog.deleteDescription",{name:U}),e[58]=n,e[59]=U,e[60]=K):K=e[60];let O;e[61]!==K?(O=s.jsx(Vt,{children:K}),e[61]=K,e[62]=O):O=e[62];let Y;e[63]!==$||e[64]!==O?(Y=s.jsxs(_t,{children:[$,O]}),e[63]=$,e[64]=O,e[65]=Y):Y=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X=()=>r(null),e[66]=X):X=e[66];let ee;e[67]!==n?(ee=n("settings.common.actions.cancel"),e[67]=n,e[68]=ee):ee=e[68];let ge;e[69]!==ee?(ge=s.jsx(H,{size:"sm",variant:"ghost",onClick:X,children:ee}),e[69]=ee,e[70]=ge):ge=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let xe;e[73]!==P||e[74]!==de?(xe=s.jsx(H,{size:"sm",onClick:P,children:de}),e[73]=P,e[74]=de,e[75]=xe):xe=e[75];let ae;e[76]!==ge||e[77]!==xe?(ae=s.jsxs(ts,{children:[ge,xe]}),e[76]=ge,e[77]=xe,e[78]=ae):ae=e[78];let te;e[79]!==Y||e[80]!==ae?(te=s.jsxs(zt,{className:"max-w-md",children:[Y,ae]}),e[79]=Y,e[80]=ae,e[81]=te):te=e[81];let ue;e[82]!==ne||e[83]!==te?(ue=s.jsx(Kt,{open:ne,onOpenChange:z,children:te}),e[82]=ne,e[83]=te,e[84]=ue):ue=e[84];let Ie;return e[85]!==q||e[86]!==Q||e[87]!==ue?(Ie=s.jsxs("div",{className:w,children:[q,Q,ue]}),e[85]=q,e[86]=Q,e[87]=ue,e[88]=Ie):Ie=e[88],Ie};function uf(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function pf(t){return t.name}function mf(t,e){return t.name.localeCompare(e.name)}const gf=()=>{const{t}=it(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=Ci(Ks(w=>({selectedSnippetName:w.selectedSnippetName,snippets:w.snippets,snippetDraft:w.snippetDraft,setSnippetDraft:w.setSnippetDraft,updateSnippet:w.updateSnippet,createSnippet:w.createSnippet}))),p=o.useMemo(()=>e?a.find(w=>w.name===e||w.aliases.includes(e))??null:null,[e,a]),m=!!(n&&n.name===e&&!p),[x,d]=o.useState(""),[y,c]=o.useState("global"),[N,h]=o.useState(""),[C,b]=o.useState(""),[S,g]=o.useState(""),[T,M]=o.useState(!1),P=o.useRef(null);o.useEffect(()=>{if(m&&n){const w={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(w.draftName),c(w.draftScope),h(w.description),b(w.aliases),g(w.content),P.current=w}else if(p){const w={draftName:"",draftScope:"global",description:p.description??"",aliases:p.aliases.join(", "),content:p.content};h(w.description),b(w.aliases),g(w.content),P.current=w}},[p,m,e,n]);const k=o.useMemo(()=>{const w=P.current;return w?m&&x!==w.draftName||m&&y!==w.draftScope?!0:N!==w.description||C!==w.aliases||S!==w.content:!1},[C,S,N,x,y,m]),f=async()=>{const w=m?x.trim().replace(/\s+/g,"-"):e?.trim();if(!w){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!S.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const F=C.split(",").map(A=>A.trim()).filter(Boolean);M(!0);try{if(!(m?await l(w,S,{aliases:F,description:N,scope:y}):await r(w,{content:S,aliases:F,description:N}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),m&&i(null)}finally{M(!1)}};return e?s.jsxs(es,{title:m?t("settings.snippets.page.title.new"):`#${e}`,description:p?p.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(_e,{divider:!1,contentClassName:"space-y-0",children:[m?s.jsxs(Lt,{label:"#",children:[s.jsx(Je,{value:x,onChange:w=>d(w.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(It,{value:y,onValueChange:w=>c(w),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ot,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(qt,{label:t("settings.common.field.description"),children:s.jsx(Je,{value:N,onChange:w=>h(w.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(qt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Je,{value:C,onChange:w=>b(w.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(_e,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:S,onChange:w=>g(w.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:f,disabled:T||!k,size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(R,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},Yl=()=>{const{t}=it(),e=Ze(y=>y.settingsGitmojiEnabled),a=Ze(y=>y.setSettingsGitmojiEnabled),n=Nd(),i=le(y=>y.gitChangesViewMode),r=le(y=>y.setGitChangesViewMode),[l,p]=o.useState(!0),m=o.useMemo(()=>[{id:"flat",label:t("settings.aiworker.git.option.flatList")},{id:"tree",label:t("settings.aiworker.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let c=null;if(!c){const N=an()?.settings;if(N)try{const C=(await N.load())?.settings;C&&(c={gitmojiEnabled:typeof C.gitmojiEnabled=="boolean"?C.gitmojiEnabled:void 0,gitChangesViewMode:C.gitChangesViewMode==="flat"||C.gitChangesViewMode==="tree"?C.gitChangesViewMode:void 0})}catch{}}if(!c){const N=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});N.ok&&(c=await N.json())}c&&(typeof c.gitmojiEnabled=="boolean"&&a(c.gitmojiEnabled),(c.gitChangesViewMode==="flat"||c.gitChangesViewMode==="tree")&&r(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{p(!1)}})()},[r,a]);const x=o.useCallback(async y=>{a(y);try{await yt({gitmojiEnabled:y})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[a]),d=o.useCallback(y=>{y!==i&&(r(y),yt({gitChangesViewMode:y}))},[i,r]);return l?null:s.jsx(_e,{title:t("settings.aiworker.git.title"),children:s.jsxs("div",{className:hs,children:[s.jsx(Ps,{settingsItem:"git.changes-view",title:t("settings.aiworker.git.changesViewTitle"),children:s.jsx(en,{"aria-label":t("settings.aiworker.git.changesViewAria"),children:m.map(y=>s.jsx(tn,{selected:i===y.id,onSelect:()=>{d(y.id)},label:y.label,ariaLabel:t("settings.aiworker.git.optionAria",{option:y.label})},y.id))})}),s.jsx(ft,{settingsItem:"git.gitmoji",checked:e,onChange:y=>{x(y)},label:t("settings.aiworker.git.enableGitmoji"),ariaLabel:t("settings.aiworker.git.enableGitmojiAria")}),s.jsx(ft,{settingsItem:"git.gitignored-files",checked:n,onChange:Sd,label:t("settings.aiworker.git.showGitignored"),ariaLabel:t("settings.aiworker.git.showGitignoredAria")})]})})},Go=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],ff=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],hf=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=it(),r=Hn(O=>O.getProfileById),l=Hn(O=>O.createProfile),p=Hn(O=>O.updateProfile),m=Hn(O=>O.deleteProfile),x=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,y=a==="global",[c,N]=o.useState(""),[h,C]=o.useState(""),[b,S]=o.useState(""),[g,T]=o.useState("ssh"),[M,P]=o.useState(""),[k,f]=o.useState(!1),[w,F]=o.useState(""),[A,I]=o.useState(""),[E,B]=o.useState("keyword"),[_,j]=o.useState("branch"),[V,q]=o.useState(!1),[L,Q]=o.useState(!1),[ne,z]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const O=n.host.split("/"),Y=O.length>=3?O[O.length-1]:n.host;N(Y),C(n.username),S(""),T("token"),P(""),f(!1),F(""),I(n.host),B("string"),j("code")}else if(d)N(""),C(""),S(""),T("ssh"),P(""),f(!1),F(""),I(""),B("keyword"),j("branch");else if(x)N(x.name),C(x.userName),S(x.userEmail),T(x.authType||"ssh"),P(x.sshKey||""),f(x.signCommits===!0),F(x.signingKey||""),I(x.host||""),B(x.color||"keyword"),j(x.icon||"branch");else if(y){const O=r("global");O&&(N(O.name),C(O.userName),S(O.userEmail),T(O.authType||"ssh"),P(O.sshKey||""),f(!1),F(""),I(O.host||""),B(O.color||"keyword"),j(O.icon||"branch"))}}},[t,a,x,d,n,y,r]);const re=async()=>{if(!h.trim()||!b.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!A.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(k&&!w.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}q(!0);try{const O={name:c.trim()||h.trim(),userName:h.trim(),userEmail:b.trim(),authType:g,sshKey:g==="ssh"&&M.trim()||null,signCommits:k,signingKey:w.trim()||null,host:g==="token"&&A.trim()||null,color:E,icon:_};let Y;if(d)Y=await l(O);else if(a)Y=await p(a,O);else return;Y?(D.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(O){console.error("Error saving profile:",O),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{q(!1)}},$=async()=>{if(!(!a||d)){z(!0);try{await m(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(O){console.error("Error deleting profile:",O),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{z(!1)}}},U=o.useMemo(()=>Go.find(Y=>Y.key===E)?.cssVar||"var(--syntax-keyword)",[E]),K=n?i("settings.gitIdentities.editor.title.importCredential"):d?i("settings.gitIdentities.editor.title.newIdentity"):y?i("settings.gitIdentities.editor.title.globalIdentity"):x?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:K}),s.jsx(Vt,{children:i(y?"settings.gitIdentities.editor.description.globalReadOnly":d?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!y&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Et} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Je,{value:c,onChange:O=>N(O.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Go.map(O=>s.jsx("button",{type:"button",onClick:()=>B(O.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",E===O.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:O.cssVar},title:O.label},O.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:ff.map(O=>{const Y=O.Icon;return s.jsx("button",{type:"button",onClick:()=>j(O.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",_===O.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:O.label,children:s.jsx(R,{name:Y,className:"w-3.5 h-3.5",style:{color:_===O.key?U:"var(--surface-muted-foreground)"}})},O.key)})})]})]}),!y&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.userName")}),!y&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Je,{value:h,onChange:O=>C(O.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!y,readOnly:y,disabled:y,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.emailAddress")}),!y&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Je,{type:"email",value:b,onChange:O=>S(O.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!y,readOnly:y,disabled:y,className:"h-8"})]})]}),!y&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="ssh",onClick:()=>T("ssh"),children:[s.jsx(R,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>T("token"),children:[s.jsx(R,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Je,{value:M,onChange:O=>P(O.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(ft,{checked:k,onChange:f,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Je,{value:w,onChange:O=>F(O.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!k,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Je,{value:A,onChange:O=>I(O.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ts,{className:"gap-2",children:[!y&&!d&&s.jsxs(H,{variant:"outline",size:"sm",onClick:()=>Q(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(R,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(H,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(y?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!y&&s.jsx(H,{size:"sm",onClick:re,disabled:V,children:i(V?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:L,onOpenChange:O=>{ne||Q(O)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||c})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"ghost",onClick:()=>Q(!1),disabled:ne,children:i("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:ne,children:i("settings.common.actions.delete")})]})]})})]})},xf={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},vf={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},yf=()=>{const t=gt.c(112),{t:e}=it(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:p,loadDiscoveredCredentials:m,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:d,getUnimportedCredentials:y}=Hn(Ks(wf)),[c,N]=o.useState(!1),[h,C]=o.useState(null),[b,S]=o.useState(null),[g,T]=o.useState(null),[M,P]=o.useState(!1);let k,f;t[0]!==x||t[1]!==m||t[2]!==p||t[3]!==l?(k=()=>{l(),p(),m(),x()},f=[l,p,m,x],t[0]=x,t[1]=m,t[2]=p,t[3]=l,t[4]=k,t[5]=f):(k=t[4],f=t[5]),o.useEffect(k,f);let w,F,A,I,E,B,_,j,V,q,L,Q,ne,z;if(t[6]!==i||t[7]!==g||t[8]!==r||t[9]!==y||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const $e=y();let Ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(Ve=(Pe,we)=>{C(Pe),S(we??null),N(!0)},t[28]=Ve):Ve=t[28];const We=Ve;let se;t[29]!==i||t[30]!==d||t[31]!==e?(se=async Pe=>{const we=i===Pe?null:Pe;if(!await d(we)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(we?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=se):se=t[32];const ie=se;let je;t[33]!==g||t[34]!==r||t[35]!==e?(je=async()=>{if(!g)return;P(!0),await r(g.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),T(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),P(!1)},t[33]=g,t[34]=r,t[35]=e,t[36]=je):je=t[36],A=je,F=es,t[37]!==e?(E=e("settings.page.git.title"),t[37]=e,t[38]=E):E=t[38],B=!0,w=_e,t[39]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=Q):Q=t[40],ne=!1;let be,Te;t[41]===Symbol.for("react.memo_cache_sentinel")?(be=()=>We("new"),Te=s.jsx(R,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=be,t[42]=Te):(be=t[41],Te=t[42]);let Ue;t[43]!==e?(Ue=e("settings.common.badge.new"),t[43]=e,t[44]=Ue):Ue=t[44],t[45]!==Ue?(z=s.jsxs(H,{size:"sm",variant:"outline",onClick:be,children:[Te," ",Ue]}),t[45]=Ue,t[46]=z):z=t[46],I="git.identities",_="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",j=n&&s.jsx(Wo,{profile:n,isDefault:i==="global",onEdit:()=>We("global"),onToggleDefault:()=>ie("global"),isReadOnly:!0,hasBorder:a.length>0||$e.length>0}),V=a.map((Pe,we)=>s.jsx(Wo,{profile:Pe,isDefault:i===Pe.id,onEdit:()=>We(Pe.id),onToggleDefault:()=>ie(Pe.id),onDelete:()=>T(Pe),hasBorder:we<a.length-1||$e.length>0},Pe.id)),q=!n&&a.length===0&&$e.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(R,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),L=$e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),$e.map((Pe,we)=>s.jsx(bf,{credential:Pe,onImport:()=>We("new",{host:Pe.host,username:Pe.username}),hasBorder:we<$e.length-1},`${Pe.host}-${Pe.username}`))]}),t[6]=i,t[7]=g,t[8]=r,t[9]=y,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=w,t[15]=F,t[16]=A,t[17]=I,t[18]=E,t[19]=B,t[20]=_,t[21]=j,t[22]=V,t[23]=q,t[24]=L,t[25]=Q,t[26]=ne,t[27]=z}else w=t[14],F=t[15],A=t[16],I=t[17],E=t[18],B=t[19],_=t[20],j=t[21],V=t[22],q=t[23],L=t[24],Q=t[25],ne=t[26],z=t[27];let re;t[47]!==_||t[48]!==j||t[49]!==V||t[50]!==q||t[51]!==L?(re=s.jsxs("div",{className:_,children:[j,V,q,L]}),t[47]=_,t[48]=j,t[49]=V,t[50]=q,t[51]=L,t[52]=re):re=t[52];let $;t[53]!==w||t[54]!==I||t[55]!==re||t[56]!==Q||t[57]!==ne||t[58]!==z?($=s.jsx(w,{title:Q,divider:ne,headerAction:z,settingsItem:I,children:re}),t[53]=w,t[54]=I,t[55]=re,t[56]=Q,t[57]=ne,t[58]=z,t[59]=$):$=t[59];let U;t[60]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Yl,{}),t[60]=U):U=t[60];let K;t[61]!==F||t[62]!==E||t[63]!==B||t[64]!==$?(K=s.jsxs(F,{title:E,showSaveStatus:B,children:[$,U]}),t[61]=F,t[62]=E,t[63]=B,t[64]=$,t[65]=K):K=t[65];let O;t[66]!==b||t[67]!==c||t[68]!==h?(O=s.jsx(hf,{open:c,onOpenChange:N,profileId:h,importData:b}),t[66]=b,t[67]=c,t[68]=h,t[69]=O):O=t[69];const Y=g!==null;let X;t[70]!==M?(X=$e=>{M||$e||T(null)},t[70]=M,t[71]=X):X=t[71];let ee;t[72]!==e?(ee=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=ee):ee=t[73];let ge;t[74]!==ee?(ge=s.jsx($t,{children:ee}),t[74]=ee,t[75]=ge):ge=t[75];const de=g?.name??"";let xe;t[76]!==e||t[77]!==de?(xe=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=xe):xe=t[78];let ae;t[79]!==xe?(ae=s.jsx(Vt,{children:xe}),t[79]=xe,t[80]=ae):ae=t[80];let te;t[81]!==ge||t[82]!==ae?(te=s.jsxs(_t,{children:[ge,ae]}),t[81]=ge,t[82]=ae,t[83]=te):te=t[83];let ue;t[84]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>T(null),t[84]=ue):ue=t[84];let Ie;t[85]!==e?(Ie=e("settings.common.actions.cancel"),t[85]=e,t[86]=Ie):Ie=t[86];let Ne;t[87]!==M||t[88]!==Ie?(Ne=s.jsx(H,{variant:"ghost",onClick:ue,disabled:M,children:Ie}),t[87]=M,t[88]=Ie,t[89]=Ne):Ne=t[89];let Se;t[90]!==A?(Se=()=>{A()},t[90]=A,t[91]=Se):Se=t[91];let ve;t[92]!==e?(ve=e("settings.common.actions.delete"),t[92]=e,t[93]=ve):ve=t[93];let Oe;t[94]!==M||t[95]!==Se||t[96]!==ve?(Oe=s.jsx(H,{size:"sm",variant:"destructive",onClick:Se,disabled:M,children:ve}),t[94]=M,t[95]=Se,t[96]=ve,t[97]=Oe):Oe=t[97];let Le;t[98]!==Ne||t[99]!==Oe?(Le=s.jsxs(ts,{children:[Ne,Oe]}),t[98]=Ne,t[99]=Oe,t[100]=Le):Le=t[100];let oe;t[101]!==te||t[102]!==Le?(oe=s.jsxs(zt,{className:"max-w-md",children:[te,Le]}),t[101]=te,t[102]=Le,t[103]=oe):oe=t[103];let he;t[104]!==Y||t[105]!==X||t[106]!==oe?(he=s.jsx(Kt,{open:Y,onOpenChange:X,children:oe}),t[104]=Y,t[105]=X,t[106]=oe,t[107]=he):he=t[107];let Me;return t[108]!==K||t[109]!==O||t[110]!==he?(Me=s.jsxs(s.Fragment,{children:[K,O,he]}),t[108]=K,t[109]=O,t[110]=he,t[111]=Me):Me=t[111],Me},Wo=t=>{const e=gt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:p,hasBorder:m}=t,{t:x}=it(),[d,y]=o.useState(!1),c=xf[a.icon||"branch"]||"git-branch",N=vf[a.color||""],h=a.authType||"ssh";let C;e[0]!==i?(C=$=>{$.currentTarget===$.target&&($.key!=="Enter"&&$.key!==" "||($.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const b=C;let S;e[2]!==n||e[3]!==p||e[4]!==l||e[5]!==r||e[6]!==x?(S=$=>s.jsxs(s.Fragment,{children:[s.jsx($,{onClick:U=>{U.stopPropagation(),r()},children:x(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!p&&l&&s.jsxs($,{onClick:U=>{U.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=n,e[3]=p,e[4]=l,e[5]=r,e[6]=x,e[7]=S):S=e[7];const g=S,T=m&&"border-b border-[var(--surface-subtle)]";let M;e[8]!==T?(M=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",T),e[8]=T,e[9]=M):M=e[9];let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=$=>{$.preventDefault(),y(!0)},e[10]=P):P=e[10];let k;e[11]!==b||e[12]!==i||e[13]!==M?(k=s.jsx("div",{className:M,onClick:i,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:P}),e[11]=b,e[12]=i,e[13]=M,e[14]=k):k=e[14];let f;e[15]!==N?(f={color:N},e[15]=N,e[16]=f):f=e[16];let w;e[17]!==c||e[18]!==f?(w=s.jsx(R,{name:c,className:"w-4 h-4 shrink-0",style:f}),e[17]=c,e[18]=f,e[19]=w):w=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let A;e[22]!==h?(A=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h}),e[22]=h,e[23]=A):A=e[23];let I;e[24]!==n||e[25]!==x?(I=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:x("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=x,e[26]=I):I=e[26];let E;e[27]!==p||e[28]!==x?(E=p&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:x("settings.agents.sidebar.badge.system")}),e[27]=p,e[28]=x,e[29]=E):E=e[29];let B;e[30]!==A||e[31]!==I||e[32]!==E||e[33]!==F?(B=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,A,I,E]}),e[30]=A,e[31]=I,e[32]=E,e[33]=F,e[34]=B):B=e[34];const _=h==="token"&&a.host?a.host:a.userEmail;let j;e[35]!==_?(j=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:_}),e[35]=_,e[36]=j):j=e[36];let V;e[37]!==B||e[38]!==j?(V=s.jsxs("div",{className:"min-w-0",children:[B,j]}),e[37]=B,e[38]=j,e[39]=V):V=e[39];let q;e[40]!==V||e[41]!==w?(q=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[w,V]}),e[40]=V,e[41]=w,e[42]=q):q=e[42];let L;e[43]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(rn,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:jf,children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=L):L=e[43];let Q;e[44]!==g?(Q=s.jsxs(ln,{children:[L,s.jsx(on,{align:"end",className:"w-fit min-w-28",children:g(cn)})]}),e[44]=g,e[45]=Q):Q=e[45];let ne;e[46]!==q||e[47]!==Q||e[48]!==k?(ne=s.jsxs(Zn,{render:k,children:[q,Q]}),e[46]=q,e[47]=Q,e[48]=k,e[49]=ne):ne=e[49];let z;e[50]!==g?(z=s.jsx(Yn,{className:"w-fit min-w-28",children:g(Xn)}),e[50]=g,e[51]=z):z=e[51];let re;return e[52]!==d||e[53]!==ne||e[54]!==z?(re=s.jsxs(ea,{open:d,onOpenChange:y,children:[ne,z]}),e[52]=d,e[53]=ne,e[54]=z,e[55]=re):re=e[55],re},bf=t=>{const e=gt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=it();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const p=l,m=p.length>=3?p[p.length-1]:a.host,x=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let y;e[2]!==d?(y=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",d),e[2]=d,e[3]=y):y=e[3];let c;e[4]!==m?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:m}),e[4]=m,e[5]=c):c=e[5];const N=x?a.host:a.username;let h;e[6]!==N?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:N}),e[6]=N,e[7]=h):h=e[7];let C;e[8]!==c||e[9]!==h?(C=s.jsxs("div",{className:"min-w-0",children:[c,h]}),e[8]=c,e[9]=h,e[10]=C):C=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(R,{name:"download",className:"h-3 w-3"}),e[11]=b):b=e[11];let S;e[12]!==r?(S=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=S):S=e[13];let g;e[14]!==n||e[15]!==S?(g=s.jsxs(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[b,S]}),e[14]=n,e[15]=S,e[16]=g):g=e[16];let T;return e[17]!==g||e[18]!==y||e[19]!==C?(T=s.jsxs("div",{className:y,children:[C,g]}),e[17]=g,e[18]=y,e[19]=C,e[20]=T):T=e[20],T};function wf(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function jf(t){return t.stopPropagation()}const kf=({embedded:t=!1})=>{const{t:e}=it(),{isMobile:a}=wa(),n=an()?.github,i=Tn(j=>j.status),r=Tn(j=>j.isLoading),l=Tn(j=>j.hasChecked),p=Tn(j=>j.refreshStatus),m=Tn(j=>j.setStatus),x=o.useCallback(async j=>{await Dn(j)},[]),[d,y]=o.useState(!1),[c,N]=o.useState(null),[h,C]=o.useState(null),b=o.useRef(null),S=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),C(null)},[]);o.useEffect(()=>((async()=>{try{l||await p(n)}catch(j){console.warn("Failed to load GitHub auth status:",j)}})(),()=>{S()}),[l,p,n,S]);const g=o.useCallback(async()=>{y(!0);try{const j=n?await n.authStart():await(async()=>{const q=await mt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),L=await q.json().catch(()=>null);if(!q.ok||!L||!("deviceCode"in L))throw new Error(L?.error||q.statusText);return L})();N(j),C(Math.max(1,j.interval)*1e3);const V=j.verificationUriComplete||j.verificationUri;x(V)}catch(j){console.error("Failed to start GitHub connect:",j),D.error(e("settings.github.page.toast.startConnectFailed"))}finally{y(!1)}},[x,n,e]),T=o.useCallback(async j=>{if(n)return n.authComplete(j);const V=await mt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:j})}),q=await V.json().catch(()=>null);if(!V.ok||!q)throw new Error(q?.error||V.statusText);return q},[n]);o.useEffect(()=>{if(!(!c?.deviceCode||!h)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const j=await T(c.deviceCode);if(j.connected){D.success(e("settings.github.page.toast.connected")),N(null),S(),await p(n,{force:!0});return}j.status==="slow_down"&&C(V=>V?V+5e3:5e3),(j.status==="expired_token"||j.status==="access_denied")&&(D.error(j.error||e("settings.github.page.toast.authorizationFailed")),N(null),S())}catch(j){console.warn("GitHub polling failed:",j)}})()},h),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[c,h,T,p,n,S,e]);const M=o.useCallback(async j=>{y(!0);try{if(n)await n.authSetGhCliDisabled(j);else{const V=await mt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:j})}),q=await V.json().catch(()=>null);if(!V.ok)throw new Error(q?.error||V.statusText)}D.success(e(j?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await p(n,{force:!0})}catch(V){console.error("Failed to update gh CLI setting:",V),D.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{y(!1)}},[p,n,e]),P=o.useCallback(async()=>{y(!0);try{if(S(),N(null),n)await n.authDisconnect();else{const j=await mt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!j.ok)throw new Error(j.statusText)}D.success(e("settings.github.page.toast.disconnected")),await p(n,{force:!0})}catch(j){console.error("Failed to disconnect GitHub:",j),D.error(e("settings.github.page.toast.disconnectFailed"))}finally{y(!1)}},[p,n,S,e]),k=o.useCallback(async j=>{if(j){y(!0);try{const V=n?await n.authActivate(j):await(async()=>{const q=await mt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:j})}),L=await q.json().catch(()=>null);if(!q.ok||!L)throw new Error(L?.error||q.statusText);return L})();m(V),D.success(e("settings.github.page.toast.accountSwitched"))}catch(V){console.error("Failed to switch GitHub account:",V),D.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{y(!1)}}},[n,m,e]);if(r&&!l)return null;const f=!!i?.connected,w=i?.user,A=(i?.accounts??[]).filter(j=>!j.current),I=i?.ghCli??null,E=I?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),B=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[f?s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?e("settings.github.page.avatarAlt.withLogin",{login:w.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:w?.name?.trim()||w?.login||"GitHub"}),s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:w?.login||e("settings.github.page.label.unknownUser")}),w?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&s.jsx("span",{children:w.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:E})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),I?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),I?.active?s.jsx(H,{size:"sm",variant:"outline",onClick:()=>M(!0),disabled:d,className:ye(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(H,{size:"sm",variant:"outline",onClick:P,disabled:d,className:ye("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(H,{size:"sm",variant:"default",onClick:g,disabled:d,children:e("settings.github.page.actions.connect")})]}),A.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:A.map(j=>{const V=j.user,q=j.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[V?.avatarUrl?s.jsx("img",{src:V.avatarUrl,alt:V.login?e("settings.github.page.avatarAlt.withLogin",{login:V.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:V?.name?.trim()||V?.login||"GitHub"}),V?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:V.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:q})]})]})]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>k(j.id),disabled:d,children:e("settings.github.page.actions.switchTo")})]},j.id)})})]})]}),f&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(H,{size:"sm",variant:"outline",onClick:g,disabled:d,className:ye(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),c&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(Ys,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:c.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:c.verificationUriComplete||c.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(H,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{S(),N(null)},children:e("settings.common.actions.cancel")})]})]})]}),_=I?.available&&!I?.active&&(!I.user||I.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[I.user?.avatarUrl?s.jsx("img",{src:I.user.avatarUrl,alt:I.user.login?e("settings.github.page.avatarAlt.withLogin",{login:I.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!I.disabled&&I.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:I.user.name?.trim()||I.user.login||"GitHub"}),!I.disabled&&I.user?.login&&s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:I.user.login}),I.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),I.user.email&&s.jsx("span",{children:I.user.email})]}),s.jsx("div",{className:ye("typography-meta text-muted-foreground",I.disabled?"opacity-60":void 0),children:I.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>M(!I.disabled),disabled:d,className:ye(a?"w-full":void 0),children:I.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[B,_?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ys,{children:e("settings.github.page.ghCli.title")}),_]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(_e,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:B}),_?s.jsx(_e,{title:e("settings.github.page.ghCli.title"),children:_}):null]})},Nf=()=>{const t=gt.c(37),{t:e}=it(),a=Tn(Sf),n=Tn(Cf),i=Tn(If),[r,l]=o.useState(!1),p=a?.connected===!0;let m;t[0]!==p||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(m=n&&!i?e("common.loading"):p?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=p,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=m):m=t[5];const x=m,d=p?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=y):y=t[6];let c;t[7]!==e?(c=e("settings.integrations.github.title"),t[7]=e,t[8]=c):c=t[8];let N;t[9]!==c?(N=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:c}),t[9]=c,t[10]=N):N=t[10];let h;t[11]!==e?(h=e("settings.integrations.github.description"),t[11]=e,t[12]=h):h=t[12];let C;t[13]!==h?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:h}),t[13]=h,t[14]=C):C=t[14];let b;t[15]!==N||t[16]!==C?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[N,C]}),t[15]=N,t[16]=C,t[17]=b):b=t[17];let S;t[18]!==d?(S=ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",d),t[18]=d,t[19]=S):S=t[19];let g;t[20]!==x||t[21]!==S?(g=s.jsx("span",{"aria-live":"polite",className:S,children:x}),t[20]=x,t[21]=S,t[22]=g):g=t[22];const T=r&&"rotate-180";let M;t[23]!==T?(M=ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T),t[23]=T,t[24]=M):M=t[24];let P;t[25]!==M?(P=s.jsx(R,{name:"arrow-down-s",className:M}),t[25]=M,t[26]=P):P=t[26];let k;t[27]!==P||t[28]!==b||t[29]!==g?(k=s.jsxs(Rn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[y,b,g,P]}),t[27]=P,t[28]=b,t[29]=g,t[30]=k):k=t[30];let f;t[31]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(Ln,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(kf,{embedded:!0})}),t[31]=f):f=t[31];let w;t[32]!==k?(w=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[k,f]}),t[32]=k,t[33]=w):w=t[33];let F;return t[34]!==r||t[35]!==w?(F=s.jsx(Mn,{open:r,onOpenChange:l,children:w}),t[34]=r,t[35]=w,t[36]=F):F=t[36],F};function Sf(t){return t.status}function Cf(t){return t.isLoading}function If(t){return t.hasChecked}const gi="__none__",fi="__inherit__";function Pf({linear:t,connected:e,organizationId:a}){const{t:n}=it(),i=Bs(b=>b.projects),[r,l]=o.useState(null),[p,m]=o.useState(!1),[x,d]=o.useState(!1),y=o.useCallback(async()=>{if(!e){l(null),m(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){l(null),m(!1);return}l(b),m(!1)}catch(b){console.error("Failed to load Linear mapping:",b),m(!0)}},[e,t]);o.useEffect(()=>{y()},[y,a]);const c=o.useCallback(async b=>{const S={};for(const g of b.teams??[])g.projectPath&&(S[g.id]=g.projectPath);d(!0),xn("saving");try{const g=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:S});if(g.connected===!1){l(null),xn("error");return}l(g),m(!1),xn("saved")}catch(g){console.error("Failed to save Linear mapping:",g),xn("error")}finally{d(!1)}},[t]);if(!e)return null;if(p&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const N=b=>i.find(g=>g.path===b)?.label?.trim()||b,h=b=>!b||b===gi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):N(b),C=b=>!b||b===fi?n("settings.integrations.linear.mapping.teams.useDefault"):N(b);return s.jsxs("div",{className:Js,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Lt,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(It,{value:r.defaultProjectPath||gi,disabled:x||i.length===0,onValueChange:b=>{c({...r,defaultProjectPath:b===gi?null:b})},children:[s.jsx(Pt,{size:Ft,className:nn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:h})}),s.jsxs(At,{children:[s.jsx(ot,{value:gi,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(b=>b.path===r.defaultProjectPath)?s.jsx(ot,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(b=>s.jsx(ot,{value:b.path,children:N(b.path)},b.id))]})]})}),s.jsx(Ps,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(r.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Js,children:(r.teams??[]).map(b=>s.jsx(Lt,{label:`${b.key} · ${b.name}`,children:s.jsxs(It,{value:b.projectPath||fi,disabled:x||i.length===0,onValueChange:S=>{c({...r,teams:(r.teams??[]).map(g=>g.id===b.id?{...g,projectPath:S===fi?null:S}:g)})},children:[s.jsx(Pt,{size:Ft,className:nn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(At,{children:[s.jsx(ot,{value:fi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!i.some(S=>S.path===b.projectPath)?s.jsx(ot,{value:b.projectPath,children:b.projectPath}):null,i.map(S=>s.jsx(ot,{value:S.path,children:N(S.path)},S.id))]})]})},b.id))})})]})}function Af({linear:t,connected:e}){const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[p,m]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let d=!1;return t.preferencesGet().then(y=>{d||(i(y.sessionComments),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0}},[e,t]);const x=o.useCallback(async d=>{const y=n;i(d),m(!0);try{const c=await t.preferencesSet({sessionComments:d});i(c.sessionComments),xn("saved")}catch{i(y),xn("error")}finally{m(!1)}},[n,t]);return e?r?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Js,children:s.jsx(Lt,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(vi,{checked:n===!0,disabled:n===null||p,onCheckedChange:d=>{x(d)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Tf=3*6e4,Ef=1500;function qo(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Df(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Mf=()=>{const{t}=it(),e=an()?.linear,a=ua(I=>I.status),n=ua(I=>I.isLoading),i=ua(I=>I.hasChecked),r=ua(I=>I.refreshStatus),l=ua(I=>I.setStatus),[p,m]=o.useState(!1),[x,d]=o.useState(!1),[y,c]=o.useState(!1),N=o.useRef(null),h=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),d(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{h()}},[i,r,e,h]);const C=o.useCallback(async()=>{if(!e)return;h(),m(!0);const I=qo(ua.getState().status);try{const E=await e.authStart(as()?"desktop":"web");d(!0),c(!0),Dn(E.authorizationUrl);const B=Date.now()+Tf;N.current=window.setInterval(()=>{(async()=>{if(Date.now()>B){h(),D.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const _=await r(e,{force:!0});Df(I,qo(_))&&(h(),D.success(t("settings.integrations.linear.toast.connected")),Cd())})()},Ef)}catch(E){console.error("Failed to start Linear connect:",E),D.error(t("settings.integrations.linear.toast.startConnectFailed")),h()}finally{m(!1)}},[r,e,h,t]),b=o.useCallback(async I=>{if(!(!e||!I)){m(!0);try{const E=await e.authActivate(I);l(E),D.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(E){console.error("Failed to switch Linear workspace:",E),D.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{m(!1)}}},[e,l,t]),S=o.useCallback(async()=>{if(e){m(!0);try{h(),await e.authDisconnect(),D.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(I){console.error("Failed to disconnect Linear:",I),D.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{m(!1)}}},[r,e,h,t]);if(!e)return null;const g=!!a?.connected,T=a?.user,M=a?.organization,k=(a?.workspaces??[]).filter(I=>!I.current),f=T?.displayName?.trim()||T?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),w=x?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):g?M?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),F=x?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",A=x||y;return s.jsx(Mn,{open:A,onOpenChange:I=>{if(x){c(!0);return}c(I)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Rn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",F),children:w}),s.jsx(R,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",A&&"rotate-180")})]}),s.jsx(Ln,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[g?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:f}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:f}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[M?.name,T?.email].filter(Boolean).join(" · ")})]})]}):x?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,g?s.jsxs(s.Fragment,{children:[s.jsx(Pf,{linear:e,connected:g,organizationId:M?.id??null}),s.jsx(Af,{linear:e,connected:g}),k.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:k.map(I=>{const E=I.user,B=I.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:B}),E?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:E.email}):null]}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(I.id)},disabled:p,children:t("settings.integrations.linear.actions.switchTo")})]},I.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:p||x,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(H,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},disabled:p,children:t("settings.integrations.linear.actions.disconnect")})]})]}):x?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",disabled:p,onClick:h,children:t("settings.common.actions.cancel")})]}):s.jsxs(H,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:p||n&&!i,children:[p?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Rf=()=>{const t=gt.c(18),{t:e}=it();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=cs(),t[0]=a):a=t[0];const n=!a,i=!!an()?.linear;let r;t[1]!==e?(r=e("settings.page.integrations.title"),t[1]=e,t[2]=r):r=t[2];let l;t[3]!==e?(l=e("settings.page.integrations.description"),t[3]=e,t[4]=l):l=t[4];let p;t[5]!==e?(p=e("settings.integrations.firstParty.title"),t[5]=e,t[6]=p):p=t[6];let m;t[7]!==e?(m=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=m):m=t[8];let x,d;t[9]===Symbol.for("react.memo_cache_sentinel")?(x=n?s.jsx(Nf,{}):null,d=i?s.jsx(Mf,{}):null,t[9]=x,t[10]=d):(x=t[9],d=t[10]);let y;t[11]!==p||t[12]!==m?(y=s.jsxs(_e,{title:p,info:m,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[x,d]}),t[11]=p,t[12]=m,t[13]=y):y=t[13];let c;return t[14]!==r||t[15]!==l||t[16]!==y?(c=s.jsx(es,{title:r,description:l,showSaveStatus:!0,children:y}),t[14]=r,t[15]=l,t[16]=y,t[17]=c):c=t[17],c},Lf=[{value:"system",labelKey:"settings.aiworker.visual.option.themeMode.system",descriptionKey:"settings.aiworker.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.aiworker.visual.option.themeMode.light",descriptionKey:"settings.aiworker.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.aiworker.visual.option.themeMode.dark",descriptionKey:"settings.aiworker.visual.option.themeMode.dark.description"}],Of=[{id:"dynamic",labelKey:"settings.aiworker.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.aiworker.visual.option.diffLayout.inline.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.aiworker.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.sideBySide.description"}],Ff=[{id:"svg",labelKey:"settings.aiworker.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.aiworker.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.ascii.description"}],Da="AiWorker - AI Coding Assistant",Jo=[{id:"system",labelKey:"settings.aiworker.visual.option.pwaOrientation.system.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.aiworker.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.aiworker.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.landscape.description"}],Qo=[{id:"native",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.description"}],tr=t=>t==="portrait"||t==="landscape"?t:"system",Kf=[{id:"markdown",labelKey:"settings.aiworker.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.aiworker.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.plain.description"}],zf=[{id:"sorted",labelKey:"settings.aiworker.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.aiworker.visual.option.chatRenderMode.live.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.live.description"}],Yo=[{id:"auto",labelKey:"settings.aiworker.visual.option.messageTransport.auto.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.aiworker.visual.option.messageTransport.ws.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.aiworker.visual.option.messageTransport.sse.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.sse.description"}],Uf=[{id:"collapsed",labelKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.aiworker.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.summary.description"}],Xo=[{id:"auto",labelKey:"settings.aiworker.visual.option.timeFormat.auto.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.aiworker.visual.option.timeFormat.24h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.aiworker.visual.option.timeFormat.12h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.12h.description"}],Zo=[{id:"auto",labelKey:"settings.aiworker.visual.option.weekStart.auto.label",descriptionKey:"settings.aiworker.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.aiworker.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.aiworker.visual.option.weekStart.sunday.label"}],_f=[{id:"steer",labelKey:"settings.aiworker.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.aiworker.visual.option.followUpBehavior.queue.label"}],$f=[{id:"ask",labelKey:"settings.aiworker.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.aiworker.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.aiworker.visual.option.largeTextPaste.inline.label"}],Vf=[{id:"global",labelKey:"settings.aiworker.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.aiworker.visual.option.inputHistoryScope.session.label"}],Bf=t=>t==="markdown"?"markdown":"plain",Hf=[{id:"left",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsRight"}],Gf=[{id:"classic",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsTrafficLights"}],Ai=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=it(),l=o.useCallback(u=>r(u),[r]),{isMobile:p}=wa(),{terminal:m}=wl(),{browserTab:x}=Hd(),d=Id(),y=le(u=>u.showReasoningTraces),c=le(u=>u.sessionRecapEnabled),N=le(u=>u.sessionSuggestionEnabled),h=le(u=>u.setSessionRecapEnabled),C=le(u=>u.setSessionSuggestionEnabled),b=le(u=>u.sessionGoalEnabled),S=le(u=>u.setSessionGoalEnabled),g=le(u=>u.sessionGoalDefaultBudgetEnabled),T=le(u=>u.setSessionGoalDefaultBudgetEnabled),M=le(u=>u.sessionGoalDefaultBudget),P=le(u=>u.setSessionGoalDefaultBudget),k=le(u=>u.setShowReasoningTraces),f=le(u=>u.streamingAutoFollowEnabled),w=le(u=>u.setStreamingAutoFollowEnabled),F=le(u=>u.collapsibleThinkingBlocks),A=le(u=>u.setCollapsibleThinkingBlocks),I=le(u=>u.mermaidRenderingMode),E=le(u=>u.setMermaidRenderingMode),B=le(u=>u.userMessageRenderingMode),_=le(u=>u.setUserMessageRenderingMode),j=le(u=>u.collapsibleUserMessages),V=le(u=>u.setCollapsibleUserMessages),q=le(u=>u.stickyUserHeader),L=le(u=>u.promptNavigatorEnabled),Q=le(u=>u.setStickyUserHeader),ne=le(u=>u.setPromptNavigatorEnabled),z=le(u=>u.autoSaveEnabled),re=le(u=>u.setAutoSaveEnabled),$=le(u=>u.wideChatLayoutEnabled),U=le(u=>u.setWideChatLayoutEnabled),K=le(u=>u.codeBlockLineWrap),O=le(u=>u.setCodeBlockLineWrap),Y=le(u=>u.chatRenderMode),X=le(u=>u.setChatRenderMode),ee=le(u=>u.activityRenderMode),ge=le(u=>u.setActivityRenderMode),de=le(u=>u.fontSize),xe=le(u=>u.setFontSize),ae=le(u=>u.terminalFontSize),te=le(u=>u.setTerminalFontSize),ue=le(u=>u.terminalShell),Ie=le(u=>u.setTerminalShell),Ne=le(u=>u.terminalLoginShells),Se=le(u=>u.setTerminalLoginShells),ve=le(u=>u.editorFontSize),Oe=le(u=>u.setEditorFontSize),Le=le(u=>u.uiFont),oe=le(u=>u.setUiFont),he=le(u=>u.monoFont),Me=le(u=>u.setMonoFont),$e=le(u=>u.padding),Ve=le(u=>u.setPadding),We=le(u=>u.inputBarOffset),se=le(u=>u.setInputBarOffset),ie=le(u=>u.mobileKeyboardMode),je=le(u=>u.setMobileKeyboardMode),be=le(u=>u.diffLayoutPreference),Te=le(u=>u.setDiffLayoutPreference),Ue=le(u=>u.showTerminalQuickKeysOnDesktop),Pe=le(u=>u.sessionTabsEnabled),we=le(u=>u.setSessionTabsEnabled),Ge=le(u=>u.setShowTerminalQuickKeysOnDesktop),pe=le(u=>u.fileEditorKeymap),Ce=le(u=>u.setFileEditorKeymap),Re=qr(u=>u.followUpBehavior),Ye=qr(u=>u.setFollowUpBehavior),W=ii(u=>u.scope),ke=ii(u=>u.entryLimit),Ae=ii(u=>u.applyScope),He=ii(u=>u.applyEntryLimit),at=le(u=>u.persistChatDraft),nt=le(u=>u.setPersistChatDraft),dt=le(u=>u.inputSpellcheckEnabled),xt=le(u=>u.setInputSpellcheckEnabled),G=le(u=>u.largeTextPasteBehavior),Be=le(u=>u.setLargeTextPasteBehavior),st=le(u=>u.enterToSend),rt=le(u=>u.setEnterToSend),ut=le(u=>u.enterToSendConfigured),St=le(u=>u.setEnterToSendConfigured),et=le(u=>u.isExpandedInput),Xe=le(u=>u.showToolFileIcons),ht=le(u=>u.setShowToolFileIcons),ze=le(u=>u.showTurnChangedFiles),jt=le(u=>u.setShowTurnChangedFiles),Ee=le(u=>u.showExpandedBashTools),wt=le(u=>u.setShowExpandedBashTools),J=le(u=>u.showExpandedEditTools),fe=le(u=>u.setShowExpandedEditTools),Fe=le(u=>u.timeFormatPreference),De=le(u=>u.setTimeFormatPreference),lt=le(u=>u.weekStartPreference),ct=le(u=>u.setWeekStartPreference),Qe=le(u=>u.showSplitAssistantMessageActions),kt=le(u=>u.setShowSplitAssistantMessageActions),vs=le(u=>u.allowPromptingSubagentSessions),Xt=le(u=>u.setAllowPromptingSubagentSessions),Ls=le(u=>u.draftStartersVisible),Gt=le(u=>u.setDraftStartersVisible),is=Ze(u=>u.settingsMessageStreamTransport),Ht=Ze(u=>u.setSettingsMessageStreamTransport),ys=is,ms=Ze(u=>u.settingsDefaultFileViewerPreview),gs=Ze(u=>u.setSettingsDefaultFileViewerPreview),ds=le(u=>u.isSettingsDialogOpen),{themeMode:Ts,setThemeMode:ce,availableThemes:pt,customThemesLoading:bt,reloadCustomThemes:Qt,lightThemeId:Yt,darkThemeId:Bt,setLightThemePreference:rs,setDarkThemePreference:bs}=Nr(),[ss,Nt]=o.useState(!1),Tt=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),Ut=le(u=>u.dockBadgeEnabled),Ot=le(u=>u.setDockBadgeEnabled),ns=Pd(),Es=le(u=>u.desktopWindowControlsPosition),Wa=le(u=>u.setDesktopWindowControlsPosition),Ti=le(u=>u.desktopWindowControlsStyle),qa=le(u=>u.setDesktopWindowControlsStyle),[Ei,zs]=o.useState(0),ja=le(u=>u.reportUsage),Ja=le(u=>u.setReportUsage),Qa=o.useCallback(u=>{Ja(u),yt({reportUsage:u})},[Ja]),Di=o.useCallback(u=>{Wa(u),yt({desktopWindowControlsPosition:u})},[Wa]),Mi=o.useCallback(u=>{qa(u),yt({desktopWindowControlsStyle:u})},[qa]),Ya=(ds||p||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Ya)return;let u=null,vt=Date.now();const Ns=()=>{const gn=Date.now();gn-vt>=420&&(zs(_n=>(_n+1)%24),vt=gn),u=requestAnimationFrame(Ns)};(typeof document>"u"||document.visibilityState==="visible")&&(u=requestAnimationFrame(Ns));const us=()=>{document.visibilityState==="visible"&&u===null?u=requestAnimationFrame(Ns):document.visibilityState!=="visible"&&u!==null&&(cancelAnimationFrame(u),u=null)};return document.addEventListener("visibilitychange",us),()=>{document.removeEventListener("visibilitychange",us),u!==null&&cancelAnimationFrame(u)}},[Ya]);const Ri=o.useCallback(u=>{_(u),yt({userMessageRenderingMode:u})},[_]),Li=o.useCallback(u=>{Q(u),yt({stickyUserHeader:u})},[Q]),ws=o.useCallback(u=>{ne(u),yt({promptNavigatorEnabled:u})},[ne]),Gs=o.useCallback(u=>{Gt(u),yt({draftStartersVisible:u})},[Gt]),sa=o.useCallback(u=>{V(u),yt({collapsibleUserMessages:u})},[V]),un=o.useCallback(u=>{U(u),yt({wideChatLayoutEnabled:u})},[U]),vn=o.useCallback(u=>{kt(u),yt({showSplitAssistantMessageActions:u})},[kt]),Rr=o.useCallback(u=>{xt(u),yt({inputSpellcheckEnabled:u})},[xt]),Xs=o.useCallback(u=>{rt(u),St(!0),yt({enterToSend:u,enterToSendConfigured:!0})},[rt,St]),Oi=o.useCallback(u=>{X(u),yt({chatRenderMode:u})},[X]),na=o.useCallback(u=>{Ht(u),yt({messageStreamTransport:u})},[Ht]),aa=o.useCallback(u=>{Ae(u),yt({inputHistoryScope:u})},[Ae]),On=o.useCallback(u=>{const vt=Math.round(u);Ad(vt)&&(He(vt),yt({inputHistoryLimit:vt}))},[He]),ka=o.useCallback(u=>{ge(u),yt({activityRenderMode:u})},[ge]),Fi=o.useCallback(u=>{E(u),yt({mermaidRenderingMode:u})},[E]),os=o.useCallback(u=>{ht(u),yt({showToolFileIcons:u})},[ht]),Ki=o.useCallback(u=>{jt(u),yt({showTurnChangedFiles:u})},[jt]),ia=o.useCallback(u=>{gs(u),yt({defaultFileViewerPreview:u}),window.dispatchEvent(new CustomEvent("aiworker:file-viewer-preview-mode-changed",{detail:{enabled:u}}))},[gs]),ra=o.useCallback(u=>{wt(u),yt({showExpandedBashTools:u})},[wt]),zi=o.useCallback(u=>{fe(u),yt({showExpandedEditTools:u})},[fe]),Xa=o.useCallback(u=>{De(u),yt({timeFormatPreference:u})},[De]),Ui=o.useCallback(u=>{ct(u),yt({weekStartPreference:u})},[ct]),Fn=o.useMemo(()=>pt.filter(u=>u.metadata.variant==="light").sort((u,vt)=>u.metadata.name.localeCompare(vt.metadata.name)),[pt]),pn=o.useMemo(()=>pt.filter(u=>u.metadata.variant==="dark").sort((u,vt)=>u.metadata.name.localeCompare(vt.metadata.name)),[pt]),yn=o.useMemo(()=>Fn.find(u=>u.metadata.id===Yt)??Fn[0],[Fn,Yt]),oa=o.useMemo(()=>pn.find(u=>u.metadata.id===Bt)??pn[0],[pn,Bt]),la=o.useCallback((u,vt)=>{const Ns=vt==="dark"?" Dark":" Light";return u.endsWith(Ns)?u.slice(0,-Ns.length):u},[]),me=u=>t?t.includes(u):!0,ls=cs(),Kn=me("theme")&&!ls,Za=me("windowControlsPosition")&&ns,ei=me("theme")||me("timeFormat")||me("weekStart"),ti=ls?ei:me("theme")||Za||me("pwaInstallName")||me("pwaOrientation")||me("timeFormat")||me("weekStart"),si=me("fontSize")||me("terminalFontSize")||me("editorFontSize")||me("spacing")||me("inputBarOffset")&&p,ni=me("terminalQuickKeys")&&!p||(me("terminalShell")||me("terminalLoginShell"))&&!ls||me("fileEditorKeymap")||me("autoSaveEnabled")||me("sessionTabs")&&!ls&&!p,_i=me("mermaidRendering")||me("sessionGoal")&&!ls||me("userMessageRendering")||me("chatRenderMode")||me("messageTransport")||me("activityRenderMode")&&Y==="sorted"||me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!ls||me("wideChatLayout")||me("codeBlockLineWrap")||me("splitAssistantMessageActions")||me("subagentReadOnlyBanner")||me("diffLayout")||me("dotfiles")||me("fileViewerPreview")||me("reasoning")||me("followUpBehavior")||me("inputHistoryScope")||me("inputHistoryLimit")||me("persistDraft")||me("largeTextPaste")||me("showToolFileIcons")||me("expandedTools")||!p&&me("inputSpellcheck")||me("enterToSend"),ca=me("chatRenderMode")||me("activityRenderMode")&&Y==="sorted",Na=me("messageTransport"),bn=me("userMessageRendering")||me("mermaidRendering")||me("diffLayout")&&!ls||me("followUpBehavior")||me("inputHistoryScope")||me("inputHistoryLimit"),da=me("sessionAssist")||me("sessionGoal")&&!ls||me("subagentReadOnlyBanner")||me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!ls||me("wideChatLayout")||me("codeBlockLineWrap")||me("splitAssistantMessageActions")||me("dotfiles")||me("fileViewerPreview")||me("persistDraft")||me("largeTextPaste")||me("showToolFileIcons")||me("showTurnChangedFiles")||!p&&me("inputSpellcheck")||me("enterToSend")||me("reasoning")||me("expandedTools"),wn=ti||si||ni,jn=me("pwaInstallName")&&qn()&&x&&!as()&&!ls,v=me("pwaOrientation")&&qn()&&!as()&&!ls,Z=me("mobileKeyboardMode")&&qn()&&!as()&&!ls&&Td(),Ke=(me("terminalShell")||me("terminalLoginShell"))&&!ls,[tt,Dt]=o.useState([]),[Ds,js]=o.useState(0);o.useEffect(()=>Tl(()=>{Dt([]),js(u=>u+1)}),[]),o.useEffect(()=>{let u=!1;if(!(!Ke||!m.listShells))return m.listShells().then(vt=>{u||Dt(vt)}).catch(()=>{u||Dt([])}),()=>{u=!0}},[Ke,m,Ds]);const _s=o.useMemo(()=>{const u=tt.filter(vt=>vt.id!=="auto");return ue==="auto"||u.some(vt=>vt.id===ue)?u:[{id:ue,name:ue,supportsLogin:!1},...u]},[tt,ue]),ks=tt.find(u=>u.id===ue)?.supportsLogin===!0,Ws=Ne.includes(ue),Sa=u=>{Se(u?[...Ne.filter(vt=>vt!==ue),ue]:Ne.filter(vt=>vt!==ue))},[mn,qs]=o.useState(""),[Ct,Wt]=o.useState("system"),zn=o.useMemo(()=>{const u=Xo.find(vt=>vt.id===Fe);return l(u?.labelKey??"settings.aiworker.visual.option.timeFormat.auto.label")},[Fe,l]),Mt=o.useMemo(()=>{const u=Zo.find(vt=>vt.id===lt);return l(u?.labelKey??"settings.aiworker.visual.option.weekStart.auto.label")},[lt,l]),Ms=o.useMemo(()=>{const u=Jo.find(vt=>vt.id===Ct);return u?l(u.labelKey):void 0},[Ct,l]),Un=o.useMemo(()=>{const u=Qo.find(vt=>vt.id===ie);return u?l(u.labelKey):void 0},[ie,l]),kn=o.useCallback(async u=>{if(typeof window>"u")return;const vt=window,us=u.trim().replace(/\s+/g," ").slice(0,64);if(await yt({pwaAppName:us}),typeof vt.__AIWORKER_SET_PWA_INSTALL_NAME__=="function"){const gn=vt.__AIWORKER_SET_PWA_INSTALL_NAME__(us);qs(gn);return}qs(us||Da),vt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]),Ca=o.useCallback(async u=>{if(typeof window>"u")return;const vt=window,Ns=tr(u);if(await yt({pwaOrientation:Ns}),typeof vt.__AIWORKER_SET_PWA_ORIENTATION__=="function"){const us=vt.__AIWORKER_SET_PWA_ORIENTATION__(Ns);Wt(us);return}Wt(Ns),vt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!jn&&!v&&!Z)return;let u=!1;return(async()=>{try{const Ns=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Ns.ok){u||qs(Da);return}const us=await Ns.json().catch(()=>({})),_n=(typeof us?.pwaAppName=="string"?us.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),ai=tr(us?.pwaOrientation),$i=Zr(us?.mobileKeyboardMode);u||(jn&&qs(_n||Da),v&&Wt(ai),Z&&je($i))}catch{u||(jn&&qs(Da),v&&Wt("system"),Z&&je("native"))}})(),()=>{u=!0}},[je,Z,jn,v]),s.jsxs("div",{className:"space-y-0",children:[ti&&s.jsxs("div",{className:"space-y-0",children:[Kn&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(An,{children:[s.jsx("div",{className:Js,children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.colorMode"),children:Lf.map(u=>s.jsx(tn,{selected:Ts===u.value,onSelect:()=>ce(u.value),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.value))})}),s.jsxs("div",{className:Js,children:[s.jsx(qt,{label:r("settings.aiworker.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(It,{value:yn?.metadata.id??"",onValueChange:rs,children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectLightThemeAria"),size:Ft,className:Nn,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectThemePlaceholder"),children:yn?la(yn.metadata.name,"light"):void 0})}),s.jsx(At,{children:Fn.map(u=>s.jsx(ot,{value:u.metadata.id,children:la(u.metadata.name,"light")},u.metadata.id))})]})}),s.jsx(qt,{label:r("settings.aiworker.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(It,{value:oa?.metadata.id??"",onValueChange:bs,children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectDarkThemeAria"),size:Ft,className:Nn,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectThemePlaceholder"),children:oa?la(oa.metadata.name,"dark"):void 0})}),s.jsx(At,{children:pn.map(u=>s.jsx(ot,{value:u.metadata.id,children:la(u.metadata.name,"dark")},u.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:bt||ss,onClick:()=>{const u=Date.now();Nt(!0),Qt().finally(()=>{const vt=Date.now()-u;if(vt<500){window.setTimeout(()=>{Nt(!1)},500-vt);return}Nt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(R,{name:"restart",className:ye("h-3.5 w-3.5",ss&&"animate-spin")}),r(ss?"settings.aiworker.visual.actions.reloadingThemes":"settings.aiworker.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:r("settings.aiworker.visual.field.themeImportInfoTooltip")})]})]})]}),Tt&&s.jsx(Va,{settingsItem:"appearance.dock-badge",children:s.jsx(ft,{checked:Ut,onChange:Ot,label:r("settings.aiworker.visual.field.dockBadge"),info:r("settings.aiworker.visual.field.dockBadgeHint"),ariaLabel:r("settings.aiworker.visual.field.dockBadge")})})]}),Za&&s.jsx(_e,{title:r("settings.aiworker.desktopNetwork.field.windowControls"),info:r("settings.aiworker.desktopNetwork.field.windowControlsPositionDescription"),divider:Kn,children:s.jsxs(An,{children:[s.jsx(qt,{label:r("settings.aiworker.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Qs,{value:Es,options:Hf.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Di,"aria-label":r("settings.aiworker.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(qt,{label:r("settings.aiworker.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Qs,{value:Ti,options:Gf.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Mi,"aria-label":r("settings.aiworker.desktopNetwork.field.windowControlsStyleAria")})})]})}),ei&&s.jsx(_e,{title:r("settings.aiworker.visual.section.localization"),children:s.jsxs(An,{children:[s.jsx(qt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(It,{value:e,onValueChange:u=>n(u),children:[s.jsx(Pt,{"aria-label":r("settings.appearance.language.select"),size:Ft,className:Nn,children:s.jsx(Rt,{children:i(e)})}),s.jsx(At,{children:a.map(u=>s.jsx(ot,{value:u,children:i(u)},u))})]})}),(me("timeFormat")||me("weekStart"))&&s.jsxs("div",{className:Js,children:[me("timeFormat")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(It,{value:Fe,onValueChange:u=>Xa(u),children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectTimeFormatAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:zn})}),s.jsx(At,{children:Xo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]})}),me("weekStart")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(It,{value:lt,onValueChange:u=>Ui(u),children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectWeekStartAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Mt})}),s.jsx(At,{children:Zo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]})})]})]})}),(jn||v||Z)&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.appInstall"),contentClassName:Js,children:[jn&&s.jsxs(Lt,{label:r("settings.aiworker.visual.field.installAppName"),info:r("settings.aiworker.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Fs,children:[s.jsx(Je,{value:mn,onChange:u=>{qs(u.target.value)},onBlur:()=>{kn(mn)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),kn(mn))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.aiworker.visual.field.pwaInstallAppNameAria")}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{qs(Da),kn("")},className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),v&&s.jsxs(Lt,{label:r("settings.aiworker.visual.field.installOrientation"),description:r("settings.aiworker.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Fs,children:[s.jsxs(It,{value:Ct,onValueChange:u=>{const vt=tr(u);Wt(vt),Ca(vt)},children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.pwaInstallOrientationAria"),size:Ft,className:zr,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectOrientationPlaceholder"),children:Ms})}),s.jsx(At,{children:Jo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Wt("system"),Ca("system")},disabled:Ct==="system",className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),Z&&s.jsxs(Lt,{label:r("settings.aiworker.visual.field.mobileKeyboardMode"),info:r("settings.aiworker.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Fs,children:[s.jsxs(It,{value:ie,onValueChange:u=>{const vt=Zr(u);je(vt),yt({mobileKeyboardMode:vt})},children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.mobileKeyboardModeAria"),size:Ft,className:zr,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectMobileKeyboardModePlaceholder"),children:Un})}),s.jsx(At,{children:Qo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{je("native"),yt({mobileKeyboardMode:"native"})},disabled:ie==="native",className:fs,"aria-label":r("settings.aiworker.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),si&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.densityAndType"),contentClassName:Js,children:[me("fontSize")&&!p||me("terminalFontSize")?s.jsxs(An,{children:[me("fontSize")&&!p&&s.jsxs(qt,{label:r("settings.aiworker.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(It,{value:Le,onValueChange:u=>oe(u),children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectInterfaceFontAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Jr.find(u=>u.id===Le)?.label})}),s.jsx(At,{children:Jr.map(u=>s.jsx(ot,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>oe(Qr),disabled:Le===Qr,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),me("terminalFontSize")&&s.jsxs(qt,{label:r("settings.aiworker.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(It,{value:he,onValueChange:u=>Me(u),children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.selectCodeFontAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Yr.find(u=>u.id===he)?.label})}),s.jsx(At,{children:Yr.map(u=>s.jsx(ot,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Me(Xr),disabled:he===Xr,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,me("fontSize")&&!p||me("terminalFontSize")||me("editorFontSize")?s.jsxs(An,{children:[me("fontSize")&&!p&&s.jsx(qt,{label:r("settings.aiworker.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:de,onValueChange:xe,min:50,max:200,step:5,className:Cs,"aria-label":r("settings.aiworker.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ma,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(100),disabled:de===100,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("terminalFontSize")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:ae,onValueChange:te,min:9,max:52,step:1,className:Cs}),s.jsx("span",{className:ma,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>te(13),disabled:ae===13,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("editorFontSize")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:ve,onValueChange:Oe,min:9,max:32,step:1,className:Cs}),s.jsx("span",{className:ma,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Oe(13),disabled:ve===13,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,me("spacing")||me("inputBarOffset")&&p?s.jsxs(An,{children:[me("spacing")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:$e,onValueChange:Ve,min:50,max:200,step:5,className:Cs}),s.jsx("span",{className:ma,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(100),disabled:$e===100,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("inputBarOffset")&&p&&s.jsx(qt,{label:r("settings.aiworker.visual.field.inputBarOffset"),info:r("settings.aiworker.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:We,onValueChange:se,min:0,max:100,step:5,className:Cs}),s.jsx("span",{className:ma,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>se(0),disabled:We===0,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),ni&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.navigation"),contentClassName:"space-y-4",children:[me("fileEditorKeymap")&&s.jsx(Ps,{title:r("settings.aiworker.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.field.fileEditorKeymap"),children:["default","vim"].map(u=>s.jsx(tn,{selected:pe===u,onSelect:()=>Ce(u),label:r(`settings.aiworker.visual.option.fileEditorKeymap.${u}`),ariaLabel:r(`settings.aiworker.visual.option.fileEditorKeymap.${u}`)},u))})}),s.jsxs("div",{className:hs,children:[me("autoSaveEnabled")&&s.jsx(ft,{checked:z,onChange:re,label:r("settings.aiworker.visual.field.autoSaveEnabled"),ariaLabel:r("settings.aiworker.visual.field.autoSaveEnabledAria"),info:r("settings.aiworker.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Ke&&s.jsx(qt,{label:r("settings.aiworker.visual.field.terminalShell"),info:r("settings.aiworker.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(It,{value:ue,onValueChange:u=>{Ed(u)&&Ie(u)},children:[s.jsx(Pt,{"aria-label":r("settings.aiworker.visual.field.terminalShellAria"),size:Ft,className:Nn,children:s.jsx(Rt,{})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:r("settings.aiworker.visual.option.terminalShell.auto")}),_s.map(u=>s.jsx(ot,{value:u.id,children:u.name},u.id))]})]})}),Ke&&ks&&s.jsx(ft,{checked:Ws,onChange:Sa,label:r("settings.aiworker.visual.field.terminalLoginShell"),ariaLabel:r("settings.aiworker.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),me("terminalQuickKeys")&&!p&&s.jsx(ft,{checked:Ue,onChange:Ge,label:r("settings.aiworker.visual.field.terminalQuickKeys"),ariaLabel:r("settings.aiworker.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.aiworker.visual.field.terminalQuickKeysTooltip",{control:Qn("ctrl"),alt:Qn("alt")})})]}),me("sessionTabs")&&!ls&&!p&&s.jsx(Ps,{title:r("settings.aiworker.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(ft,{checked:Pe,onChange:we,label:r("settings.aiworker.visual.field.sessionTabs"),ariaLabel:r("settings.aiworker.visual.field.sessionTabsAria"),info:r("settings.aiworker.visual.field.sessionTabsInfo")})})]}),_i&&s.jsxs(s.Fragment,{children:[ca&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.chatDisplay"),divider:wn,contentClassName:"space-y-6",children:[me("chatRenderMode")&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.aiworker.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:zf.map(u=>{const vt=Y===u.id,Ns=Ei%12;return s.jsxs("button",{type:"button",onClick:()=>Oi(u.id),"aria-pressed":vt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ye("typography-ui-label",vt?"text-foreground":"text-muted-foreground"),children:l(u.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:u.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(us=>{const gn=us*3+1,_n=Ns-gn+1,ai=_n<=0?0:_n===1?42:_n===2?68:92,$i=ai>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",$i?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${ai}%`}})]},us)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(us=>{const gn=Ns>=(us+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",gn?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},us)})})})]},u.id)})})}),me("activityRenderMode")&&Y==="sorted"&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.activityDefault"),children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.activityDefaultAria"),children:Uf.map(u=>s.jsx(tn,{selected:ee===u.id,onSelect:()=>ka(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.activityDefaultModeAria",{option:l(u.labelKey)})},u.id))})})]}),Na&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.messageStreamTransport"),divider:ca||wn,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Qs,{value:ys,options:Yo.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:na,"aria-label":r("settings.aiworker.visual.section.messageStreamTransport")}),(()=>{const u=Yo.find(vt=>vt.id===ys);return u?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(u.descriptionKey)}):null})()]}),bn&&s.jsx(_e,{title:r("settings.aiworker.visual.section.chatMessageOptions"),divider:ca||Na||wn,children:s.jsxs(An,{className:"lg:gap-y-6",children:[me("userMessageRendering")&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.userMessageRendering"),children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.userMessageRenderingAria"),children:Kf.map(u=>s.jsx(tn,{selected:Bf(B)===u.id,onSelect:()=>Ri(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.userMessageRenderingAria",{option:l(u.labelKey)})},u.id))})}),me("mermaidRendering")&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.mermaidRendering"),children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.mermaidRenderingAria"),children:Ff.map(u=>s.jsx(tn,{selected:I===u.id,onSelect:()=>Fi(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.mermaidRenderingAria",{option:l(u.labelKey)})},u.id))})}),me("diffLayout")&&!ls&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.diffLayout"),children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.diffLayoutAria"),children:Of.map(u=>s.jsx(tn,{selected:be===u.id,onSelect:()=>Te(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.diffLayoutAria",{option:l(u.labelKey)})},u.id))})}),me("followUpBehavior")&&s.jsx(Ps,{title:r("settings.aiworker.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.followUpBehaviorAria"),children:_f.map(u=>s.jsx(tn,{selected:Re===u.id,onSelect:()=>Ye(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.followUpBehaviorAria",{option:l(u.labelKey)})},u.id))})}),me("inputHistoryScope")&&s.jsx(Ps,{title:r("settings.aiworker.visual.field.inputHistoryScope"),info:r("settings.aiworker.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.section.inputHistoryScopeAria"),children:Vf.map(u=>s.jsx(tn,{selected:W===u.id,onSelect:()=>aa(u.id),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.id))})}),me("inputHistoryLimit")&&s.jsx(Ps,{title:r("settings.aiworker.visual.field.inputHistoryLimit"),description:r("settings.aiworker.visual.field.inputHistoryLimitDescription"),contentClassName:Fs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:pa,children:[s.jsx(xs,{value:ke,onValueChange:On,min:Md,max:Dd,step:1,className:Cs,deferExternalValueWhileFocused:!0,"aria-label":r("settings.aiworker.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ma,children:r("settings.aiworker.visual.field.inputHistoryLimitUnit")})]})})]})}),da&&s.jsxs(s.Fragment,{children:[me("expandedTools")&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.showToolsOpenedByDefault"),divider:ca||Na||bn||wn,contentClassName:hs,children:[s.jsx(ft,{checked:Ee,onChange:ra,label:r("settings.aiworker.visual.field.bash"),ariaLabel:r("settings.aiworker.visual.field.showExpandedBashToolsAria")}),s.jsx(ft,{checked:J,onChange:zi,label:r("settings.aiworker.visual.field.editTools"),ariaLabel:r("settings.aiworker.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(_e,{title:r("settings.aiworker.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:hs,children:[s.jsx(ft,{checked:Ls,onChange:Gs,label:r("settings.aiworker.visual.field.draftStartersVisible"),ariaLabel:r("settings.aiworker.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),me("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(ft,{checked:c,onChange:h,label:r("settings.aiworker.visual.field.sessionRecap"),ariaLabel:r("settings.aiworker.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(ft,{checked:N,onChange:C,label:r("settings.aiworker.visual.field.sessionSuggestion"),ariaLabel:r("settings.aiworker.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),me("subagentReadOnlyBanner")&&s.jsx(ft,{checked:vs,onChange:Xt,label:r("settings.aiworker.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.aiworker.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),me("sessionGoal")&&!ls&&s.jsxs(_e,{title:r("settings.aiworker.visual.goal.sectionTitle"),info:r("settings.aiworker.visual.goal.description"),contentClassName:hs,children:[s.jsx(ft,{checked:b,onChange:S,label:r("settings.aiworker.visual.field.sessionGoal"),ariaLabel:r("settings.aiworker.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(ft,{checked:g,onChange:T,disabled:!b,label:r("settings.aiworker.visual.goal.budgetLabel"),ariaLabel:r("settings.aiworker.visual.goal.budgetAria")}),b&&g?s.jsx(xs,{value:M,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&P(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),me("reasoning")&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:hs,children:[s.jsx(ft,{checked:y,onChange:k,label:r("settings.aiworker.visual.field.showReasoningTraces"),ariaLabel:r("settings.aiworker.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),y&&s.jsx(ft,{checked:F,onChange:A,label:r("settings.aiworker.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.aiworker.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(_e,{title:r("settings.aiworker.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:hs,children:s.jsx(ft,{checked:f,onChange:w,label:r("settings.aiworker.visual.field.streamingAutoFollow"),ariaLabel:r("settings.aiworker.visual.field.streamingAutoFollowAria"),info:r("settings.aiworker.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!ls||me("wideChatLayout")||me("splitAssistantMessageActions")||me("codeBlockLineWrap"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:hs,children:[me("collapsibleUserMessages")&&s.jsx(ft,{checked:j,onChange:sa,label:r("settings.aiworker.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.aiworker.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),me("stickyUserHeader")&&s.jsx(ft,{checked:q,onChange:Li,label:r("settings.aiworker.visual.field.stickyUserHeader"),ariaLabel:r("settings.aiworker.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),me("promptNavigatorEnabled")&&!ls&&s.jsx(ft,{checked:L,onChange:ws,label:r("settings.aiworker.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.aiworker.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),me("wideChatLayout")&&s.jsx(ft,{checked:$,onChange:un,label:r("settings.aiworker.visual.field.wideChatLayout"),ariaLabel:r("settings.aiworker.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),me("splitAssistantMessageActions")&&s.jsx(ft,{checked:Qe,onChange:vn,label:r("settings.aiworker.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.aiworker.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip")}),me("codeBlockLineWrap")&&s.jsx(ft,{checked:K,onChange:O,label:r("settings.aiworker.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.aiworker.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(me("showToolFileIcons")||me("showTurnChangedFiles")||me("dotfiles")&&!cs()||me("fileViewerPreview"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:hs,children:[me("showToolFileIcons")&&s.jsx(ft,{checked:Xe,onChange:os,label:r("settings.aiworker.visual.field.showToolFileIcons"),ariaLabel:r("settings.aiworker.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),me("showTurnChangedFiles")&&s.jsx(ft,{checked:ze,onChange:Ki,label:r("settings.aiworker.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.aiworker.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),me("dotfiles")&&!cs()&&s.jsx(ft,{checked:d,onChange:Rd,label:r("settings.aiworker.visual.field.showDotfiles"),ariaLabel:r("settings.aiworker.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),me("fileViewerPreview")&&s.jsx(ft,{checked:ms,onChange:ia,label:r("settings.aiworker.defaults.field.openFilesPreview"),ariaLabel:r("settings.aiworker.defaults.field.openFilesPreviewAria")})]}),(me("persistDraft")||me("largeTextPaste")||!p&&me("inputSpellcheck")||me("enterToSend"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.composer"),settingsItem:"chat.composer",contentClassName:hs,children:[me("persistDraft")&&s.jsx(ft,{checked:at,onChange:nt,label:r("settings.aiworker.visual.field.persistDraftMessages"),ariaLabel:r("settings.aiworker.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!p&&me("inputSpellcheck")&&s.jsx(ft,{checked:dt,onChange:Rr,label:r("settings.aiworker.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.aiworker.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"}),me("largeTextPaste")&&s.jsx(Ps,{title:r("settings.aiworker.visual.field.largeTextPaste"),info:r("settings.aiworker.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(en,{"aria-label":r("settings.aiworker.visual.field.largeTextPasteAria"),children:$f.map(u=>s.jsx(tn,{selected:G===u.id,onSelect:()=>Be(u.id),label:l(u.labelKey),ariaLabel:r("settings.aiworker.visual.field.largeTextPasteOptionAria",{option:l(u.labelKey)})},u.id))})}),me("enterToSend")&&s.jsx(ft,{checked:ut?st:!p&&!et,onChange:Xs,label:r("settings.aiworker.visual.field.enterToSend"),info:r("settings.aiworker.visual.field.enterToSendHint"),ariaLabel:r("settings.aiworker.visual.field.enterToSend"),settingsItem:"chat.enter-to-send"})]})]})]}),me("reportUsage")&&s.jsx(_e,{title:r("settings.aiworker.visual.section.privacy"),children:s.jsx(ft,{checked:ja,onChange:Qa,label:r("settings.aiworker.visual.field.sendAnonymousUsageReports"),info:r("settings.aiworker.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.aiworker.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Wf=1,qf=365,el=30,Jf=[{value:"archive",labelKey:"settings.aiworker.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.aiworker.sessionRetention.action.delete"}],Xl=()=>{const t=gt.c(88),{t:e}=it(),a=le(Qf),n=le(Yf),i=le(Xf),r=le(Zf),l=le(eh),p=le(th);let m;t[0]===Symbol.for("react.memo_cache_sentinel")?(m={autoRun:!1},t[0]=m):m=t[0];const{candidates:x,isRunning:d,runCleanup:y,action:c}=Gc(m),N=x.length;let h;t[1]!==y||t[2]!==e?(h=async()=>{const de=await y({force:!0});if(de.completedIds.length===0&&de.failedIds.length===0){D.message(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.noneEligibleArchive"):e("settings.aiworker.sessionRetention.toast.noneEligibleDelete"));return}de.completedIds.length>0&&D.success(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.archivedCount",{count:de.completedIds.length}):e("settings.aiworker.sessionRetention.toast.deletedCount",{count:de.completedIds.length})),de.failedIds.length>0&&D.error(de.action==="archive"?e("settings.aiworker.sessionRetention.toast.failedArchiveCount",{count:de.failedIds.length}):e("settings.aiworker.sessionRetention.toast.failedDeleteCount",{count:de.failedIds.length}))},t[1]=y,t[2]=e,t[3]=h):h=t[3];const C=h;let b;t[4]!==e?(b=e("settings.aiworker.sessionRetention.title"),t[4]=e,t[5]=b):b=t[5];let S;t[6]!==e?(S=e("settings.aiworker.sessionRetention.tooltip"),t[6]=e,t[7]=S):S=t[7];let g;t[8]!==e?(g=e("settings.aiworker.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=g):g=t[9];let T;t[10]!==e?(T=e("settings.aiworker.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=T):T=t[11];let M;t[12]!==a||t[13]!==r||t[14]!==g||t[15]!==T?(M=s.jsx(ft,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:g,ariaLabel:T}),t[12]=a,t[13]=r,t[14]=g,t[15]=T,t[16]=M):M=t[16];let P;t[17]!==e?(P=e("settings.aiworker.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=P):P=t[18];let k;t[19]!==e?(k=e("settings.aiworker.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=k):k=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=ye(Cs,"tabular-nums"),t[21]=f):f=t[21];let w;t[22]!==n||t[23]!==l||t[24]!==k?(w=s.jsx(xs,{value:n,onValueChange:l,min:Wf,max:qf,step:1,"aria-label":k,className:f}),t[22]=n,t[23]=l,t[24]=k,t[25]=w):w=t[25];let F;t[26]!==e?(F=e("settings.aiworker.sessionRetention.field.days"),t[26]=e,t[27]=F):F=t[27];let A;t[28]!==F?(A=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:F}),t[28]=F,t[29]=A):A=t[29];let I;t[30]!==l?(I=()=>l(el),t[30]=l,t[31]=I):I=t[31];const E=n===el;let B;t[32]!==e?(B=e("settings.aiworker.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=B):B=t[33];let _;t[34]!==e?(_=e("settings.common.actions.reset"),t[34]=e,t[35]=_):_=t[35];let j;t[36]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=j):j=t[36];let V;t[37]!==I||t[38]!==E||t[39]!==B||t[40]!==_?(V=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:I,disabled:E,className:fs,"aria-label":B,title:_,children:j}),t[37]=I,t[38]=E,t[39]=B,t[40]=_,t[41]=V):V=t[41];let q;t[42]!==w||t[43]!==A||t[44]!==V||t[45]!==P?(q=s.jsxs(Lt,{settingsItem:"sessions.retention-period",label:P,children:[w,A,V]}),t[42]=w,t[43]=A,t[44]=V,t[45]=P,t[46]=q):q=t[46];let L;t[47]!==e?(L=e("settings.aiworker.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=L):L=t[48];let Q;t[49]!==e?(Q=Jf.map(de=>({value:de.value,label:e(de.labelKey)})),t[49]=e,t[50]=Q):Q=t[50];let ne;t[51]!==i||t[52]!==p||t[53]!==Q?(ne=s.jsx(Qs,{value:i,onChange:p,options:Q}),t[51]=i,t[52]=p,t[53]=Q,t[54]=ne):ne=t[54];let z;t[55]!==L||t[56]!==ne?(z=s.jsx(Lt,{settingsItem:"sessions.retention-action",label:L,children:ne}),t[55]=L,t[56]=ne,t[57]=z):z=t[57];let re;t[58]!==q||t[59]!==z?(re=s.jsxs(Va,{className:"space-y-0",children:[q,z]}),t[58]=q,t[59]=z,t[60]=re):re=t[60];let $;t[61]!==e?($=e("settings.aiworker.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=$):$=t[62];let U;t[63]!==d||t[64]!==e?(U=e(d?"settings.aiworker.sessionRetention.actions.cleaningUp":"settings.aiworker.sessionRetention.actions.runCleanupNow"),t[63]=d,t[64]=e,t[65]=U):U=t[65];let K;t[66]!==C||t[67]!==d||t[68]!==U?(K=s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:C,disabled:d,className:"!font-normal",children:U}),t[66]=C,t[67]=d,t[68]=U,t[69]=K):K=t[69];let O;t[70]!==$||t[71]!==K?(O=s.jsx(Lt,{label:$,children:K}),t[70]=$,t[71]=K,t[72]=O):O=t[72];let Y;t[73]!==c||t[74]!==N||t[75]!==e?(Y=c==="archive"?e("settings.aiworker.sessionRetention.manualCleanup.eligibleArchiveNow",{count:N}):e("settings.aiworker.sessionRetention.manualCleanup.eligibleDeleteNow",{count:N}),t[73]=c,t[74]=N,t[75]=e,t[76]=Y):Y=t[76];let X;t[77]!==Y?(X=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Y}),t[77]=Y,t[78]=X):X=t[78];let ee;t[79]!==O||t[80]!==X?(ee=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[O,X]}),t[79]=O,t[80]=X,t[81]=ee):ee=t[81];let ge;return t[82]!==b||t[83]!==re||t[84]!==S||t[85]!==ee||t[86]!==M?(ge=s.jsxs(_e,{title:b,info:S,children:[M,re,ee]}),t[82]=b,t[83]=re,t[84]=S,t[85]=ee,t[86]=M,t[87]=ge):ge=t[87],ge};function Qf(t){return t.autoDeleteEnabled}function Yf(t){return t.autoDeleteAfterDays}function Xf(t){return t.sessionRetentionAction}function Zf(t){return t.setAutoDeleteEnabled}function eh(t){return t.setAutoDeleteAfterDays}function th(t){return t.setSessionRetentionAction}const tl=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(kr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Zl=()=>{const{t}=it(),e=le(f=>f.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,p]=o.useState(!1),[m,x]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState([]),[h,C]=o.useState(Wc),[b,S]=o.useState(""),g=o.useMemo(()=>qc(),[]),T=o.useCallback(async()=>{r(!0),S("");try{const f=await Jc();N(f)}catch(f){const w=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.loadFailed");S(w)}finally{r(!1)}},[t]);o.useEffect(()=>{let f=!1;return(async()=>{try{if(!g.supported){f||(n(!1),r(!1));return}f||n(!0)}catch{f||n(!1)}if(!f){const w=await Bi();if(C(w),!w.enabled){N([]),r(!1);return}await T()}})(),()=>{f=!0,Ur()}},[T,g.supported]);const M=o.useCallback(async()=>{if(!h.enabled){const f=t("settings.aiworker.passkeys.toast.enableUiPasswordFirst");S(f),D.message(f);return}if(!a){S(g.reason),D.message(g.reason);return}if(l){Ur(),p(!1);return}S(""),p(!0);try{await Qc(),C(await Bi()),await T(),D.success(t("settings.aiworker.passkeys.toast.added"))}catch(f){if(Yc(f)){D.message(t("settings.aiworker.passkeys.toast.setupCanceled"));return}const w=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.addFailed");S(w),D.error(w)}finally{p(!1)}},[l,T,h.enabled,g.reason,a,t]),P=o.useCallback(async f=>{x(f),S("");try{await Xc(f),C(await Bi()),await T(),D.success(t("settings.aiworker.passkeys.toast.removed"))}catch(w){const F=w instanceof Error?w.message:t("settings.aiworker.passkeys.toast.removeFailed");S(F),D.error(F)}finally{x(null)}},[T,t]),k=o.useCallback(async()=>{y(!0),S("");try{await Zc(),window.location.reload()}catch(f){const w=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.clearAuthFailed");S(w),D.error(w),y(!1)}},[t]);return s.jsxs(_e,{title:t("settings.aiworker.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Lt,{label:t("settings.aiworker.passkeys.field.currentDevice"),children:[s.jsx(H,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{M()},disabled:i||d,className:"!font-normal",children:t(l?"settings.aiworker.passkeys.actions.cancelSetup":"settings.aiworker.passkeys.actions.add")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k()},disabled:i||l||d,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(d?"settings.aiworker.passkeys.actions.signingOut":"settings.aiworker.passkeys.actions.signOutEverywhere")})]}),!h.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.uiPasswordRequired")}),h.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.loading")}):c.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:c.map(f=>s.jsxs(Lt,{label:s.jsx("span",{title:f.label,children:f.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:f.lastUsedAt?t("settings.aiworker.passkeys.item.lastUsed",{time:tl(f.lastUsedAt,t("settings.aiworker.passkeys.time.neverUsed"),e)}):t("settings.aiworker.passkeys.item.added",{time:tl(f.createdAt,t("settings.aiworker.passkeys.time.neverUsed"),e)})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P(f.id)},disabled:m===f.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:m===f.id?t("settings.aiworker.passkeys.actions.removing"):t("settings.common.actions.delete")})]},f.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},ec=()=>{const t=gt.c(14),{t:e}=it(),a=_r(sh),n=_r(nh);let i;t[0]!==e?(i=e("settings.aiworker.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.aiworker.appLinks.info"),t[2]=e,t[3]=r):r=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.appLinks.empty")}):a.map(x=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${x}://`}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(x),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.aiworker.appLinks.removeAria",{scheme:`${x}://`}),children:e("settings.common.actions.delete")})]},x)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let p;t[8]!==l?(p=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=p):p=t[9];let m;return t[10]!==i||t[11]!==r||t[12]!==p?(m=s.jsx(_e,{title:i,description:r,children:p}),t[10]=i,t[11]=r,t[12]=p,t[13]=m):m=t[13],m};function sh(t){return t.trustedSchemes}function nh(t){return t.removeTrustedScheme}const sr=t=>{const e=va(t);return e||{providerId:"",modelId:""}},tc=()=>{const{t}=it(),e=Ze(ae=>ae.setProvider),a=Ze(ae=>ae.setModel),n=Ze(ae=>ae.setAgent),i=Ze(ae=>ae.setCurrentVariant),r=Ze(ae=>ae.setCurrentVariantOverride),l=Ze(ae=>ae.setSettingsDefaultModel),p=Ze(ae=>ae.setSettingsDefaultVariant),m=Ze(ae=>ae.setSettingsDefaultAgent),x=Ze(ae=>ae.selectionSource==="manual"),d=ed(ae=>ae.currentSessionId),y=$r(ae=>ae.getSessionModelSelection),c=$r(ae=>ae.getSessionAgentSelection),N=!!(x&&d&&y(d)),h=!!(x&&d&&c(d)),C=le(ae=>ae.showDeletionDialog),b=le(ae=>ae.setShowDeletionDialog),S=Ze(ae=>ae.providers),g=Ze(ae=>ae.modelsMetadata),[T,M]=o.useState(),[P,k]=o.useState(),[f,w]=o.useState(),[F,A]=o.useState(!0),[I,E]=o.useState(),[B,_]=o.useState([]),[j,V]=o.useState(),[q,L]=o.useState(!0),Q=o.useMemo(()=>sr(T),[T]);o.useEffect(()=>{(async()=>{try{let te=null;if(!te){const ue=an()?.settings;if(ue)try{const Ne=(await ue.load())?.settings;if(Ne){const Se=Ne;te={defaultModel:typeof Ne.defaultModel=="string"?Ne.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof Ne.defaultAgent=="string"?Ne.defaultAgent:void 0,smallModelUseDefault:typeof Se.smallModelUseDefault=="boolean"?Se.smallModelUseDefault:void 0,smallModelOverride:typeof Se.smallModelOverride=="string"?Se.smallModelOverride:void 0,walkthroughModelOverride:typeof Se.walkthroughModelOverride=="string"?Se.walkthroughModelOverride:void 0}}}catch{}}if(!te){const ue=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});ue.ok&&(te=await ue.json())}if(te){const ue=typeof te.defaultModel=="string"&&te.defaultModel.trim().length>0?te.defaultModel.trim():void 0,Ie=typeof te.defaultVariant=="string"&&te.defaultVariant.trim().length>0?te.defaultVariant.trim():void 0,Ne=typeof te.defaultAgent=="string"&&te.defaultAgent.trim().length>0?te.defaultAgent.trim():void 0;ue!==void 0&&M(ue),Ie!==void 0&&k(Ie),Ne!==void 0&&w(Ne),typeof te.smallModelUseDefault=="boolean"&&A(te.smallModelUseDefault),typeof te.smallModelOverride=="string"&&te.smallModelOverride.trim()&&E(te.smallModelOverride.trim()),typeof te.walkthroughModelOverride=="string"&&te.walkthroughModelOverride.trim()&&V(te.walkthroughModelOverride.trim())}}catch(te){console.warn("Failed to load defaults settings:",te)}finally{L(!1)}})()},[]);const ne=o.useCallback(async(ae,te)=>{const ue=ae&&te?`${ae}/${te}`:void 0;M(ue),k(void 0),p(void 0),l(ue),N||(i(void 0),ae&&te&&S.find(Ne=>Ne.id===ae)&&(e(ae),a(te)));try{await yt({defaultModel:ue??"",defaultVariant:""});const Ie=await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:ue})});Ie.ok||console.warn("Failed to save default model to server:",Ie.status,Ie.statusText)}catch(Ie){console.warn("Failed to save default model:",Ie)}},[N,S,i,a,e,l,p]),z="__default__",re=o.useCallback(ae=>ae===z?t("settings.aiworker.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),$=o.useCallback(async ae=>{const te=ae===z?void 0:ae||void 0;k(te),p(te),N||r(te??null,te);try{await yt({defaultVariant:te??""})}catch(ue){console.warn("Failed to save default variant:",ue)}},[N,r,p]),U=o.useCallback(async ae=>{const te=ae||void 0;w(te),m(te),ae&&!h&&n(ae);try{await yt({defaultAgent:te??""})}catch(ue){console.warn("Failed to save default agent:",ue)}},[h,n,m]),K=o.useCallback(async ae=>{A(ae);try{await yt({smallModelUseDefault:ae})}catch(te){console.warn("Failed to save small model preference:",te)}},[]),O=o.useCallback(async(ae,te)=>{const ue=ae&&te?`${ae}/${te}`:void 0;E(ue);try{await yt({smallModelOverride:ue??""})}catch(Ie){console.warn("Failed to save small model override:",Ie)}},[]),Y=o.useCallback(async(ae,te)=>{const ue=ae&&te?`${ae}/${te}`:void 0;V(ue);try{await yt({walkthroughModelOverride:ue??""})}catch(Ie){console.warn("Failed to save walkthrough model override:",Ie)}},[]),X=o.useCallback((ae,te)=>g.get(`${ae}/${te}`)?.structured_output!==!1,[g]),ee=o.useMemo(()=>sr(I),[I]),ge=o.useMemo(()=>sr(j),[j]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const te=await mt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!te.ok)return;const ue=await te.json().catch(()=>null);!ae&&Array.isArray(ue?.authenticatedProviders)&&_(ue.authenticatedProviders.filter(Ie=>typeof Ie=="string"))}catch{}})(),()=>{ae=!0}},[]);const de=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const ue=S.find(Ie=>Ie.id===Q.providerId)?.models.find(Ie=>Ie.id===Q.modelId)?.variants;return ue?Object.keys(ue):[]},[Q.modelId,Q.providerId,S]),xe=de.length>0;return o.useEffect(()=>{!xe&&P&&(k(void 0),p(void 0),N||i(void 0),yt({defaultVariant:""}).catch(()=>{}))},[N,P,i,p,xe]),q?null:s.jsx(s.Fragment,{children:s.jsx(_e,{title:t("settings.aiworker.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.aiworker.defaults.summaryPrefix")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,xe?` (${P??t("settings.aiworker.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.aiworker.defaults.summaryOpenCodeDefault")}),f&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:f})]})]}),s.jsxs("div",{children:[s.jsx(Lt,{settingsItem:"sessions.default-model",label:t("settings.aiworker.defaults.field.defaultModel"),children:s.jsx(Ka,{providerId:Q.providerId,modelId:Q.modelId,onChange:ne,className:En})}),s.jsx(Lt,{settingsItem:"sessions.default-thinking",label:t("settings.aiworker.defaults.field.defaultThinking"),children:s.jsxs(It,{value:P??z,onValueChange:$,disabled:!xe,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.aiworker.defaults.field.thinkingPlaceholder"),children:re(P??z)})}),s.jsxs(At,{children:[s.jsx(ot,{value:z,children:t("settings.aiworker.defaults.option.default")}),de.map(ae=>s.jsx(ot,{value:ae,children:re(ae)},ae))]})]})}),s.jsx(Lt,{settingsItem:"sessions.default-agent",label:t("settings.aiworker.defaults.field.defaultAgent"),children:s.jsx(xl,{agentName:f||"",onChange:U,filter:ae=>td(ae.mode),className:En})})]}),s.jsx(Va,{className:hs,children:s.jsx(ft,{settingsItem:"sessions.deletion-dialog",checked:C,onChange:b,label:t("settings.aiworker.defaults.field.showDeletionDialog"),ariaLabel:t("settings.aiworker.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.aiworker.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.smallModel.description")})]}),s.jsx(ft,{settingsItem:"sessions.small-model",checked:F,onChange:ae=>{K(ae)},label:t("settings.aiworker.defaults.smallModel.useDefault"),ariaLabel:t("settings.aiworker.defaults.smallModel.useDefaultAria")}),F?null:s.jsx(Lt,{label:t("settings.aiworker.defaults.smallModel.overrideModel"),children:s.jsx(Ka,{providerId:ee.providerId,modelId:ee.modelId,onChange:O,allowedProviderIds:B,className:En})}),s.jsxs(Va,{className:hs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.aiworker.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.walkthroughModel.description")})]}),s.jsx(Lt,{settingsItem:"sessions.walkthrough-model",label:t("settings.aiworker.defaults.walkthroughModel.overrideModel"),children:s.jsx(Ka,{providerId:ge.providerId,modelId:ge.modelId,onChange:Y,allowedProviderIds:B,isModelAllowed:X,placeholder:t("settings.aiworker.defaults.walkthroughModel.usesSmallModel"),className:En})})]})]})]})})})},sl={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},ah={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},ih=()=>{const{t}=it(),e=o.useMemo(()=>as(),[]),a=o.useMemo(()=>cs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=le($=>$.nativeNotificationsEnabled),l=le($=>$.setNativeNotificationsEnabled),p=le($=>$.notificationMode),m=le($=>$.setNotificationMode),x=le($=>$.notifyOnSubtasks),d=le($=>$.setNotifyOnSubtasks),y=le($=>$.notifyOnCompletion),c=le($=>$.setNotifyOnCompletion),N=le($=>$.notifyOnError),h=le($=>$.setNotifyOnError),C=le($=>$.notifyOnQuestion),b=le($=>$.setNotifyOnQuestion),S=le($=>$.notificationTemplates),g=le($=>$.setNotificationTemplates),[T,M]=o.useState("default"),[P,k]=o.useState(!1),[f,w]=o.useState(!1),[F,A]=o.useState(!1);o.useEffect(()=>{if(!i){k(!1),w(!1);return}typeof Notification<"u"&&M(Notification.permission);const $=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k($),(async()=>{if(!$){w(!1);return}try{const K=await navigator.serviceWorker.getRegistration();if(!K){w(!1);return}const O=await K.pushManager.getSubscription();w(!!O)}catch{w(!1)}})()},[i]);const I=async $=>{if(e){l($);return}if(!i){l($);return}if($&&typeof Notification<"u"&&Notification.permission==="default")try{const U=await Notification.requestPermission();M(U),U==="granted"?l(!0):D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(U){console.error("Failed to request notification permission:",U),D.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!($&&T==="granted"))},E=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",B=($,U,K)=>{g(O=>({...O,[$]:{...O[$],[U]:K}}))},_=$=>{const U="=".repeat((4-$.length%4)%4),K=($+U).replace(/-/g,"+").replace(/_/g,"/"),O=atob(K),Y=new Uint8Array(O.length);for(let X=0;X<O.length;X+=1)Y[X]=O.charCodeAt(X);return Y},j=async($,U,K)=>{let O=null;const Y=new Promise((X,ee)=>{O=setTimeout(()=>{ee(new Error(K))},U)});try{return await Promise.race([$,Y])}finally{O&&clearTimeout(O)}},V=async $=>{if($.active)return;const U=$.installing||$.waiting;U&&U.state!=="activated"&&await j(new Promise(K=>{const O=()=>{U.state==="activated"&&(U.removeEventListener("statechange",O),K())};U.addEventListener("statechange",O),O()}),15e3,"Service worker activation timed out")},q=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const $=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let U=null;for(const K of $)try{const O=K.opts?navigator.serviceWorker.register("/sw.js",K.opts):navigator.serviceWorker.register("/sw.js");return await j(O,1e4,`Service worker registration timed out (${K.label})`)}catch(O){U=O}throw U instanceof Error?U:new Error("Service worker registration failed")},L=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const $=await navigator.serviceWorker.getRegistration();if($)return $;const U=await q();try{await U.update()}catch{}return await V(U),U},Q=$=>{const U=$,K=[`type=${typeof $}`,`toString=${String($)}`,`name=${String(U?.name??"")}`,`message=${String(U?.message??"")}`];let O="";try{O=JSON.stringify($)}catch{}return{summary:K.filter(Boolean).join(" | "),json:O,stack:typeof U?.stack=="string"?U.stack:""}},ne=async()=>{const $=an();if(!$?.notifications){D.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await $.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?D.success(t("settings.notifications.page.toast.testNotificationSent")):D.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(U){console.error("Test notification failed:",U),D.error(t("settings.notifications.page.toast.testNotificationFailed"))}},z=async()=>{if(!P){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const $=an();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(M(de),de!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const U=await $.push.getVapidPublicKey();if(!U?.publicKey){D.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const K=await L();await V(K);const O=await K.pushManager.getSubscription();if(!("pushManager"in K)||!K.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const X=(O??await j(K.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:_(U.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ee=X.keys;if(!X.endpoint||!ee?.p256dh||!ee.auth)throw new Error("Push subscription missing keys");if(!(await j($.push.subscribe({endpoint:X.endpoint,keys:{p256dh:ee.p256dh,auth:ee.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Ld()}),15e3,"Push subscribe request timed out"))?.ok){D.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}w(!0),D.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(U){console.error("[Push] Enable failed:",U);const K=Q(U);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:K.summary})}finally{A(!1)}},re=async()=>{if(!P){w(!1);return}const $=an();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!0);try{const K=await(await L()).pushManager.getSubscription();if(!K){w(!1);return}const O=K.endpoint;await K.unsubscribe(),await $.push.unsubscribe({endpoint:O}),w(!1),D.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{A(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:hs,children:[s.jsx(ft,{checked:r&&E,onChange:$=>{I($)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&E&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(ft,{checked:p==="always",onChange:$=>m($?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(H,{type:"button",variant:"outline",size:"sm",onClick:()=>{ne()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&E&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:hs,children:[s.jsx(ft,{checked:y,onChange:c,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(ft,{checked:x,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(ft,{checked:N,onChange:h,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(ft,{checked:C,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(_e,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(An,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map($=>s.jsxs("section",{className:"p-2",children:[s.jsx(Ys,{className:"capitalize",children:t(ah[$])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Je,{value:S[$].title,onChange:U=>B($,"title",U.target.value),className:"h-7",placeholder:t(sl[$].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(Je,{value:S[$].message,onChange:U=>B($,"message",U.target.value),className:"h-7",placeholder:t(sl[$].messageKey)})]})]})]},$))})})]}),i&&s.jsx(_e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(ft,{checked:P?f:!1,disabled:!P||F,onChange:$=>{$?z():re()},label:t("settings.notifications.page.push.enableLabel"),description:P?void 0:t("settings.notifications.page.push.unsupportedHint"),info:P?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:F?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Rs=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},rh=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],nl=t=>{const e=gt.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let p;e[2]!==n?(p=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=p):p=e[3];let m;return e[4]!==i||e[5]!==l||e[6]!==p?(m=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,p]}),e[4]=i,e[5]=l,e[6]=p,e[7]=m):m=e[7],m},oh=({selectedModelId:t,onSelect:e})=>{const{t:a}=it(),n=qe.useCallback(c=>a(c),[a]),[i,r]=qe.useState(new Map),[l,p]=qe.useState(null),m=qe.useCallback(async()=>{try{const c=await mt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const N=await c.json();Array.isArray(N?.models)&&r(new Map(N.models.map(h=>[h.id,h])))}catch{}},[]);qe.useEffect(()=>{m()},[m]);const x=Array.from(i.values()).some(c=>c.downloading);qe.useEffect(()=>{if(!x)return;const c=setInterval(()=>{m()},2e3);return()=>clearInterval(c)},[x,m]);const d=async c=>{p(c);try{await mt(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await m()}catch{}finally{p(null)}},y=async c=>{p(c);try{await mt(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await m()}catch{}finally{p(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:rh.map(c=>{const N=t===c.id,h=i.get(c.id)??null;return s.jsx("div",{className:ye("rounded-lg border border-[var(--interactive-border)] p-3",N&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(c.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(br,{checked:N,onChange:()=>e(c.id),ariaLabel:n(c.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:ye("typography-ui-label font-normal",N?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(nl,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(nl,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.size})]}),h?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:h?.installed?s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===c.id,onClick:()=>{y(c.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):h?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof h.downloadProgress=="number"?`${h.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===c.id,onClick:()=>{d(c.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})})})]})},c.id)})})},lh=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],hr="kokoro-en-v0_19",ch="kokoro-multi-lang-v1_1",dh=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],Ma=(t,e)=>`${t}:${e}`,uh=()=>{const[t,e]=qe.useState([]),[a,n]=qe.useState(null),i=qe.useCallback(async()=>{try{const p=await mt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const m=await p.json();Array.isArray(m?.ttsModels)&&e(m.ttsModels)}catch{}},[]);qe.useEffect(()=>{i()},[i]);const r=t.some(p=>p.downloading);qe.useEffect(()=>{if(!r)return;const p=setInterval(()=>{i()},2e3);return()=>clearInterval(p)},[r,i]);const l=qe.useCallback(async(p,m)=>{n(p);try{const x=m==="POST"?`/api/dictation/models/${p}/download`:`/api/dictation/models/${p}`;await mt(x,{method:m}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},ph=t=>{const e=lh.map(a=>({modelId:hr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===hr||!a.installed)){if(a.id===ch){for(const n of dh)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},mh=t=>{const e=gt.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=it();let l,p,m;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){m=Symbol.for("react.early_return_sentinel");e:{const d=a.filter(hh);if(d.length===0){m=null;break e}l="flex flex-col";let y;e[7]!==i||e[8]!==n||e[9]!==r?(y=c=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:c.description??c.id}),c.installed?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("settings.voice.page.stt.modelInstalled")}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{i(c.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})]}):c.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof c.downloadProgress=="number"?`${c.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(c.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})}),c.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:c.downloadError}):null]},c.id),e[7]=i,e[8]=n,e[9]=r,e[10]=y):y=e[10],p=d.map(y)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=p,e[6]=m}else l=e[4],p=e[5],m=e[6];if(m!==Symbol.for("react.early_return_sentinel"))return m;let x;return e[11]!==l||e[12]!==p?(x=s.jsx("div",{className:l,children:p}),e[11]=l,e[12]=p,e[13]=x):x=e[13],x},gh=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],fh=()=>{const{t}=it(),{isMobile:e}=wa(),a=Ze(G=>G.voiceProvider),n=Ze(G=>G.setVoiceProvider),i=Ze(G=>G.speechRate),r=Ze(G=>G.setSpeechRate),l=Ze(G=>G.speechPitch),p=Ze(G=>G.setSpeechPitch),m=Ze(G=>G.speechVolume),x=Ze(G=>G.setSpeechVolume),d=Ze(G=>G.sayVoice),y=Ze(G=>G.setSayVoice),c=Ze(G=>G.localTtsVoiceId),N=Ze(G=>G.localTtsModelId),h=Ze(G=>G.setLocalTtsModelId),C=uh(),b=qe.useMemo(()=>ph(C.models),[C.models]),S=Ze(G=>G.ttsFollowTextLanguage),g=Ze(G=>G.setTtsFollowTextLanguage),T=Ze(G=>G.setLocalTtsVoiceId),{speak:M,stop:P,isPlaying:k,error:f}=sd(),w=qe.useCallback(()=>{if(k){P();return}const G=b.find(Be=>Be.modelId===N&&Be.speakerId===c)?.label??String(c);M(t("settings.voice.page.preview.voiceLine",{voiceName:G}),{model:N,speakerId:c,speed:Ze.getState().speechRate})},[k,N,c,b,M,P,t]),F=Ze(G=>G.browserVoice),A=Ze(G=>G.setBrowserVoice),I=Ze(G=>G.openaiVoice),E=Ze(G=>G.setOpenaiVoice),B=Ze(G=>G.openaiApiKey),_=Ze(G=>G.setOpenaiApiKey),j=Ze(G=>G.openaiCompatibleUrl),V=Ze(G=>G.setOpenaiCompatibleUrl),q=Ze(G=>G.openaiCompatibleApiKey),L=Ze(G=>G.setOpenaiCompatibleApiKey),Q=Ze(G=>G.openaiCompatibleVoice),ne=Ze(G=>G.setOpenaiCompatibleVoice),z=Ze(G=>G.openaiCompatibleTtsModel),re=Ze(G=>G.setOpenaiCompatibleTtsModel),$=Ze(G=>G.showMessageTTSButtons),U=Ze(G=>G.ttsInputMode),K=Ze(G=>G.setTtsInputMode),O=Ze(G=>G.sttProvider),Y=Ze(G=>G.setSttProvider),X=Ze(G=>G.sttServerUrl),ee=Ze(G=>G.setSttServerUrl),ge=Ze(G=>G.sttApiKey),de=Ze(G=>G.setSttApiKey),xe=Ze(G=>G.sttModel),ae=Ze(G=>G.setSttModel),te=Ze(G=>G.sttLocalModel),ue=Ze(G=>G.setSttLocalModel),Ie=Ze(G=>G.sttLanguage),Ne=Ze(G=>G.setSttLanguage),Se=Ze(G=>G.setShowMessageTTSButtons),ve=Ze(G=>G.dictationEnabled),Oe=Ze(G=>G.setDictationEnabled),[Le,oe]=qe.useState(!1),[he,Me]=qe.useState([]),[$e,Ve]=qe.useState(!1),[We,se]=qe.useState(null),[ie,je]=qe.useState(!1),[be,Te]=qe.useState(!1),[Ue,Pe]=qe.useState(null),[we,Ge]=qe.useState(!1),[pe,Ce]=qe.useState(null),[Re,Ye]=qe.useState([]),[W,ke]=qe.useState(!1);qe.useEffect(()=>((async()=>{const Be=await Hi.waitForVoices();Ye(Be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ye(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ae=qe.useMemo(()=>Re.filter(G=>G.lang).sort((G,Be)=>{const st=G.lang.startsWith("en"),rt=Be.lang.startsWith("en");if(st&&!rt)return-1;if(!st&&rt)return 1;const ut=G.lang.localeCompare(Be.lang);return ut!==0?ut:G.name.localeCompare(Be.name)}),[Re]),He=qe.useCallback(()=>{if(W){Hi.cancelSpeech(),ke(!1);return}const G=Re.find(ut=>ut.name===F),Be=G?.name??t("settings.voice.page.preview.browserVoiceFallback"),st=t("settings.voice.page.preview.voiceLine",{voiceName:Be});ke(!0);const rt=new SpeechSynthesisUtterance(st);rt.rate=i,rt.pitch=l,rt.volume=m,G&&(rt.voice=G,rt.lang=G.lang),rt.onend=()=>ke(!1),rt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(rt)},[F,Re,i,l,m,W,t]);qe.useEffect(()=>()=>{W&&Hi.cancelSpeech()},[W]),qe.useEffect(()=>{if(!$||a!=="openai"&&a!=="openai-compatible"){je(B.trim().length>0);return}(async()=>{try{const rt=(await(await mt("/api/tts/status")).json()).available,ut=B.trim().length>0;je(rt||ut)}catch{je(B.trim().length>0)}})()},[B,$,a]),qe.useEffect(()=>{if(!$){oe(!1),Me([]);return}mt("/api/tts/say/status").then(G=>G.json()).then(G=>{if(oe(G.available),G.voices){const Be=G.voices.filter((st,rt,ut)=>ut.findIndex(St=>St.name===st.name)===rt).sort((st,rt)=>st.name.localeCompare(rt.name));Me(Be)}}).catch(()=>{oe(!1)})},[$]);const at=qe.useCallback(async()=>{if(We){Rs(We),se(null),Ve(!1);return}Ve(!0);let G=null;try{const Be=await mt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:d}),voice:d,rate:Math.round(100+(i-.5)*200)})});if(!Be.ok)throw new Error("Preview failed");const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),se(null),Ve(!1)},G.onerror=()=>{Rs(G),se(null),Ve(!1)},se(G),await G.play()}catch{Rs(G),se(null),Ve(!1)}},[d,i,We,t]);qe.useEffect(()=>()=>{Rs(We)},[We]);const nt=qe.useCallback(async()=>{if(Ue){Rs(Ue),Pe(null),Te(!1);return}Te(!0);let G=null;try{const Be=await mt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:I}),voice:I,speed:i,apiKey:B||void 0})});if(!Be.ok){const ut=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(ut.error||`HTTP ${Be.status}`)}const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),Pe(null),Te(!1)},G.onerror=()=>{Rs(G),Pe(null),Te(!1)},Pe(G),await G.play()}catch{Rs(G),Pe(null),Te(!1)}},[I,i,Ue,B,t]);qe.useEffect(()=>()=>{Rs(Ue)},[Ue]);const dt=qe.useCallback(async()=>{if(pe){Rs(pe),Ce(null),Ge(!1);return}if(!j.trim())return;Ge(!0);let G=null;try{const Be=await mt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:Q,model:z||void 0,speed:i,baseURL:j,apiKey:q||void 0})});if(!Be.ok){const ut=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(ut.error||`HTTP ${Be.status}`)}const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),Ce(null),Ge(!1)},G.onerror=()=>{Rs(G),Ce(null),Ge(!1)},Ce(G),await G.play()}catch{Rs(G),Ce(null),Ge(!1)}},[j,Q,z,q,i,pe,t]);qe.useEffect(()=>()=>{Rs(pe)},[pe]);const xt="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(ft,{checked:$,onChange:Se,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),$&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(Qs,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...Le?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:ye(Et,!ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye(Vn,!ie&&"text-[var(--status-error)]/80"),children:t(ie&&!B?"settings.voice.page.field.apiKeyHintUsingConfig":ie?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ye("relative",Fs),children:[s.jsx("input",{type:"password",value:B,onChange:G=>_(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),B&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Et,!j.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ye("relative",Fs),children:[s.jsx("input",{type:"text",value:j,onChange:G=>V(G.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),j&&s.jsx("button",{type:"button",onClick:()=>V(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Vn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Fs),children:[s.jsx("input",{type:"password",value:q,onChange:G=>L(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),q&&s.jsx("button",{type:"button",onClick:()=>L(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Fs),children:s.jsx("input",{type:"text",value:z,onChange:G=>re(G.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ye("flex items-center gap-2",Fs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:Q,onChange:G=>ne(G.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(H,{size:"xs",variant:"ghost",onClick:dt,title:t("settings.voice.page.actions.preview"),disabled:!j.trim(),children:we?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(mh,{...C}),(a==="local"||a==="say")&&s.jsx(ft,{checked:S,onChange:g,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Lt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:Ma(N,c),onValueChange:G=>{const Be=b.find(st=>Ma(st.modelId,st.speakerId)===G);Be&&(h(Be.modelId),T(Be.speakerId))},children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:G=>b.find(Be=>Ma(Be.modelId,Be.speakerId)===G)?.label??G})}),s.jsx(At,{children:b.map(G=>s.jsx(ot,{value:Ma(G.modelId,G.speakerId),children:G.label},Ma(G.modelId,G.speakerId)))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:w,title:t("settings.voice.page.actions.preview"),children:k?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})}),f?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:f}):null]}),a==="openai"&&ie&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:I,onValueChange:E,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:gh.map(G=>s.jsx(ot,{value:G.value,children:G.label},G.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:nt,title:t("settings.voice.page.actions.preview"),children:be?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Vn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Le&&he.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:d,onValueChange:y,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:he.map(G=>s.jsx(ot,{value:G.name,children:G.name},G.name))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:at,title:t("settings.voice.page.actions.preview"),children:$e?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ae.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:F||"$auto",onValueChange:G=>A(G==="$auto"?"":G),children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ae.map(G=>s.jsxs(ot,{value:G.name,children:[G.name," (",G.lang,")"]},G.name))]})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:He,title:t("settings.voice.page.actions.preview"),children:W?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Lt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:G=>r(Number(G.target.value)),className:xt}),s.jsx(xs,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:ye(Cs,"tabular-nums")})]}),s.jsxs(Lt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:G=>p(Number(G.target.value)),className:xt}),s.jsx(xs,{value:l,onValueChange:p,min:.5,max:2,step:.1,className:ye(Cs,"tabular-nums")})]}),s.jsxs(Lt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:m,onChange:G=>x(Number(G.target.value)),className:xt}),e?s.jsx(xs,{value:Math.round(m*100),onValueChange:G=>x(G/100),min:0,max:100,step:10,className:ye(Cs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(m*100),"%"]})]}),s.jsx(Ps,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Qs,{value:U,onChange:K,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(_e,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(ft,{checked:ve,onChange:Oe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ve&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(Qs,{value:O,onChange:Y,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),O==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx(oh,{selectedModelId:te,onSelect:ue})]}),O==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Et,!X.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ye("relative",Fs),children:[s.jsx("input",{type:"text",value:X,onChange:G=>ee(G.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),X&&s.jsx("button",{type:"button",onClick:()=>ee(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Vn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Fs),children:[s.jsx("input",{type:"password",value:ge,onChange:G=>de(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),ge&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Fs),children:s.jsx("input",{type:"text",value:xe,onChange:G=>ae(G.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Ie,onChange:G=>Ne(G.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})};function hh(t){return t.id===hr||t.installed||t.downloading}const hi=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],xi=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],xh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",vh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",nr=[{value:"quick",labelKey:"settings.aiworker.tunnel.option.mode.quick.label",tooltipKey:"settings.aiworker.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.aiworker.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.aiworker.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedLocal.tooltip"}],yh=[".yml",".yaml",".json"],bh="settings.aiworker.tunnel.error.invalidConfigExtension",Ra=t=>{const e=t.trim().toLowerCase();return yh.some(a=>e.endsWith(a))},wh=t=>t==="ngrok"?"ngrok":"cloudflared",sc=()=>{if(typeof window<"u"&&typeof window.__AIWORKER_PLATFORM__=="string"){const e=window.__AIWORKER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},jh=(t,e=sc())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",ar=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():wh(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():sc(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():jh(a,i);return{provider:a,dependency:n,installCommand:r}},nc=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,al=t=>{const e=gt.c(11),{provider:a}=t;let n;e[0]!==a?(n=nc(a),e[0]=a,e[1]=n):n=e[1];const i=n,p=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let m;e[2]!==p?(m=ye("size-4 shrink-0",p),e[2]=p,e[3]=m):m=e[3];let x;e[4]!==m?(x=s.jsx(R,{name:"cloud",className:m}),e[4]=m,e[5]=x):x=e[5];let d;e[6]!==i?(d=s.jsx("span",{children:i}),e[6]=i,e[7]=d):d=e[7];let y;return e[8]!==x||e[9]!==d?(y=s.jsxs("span",{className:"flex items-center gap-2",children:[x,d]}),e[8]=x,e[9]=d,e[10]=y):y=e[10],y},Pn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",xr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,il=(t,e,a)=>{const n=xr(t,e,a);return t.find(i=>i.value===n)?.label||n},rl=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},kh=(t,e)=>Cl(t,e,{hour:"2-digit",precision:"second"}),ki=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},Nh=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",p=typeof r.name=="string"?r.name.trim():"",m=ki(typeof r.hostname=="string"?r.hostname:"");!l||!p||!m||e.has(l)||a.has(m)||(e.add(l),a.add(m),n.push({id:l,name:p,hostname:m}))}return n},Sh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Ch=()=>{const{t}=it(),e=le(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[p,m]=o.useState(null),[x,d]=o.useState(null),[y,c]=o.useState(null),[N,h]=o.useState(null),[C,b]=o.useState(!1),[S,g]=o.useState(!1),[T,M]=o.useState(!1),[P,k]=o.useState("cloudflare"),[f,w]=o.useState(()=>ar("cloudflare")),[F,A]=o.useState([]),[I,E]=o.useState("quick"),[B,_]=o.useState(null),[j,V]=o.useState([]),[q,L]=o.useState({}),[Q,ne]=o.useState(""),[z,re]=o.useState({}),[$,U]=o.useState(new Set),[K,O]=o.useState(!1),[Y,X]=o.useState(""),[ee,ge]=o.useState(""),[de,xe]=o.useState(""),[ae,te]=o.useState(1800*1e3),[ue,Ie]=o.useState(480*60*1e3),[Ne,Se]=o.useState(""),[ve,Oe]=o.useState([]),[Le,oe]=o.useState(()=>Date.now()),[he,Me]=o.useState(null),$e=t(bh),Ve=o.useRef(null),We=o.useMemo(()=>B?!Ra(B):!1,[B]),se=o.useMemo(()=>j.find(J=>J.id===Q)||j[0]||null,[j,Q]),ie=o.useMemo(()=>ve.map(J=>{const fe=J.expiresAt<=Le,Fe=J.status==="active"&&!fe,De=Fe?rl(J.expiresAt-Le):J.inactiveReason==="expired"||fe?"expired":"inactive",lt=De==="expired"?t("settings.aiworker.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.aiworker.tunnel.state.revoked"):t("settings.aiworker.tunnel.state.inactive"),ct=Pn(J.mode);return{...J,isActive:Fe,mode:ct,remainingTextForSession:De,inactiveLabel:lt}}),[Le,ve,t]),je=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Le:!1,[Le,r?.bootstrapExpiresAt,r?.connectUrl]),be=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:p===I,[p,n,r,I]),Te=o.useMemo(()=>!r||n!=="active"||!p?!1:p!==I,[p,n,r,I]),Ue=o.useMemo(()=>{if(typeof he=="number"&&Number.isFinite(he)&&he>0)return he;if(typeof window>"u")return null;const fe=Ba()||window.location.href;let Fe=0;try{Fe=Number(new URL(fe).port)}catch{Fe=Number(window.location.port)}return Number.isFinite(Fe)&&Fe>0?Fe:null},[he]),Pe=o.useMemo(()=>F.find(J=>J.provider===P)??null,[F,P]),we=o.useMemo(()=>{const J=new Set(Pe?.modes?.map(fe=>fe.key).filter(fe=>fe==="quick"||fe==="managed-remote"||fe==="managed-local"));return J.size===0?nr:nr.filter(fe=>J.has(fe.value))},[Pe]),Ge=o.useMemo(()=>we.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[we]),pe=o.useMemo(()=>f.provider===P?f:ar(P),[f,P]),Ce=o.useCallback(async J=>{await Dn(J)},[]),Re=o.useCallback((J,fe)=>(w(ar(fe,J)),J.available===!0),[]),Ye=o.useCallback(async(J,fe)=>{try{const Fe=await mt("/api/openchamber/tunnel/check",{query:{provider:J},...fe?{signal:fe}:{}});if(!Fe.ok)return null;const De=await Fe.json();if(fe?.aborted)return null;const lt=Re(De,J);return i(ct=>ct==="checking"||ct==="starting"||ct==="active"||ct==="stopping"?ct:lt?"idle":"not-available"),lt}catch{return null}},[Re]),W=o.useCallback(async J=>{try{const[fe,Fe,De,lt]=await Promise.all([mt("/api/openchamber/tunnel/check",{signal:J}),mt("/api/openchamber/tunnel/status",{signal:J}),mt("/api/config/settings",{signal:J,headers:{Accept:"application/json"}}),mt("/api/openchamber/tunnel/providers",{signal:J})]),ct=await fe.json(),Qe=await Fe.json(),kt=De.ok?await De.json():{},vs=lt.ok?await lt.json():{},Xt=Qe.ttlConfig?.bootstrapTtlMs??(kt?.tunnelBootstrapTtlMs===null?null:typeof kt?.tunnelBootstrapTtlMs=="number"?kt.tunnelBootstrapTtlMs:1800*1e3),Ls=typeof Qe.ttlConfig?.sessionTtlMs=="number"?Qe.ttlConfig.sessionTtlMs:typeof kt?.tunnelSessionTtlMs=="number"?kt.tunnelSessionTtlMs:480*60*1e3,Gt=Pn(Qe.mode??kt?.tunnelMode),is=typeof kt?.tunnelProvider=="string"&&kt.tunnelProvider.trim().length>0?kt.tunnelProvider.trim().toLowerCase():"cloudflare",Ht=typeof kt?.managedLocalTunnelConfigPath=="string"&&kt.managedLocalTunnelConfigPath.trim()||null,ys=Re(ct,is),ms=Nh(Qe?.managedRemoteTunnelPresets),gs=typeof Qe.managedRemoteTunnelHostname=="string"?Qe.managedRemoteTunnelHostname:"",ds=ms.length>0?ms:gs?[{id:`legacy-${ki(gs)}`,name:gs,hostname:ki(gs)}]:[],Ts=ds[0]?.id||"";if(te(Xt),Ie(Ls),k(is),A(Array.isArray(vs?.providers)?vs.providers:[]),E(Gt),_(Ht),V(ds),ne(Ts),Oe(Array.isArray(Qe.activeSessions)?Qe.activeSessions:[]),m(Qe.activeTunnelMode?Pn(Qe.activeTunnelMode):Qe.active&&Qe.mode?Pn(Qe.mode):null),U(new Set(Array.isArray(Qe.managedRemoteTunnelTokenPresetIds)?Qe.managedRemoteTunnelTokenPresetIds:[])),Me(typeof Qe.localPort=="number"?Qe.localPort:null),Qe.active&&Qe.url){l({url:Qe.url,connectUrl:null,bootstrapExpiresAt:typeof Qe.bootstrapExpiresAt=="number"?Qe.bootstrapExpiresAt:null}),i("active");return}i(ys?"idle":"not-available")}catch{J.aborted||(i("error"),c(t("settings.aiworker.tunnel.toast.checkAvailabilityFailed")))}},[Re,t]);o.useEffect(()=>{const J=new AbortController;return W(J.signal),()=>J.abort()},[W]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let J=!1;return Ol.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(fe=>{J||d(fe)}).catch(()=>{J||d(null)}),()=>{J=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Se(t("settings.aiworker.tunnel.state.noExpiry"));return}let J=null,fe=Date.now();const Fe=()=>{const ct=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;ct<=0?Se(t("settings.aiworker.tunnel.state.expired")):Se(rl(ct))},De=()=>{const ct=Date.now();ct-fe>=1e3&&(Fe(),fe=ct),J=requestAnimationFrame(De)};Fe(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(De));const lt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(De):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),J!==null&&cancelAnimationFrame(J)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,fe=Date.now();const Fe=()=>{const lt=Date.now();lt-fe>=1e3&&(oe(lt),fe=lt),J=requestAnimationFrame(Fe)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Fe));const De=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Fe):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",De),()=>{document.removeEventListener("visibilitychange",De),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const fe=async()=>{try{const De=await mt("/api/openchamber/tunnel/status");if(!De.ok||J)return;const lt=await De.json();if(J)return;Oe(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),U(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),Me(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Fe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||fe()},5e3);return()=>{J=!0,window.clearInterval(Fe)}},[n]);const ke=o.useCallback(async J=>{M(!0);try{await yt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&E(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&k(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&_(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&V(J.managedRemoteTunnelPresets)}catch{D.error(t("settings.aiworker.tunnel.toast.saveSettingsFailed"))}finally{M(!1)}},[t]),Ae=o.useCallback(async(J,fe)=>{g(!0);try{await yt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:fe})}catch{D.error(t("settings.aiworker.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),He=o.useCallback(async J=>{const fe=J.token.trim();if(fe)try{const Fe={...z,[J.presetId]:fe};await yt({managedRemoteTunnelPresetTokens:Fe}),U(De=>{const lt=new Set(De);return lt.add(J.presetId),lt})}catch{D.error(t("settings.aiworker.tunnel.toast.saveTokenFailed"))}},[z,t]),at=o.useCallback(async J=>{h(null),c(null);const fe=F.find(De=>De.provider===J),Fe=fe?.modes?.some(De=>De.key===I)?I:Pn(fe?.modes?.[0]?.key);await ke({tunnelProvider:J,tunnelMode:Fe}),Ye(J)},[F,Ye,ke,I]),nt=o.useCallback(async()=>{const J=await El({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const fe=J.path.trim();if(!Ra(fe)){D.error($e);return}_(fe),await ke({managedLocalTunnelConfigPath:fe});return}Ve.current?.click()},[$e,ke]),dt=o.useCallback(J=>{const fe=J.trim();_(fe.length>0?fe:null)},[]),xt=o.useCallback(async()=>{if(B&&!Ra(B)){D.error($e);return}await ke({managedLocalTunnelConfigPath:B})},[$e,B,ke]),G=o.useCallback(async()=>{_(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),Be=o.useCallback(async J=>{const fe=J.target.files?.[0];if(!fe)return;const Fe=fe.name.trim();if(Fe.length!==0){if(!Ra(Fe)){D.error($e);return}_(Fe),await ke({managedLocalTunnelConfigPath:Fe}),J.target.value=""}},[$e,ke]),st=o.useCallback(async()=>{if(c(null),h(null),I==="managed-local"&&B&&!Ra(B)){c($e),D.error($e);return}i("starting");try{let J="",fe="";if(I==="managed-remote"){if(!se){i("idle"),h(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=se.hostname,fe=(z[se.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:j})}const Fe=await mt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:P,mode:I,...I==="managed-remote"&&se?{managedRemoteTunnelPresetId:se.id,managedRemoteTunnelPresetName:se.name}:{},...I==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...I==="managed-remote"&&fe?{managedRemoteTunnelToken:fe}:{},...I==="managed-local"&&B?{configPath:B}:{}})}),De=await Fe.json();if(!Fe.ok||!De.ok){if(I==="managed-remote"&&typeof De.error=="string"&&De.error.includes("Managed remote tunnel token is required")){i("idle"),h(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),D.error(t("settings.aiworker.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),c(De.error||t("settings.aiworker.tunnel.toast.startFailed")),D.error(De.error||t("settings.aiworker.tunnel.toast.startFailed"));return}const lt=typeof De.url=="string"?De.url:"";if(!lt){i("error"),c(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:lt,connectUrl:typeof De.connectUrl=="string"?De.connectUrl:null,bootstrapExpiresAt:typeof De.bootstrapExpiresAt=="number"?De.bootstrapExpiresAt:null}),m(De.activeTunnelMode?Pn(De.activeTunnelMode):De.mode?Pn(De.mode):I),Oe(Array.isArray(De.activeSessions)?De.activeSessions:[]),Array.isArray(De.managedRemoteTunnelTokenPresetIds)&&U(new Set(De.managedRemoteTunnelTokenPresetIds)),typeof De.localPort=="number"&&Me(De.localPort),typeof De.mode=="string"&&E(Pn(De.mode)),i("active"),De.replacedTunnel){const ct=typeof De.revokedBootstrapCount=="number"?De.revokedBootstrapCount:0,Qe=typeof De.invalidatedSessionCount=="number"?De.invalidatedSessionCount:0;ct===1&&Qe===1?D.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleSingle")):ct===1?D.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Qe})):Qe===1?D.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ct})):D.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ct,invalidatedSessionCount:Qe}))}else D.success(t("settings.aiworker.tunnel.toast.linkReady"))}catch{i("error"),c(t("settings.aiworker.tunnel.toast.startFailed")),D.error(t("settings.aiworker.tunnel.toast.startFailed"))}},[$e,j,ke,se,z,t,P,I,B]),rt=o.useCallback(async()=>{i("stopping");try{await mt("/api/openchamber/tunnel/stop",{method:"POST"});const J=await mt("/api/openchamber/tunnel/status");if(J.ok){const fe=await J.json();Oe(Array.isArray(fe.activeSessions)?fe.activeSessions:[]),U(new Set(Array.isArray(fe.managedRemoteTunnelTokenPresetIds)?fe.managedRemoteTunnelTokenPresetIds:[])),Me(typeof fe.localPort=="number"?fe.localPort:null)}l(null),m(null),d(null),i("idle"),D.success(t("settings.aiworker.tunnel.toast.stopped"))}catch{i("error"),c(t("settings.aiworker.tunnel.toast.stopFailed")),D.error(t("settings.aiworker.tunnel.toast.stopFailed"))}},[t]),ut=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),b(!0),D.success(t("settings.aiworker.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{D.error(t("settings.aiworker.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),St=o.useCallback(async J=>{const fe=hi.find(Fe=>Fe.value===J);fe&&(te(fe.ms),await Ae(fe.ms,ue))},[Ae,ue]),et=o.useCallback(async J=>{const fe=xi.find(Fe=>Fe.value===J);!fe||fe.ms===null||(Ie(fe.ms),await Ae(ae,fe.ms))},[ae,Ae]),Xe=o.useCallback(async J=>{h(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await ke({tunnelMode:J,managedRemoteTunnelPresets:j})},[j,ke,n]),ht=o.useCallback(async(J,fe)=>{try{await yt({managedRemoteTunnelPresets:fe})}catch{D.error(t("settings.aiworker.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),ze=o.useCallback(J=>{const fe=j.find(Fe=>Fe.id===J);fe&&(ne(fe.id),h(null),ht(fe,j))},[j,ht]),jt=o.useCallback(async()=>{const J=Y.trim(),fe=ki(ee),Fe=de.trim();if(!J){D.error(t("settings.aiworker.tunnel.toast.tunnelNameRequired"));return}if(!fe){D.error(t("settings.aiworker.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Fe){D.error(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequired"));return}if(j.some(ct=>ct.hostname===fe)){D.error(t("settings.aiworker.tunnel.toast.hostnameAlreadyExists"));return}const De={id:Sh(),name:J,hostname:fe},lt=[...j,De];V(lt),ne(De.id),L(ct=>({...ct,[De.id]:!0})),re(ct=>({...ct,[De.id]:Fe})),h(null),O(!1),X(""),ge(""),xe(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...z,[De.id]:Fe}}),await He({presetId:De.id,presetName:De.name,hostname:De.hostname,token:Fe}),D.success(t("settings.aiworker.tunnel.toast.managedRemoteSaved"))},[j,ee,Y,de,He,ke,z,t]),Ee=o.useCallback(async J=>{const fe=j.find(Qe=>Qe.id===J);if(!fe)return;const Fe=j.filter(Qe=>Qe.id!==fe.id),De=Fe[0]?.id||"",lt=Q===fe.id?De:Q,ct=Object.fromEntries(Object.entries(z).filter(([Qe,kt])=>Qe!==fe.id&&kt.trim().length>0));V(Fe),ne(lt),L(Qe=>{const kt={...Qe};return delete kt[fe.id],kt}),re(Qe=>{const kt={...Qe};return delete kt[fe.id],kt}),U(Qe=>{const kt=new Set(Qe);return kt.delete(fe.id),kt}),h(null),await ke({managedRemoteTunnelPresets:Fe,managedRemoteTunnelPresetTokens:ct}),D.success(t("settings.aiworker.tunnel.toast.managedRemoteRemoved"))},[j,ke,Q,z,t]),wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.aiworker.tunnel.state.loading")})}):s.jsx(_e,{title:t("settings.aiworker.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.aiworker.tunnel.description")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[ie.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(R,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Vr,children:t("settings.aiworker.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ie.map(J=>{const fe=J.mode==="quick",Fe=J.mode==="managed-remote",De=fe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Fe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",lt=J.isActive?fe?"text-[var(--status-warning)]":Fe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ct=t(fe?"settings.aiworker.tunnel.badge.quick":Fe?"settings.aiworker.tunnel.badge.remote":"settings.aiworker.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(R,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",lt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",De),children:ct}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.session.redeemedAt",{time:kh(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.aiworker.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.aiworker.tunnel.state.inactive")?t("settings.aiworker.tunnel.state.inactive"):t("settings.aiworker.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(R,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:Vr,children:t("settings.aiworker.tunnel.notAvailable.dependencyNotFound",{dependency:pe.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:pe.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.provider")}),s.jsxs(It,{value:P,onValueChange:J=>{at(J)},disabled:T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[16rem]",children:s.jsx(Rt,{placeholder:t("settings.aiworker.tunnel.field.providerPlaceholder"),children:nc(P)})}),s.jsxs(At,{children:[F.length>0?F.map(J=>s.jsx(ot,{value:J.provider,children:s.jsx(al,{provider:J.provider})},J.provider)):s.jsx(ot,{value:"cloudflare",children:s.jsx(al,{provider:"cloudflare"})}),s.jsx(ot,{value:"__more-soon",disabled:!0,children:t("settings.aiworker.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:we.map(J=>s.jsxs(wr,{children:[s.jsx(jr,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":I===J.value,className:"!font-normal",onClick:()=>{Xe(J.value)},disabled:T||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(bl,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Et,"shrink-0"),children:t("settings.aiworker.tunnel.field.connectLinkTtl")}),s.jsxs(It,{value:xr(hi,ae,"1800000"),onValueChange:J=>{St(J)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:il(hi,ae,"1800000")})}),s.jsx(At,{children:hi.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Et,"shrink-0"),children:t("settings.aiworker.tunnel.field.tunnelSessionTtl")}),s.jsxs(It,{value:xr(xi,ue,"28800000"),onValueChange:J=>{et(J)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:il(xi,ue,"28800000")})}),s.jsx(At,{children:xi.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.value))})]})]})]}),I==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(R,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.option.mode.quick.tooltip")}),Ge&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.quickModeReliability")})]})]})}),I==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ue=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Ue]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Ys,{children:t("settings.aiworker.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>O(J=>!J),disabled:n==="starting"||n==="stopping"||T,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),j.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:j.map((J,fe)=>{const Fe=z[J.id]||"",De=$.has(J.id),lt=q[J.id]??!1;return s.jsx("div",{className:ye(fe<j.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Mn,{open:lt,onOpenChange:ct=>{L(Qe=>({...Qe,[J.id]:ct})),ct&&ze(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Rn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||T,children:[lt?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:J.name})]}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.aiworker.tunnel.actions.removePresetAria",{name:J.name}),onClick:()=>{Ee(J.id)},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Ln,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:J.hostname})]}),s.jsx(Je,{type:"password",value:Fe,onChange:ct=>{const Qe=ct.target.value;h(null),re(kt=>({...kt,[J.id]:Qe}))},onBlur:ct=>{const Qe=ct.currentTarget.value.trim();Qe&&He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Qe})},placeholder:t(De?"settings.aiworker.tunnel.field.savedTokenAvailablePlaceholder":"settings.aiworker.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Fe.trim().length===0,onClick:()=>{He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Fe})},children:t("settings.aiworker.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.empty.noManagedRemoteTunnels")}),K&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Je,{value:Y,onChange:J=>X(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{value:ee,onChange:J=>ge(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{type:"password",value:de,onChange:J=>xe(J.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),typeof Ue=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ue]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{jt()},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{O(!1),X(""),ge(""),xe("")},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.aiworker.tunnel.tooltip.tokensSavedPath")})]}),!se&&N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})]}),I==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{Be(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:B||"",onChange:J=>{dt(J.target.value)},onBlur:()=>{xt()},placeholder:t("settings.aiworker.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||T}),s.jsx(H,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.browseConfigFileAria"),onClick:()=>{nt()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"folder",className:"size-3.5"})}),B&&s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.clearConfigFileAria"),onClick:()=>{G()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(B?"settings.aiworker.tunnel.note.customConfigUsed":"settings.aiworker.tunnel.note.defaultConfigUsed")}),We&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:$e})]})}),!be&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(R,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ce(xh)},children:[t("settings.aiworker.tunnel.actions.openManagedRemoteDocs"),s.jsx(R,{name:"external-link",className:"size-3.5"})]})]}),I==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ce(vh)},children:[t("settings.aiworker.tunnel.actions.openManagedLocalDocs"),s.jsx(R,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.startModeAndGenerateLink",{mode:a(nr.find(J=>J.value===I)?.labelKey??"settings.aiworker.tunnel.option.mode.quick.label")})})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(It,{value:Q||(j[0]?.id??""),onValueChange:J=>{ze(J)},disabled:T||n==="starting"||n==="stopping"||j.length<=1,children:[s.jsx(Pt,{size:Ft,children:s.jsx(Rt,{placeholder:t("settings.aiworker.tunnel.field.selectSavedTunnelPlaceholder"),children:se?.name})}),s.jsx(At,{fitContent:!0,children:j.map(J=>s.jsx(ot,{value:J.id,children:J.name},J.id))})]})]}),Te&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(R,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(H,{size:"sm",variant:"outline",onClick:st,disabled:n==="starting"||T||I==="managed-remote"&&!se||I==="managed-local"&&We,className:ye(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.startingTunnel")]}):t("settings.aiworker.tunnel.actions.startTunnel")})]})]}),be&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.aiworker.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),je&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(H,{size:"sm",variant:"ghost",onClick:ut,className:"shrink-0 gap-1.5",children:[C?s.jsx(R,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(R,{name:"file-copy",className:"size-3.5"}),t(C?"settings.aiworker.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.expires"),": ",r.bootstrapExpiresAt?Ne:t("settings.aiworker.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[x?s.jsx("img",{src:x,alt:t("settings.aiworker.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{size:"sm",variant:"outline",onClick:st,disabled:n==="stopping"||T||I==="managed-local"&&We,className:wt,children:[s.jsx(R,{name:"restart",className:"size-3.5"}),t("settings.aiworker.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:rt,disabled:n==="stopping"||T,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.stopping")]}):t("settings.aiworker.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&y&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y}),s.jsx(H,{size:"sm",variant:"ghost",onClick:st,children:t("settings.aiworker.tunnel.actions.retry")})]})]})})},ac=()=>{const{t}=it(),[e,a]=qe.useState(""),[n,i]=qe.useState(!0),[r,l]=qe.useState(!1),p=le(c=>c.showOpenCodeUpdateNotifications),m=le(c=>c.setShowOpenCodeUpdateNotifications);qe.useEffect(()=>{let c=!1;return(async()=>{try{const N=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const h=await N.json().catch(()=>null);if(c||!h)return;const C=typeof h.opencodeBinary=="string"?h.opencodeBinary.trim():"";a(C)}catch{}finally{c||i(!1)}})(),()=>{c=!0}},[]);const x=qe.useCallback(async()=>{if(!(typeof window>"u")&&as())try{const c=await El();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),d=qe.useCallback(async()=>{l(!0);try{const c=e.trim(),N=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await yt({opencodeBinary:N}),Gn("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),y=qe.useCallback(c=>{m(c),yt({showOpenCodeUpdateNotifications:c})},[m]);return s.jsx(_e,{title:t("settings.aiworker.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Lt,{settingsItem:"sessions.opencode-binary",label:t("settings.aiworker.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.aiworker.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.aiworker.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(Je,{value:e,onChange:c=>a(c.target.value),placeholder:t("settings.aiworker.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:x,disabled:n||r||!as(),className:fs,"aria-label":t("settings.aiworker.opencodeCli.actions.browseAria"),title:t("settings.aiworker.opencodeCli.actions.browse"),children:s.jsx(R,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Va,{className:hs,children:[!Dl()&&s.jsx(ft,{settingsItem:"sessions.opencode-update-notifications",checked:p,onChange:y,label:t("settings.aiworker.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.aiworker.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:d,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},ic=()=>{const t=gt.c(44),{t:e}=it(),a=le(Ih),n=le(Ph),i=le(Ah),r=le(Th),l=le(Eh),p=le(Dh),m=le(Mh);let x;t[0]!==n?(x=I=>{n(I),yt({agentControlToolEnabled:I}),Gn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=x):x=t[1];const d=x;let y;t[2]!==r?(y=I=>{r(I),yt({agentWebToolEnabled:I}),Gn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=y):y=t[3];const c=y;let N;t[4]!==m?(N=I=>{m(I),yt({agentMemoryToolEnabled:I}).finally(()=>{I&&nd.getState().refresh()}),Gn("cli",{id:"agent-memory-tool"})},t[4]=m,t[5]=N):N=t[5];const h=N;let C;t[6]!==e?(C=e("settings.aiworker.tools.title"),t[6]=e,t[7]=C):C=t[7];let b;t[8]!==e?(b=e("settings.aiworker.tools.field.agentControlTool"),t[8]=e,t[9]=b):b=t[9];let S;t[10]!==e?(S=e("settings.aiworker.tools.field.agentControlToolAria"),t[10]=e,t[11]=S):S=t[11];let g;t[12]!==e?(g=e("settings.aiworker.tools.field.agentControlToolInfo"),t[12]=e,t[13]=g):g=t[13];let T;t[14]!==a||t[15]!==d||t[16]!==b||t[17]!==S||t[18]!==g?(T=s.jsx(ft,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:b,ariaLabel:S,info:g}),t[14]=a,t[15]=d,t[16]=b,t[17]=S,t[18]=g,t[19]=T):T=t[19];let M;t[20]!==e?(M=e("settings.aiworker.tools.field.agentWebTool"),t[20]=e,t[21]=M):M=t[21];let P;t[22]!==e?(P=e("settings.aiworker.tools.field.agentWebToolAria"),t[22]=e,t[23]=P):P=t[23];let k;t[24]!==e?(k=e("settings.aiworker.tools.field.agentWebToolInfo"),t[24]=e,t[25]=k):k=t[25];let f;t[26]!==i||t[27]!==c||t[28]!==k||t[29]!==M||t[30]!==P?(f=s.jsx(ft,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:c,label:M,ariaLabel:P,info:k}),t[26]=i,t[27]=c,t[28]=k,t[29]=M,t[30]=P,t[31]=f):f=t[31];let w;t[32]!==p||t[33]!==l||t[34]!==h||t[35]!==e?(w=p?s.jsx(ft,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:h,label:e("settings.aiworker.tools.field.agentMemoryTool"),ariaLabel:e("settings.aiworker.tools.field.agentMemoryToolAria"),info:e("settings.aiworker.tools.field.agentMemoryToolInfo")}):null,t[32]=p,t[33]=l,t[34]=h,t[35]=e,t[36]=w):w=t[36];let F;t[37]!==f||t[38]!==w||t[39]!==T?(F=s.jsxs("div",{className:hs,children:[T,f,w]}),t[37]=f,t[38]=w,t[39]=T,t[40]=F):F=t[40];let A;return t[41]!==F||t[42]!==C?(A=s.jsx(_e,{title:C,children:F}),t[41]=F,t[42]=C,t[43]=A):A=t[43],A};function Ih(t){return t.agentControlToolEnabled}function Ph(t){return t.setAgentControlToolEnabled}function Ah(t){return t.agentWebToolEnabled}function Th(t){return t.setAgentWebToolEnabled}function Eh(t){return t.agentMemoryToolEnabled}function Dh(t){return t.agentMemoryFeatureAvailable}function Mh(t){return t.setAgentMemoryToolEnabled}const rc=()=>{const{t}=it(),e=as()&&Ha(),a=e&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[n,i]=qe.useState(!1),[r,l]=qe.useState(!1),[p,m]=qe.useState(""),[x,d]=qe.useState(""),[y,c]=qe.useState(!1),[N,h]=qe.useState(!1),[C,b]=qe.useState(null),[S,g]=qe.useState(!0),[T,M]=qe.useState(!1),[P,k]=qe.useState(!1),[f,w]=qe.useState(!1),[F,A]=qe.useState(!1),[I,E]=qe.useState(!1),[B,_]=qe.useState(!1),[j,V]=qe.useState(!1),[q,L]=qe.useState(!0),[Q,ne]=qe.useState(!0),[z,re]=qe.useState(!1),[$,U]=qe.useState(!1),[K,O]=qe.useState(!1),[Y,X]=qe.useState(null),[ee,ge]=qe.useState(null);qe.useEffect(()=>{if(!e){g(!1);return}let oe=!1;return(async()=>{try{const he=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!he.ok)throw new Error(t("settings.aiworker.desktopNetwork.error.loadFailed"));const Me=await he.json().catch(()=>null);if(oe)return;const $e=Me?.desktopLanAccessEnabled===!0,Ve=typeof Me?.desktopUiPassword=="string"?Me.desktopUiPassword:"";i($e),l($e),m(Ve),d(Ve),h(Me?.desktopLanAccessActive===!0),b(typeof Me?.desktopLanAccessBlockedReason=="string"?Me.desktopLanAccessBlockedReason:null);const We=Me?.desktopMacMenuBarEnabled!==!1;L(We),ne(We),X(null)}catch(he){oe||X(he instanceof Error?he.message:t("settings.aiworker.desktopNetwork.error.loadFailed"))}finally{oe||g(!1)}})(),()=>{oe=!0}},[e,t]),qe.useEffect(()=>{if(!e){k(!1);return}let oe=!1;return(async()=>{const he=await Od();oe||(k(he?.supported===!0),w(he?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e){E(!1);return}let oe=!1;return(async()=>{const he=await Fd();oe||(E(he?.supported===!0),_(he?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e){re(!1);return}let oe=!1;return(async()=>{const he=await Kd();oe||(re(he?.supported===!0),U(he?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e||!r){ge(null);return}let oe=!1;return(async()=>{const he=await Al();oe||ge(he)})(),()=>{oe=!0}},[r,e]);const de=r!==n||x!==p||Q!==q,xe=qe.useMemo(()=>{if(typeof window>"u")return null;const he=Ba()||window.location.href;let Me=0;try{Me=Number(new URL(he).port)}catch{Me=Number(window.location.port)}return Number.isFinite(Me)&&Me>0?Me:null},[]),ae=r&&N&&ee&&xe?`http://${ee}:${xe}`:null,te=r&&!x.trim(),ue=n&&!N&&C==="missing-password",Ie=S||T||!de||te,Ne=qe.useCallback(oe=>{d(oe),oe.trim()||l(!1)},[]),Se=qe.useCallback(async()=>{if(!P||F)return;const oe=!f;w(oe),A(!0),X(null);try{const he=await zd(oe);if(!he?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.launchAtLoginUnsupported"));w(he.enabled)}catch(he){w(!oe),X(he instanceof Error?he.message:t("settings.aiworker.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{A(!1)}},[F,f,P,t]),ve=qe.useCallback(async()=>{if(!I||j)return;const oe=!B;_(oe),V(!0),X(null);try{const he=await Ud(oe);if(!he)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"));if(!he.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTrayUnsupported"));_(he.enabled)}catch(he){_(!oe),X(he instanceof Error?he.message:t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{V(!1)}},[j,B,I,t]),Oe=qe.useCallback(async()=>{if(!z||K)return;const oe=!$;U(oe),O(!0),X(null);try{const he=await _d(oe);if(!he?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.keepAwakeUnsupported"));U(he.enabled)}catch(he){U(!oe),X(he instanceof Error?he.message:t("settings.aiworker.desktopNetwork.error.keepAwakeSaveFailed"))}finally{O(!1)}},[K,$,z,t]),Le=qe.useCallback(async()=>{if(de){M(!0),X(null);try{if(!(await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:x,desktopMacMenuBarEnabled:Q})})).ok)throw new Error(t("settings.aiworker.desktopNetwork.error.saveFailed"));if(i(r),m(x),L(Q),!await $d())throw new Error(t("settings.aiworker.desktopNetwork.error.savedRestartFailed"))}catch(oe){X(oe instanceof Error?oe.message:t("settings.aiworker.desktopNetwork.error.saveFailed")),M(!1)}}},[Q,x,r,de,t]);return e?s.jsx(_e,{title:t("settings.aiworker.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[P||a||I||z?s.jsxs("div",{className:hs,children:[P?s.jsx(ft,{settingsItem:"sessions.desktop-launch-at-login",checked:f,onChange:oe=>{oe!==f&&Se()},disabled:F,label:t("settings.aiworker.desktopNetwork.field.launchAtLogin"),info:t("settings.aiworker.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(ft,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:ne,disabled:S||T,label:t("settings.aiworker.desktopNetwork.field.macMenuBar"),info:t("settings.aiworker.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.macMenuBarAria")}):null,I?s.jsx(ft,{settingsItem:"sessions.desktop-minimize-to-tray",checked:B,onChange:oe=>{oe!==B&&ve()},disabled:j,label:t("settings.aiworker.desktopNetwork.field.minimizeToTray"),info:t("settings.aiworker.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.minimizeToTrayAria")}):null,z?s.jsx(ft,{settingsItem:"sessions.desktop-keep-awake",checked:$,onChange:oe=>{oe!==$&&Oe()},disabled:K,label:t("settings.aiworker.desktopNetwork.field.keepAwake"),info:t("settings.aiworker.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.aiworker.desktopPassword.field.password")}),info:t("settings.aiworker.desktopPassword.field.passwordDescription"),children:[s.jsx(Je,{id:"desktop-ui-password",type:y?"text":"password",className:"h-8 min-w-0 flex-1",value:x,onChange:oe=>Ne(oe.target.value),placeholder:t("settings.aiworker.desktopPassword.field.passwordPlaceholder"),disabled:S||T,required:r,"aria-invalid":te}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(oe=>!oe),className:fs,"aria-label":t(y?"settings.aiworker.desktopPassword.actions.hidePassword":"settings.aiworker.desktopPassword.actions.showPassword"),"aria-pressed":y,children:s.jsx(R,{name:y?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:hs,children:s.jsx(ft,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:S||T,label:t("settings.aiworker.desktopNetwork.field.allowLanAccess"),info:t("settings.aiworker.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.warning")}),te||ue?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.aiworker.desktopNetwork.field.allowLanAccessAria")})}),Y?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Y}):null,ae?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(de&&!n?"settings.aiworker.desktopNetwork.hint.openAfterRestart":"settings.aiworker.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ae})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:Le,disabled:Ie,className:"shrink-0 !font-normal",children:t(T?"settings.common.actions.saving":"settings.aiworker.desktopNetwork.actions.saveAndRestart")})})]})}):null},oc=new Set(["shift","control","alt","meta"]),Dr=3,Rh=3e3;function Mr(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Lh(t){return t.action.customizable}function ol(t){if(Mr(t)>Dr)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Pi(e.join("+")):null}function Oh(t){if(oc.has(t.key.toLowerCase())||Mr(t,!0)>Dr)return null;const e=rd(od(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),Pi(a.join("+"))}function Fh(t){const e=t.key.toLowerCase();if(!oc.has(e)||Mr(t,!0)>Dr)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?Pi(a.join("+")):null}function ll(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Kh(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:ol(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Oh(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:ol(e)}}const zh=t=>{const e=gt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=it();let p;e[0]!==l?(p=te=>l(te.settingsLabelKey),e[0]=l,e[1]=p):p=e[1];const m=p;let x;e[2]!==m?(x=te=>te.action.customizable?m(te.action):Qn(te.action.defaultBinding),e[2]=m,e[3]=x):x=e[3];const d=x;let y;e[4]===Symbol.for("react.memo_cache_sentinel")?(y={chords:[],livePreview:null,settled:!1},e[4]=y):y=e[4];const[c,N]=o.useState(y),h=o.useRef(null);let C,b;e[5]!==a?(C=()=>{a&&(N({chords:[],livePreview:null,settled:!1}),h.current?.focus())},b=[a],e[5]=a,e[6]=C,e[7]=b):(C=e[6],b=e[7]),o.useEffect(C,b);const S=c.chords.length===1&&!c.settled;let g,T;e[8]!==S?(g=()=>{if(!S)return;const te=window.setTimeout(()=>N(ll),Rh);return()=>window.clearTimeout(te)},T=[S],e[8]=S,e[9]=g,e[10]=T):(g=e[9],T=e[10]),o.useEffect(g,T);let M;e[11]!==c.chords?(M=Pi(c.chords.join(" ")),e[11]=c.chords,e[12]=M):M=e[12];const P=M;let k;e[13]!==a||e[14]!==P||e[15]!==n?(k=a&&P?ad(a.id,P,n):[],e[13]=a,e[14]=P,e[15]=n,e[16]=k):k=e[16];const f=k;let w;e[17]!==f?(w=f.find(Uh),e[17]=f,e[18]=w):w=e[18];const F=w;let A,I,E,B,_,j,V,q,L,Q,ne,z,re,$,U;if(e[19]!==a||e[20]!==m||e[21]!==P||e[22]!==d||e[23]!==f||e[24]!==r||e[25]!==i||e[26]!==F||e[27]!==c||e[28]!==l){const te=f.filter(Lh);_=te.find(_h);const ue=te.find($h),Ie=f.find(Vh);let Ne;e[44]!==r?(Ne=()=>r(!1),e[44]=r,e[45]=Ne):Ne=e[45],E=Ne,B=()=>{c.settled||N(ll),!(!a||!P||F||_)&&(i(a.id,P,ue?.action.id),E())};let Se;e[46]!==a||e[47]!==c?(Se=(be,Te)=>{be.preventDefault(),be.stopPropagation();const Ue=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Te==="keyup"&&Ue&&c.chords.length===0){const we=Fh(be);if(we){N({chords:[we],livePreview:null,settled:!0});return}}const Pe=Kh(c,{altKey:be.altKey,code:be.nativeEvent.code,ctrlKey:be.ctrlKey,isComposing:be.nativeEvent.isComposing,key:be.key,metaKey:be.metaKey,repeat:be.repeat,shiftKey:be.shiftKey},Te);N(Ue&&Pe.chords.length>1?c:Pe)},e[46]=a,e[47]=c,e[48]=Se):Se=e[48];const ve=Se;I=Kt,$=a!==null,U=Bh,A=zt,j="max-w-md",V=h,q=!1;let Oe;e[49]!==a||e[50]!==m||e[51]!==l?(Oe=a?l("settings.aiworker.keyboardShortcuts.dialog.title",{action:m(a)}):"",e[49]=a,e[50]=m,e[51]=l,e[52]=Oe):Oe=e[52];let Le;e[53]!==Oe?(Le=s.jsx($t,{children:Oe}),e[53]=Oe,e[54]=Le):Le=e[54];let oe;e[55]!==l?(oe=l("settings.aiworker.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=oe):oe=e[56];let he;e[57]!==oe?(he=s.jsx(Vt,{children:oe}),e[57]=oe,e[58]=he):he=e[58],e[59]!==Le||e[60]!==he?(L=s.jsxs(_t,{children:[Le,he]}),e[59]=Le,e[60]=he,e[61]=L):L=e[61];let Me,$e;e[62]!==ve?(Me=be=>ve(be,"keydown"),$e=be=>ve(be,"keyup"),e[62]=ve,e[63]=Me,e[64]=$e):(Me=e[63],$e=e[64]);let Ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ve=()=>N(Hh),e[65]=Ve):Ve=e[65];let We;e[66]!==c.chords?(We=c.chords.map(Gh),e[66]=c.chords,e[67]=We):We=e[67];let se;e[68]!==c.livePreview?(se=c.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:Qn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=se):se=e[69];let ie;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(ie=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.aiworker.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.livePreview,e[72]=l,e[73]=ie):ie=e[73];let je;e[74]!==We||e[75]!==se||e[76]!==ie?(je=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[We,se,ie]}),e[74]=We,e[75]=se,e[76]=ie,e[77]=je):je=e[77],e[78]!==Me||e[79]!==$e||e[80]!==je?(Q=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:h,onKeyDown:Me,onKeyUp:$e,onBlur:Ve,children:je}),e[78]=Me,e[79]=$e,e[80]=je,e[81]=Q):Q=e[81],ne=c.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.internalConflict")}):c.settled&&_?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.prefixConflict",{action:m(_.action)})}):null,z=c.settled&&ue&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.error.exactConflict",{action:m(ue.action)})}):null,re=c.settled&&Ie&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.contextualPrefix",{action:d(Ie)})}):null,e[19]=a,e[20]=m,e[21]=P,e[22]=d,e[23]=f,e[24]=r,e[25]=i,e[26]=F,e[27]=c,e[28]=l,e[29]=A,e[30]=I,e[31]=E,e[32]=B,e[33]=_,e[34]=j,e[35]=V,e[36]=q,e[37]=L,e[38]=Q,e[39]=ne,e[40]=z,e[41]=re,e[42]=$,e[43]=U}else A=e[29],I=e[30],E=e[31],B=e[32],_=e[33],j=e[34],V=e[35],q=e[36],L=e[37],Q=e[38],ne=e[39],z=e[40],re=e[41],$=e[42],U=e[43];let K;e[82]!==P||e[83]!==c.settled||e[84]!==l?(K=c.settled&&P&&id(P)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=P,e[83]=c.settled,e[84]=l,e[85]=K):K=e[85];let O;e[86]!==l?(O=l("settings.common.actions.cancel"),e[86]=l,e[87]=O):O=e[87];let Y;e[88]!==E||e[89]!==O?(Y=s.jsx(H,{type:"button",variant:"ghost",size:"sm",onClick:E,children:O}),e[88]=E,e[89]=O,e[90]=Y):Y=e[90];const X=!P||c.settled&&(!!F||!!_);let ee;e[91]!==l?(ee=l("settings.aiworker.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ee):ee=e[92];let ge;e[93]!==B||e[94]!==X||e[95]!==ee?(ge=s.jsx(H,{type:"button",size:"sm",disabled:X,onClick:B,children:ee}),e[93]=B,e[94]=X,e[95]=ee,e[96]=ge):ge=e[96];let de;e[97]!==Y||e[98]!==ge?(de=s.jsxs(ts,{children:[Y,ge]}),e[97]=Y,e[98]=ge,e[99]=de):de=e[99];let xe;e[100]!==A||e[101]!==j||e[102]!==V||e[103]!==q||e[104]!==L||e[105]!==Q||e[106]!==ne||e[107]!==z||e[108]!==re||e[109]!==K||e[110]!==de?(xe=s.jsxs(A,{className:j,initialFocus:V,showCloseButton:q,children:[L,Q,ne,z,re,K,de]}),e[100]=A,e[101]=j,e[102]=V,e[103]=q,e[104]=L,e[105]=Q,e[106]=ne,e[107]=z,e[108]=re,e[109]=K,e[110]=de,e[111]=xe):xe=e[111];let ae;return e[112]!==I||e[113]!==$||e[114]!==U||e[115]!==xe?(ae=s.jsx(I,{open:$,onOpenChange:U,children:xe}),e[112]=I,e[113]=$,e[114]=U,e[115]=xe,e[116]=ae):ae=e[116],ae};function Uh(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function _h(t){return t.kind==="prefix"}function $h(t){return t.kind==="exact"}function Vh(t){return t.kind==="contextual-prefix"}function Bh(t,e){t||e.cancel()}function Hh(t){return{...t,livePreview:null}}function Gh(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:Qn(t)},`${t}-${e}`)}const Wh=["session","models","panels","navigation","application"],qh=()=>{const t=gt.c(24),{t:e}=it(),a=le(Jh),n=le(Qh),i=le(Yh),r=le(Xh),[l,p]=o.useState(null);let m;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const P=ld();m=cs()?P.filter(Zh):P,t[0]=m}else m=t[0];const x=m,d=ex;let y;t[1]!==n||t[2]!==a?(y=(P,k,f)=>{const w={...a,[P]:k};f&&(w[f]=Gi),n(P,k),f&&n(f,Gi),d(w)},t[1]=n,t[2]=a,t[3]=y):y=t[3];const c=y;let N;t[4]!==i||t[5]!==a?(N=P=>{const k={...a};delete k[P],i(P),d(k)},t[4]=i,t[5]=a,t[6]=N):N=t[6];const h=N;let C;t[7]!==a||t[8]!==e?(C=P=>{const k="prefixStyle"in P&&P.prefixStyle,f=k?cd(P.id,a):Il(P.id,a),w=Qn(f,e("settings.aiworker.keyboardShortcuts.unassigned"));if(!k||!f||f===Gi)return w;const F=P.id==="switch_session_tab"?e("settings.aiworker.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.aiworker.keyboardShortcuts.action.switch_context_surface.suffix");return`${w}${F}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const b=C;let S;t[10]!==r||t[11]!==h||t[12]!==b||t[13]!==a||t[14]!==e?(S=Wh.map((P,k)=>{const f=x.filter(w=>w.category===P);return f.length===0?null:s.jsx(_e,{settingsItem:k===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.aiworker.keyboardShortcuts.category.${P}`),divider:k!==0,info:k===0?e("settings.aiworker.keyboardShortcuts.tooltip"):void 0,headerAction:k===0?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{r(),d({})},children:e("settings.aiworker.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:f.map(w=>s.jsxs(Lt,{label:e(w.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:b(w)}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>p(w),children:e("settings.aiworker.keyboardShortcuts.actions.edit")}),w.id in a?s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>h(w.id),children:e("settings.common.actions.reset")}):null]},w.id))})},P)}),t[10]=r,t[11]=h,t[12]=b,t[13]=a,t[14]=e,t[15]=S):S=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=P=>{P||p(null)},t[16]=g):g=t[16];let T;t[17]!==l||t[18]!==c||t[19]!==a?(T=s.jsx(zh,{action:l,overrides:a,onSave:c,onOpenChange:g}),t[17]=l,t[18]=c,t[19]=a,t[20]=T):T=t[20];let M;return t[21]!==S||t[22]!==T?(M=s.jsxs(s.Fragment,{children:[S,T]}),t[21]=S,t[22]=T,t[23]=M):M=t[23],M};function Jh(t){return t.shortcutOverrides}function Qh(t){return t.setShortcutOverride}function Yh(t){return t.clearShortcutOverride}function Xh(t){return t.resetAllShortcutOverrides}function Zh(t){return t.id!=="toggle_prompt_navigator"}function ex(t){yt({shortcutOverrides:t})}const lc=()=>{const t=gt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Tl(()=>a(ux)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},tx=t=>{const e=gt.c(80),{section:a}=t,{t:n}=it(),{isMobile:i}=wa();lc();let r;e[0]!==i?(r=i&&qn(),e[0]=i,e[1]=r):r=e[1];const l=r;let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=cs(),e[2]=p):p=e[2];const m=p;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=as()&&Ha(),e[3]=x):x=e[3];const d=x;if(!a){let z,re,$,U,K,O,Y,X;e[4]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Ai,{}),U=s.jsx(tc,{}),K=d&&s.jsx(rc,{}),O=!m&&s.jsx(ac,{}),Y=!m&&s.jsx(ic,{}),X=s.jsx(Xl,{}),z=s.jsx(ec,{}),re=qn()&&!as()&&!m&&!Ml()&&s.jsx(Zl,{}),e[4]=z,e[5]=re,e[6]=$,e[7]=U,e[8]=K,e[9]=O,e[10]=Y,e[11]=X):(z=e[4],re=e[5],$=e[6],U=e[7],K=e[8],O=e[9],Y=e[10],X=e[11]);let ee;e[12]!==l?(ee=l&&s.jsx(Fl,{}),e[12]=l,e[13]=ee):ee=e[13];let ge;return e[14]!==ee?(ge=s.jsxs(es,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[$,U,K,O,Y,X,z,re,ee]}),e[14]=ee,e[15]=ge):ge=e[15],ge}let y;e[16]!==a?(y=()=>{switch(a){case"general":return s.jsx(nx,{});case"visual":return s.jsx(ax,{});case"chat":return s.jsx(ix,{});case"sessions":return s.jsx(rx,{});case"shortcuts":return s.jsx(sx,{});case"git":return s.jsx(ox,{});case"notifications":return s.jsx(lx,{});case"voice":return s.jsx(cx,{});case"tunnel":return s.jsx(dx,{});default:return null}},e[16]=a,e[17]=y):y=e[17];const c=y;let N;e[18]!==n?(N=n("settings.page.general.title"),e[18]=n,e[19]=N):N=e[19];let h;e[20]!==n?(h=n("settings.page.appearance.title"),e[20]=n,e[21]=h):h=e[21];let C;e[22]!==n?(C=n("settings.page.chat.title"),e[22]=n,e[23]=C):C=e[23];let b;e[24]!==n?(b=n("settings.page.sessions.title"),e[24]=n,e[25]=b):b=e[25];let S;e[26]!==n?(S=n("settings.page.shortcuts.title"),e[26]=n,e[27]=S):S=e[27];let g;e[28]!==n?(g=n("settings.page.git.title"),e[28]=n,e[29]=g):g=e[29];let T;e[30]!==n?(T=n("settings.page.git.title"),e[30]=n,e[31]=T):T=e[31];let M;e[32]!==n?(M=n("settings.page.notifications.title"),e[32]=n,e[33]=M):M=e[33];let P;e[34]!==n?(P=n("settings.page.voice.title"),e[34]=n,e[35]=P):P=e[35];let k;e[36]!==n?(k=n("settings.page.tunnel.title"),e[36]=n,e[37]=k):k=e[37];let f;e[38]!==g||e[39]!==T||e[40]!==M||e[41]!==P||e[42]!==k||e[43]!==N||e[44]!==h||e[45]!==C||e[46]!==b||e[47]!==S?(f={general:N,visual:h,chat:C,sessions:b,shortcuts:S,git:g,github:T,notifications:M,voice:P,tunnel:k},e[38]=g,e[39]=T,e[40]=M,e[41]=P,e[42]=k,e[43]=N,e[44]=h,e[45]=C,e[46]=b,e[47]=S,e[48]=f):f=e[48];const w=f[a];let F;e[49]!==n?(F=n("settings.page.general.description"),e[49]=n,e[50]=F):F=e[50];let A;e[51]!==n?(A=n("settings.page.appearance.description"),e[51]=n,e[52]=A):A=e[52];let I;e[53]!==n?(I=n("settings.page.chat.description"),e[53]=n,e[54]=I):I=e[54];let E;e[55]!==n?(E=n("settings.page.sessions.description"),e[55]=n,e[56]=E):E=e[56];let B;e[57]!==n?(B=n("settings.page.shortcuts.description"),e[57]=n,e[58]=B):B=e[58];let _;e[59]!==n?(_=n("settings.page.notifications.description"),e[59]=n,e[60]=_):_=e[60];let j;e[61]!==n?(j=n("settings.page.voice.description"),e[61]=n,e[62]=j):j=e[62];let V;e[63]!==n?(V=n("settings.page.tunnel.description"),e[63]=n,e[64]=V):V=e[64];let q;e[65]!==F||e[66]!==A||e[67]!==I||e[68]!==E||e[69]!==B||e[70]!==_||e[71]!==j||e[72]!==V?(q={general:F,visual:A,chat:I,sessions:E,shortcuts:B,git:void 0,github:void 0,notifications:_,voice:j,tunnel:V},e[65]=F,e[66]=A,e[67]=I,e[68]=E,e[69]=B,e[70]=_,e[71]=j,e[72]=V,e[73]=q):q=e[73];const L=q[a];let Q;e[74]!==c?(Q=c(),e[74]=c,e[75]=Q):Q=e[75];let ne;return e[76]!==L||e[77]!==w||e[78]!==Q?(ne=s.jsx(es,{title:w,description:L,showSaveStatus:!0,className:"openchamber-page-body",children:Q}),e[76]=L,e[77]=w,e[78]=Q,e[79]=ne):ne=e[79],ne},sx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(qh,{}),t[0]=e):e=t[0],e},nx=()=>{const t=gt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;lc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=as()&&Ha(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=qn()&&!as()&&!a&&!Ml(),t[2]=r):r=t[2];const l=r;let p,m,x,d,y;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=i&&s.jsx(rc,{}),m=l&&s.jsx(Zl,{}),x=s.jsx(ec,{}),d=!a&&s.jsx(ac,{}),y=!a&&s.jsx(ic,{}),t[3]=p,t[4]=m,t[5]=x,t[6]=d,t[7]=y):(p=t[3],m=t[4],x=t[5],d=t[6],y=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let N;return t[9]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs(s.Fragment,{children:[p,m,x,d,y,s.jsx(Ai,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=N):N=t[9],N},ax=()=>{const t=gt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ai,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},ix=()=>{const t=gt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ai,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},rx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(tc,{}),s.jsx(Xl,{})]}),t[0]=e):e=t[0],e},ox=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Yl,{}),t[0]=e):e=t[0],e},lx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(ih,{}),t[0]=e):e=t[0],e},cx=()=>{const t=gt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(fh,{}),t[0]=e):e=t[0],e},dx=()=>{const t=gt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ch,{}),t[0]=e):e=t[0],e};function ux(t){return t+1}const px=t=>{const e=gt.c(85),{className:a}=t,{t:n}=it(),i=Wn(Pl),r=Wn(mx),l=le(gx),p=le(fx),[m,x]=qe.useState(!1),[d,y]=qe.useState(!1),c=i>0;let N;e[0]!==n?(N=async()=>{try{const Ne=await dd({message:n("settings.view.pendingRestart.applying")});if(Ne.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ne.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(Ne){const Se=Ne,ve=Se instanceof Error&&Se.message?Se.message:n("settings.view.pendingRestart.applyFailed");D.error(ve)}},e[0]=n,e[1]=N):N=e[1];const h=N;let C;e[2]!==n?(C=async()=>{try{await Nl({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),Wn.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const b=C;let S;e[4]!==d||e[5]!==h||e[6]!==p?(S=()=>{d&&p(!1),x(!1),y(!1),h()},e[4]=d,e[5]=h,e[6]=p,e[7]=S):S=e[7];const g=S;let T;e[8]!==c||e[9]!==h||e[10]!==b||e[11]!==l?(T=()=>{if(!c){b();return}if(l){y(!1),x(!0);return}h()},e[8]=c,e[9]=h,e[10]=b,e[11]=l,e[12]=T):T=e[12];const M=T;let P;e[13]!==c||e[14]!==r||e[15]!==n?(P=n(c?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=r,e[15]=n,e[16]=P):P=e[16];const k=P;let f;e[17]!==c||e[18]!==i||e[19]!==n?(f=c?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=i,e[19]=n,e[20]=f):f=e[20];const w=f,F=c?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",A=r&&"opacity-80";let I;e[21]!==a||e[22]!==F||e[23]!==A?(I=ye("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F,A,a),e[21]=a,e[22]=F,e[23]=A,e[24]=I):I=e[24];let E;e[25]!==c||e[26]!==i?(E=c?s.jsx("span",{className:ye("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(R,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=c,e[26]=i,e[27]=E):E=e[27];let B;e[28]!==k?(B=s.jsx("span",{className:"truncate",children:k}),e[28]=k,e[29]=B):B=e[29];let _;e[30]!==M||e[31]!==r||e[32]!==E||e[33]!==B||e[34]!==I||e[35]!==w?(_=s.jsxs("button",{type:"button",disabled:r,title:w,"aria-label":w,onClick:M,className:I,children:[E,B]}),e[30]=M,e[31]=r,e[32]=E,e[33]=B,e[34]=I,e[35]=w,e[36]=_):_=e[36];let j;e[37]===Symbol.for("react.memo_cache_sentinel")?(j=Ne=>{x(Ne),Ne||y(!1)},e[37]=j):j=e[37];let V;e[38]!==n?(V=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=V):V=e[39];let q;e[40]!==V?(q=s.jsx($t,{children:V}),e[40]=V,e[41]=q):q=e[41];let L;e[42]!==n?(L=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=L):L=e[43];let Q;e[44]!==L?(Q=s.jsx(Vt,{children:L}),e[44]=L,e[45]=Q):Q=e[45];let ne;e[46]!==q||e[47]!==Q?(ne=s.jsxs(_t,{children:[q,Q]}),e[46]=q,e[47]=Q,e[48]=ne):ne=e[48];let z;e[49]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[49]=z):z=e[49];let re;e[50]===Symbol.for("react.memo_cache_sentinel")?(re=()=>x(!1),e[50]=re):re=e[50];let $;e[51]!==n?($=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=$):$=e[52];let U;e[53]!==$?(U=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:re,children:$})}),e[53]=$,e[54]=U):U=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K={width:"40%"},e[55]=K):K=e[55];let O;e[56]!==n?(O=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=O):O=e[57];let Y;e[58]!==g||e[59]!==O?(Y=s.jsx("div",{className:"min-w-0 shrink-0",style:K,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:g,children:O})}),e[58]=g,e[59]=O,e[60]=Y):Y=e[60];let X;e[61]!==U||e[62]!==Y?(X=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[U,Y]}),e[61]=U,e[62]=Y,e[63]=X):X=e[63];let ee;e[64]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>y(hx),e[64]=ee):ee=e[64];let ge;e[65]!==d?(ge=d?s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=d,e[66]=ge):ge=e[66];let de;e[67]!==n?(de=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=de):de=e[68];let xe;e[69]!==d||e[70]!==ge||e[71]!==de?(xe=s.jsxs("button",{type:"button",onClick:ee,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":d,children:[ge,de]}),e[69]=d,e[70]=ge,e[71]=de,e[72]=xe):xe=e[72];let ae;e[73]!==X||e[74]!==xe?(ae=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[X,xe]}),e[73]=X,e[74]=xe,e[75]=ae):ae=e[75];let te;e[76]!==ne||e[77]!==ae?(te=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[ne,ae]}),e[76]=ne,e[77]=ae,e[78]=te):te=e[78];let ue;e[79]!==m||e[80]!==te?(ue=s.jsx(Kt,{open:m,onOpenChange:j,children:te}),e[79]=m,e[80]=te,e[81]=ue):ue=e[81];let Ie;return e[82]!==_||e[83]!==ue?(Ie=s.jsxs(s.Fragment,{children:[_,ue]}),e[82]=_,e[83]=ue,e[84]=Ie):Ie=e[84],Ie};function mx(t){return t.isApplying}function gx(t){return t.showOpenCodeRestartConfirm}function fx(t){return t.setShowOpenCodeRestartConfirm}function hx(t){return!t}const xx=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.aiworker.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.aiworker.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.aiworker.visual.field.dockBadge",descriptionKey:"settings.aiworker.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.aiworker.visual.field.installAppName",descriptionKey:"settings.aiworker.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.aiworker.visual.field.installOrientation",descriptionKey:"settings.aiworker.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.aiworker.visual.field.mobileKeyboardMode",descriptionKey:"settings.aiworker.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.aiworker.visual.field.terminalShell",descriptionKey:"settings.aiworker.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.aiworker.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.aiworker.visual.field.inputBarOffset",descriptionKey:"settings.aiworker.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.aiworker.visual.field.autoSaveEnabled",descriptionKey:"settings.aiworker.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.aiworker.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.aiworker.visual.field.sessionTabsGroup",descriptionKey:"settings.aiworker.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.aiworker.visual.field.terminalQuickKeys",descriptionKey:"settings.aiworker.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.aiworker.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.aiworker.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.aiworker.appLinks.title",descriptionKey:"settings.aiworker.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.aiworker.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.aiworker.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.aiworker.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.aiworker.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.aiworker.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.aiworker.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.aiworker.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.aiworker.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.aiworker.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.aiworker.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.aiworker.visual.field.streamingAutoFollow",descriptionKey:"settings.aiworker.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.aiworker.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.aiworker.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.aiworker.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.aiworker.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.aiworker.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.aiworker.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.aiworker.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.aiworker.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.aiworker.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.aiworker.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.aiworker.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.aiworker.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.aiworker.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.aiworker.visual.section.followUpBehavior",descriptionKey:"settings.aiworker.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryScope",descriptionKey:"settings.aiworker.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.aiworker.visual.field.inputHistoryLimit",descriptionKey:"settings.aiworker.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.aiworker.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.aiworker.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.aiworker.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.aiworker.visual.field.largeTextPaste",descriptionKey:"settings.aiworker.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.aiworker.visual.field.enterToSend",descriptionKey:"settings.aiworker.visual.field.enterToSendHint",keywords:["enter","shift enter","send","newline"]},{id:"sessions.default-model",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.aiworker.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.aiworker.defaults.smallModel.title",descriptionKey:"settings.aiworker.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.aiworker.defaults.walkthroughModel.title",descriptionKey:"settings.aiworker.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.aiworker.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.aiworker.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.aiworker.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.macMenuBar",descriptionKey:"settings.aiworker.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.aiworker.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.keepAwake",descriptionKey:"settings.aiworker.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.aiworker.desktopPassword.field.password",descriptionKey:"settings.aiworker.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.aiworker.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.aiworker.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.aiworker.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentControlTool",descriptionKey:"settings.aiworker.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","aiworker","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentWebTool",descriptionKey:"settings.aiworker.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","aiworker"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentMemoryTool",descriptionKey:"settings.aiworker.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","aiworker"],isAvailable:t=>!t.isVSCode&&le.getState().agentMemoryFeatureAvailable},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.aiworker.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.aiworker.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.aiworker.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.aiworker.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.aiworker.keyboardShortcuts.title",descriptionKey:"settings.aiworker.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.provider",descriptionKey:"settings.aiworker.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.connectLinkTtl",descriptionKey:"settings.aiworker.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.aiworker.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.configurationFile",descriptionKey:"settings.aiworker.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.aiworker.tunnel.actions.startTunnel",descriptionKey:"settings.aiworker.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode}];function cl(t){return t.trim().toLocaleLowerCase()}function vx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=cl(t);if(!r)return[];const l=a?new Set(a):null,p=r.split(/\s+/).filter(Boolean);return xx.flatMap(m=>{if(l&&!l.has(m.page))return[];const x=Oa(m.page);if(!x||x.isAvailable&&!x.isAvailable(e)||m.isAvailable&&!m.isAvailable(e))return[];const d=n(m.titleKey),y=m.descriptionKey?n(m.descriptionKey):null,c=cl([d,y,i(m.page),...m.keywords??[]].filter(Boolean).join(" "));return p.every(N=>c.includes(N))?[{...m,title:d,description:y,pageTitle:i(m.page)}]:[]})}const dl=256,ul=280,cc="__aiworkerSettingsDetail",yx=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],bx=["general","projects","opencode","content"],wx="__add_provider__";function jx(t,e){const a=cs(),n=!t&&qn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function pl(t,e){return t.isAvailable?t.isAvailable(e):!0}function vr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function La(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function ir(t){if(!vr(t))return null;const e=t[cc];if(!vr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Rl(a),stage:n}}function kx(){return typeof window>"u"||!vr(window.history.state)?{}:window.history.state}const Lx=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav"})=>{const{t:r}=it(),l=wa(),p=e??l.isMobile,m=Wn(Pl),x=le(se=>se.settingsPage),d=le(se=>se.isSettingsDialogOpen),y=le(se=>se.setSettingsPage),c=le(se=>se.shortcutOverrides.open_settings),N=Rl(x),[h,C]=o.useState(i),b=o.useRef(i==="nav"?N:null);o.useEffect(()=>{!p&&N==="home"&&y("general")},[p,y,N]);const[S,g]=o.useState(""),[T,M]=o.useState(null),[P,k]=o.useState(0),f=o.useRef(null),w=o.useRef(!1),F=o.useRef([]),A=o.useRef(0),I=o.useRef(!1),E=o.useMemo(()=>as(),[]),B=o.useMemo(()=>as()&&Ha(),[]),_=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),j=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="win32",[]),V=o.useMemo(()=>as()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="linux",[]),q=o.useMemo(()=>Dl(),[]),L=o.useMemo(()=>jx(E,p),[E,p]),Q=o.useMemo(()=>{const se=n?new Set(n):null;return Gd.filter(ie=>ie.slug!=="home").filter(ie=>!se||se.has(ie.slug)).filter(ie=>pl(ie,L)).filter(ie=>!(L.isVSCode&&ie.slug==="projects")).filter(ie=>!(p&&ie.slug==="shortcuts"))},[L,p,n]),ne=o.useMemo(()=>{const se=new Map(yx.map((ie,je)=>[ie,je]));return Q.slice().sort((ie,je)=>(se.get(ie.slug)??999)-(se.get(je.slug)??999))},[Q]),z=Bs(se=>se.activeProjectId),re=Us();o.useEffect(()=>{if(!(!d&&!L.isVSCode&&!a)){if(N==="agents"){Jn.getState().loadAgents(re);return}if(N==="commands"){ya.getState().loadCommands(re);return}if(N==="mcp"){ba.getState().loadMcpConfigs({directory:re});return}if(N==="plugins"){ps.getState().loadPlugins();return}(N==="skills.installed"||N==="skills.catalog")&&(Vs.getState().loadSkills(re),fn.getState().loadCatalog()),N==="snippets"&&Ci.getState().loadSnippets()}},[z,d,a,L.isVSCode,re,N]);const $=o.useCallback(se=>{if(y(se),b.current=se,!p)return;const ie=Oa(se);if(!ie||ie.slug==="home"){C("nav");return}C(ie.kind==="split"?"page-sidebar":"page-content")},[p,y]),U=o.useMemo(()=>Oa(N),[N]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),O=o.useCallback(se=>{switch(se){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),Y=o.useMemo(()=>vx({query:S,runtimeCtx:{...L,isDesktopLocalOrigin:B,isMac:_,isWindows:j,isLinux:V,isWindowsArm64:q},visiblePageSlugs:n,t:r,getPageTitle:O}),[O,q,B,_,j,V,L,S,r,n]),X=o.useCallback(se=>{if(se.id.startsWith("agents.")){const ie=Jn.getState(),je=La("new-agent",ie.agents.map(be=>be.name));return ie.setAgentDraft({name:je,scope:"user"}),ie.setSelectedAgent(je),se.id==="agents.create"?"agents.name":se.id}if(se.id.startsWith("commands.")){const ie=ya.getState(),je=La("new-command",ie.commands.map(be=>be.name));return ie.setCommandDraft({name:je,scope:"user"}),ie.setSelectedCommand(je),se.id==="commands.create"?"commands.name":se.id}if(se.id.startsWith("mcp.")){const ie=ba.getState(),je=La("new-mcp-server",ie.mcpServers.map(be=>be.name));return ie.setMcpDraft({name:je,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ie.setSelectedMcp(je),se.id==="mcp.create"?"mcp.server":se.id}if(se.id.startsWith("snippets.")){const ie=Ci.getState(),je=La("new-snippet",ie.snippets.map(be=>be.name));return ie.setSnippetDraft({name:je,scope:"global"}),ie.setSelectedSnippet(je),se.id==="snippets.create"?"snippets.content":se.id}if(se.id.startsWith("skills.")){const ie=Vs.getState(),je=La("new-skill",ie.skills.map(be=>be.name));return ie.setSkillDraft({name:je,scope:"user",source:"opencode",description:"",instructions:""}),ie.setSelectedSkill(je),se.id==="skills.create"?"skills.basic-information":se.id}return se.id==="providers.connect"&&Ze.getState().setSelectedProvider(wx),se.id==="plugins.create"?"plugins.spec":se.id},[]),ee=o.useMemo(()=>{const se=[],ie=new Map;for(const je of Y){let be=ie.get(je.page);be||(be={page:je.page,pageTitle:je.pageTitle,results:[]},ie.set(je.page,be),se.push(be)),be.results.push(je)}return se},[Y]);o.useEffect(()=>{k(0),A.current=0,I.current=!1},[S]),o.useEffect(()=>{A.current=P},[P]),o.useEffect(()=>{F.current[P]?.scrollIntoView({block:"nearest"})},[P]),o.useEffect(()=>{P>=Y.length&&k(Math.max(0,Y.length-1)),F.current.length=Y.length},[P,Y.length]);const ge=o.useCallback(se=>{const ie=X(se);M(ie),$(se.page),p&&C("page-content"),se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("aiworker:settings-open-plugin-add"))},50)},[p,$,X]),de=o.useCallback(se=>{if(S.trim()){if(se.key==="Escape"){se.preventDefault(),g("");return}if(Y.length!==0){if(se.key==="ArrowDown"){se.preventDefault(),I.current=!0,k(ie=>(ie+1)%Y.length);return}if(se.key==="ArrowUp"){se.preventDefault(),I.current=!0,k(ie=>(ie-1+Y.length)%Y.length);return}if(se.key==="Enter"){se.preventDefault();const ie=(A.current%Y.length+Y.length)%Y.length,je=Y[ie]??Y[0];je&&ge(je)}}}},[ge,S,Y]);o.useEffect(()=>{const se=T;if(!se)return;let ie=!1;const je=window.requestAnimationFrame(()=>{if(ie)return;const be=typeof CSS<"u"&&CSS.escape?CSS.escape(se):se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Te=f.current?.querySelector(`[data-settings-item="${be}"]`);Te&&(M(null),Te.scrollIntoView({block:"center",behavior:"smooth"}),Te.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Te.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ie=!0,window.cancelAnimationFrame(je)}},[T,N]);const xe=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:jl,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ae=o.useCallback((se,ie)=>{switch(se){case"projects":return s.jsx(Em,{onItemSelect:ie.onItemSelect});case"agents":return s.jsx(xu,{onItemSelect:ie.onItemSelect});case"commands":return s.jsx(Ru,{onItemSelect:ie.onItemSelect});case"mcp":return s.jsx($u,{onItemSelect:ie.onItemSelect});case"plugins":return s.jsx(Ap,{onItemSelect:ie.onItemSelect});case"skills.installed":return s.jsx(Vp,{onItemSelect:ie.onItemSelect});case"providers":return s.jsx(ig,{onItemSelect:ie.onItemSelect});case"usage":return s.jsx($g,{onItemSelect:ie.onItemSelect});case"magic-prompts":return s.jsx(rf,{onItemSelect:ie.onItemSelect});case"snippets":return s.jsx(df,{onItemSelect:ie.onItemSelect});default:return null}},[]),te=o.useCallback(se=>{const ie=Oa(se);if(ie&&!pl(ie,L))return xe();switch(se){case"projects":return s.jsx(Om,{});case"remote-instances":return s.jsx(sg,{});case"agents":return s.jsx(Pu,{});case"behavior":return s.jsx(Mu,{});case"commands":return s.jsx(_u,{});case"mcp":return s.jsx(dp,{});case"plugins":return s.jsx(_p,{});case"skills.installed":return s.jsx(wo,{view:"installed"});case"skills.catalog":return s.jsx(wo,{view:"catalog"});case"providers":return s.jsx(Ug,{});case"usage":return s.jsx(nf,{});case"about":return s.jsx(es,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Fl,{})});case"magic-prompts":return s.jsx(cf,{});case"snippets":return s.jsx(gf,{});case"git":return s.jsx(yf,{});case"integrations":return s.jsx(Rf,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const je=K[se]??"visual";return s.jsx(tx,{section:je})}default:return null}},[K,xe,L,r]);o.useEffect(()=>{if(!p||h!=="nav"||N==="home"||b.current===N)return;const se=Oa(N);!se||se.slug==="home"||(b.current=N,C(se.kind==="split"?"page-sidebar":"page-content"))},[p,h,N]);const ue=p&&h!=="nav",Ie=p&&h==="page-content"&&N==="skills.installed",Ne=h==="page-content"&&U?.kind==="split"&&!Ie,Se=r(Ie?"settings.view.actions.back":ue?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),ve=Il("open_settings",c===void 0?void 0:{open_settings:c}),Oe=ve?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Qn(ve)}):r("settings.view.actions.closeSettings"),Le=o.useCallback(se=>{if(typeof window>"u"||L.isVSCode)return;const ie=ir(window.history.state);ie?.page===se&&ie.stage==="page-content"||window.history.pushState({...kx(),[cc]:{page:se,stage:"page-content"}},"",window.location.href)},[L.isVSCode]),oe=o.useCallback(()=>{w.current=!0,C("page-content"),N==="skills.installed"&&Le(N)},[Le,N]);o.useEffect(()=>{if(!p||h!=="page-content"||!w.current)return;w.current=!1;const se=window.requestAnimationFrame(()=>{f.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(se)}},[p,h,N]);const he=o.useCallback(()=>{if(Ie){if((typeof window<"u"?ir(window.history.state):null)?.page===N&&!L.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[Ie,L.isVSCode,N]);o.useEffect(()=>{if(!p||L.isVSCode)return;const se=ie=>{if(N!=="skills.installed")return;if(ir(ie.state)?.page==="skills.installed"){C("page-content");return}C(be=>be==="page-content"?"page-sidebar":be)};return window.addEventListener("popstate",se),()=>{window.removeEventListener("popstate",se)}},[p,L.isVSCode,N]);const Me=o.useCallback(()=>{C("page-sidebar")},[]),$e=()=>{const se=S.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(R,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:S,onChange:ie=>g(ie.target.value),onKeyDown:de,placeholder:r("settings.view.search.placeholder"),"aria-label":r("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),se&&s.jsx("button",{type:"button",onClick:()=>g(""),"aria-label":r("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:se?Y.length>0?(()=>{let ie=0;return ee.map(je=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:je.pageTitle}),je.results.map(be=>{const Te=ie;ie+=1;const Ue=Te===P,Pe=!!be.description;return s.jsxs("button",{type:"button",ref:we=>{F.current[Te]=we},onMouseMove:()=>{I.current=!1,k(Te)},onClick:()=>ge(be),className:ye("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Pe?"min-h-11 py-1.5":"py-2",Ue?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:be.title}),Pe&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:be.description})]},be.id)})]},je.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const ie=new Map;for(const be of ne){const Te=be.group,Ue=ie.get(Te);Ue?Ue.push(be):ie.set(Te,[be])}return bx.map(be=>({group:be,pages:ie.get(be)??[]})).filter(be=>be.pages.length>0).map(({group:be,pages:Te},Ue)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ye("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ue===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${be}`)}),Te.map(Pe=>{const we=N===Pe.slug&&!(p&&h==="nav"),Ge=Wd(Pe.slug);return!Ge&&Pe.slug!=="mcp"?null:s.jsx(wr,{children:s.jsx(jr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>$(Pe.slug),"aria-current":we?"page":void 0,className:ye("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",we?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Pe.slug==="mcp"?s.jsx(ud,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(R,{name:Ge,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:O(Pe.slug)}),Pe.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:r("settings.view.badge.beta")})]})]})})},Pe.slug)})]},be))})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!L.isVSCode||m>0)&&s.jsx(px,{})})})]})},Ve=()=>{if(h==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Sn,{children:$e()})})});if(!U)return s.jsx("div",{className:"flex-1 bg-background"});if(h==="page-sidebar"){if(U.kind!=="split"){const ie=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:ie})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:ae(N,{onItemSelect:oe})})})}const se=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:se})})},We=()=>!U||N==="home"?null:U.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("border-r",L.isVSCode?"bg-background":"bg-sidebar"),style:{width:ul,minWidth:ul,borderColor:"var(--interactive-border)"},children:s.jsx(Sn,{children:ae(N,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:te(N)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:te(N)})});return s.jsxs("div",{ref:f,"data-settings-view":"true",className:ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[p?s.jsxs("div",{className:ye("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",h!=="nav"&&"border-b","bg-background"),style:h!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ue?s.jsx("button",{type:"button",onClick:he,"aria-label":Se,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:h==="nav"?r("settings.view.home.title"):U?O(U.slug):r("settings.view.home.title")}),Ne&&s.jsx("button",{type:"button",onClick:Me,"aria-label":r("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"list-unordered",className:"h-5 w-5"})}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Oe,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ue&&s.jsx("div",{className:ye("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:he,"aria-label":r("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:ye("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Oe,className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:p?Ve():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",E?"bg-sidebar":L.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${dl}px`,minWidth:`${dl}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Sn,{children:$e()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:We()})]})})]})};export{Fl as A,Lx as S};
|