openclaw / src /plugins /runtime /generation-scope.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
4c76b0d verified
Raw
History Blame Contribute Delete
1.79 kB
import {
runOutsidePluginMetadataSnapshotScope,
withPluginMetadataSnapshotScope,
} from "../current-plugin-metadata-snapshot.js";
import type { PluginMetadataSnapshot } from "../plugin-metadata-snapshot.types.js";
import { createEmptyPluginRegistry } from "../registry-empty.js";
import type { PluginRegistry } from "../registry-types.js";
import {
runOutsidePluginRuntimeRegistryScope,
withPluginRuntimeRegistryScope,
} from "./gateway-request-scope.js";
import {
withPluginRuntimeGenerationRegistryScope,
runOutsidePluginRuntimeGenerationRegistryScope,
} from "./generation-state.js";
export { getPluginRuntimeGenerationRegistry } from "./generation-state.js";
/** Carries one prepared plugin generation through all nested runtime lookups. */
export function withPluginRuntimeGenerationScope<T>(
generation: {
metadataSnapshot: PluginMetadataSnapshot;
pluginRegistry?: PluginRegistry;
},
run: () => T,
): T {
const pluginRegistry = generation.pluginRegistry ?? createEmptyPluginRegistry();
return withPluginMetadataSnapshotScope(
generation.metadataSnapshot,
() =>
withPluginRuntimeGenerationRegistryScope(pluginRegistry, () =>
withPluginRuntimeRegistryScope(
pluginRegistry,
run,
generation.metadataSnapshot.declaredProviderOwners,
),
),
// The prepared generation already owns discovery and policy compatibility.
{ trustConfigIdentity: true },
);
}
/** Re-admission drops the old generation while retaining the exact Gateway caller. */
export function runOutsidePluginRuntimeGenerationScope<T>(run: () => T): T {
return runOutsidePluginRuntimeGenerationRegistryScope(() =>
runOutsidePluginMetadataSnapshotScope(() => runOutsidePluginRuntimeRegistryScope(run)),
);
}