fix: identify OpenCode Go requests by session
This commit is contained in:
@@ -11,7 +11,7 @@ const toWindow = (usedPercent: number, resetAt: string) => ({
|
||||
});
|
||||
|
||||
export const fetchOpenCodeGoUsage = async (credential: OpenCodeGoCredential) => {
|
||||
const response = await fetch('https://opencode.ai/zen/go/v1/usage', { headers: { Accept: 'application/json', Authorization: `Bearer ${credential.apiKey}` }, signal: AbortSignal.timeout(15_000) });
|
||||
const response = await fetch('https://opencode.ai/zen/go/v1/usage', { headers: { Accept: 'application/json', Authorization: `Bearer ${credential.apiKey}`, 'x-opencode-session': 'openchamber-usage' }, signal: AbortSignal.timeout(15_000) });
|
||||
if (response.status === 401 || response.status === 403 || (response.status >= 300 && response.status < 400)) throw new Error('OpenCode Go authentication failed');
|
||||
if (!response.ok) throw new Error(`OpenCode Go usage API returned HTTP ${response.status}`);
|
||||
const payload = await response.json().catch(() => null) as { usage?: Record<string, { percent?: unknown; resetsAt?: unknown }> } | null;
|
||||
|
||||
@@ -99,6 +99,7 @@ describe('OpenCode Go quota provider (VS Code parity)', () => {
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal((request?.headers as Record<string, string>).Authorization, 'Bearer test-token');
|
||||
assert.equal((request?.headers as Record<string, string>)['x-opencode-session'], 'openchamber-usage');
|
||||
assert.equal(result.usage!.windows['5h']!.usedPercent, 25);
|
||||
assert.throws(() => fs.statSync(legacyPath));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user