From 3819ab71ca570ecfbc4a71e896957c4902c7f823 Mon Sep 17 00:00:00 2001 From: Hotakus Date: Fri, 25 Sep 2026 18:40:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(v2):=20=E4=BF=AE=E5=A4=8D=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=BB=E5=8F=96=E5=AE=BF=E4=B8=BB=20SQLite?= =?UTF-8?q?=20=E5=87=AD=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/v2/commands.ts | 2 ++ src/v2/credentials.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/v2/commands.ts b/src/v2/commands.ts index 33c52e0..7fff50f 100644 --- a/src/v2/commands.ts +++ b/src/v2/commands.ts @@ -32,6 +32,8 @@ export function findOpencodeKeyV2(context: Context, provider: BalanceProvider): if (k) return k const optionKey = typeof hit.options?.apiKey === "string" ? hit.options.apiKey : "" if (optionKey) return optionKey + // 用 OpenCode provider 的 integration_id 去查 SQLite(而非 balance provider id) + if (hit.id) return resolveCredentialToken(hit.id) } } catch { /* fall through to stored credentials */ } return resolveCredentialToken(provider.id) diff --git a/src/v2/credentials.ts b/src/v2/credentials.ts index ead9912..2f24a0c 100644 --- a/src/v2/credentials.ts +++ b/src/v2/credentials.ts @@ -93,7 +93,7 @@ export function readDbCredential(integrationId: string): CredentialValue | undef if (!db || !integrationId) return undefined try { const row = db.query( - "SELECT value FROM credential WHERE integration_id = ? AND active = 1 ORDER BY time_updated DESC LIMIT 1", + "SELECT value FROM credential WHERE integration_id = ? AND active IS NOT 0 ORDER BY time_updated DESC LIMIT 1", ).get(integrationId) return parseCredentialValue(row?.value) } catch { @@ -125,11 +125,11 @@ export function readAuthJsonCredential(providerID: string): CredentialValue | un return undefined } -/** 凭据 → 余额查询 token(oauth 用 access,api 用 key)。 */ +/** 凭据 → 余额查询 token(oauth 用 access,api/key 用 key)。 */ export function credentialToken(value: CredentialValue | undefined): string { if (!value) return "" if (value.type === "oauth" && typeof value.access === "string") return value.access - if (value.type === "api" && typeof value.key === "string") return value.key + if ((value.type === "api" || value.type === "key") && typeof value.key === "string") return value.key return "" }