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

@@ -48,6 +48,33 @@ export function normalizeProviderId(provider: string): string {
return normalized;
}
export function findNormalizedProviderValue<T>(
entries: Record<string, T> | undefined,
provider: string,
): T | undefined {
if (!entries) {
return undefined;
}
const providerKey = normalizeProviderId(provider);
for (const [key, value] of Object.entries(entries)) {
if (normalizeProviderId(key) === providerKey) {
return value;
}
}
return undefined;
}
export function findNormalizedProviderKey(
entries: Record<string, unknown> | undefined,
provider: string,
): string | undefined {
if (!entries) {
return undefined;
}
const providerKey = normalizeProviderId(provider);
return Object.keys(entries).find((key) => normalizeProviderId(key) === providerKey);
}
export function isCliProvider(provider: string, cfg?: OpenClawConfig): boolean {
const normalized = normalizeProviderId(provider);
if (normalized === "claude-cli") {