mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
refactor(pi): share session manager runtime registry
This commit is contained in:
29
src/agents/pi-extensions/session-manager-runtime-registry.ts
Normal file
29
src/agents/pi-extensions/session-manager-runtime-registry.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export function createSessionManagerRuntimeRegistry<TValue>() {
|
||||
// Session-scoped runtime registry keyed by object identity.
|
||||
// The SessionManager instance must stay stable across set/get calls.
|
||||
const registry = new WeakMap<object, TValue>();
|
||||
|
||||
const set = (sessionManager: unknown, value: TValue | null): void => {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = sessionManager;
|
||||
if (value === null) {
|
||||
registry.delete(key);
|
||||
return;
|
||||
}
|
||||
|
||||
registry.set(key, value);
|
||||
};
|
||||
|
||||
const get = (sessionManager: unknown): TValue | null => {
|
||||
if (!sessionManager || typeof sessionManager !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return registry.get(sessionManager) ?? null;
|
||||
};
|
||||
|
||||
return { set, get };
|
||||
}
|
||||
Reference in New Issue
Block a user