Spaces:
Paused
Paused
Download src/agents/pi-extensions/context-pruning/runtime.ts from nikhtu10/OpenClawBot: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/nikhtu10/OpenClawBot/resolve/main/src/agents/pi-extensions/context-pruning/runtime.ts
- Command line
-
hf download hf://spaces/nikhtu10/OpenClawBot/src/agents/pi-extensions/context-pruning/runtime.ts
-
curl -L -o runtime.ts https://huggingface.co/spaces/nikhtu10/OpenClawBot/resolve/main/src/agents/pi-extensions/context-pruning/runtime.ts
1.17 kB
| import type { EffectiveContextPruningSettings } from "./settings.js"; | |
| export type ContextPruningRuntimeValue = { | |
| settings: EffectiveContextPruningSettings; | |
| contextWindowTokens?: number | null; | |
| isToolPrunable: (toolName: string) => boolean; | |
| 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>(); | |
| export function setContextPruningRuntime( | |
| sessionManager: unknown, | |
| value: ContextPruningRuntimeValue | null, | |
| ): void { | |
| if (!sessionManager || typeof sessionManager !== "object") { | |
| return; | |
| } | |
| 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; | |
| } | |