import type { ServerResponse } from "node:http"; import type { AgentAttachment } from "../agent/types.js"; import type { CanvasSnapshot } from "./types.js"; type TurnAttachment = { clientId: string; id: string; name: string; type: string; size: number; width: number; height: number; dataUrl: string; }; export type CodexState = { busy: boolean; threadId: string; turnId: string; }; export type McpStartupState = "starting" | "ready" | "failed" | "cancelled"; export type ConversationState = { revision: number; conversationId: string; threadId: string; status: "idle" | "preparing" | "ready" | "warning" | "running" | "failed"; mcpStatuses: Record; sourceClientId?: string; error?: string; }; type McpInventoryItem = { name: string; authStatus?: string; }; export declare const AGENT_PROTOCOL_VERSION = 6; /** 管理网页画布连接、状态、附件和工具请求。 */ export declare class CanvasSession { private clients; private clientFocusOrder; private pending; private pendingApprovals; private canvasStates; private turnAttachments; private codexReplayEvents; private codexReplayActiveItems; private codexMutationBusy; private activeClientId; private boundClientId; private focusSequence; private codexState; private conversationState; private conversationInventoryComplete; private preparedConversationThreadId; constructor(activeThreadId?: string); /** 获取当前目标网页的画布状态。 */ private get canvasState(); /** 获取当前 turn 绑定或最近激活的网页客户端。 */ private get targetClientId(); /** 返回 Canvas Agent 当前连接状态。 */ health(): { ok: boolean; protocolVersion: number; hasCanvas: boolean; clients: number; codexBusy: boolean; conversation: ConversationState; }; /** 返回 Codex 是否正在执行任务。 */ get codexBusy(): boolean; get codexThreadId(): string; /** Return a copy that callers can restore after a temporary Codex operation. */ get codexStateSnapshot(): CodexState; /** 返回站点级对话的权威快照。 */ get conversationStateSnapshot(): ConversationState; /** 原子开始一次新建或恢复对话流程。 */ beginConversation(options?: { threadId?: string; conversationId?: string; sourceClientId?: string; }): ConversationState; /** 记录预热阶段单个 MCP 服务的启动状态。 */ updateConversationMcp(name: string, status: McpStartupState, error?: string | null, failureReason?: string | null): ConversationState; /** 用 app-server 的完整 MCP 清单补齐未发送逐项通知的服务。 */ completeConversationMcpInventory(services: McpInventoryItem[]): ConversationState; /** MCP 清单读取结束后提交线程和最终可发送状态。 */ completeConversationPreparation(threadId: string): ConversationState; /** 将创建线程或读取 MCP 清单的失败保存为不可发送状态。 */ failConversationPreparation(error: string): ConversationState; /** 切换到无需重新预热的既有状态,例如删除当前对话后的空状态。 */ activateConversation(threadId: string, sourceClientId?: string): ConversationState; markConversationRunning(threadId: string): ConversationState; finishConversationRun(threadId: string): ConversationState; /** 判断网页客户端是否仍连接到当前 Agent。 */ hasClient(clientId: string): boolean; /** 读取指定网页上报的画布,避免提炼时受最近焦点或其他标签页影响。 */ canvasStateForClient(clientId: string): CanvasSnapshot | null; /** 原子取得 Codex 写操作权限,避免多个网页并发切换或修改会话。 */ beginCodexMutation(): boolean; /** 释放 Codex 写操作权限。 */ endCodexMutation(): void; /** 返回当前 Codex turn 的线程、turn 和发起网页。 */ get codexEventScope(): { threadId: string; turnId: string; sourceClientId: string; }; /** 返回刷新后仍需展示的 Codex 权限请求。 */ get codexPendingApprovals(): Record[]; /** 跟踪需要跨页面重连恢复的 Codex 权限请求。 */ trackCodexEvent(type: string, payload: Record): void; /** 更新并广播 Codex 运行状态;静默后台活动可保留上一 turn 的断线重放。 */ setCodexState(patch: Partial, options?: { preserveReplay?: boolean; }): void; /** 权威历史已覆盖指定 turn 后,清理其断线重放事件。 */ acknowledgeCodexHistory(threadId: string, turnIds: string[]): void; /** 建立网页与 Canvas Agent 之间的 SSE 连接。 */ openEvents(url: URL, res: ServerResponse, activeThreadId?: string): void; private updateConversation; /** 保存指定网页上报的最新画布快照。 */ updateState(body: unknown, clientId?: string): void; /** 将指定网页设为最近激活的工具目标。 */ activateClient(clientId: string): void; /** 将当前 Agent turn 固定绑定到指定网页。 */ bindClient(clientId: string): void; /** 解除当前 Agent turn 的网页绑定。 */ releaseClient(clientId: string): void; /** 保存当前 turn 可用的图片附件并返回安全引用。 */ setTurnAttachments(clientId: string, attachments: AgentAttachment[]): { id: string; name: string; type: string; size: number; width: number; height: number; }[]; /** 清理指定网页或全部 turn 附件。 */ clearTurnAttachments(clientId?: string): void; /** 获取属于指定网页 turn 的图片附件。 */ getTurnAttachment(clientId: string, attachmentId: string): TurnAttachment; /** 接收网页返回的工具调用结果。 */ resolveResult(clientId: string, body: { requestId?: string; error?: string; result?: unknown; }): boolean; /** 向全部已连接网页广播事件。 */ emitAll(type: string, payload: unknown): void; /** 向全部网页广播带线程归属的事件。 */ emitThread(type: string, threadId: string, payload?: Record): void; /** 为断线重连保存完整的最新文本快照,实时连接仍只接收增量。 */ private replaySnapshot; private clearReplayActiveTurn; /** 校验工具参数并将调用分派到当前目标网页。 */ callTool(name: unknown, rawInput: unknown): Promise; /** 将当前 turn 的附件转换为画布图片节点。 */ private createAttachmentNodes; /** 向目标网页发送工具请求并等待调用结果。 */ private requestCanvasTool; } export {};