pi-web-ui 0.113.1 → 0.114.1
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/CHANGELOG.md +71 -1
- package/README.md +187 -316
- package/README.zh-CN.md +227 -299
- package/README.zh-TW.md +227 -299
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +4081 -4041
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2419 -1174
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +69 -13
- package/dist/server/canvas/canvas-agent-tool.js +68 -18
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +519 -202
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +110 -24
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +351 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +830 -0
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +529 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +996 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +84 -27
- package/dist/server/dsh/dsh-agent-service.js +282 -159
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/global-loader.js +40 -2
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +285 -255
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +288 -94
- package/dist/server/preset-fields.js +56 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +113 -72
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +199 -106
- package/dist/server/request-context.js +164 -0
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +106 -55
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +273 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +48 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +357 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/vision-bridge.js +18 -18
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +148 -0
- package/docs/device-desktop.md +48 -0
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +5 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -676
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +11 -1
- package/themes/aetheris.css +501 -607
- package/themes/ayu-light.css +116 -140
- package/themes/bases/flow-base.css +1357 -1363
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +688 -687
- package/themes/bases/zhupi-base.css +660 -659
- package/themes/catppuccin-latte.css +119 -142
- package/themes/catppuccin.css +116 -147
- package/themes/claude-code-dark.css +147 -146
- package/themes/codex.css +114 -138
- package/themes/cyberpunk.css +50 -108
- package/themes/dark-teal.css +264 -265
- package/themes/dazzle.css +38 -108
- package/themes/everforest-light.css +115 -138
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -138
- package/themes/gruvbox-light.css +115 -138
- package/themes/kanagawa-lotus.css +115 -138
- package/themes/md-preview.css +24 -234
- package/themes/mist.css +166 -186
- package/themes/nord.css +107 -138
- package/themes/one-dark.css +106 -139
- package/themes/paper.css +174 -186
- package/themes/rose-pine-dawn.css +114 -138
- package/themes/sakura.css +166 -186
- package/themes/solarized-light.css +114 -137
- package/themes/tokyo-night.css +115 -146
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -186
- package/themes/zhujian-dark.css +115 -114
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -114
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/CanvasStudio-PI9pid0Y.js +1579 -0
- package/web/dist/assets/CanvasStudio-nf5-HxLM.js +1579 -0
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/TerminalPanel-BBuM_Sez.js +3 -0
- package/web/dist/assets/TerminalPanel-D6x6xz8Q.js +3 -0
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/desktop-YguLbrX1.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-BRBg6zmQ.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +42 -35
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 动作:list(工程摘要)/ get(整图 JSON)/ create_graph(新建工程)/ delete_graph(删除工程)/
|
|
5
5
|
* add_node / update_node / delete_node / add_edge / delete_edge / apply_dag(整图节点边替换,角色白名单+环检测)。
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 直接读写 canvas-store 落盘文件;前端画布下次 load 即见,聊天里即时回执。
|
|
6
|
+
* 运行与调试通过注入的 CanvasOrchestrator;编辑走版本检查与严格校验,成功后广播。
|
|
7
|
+
* 运行失败广播明确错误,状态与证据由调度器统一持久化。
|
|
9
8
|
*/
|
|
10
9
|
import { Type } from "typebox";
|
|
11
10
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
@@ -13,6 +12,7 @@ import { pick } from "../i18n.js";
|
|
|
13
12
|
import { CANVAS_TOOL_NAME } from "../tool-manager.js";
|
|
14
13
|
import { deleteCanvasGraph, listCanvasGraphs, loadCanvasGraph, saveCanvasGraph } from "./canvas-store.js";
|
|
15
14
|
import { addCustomCard, deleteCustomCard, listCustomCards, updateCustomCard } from "./canvas-cards.js";
|
|
15
|
+
import { assertCanvasGraph } from "./canvas-validation.js";
|
|
16
16
|
/** 新节点 cwd:显式参数 > 当前项目 > 服务启动目录(".") */
|
|
17
17
|
function defaultNodeCwd(host, p) {
|
|
18
18
|
const explicit = typeof p.cwd === "string" ? p.cwd.trim().slice(0, 256) : "";
|
|
@@ -48,7 +48,10 @@ function pushCards(dataDir) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
function saveAndPush(dataDir, graph) {
|
|
51
|
-
|
|
51
|
+
assertCanvasGraph(graph);
|
|
52
|
+
const result = saveCanvasGraph(dataDir, graph, { expectedRev: graph.rev ?? 0 });
|
|
53
|
+
if (result.conflict)
|
|
54
|
+
throw new Error("Canvas changed; get the latest graph before editing again");
|
|
52
55
|
try {
|
|
53
56
|
canvasBroadcaster?.({ type: "canvas_graph_state", graph });
|
|
54
57
|
}
|
|
@@ -156,17 +159,23 @@ function hasCycle(n, edges) {
|
|
|
156
159
|
}
|
|
157
160
|
export function makeCanvasTool(host, lang) {
|
|
158
161
|
const getLang = lang ?? host.lang ?? (() => "en");
|
|
159
|
-
const text = (t, details = {}) =>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
const text = (t, details = {}) => {
|
|
163
|
+
const encoded = JSON.stringify(details);
|
|
164
|
+
const oversized = Buffer.byteLength(encoded, "utf8") > 60_000;
|
|
165
|
+
return {
|
|
166
|
+
content: [{ type: "text", text: oversized ? `${t}\n${encoded}` : t }],
|
|
167
|
+
details: oversized
|
|
168
|
+
? { truncated: true, note: "Full graph is included in text; details exceeded the UI budget" }
|
|
169
|
+
: details,
|
|
170
|
+
};
|
|
171
|
+
};
|
|
163
172
|
return defineTool({
|
|
164
173
|
name: CANVAS_TOOL_NAME,
|
|
165
174
|
label: "Canvas pipeline",
|
|
166
175
|
description: "Read and edit canvas workflow graphs: list/get/create/delete graphs, add/update/delete nodes and edges, replace the DAG, layout/rearrange nodes on a tidy grid, run all or one node, stop, steer a running node, approve/reject review gates, read node logs, reset status, manage reusable custom cards. Use it when the user asks to create, change, run, or debug a pipeline.",
|
|
167
|
-
promptSnippet: "
|
|
176
|
+
promptSnippet: "Inspect, edit, run, or debug canvas workflows and canvas references.",
|
|
168
177
|
promptGuidelines: [
|
|
169
|
-
"
|
|
178
|
+
"Get the referenced graph before editing or running it; a canvas reference alone does not request execution",
|
|
170
179
|
"Running nodes costs tokens/time: prefer run_node for single-node debug, run_all only when the user asks",
|
|
171
180
|
"After steering or review, use get_log to confirm the node state before summarizing",
|
|
172
181
|
"New nodes default their cwd to the user's current project (getCwd); pass an absolute cwd only to pin another project",
|
|
@@ -278,7 +287,7 @@ export function makeCanvasTool(host, lang) {
|
|
|
278
287
|
return text(pick(getLang(), "缺少 graphId,先用 action=list 查看工程。", "Missing graphId; call action=list first.", "canvas.missing.id", {}), { ok: false });
|
|
279
288
|
if (graphId === "default")
|
|
280
289
|
return text(pick(getLang(), "默认工程不可删。", "The default graph cannot be deleted.", "canvas.graph.protected", {}), { ok: false });
|
|
281
|
-
const ok = deleteCanvasGraph(dataDir, graphId);
|
|
290
|
+
const ok = canvasRuntime ? canvasRuntime.deleteGraph(graphId) : deleteCanvasGraph(dataDir, graphId);
|
|
282
291
|
if (ok) {
|
|
283
292
|
try {
|
|
284
293
|
canvasBroadcaster?.({ type: "canvas_list_result", graphs: listCanvasGraphs(dataDir) });
|
|
@@ -311,7 +320,7 @@ export function makeCanvasTool(host, lang) {
|
|
|
311
320
|
x: 80 + (graph.nodes.length % 3) * 380,
|
|
312
321
|
y: 80 + Math.floor(graph.nodes.length / 3) * 260,
|
|
313
322
|
width: 300,
|
|
314
|
-
engine: ["pi", "dsh", "claude", "durable"].includes(card.engine)
|
|
323
|
+
engine: ["pi", "dsh", "codex", "claude", "durable"].includes(card.engine)
|
|
315
324
|
? card.engine
|
|
316
325
|
: "pi",
|
|
317
326
|
model: card.model || graph.nodes[0]?.model || "pi/default",
|
|
@@ -362,7 +371,22 @@ export function makeCanvasTool(host, lang) {
|
|
|
362
371
|
return text(pick(getLang(), `节点不存在:${nodeId}`, `Node not found: ${nodeId}`, "canvas.node.missing", {}), { ok: false });
|
|
363
372
|
const patch = (p.patch ?? {});
|
|
364
373
|
for (const [k, v] of Object.entries(patch)) {
|
|
365
|
-
if ([
|
|
374
|
+
if (![
|
|
375
|
+
"title",
|
|
376
|
+
"role",
|
|
377
|
+
"x",
|
|
378
|
+
"y",
|
|
379
|
+
"width",
|
|
380
|
+
"height",
|
|
381
|
+
"engine",
|
|
382
|
+
"model",
|
|
383
|
+
"thinkingLevel",
|
|
384
|
+
"cwd",
|
|
385
|
+
"useWorktree",
|
|
386
|
+
"systemPromptOverride",
|
|
387
|
+
"instruction",
|
|
388
|
+
"config",
|
|
389
|
+
].includes(k))
|
|
366
390
|
continue;
|
|
367
391
|
if (k === "role" && typeof v === "string" && !VALID_ROLES.has(v))
|
|
368
392
|
continue;
|
|
@@ -423,7 +447,11 @@ export function makeCanvasTool(host, lang) {
|
|
|
423
447
|
}
|
|
424
448
|
}
|
|
425
449
|
const idx = rawNodes.map((_, i) => i);
|
|
426
|
-
const normEdges = rawEdges.map((e) => ({
|
|
450
|
+
const normEdges = rawEdges.map((e) => ({
|
|
451
|
+
...e,
|
|
452
|
+
from: Number(e.from ?? e.source),
|
|
453
|
+
to: Number(e.to ?? e.target),
|
|
454
|
+
}));
|
|
427
455
|
for (const e of normEdges) {
|
|
428
456
|
if (!idx.includes(e.from) || !idx.includes(e.to) || e.from === e.to) {
|
|
429
457
|
return text(pick(getLang(), "边下标非法。", "Invalid edge indices.", "canvas.dag.edge", {}), {
|
|
@@ -449,12 +477,16 @@ export function makeCanvasTool(host, lang) {
|
|
|
449
477
|
useWorktree: false,
|
|
450
478
|
status: "idle",
|
|
451
479
|
...(typeof n.instruction === "string" && n.instruction ? { instruction: n.instruction } : {}),
|
|
480
|
+
...(n.config && typeof n.config === "object" ? { config: n.config } : {}),
|
|
452
481
|
}));
|
|
453
482
|
const edges = normEdges.map((e, i) => ({
|
|
454
483
|
id: `e_${now}_${i}`,
|
|
455
484
|
sourceNodeId: nodes[e.from].id,
|
|
456
485
|
targetNodeId: nodes[e.to].id,
|
|
457
|
-
type: "handoff",
|
|
486
|
+
type: (e.type ?? "handoff"),
|
|
487
|
+
...(typeof e.sourcePort === "string" ? { sourcePort: e.sourcePort } : {}),
|
|
488
|
+
...(typeof e.targetPort === "string" ? { targetPort: e.targetPort } : {}),
|
|
489
|
+
...(typeof e.label === "string" ? { label: e.label } : {}),
|
|
458
490
|
}));
|
|
459
491
|
const next = { ...graph, nodes, edges, updatedAt: now };
|
|
460
492
|
saveAndPush(dataDir, next);
|
|
@@ -477,7 +509,16 @@ export function makeCanvasTool(host, lang) {
|
|
|
477
509
|
return text(pick(getLang(), "运行态未就绪(服务刚启动/未注入),请稍后重试或在 Canvas Studio 里操作。", "Canvas runtime not ready; retry later or use Canvas Studio.", "canvas.runtime.missing", {}), { ok: false });
|
|
478
510
|
const nodeId = typeof p.nodeId === "string" ? p.nodeId : "";
|
|
479
511
|
if (action === "run_all") {
|
|
480
|
-
void canvasRuntime
|
|
512
|
+
void canvasRuntime
|
|
513
|
+
.runAll(graph, typeof p.prompt === "string" ? p.prompt : undefined, host.getCwd?.())
|
|
514
|
+
.catch((error) => {
|
|
515
|
+
canvasBroadcaster?.({
|
|
516
|
+
type: "canvas_error",
|
|
517
|
+
code: "execution_error",
|
|
518
|
+
graphId,
|
|
519
|
+
message: error.message,
|
|
520
|
+
});
|
|
521
|
+
});
|
|
481
522
|
return text(pick(getLang(), `已启动整图运行:${graph.name},进度在 Canvas Studio 看直播。`, `Started run-all for ${graph.name}; watch progress in Canvas Studio.`, "canvas.run.started", {}), { ok: true, graphId });
|
|
482
523
|
}
|
|
483
524
|
if (action === "run_node") {
|
|
@@ -485,7 +526,16 @@ export function makeCanvasTool(host, lang) {
|
|
|
485
526
|
return text(pick(getLang(), "缺少 nodeId。", "Missing nodeId.", "canvas.node.missing", {}), {
|
|
486
527
|
ok: false,
|
|
487
528
|
});
|
|
488
|
-
void canvasRuntime
|
|
529
|
+
void canvasRuntime
|
|
530
|
+
.runNode(graph, nodeId, typeof p.prompt === "string" ? p.prompt : undefined, host.getCwd?.())
|
|
531
|
+
.catch((error) => {
|
|
532
|
+
canvasBroadcaster?.({
|
|
533
|
+
type: "canvas_error",
|
|
534
|
+
code: "execution_error",
|
|
535
|
+
graphId,
|
|
536
|
+
message: error.message,
|
|
537
|
+
});
|
|
538
|
+
});
|
|
489
539
|
return text(pick(getLang(), `已启动节点 ${nodeId},日志可用 get_log 查看。`, `Started node ${nodeId}; use get_log to inspect.`, "canvas.node.started", {}), { ok: true, graphId, nodeId });
|
|
490
540
|
}
|
|
491
541
|
if (action === "stop_node") {
|
|
@@ -502,7 +552,7 @@ export function makeCanvasTool(host, lang) {
|
|
|
502
552
|
const message = typeof p.message === "string" ? p.message : "";
|
|
503
553
|
if (!nodeId || !message)
|
|
504
554
|
return text(pick(getLang(), "steer 需要 nodeId + message。", "steer needs nodeId + message.", "canvas.steer.bad", {}), { ok: false });
|
|
505
|
-
canvasRuntime.steerNode(graphId, nodeId, message);
|
|
555
|
+
await canvasRuntime.steerNode(graphId, nodeId, message);
|
|
506
556
|
return text(pick(getLang(), `已向节点 ${nodeId} 追问/转向。`, `Steered node ${nodeId}.`, "canvas.steered", {}), { ok: true });
|
|
507
557
|
}
|
|
508
558
|
if (action === "review_node") {
|
|
@@ -8,7 +8,7 @@ import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
10
10
|
import { isSafeGraphId } from "./canvas-store.js";
|
|
11
|
-
const VALID_ENGINES = new Set(["pi", "dsh", "claude", "durable"]);
|
|
11
|
+
const VALID_ENGINES = new Set(["pi", "dsh", "codex", "claude", "durable"]);
|
|
12
12
|
/** 卡片 id 与节点 id 同一安全口径:可作文件名/分支名,不穿越。 */
|
|
13
13
|
export function isSafeCardId(id) {
|
|
14
14
|
return isSafeGraphId(id);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isSafeGraphId, listCanvasGraphs, loadCanvasGraph, saveCanvasGraph } from "./canvas-store.js";
|
|
2
2
|
import { deleteCustomCard, listCustomCards } from "./canvas-cards.js";
|
|
3
|
+
import { assertCanvasGraph } from "./canvas-validation.js";
|
|
3
4
|
export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
5
|
+
const fail = (error, graphId, requestId) => send({
|
|
6
|
+
type: "canvas_error",
|
|
7
|
+
code: "execution_error",
|
|
8
|
+
message: error instanceof Error ? error.message : String(error),
|
|
9
|
+
graphId,
|
|
10
|
+
requestId,
|
|
11
|
+
});
|
|
4
12
|
switch (msg.type) {
|
|
5
13
|
case "canvas_list": {
|
|
6
14
|
const graphs = listCanvasGraphs(dataDir);
|
|
@@ -26,12 +34,15 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
26
34
|
return true;
|
|
27
35
|
try {
|
|
28
36
|
const graph = loadCanvasGraph(dataDir, msg.id);
|
|
29
|
-
send({ type: "canvas_graph_state", graph });
|
|
37
|
+
send({ type: "canvas_graph_state", graph, requestId: msg.requestId });
|
|
30
38
|
}
|
|
31
|
-
catch {
|
|
39
|
+
catch (error) {
|
|
32
40
|
send({
|
|
33
|
-
type: "
|
|
34
|
-
|
|
41
|
+
type: "canvas_error",
|
|
42
|
+
code: "not_found",
|
|
43
|
+
message: error instanceof Error ? error.message : String(error),
|
|
44
|
+
graphId: msg.id,
|
|
45
|
+
requestId: msg.requestId,
|
|
35
46
|
});
|
|
36
47
|
}
|
|
37
48
|
return true;
|
|
@@ -39,7 +50,33 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
39
50
|
case "canvas_save": {
|
|
40
51
|
if (!isSafeGraphId(msg.graph?.id))
|
|
41
52
|
return true;
|
|
42
|
-
|
|
53
|
+
try {
|
|
54
|
+
assertCanvasGraph(msg.graph);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
send({
|
|
58
|
+
type: "canvas_error",
|
|
59
|
+
code: "invalid_graph",
|
|
60
|
+
message: error.message,
|
|
61
|
+
graphId: msg.graph.id,
|
|
62
|
+
requestId: msg.requestId,
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
let res;
|
|
67
|
+
try {
|
|
68
|
+
res = saveCanvasGraph(dataDir, msg.graph, { expectedRev: msg.baseRev ?? msg.graph.rev ?? 0 });
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
send({
|
|
72
|
+
type: "canvas_error",
|
|
73
|
+
code: "save_failed",
|
|
74
|
+
message: error.message,
|
|
75
|
+
graphId: msg.graph.id,
|
|
76
|
+
requestId: msg.requestId,
|
|
77
|
+
});
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
43
80
|
if (res.conflict) {
|
|
44
81
|
send({
|
|
45
82
|
type: "canvas_error",
|
|
@@ -49,10 +86,10 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
49
86
|
graph: res.graph,
|
|
50
87
|
requestId: msg.requestId,
|
|
51
88
|
});
|
|
52
|
-
send({ type: "canvas_graph_state", graph: res.graph });
|
|
89
|
+
send({ type: "canvas_graph_state", graph: res.graph, requestId: msg.requestId });
|
|
53
90
|
return true;
|
|
54
91
|
}
|
|
55
|
-
send({ type: "canvas_graph_state", graph:
|
|
92
|
+
send({ type: "canvas_graph_state", graph: res.graph, requestId: msg.requestId });
|
|
56
93
|
const graphs = listCanvasGraphs(dataDir);
|
|
57
94
|
send({ type: "canvas_list_result", graphs });
|
|
58
95
|
return true;
|
|
@@ -60,7 +97,7 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
60
97
|
case "canvas_delete": {
|
|
61
98
|
if (!isSafeGraphId(msg.id))
|
|
62
99
|
return true;
|
|
63
|
-
|
|
100
|
+
orchestrator.deleteGraph(msg.id);
|
|
64
101
|
const graphs = listCanvasGraphs(dataDir);
|
|
65
102
|
send({ type: "canvas_list_result", graphs });
|
|
66
103
|
return true;
|
|
@@ -68,20 +105,24 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
68
105
|
case "canvas_run_all": {
|
|
69
106
|
try {
|
|
70
107
|
const graph = loadCanvasGraph(dataDir, msg.graphId);
|
|
71
|
-
|
|
108
|
+
assertCanvasGraph(graph);
|
|
109
|
+
void orchestrator.runAll(graph, msg.initialPrompt, opts?.runBase).catch((error) => fail(error, msg.graphId));
|
|
72
110
|
}
|
|
73
|
-
catch {
|
|
74
|
-
|
|
111
|
+
catch (error) {
|
|
112
|
+
fail(error, msg.graphId);
|
|
75
113
|
}
|
|
76
114
|
return true;
|
|
77
115
|
}
|
|
78
116
|
case "canvas_run_node": {
|
|
79
117
|
try {
|
|
80
118
|
const graph = loadCanvasGraph(dataDir, msg.graphId);
|
|
81
|
-
|
|
119
|
+
assertCanvasGraph(graph);
|
|
120
|
+
void orchestrator
|
|
121
|
+
.runNode(graph, msg.nodeId, msg.prompt, opts?.runBase)
|
|
122
|
+
.catch((error) => fail(error, msg.graphId));
|
|
82
123
|
}
|
|
83
|
-
catch {
|
|
84
|
-
|
|
124
|
+
catch (error) {
|
|
125
|
+
fail(error, msg.graphId);
|
|
85
126
|
}
|
|
86
127
|
return true;
|
|
87
128
|
}
|
|
@@ -96,7 +137,7 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
96
137
|
case "canvas_steer_node": {
|
|
97
138
|
if (!isSafeGraphId(msg.graphId))
|
|
98
139
|
return true;
|
|
99
|
-
orchestrator.steerNode(msg.graphId, msg.nodeId, msg.message);
|
|
140
|
+
void orchestrator.steerNode(msg.graphId, msg.nodeId, msg.message).catch((error) => fail(error, msg.graphId));
|
|
100
141
|
return true;
|
|
101
142
|
}
|
|
102
143
|
case "canvas_get_log": {
|
|
@@ -133,8 +174,8 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
133
174
|
if (graph)
|
|
134
175
|
send({ type: "canvas_graph_state", graph });
|
|
135
176
|
}
|
|
136
|
-
catch {
|
|
137
|
-
|
|
177
|
+
catch (error) {
|
|
178
|
+
fail(error, msg.graphId);
|
|
138
179
|
}
|
|
139
180
|
return true;
|
|
140
181
|
}
|
|
@@ -144,8 +185,8 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
144
185
|
orchestrator.resetStatus(graph);
|
|
145
186
|
send({ type: "canvas_graph_state", graph });
|
|
146
187
|
}
|
|
147
|
-
catch {
|
|
148
|
-
|
|
188
|
+
catch (error) {
|
|
189
|
+
fail(error, msg.graphId);
|
|
149
190
|
}
|
|
150
191
|
return true;
|
|
151
192
|
}
|