From d6b208342edf97bafa5b1dcc986b782f9879d141 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 21 May 2026 17:30:08 +0900 Subject: feat: SQLite database for all credentials, keys, wake schedule, and usage cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add SQLite database at ~/.local/share/dispatch/dispatch.db with tables: credentials, api_keys, wake_schedule, usage_cache - Store Claude OAuth credentials in DB with import button in Model Status UI - Store OpenCode/Copilot API keys in DB with paste-to-import modal - Store OpenCode cookie and workspace IDs in DB - Migrate wake schedule from .wake-schedule.json to DB - Migrate usage cache from in-memory Map + localStorage to DB - Remove all env var and file fallbacks — DB is the single source of truth - Add seed scripts: bin/import-credentials.ts, bin/seed-opencode-keys.ts - Docker: container runs as host UID/GID with matching home directory - Clean up dispatch.toml: remove env fields, update comments - Progress bar time markers for usage cycle tracking --- packages/core/src/credentials/opencode.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'packages/core/src/credentials/opencode.ts') diff --git a/packages/core/src/credentials/opencode.ts b/packages/core/src/credentials/opencode.ts index 7a74486..b8a9d4d 100644 --- a/packages/core/src/credentials/opencode.ts +++ b/packages/core/src/credentials/opencode.ts @@ -1,3 +1,5 @@ +import { resolveApiKey } from "./api-keys.js"; + // ─── OpenCode Usage Tracking ────────────────────────────────── // OpenCode has no public usage API. We scrape usage from the // SolidStart SSR-rendered workspace page using a session cookie. @@ -16,14 +18,14 @@ export interface OpencodeUsageReport { } function getWorkspaceId(keyId: string): string | undefined { - // Match ai-usage convention: opencode-1 → OPENCODE_WS1_ID, opencode-2 → OPENCODE_WS2_ID + // Check DB for workspace ID: stored as "opencode-ws1", "opencode-ws2", or "opencode-ws" const match = keyId.match(/opencode-(\d+)$/i); if (match) { const num = match[1]; - const specific = process.env[`OPENCODE_WS${num}_ID`]; + const specific = resolveApiKey(`opencode-ws${num}`); if (specific) return specific; } - return process.env.OPENCODE_WS_ID; + return resolveApiKey("opencode-ws") ?? undefined; } function parseOcDouble(html: string, key: string): number { @@ -71,7 +73,7 @@ function parseOcBucket( export async function fetchOpencodeUsage( keyId: string, ): Promise { - const cookie = process.env.OPENCODE_COOKIE; + const cookie = resolveApiKey("opencode-cookie"); const wsId = getWorkspaceId(keyId); if (!cookie || !wsId) { -- cgit v1.2.3