refactor(model): share normalized provider map lookups

This commit is contained in:
Peter Steinberger
2026-02-16 22:58:23 +00:00
parent 1fca7c3928
commit 9f0fc74d10
5 changed files with 43 additions and 58 deletions

View File

@@ -10,7 +10,7 @@ import {
resolveAuthProfileOrder,
resolveEnvApiKey,
} from "../../agents/model-auth.js";
import { normalizeProviderId } from "../../agents/model-selection.js";
import { findNormalizedProviderValue, normalizeProviderId } from "../../agents/model-selection.js";
import { shortenHomePath } from "../../utils.js";
export type ModelAuthDetailMode = "compact" | "verbose";
@@ -39,18 +39,7 @@ export const resolveAuthLabel = async (
});
const order = resolveAuthProfileOrder({ cfg, store, provider });
const providerKey = normalizeProviderId(provider);
const lastGood = (() => {
const map = store.lastGood;
if (!map) {
return undefined;
}
for (const [key, value] of Object.entries(map)) {
if (normalizeProviderId(key) === providerKey) {
return value;
}
}
return undefined;
})();
const lastGood = findNormalizedProviderValue(store.lastGood, providerKey);
const nextProfileId = order[0];
const now = Date.now();