fix: restore auth fallback ordering

This commit is contained in:
Peter Steinberger
2026-01-06 01:38:09 +00:00
parent 6f541d6304
commit 87f4efda8d
5 changed files with 59 additions and 8 deletions

View File

@@ -258,10 +258,16 @@ export function resolveAuthProfileOrder(params: {
.map(([profileId]) => profileId)
: [];
const lastGood = store.lastGood?.[provider];
const order =
const baseOrder =
configuredOrder ??
(explicitProfiles.length > 0 ? explicitProfiles : undefined);
if (!order) return [];
(explicitProfiles.length > 0
? explicitProfiles
: listProfilesForProvider(store, provider));
if (baseOrder.length === 0) return [];
const order =
configuredOrder && configuredOrder.length > 0
? baseOrder
: orderProfilesByMode(baseOrder, store);
const filtered = order.filter((profileId) => {
const cred = store.profiles[profileId];
@@ -288,6 +294,20 @@ export function resolveAuthProfileOrder(params: {
return deduped;
}
function orderProfilesByMode(
order: string[],
store: AuthProfileStore,
): string[] {
const scored = order.map((profileId) => {
const type = store.profiles[profileId]?.type;
const score = type === "oauth" ? 0 : type === "api_key" ? 1 : 2;
return { profileId, score };
});
return scored
.sort((a, b) => a.score - b.score)
.map((entry) => entry.profileId);
}
export async function resolveApiKeyForProfile(params: {
cfg?: ClawdbotConfig;
store: AuthProfileStore;