mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe provider registry normalizers
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
|
||||
export function normalizeCapabilityProviderId(providerId: string | undefined): string | undefined {
|
||||
return normalizeOptionalString(providerId)?.toLowerCase();
|
||||
}
|
||||
|
||||
export function buildCapabilityProviderMaps<T extends { id: string; aliases?: readonly string[] }>(
|
||||
providers: readonly T[],
|
||||
normalizeId: (providerId: string | undefined) => string | undefined = (providerId) =>
|
||||
normalizeOptionalString(providerId)?.toLowerCase(),
|
||||
normalizeId: (
|
||||
providerId: string | undefined,
|
||||
) => string | undefined = normalizeCapabilityProviderId,
|
||||
): {
|
||||
canonical: Map<string, T>;
|
||||
aliases: Map<string, T>;
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolvePluginCapabilityProviders } from "../plugins/capability-provider-runtime.js";
|
||||
import {
|
||||
buildCapabilityProviderMaps,
|
||||
normalizeCapabilityProviderId,
|
||||
} from "../plugins/provider-registry-shared.js";
|
||||
import type { RealtimeTranscriptionProviderPlugin } from "../plugins/types.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import type { RealtimeTranscriptionProviderId } from "./provider-types.js";
|
||||
|
||||
export function normalizeRealtimeTranscriptionProviderId(
|
||||
providerId: string | undefined,
|
||||
): RealtimeTranscriptionProviderId | undefined {
|
||||
return normalizeOptionalString(providerId)?.toLowerCase();
|
||||
return normalizeCapabilityProviderId(providerId);
|
||||
}
|
||||
|
||||
function resolveRealtimeTranscriptionProviderEntries(
|
||||
@@ -23,28 +26,7 @@ function buildProviderMaps(cfg?: OpenClawConfig): {
|
||||
canonical: Map<string, RealtimeTranscriptionProviderPlugin>;
|
||||
aliases: Map<string, RealtimeTranscriptionProviderPlugin>;
|
||||
} {
|
||||
const canonical = new Map<string, RealtimeTranscriptionProviderPlugin>();
|
||||
const aliases = new Map<string, RealtimeTranscriptionProviderPlugin>();
|
||||
const register = (provider: RealtimeTranscriptionProviderPlugin) => {
|
||||
const id = normalizeRealtimeTranscriptionProviderId(provider.id);
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
canonical.set(id, provider);
|
||||
aliases.set(id, provider);
|
||||
for (const alias of provider.aliases ?? []) {
|
||||
const normalizedAlias = normalizeRealtimeTranscriptionProviderId(alias);
|
||||
if (normalizedAlias) {
|
||||
aliases.set(normalizedAlias, provider);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const provider of resolveRealtimeTranscriptionProviderEntries(cfg)) {
|
||||
register(provider);
|
||||
}
|
||||
|
||||
return { canonical, aliases };
|
||||
return buildCapabilityProviderMaps(resolveRealtimeTranscriptionProviderEntries(cfg));
|
||||
}
|
||||
|
||||
export function listRealtimeTranscriptionProviders(
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolvePluginCapabilityProviders } from "../plugins/capability-provider-runtime.js";
|
||||
import { buildCapabilityProviderMaps } from "../plugins/provider-registry-shared.js";
|
||||
import {
|
||||
buildCapabilityProviderMaps,
|
||||
normalizeCapabilityProviderId,
|
||||
} from "../plugins/provider-registry-shared.js";
|
||||
import type { RealtimeVoiceProviderPlugin } from "../plugins/types.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import type { RealtimeVoiceProviderId } from "./provider-types.js";
|
||||
|
||||
export function normalizeRealtimeVoiceProviderId(
|
||||
providerId: string | undefined,
|
||||
): RealtimeVoiceProviderId | undefined {
|
||||
return normalizeOptionalString(providerId)?.toLowerCase();
|
||||
return normalizeCapabilityProviderId(providerId);
|
||||
}
|
||||
|
||||
function resolveRealtimeVoiceProviderEntries(cfg?: OpenClawConfig): RealtimeVoiceProviderPlugin[] {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolvePluginCapabilityProviders } from "../plugins/capability-provider-runtime.js";
|
||||
import { buildCapabilityProviderMaps } from "../plugins/provider-registry-shared.js";
|
||||
import {
|
||||
buildCapabilityProviderMaps,
|
||||
normalizeCapabilityProviderId,
|
||||
} from "../plugins/provider-registry-shared.js";
|
||||
import type { SpeechProviderPlugin } from "../plugins/types.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import type { SpeechProviderId } from "./provider-types.js";
|
||||
|
||||
export function normalizeSpeechProviderId(
|
||||
providerId: string | undefined,
|
||||
): SpeechProviderId | undefined {
|
||||
return normalizeOptionalString(providerId)?.toLowerCase();
|
||||
return normalizeCapabilityProviderId(providerId);
|
||||
}
|
||||
|
||||
function resolveSpeechProviderPluginEntries(cfg?: OpenClawConfig): SpeechProviderPlugin[] {
|
||||
|
||||
Reference in New Issue
Block a user