fix: support multi-account auth entries when resolving discovery token
38 unmodified lines39404142434445464748495051525354464748495055565758596061626364656628 unmodified lines38 unmodified lines } return join(homedir(), ".prime", "agent");}
interface StoredCredential { type?: string; access?: string;}
/** * auth.json stores a bare credential per provider, or an array once more than * one account is logged in (multi-account credential pooling). */function readExistingAccessToken(): string | undefined { try { const authPath = join(getAgentDir(), "auth.json"); const auth = JSON.parse(readFileSync(authPath, "utf-8")) as Record<string, { type?: string; access?: string }>; const entry = auth[PROVIDER_ID]; if (entry?.type === "oauth" && typeof entry.access === "string" && entry.access.length > 0) { return entry.access; } const auth = JSON.parse(readFileSync(authPath, "utf-8")) as Record<string, StoredCredential | StoredCredential[]>; const stored = auth[PROVIDER_ID]; const credentials = Array.isArray(stored) ? stored : [stored]; const entry = credentials.find( (credential) => credential?.type === "oauth" && typeof credential.access === "string" && credential.access.length > 0, ); if (entry) return entry.access; } catch { // No auth file or not logged in yet. } return undefined;28 unmodified lines28 unmodified lines2930313233343435363738353637383940414243444544464748495033 unmodified lines28 unmodified lines console.error("Available:", STATIC_PROVIDER_MODELS.map((m) => m.id).join(", ")); process.exit(1); }
type Credential = { type?: string; access?: string; projectId?: string }; const authPath = join(getAgentDir(), "auth.json"); const auth = JSON.parse(readFileSync(authPath, "utf-8")) as Record< string, { type?: string; access?: string; projectId?: string } >; const access = auth["google-antigravity"]?.access; const auth = JSON.parse(readFileSync(authPath, "utf-8")) as Record<string, Credential | Credential[]>; const stored = auth["google-antigravity"]; const credential = (Array.isArray(stored) ? stored : [stored]).find( (entry) => entry?.type === "oauth" && typeof entry.access === "string" && entry.access.length > 0, ); const access = credential?.access; if (!access) { console.error("No google-antigravity credentials. Run /login google-antigravity first."); process.exit(1); }
const apiKey = JSON.stringify({ token: access, projectId: auth["google-antigravity"]?.projectId ?? "" }); const apiKey = JSON.stringify({ token: access, projectId: credential?.projectId ?? "" });
registerApiProvider({ api: "google-antigravity" as Api, stream: (model, context, options) => streamAntigravity(model, context, options),33 unmodified lines