@vantran-se/openchamber-web 1.24.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -8
- package/bin/lib/commands-connect-url.js +3 -8
- package/bin/lib/commands-tunnel.js +3 -0
- package/dist/assets/{CodeMirrorCommentWidgets-B4a0JkUz.js → CodeMirrorCommentWidgets-B82Oye3V.js} +1 -1
- package/dist/assets/DiffView-DJLmWn6Z.js +4 -0
- package/dist/assets/FilesView-DjksmZRo.js +17 -0
- package/dist/assets/{GitView-Byu2DY7s.js → GitView-DiUsUIgr.js} +4 -4
- package/dist/assets/{GuestAttachDialog-B808E0-d.js → GuestAttachDialog-CYwWYLr3.js} +1 -1
- package/dist/assets/GuestSurfacePane-CmctyRI4.js +1 -0
- package/dist/assets/{JsonTreeView-VW_7czo3.js → JsonTreeView-DOHHcbgJ.js} +1 -1
- package/dist/assets/LinearIssuesView-DaqnylcV.js +1 -0
- package/dist/assets/MarkdownImageGallery-HJNvWt7L.js +1 -0
- package/dist/assets/MarkdownRendererImpl-nDZRGg2I.js +12 -0
- package/dist/assets/OnboardingScreen-C2B5Bsof.js +1 -0
- package/dist/assets/{PatchDiff-DCjGhlYV.js → PatchDiff-C4FLBjpt.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CEDZNkU2.js → PierreDiffViewer-C_1S9c9n.js} +1 -1
- package/dist/assets/PlanView-_eZvb-G5.js +5 -0
- package/dist/assets/PluginPane-sM8fcZIV.js +3 -0
- package/dist/assets/SettingsView-BRfr46hb.js +29 -0
- package/dist/assets/SettingsWindow-CcUDwQHg.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-CrN1ZGwl.js +1 -0
- package/dist/assets/ToolOutputDialog-Cij4jI09.js +15 -0
- package/dist/assets/ToolPartDiffPreview-BXzwQ-JY.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-NU0FHFhT.js → VirtualizedFileDiff-DSWTLJNH.js} +4 -4
- package/dist/assets/{WalkthroughView-BZyjhqHv.js → WalkthroughView-CpUUgY8H.js} +2 -2
- package/dist/assets/appThemeRegistry-B5tHTkR8.js +1 -0
- package/dist/assets/{commitAndPush-BDftrjr6.js → commitAndPush-D7D8qV8p.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DlWlEM3x.js → computeVirtualFileMetrics-cq9uQ30i.js} +1 -1
- package/dist/assets/de-CUO1-KqF.js +10 -0
- package/dist/assets/es-BlbC6sGJ.js +16 -0
- package/dist/assets/fr-D2nwe_0W.js +14 -0
- package/dist/assets/index-BQOoYIOu.js +1 -0
- package/dist/assets/index-CLcM8HKx.css +1 -0
- package/dist/assets/index-CvLgnuNI.js +41 -0
- package/dist/assets/{isDiffPlainText-CO4e5J_S.js → isDiffPlainText-D0obJ2p8.js} +1 -1
- package/dist/assets/{isFilePlainText-ue6kCou7.js → isFilePlainText-DB3_rjyW.js} +1 -1
- package/dist/assets/ja-CA7vnDsZ.js +16 -0
- package/dist/assets/ko-Chy6a9l-.js +16 -0
- package/dist/assets/main-B9JFK3vF.js +896 -0
- package/dist/assets/main-Bhiqnrhd.js +2 -0
- package/dist/assets/{markdownCore-CK48LG0z.js → markdownCore-tfqOFaBd.js} +4 -4
- package/dist/assets/miniChat-B0UOL5zA.js +2 -0
- package/dist/assets/mobile-BJppFIEo.js +2 -0
- package/dist/assets/{patchFileDiff-D7QVlovD.js → patchFileDiff-Db6KuwCP.js} +3 -3
- package/dist/assets/pl-CTR5A_1P.js +16 -0
- package/dist/assets/pt-BR-BE1O1KEx.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-Yz5sfoFh.js +2 -0
- package/dist/assets/renderMobileApp-QQ-yB8aY.js +25 -0
- package/dist/assets/runtimeEndpointReset-DKDdzRzm.js +27 -0
- package/dist/assets/scheduledTasksApi-C5sCuNqf.js +1 -0
- package/dist/assets/{shikiHighlight-BPu3JiQs.js → shikiHighlight-xURoo5t_.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-DWqRPo9A.js → textMateThemeFromAppTheme-BZLGuYTU.js} +1 -1
- package/dist/assets/tr-Bh5vK6cW.js +7 -0
- package/dist/assets/uk-CLDkZFy_.js +16 -0
- package/dist/assets/useAppFontEffects-BxrtCnfR.js +7337 -0
- package/dist/assets/{useInlineCommentController-CgS0fnw_.js → useInlineCommentController-CeXuR-SR.js} +2 -2
- package/dist/assets/useRootScrollLock-DgWxezc1.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-Bx2EHc1O.js → vendor-codemirror-language-data-DOuaQUZ0.js} +2 -2
- package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
- package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
- package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
- package/dist/assets/{vendor-zod-CgAdXWZO.js → vendor-zod-Gea9uBlY.js} +1 -1
- package/dist/assets/{web-components-DxX8bZ1o.js → web-components-63H1h21j.js} +2 -2
- package/dist/assets/zh-CN-DODgcmYj.js +16 -0
- package/dist/assets/zh-TW-ByNfIwLA.js +16 -0
- package/dist/index.html +13 -7
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +6 -5
- package/server/index.d.ts +1 -0
- package/server/index.js +246 -91
- package/server/lib/agent-tool/DOCUMENTATION.md +32 -15
- package/server/lib/agent-tool/runtime.js +135 -54
- package/server/lib/agent-tool/runtime.test.js +155 -87
- package/server/lib/browser-control/DOCUMENTATION.md +37 -2
- package/server/lib/browser-control/provider.js +217 -0
- package/server/lib/browser-control/provider.test.js +251 -0
- package/server/lib/context-obligatory/runtime.js +61 -50
- package/server/lib/context-obligatory/runtime.test.js +62 -162
- package/server/lib/event-stream/DOCUMENTATION.md +12 -1
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +68 -57
- package/server/lib/event-stream/directory-ws-bridge.js +1 -1
- package/server/lib/event-stream/global-hub.js +10 -1
- package/server/lib/event-stream/global-hub.test.js +27 -26
- package/server/lib/event-stream/index.js +6 -0
- package/server/lib/event-stream/protocol.js +26 -19
- package/server/lib/event-stream/protocol.test.js +18 -7
- package/server/lib/event-stream/rebind.test.js +5 -5
- package/server/lib/event-stream/runtime.test.js +17 -15
- package/server/lib/event-stream/translate-v2.js +313 -0
- package/server/lib/event-stream/translate-v2.test.js +209 -0
- package/server/lib/event-stream/upstream-reader.test.js +16 -16
- package/server/lib/fs/DOCUMENTATION.md +4 -2
- package/server/lib/fs/byte-range.js +35 -0
- package/server/lib/fs/byte-range.test.js +31 -0
- package/server/lib/fs/routes.js +47 -42
- package/server/lib/fs/routes.test.js +123 -18
- package/server/lib/git/service.js +12 -0
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/github/pr-status.js +22 -2
- package/server/lib/github/pr-status.test.js +27 -14
- package/server/lib/guests/DOCUMENTATION.md +13 -0
- package/server/lib/guests/catalog.js +12 -0
- package/server/lib/guests/catalog.test.js +33 -0
- package/server/lib/guests/routes.js +10 -1
- package/server/lib/guests/service.js +192 -14
- package/server/lib/guests/service.test.js +201 -1
- package/server/lib/guests/surface.js +630 -0
- package/server/lib/guests/surface.test.js +486 -0
- package/server/lib/markdown-image-grants/routes.js +18 -5
- package/server/lib/markdown-image-grants/routes.test.js +9 -6
- package/server/lib/message-queue/DOCUMENTATION.md +33 -22
- package/server/lib/message-queue/runtime.js +155 -100
- package/server/lib/message-queue/runtime.test.js +168 -82
- package/server/lib/notifications/DOCUMENTATION.md +28 -0
- package/server/lib/notifications/control-stream.http.test.js +68 -0
- package/server/lib/notifications/emitter-runtime.js +15 -0
- package/server/lib/notifications/emitter-runtime.test.js +32 -0
- package/server/lib/notifications/push-runtime.js +5 -1
- package/server/lib/notifications/push-runtime.test.js +2 -2
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +115 -26
- package/server/lib/notifications/template-runtime.js +13 -15
- package/server/lib/notifications/template-runtime.test.js +16 -9
- package/server/lib/notifications/trigger-runtime.test.js +187 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
- package/server/lib/openchamber-control/actions.js +3 -2
- package/server/lib/openchamber-control/error.js +1 -1
- package/server/lib/openchamber-control/file-open.js +59 -0
- package/server/lib/openchamber-control/file-open.test.js +57 -0
- package/server/lib/openchamber-control/routes.test.js +12 -0
- package/server/lib/openchamber-control/service.js +102 -49
- package/server/lib/openchamber-control/service.test.js +84 -44
- package/server/lib/openchamber-sessions/archive-store.js +224 -0
- package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
- package/server/lib/openchamber-sessions/opencode-client.js +22 -0
- package/server/lib/openchamber-sessions/routes.js +398 -328
- package/server/lib/openchamber-sessions/routes.test.js +777 -740
- package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
- package/server/lib/opencode/DOCUMENTATION.md +449 -29
- package/server/lib/opencode/agents.js +233 -327
- package/server/lib/opencode/auth.js +41 -44
- package/server/lib/opencode/auth.test.js +92 -0
- package/server/lib/opencode/cli-upgrade.d.ts +4 -0
- package/server/lib/opencode/cli-upgrade.js +18 -0
- package/server/lib/opencode/cli-upgrade.test.js +36 -0
- package/server/lib/opencode/commands.js +164 -145
- package/server/lib/opencode/compatibility.d.ts +16 -0
- package/server/lib/opencode/compatibility.js +88 -0
- package/server/lib/opencode/compatibility.test.js +62 -0
- package/server/lib/opencode/config-entity-routes.js +58 -29
- package/server/lib/opencode/config-entity-v2.test.js +290 -0
- package/server/lib/opencode/config-mutation-response.js +17 -7
- package/server/lib/opencode/config-mutation-response.test.js +4 -7
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.d.ts +183 -0
- package/server/lib/opencode/config-v2.js +801 -0
- package/server/lib/opencode/config-v2.test.js +466 -0
- package/server/lib/opencode/credential-db.js +144 -0
- package/server/lib/opencode/credential-db.test.js +104 -0
- package/server/lib/opencode/env-runtime.js +48 -9
- package/server/lib/opencode/env-runtime.test.js +45 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -5
- package/server/lib/opencode/lifecycle-process.test.js +7 -4
- package/server/lib/opencode/lifecycle.js +85 -30
- package/server/lib/opencode/lifecycle.test.js +80 -8
- package/server/lib/opencode/login-shell-env.js +27 -0
- package/server/lib/opencode/managed-config-file.js +119 -0
- package/server/lib/opencode/managed-config-file.test.js +152 -0
- package/server/lib/opencode/managed-plugin-config.js +33 -13
- package/server/lib/opencode/mcp.js +43 -149
- package/server/lib/opencode/network-runtime.js +6 -7
- package/server/lib/opencode/openchamber-routes.test.js +2 -5
- package/server/lib/opencode/plugin-routes.js +3 -3
- package/server/lib/opencode/plugin-routes.test.js +6 -24
- package/server/lib/opencode/plugins.js +91 -40
- package/server/lib/opencode/plugins.test.js +28 -15
- package/server/lib/opencode/providers.js +63 -83
- package/server/lib/opencode/providers.test.js +128 -59
- package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
- package/server/lib/opencode/proxy.js +179 -129
- package/server/lib/opencode/pwa-manifest-routes.js +4 -2
- package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
- package/server/lib/opencode/response-envelope.js +14 -0
- package/server/lib/opencode/response-envelope.test.js +23 -0
- package/server/lib/opencode/routes-upgrade.test.js +73 -116
- package/server/lib/opencode/routes.js +121 -428
- package/server/lib/opencode/server-utils-runtime.js +10 -4
- package/server/lib/opencode/session-activity.js +78 -0
- package/server/lib/opencode/session-runtime.js +21 -10
- package/server/lib/opencode/session-runtime.test.js +9 -9
- package/server/lib/opencode/settings-helpers.js +9 -9
- package/server/lib/opencode/settings-helpers.test.js +7 -12
- package/server/lib/opencode/settings-registry.json +6 -8
- package/server/lib/opencode/settings-runtime.js +18 -1
- package/server/lib/opencode/settings-runtime.test.js +31 -2
- package/server/lib/opencode/shared.js +54 -22
- package/server/lib/opencode/shared.test.js +8 -4
- package/server/lib/opencode/shutdown-runtime.js +54 -7
- package/server/lib/opencode/shutdown-runtime.test.js +224 -30
- package/server/lib/opencode/skill-routes.js +23 -24
- package/server/lib/opencode/skills.js +7 -5
- package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
- package/server/lib/opencode/upgrade-capability.test.js +1 -1
- package/server/lib/opencode/v1-migration-topup.js +288 -0
- package/server/lib/opencode/v1-migration-topup.test.js +266 -0
- package/server/lib/opencode/v2-install.d.ts +8 -0
- package/server/lib/opencode/v2-install.js +158 -0
- package/server/lib/opencode/v2-install.test.js +124 -0
- package/server/lib/opencode/watcher.js +10 -3
- package/server/lib/opencode/watcher.test.js +17 -21
- package/server/lib/opencode/websearch-config.js +66 -0
- package/server/lib/package-manager.js +55 -68
- package/server/lib/package-manager.test.js +241 -75
- package/server/lib/permission-auto-accept/runtime.js +38 -22
- package/server/lib/permission-auto-accept/runtime.test.js +39 -17
- package/server/lib/quota/DOCUMENTATION.md +4 -0
- package/server/lib/quota/providers/xai.js +4 -4
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +7 -0
- package/server/lib/routing/DOCUMENTATION.md +52 -21
- package/server/lib/routing/defaults.js +23 -6
- package/server/lib/routing/jev.js +17 -7
- package/server/lib/routing/routes.http.test.js +68 -33
- package/server/lib/routing/routes.js +65 -22
- package/server/lib/routing/runtime.js +145 -48
- package/server/lib/routing/runtime.test.js +79 -55
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
- package/server/lib/scheduled-tasks/runtime.js +81 -74
- package/server/lib/scheduled-tasks/runtime.test.js +53 -1
- package/server/lib/session-assist/DOCUMENTATION.md +8 -3
- package/server/lib/session-assist/context.js +122 -46
- package/server/lib/session-assist/context.test.js +117 -49
- package/server/lib/session-assist/runtime.js +52 -22
- package/server/lib/session-assist/runtime.test.js +145 -173
- package/server/lib/session-goal/DOCUMENTATION.md +23 -15
- package/server/lib/session-goal/create.js +9 -12
- package/server/lib/session-goal/create.test.js +27 -28
- package/server/lib/session-goal/runtime.js +164 -77
- package/server/lib/session-goal/runtime.test.js +271 -519
- package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
- package/server/lib/session-knowledge/runtime.js +59 -41
- package/server/lib/session-knowledge/runtime.test.js +90 -20
- package/server/lib/small-model/DOCUMENTATION.md +154 -208
- package/server/lib/small-model/client.js +113 -0
- package/server/lib/small-model/index.js +296 -158
- package/server/lib/small-model/index.test.js +423 -256
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/spaces/DOCUMENTATION.md +807 -0
- package/server/lib/spaces/code-in-bait.js +185 -0
- package/server/lib/spaces/code-in.js +641 -0
- package/server/lib/spaces/code-in.test.js +1048 -0
- package/server/lib/spaces/errors.js +8 -0
- package/server/lib/spaces/exec-http.js +94 -0
- package/server/lib/spaces/gatekeeper-channel.js +202 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
- package/server/lib/spaces/gatekeeper-program.cjs +914 -0
- package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
- package/server/lib/spaces/hardening.js +457 -0
- package/server/lib/spaces/hardening.test.js +368 -0
- package/server/lib/spaces/host-git.js +127 -0
- package/server/lib/spaces/host-git.test.js +137 -0
- package/server/lib/spaces/labels.js +234 -0
- package/server/lib/spaces/labels.test.js +219 -0
- package/server/lib/spaces/layout.js +184 -0
- package/server/lib/spaces/layout.test.js +30 -0
- package/server/lib/spaces/manager.js +82 -0
- package/server/lib/spaces/manager.test.js +114 -0
- package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
- package/server/lib/spaces/places/contract-suite.js +156 -0
- package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
- package/server/lib/spaces/places/contract.test.js +6 -0
- package/server/lib/spaces/places/docker-engine.js +126 -0
- package/server/lib/spaces/places/docker-live-support.js +202 -0
- package/server/lib/spaces/places/docker-tools.js +186 -0
- package/server/lib/spaces/places/docker.js +587 -0
- package/server/lib/spaces/places/docker.test.js +1610 -0
- package/server/lib/spaces/places/escape-suite.js +1018 -0
- package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
- package/server/lib/spaces/places/fake-docker.js +375 -0
- package/server/lib/spaces/places/memory-place.js +103 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
- package/server/lib/spaces/places/registry.js +43 -0
- package/server/lib/spaces/places/registry.test.js +50 -0
- package/server/lib/spaces/places/server.docker.live.test.js +225 -0
- package/server/lib/spaces/run-command.js +261 -0
- package/server/lib/spaces/run-command.test.js +396 -0
- package/server/lib/spaces/space-server.js +190 -0
- package/server/lib/spaces/space-server.test.js +335 -0
- package/server/lib/spaces/tools-filler.js +82 -0
- package/server/lib/spaces/tools-filler.test.js +148 -0
- package/server/lib/spaces/tools-pack.js +49 -0
- package/server/lib/spaces/tools-pack.test.js +57 -0
- package/server/lib/spaces/tools.js +138 -0
- package/server/lib/spaces/tools.test.js +153 -0
- package/server/lib/tts/openai-sdk.js +11 -0
- package/server/lib/tts/service.js +7 -5
- package/server/lib/tts/stt.js +3 -2
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +7 -0
- package/server/lib/tunnels/routes.test.js +55 -0
- package/server/lib/ui-auth/ui-auth.js +38 -2
- package/server/lib/ui-auth/ui-auth.test.js +42 -0
- package/server/lib/ui-auth/ui-passkeys.js +12 -10
- package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
- package/server/lib/walkthrough/pull-request.js +61 -8
- package/server/lib/walkthrough/pull-request.test.js +54 -1
- package/server/lib/walkthrough/routes.js +20 -0
- package/server/lib/walkthrough/routes.test.js +19 -0
- package/server/opencode-proxy.test.js +190 -166
- package/server/opencode-worktree-readiness.test.js +5 -4
- package/dist/assets/DiffView-B2CD9wC8.js +0 -4
- package/dist/assets/FilesView-C4vMFclc.js +0 -13
- package/dist/assets/LinearIssuesView-EzGNCGrd.js +0 -1
- package/dist/assets/MarkdownImageGallery-B2YUDFaB.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B4ikIzR3.js +0 -12
- package/dist/assets/OnboardingScreen-CQHBSTEi.js +0 -1
- package/dist/assets/PlanView-D3x-pTkZ.js +0 -5
- package/dist/assets/PluginPane-DEcgDQ9h.js +0 -3
- package/dist/assets/SettingsView-CSinuH-1.js +0 -29
- package/dist/assets/SettingsWindow-B5CHoJFZ.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-oxeACCWs.js +0 -1
- package/dist/assets/ToolOutputDialog-tLNWmfcW.js +0 -15
- package/dist/assets/ToolPartDiffPreview-CflzmK-x.js +0 -8
- package/dist/assets/appThemeRegistry-DLicw4dH.js +0 -1
- package/dist/assets/de-Bro6_zyl.js +0 -10
- package/dist/assets/es-Bb9XQZvd.js +0 -16
- package/dist/assets/fr-Dgfzn-IL.js +0 -14
- package/dist/assets/index-CtQNmqUL.js +0 -1
- package/dist/assets/index-DqaMWNrC.css +0 -1
- package/dist/assets/index-Dqc6USl3.js +0 -40
- package/dist/assets/ja-BYsakGFh.js +0 -16
- package/dist/assets/ko-BSaQz9aN.js +0 -16
- package/dist/assets/main-B62_pjL5.js +0 -2
- package/dist/assets/main-BEdcOI2P.js +0 -896
- package/dist/assets/miniChat-LT8Rqofr.js +0 -2
- package/dist/assets/mobile-CqarEynh.js +0 -2
- package/dist/assets/pl-OIviPdoj.js +0 -16
- package/dist/assets/pt-BR-Cltg-E6s.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-COyLTtZx.js +0 -2
- package/dist/assets/renderMobileApp-BC1MHg6g.js +0 -25
- package/dist/assets/runtimeEndpointReset-DdrazOVH.js +0 -25
- package/dist/assets/scheduledTasksApi-B2SWMGEU.js +0 -1
- package/dist/assets/tr-CQI-KPre.js +0 -7
- package/dist/assets/uk-CqW7R4DA.js +0 -16
- package/dist/assets/useAppFontEffects-ne84JBVL.js +0 -7333
- package/dist/assets/useRootScrollLock-Cpf1qoGp.js +0 -2
- package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
- package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
- package/dist/assets/zh-CN-CVZG_o_J.js +0 -16
- package/dist/assets/zh-TW-D5ZxzCZp.js +0 -16
- package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
- package/server/lib/routing/feature-flag.js +0 -11
- package/server/lib/small-model/call.js +0 -851
- package/server/lib/small-model/call.test.js +0 -1292
- package/server/lib/small-model/catalog.js +0 -13
- package/server/lib/small-model/resolve.js +0 -131
- package/server/lib/small-model/resolve.test.js +0 -197
- package/server/lib/small-model/runtime-providers.js +0 -164
- package/server/lib/small-model/runtime-providers.test.js +0 -118
- package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
- package/server/lib/system-prompt/runtime.js +0 -49
- package/server/lib/system-prompt/runtime.test.js +0 -76
- package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-C4vMFclc.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-Dqc6USl3.js","assets/vendor-zod-CgAdXWZO.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-DqaMWNrC.css","assets/useAppFontEffects-ne84JBVL.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-CsXYnR5c.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/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-Bq3iTZ6r.js","assets/vendor-motion-dom-DcCgeG69.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-ClYN8CzB.js","assets/vendor-tanstack-virtual-core-BewVQryB.js","assets/contextPanelEmbeddedChat-CirXEPJq.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-Bx2EHc1O.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-BuBPBC3R.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-DdrazOVH.js","assets/GuestAttachDialog-B808E0-d.js","assets/PluginPane-DEcgDQ9h.js","assets/shikiHighlight-BPu3JiQs.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-VW_7czo3.js","assets/web-components-DxX8bZ1o.js","assets/computeVirtualFileMetrics-DlWlEM3x.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/Virtualizer-CZlLSacm.js","assets/isFilePlainText-ue6kCou7.js","assets/appThemeRegistry-DLicw4dH.js","assets/textMateThemeFromAppTheme-DWqRPo9A.js","assets/Virtualizer-D_a8gKmg.js","assets/scheduledTasksApi-B2SWMGEU.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/useInlineCommentController-CgS0fnw_.js","assets/CodeMirrorCommentWidgets-B4a0JkUz.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{f as ce,r as an,j as t,R as c,c as zt,h as Oo}from"./vendor-react-BUCujlKS.js";import"./vendor-katex-CHD9BdDO.js";import{u as it,a as Wt,b as $r,d as qn,i as Be,e as ot,s as At,f as ps,h as pn,j as Bo,k as Fr,l as Lo,p as $o,m as Fo,n as xt,o as Wo,q as Jn,t as Vo,G as Yn,v as Uo,x as Xn,y as Qn,z as Zn,A as Go,B as er,M as Cs,C as Ko,D as Ho}from"./index-Dqc6USl3.js";import{u as hn,a as qo,b as We,c as Wr,d as Vr,r as gn,e as Jo,f as de,t as le,o as Yo,I as Q,B as pe,g as Xo,O as Tt,h as Y,P as Qo,i as Zo,j as ei,k as ti,l as Je,m as si,n as ht,p as ni,q as tr,s as ri,v as oi,w as bn,x as ii,y as ai,z as Se,A as li,C as Ur,D as Gr,E as Kr,F as ci,G as xn,H as ui,J as Hr,K as He,L as qr,M as di,N as fi,Q as mi,R as Jr,S as Yr,T as Xr,U as Qr,V as Zr,W as eo,X as pi,Y as hi,Z as yn,_ as gi,$ as bi,a0 as ss,a1 as Xs,a2 as xi,a3 as to,a4 as yi,a5 as $s,a6 as so,a7 as no,a8 as os,a9 as _t,aa as vi,ab as wi,ac as ji,ad as ki,ae as Si,af as vn,ag as Ni,ah as Ci,ai as Ei,aj as Ri,ak as Pi,al as Ai,am as Ti,an as Ii,ao as sr,ap as Di,aq as _i,ar as Mi,as as zi,at as Oi,au as Es,av as Bi,aw as Li,ax as ro,ay as Xe,az as $i,aA as Fi,aB as Wi,aC as Vi,aD as Ui,aE as Gi,aF as Ki,aG as oo,aH as Hi,aI as qi,aJ as Ji,aK as Yi,aL as Xi,aM as Qi,aN as Zi,aO as ea,aP as ta,aQ as sa,aR as na,aS as ra,aT as oa,aU as ia,aV as aa,aW as la,aX as ca,aY as ua,aZ as da,a_ as fa,a$ as ma,b0 as pa,b1 as ha,b2 as ga,b3 as ba,b4 as xa,b5 as ya,b6 as va,b7 as wa,b8 as ja,b9 as ka,ba as Sa,bb as Na,bc as Ca,bd as Ea}from"./useAppFontEffects-ne84JBVL.js";import{u as It,S as io,s as Ra,p as Pa,a as Aa,D as Ta,N as Ia,b as Da,r as _a,c as Ma,g as za,h as Oa,d as Ba,B as La,e as $a,f as Fa,i as Wa,j as Va,T as Ua,P as Ga,k as Ka,l as Ha,m as qa,n as Ja,A as Ya,O as Xa,C as Qa,o as Za,q as el,t as tl}from"./runtimeEndpointReset-DdrazOVH.js";import{_ as Ot}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as sl,A as nl}from"./SettingsView-CSinuH-1.js";import{PlanView as rl}from"./PlanView-D3x-pTkZ.js";import{p as ol}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as il}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as ln,s as ao,M as wn,a as _s,J as cn,p as al,_ as nr,d as ll,f as jn,V as cl,K as rr,P as ul,b as dl,c as fl,Q as ml,r as pl,U as hl,Z as gl}from"./vendor-remixicon-react-BDmGmFCA.js";import{f as kn,h as Bt,i as Sn,P as Nn,D as Cn,j as En}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as Rn,S as Pn,v as An,u as Tn}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as In}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as Dn,p as lo}from"./vendor-zustand-BAGL70zf.js";import{toast as or}from"./vendor-sonner-DFyL3AvE.js";import{C as bl,a as xl,D as yl,p as ir}from"./commitAndPush-BDftrjr6.js";import{u as vl,a as wl,b as jl,c as kl,i as Sl,f as Nl,B as Cl,C as El,P as ar}from"./patchFileDiff-D7QVlovD.js";import{u as Rl,a as Pl,i as Al,S as Tl,b as Il}from"./SubmoduleDiffSummary-oxeACCWs.js";import{P as Dl}from"./PierreDiffViewer-CEDZNkU2.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-CgAdXWZO.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Bx2EHc1O.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-B808E0-d.js";import"./PluginPane-DEcgDQ9h.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-BPu3JiQs.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./appThemeRegistry-DLicw4dH.js";import"./textMateThemeFromAppTheme-DWqRPo9A.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-strip-json-comments-5dJlOkP1.js";import"./useInlineCommentController-CgS0fnw_.js";import"./CodeMirrorCommentWidgets-B4a0JkUz.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./VirtualizedFileDiff-NU0FHFhT.js";import"./web-components-DxX8bZ1o.js";import"./computeVirtualFileMetrics-DlWlEM3x.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isDiffPlainText-CO4e5J_S.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";let co=null,lr=!1;const _l=new Promise(n=>{co=n});function Ml(){lr||(lr=!0,co?.())}const zl=6,Ol=n=>n.parentID??null,cr=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Bl=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Ll=(n,e)=>{if(!n)return"";let s=null,o=-1;for(const r of e){const i=Bl(r.path);(n===i||n.startsWith(`${i}/`))&&i.length>o&&(s=r,o=i.length)}return s?s.label?.trim()||cr(s.path):cr(n)},$l=()=>{const n=hn.getState().activeSessions,e=qo.getState().index.session.unseenCount,s=it.getState().notifyOnSubtasks,o=We.getState().projects,r=Wr.getState().ids,i=Vr.getState().rankById;let a=0;const u=[];for(const f of n){const l=Ol(f)!==null,b=(e[f.id]??0)>0&&(!l||s);b&&(a+=1),l||u.push({session:f,unread:b,project:Ll(gn(f),o)})}u.sort((f,l)=>Jo(f.session,l.session,r,i));const d=u.slice(0,zl).map(({session:f,unread:l,project:p})=>({id:f.id,title:f.title??"",unread:l,project:p}));return{runtimeKey:Wt(),attentionCount:a,recentSessions:d}},Fl="__OPENCHAMBER_WIDGET_SNAPSHOT__",Wl=()=>{typeof window>"u"||(window[Fl]=()=>{try{return JSON.stringify($l())}catch{return null}})},Qs="mobile-app-update-available",ur="mobile-app-update-toast-dismissed-version",Vl=()=>{const n=ce.c(8),{t:e}=de(),s=It(Ul),o=It(Gl),r=It(Kl),i=It(Hl);let a;n[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,n[0]=a):a=n[0];const u=an.useRef(a);let d,f;return n[1]!==s||n[2]!==i||n[3]!==o||n[4]!==e||n[5]!==r?(d=()=>{if($r()!=="android"||o!=="mobile"||!s||!r||!i){le.dismiss(Qs);return}qn().getItem(ur)!==r&&(u.current.has(r)||(u.current.add(r),le.info(e("mobileUpdate.toast.available.title"),{id:Qs,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(Q,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Yo(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{qn().setItem(ur,r),le.dismiss(Qs)}}})))},f=[s,i,o,e,r],n[1]=s,n[2]=i,n[3]=o,n[4]=e,n[5]=r,n[6]=d,n[7]=f):(d=n[6],f=n[7]),an.useEffect(d,f),null};function Ul(n){return n.available}function Gl(n){return n.runtimeType}function Kl(n){return n.info?.version}function Hl(n){return n.info?.downloadUrl}const dr=300,ql="openchamber.mobile.connectLog.v1",Dt=[];if(typeof window<"u")try{window.localStorage.removeItem(ql)}catch{}const _n=(n,e)=>{Dt.push({at:Date.now(),step:n,detail:e}),Dt.length>dr&&Dt.splice(0,Dt.length-dr)};typeof window<"u"&&_n("app:launch","{}");const Jl=()=>[...Dt],Yl=n=>{const e=new Date(n),s=(o,r=2)=>String(o).padStart(r,"0");return`${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}.${s(e.getMilliseconds(),3)}`},uo=n=>`${Yl(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Xl=()=>Dt.map(uo).join(`
|
|
3
|
-
`),fo=(n,e)=>{const s=ce.c(10),o=700,r=c.useRef(null),i=c.useRef(null),a=c.useRef(!1);let u;s[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,i.current=null},s[0]=u):u=s[0];const d=u;let f,l;s[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>d,l=[d],s[1]=f,s[2]=l):(f=s[1],l=s[2]),c.useEffect(f,l);let p;s[3]!==o||s[4]!==n?(p=N=>{a.current=!1,i.current={x:N.clientX,y:N.clientY},r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,a.current=!0,n()},o)},s[3]=o,s[4]=n,s[5]=p):p=s[5];const b=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=N=>{const C=i.current;C&&(Math.abs(N.clientX-C.x)>10||Math.abs(N.clientY-C.y)>10)&&d()},s[6]=h):h=s[6];const v=h;let S;s[7]===Symbol.for("react.memo_cache_sentinel")?(S=N=>{a.current&&(a.current=!1,N.preventDefault(),N.stopPropagation())},s[7]=S):S=s[7];const w=S;let T;return s[8]!==b?(T={onPointerDown:b,onPointerMove:v,onPointerUp:d,onPointerCancel:d,onClickCapture:w},s[8]=b,s[9]=T):T=s[9],T},Ms="openchamber.mobile.connections.v1",Ql="openchamber.mobile.",fr="openchamber.mobile.deviceId",Zl=()=>{try{const n=window.localStorage.getItem(fr);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(fr,e),e}catch{return crypto.randomUUID()}},mr=()=>`mobile:${Zl()}`,pr=()=>{try{const n=il.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},mo=12,po=8e3,ec=2500,tc=3e3,zs=2500,sc=()=>{let n=0;return{begin:()=>(n+=1,n),cancel:()=>{n+=1},isCurrent:e=>e===n}},Vt=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,o=new URL(s);return o.hash="",o.search="",o.pathname=o.pathname.replace(/\/+$/,""),o.toString().replace(/\/+$/,"")},Ts=n=>{try{return new URL(n).host}catch{return n}},Lt=n=>{try{return Vt(n)}catch{return n.trim().replace(/\/+$/g,"")}},ho=(n,e)=>Lt(n)===Lt(e),go=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,nc=n=>`relay://${n.serverId}`,Fs=n=>n.candidates.filter(e=>e.kind==="direct"),yt=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},at=n=>{const e=Fs(n)[0];if(e)return e.url;const s=yt(n);return s?nc(s):""},De=n=>{const e=yt(n);if(e)return go(e);const s=Fs(n)[0];return s?Lt(s.url):""},Os=(n,e)=>{const s=n.find(i=>i.kind==="relay"),o=s&&s.kind==="relay"?s.relay.serverId:null,r=new Set(n.filter(i=>i.kind==="direct").map(i=>Lt(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has(Lt(i.url)))},Mn=n=>{const e=(()=>{try{return Vt(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},hr=n=>{if(n.candidates&&n.candidates.length>0)return n.candidates;const e=[];return typeof n.url=="string"&&n.url.trim()&&!/^relay:\/\//i.test(n.url.trim())&&e.push(...Mn(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},zn=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;const e=n;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const s=e.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const o=s;return o.kty!=="EC"||o.crv!=="P-256"||typeof o.x!="string"||!o.x||typeof o.y!="string"||!o.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:o.x,y:o.y}}},bo=n=>{try{return JSON.stringify(n)}catch{return String(n)}},ge=(n,e={})=>{const s=bo(e);console.info("[mobile-connect]",n,s),_n(n,s)},ns=(n,e={})=>{ge(n,e)},$t=(n,e={})=>{const s=bo(e);console.info("[mobile-storage]",n,s),_n(n,s)},rc=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},oc=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},ic=async(n,e)=>{if(!Be())return null;try{const{CapacitorHttp:s}=await Ot(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=Lo(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(o.entries()),data:oc(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>rc(r.data)}}catch(s){return ge("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},ac=async(n,e)=>{const s=await fetch(n,e).catch(o=>(ge("browser-fetch:failed",{url:n,error:o instanceof Error?o.message:String(o)}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},ut=async(n,e,s)=>{let o;const r=new Promise(i=>{o=window.setTimeout(()=>{s?.(),i(null)},n)});try{return await Promise.race([e,r])}catch{return null}finally{o!==void 0&&window.clearTimeout(o)}},vt=async(n,e,s)=>{const o=s?.totalTimeoutMs??po,r=Date.now(),i=await ut(Math.min(ec,o),ic(n,e));if(i)return i;const a=new AbortController,u=Math.max(500,o-(Date.now()-r));return ut(u,ac(n,{...e,signal:a.signal}),()=>a.abort())},Ws=async n=>{if(!n)return null;const e=await n.json().catch(()=>null);if(!e||typeof e!="object")return null;const s=e;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},Ft=15e3,lc=async(n,e,s,o=Ft,r)=>{const i=Fr({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),a=u=>u==="ok"&&r?.keepTunnel?{outcome:u,tunnel:i}:(i.close(),{outcome:u});try{const u=e?{Authorization:`Bearer ${e}`}:void 0,d=await ut(o,i.fetch("/auth/session",{headers:u}).catch(()=>null));if(ge("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!e}),!d)return a("unreachable");if(d.status===401)return a(e?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return a("auth-failed");const f=await Ws(d);return f&&f.disabled!==!0&&f.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(u){throw i.close(),u}},cc=(n,e,s,o,r)=>{const i=typeof window<"u"?window.location.origin:"",a={relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk,...s?{grant:s}:{}};r&&Bo(a,r),At({apiBaseUrl:i,clientToken:e,runtimeKey:o??go(n),relay:a})},uc=n=>{if(!n||typeof n!="object")return null;const e=n;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const s=zn(e.relay);return s?{kind:"relay",relay:s}:null}return null},dc=n=>{if(n.mode==="relay"){const e=zn(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?Mn(n.url):[]},jt=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(Ms)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=Be();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const o=s;if(typeof o.id!="string")return[];const r=Array.isArray(o.candidates)?o.candidates.map(uc).filter(d=>!!d):dc(o);if(r.length===0)return[];const i=typeof o.clientToken=="string"&&o.clientToken.trim()?o.clientToken:void 0,a=typeof o.label=="string"&&o.label.trim()?o.label:Ts(at({candidates:r})),u={id:o.id,label:a,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...u,hasToken:!!o.hasToken||!!i}]:[{...u,clientToken:i,hasToken:!!i}]}).sort((s,o)=>o.lastUsedAt-s.lastUsedAt)},un=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},On=n=>{if(typeof window>"u")return;const e=Be(),s=n.slice(0,mo).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(un),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(Ms,JSON.stringify(s))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},xo=(n,e)=>{const s=n.find(i=>e.id&&i.id===e.id||Os(i.candidates,e.candidates)),o=Be(),r={id:e.id||s?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...o?{hasToken:e.hasToken??(!!e.clientToken||s?.hasToken||!1)}:{clientToken:e.clientToken??s?.clientToken,hasToken:!!(e.clientToken??s?.clientToken)}};return[r,...n.filter(i=>i.id!==r.id&&!Os(i.candidates,e.candidates))].slice(0,mo)},Bn=ol,fc=0,Ln=n=>`${Ql}token.${encodeURIComponent(n)}`,mc=async(n,e)=>{let s;const o=new Promise(r=>{s=window.setTimeout(()=>r(e),tc)});try{return await Promise.race([n.catch(()=>e),o])}finally{s!==void 0&&window.clearTimeout(s)}},$n=async(n,e,s)=>Be()?mc(e().catch(o=>(console.warn(`[mobile-storage] ${n} failed`,o),s)),s):s,hs=async n=>{$t("secure:read-start",{key:n});const e=await $n("secure:read",async()=>(await Bn.internalGetItem({prefixedKey:Ln(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return $t("secure:read",{key:n,hasToken:!!s}),s},gt=async(n,e)=>{$t("secure:write-start",{key:n});const s=await $n("secure:write",async()=>(await Bn.internalSetItem({prefixedKey:Ln(n),data:e,sync:!1,access:fc}),!0),!1);return $t("secure:write",{key:n,ok:s}),s},pc=async n=>{await $n("secure:delete",async()=>(await Bn.internalRemoveItem({prefixedKey:Ln(n),sync:!1}),!0),!1)},hc=async(n,e)=>{let s=0,o=0;return{records:await Promise.all(n.map(async i=>{if(!i||typeof i!="object")return i;const a=i,u=typeof a.url=="string"?a.url:null,d=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!u||!d)return i;if(!await e(u,d))return o+=1,i;s+=1;const{clientToken:f,...l}=a;return{...l,hasToken:!0}})),migrated:s,failed:o}},yo=async()=>{if(typeof window>"u"||!Be())return;let n;try{n=JSON.parse(window.localStorage.getItem(Ms)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(o=>!!o&&typeof o=="object"&&typeof o.url=="string"&&typeof o.clientToken=="string"&&!!o.clientToken.trim());if(e.length===0)return;$t("secure:migrate-start",{count:e.length});const s=await hc(n,async(o,r)=>{const i=Lt(o);return await gt(i,r)?await hs(i)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(Ms,JSON.stringify(s.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}$t("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},gc=async()=>(await yo(),jt()),Bs=async n=>{const e=xo(jt(),n);return On(e),Be()&&n.clientToken&&await gt(De({candidates:n.candidates}),n.clientToken),e},bc=async n=>{const e=jt(),s=e.find(r=>r.id===n)??null,o=e.filter(r=>r.id!==n);return On(o),s&&Be()&&await pc(De(s)),o},xc=1500,Ls=async(n,e,s)=>{const o=s?.fast?{totalTimeoutMs:zs}:void 0,r=yt({candidates:n})?.serverId??null,i=n.find(f=>f.kind==="relay")??null,a=n.filter(f=>f.kind==="direct"),u=async()=>{for(const f of a){const l=Vt(f.url)||f.url,p=e?{Authorization:`Bearer ${e}`}:void 0,b=await vt(`${l}/health`,{method:"GET"},o);if(ge("probe:direct:health",{url:l,ok:b?.ok===!0,status:b?.status??null,source:b?.source??null}),!b?.ok)continue;if(r){const w=await b.json().catch(()=>null),T=w&&typeof w=="object"?w.serverId:null;if(typeof T=="string"&&T&&T!==r){ge("probe:server-id-mismatch",{url:l});continue}}const h=await vt(`${l}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(ge("probe:direct:session",{url:l,ok:h?.ok===!0,status:h?.status??null,source:h?.source??null,hasToken:!!e}),h?.status===401)return{status:"needs-login"};if(!h||!h.ok&&h.status!==404)continue;const v=await Ws(h);if(v&&v.disabled!==!0&&v.authenticated===!1)return{status:"needs-login"};const S=v?.disabled===!0;return!e&&Be()&&!S&&v?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:l}}}return{status:"unreachable"}},d=async()=>{if(!i)return{status:"unreachable"};const{outcome:f,tunnel:l}=await lc(i.relay,e,void 0,s?.fast?zs:po,{keepTunnel:!0});return f==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:l}}:f==="needs-login"||f==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?a.length===0?d():new Promise(f=>{let l=!1,p=!1,b,h=null,v=null;const S=N=>{N?.status==="ok"&&N.transport.kind==="relay"&&N.transport.tunnel?.close()},w=N=>{l||(l=!0,f(N))},T=()=>{p||l||(b!==void 0&&(window.clearTimeout(b),b=void 0),d().then(N=>{if(v=N,l||p){S(N);return}if(N.status==="ok"||N.status==="needs-login"){w(N);return}h&&w(h)}))};u().then(N=>{if(h=N,!l){if(N.status==="ok"||N.status==="needs-login"){p=!0,b!==void 0&&window.clearTimeout(b),S(v),w(N);return}if(v){w(v);return}T()}}),b=window.setTimeout(T,xc)}):u()},bt=(n,e,s)=>{n.kind==="relay"?cc(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):At({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),wo()},is=()=>{const n=jt()[0];return n?.label?.trim()?n.label:null},rs=async n=>{const e=n?.fast!==!1;await yo();const s=jt()[0];if(ge("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let o;if(Be()){if(s.hasToken&&(o=await hs(De(s)),!o))return{status:"no-candidate"}}else if(o=s.clientToken,!o&&s.hasToken)return{status:"no-candidate"};const r=await Ls(s.candidates,o,{fast:e});return ge("auto-connect:probe",{status:r.status,candidates:s.candidates.map(i=>i.kind)}),r.status==="needs-login"?{status:"needs-login",label:s.label}:r.status!=="ok"?{status:"unreachable",label:s.label}:n?.skipIfConnected&&ot()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),ge("auto-connect:superseded",{}),{status:"no-candidate"}):(await Bs({id:s.id,label:s.label,candidates:s.candidates}),bt(r.transport,o??null,{runtimeKey:De(s)}),{status:"connected"})},yc=async(n,e)=>{let s="";try{s=Vt(n.url)}catch{return!1}if(!s)return!1;const o=n.clientToken?.trim()||void 0,r=o?{Authorization:`Bearer ${o}`}:void 0,i=e?.fast?{totalTimeoutMs:zs}:void 0;if(!(await vt(`${s}/health`,{method:"GET",headers:r},i))?.ok)return!1;const u=await vt(`${s}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!u||!u.ok&&u.status!==404)return!1;const d=await Ws(u);return!(d&&d.disabled!==!0&&d.authenticated===!1)},vc=n=>[...n].sort((e,s)=>{const o=(e.priority??100)-(s.priority??100);if(o!==0)return o;const r=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return r(e)-r(s)}).flatMap(e=>{if(e.type==="relay"){const s=zn({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Mn(e.url)}),gr=async n=>{const e=yt({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const i=Fr(s.relay),a=await ut(Ft,i.fetch("/health").catch(()=>null));if(ge("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:s.relay,tunnel:i};i.close();continue}const o=Vt(s.url)||s.url,r=await vt(`${o}/health`,{method:"GET"});if(ge("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const i=await r.json().catch(()=>null),a=i&&typeof i=="object"?i.serverId:null;if(typeof a=="string"&&a&&a!==e){ge("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},wc=async(n,e)=>{if(!ps())return yc(n,e);const s=await ut(e?.fast?zs:Ft,pn("/auth/session").then(r=>r).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const o=await Ws(s);return!(o&&o.disabled!==!0&&o.authenticated===!1)},jc=n=>n.kind==="relay"?ps():!ps()&&ho(n.url,ot()),vo=()=>{const n=Wt();return n?jt().find(e=>De(e)===n)??null:null},br=n=>{const e=Wt();return!!e&&De(n)===e},Is=async n=>{const e=n?.fast!==!1,s=vo();if(!s)return ge("reprobe:no-connection",{runtimeKey:!!Wt()}),"no-connection";let o;if(Be()?o=s.hasToken?await hs(De(s)):void 0:o=s.clientToken,!o&&s.hasToken)return ge("reprobe:no-token",{hasToken:!0}),"unreachable";ge("reprobe:start",{candidates:s.candidates.map(f=>f.kind),fast:e,hasToken:!!o});const r=s.candidates.findIndex(f=>jc(f.kind==="relay"?{kind:"relay",relay:f.relay}:{kind:"direct",url:f.url})),i=r>=0?s.candidates.slice(0,r):s.candidates,a=await Ls(i,o,{fast:e});if(ge("reprobe:better",{status:a.status,probed:i.length}),a.status==="ok")return await Bs({id:s.id,label:s.label,candidates:s.candidates}),bt(a.transport,o??null,{runtimeKey:De(s)}),"switched";if(a.status==="needs-login")return"needs-login";if(r>=0){const f=await wc({url:ot(),clientToken:o},{fast:e});if(ge("reprobe:current",{stillValid:f}),f)return wo(),"unchanged"}const u=r>=0?s.candidates.slice(r+1):[],d=await Ls(u,o,{fast:e});return ge("reprobe:fallback",{status:d.status,probed:u.length}),d.status==="ok"?(await Bs({id:s.id,label:s.label,candidates:s.candidates}),bt(d.transport,o??null,{runtimeKey:De(s)}),"switched"):d.status==="needs-login"?"needs-login":"unreachable"},kc=5e3;let Zs=!1;const Sc=async()=>{if(Zs)return"skipped";const n=vo();if(!n)return ge("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=yt(n);if(!e)return ge("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";Zs=!0;try{const s=await ut(Ft,pn("/api/client-auth/connection/candidates").then(f=>f).catch(()=>null));if(!s?.ok)return ge("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const o=await s.json().catch(()=>null);if(!o||o.serverId!==e.serverId)return ge("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(o.candidates)?o.candidates:[],i=[];for(const f of r){if(!f||typeof f!="object")continue;const l=f;if(!(l.type!=="lan"||typeof l.url!="string"))try{const p=Vt(l.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return ge("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=Fs(n).filter(f=>f.url.startsWith("https://")),u=[...i.map(f=>({kind:"direct",url:f})),...a,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(un))===JSON.stringify(u.map(un))?"unchanged":(ge("candidates:refreshed",{lanCount:i.length}),await Bs({id:n.id,label:n.label,candidates:u}),"updated")}finally{Zs=!1}},wo=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await Sc().catch(()=>"skipped");ge("candidates:refresh-result",{result:n}),n==="updated"&&ps()&&await Is().catch(()=>null)})()},kc)},jo=n=>{const{t:e}=de(),[s,o]=c.useState(()=>jt()),[r,i]=c.useState(null),[a,u]=c.useState(null),[d,f]=c.useState(null),l=c.useRef(s),p=c.useRef(null),b=c.useRef(sc()),h=c.useCallback(k=>{l.current=k,o(k)},[]),v=c.useCallback(k=>{p.current=k,i(k)},[]),S=c.useCallback(k=>{p.current===k&&(p.current=null,i(null))},[]);c.useEffect(()=>{let k=!1;return gc().then(E=>{k||h(E)}),()=>{k=!0}},[h]);const w=c.useCallback(k=>{const E=xo(l.current,k);return h(E),On(E),E},[h]),T=c.useCallback(async k=>{u(null),v("connect");try{const E=hr(k);if(E.length===0){u(e("mobile.connect.error.urlRequired"));return}const y=k.id?l.current.find(K=>K.id===k.id):l.current.find(K=>Os(K.candidates,E)),z=k.label?.trim()||y?.label||Ts(at({candidates:E})),M=k.relayGrant;let R=k.clientToken?.trim()||void 0;const x=!!R;R||(Be()?y?.hasToken&&(R=await hs(De({candidates:E}))):R=y?.clientToken),ge("connect:start",{candidates:E.map(K=>K.kind),hasToken:!!R});const D=await Ls(E,R);if(ge("connect:probe",{status:D.status}),D.status==="unreachable"){u(e("mobile.connect.error.unreachable"));return}if(D.status==="needs-login"){w({id:y?.id,label:z,candidates:E}),f({id:y?.id??crypto.randomUUID(),label:z,candidates:E,relay:yt({candidates:E})??void 0,relayGrant:M});return}R&&x&&Be()&&await gt(De({candidates:E}),R),w({id:y?.id,label:z,candidates:E,clientToken:R}),bt(D.transport,R??null,{runtimeKey:De({candidates:E}),grant:M}),n()}catch(E){console.warn("[mobile-connect] connect threw",E),u(e("mobile.connect.error.invalidUrl"))}finally{S("connect")}},[v,S,n,w,e]),N=c.useCallback(async k=>{if(p.current==="pairing")return;u(null),v("pairing");const E=vc(k.candidates);let y=null,z=!1;try{if(y=await gr(E),!y){u(e("mobile.connect.error.unreachable"));return}const M=JSON.stringify({pairingId:k.pairingId,secret:k.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:pr(),dedupeKey:mr()}),R={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:M},x=y.kind==="relay"?await ut(Ft,y.tunnel.fetch("/api/client-auth/pairing/redeem",R).catch(()=>null)):await vt(`${y.url}/api/client-auth/pairing/redeem`,R);if(!x?.ok){u(e("mobile.connect.error.authRequired"));return}const D=await x.json().catch(()=>null),K=typeof D?.clientToken=="string"?D.clientToken.trim():"";if(!K){u(e("mobile.connect.error.authRequired"));return}const g=typeof D?.server?.label=="string"?D.server.label:"",L=k.label||g||Ts(at({candidates:E}));if(Be()&&!await gt(De({candidates:E}),K)){u(e("mobile.connect.error.authRequired"));return}w({label:L,candidates:E,clientToken:K}),bt(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},K,{runtimeKey:De({candidates:E})}),z=y.kind==="relay",n()}catch(M){console.warn("[mobile-connect] pairing threw",M),u(e("mobile.connect.error.authRequired"))}finally{!z&&y?.kind==="relay"&&y.tunnel.close(),S("pairing")}},[v,S,n,w,e]),C=c.useCallback(async k=>{if(!d||!k.trim()||p.current==="password")return;u(null),v("password");const E=b.current.begin(),y=()=>b.current.isCurrent(E),{id:z,label:M,candidates:R}=d;let x=null,D=!1;try{if(x=await gr(R),!y())return;if(!x){u(e("mobile.connect.error.unreachable"));return}const K={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:k,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:pr(),dedupeKey:mr()})};ge("password:start",{transport:x.kind});const g=x.kind==="relay"?await ut(Ft,x.tunnel.fetch("/auth/session",K).catch(()=>null)):await vt(`${x.url}/auth/session`,K);if(!y())return;if(ge("password:done",{ok:g?.ok===!0,status:g?.status??null}),!g?.ok){u(e("mobile.connect.error.passwordFailed"));return}const L=await g.json().catch(()=>null);if(!y())return;const F=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(ge("password:token",{issued:!!F}),!F){if(x.kind==="direct"&&!Be()){w({id:z,label:M,candidates:R}),f(null),bt({kind:"direct",url:x.url},null,{runtimeKey:De({candidates:R})}),n();return}u(e("mobile.connect.error.authRequired"));return}if(Be()&&(!y()||(await gt(De({candidates:R}),F),!y()))||!y()||(w({id:z,label:M,candidates:R,clientToken:F}),f(null),bt(x.kind==="relay"?{kind:"relay",relay:x.relay,tunnel:x.tunnel}:{kind:"direct",url:x.url},F,{runtimeKey:De({candidates:R})}),D=x.kind==="relay",!y()))return;n()}catch(K){if(!y())return;console.warn("[mobile-connect] password threw",K),u(e("mobile.connect.error.passwordFailed"))}finally{!D&&x?.kind==="relay"&&x.tunnel.close(),y()&&S("password")}},[v,S,n,d,w,e]),I=c.useCallback(()=>{b.current.cancel(),S("password"),f(null),u(null)},[S]),j=c.useCallback(async k=>{u(null);let E=hr(k);const y=k.id?l.current.find(x=>x.id===k.id)??null:null;if(y){const x=E.filter(g=>g.kind==="direct"),D=Fs(y).filter(g=>g.url.startsWith("https://")&&!x.some(L=>ho(L.url,g.url))),K=yt(y);E=[...x,...D,...K?[{kind:"relay",relay:K}]:[]]}if(E.length===0)return u(e("mobile.connect.error.urlRequired")),null;const z=k.clientToken?.trim()||void 0,M=k.label?.trim()||Ts(at({candidates:E}));if(Be()){const x=De({candidates:E});if(z)await gt(x,z);else if(y?.hasToken){const D=De(y);if(D&&x&&D!==x){const K=await hs(D);K&&await gt(x,K)}}}return w({id:k.id,label:M,candidates:E,clientToken:z}).find(x=>Os(x.candidates,E))??null},[w,e]),P=c.useCallback(async k=>{const E=l.current.find(z=>z.id===k)??null,y=await bc(k);return h(y),E},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:d,connect:T,redeemPairingConnection:N,submitPassword:C,cancelPassword:I,saveConnection:j,removeConnection:P,setError:u}},ko=n=>{const e=ce.c(31),{onClose:s}=n,{t:o}=de(),[r,i]=c.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Jl(),e[0]=a):a=e[0];const u=a;let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{Xo(Xl()).then(k=>{k.ok&&(i(!0),window.setTimeout(()=>i(!1),2e3))})},e[1]=d):d=e[1];const f=d;let l;e[2]!==o?(l=o("mobile.connectionDebug.title"),e[2]=o,e[3]=l):l=e[3];let p;e[4]!==l?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:l}),e[4]=l,e[5]=p):p=e[5];const b=r?"check":"file-copy";let h;e[6]!==b?(h=t.jsx(Q,{name:b,className:"size-4"}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r||e[9]!==o?(v=o(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=o,e[10]=v):v=e[10];let S;e[11]!==h||e[12]!==v?(S=t.jsxs(pe,{type:"button",variant:"outline",size:"sm",onClick:f,disabled:u.length===0,children:[h,v]}),e[11]=h,e[12]=v,e[13]=S):S=e[13];let w;e[14]!==o?(w=o("mobile.connectionDebug.close"),e[14]=o,e[15]=w):w=e[15];let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Q,{name:"close",className:"size-[18px]"}),e[16]=T):T=e[16];let N;e[17]!==s||e[18]!==w?(N=t.jsx(pe,{type:"button",variant:"ghost",size:"icon","aria-label":w,onClick:s,children:T}),e[17]=s,e[18]=w,e[19]=N):N=e[19];let C;e[20]!==N||e[21]!==S?(C=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[S,N]}),e[20]=N,e[21]=S,e[22]=C):C=e[22];let I;e[23]!==C||e[24]!==p?(I=t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-4 py-2.5",children:[p,C]}),e[23]=C,e[24]=p,e[25]=I):I=e[25];let j;e[26]!==o?(j=t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-3",children:u.length===0?t.jsx("p",{className:"typography-small text-muted-foreground",children:o("mobile.connectionDebug.empty")}):t.jsx("pre",{className:"whitespace-pre-wrap break-words typography-code text-muted-foreground",children:u.map(uo).join(`
|
|
4
|
-
`)})}),e[26]=o,e[27]=j):j=e[27];let P;return e[28]!==I||e[29]!==j?(P=t.jsxs("div",{className:"fixed inset-0 z-[70] flex flex-col bg-background pb-[var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))] pt-[var(--safe-area-inset-top,env(safe-area-inset-top,0px))] text-foreground",children:[I,j]}),e[28]=I,e[29]=j,e[30]=P):P=e[30],P},So=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},Nc=()=>window.Capacitor?.getPlatform?.()==="android",No=n=>{const e=n.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const s=$o(e);return s?{pairing:s}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Co=(n,e)=>{const s=No(n);if(!s&&e?.pairingStringFallback){const o=Fo(n);if(o)return{status:"pairing",pairing:o}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Cc=async(n,e)=>{if(!n.startScan||!n.stopScan||!n.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let s,o,r=!1,i=()=>{};const a=new Promise(f=>{i=f}),u=f=>{r||(r=!0,i(f))},d=()=>u({status:"cancelled"});e?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:l})=>{const p=l?.[0],b=(p?.rawValue??p?.displayValue??"").trim();b&&u(Co(b,{pairingStringFallback:!0}))})).then(l=>{s=l}),Promise.resolve(n.addListener("scanError",()=>u({status:"failed"}))).then(l=>{o=l})])).some(({status:l})=>l==="rejected")?u({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>u({status:"failed"})),await a}finally{e?.removeEventListener("abort",d),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(o?.remove()),n.stopScan()])}},dn=()=>So()!==null,Eo=async n=>{const e=So();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const a=(await e.requestPermissions())?.camera;if(a&&a!=="granted"&&a!=="limited")return{status:"permission-denied"}}if(n?.signal?.aborted)return{status:"cancelled"};if(Nc())return Cc(e,n?.signal);if(!e.scan)return{status:"unsupported"};const o=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(o?.rawValue??o?.displayValue??"").trim();return r?Co(r):{status:"cancelled"}}catch{return{status:"failed"}}},Mt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},as="oc-surface-elevated h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-interactive-border-focus focus:ring-2 focus:ring-ring",Ro=n=>{const e=ce.c(22),{onCancel:s}=n,{t:o}=de(),r=c.useRef(null);let i,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const T={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},N={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const C=new Map,I=P=>{!(P instanceof HTMLElement)||P===r.current||C.has(P)||(C.set(P,{opacity:P.style.opacity,pointerEvents:P.style.pointerEvents}),P.style.setProperty("opacity","0"),P.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(I);const j=new MutationObserver(P=>{P.forEach(k=>k.addedNodes.forEach(I))});return j.observe(document.body,{childList:!0}),()=>{j.disconnect(),C.forEach(Ec),T.value?document.documentElement.style.setProperty("background-color",T.value,T.priority):document.documentElement.style.removeProperty("background-color"),N.value?document.body.style.setProperty("background-color",N.value,N.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),c.useLayoutEffect(i,a);let u,d;e[2]!==s?(u=()=>{const T=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},d=[s],e[2]=s,e[3]=u,e[4]=d):(u=e[3],d=e[4]),c.useEffect(u,d);let f;e[5]!==o?(f=o("mobile.connect.scanQr"),e[5]=o,e[6]=f):f=e[6];let l;e[7]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=l):l=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,e[9]=p):p=e[9];let b;e[10]!==p?(b=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[l,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=b):b=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(Q,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let v;e[13]!==o?(v=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=v):v=e[14];let S;e[15]!==s||e[16]!==v?(S=t.jsxs(pe,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,v]}),e[15]=s,e[16]=v,e[17]=S):S=e[17];let w;return e[18]!==S||e[19]!==f||e[20]!==b?(w=zt.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":f,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[b,S]}),document.body),e[18]=S,e[19]=f,e[20]=b,e[21]=w):w=e[21],w},Po=()=>{const n=ce.c(6),{t:e}=de();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(Tt,{width:96,height:96,isAnimated:!0}),n[0]=s):s=n[0];let o;n[1]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(Q,{name:"loader-4",className:"size-[18px] animate-spin"}),n[1]=o):o=n[1];let r;n[2]!==e?(r=e("mobile.connect.connecting"),n[2]=e,n[3]=r):r=n[3];let i;return n[4]!==r?(i=zt.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[s,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[o,t.jsx("span",{children:r})]})]}),document.body),n[4]=r,n[5]=i):i=n[5],i};function Ec(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const Rc=({onConnected:n,notice:e=null})=>{const{t:s}=de(),o=jo(n),{connections:r,isBusy:i,isPasswordBusy:a,error:u,pendingConnection:d}=o,[f,l]=c.useState(""),[p,b]=c.useState(""),[h,v]=c.useState(""),[S,w]=c.useState(!1),[T,N]=c.useState(!1),C=c.useRef(null),I=c.useMemo(()=>dn(),[]),[j,P]=c.useState(()=>!dn()),[k,E]=c.useState(null),[y,z]=c.useState(""),[M,R]=c.useState(!1),x=fo(c.useCallback(()=>R(!0),[])),D=c.useCallback(B=>{B.preventDefault(),o.connect({url:f,clientToken:h,label:p})},[h,o,p,f]),K=c.useCallback(B=>{if(/^openchamber:\/\//i.test(B.trim())){const W=No(B);if(W){if("pairing"in W){o.redeemPairingConnection(W.pairing);return}l(W.url),W.label&&b(W.label),W.clientToken&&v(W.clientToken);return}}l(B)},[o]),g=c.useCallback(async()=>{if(C.current||i)return;o.setError(null),w(!0);const B=new AbortController;C.current=B;try{const W=await Eo({signal:B.signal});switch(C.current===B&&(C.current=null,w(!1)),W.status){case"ok":N(!0),l(W.url),W.label&&b(W.label),W.clientToken&&v(W.clientToken),await o.connect({url:W.url,clientToken:W.clientToken,label:W.label});break;case"pairing":N(!0),await o.redeemPairingConnection(W.pairing);break;case"permission-denied":o.setError(s("mobile.connect.scan.permissionDenied"));break;case"invalid":o.setError(s("mobile.connect.scan.invalid"));break;case"unsupported":o.setError(s("mobile.connect.scan.unsupported"));break;case"failed":o.setError(s("mobile.connect.scan.failed"));break;default:break}}finally{N(!1),C.current===B&&(C.current=null,w(!1))}},[o,i,s]);c.useEffect(()=>()=>C.current?.abort(),[]);const L=c.useCallback(B=>{B.preventDefault(),o.submitPassword(y)},[o,y]),F=c.useCallback(()=>{z(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[S?t.jsx(Ro,{onCancel:()=>C.current?.abort()}):null,T?t.jsx(Po,{}):null,M?t.jsx(ko,{onClose:()=>R(!1)}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx("span",{...x,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(Tt,{width:72,height:72,className:"size-[72px]"})}),t.jsx("h1",{className:"typography-h2 text-foreground",children:s("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(Q,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?s("mobile.connect.notice.authExpired",{label:e.label}):s("mobile.connect.notice.unreachable",{label:e.label})})]}):null,d?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:L,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Q,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(B=>B.kind==="direct")?at(d):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...Mt,value:y,onChange:B=>z(B.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:as}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!y.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:F,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[I?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{g()},disabled:S||i,children:[t.jsx(Q,{name:"scan-2",className:Y("size-[18px]",S&&"animate-pulse")}),s(i?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:s("mobile.connect.welcome.scanHint")})]}):null,u&&!j?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:s("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(B=>{const W=k===B.id;return t.jsxs("button",{type:"button",disabled:i,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-70",onClick:()=>{E(B.id),o.connect({id:B.id,candidates:B.candidates,clientToken:B.clientToken,label:B.label}).finally(()=>E(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Q,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:B.label}),t.jsx("span",{className:Y("block truncate typography-small",W?"text-foreground":"text-muted-foreground"),children:W?s("mobile.connect.connecting"):B.candidates.some(re=>re.kind==="direct")?at(B):s("mobile.connect.relay.badge")})]}),W?t.jsx(Q,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Q,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},B.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[I?t.jsxs("button",{type:"button",onClick:()=>P(B=>!B),"aria-expanded":j,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(Q,{name:"arrow-down-s",className:Y("size-4 transition-transform duration-200",j&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:j?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:D,children:[t.jsx("input",{...Mt,value:f,onChange:B=>K(B.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:j?void 0:-1,className:Y(as,"text-center")}),t.jsx("input",{value:p,onChange:B=>b(B.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:j?void 0:-1,className:Y(as,"text-center")}),t.jsx("input",{...Mt,value:h,onChange:B=>v(B.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:j?void 0:-1,autoCapitalize:"none",className:Y(as,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",variant:I?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||S||!f.trim(),children:s(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},Pc=n=>{const e=n.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},Ac=n=>{const e=ce.c(12),{groups:s,displayMode:o,timeFormatPreference:r,className:i}=n;let a;e[0]!==i?(a=Y("space-y-1.5",i),e[0]=i,e[1]=a):a=e[1];let u;if(e[2]!==o||e[3]!==s||e[4]!==r){let f;e[6]!==o||e[7]!==r?(f=l=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Qo,{providerId:l.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:l.providerName}),l.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:l.planLabel}):null,l.status&&l.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:l.status}):null]}),l.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:l.rows.map(p=>{const b=o==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Zo(p.window.valueLabel,b),v=ei(p.window.resetAt,p.window.resetAfterFormatted??p.window.resetAtFormatted,r);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"shrink-0 truncate typography-ui-label text-muted-foreground",children:p.subtitle?`${p.subtitle} · ${p.label}`:p.label}),v?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:v}):null]}),t.jsx("span",{className:Y("shrink-0 typography-ui-label font-semibold tabular-nums",Pc(p.window)),children:h==="-"?"":h})]},p.key)})}):null,l.status&&l.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:l.status}):null]},l.providerId),e[6]=o,e[7]=r,e[8]=f):f=e[8],u=s.map(f),e[2]=o,e[3]=s,e[4]=r,e[5]=u}else u=e[5];let d;return e[9]!==a||e[10]!==u?(d=t.jsx("div",{className:a,children:u}),e[9]=a,e[10]=u,e[11]=d):d=e[11],d},xr=380,Tc=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},en=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),Ic="—",Ao=n=>{const e=ce.c(20),{percentage:s}=n;let o,r,i,a,u,d,f;if(e[0]!==s){i=ii(s??0)??0;const h=ai(s??0);r=h==="critical"?"var(--status-error)":h==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,a="0 0 18 18",u="size-[18px] -rotate-90",d="progressbar",f=s===null?void 0:Math.round(i),e[0]=s,e[1]=o,e[2]=r,e[3]=i,e[4]=a,e[5]=u,e[6]=d,e[7]=f}else o=e[1],r=e[2],i=e[3],a=e[4],u=e[5],d=e[6],f=e[7];let l;e[8]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=l):l=e[8];let p;e[9]!==o||e[10]!==s||e[11]!==r||e[12]!==i?(p=s===null?null:t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:o*(1-i/100),className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=s,e[11]=r,e[12]=i,e[13]=p):p=e[13];let b;return e[14]!==a||e[15]!==u||e[16]!==d||e[17]!==f||e[18]!==p?(b=t.jsxs("svg",{viewBox:a,className:u,role:d,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100,children:[l,p]}),e[14]=a,e[15]=u,e[16]=d,e[17]=f,e[18]=p,e[19]=b):b=e[19],b},Dc=n=>{const e=ce.c(13),{icon:s,iconNode:o,label:r,children:i}=n;let a;e[0]!==s||e[1]!==o?(a=o??(s?t.jsx(Q,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=o,e[2]=a):a=e[2];let u;e[3]!==a?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=u):u=e[4];let d;e[5]!==r?(d=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=d):d=e[6];let f;e[7]!==i?(f=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:i}),e[7]=i,e[8]=f):f=e[8];let l;return e[9]!==u||e[10]!==d||e[11]!==f?(l=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[u,d,f]}),e[9]=u,e[10]=d,e[11]=f,e[12]=l):l=e[12],l},_c=n=>{const e=ce.c(53),{open:s,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:a,usageDisplayMode:u,isUsageLoading:d,timeFormatPreference:f}=n,{t:l}=de(),p=c.useRef(null),[b,h]=c.useState(s),[v,S]=c.useState(!1),{enabled:w}=bn(),T=c.useRef(null),[N,C]=c.useState(null);let I,j;e[0]!==r||e[1]!==w||e[2]!==s||e[3]!==b?(I=()=>{if(!s||!w||!b)return;const V=()=>{const se=r.current?.getBoundingClientRect(),ae=T.current?.getBoundingClientRect();if(!se||!ae){C(null);return}const ue=se.left-ae.left,U=Math.min(Math.max(ue,8),Math.max(8,ae.width-xr-8));C(U)};V();const Z=T.current;if(typeof ResizeObserver>"u"||!Z)return;const te=new ResizeObserver(V);return te.observe(Z),()=>te.disconnect()},j=[r,w,s,b],e[0]=r,e[1]=w,e[2]=s,e[3]=b,e[4]=I,e[5]=j):(I=e[4],j=e[5]),c.useLayoutEffect(I,j);const P=w&&N!==null;let k,E;e[6]!==s||e[7]!==b?(k=()=>{if(s){h(!0),S(!1);return}if(!b)return;S(!0);const V=window.setTimeout(()=>{h(!1),S(!1)},140);return()=>window.clearTimeout(V)},E=[s,b],e[6]=s,e[7]=b,e[8]=k,e[9]=E):(k=e[8],E=e[9]),c.useEffect(k,E);let y,z;e[10]!==o||e[11]!==s?(y=()=>{if(!s)return;const V=Z=>{Z.key==="Escape"&&o()};return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},z=[o,s],e[10]=o,e[11]=s,e[12]=y,e[13]=z):(y=e[12],z=e[13]),c.useEffect(y,z);let M,R;if(e[14]!==r||e[15]!==o||e[16]!==s?(M=()=>{if(!s)return;const V=Z=>{const te=Z.target;if(!(te instanceof Node)){o();return}p.current?.contains(te)||r.current?.contains(te)||o()};return document.addEventListener("pointerdown",V,!0),document.addEventListener("wheel",V,!0),()=>{document.removeEventListener("pointerdown",V,!0),document.removeEventListener("wheel",V,!0)}},R=[r,o,s],e[14]=r,e[15]=o,e[16]=s,e[17]=M,e[18]=R):(M=e[17],R=e[18]),c.useEffect(M,R),!b)return null;let x;e[19]!==l?(x=l("mobile.header.openMetadataAria"),e[19]=l,e[20]=x):x=e[20];const D=P?"absolute origin-top-left":"mx-3 mt-2",K=v?"pointer-events-none":"pointer-events-auto";let g;e[21]!==D||e[22]!==K?(g=Y("oc-surface-elevated overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",D,K),e[21]=D,e[22]=K,e[23]=g):g=e[23];const L=`${v?"session-metadata-out":"session-metadata-in"} ${v?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let F;e[24]!==N||e[25]!==P?(F=P?{top:8,left:N??8,width:`min(${xr}px, calc(100% - 16px))`}:null,e[24]=N,e[25]=P,e[26]=F):F=e[26];let B;e[27]!==L||e[28]!==F?(B={animation:L,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...F},e[27]=L,e[28]=F,e[29]=B):B=e[29];let W;e[30]!==i||e[31]!==l?(W=i?t.jsx(Dc,{iconNode:t.jsx(Ao,{percentage:i.state==="measured"?i.percentage:null}),label:l("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[i.state==="measured"?t.jsxs("span",{className:Y("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}):null,t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=l,e[32]=W):W=e[32];let re;e[33]!==i?.state||e[34]!==l?(re=i?.state==="compacted"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:l("contextUsage.compacted.description")}):null,e[33]=i?.state,e[34]=l,e[35]=re):re=e[35];let ne;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==a?(ne=t.jsx(Mc,{groups:a,displayMode:u,isLoading:d,timeFormatPreference:f}),e[36]=d,e[37]=f,e[38]=u,e[39]=a,e[40]=ne):ne=e[40];let ee;e[41]!==W||e[42]!==re||e[43]!==ne?(ee=t.jsxs("div",{className:"space-y-1",children:[W,re,ne]}),e[41]=W,e[42]=re,e[43]=ne,e[44]=ee):ee=e[44];let _;e[45]!==g||e[46]!==B||e[47]!==ee||e[48]!==x?(_=t.jsx("div",{ref:p,role:"dialog","aria-label":x,className:g,style:B,children:ee}),e[45]=g,e[46]=B,e[47]=ee,e[48]=x,e[49]=_):_=e[49];let G;e[50]===Symbol.for("react.memo_cache_sentinel")?(G=t.jsx("style",{children:`
|
|
5
|
-
@keyframes session-metadata-in {
|
|
6
|
-
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
7
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
8
|
-
}
|
|
9
|
-
@keyframes session-metadata-out {
|
|
10
|
-
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
11
|
-
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
12
|
-
}
|
|
13
|
-
`}),e[50]=G):G=e[50];let X;return e[51]!==_?(X=t.jsxs("div",{ref:T,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[_,G]}),e[51]=_,e[52]=X):X=e[52],X},Mc=n=>{const e=ce.c(30),{groups:s,displayMode:o,isLoading:r,timeFormatPreference:i}=n,{t:a}=de();let u;e[0]!==o||e[1]!==a?(u=a(o==="remaining"?"header.services.remaining":"header.services.used"),e[0]=o,e[1]=a,e[2]=u):u=e[2];const d=u;if(s.length===0){if(!r)return null;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Q,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=N):N=e[3];let C;e[4]!==a?(C=a("common.loading"),e[4]=a,e[5]=C):C=e[5];let I;return e[6]!==C?(I=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[N,t.jsx("span",{className:"typography-ui-label",children:C})]}),e[6]=C,e[7]=I):I=e[7],I}let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(Q,{name:"timer",className:"size-[18px]"})}),e[8]=f):f=e[8];let l;e[9]!==a?(l=a("mobile.header.metadata.usage"),e[9]=a,e[10]=l):l=e[10];let p;e[11]!==l?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:l}),e[11]=l,e[12]=p):p=e[12];let b;e[13]!==r?(b=r?t.jsx(Q,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=b):b=e[14];let h;e[15]!==d?(h=t.jsx("span",{className:"truncate",children:d}),e[15]=d,e[16]=h):h=e[16];let v;e[17]!==b||e[18]!==h?(v=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[b,h]}),e[17]=b,e[18]=h,e[19]=v):v=e[19];let S;e[20]!==p||e[21]!==v?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[f,p,v]}),e[20]=p,e[21]=v,e[22]=S):S=e[22];let w;e[23]!==o||e[24]!==s||e[25]!==i?(w=t.jsx(Ac,{groups:s,displayMode:o,timeFormatPreference:i}),e[23]=o,e[24]=s,e[25]=i,e[26]=w):w=e[26];let T;return e[27]!==S||e[28]!==w?(T=t.jsxs("div",{className:"pt-2.5",children:[S,w]}),e[27]=S,e[28]=w,e[29]=T):T=e[29],T},zc=c.memo(function({open:e,onOpenChange:s,currentSessionId:o,effectiveDirectory:r,isNewSessionDraftOpen:i}){const{t:a}=de(),u=c.useRef(null),d=ti(o??"",r||void 0),f=Je(g=>g.providers),l=Je(g=>g.currentProviderId),p=Je(g=>g.currentModelId),b=Je(g=>g.getModelMetadata);Je(g=>g.modelsMetadata.size);const h=si(c.useCallback(g=>o?g.sessionModelSelections.get(o)??null:null,[o])),v=ht(g=>g.results),S=ht(g=>g.refreshErrors),w=c.useRef(!1),T=ht(g=>g.loadSettings),N=ht(g=>g.fetchAllQuotas),C=ht(g=>g.isLoading),I=ht(g=>g.displayMode),j=ht(g=>g.dropdownProviderIds),P=it(g=>g.timeFormatPreference);ni(),c.useEffect(()=>{T()},[T]),c.useEffect(()=>{tr(j)},[j]),c.useEffect(()=>{if(!e){w.current=!1;return}w.current||C||!j.some(L=>!v.some(F=>F.providerId===L)||S[L])||(w.current=!0,N())},[j,N,C,e,v,S]);const E=c.useMemo(()=>{for(let g=d.length-1;g>=0;g-=1){const L=d[g];if(L.role!=="user")continue;const F=typeof L.model?.providerID=="string"&&L.model.providerID.trim().length>0?L.model.providerID:void 0,B=typeof L.model?.modelID=="string"&&L.model.modelID.trim().length>0?L.model.modelID:void 0;if(F&&B)return{providerID:F,modelID:B}}return null},[d])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(l&&p?{providerID:l,modelID:p}:null),z=(E?f.find(g=>g.id===E.providerID):void 0)?.models.find(g=>g.id===E?.modelID),M=E?b(E.providerID,E.modelID):void 0,R=Tc(z?.limit,"context")??M?.limit?.context??0,x=c.useMemo(()=>ri(d),[d]),D=c.useMemo(()=>{if(i||!x||R<=0)return null;if(x.state==="compacted")return{state:"compacted",tokens:`${Ic}/${en(R)}`};const g=Math.min(x.totalTokens/R*100,999),L=g>=90?"text-[var(--status-error)]":g>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]";return{state:"measured",percentage:g,tokens:`${en(x.totalTokens)}/${en(R)}`,colorClass:L}},[x,R,i]),K=oi();return c.useEffect(()=>{!e||K.length===0||tr(K.map(g=>g.providerId))},[e,K]),t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:u,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":a("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(g=>!g),style:{touchAction:"manipulation"},children:t.jsx(Ao,{percentage:D?.state==="compacted"?null:D?.percentage??0})}),t.jsx(_c,{open:e,onClose:()=>s(!1),anchorRef:u,contextDisplay:D,usageGroups:K,usageDisplayMode:I,isUsageLoading:C,timeFormatPreference:P})]})}),Oc=10,yr=380,Bc=(n,e)=>n.title?.trim()||e,Lc=n=>{const e=ce.c(32),{session:s,meta:o,active:r,onSelect:i}=n,{t:a}=de(),u=Ur(s.id),d=Gr(s.id),f=u?.type??"idle",l=f==="busy"||f==="retry",p=!l&&d>0&&!r,b=Kr(s.id,l),h=(l||p)&&b,v=s.time?.updated??s.time?.created??0;let S;e[0]!==v?(S=ci(v),e[0]=v,e[1]=S):S=e[1];const w=S,T=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let N;e[2]!==T?(N=Y("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",T),e[2]=T,e[3]=N):N=e[3];let C;e[4]===Symbol.for("react.memo_cache_sentinel")?(C={touchAction:"manipulation"},e[4]=C):C=e[4];const I=r?"text-primary":"text-foreground";let j;e[5]!==I?(j=Y("block truncate typography-ui-label",I),e[5]=I,e[6]=j):j=e[6];let P;e[7]!==s||e[8]!==a?(P=Bc(s,a("sessions.sidebar.session.untitled")),e[7]=s,e[8]=a,e[9]=P):P=e[9];let k;e[10]!==j||e[11]!==P?(k=t.jsx("span",{className:j,children:P}),e[10]=j,e[11]=P,e[12]=k):k=e[12];let E;e[13]!==o?(E=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:o}):null,e[13]=o,e[14]=E):E=e[14];let y;e[15]!==E||e[16]!==k?(y=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[k,E]}),e[15]=E,e[16]=k,e[17]=y):y=e[17];let z;e[18]!==l||e[19]!==p?(z=l||p?t.jsx("span",{className:Y("size-1.5 shrink-0 rounded-full",l?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):null,e[18]=l,e[19]=p,e[20]=z):z=e[20];let M;e[21]!==l||e[22]!==s.id||e[23]!==h||e[24]!==w?(M=h?t.jsx(io,{sessionId:s.id,running:l,className:"typography-micro"}):w?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:w}):null,e[21]=l,e[22]=s.id,e[23]=h,e[24]=w,e[25]=M):M=e[25];let R;return e[26]!==i||e[27]!==y||e[28]!==z||e[29]!==M||e[30]!==N?(R=t.jsxs("button",{type:"button",className:N,onClick:i,style:C,children:[y,z,M]}),e[26]=i,e[27]=y,e[28]=z,e[29]=M,e[30]=N,e[31]=R):R=e[31],R},$c=n=>{const e=ce.c(50),{open:s,onClose:o,anchorRef:r}=n,{t:i}=de(),a=c.useRef(null),[u,d]=c.useState(s),[f,l]=c.useState(!1),{enabled:p}=bn(),b=c.useRef(null),[h,v]=c.useState(null);let S,w;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==u?(S=()=>{if(!s||!p||!u)return;const V=()=>{const se=r.current?.getBoundingClientRect(),ae=b.current?.getBoundingClientRect();if(!se||!ae){v(null);return}const ue=se.left-ae.left;v(Math.min(Math.max(ue,8),Math.max(8,ae.width-yr-8)))};V();const Z=b.current;if(typeof ResizeObserver>"u"||!Z)return;const te=new ResizeObserver(V);return te.observe(Z),()=>te.disconnect()},w=[r,p,s,u],e[0]=r,e[1]=p,e[2]=s,e[3]=u,e[4]=S,e[5]=w):(S=e[4],w=e[5]),c.useLayoutEffect(S,w);const T=p&&h!==null,N=Se(Fc),C=Se(Wc),I=We(Vc);let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j={maxParents:Oc},e[6]=j):j=e[6];const P=li(s||u,j);let k,E;e[7]!==s||e[8]!==u?(k=()=>{if(s){xn(),d(!0),l(!1);return}if(!u)return;l(!0);const V=window.setTimeout(()=>{d(!1),l(!1)},140);return()=>window.clearTimeout(V)},E=[s,u],e[7]=s,e[8]=u,e[9]=k,e[10]=E):(k=e[9],E=e[10]),c.useEffect(k,E);let y,z;e[11]!==o||e[12]!==s?(y=()=>{if(!s)return;const V=Z=>{Z.key==="Escape"&&o()};return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},z=[o,s],e[11]=o,e[12]=s,e[13]=y,e[14]=z):(y=e[13],z=e[14]),c.useEffect(y,z);let M,R;e[15]!==r||e[16]!==o||e[17]!==s?(M=()=>{if(!s)return;const V=Z=>{const te=Z.target;if(!(te instanceof Node)){o();return}a.current?.contains(te)||r.current?.contains(te)||o()};return document.addEventListener("pointerdown",V,!0),()=>document.removeEventListener("pointerdown",V,!0)},R=[r,o,s],e[15]=r,e[16]=o,e[17]=s,e[18]=M,e[19]=R):(M=e[18],R=e[19]),c.useEffect(M,R);let x;e[20]!==o||e[21]!==C?(x=V=>{C(V.id,gn(V)),o()},e[20]=o,e[21]=C,e[22]=x):x=e[22];const D=x;if(!u)return null;let K;e[23]!==i?(K=i("sessions.switcher.openAria"),e[23]=i,e[24]=K):K=e[24];const g=T?"absolute origin-top-left":"mx-3 mt-2",L=f?"pointer-events-none":"pointer-events-auto";let F;e[25]!==g||e[26]!==L?(F=Y("oc-surface-elevated flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",g,L),e[25]=g,e[26]=L,e[27]=F):F=e[27];const B=`${f?"session-switcher-out":"session-switcher-in"} ${f?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let W;e[28]!==h||e[29]!==T?(W=T?{top:8,left:h??8,width:`min(${yr}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=T,e[30]=W):W=e[30];let re;e[31]!==B||e[32]!==W?(re={animation:B,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...W},e[31]=B,e[32]=W,e[33]=re):re=e[33];let ne;e[34]!==N||e[35]!==D||e[36]!==P||e[37]!==I||e[38]!==i?(ne=P.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:i("sessions.switcher.empty")}):P.map(V=>{const Z=V.node.session,te=[V.secondaryMeta?.projectLabel,V.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(Lc,{session:Z,meta:te,active:Z.id===N,onSelect:()=>{V.projectId&&I(V.projectId),D(Z)}},Z.id)}),e[34]=N,e[35]=D,e[36]=P,e[37]=I,e[38]=i,e[39]=ne):ne=e[39];let ee;e[40]!==ne?(ee=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:ne}),e[40]=ne,e[41]=ee):ee=e[41];let _;e[42]!==K||e[43]!==F||e[44]!==re||e[45]!==ee?(_=t.jsx("div",{ref:a,role:"dialog","aria-label":K,className:F,style:re,children:ee}),e[42]=K,e[43]=F,e[44]=re,e[45]=ee,e[46]=_):_=e[46];let G;e[47]===Symbol.for("react.memo_cache_sentinel")?(G=t.jsx("style",{children:`
|
|
14
|
-
@keyframes session-switcher-in {
|
|
15
|
-
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
16
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
17
|
-
}
|
|
18
|
-
@keyframes session-switcher-out {
|
|
19
|
-
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
20
|
-
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
21
|
-
}
|
|
22
|
-
`}),e[47]=G):G=e[47];let X;return e[48]!==_?(X=t.jsxs("div",{ref:b,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[_,G]}),e[48]=_,e[49]=X):X=e[49],X};function Fc(n){return n.currentSessionId}function Wc(n){return n.setCurrentSession}function Vc(n){return n.setActiveProjectIdOnly}const Uc=n=>{const e=ce.c(78),{onOpenSessions:s,onOpenWorkspace:o,compactTitle:r}=n,i=r===void 0?!1:r,{t:a}=de(),[u,d]=c.useState(!1),[f,l]=c.useState(!1),p=c.useRef(null),b=xt(Gc),h=Se(Kc);let v;e[0]!==h?(v=Ce=>h?Ce.getDirectoryForSession(h):null,e[0]=h,e[1]=v):v=e[1];const w=Se(v)||b,T=ui(h,w||void 0),N=Se(Hc),C=Hr(w||null);let I;e[2]!==w||e[3]!==C?(I=Ce=>{if(!w||C!==!0)return!1;const Ee=Ce.directories.get(w)?.status;return!!(Ee&&!Ee.isClean)},e[2]=w,e[3]=C,e[4]=I):I=e[4];const j=He(I);let P;e[5]!==T?.title?(P=T?.title?.trim(),e[5]=T?.title,e[6]=P):P=e[6];const k=P;let E;e[7]!==h||e[8]!==k||e[9]!==a?(E=k||a(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[7]=h,e[8]=k,e[9]=a,e[10]=E):E=e[10];const y=E;let z;e[11]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{d(!1),l(!1)},e[11]=z):z=e[11];let M;e[12]!==h||e[13]!==w?(M=[h,w],e[12]=h,e[13]=w,e[14]=M):M=e[14],c.useEffect(z,M);let R;e[15]!==s?(R=()=>{d(!1),l(!1),s()},e[15]=s,e[16]=R):R=e[16];const x=R;let D;e[17]===Symbol.for("react.memo_cache_sentinel")?(D=Ce=>{d(Ee=>{const ve=typeof Ce=="function"?Ce(Ee):Ce;return ve&&l(!1),ve})},e[17]=D):D=e[17];const K=D;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{l(Ce=>{const Ee=!Ce;return Ee&&d(!1),Ee})},e[18]=g):g=e[18];const L=g;let F;e[19]===Symbol.for("react.memo_cache_sentinel")?(F={paddingTop:"var(--oc-safe-area-top, 0px)"},e[19]=F):F=e[19];let B;e[20]!==a?(B=a("mobile.sessions.openSheetAria"),e[20]=a,e[21]=B):B=e[21];let W,re;e[22]===Symbol.for("react.memo_cache_sentinel")?(W={touchAction:"manipulation"},re=t.jsx(Q,{name:"list-unordered",className:"size-5"}),e[22]=W,e[23]=re):(W=e[22],re=e[23]);let ne;e[24]!==x||e[25]!==B?(ne=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":B,onClick:x,style:W,children:re}),e[24]=x,e[25]=B,e[26]=ne):ne=e[26];const ee=i?"shrink":"flex-1";let _;e[27]!==ee?(_=Y("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",ee),e[27]=ee,e[28]=_):_=e[28];let G;e[29]!==a?(G=a("sessions.switcher.openAria"),e[29]=a,e[30]=G):G=e[30];let X;e[31]===Symbol.for("react.memo_cache_sentinel")?(X={touchAction:"manipulation"},e[31]=X):X=e[31];let V;e[32]!==y?(V=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:y}),e[32]=y,e[33]=V):V=e[33];const Z=f&&"rotate-180";let te;e[34]!==Z?(te=Y("size-4 shrink-0 text-muted-foreground transition-transform duration-150",Z),e[34]=Z,e[35]=te):te=e[35];let se;e[36]!==te?(se=t.jsx(Q,{name:"arrow-down-s",className:te}),e[36]=te,e[37]=se):se=e[37];let ae;e[38]!==V||e[39]!==se?(ae=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[V,se]}),e[38]=V,e[39]=se,e[40]=ae):ae=e[40];let ue;e[41]!==f||e[42]!==_||e[43]!==G||e[44]!==ae?(ue=t.jsx("button",{ref:p,type:"button",className:_,"aria-label":G,"aria-haspopup":"dialog","aria-expanded":f,onClick:L,style:X,children:ae}),e[41]=f,e[42]=_,e[43]=G,e[44]=ae,e[45]=ue):ue=e[45];let U;e[46]!==i?(U=i?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[46]=i,e[47]=U):U=e[47];let ie;e[48]!==h||e[49]!==w||e[50]!==N||e[51]!==u?(ie=t.jsx(zc,{open:u,onOpenChange:K,currentSessionId:h,effectiveDirectory:w,isNewSessionDraftOpen:N}),e[48]=h,e[49]=w,e[50]=N,e[51]=u,e[52]=ie):ie=e[52];let xe;e[53]!==j||e[54]!==a?(xe=a(j?"mobile.header.openWorkspaceWithChangesAria":"mobile.header.openWorkspaceAria"),e[53]=j,e[54]=a,e[55]=xe):xe=e[55];let Ne;e[56]!==o?(Ne=()=>{d(!1),l(!1),o()},e[56]=o,e[57]=Ne):Ne=e[57];let q,ye;e[58]===Symbol.for("react.memo_cache_sentinel")?(q={touchAction:"manipulation"},ye=t.jsx(Q,{name:"pencil-ruler-2",className:"size-5"}),e[58]=q,e[59]=ye):(q=e[58],ye=e[59]);let Re;e[60]!==j?(Re=j?t.jsx("span",{className:"absolute right-1.5 top-1.5 size-2.5 rounded-full border-2 border-[var(--background)] bg-[var(--status-warning)]","aria-hidden":!0}):null,e[60]=j,e[61]=Re):Re=e[61];let _e;e[62]!==xe||e[63]!==Ne||e[64]!==Re?(_e=t.jsxs("button",{type:"button",className:"relative flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":xe,onClick:Ne,style:q,children:[ye,Re]}),e[62]=xe,e[63]=Ne,e[64]=Re,e[65]=_e):_e=e[65];let Ie;e[66]!==ne||e[67]!==ue||e[68]!==U||e[69]!==ie||e[70]!==_e?(Ie=t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:F,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[ne,ue,U,ie,_e]})}),e[66]=ne,e[67]=ue,e[68]=U,e[69]=ie,e[70]=_e,e[71]=Ie):Ie=e[71];let Ve;e[72]===Symbol.for("react.memo_cache_sentinel")?(Ve=()=>l(!1),e[72]=Ve):Ve=e[72];let Me;e[73]!==f?(Me=t.jsx($c,{open:f,onClose:Ve,anchorRef:p}),e[73]=f,e[74]=Me):Me=e[74];let Fe;return e[75]!==Ie||e[76]!==Me?(Fe=t.jsxs(t.Fragment,{children:[Ie,Me]}),e[75]=Ie,e[76]=Me,e[77]=Fe):Fe=e[77],Fe};function Gc(n){return n.currentDirectory}function Kc(n){return n.currentSessionId}function Hc(n){return!!n.newSessionDraft?.open}const qc=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=de(),o=jo(e),{connections:r,isBusy:i,isPasswordBusy:a,error:u,pendingConnection:d,connect:f,submitPassword:l,cancelPassword:p,saveConnection:b,removeConnection:h,setError:v}=o,[S,w]=c.useState(null),T=S?r.find(U=>U.id===S)??null:null,[N,C]=c.useState(null),[I,j]=c.useState(""),[P,k]=c.useState(""),[E,y]=c.useState(""),[z,M]=c.useState(""),[R,x]=c.useState(!1),[D,K]=c.useState(!1),g=c.useRef(null),L=c.useMemo(()=>dn(),[]),[F,B]=c.useState(!1),[W,re]=c.useState(null),[ne,ee]=c.useState(!1),_=fo(c.useCallback(()=>ee(!0),[])),G=c.useCallback(()=>{w(null),j(""),k(""),y(""),v(null),B(!1)},[v]),X=c.useCallback(U=>{U.preventDefault(),b({id:S??void 0,url:I,label:P,clientToken:E}).then(ie=>{ie&&G()})},[E,S,P,G,b,I]),V=c.useCallback(async()=>{if(g.current)return;v(null),x(!0);const U=new AbortController;g.current=U;try{const ie=await Eo({signal:U.signal});switch(g.current===U&&(g.current=null,x(!1)),ie.status){case"ok":j(ie.url),ie.label&&k(ie.label),ie.clientToken&&y(ie.clientToken),B(!0);break;case"pairing":K(!0),await o.redeemPairingConnection(ie.pairing);break;case"permission-denied":v(s("mobile.connect.scan.permissionDenied"));break;case"invalid":v(s("mobile.connect.scan.invalid"));break;case"unsupported":v(s("mobile.connect.scan.unsupported"));break;case"failed":v(s("mobile.connect.scan.failed"));break;default:break}}finally{K(!1),g.current===U&&(g.current=null,x(!1))}},[o,v,s]);c.useEffect(()=>()=>g.current?.abort(),[]);const Z=c.useCallback(U=>{U.preventDefault(),l(z)},[z,l]),te=c.useCallback(()=>{M(""),p()},[p]),se=c.useCallback(U=>{C(ie=>ie===U?null:U)},[]),ae=c.useCallback(U=>{C(null),S===U&&G();const ie=r.length===1;h(U).then(xe=>{xe&&(ie||br(xe))&&n()})},[r.length,S,n,h,G]),ue=as;return d?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:Z,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Q,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(U=>U.kind==="direct")?at(d):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...Mt,value:z,onChange:U=>M(U.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ue}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!z.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:te,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[R?t.jsx(Ro,{onCancel:()=>g.current?.abort()}):null,D?t.jsx(Po,{}):null,ne?t.jsx(ko,{onClose:()=>ee(!1)}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{..._,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(U=>{const ie=N===U.id,xe=br(U),Ne=W===U.id,q=Ne?s("mobile.connect.connecting"):xe?ps()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):U.candidates.some(ye=>ye.kind==="direct")?at(U):s("mobile.connect.relay.badge");return t.jsxs("div",{className:Y("flex items-center border-b border-border/70 transition-colors last:border-b-0",ie&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-60",onClick:()=>{xe||(re(U.id),f({id:U.id,candidates:U.candidates,clientToken:U.clientToken,label:U.label}).finally(()=>re(null)))},disabled:i&&!Ne||ie,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(Q,{name:"server",className:"size-[18px]"}),xe?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:U.label}),t.jsx("span",{className:Y("block truncate typography-small",xe&&!Ne?"text-[var(--status-success)]":"text-muted-foreground"),children:q})]}),Ne?t.jsx(Q,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[ie?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:U.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>ae(U.id),style:{touchAction:"manipulation"},children:[t.jsx(Q,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):U.candidates.some(ye=>ye.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>{w(U.id),j(at(U)),k(U.label),y(U.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":ie?s("mobile.instances.cancelDeleteAria",{label:U.label}):s("mobile.instances.deleteAria",{label:U.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>se(U.id),style:{touchAction:"manipulation"},children:t.jsx(Q,{name:ie?"close":"delete-bin",className:"size-[18px]"})})]})]},U.id)})}):t.jsx("p",{..._,className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),!F&&!T?t.jsxs("div",{className:"space-y-2",children:[L?t.jsxs(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{V()},disabled:R,children:[t.jsx(Q,{name:"scan-2",className:Y("size-[18px]",R&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(pe,{type:"button",variant:L?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),B(!0)},children:[t.jsx(Q,{name:"add",className:"size-[18px]"}),s("mobile.instances.addManual")]}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:X,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:s(T?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(pe,{type:"button",variant:"ghost",size:"xs",onClick:G,children:s("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...Mt,value:I,onChange:U=>j(U.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:P,onChange:U=>k(U.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...Mt,value:E,onChange:U=>y(U.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ue}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(T?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},Te=n=>Wo(n)??"",tn=n=>{const e=Te(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},vr=Dn(n=>({expandedParents:{},toggleParent:e=>n(s=>{const o={...s.expandedParents};return o[e]?delete o[e]:o[e]=!0,{expandedParents:o}})})),Rs=Dn()(lo(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(o=>({projectExpanded:{...o.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(o=>({worktreeExpanded:{...o.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),fn=Dn()(lo(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(o=>({orderByProject:{...o.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),wr=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Jc=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,i)=>[wr(r),i])),o=r=>s.get(wr(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,i)=>({worktree:r,index:i})).sort((r,i)=>{const a=o(r.worktree)-o(i.worktree);return a!==0?a:r.index-i.index}).map(r=>r.worktree)},ls=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Yc=n=>{const e=n;return ls(e.directory??e.project?.worktree??null)},To=({open:n,project:e,worktree:s,onClose:o,onDeleted:r})=>{const{t:i}=de(),a=qr(),u=hn(y=>y.activeSessions),d=Se(y=>y.archiveSessions),f=xt(y=>y.currentDirectory),[l,p]=c.useState(!1),[b,h]=c.useState(!1),[v,S]=c.useState(!1),[w,T]=c.useState(!1),N=ls(s?.path),C=typeof s?.branch=="string"&&s.branch.trim().length>0,I=c.useMemo(()=>{if(!N)return[];const y=new Map;for(const z of[...u,...a])Yc(z)===N&&y.set(z.id,z);return Array.from(y.values())},[u,a,N]);c.useEffect(()=>{if(!n){p(!1),h(!1),S(!1),T(!1);return}if(!s?.path)return;let y=!1;return di(s.path).then(z=>{y||S(!!z?.isDirty)}).catch(()=>{y||S(!!s.status?.isDirty)}),()=>{y=!0}},[n,s?.path,s?.status?.isDirty]);const j=c.useCallback((y,z)=>{const M=fi(y),R=le.loading(i("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:M}));(async()=>{try{if(z.length>0){const{failedIds:x}=await d(z);if(x.length>0){le.error(x.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:x.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:x.length}),{id:R,description:i("sessions.sidebar.dialogs.deleteResult.tryAgain")});return}}await mi(e,y,{deleteRemoteBranch:C&&b,deleteLocalBranch:C&&l}),ls(f)===N&&ls(e.path)&&xt.getState().setDirectory(ls(e.path),{showOverlay:!1}),le.success(i("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:M}),{id:R,description:i(C&&b?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(x){le.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:M}),{id:R,description:x instanceof Error?x.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[d,f,l,b,C,r,e,i,N]),P=()=>{!s||w||(T(!0),j(s,I.map(y=>y.id)),o())};if(!s)return null;const k=s.branch||s.label||s.path,E=(y,z,M,R)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":y,disabled:R,onClick:()=>z(!y),className:Y("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",R&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:M}),t.jsx("span",{className:Y("relative h-6 w-10 shrink-0 rounded-full transition-colors",y?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:Y("absolute top-0.5 size-5 rounded-full bg-white transition-transform",y?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Jr,{open:n,onClose:o,title:i("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(pe,{variant:"ghost",className:"flex-1",onClick:o,disabled:w,children:i("projectEditDialog.actions.cancel")}),t.jsx(pe,{variant:"destructive",className:"flex-1",onClick:()=>{P()},disabled:w,children:i("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:i("mobile.projectEdit.deleteWorktreeConfirm",{name:k})}),v?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:i("mobile.projectEdit.deleteWorktreeDirty")}):null,I.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.deleteWorktreeArchiveNote",{count:I.length})}):null,C?t.jsxs("div",{className:"flex flex-col gap-2",children:[E(l,p,i("mobile.projectEdit.deleteLocalBranch"),w),E(b,h,i("mobile.projectEdit.deleteRemoteBranch"),w)]}):null]})})},jr="mobile-surface-root",sn=16,Ps=200,Xc=()=>{if(typeof document>"u")return null;let n=document.getElementById(jr);return n||(n=document.createElement("div"),n.id=jr,document.body.appendChild(n)),n},cs=({open:n,onClose:e,title:s,subtitle:o,trailing:r,disableEscapeDismiss:i=!1,headerless:a=!1,noHeaderBorder:u=!1,ariaLabel:d,variant:f="fullscreen",dialogAlign:l="chat",children:p})=>{const{t:b}=de(),h=c.useRef(null),[v,S]=c.useState(!1),[w,T]=c.useState(!1),N=c.useRef(null),C=c.useRef(null),I=c.useRef(e);if(c.useEffect(()=>{I.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Xc()),c.useEffect(()=>{if(!n){S(!1);return}const k=window.setTimeout(()=>S(!0),sn);return()=>window.clearTimeout(k)},[n]),c.useEffect(()=>{if(!n){T(!1);return}const k=window.setTimeout(()=>T(!0),sn+Ps+80);return()=>window.clearTimeout(k)},[n]),c.useEffect(()=>{if(!n)return;const k=document.body.style.overflow;C.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const E=()=>{const M=N.current;if(!M)return;(M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??M).focus({preventScroll:!0})},y=window.setTimeout(E,sn),z=M=>{if(M.key==="Escape"&&!i){I.current();return}if(M.key!=="Tab")return;const R=N.current;if(!R)return;const x=Array.from(R.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(L=>!L.hasAttribute("disabled")&&L.getAttribute("aria-hidden")!=="true");if(x.length===0){M.preventDefault(),R.focus({preventScroll:!0});return}const D=x[0],K=x[x.length-1],g=document.activeElement;M.shiftKey&&g===D?(M.preventDefault(),K.focus({preventScroll:!0})):!M.shiftKey&&g===K&&(M.preventDefault(),D.focus({preventScroll:!0}))};return document.addEventListener("keydown",z),()=>{window.clearTimeout(y),document.body.style.overflow=k,document.removeEventListener("keydown",z),C.current?.focus?.({preventScroll:!0}),C.current=null}},[i,n]),!n||!h.current)return null;const j=f==="dialog",P=t.jsxs("section",{ref:N,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:Y("flex flex-col bg-background text-foreground",j?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50"),style:j?{opacity:v?1:0,transform:v?"none":"scale(0.97)",transition:`opacity ${Ps}ms ease-out, transform ${Ps}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:`transform ${Ps}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:k=>{v&&k.target===k.currentTarget&&k.propertyName==="transform"&&T(!0)},children:[a?null:t.jsxs("header",{className:Y("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!u&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":b("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,o?typeof o=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:o}):o:null]}),r?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:r}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:p}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return j?zt.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:v?1:0,paddingLeft:l==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:l==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:k=>k.stopPropagation(),children:P})}),h.current):zt.createPortal(P,h.current)},Qc=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Zc=n=>{const e=ce.c(36),{worktree:s,onDelete:o}=n,{t:r}=de();let i;e[0]!==s.path?(i={id:s.path},e[0]=s.path,e[1]=i):i=e[1];const{attributes:a,listeners:u,setNodeRef:d,transform:f,transition:l,isDragging:p}=Tn(i);let b;e[2]!==f?(b=In.Transform.toString(f),e[2]=f,e[3]=b):b=e[3];const h=p?10:1;let v;e[4]!==b||e[5]!==h||e[6]!==l?(v={transform:b,transition:l,zIndex:h},e[4]=b,e[5]=h,e[6]=l,e[7]=v):v=e[7];const S=v,w=s.branch||s.label||s.path,T=p&&"shadow-lg shadow-black/20";let N;e[8]!==T?(N=Y("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",T),e[8]=T,e[9]=N):N=e[9];let C;e[10]!==w||e[11]!==r?(C=r("mobile.projectEdit.dragWorktreeAria",{label:w}),e[10]=w,e[11]=r,e[12]=C):C=e[12];let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(wn,{className:"size-4"}),e[13]=I):I=e[13];let j;e[14]!==a||e[15]!==u||e[16]!==C?(j=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":C,...a,...u,children:I}),e[14]=a,e[15]=u,e[16]=C,e[17]=j):j=e[17];let P;e[18]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Q,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=P):P=e[18];let k;e[19]!==w?(k=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:w}),e[19]=w,e[20]=k):k=e[20];let E;e[21]!==w||e[22]!==r?(E=r("mobile.projectEdit.deleteWorktreeAria",{label:w}),e[21]=w,e[22]=r,e[23]=E):E=e[23];let y,z;e[24]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation"},z=t.jsx(_s,{className:"size-4"}),e[24]=y,e[25]=z):(y=e[24],z=e[25]);let M;e[26]!==o||e[27]!==E?(M=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":E,onClick:o,style:y,children:z}),e[26]=o,e[27]=E,e[28]=M):M=e[28];let R;return e[29]!==d||e[30]!==S||e[31]!==k||e[32]!==M||e[33]!==N||e[34]!==j?(R=t.jsxs("div",{ref:d,style:S,className:N,children:[j,P,k,M]}),e[29]=d,e[30]=S,e[31]=k,e[32]=M,e[33]=N,e[34]=j,e[35]=R):R=e[35],R},eu=({open:n,project:e,onClose:s,onWorktreesChanged:o})=>{const{t:r}=de(),{currentTheme:i}=Yr(),a=We(g=>g.updateProjectMeta),u=We(g=>g.discoverProjectIcon),d=We(g=>g.removeProjectIcon),f=fn(g=>g.setWorktreeOrder),l=We(g=>e?g.projects.find(L=>L.id===e.id)?.iconImage??null:null),[p,b]=c.useState(""),[h,v]=c.useState(null),[S,w]=c.useState(null),[T,N]=c.useState(!1),[C,I]=c.useState([]),[j,P]=c.useState(null),k=e?.id??null;c.useEffect(()=>{!n||!e||(b(e.label),v(e.icon??null),w(e.color??null),I(e.worktrees))},[n,k]),c.useEffect(()=>{!n||!e||I(g=>{const L=e.worktrees.map(W=>W.path),F=g.map(W=>W.path);return L.length===F.length&&L.every(W=>F.includes(W))?g:e.worktrees})},[e?.worktrees]);const E=kn(Bt(Nn,{activationConstraint:{distance:8}}),Bt(Sn,{coordinateGetter:Rn})),y=()=>{if(!e)return;const g=p.trim();a(e.id,{label:g||e.label,icon:h,color:S}),s()},z=()=>{!e||T||(N(!0),u(e.id).then(g=>{if(!g.ok){le.error(g.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(g.skipped){le.success(r("projectEditDialog.toast.customIconAlreadySet"));return}le.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>N(!1)))},M=()=>{e&&d(e.id).then(g=>{if(!g.ok){le.error(g.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}le.success(r("projectEditDialog.toast.iconRemoved"))})},R=g=>{const{active:L,over:F}=g;if(!F||L.id===F.id||!e)return;const B=C.findIndex(ee=>ee.path===L.id),W=C.findIndex(ee=>ee.path===F.id);if(B<0||W<0)return;const re=[...C],[ne]=re.splice(B,1);re.splice(W,0,ne),I(re),f(e.id,re.map(ee=>Qc(ee.path)))},x=S?Xr[S]??null:null,D=h?Qr[h]:null,K=!!l;return t.jsxs(t.Fragment,{children:[t.jsx(cs,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:y,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(ao,{className:"size-4"}),r("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:K?t.jsx(Zr,{project:{id:e.id,iconImage:l},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(ln,{className:"size-7"})}):D?t.jsx(Q,{name:D,className:"size-7",style:x?{color:x}:void 0}):t.jsx(ln,{className:"size-7",style:x?{color:x}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(eo,{value:p,onChange:g=>b(g.target.value),placeholder:r("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>w(null),"aria-label":r("projectEditDialog.option.none"),className:Y("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),pi.map(g=>t.jsx("button",{type:"button",onClick:()=>w(g.key),"aria-label":g.label,title:g.label,className:Y("size-9 rounded-xl border-2 transition-all",S===g.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:g.cssVar,touchAction:"manipulation"}},g.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>v(null),"aria-label":r("projectEditDialog.option.none"),className:Y("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===null?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),hi.map(g=>t.jsx("button",{type:"button",onClick:()=>v(g.key),"aria-label":g.label,title:g.label,className:Y("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===g.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(Q,{name:g.Icon,className:"size-4",style:x?{color:x}:void 0})},g.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(pe,{size:"sm",variant:"outline",onClick:z,disabled:T,children:r(T?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),K?t.jsx(pe,{size:"sm",variant:"outline",onClick:M,children:r("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("mobile.projectEdit.worktreesTitle")}),C.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.reorderHint")}),t.jsx(Cn,{sensors:E,collisionDetection:En,onDragEnd:R,children:t.jsx(Pn,{items:C.map(g=>g.path),strategy:An,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:C.map(g=>t.jsx(Zc,{worktree:g,onDelete:()=>P(g)},g.path))})})})]})]}):null]}):null}),e?t.jsx(To,{open:!!j,project:{id:e.id,path:e.path},worktree:j,onClose:()=>P(null),onDeleted:()=>{I(g=>g.filter(L=>L.path!==j?.path)),o?.()}}):null]})},tu=32,su=80,nu=64,ru=.7,Fn=(n,e)=>{const s=c.useRef(e);s.current=e;const o=e.enabled??!0;c.useEffect(()=>{if(!o)return;const r=n.current;if(!r)return;const a=window.Capacitor?.getPlatform?.()==="android"?su:tu;let u=!1,d=!1,f=0,l=0;const p=h=>{if(h.touches.length!==1){u=!1;return}const v=h.touches[0],S=r.clientWidth,w=v.clientX<=a,T=v.clientX>=S-a;u=w||T,d=w,f=v.clientX,l=v.clientY},b=h=>{if(!u)return;u=!1;const v=h.changedTouches[0];if(!v)return;const S=v.clientX-f,w=v.clientY-l;Math.abs(S)<nu||Math.abs(w)>Math.abs(S)*ru||d&&S<=0||!d&&S>=0||(d?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",p,{passive:!0}),r.addEventListener("touchend",b,{passive:!0}),()=>{r.removeEventListener("touchstart",p),r.removeEventListener("touchend",b)}},[o,n])},ou=new Set,iu=[["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"]],nn=7,As=40,au=16,Et=n=>n.parentID??null,us=n=>{const e=n;return Te(e.directory??e.project?.worktree??null)},lu=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},cu=n=>{if(n<=0)return"";const e=Date.now()-n;if(e<6e4)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const o=Math.floor(s/60);if(o<24)return`${o}h`;const r=Math.floor(o/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},uu=(n,e)=>{const s=Te(n),o=Te(e),r=o.endsWith("/")?o:`${o}/`;return!!(s&&o&&(s===o||s.startsWith(r)))},Ds=(n,e)=>n.worktrees.find(s=>Te(s.path)===e)??null,Io=(n,e)=>e===n.path||!!Ds(n,e),rn=(n,e)=>{const s=Te(e);return s?n.find(o=>Io(o,s))??null:null},on=(n,e,s)=>to([n.title,n.id,us(n),e],s),mn=n=>{const e=ce.c(17),{project:s,size:o}=n,r=o===void 0?"md":o,{currentTheme:i}=Yr(),a=s.icon?Qr[s.icon]:null,u=s.color?Xr[s.color]??null:null,d=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",f=r==="sm"?"size-3.5":"size-4";let l;e[0]!==a||e[1]!==u||e[2]!==f?(l=a?t.jsx(Q,{name:a,className:f,style:u?{color:u}:void 0}):t.jsx(ln,{className:f,style:u?{color:u}:void 0}),e[0]=a,e[1]=u,e[2]=f,e[3]=l):l=e[3];const p=l;let b;e[4]!==d?(b=Y("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",d),e[4]=d,e[5]=b):b=e[5];let h;e[6]!==s.iconBackground?(h=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[6]=s.iconBackground,e[7]=h):h=e[7];let v;e[8]!==i||e[9]!==p||e[10]!==s.iconImage||e[11]!==s.id?(v=s.iconImage?t.jsx(Zr,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[8]=i,e[9]=p,e[10]=s.iconImage,e[11]=s.id,e[12]=v):v=e[12];let S;return e[13]!==b||e[14]!==h||e[15]!==v?(S=t.jsx("span",{className:b,style:h,children:v}),e[13]=b,e[14]=h,e[15]=v,e[16]=S):S=e[16],S},du=n=>{const e=ce.c(2),{ariaLabel:s}=n;let o;return e[0]!==s?(o=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=o):o=e[1],o},kr=n=>{const e=ce.c(12),{onClick:s,className:o}=n,{t:r}=de();let i;e[0]!==r?(i=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=i):i=e[1];const a=i;let u;e[2]!==o?(u=Y("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",o),e[2]=o,e[3]=u):u=e[3];let d;e[4]!==s?(d=b=>{b.stopPropagation(),s()},e[4]=s,e[5]=d):d=e[5];let f,l;e[6]===Symbol.for("react.memo_cache_sentinel")?(f={touchAction:"manipulation"},l=t.jsx(Q,{name:"node-tree",className:"size-4"}),e[6]=f,e[7]=l):(f=e[6],l=e[7]);let p;return e[8]!==a||e[9]!==u||e[10]!==d?(p=t.jsx("button",{type:"button",className:u,"aria-label":a,title:a,onClick:d,style:f,children:l}),e[8]=a,e[9]=u,e[10]=d,e[11]=p):p=e[11],p},Sr=n=>{const e=ce.c(10),{label:s,onClick:o,className:r}=n;let i;e[0]!==r?(i=Y("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==o?(a=l=>{l.stopPropagation(),o()},e[2]=o,e[3]=a):a=e[3];let u,d;e[4]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},d=t.jsx(Q,{name:"add",className:"size-4"}),e[4]=u,e[5]=d):(u=e[4],d=e[5]);let f;return e[6]!==s||e[7]!==i||e[8]!==a?(f=t.jsx("button",{type:"button",className:i,"aria-label":s,title:s,onClick:a,style:u,children:d}),e[6]=s,e[7]=i,e[8]=a,e[9]=f):f=e[9],f},Rt=192,Do=180,Nr=n=>{const e=ce.c(25),{actionsWidth:s,actions:o,revealed:r,onRevealedChange:i,children:a}=n,u=c.useRef(null),d=c.useRef(null),f=c.useRef(!1),l=c.useRef(0),p=c.useRef(r);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=(R,x)=>{const D=u.current;D&&(D.style.transition=x?`transform ${Do}ms ease-out`:"none",D.style.transform=R===0?"none":`translateX(${R}px)`,l.current=R)},e[0]=b):b=e[0];const h=b;let v,S;e[1]!==s||e[2]!==r?(v=()=>{p.current=r,h(r?s:0,!0)},S=[s,h,r],e[1]=s,e[2]=r,e[3]=v,e[4]=S):(v=e[3],S=e[4]),c.useEffect(v,S);let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=R=>{if(R.touches.length!==1)return;const x=R.touches[0];d.current={x:x.clientX,y:x.clientY},f.current=!1},e[5]=w):w=e[5];const T=w;let N;e[6]!==s?(N=R=>{if(!d.current)return;const x=R.touches[0],D=x.clientX-d.current.x,K=x.clientY-d.current.y;if(!f.current){if(Math.abs(D)<8||Math.abs(D)<=Math.abs(K))return;f.current=!0}const g=p.current?s:0;h(Math.max(0,Math.min(s,g+D)),!1)},e[6]=s,e[7]=N):N=e[7];const C=N;let I;e[8]!==s||e[9]!==i?(I=()=>{if(d.current=null,!f.current)return;f.current=!1;const R=l.current>s/2;h(R?s:0,!0),R!==p.current&&i(R)},e[8]=s,e[9]=i,e[10]=I):I=e[10];const j=I;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"pan-y"},e[11]=P):P=e[11];let k;e[12]!==s?(k={width:s},e[12]=s,e[13]=k):k=e[13];const E=!r;let y;e[14]!==o||e[15]!==k||e[16]!==E?(y=t.jsx("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:k,"aria-hidden":E,children:o}),e[14]=o,e[15]=k,e[16]=E,e[17]=y):y=e[17];let z;e[18]!==a?(z=t.jsx("div",{ref:u,className:"relative flex w-full items-center bg-background",children:a}),e[18]=a,e[19]=z):z=e[19];let M;return e[20]!==j||e[21]!==C||e[22]!==y||e[23]!==z?(M=t.jsxs("div",{className:"relative overflow-hidden",onTouchStart:T,onTouchMove:C,onTouchEnd:j,onTouchCancel:j,style:P,children:[y,z]}),e[20]=j,e[21]=C,e[22]=y,e[23]=z,e[24]=M):M=e[24],M},fu=n=>{const e=ce.c(41),{initialTitle:s,indent:o,onSubmit:r,onCancel:i}=n,{t:a}=de(),[u,d]=c.useState(s),f=vu;let l;e[0]!==s||e[1]!==i||e[2]!==r||e[3]!==u?(l=()=>{const x=u.trim();if(!x||x===s.trim()){i();return}r(x)},e[0]=s,e[1]=i,e[2]=r,e[3]=u,e[4]=l):l=e[4];const p=l;let b;e[5]!==o?(b={paddingLeft:o},e[5]=o,e[6]=b):b=e[6];let h;e[7]!==p?(h=x=>{x.preventDefault(),p()},e[7]=p,e[8]=h):h=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=x=>d(x.target.value),e[9]=v):v=e[9];let S;e[10]!==i?(S=x=>Oa(x,i),e[10]=i,e[11]=S):S=e[11];let w;e[12]!==a?(w=a("sessions.sidebar.session.rename.save"),e[12]=a,e[13]=w):w=e[13];let T;e[14]!==a?(T=a("sessions.sidebar.session.menu.rename"),e[14]=a,e[15]=T):T=e[15];let N;e[16]===Symbol.for("react.memo_cache_sentinel")?(N={minHeight:0},e[16]=N):N=e[16];let C;e[17]!==S||e[18]!==w||e[19]!==T||e[20]!==u?(C=t.jsx("input",{ref:f,value:u,onChange:v,onKeyDown:S,"aria-label":w,placeholder:T,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:N,enterKeyHint:"done"}),e[17]=S,e[18]=w,e[19]=T,e[20]=u,e[21]=C):C=e[21];let I;e[22]!==a?(I=a("sessions.sidebar.session.rename.save"),e[22]=a,e[23]=I):I=e[23];let j,P;e[24]===Symbol.for("react.memo_cache_sentinel")?(j={touchAction:"manipulation",minHeight:0,minWidth:0},P=t.jsx(Q,{name:"check",className:"size-4"}),e[24]=j,e[25]=P):(j=e[24],P=e[25]);let k;e[26]!==I?(k=t.jsx("button",{type:"submit","aria-label":I,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:j,children:P}),e[26]=I,e[27]=k):k=e[27];let E;e[28]!==a?(E=a("sessions.sidebar.session.rename.cancel"),e[28]=a,e[29]=E):E=e[29];let y,z;e[30]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation",minHeight:0,minWidth:0},z=t.jsx(Q,{name:"close",className:"size-4"}),e[30]=y,e[31]=z):(y=e[30],z=e[31]);let M;e[32]!==i||e[33]!==E?(M=t.jsx("button",{type:"button",onClick:i,"aria-label":E,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:y,children:z}),e[32]=i,e[33]=E,e[34]=M):M=e[34];let R;return e[35]!==k||e[36]!==M||e[37]!==b||e[38]!==h||e[39]!==C?(R=t.jsxs("form",{className:"flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",style:b,onSubmit:h,children:[C,k,M]}),e[35]=k,e[36]=M,e[37]=b,e[38]=h,e[39]=C,e[40]=R):R=e[40],R},Cr=n=>{const e=ce.c(52),{session:s,active:o,indent:r,contextLabel:i,hasChildren:a,expanded:u,onToggleChildren:d,onSelect:f,revealed:l,onRevealedChange:p,confirmingDelete:b,onArchive:h,onRequestDelete:v,onConfirmDelete:S,renaming:w,onRequestRename:T,onSubmitRename:N,onCancelRename:C}=n,I=a===void 0?!1:a,j=u===void 0?!1:u,P=l===void 0?!1:l,k=b===void 0?!1:b,E=w===void 0?!1:w,{t:y}=de();let z;e[0]!==s?(z=cu(lu(s)),e[0]=s,e[1]=z):z=e[1];const M=z,R=s.title?.trim()||y("mobile.sessions.untitled"),x=!!(p&&h),D=Da(s.id,s.directory,x&&P),K=Ur(s.id),g=Gr(s.id),L=K?.type??"idle",F=L==="busy"||L==="retry",B=!F&&g>0&&!o,W=Kr(s.id,F),re=(F||B)&&W,ne=c.useRef(null),ee=c.useRef(null),_=c.useRef(!1),G=c.useRef(0),X=c.useRef(P);let V;e[2]===Symbol.for("react.memo_cache_sentinel")?(V=(Ae,Qe)=>{const Pe=ne.current;Pe&&(Pe.style.transition=Qe?`transform ${Do}ms ease-out`:"none",Pe.style.transform=Ae===0?"none":`translateX(${Ae}px)`,G.current=Ae)},e[2]=V):V=e[2];const Z=V;let te,se;e[3]!==P?(te=()=>{X.current=P,Z(P?Rt:0,!0)},se=[Z,P],e[3]=P,e[4]=te,e[5]=se):(te=e[4],se=e[5]),c.useEffect(te,se);let ae;e[6]!==x?(ae=Ae=>{if(!x||Ae.touches.length!==1)return;const Qe=Ae.touches[0];ee.current={x:Qe.clientX,y:Qe.clientY},_.current=!1},e[6]=x,e[7]=ae):ae=e[7];const ue=ae;let U;e[8]!==x?(U=Ae=>{if(!x||!ee.current)return;const Qe=Ae.touches[0],Pe=Qe.clientX-ee.current.x,lt=Qe.clientY-ee.current.y;if(!_.current){if(Math.abs(Pe)<8||Math.abs(Pe)<=Math.abs(lt))return;_.current=!0}const Ut=X.current?Rt:0,$e=Math.max(0,Math.min(Rt,Ut+Pe));Z($e,!1)},e[8]=x,e[9]=U):U=e[9];const ie=U;let xe;e[10]!==p?(xe=()=>{if(ee.current=null,!_.current)return;_.current=!1;const Ae=G.current>Rt/2;Z(Ae?Rt:0,!0),Ae!==X.current&&p?.(Ae)},e[10]=p,e[11]=xe):xe=e[11];const Ne=xe,q=o||void 0,ye="relative overflow-hidden";let Re;e[12]!==x?(Re=x?{touchAction:"pan-y"}:void 0,e[12]=x,e[13]=Re):Re=e[13];const _e=x?t.jsxs("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:{width:Rt},"aria-hidden":!P,children:[t.jsx("button",{type:"button",tabIndex:P?0:-1,className:Y("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",k?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":k?y("mobile.sessions.confirmDeleteSessionAria",{title:R}):y("mobile.sessions.deleteSessionAria",{title:R}),onClick:k?S:v,style:{touchAction:"manipulation"},children:t.jsx(_s,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:P?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":y("mobile.sessions.archiveSessionAria",{title:R}),onClick:h,style:{touchAction:"manipulation"},children:t.jsx(ll,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:P?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":y("mobile.sessions.renameSessionAria",{title:R}),onClick:T,style:{touchAction:"manipulation"},children:t.jsx(cn,{className:"size-[18px]"})}),t.jsx(pe,{variant:"ghost",size:"icon",tabIndex:P?0:-1,className:"flex-1 self-center text-muted-foreground",disabled:D.disabled,"aria-label":y("sessions.aiRename.action"),"aria-description":D.hint,title:D.hint,onClick:()=>{D.run(),p?.(!1)},style:{touchAction:"manipulation"},children:t.jsx(Q,{name:D.pending?"loader-4":"ai-generate-2",className:D.pending?"size-[18px] animate-spin":"size-[18px]"})})]}):null,Ie=x&&"bg-background",Ve=o&&(x?"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]":"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]");let Me;e[14]!==Ie||e[15]!==Ve?(Me=Y("relative flex items-center gap-1 transition-colors",Ie,Ve),e[14]=Ie,e[15]=Ve,e[16]=Me):Me=e[16];let Fe;e[17]!==D.pending||e[18]!==j||e[19]!==I||e[20]!==r||e[21]!==F||e[22]!==d||e[23]!==B||e[24]!==y?(Fe=D.pending||F||B||I&&d?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":D.pending?y("sessions.aiRename.generating"):y(j?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!I||!d,onClick:Ae=>{Ae.stopPropagation(),d?.()},children:D.pending?t.jsx(Q,{name:"loader-4",className:"size-3 animate-spin text-primary","aria-label":y("sessions.aiRename.generating")}):F||B?t.jsx("span",{className:Y("size-1.5 rounded-full",F?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):t.jsx(jn,{className:Y("size-[18px] transition-transform duration-150",j?"rotate-0":"-rotate-90")})}):null,e[17]=D.pending,e[18]=j,e[19]=I,e[20]=r,e[21]=F,e[22]=d,e[23]=B,e[24]=y,e[25]=Fe):Fe=e[25];let Ce;e[26]!==o||e[27]!==i||e[28]!==r||e[29]!==F||e[30]!==C||e[31]!==p||e[32]!==f||e[33]!==N||e[34]!==E||e[35]!==s.id||e[36]!==re||e[37]!==M||e[38]!==R?(Ce=E&&N&&C?t.jsx(fu,{initialTitle:R,indent:r,onSubmit:N,onCancel:C}):t.jsx("button",{type:"button",className:Y("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",i?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(X.current){p?.(!1);return}f()},children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("span",{className:"flex items-center gap-2.5",children:[t.jsx("span",{className:Y("block min-w-0 flex-1 truncate typography-ui-label",o?"text-primary":"text-foreground"),children:R}),re?t.jsx(io,{sessionId:s.id,running:F,className:"typography-micro"}):M?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:M}):null]}),i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null]})}),e[26]=o,e[27]=i,e[28]=r,e[29]=F,e[30]=C,e[31]=p,e[32]=f,e[33]=N,e[34]=E,e[35]=s.id,e[36]=re,e[37]=M,e[38]=R,e[39]=Ce):Ce=e[39];let Ee;e[40]!==Me||e[41]!==Fe||e[42]!==Ce?(Ee=t.jsxs("div",{ref:ne,className:Me,children:[Fe,Ce]}),e[40]=Me,e[41]=Fe,e[42]=Ce,e[43]=Ee):Ee=e[43];let ve;return e[44]!==Ne||e[45]!==ie||e[46]!==ue||e[47]!==q||e[48]!==Re||e[49]!==_e||e[50]!==Ee?(ve=t.jsxs("div",{"data-active-session":q,className:ye,onTouchStart:ue,onTouchMove:ie,onTouchEnd:Ne,onTouchCancel:Ne,style:Re,children:[_e,Ee]}),e[44]=Ne,e[45]=ie,e[46]=ue,e[47]=q,e[48]=Re,e[49]=_e,e[50]=Ee,e[51]=ve):ve=e[51],ve},mu=n=>{const e=ce.c(11),{indent:s,onClick:o}=n,{t:r}=de();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(jn,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=u):u=e[4];let d;e[5]!==u?(d=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=d):d=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==d?(f=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=f):f=e[10],f},pu=n=>{const e=ce.c(11),{indent:s,onClick:o}=n,{t:r}=de();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(cl,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=u):u=e[4];let d;e[5]!==u?(d=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=d):d=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==d?(f=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=f):f=e[10],f},hu=n=>{const e=ce.c(29),{worktree:s}=n,{t:o}=de();let r;e[0]!==s.path?(r=Te(s.path),e[0]=s.path,e[1]=r):r=e[1];const i=r;let a;e[2]!==i?(a={id:i},e[2]=i,e[3]=a):a=e[3];const{attributes:u,listeners:d,setNodeRef:f,transform:l,transition:p,isDragging:b}=Tn(a),h=s.branch||s.label||s.path;let v;e[4]!==l?(v=In.Transform.toString(l),e[4]=l,e[5]=v):v=e[5];const S=b?10:1;let w;e[6]!==v||e[7]!==S||e[8]!==p?(w={transform:v,transition:p,zIndex:S},e[6]=v,e[7]=S,e[8]=p,e[9]=w):w=e[9];const T=b&&"shadow-lg shadow-black/20";let N;e[10]!==T?(N=Y("flex items-center gap-1 rounded-xl bg-background px-1 py-1",T),e[10]=T,e[11]=N):N=e[11];let C;e[12]!==h||e[13]!==o?(C=o("mobile.sessions.dragHandleAria",{label:h}),e[12]=h,e[13]=o,e[14]=C):C=e[14];let I;e[15]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(wn,{className:"size-4"}),e[15]=I):I=e[15];let j;e[16]!==u||e[17]!==d||e[18]!==C?(j=t.jsx("button",{type:"button",className:"flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-lg text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":C,...u,...d,children:I}),e[16]=u,e[17]=d,e[18]=C,e[19]=j):j=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Q,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=P):P=e[20];let k;e[21]!==h?(k=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-bold text-muted-foreground",children:h}),e[21]=h,e[22]=k):k=e[22];let E;return e[23]!==f||e[24]!==j||e[25]!==k||e[26]!==w||e[27]!==N?(E=t.jsxs("div",{ref:f,style:w,className:N,children:[j,P,k]}),e[23]=f,e[24]=j,e[25]=k,e[26]=w,e[27]=N,e[28]=E):E=e[28],E},gu=n=>{const e=ce.c(61),{project:s,totalSessions:o,expanded:r,onToggleExpanded:i,onReorderWorktrees:a}=n,{t:u}=de();let d;e[0]!==s.id?(d={id:s.id},e[0]=s.id,e[1]=d):d=e[1];const{attributes:f,listeners:l,setNodeRef:p,transform:b,transition:h,isDragging:v}=Tn(d);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={activationConstraint:{distance:8}},e[2]=S):S=e[2];let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={coordinateGetter:Rn},e[3]=w):w=e[3];const T=kn(Bt(Nn,S),Bt(Sn,w)),N=s.worktrees.length>0;let C;e[4]!==a||e[5]!==s.worktrees?(C=_=>{const{active:G,over:X}=_;if(!X||G.id===X.id)return;const V=s.worktrees.map(wu),Z=V.indexOf(String(G.id)),te=V.indexOf(String(X.id));if(Z<0||te<0)return;const se=[...V],[ae]=se.splice(Z,1);se.splice(te,0,ae),a(se)},e[4]=a,e[5]=s.worktrees,e[6]=C):C=e[6];const I=C;let j;e[7]!==b?(j=In.Transform.toString(b),e[7]=b,e[8]=j):j=e[8];const P=v?10:1;let k;e[9]!==j||e[10]!==P||e[11]!==h?(k={transform:j,transition:h,zIndex:P},e[9]=j,e[10]=P,e[11]=h,e[12]=k):k=e[12];const E=v&&"shadow-lg shadow-black/20";let y;e[13]!==E?(y=Y("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",E),e[13]=E,e[14]=y):y=e[14];let z;e[15]!==s.label||e[16]!==u?(z=u("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=u,e[17]=z):z=e[17];let M;e[18]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(wn,{className:"size-4"}),e[18]=M):M=e[18];let R;e[19]!==f||e[20]!==l||e[21]!==z?(R=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":z,...f,...l,children:M}),e[19]=f,e[20]=l,e[21]=z,e[22]=R):R=e[22];let x;e[23]!==r||e[24]!==s.label||e[25]!==u?(x=r?u("sessions.sidebar.group.collapseAria",{label:s.label}):u("sessions.sidebar.group.expandAria",{label:s.label}),e[23]=r,e[24]=s.label,e[25]=u,e[26]=x):x=e[26];const D=!N;let K;e[27]===Symbol.for("react.memo_cache_sentinel")?(K={touchAction:"manipulation"},e[27]=K):K=e[27];let g;e[28]!==s?(g=t.jsx(mn,{project:s}),e[28]=s,e[29]=g):g=e[29];let L;e[30]!==s.label?(L=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s.label}),e[30]=s.label,e[31]=L):L=e[31];let F;e[32]!==o?(F=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:o}),e[32]=o,e[33]=F):F=e[33];let B;e[34]!==r||e[35]!==N?(B=N?t.jsx(jn,{className:Y("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=N,e[36]=B):B=e[36];let W;e[37]!==r||e[38]!==i||e[39]!==x||e[40]!==D||e[41]!==g||e[42]!==L||e[43]!==F||e[44]!==B?(W=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",onClick:i,"aria-expanded":r,"aria-label":x,disabled:D,style:K,children:[g,L,F,B]}),e[37]=r,e[38]=i,e[39]=x,e[40]=D,e[41]=g,e[42]=L,e[43]=F,e[44]=B,e[45]=W):W=e[45];let re;e[46]!==R||e[47]!==W?(re=t.jsxs("div",{className:"flex items-center gap-1",children:[R,W]}),e[46]=R,e[47]=W,e[48]=re):re=e[48];let ne;e[49]!==r||e[50]!==I||e[51]!==N||e[52]!==s.worktrees||e[53]!==T?(ne=r&&N?t.jsx(Cn,{sensors:T,collisionDetection:En,onDragEnd:I,children:t.jsx(Pn,{items:s.worktrees.map(ju),strategy:An,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map(ku)})})}):null,e[49]=r,e[50]=I,e[51]=N,e[52]=s.worktrees,e[53]=T,e[54]=ne):ne=e[54];let ee;return e[55]!==p||e[56]!==re||e[57]!==ne||e[58]!==k||e[59]!==y?(ee=t.jsxs("div",{ref:p,style:k,className:y,children:[re,ne]}),e[55]=p,e[56]=re,e[57]=ne,e[58]=k,e[59]=y,e[60]=ee):ee=e[60],ee},Er=({open:n,onOpenChange:e,variant:s="drawer",footer:o})=>{const{t:r}=de(),{git:i}=yn(),a=qr(),u=hn(m=>m.activeSessions),d=Wr(c.useCallback(m=>n||s==="sidebar"?m.ids:ou,[n,s])),f=Vr(c.useCallback(m=>n||s==="sidebar"?m.rankById:gi,[n,s])),l=We(m=>m.projects),p=We(m=>m.activeProjectId),b=xt(m=>m.currentDirectory),h=Se(m=>m.currentSessionId),v=Se(m=>m.setCurrentSession),S=Se(m=>m.archiveSession),w=Se(m=>m.archiveSessions),T=Se(m=>m.deleteSession),N=Se(m=>m.deleteSessions),C=Se(m=>m.updateSessionTitle),I=Se(m=>m.openNewSessionDraft),j=We(m=>m.setActiveProject),P=We(m=>m.setActiveProjectIdOnly),k=We(m=>m.reorderProjects),E=We(m=>m.manualProjectOrder),y=Jn(m=>m.projectSortOrder),z=Jn(m=>m.setProjectSortOrder),M=We(m=>m.removeProject),R=Rs(m=>m.projectExpanded),x=Rs(m=>m.worktreeExpanded),D=Rs(m=>m.setProjectExpanded),K=Rs(m=>m.setWorktreeExpanded),g=fn(m=>m.orderByProject),L=fn(m=>m.setWorktreeOrder),F=vr(m=>m.expandedParents),B=vr(m=>m.toggleParent),[W,re]=c.useState(""),[ne,ee]=c.useState(null),[_,G]=c.useState(null),[X,V]=c.useState(null),[Z,te]=c.useState(null),[se,ae]=c.useState(null),[ue,U]=c.useState(null),[ie,xe]=c.useState(null),[Ne,q]=c.useState(0),[ye,Re]=c.useState(!1),[_e,Ie]=c.useState(!1),[Ve,Me]=c.useState(!1),[Fe,Ce]=c.useState(null),[Ee,ve]=c.useState(()=>new Map(Se.getState().availableWorktreesByProject)),[Ae,Qe]=c.useState(()=>{const m=new Set;for(const[$,H]of Se.getState().availableWorktreesByProject)H.length>0&&m.add($);return m}),[Pe,lt]=c.useState(!1),[Ut,$e]=c.useState(new Set),[Ue,et]=c.useState(new Map);c.useEffect(()=>{if(!n){re(""),lt(!1),$e(new Set),et(new Map),ee(null),G(null),V(null),te(null),ae(null),U(null);return}xn(a)},[n]),c.useEffect(()=>{Pe||$e(new Set)},[Pe]),c.useEffect(()=>{if(!n||l.length===0)return;let m=!1;return(async()=>{const H=await Promise.all(l.map(async me=>{const fe=Te(me.path);if(!fe)return null;const Le=await i.checkIsGitRepository(fe).catch(()=>!1),Ze=Le?await so({id:me.id,path:fe}).catch(()=>[]):[];return[fe,Ze,Le]}));if(m)return;const oe=new Map,he=new Set;for(const me of H)me&&(oe.set(me[0],me[1]),me[2]&&he.add(me[0]));ve(no(l,oe)),Qe(he)})(),()=>{m=!0}},[i,n,l,Ne]);const we=c.useMemo(()=>Ra(l.map(m=>({id:m.id,label:m.label?.trim()||tn(m.path),path:Te(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:Ae.has(Te(m.path)),worktrees:Jc(g[m.id],Ee.get(Te(m.path))??[]),addedAt:m.addedAt,lastOpenedAt:m.lastOpenedAt})),y,E),[Ae,E,y,l,g,Ee]),Ge=c.useMemo(()=>{const m=new Map(a.map(oe=>[oe.id,oe])),$=u.map(oe=>{const he=m.get(oe.id);return he?bi(he,oe):oe}),H=new Set($.map(oe=>oe.id));for(const oe of a)H.has(oe.id)||$.push(oe);return $.filter(oe=>!oe.time?.archived)},[u,a]),Vs=c.useMemo(()=>{const m=new Map;for(const $ of Ge){const H=Et($);if(!H)continue;const oe=m.get(H)??[];oe.push($),m.set(H,oe)}return m},[Ge]),{projectSessions:Gt,chatSessions:be}=c.useMemo(()=>Pa(Ge,!1),[Ge]),Kt=c.useMemo(()=>({key:ss,label:"",path:"",worktree:null,sessions:Xs(be,d,f)}),[be,d,f]),Ht=`${ss}::${ss}`,rt=c.useMemo(()=>be.filter(m=>!Et(m)).length,[be]),ze=W.trim().toLowerCase(),gs=c.useRef(null);c.useEffect(()=>{if(!n)return;const m=window.requestAnimationFrame(()=>{const $=gs.current;if(!$)return;($.querySelector('[data-active-session="true"]')??$.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[n]);const kt=c.useMemo(()=>{const m=we.map(H=>({project:H,buckets:[],totalSessions:0,isActive:H.id===p})),$=(H,oe,he)=>{const me=Te(oe)||H.project.path,fe=me||"__root__";let Le=H.buckets.find(Ze=>Ze.key===fe);return Le||(Le={key:fe,label:he?.branch||tn(me),path:me,worktree:he,sessions:[]},H.buckets.push(Le)),Le};for(const H of m){$(H,H.project.path,null);for(const oe of H.project.worktrees)$(H,oe.path,oe)}for(const H of Gt){const oe=us(H);if(!oe)continue;const he=Te(oe),me=m.find(Ze=>Io(Ze.project,he));if(!me)continue;const fe=Ds(me.project,he);(fe?$(me,fe.path,fe):$(me,me.project.path,null)).sessions.push(H)}for(const H of m)for(const oe of H.buckets){oe.sessions=Xs(oe.sessions,d,f);for(const he of oe.sessions)Et(he)||(H.totalSessions+=1)}return m},[p,d,Gt,we,f]),bs=Te(b),dt=m=>m.isActive?bs===m.project.path?m.project.path:m.project.worktrees.find(H=>uu(bs,H.path))?.path??m.project.path:null,Ke=m=>R[m.project.id]??!0,tt=(m,$)=>x[`${m.project.id}::${$.key}`]??!0,St=m=>{et($=>{if(!$.has(m))return $;const H=new Map($);return H.delete(m),H})},ct=m=>{et($=>{let H=!1;const oe=new Map($),he=`${m}::`;for(const me of oe.keys())me.startsWith(he)&&(oe.delete(me),H=!0);return H?oe:$})},Us=(m,$)=>{et(H=>{const oe=new Map(H);return oe.set(m,$+nn),oe})},qt=(m,$,H)=>{const oe=new Set($.sessions.map(ke=>ke.id)),he=new Map;for(const ke of $.sessions){const nt=Et(ke);if(nt&&oe.has(nt)){const es=he.get(nt)??[];es.push(ke),he.set(nt,es)}}const me=$.sessions.filter(ke=>{const nt=Et(ke);return!nt||!oe.has(nt)}),fe=Ue.get(m)??nn,Le=me.slice(0,fe),Ze=me.length-Le.length,Js=me.length>nn&&Ze===0,Kn=(ke,nt)=>{const es=he.get(ke.id)??[],Ys=es.length>0,Hn=!!F[ke.id];return t.jsxs(c.Fragment,{children:[t.jsx(Cr,{session:ke,active:h===ke.id,indent:nt,hasChildren:Ys,expanded:Hn,onToggleChildren:Ys?()=>B(ke.id):void 0,onSelect:()=>xs(ke),revealed:_===ke.id,onRevealedChange:ts=>Nt(ke.id,ts),confirmingDelete:X===ke.id,onArchive:()=>{Ct(ke)},onRequestDelete:()=>V(ke.id),onConfirmDelete:()=>{vs(ke)},renaming:Z===ke.id,onRequestRename:()=>mt(ke.id),onSubmitRename:ts=>{Jt(ke.id,ts)},onCancelRename:()=>te(null)}),Ys&&Hn?es.map(ts=>Kn(ts,nt+au)):null]},ke.id)};return t.jsxs("div",{children:[Le.map(ke=>Kn(ke,H)),Ze>0?t.jsx(mu,{indent:H,onClick:()=>Us(m,Le.length)}):null,Js?t.jsx(pu,{indent:H,onClick:()=>St(m)}):null]})},Oe=(m,$)=>{D(m,!$),ct(m)},Gs=(m,$,H)=>{K(`${m}::${$}`,!H),St(`${m}::${$}`)},xs=m=>{const $=us(m)||null,H=rn(we,$??"");if(H){P(H.id),D(H.id,!0);const oe=Ds(H,Te($??""));oe&&K(`${H.id}::${Te(oe.path)}`,!0)}v(m.id,$),e(!1)},Nt=(m,$)=>{G($?m:null),V(null),ae(null),U(null)},ft=(m,$)=>{ae($?m:null),U(null),G(null),V(null)},ys=(m,$)=>(G(null),V(null),_a(m,$,Ma($.id,za(Vs,$.id),m==="delete"),{archiveSession:S,archiveSessions:w,deleteSession:T,deleteSessions:N},r)),Ct=m=>ys("archive",m),vs=m=>ys("delete",m),mt=m=>{G(null),V(null),te(m)},Jt=async(m,$)=>{te(null);try{await C(m,$)}catch{le.error(r("mobile.sessions.renameError"))}},Yt=()=>{I(),e(!1)},Xt=m=>{Ce(m),P(m),Me(!0)},Ks=kn(Bt(Nn,{activationConstraint:{distance:8}}),Bt(Sn,{coordinateGetter:Rn})),Hs=m=>{z(m),Vo({sidebarProjectSortOrder:m}),m!=="manual"&<(!1)},ws=m=>{const{active:$,over:H}=m;if(!H||$.id===H.id)return;const oe=we.findIndex(me=>me.id===$.id),he=we.findIndex(me=>me.id===H.id);oe<0||he<0||k(oe,he)},qs=m=>{$e($=>{const H=new Set($);return H.has(m)?H.delete(m):H.add(m),H})},Qt=c.useCallback(m=>{const $=us(m);if(xi($))return r("mobile.sessions.section.chats");const H=rn(we,$);if(!H)return tn($)||$;const oe=Ds(H,Te($));return oe?.branch?`${H.label} · ${oe.branch}`:H.label},[we,r]),js=m=>{j(m.id),e(!1)},Zt=m=>{P(m.id),I({selectedProjectId:m.id,directoryOverride:m.path}),e(!1)},A=c.useMemo(()=>ze?kt.filter(m=>to([m.project.label,m.project.path],ze)?!0:m.buckets.some($=>$.sessions.some(H=>on(H,m.project.label,ze)))):kt,[ze,kt]),O=c.useMemo(()=>ze?Xs(Ge.filter(m=>{if(Et(m))return!1;const $=us(m),H=rn(we,$);return on(m,H?.label??"",ze)}),d,f):[],[ze,d,we,f,Ge]),J=c.useMemo(()=>ze?yi(we,ze,m=>[m.label,m.path]):[],[ze,we]),je=ze&&O.length===0&&J.length===0,st=!ze&&we.length>1&&y==="manual",ks=!Pe&&!ze&&we.length>1?t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.sortProjects"),title:r("sessions.sidebar.header.actions.sortProjects"),onClick:()=>Re(!0),style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"equalizer-2",className:"size-4"})}):null,pt=st?t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r(Pe?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":Pe,onClick:()=>lt(m=>!m),style:{touchAction:"manipulation"},children:Pe?t.jsx(ao,{className:"size-4"}):t.jsx(cn,{className:"size-4"})}):null,Ss=!Pe&&we.length>0?t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:Yt,style:{touchAction:"manipulation"},children:[t.jsx(al,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,Un=Pe?null:t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>Ie(!0),style:{touchAction:"manipulation"},children:t.jsx(nr,{className:"size-4"})}),Ns=Ss||Un||ks||pt?t.jsxs(t.Fragment,{children:[Un,ks,pt,Ss]}):null,Gn=t.jsxs("div",{ref:gs,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs($s,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:Y("px-4 pb-2 pt-1",Pe&&"hidden"),children:t.jsx(Aa,{value:W,onSearch:re,active:n||s==="sidebar",mobile:!0,placeholder:r("mobile.sessions.search.placeholder"),clearLabel:r("mobile.sessions.clearSearchAria")})}),we.length===0&&be.length===0?t.jsx(Ar,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>Ie(!0),children:[t.jsx(nr,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):je?t.jsx(Ar,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):ze&&!Pe?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[O.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:O.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:O.map((m,$)=>t.jsx("div",{className:Y($>0&&"border-t border-border/70"),children:t.jsx(Cr,{session:m,active:h===m.id,indent:12,contextLabel:Qt(m),onSelect:()=>xs(m)})},m.id))})]}):null,J.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:J.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:J.map((m,$)=>t.jsxs("div",{className:Y("flex items-center",$>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>js(m),style:{touchAction:"manipulation"},children:[t.jsx(mn,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label})]}),m.isGitRepo?t.jsx(kr,{onClick:()=>Xt(m.id)}):null,t.jsx(Sr,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.label}),onClick:()=>Zt(m)})]},m.id))})]}):null]}):Pe?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx(Cn,{sensors:Ks,collisionDetection:En,onDragEnd:ws,children:t.jsx(Pn,{items:we.map(m=>m.id),strategy:An,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:we.map(m=>{const $=kt.find(H=>H.project.id===m.id);return t.jsx(gu,{project:m,totalSessions:$?.totalSessions??0,expanded:Ut.has(m.id),onToggleExpanded:()=>qs(m.id),onReorderWorktrees:H=>L(m.id,H)},m.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const m=R[ss]??!0,$=r("mobile.sessions.section.chats");return t.jsxs("section",{children:[t.jsx("div",{className:"flex min-h-12 w-full items-center",children:t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(se){ft(se,!1);return}Oe(ss,m)},"aria-expanded":m,"aria-label":m?r("sessions.sidebar.group.collapseAria",{label:$}):r("sessions.sidebar.group.expandAria",{label:$}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(Q,{name:"chat-4",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:$}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:rt})]})}),m?t.jsx("div",{className:"pb-2",children:Kt.sessions.length>0?qt(Ht,Kt,As):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:As},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),A.map(m=>{const $=Ke(m),H=ze?m.buckets.filter(he=>he.sessions.some(me=>on(me,m.project.label,ze))):m.buckets,oe=dt(m);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(Nr,{actionsWidth:96,revealed:se===`project:${m.project.id}`,onRevealedChange:he=>ft(`project:${m.project.id}`,he),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:se===`project:${m.project.id}`?0:-1,className:Y("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",ue===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":ue===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(ue===m.project.id){ae(null),U(null),M(m.project.id),le.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}U(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(_s,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:se===`project:${m.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{ae(null),ee(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(cn,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":m.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(se){ft(se,!1);return}Oe(m.project.id,$)},"aria-expanded":$,"aria-label":$?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(mn,{project:m.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:m.project.label})]}),m.project.isGitRepo?t.jsx(kr,{onClick:()=>Xt(m.project.id)}):null,t.jsx(Sr,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.project.label}),onClick:()=>Zt(m.project)})]})}),$?t.jsx("div",{className:"pb-2",children:(()=>{const he=H.find(fe=>fe.worktree===null),me=H.filter(fe=>fe.worktree!==null);return t.jsxs(t.Fragment,{children:[he&&he.sessions.length>0?qt(`${m.project.id}::${he.key}`,he,As):null,me.map(fe=>{const Le=tt(m,fe),Ze=oe===fe.path;return t.jsxs("div",{children:[t.jsx(Nr,{actionsWidth:48,revealed:se===`wt:${fe.key}`,onRevealedChange:Js=>ft(`wt:${fe.key}`,Js),actions:t.jsx("button",{type:"button",tabIndex:se===`wt:${fe.key}`?0:-1,className:"flex flex-1 items-center justify-center text-[var(--status-error)] transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive","aria-label":r("mobile.projectEdit.deleteWorktreeAria",{label:fe.label}),onClick:()=>{ae(null),fe.worktree&&xe({project:m.project,worktree:fe.worktree})},style:{touchAction:"manipulation"},children:t.jsx(_s,{className:"size-[18px]"})}),children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(se){ft(se,!1);return}Gs(m.project.id,fe.key,Le)},"aria-expanded":Le,"aria-label":Le?r("sessions.sidebar.group.collapseAria",{label:fe.label}):r("sessions.sidebar.group.expandAria",{label:fe.label}),style:{touchAction:"manipulation"},children:[t.jsx(Q,{name:"git-branch",className:Y("size-4 shrink-0",Ze?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Y("block min-w-0 flex-1 truncate typography-ui-label font-bold",Ze?"text-foreground":"text-muted-foreground"),children:fe.label}),Ze?t.jsx(du,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:fe.sessions.length})]})}),Le?qt(`${m.project.id}::${fe.key}`,fe,As):null]},fe.key)})]})})()}):null]},m.project.id)})]})]}),o?t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/70 px-2 pt-1.5",style:{paddingBottom:"calc(0.375rem + var(--oc-safe-area-bottom, 0px))"},children:[o.instanceLabel&&o.onOpenInstances?t.jsxs(pe,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:o.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(Q,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:o.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o.onOpenUpdate?t.jsxs(pe,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(Q,{name:"download",className:"size-5"}),t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0})]}):null,t.jsx(pe,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(Ta,{open:_e,onOpenChange:Ie}),t.jsx(Ia,{open:Ve,onOpenChange:m=>{Me(m),m||Ce(null)},onWorktreeCreated:(m,$)=>{$?.sessionId?v($.sessionId,m):I({selectedProjectId:Fe,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(eu,{open:ne!==null,project:we.find(m=>m.id===ne)??null,onClose:()=>ee(null),onWorktreesChanged:()=>q(m=>m+1)}),t.jsx(Jr,{open:ye,onClose:()=>Re(!1),title:r("sessions.sidebar.header.actions.sortProjects"),children:t.jsx("div",{className:"flex flex-col",children:iu.map(([m,$])=>t.jsxs("button",{type:"button",className:Y("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",y===m?"text-primary":"text-foreground"),onClick:()=>{Hs(m),Re(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r($)}),y===m?t.jsx(Q,{name:"check",className:"size-4"}):null]},m))})}),ie?t.jsx(To,{open:!0,project:{id:ie.project.id,path:ie.project.path},worktree:ie.worktree,onClose:()=>xe(null),onDeleted:()=>q(m=>m+1)}):null]});return s==="sidebar"?n?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Ns?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Ns}):null]}),Gn]}):null:t.jsxs(yu,{open:n,onClose:()=>e(!1),onSwipeClose:()=>{if(_||se){G(null),ae(null),V(null),U(null);return}e(!1)},ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Ns?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Ns}):null]}),Gn]})},Rr="mobile-surface-root",bu=16,Pr=320,xu="cubic-bezier(0.22, 1, 0.36, 1)",yu=({open:n,onClose:e,onSwipeClose:s,ariaLabel:o,children:r})=>{const i=c.useRef(null),a=c.useRef(null),[u,d]=c.useState(!1),[f,l]=c.useState(n),p=c.useRef(e);c.useEffect(()=>{p.current=e},[e]);const b=c.useRef(s);if(c.useEffect(()=>{b.current=s},[s]),Fn(a,{enabled:n,onRightEdgeSwipe:()=>(b.current??p.current)()}),typeof document<"u"&&!i.current){let h=document.getElementById(Rr);h||(h=document.createElement("div"),h.id=Rr,document.body.appendChild(h)),i.current=h}return c.useEffect(()=>{if(n){l(!0);const v=window.setTimeout(()=>d(!0),bu);return()=>window.clearTimeout(v)}d(!1);const h=window.setTimeout(()=>l(!1),Pr+40);return()=>window.clearTimeout(h)},[n]),c.useEffect(()=>{if(!n)return;const h=document.body.style.overflow;document.body.style.overflow="hidden";const v=S=>{S.key==="Escape"&&p.current()};return document.addEventListener("keydown",v),()=>{document.body.style.overflow=h,document.removeEventListener("keydown",v)}},[n]),i.current?zt.createPortal(t.jsx("section",{ref:a,role:"dialog","aria-modal":"true","aria-label":o,"aria-hidden":!n,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:u?"none":"translateX(-100%)",transition:`transform ${Pr}ms ${xu}`,visibility:f?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r})}),i.current):null},Ar=n=>{const e=ce.c(10),{title:s,description:o,action:r}=n;let i;e[0]!==s?(i=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=i):i=e[1];let a;e[2]!==o?(a=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[2]=o,e[3]=a):a=e[3];let u;e[4]!==r?(u=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=u):u=e[5];let d;return e[6]!==i||e[7]!==a||e[8]!==u?(d=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[i,a,u]}),e[6]=i,e[7]=a,e[8]=u,e[9]=d):d=e[9],d};function vu(n){n&&(n.focus(),n.select())}function wu(n){return Te(n.path)}function ju(n){return Te(n.path)}function ku(n){return t.jsx(hu,{worktree:n},Te(n.path))}const Su=(n,e)=>{if(!n)return e("mcpDropdown.status.unknown");switch(n.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:n.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:n.error||""});default:return n.status}},Nu=n=>{switch(n?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Cu=({active:n,className:e,headerAction:s,listClassName:o,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:a}=de(),d=xt(j=>j.currentDirectory)??null,f=os(j=>j.getStatusForDirectory(d)),l=os(j=>j.refresh),p=os(j=>j.connect),b=os(j=>j.disconnect),h=_t(j=>j.mcpServers),v=_t(j=>j.loadMcpConfigs),[S,w]=c.useState(!1),[T,N]=c.useState(null);c.useEffect(()=>{l({directory:d,silent:!0})},[l,d]),c.useEffect(()=>{v({force:!0})},[v]),c.useEffect(()=>{n&&Promise.all([l({directory:d,silent:!0}),v({force:!0})])},[n,l,d,v]);const C=c.useMemo(()=>{const j=new Set(Object.keys(f));for(const P of h)P?.name&&j.add(P.name);return Array.from(j).sort((P,k)=>P.localeCompare(k))},[h,f]),I=c.useCallback(j=>{if(j?.preventDefault(),S)return;w(!0);const P=new Promise(k=>setTimeout(k,500));Promise.all([l({directory:d}),P]).finally(()=>{w(!1)})},[S,l,d]);return t.jsxs("div",{className:Y("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("mcpDropdown.title")}),d&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:d.split("/").pop()||d})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:S,onClick:I,"aria-label":a("mcpDropdown.actions.refreshAria"),children:t.jsx(Q,{name:"refresh",className:Y("h-4 w-4",S&&"animate-spin")})})]})]})}),t.jsx("div",{className:Y("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",o),children:t.jsxs("div",{className:Y(!i&&C.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[C.map(j=>{const P=f[j],k=Nu(P),E=P?.status==="connected",y=T===j,z=Su(P,a);return t.jsxs("div",{className:Y("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(vi,{children:[t.jsx(wi,{asChild:!0,children:t.jsx("span",{className:Y("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",k==="success"&&"bg-status-success",k==="error"&&"bg-status-error",k==="warning"&&"bg-status-warning",k==="default"&&"bg-muted-foreground/40"),"aria-label":z})}),t.jsx(ji,{side:"left",children:t.jsx("p",{children:z})})]}),t.jsx("span",{className:Y("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:j})]})}),t.jsx(ki,{checked:E,disabled:y,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{N(j);try{if(!M){await b(j,d);return}const R=f?.[j]?.status;if(R==="needs_auth"||R==="needs_client_registration"){const{opened:x}=await Si({name:j,directory:d});x||or.error(a("mcpDropdown.toast.authorizeOpenFailed"));return}await p(j,d)}catch(R){or.error(R instanceof Error?R.message:a("mcpDropdown.toast.authorizeFailed"))}finally{N(null)}}})]},j)}),C.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:a("mcpDropdown.empty.configureInConfig")})]})})]})},Tr={status:"loading"},Pt={type:"list"},Eu=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ru=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},Pu=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Ir=(n,e)=>e?`${n}\0staged`:n,Au=n=>{const e=ce.c(8),s=vn()??null;let o;e[0]!==s?(o=Eu(s),e[0]=s,e[1]=o):o=e[1];const r=o,i=n.visible??!0;let a;e[2]!==i?(a={enabled:i},e[2]=i,e[3]=a):a=e[3];const u=Ni(r||null,a);let d;return e[4]!==n||e[5]!==u||e[6]!==r?(d=t.jsx(Tu,{...n,rootDirectory:r,repository:u}),e[4]=n,e[5]=u,e[6]=r,e[7]=d):d=e[7],d},Tu=({rootDirectory:n,repository:e,onClose:s,initialDiff:o,visible:r=!0})=>{const{t:i}=de(),{git:a}=yn(),{rootIsGitRepo:u,gitDirectory:d,nestedRepos:f}=e,l=d??n,p=Ci(l||null),b=Ei(l||null),h=Hr(l||null),v=Ri(l||null),S=He(A=>A.setActiveDirectory),w=He(A=>A.ensureAll),T=He(A=>A.ensureNestedRepos),N=He(A=>A.selectNestedRepo),C=He(A=>A.fetchStatus),I=He(A=>A.fetchBranches),j=He(A=>A.prefetchDiffs),P=He(A=>A.getDiff),k=He(A=>A.setDiff),E=He(A=>A.runtimeKey),y=JSON.stringify([E,l]),z=c.useRef(y);z.current=y;const[M,R]=c.useState(()=>({ownerKey:y,mode:"working",route:o?.path?{type:"diff",path:o.path,staged:o.staged}:Pt})),x=M.ownerKey===y?M.mode:"working",D=M.ownerKey===y?M.route:Pt,[K,g]=c.useState(!1),L=c.useCallback(A=>{R({ownerKey:y,mode:A,route:Pt}),g(!1)},[y]),F=c.useCallback(A=>{R(O=>({ownerKey:y,mode:O.ownerKey===y?O.mode:"working",route:A}))},[y]);c.useEffect(()=>{R(A=>A.ownerKey===y?A:{ownerKey:y,mode:"working",route:Pt}),g(!1)},[y]),c.useEffect(()=>{r||g(!1)},[r]),c.useEffect(()=>{o?.path&&R({ownerKey:z.current,mode:"working",route:{type:"diff",path:o.path,staged:o.staged}})},[o]);const[B,W]=c.useState(null),[re,ne]=c.useState(null),[ee,_]=c.useState(""),[G,X]=c.useState(new Set),[V,Z]=c.useState(!1),[te,se]=c.useState(!1),[ae,ue]=c.useState([]),[U,ie]=c.useState([]),[xe,Ne]=c.useState([]),[q,ye]=c.useState(null),[Re,_e]=c.useState(null),[Ie,Ve]=c.useState(null),[Me,Fe]=c.useState(0),[Ce,Ee]=c.useState(null),ve=p?.current??null,Ae=p?.tracking?.trim().split("/")[0],Qe=(Ae&&b?.defaultBranches?.[Ae])??b?.defaultBranches?.origin??null,Pe=Il(ve,Qe),lt=h===!1||Al(ve,Qe,p!==null,b!==null),Ut=vl(A=>A.setOverride),$e=wl(l||null,ve,r&&x==="branch"&&Pe),Ue=jl(l||null,ve,r&&x==="commit"&&h===!0),et=Ue.selectedCommit?.hash??null,we=kl(l||null,ve,r&&x==="pr"&&h===!0),Ge=we.selectedSource,Vs=c.useMemo(()=>x==="pr"?Ge:x==="branch"&&ve&&$e.base?{kind:"branch",baseRef:$e.base,headRef:ve}:x==="commit"&&et?{kind:"commit",hash:et}:null,[$e.base,ve,x,et,Ge]),Gt=x==="branch"?$e.revision:"",be=Rl(l||null,Vs,r&&h===!0,Gt),{fetchDiff:Kt}=be,Ht=c.useMemo(()=>be.files?[...be.files].sort((A,O)=>A.path.localeCompare(O.path)):null,[be.files]),rt=D.type==="comparison"&&D.sourceKey===be.key?D.path:null,[ze,gs]=c.useState(0),kt=c.useCallback(async A=>{try{const{diff:O}=await Kt(A),J={original:"",modified:"",isBinary:Sl(O)};return J.isBinary||(J.fileDiff=Nl(A,O)),{status:"ready",diff:J}}catch(O){return{status:"error",message:O instanceof Error?O.message:i("diffView.state.failedToLoadDiff")}}},[Kt,i]),bs=Pl(be.files?x==="pr"?JSON.stringify([be.key,be.revision]):be.key:null,r&&rt?rt:"",r?kt:null,Tr,JSON.stringify([Gt,x==="pr"?be.revision:0,ze])),dt=rt?bs.get(rt)??Tr:null;c.useEffect(()=>{x==="branch"&<&&L("working")},[lt,L,x]),c.useEffect(()=>{R(A=>A.ownerKey===y&&A.route.type==="comparison"&&A.route.sourceKey!==be.key?{...A,route:Pt}:A)},[be.key,y]);const Ke=c.useMemo(()=>{const A=p?.files??[],O=new Map;for(const J of A)O.set(J.path,J);return Array.from(O.values()).sort((J,je)=>J.path.localeCompare(je.path))},[p?.files]),tt=c.useMemo(()=>Ke.filter(Ru),[Ke]),St=c.useMemo(()=>Ke.filter(Pu),[Ke]),ct=c.useMemo(()=>{if(xe.length>0)return xe;const A=p?.tracking?.includes("/")?p.tracking.split("/")[0]:null;return A||q?[{name:A||"origin",fetchUrl:q??"",pushUrl:q??""}]:[]},[q,xe,p?.tracking]),Us=He(c.useCallback(A=>!l||D.type!=="diff"?null:A.directories.get(l)?.diffCache.get(Ir(D.path,D.staged))??null,[l,D])),qt=c.useMemo(()=>D.type!=="diff"?null:Ke.find(A=>A.path===D.path)??null,[Ke,D]),Oe=c.useCallback(async(A=!0)=>{if(l)try{await Promise.all([C(l,a),I(l,a)])}catch(O){A&&le.error(O instanceof Error?O.message:i("gitView.toast.refreshRepositoryFailed"))}},[l,I,C,a,i]),Gs=c.useMemo(()=>(b?.all??[]).filter(A=>!A.startsWith("remotes/")).sort(),[b]),xs=c.useMemo(()=>(b?.all??[]).filter(A=>A.startsWith("remotes/")).map(A=>A.replace(/^remotes\//,"")).sort(),[b]),Nt=c.useCallback(async A=>{if(!l)return;const O=A.replace(/^remotes\//,"");try{const J=await a.checkoutBranch(l,O);le.success(i("gitView.toast.checkedOut",{name:J.branch||O})),await Oe()}catch(J){le.error(J instanceof Error?J.message:i("gitView.toast.checkoutFailed",{name:O}))}},[l,a,Oe,i]),ft=c.useCallback(A=>{const O=A.replace(/^remotes\//,"");if((p?.files?.length??0)>0){Ee(O);return}Nt(O)},[Nt,p?.files]),ys=c.useCallback(async(A,O)=>{if(l)try{await a.createBranch(l,A,ve??"HEAD"),await a.checkoutBranch(l,A),O&&await a.gitPush(l,{remote:O.name,branch:A,options:["--set-upstream"]}),await Oe()}catch(J){throw le.error(J instanceof Error?J.message:i("gitView.toast.createBranchFailed")),J}},[ve,l,a,Oe,i]),Ct=c.useCallback(async()=>{if(!l){Ne([]),ye(null);return}try{const[A,O]=await Promise.all([a.getRemotes(l).catch(()=>[]),a.getRemoteUrl?a.getRemoteUrl(l).catch(()=>null):Promise.resolve(null)]);Ne(A),ye(O)}catch{Ne([]),ye(null)}},[l,a]);c.useEffect(()=>{!l||!r||(S(l),w(l,a))},[l,w,a,S,r]),c.useEffect(()=>{r&&Ct()},[Ct,r]),c.useEffect(()=>{if(!r||x!=="working"||!l||Ke.length===0)return;const A=Array.from(new Set([...tt.map(J=>J.path),...U,...Ke.slice(0,20).map(J=>J.path)])).filter(Boolean);if(A.length===0)return;const O=window.setTimeout(()=>{j(l,a,A,{maxFiles:40})},120);return()=>window.clearTimeout(O)},[Ke,l,a,x,j,tt,U,r]),c.useEffect(()=>{if(!r)return;if(D.type!=="diff"){_e(null);return}const A=Ir(D.path,D.staged);if(Ve(null),!l||P(l,A)){_e(null);return}let O=!1;const J=Wt();return _e(null),a.getGitFileDiff(l,{path:D.path,staged:D.staged||void 0}).then(je=>{O||k(l,A,{original:je.original??"",modified:je.modified??"",isBinary:je.isBinary,submodule:je.submodule},J)}).catch(je=>{if(!O){if(je instanceof Yn&&je.reason!=="path_not_found"){Ve({key:`${l}\0${D.path}`,reason:je.reason});return}je instanceof Yn&&C(l,a,{force:!0,silent:!0}),_e(je instanceof Error?je.message:String(je))}}),()=>{O=!0}},[l,Me,C,P,a,D,k,r]);const vs=async(A,O)=>{if(l){W(A);try{if(A==="fetch"){if(!O)throw new Error(i("mobile.changes.noRemote"));await a.gitFetch(l,{remote:O.name}),le.success(i("gitView.toast.fetchedFromRemote",{name:O.name}))}else if(A==="sync"){if(!O)throw new Error(i("mobile.changes.noRemote"));let J=0;const je=await ir({git:a,directory:l,remote:O,dirtyWorktreeError:i("gitView.toast.commitOrStashBeforeSync"),onPulled:st=>{J=st.files.length}});J>0&&le.success(J===1?i("gitView.toast.pulledFilesSingle",{count:J,name:O.name}):i("gitView.toast.pulledFilesPlural",{count:J,name:O.name})),je.pushed.length>0?le.success(i("gitView.toast.pushedToUpstream",{name:je.pushed[0].remote})):J===0&&le.success(i("gitView.toast.alreadyUpToDate"))}await Oe(!1),await Ct()}catch(J){le.error(J instanceof Error?J.message:i("gitView.toast.syncActionFailed",{action:i("gitView.sync.syncChanges")}))}finally{W(null)}}},mt=c.useCallback(async(A,O)=>{if(!(!l||A.length===0))try{O==="stage"?A.length>1?await Pi(l,A):await Ai(l,A[0]):A.length>1?await Ti(l,A):await Ii(l,A[0]),await Oe(!1)}catch(J){le.error(J instanceof Error?J.message:i(O==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[l,Oe,i]),Jt=c.useCallback((A,O=!1)=>{F({type:"diff",path:A,staged:O})},[F]),Yt=c.useCallback(async A=>{if(l){X(O=>new Set(O).add(A));try{await a.revertGitFile(l,A),le.success(i("gitView.toast.revertedFile",{path:A})),await Oe(!1)}catch(O){le.error(O instanceof Error?O.message:i("gitView.toast.revertFailed"))}finally{X(O=>{const J=new Set(O);return J.delete(A),J})}}},[l,a,Oe,i]),Xt=c.useCallback(async A=>{if(!l||A.length===0||V)return;const O=Array.from(new Set(A));Z(!0),X(new Set(O));try{await Promise.all(O.map(J=>a.revertGitFile(l,J))),await Oe(!1),le.success(O.length===1?i("gitView.toast.revertedFilesSingle",{count:O.length}):i("gitView.toast.revertedFilesPlural",{count:O.length}))}catch(J){le.error(J instanceof Error?J.message:i("gitView.toast.revertFailed"))}finally{X(new Set),Z(!1)}},[l,a,V,Oe,i]),Ks=c.useCallback(A=>{const O=A.map(J=>J.trim()).filter(Boolean);if(O.length===0){ue([]);return}_(J=>`${J.trim()}${J.trim()?`
|
|
23
|
-
|
|
24
|
-
`:""}${O.join(`
|
|
25
|
-
`)}`.trim()),ue([])},[]),Hs=c.useCallback(async()=>{if(!l)return;const A=tt.map(O=>O.path).sort();if(A.length===0){le.error(i("gitView.toast.selectFileToDescribe"));return}se(!0);try{const{message:O}=await sr(l,A);_(O.subject?.trim()??""),ue(Array.isArray(O.highlights)?O.highlights:[])}catch(O){le.error(O instanceof Error?O.message:i("gitView.toast.generateCommitMessageFailed"))}finally{se(!1)}},[l,tt,i]),ws=async(A={})=>{if(!l)return;if(!ee.trim()){le.error(i("gitView.toast.enterCommitMessage"));return}const O=tt.map(J=>J.path).sort();if(O.length===0){le.error(i("gitView.toast.selectFileToCommit"));return}ne(A.pushAfter?"commitAndPush":"commit");try{if(await a.createGitCommit(l,ee.trim(),{files:O}),le.success(i("gitView.toast.commitCreated")),_(""),ue([]),A.pushAfter){const J=p?.tracking?.split("/")[0],je=ct.find(st=>st.name===J)??ct[0];if(!je)throw new Error(i("mobile.changes.noRemote"));W("sync"),await ir({git:a,directory:l,remote:je,dirtyWorktreeError:i("gitView.toast.commitOrStashBeforeSync"),onPushed:st=>{le.success(i("gitView.toast.pushedToUpstream",{name:st.pushed[0].remote}))}}),await Oe(!1),await Ct()}else await Oe(!1)}catch(J){le.error(J instanceof Error?J.message:i("gitView.toast.createCommitFailed"))}finally{ne(null),A.pushAfter&&W(null)}},qs=c.useMemo(()=>{const A=[];return tt.length>0&&A.push({id:"staged",title:i("gitView.changes.stagedTitle"),entries:tt,statsScope:"staged",actionSymbol:"-",actionAllLabel:i("gitView.changes.unstageAllAria"),getActionLabel:O=>i("gitView.changes.unstageFileAria",{path:O}),onActionFile:O=>{mt([O],"unstage")},onActionAll:O=>{mt(O,"unstage")},onViewDiff:O=>Jt(O,!0),onRevertFile:Yt,showRevertActions:!1,accent:!0}),St.length>0&&A.push({id:"unstaged",title:i("gitView.changes.title"),entries:St,statsScope:"working",actionSymbol:"+",actionAllLabel:i("gitView.changes.stageAllAria"),getActionLabel:O=>i("gitView.changes.stageFileAria",{path:O}),onActionFile:O=>{mt([O],"stage")},onActionAll:O=>{mt(O,"stage")},onViewDiff:O=>Jt(O,!1),onRevertFile:Yt}),A},[Yt,Jt,mt,tt,i,St]),Qt=A=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":i("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:i("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:p?.current||l||""})]}),u===!1&&Array.isArray(f)&&f.length>0?t.jsx(Fa,{repositories:f,selectedRepository:d??null,onSelectRepository:O=>{n&&N(n,O)},repositoryRoot:n??void 0}):null]}),t.jsx("div",{className:"min-h-0 flex-1",children:A})]});if(!l)return Qt(t.jsx(Ye,{message:i("gitView.empty.selectSessionOrDirectory")}));if(u===!1&&h!==!0)return Qt(t.jsx(Wa,{rootIsGitRepo:u,resolvedIsGitRepo:h,nestedRepos:f,onRetryDiscovery:()=>{n&&T(n,{force:!0})}}));if(v&&h===null)return Qt(t.jsx(Ye,{loading:!0,message:i("gitView.loading.checkingRepository")}));if(D.type==="diff")return t.jsx(Dr,{path:D.path,diff:Us,staged:D.staged,fileExists:!!qt,unavailableReason:Ie?.key===`${l}\0${D.path}`?Ie.reason:null,error:Re,onBack:()=>F({type:"list"}),onRetry:()=>Fe(A=>A+1)});const js=i(x==="pr"?"session.githubIntegration.tabs.pullRequests":x==="branch"?"diffView.scope.branch":x==="commit"?"commitComparison.mode":"mobile.nav.changes"),Zt=x==="branch"&&$e.base?Ba($e.base):x==="commit"?et?.slice(0,8):x==="pr"&&Ge?`#${Ge.number}`:null;if(rt&&dt)return t.jsx(Dr,{path:rt,subtitle:[js,Zt].filter(Boolean).join(" · "),diff:dt.status==="ready"?dt.diff:null,fileExists:!be.files||be.files.some(A=>A.path===rt),error:be.error??(dt.status==="error"?dt.message:null),onBack:()=>F(Pt),onRetry:()=>{be.error&&be.refresh(),gs(A=>A+1)}});const Vn=()=>x==="pr"&&!Ge?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx(Ye,{loading:we.loading,message:we.error??(we.loading?i("session.githubPrPicker.loading.pullRequests"):i("pullRequestComparison.select"))}),!we.loading&&t.jsx(ar,{mobile:!0,comparison:we})]}):x==="branch"&&!$e.base?t.jsx(Ye,{loading:!$e.resolved,message:$e.resolved?i("gitView.pr.toast.baseBranchRequired"):i("diffView.branch.resolvingBase")}):x==="commit"&&!et?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[Ue.loading&&t.jsx(Q,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:Ue.loading?i("diffView.state.loadingChanges"):Ue.error??i("commitComparison.noCommits")}),Ue.error&&t.jsx(pe,{variant:"outline",size:"lg",onClick:()=>{Ue.refresh()},children:i("diffView.actions.retry")})]}):be.error?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"typography-ui-label font-semibold",children:i("diffView.state.failedToLoadDiff")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:be.error}),t.jsx(pe,{variant:"outline",size:"lg",onClick:()=>{be.refresh()},children:i("diffView.actions.retry")})]}):Ht?Ht.length===0?t.jsx(Ye,{icon:x==="branch",message:x==="pr"?i("walkthrough.blocked.emptyDiff.description"):x==="commit"?i("commitComparison.emptyDiff"):i("diffView.branch.empty",{base:Zt??""})}):t.jsx(Iu,{files:Ht,onSelect:A=>{be.key&&F({type:"comparison",path:A,sourceKey:be.key})}}):t.jsx(Ye,{loading:!0,message:i("diffView.state.loadingChanges")});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":i("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"close",className:"size-5"})}):null,t.jsxs(Di,{open:K,onOpenChange:g,children:[t.jsx(_i,{asChild:!0,children:t.jsxs(pe,{variant:"outline",className:Mi({size:"default"}),"data-mobile-comparison-trigger":!0,"aria-label":i("diffView.scope.selectorAria"),children:[t.jsx("span",{children:js}),t.jsx(Q,{name:"arrow-down-s",className:"size-4"})]})}),t.jsx(zi,{align:"start",children:t.jsxs(Oi,{value:x,onValueChange:A=>{(A==="working"||A==="branch"||A==="commit"||A==="pr")&&L(A)},children:[t.jsx(Es,{value:"working",className:"min-h-8 items-center",children:i("mobile.nav.changes")}),Pe&&t.jsx(Es,{value:"branch",className:"min-h-8 items-center",children:i("diffView.scope.branch")}),t.jsx(Es,{value:"commit",className:"min-h-8 items-center",children:i("commitComparison.mode")}),t.jsx(Es,{value:"pr",className:"min-h-8 items-center",children:i("session.githubIntegration.tabs.pullRequests")})]})})]}),r&&x==="branch"&&t.jsx(Cl,{mobile:!0,branches:b?.all??[],currentBranch:ve,base:$e.base,onSelect:A=>{ve&&Ut(l,ve,A)}},JSON.stringify([y,ve])),r&&x==="commit"&&t.jsx(El,{mobile:!0,commits:Ue.commits,selectedHash:et,loading:Ue.loading,error:Ue.error,onSelect:Ue.select,onRefresh:()=>{Ue.refresh()}},JSON.stringify([y,ve])),r&&x==="pr"&&t.jsxs(t.Fragment,{children:[t.jsx(ar,{mobile:!0,comparison:we},JSON.stringify([y,ve])),Ge&&t.jsx(pe,{variant:"ghost",size:"sm",disabled:be.loading,"aria-label":i("session.githubIssuePicker.actions.refresh"),onClick:()=>{be.refresh()},children:t.jsx(Q,{name:"refresh",className:"size-4"})})]})]}),x==="working"&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(La,{currentBranch:p?.current,localBranches:Gs,remoteBranches:xs,branchInfo:b?.branches,currentBranchAhead:p?.ahead,onCheckout:A=>{ft(A)},onCreate:ys,remotes:ct,disabled:v,directory:l,switchBlockedNotice:(p?.files?.length??0)>0?i("gitView.branch.switchBlockedNotice"):null})}),t.jsx($a,{syncAction:B,remotes:ct,onFetch:A=>{vs("fetch",A)},onSync:A=>{vs("sync",A)},disabled:re!==null||v,aheadCount:p?.ahead??0,behindCount:p?.behind??0,trackingRemoteName:p?.tracking?.split("/")[0],hasUncommittedChanges:Ke.length>0})]}),x!=="working"?t.jsx("div",{className:"min-h-0 flex-1",children:Vn()}):Ke.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(bl,{groups:qs,diffStats:p?.diffStats,revertingPaths:G,onRevertAll:Xt,isRevertingAll:V,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:ie})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(xl,{stagedCount:tt.length,commitMessage:ee,onCommitMessageChange:_,generatedHighlights:ae,onInsertHighlights:Ks,onGenerateMessage:Hs,isGeneratingMessage:te,onCommit:()=>{ws({pushAfter:!1})},onCommitAndPush:()=>{ws({pushAfter:!0})},commitAction:re,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ye,{icon:!0,message:i("gitView.empty.cleanTitle"),description:i("mobile.changes.cleanDescription")})}),t.jsx(yl,{open:Ce!==null,onOpenChange:A=>{A||Ee(null)},targetBranch:Ce??"",changedFileCount:p?.files?.length??0,onCommitAndSwitch:async(A,O)=>{const J=Ce;if(!J||!l)return;const je=p?.current??null;await a.createGitCommit(l,A,{addAll:!0});let st=null;if(O){const ks=p?.tracking?.split("/")[0],pt=ct.find(Ss=>Ss.name===ks)??ct[0];try{if(!pt)throw new Error(i("mobile.changes.noRemote"));await a.gitPush(l,p?.tracking?{remote:pt.name}:{remote:pt.name,branch:je??void 0,options:["--set-upstream"]}),st=pt.name}catch{le.error(i("gitView.dirtySwitch.pushFailed")),await Oe(),Ee(null);return}}le.success(je?st?i("gitView.toast.pushedToUpstream",{name:st}):i("gitView.dirtySwitch.committedNotPushed",{branch:je}):i("gitView.toast.commitCreated")),await Oe(),Ee(null),await Nt(J)},onGenerateMessage:async()=>{if(!l)return"";const A=(p?.files??[]).map(J=>J.path).sort(),{message:O}=await sr(l,A);return O.subject?.trim()??""},onRevertAndSwitch:async()=>{const A=Ce;if(!A||!l)return;await Xt((p?.files??[]).map(J=>J.path));const O=await a.getGitStatus(l);if(!O.isClean&&(O.files?.length??0)>0){le.error(i("gitView.dirtySwitch.revertIncomplete"));return}Ee(null),await Nt(A)}})]})},Ye=n=>{const e=ce.c(13),{message:s,description:o,loading:r,icon:i}=n,a=r===void 0?!1:r,u=i===void 0?!1:i;let d;e[0]!==a?(d=a?t.jsx(Q,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let f;e[2]!==u?(f=u?t.jsx(Q,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=u,e[3]=f):f=e[3];let l;e[4]!==s?(l=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=l):l=e[5];let p;e[6]!==o?(p=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[6]=o,e[7]=p):p=e[7];let b;return e[8]!==d||e[9]!==f||e[10]!==l||e[11]!==p?(b=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[d,f,l,p]})}),e[8]=d,e[9]=f,e[10]=l,e[11]=p,e[12]=b):b=e[12],b},Dr=n=>{const e=ce.c(31),{path:s,subtitle:o,diff:r,staged:i,fileExists:a,unavailableReason:u,error:d,onBack:f,onRetry:l}=n,p=i===void 0?!1:i,b=u===void 0?null:u,{t:h}=de();let v;e[0]!==s?(v=Bi(s)||"text",e[0]=s,e[1]=v):v=e[1];const S=v;let w;e[2]!==h?(w=h("header.actions.backAria"),e[2]=h,e[3]=w):w=e[3];let T;e[4]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Q,{name:"arrow-left",className:"size-5"}),e[4]=T):T=e[4];let N;e[5]!==f||e[6]!==w?(N=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":w,onClick:f,children:T}),e[5]=f,e[6]=w,e[7]=N):N=e[7];let C;e[8]!==s?(C=t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s}),e[8]=s,e[9]=C):C=e[9];let I;e[10]!==o?(I=o&&t.jsx("p",{className:"truncate typography-meta text-muted-foreground",children:o}),e[10]=o,e[11]=I):I=e[11];let j;e[12]!==C||e[13]!==I?(j=t.jsxs("div",{className:"min-w-0 flex-1 px-2",children:[C,I]}),e[12]=C,e[13]=I,e[14]=j):j=e[14];let P;e[15]!==N||e[16]!==j?(P=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[N,j]}),e[15]=N,e[16]=j,e[17]=P):P=e[17];let k;e[18]!==r||e[19]!==d||e[20]!==a||e[21]!==S||e[22]!==l||e[23]!==s||e[24]!==p||e[25]!==h||e[26]!==b?(k=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:a?b==="nested_repository"?t.jsx(Ye,{icon:!0,message:h("diffView.unavailable.nestedRepositoryTitle"),description:h("diffView.unavailable.nestedRepositoryDescription")}):b==="untracked_directory"?t.jsx(Ye,{icon:!0,message:h("diffView.unavailable.untrackedDirectoryTitle"),description:h("diffView.unavailable.untrackedDirectoryDescription")}):d?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:h("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:d}),t.jsx(pe,{type:"button",size:"sm",variant:"outline",onClick:l,children:h("diffView.actions.retry")})]})}):r?r.submodule?t.jsx("div",{className:"p-3",children:t.jsx(Tl,{state:r.submodule,staged:p})}):r.isBinary?t.jsx(Ye,{icon:!0,message:h("diffView.binary.unavailable")}):Li(s)&&!r.fileDiff?t.jsx(Ye,{icon:!0,message:h("mobile.changes.diffDetail.imageUnavailable")}):t.jsx($s,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Dl,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:S,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ye,{loading:!0,message:h("diffView.state.loadingDiff")}):t.jsx(Ye,{icon:!0,message:h("mobile.changes.diffDetail.missingTitle"),description:h("mobile.changes.diffDetail.missingDescription")})}),e[18]=r,e[19]=d,e[20]=a,e[21]=S,e[22]=l,e[23]=s,e[24]=p,e[25]=h,e[26]=b,e[27]=k):k=e[27];let E;return e[28]!==P||e[29]!==k?(E=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[P,k]}),e[28]=P,e[29]=k,e[30]=E):E=e[30],E},Iu=n=>{const e=ce.c(12),{files:s,onSelect:o}=n,{t:r}=de();let i;e[0]!==r?(i=r("gitView.changes.changedFilesAria"),e[0]=r,e[1]=i):i=e[1];let a;if(e[2]!==s||e[3]!==o||e[4]!==r){let d;e[6]!==o||e[7]!==r?(d=f=>{const l=f.status==="A"?r("diffView.change.new"):f.status==="D"?r("diffView.change.deleted"):f.status==="R"?r("diffView.change.renamed"):f.status==="C"?r("diffView.change.copied"):r("diffView.change.modified"),p=f.status==="A"?"var(--status-success)":f.status==="D"?"var(--status-error)":f.status==="R"||f.status==="C"?"var(--status-info)":"var(--status-warning)";return t.jsx("li",{children:t.jsxs(pe,{variant:"ghost",size:"lg",className:"w-full justify-start gap-2.5 text-left normal-case",onClick:()=>o(f.path),children:[t.jsx("span",{className:"w-4 shrink-0 text-center typography-meta font-semibold uppercase",style:{color:p},"aria-label":l,children:f.status}),t.jsx(ro,{filePath:f.path,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label",title:f.path,children:f.path}),(f.insertions>0||f.deletions>0)&&t.jsxs("span",{className:"shrink-0 typography-meta text-muted-foreground",children:["+",f.insertions," -",f.deletions]}),t.jsx(Q,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground"})]})},f.path)},e[6]=o,e[7]=r,e[8]=d):d=e[8],a=s.map(d),e[2]=s,e[3]=o,e[4]=r,e[5]=a}else a=e[5];let u;return e[9]!==i||e[10]!==a?(u=t.jsx($s,{className:"h-full overflow-y-auto overflow-x-hidden px-3 py-2",children:t.jsx("ul",{"aria-label":i,className:"flex flex-col gap-1",children:a})}),e[9]=i,e[10]=a,e[11]=u):u=e[11],u},Du=c.lazy(()=>Ot(()=>import("./FilesView-C4vMFclc.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,124,125,126])).then(n=>({default:n.FilesView}))),wt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),fs=n=>{const e=wt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},_u=n=>{const e=wt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},Mu=(n,e)=>{const s=wt(n),o=wt(e);return!o||s===o?fs(s):s.startsWith(`${o}/`)?s.slice(o.length+1):s},zu=n=>{if(typeof n!="number"||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const o of e){if(s<1024||o===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${o}`;s/=1024}return""},Ou=({onClose:n})=>{const{t:e}=de(),{files:s}=yn(),o=Uo(g=>g.setSelectedPath),r=wt(vn()??null),[i,a]=c.useState(()=>({type:"browser",directory:r})),[u,d]=c.useState([]),[f,l]=c.useState(!1),[p,b]=c.useState(null),[h,v]=c.useState(""),[S,w]=c.useState([]),[T,N]=c.useState(!1),C=c.useRef(0);c.useEffect(()=>{r&&a(g=>g.type==="browser"&&g.directory?g:{type:"browser",directory:r})},[r]);const I=i.type==="browser"?i.directory:i.returnDirectory,j=c.useCallback(async g=>{if(!g)return;const L=C.current+1;C.current=L,l(!0),b(null);try{const F=await s.listDirectory(g);if(C.current!==L)return;d(F.entries.slice().sort((B,W)=>B.isDirectory!==W.isDirectory?B.isDirectory?-1:1:B.name.localeCompare(W.name)))}catch(F){if(C.current!==L)return;d([]),b(F instanceof Error?F.message:e("mobile.files.error.listFailed"))}finally{C.current===L&&l(!1)}},[s,e]);c.useEffect(()=>{i.type==="browser"&&j(i.directory)},[j,i]),c.useEffect(()=>{if(i.type!=="browser")return;const g=h.trim();if(!g){w([]),N(!1);return}let L=!1;const F=window.setTimeout(()=>{N(!0),s.search({directory:i.directory,query:g,maxResults:40}).then(B=>{L||w(B)}).catch(()=>{L||w([])}).finally(()=>{L||N(!1)})},250);return()=>{L=!0,window.clearTimeout(F)}},[s,h,i]);const P=g=>{v(""),a({type:"browser",directory:g})},k=g=>{o(r,g),a({type:"file",path:g,returnDirectory:I||r})},E=it(g=>g.pendingFileFocusPath),y=it(g=>g.pendingFileNavigation);if(c.useEffect(()=>{const g=wt(y?.path??E??"");!g||!r||g!==r&&!g.startsWith(`${r}/`)||(o(r,g),a({type:"file",path:g,returnDirectory:r}),E&&it.getState().setPendingFileFocusPath(null))},[E,y,r,o]),!r)return t.jsx(ms,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("header.actions.backAria"),onClick:()=>a({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(rr,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:fs(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Xe,{children:t.jsx(c.Suspense,{fallback:t.jsx(ms,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(Du,{mode:"editor-only"})})})})]});const z=i.directory===r?e("mobile.files.rootDirectory"):fs(i.directory),M=h.trim()?S:[],R=_u(i.directory),x=i.directory!==r&&R!==null&&(R===r||R.startsWith(`${r}/`)),D=x&&!h.trim(),K=x?R:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[n?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(ul,{className:"size-5"})}):null,D&&K?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("mobile.files.backToParentAria",{name:fs(K)}),onClick:()=>P(K),style:{touchAction:"manipulation"},children:t.jsx(rr,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:z})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("mobile.files.refreshAria"),onClick:()=>{j(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(dl,{className:Y("size-5",f&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(fl,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(eo,{value:h,onChange:g=>v(g.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx($s,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(ms,{message:p}):h.trim()?t.jsx(Bu,{results:M,isSearching:T,onOpenFile:k}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[u.length===0&&!f?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,u.map(g=>t.jsx(_o,{name:g.name,path:g.path,directory:g.isDirectory,meta:g.isDirectory?void 0:zu(g.size),onClick:()=>g.isDirectory?P(g.path):k(g.path)},g.path))]})})]})},_o=n=>{const e=ce.c(16),{name:s,path:o,directory:r,meta:i,onClick:a}=n;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},e[0]=u):u=e[0];let d;e[1]!==r||e[2]!==o?(d=r?t.jsx(ml,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(ro,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=d):d=e[3];let f;e[4]!==s?(f=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=f):f=e[5];let l;e[6]!==i?(l=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=l):l=e[7];let p;e[8]!==r?(p=r?t.jsx(pl,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let b;return e[10]!==a||e[11]!==d||e[12]!==f||e[13]!==l||e[14]!==p?(b=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:a,style:u,children:[d,f,l,p]}),e[10]=a,e[11]=d,e[12]=f,e[13]=l,e[14]=p,e[15]=b):b=e[15],b},Bu=n=>{const e=ce.c(10),{results:s,isSearching:o,onOpenFile:r}=n,{t:i}=de(),a=wt(vn()??null);if(o){let l;e[0]!==i?(l=i("common.loading"),e[0]=i,e[1]=l):l=e[1];let p;return e[2]!==l?(p=t.jsx(ms,{loading:!0,message:l}),e[2]=l,e[3]=p):p=e[3],p}if(s.length===0){let l;e[4]!==i?(l=i("mobile.files.search.empty"),e[4]=i,e[5]=l):l=e[5];let p;return e[6]!==l?(p=t.jsx(ms,{message:l}),e[6]=l,e[7]=p):p=e[7],p}const u="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",d=s.map(l=>t.jsx(_o,{name:fs(l.path),path:l.path,directory:!1,meta:Mu(l.path,a),onClick:()=>r(l.path)},l.path));let f;return e[8]!==d?(f=t.jsx("div",{className:u,children:d}),e[8]=d,e[9]=f):f=e[9],f},ms=n=>{const e=ce.c(7),{message:s,loading:o}=n,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(hl,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(gl,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==s?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[2]=s,e[3]=a):a=e[3];let u;return e[4]!==i||e[5]!==a?(u=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[i,a]})}),e[4]=i,e[5]=a,e[6]=u):u=e[6],u},_r="mobile-surface-root",Lu=16,Mr=320,$u="cubic-bezier(0.22, 1, 0.36, 1)",Fu=n=>{const e=ce.c(36),{onOpenMcpSettings:s}=n,{t:o}=de(),[r,i]=c.useState(!1),a=xt(Vu),u=os(Uu),d=_t(Gu);let f;e[0]!==a||e[1]!==r||e[2]!==d||e[3]!==u?(f=()=>{if(r)return;i(!0);const z=new Promise(Ku);Promise.all([u({directory:a||null,silent:!0}),d({force:!0}),z]).finally(()=>i(!1))},e[0]=a,e[1]=r,e[2]=d,e[3]=u,e[4]=f):f=e[4];const l=f;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let b;e[7]!==o?(b=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=b):b=e[8];let h,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},v=t.jsx(Q,{name:"add",className:"size-5"}),e[9]=h,e[10]=v):(h=e[9],v=e[10]);let S;e[11]!==s||e[12]!==p||e[13]!==b?(S=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:s,"aria-label":p,title:b,style:h,children:v}),e[11]=s,e[12]=p,e[13]=b,e[14]=S):S=e[14];let w;e[15]!==o?(w=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=w):w=e[16];let T;e[17]!==o?(T=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=T):T=e[18];let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N={touchAction:"manipulation"},e[19]=N):N=e[19];const C=r&&"animate-spin";let I;e[20]!==C?(I=Y("size-5",C),e[20]=C,e[21]=I):I=e[21];let j;e[22]!==I?(j=t.jsx(Q,{name:"refresh",className:I}),e[22]=I,e[23]=j):j=e[23];let P;e[24]!==r||e[25]!==l||e[26]!==j||e[27]!==w||e[28]!==T?(P=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:l,disabled:r,"aria-label":w,title:T,style:N,children:j}),e[24]=r,e[25]=l,e[26]=j,e[27]=w,e[28]=T,e[29]=P):P=e[29];let k;e[30]!==P||e[31]!==S?(k=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[S,P]}),e[30]=P,e[31]=S,e[32]=k):k=e[32];let E;e[33]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Cu,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=E):E=e[33];let y;return e[34]!==k?(y=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[k,E]}),e[34]=k,e[35]=y):y=e[35],y},Wu=({open:n,onClose:e,tab:s,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:a,variant:u="drawer"})=>{const{t:d}=de(),f=c.useRef(null),l=c.useRef(null),[p,b]=c.useState(!1),[h,v]=c.useState(n),S=c.useRef(e);c.useEffect(()=>{S.current=e},[e]);const w=c.useRef(s);c.useEffect(()=>{w.current=s},[s]),Fn(l,{enabled:u==="drawer"&&n,onLeftEdgeSwipe:()=>S.current()});const[T,N]=c.useState(()=>new Set);if(c.useEffect(()=>{n&&N(j=>{if(j.has(s))return j;const P=new Set(j);return P.add(s),P})},[n,s]),typeof document<"u"&&!f.current){let j=document.getElementById(_r);j||(j=document.createElement("div"),j.id=_r,document.body.appendChild(j)),f.current=j}if(c.useEffect(()=>{if(n){v(!0);const P=window.setTimeout(()=>b(!0),Lu);return()=>window.clearTimeout(P)}b(!1);const j=window.setTimeout(()=>v(!1),Mr+40);return()=>window.clearTimeout(j)},[n]),c.useEffect(()=>{if(!n)return;const j=document.body.style.overflow;u==="drawer"&&(document.body.style.overflow="hidden");const P=k=>{k.key!=="Escape"||w.current==="terminal"||Fi(k.target)||S.current()};return document.addEventListener("keydown",P),()=>{u==="drawer"&&(document.body.style.overflow=j),document.removeEventListener("keydown",P)}},[n,u]),u==="drawer"&&!f.current)return null;const C=[{id:"changes",label:d("mobile.menu.changes"),icon:t.jsx(Q,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:d("mobile.menu.files"),icon:t.jsx(Q,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:d("mobile.menu.terminal"),icon:t.jsx(Q,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:d("contextRail.surface.notes"),icon:t.jsx(Q,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:d("mobile.menu.mcp"),icon:t.jsx($i,{className:"h-3.5 w-3.5"})}],I=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:h?t.jsx(Va,{items:C,activeId:s,onSelect:j=>o(j),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":d("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Q,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[T.has("changes")?t.jsx("div",{className:Y("h-full",s!=="changes"&&"hidden"),children:t.jsx(Xe,{children:t.jsx(Au,{visible:n&&s==="changes",initialDiff:r})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,T.has("files")?t.jsx("div",{className:Y("h-full",s!=="files"&&"hidden"),children:t.jsx(Xe,{children:t.jsx(Ou,{})})}):null,T.has("terminal")?t.jsx("div",{className:Y("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Xe,{children:t.jsx(Ua,{visible:n&&s==="terminal"})})}):null,T.has("notes")?t.jsx("div",{className:Y("h-full",s!=="notes"&&"hidden"),children:t.jsx(Xe,{children:t.jsx(Ga,{onActionComplete:e,onOpenPlan:i})})}):null,T.has("mcp")?t.jsx("div",{className:Y("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Xe,{children:t.jsx(Fu,{onOpenMcpSettings:a})})}):null]})]});return u==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:I}):zt.createPortal(t.jsx("section",{ref:l,role:"dialog","aria-modal":"true","aria-label":d("mobile.header.openWorkspaceAria"),"aria-hidden":!n,className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:p?"none":"translateX(100%)",transition:`transform ${Mr}ms ${$u}`,visibility:h?"visible":"hidden",pointerEvents:n?"auto":"none"},children:I}),f.current)};function Vu(n){return n.currentDirectory}function Uu(n){return n.refresh}function Gu(n){return n.loadMcpConfigs}function Ku(n){return window.setTimeout(n,500)}function Hu(n){const e=ce.c(4),s=2500,{uiFont:o}=Wi(),[r,i]=c.useState(!1);let a,u;return e[0]!==s||e[1]!==o?(a=()=>{let d=!1;const f=()=>{d||i(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(f))},p=Promise.all([Vi(o).catch(Qu),document.fonts?.ready?.then(Xu).catch(Yu)??Promise.resolve(),_l.catch(Ju)]).then(qu),b=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,b]).then(l),()=>{d=!0}},u=[o,s],e[0]=s,e[1]=o,e[2]=a,e[3]=u):(a=e[2],u=e[3]),c.useEffect(a,u),r}function qu(){}function Ju(){}function Yu(){}function Xu(){}function Qu(){}const Zu="openchamber",ed=n=>n.replace(/^\/+|\/+$/g,""),td=n=>{const e=ed(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function sd(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${Zu}:`)return null;const s=td(e),o=(s[0]??"").toLowerCase(),r=s.slice(1),i=e.searchParams;switch(o){case"session":{const a=r[0]||i.get("id")||"";return a?{type:"session",sessionId:a,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const a=i.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const a=(r[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let qe={},Mo=!1,ds=null;const nd=n=>{switch(n.type){case"session":return Se.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=Se.getState();return e.openNewSessionDraft(),(n.directory||n.projectId)&&e.setNewSessionDraftTarget({directoryOverride:n.directory??null,projectId:n.projectId??null,selectedProjectId:n.projectId??null}),!0}case"sessions":return qe.openSessions?(qe.openSessions(n.filter),!0):!1;case"status":return qe.openSessions?(qe.openSessions(),!0):!1;case"view":return qe.openView?(qe.openView(n.target),!0):!1;case"changes":return qe.openChanges?(qe.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return qe.openSettings?(qe.openSettings(n.section),!0):!1}},Wn=()=>{if(!Mo||!ds)return;const n=ds;ds=null,nd(n)||(ds=n)},zo=n=>{ds=n,Wn()},zr=n=>{const e=sd(n);e&&zo(e)},rd=n=>{Mo=n,Wn()},od=n=>{const e=ce.c(3);let s,o;e[0]!==n?(s=()=>(qe=n,Wn(),()=>{qe===n&&(qe={})}),o=[n],e[0]=n,e[1]=s,e[2]=o):(s=e[1],o=e[2]),c.useEffect(s,o)},id=n=>{const{ready:e}=n;c.useEffect(()=>{rd(e)},[e]),c.useEffect(()=>{if(!Be())return;let s=!1;const o=[];return Ot(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([127,5,128])).then(async({App:r})=>{if(s)return;const i=await r.addListener("appUrlOpen",a=>{zr(a?.url)});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),Ot(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([129,128])).then(async({PushNotifications:r})=>{if(s)return;const i=await r.addListener("pushNotificationActionPerformed",a=>{const u=a?.notification?.data,d=typeof u?.url=="string"?u.url:typeof u?.deeplink=="string"?u.deeplink:void 0;if(d){zr(d);return}const f=typeof u?.sessionId=="string"?u.sessionId:void 0;f&&zo({type:"session",sessionId:f})});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,o.forEach(r=>r())}},[])},ad=()=>{if(typeof window>"u")return;const n=window.__OPENCHAMBER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},ld=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},cd=n=>{const{enabled:e}=n,s=it(r=>r.nativeNotificationsEnabled),o=c.useRef(null);c.useEffect(()=>{if(!e||!s||!ld())return;let r=!1;const i=[];return Ot(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([129,128])).then(async({PushNotifications:a})=>{if(r)return;let u=await a.checkPermissions().catch(()=>null);if(u?.receive!=="granted"&&(u=await a.requestPermissions().catch(()=>null)),u?.receive!=="granted")return;const d=await a.addListener("registration",l=>{o.current=l.value,Xn()?.push?.registerApnsToken?.({token:l.value,platform:$r(),environment:ad()})}),f=await a.addListener("registrationError",l=>{console.warn("[Push] APNs registration error:",l)});if(await a.register().catch(()=>{}),r){d.remove(),f.remove();return}i.push(()=>{d.remove()},()=>{f.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(a=>a())}},[e,s]),c.useEffect(()=>{if(s)return;const r=o.current;if(!r)return;o.current=null,Xn()?.push?.unregisterApnsToken?.({token:r})},[s])},Or=n=>{const e=ce.c(12),{side:s,isResizing:o,ariaLabel:r,handleProps:i}=n,a=s==="left"?"right-0":"left-0";let u;e[0]!==a?(u=Y("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=u):u=e[1];const d=s==="left"?"right-0":"left-0",f=o&&"bg-[var(--interactive-border)]";let l;e[2]!==d||e[3]!==f?(l=Y("absolute inset-y-0 w-[3px] transition-colors",d,f),e[2]=d,e[3]=f,e[4]=l):l=e[4];let p;e[5]!==l?(p=t.jsx("div",{className:l}),e[5]=l,e[6]=p):p=e[6];let b;return e[7]!==r||e[8]!==i||e[9]!==u||e[10]!==p?(b=t.jsx("div",{className:u,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=u,e[10]=p,e[11]=b):b=e[11],b},ud=320,dd=380,Br=280,fd=560,md=900;function Lr(n,e,s,o){const r=ce.c(23),i=o===void 0?fd:o,a=c.useRef(null);let u;r[0]!==s||r[1]!==i||r[2]!==e?(u=()=>{if(typeof window>"u")return s;const x=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(x)?Math.min(i,Math.max(Br,x)):s},r[0]=s,r[1]=i,r[2]=e,r[3]=u):u=r[3];const[d,f]=c.useState(u),[l,p]=c.useState(!1),b=c.useRef(0),h=c.useRef(d),v=c.useRef(null),S=c.useRef(null);let w;r[4]!==i?(w=x=>Math.min(i,Math.max(Br,Math.round(x))),r[4]=i,r[5]=w):w=r[5];const T=w;let N;r[6]===Symbol.for("react.memo_cache_sentinel")?(N=x=>{const D=a.current;D&&(D.style.width=`${x}px`,D.style.minWidth=`${x}px`,D.style.maxWidth=`${x}px`,D.style.setProperty("--oc-ipad-sidebar-width",`${x}px`))},r[6]=N):N=r[6];const C=N;let I;r[7]!==d?(I=x=>{try{x.currentTarget.setPointerCapture(x.pointerId)}catch{}S.current=x.pointerId,b.current=x.clientX,h.current=d,v.current=d,p(!0),x.preventDefault()},r[7]=d,r[8]=I):I=r[8];const j=I;let P;r[9]!==T||r[10]!==n?(P=x=>{if(S.current!==x.pointerId)return;const D=x.clientX-b.current,K=T(h.current+(n==="left"?D:-D));v.current!==K&&(v.current=K,C(K))},r[9]=T,r[10]=n,r[11]=P):P=r[11];const k=P;let E;r[12]!==T||r[13]!==e?(E=x=>{if(S.current!==x.pointerId)return;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}const D=T(v.current??h.current);S.current=null,v.current=null,p(!1),f(D);try{window.localStorage.setItem(e,String(D))}catch{}},r[12]=T,r[13]=e,r[14]=E):E=r[14];const y=E;let z;r[15]!==j||r[16]!==y||r[17]!==k?(z={onPointerDown:j,onPointerMove:k,onPointerUp:y,onPointerCancel:y},r[15]=j,r[16]=y,r[17]=k,r[18]=z):z=r[18];const M=z;let R;return r[19]!==M||r[20]!==l||r[21]!==d?(R={asideRef:a,width:d,isResizing:l,handleProps:M},r[19]=M,r[20]=l,r[21]=d,r[22]=R):R=r[22],R}const pd=["general","appearance","chat","notifications","sessions","routing","git","magic-prompts","snippets","behavior","agents","commands","mcp","plugins","skills.installed","skills.catalog","providers","usage","voice","integrations","about"],hd=1e3,gd=({onActiveConnectionDeleted:n})=>{const{t:e}=de();Za();const[s,o]=c.useState(!1),[r,i]=c.useState(null),[a,u]=c.useState(!1),[d,f]=c.useState("changes"),[l,p]=c.useState(null),[b,h]=c.useState("nav"),[v,S]=c.useState(null),w=it(q=>q.setSettingsPage),T=it(q=>q.wideChatLayoutEnabled),N=It(q=>q.available),C=It(q=>q.runtimeType),I=c.useMemo(()=>oo(),[]),j=_t(q=>q.mcpServers),P=_t(q=>q.setMcpDraft),k=_t(q=>q.setSelectedMcp),E=c.useCallback(()=>{i(null),p(null)},[]),y=c.useCallback(q=>{i(q)},[]),z=c.useCallback(()=>{u(!1)},[]),M=c.useCallback(q=>{h(q),y("settings")},[y]),{enabled:R,roomyForPanels:x}=bn(),K=fa()==="portrait",g=ma(),[L,F]=c.useState(()=>pa().roomyForPanels),B=c.useCallback(()=>{F(q=>!q)},[]);c.useEffect(()=>{R||F(!1)},[R]);const W=c.useCallback(()=>{S(null),f("files"),u(!0)},[]),re=c.useCallback((q=null)=>{S(q),f("changes"),u(!0)},[]),ne=Lr("left","openchamber.ipad.leftSidebarWidth",ud),ee=Lr("right","openchamber.ipad.rightSidebarWidth",dd,md),_=x,G=_&&a?ee.width:0,X=R&&L?ne.width:0;c.useEffect(()=>{if(typeof document>"u")return;const q=document.documentElement;return q.style.setProperty("--oc-chat-inset-left",`${X}px`),q.style.setProperty("--oc-chat-inset-right",`${G}px`),()=>{q.style.removeProperty("--oc-chat-inset-left"),q.style.removeProperty("--oc-chat-inset-right")}},[X,G]),c.useEffect(()=>{if(typeof document>"u")return;const q=document.documentElement;return q.classList.toggle("wide-chat-layout",T),()=>q.classList.remove("wide-chat-layout")},[T]),c.useEffect(()=>{if(typeof document>"u")return;const q=R&&(K||g),ye=document.documentElement;return ye.classList.toggle("oc-keep-draft-starters",q),()=>ye.classList.remove("oc-keep-draft-starters")},[g,R,K]);const V=c.useMemo(()=>({openChanges:({diffPath:q,staged:ye}={})=>{re(q?{path:q,staged:ye===!0}:null)},openFiles:()=>W(),openSettings:()=>M("nav")}),[re,W,M]),Z=c.useMemo(()=>({openSessions:()=>{R?F(!0):o(!0)},openView:q=>{if(q==="files"){W();return}if(q==="mcp"){f("mcp"),u(!0);return}y(q)},openChanges:({path:q,staged:ye}={})=>{re(q?{path:q,staged:ye===!0}:null)},openSettings:q=>{q&&w(q),M(q?"page-content":"nav")}}),[R,re,W,M,y,w]);od(Z);const te=c.useRef(null);Fn(te,{onLeftEdgeSwipe:()=>{R?F(!0):o(!0)},onRightEdgeSwipe:()=>u(!0)});const se=c.useRef(null),ae=c.useCallback(q=>{se.current=q},[]),ue=c.useCallback(()=>l?(p(null),!0):r==="settings"&&se.current?.()?!0:r?(E(),!0):a?(z(),!0):s?(o(!1),!0):!1,[r,E,z,l,s,a]);ha(ue);const U=!I&&N&&(C==="desktop"||C==="web"),ie=R?"dialog":"fullscreen",xe=c.useMemo(()=>({instanceLabel:I?is():null,onOpenInstances:I?()=>y("instances"):void 0,onOpenSettings:()=>M("nav"),onOpenUpdate:U?()=>y("update"):void 0}),[M,y,I,U]),Ne=c.useCallback(()=>{const q="new-mcp-server";let ye=q,Re=1;for(;j.some(Ie=>Ie.name===ye);)ye=`${q}-${Re}`,Re+=1;P({name:ye,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),k(ye),w("mcp"),M("page-content")},[j,M,P,k,w]);return t.jsx(ga,{actions:V,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[R?t.jsxs("aside",{ref:ne.asideRef,className:Y("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!L&&"border-r-0"),style:{width:L?ne.width:0,minWidth:L?ne.width:0,maxWidth:L?ne.width:0,"--oc-ipad-sidebar-width":`${ne.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ne.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!L,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Y("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ne.isResizing&&"pointer-events-none",!L&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Xe,{children:t.jsx(Er,{open:!0,variant:"sidebar",onOpenChange:q=>{!q&&!x&&F(!1)},footer:xe})})}),L?t.jsx(Or,{side:"left",isResizing:ne.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:ne.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(Uc,{onOpenSessions:()=>R?B():o(!0),onOpenWorkspace:()=>u(!0),compactTitle:R}),t.jsx("main",{ref:te,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(Xe,{children:t.jsx(el,{})})})})]}),R?null:t.jsx(Er,{open:s,onOpenChange:o,footer:xe}),t.jsxs("aside",{ref:ee.asideRef,className:Y("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!G&&"border-l-0"),style:{width:G,minWidth:G,maxWidth:G,"--oc-ipad-sidebar-width":`${ee.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ee.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!G,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Y("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ee.isResizing&&"pointer-events-none",!G&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Xe,{children:t.jsx(Wu,{open:a,onClose:z,tab:d,onTabChange:f,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:Ne,variant:_?"panel":"drawer"})})}),G?t.jsx(Or,{side:"right",isResizing:ee.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:ee.handleProps}):null]}),l?t.jsx(cs,{open:!0,variant:ie,onClose:()=>p(null),ariaLabel:l.title,title:l.title,children:t.jsx(Xe,{children:t.jsx(rl,{savedProjectPlan:{projectRef:l.projectRef,planId:l.id},onNavigatedToChat:()=>{E(),z()}})})}):null,r==="instances"&&I?t.jsx(cs,{open:!0,variant:ie,dialogAlign:"app",onClose:E,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(qc,{onConnect:E,onActiveConnectionDeleted:n})}):null,r==="settings"?t.jsx(cs,{open:!0,variant:ie,dialogAlign:"app",onClose:E,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Xe,{children:t.jsx(sl,{forceMobile:!0,isWindowed:!0,initialMobileStage:b,registerBackHandler:ae,visiblePageSlugs:pd.filter(q=>!(I&&q==="about")),onClose:E})})}):null,r==="update"?t.jsx(cs,{open:!0,variant:ie,dialogAlign:"app",onClose:E,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Xe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(nl,{initialUpdateDialogOpen:!0})})})}):null]})})};function bd({apis:n}){const{t:e}=de(),s=Je(_=>_.initializeApp),o=Je(_=>_.isInitialized),r=Je(_=>_.isConnected),i=Je(_=>_.connectionPhase),a=Je(_=>_.providers.length),u=Je(_=>_.agents.length),d=Je(_=>_.loadProviders),f=Je(_=>_.loadAgents),l=xt(_=>_.currentDirectory),p=Se(_=>_.error),b=Se(_=>_.clearError),h=it(_=>_.setIsMobile),v=Ui(_=>_.refreshStatus),S=Gi(_=>_.refreshStatus),w=Ki(_=>_.setPlanModeEnabled),T=We(_=>_.projects),[N,C]=c.useState(0),[I,j]=c.useState(0),[P,k]=c.useState(!1),[E,y]=c.useState("pending"),[z,M]=c.useState(null),R=c.useMemo(()=>is(),[]),[,x]=c.useReducer(_=>_+1,0),D=c.useMemo(()=>oo(),[]),K=c.useRef(0),g=c.useRef(0),L=c.useCallback(()=>{const _=ot(),G=g.current+1;if(g.current=G,!_){ns("resume:auto-connect",{}),rs();return}ns("resume:reprobe",{});const X=()=>{s(),v(n.github,{force:!0}),S(n.linear,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),u===0&&f({source:"mobileApp:nativeResume"})},V=te=>{ns("resume:disconnect",{reason:te}),At({apiBaseUrl:"",clientToken:null,runtimeKey:Cs}),C(se=>se+1)};Is().then(te=>{if(g.current===G){if(te==="no-connection"){V("no-connection");return}if(te==="needs-login"){M({kind:"auth-expired",label:is()??""}),V("needs-login");return}if(te==="unreachable"){const se=[4e3,1e4],ae=ue=>{window.setTimeout(()=>{if(g.current!==G)return;const U=ue===se.length-1;Is({fast:!U}).then(ie=>{if(g.current===G&&ie!=="switched"){if(ie==="unchanged"){X();return}if(ie==="needs-login"){M({kind:"auth-expired",label:is()??""}),V("retry-needs-login");return}if(!U){ae(ue+1);return}V(`retry-${ie}`)}})},se[ue])};ae(0);return}te!=="switched"&&X()}});const Z=Date.now();Z-K.current>=hd&&(K.current=Z,window.dispatchEvent(new Event("openchamber:system-resume")))},[u,n.github,n.linear,s,f,d,a,v,S]);Hi(),qi(L),c.useEffect(()=>{if(!D)return;let _;const G=()=>{window.clearTimeout(_),_=window.setTimeout(()=>L(),1500)};return window.addEventListener("online",G),()=>{window.removeEventListener("online",G),window.clearTimeout(_)}},[D,L]),c.useEffect(()=>{if(D)return Qn.subscribe((_,G)=>{_.state==="expired"&&G.state!=="expired"&&(L(),Qn.getState().markAuthenticated())})},[D,L]),c.useEffect(()=>(Zn(n),()=>Zn(null)),[n]),c.useEffect(()=>Go(_=>{if(ns("endpoint:changed",{runtimeKey:_.runtimeKey||"none",previousRuntimeKey:_.previousRuntimeKey||"none",connected:!!_.apiBaseUrl}),!!_.runtimeKey&&_.runtimeKey===_.previousRuntimeKey){Ka(),x();return}Ha(_),j(X=>X+1),C(X=>X+1)}),[]),c.useEffect(()=>{if(!D||r||ot()){y("done");return}let _=!1;return y("attempting"),(async()=>{const G=await rs().catch(()=>({status:"no-candidate"}));_||(G.status==="unreachable"?M({kind:"unreachable",label:G.label}):G.status==="needs-login"&&M({kind:"auth-expired",label:G.label}),y("done"),G.status==="unreachable"&&rs({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{_=!0}},[]),c.useEffect(()=>{if(!D||!ot())return;let _=!1;const G=X=>{ns("cold-launch:drop",{kind:X?.kind??"unknown"}),X&&M(X),At({apiBaseUrl:"",clientToken:null,runtimeKey:Cs}),C(V=>V+1)};return Is().then(async X=>{if(_||X==="switched"||X==="unchanged")return;const V=is();if(X==="needs-login"){G({kind:"auth-expired",label:V??""});return}if(X==="unreachable"){G(V?{kind:"unreachable",label:V}:null),rs({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const Z=await rs().catch(()=>({status:"no-candidate"}));_||Z.status==="connected"||(Z.status==="needs-login"?G({kind:"auth-expired",label:Z.label}):Z.status==="unreachable"?G({kind:"unreachable",label:Z.label}):G(null))}),()=>{_=!0}},[]),c.useEffect(()=>{h(!0)},[h]),c.useEffect(()=>{D&&!ot()||s()},[N,s,D]),c.useEffect(()=>{r&&(a===0&&d({source:"mobileApp:recovery"}),u===0&&f({source:"mobileApp:recovery"}))},[u,r,f,d,a]);const F=c.useRef(!1),[B,W]=c.useState(D);c.useEffect(()=>{if(!D||!r||F.current)return;if(Se.getState().currentSessionId){F.current=!0,W(!1);return}const _=Wt(),G=Ji(_);if(!G){F.current=!0,W(!1);return}let X=!1;const V=window.setTimeout(()=>W(!1),6e3);return(async()=>{const Z=await xn().catch(()=>null);if(X)return;if(!Z){W(!1);return}F.current=!0;const te=Z.activeSessions.find(ae=>ae.id===G.sessionId);if(!te){Yi(_),W(!1);return}const se=Se.getState();se.currentSessionId||se.setCurrentSession(te.id,gn(te)??G.directory??void 0),W(!1)})(),()=>{X=!0,window.clearTimeout(V)}},[N,r,D]),c.useEffect(()=>{r&&er.setDirectory(l)},[l,r]),c.useEffect(()=>{r&&(v(n.github,{force:!0}),S(n.linear,{force:!0}))},[n.github,n.linear,r,v,S]),c.useEffect(()=>{if(!r||T.length===0)return;let _=!1;return(async()=>{const X=new Map(Se.getState().availableWorktreesByProject);if(await Promise.all(T.map(async te=>{const se=te.path.replace(/\\/g,"/").replace(/\/+$/,"");if(se)try{if(!(He.getState().directories.get(se)?.isGitRepo??await Ot(()=>import("./useAppFontEffects-ne84JBVL.js").then(ie=>ie.kO),__vite__mapDeps([9,1,2,3,4,5,6,7,8,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(ie=>ie.checkIsGitRepository(se))))return;const U=await so({id:te.id,path:se});if(_)return;X.set(se,U)}catch{}})),_)return;const V=no(T,X),Z=Se.getState().availableWorktreesByProject;ua(V,Z)||Se.setState({availableWorktrees:[...V.values()].flat(),availableWorktreesByProject:V})})(),()=>{_=!0}},[r,T]),c.useEffect(()=>{if(!r)return;let _=!1;const G=Xi(X=>{X.type==="worktree-changed"&&da(T,X.directories,()=>_)});return()=>{_=!0,G()}},[r,T]),c.useEffect(()=>{let _=!1;return(async()=>{const X=await pn("/health",{method:"GET"}).catch(()=>null);if(!X||!X.ok||_)return;const V=await X.json().catch(()=>null);if(!V||_)return;const Z=V.planModeExperimentalEnabled;w(Z===!0||Z===1||Z==="1"||Z==="true")})(),()=>{_=!0}},[w]),c.useEffect(()=>{if(!p)return;const _=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(_)},[b,p]),c.useEffect(()=>{if(!(!r&&(D?!!ot():!0))){k(!1);return}const G=window.setTimeout(()=>{k(!0)},D?4e3:8e3);return()=>window.clearTimeout(G)},[r,D,N,I]),Qi(),Zi({enabled:!0}),qa(),ea(),ta(),Ja(),cd({enabled:D&&r}),id({ready:D&&r&&o});const re=Hu(),ne=!r&&i==="reconnecting";if(!re)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(Tt,{width:120,height:120,isAnimated:!0,variant:"splash"})});const ee=!!ot();return D&&(!ee||!r&&!ne)?ee?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Tt,{width:120,height:120,isAnimated:!P,variant:"splash"}),P?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(pe,{type:"button",variant:"outline",onClick:()=>{At({apiBaseUrl:"",clientToken:null,runtimeKey:Cs}),C(_=>_+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):E!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:[t.jsx(Tt,{width:120,height:120,isAnimated:!0,variant:"splash"}),R?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[R,t.jsx(sa,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Rc,{onConnected:()=>C(_=>_+1),notice:z})}):!r&&!ne?P?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(Tt,{width:120,height:120,isAnimated:!0,variant:"splash"})}):t.jsx(Xe,{children:t.jsx(na,{sdk:er.getSdkClient(),directory:l||"",children:t.jsx(ra,{apis:n,children:t.jsx(oa,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(Ya,{ready:!D||!B,animated:!0}),t.jsx(ia,{embeddedBackgroundWorkEnabled:o}),t.jsx(Xa,{}),t.jsx(Vl,{}),t.jsx(gd,{onActiveConnectionDeleted:()=>{At({apiBaseUrl:"",clientToken:null,runtimeKey:Cs}),C(_=>_+1)}}),t.jsx(aa,{}),t.jsx(la,{}),t.jsx(ca,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(Qa,{}):null]})})})},I)})}const xd=()=>{ka(),Ko().then(()=>{Promise.all([Ho(),Sa()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),Na(),Ca(),Ea()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{Ml()})};function Jm(n){window.__OPENCHAMBER_SURFACE__="mobile",ba(),xd(),Wl(),xa();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const o=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=o?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,i=t.jsx(bd,{apis:r});Oo.createRoot(e).render(t.jsx(an.StrictMode,{children:t.jsx(ya,{children:t.jsx(va,{children:t.jsx(wa,{children:t.jsx(tl,{children:o?i:t.jsx(ja,{children:i})})})})})}))}export{Jm as renderMobileApp};
|