/** * Extract a Bearer token from Pi's stored Credential shape. */ import type { Credential } from "@earendil-works/pi-ai"; export function accessTokenFromCredential( credential: Credential | undefined, ): string | undefined { if (!credential) return undefined; if (credential.type === "oauth") { const access = credential.access?.trim(); return access || undefined; } if (credential.type === "api_key") { const key = credential.key?.trim(); return key || undefined; } return undefined; }