@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
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 basketikun
|
|
4
|
+
Copyright (c) 2026 KobinFlow (kobingogo) — modifications for 点染 Dianran
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# 点染 Dianran · Canvas Agent
|
|
2
|
+
|
|
3
|
+
本地 Canvas Agent 用来连接画布网页和用户电脑上的 Codex / Claude Code。本地开发时优先连接 `http://localhost:3000`,不需要先使用线上站点。
|
|
4
|
+
|
|
5
|
+
## 启动
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y @kobinflow/canvas-agent@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
带上 `@latest` 是因为 npx 会缓存已下载的版本,不加就可能一直运行旧版本。
|
|
12
|
+
|
|
13
|
+
需要排查连接、线程、Codex app-server 或工具调用问题时,可开启 Debug 模式:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx -y @kobinflow/canvas-agent@latest --debug
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Debug 日志会以 `[DEBUG][HH:mm:ss]` 等传统格式输出到终端,并按启动日期保存到 `~/.infinite-canvas/logs/canvas-agent-YYYY-MM-DD.log`。终端日志带级别颜色,文件日志为纯文本;日志包含 HTTP、SSE、线程、turn、Codex app-server 和工具调用事件,token 与图片 Data URL 会自动隐藏。
|
|
20
|
+
|
|
21
|
+
本仓库开发时也可以直接运行:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd canvas-agent
|
|
25
|
+
npm install
|
|
26
|
+
npm run build
|
|
27
|
+
node dist/index.js
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
启动后会输出本机地址和 token:
|
|
31
|
+
|
|
32
|
+
```txt
|
|
33
|
+
Local URL: http://127.0.0.1:17371
|
|
34
|
+
Connect token: xxxxxx
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
在画布右上角点击 `Agent`,填入地址和 token 后连接。
|
|
38
|
+
|
|
39
|
+
Codex app 插件会读取启动输出里的 Local URL 和 Connect token,并直接打开画布网页地址;Canvas Agent 不负责生成画布打开 URL。
|
|
40
|
+
|
|
41
|
+
Canvas Agent 默认只监听 `127.0.0.1`。网页第一次带正确 token 连接后,Canvas Agent 会记录该网页 Origin;之后其他 Origin 不能复用这个本地 Agent,除非用户清理 `~/.infinite-canvas/canvas-agent.json` 里的 `origins`。
|
|
42
|
+
|
|
43
|
+
## 发布
|
|
44
|
+
|
|
45
|
+
`canvas-agent` 使用自己的 `package.json` 版本号,不跟仓库根目录 `VERSION` 绑定。推送到 `main` 后,GitHub Actions 会检查 npm 上是否已经存在当前包版本;不存在时才发布 `@kobinflow/canvas-agent`。
|
|
46
|
+
|
|
47
|
+
发布前需要在 GitHub 仓库 Secrets 中配置 `NPM_TOKEN`。
|
|
48
|
+
|
|
49
|
+
## Codex MCP
|
|
50
|
+
|
|
51
|
+
如果希望 Codex 终端能直接操作画布,需要先把 Canvas Agent 注册成 Codex MCP。
|
|
52
|
+
|
|
53
|
+
直接运行 `npx -y @kobinflow/canvas-agent@latest` 只启动本地 Agent 服务,不会安装 MCP,也不会增加 Codex 工具上下文。只有安装 Codex app 插件,或手动执行 `codex mcp add` 后,`infinite-canvas` 工具才会进入 Codex 上下文;由于工具较多,不使用时建议移除。
|
|
54
|
+
|
|
55
|
+
通过插件安装时移除插件:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
codex plugin remove infinite-canvas
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
手动添加 MCP 时移除 MCP:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
codex mcp remove infinite-canvas
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Codex app 插件
|
|
68
|
+
|
|
69
|
+
仓库内提供了 Codex app 插件:`plugins/infinite-canvas`。在 Codex app 中添加本仓库的 marketplace 后,可以安装 `Infinite Canvas` 插件;插件会注册同一个 `infinite-canvas` MCP,并带上画布操作说明。
|
|
70
|
+
|
|
71
|
+
添加本地 marketplace 时建议使用仓库绝对路径,避免 Codex 从其他工作目录解析失败:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cd /path/to/infinite-canvas
|
|
75
|
+
codex plugin marketplace add "$(pwd)"
|
|
76
|
+
codex plugin add infinite-canvas@infinite-canvas-local
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
插件默认通过 npm 启动 MCP;这个命令只提供 MCP 工具,不会把 MCP 写入全局配置,也不会在退出时自动卸载:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx -y @kobinflow/canvas-agent@latest mcp
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
使用时可以直接在 Codex 里说“打开 Infinite Canvas”,插件会启动本地 Agent,读取 Local URL 和 Connect token,然后在右侧打开 `https://canvas.best/` 并自动新建、连接画布;只有明确要求使用本地项目时才会启动本地前端。
|
|
86
|
+
|
|
87
|
+
Canvas Agent 启动后,给 Codex 添加 MCP:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
codex mcp add infinite-canvas -- npx -y @kobinflow/canvas-agent@latest mcp
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
本仓库开发时可以改成,实际使用建议替换为本机绝对路径:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
codex mcp add infinite-canvas -- node /path/to/infinite-canvas/canvas-agent/dist/index.js mcp
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Canvas Agent 源码使用 TypeScript 编写,MCP 协议层使用官方 `@modelcontextprotocol/sdk`,工具入参使用 `zod` 描述。
|
|
100
|
+
|
|
101
|
+
如果希望终端里的 Codex 不被 MCP 审批卡住,可以在 `~/.codex/config.toml` 里给这个 MCP 设置自动放行:
|
|
102
|
+
|
|
103
|
+
```toml
|
|
104
|
+
[mcp_servers.infinite-canvas]
|
|
105
|
+
command = "npx"
|
|
106
|
+
args = ["-y", "@kobinflow/canvas-agent@latest", "mcp"]
|
|
107
|
+
default_tools_approval_mode = "approve"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
可用工具:
|
|
111
|
+
|
|
112
|
+
- `canvas_get_state`
|
|
113
|
+
- `canvas_get_selection`
|
|
114
|
+
- `canvas_export_snapshot`
|
|
115
|
+
- `canvas_apply_ops`
|
|
116
|
+
- `canvas_create_text_node`
|
|
117
|
+
- `canvas_create_image_prompt_flow`
|
|
118
|
+
|
|
119
|
+
`canvas_apply_ops` 示例:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"ops": [
|
|
124
|
+
{
|
|
125
|
+
"type": "add_node",
|
|
126
|
+
"nodeType": "text",
|
|
127
|
+
"title": "标题",
|
|
128
|
+
"position": { "x": 0, "y": 0 },
|
|
129
|
+
"metadata": { "content": "文本内容" }
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 侧边栏 Codex
|
|
136
|
+
|
|
137
|
+
本地面板会把提示词发送给 Canvas Agent。Canvas Agent 使用官方 `@openai/codex` CLI 的 `codex app-server --stdio` 启动并复用同一个 Codex thread,启动时会注入 `infinite-canvas` MCP 配置并自动放行 MCP 审批,真正执行画布修改前仍由网页侧边栏二次确认。
|
|
138
|
+
|
|
139
|
+
侧边栏会展示 Codex 返回的 `thread.started`、`turn.started`、`item.*`、`turn.completed` 等结构化事件;Canvas Agent 会合并短时间内的回复、思考摘要和命令输出增量,网页使用同一条消息持续更新,并把任务进度、计划、搜索、文件修改与工具操作整理为中文过程时间线。
|
|
140
|
+
|
|
141
|
+
侧边栏上传或粘贴的图片会先发到本机 Canvas Agent,再由 Canvas Agent 临时写入本机文件并作为 app-server `localImage` 输入传给 Codex;前端会提示附件体积,单次请求体限制为 30MB。
|
|
142
|
+
|
|
143
|
+
## Claude Code
|
|
144
|
+
|
|
145
|
+
Claude Code Adapter 代码暂时保留,但当前网页侧边栏只开放 Codex。后续开放 Claude 入口时,Canvas Agent 会调用本机 `claude -p --output-format stream-json` 并把流式 JSON 事件转发到侧边栏。
|
|
146
|
+
|
|
147
|
+
如果希望 Claude Code 也能操作画布,需要给 Claude Code 添加同一个 MCP。建议用 user scope,避免 Canvas Agent 从不同目录启动时找不到配置:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
claude mcp add --scope user --transport stdio infinite-canvas -- npx -y @kobinflow/canvas-agent@latest mcp
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
本仓库开发时可以改成:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
claude mcp add --scope user --transport stdio infinite-canvas -- node /path/to/infinite-canvas/canvas-agent/dist/index.js mcp
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Canvas Agent 调用 Claude Code 时会默认带上 `--allowedTools mcp__infinite-canvas__*`,画布写操作仍由网页侧边栏确认。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Infinite Canvas Agent
|
|
2
|
+
|
|
3
|
+
你正在帮助用户操作点染(Dianran)画布网站。
|
|
4
|
+
|
|
5
|
+
- 用户要求操作画布时,默认目标就是网页当前已经打开的画布。需要了解内容时先使用 `canvas_get_state`;读取成功后直接在该画布执行任务,不要调用 `canvas_list_projects`,也不要用 `site_navigate` 重复进入画布。
|
|
6
|
+
- 只有用户明确要求查看、选择或切换其他画布,或者 `canvas_get_state` 明确提示当前没有已连接画布时,才使用 `canvas_list_projects` 和 `site_navigate`。`site_navigate` 可跳转 `/`、`/canvas`、`/canvas/:id`、`/image`、`/video`、`/prompts`、`/assets`、`/config`。
|
|
7
|
+
- 修改当前画布时根据任务使用已配置的 infinite-canvas MCP 工具;复杂批量改动使用 `canvas_apply_ops`。
|
|
8
|
+
- 用户要求把上传附件放入画布或作为生成参考图时,必须先用 `canvas_create_attachment_nodes` 创建真实图片节点,再把节点 ID 传给生成流程,不要创建空图片占位节点。
|
|
9
|
+
- 生图与视频工作台分别使用 `workbench_image_*`、`workbench_video_*` 工具;提示词和素材分别使用 `prompts_search`、`assets_*` 工具。
|
|
10
|
+
- 用户要求生成图片、视频、音频或文本时,默认调用对应的 `canvas_generate_image`、`canvas_generate_video`、`canvas_generate_audio`、`canvas_generate_text`,通过当前画布的生成节点完成任务。
|
|
11
|
+
- 只有用户明确要求使用“Codex 内置生图”“ImageGen 技能”或意思明确相同的能力时,才使用 Codex 自带的 `imagegen`;不要因为用户只说“生成图片”就自行改用内置生图。内置生图完成后,其结果会由 Canvas Agent 自动展示到对话并插入当前画布,无需再创建空节点或重复生成。
|
|
12
|
+
- 只有用户明确说要在生图/视频工作台生成时,才使用 `workbench_image_*`、`workbench_video_*`。生成任务提交后应说明已经在画布或工作台开始生成,不要在实际没有结果时声称“已生成”。
|
|
13
|
+
- 需要生成内容时直接调用对应生成工具,不要绑定特定业务场景,不要模拟鼠标点击,不要要求用户手动复制 JSON。
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { AGENT_PROMPT } from "../config.js";
|
|
3
|
+
import { createAgentLogWriter } from "../utils/agent-runtime.js";
|
|
4
|
+
import { errorMessage } from "../utils/value.js";
|
|
5
|
+
/** 使用 Claude CLI 执行一次带 Canvas Agent 工具的任务。 */
|
|
6
|
+
export function runClaudeTurn(prompt, emit) {
|
|
7
|
+
const fullPrompt = withAgentPrompt(prompt);
|
|
8
|
+
if (!fullPrompt)
|
|
9
|
+
return;
|
|
10
|
+
const child = spawnAgent("claude", ["-p", "--output-format", "stream-json", "--verbose", "--include-partial-messages", "--allowedTools", "mcp__infinite-canvas__*", fullPrompt], emit);
|
|
11
|
+
if (child)
|
|
12
|
+
pipeJsonLines(child, emit, "claude");
|
|
13
|
+
}
|
|
14
|
+
/** 为 Claude CLI 请求拼接 Canvas Agent 指令。 */
|
|
15
|
+
function withAgentPrompt(prompt) {
|
|
16
|
+
return prompt.trim() ? `${AGENT_PROMPT}\n\n用户请求:${prompt}` : "";
|
|
17
|
+
}
|
|
18
|
+
/** 将 Claude CLI 的 JSON Lines 输出转换为 Agent 事件。 */
|
|
19
|
+
function pipeJsonLines(child, emit, agent) {
|
|
20
|
+
let out = "";
|
|
21
|
+
const stderr = createAgentLogWriter((text) => emit("agent_log", { text }));
|
|
22
|
+
child.stdout?.on("data", (chunk) => {
|
|
23
|
+
out += chunk.toString();
|
|
24
|
+
const lines = out.split(/\r?\n/);
|
|
25
|
+
out = lines.pop() || "";
|
|
26
|
+
lines.filter(Boolean).forEach((line) => {
|
|
27
|
+
try {
|
|
28
|
+
emit("agent_event", { agent, ...JSON.parse(line) });
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
emit("agent_event", { agent, type: "raw", text: line });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
child.stderr?.on("data", (chunk) => stderr.write(chunk.toString()));
|
|
36
|
+
child.on("error", (error) => {
|
|
37
|
+
stderr.flush();
|
|
38
|
+
emit("agent_error", { message: error.message });
|
|
39
|
+
});
|
|
40
|
+
child.on("close", (code) => {
|
|
41
|
+
stderr.flush();
|
|
42
|
+
emit("agent_done", { agent, code });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** 启动外部 Agent CLI,并将同步启动异常转换为事件。 */
|
|
46
|
+
function spawnAgent(name, args, emit) {
|
|
47
|
+
try {
|
|
48
|
+
return spawn(name, args, { stdio: ["ignore", "pipe", "pipe"], shell: process.platform === "win32", windowsHide: true });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
emit("agent_error", { message: errorMessage(error) });
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type JsonRecord } from "../utils/value.js";
|
|
2
|
+
import type { CodexPlanUpdate, CodexReasoningEffort, CodexRequestParams, CodexSkillSelector } from "./codex-protocol.js";
|
|
3
|
+
import type { AgentEmit, AgentPermissionMode } from "./types.js";
|
|
4
|
+
/** 表示错误已经通过 app-server 终态或进程事件通知过网页。 */
|
|
5
|
+
export declare class CodexReportedError extends Error {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
/** 封装 Codex app-server 的 JSON-RPC 通信与事件转换。 */
|
|
9
|
+
export declare class CodexAppClient {
|
|
10
|
+
private child;
|
|
11
|
+
private emit;
|
|
12
|
+
private eventHistory;
|
|
13
|
+
private nextId;
|
|
14
|
+
private buffer;
|
|
15
|
+
private currentThreadId;
|
|
16
|
+
private currentTurnId;
|
|
17
|
+
private pendingTurnStart?;
|
|
18
|
+
private startedTurnKeys;
|
|
19
|
+
private textByItem;
|
|
20
|
+
private reasoningTextByItem;
|
|
21
|
+
private lastUsage;
|
|
22
|
+
private pending;
|
|
23
|
+
private activeTurns;
|
|
24
|
+
private completedTurns;
|
|
25
|
+
private completedTurnResults;
|
|
26
|
+
private pendingDeltas;
|
|
27
|
+
private startedItems;
|
|
28
|
+
private itemSequences;
|
|
29
|
+
private nextItemSequences;
|
|
30
|
+
private plansByTurn;
|
|
31
|
+
private approvalRequests;
|
|
32
|
+
private finalizingTurns;
|
|
33
|
+
private skillReloads;
|
|
34
|
+
private silentThreadIds;
|
|
35
|
+
private structuredOutputByTurn;
|
|
36
|
+
private pendingSilentThreadStarts;
|
|
37
|
+
private pendingThreadStartedNotifications;
|
|
38
|
+
private pendingPreheatThreadStarts;
|
|
39
|
+
private preheatingThreadIds;
|
|
40
|
+
private failing;
|
|
41
|
+
private failureMessage;
|
|
42
|
+
/** 保存 app-server 子进程和事件出口。 */
|
|
43
|
+
private constructor();
|
|
44
|
+
/** 启动并初始化 Codex app-server。 */
|
|
45
|
+
static start(emit: AgentEmit, onExit: () => void): Promise<CodexAppClient>;
|
|
46
|
+
/** 创建新的 Codex 线程。 */
|
|
47
|
+
startThread(cwd?: string, permissionMode?: AgentPermissionMode, preheat?: boolean): Promise<import("./codex-protocol.js").CodexThread>;
|
|
48
|
+
/** 创建不会持久化或向网页广播的草稿线程。 */
|
|
49
|
+
startSkillDraftThread(cwd: string): Promise<import("./codex-protocol.js").CodexThread>;
|
|
50
|
+
/** 从指定对话派生不会持久化或向网页广播的草稿线程。 */
|
|
51
|
+
forkSkillDraftThread(threadId: string, cwd: string): Promise<import("./codex-protocol.js").CodexThread>;
|
|
52
|
+
/** 恢复已有 Codex 线程。 */
|
|
53
|
+
resumeThread(threadId: string, cwd?: string, permissionMode?: AgentPermissionMode, preheat?: boolean): Promise<import("./codex-protocol.js").CodexThread>;
|
|
54
|
+
/** 以 app-server 的权威 MCP 清单响应作为预热完成边界。 */
|
|
55
|
+
private completeMcpPreheat;
|
|
56
|
+
/** 查询 Codex 线程列表。 */
|
|
57
|
+
listThreads(params: CodexRequestParams<"thread/list">): Promise<{
|
|
58
|
+
data: import("./codex-protocol.js").CodexThread[];
|
|
59
|
+
nextCursor: string | null;
|
|
60
|
+
backwardsCursor: string | null;
|
|
61
|
+
}>;
|
|
62
|
+
/** 读取指定 Codex 线程。 */
|
|
63
|
+
readThread(threadId: string, includeTurns?: boolean): Promise<{
|
|
64
|
+
thread: import("./codex-protocol.js").CodexThread;
|
|
65
|
+
}>;
|
|
66
|
+
/** 归档指定 Codex 线程。 */
|
|
67
|
+
archiveThread(threadId: string): Promise<Record<string, never>>;
|
|
68
|
+
/** 释放临时草稿线程的 App Server 订阅和进程内缓存。 */
|
|
69
|
+
closeSkillDraftThread(threadId: string): Promise<void>;
|
|
70
|
+
/** 查询当前账号可用的 Codex 模型。 */
|
|
71
|
+
listModels(): Promise<{
|
|
72
|
+
data: import("./codex-protocol.js").CodexModel[];
|
|
73
|
+
nextCursor: string | null;
|
|
74
|
+
}>;
|
|
75
|
+
/** 查询指定工作空间可发现的 Codex Skills。 */
|
|
76
|
+
listSkills(cwd: string, forceReload?: boolean): Promise<{
|
|
77
|
+
data: import("./codex-protocol.js").CodexSkillsListEntry[];
|
|
78
|
+
}>;
|
|
79
|
+
/** 修改一个已发现 Skill 的启用状态。 */
|
|
80
|
+
setSkillEnabled(path: string, enabled: boolean): Promise<{
|
|
81
|
+
effectiveEnabled: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/** 返回指定线程在当前进程中收到的最新任务计划。 */
|
|
84
|
+
planUpdates(threadId: string): CodexPlanUpdate[];
|
|
85
|
+
/** 清理已归档线程的任务计划缓存。 */
|
|
86
|
+
clearPlanUpdates(threadId: string): void;
|
|
87
|
+
/** 启动一个 Codex turn 并等待完成通知。 */
|
|
88
|
+
startTurn(threadId: string, prompt: string, images: string[], permissionMode: AgentPermissionMode, model?: string, effort?: CodexReasoningEffort, onTurn?: (turnId: string) => void, skill?: CodexSkillSelector, messageText?: string, outputSchema?: JsonRecord): Promise<unknown>;
|
|
89
|
+
/** 在静默线程中生成结构化输出。 */
|
|
90
|
+
generateSkillDraft(threadId: string, prompt: string, outputSchema: JsonRecord, model?: string, effort?: CodexReasoningEffort): Promise<string>;
|
|
91
|
+
/** 中断当前正在运行且属于指定线程的 Codex turn。 */
|
|
92
|
+
interruptCurrentTurn(requestedThreadId?: string): Promise<boolean>;
|
|
93
|
+
/** 回复网页端已经确认的 Codex 权限请求。 */
|
|
94
|
+
resolveApproval(requestId: string, decision: string): boolean;
|
|
95
|
+
/** 标记下一次临时线程创建,使早于请求响应到达的通知也不会外泄。 */
|
|
96
|
+
private startSilentThread;
|
|
97
|
+
/** 发送 JSON-RPC 请求并保存待处理 Promise。 */
|
|
98
|
+
private request;
|
|
99
|
+
/** 发送无需响应的 JSON-RPC 通知。 */
|
|
100
|
+
private notify;
|
|
101
|
+
/** 将 JSON-RPC 消息写入 app-server 标准输入。 */
|
|
102
|
+
private write;
|
|
103
|
+
/** 按行解析 app-server 标准输出。 */
|
|
104
|
+
private read;
|
|
105
|
+
/** 分派单条 JSON-RPC 响应、请求或通知。 */
|
|
106
|
+
private handle;
|
|
107
|
+
/** 转换并广播 app-server 通知。 */
|
|
108
|
+
private handleNotification;
|
|
109
|
+
/** 草稿线程存续期间隐藏 app-server 自身输出,避免混入网页诊断日志。 */
|
|
110
|
+
private get skillDraftActive();
|
|
111
|
+
/** 消化临时草稿线程事件,不广播、不落补充历史。 */
|
|
112
|
+
private handleSilentNotification;
|
|
113
|
+
/** 请求响应确定静默线程 ID 后,重新分流早到的启动通知。 */
|
|
114
|
+
private flushPendingThreadStartedNotifications;
|
|
115
|
+
/** 补充历史落盘后再广播 turn 终态,确保界面完成状态可跨 Agent 重启恢复。 */
|
|
116
|
+
private completeTurn;
|
|
117
|
+
/** 合并并广播 Agent 文本或执行输出增量。 */
|
|
118
|
+
private emitDelta;
|
|
119
|
+
/** 合并短时间内的文本增量,减少 SSE 传输和前端渲染次数。 */
|
|
120
|
+
private flushDelta;
|
|
121
|
+
/** 按 Codex summaryIndex 保存 reasoning 分段,顺序与线程历史一致。 */
|
|
122
|
+
private appendReasoningText;
|
|
123
|
+
/** turn 结束时发送最后一批增量并清理未收到 item.completed 的缓存。 */
|
|
124
|
+
private finishTurnDeltas;
|
|
125
|
+
/** 为一个 turn 内的 item 固定开始顺序,完成通知只更新内容。 */
|
|
126
|
+
private assignItemSequence;
|
|
127
|
+
/** 在通知或 turn/start 响应到达时回调一次 turn 启动状态。 */
|
|
128
|
+
private notifyTurnStarted;
|
|
129
|
+
/** 自动回复 app-server 发起的授权或交互请求。 */
|
|
130
|
+
private answerServerRequest;
|
|
131
|
+
/** 完成指定 JSON-RPC 请求。 */
|
|
132
|
+
private resolve;
|
|
133
|
+
/** 拒绝指定 JSON-RPC 请求。 */
|
|
134
|
+
private reject;
|
|
135
|
+
/** 拒绝进程退出时仍未完成的请求与 turn。 */
|
|
136
|
+
private failAll;
|
|
137
|
+
}
|
|
138
|
+
/** 合并单个 reasoning 分段增量并按 summaryIndex 输出。 */
|
|
139
|
+
export declare function appendReasoningDelta(segments: Map<number, string>, summaryIndex: number | undefined, delta: string): string;
|