import type { InteractionRequest, InteractionAnswer, InteractionStore, InteractionType, InteractionSource } from './types.js'; /** * InteractionService — 管理用户交互请求的生命周期 * * 用法: * 1. Agent 工具调用 service.requestInteraction(...) 创建请求 * 2. 前端通过 SSE 收到 interaction-request 事件 * 3. 用户在前端选择后 POST 回答 * 4. service.answerInteraction(...) 解析等待的 Promise * 5. Agent 工具拿到答案继续执行 */ export declare class InteractionService { private store; private waiters; private defaultTimeoutMs; constructor(store: InteractionStore, defaultTimeoutMs?: number); /** * 清理 waiter:清除超时和轮询定时器,从 map 中删除并返回 */ private clearWaiter; /** * 创建交互请求并返回 Promise,等待用户回答 */ requestInteraction(params: { sessionId: string; threadId?: string | number; parentToolCallId?: string; source: InteractionSource; agentName?: string; type: InteractionType; title: string; message: string; options?: InteractionRequest['options']; allowFreeText?: boolean; required?: boolean; timeoutMs?: number; /** 创建请求后的回调(用于发送 SSE 事件通知前端) */ emit?: (request: InteractionRequest) => void; /** 交互不再等待(超时/取消/中止)后的回调,用于向前端推送失效事件(interaction-timeout) */ onExpired?: (request: InteractionRequest) => void; /** 会话/工具中止信号 */ abortSignal?: AbortSignal; /** 扩展字段(如 permissionId 用于权限审批联动) */ meta?: Record; }): Promise; /** * 创建交互请求(非阻塞,不等待用户回答) * 用于权限审批等场景:创建后通过 SSE 通知前端,但当前执行流继续(通常配合 block 工具) */ createInteraction(params: { sessionId: string; threadId?: string | number; parentToolCallId?: string; source: InteractionSource; agentName?: string; type: InteractionType; title: string; message: string; options?: InteractionRequest['options']; allowFreeText?: boolean; required?: boolean; timeoutMs?: number; /** 扩展字段(如 permissionId 用于权限审批联动) */ meta?: Record; }): InteractionRequest; /** * 回答交互请求 * 先更新 store(跨进程可见),再尝试 resolve 本地 waiter。 * 即使本地 waiter 不存在(跨进程场景),store 已更新,轮询方会检测到。 */ answerInteraction(requestId: string, answer: InteractionAnswer): boolean; /** * 取消交互请求 * 先更新 store(跨进程可见),再尝试 reject 本地 waiter。 * 即使本地 waiter 不存在(跨进程场景),store 已更新,轮询方会检测到。 */ cancelInteraction(requestId: string): boolean; /** * 获取 pending 请求列表 */ listPending(sessionId: string): InteractionRequest[]; /** * 获取单个请求 */ getRequest(requestId: string): InteractionRequest | undefined; /** * 取消会话下所有 pending 请求 */ cancelAllForSession(sessionId: string): void; /** * 取消线程下所有 pending 请求(包含使用子会话 ID 创建的交互) */ cancelAllForThread(threadId: string | number): void; /** * 清理已完成/已过期/已取消的请求 */ cleanup(olderThanMs?: number): number; } //# sourceMappingURL=service.d.ts.map