@openchamber/web 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
- package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
- package/dist/assets/FilesView-B_NJFLBH.js +17 -0
- package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
- package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
- package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
- package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
- package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
- package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
- package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
- package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
- package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
- package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
- package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
- package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
- package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
- package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
- package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
- package/dist/assets/de-D4hpTCNY.js +10 -0
- package/dist/assets/es-Bw9m3H62.js +16 -0
- package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
- package/dist/assets/fr-Bhll42P0.js +14 -0
- package/dist/assets/index-Btd2mmYT.js +42 -0
- package/dist/assets/index-C-7hQnEc.css +1 -0
- package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
- package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
- package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
- package/dist/assets/ja-CsHoT43d.js +16 -0
- package/dist/assets/ko-BBNdtFa4.js +16 -0
- package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
- package/dist/assets/main-kYkr_urz.js +1000 -0
- package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
- package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
- package/dist/assets/mobile-CviaXnnU.js +2 -0
- package/dist/assets/nl-DszyktfH.js +16 -0
- package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
- package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
- package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
- package/dist/assets/pl-Bk9_mUXc.js +16 -0
- package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
- package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
- package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
- package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
- package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
- package/dist/assets/space-close-C1tL-_0t.js +1 -0
- package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
- package/dist/assets/tr-C_13w7CX.js +7 -0
- package/dist/assets/uk-BZTsG-q_.js +16 -0
- package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
- package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
- package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
- package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
- package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
- package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
- package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
- package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
- package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
- package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
- package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
- package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
- package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +4 -4
- package/server/index.js +58 -1
- package/server/lib/browser-control/DOCUMENTATION.md +8 -1
- package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
- package/server/lib/dev-tunnel/runtime.js +94 -38
- package/server/lib/dev-tunnel/tunnel.test.js +16 -2
- package/server/lib/dictation/DOCUMENTATION.md +23 -10
- package/server/lib/dictation/audio.js +28 -0
- package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
- package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
- package/server/lib/dictation/local/worker-client.js +28 -10
- package/server/lib/dictation/local/worker-process.js +25 -1
- package/server/lib/dictation/stream-manager.js +160 -53
- package/server/lib/dictation/stream-manager.test.js +108 -7
- package/server/lib/enterprise-mode.d.ts +2 -0
- package/server/lib/enterprise-mode.js +84 -9
- package/server/lib/enterprise-mode.test.js +115 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -2
- package/server/lib/fs/routes.js +28 -1
- package/server/lib/fs/routes.test.js +31 -5
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +61 -2
- package/server/lib/git/service.test.js +141 -0
- package/server/lib/github/DOCUMENTATION.md +18 -0
- package/server/lib/github/checks-summary.js +76 -0
- package/server/lib/github/pr-summaries.js +282 -0
- package/server/lib/github/pr-summaries.test.js +209 -0
- package/server/lib/github/routes.js +42 -77
- package/server/lib/github/routes.test.js +77 -0
- package/server/lib/inherited-env.js +51 -0
- package/server/lib/inherited-env.test.js +59 -0
- package/server/lib/message-search/DOCUMENTATION.md +83 -0
- package/server/lib/message-search/indexer.js +336 -0
- package/server/lib/message-search/indexer.test.js +341 -0
- package/server/lib/message-search/routes.js +92 -0
- package/server/lib/message-search/runtime.js +234 -0
- package/server/lib/message-search/runtime.test.js +108 -0
- package/server/lib/message-search/sqlite.js +74 -0
- package/server/lib/message-search/store.js +289 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +1 -1
- package/server/lib/openchamber-control/service.js +21 -2
- package/server/lib/openchamber-control/service.test.js +50 -0
- package/server/lib/openchamber-sessions/routes.js +15 -0
- package/server/lib/openchamber-sessions/routes.test.js +31 -0
- package/server/lib/opencode/DOCUMENTATION.md +43 -38
- package/server/lib/opencode/auth.d.ts +24 -0
- package/server/lib/opencode/auth.js +130 -66
- package/server/lib/opencode/auth.test.js +114 -70
- package/server/lib/opencode/compatibility.js +4 -3
- package/server/lib/opencode/compatibility.test.js +10 -10
- package/server/lib/opencode/feature-routes-runtime.js +3 -0
- package/server/lib/opencode/lifecycle.js +21 -12
- package/server/lib/opencode/lifecycle.test.js +38 -5
- package/server/lib/opencode/provider-source-route.test.js +55 -2
- package/server/lib/opencode/routes.js +17 -4
- package/server/lib/opencode/settings-helpers.js +6 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +16 -0
- package/server/lib/opencode/settings-runtime.js +9 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/v1-migration-topup.js +13 -3
- package/server/lib/opencode/v2-install.test.js +13 -13
- package/server/lib/quota/DOCUMENTATION.md +11 -5
- package/server/lib/quota/providers/claude/auth.js +19 -6
- package/server/lib/quota/providers/claude/auth.test.js +22 -9
- package/server/lib/quota/providers/claude/index.js +3 -3
- package/server/lib/quota/providers/claude/index.test.js +3 -2
- package/server/lib/quota/providers/cline-pass.js +4 -4
- package/server/lib/quota/providers/codex.js +3 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +4 -5
- package/server/lib/quota/providers/copilot.test.js +1 -1
- package/server/lib/quota/providers/deepseek.js +3 -4
- package/server/lib/quota/providers/deepseek.test.js +1 -1
- package/server/lib/quota/providers/google/auth.js +1 -3
- package/server/lib/quota/providers/google/index.js +3 -2
- package/server/lib/quota/providers/hyper.js +4 -4
- package/server/lib/quota/providers/index.js +9 -2
- package/server/lib/quota/providers/index.test.js +5 -3
- package/server/lib/quota/providers/kimi.js +16 -11
- package/server/lib/quota/providers/kimi.test.js +81 -38
- package/server/lib/quota/providers/minimax-shared.js +3 -4
- package/server/lib/quota/providers/nanogpt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.test.js +1 -1
- package/server/lib/quota/providers/openai.js +2 -8
- package/server/lib/quota/providers/opencode-go.js +5 -5
- package/server/lib/quota/providers/opencode-go.test.js +1 -1
- package/server/lib/quota/providers/openrouter.js +30 -6
- package/server/lib/quota/providers/openrouter.test.js +122 -1
- package/server/lib/quota/providers/wafer.js +3 -4
- package/server/lib/quota/providers/xai.js +12 -12
- package/server/lib/quota/providers/zai.js +3 -4
- package/server/lib/quota/providers/zai.test.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/routing/DOCUMENTATION.md +4 -0
- package/server/lib/routing/runtime.js +45 -4
- package/server/lib/routing/runtime.test.js +35 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
- package/server/lib/scheduled-tasks/chats-scope.js +50 -0
- package/server/lib/scheduled-tasks/runtime.js +57 -23
- package/server/lib/scheduled-tasks/runtime.test.js +103 -1
- package/server/lib/scheduled-tasks/service.js +37 -29
- package/server/lib/scheduled-tasks/service.test.js +39 -0
- package/server/lib/spaces/DOCUMENTATION.md +54 -9
- package/server/lib/spaces/host.js +24 -3
- package/server/lib/spaces/journey.js +111 -11
- package/server/lib/spaces/journey.test.js +189 -8
- package/server/lib/spaces/places/docker-disk.js +151 -0
- package/server/lib/spaces/places/docker-disk.test.js +167 -0
- package/server/lib/spaces/places/docker-tools.js +11 -1
- package/server/lib/spaces/places/docker.js +4 -2
- package/server/lib/spaces/places/fake-docker.js +36 -2
- package/server/lib/spaces/routes.js +21 -4
- package/server/lib/spaces/routes.test.js +6 -2
- package/server/lib/spaces/space-archive.js +275 -0
- package/server/lib/spaces/space-archive.test.js +194 -0
- package/server/lib/spaces/space-opencode.js +139 -6
- package/server/lib/spaces/space-opencode.test.js +82 -1
- package/server/lib/spaces/space-records.js +3 -0
- package/server/lib/spaces/space-setup.js +10 -5
- package/server/lib/spaces/space-setup.test.js +8 -2
- package/server/lib/terminal/DOCUMENTATION.md +1 -0
- package/server/lib/terminal/runtime.js +6 -1
- package/server/lib/terminal/runtime.test.js +19 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +8 -8
- package/dist/assets/FilesView-CN34wm_N.js +0 -17
- package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
- package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
- package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
- package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
- package/dist/assets/SettingsWindow-CofS020b.js +0 -1
- package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
- package/dist/assets/de-DlgBHUAI.js +0 -10
- package/dist/assets/es-BC8G41U8.js +0 -16
- package/dist/assets/fr-I0z3vVjy.js +0 -14
- package/dist/assets/index-CgR5rJq_.js +0 -41
- package/dist/assets/index-adyy_sEk.css +0 -1
- package/dist/assets/ja-BIElEsY8.js +0 -16
- package/dist/assets/ko-DRnnHetA.js +0 -16
- package/dist/assets/main-DVX34beR.js +0 -886
- package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
- package/dist/assets/mobile-BrlBrNfZ.js +0 -2
- package/dist/assets/nl-DzUV-kwp.js +0 -16
- package/dist/assets/pl-Bb-cb7k7.js +0 -16
- package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
- package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
- package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
- package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
- package/dist/assets/tr-DXEDSoYO.js +0 -7
- package/dist/assets/uk-C8hN--q_.js +0 -16
- package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
- package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
- package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
- package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
- package/server/lib/opencode/credential-db.js +0 -144
- package/server/lib/opencode/credential-db.test.js +0 -104
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* READ-ONLY view of the credentials OpenCode 2.x keeps in its SQLite database.
|
|
3
|
-
*
|
|
4
|
-
* OpenCode 2.x imports the legacy `auth.json` once and from then on stores
|
|
5
|
-
* every credential in `<data>/opencode.db`, table `credential`, as plain JSON.
|
|
6
|
-
* There is no HTTP route that hands a key back, so the quota providers and
|
|
7
|
-
* voice keys would only ever see credentials that predate the upgrade. This
|
|
8
|
-
* module reads the table directly and projects each row into the legacy
|
|
9
|
-
* `auth.json` entry shape the rest of the server already understands, so a
|
|
10
|
-
* key added through OpenCode after the upgrade works like one that was
|
|
11
|
-
* imported. The database is opened read-only and never written.
|
|
12
|
-
*
|
|
13
|
-
* The table layout is OpenCode's private schema (verified against v2.0.x
|
|
14
|
-
* `packages/core/src/credential/sql.ts`); a schema change makes this reader
|
|
15
|
-
* return null and the caller falls back to `auth.json`.
|
|
16
|
-
*
|
|
17
|
-
* `node:sqlite` ships with Node 22.13+, `bun:sqlite` with Bun; a runtime
|
|
18
|
-
* without either also falls back to the file, silently.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { createRequire } from 'node:module';
|
|
22
|
-
|
|
23
|
-
const DB_FILE_NAME = 'opencode.db';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A minimal read-only connection: `all(sql)` and `close()`. Node provides it
|
|
27
|
-
* through `node:sqlite`, Bun through `bun:sqlite`; both are built in. Neither
|
|
28
|
-
* being available yields null and the caller falls back to `auth.json`.
|
|
29
|
-
*/
|
|
30
|
-
let openConnection;
|
|
31
|
-
const loadSqlite = () => {
|
|
32
|
-
if (openConnection !== undefined) return openConnection;
|
|
33
|
-
const require = createRequire(import.meta.url);
|
|
34
|
-
openConnection = null;
|
|
35
|
-
try {
|
|
36
|
-
const node = typeof process.getBuiltinModule === 'function' ? process.getBuiltinModule('node:sqlite') : null;
|
|
37
|
-
const { DatabaseSync } = node ?? require('node:sqlite');
|
|
38
|
-
if (typeof DatabaseSync === 'function') {
|
|
39
|
-
openConnection = (dbPath) => {
|
|
40
|
-
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
41
|
-
return { all: (sql) => db.prepare(sql).all(), close: () => db.close() };
|
|
42
|
-
};
|
|
43
|
-
return openConnection;
|
|
44
|
-
}
|
|
45
|
-
} catch {
|
|
46
|
-
// Not Node, or a Node without node:sqlite; try Bun next.
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
const { Database } = require('bun:sqlite');
|
|
50
|
-
if (typeof Database === 'function') {
|
|
51
|
-
openConnection = (dbPath) => {
|
|
52
|
-
const db = new Database(dbPath, { readonly: true });
|
|
53
|
-
return { all: (sql) => db.query(sql).all(), close: () => db.close() };
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
// No sqlite runtime at all.
|
|
58
|
-
}
|
|
59
|
-
return openConnection;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Where OpenCode keeps its database: `OPENCODE_DB` when set (absolute or
|
|
64
|
-
* relative to the data dir), else `opencode.db` in the data dir.
|
|
65
|
-
* @param {{ dataDir: string, env?: NodeJS.ProcessEnv, path: typeof import('node:path') }} options
|
|
66
|
-
*/
|
|
67
|
-
export const resolveCredentialDbPath = ({ dataDir, env = process.env, path }) => {
|
|
68
|
-
const configured = (env.OPENCODE_DB ?? '').trim();
|
|
69
|
-
if (configured && configured !== ':memory:') return path.resolve(dataDir, configured);
|
|
70
|
-
return path.join(dataDir, DB_FILE_NAME);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Project one stored `credential.value` into the legacy `auth.json` entry
|
|
75
|
-
* shape (`{ type: 'api', key }` / `{ type: 'oauth', access, refresh, expires }`).
|
|
76
|
-
* Returns null for a value this reader does not understand.
|
|
77
|
-
*/
|
|
78
|
-
export const projectCredentialValue = (raw) => {
|
|
79
|
-
let value;
|
|
80
|
-
try {
|
|
81
|
-
value = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
82
|
-
} catch {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
if (!value || typeof value !== 'object') return null;
|
|
86
|
-
if (value.type === 'key' && typeof value.key === 'string') {
|
|
87
|
-
const entry = { type: 'api', key: value.key };
|
|
88
|
-
if (value.metadata && typeof value.metadata === 'object') entry.metadata = value.metadata;
|
|
89
|
-
return entry;
|
|
90
|
-
}
|
|
91
|
-
if (value.type === 'oauth' && typeof value.access === 'string' && typeof value.refresh === 'string') {
|
|
92
|
-
const entry = { type: 'oauth', access: value.access, refresh: value.refresh, expires: Number(value.expires) || 0 };
|
|
93
|
-
const metadata = value.metadata && typeof value.metadata === 'object' ? value.metadata : {};
|
|
94
|
-
if (typeof metadata.accountID === 'string') entry.accountId = metadata.accountID;
|
|
95
|
-
if (typeof metadata.enterpriseUrl === 'string') entry.enterpriseUrl = metadata.enterpriseUrl;
|
|
96
|
-
return entry;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Read every integration's selected credential from the database.
|
|
103
|
-
*
|
|
104
|
-
* An integration may hold several credentials; the one OpenCode uses is the
|
|
105
|
-
* `active` row, else the most recently updated one, which mirrors how
|
|
106
|
-
* OpenCode itself picks. The result is keyed by integration id, which for
|
|
107
|
-
* providers is the provider id (`openai`, `github-copilot`, ...).
|
|
108
|
-
*
|
|
109
|
-
* @returns {Record<string, object> | null} null when the database or the
|
|
110
|
-
* sqlite runtime is unavailable, so the caller can tell "no credentials"
|
|
111
|
-
* from "could not look".
|
|
112
|
-
*/
|
|
113
|
-
export const readCredentialsFromDb = ({ dbPath, fs }) => {
|
|
114
|
-
const open = loadSqlite();
|
|
115
|
-
if (!open) return null;
|
|
116
|
-
if (!fs.existsSync(dbPath)) return null;
|
|
117
|
-
|
|
118
|
-
let db;
|
|
119
|
-
try {
|
|
120
|
-
db = open(dbPath);
|
|
121
|
-
const rows = db.all(
|
|
122
|
-
'SELECT integration_id, value, active, time_updated FROM credential ' +
|
|
123
|
-
'WHERE integration_id IS NOT NULL ' +
|
|
124
|
-
'ORDER BY integration_id, active DESC, time_updated DESC',
|
|
125
|
-
);
|
|
126
|
-
const result = {};
|
|
127
|
-
for (const row of rows) {
|
|
128
|
-
const id = typeof row.integration_id === 'string' ? row.integration_id : '';
|
|
129
|
-
if (!id || id in result) continue;
|
|
130
|
-
const entry = projectCredentialValue(row.value);
|
|
131
|
-
if (entry) result[id] = entry;
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.warn('Could not read OpenCode credentials database:', error instanceof Error ? error.message : error);
|
|
136
|
-
return null;
|
|
137
|
-
} finally {
|
|
138
|
-
try {
|
|
139
|
-
db?.close();
|
|
140
|
-
} catch {
|
|
141
|
-
// The connection is read-only; a failed close changes nothing.
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
|
|
7
|
-
import { projectCredentialValue, readCredentialsFromDb, resolveCredentialDbPath } from './credential-db.js';
|
|
8
|
-
|
|
9
|
-
const sqlite = (() => {
|
|
10
|
-
try {
|
|
11
|
-
return createRequire(import.meta.url)('node:sqlite');
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
})();
|
|
16
|
-
|
|
17
|
-
const seed = (dbPath, rows) => {
|
|
18
|
-
const db = new sqlite.DatabaseSync(dbPath);
|
|
19
|
-
db.exec(
|
|
20
|
-
'CREATE TABLE credential (id TEXT PRIMARY KEY, integration_id TEXT, label TEXT NOT NULL, value TEXT NOT NULL, ' +
|
|
21
|
-
'connector_id TEXT, method_id TEXT, active INTEGER, time_created INTEGER NOT NULL, time_updated INTEGER NOT NULL)',
|
|
22
|
-
);
|
|
23
|
-
const insert = db.prepare(
|
|
24
|
-
'INSERT INTO credential (id, integration_id, label, value, active, time_created, time_updated) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
|
25
|
-
);
|
|
26
|
-
for (const row of rows) {
|
|
27
|
-
insert.run(row.id, row.integration, row.label ?? 'default', JSON.stringify(row.value), row.active ?? null, row.time ?? 1, row.time ?? 1);
|
|
28
|
-
}
|
|
29
|
-
db.close();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
describe('projectCredentialValue', () => {
|
|
33
|
-
it('maps a stored key to the legacy api entry', () => {
|
|
34
|
-
expect(projectCredentialValue({ type: 'key', key: 'sk-1', metadata: { region: 'eu' } })).toEqual({
|
|
35
|
-
type: 'api',
|
|
36
|
-
key: 'sk-1',
|
|
37
|
-
metadata: { region: 'eu' },
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('maps a stored oauth credential, including the account and enterprise fields', () => {
|
|
42
|
-
expect(
|
|
43
|
-
projectCredentialValue({
|
|
44
|
-
type: 'oauth',
|
|
45
|
-
methodID: 'chatgpt-browser',
|
|
46
|
-
access: 'a',
|
|
47
|
-
refresh: 'r',
|
|
48
|
-
expires: 42,
|
|
49
|
-
metadata: { accountID: 'acc', enterpriseUrl: 'https://ghe.example' },
|
|
50
|
-
}),
|
|
51
|
-
).toEqual({ type: 'oauth', access: 'a', refresh: 'r', expires: 42, accountId: 'acc', enterpriseUrl: 'https://ghe.example' });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('rejects shapes it does not understand instead of guessing', () => {
|
|
55
|
-
expect(projectCredentialValue('not json')).toBeNull();
|
|
56
|
-
expect(projectCredentialValue({ type: 'oauth', access: 'a' })).toBeNull();
|
|
57
|
-
expect(projectCredentialValue({ type: 'something-new', key: 'x' })).toBeNull();
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('resolveCredentialDbPath', () => {
|
|
62
|
-
it('defaults to opencode.db in the data dir and honours OPENCODE_DB', () => {
|
|
63
|
-
expect(resolveCredentialDbPath({ dataDir: '/data', env: {}, path })).toBe(path.join('/data', 'opencode.db'));
|
|
64
|
-
expect(resolveCredentialDbPath({ dataDir: '/data', env: { OPENCODE_DB: 'other.db' }, path })).toBe(path.resolve('/data', 'other.db'));
|
|
65
|
-
expect(resolveCredentialDbPath({ dataDir: '/data', env: { OPENCODE_DB: '/abs/x.db' }, path })).toBe(path.resolve('/abs/x.db'));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe.skipIf(!sqlite)('readCredentialsFromDb', () => {
|
|
70
|
-
let dir;
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-cred-'));
|
|
73
|
-
});
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('returns null when there is no database, so the caller can fall back', () => {
|
|
79
|
-
expect(readCredentialsFromDb({ dbPath: path.join(dir, 'opencode.db'), fs })).toBeNull();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('picks the active credential per integration, else the newest one', () => {
|
|
83
|
-
const dbPath = path.join(dir, 'opencode.db');
|
|
84
|
-
seed(dbPath, [
|
|
85
|
-
{ id: 'c1', integration: 'openai', value: { type: 'oauth', access: 'old', refresh: 'r1', expires: 1 }, active: 0, time: 5 },
|
|
86
|
-
{ id: 'c2', integration: 'openai', value: { type: 'oauth', access: 'new', refresh: 'r2', expires: 2 }, active: 1, time: 2 },
|
|
87
|
-
{ id: 'c3', integration: 'opencode-go', value: { type: 'key', key: 'go-old' }, time: 1 },
|
|
88
|
-
{ id: 'c4', integration: 'opencode-go', value: { type: 'key', key: 'go-new' }, time: 9 },
|
|
89
|
-
{ id: 'c5', integration: 'weird', value: { type: 'future' }, time: 1 },
|
|
90
|
-
]);
|
|
91
|
-
expect(readCredentialsFromDb({ dbPath, fs })).toEqual({
|
|
92
|
-
openai: { type: 'oauth', access: 'new', refresh: 'r2', expires: 2 },
|
|
93
|
-
'opencode-go': { type: 'api', key: 'go-new' },
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('returns null rather than throwing when the schema is not what it expects', () => {
|
|
98
|
-
const dbPath = path.join(dir, 'opencode.db');
|
|
99
|
-
const db = new sqlite.DatabaseSync(dbPath);
|
|
100
|
-
db.exec('CREATE TABLE credential (id TEXT PRIMARY KEY)');
|
|
101
|
-
db.close();
|
|
102
|
-
expect(readCredentialsFromDb({ dbPath, fs })).toBeNull();
|
|
103
|
-
});
|
|
104
|
-
});
|