Download src/infra/active-node-context.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/infra/active-node-context.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/infra/active-node-context.ts
-
curl -L -o active-node-context.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/infra/active-node-context.ts
1.44 kB
| /** Stable active-node identity projected into the dynamic model runtime line. */ | |
| type ActiveNodeContext = { | |
| nodeId: string; | |
| pairingGeneration?: string; | |
| }; | |
| type ActiveNodeContextState = ActiveNodeContext & { | |
| isCurrent?: () => boolean; | |
| }; | |
| let activeNodeContext: ActiveNodeContextState | null = null; | |
| function snapshotActiveNodeContext(context: ActiveNodeContextState): ActiveNodeContext { | |
| return { | |
| nodeId: context.nodeId, | |
| ...(context.pairingGeneration ? { pairingGeneration: context.pairingGeneration } : {}), | |
| }; | |
| } | |
| /** Publishes the gateway's current active-node choice without volatile timestamps. */ | |
| export function setActiveNodeContext( | |
| next: ActiveNodeContext | null, | |
| options?: { isCurrent?: () => boolean }, | |
| ): void { | |
| activeNodeContext = next ? { ...next, ...options } : null; | |
| } | |
| /** Revalidates the published node before projecting it into an agent prompt. */ | |
| export function getCurrentActiveNodeContext(): ActiveNodeContext | null { | |
| if (!activeNodeContext) { | |
| return null; | |
| } | |
| try { | |
| if (activeNodeContext.isCurrent && !activeNodeContext.isCurrent()) { | |
| return null; | |
| } | |
| } catch { | |
| return null; | |
| } | |
| return snapshotActiveNodeContext(activeNodeContext); | |
| } | |
| /** Formats the stable authenticated id; node-controlled labels stay out of prompt text. */ | |
| export function formatActiveNodeContextLabel( | |
| context: ActiveNodeContext | null, | |
| ): string | undefined { | |
| return context?.nodeId; | |
| } | |