diff --git a/src/plugins/provider-hook-runtime.ts b/src/plugins/provider-hook-runtime.ts index 96013079e9bb..e6ec239a4faf 100644 --- a/src/plugins/provider-hook-runtime.ts +++ b/src/plugins/provider-hook-runtime.ts @@ -1,8 +1,5 @@ // Runtime bridge for invoking provider hooks supplied by plugins. -import { - findNormalizedProviderValue, - normalizeProviderId, -} from "@openclaw/model-catalog-core/provider-id"; +import { findNormalizedProviderValue } from "@openclaw/model-catalog-core/provider-id"; import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, @@ -18,6 +15,7 @@ import { import { resolvePluginControlPlaneFingerprint } from "./plugin-control-plane-context.js"; import type { PluginMetadataRegistryView } from "./plugin-metadata-snapshot.types.js"; import { resolveProviderConfigApiOwnerHint } from "./provider-config-owner.js"; +import { matchesProviderPluginRef } from "./provider-registry-shared.js"; import { isPluginProvidersLoadInFlight, resolvePluginProviders } from "./providers.runtime.js"; import type { PluginRegistry } from "./registry-types.js"; import { @@ -62,19 +60,6 @@ export function clearProviderRuntimePluginCacheForTest(): void { defaultProviderRuntimePluginCache.clear(); } -function matchesProviderId(provider: ProviderPlugin, providerId: string): boolean { - const normalized = normalizeProviderId(providerId); - if (!normalized) { - return false; - } - if (normalizeProviderId(provider.id) === normalized) { - return true; - } - return [...(provider.aliases ?? []), ...(provider.hookAliases ?? [])].some( - (alias) => normalizeProviderId(alias) === normalized, - ); -} - function resolveProviderRuntimePluginCacheKey( params: ProviderRuntimePluginLookupParams, registryState = getPluginRegistryState(), @@ -186,10 +171,10 @@ function findProviderRuntimePluginInRegistry(params: { if (params.apiOwnerHint) { return ( matchesProviderLiteralId(plugin, params.provider) || - matchesProviderId(plugin, params.apiOwnerHint) + matchesProviderPluginRef(plugin, params.apiOwnerHint) ); } - return matchesProviderId(plugin, params.provider); + return matchesProviderPluginRef(plugin, params.provider); }); } @@ -276,10 +261,10 @@ export function resolveProviderRuntimePlugin( if (apiOwnerHint) { return ( matchesProviderLiteralId(plugin, params.provider) || - matchesProviderId(plugin, apiOwnerHint) + matchesProviderPluginRef(plugin, apiOwnerHint) ); } - return matchesProviderId(plugin, params.provider); + return matchesProviderPluginRef(plugin, params.provider); }) ?? null ); }; @@ -335,7 +320,7 @@ export function resolveProviderHookPlugin(params: { config: params.config, workspaceDir: params.workspaceDir, env: params.env, - }).find((candidate) => matchesProviderId(candidate, params.provider)); + }).find((candidate) => matchesProviderPluginRef(candidate, params.provider)); } export function resolveProviderRuntimePluginHandle( diff --git a/src/plugins/provider-registry-shared.ts b/src/plugins/provider-registry-shared.ts index 4a67699a11c8..4efa2718d07b 100644 --- a/src/plugins/provider-registry-shared.ts +++ b/src/plugins/provider-registry-shared.ts @@ -1,4 +1,5 @@ // Shares provider registry normalization helpers across plugin paths. +import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id"; import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce"; import { isBlockedObjectKey } from "../infra/prototype-keys.js"; @@ -8,6 +9,20 @@ export function normalizeCapabilityProviderId(providerId: string | undefined): s return normalized && !isBlockedObjectKey(normalized) ? normalized : undefined; } +export function matchesProviderPluginRef( + provider: { id: string; aliases?: readonly string[]; hookAliases?: readonly string[] }, + providerId: string, +): boolean { + const normalized = normalizeProviderId(providerId); + return Boolean( + normalized && + (normalizeProviderId(provider.id) === normalized || + [...(provider.aliases ?? []), ...(provider.hookAliases ?? [])].some( + (alias) => normalizeProviderId(alias) === normalized, + )), + ); +} + /** Builds canonical and alias lookup maps for capability providers. */ export function buildCapabilityProviderMaps( providers: readonly T[], diff --git a/src/plugins/provider-runtime.ts b/src/plugins/provider-runtime.ts index e6cb49108a31..a5036b88f849 100644 --- a/src/plugins/provider-runtime.ts +++ b/src/plugins/provider-runtime.ts @@ -41,6 +41,7 @@ import { wrapProviderStreamFn, } from "./provider-hook-runtime.js"; import { resolveBundledProviderPolicySurface } from "./provider-public-artifacts.js"; +import { matchesProviderPluginRef } from "./provider-registry-shared.js"; import type { ProviderRuntimeModel } from "./provider-runtime-model.types.js"; import type { ProviderThinkingProfile } from "./provider-thinking.types.js"; import { @@ -94,19 +95,6 @@ import type { PluginTextTransforms, } from "./types.js"; -function matchesProviderPluginRef(provider: ProviderPlugin, providerId: string): boolean { - const normalized = normalizeProviderId(providerId); - if (!normalized) { - return false; - } - if (normalizeProviderId(provider.id) === normalized) { - return true; - } - return [...(provider.aliases ?? []), ...(provider.hookAliases ?? [])].some( - (alias) => normalizeProviderId(alias) === normalized, - ); -} - function resolveProviderHookRefs( provider: string, providerConfig?: ModelProviderConfig, diff --git a/src/plugins/provider-thinking-active.ts b/src/plugins/provider-thinking-active.ts index b506b3ad4d30..ec0d88080942 100644 --- a/src/plugins/provider-thinking-active.ts +++ b/src/plugins/provider-thinking-active.ts @@ -1,5 +1,5 @@ // Reads provider thinking policy from the active runtime registry only. -import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id"; +import { matchesProviderPluginRef } from "./provider-registry-shared.js"; import type { ProviderDefaultThinkingPolicyContext, ProviderThinkingProfile, @@ -28,19 +28,6 @@ type ThinkingHookParams = { context: TContext; }; -function matchesProviderId(provider: ActiveThinkingProvider, providerId: string): boolean { - const normalized = normalizeProviderId(providerId); - if (!normalized) { - return false; - } - if (normalizeProviderId(provider.id) === normalized) { - return true; - } - return [...(provider.aliases ?? []), ...(provider.hookAliases ?? [])].some( - (alias) => normalizeProviderId(alias) === normalized, - ); -} - function resolveActiveThinkingProvider(providerId: string): ActiveThinkingProvider | undefined { const state = ( globalThis as typeof globalThis & { @@ -48,7 +35,7 @@ function resolveActiveThinkingProvider(providerId: string): ActiveThinkingProvid } )[PLUGIN_REGISTRY_STATE]; return state?.activeRegistry?.providers?.find((entry) => - matchesProviderId(entry.provider, providerId), + matchesProviderPluginRef(entry.provider, providerId), )?.provider; }