feat(quota): add OpenCode Go usage tracking (#2155)

* feat(quota): add OpenCode Go usage tracking

* fix(quota): align OpenCode Go VS Code parsing
This commit is contained in:
Bohdan Triapitsyn
2026-07-12 14:48:50 +03:00
committed by GitHub
parent b4f50e0a01
commit 3d90eddcaf
26 changed files with 658 additions and 1 deletions
@@ -6,6 +6,7 @@ import { randomUUID } from 'crypto';
import { removeProviderConfig, getProviderSources } from './opencodeConfig';
import { getProviderAuth, removeProviderAuth } from './opencodeAuth';
import { fetchQuotaForProvider, listConfiguredQuotaProviders } from './quotaProviders';
import { deleteOpenCodeGoCredential, fetchOpenCodeGoUsage, getOpenCodeGoCredentialStatus, normalizeOpenCodeGoCredential, readOpenCodeGoCredential, writeOpenCodeGoCredential } from './opencodeGoQuota';
import { getSessionActivitySnapshot } from './sessionActivityWatcher';
import type { BridgeContext, BridgeResponse } from './bridge';
@@ -481,6 +482,29 @@ export async function handleSystemBridgeMessage(
}
}
case 'api:quota:opencode-go-credentials': {
const { method, credential: input } = (payload || {}) as { method?: string; credential?: unknown };
try {
if (method === 'GET') return { id, type, success: true, data: getOpenCodeGoCredentialStatus() };
if (method === 'DELETE') { deleteOpenCodeGoCredential(); return { id, type, success: true, data: { configured: false } }; }
if (method === 'PUT') {
const credential = normalizeOpenCodeGoCredential(input);
if (!credential) return { id, type, success: false, error: 'Workspace ID and auth cookie are required' };
await fetchOpenCodeGoUsage(credential);
return { id, type, success: true, data: writeOpenCodeGoCredential(credential) };
}
if (method === 'VALIDATE') {
const credential = readOpenCodeGoCredential();
if (!credential) return { id, type, success: false, error: 'Not configured' };
await fetchOpenCodeGoUsage(credential);
return { id, type, success: true, data: { valid: true } };
}
return { id, type, success: false, error: 'Unsupported method' };
} catch (error) {
return { id, type, success: false, error: error instanceof Error ? error.message : String(error) };
}
}
case 'api:quota:get': {
const { providerId } = (payload || {}) as { providerId?: string };
if (!providerId) {