MCPcopy Index your code
hub / github.com/simstudioai/sim / resolveVertexCredential

Function resolveVertexCredential

apps/sim/app/api/providers/route.ts:418–450  ·  view source on GitHub ↗

* Resolves a Vertex AI OAuth credential to an access token

(requestId: string, credentialId: string)

Source from the content-addressed store, hash-verified

416 * Resolves a Vertex AI OAuth credential to an access token
417 */
418async 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}

Callers 1

route.tsFile · 0.70

Calls 5

resolveOAuthAccountIdFunction · 0.90
getServiceAccountTokenFunction · 0.90
refreshTokenIfNeededFunction · 0.90
infoMethod · 0.80
eqFunction · 0.50

Tested by

no test coverage detected