@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
|
@@ -3,7 +3,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
const credential = vi.fn();
|
|
4
4
|
|
|
5
5
|
vi.mock('./auth.js', () => ({
|
|
6
|
-
|
|
6
|
+
findClaudeCredential: () => credential(),
|
|
7
|
+
loadClaudeCredential: async () => credential(),
|
|
7
8
|
}));
|
|
8
9
|
|
|
9
10
|
import { fetchQuota, isConfigured, resetClaudeQuotaCache } from './index.js';
|
|
@@ -50,7 +51,7 @@ describe('Claude quota provider', () => {
|
|
|
50
51
|
it('reports not configured when no credential source has a token', async () => {
|
|
51
52
|
credential.mockReturnValue(null);
|
|
52
53
|
|
|
53
|
-
expect(isConfigured()).toBe(false);
|
|
54
|
+
expect(isConfigured({})).toBe(false);
|
|
54
55
|
const result = await fetchQuota();
|
|
55
56
|
expect(result.configured).toBe(false);
|
|
56
57
|
expect(result.ok).toBe(false);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -29,10 +29,10 @@ const getApiKey = (auth) => {
|
|
|
29
29
|
return asNonEmptyString(entry?.key) ?? asNonEmptyString(entry?.token);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export const isConfigured = (auth
|
|
32
|
+
export const isConfigured = (auth) => Boolean(getApiKey(auth));
|
|
33
33
|
|
|
34
|
-
export const fetchQuota = async ({ readAuth =
|
|
35
|
-
const apiKey = getApiKey(readAuth());
|
|
34
|
+
export const fetchQuota = async ({ readAuth = readOpenCodeCredentials, fetchImpl = fetch } = {}) => {
|
|
35
|
+
const apiKey = getApiKey(await readAuth());
|
|
36
36
|
|
|
37
37
|
if (!apiKey) {
|
|
38
38
|
return buildResult({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -14,14 +14,13 @@ export const providerId = 'codex';
|
|
|
14
14
|
export const providerName = 'Codex';
|
|
15
15
|
const aliases = ['openai', 'codex', 'chatgpt'];
|
|
16
16
|
|
|
17
|
-
export const isConfigured = () => {
|
|
18
|
-
const auth = readAuthFile();
|
|
17
|
+
export const isConfigured = (auth) => {
|
|
19
18
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
20
19
|
return Boolean(entry?.access || entry?.token);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
export const fetchQuota = async () => {
|
|
24
|
-
const auth =
|
|
23
|
+
const auth = await readOpenCodeCredentials();
|
|
25
24
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
26
25
|
const accessToken = entry?.access ?? entry?.token;
|
|
27
26
|
const accountId = entry?.accountId;
|
|
@@ -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 () => ({ openai: { access: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota } from './codex.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -61,14 +61,13 @@ export const providerId = 'github-copilot';
|
|
|
61
61
|
export const providerName = 'GitHub Copilot';
|
|
62
62
|
const aliases = ['github-copilot', 'copilot'];
|
|
63
63
|
|
|
64
|
-
export const isConfigured = () => {
|
|
65
|
-
const auth = readAuthFile();
|
|
64
|
+
export const isConfigured = (auth) => {
|
|
66
65
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
67
66
|
return Boolean(entry?.access || entry?.token);
|
|
68
67
|
};
|
|
69
68
|
|
|
70
69
|
export const fetchQuota = async () => {
|
|
71
|
-
const auth =
|
|
70
|
+
const auth = await readOpenCodeCredentials();
|
|
72
71
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
73
72
|
const accessToken = entry?.access ?? entry?.token;
|
|
74
73
|
|
|
@@ -126,7 +125,7 @@ export const providerIdAddon = 'github-copilot-addon';
|
|
|
126
125
|
export const providerNameAddon = 'GitHub Copilot Add-on';
|
|
127
126
|
|
|
128
127
|
export const fetchQuotaAddon = async () => {
|
|
129
|
-
const auth =
|
|
128
|
+
const auth = await readOpenCodeCredentials();
|
|
130
129
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
131
130
|
const accessToken = entry?.access ?? entry?.token;
|
|
132
131
|
|
|
@@ -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 () => ({ 'github-copilot': { access: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota, fetchQuotaAddon } from './copilot.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -13,14 +13,13 @@ export const providerName = 'DeepSeek';
|
|
|
13
13
|
const aliases = ['deepseek'];
|
|
14
14
|
const DEEPSEEK_QUOTA_URL = 'https://api.deepseek.com/user/balance';
|
|
15
15
|
|
|
16
|
-
export const isConfigured = () => {
|
|
17
|
-
const auth = readAuthFile();
|
|
16
|
+
export const isConfigured = (auth) => {
|
|
18
17
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
19
18
|
return Boolean(entry?.key || entry?.token);
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
export const fetchQuota = async () => {
|
|
23
|
-
const auth =
|
|
22
|
+
const auth = await readOpenCodeCredentials();
|
|
24
23
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
25
24
|
const apiKey = entry?.key ?? entry?.token;
|
|
26
25
|
|
|
@@ -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 () => ({ deepseek: { key: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota } from './deepseek.js';
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
asNonEmptyString,
|
|
15
15
|
toTimestamp
|
|
16
16
|
} from '../../utils/index.js';
|
|
17
|
-
import { readAuthFile } from '../../../opencode/auth.js';
|
|
18
17
|
import { parseGoogleRefreshToken } from './transforms.js';
|
|
19
18
|
|
|
20
19
|
const ANTIGRAVITY_GOOGLE_CLIENT_ID =
|
|
@@ -90,8 +89,7 @@ const resolveAntigravityAuth = () => {
|
|
|
90
89
|
return null;
|
|
91
90
|
};
|
|
92
91
|
|
|
93
|
-
export const resolveGoogleAuthSources = () => {
|
|
94
|
-
const auth = readAuthFile();
|
|
92
|
+
export const resolveGoogleAuthSources = (auth) => {
|
|
95
93
|
const sources = [];
|
|
96
94
|
|
|
97
95
|
const geminiAuth = resolveGeminiCliAuth(auth);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readOpenCodeCredentials } from '../../../opencode/auth.js';
|
|
1
2
|
import { buildResult } from '../../utils/index.js';
|
|
2
3
|
import {
|
|
3
4
|
resolveGoogleAuthSources,
|
|
@@ -17,10 +18,10 @@ export const providerId = 'google';
|
|
|
17
18
|
export const providerName = 'Google';
|
|
18
19
|
export const aliases = ['google', 'google.oauth'];
|
|
19
20
|
|
|
20
|
-
export const isConfigured = () => resolveGoogleAuthSources().length > 0;
|
|
21
|
+
export const isConfigured = (auth) => resolveGoogleAuthSources(auth).length > 0;
|
|
21
22
|
|
|
22
23
|
export const fetchGoogleQuota = async () => {
|
|
23
|
-
const authSources = resolveGoogleAuthSources();
|
|
24
|
+
const authSources = resolveGoogleAuthSources(await readOpenCodeCredentials());
|
|
24
25
|
if (!authSources.length) {
|
|
25
26
|
return buildResult({
|
|
26
27
|
providerId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -21,10 +21,10 @@ const getApiKey = (auth) => {
|
|
|
21
21
|
return asNonEmptyString(entry?.key) ?? asNonEmptyString(entry?.token);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export const isConfigured = (auth
|
|
24
|
+
export const isConfigured = (auth) => Boolean(getApiKey(auth));
|
|
25
25
|
|
|
26
|
-
export const fetchQuota = async ({ readAuth =
|
|
27
|
-
const apiKey = getApiKey(readAuth());
|
|
26
|
+
export const fetchQuota = async ({ readAuth = readOpenCodeCredentials, fetchImpl = fetch } = {}) => {
|
|
27
|
+
const apiKey = getApiKey(await readAuth());
|
|
28
28
|
|
|
29
29
|
if (!apiKey) {
|
|
30
30
|
return buildResult({
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @module quota/providers
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
8
9
|
import { buildResult } from '../utils/index.js';
|
|
9
10
|
|
|
10
11
|
import * as claude from './claude/index.js';
|
|
@@ -168,12 +169,18 @@ const registry = {
|
|
|
168
169
|
const pendingFetches = new Map();
|
|
169
170
|
|
|
170
171
|
|
|
171
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Providers with a usable credential. OpenCode's stored credentials are read
|
|
174
|
+
* once and handed to every provider; when OpenCode cannot be asked this
|
|
175
|
+
* throws, so a transient failure does not look like "nothing configured".
|
|
176
|
+
*/
|
|
177
|
+
export const listConfiguredQuotaProviders = async () => {
|
|
178
|
+
const auth = await readOpenCodeCredentials();
|
|
172
179
|
const configured = [];
|
|
173
180
|
|
|
174
181
|
for (const [id, provider] of Object.entries(registry)) {
|
|
175
182
|
try {
|
|
176
|
-
if (provider.isConfigured()) {
|
|
183
|
+
if (provider.isConfigured(auth)) {
|
|
177
184
|
configured.push(id);
|
|
178
185
|
}
|
|
179
186
|
} catch {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('../../opencode/auth.js', () => ({ readOpenCodeCredentials: async () => ({}) }));
|
|
2
4
|
|
|
3
5
|
import * as google from './google/index.js';
|
|
4
6
|
import { fetchQuotaForProvider, listConfiguredQuotaProviders } from './index.js';
|
|
@@ -11,8 +13,8 @@ describe('quota provider registry', () => {
|
|
|
11
13
|
expect(typeof google.resolveGoogleAuthSources).toBe('function');
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
it('can list configured providers without missing provider exports', () => {
|
|
15
|
-
expect(
|
|
16
|
+
it('can list configured providers without missing provider exports', async () => {
|
|
17
|
+
await expect(listConfiguredQuotaProviders()).resolves.toBeInstanceOf(Array);
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
it('coalesces concurrent refreshes by provider ID', async () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -7,12 +7,18 @@ import {
|
|
|
7
7
|
toNumber,
|
|
8
8
|
toTimestamp,
|
|
9
9
|
durationToLabel,
|
|
10
|
-
durationToSeconds
|
|
10
|
+
durationToSeconds,
|
|
11
|
+
asNonEmptyString
|
|
11
12
|
} from '../utils/index.js';
|
|
12
13
|
|
|
13
14
|
export const providerId = 'kimi-for-coding';
|
|
14
15
|
export const providerName = 'Kimi for Coding';
|
|
15
|
-
|
|
16
|
+
// OpenCode stores the Kimi For Coding plans as `kimi-code-plan-cn` (kimi.com)
|
|
17
|
+
// and `kimi-code-plan-global` (kimi.ai). The China plan comes first: its key
|
|
18
|
+
// works at the api.kimi.com usage address, and a pre-split `kimi-for-coding`
|
|
19
|
+
// key left behind with a dead credential must not shadow it. The global plan
|
|
20
|
+
// stays last, as before, since its key is not known to work at that address.
|
|
21
|
+
export const aliases = ['kimi-code-plan-cn', 'kimi-for-coding', 'kimi', 'kimi-code-plan-global'];
|
|
16
22
|
|
|
17
23
|
// Kimi's weekly `usage` block reports `used`; its rate-limit `limits[].detail`
|
|
18
24
|
// blocks report `remaining` instead. Neither field is guaranteed present, so
|
|
@@ -28,16 +34,15 @@ const computeUsedPercent = (total, used, remaining) => {
|
|
|
28
34
|
return null;
|
|
29
35
|
};
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
const auth = readAuthFile();
|
|
37
|
+
const getApiKey = (auth) => {
|
|
33
38
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
34
|
-
return
|
|
39
|
+
return asNonEmptyString(entry?.key) ?? asNonEmptyString(entry?.token);
|
|
35
40
|
};
|
|
36
41
|
|
|
37
|
-
export const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const apiKey =
|
|
42
|
+
export const isConfigured = (auth) => Boolean(getApiKey(auth));
|
|
43
|
+
|
|
44
|
+
export const fetchQuota = async ({ readAuth = readOpenCodeCredentials, fetchImpl = fetch } = {}) => {
|
|
45
|
+
const apiKey = getApiKey(await readAuth());
|
|
41
46
|
|
|
42
47
|
if (!apiKey) {
|
|
43
48
|
return buildResult({
|
|
@@ -50,7 +55,7 @@ export const fetchQuota = async () => {
|
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
try {
|
|
53
|
-
const response = await
|
|
58
|
+
const response = await fetchImpl('https://api.kimi.com/coding/v1/usages', {
|
|
54
59
|
method: 'GET',
|
|
55
60
|
headers: {
|
|
56
61
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
readAuthFile: () => ({ 'kimi-for-coding': { key: 'test-token' } }),
|
|
5
|
-
}));
|
|
3
|
+
import { fetchQuota, isConfigured } from './kimi.js';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
vi.unstubAllGlobals();
|
|
11
|
-
});
|
|
5
|
+
const readAuth = () => ({ 'kimi-for-coding': { key: 'test-token' } });
|
|
12
6
|
|
|
13
7
|
const mockResponse = (body, init = {}) => ({
|
|
14
8
|
ok: true,
|
|
@@ -21,17 +15,17 @@ describe('Kimi for Coding quota provider', () => {
|
|
|
21
15
|
it('computes weekly usedPercent from the used field (live API shape, no remaining field)', async () => {
|
|
22
16
|
// Captured from GET https://api.kimi.com/coding/v1/usages — the weekly
|
|
23
17
|
// `usage` block only ever includes `used`, never `remaining`.
|
|
24
|
-
|
|
18
|
+
const fetchImpl = async () => (
|
|
25
19
|
mockResponse({
|
|
26
20
|
usage: { limit: '100', used: '100', resetTime: '2026-08-04T06:21:48.514003Z' },
|
|
27
21
|
limits: [{
|
|
28
22
|
window: { duration: 300, timeUnit: 'TIME_UNIT_MINUTE' },
|
|
29
23
|
detail: { limit: '100', remaining: '100', resetTime: '2026-08-03T07:21:48.514003Z' },
|
|
30
24
|
}],
|
|
31
|
-
})
|
|
32
|
-
)
|
|
25
|
+
})
|
|
26
|
+
);
|
|
33
27
|
|
|
34
|
-
const result = await fetchQuota();
|
|
28
|
+
const result = await fetchQuota({ readAuth, fetchImpl });
|
|
35
29
|
|
|
36
30
|
expect(result.ok).toBe(true);
|
|
37
31
|
expect(result.usage.windows.weekly.usedPercent).toBe(100);
|
|
@@ -39,70 +33,119 @@ describe('Kimi for Coding quota provider', () => {
|
|
|
39
33
|
});
|
|
40
34
|
|
|
41
35
|
it('falls back to computing usedPercent from remaining when used is absent', async () => {
|
|
42
|
-
|
|
36
|
+
const fetchImpl = async () => (
|
|
43
37
|
mockResponse({
|
|
44
38
|
usage: { limit: '2048', remaining: '512', resetTime: '2026-08-04T06:21:48.514003Z' },
|
|
45
39
|
limits: [],
|
|
46
|
-
})
|
|
47
|
-
)
|
|
40
|
+
})
|
|
41
|
+
);
|
|
48
42
|
|
|
49
|
-
const result = await fetchQuota();
|
|
43
|
+
const result = await fetchQuota({ readAuth, fetchImpl });
|
|
50
44
|
|
|
51
45
|
expect(result.usage.windows.weekly.usedPercent).toBe(75);
|
|
52
46
|
});
|
|
53
47
|
|
|
54
48
|
it('prefers used over remaining when both fields are present', async () => {
|
|
55
|
-
|
|
49
|
+
const fetchImpl = async () => (
|
|
56
50
|
mockResponse({
|
|
57
51
|
usage: { limit: '100', used: '30', remaining: '999', resetTime: null },
|
|
58
52
|
limits: [],
|
|
59
|
-
})
|
|
60
|
-
)
|
|
53
|
+
})
|
|
54
|
+
);
|
|
61
55
|
|
|
62
|
-
const result = await fetchQuota();
|
|
56
|
+
const result = await fetchQuota({ readAuth, fetchImpl });
|
|
63
57
|
|
|
64
58
|
expect(result.usage.windows.weekly.usedPercent).toBe(30);
|
|
65
59
|
});
|
|
66
60
|
|
|
67
61
|
it('reports null usedPercent when neither used nor remaining is present', async () => {
|
|
68
|
-
|
|
62
|
+
const fetchImpl = async () => (
|
|
69
63
|
mockResponse({
|
|
70
64
|
usage: { limit: '100', resetTime: null },
|
|
71
65
|
limits: [],
|
|
72
|
-
})
|
|
73
|
-
)
|
|
66
|
+
})
|
|
67
|
+
);
|
|
74
68
|
|
|
75
|
-
const result = await fetchQuota();
|
|
69
|
+
const result = await fetchQuota({ readAuth, fetchImpl });
|
|
76
70
|
|
|
77
71
|
expect(result.usage.windows.weekly.usedPercent).toBeNull();
|
|
78
72
|
});
|
|
79
73
|
|
|
80
74
|
it('reports not configured when no credentials are stored', async () => {
|
|
81
|
-
|
|
82
|
-
vi.resetModules();
|
|
83
|
-
const { fetchQuota: fetchQuotaFresh } = await import('./kimi.js');
|
|
84
|
-
|
|
85
|
-
const result = await fetchQuotaFresh();
|
|
75
|
+
const result = await fetchQuota({ readAuth: () => ({}), fetchImpl: async () => { throw new Error('Unexpected fetch'); } });
|
|
86
76
|
|
|
87
77
|
expect(result.ok).toBe(false);
|
|
88
78
|
expect(result.configured).toBe(false);
|
|
89
79
|
expect(result.error).toBe('Not configured');
|
|
80
|
+
});
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
it('skips a blank key and uses the token next to it', async () => {
|
|
83
|
+
const auth = { 'kimi-code-plan-cn': { key: ' ', token: 'cn-token' } };
|
|
84
|
+
let authorization;
|
|
85
|
+
const fetchImpl = async (_url, init) => {
|
|
86
|
+
authorization = init.headers.Authorization;
|
|
87
|
+
return mockResponse({ usage: null, limits: [] });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
await fetchQuota({ readAuth: () => auth, fetchImpl });
|
|
91
|
+
|
|
92
|
+
expect(isConfigured(auth)).toBe(true);
|
|
93
|
+
expect(authorization).toBe('Bearer cn-token');
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
it('surfaces API errors with status', async () => {
|
|
96
|
-
|
|
97
|
-
ok: false,
|
|
98
|
-
status: 401,
|
|
99
|
-
json: async () => ({}),
|
|
100
|
-
}));
|
|
97
|
+
const fetchImpl = async () => ({ ok: false, status: 401, json: async () => ({}) });
|
|
101
98
|
|
|
102
|
-
const result = await fetchQuota();
|
|
99
|
+
const result = await fetchQuota({ readAuth, fetchImpl });
|
|
103
100
|
|
|
104
101
|
expect(result.ok).toBe(false);
|
|
105
102
|
expect(result.configured).toBe(true);
|
|
106
103
|
expect(result.error).toBe('API error: 401');
|
|
107
104
|
});
|
|
105
|
+
|
|
106
|
+
describe('credential lookup', () => {
|
|
107
|
+
const sentKey = async (auth) => {
|
|
108
|
+
let authorization;
|
|
109
|
+
const fetchImpl = async (_url, init) => {
|
|
110
|
+
authorization = init.headers.Authorization;
|
|
111
|
+
return mockResponse({ usage: null, limits: [] });
|
|
112
|
+
};
|
|
113
|
+
const result = await fetchQuota({ readAuth: () => auth, fetchImpl });
|
|
114
|
+
return { result, authorization };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
it('finds a China plan credential stored under kimi-code-plan-cn', async () => {
|
|
118
|
+
const auth = { 'kimi-code-plan-cn': { type: 'api', key: 'cn-key' } };
|
|
119
|
+
|
|
120
|
+
const { result, authorization } = await sentKey(auth);
|
|
121
|
+
|
|
122
|
+
expect(isConfigured(auth)).toBe(true);
|
|
123
|
+
expect(result.ok).toBe(true);
|
|
124
|
+
expect(authorization).toBe('Bearer cn-key');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('prefers the China plan credential over a leftover pre-split kimi-for-coding key', async () => {
|
|
128
|
+
const { authorization } = await sentKey({
|
|
129
|
+
'kimi-for-coding': { type: 'api', key: 'stale-key' },
|
|
130
|
+
kimi: { type: 'api', key: 'older-key' },
|
|
131
|
+
'kimi-code-plan-cn': { type: 'api', key: 'cn-key' },
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(authorization).toBe('Bearer cn-key');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('still reads the global plan and the pre-split ids when they are the only credential', async () => {
|
|
138
|
+
expect((await sentKey({ 'kimi-code-plan-global': { key: 'global-key' } })).authorization).toBe('Bearer global-key');
|
|
139
|
+
expect((await sentKey({ 'kimi-for-coding': { key: 'legacy-key' } })).authorization).toBe('Bearer legacy-key');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('keeps a pre-split key ahead of the global plan, as before', async () => {
|
|
143
|
+
const { authorization } = await sentKey({
|
|
144
|
+
'kimi-code-plan-global': { key: 'global-key' },
|
|
145
|
+
'kimi-for-coding': { key: 'legacy-key' },
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(authorization).toBe('Bearer legacy-key');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
108
151
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -138,14 +138,13 @@ const calculateUsage = (model, isTokenPlan) => {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
export const createMiniMaxCodingPlanProvider = ({ providerId, providerName, aliases, tokenPlanUrl, codingPlanUrl }) => {
|
|
141
|
-
const isConfigured = () => {
|
|
142
|
-
const auth = readAuthFile();
|
|
141
|
+
const isConfigured = (auth) => {
|
|
143
142
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
144
143
|
return Boolean(entry?.key || entry?.token);
|
|
145
144
|
};
|
|
146
145
|
|
|
147
146
|
const fetchQuota = async () => {
|
|
148
|
-
const auth =
|
|
147
|
+
const auth = await readOpenCodeCredentials();
|
|
149
148
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
150
149
|
const apiKey = entry?.key ?? entry?.token;
|
|
151
150
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -14,14 +14,13 @@ export const providerId = 'nano-gpt';
|
|
|
14
14
|
export const providerName = 'NanoGPT';
|
|
15
15
|
const aliases = ['nano-gpt', 'nanogpt', 'nano_gpt'];
|
|
16
16
|
|
|
17
|
-
export const isConfigured = () => {
|
|
18
|
-
const auth = readAuthFile();
|
|
17
|
+
export const isConfigured = (auth) => {
|
|
19
18
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
20
19
|
return Boolean(entry?.key || entry?.token);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
export const fetchQuota = async () => {
|
|
24
|
-
const auth =
|
|
23
|
+
const auth = await readOpenCodeCredentials();
|
|
25
24
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
26
25
|
const apiKey = entry?.key ?? entry?.token;
|
|
27
26
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -25,14 +25,13 @@ const periodToWindowSeconds = (period) => {
|
|
|
25
25
|
return null;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const isConfigured = () => {
|
|
29
|
-
const auth = readAuthFile();
|
|
28
|
+
export const isConfigured = (auth) => {
|
|
30
29
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
31
30
|
return Boolean(entry?.key || entry?.token);
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
export const fetchQuota = async () => {
|
|
35
|
-
const auth =
|
|
34
|
+
const auth = await readOpenCodeCredentials();
|
|
36
35
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
37
36
|
const apiKey = entry?.key ?? entry?.token;
|
|
38
37
|
|
|
@@ -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 () => ({ neuralwatt: { key: 'test-token' } }),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
7
|
import { fetchQuota } from './neuralwatt.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import {
|
|
3
3
|
getAuthEntry,
|
|
4
4
|
normalizeAuthEntry,
|
|
@@ -12,14 +12,8 @@ const providerId = 'openai';
|
|
|
12
12
|
const providerName = 'OpenAI';
|
|
13
13
|
const aliases = ['openai', 'codex', 'chatgpt'];
|
|
14
14
|
|
|
15
|
-
const isConfigured = () => {
|
|
16
|
-
const auth = readAuthFile();
|
|
17
|
-
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
18
|
-
return Boolean(entry?.access || entry?.token);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
15
|
export const fetchQuota = async () => {
|
|
22
|
-
const auth =
|
|
16
|
+
const auth = await readOpenCodeCredentials();
|
|
23
17
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
24
18
|
const accessToken = entry?.access ?? entry?.token;
|
|
25
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readOpenCodeCredentials } from '../../opencode/auth.js';
|
|
2
2
|
import { deleteLegacyOpenCodeGoCredential } from '../credentials/store.js';
|
|
3
3
|
import { buildResult, getAuthEntry, normalizeAuthEntry, toUsageWindow } from '../utils/index.js';
|
|
4
4
|
|
|
@@ -51,17 +51,17 @@ export const fetchOpenCodeGoUsage = async (apiKey, fetchImpl = fetch) => {
|
|
|
51
51
|
return windows;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const getApiKey = () => {
|
|
55
|
-
const entry = normalizeAuthEntry(getAuthEntry(
|
|
54
|
+
const getApiKey = (auth) => {
|
|
55
|
+
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
56
56
|
return entry?.key ?? entry?.token ?? null;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export const isConfigured = () => Boolean(getApiKey());
|
|
59
|
+
export const isConfigured = (auth) => Boolean(getApiKey(auth));
|
|
60
60
|
|
|
61
61
|
export const fetchQuota = async () => {
|
|
62
62
|
try {
|
|
63
63
|
deleteLegacyOpenCodeGoCredential();
|
|
64
|
-
const apiKey = getApiKey();
|
|
64
|
+
const apiKey = getApiKey(await readOpenCodeCredentials());
|
|
65
65
|
if (!apiKey) return buildResult({ providerId, providerName, ok: false, configured: false, error: 'Not configured' });
|
|
66
66
|
const windows = await fetchOpenCodeGoUsage(apiKey);
|
|
67
67
|
return buildResult({ providerId, providerName, ok: true, configured: true, usage: { windows } });
|
|
@@ -8,7 +8,7 @@ const temporaryDataDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'openchambe
|
|
|
8
8
|
process.env.OPENCHAMBER_DATA_DIR = temporaryDataDirectory;
|
|
9
9
|
|
|
10
10
|
vi.mock('../../opencode/auth.js', () => ({
|
|
11
|
-
|
|
11
|
+
readOpenCodeCredentials: async () => ({ 'opencode-go': { key: 'test-key' } }),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
14
|
import { fetchOpenCodeGoUsage, fetchQuota, parseOpenCodeGoUsage } from './opencode-go.js';
|