@openchamber/web 1.21.0 → 1.21.1
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/bin/cli.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
- package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
- package/dist/assets/{DiffView-D5cvbEPb.js → DiffView-Db6bjVv1.js} +3 -3
- package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
- package/dist/assets/GitView-CHzJxTi0.js +6 -0
- package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-CggOsLot.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
- package/dist/assets/{OnboardingScreen-w2VG4fWY.js → OnboardingScreen-C98d69Fp.js} +1 -1
- package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-DJYMUiXA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-CY2bx_SB.js} +3 -3
- package/dist/assets/PlanView-PkiOY_9H.js +5 -0
- package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
- package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-oyOm2fHR.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-BP7ebDFF.js} +1 -1
- package/dist/assets/{WalkthroughView-D9Q4lr5x.js → WalkthroughView-MuJodAHD.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-CZ0xPeaT.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-C9abMBTb.js} +1 -1
- package/dist/assets/de-CEoCz3j6.js +9 -0
- package/dist/assets/es-DwyXCqaL.js +15 -0
- package/dist/assets/{fr-5qJM0nFS.js → fr-CS7Csln9.js} +5 -5
- package/dist/assets/index-CUKcHnUA.css +1 -0
- package/dist/assets/{index-Brm3X9rs.js → index-CaPAjwXQ.js} +1 -1
- package/dist/assets/index-DIvDEKE-.js +7 -0
- package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
- package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-DiLRrkJr.js} +1 -1
- package/dist/assets/ja-vnwqLcx6.js +15 -0
- package/dist/assets/ko-CXuSfZv5.js +15 -0
- package/dist/assets/{main-vUCh0VB0.js → main-D5RWr6sJ.js} +2 -2
- package/dist/assets/main-DLlfDjQ_.js +926 -0
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
- package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-CqR3icsk.js} +2 -2
- package/dist/assets/{mobile-CkX6H-IT.js → mobile-RN_UTTlB.js} +2 -2
- package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-CjRR5ESs.js} +3 -3
- package/dist/assets/pl-BJxry0Mi.js +15 -0
- package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-1wC94fQK.js} +2 -2
- package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
- package/dist/assets/{scheduledTasksApi-CAGPh_gZ.js → scheduledTasksApi-mjMDet_H.js} +1 -1
- package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-fGmFkxAM.js} +1 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
- package/dist/assets/uk-ClgQjmlw.js +15 -0
- package/dist/assets/{useAppFontEffects-Cll4gnsh.js → useAppFontEffects-KP8_yiGW.js} +143 -141
- package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-HIjtuhxD.js} +2 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
- package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/{web-components-DLnGY4fs.js → web-components-DOXvU-tB.js} +1 -1
- package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
- package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/public/site.webmanifest +1 -1
- package/server/index.js +2 -2
- package/server/lib/cloudflare-tunnel.js +1 -1
- package/server/lib/fs/DOCUMENTATION.md +1 -0
- package/server/lib/fs/routes.js +21 -0
- package/server/lib/fs/routes.test.js +89 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- package/server/lib/quota/DOCUMENTATION.md +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- package/server/lib/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
- package/dist/assets/FilesView-DPU8aNPL.js +0 -17
- package/dist/assets/GitView-Ct6xWrVH.js +0 -6
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
- package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
- package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
- package/dist/assets/de-B_LdJwEM.js +0 -9
- package/dist/assets/es-CubfsAYV.js +0 -15
- package/dist/assets/index-BW82eK5v.css +0 -1
- package/dist/assets/index-rlLjZUM5.js +0 -7
- package/dist/assets/ja-DJYIBUlH.js +0 -15
- package/dist/assets/ko-DcUBkB7y.js +0 -15
- package/dist/assets/main-DLBxKIoX.js +0 -926
- package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
- package/dist/assets/pl-rB6BLcio.js +0 -15
- package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
- package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
- package/dist/assets/uk-INZlFD9A.js +0 -15
- package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
- package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
|
@@ -164,6 +164,41 @@ ${desktopReturn ? `<a class="return" href="openchamber://focus/mcp-auth">Return
|
|
|
164
164
|
return versions.sort((left, right) => compareVersions(right, left))[0];
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
+
// OpenCode's `/global/upgrade` requires an explicit semver target and rejects
|
|
168
|
+
// a bodyless call, so "update to the latest" has to name the version. The
|
|
169
|
+
// release lookup is the same one the upgrade-status check already uses to
|
|
170
|
+
// decide there is anything to offer.
|
|
171
|
+
const resolveOpenCodeUpgradeTarget = async (requestedTarget) => {
|
|
172
|
+
if (typeof requestedTarget === 'string' && requestedTarget.trim().length > 0) {
|
|
173
|
+
return { resolved: true, target: requestedTarget.trim() };
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const latest = await fetchLatestOpenCodeVersion();
|
|
177
|
+
if (!latest) {
|
|
178
|
+
return { resolved: false, reason: 'The latest OpenCode version could not be determined.' };
|
|
179
|
+
}
|
|
180
|
+
return { resolved: true, target: latest };
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return {
|
|
183
|
+
resolved: false,
|
|
184
|
+
reason: error instanceof Error ? error.message : 'The latest OpenCode version could not be determined.',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// OpenCode reports a rejected upgrade as `{ name, data: { message, kind } }`,
|
|
190
|
+
// which carries no `error` field. Reading only `error` left the user with the
|
|
191
|
+
// bare HTTP status text ("Bad Request") and nothing to act on.
|
|
192
|
+
const readOpenCodeUpgradeErrorMessage = (payload, response) => {
|
|
193
|
+
const candidates = [payload?.error, payload?.data?.message, payload?.message];
|
|
194
|
+
for (const candidate of candidates) {
|
|
195
|
+
if (typeof candidate === 'string' && candidate.trim().length > 0) {
|
|
196
|
+
return candidate.trim();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return response.statusText || 'Failed to upgrade OpenCode';
|
|
200
|
+
};
|
|
201
|
+
|
|
167
202
|
const pruneExpiredPendingMcpAuthContexts = () => {
|
|
168
203
|
const now = Date.now();
|
|
169
204
|
for (const [state, entry] of pendingMcpAuthContextByState.entries()) {
|
|
@@ -218,10 +253,23 @@ ${desktopReturn ? `<a class="return" href="openchamber://focus/mcp-auth">Return
|
|
|
218
253
|
});
|
|
219
254
|
}
|
|
220
255
|
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
256
|
+
const requestedTarget = req.body?.target;
|
|
257
|
+
// The target lookup reaches the network, so it runs inside the operation:
|
|
258
|
+
// the in-flight lock is taken synchronously above, and a second click
|
|
259
|
+
// cannot slip past while the release version is being resolved.
|
|
224
260
|
const upgradeOperation = (async () => {
|
|
261
|
+
const targetResolution = await resolveOpenCodeUpgradeTarget(requestedTarget);
|
|
262
|
+
if (!targetResolution.resolved) {
|
|
263
|
+
return {
|
|
264
|
+
status: 502,
|
|
265
|
+
body: {
|
|
266
|
+
success: false,
|
|
267
|
+
code: 'OPENCODE_UPGRADE_TARGET_UNRESOLVED',
|
|
268
|
+
error: `Could not determine which OpenCode version to install: ${targetResolution.reason}`,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
225
273
|
const response = await fetch(buildOpenCodeUrl('/global/upgrade', ''), {
|
|
226
274
|
method: 'POST',
|
|
227
275
|
headers: {
|
|
@@ -229,7 +277,7 @@ ${desktopReturn ? `<a class="return" href="openchamber://focus/mcp-auth">Return
|
|
|
229
277
|
Accept: 'application/json',
|
|
230
278
|
...getOpenCodeAuthHeaders(),
|
|
231
279
|
},
|
|
232
|
-
body: JSON.stringify(
|
|
280
|
+
body: JSON.stringify({ target: targetResolution.target }),
|
|
233
281
|
});
|
|
234
282
|
const payload = await response.json().catch(() => null);
|
|
235
283
|
if (!response.ok) {
|
|
@@ -237,7 +285,7 @@ ${desktopReturn ? `<a class="return" href="openchamber://focus/mcp-auth">Return
|
|
|
237
285
|
status: response.status,
|
|
238
286
|
body: {
|
|
239
287
|
success: false,
|
|
240
|
-
error: payload
|
|
288
|
+
error: readOpenCodeUpgradeErrorMessage(payload, response),
|
|
241
289
|
},
|
|
242
290
|
};
|
|
243
291
|
}
|
|
@@ -616,6 +616,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
616
616
|
if (typeof candidate.terminalFontSize === 'number' && Number.isFinite(candidate.terminalFontSize)) {
|
|
617
617
|
result.terminalFontSize = Math.max(9, Math.min(52, Math.round(candidate.terminalFontSize)));
|
|
618
618
|
}
|
|
619
|
+
if (typeof candidate.editorFontSize === 'number' && Number.isFinite(candidate.editorFontSize)) {
|
|
620
|
+
result.editorFontSize = Math.max(9, Math.min(32, Math.round(candidate.editorFontSize)));
|
|
621
|
+
}
|
|
619
622
|
if (typeof candidate.terminalShell === 'string') {
|
|
620
623
|
const shell = candidate.terminalShell.trim().toLowerCase();
|
|
621
624
|
if (TERMINAL_SHELL_VALUES.has(shell)) result.terminalShell = shell;
|
|
@@ -104,6 +104,16 @@ describe('settings helpers', () => {
|
|
|
104
104
|
expect(helpers.sanitizeSettingsUpdate({ collapsibleUserMessages: 'true' })).toEqual({});
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
it('sanitizes and returns the persisted editor font size', () => {
|
|
108
|
+
const helpers = createTestHelpers();
|
|
109
|
+
|
|
110
|
+
expect(helpers.sanitizeSettingsUpdate({ editorFontSize: 20.6 })).toEqual({ editorFontSize: 21 });
|
|
111
|
+
expect(helpers.sanitizeSettingsUpdate({ editorFontSize: 8 })).toEqual({ editorFontSize: 9 });
|
|
112
|
+
expect(helpers.sanitizeSettingsUpdate({ editorFontSize: 33 })).toEqual({ editorFontSize: 32 });
|
|
113
|
+
expect(helpers.sanitizeSettingsUpdate({ editorFontSize: Number.NaN })).toEqual({});
|
|
114
|
+
expect(helpers.formatSettingsResponse({ editorFontSize: 20 })).toMatchObject({ editorFontSize: 20 });
|
|
115
|
+
});
|
|
116
|
+
|
|
107
117
|
it('accepts messageStreamTransport as a persisted shared setting', () => {
|
|
108
118
|
const helpers = createTestHelpers();
|
|
109
119
|
|
|
@@ -116,7 +116,7 @@ export const createThemeRuntime = (dependencies) => {
|
|
|
116
116
|
const seen = new Set();
|
|
117
117
|
|
|
118
118
|
for (const entry of entries) {
|
|
119
|
-
if (!entry.isFile()) continue;
|
|
119
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
120
120
|
if (!entry.name.toLowerCase().endsWith('.json')) continue;
|
|
121
121
|
|
|
122
122
|
const filePath = path.join(themesDir, entry.name);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createThemeRuntime } from './theme-runtime.js';
|
|
4
|
+
|
|
5
|
+
const validTheme = (id = 'custom-theme') => ({
|
|
6
|
+
metadata: {
|
|
7
|
+
id,
|
|
8
|
+
name: 'Custom Theme',
|
|
9
|
+
variant: 'dark',
|
|
10
|
+
},
|
|
11
|
+
colors: {
|
|
12
|
+
primary: {
|
|
13
|
+
base: '#ffffff',
|
|
14
|
+
foreground: '#000000',
|
|
15
|
+
},
|
|
16
|
+
surface: {
|
|
17
|
+
background: '#000000',
|
|
18
|
+
foreground: '#ffffff',
|
|
19
|
+
muted: '#111111',
|
|
20
|
+
mutedForeground: '#eeeeee',
|
|
21
|
+
elevated: '#222222',
|
|
22
|
+
elevatedForeground: '#dddddd',
|
|
23
|
+
subtle: '#333333',
|
|
24
|
+
},
|
|
25
|
+
interactive: {
|
|
26
|
+
border: '#444444',
|
|
27
|
+
selection: '#555555',
|
|
28
|
+
selectionForeground: '#ffffff',
|
|
29
|
+
focusRing: '#666666',
|
|
30
|
+
hover: '#777777',
|
|
31
|
+
},
|
|
32
|
+
status: {
|
|
33
|
+
error: '#ff0000',
|
|
34
|
+
errorForeground: '#ffffff',
|
|
35
|
+
errorBackground: '#330000',
|
|
36
|
+
errorBorder: '#660000',
|
|
37
|
+
warning: '#ffaa00',
|
|
38
|
+
warningForeground: '#000000',
|
|
39
|
+
warningBackground: '#332200',
|
|
40
|
+
warningBorder: '#664400',
|
|
41
|
+
success: '#00ff00',
|
|
42
|
+
successForeground: '#000000',
|
|
43
|
+
successBackground: '#003300',
|
|
44
|
+
successBorder: '#006600',
|
|
45
|
+
info: '#0000ff',
|
|
46
|
+
infoForeground: '#ffffff',
|
|
47
|
+
infoBackground: '#000033',
|
|
48
|
+
infoBorder: '#000066',
|
|
49
|
+
},
|
|
50
|
+
syntax: {
|
|
51
|
+
base: {
|
|
52
|
+
background: '#000000',
|
|
53
|
+
foreground: '#ffffff',
|
|
54
|
+
keyword: '#ff00ff',
|
|
55
|
+
string: '#00ff00',
|
|
56
|
+
number: '#ffaa00',
|
|
57
|
+
function: '#00ffff',
|
|
58
|
+
variable: '#ffffff',
|
|
59
|
+
type: '#ffff00',
|
|
60
|
+
comment: '#888888',
|
|
61
|
+
operator: '#ffffff',
|
|
62
|
+
},
|
|
63
|
+
highlights: {
|
|
64
|
+
diffAdded: '#003300',
|
|
65
|
+
diffRemoved: '#330000',
|
|
66
|
+
lineNumber: '#888888',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const fileEntry = (name, type = 'file') => ({
|
|
73
|
+
name,
|
|
74
|
+
isFile: () => type === 'file',
|
|
75
|
+
isDirectory: () => type === 'directory',
|
|
76
|
+
isSymbolicLink: () => type === 'symlink',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const createTestRuntime = ({ entries, files, stats }) => createThemeRuntime({
|
|
80
|
+
fsPromises: {
|
|
81
|
+
readdir: async () => entries,
|
|
82
|
+
stat: async (filePath) => stats[filePath],
|
|
83
|
+
readFile: async (filePath) => files[filePath],
|
|
84
|
+
},
|
|
85
|
+
path: { join: (...parts) => parts.join('/') },
|
|
86
|
+
themesDir: '/themes',
|
|
87
|
+
maxThemeJsonBytes: 512 * 1024,
|
|
88
|
+
logger: { warn: () => {} },
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('theme runtime', () => {
|
|
92
|
+
describe('readCustomThemesFromDisk', () => {
|
|
93
|
+
it('loads valid theme files', async () => {
|
|
94
|
+
const runtime = createTestRuntime({
|
|
95
|
+
entries: [fileEntry('direct.json')],
|
|
96
|
+
files: { '/themes/direct.json': JSON.stringify(validTheme('direct-theme')) },
|
|
97
|
+
stats: { '/themes/direct.json': { isFile: () => true, size: 1024 } },
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const themes = await runtime.readCustomThemesFromDisk();
|
|
101
|
+
|
|
102
|
+
expect(themes.map((theme) => theme.metadata.id)).toEqual(['direct-theme']);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('loads JSON themes whose directory entry is a symbolic link', async () => {
|
|
106
|
+
const runtime = createTestRuntime({
|
|
107
|
+
entries: [fileEntry('linked.json', 'symlink')],
|
|
108
|
+
files: { '/themes/linked.json': JSON.stringify(validTheme('linked-theme')) },
|
|
109
|
+
stats: { '/themes/linked.json': { isFile: () => true, size: 1024 } },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const themes = await runtime.readCustomThemesFromDisk();
|
|
113
|
+
|
|
114
|
+
expect(themes.map((theme) => theme.metadata.id)).toEqual(['linked-theme']);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('skips JSON directories after stat resolution', async () => {
|
|
118
|
+
const runtime = createTestRuntime({
|
|
119
|
+
entries: [fileEntry('directory.json', 'directory')],
|
|
120
|
+
files: { '/themes/directory.json': JSON.stringify(validTheme('directory-theme')) },
|
|
121
|
+
stats: { '/themes/directory.json': { isFile: () => false, size: 1024 } },
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const themes = await runtime.readCustomThemesFromDisk();
|
|
125
|
+
|
|
126
|
+
expect(themes).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -97,6 +97,25 @@ In 2025/2026 MiniMax rebranded "Coding Plan" to "Token Plan" alongside the M3 mo
|
|
|
97
97
|
|
|
98
98
|
The provider computes `usedPercent` from whichever of `used`/`remaining` is present (`used` takes precedence when both exist) rather than assuming one field name. Both `packages/web/server/lib/quota/providers/kimi.js` and `packages/vscode/src/quotaProviders.ts` (`fetchKimiQuota`) must stay in sync — the VS Code extension duplicates this parsing logic rather than importing it.
|
|
99
99
|
|
|
100
|
+
## GitHub Copilot quota semantics
|
|
101
|
+
|
|
102
|
+
GitHub Copilot usage exposes only the `premium_interactions` snapshot as the
|
|
103
|
+
`premium_interactions` window. Shared UI labels that window **AI Credits** and treats it as
|
|
104
|
+
the provider's primary usage marker. Legacy chat-request quota and unlimited
|
|
105
|
+
completion quota are intentionally omitted. Keep
|
|
106
|
+
`packages/web/server/lib/quota/providers/copilot.js` and
|
|
107
|
+
`packages/vscode/src/quotaProviders.ts` in sync.
|
|
108
|
+
|
|
109
|
+
The `/copilot_internal/user` endpoint is undocumented; its quota semantics mirror
|
|
110
|
+
what `microsoft/vscode-copilot-chat` consumes (`CopilotUserQuotaInfo`). Each
|
|
111
|
+
snapshot carries `entitlement`, `remaining`, `unlimited`, and
|
|
112
|
+
`percent_remaining`. Providers must honor these rules:
|
|
113
|
+
|
|
114
|
+
- `unlimited: true` renders a percent-less window with an "Unlimited" value label.
|
|
115
|
+
- Percent math requires a positive `entitlement`; entitlements of `0`, `-1`, or null are unusable.
|
|
116
|
+
- When entitlement/remaining are unusable, fall back to `100 - percent_remaining`.
|
|
117
|
+
- Snapshots other than `premium_interactions` (legacy annual plans) yield zero windows.
|
|
118
|
+
|
|
100
119
|
## Notes for contributors
|
|
101
120
|
- Keep provider IDs stable; clients use them directly.
|
|
102
121
|
- Avoid adding alias-based dispatch in `fetchQuotaForProvider`; dispatch currently expects exact provider IDs.
|
|
@@ -13,14 +13,35 @@ const buildCopilotWindows = (payload) => {
|
|
|
13
13
|
const resetAt = toTimestamp(payload?.quota_reset_date);
|
|
14
14
|
const windows = {};
|
|
15
15
|
|
|
16
|
+
// Mirrors the quota semantics of microsoft/vscode-copilot-chat
|
|
17
|
+
// (CopilotUserQuotaInfo): each snapshot carries entitlement, remaining,
|
|
18
|
+
// unlimited, and percent_remaining. Unlimited plans report no usable
|
|
19
|
+
// entitlement; percent_remaining is a server-computed fallback.
|
|
16
20
|
const addWindow = (label, snapshot) => {
|
|
17
21
|
if (!snapshot) return;
|
|
22
|
+
|
|
23
|
+
if (snapshot.unlimited === true) {
|
|
24
|
+
windows[label] = toUsageWindow({
|
|
25
|
+
usedPercent: null,
|
|
26
|
+
windowSeconds: null,
|
|
27
|
+
resetAt,
|
|
28
|
+
valueLabel: 'Unlimited'
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
const entitlement = toNumber(snapshot.entitlement);
|
|
19
34
|
const remaining = toNumber(snapshot.remaining);
|
|
20
|
-
|
|
21
|
-
? Math.max(0, 100 - (remaining / entitlement) * 100)
|
|
35
|
+
let usedPercent = entitlement !== null && entitlement > 0 && remaining !== null
|
|
36
|
+
? Math.min(100, Math.max(0, 100 - (remaining / entitlement) * 100))
|
|
22
37
|
: null;
|
|
23
|
-
|
|
38
|
+
if (usedPercent === null) {
|
|
39
|
+
const percentRemaining = toNumber(snapshot.percent_remaining);
|
|
40
|
+
if (percentRemaining !== null) {
|
|
41
|
+
usedPercent = Math.min(100, Math.max(0, 100 - percentRemaining));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const valueLabel = entitlement !== null && entitlement > 0 && remaining !== null
|
|
24
45
|
? `${remaining.toFixed(0)} / ${entitlement.toFixed(0)} left`
|
|
25
46
|
: null;
|
|
26
47
|
windows[label] = toUsageWindow({
|
|
@@ -31,9 +52,7 @@ const buildCopilotWindows = (payload) => {
|
|
|
31
52
|
});
|
|
32
53
|
};
|
|
33
54
|
|
|
34
|
-
addWindow('
|
|
35
|
-
addWindow('completions', quota.completions);
|
|
36
|
-
addWindow('premium', quota.premium_interactions);
|
|
55
|
+
addWindow('premium_interactions', quota.premium_interactions);
|
|
37
56
|
|
|
38
57
|
return windows;
|
|
39
58
|
};
|
|
@@ -143,15 +162,12 @@ export const fetchQuotaAddon = async () => {
|
|
|
143
162
|
}
|
|
144
163
|
|
|
145
164
|
const payload = await response.json();
|
|
146
|
-
const windows = buildCopilotWindows(payload);
|
|
147
|
-
const premium = windows.premium ? { premium: windows.premium } : windows;
|
|
148
|
-
|
|
149
165
|
return buildResult({
|
|
150
166
|
providerId: providerIdAddon,
|
|
151
167
|
providerName: providerNameAddon,
|
|
152
168
|
ok: true,
|
|
153
169
|
configured: true,
|
|
154
|
-
usage: { windows:
|
|
170
|
+
usage: { windows: buildCopilotWindows(payload) }
|
|
155
171
|
});
|
|
156
172
|
} catch (error) {
|
|
157
173
|
return buildResult({
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('../../opencode/auth.js', () => ({
|
|
4
|
+
readAuthFile: () => ({ 'github-copilot': { access: 'test-token' } }),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
import { fetchQuota, fetchQuotaAddon } from './copilot.js';
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const payload = {
|
|
14
|
+
quota_reset_date: '2026-09-01T00:00:00Z',
|
|
15
|
+
quota_snapshots: {
|
|
16
|
+
chat: { entitlement: 100, remaining: 80 },
|
|
17
|
+
completions: { entitlement: 1000, remaining: 900 },
|
|
18
|
+
premium_interactions: { entitlement: 300, remaining: 225 },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const mockResponse = (body = payload) => ({
|
|
23
|
+
ok: true,
|
|
24
|
+
status: 200,
|
|
25
|
+
json: async () => body,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('GitHub Copilot quota provider', () => {
|
|
29
|
+
it.each([
|
|
30
|
+
['primary provider', fetchQuota],
|
|
31
|
+
['add-on provider', fetchQuotaAddon],
|
|
32
|
+
])('exposes only premium interactions for the %s', async (_name, fetchProviderQuota) => {
|
|
33
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse()));
|
|
34
|
+
|
|
35
|
+
const result = await fetchProviderQuota();
|
|
36
|
+
|
|
37
|
+
expect(result.ok).toBe(true);
|
|
38
|
+
expect(Object.keys(result.usage.windows)).toEqual(['premium_interactions']);
|
|
39
|
+
expect(result.usage.windows.premium_interactions.usedPercent).toBe(25);
|
|
40
|
+
expect(result.usage.windows.premium_interactions.valueLabel).toBe('225 / 300 left');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it.each([
|
|
44
|
+
['primary provider', fetchQuota],
|
|
45
|
+
['add-on provider', fetchQuotaAddon],
|
|
46
|
+
])('reports unlimited plans without a percent for the %s', async (_name, fetchProviderQuota) => {
|
|
47
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
48
|
+
quota_reset_date: '2026-09-01T00:00:00Z',
|
|
49
|
+
quota_snapshots: {
|
|
50
|
+
premium_interactions: { unlimited: true, entitlement: -1, remaining: -1 },
|
|
51
|
+
},
|
|
52
|
+
})));
|
|
53
|
+
|
|
54
|
+
const result = await fetchProviderQuota();
|
|
55
|
+
|
|
56
|
+
expect(result.ok).toBe(true);
|
|
57
|
+
expect(result.usage.windows.premium_interactions.usedPercent).toBeNull();
|
|
58
|
+
expect(result.usage.windows.premium_interactions.valueLabel).toBe('Unlimited');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it.each([
|
|
62
|
+
['primary provider', fetchQuota],
|
|
63
|
+
['add-on provider', fetchQuotaAddon],
|
|
64
|
+
])('falls back to percent_remaining when entitlement is unusable for the %s', async (_name, fetchProviderQuota) => {
|
|
65
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
66
|
+
quota_reset_date: '2026-09-01T00:00:00Z',
|
|
67
|
+
quota_snapshots: {
|
|
68
|
+
premium_interactions: { entitlement: 0, remaining: 0, percent_remaining: 75.5 },
|
|
69
|
+
},
|
|
70
|
+
})));
|
|
71
|
+
|
|
72
|
+
const result = await fetchProviderQuota();
|
|
73
|
+
|
|
74
|
+
expect(result.ok).toBe(true);
|
|
75
|
+
expect(result.usage.windows.premium_interactions.usedPercent).toBeCloseTo(24.5);
|
|
76
|
+
expect(result.usage.windows.premium_interactions.valueLabel ?? null).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -103,18 +103,24 @@ other runtime API.
|
|
|
103
103
|
`https://chatgpt.com/backend-api/codex/responses` with
|
|
104
104
|
`ChatGPT-Account-Id`; expired tokens are refreshed against
|
|
105
105
|
`auth.openai.com` (single-flight) and written back to `auth.json`.
|
|
106
|
-
- **Anthropic** (`type: api`): `/
|
|
106
|
+
- **Anthropic** (`type: api`): `/messages` with `x-api-key`, against
|
|
107
|
+
`provider.anthropic.options.baseURL` when configured (used as-is, matching
|
|
108
|
+
`@ai-sdk/anthropic` — no `/v1` is inserted) or `https://api.anthropic.com/v1`
|
|
109
|
+
otherwise.
|
|
107
110
|
- **Google** (`type: api`): `generateContent` with `x-goog-api-key`; Gemini 3
|
|
108
|
-
uses `thinkingLevel
|
|
111
|
+
uses `thinkingLevel`, Gemini 2.x uses `thinkingBudget: 0`, and all other
|
|
112
|
+
models omit `thinkingConfig` entirely.
|
|
109
113
|
- Everything else: OpenAI-compatible `/chat/completions` against the
|
|
110
114
|
provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
|
|
111
115
|
in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
|
|
112
116
|
endpoint, (3) the endpoint OpenCode resolved at runtime, or (4) the
|
|
113
117
|
provider's `api` field from the models.dev catalog. The credential follows
|
|
114
118
|
the same shape: config `options.apiKey`, then the runtime credential, then
|
|
115
|
-
the auth.json entry.
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
the auth.json entry. `provider.<id>.options.headers` is sent with the
|
|
120
|
+
request and overrides the bearer default, so gateways that authenticate on
|
|
121
|
+
their own header work here exactly as they do in a chat turn. Configured API
|
|
122
|
+
keys and header values honor OpenCode's `{env:NAME}` and `{file:path}`
|
|
123
|
+
substitutions; file contents and resolved credentials remain server-side.
|
|
118
124
|
- The runtime credential is refused for providers listed in
|
|
119
125
|
`OWN_CREDENTIAL_HANDLING`. Their branches need the stored entry rather than
|
|
120
126
|
a bearer token: the clearest case is the ChatGPT-plan `openai` login, whose
|
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readAuthFile, writeAuthFile } from '../opencode/auth.js';
|
|
5
|
-
import { readConfig, readConfigLayers } from '../opencode/shared.js';
|
|
5
|
+
import { readConfig, readConfigLayers, isPlainObject } from '../opencode/shared.js';
|
|
6
6
|
import { getCatalogProvider } from './catalog.js';
|
|
7
7
|
import { getAuthEntryForProvider } from './resolve.js';
|
|
8
8
|
import { getRuntimeProvider } from './runtime-providers.js';
|
|
@@ -19,6 +19,18 @@ const DEFAULT_MAX_OUTPUT_TOKENS = 4_000;
|
|
|
19
19
|
|
|
20
20
|
const USER_AGENT = 'opencode/1.0 openchamber';
|
|
21
21
|
|
|
22
|
+
const mergeHeadersCaseInsensitive = (base, overrides) => {
|
|
23
|
+
const merged = { ...base };
|
|
24
|
+
for (const [name, value] of Object.entries(overrides || {})) {
|
|
25
|
+
const existingName = Object.keys(merged).find((key) => key.toLowerCase() === name.toLowerCase());
|
|
26
|
+
if (existingName) {
|
|
27
|
+
delete merged[existingName];
|
|
28
|
+
}
|
|
29
|
+
merged[name] = value;
|
|
30
|
+
}
|
|
31
|
+
return merged;
|
|
32
|
+
};
|
|
33
|
+
|
|
22
34
|
const CODEX_TOKEN_URL = 'https://auth.openai.com/oauth/token';
|
|
23
35
|
const CODEX_CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';
|
|
24
36
|
const CODEX_RESPONSES_URL = 'https://chatgpt.com/backend-api/codex/responses';
|
|
@@ -157,11 +169,10 @@ const callOpenaiCompatible = async ({ baseURL, headers, modelID, prompt, system,
|
|
|
157
169
|
});
|
|
158
170
|
const response = await fetch(`${trimmedBase}/chat/completions`, {
|
|
159
171
|
method: 'POST',
|
|
160
|
-
headers: {
|
|
172
|
+
headers: mergeHeadersCaseInsensitive({
|
|
161
173
|
'Content-Type': 'application/json',
|
|
162
174
|
Accept: 'application/json',
|
|
163
|
-
|
|
164
|
-
},
|
|
175
|
+
}, headers),
|
|
165
176
|
body: JSON.stringify({
|
|
166
177
|
model: modelID,
|
|
167
178
|
messages: [
|
|
@@ -340,8 +351,11 @@ const callMessages = async ({ url, headers, modelID, prompt, system, maxOutputTo
|
|
|
340
351
|
return text;
|
|
341
352
|
};
|
|
342
353
|
|
|
343
|
-
const callAnthropic = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
|
|
344
|
-
|
|
354
|
+
const callAnthropic = async ({ apiKey, baseURL, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
|
|
355
|
+
// Matches @ai-sdk/anthropic: baseURL is the full API prefix (commonly
|
|
356
|
+
// already ending in /v1), so it gets /messages appended as-is rather than
|
|
357
|
+
// having /v1/messages appended, which would double up a configured /v1.
|
|
358
|
+
url: `${(baseURL || 'https://api.anthropic.com/v1').replace(/\/+$/, '')}/messages`,
|
|
345
359
|
headers: {
|
|
346
360
|
'x-api-key': apiKey,
|
|
347
361
|
'anthropic-version': '2023-06-01',
|
|
@@ -403,9 +417,10 @@ const getCopilotEndpoint = async ({ baseURL, headers, modelID }) => {
|
|
|
403
417
|
|
|
404
418
|
const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => {
|
|
405
419
|
const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(modelID)}:generateContent`;
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
420
|
+
const lowerModelID = modelID.toLowerCase();
|
|
421
|
+
const thinkingConfig = lowerModelID.startsWith('gemini-3')
|
|
422
|
+
? { thinkingLevel: lowerModelID.includes('flash') ? 'minimal' : 'low' }
|
|
423
|
+
: lowerModelID.startsWith('gemini-2') ? { thinkingBudget: 0 } : null;
|
|
409
424
|
const response = await fetch(url, {
|
|
410
425
|
method: 'POST',
|
|
411
426
|
headers: {
|
|
@@ -415,13 +430,11 @@ const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, re
|
|
|
415
430
|
},
|
|
416
431
|
body: JSON.stringify({
|
|
417
432
|
contents: [{ role: 'user', parts: [{ text: prompt }] }],
|
|
418
|
-
...(system
|
|
433
|
+
...(system && { systemInstruction: { parts: [{ text: system }] } }),
|
|
419
434
|
generationConfig: {
|
|
420
435
|
maxOutputTokens,
|
|
421
|
-
thinkingConfig,
|
|
422
|
-
...(responseSchema
|
|
423
|
-
? { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }
|
|
424
|
-
: {}),
|
|
436
|
+
...(thinkingConfig && { thinkingConfig }),
|
|
437
|
+
...(responseSchema && { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }),
|
|
425
438
|
},
|
|
426
439
|
}),
|
|
427
440
|
signal: requestSignal(timeoutMs, signal),
|
|
@@ -508,7 +521,7 @@ const callCodexResponses = async ({ accessToken, accountId, modelID, prompt, sys
|
|
|
508
521
|
// Custom provider configuration support
|
|
509
522
|
// ---------------------------------------------------------------------------
|
|
510
523
|
|
|
511
|
-
const
|
|
524
|
+
const resolveConfigValue = (value, workingDirectory, providerID, headerName = null) => {
|
|
512
525
|
const envMatch = value.match(/^\{env:([^}]+)\}$/i);
|
|
513
526
|
if (envMatch) {
|
|
514
527
|
return process.env[envMatch[1].trim()]?.trim() || null;
|
|
@@ -529,7 +542,12 @@ const resolveConfigApiKey = (value, workingDirectory, providerID) => {
|
|
|
529
542
|
{ config: layers.customConfig, filePath: layers.paths.customPath },
|
|
530
543
|
{ config: layers.projectConfig, filePath: layers.paths.projectPath },
|
|
531
544
|
{ config: layers.userConfig, filePath: layers.paths.userPath },
|
|
532
|
-
].find(({ config }) =>
|
|
545
|
+
].find(({ config }) => {
|
|
546
|
+
const options = config?.provider?.[providerID]?.options;
|
|
547
|
+
return headerName
|
|
548
|
+
? options?.headers?.[headerName] === value
|
|
549
|
+
: options?.apiKey === value;
|
|
550
|
+
});
|
|
533
551
|
resolvedPath = path.resolve(source?.filePath ? path.dirname(source.filePath) : workingDirectory || process.cwd(), configuredPath);
|
|
534
552
|
}
|
|
535
553
|
|
|
@@ -538,10 +556,33 @@ const resolveConfigApiKey = (value, workingDirectory, providerID) => {
|
|
|
538
556
|
if (!key) throw new Error('empty file');
|
|
539
557
|
return key;
|
|
540
558
|
} catch {
|
|
541
|
-
throw new Error(`Failed to resolve configured apiKey file for provider "${providerID}"`);
|
|
559
|
+
throw new Error(`Failed to resolve configured ${headerName ? `header "${headerName}"` : 'apiKey'} file for provider "${providerID}"`);
|
|
542
560
|
}
|
|
543
561
|
};
|
|
544
562
|
|
|
563
|
+
/**
|
|
564
|
+
* `options.headers` from the provider config, with the same `{env:…}`/`{file:…}`
|
|
565
|
+
* substitutions the API key gets.
|
|
566
|
+
*
|
|
567
|
+
* OpenCode sends these on every request, so dropping them here would have the
|
|
568
|
+
* small model authenticating differently from the request path against the same
|
|
569
|
+
* URL. Gateways fronted by an API-management layer reject a bearer-only request
|
|
570
|
+
* outright, because the header is the credential rather than a supplement to it.
|
|
571
|
+
*/
|
|
572
|
+
const readConfiguredHeaders = (providerCfg, workingDirectory, providerID) => {
|
|
573
|
+
const configured = providerCfg?.options?.headers;
|
|
574
|
+
if (!isPlainObject(configured)) return null;
|
|
575
|
+
const headers = {};
|
|
576
|
+
for (const [name, value] of Object.entries(configured)) {
|
|
577
|
+
// Config headers are strings; a malformed entry is skipped rather than
|
|
578
|
+
// stringified into a header the gateway would reject.
|
|
579
|
+
if (String(value) !== value) continue;
|
|
580
|
+
const resolved = resolveConfigValue(value.trim(), workingDirectory, providerID, name);
|
|
581
|
+
if (resolved) headers[name] = resolved;
|
|
582
|
+
}
|
|
583
|
+
return Object.keys(headers).length ? headers : null;
|
|
584
|
+
};
|
|
585
|
+
|
|
545
586
|
const readProviderConfig = (workingDirectory, providerID) => {
|
|
546
587
|
try {
|
|
547
588
|
const config = readConfig(workingDirectory);
|
|
@@ -549,9 +590,10 @@ const readProviderConfig = (workingDirectory, providerID) => {
|
|
|
549
590
|
if (!providerCfg || typeof providerCfg !== 'object') return null;
|
|
550
591
|
const baseURL = typeof providerCfg?.options?.baseURL === 'string' ? providerCfg.options.baseURL.trim() : null;
|
|
551
592
|
const rawApiKey = typeof providerCfg?.options?.apiKey === 'string' ? providerCfg.options.apiKey.trim() : null;
|
|
552
|
-
const apiKey = rawApiKey ?
|
|
593
|
+
const apiKey = rawApiKey ? resolveConfigValue(rawApiKey, workingDirectory, providerID) : null;
|
|
553
594
|
return {
|
|
554
595
|
baseURL,
|
|
596
|
+
headers: readConfiguredHeaders(providerCfg, workingDirectory, providerID),
|
|
555
597
|
// Shape the config-supplied key as a regular api-key auth entry so it
|
|
556
598
|
// can win the precedence check below and flow through the dispatch's
|
|
557
599
|
// `entry.type === 'api' ? entry.key : ...` branch unchanged.
|
|
@@ -706,7 +748,7 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
|
|
|
706
748
|
}
|
|
707
749
|
|
|
708
750
|
if (providerID === 'anthropic') {
|
|
709
|
-
return callAnthropic({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
|
|
751
|
+
return callAnthropic({ apiKey, baseURL: providerConfig?.baseURL, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
|
|
710
752
|
}
|
|
711
753
|
if (providerID === 'google') {
|
|
712
754
|
return callGoogle({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
|
|
@@ -751,7 +793,9 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
|
|
|
751
793
|
|
|
752
794
|
return callOpenaiCompatible({
|
|
753
795
|
baseURL,
|
|
754
|
-
headers:
|
|
796
|
+
// Configured headers last: a gateway that authenticates on its own header
|
|
797
|
+
// must be able to override the bearer default rather than sit beside it.
|
|
798
|
+
headers: mergeHeadersCaseInsensitive({ Authorization: `Bearer ${apiKey}` }, providerConfig?.headers),
|
|
755
799
|
modelID,
|
|
756
800
|
prompt,
|
|
757
801
|
system,
|