Skip to content

Commit 671c6e7

Browse files
authored
refactor(agents): reuse auth profile listing (#132919)
1 parent 2020b70 commit 671c6e7

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

‎src/agents/models-config.providers.secret-helpers.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { normalizeOptionalString } from "@openclaw/normalization-core/string-coe
55
import type { OpenClawConfig } from "../config/types.openclaw.js";
66
import { coerceSecretRef, resolveSecretInputRef } from "../config/types.secrets.js";
77
import { normalizeOptionalSecretInput } from "../utils/normalize-secret-input.js";
8+
import { listProfilesForProvider } from "./auth-profiles/profile-list.js";
89
import type { AuthProfileStore } from "./auth-profiles/types.js";
910
import { resolveEnvApiKey, type EnvApiKeyLookupOptions } from "./model-auth-env.js";
1011
import {
@@ -14,7 +15,6 @@ import {
1415
resolveNonEnvSecretRefHeaderValueMarker,
1516
} from "./model-auth-markers.js";
1617
import { resolveAwsSdkEnvVarName } from "./model-auth-runtime-shared.js";
17-
import { resolveProviderIdForAuth } from "./provider-auth-aliases.js";
1818

1919
/**
2020
* Secret-aware provider config helpers.
@@ -201,21 +201,13 @@ export function resolveApiKeyFromCredential(
201201
return undefined;
202202
}
203203

204-
/** Lists auth profile ids whose provider aliases match the requested provider. */
205-
export function listAuthProfilesForProvider(store: AuthProfileStore, provider: string): string[] {
206-
const providerKey = resolveProviderIdForAuth(provider);
207-
return Object.entries(store.profiles)
208-
.filter(([, cred]) => resolveProviderIdForAuth(cred.provider) === providerKey)
209-
.map(([id]) => id);
210-
}
211-
212204
/** Resolves the first usable API key from matching auth profiles. */
213205
export function resolveApiKeyFromProfiles(params: {
214206
provider: string;
215207
store: AuthProfileStore;
216208
env?: NodeJS.ProcessEnv;
217209
}): ProfileApiKeyResolution | undefined {
218-
const ids = listAuthProfilesForProvider(params.store, params.provider);
210+
const ids = listProfilesForProvider(params.store, params.provider);
219211
for (const id of ids) {
220212
const resolved = resolveApiKeyFromCredential(params.store.profiles[id], params.env);
221213
if (resolved) {

‎src/agents/models-config.providers.secrets.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
88
import { resolveSecretInputRef } from "../config/types.secrets.js";
99
import { resolveProviderSyntheticAuthWithPlugin } from "../plugins/provider-runtime.js";
1010
import type { ProviderAuthEvidence } from "../secrets/provider-env-vars.js";
11+
import { listProfilesForProvider } from "./auth-profiles/profile-list.js";
1112
import type { AuthProfileStore } from "./auth-profiles/types.js";
1213
import { resolveProviderEnvAuthLookupMaps } from "./model-auth-env-vars.js";
1314
import {
@@ -17,7 +18,6 @@ import {
1718
resolveNonEnvSecretRefApiKeyMarker,
1819
} from "./model-auth-markers.js";
1920
import {
20-
listAuthProfilesForProvider,
2121
normalizeApiKeyConfig,
2222
resolveApiKeyFromCredential,
2323
resolveApiKeyFromProfiles,
@@ -191,7 +191,7 @@ export function createProviderAuthResolver(
191191
const lookupCaches = getLookupCaches();
192192
const authProvider = resolveProviderIdForAuthFromCaches(provider, lookupCaches);
193193
const authStore = resolveAuthProfileStoreInput(authStoreInput);
194-
const ids = listAuthProfilesForProvider(authStore, authProvider);
194+
const ids = listProfilesForProvider(authStore, authProvider);
195195

196196
let oauthCandidate:
197197
| {

0 commit comments

Comments
 (0)