mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 09:32:12 +00:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { getCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
|
|
import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.types.js";
|
|
|
|
type CachedGatewayPluginConfig = {
|
|
snapshot: PluginMetadataSnapshot;
|
|
config: OpenClawConfig;
|
|
};
|
|
|
|
const gatewayPluginConfigCache = new WeakMap<OpenClawConfig, CachedGatewayPluginConfig>();
|
|
|
|
export function resolveGatewayPluginConfig(params: { config: OpenClawConfig }): OpenClawConfig {
|
|
const currentSnapshot = getCurrentPluginMetadataSnapshot({
|
|
config: params.config,
|
|
allowWorkspaceScopedSnapshot: true,
|
|
});
|
|
if (!currentSnapshot) {
|
|
return applyPluginAutoEnable({
|
|
config: params.config,
|
|
}).config;
|
|
}
|
|
|
|
const cached = gatewayPluginConfigCache.get(params.config);
|
|
if (cached?.snapshot === currentSnapshot) {
|
|
return cached.config;
|
|
}
|
|
|
|
const config = applyPluginAutoEnable({
|
|
config: params.config,
|
|
manifestRegistry: currentSnapshot.manifestRegistry,
|
|
discovery: currentSnapshot.discovery,
|
|
}).config;
|
|
gatewayPluginConfigCache.set(params.config, { snapshot: currentSnapshot, config });
|
|
return config;
|
|
}
|