mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 10:44:45 +00:00
test(agents): isolate shared subagent state
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { normalizeProviderId } from "../agents/provider-id.js";
|
||||
import type { ModelProviderConfig } from "../config/types.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { resolveBundledPluginsDir } from "./bundled-dir.js";
|
||||
import type {
|
||||
ProviderApplyConfigDefaultsContext,
|
||||
ProviderNormalizeConfigContext,
|
||||
@@ -20,6 +21,11 @@ export type BundledProviderPolicySurface = {
|
||||
|
||||
const bundledProviderPolicySurfaceCache = new Map<string, BundledProviderPolicySurface | null>();
|
||||
|
||||
function buildProviderPolicySurfaceCacheKey(providerId: string): string {
|
||||
const bundledPluginsDir = resolveBundledPluginsDir();
|
||||
return `${providerId}::${bundledPluginsDir ?? "<default>"}`;
|
||||
}
|
||||
|
||||
function hasProviderPolicyHook(
|
||||
mod: Record<string, unknown>,
|
||||
): mod is Record<string, unknown> & BundledProviderPolicySurface {
|
||||
@@ -66,16 +72,17 @@ export function resolveBundledProviderPolicySurface(
|
||||
if (!normalizedProviderId) {
|
||||
return null;
|
||||
}
|
||||
if (bundledProviderPolicySurfaceCache.has(normalizedProviderId)) {
|
||||
return bundledProviderPolicySurfaceCache.get(normalizedProviderId) ?? null;
|
||||
const cacheKey = buildProviderPolicySurfaceCacheKey(normalizedProviderId);
|
||||
if (bundledProviderPolicySurfaceCache.has(cacheKey)) {
|
||||
return bundledProviderPolicySurfaceCache.get(cacheKey) ?? null;
|
||||
}
|
||||
|
||||
const surface = tryLoadBundledProviderPolicySurface(normalizedProviderId);
|
||||
if (surface) {
|
||||
bundledProviderPolicySurfaceCache.set(normalizedProviderId, surface);
|
||||
bundledProviderPolicySurfaceCache.set(cacheKey, surface);
|
||||
return surface;
|
||||
}
|
||||
|
||||
bundledProviderPolicySurfaceCache.set(normalizedProviderId, null);
|
||||
bundledProviderPolicySurfaceCache.set(cacheKey, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user