@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,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
|
+
import { readConfigLayers } from '../../opencode/shared.js';
|
|
3
|
+
import { isRecord, toProviderEntity } from '../../opencode/config-v2.js';
|
|
2
4
|
import {
|
|
3
5
|
getAuthEntry,
|
|
4
6
|
normalizeAuthEntry,
|
|
@@ -6,15 +8,38 @@ import {
|
|
|
6
8
|
toUsageWindow,
|
|
7
9
|
toNumber,
|
|
8
10
|
asObject,
|
|
11
|
+
asNonEmptyString,
|
|
9
12
|
formatMoney
|
|
10
13
|
} from '../utils/index.js';
|
|
11
14
|
|
|
12
15
|
export const providerId = 'openrouter';
|
|
13
16
|
export const providerName = 'OpenRouter';
|
|
14
17
|
export const aliases = ['openrouter'];
|
|
15
|
-
const
|
|
18
|
+
const OPENROUTER_API_BASE = 'https://openrouter.ai/api/v1';
|
|
16
19
|
const PERIOD_SECONDS = { daily: 86400, weekly: 604800, monthly: 30 * 86400 };
|
|
17
20
|
|
|
21
|
+
// The stored key is valid for whichever gateway the configured baseURL points
|
|
22
|
+
// at, so the usage lookup must ride the same base as chat. The endpoint shape
|
|
23
|
+
// stays `<base>/key`; with nothing configured the base is OpenRouter itself.
|
|
24
|
+
// OpenCode takes the address from `settings.baseURL`, legacy `options.baseURL`
|
|
25
|
+
// or legacy `api`, and toProviderEntity folds all three. Each section is read
|
|
26
|
+
// on its own so a v2 entry without an address cannot hide a v1 address that
|
|
27
|
+
// another config file sets.
|
|
28
|
+
const resolveQuotaBase = () => {
|
|
29
|
+
try {
|
|
30
|
+
const { mergedConfig } = readConfigLayers();
|
|
31
|
+
const readBaseURL = (sectionKey) => {
|
|
32
|
+
const section = mergedConfig?.[sectionKey];
|
|
33
|
+
return isRecord(section) ? asNonEmptyString(toProviderEntity(section.openrouter).settings?.baseURL) : null;
|
|
34
|
+
};
|
|
35
|
+
const base = readBaseURL('providers') ?? readBaseURL('provider');
|
|
36
|
+
return base?.replace(/\/+$/, '') || null;
|
|
37
|
+
} catch {
|
|
38
|
+
// A config read failure must not take the default-endpoint lookup down.
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
18
43
|
export const resolveResetAt = (limitReset, nowMs) => {
|
|
19
44
|
const now = new Date(nowMs);
|
|
20
45
|
const y = now.getUTCFullYear();
|
|
@@ -30,14 +55,13 @@ export const resolveResetAt = (limitReset, nowMs) => {
|
|
|
30
55
|
return null;
|
|
31
56
|
};
|
|
32
57
|
|
|
33
|
-
export const isConfigured = () => {
|
|
34
|
-
const auth = readAuthFile();
|
|
58
|
+
export const isConfigured = (auth) => {
|
|
35
59
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
36
60
|
return Boolean(entry?.key || entry?.token);
|
|
37
61
|
};
|
|
38
62
|
|
|
39
63
|
export const fetchQuota = async () => {
|
|
40
|
-
const auth =
|
|
64
|
+
const auth = await readOpenCodeCredentials();
|
|
41
65
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
42
66
|
const apiKey = entry?.key ?? entry?.token;
|
|
43
67
|
|
|
@@ -54,7 +78,7 @@ export const fetchQuota = async () => {
|
|
|
54
78
|
const timeoutSignal = AbortSignal.timeout(15_000);
|
|
55
79
|
|
|
56
80
|
try {
|
|
57
|
-
const response = await fetch(
|
|
81
|
+
const response = await fetch(`${resolveQuotaBase() ?? OPENROUTER_API_BASE}/key`, {
|
|
58
82
|
method: 'GET',
|
|
59
83
|
headers: {
|
|
60
84
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
2
5
|
|
|
3
6
|
vi.mock('../../opencode/auth.js', () => ({
|
|
4
|
-
|
|
7
|
+
readOpenCodeCredentials: async () => ({ openrouter: { key: 'test-token' } }),
|
|
5
8
|
}));
|
|
6
9
|
|
|
10
|
+
// The quota base URL is resolved through the real config-layer reader. Point
|
|
11
|
+
// its global config directory at a path that does not exist so the machine's
|
|
12
|
+
// own opencode.json can never leak into these assertions; the custom layer is
|
|
13
|
+
// resolved from OPENCODE_CONFIG at call time, so each test stubs it fresh.
|
|
14
|
+
vi.hoisted(() => {
|
|
15
|
+
process.env.OPENCODE_CONFIG_DIR = 'openrouter-quota-test-without-config-dir';
|
|
16
|
+
});
|
|
17
|
+
|
|
7
18
|
import { fetchQuota, resolveResetAt } from './openrouter.js';
|
|
8
19
|
|
|
20
|
+
const createdConfigPaths = [];
|
|
21
|
+
|
|
22
|
+
const stubCustomConfigPath = () => {
|
|
23
|
+
const filePath = path.join(os.tmpdir(), `openrouter-quota-config-${process.pid}-${Math.random().toString(16).slice(2)}`);
|
|
24
|
+
vi.stubEnv('OPENCODE_CONFIG', filePath);
|
|
25
|
+
createdConfigPaths.push(filePath);
|
|
26
|
+
return filePath;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const writeCustomConfig = (config) => {
|
|
30
|
+
fs.writeFileSync(stubCustomConfigPath(), JSON.stringify(config));
|
|
31
|
+
};
|
|
32
|
+
|
|
9
33
|
afterEach(() => {
|
|
10
34
|
vi.unstubAllGlobals();
|
|
35
|
+
vi.unstubAllEnvs();
|
|
36
|
+
for (const filePath of createdConfigPaths.splice(0)) {
|
|
37
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
38
|
+
}
|
|
11
39
|
});
|
|
12
40
|
|
|
13
41
|
const mockResponse = (body, init = {}) => ({
|
|
@@ -292,6 +320,99 @@ describe('OpenRouter quota provider', () => {
|
|
|
292
320
|
expect(requestedUrl).not.toContain('/api/v1/credits');
|
|
293
321
|
});
|
|
294
322
|
|
|
323
|
+
it('reads the key endpoint from the configured v2 provider baseURL', async () => {
|
|
324
|
+
writeCustomConfig({
|
|
325
|
+
providers: {
|
|
326
|
+
openrouter: { settings: { baseURL: 'https://gateway.example.com/v1' } },
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
330
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
331
|
+
|
|
332
|
+
await fetchQuota();
|
|
333
|
+
|
|
334
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://gateway.example.com/v1/key');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('reads the key endpoint from the legacy provider options baseURL', async () => {
|
|
338
|
+
writeCustomConfig({
|
|
339
|
+
provider: {
|
|
340
|
+
openrouter: { options: { baseURL: 'https://legacy.example.com/v1' } },
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
344
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
345
|
+
|
|
346
|
+
await fetchQuota();
|
|
347
|
+
|
|
348
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://legacy.example.com/v1/key');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('reads the key endpoint from the legacy provider api field', async () => {
|
|
352
|
+
writeCustomConfig({
|
|
353
|
+
provider: {
|
|
354
|
+
openrouter: { api: 'https://legacy-api.example.com/v1' },
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
358
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
359
|
+
|
|
360
|
+
await fetchQuota();
|
|
361
|
+
|
|
362
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://legacy-api.example.com/v1/key');
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('keeps a legacy baseURL when the v2 entry has no address', async () => {
|
|
366
|
+
writeCustomConfig({
|
|
367
|
+
providers: {
|
|
368
|
+
openrouter: { models: { 'openai/gpt-5': {} } },
|
|
369
|
+
},
|
|
370
|
+
provider: {
|
|
371
|
+
openrouter: { options: { baseURL: 'https://legacy.example.com/v1' } },
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
375
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
376
|
+
|
|
377
|
+
await fetchQuota();
|
|
378
|
+
|
|
379
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://legacy.example.com/v1/key');
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('strips trailing slashes from the configured baseURL', async () => {
|
|
383
|
+
writeCustomConfig({
|
|
384
|
+
providers: {
|
|
385
|
+
openrouter: { settings: { baseURL: 'https://gateway.example.com/v1/' } },
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
389
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
390
|
+
|
|
391
|
+
await fetchQuota();
|
|
392
|
+
|
|
393
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://gateway.example.com/v1/key');
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('keeps the default key endpoint when no baseURL is configured', async () => {
|
|
397
|
+
stubCustomConfigPath();
|
|
398
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
399
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
400
|
+
|
|
401
|
+
await fetchQuota();
|
|
402
|
+
|
|
403
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://openrouter.ai/api/v1/key');
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('keeps the default key endpoint when the config cannot be read', async () => {
|
|
407
|
+
fs.mkdirSync(stubCustomConfigPath());
|
|
408
|
+
const fetchMock = vi.fn().mockResolvedValue(mockResponse(DOCUMENTED_PAYLOAD));
|
|
409
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
410
|
+
|
|
411
|
+
await fetchQuota();
|
|
412
|
+
|
|
413
|
+
expect(fetchMock.mock.calls[0][0]).toBe('https://openrouter.ai/api/v1/key');
|
|
414
|
+
});
|
|
415
|
+
|
|
295
416
|
it('resolves daily reset at the next UTC day across year boundaries', () => {
|
|
296
417
|
expect(resolveResetAt('daily', Date.UTC(2024, 11, 31, 23, 59))).toBe(Date.UTC(2025, 0, 1));
|
|
297
418
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -17,14 +17,13 @@ const aliases = ['wafer', 'wafer-ai', 'wafer_ai', 'wafer.ai'];
|
|
|
17
17
|
const WAFER_QUOTA_URL = 'https://pass.wafer.ai/v1/inference/quota';
|
|
18
18
|
const WAFER_WINDOW_SECONDS = 5 * 3600;
|
|
19
19
|
|
|
20
|
-
export const isConfigured = () => {
|
|
21
|
-
const auth = readAuthFile();
|
|
20
|
+
export const isConfigured = (auth) => {
|
|
22
21
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
23
22
|
return Boolean(entry?.key || entry?.token);
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
export const fetchQuota = async () => {
|
|
27
|
-
const auth =
|
|
26
|
+
const auth = await readOpenCodeCredentials();
|
|
28
27
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
29
28
|
const apiKey = entry?.key ?? entry?.token;
|
|
30
29
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import { buildResult, toUsageWindow } from '../utils/index.js';
|
|
3
3
|
|
|
4
4
|
export const providerId = 'xai';
|
|
@@ -19,16 +19,16 @@ const nonEmptyString = (value) => {
|
|
|
19
19
|
return trimmed ? trimmed : null;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const xaiEntryOf = (auth) => {
|
|
23
|
+
const entry = auth?.xai;
|
|
24
|
+
if (entry?.type !== 'oauth') return null;
|
|
25
|
+
if (!nonEmptyString(entry.access) && !nonEmptyString(entry.refresh)) return null;
|
|
26
|
+
return entry;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const readXaiAuth = async () => {
|
|
23
30
|
try {
|
|
24
|
-
|
|
25
|
-
if (!entry || typeof entry !== 'object' || entry.type !== 'oauth') {
|
|
26
|
-
return { entry: null, error: null };
|
|
27
|
-
}
|
|
28
|
-
if (!nonEmptyString(entry.access) && !nonEmptyString(entry.refresh)) {
|
|
29
|
-
return { entry: null, error: null };
|
|
30
|
-
}
|
|
31
|
-
return { entry, error: null };
|
|
31
|
+
return { entry: xaiEntryOf(await readOpenCodeCredentials()), error: null };
|
|
32
32
|
} catch {
|
|
33
33
|
return { entry: null, error: 'Failed to read xAI OAuth credentials' };
|
|
34
34
|
}
|
|
@@ -340,10 +340,10 @@ const fetchUsage = async (accessToken) => {
|
|
|
340
340
|
return parseUsage(new Uint8Array(await response.arrayBuffer()));
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
-
export const isConfigured = () => Boolean(
|
|
343
|
+
export const isConfigured = (auth) => Boolean(xaiEntryOf(auth));
|
|
344
344
|
|
|
345
345
|
export const fetchQuota = async () => {
|
|
346
|
-
const { entry, error: authError } = readXaiAuth();
|
|
346
|
+
const { entry, error: authError } = await readXaiAuth();
|
|
347
347
|
if (authError) {
|
|
348
348
|
return buildResult({
|
|
349
349
|
providerId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -28,14 +28,13 @@ const formatCreditValueLabel = (limit) => {
|
|
|
28
28
|
return `${formatCreditAmount(used)} / ${formatCreditAmount(total)} credits`;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const isConfigured = () => {
|
|
32
|
-
const auth = readAuthFile();
|
|
31
|
+
export const isConfigured = (auth) => {
|
|
33
32
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
34
33
|
return Boolean(entry?.key || entry?.token);
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
export const fetchQuota = async () => {
|
|
38
|
-
const auth =
|
|
37
|
+
const auth = await readOpenCodeCredentials();
|
|
39
38
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
40
39
|
const apiKey = entry?.key ?? entry?.token;
|
|
41
40
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
vi.mock('../../opencode/auth.js', () => ({
|
|
4
|
-
|
|
4
|
+
readOpenCodeCredentials: async () => ({ 'zai-coding-plan': { key: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota } from './zai.js';
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* `data.level` is the plan tier (for example "lite") and becomes `planLabel`.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
20
20
|
import { readConfigLayers } from '../../opencode/shared.js';
|
|
21
21
|
import {
|
|
22
22
|
getAuthEntry,
|
|
@@ -70,8 +70,7 @@ const envelopeError = (payload) => {
|
|
|
70
70
|
return msg ?? `API error: ${code ?? 'unknown'}`;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
function getApiKey() {
|
|
74
|
-
const auth = readAuthFile();
|
|
73
|
+
function getApiKey(auth) {
|
|
75
74
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
76
75
|
const apiKeyFromAuth = entry?.key ?? entry?.token;
|
|
77
76
|
|
|
@@ -95,12 +94,12 @@ function getApiKey() {
|
|
|
95
94
|
return null;
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
export const isConfigured = () => {
|
|
99
|
-
return Boolean(getApiKey());
|
|
97
|
+
export const isConfigured = (auth) => {
|
|
98
|
+
return Boolean(getApiKey(auth));
|
|
100
99
|
};
|
|
101
100
|
|
|
102
101
|
export const fetchQuota = async () => {
|
|
103
|
-
const apiKey = getApiKey();
|
|
102
|
+
const apiKey = getApiKey(await readOpenCodeCredentials());
|
|
104
103
|
|
|
105
104
|
if (!apiKey) {
|
|
106
105
|
return buildResult({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
vi.mock('../../opencode/auth.js', () => ({
|
|
4
|
-
|
|
4
|
+
readOpenCodeCredentials: async () => ({ 'zhipuai-coding-plan': { key: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota } from './zhipuai-coding-plan.js';
|
|
@@ -28,7 +28,7 @@ export function registerQuotaRoutes(app, { getQuotaProviders }) {
|
|
|
28
28
|
app.get('/api/quota/providers', async (_req, res) => {
|
|
29
29
|
try {
|
|
30
30
|
const { listConfiguredQuotaProviders } = await getQuotaProviders();
|
|
31
|
-
res.json({ providers: listConfiguredQuotaProviders() });
|
|
31
|
+
res.json({ providers: await listConfiguredQuotaProviders() });
|
|
32
32
|
} catch (error) {
|
|
33
33
|
console.error('Failed to list quota providers:', error);
|
|
34
34
|
res.status(500).json({ error: error.message || 'Failed to list quota providers' });
|
|
@@ -83,6 +83,10 @@ Auto. There is no env gate — the feature shipped dark behind
|
|
|
83
83
|
- A category without a model uses the fallback model *and* variant; a variant
|
|
84
84
|
only travels with the model it was chosen for. A category agent replaces the
|
|
85
85
|
composer's agent; an empty one keeps it.
|
|
86
|
+
- A variant the model's catalog entry does not list is dropped before the
|
|
87
|
+
switch, so the reply runs on the model's default thinking instead of OpenCode
|
|
88
|
+
refusing it (Settings from before #4133 saved list positions like `"2"`).
|
|
89
|
+
An unreadable catalog, or one that does not know the model yet, keeps it.
|
|
86
90
|
- Auto is offered (`autoReady`) with a usable classification provider
|
|
87
91
|
(`jevAvailable`), `enabled`, a fallback model and at least two enabled
|
|
88
92
|
categories.
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
resolveClassifier,
|
|
27
27
|
} from './classifier.js';
|
|
28
28
|
import { loadRoutingHistory } from './history.js';
|
|
29
|
-
import {
|
|
29
|
+
import { readOpenCodeCredentials } from '../opencode/auth.js';
|
|
30
30
|
import { ENTERPRISE_MODE_ERROR, isEnterpriseMode } from '../enterprise-mode.js';
|
|
31
31
|
|
|
32
32
|
const HISTORY_TIMEOUT_MS = 2500;
|
|
@@ -55,6 +55,15 @@ export const requestTextOf = (body) => {
|
|
|
55
55
|
|
|
56
56
|
const agentBodySchema = z.object({ agent: z.string().trim().min(1) });
|
|
57
57
|
|
|
58
|
+
// v2 serves one flat model catalogue; a model's thinking levels are `{ id }[]`.
|
|
59
|
+
const catalogResponseSchema = z.object({
|
|
60
|
+
data: z.array(z.object({
|
|
61
|
+
providerID: z.string(),
|
|
62
|
+
modelID: z.string(),
|
|
63
|
+
variants: z.array(z.object({ id: z.string() })).default([]),
|
|
64
|
+
})),
|
|
65
|
+
});
|
|
66
|
+
|
|
58
67
|
const customEndpointInputSchema = z.object({
|
|
59
68
|
url: z.string().trim().min(1).max(2000),
|
|
60
69
|
model: z.string().trim().min(1).max(200),
|
|
@@ -84,10 +93,10 @@ const envKeySchema = z.string().trim().min(1);
|
|
|
84
93
|
*/
|
|
85
94
|
const PROVIDER_ENV_KEYS = { openrouter: 'OPENROUTER_API_KEY', vercel: 'AI_GATEWAY_API_KEY' };
|
|
86
95
|
|
|
87
|
-
export const readOpenCodeKeys = ({ readAuth =
|
|
96
|
+
export const readOpenCodeKeys = async ({ readAuth = readOpenCodeCredentials, env = process.env } = {}) => {
|
|
88
97
|
let auth = {};
|
|
89
98
|
try {
|
|
90
|
-
auth = readAuth();
|
|
99
|
+
auth = await readAuth();
|
|
91
100
|
} catch {
|
|
92
101
|
// An unreadable credential store still leaves the environment.
|
|
93
102
|
}
|
|
@@ -112,6 +121,7 @@ export function createRoutingRuntime({
|
|
|
112
121
|
zenPromotionActive = ZEN_JEV_PROMOTION_ACTIVE,
|
|
113
122
|
enterpriseMode = isEnterpriseMode,
|
|
114
123
|
readPinnedEndpoint = readPinnedCustomEndpoint,
|
|
124
|
+
listCatalogModels = null,
|
|
115
125
|
now = Date.now,
|
|
116
126
|
}) {
|
|
117
127
|
const permissionDecisions = new Map();
|
|
@@ -144,7 +154,7 @@ export function createRoutingRuntime({
|
|
|
144
154
|
// An endpoint the administrator pinned replaces the one saved in Settings.
|
|
145
155
|
const pinned = readPinnedEndpoint();
|
|
146
156
|
const customEndpoint = pinned ?? savedEndpoint;
|
|
147
|
-
const keys = { typesafeKey, customEndpoint, ...readProviderKeys() };
|
|
157
|
+
const keys = { typesafeKey, customEndpoint, ...(await readProviderKeys()) };
|
|
148
158
|
// Enterprise mode overrides whatever was picked; the pick itself is kept.
|
|
149
159
|
// The pinned endpoint is the administrator's own, so there it is the
|
|
150
160
|
// default and Off the only other choice.
|
|
@@ -237,6 +247,36 @@ export function createRoutingRuntime({
|
|
|
237
247
|
};
|
|
238
248
|
};
|
|
239
249
|
|
|
250
|
+
const readCatalog = listCatalogModels
|
|
251
|
+
?? (async (directory) => catalogResponseSchema.parse(await openCodeClient(directory).model.list()).data);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Drops a variant the model does not list, so the reply runs on the model's
|
|
255
|
+
* default thinking instead of OpenCode refusing it. Routing settings from
|
|
256
|
+
* before #4133 saved list positions ("0", "1", "2") as variants. A catalog
|
|
257
|
+
* that cannot be read, or does not know the model yet, keeps the variant.
|
|
258
|
+
*/
|
|
259
|
+
const withKnownVariant = async (selection, directory) => {
|
|
260
|
+
const variant = selection.model.variant;
|
|
261
|
+
if (!variant) return selection;
|
|
262
|
+
let models;
|
|
263
|
+
try {
|
|
264
|
+
models = await readCatalog(directory);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.warn('[routing] model catalog unavailable, keeping the saved variant:', errorMessage(error));
|
|
267
|
+
return selection;
|
|
268
|
+
}
|
|
269
|
+
const { providerID, id } = selection.model;
|
|
270
|
+
const entry = models.find((model) => model.providerID === providerID && model.modelID === id);
|
|
271
|
+
if (!entry || entry.variants.some((known) => known.id === variant)) return selection;
|
|
272
|
+
console.warn(`[routing] ${providerID}/${id} has no "${variant}" thinking level; using its default`);
|
|
273
|
+
return {
|
|
274
|
+
...selection,
|
|
275
|
+
model: { providerID, id },
|
|
276
|
+
decision: { ...selection.decision, variant: null },
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
240
280
|
/**
|
|
241
281
|
* Resolves one send that named the Auto sentinel. Returns the model and
|
|
242
282
|
* agent the send must use, or null when a real model was selected.
|
|
@@ -284,6 +324,7 @@ export function createRoutingRuntime({
|
|
|
284
324
|
} else {
|
|
285
325
|
selection = chooseSelection(config, null, agent);
|
|
286
326
|
}
|
|
327
|
+
selection = await withKnownVariant(selection, directory);
|
|
287
328
|
Object.assign(decision, selection.decision);
|
|
288
329
|
broadcast('openchamber:routing.decision', decision);
|
|
289
330
|
return { model: selection.model, agent: selection.agent, decision };
|
|
@@ -19,7 +19,7 @@ const readyConfig = () => {
|
|
|
19
19
|
return config;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const makeRuntime = ({ config = readyConfig(), token = 'key', classifierSource = null, customEndpoint = null, providerKeys = {}, zenPromotionActive = true, enterprise = false, pinned = null, answers, askError } = {}) => {
|
|
22
|
+
const makeRuntime = ({ config = readyConfig(), token = 'key', classifierSource = null, customEndpoint = null, providerKeys = {}, zenPromotionActive = true, enterprise = false, pinned = null, catalog = [], answers, askError } = {}) => {
|
|
23
23
|
const events = [];
|
|
24
24
|
const store = {
|
|
25
25
|
readConfig: vi.fn(async () => config),
|
|
@@ -45,6 +45,10 @@ const makeRuntime = ({ config = readyConfig(), token = 'key', classifierSource =
|
|
|
45
45
|
zenPromotionActive,
|
|
46
46
|
enterpriseMode: () => enterprise,
|
|
47
47
|
readPinnedEndpoint: () => pinned,
|
|
48
|
+
listCatalogModels: async () => {
|
|
49
|
+
if (catalog instanceof Error) throw catalog;
|
|
50
|
+
return catalog;
|
|
51
|
+
},
|
|
48
52
|
});
|
|
49
53
|
return { runtime, store, jev, events };
|
|
50
54
|
};
|
|
@@ -142,6 +146,31 @@ describe('resolveAutoSelection', () => {
|
|
|
142
146
|
const noFallback = makeRuntime({ config: { ...readyConfig(), fallback: null }, answers: {} });
|
|
143
147
|
await expect(noFallback.runtime.resolveAutoSelection(send())).rejects.toMatchObject({ status: 400 });
|
|
144
148
|
});
|
|
149
|
+
|
|
150
|
+
it('drops a saved variant the model does not list, such as a list position saved before #4133', async () => {
|
|
151
|
+
const config = readyConfig();
|
|
152
|
+
config.fallback = { model: FALLBACK.model, variant: '2' };
|
|
153
|
+
const catalog = [{ providerID: 'anthropic', modelID: 'claude-sonnet-5', variants: [{ id: 'low' }, { id: 'high' }] }];
|
|
154
|
+
const { runtime, events } = makeRuntime({ config, catalog, answers: { category: { choice: 'trivial', confidence: 0.99 } } });
|
|
155
|
+
const resolved = await runtime.resolveAutoSelection(send());
|
|
156
|
+
expect(resolved.model).toEqual({ providerID: 'anthropic', id: 'claude-sonnet-5' });
|
|
157
|
+
expect(resolved.decision.variant).toBeNull();
|
|
158
|
+
expect(events.at(-1).properties.variant).toBeNull();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('keeps a known variant, and any variant when the catalog cannot vouch for the model', async () => {
|
|
162
|
+
const known = makeRuntime({
|
|
163
|
+
catalog: [{ providerID: 'anthropic', modelID: 'claude-sonnet-5', variants: [{ id: 'medium' }] }],
|
|
164
|
+
answers: { category: { choice: 'trivial', confidence: 0.99 } },
|
|
165
|
+
});
|
|
166
|
+
expect((await known.runtime.resolveAutoSelection(send())).model.variant).toBe('medium');
|
|
167
|
+
|
|
168
|
+
const unknownModel = makeRuntime({ catalog: [], answers: { category: { choice: 'trivial', confidence: 0.99 } } });
|
|
169
|
+
expect((await unknownModel.runtime.resolveAutoSelection(send())).model.variant).toBe('medium');
|
|
170
|
+
|
|
171
|
+
const unreachable = makeRuntime({ catalog: new Error('OpenCode down'), answers: { category: { choice: 'trivial', confidence: 0.99 } } });
|
|
172
|
+
expect((await unreachable.runtime.resolveAutoSelection(send())).model.variant).toBe('medium');
|
|
173
|
+
});
|
|
145
174
|
});
|
|
146
175
|
|
|
147
176
|
describe('jev endpoint', () => {
|
|
@@ -255,19 +284,19 @@ describe('resolveClassifier', () => {
|
|
|
255
284
|
describe('readOpenCodeKeys', () => {
|
|
256
285
|
const env = { OPENROUTER_API_KEY: 'or-env', AI_GATEWAY_API_KEY: ' gw-env ' };
|
|
257
286
|
|
|
258
|
-
it('prefers a key saved in OpenCode and falls back to the variable OpenCode reads', () => {
|
|
287
|
+
it('prefers a key saved in OpenCode and falls back to the variable OpenCode reads', async () => {
|
|
259
288
|
const readAuth = () => ({
|
|
260
289
|
opencode: { type: 'api', key: 'zen' },
|
|
261
290
|
openrouter: { type: 'api', key: 'or-saved' },
|
|
262
291
|
vercel: { type: 'oauth', access: 'a', refresh: 'r', expires: 0 },
|
|
263
292
|
});
|
|
264
|
-
expect(readOpenCodeKeys({ readAuth, env })).toEqual({ zenKey: 'zen', openrouterKey: 'or-saved', vercelKey: 'gw-env' });
|
|
293
|
+
expect(await readOpenCodeKeys({ readAuth, env })).toEqual({ zenKey: 'zen', openrouterKey: 'or-saved', vercelKey: 'gw-env' });
|
|
265
294
|
});
|
|
266
295
|
|
|
267
|
-
it('keeps the variables when the credential store cannot be read, and ignores blank ones', () => {
|
|
296
|
+
it('keeps the variables when the credential store cannot be read, and ignores blank ones', async () => {
|
|
268
297
|
const readAuth = () => { throw new Error('locked'); };
|
|
269
|
-
expect(readOpenCodeKeys({ readAuth, env })).toEqual({ zenKey: null, openrouterKey: 'or-env', vercelKey: 'gw-env' });
|
|
270
|
-
expect(readOpenCodeKeys({ readAuth: () => ({}), env: { OPENROUTER_API_KEY: ' ' } })).toEqual({ zenKey: null, openrouterKey: null, vercelKey: null });
|
|
298
|
+
expect(await readOpenCodeKeys({ readAuth, env })).toEqual({ zenKey: null, openrouterKey: 'or-env', vercelKey: 'gw-env' });
|
|
299
|
+
expect(await readOpenCodeKeys({ readAuth: () => ({}), env: { OPENROUTER_API_KEY: ' ' } })).toEqual({ zenKey: null, openrouterKey: null, vercelKey: null });
|
|
271
300
|
});
|
|
272
301
|
});
|
|
273
302
|
|
|
@@ -8,6 +8,33 @@ Server-owned scheduled task runtime and routes for OpenChamber-only automation.
|
|
|
8
8
|
- Markdown loop discovery/parsing is owned by `packages/web/server/lib/scheduled-tasks/loops.js`.
|
|
9
9
|
- Runtime orchestration and execution is owned by `packages/web/server/lib/scheduled-tasks/runtime.js`.
|
|
10
10
|
- This module is OpenChamber feature logic; it is intentionally separate from OpenCode proxy/runtime internals.
|
|
11
|
+
- The chats scope is owned by `packages/web/server/lib/scheduled-tasks/chats-scope.js`.
|
|
12
|
+
|
|
13
|
+
## Chats scope
|
|
14
|
+
|
|
15
|
+
Chats (sessions outside any project) can have scheduled tasks too. They are
|
|
16
|
+
scheduled like one more project, with three differences:
|
|
17
|
+
|
|
18
|
+
- **Identity.** The UI and the routes address the scope as `openchamber:chats`
|
|
19
|
+
(the UI's `CHAT_DRAFT_PROJECT_ID`). A colon is not a valid Windows file name,
|
|
20
|
+
so tasks are stored under the chats root's path id
|
|
21
|
+
(`createProjectIdFromPath(<chats root>)`, the same id agent memory uses for
|
|
22
|
+
chats). The service maps the public id to the storage id on the way in, and
|
|
23
|
+
`openchamber:scheduled-task-ran` events map it back on the way out.
|
|
24
|
+
- **One new chat per run.** A project run works in the project path. A chats run
|
|
25
|
+
creates `<chats root>/<yyyy-mm-dd>/session-<uuid>`, the layout the UI uses for
|
|
26
|
+
a new chat, and starts the session there, so each run lands in the sidebar's
|
|
27
|
+
chats section as its own chat. If the session cannot be created, the empty
|
|
28
|
+
directory is removed. The run result carries the directory, so "Run now" can
|
|
29
|
+
open the new chat.
|
|
30
|
+
- **No loop files.** The chats root is not a repository. User-scope loops
|
|
31
|
+
already run once per project, so the chats scope never discovers loops.
|
|
32
|
+
- **Directory resolution.** `resolveProjectID({ directory })` maps any
|
|
33
|
+
directory inside the chats root to the chats scope, after checking registered
|
|
34
|
+
projects, so an agent working in a chat schedules into chats.
|
|
35
|
+
|
|
36
|
+
The chats root is `OPENCHAMBER_CHATS_DIR` (default `<config root>/chats`). The
|
|
37
|
+
VS Code extension has no chats, so its UI does not offer the scope.
|
|
11
38
|
|
|
12
39
|
## Cross-instance occurrence claiming
|
|
13
40
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
5
|
+
|
|
6
|
+
// The id the UI already uses for the chats list (CHAT_DRAFT_PROJECT_ID). It is
|
|
7
|
+
// not a valid file name on Windows, so tasks are stored under the chats root's
|
|
8
|
+
// path id instead and this id only exists at the API edge.
|
|
9
|
+
export const CHATS_SCOPE_PUBLIC_ID = 'openchamber:chats';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Chats have no project checkout: every chat owns a fresh directory under the
|
|
13
|
+
* managed chats root. A scheduled task in the chats scope therefore stores its
|
|
14
|
+
* definition under the root and opens a new chat directory for each run.
|
|
15
|
+
*/
|
|
16
|
+
export const createChatsScope = (chatsRoot) => {
|
|
17
|
+
const root = path.resolve(chatsRoot);
|
|
18
|
+
const id = createProjectIdFromPath(root);
|
|
19
|
+
|
|
20
|
+
const contains = (directory) => {
|
|
21
|
+
const relative = path.relative(root, path.resolve(directory));
|
|
22
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Same layout the UI uses for a new chat: <root>/<yyyy-mm-dd>/session-<uuid>.
|
|
26
|
+
const createChatDirectory = async (now = new Date()) => {
|
|
27
|
+
const date = [
|
|
28
|
+
now.getFullYear(),
|
|
29
|
+
String(now.getMonth() + 1).padStart(2, '0'),
|
|
30
|
+
String(now.getDate()).padStart(2, '0'),
|
|
31
|
+
].join('-');
|
|
32
|
+
const directory = path.join(root, date, `session-${crypto.randomUUID()}`);
|
|
33
|
+
await fs.mkdir(directory, { recursive: true });
|
|
34
|
+
return directory;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Only for a run that never got a session: the directory is still empty,
|
|
38
|
+
// and a non-recursive removal refuses to touch anything that is not.
|
|
39
|
+
const discardChatDirectory = (directory) => fs.rmdir(directory).catch(() => undefined);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
id,
|
|
43
|
+
root,
|
|
44
|
+
toStorageID: (projectID) => (projectID === CHATS_SCOPE_PUBLIC_ID ? id : projectID),
|
|
45
|
+
toPublicID: (projectID) => (projectID === id ? CHATS_SCOPE_PUBLIC_ID : projectID),
|
|
46
|
+
contains,
|
|
47
|
+
createChatDirectory,
|
|
48
|
+
discardChatDirectory,
|
|
49
|
+
};
|
|
50
|
+
};
|