feat: switch OpenCode Go usage to API

OpenCode Go now reads quota usage with a bearer API key from OpenCode auth.json
Removes the old workspace ID and browser cookie credential flow
Deletes legacy OpenCode Go credential files during upgrade
This commit is contained in:
Bohdan Triapitsyn
2026-08-12 01:49:22 +03:00
parent d1224213ca
commit 5917325d49
29 changed files with 192 additions and 182 deletions
+3 -6
View File
@@ -6,7 +6,6 @@ import { randomUUID } from 'crypto';
import { removeProviderConfig, getProviderSources, upsertProviderConfig } from './opencodeConfig';
import { getProviderAuth, removeProviderAuth } from './opencodeAuth';
import { fetchQuotaForProvider, listConfiguredQuotaProviders } from './quotaProviders';
import { fetchOpenCodeGoUsage } from './opencodeGoQuota';
import { credentialStatus, deleteCredential, importCursorCredential, normalizeCredential, readCredential, validateCredential, writeCredential, type ManagedProvider } from './quotaCredentials';
import { getSessionActivitySnapshot } from './sessionActivityWatcher';
import { getOpenCodeUpgradeStatus, upgradeManagedOpenCode } from './opencode-upgrade-runtime';
@@ -554,7 +553,7 @@ export async function handleSystemBridgeMessage(
case 'api:quota:credentials': {
const { providerId, method, credential: input } = (payload || {}) as { providerId?: ManagedProvider; method?: string; credential?: unknown };
try {
if (!providerId || !['opencode-go', 'ollama-cloud', 'cursor'].includes(providerId)) return { id, type, success: false, error: 'Unsupported credential provider' };
if (!providerId || !['ollama-cloud', 'cursor'].includes(providerId)) return { id, type, success: false, error: 'Unsupported credential provider' };
if (method === 'GET') return { id, type, success: true, data: credentialStatus(providerId) };
if (method === 'DELETE') { deleteCredential(providerId); return { id, type, success: true, data: { configured: false } }; }
if (method === 'IMPORT') {
@@ -566,15 +565,13 @@ export async function handleSystemBridgeMessage(
if (method === 'PUT') {
const credential = normalizeCredential(providerId, input);
if (!credential) return { id, type, success: false, error: 'Invalid credential' };
if (providerId === 'opencode-go') await fetchOpenCodeGoUsage(credential as { workspaceId: string; authCookie: string });
else await validateCredential(providerId, credential);
await validateCredential(providerId, credential);
return { id, type, success: true, data: writeCredential(providerId, credential) };
}
if (method === 'VALIDATE') {
const credential = readCredential(providerId);
if (!credential) return { id, type, success: false, error: 'Not configured' };
if (providerId === 'opencode-go') await fetchOpenCodeGoUsage(credential as { workspaceId: string; authCookie: string });
else await validateCredential(providerId, credential);
await validateCredential(providerId, credential);
return { id, type, success: true, data: { valid: true } };
}
return { id, type, success: false, error: 'Unsupported method' };