State

@three-blocks/proAIPerceptionState
new State()

State - Key-value perception store with timestamps

Stores AI perception data written by Sensors and read by Intents. Each key tracks when it was last updated for staleness detection.

Usage

Example
// Sensor writes perception data
state.set('targetVisible', true);
state.set('targetPosition', { x: 10, y: 0, z: 5 });

// Intent reads perception data
const visible = state.get('targetVisible', false);
const pos = state.get('targetPosition');

// Check staleness
const age = state.getAge('targetVisible'); // seconds since update

Properties

.size :

Get the number of entries in the state.

Methods

set#

set(key : string, value : any) : State

Set a value in the state.

Parameters
keystring
The key to set.
valueany
The value to store.
Returns
State — This instance for chaining.

setMultiple#

setMultiple(entries : Object) : State

Set multiple values at once.

Parameters
entriesObject
Object with key-value pairs to set.
Returns
State — This instance for chaining.

get#

get(key : string, defaultValue : any) : any

Get a value from the state.

Parameters
keystring
The key to get.
defaultValueoptionalany
Value to return if key doesn't exist.
Default is null.
Returns
any — The stored value or default.

has#

has(key : string) : boolean

Check if a key exists in the state.

Parameters
keystring
The key to check.
Returns
boolean — True if the key exists.

getAge#

getAge(key : string) : number

Get the age of a value in seconds.

Parameters
keystring
The key to check.
Returns
number — Seconds since last update, or Infinity if never set.

delete#

delete(key : string) : boolean

Delete a key from the state.

Parameters
keystring
The key to delete.
Returns
boolean — True if the key existed and was deleted.

clear#

clear() : State

Clear all state data.

Returns
State — This instance for chaining.

update#

update(delta : number) : State

Update the internal time reference. Called each frame before sensors run.

Parameters
deltanumber
Time delta in seconds.
Returns
State — This instance for chaining.

keys#

keys() : Array<string>

Get all keys in the state.

Returns
Array<string> — Array of all keys.