* Resolves a Vertex AI OAuth credential to an access token
(requestId: string, credentialId: string)
| 416 | * Resolves a Vertex AI OAuth credential to an access token |
| 417 | */ |
| 418 | async function resolveVertexCredential(requestId: string, credentialId: string): Promise<string> { |
| 419 | logger.info(`[${requestId}] Resolving Vertex AI credential: ${credentialId}`) |
| 420 | |
| 421 | const resolved = await resolveOAuthAccountId(credentialId) |
| 422 | if (!resolved) { |
| 423 | throw new Error(`Vertex AI credential not found: ${credentialId}`) |
| 424 | } |
| 425 | |
| 426 | if (resolved.credentialType === 'service_account' && resolved.credentialId) { |
| 427 | const accessToken = await getServiceAccountToken(resolved.credentialId, [ |
| 428 | 'https://www.googleapis.com/auth/cloud-platform', |
| 429 | ]) |
| 430 | logger.info(`[${requestId}] Successfully resolved Vertex AI service account credential`) |
| 431 | return accessToken |
| 432 | } |
| 433 | |
| 434 | const credential = await db.query.account.findFirst({ |
| 435 | where: eq(account.id, resolved.accountId), |
| 436 | }) |
| 437 | |
| 438 | if (!credential) { |
| 439 | throw new Error(`Vertex AI credential not found: ${credentialId}`) |
| 440 | } |
| 441 | |
| 442 | const { accessToken } = await refreshTokenIfNeeded(requestId, credential, resolved.accountId) |
| 443 | |
| 444 | if (!accessToken) { |
| 445 | throw new Error('Failed to get Vertex AI access token') |
| 446 | } |
| 447 | |
| 448 | logger.info(`[${requestId}] Successfully resolved Vertex AI credential`) |
| 449 | return accessToken |
| 450 | } |
no test coverage detected