mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:51:24 +00:00
refactor(model): share normalized provider map lookups
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user