@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,81 +1,145 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* READ-ONLY view of OpenCode's provider credentials
|
|
2
|
+
* READ-ONLY view of OpenCode's provider credentials, shared by the web server
|
|
3
|
+
* and the VS Code extension host.
|
|
3
4
|
*
|
|
4
|
-
* OpenCode 2.x
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
5
|
+
* OpenCode 2.x owns every credential. Since 2.0.20 it hands them back over
|
|
6
|
+
* `GET /api/credential`, secrets included, so the quota providers, voice keys
|
|
7
|
+
* and routing read what the running OpenCode actually uses. Each call asks
|
|
8
|
+
* OpenCode; concurrent callers share one request. A failed read throws rather
|
|
9
|
+
* than answering `{}`: "OpenCode is unreachable" must not look like "the user
|
|
10
|
+
* has no keys".
|
|
11
|
+
*
|
|
12
|
+
* A key OpenCode picks up from an environment variable (`ZAI_API_KEY`, ...)
|
|
13
|
+
* is never stored, and that route does not list it. `GET /api/integration`
|
|
14
|
+
* names the variable a connection came from, but not its value. When
|
|
15
|
+
* OpenChamber launched OpenCode itself it knows the environment it passed, so
|
|
16
|
+
* the source reads the value from there; an external OpenCode runs with an
|
|
17
|
+
* environment of its own, and its variable keys stay unknown. A stored
|
|
18
|
+
* credential wins over a variable, which is the order OpenCode itself uses.
|
|
19
|
+
*
|
|
20
|
+
* The answer keeps the legacy `auth.json` entry shape the consumers were
|
|
21
|
+
* written against: `{ type: 'api', key }` / `{ type: 'oauth', access, refresh,
|
|
22
|
+
* expires, accountId?, enterpriseUrl? }`, keyed by integration id, which for
|
|
23
|
+
* providers is the provider id. Nothing here writes.
|
|
18
24
|
*/
|
|
19
25
|
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import os from 'os';
|
|
23
|
-
import { readCredentialsFromDb, resolveCredentialDbPath } from './credential-db.js';
|
|
26
|
+
import { OpenCode } from '@opencode/client';
|
|
27
|
+
import { z } from 'zod';
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
// Wired once per runtime: `server/index.js` on the web server, the extension
|
|
30
|
+
// entry point in VS Code. Until then every read throws.
|
|
31
|
+
let source = null;
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
/** Wires the reader to a credential source (`{ list }`). Pass `null` to detach. */
|
|
34
|
+
export function configureOpenCodeCredentials(next) {
|
|
35
|
+
source = next ?? null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The value of each variable OpenCode reports as a connection, keyed by
|
|
40
|
+
* integration id, taken from the environment OpenCode was launched with.
|
|
41
|
+
*/
|
|
42
|
+
export const projectEnvironmentKeys = (integrations, environment) => {
|
|
43
|
+
const result = {};
|
|
44
|
+
for (const integration of integrations) {
|
|
45
|
+
for (const connection of integration.connections) {
|
|
46
|
+
if (connection.type !== 'env' || integration.id in result) continue;
|
|
47
|
+
const key = (environment[connection.name] ?? '').trim();
|
|
48
|
+
if (key) result[integration.id] = key;
|
|
37
49
|
}
|
|
38
|
-
return JSON.parse(trimmed);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error('Failed to read auth file:', error);
|
|
41
|
-
throw new Error('Failed to read OpenCode auth configuration');
|
|
42
50
|
}
|
|
43
|
-
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
44
53
|
|
|
45
54
|
/**
|
|
46
|
-
* The
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* it is the sole source left.
|
|
51
|
-
*
|
|
52
|
-
* @param {{ dbPath?: string, authFile?: string, fileSystem?: typeof fs }} [options] test seams; production callers pass nothing.
|
|
55
|
+
* The running OpenCode as a credential source. The URL and auth headers are
|
|
56
|
+
* read on every call because the port and the server password both move
|
|
57
|
+
* across an OpenCode restart. `getLaunchEnvironment` answers the environment
|
|
58
|
+
* a managed OpenCode was started with, or null for an external one.
|
|
53
59
|
*/
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
60
|
+
export const openCodeCredentialSource = ({ buildOpenCodeUrl, getOpenCodeAuthHeaders, getLaunchEnvironment = () => null }) => {
|
|
61
|
+
const client = () => OpenCode.make({
|
|
62
|
+
baseUrl: buildOpenCodeUrl('', '').replace(/\/+$/, ''),
|
|
63
|
+
headers: { ...getOpenCodeAuthHeaders() },
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
list: () => client().credential.list(),
|
|
67
|
+
listEnvironmentKeys: async () => {
|
|
68
|
+
const environment = getLaunchEnvironment();
|
|
69
|
+
if (!environment) return {};
|
|
70
|
+
const { data } = await client().integration.list();
|
|
71
|
+
return projectEnvironmentKeys(data, environment);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
};
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
const auth = readAuthFile();
|
|
67
|
-
return auth[providerId] || null;
|
|
68
|
-
}
|
|
76
|
+
const metadataString = z.string();
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
78
|
+
/** One stored credential value → legacy `auth.json` entry. */
|
|
79
|
+
const projectCredentialValue = (value) => {
|
|
80
|
+
if (value.type === 'key') {
|
|
81
|
+
return value.metadata ? { type: 'api', key: value.key, metadata: value.metadata } : { type: 'api', key: value.key };
|
|
82
|
+
}
|
|
83
|
+
const entry = { type: 'oauth', access: value.access, refresh: value.refresh, expires: value.expires };
|
|
84
|
+
const accountId = metadataString.safeParse(value.metadata?.accountID).data;
|
|
85
|
+
const enterpriseUrl = metadataString.safeParse(value.metadata?.enterpriseUrl).data;
|
|
86
|
+
if (accountId !== undefined) entry.accountId = accountId;
|
|
87
|
+
if (enterpriseUrl !== undefined) entry.enterpriseUrl = enterpriseUrl;
|
|
88
|
+
return entry;
|
|
89
|
+
};
|
|
74
90
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
/** Each integration's selected credential; OpenCode marks exactly one `active` per integration. */
|
|
92
|
+
export const projectCredentialEntries = (entries) => {
|
|
93
|
+
const result = {};
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
if (entry.active) result[entry.integrationID] = projectCredentialValue(entry.value);
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const readStored = async (current) => projectCredentialEntries(await current.list());
|
|
101
|
+
|
|
102
|
+
const readWithEnvironment = async (current) => {
|
|
103
|
+
const [stored, environmentKeys] = await Promise.all([
|
|
104
|
+
readStored(current),
|
|
105
|
+
current.listEnvironmentKeys ? current.listEnvironmentKeys() : {},
|
|
106
|
+
]);
|
|
107
|
+
const result = {};
|
|
108
|
+
for (const [integrationID, key] of Object.entries(environmentKeys)) result[integrationID] = { type: 'api', key };
|
|
109
|
+
return { ...result, ...stored };
|
|
81
110
|
};
|
|
111
|
+
|
|
112
|
+
const coalesce = () => {
|
|
113
|
+
let pending = null;
|
|
114
|
+
return (read) => {
|
|
115
|
+
if (!pending) {
|
|
116
|
+
const current = source;
|
|
117
|
+
pending = (current ? read(current) : Promise.reject(new Error('OpenCode is not connected yet')))
|
|
118
|
+
.finally(() => {
|
|
119
|
+
pending = null;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return pending;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const sharedRead = coalesce();
|
|
127
|
+
const sharedStoredRead = coalesce();
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The keys the running OpenCode uses, keyed by provider id: stored
|
|
131
|
+
* credentials, plus variable keys when OpenChamber launched OpenCode.
|
|
132
|
+
* Throws when OpenCode cannot be asked.
|
|
133
|
+
*/
|
|
134
|
+
export function readOpenCodeCredentials() {
|
|
135
|
+
return sharedRead(readWithEnvironment);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The credential stored for one provider, or null. Variables do not count:
|
|
140
|
+
* callers ask whether a login exists in OpenCode's own store.
|
|
141
|
+
*/
|
|
142
|
+
export async function getProviderAuth(providerId) {
|
|
143
|
+
const credentials = await sharedStoredRead(readStored);
|
|
144
|
+
return credentials[providerId] || null;
|
|
145
|
+
}
|
|
@@ -1,92 +1,136 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it
|
|
2
|
-
import
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import http from 'node:http';
|
|
6
3
|
|
|
7
|
-
import {
|
|
4
|
+
import { configureOpenCodeCredentials, getProviderAuth, openCodeCredentialSource, projectCredentialEntries, projectEnvironmentKeys, readOpenCodeCredentials } from './auth.js';
|
|
8
5
|
|
|
9
|
-
const
|
|
10
|
-
try {
|
|
11
|
-
return createRequire(import.meta.url)('node:sqlite');
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
})();
|
|
6
|
+
const entry = (integrationID, active, value) => ({ id: `cred_${integrationID}_${active}`, integrationID, label: 'default', active, value });
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
describe('projectCredentialEntries', () => {
|
|
9
|
+
it('keeps each integration’s active credential in the legacy entry shape', () => {
|
|
10
|
+
const projected = projectCredentialEntries([
|
|
11
|
+
entry('zai-coding-plan', false, { type: 'key', key: 'old' }),
|
|
12
|
+
entry('zai-coding-plan', true, { type: 'key', key: 'zai-key' }),
|
|
13
|
+
entry('openai', true, {
|
|
14
|
+
type: 'oauth',
|
|
15
|
+
methodID: 'chatgpt-browser',
|
|
16
|
+
access: 'at',
|
|
17
|
+
refresh: 'rt',
|
|
18
|
+
expires: 42,
|
|
19
|
+
metadata: { accountID: 'acc_1' },
|
|
20
|
+
}),
|
|
21
|
+
entry('github-copilot', true, {
|
|
22
|
+
type: 'oauth',
|
|
23
|
+
methodID: 'device',
|
|
24
|
+
access: 'gh',
|
|
25
|
+
refresh: 'gh-r',
|
|
26
|
+
expires: 0,
|
|
27
|
+
metadata: { enterpriseUrl: 'https://ghe.example' },
|
|
28
|
+
}),
|
|
29
|
+
entry('custom', true, { type: 'key', key: 'k', metadata: { region: 'eu' } }),
|
|
30
|
+
]);
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'INSERT INTO credential (id, integration_id, label, value, active, time_created, time_updated) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
|
29
|
-
);
|
|
30
|
-
for (const [index, row] of rows.entries()) {
|
|
31
|
-
insert.run(`c${index}`, row.integration, 'default', JSON.stringify(row.value), 1, 1, 1);
|
|
32
|
-
}
|
|
33
|
-
db.close();
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const read = () => readAuthFile({ dbPath, authFile, fileSystem: fs });
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'oc-auth-'));
|
|
40
|
-
dbPath = path.join(dir, 'opencode.db');
|
|
41
|
-
authFile = path.join(dir, 'auth.json');
|
|
42
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
43
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
32
|
+
expect(projected).toEqual({
|
|
33
|
+
'zai-coding-plan': { type: 'api', key: 'zai-key' },
|
|
34
|
+
openai: { type: 'oauth', access: 'at', refresh: 'rt', expires: 42, accountId: 'acc_1' },
|
|
35
|
+
'github-copilot': { type: 'oauth', access: 'gh', refresh: 'gh-r', expires: 0, enterpriseUrl: 'https://ghe.example' },
|
|
36
|
+
custom: { type: 'api', key: 'k', metadata: { region: 'eu' } },
|
|
37
|
+
});
|
|
38
|
+
});
|
|
44
39
|
});
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
describe('projectEnvironmentKeys', () => {
|
|
42
|
+
it('takes each variable OpenCode reports from the launch environment', () => {
|
|
43
|
+
const integrations = [
|
|
44
|
+
{ id: 'zai-coding-plan', connections: [{ type: 'env', name: 'ZHIPU_API_KEY' }] },
|
|
45
|
+
{ id: 'deepseek', connections: [{ type: 'credential', id: 'c', label: 'default', method: 'key' }] },
|
|
46
|
+
{ id: 'openrouter', connections: [{ type: 'env', name: 'OPENROUTER_API_KEY' }] },
|
|
47
|
+
{ id: 'blank', connections: [{ type: 'env', name: 'BLANK_KEY' }] },
|
|
48
|
+
];
|
|
49
|
+
expect(projectEnvironmentKeys(integrations, { ZHIPU_API_KEY: ' zk ', BLANK_KEY: ' ' })).toEqual({ 'zai-coding-plan': 'zk' });
|
|
50
|
+
});
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
describe
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
describe('readOpenCodeCredentials', () => {
|
|
54
|
+
let server;
|
|
55
|
+
let requests;
|
|
56
|
+
let respond;
|
|
57
|
+
let integrations;
|
|
58
|
+
let launchEnvironment;
|
|
59
|
+
|
|
60
|
+
beforeEach(async () => {
|
|
61
|
+
requests = [];
|
|
62
|
+
integrations = [];
|
|
63
|
+
launchEnvironment = null;
|
|
64
|
+
respond = (res) => {
|
|
65
|
+
res.setHeader('content-type', 'application/json');
|
|
66
|
+
res.end(JSON.stringify({ data: [entry('deepseek', true, { type: 'key', key: 'ds' })] }));
|
|
67
|
+
};
|
|
68
|
+
server = http.createServer((req, res) => {
|
|
69
|
+
requests.push({ url: req.url, authorization: req.headers.authorization });
|
|
70
|
+
if (req.url.startsWith('/api/integration')) {
|
|
71
|
+
res.setHeader('content-type', 'application/json');
|
|
72
|
+
res.end(JSON.stringify({ data: integrations }));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
respond(res);
|
|
76
|
+
});
|
|
77
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
78
|
+
const { port } = server.address();
|
|
79
|
+
configureOpenCodeCredentials(openCodeCredentialSource({
|
|
80
|
+
buildOpenCodeUrl: (path) => `http://127.0.0.1:${port}${path}`,
|
|
81
|
+
getOpenCodeAuthHeaders: () => ({ Authorization: 'Basic test' }),
|
|
82
|
+
getLaunchEnvironment: () => launchEnvironment,
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(async () => {
|
|
87
|
+
configureOpenCodeCredentials(null);
|
|
88
|
+
await new Promise((resolve) => server.close(resolve));
|
|
57
89
|
});
|
|
58
90
|
|
|
59
|
-
it('
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
expect(
|
|
91
|
+
it('asks the running OpenCode with its auth headers', async () => {
|
|
92
|
+
await expect(readOpenCodeCredentials()).resolves.toEqual({ deepseek: { type: 'api', key: 'ds' } });
|
|
93
|
+
await expect(getProviderAuth('deepseek')).resolves.toEqual({ type: 'api', key: 'ds' });
|
|
94
|
+
await expect(getProviderAuth('openai')).resolves.toBeNull();
|
|
95
|
+
expect(requests[0]).toEqual({ url: '/api/credential', authorization: 'Basic test' });
|
|
63
96
|
});
|
|
64
97
|
|
|
65
|
-
it('
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
it('adds variable keys of a managed OpenCode, with stored credentials winning', async () => {
|
|
99
|
+
integrations = [
|
|
100
|
+
{ id: 'deepseek', connections: [{ type: 'env', name: 'DEEPSEEK_API_KEY' }] },
|
|
101
|
+
{ id: 'zai-coding-plan', connections: [{ type: 'env', name: 'ZHIPU_API_KEY' }] },
|
|
102
|
+
];
|
|
103
|
+
launchEnvironment = { DEEPSEEK_API_KEY: 'ds-env', ZHIPU_API_KEY: 'zk-env' };
|
|
104
|
+
await expect(readOpenCodeCredentials()).resolves.toEqual({
|
|
105
|
+
deepseek: { type: 'api', key: 'ds' },
|
|
106
|
+
'zai-coding-plan': { type: 'api', key: 'zk-env' },
|
|
107
|
+
});
|
|
108
|
+
// A variable is not a stored login.
|
|
109
|
+
await expect(getProviderAuth('zai-coding-plan')).resolves.toBeNull();
|
|
69
110
|
});
|
|
70
111
|
|
|
71
|
-
it('
|
|
72
|
-
|
|
73
|
-
expect(
|
|
112
|
+
it('leaves variable keys out for an external OpenCode', async () => {
|
|
113
|
+
integrations = [{ id: 'zai-coding-plan', connections: [{ type: 'env', name: 'ZHIPU_API_KEY' }] }];
|
|
114
|
+
await expect(readOpenCodeCredentials()).resolves.toEqual({ deepseek: { type: 'api', key: 'ds' } });
|
|
115
|
+
expect(requests.map((request) => request.url)).toEqual(['/api/credential']);
|
|
74
116
|
});
|
|
75
117
|
|
|
76
|
-
it('
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
fs.writeFileSync(authFile, JSON.stringify({ openai: { type: 'api', key: 'legacy' } }));
|
|
81
|
-
expect(read()).toEqual({ openai: { type: 'api', key: 'legacy' } });
|
|
118
|
+
it('shares one request between concurrent callers', async () => {
|
|
119
|
+
const [first, second] = await Promise.all([readOpenCodeCredentials(), readOpenCodeCredentials()]);
|
|
120
|
+
expect(first).toBe(second);
|
|
121
|
+
expect(requests).toHaveLength(1);
|
|
82
122
|
});
|
|
83
123
|
|
|
84
|
-
it('
|
|
85
|
-
|
|
86
|
-
|
|
124
|
+
it('throws instead of answering empty when OpenCode fails', async () => {
|
|
125
|
+
respond = (res) => {
|
|
126
|
+
res.statusCode = 500;
|
|
127
|
+
res.end('{}');
|
|
128
|
+
};
|
|
129
|
+
await expect(readOpenCodeCredentials()).rejects.toThrow();
|
|
87
130
|
});
|
|
88
131
|
|
|
89
|
-
it('
|
|
90
|
-
|
|
132
|
+
it('throws before OpenCode is wired', async () => {
|
|
133
|
+
configureOpenCodeCredentials(null);
|
|
134
|
+
await expect(readOpenCodeCredentials()).rejects.toThrow('OpenCode is not connected yet');
|
|
91
135
|
});
|
|
92
136
|
});
|
|
@@ -8,10 +8,11 @@ const infoSchema = z.object({ version: versionSchema });
|
|
|
8
8
|
const legacyHealthSchema = z.object({ version: versionSchema, healthy: z.boolean() });
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Oldest OpenCode OpenChamber runs against. 2.0.
|
|
12
|
-
*
|
|
11
|
+
* Oldest OpenCode OpenChamber runs against. 2.0.20 added `GET /api/credential`,
|
|
12
|
+
* the only way to read the provider keys quota lookups, voice and routing use
|
|
13
|
+
* (2.0.15 before it added `PATCH /api/session` metadata).
|
|
13
14
|
*/
|
|
14
|
-
const MINIMUM_OPENCODE_VERSION = '2.0.
|
|
15
|
+
const MINIMUM_OPENCODE_VERSION = '2.0.20';
|
|
15
16
|
|
|
16
17
|
const releaseParts = (version) => version.split(/[-+]/, 1)[0].split('.').map(Number);
|
|
17
18
|
|
|
@@ -6,18 +6,18 @@ const cli = (output, code = 0) => ({ binary: process.execPath, args: ['-e', `con
|
|
|
6
6
|
describe('OpenCode compatibility', () => {
|
|
7
7
|
it('recognizes both CLI version formats before launching a server', async () => {
|
|
8
8
|
expect(await readOpenCodeCliVersion(cli('1.18.32'))).toBe('1.18.32');
|
|
9
|
-
expect(await requireOpenCodeV2(cli('opencode v2.0.
|
|
10
|
-
await expect(requireOpenCodeV2(cli('2.0.
|
|
9
|
+
expect(await requireOpenCodeV2(cli('opencode v2.0.20'))).toBe('2.0.20');
|
|
10
|
+
await expect(requireOpenCodeV2(cli('2.0.19'))).rejects.toBeInstanceOf(UnsupportedOpenCodeVersionError);
|
|
11
11
|
await expect(requireOpenCodeV2(cli('1.18.32'))).rejects.toBeInstanceOf(UnsupportedOpenCodeVersionError);
|
|
12
|
-
await expect(readOpenCodeCliVersion(cli('2.0.
|
|
13
|
-
await expect(readOpenCodeCliVersion(cli('error, requires 2.0.
|
|
12
|
+
await expect(readOpenCodeCliVersion(cli('2.0.19', 1))).rejects.toThrow();
|
|
13
|
+
await expect(readOpenCodeCliVersion(cli('error, requires 2.0.19'))).rejects.toThrow();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('does not accept HTTP 200 HTML or malformed JSON as readiness', async () => {
|
|
17
17
|
expect(await readOpenCodeInfo(new Response('<html>OpenCode</html>'))).toBeNull();
|
|
18
18
|
expect(await readOpenCodeInfo(Response.json({ healthy: true }))).toBeNull();
|
|
19
19
|
expect(await readOpenCodeInfo(Response.json({ version: 'not a version' }))).toBeNull();
|
|
20
|
-
expect(await readOpenCodeInfo(Response.json({ version: '2.0.
|
|
20
|
+
expect(await readOpenCodeInfo(Response.json({ version: '2.0.19' }))).toEqual({ version: '2.0.19' });
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it('identifies external v1 through its legacy health contract', async () => {
|
|
@@ -48,22 +48,22 @@ describe('OpenCode compatibility', () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('accepts 2.x from the minimum on and nothing older or of another major', () => {
|
|
51
|
-
for (const version of ['2.0.
|
|
51
|
+
for (const version of ['2.0.20', '2.0.21', '2.1.0', '2.0.20-beta.1']) {
|
|
52
52
|
expect(describeOpenCodeCompatibility(version, 'managed', true).state).toBe('compatible');
|
|
53
53
|
}
|
|
54
|
-
for (const version of ['1.18.32', '2.0.
|
|
54
|
+
for (const version of ['1.18.32', '2.0.19', '2.0.9', '3.0.0']) {
|
|
55
55
|
expect(describeOpenCodeCompatibility(version, 'managed', true).state).toBe('incompatible');
|
|
56
56
|
}
|
|
57
|
-
expect(describeOpenCodeCompatibility('2.0.
|
|
57
|
+
expect(describeOpenCodeCompatibility('2.0.19', 'managed', true).minimumVersion).toBe('2.0.20');
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('only offers installation for a known managed CLI older than the minimum', () => {
|
|
61
61
|
expect(describeOpenCodeCompatibility('1.18.32', 'managed', true)).toMatchObject({ state: 'incompatible', canInstall: true });
|
|
62
|
-
expect(describeOpenCodeCompatibility('2.0.
|
|
62
|
+
expect(describeOpenCodeCompatibility('2.0.19', 'managed', true)).toMatchObject({ state: 'incompatible', canInstall: true });
|
|
63
63
|
for (const installation of ['external', 'bundled']) {
|
|
64
64
|
expect(describeOpenCodeCompatibility('1.18.32', installation, true).canInstall).toBe(false);
|
|
65
65
|
}
|
|
66
|
-
for (const version of [null, '2.0.
|
|
66
|
+
for (const version of [null, '2.0.20', '3.0.0']) {
|
|
67
67
|
expect(describeOpenCodeCompatibility(version, 'managed', true).canInstall).toBe(false);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
@@ -16,6 +16,7 @@ import { registerProjectContextRoutes } from '../project-context/routes.js';
|
|
|
16
16
|
import { registerProjectSetupRoutes } from '../projects/routes.js';
|
|
17
17
|
import { registerAgentMemoryRoutes } from '../agent-memory/routes.js';
|
|
18
18
|
import { registerSessionKnowledgeRoutes } from '../session-knowledge/routes.js';
|
|
19
|
+
import { registerMessageSearchRoutes } from '../message-search/routes.js';
|
|
19
20
|
import { registerPermissionAutoAcceptRoutes } from '../permission-auto-accept/runtime.js';
|
|
20
21
|
import { registerMessageQueueRoutes } from '../message-queue/runtime.js';
|
|
21
22
|
import { registerRoutingPromptRewrite, registerRoutingRoutes } from '../routing/routes.js';
|
|
@@ -93,6 +94,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
93
94
|
|
|
94
95
|
const registerRoutes = async (app, routeDependencies) => {
|
|
95
96
|
const {
|
|
97
|
+
messageSearchRuntime,
|
|
96
98
|
crypto,
|
|
97
99
|
fs,
|
|
98
100
|
os,
|
|
@@ -360,6 +362,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
360
362
|
registerProjectSetupRoutes(app, { projectConfigRuntime });
|
|
361
363
|
registerAgentMemoryRoutes(app, { agentMemoryRuntime, isAgentMemoryEnabled });
|
|
362
364
|
registerSessionKnowledgeRoutes(app, { sessionKnowledgeRuntime });
|
|
365
|
+
registerMessageSearchRoutes(app, { messageSearchRuntime });
|
|
363
366
|
|
|
364
367
|
registerSessionFoldersRoutes(app, {
|
|
365
368
|
fsPromises,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readOpenCodeInfo, readExternalOpenCodeVersion, isSupportedOpenCodeVersion, requireOpenCodeV2, UnsupportedOpenCodeVersionError } from './compatibility.js';
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import net from 'node:net';
|
|
4
|
-
import { stripAppImageArgv0Leak } from '../inherited-env.js';
|
|
4
|
+
import { stripAppImageArgv0Leak, stripAppImageLauncherEnv } from '../inherited-env.js';
|
|
5
5
|
import { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } from './managed-process-registry.js';
|
|
6
6
|
import { applyProviderEnvAliases } from './provider-env-aliases.js';
|
|
7
7
|
import { recordStartupPerformance } from './startup-performance.js';
|
|
@@ -147,6 +147,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
147
147
|
} = deps;
|
|
148
148
|
|
|
149
149
|
let managedPreflight = null;
|
|
150
|
+
// The environment the managed OpenCode was launched with. Keys OpenCode
|
|
151
|
+
// takes from environment variables are never stored in it, so this is the
|
|
152
|
+
// only place their values can be read back (see auth.js).
|
|
153
|
+
let managedProcessEnv = null;
|
|
150
154
|
|
|
151
155
|
const killProcessOnPortWin32 = (port) => {
|
|
152
156
|
try {
|
|
@@ -761,6 +765,19 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
761
765
|
console.warn('[OpenCode] V1 session migration top-up failed:', error instanceof Error ? error.message : error);
|
|
762
766
|
}
|
|
763
767
|
|
|
768
|
+
const processEnv = stripAppImageLauncherEnv(stripAppImageArgv0Leak(applyProviderEnvAliases({
|
|
769
|
+
...shellEnv,
|
|
770
|
+
...process.env,
|
|
771
|
+
...managedOpenCodeEnv,
|
|
772
|
+
PATH: envPath,
|
|
773
|
+
// OpenCode 2 reads OPENCODE_PASSWORD before the legacy name, so a
|
|
774
|
+
// user's own OPENCODE_PASSWORD would otherwise win and every request
|
|
775
|
+
// we send with openCodePassword would get 401.
|
|
776
|
+
OPENCODE_PASSWORD: openCodePassword,
|
|
777
|
+
OPENCODE_SERVER_PASSWORD: openCodePassword,
|
|
778
|
+
})));
|
|
779
|
+
managedProcessEnv = processEnv;
|
|
780
|
+
|
|
764
781
|
let serverInstance;
|
|
765
782
|
try {
|
|
766
783
|
if (state.isShuttingDown) throw new Error('OpenCode startup cancelled during shutdown');
|
|
@@ -771,17 +788,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
771
788
|
timeout: managedStartupTimeoutMs,
|
|
772
789
|
cwd: state.openCodeWorkingDirectory,
|
|
773
790
|
shellEnvKeysCount: Object.keys(shellEnv).length,
|
|
774
|
-
env:
|
|
775
|
-
...shellEnv,
|
|
776
|
-
...process.env,
|
|
777
|
-
...managedOpenCodeEnv,
|
|
778
|
-
PATH: envPath,
|
|
779
|
-
// OpenCode 2 reads OPENCODE_PASSWORD before the legacy name, so a
|
|
780
|
-
// user's own OPENCODE_PASSWORD would otherwise win and every request
|
|
781
|
-
// we send with openCodePassword would get 401.
|
|
782
|
-
OPENCODE_PASSWORD: openCodePassword,
|
|
783
|
-
OPENCODE_SERVER_PASSWORD: openCodePassword,
|
|
784
|
-
})),
|
|
791
|
+
env: processEnv,
|
|
785
792
|
});
|
|
786
793
|
|
|
787
794
|
if (!serverInstance || !serverInstance.url) {
|
|
@@ -1403,6 +1410,8 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1403
1410
|
};
|
|
1404
1411
|
|
|
1405
1412
|
return {
|
|
1413
|
+
/** The managed OpenCode's launch environment; null for an external OpenCode or before the first launch. */
|
|
1414
|
+
getManagedOpenCodeProcessEnv: () => (state.isExternalOpenCode ? null : managedProcessEnv),
|
|
1406
1415
|
getManagedOpenCodePreflight: async () => {
|
|
1407
1416
|
const preflight = managedPreflight;
|
|
1408
1417
|
if (!preflight || state.isExternalOpenCode || state.isShuttingDown) return false;
|