/** * 状态管理器 * 支持两种订阅模式: * 1. 最新状态模式:订阅最新状态,适用于状态覆盖场景 * 2. 绑定状态模式:订阅特定stateKey,适用于状态隔离场景 */ export interface StateManager { /** * 获取当前活跃的状态key */ getCurrentStateKey: () => string | null; /** * 获取当前状态(基于当前状态key) */ getCurrentState: () => any; /** * 获取指定状态key的状态 */ getState: (stateKey: string) => any; /** * 获取所有状态keys */ getAllStateKeys: () => string[]; /** * 订阅状态变化 * @param callback 状态变化回调函数 * @param targetStateKey 可选:指定订阅特定的stateKey,不传则订阅当前活跃状态 */ subscribe: (callback: (state: any, stateKey: string) => void, targetStateKey?: string) => () => void; /** * 处理AG-UI状态事件,自动从事件中提取stateKey */ handleStateEvent: (event: { type: string; snapshot?: any; delta?: any[]; }) => void; /** * 清理所有状态和订阅 */ clear: () => void; } export declare class StateManagerImpl implements StateManager { private states; private currentStateKey; private latestSubscribers; private boundSubscribers; /** * 获取当前活跃的状态key */ getCurrentStateKey(): string | null; /** * 获取当前状态(基于当前状态key) */ getCurrentState(): any; /** * 获取指定状态key的状态 */ getState(stateKey: string): any; /** * 获取所有状态keys */ getAllStateKeys(): string[]; /** * 订阅最新状态(覆盖模式) * 适用于只有一个组件,每轮都用新状态更新的场景 */ subscribeToLatest(callback: (state: any, stateKey: string) => void): () => void; /** * 订阅状态变化(实现 StateManager 接口) * @param callback 状态变化回调函数 * @param targetStateKey 可选:指定订阅特定的stateKey,不传则订阅当前活跃状态 */ subscribe(callback: (state: any, stateKey: string) => void, targetStateKey?: string): () => void; /** * 订阅特定状态(隔离模式) * 适用于每轮对话创建新组件,各自保持独立状态的场景 */ subscribeToState(stateKey: string, callback: (state: any) => void): () => void; /** * 处理AG-UI状态事件 * 自动从事件中提取stateKey,无需外部传递 */ handleStateEvent(event: { type: string; snapshot?: any; delta?: any[]; }): void; clear(): void; /** * 设置状态并立即通知订阅者 */ private setState; /** * 通知订阅者 */ private notifySubscribers; } export declare const stateManager: StateManagerImpl;