/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { SchemaLike } from '../utils/schema.js'; /** Raised when a state mutation violates the declared state schema. */ export declare class StateSchemaError extends TypeError { constructor(message: string); } /** Type guard for {@link StateSchemaError}. */ export declare function isStateSchemaError(e: unknown): e is StateSchemaError; /** * A state mapping that maintains the current value and the pending-commit * delta. */ export declare class State { /** The current value of the state. */ private value; /** The delta change to the current value that hasn't been committed. */ private delta; /** * Declares the keys this state may hold and their types. When set, every * mutation is checked against it; prefixed keys are exempt. */ readonly schema?: SchemaLike | undefined; static readonly APP_PREFIX = "app:"; static readonly USER_PREFIX = "user:"; static readonly TEMP_PREFIX = "temp:"; constructor( /** The current value of the state. */ value?: Record, /** The delta change to the current value that hasn't been committed. */ delta?: Record, /** * Declares the keys this state may hold and their types. When set, every * mutation is checked against it; prefixed keys are exempt. */ schema?: SchemaLike | undefined); /** * Checks a whole delta against {@link schema}, for writes that reach the * session without passing through this object — a node emitting an event * that carries its own `stateDelta`. */ validateDelta(delta: Record): void; /** * Checks one key/value pair against {@link schema}, throwing * {@link StateSchemaError} when the key is undeclared or its value does not * match the declared type. * * Prefixed keys (`app:`, `user:`, `temp:`, or any other namespace) belong to * a scope wider than this state and are never validated — the same carve-out * adk-python makes. */ private validate; /** * Returns the value of the state dict for the given key. * * @param key The key to get the value for. * @param defaultValue The default value to return if the key is not found. * @return The value of the state for the given key, or the default value if * not found. */ get(key: string, defaultValue?: T): T | undefined; /** * Sets the value of the state dict for the given key. * * @param key The key to set the value for. * @param value The value to set. */ set(key: string, value: unknown): void; /** * Whether the state has pending delta. */ has(key: string): boolean; /** * Whether the state has pending delta. */ hasDelta(): boolean; /** * Updates the state dict with the given delta. * * @param delta The delta to update the state with. */ update(delta: Record): void; /** * Returns the state as a plain JSON object. */ toRecord(): Record; }