@aiworker/web 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/cli.js +14 -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-B1Gizi3a.js} +1 -1
- package/dist/assets/DiffView-DXjVsEOw.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-aig6zJjg.js +1 -0
- package/dist/assets/FilesView-CJdG0-wk.js +17 -0
- package/dist/assets/GitView-BXsS3jG6.js +6 -0
- package/dist/assets/{JsonTreeView-B0BdZEHG.js → JsonTreeView-D_hpXBnF.js} +1 -1
- package/dist/assets/LinearIssuesView-BoUiLQG1.js +1 -0
- package/dist/assets/MarkdownImageGallery-B_B_a9KS.js +1 -0
- package/dist/assets/MarkdownRendererImpl-xgyyLiBM.js +12 -0
- package/dist/assets/OnboardingScreen-DIp84OWt.js +1 -0
- package/dist/assets/{PatchDiff-DvfqDql7.js → PatchDiff-8p6nLJaU.js} +1 -1
- package/dist/assets/PierreDiffViewer-DjC8nTk9.js +161 -0
- package/dist/assets/PlanView-CJTmOF6I.js +5 -0
- package/dist/assets/SettingsView-DD-JqIJx.js +28 -0
- package/dist/assets/{SettingsWindow-i45U1Cy1.js → SettingsWindow-Cpb4hM6q.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-BTwyh5OF.js → ToolOutputDialog-DfaKZXNU.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-DtZLzrSK.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-DD8lDVej.js → VirtualizedFileDiff-C8i9HpTB.js} +1 -1
- package/dist/assets/WalkthroughView-DeKMvZlL.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-BMIRgMHv.js → computeVirtualFileMetrics-BBI7ZwrC.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
- package/dist/assets/de-DCrsQ5zS.js +10 -0
- package/dist/assets/es-Dwv4YfH6.js +16 -0
- package/dist/assets/fr-BCWg4Cnx.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/index-B68h5S5B.css +1 -0
- package/dist/assets/index-DVwMarHI.js +39 -0
- package/dist/assets/{index-CODwDsU_.js → index-jXSK5RrB.js} +1 -1
- package/dist/assets/{isDiffPlainText-BqayB8d3.js → isDiffPlainText-B_x_rVon.js} +1 -1
- package/dist/assets/{isFilePlainText-QfoiKJNY.js → isFilePlainText-DW_xMer1.js} +1 -1
- package/dist/assets/ja-Bruw3RYC.js +16 -0
- package/dist/assets/ko-idhXGF8j.js +16 -0
- package/dist/assets/main-BkyaQhJX.js +930 -0
- package/dist/assets/{main-C5DVOxc6.js → main-CzdPuL0s.js} +2 -2
- package/dist/assets/markdownCore-Cn4Tyejo.js +5 -0
- package/dist/assets/{miniChat-DUJ4irZc.js → miniChat-CCkqKOLp.js} +2 -2
- package/dist/assets/{mobile-CcaxB0n4.js → mobile-mvxTo055.js} +2 -2
- package/dist/assets/patchFileDiff-Csk4iNUi.js +13 -0
- package/dist/assets/pl-CGZWUqZJ.js +16 -0
- package/dist/assets/pt-BR-B8V7u7tA.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +2 -0
- package/dist/assets/renderMobileApp-B48CsP4r.js +25 -0
- package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +17 -0
- package/dist/assets/scheduledTasksApi-BW0Etzwz.js +1 -0
- package/dist/assets/{shikiHighlight-DYOWuY65.js → shikiHighlight-CRl0SUC9.js} +1 -1
- package/dist/assets/surface-oMvhsog3.js +1 -0
- package/dist/assets/tr-BK_KiO2V.js +7 -0
- package/dist/assets/uk-CG74xV8N.js +16 -0
- package/dist/assets/useAppFontEffects-CPKeOpUo.js +7284 -0
- package/dist/assets/useGitComparison-DH220WmO.js +1 -0
- package/dist/assets/useInlineCommentController-BiWz4AVb.js +2 -0
- package/dist/assets/useRootScrollLock-BS4-kr7P.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DFZik9R2.js → vendor-codemirror-language-data-Bg4AEeCr.js} +2 -2
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-Bhg83tjf.js → web-components-z7hfnS8n.js} +1 -1
- package/dist/assets/zh-CN-T4AXofZI.js +16 -0
- package/dist/assets/zh-TW-Dte40sxp.js +16 -0
- package/dist/index.html +21 -59
- package/dist/mini-chat.html +7 -7
- package/dist/mobile.html +5 -5
- package/package.json +3 -4
- package/server/index.d.ts +15 -0
- package/server/index.js +158 -89
- 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/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- 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 +18 -18
- package/server/lib/fs/DOCUMENTATION.md +5 -0
- package/server/lib/fs/routes.js +68 -26
- package/server/lib/fs/routes.test.js +208 -22
- package/server/lib/git/DOCUMENTATION.md +32 -6
- 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 +41 -5
- package/server/lib/git/service.js +300 -224
- package/server/lib/git/service.test.js +596 -28
- 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 +17 -10
- package/server/lib/inherited-env.test.js +10 -11
- 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 +161 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -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 +30 -6
- package/server/lib/opencode/auth.js +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +8 -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 +19 -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 +79 -19
- package/server/lib/opencode/openchamber-routes.test.js +139 -12
- 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 +19 -17
- 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-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +116 -44
- package/server/lib/opencode/settings-helpers.test.js +354 -12
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +141 -20
- package/server/lib/opencode/settings-runtime.test.js +191 -4
- 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/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +16 -1
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +144 -11
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +40 -2
- 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/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -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 +22 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +32 -1
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +3 -2
- package/server/lib/quota/providers/opencode-go.test.js +35 -6
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- 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 +56 -1
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +38 -9
- 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-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +69 -18
- 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 +15 -18
- 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 +91 -30
- 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 +7 -2
- package/server/lib/small-model/call.js +18 -7
- package/server/lib/small-model/call.test.js +58 -6
- package/server/lib/small-model/index.js +12 -16
- 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/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -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 +14 -10
- package/server/lib/terminal/runtime.js +190 -31
- package/server/lib/terminal/runtime.test.js +572 -38
- 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/DOCUMENTATION.md +33 -14
- 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 +11 -15
- package/server/lib/walkthrough/model-settings.test.js +1 -1
- package/server/lib/walkthrough/prompt.js +3 -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/sources.js +23 -2
- 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/DiffView-DluiRSla.js +0 -4
- 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/MarkdownImageGallery-ClOvuZxC.js +0 -1
- package/dist/assets/MarkdownRendererImpl-Dt9mjTRN.js +0 -12
- package/dist/assets/OnboardingScreen-D2DG7K6b.js +0 -1
- package/dist/assets/PierreDiffViewer-B7m3f0d7.js +0 -157
- 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/WalkthroughView-egQgxel3.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C3fjDbdg.js +0 -1
- package/dist/assets/de-C1P6X5Rs.js +0 -9
- package/dist/assets/es-CDgaF1_t.js +0 -15
- package/dist/assets/fr-Bgxqvvz_.js +0 -13
- package/dist/assets/index-C57jT0Sa.css +0 -1
- package/dist/assets/index-DW_E3rnL.js +0 -7
- package/dist/assets/ja-BDRrEcNP.js +0 -15
- package/dist/assets/ko-Ba8sQV79.js +0 -15
- package/dist/assets/main-Bv5Pkngh.js +0 -928
- package/dist/assets/markdownCore-CZwzz5gw.js +0 -3
- package/dist/assets/patchFileDiff-yNfWXN4E.js +0 -10
- package/dist/assets/pl-Dioz29BI.js +0 -15
- package/dist/assets/pt-BR-DIs6ElwV.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BcKLHXKe.js +0 -2
- package/dist/assets/renderMobileApp-D9yQJy0L.js +0 -25
- package/dist/assets/runtimeEndpointReset-CjhvxLH0.js +0 -16
- package/dist/assets/scheduledTasksApi-DLW0mkQK.js +0 -1
- package/dist/assets/tr-DFnMlPxY.js +0 -6
- package/dist/assets/uk-ZrCNjM7Y.js +0 -15
- package/dist/assets/useAppFontEffects-CjrntdL0.js +0 -7310
- package/dist/assets/useInlineCommentController-CDEuSlPH.js +0 -2
- package/dist/assets/useRootScrollLock-BHYPkrLv.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-iv_AV4EC.js +0 -15
- package/dist/assets/zh-TW-CzEUk38j.js +0 -15
- 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
|
@@ -1,928 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-egQgxel3.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-CjrntdL0.js","assets/index-DW_E3rnL.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-zod-BLfBSgBh.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-C57jT0Sa.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BeMD8X_w.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-C3fjDbdg.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-livSKyyV.js","assets/vendor-motion-dom-D_o3BTI3.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-DFZik9R2.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-gg7YLRW7.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-B7m3f0d7.js","assets/web-components-Bhg83tjf.js","assets/computeVirtualFileMetrics-BMIRgMHv.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-DD8lDVej.js","assets/isDiffPlainText-BqayB8d3.js","assets/vendor-diff-C3JhlQdm.js","assets/Virtualizer-D_a8gKmg.js","assets/useInlineCommentController-CDEuSlPH.js","assets/runtimeEndpointReset-CjhvxLH0.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-yNfWXN4E.js","assets/useRootScrollLock-BHYPkrLv.js","assets/scheduledTasksApi-DLW0mkQK.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-DluiRSla.js","assets/FilesView-Bdq8ppva.js","assets/shikiHighlight-DYOWuY65.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-B0BdZEHG.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-QfoiKJNY.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-B3u7UIcE.js","assets/GitView-Znn7VJcP.js","assets/CommitSection-SGBCAW0w.js","assets/LinearIssuesView-jP-hXyac.js","assets/PlanView-B0F3BtPZ.js","assets/SettingsWindow-i45U1Cy1.js","assets/SettingsView-BBW-S-gh.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/OnboardingScreen-D2DG7K6b.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{f as Xe,R as c,j as s,r as it,h as Mm}from"./vendor-react-BUCujlKS.js";import{z as pn,A as Uo,O as Ka,D as Om,B as Fm,C as nd,r as ds,o as Ko,u as De,E as Bm,F as Nn,G as _m,H as ct,I as qs,J as Ho,K as rd,L as od,v as Go,m as Zt,N as Rn,P as Fr,e as Mn,Q as Lm,a as Ss,R as $m,S as Wm,T as zm,U as id,n as dn,w as Qs,V as Vm,W as ad,X as Um,Y as ld,Z as Km,_ as nr,$ as fa,d as Po,a0 as Dr,a1 as ls,a2 as vi,a3 as Hm,a4 as Gm,i as qm,a5 as ho,a6 as po,a7 as Qm,a8 as Ha,a9 as Ym,aa as Xm,ab as Jm,ac as Zm,ad as Ga,ae as qa,af as Qa,ag as Ya,ah as ef,t as Xa,ai as tf,aj as sf,ak as nf,x as rf,y as of}from"./index-DW_E3rnL.js";import{_ as Bn}from"./vendor-vite-runtime-DD1OZmLC.js";import{f as pt,h as Te,b0 as $t,I as M,g as fn,t as Fe,b1 as Ys,b2 as Es,b3 as Xs,b4 as Js,L as Jn,V as An,b5 as _n,o as qo,b6 as Ja,a6 as gt,a7 as xt,a8 as bt,b as Vt,y as Qe,G as af,b7 as Jr,u as As,A as ha,C as cd,b8 as ji,b9 as lf,ba as dd,bb as ud,r as _s,bc as md,bd as pa,be as Qo,bf as fd,bg as hd,bh as cf,bi as Za,bj as df,bk as uf,bl as ga,bm as ki,bn as mf,bo as ff,K as pd,bp as hf,l as Ut,bq as pf,n as rr,br as gd,bs as gf,bt as xf,bu as bf,bv as yf,p as wf,bw as xd,bx as Sf,by as vf,bz as jf,bA as bd,bB as yd,bC as kf,av as xa,bD as Qn,bE as Gr,bF as Cf,bG as vs,bH as js,bI as Ls,bJ as Ds,bK as Ps,bL as gn,B as at,ao as Gs,bM as Nf,bN as Af,at as Cn,bO as go,bP as Hs,bQ as Yo,bR as wd,bS as Ci,bT as Df,bU as Ms,bV as Os,bW as Cs,bX as Fs,bY as es,S as jn,bZ as or,b_ as el,b$ as lr,M as Xo,ab as qr,ac as Pf,ad as ba,c0 as Sd,ae as vd,ag as On,c1 as Jo,c2 as kn,a1 as ya,c3 as If,c4 as Tf,an as Rf,c5 as Ef,c6 as Mf,c7 as Of,ap as wa,c8 as Sa,c9 as Tr,ca as jd,cb as Ff,cc as Bf,cd as Qr,ce as _f,O as kd,cf as Lf,cg as Ln,ch as $f,ci as Wf,cj as ri,ck as Cd,cl as Nd,cm as zf,au as Ni,cn as Ai,co as Vf,cp as tl,cq as Pr,c as Br,d as va,Z as Uf,cr as Ad,cs as wr,ct as Ir,cu as Kf,cv as Hf,cw as Gf,W as Dd,aq as qf,cx as Qf,cy as Yf,cz as Xf,cA as Jf,cB as Pd,cC as hn,cD as Zf,cE as Id,cF as eh,cG as Di,cH as th,cI as sh,cJ as Td,cK as nh,cL as Rd,$ as Io,cM as Pi,Q as ja,N as ka,R as Ca,cN as Na,a as Aa,_ as rh,cO as sl,cP as Ii,cQ as Ed,cR as oh,cS as Md,cT as ih,P as Ti,H as ah,cU as nl,cV as lh,cW as rl,cX as ch,cY as cs,cZ as dh,c_ as Fn,c$ as Da,d0 as Od,d1 as uh,d2 as Fd,d3 as Bd,d4 as mh,D as fh,d5 as hh,d6 as ph,d7 as gh,d8 as ol,d9 as xh,da as bh,db as _d,E as yh,dc as xo,dd as Ld,de as wh,df as Sh,dg as vh,dh as jh,e as $d,di as Pa,dj as kh,dk as _r,dl as Ch,dm as il,dn as Nh,dp as Ah,Y as Dh,dq as Ph,aH as Ri,a2 as al,aL as ll,a3 as cl,dr as Ih,J as Th,ds as Rh,dt as Eh,du as Mh,dv as Wd,dw as zd,dx as Vd,dy as Oh,F as Ia,dz as Fh,a0 as Bh,dA as _h,dB as Lh,dC as $h,dD as Wh,dE as zh,dF as Vh,dG as Uh,dH as Kh,dI as To,af as Hh,dJ as Gh,dK as dl,dL as qh,dM as Qh,dN as Yh,dO as Xh,dP as Ro,dQ as Jh,dR as ul,dS as Zh,dT as ep,dU as tp,dV as sp,dW as np,dX as rp,dY as bo,dZ as op,d_ as ip,i as ap,d$ as lp,e0 as cp,e1 as dp,e2 as up,a4 as mp,e3 as fp,e4 as hp,e5 as pp,e6 as gp,e7 as ml,e8 as xp,aB as bp,aC as yp,aD as wp,aF as fl,aG as hl,aJ as pl,aI as Ud,aK as Kd,e9 as Sp,aX as vp,aY as jp,aZ as kp,a_ as Cp,a$ as Np,aR as Ap,aT as Dp,aU as Pp,aV as Ip,aW as Tp}from"./useAppFontEffects-CjrntdL0.js";import{u as Hd,S as gl,C as Rp,W as Gd,f as Ep,a as Mp}from"./useRootScrollLock-BHYPkrLv.js";import{j as xl,k as qt,n as Op,l as bl,t as wn,m as Fp,o as oi,q as Bp,s as _p,U as qd,v as Ei,w as Mi,d as Qd,x as Yd,c as Lp,b as $p,y as Xd,z as Oi,A as Kn,B as Jd,E as Zd,P as Wp,T as zp,F as Vp,G as Up,H as Kp,S as yl,I as Hp,J as Gp,K as qp,u as Rr,N as Qp,D as Yp,W as Xp,L as wl,M as Jp,f as Zp,h as eu,i as eg,Q as tg,R as sg,V as ng,e as rg,g as og,O as tu,C as ig}from"./runtimeEndpointReset-CjhvxLH0.js";import{u as Wn,n as ag,f as lg,a as Sl,s as cg,d as dg,b as ug,r as mg}from"./scheduledTasksApi-DLW0mkQK.js";import{f as Lr,h as En,T as su,M as nu,D as $r,j as Wr,d as fg,P as Fi,b as hg,k as Bi,i as pg}from"./vendor-dnd-kit-core-BZknOX2w.js";import{u as Zo,S as Eo,h as gg,a as ru,v as _i,s as xg}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as ei}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{S as ou,M as iu,C as au,a as Li,b as $i,c as Wi,d as lu,e as bg,f as yg}from"./vendor-base-ui-BeMD8X_w.js";import{c as Zn,u as Xn,d as cu,p as wg}from"./vendor-zustand-BAGL70zf.js";import{g as Sg,b as vg,E as du,c as jg,d as kg,e as Cg,f as Ng,i as Ag}from"./contextPanelEmbeddedChat-C3fjDbdg.js";import{a as Ta,s as gr,r as uu}from"./vendor-zod-BLfBSgBh.js";import{u as Dg}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{d as mu}from"./vendor-cron-parser-CUcP7OfX.js";const Pg="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",Ig="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",ii=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__AIWORKER_PLATFORM__==="darwin"?Pg:t.id==="terminal"?Ig:void 0}),vl=t=>{const e=Xe.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[o,l]=c.useState(!1);let a;e[0]!==n?(a=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=a):a=e[1];const u=a,d=r||i;if(d&&!o){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>l(!0),e[2]=g):g=e[2];let p;return e[3]!==d?(p=s.jsx("img",{src:d,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=d,e[4]=p):p=e[4],p}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=Te("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:h,children:u}),e[6]=u,e[7]=f):f=e[7],f},Tg=t=>{const e=Xe.c(75),{directory:n,className:r}=t,{t:i}=pt(),o=Wn(Rg),l=Wn(Eg),a=Wn(Mg),u=Wn(Og),d=Wn(Fg),h=Wn(Bg),f=Wn(_g);let g,p;e[0]!==d?(g=()=>{d()},p=[d],e[0]=d,e[1]=g,e[2]=p):(g=e[1],p=e[2]),c.useEffect(g,p);const w=pn()&&Uo();let v;e:{let L;e[3]!==l||e[4]!==o?(L=l.find(ue=>ue.id===o)??l.find(Lg)??l[0]??Ka[0],e[3]=l,e[4]=o,e[5]=L):L=e[5];const le=L;if(le){let ue;e[6]!==le?(ue=ii(le),e[6]=le,e[7]=ue):ue=e[7],v=ue;break e}let Z;e[8]===Symbol.for("react.memo_cache_sentinel")?(Z=ii(Ka[0]),e[8]=Z):Z=e[8],v=Z}const x=v;if(!w||!n||l.length===0)return null;let m;e[9]!==n?(m=async L=>{await Fm(n,L.id,L.appName)||await nd(n,L.appName)},e[9]=n,e[10]=m):m=e[10];const b=m;let y;e[11]!==b||e[12]!==f?(y=async L=>{await f(L.id),await b(L)},e[11]=b,e[12]=f,e[13]=y):y=e[13];const S=y;let N;e[14]!==n||e[15]!==i?(N=async()=>{(await fn(n)).ok&&Fe.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=N):N=e[16];const C=N;let k;e[17]!==r?(k=Te("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=k):k=e[18];let A;e[19]!==b||e[20]!==x?(A=()=>{b(x)},e[19]=b,e[20]=x,e[21]=A):A=e[21];const D=u&&"animate-pulse";let P;e[22]!==D?(P=Te("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",D),e[22]=D,e[23]=P):P=e[23];let F;e[24]!==x.label||e[25]!==i?(F=i("openInApp.actions.openInAria",{app:x.label}),e[24]=x.label,e[25]=i,e[26]=F):F=e[26];let W;e[27]!==x.fallbackIconDataUrl||e[28]!==x.iconDataUrl||e[29]!==x.label?(W=s.jsx(vl,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[27]=x.fallbackIconDataUrl,e[28]=x.iconDataUrl,e[29]=x.label,e[30]=W):W=e[30];let E;e[31]!==P||e[32]!==F||e[33]!==W||e[34]!==A?(E=s.jsx("button",{type:"button",onClick:A,className:P,"aria-label":F,children:W}),e[31]=P,e[32]=F,e[33]=W,e[34]=A,e[35]=E):E=e[35];let H;e[36]===Symbol.for("react.memo_cache_sentinel")?(H=Te("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=H):H=e[36];let z;e[37]!==i?(z=i("openInApp.actions.chooseAppAria"),e[37]=i,e[38]=z):z=e[38];let B;e[39]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(M,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=B):B=e[39];let T;e[40]!==z?(T=s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:H,"aria-label":z,children:B})}),e[40]=z,e[41]=T):T=e[41];let j;e[42]!==C?(j=()=>{C()},e[42]=C,e[43]=j):j=e[43];let I;e[44]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(M,{name:"file-copy",className:"h-4 w-4"}),e[44]=I):I=e[44];let _;e[45]!==i?(_=i("openInApp.actions.copyPath"),e[45]=i,e[46]=_):_=e[46];let K;e[47]!==_?(K=s.jsx("span",{className:"typography-ui-label text-foreground",children:_}),e[47]=_,e[48]=K):K=e[48];let G;e[49]!==j||e[50]!==K?(G=s.jsxs($t,{className:"flex items-center gap-2",onClick:j,children:[I,K]}),e[49]=j,e[50]=K,e[51]=G):G=e[51];let Q;e[52]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Es,{}),e[52]=Q):Q=e[52];let ge;if(e[53]!==l||e[54]!==S||e[55]!==x.id){let L;e[57]!==S||e[58]!==x.id?(L=le=>{const Z=ii(le);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{S(le)},children:[s.jsx(vl,{label:le.label,iconDataUrl:le.iconDataUrl,fallbackIconDataUrl:Z.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:le.label}),x.id===le.id?s.jsx(M,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},le.id)},e[57]=S,e[58]=x.id,e[59]=L):L=e[59],ge=l.map(L),e[53]=l,e[54]=S,e[55]=x.id,e[56]=ge}else ge=e[56];let se;e[60]!==a||e[61]!==h||e[62]!==i?(se=a?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{h(!0)},children:[s.jsx(M,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[60]=a,e[61]=h,e[62]=i,e[63]=se):se=e[63];let Y;e[64]!==G||e[65]!==ge||e[66]!==se?(Y=s.jsxs(Xs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[G,Q,ge,se]}),e[64]=G,e[65]=ge,e[66]=se,e[67]=Y):Y=e[67];let te;e[68]!==T||e[69]!==Y?(te=s.jsxs(Js,{children:[T,Y]}),e[68]=T,e[69]=Y,e[70]=te):te=e[70];let he;return e[71]!==E||e[72]!==te||e[73]!==k?(he=s.jsxs("div",{className:k,children:[E,te]}),e[71]=E,e[72]=te,e[73]=k,e[74]=he):he=e[74],he};function Rg(t){return t.selectedAppId}function Eg(t){return t.availableApps}function Mg(t){return t.isCacheStale}function Og(t){return t.isScanning}function Fg(t){return t.initialize}function Bg(t){return t.loadInstalledApps}function _g(t){return t.selectApp}function Lg(t){return t.id===Om}const Mo=new Map,zi=new Set,fu=()=>{for(const t of zi)t()},ai=(t,e)=>{const n=t.trim();n&&(e.length===0?Mo.delete(n):Mo.set(n,[...e]),fu())},$g=t=>{Mo.delete(t.trim())&&fu()},hu=[],Wg=t=>Mo.get(t.trim())??hu,zg=t=>(zi.add(t),()=>{zi.delete(t)}),Vg=t=>{const e=Xe.c(2);let n;return e[0]!==t?(n=()=>Wg(t),e[0]=t,e[1]=n):n=e[1],c.useSyncExternalStore(zg,n,Ug)};function Ug(){return hu}const Kg=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Hg=["dev","start","preview","serve"];async function Gg(t,e,n){if(!t)return null;const r=Yg(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const i=Xg(n);if(i){const o=await Jg(t);return{command:`${o==="npm"?"npm run":o==="yarn"?"yarn":o==="pnpm"?"pnpm":o==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await qg(t)){const i=await Qg(),o=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${o}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${o}/`}}return null}async function qg(t){const e=`${t}/index.html`,n=await Oo(e,t);return typeof n=="string"&&n.trim().length>0}async function Qg(){try{const t=await ds("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Yg(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Hg.some(i=>n.includes(i)))return e}return null}function Xg(t){for(const{pattern:e}of Kg)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Jg(t){const e=await Oo(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,i]of n){const o=await Oo(`${t}/${r}`,t);if(typeof o=="string"&&o.trim().length>0)return i}return"npm"}async function Oo(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),i=await ds(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(i.ok)return i.text()}catch{}const n=Ko()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await ds(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Zg(t){try{const e=await Oo(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const ex=(t,e,n)=>new Promise(r=>{let i=!1,o=null,l=null;const a=u=>{i||(i=!0,l&&clearTimeout(l),o?.close(),r(u))};o=t.connect(e,{onEvent:u=>{(u.type==="exit"||u.type==="snapshot"&&u.status==="exited")&&a(!0)},onError:(u,d)=>{d&&a(!0)}}),i?o.close():l=setTimeout(()=>a(!1),n)}),Us="__aiworker_auto_discover_preview__",tx=15e3,sx=3e3,nx=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},rx=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},ox=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:o}=pt(),{currentTheme:l}=Jn(),{terminal:a,runtime:u}=An(),{isMobile:d}=_n(),h=c.useMemo(()=>pn(),[]),f=xl(q=>q.instances),g=xl(q=>q.load),p=De(q=>q.terminalShell),w=De(q=>q.terminalLoginShells.includes(q.terminalShell)),v=De(q=>q.setSettingsPage),x=De(q=>q.setSettingsDialogOpen),m=De(q=>q.setSettingsProjectsSelectedId),b=De(q=>q.openContextPreview),y=qt(q=>q.ensureDirectory),S=qt(q=>q.setTabLabel),N=qt(q=>q.setTabIconKey),C=qt(q=>q.setActiveTab),k=qt(q=>q.setConnecting),A=qt(q=>q.setTabSessionId),D=qt(q=>q.setTabPreviewUrl),P=qt(q=>q.projectActionRuns),F=qt(q=>q.setProjectActionRun),W=qt(q=>q.updateProjectActionRunStatus),E=qt(q=>q.removeProjectActionRun),[H,z]=c.useState([]),[B,T]=c.useState(null),[j,I]=c.useState(!1),_=c.useRef({}),K=c.useRef({}),G=c.useRef({}),Q=c.useRef({}),ge=c.useRef(new Set),se=c.useRef(0),Y=t?.id??null,te=t?.path??"",he=c.useMemo(()=>Y?{id:Y,path:te}:null,[Y,te]);c.useEffect(()=>{h&&g().catch(()=>{})},[h,g]);const L=c.useCallback(async q=>{await qo(q)},[]),le=c.useCallback(async()=>{if(!he)return;const q=se.current+1;se.current=q,I(!0);try{const Ee=await Ja(he);if(se.current!==q)return;const Me=Ee.actions;z(Me),T(O=>O===Us||O&&Me.some(oe=>oe.id===O)?O:null)}catch{if(se.current!==q)return}finally{se.current===q&&I(!1)}},[he]),Z=c.useMemo(()=>Op(e||he?.path||""),[e,he?.path]),ue=c.useMemo(()=>B?H.find(q=>q.id===B)??null:null,[H,B]),V=c.useMemo(()=>({id:Us,name:o("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[o]),ee=!d,be=c.useMemo(()=>ee?[V,...H]:H,[H,V,ee]);c.useEffect(()=>{le()},[le]),c.useEffect(()=>{if(typeof window>"u")return;const q=Ee=>{const Me=Ee.detail;Y&&(Me?.projectId&&Me.projectId!==Y||le())};return window.addEventListener(bl,q),()=>{window.removeEventListener(bl,q)}},[le,Y]),c.useEffect(()=>{B&&(B===Us&&ee||H.some(q=>q.id===B)||T(null))},[H,ee,B]),c.useEffect(()=>{const q=Me=>{delete Q.current[Me];const O=K.current[Me];if(!O||O.openedUrl)return;const oe=qt.getState(),re=oe.projectActionRuns[Me];if(!re)return;const we=O.announced;if(we.length!==0){if(O.openedUrl=!0,oe.updateProjectActionRunStatus(Me,"running"),we.length===1){ai(re.directory,[]),D(re.directory,re.tabId,we[0],{locked:!1,autoOpened:!0}),b(re.directory,we[0]);return}O.offering=!0,ai(re.directory,we),De.getState().openContextSurface(re.directory,"browser"),Fe.info(o("projectActions.toast.multipleServers"))}},Ee=()=>{const Me=qt.getState(),O=Me.sessions,oe=Me.projectActionRuns;for(const[re,we]of Object.entries(oe)){const st=O.get(we.directory)?.tabs.find(qe=>qe.id===we.tabId);if(!st||st.terminalSessionId!==we.sessionId){E(re);continue}const Ge=K.current[re]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1,announced:[],offering:!1};K.current[re]=Ge;const ae=be.find(qe=>qe.id===we.actionId),X=Me.getBuffer(we.directory,we.tabId).chunks;if(!ae||X.length===0)continue;const ve=X.filter(qe=>Ge.lastSeenChunkId===null||qe.id>Ge.lastSeenChunkId);if(ve.length===0)continue;const Le=ve.map(qe=>qe.data).join(""),$e=`${Ge.tail}${Le}`;if(Ge.openInPreview&&(!Ge.openedUrl||Ge.offering)){const qe=Bp($e),nt=Ge.announced.length;for(const vt of qe)Ge.announced.includes(vt)||Ge.announced.push(vt);const yt=Ge.announced.length-nt;Ge.offering&&yt>0?ai(we.directory,Ge.announced):!Ge.openedUrl&&nt===0&&Ge.announced.length>0&&(window.clearTimeout(Q.current[re]),Q.current[re]=window.setTimeout(()=>q(re),sx))}const Ue=!Ge.openedUrl&&ae.autoOpenUrl===!0&&!Ge.openInPreview?_p($e):null,We=ve[ve.length-1]?.id??Ge.lastSeenChunkId;if(Ge.lastSeenChunkId=We,Ge.tail=$e.slice(-512),Ue)if(Ge.openedUrl=!0,Ge.openInPreview){const qe=oe[re];qe&&(D(qe.directory,qe.tabId,Ue,{locked:!1,autoOpened:!1}),qe.status==="waiting-for-preview"&&W(re,"running"),window.clearTimeout(Q.current[re]),delete Q.current[re],b(qe.directory,Ue))}else L(Ue),Fe.success(o("projectActions.toast.openedUrlFromOutput"));K.current[re]=Ge}for(const re of Object.keys(K.current))oe[re]||(delete K.current[re],window.clearTimeout(Q.current[re]),delete Q.current[re])};return Ee(),qt.subscribe((Me,O)=>{(Me.sessions!==O.sessions||Me.buffers!==O.buffers)&&Ee()})},[be,b,L,P,E,D,o,W]);const xe=c.useCallback(async(q,Ee={})=>{if(!Z)throw new Error(o("projectActions.error.noActiveDirectory"));const Me=wn(Z,q.id);y(Z);const O=qt.getState(),oe=O.getDirectoryState(Z);let re=_.current[Me]||null;const we=re?!!oe?.tabs.some(Ge=>Ge.id===re):!1;(!re||!we)&&(re=O.createTab(Z),_.current[Me]=re),S(Z,re,`Action: ${q.name}`),N(Z,re,q.icon||"play"),C(Z,re),Ee.revealTerminal!==!1&&De.getState().openContextPanelTab(Z,{mode:"terminal"});const st=qt.getState().getDirectoryState(Z)?.tabs.find(Ge=>Ge.id===re);return{key:Me,tabId:re,sessionId:st?.terminalSessionId??null}},[y,Z,C,N,S,o]),Ne=c.useCallback(async q=>{if(u.isVSCode||!i&&d)return;if(!Z){Fe.error(o("projectActions.error.noActiveDirectoryForAction"));return}const Ee=wn(Z,q.id),Me=P[Ee];if(!(Me&&Me.status==="running")&&!ge.current.has(Ee)){ge.current.add(Ee);try{const O=q.id===Us?await(async()=>{const[Ue,We]=await Promise.all([Ja({id:he?.id??"",path:Z}),Zg(Z)]),qe=await Gg(Z,Ue.actions,We);if(!qe)throw new Error(o("contextPanel.preview.noDevServer"));return{id:Us,name:o("projectActions.actions.autoDiscover"),command:qe.command,icon:"scan-2",autoOpenUrl:!0,openUrl:qe.previewUrlHint||""}})():q,oe=O.autoOpenUrl===!0&&(O.openUrl||"").trim().length>0,re=!oe&&q.id!==Us,{key:we,tabId:Ve,sessionId:st}=await xe(O,{revealTerminal:re});let Ge=st;if(!Ge){k(Z,Ve,!0);try{Ge=(await a.createSession({cwd:Z,sessionId:Ve,shell:p,loginShell:w,themeMode:l.metadata.variant==="light"?"light":"dark",terminalBackground:l.colors.surface.background,terminalForeground:l.colors.syntax.base.foreground})).sessionId,A(Z,Ve,Ge)}finally{k(Z,Ve,!1)}}if(!Ge)throw new Error(o("projectActions.error.failedToCreateTerminalSession"));G.current[we]?.(),k(Z,Ve,!0);const ae=a.connect(Ge,{onEvent:Ue=>{Ue.type==="snapshot"&&(qt.getState().replaceBuffer(Z,Ve,Ue.data??"",Ue.sequence??0),qt.getState().setConnecting(Z,Ve,!1)),Ue.type==="data"&&typeof Ue.data=="string"&&Ue.data.length>0&&qt.getState().appendToBuffer(Z,Ve,Ue.data,Ue.sequence,Ue.replayData),Ue.type==="exit"&&(qt.getState().setTabLifecycle(Z,Ve,"exited"),qt.getState().setConnecting(Z,Ve,!1),qt.getState().removeProjectActionRun(we),delete K.current[we],G.current[we]?.(),delete G.current[we],window.clearTimeout(Q.current[we]),delete Q.current[we])},onError:(Ue,We)=>{qt.getState().setConnecting(Z,Ve,!1),We&&(qt.getState().setTabLifecycle(Z,Ve,"exited"),qt.getState().setTabSessionId(Z,Ve,null),qt.getState().removeProjectActionRun(we))}});G.current[we]=ae.close;const X=O.autoOpenUrl===!0&&h&&(O.desktopOpenSshForward||"").trim().length>0,ve=O.autoOpenUrl?rx(O.openUrl):null,Le=O.autoOpenUrl&&h?Fp(O.desktopOpenSshForward,f):null;F({key:we,directory:Z,actionId:O.id,tabId:Ve,sessionId:Ge,status:O.id===Us&&!ve?"waiting-for-preview":"running"}),window.clearTimeout(Q.current[we]),delete Q.current[we],O.id===Us&&!ve&&(Q.current[we]=window.setTimeout(()=>{const Ue=qt.getState(),We=Ue.projectActionRuns[we];Ue.updateProjectActionRunStatus(we,"running"),We&&(Ue.setActiveTab(We.directory,We.tabId),De.getState().openContextPanelTab(We.directory,{mode:"terminal"})),delete Q.current[we]},tx)),K.current[we]={lastSeenChunkId:null,openedUrl:!!Le||!!ve||oe,tail:"",openInPreview:O.id===Us,announced:[],offering:!1};const $e=nx(O.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await a.sendInput(Ge,`${$e}\r`),Le?(D(Z,Ve,null,{locked:!0}),L(Le),Fe.success(o("projectActions.toast.openedForwardedUrl"))):ve?(D(Z,Ve,ve,{locked:!0,autoOpened:!0}),b(Z,ve),Fe.success(o("projectActions.toast.openedActionUrl"))):oe?(D(Z,Ve,null,{locked:!0}),Fe.error(o("projectActions.error.invalidCustomUrlFormat"))):X?(D(Z,Ve,null,{locked:!0}),Fe.error(o("projectActions.error.selectedDesktopSshForwardUnavailable"))):D(Z,Ve,null,{locked:!1,autoOpened:!1})}catch(O){E(Ee),delete K.current[Ee],G.current[Ee]?.(),delete G.current[Ee],window.clearTimeout(Q.current[Ee]),delete Q.current[Ee],Fe.error(O instanceof Error?O.message:o("projectActions.error.failedToRunAction"))}finally{ge.current.delete(Ee)}}},[l.colors.surface.background,l.colors.syntax.base.foreground,l.metadata.variant,f,xe,i,d,h,Z,w,p,L,b,P,u.isVSCode,E,k,F,D,A,he?.id,o,a]),Pe=c.useCallback(async q=>{const Ee=wn(Z,q.id),Me=P[Ee];if(!Me)return;W(Ee,"stopping");const O=ex(a,Me.sessionId,1e3);try{await a.sendInput(Me.sessionId,"")}catch{}const oe=await O;if(qt.getState().getDirectoryState(Me.directory)?.tabs.find(Ve=>Ve.id===Me.tabId)?.terminalSessionId===Me.sessionId&&!oe){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:Me.sessionId})}catch{}else try{await a.close(Me.sessionId)}catch{}A(Me.directory,Me.tabId,null)}E(Ee),delete K.current[Ee],G.current[Ee]?.(),delete G.current[Ee],window.clearTimeout(Q.current[Ee]),delete Q.current[Ee]},[Z,P,E,A,a,W]),Se=c.useCallback(()=>{const q=ue??be[0];if(!q)return;const Ee=wn(Z,q.id),Me=P[Ee];if(Me?.status!=="stopping"){if(Me){Pe(q);return}Ne(q)}},[be,Z,Ne,P,ue,Pe]),Re=c.useCallback((q,Ee=!1)=>{if(T(q.id),!Ee){Ne(q);return}const Me=wn(Z,q.id),O=P[Me];if(O?.status!=="stopping"){if(O){Pe(q);return}Ne(q)}},[Z,Ne,P,Pe]),ye=c.useCallback(()=>{he?.id&&(m(he.id),v("projects"),x(!0))},[x,v,m,he?.id]),pe=ue??be[0]??null,me=pe?P[wn(Z,pe.id)]:null,je=qt(q=>me?q.sessions.get(me.directory)?.tabs.find(Ee=>Ee.id===me.tabId)?.previewUrl??null:null);if(u.isVSCode||!i&&d||!he||!Z)return null;const ne=ue??be[0]??null;if(!ne)return null;const fe=ne.icon||"play",ce=ne.id===Us?"scan-2":oi[fe]||"play",R=wn(Z,ne.id),$=P[R],de=$?.status==="stopping",ie=$?.status==="waiting-for-preview",Ae=!!($&&je),Be=()=>{!$||!je||b($.directory,je)},Ce=ne.id===Us;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:j||de,className:Te("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:Se,"aria-label":$?o("projectActions.actions.stopNamedAria",{name:ne.name}):o("projectActions.actions.runNamedAria",{name:ne.name}),children:de||ie?s.jsx(M,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):$?s.jsx(M,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(M,{name:ce,className:"h-5 w-5"})})}),Ce?s.jsx(bt,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),Ae?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("projectActions.actions.openPreview"),onClick:Be,children:s.jsx(M,{name:"global",className:"h-4 w-4"})})}),s.jsx(bt,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Js,{children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Xs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ye,children:[s.jsx(M,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Es,{}),be.map(q=>{const Ee=q.icon||"play",Me=q.id===Us?"scan-2":oi[Ee]||"play",O=wn(Z,q.id),oe=P[O],re=!!oe,we=oe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Re(q,!0)},children:[s.jsx(M,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),we||oe?.status==="waiting-for-preview"?s.jsx(M,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):re?s.jsx(M,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]}):s.jsxs("div",{className:Te("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Se,disabled:j||de,className:Te("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":$?o("projectActions.actions.stopNamedAria",{name:ne.name}):o("projectActions.actions.runNamedAria",{name:ne.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:de||ie?s.jsx(M,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):$?s.jsx(M,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(M,{name:ce,className:"h-4 w-4"})})})}),Ce?s.jsx(bt,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),Ae?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be,className:Te(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":o("projectActions.actions.openPreview"),children:s.jsx(M,{name:"global",className:"h-4 w-4"})})}),s.jsx(bt,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(Js,{children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:Te(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(M,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Xs,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ye,children:[s.jsx(M,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Es,{}),be.map(q=>{const Ee=q.icon||"play",Me=q.id===Us?"scan-2":oi[Ee]||"play",O=wn(Z,q.id),oe=P[O],re=!!oe,we=oe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Re(q,!0)},children:[s.jsx(M,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),we||oe?.status==="waiting-for-preview"?s.jsx(M,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):re?s.jsx(M,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]})},Zr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function ix(){const t=Vt(f=>f.activeProjectId?f.projects.find(g=>g.id===f.activeProjectId)??null:null),e=Qe(f=>f.currentSessionId),n=af(e??null),r=Qe(f=>e?f.worktreeMetadata.get(e)?.path??"":""),i=Qe(f=>f.newSessionDraft?.open?Zr(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),o=c.useMemo(()=>Zr(r||""),[r]),l=c.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return Zr(f||"")},[n?.directory]),a=o||l||i,u=c.useMemo(()=>Zr(a||t?.path||""),[t?.path,a]),d=c.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),h=c.useRef(null);return c.useEffect(()=>{d&&u&&(h.current={projectRef:d,directory:u})},[u,d]),c.useMemo(()=>d&&u?{projectRef:d,directory:u}:h.current,[d,u])}const ax=({transform:t})=>({...t,y:0}),lx={Item:$t,Separator:Es},cx={Item:({className:t,...e})=>s.jsx(iu,{className:Te(ud,t),...e}),Separator:({className:t,...e})=>s.jsx(ou,{className:Te(dd,t),...e})},dx=t=>{const e=Xe.c(62),{tab:n,isActive:r,suppressControls:i,onSelect:o,onClose:l,renderMenu:a,closeOtherTabs:u,onMenuOpenChangeComplete:d,children:h}=t,{t:f}=pt(),[g,p]=c.useState(!1),[w,v]=c.useState(!1),[x,m]=c.useState(!1);let b;e[0]!==n.id?(b={id:n.id},e[0]=n.id,e[1]=b):b=e[1];const{attributes:y,listeners:S,setNodeRef:N,transform:C,transition:k,isDragging:A}=Zo(b);let D;e[2]!==f||e[3]!==n.session.title?(D=n.session.title?.trim()||f("sessions.sidebar.session.untitled"),e[2]=f,e[3]=n.session.title,e[4]=D):D=e[4];const P=D,F=!i&&(g||w),W=ha(n.id),E=W?.type==="busy"||W?.type==="retry",z=cd(n.id)>0&&!r&&!E,B=E||z;let T;e[5]!==E||e[6]!==f?(T=f(E?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),e[5]=E,e[6]=f,e[7]=T):T=e[7];const j=T;let I;e[8]!==u||e[9]!==r||e[10]!==o||e[11]!==n?(I=be=>({session:n.session,isActive:r,select:()=>o(n),closeOtherTabs:()=>u(n.id),components:be}),e[8]=u,e[9]=r,e[10]=o,e[11]=n,e[12]=I):I=e[12];const _=I;let K;e[13]!==C?(K=ei.Translate.toString(C),e[13]=C,e[14]=K):K=e[14];let G;e[15]!==K||e[16]!==k?(G={transform:K,transition:k},e[15]=K,e[16]=k,e[17]=G):G=e[17];const Q=A&&"z-10 opacity-60";let ge;e[18]!==Q?(ge=Te("session-tab-slot flex h-7 w-44 shrink-0 touch-none",Q),e[18]=Q,e[19]=ge):ge=e[19];const se=r?"true":"false";let Y;e[20]!==r?(Y=r?{"data-active-session-tab":!0}:{},e[20]=r,e[21]=Y):Y=e[21];let te;e[22]!==d?(te=be=>d?.(be),e[22]=d,e[23]=te):te=e[23];let he;e[24]!==h||e[25]!==j||e[26]!==r||e[27]!==E||e[28]!==_||e[29]!==g||e[30]!==l||e[31]!==d||e[32]!==o||e[33]!==F||e[34]!==a||e[35]!==B||e[36]!==i||e[37]!==f||e[38]!==n||e[39]!==P?(he=s.jsx(au,{render:be=>s.jsxs("div",{...be,role:"tab","aria-selected":r,tabIndex:r?void 0:0,onClick:r?void 0:()=>o(n),onKeyDown:r?void 0:xe=>{(xe.key==="Enter"||xe.key===" ")&&(xe.preventDefault(),o(n))},onAuxClick:xe=>{xe.button===1&&(xe.preventDefault(),l(n.id))},"data-controls-open":F?"true":"false",className:Te("session-tab group/session-tab relative flex h-7 w-full min-w-0 select-none items-center rounded-md px-2",r?"bg-interactive-selection":Te("cursor-pointer text-muted-foreground hover:bg-interactive-hover hover:text-foreground",F&&"bg-interactive-hover text-foreground")),children:[s.jsxs("div",{className:Te("flex min-w-0 flex-1 items-center",!i&&"group-hover/session-tab:pr-10",F&&"pr-10"),children:[s.jsx("div",{className:Te("min-w-0 flex-1 overflow-hidden whitespace-nowrap",!i&&"session-tab-title"),children:r?h:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:s.jsx("span",{className:"block max-w-full overflow-hidden whitespace-nowrap text-[13px] font-medium leading-4",children:P})})}),B?s.jsx("span",{className:Te("ml-1.5 h-1.5 w-1.5 shrink-0 rounded-full",E?"bg-primary":"bg-[var(--status-info)]",!i&&"group-hover/session-tab:opacity-0",F&&"opacity-0"),"aria-label":j}):null]}),i?null:s.jsxs("div",{onClick:mx,onPointerDown:fx,className:Te("absolute right-1 top-1/2 hidden -translate-y-1/2 items-center gap-0.5","opacity-0 transition-opacity duration-150","group-hover/session-tab:flex group-hover/session-tab:opacity-100",F&&"flex opacity-100"),children:[s.jsxs(Js,{open:g,onOpenChange:xe=>{p(xe),xe&&v(!0)},onOpenChangeComplete:xe=>{xe||v(!1),d?.(xe)},children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f("header.sessionTabs.tabMenuAria"),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"more",className:"size-4"})})}),s.jsx(Xs,{align:"start",className:"min-w-[190px]",children:a(_(lx))})]}),s.jsx("button",{type:"button","aria-label":f("header.sessionTabs.closeTab"),onClick:()=>l(n.id),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"size-4"})})]})]})}),e[24]=h,e[25]=j,e[26]=r,e[27]=E,e[28]=_,e[29]=g,e[30]=l,e[31]=d,e[32]=o,e[33]=F,e[34]=a,e[35]=B,e[36]=i,e[37]=f,e[38]=n,e[39]=P,e[40]=he):he=e[40];let L,le;e[41]===Symbol.for("react.memo_cache_sentinel")?(L={color:"var(--surface-elevated-foreground)"},le=Te(ji,"min-w-[190px]"),e[41]=L,e[42]=le):(L=e[41],le=e[42]);let Z;e[43]!==_||e[44]!==a?(Z=a(_(cx)),e[43]=_,e[44]=a,e[45]=Z):Z=e[45];let ue;e[46]!==Z?(ue=s.jsx(Li,{children:s.jsx($i,{className:"app-region-no-drag z-50",children:s.jsx(Wi,{"data-slot":"dropdown-menu-content",style:L,className:le,children:Z})})}),e[46]=Z,e[47]=ue):ue=e[47];let V;e[48]!==x||e[49]!==te||e[50]!==he||e[51]!==ue?(V=s.jsxs(lu,{open:x,onOpenChange:m,onOpenChangeComplete:te,children:[he,ue]}),e[48]=x,e[49]=te,e[50]=he,e[51]=ue,e[52]=V):V=e[52];let ee;return e[53]!==y||e[54]!==S||e[55]!==N||e[56]!==Y||e[57]!==V||e[58]!==G||e[59]!==ge||e[60]!==se?(ee=s.jsx("div",{ref:N,style:G,className:ge,"data-active":se,...Y,...y,...S,children:V}),e[53]=y,e[54]=S,e[55]=N,e[56]=Y,e[57]=V,e[58]=G,e[59]=ge,e[60]=se,e[61]=ee):ee=e[61],ee},ux=t=>{const e=Xe.c(64),{renderMenu:n,onMenuOpenChangeComplete:r,suppressActiveTabControls:i,children:o}=t,l=i===void 0?!1:i,{t:a}=pt(),u=Jr(hx),d=Jr(px),h=Jr(gx),f=Jr(xx),g=Qe(bx),p=Qe(yx),w=As(wx);let v,x;e[0]!==g||e[1]!==d?(v=()=>{g&&d(g)},x=[g,d],e[0]=g,e[1]=d,e[2]=v,e[3]=x):(v=e[2],x=e[3]),c.useEffect(v,x);let m;if(e[4]!==w){m=new Map;for(const Se of w)m.set(Se.id,Se);e[4]=w,e[5]=m}else m=e[5];const b=m;let y;if(e[6]!==b||e[7]!==u){y=[];for(const Se of u){const Re=b.get(Se);Re&&y.push({id:Se,session:Re})}e[6]=b,e[7]=u,e[8]=y}else y=e[8];const S=y;let N;e[9]!==p?(N=Se=>{p(Se.id,_s(Se.session))},e[9]=p,e[10]=N):N=e[10];const C=N,k=Sx;let A;e[11]!==h||e[12]!==g||e[13]!==C||e[14]!==S?(A=Se=>{if(h(Se),g&&g!==Se){const Re=S.find(ye=>ye.id===Se);Re&&C(Re)}},e[11]=h,e[12]=g,e[13]=C,e[14]=S,e[15]=A):A=e[15];const D=A;let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P={activationConstraint:{distance:8}},e[16]=P):P=e[16];let F;e[17]===Symbol.for("react.memo_cache_sentinel")?(F={activationConstraint:{delay:200,tolerance:6}},e[17]=F):F=e[17];const W=Lr(En(nu,P),En(su,F));let E;e[18]!==f?(E=Se=>{const{active:Re,over:ye}=Se;ye&&Re.id!==ye.id&&f(String(Re.id),String(ye.id))},e[18]=f,e[19]=E):E=e[19];const H=E,z=c.useRef(null);let B;e[20]===Symbol.for("react.memo_cache_sentinel")?(B={left:!1,right:!1},e[20]=B):B=e[20];const[T,j]=c.useState(B);let I;e[21]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{const Se=z.current;if(!Se)return;const Re=Se.scrollLeft>2,ye=Se.scrollLeft+Se.clientWidth<Se.scrollWidth-2;j(pe=>pe.left===Re&&pe.right===ye?pe:{left:Re,right:ye})},e[21]=I):I=e[21];const _=I;let K;e[22]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{_();const Se=z.current;if(!Se||!globalThis.ResizeObserver)return;const Re=new ResizeObserver(_);return Re.observe(Se),()=>Re.disconnect()},e[22]=K):K=e[22];let G;e[23]!==S.length?(G=[_,S.length],e[23]=S.length,e[24]=G):G=e[24],c.useEffect(K,G);let Q;e[25]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{z.current?.querySelector("[data-active-session-tab]")?.scrollIntoView({block:"nearest",inline:"nearest"})},e[25]=Q):Q=e[25];let ge;e[26]!==g?(ge=[g],e[26]=g,e[27]=ge):ge=e[27],c.useEffect(Q,ge);const se=T.left&&T.right?"linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent)":T.left?"linear-gradient(to right, transparent, black 24px)":T.right?"linear-gradient(to right, black calc(100% - 24px), transparent)":void 0;let Y;e[28]!==S?(Y=S.map(vx),e[28]=S,e[29]=Y):Y=e[29];const te=Y;let he;e[30]!==g||e[31]!==S?(he=!g||!S.some(Se=>Se.id===g),e[30]=g,e[31]=S,e[32]=he):he=e[32];const L=he;let le;e[33]!==a?(le=a("header.sessionTabs.stripAria"),e[33]=a,e[34]=le):le=e[34];let Z;e[35]!==se?(Z=se?{maskImage:se,WebkitMaskImage:se}:void 0,e[35]=se,e[36]=Z):Z=e[36];let ue;e[37]===Symbol.for("react.memo_cache_sentinel")?(ue=[ax],e[37]=ue):ue=e[37];let V;e[38]!==o||e[39]!==g||e[40]!==D||e[41]!==C||e[42]!==r||e[43]!==n||e[44]!==l||e[45]!==S?(V=S.map(Se=>s.jsx(dx,{tab:Se,isActive:Se.id===g,suppressControls:Se.id===g&&l,onSelect:C,onClose:k,renderMenu:n,closeOtherTabs:D,onMenuOpenChangeComplete:r,children:Se.id===g?o:null},Se.id)),e[38]=o,e[39]=g,e[40]=D,e[41]=C,e[42]=r,e[43]=n,e[44]=l,e[45]=S,e[46]=V):V=e[46];let ee;e[47]!==V||e[48]!==te?(ee=s.jsx(Eo,{items:te,strategy:gg,children:V}),e[47]=V,e[48]=te,e[49]=ee):ee=e[49];let be;e[50]!==H||e[51]!==W||e[52]!==ee?(be=s.jsx($r,{sensors:W,collisionDetection:Wr,modifiers:ue,onDragEnd:H,children:ee}),e[50]=H,e[51]=W,e[52]=ee,e[53]=be):be=e[53];let xe;e[54]!==o||e[55]!==L?(xe=L?s.jsx("div",{role:"tab","aria-selected":!0,className:"session-tab-slot flex h-7 w-44 shrink-0 items-center rounded-md bg-interactive-selection px-2","data-active":"true",children:s.jsx("div",{className:"min-w-0 flex-1",children:o})}):null,e[54]=o,e[55]=L,e[56]=xe):xe=e[56];let Ne;e[57]!==Z||e[58]!==be||e[59]!==xe?(Ne=s.jsxs("div",{ref:z,onScroll:_,className:"session-tabs-scroll flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overscroll-x-contain",style:Z,children:[be,xe]}),e[57]=Z,e[58]=be,e[59]=xe,e[60]=Ne):Ne=e[60];let Pe;return e[61]!==le||e[62]!==Ne?(Pe=s.jsx("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center",role:"tablist","aria-label":le,children:Ne}),e[61]=le,e[62]=Ne,e[63]=Pe):Pe=e[63],Pe};function mx(t){return t.stopPropagation()}function fx(t){return t.stopPropagation()}function hx(t){return t.tabIds}function px(t){return t.ensureTab}function gx(t){return t.closeOtherTabs}function xx(t){return t.reorderTabs}function bx(t){return t.currentSessionId}function yx(t){return t.setCurrentSession}function wx(t){return t.activeSessions}function Sx(t){lf(t)}function vx(t){return t.id}function jx(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(pa(),{month:"short"}),r=e.getDate(),i=e.getFullYear(),o=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${i}, ${o}:${l}`}function kx(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function Cx(t){const e=t.info.role==="user"?"User":"Assistant",n=jx(t.info.time?.created),r=kx(t),i=n&&r?`${n} (${r})`:n||r;return i?`**${e}**
|
|
4
|
-
|
|
5
|
-
*${i}*`:`**${e}**`}function Nx(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function pu(t){const e=Cx(t),n=Nx(t.parts).trim();return n?`${e}
|
|
6
|
-
|
|
7
|
-
${n}`:""}function gu(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",i=`${n} Sub-agent: ${t.title}${r}
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
`,o=t.records.map(pu).filter(Boolean).join(`
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
`),l=[i+o];for(const a of t.children)l.push(gu(a,e+1));return l.join(`
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
`)}function xu(t,e,n){const r=e?.trim()||"Session",i=new Date().toISOString().split("T")[0],o=`# ${r}
|
|
20
|
-
|
|
21
|
-
*Exported on ${i}*
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
`,l=t.map(pu).filter(Boolean).join(`
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
`);let a=o+l;if(n&&n.length>0){const u=n.map(d=>gu(d,1)).join(`
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
`);a+=`
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
`+u}return a}function bu(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function yu(t,e){const n=await Bm(e,t);if(n)return n;if(!Nn())return null;try{const r=await Ko()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const i=typeof r.path=="string"?r.path.trim():"";return i.length>0?i:null}catch{return null}}async function Ax(t){const e=Ko()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await _m(t)?!0:nd(t)}function Dx(){return md()}function wu(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",i=new Date().toISOString().split("T")[0];return`${r}-${i}.md`}const Vi=(t,e)=>({success:t(e.success),failure:t(e.failure),sourceVerificationFailed:t("sessions.sidebar.session.moveToWorktree.sourceVerificationFailed"),applyChangesFailed:t("sessions.sidebar.session.moveToWorktree.applyChangesFailed"),changesMayBeInDestination:t("sessions.sidebar.session.moveToWorktree.changesMayBeInDestination")}),$n=Zn(()=>({pendingSessionIds:new Set,requestingSessionIds:new Set,confirmation:null})),Su=t=>{const e=Xe.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t)||r.requestingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],$n(n)},Px=()=>$n(Lx),vu=()=>$n.getState().confirmation,Ra=t=>{$n.setState(e=>e.confirmation===t?e:{...e,confirmation:t})},jl=(t,e)=>{$n.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{...n,pendingSessionIds:r}})},ir=(t,e)=>{$n.setState(n=>{if(n.requestingSessionIds.has(t)===e)return n;const r=new Set(n.requestingSessionIds);return e?r.add(t):r.delete(t),{...n,requestingSessionIds:r}})},Ix="Unable to apply your changes in the destination directory",Tx=t=>t.status===400&&t.message.includes(Ix),Rx=async(t,e)=>{try{const u=(await fd(t,{mode:"light"})).current?.trim();if(u)return u}catch{}const n=ct(t),r=ct(e)??e,i=Qe.getState().availableWorktreesByProject,l=(i.get(r)??i.get(e)??[]).find(a=>ct(a.path)===n)?.branch?.trim();if(l)return l;throw new Error("Unable to determine the current branch")},kl=t=>{for(const e of t){const n=df(e.id);if(n==="unknown")throw new Error("Session status is unavailable");if(n==="active")throw new Error("Session is not idle")}};class ju extends Error{changesMayBeInDestination;constructor(e,n,r){super(e,{cause:n}),this.name="IncompleteRollbackError",this.changesMayBeInDestination=r}}const Ex=(t,e,n)=>{const r=e.map(({sessionId:i,error:o})=>`${i}: ${o.message}`).join(", ");return new ju(`Session move partially failed and could not be fully rolled back: ${t.message}. Rollback failures: ${r}`,{moveError:t,rollbackFailures:e},n)},Mx=async(t,e,n,r)=>{const i=[];for(const o of[...t].reverse()){if(uf(o.id)){i.push({sessionId:o.id,error:new Error("Session is not idle")});continue}try{await hd(o,n,e,!1),Qe.getState().setWorktreeMetadata(o.id,r.get(o.id)??null)}catch(l){i.push({sessionId:o.id,error:l instanceof Error?l:new Error(String(l))})}}return i};class ku extends Error{constructor(e){super(e.message,{cause:e}),this.name="ChangesMayBeInDestinationError"}}const Cl=async(t,e,n)=>{try{await pd(t,e,{deleteLocalBranch:!0})}catch{throw new Error(`Session move failed and the new worktree could not be removed: ${n.message}`)}throw n},Nl=async(t,e)=>{const n=e?[t,e]:[t];try{await ga(n)}catch(r){console.warn("[session-worktree-move] Failed to refresh moved sessions",r)}},Cu=async(t,e)=>{if($n.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");jl(t.root.id,!0);try{const n=[...t.descendants,t.root],r=new Map(n.map(a=>[a.id,Qe.getState().getWorktreeMetadata(a.id)]));kl(n);let i=null;const o=[];let l=!1;try{i=await e();for(const[a,u]of n.entries()){kl(n.slice(a));const d=u.id===t.root.id&&t.moveChanges;try{await hd(u,t.sourceDirectory,i.directory,d)}catch(h){throw d&&cf(h)&&(l=!0),h}o.push(u),u.id!==t.root.id&&Qe.getState().setWorktreeMetadata(u.id,Za(i.metadata))}}catch(a){const u=a instanceof Error?a:new Error(String(a)),d=await Mx(o,t.sourceDirectory,i?.directory??t.sourceDirectory,r);if(l&&await Nl(t.sourceDirectory,i?.directory),d.length>0)throw Ex(u,d,l);if(l)throw new ku(u);if(i?.onMoveFailure)return i.onMoveFailure(u);throw u}return Qe.getState().setWorktreeMetadata(t.root.id,Za(i.metadata)),await Nl(t.sourceDirectory,i.directory),i.directory}finally{jl(t.root.id,!1)}},Ox=async t=>{const e=ct(t.sourceDirectory)??t.sourceDirectory,n=ct(t.destination.path)??t.destination.path;if(e===n)throw new Error("Source and destination are the same");if(t.destination.worktreeStatus!=="ready")throw new Error("Destination worktree is not ready");return Cu(t,async()=>({directory:t.destination.path,metadata:t.destination}))},Fx=async t=>Cu(t,async()=>{const e=ki(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=await Qo(t.sourceDirectory)?await Rx(t.sourceDirectory,e.path):null,r=await mf(e,n?{startRef:n}:{});try{await ff(r.path)}catch(i){const o=i instanceof Error?i:new Error(String(i));return Cl(e,r,o)}return{directory:r.path,metadata:r,onMoveFailure:async i=>Cl(e,r,i)}}),Bx=(t,e,n)=>e instanceof ku?t.changesMayBeInDestination:e instanceof ju&&e.changesMayBeInDestination?`${e.message} ${t.changesMayBeInDestination}`:n&&Tx(e)?t.applyChangesFailed:e.message,Ui=(t,e)=>{(t.kind==="existing"?Ox({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,destination:t.destination,moveChanges:e}):Fx({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,moveChanges:e})).then(()=>Fe.success(t.messages.success)).catch(r=>{const i=r instanceof Error?r:new Error(String(r));Fe.error(t.messages.failure,{description:Bx(t.messages,i,e)})})},_x=()=>{const t=vu();t&&(ir(t.intent.root.id,!1),Ra(null))},Nu=t=>{const e=vu();if(!e)return;const{intent:n}=e;Ra(null),ir(n.root.id,!1),Ui(n,t)},Ki=t=>{const e=$n.getState();e.confirmation||e.pendingSessionIds.has(t.root.id)||e.requestingSessionIds.has(t.root.id)||(ir(t.root.id,!0),(async()=>{try{if(!await Qo(t.sourceDirectory)){ir(t.root.id,!1),Ui(t,!1);return}const r=await fd(t.sourceDirectory);if(r.isClean){ir(t.root.id,!1),Ui(t,!1);return}const i=r.files.filter(o=>{const l=o.index.trim();return l!==""&&l!=="?"}).length;Ra({intent:t,dirtyFileCount:r.files.length,stagedFileCount:i})}catch{Fe.error(t.messages.failure,{description:t.messages.sourceVerificationFailed}),ir(t.root.id,!1)}})())};function Lx(t){return t.confirmation}const Fo="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",$x=c.memo(function(e){const n=Xe.c(17),{visible:r,title:i,ariaLabel:o,onClick:l,className:a,Icon:u,iconClassName:d,pressed:h}=e,f=r===void 0?!0:r,g=h===void 0?!1:h;if(!f)return null;const p=a??Fo,w=g&&"bg-interactive-selection text-interactive-selection-foreground";let v;n[0]!==p||n[1]!==w?(v=Te(p,w),n[0]=p,n[1]=w,n[2]=v):v=n[2];const x=d??"h-[18px] w-[18px]";let m;n[3]!==u||n[4]!==x?(m=s.jsx(M,{name:u,className:x}),n[3]=u,n[4]=x,n[5]=m):m=n[5];let b;n[6]!==o||n[7]!==l||n[8]!==g||n[9]!==v||n[10]!==m?(b=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":o,"aria-pressed":g,className:v,children:m})}),n[6]=o,n[7]=l,n[8]=g,n[9]=v,n[10]=m,n[11]=b):b=n[11];let y;n[12]!==i?(y=s.jsx(bt,{children:s.jsx("p",{children:i})}),n[12]=i,n[13]=y):y=n[13];let S;return n[14]!==b||n[15]!==y?(S=s.jsxs(gt,{children:[b,y]}),n[14]=b,n[15]=y,n[16]=S):S=n[16],S}),Wx=c.memo(function(e){const n=Xe.c(43),{isDesktopApp:r,currentInstanceLabel:i,compactCurrentInstanceLabel:o,currentInstanceIsLocal:l,isDesktopServicesOpen:a,setIsDesktopServicesOpen:u,refreshCurrentInstanceLabel:d,shortcutLabel:h,remoteUpdateInfo:f,remoteUpdateChecking:g,remoteUpdateError:p,onOpenRemoteUpdate:w}=e,{t:v}=pt();let x;n[0]!==d||n[1]!==u?(x=E=>{u(E),E&&d()},n[0]=d,n[1]=u,n[2]=x):x=n[2];let m;n[3]!==i||n[4]!==r||n[5]!==v?(m=r?v("header.services.openWithCurrent",{current:i}):v("header.services.open"),n[3]=i,n[4]=r,n[5]=v,n[6]=m):m=n[6];const b=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let y;n[7]!==b?(y=Te(Fo,b),n[7]=b,n[8]=y):y=n[8];let S;n[9]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(M,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=S):S=n[9];let N;n[10]!==o||n[11]!==r?(N=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:o}):null,n[10]=o,n[11]=r,n[12]=N):N=n[12];let C;n[13]!==m||n[14]!==y||n[15]!==N?(C=s.jsx(xt,{asChild:!0,children:s.jsx(Ys,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":m,className:y,children:[S,N]})})}),n[13]=m,n[14]=y,n[15]=N,n[16]=C):C=n[16];let k;n[17]!==i||n[18]!==h||n[19]!==v?(k=v("header.services.tooltip.currentInstance",{current:i,toggle:h("toggle_services_menu")}),n[17]=i,n[18]=h,n[19]=v,n[20]=k):k=n[20];let A;n[21]!==k?(A=s.jsx(bt,{children:s.jsx("p",{children:k})}),n[21]=k,n[22]=A):A=n[22];let D;n[23]!==C||n[24]!==A?(D=s.jsxs(gt,{children:[C,A]}),n[23]=C,n[24]=A,n[25]=D):D=n[25];let P;n[26]!==l||n[27]!==r||n[28]!==a||n[29]!==w||n[30]!==g||n[31]!==p||n[32]!==f||n[33]!==u||n[34]!==v?(P=r?s.jsxs("div",{children:[l?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:v("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:f?.available?v("header.services.remoteUpdate.available",{version:f.version||""}):g?v("header.services.remoteUpdate.checking"):p||v("header.services.remoteUpdate.upToDate")})]}),f?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:w,children:v("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(hf,{embedded:!0,open:a,onOpenChange:Kx,onHostSwitched:()=>u(!1)})]}):null,n[26]=l,n[27]=r,n[28]=a,n[29]=w,n[30]=g,n[31]=p,n[32]=f,n[33]=u,n[34]=v,n[35]=P):P=n[35];let F;n[36]!==P?(F=s.jsx(Xs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:P}),n[36]=P,n[37]=F):F=n[37];let W;return n[38]!==a||n[39]!==x||n[40]!==D||n[41]!==F?(W=s.jsxs(Js,{open:a,onOpenChange:x,children:[D,F]}),n[38]=a,n[39]=x,n[40]=D,n[41]=F,n[42]=W):W=n[42],W}),zx=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),Vx=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],i=n[1].slice(0,3),o=`${r} ${i}`.trim();return n.length>2||o.length<e.length?`${o}...`:o}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Sn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Al=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,Ux=()=>{qs("ui.header.render");const{t}=pt(),e=De(U=>U.isSidebarOpen),n=De(U=>U.openContextOverview),r=De(U=>U.closeContextPanel),i=De(U=>U.shortcutOverrides),o=De(U=>U.sessionTabsEnabled),l=Ut(U=>U.getCurrentModel),a=Qe(U=>U.getContextUsage),u=Qe(U=>!!U.newSessionDraft?.open),d=Qe(U=>U.currentSessionId),h=pf(d??""),f=ha(d??""),g=Su(d??""),p=As(Xn(c.useCallback(U=>{if(!d)return null;const _e=[...U.activeSessions,...U.archivedSessions].find(mt=>mt.id===d);if(!_e)return null;const Je=_e;return{title:_e.title??null,directory:Je.directory??null,created:_e.time?.created??null,slug:Je.slug??null,shareUrl:_e.share?.url??null,parentId:_e.parentID??null}},[d]))),w=Vt(Xn(U=>{if(!U.activeProjectId)return null;const _e=U.projects.find(Je=>Je.id===U.activeProjectId);return _e?{id:_e.id,path:_e.path,label:_e.label}:null})),v=c.useMemo(()=>{if(!w)return null;const U=w.label?.trim();if(U)return U;const _e=w.path.split(/[\\/]/).filter(Boolean);return _e[_e.length-1]??null},[w]),x=rr(U=>U.loadSettings),{isMobile:m}=_n(),b=c.useRef(null),[y,S]=c.useState(()=>typeof window>"u"?!1:pn()),N=c.useMemo(()=>Ho(),[]),C=gd(),[k,A]=c.useState(!1),D=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:P,side:F}=Hd(),W=c.useMemo(()=>{if(typeof window>"u")return null;const U=window.__AIWORKER_MACOS_MAJOR__;if(typeof U=="number"&&Number.isFinite(U)&&U>0)return U;if(typeof navigator>"u")return null;const _e=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!_e)return null;const Je=Number.parseInt(_e[1],10),mt=Number.parseInt(_e[2],10);return Number.isNaN(Je)?null:Je===10?mt:Je},[]);it.useEffect(()=>{typeof window>"u"||S(pn())},[]);const E=l(),H=E&&typeof E.limit=="object"&&E.limit!==null?E.limit:null,z=H&&typeof H.context=="number"?H.context:0,B=H&&typeof H.output=="number"?H.output:0,T=a(z,B),[j,I]=c.useState(null),_=!d||h;it.useEffect(()=>{if(!d){I(U=>U===null?U:null);return}if(T&&T.totalTokens>0){I(U=>zx(U,T)?U:T);return}_&&I(U=>U===null?U:null)},[T,d,_]);const[K,G]=c.useState(!1),[Q,ge]=c.useState("Local"),[se,Y]=c.useState(!0),[te,he]=c.useState(!1),[L,le]=c.useState(null),[Z,ue]=c.useState(!1),[V,ee]=c.useState(null),be=c.useMemo(()=>Vx(Q),[Q]),xe=c.useMemo(()=>Nn(),[]),Ne=De(U=>U.workStatusPanelVisible),Pe=De(U=>U.workStatusPanelEnabled),Se=De(U=>U.setWorkStatusPanelEnabled),Re=De(U=>U.workStatusPanelFits),ye=De(U=>U.workStatusOverlayOpen),pe=De(U=>U.setWorkStatusOverlayOpen),je=Pe&&Re||ye,ne=c.useCallback(()=>{if(Pe&&!Re){pe(!ye);return}Se(!Pe)},[pe,Se,ye,Pe,Re]),fe=!xe&&!Ne&&!!j&&j.totalTokens>0,ce=j&&j.contextLimit>0?Math.min(999,j.totalTokens/j.contextLimit*100):0,R=c.useCallback(async()=>{if(!(typeof window>"u"||!y))try{if(Uo()){ge("Local"),Y(!0);return}Y(!1);const U=await rd(),_e=gf(),Je=xf([bf(_e),...U.hosts]);if(Je.id===yf){ge("Local"),Y(!0);return}ge(od(Je.label.trim()||"Instance"))}catch{ge("Local"),Y(!0)}},[y]);it.useEffect(()=>(R(),Go(()=>{R()})),[R]);const $=c.useCallback(async()=>{if(se){le(null),ee(null);return}ue(!0),ee(null);try{const U=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),_e=await ds(`/api/openchamber/update-check?${U.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!_e.ok)throw new Error(`Server responded with ${_e.status}`);const Je=await _e.json();le({available:Je.available??!1,version:Je.version,currentVersion:Je.currentVersion??"unknown",body:Je.body,nextSuggestedCheckInSec:typeof Je.nextSuggestedCheckInSec=="number"?Je.nextSuggestedCheckInSec:void 0,packageManager:Je.packageManager,updateCommand:Je.updateCommand})}catch(U){le(null),ee(U instanceof Error?U.message:t("header.services.remoteUpdate.error"))}finally{ue(!1)}},[se,t]);c.useEffect(()=>{le(null),ee(null),he(!1)},[se,Q]),c.useEffect(()=>{if(!y||se)return;const U=3e3,_e=3600*1e3;let Je=!1,mt=null;const ht=Ft=>{mt=window.setTimeout(()=>{if(Je||typeof document<"u"&&document.visibilityState!=="visible"){ht(_e);return}$().finally(()=>{Je||ht(_e)})},Ft)};return ht(U),()=>{Je=!0,mt!==null&&window.clearTimeout(mt)}},[$,se,Q,y]);const de=c.useCallback(()=>{if(L?.available){he(!0);return}$()},[$,L?.available]);wf(),c.useEffect(()=>{x()},[x]);const ie=d?p??null:null,Ae=c.useRef(null),[Be,Ce]=c.useState(0);c.useEffect(()=>{if(!d){Ae.current&&(Ae.current=null,Ce(mt=>mt+1));return}if(ie){Ae.current={sessionId:d,session:ie,expiresAt:Date.now()+2e3};return}const U=Ae.current;if(!U||U.sessionId!==d)return;const _e=U.expiresAt-Date.now();if(_e<=0){Ae.current=null,Ce(mt=>mt+1);return}const Je=window.setTimeout(()=>{Ae.current?.sessionId===d&&(Ae.current=null),Ce(mt=>mt+1)},_e);return()=>{window.clearTimeout(Je)}},[d,ie]);const q=(()=>{if(ie)return ie;if(!d)return null;const U=Ae.current;return U&&U.sessionId===d&&U.expiresAt>Date.now()?U.session:null})(),Ee=Qe(U=>d?U.worktreeMetadata.get(d)?.path??"":""),Me=Qe(U=>d?U.worktreeMetadata.get(d)?.branch?.trim()??null:null),O=xd(U=>d?U.getAttachment(d):void 0),oe=c.useMemo(()=>O?Sf(O,{pending:t("gitView.empty.worktreeSetupInProgress")}):null,[t,O]),re=c.useMemo(()=>O?O.legacy?"legacy":O.degraded?"degraded":O.worktreeStatus==="pending"?"pending":O.worktreeStatus==="missing"?"missing":O.worktreeStatus==="invalid"?"invalid":O.attentionReason?"attention":null:null,[O]),we=c.useMemo(()=>Sn(Ee||""),[Ee]),Ve=c.useMemo(()=>{const U=typeof q?.directory=="string"?q.directory:"";return Sn(U||"")},[q?.directory]),st=Qe(U=>U.newSessionDraft?.open?Sn(U.newSessionDraft.bootstrapPendingDirectory??U.newSessionDraft.directoryOverride??""):""),Ge=Qe(U=>U.newSessionDraft.target),ae=Qe(U=>U.newSessionDraft.selectedProjectId),X=Qe(U=>U.currentSessionDirectory),ve=Zt(U=>U.homeDirectory),Le=c.useMemo(()=>we||Ve||st,[st,Ve,we]),$e=De(c.useCallback(U=>{const _e=Sn(Le||"");return _e?Al(U.contextPanelByDirectory[_e]):null},[Le])),Ue=Qe(U=>{const _e=Sn(we||Ve||"");if(!_e)return null;for(const Je of U.availableWorktreesByProject.values()){const ht=Je.find(Ft=>Sn(Ft.path)===_e)?.branch?.trim();if(ht)return ht}return null}),qe=vf(Le||null)||Me||Ue,nt=u?Ge==="chat":jf(Ve||X,ve),yt=!nt&&!Ne&&!!(v||qe||!u&&re),vt=c.useMemo(()=>{if(!d)return v??"AiWorker";const U=q?.title?.trim();return U&&U.length>0?U:"Untitled Session"},[v,q?.title,d]),He=bd(Le||void 0,{bootstrap:!1}),Mt=yd(),jt=Qe(U=>U.updateSessionTitle),kt=Qe(U=>U.shareSession),Tt=Qe(U=>U.unshareSession),wt=Qe(U=>U.archiveSessions),Nt=Qe(U=>U.deleteSessions),[Dt,ft]=c.useState(!1),[Ze,ke]=c.useState(!1),tt=c.useRef(null),[lt,At]=c.useState(""),[Ye,rt]=c.useState(null),It=c.useRef(null),Ct=c.useCallback(()=>{d&&(At(q?.title?.trim()||vt),ft(!0))},[q?.title,d,vt]),Pt=c.useRef(Ct);Pt.current=Ct,c.useEffect(()=>{if(ke(!1),rt(null),d&&tt.current===d){tt.current=null,Pt.current();return}ft(!1),At("")},[d]);const Wt=c.useCallback(async()=>{if(!d)return;const U=lt.trim();U&&U!==q?.title?.trim()&&await jt(d,U),ft(!1)},[q?.title,d,lt,jt]);c.useEffect(()=>{if(!Dt)return;const U=_e=>{const Je=_e.target;(!Je||!It.current?.contains(Je))&&Wt()};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[Dt,Wt]);const Yt=c.useCallback(U=>{U&&fn(U).then(_e=>{Fe[_e.ok?"success":"error"](t(_e.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(t("sessions.sidebar.session.copyId.error")))},[t]),Kt=c.useCallback(async U=>{if(!U)return;const _e=await kt(U);if(_e?.share?.url){const Je=await fn(_e.share.url);Fe[Je.ok?"success":"warning"](t("sessions.sidebar.session.share.successTitle"),{description:t(Je.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Fe.error(t("sessions.sidebar.session.share.error"))},[kt,t]),Bt=c.useCallback(U=>{U&&fn(U).then(_e=>{Fe[_e.ok?"success":"error"](t(_e.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Fe.error(t("sessions.sidebar.session.share.copyUrlError")))},[t]),ts=c.useCallback(async U=>{if(!U)return;const _e=await Tt(U);Fe[_e?"success":"error"](t(_e?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[t,Tt]),zt=c.useCallback(async()=>{if(!d||!Le){Fe.error(t("sessions.sidebar.session.export.nothingToExport"));return}try{await Mt.loadCompleteHistory(d,Le)}catch{Fe.error(t("sessions.sidebar.session.export.failedLoadHistory"));return}const U=kf(He.getState(),d).list;if(U.length===0){Fe.error(t("sessions.sidebar.session.export.nothingToExport"));return}const _e=xu(U,q?.title??null),Je=wu(q?.title??null);await yu(_e,Je)||bu(_e,Je),Fe.success(t("sessions.sidebar.session.export.success"))},[q?.title,d,He,Le,Mt,t]),_t=f?.type==="busy"||f?.type==="retry",Oe=c.useCallback(()=>{if(!d||!Ve||_t||g)return;const U=As.getState().activeSessions,_e=U.find(ht=>ht.id===d);if(!_e)return;const Je=[],mt=[d];for(let ht=0;ht<mt.length;ht+=1){const Ft=mt[ht];for(const ns of U)ns.parentID===Ft&&(Je.push(ns),mt.push(ns.id))}Ki({kind:"quick",root:_e,descendants:Je,sourceDirectory:Ve,messages:Vi(t,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},[d,_t,g,Ve,t]),Ke=c.useCallback(async()=>{if(!Ye)return;const U=As.getState().activeSessions,_e=[Ye.sessionId];for(let Ft=0;Ft<_e.length;Ft+=1){const ns=_e[Ft];for(const Ht of U)Ht.parentID===ns&&!_e.includes(Ht.id)&&_e.push(Ht.id)}const Je=Ye.action;if(rt(null),(Je==="archive"?await wt(_e):await Nt(_e)).failedIds.length>0){Fe.error(t(Je==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Fe.success(t(Je==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[wt,Nt,Ye,t]),et=De(U=>U.isScheduledTasksDialogOpen),dt=De(U=>U.isArchivePageOpen),ut=De(U=>U.worktreesPageProjectId),St=De(U=>U.isMultiRunLauncherOpen),ot=Vt(U=>{if(!ut)return null;const _e=U.projects.find(Je=>Je.id===ut);return _e?.label?.trim()||_e?.path?.split("/").pop()||null}),Lt=c.useMemo(()=>et?{title:t("sessions.scheduledTasks.dialog.title"),subtitle:null}:dt?{title:t("sessions.archivePage.title"),subtitle:null}:ut?{title:t("sessions.worktreesPage.title",{project:ot??""}),subtitle:null}:St?{title:t("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[dt,St,et,t,ut,ot]),Qt=c.useMemo(()=>Sn(Le||w?.path||""),[w?.path,Le]),us=ix(),$s=xa(U=>U.planModeEnabled),rs=Qe(U=>U.isSessionPlanAvailable),Is=$s&&d?rs(d):!1,ss=c.useRef("");c.useEffect(()=>{if(!$s||!d)return;const U=`${d||"none"}:${Ve||"none"}:${q?.created||0}:${q?.slug||"none"}`;ss.current!==U&&(ss.current=U)},[$s,Is,q?.slug,q?.created,d,Ve]);const Ns=c.useCallback(()=>{Rn("desktop_open_draft_mini_chat_window",{directory:nt?"":st,projectId:nt?null:ae,apiBaseUrl:Mn(),clientToken:Fr()}).catch(U=>{console.warn("[header] failed to open draft mini chat window",U)})},[st,ae,nt]),Ws=c.useCallback(()=>{if(u){Ns();return}d&&Rn("desktop_open_session_mini_chat_window",{sessionId:d,directory:Ve||Sn(X||"")||we,apiBaseUrl:Mn(),clientToken:Fr()}).catch(U=>{console.warn("[header] failed to open session mini chat window",U)})},[d,Ns,u,X,Ve,we]),cn=c.useCallback(()=>{const U=Sn(Le||"");if(!U)return;const _e=De.getState().contextPanelByDirectory[U];if(Al(_e)==="context"){r(U);return}n(U)},[r,n,Le]),bn=$e==="context",ms=Fo,xs=c.useMemo(()=>y&&D&&!k?"5.5rem":C?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!y||P)&&!xe?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[y,k,D,C,xe,P]);it.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",xs)},[xs]);const zs=e?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",an=e?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";it.useEffect(()=>{if(!y||!D){A(!1);return}let U=!1;const _e=async()=>{try{const mt=await Rn("desktop_is_window_fullscreen");U||A(mt===!0)}catch{U||A(!1)}},Je=()=>{_e()};return _e(),window.addEventListener("aiworker:window-resized",Je),()=>{U=!0,window.removeEventListener("aiworker:window-resized",Je)}},[y,D]);const is=c.useMemo(()=>!y||!D||W===null?"":W>=26?"h-12":W<=15?"h-14":"",[y,D,W]),Vs=c.useMemo(()=>{if(!(y&&!P||xe)&&!(P&&F==="right"))return{paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[y,xe,P,F]),Rt=c.useCallback(()=>{if(typeof document>"u")return;const U=b.current?.getBoundingClientRect().height;U&&document.documentElement.style.setProperty("--oc-header-height",`${U}px`)},[]);it.useEffect(()=>{if(typeof window>"u")return;Rt();const U=b.current;if(!U||typeof ResizeObserver>"u")return()=>{};let _e=0;const Je=()=>{_e||(_e=requestAnimationFrame(()=>{_e=0,Rt()}))},mt=new ResizeObserver(Je);return mt.observe(U),window.addEventListener("resize",Je),window.addEventListener("orientationchange",Je),()=>{_e&&cancelAnimationFrame(_e),mt.disconnect(),window.removeEventListener("resize",Je),window.removeEventListener("orientationchange",Je)}},[Rt]),it.useEffect(()=>{Rt()},[Rt,m,is]);const Ot=c.useCallback(async U=>{const _e=U.target;_e.closest(".app-region-no-drag")||_e.closest("button, a, input, select, textarea")||U.button===0&&y&&await Lm()},[y]),Xt=c.useCallback(U=>Qn(Gr(U,i)),[i]);Cf({rename_current_session:()=>{if(!d||m)return!1;Ct()},toggle_services_menu:()=>{if(K){G(!1);return}G(!0),R()}});const bs=s.jsxs(s.Fragment,{children:[us?s.jsx(ox,{projectRef:us.projectRef,directory:us.directory,className:"mr-2"}):null,s.jsx(Tg,{directory:Qt,className:"mr-1"}),y?s.jsx(Wx,{isDesktopApp:y,currentInstanceLabel:Q,compactCurrentInstanceLabel:be,currentInstanceIsLocal:se,isDesktopServicesOpen:K,setIsDesktopServicesOpen:G,refreshCurrentInstanceLabel:R,shortcutLabel:Xt,remoteUpdateInfo:L,remoteUpdateChecking:Z,remoteUpdateError:V,onOpenRemoteUpdate:de}):null]}),fs=N&&(u||!!d),Ts=c.useCallback(({session:U,isActive:_e,select:Je,closeOtherTabs:mt,components:ht})=>{const{Item:Ft,Separator:ns}=ht,Ht=U.share?.url??null,Zs=_e&&!xe&&!nt&&q&&!q.parentId;return s.jsxs(s.Fragment,{children:[s.jsxs(Ft,{onClick:()=>{_e||Je(),tt.current=U.id},children:[s.jsx(M,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ft,{onClick:()=>Yt(U.id),children:[s.jsx(M,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(ns,{}),Ht?s.jsxs(s.Fragment,{children:[s.jsxs(Ft,{onClick:()=>Bt(Ht),children:[s.jsx(M,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Ft,{onClick:()=>{ts(U.id)},children:[s.jsx(M,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ft,{onClick:()=>{Kt(U.id)},children:[s.jsx(M,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),_e?s.jsxs(Ft,{onClick:()=>{zt()},children:[s.jsx(M,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}):null,Zs?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Ft,{disabled:!Ve||_t||g,onClick:Oe,className:"w-full",children:[s.jsx(M,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(bt,{side:"right",className:"max-w-72",children:t(g?"sessions.sidebar.session.moveToWorktree.tooltipMoving":_t?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(ns,{}),s.jsxs(Ft,{onClick:mt,children:[s.jsx(M,{name:"close-circle",className:"mr-2 size-4"}),t("header.sessionTabs.closeOtherTabs")]}),s.jsx(ns,{}),s.jsxs(Ft,{onClick:()=>rt({action:"archive",sessionId:U.id}),children:[s.jsx(M,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Ft,{className:"text-destructive focus:text-destructive",onClick:()=>rt({action:"delete",sessionId:U.id}),children:[s.jsx(M,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})},[Yt,Bt,q,zt,nt,_t,g,xe,Oe,Ve,Kt,t,ts]),J=()=>s.jsxs("div",{onMouseDown:Ot,className:Te("app-region-drag relative flex h-12 select-none items-center",P&&F==="right"?"pr-0":"pr-3",is),style:Vs,role:"tablist","aria-label":t("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:zs}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:an}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Lt?s.jsxs("div",{className:"mr-3 flex min-w-0 flex-col items-start px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:Lt.title}),Lt.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:Lt.subtitle}):null]}):xe||!o?s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[e?null:s.jsx(gl,{align:"start",children:s.jsx("button",{type:"button",className:ms,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(M,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[Dt?s.jsxs("form",{ref:It,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:U=>U.stopPropagation(),onSubmit:U=>{U.preventDefault(),Wt()},children:[s.jsx("input",{value:lt,onChange:U=>At(U.target.value),autoFocus:!0,onKeyDown:U=>{U.stopPropagation(),U.key==="Escape"&&ft(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":t("sessions.sidebar.session.rename.save"),title:t("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>ft(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):vt}),yt?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[v?s.jsx("span",{className:"truncate",children:v}):null,qe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(M,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:qe})]}):null,!u&&re?s.jsxs("span",{className:Te("inline-flex min-w-0 items-center gap-0.5",re==="attention"||re==="invalid"||re==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(M,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe})]}):null]}):null]}),s.jsx("div",{className:Te("flex h-[18px] shrink-0 items-center justify-center",yt?"self-start":"self-center"),children:d&&!u&&!Dt?s.jsxs(Js,{open:Ze,onOpenChange:ke,onOpenChangeComplete:U=>{!U&&tt.current&&tt.current===d&&(tt.current=null,Ct())},children:[s.jsx(Ys,{asChild:!0,children:s.jsx(at,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":t("header.sessionActions.openAria"),children:s.jsx(M,{name:"more",className:"size-4"})})}),s.jsxs(Xs,{align:"end",className:"min-w-[190px]",children:[s.jsxs($t,{onClick:()=>{tt.current=d},children:[s.jsx(M,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>d&&Yt(d),children:[s.jsx(M,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(Es,{}),q?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs($t,{onClick:()=>Bt(q?.shareUrl),children:[s.jsx(M,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs($t,{onClick:()=>{d&&ts(d)},children:[s.jsx(M,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>{d&&Kt(d)},children:[s.jsx(M,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{zt()},children:[s.jsx(M,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}),!xe&&!nt&&q&&!q.parentId?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs($t,{disabled:!Ve||_t||g,onClick:Oe,className:"w-full",children:[s.jsx(M,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(bt,{side:"right",className:"max-w-72",children:t(g?"sessions.sidebar.session.moveToWorktree.tooltipMoving":_t?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(Es,{}),s.jsxs($t,{onClick:()=>{d&&rt({action:"archive",sessionId:d})},children:[s.jsx(M,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs($t,{className:"text-destructive focus:text-destructive",onClick:()=>{d&&rt({action:"delete",sessionId:d})},children:[s.jsx(M,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}):s.jsxs("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center gap-0.5 text-left",children:[e?null:s.jsx(gl,{align:"start",children:s.jsx("button",{type:"button",className:ms,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(M,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsx(ux,{renderMenu:Ts,suppressActiveTabControls:Dt,onMenuOpenChangeComplete:U=>{!U&&tt.current&&tt.current===d&&(tt.current=null,Ct())},children:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:Dt?s.jsxs("form",{ref:It,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:U=>U.stopPropagation(),onSubmit:U=>{U.preventDefault(),Wt()},children:[s.jsx("input",{value:lt,onChange:U=>At(U.target.value),autoFocus:!0,onKeyDown:U=>{U.stopPropagation(),U.key==="Escape"&&ft(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent text-[13px] font-medium leading-4 outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":t("sessions.sidebar.session.rename.save"),title:t("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>ft(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"block overflow-hidden whitespace-nowrap text-[13px] font-medium leading-4 text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):vt})})})]}),Lt||xe||!o?s.jsx("div",{className:"flex-1"}):null,s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[fe&&j?s.jsx(Rp,{totalTokens:j.totalTokens,percentage:ce,colorPercentage:j.percentage,contextLimit:j.contextLimit,outputLimit:j.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:cn,pressed:bn,className:fs?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx($x,{visible:fs,title:t(u?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:t(u?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Ws,className:Te(ms,"mr-1"),Icon:"picture-in-picture-2"}),xe?null:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":je,"aria-label":t("header.workStatusPanel.toggleAria"),onClick:ne,className:Te(Fo,"mr-1",je?"text-foreground":"text-muted-foreground/50"),children:s.jsx(M,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(bt,{side:"bottom",children:t(Pe&&!Re?ye?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":Pe?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}),bs,s.jsx(Gd,{visible:P&&F==="right",position:"right"})]})]})]});return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:b,className:"header-safe-area relative z-10 bg-background",style:{"--padding-scale":"1"},children:J()}),s.jsx(vs,{open:Ye!==null,onOpenChange:U=>{U||rt(null)},children:s.jsxs(js,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Ls,{children:[s.jsx(Ds,{children:Ye?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.title"):t("sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Ps,{children:Ye?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:vt}):t("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:vt})})]}),s.jsxs(gn,{children:[s.jsx(at,{variant:"outline",size:"sm",onClick:()=>rt(null),children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",size:"sm",onClick:()=>{Ke()},children:Ye?.action==="delete"?t("sessions.sidebar.bulkActions.delete"):t("sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(qd,{open:te,onOpenChange:he,info:L,downloading:!1,downloaded:!1,progress:null,error:V,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Kx(){}const Dl=280,Pl=280,Il=500,Hx=({isOpen:t,isMobile:e,children:n,className:r,topBar:i})=>{const{t:o}=pt(),l=De(k=>k.sidebarWidth),a=De(k=>k.setSidebarWidth),[u,d]=c.useState(!1),h=c.useRef(0),f=c.useRef(l||Dl),g=c.useRef(null),p=c.useRef(null),w=c.useRef(null),v=c.useCallback(k=>Math.min(Il,Math.max(Pl,k)),[]),x=c.useCallback(k=>{const A=w.current;A&&(A.style.width=`${k}px`,A.style.minWidth=`${k}px`,A.style.maxWidth=`${k}px`,A.style.setProperty("--oc-left-sidebar-width",`${k}px`))},[]);if(c.useEffect(()=>{e&&u&&d(!1)},[e,u]),c.useEffect(()=>{u||(g.current=null,p.current=null)},[u]),e)return null;const m=Math.min(Il,Math.max(Pl,l||Dl)),b=t?m:0,y=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}p.current=k.pointerId,d(!0),h.current=k.clientX,f.current=b,g.current=b,x(b),k.preventDefault()}},S=k=>{if(e||!u||p.current!==k.pointerId)return;const A=k.clientX-h.current,D=v(f.current+A);g.current!==D&&(g.current=D,x(D))},N=k=>{if(p.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const A=v(g.current??b);p.current=null,g.current=null,d(!1),a(A)},C=u?g.current??b:b;return s.jsxs("aside",{ref:w,className:Te("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${u?C:m}px`,overflowX:"clip",transitionProperty:u?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&s.jsx("div",{className:Te("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:y,onPointerMove:S,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":o("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Te("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",u&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[i,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(Gs,{children:n})})]})]})},Gx=()=>{const t=Xe.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},Tl="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",qx=()=>{const t=Xe.c(32),{t:e}=pt(),n=De(Qx),r=De(Yx),i=c.useRef(null),o=Qn(Gr("toggle_sidebar",r)),{usesFramelessChrome:l,side:a}=Hd(),u=Jx;let d,h;t[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{if(typeof document>"u")return;const W=i.current;if(!W)return;const E=()=>{const z=Math.max(W.getBoundingClientRect().width,W.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(z)}px`)};if(E(),typeof ResizeObserver>"u")return;const H=new ResizeObserver(E);return H.observe(W),()=>{H.disconnect()}},h=[],t[0]=d,t[1]=h):(d=t[0],h=t[1]),c.useEffect(d,h);const f="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let g;t[2]===Symbol.for("react.memo_cache_sentinel")?(g={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=g):g=t[2];const p="flex items-center gap-2";let w;t[3]!==l||t[4]!==a?(w=l&&a==="left"?s.jsx(Gd,{visible:!0,position:"left"}):null,t[3]=l,t[4]=a,t[5]=w):w=t[5];let v;t[6]!==e||t[7]!==l?(v=l?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:Te(Tl,"shrink-0"),children:s.jsx(M,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(bt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=l,t[8]=v):v=t[8];const x=gt;let m;t[9]!==e?(m=e("header.actions.openSessionsAria"),t[9]=e,t[10]=m):m=t[10];let b,y;t[11]===Symbol.for("react.memo_cache_sentinel")?(b=Te(Tl,"shrink-0"),y=s.jsx(M,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=b,t[12]=y):(b=t[11],y=t[12]);let S;t[13]!==m||t[14]!==n?(S=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":m,className:b,children:y})}),t[13]=m,t[14]=n,t[15]=S):S=t[15];const N=bt,C=e("header.actions.openSessionsWithShortcut",{shortcut:o});let k;t[16]!==C?(k=s.jsx("p",{children:C}),t[16]=C,t[17]=k):k=t[17];let A;t[18]!==N||t[19]!==k?(A=s.jsx(N,{children:k}),t[18]=N,t[19]=k,t[20]=A):A=t[20];let D;t[21]!==x||t[22]!==S||t[23]!==A?(D=s.jsxs(x,{children:[S,A]}),t[21]=x,t[22]=S,t[23]=A,t[24]=D):D=t[24];let P;t[25]!==D||t[26]!==w||t[27]!==v?(P=s.jsxs("div",{ref:i,className:p,children:[w,v,D]}),t[25]=D,t[26]=w,t[27]=v,t[28]=P):P=t[28];let F;return t[29]!==P||t[30]!==g?(F=s.jsx("div",{className:f,style:g,children:P}),t[29]=P,t[30]=g,t[31]=F):F=t[31],F};function Qx(t){return t.toggleSidebar}function Yx(t){return t.shortcutOverrides}function Xx(t){console.warn("[titlebar] failed to open app menu",t)}function Jx(t){const e=t.currentTarget.getBoundingClientRect();Rn("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Xx)}function Au(t){const e=Xe.c(5),{className:n}=t,i=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let o,l,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),l=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),a=s.jsx(M,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=o,e[1]=l,e[2]=a):(o=e[0],l=e[1],a=e[2]);let u;return e[3]!==i?(u=s.jsxs("span",{"aria-hidden":"true",className:i,children:[o,l,a]}),e[3]=i,e[4]=u):u=e[4],u}const Rl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Zx(t,e,n){const r=Xe.c(5),[i,o]=c.useState();let l,a;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){o(void 0);return}if(!t){o(void 0);return}o(void 0);let u=!1;return(async()=>{const[d,h]=await Promise.all([Nf(t),Af(t)]).catch(eb);if(u)return;const f=Rl(d),g=Rl(h);if(!f||!g||g===f)return;const p=n||"",w=g.split("/").filter(Boolean).pop()||g;o({source:"sdk",path:g,projectDirectory:f,branch:p,label:p||w,name:w,worktreeRoot:g,worktreeStatus:"ready",headState:p?"branch":"unborn",worktreeSource:"existing"})})(),()=>{u=!0}},a=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=a):(l=r[3],a=r[4]),c.useEffect(l,a),e??i}function eb(){return["",""]}const El="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",tb=async(t,e)=>{if(t)return t.authActivate(e);const n=await ds("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:e})}),r=await n.json().catch(()=>null);if(!n.ok||!r)throw new Error(r?.error||n.statusText);return r},Ml=({className:t})=>{const{t:e}=pt(),{github:n}=An(),r=Cn(p=>p.status),i=Cn(p=>p.setStatus),[o,l]=c.useState(!1),a=c.useCallback(async p=>{if(!(!p||o)){l(!0);try{i(await tb(n,p))}catch(w){console.error("Failed to switch GitHub account:",w)}finally{l(!1)}}},[n,o,i]);if(!r?.connected)return null;const u=r.user?.login??null,d=r.user?.avatarUrl??null,h=r.accounts??[],f=u?e("header.github.connectedWithLogin",{login:u}):e("header.github.connected"),g=d?s.jsx("img",{src:d,alt:u?e("header.github.avatarWithLogin",{login:u}):e("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(M,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"});return h.length<=1?s.jsx("div",{className:Te(El,t),title:f,children:g}):s.jsxs(Js,{children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:Te(El,"p-0 hover:ring-2 hover:ring-primary/40 disabled:opacity-50",t),title:f,disabled:o,children:g})}),s.jsxs(Xs,{align:"end",className:"w-64",children:[s.jsx(go,{className:"typography-ui-header font-semibold text-foreground",children:e("header.github.accountsTitle")}),s.jsx(Es,{}),h.map(p=>{const w=p.user,v=!!p.current,x=p.source==="gh-cli"?e("header.github.accountSource.cli"):e("header.github.accountSource.oauth");return s.jsxs($t,{className:"gap-2",disabled:o,onSelect:()=>{v||a(p.id)},children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?e("header.github.avatarWithLogin",{login:w.login}):e("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(M,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:w?.name?.trim()||w?.login||"GitHub"}),w?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:w.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:x})]}):null]}),v?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null]},p.id)})]})]})};class ti extends Error{code;model;requiredChars;availableChars;constructor(e,n={}){super(e),this.name="WalkthroughError",this.code=n.code,this.model=n.model,this.requiredChars=n.requiredChars,this.availableChars=n.availableChars}}const si="/api/walkthrough",Du=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),Pu=()=>new ti("This AiWorker server has no walkthrough API",{code:"server-unsupported"}),sb=t=>!Du(t)&&(t.ok||t.status===404),Ea=async(t,e)=>{if(sb(t))throw Pu();const n=await t.json().catch(()=>null);throw new ti(typeof n?.error=="string"?n.error:e,{code:typeof n?.code=="string"?n.code:void 0,model:n?.model??void 0,requiredChars:typeof n?.requiredChars=="number"?n.requiredChars:void 0,availableChars:typeof n?.availableChars=="number"?n.availableChars:void 0})},Iu=async t=>{if(!Du(t))throw Pu();try{return await t.json()}catch{throw new ti("The server returned a malformed walkthrough response")}};async function nb(t,e,n={}){const r=await ds(si,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?Iu(r):Ea(r,"Failed to load walkthrough")}async function rb(t,e,n={}){const r=await ds(`${si}/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e,force:n.force===!0,...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}}),signal:n.signal});return r.ok?Iu(r):Ea(r,"Failed to generate walkthrough")}async function ob(t,e){const n=await ds(`${si}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await Ea(n,"Failed to cancel walkthrough generation")}async function ib(t,e,n){const r=await ds(`${si}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const i=await r.json().catch(()=>null);return typeof i?.stage=="string"?i.stage:null}const Sr={status:"idle",stage:null,result:null,readiness:null,error:null},ab=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,Dn=(t,e)=>`${Ss()}\0${t}\0${ab(e)}`,Ol=t=>t instanceof ti?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},sn=new Map,vr=new Map,lb=1e3,cb=Zn()(cu((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,i)=>{const o=Dn(n,r);t(l=>{const a={...l.selectedLanguage};return i?a[o]=i:delete a[o],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[Dn(n,r)],selectModel:(n,r,i)=>{const o=Dn(n,r);t(l=>{const a={...l.selectedModel};return i?a[o]=i:delete a[o],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[Dn(n,r)],requestSource:(n,r)=>{t(i=>({requestedSource:{...i.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const i={...r.requestedSource};return delete i[n],{requestedSource:i}})},getEntry:(n,r)=>e().entries[Dn(n,r)]??Sr,load:async(n,r,i={})=>{if(!n)return;const o=Dn(n,r);if(e().entries[o]?.status==="generating")return;sn.get(o)?.abort();const a=new AbortController;sn.set(o,a),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Sr,status:"loading",error:null}}}));try{const u=await nb(n,r,{model:e().selectedModel[o],language:i.language,signal:a.signal});if(a.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{status:"ready",stage:null,result:u,readiness:u.readiness??null,error:null}}})),u.generating&&e().generate(n,r,{language:i.language})}catch(u){if(a.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Sr,status:"error",stage:null,error:Ol(u)}}}))}finally{sn.get(o)===a&&sn.delete(o)}},generate:async(n,r,i={})=>{if(!n)return;const o=Dn(n,r);sn.get(o)?.abort();const l=new AbortController;sn.set(o,l),t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Sr,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const u=vr.get(o);u!==void 0&&(clearInterval(u),vr.delete(o))};a(),vr.set(o,setInterval(()=>{ib(n,r).then(u=>{!u||l.signal.aborted||t(d=>{const h=d.entries[o];return!h||h.status!=="generating"||h.stage===u?d:{entries:{...d.entries,[o]:{...h,stage:u}}}})}).catch(()=>{})},lb));try{const u=await rb(n,r,{force:i.force,model:e().selectedModel[o],language:i.language,signal:l.signal});if(l.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{status:"ready",stage:null,result:u,readiness:d.entries[o]?.readiness??null,error:null}}}))}catch(u){if(l.signal.aborted)return;t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Sr,status:"error",stage:null,error:Ol(u)}}}))}finally{a(),sn.get(o)===l&&sn.delete(o)}},cancel:(n,r)=>{const i=Dn(n,r);ob(n,r).catch(()=>{}),sn.get(i)?.abort(),sn.delete(i),t(o=>{const l=o.entries[i];return l?{entries:{...o.entries,[i]:{...l,status:l.result?"ready":"idle",stage:null,error:null}}}:o})},reset:()=>{for(const n of sn.values())n.abort();sn.clear();for(const n of vr.values())clearInterval(n);vr.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),db="border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)] hover:text-[var(--status-info)]",ub=3e4,Fl=20,Tu=(t,e)=>JSON.stringify([Ss(),t,e]),mb=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,i]=e;return typeof n!="string"||typeof r!="string"||typeof i!="number"?null:{runtimeKey:n,directory:r,number:i}}catch{return null}},Bl=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),eo=new Map,fb=t=>{const e=Object.entries(t);return e.length<=Fl?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Fl))},_l=Zn()((t,e)=>({entries:{},ensure:async(n,r,i,o)=>{const l=Tu(r,i),a=o?.includeCheckDetails??!1,u=e().entries[l],d=u&&u.result&&Date.now()-u.fetchedAt<ub&&(u.hasCheckDetails||!a);if(!o?.force&&d)return u.result;const h=`${l}::${a?"details":"plain"}`,g=eo.get(`${l}::details`)??(a?null:eo.get(h));if(g&&!o?.force)return g;const p=(async()=>{t(w=>({entries:{...w.entries,[l]:{...w.entries[l]??Bl(),isLoading:!0,error:null}}}));try{const w=await n.prContext(r,i,{includeDiff:!1,includeCheckDetails:a,sourceRepo:o?.sourceRepo??null});return t(v=>({entries:fb({...v.entries,[l]:{result:w,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),w}catch(w){const v=w instanceof Error?w.message:"Failed to load pull request context";return t(x=>({entries:{...x.entries,[l]:{...x.entries[l]??Bl(),isLoading:!1,error:v}}})),null}finally{eo.delete(h)}})();return eo.set(h,p),p},invalidate:(n,r)=>{t(i=>{const o={};for(const[l,a]of Object.entries(i.entries)){const u=mb(l);u&&u.directory===n&&(r==null||u.number===r)||(o[l]=a)}return{entries:o}})}})),hb=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const o of t){if(o.status==="in_progress"){e.pending+=1,e.inProgress+=1,o.startedAt&&(!n||o.startedAt<n)&&(n=o.startedAt);continue}if(o.status==="queued"){e.pending+=1,e.queued+=1;continue}const l=typeof o.conclusion=="string"?o.conclusion.toLowerCase():"";if(!l){e.pending+=1;continue}l==="success"||l==="neutral"||l==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},pb=35e3,li=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const i=e?Date.parse(e):n??Date.now();if(!Number.isFinite(i)||i<=r)return null;const o=Math.floor((i-r)/6e4);if(o<1)return"<1m";if(o<60)return`${o}m`;const l=Math.floor(o/60),a=o%60;return a>0?`${l}h ${a}m`:`${l}h`},ci=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},Ll=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},gb=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},xb=[2e3,5e3],bb=600,$l=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),In=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},yb=(t,e)=>{const n=In(t);if(!n||n.includes("->"))return"";if(e){const i=`${e}/`;return n.startsWith(i)?n.slice(i.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},wb=(t,e)=>`${t}::${e}`,Ma=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},di=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const o=t.find(l=>l.name===n);if(o)return o}const r=Ma(e.trackingBranch);if(r){const o=r==="origin"?t.find(a=>a.name==="upstream"):null;if(o)return o;const l=t.find(a=>a.name===r);if(l)return l}const i=t.find(o=>o.name==="origin");return i||(t[0]??null)},Sb=t=>t.startsWith("pr-"),vb=(t,e)=>{const n=Ma(e),r=new Map(t.map(l=>[l.name,l])),i=[],o=l=>{l&&(i.some(a=>a.name===l.name)||i.push(l))};return n&&o(r.get(n)),o(r.get("upstream")),o(r.get("origin")),t.filter(l=>!Sb(l.name)).forEach(l=>o(l)),t.forEach(l=>o(l)),i},jr=new Map,to=qo;function jb(t,e){const[n,r]=c.useState(null),[i,o]=c.useState([]),l=c.useRef(null);return c.useEffect(()=>{r(null),o([])},[t]),c.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.current=t;let a=!1;return(async()=>{try{const u=await e.repoUpstream(t);if(a||!u?.isFork||!u.upstream||(r(u.upstream),!e.repoBranches))return;try{const d=await e.repoBranches(u.upstream.owner,u.upstream.repo);a||o(d)}catch{}}catch{}})(),()=>{a=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:i}}const kb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:o=[],onGeneratedDescription:l})=>{const{t:a}=pt(),u=De(J=>J.timeFormatPreference),{github:d}=An(),h=Cn(J=>J.status),f=Cn(J=>J.hasChecked),g=De(J=>J.setSettingsDialogOpen),p=De(J=>J.setSettingsPage),w=Qe(J=>J.currentSessionId),v=Qe(J=>!!J.newSessionDraft?.open),{isMobile:x,hasTouchInput:m,screenWidth:b}=_n(),y=De(J=>J.openContextSurface),S=cb(J=>J.requestSource),N=!x&&b>=768&&!Nn(),C=c.useCallback(()=>{p("integrations"),g(!0)},[g,p]),k=c.useMemo(()=>wb(t,e),[t,e]),A=c.useMemo(()=>jr.get(k)??null,[k]),D=Hs(J=>J.ensureEntry),P=Hs(J=>J.setParams),F=Hs(J=>J.startWatching),W=Hs(J=>J.stopWatching),E=Hs(J=>J.refresh),H=Hs(J=>J.updateStatus),[z,B]=c.useState(()=>A?.title??$l(e)),[T,j]=c.useState(()=>A?.body??""),[I,_]=c.useState(()=>A?.draft??!1),[K,G]=c.useState(()=>A?.additionalContext??""),[Q,ge]=c.useState(()=>{const J=typeof A?.targetBaseBranch=="string"?In(A.targetBaseBranch):"";return J||In(n)}),[se,Y]=c.useState("squash"),[te,he]=c.useState(!1),[L,le]=c.useState(!1),[Z,ue]=c.useState(!1),[V,ee]=c.useState(!1),[be,xe]=c.useState(!1),[Ne,Pe]=c.useState(!1),[Se,Re]=c.useState(null),[ye,pe]=c.useState(""),[me,je]=c.useState(""),[ne,fe]=c.useState(!1),[ce,R]=c.useState(!1),[$,de]=c.useState(()=>di(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r})),[ie,Ae]=c.useState(!1),{detectedUpstream:Be,upstreamBranches:Ce}=jb(t,d);c.useEffect(()=>{Ae(!1)},[t]);const q=i.some(J=>J.name==="upstream"),Me=!!(t&&e&&n&&(e!==n||(q||Be!==null))),O=c.useMemo(()=>Yo(t,e,$?.name??null),[t,e,$?.name]),oe=Hs(J=>J.entries[O]),re=oe?.isLoading??!1,we=oe?.status??null,Ve=oe?.error??null,st=oe?.isInitialStatusResolved??!1,Ge=c.useMemo(()=>{const J=ie?null:$?.name?.trim()||null,ze=new Set;for(const Je of o){const mt=yb(Je,J);!mt||mt==="HEAD"||ze.add(mt)}if(ie)for(const Je of Ce)Je&&Je!=="HEAD"&&ze.add(Je);const U=In(n);U&&U!=="HEAD"&&ze.add(U);const _e=In(Q);return _e&&_e!=="HEAD"&&ze.add(_e),Array.from(ze).sort((Je,mt)=>Je.localeCompare(mt))},[n,o,$?.name,Q,Ce,ie]);c.useEffect(()=>{if(i.length===0){$&&de(null);return}(!$||!i.some(J=>J.name===$.name))&&de(di(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r}))},[A?.selectedRemoteName,i,$,r]),c.useEffect(()=>{const J=In(n);if(!Q&&J){ge(J);return}if(Ge.length!==0&&!Ge.includes(Q)){const ze=Ge.includes(J)?J:Ge[0];ze&&ge(ze)}},[Ge,n,Q]);const[ae,X]=c.useState(()=>A?.activeSegment??"overview"),[ve,Le]=c.useState(new Set),[$e,Ue]=c.useState(new Set),We=c.useRef(new Set),qe=c.useRef(null),nt=c.useRef(!1),yt=c.useRef(new Set),vt=c.useRef([]);c.useEffect(()=>{Be&&!q&&Ae(!0)},[Be,q]),c.useEffect(()=>{ie&&Be?.defaultBranch&&ge(Be.defaultBranch)},[ie,Be?.defaultBranch]);const He=we?.pr??null,Mt=He?.state==="merged"||He?.state==="closed",jt=Mt?null:He,kt=jt?Tu(t,jt.number):null,Tt=_l(J=>kt?J.entries[kt]:void 0),wt=_l(J=>J.ensure),Nt=Tt?.result??null,Dt=Tt?.isLoading??!1,ft=c.useCallback(J=>{X(J);const ze=jr.get(k);ze&&jr.set(k,{...ze,activeSegment:J})},[k]);c.useEffect(()=>{!jt||!d?.prContext||ae==="overview"||wt(d,t,jt.number,{includeCheckDetails:ae==="checks",sourceRepo:we?.repo??null})},[ae,t,wt,d,jt,we?.repo]);const Ze=we?.checks??null,ke=(Ze?.pending??0)>0,tt=Nt?.checkRuns??null,lt=Nt?.fetchedAt;c.useEffect(()=>{if(!tt||tt.length===0)return;const J=hb(tt);H(O,ze=>{if(!ze?.pr||typeof lt=="number"&&typeof ze.fetchedAt=="number"&<<ze.fetchedAt)return ze;const U=ze.checks;return U&&U.state===J.state&&U.total===J.total&&U.success===J.success&&U.failure===J.failure&&U.pending===J.pending&&U.inProgress===J.inProgress&&U.queued===J.queued&&U.startedAt===J.startedAt?ze:{...ze,checks:J,...typeof lt=="number"?{fetchedAt:lt}:{}}})},[tt,lt,O,H]),c.useEffect(()=>{if(ae!=="checks"||!ke||!He||!d?.prContext)return;const J=window.setInterval(()=>{wt(d,t,He.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null,force:!0})},pb);return()=>window.clearInterval(J)},[ae,ke,t,wt,d,He,we?.repo]);const[At,Ye]=c.useState(()=>Date.now());c.useEffect(()=>{if(!ke)return;Ye(Date.now());const J=window.setInterval(()=>Ye(Date.now()),3e4);return()=>window.clearInterval(J)},[ke]);const rt=He?`${t}#${He.number}`:null,It=!!(rt&&Se===rt);c.useEffect(()=>{if(!d?.prContext||!He||typeof He.body=="string"&&He.body.length>0)return;const J=`${t}#${He.number}`;if(We.current.has(J))return;We.current.add(J),Re(J);let ze=!1;return wt(d,t,He.number,{sourceRepo:we?.repo??null}).then(U=>{if(ze)return;const _e=U?.pr;_e&&H(O,Je=>!Je?.pr||Je.pr.number!==He.number?Je:{...Je,pr:{...Je.pr,body:_e.body||""}})}).catch(()=>{}).finally(()=>{ze||Re(U=>U===J?null:U)}),()=>{ze=!0}},[t,wt,d,He,O,we?.repo,H]),c.useEffect(()=>{if(!He){Pe(!1),pe(""),je(""),qe.current=null;return}const J=qe.current!==null&&qe.current!==He.number;J&&Pe(!1),(!Ne||J)&&(pe(He.title||""),je(He.body||"")),qe.current=He.number},[Ne,He]);const Ct=c.useCallback(J=>{if(!J)return"";const ze=Date.parse(J);return Number.isFinite(ze)?wd(ze,u,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):J},[u]),Pt=c.useMemo(()=>{const J=h?.user?.login;return typeof J=="string"?J.trim():""},[h]),Wt=c.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Yt=c.useCallback(J=>{const ze=Pt.toLowerCase(),U=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return J.replace(U,(_e,Je,mt)=>{const ht=`@${mt}`,Ft=mt.toLowerCase();return`${Je}[${ht}](https://github.com/${Ft}${ze&&Ft===ze?"?oc-self-mention=1":""})`})},[Pt]),Kt=c.useMemo(()=>{const J=(Nt?.issueComments??[]).map(_e=>({id:`issue-${_e.id}`,body:_e.body||"",authorName:_e.author?.name||_e.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:_e.author?.login||null,avatarUrl:_e.author?.avatarUrl||null,createdAt:_e.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),ze=(Nt?.reviewComments??[]).map(_e=>({id:`review-${_e.id}`,body:_e.body||"",authorName:_e.author?.name||_e.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:_e.author?.login||null,avatarUrl:_e.author?.avatarUrl||null,createdAt:_e.createdAt,context:a("gitView.pr.comments.reviewContext"),path:_e.path||null,line:_e.line??null})),U=[...J,...ze];return U.sort((_e,Je)=>{const mt=_e.createdAt?Date.parse(_e.createdAt):0,ht=Je.createdAt?Date.parse(Je.createdAt):0,Ft=Number.isFinite(mt)?mt:0,ns=Number.isFinite(ht)?ht:0;return Ft-ns}),U},[Nt,a]),Bt=c.useCallback(()=>{const J=w??(v?"draft":null);return J?{directory:t,sessionKey:J}:(Fe.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[w,t,v,a]),ts=c.useCallback((J,ze)=>{const U=ze.authorLogin?`@${ze.authorLogin}`:ze.authorName,_e=ze.path?` · ${ze.path}${ze.line?`:${ze.line}`:""}`:"";Ci.getState().addDraft(J,{source:"pr-comment",fileLabel:`PR #${He?.number??""} ${U}${_e}`,startLine:ze.line??0,endLine:ze.line??0,code:ze.body,language:"markdown",text:""})},[He?.number]),zt=c.useCallback((J,ze)=>{const U=J.status||"unknown",_e=J.conclusion??void 0,Je=_e?`${U} / ${_e}`:U,mt=J.app?.name||J.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:ze?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[ze?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:J.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:mt?`${mt} · ${Je}`:Je})]}),J.detailsUrl?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:J.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(M,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),J.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:J.output.title}):null,J.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:J.output.summary}):null,J.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap break-words max-h-48 overflow-y-auto",children:J.output.text}):null,Array.isArray(J.annotations)&&J.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",J.annotations.length>20?` (showing 20/${J.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:J.annotations.slice(0,20).map((ht,Ft)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro break-words text-[var(--status-error)]",children:[ht.title||ht.level||"Issue",ht.path?` · ${ht.path}`:"",typeof ht.startLine=="number"?`:${ht.startLine}`:"",typeof ht.endLine=="number"&&ht.endLine!==ht.startLine?`-${ht.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:ht.message}),ht.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:ht.rawDetails}):null]},`${ht.path||"file"}:${ht.startLine||Ft}:${Ft}`))})]}):null,J.job?.steps&&J.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:J.job.steps.map((ht,Ft)=>{const ns=(ht.conclusion||"").toLowerCase(),Ht=ns&&!["success","neutral","skipped"].includes(ns),Zs=`${J.id??"run"}:${J.job?.jobId??"job"}:${ht.number??Ft}:${ht.name}`,yn=ve.has(Zs);return Ht?s.jsxs(Ei,{open:yn,children:[s.jsxs("button",{type:"button",onClick:()=>{Le(ni=>{const er=new Set(ni);return er.has(Zs)?er.delete(Zs):er.add(Zs),er})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Ht?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[yn?s.jsx(M,{name:"arrow-down-s",className:"size-4"}):s.jsx(M,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:ht.name}),ht.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ht.conclusion}):null]}),s.jsx(Mi,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof ht.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",ht.number]}):null,ht.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",ht.status]}):null,ht.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",ht.conclusion]}):null,ht.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",Ct(ht.startedAt)]}):null,ht.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",Ct(ht.completedAt)]}):null]})})]},Zs):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:ht.name}),ht.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:ht.conclusion}):null]},Zs)})})]}):null]})},[ve,Ct,a]),[_t,Oe]=c.useState(!1),[Ke,et]=c.useState(!1),dt=c.useCallback(async()=>{if(!d?.prContext){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!He)return;const J=Bt();if(J){Oe(!0);try{const ze=await wt(d,t,He.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null});if(!ze){Fe.error(a("gitView.pr.toast.loadChecksFailed"));return}const _e=(ze.checkRuns??[]).filter(mt=>ci(mt.conclusion));if(_e.length===0){Fe.message(a("gitView.pr.toast.noFailedChecks"));return}const Je=Ci.getState();for(const mt of _e){const ht=(mt.annotations??[]).map(Ht=>[[Ht.level,Ht.title].filter(Boolean).join(" "),Ht.path?`${Ht.path}${typeof Ht.startLine=="number"?`:${Ht.startLine}`:""}`:null,Ht.message,Ht.rawDetails].filter(Boolean).join(`
|
|
38
|
-
`)),Ft=(mt.job?.steps??[]).filter(Ht=>ci(Ht.conclusion)).map(Ht=>`step ${Ht.number??"?"}: ${Ht.name} → ${Ht.conclusion}`),ns=[`check: ${mt.job?.workflowName?`${mt.job.workflowName} / ${mt.name}`:mt.name}`,`status: ${mt.status??"unknown"} / ${mt.conclusion??"unknown"}`,mt.detailsUrl?`url: ${mt.detailsUrl}`:null,mt.output?.title?`title: ${mt.output.title}`:null,mt.output?.summary?`summary:
|
|
39
|
-
${mt.output.summary}`:null,Ft.length>0?`failed steps:
|
|
40
|
-
${Ft.join(`
|
|
41
|
-
`)}`:null,ht.length>0?`annotations:
|
|
42
|
-
${ht.join(`
|
|
43
|
-
---
|
|
44
|
-
`)}`:null].filter(Boolean).join(`
|
|
45
|
-
|
|
46
|
-
`);Je.addDraft(J,{source:"pr-check",fileLabel:`PR #${He.number} · ${mt.name}`,startLine:0,endLine:0,code:ns,language:"text",text:""})}}catch(ze){const U=ze instanceof Error?ze.message:String(ze);Fe.error(a("gitView.pr.toast.loadChecksFailed"),{description:U})}finally{Oe(!1)}}},[t,wt,d,He,Bt,we?.repo,a]),ut=c.useCallback(async()=>{if(!d?.prContext){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!He)return;const J=Bt();if(J){et(!0);try{if(!await wt(d,t,He.number,{sourceRepo:we?.repo??null})){Fe.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Kt.length===0){Fe.message(a("gitView.pr.toast.noPrComments"));return}for(const U of Kt)ts(J,U)}catch(ze){const U=ze instanceof Error?ze.message:String(ze);Fe.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:U})}finally{et(!1)}}},[ts,t,wt,d,He,Bt,we?.repo,a,Kt]),St=c.useCallback(async J=>{const ze=Bt();ze&&ts(ze,J)},[ts,Bt]),ot=c.useCallback(async J=>{await E(O,J)},[O,E]),[Lt,Qt]=c.useState(!1),us=c.useRef(!0);c.useEffect(()=>(us.current=!0,()=>{us.current=!1}),[]);const $s=c.useCallback(async()=>{if(Lt)return;Qt(!0);const J=Date.now();try{await ot({force:!0})}finally{const ze=bb-(Date.now()-J);ze>0&&await new Promise(U=>window.setTimeout(U,ze)),us.current&&Qt(!1)}},[Lt,ot]),rs=c.useCallback(()=>{vt.current.forEach(J=>{window.clearTimeout(J)}),vt.current=xb.map(J=>window.setTimeout(()=>{ot({force:!0,silent:!0,markInitialResolved:!0})},J))},[ot]);c.useEffect(()=>{if(!d?.prStatus||!Me||i.length<=1||nt.current||we?.pr)return;const J=`${k}::${$?.name??""}`;if(yt.current.has(J))return;yt.current.add(J);const ze=vb(i,r).filter(Je=>Je.name!==$?.name);if(ze.length===0)return;let U=!1;return(async()=>{for(const Je of ze){if(U)return;try{if(!(await d.prStatus(t,e,Je.name))?.pr)continue;if(U)return;de(ht=>ht?.name===Je.name?ht:Je);return}catch{}}})(),()=>{U=!0}},[e,Me,t,d,i,$?.name,k,we?.pr,r]),c.useEffect(()=>{D(O),P(O,{directory:t,branch:e,remoteName:$?.name??null,canShow:Me,github:d,githubAuthChecked:f,githubConnected:h?.connected??null})},[e,Me,t,D,d,f,h?.connected,O,$?.name,P]),c.useEffect(()=>(F(O),()=>{W(O)}),[O,F,W]),c.useEffect(()=>{const J=jr.get(k)??null;B(J?.title??$l(e)),j(J?.body??""),_(J?.draft??!1),ge(J?.targetBaseBranch?In(J.targetBaseBranch):In(n));const ze=di(i,{selectedRemoteName:J?.selectedRemoteName,trackingBranch:r});de(U=>U?.name===ze?.name?U:ze)},[n,e,i,k,r]),c.useEffect(()=>{ot({markInitialResolved:!0})},[O,ot]),c.useEffect(()=>{!Me||!$?.name||ot({force:!0,silent:!0,markInitialResolved:!0})},[Me,ot,$?.name]),c.useEffect(()=>{const J=we?.resolvedRemoteName?.trim();if(!J||nt.current)return;const ze=i.find(U=>U.name===J);ze&&de(U=>U?.name===ze.name?U:ze)},[i,we?.resolvedRemoteName]),c.useEffect(()=>{const J=()=>{const U=Hs.getState().entries[O]?.lastRefreshAt??0;Date.now()-U>6e4&&ot({force:!0,silent:!0})},ze=()=>{document.visibilityState==="visible"&&J()};return window.addEventListener("focus",J),document.addEventListener("visibilitychange",ze),()=>{window.removeEventListener("focus",J),document.removeEventListener("visibilitychange",ze)}},[O,ot]),c.useEffect(()=>{f&&h?.connected===!1&&ot({force:!0,silent:!0,markInitialResolved:!0})},[f,h,ot]),c.useEffect(()=>{!t||!e||jr.set(k,{title:z,body:T,draft:I,additionalContext:K,targetBaseBranch:Q,selectedRemoteName:$?.name,activeSegment:ae})},[k,z,T,I,K,Q,$?.name,t,e,ae]),c.useEffect(()=>{const J=vt.current;return()=>{J.forEach(ze=>{window.clearTimeout(ze)}),vt.current=[]}},[]);const Is=c.useCallback(async()=>{if(!te&&t){he(!0);try{const ze={base:ie&&Be?.defaultBranchSha?Be.defaultBranchSha:Q,head:e};K&&(ze.context=K);const U=await Df(t,ze);U.title?.trim()&&B(U.title.trim()),U.body?.trim()&&j(U.body.trim()),l?.()}catch(J){const ze=J instanceof Error?J.message:String(J);Fe.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:ze})}finally{he(!1)}}},[K,e,Be?.defaultBranchSha,t,te,l,Q,a,ie]),ss=c.useCallback(async()=>{if(!d?.prCreate){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const J=z.trim();if(!J){Fe.error(a("gitView.pr.toast.titleRequired"));return}const ze=Q.trim();if(!ze){Fe.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!ie&&ze===e){Fe.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}le(!0);try{const U=Ma(r),_e=ie&&Be,Je=await d.prCreate({directory:t,title:J,head:e,base:ze,...T.trim()?{body:T}:{},draft:I,..._e?{targetRepo:{owner:Be.owner,repo:Be.repo},headRemote:"origin"}:{...$?{remote:$.name}:{},...U&&U!==$?.name?{headRemote:U}:{}}});Fe.success(a("gitView.pr.toast.prCreated")),H(O,mt=>mt&&{...mt,pr:Je}),await ot({force:!0}),rs()}catch(U){const _e=U instanceof Error?U.message:String(U);Fe.error(a("gitView.pr.toast.createPrFailed"),{description:_e})}finally{le(!1)}},[T,e,Be,t,I,d,O,ot,rs,$,Q,z,r,H,ie,a]),Ns=c.useCallback(async J=>{if(!d?.prMerge){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}ee(!0);try{const ze=await d.prMerge({directory:t,number:J.number,method:se});ze.merged?Fe.success(a("gitView.pr.toast.prMerged")):Fe.message(a("gitView.pr.toast.prNotMerged"),{description:ze.message||a("gitView.pr.notMergeable")}),await ot({force:!0}),rs()}catch(ze){const U=ze instanceof Error?ze.message:String(ze);Fe.error(a("gitView.pr.toast.mergeFailed"),{description:U}),J.url&&to(J.url)}finally{ee(!1)}},[t,d,se,ot,rs,a]),Ws=c.useCallback(async J=>{if(!d?.prReady){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}xe(!0);try{await d.prReady({directory:t,number:J.number}),Fe.success(a("gitView.pr.toast.markedReady")),await ot({force:!0}),rs()}catch(ze){const U=ze instanceof Error?ze.message:String(ze);Fe.error(a("gitView.pr.toast.markReadyFailed"),{description:U}),J.url&&to(J.url)}finally{xe(!1)}},[t,d,ot,rs,a]),cn=c.useCallback(async J=>{if(!d?.prUpdate){Fe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const ze=ye.trim();if(!ze){Fe.error(a("gitView.pr.toast.titleRequired"));return}ue(!0);try{const U=await d.prUpdate({directory:t,number:J.number,title:ze,body:me});H(O,_e=>_e&&{..._e,pr:{..._e.pr??J,...U}}),Pe(!1),Fe.success(a("gitView.pr.toast.prUpdated")),await ot({force:!0}),rs()}catch(U){const _e=U instanceof Error?U.message:String(U);Fe.error(a("gitView.pr.toast.updatePrFailed"),{description:_e})}finally{ue(!1)}},[t,me,ye,d,O,ot,rs,H,a]);if(!Me)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("gitView.pullRequest.title")}),s.jsx(Ml,{})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pullRequest.availableOnFeatureBranches")})]})});const bn=we?.repo?.url||null,ms=ie&&Be?.url?Be.url:bn,xs=!!we?.canMerge,zs=!!we?.connected,an=f&&we?.connected===!1,is=gb(we),Vs=is?`var(--pr-${is})`:"var(--status-info)",Rt=is==="draft"?"git-pr-draft":is==="merged"?"git-merge":is==="closed"?"git-close-pull-request":"git-pull-request",Ot=He?[`${He.state}${He.draft?" (draft)":""}`,He.mergeable===!1?a("gitView.pr.notMergeable"):null,He.state==="open"&&typeof He.mergeableState=="string"&&He.mergeableState&&He.mergeableState!=="unknown"?He.mergeableState:null].filter(Boolean).join(" · "):"",Xt=Ze?Ze.total>0?`${Ze.success}/${Ze.total} ${a("gitView.pr.checks.label")}`:`${Ze.state} ${a("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"@container/pr-actions flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[He?s.jsxs(at,{type:"button",variant:"outline",size:"xs",className:"shrink-0",onClick:()=>{to(He.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(M,{name:Rt,className:"size-4 shrink-0",style:{color:Vs}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(M,{name:Rt,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:a("gitView.pullRequest.title")}),He?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",He.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[He&&N?s.jsxs(at,{variant:"outline",size:"sm",className:Te("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",db),onClick:()=>{S(t,{kind:"pr",number:He.number}),y(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(M,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{variant:"ghost",size:"sm",className:"h-7 w-7 px-0",disabled:re||Lt,onClick:()=>{$s()},"aria-label":a("gitView.pr.actions.refreshAria"),children:re||Lt?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):s.jsx(M,{name:"refresh",className:"size-4 text-muted-foreground"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]}),s.jsx(Ml,{className:"h-7 w-7"})]})]}),He?s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Vs},children:Ot}),Ze?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Ll(Ze.state)}`}),Xt]}):null,r&&$&&r.split("/")[0]!==$.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",$.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[xs&&He.draft&&He.state==="open"?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Ws(He),disabled:be||V||Z||Ne,"aria-label":a("gitView.pr.actions.markReadyAria"),children:be?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,xs?s.jsxs(s.Fragment,{children:[s.jsxs(Ms,{value:se,onValueChange:J=>Y(J),disabled:V||He.state!=="open",children:[s.jsx(Os,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Cs,{})}),s.jsxs(Fs,{children:[s.jsx(es,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(es,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(es,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Ns(He),disabled:V||be||He.state!=="open"||He.draft||Z||Ne,"aria-label":a("gitView.pr.actions.mergePrAria"),children:V?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"git-merge",className:"size-4"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[an?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(at,{variant:"outline",size:"sm",onClick:C,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,Ve?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:Ve}),ms?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ms,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(M,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!He&&!st&&!Ve&&!an?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):He&&!Mt?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(Qd,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:Ze&&Ze.total>0?`${a("gitView.pr.segment.checks")} ${Ze.success}/${Ze.total}`:a("gitView.pr.segment.checks"),icon:Ze?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Ll(Ze.state)}`}):void 0},{id:"comments",label:Nt?`${a("gitView.pr.segment.comments")} ${(Nt.issueComments?.length??0)+(Nt.reviewComments?.length??0)}`:a("gitView.pr.segment.comments")}],activeId:ae,onSelect:J=>ft(J),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),ae==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[xs&&He.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,xs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.noMergePermission")}),s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:Ne?s.jsx(jn,{value:ye,onChange:J=>pe(J.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:He.title})}),He.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:Ne?s.jsxs(s.Fragment,{children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{Pe(!1),pe(He.title||""),je(He.body||"")},disabled:Z,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(M,{name:"close",className:"size-4"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>cn(He),disabled:Z||!ye.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:Z?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"check",className:"size-4"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Pe(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(M,{name:"edit",className:"size-4"})})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),Ne?s.jsx(or,{value:me,onChange:J=>je(J.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m}):null,Ne?null:He.body?.trim()?s.jsx(el,{content:He.body,className:"typography-markdown-body min-w-0 text-muted-foreground break-words",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:a(It?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,ae==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[Ze&&Ze.total>0?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-muted/40",children:[Ze.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${Ze.success/Ze.total*100}%`}}):null,Ze.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${Ze.failure/Ze.total*100}%`}}):null,Ze.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${Ze.pending/Ze.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Ze.success,"/",Ze.total," ",a("gitView.pr.checks.label")]}),(Ze.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(M,{name:"loader-4",className:"size-3.5 animate-spin"}),li(Ze.startedAt,void 0,At)]}):null]}):null,Ze?.failure?s.jsxs(at,{variant:"outline",size:"sm",className:"w-fit gap-1.5 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:dt,disabled:_t,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[_t?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"ai-generate-2",className:"size-4"}),a("gitView.pr.actions.resolveFailedChecks")]}):null,(Nt?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(Nt?.checkRuns??[]).map((J,ze)=>{const U=`${J.id??"run"}:${J.name}:${ze}`,_e=J.status==="in_progress",Je=J.status==="queued",mt=ci(J.conclusion),ht=$e.has(U),Ft=!!(J.output?.title||J.output?.summary||J.output?.text||(J.annotations?.length??0)>0||(J.job?.steps?.length??0)>0||J.detailsUrl),ns=J.job?.workflowName,Ht=_e?li(J.startedAt,void 0,At):li(J.startedAt,J.completedAt);return s.jsxs("div",{className:Te("rounded-md border border-border/40",mt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!Ft,onClick:()=>{Ue(Zs=>{const yn=new Set(Zs);return yn.has(U)?yn.delete(U):yn.add(U),yn})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[_e?s.jsx(M,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):Je?s.jsx(M,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):mt?s.jsx(M,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(M,{name:"checkbox-circle",className:"size-4 shrink-0 text-[var(--status-success)]"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ns&&ns!==J.name?`${ns} / ${J.name}`:J.name}),Ht?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Ht}):null,Ft?s.jsx(M,{name:"arrow-down-s",className:Te("size-4 shrink-0 text-muted-foreground transition-transform",ht&&"rotate-180")}):null]}),ht&&Ft?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:zt(J,{hideHeader:!0})}):null]},U)})}):Dt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.checkDetails.empty")})]}):null,ae==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Kt.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(at,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)]",onClick:ut,disabled:Ke,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Ke?s.jsx(M,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(M,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Kt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Kt.map((J,ze)=>{const U=(J.authorName||"?").charAt(0).toUpperCase(),_e=ze===Kt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[_e?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:J.avatarUrl?s.jsx("img",{src:J.avatarUrl,alt:J.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:U})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[J.authorName,J.authorLogin&&J.authorLogin!==J.authorName?` · @${J.authorLogin}`:""]}),J.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:Ct(J.createdAt)}):null,s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsxs(at,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{St(J)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(M,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(bt,{children:s.jsx("p",{children:a("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[J.context,J.path?` · ${J.path}`:"",J.line?`:${J.line}`:""]}),s.jsx(el,{content:Yt(J.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Wt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},J.id)})})}):Dt&&!Nt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[He&&Mt?s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md border border-border/60 bg-surface-muted/40 px-2.5 py-2",children:[s.jsx(M,{name:He.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:Vs}}),s.jsx("div",{className:"min-w-0 flex-1 typography-micro text-muted-foreground",children:He.state==="merged"?a("gitView.pr.history.merged",{number:He.number,base:He.base||Q}):a("gitView.pr.history.closed",{number:He.number})}),s.jsx(at,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{to(He.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(M,{name:"external-link",className:"size-3.5"})})]}):null,s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",Q," ",s.jsxs("span",{className:"opacity-60",children:["(",ie&&Be?"upstream":"remote",")"]})]})]}),ms?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ms,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(M,{name:"external-link",className:"size-4"}),a("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.title")}),s.jsx(jn,{value:z,onChange:J=>B(J.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.baseBranch")}),Ge.length>0?s.jsxs(Ms,{value:Q,onValueChange:ge,children:[s.jsx(Os,{size:"lg",children:s.jsx(Cs,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Fs,{children:Ge.map(J=>s.jsx(es,{value:J,children:J},J))})]}):s.jsx(jn,{value:Q,onChange:J=>ge(J.target.value),placeholder:a("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.description")}),s.jsx(or,{value:T,onChange:J=>j(J.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:m?"on":"off",autoCapitalize:m?"sentences":"off",spellCheck:m})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":I,onClick:()=>_(J=>!J),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),_(ze=>!ze))},children:[s.jsx(lr,{size:"sm",checked:I,onChange:J=>_(J),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),x?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx(at,{variant:"outline",size:"sm",onClick:()=>R(!0),children:K.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),K.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:a("gitView.pr.additionalContext.added")})})]}):s.jsxs(Ei,{open:ne,onOpenChange:fe,children:[s.jsxs(Yd,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ne?a("gitView.pr.actions.hide"):K.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(Mi,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(or,{value:K,onChange:J=>G(J.target.value),className:"min-h-[100px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Xo,{open:ce,onClose:()=>R(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(at,{size:"sm",onClick:()=>R(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(or,{value:K,onChange:J=>G(J.target.value),className:"min-h-[200px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(at,{variant:"outline",size:"sm",onClick:Is,disabled:te||L,children:[te?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(at,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:ss,disabled:L||!zs||!Q.trim()||!ie&&Q.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:L?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(M,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},Cb=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:i,defaultBranch:o,headBranch:l}=t,a=typeof l=="string"?l.trim():"",u=p=>{if(!p)return"";let w=p.trim();if(!w||w==="HEAD")return"";if(n.includes(w))return w;w.startsWith("refs/heads/")&&(w=w.slice(11)),w.startsWith("heads/")&&(w=w.slice(6)),w.startsWith("remotes/")&&(w=w.slice(8));const v=w.indexOf("/");if(v>0){const x=w.slice(0,v);if(e.has(x)){const m=w.slice(v+1).trim();m&&(w=m)}}return w},d=p=>{const w=u(typeof p=="string"?p:"");return w&&w!==a?w:""},h=d(r);if(h)return h;const f=d(i);if(f)return f;const g=d(o);return g||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},q5=t=>{const{baseBranch:e,localBranches:n,remoteBranches:r}=t;return n.includes(e)?!0:r.some(i=>{const o=i.indexOf("/");return o>0&&i.slice(o+1)===e})},ui=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),so=new Map,no=new Map,Pn=t=>`${Ss()}::${t}`,Nb=()=>{const t=Xe.c(115),{t:e}=pt(),{git:n}=An(),r=qr(),{rootIsGitRepo:i,gitDirectory:o,nestedRepos:l}=Pf(r??null),a=ba(o??null),u=Sd(o??null),d=vd(o??null),{ensureAll:h,ensureNestedRepos:f,selectNestedRepo:g}=On(Xn(Ab)),p=Qe(Db),w=Qe(Pb),v=Qe(Ib),x=Qe(Tb);let m;t[0]!==r?(m=ui(r),t[0]=r,t[1]=m):m=t[1];const b=m;let y;if(t[2]!==x||t[3]!==b||t[4]!==v){e:{if(!b){y=void 0;break e}let $;if(t[6]!==x||t[7]!==b){let ie;t[9]!==b?(ie=Ae=>ui(Ae.path)===b,t[9]=b,t[10]=ie):ie=t[10],$=x.find(ie),t[6]=x,t[7]=b,t[8]=$}else $=t[8];const de=$;if(de){y=de;break e}for(const ie of v.values())if(ui(ie.path)===b){y=ie;break e}y=void 0}t[2]=x,t[3]=b,t[4]=v,t[5]=y}else y=t[5];const S=y;let N;t[11]!==p||t[12]!==S||t[13]!==w?.open||t[14]!==v?(N=()=>{if(p)return v.get(p)??S;if(w?.open)return S},t[11]=p,t[12]=S,t[13]=w?.open,t[14]=v,t[15]=N):N=t[15],w?.open;let C;t[16]!==N?(C=N(),t[16]=N,t[17]=C):C=t[17];const k=C;let A;t[18]!==p?(A=$=>p?$.getAttachment(p):void 0,t[18]=p,t[19]=A):A=t[19];const D=xd(A),P=D&&!D.degraded&&!D.legacy?D.worktreeRoot??void 0:void 0,F=Zx(r,k,a?.current??void 0);let W,E;t[20]!==h||t[21]!==n||t[22]!==o?(W=()=>{!o||!n||h(o,n)},E=[o,h,n],t[20]=h,t[21]=n,t[22]=o,t[23]=W,t[24]=E):(W=t[23],E=t[24]),c.useEffect(W,E);const[H,z]=c.useState(null);let B;t[25]!==P||t[26]!==F?.projectDirectory?(B=()=>{const $=P||F?.projectDirectory;if(!$){z(null);return}let de=!1;return Jo($).then(ie=>{if(de)return;const Ae=ie.trim();z(Ae&&Ae!=="HEAD"?Ae:null)}).catch(()=>{de||z(null)}),()=>{de=!0}},t[25]=P,t[26]=F?.projectDirectory,t[27]=B):B=t[27];const T=F?.projectDirectory;let j;t[28]!==P||t[29]!==T?(j=[P,T],t[28]=P,t[29]=T,t[30]=j):j=t[30],c.useEffect(B,j);let I;t[31]!==o?(I=()=>(o?so.get(Pn(o)):void 0)??[],t[31]=o,t[32]=I):I=t[32];const[_,K]=c.useState(I);let G;t[33]!==o?(G=()=>(o?no.get(Pn(o)):void 0)??null,t[33]=o,t[34]=G):G=t[34];const[Q,ge]=c.useState(G);let se,Y;t[35]!==n||t[36]!==o?(se=()=>{if(!o||!n?.getRemotes){K([]);return}K(so.get(Pn(o))??[]);let $=!1;return n.getRemotes(o).then(de=>{$||(so.set(Pn(o),de??[]),K(de??[]))}).catch(()=>{$||K(so.get(Pn(o))??[])}),()=>{$=!0}},Y=[o,n],t[35]=n,t[36]=o,t[37]=se,t[38]=Y):(se=t[37],Y=t[38]),c.useEffect(se,Y);let te,he;t[39]!==n||t[40]!==o?(te=()=>{if(!o||!n?.getRemoteUrl){ge(null);return}ge(no.get(Pn(o))??null);let $=!1;return n.getRemoteUrl(o).then(de=>{$||(no.set(Pn(o),de),ge(de))}).catch(()=>{$||ge(no.get(Pn(o))??null)}),()=>{$=!0}},he=[o,n],t[39]=n,t[40]=o,t[41]=te,t[42]=he):(te=t[41],he=t[42]),c.useEffect(te,he);let L;e:{if(!u?.all){let de;t[43]===Symbol.for("react.memo_cache_sentinel")?(de=[],t[43]=de):de=t[43],L=de;break e}let $;t[44]!==u.all?($=u.all.filter(Rb).sort(),t[44]=u.all,t[45]=$):$=t[45],L=$}const le=L;let Z;e:{if(!u?.all){let de;t[46]===Symbol.for("react.memo_cache_sentinel")?(de=[],t[46]=de):de=t[46],Z=de;break e}let $;t[47]!==u.all?($=u.all.filter(Eb).map(Mb).sort(),t[47]=u.all,t[48]=$):$=t[48],Z=$}const ue=Z;let V;t[49]!==ue||t[50]!==Q||t[51]!==_||t[52]!==a?.tracking?(V=()=>{if(_.length>0)return _;const $=new Set,de=a?.tracking?.trim();de&&de.includes("/")&&$.add(de.split("/")[0]);for(const ie of ue){const Ae=ie.indexOf("/");Ae>0&&$.add(ie.slice(0,Ae))}return $.size===0&&Q&&$.add("origin"),Array.from($).map(ie=>({name:ie,fetchUrl:Q??"",pushUrl:Q??""}))},t[49]=ue,t[50]=Q,t[51]=_,t[52]=a?.tracking,t[53]=V):V=t[53],a?.tracking;let ee;t[54]!==V?(ee=V(),t[54]=V,t[55]=ee):ee=t[55];const be=ee,xe=a?.current??null;a?.tracking;let Ne;t[56]!==a?.tracking?(Ne=a?.tracking?.trim().split("/")[0],t[56]=a?.tracking,t[57]=Ne):Ne=t[57];const Pe=Ne,Se=(Pe&&u?.defaultBranches?.[Pe])??u?.defaultBranches?.origin;let Re;t[58]!==xe||t[59]!==Se||t[60]!==be||t[61]!==le||t[62]!==H||t[63]!==F?.createdFromBranch?(Re=()=>Cb({remoteNames:new Set(be.map(Ob)),localBranches:le,worktreeCreatedFromBranch:F?.createdFromBranch,rootBranchHint:H,defaultBranch:Se,headBranch:xe}),t[58]=xe,t[59]=Se,t[60]=be,t[61]=le,t[62]=H,t[63]=F?.createdFromBranch,t[64]=Re):Re=t[64],F?.createdFromBranch;let ye;t[65]!==Re?(ye=Re(),t[65]=Re,t[66]=ye):ye=t[66];const pe=ye;if(!r){let $;t[67]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(M,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=$):$=t[67];let de;t[68]!==e?(de=e("gitView.pullRequest.title"),t[68]=e,t[69]=de):de=t[69];let ie;t[70]!==de?(ie=s.jsx("div",{className:"typography-ui-header text-foreground",children:de}),t[70]=de,t[71]=ie):ie=t[71];let Ae;t[72]!==e?(Ae=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=Ae):Ae=t[73];let Be;t[74]!==Ae?(Be=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Ae}),t[74]=Ae,t[75]=Be):Be=t[75];let Ce;return t[76]!==ie||t[77]!==Be?(Ce=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[$,ie,Be]}),t[76]=ie,t[77]=Be,t[78]=Ce):Ce=t[78],Ce}if(i===!1&&d!==!0){let $;t[79]!==r||t[80]!==f?($=()=>{f(r,{force:!0})},t[79]=r,t[80]=f,t[81]=$):$=t[81];let de;return t[82]!==d||t[83]!==l||t[84]!==i||t[85]!==$?(de=s.jsx(Lp,{rootIsGitRepo:i,resolvedIsGitRepo:d,nestedRepos:l,onRetryDiscovery:$}),t[82]=d,t[83]=l,t[84]=i,t[85]=$,t[86]=de):de=t[86],de}if(!xe){let $;t[87]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(M,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[87]=$):$=t[87];let de;t[88]!==e?(de=e("gitView.pullRequest.title"),t[88]=e,t[89]=de):de=t[89];let ie;t[90]!==de?(ie=s.jsx("div",{className:"typography-ui-header text-foreground",children:de}),t[90]=de,t[91]=ie):ie=t[91];let Ae;t[92]!==e?(Ae=e("gitView.pullRequest.createHint"),t[92]=e,t[93]=Ae):Ae=t[93];let Be;t[94]!==Ae?(Be=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Ae}),t[94]=Ae,t[95]=Be):Be=t[95];let Ce;return t[96]!==ie||t[97]!==Be?(Ce=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[$,ie,Be]}),t[96]=ie,t[97]=Be,t[98]=Ce):Ce=t[98],Ce}const me=i===!1&&Array.isArray(l)&&l.length>0;let je;t[99]!==r||t[100]!==o||t[101]!==l||t[102]!==g||t[103]!==me?(je=me?s.jsx("div",{className:"flex shrink-0 items-center border-b border-border/60 px-4 py-2",children:s.jsx($p,{repositories:l,selectedRepository:o??null,onSelectRepository:$=>{r&&g(r,$)},repositoryRoot:r??void 0})}):null,t[99]=r,t[100]=o,t[101]=l,t[102]=g,t[103]=me,t[104]=je):je=t[104];const ne=o??r,fe=a?.tracking??void 0;let ce;t[105]!==pe||t[106]!==xe||t[107]!==ue||t[108]!==_||t[109]!==ne||t[110]!==fe?(ce=s.jsx(kn,{as:ya,outerClassName:"h-full min-h-0 flex-1",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(kb,{directory:ne,branch:xe,baseBranch:pe,trackingBranch:fe,remotes:_,remoteBranches:ue})}),t[105]=pe,t[106]=xe,t[107]=ue,t[108]=_,t[109]=ne,t[110]=fe,t[111]=ce):ce=t[111];let R;return t[112]!==je||t[113]!==ce?(R=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[je,ce]}),t[112]=je,t[113]=ce,t[114]=R):R=t[114],R};function Ab(t){return{ensureAll:t.ensureAll,ensureNestedRepos:t.ensureNestedRepos,selectNestedRepo:t.selectNestedRepo}}function Db(t){return t.currentSessionId}function Pb(t){return t.newSessionDraft}function Ib(t){return t.worktreeMetadata}function Tb(t){return t.availableWorktrees}function Rb(t){return!t.startsWith("remotes/")}function Eb(t){return t.startsWith("remotes/")}function Mb(t){return t.replace(/^remotes\//,"")}function Ob(t){return t.name}const Hi=2e4,Fb=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},ro=(t,e)=>Mf(Of.getState().dictionary,t,e),Bb=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},_b=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const i=await ds(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!i.ok){const o=await i.json().catch(()=>({error:i.statusText}));throw new Error(o.error||"Failed to read file")}return i.text()},Ru=async(t,e,n)=>{if(If(e)||Tf(e)||Rf(e))return{ok:!0};try{const r=await _b(t,e,n);return Ef(r)?{ok:!1,reason:"binary"}:Fb(r,Hi)>Hi?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:Bb(r)}}},Eu=t=>{if(t==="too-large"){const e=Hi.toLocaleString(pa());return ro("contextFileOpen.failure.tooLarge",{count:e})}return ro(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},Wl=8;let Gi=null;const Mu=t=>{Gi={x:t.clientX,y:t.clientY}},Ou=t=>{const e=Gi;return Gi=null,!e||t.dataTransfer&&t.dataTransfer.dropEffect!=="none"?!1:Math.abs(t.clientX-e.x)<=Wl&&Math.abs(t.clientY-e.y)<=Wl},zl=3,cr=t=>Array.from(t.types).includes("Files"),Lb=t=>{const e=Array.from(t.items);return e.length===0?Array.from(t.files):e.flatMap(n=>{if(n.kind!=="file"||n.webkitGetAsEntry()?.isDirectory)return[];const r=n.getAsFile();return r?[r]:[]})},Vl=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},$b=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),as=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Oa=(t,e)=>{const n=as(e),r=as(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Wb=(t,e)=>{const n=Oa(t,e);if(n!==".")return n;const r=as(t);return r.split("/").filter(Boolean).pop()??r},zb=t=>{const e=as(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},Vb=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ub=new Set(["node_modules"]),Kb=t=>Ub.has(t),Hb=t=>{const e=as(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Gb=8,un=new Map,Fa=t=>JSON.stringify([Ss(),t]),qb=t=>{const e=Fa(t),n=un.get(e);return n?(n.touchedAt=Date.now(),un.delete(e),un.set(e,n),n):null},mi=t=>{const e=Fa(t),n=un.get(e);if(n)return n.touchedAt=Date.now(),n;if(un.size>=Gb){const i=un.keys().next().value;i!==void 0&&un.delete(i)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return un.set(e,r),r},Qb=t=>{un.delete(Fa(t))},Fu=(t,e)=>s.jsx(wa,{filePath:t,extension:e}),Yb=t=>{const e=Xe.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const i=r[n];let o;return e[1]!==i?(o=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=o):o=e[2],o},Xb=t=>{const e=Xe.c(87),{node:n,root:r,isExpanded:i,isActive:o,isBrowserClient:l,status:a,badge:u,isDropTarget:d,canUpload:h,permissions:f,downloadFile:g,onSelect:p,onToggle:w,onRevealPath:v,onOpenDialog:x,onSetDropTarget:m,onDropFiles:b}=t,{t:y}=pt(),S=n.type==="directory";let N;e[0]!==S||e[1]!==n.path?(N=S?n.path:zb(n.path),e[0]=S,e[1]=n.path,e[2]=N):N=e[2];const C=N,{canRename:k,canCreateFile:A,canCreateFolder:D,canDelete:P,canReveal:F}=f,W=!S&&!!g,E=F&&!l,H=k||A||D||P||W||E,[z,B]=c.useState(!1),[T,j]=c.useState(!1);let I;e[3]!==H?(I=$=>{H&&($?.preventDefault(),j(!0))},e[3]=H,e[4]=I):I=e[4];const _=I;let K;e[5]!==S||e[6]!==n||e[7]!==p||e[8]!==w?(K=()=>{S?w(n.path):p(n)},e[5]=S,e[6]=n,e[7]=p,e[8]=w,e[9]=K):K=e[9];const G=K;let Q;e[10]===Symbol.for("react.memo_cache_sentinel")?(Q=$=>{$.stopPropagation(),j(!1),B(!0)},e[10]=Q):Q=e[10];const ge=Q;let se;e[11]!==A||e[12]!==D||e[13]!==P||e[14]!==k||e[15]!==E||e[16]!==g||e[17]!==l||e[18]!==S||e[19]!==n||e[20]!==x||e[21]!==v||e[22]!==y?(se=$=>{const{Item:de,Separator:ie}=$;return s.jsxs(s.Fragment,{children:[k&&s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),x("rename",n)},children:[s.jsx(M,{name:"edit",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),fn(n.path).then(Be=>{if(Be.ok){Fe.success(y("sidebarFilesTree.toast.pathCopied"));return}Fe.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(M,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),!S&&g&&s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),g(n.path).catch(Be=>{console.error("Download failed:",Be),Fe.error(y("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(M,{name:"download",className:"mr-2 h-4 w-4"})," ",y(l?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),E&&s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),v(n.path)},children:[s.jsx(M,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",y(md())]}),S&&(A||D)&&s.jsxs(s.Fragment,{children:[s.jsx(ie,{}),A&&s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),x("createFile",n)},children:[s.jsx(M,{name:"file-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFile")]}),D&&s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),x("createFolder",n)},children:[s.jsx(M,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(ie,{}),s.jsxs(de,{onClick:Ae=>{Ae.stopPropagation(),x("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(M,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})},e[11]=A,e[12]=D,e[13]=P,e[14]=k,e[15]=E,e[16]=g,e[17]=l,e[18]=S,e[19]=n,e[20]=x,e[21]=v,e[22]=y,e[23]=se):se=e[23];const Y=se;let te;e[24]!==n.path||e[25]!==r?(te=$=>{Mu($);const de=Oa(r,n.path);!de||de==="."||($.dataTransfer.setData("application/x-openchamber-file-path",de),$.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=te):te=e[26];const he=te;let L;e[27]!==G?(L=$=>{Ou($)&&G()},e[27]=G,e[28]=L):L=e[28];const le=L;let Z;e[29]!==h||e[30]!==m||e[31]!==C?(Z=$=>{!h||!C||!cr($.dataTransfer)||($.preventDefault(),$.stopPropagation(),$.dataTransfer.dropEffect="copy",m(C))},e[29]=h,e[30]=m,e[31]=C,e[32]=Z):Z=e[32];const ue=Z;let V;e[33]!==h||e[34]!==m||e[35]!==C?(V=$=>{!h||!C||!cr($.dataTransfer)||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||($.stopPropagation(),m(null))},e[33]=h,e[34]=m,e[35]=C,e[36]=V):V=e[36];const ee=V;let be;e[37]!==h||e[38]!==b||e[39]!==C?(be=$=>{!h||!C||!cr($.dataTransfer)||($.preventDefault(),$.stopPropagation(),b(C,$.dataTransfer))},e[37]=h,e[38]=b,e[39]=C,e[40]=be):be=e[40];const xe=be;let Ne;e[41]!==_||e[42]!==ee||e[43]!==ue||e[44]!==xe?(Ne=s.jsx("div",{className:"group relative flex items-center",onContextMenu:_,onDragEnter:ue,onDragOver:ue,onDragLeave:ee,onDrop:xe}),e[41]=_,e[42]=ee,e[43]=ue,e[44]=xe,e[45]=Ne):Ne=e[45];const Pe=d?"bg-interactive-selection ring-2 ring-inset ring-primary":o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[46]!==Pe?(Se=Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",Pe),e[46]=Pe,e[47]=Se):Se=e[47];let Re;e[48]!==S||e[49]!==i||e[50]!==n.extension||e[51]!==n.path?(Re=S?i?s.jsx(M,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(M,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Fu(n.path,n.extension),e[48]=S,e[49]=i,e[50]=n.extension,e[51]=n.path,e[52]=Re):Re=e[52];let ye;e[53]!==n.name||e[54]!==n.path?(ye=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[53]=n.name,e[54]=n.path,e[55]=ye):ye=e[55];let pe;e[56]!==S||e[57]!==a?(pe=!S&&a&&s.jsx(Yb,{status:a}),e[56]=S,e[57]=a,e[58]=pe):pe=e[58];let me;e[59]!==u||e[60]!==S?(me=S&&u&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[u.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",u.modified]}),u.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",u.added]})]}),e[59]=u,e[60]=S,e[61]=me):me=e[61];let je;e[62]!==_||e[63]!==le||e[64]!==he||e[65]!==G||e[66]!==Se||e[67]!==Re||e[68]!==ye||e[69]!==pe||e[70]!==me?(je=s.jsxs("button",{type:"button",onClick:G,onContextMenu:_,draggable:!0,onDragStart:he,onDragEnd:le,className:Se,children:[Re,ye,pe,me]}),e[62]=_,e[63]=le,e[64]=he,e[65]=G,e[66]=Se,e[67]=Re,e[68]=ye,e[69]=pe,e[70]=me,e[71]=je):je=e[71];let ne;e[72]!==z||e[73]!==H||e[74]!==Y||e[75]!==y?(ne=H&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Js,{open:z,onOpenChange:B,children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Ys,{asChild:!0,children:s.jsx(at,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ge,title:y("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":y("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(M,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(bt,{side:"bottom",sideOffset:6,children:y("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Xs,{align:"end",side:"bottom",onCloseAutoFocus:()=>B(!1),children:Y({Item:$t,Separator:Es})})]})}),e[72]=z,e[73]=H,e[74]=Y,e[75]=y,e[76]=ne):ne=e[76];let fe;e[77]!==Ne||e[78]!==je||e[79]!==ne?(fe=s.jsxs(Jd,{render:Ne,children:[je,ne]}),e[77]=Ne,e[78]=je,e[79]=ne,e[80]=fe):fe=e[80];let ce;e[81]!==Y?(ce=s.jsx(Xd,{className:"min-w-[180px]",children:Y({Item:Kn,Separator:Oi})}),e[81]=Y,e[82]=ce):ce=e[82];let R;return e[83]!==T||e[84]!==fe||e[85]!==ce?(R=s.jsxs(Zd,{open:T,onOpenChange:j,children:[fe,ce]}),e[83]=T,e[84]=fe,e[85]=ce,e[86]=R):R=e[86],R},Jb=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.isDropTarget===e.isDropTarget&&t.canUpload===e.canUpload&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog&&t.onSetDropTarget===e.onSetDropTarget&&t.onDropFiles===e.onDropFiles,Zb=c.memo(Xb,Jb),ey=()=>{const{t}=pt(),{files:e,runtime:n}=An(),r=$m(n.platform),i=qr()??"",o=as(i.trim()),l=Wm(),a=zm(),u=id(X=>X.searchFiles),d=De(X=>X.openContextFile),h=ba(i),[f,g]=c.useState(""),p=Sa(f,200),w=c.useRef(null),[v,x]=c.useState([]),[m,b]=c.useState(!1),[y,S]=c.useState(null),[N,C]=c.useState(!1),[k,A]=c.useState(null),D=c.useRef(!1),P=c.useRef(o);P.current=o;const[F,W]=c.useState({}),[E,H]=c.useState({}),z=c.useRef(new Set),B=c.useRef(new Set),T=c.useRef(null);c.useEffect(()=>{if(S(null),A(null),!o){W({}),H({}),z.current=new Set;return}const X=qb(o);X?(W({...X.childrenByDir}),H({...X.loadErrorsByDir}),z.current=new Set(X.loadedDirs)):(W({}),H({}),z.current=new Set)},[o]),c.useEffect(()=>{if(!o)return;const X=mi(o);X.childrenByDir=F},[o,F]),c.useEffect(()=>{if(!o)return;const X=mi(o);X.loadErrorsByDir=E},[o,E]),c.useEffect(()=>{if(!o)return;const X=mi(o);X.loadedDirs=new Set(z.current)},[o,F,E]),c.useEffect(()=>()=>{if(!o)return;const X=un.get(o);X&&X.loadedDirs.size===0&&Object.keys(X.childrenByDir).length===0&&Qb(o)},[o]);const j=c.useMemo(()=>[],[]),I=c.useMemo(()=>[],[]),_=dn(X=>o?X.byRoot[o]?.expandedPaths??j:j),K=dn(X=>o?X.byRoot[o]?.selectedPath??null:null),G=dn(X=>X.setSelectedPath),Q=dn(X=>X.addOpenPath),ge=dn(X=>X.removeOpenPathsByPrefix),se=dn(X=>X.toggleExpandedPath),Y=dn(X=>X.collapseAllExpandedPaths),te=De(X=>o?X.contextPanelByDirectory[o]?.tabs??I:I),he=c.useMemo(()=>new Set(te.map(X=>X.mode==="file"?X.targetPath:null).filter(X=>typeof X=="string"&&X.length>0).map(X=>as(X))),[te]),[L,le]=c.useState(null),[Z,ue]=c.useState(null),[V,ee]=c.useState(""),[be,xe]=c.useState(!1),Ne=!!e.writeFile,Pe=!!e.createDirectory,Se=!!e.rename,Re=!!e.delete,ye=!!e.revealPath,pe=!!e.uploadFile,me=c.useMemo(()=>({canRename:Se,canCreateFile:Ne,canCreateFolder:Pe,canDelete:Re,canReveal:ye}),[Se,Ne,Pe,Re,ye]),je=c.useCallback(X=>{e.revealPath&&e.revealPath(X).catch(()=>{Fe.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),ne=c.useCallback((X,ve)=>{le(X),ue(ve),ee(X==="rename"&&ve.name||""),xe(!1)},[]),fe=c.useCallback((X,ve)=>{const Le=ve.filter($e=>$e&&typeof $e.name=="string"&&$e.name.length>0).filter($e=>l||!$e.name.startsWith(".")).filter($e=>a||!Kb($e.name)).map($e=>{const Ue=$e.name,We=as($e.path||""),qe=We?Vb(We)?We:as(`${X}/${We}`):as(`${X}/${Ue}`),nt=$e.isDirectory?"directory":"file",yt=nt==="file"&&Ue.includes(".")?Ue.split(".").pop()?.toLowerCase():void 0;return{name:Ue,path:qe,type:nt,extension:yt}});return $b(Le)},[a,l]),ce=c.useCallback(async(X,ve)=>{const Le=as(X.trim());if(!Le||z.current.has(Le)||B.current.has(Le))return;B.current=new Set(B.current),B.current.add(Le);const $e=e.listDirectory?e.listDirectory(Le).then(Ue=>Ue.entries.map(We=>({name:We.name,path:We.path,isDirectory:We.isDirectory}))):Qs.listLocalDirectory(Le).then(Ue=>Ue.map(We=>({name:We.name,path:We.path,isDirectory:We.isDirectory})));try{const Ue=await $e;if(ve?.())return;const We=fe(Le,Ue);z.current=new Set(z.current),z.current.add(Le),H(qe=>{if(!qe[Le])return qe;const nt={...qe};return delete nt[Le],nt}),W(qe=>({...qe,[Le]:We}))}catch(Ue){if(ve?.())return;const We=Ue instanceof Error?Ue.message:String(Ue??"");console.error("Failed to load sidebar directory:",Ue),H(qe=>({...qe,[Le]:We}))}finally{B.current=new Set(B.current),B.current.delete(Le)}},[e,fe]),R=c.useCallback(async()=>{if(!o)return;T.current?.abort();const X=new AbortController;T.current=X;try{const Le=(dn.getState().byRoot[o]?.expandedPaths??[]).map(We=>as(We)).filter(We=>!!We&&We!==o&&We.startsWith(`${o}/`)),$e=[o,...Le];z.current=new Set(z.current);for(const We of $e)z.current.delete(We);H(We=>{if(Object.keys(We).length===0)return We;const qe={...We};let nt=!1;for(const yt of $e)yt in qe&&(delete qe[yt],nt=!0);return nt?qe:We});const Ue=()=>X.signal.aborted;await ce(o,Ue);for(let We=0;We<Le.length&&!X.signal.aborted;We+=3){const qe=Le.slice(We,We+3);await Promise.all(qe.map(nt=>ce(nt,Ue)))}}catch(ve){if(X.signal.aborted)return;console.error("Failed to refresh sidebar tree:",ve)}finally{T.current===X&&(T.current=null)}},[ce,o]),$=c.useCallback(async X=>{if(!X){await R();return}const ve=as(X);z.current=new Set(z.current),z.current.delete(ve),B.current=new Set(B.current),B.current.delete(ve),await ce(ve)},[ce,R]);c.useEffect(()=>{o&&(T.current?.abort(),z.current=new Set,B.current=new Set,H({}),W(X=>Object.keys(X).length===0?X:{}),ce(o))},[ce,o,l,a]),c.useEffect(()=>{if(!o||_.length===0)return;const X=_.map($e=>as($e)).filter($e=>!!$e&&$e!==o&&$e.startsWith(`${o}/`)&&!z.current.has($e)&&!B.current.has($e)).sort(($e,Ue)=>$e.split("/").length-Ue.split("/").length);if(X.length===0)return;let ve=!1;const Le=()=>ve;return(async()=>{for(let $e=0;$e<X.length&&!ve;$e+=3){const Ue=X.slice($e,$e+3);await Promise.all(Ue.map(We=>ce(We,Le)))}})(),()=>{ve=!0}},[_,ce,o]),c.useEffect(()=>{if(!i){x([]),b(!1);return}const X=p.trim();if(!X){x([]),b(!1);return}let ve=!1;return b(!0),u(i,X,150,{includeHidden:l,respectGitignore:!a,type:"file"}).then(Le=>{if(ve)return;const Ue=Le.filter(We=>a||!Hb(We.path)).map(We=>({name:We.name,path:as(We.path),type:"file",extension:We.extension,relativePath:We.relativePath}));x(Ue)}).catch(()=>{ve||x([])}).finally(()=>{ve||b(!1)}),()=>{ve=!0}},[i,p,u,l,a]);const de=c.useMemo(()=>{const X=new Map;if(!h?.files)return X;for(const ve of h.files)ve.index==="A"||ve.working_dir==="?"?X.set(ve.path,"git-added"):ve.index==="D"?X.set(ve.path,"git-deleted"):(ve.index==="M"||ve.working_dir==="M")&&X.set(ve.path,"git-modified");return X},[h]),ie=c.useMemo(()=>{const X=new Map;if(!h?.files||!o)return X;for(const ve of h.files){const Le=ve.index==="M"||ve.working_dir==="M",$e=ve.index==="A"||ve.working_dir==="?";if(!Le&&!$e)continue;const Ue=ve.path.split("/");if(Ue.length<=1)continue;let We=o;for(let qe=0;qe<Ue.length-1;qe++){We=`${We}/${Ue[qe]}`;let nt=X.get(We);nt||(nt={modified:0,added:0},X.set(We,nt)),Le&&nt.modified++,$e&&nt.added++}}return X},[h,o]),Ae=c.useCallback(X=>{if(he.has(X))return"open";if(de.size===0)return null;const ve=X.startsWith(o+"/")?X.slice(o.length+1):X;return de.get(ve)??null},[he,de,o]),Be=c.useCallback(X=>{if(ie.size===0)return null;const ve=ie.get(X);return ve&&ve.modified+ve.added>0?ve:null},[ie]),Ce=c.useCallback(async X=>{if(!o)return;const ve=await Ru(e,X.path,{directory:o});if(!ve.ok){Fe.error(Eu(ve.reason));return}G(o,X.path),Q(o,X.path),d(o,X.path)},[Q,e,d,o,G]),q=c.useCallback(async X=>{const ve=as(X);o&&(se(o,ve),z.current.has(ve)||await ce(ve))},[ce,o,se]),Ee=c.useCallback(async(X,ve,Le=!1)=>{const $e=e.uploadFile;if(!$e||ve.length===0||D.current||!o)return;const Ue=o,We=Ss();D.current=!0,C(!0),S(X),Le&&A(null);const qe=[];for(let jt=0;jt<ve.length;jt+=zl){const kt=ve.slice(jt,jt+zl),Tt=await Promise.all(kt.map(async wt=>{const Nt=Vl(wt);if(!Nt||Ss()!==We)return"failed";try{return(await $e(as(`${X}/${Nt}`),wt,{directory:Ue,overwrite:Le})).success?"uploaded":"failed"}catch(Dt){return!Le&&Vm(Dt)&&Dt.reason==="already-exists"?"conflict":"failed"}}));qe.push(...Tt)}const nt=qe.filter(jt=>jt==="uploaded").length,yt=qe.filter(jt=>jt==="failed").length,vt=ve.filter((jt,kt)=>qe[kt]==="conflict"),He=ve.flatMap((jt,kt)=>{const Tt=Vl(jt);return qe[kt]==="uploaded"&&Tt?[as(`${X}/${Tt}`)]:[]}),Mt=P.current===Ue&&Ss()===We;try{He.length>0&&ag({runtimeKey:We,paths:He}),nt>0&&Mt&&await $(X),nt>0&&Fe.success(t(vt.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),yt>0&&Fe.error(t("sidebarFilesTree.toast.uploadFailed")),vt.length>0&&Mt&&A({directory:X,files:vt,runtimeKey:We,workspaceRoot:Ue})}finally{D.current=!1,C(!1),S(null)}},[e.uploadFile,$,o,t]),Me=c.useCallback((X,ve)=>{const Le=Lb(ve);Le.length!==0&&Ee(X,Le)},[Ee]),O=c.useCallback(X=>{!pe||D.current||!o||!cr(X.dataTransfer)||(X.preventDefault(),X.dataTransfer.dropEffect="copy",S(o))},[pe,o]),oe=c.useCallback(X=>{cr(X.dataTransfer)&&(X.relatedTarget instanceof Node&&X.currentTarget.contains(X.relatedTarget)||S(null))},[]),re=c.useCallback(X=>{!pe||D.current||!o||!cr(X.dataTransfer)||(X.preventDefault(),Me(o,X.dataTransfer))},[pe,Me,o]),we=c.useCallback(async X=>{if(X?.preventDefault(),!Z||!L)return;xe(!0);const ve=()=>xe(!1),Le=()=>le(null);if(L==="createFile"){if(!V.trim()){Fe.error(t("sidebarFilesTree.toast.filenameRequired")),ve();return}if(!e.writeFile){Fe.error(t("sidebarFilesTree.toast.writeNotSupported")),ve();return}const $e=Z.path,Ue=$e?`${$e}/`:"",We=as(`${Ue}${V.trim()}`);await e.writeFile(We,"").then(async qe=>{qe.success&&(Fe.success(t("sidebarFilesTree.toast.fileCreated")),await $($e)),Le()}).catch(()=>Fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(L==="createFolder"){if(!V.trim()){Fe.error(t("sidebarFilesTree.toast.folderNameRequired")),ve();return}const $e=Z.path,Ue=$e?`${$e}/`:"",We=as(`${Ue}${V.trim()}`);await e.createDirectory(We).then(async qe=>{qe.success&&(Fe.success(t("sidebarFilesTree.toast.folderCreated")),await $($e)),Le()}).catch(()=>Fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(L==="rename"){if(!V.trim()){Fe.error(t("sidebarFilesTree.toast.nameRequired")),ve();return}if(!e.rename){Fe.error(t("sidebarFilesTree.toast.renameNotSupported")),ve();return}const $e=Z.path,Ue=$e.split("/").slice(0,-1).join("/"),We=Ue?`${Ue}/`:"",qe=as(`${We}${V.trim()}`);await e.rename($e,qe).then(async nt=>{nt.success&&(Fe.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await $(Ue),o&&ge(o,$e),(K===$e||K&&K.startsWith(`${$e}/`))&&G(o,null)),Le()}).catch(()=>Fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(L==="delete"){if(!e.delete){Fe.error(t("sidebarFilesTree.toast.deleteNotSupported")),ve();return}const $e=Z.path,Ue=$e.split("/").slice(0,-1).join("/");await e.delete($e).then(async We=>{We.success&&(Fe.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await $(Ue),o&&ge(o,$e),(K===$e||K&&K.startsWith($e+"/"))&&G(o,null)),Le()}).catch(()=>Fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}ve()},[L,Z,V,e,$,ge,o,K,G,t]);function Ve(X,ve){const Le=F[X]??[];return Le.map(($e,Ue)=>{const We=$e.type==="directory",qe=We&&_.includes($e.path),nt=K===$e.path,yt=Ue===Le.length-1;return s.jsxs("li",{className:"relative",children:[ve>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),yt&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Zb,{node:$e,root:o,isExpanded:qe,isActive:nt,isBrowserClient:r,status:We?void 0:Ae($e.path),badge:We?Be($e.path):void 0,isDropTarget:We&&y===$e.path,canUpload:pe&&!N,permissions:me,downloadFile:e.downloadFile,onSelect:Ce,onToggle:q,onRevealPath:je,onOpenDialog:ne,onSetDropTarget:S,onDropFiles:Me}),We&&qe&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[E[$e.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:E[$e.path],children:E[$e.path]}),s.jsxs(at,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{$($e.path)},children:[s.jsx(M,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,Ve($e.path,ve+1)]})]},$e.path)})}const st=!!(o&&F[o]),Ge=o?E[o]:null,ae=y?Wb(o,y):"";return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Ne&&s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>ne("createFile",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(M,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(bt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Pe&&s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>ne("createFolder",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(M,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(bt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>{R()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(M,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(bt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>{o&&Y(o)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(M,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(bt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(M,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(jn,{ref:w,value:f,onChange:X=>g(X.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{g(""),w.current?.focus()},children:s.jsx(M,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsxs("div",{className:"relative flex-1 min-h-0",children:[s.jsx(kn,{outerClassName:"h-full min-h-0",className:Te("p-2",y===o&&"bg-interactive-selection/10"),onDragEnter:O,onDragOver:O,onDragLeave:oe,onDrop:re,children:s.jsx("ul",{className:"flex flex-col",children:m?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):v.length>0?v.map(X=>{const ve=K===X.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ce(X),draggable:!0,onDragStart:Le=>{Mu(Le);const $e=X.relativePath||Oa(o??"",X.path);!$e||$e==="."||(Le.dataTransfer.setData("application/x-openchamber-file-path",$e),Le.dataTransfer.effectAllowed="copy")},onDragEnd:Le=>{Ou(Le)&&Ce(X)},className:Te("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",ve?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:X.path,children:[Fu(X.path,X.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:X.relativePath??X.path})]})},X.path)}):Ge?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:Ge}),s.jsxs(at,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{R()},children:[s.jsx(M,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):st&&o?Ve(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),y?s.jsxs("div",{className:"pointer-events-none absolute left-2 right-2 top-2 z-50 flex items-center gap-2 rounded-md border border-primary bg-background/95 px-2 py-1.5 shadow-sm",children:[s.jsx(M,{name:N?"loader-4":"folder-received",className:Te("size-4 flex-shrink-0",N&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:ae,children:t(N?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:ae})})]}):null]}),s.jsx(vs,{open:!!k,onOpenChange:X=>!X&&A(null),children:s.jsxs(js,{children:[s.jsxs(Ls,{children:[s.jsx(Ds,{children:t("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(Ps,{children:t("sidebarFilesTree.dialog.uploadConflicts.description",{path:k?.directory??""})})]}),s.jsx(kn,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:k?.files.map((X,ve)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:X.name,children:X.name},`${X.name}-${X.size}-${ve}`))}),s.jsxs(gn,{children:[s.jsx(at,{variant:"outline",onClick:()=>A(null),disabled:N,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(at,{onClick:()=>{if(k){if(k.runtimeKey!==Ss()||k.workspaceRoot!==o){A(null);return}Ee(k.directory,k.files,!0)}},disabled:N,children:t("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx(vs,{open:!!L,onOpenChange:X=>!X&&le(null),children:s.jsxs(js,{children:[s.jsxs(Ls,{children:[s.jsxs(Ds,{children:[L==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),L==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),L==="rename"&&t("sidebarFilesTree.dialog.rename.title"),L==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Ps,{children:[L==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:Z?.path??t("sidebarFilesTree.dialog.rootFallback")}),L==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:Z?.path??t("sidebarFilesTree.dialog.rootFallback")}),L==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:Z?.name??""}),L==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:Z?.name??""})]})]}),L!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(jn,{value:V,onChange:X=>ee(X.target.value),placeholder:t(L==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:X=>{X.key==="Enter"&&we()},autoFocus:!0})}),s.jsxs(gn,{children:[s.jsx(at,{variant:"outline",onClick:()=>le(null),disabled:be,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(at,{variant:L==="delete"?"destructive":"default",onClick:()=>{we()},disabled:be||L!=="delete"&&!V.trim(),children:be?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):t(L==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},Ul=60,ty=t=>{try{return new URL(t).origin}catch{return""}},fi=new Set,Bu=Zn()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const i=ty(n);!i||!r||e().byOrigin[i]||fi.has(i)||(fi.add(i),Tr("desktop_browser_fetch_favicon",{url:r}).then(o=>{const l=typeof o?.dataUrl=="string"?o.dataUrl:"";l&&t(a=>{const u={...a.byOrigin,[i]:l},d=Object.keys(u);if(d.length<=Ul)return{byOrigin:u};for(const h of d.slice(0,d.length-Ul))delete u[h];return{byOrigin:u}})}).catch(()=>{}).finally(()=>{fi.delete(i)}))}})),Ba=t=>t,qi=t=>{const e=Ba(t).type;return typeof e=="string"?e:""},sy=t=>{const e=Ba(t).tool;return typeof e=="string"?e:""},ny=t=>{const e=Ba(t).text;return typeof e=="string"?e:""},ry=t=>{const e=qi(t);return e==="tool"?sy(t).trim().toLowerCase()||"tool":e||"unknown"},oy=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=ry(n);e.includes(r)||e.push(r)}return e.join(" + ")},iy=t=>t.replace(/\s+/g," ").trim(),ay=t=>{for(const n of t)if(qi(n)==="text"){const r=iy(ny(n));if(r.length===0)continue;return r}const e=t.filter(n=>qi(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},ly=(t,e,n)=>`${n(t)} / ${n(e)}`,cy=t=>{if(t==="12h")return!0;if(t==="24h")return!1},dy=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=cy(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},Qi={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},yo={user:0,assistant:0,tool:0,other:0},Tn=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,hi=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(h=>h.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Qi,total:Tn(n)};if(!n||typeof n!="object")return Qi;const r=n,i=Tn(r.input),o=Tn(r.output),l=Tn(r.reasoning),a=Tn(r.cache?.read),u=Tn(r.cache?.write),d=Tn(r.total);return{input:i,output:o,reasoning:l,cacheRead:a,cacheWrite:u,total:d>0?d:i+o+l+a+u}},uy=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Ks=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Ks(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Ks(n),0):0,my=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...yo,assistant:Ks(n.text)+Ks(n.content)};const i=uy(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Ks(n.input)+Ks(n.output)+Ks(n.error)+Ks(n.call?.input)+Ks(n.call?.output)+Ks(n.call?.error)+Ks(n.raw)+Math.round(Ks(n.metadata)*.25)+Math.round(Ks(n.state)*.1),other:0}:e==="user"?{user:i.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},Kl=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),fy=t=>{const e=Qr(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},hy=(t,e)=>{if(t.length===0)return{...yo};const n=t.reduce((r,i)=>{const o=fy(i);let l={...yo};for(const a of i.parts)l=Kl(l,my(a,o));return Kl(r,l)},{...yo});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Un=t=>t.toLocaleString(pa()),py=(t,e)=>!t||!Number.isFinite(t)?"-":wd(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),gy=(t,e,n)=>{const r=t.find(o=>o.id===e),i=r?.models?.find(o=>o.id===n);return{providerName:r?.name||e||"-",modelName:i?.name||n||"-",contextLimit:typeof i?.limit?.context=="number"?i.limit.context:null}},xy=()=>{const t=Xe.c(203),{t:e}=pt(),n=De(by);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[i,o]=c.useState(r),[l,a]=c.useState(null),u=c.useRef(null),d=Qe(yy),h=Qe(wy),f=jd(h??void 0),g=Ff(d??"",h??void 0),p=Ut(Sy);let w;t[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null),o(vy),a(null)},t[1]=w):w=t[1];let v;t[2]!==h||t[3]!==d?(v=[h,d],t[2]=h,t[3]=d,t[4]=v):v=t[4],c.useEffect(w,v);let x,m;t[5]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},m=[],t[5]=x,t[6]=m):(x=t[5],m=t[6]),c.useEffect(x,m);let b;t[7]===Symbol.for("react.memo_cache_sentinel")?(b=async(ft,Ze)=>{(await fn(Ze)).ok?(a(ft),u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{a(tt=>tt===ft?null:tt),u.current=null},2e3)):a(null)},t[7]=b):b=t[7];const y=b;let S;t[8]!==d||t[9]!==f?(S=d?f.find(ft=>ft.id===d)??null:null,t[8]=d,t[9]=f,t[10]=S):S=t[10];const N=S;let C,k,A,D,P,F;if(t[11]!==p||t[12]!==g){C=g.filter(jy);let ft;t[19]!==g?(ft=g.filter(ky),t[19]=g,t[20]=ft):ft=t[20],F=ft;let Ze=null;for(let tt=C.length-1;tt>=0;tt=tt-1,tt){const lt=C[tt];if(hi(lt).total>0){Ze=lt;break}}D=Ze?hi(Ze):Qi,k=Bf({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),P=C.reduce(Cy,0);const ke=Ze?.info??null;A=gy(p,ke?.providerID||"",ke?.modelID||""),t[11]=p,t[12]=g,t[13]=C,t[14]=k,t[15]=A,t[16]=D,t[17]=P,t[18]=F}else C=t[13],k=t[14],A=t[15],D=t[16],P=t[17],F=t[18];const W=A,E=W.contextLimit,H=E&&E>0?Math.min(999,D.total/E*100):0;let z;if(t[21]!==g){const ft=[...g].reverse().find(Ny)?.info?.system||"";z=hy(g,ft),t[21]=g,t[22]=z}else z=t[22];const B=z,T=B.user,j=B.assistant,I=B.tool,_=Math.max(0,D.input-T-j-I),K=T+j+I+_,G=g[0]?.info?.time?.created,Q=g.length>0?g[g.length-1]?.info?.time?.created:null;let ge;t[23]!==N?.title||t[24]!==e?(ge=N?.title||e("contextSidebar.session.untitled"),t[23]=N?.title,t[24]=e,t[25]=ge):ge=t[25];const se=N?.time?.created??G??null,Y=Q??N?.time?.created??null;let te;t[26]!==j||t[27]!==_||t[28]!==I||t[29]!==T?(te={user:T,assistant:j,tool:I,other:_},t[26]=j,t[27]=_,t[28]=I,t[29]=T,t[30]=te):te=t[30];let he;t[31]!==C.length||t[32]!==K||t[33]!==k||t[34]!==E||t[35]!==W||t[36]!==g.length||t[37]!==se||t[38]!==Y||t[39]!==te||t[40]!==ge||t[41]!==D||t[42]!==P||t[43]!==H||t[44]!==F.length?(he={sessionTitle:ge,messagesCount:g.length,userMessagesCount:F.length,assistantMessagesCount:C.length,createdAt:se,lastActivityAt:Y,providerModel:W,tokenBreakdown:D,usagePercent:H,cacheHitRate:k,totalAssistantCost:P,contextLimit:E,breakdown:te,breakdownTotal:K},t[31]=C.length,t[32]=K,t[33]=k,t[34]=E,t[35]=W,t[36]=g.length,t[37]=se,t[38]=Y,t[39]=te,t[40]=ge,t[41]=D,t[42]=P,t[43]=H,t[44]=F.length,t[45]=he):he=t[45];const L=he;if(!d){let ft;t[46]!==e?(ft=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=ft):ft=t[47];let Ze;return t[48]!==ft?(Ze=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:ft}),t[48]=ft,t[49]=Ze):Ze=t[49],Ze}let le;t[50]!==e?(le=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=le):le=t[51];let Z;t[52]!==le||t[53]!==L.breakdown.user?(Z={key:"user",label:le,value:L.breakdown.user,color:"var(--status-success)"},t[52]=le,t[53]=L.breakdown.user,t[54]=Z):Z=t[54];let ue;t[55]!==e?(ue=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=ue):ue=t[56];let V;t[57]!==ue||t[58]!==L.breakdown.assistant?(V={key:"assistant",label:ue,value:L.breakdown.assistant,color:"var(--primary-base)"},t[57]=ue,t[58]=L.breakdown.assistant,t[59]=V):V=t[59];let ee;t[60]!==e?(ee=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ee):ee=t[61];let be;t[62]!==ee||t[63]!==L.breakdown.tool?(be={key:"tool",label:ee,value:L.breakdown.tool,color:"var(--status-warning)"},t[62]=ee,t[63]=L.breakdown.tool,t[64]=be):be=t[64];let xe;t[65]!==e?(xe=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=xe):xe=t[66];let Ne;t[67]!==xe||t[68]!==L.breakdown.other?(Ne={key:"other",label:xe,value:L.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=xe,t[68]=L.breakdown.other,t[69]=Ne):Ne=t[69];let Pe;t[70]!==Z||t[71]!==V||t[72]!==be||t[73]!==Ne?(Pe=[Z,V,be,Ne],t[70]=Z,t[71]=V,t[72]=be,t[73]=Ne,t[74]=Pe):Pe=t[74];const Se=Pe;let Re;t[75]!==L.sessionTitle?(Re=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:L.sessionTitle}),t[75]=L.sessionTitle,t[76]=Re):Re=t[76];let ye;t[77]!==L.providerModel.modelName||t[78]!==L.providerModel.providerName?(ye=s.jsxs("span",{children:[L.providerModel.providerName," / ",L.providerModel.modelName]}),t[77]=L.providerModel.modelName,t[78]=L.providerModel.providerName,t[79]=ye):ye=t[79];let pe;t[80]!==n||t[81]!==L.createdAt?(pe=L.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:py(L.createdAt,n)})]}),t[80]=n,t[81]=L.createdAt,t[82]=pe):pe=t[82];let me;t[83]!==ye||t[84]!==pe?(me=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[ye,pe]}),t[83]=ye,t[84]=pe,t[85]=me):me=t[85];let je;t[86]!==Re||t[87]!==me?(je=s.jsxs("div",{className:"mb-6",children:[Re,me]}),t[86]=Re,t[87]=me,t[88]=je):je=t[88];let ne;t[89]!==e?(ne=e("contextSidebar.section.context"),t[89]=e,t[90]=ne):ne=t[90];let fe;t[91]!==ne?(fe=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ne}),t[91]=ne,t[92]=fe):fe=t[92];let ce;t[93]!==L.tokenBreakdown.total?(ce=Un(L.tokenBreakdown.total),t[93]=L.tokenBreakdown.total,t[94]=ce):ce=t[94];let R;t[95]!==L.contextLimit?(R=L.contextLimit?` / ${Un(L.contextLimit)}`:"",t[95]=L.contextLimit,t[96]=R):R=t[96];let $;t[97]!==ce||t[98]!==R?($=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ce,R]}),t[97]=ce,t[98]=R,t[99]=$):$=t[99];let de;t[100]!==fe||t[101]!==$?(de=s.jsxs("div",{className:"flex items-baseline justify-between",children:[fe,$]}),t[100]=fe,t[101]=$,t[102]=de):de=t[102];let ie;t[103]!==L.usagePercent?(ie=L.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,L.usagePercent)}%`,backgroundColor:L.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=L.usagePercent,t[104]=ie):ie=t[104];let Ae;t[105]!==ie?(Ae=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ie}),t[105]=ie,t[106]=Ae):Ae=t[106];let Be;t[107]!==e||t[108]!==L.usagePercent?(Be=e("contextSidebar.context.percentUsed",{percent:L.usagePercent.toFixed(1)}),t[107]=e,t[108]=L.usagePercent,t[109]=Be):Be=t[109];let Ce;t[110]!==Be?(Ce=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Be}),t[110]=Be,t[111]=Ce):Ce=t[111];let q;t[112]!==de||t[113]!==Ae||t[114]!==Ce?(q=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[de,Ae,Ce]}),t[112]=de,t[113]=Ae,t[114]=Ce,t[115]=q):q=t[115];let Ee;t[116]!==e?(Ee=e("contextSidebar.stats.messages"),t[116]=e,t[117]=Ee):Ee=t[117];let Me;t[118]!==L.messagesCount?(Me=Un(L.messagesCount),t[118]=L.messagesCount,t[119]=Me):Me=t[119];let O;t[120]!==Ee||t[121]!==Me?(O={label:Ee,value:Me},t[120]=Ee,t[121]=Me,t[122]=O):O=t[122];let oe;t[123]!==e?(oe=e("contextSidebar.stats.user"),t[123]=e,t[124]=oe):oe=t[124];let re;t[125]!==L.userMessagesCount?(re=Un(L.userMessagesCount),t[125]=L.userMessagesCount,t[126]=re):re=t[126];let we;t[127]!==oe||t[128]!==re?(we={label:oe,value:re},t[127]=oe,t[128]=re,t[129]=we):we=t[129];let Ve;t[130]!==e?(Ve=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Ve):Ve=t[131];let st;t[132]!==L.assistantMessagesCount?(st=Un(L.assistantMessagesCount),t[132]=L.assistantMessagesCount,t[133]=st):st=t[133];let Ge;t[134]!==Ve||t[135]!==st?(Ge={label:Ve,value:st},t[134]=Ve,t[135]=st,t[136]=Ge):Ge=t[136];let ae;t[137]!==e?(ae=e("contextSidebar.stats.cost"),t[137]=e,t[138]=ae):ae=t[138];let X;t[139]!==L.totalAssistantCost?(X=Ep(L.totalAssistantCost),t[139]=L.totalAssistantCost,t[140]=X):X=t[140];let ve;t[141]!==ae||t[142]!==X?(ve={label:ae,value:X},t[141]=ae,t[142]=X,t[143]=ve):ve=t[143];let Le;t[144]!==O||t[145]!==we||t[146]!==Ge||t[147]!==ve?(Le=[O,we,Ge,ve],t[144]=O,t[145]=we,t[146]=Ge,t[147]=ve,t[148]=Le):Le=t[148];const $e=Le;let Ue;t[149]!==$e?(Ue=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:$e.map(Ay)}),t[149]=$e,t[150]=Ue):Ue=t[150];let We;t[151]!==e?(We=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=We):We=t[152];let qe;t[153]!==We?(qe=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:We}),t[153]=We,t[154]=qe):qe=t[154];let nt;t[155]!==e||t[156]!==L.cacheHitRate.hasInput||t[157]!==L.cacheHitRate.percent||t[158]!==L.tokenBreakdown.cacheRead||t[159]!==L.tokenBreakdown.cacheWrite||t[160]!==L.tokenBreakdown.input||t[161]!==L.tokenBreakdown.output||t[162]!==L.tokenBreakdown.reasoning?(nt=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:L.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:L.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:L.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:L.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:L.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:L.cacheHitRate.hasInput?L.cacheHitRate.percent:null,format:"percent"}].map(Dy)}),t[155]=e,t[156]=L.cacheHitRate.hasInput,t[157]=L.cacheHitRate.percent,t[158]=L.tokenBreakdown.cacheRead,t[159]=L.tokenBreakdown.cacheWrite,t[160]=L.tokenBreakdown.input,t[161]=L.tokenBreakdown.output,t[162]=L.tokenBreakdown.reasoning,t[163]=nt):nt=t[163];let yt;t[164]!==qe||t[165]!==nt?(yt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[qe,nt]}),t[164]=qe,t[165]=nt,t[166]=yt):yt=t[166];let vt;t[167]!==Se||t[168]!==L.breakdownTotal?(vt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Se.map(ft=>ft.value<=0||L.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ft.value/L.breakdownTotal*100}%`,backgroundColor:ft.color}},ft.key))}),t[167]=Se,t[168]=L.breakdownTotal,t[169]=vt):vt=t[169];let He;t[170]!==Se||t[171]!==L.breakdownTotal?(He=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:Se.map(ft=>{const Ze=L.breakdownTotal>0?ft.value/L.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:ft.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ft.label," ",s.jsxs("span",{className:"tabular-nums",children:[Ze.toFixed(0),"%"]})]})]},ft.key)})}),t[170]=Se,t[171]=L.breakdownTotal,t[172]=He):He=t[172];let Mt;t[173]!==vt||t[174]!==He?(Mt=s.jsxs("div",{className:"mb-6",children:[vt,He]}),t[173]=vt,t[174]=He,t[175]=Mt):Mt=t[175];let jt;t[176]!==e?(jt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=jt):jt=t[177];let kt;t[178]!==jt?(kt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:jt}),t[178]=jt,t[179]=kt):kt=t[179];let Tt;if(t[180]!==l||t[181]!==i||t[182]!==g||t[183]!==e||t[184]!==n){let ft;t[186]!==l||t[187]!==i||t[188]!==e||t[189]!==n?(ft=Ze=>{const tt=Qr(Ze.info).role,lt=tt==="assistant",At=tt==="user",Ye=i[Ze.info.id]===!0,rt=l===Ze.info.id,It=Ze.info.time?.created??null,Ct=oy(Ze.parts),Pt=lt?hi({info:Ze.info,parts:Ze.parts}):null,Wt=At?ay(Ze.parts):"",Yt=dy(It,n),Kt=Ct||"—",Bt=Pt?ly(Pt.input,Pt.output,Un):"",ts=tt||"unknown",zt=Ct?`${ts}: ${Ct}`:ts,_t=Ye?JSON.stringify({info:Ze.info,parts:Ze.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Ye,onClick:()=>{o(Oe=>({...Oe,[Ze.info.id]:Oe[Ze.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:lt?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[At?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",Wt]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:lt?Kt:zt}),lt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Bt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Yt})]})}),Ye&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Oe=>{Oe.stopPropagation(),y(Ze.info.id,_t)},"aria-label":e(rt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(rt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:rt?s.jsx(M,{name:"check",className:"size-3.5"}):s.jsx(M,{name:"file-copy",className:"size-3.5"})})}),s.jsx(_f,{language:"json",code:_t,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},Ze.info.id)},t[186]=l,t[187]=i,t[188]=e,t[189]=n,t[190]=ft):ft=t[190],Tt=[...g].reverse().map(ft),t[180]=l,t[181]=i,t[182]=g,t[183]=e,t[184]=n,t[185]=Tt}else Tt=t[185];let wt;t[191]!==Tt?(wt=s.jsx("div",{className:"mt-2.5 space-y-1",children:Tt}),t[191]=Tt,t[192]=wt):wt=t[192];let Nt;t[193]!==kt||t[194]!==wt?(Nt=s.jsxs("div",{children:[kt,wt]}),t[193]=kt,t[194]=wt,t[195]=Nt):Nt=t[195];let Dt;return t[196]!==je||t[197]!==q||t[198]!==Ue||t[199]!==yt||t[200]!==Mt||t[201]!==Nt?(Dt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[je,q,Ue,yt,Mt,Nt]})}),t[196]=je,t[197]=q,t[198]=Ue,t[199]=yt,t[200]=Mt,t[201]=Nt,t[202]=Dt):Dt=t[202],Dt};function by(t){return t.timeFormatPreference}function yy(t){return t.currentSessionId}function wy(t){return t.currentSessionDirectory}function Sy(t){return t.providers}function vy(t){return Object.keys(t).length>0?{}:t}function jy(t){return Qr(t.info).role==="assistant"}function ky(t){return Qr(t.info).isUser}function Cy(t,e){const n=Tn(e.info.cost);return t+n}function Ny(t){return Qr(t.info).isUser&&typeof t.info.system=="string"}function Ay(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Dy(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Un(t.value):"—"})]},t.label)}const _u=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),Py=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return _u.has(n.toLowerCase())},on="about:blank",dr=t=>{const e=t.trim();if(!e)return on;const n=e.includes("://")?e:`${Py(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?on:r.toString()}catch{return on}},xr=t=>{try{return _u.has(new URL(t).hostname.toLowerCase())}catch{return!1}},_a=t=>{if(!t||t===on)return"";try{return new URL(t).host||t}catch{return t}},Iy=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),Ty=(t,e)=>Iy.has(t)&&xr(e),Ry=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.port=="number"&&Number.isFinite(e.port)&&typeof e.url=="string"&&e.url.length>0&&typeof e.command=="string"},Ey=async t=>{try{const e=await ds("/api/dev-servers",{signal:t});if(!e.ok)return{kind:"unavailable"};const n=await e.json();if(!n||typeof n!="object")return{kind:"unavailable"};const r=n.servers;return Array.isArray(r)?{kind:"ready",servers:r.filter(Ry)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},My=async t=>{try{const e=await ds("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})});if(!e.ok)return null;const n=await e.json();if(!n||typeof n!="object")return null;const r=n.status;return typeof r=="number"&&Number.isFinite(r)?r:null}catch{return null}},Oy=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:null}catch{return null}},Fy=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const i=Oy(r);i!==null&&!n.has(i)&&n.set(i,r)}return e?e.map(r=>{const i=n.get(r.port);return{url:i??r.url,port:r.port,announced:i!==void 0}}).sort((r,i)=>r.announced!==i.announced?r.announced?-1:1:r.port-i.port):[...n.entries()].map(([r,i])=>({url:i,port:r,announced:!0})).sort((r,i)=>r.port-i.port)},Yi="__aiworkerBrowserAnnotationActive",By=`(() => {
|
|
47
|
-
try {
|
|
48
|
-
var host = document.querySelector('[data-openchamber-annotation]');
|
|
49
|
-
if (host && host.parentNode) host.parentNode.removeChild(host);
|
|
50
|
-
} catch (error) { /* page navigated away */ }
|
|
51
|
-
try {
|
|
52
|
-
var cursor = document.getElementById('openchamber-annotation-cursor');
|
|
53
|
-
if (cursor && cursor.parentNode) cursor.parentNode.removeChild(cursor);
|
|
54
|
-
} catch (error) { /* page navigated away */ }
|
|
55
|
-
try { delete window['${Yi}']; } catch (error) { /* non-configurable */ }
|
|
56
|
-
})();`,_y=(t,e)=>{const n=JSON.stringify({theme:t,labels:e});return String.raw`new Promise((resolve) => {
|
|
57
|
-
var CONFIG = ${n};
|
|
58
|
-
var THEME = CONFIG.theme;
|
|
59
|
-
var LABELS = CONFIG.labels;
|
|
60
|
-
var OVERLAY_ATTR = 'data-openchamber-annotation';
|
|
61
|
-
var Z_OVERLAY = 2147483646;
|
|
62
|
-
var MAX_TEXT = 400;
|
|
63
|
-
var MIN_RECT = 3;
|
|
64
|
-
var EDITOR_GAP = 10;
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
var stale = document.querySelector('[' + OVERLAY_ATTR + ']');
|
|
68
|
-
if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
|
|
69
|
-
} catch (error) { /* nothing to clean */ }
|
|
70
|
-
|
|
71
|
-
window['${Yi}'] = true;
|
|
72
|
-
|
|
73
|
-
var counter = 0;
|
|
74
|
-
var nextId = function (prefix) { counter += 1; return prefix + '-' + counter; };
|
|
75
|
-
|
|
76
|
-
var selected = null;
|
|
77
|
-
var regions = [];
|
|
78
|
-
var strokes = [];
|
|
79
|
-
var tool = 'select';
|
|
80
|
-
var settled = false;
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------- geometry
|
|
83
|
-
|
|
84
|
-
var rectFrom = function (domRect) {
|
|
85
|
-
return { x: domRect.left, y: domRect.top, width: domRect.width, height: domRect.height };
|
|
86
|
-
};
|
|
87
|
-
var normalizeRect = function (ax, ay, bx, by) {
|
|
88
|
-
return { x: Math.min(ax, bx), y: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
|
|
89
|
-
};
|
|
90
|
-
var usableRect = function (rect) { return rect.width >= MIN_RECT && rect.height >= MIN_RECT; };
|
|
91
|
-
|
|
92
|
-
// ------------------------------------------------------------- description
|
|
93
|
-
|
|
94
|
-
var isOverlayNode = function (element) {
|
|
95
|
-
var node = element;
|
|
96
|
-
while (node) {
|
|
97
|
-
if (node.nodeType === 1 && node.hasAttribute && node.hasAttribute(OVERLAY_ATTR)) return true;
|
|
98
|
-
node = node.parentNode || (node.host || null);
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
var elementFromPoint = function (x, y) {
|
|
104
|
-
var found = document.elementFromPoint(x, y);
|
|
105
|
-
if (!found || isOverlayNode(found)) return null;
|
|
106
|
-
return found;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var selectorPart = function (element) {
|
|
110
|
-
var part = element.tagName.toLowerCase();
|
|
111
|
-
if (element.id) return part + '#' + element.id;
|
|
112
|
-
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
113
|
-
if (className) {
|
|
114
|
-
var first = className.split(/\s+/).filter(Boolean).slice(0, 2).join('.');
|
|
115
|
-
if (first) part += '.' + first;
|
|
116
|
-
}
|
|
117
|
-
return part;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
var buildSelector = function (element) {
|
|
121
|
-
if (element.id) return '#' + element.id;
|
|
122
|
-
var parts = [];
|
|
123
|
-
var node = element;
|
|
124
|
-
var depth = 0;
|
|
125
|
-
while (node && node.nodeType === 1 && depth < 5) {
|
|
126
|
-
var part = selectorPart(node);
|
|
127
|
-
var parent = node.parentElement;
|
|
128
|
-
if (parent) {
|
|
129
|
-
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
130
|
-
return child.tagName === node.tagName;
|
|
131
|
-
});
|
|
132
|
-
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
133
|
-
}
|
|
134
|
-
parts.unshift(part);
|
|
135
|
-
if (node.id) break;
|
|
136
|
-
node = parent;
|
|
137
|
-
depth += 1;
|
|
138
|
-
}
|
|
139
|
-
return parts.join(' > ');
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
var INTERESTING_ATTRS = ['id', 'class', 'name', 'type', 'href', 'src', 'alt', 'title', 'role', 'placeholder', 'aria-label', 'data-testid'];
|
|
143
|
-
var STYLE_PROPS = [
|
|
144
|
-
'display', 'position', 'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontFamily',
|
|
145
|
-
'lineHeight', 'padding', 'margin', 'border', 'borderRadius', 'width', 'height', 'opacity',
|
|
146
|
-
'zIndex', 'flexDirection', 'justifyContent', 'alignItems', 'gap', 'textAlign'
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
var describe = function (element) {
|
|
150
|
-
var computed = window.getComputedStyle(element);
|
|
151
|
-
var attributes = {};
|
|
152
|
-
for (var i = 0; i < INTERESTING_ATTRS.length; i += 1) {
|
|
153
|
-
var name = INTERESTING_ATTRS[i];
|
|
154
|
-
var value = element.getAttribute(name);
|
|
155
|
-
if (value) attributes[name] = String(value).slice(0, 200);
|
|
156
|
-
}
|
|
157
|
-
var computedStyle = {};
|
|
158
|
-
for (var j = 0; j < STYLE_PROPS.length; j += 1) {
|
|
159
|
-
var prop = STYLE_PROPS[j];
|
|
160
|
-
computedStyle[prop] = String(computed[prop] == null ? '' : computed[prop]);
|
|
161
|
-
}
|
|
162
|
-
var ancestry = [];
|
|
163
|
-
var node = element.parentElement;
|
|
164
|
-
var depth = 0;
|
|
165
|
-
while (node && node.nodeType === 1 && depth < 4) {
|
|
166
|
-
var entry = { tag: node.tagName.toLowerCase(), selectorPart: selectorPart(node) };
|
|
167
|
-
if (node.id) entry.id = node.id;
|
|
168
|
-
var cls = typeof node.className === 'string' ? node.className.trim() : '';
|
|
169
|
-
if (cls) entry.className = cls.slice(0, 200);
|
|
170
|
-
ancestry.unshift(entry);
|
|
171
|
-
node = node.parentElement;
|
|
172
|
-
depth += 1;
|
|
173
|
-
}
|
|
174
|
-
var box = element.getBoundingClientRect();
|
|
175
|
-
var text = (element.textContent == null ? '' : String(element.textContent)).replace(/\s+/g, ' ').trim();
|
|
176
|
-
return {
|
|
177
|
-
tag: element.tagName.toLowerCase(),
|
|
178
|
-
text: text.slice(0, MAX_TEXT),
|
|
179
|
-
selector: buildSelector(element),
|
|
180
|
-
path: ancestry.map(function (e) { return e.selectorPart; }).concat([selectorPart(element)]).join(' > '),
|
|
181
|
-
bounds: rectFrom(box),
|
|
182
|
-
center: { x: box.left + box.width / 2, y: box.top + box.height / 2 },
|
|
183
|
-
attributes: attributes,
|
|
184
|
-
computedStyle: computedStyle,
|
|
185
|
-
ancestry: ancestry
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// ------------------------------------------------------------------ chrome
|
|
190
|
-
|
|
191
|
-
var host = document.createElement('div');
|
|
192
|
-
host.setAttribute(OVERLAY_ATTR, '');
|
|
193
|
-
host.style.cssText = 'position:fixed;inset:0;z-index:' + Z_OVERLAY + ';pointer-events:none';
|
|
194
|
-
var shadow = host.attachShadow({ mode: 'closed' });
|
|
195
|
-
|
|
196
|
-
var style = document.createElement('style');
|
|
197
|
-
style.textContent = [
|
|
198
|
-
':host{all:initial}',
|
|
199
|
-
'*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}',
|
|
200
|
-
'.layer{position:fixed;inset:0;pointer-events:none}',
|
|
201
|
-
'.box{position:fixed;left:0;top:0;display:none;pointer-events:none;border:1.5px solid ' + THEME.primary + ';background:' + THEME.primarySoft + ';border-radius:2px}',
|
|
202
|
-
'.label{position:fixed;left:0;top:0;display:none;pointer-events:none;padding:1px 6px;border-radius:4px;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';font-size:11px;line-height:17px;white-space:nowrap;font-weight:600}',
|
|
203
|
-
'.tools{position:fixed;top:14px;left:50%;transform:translateX(-50%);display:flex;gap:2px;padding:4px;border-radius:999px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 6px 20px rgba(0,0,0,.24);pointer-events:auto}',
|
|
204
|
-
'.tools button{appearance:none;border:none;background:transparent;color:' + THEME.mutedText + ';border-radius:999px;padding:5px 14px;font-size:12px;line-height:18px;font-weight:500;cursor:pointer;white-space:nowrap}',
|
|
205
|
-
'.tools button:hover{background:' + THEME.primaryFaint + '}',
|
|
206
|
-
'.tools button[aria-pressed="true"]{background:' + THEME.primarySoft + ';color:' + THEME.primary + ';font-weight:600}',
|
|
207
|
-
'.editor{position:fixed;left:0;top:0;display:none;align-items:center;gap:8px;width:min(420px,calc(100vw - 24px));padding:6px;padding-left:16px;border-radius:22px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 8px 28px rgba(0,0,0,.3);pointer-events:auto}',
|
|
208
|
-
'.editor textarea{flex:1;min-width:0;resize:none;border:none;background:transparent;color:' + THEME.text + ';font-size:13px;line-height:20px;outline:none;padding:6px 0;min-height:32px;max-height:104px;display:block}',
|
|
209
|
-
'.editor textarea::placeholder{color:' + THEME.mutedText + '}',
|
|
210
|
-
'.editor button{appearance:none;border:none;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';border-radius:999px;width:32px;height:32px;padding:0;display:flex;align-items:center;justify-content:center;flex-shrink:0;cursor:pointer}',
|
|
211
|
-
'.editor button svg{width:16px;height:16px;display:block}',
|
|
212
|
-
'.editor button[disabled]{opacity:.5;cursor:default}'
|
|
213
|
-
].join('');
|
|
214
|
-
shadow.appendChild(style);
|
|
215
|
-
|
|
216
|
-
var cursorStyle = document.createElement('style');
|
|
217
|
-
cursorStyle.id = 'openchamber-annotation-cursor';
|
|
218
|
-
document.head.appendChild(cursorStyle);
|
|
219
|
-
var setCursor = function (value) {
|
|
220
|
-
cursorStyle.textContent = value ? '*{cursor:' + value + ' !important}' : '';
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
var svgNS = 'http://www.w3.org/2000/svg';
|
|
224
|
-
var svg = document.createElementNS(svgNS, 'svg');
|
|
225
|
-
svg.setAttribute('class', 'layer');
|
|
226
|
-
svg.style.overflow = 'visible';
|
|
227
|
-
shadow.appendChild(svg);
|
|
228
|
-
|
|
229
|
-
var hoverBox = document.createElement('div');
|
|
230
|
-
hoverBox.className = 'box';
|
|
231
|
-
var hoverLabel = document.createElement('div');
|
|
232
|
-
hoverLabel.className = 'label';
|
|
233
|
-
var marqueeBox = document.createElement('div');
|
|
234
|
-
marqueeBox.className = 'box';
|
|
235
|
-
shadow.append(hoverBox, hoverLabel, marqueeBox);
|
|
236
|
-
|
|
237
|
-
var positionBox = function (node, rect) {
|
|
238
|
-
node.style.display = 'block';
|
|
239
|
-
node.style.transform = 'translate(' + rect.x + 'px,' + rect.y + 'px)';
|
|
240
|
-
node.style.width = rect.width + 'px';
|
|
241
|
-
node.style.height = rect.height + 'px';
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
var tools = document.createElement('div');
|
|
245
|
-
tools.className = 'tools';
|
|
246
|
-
shadow.appendChild(tools);
|
|
247
|
-
|
|
248
|
-
var toolButtons = {};
|
|
249
|
-
[['select', LABELS.select], ['marquee', LABELS.marquee], ['draw', LABELS.draw]].forEach(function (entry) {
|
|
250
|
-
var button = document.createElement('button');
|
|
251
|
-
button.type = 'button';
|
|
252
|
-
button.textContent = entry[1];
|
|
253
|
-
button.addEventListener('click', function () { setTool(entry[0]); });
|
|
254
|
-
toolButtons[entry[0]] = button;
|
|
255
|
-
tools.appendChild(button);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
var editor = document.createElement('div');
|
|
259
|
-
editor.className = 'editor';
|
|
260
|
-
shadow.appendChild(editor);
|
|
261
|
-
|
|
262
|
-
var comment = document.createElement('textarea');
|
|
263
|
-
comment.rows = 1;
|
|
264
|
-
comment.placeholder = LABELS.commentPlaceholder;
|
|
265
|
-
var submit = document.createElement('button');
|
|
266
|
-
submit.type = 'button';
|
|
267
|
-
// Icon-only attach button (Remix attachment-2), matching the chat comment
|
|
268
|
-
// input; the localized label stays available to assistive tech.
|
|
269
|
-
submit.setAttribute('aria-label', LABELS.submit);
|
|
270
|
-
submit.title = LABELS.submit;
|
|
271
|
-
submit.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.8287 7.75737L9.1718 13.4142C8.78127 13.8047 8.78127 14.4379 9.1718 14.8284C9.56232 15.219 10.1955 15.219 10.586 14.8284L16.2429 9.17158C17.4144 8.00001 17.4144 6.10052 16.2429 4.92894C15.0713 3.75737 13.1718 3.75737 12.0002 4.92894L6.34337 10.5858C4.39075 12.5384 4.39075 15.7042 6.34337 17.6569C8.29599 19.6095 11.4618 19.6095 13.4144 17.6569L19.0713 12L20.4855 13.4142L14.8287 19.0711C12.095 21.8047 7.66283 21.8047 4.92916 19.0711C2.19549 16.3374 2.19549 11.9053 4.92916 9.17158L10.586 3.51473C12.5386 1.56211 15.7045 1.56211 17.6571 3.51473C19.6097 5.46735 19.6097 8.63317 17.6571 10.5858L12.0002 16.2427C10.8287 17.4142 8.92916 17.4142 7.75759 16.2427C6.58601 15.0711 6.58601 13.1716 7.75759 12L13.4144 6.34316L14.8287 7.75737Z" fill="currentColor"/></svg>';
|
|
272
|
-
editor.append(comment, submit);
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Grows the box with its content.
|
|
276
|
-
*
|
|
277
|
-
* A hidden element reports scrollHeight 0, so measuring one collapses the
|
|
278
|
-
* field to nothing — which is what left a sliver of a click target and an
|
|
279
|
-
* invisible caret. Measuring only while visible, and never below the CSS
|
|
280
|
-
* min-height, keeps it usable.
|
|
281
|
-
*/
|
|
282
|
-
var resizeComment = function () {
|
|
283
|
-
if (editor.style.display === 'none') return;
|
|
284
|
-
comment.style.height = 'auto';
|
|
285
|
-
comment.style.height = Math.max(32, Math.min(comment.scrollHeight, 104)) + 'px';
|
|
286
|
-
};
|
|
287
|
-
comment.addEventListener('input', resizeComment);
|
|
288
|
-
|
|
289
|
-
// -------------------------------------------------------------- selection
|
|
290
|
-
|
|
291
|
-
var lastTargetRect = null;
|
|
292
|
-
|
|
293
|
-
/** Places the comment box under whatever was just marked, kept on screen. */
|
|
294
|
-
var positionEditor = function () {
|
|
295
|
-
if (!lastTargetRect) {
|
|
296
|
-
editor.style.display = 'none';
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
var wasHidden = editor.style.display === 'none';
|
|
300
|
-
editor.style.display = 'flex';
|
|
301
|
-
// Measured now that it is laid out, not while it was still hidden.
|
|
302
|
-
if (wasHidden) resizeComment();
|
|
303
|
-
var box = editor.getBoundingClientRect();
|
|
304
|
-
var left = lastTargetRect.x + lastTargetRect.width / 2 - box.width / 2;
|
|
305
|
-
var top = lastTargetRect.y + lastTargetRect.height + EDITOR_GAP;
|
|
306
|
-
// Above the target when there is no room below, so the box is never left
|
|
307
|
-
// half off the bottom of the page.
|
|
308
|
-
if (top + box.height > window.innerHeight - 8) {
|
|
309
|
-
top = Math.max(8, lastTargetRect.y - box.height - EDITOR_GAP);
|
|
310
|
-
}
|
|
311
|
-
left = Math.max(8, Math.min(left, window.innerWidth - box.width - 8));
|
|
312
|
-
editor.style.transform = 'translate(' + Math.round(left) + 'px,' + Math.round(top) + 'px)';
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
/** Focus after layout: focusing a zero-height field puts the caret nowhere. */
|
|
316
|
-
var focusComment = function () {
|
|
317
|
-
requestAnimationFrame(function () {
|
|
318
|
-
try {
|
|
319
|
-
comment.focus({ preventScroll: true });
|
|
320
|
-
comment.setSelectionRange(comment.value.length, comment.value.length);
|
|
321
|
-
} catch (error) { /* field went away */ }
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
var hasTargets = function () {
|
|
326
|
-
return Boolean(selected) || regions.length > 0 || strokes.length > 0;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
var syncChrome = function () {
|
|
330
|
-
submit.disabled = !hasTargets();
|
|
331
|
-
if (!hasTargets()) {
|
|
332
|
-
lastTargetRect = null;
|
|
333
|
-
editor.style.display = 'none';
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
positionEditor();
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
var syncSelectionVisuals = function () {
|
|
340
|
-
if (!selected) return;
|
|
341
|
-
var rect = rectFrom(selected.element.getBoundingClientRect());
|
|
342
|
-
if (!usableRect(rect)) {
|
|
343
|
-
selected.outline.style.display = 'none';
|
|
344
|
-
selected.badge.style.display = 'none';
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
positionBox(selected.outline, rect);
|
|
348
|
-
selected.badge.style.display = 'block';
|
|
349
|
-
selected.badge.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
350
|
-
lastTargetRect = rect;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
var dropSelection = function () {
|
|
354
|
-
if (!selected) return;
|
|
355
|
-
selected.outline.remove();
|
|
356
|
-
selected.badge.remove();
|
|
357
|
-
selected = null;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
var selectElement = function (element) {
|
|
361
|
-
var wasSelected = selected && selected.element === element;
|
|
362
|
-
dropSelection();
|
|
363
|
-
if (wasSelected) {
|
|
364
|
-
// Clicking the chosen element again clears it, so a misclick costs one
|
|
365
|
-
// click rather than starting over.
|
|
366
|
-
lastTargetRect = null;
|
|
367
|
-
syncChrome();
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
var outline = document.createElement('div');
|
|
371
|
-
outline.className = 'box';
|
|
372
|
-
var badge = document.createElement('div');
|
|
373
|
-
badge.className = 'label';
|
|
374
|
-
badge.textContent = selectorPart(element);
|
|
375
|
-
shadow.append(outline, badge);
|
|
376
|
-
selected = { id: nextId('element'), element: element, outline: outline, badge: badge };
|
|
377
|
-
syncSelectionVisuals();
|
|
378
|
-
syncChrome();
|
|
379
|
-
focusComment();
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
var setTool = function (next) {
|
|
383
|
-
tool = next;
|
|
384
|
-
hoverBox.style.display = 'none';
|
|
385
|
-
hoverLabel.style.display = 'none';
|
|
386
|
-
marqueeBox.style.display = 'none';
|
|
387
|
-
setCursor(next === 'select' ? '' : 'crosshair');
|
|
388
|
-
for (var key in toolButtons) {
|
|
389
|
-
if (Object.prototype.hasOwnProperty.call(toolButtons, key)) {
|
|
390
|
-
toolButtons[key].setAttribute('aria-pressed', key === next ? 'true' : 'false');
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// ------------------------------------------------------------- interaction
|
|
396
|
-
|
|
397
|
-
var drag = null;
|
|
398
|
-
|
|
399
|
-
var onPointerMove = function (event) {
|
|
400
|
-
if (drag) {
|
|
401
|
-
if (drag.kind === 'marquee') {
|
|
402
|
-
drag.rect = normalizeRect(drag.startX, drag.startY, event.clientX, event.clientY);
|
|
403
|
-
positionBox(marqueeBox, drag.rect);
|
|
404
|
-
} else if (drag.kind === 'draw') {
|
|
405
|
-
drag.points.push({ x: event.clientX, y: event.clientY });
|
|
406
|
-
drag.path.setAttribute('d', drag.points.map(function (point, index) {
|
|
407
|
-
return (index === 0 ? 'M' : 'L') + point.x + ' ' + point.y;
|
|
408
|
-
}).join(' '));
|
|
409
|
-
}
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (tool !== 'select') return;
|
|
414
|
-
var element = elementFromPoint(event.clientX, event.clientY);
|
|
415
|
-
if (!element) {
|
|
416
|
-
hoverBox.style.display = 'none';
|
|
417
|
-
hoverLabel.style.display = 'none';
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
var rect = rectFrom(element.getBoundingClientRect());
|
|
421
|
-
positionBox(hoverBox, rect);
|
|
422
|
-
hoverLabel.textContent = selectorPart(element);
|
|
423
|
-
hoverLabel.style.display = 'block';
|
|
424
|
-
hoverLabel.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
var onPointerDown = function (event) {
|
|
428
|
-
if (event.button !== 0) return;
|
|
429
|
-
if (isOverlayNode(event.target)) return;
|
|
430
|
-
event.preventDefault();
|
|
431
|
-
event.stopPropagation();
|
|
432
|
-
|
|
433
|
-
if (tool === 'select') {
|
|
434
|
-
var element = elementFromPoint(event.clientX, event.clientY);
|
|
435
|
-
if (element) selectElement(element);
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (tool === 'marquee') {
|
|
440
|
-
drag = { kind: 'marquee', startX: event.clientX, startY: event.clientY, rect: null };
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
var path = document.createElementNS(svgNS, 'path');
|
|
445
|
-
path.setAttribute('fill', 'none');
|
|
446
|
-
path.setAttribute('stroke', THEME.primary);
|
|
447
|
-
path.setAttribute('stroke-width', '2.5');
|
|
448
|
-
path.setAttribute('stroke-linecap', 'round');
|
|
449
|
-
path.setAttribute('stroke-linejoin', 'round');
|
|
450
|
-
svg.appendChild(path);
|
|
451
|
-
drag = { kind: 'draw', path: path, points: [{ x: event.clientX, y: event.clientY }] };
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
var onPointerUp = function () {
|
|
455
|
-
if (!drag) return;
|
|
456
|
-
var finished = drag;
|
|
457
|
-
drag = null;
|
|
458
|
-
|
|
459
|
-
if (finished.kind === 'marquee') {
|
|
460
|
-
marqueeBox.style.display = 'none';
|
|
461
|
-
var rect = finished.rect;
|
|
462
|
-
if (!rect || !usableRect(rect)) return;
|
|
463
|
-
// A region marks an area, not the elements inside it: expanding it into a
|
|
464
|
-
// selection made the result depend on the page's markup rather than on
|
|
465
|
-
// what was drawn.
|
|
466
|
-
regions.push({ id: nextId('region'), rect: rect });
|
|
467
|
-
var outline = document.createElementNS(svgNS, 'rect');
|
|
468
|
-
outline.setAttribute('x', String(rect.x));
|
|
469
|
-
outline.setAttribute('y', String(rect.y));
|
|
470
|
-
outline.setAttribute('width', String(rect.width));
|
|
471
|
-
outline.setAttribute('height', String(rect.height));
|
|
472
|
-
outline.style.fill = THEME.primarySoft;
|
|
473
|
-
outline.setAttribute('stroke', THEME.primary);
|
|
474
|
-
outline.setAttribute('stroke-width', '1.5');
|
|
475
|
-
outline.setAttribute('rx', '2');
|
|
476
|
-
svg.appendChild(outline);
|
|
477
|
-
lastTargetRect = rect;
|
|
478
|
-
syncChrome();
|
|
479
|
-
focusComment();
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
var points = finished.points;
|
|
484
|
-
if (points.length < 2) {
|
|
485
|
-
if (finished.path.parentNode) finished.path.parentNode.removeChild(finished.path);
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
var minX = points[0].x, minY = points[0].y, maxX = points[0].x, maxY = points[0].y;
|
|
489
|
-
for (var p = 1; p < points.length; p += 1) {
|
|
490
|
-
minX = Math.min(minX, points[p].x);
|
|
491
|
-
minY = Math.min(minY, points[p].y);
|
|
492
|
-
maxX = Math.max(maxX, points[p].x);
|
|
493
|
-
maxY = Math.max(maxY, points[p].y);
|
|
494
|
-
}
|
|
495
|
-
var bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
496
|
-
strokes.push({ id: nextId('stroke'), points: points, bounds: bounds });
|
|
497
|
-
lastTargetRect = bounds;
|
|
498
|
-
syncChrome();
|
|
499
|
-
focusComment();
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Swallows the page's own mouse handling while annotating.
|
|
504
|
-
*
|
|
505
|
-
* Blocking pointerdown is not enough: a click still follows it, so marking a
|
|
506
|
-
* button pressed that button and marking a link navigated away from the page
|
|
507
|
-
* being annotated. These are the events that reach page code, so these are
|
|
508
|
-
* the ones that have to stop.
|
|
509
|
-
*/
|
|
510
|
-
var blockPageInteraction = function (event) {
|
|
511
|
-
if (isOverlayNode(event.target)) return;
|
|
512
|
-
event.preventDefault();
|
|
513
|
-
event.stopPropagation();
|
|
514
|
-
};
|
|
515
|
-
var BLOCKED_EVENTS = ['click', 'auxclick', 'dblclick', 'mousedown', 'mouseup', 'contextmenu'];
|
|
516
|
-
|
|
517
|
-
var onScrollOrResize = function () {
|
|
518
|
-
syncSelectionVisuals();
|
|
519
|
-
positionEditor();
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
var onKeyDown = function (event) {
|
|
523
|
-
if (event.key === 'Escape') {
|
|
524
|
-
event.preventDefault();
|
|
525
|
-
event.stopImmediatePropagation();
|
|
526
|
-
finish(null);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
var onCommentKeyDown = function (event) {
|
|
531
|
-
// Do not let the annotated page treat typed letters as its own shortcuts.
|
|
532
|
-
event.stopPropagation();
|
|
533
|
-
if (event.key === 'Enter' && !event.shiftKey) {
|
|
534
|
-
event.preventDefault();
|
|
535
|
-
attach();
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
document.addEventListener('pointermove', onPointerMove, true);
|
|
540
|
-
document.addEventListener('pointerdown', onPointerDown, true);
|
|
541
|
-
document.addEventListener('pointerup', onPointerUp, true);
|
|
542
|
-
BLOCKED_EVENTS.forEach(function (name) {
|
|
543
|
-
window.addEventListener(name, blockPageInteraction, { capture: true, passive: false });
|
|
544
|
-
});
|
|
545
|
-
window.addEventListener('scroll', onScrollOrResize, true);
|
|
546
|
-
window.addEventListener('resize', onScrollOrResize, true);
|
|
547
|
-
window.addEventListener('keydown', onKeyDown, true);
|
|
548
|
-
comment.addEventListener('keydown', onCommentKeyDown);
|
|
549
|
-
|
|
550
|
-
// ------------------------------------------------------------------ finish
|
|
551
|
-
|
|
552
|
-
var teardown = function () {
|
|
553
|
-
document.removeEventListener('pointermove', onPointerMove, true);
|
|
554
|
-
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
555
|
-
document.removeEventListener('pointerup', onPointerUp, true);
|
|
556
|
-
BLOCKED_EVENTS.forEach(function (name) {
|
|
557
|
-
window.removeEventListener(name, blockPageInteraction, true);
|
|
558
|
-
});
|
|
559
|
-
window.removeEventListener('scroll', onScrollOrResize, true);
|
|
560
|
-
window.removeEventListener('resize', onScrollOrResize, true);
|
|
561
|
-
window.removeEventListener('keydown', onKeyDown, true);
|
|
562
|
-
comment.removeEventListener('keydown', onCommentKeyDown);
|
|
563
|
-
setCursor('');
|
|
564
|
-
if (cursorStyle.parentNode) cursorStyle.parentNode.removeChild(cursorStyle);
|
|
565
|
-
if (host.parentNode) host.parentNode.removeChild(host);
|
|
566
|
-
try { delete window['${Yi}']; } catch (error) { /* non-configurable */ }
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
var finish = function (payload) {
|
|
570
|
-
if (settled) return;
|
|
571
|
-
settled = true;
|
|
572
|
-
teardown();
|
|
573
|
-
// Removing the chrome is not enough: the host screenshots this page right
|
|
574
|
-
// after we resolve, and the compositor can still hold a frame containing
|
|
575
|
-
// our outlines. Yield two frames so the page has actually repainted.
|
|
576
|
-
requestAnimationFrame(function () {
|
|
577
|
-
requestAnimationFrame(function () { resolve(payload); });
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
var attach = function () {
|
|
582
|
-
if (!hasTargets()) return;
|
|
583
|
-
finish({
|
|
584
|
-
id: 'annotation-' + Date.now(),
|
|
585
|
-
pageUrl: String(location.href),
|
|
586
|
-
pageTitle: String(document.title || ''),
|
|
587
|
-
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
588
|
-
devicePixelRatio: window.devicePixelRatio || 1,
|
|
589
|
-
comment: comment.value,
|
|
590
|
-
// Zero or one element, never more. Kept as a list so elements, regions
|
|
591
|
-
// and strokes stay one uniform shape for everything downstream.
|
|
592
|
-
elements: selected ? [{ id: selected.id, element: describe(selected.element) }] : [],
|
|
593
|
-
regions: regions.map(function (entry) { return { id: entry.id, rect: entry.rect }; }),
|
|
594
|
-
strokes: strokes.map(function (entry) {
|
|
595
|
-
return { id: entry.id, points: entry.points, bounds: entry.bounds };
|
|
596
|
-
})
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
submit.addEventListener('click', attach);
|
|
601
|
-
|
|
602
|
-
(document.body || document.documentElement).appendChild(host);
|
|
603
|
-
setTool('select');
|
|
604
|
-
syncChrome();
|
|
605
|
-
});`},Ly={kind:"idle"},xn=t=>typeof t=="object"&&t!==null,vn=t=>typeof t=="number"&&Number.isFinite(t),Hl=t=>xn(t)&&Object.values(t).every(e=>typeof e=="string"),La=t=>xn(t)&&vn(t.x)&&vn(t.y)&&vn(t.width)&&vn(t.height),Lu=t=>xn(t)&&vn(t.x)&&vn(t.y),$y=t=>xn(t)&&typeof t.tag=="string"&&typeof t.selectorPart=="string"&&(t.id===void 0||typeof t.id=="string")&&(t.className===void 0||typeof t.className=="string"),Wy=t=>xn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&La(t.bounds)&&Lu(t.center)&&Hl(t.attributes)&&Hl(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every($y),zy=t=>xn(t)&&typeof t.id=="string"&&Wy(t.element),Vy=t=>xn(t)&&typeof t.id=="string"&&La(t.rect),Uy=t=>xn(t)&&typeof t.id=="string"&&La(t.bounds)&&Array.isArray(t.points)&&t.points.every(Lu),Ky=t=>xn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&xn(t.viewport)&&vn(t.viewport.width)&&vn(t.viewport.height)&&vn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(zy)&&Array.isArray(t.regions)&&t.regions.every(Vy)&&Array.isArray(t.strokes)&&t.strokes.every(Uy),Hy=1600,Gy=t=>new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to decode browser page capture")),r.src=t}),qy=async({base64:t,mime:e,captureWidth:n,captureHeight:r,cssWidth:i,cssHeight:o,payload:l,accentColor:a,accentFill:u})=>{if(!t)return null;try{const d=await Gy(`data:${e};base64,${t}`),h=Math.max(1,d.naturalWidth||n),f=Math.max(1,d.naturalHeight||r),g=h/Math.max(1,i||h),p=f/Math.max(1,o||f),w=Math.min(1,Hy/h),v=document.createElement("canvas");v.width=Math.max(1,Math.floor(h*w)),v.height=Math.max(1,Math.floor(f*w));const x=v.getContext("2d");if(!x)return null;x.scale(w,w),x.drawImage(d,0,0,h,f);const m=N=>({x:N.x*g,y:N.y*p,width:N.width*g,height:N.height*p}),b=Math.max(2,2.5*g/Math.max(w,.2));x.strokeStyle=a,x.fillStyle=u;const y=N=>{const C=m(N);x.lineWidth=b,x.fillRect(C.x,C.y,C.width,C.height),x.strokeRect(C.x,C.y,C.width,C.height)};for(const N of l.elements)y(N.element.bounds);for(const N of l.regions)y(N.rect);for(const N of l.strokes)N.points.length<2||(x.beginPath(),N.points.forEach((C,k)=>{const A=C.x*g,D=C.y*p;k===0?x.moveTo(A,D):x.lineTo(A,D)}),x.lineCap="round",x.lineJoin="round",x.lineWidth=b*1.4,x.stroke());const S=await new Promise(N=>v.toBlob(N,"image/jpeg",.85));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Qy="({ width: window.innerWidth, height: window.innerHeight })",Yy=async t=>{try{const e=await t.executeJavaScript(Qy,!0);if(!e||typeof e!="object")return null;const n=e;return typeof n.width!="number"||typeof n.height!="number"||!Number.isFinite(n.width)||!Number.isFinite(n.height)?null:{width:n.width,height:n.height}}catch{return null}},wo=async t=>{try{await t.executeJavaScript(By,!1)}catch{}},Xy=async({host:t,theme:e,labels:n})=>{const r=_y(e,n),i=await t.executeJavaScript(r,!0);if(i==null)return null;if(!Ky(i))return await wo(t),null;const o=i;try{const l=await Yy(t)??o.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:o,screenshot:null};const u=await qy({base64:a.base64,mime:a.mime||"image/jpeg",captureWidth:a.width,captureHeight:a.height,cssWidth:l.width,cssHeight:l.height,payload:o,accentColor:e.primary,accentFill:e.primarySoft});return{payload:o,screenshot:u}}catch{return{payload:o,screenshot:null}}},nn={colorScheme:"dark",primary:"rgb(59, 130, 246)",primarySoft:"rgba(59, 130, 246, 0.16)",primaryFaint:"rgba(59, 130, 246, 0.10)",primaryContrast:"rgb(255, 255, 255)",surface:"rgb(24, 24, 27)",surfaceElevated:"rgb(32, 32, 36)",glassSurface:"rgba(32, 32, 36, 0.64)",glassFilter:"blur(26px) saturate(1.16)",border:"rgba(255, 255, 255, 0.14)",text:"rgb(244, 244, 245)",mutedText:"rgba(244, 244, 245, 0.62)"},Jy=()=>{if(typeof document>"u"||!document.body)return null;const t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;pointer-events:none",document.body.appendChild(t),{read:e=>{t.style.backgroundColor="",t.style.backgroundColor=e;const n=window.getComputedStyle(t).backgroundColor;return n&&n!=="rgba(0, 0, 0, 0)"?n:""},readVariable:e=>window.getComputedStyle(document.documentElement).getPropertyValue(e).trim(),dispose:()=>t.remove()}},Zy=t=>{const e=Jy();if(!e)return{...nn,colorScheme:t};try{const n=(a,u)=>e.read(`var(${a})`)||u,r=(a,u,d)=>e.read(`color-mix(in srgb, var(${a}) ${u}%, transparent)`)||d,i=e.readVariable("--oc-glass-tooltip-opacity")||"62%",o=e.readVariable("--oc-glass-blur")||"26px",l=e.readVariable("--oc-glass-saturation")||"1.16";return{colorScheme:t,glassSurface:e.read(`color-mix(in srgb, var(--surface-elevated) ${i}, transparent)`)||nn.glassSurface,glassFilter:`blur(${o}) saturate(${l})`,primary:n("--primary",nn.primary),primarySoft:r("--primary",16,nn.primarySoft),primaryFaint:r("--primary",10,nn.primaryFaint),primaryContrast:n("--primary-foreground",nn.primaryContrast),surface:n("--surface-background",nn.surface),surfaceElevated:n("--surface-elevated",nn.surfaceElevated),border:n("--border",nn.border),text:n("--foreground",nn.text),mutedText:n("--muted-foreground",nn.mutedText)}}catch{return{...nn,colorScheme:t}}finally{e.dispose()}};let ur=null,mr=null,So=null,zr=0,Bo=null;const mn=new Set,e1=3e4,t1=45e3,$u=()=>{So&&(clearTimeout(So),So=null)},Wu=()=>{if(mr||mn.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(zr,5)),e1);mr=setTimeout(()=>{mr=null,zr+=1,$a()},t)},Vr=()=>{$u(),ur&&ur.close(),ur=null},Gl=()=>{$u(),mn.size!==0&&(So=setTimeout(()=>{Vr(),Wu()},t1))},s1=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},oo=t=>!t||typeof t!="object"?null:t,n1=t=>{if(t.type==="aiworker:event-stream-ready"){zr=0;return}if(t.type==="aiworker:heartbeat")return;if(t.type==="aiworker:agent-memory-changed"){const u=oo(t.properties),h={type:"agent-memory-changed",scope:u?.scope==="project"?"project":"global",...typeof u?.projectId=="string"&&u.projectId.length>0?{projectId:u.projectId}:{}};for(const f of mn)f(h);return}if(t.type==="aiworker:session-created"){const u=oo(t.properties),d=typeof u?.sessionId=="string"?u.sessionId:"",h=typeof u?.directory=="string"?u.directory:"";if(!d||!h)return;const f={type:"session-created",sessionId:d,directory:h,createdAt:typeof u?.createdAt=="number"?u.createdAt:Date.now(),promptDispatched:u?.promptDispatched===!0,dispatchedAsCommand:u?.dispatchedAsCommand===!0,...typeof u?.projectId=="string"&&u.projectId.length>0?{projectId:u.projectId}:{}};for(const g of mn)g(f);return}if(t.type==="aiworker:browser-control-request"){const u=oo(t.properties),d=typeof u?.requestId=="string"?u.requestId:"",h=typeof u?.action=="string"?u.action:"";if(!d||!h)return;const f=u?.parameters,g={type:"browser-control-request",requestId:d,action:h,parameters:f&&typeof f=="object"&&!Array.isArray(f)?f:{}};for(const p of mn)p(g);return}if(t.type!=="aiworker:scheduled-task-ran")return;const e=oo(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",i=typeof e?.ranAt=="number"?e.ranAt:Date.now(),o=e?.status,l=o==="running"||o==="error"?o:"success";if(!n||!r)return;const a={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:i,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const u of mn)u(a)},$a=()=>{if(typeof window>"u"||mn.size===0||typeof EventSource!="function"||ur&&ur.readyState!==EventSource.CLOSED)return;Vr();const t=typeof window<"u"&&!!window.__AIWORKER_ELECTRON__,e=new EventSource(ad().sse("/api/openchamber/events",t?{browser:"1"}:void 0));e.onopen=()=>{Gl()},e.onmessage=n=>{Gl();const r=s1(n.data);r&&n1(r)},e.onerror=()=>{Vr(),Wu()},ur=e},r1=()=>{Bo||typeof window>"u"||(Bo=Go(()=>{Vr(),zr=0,$a()}))},o1=()=>{Bo?.(),Bo=null},Yr=t=>(mn.add(t),r1(),$a(),()=>{mn.delete(t),mn.size===0&&(mr&&(clearTimeout(mr),mr=null),zr=0,Vr(),o1())}),i1=2e3,a1=50;let Yn=null,fr=null,Er=null;const l1=async t=>{try{const e=await ds("/api/browser-control/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t})});return e.ok?(await e.json())?.granted===!0:!1}catch{return!1}},sr=async(t,e)=>{try{const n=await ds("/api/browser-control/result",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t,...e})});n.ok||console.warn(`[browser-control] the server rejected the result for ${t} (HTTP ${n.status}); the agent will see this action time out`)}catch(n){console.warn(`[browser-control] could not deliver the result for ${t}:`,n)}},c1=async(t=i1)=>{const e=Date.now()+t;for(;!Yn&&Date.now()<e;)await new Promise(n=>setTimeout(n,a1));return Yn},d1=async t=>{const e=t.action==="browser.open",n=Yn;if(!(!n&&!(e&&fr))&&await l1(t.requestId))try{if(e&&!n){const i=typeof t.parameters.url=="string"?t.parameters.url:"";if(!i){await sr(t.requestId,{ok:!1,error:"url is required"});return}fr?.(i);const o=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!o||o==="fill"){await sr(t.requestId,{ok:!0,data:{url:i,opened:!0}});return}const l=await c1();if(!l){await sr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!1,note:"The panel had no browser view yet, so the viewport was not applied. Call browser.resize now that one exists."}});return}const a=await l.run("browser.resize",{viewport:o}),u=a&&typeof a=="object"?a.viewport??null:null;await sr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!0,viewport:u}});return}const r=await n.run(t.action,t.parameters);await sr(t.requestId,{ok:!0,data:r})}catch(r){await sr(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},zu=()=>{Er||(Er=Yr(t=>{t.type==="browser-control-request"&&d1({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},Vu=()=>{Yn||fr||!Er||(Er(),Er=null)},u1=t=>(Yn=t,zu(),()=>{Yn===t&&(Yn=null),Vu()}),m1=t=>(fr=t,zu(),()=>{fr===t&&(fr=null),Vu()}),f1=50,h1=6,p1=2048,g1=200,Uu=t=>{const e=dr(String(t??"").trim());if(!e||e.length>p1)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},x1=(t,e)=>{const n=Uu(e.url);if(!n)return t;const r=t.find(l=>l.url===n),i=String(e.title??"").trim().slice(0,g1)||r?.title||"";return[{url:n,title:i,lastVisitedAt:e.at},...t.filter(l=>l.url!==n)].slice(0,f1)},b1=(t,e)=>{const n=Uu(e);return t.filter(r=>r.url!==n)},y1=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),Ku=(t,e,n=h1)=>{const r=String(e??"").trim().toLowerCase(),i=[...t].sort((l,a)=>a.lastVisitedAt-l.lastVisitedAt);if(!r)return i.slice(0,n);const o=r.replace(/^https?:\/\//,"");return i.filter(l=>{const a=y1(l);return l.url===r||a===o?!1:a.includes(o)}).slice(0,n)},ql=20,vo=t=>{const e=ct((t||"").trim());return e?JSON.stringify([Ss(),e]):""},w1=t=>{const e=Object.keys(t);if(e.length<=ql)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,i)=>i[1]-r[1]).slice(0,ql);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},hr=Zn()(wg(t=>({byProject:{},recordVisit:(e,n)=>{const r=vo(e);r&&t(i=>{const o=i.byProject[r]??[],l=x1(o,{...n,at:Date.now()});return l===o?i:{byProject:w1({...i.byProject,[r]:l})}})},forget:(e,n)=>{const r=vo(e);r&&t(i=>{const o=i.byProject[r];return o?{byProject:{...i.byProject,[r]:b1(o,n)}}:i})},clear:e=>{const n=vo(e);n&&t(r=>{if(!(n in r.byProject))return r;const i={...r.byProject};return delete i[n],{byProject:i}})}}),{name:"openchamber-browser-history",version:1,storage:Um(),partialize:t=>({byProject:t.byProject})})),S1=[],Hu=t=>e=>{const n=vo(t);return(n?e.byProject[n]:void 0)??S1},Xi=new Map,Ur=new Map,Gu=()=>typeof window<"u"&&!!window.__AIWORKER_ELECTRON__,qu=t=>{if(!t)return!1;try{const e=new URL(t,typeof window<"u"?window.location.href:void 0),n=typeof window<"u"?window.__AIWORKER_LOCAL_ORIGIN__:"";return n&&e.origin===n?!1:!xr(e.toString())}catch{return!1}},Qu=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:0}catch{return 0}},Ql=(t,e)=>{try{const n=new URL(t);return n.protocol="http:",n.hostname="127.0.0.1",n.port=String(e),n.toString()}catch{return t}};class Mr extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const Yl=async t=>{if(!t||!Gu()||!xr(t))return t;const e=Mn();if(!qu(e))return t;const n=Qu(t);if(!n)return t;const r=`${e}|${n}`,i=Xi.get(r);if(i){try{Ur.set(i,new URL(t).origin)}catch{}return Ql(t,i)}try{const o=await Tr("desktop_dev_tunnel_open",{baseUrl:e,port:n,clientToken:Fr(),requestHeaders:ld()});if(!o||!Number.isInteger(o.localPort)||o.localPort<=0)throw new Mr(t);Xi.set(r,o.localPort);try{Ur.set(o.localPort,new URL(t).origin)}catch{}return Ql(t,o.localPort)}catch(o){throw o instanceof Mr?o:new Mr(t)}},Xl=t=>{if(!t||!Gu()||!xr(t)||!qu(Mn()))return!1;const e=Qu(t);return e>0&&!Ur.has(e)},kr=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=Ur.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},v1=()=>{Xi.clear(),Ur.clear()};typeof window<"u"&&Go(v1);const Jl=6e3,j1=120,k1=80,C1=`
|
|
606
|
-
var MAX_ELEMENTS = ${j1};
|
|
607
|
-
var MAX_LABEL_CHARS = ${k1};
|
|
608
|
-
var visible = function (element) {
|
|
609
|
-
var rect = element.getBoundingClientRect();
|
|
610
|
-
if (rect.width < 1 || rect.height < 1) return false;
|
|
611
|
-
var style = window.getComputedStyle(element);
|
|
612
|
-
return style.visibility !== 'hidden' && style.display !== 'none' && Number(style.opacity) !== 0;
|
|
613
|
-
};
|
|
614
|
-
var label = function (element) {
|
|
615
|
-
var aria = element.getAttribute('aria-label');
|
|
616
|
-
if (aria) return aria.trim();
|
|
617
|
-
var value = element.getAttribute('value');
|
|
618
|
-
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
619
|
-
if (text) return text.slice(0, MAX_LABEL_CHARS);
|
|
620
|
-
if (value) return String(value).slice(0, MAX_LABEL_CHARS);
|
|
621
|
-
var placeholder = element.getAttribute('placeholder');
|
|
622
|
-
return placeholder ? placeholder.trim().slice(0, MAX_LABEL_CHARS) : '';
|
|
623
|
-
};
|
|
624
|
-
var isUnique = function (selector) {
|
|
625
|
-
try {
|
|
626
|
-
return document.querySelectorAll(selector).length === 1;
|
|
627
|
-
} catch (error) {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Names an element by what it is, falling back to where it sits.
|
|
634
|
-
*
|
|
635
|
-
* A positional chain like 'main > section:nth-of-type(3) > div > a' survives
|
|
636
|
-
* only until the markup shifts, and says nothing about what it points at.
|
|
637
|
-
* Anything the page states about identity — an id, a test id, an accessible
|
|
638
|
-
* name — outlives edits and reads as the thing it selects. The chain remains
|
|
639
|
-
* as the last resort, because something always has to work.
|
|
640
|
-
*/
|
|
641
|
-
var cssPath = function (element) {
|
|
642
|
-
var tag = element.tagName.toLowerCase();
|
|
643
|
-
|
|
644
|
-
if (element.id) {
|
|
645
|
-
var byId = '#' + CSS.escape(element.id);
|
|
646
|
-
if (isUnique(byId)) return byId;
|
|
647
|
-
}
|
|
648
|
-
var stableAttrs = ['data-testid', 'data-test-id', 'data-test', 'name', 'aria-label'];
|
|
649
|
-
for (var a = 0; a < stableAttrs.length; a += 1) {
|
|
650
|
-
var value = element.getAttribute(stableAttrs[a]);
|
|
651
|
-
if (!value) continue;
|
|
652
|
-
var raw = String(value);
|
|
653
|
-
// A value containing a quote would need escaping for no real gain: such
|
|
654
|
-
// attributes are rare, and the positional chain still covers them.
|
|
655
|
-
if (raw.indexOf('"') !== -1) continue;
|
|
656
|
-
var byAttr = tag + '[' + stableAttrs[a] + '="' + raw + '"]';
|
|
657
|
-
if (isUnique(byAttr)) return byAttr;
|
|
658
|
-
}
|
|
659
|
-
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
660
|
-
if (className) {
|
|
661
|
-
var classes = className.split(/\\s+/).filter(Boolean);
|
|
662
|
-
for (var c = 0; c < classes.length; c += 1) {
|
|
663
|
-
var byClass = tag + '.' + CSS.escape(classes[c]);
|
|
664
|
-
if (isUnique(byClass)) return byClass;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
var parts = [];
|
|
669
|
-
var node = element;
|
|
670
|
-
var depth = 0;
|
|
671
|
-
while (node && node.nodeType === 1 && depth < 6) {
|
|
672
|
-
var part = node.tagName.toLowerCase();
|
|
673
|
-
var parent = node.parentElement;
|
|
674
|
-
if (!parent) { parts.unshift(part); break; }
|
|
675
|
-
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
676
|
-
return child.tagName === node.tagName;
|
|
677
|
-
});
|
|
678
|
-
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
679
|
-
parts.unshift(part);
|
|
680
|
-
if (node.id) { parts[0] = '#' + CSS.escape(node.id); break; }
|
|
681
|
-
node = parent;
|
|
682
|
-
depth += 1;
|
|
683
|
-
}
|
|
684
|
-
return parts.join(' > ');
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
/** What a screen reader would announce, or '' when there is nothing to say. */
|
|
688
|
-
var accessibleName = function (element) {
|
|
689
|
-
var aria = element.getAttribute('aria-label');
|
|
690
|
-
if (aria && aria.trim()) return aria.trim();
|
|
691
|
-
var labelled = element.getAttribute('aria-labelledby');
|
|
692
|
-
if (labelled) {
|
|
693
|
-
var source = document.getElementById(labelled.split(/\\s+/)[0]);
|
|
694
|
-
if (source && (source.innerText || '').trim()) return source.innerText.trim();
|
|
695
|
-
}
|
|
696
|
-
var title = element.getAttribute('title');
|
|
697
|
-
if (title && title.trim()) return title.trim();
|
|
698
|
-
var alt = element.getAttribute('alt');
|
|
699
|
-
if (alt && alt.trim()) return alt.trim();
|
|
700
|
-
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
701
|
-
if (text) return text;
|
|
702
|
-
var value = element.getAttribute('value');
|
|
703
|
-
return value && String(value).trim() ? String(value).trim() : '';
|
|
704
|
-
};
|
|
705
|
-
var findByText = function (needle) {
|
|
706
|
-
var wanted = String(needle).replace(/\\s+/g, ' ').trim().toLowerCase();
|
|
707
|
-
var candidates = document.querySelectorAll('a, button, [role="button"], [role="link"], input[type="submit"], input[type="button"], summary, label');
|
|
708
|
-
var exact = null;
|
|
709
|
-
var partial = null;
|
|
710
|
-
for (var i = 0; i < candidates.length; i += 1) {
|
|
711
|
-
var element = candidates[i];
|
|
712
|
-
if (!visible(element)) continue;
|
|
713
|
-
var text = label(element).toLowerCase();
|
|
714
|
-
if (!text) continue;
|
|
715
|
-
if (text === wanted) { exact = element; break; }
|
|
716
|
-
if (!partial && text.indexOf(wanted) !== -1) partial = element;
|
|
717
|
-
}
|
|
718
|
-
return exact || partial;
|
|
719
|
-
};
|
|
720
|
-
`,Xr=t=>`(() => {
|
|
721
|
-
${C1}
|
|
722
|
-
${t}
|
|
723
|
-
})()`,N1=({selector:t}={})=>Xr(`
|
|
724
|
-
var scopeSelector = ${JSON.stringify(t??"")};
|
|
725
|
-
var root = document;
|
|
726
|
-
if (scopeSelector) {
|
|
727
|
-
try { root = document.querySelector(scopeSelector); }
|
|
728
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + scopeSelector }; }
|
|
729
|
-
if (!root) return { ok: false, error: 'No element matches ' + scopeSelector };
|
|
730
|
-
}
|
|
731
|
-
var interactive = root.querySelectorAll('a[href], button, input, select, textarea, [role="button"], [role="link"], [role="tab"], [contenteditable="true"]');
|
|
732
|
-
var elements = [];
|
|
733
|
-
var visibleTotal = 0;
|
|
734
|
-
for (var i = 0; i < interactive.length; i += 1) {
|
|
735
|
-
var element = interactive[i];
|
|
736
|
-
if (!visible(element)) continue;
|
|
737
|
-
visibleTotal += 1;
|
|
738
|
-
if (elements.length >= MAX_ELEMENTS) continue;
|
|
739
|
-
|
|
740
|
-
var rect = element.getBoundingClientRect();
|
|
741
|
-
// Empty and default-valued fields are left out rather than serialized as
|
|
742
|
-
// "" and false. Repeated across a hundred entries that overhead dwarfed
|
|
743
|
-
// the information it carried.
|
|
744
|
-
var entry = {
|
|
745
|
-
selector: cssPath(element),
|
|
746
|
-
tag: element.tagName.toLowerCase(),
|
|
747
|
-
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
748
|
-
};
|
|
749
|
-
// The list covers the whole document so anything can be clicked without
|
|
750
|
-
// scrolling to it first, which means bounds alone do not say what is on
|
|
751
|
-
// screen — a negative y reads as a bug otherwise.
|
|
752
|
-
if (rect.bottom > 0 && rect.top < window.innerHeight) entry.inViewport = true;
|
|
753
|
-
var type = element.getAttribute('type');
|
|
754
|
-
if (type) entry.type = type;
|
|
755
|
-
var role = element.getAttribute('role');
|
|
756
|
-
if (role) entry.role = role;
|
|
757
|
-
var labelText = label(element);
|
|
758
|
-
if (labelText) entry.label = labelText;
|
|
759
|
-
if (element.disabled === true) entry.disabled = true;
|
|
760
|
-
// Flagged rather than described: reporting the accessible name of every
|
|
761
|
-
// element would cost more than it tells, while its absence on something
|
|
762
|
-
// clickable is a defect worth naming.
|
|
763
|
-
if (!accessibleName(element)) entry.missingAccessibleName = true;
|
|
764
|
-
elements.push(entry);
|
|
765
|
-
}
|
|
766
|
-
var body = document.body ? (document.body.innerText || '') : '';
|
|
767
|
-
var text = body.replace(/\\n{3,}/g, '\\n\\n').trim();
|
|
768
|
-
var docEl = document.documentElement;
|
|
769
|
-
var result = {
|
|
770
|
-
ok: true,
|
|
771
|
-
url: String(location.href),
|
|
772
|
-
title: String(document.title || ''),
|
|
773
|
-
scope: scopeSelector || 'document',
|
|
774
|
-
scrollY: Math.round(window.scrollY),
|
|
775
|
-
maxScrollY: Math.max(0, Math.round(docEl.scrollHeight - window.innerHeight)),
|
|
776
|
-
text: text.slice(0, ${Jl}),
|
|
777
|
-
elements: elements
|
|
778
|
-
};
|
|
779
|
-
// State what was dropped. A capped list that reports only its own length
|
|
780
|
-
// reads as the whole page, and the agent acts as if it had seen everything.
|
|
781
|
-
if (text.length > ${Jl}) {
|
|
782
|
-
result.textTruncated = true;
|
|
783
|
-
result.textTotalChars = text.length;
|
|
784
|
-
}
|
|
785
|
-
if (visibleTotal > elements.length) {
|
|
786
|
-
result.elementsTruncated = true;
|
|
787
|
-
result.interactiveElementsOnPage = visibleTotal;
|
|
788
|
-
}
|
|
789
|
-
return result;
|
|
790
|
-
`),A1=({selector:t,text:e})=>Xr(`
|
|
791
|
-
var selector = ${JSON.stringify(t??"")};
|
|
792
|
-
var text = ${JSON.stringify(e??"")};
|
|
793
|
-
var target = null;
|
|
794
|
-
if (selector) {
|
|
795
|
-
try { target = document.querySelector(selector); }
|
|
796
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
797
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
798
|
-
} else {
|
|
799
|
-
target = findByText(text);
|
|
800
|
-
if (!target) return { ok: false, error: 'No clickable element has the label ' + text };
|
|
801
|
-
}
|
|
802
|
-
if (target.disabled === true) return { ok: false, error: 'Element is disabled' };
|
|
803
|
-
target.scrollIntoView({ block: 'center', inline: 'center' });
|
|
804
|
-
target.click();
|
|
805
|
-
return { ok: true, clicked: cssPath(target), label: label(target), url: String(location.href) };
|
|
806
|
-
`),D1=({selector:t,value:e,submit:n})=>Xr(`
|
|
807
|
-
var selector = ${JSON.stringify(t)};
|
|
808
|
-
var value = ${JSON.stringify(e)};
|
|
809
|
-
var target = null;
|
|
810
|
-
try { target = document.querySelector(selector); }
|
|
811
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
812
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
813
|
-
|
|
814
|
-
var editable = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
815
|
-
if (!editable) return { ok: false, error: selector + ' is not a text field' };
|
|
816
|
-
if (target.disabled === true || target.readOnly === true) return { ok: false, error: 'Field is not editable' };
|
|
817
|
-
|
|
818
|
-
target.scrollIntoView({ block: 'center' });
|
|
819
|
-
target.focus();
|
|
820
|
-
if (target.isContentEditable) {
|
|
821
|
-
target.textContent = value;
|
|
822
|
-
} else {
|
|
823
|
-
// Frameworks track the value through the native setter; assigning the
|
|
824
|
-
// property directly leaves React and friends unaware of the change.
|
|
825
|
-
var prototype = target.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
826
|
-
var setter = Object.getOwnPropertyDescriptor(prototype, 'value');
|
|
827
|
-
if (setter && setter.set) setter.set.call(target, value);
|
|
828
|
-
else target.value = value;
|
|
829
|
-
}
|
|
830
|
-
target.dispatchEvent(new Event('input', { bubbles: true }));
|
|
831
|
-
target.dispatchEvent(new Event('change', { bubbles: true }));
|
|
832
|
-
|
|
833
|
-
if (${n?"true":"false"}) {
|
|
834
|
-
var enter = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true };
|
|
835
|
-
target.dispatchEvent(new KeyboardEvent('keydown', enter));
|
|
836
|
-
target.dispatchEvent(new KeyboardEvent('keyup', enter));
|
|
837
|
-
var form = target.form;
|
|
838
|
-
if (form && typeof form.requestSubmit === 'function') form.requestSubmit();
|
|
839
|
-
}
|
|
840
|
-
return { ok: true, selector: cssPath(target), url: String(location.href) };
|
|
841
|
-
`),P1=({selector:t,direction:e})=>Xr(`
|
|
842
|
-
var selector = ${JSON.stringify(t??"")};
|
|
843
|
-
var direction = ${JSON.stringify(e??"")};
|
|
844
|
-
|
|
845
|
-
var settle = function (extra) {
|
|
846
|
-
return new Promise(function (resolve) {
|
|
847
|
-
requestAnimationFrame(function () {
|
|
848
|
-
requestAnimationFrame(function () {
|
|
849
|
-
var doc = document.documentElement;
|
|
850
|
-
var maxScrollY = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
851
|
-
var scrollY = Math.round(window.scrollY);
|
|
852
|
-
var result = { ok: true, scrollY: scrollY, maxScrollY: Math.round(maxScrollY) };
|
|
853
|
-
result.atTop = scrollY <= 1;
|
|
854
|
-
result.atBottom = scrollY >= maxScrollY - 1;
|
|
855
|
-
for (var key in extra) {
|
|
856
|
-
if (Object.prototype.hasOwnProperty.call(extra, key)) result[key] = extra[key];
|
|
857
|
-
}
|
|
858
|
-
resolve(result);
|
|
859
|
-
});
|
|
860
|
-
});
|
|
861
|
-
});
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
if (selector) {
|
|
865
|
-
var target = null;
|
|
866
|
-
try { target = document.querySelector(selector); }
|
|
867
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
868
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
869
|
-
// Instant on purpose: the page's own smooth scrolling would still be
|
|
870
|
-
// animating when the next action runs against it.
|
|
871
|
-
target.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
872
|
-
return settle({ scrolledTo: cssPath(target) });
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
var doc = document.documentElement;
|
|
876
|
-
var page = Math.round(window.innerHeight * 0.85);
|
|
877
|
-
var bottom = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
878
|
-
if (direction === 'down') window.scrollTo({ top: window.scrollY + page, behavior: 'instant' });
|
|
879
|
-
else if (direction === 'up') window.scrollTo({ top: window.scrollY - page, behavior: 'instant' });
|
|
880
|
-
else if (direction === 'top') window.scrollTo({ top: 0, behavior: 'instant' });
|
|
881
|
-
else if (direction === 'bottom') window.scrollTo({ top: bottom, behavior: 'instant' });
|
|
882
|
-
else return { ok: false, error: 'Unknown scroll direction: ' + direction };
|
|
883
|
-
return settle({ direction: direction });
|
|
884
|
-
`),I1=["color","background-color","background-image","opacity","font-family","font-size","font-weight","line-height","letter-spacing","text-align","border-radius","border-width","border-style","border-color","box-shadow","display","position","width","height","padding","margin","gap","flex-direction","justify-content","align-items","z-index","overflow","visibility"],T1=({selector:t})=>Xr(`
|
|
885
|
-
var selector = ${JSON.stringify(t)};
|
|
886
|
-
var target = null;
|
|
887
|
-
try { target = document.querySelector(selector); }
|
|
888
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
889
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
890
|
-
|
|
891
|
-
var computed = window.getComputedStyle(target);
|
|
892
|
-
var styles = {};
|
|
893
|
-
var props = ${JSON.stringify(I1)};
|
|
894
|
-
for (var i = 0; i < props.length; i += 1) {
|
|
895
|
-
var value = computed.getPropertyValue(props[i]);
|
|
896
|
-
if (value) styles[props[i]] = String(value).trim();
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
var rect = target.getBoundingClientRect();
|
|
900
|
-
return {
|
|
901
|
-
ok: true,
|
|
902
|
-
selector: cssPath(target),
|
|
903
|
-
tag: target.tagName.toLowerCase(),
|
|
904
|
-
label: label(target),
|
|
905
|
-
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
|
|
906
|
-
inViewport: rect.bottom > 0 && rect.top < window.innerHeight,
|
|
907
|
-
styles: styles
|
|
908
|
-
};
|
|
909
|
-
`),R1=t=>{const e=Xe.c(18),{entries:n,activeIndex:r,onSelect:i,onForget:o,onHighlight:l}=t,{t:a}=pt();if(n.length===0)return null;let u;e[0]!==a?(u=a("contextPanel.browser.history.label"),e[0]=a,e[1]=u):u=e[1];let d;if(e[2]!==r||e[3]!==n||e[4]!==o||e[5]!==l||e[6]!==i||e[7]!==a){let f;e[9]!==r||e[10]!==o||e[11]!==l||e[12]!==i||e[13]!==a?(f=(g,p)=>s.jsxs("div",{role:"option","aria-selected":p===r,className:Te("group flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1",p===r?"bg-interactive-hover":"hover:bg-interactive-hover"),onPointerDown:w=>{w.preventDefault(),i(g.url)},onPointerEnter:()=>l(p),children:[s.jsx(M,{name:"global",className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate typography-micro text-foreground",children:g.title||_a(g.url)}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:g.url})]}),s.jsx("button",{type:"button",className:Te("shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity","hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"),"aria-label":a("contextPanel.browser.history.forget"),title:a("contextPanel.browser.history.forget"),onPointerDown:w=>{w.preventDefault(),w.stopPropagation(),o(g.url)},children:s.jsx(M,{name:"close",className:"size-3","aria-hidden":"true"})})]},g.url),e[9]=r,e[10]=o,e[11]=l,e[12]=i,e[13]=a,e[14]=f):f=e[14],d=n.map(f),e[2]=r,e[3]=n,e[4]=o,e[5]=l,e[6]=i,e[7]=a,e[8]=d}else d=e[8];let h;return e[15]!==u||e[16]!==d?(h=s.jsx("div",{className:"oc-glass-popover oc-glass-floating absolute inset-x-0 top-full z-50 mt-1 overflow-hidden rounded-xl p-1",role:"listbox","aria-label":u,children:d}),e[15]=u,e[16]=d,e[17]=h):h=e[17],h},rn=t=>{const e=Xe.c(17),{icon:n,label:r,onClick:i,disabled:o,pressed:l}=t,a=l?"secondary":"ghost",u=l&&"text-foreground";let d;e[0]!==u?(d=Te("w-6 shrink-0 rounded-full px-0 text-muted-foreground","hover:text-foreground",u),e[0]=u,e[1]=d):d=e[1];let h;e[2]!==n?(h=s.jsx(M,{name:n,className:"size-3.5","aria-hidden":"true"}),e[2]=n,e[3]=h):h=e[3];let f;e[4]!==o||e[5]!==r||e[6]!==i||e[7]!==l||e[8]!==a||e[9]!==d||e[10]!==h?(f=s.jsx(xt,{asChild:!0,children:s.jsx(at,{type:"button",variant:a,size:"xs",className:d,onClick:i,disabled:o,"aria-label":r,"aria-pressed":l,children:h})}),e[4]=o,e[5]=r,e[6]=i,e[7]=l,e[8]=a,e[9]=d,e[10]=h,e[11]=f):f=e[11];let g;e[12]!==r?(g=s.jsx(bt,{sideOffset:6,children:r}),e[12]=r,e[13]=g):g=e[13];let p;return e[14]!==f||e[15]!==g?(p=s.jsxs(gt,{children:[f,g]}),e[14]=f,e[15]=g,e[16]=p):p=e[16],p},Yu=t=>{const e=Xe.c(104),{address:n,suggestions:r,onForgetSuggestion:i,onAddressChange:o,onSubmit:l,onBack:a,onForward:u,onReload:d,onOpenExternal:h,canGoBack:f,canGoForward:g,isLoading:p,onAnnotate:w,onOpenDevTools:v,isAnnotating:x,onHardReload:m,onZoomIn:b,onZoomOut:y,onZoomReset:S,zoomPercent:N,onClearCookies:C,onClearCache:k,onToggleDeviceBar:A,isDeviceBarOpen:D}=t;let P;e[0]!==r?(P=r===void 0?[]:r,e[0]=r,e[1]=P):P=e[1];const F=P,W=N===void 0?100:N,{t:E}=pt(),[H,z]=c.useState(!1),[B,T]=c.useState(-1);let j;e[2]!==H||e[3]!==F?(j=H?F:[],e[2]=H,e[3]=F,e[4]=j):j=e[4];const I=j;let _;e[5]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{T(-1)},e[5]=_):_=e[5];let K;e[6]!==n||e[7]!==H?(K=[n,H],e[6]=n,e[7]=H,e[8]=K):K=e[8],c.useEffect(_,K);let G;e[9]!==l?(G=q=>{z(!1),T(-1),l(q)},e[9]=l,e[10]=G):G=e[10];const Q=G;let ge;e[11]!==B||e[12]!==Q||e[13]!==I?(ge=q=>{if(I.length!==0){if(q.key==="ArrowDown"||q.key==="ArrowUp"){q.preventDefault();const Ee=q.key==="ArrowDown"?1:-1,Me=I.length;T(O=>{const oe=O+Ee;return oe<-1?Me-1:oe>=Me?-1:oe});return}if(q.key==="Escape"&&B>=0){q.preventDefault(),T(-1);return}if(q.key==="Enter"&&B>=0){q.preventDefault();const Ee=I[B];Ee&&Q(Ee.url)}}},e[11]=B,e[12]=Q,e[13]=I,e[14]=ge):ge=e[14];const se=ge;let Y;e[15]!==E?(Y=E("contextPanel.browser.back"),e[15]=E,e[16]=Y):Y=e[16];const te=!f;let he;e[17]!==a||e[18]!==te||e[19]!==Y?(he=s.jsx(rn,{icon:"arrow-left",label:Y,onClick:a,disabled:te}),e[17]=a,e[18]=te,e[19]=Y,e[20]=he):he=e[20];let L;e[21]!==E?(L=E("contextPanel.browser.forward"),e[21]=E,e[22]=L):L=e[22];const le=!g;let Z;e[23]!==u||e[24]!==L||e[25]!==le?(Z=s.jsx(rn,{icon:"arrow-right",label:L,onClick:u,disabled:le}),e[23]=u,e[24]=L,e[25]=le,e[26]=Z):Z=e[26];let ue;e[27]!==p||e[28]!==E?(ue=E(p?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=p,e[28]=E,e[29]=ue):ue=e[29];let V;e[30]!==d||e[31]!==ue?(V=s.jsx(rn,{icon:"refresh",label:ue,onClick:d}),e[30]=d,e[31]=ue,e[32]=V):V=e[32];let ee;e[33]!==m||e[34]!==E?(ee=m?s.jsx(rn,{icon:"restart",label:E("contextPanel.browser.hardReload"),onClick:m}):null,e[33]=m,e[34]=E,e[35]=ee):ee=e[35];let be;e[36]!==n||e[37]!==Q?(be=q=>{q.preventDefault(),Q(n)},e[36]=n,e[37]=Q,e[38]=be):be=e[38];let xe;e[39]!==o?(xe=q=>o(q.target.value),e[39]=o,e[40]=xe):xe=e[40];let Ne,Pe;e[41]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>z(!0),Pe=()=>z(!1),e[41]=Ne,e[42]=Pe):(Ne=e[41],Pe=e[42]);const Se=I.length>0;let Re;e[43]===Symbol.for("react.memo_cache_sentinel")?(Re=Te("h-6 w-full rounded-full border border-border/50 bg-[var(--surface-elevated)] px-3","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[43]=Re):Re=e[43];let ye;e[44]!==E?(ye=E("contextPanel.browser.addressAria"),e[44]=E,e[45]=ye):ye=e[45];let pe;e[46]!==n||e[47]!==se||e[48]!==xe||e[49]!==Se||e[50]!==ye?(pe=s.jsx("input",{value:n,onChange:xe,onFocus:Ne,onBlur:Pe,onKeyDown:se,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":Se,"aria-controls":"openchamber-browser-address-suggestions",className:Re,"aria-label":ye}),e[46]=n,e[47]=se,e[48]=xe,e[49]=Se,e[50]=ye,e[51]=pe):pe=e[51];let me;e[52]!==i?(me=q=>i?.(q),e[52]=i,e[53]=me):me=e[53];let je;e[54]!==B||e[55]!==Q||e[56]!==me||e[57]!==I?(je=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(R1,{entries:I,activeIndex:B,onSelect:Q,onForget:me,onHighlight:T})}),e[54]=B,e[55]=Q,e[56]=me,e[57]=I,e[58]=je):je=e[58];let ne;e[59]!==be||e[60]!==pe||e[61]!==je?(ne=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:be,children:[pe,je]}),e[59]=be,e[60]=pe,e[61]=je,e[62]=ne):ne=e[62];let fe;e[63]!==b||e[64]!==y||e[65]!==S||e[66]!==E||e[67]!==W?(fe=y&&b?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(rn,{icon:"subtract",label:E("contextPanel.browser.zoomOut"),onClick:y}),W!==100&&S?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsxs(at,{type:"button",variant:"ghost",size:"xs",className:"shrink-0 rounded-full px-1.5 typography-micro tabular-nums text-muted-foreground",onClick:S,"aria-label":E("contextPanel.browser.zoomReset"),children:[W,"%"]})}),s.jsx(bt,{sideOffset:6,children:E("contextPanel.browser.zoomReset")})]}):null,s.jsx(rn,{icon:"add",label:E("contextPanel.browser.zoomIn"),onClick:b})]}):null,e[63]=b,e[64]=y,e[65]=S,e[66]=E,e[67]=W,e[68]=fe):fe=e[68];let ce;e[69]!==C||e[70]!==E?(ce=C?s.jsx(rn,{icon:"delete-bin",label:E("contextPanel.browser.clearCookies"),onClick:C}):null,e[69]=C,e[70]=E,e[71]=ce):ce=e[71];let R;e[72]!==k||e[73]!==E?(R=k?s.jsx(rn,{icon:"database-2",label:E("contextPanel.browser.clearCache"),onClick:k}):null,e[72]=k,e[73]=E,e[74]=R):R=e[74];let $;e[75]!==D||e[76]!==A||e[77]!==E?($=A?s.jsx(rn,{icon:"smartphone",label:E("contextPanel.browser.deviceToolbar"),onClick:A,pressed:D}):null,e[75]=D,e[76]=A,e[77]=E,e[78]=$):$=e[78];let de;e[79]!==x||e[80]!==w||e[81]!==E?(de=w?s.jsx(rn,{icon:"markup",label:E("contextPanel.browser.annotate.toggle"),onClick:w,pressed:x}):null,e[79]=x,e[80]=w,e[81]=E,e[82]=de):de=e[82];let ie;e[83]!==v||e[84]!==E?(ie=v?s.jsx(rn,{icon:"terminal-box",label:E("contextPanel.browser.devTools"),onClick:v}):null,e[83]=v,e[84]=E,e[85]=ie):ie=e[85];let Ae;e[86]!==E?(Ae=E("contextPanel.browser.openExternal"),e[86]=E,e[87]=Ae):Ae=e[87];let Be;e[88]!==h||e[89]!==Ae?(Be=s.jsx(rn,{icon:"external-link",label:Ae,onClick:h}),e[88]=h,e[89]=Ae,e[90]=Be):Be=e[90];let Ce;return e[91]!==he||e[92]!==Z||e[93]!==V||e[94]!==ee||e[95]!==ne||e[96]!==fe||e[97]!==ce||e[98]!==R||e[99]!==$||e[100]!==de||e[101]!==ie||e[102]!==Be?(Ce=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[he,Z,V,ee,ne,fe,ce,R,$,de,ie,Be]}),e[91]=he,e[92]=Z,e[93]=V,e[94]=ee,e[95]=ne,e[96]=fe,e[97]=ce,e[98]=R,e[99]=$,e[100]=de,e[101]=ie,e[102]=Be,e[103]=Ce):Ce=e[103],Ce},_o={kind:"fill"},Zl=240,E1=3840,Xu=[{id:"iphone-se",label:"iPhone SE",width:375,height:667},{id:"iphone-14",label:"iPhone 14",width:390,height:844},{id:"iphone-14-pro-max",label:"iPhone 14 Pro Max",width:430,height:932},{id:"pixel-7",label:"Pixel 7",width:412,height:915},{id:"ipad-mini",label:"iPad mini",width:768,height:1024},{id:"ipad-pro",label:"iPad Pro",width:1024,height:1366},{id:"laptop",label:"Laptop",width:1280,height:800},{id:"desktop",label:"Desktop",width:1440,height:900}],ec=t=>Number.isFinite(t)?Math.round(Math.min(E1,Math.max(Zl,t))):Zl,Lo=t=>t.kind==="fill"?null:{width:t.width,height:t.height},Ju=t=>{const e=Xu.find(n=>n.id===t);return e?{kind:"preset",id:e.id,width:e.width,height:e.height}:null},M1=t=>t.kind==="fill"?t:{kind:"custom",width:t.height,height:t.width},O1=(t,e)=>{const n=Lo(t);if(!n)return null;const r=Math.max(1,e.width),i=Math.max(1,e.height),o=Math.min(1,r/n.width,i/n.height);return{width:n.width,height:n.height,scale:o}},F1=["mobile","tablet","desktop","fill"],B1={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},tc=t=>typeof t=="string"&&F1.includes(t),Ji=t=>t==="fill"?_o:Ju(B1[t])??_o,io=t=>{const e=Lo(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=Ji(n),i=Lo(r);if(i&&i.width===e.width&&i.height===e.height)return{mode:n,width:e.width,height:e.height}}return{mode:"custom",width:e.width,height:e.height}},_1=t=>{const e=Xe.c(70),{viewport:n,onViewportChange:r,colorScheme:i,onColorSchemeChange:o,scale:l}=t,{t:a}=pt();let u;e[0]!==n?(u=Lo(n),e[0]=n,e[1]=u):u=e[1];const d=u,h=n.kind==="preset"?n.id:"";let f;e[2]!==r||e[3]!==d?(f=(te,he)=>{const L=Number.parseInt(he,10);if(!Number.isFinite(L))return;const le=d??{width:1280,height:800};r({kind:"custom",width:ec(te==="width"?L:le.width),height:ec(te==="height"?L:le.height)})},e[2]=r,e[3]=d,e[4]=f):f=e[4];const g=f;let p;e[5]===Symbol.for("react.memo_cache_sentinel")?(p=Te("h-6 w-14 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2 text-center","typography-micro tabular-nums text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[5]=p):p=e[5];const w=p;let v;e[6]!==r?(v=te=>{const he=Ju(te.target.value);r(he??_o)},e[6]=r,e[7]=v):v=e[7];let x;e[8]!==a?(x=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=x):x=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=Te("h-6 shrink-0 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[10]=m):m=e[10];let b;e[11]!==a?(b=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=b):b=e[12];let y;e[13]!==b?(y=s.jsx("option",{value:"",children:b}),e[13]=b,e[14]=y):y=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=Xu.map(L1),e[15]=S):S=e[15];let N;e[16]!==h||e[17]!==v||e[18]!==x||e[19]!==y?(N=s.jsxs("select",{value:h,onChange:v,"aria-label":x,className:m,children:[y,S]}),e[16]=h,e[17]=v,e[18]=x,e[19]=y,e[20]=N):N=e[20];const C=d?String(d.width):"";let k;e[21]!==g?(k=te=>g("width",te.target.value),e[21]=g,e[22]=k):k=e[22];let A;e[23]!==a?(A=a("contextPanel.browser.device.width"),e[23]=a,e[24]=A):A=e[24];let D;e[25]!==C||e[26]!==k||e[27]!==A?(D=s.jsx("input",{value:C,onChange:k,placeholder:"—",inputMode:"numeric","aria-label":A,className:w}),e[25]=C,e[26]=k,e[27]=A,e[28]=D):D=e[28];let P;e[29]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=P):P=e[29];const F=d?String(d.height):"";let W;e[30]!==g?(W=te=>g("height",te.target.value),e[30]=g,e[31]=W):W=e[31];let E;e[32]!==a?(E=a("contextPanel.browser.device.height"),e[32]=a,e[33]=E):E=e[33];let H;e[34]!==F||e[35]!==W||e[36]!==E?(H=s.jsx("input",{value:F,onChange:W,placeholder:"—",inputMode:"numeric","aria-label":E,className:w}),e[34]=F,e[35]=W,e[36]=E,e[37]=H):H=e[37];let z;e[38]!==r||e[39]!==n?(z=()=>r(M1(n)),e[38]=r,e[39]=n,e[40]=z):z=e[40];const B=!d;let T;e[41]!==a?(T=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=T):T=e[42];let j;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(M,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=j):j=e[43];let I;e[44]!==z||e[45]!==B||e[46]!==T?(I=s.jsx(xt,{asChild:!0,children:s.jsx(at,{type:"button",variant:"ghost",size:"xs",className:"w-6 shrink-0 rounded-full px-0 text-muted-foreground hover:text-foreground",onClick:z,disabled:B,"aria-label":T,children:j})}),e[44]=z,e[45]=B,e[46]=T,e[47]=I):I=e[47];let _;e[48]!==a?(_=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=_):_=e[49];let K;e[50]!==_?(K=s.jsx(bt,{sideOffset:6,children:_}),e[50]=_,e[51]=K):K=e[51];let G;e[52]!==I||e[53]!==K?(G=s.jsxs(gt,{children:[I,K]}),e[52]=I,e[53]=K,e[54]=G):G=e[54];let Q;e[55]!==l||e[56]!==d?(Q=d&&l<1?s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Math.round(l*100),"%"]}):null,e[55]=l,e[56]=d,e[57]=Q):Q=e[57];let ge;e[58]===Symbol.for("react.memo_cache_sentinel")?(ge=["system","light","dark"],e[58]=ge):ge=e[58];let se;e[59]!==i||e[60]!==o||e[61]!==a?(se=s.jsx("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:ge.map(te=>s.jsx(at,{type:"button",variant:i===te?"secondary":"ghost",size:"xs",className:Te("shrink-0 rounded-full px-2.5 typography-micro",i===te?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>o(te),"aria-pressed":i===te,children:a(te==="system"?"contextPanel.browser.device.schemeSystem":te==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},te))}),e[59]=i,e[60]=o,e[61]=a,e[62]=se):se=e[62];let Y;return e[63]!==N||e[64]!==D||e[65]!==H||e[66]!==G||e[67]!==Q||e[68]!==se?(Y=s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[N,D,P,H,G,Q,se]}),e[63]=N,e[64]=D,e[65]=H,e[66]=G,e[67]=Q,e[68]=se,e[69]=Y):Y=e[69],Y};function L1(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const $1=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},W1=2e3,z1=()=>{if(typeof window>"u"||window.__AIWORKER_ELECTRON__)return!1;const t=Mn();if(!t)return!1;try{return!xr(new URL(t,window.location.href).toString())}catch{return!1}},Zu=t=>{const e=Xe.c(33),{onOpen:n,directory:r}=t,i=r===void 0?"":r,{t:o}=pt();let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={kind:"loading"},e[0]=l):l=e[0];const[a,u]=c.useState(l),d=Vg(i),[h]=c.useState(z1);let f,g;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{let D=!0,P=null;const F=new AbortController,W=()=>{Ey(F.signal).then(E=>{D&&(u(E),P=setTimeout(W,W1))})};return W(),()=>{D=!1,P&&clearTimeout(P),F.abort()}},g=[],e[1]=f,e[2]=g):(f=e[1],g=e[2]),c.useEffect(f,g);const p=a.kind==="ready"?a.servers:null;let w;e[3]!==d||e[4]!==p?(w=Fy({announced:d,discovered:p}),e[3]=d,e[4]=p,e[5]=w):w=e[5];const v=w;let x;e[6]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(kd,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=x):x=e[6];let m;e[7]!==o?(m=o("contextPanel.browser.empty"),e[7]=o,e[8]=m):m=e[8];let b;e[9]!==m?(b=s.jsx("span",{className:"typography-ui-header text-foreground",children:m}),e[9]=m,e[10]=b):b=e[10];let y;e[11]!==o?(y=o("contextPanel.browser.emptyHint"),e[11]=o,e[12]=y):y=e[12];let S;e[13]!==y?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:y}),e[13]=y,e[14]=S):S=e[14];let N;e[15]!==S||e[16]!==b?(N=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[b,S]}),e[15]=S,e[16]=b,e[17]=N):N=e[17];let C;e[18]!==d||e[19]!==v||e[20]!==i||e[21]!==n||e[22]!==h||e[23]!==o?(C=v.length>0?s.jsxs("div",{className:"flex min-h-0 w-full max-w-sm flex-col gap-1",children:[s.jsx("span",{className:"shrink-0 typography-micro text-left text-muted-foreground",children:d.length>0?o("contextPanel.browser.devServers.justStarted"):o("contextPanel.browser.devServers.title")}),h?s.jsx("span",{className:"shrink-0 pb-1 text-left typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.remoteOnly")}):null,s.jsx("div",{className:"flex min-h-0 flex-col gap-1 overflow-y-auto pr-0.5",children:v.map(D=>s.jsxs(at,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{$g(i),n(D.url)},children:[s.jsx(M,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:_a(D.url)||D.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:$1(D.url)})]},D.port))})]}):null,e[18]=d,e[19]=v,e[20]=i,e[21]=n,e[22]=h,e[23]=o,e[24]=C):C=e[24];let k;e[25]!==v.length||e[26]!==a.kind||e[27]!==o?(k=v.length===0&&a.kind==="unavailable"?s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.unavailable")}):null,e[25]=v.length,e[26]=a.kind,e[27]=o,e[28]=k):k=e[28];let A;return e[29]!==N||e[30]!==C||e[31]!==k?(A=s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-5 overflow-hidden bg-background p-6 text-center",children:[x,N,C,k]}),e[29]=N,e[30]=C,e[31]=k,e[32]=A):A=e[32],A},Bs=t=>Math.round(t),V1=(t,e)=>{const n=t.text.trim(),r=Object.entries(t.attributes).map(([a,u])=>`${a}="${u}"`).join(" "),i=t.ancestry.map(a=>a.selectorPart).join(" > "),o=t.computedStyle,l=t.bounds;return[`Element ${e+1}: ${t.tag}`,n?`- Text: ${n}`:null,`- Selector: ${t.selector}`,`- Path: ${t.path}`,i?`- Ancestry: ${i}`:null,r?`- Attributes: ${r}`:null,`- Bounds: x=${Bs(l.x)}, y=${Bs(l.y)}, width=${Bs(l.width)}, height=${Bs(l.height)}`,`- Styles: display=${o.display??""}; position=${o.position??""}; font=${o.fontWeight??""} ${o.fontSize??""} / ${o.lineHeight??""} ${o.fontFamily??""}; color=${o.color??""}; background=${o.backgroundColor??""}`].filter(a=>typeof a=="string")},U1=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Bs(n.x)}, y=${Bs(n.y)}, width=${Bs(n.width)}, height=${Bs(n.height)}`},K1=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Bs(n.x)}, y=${Bs(n.y)}, width=${Bs(n.width)}, height=${Bs(n.height)}`},H1=({payload:t,screenshotAttached:e,intro:n})=>{const r=n.replace(/[.:]+$/g,""),i=t.comment.trim(),o=[`${r}:`,`Page: ${t.pageTitle.trim()||t.pageUrl||"browser"}`,t.pageTitle.trim()&&t.pageUrl?`URL: ${t.pageUrl}`:null,`Viewport: ${Bs(t.viewport.width)}x${Bs(t.viewport.height)}, DPR ${t.devicePixelRatio}`,`Screenshot: ${e?"attached":"not attached"}`,i?`Comment: ${i}`:null];for(const[l,a]of t.elements.entries())o.push("",...V1(a.element,l));return t.regions.length>0&&(o.push(""),t.regions.forEach((l,a)=>o.push(U1(l,a)))),t.strokes.length>0&&(o.push(""),t.strokes.forEach((l,a)=>o.push(K1(l,a)))),o.filter(l=>typeof l=="string").join(`
|
|
910
|
-
`)},G1=t=>{const e=Xe.c(7),{t:n}=pt(),r=Qe(Q1),i=Qe(Y1),o=Ci(X1),l=Lf(J1);let a;return e[0]!==l||e[1]!==o||e[2]!==r||e[3]!==t||e[4]!==i||e[5]!==n?(a=async u=>{const d=r??(i?"draft":null);if(!d){Fe.error(n("contextPanel.browser.annotate.noSession"));return}let h=!1;if(u.screenshot)try{await l(u.screenshot),h=!0}catch{h=!1}o({directory:t,sessionKey:d},{source:"preview-annotation",fileLabel:u.payload.pageUrl||"browser",startLine:1,endLine:1,code:H1({payload:u.payload,screenshotAttached:h,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),Fe.success(n("contextPanel.browser.annotate.attached"))},e[0]=l,e[1]=o,e[2]=r,e[3]=t,e[4]=i,e[5]=n,e[6]=a):a=e[6],a},q1=()=>{const t=Xe.c(16),{t:e}=pt();let n;t[0]!==e?(n=e("contextPanel.browser.annotate.tool.element"),t[0]=e,t[1]=n):n=t[1];let r;t[2]!==e?(r=e("contextPanel.browser.annotate.tool.region"),t[2]=e,t[3]=r):r=t[3];let i;t[4]!==e?(i=e("contextPanel.browser.annotate.tool.draw"),t[4]=e,t[5]=i):i=t[5];let o;t[6]!==e?(o=e("contextPanel.browser.annotate.commentPlaceholder"),t[6]=e,t[7]=o):o=t[7];let l;t[8]!==e?(l=e("contextPanel.browser.annotate.submit"),t[8]=e,t[9]=l):l=t[9];let a;return t[10]!==n||t[11]!==r||t[12]!==i||t[13]!==o||t[14]!==l?(a={select:n,marquee:r,draw:i,commentPlaceholder:o,submit:l},t[10]=n,t[11]=r,t[12]=i,t[13]=o,t[14]=l,t[15]=a):a=t[15],a};function Q1(t){return t.currentSessionId}function Y1(t){return t.newSessionDraft?.open}function X1(t){return t.addDraft}function J1(t){return t.addAttachedFile}const Z1=3e4,ew=3,tw=250,sw={attempts:0,windowStartedAt:null},nw=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=Z1,r=n?0:t.attempts;return r>=ew?null:{delayMs:tw*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},rw=-3,ao=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",ar=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},ow=(t,{initialUrl:e,onUrlChange:n})=>{const[r,i]=c.useState(e?{kind:"loading",url:e}:Ly),[o,l]=c.useState(e),[a,u]=c.useState(""),[d,h]=c.useState(!1),[f,g]=c.useState(!1),p=c.useRef(n);p.current=n;const w=c.useRef(sw);return c.useEffect(()=>{if(!t)return;const v=()=>{try{const P=t.getURL();return ao(P)?P:""}catch{return""}},x=()=>{try{h(t.canGoBack()),g(t.canGoForward())}catch{}},m=P=>{ao(P)&&(l(P),p.current(P))},b=()=>{const P=v();i({kind:"loading",url:P})},y=()=>{const P=v();let F="";try{F=t.getTitle()||""}catch{F=""}u(F),m(P),x(),i(W=>W.kind==="failed"&&W.url===P?W:{kind:"ready",url:P,title:F})},S=P=>{const F=ar(P);ao(F.url)&&(m(F.url),x())},N=P=>{const F=ar(P),W=Array.isArray(F.favicons)?F.favicons.find(Boolean):"",E=v();W&&E&&Bu.getState().resolve(E,W)},C=P=>{const F=ar(P);typeof F.title=="string"&&u(F.title)},k=P=>{const F=ar(P);if(F.isMainFrame===!1)return;const W=typeof F.errorCode=="number"?F.errorCode:0;W!==rw&&i({kind:"failed",url:ao(F.validatedURL)?F.validatedURL:v(),code:W,description:typeof F.errorDescription=="string"?F.errorDescription:""})};let A=null;const D=()=>{const P=v(),F=nw(w.current,Date.now());if(!F){i({kind:"failed",url:P,code:0,description:"",crashed:!0});return}w.current=F.state,i({kind:"loading",url:P}),A=setTimeout(()=>{A=null;try{t.reload()}catch{i({kind:"failed",url:P,code:0,description:"",crashed:!0})}},F.delayMs)};t.addEventListener("did-start-loading",b),t.addEventListener("did-stop-loading",y),t.addEventListener("did-navigate",S),t.addEventListener("did-navigate-in-page",S),t.addEventListener("page-title-updated",C),t.addEventListener("page-favicon-updated",N),t.addEventListener("did-fail-load",k),t.addEventListener("render-process-gone",D),t.addEventListener("crashed",D);try{!t.isLoading()&&v()&&y()}catch{}return()=>{A!==null&&clearTimeout(A),t.removeEventListener("render-process-gone",D),t.removeEventListener("crashed",D),t.removeEventListener("did-start-loading",b),t.removeEventListener("did-stop-loading",y),t.removeEventListener("did-navigate",S),t.removeEventListener("did-navigate-in-page",S),t.removeEventListener("page-title-updated",C),t.removeEventListener("page-favicon-updated",N),t.removeEventListener("did-fail-load",k)}},[t]),{status:r,url:o,title:a,canGoBack:d,canGoForward:f}},iw=()=>typeof window<"u"&&!!window.__AIWORKER_ELECTRON__,aw=4e4,sc=.5,lw=-3,cw=4,dw="persist:openchamber-browser",nc=20,uw=600,mw=2e4,fw=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=pt(),{currentTheme:i}=Jn(),o=c.useRef(null),[l,a]=c.useState(null),u=c.useCallback(ne=>{o.current=ne,a(ne)},[]),d=De(ne=>ne.setContextPanelTabTargetPath),h=c.useRef(dr(t)),f=h.current!==on?h.current:"",[g,p]=c.useState(f?null:on),[w,v]=c.useState(f),[x,m]=c.useState(!1),[b,y]=c.useState(!1),[S,N]=c.useState(0),[C,k]=c.useState(!1),[A,D]=c.useState(_o),P=c.useRef(A);P.current=A;const F=c.useRef([]),[W,E]=c.useState("system"),[H,z]=c.useState({width:0,height:0}),B=c.useRef(null),T=c.useRef(null),j=c.useRef(!1),I=c.useRef(Date.now()),_=c.useCallback(ne=>{!ne||ne===on||!e||!n||d(e,n,ne)},[e,n,d]),K=ow(l,{initialUrl:f,onUrlChange:c.useCallback(ne=>{const fe=kr(ne);v(fe),_(fe)},[_])}),[G,Q]=c.useState(null),ge=G1(e),se=q1(),Y=K.status.kind==="loading",te=hr(Hu(e)),he=hr(ne=>ne.recordVisit),L=hr(ne=>ne.forget);c.useEffect(()=>{K.status.kind==="ready"&&he(e,{url:kr(K.status.url),title:K.status.title})},[e,K.status,he]);const le=c.useMemo(()=>Ku(te,w),[te,w]),Z=c.useCallback(ne=>{const fe=dr(ne);fe!==on&&(v(fe),Q(null),Yl(fe).then(ce=>{const R=o.current;if(!R){p(ce);return}try{R.loadURL(ce)}catch{p(ce)}}).catch(ce=>{ce instanceof Mr&&Q(fe)}))},[]);c.useEffect(()=>{if(!f)return;let ne=!0;return Yl(f).then(fe=>{ne&&p(fe)}).catch(fe=>{if(ne){if(fe instanceof Mr){Q(f),p(on);return}p(f)}}),()=>{ne=!1}},[]);const ue=c.useMemo(()=>({executeJavaScript:async(ne,fe)=>{const ce=o.current;if(!ce)throw new Error("Browser view is not available");return ce.executeJavaScript(ne,fe)},capturePage:async()=>{const ne=o.current;if(!ne)return null;const fe=ne.getWebContentsId();return Number.isFinite(fe)?await Tr("desktop_browser_capture_page",{webContentsId:fe}):null}}),[]),V=c.useCallback(()=>{if(x){m(!1),wo(ue);return}if(!K.url){Fe.error(r("contextPanel.browser.annotate.noPage"));return}const ne=Zy(i.metadata.variant==="light"?"light":"dark");m(!0),Xy({host:ue,theme:ne,labels:se}).then(async fe=>{m(!1),fe&&await ge(fe)}).catch(()=>{m(!1),Fe.error(r("contextPanel.browser.annotate.failed"))})},[ue,ge,i,x,K.url,se,r]);c.useEffect(()=>{if(!x)return;const ne=fe=>{fe.key==="Escape"&&(fe.preventDefault(),fe.stopImmediatePropagation(),m(!1),wo(ue))};return window.addEventListener("keydown",ne,!0),()=>window.removeEventListener("keydown",ne,!0)},[ue,x]);const ee=c.useCallback(async(ne=8e3)=>{const fe=Date.now();for(;;){const ce=o.current;if(!ce)return!1;let R=!1;try{R=ce.isLoading()}catch{return!1}if(!R)return!0;if(Date.now()-fe>ne)return!1;await new Promise($=>setTimeout($,120))}},[]),be=c.useCallback(async(ne,fe)=>{const ce=o.current;if(!ce)throw new Error("The browser panel is not ready");const R=()=>{tc(fe.viewport)&&(D(Ji(fe.viewport)),k(!0))};if(ne==="browser.back"||ne==="browser.forward"){const Ce=ne==="browser.back";if(!(Ce?ce.canGoBack():ce.canGoForward()))throw new Error(Ce?"There is nothing to go back to in this tab":"There is nothing to go forward to in this tab");Ce?ce.goBack():ce.goForward(),await new Promise(Me=>setTimeout(Me,150)),await ee();let Ee="";try{Ee=ce.getTitle()||""}catch{Ee=""}return{url:kr(ce.getURL()),title:Ee}}if(ne==="browser.capture"){De.getState().openContextBrowser(e,ce.getURL());const Ce=Date.now()+1200;let q=0,Ee=0;for(;Ee<2&&Date.now()<Ce;){const oe=ce.getBoundingClientRect().width;Ee=oe>=2&&Math.abs(oe-q)<.5?Ee+1:0,q=oe,await new Promise(re=>setTimeout(re,50))}await new Promise(oe=>{requestAnimationFrame(()=>requestAnimationFrame(()=>oe()))}),await ee();const Me=await ue.capturePage();if(!Me)throw new Error("The page could not be captured");let O="";try{O=ce.getTitle()||""}catch{O=""}return{...Me,url:kr(ce.getURL()),title:O,viewport:io(P.current)}}if(ne==="browser.resize"){if(!tc(fe.viewport))throw new Error("viewport is required");return R(),await new Promise(Ce=>setTimeout(Ce,200)),await ee(),{viewport:io(Ji(fe.viewport))}}if(ne==="browser.open"){const Ce=typeof fe.url=="string"?fe.url:"";if(!Ce)throw new Error("url is required");R(),Z(Ce),await new Promise(Me=>setTimeout(Me,150));const q=await ee(25e3);let Ee="";try{Ee=ce.getTitle()||""}catch{Ee=""}return{url:dr(Ce),title:Ee,opened:!0,settled:q,viewport:io(P.current)}}await ee();const $=Ce=>typeof Ce=="string"&&Ce?Ce:void 0,ie=(()=>{switch(ne){case"browser.snapshot":return N1({selector:$(fe.selector)});case"browser.click":return A1({selector:$(fe.selector),text:$(fe.text)});case"browser.type":return D1({selector:String(fe.selector??""),value:String(fe.value??""),submit:fe.submit===!0});case"browser.inspect":return T1({selector:String(fe.selector??"")});case"browser.scroll":return P1({selector:$(fe.selector),direction:$(fe.direction)});default:return null}})();if(!ie)throw new Error(`Unsupported browser action: ${ne}`);const Ae=await ce.executeJavaScript(ie,!0);if(!Ae||typeof Ae!="object")throw new Error("The page returned no result");const Be=Ae;if(Be.ok!==!0)throw new Error(typeof Be.error=="string"&&Be.error?Be.error:"Browser action failed");if(ne==="browser.snapshot"){const Ce=F.current;return{...Be,viewport:io(P.current),...Ce.length>0?{consoleProblems:[...Ce]}:{}}}return(ne==="browser.click"||ne==="browser.type"&&fe.submit===!0)&&(await new Promise(Ce=>setTimeout(Ce,150)),await ee()),Ae},[ue,e,Z,ee]);c.useEffect(()=>u1({run:be}),[be]),c.useEffect(()=>{const ne=ue;return()=>{wo(ne)}},[ue]),c.useEffect(()=>{if(!l)return;const ne=ce=>{const R=ce;if(typeof R.level!="number"||R.level<2)return;const $=R.sourceId?`${R.sourceId}${R.line?`:${R.line}`:""}`:"";F.current.push({level:R.level>=3?"error":"warning",message:String(R.message??"").slice(0,400),source:$}),F.current.length>nc&&F.current.splice(0,F.current.length-nc)},fe=()=>{F.current=[]};return l.addEventListener("console-message",ne),l.addEventListener("did-start-loading",fe),()=>{l.removeEventListener("console-message",ne),l.removeEventListener("did-start-loading",fe)}},[l]);const xe=c.useRef(new Set),Ne=c.useCallback(ne=>{xe.current.clear(),Z(ne)},[Z]);c.useEffect(()=>{if(!l)return;const ne=ce=>{const R=ar(ce),$=typeof R.url=="string"?R.url:"";!$||!Xl($)||(ce.preventDefault(),Z($))},fe=ce=>{const R=ar(ce);if(R.isMainFrame===!1||R.errorCode===-3)return;const $=typeof R.validatedURL=="string"?R.validatedURL:"";!$||!Xl($)||xe.current.has($)||(xe.current.add($),Z($))};return l.addEventListener("will-navigate",ne),l.addEventListener("did-fail-load",fe),()=>{l.removeEventListener("will-navigate",ne),l.removeEventListener("did-fail-load",fe)}},[Z,l]),c.useEffect(()=>{if(!l)return;const ne=fe=>{const ce=fe.detail;fe.preventDefault(),ce?.url&&Z(ce.url)};return l.addEventListener("new-window",ne),()=>l.removeEventListener("new-window",ne)},[Z,l]);const Pe=c.useCallback(ne=>{const fe=Math.min(cw,Math.max(lw,ne));N(fe);try{o.current?.setZoomLevel(fe)}catch{}},[]),Se=c.useCallback(ne=>{Tr("desktop_browser_clear_data",{partition:dw,cookies:ne==="cookies",cache:ne==="cache"}).then(()=>{Fe.success(r(ne==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{o.current?.reloadIgnoringCache()}catch{}}).catch(()=>Fe.error(r("contextPanel.browser.clearFailed")))},[r]);c.useEffect(()=>{const ne=B.current;if(!ne||typeof ResizeObserver>"u")return;const fe=new ResizeObserver(ce=>{const R=ce[0]?.contentRect;R&&z({width:R.width,height:R.height})});return fe.observe(ne),()=>fe.disconnect()},[]);const Re=c.useCallback(ne=>{E(ne);const fe=o.current;if(!fe)return;let ce=-1;try{ce=fe.getWebContentsId()}catch{return}Tr("desktop_browser_set_color_scheme",{webContentsId:ce,scheme:ne}).catch(R=>{E("system"),Fe.error(R instanceof Error?R.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),ye=c.useCallback(()=>{try{Y?o.current?.stop():o.current?.reload()}catch{}},[Y]),pe=K.status;c.useEffect(()=>{const ne=()=>{y(!0);const R=setTimeout(()=>{try{o.current?.reload()}catch{}},uw);return()=>clearTimeout(R)};if(pe.kind==="failed"){if(!Ty(pe.code,pe.url)){y(!1);return}const R=Date.now(),$=T.current?.url===pe.url?T.current:{url:pe.url,startedAt:R};if(T.current=$,R-$.startedAt>aw){y(!1);return}return ne()}if(pe.kind==="loading")return;if(T.current=null,pe.kind!=="ready"||!pe.url||!xr(pe.url)){j.current=!0,y(!1);return}if(j.current||Date.now()-I.current>mw){j.current=!0,y(!1);return}let fe=!1,ce=null;return My(kr(pe.url)).then(R=>{if(!fe){if(R===null||R<500){j.current=!0,y(!1);return}ce=ne()}}),()=>{fe=!0,ce?.()}},[pe]);const me=K.status.kind==="failed"&&!b?K.status:null,je=O1(A,H);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(Yu,{address:w,onAddressChange:v,onSubmit:Ne,suggestions:le,onForgetSuggestion:ne=>L(e,ne),onBack:()=>{try{o.current?.goBack()}catch{}},onForward:()=>{try{o.current?.goForward()}catch{}},onReload:ye,onOpenExternal:()=>{qo(K.url||w)},canGoBack:K.canGoBack,canGoForward:K.canGoForward,isLoading:Y,onAnnotate:V,isAnnotating:x,onOpenDevTools:()=>{try{o.current?.openDevTools()}catch{}},onHardReload:()=>{try{o.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>Pe(S+sc),onZoomOut:()=>Pe(S-sc),onZoomReset:()=>Pe(0),zoomPercent:Math.round(Math.pow(1.2,S)*100),onClearCookies:()=>Se("cookies"),onClearCache:()=>Se("cache"),onToggleDeviceBar:()=>k(ne=>!ne),isDeviceBarOpen:C}),C?s.jsx(_1,{viewport:A,onViewportChange:D,colorScheme:W,onColorSchemeChange:Re,scale:je?.scale??1}):null,s.jsxs("div",{ref:B,className:Te("relative min-h-0 flex-1 bg-background",je&&"flex items-center justify-center overflow-hidden bg-[var(--surface-muted)]"),children:[g!==null?s.jsx("webview",{ref:u,src:g,partition:"persist:openchamber-browser",allowpopups:!0,style:je?{width:`${je.width}px`,height:`${je.height}px`,transform:`scale(${je.scale})`,border:"none",flex:"none",boxShadow:"0 2px 18px rgba(0,0,0,.28)"}:{width:"100%",height:"100%",border:"none"}}):null,g!==null&&!f&&!K.url&&!Y?s.jsx(Zu,{onOpen:Ne,directory:e}):null,b?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.waitingForServer")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.waitingForServerHint")})]}):null,G?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.tunnelFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.tunnelFailedHint",{url:G})})]}):null,me&&!G?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:me.crashed?r("contextPanel.browser.crashed"):r("contextPanel.browser.loadFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:me.crashed?r("contextPanel.browser.crashedHint"):me.description||r("contextPanel.browser.loadFailedUnknown")})]}):null,Y?s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-0.5 overflow-hidden",children:s.jsx("div",{className:"h-full w-1/3 animate-[browser-progress_1.1s_ease-in-out_infinite] bg-[var(--primary)]"})}):null]})]})},hw=t=>{const e=Xe.c(49),{initialUrl:n,directory:r,tabID:i}=t,{t:o}=pt(),l=De(gw);let a;e[0]!==n?(a=dr(n),e[0]=n,e[1]=a):a=e[1];const u=a,d=u!==on?u:"",[h,f]=c.useState(d),[g,p]=c.useState(d);let w;e[2]!==d?(w=d?[d]:[],e[2]=d,e[3]=w):w=e[3];const[v,x]=c.useState(w),[m,b]=c.useState(d?0:-1),[y,S]=c.useReducer(xw,0);let N;e[4]!==r||e[5]!==l||e[6]!==i?(N=Y=>{!Y||Y===on||!r||!i||l(r,i,Y)},e[4]=r,e[5]=l,e[6]=i,e[7]=N):N=e[7];const C=N;let k;e[8]!==r?(k=Hu(r),e[8]=r,e[9]=k):k=e[9];const A=hr(k),D=hr(bw),P=hr(yw);let F;e[10]!==h||e[11]!==A?(F=Ku(A,h),e[10]=h,e[11]=A,e[12]=F):F=e[12];const W=F;let E;e[13]!==r||e[14]!==m||e[15]!==C||e[16]!==D?(E=Y=>{const te=dr(Y);te!==on&&(f(te),p(te),C(te),D(r,{url:te}),x(he=>{const L=m>=0?he.slice(0,m+1):[];return L[L.length-1]===te?(b(L.length-1),L):(b(L.length),[...L,te])}))},e[13]=r,e[14]=m,e[15]=C,e[16]=D,e[17]=E):E=e[17];const H=E;let z;e[18]!==v||e[19]!==C?(z=Y=>{const te=v[Y];te&&(b(Y),f(te),p(te),C(te))},e[18]=v,e[19]=C,e[20]=z):z=e[20];const B=z;let T;e[21]!==r||e[22]!==P?(T=Y=>P(r,Y),e[21]=r,e[22]=P,e[23]=T):T=e[23];let j,I;e[24]!==B||e[25]!==m?(I=()=>B(m-1),j=()=>B(m+1),e[24]=B,e[25]=m,e[26]=j,e[27]=I):(j=e[26],I=e[27]);let _;e[28]!==h||e[29]!==g?(_=()=>{qo(g||h)},e[28]=h,e[29]=g,e[30]=_):_=e[30];const K=m>0,G=m>=0&&m<v.length-1;let Q;e[31]!==h||e[32]!==H||e[33]!==W||e[34]!==j||e[35]!==_||e[36]!==K||e[37]!==G||e[38]!==T||e[39]!==I?(Q=s.jsx(Yu,{address:h,onAddressChange:f,onSubmit:H,suggestions:W,onForgetSuggestion:T,onBack:I,onForward:j,onReload:S,onOpenExternal:_,canGoBack:K,canGoForward:G,isLoading:!1}),e[31]=h,e[32]=H,e[33]=W,e[34]=j,e[35]=_,e[36]=K,e[37]=G,e[38]=T,e[39]=I,e[40]=Q):Q=e[40];let ge;e[41]!==g||e[42]!==H||e[43]!==y||e[44]!==o?(ge=s.jsx("div",{className:"relative min-h-0 flex-1 bg-background",children:g?s.jsx("iframe",{src:g,title:o("contextPanel.browser.frameTitle"),className:"h-full w-full border-none bg-white",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups"},`${g}|${y}`):s.jsx(Zu,{onOpen:H})}),e[41]=g,e[42]=H,e[43]=y,e[44]=o,e[45]=ge):ge=e[45];let se;return e[46]!==Q||e[47]!==ge?(se=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Q,ge]}),e[46]=Q,e[47]=ge,e[48]=se):se=e[48],se},pw=t=>{const e=Xe.c(3),[n]=c.useState(iw);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(fw,{...t}):s.jsx(hw,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function gw(t){return t.setContextPanelTabTargetPath}function xw(t){return t+1}function bw(t){return t.recordVisit}function yw(t){return t.forget}const ww=Ln(()=>Bn(()=>import("./WalkthroughView-egQgxel3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123])).then(t=>({default:t.WalkthroughView}))),Sw=Ln(()=>Bn(()=>import("./DiffView-DluiRSla.js"),__vite__mapDeps([124,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,117,118,119,120,121,122,123])).then(t=>({default:t.DiffView}))),vw=Ln(()=>Bn(()=>import("./FilesView-Bdq8ppva.js"),__vite__mapDeps([125,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,126,127,128,129,130,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,131,132,117,118,114,121,133,115,134])).then(t=>({default:t.FilesView}))),jw=Ln(()=>Bn(()=>import("./GitView-Znn7VJcP.js"),__vite__mapDeps([135,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,136,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,117,118,120,121,122,123])).then(t=>({default:t.GitView}))),kw=Ln(()=>Bn(()=>import("./LinearIssuesView-jP-hXyac.js"),__vite__mapDeps([137,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(t=>({default:t.LinearIssuesView}))),Cw=Ln(()=>Bn(()=>import("./PlanView-B0F3BtPZ.js"),__vite__mapDeps([138,1,2,4,5,6,7,8,9,126,57,58,59,60,61,62,79,55,56,63,127,128,129,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,80,81,82,115,116,134,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100])).then(t=>({default:t.PlanView}))),Nw=380,Aw=1400,em=600,Dw=100,Pw=24,$o=new Map,Iw=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},rc=t=>Number.isFinite(t)?Math.min(Aw,Math.max(Nw,Math.round(t))):em,Tw=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Rw=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},tm=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="linear"?"contextPanel.mode.linear":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),Ew=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},Mw=(t,e,n)=>{if(t.mode==="chat"){const r=Zi(t.dedupeKey);if(r){const o=e.get(r)?.trim();if(o)return o}const i=t.sessionTitleFallback?.trim();return i||n("contextPanel.mode.chat")}return t.mode==="browser"?_a(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?Ew(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):tm(t.mode,n)},oc=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(wa,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(Au,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(M,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(M,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(M,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="linear")return s.jsx(M,{name:"linear",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(M,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(M,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(M,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(M,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(M,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="browser"){const n=Ow(t.targetPath??"",e);return n?s.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"h-3.5 w-3.5 rounded-[3px] object-contain"}):s.jsx(M,{name:"global",className:"h-3.5 w-3.5"})}},Ow=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},Fw=200,Bw=480,_w=({visible:t})=>{const{t:e}=pt(),n=De(m=>m.contextEditorTreeWidth),r=De(m=>m.setContextEditorTreeWidth),[i,o]=c.useState(!1),l=c.useRef(0),a=c.useRef(n),u=c.useRef(null),d=c.useRef(null),h=c.useRef(null),f=c.useCallback(m=>Math.min(Bw,Math.max(Fw,Math.round(m))),[]),g=c.useCallback(m=>{const b=h.current;b&&(b.style.width=`${m}px`,b.style.setProperty("--oc-editor-tree-width",`${m}px`))},[]),p=m=>{if(t){try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}d.current=m.pointerId,o(!0),l.current=m.clientX,a.current=n,u.current=n,m.preventDefault()}},w=m=>{if(!i||d.current!==m.pointerId)return;const b=l.current-m.clientX,y=f(a.current+b);u.current!==y&&(u.current=y,g(y))},v=m=>{if(d.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const b=f(u.current??n);d.current=null,u.current=null,o(!1),r(b)},x=t?n:0;return s.jsxs("div",{ref:h,className:Te("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${i?u.current??x:x}px`,"--oc-editor-tree-width":`${i?u.current??n:n}px`,overflowX:"clip",transitionProperty:i?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:Te("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",i&&"bg-[var(--interactive-border)]"),onPointerDown:p,onPointerMove:w,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:Te("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",i&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(ey,{})})]})},Zi=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Lw=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},$w=(t,e)=>{if(e.length===0)return $o;const n=new Set(e),r=new Map;for(const i of t){if(!n.has(i.id))continue;const o=i.title?.trim();o&&r.set(i.id,o)}return r.size===0?$o:r},Ww=(t,e)=>{const n=bd(t),r=c.useRef($o),i=c.useRef(e);return i.current=e,c.useSyncExternalStore(n.subscribe,c.useCallback(()=>{const o=$w(n.getState().session,i.current);return Lw(r.current,o)?r.current:(r.current=o,o)},[n]),()=>$o)},zw=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Vw=()=>{const{t}=pt(),e=qr()??"",n=c.useMemo(()=>Iw(e),[e]),r=De(ae=>n?ae.contextPanelByDirectory[n]:void 0),i=De(ae=>ae.closeContextPanel),o=De(ae=>ae.closeContextPanelTab),l=De(ae=>ae.openContextPanelTab),a=De(ae=>ae.toggleContextPanelExpanded),u=De(ae=>ae.setContextPanelWidth),d=De(ae=>ae.setActiveContextPanelTab),h=De(ae=>ae.openContextBrowser);c.useEffect(()=>{if(e)return m1(ae=>h(e,ae))},[e,h]);const f=De(ae=>ae.reorderContextPanelTabs),g=dn(ae=>ae.setSelectedPath),p=De(ae=>ae.contextEditorTreeVisible),w=De(ae=>ae.toggleContextEditorTree),v=De(ae=>ae.openNewContextBrowserTab),x=Bu(ae=>ae.byOrigin),m=De(ae=>ae.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:y,lightThemeId:S,darkThemeId:N,currentTheme:C}=Jn(),k=c.useMemo(()=>r?.tabs??[],[r?.tabs]),A=k.find(ae=>ae.id===r?.activeTabId)??k[k.length-1]??null,D=!!(r?.isOpen&&A),P=!!(D&&r?.expanded),[F,W]=c.useState(null),E=A?.mode??null,H=E?r?.widthByMode?.[E]:void 0,z=E?$f(E):.5,B=F??(typeof window<"u"?window.innerWidth:em*2),T=rc(H??Math.round(z*B)),j=c.useMemo(()=>{const ae=[];for(const X of k){if(X.mode!=="chat")continue;const ve=Zi(X.dedupeKey);ve&&!ae.includes(ve)&&ae.push(ve)}return ae},[k]),I=Ww(n||void 0,j),[_,K]=c.useState(!1),G=c.useRef(0),Q=c.useRef(T),ge=c.useRef(null),se=c.useRef(null),Y=c.useRef(null),te=c.useRef(new Map),he=c.useRef(new Map),L=c.useRef(!1);c.useLayoutEffect(()=>{const ae=Y.current?.parentElement;if(!ae||typeof ResizeObserver>"u")return;const X=new ResizeObserver(()=>{W(ae.clientWidth||null)});return X.observe(ae),W(ae.clientWidth||null),()=>X.disconnect()},[]),c.useEffect(()=>{if(!D||L.current){L.current=D;return}const ae=window.requestAnimationFrame(()=>{Y.current?.focus({preventScroll:!0})});return L.current=!0,()=>window.cancelAnimationFrame(ae)},[D]);const le=c.useRef(null),Z=c.useRef(null),ue=c.useCallback(()=>{Z.current=null;const ae=Y.current,X=ge.current;!ae||X===null||ae.style.setProperty("--oc-context-panel-width",`${X}px`)},[]);c.useEffect(()=>()=>{Z.current!==null&&clearTimeout(Z.current)},[]);const V=c.useCallback(ae=>{const X=rc(ae),ve=le.current;return ve===null?X:Math.min(X,Math.max(1,ve))},[]),ee=c.useCallback(ae=>{!D||P||!n||(se.current=ae.pointerId,K(!0),G.current=ae.clientX,Q.current=T,ge.current=T,le.current=Tw(Y.current),document.documentElement.style.cursor="col-resize",ae.preventDefault())},[n,P,D,T]),be=c.useCallback(()=>{const ae=V(ge.current??T);ge.current=null,le.current=null,Z.current!==null&&(clearTimeout(Z.current),Z.current=null),document.documentElement.style.cursor="",n&&E&&u(n,E,ae),K(!1),se.current=null},[E,V,n,u,T]);c.useEffect(()=>{if(!_)return;const ae=Le=>{if(se.current!==Le.pointerId)return;const $e=G.current-Le.clientX,Ue=V(Q.current+$e);ge.current!==Ue&&(ge.current=Ue,Z.current===null&&(Z.current=setTimeout(ue,Dw)))},X=Le=>{se.current===Le.pointerId&&be()},ve=()=>{be()};return window.addEventListener("pointermove",ae),window.addEventListener("pointerup",X),window.addEventListener("pointercancel",X),window.addEventListener("blur",ve),()=>{window.removeEventListener("pointermove",ae),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",X),window.removeEventListener("blur",ve)}},[ue,V,be,_]),c.useEffect(()=>{_||(ge.current=null,document.documentElement.style.cursor="")},[_]);const xe=c.useCallback(()=>{n&&i(n)},[i,n]),Ne=c.useCallback(()=>{n&&a(n)},[n,a]),Pe=c.useCallback(ae=>{ae.key==="Escape"&&(Wf(ae.target)||(ae.preventDefault(),ae.stopPropagation(),xe()))},[xe]);c.useEffect(()=>{if(!(!n||!A)&&A.mode==="file"&&A.targetPath){g(n,A.targetPath,{allowOutsideRoot:!0});return}},[A,n,g]);const Se=c.useMemo(()=>k.filter(ae=>ae.mode==="chat"),[k]),Re=D&&A?.mode==="chat"?A.id:null,ye=D&&A?.mode==="chat"?Zi(A.dedupeKey):null,pe=Sg(Se,Re);c.useEffect(()=>{if(!D||!n||!ye||typeof window>"u")return;const ae=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){ri(n,ye,!1);return}Cd(ye),ri(n,ye,!0)};ae();const X=window.setInterval(ae,1e4);return window.addEventListener("focus",ae),window.addEventListener("blur",ae),document.addEventListener("visibilitychange",ae),()=>{window.clearInterval(X),window.removeEventListener("focus",ae),window.removeEventListener("blur",ae),document.removeEventListener("visibilitychange",ae),ri(n,ye,!1)}},[ye,n,D]);const me=c.useCallback((ae,X,ve)=>vg(he.current,ae,X,n||null,ve,{mode:b,lightThemeId:S,darkThemeId:N,currentTheme:C},{allowPromptingSubagentSessions:m}),[m,C,N,n,S,b]),je=pe&&ye?me(pe.id,ye,pe.readOnly):null;c.useEffect(()=>{const ae=new Set(k.map(X=>X.id));for(const X of he.current.keys())ae.has(X)||he.current.delete(X)},[k]);const ne=c.useCallback(ae=>{!n||A?.mode!=="diff"||l(n,{mode:"diff",targetPath:A.targetPath,stagedDiff:ae==="staged",diffScope:ae})},[A,n,l]),fe=c.useCallback(()=>{if(typeof window>"u")return;const ae={themeMode:b,lightThemeId:S,darkThemeId:N,currentTheme:C};for(const X of te.current.values()){const ve=X.contentWindow;ve&&ve.postMessage({type:"aiworker:theme-sync",payload:ae},window.location.origin)}},[C,N,S,b]),ce=c.useCallback(()=>{if(typeof window>"u")return;const ae={allowPromptingSubagentSessions:m};for(const X of te.current.values()){const ve=X.contentWindow;ve&&ve.postMessage({type:"aiworker:chat-settings-sync",payload:ae},window.location.origin)}},[m]),R=c.useCallback((ae,X,ve)=>{const Le=X.contentWindow;Le&&Le.postMessage({type:du,payload:{visible:Re===ae}},ve)},[Re]),$=c.useCallback(()=>{if(!(typeof window>"u"))for(const[ae,X]of te.current.entries())R(ae,X,window.location.origin)},[R]);c.useEffect(()=>{if(typeof window>"u")return;const ae=X=>{if(X.origin!==window.location.origin)return;const ve=Array.from(te.current.entries()).find(([,qe])=>qe.contentWindow===X.source);if(!ve)return;const Le=X.data;if(Le?.type===jg){const[qe,nt]=ve;R(qe,nt,X.origin);return}if(Le?.type===kg){if(typeof Le.requestId!="string"||!Le.requestId)return;const qe=Ss(),nt={apiBaseUrl:Mn(),clientToken:Fr(),localOrigin:typeof window.__AIWORKER_LOCAL_ORIGIN__=="string"?window.__AIWORKER_LOCAL_ORIGIN__:"",runtimeHeaders:ld(),relayHostId:qe.startsWith("host:")?qe.slice(5):"",relay:Km()??void 0};X.source?.postMessage({type:Cg,requestId:Le.requestId,payload:nt},X.origin);return}if(Le?.type==="aiworker:theme-sync-request"){fe();return}if(Le?.type==="aiworker:chat-settings-request"){ce();return}if(Le?.type!=="aiworker:cycle-theme-request")return;const $e=["light","dark","system"],We=($e.indexOf(b)+1)%$e.length;y($e[We])};return window.addEventListener("message",ae),()=>window.removeEventListener("message",ae)},[ce,R,fe,y,b]),c.useLayoutEffect(()=>{k.some(X=>X.mode==="chat")&&(fe(),ce(),$())},[N,S,ce,$,fe,k,b]);const de=A?.mode==="file"||A?.mode==="chat"||A?.mode==="browser",ie=c.useMemo(()=>A?k.filter(ae=>ae.mode===A.mode):[],[A,k]),Ae=c.useMemo(()=>ie.map(ae=>{const X=Mw(ae,I,t),ve=zw(X,Pw),Le=Rw(ae.targetPath,e);return{id:ae.id,label:ve,icon:oc(ae,x),title:Le?`${X}: ${Le}`:X,closeLabel:t("contextPanel.tab.closeTabAria",{label:ve})}}),[ie,e,x,I,t]),Be=A?.mode==="context"?s.jsx(xy,{}):A?.mode==="git"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(jw,{isActive:D})}):A?.mode==="pr"?s.jsx(Nb,{}):A?.mode==="linear"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(kw,{})}):A?.mode==="notes"?s.jsx(Wp,{}):A?.mode==="plan"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(Cw,{targetPath:A.targetPath,savedProjectPlan:A.projectPlanId&&A.projectPlanRef?{projectRef:A.projectPlanRef,planId:A.projectPlanId}:null})}):null,Ce=c.useMemo(()=>k.filter(ae=>ae.mode==="browser"),[k]),q=c.useMemo(()=>k.filter(ae=>ae.mode==="diff"),[k]),Ee=c.useMemo(()=>k.some(ae=>ae.mode==="terminal"),[k]),Me=c.useMemo(()=>k.some(ae=>ae.mode==="walkthrough"),[k]),O=c.useMemo(()=>k.some(ae=>ae.mode==="file"),[k]),oe=c.useMemo(()=>k.some(ae=>ae.mode==="file"&&ae.targetPath),[k]),re=A?.mode==="file",we=De(ae=>ae.closeContextPanelTabs),Ve=c.useCallback(ae=>{if(!n)return null;const{id:X,index:ve,allIds:Le,close:$e}=ae,Ue=()=>we(n,Le.filter(Mt=>Mt!==X)),We=()=>we(n,Le.slice(0,ve)),qe=()=>we(n,Le.slice(ve+1)),nt=()=>we(n,Le),yt=Le.length>1,vt=ve===0,He=ve===Le.length-1;return s.jsxs(s.Fragment,{children:[s.jsxs(Kn,{onClick:$e,children:[s.jsx(M,{name:"close",className:"mr-2 size-4"}),t("contextPanel.tab.menu.close")]}),s.jsx(Oi,{}),s.jsxs(Kn,{onClick:Ue,disabled:!yt,children:[s.jsx(M,{name:"expand-horizontal",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeOthers")]}),s.jsxs(Kn,{onClick:We,disabled:vt,children:[s.jsx(M,{name:"expand-left",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToLeft")]}),s.jsxs(Kn,{onClick:qe,disabled:He,children:[s.jsx(M,{name:"expand-right",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToRight")]}),s.jsx(Oi,{}),s.jsxs(Kn,{onClick:nt,disabled:!yt,children:[s.jsx(M,{name:"close-circle",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeAll")]})]})},[we,n,t]),st=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[de?s.jsx(Qd,{items:Ae,activeId:A?.id??null,onSelect:ae=>{n&&d(n,ae)},onClose:ae=>{n&&o(n,ae)},onReorder:(ae,X)=>{n&&f(n,ae,X)},layoutMode:"scrollable",variant:"default",tabContextMenu:Ve}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[A?oc(A,x):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:A?tm(A.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[A?.mode==="browser"?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&v(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(M,{name:"add",className:"h-3.5 w-3.5"})}):null,re?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:w,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":p,children:s.jsx(M,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:Ne,className:"h-7 w-7 p-0",title:t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:P?s.jsx(M,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(M,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:xe,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(M,{name:"close",className:"h-3.5 w-3.5"})})]})]}),Ge=D?P?{"--oc-context-panel-width":F!==null?`${F}px`:"100%",width:F!==null?`${F}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${T}px`}:{"--oc-context-panel-width":`${T}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:Y,"data-context-panel":"true",tabIndex:-1,inert:!D||void 0,className:Te("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!D&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:Pe,style:Ge,children:[D&&!P&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),D&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&s.jsx("div",{className:Te("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",_&&"bg-[var(--interactive-border)]"),onPointerDown:ee,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:Te("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!D&&"pointer-events-none select-none opacity-0"),style:{width:P?F!==null?`${F}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!D,children:[st,s.jsxs("div",{className:Te("relative min-h-0 flex-1 overflow-hidden",_&&"pointer-events-none"),children:[O?s.jsxs("div",{className:Te("absolute inset-0 flex",re?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:oe?s.jsx(c.Suspense,{fallback:null,children:s.jsx(vw,{mode:"editor-only"})}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(M,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.editorEmpty.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.editorEmpty.description")})]})}),s.jsx(_w,{visible:p})]}):null,pe&&ye&&je?s.jsx("iframe",{ref:ae=>{if(!ae){te.current.delete(pe.id);return}te.current.set(pe.id,ae)},src:je,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ye}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{fe(),ce(),$()}},pe.id):null,Ce.map(ae=>s.jsx("div",{className:Te("absolute inset-0",A?.id!==ae.id&&"hidden"),children:s.jsx(pw,{initialUrl:ae.targetPath??"",directory:n,tabID:ae.id})},ae.id)),q.map(ae=>s.jsx("div",{className:Te("absolute inset-0",A?.id!==ae.id&&"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(Sw,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:ae.diffScope??(ae.stagedDiff?"staged":"working"),onDiffScopeChange:ne,targetFilePath:ae.targetPath,flushContent:!0})})},ae.id)),Ee?s.jsx("div",{className:Te("absolute inset-0",A?.mode==="terminal"?"block":"hidden"),children:s.jsx(zp,{visible:D&&A?.mode==="terminal"})}):null,Me?s.jsx("div",{className:Te("absolute inset-0",A?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(ww,{directory:e,visible:A?.mode==="walkthrough"})})}):null,A?.mode!=="chat"&&!re&&A?.mode!=="browser"&&A?.mode!=="diff"&&A?.mode!=="terminal"&&A?.mode!=="walkthrough"?Be:null]})]})]})},Uw=t=>{const e=Xe.c(42),{open:n,onOpenChange:r}=t,{t:i}=pt(),o=De(Kw),l=De(Hw),a=De(Gw),u=De(qw);let d;e[0]!==o?(d=Nd(o),e[0]=o,e[1]=d):d=e[1];const h=d,f=l.length===0;let g;if(e[2]!==l||e[3]!==h){let A;e[5]!==l?(A=D=>l.includes(D.id),e[5]=l,e[6]=A):A=e[6],g=h.every(A),e[2]=l,e[3]=h,e[4]=g}else g=e[4];const p=g;let w;e[7]!==i?(w=i("contextRail.configure.dialogTitle"),e[7]=i,e[8]=w):w=e[8];let v;e[9]!==w?(v=s.jsx(Ds,{children:w}),e[9]=w,e[10]=v):v=e[10];let x;e[11]!==i?(x=i("contextRail.configure.dialogDescription"),e[11]=i,e[12]=x):x=e[12];let m;e[13]!==x?(m=s.jsx(Ps,{children:x}),e[13]=x,e[14]=m):m=e[14];let b;e[15]!==v||e[16]!==m?(b=s.jsxs(Ls,{children:[v,m]}),e[15]=v,e[16]=m,e[17]=b):b=e[17];let y;if(e[18]!==l||e[19]!==a||e[20]!==h||e[21]!==i){let A;e[23]!==l||e[24]!==a||e[25]!==i?(A=D=>s.jsx(zf,{settingsItem:`layout.context-rail.surface.${D.id}`,checked:!l.includes(D.id),onChange:P=>a(D.id,P),label:i(D.labelKey),ariaLabel:i(D.labelKey)},D.id),e[23]=l,e[24]=a,e[25]=i,e[26]=A):A=e[26],y=h.map(A),e[18]=l,e[19]=a,e[20]=h,e[21]=i,e[22]=y}else y=e[22];let S;e[27]!==y?(S=s.jsx("div",{className:"flex flex-col",children:y}),e[27]=y,e[28]=S):S=e[28];let N;e[29]!==f||e[30]!==p||e[31]!==u||e[32]!==i?(N=f?null:s.jsxs("div",{className:"flex items-center justify-between border-t pt-3",children:[p?s.jsx("span",{className:"text-xs text-destructive",children:i("contextRail.configure.noneWarning")}):s.jsx("span",{}),s.jsx(at,{variant:"link",size:"xs",onClick:()=>u([]),className:"normal-case text-muted-foreground hover:text-foreground",children:i("contextRail.configure.showAll")})]}),e[29]=f,e[30]=p,e[31]=u,e[32]=i,e[33]=N):N=e[33];let C;e[34]!==N||e[35]!==b||e[36]!==S?(C=s.jsxs(js,{className:"max-w-md",children:[b,S,N]}),e[34]=N,e[35]=b,e[36]=S,e[37]=C):C=e[37];let k;return e[38]!==r||e[39]!==n||e[40]!==C?(k=s.jsx(vs,{open:n,onOpenChange:r,children:C}),e[38]=r,e[39]=n,e[40]=C,e[41]=k):k=e[41],k};function Kw(t){return t.contextRailOrder}function Hw(t){return t.contextRailHiddenSurfaces}function Gw(t){return t.setContextRailSurfaceVisible}function qw(t){return t.setContextRailHiddenSurfaces}const sm=150,Qw=500,Yw=[],Xw=t=>t>99?"99+":String(t),Jw=t=>{const e=Xe.c(51),{surface:n,isActive:r,showActivityDot:i,label:o,description:l,badgeCount:a,badgeAriaLabel:u,badgeDescription:d,orderNumber:h,showOrderNumber:f,onSelect:g}=t;let p;e[0]!==n.id?(p={id:n.id},e[0]=n.id,e[1]=p):p=e[1];const{attributes:w,listeners:v,setNodeRef:x,transform:m,transition:b,isDragging:y}=Zo(p);let S;e[2]!==a?(S=a!=null&&a>0?Xw(a):null,e[2]=a,e[3]=S):S=e[3];const N=S;let C;e[4]!==m?(C=ei.Translate.toString(m),e[4]=m,e[5]=C):C=e[5];let k;e[6]!==C||e[7]!==b?(k={transform:C,transition:b},e[6]=C,e[7]=b,e[8]=k):k=e[8];const A=y&&"z-10 opacity-70";let D;e[9]!==A?(D=Te("relative",A),e[9]=A,e[10]=D):D=e[10];let P;e[11]!==g||e[12]!==n?(P=()=>g(n),e[11]=g,e[12]=n,e[13]=P):P=e[13];const F=u??o,W=r?"text-primary":"text-muted-foreground hover:text-foreground";let E;e[14]!==W?(E=Te("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",W),e[14]=W,e[15]=E):E=e[15];let H;e[16]!==n.icon||e[17]!==n.id?(H=n.id==="diff"?s.jsx(Au,{}):s.jsx(M,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=H):H=e[18];let z;e[19]!==N||e[20]!==h||e[21]!==i||e[22]!==f?(z=f&&h!=null?s.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:h===10?"0":h}):N?s.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:N}):i?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[19]=N,e[20]=h,e[21]=i,e[22]=f,e[23]=z):z=e[23];let B;e[24]!==w||e[25]!==r||e[26]!==v||e[27]!==E||e[28]!==H||e[29]!==z||e[30]!==P||e[31]!==F?(B=s.jsx(xt,{asChild:!0,children:s.jsxs("button",{type:"button",...w,...v,onClick:P,"aria-label":F,"aria-pressed":r,className:E,children:[H,z]})}),e[24]=w,e[25]=r,e[26]=v,e[27]=E,e[28]=H,e[29]=z,e[30]=P,e[31]=F,e[32]=B):B=e[32];let T;e[33]!==o?(T=s.jsx("span",{children:o}),e[33]=o,e[34]=T):T=e[34];let j;e[35]!==l?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:l}),e[35]=l,e[36]=j):j=e[36];let I;e[37]!==d?(I=d?s.jsx("span",{className:"typography-micro text-muted-foreground",children:d}):null,e[37]=d,e[38]=I):I=e[38];let _;e[39]!==T||e[40]!==j||e[41]!==I?(_=s.jsx(bt,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[T,j,I]})}),e[39]=T,e[40]=j,e[41]=I,e[42]=_):_=e[42];let K;e[43]!==B||e[44]!==_?(K=s.jsxs(gt,{delayDuration:sm,children:[B,_]}),e[43]=B,e[44]=_,e[45]=K):K=e[45];let G;return e[46]!==x||e[47]!==K||e[48]!==k||e[49]!==D?(G=s.jsx("div",{ref:x,style:k,className:D,children:K}),e[46]=x,e[47]=K,e[48]=k,e[49]=D,e[50]=G):G=e[50],G},Zw=()=>{const t=Xe.c(86),{t:e}=pt(),n=qr();let r;t[0]!==n?(r=n?nr(n):"",t[0]=n,t[1]=r):r=t[1];const i=r;let o;t[2]!==i?(o=me=>i?me.contextPanelByDirectory[i]:void 0,t[2]=i,t[3]=o):o=t[3];const l=De(o),a=De(eS),u=De(tS),d=De(sS),h=De(nS),f=De(rS),g=De(oS),p=De(iS),w=xa(aS),v=Ni(lS),x=Ni(cS),m=Cn(dS),b=Cn(uS),{screenWidth:y}=_n(),S=ba(i||null);let N;t[4]!==p?(N=Ai("switch_context_surface",p),t[4]=p,t[5]=N):N=t[5];const C=N,[k,A]=c.useState(!1);let D,P;t[6]!==C?(D=()=>{const me=new Set;let je=null,ne=!1;const fe=mS,ce=()=>{tl(C,me)?!ne&&je===null&&(je=setTimeout(()=>A(!0),Qw)):(ne=!1,je!==null&&(clearTimeout(je),je=null),A(!1))},R=ie=>{if(me.add(ie.key.toLowerCase()),fe(ie.key)&&tl(C,me)){ne=!0,je!==null&&(clearTimeout(je),je=null),A(!1);return}ce()},$=ie=>{me.delete(ie.key.toLowerCase()),ce()},de=()=>{me.clear(),ne=!1,je!==null&&(clearTimeout(je),je=null),A(!1)};return window.addEventListener("keydown",R,!0),window.addEventListener("keyup",$,!0),window.addEventListener("blur",de),()=>{window.removeEventListener("keydown",R,!0),window.removeEventListener("keyup",$,!0),window.removeEventListener("blur",de),je!==null&&clearTimeout(je)}},P=[C],t[6]=C,t[7]=D,t[8]=P):(D=t[7],P=t[8]),c.useEffect(D,P);let F;t[9]===Symbol.for("react.memo_cache_sentinel")?(F={activationConstraint:{distance:8}},t[9]=F):F=t[9];let W;t[10]===Symbol.for("react.memo_cache_sentinel")?(W={activationConstraint:{delay:200,tolerance:6}},t[10]=W):W=t[10];const E=Lr(En(nu,F),En(su,W)),H=l?.tabs??Yw;let z;t[11]!==l?.activeTabId||t[12]!==H?(z=H.find(me=>me.id===l?.activeTabId)??null,t[11]=l?.activeTabId,t[12]=H,t[13]=z):z=t[13];const B=z,T=l?.isOpen?B?.mode??null:null,j=S?.files.length??0;let I;t[14]!==d||t[15]!==u||t[16]!==b||t[17]!==x||t[18]!==w||t[19]!==y||t[20]!==H?(I=Vf({railOrder:u,hiddenSurfaces:d,planModeEnabled:w,isVSCode:Nn(),screenWidth:y,tabs:H,linearConnected:x,githubConnected:b}),t[14]=d,t[15]=u,t[16]=b,t[17]=x,t[18]=w,t[19]=y,t[20]=H,t[21]=I):I=t[21];const _=I;let K,G;t[22]!==T||t[23]!==g||t[24]!==i||t[25]!==v||t[26]!==x?(G=()=>{!i||!v||x||T!=="linear"||g(i)},K=[T,g,i,v,x],t[22]=T,t[23]=g,t[24]=i,t[25]=v,t[26]=x,t[27]=K,t[28]=G):(K=t[27],G=t[28]),c.useEffect(G,K);let Q,ge;t[29]!==T||t[30]!==g||t[31]!==i||t[32]!==m||t[33]!==b?(Q=()=>{!i||!m||b||T!=="pr"||g(i)},ge=[T,g,i,m,b],t[29]=T,t[30]=g,t[31]=i,t[32]=m,t[33]=b,t[34]=Q,t[35]=ge):(Q=t[34],ge=t[35]),c.useEffect(Q,ge);const[se,Y]=c.useState(!1);let te;t[36]!==h?(te=me=>{const{active:je,over:ne}=me;if(!ne||je.id===ne.id)return;const fe=Nd(De.getState().contextRailOrder).map(fS),ce=fe.indexOf(je.id),R=fe.indexOf(ne.id);ce===-1||R===-1||h(ru(fe,ce,R))},t[36]=h,t[37]=te):te=t[37];const he=te;if(!i)return null;let L;t[38]!==e?(L=e("contextRail.aria.rail"),t[38]=e,t[39]=L):L=t[39];let le;t[40]!==_?(le=_.map(hS),t[40]=_,t[41]=le):le=t[41];let Z;if(t[42]!==T||t[43]!==j||t[44]!==i||t[45]!==f||t[46]!==k||t[47]!==_||t[48]!==e||t[49]!==a){let me;t[51]!==T||t[52]!==j||t[53]!==i||t[54]!==f||t[55]!==k||t[56]!==e||t[57]!==a?(me=(je,ne)=>{const fe=e(je.labelKey),ce=je.id==="git"&&!a?j:0,R=ce>0?ce:null;return s.jsx(Jw,{surface:je,isActive:T===je.mode,showActivityDot:!1,label:fe,description:e(je.descriptionKey),badgeCount:R,badgeAriaLabel:R!==null?e(R===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:fe,count:R}):null,badgeDescription:R!==null?e(R===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:R}):null,orderNumber:ne+1,showOrderNumber:k,onSelect:$=>f(i,$.mode)},je.id)},t[51]=T,t[52]=j,t[53]=i,t[54]=f,t[55]=k,t[56]=e,t[57]=a,t[58]=me):me=t[58],Z=_.map(me),t[42]=T,t[43]=j,t[44]=i,t[45]=f,t[46]=k,t[47]=_,t[48]=e,t[49]=a,t[50]=Z}else Z=t[50];let ue;t[59]!==le||t[60]!==Z?(ue=s.jsx(Eo,{items:le,strategy:_i,children:Z}),t[59]=le,t[60]=Z,t[61]=ue):ue=t[61];let V;t[62]!==he||t[63]!==E||t[64]!==ue?(V=s.jsx($r,{sensors:E,collisionDetection:Wr,onDragEnd:he,children:ue}),t[62]=he,t[63]=E,t[64]=ue,t[65]=V):V=t[65];let ee;t[66]!==e?(ee=e("contextRail.configure.open"),t[66]=e,t[67]=ee):ee=t[67];let be;t[68]===Symbol.for("react.memo_cache_sentinel")?(be=()=>Y(!0),t[68]=be):be=t[68];let xe;t[69]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(M,{name:"equalizer-2",className:"h-[18px] w-[18px]"}),t[69]=xe):xe=t[69];let Ne;t[70]!==ee?(Ne=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":ee,onClick:be,className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground",children:xe})}),t[70]=ee,t[71]=Ne):Ne=t[71];let Pe;t[72]!==e?(Pe=e("contextRail.configure.open"),t[72]=e,t[73]=Pe):Pe=t[73];let Se;t[74]!==Pe?(Se=s.jsx(bt,{side:"left",sideOffset:8,children:Pe}),t[74]=Pe,t[75]=Se):Se=t[75];let Re;t[76]!==Ne||t[77]!==Se?(Re=s.jsxs(gt,{delayDuration:sm,children:[Ne,Se]}),t[76]=Ne,t[77]=Se,t[78]=Re):Re=t[78];let ye;t[79]!==se?(ye=s.jsx(Uw,{open:se,onOpenChange:Y}),t[79]=se,t[80]=ye):ye=t[80];let pe;return t[81]!==L||t[82]!==V||t[83]!==Re||t[84]!==ye?(pe=s.jsxs("nav",{"aria-label":L,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:[V,Re,ye]}),t[81]=L,t[82]=V,t[83]=Re,t[84]=ye,t[85]=pe):pe=t[85],pe};function eS(t){return t.workStatusPanelVisible}function tS(t){return t.contextRailOrder}function sS(t){return t.contextRailHiddenSurfaces}function nS(t){return t.setContextRailOrder}function rS(t){return t.openContextSurface}function oS(t){return t.closeContextPanel}function iS(t){return t.shortcutOverrides}function aS(t){return t.planModeEnabled}function lS(t){return t.hasChecked}function cS(t){return t.status?.connected===!0}function dS(t){return t.hasChecked}function uS(t){return t.status?.connected===!0}function mS(t){return t.length===1&&t>="0"&&t<="9"}function fS(t){return t.id}function hS(t){return t.id}const pS=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),gS=(t,e,n,r)=>!n||r!==n||t.length===0?[]:Pr(t,e,i=>i.relativePath||i.name,{limit:10,threshold:.4}),xS=new Set,bS=[],ea=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",o=/^[A-Za-z]:\/$/.test(r);return!i&&!o&&(r=r.replace(/\/+$/,"")),r},yS=()=>{const t=Xe.c(182),{t:e}=pt(),n=De(wS),r=De(SS),i=De(vS),o=De(jS),l=De(kS),a=De(CS),u=De(NS),d=De(AS),h=De(DS),f=De(PS),g=De(IS),p=De(TS),w=De(RS),v=Qe(ES),x=Qe(MS),m=Qe(OS),b=Br(FS);let y;t[0]!==n?(y=Ye=>n?Ye.activeSessions:bS,t[0]=n,t[1]=y):y=t[1];const S=As(y);let N;t[2]!==n?(N=Ye=>n?Ye.ids:xS,t[2]=n,t[3]=N):N=t[3];const C=Br(N);let k;t[4]!==n?(k=Ye=>n?Ye.rankById:Dd,t[4]=n,t[5]=k):k=t[5];const A=va(k),D=Zt(BS),P=Vt(_S),F=Vt(LS),W=qr(),E=id($S),{files:H,git:z}=An(),B=On(WS),{isMobile:T}=_n();let j;t[6]!==W?(j=W?ea(W):null,t[6]=W,t[7]=j):j=t[7];const I=j,[_,K]=c.useState(""),Q=Sa(_,200).trim();let ge;t[8]!==_?(ge=_.trim(),t[8]=_,t[9]=ge):ge=t[9];const se=ge;let Y,te;t[10]!==n?(Y=()=>{n&&K("")},te=[n],t[10]=n,t[11]=Y,t[12]=te):(Y=t[11],te=t[12]),c.useEffect(Y,te);let he,L;t[13]!==S||t[14]!==B||t[15]!==z||t[16]!==n?(he=()=>{if(!n||!z)return;const Ye=setTimeout(()=>{const rt=new Set;for(const It of S){const Ct=_s(It);!Ct||rt.has(Ct)||(rt.add(Ct),B(Ct,z))}},0);return()=>clearTimeout(Ye)},L=[n,S,z,B],t[13]=S,t[14]=B,t[15]=z,t[16]=n,t[17]=he,t[18]=L):(he=t[17],L=t[18]),c.useEffect(he,L);let le;t[19]!==r?(le=()=>r(!1),t[19]=r,t[20]=le):le=t[20];const Z=le;let ue;t[21]!==Z?(ue=Ye=>()=>{Z(),Ye()},t[21]=Z,t[22]=ue):ue=t[22];const V=ue;let ee;t[23]!==P?.id||t[24]!==P?.path||t[25]!==D||t[26]!==m||t[27]!==T||t[28]!==u||t[29]!==d||t[30]!==g||t[31]!==v||t[32]!==V||t[33]!==p||t[34]!==w||t[35]!==l||t[36]!==i||t[37]!==e||t[38]!==b||t[39]!==a?(ee=()=>{const Ye=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(M,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:V(()=>{l(!1),v()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(M,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:V(zS)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(M,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:V(VS)},{id:"toggle-sidebar",title:e(T?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(M,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(T?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:V(()=>{if(T){const{isSessionSwitcherOpen:rt}=De.getState();l(!rt)}else a()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(M,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:V(()=>{D&&d(D,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(M,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:V(()=>{D&&u(D)})},{id:"cycle-theme",secondary:!0,title:e("commandPalette.item.cycleTheme"),icon:s.jsx(M,{name:"palette",className:"mr-2 h-4 w-4"}),shortcutId:"cycle_theme",searchText:e("commandPalette.item.cycleTheme"),onSelect:V(US)},{id:"open-status",secondary:!0,title:e("commandPalette.item.showOpenCodeStatus"),icon:s.jsx(M,{name:"pulse",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showOpenCodeStatus"),onSelect:V(KS)},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(M,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:V(()=>i(!0))}];return Ye.push({id:"pin-session",secondary:!0,title:e("commandPalette.item.pinSession"),icon:s.jsx(M,{name:"pushpin",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.pinSession"),onSelect:V(()=>{m&&D&&b({directory:D,sessionId:m})})},{id:"copy-session-id",secondary:!0,title:e("commandPalette.item.copySessionId"),icon:s.jsx(M,{name:"file-copy",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.copySessionId"),onSelect:V(()=>{m&&fn(m).then(rt=>{if(rt.ok){Fe.success(e("sessions.sidebar.session.copyId.success"));return}Fe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(e("sessions.sidebar.session.copyId.error")))})},{id:"open-multi-run",secondary:!0,title:e("commandPalette.item.openMultiRun"),icon:s.jsx(M,{name:"checkbox-multiple",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openMultiRun"),onSelect:V(()=>{l(!1),g()})},{id:"open-archive",secondary:!0,title:e("commandPalette.item.openArchive"),icon:s.jsx(M,{name:"archive",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openArchive"),onSelect:V(()=>{l(!1),p(!0)})},{id:"open-notes",secondary:!0,title:e("commandPalette.item.openNotes"),icon:s.jsx(M,{name:"sticky-note",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openNotes"),onSelect:V(()=>{D&&(w("notes"),d(D,"notes"))})},{id:"open-todos",secondary:!0,title:e("commandPalette.item.openTodos"),icon:s.jsx(M,{name:"checkbox-circle",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openTodos"),onSelect:V(()=>{D&&(w("todos"),d(D,"notes"))})}),Ye.push({id:"toggle-memory-debug",secondary:!0,title:e("commandPalette.item.toggleMemoryDebug"),icon:s.jsx(M,{name:"bug",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.toggleMemoryDebug"),onSelect:V(HS)}),Ho()&&Ye.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(M,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:V(()=>{Rn("desktop_open_draft_mini_chat_window",{directory:ea(D||P?.path||""),projectId:P?.id??null}).catch(GS)})}),Ye},t[23]=P?.id,t[24]=P?.path,t[25]=D,t[26]=m,t[27]=T,t[28]=u,t[29]=d,t[30]=g,t[31]=v,t[32]=V,t[33]=p,t[34]=w,t[35]=l,t[36]=i,t[37]=e,t[38]=b,t[39]=a,t[40]=ee):ee=t[40],P?.id,P?.path;let be;t[41]!==ee?(be=ee(),t[41]=ee,t[42]=be):be=t[42];const xe=be;let Ne;t[43]===Symbol.for("react.memo_cache_sentinel")?(Ne=pn(),t[43]=Ne):Ne=t[43];const Pe=Ne;let Se,Re;t[44]===Symbol.for("react.memo_cache_sentinel")?(Se=Nn(),Re=!Pe&&fa(),t[44]=Se,t[45]=Re):(Se=t[44],Re=t[45]);let ye;t[46]!==T?(ye={isVSCode:Se,isWeb:Re,isDesktop:Pe,isMobile:T},t[46]=T,t[47]=ye):ye=t[47];const pe=ye;let me;if(t[48]!==V||t[49]!==i||t[50]!==o||t[51]!==pe){let Ye;t[53]!==pe?(Ye=It=>It.isAvailable?It.isAvailable(pe):!0,t[53]=pe,t[54]=Ye):Ye=t[54];let rt;t[55]!==V||t[56]!==i||t[57]!==o?(rt=It=>{const Ct=Up(It.slug)??"settings-3",Pt=(It.keywords??[]).join(" ");return{id:`settings:${It.slug}`,title:It.title,icon:It.slug==="mcp"?s.jsx(qf,{className:"mr-2 h-4 w-4"}):s.jsx(M,{name:Ct,className:"mr-2 h-4 w-4"}),searchText:`${It.title} ${It.group} ${Pt}`,onSelect:V(()=>{o(It.slug),i(!0)})}},t[55]=V,t[56]=i,t[57]=o,t[58]=rt):rt=t[58],me=Vp.filter(qS).filter(Ye).map(rt),t[48]=V,t[49]=i,t[50]=o,t[51]=pe,t[52]=me}else me=t[52];const je=me;let ne;if(t[59]!==S||t[60]!==C||t[61]!==A){const Ye=S.filter(QS);ne=Uf(Ye,C,A),t[59]=S,t[60]=C,t[61]=A,t[62]=ne}else ne=t[62];const fe=ne,ce=Ad(),R=Qe(YS);let $;t[63]!==ce||t[64]!==R?($=(Ye,rt)=>{const It=R.get(Ye);return It?.branch?It.branch.trim()||null:rt&&ce.get(rt)?.trim()||null},t[63]=ce,t[64]=R,t[65]=$):$=t[65];const de=$;let ie;t[66]===Symbol.for("react.memo_cache_sentinel")?(ie=[],t[66]=ie):ie=t[66];const[Ae,Be]=c.useState(ie),[Ce,q]=c.useState(""),Ee=pS(I,Q);let Me;t[67]!==I||t[68]!==Ee||t[69]!==n||t[70]!==E||t[71]!==Be||t[72]!==q||t[73]!==Q?(Me=()=>{if(!n){Be([]),q("");return}if(!Ee){Be([]),q("");return}if(!I){Be([]),q("");return}let Ye=!1;return E(I,Q,40,{type:"file"}).then(rt=>{Ye||(Be(rt.map(XS)),q(Ee))}).catch(()=>{Ye||(Be([]),q(Ee))}),()=>{Ye=!0}},t[67]=I,t[68]=Ee,t[69]=n,t[70]=E,t[71]=Be,t[72]=q,t[73]=Q,t[74]=Me):Me=t[74];let O;t[75]!==I||t[76]!==Ee||t[77]!==n||t[78]!==E||t[79]!==Q?(O=[n,I,Q,Ee,E],t[75]=I,t[76]=Ee,t[77]=n,t[78]=E,t[79]=Q,t[80]=O):O=t[80],c.useEffect(Me,O);const oe=se.length>0;let re;e:{if(!oe){let rt;t[81]!==xe?(rt=xe.filter(JS).map(ZS),t[81]=xe,t[82]=rt):rt=t[82],re=rt;break e}let Ye;t[83]!==xe||t[84]!==se?(Ye=Pr(xe,se,ev,{limit:7,noFuzzy:!0}),t[83]=xe,t[84]=se,t[85]=Ye):Ye=t[85],re=Ye}const we=re;let Ve;e:{if(!oe){let rt;t[86]===Symbol.for("react.memo_cache_sentinel")?(rt=[],t[86]=rt):rt=t[86],Ve=rt;break e}let Ye;t[87]!==se||t[88]!==je?(Ye=Pr(je,se,tv,{limit:7,noFuzzy:!0}),t[87]=se,t[88]=je,t[89]=Ye):Ye=t[89],Ve=Ye}const st=Ve;let Ge;e:{if(!oe){let rt;t[90]!==fe?(rt=fe.slice(0,5).map(sv),t[90]=fe,t[91]=rt):rt=t[91],Ge=rt;break e}let Ye;t[92]!==se||t[93]!==fe?(Ye=Pr(fe,se,nv,{limit:7,threshold:.2}),t[92]=se,t[93]=fe,t[94]=Ye):Ye=t[94],Ge=Ye}const ae=Ge;let X;e:{if(!n){let rt;t[95]===Symbol.for("react.memo_cache_sentinel")?(rt=[],t[95]=rt):rt=t[95],X=rt;break e}let Ye;t[96]!==Ae||t[97]!==Ce||t[98]!==Ee||t[99]!==Q?(Ye=gS(Ae,Q,Ee,Ce),t[96]=Ae,t[97]=Ce,t[98]=Ee,t[99]=Q,t[100]=Ye):Ye=t[100],X=Ye}const ve=X,Le=n&&Ee.length>0&&Ce!==Ee;let $e;e:{if(!oe){let rt;t[101]===Symbol.for("react.memo_cache_sentinel")?(rt=[],t[101]=rt):rt=t[101],$e=rt;break e}let Ye;if(t[102]!==se||t[103]!==F){const rt=F.map(rv);Ye=Pr(rt,se,ov,{limit:7,threshold:.4}),t[102]=se,t[103]=F,t[104]=Ye}else Ye=t[104];$e=Ye}const Ue=$e;let We,qe,nt,yt,vt,He,Mt,jt,kt,Tt,wt,Nt,Dt,ft;if(t[105]!==de||t[106]!==Z||t[107]!==I||t[108]!==H||t[109]!==oe||t[110]!==n||t[111]!==h||t[112]!==v||t[113]!==_||t[114]!==we||t[115]!==ve||t[116]!==Ue||t[117]!==ae||t[118]!==st||t[119]!==r||t[120]!==x||t[121]!==f||t[122]!==e){const Ye=we.map(iv),rt=st.map(av),It=ae.map(lv),Ct=oe?ve.map(cv):[],Pt=oe?Ue.map(dv):[];let Wt;e:{if(!oe){Wt=["commands","sessions"];break e}const St=uv,ot=[{key:"commands",score:St(we)},{key:"settings",score:St(st)},{key:"sessions",score:St(ae)},{key:"files",score:St(ve)},{key:"projects",score:St(Ue)}];ot.sort(mv),Wt=ot.map(fv)}const Yt=Wt,Kt=St=>{Z(),x(St.id,_s(St))},Bt=async St=>{if(!I)return;const ot=await Ru(H,St,{directory:I});if(!ot.ok){Fe.error(Eu(ot.reason));return}h(I,St),Z()},ts=(St,ot)=>{Z(),v({selectedProjectId:St,directoryOverride:ot})},zt=St=>Qn(Gr(St,f));yt=vs,Nt=n,Dt=r;let _t;t[137]!==e?(_t=e("commandPalette.title"),t[137]=e,t[138]=_t):_t=t[138];let Oe;t[139]!==_t?(Oe=s.jsx(Ds,{children:_t}),t[139]=_t,t[140]=Oe):Oe=t[140];let Ke;t[141]!==e?(Ke=e("commandPalette.description"),t[141]=e,t[142]=Ke):Ke=t[142];let et;t[143]!==Ke?(et=s.jsx(Ps,{children:Ke}),t[143]=Ke,t[144]=et):et=t[144],t[145]!==Oe||t[146]!==et?(ft=s.jsxs(Ls,{className:"sr-only",children:[Oe,et]}),t[145]=Oe,t[146]=et,t[147]=ft):ft=t[147],nt=js,Tt="overflow-hidden p-0",wt=!0,qe=Qf,Mt=!1,jt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let dt;t[148]!==e?(dt=e("commandPalette.input.placeholder"),t[148]=e,t[149]=dt):dt=t[149],t[150]!==_||t[151]!==dt?(kt=s.jsx(Yf,{value:_,onValueChange:K,placeholder:dt}),t[150]=_,t[151]=dt,t[152]=kt):kt=t[152],We=Xf;let ut;t[153]!==e?(ut=e("commandPalette.empty.noResults"),t[153]=e,t[154]=ut):ut=t[154],t[155]!==ut?(vt=s.jsx(Jf,{children:ut}),t[155]=ut,t[156]=vt):vt=t[156],He=Yt.map(St=>St==="commands"&&Ye.length>0?s.jsx(wr,{children:Ye.map(ot=>s.jsxs(Ir,{value:ot.id,onSelect:ot.onSelect,children:[ot.icon,s.jsx("span",{children:ot.title}),ot.shortcutId?s.jsx(Kf,{children:zt(ot.shortcutId)}):null]},ot.id))},"commands"):St==="settings"&&rt.length>0?s.jsx(wr,{children:rt.map(hv)},"settings"):St==="sessions"&&It.length>0?s.jsx(wr,{children:It.map(ot=>{const Lt=ot.title||e("commandPalette.session.untitled"),Qt=_s(ot),us=de(ot.id,Qt);return s.jsxs(Ir,{value:`session:${ot.id}`,onSelect:()=>Kt(ot),children:[s.jsx(M,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Lt}),us?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(M,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:us})]}):null]},ot.id)})},"sessions"):St==="files"&&Ct.length>0?s.jsx(wr,{children:Ct.map(ot=>{const Lt=Hf(ot.relativePath||ot.name,{maxLength:80});return s.jsxs(Ir,{value:`file:${ot.path}`,onSelect:()=>{Bt(ot.path)},children:[s.jsx(wa,{filePath:ot.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":ot.relativePath,children:Lt})]},`file:${ot.path}`)})},"files"):St==="projects"&&Pt.length>0?s.jsx(wr,{children:Pt.map(ot=>{const Lt=ot.displayName;return s.jsxs(Ir,{value:`project:${ot.id}`,onSelect:()=>ts(ot.id,ot.path),children:[s.jsx(M,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Lt}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:ot.path})]},`project:${ot.id}`)})},"projects"):null),t[105]=de,t[106]=Z,t[107]=I,t[108]=H,t[109]=oe,t[110]=n,t[111]=h,t[112]=v,t[113]=_,t[114]=we,t[115]=ve,t[116]=Ue,t[117]=ae,t[118]=st,t[119]=r,t[120]=x,t[121]=f,t[122]=e,t[123]=We,t[124]=qe,t[125]=nt,t[126]=yt,t[127]=vt,t[128]=He,t[129]=Mt,t[130]=jt,t[131]=kt,t[132]=Tt,t[133]=wt,t[134]=Nt,t[135]=Dt,t[136]=ft}else We=t[123],qe=t[124],nt=t[125],yt=t[126],vt=t[127],He=t[128],Mt=t[129],jt=t[130],kt=t[131],Tt=t[132],wt=t[133],Nt=t[134],Dt=t[135],ft=t[136];let Ze;t[157]!==Le||t[158]!==e?(Ze=Le?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[157]=Le,t[158]=e,t[159]=Ze):Ze=t[159];let ke;t[160]!==We||t[161]!==vt||t[162]!==He||t[163]!==Ze?(ke=s.jsxs(We,{children:[vt,He,Ze]}),t[160]=We,t[161]=vt,t[162]=He,t[163]=Ze,t[164]=ke):ke=t[164];let tt;t[165]!==qe||t[166]!==Mt||t[167]!==jt||t[168]!==kt||t[169]!==ke?(tt=s.jsxs(qe,{shouldFilter:Mt,className:jt,children:[kt,ke]}),t[165]=qe,t[166]=Mt,t[167]=jt,t[168]=kt,t[169]=ke,t[170]=tt):tt=t[170];let lt;t[171]!==nt||t[172]!==Tt||t[173]!==wt||t[174]!==tt?(lt=s.jsx(nt,{className:Tt,showCloseButton:wt,children:tt}),t[171]=nt,t[172]=Tt,t[173]=wt,t[174]=tt,t[175]=lt):lt=t[175];let At;return t[176]!==yt||t[177]!==Nt||t[178]!==Dt||t[179]!==ft||t[180]!==lt?(At=s.jsxs(yt,{open:Nt,onOpenChange:Dt,children:[ft,lt]}),t[176]=yt,t[177]=Nt,t[178]=Dt,t[179]=ft,t[180]=lt,t[181]=At):At=t[181],At};function wS(t){return t.isCommandPaletteOpen}function SS(t){return t.setCommandPaletteOpen}function vS(t){return t.setSettingsDialogOpen}function jS(t){return t.setSettingsPage}function kS(t){return t.setSessionSwitcherOpen}function CS(t){return t.toggleSidebar}function NS(t){return t.openContextOverview}function AS(t){return t.openContextSurface}function DS(t){return t.openContextFile}function PS(t){return t.shortcutOverrides}function IS(t){return t.openMultiRunLauncher}function TS(t){return t.setArchivePageOpen}function RS(t){return t.setProjectContextTab}function ES(t){return t.openNewSessionDraft}function MS(t){return t.setCurrentSession}function OS(t){return t.currentSessionId}function FS(t){return t.toggle}function BS(t){return t.currentDirectory}function _S(t){return t.getActiveProject()}function LS(t){return t.projects}function $S(t){return t.searchFiles}function WS(t){return t.ensureStatus}function zS(){Pd()}function VS(){hn.requestDirectoryDialog()}function US(){Zf.invoke("cycle_theme")}function KS(){Id()}function HS(){window.dispatchEvent(new CustomEvent("aiworker:memory-debug-toggle"))}function GS(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function qS(t){return t.slug!=="home"}function QS(t){return!Gf(t)}function YS(t){return t.worktreeMetadata}function XS(t){return{path:ea(t.path),name:t.name,relativePath:t.relativePath}}function JS(t){return!t.secondary}function ZS(t){return{item:t,score:0}}function ev(t){return t.searchText}function tv(t){return t.searchText}function sv(t){return{item:t,score:0}}function nv(t){return t.title||""}function rv(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function ov(t){return t.searchText}function iv(t){return t.item}function av(t){return t.item}function lv(t){return t.item}function cv(t){return t.item}function dv(t){return t.item}function uv(t){return t.length?t[0].score:1/0}function mv(t,e){return t.score-e.score}function fv(t){return t.key}function hv(t){return s.jsxs(Ir,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const ic=(t,e,n)=>Qn(Gr(t,e),n),pv=()=>{const t=Xe.c(68),{t:e}=pt(),n=De(gv),r=De(xv),i=De(bv);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=Nn(),t[0]=o):o=t[0];const l=o;let a,u,d,h,f,g,p,w,v;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const z=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[Qn("mod+shift+alt+n")],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"open_draft_project_picker",icon:"folder",keys:""},{id:"open_draft_worktree_picker",icon:"git-branch",keys:""},{id:"open_session_list",icon:"list-unordered",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{keys:[`${Qn(Ai("switch_context_surface",i))} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"},{keys:[`${Qn(Ai("switch_session_tab",i))} + 1...9`],descriptionKey:"helpDialog.item.switchSessionTab",icon:"layout-right"}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];u=vs,w=n,v=r,a=js,g="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let B;t[14]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(M,{name:"command",className:"h-5 w-5"}),t[14]=B):B=t[14];let T;t[15]!==e?(T=e("helpDialog.title"),t[15]=e,t[16]=T):T=t[16];let j;t[17]!==T?(j=s.jsxs(Ds,{className:"flex items-center gap-2",children:[B,T]}),t[17]=T,t[18]=j):j=t[18];let I;t[19]!==e?(I=e("helpDialog.description"),t[19]=e,t[20]=I):I=t[20];let _;t[21]!==I?(_=s.jsx(Ps,{children:I}),t[21]=I,t[22]=_):_=t[22],t[23]!==j||t[24]!==_?(p=s.jsxs(Ls,{children:[j,_]}),t[23]=j,t[24]=_,t[25]=p):p=t[25],f="flex-1 overflow-y-auto mt-3 pr-1",d="space-y-4",h=z.map(K=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(K.categoryKey)}),s.jsx("div",{className:"space-y-1",children:K.items.filter(G=>!(l&&G.id==="toggle_prompt_navigator")).map(G=>{const Q=G.id?eh(G.id):void 0,ge=G.descriptionKey??(Q?.customizable?Q.settingsLabelKey:void 0);if(!ge||G.id&&!Gr(G.id,i))return null;const se=G.id?ic(G.id,i,e("settings.aiworker.keyboardShortcuts.unassigned")):Array.isArray(G.keys)?G.keys:G.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[G.icon&&s.jsx(M,{name:G.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(ge)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(se)?se:[se]).map((Y,te)=>s.jsxs(c.Fragment,{children:[te>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:Y})]},`${Y}-${te}`))})]},G.id||ge)})})]},K.categoryKey)),t[1]=n,t[2]=r,t[3]=i,t[4]=e,t[5]=a,t[6]=u,t[7]=d,t[8]=h,t[9]=f,t[10]=g,t[11]=p,t[12]=w,t[13]=v}else a=t[5],u=t[6],d=t[7],h=t[8],f=t[9],g=t[10],p=t[11],w=t[12],v=t[13];let x;t[26]!==d||t[27]!==h?(x=s.jsx("div",{className:d,children:h}),t[26]=d,t[27]=h,t[28]=x):x=t[28];let m;t[29]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(M,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=m):m=t[29];let b;t[30]!==e?(b=e("helpDialog.proTips.title"),t[30]=e,t[31]=b):b=t[31];let y;t[32]!==b?(y=s.jsx("p",{className:"font-medium mb-1",children:b}),t[32]=b,t[33]=y):y=t[33];let S;t[34]!==i||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:ic("open_command_palette",i,e("settings.aiworker.keyboardShortcuts.unassigned"))}),t[34]=i,t[35]=e,t[36]=S):S=t[36];let N;t[37]!==S?(N=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=N):N=t[38];let C;t[39]!==e?(C=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=C):C=t[40];let k;t[41]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[41]=C,t[42]=k):k=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.leaderSequences"),t[43]=e,t[44]=A):A=t[44];let D;t[45]!==A?(D=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=D):D=t[46];let P;t[47]!==N||t[48]!==k||t[49]!==D?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[N,k,D]}),t[47]=N,t[48]=k,t[49]=D,t[50]=P):P=t[50];let F;t[51]!==y||t[52]!==P?(F=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[m,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,P]})]})}),t[51]=y,t[52]=P,t[53]=F):F=t[53];let W;t[54]!==F||t[55]!==f||t[56]!==x?(W=s.jsxs("div",{className:f,children:[x,F]}),t[54]=F,t[55]=f,t[56]=x,t[57]=W):W=t[57];let E;t[58]!==a||t[59]!==W||t[60]!==g||t[61]!==p?(E=s.jsxs(a,{className:g,children:[p,W]}),t[58]=a,t[59]=W,t[60]=g,t[61]=p,t[62]=E):E=t[62];let H;return t[63]!==u||t[64]!==E||t[65]!==w||t[66]!==v?(H=s.jsx(u,{open:w,onOpenChange:v,children:E}),t[63]=u,t[64]=E,t[65]=w,t[66]=v,t[67]=H):H=t[67],H};function gv(t){return t.isHelpDialogOpen}function xv(t){return t.setHelpDialogOpen}function bv(t){return t.shortcutOverrides}const yv=()=>{const t=Xe.c(32),{t:e}=pt(),n=De(wv),r=De(Sv),i=De(vv);let o;t[0]!==i||t[1]!==e?(o=async()=>{if(!i)return;if((await fn(i)).ok){Fe.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Fe.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=i,t[1]=e,t[2]=o):o=t[2];const l=o;let a;t[3]!==e?(a=e("openCodeStatusDialog.title"),t[3]=e,t[4]=a):a=t[4];let u;t[5]!==a?(u=s.jsx(Ds,{children:a}),t[5]=a,t[6]=u):u=t[6];let d;t[7]!==e?(d=e("openCodeStatusDialog.description"),t[7]=e,t[8]=d):d=t[8];let h;t[9]!==d?(h=s.jsx(Ps,{children:d}),t[9]=d,t[10]=h):h=t[10];let f;t[11]!==u||t[12]!==h?(f=s.jsxs(Ls,{children:[u,h]}),t[11]=u,t[12]=h,t[13]=f):f=t[13];let g;t[14]!==e?(g=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=g):g=t[15];let p;t[16]!==l||t[17]!==g?(p=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:g})}),t[16]=l,t[17]=g,t[18]=p):p=t[18];let w;t[19]!==i||t[20]!==e?(w=i||e("openCodeStatusDialog.empty.noData"),t[19]=i,t[20]=e,t[21]=w):w=t[21];let v;t[22]!==w?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:w}),t[22]=w,t[23]=v):v=t[23];let x;t[24]!==f||t[25]!==p||t[26]!==v?(x=s.jsxs(js,{className:"max-w-2xl",children:[f,p,v]}),t[24]=f,t[25]=p,t[26]=v,t[27]=x):x=t[27];let m;return t[28]!==n||t[29]!==r||t[30]!==x?(m=s.jsx(vs,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=m):m=t[31],m};function wv(t){return t.isOpenCodeStatusDialogOpen}function Sv(t){return t.setOpenCodeStatusDialogOpen}function vv(t){return t.openCodeStatusText}const jv=t=>{const e=Xe.c(16),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:i,sessionSearchInputRef:o,sessionSearchContainerRef:l}=t,a=n===void 0?!0:n;let u,d;e[0]!==a||e[1]!==r||e[2]!==o?(u=()=>{if(!a||!r||typeof window>"u")return;const w=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(w)},d=[a,r,o],e[0]=a,e[1]=r,e[2]=o,e[3]=u,e[4]=d):(u=e[3],d=e[4]),c.useEffect(u,d);let h,f;e[5]!==a||e[6]!==o||e[7]!==i?(h=()=>{if(!a||typeof window>"u")return;const w=()=>{i(!0),o.current?.focus(),o.current?.select()};return window.addEventListener("aiworker:sidebar-session-search",w),()=>window.removeEventListener("aiworker:sidebar-session-search",w)},f=[a,i,o],e[5]=a,e[6]=o,e[7]=i,e[8]=h,e[9]=f):(h=e[8],f=e[9]),c.useEffect(h,f);let g,p;e[10]!==a||e[11]!==r||e[12]!==l||e[13]!==i?(g=()=>{if(!a||!r||typeof document>"u")return;const w=v=>{l.current&&(l.current.contains(v.target)||i(!1))};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},p=[a,r,i,l],e[10]=a,e[11]=r,e[12]=l,e[13]=i,e[14]=g,e[15]=p):(g=e[14],p=e[15]),c.useEffect(g,p)},kv=t=>{const e=Xe.c(4);let n;e[0]!==t?(n=(o,l)=>{const a=t.get(o);if(!a||a.length===0)return l;const u=new Map(l.map(Cv)),d=[];a.forEach(g=>{const p=u.get(g);p&&(d.push(p),u.delete(g))});const h=[],f=[];return l.forEach(g=>{u.has(g.id)&&(g.isArchivedBucket?f.push(g):h.push(g))}),[...h,...d,...f]},e[0]=t,e[1]=n):n=e[1];const r=n;let i;return e[2]!==r?(i={getOrderedGroups:r},e[2]=r,e[3]=i):i=e[3],i};function Cv(t){return[t.id,t]}const lo="oc.sessions.projectCollapse",ac="oc.sessions.groupOrder",lc="oc.sessions.groupCollapse",cc=t=>{if(!t)return new Set;try{const e=Ta(gr()).safeParse(JSON.parse(t));return new Set(e.success?e.data:[])}catch{return new Set}},Nv=t=>{if(!t)return new Map;try{const e=uu(gr(),Ta(gr())).safeParse(JSON.parse(t));if(!e.success)return new Map;const n=new Map;for(const[r,i]of Object.entries(e.data))n.set(r,i);return n}catch{return new Map}},Av=t=>{const e=Xe.c(39),{isVSCode:n,projects:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Po(),e[0]=i):i=e[0];const o=i;let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=()=>cc(o.getItem(lo)),e[1]=l):l=e[1];const[a,u]=c.useState(l);let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=()=>cc(o.getItem(lc)),e[2]=d):d=e[2];const[h,f]=c.useState(d);let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=()=>Nv(o.getItem(ac)),e[3]=g):g=e[3];const[p,w]=c.useState(g),v=c.useRef(0),x=c.useRef(!1),m=c.useRef(!1),b=c.useRef(null),y=c.useRef(null);let S;e[4]!==n?(S=()=>{if(n)return;const le=y.current;if(y.current=null,b.current=null,!le)return;const{projects:Z}=Vt.getState(),ue=Z.map(V=>({...V,sidebarCollapsed:le.has(V.id)}));Dr({projects:ue}).catch(Dv)},e[4]=n,e[5]=S):S=e[5];const N=S;let C;e[6]!==N||e[7]!==n?(C=le=>{!globalThis.window||n||(y.current=le,b.current!==null&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>{N()},700))},e[6]=N,e[7]=n,e[8]=C):C=e[8];const k=C;let A,D;e[9]===Symbol.for("react.memo_cache_sentinel")?(A=()=>()=>{globalThis.window&&b.current!==null&&window.clearTimeout(b.current),b.current=null,y.current=null},D=[],e[9]=A,e[10]=D):(A=e[9],D=e[10]),c.useEffect(A,D);let P,F;e[11]!==p?(F=()=>{if(m.current)try{o.setItem(ac,JSON.stringify(Object.fromEntries(p.entries())))}catch{}},P=[p,o],e[11]=p,e[12]=P,e[13]=F):(P=e[12],F=e[13]),c.useEffect(F,P);let W,E;e[14]!==h?(W=()=>{if(x.current)try{o.setItem(lc,JSON.stringify(Array.from(h)))}catch{}},E=[h,o],e[14]=h,e[15]=W,e[16]=E):(W=e[15],E=e[16]),c.useEffect(W,E);let H;e[17]!==r||e[18]!==k?(H=()=>{v.current=Date.now()+150,x.current=!0,f(new Set),u(()=>{const le=new Set(r.map(Pv));try{o.setItem(lo,JSON.stringify(Array.from(le)))}catch{}return k(le),le})},e[17]=r,e[18]=k,e[19]=H):H=e[19];const z=H;let B;e[20]!==k?(B=()=>{v.current=Date.now()+150,x.current=!0,f(new Set),u(()=>{const le=new Set;try{o.setItem(lo,JSON.stringify([]))}catch{}return k(le),le})},e[20]=k,e[21]=B):B=e[21];const T=B;let j;e[22]!==k?(j=le=>{v.current=Date.now()+150,u(Z=>{const ue=new Set(Z);ue.has(le)?ue.delete(le):ue.add(le);try{o.setItem(lo,JSON.stringify(Array.from(ue)))}catch{}return k(ue),ue})},e[22]=k,e[23]=j):j=e[23];const I=j;let _;e[24]===Symbol.for("react.memo_cache_sentinel")?(_=le=>{x.current=!0,f(Z=>{const ue=new Set(Z);return ue.has(le)?ue.delete(le):ue.add(le),ue})},e[24]=_):_=e[24];const K=_;let G;e[25]===Symbol.for("react.memo_cache_sentinel")?(G=le=>{m.current=!0,w(le)},e[25]=G):G=e[25];const Q=G,{getOrderedGroups:ge}=kv(p);let se;e[26]!==h||e[27]!==a||e[28]!==p?(se={collapsedProjects:a,collapsedGroups:h,groupOrderByProject:p},e[26]=h,e[27]=a,e[28]=p,e[29]=se):se=e[29];const Y=se;let te;e[30]!==z||e[31]!==T||e[32]!==ge||e[33]!==k||e[34]!==I?(te={setCollapsedProjects:u,toggleProject:I,collapseAllProjects:z,expandAllProjects:T,scheduleCollapsedProjectsPersist:k,setCollapsedGroups:f,toggleGroup:K,setGroupOrderByProject:Q,getOrderedGroups:ge},e[30]=z,e[31]=T,e[32]=ge,e[33]=k,e[34]=I,e[35]=te):te=e[35];const he=te;let L;return e[36]!==he||e[37]!==Y?(L={state:Y,actions:he},e[36]=he,e[37]=Y,e[38]=L):L=e[38],L};function Dv(){}function Pv(t){return t.id}const Iv=5*6e4,Tv=t=>{const e=Xe.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:i,setProjectRepoStatus:o,setProjectRootBranches:l}=t,a=r===void 0?!0:r,{git:u}=An(),d=On(Rv);let h,f;e[0]!==a||e[1]!==d||e[2]!==u||e[3]!==n||e[4]!==o?(h=()=>{if(!a||!u||n.length===0){o(new Map);return}n.forEach(C=>{Di(()=>d(C.normalizedPath,u))})},f=[a,n,u,d,o],e[0]=a,e[1]=d,e[2]=u,e[3]=n,e[4]=o,e[5]=h,e[6]=f):(h=e[5],f=e[6]),c.useEffect(h,f);let g,p;e[7]!==a||e[8]!==i||e[9]!==n||e[10]!==o?(g=()=>{if(!a)return;const C=new Map;n.forEach(k=>{C.set(k.id,i.get(k.normalizedPath)?.isGitRepo??null)}),o(C)},p=[a,n,i,o],e[7]=a,e[8]=i,e[9]=n,e[10]=o,e[11]=g,e[12]=p):(g=e[11],p=e[12]),c.useEffect(g,p);let w;if(e[13]!==i||e[14]!==n){let C;e[16]!==i?(C=k=>{const A=i.get(k.normalizedPath)?.branch??"";return`${k.id}:${A}`},e[16]=i,e[17]=C):C=e[17],w=n.map(C).join("|"),e[13]=i,e[14]=n,e[15]=w}else w=e[15];const v=w;let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[18]=x):x=e[18];const m=c.useRef(x);let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[19]=b):b=e[19];const y=c.useRef(b);let S;e[20]!==a||e[21]!==i||e[22]!==n||e[23]!==l?(S=()=>{if(!a)return;let C=!1;const k=setTimeout(()=>{(async()=>{const D=new Set(n.map(Ev));for(const z of m.current.keys())D.has(z)||(m.current.delete(z),y.current.delete(z));const P=Date.now(),F=n.filter(z=>{const B=i.get(z.normalizedPath);if(B?.isGitRepo===!1)return m.current.delete(z.id),y.current.delete(z.id),!1;if(B?.isGitRepo!==!0||B.branch===null)return!1;const T=B.branch.trim(),j=`${z.normalizedPath}\0${T}`,I=m.current.get(z.id);if(I===j){const _=y.current.get(z.id);return _&&(_.at=P),!1}return!(I!==void 0&&P-(y.current.get(z.id)?.at??0)<Iv)});if(F.length===0)return;const W=await th(F,2,async z=>{const B=i.get(z.normalizedPath)?.branch?.trim()??"",T=`${z.normalizedPath}\0${B}`,j=await Di(()=>Jo(z.normalizedPath,B?{knownBranch:B}:void 0)).catch(Mv);return{id:z.id,inputKey:T,branch:j}});if(C)return;const E=W.filter(Ov);if(E.length===0)return;const H=Date.now();l(z=>{const B=new Map(z);return E.forEach(T=>{const{id:j,branch:I}=T;I&&B.set(j,I)}),B}),E.forEach(z=>{const{id:B,inputKey:T,branch:j}=z;m.current.set(B,T),j&&y.current.set(B,{branch:j,at:H})})})()},150);return()=>{C=!0,clearTimeout(k)}},e[20]=a,e[21]=i,e[22]=n,e[23]=l,e[24]=S):S=e[24];let N;e[25]!==a||e[26]!==i||e[27]!==n||e[28]!==v||e[29]!==l?(N=[a,n,v,i,l],e[25]=a,e[26]=i,e[27]=n,e[28]=v,e[29]=l,e[30]=N):N=e[30],c.useEffect(S,N)};function Rv(t){return t.ensureStatus}function Ev(t){return t.id}function Mv(){return null}function Ov(t){return t.branch}const Fv=t=>{const e=Xe.c(10),{open:n,onOpenChange:r,project:i,onSave:o}=t;let l;e[0]!==o||e[1]!==n||e[2]!==i?(l=n&&i?s.jsx(Kp,{project:i,onIdentitySave:o,showWorktrees:!1}):null,e[0]=o,e[1]=n,e[2]=i,e[3]=l):l=e[3];let a;e[4]!==l?(a=s.jsx(js,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(kn,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:l})})}),e[4]=l,e[5]=a):a=e[5];let u;return e[6]!==r||e[7]!==n||e[8]!==a?(u=s.jsx(vs,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=u):u=e[9],u},Bv=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const i of t){r.has(i)||(r.add(i),n.push(i));const o=e.get(i);if(o)for(const l of o)r.has(l)||(r.add(l),n.push(l))}return n},gs=Zn()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,i)=>{const o=e(),l=new Set(o.selectedIds);let a=o.scopeKey,u=o.anchorId;r!==null&&o.scopeKey!==null&&r!==o.scopeKey?(l.clear(),a=r,u=null):a===null&&r!==null&&(a=r);const h=i&&i.length>0?[n,...i]:[n];if(l.has(n)){for(const g of h)l.delete(g);u===n&&(u=null)}else{for(const g of h)l.add(g);u=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:a,anchorId:u})},setRange:(n,r,i,o,l)=>{const a=e();if(i.length===0)return;const u=n&&i.includes(n)?n:i[0],d=i.indexOf(u),h=i.indexOf(r);if(d<0||h<0)return;const[f,g]=d<=h?[d,h]:[h,d],p=i.slice(f,g+1),w=Bv(p,l),x=o!==null&&a.scopeKey!==null&&o!==a.scopeKey?new Set:new Set(a.selectedIds);for(const m of w)x.add(m);t({selectedIds:x,scopeKey:o??a.scopeKey,anchorId:u})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const i=new Set(r.selectedIds);for(const o of n)i.delete(o);i.size!==r.selectedIds.size&&(i.size===0?t({selectedIds:i,scopeKey:null,anchorId:null}):t({selectedIds:i}))}}));function _v(t){const e=Xe.c(213),{t:n}=pt(),{hideDirectoryControls:r,showProjectDisplayControls:i,showRecentControls:o,handleOpenDirectoryDialog:l,onOpenScheduled:a,onOpenMultiRun:u,canOpenMultiRun:d,onOpenArchive:h,headerActionIconClass:f,headerActionButtonClass:g,isSessionSearchOpen:p,setIsSessionSearchOpen:w,sessionSearchInputRef:v,sessionSearchQuery:x,setSessionSearchQuery:m,hasSessionSearchQuery:b,searchMatchCount:y,collapseAllProjects:S,expandAllProjects:N}=t,C=gs(Xv),k=gs(Yv),A=ls(Qv),D=ls(qv),P=ls(Gv),F=ls(Hv),W=ls(Kv),E=ls(Uv),H=ls(Vv),z=ls(zv),B=ls(Wv),T=ls($v),j=i&&B==="single";if(r)return null;let I;e[0]!==g?(I=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=g,e[1]=I):I=e[1];let _;e[2]!==n?(_=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=_):_=e[3];let K;e[4]!==f?(K=s.jsx(M,{name:"folder-add",className:f}),e[4]=f,e[5]=K):K=e[5];let G;e[6]!==l||e[7]!==I||e[8]!==_||e[9]!==K?(G=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:I,"aria-label":_,children:K})}),e[6]=l,e[7]=I,e[8]=_,e[9]=K,e[10]=G):G=e[10];let Q;e[11]!==n?(Q=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=Q):Q=e[12];let ge;e[13]!==Q?(ge=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Q})}),e[13]=Q,e[14]=ge):ge=e[14];let se;e[15]!==G||e[16]!==ge?(se=s.jsxs(gt,{children:[G,ge]}),e[15]=G,e[16]=ge,e[17]=se):se=e[17];let Y;e[18]!==g?(Y=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=g,e[19]=Y):Y=e[19];let te;e[20]!==n?(te=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=te):te=e[21];let he;e[22]!==f?(he=s.jsx(M,{name:"calendar-schedule",className:f}),e[22]=f,e[23]=he):he=e[23];let L;e[24]!==a||e[25]!==Y||e[26]!==te||e[27]!==he?(L=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Y,"aria-label":te,children:he})}),e[24]=a,e[25]=Y,e[26]=te,e[27]=he,e[28]=L):L=e[28];let le;e[29]!==n?(le=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=le):le=e[30];let Z;e[31]!==le?(Z=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:le})}),e[31]=le,e[32]=Z):Z=e[32];let ue;e[33]!==L||e[34]!==Z?(ue=s.jsxs(gt,{children:[L,Z]}),e[33]=L,e[34]=Z,e[35]=ue):ue=e[35];let V;e[36]!==g?(V=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=g,e[37]=V):V=e[37];let ee;e[38]!==n?(ee=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=ee):ee=e[39];const be=!d;let xe;e[40]!==f?(xe=s.jsx(sh,{className:f}),e[40]=f,e[41]=xe):xe=e[41];let Ne;e[42]!==u||e[43]!==V||e[44]!==ee||e[45]!==be||e[46]!==xe?(Ne=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:V,"aria-label":ee,disabled:be,children:xe})}),e[42]=u,e[43]=V,e[44]=ee,e[45]=be,e[46]=xe,e[47]=Ne):Ne=e[47];let Pe;e[48]!==n?(Pe=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=Pe):Pe=e[49];let Se;e[50]!==Pe?(Se=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Pe})}),e[50]=Pe,e[51]=Se):Se=e[51];let Re;e[52]!==Ne||e[53]!==Se?(Re=s.jsxs(gt,{children:[Ne,Se]}),e[52]=Ne,e[53]=Se,e[54]=Re):Re=e[54];let ye;e[55]!==g?(ye=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=g,e[56]=ye):ye=e[56];let pe;e[57]!==n?(pe=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=pe):pe=e[58];let me;e[59]!==f?(me=s.jsx(M,{name:"archive",className:f}),e[59]=f,e[60]=me):me=e[60];let je;e[61]!==h||e[62]!==ye||e[63]!==pe||e[64]!==me?(je=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:ye,"aria-label":pe,children:me})}),e[61]=h,e[62]=ye,e[63]=pe,e[64]=me,e[65]=je):je=e[65];let ne;e[66]!==n?(ne=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=ne):ne=e[67];let fe;e[68]!==ne?(fe=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[68]=ne,e[69]=fe):fe=e[69];let ce;e[70]!==je||e[71]!==fe?(ce=s.jsxs(gt,{children:[je,fe]}),e[70]=je,e[71]=fe,e[72]=ce):ce=e[72];let R;e[73]!==ue||e[74]!==Re||e[75]!==ce||e[76]!==se?(R=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[se,ue,Re,ce]}),e[73]=ue,e[74]=Re,e[75]=ce,e[76]=se,e[77]=R):R=e[77];let $;e[78]!==w?($=()=>w(Lv),e[78]=w,e[79]=$):$=e[79];let de;e[80]!==g?(de=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=g,e[81]=de):de=e[81];let ie;e[82]!==n?(ie=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=ie):ie=e[83];let Ae;e[84]!==f?(Ae=s.jsx(M,{name:"search",className:f}),e[84]=f,e[85]=Ae):Ae=e[85];let Be;e[86]!==p||e[87]!==$||e[88]!==de||e[89]!==ie||e[90]!==Ae?(Be=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:$,className:de,"aria-label":ie,"aria-expanded":p,children:Ae})}),e[86]=p,e[87]=$,e[88]=de,e[89]=ie,e[90]=Ae,e[91]=Be):Be=e[91];let Ce;e[92]!==n?(Ce=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=Ce):Ce=e[93];let q;e[94]!==Ce?(q=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ce})}),e[94]=Ce,e[95]=q):q=e[95];let Ee;e[96]!==Be||e[97]!==q?(Ee=s.jsxs(gt,{children:[Be,q]}),e[96]=Be,e[97]=q,e[98]=Ee):Ee=e[98];const Me=C&&"bg-interactive-hover text-primary";let O;e[99]!==g||e[100]!==Me?(O=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent",Me),e[99]=g,e[100]=Me,e[101]=O):O=e[101];let oe;e[102]!==C||e[103]!==n?(oe=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=C,e[103]=n,e[104]=oe):oe=e[104];let re;e[105]!==f?(re=s.jsx(M,{name:"checkbox-multiple",className:f}),e[105]=f,e[106]=re):re=e[106];let we;e[107]!==C||e[108]!==O||e[109]!==oe||e[110]!==re||e[111]!==k?(we=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:O,"aria-label":oe,"aria-pressed":C,children:re})}),e[107]=C,e[108]=O,e[109]=oe,e[110]=re,e[111]=k,e[112]=we):we=e[112];let Ve;e[113]!==C||e[114]!==n?(Ve=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=C,e[114]=n,e[115]=Ve):Ve=e[115];let st;e[116]!==Ve?(st=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ve})}),e[116]=Ve,e[117]=st):st=e[117];let Ge;e[118]!==we||e[119]!==st?(Ge=s.jsxs(gt,{children:[we,st]}),e[118]=we,e[119]=st,e[120]=Ge):Ge=e[120];let ae;e[121]!==g?(ae=Te(g,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=g,e[122]=ae):ae=e[122];let X;e[123]!==n?(X=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=X):X=e[124];let ve;e[125]!==f?(ve=s.jsx(M,{name:"equalizer-2",className:f}),e[125]=f,e[126]=ve):ve=e[126];let Le;e[127]!==ae||e[128]!==X||e[129]!==ve?(Le=s.jsx(xt,{asChild:!0,children:s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:ae,"aria-label":X,children:ve})})}),e[127]=ae,e[128]=X,e[129]=ve,e[130]=Le):Le=e[130];let $e;e[131]!==n?($e=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=$e):$e=e[132];let Ue;e[133]!==$e?(Ue=s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:$e})}),e[133]=$e,e[134]=Ue):Ue=e[134];let We;e[135]!==Le||e[136]!==Ue?(We=s.jsxs(gt,{children:[Le,Ue]}),e[135]=Le,e[136]=Ue,e[137]=We):We=e[137];let qe;e[138]!==n?(qe=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=qe):qe=e[139];let nt;e[140]!==qe?(nt=s.jsx(go,{children:qe}),e[140]=qe,e[141]=nt):nt=e[141];let yt;e[142]!==P||e[143]!==F||e[144]!==n?(yt=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]].map(Ct=>{const[Pt,Wt]=Ct;return s.jsxs($t,{onClick:()=>{F(Pt),Dr({sidebarProjectSortOrder:Pt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Wt)}),P===Pt?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null]},Pt)}),e[142]=P,e[143]=F,e[144]=n,e[145]=yt):yt=e[145];let vt;e[146]===Symbol.for("react.memo_cache_sentinel")?(vt=s.jsx(Es,{}),e[146]=vt):vt=e[146];let He;e[147]!==B||e[148]!==T||e[149]!==i||e[150]!==n?(He=i?s.jsxs(s.Fragment,{children:[s.jsx(go,{children:n("sessions.sidebar.header.projectDisplay.label")}),[["all","sessions.sidebar.header.projectDisplay.all"],["single","sessions.sidebar.header.projectDisplay.single"]].map(Ct=>{const[Pt,Wt]=Ct;return s.jsxs($t,{onClick:()=>{T(Pt),Dr({sidebarProjectDisplayMode:Pt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Wt)}),B===Pt?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null]},Pt)}),s.jsx(Es,{})]}):null,e[147]=B,e[148]=T,e[149]=i,e[150]=n,e[151]=He):He=e[151];let Mt;e[152]!==n?(Mt=n("sessions.sidebar.header.grouping.label"),e[152]=n,e[153]=Mt):Mt=e[153];let jt;e[154]!==Mt?(jt=s.jsx(go,{children:Mt}),e[154]=Mt,e[155]=jt):jt=e[155];let kt;e[156]!==W||e[157]!==E||e[158]!==n?(kt=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(Ct=>{const[Pt,Wt]=Ct;return s.jsxs($t,{onClick:()=>{E(Pt),Dr({sidebarSessionGroupingMode:Pt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Wt)}),W===Pt?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null]},Pt)}),e[156]=W,e[157]=E,e[158]=n,e[159]=kt):kt=e[159];let Tt;e[160]===Symbol.for("react.memo_cache_sentinel")?(Tt=s.jsx(Es,{}),e[160]=Tt):Tt=e[160];let wt;e[161]!==j||e[162]!==o||e[163]!==A||e[164]!==n||e[165]!==D?(wt=o&&!j?s.jsxs($t,{onClick:()=>{D(),Dr({sidebarShowRecentSection:!A})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),A?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[161]=j,e[162]=o,e[163]=A,e[164]=n,e[165]=D,e[166]=wt):wt=e[166];let Nt;e[167]!==n?(Nt=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[167]=n,e[168]=Nt):Nt=e[168];let Dt;e[169]!==Nt?(Dt=s.jsx("span",{children:Nt}),e[169]=Nt,e[170]=Dt):Dt=e[170];let ft;e[171]!==H?(ft=H?s.jsx(M,{name:"check",className:"h-4 w-4 text-primary"}):null,e[171]=H,e[172]=ft):ft=e[172];let Ze;e[173]!==Dt||e[174]!==ft||e[175]!==z?(Ze=s.jsxs($t,{onClick:z,className:"flex items-center justify-between",children:[Dt,ft]}),e[173]=Dt,e[174]=ft,e[175]=z,e[176]=Ze):Ze=e[176];let ke;e[177]!==S||e[178]!==N||e[179]!==j||e[180]!==n?(ke=j?null:s.jsxs(s.Fragment,{children:[s.jsx(Es,{}),s.jsxs($t,{onClick:S,className:"flex items-center gap-2",children:[s.jsx(M,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs($t,{onClick:N,className:"flex items-center gap-2",children:[s.jsx(M,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]}),e[177]=S,e[178]=N,e[179]=j,e[180]=n,e[181]=ke):ke=e[181];let tt;e[182]!==nt||e[183]!==yt||e[184]!==He||e[185]!==jt||e[186]!==kt||e[187]!==wt||e[188]!==Ze||e[189]!==ke?(tt=s.jsxs(Xs,{align:"end",className:"min-w-[180px]",children:[nt,yt,vt,He,jt,kt,Tt,wt,Ze,ke]}),e[182]=nt,e[183]=yt,e[184]=He,e[185]=jt,e[186]=kt,e[187]=wt,e[188]=Ze,e[189]=ke,e[190]=tt):tt=e[190];let lt;e[191]!==We||e[192]!==tt?(lt=s.jsxs(Js,{children:[We,tt]}),e[191]=We,e[192]=tt,e[193]=lt):lt=e[193];let At;e[194]!==Ee||e[195]!==Ge||e[196]!==lt?(At=s.jsxs("div",{className:"flex items-center gap-1.5",children:[Ee,Ge,lt]}),e[194]=Ee,e[195]=Ge,e[196]=lt,e[197]=At):At=e[197];let Ye;e[198]!==R||e[199]!==At?(Ye=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[R,At]}),e[198]=R,e[199]=At,e[200]=Ye):Ye=e[200];let rt;e[201]!==b||e[202]!==p||e[203]!==y||e[204]!==v||e[205]!==x||e[206]!==w||e[207]!==m||e[208]!==n?(rt=p?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[b?s.jsx("span",{children:y===1?n("sessions.sidebar.header.search.matchCountSingle",{count:y}):n("sessions.sidebar.header.search.matchCountPlural",{count:y})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(M,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:v,value:x,onChange:Ct=>m(Ct.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:Ct=>{Ct.key==="Escape"&&(Ct.stopPropagation(),b?m(""):w(!1))}}),x.length>0?s.jsx("button",{type:"button",onClick:()=>m(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(M,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[201]=b,e[202]=p,e[203]=y,e[204]=v,e[205]=x,e[206]=w,e[207]=m,e[208]=n,e[209]=rt):rt=e[209];let It;return e[210]!==Ye||e[211]!==rt?(It=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[Ye,rt]})}),e[210]=Ye,e[211]=rt,e[212]=It):It=e[212],It}function Lv(t){return!t}function $v(t){return t.setProjectDisplayMode}function Wv(t){return t.projectDisplayMode}function zv(t){return t.toggleStickyZoneHeaders}function Vv(t){return t.stickyZoneHeaders}function Uv(t){return t.setSessionGroupingMode}function Kv(t){return t.sessionGroupingMode}function Hv(t){return t.setProjectSortOrder}function Gv(t){return t.projectSortOrder}function qv(t){return t.toggleRecentSection}function Qv(t){return t.showRecentSection}function Yv(t){return t.toggleMode}function Xv(t){return t.enabled}function Jv(t){const e=Xe.c(8),{t:n}=pt(),r=t.onNewSession;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(M,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=i):i=e[0];let o;e[1]!==n?(o=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==o?(l=s.jsx("span",{className:"truncate",children:o}),e[3]=o,e[4]=l):l=e[4];let a;return e[5]!==t.onNewSession||e[6]!==l?(a=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 pt-1.5",children:s.jsxs("button",{type:"button",onClick:r,className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left typography-ui-label font-normal text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[i,l]})}),e[5]=t.onNewSession,e[6]=l,e[7]=a):a=e[7],a}const pi="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function Zv(t){const e=Xe.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:i,onOpenUpdate:o,showRuntimeButtons:l,showUpdateButton:a}=t,u=l===void 0?!0:l,d=a===void 0?!0:a,{t:h}=pt();if(!u&&!d)return null;let f;e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==u||e[4]!==h?(f=u?s.jsxs(s.Fragment,{children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:pi,"aria-label":h("sessions.sidebar.footer.actions.settings"),children:s.jsx(M,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:pi,"aria-label":h("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(M,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:pi,"aria-label":h("sessions.sidebar.footer.actions.aboutAiWorker"),children:s.jsx(M,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.aboutAiWorker")})})]})]}):null,e[0]=i,e[1]=n,e[2]=r,e[3]=u,e[4]=h,e[5]=f):f=e[5];let g;e[6]!==o||e[7]!==d||e[8]!==h?(g=d?s.jsx(at,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:o,children:h("sessions.sidebar.footer.actions.update")}):null,e[6]=o,e[7]=d,e[8]=h,e[9]=g):g=e[9];let p;return e[10]!==f||e[11]!==g?(p=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,g]}),e[10]=f,e[11]=g,e[12]=p):p=e[12],p}const e0=t=>{const e=Xe.c(12),{normalizedProjects:n,enabled:r,ownership:i,isSessionsLoading:o,hasAuthoritativeGlobalSessions:l,isWorktreeTopologyLoading:a,unresolvedWorktreeProjectPaths:u,foldersMap:d,createFolder:h,addSessionToFolder:f}=t,g=r===void 0?!0:r;let p,w;e[0]!==f||e[1]!==h||e[2]!==g||e[3]!==d||e[4]!==l||e[5]!==o||e[6]!==a||e[7]!==n||e[8]!==i||e[9]!==u?(p=()=>{!g||o||!l||a||n.forEach(v=>{if(u.has(v.normalizedPath))return;const x=Td(v.normalizedPath),m=i.archivedSessionsByProject.get(v.id)??[],b=d[x]??[],y=new Map(b.map(t0));m.forEach(S=>{const N=nh(S,v.normalizedPath),C=N.toLowerCase();let k=y.get(C);k||(k=h(x,N),y.set(C,k)),k.sessionIds.includes(S.id)||f(x,k.id,S.id)})})},w=[n,g,i,o,l,a,u,d,h,f],e[0]=f,e[1]=h,e[2]=g,e[3]=d,e[4]=l,e[5]=o,e[6]=a,e[7]=n,e[8]=i,e[9]=u,e[10]=p,e[11]=w):(p=e[10],w=e[11]),c.useEffect(p,w)};function t0(t){return[t.name.toLowerCase(),t]}function s0({activeProjectId:t,currentSessionId:e,currentSessionOwnerProjectId:n,projectMap:r,metaByProject:i,rememberedSessionId:o,fallbackSessionId:l}){if(e&&n===t)return{kind:"preserve-current"};if(n==null){const d=!!(e&&Array.from(i.entries()).some(([h,f])=>h!==t&&f.has(e)));if(e&&r&&!d)return{kind:"preserve-current"}}if(!r||r.size===0)return{kind:"open-draft"};const u=(o&&r.has(o)?o:null)??l;return!u||u===e?{kind:"none"}:{kind:"select-session",sessionId:u}}const n0=t=>{const e=Xe.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:o,currentSessionId:l,currentSessionOwnerProjectId:a,handleSessionSelect:u,newSessionDraftOpen:d,mobileVariant:h,openNewSessionDraft:f,setSessionSwitcherOpen:g}=t;let p,w;if(e[0]!==n){w=new Map,p=new Map;const C=(k,A,D,P)=>{w.has(k)||w.set(k,new Map);const F=w.get(k);P.forEach(W=>{const E=ct(W.worktree?.path??W.session.directory??D??A);F.set(W.session.id,{directory:E}),p.has(k)||p.set(k,{id:W.session.id,directory:E}),W.children.length>0&&C(k,A,E,W.children)})};n.forEach(k=>{k.groups.forEach(A=>{C(k.project.id,k.project.normalizedPath,A.directory,A.sessions)})}),e[0]=n,e[1]=p,e[2]=w}else p=e[1],w=e[2];let v;e[3]!==p||e[4]!==w?(v={metaByProject:w,firstSessionByProject:p},e[3]=p,e[4]=w,e[5]=v):v=e[5];const x=v,m=c.useRef(null);let b,y;e[6]!==r||e[7]!==i||e[8]!==l||e[9]!==a||e[10]!==u||e[11]!==h||e[12]!==d||e[13]!==f||e[14]!==n||e[15]!==x||e[16]!==o||e[17]!==g?(b=()=>{if(!r||d||De.getState().isNewWorktreeDialogOpen||m.current===r)return;const C=n.find(P=>P.project.id===r);if(!C)return;const k=x.metaByProject.get(r);if(l&&k&&k.has(l)){m.current=r,o(P=>{if(P.get(r)===l)return P;const F=new Map(P);return F.set(r,l),F});return}const A=s0({activeProjectId:r,currentSessionId:l,currentSessionOwnerProjectId:a,projectMap:k,metaByProject:x.metaByProject,rememberedSessionId:i.get(r),fallbackSessionId:x.firstSessionByProject.get(r)?.id??null});if(A.kind==="preserve-current"){a===r&&(m.current=r);return}if(m.current=r,A.kind==="open-draft"){h&&g(!1),f({selectedProjectId:C.project.id,directoryOverride:C.project.normalizedPath});return}if(A.kind!=="select-session")return;const D=k?.get(A.sessionId)?.directory??null;u(A.sessionId,D)},y=[r,i,l,a,u,d,h,f,n,x,g,o],e[6]=r,e[7]=i,e[8]=l,e[9]=a,e[10]=u,e[11]=h,e[12]=d,e[13]=f,e[14]=n,e[15]=x,e[16]=o,e[17]=g,e[18]=b,e[19]=y):(b=e[18],y=e[19]),c.useLayoutEffect(b,y);let S,N;e[20]!==r||e[21]!==l||e[22]!==x||e[23]!==o?(S=()=>{if(!r||!l)return;const C=x.metaByProject.get(r);!C||!C.has(l)||o(k=>{if(k.get(r)===l)return k;const A=new Map(k);return A.set(r,l),A})},N=[r,l,x,o],e[20]=r,e[21]=l,e[22]=x,e[23]=o,e[24]=S,e[25]=N):(S=e[24],N=e[25]),c.useEffect(S,N)},r0=t=>{const e=Xe.c(20);let n,r,i,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:i,sessionOwnerBySessionId:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=o):(n=e[1],r=e[2],i=e[3],o=e[4]);const l=Qe(o0),a=Qe(i0);let u;e[5]!==l||e[6]!==o?(u=l?o?.get(l)?.projectId??null:null,e[5]=l,e[6]=o,e[7]=u):u=e[7];const d=u;let h;e[8]!==r?(h=()=>new Map(r),e[8]=r,e[9]=h):h=e[9];const[f,g]=c.useState(h);let p;e[10]!==f||e[11]!==n||e[12]!==l||e[13]!==d||e[14]!==a?(p={...n,activeSessionByProject:f,setActiveSessionByProject:g,currentSessionId:l,currentSessionOwnerProjectId:d,newSessionDraftOpen:a},e[10]=f,e[11]=n,e[12]=l,e[13]=d,e[14]=a,e[15]=p):p=e[15],n0(p);let w,v;return e[16]!==f||e[17]!==i?(w=()=>{i(f)},v=[f,i],e[16]=f,e[17]=i,e[18]=w,e[19]=v):(w=e[18],v=e[19]),c.useEffect(w,v),null};function o0(t){return t.currentSessionId}function i0(t){return!!t.newSessionDraft?.open}const dc={selected:0,"active-project":1,expanded:2,visible:3,background:4};function nm(t){const e=new Map,n=(r,i,o)=>{const l=ct(r??null);if(!l)return;const a=e.get(l);a&&dc[a.priority]<=dc[i]||e.set(l,{directory:l,priority:i,reason:o})};for(const r of t.knownDirectories??[])n(r,"background","known-project");n(t.activeProjectDirectory,"active-project","project-expanded");for(const r of t.projectSections??[]){const i=!t.collapsedProjects.has(r.project.id);let o="background";r.project.id===t.activeProjectId?o="active-project":i&&(o="expanded"),n(r.project.normalizedPath,o,i?"project-expanded":"known-project");for(const l of r.groups){if(!l.directory||l.isArchivedBucket||l.isMain)continue;const a=i&&!t.collapsedGroups.has(`${r.project.id}:${l.id}`);let u="background";a?u="expanded":i&&(u="visible"),n(l.directory,u,a?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const a0=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,uc=(t,e,n)=>{a0(t.get(e),n)&&t.set(e,n)},l0=t=>{const e=t;return ct(e.directory)??ct(e.project?.worktree)},c0=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},d0=(t,e,n,r,i=[])=>{const o=new Map,l=new Map;for(const w of e){const v=ct(w.normalizedPath);if(!v)continue;const x=l.get(v);(!x||w.id.localeCompare(x.id)<0)&&l.set(v,w),uc(o,v,{projectId:w.id,projectRoot:v,scopeDirectory:v,kind:"project"})}if(!r)for(const[w,v]of n){const x=ct(w),m=x?l.get(x):void 0;if(!(!m||!x))for(const b of v){const y=ct(b.path);y&&uc(o,y,{projectId:m.id,projectRoot:x,scopeDirectory:y,kind:"worktree"})}}const a=new Map,u=new Map,d=new Map,h=new Map,f=new Map,g=w=>{if(!w)return null;if(a.has(w))return a.get(w)??null;if(r){const b=o.get(w)??null;return a.set(w,b),b}const v=[];let x=w,m=null;for(;x;){if(a.has(x)){m=a.get(x)??null;break}if(v.push(x),m=o.get(x)??null,m)break;x=c0(x)}for(const b of v)a.set(b,m);return m},p=(w,v,x)=>{for(const m of w){const b=g(l0(m));if(!b)continue;u.set(m.id,b);const y=v.get(b.projectId);if(y?y.push(m):v.set(b.projectId,[m]),!x)continue;const S=x.get(b.scopeDirectory);S?S.add(m.id):x.set(b.scopeDirectory,new Set([m.id]))}};return p(t,d,f),p(i,h),{bySessionId:u,sessionsByProject:d,archivedSessionsByProject:h,sessionsByScope:f,directoryResolutions:a.size}},u0=t=>{const e=Xe.c(7),{ownership:n}=t;let r;e[0]!==n?(r=u=>n.sessionsByProject.get(u)??[],e[0]=n,e[1]=r):r=e[1];const i=r;let o;e[2]!==n?(o=u=>n.archivedSessionsByProject.get(u)??[],e[2]=n,e[3]=o):o=e[3];const l=o;let a;return e[4]!==l||e[5]!==i?(a={getSessionsForProject:i,getArchivedSessionsForProject:l},e[4]=l,e[5]=i,e[6]=a):a=e[6],a},m0=(t,e)=>t.map(n=>{const r=ct(n.path)??n.path;return`${r}=${e.get(r)??""}`}).join(`
|
|
911
|
-
`),f0=[],h0=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:l,gitBranches:a,lastRepoStatus:u,buildGroupedSessions:d,hasSessionSearchQuery:h,normalizedSessionSearchQuery:f,filterSessionNodesForSearch:g,buildGroupSearchText:p,foldersMap:w,standaloneGroups:v}=t,x=c.useRef(new Map),m=c.useMemo(()=>{const D=x.current,P=new Map;let F=0,W=0;const E=(z,B)=>z.length===B.length&&z.every((T,j)=>T===B[j]),H=e.map(z=>{const B=n(z.id),T=r(z.id),j=i.get(z.normalizedPath)??f0,I=o.has(z.id)?!!o.get(z.id):u,_=l.get(z.id)??null,K=m0(j,a),G=D.get(z.id);if(G&&G.project===z&&E(G.activeSessions,B)&&E(G.archivedSessions,T)&&G.availableWorktrees===j&&G.rootBranch===_&&G.worktreeBranchesKey===K&&G.isRepo===I&&G.buildGroupedSessions===d)return F+=1,P.set(z.id,G),G.section;if(W+=1,G){const Y=G.project!==z?"project":E(G.activeSessions,B)?E(G.archivedSessions,T)?G.availableWorktrees!==j?"worktrees":G.rootBranch!==_?"branch":G.worktreeBranchesKey!==K?"worktreeBranches":G.isRepo!==I?"repo":"builder":"archived":"sessions";qs(`ui.sidebar.project_section.rebuilt_reason.${Y}`)}const Q=Rd([...B,...T]),ge=d(Q,z.normalizedPath,j,_,I),se={project:z,groups:ge};return P.set(z.id,{project:z,activeSessions:B,archivedSessions:T,availableWorktrees:j,rootBranch:_,worktreeBranchesKey:K,isRepo:I,buildGroupedSessions:d,section:se}),se});return x.current=P,F>0&&qs("ui.sidebar.project_section.reused",F),W>0&&qs("ui.sidebar.project_section.rebuilt",W),H},[e,n,r,i,o,u,d,l,a]),b=c.useMemo(()=>m,[m]),y=c.useMemo(()=>{const D=new WeakMap;if(!h)return D;const P=W=>W.reduce((E,H)=>E+1+P(H.children),0),F=W=>{const E=g(W.sessions,f),H=P(E),z=Io([p(W)],f),B=ct(W.directory??null),j=(B?w[B]??[]:[]).filter(I=>Io([I.name],f)).length;D.set(W,{filteredNodes:E,matchedSessionCount:H,folderNameMatchCount:j,groupMatches:z,hasMatch:z||H>0||j>0})};return b.forEach(W=>{W.groups.forEach(F)}),v.forEach(F),D},[h,b,v,g,f,p,w]),S=c.useMemo(()=>h?b.map(D=>({...D,groups:D.groups.filter(P=>y.get(P)?.hasMatch===!0)})).filter(D=>D.groups.length>0):b,[h,b,y]),N=h?S:b,C=c.useRef(new WeakMap),k=c.useMemo(()=>{const D=C.current;return N.map(P=>{const F=D.get(P);if(F&&F.query===f)return F.section;const W=P.groups.filter(I=>!I.isArchivedBucket),E=P.groups.filter(I=>I.isArchivedBucket),H=W.flatMap(I=>h?y.get(I)?.filteredNodes??[]:I.sessions),z=W.map(I=>({scopeKey:I.folderScopeKey??ct(I.directory??null),directory:I.directory??null})).filter(I=>!!I.scopeKey),B=W.find(I=>I.isMain)??null,T={id:"flat",label:B?.label??"",branch:B?.branch??null,description:B?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:B?.directory??P.project.normalizedPath,folderScopeKey:B?.folderScopeKey??P.project.normalizedPath,folderScopes:z,sessions:H};if(h){const I=W.map(_=>y.get(_)).filter(_=>!!_);y.set(T,{filteredNodes:H,matchedSessionCount:I.reduce((_,K)=>_+K.matchedSessionCount,0),folderNameMatchCount:I.reduce((_,K)=>_+K.folderNameMatchCount,0),groupMatches:I.some(_=>_.groupMatches),hasMatch:I.some(_=>_.hasMatch)})}const j={project:P.project,groups:[T,...E]};return D.set(P,{query:f,section:j}),j})},[y,h,f,N]),A=c.useMemo(()=>{if(!h)return 0;const D=(F,W)=>{const E=y.get(W);if(!E)return F;const H=E.folderNameMatchCount+(E.groupMatches?1:0);return F+E.matchedSessionCount+H},P=N.reduce((F,W)=>W.groups.reduce(D,F),0);return v.reduce(D,P)},[h,N,v,y]);return{projectSections:m,visibleProjectSections:b,groupSearchDataByGroup:y,searchableProjectSections:S,sectionsForRender:N,flatSectionsForRender:k,searchMatchCount:A}},p0=180,mc=150,g0=2,x0=8,fc=[-1,1,-2,2],gi=t=>`${t.directory}
|
|
912
|
-
${t.sessionId}`,b0=t=>t?.directory?.trim()||null,y0=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:i})=>{const o=c.useRef(new Map),l=c.useRef([]),a=c.useRef(new Set),u=c.useRef(0),d=c.useMemo(()=>Nn(),[]),h=c.useCallback(()=>{u.current+=1,l.current=[],o.current.forEach(p=>window.clearTimeout(p)),o.current.clear()},[]),f=c.useCallback(()=>{if(!(!t||d))for(;a.current.size<g0&&l.current.length>0;){const p=l.current.shift();if(!p)break;if(p.generation!==u.current||Qe.getState().currentSessionId===p.sessionId||Pi(p.sessionId,p.directory).renderable)continue;const v=gi(p);a.current.add(v),i({directory:p.directory,sessionID:p.sessionId}).catch(()=>{}).finally(()=>{a.current.delete(v),f()})}},[t,d,i]),g=c.useCallback(p=>{const w=p?.id,v=b0(p);if(!t||d||!w||!v||w===e)return;const x={sessionId:w,directory:v,generation:u.current},m=gi(x);if(Pi(w,v).renderable||a.current.has(m)||l.current.some(S=>gi(S)===m))return;const b=o.current.get(m);b!==void 0&&window.clearTimeout(b);const y=window.setTimeout(()=>{if(o.current.delete(m),x.generation!==u.current)return;const S=l.current;S.length>=x0&&S.shift(),S.push(x),f()},p0);o.current.set(m,y)},[e,t,d,f]);c.useEffect(()=>{h()},[h,e,t,d]),c.useEffect(()=>{if(!t||d||!e||n.length===0)return;const p=window.setTimeout(()=>{const w=n.findIndex(v=>v.id===e);if(!(w<0))for(const v of fc)g(n[w+v])},mc);return()=>window.clearTimeout(p)},[e,t,d,g,n]),c.useEffect(()=>{if(!t||d||!e||r.length===0)return;const p=window.setTimeout(()=>{const w=r.findIndex(v=>v.id===e);if(!(w<0))for(const v of fc)g(r[w+v])},mc);return()=>window.clearTimeout(p)},[e,t,d,r,g]),c.useEffect(()=>h,[h])},w0=t=>{const e=Xe.c(3),n=Qe(S0);let r;return e[0]!==t||e[1]!==n?(r={...t,currentSessionId:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],y0(r),null};function S0(t){return t.currentSessionId}const jo=t=>{const e=Xe.c(22),{id:n,projectLabel:r,projectIcon:i,projectColor:o,projectIconImage:l,projectIconBackground:a,isCollapsed:u,alwaysShowActions:d}=t,h=d===void 0?!1:d,{currentTheme:f}=Jn(),g=i?ja[i]:null,p=o?ka[o]??null:null,w=u!==void 0,v=w?h?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let x;e[0]!==h||e[1]!==w||e[2]!==u?(x=w?s.jsx("span",{className:Te("h-3.5 w-3.5 items-center justify-center text-muted-foreground",h?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:s.jsx(M,{name:u?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=h,e[1]=w,e[2]=u,e[3]=x):x=e[3];let m;e[4]!==h||e[5]!==f||e[6]!==w||e[7]!==p||e[8]!==v||e[9]!==n||e[10]!==a||e[11]!==l||e[12]!==g?(m=l?s.jsx("span",{className:Te("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",w&&h?"hidden":"inline-flex",v),style:a?{backgroundColor:a}:void 0,children:s.jsx(Ca,{project:{id:n,iconImage:l},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:g?s.jsx(M,{name:g,className:"h-3.5 w-3.5",style:p?{color:p}:void 0}):s.jsx(M,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:p?{color:p}:void 0})})}):g?s.jsx(M,{name:g,className:Te("h-3.5 w-3.5",v),style:p?{color:p}:void 0}):s.jsx(M,{name:"folder",className:Te("h-3.5 w-3.5 text-muted-foreground/80",v),style:p?{color:p}:void 0}),e[4]=h,e[5]=f,e[6]=w,e[7]=p,e[8]=v,e[9]=n,e[10]=a,e[11]=l,e[12]=g,e[13]=m):m=e[13];let b;e[14]!==x||e[15]!==m?(b=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[x,m]}),e[14]=x,e[15]=m,e[16]=b):b=e[16];let y;e[17]!==r?(y=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=y):y=e[18];let S;return e[19]!==b||e[20]!==y?(S=s.jsxs(s.Fragment,{children:[b,y]}),e[19]=b,e[20]=y,e[21]=S):S=e[21],S},v0=t=>{const e=Xe.c(62),{id:n,disabled:r,projectLabel:i,projectDescription:o,projectIcon:l,projectColor:a,projectIconImage:u,projectIconBackground:d,isCollapsed:h,isRepo:f,isDesktopShell:g,hideDirectoryControls:p,alwaysShowActions:w,onToggle:v,onNewSession:x,onNewWorktreeSession:m,onManageWorktrees:b,onRenameStart:y,onClose:S,sentinelRef:N,children:C,showCreateButtons:k,hideHeader:A,statusIndicator:D,openSidebarMenuKey:P,setOpenSidebarMenuKey:F,projectPickerOptions:W,onProjectSelect:E}=t,H=r===void 0?!1:r,z=k===void 0?!0:k,B=A===void 0?!1:A,T=D===void 0?null:D,{t:j}=pt(),I=ls(C0);let _;e[0]!==H||e[1]!==n?(_={id:n,disabled:H},e[0]=H,e[1]=n,e[2]=_):_=e[2];const{attributes:K,listeners:G,setNodeRef:Q,transform:ge,transition:se,isDragging:Y}=Zo(_),te=c.useRef(!1),he=`project:${n}`,L=P===he,[le,Z]=c.useState(!1),ue=!!(W&&E);let V;e[3]!==he||e[4]!==F?(V=de=>{de&&Z(!1),F(de?he:null)},e[3]=he,e[4]=F,e[5]=V):V=e[5];const ee=V;let be;e[6]!==p||e[7]!==f||e[8]!==S||e[9]!==b||e[10]!==x||e[11]!==y||e[12]!==z||e[13]!==j?(be=de=>s.jsxs(s.Fragment,{children:[z&&!f&&!p&&x&&s.jsxs(de,{onClick:x,children:[s.jsx(M,{name:"add",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.newSession")]}),f&&!p&&b&&s.jsxs(de,{onClick:b,children:[s.jsx(M,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(de,{onClick:y,children:[s.jsx(M,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.edit")]}),s.jsxs(de,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(M,{name:"close",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=p,e[7]=f,e[8]=S,e[9]=b,e[10]=x,e[11]=y,e[12]=z,e[13]=j,e[14]=be):be=e[14];const xe=be,Ne=N0,Pe=A0,Se=D0;let Re;e[15]===Symbol.for("react.memo_cache_sentinel")?(Re=de=>{(de.button===2||de.button===0&&de.ctrlKey)&&(te.current=!0)},e[15]=Re):Re=e[15];const ye=Re;let pe;e[16]!==v?(pe=de=>{if(de.currentTarget.blur(),te.current){te.current=!1;return}v()},e[16]=v,e[17]=pe):pe=e[17];const me=pe;let je;e[18]!==ge?(je=ei.Transform.toString(ge),e[18]=ge,e[19]=je):je=e[19];let ne;e[20]!==je||e[21]!==se?(ne={transform:je,transition:se},e[20]=je,e[21]=se,e[22]=ne):ne=e[22];const fe=Y&&"opacity-30";let ce;e[23]!==fe?(ce=Te("relative",fe),e[23]=fe,e[24]=ce):ce=e[24];let R;e[25]!==w||e[26]!==K||e[27]!==ee||e[28]!==me||e[29]!==p||e[30]!==B||e[31]!==n||e[32]!==h||e[33]!==le||e[34]!==g||e[35]!==L||e[36]!==ue||e[37]!==f||e[38]!==G||e[39]!==x||e[40]!==m||e[41]!==E||e[42]!==a||e[43]!==o||e[44]!==l||e[45]!==d||e[46]!==u||e[47]!==i||e[48]!==W||e[49]!==xe||e[50]!==N||e[51]!==z||e[52]!==T||e[53]!==I||e[54]!==j?(R=B?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:N,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Zd,{open:le,onOpenChange:Z,children:[s.jsx(Jd,{render:s.jsx("div",{className:Te("-ml-2.5 -mr-2 text-left group/project select-none",I&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":I?"true":void 0,onContextMenu:de=>{p||(de.preventDefault(),Z(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...K,children:[ue?s.jsxs(Js,{children:[s.jsx(Ys,{asChild:!0,children:s.jsxs("button",{type:"button",className:Te("flex min-w-0 flex-1 items-center gap-1.5 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-[padding]",f&&!p?w?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":w?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),"aria-label":j("sessions.sidebar.project.selectAria",{project:i}),children:[s.jsx(jo,{id:n,projectLabel:i,projectIcon:l,projectColor:a,projectIconImage:u,projectIconBackground:d}),s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Xs,{align:"start",className:"max-h-[70vh] min-w-[220px] overflow-y-auto",children:W?.map(de=>s.jsxs($t,{onClick:()=>E?.(de.id),className:"flex items-center justify-between gap-3",title:de.projectDescription,children:[s.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:s.jsx(jo,{...de})}),de.id===n?s.jsx(M,{name:"check",className:"h-4 w-4 flex-shrink-0 text-primary"}):null]},de.id))})]}):s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:ye,onClick:me,...G,className:Te("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!p?w?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":w?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(jo,{id:n,projectLabel:i,projectIcon:l,projectColor:a,projectIconImage:u,projectIconBackground:d,isCollapsed:h,alwaysShowActions:w}),T?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:T}):null]})}),s.jsx(bt,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Te("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",z?"right-7":"right-0.5"),children:[z&&f&&!p&&m?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),m()},className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(M,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:j("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,p?null:s.jsxs(Js,{open:L,onOpenChange:ee,children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",L?"opacity-100 pointer-events-auto":w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j("sessions.sidebar.project.actions.projectMenu"),onPointerDown:Pe,onMouseDown:Se,onClick:Ne,children:s.jsx(M,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Xs,{align:"end",className:"min-w-[180px]",children:xe($t)})]})]}),z&&x?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),x()},className:Te("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",w?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(M,{name:"add",className:"h-4 w-4"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:j(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Xd,{className:"min-w-[180px]",children:xe(Kn)})]})]}),e[25]=w,e[26]=K,e[27]=ee,e[28]=me,e[29]=p,e[30]=B,e[31]=n,e[32]=h,e[33]=le,e[34]=g,e[35]=L,e[36]=ue,e[37]=f,e[38]=G,e[39]=x,e[40]=m,e[41]=E,e[42]=a,e[43]=o,e[44]=l,e[45]=d,e[46]=u,e[47]=i,e[48]=W,e[49]=xe,e[50]=N,e[51]=z,e[52]=T,e[53]=I,e[54]=j,e[55]=R):R=e[55];let $;return e[56]!==C||e[57]!==Q||e[58]!==ne||e[59]!==ce||e[60]!==R?($=s.jsxs("div",{ref:Q,style:ne,className:ce,children:[R,C]}),e[56]=C,e[57]=Q,e[58]=ne,e[59]=ce,e[60]=R,e[61]=$):$=e[61],$},j0=t=>{const e=Xe.c(21),{id:n,disabled:r,children:i}=t,o=r===void 0?!1:r;let l;e[0]!==o||e[1]!==n?(l={id:n,disabled:o},e[0]=o,e[1]=n,e[2]=l):l=e[2];const{listeners:a,setNodeRef:u,setActivatorNodeRef:d,transform:h,transition:f,isDragging:g}=Zo(l);let p;e[3]!==a||e[4]!==d?(p={listeners:a,setActivatorNodeRef:d},e[3]=a,e[4]=d,e[5]=p):p=e[5];const w=p;let v;e[6]!==h?(v=ei.Transform.toString(h),e[6]=h,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==f?(x={transform:v,transition:f},e[8]=v,e[9]=f,e[10]=x):x=e[10];const m=g&&"opacity-50";let b;e[11]!==m?(b=Te("space-y-0.5 rounded-md",m),e[11]=m,e[12]=b):b=e[12];let y;e[13]!==i||e[14]!==w?(y=i(w),e[13]=i,e[14]=w,e[15]=y):y=e[15];let S;return e[16]!==u||e[17]!==x||e[18]!==b||e[19]!==y?(S=s.jsx("div",{ref:u,style:x,className:b,children:y}),e[16]=u,e[17]=x,e[18]=b,e[19]=y,e[20]=S):S=e[20],S},k0=c.memo(j0);function C0(t){return t.stickyZoneHeaders}function N0(t){t.stopPropagation()}function A0(t){t.stopPropagation()}function D0(t){t.stopPropagation()}const P0=(t,e)=>{const n=new Set,r=new Set,i=(o,l)=>{n.add(o.session.id),(!l||e)&&r.add(o.session.id),o.children.forEach(a=>i(a,!0))};return t.forEach(o=>i(o,!1)),{active:n,unread:r}},rm=t=>{const e=Xe.c(9),{nodes:n,includeUnreadSubtasks:r,enabled:i}=t,o=i===void 0?!0:i;let l;e[0]!==r||e[1]!==n?(l=P0(n,r),e[0]=r,e[1]=n,e[2]=l):l=e[2];const a=l;let u;e[3]!==o||e[4]!==a.active?(u=g=>{if(!o)return null;for(const p of a.active){const w=g.statusById.get(p)?.status.type;if(w==="busy"||w==="retry")return"active"}return null},e[3]=o,e[4]=a.active,e[5]=u):u=e[5];const d=Na(u);let h;e[6]!==o||e[7]!==a.unread?(h=g=>{if(!o)return null;for(const p of a.unread)if((g.index.session.unseenCount[p]??0)>0)return"unread";return null},e[6]=o,e[7]=a.unread,e[8]=h):h=e[8];const f=Aa(h);return d??f};function om(t){const e=Xe.c(6),{state:n,activeLabel:r,unreadLabel:i,className:o}=t,l=n==="active"?r:i,a=n==="active"?"bg-primary":"bg-[var(--status-info)]";let u;e[0]!==o||e[1]!==a?(u=Te("h-1.5 w-1.5 shrink-0 rounded-full",a,o),e[0]=o,e[1]=a,e[2]=u):u=e[2];let d;return e[3]!==l||e[4]!==u?(d=s.jsx("span",{className:u,"aria-label":l,title:l}),e[3]=l,e[4]=u,e[5]=d):d=e[5],d}const I0=t=>{const e=Xe.c(11),{nodes:n,includeUnreadSubtasks:r}=t,{t:i}=pt();let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=rm(o);if(!l)return null;let a;e[3]!==i?(a=i("sessions.sidebar.session.status.active"),e[3]=i,e[4]=a):a=e[4];let u;e[5]!==i?(u=i("sessions.sidebar.session.status.unread"),e[5]=i,e[6]=u):u=e[6];let d;return e[7]!==l||e[8]!==a||e[9]!==u?(d=s.jsx(om,{state:l,activeLabel:a,unreadLabel:u}),e[7]=l,e[8]=a,e[9]=u,e[10]=d):d=e[10],d},T0=t=>{const e=Xe.c(82),{folder:n,displayName:r,sessions:i,subFolderItems:o,isCollapsed:l,collapsedActivityState:a,onToggle:u,onRename:d,onDelete:h,children:f,mobileVariant:g,alwaysShowActions:p,isRenaming:w,renameDraft:v,onRenameDraftChange:x,onRenameSave:m,onRenameCancel:b,droppableRef:y,isDropTarget:S,onNewSession:N,depth:C,hideActions:k,archivedBucket:A}=t,D=a===void 0?null:a,F=p===void 0?g===void 0?!1:g:p,W=w===void 0?!1:w,E=v===void 0?"":v,H=S===void 0?!1:S,z=k===void 0?!1:k,B=A===void 0?!1:A,{t:T}=pt(),[j,I]=c.useState(!1),[_,K]=c.useState(""),G=c.useRef(null),Q=W||j,ge=W?E:_;let se;e[0]!==n.name?(se=()=>{K(n.name),I(!0)},e[0]=n.name,e[1]=se):se=e[1];const Y=se;let te;e[2]!==ge||e[3]!==n.name||e[4]!==W||e[5]!==d||e[6]!==m?(te=()=>{const Ce=ge.trim();Ce&&Ce!==n.name&&d(Ce),W&&m&&m(),I(!1),K("")},e[2]=ge,e[3]=n.name,e[4]=W,e[5]=d,e[6]=m,e[7]=te):te=e[7];const he=te;let L;e[8]!==W||e[9]!==b?(L=()=>{W&&b&&b(),I(!1),K("")},e[8]=W,e[9]=b,e[10]=L):L=e[10];const le=L;let Z;e[11]!==W||e[12]!==x?(Z=Ce=>{W&&x?x(Ce):K(Ce)},e[11]=W,e[12]=x,e[13]=Z):Z=e[13];const ue=Z;let V,ee;e[14]!==W?(V=()=>{if(!W)return;const Ce=()=>{const Me=G.current;Me&&(Me.focus(),Me.select())},q=requestAnimationFrame(Ce),Ee=window.setTimeout(Ce,0);return()=>{cancelAnimationFrame(q),window.clearTimeout(Ee)}},ee=[W],e[14]=W,e[15]=V,e[16]=ee):(V=e[15],ee=e[16]),c.useEffect(V,ee);const be=l?"folder":"folder-open",xe=H&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Ne;e[17]!==xe?(Ne=Te("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",xe),e[17]=xe,e[18]=Ne):Ne=e[18];let Pe;e[19]!==u||e[20]!==Q?(Pe=Q?void 0:Ce=>{Ce.currentTarget.blur(),u()},e[19]=u,e[20]=Q,e[21]=Pe):Pe=e[21];const Se=Q?void 0:"button",Re=Q?void 0:0;let ye;e[22]!==u||e[23]!==Q?(ye=Q?void 0:Ce=>{(Ce.key==="Enter"||Ce.key===" ")&&(Ce.preventDefault(),u())},e[22]=u,e[23]=Q,e[24]=ye):ye=e[24];let pe;e[25]!==n.name||e[26]!==l||e[27]!==T?(pe=l?T("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):T("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=l,e[27]=T,e[28]=pe):pe=e[28];const me=B?F?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":F?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let je;e[29]!==me?(je=Te("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",me),e[29]=me,e[30]=je):je=e[30];const ne=H?"text-primary":"text-muted-foreground";let fe;e[31]!==ne?(fe=Te("h-3.5 w-3.5 flex-shrink-0",ne),e[31]=ne,e[32]=fe):fe=e[32];let ce;e[33]!==be||e[34]!==fe?(ce=s.jsx(M,{name:be,className:fe}),e[33]=be,e[34]=fe,e[35]=ce):ce=e[35];let R;e[36]!==D||e[37]!==r||e[38]!==ge||e[39]!==n.name||e[40]!==le||e[41]!==ue||e[42]!==he||e[43]!==l||e[44]!==H||e[45]!==Q||e[46]!==i||e[47]!==T?(R=Q?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:E0,onMouseDown:M0,onSubmit:Ce=>{Ce.preventDefault(),he()},children:[s.jsx("input",{ref:G,value:ge,onChange:Ce=>ue(Ce.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:T("sessions.sidebar.folderItem.namePlaceholder"),onClick:O0,onPointerDown:F0,onMouseDown:B0,onKeyDown:Ce=>{if(Ce.key==="Escape"){Ce.stopPropagation(),le();return}(Ce.key===" "||Ce.key==="Enter")&&Ce.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:_0,onPointerDown:L0,onMouseDown:$0,children:s.jsx(M,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),le()},onPointerDown:W0,onMouseDown:z0,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("span",{className:Te("typography-ui-label font-semibold truncate",H?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(bt,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",i.length]}),D?s.jsx(om,{state:D,activeLabel:T("sessions.sidebar.session.status.active"),unreadLabel:T("sessions.sidebar.session.status.unread")}):null,l?s.jsx(M,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=D,e[37]=r,e[38]=ge,e[39]=n.name,e[40]=le,e[41]=ue,e[42]=he,e[43]=l,e[44]=H,e[45]=Q,e[46]=i,e[47]=T,e[48]=R):R=e[48];let $;e[49]!==je||e[50]!==ce||e[51]!==R?($=s.jsxs("div",{className:je,children:[ce,R]}),e[49]=je,e[50]=ce,e[51]=R,e[52]=$):$=e[52];let de;e[53]!==F||e[54]!==B||e[55]!==n.name||e[56]!==Y||e[57]!==z||e[58]!==h||e[59]!==N||e[60]!==Q||e[61]!==T?(de=!Q&&(!z||B)?s.jsx("div",{className:Te("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",F?"opacity-100":"opacity-0 pointer-events-none group-hover/folder:opacity-100 group-hover/folder:pointer-events-auto group-focus-within/folder:opacity-100 group-focus-within/folder:pointer-events-auto"),children:s.jsxs("div",{className:"flex items-center gap-0.5",children:[!B&&N?s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),N()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":T("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:T("sessions.sidebar.project.actions.newSession"),children:s.jsx(M,{name:"add",className:"h-3.5 w-3.5"})}):null,B?null:s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),Y()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":T("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(M,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Ce=>{Ce.stopPropagation(),h()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B?T("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):T("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(M,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=F,e[54]=B,e[55]=n.name,e[56]=Y,e[57]=z,e[58]=h,e[59]=N,e[60]=Q,e[61]=T,e[62]=de):de=e[62];let ie;e[63]!==y||e[64]!==Ne||e[65]!==Pe||e[66]!==Se||e[67]!==Re||e[68]!==ye||e[69]!==pe||e[70]!==$||e[71]!==de?(ie=s.jsxs("div",{ref:y,className:Ne,onClick:Pe,role:Se,tabIndex:Re,onKeyDown:ye,"aria-label":pe,children:[$,de]}),e[63]=y,e[64]=Ne,e[65]=Pe,e[66]=Se,e[67]=Re,e[68]=ye,e[69]=pe,e[70]=$,e[71]=de,e[72]=ie):ie=e[72];let Ae;e[73]!==f||e[74]!==l||e[75]!==i||e[76]!==o||e[77]!==T?(Ae=l?null:s.jsxs("div",{className:"pb-1",children:[o,i.length>0?f:o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:T("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=f,e[74]=l,e[75]=i,e[76]=o,e[77]=T,e[78]=Ae):Ae=e[78];let Be;return e[79]!==ie||e[80]!==Ae?(Be=s.jsxs("div",{className:"oc-folder",children:[ie,Ae]}),e[79]=ie,e[80]=Ae,e[81]=Be):Be=e[81],Be},R0=c.memo(T0);function E0(t){return t.stopPropagation()}function M0(t){return t.stopPropagation()}function O0(t){return t.stopPropagation()}function F0(t){return t.stopPropagation()}function B0(t){return t.stopPropagation()}function _0(t){return t.stopPropagation()}function L0(t){return t.stopPropagation()}function $0(t){return t.stopPropagation()}function W0(t){return t.stopPropagation()}function z0(t){return t.stopPropagation()}const V0=t=>{const e=Xe.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:o}=t,l=`session-drag:${n}`;let a;e[0]!==r||e[1]!==n||e[2]!==i?(a={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:i},e[0]=r,e[1]=n,e[2]=i,e[3]=a):a=e[3];let u;e[4]!==l||e[5]!==a?(u={id:l,data:a},e[4]=l,e[5]=a,e[6]=u):u=e[6];const{attributes:d,listeners:h,setNodeRef:f,isDragging:g}=fg(u);let p;e[7]!==h?(p=m=>{m.stopPropagation(),h?.onPointerDown&&h.onPointerDown(m)},e[7]=h,e[8]=p):p=e[8];const w=p,v=g?"opacity-30":void 0;let x;return e[9]!==d||e[10]!==o||e[11]!==w||e[12]!==f||e[13]!==v?(x=s.jsx("div",{ref:f,...d,onPointerDown:w,className:v,children:o}),e[9]=d,e[10]=o,e[11]=w,e[12]=f,e[13]=v,e[14]=x):x=e[14],x},U0=t=>{const e=Xe.c(11),{folderId:n,children:r}=t,i=`folder-drop:${n}`;let o;e[0]!==n?(o={type:"folder",folderId:n},e[0]=n,e[1]=o):o=e[1];let l;e[2]!==i||e[3]!==o?(l={id:i,data:o},e[2]=i,e[3]=o,e[4]=l):l=e[4];const{setNodeRef:a,isOver:u}=hg(l);let d;e[5]!==r||e[6]!==u||e[7]!==a?(d=r(a,u),e[5]=r,e[6]=u,e[7]=a,e[8]=d):d=e[8];let h;return e[9]!==d?(h=s.jsx(s.Fragment,{children:d}),e[9]=d,e[10]=h):h=e[10],h},K0=t=>{const e=Xe.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:i,children:o}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const a=Lr(En(Fi,l)),[u,d]=c.useState(null),[h,f]=c.useState("Session"),[g,p]=c.useState(null),[w,v]=c.useState(null);if(!n){let k;return e[1]!==o?(k=s.jsx(s.Fragment,{children:o}),e[1]=o,e[2]=k):k=e[2],k}let x;e[3]!==i?(x=k=>{d(null),p(null),v(null);const{active:A,over:D}=k;if(!D)return;const P=A.data.current,F=D.data.current;P?.type==="session"&&P.sessionId&&F?.type==="folder"&&F.folderId&&i(P.sessionId,F.folderId)},e[3]=i,e[4]=x):x=e[4];const m=x;let b,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=k=>{const A=k.active.data.current;if(A?.type==="session"&&A.sessionId){d(A.sessionId),f(A.sessionTitle??"Session");const D=k.active.rect.current.initial?.width,P=k.active.rect.current.initial?.height;p(typeof D=="number"?D:null),v(typeof P=="number"?P:null)}},y=()=>{d(null),p(null),v(null)},e[5]=b,e[6]=y):(b=e[5],y=e[6]);let S;e[7]!==w||e[8]!==u||e[9]!==h||e[10]!==g||e[11]!==r?(S=u&&r?s.jsxs("div",{style:{width:g?`${g}px`:"auto",height:w?`${w}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(M,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:h})]}):null,e[7]=w,e[8]=u,e[9]=h,e[10]=g,e[11]=r,e[12]=S):S=e[12];let N;e[13]!==S?(N=s.jsx(Bi,{children:S}),e[13]=S,e[14]=N):N=e[14];let C;return e[15]!==o||e[16]!==m||e[17]!==a||e[18]!==N?(C=s.jsxs($r,{sensors:a,collisionDetection:Wr,onDragStart:b,onDragCancel:y,onDragEnd:m,children:[o,N]}),e[15]=o,e[16]=m,e[17]=a,e[18]=N,e[19]=C):C=e[19],C},ta=(t,e,n)=>{if(!e)return;const r=i=>{let o=i.session.id===e;for(const l of i.children)o=r(l)||o;return o&&n.add(i.session.id),o};for(const i of t)r(i)},Gn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Gn(n,e))return!0;return!1},H0=({isSubtaskSession:t,archivedBucket:e,isVSCode:n,sessionDirectory:r})=>!t&&!e&&!n&&!rh(r),G0=({sessionDirectory:t,isStreaming:e,isMovingToWorktree:n})=>!t||e||n,q0=(t,e,n)=>{const r=new Map,i=o=>{const l=_s(o.session)??ct(o.worktree?.path)??n;if(l){const a=r.get(l)??[];a.push(o.session.id),r.set(l,a)}if(!(o===t&&e))for(const a of o.children)i(a)};return i(t),[...r].map(([o,l])=>({directory:o,sessionIDs:l}))},Q0=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const i=new Set;let o=r.session.parentID??null;for(;o&&!i.has(o);){if(n.has(o)&&e.has(o))return!1;i.add(o),o=e.get(o)?.session?.parentID??null}return!0})},Y0=t=>{const e=new Map(t.map(l=>[l.id,l])),n=new Map;for(const l of t){if(!l.parentId||!e.has(l.parentId))continue;const a=n.get(l.parentId)??[];a.push(l),n.set(l.parentId,a)}const r=new Set,i=[],o=l=>{if(r.has(l.id))return;i.push(l);const a=[l.id];for(;a.length>0;){const u=a.pop();if(!(!u||r.has(u))){r.add(u);for(const d of n.get(u)??[])a.push(d.id)}}};return t.forEach(l=>{(!l.parentId||!e.has(l.parentId))&&o(l)}),t.forEach(o),i},X0=(t,e)=>{const n=new Map(t.map(u=>[u.id,u])),r=new Map,i=new Set;for(const u of t){if(u.parentId&&!n.has(u.parentId)){i.add(u.id);continue}if(u.parentId){const f=r.get(u.parentId)??[];f.push(u.id),r.set(u.parentId,f)}const d=new Set;let h=u.id;for(;h;){if(d.has(h)){i.add(u.id);break}d.add(h),h=n.get(h)?.parentId}}const o=new Set,l=new Set,a=u=>{if(o.has(u))return!0;if(l.has(u))return!1;const d=n.get(u);if(!d)return!1;l.add(u);let h=i.has(u);return!h&&e.archivedBucket&&d.nodeCount===0?h=(r.get(u)??[]).some(a):(!h&&!e.searchQuery&&(h=!0),!h&&(d.nodeCount>0||Io([d.name],e.searchQuery))&&(h=!0),h||(h=(r.get(u)??[]).some(a))),l.delete(u),h&&o.add(u),h};return t.forEach(u=>a(u.id)),new Set(t.filter(u=>o.has(u.id)).map(u=>u.id))},hc=new WeakMap;let pc=1;const J0=t=>{const e=hc.get(t);if(e!==void 0)return e;const n=pc;return pc+=1,hc.set(t,n),n},Wo=t=>t.children.length===0?"":t.children.map(n=>{const r=J0(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${Wo(n)}`}).join("|"),im=(t,e,n,r,i,o)=>{const l=Ss(),a=(u,d)=>{if(u.session.id!==d.session.id||u.children.length!==d.children.length)return!0;const h=u.session.directory??i,f=d.session.directory??o,g=sl(l,h??"",u.session.id),p=sl(l,f??"",d.session.id);return(g?n.has(g):!1)!==(p?r.has(p):!1)?!0:u.children.some((w,v)=>a(w,d.children[v]))};return a(t,e)},Z0=t=>t.actionsAlwaysVisible?"":`transition-opacity duration-150 ${t.menuOpen?"opacity-0":t.hideOnHoverClass}`,Kr=(t,e,n,r)=>{if(!e)return null;const i=r?"archived":"active";let o=null;const l=a=>{if(`${n}:${i}:${a.session.id}`===e)return o=a.session.id,!0;for(const d of a.children)if(l(d))return!0;return!1};return t.forEach(a=>l(a)),o};let sa=!1;const na=new Set;let gc=!1;function ej(){for(const t of na)t()}function Wa(t){sa!==t&&(sa=t,ej())}function tj(t){t.key==="Shift"&&Wa(!0)}function sj(t){t.key==="Shift"&&Wa(!1)}function nj(){Wa(!1)}function rj(){gc||typeof window>"u"||(gc=!0,window.addEventListener("keydown",tj),window.addEventListener("keyup",sj),window.addEventListener("blur",nj))}function oj(t){return rj(),na.add(t),()=>{na.delete(t)}}function ij(){return sa}function aj(){return!1}function lj(){return it.useSyncExternalStore(oj,ij,aj)}const cj=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,am=/^g[1-9]\d*$/,Cr=(t,e,n,r,i)=>{if(!cj.test(t)||e!==void 0&&!am.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(i===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(i==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:o,fusion:!1}},ko=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Cr(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,u,d]=e;return am.test(a)?Cr(n,a,u,d,void 0):Cr(n,void 0,a,u,d)}const[,r,i,o,l]=e;return r===""?Cr(n,void 0,i,o,l):Cr(n,r,i,o,l)},dj=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},uj=(t,e,n,r)=>{const i=[t];return r&&i.push(r),i.push(e,n,"fusion"),i.join("/")},lm=t=>{const e=Xe.c(36),{value:n,onChange:r,className:i,disabled:o,id:l,portalToBody:a}=t,{t:u}=pt(),d=Ut(mj),h=Ut(fj),f=Ut(hj);let g;e[0]!==d?(g=d(),e[0]=d,e[1]=g):g=e[1];const p=g;let w;e[2]!==p?(w=p.filter(pj),e[2]=p,e[3]=w):w=e[3];const v=w;let x,m;e[4]!==p.length||e[5]!==h?(x=()=>{p.length===0&&h()},m=[p.length,h],e[4]=p.length,e[5]=h,e[6]=x,e[7]=m):(x=e[6],m=e[7]),c.useEffect(x,m);let b,y;e[8]!==f||e[9]!==o||e[10]!==r||e[11]!==v||e[12]!==n?(b=()=>{if(o)return;const W=n.trim();if(W.length>0&&v.some(z=>z.name===W))return;const E=typeof f=="string"&&f.trim().length>0?f.trim():null;if(E&&v.some(z=>z.name===E)){r(E);return}const H=v[0]?.name;H&&r(H)},y=[f,o,r,v,n],e[8]=f,e[9]=o,e[10]=r,e[11]=v,e[12]=n,e[13]=b,e[14]=y):(b=e[13],y=e[14]),c.useEffect(b,y);const S=n.trim().length>0?n:void 0;let N;e[15]!==i?(N=Te("max-w-full",i),e[15]=i,e[16]=N):N=e[16];let C;e[17]!==u?(C=u("multirun.agentSelector.placeholder"),e[17]=u,e[18]=C):C=e[18];let k;e[19]!==C?(k=s.jsx(Cs,{placeholder:C}),e[19]=C,e[20]=k):k=e[20];let A;e[21]!==l||e[22]!==N||e[23]!==k?(A=s.jsx(Os,{id:l,size:"lg",className:N,children:k}),e[21]=l,e[22]=N,e[23]=k,e[24]=A):A=e[24];let D;e[25]!==v?(D=v.length>0&&s.jsx(Ii,{children:v.map(gj)}),e[25]=v,e[26]=D):D=e[26];let P;e[27]!==a||e[28]!==D?(P=s.jsx(Fs,{fitContent:!0,portalToBody:a,children:D}),e[27]=a,e[28]=D,e[29]=P):P=e[29];let F;return e[30]!==o||e[31]!==r||e[32]!==S||e[33]!==A||e[34]!==P?(F=s.jsxs(Ms,{value:S,onValueChange:r,disabled:o,children:[A,P]}),e[30]=o,e[31]=r,e[32]=S,e[33]=A,e[34]=P,e[35]=F):F=e[35],F};function mj(t){return t.getVisibleAgents}function fj(t){return t.loadAgents}function hj(t){return t.currentAgentName}function pj(t){return Ed(t.mode)}function gj(t){return s.jsx(es,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const xj="h-7",Or=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,bj=t=>{const e=Xe.c(12),{model:n,instanceIndex:r,totalSameModel:i,onRemove:o}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,a=i>1?`${l} (${r})`:l;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Te("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",xj),e[0]=u):u=e[0];let d;e[1]!==n.providerID?(d=s.jsx(Ti,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=d):d=e[2];let h;e[3]!==a?(h=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:a}),e[3]=a,e[4]=h):h=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(M,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let g;e[6]!==o?(g=s.jsx("button",{type:"button",onClick:o,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=o,e[7]=g):g=e[7];let p;return e[8]!==d||e[9]!==h||e[10]!==g?(p=s.jsxs("div",{className:u,children:[d,h,g]}),e[8]=d,e[9]=h,e[10]=g,e[11]=p):p=e[11],p},cm=t=>{const e=Xe.c(120),{selectedModels:n,onAdd:r,onRemove:i,onUpdate:o,minModels:l,addButtonLabel:a,showChips:u,maxModels:d,addButtonClassName:h,dropdownSide:f,dropdownClassName:g,containerClassName:p,triggerIcon:w}=t,v=u===void 0?!0:u,x=f===void 0?"top":f,{t:m}=pt(),b=Ut(yj),y=Ut(wj),S=De(Sj),N=De(vj),{favoriteModelsList:C,recentModelsList:k}=oh(),A=De(jj),D=De(kj),[P,F]=c.useState(!1),[W,E]=c.useState(""),[H,z]=c.useState(null),B=c.useRef(null),T=c.useRef(null),j=d===1,I=d===void 0||n.length<d||j;let _;if(e[0]!==n){_=new Map;for(const we of n){const Ve=`${we.providerID}:${we.modelID}`;_.set(Ve,(_.get(Ve)||0)+1)}e[0]=n,e[1]=_}else _=e[1];const K=_;let G;e[2]!==n?(G=we=>n.filter(st=>st.providerID===we.providerID&&st.modelID===we.modelID).findIndex(st=>st.instanceId===we.instanceId)+1,e[2]=n,e[3]=G):G=e[3];const Q=G;let ge,se;e[4]!==x||e[5]!==P?(ge=()=>{if(!P||!T.current)return;const we=T.current.getBoundingClientRect();if(x==="bottom"){const ve=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-we.bottom-16-112;z(Math.max(160,Math.min(320,ve)));return}let Ve=T.current.parentElement;for(;Ve&&!Ve.matches('[role="dialog"], [data-scroll-shadow-scroller]');){const ae=getComputedStyle(Ve);if(ae.overflow==="auto"||ae.overflow==="hidden"||ae.overflowY==="auto"||ae.overflowY==="hidden")break;Ve=Ve.parentElement}const st=Ve?Ve.getBoundingClientRect().top:0,Ge=we.top-st-16;z(Math.max(150,Math.min(300,Ge)))},se=[x,P],e[4]=x,e[5]=P,e[6]=ge,e[7]=se):(ge=e[6],se=e[7]),c.useEffect(ge,se);let Y,te;e[8]!==I||e[9]!==P?(Y=()=>{!I&&P&&(F(!1),E(""))},te=[I,P],e[8]=I,e[9]=P,e[10]=Y,e[11]=te):(Y=e[10],te=e[11]),c.useEffect(Y,te);let he,L;e[12]!==P?(he=()=>{if(!P)return;const we=Ve=>{B.current&&!B.current.contains(Ve.target)&&(F(!1),E(""))};return document.addEventListener("mousedown",we),()=>document.removeEventListener("mousedown",we)},L=[P],e[12]=P,e[13]=he,e[14]=L):(he=e[13],L=e[14]),c.useEffect(he,L);let le;e[15]!==j||e[16]!==r||e[17]!==o||e[18]!==n.length?(le=we=>{const Ve={providerID:we.providerID,modelID:we.modelID,displayName:we.model.name||we.modelID,instanceId:Or()};j&&n.length>0&&o?o(0,Ve):r(Ve),j&&(F(!1),E(""))},e[15]=j,e[16]=r,e[17]=o,e[18]=n.length,e[19]=le):le=e[19];const Z=le;let ue;e[20]!==m?(ue=m("multirun.modelMultiSelect.search.placeholder"),e[20]=m,e[21]=ue):ue=e[21];let V;e[22]!==m?(V=m("multirun.modelMultiSelect.search.noResults"),e[22]=m,e[23]=V):V=e[23];let ee;e[24]!==m?(ee=m("multirun.modelMultiSelect.sections.favorites"),e[24]=m,e[25]=ee):ee=e[25];let be;e[26]!==m?(be=m("multirun.modelMultiSelect.sections.recent"),e[26]=m,e[27]=be):be=e[27];let xe;e[28]!==m?(xe=m("multirun.modelMultiSelect.keyboard.hint"),e[28]=m,e[29]=xe):xe=e[29];let Ne;e[30]!==m?(Ne=m("settings.agents.modelSelector.actions.favorite"),e[30]=m,e[31]=Ne):Ne=e[31];let Pe;e[32]!==m?(Pe=m("settings.agents.modelSelector.actions.unfavorite"),e[32]=m,e[33]=Pe):Pe=e[33];let Se;e[34]!==m?(Se=m("chat.modelControls.capabilities"),e[34]=m,e[35]=Se):Se=e[35];let Re;e[36]!==m?(Re=m("chat.modelControls.capability.toolCalling"),e[36]=m,e[37]=Re):Re=e[37];let ye;e[38]!==m?(ye=m("chat.modelControls.capability.reasoning"),e[38]=m,e[39]=ye):ye=e[39];let pe;e[40]!==m?(pe=m("chat.modelControls.input"),e[40]=m,e[41]=pe):pe=e[41];let me;e[42]!==m?(me=m("chat.modelControls.output"),e[42]=m,e[43]=me):me=e[43];let je;e[44]!==m?(je=m("chat.modelControls.costPerMillion"),e[44]=m,e[45]=je):je=e[45];let ne;e[46]!==ue||e[47]!==V||e[48]!==ee||e[49]!==be||e[50]!==xe||e[51]!==Ne||e[52]!==Pe||e[53]!==Se||e[54]!==Re||e[55]!==ye||e[56]!==pe||e[57]!==me||e[58]!==je?(ne={searchPlaceholder:ue,noResults:V,favorites:ee,recent:be,keyboardHint:xe,favorite:Ne,unfavorite:Pe,capabilities:Se,capabilityToolCalling:Re,capabilityReasoning:ye,input:pe,output:me,costPerMillion:je},e[46]=ue,e[47]=V,e[48]=ee,e[49]=be,e[50]=xe,e[51]=Ne,e[52]=Pe,e[53]=Se,e[54]=Re,e[55]=ye,e[56]=pe,e[57]=me,e[58]=je,e[59]=ne):ne=e[59];const fe=ne;let ce;e[60]!==p?(ce=Te("relative",p),e[60]=p,e[61]=ce):ce=e[61];const R=P?"":void 0;let $;e[62]!==h?($=Te(Md({size:"default"}),"w-fit",h),e[62]=h,e[63]=$):$=e[63];const de=!I;let ie;e[64]!==P?(ie=()=>{F(!P)},e[64]=P,e[65]=ie):ie=e[65];let Ae;e[66]!==w?(Ae=w??s.jsx(M,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=w,e[67]=Ae):Ae=e[67];let Be;e[68]!==a||e[69]!==m?(Be=a??m("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=m,e[70]=Be):Be=e[70];let Ce;e[71]!==R||e[72]!==$||e[73]!==de||e[74]!==ie||e[75]!==Ae||e[76]!==Be?(Ce=s.jsxs("button",{ref:T,type:"button","data-popup-open":R,className:$,disabled:de,onClick:ie,children:[Ae,Be]}),e[71]=R,e[72]=$,e[73]=de,e[74]=ie,e[75]=Ae,e[76]=Be,e[77]=Ce):Ce=e[77];let q;e[78]!==H||e[79]!==I||e[80]!==g||e[81]!==x||e[82]!==C||e[83]!==Z||e[84]!==A||e[85]!==N||e[86]!==P||e[87]!==fe||e[88]!==K||e[89]!==y||e[90]!==D||e[91]!==b||e[92]!==k||e[93]!==W||e[94]!==S?(q=P?s.jsx("div",{className:Te("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",x==="top"?"bottom-full mb-1":"top-full mt-1",g),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(ih,{providers:b,providerOrder:D,favoriteModels:C,recentModels:k,modelsMetadata:y,hiddenModels:A,searchQuery:W,onSearchQueryChange:E,onSelect:Z,labels:fe,selectionCount:we=>K.get(`${we.providerID}:${we.modelID}`)||0,disabled:!I,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:H?`${H}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:P,isFavorite:we=>N(we.providerID,we.modelID),onToggleFavorite:we=>S(we.providerID,we.modelID),onEscape:()=>{F(!1),E("")}})}):null,e[78]=H,e[79]=I,e[80]=g,e[81]=x,e[82]=C,e[83]=Z,e[84]=A,e[85]=N,e[86]=P,e[87]=fe,e[88]=K,e[89]=y,e[90]=D,e[91]=b,e[92]=k,e[93]=W,e[94]=S,e[95]=q):q=e[95];let Ee;e[96]!==ce||e[97]!==Ce||e[98]!==q?(Ee=s.jsxs("div",{className:ce,ref:B,children:[Ce,q]}),e[96]=ce,e[97]=Ce,e[98]=q,e[99]=Ee):Ee=e[99];let Me;e[100]!==Q||e[101]!==K||e[102]!==i||e[103]!==o||e[104]!==b||e[105]!==n||e[106]!==v||e[107]!==m?(Me=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((we,Ve)=>{const st=`${we.providerID}:${we.modelID}`,Ge=K.get(st)||1,ae=Q(we),ve=b.find(We=>We.id===we.providerID)?.models?.find(We=>We.id===we.modelID),Le=ve?.variants?Object.keys(ve.variants):[],$e=Le.length>0,Ue=we.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(bj,{model:we,instanceIndex:ae,totalSameModel:Ge,onRemove:()=>i(Ve)}),$e&&s.jsxs(Ms,{value:Ue,onValueChange:We=>{if(!o)return;o(Ve,{...we,variant:We==="__default__"?void 0:We})},children:[s.jsxs(Os,{size:"sm",className:"gap-1.5",children:[s.jsx(M,{name:"brain-ai-3",className:Te("h-3.5 w-3.5 flex-shrink-0",Ue==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Cs,{placeholder:m("multirun.modelMultiSelect.variant.placeholder"),children:We=>We==="__default__"?m("multirun.modelMultiSelect.variant.default"):We})]}),s.jsxs(Fs,{fitContent:!0,children:[s.jsx(es,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:m("multirun.modelMultiSelect.variant.default")}),Le.map(Cj)]})]})]},we.instanceId)})}),e[100]=Q,e[101]=K,e[102]=i,e[103]=o,e[104]=b,e[105]=n,e[106]=v,e[107]=m,e[108]=Me):Me=e[108];let O;e[109]!==Ee||e[110]!==Me?(O=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Ee,Me]}),e[109]=Ee,e[110]=Me,e[111]=O):O=e[111];let oe;e[112]!==d||e[113]!==l||e[114]!==n.length||e[115]!==m?(oe=l!==void 0&&n.length<l&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:d!==void 0?m("multirun.modelMultiSelect.validation.minToMax",{min:l,max:d}):m("multirun.modelMultiSelect.validation.minOnly",{min:l})}),e[112]=d,e[113]=l,e[114]=n.length,e[115]=m,e[116]=oe):oe=e[116];let re;return e[117]!==O||e[118]!==oe?(re=s.jsxs("div",{className:"space-y-2",children:[O,oe]}),e[117]=O,e[118]=oe,e[119]=re):re=e[119],re};function yj(t){return t.providers}function wj(t){return t.modelsMetadata}function Sj(t){return t.toggleFavoriteModel}function vj(t){return t.isFavoriteModel}function jj(t){return t.hiddenModels}function kj(t){return t.providerOrder}function Cj(t){return s.jsx(es,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const Nj=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
913
|
-
|
|
914
|
-
--- RESULT ${n+1}: ${r} ---
|
|
915
|
-
${e.trim()}
|
|
916
|
-
--- END RESULT ${n+1} ---`},xc=(t,e)=>Qe.getState().getWorktreeMetadata(t)?.projectDirectory??e,Aj=async t=>{const e=t.directory??void 0,n=lh(t.session.id,e);if(n.length===0&&t.directory){const i=(await Qs.withDirectory(t.directory,()=>Qs.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let o=i.length-1;o>=0;o-=1){const l=i[o];if(l.info?.role==="assistant")return rl(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return rl(ch(i.id,e)).trim()}return""};function Dj({session:t,open:e,onOpenChange:n}){const{t:r}=pt(),i=ah(),o=As(j=>j.activeSessions),l=As(j=>j.archivedSessions),a=Ut(j=>j.providers),u=Ut(j=>j.currentProviderId),d=Ut(j=>j.currentModelId),h=Ut(j=>j.currentAgentName),[f,g]=c.useState(u??""),[p,w]=c.useState(d??""),[v,x]=c.useState(()=>u&&d?[{providerID:u,modelID:d,instanceId:Or()}]:[]),[m,b]=c.useState(""),[y,S]=c.useState(h??""),[N,C]=c.useState([]),[k,A]=c.useState(!1),D=c.useMemo(()=>ko(t.title),[t.title]),P=c.useMemo(()=>{const j=new Map;for(const I of i)j.set(I.id,I);for(const I of o)j.set(I.id,I);for(const I of l)j.set(I.id,I);return t.id&&j.set(t.id,t),Array.from(j.values())},[o,l,i,t]);c.useEffect(()=>{if(!e||!D)return;const j=Qe.getState().getDirectoryForSession(t.id),I=xc(t.id,j),_=P.map(K=>{const G=ko(K.title);if(!G||G.groupSlug!==D.groupSlug||G.fusion||(G.runGroup??null)!==(D.runGroup??null))return null;const Q=Qe.getState().getDirectoryForSession(K.id)??_s(K),ge=xc(K.id,Q);return I&&ge&&I!==ge?null:{session:K,directory:Q,projectDirectory:ge}}).filter(K=>K!==null).sort((K,G)=>(K.session.time?.created??0)-(G.session.time?.created??0));C(_)},[P,e,D,t.id]);const W=a.find(j=>j.id===f)?.models.find(j=>j.id===p),E=W?.variants?Object.keys(W.variants):[],H=!!(D&&f&&p&&N.length>0&&!k),z=c.useCallback(j=>{x([j]),g(j.providerID),w(j.modelID),b("")},[]),B=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),T=async()=>{if(!(!D||!f||!p)){A(!0);try{const j=await Promise.all(N.map(se=>Aj(se))),I=N.map((se,Y)=>({source:se,text:j[Y]??""})).filter(se=>se.text.trim().length>0);if(I.length===0){Fe.error(r("multirun.fusion.toast.noOutputs"));return}const _=N[0]?.projectDirectory??N[0]?.directory??null,K=uj(D.groupSlug,f,p,D.runGroup),[G,Q]=await Promise.all([nl("session.fusion.visible"),nl("session.fusion.instructions")]),ge=await Qe.getState().createSession(K,_,null);if(!ge)throw new Error("Failed to create fusion session");Qe.getState().setCurrentSession(ge.id,_),n(!1),await Qs.sendMessage({id:ge.id,providerID:f,modelID:p,variant:m||void 0,agent:y||void 0,text:G,additionalParts:[{text:Q,synthetic:!0},...I.map((se,Y)=>({text:Nj(se.source,se.text,Y),synthetic:!0})),{text:`
|
|
917
|
-
|
|
918
|
-
--- FUSION INPUTS END ---
|
|
919
|
-
Now write the final fused answer.`,synthetic:!0}],directory:_??Qs.getDirectory()})}catch(j){console.error("[MultiRunFusion] Failed to start fusion",j),Fe.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(vs,{open:e,onOpenChange:n,children:s.jsxs(js,{className:"max-w-xl overflow-visible",children:[s.jsxs(Ls,{children:[s.jsx(Ds,{children:r("multirun.fusion.title")}),s.jsx(Ps,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(cm,{selectedModels:v,onAdd:z,onUpdate:(j,I)=>z(I),onRemove:()=>{x([]),g(""),w(""),b("")},maxModels:1,addButtonLabel:B,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(Ti,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(Ms,{value:m||"__default__",onValueChange:j=>b(j==="__default__"?"":j),children:[s.jsxs(Os,{size:"lg",className:"w-fit",children:[s.jsx(M,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Cs,{children:j=>j==="__default__"?r("multirun.modelMultiSelect.variant.default"):j})]}),s.jsxs(Fs,{fitContent:!0,portalToBody:!0,children:[s.jsx(es,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(j=>s.jsx(es,{value:j,children:j},j))]})]}):null,s.jsx(lm,{value:y,onChange:S,portalToBody:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:N.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:N.map(j=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Ti,{providerId:ko(j.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.session.title||j.session.id}),s.jsx("button",{type:"button",onClick:()=>C(I=>I.filter(_=>_.session.id!==j.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"h-4 w-4"})})]},j.session.id))})]}),s.jsxs(gn,{children:[s.jsx(at,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(at,{onClick:T,disabled:!H,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function Pj(t){const e=Xe.c(7);let n,r,i,o,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=o,e[4]=l):(n=e[0],r=e[1],i=e[2],o=e[3],l=e[4]);let a;return e[5]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,o,l]}),e[5]=t,e[6]=a):a=e[6],a}const Ij=(t,e)=>(t.current.runtimeKey!==e||(t.current={...t.current,revision:t.current.revision+1}),t.current.revision),dm=t=>new Map([...t.entries()].map(([e,n])=>[e,n.map(r=>Hr(r))])),ra=t=>((t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey||t.rawWorktreesByProjectRef.current.worktreesByProject.size===0&&t.publishedWorktreesByProject.size>0)&&(t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.rawWorktreesByProjectRef.current.runtimeKey===t.runtimeKey?t.rawWorktreesByProjectRef.current.revision:0,worktreesByProject:dm(t.publishedWorktreesByProject)}),t.rawWorktreesByProjectRef.current),um=(t,e)=>{const n=t.metadata.branch||t.metadata.name||t.metadata.label||t.metadata.path,r=e.metadata.branch||e.metadata.name||e.metadata.label||e.metadata.path,i=n.localeCompare(r,void 0,{sensitivity:"base"});return i!==0?i:t.metadata.path.localeCompare(e.metadata.path,void 0,{sensitivity:"base"})},bc=t=>{const e=t.split("/").filter(Boolean);return e[e.length-1]??t},Hr=t=>({...t,path:ct(t.path)??t.path,projectDirectory:ct(t.projectDirectory)??t.projectDirectory,worktreeRoot:ct(t.worktreeRoot??t.path)??t.worktreeRoot}),yc=t=>{const{currentWorktree:e,path:n,projectDirectory:r,projectRootBranch:i}=t,l=ct(e?.path??null)===n,a=l?e?.branch??"":i??"",u={path:n,projectDirectory:r,branch:a,label:l?e?.label||e?.branch||e?.name||bc(n):i||bc(n),name:l?e?.name:void 0,worktreeRoot:l?ct(e?.worktreeRoot??n)??n:n,worktreeStatus:l?e?.worktreeStatus??"ready":"ready",worktreeSource:l?e?.worktreeSource??"existing":"existing",headState:l?e?.headState:i?"branch":void 0};return l&&e?{...e,...u}:u},wc=t=>{const e=ct(t.projectPath??null),n=ct(t.sourceDirectory??null)??ct(t.currentWorktree?.path??null),r=ct(t.discoveredWorktrees.find(h=>ct(h.projectDirectory??null))?.projectDirectory??null),i=ct(t.currentWorktree?.projectDirectory??null),o=r??i??e,l=new Map,a=h=>{const f=ct(h.metadata.path??null);!f||l.has(f)||l.set(f,{...h,metadata:Hr({...h.metadata,path:f})})};for(const h of t.discoveredWorktrees){const f=ct(h.path??null);f&&a({metadata:Hr({...h,path:f,projectDirectory:ct(h.projectDirectory??null)??o??e??f}),isPrimary:o===f,isCurrent:n===f})}o&&!l.has(o)&&a({metadata:yc({path:o,projectDirectory:o,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:!0,isCurrent:n===o}),n&&!l.has(n)&&a({metadata:yc({path:n,projectDirectory:o??e??n,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:o===n,isCurrent:!0});const u=[],d=[];for(const h of l.values()){if(h.isPrimary){u.push(h);continue}d.push(h)}return u.sort((h,f)=>h.metadata.path.localeCompare(f.metadata.path,void 0,{sensitivity:"base"})),d.sort(um),[...u,...d]},Tj=(t,e)=>{const n=e.getRuntimeKey(),r=e.getPublishedWorktreesByProject(),i=ra({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:r,runtimeKey:n}),l=(t.projectId?e.projects.find(d=>d.id===t.projectId)??null:null)??(t.sourceDirectory?e.resolveProject(t.sourceDirectory):null),a=ct(l?.path??null);return{cachedTargets:wc({projectPath:a,discoveredWorktrees:a?i.worktreesByProject.get(a)??[]:[],sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch}),refreshTargets:(async()=>{if(!l||!a)throw new Error("Unable to resolve worktree project");const d=await e.listProjectWorktrees(l,{force:!0});if(e.getRuntimeKey()!==n)throw new Error("Runtime changed during worktree refresh");const h=e.getCurrentProjects(),f=h.find(S=>S.id===l.id)??null;if(!f||ct(f.path??null)!==a)throw new Error("Project removed during worktree refresh");const g=ra({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:e.getPublishedWorktreesByProject(),runtimeKey:n}),p=dm(g.worktreesByProject),w=[...d].map(S=>Hr(S)).sort((S,N)=>um({metadata:S},{metadata:N})),v=ct(w.find(S=>ct(S.projectDirectory??null))?.projectDirectory??t.currentWorktree?.projectDirectory??l.path),x=new Set([a]);for(const[S,N]of p.entries()){const C=ct(N.find(k=>ct(k.projectDirectory??null))?.projectDirectory??S);C&&C===v&&x.add(S)}for(const S of x){if(w.length===0){p.delete(S);continue}p.set(S,w.map(N=>Hr(N)))}Ij(e.rawWorktreesByProjectRef,n),e.rawWorktreesByProjectRef.current={runtimeKey:n,revision:e.rawWorktreesByProjectRef.current.revision,worktreesByProject:p};const m=e.partitionWorktreesByRegisteredProject(h,p),b=[...m.values()].flat();e.recordWorktreesSeen(b.map(S=>S.path),e.now());const y=e.getPublishedWorktreesByProject();return e.worktreeMapsEqual(m,y)||e.publishTopology({availableWorktrees:b,availableWorktreesByProject:m}),wc({projectPath:a,discoveredWorktrees:w,sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch})})()}},Rj=t=>{if(t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey)return!1;if(t.rawWorktreesByProjectRef.current.revision!==t.capturedRevision)return t.requestRediscovery(),!1;const e=t.partitionWorktreesByRegisteredProject(t.projects,t.nextRawWorktreesByProject),n=[...e.values()].flat();return t.recordWorktreesSeen(n.map(r=>r.path),t.now()),t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.capturedRevision,worktreesByProject:new Map(t.nextRawWorktreesByProject)},t.worktreeMapsEqual(e,t.publishedWorktreesByProject)||t.publishTopology({availableWorktrees:n,availableWorktreesByProject:e}),!0},Ej=t=>({refreshState:t.isRefreshing?"loading":t.loadFailed&&t.targets.length===0?"error":null,showNewWorktreeAction:!0}),Mj=(t,e)=>ct(t.worktree?.path??null)===ct(e.worktree?.path??null)&&t.worktree?.branch===e.worktree?.branch,oa=6,co=14,Sc=oa+14+6,xi=new WeakMap,Oj=t=>{const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;xi.get(n)?.();const r=e.getBoundingClientRect().top;let i=3,o=!1,l=null;const a=()=>{o=!0,l!==null&&window.cancelAnimationFrame(l),l=null,xi.delete(n),n.removeEventListener("wheel",a),n.removeEventListener("touchstart",a)},u=()=>{if(o||!e.isConnected||!n.isConnected){a();return}const d=e.getBoundingClientRect().top-r;if(Math.abs(d)>.5&&(n.scrollTop+=d,qs("ui.sidebar.selection_scroll_anchor_adjustment")),i-=1,i<=0){a();return}l=window.requestAnimationFrame(u)};n.addEventListener("wheel",a,{passive:!0}),n.addEventListener("touchstart",a,{passive:!0}),xi.set(n,a),l=window.requestAnimationFrame(u)},Fj=c.memo(function(e){const n=Xe.c(22),{archiveLabel:r,deleteLabel:i,buttonSizeClass:o,iconSizeClass:l,onPointerDown:a,onMouseDown:u,onArchive:d,onDelete:h}=e,f=lj(),g=f?i:r;let p;n[0]!==d||n[1]!==h||n[2]!==f?(p=C=>{if(f||C.shiftKey){h(C);return}d(C)},n[0]=d,n[1]=h,n[2]=f,n[3]=p):p=n[3];const w=p,v=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let x;n[4]!==o||n[5]!==v?(x=Te("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v,o),n[4]=o,n[5]=v,n[6]=x):x=n[6];const m=f?"delete-bin":"archive";let b;n[7]!==l||n[8]!==m?(b=s.jsx(M,{name:m,className:l}),n[7]=l,n[8]=m,n[9]=b):b=n[9];let y;n[10]!==w||n[11]!==g||n[12]!==u||n[13]!==a||n[14]!==x||n[15]!==b?(y=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",className:x,"aria-label":g,onPointerDown:a,onMouseDown:u,onClick:w,onKeyDown:Kj,children:b})}),n[10]=w,n[11]=g,n[12]=u,n[13]=a,n[14]=x,n[15]=b,n[16]=y):y=n[16];let S;n[17]!==g?(S=s.jsx(bt,{side:"left",sideOffset:8,children:g}),n[17]=g,n[18]=S):S=n[18];let N;return n[19]!==y||n[20]!==S?(N=s.jsxs(gt,{children:[y,S]}),n[19]=y,n[20]=S,n[21]=N):N=n[21],N});function Bj(t){qs("ui.sidebar_session_node.render");const{t:e}=pt(),{node:n,depth:r=0,groupDirectory:i,projectId:o,archivedBucket:l=!1,pinnedSessionIds:a,expandedParents:u,hasSessionSearchQuery:d,normalizedSessionSearchQuery:h,notifyOnSubtasks:f,editingId:g,setEditingId:p,editTitle:w,setEditTitle:v,handleSaveEdit:x,handleCancelEdit:m,toggleParent:b,handleSessionSelect:y,handleSessionDoubleClick:S,handleShareSession:N,copiedSessionId:C,handleCopyShareUrl:k,handleCopySessionId:A,handleUnshareSession:D,openSidebarMenuKey:P,setOpenSidebarMenuKey:F,createFolderAndStartRename:W,handleDeleteSession:E,handleRestoreSession:H,startSessionWorktreeMenuLoad:z,mobileVariant:B,alwaysShowActions:T,secondaryMeta:j,renderContext:I="project",children:_}=t,K=Br(Ie=>Ie.toggle),G=cs(Ie=>Ie.getFoldersForScope),Q=cs(Ie=>Ie.getSessionFolderId),ge=cs(Ie=>Ie.removeSessionFromFolder),se=cs(Ie=>Ie.addSessionToFolder),Y=De(Ie=>Ie.openContextPanelTab),te=c.useMemo(()=>Nn(),[]),he=c.useMemo(()=>Ho(),[]),L=c.useContext(dh),le=te?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",Z=te?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ue=te,V=!l&&!B,ee=te?V&&ue?"group-hover:pr-18":V||ue?"group-hover:pr-14":"group-hover:pr-8":V?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",be=V?"pr-13":"pr-7",xe=c.useRef(!1),[Ne,Pe]=c.useState(!1),Se=c.useRef(g);Se.current=g;const Re=c.useRef(null),ye=c.useRef(!1),pe=c.useRef(x);pe.current=x;const[me,je]=c.useState(w),ne=c.useRef(me);ne.current=me;const fe=c.useRef(null),ce=c.useRef(null),R=n.session,$=R,de=Vt(c.useCallback(Ie=>{if(j?.projectLabel||!o)return null;const Et=Ie.projects.find(Gt=>Gt.id===o);return Et?Et.label?.trim()||Fn(ct(Et.path)??Et.path,null)||Et.path:null},[o,j?.projectLabel])),ie=j?.projectLabel??(de?Da(de):null),Ae=j?.branchLabel??n.worktree?.branch??null,Be=c.useMemo(()=>{if(te)return null;const Ie=n.worktree?.branch?.trim(),Et=ct(n.worktree?.path??null);return Ie&&Et?Yo(Et,Ie):null},[te,n.worktree]),Ce=Od(Be),q=Ce?`var(--pr-${Ce.visualState})`:void 0,Ee=ls(Ie=>Ie.sessionGroupingMode),Me=!!Ae&&(I==="recent"||Ee==="flat"),O=c.useMemo(()=>{if(!Ce)return null;switch(Ce.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return Ce.canMerge===!0||Ce.mergeableState==="clean"||Ce.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return Ce.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked");case"draft":return e("sessions.sidebar.group.pr.status.draft");case"closed":return e("sessions.sidebar.group.pr.status.closed");default:return null}},[Ce,e]),oe=Qe(Ie=>Ie.currentSessionId===R.id),re=ct(R.directory??null)??ct(i??null),we=o??re??null,Ve=uh(),st=Fd(),Ge=te,ae=gs(Ie=>Ie.enabled),X=gs(c.useCallback(Ie=>Ie.selectedIds.has(R.id),[R.id])),ve=gs(Ie=>Ie.toggleSelected),Le=gs(Ie=>Ie.setRange),$e=c.useCallback(Ie=>{const Et=[],Gt=os=>{os.children.forEach(ys=>{Et.push(ys.session.id),Gt(ys)})};return Gt(Ie),Et},[]),Ue=c.useCallback(Ie=>{const Et=[],Gt=os=>{os.children.forEach(ys=>{Et.push(ys.session),Gt(ys)})};return Gt(Ie),Et},[]),[We,qe]=c.useState(!1),[nt,yt]=c.useState(!0),vt=`${I}:${l?"archived":"active"}:${R.id}`,He=Bd(c.useCallback(Ie=>!!Ie.sessionMemoryState.get(mh(R.id))?.isZombie,[R.id])),jt=ha(R.id)?.type??"idle",kt=jt==="busy"||jt==="retry",Tt=fh(R.id,kt),wt=Su(R.id),Nt=n.worktree??Qe.getState().getWorktreeMetadata(R.id)??null,[Dt,ft]=c.useState([]),[Ze,ke]=c.useState(!1),[tt,lt]=c.useState(!1),At=c.useRef(!1),Ye=c.useRef(0),rt=hh(R.id,re??void 0,{bootstrap:!1}),It=ph($),Ct=It?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(ol[It.status]),"aria-label":e(ol[It.status]),children:s.jsx(M,{name:"target",className:"h-3 w-3",style:{color:gh[It.status]}})}):null,Pt=$.title||e("sessions.sidebar.session.untitled"),Wt=n.children.length>0,Yt=xh(a,re,R.id),Kt=vt,Bt=d?!0:u.has(Kt),ts=c.useMemo(()=>q0(n,Bt,re),[Bt,n,re]),zt=bh(ts),_t=!!$.parentID,Ke=cd(R.id)>0&&(!_t||f),et=$.time?.updated||$.time?.created||Date.now(),dt=_d(et),ut=yh(et),St=P===vt,[ot,Lt]=c.useState(!1),Qt=St||ot,us=c.useMemo(()=>ko($.title)!==null,[$.title]),[$s,rs]=c.useState(!1),Is=c.useMemo(()=>$e(n).length,[$e,n]),ss=c.useCallback(async Ie=>{const Et=[];let Gt=0;for(const os of Ie)try{if(!re)throw new Error("Session directory is required for export");const ys=await Ve({directory:re,sessionID:os.session.id});if(!ys)throw new Error("Session runtime changed during export");const hs=os.session.title||e("sessions.sidebar.session.export.untitledSubagent"),en=os.session.agent,Jt=await ss(os.children);Gt+=Jt.skipped,Et.push({title:hs,agent:en,records:ys,children:Jt.children})}catch{Gt+=$e(os).length+1}return{children:Et,skipped:Gt}},[$e,Ve,re,e]),Ns=c.useCallback(Ie=>{Ie<=0||Fe.warning(Ie===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Ie}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Ie}))},[e]),Ws=c.useCallback(async Ie=>{if(!re){Fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}const Et=await Ve({directory:re,sessionID:R.id}).catch(()=>null);if(!Et){Fe.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}if(Et.length===0){Fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Gt,os=0;if(Ie&&n.children.length>0){const Jt=await ss(n.children);Gt=Jt.children,os=Jt.skipped}const ys=xu(Et,$.title??null,Gt),hs=wu($.title??null),en=await yu(ys,hs);if(en){Fe.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Dx()),onClick:()=>{Ax(en).then(Jt=>{Jt||Fe.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Ns(os);return}bu(ys,hs),Fe.success(e("sessions.sidebar.session.export.success")),Ns(os)},[ss,Ve,n.children,$.title,R.id,re,Ns,e]),cn=c.useCallback(async()=>{if(n.children.length>0){yt(!0),qe(!0);return}await Ws(!1)},[Ws,n.children.length]),bn=c.useCallback(()=>{re&&Rn("desktop_open_session_mini_chat_window",{sessionId:R.id,directory:re,apiBaseUrl:Mn(),clientToken:Fr()}).catch(Ie=>{console.warn("[session-sidebar] failed to open mini chat window",Ie)})},[R.id,re]);if(c.useEffect(()=>{if(g!==R.id)return;const Ie=Et=>{const os=(Et.target instanceof HTMLElement?Et.target:null)?.closest?.(`[data-session-rename-form="${CSS.escape(R.id)}"]`);ce.current&&!os&&pe.current(ne.current)};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},[g,R.id]),c.useLayoutEffect(()=>{if(g!==R.id){fe.current===R.id&&(fe.current=null);return}fe.current!==R.id&&(fe.current=R.id,je(w))},[g,w,R.id]),g===R.id)return s.jsx("div",{style:{paddingLeft:Sc+r*co},className:"group relative my-0.5 flex items-center rounded-sm py-1 pr-1.5",children:s.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:s.jsxs("form",{ref:ce,"data-session-rename-form":R.id,className:"flex w-full items-center gap-2",onSubmit:Ie=>{Ie.preventDefault(),x(me)},children:[s.jsx("input",{value:me,onChange:Ie=>je(Ie.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:Ie=>{if(Ie.stopPropagation(),Ie.key==="Escape"){m();return}}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:m,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(M,{name:"close",className:"size-4"})})]})})},R.id);const ms=rt.length,xs=zt===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:zt}),zs=Z0({actionsAlwaysVisible:T&&!te,menuOpen:Qt,hideOnHoverClass:Z}),an=!wt&&!kt&&Ke&&!oe,is=kt||an,Vs=e(kt?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),Rt=s.jsx("span",{className:Te("h-1.5 w-1.5 rounded-full",kt?"bg-primary":"bg-[var(--status-info)]"),"aria-label":Vs,title:Vs}),Ot=(kt||an)&&Tt,Xt=!T&&Wt&&(wt||is||Yt),bs=Yt&&!wt&&!is,fs=s.jsx(M,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),Ts=wt||is||bs?s.jsx("span",{style:{left:oa+r*co},className:Te("pointer-events-none absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",Xt?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:wt?s.jsx(M,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):is?Rt:bs?fs:null}):null,J=Wt&&!T&&(wt||is||Yt),ze=Wt?s.jsx("span",{role:"button",tabIndex:0,onClick:Ie=>{Ie.stopPropagation(),Ie.currentTarget.blur(),b(Kt)},onKeyDown:Ie=>{(Ie.key==="Enter"||Ie.key===" ")&&(Ie.preventDefault(),Ie.stopPropagation(),b(Kt))},style:{minWidth:14,minHeight:14,left:oa+r*co},className:Te("absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",J?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Bt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Bt?s.jsx(M,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(M,{name:"arrow-right-s",className:"h-3 w-3"})}):null,U=He?s.jsx(M,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,_e=Ie=>{Ie&&Lt(!1),F(Ie?vt:null)},Je=Ie=>{if(!Ie&&Re.current){const{id:Et,title:Gt}=Re.current;Re.current=null,p(Et),v(Gt)}},mt=Ie=>{Lt(Ie)},ht=Ie=>{Ie.preventDefault(),Ie.stopPropagation(),F(St?null:vt)},Ft=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},ns=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},Ht=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},Zs=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},yn=Ie=>{Ie.preventDefault(),Ie.stopPropagation(),F(null),E(R,{archivedBucket:l})},ni=Ie=>{Ie.preventDefault(),Ie.stopPropagation(),F(null),E(R,{archivedBucket:l,hardDelete:!0,skipConfirm:!0})},er=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},Nm=Ie=>{Ie.preventDefault(),Ie.stopPropagation()},Am=Ie=>{Ie.preventDefault(),Ie.stopPropagation(),L?.vscode?.executeCommand("aiworker.openSessionInEditor",R.id,Pt)},za=Ie=>{if(xe.current){xe.current=!1;return}if(ae){if(Ie?.preventDefault(),Ie?.stopPropagation(),Ie?.shiftKey){const Gt=Array.from(document.querySelectorAll("[data-session-row]")).map(hs=>hs.getAttribute("data-session-row")).filter(hs=>hs!==null&&hs.length>0),os=gs.getState().anchorId,ys=new Map;ys.set(R.id,$e(n)),Le(os,R.id,Gt,we,ys);return}ve(R.id,we,$e(n));return}Ie?.currentTarget&&Oj(Ie.currentTarget),y(R.id,re)},Dm=Ie=>{Ie.defaultPrevented||(Ie.target instanceof HTMLElement?Ie.target:null)?.closest('button, a, input, [role="menuitem"], [role="menu"]')||za(Ie)},Pm=Ie=>{(Ie.button===2||Ie.button===0&&Ie.ctrlKey&&!ae)&&(xe.current=!0)},Im=Ie=>{B&&Ie.pointerType==="touch"&&Pe(!0),Ie.button===0&&!oe&&!ae&&!Ge&&re&&!Pi(R.id,re).renderable&&st({directory:re,sessionID:R.id}).catch(()=>{})},Va=Ie=>{B&&Ie.pointerType==="touch"&&Pe(!1)},Tm=Ie=>{At.current=Ie,Ye.current+=1;const Et=Ye.current;if(!Ie){ke(!1),lt(!1);return}const Gt=z({projectId:o??null,sourceDirectory:re,currentWorktree:Nt});ft(Gt.cachedTargets),ke(!0),lt(!1),Gt.refreshTargets.then(os=>{!At.current||Ye.current!==Et||(ft(os),ke(!1),lt(!1))}).catch(()=>{!At.current||Ye.current!==Et||(ke(!1),lt(!0))})},Ua=({Item:Ie,Separator:Et,Sub:Gt,SubTrigger:os,SubContent:ys})=>s.jsxs(s.Fragment,{children:[s.jsxs(Ie,{onClick:()=>{Re.current={id:R.id,title:Pt}},className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ie,{onClick:()=>A(R.id),className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(Ie,{onClick:()=>re&&K({directory:re,sessionId:R.id}),className:"[&>svg]:mr-1",children:[Yt?s.jsx(M,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(M,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Yt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),$.share?s.jsxs(s.Fragment,{children:[s.jsx(Ie,{onClick:()=>{$.share?.url&&k($.share.url,R.id)},className:"[&>svg]:mr-1",children:C===R.id?s.jsxs(s.Fragment,{children:[s.jsx(M,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(M,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Ie,{onClick:()=>D(R.id),className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ie,{onClick:()=>N($),className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Ie,{onClick:()=>{cn()},className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),H0({isSubtaskSession:_t,archivedBucket:!!l,isVSCode:te,sessionDirectory:re})?(()=>{const hs=G0({sessionDirectory:re,isStreaming:kt,isMovingToWorktree:wt}),en=Ej({targets:Dt,isRefreshing:Ze,loadFailed:tt});return s.jsxs(Gt,{onOpenChange:Tm,children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsxs(os,{disabled:hs,className:"w-full [&>svg]:mr-1","data-session-worktree-submenu-trigger":R.id,children:[s.jsx(M,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktreeTargets")]})}),s.jsx(bt,{side:"right",className:"max-w-72",children:e(wt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":kt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltipTargets")})]}),s.jsxs(ys,{className:"min-w-[220px]","data-session-worktree-submenu":R.id,children:[Dt.map(Jt=>{const tn=ct(Jt.metadata.path??null)??Jt.metadata.path,yr=Jt.isPrimary?e("sessions.sidebar.session.moveToWorktree.main"):Jt.metadata.label||Jt.metadata.branch||Jt.metadata.name||Jt.metadata.path,ps=Jt.isCurrent||Jt.metadata.worktreeStatus!=="ready";return s.jsxs(Ie,{disabled:ps,title:Jt.metadata.path,"data-session-worktree-target":tn,onClick:()=>{ps||!re||Ki({kind:"existing",root:$,descendants:Ue(n),sourceDirectory:re,destination:Jt.metadata,messages:Vi(e,{success:"sessions.sidebar.session.moveToWorktree.existingSuccess",failure:"sessions.sidebar.session.moveToWorktree.existingFailed"})})},children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1 truncate",children:[s.jsx("span",{className:"truncate",children:yr}),Jt.isCurrent?s.jsx("span",{className:"sr-only",children:e("sessions.sidebar.session.moveToWorktree.current")}):null]}),Jt.isCurrent?s.jsx(M,{name:"check",className:"ml-2 h-3.5 w-3.5 flex-shrink-0 text-primary","aria-hidden":"true"}):null]},tn)}),en.refreshState==="loading"?s.jsx(Ie,{disabled:!0,"data-session-worktree-refresh-state":"loading",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.refreshing")}):null,en.refreshState==="error"?s.jsx(Ie,{disabled:!0,"data-session-worktree-refresh-state":"error",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.loadFailed")}):null,s.jsx(Et,{}),s.jsxs(Ie,{disabled:hs,"data-session-worktree-new-action":"true",onClick:()=>{hs||!re||Ki({kind:"quick",root:$,descendants:Ue(n),sourceDirectory:re,messages:Vi(e,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.newWorktree")]})]})]})})():null,us?s.jsxs(Ie,{onClick:()=>rs(!0),className:"[&>svg]:mr-1",children:[s.jsx(Pj,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,re&&!l?(()=>{const hs=[],en=ps=>{const ks=ct(ps??null);ks&&!hs.includes(ks)&&hs.push(ks)};if(o&&!te){const ps=Vt.getState().projects.find(tr=>tr.id===o),ks=ct(ps?.path??null);en(ks),ks&&(Qe.getState().availableWorktreesByProject.get(ks)??[]).forEach(tr=>en(tr.path))}en(Ld(re)),en(re);const Jt=hs.flatMap(ps=>G(ps).map(ks=>({scope:ps,folder:ks}))),tn=Jt.find(({scope:ps,folder:ks})=>Q(ps,R.id)===ks.id)??null,yr=hs[0]??re;return s.jsxs(s.Fragment,{children:[s.jsx(Et,{}),s.jsxs(Gt,{children:[s.jsxs(os,{className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(ys,{className:"min-w-[180px]",children:[Jt.length===0?s.jsx(Ie,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Jt.map(({scope:ps,folder:ks})=>{const tr=tn?.folder.id===ks.id;return s.jsxs(Ie,{onClick:()=>{if(tr){ge(ps,R.id);return}tn&&tn.scope!==ps&&ge(tn.scope,R.id),se(ps,ks.id,R.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:ks.name}),tr?s.jsx(M,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},ks.id)}),s.jsx(Et,{}),s.jsxs(Ie,{onClick:()=>{const ps=W(yr);ps&&(ye.current=!0,tn&&tn.scope!==yr&&ge(tn.scope,R.id),se(yr,ps.id,R.id))},children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),tn?s.jsxs(Ie,{onClick:()=>{ge(tn.scope,R.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(M,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,te?null:s.jsxs(Ie,{disabled:!re,onClick:()=>{re&&Y(re,{mode:"chat",dedupeKey:`session:${R.id}`,label:Pt,sessionTitleFallback:Pt})},className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),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:e("sessions.sidebar.session.menu.betaBadge")})]}),he?s.jsxs(Ie,{disabled:!re,onClick:bn,className:"[&>svg]:mr-1",children:[s.jsx(M,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Et,{}),l?null:s.jsxs(Ie,{className:"[&>svg]:mr-1",onClick:()=>E(R,{archivedBucket:l}),children:[s.jsx(M,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),l?s.jsxs(Ie,{className:"[&>svg]:mr-1",onClick:()=>H(R),children:[s.jsx(M,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(Ie,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>E(R,{archivedBucket:l,hardDelete:!0}),children:[s.jsx(M,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Rm=s.jsx(Xs,{align:"end",className:"min-w-[180px]",finalFocus:()=>ye.current?(ye.current=!1,!1):!Se.current,children:Ua({Item:$t,Separator:Es,Sub:Sh,SubTrigger:vh,SubContent:jh})}),Em=s.jsx(Li,{children:s.jsx($i,{className:"app-region-no-drag z-50",children:s.jsx(Wi,{"data-slot":"dropdown-menu-content",finalFocus:()=>ye.current?(ye.current=!1,!1):!Se.current,style:{color:"var(--surface-elevated-foreground)"},className:Te(ji,"min-w-[180px]"),children:Ua({Item:({className:Ie,...Et})=>s.jsx(iu,{className:Te(ud,Ie),...Et}),Separator:({className:Ie,...Et})=>s.jsx(ou,{className:Te(dd,Ie),...Et}),Sub:bg,SubTrigger:({className:Ie,children:Et,...Gt})=>s.jsxs(yg,{className:Te(wh,Ie),...Gt,children:[Et,s.jsx(M,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Ie,children:Et,...Gt})=>s.jsx(Li,{children:s.jsx($i,{className:"app-region-no-drag z-50",children:s.jsx(Wi,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Te(ji,Ie),...Gt,children:Et})})})})})})});return s.jsxs(c.Fragment,{children:[s.jsx(V0,{sessionId:R.id,sessionDirectory:re??null,sessionTitle:Pt,children:s.jsxs(lu,{open:ot,onOpenChange:mt,onOpenChangeComplete:Je,children:[s.jsxs(au,{render:s.jsx("div",{"data-session-row":R.id,"data-session-scope":we??"","data-session-archived":l?"1":"0","aria-current":oe?"page":void 0,onClick:Dm,style:{paddingLeft:Sc+r*co},className:Te("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",oe&&!X&&"bg-primary/10",X&&"bg-interactive-selection")}),children:[Ts,ze,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:Im,onPointerUp:Va,onPointerCancel:Va,onMouseDown:Pm,onClick:Ie=>za(Ie),onDoubleClick:Ie=>{Ie.stopPropagation(),S(R.id,Pt)},className:Te("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",Ne&&"bg-interactive-hover/70",T?te?ee:be:ee),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:Te("block min-w-0 flex-1 truncate typography-ui-label font-normal",oe?"text-primary":Ke?"text-foreground":"text-foreground/80"),children:xo(Pt,h)}),T?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 typography-micro text-muted-foreground/75",children:Ot?s.jsx(yl,{sessionId:R.id,running:kt}):s.jsxs(s.Fragment,{children:[Ct,Me?s.jsx(M,{name:"git-branch",className:Te("h-3 w-3",!q&&"text-muted-foreground/60"),style:q?{color:q}:void 0}):null,ut]})}):Ot||Ct||Me||I==="recent"?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:Te("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",Qt?"opacity-0":Z),children:Ot?s.jsx(yl,{sessionId:R.id,running:kt,className:"typography-micro"}):s.jsxs(s.Fragment,{children:[Ct,Me?s.jsx(M,{name:"git-branch",className:Te("h-3 w-3",!q&&"text-muted-foreground/60"),style:q?{color:q}:void 0}):null,I==="recent"?s.jsx("span",{className:"flex-shrink-0 typography-micro leading-none text-muted-foreground/75 tabular-nums",children:ut}):null]})})}):null,ms>0?s.jsxs("span",{className:Te("inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",zs),title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(M,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ms})]}):null,zt>0?s.jsxs("span",{className:Te("inline-flex items-center gap-1 rounded bg-status-info/10 px-1 py-0.5 text-[0.7rem] text-status-info flex-shrink-0",zs),title:xs,"aria-label":xs,children:[s.jsx(M,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:zt})]}):null]})})}),te?null:s.jsx(bt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:Pt}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:dt,children:ut})]}),ie?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(M,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:ie})]}):null,Ae?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(M,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:q?{color:q}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:Ae})]}):null,Ce&&O?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(M,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:q?{color:q}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:q?{color:q}:void 0,children:["#",Ce.number," · ",O]})]}):null]})})]})}),U&&!B?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:U}):null,s.jsxs("div",{className:Te("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Qt||T&&!te?"opacity-100":Te("opacity-0",le)),children:[V?s.jsx(Fj,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:T?"h-6 w-6":"h-4 w-4",iconSizeClass:T?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:Ht,onMouseDown:Zs,onArchive:yn,onDelete:ni}):null,ue?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",T?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:er,onMouseDown:Nm,onClick:Am,onKeyDown:Ie=>Ie.stopPropagation(),children:s.jsx(M,{name:"external-link",className:Te(T?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(bt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Js,{open:St,onOpenChange:_e,onOpenChangeComplete:Je,children:[s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:Te("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",T?"h-6 w-6 opacity-100":Qt?"h-4 w-4 opacity-100":Te("h-4 w-4 opacity-0",le)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ft,onMouseDown:ns,onClick:ht,onKeyDown:Ie=>Ie.stopPropagation(),children:s.jsx(M,{name:"more-2",className:Te(T?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Rm]})]})]}),Em]})}),Wt&&Bt?_:null,s.jsx(vs,{open:We,onOpenChange:qe,children:s.jsxs(js,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Ls,{children:[s.jsx(Ds,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ps,{children:Is===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Is}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Is})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:nt,onChange:Ie=>yt(Ie.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(gn,{children:[s.jsx(at,{type:"button",onClick:()=>qe(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{type:"button",onClick:()=>{qe(!1),Ws(nt)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),us?s.jsx(Dj,{session:$,open:$s,onOpenChange:rs}):null]},R.id)}const vc=t=>ct(t.session.directory??null),_j=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),Lj=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},jc=t=>t.menuOpenSessionId??Lj(t),uo=(t,e,n)=>e?n.has(t.node.session.id)?!0:Gn(t.node,e):!1,ia=(t,e,n,r,i)=>{if(t.session.id!==e.session.id)return!0;const o=i(t);if(n.has(o)!==r.has(o)||t.children.length!==e.children.length)return!0;for(let l=0;l<t.children.length;l+=1)if(ia(t.children[l],e.children[l],n,r,i))return!0;return!1},$j=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return ia(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${t.renderContext??"project"}:${n}:${i.session.id}`)||ia(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${e.renderContext??"project"}:${r}:${i.session.id}`)},Wj=(t,e)=>t.id===e.id&&t.title===e.title&&t.directory===e.directory&&t.parentID===e.parentID&&t.share?.url===e.share?.url&&t.time?.created===e.time?.created&&t.time?.updated===e.time?.updated&&t.time?.archived===e.time?.archived,zj=(t,e)=>{if(t.node.session.id!==e.node.session.id||!Wj(t.node.session,e.node.session)||!Mj(t.node,e.node))return"node";if(t.depth!==e.depth)return"depth";if(t.groupDirectory!==e.groupDirectory)return"groupDirectory";if(t.projectId!==e.projectId)return"projectId";if(t.archivedBucket!==e.archivedBucket)return"archivedBucket";if((t.renderContext??"project")!==(e.renderContext??"project"))return"renderContext";if(t.mobileVariant!==e.mobileVariant)return"mobileVariant";if(t.alwaysShowActions!==e.alwaysShowActions)return"alwaysShowActions";if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery)return"hasSessionSearchQuery";if(t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery)return"normalizedSessionSearchQuery";if(t.notifyOnSubtasks!==e.notifyOnSubtasks)return"notifyOnSubtasks";if(t.nodeStructureKey!==e.nodeStructureKey)return"nodeStructureKey";if(t.relativeTimeTick!==e.relativeTimeTick)return"relativeTimeTick";if(vc(t.node)!==vc(e.node))return"nodeDirectory";if(!_j(t.secondaryMeta,e.secondaryMeta))return"secondaryMeta";if(t.pinnedSessionIds!==e.pinnedSessionIds&&im(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory))return"pinnedSessionIds";if(t.expandedParents!==e.expandedParents&&$j(t,e))return"expandedParents";if(t.editingId!==e.editingId&&(uo(t,t.editingId,t.subtreeContainsEditing)||uo(e,e.editingId,e.subtreeContainsEditing)))return"editingId";if(t.editTitle!==e.editTitle&&(uo(t,t.editingId,t.subtreeContainsEditing)||uo(e,e.editingId,e.subtreeContainsEditing)))return"editTitle";if(t.copiedSessionId!==e.copiedSessionId&&(Gn(t.node,t.copiedSessionId)||Gn(e.node,e.copiedSessionId)))return"copiedSessionId";if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const r=jc(t),i=jc(e);if(Gn(t.node,r)||Gn(e.node,i))return"openSidebarMenuKey"}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.children===e.children?null:"callbacks"},Vj=(t,e)=>{const n=zj(t,e);return n===null?!0:(qs(`ui.sidebar_session_node.props_changed.${n}`),!1)},Uj=c.memo(Bj,Vj);function Kj(t){return t.stopPropagation()}const Hj=t=>{const{t:e}=pt(),n=c.useRef(null),r=c.useRef(t.editingId),i=c.useRef(t.editTitle),o=c.useRef(t.deleteSessionConfirm);r.current=t.editingId,i.current=t.editTitle,o.current=t.deleteSessionConfirm;const l=De(Y=>Y.setSessionSwitcherOpen),a=Qe(Y=>Y.setCurrentSession),u=Qe(Y=>Y.updateSessionTitle),d=Qe(Y=>Y.shareSession),h=Qe(Y=>Y.unshareSession),f=Qe(Y=>Y.deleteSession),g=Qe(Y=>Y.deleteSessions),p=Qe(Y=>Y.archiveSession),w=Qe(Y=>Y.archiveSessions),v=Qe(Y=>Y.unarchiveSession),{mobileVariant:x,allowReselect:m,onSessionSelected:b,isSessionSearchOpen:y,sessionSearchQuery:S,setSessionSearchQuery:N,setIsSessionSearchOpen:C,descendantIds:k,showDeletionDialog:A,setDeleteSessionConfirm:D,setEditingId:P,setEditTitle:F,setCopiedSessionId:W}=t;c.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const E=c.useCallback((Y,te)=>{vi("navigation.session_select"),De.getState().closeMainSurfaces();const he=()=>{!y&&S.length===0||(N(""),C(!1))};if(x&&l(!1),Y===Qe.getState().currentSessionId){m&&b?.(Y),he();return}vi("navigation.session_state_set"),a(Y,te??null),b?.(Y),he()},[m,y,x,b,S,a,C,N,l]),H=c.useCallback((Y,te)=>{P(Y),F(te)},[F,P]),z=c.useCallback(async Y=>{const te=r.current;if(!te)return;const he=(Y??i.current).trim();he&&await u(te,he),P(null),F("")},[F,P,u]),B=c.useCallback(()=>{P(null),F("")},[F,P]),T=c.useCallback(async(Y,te)=>{try{return(await fn(Y)).ok?(W(te),n.current&&clearTimeout(n.current),n.current=window.setTimeout(()=>{W(null),n.current=null},2e3),!0):!1}catch{return!1}},[W]),j=c.useCallback(async Y=>{const te=await d(Y.id);if(!te?.share?.url){Fe.error(e("sessions.sidebar.session.share.error"));return}const he=await T(te.share.url,Y.id);Fe[he?"success":"warning"](e("sessions.sidebar.session.share.successTitle"),{description:e(he?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},[T,d,e]),I=c.useCallback((Y,te)=>{T(Y,te).then(he=>{he||Fe.error(e("sessions.sidebar.session.share.copyUrlError"))})},[T,e]),_=c.useCallback(Y=>{fn(Y).then(te=>{if(te.ok){Fe.success(e("sessions.sidebar.session.copyId.success"));return}Fe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Fe.error(e("sessions.sidebar.session.copyId.error")))},[e]),K=c.useCallback(async Y=>{await h(Y)?Fe.success(e("sessions.sidebar.session.unshare.success")):Fe.error(e("sessions.sidebar.session.unshare.error"))},[e,h]),G=c.useCallback(async(Y,te,he)=>{const L=te?.archivedBucket===!0||te?.hardDelete===!0,le=he?.descendantIds??k;if(le.length===0){(L?await f(Y.id):await p(Y.id))?Fe.success(e(L?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):Fe.error(e(L?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Z=[Y.id,...le];if(L){const{deletedIds:ee,failedIds:be}=await g(Z);if(be.length===0){const xe=ee.length;Fe.success(xe===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:xe}):e("sessions.sidebar.bulkActions.deletedPlural",{count:xe}))}else Fe.error(e("sessions.sidebar.session.delete.error"));return}const{archivedIds:ue,failedIds:V}=await w(Z);ue.length>0&&Fe.success(ue.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:ue.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:ue.length})),V.length>0&&Fe.error(V.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:V.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:V.length}))},[p,w,f,g,k,e]),Q=c.useCallback((Y,te)=>{const he=te?.archivedBucket===!0||te?.hardDelete===!0,L=[...k];if(!A||te?.skipConfirm===!0){G(Y,te,{descendantIds:L});return}D({session:Y,descendantCount:L.length,descendantIds:L,archivedBucket:he})},[k,G,D,A]),ge=c.useCallback(async()=>{const Y=o.current;if(!Y)return;const{session:te,archivedBucket:he,descendantIds:L}=Y;D(null),await G(te,{archivedBucket:he},{descendantIds:L})},[G,D]),se=c.useCallback(async Y=>{await v(Y.id)?Fe.success(e("sessions.sidebar.session.restore.success")):Fe.error(e("sessions.sidebar.session.restore.error"))},[e,v]);return c.useMemo(()=>({handleSessionSelect:E,handleSessionDoubleClick:H,handleSaveEdit:z,handleCancelEdit:B,handleShareSession:j,handleCopyShareUrl:I,handleCopySessionId:_,handleUnshareSession:K,handleDeleteSession:Q,handleRestoreSession:se,confirmDeleteSession:ge}),[B,_,I,Q,se,z,H,E,j,K,ge])};function Gj(t){const e=Xe.c(71),{t:n}=pt(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t;let u,d,h,f,g,p,w,v,x,m;if(e[0]!==i||e[1]!==n||e[2]!==r){const I=n("sessions.sidebar.session.untitled");f=vs,x=!!r,e[13]!==i?(m=K=>{K||i(null)},e[13]=i,e[14]=m):m=e[14],h=js,w=!1,v="max-w-sm gap-5",d=Ls;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(p=s.jsx(Ds,{children:_}),e[18]=_,e[19]=p):p=e[19],u=Ps,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||I,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||I,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||I,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||I,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||I}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||I}),e[0]=i,e[1]=n,e[2]=r,e[3]=u,e[4]=d,e[5]=h,e[6]=f,e[7]=g,e[8]=p,e[9]=w,e[10]=v,e[11]=x,e[12]=m}else u=e[3],d=e[4],h=e[5],f=e[6],g=e[7],p=e[8],w=e[9],v=e[10],x=e[11],m=e[12];let b;e[20]!==u||e[21]!==g?(b=s.jsx(u,{children:g}),e[20]=u,e[21]=g,e[22]=b):b=e[22];let y;e[23]!==d||e[24]!==p||e[25]!==b?(y=s.jsxs(d,{children:[p,b]}),e[23]=d,e[24]=p,e[25]=b,e[26]=y):y=e[26];let S;e[27]!==l||e[28]!==o?(S=()=>l(!o),e[27]=l,e[28]=o,e[29]=S):S=e[29];const N=!o;let C;e[30]!==o?(C=o?s.jsx(M,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(M,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=o,e[31]=C):C=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let A;e[34]!==C||e[35]!==k||e[36]!==S||e[37]!==N?(A=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-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":N,children:[C,k]}),e[34]=C,e[35]=k,e[36]=S,e[37]=N,e[38]=A):A=e[38];let D;e[39]!==i?(D=()=>i(null),e[39]=i,e[40]=D):D=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let F;e[43]!==D||e[44]!==P?(F=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=D,e[44]=P,e[45]=F):F=e[45];let W;e[46]!==a?(W=()=>{a()},e[46]=a,e[47]=W):W=e[47];let E;e[48]!==n||e[49]!==r?.archivedBucket?(E=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=E):E=e[50];let H;e[51]!==W||e[52]!==E?(H=s.jsx("button",{type:"button",onClick:W,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[51]=W,e[52]=E,e[53]=H):H=e[53];let z;e[54]!==F||e[55]!==H?(z=s.jsxs("div",{className:"flex items-center gap-2",children:[F,H]}),e[54]=F,e[55]=H,e[56]=z):z=e[56];let B;e[57]!==A||e[58]!==z?(B=s.jsxs(gn,{className:"w-full sm:items-center sm:justify-between",children:[A,z]}),e[57]=A,e[58]=z,e[59]=B):B=e[59];let T;e[60]!==h||e[61]!==w||e[62]!==B||e[63]!==v||e[64]!==y?(T=s.jsxs(h,{showCloseButton:w,className:v,children:[y,B]}),e[60]=h,e[61]=w,e[62]=B,e[63]=v,e[64]=y,e[65]=T):T=e[65];let j;return e[66]!==f||e[67]!==T||e[68]!==x||e[69]!==m?(j=s.jsx(f,{open:x,onOpenChange:m,children:T}),e[66]=f,e[67]=T,e[68]=x,e[69]=m,e[70]=j):j=e[70],j}function qj(t){const e=Xe.c(57),{t:n}=pt(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t,u=r?.archivedBucket===!0,d=r?.sessionCount??0;let h;e[0]!==u||e[1]!==d||e[2]!==n?(h=n(u?d===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":d===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=u,e[1]=d,e[2]=n,e[3]=h):h=e[3];const f=h;let g;e[4]!==u||e[5]!==d||e[6]!==n?(g=u?d===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:d}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:d}):d===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:d}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:d}),e[4]=u,e[5]=d,e[6]=n,e[7]=g):g=e[7];const p=g,w=!!r;let v;e[8]!==i?(v=j=>{j||i(null)},e[8]=i,e[9]=v):v=e[9];let x;e[10]!==f?(x=s.jsx(Ds,{children:f}),e[10]=f,e[11]=x):x=e[11];let m;e[12]!==p?(m=s.jsx(Ps,{children:p}),e[12]=p,e[13]=m):m=e[13];let b;e[14]!==x||e[15]!==m?(b=s.jsxs(Ls,{children:[x,m]}),e[14]=x,e[15]=m,e[16]=b):b=e[16];let y;e[17]!==l||e[18]!==o?(y=()=>l(!o),e[17]=l,e[18]=o,e[19]=y):y=e[19];const S=!o;let N;e[20]!==o?(N=o?s.jsx(M,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(M,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=o,e[21]=N):N=e[21];let C;e[22]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=C):C=e[23];let k;e[24]!==C||e[25]!==y||e[26]!==S||e[27]!==N?(k=s.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-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":S,children:[N,C]}),e[24]=C,e[25]=y,e[26]=S,e[27]=N,e[28]=k):k=e[28];let A;e[29]!==i?(A=()=>i(null),e[29]=i,e[30]=A):A=e[30];let D;e[31]!==n?(D=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=D):D=e[32];let P;e[33]!==A||e[34]!==D?(P=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:D}),e[33]=A,e[34]=D,e[35]=P):P=e[35];let F;e[36]!==a?(F=()=>{a()},e[36]=a,e[37]=F):F=e[37];let W;e[38]!==u||e[39]!==n?(W=n(u?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=u,e[39]=n,e[40]=W):W=e[40];let E;e[41]!==F||e[42]!==W?(E=s.jsx("button",{type:"button",onClick:F,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:W}),e[41]=F,e[42]=W,e[43]=E):E=e[43];let H;e[44]!==P||e[45]!==E?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[P,E]}),e[44]=P,e[45]=E,e[46]=H):H=e[46];let z;e[47]!==k||e[48]!==H?(z=s.jsxs(gn,{className:"w-full sm:items-center sm:justify-between",children:[k,H]}),e[47]=k,e[48]=H,e[49]=z):z=e[49];let B;e[50]!==z||e[51]!==b?(B=s.jsxs(js,{showCloseButton:!1,className:"max-w-sm gap-5",children:[b,z]}),e[50]=z,e[51]=b,e[52]=B):B=e[52];let T;return e[53]!==w||e[54]!==B||e[55]!==v?(T=s.jsx(vs,{open:w,onOpenChange:v,children:B}),e[53]=w,e[54]=B,e[55]=v,e[56]=T):T=e[56],T}function Qj(t){const e=Xe.c(36),{t:n}=pt(),{value:r,setValue:i,onConfirm:o}=t,l=!!r;let a;e[0]!==i?(a=N=>{N||i(null)},e[0]=i,e[1]=a):a=e[1];let u;e[2]!==n?(u=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=u):u=e[3];let d;e[4]!==u?(d=s.jsx(Ds,{children:u}),e[4]=u,e[5]=d):d=e[5];let h;e[6]!==n||e[7]!==r?(h=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=h):h=e[8];let f;e[9]!==h?(f=s.jsx(Ps,{children:h}),e[9]=h,e[10]=f):f=e[10];let g;e[11]!==d||e[12]!==f?(g=s.jsxs(Ls,{children:[d,f]}),e[11]=d,e[12]=f,e[13]=g):g=e[13];let p;e[14]!==i?(p=()=>i(null),e[14]=i,e[15]=p):p=e[15];let w;e[16]!==n?(w=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=w):w=e[17];let v;e[18]!==p||e[19]!==w?(v=s.jsx("button",{type:"button",onClick:p,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:w}),e[18]=p,e[19]=w,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let m;e[23]!==o||e[24]!==x?(m=s.jsx("button",{type:"button",onClick:o,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=o,e[24]=x,e[25]=m):m=e[25];let b;e[26]!==m||e[27]!==v?(b=s.jsxs(gn,{children:[v,m]}),e[26]=m,e[27]=v,e[28]=b):b=e[28];let y;e[29]!==b||e[30]!==g?(y=s.jsxs(js,{showCloseButton:!1,className:"max-w-sm gap-5",children:[g,b]}),e[29]=b,e[30]=g,e[31]=y):y=e[31];let S;return e[32]!==l||e[33]!==a||e[34]!==y?(S=s.jsx(vs,{open:l,onOpenChange:a,children:y}),e[32]=l,e[33]=a,e[34]=y,e[35]=S):S=e[35],S}const Yj=new Set;function zo(t){const e=Xe.c(142),{node:n,depth:r,groupDirectory:i,projectId:o,archivedBucket:l,secondaryMeta:a,renderContext:u,renderExtras:d,pinnedSessionIds:h,expandedParents:f,hasSessionSearchQuery:g,normalizedSessionSearchQuery:p,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,toggleParent:y,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:F,deleteSessionConfirm:W,setDeleteSessionConfirm:E,startFolderRename:H,copiedSessionId:z,setCopiedSessionId:B,startSessionWorktreeMenuLoad:T,mobileVariant:j,alwaysShowActions:I}=t,_=r===void 0?0:r,K=l===void 0?!1:l,G=u===void 0?"project":u,Q=cs(e2),ge=cs(Zj),se=De(Jj),Y=De(Xj);let te;if(e[0]!==n){te=[];const Me=O=>O.children.forEach(oe=>{te.push(oe.session.id),Me(oe)});Me(n),e[0]=n,e[1]=te}else te=e[1];const he=te.join(`
|
|
920
|
-
`);let L;e[2]!==he?(L=he?he.split(`
|
|
921
|
-
`):[],e[2]=he,e[3]=L):L=e[3];const le=L;let Z;e[4]!==Q||e[5]!==H||e[6]!==ge?(Z=(Me,O)=>{if(!Me)return null;O&&cs.getState().collapsedFolderIds.has(O)&&ge(O);const oe=Q(Me,"New folder",O);return H(Me,oe),oe},e[4]=Q,e[5]=H,e[6]=ge,e[7]=Z):Z=e[7];const ue=Z;let V;e[8]!==C||e[9]!==z||e[10]!==W||e[11]!==le||e[12]!==m||e[13]!==v||e[14]!==A||e[15]!==j||e[16]!==k||e[17]!==D||e[18]!==B||e[19]!==E||e[20]!==b||e[21]!==x||e[22]!==F||e[23]!==P||e[24]!==se?(V={mobileVariant:j,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:F,descendantIds:le,showDeletionDialog:se,setDeleteSessionConfirm:E,deleteSessionConfirm:W,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,copiedSessionId:z,setCopiedSessionId:B},e[8]=C,e[9]=z,e[10]=W,e[11]=le,e[12]=m,e[13]=v,e[14]=A,e[15]=j,e[16]=k,e[17]=D,e[18]=B,e[19]=E,e[20]=b,e[21]=x,e[22]=F,e[23]=P,e[24]=se,e[25]=V):V=e[25];const ee=Hj(V),be=d?.childRenderExtrasFor,xe=n.session.directory??i;let Ne;e[26]!==K||e[27]!==o||e[28]!==G||e[29]!==xe?(Ne={groupDirectory:xe,projectId:o,archivedBucket:K,renderContext:G},e[26]=K,e[27]=o,e[28]=G,e[29]=xe,e[30]=Ne):Ne=e[30];const Pe=Ne,Se=ee.handleSaveEdit,Re=ee.handleCancelEdit,ye=ee.handleSessionSelect,pe=ee.handleSessionDoubleClick,me=ee.handleShareSession,je=ee.handleCopyShareUrl,ne=ee.handleCopySessionId,fe=ee.handleUnshareSession,ce=ee.handleDeleteSession,R=ee.handleRestoreSession,$=d?.subtreeContainsEditing??Yj,de=d?.menuOpenSessionId??null,ie=d?.nodeStructureKey??"",Ae=d?.relativeTimeTick;let Be;if(e[31]!==C||e[32]!==I||e[33]!==Pe||e[34]!==be||e[35]!==z||e[36]!==W||e[37]!==_||e[38]!==m||e[39]!==v||e[40]!==f||e[41]!==g||e[42]!==A||e[43]!==j||e[44]!==n.children||e[45]!==p||e[46]!==w||e[47]!==k||e[48]!==S||e[49]!==h||e[50]!==D||e[51]!==B||e[52]!==E||e[53]!==b||e[54]!==x||e[55]!==F||e[56]!==N||e[57]!==P||e[58]!==H||e[59]!==T||e[60]!==y){let Me;e[62]!==C||e[63]!==I||e[64]!==Pe||e[65]!==be||e[66]!==z||e[67]!==W||e[68]!==_||e[69]!==m||e[70]!==v||e[71]!==f||e[72]!==g||e[73]!==A||e[74]!==j||e[75]!==p||e[76]!==w||e[77]!==k||e[78]!==S||e[79]!==h||e[80]!==D||e[81]!==B||e[82]!==E||e[83]!==b||e[84]!==x||e[85]!==F||e[86]!==N||e[87]!==P||e[88]!==H||e[89]!==T||e[90]!==y?(Me=O=>s.jsx(zo,{node:O,pinnedSessionIds:h,expandedParents:f,hasSessionSearchQuery:g,normalizedSessionSearchQuery:p,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,copiedSessionId:z,setEditTitle:b,toggleParent:y,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:F,deleteSessionConfirm:W,setDeleteSessionConfirm:E,startFolderRename:H,setCopiedSessionId:B,startSessionWorktreeMenuLoad:T,mobileVariant:j,alwaysShowActions:I,depth:_+1,...Pe,renderExtras:be?.(O)},O.session.id),e[62]=C,e[63]=I,e[64]=Pe,e[65]=be,e[66]=z,e[67]=W,e[68]=_,e[69]=m,e[70]=v,e[71]=f,e[72]=g,e[73]=A,e[74]=j,e[75]=p,e[76]=w,e[77]=k,e[78]=S,e[79]=h,e[80]=D,e[81]=B,e[82]=E,e[83]=b,e[84]=x,e[85]=F,e[86]=N,e[87]=P,e[88]=H,e[89]=T,e[90]=y,e[91]=Me):Me=e[91],Be=n.children.map(Me),e[31]=C,e[32]=I,e[33]=Pe,e[34]=be,e[35]=z,e[36]=W,e[37]=_,e[38]=m,e[39]=v,e[40]=f,e[41]=g,e[42]=A,e[43]=j,e[44]=n.children,e[45]=p,e[46]=w,e[47]=k,e[48]=S,e[49]=h,e[50]=D,e[51]=B,e[52]=E,e[53]=b,e[54]=x,e[55]=F,e[56]=N,e[57]=P,e[58]=H,e[59]=T,e[60]=y,e[61]=Be}else Be=e[61];let Ce;e[92]!==I||e[93]!==K||e[94]!==z||e[95]!==ue||e[96]!==_||e[97]!==m||e[98]!==v||e[99]!==f||e[100]!==i||e[101]!==g||e[102]!==j||e[103]!==n||e[104]!==p||e[105]!==w||e[106]!==S||e[107]!==h||e[108]!==o||e[109]!==G||e[110]!==a||e[111]!==ee.handleCancelEdit||e[112]!==ee.handleCopySessionId||e[113]!==ee.handleCopyShareUrl||e[114]!==ee.handleDeleteSession||e[115]!==ee.handleRestoreSession||e[116]!==ee.handleSaveEdit||e[117]!==ee.handleSessionDoubleClick||e[118]!==ee.handleSessionSelect||e[119]!==ee.handleShareSession||e[120]!==ee.handleUnshareSession||e[121]!==b||e[122]!==x||e[123]!==N||e[124]!==T||e[125]!==$||e[126]!==de||e[127]!==ie||e[128]!==Ae||e[129]!==Be||e[130]!==y?(Ce=s.jsx(Uj,{expandedParents:f,hasSessionSearchQuery:g,normalizedSessionSearchQuery:p,notifyOnSubtasks:w,editingId:v,setEditingId:x,editTitle:m,setEditTitle:b,handleSaveEdit:Se,handleCancelEdit:Re,toggleParent:y,handleSessionSelect:ye,handleSessionDoubleClick:pe,handleShareSession:me,copiedSessionId:z,handleCopyShareUrl:je,handleCopySessionId:ne,handleUnshareSession:fe,openSidebarMenuKey:S,setOpenSidebarMenuKey:N,createFolderAndStartRename:ue,handleDeleteSession:ce,handleRestoreSession:R,startSessionWorktreeMenuLoad:T,mobileVariant:j,alwaysShowActions:I,pinnedSessionIds:h,node:n,depth:_,groupDirectory:i,projectId:o,archivedBucket:K,secondaryMeta:a,renderContext:G,subtreeContainsEditing:$,menuOpenSessionId:de,nodeStructureKey:ie,relativeTimeTick:Ae,children:Be}),e[92]=I,e[93]=K,e[94]=z,e[95]=ue,e[96]=_,e[97]=m,e[98]=v,e[99]=f,e[100]=i,e[101]=g,e[102]=j,e[103]=n,e[104]=p,e[105]=w,e[106]=S,e[107]=h,e[108]=o,e[109]=G,e[110]=a,e[111]=ee.handleCancelEdit,e[112]=ee.handleCopySessionId,e[113]=ee.handleCopyShareUrl,e[114]=ee.handleDeleteSession,e[115]=ee.handleRestoreSession,e[116]=ee.handleSaveEdit,e[117]=ee.handleSessionDoubleClick,e[118]=ee.handleSessionSelect,e[119]=ee.handleShareSession,e[120]=ee.handleUnshareSession,e[121]=b,e[122]=x,e[123]=N,e[124]=T,e[125]=$,e[126]=de,e[127]=ie,e[128]=Ae,e[129]=Be,e[130]=y,e[131]=Ce):Ce=e[131];let q;e[132]!==W||e[133]!==n.session.id||e[134]!==ee.confirmDeleteSession||e[135]!==E||e[136]!==Y||e[137]!==se?(q=W?.session.id===n.session.id?s.jsx(Gj,{value:W,setValue:E,showDeletionDialog:se,setShowDeletionDialog:Y,onConfirm:ee.confirmDeleteSession}):null,e[132]=W,e[133]=n.session.id,e[134]=ee.confirmDeleteSession,e[135]=E,e[136]=Y,e[137]=se,e[138]=q):q=e[138];let Ee;return e[139]!==Ce||e[140]!==q?(Ee=s.jsxs(s.Fragment,{children:[Ce,q]}),e[139]=Ce,e[140]=q,e[141]=Ee):Ee=e[141],Ee}function Xj(t){return t.setShowDeletionDialog}function Jj(t){return t.showDeletionDialog}function Zj(t){return t.toggleFolderCollapse}function e2(t){return t.createFolder}const t2=50,s2=28,kc=[],n2=t=>{const e=Xe.c(6),{nodes:n,includeUnreadSubtasks:r,children:i}=t;let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=rm(o);let a;return e[3]!==i||e[4]!==l?(a=i(l),e[3]=i,e[4]=l,e[5]=a):a=e[5],a},Nr=(t,e)=>e?t.sessions.some(n=>Gn(n,e)):!1,r2=(t,e,n)=>t.sessions.some(r=>im(r,r,e,n,t.directory,t.directory)),o2=(t,e,n)=>{const r=i=>{const o=i.session.id;return e.get(o)!==n.get(o)?!0:i.children.some(r)};return t.sessions.some(r)},i2=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",i=o=>{const l=`project:${r}:${o.session.id}`;return e.has(l)!==n.has(l)?!0:o.children.some(i)};return t.sessions.some(i)},a2=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.sessionBatchSize!==e.sessionBatchSize||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&r2(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.sessionOrderIndex!==e.sessionOrderIndex&&o2(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.expandedParents!==e.expandedParents&&i2(e.group,t.expandedParents,e.expandedParents)||t.editingId!==e.editingId&&(Nr(e.group,t.editingId)||Nr(e.group,e.editingId))||t.editTitle!==e.editTitle&&Nr(e.group,e.editingId)||t.copiedSessionId!==e.copiedSessionId&&(Nr(e.group,t.copiedSessionId)||Nr(e.group,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=e.group.isArchivedBucket===!0,r=Kr(e.group.sessions,t.openSidebarMenuKey,"project",n),i=Kr(e.group.sessions,e.openSidebarMenuKey,"project",n);if(r||i)return!1}if(t.folderRename!==e.folderRename){const n=e.group.folderScopes?.map(r=>r.scopeKey)??[e.group.folderScopeKey??ct(e.group.directory??null)];if(n.includes(t.folderRename?.scopeKey??null)||n.includes(e.folderRename?.scopeKey??null))return!1}return t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef&&t.notifyOnSubtasks===e.notifyOnSubtasks&&t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.toggleParent===e.toggleParent&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.allowReselect===e.allowReselect&&t.onSessionSelected===e.onSessionSelected&&t.isSessionSearchOpen===e.isSessionSearchOpen&&t.sessionSearchQuery===e.sessionSearchQuery&&t.setSessionSearchQuery===e.setSessionSearchQuery&&t.setIsSessionSearchOpen===e.setIsSessionSearchOpen&&t.deleteSessionConfirm===e.deleteSessionConfirm&&t.setDeleteSessionConfirm===e.setDeleteSessionConfirm&&t.startFolderRename===e.startFolderRename&&t.setCopiedSessionId===e.setCopiedSessionId&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.setFolderRenameDraft===e.setFolderRenameDraft&&t.clearFolderRename===e.clearFolderRename};function l2(t){const{t:e}=pt(),{group:n,groupKey:r,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,groupSearchDataByGroup:u,visibleSessionCount:d,sessionBatchSize:h,collapsedGroups:f,hideDirectoryControls:g,showMoreGroupSessions:p,resetGroupSessionLimit:w,mobileVariant:v,alwaysShowActions:x,activeProjectId:m,setActiveProjectIdOnly:b,setSessionSwitcherOpen:y,openNewSessionDraft:S,pinnedSessionIds:N,sessionOrderIndex:C,notifyOnSubtasks:k,onToggleCollapsedGroup:A,dragHandleProps:D,compactBodyPadding:P=!1,scrollContainerRef:F,expandedParents:W,editingId:E,openSidebarMenuKey:H,editTitle:z,copiedSessionId:B,folderRename:T,setFolderRenameDraft:j,clearFolderRename:I}=t,_=cs(Oe=>Oe.toggleFolderCollapse),K=cs(Oe=>Oe.renameFolder),G=cs(Oe=>Oe.deleteFolder),Q=cs(Oe=>Oe.addSessionToFolder),ge=De(Oe=>Oe.showDeletionDialog),[se,Y]=c.useState(null),te=c.useCallback((Oe,Ke)=>{const et=C.get(Oe.session.id),dt=C.get(Ke.session.id);if(et!==void 0||dt!==void 0){if(et===void 0)return 1;if(dt===void 0)return-1;if(et!==dt)return et-dt}return $d(Oe.session,Ke.session,N,Dd)},[N,C]),he=l?u.get(n):null,L=l?!1:f.has(r),le=c.useMemo(()=>{if(n.isMain||n.isArchivedBucket||o)return null;const Oe=ct(n.directory??null),Ke=n.branch?.trim();return Oe&&Ke?Yo(Oe,Ke):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,o]),Z=Od(le),ue=Z?`var(--pr-${Z.visualState})`:void 0,V=Pa(),ee=c.useMemo(()=>{const Oe=n.folderScopes?.map(Ke=>ct(Ke.directory))??[ct(n.directory??null)];return[...new Set(Oe.filter(Ke=>!!Ke))]},[n.directory,n.folderScopes]);c.useSyncExternalStore(c.useCallback(Oe=>ee.length>0?V.subscribeBootstrap(Oe):()=>{},[ee.length,V]),c.useCallback(()=>ee.map(Oe=>`${Oe}\0${V.getBootstrapState(Oe)??""}\0${V.getBootstrapFailure(Oe)??""}`).join(""),[ee,V]),c.useCallback(()=>"",[]));const be=ee.some(Oe=>{const Ke=V.getBootstrapState(Oe);return Ke==="queued"||Ke==="running"}),xe=ee.find(Oe=>V.getBootstrapState(Oe)==="failed")??null,Ne=xe?V.getBootstrapFailure(xe):void 0,Pe=Ne==="os-permission"&&Hm(),[Se,Re]=c.useState(!1),ye=c.useCallback(()=>{xe&&V.requestBootstrap({directory:xe,priority:L?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[V,xe,n.isMain,L]),pe=c.useCallback(async()=>{if(!(!xe||!Pe||Se)){Re(!0);try{(await Gm(xe)).success&&ye()}finally{Re(!1)}}},[Pe,xe,Se,ye]),me=h??(g?10:5),je=Math.max(me,d??me),ne=l?he?.groupMatches===!0:!1,fe=l,ce=c.useMemo(()=>[...fe?he?.filteredNodes??[]:n.sessions].sort(te),[te,n.sessions,he?.filteredNodes,fe]),R=n.folderScopeKey??ct(n.directory??null),$=c.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:R?[{scopeKey:R,directory:n.directory??null}]:[],[R,n.directory,n.folderScopes]),de=cs(Xn(c.useCallback(Oe=>$.map(({scopeKey:Ke})=>Oe.foldersMap[Ke]??kc),[$]))),ie=c.useMemo(()=>$.flatMap(({scopeKey:Oe,directory:Ke},et)=>(de[et]??kc).map(ut=>({folder:ut,scopeKey:Oe,scopeDirectory:Ke}))),[de,$]),Ae=cs(Xn(c.useCallback(Oe=>new Set(de.flatMap(Ke=>Ke.filter(et=>Oe.collapsedFolderIds.has(et.id)).map(et=>et.id))),[de]))),Be=c.useMemo(()=>{const Oe=new Map,Ke=et=>{et.forEach(dt=>{Oe.set(dt.session.id,dt),dt.children.length>0&&Ke(dt.children)})};return Ke(ce),Oe},[ce]),Ce=c.useMemo(()=>ie.map(({folder:Oe,scopeKey:Ke,scopeDirectory:et})=>{const dt=Q0(Oe.sessionIds,Be).sort(te);return{folder:Oe,scopeKey:Ke,scopeDirectory:et,nodes:dt}}),[ie,Be,te]),q=c.useMemo(()=>{const Oe=X0(Ce.map(({folder:Ke,nodes:et})=>({id:Ke.id,name:Ke.name,parentId:Ke.parentId,nodeCount:et.length})),{archivedBucket:n.isArchivedBucket===!0,searchQuery:l?a:""});return Ce.filter(({folder:Ke})=>Oe.has(Ke.id))},[Ce,n.isArchivedBucket,l,a]),Ee=E,Me=H,O=W,oe=c.useMemo(()=>new Set(q.flatMap(Oe=>Oe.folder.sessionIds)),[q]),re=c.useMemo(()=>ce.filter(Oe=>!oe.has(Oe.session.id)),[ce,oe]),we=c.useMemo(()=>{const Oe=new Map(q.map(Ke=>[Ke.folder.id,Ke]));return Y0(q.map(Ke=>Ke.folder)).map(Ke=>Oe.get(Ke.id)).filter(Ke=>!!Ke)},[q]),Ve=c.useMemo(()=>{const Oe=new Map;return q.forEach(Ke=>{if(!Ke.folder.parentId)return;const et=Oe.get(Ke.folder.parentId)??[];et.push(Ke),Oe.set(Ke.folder.parentId,et)}),Oe},[q]),st=c.useMemo(()=>{const Oe=new Map(q.map(dt=>[dt.folder.id,dt])),Ke=new Map,et=(dt,ut)=>{const St=Ke.get(dt);if(St!==void 0)return St;if(ut.has(dt))return[];ut.add(dt);const ot=Oe.get(dt),Lt=ot?[...ot.nodes]:[];for(const Qt of Ve.get(dt)??[])Lt.push(...et(Qt.folder.id,ut));return Ke.set(dt,Lt),Lt};return q.forEach(({folder:dt})=>et(dt.id,new Set)),Ke},[q,Ve]),Ge="project",ae=c.useMemo(()=>{const Oe=new Set;return ta(ce,Ee,Oe),q.forEach(({nodes:Ke})=>{ta(Ke,Ee,Oe)}),Oe},[ce,q,Ee]),X=c.useMemo(()=>{if(!Me)return null;const Oe=Kr(ce,Me,Ge,!!n.isArchivedBucket);if(Oe)return Oe;for(const{nodes:Ke}of q){const et=Kr(Ke,Me,Ge,!!n.isArchivedBucket);if(et)return et}return null},[Me,ce,q,n.isArchivedBucket]),ve=c.useCallback(Oe=>{const Ke=new WeakMap,et=dt=>{Ke.set(dt,Wo(dt));for(const ut of dt.children)et(ut)};return Oe.forEach(et),Ke},[]),Le=c.useMemo(()=>ve(ce),[ve,ce]),$e=c.useMemo(()=>{const Oe=new WeakMap;return q.forEach(({nodes:Ke})=>{Ke.forEach(et=>Oe.set(et,Wo(et)))}),Oe},[q]),Ue=c.useCallback(Oe=>Le.get(Oe)??$e.get(Oe)??"",[Le,$e]),We=c.useCallback(Oe=>({subtreeContainsEditing:ae,menuOpenSessionId:X,nodeStructureKey:Ue(Oe)}),[ae,X,Ue]),qe=re.length,nt=n.isArchivedBucket||l?re:re.slice(0,je),yt=qe-nt.length,vt=!n.isArchivedBucket&&!l&&qe>me&&yt===0,He=n.isArchivedBucket===!0&&!l&&nt.length>=t2,Mt=n.isArchivedBucket?"archived":"active",jt=He&&nt.some(Oe=>{if(Oe.children.length===0)return!1;const Ke=`project:${Mt}:${Oe.session.id}`;return O.has(Ke)}),kt=c.useRef(null),[Tt,wt]=c.useState(null),[Nt,Dt]=c.useState(0),[,ft]=c.useState(0);c.useEffect(()=>{if(!He)return;const Oe=kt.current;if(!Oe||!globalThis.ResizeObserver)return;const Ke=new ResizeObserver(()=>ft(et=>et+1));return Ke.observe(Oe),()=>Ke.disconnect()},[He]),c.useLayoutEffect(()=>{if(!He){Tt!==null&&wt(null),Nt!==0&&Dt(0);return}const Oe=kt.current;if(!Oe)return;let Ke=Tt;const et=F?.current??null;if(et&&et.contains(Oe)){if(Ke=et,Ke!==Tt){wt(Ke);return}}else if(!Ke||!Ke.contains(Oe)){let ut=Oe.parentElement;for(;ut;){const St=window.getComputedStyle(ut);if(St.overflowY==="auto"||St.overflowY==="scroll"){Ke=ut;break}ut=ut.parentElement}if(Ke!==Tt){wt(Ke);return}}if(!Ke)return;const dt=Oe.getBoundingClientRect().top-Ke.getBoundingClientRect().top+Ke.scrollTop;Dt(ut=>Math.abs(ut-dt)<1?ut:dt)});const Ze=He&&Tt!==null,ke=Dg({count:nt.length,enabled:Ze,getScrollElement:()=>Tt,initialOffset:()=>Tt?.scrollTop??0,estimateSize:()=>s2,overscan:jt?20:8,scrollMargin:Nt,getItemKey:Oe=>nt[Oe]?.session.id??Oe}),tt=c.useCallback(Oe=>{const Ke=[],et=dt=>{dt.forEach(ut=>{Ke.push(ut.session),ut.children.length>0&&et(ut.children)})};return et(Oe),Ke},[]),lt=c.useMemo(()=>tt(ce),[tt,ce]),At=c.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Oe=new Map,Ke=new Map;for(const{folder:dt}of q){if(!dt.parentId)continue;const ut=Ke.get(dt.parentId)??[];ut.push(dt.id),Ke.set(dt.parentId,ut)}const et=(dt,ut)=>{if(ut.has(dt))return[];ut.add(dt);const St=q.find(({folder:Qt})=>Qt.id===dt),ot=St?tt(St.nodes):[],Lt=Ke.get(dt)??[];for(const Qt of Lt)ot.push(...et(Qt,ut));return ot};for(const{folder:dt}of q)Oe.set(dt.id,et(dt.id,new Set));return Oe},[q,tt,n.isArchivedBucket]);if(l&&!ne&&we.length===0&&re.length===0)return null;const Ye=!n.isMain&&!!n.branch,rt=n.branch&&kh(n.branch,n.label)?{label:n.branch}:null,It=L?s.jsx(I0,{nodes:ce,includeUnreadSubtasks:k}):null,Ct=(Oe,Ke)=>{const{folder:et,scopeKey:dt,scopeDirectory:ut,nodes:St}=Oe,ot=At.get(et.id)??[],Lt=T?.folderId===et.id&&T?.scopeKey===dt,Qt=l?!1:Ae.has(et.id),us=$s=>s.jsx(U0,{folderId:et.id,children:(rs,Is)=>s.jsx(R0,{folder:et,displayName:Ke,sessions:St,isCollapsed:Qt,collapsedActivityState:$s,onToggle:()=>_(et.id),onRename:ss=>{K(dt,et.id,ss)},onDelete:()=>{if(n.isArchivedBucket){hn.requestDelete({sessions:ot,mode:"session"});return}if(!ge){G(dt,et.id);return}const ss=q.filter(({folder:Ws})=>Ws.parentId===et.id).length,Ns=St.length;Y({scopeKey:dt,folderId:et.id,folderName:et.name,subFolderCount:ss,sessionCount:Ns})},groupDirectory:ut??n.directory,projectId:i,mobileVariant:v,alwaysShowActions:x,isRenaming:Lt,renameDraft:Lt?T?.draft:void 0,onRenameDraftChange:j,onRenameSave:()=>{const ss=T?.draft.trim()??"";ss&&K(dt,et.id,ss),I()},onRenameCancel:I,droppableRef:rs,isDropTarget:Is,depth:0,onNewSession:()=>{i&&i!==m&&b(i),v&&y(!1),S({selectedProjectId:i,directoryOverride:ut??n.directory,targetFolderId:et.id,target:n.draftTarget})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0,children:St.map(ss=>s.jsx(zo,{node:ss,pinnedSessionIds:N,expandedParents:W,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:E,editTitle:z,copiedSessionId:B,openSidebarMenuKey:H,mobileVariant:v,alwaysShowActions:x,groupDirectory:ut??n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:ae,menuOpenSessionId:X,nodeStructureKey:Ue(ss),childRenderExtrasFor:We},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},ss.session.id))})},et.id);return Qt?s.jsx(n2,{nodes:st.get(et.id)??St,includeUnreadSubtasks:k,children:us},et.id):us(null)},Pt=()=>{const Oe=new Map;for(const ut of q){const St=ut.folder.parentId;if(!St)continue;const ot=Oe.get(St);ot?ot.push(ut):Oe.set(St,[ut])}const Ke=[],et=new Set,dt=(ut,St)=>{if(et.has(ut.folder.id))return;et.add(ut.folder.id);const ot=St?`${St} / ${ut.folder.name}`:ut.folder.name;Ke.push(Ct(ut,ot)),!(!l&&Ae.has(ut.folder.id))&&(Oe.get(ut.folder.id)??[]).forEach(Qt=>dt(Qt,ot))};return we.forEach(ut=>dt(ut,"")),Ke},Wt=!!(!n.isMain&&n.worktree),Yt=x?Wt?"pr-14":"pr-7":Wt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",Kt=xe?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(Ne==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),Pe?s.jsx(at,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:Se,onClick:()=>{pe()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(at,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:ye,children:e("sessions.sidebar.group.empty.retry")})]}):null,Bt=Oe=>s.jsx(zo,{node:Oe,pinnedSessionIds:N,expandedParents:W,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:E,editTitle:z,copiedSessionId:B,openSidebarMenuKey:H,mobileVariant:v,alwaysShowActions:x,groupDirectory:n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:ae,menuOpenSessionId:X,nodeStructureKey:Ue(Oe),childRenderExtrasFor:We},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},Oe.session.id),ts=s.jsxs(K0,{scopeKey:$[0]?.scopeKey??R,hasFolders:q.length>0,onSessionDroppedOnFolder:(Oe,Ke)=>{const et=q.find(({folder:ut})=>ut.id===Ke);if(!et)return;const dt=cs.getState();for(const{scopeKey:ut}of $)ut!==et.scopeKey&&dt.getSessionFolderId(ut,Oe)&&dt.removeSessionFromFolder(ut,Oe);Q(et.scopeKey,Ke,Oe)},children:[Pt(),He?s.jsx("div",{ref:kt,children:Ze?s.jsx("div",{style:{height:ke.getTotalSize(),position:"relative"},children:ke.getVirtualItems().map(Oe=>{const Ke=nt[Oe.index];return Ke?s.jsx("div",{"data-index":Oe.index,ref:ke.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Oe.start-Nt}px)`},children:Bt(Ke)},Ke.session.id):null})}):nt.map(Bt)}):nt.map(Bt),qe===0&&q.length===0?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):be?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(M,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Kt||(n.emptyMessage??e("sessions.sidebar.group.empty.noSessionsInWorkspace"))}):null,qe>0&&Kt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Kt}):null,yt>0?s.jsx("button",{type:"button",onClick:()=>p(r,nt.length,h??7),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,vt?s.jsx("button",{type:"button",onClick:()=>w(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),zt="pb-2",_t=s.jsx(Qj,{value:se,setValue:Y,onConfirm:()=>{const Oe=se;Oe&&(G(Oe.scopeKey,Oe.folderId),Y(null))}});return o?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Te("oc-group-body",zt),children:ts})}),_t]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Te("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>A(r),role:"button",tabIndex:0,onKeyDown:Oe=>{(Oe.key==="Enter"||Oe.key===" ")&&(Oe.preventDefault(),A(r))},"aria-label":L?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!L,children:[s.jsx("div",{ref:D?.setActivatorNodeRef,className:Te("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",Yt),...D?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(M,{name:"archive",className:Te("h-3.5 w-3.5 shrink-0 text-muted-foreground",x?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Te("text-muted-foreground h-3.5 w-3.5 items-center justify-center",x?"inline-flex":"hidden group-hover/gh:inline-flex"),children:L?s.jsx(M,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:xo(n.label,a)}),It]}):!n.isMain||n.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(M,{name:"git-branch",className:Te("h-3.5 w-3.5 shrink-0",!ue&&"text-muted-foreground",x?"hidden":"group-hover/gh:hidden"),style:ue?{color:ue}:void 0}),s.jsx("span",{className:Te("text-muted-foreground h-3.5 w-3.5 items-center justify-center",x?"inline-flex":"hidden group-hover/gh:inline-flex"),children:L?s.jsx(M,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-semibold text-muted-foreground",children:xo(n.label,a)}),It,Z?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:ue?{color:ue}:void 0,children:["#",Z.number]}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:xo(n.label,a)}),It]})}),Ye&&rt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(M,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(M,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:rt.label})]}):null]})}),n.isArchivedBucket&<.length>0?s.jsx("div",{className:Te("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),hn.requestDelete({sessions:lt,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(M,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Te("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),hn.requestDelete({sessions:lt,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(M,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Te("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",x?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),i&&i!==m&&b(i),v&&y(!1),S({selectedProjectId:i,directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(M,{name:"add",className:"h-4 w-4"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),L?null:s.jsx("div",{className:Te("oc-group-body",zt),children:ts})]}),_t]})}const Co=c.memo(l2,a2),c2=(t,e,n)=>e?t.filter(r=>r.project.id===n):t,d2=t=>t?"top-content":"empty-state",u2=(t,e)=>{const n=t.groups.find(o=>o.isMain&&o.sessions.length>0)??t.groups.find(o=>o.sessions.length>0)??t.groups.find(o=>o.isMain)??t.groups[0];if(!n)return[];const r=t.groups.find(o=>o.isArchivedBucket&&o.id!==n.id);return[n,...r?[r]:[]].map(o=>({group:o,groupKey:`${t.project.id}:${o.id}`,projectId:t.project.id,hideGroupLabel:o.id===n.id}))},m2=48,f2=32,h2=24,bi=(t,e)=>Da(t.label?.trim()||Fn(t.normalizedPath,e)||t.normalizedPath);function p2(t){const e=Xe.c(42);qs("ui.sidebar_projects_list.render");const{t:n}=pt(),{model:r,view:i,actions:o}=t,l=r.state.editingId!==null,a=i.isDesktopShellRuntime&&i.stickyZoneHeaders&&!r.singleProjectMode;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={activationConstraint:{distance:8}},e[0]=u):u=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={coordinateGetter:xg},e[1]=d):d=e[1];const h=Lr(En(Fi,u),En(pg,d));let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f={activationConstraint:{distance:8}},e[2]=f):f=e[2];const g=Lr(En(Fi,f)),p=c.useRef(null),w=c.useRef(0);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=he=>{const le=he.scrollTop>1?Math.min(f2+he.scrollTop,m2):0;w.current=le;const Z=he.closest(".oc-sticky-fade-root");Z?.style.setProperty("--scroll-shadow-top-size",`${le}px`),Z?.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(le-8,0),h2)}px`)},e[3]=v):v=e[3];const x=v;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=he=>{he.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||he.clientY-he.currentTarget.getBoundingClientRect().top>=w.current||(he.preventDefault(),he.stopPropagation())},e[4]=m):m=e[4];const b=m,y=c2(r.sectionsForRender,r.singleProjectMode,r.singleProjectId),S=r.projectSections.length>0&&y.length>0;let N,C;e[5]!==a||e[6]!==S?(N=()=>{a&&S&&p.current&&x(p.current)},C=[a,S,x],e[5]=a,e[6]=S,e[7]=N,e[8]=C):(N=e[7],C=e[8]),c.useLayoutEffect(N,C);let k=null;for(const he of r.projectSections)r.stuckProjectHeaders.has(he.project.id)&&(k=he.project);const A=k??(r.hasSharedSessions?null:y[0]?.project??null),D=A?bi(A,i.homeDirectory):null;let P;if(e[9]!==r.projectSections||e[10]!==i.homeDirectory){let he;e[12]!==i.homeDirectory?(he=L=>({id:L.project.id,projectLabel:bi(L.project,i.homeDirectory),projectDescription:_r(L.project.normalizedPath,i.homeDirectory),projectIcon:L.project.icon,projectColor:L.project.color,projectIconImage:L.project.iconImage,projectIconBackground:L.project.iconBackground}),e[12]=i.homeDirectory,e[13]=he):he=e[13],P=r.projectSections.map(he),e[9]=r.projectSections,e[10]=i.homeDirectory,e[11]=P}else P=e[11];const F=P;if(r.projectSections.length===0){let he;return e[14]!==r.emptyState||e[15]!==r.topContent?(he=s.jsxs(kn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:[r.topContent,r.emptyState]}),e[14]=r.emptyState,e[15]=r.topContent,e[16]=he):he=e[16],he}if(r.sectionsForRender.length===0){const L=d2(r.topContentHasSearchMatches===!0)==="top-content"?r.topContent:r.searchEmptyState;let le;return e[17]!==L?(le=s.jsx(kn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:L}),e[17]=L,e[18]=le):le=e[18],le}const W="oc-sticky-fade-root relative flex min-h-0 flex-1";let E;e[19]!==a?(E=a?{"--scroll-shadow-top-size":"0px"}:void 0,e[19]=a,e[20]=E):E=e[20];const H=a?b:void 0,z=a?b:void 0,B=a?b:void 0,T=kn,j=!0,I=!a,_=96,K="flex-1 min-h-0",G="oc-sidebar-scroller oc-sticky-fade-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]";let Q;e[21]!==a?(Q=a?he=>x(he.currentTarget):void 0,e[21]=a,e[22]=Q):Q=e[22];const ge=i.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const he=y.find(le=>le.project.id===r.activeProjectId)??y[0];if(!he)return i.hasSessionSearchQuery?r.searchEmptyState:r.emptyState;const L=u2(he);return L.length?L.map(le=>{const{group:Z,groupKey:ue,projectId:V,hideGroupLabel:ee}=le;return s.jsx(c.Fragment,{children:s.jsx(Co,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:Z,groupKey:ue,projectId:V,hideGroupLabel:ee,visibleSessionCount:r.state.visibleSessionCountByGroup.get(ue),compactBodyPadding:!0,scrollContainerRef:p})},ue)}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})()}):s.jsxs($r,{sensors:h,collisionDetection:Wr,onDragEnd:he=>{if(l||i.projectSortOrder!=="manual")return;const{active:L,over:le}=he;if(!le||L.id===le.id)return;const Z=r.sectionsForRender.findIndex(V=>V.project.id===L.id),ue=r.sectionsForRender.findIndex(V=>V.project.id===le.id);Z===-1||ue===-1||Z===ue||o.reorderProjects(Z,ue)},children:[s.jsx(Eo,{items:y.map(y2),strategy:_i,children:y.map(he=>{const L=he.project,le=L.id,Z=bi(L,i.homeDirectory),ue=_r(L.normalizedPath,i.homeDirectory),V=r.singleProjectMode?!1:i.collapsedProjects.has(le),ee=r.projectRepoStatus.get(le);return s.jsx(v0,{id:le,disabled:r.singleProjectMode||i.projectSortOrder!=="manual",projectLabel:Z,projectDescription:ue,projectIcon:L.icon,projectColor:L.color,projectIconImage:L.iconImage,projectIconBackground:L.iconBackground,isCollapsed:V,isRepo:!!ee,isDesktopShell:i.isDesktopShellRuntime,hideDirectoryControls:i.hideDirectoryControls,mobileVariant:i.mobileVariant,alwaysShowActions:i.alwaysShowActions,statusIndicator:V?o.renderProjectStatusIndicator?.(le,he.groups):null,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,projectPickerOptions:r.singleProjectMode?F:void 0,onProjectSelect:r.singleProjectMode?o.setSingleProjectId:void 0,onToggle:()=>{r.singleProjectMode||o.toggleProject(le)},onNewSession:()=>{le!==r.activeProjectId&&o.setActiveProjectIdOnly(le),i.mobileVariant&&o.setSessionSwitcherOpen(!1),o.openNewSessionDraft({selectedProjectId:le,directoryOverride:L.normalizedPath})},onNewWorktreeSession:()=>{le!==r.activeProjectId&&o.setActiveProjectIdOnly(le),o.openNewWorktreeDialog()},onManageWorktrees:()=>o.openWorktreesPage(le),onRenameStart:()=>o.openProjectEditDialog(le),onClose:()=>o.removeProject(le),sentinelRef:be=>{r.projectHeaderSentinelRefs.current.set(le,be)},showCreateButtons:!0,children:V?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const be=he.groups,xe=be.find(b2)??null,Ne=xe?be.filter(Pe=>Pe.id!==xe.id):be;return s.jsxs($r,{sensors:g,collisionDetection:Wr,onDragEnd:Pe=>{if(l)return;const{active:Se,over:Re}=Pe;if(!Re||Se.id===Re.id)return;const ye=Ne.findIndex(ne=>ne.id===Se.id),pe=Ne.findIndex(ne=>ne.id===Re.id);if(ye===-1||pe===-1||ye===pe)return;const me=ru(Ne,ye,pe).map(x2),je=xe?[xe.id,...me]:me;o.setGroupOrderByProject(ne=>{const fe=new Map(ne);return fe.set(le,je),fe})},children:[xe?s.jsx(Co,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:xe,groupKey:`${le}:${xe.id}`,projectId:le,hideGroupLabel:!0,visibleSessionCount:r.state.visibleSessionCountByGroup.get(`${le}:${xe.id}`),scrollContainerRef:p}):null,s.jsx(Eo,{items:Ne.map(g2),strategy:_i,children:Ne.map(Pe=>{const Se=`${le}:${Pe.id}`;return s.jsx(k0,{id:Pe.id,disabled:l,children:Re=>s.jsx(Co,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:Pe,groupKey:Se,projectId:le,visibleSessionCount:r.state.visibleSessionCountByGroup.get(Se),dragHandleProps:Re,scrollContainerRef:p})},Pe.id)})}),s.jsx(Bi,{dropAnimation:null})]})})()})},le)})}),s.jsx(Bi,{dropAnimation:null})]});let se;e[23]!==T||e[24]!==r.topContent||e[25]!==I||e[26]!==Q||e[27]!==ge?(se=s.jsxs(T,{ref:p,useScrollShadow:j,hideTopScrollShadow:I,scrollShadowSize:_,outerClassName:K,className:G,onScroll:Q,children:[r.topContent,ge]}),e[23]=T,e[24]=r.topContent,e[25]=I,e[26]=Q,e[27]=ge,e[28]=se):se=e[28];let Y;e[29]!==a||e[30]!==A||e[31]!==D||e[32]!==r.hasSharedSessions||e[33]!==n?(Y=a&&(A||r.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:A&&D?s.jsx(jo,{id:A.id,projectLabel:D,projectIcon:A.icon,projectColor:A.color,projectIconImage:A.iconImage,projectIconBackground:A.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(M,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:n("sessions.sidebar.activity.recentTitle")})]})}):null,e[29]=a,e[30]=A,e[31]=D,e[32]=r.hasSharedSessions,e[33]=n,e[34]=Y):Y=e[34];let te;return e[35]!==H||e[36]!==z||e[37]!==B||e[38]!==se||e[39]!==Y||e[40]!==E?(te=s.jsxs("div",{className:W,style:E,onPointerDownCapture:H,onClickCapture:z,onContextMenuCapture:B,children:[se,Y]}),e[35]=H,e[36]=z,e[37]=B,e[38]=se,e[39]=Y,e[40]=E,e[41]=te):te=e[41],te}function g2(t){return t.id}function x2(t){return t.id}function b2(t){return t.isMain}function y2(t){return t.project.id}const w2=c.memo(p2),aa=new Map,Cc=(t,e)=>{for(const n of t){const r=ct(n??null);r&&!aa.has(r)&&aa.set(r,e)}},Nc=t=>{const e=ct(t??null);return e?aa.get(e)??0:0},mo=t=>!!t.time?.archived,S2=t=>{const{t:e}=pt(),n=c.useRef(t.gitBranches);n.current=t.gitBranches;const r=c.useCallback(a=>[a.label,a.branch??"",a.description??"",a.directory??""].join(" ").toLowerCase(),[]),i=c.useCallback(a=>{const u=ct(a.directory??null)??"";return`${(a.title||e("sessions.sidebar.session.untitled")).trim()} ${u}`.toLowerCase()},[e]),o=c.useCallback((a,u)=>u?a.flatMap(d=>{if(Io([i(d.session)],u))return[d];const f=o(d.children,u);return f.length===0?[]:[{...d,children:f}]}):a,[i]),l=c.useCallback((a,u,d,h,f)=>{const g=ct(u??null),p=Rd(a),w=new Map(p.map(B=>[B.id,B])),v=new Map;p.forEach(B=>{const T=B.parentID;if(!T)return;const j=w.get(T);if(!j||mo(j)!==mo(B))return;const I=v.get(T)??[];I.push(B),v.set(T,I)});const x=new Map;d.forEach(B=>{if(B.path){const T=ct(B.path)??B.path;x.set(T,B)}});const m=B=>{const T=ct(B.directory??null),j=t.worktreeMetadata.get(B.id)??null;if(j)return j;if(T){const I=x.get(T)??null;if(I&&T!==g)return I}return null},b=new Set,y=B=>{b.add(B.id);const T=v.get(B.id)??[],j=[];for(const I of T)b.has(I.id)||j.push(y(I));return{session:B,children:j,worktree:m(B)}},S=p.filter(B=>{const T=B.parentID;if(!T)return!0;const j=w.get(T);return j?mo(j)!==mo(B):!0}),N=[],C=B=>{b.has(B.id)||N.push(y(B))};S.forEach(C),p.forEach(C);const k=new Map,A="__archived__",D=B=>{if(B.time?.archived)return A;if(t.isVSCode)return g??"__project_root__";const j=ct(t.worktreeMetadata.get(B.id)?.path??null)??_s(B);return j?j!==g&&x.has(j)?j:j===g?g??"__project_root__":A:A};N.forEach(B=>{const T=D(B.session);k.has(T)||k.set(T,[]),k.get(T)?.push(B)});const P=g??"__project_root__",F=[{id:"root",label:f&&h&&h!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:h}):e("sessions.sidebar.grouping.projectRoot"),branch:h??null,description:g?_r(g,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:g,folderScopeKey:g,sessions:k.get(P)??[]}],W=new Map;d.forEach(B=>{const T=ct(B.path)??B.path,j=k.get(T)??[],I=j.length>0,_=j.reduce((K,G)=>{const Q=Ch(G.session,t.sessionOrderRanks);return Number.isFinite(Q)?Math.max(K,Q):K},0);W.set(T,{hasActiveSession:I,lastUpdatedAt:_})});const E=[...d].sort((B,T)=>{const j=ct(B.path)??B.path,I=ct(T.path)??T.path,_=W.get(j)??{hasActiveSession:!1,lastUpdatedAt:0},K=W.get(I)??{hasActiveSession:!1,lastUpdatedAt:0};if(_.hasActiveSession!==K.hasActiveSession)return _.hasActiveSession?-1:1;if(_.hasActiveSession&&K.hasActiveSession)return K.lastUpdatedAt-_.lastUpdatedAt;const G=Nc(B.path),Q=Nc(T.path);if(G!==Q)return Q-G;const ge=(B.label||B.branch||B.name||B.path||"").toLowerCase(),se=(T.label||T.branch||T.name||T.path||"").toLowerCase();return ge.localeCompare(se)});(t.isVSCode?[]:E).forEach(B=>{const T=ct(B.path)??B.path,j=n.current.get(T)?.trim()||null,I=B.branch?.trim()||null,K=!!(j&&I&&B.label&&il(B.label)===il(I))?j:B.label||B.name||Fn(T,t.homeDirectory)||T;F.push({id:`worktree:${T}`,label:K,branch:j||I,description:_r(T,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:B,directory:T,folderScopeKey:T,sessions:k.get(T)??[]})});const z=k.get(A)??[];return z.length>0&&F.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&g?Td(g):null,sessions:z}),F},[t.homeDirectory,t.worktreeMetadata,t.sessionOrderRanks,t.isVSCode,e]);return{buildGroupSearchText:r,buildSessionSearchText:i,filterSessionNodesForSearch:o,buildGroupedSessions:l}},v2=t=>{const e=Xe.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:i,projectHeaderSentinelRefs:o}=t,l=n===void 0?!0:n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[u,d]=c.useState(a);let h;e[1]!==l||e[2]!==r||e[3]!==o?(h=()=>{if(!l||!r){d(j2);return}const p=Array.from(o.current.values()).find(k2)?.closest(".oc-sidebar-scroller")??null;if(!p)return;const w=new IntersectionObserver(v=>{d(x=>{const m=new Set(x);let b=!1;for(const y of v){const S=y.target.dataset.projectId;if(!S)continue;const N=y.rootBounds?.top??p.getBoundingClientRect().top,C=!y.isIntersecting&&y.boundingClientRect.top<N;m.has(S)!==C&&(b=!0,C?m.add(S):m.delete(S))}return b?m:x})},{root:p,threshold:0});return o.current.forEach(v=>{v&&w.observe(v)}),()=>w.disconnect()},e[1]=l,e[2]=r,e[3]=o,e[4]=h):h=e[4];let f;return e[5]!==l||e[6]!==r||e[7]!==o||e[8]!==i?(f=[l,r,o,i],e[5]=l,e[6]=r,e[7]=o,e[8]=i,e[9]=f):f=e[9],c.useEffect(h,f),u};function j2(t){return t.size===0?t:new Set}function k2(t){return t!==null}const C2=t=>{const e=Xe.c(51),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:o,onMoveToFolder:l,onCreateFolderAndMove:a,onRemoveFromFolder:u,canRemoveFromFolder:d,onRestore:h,onDelete:f,onDone:g}=t,{t:p}=pt(),w=!!r&&!o;let v;e[0]!==o||e[1]!==p?(v=p(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=o,e[1]=p,e[2]=v):v=e[2];const x=v;let m;e[3]!==n||e[4]!==p?(m=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=m):m=e[5];let b;e[6]!==m?(b=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:m}),e[6]=m,e[7]=b):b=e[7];let y;e[8]!==w||e[9]!==d||e[10]!==a||e[11]!==l||e[12]!==u||e[13]!==i||e[14]!==p?(y=w?s.jsxs(Js,{children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(Ys,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(M,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Xs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):i.map(j=>s.jsx($t,{onClick:()=>l(j.id),children:s.jsx("span",{className:"flex-1 truncate",children:j.name})},j.id)),s.jsx(Es,{}),s.jsxs($t,{onClick:a,children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),d?s.jsxs($t,{onClick:u,className:"text-destructive focus:text-destructive",children:[s.jsx(M,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=w,e[9]=d,e[10]=a,e[11]=l,e[12]=u,e[13]=i,e[14]=p,e[15]=y):y=e[15];let S;e[16]!==o||e[17]!==h||e[18]!==p?(S=o?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":p("sessions.sidebar.bulkActions.restore"),children:s.jsx(M,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=o,e[17]=h,e[18]=p,e[19]=S):S=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=Te("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[20]=N):N=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(M,{name:"delete-bin",className:"h-4 w-4"}),e[21]=C):C=e[21];let k;e[22]!==x||e[23]!==f?(k=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:N,"aria-label":x,children:C})}),e[22]=x,e[23]=f,e[24]=k):k=e[24];let A;e[25]!==x?(A=s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x})}),e[25]=x,e[26]=A):A=e[26];let D;e[27]!==k||e[28]!==A?(D=s.jsxs(gt,{children:[k,A]}),e[27]=k,e[28]=A,e[29]=D):D=e[29];let P;e[30]!==p?(P=p("sessions.sidebar.header.actions.exitSelection"),e[30]=p,e[31]=P):P=e[31];let F;e[32]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(M,{name:"close",className:"h-4 w-4"}),e[32]=F):F=e[32];let W;e[33]!==g||e[34]!==P?(W=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:g,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":P,children:F})}),e[33]=g,e[34]=P,e[35]=W):W=e[35];let E;e[36]!==p?(E=p("sessions.sidebar.header.actions.exitSelection"),e[36]=p,e[37]=E):E=e[37];let H;e[38]!==E?(H=s.jsx(bt,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[38]=E,e[39]=H):H=e[39];let z;e[40]!==W||e[41]!==H?(z=s.jsxs(gt,{children:[W,H]}),e[40]=W,e[41]=H,e[42]=z):z=e[42];let B;e[43]!==D||e[44]!==z||e[45]!==y||e[46]!==S?(B=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,S,D,z]}),e[43]=D,e[44]=z,e[45]=y,e[46]=S,e[47]=B):B=e[47];let T;return e[48]!==B||e[49]!==b?(T=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[b,B]}),e[48]=B,e[49]=b,e[50]=T):T=e[50],T},N2=(t,e)=>{if(!t)return[];const n=e(t);return n.length>0?n.map(r=>r.scopeKey):[t]},A2=t=>{const{t:e}=pt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,getFolderScopesForProject:o,addSessionsToFolder:l,removeSessionsFromFolders:a,createFolderAndStartRename:u,archiveSessions:d,unarchiveSessions:h,deleteSessions:f,setBulkDeleteConfirm:g}=t,p=gs(j=>j.enabled),w=gs(j=>j.selectedIds.size),v=w>0,x=gs(j=>j.selectedIds),m=gs(j=>j.scopeKey),b=c.useCallback(()=>{gs.getState().toggleMode()},[]),y=c.useCallback(()=>{gs.getState().disable()},[]),S=c.useMemo(()=>{if(!v||typeof document>"u")return!1;let j=!1,I=!1;for(const _ of x){const K=document.querySelectorAll(`[data-session-row="${CSS.escape(_)}"]`);for(const G of K)G.getAttribute("data-session-archived")==="1"?I=!0:j=!0}return I&&!j},[v,x]),N=c.useMemo(()=>{if(m)return m;if(!v||typeof document>"u")return null;for(const j of x){const _=document.querySelector(`[data-session-row="${CSS.escape(j)}"]`)?.getAttribute("data-session-scope");if(_&&_.length>0)return _}return null},[v,x,m]),C=c.useMemo(()=>N2(N,o),[N,o]),k=c.useMemo(()=>C.flatMap(j=>i[j]??[]),[i,C]),A=c.useCallback(j=>{for(const I of C)if((i[I]??[]).some(_=>_.id===j))return I;return null},[i,C]),D=c.useMemo(()=>{if(!v)return!1;for(const j of C)for(const I of i[j]??[])for(const _ of I.sessionIds)if(x.has(_))return!0;return!1},[i,C,v,x]),P=c.useCallback((j,I)=>{const _=Array.from(x);for(const K of C)K!==j&&a(K,_);l(j,I,_)},[l,a,x,C]),F=c.useCallback(j=>{if(!v)return;const I=A(j);I&&P(I,j)},[v,P,A]),W=c.useCallback(()=>{const j=C[0];if(!j||!v)return;const I=u(j);I&&P(j,I.id)},[u,v,P,C]),E=c.useCallback(()=>{if(!v)return;const j=Array.from(x);for(const I of C)a(I,j)},[a,x,C,v]),H=c.useCallback(async()=>{const j=Array.from(x);if(j.length!==0){if(S){const{deletedIds:I,failedIds:_}=await f(j);I.length>0&&Fe.success(I.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:I.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:I.length})),_.length>0&&Fe.error(_.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:_.length}))}else{const{archivedIds:I,failedIds:_}=await d(j);I.length>0&&Fe.success(I.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:I.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:I.length})),_.length>0&&Fe.error(_.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:_.length}))}gs.getState().clear()}},[d,S,f,x,e]),z=c.useCallback(()=>{if(!v)return;const j=x.size;if(!r){H();return}g({sessionCount:j,archivedBucket:S})},[S,H,x,r,g,v]),B=c.useCallback(async()=>{if(!v||!S)return;const j=Array.from(x),{restoredIds:I,failedIds:_}=await h(j);I.length>0&&Fe.success(I.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:I.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:I.length})),_.length>0&&Fe.error(_.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:_.length})),gs.getState().clear()},[S,v,x,e,h]),T=c.useCallback(async()=>{g(null),await H()},[H]);return c.useEffect(()=>{if(!p)return;const j=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),I=_=>{if(n)return;const K=_.target;if(K&&(K.tagName==="INPUT"||K.tagName==="TEXTAREA"||K.isContentEditable))return;const G=j?_.metaKey:_.ctrlKey;if(_.key==="Escape"){_.preventDefault(),gs.getState().disable();return}if(G&&_.key==="Backspace"){_.preventDefault(),z();return}if(G&&(_.key==="a"||_.key==="A")){const Q=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Q.length===0)return;_.preventDefault();const se=gs.getState().scopeKey??Q[0]?.getAttribute("data-session-scope")??null,Y=he=>se?he.getAttribute("data-session-scope")===se:!0,te=Q.filter(Y).map(he=>he.getAttribute("data-session-row")).filter(he=>typeof he=="string"&&he.length>0);if(te.length===0)return;gs.getState().replaceAll(te,se||null)}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[z,n,p]),{selectionModeEnabled:p,hasSelection:v,selectedIdsSize:w,bulkScopeIsArchived:S,derivedSelectionScope:N,bulkScopeFolders:k,bulkCanRemoveFromFolder:D,handleToggleSelectionMode:b,handleExitSelectionMode:y,handleBulkMoveToFolder:F,handleBulkCreateFolderAndMove:W,handleBulkRemoveFromFolder:E,handleBulkDelete:z,handleBulkRestore:B,confirmBulkDelete:T}};function D2(t){const e=Xe.c(36),{getFolderScopesForProject:n,isInlineEditing:r,startFolderRename:i}=t,[o,l]=c.useState(null),a=De(B2),u=De(F2),d=cs(O2),h=cs(M2),f=cs(E2),g=cs(R2),p=Qe(T2),w=Qe(I2),v=Qe(P2);let x;e[0]!==h||e[1]!==i?(x=C=>{const k=h(C,"New folder");return i(C,k),k},e[0]=h,e[1]=i,e[2]=x):x=e[2];let m;e[3]!==f||e[4]!==p||e[5]!==v||e[6]!==d||e[7]!==n||e[8]!==r||e[9]!==g||e[10]!==a||e[11]!==x||e[12]!==w?(m={isInlineEditing:r,showDeletionDialog:a,foldersMap:d,getFolderScopesForProject:n,addSessionsToFolder:f,removeSessionsFromFolders:g,createFolderAndStartRename:x,archiveSessions:p,unarchiveSessions:w,deleteSessions:v,setBulkDeleteConfirm:l},e[3]=f,e[4]=p,e[5]=v,e[6]=d,e[7]=n,e[8]=r,e[9]=g,e[10]=a,e[11]=x,e[12]=w,e[13]=m):m=e[13];const b=A2(m);let y;e[14]!==b.bulkCanRemoveFromFolder||e[15]!==b.bulkScopeFolders||e[16]!==b.bulkScopeIsArchived||e[17]!==b.derivedSelectionScope||e[18]!==b.handleBulkCreateFolderAndMove||e[19]!==b.handleBulkDelete||e[20]!==b.handleBulkMoveToFolder||e[21]!==b.handleBulkRemoveFromFolder||e[22]!==b.handleBulkRestore||e[23]!==b.handleExitSelectionMode||e[24]!==b.hasSelection||e[25]!==b.selectedIdsSize||e[26]!==b.selectionModeEnabled?(y=b.selectionModeEnabled&&b.hasSelection?s.jsx(C2,{selectedCount:b.selectedIdsSize,scopeKey:b.derivedSelectionScope,scopeFolders:b.bulkScopeFolders,archivedBucket:b.bulkScopeIsArchived,onMoveToFolder:b.handleBulkMoveToFolder,onCreateFolderAndMove:b.handleBulkCreateFolderAndMove,onRemoveFromFolder:b.handleBulkRemoveFromFolder,canRemoveFromFolder:b.bulkCanRemoveFromFolder,onRestore:b.handleBulkRestore,onDelete:b.handleBulkDelete,onDone:b.handleExitSelectionMode}):null,e[14]=b.bulkCanRemoveFromFolder,e[15]=b.bulkScopeFolders,e[16]=b.bulkScopeIsArchived,e[17]=b.derivedSelectionScope,e[18]=b.handleBulkCreateFolderAndMove,e[19]=b.handleBulkDelete,e[20]=b.handleBulkMoveToFolder,e[21]=b.handleBulkRemoveFromFolder,e[22]=b.handleBulkRestore,e[23]=b.handleExitSelectionMode,e[24]=b.hasSelection,e[25]=b.selectedIdsSize,e[26]=b.selectionModeEnabled,e[27]=y):y=e[27];let S;e[28]!==b.confirmBulkDelete||e[29]!==o||e[30]!==u||e[31]!==a?(S=s.jsx(qj,{value:o,setValue:l,showDeletionDialog:a,setShowDeletionDialog:u,onConfirm:b.confirmBulkDelete}),e[28]=b.confirmBulkDelete,e[29]=o,e[30]=u,e[31]=a,e[32]=S):S=e[32];let N;return e[33]!==y||e[34]!==S?(N=s.jsxs(s.Fragment,{children:[y,S]}),e[33]=y,e[34]=S,e[35]=N):N=e[35],N}function P2(t){return t.deleteSessions}function I2(t){return t.unarchiveSessions}function T2(t){return t.archiveSessions}function R2(t){return t.removeSessionsFromFolders}function E2(t){return t.addSessionsToFolder}function M2(t){return t.createFolder}function O2(t){return t.foldersMap}function F2(t){return t.setShowDeletionDialog}function B2(t){return t.showDeletionDialog}const Ac=7,_2=6e4,L2=()=>{const t=Xe.c(2),[e,n]=c.useState(0);let r,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{const o=setInterval(()=>{n(W2)},_2);return()=>clearInterval(o)},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),c.useEffect(r,i),e};function $2(t){const{sections:e,variant:n="section",initialVisibleCount:r=Ac,batchSize:i=Ac}=t,{t:o}=pt(),{pinnedSessionIds:l}=t,a=ls(y=>y.stickyZoneHeaders),[u,d]=c.useState(new Set),[h,f]=c.useState(new Map),g=n==="flat",p=c.useCallback(y=>{f(S=>{if(!S.has(y))return S;const N=new Map(S);return N.delete(y),N})},[]),w=c.useCallback(y=>{p(y),d(S=>{const N=new Set(S);return N.has(y)?N.delete(y):N.add(y),N})},[p]),v=c.useCallback((y,S,N)=>{f(C=>{const k=Math.min(N,S+i),A=new Map(C);return A.set(y,k),A})},[i]),x=L2(),m=c.useCallback(y=>{const S=new Set;ta(y,t.editingId,S);const N=Kr(y,t.openSidebarMenuKey,"recent",!1),C=new WeakMap,k=D=>{C.set(D,Wo(D)),D.children.forEach(k)};y.forEach(k);const A=D=>({subtreeContainsEditing:S,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:x,childRenderExtrasFor:A});return D=>({subtreeContainsEditing:S,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:x,childRenderExtrasFor:A})},[t.editingId,t.openSidebarMenuKey,x]),b=e.filter(y=>y.items.length>0||y.key==="chats");return b.length===0?null:s.jsx("div",{className:Te(g?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:b.map(y=>{const S=u.has(y.key),N=Math.max(r,h.get(y.key)??r),C=y.items.slice(0,N),k=y.items.length-C.length,A=y.key==="chats"&&!!t.renderChatsSection,D=!A&&!g&&y.items.length>r&&k===0,P=m(C.map(W=>W.node)),F=W=>s.jsx(zo,{node:W.node,pinnedSessionIds:l,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,groupDirectory:W.groupDirectory,projectId:W.projectId,secondaryMeta:W.secondaryMeta,renderContext:"recent",renderExtras:P(W.node),setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},W.node.session.id);return g?s.jsxs("div",{className:"space-y-0.5",children:[C.map(F),k>0?s.jsx("button",{type:"button",onClick:()=>v(y.key,C.length,y.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null]},y.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsxs("div",{className:Te("relative group/chats","-ml-2.5 -mr-2",a&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":a?"true":void 0,children:[s.jsxs("button",{type:"button",onClick:()=>w(y.key),className:Te("group flex w-full items-center gap-1.5 py-1 pl-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",y.key==="chats"?"pr-10":"pr-3.5"),"aria-expanded":!S,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(M,{name:y.key==="chats"?"chat-4":"history",className:Te("h-3.5 w-3.5 text-muted-foreground/80","group-hover:hidden")}),s.jsx("span",{className:"hidden h-3.5 w-3.5 items-center justify-center text-muted-foreground group-hover:inline-flex",children:S?s.jsx(M,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(M,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:y.title})]}),y.key==="chats"&&t.onNewChat?s.jsx("button",{type:"button",onClick:W=>{W.stopPropagation(),t.onNewChat?.()},className:Te("absolute right-0.5 top-1/2 z-10 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",t.alwaysShowActions?"opacity-100":"opacity-0 pointer-events-none group-hover/chats:opacity-100 group-hover/chats:pointer-events-auto group-focus-within/chats:opacity-100 group-focus-within/chats:pointer-events-auto"),"aria-label":o("sessions.sidebar.header.actions.newSession"),children:s.jsx(M,{name:"add",className:"h-4 w-4"})}):null]}),S?null:s.jsxs("div",{className:Te("space-y-0.5"),children:[A?t.renderChatsSection?.(y.items):C.map(F),!A&&k>0?s.jsx("button",{type:"button",onClick:()=>v(y.key,C.length,y.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null,D?s.jsx("button",{type:"button",onClick:()=>p(y.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showFewer")}):null]})]},y.key)})})}function W2(t){return t+1}const z2=t=>{const e=Xe.c(61),{projects:n,availableWorktreesByProject:r,gitBranches:i,homeDirectory:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,isDesktopShellRuntime:u,sessions:d,childrenMap:h,pinnedSessionIds:f,recentSessions:g,chatSessions:p,showRecentSection:w}=t,{t:v}=pt();let x;if(e[0]!==r||e[1]!==i||e[2]!==o||e[3]!==n||e[4]!==d){x=new Map;for(const z of d){const B=ct(z.directory??null);if(!B)continue;let T=null,j=-1;for(const G of n){const Q=ct(G.normalizedPath);Q&&(B===Q||B.startsWith(`${Q}/`))&&Q.length>j&&(T=G,j=Q.length)}if(!T)continue;const I=r.get(T.normalizedPath)?.find(G=>ct(G.path)===B),_=Da(T.label?.trim()||Fn(T.normalizedPath,o)||T.normalizedPath),K=I?.branch?.trim()||i.get(B)?.trim()||null;x.set(z.id,{projectId:T.id,groupDirectory:B,projectLabel:_,branchLabel:K&&K!=="HEAD"&&K!==_?K:null})}e[0]=r,e[1]=i,e[2]=o,e[3]=n,e[4]=d,e[5]=x}else x=e[5];const m=x;let b;e[6]!==m?(b=z=>m.get(z)??null,e[6]=m,e[7]=b):b=e[7];const y=b;let S;e[8]!==h?(S=z=>({session:z,children:(h.get(z.id)??[]).filter(V2).map(U2),worktree:null}),e[8]=h,e[9]=S):S=e[9];const N=S,C=l?a:"";let k;e[10]!==y||e[11]!==N||e[12]!==g||e[13]!==C?(k=Hp({sessions:g,getSessionLocation:y,getSessionNode:N,query:C}),e[10]=y,e[11]=N,e[12]=g,e[13]=C,e[14]=k):k=e[14];const A=k;let D;e[15]!==v?(D=v("sessions.sidebar.activity.chatsTitle"),e[15]=v,e[16]=D):D=e[16];let P;if(e[17]!==p||e[18]!==N){let z;e[20]!==N?(z=B=>({node:N(B),projectId:null,groupDirectory:B.directory??null,secondaryMeta:null}),e[20]=N,e[21]=z):z=e[21],P=p.map(z),e[17]=p,e[18]=N,e[19]=P}else P=e[19];let F;e[22]!==D||e[23]!==P?(F={key:"chats",title:D,items:P},e[22]=D,e[23]=P,e[24]=F):F=e[24];let W;e[25]!==A||e[26]!==w||e[27]!==v||e[28]!==F?(W=[F,...w?A.map(z=>({...z,title:v("sessions.sidebar.activity.recentTitle")})):[]],e[25]=A,e[26]=w,e[27]=v,e[28]=F,e[29]=W):W=e[29];const E=W;let H;return e[30]!==u||e[31]!==f||e[32]!==t.allowReselect||e[33]!==t.alwaysShowActions||e[34]!==t.copiedSessionId||e[35]!==t.deleteSessionConfirm||e[36]!==t.editTitle||e[37]!==t.editingId||e[38]!==t.expandedParents||e[39]!==t.hasSessionSearchQuery||e[40]!==t.isSessionSearchOpen||e[41]!==t.mobileVariant||e[42]!==t.normalizedSessionSearchQuery||e[43]!==t.notifyOnSubtasks||e[44]!==t.onNewChat||e[45]!==t.onSessionSelected||e[46]!==t.openSidebarMenuKey||e[47]!==t.renderChatsSection||e[48]!==t.sessionSearchQuery||e[49]!==t.setCopiedSessionId||e[50]!==t.setDeleteSessionConfirm||e[51]!==t.setEditTitle||e[52]!==t.setEditingId||e[53]!==t.setIsSessionSearchOpen||e[54]!==t.setOpenSidebarMenuKey||e[55]!==t.setSessionSearchQuery||e[56]!==t.startFolderRename||e[57]!==t.startSessionWorktreeMenuLoad||e[58]!==t.toggleParent||e[59]!==E?(H=s.jsx($2,{sections:E,variant:"section",isDesktopShellRuntime:u,pinnedSessionIds:f,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onNewChat:t.onNewChat,renderChatsSection:t.renderChatsSection,setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad}),e[30]=u,e[31]=f,e[32]=t.allowReselect,e[33]=t.alwaysShowActions,e[34]=t.copiedSessionId,e[35]=t.deleteSessionConfirm,e[36]=t.editTitle,e[37]=t.editingId,e[38]=t.expandedParents,e[39]=t.hasSessionSearchQuery,e[40]=t.isSessionSearchOpen,e[41]=t.mobileVariant,e[42]=t.normalizedSessionSearchQuery,e[43]=t.notifyOnSubtasks,e[44]=t.onNewChat,e[45]=t.onSessionSelected,e[46]=t.openSidebarMenuKey,e[47]=t.renderChatsSection,e[48]=t.sessionSearchQuery,e[49]=t.setCopiedSessionId,e[50]=t.setDeleteSessionConfirm,e[51]=t.setEditTitle,e[52]=t.setEditingId,e[53]=t.setIsSessionSearchOpen,e[54]=t.setOpenSidebarMenuKey,e[55]=t.setSessionSearchQuery,e[56]=t.startFolderRename,e[57]=t.startSessionWorktreeMenuLoad,e[58]=t.toggleParent,e[59]=E,e[60]=H):H=e[60],H};function V2(t){return!t.time?.archived}function U2(t){return{session:t,children:[],worktree:null}}const mm="oc.sessions.expandedParents.v3",K2=Ta(gr()),H2=()=>{try{const t=globalThis.localStorage.getItem(mm);if(t===null)return new Set;const e=K2.safeParse(JSON.parse(t));return e.success?new Set(e.data):new Set}catch{return new Set}},G2=()=>{const[t,e]=c.useState(H2),n=c.useRef(t);n.current=t;const r=c.useCallback(i=>{const o=Nh(n.current,i);n.current=o,e(o);try{globalThis.localStorage.setItem(mm,JSON.stringify([...o]))}catch{}},[]);return{expandedParents:t,toggleParent:r}},q2=5*6e4,Q2=[],Y2=t=>!t.parentID,X2=t=>{const e=Xe.c(292),{topology:n,view:r,actions:i}=t;let o,l,a,u,d;e[0]!==i?({alwaysShowActions:o,notifyOnSubtasks:l,projectViewActions:a,rowActions:u,...d}=i,e[0]=i,e[1]=o,e[2]=l,e[3]=a,e[4]=u,e[5]=d):(o=e[1],l=e[2],a=e[3],u=e[4],d=e[5]);const h=cs(Z2),f=cs(ek),g=cs(tk),p=r.projectView,{getOrderedGroups:w,setGroupOrderByProject:v,toggleGroup:x,toggleProject:m}=a;let b;e[6]!==n.isVSCode||e[7]!==n.knownDirectories?(b={knownDirectories:n.knownDirectories,isVSCode:n.isVSCode,isVisible:!0},e[6]=n.isVSCode,e[7]=n.knownDirectories,e[8]=b):b=e[8];const y=Gp(b);let S;e[9]===Symbol.for("react.memo_cache_sentinel")?(S=new Map,e[9]=S):S=e[9];const[N,C]=c.useState(S);let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=(Rt,Ot)=>{C(Xt=>new Map(Xt).set(Rt,Ot+7))},e[10]=k):k=e[10];const A=k;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=Rt=>{C(Ot=>{if(!Ot.has(Rt))return Ot;const Xt=new Map(Ot);return Xt.delete(Rt),Xt})},e[11]=D):D=e[11];const P=D,F=ls(sk),W=ls(nk),E=ls(rk),H=ls(ok);let z;e[12]!==n.isVSCode?(z=!n.isVSCode&&!qm(),e[12]=n.isVSCode,e[13]=z):z=e[13];const T=z&&W==="single",j=F&&!T;let I;e[14]!==y.pinnedSessionIds||e[15]!==y.rootSessions||e[16]!==y.sessionOrderRanks||e[17]!==j||e[18]!==n.isVSCode?(I={enabled:j,isVSCode:n.isVSCode,pinnedSessionIds:y.pinnedSessionIds,sessionOrderRanks:y.sessionOrderRanks,sessions:y.rootSessions},e[14]=y.pinnedSessionIds,e[15]=y.rootSessions,e[16]=y.sessionOrderRanks,e[17]=j,e[18]=n.isVSCode,e[19]=I):I=e[19];const _=qp(I),[K,G]=c.useState(null),[Q,ge]=c.useState(""),[se,Y]=c.useState(null),[te,he]=c.useState(null),[L,le]=c.useState(null),[Z,ue]=c.useState(null);let V;e[20]===Symbol.for("react.memo_cache_sentinel")?(V=(Rt,Ot)=>{ue({scopeKey:Rt,folderId:Ot.id,draft:Ot.name})},e[20]=V):V=e[20];const ee=V;let be;e[21]===Symbol.for("react.memo_cache_sentinel")?(be=Rt=>{ue(Ot=>Ot?{...Ot,draft:Rt}:null)},e[21]=be):be=e[21];const xe=be;let Ne;e[22]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>ue(null),e[22]=Ne):Ne=e[22];const Pe=Ne,{expandedParents:Se,toggleParent:Re}=G2(),ye=Qe(ik);let pe;e[23]!==ye?(pe=(Rt,Ot)=>{Rt!==Qe.getState().currentSessionId&&ye(Rt,Ot)},e[23]=ye,e[24]=pe):pe=e[24];const me=pe,je=Fd();let ne;e[25]!==y.pinnedSessionIds||e[26]!==y.sessionOrderRanks||e[27]!==n.gitBranches||e[28]!==n.isVSCode||e[29]!==n.worktreeMetadata||e[30]!==r.homeDirectory?(ne={homeDirectory:r.homeDirectory,worktreeMetadata:n.worktreeMetadata,pinnedSessionIds:y.pinnedSessionIds,sessionOrderRanks:y.sessionOrderRanks,gitBranches:n.gitBranches,isVSCode:n.isVSCode},e[25]=y.pinnedSessionIds,e[26]=y.sessionOrderRanks,e[27]=n.gitBranches,e[28]=n.isVSCode,e[29]=n.worktreeMetadata,e[30]=r.homeDirectory,e[31]=ne):ne=e[31];const{buildGroupedSessions:fe,filterSessionNodesForSearch:ce,buildGroupSearchText:R}=S2(ne);let $;e[32]!==y.archivedSessions||e[33]!==y.sessions||e[34]!==n.availableWorktreesByProject||e[35]!==n.isVSCode||e[36]!==n.projects?($=d0(y.sessions,n.projects,n.availableWorktreesByProject,n.isVSCode,y.archivedSessions),e[32]=y.archivedSessions,e[33]=y.sessions,e[34]=n.availableWorktreesByProject,e[35]=n.isVSCode,e[36]=n.projects,e[37]=$):$=e[37];const de=$;let ie;e[38]!==de?(ie={ownership:de},e[38]=de,e[39]=ie):ie=e[39];const{getSessionsForProject:Ae,getArchivedSessionsForProject:Be}=u0(ie);let Ce;e:{if(n.isVSCode){Ce=null;break e}let Rt;e[40]!==y.chatSessions||e[41]!==r.homeDirectory?(Rt=Ah(r.homeDirectory)??y.chatSessions.map(ak).find(Boolean)??null,e[40]=y.chatSessions,e[41]=r.homeDirectory,e[42]=Rt):Rt=e[42];const Ot=Rt;if(!Ot){Ce=null;break e}let Xt;if(e[43]!==Ot||e[44]!==y.chatSessions){const J=[Ot,...y.chatSessions.map(lk).filter(Boolean)];let ze;e[46]!==J?(ze=new Set(J),e[46]=J,e[47]=ze):ze=e[47],Xt=Array.from(ze).filter(ck).map(dk),e[43]=Ot,e[44]=y.chatSessions,e[45]=Xt}else Xt=e[45];const bs=Xt;let fs;if(e[48]!==y.chatSessions||e[49]!==y.childrenMap){let J;e[51]!==y.childrenMap?(J=ze=>({session:ze,children:(y.childrenMap.get(ze.id)??[]).filter(mk).map(fk),worktree:null}),e[51]=y.childrenMap,e[52]=J):J=e[52],fs=y.chatSessions.filter(uk).map(J),e[48]=y.chatSessions,e[49]=y.childrenMap,e[50]=fs}else fs=e[50];let Ts;e[53]!==Ot||e[54]!==bs||e[55]!==fs?(Ts={id:"managed-chats",label:"",branch:null,description:null,isMain:!0,worktree:null,directory:Ot,folderScopeKey:Ot,folderScopes:bs,draftTarget:"chat",sessions:fs},e[53]=Ot,e[54]=bs,e[55]=fs,e[56]=Ts):Ts=e[56],Ce=Ts}const q=Ce;let Ee;e[57]!==q?(Ee=q?[q]:Q2,e[57]=q,e[58]=Ee):Ee=e[58];const Me=Ee;let O;e[59]!==R||e[60]!==fe||e[61]!==ce||e[62]!==h||e[63]!==Be||e[64]!==Ae||e[65]!==Me||e[66]!==n.availableWorktreesByProject||e[67]!==n.gitBranches||e[68]!==n.lastRepoStatus||e[69]!==n.projectRepoStatus||e[70]!==n.projectRootBranches||e[71]!==n.projects||e[72]!==r.hasSessionSearchQuery||e[73]!==r.normalizedSessionSearchQuery?(O={normalizedProjects:n.projects,getSessionsForProject:Ae,getArchivedSessionsForProject:Be,availableWorktreesByProject:n.availableWorktreesByProject,projectRepoStatus:n.projectRepoStatus,projectRootBranches:n.projectRootBranches,gitBranches:n.gitBranches,lastRepoStatus:n.lastRepoStatus,buildGroupedSessions:fe,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,filterSessionNodesForSearch:ce,buildGroupSearchText:R,foldersMap:h,standaloneGroups:Me},e[59]=R,e[60]=fe,e[61]=ce,e[62]=h,e[63]=Be,e[64]=Ae,e[65]=Me,e[66]=n.availableWorktreesByProject,e[67]=n.gitBranches,e[68]=n.lastRepoStatus,e[69]=n.projectRepoStatus,e[70]=n.projectRootBranches,e[71]=n.projects,e[72]=r.hasSessionSearchQuery,e[73]=r.normalizedSessionSearchQuery,e[74]=O):O=e[74];const{projectSections:oe,groupSearchDataByGroup:re,sectionsForRender:we,flatSectionsForRender:Ve,searchMatchCount:st}=h0(O),Ge=r.onSearchMatchCountChange;let ae,X;e[75]!==Ge||e[76]!==st?(ae=()=>{Ge(st)},X=[Ge,st],e[75]=Ge,e[76]=st,e[77]=ae,e[78]=X):(ae=e[77],X=e[78]),c.useEffect(ae,X);let ve,Le;e[79]!==Ge?(ve=()=>()=>Ge(0),Le=[Ge],e[79]=Ge,e[80]=ve,e[81]=Le):(ve=e[80],Le=e[81]),c.useEffect(ve,Le);const $e=Pa(),Ue=`session-collection-expansion:${c.useId()}`;let We,qe;e[82]!==$e||e[83]!==Ue||e[84]!==oe||e[85]!==p.collapsedGroups||e[86]!==p.collapsedProjects||e[87]!==r.activeProjectId?(We=()=>($e.setBootstrapDemand(Ue,nm({projectSections:oe,activeProjectId:r.activeProjectId,collapsedProjects:p.collapsedProjects,collapsedGroups:p.collapsedGroups,currentDirectory:null,currentSessionDirectory:null})),()=>$e.clearBootstrapDemand(Ue)),qe=[$e,Ue,oe,p.collapsedProjects,p.collapsedGroups,r.activeProjectId],e[82]=$e,e[83]=Ue,e[84]=oe,e[85]=p.collapsedGroups,e[86]=p.collapsedProjects,e[87]=r.activeProjectId,e[88]=We,e[89]=qe):(We=e[88],qe=e[89]),c.useEffect(We,qe);const nt=r.useGroupedSections?we:Ve;let yt;e[90]!==nt||e[91]!==r.showInlineArchived?(yt=r.showInlineArchived?nt:nt.map(gk),e[90]=nt,e[91]=r.showInlineArchived,e[92]=yt):yt=e[92];const vt=yt;let He;e[93]!==Ve?(He=Rt=>Ve.find(Xt=>Xt.project.id===Rt)?.groups.find(xk)?.folderScopes??[],e[93]=Ve,e[94]=He):He=e[94];const Mt=He;let jt;e[95]===Symbol.for("react.memo_cache_sentinel")?(jt=new Map,e[95]=jt):jt=e[95];const kt=c.useRef(jt);let Tt;e[96]!==oe||e[97]!==r.isDesktopShellRuntime||e[98]!==r.stickyZoneHeaders?(Tt={enabled:r.stickyZoneHeaders,isDesktopShellRuntime:r.isDesktopShellRuntime,projectSections:oe,projectHeaderSentinelRefs:kt},e[96]=oe,e[97]=r.isDesktopShellRuntime,e[98]=r.stickyZoneHeaders,e[99]=Tt):Tt=e[99];const wt=v2(Tt);let Nt;e[100]!==g||e[101]!==y.hasAuthoritativeGlobalSessions||e[102]!==f||e[103]!==h||e[104]!==de||e[105]!==n.projects||e[106]!==r.isSessionsLoading||e[107]!==r.isWorktreeTopologyLoading||e[108]!==r.unresolvedWorktreeProjectPaths?(Nt={enabled:!0,normalizedProjects:n.projects,ownership:de,isSessionsLoading:r.isSessionsLoading,hasAuthoritativeGlobalSessions:y.hasAuthoritativeGlobalSessions,isWorktreeTopologyLoading:r.isWorktreeTopologyLoading,unresolvedWorktreeProjectPaths:r.unresolvedWorktreeProjectPaths,foldersMap:h,createFolder:f,addSessionToFolder:g},e[100]=g,e[101]=y.hasAuthoritativeGlobalSessions,e[102]=f,e[103]=h,e[104]=de,e[105]=n.projects,e[106]=r.isSessionsLoading,e[107]=r.isWorktreeTopologyLoading,e[108]=r.unresolvedWorktreeProjectPaths,e[109]=Nt):Nt=e[109],e0(Nt);const{github:Dt}=An(),ft=Cn(bk),Ze=Cn(yk),ke=Hs(wk),tt=Hs(Sk),lt=Hs(vk);let At;e[110]===Symbol.for("react.memo_cache_sentinel")?(At=new Set,e[110]=At):At=e[110];const Ye=c.useRef(At);let rt;e[111]!==ke||e[112]!==Dt||e[113]!==Ze||e[114]!==ft||e[115]!==oe||e[116]!==p.collapsedProjects||e[117]!==lt||e[118]!==tt||e[119]!==n.gitBranches?(rt=()=>{if(!Dt||!Ze||!ft?.connected)return;const Rt=new Map,Ot=Date.now();oe.forEach(Xt=>{p.collapsedProjects.has(Xt.project.id)||Xt.groups.forEach(bs=>{if(bs.isArchivedBucket||bs.isMain)return;const fs=ct(bs.directory??null),Ts=bs.branch?.trim()||n.gitBranches.get(fs||"")?.trim();if(!fs||!Ts)return;const J=Yo(fs,Ts),ze=Hs.getState().entries[J],U=ze?.status?.pr?.state==="closed"||ze?.status?.pr?.state==="merged",_e=`${fs}::${Ts}`,Je=Math.max(ze?.lastRefreshAt??0,ze?.lastDiscoveryPollAt??0),mt=!!(ze?.isInitialStatusResolved&&(!ze.status?.pr||U)&&(!Ye.current.has(_e)||Ot-Je>=q2));(!ze||!ze.isInitialStatusResolved||mt)&&(mt&&Ye.current.add(_e),Rt.set(J,{directory:fs,branch:Ts}))})}),Rt.forEach((Xt,bs)=>{ke(bs),tt(bs,{...Xt,remoteName:null,canShow:!0,github:Dt,githubAuthChecked:Ze,githubConnected:ft.connected})}),Rt.size&<([...Rt.values()],{silent:!0,markInitialResolved:!0})},e[111]=ke,e[112]=Dt,e[113]=Ze,e[114]=ft,e[115]=oe,e[116]=p.collapsedProjects,e[117]=lt,e[118]=tt,e[119]=n.gitBranches,e[120]=rt):rt=e[120];const It=ft?.connected;let Ct;e[121]!==ke||e[122]!==Dt||e[123]!==Ze||e[124]!==oe||e[125]!==p.collapsedProjects||e[126]!==lt||e[127]!==tt||e[128]!==It||e[129]!==n.gitBranches?(Ct=[ke,Dt,Ze,It,oe,p.collapsedProjects,lt,tt,n.gitBranches],e[121]=ke,e[122]=Dt,e[123]=Ze,e[124]=oe,e[125]=p.collapsedProjects,e[126]=lt,e[127]=tt,e[128]=It,e[129]=n.gitBranches,e[130]=Ct):Ct=e[130],c.useEffect(rt,Ct);let Pt;e[131]!==y.orderedSessions?(Pt=new Map(y.orderedSessions.map(jk)),e[131]=y.orderedSessions,e[132]=Pt):Pt=e[132];const Wt=Pt;let Yt;if(e[133]!==w||e[134]!==vt){let Rt;e[136]!==w?(Rt=Ot=>{const Xt=w(Ot.project.id,Ot.groups);return Xt===Ot.groups?Ot:{...Ot,groups:Xt}},e[136]=w,e[137]=Rt):Rt=e[137],Yt=vt.map(Rt),e[133]=w,e[134]=vt,e[135]=Yt}else Yt=e[135];const Kt=Yt;let Bt;e[138]!==oe||e[139]!==E||e[140]!==T||e[141]!==r.activeProjectId?(Bt=null,T&&(oe.some(Rt=>Rt.project.id===E)?Bt=E:oe.some(Rt=>Rt.project.id===r.activeProjectId)?Bt=r.activeProjectId:Bt=oe[0]?.project.id??null),e[138]=oe,e[139]=E,e[140]=T,e[141]=r.activeProjectId,e[142]=Bt):Bt=e[142];const ts=T&&!r.useGroupedSections?20:void 0;let zt;e[143]!==i.startSessionWorktreeMenuLoad||e[144]!==o||e[145]!==y.pinnedSessionIds||e[146]!==L||e[147]!==te||e[148]!==Q||e[149]!==K||e[150]!==Se||e[151]!==Z||e[152]!==re||e[153]!==l||e[154]!==p.collapsedGroups||e[155]!==u.allowReselect||e[156]!==u.isSessionSearchOpen||e[157]!==u.onSessionSelected||e[158]!==u.sessionSearchQuery||e[159]!==u.setIsSessionSearchOpen||e[160]!==u.setSessionSearchQuery||e[161]!==Wt||e[162]!==ts||e[163]!==Re||e[164]!==r.activeProjectId||e[165]!==r.hasSessionSearchQuery||e[166]!==r.hideDirectoryControls||e[167]!==r.mobileVariant||e[168]!==r.normalizedSessionSearchQuery?(zt={hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,groupSearchDataByGroup:re,collapsedGroups:p.collapsedGroups,hideDirectoryControls:r.hideDirectoryControls,mobileVariant:r.mobileVariant,alwaysShowActions:o,activeProjectId:r.activeProjectId,notifyOnSubtasks:l,pinnedSessionIds:y.pinnedSessionIds,sessionOrderIndex:Wt,expandedParents:Se,editingId:K,editTitle:Q,copiedSessionId:L,sessionBatchSize:ts,setEditingId:G,setEditTitle:ge,toggleParent:Re,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:te,setDeleteSessionConfirm:he,startFolderRename:ee,setCopiedSessionId:le,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,folderRename:Z,setFolderRenameDraft:xe,clearFolderRename:Pe},e[143]=i.startSessionWorktreeMenuLoad,e[144]=o,e[145]=y.pinnedSessionIds,e[146]=L,e[147]=te,e[148]=Q,e[149]=K,e[150]=Se,e[151]=Z,e[152]=re,e[153]=l,e[154]=p.collapsedGroups,e[155]=u.allowReselect,e[156]=u.isSessionSearchOpen,e[157]=u.onSessionSelected,e[158]=u.sessionSearchQuery,e[159]=u.setIsSessionSearchOpen,e[160]=u.setSessionSearchQuery,e[161]=Wt,e[162]=ts,e[163]=Re,e[164]=r.activeProjectId,e[165]=r.hasSessionSearchQuery,e[166]=r.hideDirectoryControls,e[167]=r.mobileVariant,e[168]=r.normalizedSessionSearchQuery,e[169]=zt):zt=e[169];const _t=zt;let Oe;e[170]!==d.openNewSessionDraft||e[171]!==d.setActiveProjectIdOnly||e[172]!==d.setSessionSwitcherOpen||e[173]!==x?(Oe={showMoreGroupSessions:A,resetGroupSessionLimit:P,setActiveProjectIdOnly:d.setActiveProjectIdOnly,setSessionSwitcherOpen:d.setSessionSwitcherOpen,openNewSessionDraft:d.openNewSessionDraft,onToggleCollapsedGroup:x},e[170]=d.openNewSessionDraft,e[171]=d.setActiveProjectIdOnly,e[172]=d.setSessionSwitcherOpen,e[173]=x,e[174]=Oe):Oe=e[174];const Ke=Oe;let et;e[175]!==q||e[176]!==Ke||e[177]!==_t||e[178]!==se?(et=()=>q?s.jsx(Co,{..._t,...Ke,group:q,groupKey:"managed-chats",projectId:null,hideGroupLabel:!0,sessionBatchSize:20,scrollContainerRef:void 0,openSidebarMenuKey:se,setOpenSidebarMenuKey:Y}):null,e[175]=q,e[176]=Ke,e[177]=_t,e[178]=se,e[179]=et):et=e[179];const dt=et;let ut;e[180]!==d||e[181]!==r.mobileVariant?(ut=()=>{De.getState().closeMainSurfaces(),r.mobileVariant&&d.setSessionSwitcherOpen(!1),d.openNewSessionDraft({selectedProjectId:Dh,directoryOverride:null})},e[180]=d,e[181]=r.mobileVariant,e[182]=ut):ut=e[182];const St=ut;let ot;e[183]!==i.startSessionWorktreeMenuLoad||e[184]!==o||e[185]!==y.chatSessions||e[186]!==y.childrenMap||e[187]!==y.pinnedSessionIds||e[188]!==L||e[189]!==te||e[190]!==Q||e[191]!==K||e[192]!==Se||e[193]!==St||e[194]!==l||e[195]!==se||e[196]!==_||e[197]!==dt||e[198]!==u.allowReselect||e[199]!==u.isSessionSearchOpen||e[200]!==u.onSessionSelected||e[201]!==u.sessionSearchQuery||e[202]!==u.setIsSessionSearchOpen||e[203]!==u.setSessionSearchQuery||e[204]!==F||e[205]!==T||e[206]!==Re||e[207]!==n.availableWorktreesByProject||e[208]!==n.gitBranches||e[209]!==n.isVSCode||e[210]!==n.projects||e[211]!==r.hasSessionSearchQuery||e[212]!==r.homeDirectory||e[213]!==r.isDesktopShellRuntime||e[214]!==r.mobileVariant||e[215]!==r.normalizedSessionSearchQuery?(ot=n.isVSCode?null:s.jsx(z2,{projects:n.projects,availableWorktreesByProject:n.availableWorktreesByProject,gitBranches:n.gitBranches,homeDirectory:r.homeDirectory,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,isDesktopShellRuntime:r.isDesktopShellRuntime,sessions:_,childrenMap:y.childrenMap,pinnedSessionIds:y.pinnedSessionIds,recentSessions:_,expandedParents:Se,notifyOnSubtasks:l,editingId:K,editTitle:Q,copiedSessionId:L,openSidebarMenuKey:se,mobileVariant:r.mobileVariant,alwaysShowActions:o,setEditingId:G,setEditTitle:ge,toggleParent:Re,setOpenSidebarMenuKey:Y,allowReselect:u.allowReselect,onSessionSelected:u.onSessionSelected,isSessionSearchOpen:u.isSessionSearchOpen,sessionSearchQuery:u.sessionSearchQuery,setSessionSearchQuery:u.setSessionSearchQuery,setIsSessionSearchOpen:u.setIsSessionSearchOpen,deleteSessionConfirm:te,setDeleteSessionConfirm:he,startFolderRename:ee,setCopiedSessionId:le,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,chatSessions:y.chatSessions,renderChatsSection:dt,onNewChat:St,showRecentSection:F&&!T}),e[183]=i.startSessionWorktreeMenuLoad,e[184]=o,e[185]=y.chatSessions,e[186]=y.childrenMap,e[187]=y.pinnedSessionIds,e[188]=L,e[189]=te,e[190]=Q,e[191]=K,e[192]=Se,e[193]=St,e[194]=l,e[195]=se,e[196]=_,e[197]=dt,e[198]=u.allowReselect,e[199]=u.isSessionSearchOpen,e[200]=u.onSessionSelected,e[201]=u.sessionSearchQuery,e[202]=u.setIsSessionSearchOpen,e[203]=u.setSessionSearchQuery,e[204]=F,e[205]=T,e[206]=Re,e[207]=n.availableWorktreesByProject,e[208]=n.gitBranches,e[209]=n.isVSCode,e[210]=n.projects,e[211]=r.hasSessionSearchQuery,e[212]=r.homeDirectory,e[213]=r.isDesktopShellRuntime,e[214]=r.mobileVariant,e[215]=r.normalizedSessionSearchQuery,e[216]=ot):ot=e[216];const Lt=ot;let Qt;e[217]!==re||e[218]!==Me||e[219]!==r.hasSessionSearchQuery?(Qt=r.hasSessionSearchQuery&&Me.some(Rt=>re.get(Rt)?.hasMatch===!0),e[217]=re,e[218]=Me,e[219]=r.hasSessionSearchQuery,e[220]=Qt):Qt=e[220];const us=Qt,$s=!!Lt;let rs;e[221]!==K||e[222]!==se||e[223]!==N?(rs={editingId:K,openSidebarMenuKey:se,setOpenSidebarMenuKey:Y,visibleSessionCountByGroup:N},e[221]=K,e[222]=se,e[223]=N,e[224]=rs):rs=e[224];let Is;e[225]!==_t||e[226]!==Kt||e[227]!==oe||e[228]!==Lt||e[229]!==Bt||e[230]!==T||e[231]!==wt||e[232]!==$s||e[233]!==rs||e[234]!==us||e[235]!==n.projectRepoStatus||e[236]!==r.activeProjectId||e[237]!==r.emptyState||e[238]!==r.searchEmptyState?(Is={topContent:Lt,topContentHasSearchMatches:us,hasSharedSessions:$s,sectionsForRender:Kt,projectSections:oe,activeProjectId:r.activeProjectId,singleProjectMode:T,singleProjectId:Bt,emptyState:r.emptyState,searchEmptyState:r.searchEmptyState,projectRepoStatus:n.projectRepoStatus,stuckProjectHeaders:wt,projectHeaderSentinelRefs:kt,state:rs,groupProps:_t},e[225]=_t,e[226]=Kt,e[227]=oe,e[228]=Lt,e[229]=Bt,e[230]=T,e[231]=wt,e[232]=$s,e[233]=rs,e[234]=us,e[235]=n.projectRepoStatus,e[236]=r.activeProjectId,e[237]=r.emptyState,e[238]=r.searchEmptyState,e[239]=Is):Is=e[239];const ss=Is;let Ns;e[240]!==o||e[241]!==p.collapsedProjects||e[242]!==r.hasSessionSearchQuery||e[243]!==r.hideDirectoryControls||e[244]!==r.homeDirectory||e[245]!==r.isDesktopShellRuntime||e[246]!==r.mobileVariant||e[247]!==r.normalizedSessionSearchQuery||e[248]!==r.projectSortOrder||e[249]!==r.showOnlyMainWorkspace||e[250]!==r.stickyZoneHeaders?(Ns={homeDirectory:r.homeDirectory,collapsedProjects:p.collapsedProjects,showOnlyMainWorkspace:r.showOnlyMainWorkspace,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,hideDirectoryControls:r.hideDirectoryControls,isDesktopShellRuntime:r.isDesktopShellRuntime,stickyZoneHeaders:r.stickyZoneHeaders,mobileVariant:r.mobileVariant,alwaysShowActions:o,projectSortOrder:r.projectSortOrder},e[240]=o,e[241]=p.collapsedProjects,e[242]=r.hasSessionSearchQuery,e[243]=r.hideDirectoryControls,e[244]=r.homeDirectory,e[245]=r.isDesktopShellRuntime,e[246]=r.mobileVariant,e[247]=r.normalizedSessionSearchQuery,e[248]=r.projectSortOrder,e[249]=r.showOnlyMainWorkspace,e[250]=r.stickyZoneHeaders,e[251]=Ns):Ns=e[251];const Ws=Ns;let cn;e[252]!==Ke||e[253]!==d.openNewSessionDraft||e[254]!==d.openNewWorktreeDialog||e[255]!==d.openProjectEditDialog||e[256]!==d.openWorktreesPage||e[257]!==d.removeProject||e[258]!==d.renderProjectStatusIndicator||e[259]!==d.reorderProjects||e[260]!==d.setActiveProjectIdOnly||e[261]!==d.setSessionSwitcherOpen||e[262]!==v||e[263]!==H||e[264]!==m?(cn={group:Ke,toggleProject:m,setActiveProjectIdOnly:d.setActiveProjectIdOnly,setSessionSwitcherOpen:d.setSessionSwitcherOpen,openNewSessionDraft:d.openNewSessionDraft,openNewWorktreeDialog:d.openNewWorktreeDialog,openWorktreesPage:d.openWorktreesPage,openProjectEditDialog:d.openProjectEditDialog,removeProject:d.removeProject,reorderProjects:d.reorderProjects,setGroupOrderByProject:v,renderProjectStatusIndicator:d.renderProjectStatusIndicator,setSingleProjectId:H},e[252]=Ke,e[253]=d.openNewSessionDraft,e[254]=d.openNewWorktreeDialog,e[255]=d.openProjectEditDialog,e[256]=d.openWorktreesPage,e[257]=d.removeProject,e[258]=d.renderProjectStatusIndicator,e[259]=d.reorderProjects,e[260]=d.setActiveProjectIdOnly,e[261]=d.setSessionSwitcherOpen,e[262]=v,e[263]=H,e[264]=m,e[265]=cn):cn=e[265];const bn=cn;let ms;e[266]!==i.initialActiveSessionByProject||e[267]!==i.openNewSessionDraft||e[268]!==i.persistActiveSessionByProject||e[269]!==i.setSessionSwitcherOpen||e[270]!==de.bySessionId||e[271]!==oe||e[272]!==me||e[273]!==r.activeProjectId||e[274]!==r.mobileVariant?(ms=s.jsx(r0,{projectSections:oe,activeProjectId:r.activeProjectId,initialActiveSessionByProject:i.initialActiveSessionByProject,persistActiveSessionByProject:i.persistActiveSessionByProject,mobileVariant:r.mobileVariant,openNewSessionDraft:i.openNewSessionDraft,setSessionSwitcherOpen:i.setSessionSwitcherOpen,sessionOwnerBySessionId:de.bySessionId,handleSessionSelect:me}),e[266]=i.initialActiveSessionByProject,e[267]=i.openNewSessionDraft,e[268]=i.persistActiveSessionByProject,e[269]=i.setSessionSwitcherOpen,e[270]=de.bySessionId,e[271]=oe,e[272]=me,e[273]=r.activeProjectId,e[274]=r.mobileVariant,e[275]=ms):ms=e[275];let xs;e[276]!==y.orderedSessions||e[277]!==je||e[278]!==_?(xs=s.jsx(w0,{sortedSessions:y.orderedSessions,recentSessions:_,prefetchSession:je}),e[276]=y.orderedSessions,e[277]=je,e[278]=_,e[279]=xs):xs=e[279];let zs;e[280]!==bn||e[281]!==ss||e[282]!==Ws?(zs=s.jsx(w2,{model:ss,view:Ws,actions:bn}),e[280]=bn,e[281]=ss,e[282]=Ws,e[283]=zs):zs=e[283];const an=K!==null;let is;e[284]!==Mt||e[285]!==an?(is=s.jsx(D2,{getFolderScopesForProject:Mt,isInlineEditing:an,startFolderRename:ee}),e[284]=Mt,e[285]=an,e[286]=is):is=e[286];let Vs;return e[287]!==ms||e[288]!==xs||e[289]!==zs||e[290]!==is?(Vs=s.jsxs(s.Fragment,{children:[ms,xs,zs,is]}),e[287]=ms,e[288]=xs,e[289]=zs,e[290]=is,e[291]=Vs):Vs=e[291],Vs},J2=t=>{const e=Xe.c(2);let n;return e[0]!==t?(n=t.view.isVisible?s.jsx(X2,{...t}):null,e[0]=t,e[1]=n):n=e[1],n};function Z2(t){return t.foldersMap}function ek(t){return t.createFolder}function tk(t){return t.addSessionToFolder}function sk(t){return t.showRecentSection}function nk(t){return t.projectDisplayMode}function rk(t){return t.singleProjectId}function ok(t){return t.setSingleProjectId}function ik(t){return t.setCurrentSession}function ak(t){return Ld(t.directory)}function lk(t){return ct(t.directory??null)}function ck(t){return!!t}function dk(t){return{scopeKey:t,directory:t}}function uk(t){return!t.time?.archived&&Y2(t)}function mk(t){return!t.time?.archived}function fk(t){return{session:t,children:[],worktree:null}}function hk(t){return t.isArchivedBucket}function pk(t){return!t.isArchivedBucket}function gk(t){return t.groups.some(hk)?{...t,groups:t.groups.filter(pk)}:t}function xk(t){return!t.isArchivedBucket}function bk(t){return t.status}function yk(t){return t.hasChecked}function wk(t){return t.ensureEntry}function Sk(t){return t.setParams}function vk(t){return t.refreshTargets}function jk(t,e){return[t.id,e]}const fm=(t,e,n)=>{const r=new Set;for(const i of t){const o=ct(i.path)?.toLowerCase();o&&r.add(o)}if(n?.includeWorktrees===!1)return r;for(const i of e.values())for(const o of i){const l=ct(o.path)?.toLowerCase();l&&r.add(l)}return r},Dc="oc.sessions.activeSessionByProject",kk=[],Ck=uu(gr(),gr().min(1).catch("")),Nk=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:o=!1})=>{vi("react.session_sidebar_render"),qs("ui.session_sidebar.render"),qs(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),qs(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:l}=pt(),[a,u]=c.useState(!1),[d,h]=c.useState(""),[f,g]=c.useState(0),p=c.useRef(null),w=c.useRef(null),[v,x]=c.useState(null),m=c.useMemo(()=>Po(),[]),[b,y]=c.useState(new Map),S=De(ke=>ke.isNewWorktreeDialogOpen),N=De(ke=>ke.setNewWorktreeDialogOpen),[C,k]=c.useState(!1),A=c.useMemo(()=>{try{const ke=m.getItem(Dc);if(!ke)return new Map;const tt=Ck.safeParse(JSON.parse(ke));if(!tt.success)return new Map;const lt=new Map;return Object.entries(tt.data).forEach(([At,Ye])=>{Ye&<.set(At,Ye)}),lt}catch{return new Map}},[m]),D=c.useCallback(ke=>{try{m.setItem(Dc,JSON.stringify(Object.fromEntries(ke.entries())))}catch{}},[m]),[P,F]=c.useState(new Map),W=Zt(ke=>ke.homeDirectory),E=Vt(ke=>ke.projects),H=Vt(ke=>ke.activeProjectId),z=Vt(ke=>ke.removeProject),B=Vt(ke=>ke.setActiveProjectIdOnly),T=Vt(ke=>ke.updateProjectMeta),j=Vt(ke=>ke.reorderProjects),I=De(ke=>ke.setSettingsDialogOpen),_=De(ke=>ke.toggleHelpDialog),K=De(ke=>ke.setAboutDialogOpen),G=De(ke=>ke.setSessionSwitcherOpen),Q=De(ke=>ke.setScheduledTasksDialogOpen),ge=De(ke=>ke.setArchivePageOpen),se=De(ke=>ke.setWorktreesPageProjectId),Y=De(ke=>ke.openMultiRunLauncher),te=De(ke=>ke.notifyOnSubtasks),he=Sa(d,120),L=c.useMemo(()=>he.trim().toLowerCase(),[he]),le=L.length>0;jv({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchContainerRef:p});const Z=Ad(t),ue=c.useMemo(()=>Nn(),[]),V=Qe(ke=>ke.setCurrentSession),ee=Qe(ke=>ke.worktreeMetadata),be=Qe(ke=>ke.availableWorktreesByProject),xe=Qe(ke=>ke.openNewSessionDraft),Ne=c.useMemo(()=>fm(E,be,{includeWorktrees:!ue}),[be,ue,E]),Pe=c.useCallback(ke=>{De.getState().closeMainSurfaces(),xe(ke),ue&&window.dispatchEvent(new CustomEvent("aiworker:navigate",{detail:{view:"chat"}}))},[ue,xe]),Se=Rr(Xn(ke=>({checkForUpdates:ke.checkForUpdates,available:ke.available,runtimeType:ke.runtimeType,info:ke.info,downloading:ke.downloading,downloaded:ke.downloaded,progress:ke.progress,error:ke.error,downloadUpdate:ke.downloadUpdate,restartToUpdate:ke.restartToUpdate}))),Re=Ss(),ye=c.useMemo(()=>`${Re}|${E.map(ke=>`${ke.id}:${ct(ke.path)??""}`).join("|")}`,[E,Re]),[pe,me]=c.useState(ue?ye:null),[je,ne]=c.useReducer(ke=>ke+1,0),fe=!ue&&pe!==ye,[ce,R]=c.useState(new Set),$=c.useRef({runtimeKey:null,revision:0,worktreesByProject:new Map});c.useEffect(()=>{let ke=!1;return(async()=>{const lt=Re,At=Vt.getState().projects;if(At.length===0||ue){ke||($.current={runtimeKey:null,revision:0,worktreesByProject:new Map},R(new Set),me(ye));return}const Ye=Qe.getState().availableWorktreesByProject,rt=ra({rawWorktreesByProjectRef:$,publishedWorktreesByProject:Ye,runtimeKey:lt}),It=rt.revision,Ct=new Map(rt.worktreesByProject),Pt=new Set,Wt=3;let Yt=0;const Kt=Array.from({length:Wt},async()=>{for(;;){const zt=Yt;if(Yt+=1,zt>=At.length)return;const _t=At[zt],Oe=ct(_t.path);if(Oe)try{const Ke=await Di(async()=>On.getState().directories.get(Oe)?.isGitRepo??await Qo(Oe)?al({id:_t.id,path:Oe}):null);if(Ke===null){Ct.delete(Oe);continue}if(ke)return;Ke.length===0?Ct.delete(Oe):Ct.set(Oe,Ke)}catch{Pt.add(Oe)}}});if(await Promise.all(Kt),ke||Ss()!==lt)return;const Bt=new Set(At.map(zt=>ct(zt.path)).filter(Boolean));for(const zt of Ct.keys())Bt.has(zt)||Ct.delete(zt);Rj({rawWorktreesByProjectRef:$,runtimeKey:lt,capturedRevision:It,nextRawWorktreesByProject:Ct,publishedWorktreesByProject:Ye,partitionWorktreesByRegisteredProject:cl,projects:At,worktreeMapsEqual:ll,recordWorktreesSeen:Cc,publishTopology:zt=>{Qe.setState(zt)},requestRediscovery:()=>{ne()},now:()=>Date.now()})&&(R(Pt),me(ye))})(),()=>{ke=!0}},[ue,ye,Re,je]),c.useEffect(()=>{if(!ue)return Yr(ke=>{ke.type==="session-created"&&ne()})},[ue]);const de=c.useMemo(()=>pn(),[]),{isTablet:ie}=_n(),Ae=e||ie,Be=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noSessions.description")})]}),[l]),Ce=c.useMemo(()=>E.find(ke=>ke.id===v)??null,[E,v]),q=c.useCallback(ke=>{v&&T(v,{label:ke.label,icon:ke.icon,color:ke.color,iconBackground:ke.iconBackground,defaultModel:ke.defaultModel??null})},[v,T]),Ee=c.useCallback(()=>{N(!0)},[N]),Me=c.useCallback(()=>{const ke=Rr.getState();if(ke.available&&ke.info){k(!0);return}Se.checkForUpdates().then(()=>{const{available:tt,error:lt}=Rr.getState();if(lt){Fe.error(l("sessions.sidebar.updateCheck.errorTitle"),{description:lt});return}if(!tt){Fe.success(l("sessions.sidebar.updateCheck.latestVersion"));return}k(!0)})},[l,Se]),O=c.useCallback(()=>{e&&G(!1),I(!0)},[e,G,I]),oe=Se.available&&(Se.runtimeType==="desktop"||Se.runtimeType==="web"),re=c.useCallback(()=>{hn.requestDirectoryDialog()},[]),we=c.useMemo(()=>E.flatMap(ke=>{const tt=ct(ke.path);return tt?[{id:ke.id,path:ke.path,label:ke.label,normalizedPath:tt,icon:ke.icon??void 0,color:ke.color??void 0,iconImage:ke.iconImage??void 0,iconBackground:ke.iconBackground??void 0,addedAt:ke.addedAt,lastOpenedAt:ke.lastOpenedAt,sidebarCollapsed:ke.sidebarCollapsed}]:[]}),[E]),Ve=c.useMemo(()=>we.map(ke=>ke.normalizedPath),[we]),st=Ph(t?Ve:kk);Tv({enabled:t,normalizedProjects:we,gitRepoStatus:st,setProjectRepoStatus:y,setProjectRootBranches:F});const Ge=Qe(ke=>ke.isLoading),ae=c.useRef(!1);H&&b.has(H)&&(ae.current=!!b.get(H));const X=ls(ke=>ke.showArchivedSessions),ve=ls(ke=>ke.projectSortOrder),Le=ls(ke=>ke.stickyZoneHeaders),$e=Vt(ke=>ke.manualProjectOrder),Ue={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:i,showOnlyMainWorkspace:o,t:l,isTablet:ie,projects:E,activeProjectId:H,manualProjectOrder:$e,worktreeMetadata:ee,availableWorktreesByProject:be,gitBranches:Z,gitRepoStatus:st,updateStore:Se,showArchivedSessions:X,projectSortOrder:ve,projectRepoStatus:b,projectRootBranches:P,resolvedWorktreeTopologyKey:pe,unresolvedWorktreeProjectPaths:ce,isSessionSearchOpen:a,sessionSearchQuery:d,editingProjectDialogId:v,updateDialogOpen:C},We=c.useRef(null),qe=We.current;if(qe){let ke=!1;for(const tt of Object.keys(Ue))Object.is(qe[tt],Ue[tt])||(qs(`ui.session_sidebar.source.${tt}`),ke=!0);ke||qs("ui.session_sidebar.source.parent_or_context")}We.current=Ue;const nt=c.useMemo(()=>{const ke=[...we];switch(ve){case"a-z":ke.sort((tt,lt)=>{const At=(tt.label||tt.path).toLowerCase(),Ye=(lt.label||lt.path).toLowerCase();return At.localeCompare(Ye)});break;case"z-a":ke.sort((tt,lt)=>{const At=(tt.label||tt.path).toLowerCase();return(lt.label||lt.path).toLowerCase().localeCompare(At)});break;case"date-added":ke.sort((tt,lt)=>(lt.addedAt??0)-(tt.addedAt??0));break;case"recent":ke.sort((tt,lt)=>(lt.lastOpenedAt??0)-(tt.lastOpenedAt??0));break;case"manual":{const tt=new Map($e.map((lt,At)=>[lt,At]));ke.sort((lt,At)=>{const Ye=tt.get(lt.id)??1/0,rt=tt.get(At.id)??1/0;return Ye-rt});break}}return ke},[we,ve,$e]),yt=Av({isVSCode:ue,projects:nt}),vt=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noMatches.description")})]}),[l]),He=ue&&X,jt=ls(ke=>ke.sessionGroupingMode)==="by-worktree"&&!ue,wt=e?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",Nt="h-4.5 w-4.5",Dt=c.useCallback(()=>{e&&G(!1),Y()},[e,Y,G]),ft=c.useCallback(ke=>{const tt=ke.projectId?E.find(lt=>lt.id===ke.projectId)??null:ke.sourceDirectory?ki(ke.sourceDirectory):null;return Tj(ke,{projects:E,getCurrentProjects:()=>Vt.getState().projects,rawWorktreesByProjectRef:$,getPublishedWorktreesByProject:()=>Qe.getState().availableWorktreesByProject,resolveProject:lt=>ki(lt),listProjectWorktrees:al,partitionWorktreesByRegisteredProject:cl,worktreeMapsEqual:ll,recordWorktreesSeen:Cc,publishTopology:lt=>{Qe.setState(lt)},getRuntimeKey:Ss,now:()=>Date.now(),projectRootBranch:tt?P.get(tt.id)??null:null})},[P,E]),Ze=c.useCallback(()=>{De.getState().closeMainSurfaces(),e&&G(!1),xe()},[e,xe,G]);return s.jsx(Ri,{delay:400,closeDelay:0,timeout:300,children:s.jsxs("div",{ref:p,className:Te("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[!i&&!ue?s.jsx(Jv,{onNewSession:Ze}):null,s.jsx(_v,{hideDirectoryControls:i,showProjectDisplayControls:!ue,showRecentControls:!ue,handleOpenDirectoryDialog:re,onOpenScheduled:()=>{e&&G(!1),Q(!0)},onOpenMultiRun:Dt,canOpenMultiRun:E.length>0,onOpenArchive:()=>{e&&G(!1),ge(!0)},headerActionIconClass:Nt,headerActionButtonClass:wt,isSessionSearchOpen:a,setIsSessionSearchOpen:u,sessionSearchInputRef:w,sessionSearchQuery:d,setSessionSearchQuery:h,hasSessionSearchQuery:le,searchMatchCount:f,collapseAllProjects:yt.actions.collapseAllProjects,expandAllProjects:yt.actions.expandAllProjects}),s.jsx(J2,{topology:{projects:nt,availableWorktreesByProject:be,knownDirectories:Ne,isVSCode:ue,worktreeMetadata:ee,gitBranches:Z,projectRepoStatus:b,projectRootBranches:P,lastRepoStatus:ae.current},view:{isVisible:t,hasSessionSearchQuery:le,normalizedSessionSearchQuery:L,activeProjectId:H,showInlineArchived:He,useGroupedSections:jt,homeDirectory:W,mobileVariant:e,hideDirectoryControls:i,showOnlyMainWorkspace:o,isDesktopShellRuntime:de,stickyZoneHeaders:Le,projectSortOrder:ve,emptyState:Be,searchEmptyState:vt,isSessionsLoading:Ge,isWorktreeTopologyLoading:fe,unresolvedWorktreeProjectPaths:ce,projectView:yt.state,onSearchMatchCountChange:g},actions:{rowActions:{allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:d,setSessionSearchQuery:h,setIsSessionSearchOpen:u},alwaysShowActions:Ae,notifyOnSubtasks:te,setActiveProjectIdOnly:B,setSessionSwitcherOpen:G,openNewSessionDraft:Pe,openNewWorktreeDialog:Ee,openWorktreesPage:ke=>{e&&G(!1),se(ke)},openProjectEditDialog:x,removeProject:z,reorderProjects:j,startSessionWorktreeMenuLoad:ft,initialActiveSessionByProject:A,persistActiveSessionByProject:D,projectViewActions:yt.actions}}),s.jsx(Zv,{onOpenSettings:O,onOpenShortcuts:_,onOpenAbout:()=>K(!0),onOpenUpdate:Me,showRuntimeButtons:!ue,showUpdateButton:oe}),s.jsx(qd,{open:C,onOpenChange:k,info:Se.info,downloading:Se.downloading,downloaded:Se.downloaded,progress:Se.progress,error:Se.error,onDownload:Se.downloadUpdate,onRestart:Se.restartToUpdate,runtimeType:Se.runtimeType}),s.jsx(Fv,{open:!!Ce,onOpenChange:ke=>{ke||x(null)},project:Ce,onSave:q}),s.jsx(Qp,{open:S,onOpenChange:N,onWorktreeCreated:(ke,tt)=>{if(De.getState().closeMainSurfaces(),e&&G(!1),tt?.sessionId){V(tt.sessionId,ke);return}xe({directoryOverride:ke,preserveDirectoryOverride:!0})}})]})})},Ak=c.memo(Nk),zn=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,ln=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Dk=()=>{const{t}=pt(),[e,n]=c.useState(!1),[r,i]=c.useState(!1),[o,l]=c.useState(null),[a,u]=c.useState([]),[d,h]=c.useState(!1),[f,g]=c.useState(!1),[p,w]=c.useState(!1),[v,x]=c.useState(!1),[m,b]=c.useState(new Set),y=Qe(me=>me.getWorktreeMetadata),S=Qe(me=>me.newSessionDraft),N=Qe(me=>me.setNewSessionDraftTarget),C=Qe(me=>me.setDraftBootstrapPendingDirectory),k=Ih,A=Rh,D=Qe(me=>me.deleteSessions),P=Qe(me=>me.archiveSessions),F=De(me=>me.showDeletionDialog),W=De(me=>me.setShowDeletionDialog),E=Zt(me=>me.currentDirectory),H=Zt(me=>me.homeDirectory),z=Zt(me=>me.isHomeReady),B=Vt(me=>me.projects),T=Vt(me=>me.activeProjectId),{isMobile:j,isTablet:I,hasTouchInput:_}=_n(),K=j||I||_,G=c.useMemo(()=>{const je=(T?B.find(ne=>ne.id===T)??null:null)?.path??E;return ln(je)},[T,E,B]),Q=c.useCallback(me=>{const ne=ln(me.projectDirectory)||G;return{id:(B.find(ce=>ln(ce.path)===ne)??null)?.id??`path:${ne}`,path:ne}},[G,B]),ge=v&&m.size>0,se=c.useMemo(()=>{const me=o?.worktree;return me&&typeof me.branch=="string"&&me.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:je})=>typeof je.branch=="string"&&je.branch.trim().length>0)},[o?.worktree,a]),Y=o?.mode==="worktree",te=Y,he=p||!Y||!se,L=p||!Y;c.useEffect(()=>{r||!z||B.length>0||(i(!0),n(!0))},[r,z,B.length]);const le=c.useCallback(me=>{l({sessions:me.sessions,dateLabel:me.dateLabel,mode:me.mode??"session",worktree:me.worktree??null})},[]),Z=c.useCallback(()=>{l(null),u([]),h(!1),g(!1),w(!1),x(!1),b(new Set)},[]),ue=c.useCallback(async me=>{if(me.sessions.length===0)return;if(me.sessions.length===1){const ce=me.sessions[0];await k(ce.id)?Fe.success(t("sessions.sidebar.session.delete.success")):Fe.error(t("sessions.sidebar.session.delete.error"));return}const je=me.sessions.map(ce=>ce.id),{deletedIds:ne,failedIds:fe}=await D(je);if(ne.length>0){const ce=fe.length>0?fe.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:fe.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:fe.length}):me.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:me.dateLabel}):void 0;Fe.success(ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ne.length}),{description:zn(ce)})}fe.length>0&&Fe.error(fe.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:fe.length}),{description:zn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,D,t]);c.useEffect(()=>hn.onDeleteRequest(me=>{if(!F&&(me.mode??"session")==="session"){ue(me);return}le(me)}),[le,F,ue]),c.useEffect(()=>hn.onDirectoryRequest(()=>{n(!0)}),[]),c.useEffect(()=>{if(!o){u([]),h(!1),g(!1),x(!1),b(new Set);return}const me=o.sessions.map(fe=>{const ce=y(fe.id);return ce?{session:fe,metadata:ce}:null}).filter(fe=>!!fe);u(me),h(!1),x(!1),b(new Set);const je=new Map;if(o.worktree?.path&&je.set(ln(o.worktree.path),o.worktree),me.forEach(({metadata:fe})=>{fe.path&&je.set(ln(fe.path),fe)}),je.size===0){x(!0);return}let ne=!1;return(async()=>{const fe=new Map,ce=new Set;await Promise.all(Array.from(je.entries()).map(async([R,$])=>{try{const de=await Th($.path);fe.set(R,de),de?.isDirty&&ce.add(R)}catch{$.status&&(fe.set(R,$.status),$.status.isDirty&&ce.add(R))}})).catch(R=>{console.warn("Failed to inspect worktree status before deletion:",R)}),!ne&&(b(ce),x(!0),l(R=>{if(!R?.worktree?.path)return R;const $=ln(R.worktree.path),de=fe.get($);if(!de)return R;const ie=R.worktree.status;return ie?.isDirty===de.isDirty&&ie?.ahead===de.ahead&&ie?.behind===de.behind&&ie?.upstream===de.upstream?R:{...R,worktree:{...R.worktree,status:de}}}),u(R=>R.map($=>{const de=ln($.metadata.path),ie=fe.get(de);return ie?{session:$.session,metadata:{...$.metadata,status:ie}}:$})))})(),()=>{ne=!0}},[o,y]),c.useEffect(()=>{se||h(!1)},[se]);const V=c.useCallback(async(me,je)=>{const ne=d&&se,fe=Q(me),ce=ln(me.path),R=ln(fe.path);try{await pd(fe,me,{deleteRemoteBranch:ne,deleteLocalBranch:je});const $=ln(S?.directoryOverride);return S?.open&&ce&&$===ce&&R&&(C(null),N({projectId:fe.id,directoryOverride:R},{force:!0})),ln(E)===ce&&R&&Zt.getState().setDirectory(R,{showOverlay:!1}),!0}catch($){return Fe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:zn($ instanceof Error?$.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[se,E,d,Q,S?.directoryOverride,S?.open,C,N,t]),ee=c.useCallback((me,je)=>{const ne=d&&se;(async()=>{if(!await V(me,je))return;const ce=t(ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Fe.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:zn(ce)})})()},[se,d,V,t]),be=c.useCallback(async()=>{if(o){w(!0);try{const me=te,je=me&&d,ne=me&&f;if(o.sessions.length===0&&Y&&o.worktree){ee(o.worktree,ne),Z();return}if(o.sessions.length===1){const fe=o.sessions[0];if(!(Y?await A(fe.id):await k(fe.id))){Fe.error(t(Y?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),w(!1);return}const R=!Y&&me?t(je?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Fe.success(t(Y?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:zn(R),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const fe=o.sessions.map($=>$.id);let ce=[],R=[];if(Y){const $=await P(fe);ce=$.archivedIds,R=$.failedIds}else{const $=await D(fe);ce=$.deletedIds,R=$.failedIds}if(Y&&o.worktree&&R.length===0&&ee(o.worktree,ne),ce.length>0){const $=!Y&&me?t(je?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,ie=[R.length>0?Y?R.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:R.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:R.length}):R.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:R.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:R.length}):o.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:o.dateLabel}):void 0,$].filter(Boolean).join(" ");Fe.success(Y?ce.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:ce.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:ce.length}):ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ce.length}),{description:zn(ie||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(R.length>0&&(Fe.error(Y?R.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:R.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:R.length}):R.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:R.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:R.length}),{description:zn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),ce.length===0)){w(!1);return}}Y&&o.sessions.length===1&&o.worktree&&ee(o.worktree,ne),Z()}finally{w(!1)}}},[o,d,f,k,D,A,P,Z,te,Y,ee,t]),xe=o?.worktree??a[0]?.metadata??null,Ne=o?o.mode==="worktree"?o.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):o.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:o.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:o.sessions.length}):o.sessions.length===1?o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:o.sessions.length,dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:o.sessions.length}):"",Pe=o?s.jsxs("div",{className:Te(Y?"space-y-3":"space-y-2"),children:[o.sessions.length>0&&s.jsxs("div",{className:Te(Y?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Y&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:o.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:o.sessions.length})]}),s.jsxs("ul",{className:Te(Y?"mt-2 space-y-1":"space-y-0.5"),children:[o.sessions.slice(0,5).map(me=>s.jsxs("li",{className:Te(Y?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:Te(!Y&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:me.title||t("sessions.sidebar.session.untitled")})]},me.id)),o.sessions.length>5&&s.jsx("li",{className:Te(Y?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:o.sessions.length-5})})]})]}),Y?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(M,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),xe?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:xe.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:xe?_r(xe.path,H):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),ge&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,Se=Y?se?s.jsxs("button",{type:"button",onClick:()=>{he||h(me=>!me)},disabled:he,className:Te("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",he?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[d?s.jsx(M,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(M,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,Re=Y?s.jsxs("button",{type:"button",onClick:()=>{L||g(me=>!me)},disabled:L,className:Te("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",L?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(M,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(M,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ye=Y?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[Re,Se]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{variant:"ghost",onClick:Z,disabled:p,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",onClick:be,disabled:p,children:t(p?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>W(!F),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!F,children:[F?s.jsx(M,{name:"checkbox-blank",className:"size-4"}):s.jsx(M,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{variant:"ghost",onClick:Z,disabled:p,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",onClick:be,disabled:p,children:p?t("sessions.sidebar.sessionDialogs.actions.deleting"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),pe=Y?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[K?s.jsx(Xo,{open:!!o,onClose:()=>{p||Z()},title:pe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ye}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Ne&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Ne}),Pe]})}):s.jsx(vs,{open:!!o,onOpenChange:me=>{if(!me){if(p)return;Z()}},children:s.jsxs(js,{className:Te(Y?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Ls,{children:[s.jsxs(Ds,{className:Te(Y&&"flex items-center gap-2"),children:[Y&&s.jsx(M,{name:"delete-bin",className:"h-5 w-5"}),pe]}),Ne&&s.jsx(Ps,{children:Ne})]}),s.jsx("div",{className:Te(Y&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:Pe}),s.jsx(gn,{className:"mt-2 gap-2 pt-1 pb-1",children:ye})]})}),s.jsx(Yp,{open:e,onOpenChange:n})]})};function Pk(t){const e=Xe.c(64),{t:n}=pt(),{value:r,onMoveSessionOnly:i,onMoveAllChanges:o,onCancel:l}=t,a=!!r;let u;e[0]!==l?(u=T=>{T||l()},e[0]=l,e[1]=u):u=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.session.moveToWorktree.confirm.title"),e[2]=n,e[3]=d):d=e[3];let h;e[4]!==d?(h=s.jsx(Ds,{children:d}),e[4]=d,e[5]=h):h=e[5];const f=r?.dirtyFileCount??0;let g;e[6]!==n||e[7]!==f?(g=n("sessions.sidebar.session.moveToWorktree.confirm.changedFiles",{count:f}),e[6]=n,e[7]=f,e[8]=g):g=e[8];let p;e[9]!==n?(p=n("sessions.sidebar.session.moveToWorktree.confirm.ownership"),e[9]=n,e[10]=p):p=e[10];let w;e[11]!==g||e[12]!==p?(w=s.jsxs(Ps,{children:[g," ",p]}),e[11]=g,e[12]=p,e[13]=w):w=e[13];let v;e[14]!==h||e[15]!==w?(v=s.jsxs(Ls,{children:[h,w]}),e[14]=h,e[15]=w,e[16]=v):v=e[16];let x;e[17]!==n?(x=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnlyHelp"),e[17]=n,e[18]=x):x=e[18];let m;e[19]!==x?(m=s.jsx("p",{children:x}),e[19]=x,e[20]=m):m=e[20];let b;e[21]!==n?(b=n("sessions.sidebar.session.moveToWorktree.confirm.allChangesHelp"),e[21]=n,e[22]=b):b=e[22];let y;e[23]!==b?(y=s.jsx("p",{children:b}),e[23]=b,e[24]=y):y=e[24];let S;e[25]!==n||e[26]!==r?(S=r&&r.stagedFileCount>0?s.jsx("p",{"data-session-worktree-move-staged-warning":"true",children:n("sessions.sidebar.session.moveToWorktree.confirm.stagedWarning")}):null,e[25]=n,e[26]=r,e[27]=S):S=e[27];let N;e[28]!==n?(N=n("sessions.sidebar.session.moveToWorktree.confirm.baseWarning"),e[28]=n,e[29]=N):N=e[29];let C;e[30]!==N?(C=s.jsx("p",{children:N}),e[30]=N,e[31]=C):C=e[31];let k;e[32]!==m||e[33]!==y||e[34]!==S||e[35]!==C?(k=s.jsxs("div",{className:"space-y-2 typography-ui-label text-muted-foreground",children:[m,y,S,C]}),e[32]=m,e[33]=y,e[34]=S,e[35]=C,e[36]=k):k=e[36];let A;e[37]!==n?(A=n("sessions.sidebar.session.moveToWorktree.confirm.cancel"),e[37]=n,e[38]=A):A=e[38];let D;e[39]!==l||e[40]!==A?(D=s.jsx(at,{type:"button",variant:"neutral","data-session-worktree-move-action":"cancel",onClick:l,children:A}),e[39]=l,e[40]=A,e[41]=D):D=e[41];let P;e[42]!==n?(P=n("sessions.sidebar.session.moveToWorktree.confirm.allChanges"),e[42]=n,e[43]=P):P=e[43];let F;e[44]!==o||e[45]!==P?(F=s.jsx(at,{type:"button",variant:"outline","data-session-worktree-move-action":"all-changes",onClick:o,children:P}),e[44]=o,e[45]=P,e[46]=F):F=e[46];let W;e[47]!==n?(W=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnly"),e[47]=n,e[48]=W):W=e[48];let E;e[49]!==i||e[50]!==W?(E=s.jsx(at,{type:"button",autoFocus:!0,"data-session-worktree-move-action":"session-only",onClick:i,children:W}),e[49]=i,e[50]=W,e[51]=E):E=e[51];let H;e[52]!==D||e[53]!==F||e[54]!==E?(H=s.jsxs(gn,{className:"gap-2 sm:justify-end",children:[D,F,E]}),e[52]=D,e[53]=F,e[54]=E,e[55]=H):H=e[55];let z;e[56]!==k||e[57]!==H||e[58]!==v?(z=s.jsxs(js,{id:"session-worktree-move-confirm-dialog",showCloseButton:!1,className:"max-w-md gap-5",children:[v,k,H]}),e[56]=k,e[57]=H,e[58]=v,e[59]=z):z=e[59];let B;return e[60]!==a||e[61]!==u||e[62]!==z?(B=s.jsx(vs,{open:a,onOpenChange:u,children:z}),e[60]=a,e[61]=u,e[62]=z,e[63]=B):B=e[63],B}function hm(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return mu.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function Ik(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},i=mu.CronExpressionParser.parse(t,r),o=[];for(let l=0;l<n;l+=1){const a=i.next();a&&o.push(a.toDate())}return o}catch{return[]}}const Tk=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],Rk={"Europe/Kiev":"Europe/Kyiv","Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Rangoon":"Asia/Yangon","Asia/Katmandu":"Asia/Kathmandu","America/Godthab":"America/Nuuk","Atlantic/Faeroe":"Atlantic/Faroe","Pacific/Enderbury":"Pacific/Kanton"},qn=t=>Rk[t]??t,pm=[0,1,2,3,4,5,6],Pc="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",la=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(qn))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],Ic=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},No=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),i=Number(e[3]),o=new Date(n,r-1,i);return Number.isNaN(o.getTime())||o.getFullYear()!==n||o.getMonth()!==r-1||o.getDate()!==i?null:o},Tc=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Ek=(t,e,n)=>{const r=No(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Rc=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),Mk=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,a=new Date(n,r+1,0).getDate(),u=new Date(n,r,0).getDate(),d=[];for(let h=0;h<42;h+=1){const f=h-l+1;if(f<=0){const g=u+f;d.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>a){d.push({date:new Date(n,r+1,f-a),inCurrentMonth:!1});continue}d.push({date:new Date(n,r,f),inCurrentMonth:!0})}return d},Ok=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],i=n>=12?"PM":"AM",o=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(o).padStart(2,"0"),minute:r,meridiem:i}},Vn=(t,e,n)=>{const r=Number(t),i=Number(e),o=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(i)?Math.min(59,Math.max(0,i)):0;let a=o%12;return n==="PM"&&(a+=12),`${String(a).padStart(2,"0")}:${String(l).padStart(2,"0")}`},br=(t,e)=>{const{max:n,min:r=0,loop:i=!1}=e;let o=Number.parseInt(t,10);return Number.isFinite(o)?(i?(o>n&&(o=r),o<r&&(o=n)):(o>n&&(o=n),o<r&&(o=r)),String(o).padStart(2,"0")):"00"},Ec=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:br(t,{min:1,max:12}),fo=t=>/^[0-5][0-9]$/.test(t)?t:br(t,{max:59}),Fk=(t,e)=>br(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Mc=(t,e)=>br(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),Bk=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},_k=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},Lk=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return pm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},$k=(t,e)=>[...t.slice(e),...t.slice(0,e)],Rs=t=>{const e=Xe.c(6),{htmlFor:n,required:r,children:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=o):o=e[1];let l;return e[2]!==i||e[3]!==n||e[4]!==o?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,o]})}),e[2]=i,e[3]=n,e[4]=o,e[5]=l):l=e[5],l},Oc=t=>{const e=Xe.c(84),{value:n,onChange:r,use24Hour:i,hourAriaLabel:o,minuteAriaLabel:l,periodAriaLabel:a,amLabel:u,pmLabel:d}=t;let h;e[0]!==n?(h=Ok(n),e[0]=n,e[1]=h):h=e[1];const f=h,g=it.useRef(null),p=it.useRef(null),[w,v]=it.useState(null),[x,m]=it.useState(null),b=it.useRef(null),y=it.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=pe=>{b.current=pe,v(pe)},e[2]=S):S=e[2];const N=S;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=pe=>{y.current=pe,m(pe)},e[3]=C):C=e[3];const k=C,A=Gk,D=qk,P=Qk;let F;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==i?(F=pe=>{const me=pe.replace(/\D/g,"").slice(0,2);N(me),me.length===2&&(r(i?P(A(me),f.minute):Vn(Ec(me),f.minute,f.meridiem)),N(null),p.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=i,e[8]=F):F=e[8];const W=F;let E;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==i?(E=()=>{const pe=b.current;if(pe!==null&&(N(null),pe.length!==0)){if(i){r(P(A(pe.padStart(2,"0")),f.minute));return}r(Vn(Ec(pe.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=i,e[13]=E):E=e[13];const H=E;let z;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==i?(z=pe=>{const me=pe.replace(/\D/g,"").slice(0,2);k(me),me.length===2&&(r(i?P(f.hour24,fo(me)):Vn(f.hour12,fo(me),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=i,e[19]=z):z=e[19];const B=z;let T;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==i?(T=()=>{const pe=y.current;pe!==null&&(k(null),pe.length!==0&&r(i?P(f.hour24,fo(pe.padStart(2,"0"))):Vn(f.hour12,fo(pe.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=i,e[25]=T):T=e[25];const j=T;let I;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==i?(I=pe=>r(i?P(D(f.hour24,pe),f.minute):Vn(Fk(f.hour12,pe),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=i,e[32]=I):I=e[32];const _=I;let K;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==i?(K=pe=>r(i?P(f.hour24,Mc(f.minute,pe)):Vn(f.hour12,Mc(f.minute,pe),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=i,e[39]=K):K=e[39];const G=K;let Q;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(Q=pe=>{pe!==f.meridiem&&r(Vn(f.hour12,f.minute,pe))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=Q):Q=e[44];const ge=Q;let se;e[45]!==H||e[46]!==_?(se=pe=>{if(pe.key==="ArrowRight"){pe.preventDefault(),H(),p.current?.focus();return}(pe.key==="ArrowUp"||pe.key==="ArrowDown")&&(pe.preventDefault(),N(null),_(pe.key==="ArrowUp"?1:-1))},e[45]=H,e[46]=_,e[47]=se):se=e[47];const Y=se;let te;e[48]!==j||e[49]!==G?(te=pe=>{if(pe.key==="ArrowLeft"&&(pe.currentTarget.selectionStart??0)===0){pe.preventDefault(),j(),g.current?.focus();return}(pe.key==="ArrowUp"||pe.key==="ArrowDown")&&(pe.preventDefault(),k(null),G(pe.key==="ArrowUp"?1:-1))},e[48]=j,e[49]=G,e[50]=te):te=e[50];const he=te,L=i?"px-2":"pl-2 pr-1";let le;e[51]!==L?(le=Te("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",L),e[51]=L,e[52]=le):le=e[52];const Z=w??(i?f.hour24:f.hour12);let ue;e[53]!==W?(ue=pe=>W(pe.target.value),e[53]=W,e[54]=ue):ue=e[54];let V;e[55]===Symbol.for("react.memo_cache_sentinel")?(V=()=>N(""),e[55]=V):V=e[55];let ee;e[56]!==H||e[57]!==o||e[58]!==Y||e[59]!==Z||e[60]!==ue?(ee=s.jsx("input",{ref:g,inputMode:"numeric",value:Z,onChange:ue,onKeyDown:Y,onFocus:V,onBlur:H,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=H,e[57]=o,e[58]=Y,e[59]=Z,e[60]=ue,e[61]=ee):ee=e[61];let be;e[62]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=be):be=e[62];const xe=x??f.minute;let Ne;e[63]!==B?(Ne=pe=>B(pe.target.value),e[63]=B,e[64]=Ne):Ne=e[64];let Pe;e[65]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>k(""),e[65]=Pe):Pe=e[65];let Se;e[66]!==j||e[67]!==l||e[68]!==he||e[69]!==xe||e[70]!==Ne?(Se=s.jsx("input",{ref:p,inputMode:"numeric",value:xe,onChange:Ne,onKeyDown:he,onFocus:Pe,onBlur:j,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=j,e[67]=l,e[68]=he,e[69]=xe,e[70]=Ne,e[71]=Se):Se=e[71];let Re;e[72]!==u||e[73]!==f.meridiem||e[74]!==a||e[75]!==d||e[76]!==ge||e[77]!==i?(Re=i?null:s.jsxs(Ms,{value:f.meridiem,onValueChange:pe=>ge(pe),children:[s.jsx(Os,{"aria-label":a,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Cs,{})}),s.jsxs(Fs,{children:[s.jsx(es,{value:"AM",children:u}),s.jsx(es,{value:"PM",children:d})]})]}),e[72]=u,e[73]=f.meridiem,e[74]=a,e[75]=d,e[76]=ge,e[77]=i,e[78]=Re):Re=e[78];let ye;return e[79]!==le||e[80]!==ee||e[81]!==Se||e[82]!==Re?(ye=s.jsxs("div",{className:le,children:[ee,be,Se,Re]}),e[79]=le,e[80]=ee,e[81]=Se,e[82]=Re,e[83]=ye):ye=e[83],ye},Fc=t=>new Date(t.getFullYear(),t.getMonth(),1),Wk=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Bc=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),zk=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(i=>typeof i=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(i)).map(i=>i.trim()),r=Array.from(new Set(n)).sort((i,o)=>i.localeCompare(o));return r.length>0?r:["09:00"]},_c=(t,e)=>{const n=qn(Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC");return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:zk(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Ic(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:qn(t.schedule.timezone||n),cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null,permissionAutoAccept:t.execution.permissionAutoAccept===!0},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:Ic(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null,permissionAutoAccept:!1}}},Vk=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!hm(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},Uk=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},Kk=t=>{const e=Xe.c(64),{draft:n,setDraft:r,locale:i,t:o}=t,l=n.schedule.cronExpression;let a;e[0]!==l?(a=l.trim()?hm(l):null,e[0]=l,e[1]=a):a=e[1];const u=a;let d;e:{if(!u?.valid||!l.trim()){let I;e[2]===Symbol.for("react.memo_cache_sentinel")?(I=[],e[2]=I):I=e[2],d=I;break e}let j;e[3]!==l||e[4]!==n.schedule.timezone?(j=Ik(l,n.schedule.timezone),e[3]=l,e[4]=n.schedule.timezone,e[5]=j):j=e[5],d=j}const h=d;let f;e[6]!==n.schedule.timezone||e[7]!==i?(f=j=>new Intl.DateTimeFormat(i,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(j),e[6]=n.schedule.timezone,e[7]=i,e[8]=f):f=e[8];const g=f;let p;e[9]!==o?(p=o("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=o,e[10]=p):p=e[10];let w;e[11]!==p?(w=s.jsx(Rs,{htmlFor:"sched-cron",required:!0,children:p}),e[11]=p,e[12]=w):w=e[12];let v;e[13]!==r?(v=j=>r(I=>({...I,schedule:{...I.schedule,cronExpression:j.target.value}})),e[13]=r,e[14]=v):v=e[14];let x;e[15]!==o?(x=o("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=o,e[16]=x):x=e[16];let m;e[17]!==l||e[18]!==v||e[19]!==x?(m=s.jsx(jn,{id:"sched-cron",value:l,onChange:v,placeholder:x,className:"w-full max-w-xs font-mono"}),e[17]=l,e[18]=v,e[19]=x,e[20]=m):m=e[20];let b;e[21]!==l||e[22]!==u||e[23]!==o?(b=u&&!u.valid&&l.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:o("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=l,e[22]=u,e[23]=o,e[24]=b):b=e[24];let y;e[25]!==w||e[26]!==m||e[27]!==b?(y=s.jsxs("div",{className:"flex flex-col gap-1",children:[w,m,b]}),e[25]=w,e[26]=m,e[27]=b,e[28]=y):y=e[28];let S;e[29]!==g||e[30]!==h||e[31]!==o?(S=h.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:h.map(g).join(", ")})]}):null,e[29]=g,e[30]=h,e[31]=o,e[32]=S):S=e[32];let N;e[33]!==o?(N=o("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=o,e[34]=N):N=e[34];let C;e[35]!==N?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[35]=N,e[36]=C):C=e[36];let k;e[37]!==r||e[38]!==o?(k=Tk.map(j=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(I=>({...I,schedule:{...I.schedule,cronExpression:j.expression}})),children:[s.jsx("span",{className:"font-mono",children:j.expression}),s.jsx("span",{className:"text-muted-foreground",children:o(j.labelKey)})]},j.expression)),e[37]=r,e[38]=o,e[39]=k):k=e[39];let A;e[40]!==k?(A=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:k}),e[40]=k,e[41]=A):A=e[41];let D;e[42]!==C||e[43]!==A?(D=s.jsxs("div",{className:"flex flex-col gap-1",children:[C,A]}),e[42]=C,e[43]=A,e[44]=D):D=e[44];let P;e[45]!==o?(P=o("sessions.scheduledTasks.editor.timezone.label"),e[45]=o,e[46]=P):P=e[46];let F;e[47]!==P?(F=s.jsx(Rs,{children:P}),e[47]=P,e[48]=F):F=e[48];let W;e[49]!==r?(W=j=>{r(I=>({...I,schedule:{...I.schedule,timezone:j}}))},e[49]=r,e[50]=W):W=e[50];let E;e[51]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Os,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),e[51]=E):E=e[51];let H;e[52]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(Fs,{children:la.map(Yk)}),e[52]=H):H=e[52];let z;e[53]!==n.schedule.timezone||e[54]!==W?(z=s.jsxs(Ms,{value:n.schedule.timezone,onValueChange:W,children:[E,H]}),e[53]=n.schedule.timezone,e[54]=W,e[55]=z):z=e[55];let B;e[56]!==F||e[57]!==z?(B=s.jsxs("div",{className:"flex flex-col gap-1",children:[F,z]}),e[56]=F,e[57]=z,e[58]=B):B=e[58];let T;return e[59]!==y||e[60]!==S||e[61]!==D||e[62]!==B?(T=s.jsxs("div",{className:"flex flex-col gap-3",children:[y,S,D,B]}),e[59]=y,e[60]=S,e[61]=D,e[62]=B,e[63]=T):T=e[63],T};function Hk(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:o,locale:l}=pt(),a=Ut(O=>O.loadProviders),u=Ut(O=>O.loadAgents),d=Ut(O=>O.providers),h=Ut(O=>O.currentProviderId),f=Ut(O=>O.currentModelId),g=Ut(O=>O.currentVariant||""),p=Ut(O=>O.currentAgentName||""),w=De(O=>O.timeFormatPreference),v=De(O=>O.weekStartPreference),x=De(O=>O.isMobile),[m,b]=it.useState(()=>_c(n,{providerID:h,modelID:f,variant:g,agent:p})),[y,S]=it.useState(!1),[N,C]=it.useState(!1),[k,A]=it.useState(!1),[D,P]=it.useState(""),[F,W]=it.useState(!1),[E,H]=it.useState(""),[z,B]=it.useState(!1),[T,j]=it.useState(""),[I,_]=it.useState(()=>{const O=No(n?.schedule?.date||"")||new Date;return new Date(O.getFullYear(),O.getMonth(),1)}),K=it.useRef(null),G=it.useRef(null),Q=it.useRef(null),ge=it.useRef(null),se=it.useRef(null),Y=it.useMemo(()=>_k(l),[l]),te=it.useMemo(()=>Bk(l),[l]),he=it.useMemo(()=>w==="24h"?!0:w==="12h"?!1:Y,[w,Y]),L=it.useMemo(()=>v==="sunday"?0:v==="monday"?1:te,[v,te]),le=it.useMemo(()=>{const O=Lk(l);return $k(pm.map(oe=>({value:oe,label:O[oe]||""})),L)},[l,L]);it.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),u({source:"scheduledTaskEditor"}))},[e,a,u]),it.useEffect(()=>{if(!e)return;b(_c(n,{providerID:h,modelID:f,variant:g,agent:p}));const O=No(n?.schedule?.date||"")||new Date;_(new Date(O.getFullYear(),O.getMonth(),1)),C(!1),W(!1),A(!1),H(""),P("")},[e,n,h,f,g,p]),it.useEffect(()=>{if(!N)return;const O=oe=>{K.current&&!K.current.contains(oe.target)&&C(!1)};return document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[N]);const Z=it.useMemo(()=>{const oe=d.find(re=>re.id===m.execution.providerID)?.models?.find(re=>re.id===m.execution.modelID);return oe?.variants?Object.keys(oe.variants):[]},[d,m.execution.providerID,m.execution.modelID]),ue=Z.length>0,V=it.useMemo(()=>!ue||!m.execution.variant?"__default":Z.includes(m.execution.variant)?m.execution.variant:"__default",[m.execution.variant,ue,Z]);it.useEffect(()=>{ue||!m.execution.variant||b(O=>({...O,execution:{...O.execution,variant:""}}))},[ue,m.execution.variant]);const ee=it.useCallback((O,oe)=>{b(re=>{const we=new Set(re.schedule.weekdays);return oe?we.add(O):we.delete(O),{...re,schedule:{...re.schedule,weekdays:Array.from(we).sort((Ve,st)=>Ve-st)}}})},[]),be=it.useCallback((O,oe)=>{b(re=>{const we=re.schedule.times.slice();return we[O]=oe,{...re,schedule:{...re.schedule,times:we}}})},[]),xe=it.useCallback(O=>{b(oe=>{const re=oe.schedule.times.filter((we,Ve)=>Ve!==O);return{...oe,schedule:{...oe.schedule,times:re.length>0?re:["09:00"]}}})},[]),Ne=it.useCallback(()=>{b(O=>({...O,schedule:{...O.schedule,times:[...O.schedule.times,"12:00"]}}))},[]),Pe=it.useMemo(()=>Wk(),[]),Se=it.useMemo(()=>Fc(Pe),[Pe]),Re=it.useMemo(()=>{const O=No(m.schedule.onceDate);return O?Bc(O,Pe)?o("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(O):null},[m.schedule.onceDate,l,o,Pe]),ye=it.useMemo(()=>Fc(I).getTime()<=Se.getTime(),[I,Se]),pe=it.useMemo(()=>le.map(O=>O.label),[le]),me=it.useCallback(O=>{b(oe=>({...oe,schedule:{...oe.schedule,onceDate:O}}))},[]),je=it.useCallback((O,oe)=>{if(O.startsWith("/")){const st=O.indexOf(" "),Ge=O.indexOf(`
|
|
922
|
-
`),ae=Math.min(st===-1?O.length:st,Ge===-1?O.length:Ge);if(oe<=ae&&st===-1){H(O.substring(1,ae)),W(!0),A(!1),B(!1);return}}W(!1);const re=O.substring(0,oe),we=re.lastIndexOf("#");if(we!==-1){const st=we>0?re[we-1]:null,Ge=re.substring(we+1);if((!st||/\s/.test(st))&&!Ge.includes(" ")&&!Ge.includes(`
|
|
923
|
-
`)){j(Ge),B(!0),A(!1);return}}B(!1);const Ve=re.lastIndexOf("@");if(Ve!==-1){const st=Ve>0?re[Ve-1]:null,Ge=re.substring(Ve+1);(!st||/\s/.test(st))&&!Ge.includes(" ")&&!Ge.includes(`
|
|
924
|
-
`)?(P(Ge),A(!0)):A(!1);return}A(!1)},[]),ne=it.useCallback(O=>{b(oe=>({...oe,execution:{...oe.execution,prompt:O}}))},[]),fe=it.useCallback(O=>{const oe=m.execution.prompt,we=G.current?.selectionStart??oe.length,st=oe.substring(0,we).lastIndexOf("@"),Ge=O.relativePath&&O.relativePath.trim().length>0?O.relativePath.trim():O.path||O.name,ae=st!==-1?st:we,X=`${oe.substring(0,ae)}@${Ge} ${oe.substring(we)}`,ve=ae+Ge.length+2;ne(X),A(!1),P(""),requestAnimationFrame(()=>{const Le=G.current;Le&&(Le.selectionStart=ve,Le.selectionEnd=ve,Le.focus()),je(X,ve)})},[m.execution.prompt,ne,je]),ce=it.useCallback(O=>{const oe=m.execution.prompt,we=G.current?.selectionStart??oe.length,st=oe.substring(0,we).lastIndexOf("@"),Ge=st!==-1?st:we,ae=`${oe.substring(0,Ge)}@${O} ${oe.substring(we)}`,X=Ge+O.length+2;ne(ae),A(!1),P(""),requestAnimationFrame(()=>{const ve=G.current;ve&&(ve.selectionStart=X,ve.selectionEnd=X,ve.focus()),je(ae,X)})},[m.execution.prompt,ne,je]),R=it.useCallback(O=>{const oe=`/${O.name} `;ne(oe),W(!1),H(""),B(!1),requestAnimationFrame(()=>{const re=G.current;re&&(re.focus(),re.selectionStart=re.value.length,re.selectionEnd=re.value.length),je(oe,oe.length)})},[ne,je]),$=it.useCallback((O,oe)=>{const re=m.execution.prompt,Ve=G.current?.selectionStart??re.length,Ge=re.substring(0,Ve).lastIndexOf("#"),ae=Ge!==-1?Ge:Ve,X=`${re.substring(0,ae)}#${oe} ${re.substring(Ve)}`,ve=ae+oe.length+2;ne(X),B(!1),j(""),requestAnimationFrame(()=>{const Le=G.current;Le&&(Le.selectionStart=ve,Le.selectionEnd=ve,Le.focus()),je(X,ve)})},[m.execution.prompt,ne,je]),de=it.useCallback(O=>{if(F&&ge.current&&(O.key==="Enter"||O.key==="ArrowUp"||O.key==="ArrowDown"||O.key==="Escape"||O.key==="Tab")){O.preventDefault(),ge.current.handleKeyDown(O.key);return}k&&Q.current&&(O.key==="Enter"||O.key==="ArrowUp"||O.key==="ArrowDown"||O.key==="Escape"||O.key==="Tab")&&(O.preventDefault(),Q.current.handleKeyDown(O.key)),z&&se.current&&(O.key==="Enter"||O.key==="ArrowUp"||O.key==="ArrowDown"||O.key==="Escape"||O.key==="Tab")&&(O.preventDefault(),se.current.handleKeyDown(O.key))},[F,k,z]),ie=it.useCallback(async()=>{const O=Vk(m,o);if(O){Fe.error(O);return}const oe={...m.id?{id:m.id}:{},name:m.name.trim(),enabled:m.enabled,schedule:{kind:m.schedule.kind,timezone:m.schedule.timezone.trim(),...m.schedule.kind==="cron"?{cron:m.schedule.cronExpression.trim()}:m.schedule.kind==="once"?{date:m.schedule.onceDate,time:m.schedule.onceTime}:{times:Uk(m.schedule.times),...m.schedule.kind==="weekly"?{weekdays:m.schedule.weekdays}:{}}},execution:{prompt:m.execution.prompt,providerID:m.execution.providerID,modelID:m.execution.modelID,...m.execution.variant.trim()?{variant:m.execution.variant.trim()}:{},...m.execution.agent.trim()?{agent:m.execution.agent.trim()}:{},...m.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...m.execution.goalEnabled?{goalEnabled:!0}:{},...m.execution.goalEnabled&&m.execution.goalTokenBudget?{goalTokenBudget:m.execution.goalTokenBudget}:{}},...m.state?{state:m.state}:{}};S(!0);try{await i(oe),r(!1)}catch(re){Fe.error(re instanceof Error?re.message:o("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[m,r,i,o]),Ae=it.useId(),Be=it.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),Ce=o(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),q=o("sessions.scheduledTasks.editor.description"),Ee=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Rs,{htmlFor:"sched-name",required:!0,children:o("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(jn,{id:"sched-name",value:m.name,onChange:O=>b(oe=>({...oe,name:O.target.value})),placeholder:o("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Ms,{value:m.schedule.kind,onValueChange:O=>{b(oe=>({...oe,schedule:{...oe.schedule,kind:O,...O==="cron"&&!oe.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Os,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{children:O=>o(O==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":O==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":O==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Fs,{children:[s.jsx(es,{value:"daily",children:o("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(es,{value:"weekly",children:o("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(es,{value:"once",children:o("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(es,{value:"cron",children:o("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),m.schedule.kind==="cron"?s.jsx(Kk,{draft:m,setDraft:b,locale:l,t:o}):m.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:K,children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Te(Md({size:"default"}),"w-fit max-w-full"),onClick:()=>C(O=>!O),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(M,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ek(m.schedule.onceDate,o("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(M,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),N?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>_(O=>Rc(O,-1)),"aria-label":o("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ye,children:s.jsx(M,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(I)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(O=>Rc(O,1)),"aria-label":o("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(M,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:pe.map((O,oe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:O},`${O}-${oe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:Mk(I,L).map(({date:O,inCurrentMonth:oe})=>{const re=Tc(O),we=re===m.schedule.onceDate,Ve=Bc(O,Pe),st=O.getTime()<Pe.getTime(),Ge=we?"bg-interactive-selection text-interactive-selection-foreground":st?"text-muted-foreground/40":oe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{st||(me(re),C(!1))},disabled:st,className:["h-8 rounded-md typography-ui-label",Ge,Ve&&!we?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",st?"cursor-not-allowed opacity-45":""].join(" "),children:O.getDate()},re)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Re||""}),s.jsx(at,{type:"button",size:"xs",variant:"ghost",onClick:()=>{me(Tc(Pe)),_(new Date(Pe.getFullYear(),Pe.getMonth(),1))},children:o("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.time.label")}),s.jsx(Oc,{value:m.schedule.onceTime,use24Hour:he,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:O=>b(oe=>({...oe,schedule:{...oe.schedule,onceTime:O}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ms,{value:m.schedule.timezone,onValueChange:O=>{b(oe=>({...oe,schedule:{...oe.schedule,timezone:O}}))},children:[s.jsx(Os,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),s.jsx(Fs,{children:la.map(O=>s.jsx(es,{value:O,children:O},O))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[m.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:le.map(O=>{const oe=m.schedule.weekdays.includes(O.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",oe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(lr,{checked:oe,onChange:re=>ee(O.value,re),ariaLabel:O.label}),s.jsx("button",{type:"button",onClick:()=>ee(O.value,!oe),className:"group-hover:text-foreground",children:O.label})]},O.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:m.schedule.times.map((O,oe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Oc,{value:O,use24Hour:he,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:re=>be(oe,re)}),m.schedule.times.length>1?s.jsx(at,{type:"button",size:"icon",variant:"ghost",onClick:()=>xe(oe),"aria-label":o("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(M,{name:"close",className:"h-4 w-4"})}):null]},oe))}),s.jsx("div",{children:s.jsxs(at,{type:"button",size:"sm",variant:"outline",onClick:Ne,children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"})," ",o("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ms,{value:m.schedule.timezone,onValueChange:O=>{b(oe=>({...oe,schedule:{...oe.schedule,timezone:O}}))},children:[s.jsx(Os,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{})}),s.jsx(Fs,{children:la.map(O=>s.jsx(es,{value:O,children:O},O))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Rs,{required:!0,children:o("sessions.scheduledTasks.editor.model.label")}),s.jsx(Eh,{providerId:m.execution.providerID,modelId:m.execution.modelID,onChange:(O,oe)=>{b(re=>({...re,execution:{...re.execution,providerID:O,modelID:oe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Ms,{value:V,disabled:!ue,onValueChange:O=>{b(oe=>({...oe,execution:{...oe.execution,variant:O==="__default"?"":O}}))},children:[s.jsx(Os,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Cs,{children:O=>O==="__default"?o("sessions.scheduledTasks.editor.thinkingLevel.default"):O})}),s.jsxs(Fs,{children:[s.jsx(es,{value:"__default",children:o("sessions.scheduledTasks.editor.thinkingLevel.default")}),Z.map(O=>s.jsx(es,{value:O,children:O},O))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Rs,{children:o("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Mh,{agentName:m.execution.agent,filter:O=>Ed(O.mode),onChange:O=>b(oe=>({...oe,execution:{...oe.execution,agent:O}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Rs,{htmlFor:"sched-prompt",required:!0,children:o("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(or,{id:"sched-prompt",ref:G,value:m.execution.prompt,onChange:O=>{const oe=O.target.value;ne(oe);const re=O.target.selectionStart??oe.length;je(oe,re)},onKeyDown:de,rows:8,placeholder:o("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),F?s.jsx(Wd,{ref:ge,searchQuery:E,onCommandSelect:R,onClose:()=>W(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(zd,{ref:Q,searchQuery:D,onFileSelect:fe,onAgentSelect:ce,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,z?s.jsx(Vd,{ref:se,searchQuery:T,onSnippetSelect:$,onClose:()=>B(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),m.execution.goalEnabled?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(lr,{checked:m.execution.goalTokenBudget!==null,onChange:O=>b(oe=>({...oe,execution:{...oe.execution,goalTokenBudget:O?2e5:null}})),ariaLabel:o("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),m.execution.goalTokenBudget!==null?s.jsx(Oh,{value:m.execution.goalTokenBudget,onValueChange:O=>{typeof O=="number"&&Number.isFinite(O)&&O>0&&b(oe=>({...oe,execution:{...oe.execution,goalTokenBudget:Math.floor(O)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),Me=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(lr,{checked:m.enabled,onChange:O=>b(oe=>({...oe,enabled:O})),ariaLabel:o("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",className:Te(Pc),onClick:()=>b(O=>({...O,execution:{...O.execution,permissionAutoAccept:!O.execution.permissionAutoAccept}})),"aria-pressed":m.execution.permissionAutoAccept,"aria-label":o("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:m.execution.permissionAutoAccept?s.jsx(M,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(M,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(bt,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",className:Te(Pc,m.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>b(O=>({...O,execution:{...O.execution,goalEnabled:!O.execution.goalEnabled}})),"aria-pressed":m.execution.goalEnabled,"aria-label":o("sessions.scheduledTasks.editor.goal.aria"),children:m.execution.goalEnabled?s.jsx(M,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(M,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(bt,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:o("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(at,{type:"button",size:"sm",onClick:ie,disabled:y,children:o(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Xo,{open:e,title:Ce,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:O=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:Ce}),O]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:q})]}),footer:Me,children:Ee}):s.jsx(vs,{open:e,onOpenChange:O=>{!O&&Be()||r(O)},children:s.jsxs(js,{"aria-describedby":Ae,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ps,{id:Ae,className:"sr-only",children:q}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Ds,{className:"typography-ui-label font-medium text-foreground",children:Ce}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:q})]})}),s.jsx(ya,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ee})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Me})})]})})}function Gk(t){return br(t,{min:0,max:23})}function qk(t,e){return br(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function Qk(t,e){const n=Number(t),r=Number(e),i=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,o=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(i).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function Yk(t){return s.jsx(es,{value:t,children:t},t)}const Xk=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,i)=>r.localeCompare(i))},Jk=(t,e)=>{const n=Xk(t).join(", ")||"--:--",r=i=>e(i===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":i===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":i===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":i===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":i===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":i===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":i===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const i=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(o=>r(o)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:i,time:n,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:i,time:n})}if(t.schedule.kind==="once"){const i=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),o=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:i,time:o,timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:i,time:o})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:qn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},Zk=(t,e)=>!t||!Number.isFinite(t)?"":Fh(t,e),Lc=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),i=6e4,o=60*i,l=24*o,a=n>=0;if(r<i)return e(a?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<o){const f=Math.round(r/i);return a?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<l){const f=Math.floor(r/o),g=Math.round(r%o/i),p=g>0?`${f}h ${g}m`:`${f}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:p}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:p})}const u=Math.floor(r/l),d=Math.round(r%l/o),h=d>0?`${u}d ${d}h`:`${u}d`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:h}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:h})},e4={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},t4=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function s4(){const{t}=pt(),e=De(j=>j.isScheduledTasksDialogOpen),n=De(j=>j.setScheduledTasksDialogOpen),r=De(j=>j.isMobile),i=De(j=>j.timeFormatPreference),o=Vt(j=>j.projects),l=Vt(j=>j.getActiveProject()),a=Zt(j=>j.homeDirectory),{currentTheme:u}=Jn(),[d,h]=it.useState(""),[f,g]=it.useState([]),[p,w]=it.useState(!0),[v,x]=it.useState(!1),[m,b]=it.useState(null),[y,S]=it.useState(null),N=it.useMemo(()=>o.find(j=>j.id===d)||null,[o,d]),C=it.useCallback(j=>{const I=j.label?.trim()||Fn(j.path,a||void 0),_=j.icon?ja[j.icon]:null,K=j.color?ka[j.color]:void 0,G=_?s.jsx(M,{name:_,className:"h-3.5 w-3.5 shrink-0",style:K?{color:K}:void 0}):s.jsx(M,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:K?{color:K}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[j.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Ca,{project:{id:j.id,iconImage:j.iconImage??null},options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:G})}):G,s.jsx("span",{className:"truncate",children:I})]})},[a,u.metadata.variant,u.colors.surface.foreground]),k=it.useCallback(async(j,I)=>{if(!j){g([]);return}I?.silent||w(!0);try{const _=await lg(j);_.sort((K,G)=>{if(K.enabled!==G.enabled)return K.enabled?-1:1;const Q=K.name.localeCompare(G.name);return Q!==0?Q:(K.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(G.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(_)}catch(_){Fe.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),I?.silent||g([])}finally{I?.silent||w(!1)}},[t]);it.useEffect(()=>{if(!e)return;const j=l?.id||o[0]?.id||"";h(j),j?k(j):(g([]),w(!1))},[e,l,o,k]),it.useEffect(()=>{if(!e)return;let j=null;const I=Yr(_=>{_.type==="scheduled-task-ran"&&_.projectId===d&&(j&&clearTimeout(j),j=setTimeout(()=>{k(d,{silent:!0})},400))});return()=>{j&&clearTimeout(j),I()}},[e,d,k]);const A=it.useCallback(async j=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Sl(d,j),await k(d),Fe.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,k,t]),D=it.useCallback(async(j,I)=>{if(d){S(j.id),g(_=>_.map(K=>K.id===j.id?{...K,enabled:I}:K));try{j.loopFile?await cg(d,j.id,I):await Sl(d,{...j,enabled:I}),await k(d,{silent:!0})}catch(_){Fe.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(d,{silent:!0})}finally{S(null)}}},[d,k,t]),P=it.useCallback(async j=>{if(!(!d||!window.confirm(j.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:j.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:j.name})))){S(j.id);try{j.loopFile?await dg(d,j.id):await ug(d,j.id),await k(d,{silent:!0}),Fe.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){Fe.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[d,k,t]),F=it.useCallback(j=>{if(!j.loopFile){b(j),x(!0);return}N?.path&&(n(!1),dn.getState().setSelectedPath(N.path,j.loopFile,{allowOutsideRoot:!0}),De.getState().openContextFile(N.path,j.loopFile))},[N?.path,n]),W=it.useCallback(async j=>{if(d){S(j.id);try{const{sessionId:I,persistError:_}=await mg(d,j.id);if(await Promise.all([k(d,{silent:!0}),Ia()]),_?Fe.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):Fe.success(t("sessions.scheduledTasks.dialog.toast.started")),I){const K=o.find(G=>G.id===d);Qe.getState().setCurrentSession(I,K?.path??null)}}catch(I){Fe.error(I instanceof Error?I.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[d,o,k,t]),E=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Ms,{value:d||"__none",onValueChange:j=>{const I=j==="__none"?"":j;h(I),I?k(I):g([])},children:[s.jsx(Os,{size:"lg",className:r?"w-full":void 0,children:N?s.jsx(Cs,{children:C(N)}):s.jsx(Cs,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Fs,{children:[o.length===0?s.jsx(es,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,o.map(j=>s.jsx(es,{value:j.id,children:C(j)},j.id))]})]})]}),H=()=>{b(null),x(!0)},z=j=>{h(j),j?k(j):g([])},B=s.jsx("div",{className:"min-h-[280px]",children:p?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(j=>{const I=y===j.id,_=j.state?.lastStatus||"idle",K=e4[_],G=t(_==="success"?"sessions.scheduledTasks.dialog.status.success":_==="error"?"sessions.scheduledTasks.dialog.status.error":_==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Q=j.state?.nextRunAt,ge=j.state?.lastRunAt;return s.jsxs("div",{className:Te("rounded-lg border border-border p-4 transition-opacity",!j.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:j.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:Jk(j,t)}),j.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:j.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:j.loopFile})}):null]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(M,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),Q?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Lc(Q,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Zk(Q,i)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(M,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(M,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):ge?s.jsxs(s.Fragment,{children:[K.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${K.tone})`},children:[s.jsx(M,{name:K.Icon,className:"h-3.5 w-3.5"}),G]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Lc(ge,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),j.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:t4("error"),children:[s.jsx(M,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:j.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Te("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",j.enabled?"text-foreground":"text-muted-foreground",I&&"cursor-not-allowed opacity-50"),children:[s.jsx(lr,{checked:j.enabled,onChange:se=>{D(j,se)},ariaLabel:j.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:j.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:j.name}),disabled:I}),j.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(at,{variant:"outline",size:"sm",onClick:()=>{W(j)},disabled:I,children:[s.jsx(M,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(at,{variant:"outline",size:"sm",onClick:()=>F(j),disabled:I,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:j.name}),children:[s.jsx(M,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(at,{variant:"destructive",size:"sm",onClick:()=>{P(j)},disabled:I,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:j.name}),children:s.jsx(M,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},j.id)})})}),T=s.jsxs("div",{className:"space-y-4",children:[E,B]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Xo,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:j=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),j]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(at,{className:"w-full",onClick:H,disabled:!d,children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:o.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):o.map(j=>s.jsx("button",{type:"button",onClick:()=>z(j.id),className:Te("flex w-full min-w-0 items-center rounded-md px-2 py-1.5 text-left typography-ui-label focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",d===j.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:C(j)},j.id))})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("div",{className:"flex items-center px-6 pt-3",children:s.jsxs(at,{size:"sm",onClick:H,disabled:!d,children:[s.jsx(M,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-4",children:s.jsx("div",{className:"mx-auto w-full max-w-3xl",children:B})})]})]})}):null,s.jsx(Hk,{open:v,task:m,onOpenChange:x,onSave:A})]})}const Ao=100;function n4(){const t=Xe.c(101),{t:e}=pt(),n=De(m4),r=De(u4),i=Qe(d4),o=Qe(c4),l=Zt(l4);let a;t[0]!==n?(a=Q=>n?Q.archivedSessions:[],t[0]=n,t[1]=a):a=t[1];const u=As(Xn(a)),[d,h]=c.useState(""),[f,g]=c.useState(null),[p,w]=c.useState(Ao);let v;t[2]!==d?(v=d.trim().toLowerCase(),t[2]=d,t[3]=v):v=t[3];const x=v;let m;e:{if(!n){let ge;t[4]===Symbol.for("react.memo_cache_sentinel")?(ge=[],t[4]=ge):ge=t[4],m=ge;break e}let Q;t[5]!==u?(Q=[...u].sort(a4),t[5]=u,t[6]=Q):Q=t[6],m=Q}const b=m;let y;if(t[7]!==l||t[8]!==b||t[9]!==e){const Q=new Map;for(const ge of b){const se=ct(_s(ge))??"",Y=Q.get(se);if(Y){Y.sessions.push(ge);continue}Q.set(se,{directory:se,label:se?Fn(se,l)||se:e("sessions.archivePage.otherProjects"),sessions:[ge]})}y=[...Q.values()].sort(i4),t[7]=l,t[8]=b,t[9]=e,t[10]=y}else y=t[10];const S=y;let N;e:{if(x){let ge;t[11]!==x||t[12]!==b?(ge=Bh(b,x,o4),t[11]=x,t[12]=b,t[13]=ge):ge=t[13],N=ge;break e}if(f===null){N=b;break e}let Q;t[14]!==S||t[15]!==f?(Q=S.find(ge=>ge.directory===f)?.sessions??[],t[14]=S,t[15]=f,t[16]=Q):Q=t[16],N=Q}const C=N;let k,A,D,P,F,W,E,H,z,B;if(t[17]!==u.length||t[18]!==S||t[19]!==C||t[20]!==l||t[21]!==x||t[22]!==n||t[23]!==d||t[24]!==f||t[25]!==i||t[26]!==r||t[27]!==e||t[28]!==o||t[29]!==p){F=Symbol.for("react.early_return_sentinel");e:{const Q=C.slice(0,p);k=C.length-Q.length;const ge=u.length;let se;t[40]===Symbol.for("react.memo_cache_sentinel")?(se=ye=>{g(ye),w(Ao)},t[40]=se):se=t[40];const Y=se;let te;t[41]!==i||t[42]!==r?(te=ye=>{const pe=ct(_s(ye));i(ye.id,pe??void 0),r(!1)},t[41]=i,t[42]=r,t[43]=te):te=t[43];const he=te;let L;t[44]!==e||t[45]!==o?(L=ye=>{o(ye.id).then(pe=>{pe?Fe.success(e("sessions.sidebar.session.restore.success")):Fe.error(e("sessions.sidebar.session.restore.error"))})},t[44]=e,t[45]=o,t[46]=L):L=t[46];const le=L;if(!n){F=null;break e}let Z;t[47]!==e?(Z=(ye,pe,me,je,ne,fe,ce)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:ne,title:fe,className:Te("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",ce?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",je?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:pe}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:me})]}),ce?s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>hn.requestDelete({sessions:ce,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteProjectAria",{label:pe}),children:s.jsx(M,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(bt,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},ye),t[47]=e,t[48]=Z):Z=t[48];const ue=Z;P="absolute inset-0 z-10 flex flex-col bg-background",A="flex min-h-0 flex-1";let V;if(t[49]!==ue||t[50]!==f||t[51]!==e||t[52]!==ge){let ye;t[54]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>Y(null),t[54]=ye):ye=t[54],V=ue("__all__",e("sessions.archivePage.allDirectories"),ge,f===null,ye),t[49]=ue,t[50]=f,t[51]=e,t[52]=ge,t[53]=V}else V=t[53];let ee;if(t[55]!==S||t[56]!==ue||t[57]!==f){let ye;t[59]!==ue||t[60]!==f?(ye=pe=>ue(pe.directory||"__none__",pe.label,pe.sessions.length,f===pe.directory,()=>Y(pe.directory),pe.directory||void 0,pe.sessions),t[59]=ue,t[60]=f,t[61]=ye):ye=t[61],ee=S.map(ye),t[55]=S,t[56]=ue,t[57]=f,t[58]=ee}else ee=t[58];t[62]!==V||t[63]!==ee?(D=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[V,ee]})}),t[62]=V,t[63]=ee,t[64]=D):D=t[64],z="flex min-w-0 flex-1 flex-col";let be;t[65]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(M,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[65]=be):be=t[65];let xe;t[66]===Symbol.for("react.memo_cache_sentinel")?(xe=ye=>{h(ye.target.value),w(Ao)},t[66]=xe):xe=t[66];let Ne;t[67]!==e?(Ne=e("sessions.archivePage.searchPlaceholder"),t[67]=e,t[68]=Ne):Ne=t[68];let Pe;t[69]!==d||t[70]!==Ne?(Pe=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[be,s.jsx("input",{value:d,onChange:xe,placeholder:Ne,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[69]=d,t[70]=Ne,t[71]=Pe):Pe=t[71];let Se;t[72]!==C.length||t[73]!==e?(Se=C.length===1?e("sessions.archivePage.countSingle",{count:C.length}):e("sessions.archivePage.countPlural",{count:C.length}),t[72]=C.length,t[73]=e,t[74]=Se):Se=t[74];let Re;t[75]!==Se?(Re=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:Se}),t[75]=Se,t[76]=Re):Re=t[76],t[77]!==Pe||t[78]!==Re?(B=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[Pe,Re]}),t[77]=Pe,t[78]=Re,t[79]=B):B=t[79],H="min-h-0 flex-1 overflow-y-auto px-6 py-3",W="mx-auto w-full max-w-3xl space-y-0.5",E=Q.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:e(x?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):Q.map(ye=>{const pe=ct(_s(ye))??"",me=pe?Fn(pe,l)||pe:null;return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>he(ye),role:"button",tabIndex:0,onKeyDown:je=>{(je.key==="Enter"||je.key===" ")&&(je.preventDefault(),he(ye))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ye.title||e("sessions.sidebar.session.untitled")}),x&&me?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:pe,children:me}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:_d(ye.time?.archived??ye.time?.updated??ye.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:je=>{je.stopPropagation(),le(ye)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.restoreSessionAria",{title:ye.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(M,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:je=>{je.stopPropagation(),hn.requestDelete({sessions:[ye],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteSessionAria",{title:ye.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(M,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},ye.id)})}t[17]=u.length,t[18]=S,t[19]=C,t[20]=l,t[21]=x,t[22]=n,t[23]=d,t[24]=f,t[25]=i,t[26]=r,t[27]=e,t[28]=o,t[29]=p,t[30]=k,t[31]=A,t[32]=D,t[33]=P,t[34]=F,t[35]=W,t[36]=E,t[37]=H,t[38]=z,t[39]=B}else k=t[30],A=t[31],D=t[32],P=t[33],F=t[34],W=t[35],E=t[36],H=t[37],z=t[38],B=t[39];if(F!==Symbol.for("react.early_return_sentinel"))return F;let T;t[80]!==k||t[81]!==e?(T=k>0?s.jsx("button",{type:"button",onClick:()=>w(r4),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[80]=k,t[81]=e,t[82]=T):T=t[82];let j;t[83]!==T||t[84]!==W||t[85]!==E?(j=s.jsxs("div",{className:W,children:[E,T]}),t[83]=T,t[84]=W,t[85]=E,t[86]=j):j=t[86];let I;t[87]!==j||t[88]!==H?(I=s.jsx("div",{className:H,children:j}),t[87]=j,t[88]=H,t[89]=I):I=t[89];let _;t[90]!==I||t[91]!==z||t[92]!==B?(_=s.jsxs("div",{className:z,children:[B,I]}),t[90]=I,t[91]=z,t[92]=B,t[93]=_):_=t[93];let K;t[94]!==A||t[95]!==D||t[96]!==_?(K=s.jsxs("div",{className:A,children:[D,_]}),t[94]=A,t[95]=D,t[96]=_,t[97]=K):K=t[97];let G;return t[98]!==P||t[99]!==K?(G=s.jsx("div",{className:P,children:K}),t[98]=P,t[99]=K,t[100]=G):G=t[100],G}function r4(t){return t+Ao}function o4(t){return[t.title]}function i4(t,e){return e.sessions.length-t.sessions.length}function a4(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function l4(t){return t.homeDirectory}function c4(t){return t.unarchiveSession}function d4(t){return t.setCurrentSession}function u4(t){return t.setArchivePageOpen}function m4(t){return t.isArchivePageOpen}function f4(){const t=Xe.c(18),{t:e}=pt(),n=De(g4),r=De(p4),i=Vt(h4);let o;t[0]!==n?(o=p=>p.projects.find(w=>w.id===n)??null,t[0]=n,t[1]=o):o=t[1];const l=Vt(o);if(!n||!l)return null;let a;t[2]!==l.id||t[3]!==i||t[4]!==r?(a=()=>{i(l.id),r(!0)},t[2]=l.id,t[3]=i,t[4]=r,t[5]=a):a=t[5];let u;t[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(M,{name:"node-tree",className:"mr-1 h-3.5 w-3.5"}),t[6]=u):u=t[6];let d;t[7]!==e?(d=e("sessions.sidebar.project.actions.newWorktree"),t[7]=e,t[8]=d):d=t[8];let h;t[9]!==a||t[10]!==d?(h=s.jsx("div",{className:"flex items-center",children:s.jsxs(at,{size:"sm",onClick:a,children:[u,d]})}),t[9]=a,t[10]=d,t[11]=h):h=t[11];let f;t[12]!==l.id||t[13]!==l.path?(f=s.jsx(Xp,{projectRef:{id:l.id,path:l.path},sections:"list-only"}),t[12]=l.id,t[13]=l.path,t[14]=f):f=t[14];let g;return t[15]!==h||t[16]!==f?(g=s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-4",children:[h,f]})})}),t[15]=h,t[16]=f,t[17]=g):g=t[17],g}function h4(t){return t.setActiveProjectIdOnly}function p4(t){return t.setNewWorktreeDialogOpen}function g4(t){return t.worktreesPageProjectId}const ca=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),x4=(t,e)=>{const n=ca(t),r=ca(e);return`${n}-${r}`.substring(0,60)},$c=(t,e)=>`${t}/${e}`,b4=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Wc=(t,e)=>{const n=b4(e),r=t.directory,i=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Kh(t.id,n),Qe.getState().markSessionAsAiWorkerCreated(t.id),As.getState().upsertSession(i);try{To().ensureChild(n,{bootstrap:!1}).setState(l=>{const a=l.session.findIndex(d=>d.id===t.id);if(a>=0&&l.session[a]===i)return l;const u=a>=0?l.session.map((d,h)=>h===a?i:d):[...l.session,i].sort((d,h)=>d.id.localeCompare(h.id));return{session:u,sessionTotal:Math.max(l.sessionTotal,u.length),limit:Math.max(l.limit,u.length)}})}catch{}return i},y4=()=>{const t=Vt.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Zt.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},yi=Zn()(cu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:i,files:o,setupCommands:l}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let a=0;a<r.length;a++){if(!r[a].prompt.trim())return t({error:`Group ${a+1}: prompt is required`}),null;if(r[a].models.length<1)return t({error:`Group ${a+1}: select at least 1 model`}),null}t({isLoading:!0,error:null});try{const a=y4();if(!a)return t({error:"Select a project",isLoading:!1}),null;const u=a.path,h=await Qo(u)&&e.isolateRuns!==!1,f=ca(n),g=h?await Jo(u):void 0,p=h?await _h(u):null,w=[],v=l?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const N=r[S],C=N.prompt,k=new Map;for(const D of N.models){const P=`${D.providerID}:${D.modelID}`;k.set(P,(k.get(P)||0)+1)}const A=new Map;for(const D of N.models){const P=`${D.providerID}:${D.modelID}`,F=k.get(P)||1,W=(A.get(P)||0)+1;A.set(P,W);const E=x4(D.providerID,D.modelID),H=r.length>1?`g${S+1}`:void 0,z=F>1?$c(f,`${E}/${W}`):$c(f,E),B=H?`${H}/${z}`:z,T=dj({groupSlug:f,runGroup:H,providerID:D.providerID,modelID:D.modelID,index:F>1?W:void 0});try{if(!h){const K=await Qs.withDirectory(u,()=>Qs.createSession({title:T}));Wc(K,u),w.push({sessionId:K.id,worktreePath:u,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C});continue}const j=await Lh(a,{preferredName:B,mode:"new",branchName:B,worktreeName:B,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:p}),I={...j,createdFromBranch:g,kind:"standard"};await $h(a)&&await Wh(j.path);const _=await Qs.withDirectory(j.path,()=>Qs.createSession({title:T}));Wc(_,j.path),Qe.getState().setWorktreeMetadata(_.id,I),w.push({sessionId:_.id,worktreePath:j.path,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C})}catch(j){console.warn("[MultiRun] Failed to create session:",j)}}}const x=l?.filter(S=>S.trim().length>0)??[];x.length>0&&zh(a,x).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const m=w.map(S=>S.sessionId),b=w[0]?.sessionId??null;if(m.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const y=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=Vh.getState().expandText;await Promise.allSettled(w.map(async N=>{try{const C=await S(N.prompt).catch(()=>N.prompt);await Uh({sessionId:N.sessionId,directory:N.worktreePath,content:C,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:i,files:y})}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:m,firstSessionId:b}}catch(a){return t({error:a instanceof Error?a.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function gm(t){const e=Xe.c(30),{git:n}=An(),r=Sd(t),i=vd(t),o=Hh(t),l=Gh(t),a=On(k4),u=On(j4);let d,h;e[0]!==t||e[1]!==u||e[2]!==n||e[3]!==i||e[4]!==o?(d=()=>{!t||!n||i!==null||o||u(t,n,{silent:!0})},h=[t,n,u,i,o],e[0]=t,e[1]=u,e[2]=n,e[3]=i,e[4]=o,e[5]=d,e[6]=h):(d=e[5],h=e[6]),c.useEffect(d,h);let f;e[7]!==r?.all||e[8]!==t||e[9]!==a||e[10]!==n||e[11]!==i?(f=()=>{!t||!n||i===!0&&(r?.all||a(t,n))},e[7]=r?.all,e[8]=t,e[9]=a,e[10]=n,e[11]=i,e[12]=f):f=e[12];const g=r?.all;let p;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==i||e[17]!==g?(p=[t,n,i,g,a],e[13]=t,e[14]=a,e[15]=n,e[16]=i,e[17]=g,e[18]=p):p=e[18],c.useEffect(f,p);const w=o||i===!0&&l;let v;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],v=k;break e}let C;e[20]!==r.all?(C=r.all.filter(v4).sort(),e[20]=r.all,e[21]=C):C=e[21],v=C}const x=v;let m;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],m=k;break e}let C;e[23]!==r.all?(C=r.all.filter(S4).map(w4).sort(),e[23]=r.all,e[24]=C):C=e[24],m=C}const b=m;let y;e:{if(!t){y=null;break e}if(i!==null){y=i;break e}if(w){y=null;break e}y=r?.all?!0:null}const S=y;let N;return e[25]!==S||e[26]!==w||e[27]!==x||e[28]!==b?(N={localBranches:x,remoteBranches:b,isLoading:w,isGitRepository:S},e[25]=S,e[26]=w,e[27]=x,e[28]=b,e[29]=N):N=e[29],N}function w4(t){return t.replace(/^remotes\//,"")}function S4(t){return t.startsWith("remotes/")}function v4(t){return!t.startsWith("remotes/")}function j4(t){return t.fetchStatus}function k4(t){return t.fetchBranches}const C4=({directory:t,value:e,onChange:n,className:r,disabled:i,id:o})=>{const{t:l}=pt(),{localBranches:a,remoteBranches:u,isLoading:d,isGitRepository:h}=gm(t),f=c.useMemo(()=>[...a,...u.map(p=>`remotes/${p}`)],[a,u]);c.useEffect(()=>{if(i||d||f.length===0||e&&f.includes(e))return;const p=e;let w=!1;return(async()=>{try{const x=t?await Jo(t).catch(()=>null):null;if(w)return;const m=localStorage.getItem(wl),{sourceBranch:b,shouldClearSavedSourceBranch:y}=Jp({branches:f,savedSourceBranch:m,rootBranch:x});if(y&&localStorage.removeItem(wl),w||p&&f.includes(p))return;b&&n(b)}catch{}})(),()=>{w=!0}},[f,t,i,d,n,e]);const g=i||!h||d;return s.jsxs("div",{children:[s.jsxs(Ms,{value:e,onValueChange:n,disabled:g,children:[s.jsx(Os,{id:o,size:"lg",className:Te("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Cs,{placeholder:l(d?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Fs,{className:"max-h-[280px] max-w-[320px]",children:d?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):a.length===0&&u.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[a.length>0&&s.jsxs(Ii,{children:[s.jsx(dl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),a.map(p=>s.jsx(es,{value:p,className:"whitespace-normal break-all",children:p},p))]}),a.length>0&&u.length>0&&s.jsx(qh,{}),u.length>0&&s.jsxs(Ii,{children:[s.jsx(dl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),u.map(p=>s.jsx(es,{value:`remotes/${p}`,className:"whitespace-normal break-all",children:p},`remotes/${p}`))]})]})})]}),h===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},N4=10*1024*1024,Do=t=>{const e=Xe.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(M,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(gt,{children:[r,s.jsx(bt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},Hn=t=>{const e=Xe.c(9),{htmlFor:n,required:r,children:i,info:o}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let a;e[2]!==i||e[3]!==n||e[4]!==l?(a=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=a):a=e[5];const u=o&&o;let d;return e[6]!==a||e[7]!==u?(d=s.jsxs("div",{className:"flex items-center gap-1.5",children:[a,u]}),e[6]=a,e[7]=u,e[8]=d):d=e[8],d},A4=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=pt(),[o,l]=c.useState(""),[a,u]=c.useState(()=>[{id:Or(),prompt:"",models:[]}]),[d,h]=c.useState(""),[f,g]=c.useState([]),[p,w]=c.useState(!1),[v,x]=c.useState([]),[m,b]=c.useState(!1),[y,S]=c.useState(!1),[N,C]=c.useState(!0),k=c.useRef(null),A=Zt(R=>R.currentDirectory??null),D=Zt(R=>R.homeDirectory??null),P=c.useMemo(()=>{if(typeof window>"u")return null;const R=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof R=="string"&&R.trim().length>0?R.trim():null},[]),F=Vt(R=>R.activeProjectId),W=Vt(R=>R.setActiveProjectIdOnly),E=Vt(R=>R.projects),[H,z]=c.useState(()=>F??null);c.useEffect(()=>{if(F){z(F);return}!H&&E.length>0&&z(E[0].id)},[F,E,H]);const B=c.useMemo(()=>H?E.find(R=>R.id===H)??null:null,[E,H]),T=B?.path??A,j=c.useCallback(R=>{z(R),R!==F&&W(R)},[F,W]),{currentTheme:I}=Jn(),_=c.useCallback(R=>{const $=R.label?.trim()||Fn(R.path,D),de=R.icon?ja[R.icon]:null,ie=R.color?ka[R.color]:void 0,Ae=de?s.jsx(M,{name:de,className:"h-3.5 w-3.5 shrink-0",style:ie?{color:ie}:void 0}):s.jsx(M,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:ie?{color:ie}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[R.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:R.iconBackground?{backgroundColor:R.iconBackground}:void 0,children:s.jsx(Ca,{project:{id:R.id,iconImage:R.iconImage??null},options:{themeVariant:I.metadata.variant,iconColor:I.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Ae})}):Ae,s.jsx("span",{className:"truncate",children:$})]})},[D,I.metadata.variant,I.colors.surface.foreground]),K=c.useMemo(()=>{if(B?.path)return{id:B.id,path:B.path};const R=A??P;return R?{id:`path:${R}`,path:R}:null},[B,A,P]),[G]=c.useState(()=>typeof window<"u"?pn():!1),Q=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ge=gd(),se=c.useMemo(()=>{if(typeof window>"u")return null;const R=window.__AIWORKER_MACOS_MAJOR__;if(typeof R=="number"&&Number.isFinite(R)&&R>0)return R;if(typeof navigator>"u")return null;const $=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!$)return null;const de=Number.parseInt($[1],10),ie=Number.parseInt($[2],10);return Number.isNaN(de)?null:de===10?ie:de},[]),Y=c.useMemo(()=>G&&Q||ge?"pl-[5.5rem]":"pl-3",[G,Q,ge]),te=c.useMemo(()=>!G||!Q||se===null?"":se>=26?"h-12":se<=15?"h-14":"",[G,Q,se]),he=c.useCallback(async R=>{R.target.closest("button, a, input, select, textarea")||R.button===0&&G&&await Qh()},[G]);c.useEffect(()=>{if(!n)return;const R=$=>{$.key==="Escape"&&($.preventDefault(),$.stopPropagation(),n())};return window.addEventListener("keydown",R,!0),()=>window.removeEventListener("keydown",R,!0)},[n]);const[L,le]=c.useState(""),{isLoading:Z,isGitRepository:ue}=gm(T),V=c.useRef(!1),ee=ue===!0,be=ee&&N;c.useEffect(()=>{if(ue===!1){V.current=!0,C(!1);return}ue===!0&&V.current&&(V.current=!1,C(!0))},[ue]);const xe=yi(R=>R.createMultiRun),Ne=yi(R=>R.error),Pe=yi(R=>R.clearError);c.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&u(R=>{const $=[...R];return $.length>0&&!$[0].prompt.trim()&&($[0]={...$[0],prompt:t}),$})},[t]),c.useEffect(()=>{if(!K)return;let R=!1;return S(!0),(async()=>{try{const $=await Yh(K);R||x($)}catch{}finally{R||S(!1)}})(),()=>{R=!0}},[K]);const Se=c.useCallback((R,$)=>{u(de=>de.map(ie=>ie.id===R?{...ie,...$}:ie))},[]),Re=c.useCallback(R=>{u($=>$.filter(de=>de.id!==R))},[]),ye=c.useCallback(()=>{u(R=>[...R,{id:Or(),prompt:"",models:[]}])},[]),pe=async R=>{const $=R.target.files;if(!$)return;let de=0;for(let ie=0;ie<$.length;ie++){const Ae=$[ie];if(Ae.size>N4){Fe.error(i("multirun.launcher.toast.fileTooLarge",{fileName:Ae.name}));continue}try{const Be=await new Promise((Ce,q)=>{const Ee=new FileReader;Ee.onload=()=>Ce(Ee.result),Ee.onerror=q,Ee.readAsDataURL(Ae)});g(Ce=>[...Ce,{id:Or(),filename:Ae.name,mimeType:Ae.type||"application/octet-stream",size:Ae.size,dataUrl:Be}]),de++}catch(Be){console.error("File attach failed",Be),Fe.error(i("multirun.launcher.toast.attachFailed",{fileName:Ae.name}))}}de>0&&Fe.success(de===1?i("multirun.launcher.toast.attachedSingle",{count:de}):i("multirun.launcher.toast.attachedPlural",{count:de})),k.current&&(k.current.value="")},me=R=>{g($=>$.filter(de=>de.id!==R))},je=c.useMemo(()=>a.reduce((R,$)=>R+$.models.length,0),[a]),ne=async R=>{R.preventDefault();const $=a.filter(de=>de.prompt.trim()&&de.models.length>=1);if($.length!==0&&!(je<1)){w(!0),Pe();try{H&&H!==F&&W(H);const de=f.map(q=>({mime:q.mimeType,filename:q.filename,url:q.dataUrl})),ie=v.filter(q=>q.trim().length>0),Ae=$.map(q=>({prompt:q.prompt.trim(),models:q.models.map(Ee=>({providerID:Ee.providerID,modelID:Ee.modelID,displayName:Ee.displayName,variant:Ee.variant}))})),Be={name:o.trim(),groups:Ae,agent:d||void 0,worktreeBaseBranch:be?L:void 0,isolateRuns:be,files:de.length>0?de:void 0,setupCommands:ie.length>0?ie:void 0},Ce=await xe(Be);Ce&&(Ce.firstSessionId&&Qe.getState().setCurrentSession(Ce.firstSessionId),e?.())}finally{w(!1)}}},fe=!!(o.trim()&&a.some(R=>R.prompt.trim()&&R.models.length>=1)&&je>=1&&T&&!Z&&(ue===!1||!be||L)),ce=v.filter(R=>R.trim()).length;return s.jsxs("form",{onSubmit:ne,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:he,className:Te("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",Y,te),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(M,{name:"close",className:"h-5 w-5"})})}),s.jsx(bt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(ya,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),E.length>0?s.jsxs(Ms,{value:H??void 0,onValueChange:j,children:[s.jsx(Os,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:B?s.jsx(Cs,{children:_(B)}):s.jsx(Cs,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(Fs,{fitContent:!0,children:E.map(R=>s.jsx(es,{value:R.id,className:"max-w-[24rem]",children:_(R)},R.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"group-name",required:!0,info:s.jsx(Do,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(jn,{id:"group-name",value:o,onChange:R=>l(R.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Do,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(C4,{directory:T,value:L,onChange:le,disabled:!be,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(lr,{checked:N,onChange:C,disabled:!ee,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hn,{htmlFor:"multirun-agent",info:s.jsx(Do,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(lm,{value:d,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(Ei,{open:m,onOpenChange:b,children:[s.jsxs(Yd,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(M,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),ce>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:ce}),s.jsx(M,{name:"arrow-down-s",className:Te("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",m&&"rotate-180")})]}),s.jsx(Mi,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:y?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[v.map((R,$)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(jn,{value:R,onChange:de=>{const ie=[...v];ie[$]=de.target.value,x(ie)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>x(v.filter((de,ie)=>ie!==$)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(M,{name:"close",className:"h-3.5 w-3.5"})})]},`${R}-${$}`)),s.jsxs("button",{type:"button",onClick:()=>x([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(M,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Hn,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:pe,accept:"*/*"}),s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(M,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(bt,{children:i("multirun.launcher.attachments.tooltip")})]}),f.map(R=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[R.mimeType.startsWith("image/")?s.jsx(M,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(M,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:R.filename,children:R.filename}),s.jsx("button",{type:"button",onClick:()=>me(R.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(M,{name:"close",className:"h-3 w-3"})})]},R.id))]})]}),a.map((R,$)=>s.jsx(D4,{group:R,groupIndex:$,canRemove:a.length>1,onUpdate:Se,onRemove:Re},R.id)),s.jsxs("button",{type:"button",onClick:ye,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(M,{name:"add",className:"h-3.5 w-3.5"}),i("multirun.launcher.groups.addGroup")]}),Ne&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Ne})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!be&&ue!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(M,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}):null,s.jsx(at,{type:"submit",size:"sm",disabled:!fe||p,children:p?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithRunCount",{count:je})})})]})})]})},D4=t=>{const e=Xe.c(99),{group:n,groupIndex:r,canRemove:i,onUpdate:o,onRemove:l}=t,{t:a}=pt(),[u,d]=c.useState(!1),[h,f]=c.useState(""),[g,p]=c.useState(!1),[w,v]=c.useState(""),[x,m]=c.useState(!1),[b,y]=c.useState(""),S=c.useRef(null),N=c.useRef(null),C=c.useRef(null),k=c.useRef(null);let A;e[0]!==n.id||e[1]!==n.models||e[2]!==o?(A=ie=>{o(n.id,{models:[...n.models,ie]})},e[0]=n.id,e[1]=n.models,e[2]=o,e[3]=A):A=e[3];const D=A;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==o?(P=ie=>{o(n.id,{models:n.models.filter((Ae,Be)=>Be!==ie)})},e[4]=n.id,e[5]=n.models,e[6]=o,e[7]=P):P=e[7];const F=P;let W;e[8]!==n.id||e[9]!==n.models||e[10]!==o?(W=(ie,Ae)=>{o(n.id,{models:n.models.map((Be,Ce)=>Ce===ie?Ae:Be)})},e[8]=n.id,e[9]=n.models,e[10]=o,e[11]=W):W=e[11];const E=W;let H;e[12]===Symbol.for("react.memo_cache_sentinel")?(H=(ie,Ae)=>{if(ie.startsWith("/")){const Ee=ie.indexOf(" "),Me=ie.indexOf(`
|
|
925
|
-
`),O=Math.min(Ee===-1?ie.length:Ee,Me===-1?ie.length:Me);if(Ae<=O&&Ee===-1){v(ie.substring(1,O)),p(!0),d(!1),m(!1);return}}p(!1);const Be=ie.substring(0,Ae),Ce=Be.lastIndexOf("#");if(Ce!==-1){const Ee=Ce>0?Be[Ce-1]:null,Me=Be.substring(Ce+1);if((!Ee||/\s/.test(Ee))&&!Me.includes(" ")&&!Me.includes(`
|
|
926
|
-
`)){y(Me),m(!0),d(!1);return}}m(!1);const q=Be.lastIndexOf("@");if(q!==-1){const Ee=q>0?Be[q-1]:null,Me=Be.substring(q+1);(!Ee||/\s/.test(Ee))&&!Me.includes(" ")&&!Me.includes(`
|
|
927
|
-
`)?(f(Me),d(!0)):d(!1);return}d(!1)},e[12]=H):H=e[12];const z=H;let B;e[13]!==n.id||e[14]!==o?(B=ie=>{o(n.id,{prompt:ie})},e[13]=n.id,e[14]=o,e[15]=B):B=e[15];const T=B;let j;e[16]!==n.prompt||e[17]!==T?(j=ie=>{const Ae=n.prompt,Ce=S.current?.selectionStart??Ae.length,Ee=Ae.substring(0,Ce).lastIndexOf("@"),Me=ie.relativePath&&ie.relativePath.trim().length>0?ie.relativePath.trim():ie.path||ie.name,O=Ee!==-1?Ee:Ce,oe=`${Ae.substring(0,O)}@${Me} ${Ae.substring(Ce)}`,re=O+Me.length+2;T(oe),d(!1),f(""),requestAnimationFrame(()=>{const we=S.current;we&&(we.selectionStart=re,we.selectionEnd=re,we.focus()),z(oe,re)})},e[16]=n.prompt,e[17]=T,e[18]=j):j=e[18];const I=j;let _;e[19]!==n.prompt||e[20]!==T?(_=ie=>{const Ae=n.prompt,Ce=S.current?.selectionStart??Ae.length,Ee=Ae.substring(0,Ce).lastIndexOf("@"),Me=Ee!==-1?Ee:Ce,O=`${Ae.substring(0,Me)}@${ie} ${Ae.substring(Ce)}`,oe=Me+ie.length+2;T(O),d(!1),f(""),requestAnimationFrame(()=>{const re=S.current;re&&(re.selectionStart=oe,re.selectionEnd=oe,re.focus()),z(O,oe)})},e[19]=n.prompt,e[20]=T,e[21]=_):_=e[21];const K=_;let G;e[22]!==T?(G=ie=>{const Ae=`/${ie.name} `;T(Ae),p(!1),v(""),m(!1),requestAnimationFrame(()=>{const Be=S.current;Be&&(Be.focus(),Be.selectionStart=Be.value.length,Be.selectionEnd=Be.value.length),z(Ae,Ae.length)})},e[22]=T,e[23]=G):G=e[23];const Q=G;let ge;e[24]!==n.prompt||e[25]!==T?(ge=(ie,Ae)=>{const Be=n.prompt,q=S.current?.selectionStart??Be.length,Me=Be.substring(0,q).lastIndexOf("#"),O=Me!==-1?Me:q,oe=`${Be.substring(0,O)}#${Ae} ${Be.substring(q)}`,re=O+Ae.length+2;T(oe),m(!1),y(""),requestAnimationFrame(()=>{const we=S.current;we&&(we.selectionStart=re,we.selectionEnd=re,we.focus()),z(oe,re)})},e[24]=n.prompt,e[25]=T,e[26]=ge):ge=e[26];const se=ge;let Y;e[27]!==g||e[28]!==u||e[29]!==x?(Y=ie=>{if(g&&C.current&&(ie.key==="Enter"||ie.key==="ArrowUp"||ie.key==="ArrowDown"||ie.key==="Escape"||ie.key==="Tab")){ie.preventDefault(),C.current.handleKeyDown(ie.key);return}u&&N.current&&(ie.key==="Enter"||ie.key==="ArrowUp"||ie.key==="ArrowDown"||ie.key==="Escape"||ie.key==="Tab")&&(ie.preventDefault(),N.current.handleKeyDown(ie.key)),x&&k.current&&(ie.key==="Enter"||ie.key==="ArrowUp"||ie.key==="ArrowDown"||ie.key==="Escape"||ie.key==="Tab")&&(ie.preventDefault(),k.current.handleKeyDown(ie.key))},e[27]=g,e[28]=u,e[29]=x,e[30]=Y):Y=e[30];const te=Y,he=r+1;let L;e[31]!==a||e[32]!==he?(L=a("multirun.launcher.groups.groupLabel",{index:he}),e[31]=a,e[32]=he,e[33]=L):L=e[33];let le;e[34]!==L?(le=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:L}),e[34]=L,e[35]=le):le=e[35];let Z;e[36]!==i||e[37]!==n.id||e[38]!==l||e[39]!==a?(Z=i&&s.jsx("button",{type:"button",onClick:()=>l(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":a("multirun.launcher.groups.removeGroup"),children:s.jsx(M,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=i,e[37]=n.id,e[38]=l,e[39]=a,e[40]=Z):Z=e[40];let ue;e[41]!==le||e[42]!==Z?(ue=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[le,Z]}),e[41]=le,e[42]=Z,e[43]=ue):ue=e[43];let V;e[44]!==a?(V=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=V):V=e[45];let ee;e[46]!==V?(ee=s.jsx(Hn,{required:!0,children:V}),e[46]=V,e[47]=ee):ee=e[47];const be=n.prompt;let xe;e[48]!==T?(xe=ie=>{const Ae=ie.target.value;T(Ae);const Be=ie.target.selectionStart??Ae.length;z(Ae,Be)},e[48]=T,e[49]=xe):xe=e[49];let Ne;e[50]!==a?(Ne=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=Ne):Ne=e[51];let Pe;e[52]!==n.prompt||e[53]!==te||e[54]!==xe||e[55]!==Ne?(Pe=s.jsx(or,{ref:S,value:be,onChange:xe,onKeyDown:te,placeholder:Ne,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=te,e[54]=xe,e[55]=Ne,e[56]=Pe):Pe=e[56];let Se;e[57]!==w||e[58]!==Q||e[59]!==g?(Se=g?s.jsx(Wd,{ref:C,searchQuery:w,onCommandSelect:Q,onClose:()=>p(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=w,e[58]=Q,e[59]=g,e[60]=Se):Se=e[60];let Re;e[61]!==K||e[62]!==I||e[63]!==h||e[64]!==u?(Re=u?s.jsx(zd,{ref:N,searchQuery:h,onFileSelect:I,onAgentSelect:K,onClose:()=>d(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=K,e[62]=I,e[63]=h,e[64]=u,e[65]=Re):Re=e[65];let ye;e[66]!==se||e[67]!==x||e[68]!==b?(ye=x?s.jsx(Vd,{ref:k,searchQuery:b,onSnippetSelect:se,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=se,e[67]=x,e[68]=b,e[69]=ye):ye=e[69];let pe;e[70]!==Pe||e[71]!==Se||e[72]!==Re||e[73]!==ye?(pe=s.jsxs("div",{className:"relative",children:[Pe,Se,Re,ye]}),e[70]=Pe,e[71]=Se,e[72]=Re,e[73]=ye,e[74]=pe):pe=e[74];let me;e[75]!==ee||e[76]!==pe?(me=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ee,pe]}),e[75]=ee,e[76]=pe,e[77]=me):me=e[77];let je;e[78]!==a?(je=a("multirun.launcher.models.info"),e[78]=a,e[79]=je):je=e[79];let ne;e[80]!==je?(ne=s.jsx(Do,{children:je}),e[80]=je,e[81]=ne):ne=e[81];let fe;e[82]!==a?(fe=a("multirun.launcher.models.label"),e[82]=a,e[83]=fe):fe=e[83];let ce;e[84]!==ne||e[85]!==fe?(ce=s.jsx(Hn,{required:!0,info:ne,children:fe}),e[84]=ne,e[85]=fe,e[86]=ce):ce=e[86];let R;e[87]!==n.models||e[88]!==D||e[89]!==F||e[90]!==E?(R=s.jsx(cm,{selectedModels:n.models,onAdd:D,onRemove:F,onUpdate:E,minModels:1}),e[87]=n.models,e[88]=D,e[89]=F,e[90]=E,e[91]=R):R=e[91];let $;e[92]!==ce||e[93]!==R?($=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ce,R]}),e[92]=ce,e[93]=R,e[94]=$):$=e[94];let de;return e[95]!==ue||e[96]!==me||e[97]!==$?(de=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[ue,me,$]}),e[95]=ue,e[96]=me,e[97]=$,e[98]=de):de=e[98],de},P4=t=>{const e=new Map;for(const n of t){const r=_s(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},I4=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,i)=>{e.has(i)||n.push(r)}),n},T4=t=>{const e=Xe.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:i}=t,o=n===void 0?!0:n,l=c.useRef(null);let a,u;e[0]!==o||e[1]!==r||e[2]!==i?(a=()=>{if(!o||!r)return;const d=Ss(),h=P4(i),f=l.current?.runtimeKey===d?l.current.identities:null;for(const g of I4(f,h))Xh({runtimeKey:d,...g});l.current={runtimeKey:d,identities:h}},u=[o,r,i],e[0]=o,e[1]=r,e[2]=i,e[3]=a,e[4]=u):(a=e[3],u=e[4]),c.useEffect(a,u)},R4=new Map,E4=t=>{const e=Xe.c(26),{isVSCode:n}=t,r=Pa(),i=Vt(M4),o=Vt(O4),l=Zt(F4),a=Qe(B4);let u;e[0]!==n?(u=P=>n?R4:P.availableWorktreesByProject,e[0]=n,e[1]=u):u=e[1];const d=Qe(u),h=!n;let f;e[2]!==d||e[3]!==i||e[4]!==h?(f=fm(i,d,{includeWorktrees:h}),e[2]=d,e[3]=i,e[4]=h,e[5]=f):f=e[5];const g=f,p=As(_4),w=As(L4),v=As($4),x=`session-list-sync:${c.useId()}`;let m,b;e[6]!==o||e[7]!==x||e[8]!==r||e[9]!==l||e[10]!==a||e[11]!==g||e[12]!==i?(m=()=>(r.setBootstrapDemand(x,nm({knownDirectories:g,activeProjectDirectory:ct(i.find(P=>P.id===o)?.path??null),activeProjectId:o,collapsedProjects:new Set,collapsedGroups:new Set,currentDirectory:l,currentSessionDirectory:a})),()=>r.clearBootstrapDemand(x)),b=[o,x,r,l,a,g,i],e[6]=o,e[7]=x,e[8]=r,e[9]=l,e[10]=a,e[11]=g,e[12]=i,e[13]=m,e[14]=b):(m=e[13],b=e[14]),c.useEffect(m,b);const y=c.useRef(null);let S,N;e[15]!==n||e[16]!==g?(S=()=>{const P=new Set(g),F=y.current;y.current=P;const W=F?[...P].filter(E=>!F.has(E)):n?[...P]:[];W.length&&ga(W,Ro())},N=[n,g],e[15]=n,e[16]=g,e[17]=S,e[18]=N):(S=e[17],N=e[18]),c.useEffect(S,N);let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[19]=C):C=e[19],c.useEffect(W4,C);let k;e[20]!==w||e[21]!==p?(k=[...p,...w],e[20]=w,e[21]=p,e[22]=k):k=e[22];const A=k;let D;e[23]!==A||e[24]!==v?(D={enabled:!0,hasAuthoritativeGlobalSessions:v,sessions:A},e[23]=A,e[24]=v,e[25]=D):D=e[25],T4(D)};function M4(t){return t.projects}function O4(t){return t.activeProjectId}function F4(t){return t.currentDirectory}function B4(t){return t.currentSessionDirectory}function _4(t){return t.activeSessions}function L4(t){return t.archivedSessions}function $4(t){return t.status==="ready"}function W4(){let t=null,e=!1;const n=new Set,r=Yr(i=>{if(i.type==="scheduled-task-ran")e=!0;else if(i.type==="session-created")n.add(i.directory);else return;t&&clearTimeout(t),t=setTimeout(()=>{if(t=null,e){e=!1,n.clear(),Ia(Ro());return}const o=[...n];n.clear(),o.length&&ga(o,Ro())},500)});return()=>{t&&clearTimeout(t),r()}}const z4=Ln(()=>Bn(()=>import("./SettingsWindow-i45U1Cy1.js"),__vite__mapDeps([139,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,140,116,141,126,127,128,129,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100,142,143])).then(t=>({default:t.SettingsWindow}))),V4=()=>{const t=Xe.c(58);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={isVSCode:!1},t[0]=e):e=t[0],E4(e);const n=De(U4),r=De(K4),i=De(H4),o=De(G4),[l,a]=c.useState(!1);let u,d;t[1]!==i?(u=()=>{i&&a(!0)},d=[i],t[1]=i,t[2]=u,t[3]=d):(u=t[2],d=t[3]),c.useEffect(u,d);const h=De(q4),f=De(Q4),g=De(Y4),p=De(X4),w=De(J4),v=De(Z4),x=p||w||!!v||h;let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=[],t[4]=m):m=t[4],c.useEffect(t3,m);const{isMobile:b}=_n();Zp();const y=Px();let S,N;t[5]!==b||t[6]!==r?(S=()=>{De.getState().isMobile!==b&&r(b)},N=[b,r],t[5]=b,t[6]=r,t[7]=S,t[8]=N):(S=t[7],N=t[8]),c.useEffect(S,N);let C,k,A,D;t[9]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(yS,{}),k=s.jsx(pv,{}),A=s.jsx(yv,{}),D=s.jsx(Dk,{}),t[9]=C,t[10]=k,t[11]=A,t[12]=D):(C=t[9],k=t[10],A=t[11],D=t[12]);let P;t[13]!==y?(P=s.jsx(Pk,{value:y,onMoveSessionOnly:s3,onMoveAllChanges:n3,onCancel:_x}),t[13]=y,t[14]=P):P=t[14];let F;t[15]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(qx,{}),t[15]=F):F=t[15];let W;t[16]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(Gx,{}),t[16]=W):W=t[16];let E;t[17]!==n?(E=s.jsx(Ak,{isVisible:n}),t[17]=n,t[18]=E):E=t[18];let H;t[19]!==b||t[20]!==n||t[21]!==E?(H=s.jsx(Hx,{isOpen:n,isMobile:b,className:"border-border",topBar:W,children:E}),t[19]=b,t[20]=n,t[21]=E,t[22]=H):H=t[22];let z;t[23]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(Ux,{}),t[23]=z):z=t[23];const B=x&&"invisible";let T;t[24]!==B?(T=Te("absolute inset-0",B),t[24]=B,t[25]=T):T=t[25];const j=!i&&!x;let I;t[26]!==j?(I=s.jsx(Gs,{children:s.jsx(eu,{active:j})}),t[26]=j,t[27]=I):I=t[27];let _;t[28]!==T||t[29]!==I?(_=s.jsx("div",{className:T,children:I}),t[28]=T,t[29]=I,t[30]=_):_=t[30];let K;t[31]!==h||t[32]!==g||t[33]!==f?(K=h&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Gs,{children:s.jsx(A4,{isWindowed:!0,initialPrompt:g,onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),t[31]=h,t[32]=g,t[33]=f,t[34]=K):K=t[34];let G;t[35]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Gs,{children:s.jsx(s4,{})}),t[35]=G):G=t[35];let Q;t[36]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Gs,{children:s.jsx(n4,{})}),t[36]=Q):Q=t[36];let ge;t[37]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(Gs,{children:s.jsx(f4,{})}),t[37]=ge):ge=t[37];let se;t[38]!==_||t[39]!==K?(se=s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[_,K,G,Q,ge]}),t[38]=_,t[39]=K,t[40]=se):se=t[40];let Y;t[41]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(Vw,{}),t[41]=Y):Y=t[41];let te;t[42]!==se?(te=s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[se,Y]})})}),t[42]=se,t[43]=te):te=t[43];let he;t[44]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Gs,{children:s.jsx(Zw,{})})}),t[44]=he):he=t[44];let L;t[45]!==te?(L=s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[z,s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[te,he]})]}),t[45]=te,t[46]=L):L=t[46];let le;t[47]!==H||t[48]!==L?(le=s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[H,L]}),t[47]=H,t[48]=L,t[49]=le):le=t[49];let Z;t[50]!==i||t[51]!==o||t[52]!==l?(Z=l?s.jsx(c.Suspense,{fallback:null,children:s.jsx(z4,{open:i,onOpenChange:o})}):null,t[50]=i,t[51]=o,t[52]=l,t[53]=Z):Z=t[53];let ue;return t[54]!==P||t[55]!==le||t[56]!==Z?(ue=s.jsx(eg,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:"main-content-safe-area relative flex h-[100dvh] bg-background",children:[C,k,A,D,P,F,le,Z]})}),t[54]=P,t[55]=le,t[56]=Z,t[57]=ue):ue=t[57],ue};function U4(t){return t.isSidebarOpen}function K4(t){return t.setIsMobile}function H4(t){return t.isSettingsDialogOpen}function G4(t){return t.setSettingsDialogOpen}function q4(t){return t.isMultiRunLauncherOpen}function Q4(t){return t.setMultiRunLauncherOpen}function Y4(t){return t.multiRunLauncherPrefillPrompt}function X4(t){return t.isScheduledTasksDialogOpen}function J4(t){return t.isArchivePageOpen}function Z4(t){return t.worktreesPageProjectId}function e3(){return De.getState().closeMainSurfaces()}function t3(){const t=e3,e=Qe.subscribe((n,r)=>{const i=!!n.currentSessionId&&n.currentSessionId!==r.currentSessionId,o=!!n.newSessionDraft?.open&&n.newSessionDraft!==r.newSessionDraft;(i||o)&&t()});return()=>{e()}}function s3(){return Nu(!1)}function n3(){return Nu(!0)}const xm=12,r3=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],o3=t=>{const e=Xe.c(18),{isActive:n,burstKey:r,className:i,durationMs:o,bursts:l,onComplete:a}=t,u=r===void 0?0:r,d=o===void 0?900:o,h=l===void 0?r3:l,f=it.useRef(!1);let g,p;e[0]!==n||e[1]!==a?(g=()=>{!n&&f.current&&a?.(),n&&(f.current=!0)},p=[n,a],e[0]=n,e[1]=a,e[2]=g,e[3]=p):(g=e[2],p=e[3]),it.useEffect(g,p);let w;e[4]===Symbol.for("react.memo_cache_sentinel")?(w=Array.from({length:xm},i3),e[4]=w):w=e[4];const v=w;if(!n)return null;let x;e[5]!==i?(x=Te("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=x):x=e[6];let m;if(e[7]!==u||e[8]!==h||e[9]!==d){let y;e[11]!==u||e[12]!==d?(y=S=>{const N={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${d}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:v.map((C,k)=>{const A=C.x*S.radius,D=C.y*S.radius,P={"--translate-x":`${A}px`,"--translate-y":`${D}px`,"--particle-delay":`${C.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${S.id}-${k}-${u}`)})},`${S.id}-${u}`)},e[11]=u,e[12]=d,e[13]=y):y=e[13],m=h.map(y),e[7]=u,e[8]=h,e[9]=d,e[10]=m}else m=e[10];let b;return e[14]!==u||e[15]!==x||e[16]!==m?(b=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":u,children:m}),e[14]=u,e[15]=x,e[16]=m,e[17]=b):b=e[17],b};function i3(t,e){const n=Math.PI*2*e/xm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const a3=t=>{const e=Xe.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={isActive:!1,cycle:0},e[2]=o):o=e[2];const[l,a]=it.useState(o),u=it.useRef(null);let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{u.current&&(window.clearTimeout(u.current),u.current=null)},e[3]=d):d=e[3];const h=d;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{h(),a(l3)},e[4]=f):f=e[4];const g=f;let p;e[5]!==i?(p=()=>{h(),a(c3),u.current=window.setTimeout(()=>{a(d3),u.current=null},i)},e[5]=i,e[6]=p):p=e[6];const w=p;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>h(),x=[h],e[7]=v,e[8]=x):(v=e[7],x=e[8]),it.useEffect(v,x);let m;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==w?(m={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:w,dismissFireworks:g},e[9]=l.cycle,e[10]=l.isActive,e[11]=w,e[12]=m):m=e[12],m};function l3(t){return t.isActive?{...t,isActive:!1}:t}function c3(t){return{isActive:!0,cycle:t.cycle+1}}function d3(t){return t.isActive?{...t,isActive:!1}:t}const bm=c.createContext(void 0),u3=t=>{const e=Xe.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:o,dismissFireworks:l}=a3();let a;e[0]!==l||e[1]!==o?(a={triggerFireworks:o,dismissFireworks:l},e[0]=l,e[1]=o,e[2]=a):a=e[2];const u=a;let d;e[3]!==i||e[4]!==r?(d=s.jsx(o3,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let h;return e[6]!==n||e[7]!==d||e[8]!==u?(h=s.jsxs(bm.Provider,{value:u,children:[n,d]}),e[6]=n,e[7]=d,e[8]=u,e[9]=h):h=e[9],h},Q5=()=>{const t=c.useContext(bm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},da="aiworker_requests_in_flight",ym=1e3,m3=300*1e3,Vo=Math.ceil(m3/ym),f3=()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(da)==="1"}catch{return!1}},wm=()=>({enabled:!0,startedAt:Date.now(),inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],peakAgeMs:0,inFlightStarts:new Map,sampleCount:0,lastSampleAt:null,fetchWrapped:!1,originalFetch:null,sampleTimer:null});let h3=1;const p3=(t,e)=>{const n=window.__aiworkerRequestsInFlight__;!n||!n.enabled||(n.inFlight+=1,n.totalStarted+=1,n.inFlight>n.peak&&(n.peak=n.inFlight),n.inFlightStarts.set(t,e))},g3=t=>{const e=window.__aiworkerRequestsInFlight__;!e||!e.enabled||(e.inFlight=Math.max(0,e.inFlight-1),e.totalSettled+=1,e.inFlightStarts.delete(t))},Sm=t=>{if(t.inFlightStarts.size===0)return[];const e=Date.now(),n=[];for(const r of t.inFlightStarts.values())n.push(Math.max(0,e-r));return n.sort((r,i)=>r-i),n},pr=(t,e)=>{const n=t.length;if(n===0)return 0;if(n===1)return t[0];const r=e/100*(n-1),i=Math.floor(r),o=Math.ceil(r);return i===o?t[i]:t[i]+(t[o]-t[i])*(r-i)},x3=()=>{if(typeof window>"u")return;const t=window.__aiworkerRequestsInFlight__;if(!t||t.fetchWrapped)return;const e=window.fetch.bind(window);t.originalFetch=e,t.fetchWrapped=!0;const n=async(r,i)=>{const o=h3++;p3(o,Date.now());try{return await e(r,i)}finally{g3(o)}};window.fetch=n},zc=()=>{if(typeof window>"u")return;const t=window.__aiworkerRequestsInFlight__;!t||!t.fetchWrapped||!t.originalFetch||(window.fetch=t.originalFetch,t.fetchWrapped=!1,t.originalFetch=null)},Ar=t=>{t.length>Vo&&t.splice(0,t.length-Vo)},b3=()=>{const t=window.__aiworkerRequestsInFlight__;if(!t||!t.enabled)return;t.samples.push(t.inFlight);const e=Sm(t),n=e.length>0?e[e.length-1]:0;t.p50Samples.push(pr(e,50)),t.p90Samples.push(pr(e,90)),t.p99Samples.push(pr(e,99)),t.maxSamples.push(n),n>t.peakAgeMs&&(t.peakAgeMs=n),t.sampleCount+=1,Ar(t.samples),Ar(t.p50Samples),Ar(t.p90Samples),Ar(t.p99Samples),Ar(t.maxSamples),t.lastSampleAt=Date.now()},y3=()=>{if(typeof window>"u")return;const t=window.__aiworkerRequestsInFlight__;!t||t.sampleTimer!=null||(t.sampleTimer=window.setInterval(b3,ym))},Vc=()=>{if(typeof window>"u")return;const t=window.__aiworkerRequestsInFlight__;!t||t.sampleTimer==null||(window.clearInterval(t.sampleTimer),t.sampleTimer=null)},Uc=t=>{if(!(typeof window>"u"))try{if(t){Vc(),zc(),window.localStorage.setItem(da,"1"),window.__aiworkerRequestsInFlight__=wm(),x3(),y3();return}window.localStorage.removeItem(da),Vc(),zc(),delete window.__aiworkerRequestsInFlight__}catch{}},w3=()=>{if(typeof window>"u")return;const t=window.__aiworkerRequestsInFlight__;if(!t)return;const e=wm();t.startedAt=e.startedAt,t.inFlight=e.inFlight,t.peak=e.peak,t.totalStarted=e.totalStarted,t.totalSettled=e.totalSettled,t.samples=e.samples,t.p50Samples=e.p50Samples,t.p90Samples=e.p90Samples,t.p99Samples=e.p99Samples,t.maxSamples=e.maxSamples,t.peakAgeMs=e.peakAgeMs,t.inFlightStarts=e.inFlightStarts,t.sampleCount=e.sampleCount,t.lastSampleAt=e.lastSampleAt},ua=()=>{if(typeof window>"u")return Kc();const t=window.__aiworkerRequestsInFlight__;if(!f3()||!t)return Kc();const e=Sm(t);return{enabled:!0,startedAt:t.startedAt,durationMs:Math.max(0,Date.now()-t.startedAt),inFlight:t.inFlight,peak:t.peak,totalStarted:t.totalStarted,totalSettled:t.totalSettled,samples:t.samples.slice(),ageP50:pr(e,50),ageP90:pr(e,90),ageP99:pr(e,99),ageMax:e.length>0?e[e.length-1]:0,peakAgeMs:t.peakAgeMs,p50Samples:t.p50Samples.slice(),p90Samples:t.p90Samples.slice(),p99Samples:t.p99Samples.slice(),maxSamples:t.maxSamples.slice(),sampleCount:t.sampleCount,lastSampleAt:t.lastSampleAt,windowSeconds:Vo}},Kc=()=>({enabled:!1,startedAt:null,durationMs:0,inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],ageP50:0,ageP90:0,ageP99:0,ageMax:0,peakAgeMs:0,p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],sampleCount:0,lastSampleAt:null,windowSeconds:Vo});function S3(t){switch(t){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const vm=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},ma=t=>`${(t/1e3).toFixed(2)} s`,ws=t=>{const e=Xe.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let o;e[1]!==n?(o=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let a;return e[5]!==o||e[6]!==l?(a=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[o,l]}),e[5]=o,e[6]=l,e[7]=a):a=e[7],a},Hc=t=>{const e=Xe.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:o}=pt();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==o||e[6]!==n){const a=r.entries.slice(0,12);let u;e[8]!==r.entries?(u=r.entries.reduce(k3,0),e[8]=r.entries,e[9]=u):u=e[9];const d=u;let h;e[10]!==n?(h=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=h):h=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==o?(f=r.startedAt?vm(r.durationMs):o("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=o,e[15]=f):f=e[15];let g;e[16]!==f?(g=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=g):g=e[17];let p;e[18]!==h||e[19]!==g?(p=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h,g]}),e[18]=h,e[19]=g,e[20]=p):p=e[20];let w;e[21]!==o?(w=o("memoryDebugPanel.metric.metrics"),e[21]=o,e[22]=w):w=e[22];let v;e[23]!==r.entries.length||e[24]!==w?(v=s.jsx(ws,{label:w,value:r.entries.length}),e[23]=r.entries.length,e[24]=w,e[25]=v):v=e[25];let x;e[26]!==o?(x=o("memoryDebugPanel.metric.samples"),e[26]=o,e[27]=x):x=e[27];let m;e[28]!==x||e[29]!==d?(m=s.jsx(ws,{label:x,value:d}),e[28]=x,e[29]=d,e[30]=m):m=e[30];let b;e[31]!==o?(b=o("memoryDebugPanel.metric.lastUpdate"),e[31]=o,e[32]=b):b=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==o?(y=r.lastUpdatedAt?o("memoryDebugPanel.common.live"):o("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=o,e[35]=y):y=e[35];let S;e[36]!==b||e[37]!==y?(S=s.jsx(ws,{label:b,value:y}),e[36]=b,e[37]=y,e[38]=S):S=e[38];let N;e[39]!==m||e[40]!==S||e[41]!==v?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,m,S]}),e[39]=m,e[40]=S,e[41]=v,e[42]=N):N=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[p,N,a.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(kn,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:a.map(C=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:C.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:o("memoryDebugPanel.metric.countValue",{value:C.count})}),s.jsx("span",{children:o("memoryDebugPanel.metric.avgValue",{value:C.avg})}),s.jsx("span",{children:o("memoryDebugPanel.metric.maxValue",{value:C.max})}),s.jsx("span",{children:o("memoryDebugPanel.metric.totalValue",{value:C.total})})]})]},C.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=o,e[6]=n,e[7]=l}else l=e[7];return l},Gc=t=>{const e=Xe.c(24),{series:n,peak:r,windowSeconds:i,ariaLabel:o,maxLabel:l}=t,a=i,u=n.reduce(C3,0),d=r>0?52/r:0;let h;e[0]!==u||e[1]!==a?(h=S=>a-u+S,e[0]=u,e[1]=a,e[2]=h):h=e[2];const f=h;let g;e[3]!==d?(g=S=>56-S*d,e[3]=d,e[4]=g):g=e[4];const p=g;let w;e[5]!==l?(w=s.jsx("span",{className:"pointer-events-none absolute left-0 top-0 typography-meta text-[var(--surface-muted-foreground)]",children:l}),e[5]=l,e[6]=w):w=e[6];const v=`0 0 ${a} 56`;let x;e[7]!==a?(x=s.jsx("line",{x1:0,y1:56,x2:a,y2:56,stroke:"var(--interactive-border)",strokeWidth:1,vectorEffect:"non-scaling-stroke"}),e[7]=a,e[8]=x):x=e[8];let m;if(e[9]!==n||e[10]!==f||e[11]!==p){let S;e[13]!==f||e[14]!==p?(S=(N,C)=>{const k=N.samples.length;if(k===0)return null;const A=N.samples.map((P,F)=>`${f(F)},${p(P).toFixed(2)}`),D=`M ${A.join(" L ")}`;return s.jsxs(c.Fragment,{children:[N.filled?s.jsx("path",{d:`M ${f(0)},56 L ${A.join(" L ")} L ${f(k-1)},56 Z`,fill:`color-mix(in srgb, ${N.color} 18%, transparent)`,stroke:"none"}):null,s.jsx("path",{d:D,fill:"none",stroke:N.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},C)},e[13]=f,e[14]=p,e[15]=S):S=e[15],m=n.map(S),e[9]=n,e[10]=f,e[11]=p,e[12]=m}else m=e[12];let b;e[16]!==o||e[17]!==v||e[18]!==x||e[19]!==m?(b=s.jsxs("svg",{viewBox:v,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":o,children:[x,m]}),e[16]=o,e[17]=v,e[18]=x,e[19]=m,e[20]=b):b=e[20];let y;return e[21]!==w||e[22]!==b?(y=s.jsxs("div",{className:"relative w-full",children:[w,b]}),e[21]=w,e[22]=b,e[23]=y):y=e[23],y},v3=t=>{const e=Xe.c(100),{onClose:n}=t,{t:r}=pt(),[i,o]=c.useState("memory"),[l,a]=c.useState("idle"),u=Qe(N3),d=Bd(A3),h=jd(),f=Jh(D3),g=Hs(P3),[p,w]=c.useState(I3),[v,x]=c.useState(T3),[m,b]=c.useState(R3),y=[{label:"p50",current:m.ageP50,samples:m.p50Samples,color:"var(--status-success)"},{label:"p90",current:m.ageP90,samples:m.p90Samples,color:"var(--status-info)"},{label:"p99",current:m.ageP99,samples:m.p99Samples,color:"var(--status-warning)"},{label:"max",current:m.ageMax,samples:m.maxSamples,color:"var(--status-error)"}];let S;e[0]!==m.samples?(S=m.samples.reduce(E3,0),e[0]=m.samples,e[1]=S):S=e[1];const N=S,C=y.reduce(O3,0);let k;e[2]!==p.entries?(k=new Map,p.entries.forEach(re=>{k.set(re.metric,re.count)}),e[2]=p.entries,e[3]=k):k=e[3];let A;e[4]!==k?(A=k.get("ui.message_list.render")??0,e[4]=k,e[5]=A):A=e[5];let D;e[6]!==k?(D=k.get("ui.message_list.render.streaming")??0,e[6]=k,e[7]=D):D=e[7];let P;e[8]!==k?(P=k.get("ui.chat_message.render")??0,e[8]=k,e[9]=P):P=e[9];let F;e[10]!==k?(F=k.get("ui.chat_message.render.streaming")??0,e[10]=k,e[11]=F):F=e[11];let W;e[12]!==k?(W=k.get("ui.chat_message.render.static_during_stream")??0,e[12]=k,e[13]=W):W=e[13];let E;e[14]!==k?(E=k.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=k,e[15]=E):E=e[15];let H;e[16]!==A||e[17]!==D||e[18]!==P||e[19]!==F||e[20]!==W||e[21]!==E?(H={messageListRender:A,messageListRenderStreaming:D,chatMessageRender:P,chatMessageRenderStreaming:F,chatMessageRenderStaticDuringStream:W,chatMessageRenderStaticOutsideActiveTurnDuringStream:E},e[16]=A,e[17]=D,e[18]=P,e[19]=F,e[20]=W,e[21]=E,e[22]=H):H=e[22];const z=H;let B,T;e[23]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const re=()=>{w(ho()),x(po()),b(ua())};re();const we=window.setInterval(re,500);return()=>window.clearInterval(we)},B=[],e[23]=B,e[24]=T):(B=e[23],T=e[24]),c.useEffect(T,B);let j,I;e[25]!==l?(j=()=>{if(l==="idle")return;const re=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(re)},I=[l],e[25]=l,e[26]=j,e[27]=I):(j=e[26],I=e[27]),c.useEffect(j,I);let _=0,K=0,G=0;for(const re of Object.keys(f)){const we=f[re]??[];K=K+we.length;for(const Ve of we)Ve.role==="user"?G=G+1:Ve.role==="assistant"&&(_=_+1)}let Q;e[28]!==_||e[29]!==K||e[30]!==G?(Q={assistant:_,total:K,user:G},e[28]=_,e[29]=K,e[30]=G,e[31]=Q):Q=e[31];const ge=Q;let se;if(e[32]!==u||e[33]!==f||e[34]!==d||e[35]!==h||e[36]!==r){let re;e[38]!==u||e[39]!==f||e[40]!==d||e[41]!==r?(re=we=>{const Ve=f[we.id]??[];let st=0,Ge=0;for(const X of Ve)X.role==="user"?Ge=Ge+1:X.role==="assistant"&&(st=st+1);const ae=d.get(we.id);return{id:we.id,title:we.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:st,messageCount:Ve.length,userMessageCount:Ge,isStreaming:ae?.isStreaming||!1,isZombie:ae?.isZombie||!1,backgroundCount:ae?.backgroundMessageCount||0,lastAccessed:ae?.lastAccessedAt||0,isCurrent:we.id===u}},e[38]=u,e[39]=f,e[40]=d,e[41]=r,e[42]=re):re=e[42],se=h.map(re).sort(F3),e[32]=u,e[33]=f,e[34]=d,e[35]=h,e[36]=r,e[37]=se}else se=e[37];const Y=se;let te;e[43]!==f?(te=Object.keys(f),e[43]=f,e[44]=te):te=e[44];const he=te.length;let L;e[45]===Symbol.for("react.memo_cache_sentinel")?(L=async()=>{try{const re={generatedAt:new Date().toISOString(),ui:ho(),vscode:po()};await navigator.clipboard.writeText(JSON.stringify(re,null,2)),a("copied")}catch{a("error")}},e[45]=L):L=e[45];const le=L,Z=ep,ue="fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let V;e[46]===Symbol.for("react.memo_cache_sentinel")?(V={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=V):V=e[46];let ee;e[47]!==i?(ee=S3(i),e[47]=i,e[48]=ee):ee=e[48];let be;e[49]!==ee?(be=s.jsx(M,{name:ee,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=ee,e[50]=be):be=e[50];let xe;e[51]!==r?(xe=r("memoryDebugPanel.title"),e[51]=r,e[52]=xe):xe=e[52];let Ne;e[53]!==xe?(Ne=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:xe}),e[53]=xe,e[54]=Ne):Ne=e[54];let Pe;e[55]!==be||e[56]!==Ne?(Pe=s.jsxs("div",{className:"flex items-center gap-2",children:[be,Ne]}),e[55]=be,e[56]=Ne,e[57]=Pe):Pe=e[57];let Se;e[58]!==i?(Se=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(at,{size:"xs",variant:"ghost",onClick:le,children:s.jsx(M,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(at,{size:"xs",variant:"ghost",onClick:()=>{Qm(),w(ho()),x(po())},children:s.jsx(M,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=Se):Se=e[59];let Re;e[60]!==i?(Re=i==="requests"?s.jsx(at,{size:"xs",variant:"ghost",onClick:()=>{w3(),b(ua())},children:s.jsx(M,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=Re):Re=e[61];let ye;e[62]!==n?(ye=n?s.jsx(at,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(M,{name:"close",className:"h-4 w-4"})}):null,e[62]=n,e[63]=ye):ye=e[63];let pe;e[64]!==Se||e[65]!==Re||e[66]!==ye?(pe=s.jsxs("div",{className:"flex items-center gap-1",children:[Se,Re,ye]}),e[64]=Se,e[65]=Re,e[66]=ye,e[67]=pe):pe=e[67];let me;e[68]!==Pe||e[69]!==pe?(me=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Pe,pe]}),e[68]=Pe,e[69]=pe,e[70]=me):me=e[70];let je;e[71]===Symbol.for("react.memo_cache_sentinel")?(je={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=je):je=e[71];const ne=i==="memory"?"secondary":"ghost";let fe;e[72]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>o("memory"),e[72]=fe):fe=e[72];let ce;e[73]!==r?(ce=r("memoryDebugPanel.tabs.memory"),e[73]=r,e[74]=ce):ce=e[74];let R;e[75]!==ne||e[76]!==ce?(R=s.jsx(at,{size:"sm",variant:ne,className:"flex-1",onClick:fe,children:ce}),e[75]=ne,e[76]=ce,e[77]=R):R=e[77];const $=i==="streaming"?"secondary":"ghost";let de;e[78]===Symbol.for("react.memo_cache_sentinel")?(de=()=>o("streaming"),e[78]=de):de=e[78];let ie;e[79]!==r?(ie=r("memoryDebugPanel.tabs.streaming"),e[79]=r,e[80]=ie):ie=e[80];let Ae;e[81]!==$||e[82]!==ie?(Ae=s.jsx(at,{size:"sm",variant:$,className:"flex-1",onClick:de,children:ie}),e[81]=$,e[82]=ie,e[83]=Ae):Ae=e[83];const Be=i==="requests"?"secondary":"ghost";let Ce;e[84]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>o("requests"),e[84]=Ce):Ce=e[84];let q;e[85]!==r?(q=r("memoryDebugPanel.tabs.requests"),e[85]=r,e[86]=q):q=e[86];let Ee;e[87]!==Be||e[88]!==q?(Ee=s.jsx(at,{size:"sm",variant:Be,className:"flex-1",onClick:Ce,children:q}),e[87]=Be,e[88]=q,e[89]=Ee):Ee=e[89];let Me;e[90]!==R||e[91]!==Ae||e[92]!==Ee?(Me=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:je,children:[R,Ae,Ee]}),e[90]=R,e[91]=Ae,e[92]=Ee,e[93]=Me):Me=e[93];const O=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ws,{label:r("memoryDebugPanel.metric.totalMessages"),value:ge.total}),s.jsx(ws,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${he} / ${ul.MAX_SESSIONS}`}),s.jsx(ws,{label:r("memoryDebugPanel.metric.userMessages"),value:ge.user}),s.jsx(ws,{label:r("memoryDebugPanel.metric.assistantMessages"),value:ge.assistant})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:Zh()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:ul.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:g})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(kn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:Y.map(re=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:re.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:re.title}),re.isStreaming?s.jsx(M,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,re.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:re.assistantMessageCount,user:re.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:re.messageCount})}),re.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",re.backgroundCount]}):null]})]},re.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(gt,{children:[s.jsx(xt,{asChild:!0,children:s.jsx(at,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:h.map(B3),currentSessionId:u,cachedSessions:Object.keys(f),messageRoleCounts:ge,sessionMessageRoleCounts:Y.map(_3),memoryStates:Object.fromEntries(d)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(bt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):i==="streaming"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(at,{size:"xs",variant:"outline",onClick:le,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(ws,{label:r("memoryDebugPanel.metric.uiMetrics"),value:p.entries.length}),s.jsx(ws,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(ws,{label:r("memoryDebugPanel.metric.messageListRenders"),value:z.messageListRender}),s.jsx(ws,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:z.messageListRenderStreaming}),s.jsx(ws,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:z.chatMessageRender}),s.jsx(ws,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:z.chatMessageRenderStreaming}),s.jsx(ws,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:z.chatMessageRenderStaticDuringStream}),s.jsx(ws,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:z.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Hc,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:p,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Hc,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ws,{label:r("memoryDebugPanel.requests.totalRequests"),value:`${m.totalSettled} / ${m.totalStarted}`}),s.jsx(ws,{label:r("memoryDebugPanel.requests.tracking"),value:m.startedAt?vm(m.durationMs):r("memoryDebugPanel.common.idle")})]}),m.samples.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:r("memoryDebugPanel.requests.noSamples")}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.inFlight")}),s.jsxs("span",{children:[s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:m.inFlight}),s.jsxs("span",{className:"text-[var(--surface-muted-foreground)]",children:[" · ",r("memoryDebugPanel.requests.peak")," "]}),s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:m.peak})]})]}),s.jsx(Gc,{series:[{samples:m.samples,color:"var(--status-info)",filled:!0}],peak:N,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.chartLabel",{peak:m.peak}),maxLabel:`${N}`}),s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.duration")}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ma(m.peakAgeMs)})]}),s.jsx(Gc,{series:y.map(L3),peak:C,windowSeconds:m.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:ma(C)}),s.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:y.map($3)}),s.jsxs("div",{className:"flex items-center justify-between typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r("memoryDebugPanel.requests.windowHint",{seconds:m.windowSeconds})}),s.jsx("span",{children:r("memoryDebugPanel.requests.now")})]})]})]});let oe;return e[94]!==Z||e[95]!==V||e[96]!==me||e[97]!==Me||e[98]!==O?(oe=s.jsxs(Z,{className:ue,style:V,children:[me,Me,O]}),e[94]=Z,e[95]=V,e[96]=me,e[97]=Me,e[98]=O,e[99]=oe):oe=e[99],oe},j3=v3;function k3(t,e){return t+e.count}function C3(t,e){return Math.max(t,e.samples.length)}function N3(t){return t.currentSessionId}function A3(t){return t.sessionMemoryState}function D3(t){return t.message}function P3(t){return t.totalRequestCount}function I3(){return ho()}function T3(){return po()}function R3(){return ua()}function E3(t,e){return Math.max(t,e)}function M3(t,e){return Math.max(t,e)}function O3(t,e){return e.samples.reduce(M3,t)}function F3(t,e){return e.lastAccessed-t.lastAccessed}function B3(t){return{id:t.id,title:t.title}}function _3(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}function L3(t){return{samples:t.samples,color:t.color}}function $3(t){return s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:t.label}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ma(t.current)})]},t.label)}const W3=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},z3=async()=>{const t=W3()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},qc="aiworker:menu-action",wi="aiworker:check-for-updates",V3=t=>{const e=Qe(m=>m.openNewSessionDraft),n=De(m=>m.toggleCommandPalette),r=De(m=>m.setCommandPaletteOpen),i=De(m=>m.toggleHelpDialog),o=De(m=>m.toggleSidebar),l=De(m=>m.setSessionSwitcherOpen),a=De(m=>m.setSettingsDialogOpen),u=De(m=>m.setAboutDialogOpen),d=Rr(m=>m.checkForUpdates),{setThemeMode:h}=Jn(),f=c.useRef(!1),g=c.useCallback(()=>{f.current||(f.current=!0,d().then(()=>{const{available:m,error:b}=Rr.getState();if(b){Fe.error("Failed to check for updates",{description:b});return}m||Fe.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[d]),p=c.useCallback(()=>{hn.requestDirectoryDialog()},[]),w=c.useCallback(m=>{const b=tp();if(b.length===0)return;const y=Qe.getState().currentSessionId,S=b.findIndex(k=>k.id===y);let N=m>0?0:b.length-1;S>=0&&(N=(S+m+b.length)%b.length);const C=b[N];C&&(l(!1),Qe.getState().setCurrentSession(C.id))},[l]),v=c.useCallback(m=>{const{activeProjectId:b,projects:y,setActiveProject:S}=Vt.getState();if(y.length===0)return;const N=y.findIndex(A=>A.id===b);let C=m>0?0:y.length-1;N>=0&&(C=(N+m+y.length)%y.length);const k=y[C];k&&S(k.id)},[]),x=c.useCallback(m=>{switch(m){case"about":u(!0);break;case"settings":a(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l(!1);{const b=Qe.getState(),y=Zt.getState().currentDirectory;e(b.currentSessionId&&y?{directoryOverride:y}:void 0)}break;case"new-worktree-session":l(!1),Pd();break;case"change-workspace":p();break;case"toggle-right-sidebar":{const b=Zt.getState().currentDirectory;if(!b)break;const y=De.getState(),S=nr(b),N=y.contextPanelByDirectory[S];N?.isOpen?y.closeContextPanel(S):N?.activeTabId?y.setActiveContextPanelTab(S,N.activeTabId):y.openContextSurface(S,"git");break}case"open-right-sidebar-git":{const b=Zt.getState().currentDirectory;if(!b)break;De.getState().openContextSurface(nr(b),"git");break}case"open-right-sidebar-files":{const b=Zt.getState().currentDirectory;if(!b)break;De.getState().openContextSurface(nr(b),"file");break}case"toggle-terminal":{const b=Zt.getState().currentDirectory;if(!b)break;De.getState().openContextSurface(nr(b),"terminal");break}case"toggle-terminal-expanded":{const b=Zt.getState().currentDirectory;if(!b)break;const y=nr(b),S=De.getState(),N=S.contextPanelByDirectory[y];(N?.isOpen?N.tabs.find(k=>k.id===N.activeTabId)?.mode:null)!=="terminal"&&S.openContextSurface(y,"terminal"),S.toggleContextPanelExpanded(y);break}case"copy":{const b=new Event("aiworker:copy",{cancelable:!0});!window.dispatchEvent(b)||z3();break}case"theme-light":h("light");break;case"theme-dark":h("dark");break;case"theme-system":h("system");break;case"add-selection-to-chat":sp();break;case"toggle-sidebar":o();break;case"toggle-memory-debug":t?.();break;case"go-back":Zt.getState().goBack();break;case"go-forward":Zt.getState().goForward();break;case"previous-session":w(-1);break;case"next-session":w(1);break;case"previous-project":v(-1);break;case"next-project":v(1);break;case"help-dialog":i();break;case"download-logs":{Id().catch(()=>{Fe.error("Failed to collect OpenCode status")});break}}},[p,v,w,t,e,u,l,r,a,h,n,i,o]);c.useEffect(()=>{const m=y=>{const S=y.detail;S&&x(S)},b=()=>{g()};return window.addEventListener(qc,m),window.addEventListener(wi,b),()=>{window.removeEventListener(qc,m),window.removeEventListener(wi,b)}},[x,g]),c.useEffect(()=>{if(typeof window>"u")return;const b=window.__AIWORKER_DESKTOP__?.listen;if(typeof b!="function")return;let y=null,S=null;return b("aiworker:menu-action",N=>{const C=N?.payload;typeof C=="string"&&x(C)}).then(N=>{y=N}).catch(()=>{}),b("aiworker:check-for-updates",()=>{window.dispatchEvent(new Event(wi))}).then(N=>{S=N}).catch(()=>{}),()=>{(async()=>{try{const C=y?.();C instanceof Promise&&await C}catch{}try{const C=S?.();C instanceof Promise&&await C}catch{}})()}},[x])},U3="aiworker:tray-action",Qc=5e3,K3=500,jm=20,Yc=()=>{if(typeof window>"u")return!1;const t=window.__AIWORKER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},Xc=()=>typeof window<"u"&&window.__AIWORKER_ELECTRON__?.trayEnabled!==!1,H3=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},G3=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},km=(t,e)=>$d(t,e,Br.getState().ids,va.getState().rankById),q3=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},Q3=(t,e,n,r,i)=>{if(!t)return"";const o=op(n,r,t),l=e.project?.name,a=o?.label?.trim()||l?.trim()||q3(t),u=bo(t);let d=u&&i.get(u)||"";if(!d){for(const[h,f]of On.getState().directories)if(bo(h)===u){d=f.status?.current??"";break}}if(!d)for(const h of r.values()){const f=h.find(g=>bo(g.path)===u);if(f?.branch){d=f.branch;break}}return d?`${a} · ${d}`:a},Y3=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=rr.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const i=new Map(t.map(l=>[l.providerId,l])),o=[];for(const l of ip){if(!e.includes(l.id))continue;const a=i.get(l.id);if(!a||a.configured!==!0)continue;const u=[];for(const[h,f]of Object.entries(a.usage?.windows??{})){const g=r==="remaining"?f.remainingPercent:f.usedPercent;u.push({label:lp(h),value:ap(f.valueLabel,g)})}const d=!a.ok&&a.error?a.error:u.length===0?"No rate limits reported":null;o.push({provider:l.name,rows:u,status:d})}return{mode:r,groups:o}},X3=async()=>{try{if(Uo())return"Local AiWorker";const t=window.__AIWORKER_LOCAL_ORIGIN__||window.location.origin,e=Mn();if(e&&Ha(e,t))return"Local AiWorker";const r=(await rd()).hosts.find(i=>e?Ha(e,Ym(i)):!1);return r?.label?.trim()?od(r.label.trim()):"Instance"}catch{return""}},J3=()=>{const t=new Map,e=new Map,n=[],r=new Map;let i;try{i=To()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[o,l]of i.children.entries()){const a=l.getState();a.vcs?.branch&&e.set(bo(o)??o,a.vcs.branch);for(const u of a.session)u?.id&&r.set(u.id,u.title);for(const[u,d]of Object.entries(a.session_status??{})){const h=d?.type,f=h==="busy"?"busy":h==="retry"?"retry":"idle",g=t.get(u);(!g||g==="idle")&&t.set(u,f)}for(const[u,d]of Object.entries(a.permission??{}))for(const h of d??[]){if(!h?.id)continue;const f=h.sessionID||u;n.push({kind:"permission",id:h.id,sessionId:f,sessionTitle:"",label:H3(h),directory:o})}for(const[u,d]of Object.entries(a.question??{}))for(const h of d??[]){if(!h?.id)continue;const f=h.sessionID||u;n.push({kind:"question",id:h.id,sessionId:f,sessionTitle:"",label:G3(h),directory:o})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},Z3=()=>{const t=As.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(km).slice(0,jm).forEach(r=>{const i=_s(r);i&&e.add(i)});const n=new Map;for(const r of t){if(!r?.id)continue;const i=_s(r);if(!i||!e.has(i))continue;const o=n.get(i)??[];o.push(r.id),n.set(i,o)}return n},e5=t=>{const e=J3(),n=Aa.getState().index.session,r=As.getState().activeSessions,i=new Map(e.titleById),o=new Map;for(const x of r)if(x?.id&&(x.title&&i.set(x.id,x.title),x.parentID)){const m=o.get(x.parentID)??[];m.push(x.id),o.set(x.parentID,m)}const l=x=>{const m=[],b=[...o.get(x)??[]],y=new Set;for(;b.length;){const S=b.pop();y.has(S)||(y.add(S),m.push(S),b.push(...o.get(S)??[]))}return m},a=Na.getState().statusById,u=x=>{const m=e.statusById.get(x);return m&&m!=="idle"?m:a.get(x)?.status.type??m??"idle"},d=x=>{const m=x.map(b=>u(b));return m.includes("busy")?"busy":m.includes("retry")?"retry":"idle"},h=Vt.getState().projects,f=Qe.getState().availableWorktreesByProject,g=r.filter(x=>x?.id&&!x.parentID).slice().sort(km).slice(0,jm).map(x=>{const m=[x.id,...l(x.id)],b=_s(x)??"";return{id:x.id,title:x.title||"Untitled session",status:d(m),branch:b?e.branchByDirectory.get(b)??"":"",unseen:m.reduce((y,S)=>y+(n.unseenCount[S]??0),0),hasError:m.some(y=>n.unseenHasError[y]??!1),directory:b,subtitle:Q3(b,x,h,f,e.branchByDirectory)}}),p=e.approvals.map(x=>({...x,sessionTitle:i.get(x.sessionId)||""})),w=De.getState();let v=0;if(w.dockBadgeEnabled)for(const x of r){if(!x?.id||x.parentID)continue;let m=n.unseenCount[x.id]??0;m===0&&w.notifyOnSubtasks&&(m=l(x.id).reduce((b,y)=>b+(n.unseenCount[y]??0),0)),m>0&&(v+=1)}return{sessions:g,approvals:p,instanceName:t,usage:Y3(),dockBadgeCount:v}},t5=()=>{c.useEffect(()=>{if(!Yc()||!Xc()||!Ho())return;let t=!1,e="",n=null,r="";const i=()=>{if(t)return;const C=e5(r),k=JSON.stringify(C);k!==e&&(e=k,Rn("desktop_tray_update",C))};X3().then(C=>{t||(r=C,i())});const o=async()=>{const C=Z3();await Promise.all([...C.entries()].map(async([k,A])=>{const D=await Qs.getSessionStatusForDirectory(k).catch(()=>null);t||D===null||np(k,D,A)}))},l=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,i()},K3))},a=new Map,u=()=>{if(t)return;let C;try{C=To()}catch{return}const k=new Set;for(const[A,D]of C.children.entries())k.add(A),a.has(A)||a.set(A,D.subscribe(()=>l()));for(const[A,D]of a)k.has(A)||(D(),a.delete(A))};let d=null;try{d=To().subscribeRegistry(()=>{u(),l()})}catch{}u();const h=Aa.subscribe(()=>l()),f=As.subscribe(()=>l()),g=Vt.subscribe(()=>l()),p=Qe.subscribe(()=>l()),w=On.subscribe(()=>l()),v=De.subscribe(()=>l()),x=Na.subscribe(()=>l()),m=va.subscribe(()=>l()),b=Br.subscribe(()=>l());o();const y=window.setInterval(()=>{o()},Qc),S=rr.subscribe(()=>l());rr.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:C,results:k}=rr.getState();C.length>0&&C.some(D=>!k.some(P=>P.providerId===D))&&rr.getState().fetchQuotas(C)});const N=window.setInterval(()=>{u(),i()},Qc);return i(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(N),window.clearInterval(y),h(),f(),g(),p(),w(),v(),x(),m(),b(),S(),d?.();for(const C of a.values())C();a.clear()}},[]),c.useEffect(()=>{if(!Yc()||!Xc()||typeof window>"u")return;const e=window.__AIWORKER_DESKTOP__?.listen;if(typeof e!="function")return;const n=i=>{i.type==="respond-permission"&&rp(i.sessionId,i.id,i.response).catch(()=>{Fe.error("Failed to respond to permission request")})};let r=null;return e(U3,i=>{const o=i?.payload;!o||typeof o!="object"||typeof o.type!="string"||n(o)}).then(i=>{r=i}).catch(()=>{}),()=>{try{const i=r?.();i instanceof Promise&&i.catch(()=>{})}catch{}}},[])},s5=45e3,n5=(t,e,n=window.setInterval.bind(window),r=window.clearInterval.bind(window))=>{t();const i=n(e,s5);return()=>r(i)},r5=t=>{const e=Xe.c(3);let n,r;e[0]!==t?(n=()=>{if(t)return n5(o5,i5)},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),c.useEffect(n,r)};function o5(){cp(Ro())}function i5(){Ia()}const a5="/api/notifications/stream",l5=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),c5=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="aiworker:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},d5=t=>{const e=Xe.c(3),n=t?.enabled??!0;let r,i;e[0]!==n?(r=()=>{if(!n||pn()||!fa()||typeof window>"u"||typeof EventSource>"u")return;const o=new EventSource(ad().sse(a5));return o.onmessage=u5,()=>{o.close()}},i=[n],e[0]=n,e[1]=r,e[2]=i):(r=e[1],i=e[2]),c.useEffect(r,i)};function u5(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=De.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&l5())return;const r=c5(e);if(!r)return;Ko()?.notifications?.notifyAgentCompletion(r)}const m5=6e4,f5=t=>{const e=Xe.c(10),n=De(h5),r=dp(p5),o=tg(t)?.path??null;let l,a;e[0]!==n||e[1]!==r||e[2]!==o?(l=()=>{n&&r(o,{maxAgeMs:m5})},a=[n,r,o],e[0]=n,e[1]=r,e[2]=o,e[3]=l,e[4]=a):(l=e[3],a=e[4]),c.useEffect(l,a);let u,d;e[5]!==n||e[6]!==r||e[7]!==o?(u=()=>{if(n)return Yr(h=>{h.type==="agent-memory-changed"&&r(o)})},d=[n,r,o],e[5]=n,e[6]=r,e[7]=o,e[8]=u,e[9]=d):(u=e[8],d=e[9]),c.useEffect(u,d)};function h5(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function p5(t){return t.load}const Jc="pwa-install-toast-shown",Zc="pwa-install-toast-dismissed",g5=()=>{const t=Xe.c(6),{browserTab:e}=sg(),{t:n}=pt(),r=c.useRef(n);let i,o;t[0]!==n?(i=()=>{r.current=n},o=[n],t[0]=n,t[1]=i,t[2]=o):(i=t[1],o=t[2]),c.useEffect(i,o);let l,a;t[3]!==e?(l=()=>{if(typeof window>"u"||!fa()||!e)return;let u=null,d=null;const h=()=>{d!==null&&(Fe.dismiss(d),d=null)},f=async()=>{if(!u)return;const w=u;u=null,h(),await w.prompt();const{outcome:v}=await w.userChoice;v==="accepted"&&Fe.success(r.current("pwa.installPrompt.started"))},g=w=>{const v=w;if(typeof v.prompt!="function")return;v.preventDefault(),u=v;const x=Po(),m=Xm();ng({dismissed:x.getItem(Zc),sessionShown:m.getItem(Jc),hasActiveToast:d!==null})&&(m.setItem(Jc,"true"),d=Fe.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Po().setItem(Zc,"true"),h()}}}))},p=()=>{u=null,h(),Fe.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",p),()=>{h(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",p)}},a=[e],t[3]=e,t[4]=l,t[5]=a):(l=t[4],a=t[5]),c.useEffect(l,a)},x5=({open:t,onOpenChange:e})=>{const{t:n}=pt(),r=!1,[i,o]=c.useState(null),[l,a]=c.useState(null),[u,d]=c.useState(!1),[h,f]=c.useState(!1),[g,p]=c.useState(null),[w,v]=c.useState(!1);c.useCallback(async()=>{},[g,u,r,n]),c.useEffect(()=>{if(!t)return;(async()=>{try{const b=await ds("/api/system/info");if(b.ok){const y=await b.json();if(typeof y.aiworkerVersion=="string"&&y.aiworkerVersion.trim()){o(y.aiworkerVersion);return}}}catch{}o(await up())})()},[t]),c.useEffect(()=>{if(!t)return;let m=!1;return(async()=>{try{const y=await ds("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const S=await y.json().catch(()=>null),N=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!m&&N&&a(N)}catch{}})(),()=>{m=!0}},[t]),c.useEffect(()=>{{p(null),v(!1);return}},[t,r]);const x=i;return s.jsx(vs,{open:t,onOpenChange:e,children:s.jsx(js,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(kd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"AiWorker"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),l&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:l})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(M,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(M,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(M,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@aiworker_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},ed=t=>{if(!(typeof window>"u")){if(t){window.location.href="aiworker://focus/mcp-auth";return}window.location.replace("/")}},Si=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},b5=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to AiWorker and click Authorize again.":n},y5=()=>{const t=mp(a=>a.completeAuth),[e,n]=c.useState("working"),[r,i]=c.useState(!1),[o,l]=c.useState("Completing MCP authorization...");return c.useEffect(()=>{if(typeof window>"u"){n("error"),l("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),u=Si(a,"code"),d=fp(a),h=hp(a),f=Si(a,"error"),g=Si(a,"error_description");if(f){h&&ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(g??f);return}(async()=>{try{if(!u)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into AiWorker manually.");let p=d,w=!1;if(h){const v=await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`);if(v.ok){const x=await v.json().catch(()=>null);w=x?.origin===pp,i(w),!p&&x?.name?.trim()&&(p={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!p?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into AiWorker manually.");await t(p.name,u,p.directory),h&&await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("success"),w&&ed(!0),l("Authorization completed. You can close this tab and return to AiWorker.")}catch(p){h&&await ds(`/api/mcp/auth/pending?state=${encodeURIComponent(h)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(b5(p,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("h1",{className:gp,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:Te("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:o})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(at,{type:"button",onClick:()=>ed(r),children:"Return to AiWorker"})})]})})},td=Ln(()=>Bn(()=>import("./OnboardingScreen-D2DG7K6b.js"),__vite__mapDeps([144,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(t=>({default:t.OnboardingScreen}))),w5=()=>{const t=Xe.c(3),e=De(N5),n=De(A5);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(x5,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},S5=t=>{const e=Xe.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=pt();let o;e[0]!==i?(o=i("startup.initRecovery.title"),e[0]=i,e[1]=o):o=e[1];let l;e[2]!==o?(l=s.jsx("h1",{className:"typography-title text-foreground",children:o}),e[2]=o,e[3]=l):l=e[3];let a;e[4]!==i?(a=i("startup.initRecovery.description"),e[4]=i,e[5]=a):a=e[5];let u;e[6]!==a?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:a}),e[6]=a,e[7]=u):u=e[7];let d;e[8]!==l||e[9]!==u?(d=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,u]}),e[8]=l,e[9]=u,e[10]=d):d=e[10];let h;e[11]!==r||e[12]!==i?(h=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=h):h=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==h?(f=s.jsx(at,{type:"button",onClick:n,disabled:r,children:h}),e[14]=r,e[15]=n,e[16]=h,e[17]=f):f=e[17];let g;return e[18]!==d||e[19]!==f?(g=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[d,f]})}),e[18]=d,e[19]=f,e[20]=g):g=e[20],g},sd=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",v5=()=>{if(typeof window>"u"||!Ag())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true",allowPromptingSubagentSessions:t.has("allowPromptingSubagentSessions")?t.get("allowPromptingSubagentSessions")==="1":void 0}},j5=()=>typeof window>"u"?!1:window.location.pathname===Sp,k5=t=>{const e=Xe.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,o=Zt(D5),l=Qe(P5),a=Qe(I5),u=yd(),d=c.useRef(null);let h;e[0]!==n.directory?(h=sd(n.directory),e[0]=n.directory,e[1]=h):h=e[1];const f=h;let g;e[2]!==o?(g=sd(o),e[2]=o,e[3]=g):g=e[3];const p=g;let w,v;if(e[4]!==p||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==u?(w=()=>{if(r||f&&p!==f)return;const N=`${f}
|
|
928
|
-
${n.sessionId}`;d.current===N&&l||(d.current=N,a(n.sessionId,n.directory),u.ensureSessionRenderable(n.sessionId,!0))},v=[p,l,n.directory,n.sessionId,f,r,a,u],e[4]=p,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=a,e[11]=u,e[12]=w,e[13]=v):(w=e[12],v=e[13]),c.useEffect(w,v),f&&p!==f)return null;let x;e[14]!==i?(x=s.jsx(Ud,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=x):x=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(tu,{}),e[16]=m):m=e[16];let b;e[17]!==i||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(b=s.jsx(eu,{active:i,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=i,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=b):b=e[20];let y;e[21]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(Kd,{}),e[21]=y):y=e[21];let S;return e[22]!==x||e[23]!==b?(S=s.jsxs(s.Fragment,{children:[x,m,b,y]}),e[22]=x,e[23]=b,e[24]=S):S=e[24],S};function C5({apis:t}){c.useEffect(()=>{Jm("App:mounted"),Zm()&&console.info("[startup-trace] enabled. Run console.table(window.__AIWORKER_STARTUP_TRACE__) after startup.")},[]);const e=Ut(V=>V.initializeApp),n=Ut(V=>V.isInitialized),r=Ut(V=>V.isConnected),i=Ut(V=>V.providers.length),o=Ut(V=>V.agents.length),l=Ut(V=>V.loadProviders),a=Ut(V=>V.loadAgents),u=Qe(V=>V.error),d=Qe(V=>V.clearError),h=Zt(V=>V.currentDirectory),f=Zt(V=>V.setDirectory),g=Zt(V=>V.isSwitchingDirectory),[p,w]=c.useState(!1),v=Cn(V=>V.refreshStatus),x=Ni(V=>V.refreshStatus),[m,b]=c.useState(()=>t.runtime.isVSCode),[y,S]=c.useState(!1),[N,C]=c.useState(!1),[k,A]=c.useState(0),[D,P]=c.useState(0),[F,W]=c.useState(!1),E=De(V=>V.wideChatLayoutEnabled),H=De(V=>V.mobileKeyboardMode),z=c.useMemo(()=>pn(),[]),B=xa(V=>V.setPlanModeEnabled),[T,j]=c.useState(()=>Ga()),[I,_]=c.useState(()=>{const V=qa();return V!==null?Qa({isDesktopShell:!0,bootOutcome:V}):null}),K=c.useRef(!1),G=c.useMemo(()=>v5(),[]),Q=!G||y,ge=c.useMemo(()=>j5(),[]);c.useEffect(()=>(Ya(p),()=>{Ya(!1)}),[p]),c.useEffect(()=>(Uc(p),()=>{Uc(!1)}),[p]),c.useEffect(()=>{ef(H)},[H]),c.useEffect(()=>{b(t.runtime.isVSCode)},[t.runtime.isVSCode]),c.useEffect(()=>Go(V=>{rg(V),P(ee=>ee+1),C(!1),A(ee=>ee+1)}),[]);const se=ml(V=>{const ee=Ss();return Object.values(V.runsByOriginalSessionID).filter(be=>be.status==="running"&&be.runtimeKey===ee).map(be=>`${be.originalSessionID}:${be.phase}:${be.lastForwardedMessageID??""}:${be.expectedAssistantParentID??""}`).sort().join("|")});c.useEffect(()=>{if(G)return;const V=Ss(),ee=Object.values(ml.getState().runsByOriginalSessionID).filter(be=>be.status==="running"&&be.runtimeKey===V);for(const be of ee)xp(be.originalSessionID)},[se,G,D]),c.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",E),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[E]),c.useEffect(()=>(Xa(t),()=>Xa(null)),[t]),c.useEffect(()=>{G||(v(t.github,{force:!0}),x(t.linear,{force:!0}))},[t.github,t.linear,G,v,x]),bp();const Y=T==="valid",te=I?.screen==="main";c.useEffect(()=>{if(!tf({isDesktopShell:z,isInitialized:n,bootOutcomeKnown:Y,bootViewIsMain:te}))return;const V=setTimeout(()=>{const ee=document.getElementById("initial-loading");ee&&(ee.classList.add("fade-out"),setTimeout(()=>{ee.remove()},300))},150);return()=>clearTimeout(V)},[z,n,Y,te]),c.useEffect(()=>{if(!z||T!=="malformed")return;const V=document.getElementById("initial-loading");V&&(V.textContent="Desktop startup failed — please restart the app.")},[z,T]),c.useEffect(()=>{if(z)return;const V=setTimeout(()=>{const ee=document.getElementById("initial-loading");ee&&!n&&(ee.classList.add("fade-out"),setTimeout(()=>{ee.remove()},300))},5e3);return()=>clearTimeout(V)},[z,n]),c.useEffect(()=>{let V=!1;return(async()=>{const be=await ds("/health",{method:"GET"}).catch(()=>null);if(!be||!be.ok||V)return;const xe=await be.json().catch(()=>null);if(!xe||V)return;const Ne=xe.planModeExperimentalEnabled;B(Ne===!0||Ne===1||Ne==="1"||Ne==="true")})(),()=>{V=!0}},[B]),c.useEffect(()=>{m||e()},[e,m]),c.useEffect(()=>{if(m||n)return;let V=!0,ee,be=0;const xe=10,Ne=1e3,Pe=async()=>{if(!V)return;if(be>=xe){C(!0);return}const Se=Ut.getState();if(Se.isInitialized){C(!1);return}be+=1,await Se.initializeApp();const Re=Ut.getState();if(!V)return;if(Re.isInitialized){C(!1);return}if(be>=xe){C(!0);return}const ye=Math.min(Ne*Math.pow(2,be-1),16e3);ee=setTimeout(Pe,ye)};return ee=setTimeout(Pe,Ne),()=>{V=!1,ee&&clearTimeout(ee)}},[k,n,m]),c.useEffect(()=>{n&&C(!1)},[n]),c.useEffect(()=>{if(!N)return;const V=document.getElementById("initial-loading");V&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},[N]),c.useEffect(()=>{if(m||!r||i>0&&o>0)return;let V=!0,ee=0;const be=15,xe=async()=>{const Pe=Ut.getState();if(!(Pe.providers.length>0&&Pe.agents.length>0))try{Pe.providers.length===0&&await l({source:"startupRecovery"}),Ut.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};xe();const Ne=setInterval(()=>{if(V){if(++ee>=be){clearInterval(Ne);return}xe()}},2e3);return()=>{V=!1,clearInterval(Ne)}},[r,m,a,l,i,o]),c.useEffect(()=>{g||m||r&&Qs.setDirectory(h)},[h,g,r,m]),c.useEffect(()=>{if(!G||typeof window>"u")return;const V=xe=>{S(xe?.visible===!0)},ee=xe=>{if(xe.origin!==window.location.origin||xe.source!==window.parent)return;const Ne=xe.data;Ne?.type===du&&V(Ne.payload)},be=window;return be.__aiworkerSetEmbeddedVisibility=V,window.addEventListener("message",ee),Ng(),()=>{window.removeEventListener("message",ee),be.__aiworkerSetEmbeddedVisibility===V&&delete be.__aiworkerSetEmbeddedVisibility}},[G]),c.useEffect(()=>{!G?.directory||m||h!==G.directory&&f(G.directory,{showOverlay:!1})},[h,G,m,f]),c.useEffect(()=>{if(!G||typeof window>"u")return;const V=ee=>{ee.storageArea===window.localStorage&&ee.key==="ui-store"&&De.persist.rehydrate()};return window.addEventListener("storage",V),()=>{window.removeEventListener("storage",V)}},[G]),c.useEffect(()=>{if(typeof window>"u")return;const V=ee=>{const be=ee.detail,xe=typeof be?.sessionId=="string"?be.sessionId.trim():"";if(!xe)return;const Ne=typeof be?.directory=="string"&&be.directory.trim().length>0?be.directory.trim():null;Qe.getState().setCurrentSession(xe,Ne)};return window.addEventListener("aiworker:open-session",V),()=>window.removeEventListener("aiworker:open-session",V)},[]),c.useEffect(()=>{if(typeof window>"u")return;const V=()=>{Rn("desktop_open_draft_mini_chat_window",{directory:"",projectId:null})};return window.addEventListener("aiworker:open-mini-chat",V),()=>window.removeEventListener("aiworker:open-mini-chat",V)},[]),c.useEffect(()=>{if(typeof window>"u")return;const V=()=>{const ee=Qe.getState().currentSessionId;ee&&Cd(ee)};return window.addEventListener("focus",V),()=>window.removeEventListener("focus",V)},[]),c.useEffect(()=>{if(typeof window>"u")return;const V=ee=>{const be=ee.detail,xe=typeof be?.directory=="string"&&be.directory.trim().length>0?be.directory.trim():null,Ne=typeof be?.projectId=="string"&&be.projectId.trim().length>0?be.projectId.trim():null,Pe=!!(xe||Ne);De.getState().setSessionSwitcherOpen(!1),Qe.getState().openNewSessionDraft({target:Pe?"project":"chat",selectedProjectId:Pe?Ne:null,directoryOverride:Pe?xe:null,preserveDirectoryOverride:!!xe})};return window.addEventListener("aiworker:open-draft-session",V),()=>window.removeEventListener("aiworker:open-draft-session",V)},[]),c.useEffect(()=>{typeof window>"u"||!n||g||K.current||(K.current=!0,window.__aiworkerAppReady=!0,window.dispatchEvent(new Event("aiworker:app-ready")))},[n,g]),yp({enabled:Q}),d5({enabled:Q}),f5(h||null),g5(),wp(),Mp(),og();const he=c.useCallback(()=>{w(V=>!V)},[]);V3(he),t5(),r5(!G),c.useEffect(()=>{if(G)return;const V=()=>w(ee=>!ee);return window.addEventListener("aiworker:memory-debug-toggle",V),()=>window.removeEventListener("aiworker:memory-debug-toggle",V)},[G]),c.useEffect(()=>{G||u&&setTimeout(()=>d(),5e3)},[d,G,u]),c.useEffect(()=>{if(!z||T!=="not-injected")return;let V=!1,ee=0;const be=200,xe=2e3,Ne=50,Pe=()=>{if(V)return;ee++;const Se=Ga();if(Se!=="not-injected"){if(V=!0,j(Se),Se==="valid"){const ye=qa();ye&&_(Qa({isDesktopShell:!0,bootOutcome:ye}))}return}const Re=Math.min(be*Math.pow(1.1,ee),xe);if(ee>=Ne){const ye=document.getElementById("initial-loading");ye&&!ye.textContent?.includes("taking longer")&&(ye.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Pe,Re)};return window.setTimeout(Pe,be),()=>{V=!0}},[z,T]);const L=c.useCallback(async()=>{if(sf({isDesktopShell:pn(),isDesktopLocalOriginActive:Uo()})){await nf();return}window.location.reload()},[]),le=c.useCallback(async()=>{if(!F){C(!1),W(!0);try{await Ut.getState().initializeApp()}finally{W(!1)}Ut.getState().isInitialized||A(V=>V+1)}},[F]),Z=V=>{if(V.screen==="recovery")return V.variant};if(z&&I&&I.screen!=="main"){if(I.screen==="chooser")return s.jsx(Gs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(td,{mode:"first-launch",localAvailable:I.localAvailable!==!1,onCliAvailable:L,onChooseRemote:()=>{}})})})});const V=Z(I),ee=I.screen==="recovery"&&"url"in I?I.url:void 0;return s.jsx(Gs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(td,{mode:"recovery",recoveryVariant:V,recoveryHostUrl:ee,recoveryHostLabel:void 0,localAvailable:I.localAvailable!==!1,onCliAvailable:L})})})})}if(G)return s.jsx(Gs,{children:s.jsx(fl,{sdk:Qs.getSdkClient(),directory:h||"",children:s.jsx(hl,{apis:t,children:s.jsx(Ri,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(k5,{embeddedSessionChat:G,isVSCodeRuntime:m,embeddedBackgroundWorkEnabled:Q}),s.jsx(pl,{})]})})})},D)});if(ge)return s.jsx(Gs,{children:s.jsx(y5,{})});if(N&&!n&&!m&&!G)return s.jsx(Gs,{children:s.jsx(S5,{onRetry:()=>{le()},isRetrying:F})});const ue=!n&&!z;return s.jsx(Gs,{children:s.jsx(fl,{sdk:Qs.getSdkClient(),directory:h||"",children:s.jsx(hl,{apis:t,children:s.jsx(u3,{children:s.jsx(Ri,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:z?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Ud,{embeddedBackgroundWorkEnabled:Q}),s.jsx(tu,{}),s.jsx(V4,{}),s.jsx(Kd,{}),s.jsx(pl,{}),!ue&&s.jsxs(s.Fragment,{children:[s.jsx(ig,{}),s.jsx(w5,{}),p&&s.jsx(j3,{onClose:()=>w(!1)})]})]})})})})},D)})}function N5(t){return t.isAboutDialogOpen}function A5(t){return t.setAboutDialogOpen}function D5(t){return t.currentDirectory}function P5(t){return t.currentSessionId}function I5(t){return t.setCurrentSession}const T5=typeof window<"u"&&window.__AIWORKER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();vp();rf().then(()=>{Promise.all([of(),jp()]).catch(t=>{console.error("[main] settings init failed:",t)}),kp(),Cp(),Np()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Cm=document.getElementById("root");if(!Cm)throw new Error("Root element not found");Ap();Mm.createRoot(Cm).render(s.jsx(it.StrictMode,{children:s.jsx(Dp,{children:s.jsx(Pp,{children:s.jsx(Ip,{children:s.jsx(Tp,{children:s.jsx(C5,{apis:T5})})})})})}));const Y5=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{db as W,Zx as a,Q5 as b,Cb as d,Eu as g,q5 as h,Y5 as m,cb as u,Ru as v};
|