Class: InMemoryHandoffStateStore
Defined in: packages/core/src/handoff/HandoffStateStore.ts:39
In-memory implementation of HandoffStateStore.
Default for Node.js stateful processes. Not suitable for edge/serverless where each request runs in a fresh isolate. For those environments, implement HandoffStateStore using your platform's KV store (e.g. Cloudflare KV via @vurb/cloudflare).
TTL is enforced lazily on getAndDelete — no background timers or memory leaks from expired entries that are never retrieved.
Example
import { SwarmGateway } from '@vurb/swarm';
import { InMemoryHandoffStateStore } from '@vurb/core';
const gateway = new SwarmGateway({
registry: { finance: 'http://finance-agent:8081' },
delegationSecret: process.env.VURB_DELEGATION_SECRET!,
stateStore: new InMemoryHandoffStateStore(),
});Implements
Constructors
Constructor
new InMemoryHandoffStateStore(): InMemoryHandoffStateStore;Returns
InMemoryHandoffStateStore
Accessors
size
Get Signature
get size(): number;Defined in: packages/core/src/handoff/HandoffStateStore.ts:89
Current number of entries in the store (useful for testing).
Returns
number
Methods
delete()
delete(stateId): Promise<void>;Defined in: packages/core/src/handoff/HandoffStateStore.ts:84
delete without reading. No-op if the key does not exist.
Parameters
| Parameter | Type |
|---|---|
stateId | string |
Returns
Promise<void>
Implementation of
get()
get(stateId): Promise<Record<string, unknown> | undefined>;Defined in: packages/core/src/handoff/HandoffStateStore.ts:73
Read without deleting (non-atomic, use for two-phase pattern). Falls back gracefully if the stateId has expired.
Expired entries are pruned on access (lazy TTL cleanup), consistent with getAndDelete. Without this, expired entries would accumulate in the Map indefinitely if get() was called but the data was already expired (e.g. a slow upstream that delayed token verification past the TTL window).
Parameters
| Parameter | Type |
|---|---|
stateId | string |
Returns
Promise<Record<string, unknown> | undefined>
Implementation of
getAndDelete()
getAndDelete(stateId): Promise<Record<string, unknown> | undefined>;Defined in: packages/core/src/handoff/HandoffStateStore.ts:49
Retrieve and atomically delete the state (one-shot). Prevents state leaks after successful handoff hydration. Returns undefined if the key does not exist or has expired.
Parameters
| Parameter | Type |
|---|---|
stateId | string |
Returns
Promise<Record<string, unknown> | undefined>
Implementation of
HandoffStateStore.getAndDelete
set()
set(
stateId,
state,
ttlSeconds): Promise<void>;Defined in: packages/core/src/handoff/HandoffStateStore.ts:42
Persist a state object under stateId with a TTL.
Parameters
| Parameter | Type | Description |
|---|---|---|
stateId | string | UUID key |
state | Record<string, unknown> | Arbitrary carry-over state |
ttlSeconds | number | Expiry in seconds |
Returns
Promise<void>