ADK for TypeScript: API Reference
    Preparing search index...

    Class State

    A state mapping that maintains the current value and the pending-commit delta.

    Constructors

    • 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

    schema?: SchemaLike

    Declares the keys this state may hold and their types. When set, every mutation is checked against it; prefixed keys are exempt.

    APP_PREFIX: "app:" = 'app:'
    TEMP_PREFIX: "temp:" = 'temp:'
    USER_PREFIX: "user:" = 'user:'

    Methods

    • Returns the value of the state dict for the given key.

      Type Parameters

      • T

      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.

    • Sets the value of the state dict for the given key.

      Parameters

      • key: string

        The key to set the value for.

      • value: unknown

        The value to set.

      Returns void

    • Updates the state dict with the given delta.

      Parameters

      • delta: Record<string, unknown>

        The delta to update the state with.

      Returns 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