refactor: share live provider owner matching

This commit is contained in:
Peter Steinberger
2026-04-18 21:43:28 +01:00
parent 85826c83e4
commit 57b55883c5
3 changed files with 45 additions and 69 deletions

View File

@@ -1,7 +1,7 @@
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveProviderModernModelRef } from "../plugins/provider-runtime.js";
import { resolveOwningPluginIdsForProvider } from "../plugins/providers.js";
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
import { liveProvidersShareOwningPlugin } from "./live-provider-owner.js";
import { normalizeProviderId } from "./provider-id.js";
export type ModelRef = {
@@ -100,36 +100,6 @@ export function isHighSignalLiveModelRef(ref: ModelRef): boolean {
return isHighSignalClaudeModelId(id);
}
function sharesOwningPlugin(params: {
left: string;
right: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
ownerCache: Map<string, readonly string[]>;
}): boolean {
const resolveOwners = (provider: string): readonly string[] => {
const normalized = normalizeProviderId(provider);
const cached = params.ownerCache.get(normalized);
if (cached) {
return cached;
}
const owners =
resolveOwningPluginIdsForProvider({
provider: normalized,
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
}) ?? [];
params.ownerCache.set(normalized, owners);
return owners;
};
const leftOwners = resolveOwners(params.left);
const rightOwners = resolveOwners(params.right);
return leftOwners.some((owner) => rightOwners.includes(owner));
}
export function shouldExcludeProviderFromDefaultHighSignalLiveSweep(params: {
provider?: string | null;
useExplicitModels: boolean;
@@ -153,9 +123,7 @@ export function shouldExcludeProviderFromDefaultHighSignalLiveSweep(params: {
}
if (
requestedProvider &&
sharesOwningPlugin({
left: requestedProvider,
right: provider,
liveProvidersShareOwningPlugin(requestedProvider, provider, {
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,

View File

@@ -0,0 +1,40 @@
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveOwningPluginIdsForProvider } from "../plugins/providers.js";
import { normalizeProviderId } from "./provider-id.js";
export type LiveProviderOwnerContext = {
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
ownerCache: Map<string, readonly string[]>;
};
export function resolveCachedOwningPluginIdsForProvider(
provider: string,
context: LiveProviderOwnerContext,
): readonly string[] {
const normalized = normalizeProviderId(provider);
const cached = context.ownerCache.get(normalized);
if (cached) {
return cached;
}
const owners =
resolveOwningPluginIdsForProvider({
provider: normalized,
config: context.config,
workspaceDir: context.workspaceDir,
env: context.env,
}) ?? [];
context.ownerCache.set(normalized, owners);
return owners;
}
export function liveProvidersShareOwningPlugin(
left: string,
right: string,
context: LiveProviderOwnerContext,
): boolean {
const leftOwners = resolveCachedOwningPluginIdsForProvider(left, context);
const rightOwners = resolveCachedOwningPluginIdsForProvider(right, context);
return leftOwners.some((owner) => rightOwners.includes(owner));
}

View File

@@ -1,9 +1,9 @@
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveOwningPluginIdsForProvider } from "../plugins/providers.js";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalLowercaseString,
} from "../shared/string-coerce.js";
import { liveProvidersShareOwningPlugin } from "./live-provider-owner.js";
import { normalizeProviderId } from "./provider-id.js";
type ModelTarget = {
@@ -51,38 +51,6 @@ function parseModelTarget(raw: string): ModelTarget | null {
};
}
function hasSharedOwner(
left: string,
right: string,
params: {
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
ownerCache: Map<string, readonly string[]>;
},
): boolean {
const resolveOwners = (provider: string): readonly string[] => {
const normalized = normalizeProviderId(provider);
const cached = params.ownerCache.get(normalized);
if (cached) {
return cached;
}
const owners =
resolveOwningPluginIdsForProvider({
provider: normalized,
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
}) ?? [];
params.ownerCache.set(normalized, owners);
return owners;
};
const leftOwners = resolveOwners(left);
const rightOwners = resolveOwners(right);
return leftOwners.some((owner) => rightOwners.includes(owner));
}
export function createLiveTargetMatcher(params: {
providerFilter: Set<string> | null;
modelFilter: Set<string> | null;
@@ -108,7 +76,7 @@ export function createLiveTargetMatcher(params: {
return true;
}
if (
hasSharedOwner(normalizedRequested, normalizedProvider, {
liveProvidersShareOwningPlugin(normalizedRequested, normalizedProvider, {
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
@@ -144,7 +112,7 @@ export function createLiveTargetMatcher(params: {
return true;
}
if (
hasSharedOwner(target.provider, normalizedProvider, {
liveProvidersShareOwningPlugin(target.provider, normalizedProvider, {
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,