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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
const bindings = new Map();
|
|
4
|
+
// These tools can create unconstrained execution contexts or mutate host policy.
|
|
5
|
+
const barred = new Set([
|
|
6
|
+
"conversation",
|
|
7
|
+
"subagent",
|
|
8
|
+
"worktree",
|
|
9
|
+
"canvas",
|
|
10
|
+
"mcp",
|
|
11
|
+
"tool_manage",
|
|
12
|
+
"codemode",
|
|
13
|
+
"load_tools",
|
|
14
|
+
"browser_page",
|
|
15
|
+
"delegate_task",
|
|
16
|
+
"schedule",
|
|
17
|
+
"mcp_manage",
|
|
18
|
+
"sandbox",
|
|
19
|
+
"team",
|
|
20
|
+
"tool_search",
|
|
21
|
+
]);
|
|
22
|
+
/** Shared by execution authorization and the selectable capability catalog. */
|
|
23
|
+
export function isBotToolAllowed(name) {
|
|
24
|
+
return !barred.has(name) && !name.startsWith("subagent_") && !name.startsWith("team_");
|
|
25
|
+
}
|
|
26
|
+
export function registerBotExecution(bot) {
|
|
27
|
+
if (!bot?.enabled || !bot.id || !isAbsolute(bot.cwd) || !Number.isSafeInteger(bot.revision)) {
|
|
28
|
+
throw new Error("An enabled, versioned local Bot with an absolute cwd is required");
|
|
29
|
+
}
|
|
30
|
+
const snapshot = structuredClone(bot);
|
|
31
|
+
snapshot.cwd = resolve(snapshot.cwd);
|
|
32
|
+
Object.freeze(snapshot.tools);
|
|
33
|
+
Object.freeze(snapshot.skills);
|
|
34
|
+
Object.freeze(snapshot.mcpServers);
|
|
35
|
+
if (snapshot.model)
|
|
36
|
+
Object.freeze(snapshot.model);
|
|
37
|
+
Object.freeze(snapshot);
|
|
38
|
+
let active = true;
|
|
39
|
+
let model = snapshot.model;
|
|
40
|
+
const tools = new Set(snapshot.tools);
|
|
41
|
+
const skills = new Set(snapshot.skills);
|
|
42
|
+
const capability = {
|
|
43
|
+
bot: snapshot,
|
|
44
|
+
assertActive() {
|
|
45
|
+
if (!active)
|
|
46
|
+
throw new Error("Bot execution capability has been revoked");
|
|
47
|
+
},
|
|
48
|
+
allowsTool(name) {
|
|
49
|
+
return active && tools.has(name) && isBotToolAllowed(name);
|
|
50
|
+
},
|
|
51
|
+
filterSkills(items) {
|
|
52
|
+
this.assertActive();
|
|
53
|
+
return items.filter((item) => skills.has(item.name));
|
|
54
|
+
},
|
|
55
|
+
captureModel(fallback) {
|
|
56
|
+
this.assertActive();
|
|
57
|
+
if (!model) {
|
|
58
|
+
const slash = fallback?.indexOf("/") ?? -1;
|
|
59
|
+
if (!fallback || slash <= 0 || slash === fallback.length - 1) {
|
|
60
|
+
throw new Error("Bot requires an explicit local default model");
|
|
61
|
+
}
|
|
62
|
+
model = Object.freeze({ provider: fallback.slice(0, slash), modelId: fallback.slice(slash + 1) });
|
|
63
|
+
}
|
|
64
|
+
return model;
|
|
65
|
+
},
|
|
66
|
+
revoke() {
|
|
67
|
+
active = false;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const clientId = `device-task-${randomUUID()}`;
|
|
71
|
+
bindings.set(clientId, capability);
|
|
72
|
+
return {
|
|
73
|
+
clientId,
|
|
74
|
+
capability,
|
|
75
|
+
release() {
|
|
76
|
+
capability.revoke();
|
|
77
|
+
bindings.delete(clientId);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** A binding is removed only after the executor confirms its task has stopped. */
|
|
82
|
+
export function isBotExecutionRegistered(clientId) {
|
|
83
|
+
return bindings.has(clientId);
|
|
84
|
+
}
|
|
85
|
+
/** Unregistered private IDs fail closed, including after a server restart. */
|
|
86
|
+
export function getBotExecution(clientId) {
|
|
87
|
+
const binding = bindings.get(clientId);
|
|
88
|
+
if (!binding && clientId.startsWith("device-task-"))
|
|
89
|
+
throw new Error("Unregistered Bot execution client");
|
|
90
|
+
return binding;
|
|
91
|
+
}
|
|
92
|
+
/** Executor uses only this control surface; all other public WS commands are denied. */
|
|
93
|
+
export function botExecutionMessageAllowed(clientId, type) {
|
|
94
|
+
const capability = getBotExecution(clientId);
|
|
95
|
+
if (!capability)
|
|
96
|
+
return true;
|
|
97
|
+
if (["abort", "get_state", "pong"].includes(type))
|
|
98
|
+
return true;
|
|
99
|
+
try {
|
|
100
|
+
capability.assertActive();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return ["hello", "new_chat", "prompt"].includes(type);
|
|
106
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { DeviceWorkspaceError, validateDeviceProject } from "./workspaces.js";
|
|
5
|
+
function fail(status, code, message) {
|
|
6
|
+
throw new DeviceWorkspaceError(status, code, message);
|
|
7
|
+
}
|
|
8
|
+
function validate(input) {
|
|
9
|
+
if (!input ||
|
|
10
|
+
typeof input.id !== "string" ||
|
|
11
|
+
!input.id ||
|
|
12
|
+
input.id.length > 256 ||
|
|
13
|
+
typeof input.name !== "string" ||
|
|
14
|
+
!input.name.trim() ||
|
|
15
|
+
input.name.length > 200 ||
|
|
16
|
+
typeof input.description !== "string" ||
|
|
17
|
+
input.description.length > 4000 ||
|
|
18
|
+
typeof input.systemPrompt !== "string" ||
|
|
19
|
+
input.systemPrompt.length > 32000 ||
|
|
20
|
+
typeof input.cwd !== "string" ||
|
|
21
|
+
typeof input.enabled !== "boolean" ||
|
|
22
|
+
!Number.isSafeInteger(input.revision) ||
|
|
23
|
+
input.revision < 1 ||
|
|
24
|
+
(input.model !== undefined &&
|
|
25
|
+
(!input.model ||
|
|
26
|
+
typeof input.model.provider !== "string" ||
|
|
27
|
+
!input.model.provider ||
|
|
28
|
+
typeof input.model.modelId !== "string" ||
|
|
29
|
+
!input.model.modelId)))
|
|
30
|
+
fail(400, "BOT_INVALID", "Invalid Bot identity or model");
|
|
31
|
+
for (const key of ["tools", "skills", "mcpServers"]) {
|
|
32
|
+
if (!Array.isArray(input[key]) ||
|
|
33
|
+
input[key].length > 512 ||
|
|
34
|
+
input[key].some((v) => typeof v !== "string" || !v || v.length > 1024) ||
|
|
35
|
+
new Set(input[key]).size !== input[key].length)
|
|
36
|
+
fail(400, "BOT_INVALID", `Invalid Bot ${key}`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
id: input.id,
|
|
40
|
+
name: input.name.trim(),
|
|
41
|
+
description: input.description,
|
|
42
|
+
systemPrompt: input.systemPrompt,
|
|
43
|
+
cwd: input.cwd,
|
|
44
|
+
...(input.model ? { model: { provider: input.model.provider, modelId: input.model.modelId } } : {}),
|
|
45
|
+
tools: [...input.tools],
|
|
46
|
+
skills: [...input.skills],
|
|
47
|
+
mcpServers: [...input.mcpServers],
|
|
48
|
+
enabled: input.enabled,
|
|
49
|
+
revision: input.revision,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** One instance per service data directory. Mutations and lease admission share one serial queue. */
|
|
53
|
+
export async function createLocalBotRegistry(dataDir) {
|
|
54
|
+
await mkdir(dataDir, { recursive: true });
|
|
55
|
+
const directory = join(dataDir, "device-bots");
|
|
56
|
+
await mkdir(directory, { recursive: true });
|
|
57
|
+
const scopeFile = (scope) => join(directory, `${createHash("sha256").update(scope).digest("hex")}.json`);
|
|
58
|
+
let file = scopeFile("unpaired");
|
|
59
|
+
let bots = new Map();
|
|
60
|
+
const leases = new Map();
|
|
61
|
+
let serial = Promise.resolve();
|
|
62
|
+
function enqueue(operation) {
|
|
63
|
+
const result = serial.then(operation);
|
|
64
|
+
serial = result.catch(() => { });
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
async function load(path) {
|
|
68
|
+
const loaded = new Map();
|
|
69
|
+
try {
|
|
70
|
+
const saved = JSON.parse(await readFile(path, "utf8"));
|
|
71
|
+
if (!Array.isArray(saved))
|
|
72
|
+
throw new Error("Invalid Bot registry");
|
|
73
|
+
for (const entry of saved) {
|
|
74
|
+
const bot = validate(entry);
|
|
75
|
+
if (loaded.has(bot.id))
|
|
76
|
+
throw new Error("Duplicate Bot ID");
|
|
77
|
+
loaded.set(bot.id, bot);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code !== "ENOENT")
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
return loaded;
|
|
85
|
+
}
|
|
86
|
+
bots = await load(file);
|
|
87
|
+
async function commit(next) {
|
|
88
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
89
|
+
try {
|
|
90
|
+
await writeFile(temporary, JSON.stringify([...next.values()]), { mode: 0o600, flag: "wx" });
|
|
91
|
+
await rename(temporary, file);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
fail(500, "BOT_SAVE_FAILED", "Could not save Bot registry");
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
await rm(temporary, { force: true }).catch(() => { });
|
|
98
|
+
}
|
|
99
|
+
bots = next;
|
|
100
|
+
}
|
|
101
|
+
function mutable(id, revision) {
|
|
102
|
+
const current = bots.get(id);
|
|
103
|
+
if (!current)
|
|
104
|
+
fail(404, "BOT_NOT_FOUND", "Bot not found");
|
|
105
|
+
if (current.revision !== revision)
|
|
106
|
+
fail(409, "BOT_REVISION_CONFLICT", "Bot configuration changed");
|
|
107
|
+
if (leases.get(id))
|
|
108
|
+
fail(409, "BOT_BUSY", "Bot is busy; wait for all execution and file operations to stop");
|
|
109
|
+
return current;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
setScope: (scope) => enqueue(async () => {
|
|
113
|
+
if (typeof scope !== "string" || !scope || scope.length > 4096)
|
|
114
|
+
fail(400, "BOT_SCOPE_INVALID", "Invalid Bot scope");
|
|
115
|
+
const nextFile = scopeFile(scope);
|
|
116
|
+
if (nextFile === file)
|
|
117
|
+
return;
|
|
118
|
+
if (leases.size)
|
|
119
|
+
fail(409, "BOT_BUSY", "Bot scope is busy");
|
|
120
|
+
const next = await load(nextFile);
|
|
121
|
+
file = nextFile;
|
|
122
|
+
bots = next;
|
|
123
|
+
}),
|
|
124
|
+
list: () => structuredClone([...bots.values()]),
|
|
125
|
+
get: (id) => {
|
|
126
|
+
const bot = bots.get(id);
|
|
127
|
+
return bot && structuredClone(bot);
|
|
128
|
+
},
|
|
129
|
+
upsert: (input) => enqueue(async () => {
|
|
130
|
+
if (!input || typeof input !== "object")
|
|
131
|
+
fail(400, "BOT_INVALID", "Invalid Bot");
|
|
132
|
+
const current = input.id ? mutable(input.id, input.revision) : undefined;
|
|
133
|
+
const bot = validate({ ...input, id: current?.id ?? randomUUID(), revision: (current?.revision ?? 0) + 1 });
|
|
134
|
+
bot.cwd = await validateDeviceProject(bot.cwd, dataDir);
|
|
135
|
+
const next = new Map(bots);
|
|
136
|
+
next.set(bot.id, bot);
|
|
137
|
+
await commit(next);
|
|
138
|
+
return structuredClone(bot);
|
|
139
|
+
}),
|
|
140
|
+
remove: (id, revision) => enqueue(async () => {
|
|
141
|
+
mutable(id, revision);
|
|
142
|
+
const next = new Map(bots);
|
|
143
|
+
next.delete(id);
|
|
144
|
+
await commit(next);
|
|
145
|
+
}),
|
|
146
|
+
acquire: (id) => enqueue(async () => {
|
|
147
|
+
const bot = bots.get(id);
|
|
148
|
+
if (!bot || !bot.enabled)
|
|
149
|
+
fail(409, "BOT_UNAVAILABLE", "Bot is missing or disabled");
|
|
150
|
+
const root = await validateDeviceProject(bot.cwd, dataDir);
|
|
151
|
+
leases.set(id, (leases.get(id) ?? 0) + 1);
|
|
152
|
+
let released = false;
|
|
153
|
+
return {
|
|
154
|
+
bot: structuredClone(bot),
|
|
155
|
+
root,
|
|
156
|
+
revision: `${id}:${bot.revision}`,
|
|
157
|
+
release() {
|
|
158
|
+
if (released)
|
|
159
|
+
return;
|
|
160
|
+
released = true;
|
|
161
|
+
const count = (leases.get(id) ?? 1) - 1;
|
|
162
|
+
if (count)
|
|
163
|
+
leases.set(id, count);
|
|
164
|
+
else
|
|
165
|
+
leases.delete(id);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { transferSummary } from "./transfers.js";
|
|
4
|
+
import { checkedUrl } from "./relay.js";
|
|
5
|
+
export function createDeviceCollabService(options) {
|
|
6
|
+
const root = options.root === undefined ? undefined : resolve(options.root);
|
|
7
|
+
return {
|
|
8
|
+
async execute(action, args, signal, context) {
|
|
9
|
+
let workspace;
|
|
10
|
+
try {
|
|
11
|
+
signal?.throwIfAborted();
|
|
12
|
+
if (!context)
|
|
13
|
+
throw new Error("Invalid workspace");
|
|
14
|
+
const readOnly = action === "list_bots" || action === "list_rooms";
|
|
15
|
+
if (!readOnly && !args.sourceBotId)
|
|
16
|
+
throw new Error("Source bot required");
|
|
17
|
+
if (options.workspaceResolver && !["list_bots", "list_rooms", "create_room"].includes(action)) {
|
|
18
|
+
if (!args.roomId)
|
|
19
|
+
throw new Error("Room required");
|
|
20
|
+
if (!args.sourceBotId)
|
|
21
|
+
throw new Error("Source bot required");
|
|
22
|
+
workspace = await options.workspaceResolver({
|
|
23
|
+
roomId: args.roomId,
|
|
24
|
+
sourceBotId: args.sourceBotId,
|
|
25
|
+
context,
|
|
26
|
+
signal,
|
|
27
|
+
});
|
|
28
|
+
if (resolve(context.cwd) !== resolve(workspace.root))
|
|
29
|
+
throw new Error("Invalid workspace");
|
|
30
|
+
}
|
|
31
|
+
else if (!options.workspaceResolver && resolve(context.cwd) !== root)
|
|
32
|
+
throw new Error("Invalid workspace");
|
|
33
|
+
const config = options.getConfig();
|
|
34
|
+
if (!config || !config.deviceId || !config.credential)
|
|
35
|
+
throw new Error("Device unavailable");
|
|
36
|
+
if (!["list_bots", "list_rooms"].includes(action) && !config.allowExecution)
|
|
37
|
+
throw new Error("Device execution disabled");
|
|
38
|
+
const base = checkedUrl(config.hubUrl);
|
|
39
|
+
if (!["http:", "https:"].includes(base.protocol) || base.search)
|
|
40
|
+
throw new Error("Invalid hub URL");
|
|
41
|
+
const parentTaskId = options.getParentTask?.(context);
|
|
42
|
+
const boundBot = options.getSourceBot?.(context);
|
|
43
|
+
if (args.sourceBotId && boundBot && args.sourceBotId !== boundBot)
|
|
44
|
+
throw new Error("Invalid source bot");
|
|
45
|
+
if (action === "create_room" && options.workspaceResolver) {
|
|
46
|
+
workspace = await options.workspaceResolver({ roomId: "", sourceBotId: args.sourceBotId, context, signal });
|
|
47
|
+
if (resolve(context.cwd) !== resolve(workspace.root))
|
|
48
|
+
throw new Error("Invalid workspace");
|
|
49
|
+
}
|
|
50
|
+
const request = async (path, body) => {
|
|
51
|
+
signal?.throwIfAborted();
|
|
52
|
+
const url = new URL(base.href);
|
|
53
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}/api/agent/${path}`;
|
|
54
|
+
const response = await (options.fetch ?? fetch)(url, {
|
|
55
|
+
method: body === undefined ? "GET" : "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
authorization: `Bearer ${config.credential}`,
|
|
58
|
+
"X-Device-Id": config.deviceId,
|
|
59
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
60
|
+
},
|
|
61
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
62
|
+
signal,
|
|
63
|
+
redirect: "error",
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok)
|
|
66
|
+
throw new Error("Hub request failed");
|
|
67
|
+
const result = await response.json();
|
|
68
|
+
signal?.throwIfAborted();
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
const room = () => {
|
|
72
|
+
if (!args.roomId)
|
|
73
|
+
throw new Error("Room required");
|
|
74
|
+
return `rooms/${encodeURIComponent(args.roomId)}`;
|
|
75
|
+
};
|
|
76
|
+
switch (action) {
|
|
77
|
+
case "list_bots": {
|
|
78
|
+
const result = (await request("bots"));
|
|
79
|
+
return { bots: result.bots?.map((bot) => ({ ...bot, local: bot.deviceId === config.deviceId })) ?? [] };
|
|
80
|
+
}
|
|
81
|
+
case "list_rooms":
|
|
82
|
+
return await request("rooms");
|
|
83
|
+
case "create_room":
|
|
84
|
+
if (!args.targetBotId)
|
|
85
|
+
throw new Error("Target required");
|
|
86
|
+
return await request("rooms", {
|
|
87
|
+
name: args.name,
|
|
88
|
+
sourceBotId: args.sourceBotId,
|
|
89
|
+
botIds: [...new Set([args.sourceBotId, args.targetBotId])],
|
|
90
|
+
});
|
|
91
|
+
case "send_message":
|
|
92
|
+
return await request(`${room()}/messages`, { text: args.message, sourceBotId: args.sourceBotId });
|
|
93
|
+
case "send_task":
|
|
94
|
+
if (!args.targetBotId)
|
|
95
|
+
throw new Error("Target required");
|
|
96
|
+
return await request(`${room()}/messages`, {
|
|
97
|
+
text: args.prompt,
|
|
98
|
+
sourceBotId: args.sourceBotId,
|
|
99
|
+
targetBotIds: [args.targetBotId],
|
|
100
|
+
idempotencyKey: randomUUID(),
|
|
101
|
+
...(parentTaskId ? { parentTaskId } : {}),
|
|
102
|
+
});
|
|
103
|
+
case "sync_files": {
|
|
104
|
+
if (!args.targetBotId || !args.roomId || !args.paths?.length)
|
|
105
|
+
throw new Error("Transfer fields required");
|
|
106
|
+
const files = workspace?.files ?? options.files;
|
|
107
|
+
if (!files)
|
|
108
|
+
throw new Error("File workspace unavailable");
|
|
109
|
+
const bundle = await files.prepare({ paths: args.paths, signal });
|
|
110
|
+
const response = await request("transfers", {
|
|
111
|
+
action: "stage",
|
|
112
|
+
roomId: args.roomId,
|
|
113
|
+
sourceBotId: args.sourceBotId,
|
|
114
|
+
targetBotId: args.targetBotId,
|
|
115
|
+
bundle,
|
|
116
|
+
});
|
|
117
|
+
return summarizeTransfer(response);
|
|
118
|
+
}
|
|
119
|
+
case "transfer_preview":
|
|
120
|
+
case "transfer_apply": {
|
|
121
|
+
if (!args.roomId || !args.targetBotId || !args.transferId)
|
|
122
|
+
throw new Error("Transfer fields required");
|
|
123
|
+
if (action === "transfer_apply" && (!args.revision || !Array.isArray(args.overwritePaths)))
|
|
124
|
+
throw new Error("Explicit apply required");
|
|
125
|
+
return summarizeTransfer(await request("transfers", {
|
|
126
|
+
action: action === "transfer_apply" ? "apply" : "preview",
|
|
127
|
+
roomId: args.roomId,
|
|
128
|
+
sourceBotId: args.sourceBotId,
|
|
129
|
+
targetBotId: args.targetBotId,
|
|
130
|
+
transferId: args.transferId,
|
|
131
|
+
...(action === "transfer_apply"
|
|
132
|
+
? { revision: args.revision, overwritePaths: args.overwritePaths }
|
|
133
|
+
: {}),
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
default:
|
|
137
|
+
throw new Error("Unsupported collaboration action");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Remote errors, URLs, fetch errors and local file errors may contain secrets.
|
|
142
|
+
throw new Error(signal?.aborted ? "Device collaboration cancelled." : "Device collaboration request failed.");
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
workspace?.release();
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function summarizeTransfer(value) {
|
|
151
|
+
const id = value && typeof value === "object" ? value.transferId : undefined;
|
|
152
|
+
return { ...transferSummary(value), ...(typeof id === "string" ? { transferId: id } : {}) };
|
|
153
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { DEVICE_COLLAB_TOOL_NAME } from "../tool-manager.js";
|
|
4
|
+
export const DEVICE_COLLAB_ACTIONS = [
|
|
5
|
+
"list_bots",
|
|
6
|
+
"list_rooms",
|
|
7
|
+
"create_room",
|
|
8
|
+
"send_message",
|
|
9
|
+
"send_task",
|
|
10
|
+
"sync_files",
|
|
11
|
+
"transfer_preview",
|
|
12
|
+
"transfer_apply",
|
|
13
|
+
];
|
|
14
|
+
const parameters = Type.Object({
|
|
15
|
+
action: Type.Unsafe({ type: "string", enum: [...DEVICE_COLLAB_ACTIONS] }),
|
|
16
|
+
roomId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
17
|
+
sourceBotId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
18
|
+
targetBotId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
19
|
+
name: Type.Optional(Type.String({ minLength: 1, maxLength: 200 })),
|
|
20
|
+
message: Type.Optional(Type.String({ minLength: 1, maxLength: 16000 })),
|
|
21
|
+
prompt: Type.Optional(Type.String({ minLength: 1, maxLength: 16000 })),
|
|
22
|
+
parentTaskId: Type.Optional(Type.String({
|
|
23
|
+
minLength: 1,
|
|
24
|
+
maxLength: 256,
|
|
25
|
+
description: "Parent remote task; the service verifies or replaces this from the current session.",
|
|
26
|
+
})),
|
|
27
|
+
paths: Type.Optional(Type.Array(Type.String(), { maxItems: 200, description: "Project-relative files to send." })),
|
|
28
|
+
transferId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
29
|
+
revision: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
30
|
+
overwritePaths: Type.Optional(Type.Array(Type.String(), {
|
|
31
|
+
maxItems: 200,
|
|
32
|
+
description: "Project-relative paths explicitly approved for overwrite.",
|
|
33
|
+
})),
|
|
34
|
+
}, { additionalProperties: false });
|
|
35
|
+
let service;
|
|
36
|
+
export function setDeviceCollabService(value) {
|
|
37
|
+
service = value;
|
|
38
|
+
}
|
|
39
|
+
const allowed = {
|
|
40
|
+
list_bots: [],
|
|
41
|
+
list_rooms: [],
|
|
42
|
+
create_room: ["name", "sourceBotId", "targetBotId"],
|
|
43
|
+
send_message: ["roomId", "sourceBotId", "message"],
|
|
44
|
+
send_task: ["roomId", "sourceBotId", "targetBotId", "prompt", "parentTaskId"],
|
|
45
|
+
sync_files: ["roomId", "sourceBotId", "targetBotId", "paths"],
|
|
46
|
+
transfer_preview: ["roomId", "sourceBotId", "targetBotId", "transferId"],
|
|
47
|
+
transfer_apply: ["roomId", "sourceBotId", "targetBotId", "transferId", "revision", "overwritePaths"],
|
|
48
|
+
};
|
|
49
|
+
const required = {
|
|
50
|
+
...allowed,
|
|
51
|
+
send_task: ["roomId", "sourceBotId", "targetBotId", "prompt"],
|
|
52
|
+
};
|
|
53
|
+
function validate(input) {
|
|
54
|
+
if (!input || !Object.hasOwn(allowed, input.action))
|
|
55
|
+
throw new Error("Invalid device_collab action.");
|
|
56
|
+
const fields = allowed[input.action];
|
|
57
|
+
for (const [key, value] of Object.entries(input)) {
|
|
58
|
+
if (key === "action")
|
|
59
|
+
continue;
|
|
60
|
+
if (!fields.includes(key))
|
|
61
|
+
throw new Error("Unsupported device_collab argument.");
|
|
62
|
+
if (key === "paths" || key === "overwritePaths") {
|
|
63
|
+
if (!Array.isArray(value) || value.length > 200 || (key === "paths" && !value.length))
|
|
64
|
+
throw new Error("Invalid file paths.");
|
|
65
|
+
for (const path of value) {
|
|
66
|
+
if (typeof path !== "string" ||
|
|
67
|
+
!path ||
|
|
68
|
+
path.length > 4096 ||
|
|
69
|
+
/[\\:\x00-\x1f]/.test(path) ||
|
|
70
|
+
path.startsWith("/") ||
|
|
71
|
+
path.split("/").some((s) => !s || s === "." || s === ".."))
|
|
72
|
+
throw new Error("File paths must be project-relative without traversal.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (typeof value !== "string" ||
|
|
76
|
+
!value.trim() ||
|
|
77
|
+
value.length > (key === "message" || key === "prompt" ? 16000 : key === "name" ? 200 : 256)) {
|
|
78
|
+
throw new Error("Invalid device_collab argument value.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const key of required[input.action])
|
|
82
|
+
if (!Object.hasOwn(input, key))
|
|
83
|
+
throw new Error(`Missing device_collab argument: ${key}.`);
|
|
84
|
+
}
|
|
85
|
+
// Only structural identifiers/status/counts leave the service boundary. No raw replies,
|
|
86
|
+
// file contents, credentials, endpoints, or arbitrary service error strings are exposed.
|
|
87
|
+
const summaryKeys = new Set([
|
|
88
|
+
"id",
|
|
89
|
+
"deviceId",
|
|
90
|
+
"roomId",
|
|
91
|
+
"botId",
|
|
92
|
+
"sourceBotId",
|
|
93
|
+
"targetBotId",
|
|
94
|
+
"botIds",
|
|
95
|
+
"targetBotIds",
|
|
96
|
+
"enabled",
|
|
97
|
+
"description",
|
|
98
|
+
"transferId",
|
|
99
|
+
"taskId",
|
|
100
|
+
"messageId",
|
|
101
|
+
"revision",
|
|
102
|
+
"status",
|
|
103
|
+
"online",
|
|
104
|
+
"local",
|
|
105
|
+
"ok",
|
|
106
|
+
"count",
|
|
107
|
+
"total",
|
|
108
|
+
"size",
|
|
109
|
+
"bytes",
|
|
110
|
+
"truncated",
|
|
111
|
+
"bots",
|
|
112
|
+
"rooms",
|
|
113
|
+
"tasks",
|
|
114
|
+
"files",
|
|
115
|
+
"conflicts",
|
|
116
|
+
"path",
|
|
117
|
+
"exists",
|
|
118
|
+
"changed",
|
|
119
|
+
"name",
|
|
120
|
+
"sha256",
|
|
121
|
+
"baseline",
|
|
122
|
+
"applied",
|
|
123
|
+
"unchanged",
|
|
124
|
+
"rejected",
|
|
125
|
+
"preview",
|
|
126
|
+
"manifest",
|
|
127
|
+
"totalBytes",
|
|
128
|
+
]);
|
|
129
|
+
function summarize(value, depth = 0) {
|
|
130
|
+
if (depth > 4)
|
|
131
|
+
return undefined;
|
|
132
|
+
if (typeof value === "string")
|
|
133
|
+
return value.slice(0, 256);
|
|
134
|
+
if (typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value)))
|
|
135
|
+
return value;
|
|
136
|
+
if (Array.isArray(value))
|
|
137
|
+
return value.slice(0, 50).map((item) => summarize(item, depth + 1));
|
|
138
|
+
if (value && typeof value === "object") {
|
|
139
|
+
const out = {};
|
|
140
|
+
for (const [key, item] of Object.entries(value))
|
|
141
|
+
if (summaryKeys.has(key))
|
|
142
|
+
out[key] = summarize(item, depth + 1);
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
export function makeDeviceCollabTool() {
|
|
148
|
+
return defineTool({
|
|
149
|
+
name: DEVICE_COLLAB_TOOL_NAME,
|
|
150
|
+
label: "Bot collaboration",
|
|
151
|
+
description: "List bots and rooms, create rooms, send messages or explicit tasks, and preview or apply project file transfers. Actions use a local source bot bound to the current project. Accepts no endpoints, credentials, or arbitrary roots. Returns bounded summaries.",
|
|
152
|
+
promptSnippet: "coordinate tasks and project files with group bots",
|
|
153
|
+
promptGuidelines: [
|
|
154
|
+
"List bots and rooms first; select a local sourceBotId and explicit targetBotId for group tasks.",
|
|
155
|
+
"Use project-relative paths; preview a transfer before applying its revision and explicitly selected overwritePaths.",
|
|
156
|
+
],
|
|
157
|
+
parameters,
|
|
158
|
+
execute: async (_id, input, signal, _onUpdate, context) => {
|
|
159
|
+
const bound = service;
|
|
160
|
+
if (!bound)
|
|
161
|
+
throw new Error("Device collaboration service is not bound.");
|
|
162
|
+
signal?.throwIfAborted();
|
|
163
|
+
validate(input);
|
|
164
|
+
const captured = { cwd: context.cwd, sessionId: context.sessionManager.getSessionId() };
|
|
165
|
+
if (!captured.cwd)
|
|
166
|
+
throw new Error("Device collaboration requires a project context.");
|
|
167
|
+
const { action, ...args } = input;
|
|
168
|
+
let response;
|
|
169
|
+
try {
|
|
170
|
+
response = await bound.execute(action, args, signal, captured);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
signal?.throwIfAborted();
|
|
174
|
+
throw new Error("Device collaboration request failed.");
|
|
175
|
+
}
|
|
176
|
+
signal?.throwIfAborted();
|
|
177
|
+
let summary = response && typeof response === "object" ? (summarize(response) ?? {}) : {};
|
|
178
|
+
if (Buffer.byteLength(JSON.stringify(summary), "utf8") > 48000)
|
|
179
|
+
summary = { truncated: true };
|
|
180
|
+
const details = { action, summary };
|
|
181
|
+
return { content: [{ type: "text", text: JSON.stringify(details) }], details };
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|