pi-web-ui 0.113.0 → 0.114.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 +69 -1
- package/README.md +117 -252
- package/README.zh-CN.md +145 -223
- package/README.zh-TW.md +145 -223
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +145 -20
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2296 -1121
- 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 +18 -8
- package/dist/server/canvas/canvas-agent-tool.js +65 -15
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +516 -199
- 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 +104 -22
- 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/control-socket.js +6 -2
- 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 +332 -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 +829 -0
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +476 -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 +959 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/smoke-preview.js +3 -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 +83 -27
- package/dist/server/dsh/dsh-agent-service.js +277 -158
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/durable/durable-agent-service.js +1 -1
- 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 +110 -34
- 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 +236 -232
- 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/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- 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 +262 -92
- package/dist/server/preset-fields.js +49 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +112 -72
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +160 -67
- package/dist/server/request-context.js +164 -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/scheduler-tasks.js +63 -48
- 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 +267 -111
- package/dist/server/setup-config.js +58 -0
- 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/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +47 -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/session-store.js +48 -6
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +334 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/webui-context.js +6 -6
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/device-center.md +142 -0
- package/docs/device-desktop.md +48 -0
- package/package.json +4 -1
- package/plugin-sdk/index.d.ts +45 -9
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +1 -1
- package/themes/aetheris.css +1 -107
- package/themes/ayu-light.css +5 -29
- package/themes/bases/flow-base.css +0 -6
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +1 -0
- package/themes/bases/zhupi-base.css +1 -0
- package/themes/catppuccin-latte.css +4 -27
- package/themes/catppuccin.css +4 -35
- package/themes/claude-code-dark.css +1 -0
- package/themes/codex.css +4 -28
- package/themes/cyberpunk.css +3 -61
- package/themes/dark-teal.css +0 -1
- package/themes/dazzle.css +3 -73
- package/themes/everforest-light.css +4 -27
- package/themes/geist.css +4 -28
- package/themes/gruvbox-light.css +4 -27
- package/themes/kanagawa-lotus.css +4 -27
- package/themes/md-preview.css +3 -213
- package/themes/mist.css +4 -24
- package/themes/nord.css +4 -35
- package/themes/one-dark.css +4 -37
- package/themes/paper.css +4 -16
- package/themes/rose-pine-dawn.css +4 -28
- package/themes/sakura.css +4 -24
- package/themes/solarized-light.css +4 -27
- package/themes/tokyo-night.css +3 -34
- package/themes/white.css +4 -26
- package/themes/zhujian-dark.css +1 -0
- package/themes/zhupi-dark.css +1 -0
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
- package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
- package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
- package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
- package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
- package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
- package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
- package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
- package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
- package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
- package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
- package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/index-CPgAH5q7.js +83 -0
- package/web/dist/assets/index-Cje8iugL.js +83 -0
- package/web/dist/assets/index-DnKeiDbj.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-CqA4yW6w.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-BqdAjEjF.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +15 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-3wojLfLk.js +0 -3
- package/web/dist/assets/index-A8YXwnpZ.js +0 -2008
- package/web/dist/assets/index-BwL7qBh6.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
2
|
+
import { delimiter, join } from "node:path";
|
|
3
|
+
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
4
|
+
const MAX_FRAME = 4 * 1024 * 1024;
|
|
5
|
+
const MAX_QUEUE = 128;
|
|
6
|
+
const PROBE_OPTIONS = { encoding: "utf8", timeout: 2000, maxBuffer: 256 * 1024, shell: false };
|
|
7
|
+
function executable(name) {
|
|
8
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
9
|
+
if (!directory)
|
|
10
|
+
continue;
|
|
11
|
+
const candidate = join(directory, name);
|
|
12
|
+
try {
|
|
13
|
+
accessSync(candidate, constants.X_OK);
|
|
14
|
+
if (statSync(candidate).isFile())
|
|
15
|
+
return candidate;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
/* Missing or inaccessible PATH entry. */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function linuxDesktopStatus() {
|
|
24
|
+
const unsupported = (reason) => ({ supported: false, backend: "x11", reason });
|
|
25
|
+
if (process.platform !== "linux")
|
|
26
|
+
return unsupported("Linux X11 desktop capture requires Linux.");
|
|
27
|
+
// XWayland only captures X11 windows, not the full Wayland desktop.
|
|
28
|
+
if (process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland" || process.env.WAYLAND_DISPLAY)
|
|
29
|
+
return unsupported("Wayland desktop capture requires Portal/PipeWire and is not supported yet.");
|
|
30
|
+
if (!process.env.DISPLAY)
|
|
31
|
+
return unsupported("No X11 DISPLAY is available; Wayland requires Portal/PipeWire.");
|
|
32
|
+
if (!executable("ffmpeg"))
|
|
33
|
+
return unsupported("X11 desktop capture requires ffmpeg (x11grab).");
|
|
34
|
+
return {
|
|
35
|
+
supported: true,
|
|
36
|
+
backend: "x11",
|
|
37
|
+
...(!executable("xdotool") ? { reason: "View only: install xdotool to enable desktop control." } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function screenSize() {
|
|
41
|
+
const display = process.env.DISPLAY;
|
|
42
|
+
const info = executable("xdpyinfo");
|
|
43
|
+
if (info) {
|
|
44
|
+
try {
|
|
45
|
+
const output = execFileSync(info, ["-display", display], PROBE_OPTIONS);
|
|
46
|
+
const defaultScreen = output.match(/default screen number:\s*(\d+)/)?.[1];
|
|
47
|
+
const section = defaultScreen
|
|
48
|
+
? output.split(new RegExp(`screen #${defaultScreen}:`))[1]?.split(/screen #\d+:/)[0]
|
|
49
|
+
: output;
|
|
50
|
+
const match = section?.match(/dimensions:\s*(\d+)x(\d+)\s+pixels/);
|
|
51
|
+
if (match && +match[1] > 0 && +match[2] > 0)
|
|
52
|
+
return [+match[1], +match[2]];
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* Try xrandr when xdpyinfo cannot query this display. */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const randr = executable("xrandr");
|
|
59
|
+
if (randr) {
|
|
60
|
+
try {
|
|
61
|
+
const output = execFileSync(randr, ["--display", display, "--current"], PROBE_OPTIONS);
|
|
62
|
+
const match = output.match(/current\s+(\d+)\s+x\s+(\d+)/);
|
|
63
|
+
if (match && +match[1] > 0 && +match[2] > 0)
|
|
64
|
+
return [+match[1], +match[2]];
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* Report a useful dependency/display error below. */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error("Cannot determine X11 screen dimensions; install xdpyinfo or xrandr and check DISPLAY/XAUTHORITY.");
|
|
71
|
+
}
|
|
72
|
+
function keySymbol(code) {
|
|
73
|
+
if (/^Key[A-Z]$/.test(code))
|
|
74
|
+
return code.slice(3).toLowerCase();
|
|
75
|
+
if (/^Digit[0-9]$/.test(code))
|
|
76
|
+
return code.slice(5);
|
|
77
|
+
if (/^F([1-9]|1[0-9]|2[0-4])$/.test(code))
|
|
78
|
+
return code;
|
|
79
|
+
return {
|
|
80
|
+
Enter: "Return",
|
|
81
|
+
NumpadEnter: "KP_Enter",
|
|
82
|
+
Escape: "Escape",
|
|
83
|
+
Backspace: "BackSpace",
|
|
84
|
+
Tab: "Tab",
|
|
85
|
+
Space: "space",
|
|
86
|
+
ShiftLeft: "Shift_L",
|
|
87
|
+
ShiftRight: "Shift_R",
|
|
88
|
+
ControlLeft: "Control_L",
|
|
89
|
+
ControlRight: "Control_R",
|
|
90
|
+
AltLeft: "Alt_L",
|
|
91
|
+
AltRight: "Alt_R",
|
|
92
|
+
MetaLeft: "Super_L",
|
|
93
|
+
MetaRight: "Super_R",
|
|
94
|
+
ArrowLeft: "Left",
|
|
95
|
+
ArrowRight: "Right",
|
|
96
|
+
ArrowUp: "Up",
|
|
97
|
+
ArrowDown: "Down",
|
|
98
|
+
Home: "Home",
|
|
99
|
+
End: "End",
|
|
100
|
+
PageUp: "Prior",
|
|
101
|
+
PageDown: "Next",
|
|
102
|
+
Delete: "Delete",
|
|
103
|
+
Insert: "Insert",
|
|
104
|
+
CapsLock: "Caps_Lock",
|
|
105
|
+
Minus: "minus",
|
|
106
|
+
Equal: "equal",
|
|
107
|
+
BracketLeft: "bracketleft",
|
|
108
|
+
BracketRight: "bracketright",
|
|
109
|
+
Backslash: "backslash",
|
|
110
|
+
Semicolon: "semicolon",
|
|
111
|
+
Quote: "apostrophe",
|
|
112
|
+
Backquote: "grave",
|
|
113
|
+
Comma: "comma",
|
|
114
|
+
Period: "period",
|
|
115
|
+
Slash: "slash",
|
|
116
|
+
}[code];
|
|
117
|
+
}
|
|
118
|
+
export function startLinuxDesktop(options) {
|
|
119
|
+
let closed = false;
|
|
120
|
+
let capture;
|
|
121
|
+
let command;
|
|
122
|
+
let killTimer;
|
|
123
|
+
let pending = Buffer.alloc(0);
|
|
124
|
+
let stderr = "";
|
|
125
|
+
let queue = [];
|
|
126
|
+
const keys = new Set();
|
|
127
|
+
const buttons = new Set();
|
|
128
|
+
let control;
|
|
129
|
+
let missingControlReported = false;
|
|
130
|
+
let width = 0, height = 0;
|
|
131
|
+
const report = (message) => {
|
|
132
|
+
options.onError(message);
|
|
133
|
+
};
|
|
134
|
+
const releaseArgs = () => {
|
|
135
|
+
const args = [];
|
|
136
|
+
for (const key of keys)
|
|
137
|
+
args.push("keyup", key);
|
|
138
|
+
for (const button of buttons)
|
|
139
|
+
args.push("mouseup", button);
|
|
140
|
+
return args;
|
|
141
|
+
};
|
|
142
|
+
const releaseAfterStop = () => {
|
|
143
|
+
const args = releaseArgs();
|
|
144
|
+
keys.clear();
|
|
145
|
+
buttons.clear();
|
|
146
|
+
if (!control || !args.length)
|
|
147
|
+
return;
|
|
148
|
+
// One bounded, directly spawned cleanup command; never starts a shell.
|
|
149
|
+
execFile(control, args, { timeout: 2000, killSignal: "SIGKILL", maxBuffer: 16384, shell: false }, () => { });
|
|
150
|
+
};
|
|
151
|
+
const close = () => {
|
|
152
|
+
if (closed)
|
|
153
|
+
return;
|
|
154
|
+
closed = true;
|
|
155
|
+
pending = Buffer.alloc(0);
|
|
156
|
+
queue = [];
|
|
157
|
+
if (capture && capture.exitCode === null && capture.signalCode === null) {
|
|
158
|
+
capture.kill("SIGTERM");
|
|
159
|
+
killTimer = setTimeout(() => capture?.kill("SIGKILL"), 1000);
|
|
160
|
+
killTimer.unref();
|
|
161
|
+
}
|
|
162
|
+
// Wait for the active command's callback before releasing, avoiding a late keydown.
|
|
163
|
+
if (command)
|
|
164
|
+
command.kill("SIGKILL");
|
|
165
|
+
else
|
|
166
|
+
releaseAfterStop();
|
|
167
|
+
options.onClose();
|
|
168
|
+
};
|
|
169
|
+
const fail = (message) => {
|
|
170
|
+
if (closed)
|
|
171
|
+
return;
|
|
172
|
+
try {
|
|
173
|
+
report(message);
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
close();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const drain = () => {
|
|
180
|
+
if (closed || command || !queue.length || !control)
|
|
181
|
+
return;
|
|
182
|
+
const args = queue.shift();
|
|
183
|
+
// Track attempted downs too: an interrupted xdotool can already have injected them.
|
|
184
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
185
|
+
if (args[i] === "keydown")
|
|
186
|
+
keys.add(args[i + 1]);
|
|
187
|
+
if (args[i] === "mousedown")
|
|
188
|
+
buttons.add(args[i + 1]);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
command = execFile(control, args, { timeout: 2000, killSignal: "SIGKILL", maxBuffer: 16384, shell: false }, (error) => {
|
|
192
|
+
command = undefined;
|
|
193
|
+
if (closed) {
|
|
194
|
+
releaseAfterStop();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (error) {
|
|
198
|
+
fail(`xdotool input failed: ${error.message}`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
202
|
+
if (args[i] === "keyup")
|
|
203
|
+
keys.delete(args[i + 1]);
|
|
204
|
+
if (args[i] === "mouseup")
|
|
205
|
+
buttons.delete(args[i + 1]);
|
|
206
|
+
}
|
|
207
|
+
drain();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
command = undefined;
|
|
212
|
+
fail(`xdotool input failed: ${String(error)}`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const input = (event) => {
|
|
216
|
+
if (closed || options.readOnly !== false)
|
|
217
|
+
return;
|
|
218
|
+
if (!control) {
|
|
219
|
+
if (!missingControlReported) {
|
|
220
|
+
missingControlReported = true;
|
|
221
|
+
report("Desktop control requires xdotool; viewing remains available.");
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let args = [];
|
|
226
|
+
switch (event.type) {
|
|
227
|
+
case "pointer": {
|
|
228
|
+
if (!Number.isFinite(event.x) || !Number.isFinite(event.y))
|
|
229
|
+
return;
|
|
230
|
+
args = [
|
|
231
|
+
"mousemove",
|
|
232
|
+
"--sync",
|
|
233
|
+
String(Math.round(Math.max(0, Math.min(1, event.x)) * (width - 1))),
|
|
234
|
+
String(Math.round(Math.max(0, Math.min(1, event.y)) * (height - 1))),
|
|
235
|
+
];
|
|
236
|
+
if (event.action === "down" || event.action === "up") {
|
|
237
|
+
if (![0, 1, 2].includes(event.button))
|
|
238
|
+
return;
|
|
239
|
+
args.push(event.action === "down" ? "mousedown" : "mouseup", String([1, 2, 3][event.button]));
|
|
240
|
+
}
|
|
241
|
+
else if (event.action !== "move")
|
|
242
|
+
return;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "wheel":
|
|
246
|
+
if (!Number.isFinite(event.deltaY) || event.deltaY === 0)
|
|
247
|
+
return;
|
|
248
|
+
args = [
|
|
249
|
+
"click",
|
|
250
|
+
"--repeat",
|
|
251
|
+
String(Math.min(10, Math.max(1, Math.ceil(Math.abs(event.deltaY) / 100)))),
|
|
252
|
+
"--delay",
|
|
253
|
+
"0",
|
|
254
|
+
event.deltaY > 0 ? "5" : "4",
|
|
255
|
+
];
|
|
256
|
+
break;
|
|
257
|
+
case "key": {
|
|
258
|
+
const key = keySymbol(event.code);
|
|
259
|
+
if (!key || (event.action !== "down" && event.action !== "up"))
|
|
260
|
+
return;
|
|
261
|
+
args = [event.action === "down" ? "keydown" : "keyup", key];
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case "text":
|
|
265
|
+
if (typeof event.text !== "string" ||
|
|
266
|
+
!event.text ||
|
|
267
|
+
Buffer.byteLength(event.text) > 4096 ||
|
|
268
|
+
event.text.includes("\0"))
|
|
269
|
+
return;
|
|
270
|
+
args = ["type", "--clearmodifiers", "--delay", "0", "--", event.text];
|
|
271
|
+
break;
|
|
272
|
+
case "release":
|
|
273
|
+
queue = [];
|
|
274
|
+
args = releaseArgs();
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (!args.length)
|
|
280
|
+
return;
|
|
281
|
+
if (queue.length >= MAX_QUEUE) {
|
|
282
|
+
fail("Desktop input queue exceeded its limit.");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
queue.push(args);
|
|
286
|
+
drain();
|
|
287
|
+
};
|
|
288
|
+
try {
|
|
289
|
+
const status = linuxDesktopStatus();
|
|
290
|
+
if (!status.supported)
|
|
291
|
+
throw new Error(status.reason);
|
|
292
|
+
control = executable("xdotool");
|
|
293
|
+
[width, height] = screenSize();
|
|
294
|
+
capture = spawn(executable("ffmpeg"), [
|
|
295
|
+
"-nostdin",
|
|
296
|
+
"-hide_banner",
|
|
297
|
+
"-loglevel",
|
|
298
|
+
"error",
|
|
299
|
+
"-f",
|
|
300
|
+
"x11grab",
|
|
301
|
+
"-framerate",
|
|
302
|
+
"8",
|
|
303
|
+
"-video_size",
|
|
304
|
+
`${width}x${height}`,
|
|
305
|
+
"-i",
|
|
306
|
+
process.env.DISPLAY,
|
|
307
|
+
"-an",
|
|
308
|
+
"-vf",
|
|
309
|
+
"scale=w='min(1600,iw)':h='min(1600,ih)':force_original_aspect_ratio=decrease",
|
|
310
|
+
"-c:v",
|
|
311
|
+
"mjpeg",
|
|
312
|
+
"-q:v",
|
|
313
|
+
"5",
|
|
314
|
+
"-f",
|
|
315
|
+
"image2pipe",
|
|
316
|
+
"pipe:1",
|
|
317
|
+
], { shell: false, stdio: ["ignore", "pipe", "pipe"], env: process.env });
|
|
318
|
+
capture.stdout.on("data", (chunk) => {
|
|
319
|
+
if (closed)
|
|
320
|
+
return;
|
|
321
|
+
// Slice large writes so a single producer chunk cannot grow retained memory unboundedly.
|
|
322
|
+
for (let offset = 0; offset < chunk.length && !closed; offset += 65536) {
|
|
323
|
+
pending = Buffer.concat([pending, chunk.subarray(offset, offset + 65536)]);
|
|
324
|
+
while (pending.length && !closed) {
|
|
325
|
+
const start = pending.indexOf(Buffer.from([0xff, 0xd8]));
|
|
326
|
+
if (start < 0) {
|
|
327
|
+
pending = Buffer.from(pending.subarray(-1));
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
if (start)
|
|
331
|
+
pending = pending.subarray(start);
|
|
332
|
+
const end = pending.indexOf(Buffer.from([0xff, 0xd9]), 2);
|
|
333
|
+
if (end < 0) {
|
|
334
|
+
if (pending.length > MAX_FRAME)
|
|
335
|
+
fail("ffmpeg JPEG frame exceeded 4 MiB.");
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
if (end + 2 > MAX_FRAME) {
|
|
339
|
+
fail("ffmpeg JPEG frame exceeded 4 MiB.");
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
const frame = Buffer.from(pending.subarray(0, end + 2));
|
|
343
|
+
pending = pending.subarray(end + 2);
|
|
344
|
+
try {
|
|
345
|
+
options.onFrame(frame);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
fail(`Desktop frame callback failed: ${String(error)}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
capture.stderr.on("data", (chunk) => {
|
|
354
|
+
if (!closed)
|
|
355
|
+
stderr = (stderr + chunk.toString()).slice(-4096);
|
|
356
|
+
});
|
|
357
|
+
capture.on("error", (error) => fail(`ffmpeg capture failed: ${error.message}`));
|
|
358
|
+
capture.stdout.on("error", (error) => fail(`ffmpeg output failed: ${error.message}`));
|
|
359
|
+
capture.stderr.on("error", (error) => fail(`ffmpeg stderr failed: ${error.message}`));
|
|
360
|
+
capture.on("close", (code, signal) => {
|
|
361
|
+
if (killTimer)
|
|
362
|
+
clearTimeout(killTimer);
|
|
363
|
+
if (!closed)
|
|
364
|
+
fail(`ffmpeg capture stopped (${signal ?? code}): ${stderr || "check X11 permissions and ffmpeg x11grab support"}`);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
// Defer setup failures so callers can store the returned handle before onClose.
|
|
369
|
+
queueMicrotask(() => fail(String(error)));
|
|
370
|
+
}
|
|
371
|
+
return { input, close };
|
|
372
|
+
}
|