@kobinflow/canvas-agent 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +159 -0
- package/agent-instructions.md +13 -0
- package/dist/agent/claude.d.ts +3 -0
- package/dist/agent/claude.js +54 -0
- package/dist/agent/codex-client.d.ts +139 -0
- package/dist/agent/codex-client.js +937 -0
- package/dist/agent/codex-event-history.d.ts +21 -0
- package/dist/agent/codex-event-history.js +163 -0
- package/dist/agent/codex-history.d.ts +46 -0
- package/dist/agent/codex-history.js +822 -0
- package/dist/agent/codex-protocol.d.ts +335 -0
- package/dist/agent/codex-protocol.js +1 -0
- package/dist/agent/codex.d.ts +178 -0
- package/dist/agent/codex.js +509 -0
- package/dist/agent/message-metadata.d.ts +51 -0
- package/dist/agent/message-metadata.js +378 -0
- package/dist/agent/types.d.ts +45 -0
- package/dist/agent/types.js +1 -0
- package/dist/canvas/operations.d.ts +13 -0
- package/dist/canvas/operations.js +167 -0
- package/dist/canvas/schemas.d.ts +989 -0
- package/dist/canvas/schemas.js +155 -0
- package/dist/canvas/session.d.ts +163 -0
- package/dist/canvas/session.js +523 -0
- package/dist/canvas/tools.d.ts +214 -0
- package/dist/canvas/tools.js +27 -0
- package/dist/canvas/types.d.ts +34 -0
- package/dist/canvas/types.js +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +86 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/server/http.d.ts +2 -0
- package/dist/server/http.js +576 -0
- package/dist/server/mcp.d.ts +2 -0
- package/dist/server/mcp.js +27 -0
- package/dist/skills/store.d.ts +54 -0
- package/dist/skills/store.js +426 -0
- package/dist/utils/agent-runtime.d.ts +8 -0
- package/dist/utils/agent-runtime.js +33 -0
- package/dist/utils/date.d.ts +2 -0
- package/dist/utils/date.js +7 -0
- package/dist/utils/logger.d.ts +17 -0
- package/dist/utils/logger.js +81 -0
- package/dist/utils/value.d.ts +5 -0
- package/dist/utils/value.js +8 -0
- package/dist/version-check.d.ts +2 -0
- package/dist/version-check.js +65 -0
- package/package.json +55 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const recordSchema = z.record(z.unknown());
|
|
3
|
+
const positionSchema = z.object({ x: z.number(), y: z.number() });
|
|
4
|
+
const viewportSchema = z.object({ x: z.number(), y: z.number(), k: z.number() });
|
|
5
|
+
const nodeTypeSchema = z.enum(["image", "text", "config", "video", "audio"]);
|
|
6
|
+
const generationModeSchema = z.enum(["text", "image", "video", "audio"]);
|
|
7
|
+
/** Canvas Agent 对外提供的工具名称。 */
|
|
8
|
+
export const toolNames = [
|
|
9
|
+
"site_navigate",
|
|
10
|
+
"canvas_list_projects",
|
|
11
|
+
"canvas_get_state",
|
|
12
|
+
"canvas_get_selection",
|
|
13
|
+
"canvas_export_snapshot",
|
|
14
|
+
"canvas_apply_ops",
|
|
15
|
+
"canvas_create_node",
|
|
16
|
+
"canvas_create_attachment_nodes",
|
|
17
|
+
"canvas_create_text_node",
|
|
18
|
+
"canvas_create_text_nodes",
|
|
19
|
+
"canvas_create_config_node",
|
|
20
|
+
"canvas_create_image_prompt_flow",
|
|
21
|
+
"canvas_create_generation_flow",
|
|
22
|
+
"canvas_generate_text",
|
|
23
|
+
"canvas_generate_image",
|
|
24
|
+
"canvas_generate_video",
|
|
25
|
+
"canvas_generate_audio",
|
|
26
|
+
"canvas_update_node",
|
|
27
|
+
"canvas_update_node_text",
|
|
28
|
+
"canvas_move_nodes",
|
|
29
|
+
"canvas_resize_node",
|
|
30
|
+
"canvas_delete_nodes",
|
|
31
|
+
"canvas_connect_nodes",
|
|
32
|
+
"canvas_select_nodes",
|
|
33
|
+
"canvas_set_viewport",
|
|
34
|
+
"canvas_run_generation",
|
|
35
|
+
"generation_get_status",
|
|
36
|
+
"workbench_image_get_config",
|
|
37
|
+
"workbench_image_generate",
|
|
38
|
+
"workbench_video_get_config",
|
|
39
|
+
"workbench_video_generate",
|
|
40
|
+
"prompts_search",
|
|
41
|
+
"assets_list",
|
|
42
|
+
"assets_add",
|
|
43
|
+
];
|
|
44
|
+
export const canvasOpSchema = z.discriminatedUnion("type", [
|
|
45
|
+
z.object({ type: z.literal("add_node"), nodeType: nodeTypeSchema.optional(), id: z.string().optional(), title: z.string().optional(), x: z.number().optional(), y: z.number().optional(), width: z.number().optional(), height: z.number().optional(), position: positionSchema.optional(), metadata: recordSchema.optional() }).passthrough(),
|
|
46
|
+
z.object({ type: z.literal("update_node"), id: z.string(), patch: recordSchema.optional(), metadata: recordSchema.optional() }).passthrough(),
|
|
47
|
+
z.object({ type: z.literal("delete_node"), id: z.string().optional(), ids: z.array(z.string()).optional() }).passthrough(),
|
|
48
|
+
z.object({ type: z.literal("delete_connections"), id: z.string().optional(), ids: z.array(z.string()).optional(), all: z.boolean().optional() }).passthrough(),
|
|
49
|
+
z.object({ type: z.literal("connect_nodes"), id: z.string().optional(), fromNodeId: z.string(), toNodeId: z.string() }).passthrough(),
|
|
50
|
+
z.object({ type: z.literal("set_viewport"), viewport: viewportSchema }).passthrough(),
|
|
51
|
+
z.object({ type: z.literal("select_nodes"), ids: z.array(z.string()) }).passthrough(),
|
|
52
|
+
z.object({ type: z.literal("run_generation"), nodeId: z.string(), mode: generationModeSchema.optional(), prompt: z.string().optional() }).passthrough(),
|
|
53
|
+
]);
|
|
54
|
+
const textNodeSchema = z.object({
|
|
55
|
+
text: z.string(),
|
|
56
|
+
title: z.string().optional(),
|
|
57
|
+
x: z.number().optional(),
|
|
58
|
+
y: z.number().optional(),
|
|
59
|
+
width: z.number().optional(),
|
|
60
|
+
height: z.number().optional(),
|
|
61
|
+
});
|
|
62
|
+
const generationOptionsSchema = z.object({
|
|
63
|
+
model: z.string().optional(),
|
|
64
|
+
size: z.string().optional(),
|
|
65
|
+
quality: z.string().optional(),
|
|
66
|
+
count: z.number().optional(),
|
|
67
|
+
seconds: z.string().optional(),
|
|
68
|
+
vquality: z.string().optional(),
|
|
69
|
+
generateAudio: z.string().optional(),
|
|
70
|
+
watermark: z.string().optional(),
|
|
71
|
+
videoMode: z.string().optional(),
|
|
72
|
+
audioVoice: z.string().optional(),
|
|
73
|
+
audioFormat: z.string().optional(),
|
|
74
|
+
audioSpeed: z.string().optional(),
|
|
75
|
+
audioInstructions: z.string().optional(),
|
|
76
|
+
});
|
|
77
|
+
const generationFlowSchema = z.object({
|
|
78
|
+
prompt: z.string(),
|
|
79
|
+
title: z.string().optional(),
|
|
80
|
+
x: z.number().optional(),
|
|
81
|
+
y: z.number().optional(),
|
|
82
|
+
referenceNodeIds: z.array(z.string()).optional(),
|
|
83
|
+
});
|
|
84
|
+
export const toolInputSchemas = {
|
|
85
|
+
site_navigate: z.object({ path: z.string() }),
|
|
86
|
+
canvas_list_projects: z.object({ keyword: z.string().optional(), page: z.number().optional(), pageSize: z.number().optional() }),
|
|
87
|
+
canvas_get_state: z.object({}).passthrough(),
|
|
88
|
+
canvas_get_selection: z.object({}).passthrough(),
|
|
89
|
+
canvas_export_snapshot: z.object({}).passthrough(),
|
|
90
|
+
canvas_apply_ops: z.object({ ops: z.array(canvasOpSchema) }),
|
|
91
|
+
canvas_create_node: z.object({ nodeType: nodeTypeSchema, title: z.string().optional(), x: z.number().optional(), y: z.number().optional(), width: z.number().optional(), height: z.number().optional(), metadata: recordSchema.optional() }),
|
|
92
|
+
canvas_create_attachment_nodes: z.object({ attachmentIds: z.array(z.string()).min(1), x: z.number().optional(), y: z.number().optional(), gap: z.number().optional(), direction: z.enum(["row", "column"]).optional() }),
|
|
93
|
+
canvas_create_text_node: z.object({ text: z.string().optional(), x: z.number().optional(), y: z.number().optional(), title: z.string().optional(), width: z.number().optional(), height: z.number().optional() }),
|
|
94
|
+
canvas_create_text_nodes: z.object({ items: z.array(textNodeSchema).min(1), x: z.number().optional(), y: z.number().optional(), gap: z.number().optional(), direction: z.enum(["row", "column"]).optional() }),
|
|
95
|
+
canvas_create_config_node: z.object({ prompt: z.string().optional(), mode: generationModeSchema.optional(), title: z.string().optional(), x: z.number().optional(), y: z.number().optional(), width: z.number().optional(), height: z.number().optional(), autoRun: z.boolean().optional() }).merge(generationOptionsSchema),
|
|
96
|
+
canvas_create_image_prompt_flow: z.object({ prompt: z.string(), x: z.number().optional(), y: z.number().optional(), autoRun: z.boolean().optional() }).merge(generationOptionsSchema),
|
|
97
|
+
canvas_create_generation_flow: generationFlowSchema.extend({ mode: generationModeSchema.optional(), autoRun: z.boolean().optional() }).merge(generationOptionsSchema),
|
|
98
|
+
canvas_generate_text: generationFlowSchema.merge(generationOptionsSchema),
|
|
99
|
+
canvas_generate_image: generationFlowSchema.merge(generationOptionsSchema),
|
|
100
|
+
canvas_generate_video: generationFlowSchema.merge(generationOptionsSchema),
|
|
101
|
+
canvas_generate_audio: generationFlowSchema.merge(generationOptionsSchema),
|
|
102
|
+
canvas_update_node: z.object({ id: z.string(), patch: recordSchema.optional(), metadata: recordSchema.optional() }),
|
|
103
|
+
canvas_update_node_text: z.object({ id: z.string(), text: z.string(), title: z.string().optional() }),
|
|
104
|
+
canvas_move_nodes: z.object({ items: z.array(z.object({ id: z.string(), x: z.number().optional(), y: z.number().optional(), dx: z.number().optional(), dy: z.number().optional() })).min(1) }),
|
|
105
|
+
canvas_resize_node: z.object({ id: z.string(), width: z.number(), height: z.number(), freeResize: z.boolean().optional() }),
|
|
106
|
+
canvas_delete_nodes: z.object({ ids: z.array(z.string()).min(1) }),
|
|
107
|
+
canvas_connect_nodes: z.object({ connections: z.array(z.object({ fromNodeId: z.string(), toNodeId: z.string() })).min(1) }),
|
|
108
|
+
canvas_select_nodes: z.object({ ids: z.array(z.string()) }),
|
|
109
|
+
canvas_set_viewport: z.object({ viewport: viewportSchema }),
|
|
110
|
+
canvas_run_generation: z.object({ nodeId: z.string(), mode: generationModeSchema.optional(), prompt: z.string().optional() }),
|
|
111
|
+
generation_get_status: z.object({ scope: z.enum(["all", "canvas", "image", "video"]).optional(), taskId: z.string().optional(), nodeIds: z.array(z.string()).optional(), limit: z.number().optional() }),
|
|
112
|
+
workbench_image_get_config: z.object({}).passthrough(),
|
|
113
|
+
workbench_image_generate: z.object({ prompt: z.string(), model: z.string().optional(), quality: z.string().optional(), size: z.string().optional(), count: z.number().optional(), run: z.boolean().optional() }),
|
|
114
|
+
workbench_video_get_config: z.object({}).passthrough(),
|
|
115
|
+
workbench_video_generate: z.object({ prompt: z.string(), model: z.string().optional(), size: z.string().optional(), seconds: z.string().optional(), resolution: z.string().optional(), generateAudio: z.boolean().optional(), watermark: z.boolean().optional(), mode: z.enum(["frames", "reference"]).optional(), run: z.boolean().optional() }),
|
|
116
|
+
prompts_search: z.object({ keyword: z.string().optional(), category: z.string().optional(), tags: z.array(z.string()).optional(), page: z.number().optional(), pageSize: z.number().optional() }),
|
|
117
|
+
assets_list: z.object({ kind: z.enum(["all", "text", "image", "video"]).optional(), keyword: z.string().optional(), page: z.number().optional(), pageSize: z.number().optional() }),
|
|
118
|
+
assets_add: z.object({ kind: z.enum(["text", "image"]), title: z.string(), content: z.string().optional(), imageUrl: z.string().optional(), tags: z.array(z.string()).optional(), source: z.string().optional(), note: z.string().optional() }),
|
|
119
|
+
};
|
|
120
|
+
export const toolDescriptions = {
|
|
121
|
+
site_navigate: "跳转网站页面。path 可为 / (首页)、/canvas (我的画布)、/canvas/:id (指定画布)、/image (生图工作台)、/video (视频创作台)、/prompts (提示词库)、/assets (我的素材)、/config (配置)。操作画布前若不在画布页,先用本工具打开画布。",
|
|
122
|
+
canvas_list_projects: "列出用户全部画布(仅标题、创建/更新时间、节点数、连线数,不含完整数据),支持 keyword 搜索和 page/pageSize 分页。返回的 id 可配合 site_navigate 跳转到 /canvas/:id 打开对应画布。",
|
|
123
|
+
canvas_get_state: "读取当前网页画布的节点、连线、选区和视口。",
|
|
124
|
+
canvas_get_selection: "读取当前网页画布选中的节点。",
|
|
125
|
+
canvas_export_snapshot: "导出当前画布快照,用于理解布局。",
|
|
126
|
+
canvas_apply_ops: "批量操作当前网页画布。ops 支持 add_node、update_node、delete_node、delete_connections、connect_nodes、set_viewport、select_nodes、run_generation。",
|
|
127
|
+
canvas_create_node: "创建任意类型节点:text、image、config、video、audio。适合创建占位图、媒体占位、配置节点或自定义 metadata 节点。",
|
|
128
|
+
canvas_create_attachment_nodes: "把当前对话中用户上传的图片附件创建成真实画布图片节点。attachmentIds 使用本轮附件清单中的 ID;返回的节点 ID 可传给 canvas_create_generation_flow.referenceNodeIds 作为生成参考图。",
|
|
129
|
+
canvas_create_text_node: "在当前画布创建单个文本节点。",
|
|
130
|
+
canvas_create_text_nodes: "批量创建文本节点,适合生成标题、段落、脚本、说明等内容块。",
|
|
131
|
+
canvas_create_config_node: "创建生成配置节点,可指定 text/image/video/audio 模式和生成参数,可选择立即触发生成。",
|
|
132
|
+
canvas_create_image_prompt_flow: "创建提示词文本节点和图片生成配置节点,并自动连线,可选择立即触发生图。",
|
|
133
|
+
canvas_create_generation_flow: "创建通用生成流程:提示词文本节点、生成配置节点、参考节点连线,可用于文案、生图、视频或音频。",
|
|
134
|
+
canvas_generate_text: "创建通用文本生成流程并立即触发生成。",
|
|
135
|
+
canvas_generate_image: "创建通用图片生成流程并立即触发生成。",
|
|
136
|
+
canvas_generate_video: "创建通用视频生成流程并立即触发生成。",
|
|
137
|
+
canvas_generate_audio: "创建通用音频生成流程并立即触发生成。",
|
|
138
|
+
canvas_update_node: "更新节点基础字段或 metadata。",
|
|
139
|
+
canvas_update_node_text: "更新文本节点内容和标题。",
|
|
140
|
+
canvas_move_nodes: "移动一个或多个节点,支持绝对坐标或 dx/dy 偏移。",
|
|
141
|
+
canvas_resize_node: "调整节点尺寸。",
|
|
142
|
+
canvas_delete_nodes: "删除指定节点及相关连线。",
|
|
143
|
+
canvas_connect_nodes: "批量连接节点。",
|
|
144
|
+
canvas_select_nodes: "设置当前选中节点。",
|
|
145
|
+
canvas_set_viewport: "调整画布视口。",
|
|
146
|
+
canvas_run_generation: "触发指定节点生成,通常用于配置节点或文本/图片/视频/音频节点。",
|
|
147
|
+
generation_get_status: "查询当前活动网页的生成任务状态。默认返回画布、生图工作台和视频工作台最近任务;可用 scope 过滤来源,用 taskId 查询工作台任务,用 nodeIds 查询画布节点。",
|
|
148
|
+
workbench_image_get_config: "读取生图工作台的当前参数和可选项(可用模型、质量、分辨率 1k/2k/4k/auto、宽高比、张数范围),在调用 workbench_image_generate 前先了解可选值。",
|
|
149
|
+
workbench_image_generate: "在生图工作台填入提示词并按需设置 model、quality、size(如 16:9 或 2048x1152)、count,run 默认 true 会自动点击生成按钮。会自动跳转到生图工作台。生成为异步过程,提交后返回 taskId,可用 generation_get_status 查询状态。",
|
|
150
|
+
workbench_video_get_config: "读取视频创作台的当前参数和可选项(可用模型、清晰度 480/720/1080、比例 1:1/3:4/4:3/16:9/9:16/21:9/auto、时长 4–30 秒、首尾帧或全能参考模式、是否生成声音与水印)。",
|
|
151
|
+
workbench_video_generate: "在视频创作台填入提示词并按需设置 model、size(1:1、3:4、4:3、16:9、9:16、21:9、auto 或 1280x720)、seconds(4–30)、resolution(480/720/1080)、generateAudio、watermark、mode(frames 首尾帧 / reference 全能参考),run 默认 true 会自动点击生成按钮。会自动跳转到视频创作台。生成为异步过程,提交后返回 taskId,可用 generation_get_status 查询状态。",
|
|
152
|
+
prompts_search: "搜索提示词库(第三方提示词合集),支持 keyword、category、tags 过滤和 page/pageSize 分页,返回标题、提示词、分类、标签、封面等。",
|
|
153
|
+
assets_list: "列出用户「我的素材」,支持 kind(text/image/video)过滤、keyword 搜索和 page/pageSize 分页。为控制体积不返回图片/视频原始 data,仅返回封面与元信息。",
|
|
154
|
+
assets_add: "向「我的素材」新增素材。kind=text 时用 content 传文本内容;kind=image 时用 imageUrl 传图片地址或 dataURL。可附带 title、tags、source、note。",
|
|
155
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
import type { AgentAttachment } from "../agent/types.js";
|
|
3
|
+
import type { CanvasSnapshot } from "./types.js";
|
|
4
|
+
type TurnAttachment = {
|
|
5
|
+
clientId: string;
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
size: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
dataUrl: string;
|
|
13
|
+
};
|
|
14
|
+
export type CodexState = {
|
|
15
|
+
busy: boolean;
|
|
16
|
+
threadId: string;
|
|
17
|
+
turnId: string;
|
|
18
|
+
};
|
|
19
|
+
export type McpStartupState = "starting" | "ready" | "failed" | "cancelled";
|
|
20
|
+
export type ConversationState = {
|
|
21
|
+
revision: number;
|
|
22
|
+
conversationId: string;
|
|
23
|
+
threadId: string;
|
|
24
|
+
status: "idle" | "preparing" | "ready" | "warning" | "running" | "failed";
|
|
25
|
+
mcpStatuses: Record<string, {
|
|
26
|
+
status: McpStartupState;
|
|
27
|
+
error?: string | null;
|
|
28
|
+
failureReason?: string | null;
|
|
29
|
+
}>;
|
|
30
|
+
sourceClientId?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
type McpInventoryItem = {
|
|
34
|
+
name: string;
|
|
35
|
+
authStatus?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const AGENT_PROTOCOL_VERSION = 6;
|
|
38
|
+
/** 管理网页画布连接、状态、附件和工具请求。 */
|
|
39
|
+
export declare class CanvasSession {
|
|
40
|
+
private clients;
|
|
41
|
+
private clientFocusOrder;
|
|
42
|
+
private pending;
|
|
43
|
+
private pendingApprovals;
|
|
44
|
+
private canvasStates;
|
|
45
|
+
private turnAttachments;
|
|
46
|
+
private codexReplayEvents;
|
|
47
|
+
private codexReplayActiveItems;
|
|
48
|
+
private codexMutationBusy;
|
|
49
|
+
private activeClientId;
|
|
50
|
+
private boundClientId;
|
|
51
|
+
private focusSequence;
|
|
52
|
+
private codexState;
|
|
53
|
+
private conversationState;
|
|
54
|
+
private conversationInventoryComplete;
|
|
55
|
+
private preparedConversationThreadId;
|
|
56
|
+
constructor(activeThreadId?: string);
|
|
57
|
+
/** 获取当前目标网页的画布状态。 */
|
|
58
|
+
private get canvasState();
|
|
59
|
+
/** 获取当前 turn 绑定或最近激活的网页客户端。 */
|
|
60
|
+
private get targetClientId();
|
|
61
|
+
/** 返回 Canvas Agent 当前连接状态。 */
|
|
62
|
+
health(): {
|
|
63
|
+
ok: boolean;
|
|
64
|
+
protocolVersion: number;
|
|
65
|
+
hasCanvas: boolean;
|
|
66
|
+
clients: number;
|
|
67
|
+
codexBusy: boolean;
|
|
68
|
+
conversation: ConversationState;
|
|
69
|
+
};
|
|
70
|
+
/** 返回 Codex 是否正在执行任务。 */
|
|
71
|
+
get codexBusy(): boolean;
|
|
72
|
+
get codexThreadId(): string;
|
|
73
|
+
/** Return a copy that callers can restore after a temporary Codex operation. */
|
|
74
|
+
get codexStateSnapshot(): CodexState;
|
|
75
|
+
/** 返回站点级对话的权威快照。 */
|
|
76
|
+
get conversationStateSnapshot(): ConversationState;
|
|
77
|
+
/** 原子开始一次新建或恢复对话流程。 */
|
|
78
|
+
beginConversation(options?: {
|
|
79
|
+
threadId?: string;
|
|
80
|
+
conversationId?: string;
|
|
81
|
+
sourceClientId?: string;
|
|
82
|
+
}): ConversationState;
|
|
83
|
+
/** 记录预热阶段单个 MCP 服务的启动状态。 */
|
|
84
|
+
updateConversationMcp(name: string, status: McpStartupState, error?: string | null, failureReason?: string | null): ConversationState;
|
|
85
|
+
/** 用 app-server 的完整 MCP 清单补齐未发送逐项通知的服务。 */
|
|
86
|
+
completeConversationMcpInventory(services: McpInventoryItem[]): ConversationState;
|
|
87
|
+
/** MCP 清单读取结束后提交线程和最终可发送状态。 */
|
|
88
|
+
completeConversationPreparation(threadId: string): ConversationState;
|
|
89
|
+
/** 将创建线程或读取 MCP 清单的失败保存为不可发送状态。 */
|
|
90
|
+
failConversationPreparation(error: string): ConversationState;
|
|
91
|
+
/** 切换到无需重新预热的既有状态,例如删除当前对话后的空状态。 */
|
|
92
|
+
activateConversation(threadId: string, sourceClientId?: string): ConversationState;
|
|
93
|
+
markConversationRunning(threadId: string): ConversationState;
|
|
94
|
+
finishConversationRun(threadId: string): ConversationState;
|
|
95
|
+
/** 判断网页客户端是否仍连接到当前 Agent。 */
|
|
96
|
+
hasClient(clientId: string): boolean;
|
|
97
|
+
/** 读取指定网页上报的画布,避免提炼时受最近焦点或其他标签页影响。 */
|
|
98
|
+
canvasStateForClient(clientId: string): CanvasSnapshot | null;
|
|
99
|
+
/** 原子取得 Codex 写操作权限,避免多个网页并发切换或修改会话。 */
|
|
100
|
+
beginCodexMutation(): boolean;
|
|
101
|
+
/** 释放 Codex 写操作权限。 */
|
|
102
|
+
endCodexMutation(): void;
|
|
103
|
+
/** 返回当前 Codex turn 的线程、turn 和发起网页。 */
|
|
104
|
+
get codexEventScope(): {
|
|
105
|
+
threadId: string;
|
|
106
|
+
turnId: string;
|
|
107
|
+
sourceClientId: string;
|
|
108
|
+
};
|
|
109
|
+
/** 返回刷新后仍需展示的 Codex 权限请求。 */
|
|
110
|
+
get codexPendingApprovals(): Record<string, unknown>[];
|
|
111
|
+
/** 跟踪需要跨页面重连恢复的 Codex 权限请求。 */
|
|
112
|
+
trackCodexEvent(type: string, payload: Record<string, unknown>): void;
|
|
113
|
+
/** 更新并广播 Codex 运行状态;静默后台活动可保留上一 turn 的断线重放。 */
|
|
114
|
+
setCodexState(patch: Partial<CodexState>, options?: {
|
|
115
|
+
preserveReplay?: boolean;
|
|
116
|
+
}): void;
|
|
117
|
+
/** 权威历史已覆盖指定 turn 后,清理其断线重放事件。 */
|
|
118
|
+
acknowledgeCodexHistory(threadId: string, turnIds: string[]): void;
|
|
119
|
+
/** 建立网页与 Canvas Agent 之间的 SSE 连接。 */
|
|
120
|
+
openEvents(url: URL, res: ServerResponse, activeThreadId?: string): void;
|
|
121
|
+
private updateConversation;
|
|
122
|
+
/** 保存指定网页上报的最新画布快照。 */
|
|
123
|
+
updateState(body: unknown, clientId?: string): void;
|
|
124
|
+
/** 将指定网页设为最近激活的工具目标。 */
|
|
125
|
+
activateClient(clientId: string): void;
|
|
126
|
+
/** 将当前 Agent turn 固定绑定到指定网页。 */
|
|
127
|
+
bindClient(clientId: string): void;
|
|
128
|
+
/** 解除当前 Agent turn 的网页绑定。 */
|
|
129
|
+
releaseClient(clientId: string): void;
|
|
130
|
+
/** 保存当前 turn 可用的图片附件并返回安全引用。 */
|
|
131
|
+
setTurnAttachments(clientId: string, attachments: AgentAttachment[]): {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
type: string;
|
|
135
|
+
size: number;
|
|
136
|
+
width: number;
|
|
137
|
+
height: number;
|
|
138
|
+
}[];
|
|
139
|
+
/** 清理指定网页或全部 turn 附件。 */
|
|
140
|
+
clearTurnAttachments(clientId?: string): void;
|
|
141
|
+
/** 获取属于指定网页 turn 的图片附件。 */
|
|
142
|
+
getTurnAttachment(clientId: string, attachmentId: string): TurnAttachment;
|
|
143
|
+
/** 接收网页返回的工具调用结果。 */
|
|
144
|
+
resolveResult(clientId: string, body: {
|
|
145
|
+
requestId?: string;
|
|
146
|
+
error?: string;
|
|
147
|
+
result?: unknown;
|
|
148
|
+
}): boolean;
|
|
149
|
+
/** 向全部已连接网页广播事件。 */
|
|
150
|
+
emitAll(type: string, payload: unknown): void;
|
|
151
|
+
/** 向全部网页广播带线程归属的事件。 */
|
|
152
|
+
emitThread(type: string, threadId: string, payload?: Record<string, unknown>): void;
|
|
153
|
+
/** 为断线重连保存完整的最新文本快照,实时连接仍只接收增量。 */
|
|
154
|
+
private replaySnapshot;
|
|
155
|
+
private clearReplayActiveTurn;
|
|
156
|
+
/** 校验工具参数并将调用分派到当前目标网页。 */
|
|
157
|
+
callTool(name: unknown, rawInput: unknown): Promise<unknown>;
|
|
158
|
+
/** 将当前 turn 的附件转换为画布图片节点。 */
|
|
159
|
+
private createAttachmentNodes;
|
|
160
|
+
/** 向目标网页发送工具请求并等待调用结果。 */
|
|
161
|
+
private requestCanvasTool;
|
|
162
|
+
}
|
|
163
|
+
export {};
|