Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/v2/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/v2/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ""
}

Expand Down
Loading