GeezerVison is showing adk.dev — State | ADK for TypeScript: API Reference - v2.5.0
A state mapping that maintains the current value and the pending-commit
delta.
Constructors
constructor
-
new State( value?: Record<string, unknown>, delta?: Record<string, unknown>, schema?: SchemaLike,): State
Parameters
- value: Record<string, unknown> = {}
The current value of the state.
- delta: Record<string, unknown> = {}
The delta change to the current value that hasn't been committed.
Optionalschema: SchemaLike
Declares the keys this state may hold and their types. When set, every
mutation is checked against it; prefixed keys are exempt.
Returns State
Properties
Optional Readonlyschema
Declares the keys this state may hold and their types. When set, every
mutation is checked against it; prefixed keys are exempt.
Static ReadonlyAPP_PREFIX
APP_PREFIX: "app:" = 'app:'
Static ReadonlyTEMP_PREFIX
TEMP_PREFIX: "temp:" = 'temp:'
Static ReadonlyUSER_PREFIX
USER_PREFIX: "user:" = 'user:'
Methods
get
-
get<T>(key: string, defaultValue?: T): T | undefined
Returns the value of the state dict for the given key.
Only keys the state holds itself are found. Names inherited from
Object.prototype, such as toString, are treated as missing.
Parameters
- key: string
The key to get the value for.
OptionaldefaultValue: T
The default value to return if the key is not found.
Returns T | undefined
The value of the state for the given key, or the default value if
not found.
has
-
has(key: string): boolean
Whether the state holds the given key, either as a stored value or as a
pending delta. Names inherited from Object.prototype are not keys.
Returns boolean
hasDelta
-
Whether the state has pending delta.
Returns boolean
set
-
set(key: string, value: unknown): void
Sets the value of the state dict for the given key.
Parameters
- key: string
The key to set the value for.
- value: unknown
Returns void
toRecord
-
toRecord(): Record<string, unknown>
Returns the state as a plain JSON object.
Returns Record<string, unknown>
update
-
update(delta: Record<string, unknown>): void
Updates the state dict with the given delta.
Parameters
- delta: Record<string, unknown>
The delta to update the state with.
Returns void
validateDelta
-
validateDelta(delta: Record<string, unknown>): void
Checks a whole delta against schema, for writes that reach the
session without passing through this object — a node emitting an event
that carries its own stateDelta.
Parameters
- delta: Record<string, unknown>
Returns void
Constructors
Properties
Methods