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

    Class State

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

    • 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

    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:'
    • 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.

      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.

    • 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.

      Parameters

      • key: string

      Returns boolean

    • 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

    • Returns the state as a plain JSON object.

      Returns Record<string, unknown>

    • 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