mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 02:48:27 +00:00
refactor(pi): share session manager runtime registry
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { EffectiveContextPruningSettings } from "./settings.js";
|
||||
import { createSessionManagerRuntimeRegistry } from "../session-manager-runtime-registry.js";
|
||||
|
||||
export type ContextPruningRuntimeValue = {
|
||||
settings: EffectiveContextPruningSettings;
|
||||
@@ -7,34 +8,10 @@ export type ContextPruningRuntimeValue = {
|
||||
lastCacheTouchAt?: number | null;
|
||||
};
|
||||
|
||||
// Session-scoped runtime registry keyed by object identity.
|
||||
// Important: this relies on Pi passing the same SessionManager object instance into
|
||||
// ExtensionContext (ctx.sessionManager) that we used when calling setContextPruningRuntime.
|
||||
const REGISTRY = new WeakMap<object, ContextPruningRuntimeValue>();
|
||||
const registry = createSessionManagerRuntimeRegistry<ContextPruningRuntimeValue>();
|
||||
|
||||
export function setContextPruningRuntime(
|
||||
sessionManager: unknown,
|
||||
value: ContextPruningRuntimeValue | null,
|
||||
): void {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return;
|
||||
}
|
||||
export const setContextPruningRuntime = registry.set;
|
||||
|
||||
const key = sessionManager;
|
||||
if (value === null) {
|
||||
REGISTRY.delete(key);
|
||||
return;
|
||||
}
|
||||
|
||||
REGISTRY.set(key, value);
|
||||
}
|
||||
|
||||
export function getContextPruningRuntime(
|
||||
sessionManager: unknown,
|
||||
): ContextPruningRuntimeValue | null {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return REGISTRY.get(sessionManager) ?? null;
|
||||
}
|
||||
export const getContextPruningRuntime = registry.get;
|
||||
|
||||
Reference in New Issue
Block a user