@myrialabs/clopen 0.4.50 → 0.4.51
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 -1
- package/backend/chat/attachments.test.ts +106 -17
- package/backend/chat/attachments.ts +131 -34
- package/backend/chat/engine-handoff.ts +42 -6
- package/backend/chat/stream-manager.ts +41 -5
- package/backend/containers/actions.ts +22 -0
- package/backend/control/actions/projects.ts +93 -37
- package/backend/control/folders.test.ts +27 -2
- package/backend/control/index.ts +2 -1
- package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
- package/backend/database/migrations/086_single_owner.ts +66 -73
- package/backend/database/migrations/090_create_storage_tables.ts +83 -0
- package/backend/database/migrations/index.ts +11 -2
- package/backend/database/queries/integration-queries.ts +10 -0
- package/backend/database/queries/memory-queue-queries.ts +11 -0
- package/backend/database/queries/project-queries.ts +6 -0
- package/backend/database/queries/session-queries.ts +3 -0
- package/backend/database/utils/migration-runner.test.ts +196 -0
- package/backend/database/utils/migration-runner.ts +61 -16
- package/backend/database/utils/seeder-runner.ts +22 -16
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/cursor/environment.ts +1 -1
- package/backend/engine/adapters/qwen/session-store.ts +10 -1
- package/backend/engine/types.ts +7 -0
- package/backend/git/identity/cli.ts +35 -0
- package/backend/git/identity/env.test.ts +52 -1
- package/backend/git/identity/env.ts +69 -10
- package/backend/git/identity/index.ts +25 -6
- package/backend/git/identity/resolve.ts +2 -1
- package/backend/git/identity/scope-config.ts +13 -7
- package/backend/git-hosts/accounts.ts +106 -0
- package/backend/git-hosts/auth/client-ids.ts +34 -0
- package/backend/git-hosts/auth/connect.ts +110 -0
- package/backend/git-hosts/auth/endpoints.ts +130 -0
- package/backend/git-hosts/auth/flows.ts +355 -0
- package/backend/git-hosts/auth/local.ts +152 -0
- package/backend/git-hosts/ci.ts +18 -0
- package/backend/git-hosts/cli.test.ts +82 -0
- package/backend/git-hosts/cli.ts +342 -0
- package/backend/git-hosts/credentials.ts +173 -0
- package/backend/git-hosts/git-credential.ts +30 -0
- package/backend/git-hosts/health.ts +39 -0
- package/backend/git-hosts/http.ts +174 -0
- package/backend/git-hosts/index.ts +34 -0
- package/backend/git-hosts/providers/bitbucket.ts +186 -0
- package/backend/git-hosts/providers/gitea.ts +208 -0
- package/backend/git-hosts/providers/github.ts +270 -0
- package/backend/git-hosts/providers/gitlab-client.ts +70 -0
- package/backend/git-hosts/providers/gitlab.ts +285 -0
- package/backend/git-hosts/providers/locators.test.ts +68 -0
- package/backend/git-hosts/registry.ts +50 -0
- package/backend/git-hosts/service.ts +432 -0
- package/backend/git-hosts/types.ts +82 -0
- package/backend/git-hosts/urls.test.ts +42 -0
- package/backend/git-hosts/urls.ts +69 -0
- package/backend/index.ts +50 -10
- package/backend/integrations/accounts.ts +50 -3
- package/backend/integrations/registry/define.ts +9 -0
- package/backend/integrations/registry/index.ts +11 -0
- package/backend/integrations/registry/providers/bitbucket.ts +51 -0
- package/backend/integrations/registry/providers/gitea.ts +53 -0
- package/backend/integrations/registry/providers/github.ts +24 -7
- package/backend/integrations/registry/providers/gitlab.ts +57 -0
- package/backend/integrations/registry/types.ts +13 -1
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
- package/backend/mentions/diff.ts +63 -0
- package/backend/mentions/index.ts +109 -0
- package/backend/mentions/mentions.test.ts +27 -0
- package/backend/mentions/shared.ts +82 -0
- package/backend/mentions/sources/ai-changes.ts +140 -0
- package/backend/mentions/sources/chats.ts +122 -0
- package/backend/mentions/sources/database.ts +211 -0
- package/backend/mentions/sources/files.ts +240 -0
- package/backend/mentions/sources/git.ts +308 -0
- package/backend/mentions/sources/notes-memory.ts +121 -0
- package/backend/mentions/sources/ops.ts +125 -0
- package/backend/mentions/sources/preview.ts +153 -0
- package/backend/mentions/sources/projects.ts +114 -0
- package/backend/mentions/sources/system.ts +135 -0
- package/backend/mentions/sources/terminal.ts +50 -0
- package/backend/mentions/types.ts +75 -0
- package/backend/preview/browser/bot-check-frames.test.ts +49 -0
- package/backend/preview/browser/bot-check-frames.ts +66 -0
- package/backend/preview/browser/browser-dialog-handler.ts +6 -5
- package/backend/preview/browser/browser-host-bridge.ts +4 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
- package/backend/preview/browser/browser-pool.ts +26 -17
- package/backend/preview/browser/browser-preview-service.ts +164 -2
- package/backend/preview/browser/browser-screenshot.test.ts +113 -0
- package/backend/preview/browser/browser-screenshot.ts +396 -0
- package/backend/preview/browser/browser-tab-manager.ts +35 -186
- package/backend/preview/browser/browser-video-capture.ts +12 -17
- package/backend/preview/browser/element-describe.ts +125 -0
- package/backend/preview/browser/page-binding.ts +141 -0
- package/backend/preview/browser/screenshot-files.test.ts +117 -0
- package/backend/preview/browser/screenshot-files.ts +134 -0
- package/backend/preview/browser/user-agent.test.ts +25 -0
- package/backend/preview/browser/user-agent.ts +100 -0
- package/backend/projects/engine-transcripts.ts +153 -0
- package/backend/projects/folder-guard.ts +55 -0
- package/backend/projects/move.test.ts +208 -0
- package/backend/projects/move.ts +277 -0
- package/backend/projects/project-cleanup.integration.test.ts +3 -1
- package/backend/projects/project-cleanup.ts +10 -0
- package/backend/storage/actions.ts +260 -0
- package/backend/storage/chats.test.ts +57 -0
- package/backend/storage/chats.ts +170 -0
- package/backend/storage/database.ts +105 -0
- package/backend/storage/engine-homes.ts +145 -0
- package/backend/storage/fs-size.ts +111 -0
- package/backend/storage/history.ts +39 -0
- package/backend/storage/policy.ts +156 -0
- package/backend/storage/preview-profiles.ts +169 -0
- package/backend/storage/purge.ts +158 -0
- package/backend/storage/scanner.ts +339 -0
- package/backend/storage/session-index.ts +208 -0
- package/backend/storage/snapshots.ts +99 -0
- package/backend/storage/storage-flow.test.ts +137 -0
- package/backend/storage/transcripts/aliases.ts +75 -0
- package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
- package/backend/storage/transcripts/claude-dedupe.ts +152 -0
- package/backend/storage/transcripts/claude.ts +155 -0
- package/backend/storage/transcripts/cursor.ts +165 -0
- package/backend/storage/transcripts/file-stores.ts +224 -0
- package/backend/storage/transcripts/index.ts +207 -0
- package/backend/storage/transcripts/opencode.ts +124 -0
- package/backend/storage/transcripts/references.ts +42 -0
- package/backend/storage/transcripts/types.ts +58 -0
- package/backend/storage/worktrees.ts +114 -0
- package/backend/terminal/ptykit.ts +25 -0
- package/backend/update/registry.ts +24 -0
- package/backend/update/release-notes.test.ts +110 -0
- package/backend/update/release-notes.ts +132 -0
- package/backend/update/restart.ts +159 -0
- package/backend/utils/env.test.ts +64 -0
- package/backend/utils/env.ts +23 -55
- package/backend/utils/port-utils.ts +13 -0
- package/backend/work/index.ts +13 -2
- package/backend/work/providers/github/actions-logs.ts +1 -1
- package/backend/work/providers/github/adapter.ts +32 -1
- package/backend/work/providers/github/client.ts +7 -3
- package/backend/work/providers/gitlab/adapter.ts +770 -0
- package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
- package/backend/work/service.ts +60 -36
- package/backend/work/start-work.ts +1 -1
- package/backend/work/types.ts +4 -0
- package/backend/worktrees/index.ts +1 -0
- package/backend/worktrees/service.ts +23 -2
- package/backend/ws/chat/composer.ts +47 -6
- package/backend/ws/files/search.ts +1 -1
- package/backend/ws/files/write.ts +27 -0
- package/backend/ws/hosting/index.ts +231 -0
- package/backend/ws/index.ts +12 -2
- package/backend/ws/integrations/crud.ts +31 -5
- package/backend/ws/integrations/hosting-auth.ts +227 -0
- package/backend/ws/integrations/index.ts +2 -0
- package/backend/ws/mentions/index.ts +81 -0
- package/backend/ws/preview/browser/screenshot.ts +184 -0
- package/backend/ws/preview/index.ts +23 -0
- package/backend/ws/projects/crud.ts +66 -58
- package/backend/ws/sessions/crud.ts +7 -95
- package/backend/ws/snapshot/changes.ts +3 -3
- package/backend/ws/storage/index.ts +102 -0
- package/backend/ws/system/index.ts +7 -0
- package/backend/ws/system/operations.ts +125 -69
- package/backend/ws/work/context.ts +3 -4
- package/backend/ws/work/crud.ts +33 -0
- package/backend/ws/work/schemas.ts +4 -1
- package/bin/clopen.ts +15 -16
- package/dist/assets/{index-By6KdSLT.js → index-B9rHDvjg.js} +1 -1
- package/dist/assets/index-B9rHDvjg.js.br +0 -0
- package/dist/assets/index-B9rHDvjg.js.gz +0 -0
- package/dist/assets/{index-DV4TiDn1.js → index-DFlwOd7k.js} +1 -1
- package/dist/assets/index-DFlwOd7k.js.br +0 -0
- package/dist/assets/index-DFlwOd7k.js.gz +0 -0
- package/dist/assets/main-Bz_brxxS.css +1 -0
- package/dist/assets/main-Bz_brxxS.css.br +0 -0
- package/dist/assets/main-Bz_brxxS.css.gz +0 -0
- package/dist/assets/main-DRcX9SHx.js +1273 -0
- package/dist/assets/main-DRcX9SHx.js.br +0 -0
- package/dist/assets/main-DRcX9SHx.js.gz +0 -0
- package/dist/assets/pdf-DfwfQPLy.js +57 -0
- package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
- package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
- package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
- package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
- package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
- package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
- package/package.json +6 -7
- package/scripts/start.ts +21 -4
- package/shared/constants/binary-extensions.ts +20 -4
- package/shared/constants/support.test.ts +27 -0
- package/shared/constants/support.ts +79 -0
- package/shared/constants/tool-icons.ts +7 -1
- package/shared/types/database/schema.ts +6 -0
- package/shared/types/git-hosting.ts +241 -0
- package/shared/types/integrations.ts +51 -1
- package/shared/types/mentions.ts +96 -0
- package/shared/types/release-notes.ts +31 -0
- package/shared/types/storage.ts +175 -0
- package/shared/types/stores/settings.ts +16 -0
- package/shared/types/unified/index.ts +1 -0
- package/shared/types/unified/message.ts +26 -1
- package/shared/types/unified/tool.ts +4 -0
- package/shared/types/work.ts +6 -0
- package/shared/utils/attachment-mentions.test.ts +39 -0
- package/shared/utils/attachment-mentions.ts +100 -0
- package/shared/utils/context-document.test.ts +53 -0
- package/shared/utils/context-document.ts +226 -0
- package/shared/utils/device-frame.test.ts +73 -0
- package/shared/utils/device-frame.ts +320 -0
- package/shared/utils/fuzzy.ts +79 -0
- package/shared/utils/launcher-fingerprint.test.ts +73 -0
- package/shared/utils/launcher-fingerprint.ts +108 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/page-colors.test.ts +17 -0
- package/shared/utils/page-colors.ts +24 -0
- package/shared/utils/process-supervisor.test.ts +18 -1
- package/shared/utils/process-supervisor.ts +12 -23
- package/shared/utils/restart-intent.test.ts +57 -0
- package/shared/utils/restart-intent.ts +80 -0
- package/shared/utils/semver.test.ts +33 -0
- package/shared/utils/semver.ts +35 -0
- package/shared/utils/supervised-child.ts +44 -0
- package/shared/utils/supervisor-protocol.ts +20 -0
- package/.env.example +0 -9
- package/dist/assets/index-By6KdSLT.js.br +0 -0
- package/dist/assets/index-By6KdSLT.js.gz +0 -0
- package/dist/assets/index-DV4TiDn1.js.br +0 -0
- package/dist/assets/index-DV4TiDn1.js.gz +0 -0
- package/dist/assets/main-DIESTGTD.css +0 -1
- package/dist/assets/main-DIESTGTD.css.br +0 -0
- package/dist/assets/main-DIESTGTD.css.gz +0 -0
- package/dist/assets/main-Da3JKoua.js +0 -1240
- package/dist/assets/main-Da3JKoua.js.br +0 -0
- package/dist/assets/main-Da3JKoua.js.gz +0 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two OAuth sign-ins: the device flow (GitHub, GitLab) and the browser
|
|
3
|
+
* authorization-code flow with PKCE (Gitea/Forgejo, self-managed GitLab).
|
|
4
|
+
*
|
|
5
|
+
* Both are driven from the SERVER. The client starts a flow, shows what the
|
|
6
|
+
* user needs (a code to type, or a page to open), and polls one status. The
|
|
7
|
+
* device code and the PKCE verifier never leave this module — a device code is
|
|
8
|
+
* a credential until it expires, and a verifier is what makes a stolen
|
|
9
|
+
* authorization code worthless.
|
|
10
|
+
*
|
|
11
|
+
* Flows live in memory. A restart mid-sign-in loses the flow, and the dialog
|
|
12
|
+
* reports it as expired; there is nothing durable worth persisting about a
|
|
13
|
+
* code that dies in fifteen minutes.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { randomBytes } from 'node:crypto';
|
|
17
|
+
import type {
|
|
18
|
+
AuthFlowPoll,
|
|
19
|
+
AuthFlowStatus,
|
|
20
|
+
BrowserFlowStart,
|
|
21
|
+
DeviceFlowStart,
|
|
22
|
+
GitHostKind
|
|
23
|
+
} from '$shared/types/git-hosting';
|
|
24
|
+
import type { IntegrationCapability } from '$shared/types/integrations';
|
|
25
|
+
import { getProvider } from '$backend/integrations';
|
|
26
|
+
import { SERVER_ENV } from '$backend/utils/env';
|
|
27
|
+
import { debug } from '$shared/utils/logger';
|
|
28
|
+
import { browserEndpoints, deviceEndpoints, OAuthGrantError, requestToken, type TokenSet } from './endpoints';
|
|
29
|
+
import { bundledClientId } from './client-ids';
|
|
30
|
+
import { connectHostAccount } from './connect';
|
|
31
|
+
import { normaliseBaseUrl } from '../urls';
|
|
32
|
+
|
|
33
|
+
interface FlowTarget {
|
|
34
|
+
provider: GitHostKind;
|
|
35
|
+
baseUrl: string;
|
|
36
|
+
clientId: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
projectId?: string | null;
|
|
39
|
+
capabilities?: IntegrationCapability[];
|
|
40
|
+
/** Reconnect this account rather than creating one. */
|
|
41
|
+
accountId?: string | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface FlowState {
|
|
45
|
+
target: FlowTarget;
|
|
46
|
+
status: AuthFlowStatus;
|
|
47
|
+
accountId: string | null;
|
|
48
|
+
error: string | null;
|
|
49
|
+
expiresAt: number;
|
|
50
|
+
cancel?: () => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface DeviceFlow extends FlowState {
|
|
54
|
+
kind: 'device';
|
|
55
|
+
deviceCode: string;
|
|
56
|
+
intervalMs: number;
|
|
57
|
+
tokenUrl: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface BrowserFlow extends FlowState {
|
|
61
|
+
kind: 'browser';
|
|
62
|
+
verifier: string;
|
|
63
|
+
redirectUri: string;
|
|
64
|
+
tokenUrl: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const flows = new Map<string, DeviceFlow | BrowserFlow>();
|
|
68
|
+
|
|
69
|
+
/** Settled flows are kept this long so a late poll still learns the outcome. */
|
|
70
|
+
const SETTLED_TTL_MS = 5 * 60 * 1000;
|
|
71
|
+
|
|
72
|
+
function newId(): string {
|
|
73
|
+
return randomBytes(18).toString('base64url');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function settle(id: string, flow: FlowState, status: AuthFlowStatus, detail: { accountId?: string; error?: string } = {}): void {
|
|
77
|
+
flow.status = status;
|
|
78
|
+
flow.accountId = detail.accountId ?? null;
|
|
79
|
+
flow.error = detail.error ?? null;
|
|
80
|
+
flow.cancel?.();
|
|
81
|
+
setTimeout(() => flows.delete(id), SETTLED_TTL_MS).unref?.();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The client id for a flow: the user's own app when one was given, Clopen's
|
|
86
|
+
* for the cloud host otherwise. A self-hosted server never falls back to ours
|
|
87
|
+
* — our app does not exist there, and the sign-in page would say so in a way
|
|
88
|
+
* that reads like Clopen is broken.
|
|
89
|
+
*/
|
|
90
|
+
function resolveClientId(provider: GitHostKind, baseUrl: string, own: string | undefined): string {
|
|
91
|
+
const given = (own ?? '').trim();
|
|
92
|
+
if (given) return given;
|
|
93
|
+
if (!baseUrl) {
|
|
94
|
+
const bundled = bundledClientId(provider);
|
|
95
|
+
if (bundled) return bundled;
|
|
96
|
+
throw new Error('Browser sign-in is not configured for this Clopen build. Use a token, or enter your own OAuth application\'s client id.');
|
|
97
|
+
}
|
|
98
|
+
throw new Error('A self-hosted server needs its own OAuth application. Register one there and enter its client id, or use a token.');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function scopesFor(provider: GitHostKind): string[] {
|
|
102
|
+
return getProvider(provider)?.hosting?.scopes ?? [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function finish(id: string, flow: DeviceFlow | BrowserFlow, tokens: TokenSet): Promise<void> {
|
|
106
|
+
try {
|
|
107
|
+
const { account } = await connectHostAccount({
|
|
108
|
+
provider: flow.target.provider,
|
|
109
|
+
accountId: flow.target.accountId,
|
|
110
|
+
label: flow.target.label,
|
|
111
|
+
projectId: flow.target.projectId,
|
|
112
|
+
capabilities: flow.target.capabilities,
|
|
113
|
+
authMethod: flow.kind === 'device' ? 'oauth-device' : 'oauth-code',
|
|
114
|
+
source: 'oauth',
|
|
115
|
+
fields: {
|
|
116
|
+
token: tokens.accessToken,
|
|
117
|
+
...(flow.target.baseUrl && { baseUrl: flow.target.baseUrl })
|
|
118
|
+
},
|
|
119
|
+
extra: {
|
|
120
|
+
clientId: flow.target.clientId,
|
|
121
|
+
...(tokens.refreshToken && { refreshToken: tokens.refreshToken }),
|
|
122
|
+
...(tokens.expiresAt && { expiresAt: tokens.expiresAt })
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
settle(id, flow, 'success', { accountId: account.id });
|
|
126
|
+
} catch (error) {
|
|
127
|
+
settle(id, flow, 'error', { error: error instanceof Error ? error.message : String(error) });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Device flow
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
interface DeviceCodeWire {
|
|
136
|
+
device_code?: string;
|
|
137
|
+
user_code?: string;
|
|
138
|
+
verification_uri?: string;
|
|
139
|
+
verification_url?: string;
|
|
140
|
+
verification_uri_complete?: string;
|
|
141
|
+
expires_in?: number;
|
|
142
|
+
interval?: number;
|
|
143
|
+
error?: string;
|
|
144
|
+
error_description?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function startDeviceFlow(input: Omit<FlowTarget, 'clientId' | 'baseUrl'> & { baseUrl?: string; clientId?: string }): Promise<DeviceFlowStart> {
|
|
148
|
+
const baseUrl = normaliseBaseUrl(input.baseUrl);
|
|
149
|
+
const endpoints = deviceEndpoints(input.provider, baseUrl);
|
|
150
|
+
if (!endpoints) throw new Error('This service does not support signing in with a code');
|
|
151
|
+
const clientId = resolveClientId(input.provider, baseUrl, input.clientId);
|
|
152
|
+
|
|
153
|
+
let wire: DeviceCodeWire;
|
|
154
|
+
try {
|
|
155
|
+
const response = await fetch(endpoints.deviceCode, {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers: { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'clopen' },
|
|
158
|
+
body: new URLSearchParams({ client_id: clientId, scope: scopesFor(input.provider).join(' ') }).toString(),
|
|
159
|
+
signal: AbortSignal.timeout(20_000)
|
|
160
|
+
});
|
|
161
|
+
wire = (await response.json().catch(() => ({}))) as DeviceCodeWire;
|
|
162
|
+
if (!response.ok && !wire.error) wire.error = `HTTP ${response.status}`;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw new Error(`Could not reach the sign-in server: ${error instanceof Error ? error.message : String(error)}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const verificationUri = wire.verification_uri ?? wire.verification_url;
|
|
168
|
+
if (wire.error || !wire.device_code || !wire.user_code || !verificationUri) {
|
|
169
|
+
// The usual cause on a self-hosted server: the application does not have
|
|
170
|
+
// the device grant enabled, or is confidential.
|
|
171
|
+
throw new Error(
|
|
172
|
+
wire.error_description || wire.error
|
|
173
|
+
? `The server refused the sign-in: ${wire.error_description || wire.error}. Check that the OAuth application allows the device flow and is not confidential.`
|
|
174
|
+
: 'The server did not start a sign-in'
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const id = newId();
|
|
179
|
+
const flow: DeviceFlow = {
|
|
180
|
+
kind: 'device',
|
|
181
|
+
target: { ...input, baseUrl, clientId },
|
|
182
|
+
status: 'pending',
|
|
183
|
+
accountId: null,
|
|
184
|
+
error: null,
|
|
185
|
+
expiresAt: Date.now() + (wire.expires_in ?? 900) * 1000,
|
|
186
|
+
deviceCode: wire.device_code,
|
|
187
|
+
intervalMs: Math.max(wire.interval ?? 5, 1) * 1000,
|
|
188
|
+
tokenUrl: endpoints.token
|
|
189
|
+
};
|
|
190
|
+
flows.set(id, flow);
|
|
191
|
+
void pollDevice(id, flow);
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
flowId: id,
|
|
195
|
+
userCode: wire.user_code,
|
|
196
|
+
verificationUri,
|
|
197
|
+
verificationUriComplete: wire.verification_uri_complete ?? null,
|
|
198
|
+
expiresAt: new Date(flow.expiresAt).toISOString(),
|
|
199
|
+
intervalSeconds: flow.intervalMs / 1000
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Ask the token endpoint at the interval the server asked for, until it answers. */
|
|
204
|
+
async function pollDevice(id: string, flow: DeviceFlow): Promise<void> {
|
|
205
|
+
let stopped = false;
|
|
206
|
+
flow.cancel = () => { stopped = true; };
|
|
207
|
+
|
|
208
|
+
while (!stopped && flow.status === 'pending') {
|
|
209
|
+
await Bun.sleep(flow.intervalMs);
|
|
210
|
+
if (stopped || flow.status !== 'pending') return;
|
|
211
|
+
if (Date.now() > flow.expiresAt) {
|
|
212
|
+
settle(id, flow, 'expired');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const tokens = await requestToken(flow.tokenUrl, {
|
|
217
|
+
client_id: flow.target.clientId,
|
|
218
|
+
device_code: flow.deviceCode,
|
|
219
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code'
|
|
220
|
+
});
|
|
221
|
+
await finish(id, flow, tokens);
|
|
222
|
+
return;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error instanceof OAuthGrantError) {
|
|
225
|
+
if (error.code === 'authorization_pending') continue;
|
|
226
|
+
// The server is telling us to back off; RFC 8628 says by five seconds.
|
|
227
|
+
if (error.code === 'slow_down') {
|
|
228
|
+
flow.intervalMs += 5000;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (error.code === 'expired_token') {
|
|
232
|
+
settle(id, flow, 'expired');
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (error.code === 'access_denied') {
|
|
236
|
+
settle(id, flow, 'denied');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
debug.warn('git-hosts', 'Device sign-in failed:', error);
|
|
241
|
+
settle(id, flow, 'error', { error: error instanceof Error ? error.message : String(error) });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// Browser flow (authorization code + PKCE)
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
/** Where the service sends the browser back. Registered by the user on their OAuth app. */
|
|
252
|
+
export function oauthCallbackUri(): string {
|
|
253
|
+
return `http://localhost:${SERVER_ENV.PORT}/api/integrations/oauth/callback`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function challengeOf(verifier: string): Promise<string> {
|
|
257
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));
|
|
258
|
+
return Buffer.from(digest).toString('base64url');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Ten minutes to finish signing in, matching the device flow's window. */
|
|
262
|
+
const BROWSER_FLOW_MS = 10 * 60 * 1000;
|
|
263
|
+
|
|
264
|
+
export async function startBrowserFlow(input: Omit<FlowTarget, 'clientId' | 'baseUrl'> & { baseUrl?: string; clientId?: string }): Promise<BrowserFlowStart> {
|
|
265
|
+
const baseUrl = normaliseBaseUrl(input.baseUrl);
|
|
266
|
+
const endpoints = browserEndpoints(input.provider, baseUrl);
|
|
267
|
+
if (!endpoints) throw new Error('This service does not support signing in through the browser');
|
|
268
|
+
const clientId = resolveClientId(input.provider, baseUrl, input.clientId);
|
|
269
|
+
|
|
270
|
+
const id = newId();
|
|
271
|
+
const verifier = randomBytes(48).toString('base64url');
|
|
272
|
+
const redirectUri = oauthCallbackUri();
|
|
273
|
+
const flow: BrowserFlow = {
|
|
274
|
+
kind: 'browser',
|
|
275
|
+
target: { ...input, baseUrl, clientId },
|
|
276
|
+
status: 'pending',
|
|
277
|
+
accountId: null,
|
|
278
|
+
error: null,
|
|
279
|
+
expiresAt: Date.now() + BROWSER_FLOW_MS,
|
|
280
|
+
verifier,
|
|
281
|
+
redirectUri,
|
|
282
|
+
tokenUrl: endpoints.token
|
|
283
|
+
};
|
|
284
|
+
flows.set(id, flow);
|
|
285
|
+
const timer = setTimeout(() => {
|
|
286
|
+
if (flow.status === 'pending') settle(id, flow, 'expired');
|
|
287
|
+
}, BROWSER_FLOW_MS);
|
|
288
|
+
flow.cancel = () => clearTimeout(timer);
|
|
289
|
+
|
|
290
|
+
const params = new URLSearchParams({
|
|
291
|
+
client_id: clientId,
|
|
292
|
+
redirect_uri: redirectUri,
|
|
293
|
+
response_type: 'code',
|
|
294
|
+
// The flow id doubles as the OAuth state: unguessable, single-use, and
|
|
295
|
+
// the key the callback finds the verifier under.
|
|
296
|
+
state: id,
|
|
297
|
+
code_challenge: await challengeOf(verifier),
|
|
298
|
+
code_challenge_method: 'S256',
|
|
299
|
+
scope: scopesFor(input.provider).join(' ')
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return { flowId: id, authorizeUrl: `${endpoints.authorize}?${params.toString()}`, redirectUri };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Called by the HTTP callback route. Throws with a message for the landing page. */
|
|
306
|
+
export async function completeBrowserFlow(state: string, code: string): Promise<void> {
|
|
307
|
+
const flow = flows.get(state);
|
|
308
|
+
if (!flow || flow.kind !== 'browser') throw new Error('This sign-in has expired or was already used');
|
|
309
|
+
if (flow.status !== 'pending') throw new Error('This sign-in has already finished');
|
|
310
|
+
|
|
311
|
+
let tokens: TokenSet;
|
|
312
|
+
try {
|
|
313
|
+
tokens = await requestToken(flow.tokenUrl, {
|
|
314
|
+
grant_type: 'authorization_code',
|
|
315
|
+
code,
|
|
316
|
+
client_id: flow.target.clientId,
|
|
317
|
+
redirect_uri: flow.redirectUri,
|
|
318
|
+
code_verifier: flow.verifier
|
|
319
|
+
});
|
|
320
|
+
} catch (error) {
|
|
321
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
322
|
+
settle(state, flow, 'error', { error: message });
|
|
323
|
+
throw new Error(message);
|
|
324
|
+
}
|
|
325
|
+
await finish(state, flow, tokens);
|
|
326
|
+
// `finish` settles the flow; read it back through a widened type, since the
|
|
327
|
+
// narrowing above still believes it is pending.
|
|
328
|
+
const settled = flow as FlowState;
|
|
329
|
+
if (settled.status === 'error') throw new Error(settled.error ?? 'Could not connect the account');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The browser came back with an error instead of a code. */
|
|
333
|
+
export function failBrowserFlow(state: string, error: string): void {
|
|
334
|
+
const flow = flows.get(state);
|
|
335
|
+
if (!flow || flow.status !== 'pending') return;
|
|
336
|
+
settle(state, flow, error === 'access_denied' ? 'denied' : 'error', { error });
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
// Both
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
|
|
343
|
+
export function pollFlow(id: string): AuthFlowPoll {
|
|
344
|
+
const flow = flows.get(id);
|
|
345
|
+
if (!flow) return { status: 'expired', accountId: null, error: null };
|
|
346
|
+
if (flow.status === 'pending' && Date.now() > flow.expiresAt) settle(id, flow, 'expired');
|
|
347
|
+
return { status: flow.status, accountId: flow.accountId, error: flow.error };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function cancelFlow(id: string): void {
|
|
351
|
+
const flow = flows.get(id);
|
|
352
|
+
if (!flow) return;
|
|
353
|
+
flow.cancel?.();
|
|
354
|
+
flows.delete(id);
|
|
355
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connecting from what is already on this machine, and recognising a server.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { DetectedCredential, GitHostKind, ServerProbeResult } from '$shared/types/git-hosting';
|
|
6
|
+
import type { IntegrationCapability } from '$shared/types/integrations';
|
|
7
|
+
import { getProvider } from '$backend/integrations';
|
|
8
|
+
import { cliForProvider, detectCliLogins, readCliToken, readKeychain, teaServerUrl, type CliTool } from '../cli';
|
|
9
|
+
import { hostOfBase, normaliseBaseUrl } from '../urls';
|
|
10
|
+
import { connectHostAccount } from './connect';
|
|
11
|
+
|
|
12
|
+
interface LocalTarget {
|
|
13
|
+
provider: GitHostKind;
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
projectId?: string | null;
|
|
17
|
+
capabilities?: IntegrationCapability[];
|
|
18
|
+
accountId?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The host a provider + optional server URL resolves to. */
|
|
22
|
+
function hostFor(provider: GitHostKind, baseUrl: string | undefined): string | null {
|
|
23
|
+
const base = normaliseBaseUrl(baseUrl);
|
|
24
|
+
if (base) return hostOfBase(base) || null;
|
|
25
|
+
return getProvider(provider)?.hosting?.defaultHost ?? null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Logins found on this machine. With no server URL, every host the CLI knows
|
|
30
|
+
* is listed — that is how "gh is signed in to ghe.acme.com" gets offered
|
|
31
|
+
* before anyone types the address.
|
|
32
|
+
*/
|
|
33
|
+
export async function detectLocal(provider: GitHostKind, baseUrl?: string): Promise<DetectedCredential[]> {
|
|
34
|
+
const explicit = normaliseBaseUrl(baseUrl);
|
|
35
|
+
const host = explicit ? hostOfBase(explicit) : null;
|
|
36
|
+
const found = await detectCliLogins(provider, host);
|
|
37
|
+
if (host || found.length > 0) return found;
|
|
38
|
+
// No URL and nothing listed: at least ask about the cloud host by name,
|
|
39
|
+
// which catches a CLI that keeps its hosts file somewhere unusual.
|
|
40
|
+
const fallbackHost = hostFor(provider, undefined);
|
|
41
|
+
return fallbackHost ? detectCliLogins(provider, fallbackHost) : [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function connectFromCli(
|
|
45
|
+
input: LocalTarget & { host: string; mode: 'linked' | 'copy' }
|
|
46
|
+
): Promise<Awaited<ReturnType<typeof connectHostAccount>>> {
|
|
47
|
+
const tool = cliForProvider(input.provider);
|
|
48
|
+
if (!tool) throw new Error('This service has no CLI to borrow a login from');
|
|
49
|
+
|
|
50
|
+
const token = await readCliToken(tool, input.host);
|
|
51
|
+
if (!token) throw new Error(`${tool} has no token for ${input.host}. Run "${tool} auth login" first.`);
|
|
52
|
+
|
|
53
|
+
// The server root: the cloud default needs none; any other host needs one,
|
|
54
|
+
// and `tea` knows the exact URL including a sub-path.
|
|
55
|
+
const cloudHost = getProvider(input.provider)?.hosting?.defaultHost;
|
|
56
|
+
const baseUrl = input.host === cloudHost
|
|
57
|
+
? ''
|
|
58
|
+
: (tool === 'tea' ? teaServerUrl(input.host) : null) ?? `https://${input.host}`;
|
|
59
|
+
|
|
60
|
+
const linked = input.mode === 'linked';
|
|
61
|
+
return connectHostAccount({
|
|
62
|
+
provider: input.provider,
|
|
63
|
+
accountId: input.accountId,
|
|
64
|
+
label: input.label,
|
|
65
|
+
projectId: input.projectId,
|
|
66
|
+
capabilities: input.capabilities,
|
|
67
|
+
authMethod: 'cli',
|
|
68
|
+
source: linked ? 'cli' : 'token',
|
|
69
|
+
fields: { token, ...(baseUrl && { baseUrl }) },
|
|
70
|
+
extra: linked ? { cliTool: tool satisfies CliTool, cliHost: input.host } : {}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function connectFromKeychain(
|
|
75
|
+
input: LocalTarget
|
|
76
|
+
): Promise<Awaited<ReturnType<typeof connectHostAccount>>> {
|
|
77
|
+
const host = hostFor(input.provider, input.baseUrl);
|
|
78
|
+
if (!host) throw new Error('Enter the server URL first');
|
|
79
|
+
const found = await readKeychain(host);
|
|
80
|
+
if (!found) throw new Error(`Nothing is stored for ${host} in git's credential helpers.`);
|
|
81
|
+
|
|
82
|
+
const baseUrl = normaliseBaseUrl(input.baseUrl);
|
|
83
|
+
return connectHostAccount({
|
|
84
|
+
provider: input.provider,
|
|
85
|
+
accountId: input.accountId,
|
|
86
|
+
label: input.label,
|
|
87
|
+
projectId: input.projectId,
|
|
88
|
+
capabilities: input.capabilities,
|
|
89
|
+
authMethod: 'cli',
|
|
90
|
+
source: 'keychain',
|
|
91
|
+
fields: {
|
|
92
|
+
token: found.password,
|
|
93
|
+
...(baseUrl && { baseUrl }),
|
|
94
|
+
// Bitbucket authenticates the API as email:token. A keychain entry
|
|
95
|
+
// holds the git username instead, which is only right if the user
|
|
96
|
+
// stored their email there; the connect form asks when it is not.
|
|
97
|
+
...(input.provider === 'bitbucket' && found.username.includes('@') && { email: found.username })
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* What a server URL is. Tried in order of how cheaply each answers:
|
|
104
|
+
* GitLab's version endpoint needs auth on most installs but still answers 401
|
|
105
|
+
* with a recognisable shape, Gitea's and Forgejo's are public.
|
|
106
|
+
*/
|
|
107
|
+
export async function probeServer(rawUrl: string): Promise<ServerProbeResult> {
|
|
108
|
+
const baseUrl = normaliseBaseUrl(rawUrl);
|
|
109
|
+
const empty: ServerProbeResult = { provider: null, flavour: null, version: null, baseUrl };
|
|
110
|
+
if (!baseUrl) return empty;
|
|
111
|
+
|
|
112
|
+
const get = async (path: string) => {
|
|
113
|
+
try {
|
|
114
|
+
return await fetch(`${baseUrl}${path}`, {
|
|
115
|
+
headers: { Accept: 'application/json', 'User-Agent': 'clopen' },
|
|
116
|
+
signal: AbortSignal.timeout(8000),
|
|
117
|
+
redirect: 'follow'
|
|
118
|
+
});
|
|
119
|
+
} catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Forgejo answers its own endpoint; Gitea does not, so ask Forgejo first.
|
|
125
|
+
const forgejo = await get('/api/forgejo/v1/version');
|
|
126
|
+
if (forgejo?.ok) {
|
|
127
|
+
const body = (await forgejo.json().catch(() => ({}))) as { version?: string };
|
|
128
|
+
return { provider: 'gitea', flavour: 'forgejo', version: body.version ?? null, baseUrl };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const gitea = await get('/api/v1/version');
|
|
132
|
+
if (gitea?.ok) {
|
|
133
|
+
const body = (await gitea.json().catch(() => ({}))) as { version?: string };
|
|
134
|
+
return { provider: 'gitea', flavour: 'gitea', version: body.version ?? null, baseUrl };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const gitlab = await get('/api/v4/version');
|
|
138
|
+
if (gitlab && (gitlab.ok || gitlab.status === 401)) {
|
|
139
|
+
const body = (await gitlab.json().catch(() => ({}))) as { version?: string; message?: string };
|
|
140
|
+
if (gitlab.ok || body.message?.includes('Unauthorized')) {
|
|
141
|
+
return { provider: 'gitlab', flavour: 'gitlab', version: body.version ?? null, baseUrl };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const ghes = await get('/api/v3/meta');
|
|
146
|
+
if (ghes && (ghes.ok || ghes.headers.get('x-github-request-id'))) {
|
|
147
|
+
const body = (await ghes.json().catch(() => ({}))) as { installed_version?: string };
|
|
148
|
+
return { provider: 'github', flavour: 'github-enterprise', version: body.installed_version ?? null, baseUrl };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return empty;
|
|
152
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rolling many CI signals on one commit into the single state a row can show.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { CommitCiState, CommitCiStatus } from '$shared/types/git-hosting';
|
|
6
|
+
|
|
7
|
+
/** One state for a commit from every signal on it: any failure fails, any pending is pending. */
|
|
8
|
+
export function rollUp(sha: string, states: CommitCiState[], url: string | null): CommitCiStatus {
|
|
9
|
+
if (states.length === 0) return { sha, state: 'none', url: null, summary: 'No checks' };
|
|
10
|
+
const passed = states.filter((state) => state === 'success').length;
|
|
11
|
+
const failed = states.filter((state) => state === 'failure').length;
|
|
12
|
+
const pending = states.filter((state) => state === 'pending').length;
|
|
13
|
+
const state: CommitCiState = failed > 0 ? 'failure' : pending > 0 ? 'pending' : 'success';
|
|
14
|
+
const parts = [`${passed} of ${states.length} checks passed`];
|
|
15
|
+
if (failed > 0) parts.push(`${failed} failed`);
|
|
16
|
+
if (pending > 0) parts.push(`${pending} running`);
|
|
17
|
+
return { sha, state, url, summary: parts.join(', ') };
|
|
18
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { parseGhHosts, parseGlabHosts, parseTeaLogins } from './cli';
|
|
3
|
+
|
|
4
|
+
describe('parseGhHosts', () => {
|
|
5
|
+
test('reads each host and the user signed in to it', () => {
|
|
6
|
+
const text = [
|
|
7
|
+
'github.com:',
|
|
8
|
+
' users:',
|
|
9
|
+
' octocat:',
|
|
10
|
+
' git_protocol: https',
|
|
11
|
+
' user: octocat',
|
|
12
|
+
'ghe.example.com:',
|
|
13
|
+
' user: "mona"',
|
|
14
|
+
''
|
|
15
|
+
].join('\n');
|
|
16
|
+
expect(parseGhHosts(text)).toEqual([
|
|
17
|
+
{ host: 'github.com', login: 'octocat' },
|
|
18
|
+
{ host: 'ghe.example.com', login: 'mona' }
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('a host with no user line is still listed', () => {
|
|
23
|
+
expect(parseGhHosts('github.com:\n git_protocol: ssh\n')).toEqual([{ host: 'github.com', login: null }]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('ignores comments and blank lines', () => {
|
|
27
|
+
expect(parseGhHosts('# managed by gh\n\n')).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('parseGlabHosts', () => {
|
|
32
|
+
test('reads hosts nested under hosts:, with their user and whether a token is set', () => {
|
|
33
|
+
const text = [
|
|
34
|
+
'git_protocol: ssh',
|
|
35
|
+
'hosts:',
|
|
36
|
+
' gitlab.com:',
|
|
37
|
+
' token: glpat-xxxxxxxx',
|
|
38
|
+
' api_host: gitlab.com',
|
|
39
|
+
' user: octocat',
|
|
40
|
+
' gitlab.example.com:',
|
|
41
|
+
' api_protocol: https',
|
|
42
|
+
' user: mona',
|
|
43
|
+
'editor: vim',
|
|
44
|
+
''
|
|
45
|
+
].join('\n');
|
|
46
|
+
expect(parseGlabHosts(text)).toEqual([
|
|
47
|
+
{ host: 'gitlab.com', login: 'octocat', hasToken: true },
|
|
48
|
+
{ host: 'gitlab.example.com', login: 'mona', hasToken: false }
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('keys outside hosts: are not hosts', () => {
|
|
53
|
+
expect(parseGlabHosts('aliases:\n co: mr checkout\n')).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('parseTeaLogins', () => {
|
|
58
|
+
test('reads every login in the list, with its url, user and token', () => {
|
|
59
|
+
const text = [
|
|
60
|
+
'logins:',
|
|
61
|
+
'- name: work',
|
|
62
|
+
' url: https://git.example.com/',
|
|
63
|
+
' token: abc123',
|
|
64
|
+
' default: true',
|
|
65
|
+
' user: octocat',
|
|
66
|
+
'- name: codeberg',
|
|
67
|
+
' url: https://codeberg.org',
|
|
68
|
+
' user: mona',
|
|
69
|
+
'preferences:',
|
|
70
|
+
' editor: false',
|
|
71
|
+
''
|
|
72
|
+
].join('\n');
|
|
73
|
+
expect(parseTeaLogins(text)).toEqual([
|
|
74
|
+
{ url: 'https://git.example.com', host: 'git.example.com', login: 'octocat', token: 'abc123' },
|
|
75
|
+
{ url: 'https://codeberg.org', host: 'codeberg.org', login: 'mona', token: null }
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('a login with an unparseable url is skipped, not thrown', () => {
|
|
80
|
+
expect(parseTeaLogins('logins:\n- name: x\n url: not a url\n')).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
});
|