pi-web-ui 0.118.0 → 0.120.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/CHANGELOG.md +143 -1
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +930 -166
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/ask-user-question-tool.js +3 -40
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/background-executors.js +235 -0
- package/dist/server/bash-timeout.js +47 -0
- package/dist/server/bash-tool.js +72 -5
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/browser-page-tool.js +38 -29
- package/dist/server/browser-script-tool.js +119 -0
- package/dist/server/canvas/canvas-agent-tool.js +46 -35
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/claim-files-tool.js +6 -7
- package/dist/server/client-state.js +457 -41
- package/dist/server/communicate-tool.js +59 -77
- package/dist/server/compact-context-tool.js +4 -13
- package/dist/server/conversation-communication.js +23 -1
- package/dist/server/conversation-read-tool.js +14 -23
- package/dist/server/conversation-rows.js +17 -0
- package/dist/server/conversation-tool-names.js +2 -2
- package/dist/server/conversation-tool.js +23 -15
- package/dist/server/conversation-touches.js +1 -1
- package/dist/server/delegate-mode.js +0 -1
- package/dist/server/delegate-task.js +18 -39
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-execution.js +0 -1
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/device-center/task-progress.js +2 -2
- package/dist/server/dispatch-domain-handlers.js +97 -24
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +21 -19
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/edit-tool.js +293 -0
- package/dist/server/engine-catalog.js +8 -2
- package/dist/server/engine-cli.js +29 -7
- package/dist/server/engine-probe.js +11 -6
- package/dist/server/eval-tool.js +5 -19
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -3
- package/dist/server/index.js +92 -3
- package/dist/server/job-runner.js +345 -0
- package/dist/server/lsp-tool.js +10 -28
- package/dist/server/marker-service.js +42 -30
- package/dist/server/mcp-agent-tool.js +22 -47
- package/dist/server/model-session.js +16 -0
- package/dist/server/native-cli-session-hooks.js +3 -2
- package/dist/server/native-cli-session.js +27 -2
- package/dist/server/patch-tool.js +2 -8
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +7 -4
- package/dist/server/plan-update-tool.js +5 -8
- package/dist/server/plugin-api-catalog.js +13 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-catalog.js +6 -0
- package/dist/server/plugin-delivery.js +358 -0
- package/dist/server/plugin-inbox.js +152 -0
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-ledger.js +183 -0
- package/dist/server/plugin-manifest-validate.js +19 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +205 -48
- package/dist/server/present-files-tool.js +7 -13
- package/dist/server/preset-fields.js +23 -12
- package/dist/server/preset-share.js +1 -1
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/question-params.js +98 -0
- package/dist/server/quick-ask-settings.js +0 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/read-tool.js +10 -17
- package/dist/server/remote-ssh-service.js +40 -1
- package/dist/server/sandbox-runtime-gate.js +1 -1
- package/dist/server/sandbox-service.js +0 -1
- package/dist/server/sandbox-tool.js +25 -34
- package/dist/server/schedule-agent-tool.js +9 -19
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +49 -19
- package/dist/server/skill-tool.js +4 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -3
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +566 -211
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +34 -28
- package/dist/server/tool-approval.js +15 -1
- package/dist/server/tool-guards.js +0 -91
- package/dist/server/tool-manager.js +127 -47
- package/dist/server/tool-overrides.js +8 -1
- package/dist/server/tool-prompt-overrides.js +3 -6
- package/dist/server/tool-prompts.js +60 -17
- package/dist/server/universal/driver-base.js +2 -0
- package/dist/server/universal/drivers/claude-code.js +210 -211
- package/dist/server/universal/drivers/codex.js +29 -24
- package/dist/server/universal/engine-mcp.js +107 -0
- package/dist/server/universal/universal-attachments.js +77 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +106 -69
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/dist/server/worktree-tool.js +13 -20
- package/docs/README.md +40 -36
- package/docs/architecture-plugins.md +64 -35
- package/docs/device-center.md +1 -1
- package/package.json +16 -4
- package/plugin-sdk/index.d.ts +102 -0
- package/plugins/catalog.json +23 -51
- package/themes/bases/flow-base.css +8 -17
- package/themes/dark-teal.css +0 -3
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
- package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
- package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
- package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
- package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
- package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
- package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
- package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
- package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
- package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
- package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
- package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
- package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
- package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
- package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/dist/server/edit-soft-tool.js +0 -297
- package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
- package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
- package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
- package/web/dist/assets/index-CQc3VrWa.css +0 -1
- package/web/dist/assets/index-D_AGu4Zv.js +0 -404
- package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
- package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
- package/web/dist/assets/theme-DGL7hLUs.js +0 -1
|
@@ -266,13 +266,17 @@ export class BgServerTracker {
|
|
|
266
266
|
port,
|
|
267
267
|
pid: v.pid,
|
|
268
268
|
since: v.since,
|
|
269
|
+
kind: "port",
|
|
269
270
|
...(v.name ? { name: v.name } : {}),
|
|
270
271
|
...(v.command ? { command: v.command } : {}),
|
|
271
272
|
...(v.keep ? { keep: true } : {}),
|
|
272
273
|
}))
|
|
273
274
|
.sort((a, b) => a.since - b.since);
|
|
274
275
|
for (const t of this.opts.pluginTasks?.() ?? [])
|
|
275
|
-
out.push(t);
|
|
276
|
+
out.push({ kind: "plugin", ...t });
|
|
277
|
+
// bash background 的 job 行:不靠端口 diff,而是 JobRegistry 显式登记(不监听端口的任务也能看见)。
|
|
278
|
+
for (const j of this.opts.jobs?.() ?? [])
|
|
279
|
+
out.push({ kind: "job", ...j });
|
|
276
280
|
return out;
|
|
277
281
|
}
|
|
278
282
|
push() {
|
|
@@ -396,19 +400,21 @@ export class BgServerTracker {
|
|
|
396
400
|
return killed;
|
|
397
401
|
}
|
|
398
402
|
async killAll() {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
403
|
+
// 「全部关闭」的语义是「把后台都停了」:端口行 + bash background 的 job 行一起收。
|
|
404
|
+
// 插件常驻任务不在内(它们由插件自己的 stop 回调负责,面板上也单独走 kill_background_server{taskId})。
|
|
405
|
+
const killedJobs = this.opts.killAllJobs?.() ?? [];
|
|
406
|
+
const killed = killedJobs.map((id) => `job:${id}`);
|
|
407
|
+
if (this.servers.size > 0) {
|
|
408
|
+
await this.verifyBeforeKill();
|
|
409
|
+
// eslint-disable-next-line unicorn/no-useless-spread -- snapshot: killPidTree 的异步回调可能改 map
|
|
410
|
+
for (const [port, { pid }] of [...this.servers]) {
|
|
411
|
+
killPidTree(pid);
|
|
412
|
+
killed.push(String(port));
|
|
413
|
+
}
|
|
414
|
+
this.servers.clear();
|
|
409
415
|
}
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
if (killed.length > 0)
|
|
417
|
+
this.push();
|
|
412
418
|
return killed;
|
|
413
419
|
}
|
|
414
420
|
}
|
|
@@ -8,6 +8,24 @@ export function normalizePageCallTimeoutMs(v) {
|
|
|
8
8
|
return Math.min(PAGE_CALL_MAX_TIMEOUT_MS, Math.max(PAGE_CALL_MIN_TIMEOUT_MS, n));
|
|
9
9
|
}
|
|
10
10
|
const BROWSER_PAGE_ARG_KEYS = ["what", "selector", "text", "url", "code", "all", "index", "maxEdge"];
|
|
11
|
+
/** `op` 的枚举:schema 里显式列出,运行时仍接受任意非空字符串(旧客户端兼容)。 */
|
|
12
|
+
export const BROWSER_PAGE_OPS = [
|
|
13
|
+
"status",
|
|
14
|
+
"pages",
|
|
15
|
+
"read",
|
|
16
|
+
"click",
|
|
17
|
+
"type",
|
|
18
|
+
"scroll",
|
|
19
|
+
"goto",
|
|
20
|
+
"wait",
|
|
21
|
+
"eval",
|
|
22
|
+
"shot",
|
|
23
|
+
"snapshot",
|
|
24
|
+
];
|
|
25
|
+
export const BROWSER_PAGE_WHAT = ["text", "html", "title", "url", "query"];
|
|
26
|
+
/** 每 op 的签名是参数文档的唯一归属地,字段本身不再写说明。 */
|
|
27
|
+
export const BROWSER_PAGE_OP_SIGNATURE = "status | pages | read(target?,what?,selector?,all?) | click(selector,index?) | type(selector,text) | " +
|
|
28
|
+
"scroll(selector?) | goto(url) | wait(selector?,text?,timeoutMs?) | eval(code) | shot(maxEdge?) | snapshot";
|
|
11
29
|
export function collectBrowserPageArgs(params) {
|
|
12
30
|
const args = {};
|
|
13
31
|
for (const k of BROWSER_PAGE_ARG_KEYS) {
|
|
@@ -32,48 +50,39 @@ export function formatBrowserPageError(op, error) {
|
|
|
32
50
|
return [
|
|
33
51
|
`browser_page "${op}" failed: ${error}`,
|
|
34
52
|
`browser_page "${op}" 失败:${error}`,
|
|
35
|
-
'Next:
|
|
36
|
-
'
|
|
53
|
+
'Next: op:"pages" lists the open tabs and marks the one the user has open with active:true. In a regular browser, enable and pair page-picker and allow the target page in the extension.',
|
|
54
|
+
'下一步:op:"pages" 会列出已打开的标签页,并用 active:true 标出用户当前打开的那个;使用普通浏览器时,请启用并配对 page-picker,再在扩展中授权目标页面。',
|
|
37
55
|
].join("\n");
|
|
38
56
|
}
|
|
39
57
|
export function makeBrowserPageTool(clientSession, ownerId) {
|
|
40
58
|
return {
|
|
41
59
|
name: BROWSER_PAGE_TOOL_NAME,
|
|
42
60
|
label: "Browser page",
|
|
43
|
-
description:
|
|
44
|
-
"Read or act on a page in the user's AI Browser tabs or a regular browser through page-picker (the server only forwards).",
|
|
45
|
-
"Only the parameters below exist — an op option that is not a field here (e.g. type's submit) is unavailable.",
|
|
46
|
-
"ops: status | pages | read (what? selector? all?) | click (selector? index?) | type (selector text) | scroll (selector?) | goto (url) | wait (selector? text? timeoutMs?) | eval (code, disabled by default) | shot (maxEdge?) | snapshot (AI Browser)",
|
|
47
|
-
].join("\n"),
|
|
61
|
+
description: "Read or act on AI Browser tabs or page-picker.",
|
|
48
62
|
promptSnippet: "operate a page in AI Browser or through the page-picker extension",
|
|
49
63
|
promptGuidelines: [
|
|
50
64
|
"Only use browser_page when the user asked you to read or act on a page in their browser; " +
|
|
51
65
|
"never click or type on their pages on your own initiative",
|
|
52
|
-
'Start with op:"pages";
|
|
53
|
-
|
|
66
|
+
'Start with op:"pages"; the page marked active:true is the one the user is viewing now. When the user says "this page", pass that page\'s tabId (AI Browser) or origin (page-picker) as target.',
|
|
67
|
+
"Multiple tabs may be open: always pass an explicit target rather than assuming one, " +
|
|
68
|
+
"and name the missing browser setting instead of retrying when the tool is unavailable.",
|
|
54
69
|
],
|
|
55
70
|
parameters: Type.Object({
|
|
56
|
-
op: Type.
|
|
57
|
-
|
|
71
|
+
op: Type.Unsafe({
|
|
72
|
+
type: "string",
|
|
73
|
+
enum: [...BROWSER_PAGE_OPS],
|
|
74
|
+
description: BROWSER_PAGE_OP_SIGNATURE,
|
|
58
75
|
}),
|
|
59
|
-
target: Type.Optional(Type.String({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
all: Type.Optional(Type.Boolean({ description: "For op:read — return every match instead of only the first one." })),
|
|
70
|
-
index: Type.Optional(Type.Number({ description: "For op:click — which match to click (default: 0)." })),
|
|
71
|
-
maxEdge: Type.Optional(Type.Number({
|
|
72
|
-
description: "For op:shot — max px of the longer side (320-1568, default 1280).",
|
|
73
|
-
})),
|
|
74
|
-
timeoutMs: Type.Optional(Type.Number({
|
|
75
|
-
description: "How long the server waits for the browser (1000-120000 ms, default 30000).",
|
|
76
|
-
})),
|
|
76
|
+
target: Type.Optional(Type.String({ description: "Origin URL or native tabId" })),
|
|
77
|
+
what: Type.Optional(Type.Unsafe({ type: "string", enum: [...BROWSER_PAGE_WHAT] })),
|
|
78
|
+
selector: Type.Optional(Type.String()),
|
|
79
|
+
text: Type.Optional(Type.String()),
|
|
80
|
+
url: Type.Optional(Type.String()),
|
|
81
|
+
code: Type.Optional(Type.String()),
|
|
82
|
+
all: Type.Optional(Type.Boolean()),
|
|
83
|
+
index: Type.Optional(Type.Number()),
|
|
84
|
+
maxEdge: Type.Optional(Type.Number()),
|
|
85
|
+
timeoutMs: Type.Optional(Type.Number()),
|
|
77
86
|
}),
|
|
78
87
|
execute: async (_id, params, signal) => {
|
|
79
88
|
const p = (params ?? {});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { formatPageCallResult, normalizePageCallTimeoutMs, } from "./browser-page-tool.js";
|
|
3
|
+
import { BROWSER_SCRIPT_TOOL_NAME } from "./tool-manager.js";
|
|
4
|
+
/** 脚本动作:临时(会话内)/ 永久(落盘)共用同一套记录,`persist` 决定生命周期。 */
|
|
5
|
+
export const BROWSER_SCRIPT_ACTIONS = [
|
|
6
|
+
"list",
|
|
7
|
+
"status",
|
|
8
|
+
"create",
|
|
9
|
+
"update",
|
|
10
|
+
"remove",
|
|
11
|
+
"enable",
|
|
12
|
+
"disable",
|
|
13
|
+
"run",
|
|
14
|
+
];
|
|
15
|
+
export const BROWSER_SCRIPT_RUN_AT = ["dom-ready", "document-start"];
|
|
16
|
+
export const BROWSER_SCRIPT_WORLD = ["main", "isolated"];
|
|
17
|
+
const SCRIPT_ARG_KEYS = [
|
|
18
|
+
"id",
|
|
19
|
+
"name",
|
|
20
|
+
"matches",
|
|
21
|
+
"code",
|
|
22
|
+
"css",
|
|
23
|
+
"runAt",
|
|
24
|
+
"world",
|
|
25
|
+
"spa",
|
|
26
|
+
"persist",
|
|
27
|
+
"enabled",
|
|
28
|
+
"tabId",
|
|
29
|
+
];
|
|
30
|
+
const ACTION_SIGNATURE = "list | status(target?) | create(name,code,css?,matches?,runAt?,world?,spa?,persist?) | " +
|
|
31
|
+
"update(id|name,...) | remove(id|name) | enable(id|name) | disable(id|name) | run(id|name,target?)";
|
|
32
|
+
export const BROWSER_SCRIPT_ARG_HINT = "matches: host globs (example.com, *.example.com), full-URL globs, re:<regex>, or * for every page";
|
|
33
|
+
export function collectBrowserScriptArgs(params) {
|
|
34
|
+
const args = {};
|
|
35
|
+
for (const key of SCRIPT_ARG_KEYS) {
|
|
36
|
+
if (params[key] !== undefined)
|
|
37
|
+
args[key] = params[key];
|
|
38
|
+
}
|
|
39
|
+
return args;
|
|
40
|
+
}
|
|
41
|
+
export function formatBrowserScriptError(action, error) {
|
|
42
|
+
return [
|
|
43
|
+
`browser_script "${action}" failed: ${error}`,
|
|
44
|
+
`browser_script "${action}" 失败:${error}`,
|
|
45
|
+
'Next: run action:"list" to see existing scripts and their ids; page scripts only apply to http(s) tabs in the AI Browser.',
|
|
46
|
+
'下一步:先用 action:"list" 查看已有脚本与 id;页面脚本只作用于 AI 浏览器里的 http(s) 标签页。',
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
function asArray(value) {
|
|
50
|
+
if (typeof value === "string")
|
|
51
|
+
return value.trim() ? [value.trim()] : [];
|
|
52
|
+
if (Array.isArray(value))
|
|
53
|
+
return value.filter((item) => typeof item === "string");
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
export function makeBrowserScriptTool(clientSession, ownerId) {
|
|
57
|
+
return {
|
|
58
|
+
name: BROWSER_SCRIPT_TOOL_NAME,
|
|
59
|
+
label: "Browser page script",
|
|
60
|
+
description: "Inject JavaScript or CSS into an AI Browser tab, temporarily or permanently. " +
|
|
61
|
+
"Scripts run on matching pages from now on, so create one only when the user asked for a lasting change. " +
|
|
62
|
+
"When `matches` is omitted, a new script targets only the site of the current tab.",
|
|
63
|
+
promptSnippet: "inject temporary or persistent scripts into AI Browser pages",
|
|
64
|
+
promptGuidelines: [
|
|
65
|
+
"Use browser_script only when the user asked to change how a page behaves or looks; read pages with browser_page.",
|
|
66
|
+
"Pass persist:false (default) for one-off tweaks and persist:true only when the user wants the change to stay.",
|
|
67
|
+
"Scripts run again on every matching page load. Give each one a stable name and update it instead of creating duplicates.",
|
|
68
|
+
"Return a cleanup function from the script body to make removal undo its DOM/CSS changes; verify the effect afterwards.",
|
|
69
|
+
],
|
|
70
|
+
parameters: Type.Object({
|
|
71
|
+
action: Type.Unsafe({
|
|
72
|
+
type: "string",
|
|
73
|
+
enum: [...BROWSER_SCRIPT_ACTIONS],
|
|
74
|
+
description: ACTION_SIGNATURE,
|
|
75
|
+
}),
|
|
76
|
+
target: Type.Optional(Type.String({ description: "Origin URL or native tabId" })),
|
|
77
|
+
id: Type.Optional(Type.String()),
|
|
78
|
+
name: Type.Optional(Type.String()),
|
|
79
|
+
matches: Type.Optional(Type.Array(Type.String(), { description: BROWSER_SCRIPT_ARG_HINT })),
|
|
80
|
+
code: Type.Optional(Type.String()),
|
|
81
|
+
css: Type.Optional(Type.String()),
|
|
82
|
+
runAt: Type.Optional(Type.Unsafe({ type: "string", enum: [...BROWSER_SCRIPT_RUN_AT] })),
|
|
83
|
+
world: Type.Optional(Type.Unsafe({ type: "string", enum: [...BROWSER_SCRIPT_WORLD] })),
|
|
84
|
+
spa: Type.Optional(Type.Boolean()),
|
|
85
|
+
persist: Type.Optional(Type.Boolean()),
|
|
86
|
+
enabled: Type.Optional(Type.Boolean()),
|
|
87
|
+
tabId: Type.Optional(Type.String()),
|
|
88
|
+
timeoutMs: Type.Optional(Type.Number()),
|
|
89
|
+
}),
|
|
90
|
+
execute: async (_id, params, signal) => {
|
|
91
|
+
const p = (params ?? {});
|
|
92
|
+
const action = typeof p.action === "string" ? p.action.trim() : "";
|
|
93
|
+
if (!action) {
|
|
94
|
+
throw new Error('browser_script requires `action` (e.g. "list", "create", "run").\nbrowser_script 需要 action(如 list/create/run)。');
|
|
95
|
+
}
|
|
96
|
+
if (!BROWSER_SCRIPT_ACTIONS.includes(action)) {
|
|
97
|
+
throw new Error(`Unsupported browser_script action: ${action} (expected ${BROWSER_SCRIPT_ACTIONS.join(" | ")})`);
|
|
98
|
+
}
|
|
99
|
+
const args = collectBrowserScriptArgs(p);
|
|
100
|
+
const matches = asArray(p.matches);
|
|
101
|
+
if (matches)
|
|
102
|
+
args.matches = matches;
|
|
103
|
+
else
|
|
104
|
+
delete args.matches;
|
|
105
|
+
const resolved = await clientSession.pageCall({
|
|
106
|
+
op: `script.${action}`,
|
|
107
|
+
args,
|
|
108
|
+
target: typeof p.target === "string" && p.target.length > 0 ? p.target : undefined,
|
|
109
|
+
timeoutMs: normalizePageCallTimeoutMs(p.timeoutMs),
|
|
110
|
+
}, { aborted: signal?.aborted }, ownerId);
|
|
111
|
+
if (!resolved.ok)
|
|
112
|
+
throw new Error(formatBrowserScriptError(action, resolved.error));
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: formatPageCallResult(resolved.result) }],
|
|
115
|
+
details: { action, args, target: p.target, result: resolved.result },
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -81,52 +81,63 @@ const VALID_ROLES = new Set([
|
|
|
81
81
|
"pstack",
|
|
82
82
|
"skill",
|
|
83
83
|
]);
|
|
84
|
+
const CANVAS_ACTIONS = [
|
|
85
|
+
"list",
|
|
86
|
+
"get",
|
|
87
|
+
"create_graph",
|
|
88
|
+
"delete_graph",
|
|
89
|
+
"run_all",
|
|
90
|
+
"run_node",
|
|
91
|
+
"stop_node",
|
|
92
|
+
"stop_all",
|
|
93
|
+
"steer_node",
|
|
94
|
+
"review_node",
|
|
95
|
+
"get_log",
|
|
96
|
+
"reset_status",
|
|
97
|
+
"layout_graph",
|
|
98
|
+
"card_list",
|
|
99
|
+
"card_add",
|
|
100
|
+
"card_update",
|
|
101
|
+
"card_delete",
|
|
102
|
+
"card_place",
|
|
103
|
+
"add_node",
|
|
104
|
+
"update_node",
|
|
105
|
+
"delete_node",
|
|
106
|
+
"add_edge",
|
|
107
|
+
"delete_edge",
|
|
108
|
+
"apply_dag",
|
|
109
|
+
];
|
|
110
|
+
/** 每 action 要哪些参数,只在 `action` 字段里交代一次;字段本身不再写说明。 */
|
|
111
|
+
export const CANVAS_ACTION_SIGNATURE = "list | get(graphId) | create_graph(title?,instruction?) | delete_graph/layout_graph/run_all/stop_all/reset_status(graphId) | " +
|
|
112
|
+
"run_node/stop_node/get_log(graphId,nodeId) | steer_node(graphId,nodeId,message) | " +
|
|
113
|
+
"review_node(graphId,nodeId,decision,comment?) | add_node(graphId,title,role,instruction?) | " +
|
|
114
|
+
"update_node(graphId,nodeId,patch) | delete_node(graphId,nodeId) | " +
|
|
115
|
+
"add_edge(graphId,sourceNodeId,targetNodeId) | delete_edge(graphId,edgeId) | apply_dag(graphId,nodes,edges) | " +
|
|
116
|
+
"card_list | card_add(title,role,instruction?) | card_update(cardId,title?,role?,instruction?,patch?) | " +
|
|
117
|
+
"card_delete/card_place(cardId)";
|
|
84
118
|
const canvasSchema = Type.Object({
|
|
85
|
-
action: Type.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
Type.Literal("run_node"),
|
|
92
|
-
Type.Literal("stop_node"),
|
|
93
|
-
Type.Literal("stop_all"),
|
|
94
|
-
Type.Literal("steer_node"),
|
|
95
|
-
Type.Literal("review_node"),
|
|
96
|
-
Type.Literal("get_log"),
|
|
97
|
-
Type.Literal("reset_status"),
|
|
98
|
-
Type.Literal("layout_graph"),
|
|
99
|
-
Type.Literal("card_list"),
|
|
100
|
-
Type.Literal("card_add"),
|
|
101
|
-
Type.Literal("card_update"),
|
|
102
|
-
Type.Literal("card_delete"),
|
|
103
|
-
Type.Literal("card_place"),
|
|
104
|
-
Type.Literal("add_node"),
|
|
105
|
-
Type.Literal("update_node"),
|
|
106
|
-
Type.Literal("delete_node"),
|
|
107
|
-
Type.Literal("add_edge"),
|
|
108
|
-
Type.Literal("delete_edge"),
|
|
109
|
-
Type.Literal("apply_dag"),
|
|
110
|
-
]),
|
|
111
|
-
graphId: Type.Optional(Type.String({ description: "Target canvas graph id (list omits it)" })),
|
|
119
|
+
action: Type.Unsafe({
|
|
120
|
+
type: "string",
|
|
121
|
+
enum: [...CANVAS_ACTIONS],
|
|
122
|
+
description: CANVAS_ACTION_SIGNATURE,
|
|
123
|
+
}),
|
|
124
|
+
graphId: Type.Optional(Type.String()),
|
|
112
125
|
title: Type.Optional(Type.String()),
|
|
113
126
|
role: Type.Optional(Type.String()),
|
|
114
127
|
instruction: Type.Optional(Type.String()),
|
|
115
128
|
nodeId: Type.Optional(Type.String()),
|
|
116
|
-
cardId: Type.Optional(Type.String(
|
|
117
|
-
cwd: Type.Optional(Type.String({
|
|
118
|
-
description: "Working directory for a new node (absolute path pins a project; omit = current project)",
|
|
119
|
-
})),
|
|
129
|
+
cardId: Type.Optional(Type.String()),
|
|
130
|
+
cwd: Type.Optional(Type.String({ description: "Working directory for a new node (absolute path pins a project)" })),
|
|
120
131
|
message: Type.Optional(Type.String()),
|
|
121
132
|
prompt: Type.Optional(Type.String()),
|
|
122
133
|
decision: Type.Optional(Type.String()),
|
|
123
134
|
comment: Type.Optional(Type.String()),
|
|
124
|
-
patch: Type.Optional(Type.
|
|
135
|
+
patch: Type.Optional(Type.Unsafe({ type: "object" })),
|
|
125
136
|
sourceNodeId: Type.Optional(Type.String()),
|
|
126
137
|
targetNodeId: Type.Optional(Type.String()),
|
|
127
138
|
edgeId: Type.Optional(Type.String()),
|
|
128
|
-
nodes: Type.Optional(Type.Array(Type.
|
|
129
|
-
edges: Type.Optional(Type.Array(Type.
|
|
139
|
+
nodes: Type.Optional(Type.Array(Type.Unsafe({ type: "object" }))),
|
|
140
|
+
edges: Type.Optional(Type.Array(Type.Unsafe({ type: "object" }))),
|
|
130
141
|
});
|
|
131
142
|
function hasCycle(n, edges) {
|
|
132
143
|
const adj = Array.from({ length: n }, () => []);
|
|
@@ -163,7 +174,7 @@ export function makeCanvasTool(host, lang) {
|
|
|
163
174
|
return defineTool({
|
|
164
175
|
name: CANVAS_TOOL_NAME,
|
|
165
176
|
label: "Canvas pipeline",
|
|
166
|
-
description: "Read and edit canvas workflow graphs:
|
|
177
|
+
description: "Read and edit canvas workflow graphs: nodes and edges (single or whole DAG), layout, run and steer nodes, review gates, logs, and reusable custom cards.",
|
|
167
178
|
promptSnippet: "Inspect, edit, run, or debug canvas workflows and canvas references.",
|
|
168
179
|
promptGuidelines: [
|
|
169
180
|
"Get the referenced graph before editing or running it; a canvas reference alone does not request execution",
|
|
@@ -50,8 +50,19 @@ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
|
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
case "canvas_save": {
|
|
53
|
-
if (!isSafeGraphId(msg.graph?.id))
|
|
53
|
+
if (!isSafeGraphId(msg.graph?.id)) {
|
|
54
|
+
send({
|
|
55
|
+
type: "canvas_error",
|
|
56
|
+
code: "invalid_graph",
|
|
57
|
+
message: `Invalid canvas graph id: ${String(msg.graph?.id)}`,
|
|
58
|
+
messageI18n: canvasRuntimeMessage("error.invalidGraphId", {
|
|
59
|
+
id: String(msg.graph?.id),
|
|
60
|
+
}),
|
|
61
|
+
graphId: typeof msg.graph?.id === "string" ? msg.graph.id : undefined,
|
|
62
|
+
requestId: msg.requestId,
|
|
63
|
+
});
|
|
54
64
|
return true;
|
|
65
|
+
}
|
|
55
66
|
try {
|
|
56
67
|
assertCanvasGraph(msg.graph);
|
|
57
68
|
}
|
|
@@ -4,6 +4,7 @@ import { pick } from "./i18n.js";
|
|
|
4
4
|
import { CLAIM_FILES_TOOL_NAME } from "./tool-manager.js";
|
|
5
5
|
import { CLAIM_TTL_MS, resolveClaimPath } from "./claim-store.js";
|
|
6
6
|
export { CLAIM_FILES_TOOL_NAME };
|
|
7
|
+
export const CLAIM_FILES_ACTIONS = ["claim", "release", "list"];
|
|
7
8
|
function fmtTtl(ms) {
|
|
8
9
|
const m = Math.round(ms / 60000);
|
|
9
10
|
return m >= 60 ? `${Math.floor(m / 60)}h${m % 60 ? `${m % 60}m` : ""}` : `${m}m`;
|
|
@@ -17,15 +18,13 @@ export function makeClaimFilesTool(host, lang) {
|
|
|
17
18
|
return defineTool({
|
|
18
19
|
name: CLAIM_FILES_TOOL_NAME,
|
|
19
20
|
label: "Claim files to avoid parallel conflicts",
|
|
20
|
-
description: "
|
|
21
|
-
"Claims release when the run ends (completion, error, or stop); prompts refresh their 30-minute fallback expiry. " +
|
|
22
|
-
"Paths must stay inside the project.",
|
|
21
|
+
description: "Advisory file reservation for parallel runs (auto-releases on run end).",
|
|
23
22
|
promptSnippet: "reserve files you are about to edit (parallel-run guard)",
|
|
24
23
|
parameters: Type.Object({
|
|
25
|
-
action: Type.Optional(Type.
|
|
26
|
-
paths: Type.Optional(Type.Array(Type.String()
|
|
27
|
-
note: Type.Optional(Type.String(
|
|
28
|
-
ttlMinutes: Type.Optional(Type.Number(
|
|
24
|
+
action: Type.Optional(Type.Unsafe({ type: "string", enum: [...CLAIM_FILES_ACTIONS] })),
|
|
25
|
+
paths: Type.Optional(Type.Array(Type.String())),
|
|
26
|
+
note: Type.Optional(Type.String()),
|
|
27
|
+
ttlMinutes: Type.Optional(Type.Number()),
|
|
29
28
|
}),
|
|
30
29
|
execute: async (_id, p, _signal, _onUpdate, _ctx) => {
|
|
31
30
|
const store = host.store();
|