fix(models): sync auth-profiles before availability checks

This commit is contained in:
Sebastian
2026-02-16 21:00:25 -05:00
parent fbda9a93fd
commit 4ca75bed56
6 changed files with 178 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { ensureAuthProfileStore } from "./auth-profiles.js";
import type { AuthProfileCredential } from "./auth-profiles/types.js";
import { normalizeProviderId } from "./model-selection.js";
type AuthJsonCredential =
| {
@@ -50,6 +51,13 @@ function convertCredential(cred: AuthProfileCredential): AuthJsonCredential | nu
if (!token) {
return null;
}
const expires =
typeof (cred as { expires?: unknown }).expires === "number"
? (cred as { expires: number }).expires
: Number.NaN;
if (Number.isFinite(expires) && expires > 0 && Date.now() >= expires) {
return null;
}
return { type: "api_key", key: token };
}
@@ -114,7 +122,7 @@ export async function ensurePiAuthJsonFromAuthProfiles(agentDir: string): Promis
const providerCredentials = new Map<string, AuthJsonCredential>();
for (const [, cred] of Object.entries(store.profiles)) {
const provider = cred.provider;
const provider = normalizeProviderId(String(cred.provider ?? "")).trim();
if (!provider || providerCredentials.has(provider)) {
continue;
}