@copylee/dsh-computer-use 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +14 -8
- package/helper/CuHelper.cs +1382 -1248
- package/helper/deepseek-white.png +0 -0
- package/lib/index.js +208 -48
- package/lib/types/computer.d.ts +16 -2
- package/lib/types/helper-client.d.ts +2 -1
- package/lib/types/index.d.ts +5 -0
- package/lib/types/overlay.d.ts +43 -4
- package/package.json +3 -2
|
Binary file
|
package/lib/index.js
CHANGED
|
@@ -465,6 +465,8 @@ const MUTATING = /* @__PURE__ */ new Set([
|
|
|
465
465
|
"hold_key",
|
|
466
466
|
"mouse_move"
|
|
467
467
|
]);
|
|
468
|
+
/** Actions that wait for the user to stop typing before they run. */
|
|
469
|
+
const INPUT = new Set([...MUTATING].filter((action) => action !== "mouse_move"));
|
|
468
470
|
var Computer = class Computer {
|
|
469
471
|
helper;
|
|
470
472
|
access;
|
|
@@ -525,7 +527,24 @@ var Computer = class Computer {
|
|
|
525
527
|
await this.refreshDisplays();
|
|
526
528
|
const display = await this.display();
|
|
527
529
|
const size = this.shotSize(display);
|
|
528
|
-
|
|
530
|
+
const shot = await this.capture(display, size);
|
|
531
|
+
await this.remember();
|
|
532
|
+
return shot;
|
|
533
|
+
}
|
|
534
|
+
/** The foreground window as of the model's latest look at the screen. */
|
|
535
|
+
seen;
|
|
536
|
+
async remember() {
|
|
537
|
+
this.seen = await this.foreground().catch(() => void 0);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Did another window come to the front since the model last looked, without
|
|
541
|
+
* the agent acting in between? Then the user (or a popup) changed the screen.
|
|
542
|
+
*/
|
|
543
|
+
async foregroundChanged() {
|
|
544
|
+
const seen = this.seen;
|
|
545
|
+
if (!seen) return void 0;
|
|
546
|
+
const now = await this.foreground().catch(() => void 0);
|
|
547
|
+
return now && now.hwnd !== seen.hwnd ? now : void 0;
|
|
529
548
|
}
|
|
530
549
|
async capture(rect, out) {
|
|
531
550
|
const result = await this.helper.call("screenshot", {
|
|
@@ -571,6 +590,7 @@ var Computer = class Computer {
|
|
|
571
590
|
/** Short description of the frontmost window, for result text. */
|
|
572
591
|
async describeForeground() {
|
|
573
592
|
const win = await this.foreground().catch(() => void 0);
|
|
593
|
+
this.seen = win;
|
|
574
594
|
if (!win) return "Foreground window: none (desktop).";
|
|
575
595
|
return `Foreground window: ${win.exe} — "${win.title.slice(0, 80)}".`;
|
|
576
596
|
}
|
|
@@ -614,6 +634,30 @@ var Computer = class Computer {
|
|
|
614
634
|
if (call.signal.aborted) throw new Error("Cancelled.");
|
|
615
635
|
await this.overlay.begin(call.agent, Computer.statusOf(input));
|
|
616
636
|
const { action } = input;
|
|
637
|
+
const s = this.settings();
|
|
638
|
+
const wasPaused = this.overlay.paused;
|
|
639
|
+
if (await this.overlay.yieldToUser(call.signal, s.pauseOnUserInput && INPUT.has(action)) && INPUT.has(action)) {
|
|
640
|
+
await this.overlay.begin(call.agent, Computer.statusOf(input));
|
|
641
|
+
return {
|
|
642
|
+
text: `Not done: ${wasPaused ? "the user paused computer use (Esc) and has now resumed" : "the user was typing on the keyboard, so you were paused until they stopped"}. ${action} was NOT performed. Look at the new screenshot and re-plan before acting.`,
|
|
643
|
+
...call.vision ? { image: await this.screenshot() } : {},
|
|
644
|
+
skipped: true
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
if (s.pauseOnUserInput && INPUT.has(action)) {
|
|
648
|
+
const changed = await this.foregroundChanged();
|
|
649
|
+
if (changed) {
|
|
650
|
+
await this.overlay.status("检测到窗口切换,重新查看屏幕");
|
|
651
|
+
const image = call.vision ? await this.screenshot() : void 0;
|
|
652
|
+
if (!image) this.seen = changed;
|
|
653
|
+
return {
|
|
654
|
+
text: `Not done: since your last look the foreground window changed to ${changed.exe} ("${changed.title.slice(0, 60)}") without you acting, most likely the user opened it. ${action} was NOT performed. Look at the new screenshot and decide whether to continue there, switch back, or ask the user.`,
|
|
655
|
+
...image ? { image } : {},
|
|
656
|
+
skipped: true
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (INPUT.has(action)) this.seen = void 0;
|
|
617
661
|
switch (action) {
|
|
618
662
|
case "screenshot": {
|
|
619
663
|
const shot = await this.screenshot();
|
|
@@ -782,11 +826,14 @@ const REFERENCES = [
|
|
|
782
826
|
"UIAutomationTypes.dll",
|
|
783
827
|
"WindowsBase.dll"
|
|
784
828
|
];
|
|
785
|
-
/**
|
|
786
|
-
function
|
|
787
|
-
const candidates = [
|
|
829
|
+
/** A file in helper/ at the package root: one level up from lib/ or src/, two from lib/types/. */
|
|
830
|
+
function helperAssetPath(name) {
|
|
831
|
+
const candidates = [`../helper/${name}`, `../../helper/${name}`].map((rel) => fileURLToPath(new URL(rel, import.meta.url)));
|
|
788
832
|
return candidates.find((path) => existsSync(path)) ?? candidates[0];
|
|
789
833
|
}
|
|
834
|
+
function helperSourcePath() {
|
|
835
|
+
return helperAssetPath("CuHelper.cs");
|
|
836
|
+
}
|
|
790
837
|
function frameworkDir() {
|
|
791
838
|
const windir = process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows";
|
|
792
839
|
for (const arch of ["Framework64", "Framework"]) {
|
|
@@ -982,34 +1029,80 @@ var HelperClient = class {
|
|
|
982
1029
|
//#endregion
|
|
983
1030
|
//#region lib/types/overlay.js
|
|
984
1031
|
/**
|
|
985
|
-
* The "AI is controlling your computer" indicator
|
|
986
|
-
* every display plus a status pill
|
|
1032
|
+
* The "AI is controlling your computer" indicator and the user's controls:
|
|
1033
|
+
* an orange glow around every display plus a status pill, both excluded from
|
|
987
1034
|
* screenshots. Shown on the first action of a run, hidden when that agent
|
|
988
|
-
* goes idle
|
|
1035
|
+
* goes idle. A physical Esc pauses / resumes, the stop button cancels the
|
|
1036
|
+
* agent, and typing on the keyboard makes the agent wait. While controlling,
|
|
1037
|
+
* the DeepSeek Harness window can shrink into an always-on-top card.
|
|
989
1038
|
*/
|
|
990
1039
|
/** Without a status change from the host, hide after this long without actions. */
|
|
991
1040
|
const IDLE_HIDE_MS = 9e4;
|
|
1041
|
+
/** A pause longer than this ends the tool call with a message for the model. */
|
|
1042
|
+
const MAX_PAUSE_MS = 15e5;
|
|
1043
|
+
/** Card rectangle in the bottom-right corner of a display's work area. */
|
|
1044
|
+
function cardRect(display) {
|
|
1045
|
+
const scale = display.dpi / 96;
|
|
1046
|
+
const margin = Math.round(16 * scale);
|
|
1047
|
+
const width = Math.round(Math.min(Math.max(display.workWidth * .28, 400 * scale), 560 * scale, display.workWidth - 2 * margin));
|
|
1048
|
+
const height = Math.round(Math.min(display.workHeight * .66, display.workHeight - 2 * margin));
|
|
1049
|
+
return {
|
|
1050
|
+
x: display.workX + display.workWidth - width - margin,
|
|
1051
|
+
y: display.workY + display.workHeight - height - margin,
|
|
1052
|
+
width,
|
|
1053
|
+
height
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
992
1056
|
var OverlayController = class {
|
|
993
1057
|
helper;
|
|
994
1058
|
settings;
|
|
995
1059
|
log;
|
|
1060
|
+
iconPath;
|
|
996
1061
|
agent;
|
|
997
1062
|
visible = false;
|
|
998
1063
|
idleTimer;
|
|
999
|
-
|
|
1064
|
+
hostWindows = [];
|
|
1000
1065
|
stopping = false;
|
|
1001
|
-
|
|
1066
|
+
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
1067
|
+
paused = false;
|
|
1068
|
+
/** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
|
|
1069
|
+
lastUserInput = 0;
|
|
1070
|
+
constructor(helper, settings, log, iconPath = "") {
|
|
1002
1071
|
this.helper = helper;
|
|
1003
1072
|
this.settings = settings;
|
|
1004
1073
|
this.log = log;
|
|
1074
|
+
this.iconPath = iconPath;
|
|
1005
1075
|
helper.onEvent((event) => {
|
|
1006
1076
|
if (event.event === "stop") this.stop(event.reason ?? "user");
|
|
1077
|
+
else if (event.event === "pause") this.paused = true;
|
|
1078
|
+
else if (event.event === "resume") this.paused = false;
|
|
1079
|
+
else if (event.event === "user_input") this.lastUserInput = Date.now();
|
|
1007
1080
|
});
|
|
1008
1081
|
}
|
|
1009
1082
|
/** The agent currently driving the computer, if any. */
|
|
1010
1083
|
get controller() {
|
|
1011
1084
|
return this.agent;
|
|
1012
1085
|
}
|
|
1086
|
+
/** Did the user type after `since`? */
|
|
1087
|
+
userTypedSince(since) {
|
|
1088
|
+
return this.lastUserInput > since;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Hold the next action while the user has paused (Esc) or is typing.
|
|
1092
|
+
* Returns whether it had to wait, so the caller can re-check the screen.
|
|
1093
|
+
*/
|
|
1094
|
+
async yieldToUser(signal, waitForTyping) {
|
|
1095
|
+
const idleMs = this.settings().userIdleMs;
|
|
1096
|
+
const typing = () => waitForTyping && Date.now() - this.lastUserInput < idleMs;
|
|
1097
|
+
if (!this.paused && !typing()) return false;
|
|
1098
|
+
const started = Date.now();
|
|
1099
|
+
while (this.paused || typing()) {
|
|
1100
|
+
if (signal.aborted) throw new Error("Cancelled.");
|
|
1101
|
+
if (Date.now() - started > MAX_PAUSE_MS) throw new Error("Computer use has been paused by the user for a long time. Stop here and ask the user whether to continue.");
|
|
1102
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1103
|
+
}
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1013
1106
|
/** Called before every action: shows the overlay once and updates its status line. */
|
|
1014
1107
|
async begin(agent, status) {
|
|
1015
1108
|
if (agent) this.agent = agent;
|
|
@@ -1017,14 +1110,20 @@ var OverlayController = class {
|
|
|
1017
1110
|
const settings = this.settings();
|
|
1018
1111
|
if (!this.visible) {
|
|
1019
1112
|
this.visible = true;
|
|
1020
|
-
|
|
1113
|
+
this.paused = false;
|
|
1114
|
+
await this.shrinkHost(settings.hostWindow);
|
|
1021
1115
|
if (settings.overlay) await this.helper.call("overlay_show", {
|
|
1022
|
-
label: `${settings.overlayLabel || "DeepSeek"}
|
|
1023
|
-
status
|
|
1116
|
+
label: `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
|
|
1117
|
+
status,
|
|
1118
|
+
icon: this.iconPath,
|
|
1119
|
+
idleMs: settings.userIdleMs
|
|
1024
1120
|
}).catch((error) => this.log(`overlay: ${String(error)}`));
|
|
1025
1121
|
return;
|
|
1026
1122
|
}
|
|
1027
|
-
|
|
1123
|
+
await this.status(status);
|
|
1124
|
+
}
|
|
1125
|
+
async status(status) {
|
|
1126
|
+
if (this.visible && this.settings().overlay) await this.helper.call("overlay_status", { status }).catch(() => {});
|
|
1028
1127
|
}
|
|
1029
1128
|
/** Agent finished (idle), was cancelled, or the plugin is stopping. */
|
|
1030
1129
|
async end(agent) {
|
|
@@ -1032,6 +1131,7 @@ var OverlayController = class {
|
|
|
1032
1131
|
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
1033
1132
|
this.idleTimer = void 0;
|
|
1034
1133
|
this.agent = void 0;
|
|
1134
|
+
this.paused = false;
|
|
1035
1135
|
if (!this.visible) return;
|
|
1036
1136
|
this.visible = false;
|
|
1037
1137
|
await this.helper.call("overlay_hide").catch(() => {});
|
|
@@ -1058,23 +1158,47 @@ var OverlayController = class {
|
|
|
1058
1158
|
}, IDLE_HIDE_MS);
|
|
1059
1159
|
this.idleTimer.unref();
|
|
1060
1160
|
}
|
|
1061
|
-
|
|
1161
|
+
/** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
|
|
1162
|
+
async shrinkHost(mode) {
|
|
1163
|
+
if (mode === "keep") return;
|
|
1062
1164
|
try {
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1165
|
+
const rows = (await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized);
|
|
1166
|
+
if (rows.length === 0) return;
|
|
1167
|
+
if (mode === "minimize") {
|
|
1168
|
+
for (const row of rows) await this.helper.call("window_cmd", {
|
|
1169
|
+
hwnd: row.hwnd,
|
|
1170
|
+
op: "minimize"
|
|
1171
|
+
});
|
|
1172
|
+
this.hostWindows = rows.map((row) => ({
|
|
1173
|
+
hwnd: row.hwnd,
|
|
1174
|
+
mode: "minimize"
|
|
1175
|
+
}));
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
const main = rows.find((row) => row.foreground) ?? rows.reduce((a, b) => a.width * a.height >= b.width * b.height ? a : b);
|
|
1179
|
+
const displays = await this.helper.call("displays");
|
|
1180
|
+
const cx = main.x + main.width / 2;
|
|
1181
|
+
const cy = main.y + main.height / 2;
|
|
1182
|
+
const display = displays.find((d) => cx >= d.x && cx < d.x + d.width && cy >= d.y && cy < d.y + d.height) ?? displays.find((d) => d.primary) ?? displays[0];
|
|
1183
|
+
if (!display) return;
|
|
1184
|
+
await this.helper.call("window_card", {
|
|
1185
|
+
hwnd: main.hwnd,
|
|
1186
|
+
...cardRect(display)
|
|
1067
1187
|
});
|
|
1068
|
-
this.
|
|
1188
|
+
this.hostWindows = [{
|
|
1189
|
+
hwnd: main.hwnd,
|
|
1190
|
+
mode: "card"
|
|
1191
|
+
}];
|
|
1069
1192
|
} catch (error) {
|
|
1070
|
-
this.log(`
|
|
1193
|
+
this.log(`host window ${mode}: ${String(error)}`);
|
|
1071
1194
|
}
|
|
1072
1195
|
}
|
|
1073
1196
|
async restoreHost() {
|
|
1074
|
-
const
|
|
1075
|
-
this.
|
|
1076
|
-
for (const
|
|
1077
|
-
|
|
1197
|
+
const windows = this.hostWindows;
|
|
1198
|
+
this.hostWindows = [];
|
|
1199
|
+
for (const win of windows) if (win.mode === "card") await this.helper.call("window_uncard", { hwnd: win.hwnd }).catch(() => {});
|
|
1200
|
+
else await this.helper.call("window_cmd", {
|
|
1201
|
+
hwnd: win.hwnd,
|
|
1078
1202
|
op: "restore"
|
|
1079
1203
|
}).catch(() => {});
|
|
1080
1204
|
}
|
|
@@ -1085,16 +1209,16 @@ function promptText(mode) {
|
|
|
1085
1209
|
return `# Computer use (Windows desktop)
|
|
1086
1210
|
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
|
|
1087
1211
|
${mode === "per-app" ? "- Before acting on an app, call request_access once with every app the task needs; the user approves it. Input to apps that are not granted is refused.\n" : ""}- Start with a screenshot (computer action "screenshot") unless you just received one. All coordinates are pixels of the latest screenshot; the plugin converts them for DPI and scaling.
|
|
1088
|
-
- Open or switch apps with open_application (by name) rather than hunting through the taskbar or Start menu. Use windows to see which windows exist; each line shows the process .exe.
|
|
1089
|
-
- The "DeepSeek Harness.exe" window is your own chat interface. Never click or type into it; bring the target window to the front first.
|
|
1212
|
+
- Open or switch apps with open_application (by name; it also finds desktop shortcuts) rather than hunting through the taskbar or Start menu or starting GUI apps from a shell. Use windows to see which windows exist; each line shows the process .exe.
|
|
1213
|
+
- The "DeepSeek Harness.exe" window is your own chat interface; while you control the computer it may float as a small card in a corner. Never click or type into it; bring the target window to the front first, and work around the card.
|
|
1090
1214
|
- Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets; zoom in when text is small.
|
|
1091
1215
|
- Actions return a fresh screenshot. Check it before continuing and verify the result instead of assuming success. Use computer_batch for several confident steps in a row.
|
|
1092
1216
|
- If the user has a dedicated tool for a website or service (browser automation, an API tool), prefer it over driving the desktop.
|
|
1093
1217
|
- Do not enter passwords, payment details or solve CAPTCHAs: stop and ask the user to do that step. Ask before irreversible actions (sending messages, deleting, purchasing) unless the user clearly asked for them.
|
|
1094
|
-
- The user sees an orange border and can press Esc at any time
|
|
1218
|
+
- The user sees an orange border and can press Esc to pause you at any time. If they pause, type on the keyboard or switch windows, you wait; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
|
|
1095
1219
|
}
|
|
1096
1220
|
//#endregion
|
|
1097
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.
|
|
1221
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_0d6b19188928ab894325adc32e18b0b5/node_modules/@deepseek-ai/dsh-scope/lib/index.js
|
|
1098
1222
|
/**
|
|
1099
1223
|
* Shared insertion-ordered storage and effect ownership for scope-aware registries.
|
|
1100
1224
|
*
|
|
@@ -1373,7 +1497,7 @@ function scopeTarget(base, key) {
|
|
|
1373
1497
|
return carrier;
|
|
1374
1498
|
}
|
|
1375
1499
|
//#endregion
|
|
1376
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-typert-
|
|
1500
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
|
|
1377
1501
|
/** The one Remote failure class shared by owners, the Gateway, and consumers. */
|
|
1378
1502
|
/**
|
|
1379
1503
|
* One Remote call failure: a real Error carrying its stable code and typed
|
|
@@ -1533,7 +1657,7 @@ function validateName(subject, value) {
|
|
|
1533
1657
|
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
1534
1658
|
}
|
|
1535
1659
|
//#endregion
|
|
1536
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-util-
|
|
1660
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
|
|
1537
1661
|
/** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
|
|
1538
1662
|
/**
|
|
1539
1663
|
* Mark an unreachable closed-union branch.
|
|
@@ -1745,7 +1869,7 @@ function deepFreeze(value) {
|
|
|
1745
1869
|
return value;
|
|
1746
1870
|
}
|
|
1747
1871
|
//#endregion
|
|
1748
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-util-
|
|
1872
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-util-crypto@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
|
|
1749
1873
|
/**
|
|
1750
1874
|
* Random v4 UUID, minted from `crypto.getRandomValues`.
|
|
1751
1875
|
* @returns the UUID string.
|
|
@@ -1781,7 +1905,7 @@ function brandString(value) {
|
|
|
1781
1905
|
return value;
|
|
1782
1906
|
}
|
|
1783
1907
|
//#endregion
|
|
1784
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.
|
|
1908
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
|
|
1785
1909
|
/** Largest delay Node schedules without clamping it to one millisecond. */
|
|
1786
1910
|
const MAX_TIMER_DELAY_MS = 2147483647;
|
|
1787
1911
|
//#endregion
|
|
@@ -2962,7 +3086,7 @@ function adapterFailureChunk(error, signal) {
|
|
|
2962
3086
|
};
|
|
2963
3087
|
}
|
|
2964
3088
|
//#endregion
|
|
2965
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0._2cc6ce11d95db65b014013a78bf96eaa/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
|
|
3089
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.2._2cc6ce11d95db65b014013a78bf96eaa/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
|
|
2966
3090
|
/**
|
|
2967
3091
|
* The escalation vocabulary and choreography shared by every sandbox-enforcing
|
|
2968
3092
|
* tool family (`@deepseek-ai/dsh-tool-bash`, `@deepseek-ai/dsh-tool-fs`): the
|
|
@@ -3048,7 +3172,7 @@ async function approveEscalation(request, approval) {
|
|
|
3048
3172
|
}
|
|
3049
3173
|
}
|
|
3050
3174
|
//#endregion
|
|
3051
|
-
//#region node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.
|
|
3175
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.0-rc.2_c6e351a6a6cfd1c2a664558bffcd410d/node_modules/@deepseek-ai/dsh-tools/lib/index.js
|
|
3052
3176
|
/**
|
|
3053
3177
|
* Enforced JSON Schema subset shared by tool outputs, generated PTC mode
|
|
3054
3178
|
* types, subagents, and workflows. The subset accepts any JSON root, an
|
|
@@ -6832,7 +6956,7 @@ function createTools(host) {
|
|
|
6832
6956
|
description: "Control the Windows desktop with the mouse and keyboard, like a person. Coordinates are pixels of the latest screenshot (the plugin handles DPI and scaling). Clicks, typing, keys and scrolls return a fresh screenshot automatically, so do not call screenshot again right after. Prefer keyboard shortcuts when they are reliable. zoom shows a region at full resolution for small text.",
|
|
6833
6957
|
parameters: actionProperties,
|
|
6834
6958
|
output,
|
|
6835
|
-
timeoutMs:
|
|
6959
|
+
timeoutMs: 18e5,
|
|
6836
6960
|
async execute(args, exec) {
|
|
6837
6961
|
const call = await host.context(exec);
|
|
6838
6962
|
const input = args;
|
|
@@ -6868,7 +6992,7 @@ function createTools(host) {
|
|
|
6868
6992
|
}
|
|
6869
6993
|
} },
|
|
6870
6994
|
output,
|
|
6871
|
-
timeoutMs:
|
|
6995
|
+
timeoutMs: 18e5,
|
|
6872
6996
|
async execute(args, exec) {
|
|
6873
6997
|
const call = await host.context(exec);
|
|
6874
6998
|
const actions = args.actions;
|
|
@@ -6882,9 +7006,18 @@ function createTools(host) {
|
|
|
6882
7006
|
break;
|
|
6883
7007
|
}
|
|
6884
7008
|
try {
|
|
7009
|
+
const stepStart = Date.now();
|
|
6885
7010
|
const outcome = await computer.run(input, call);
|
|
7011
|
+
if (outcome.skipped) {
|
|
7012
|
+
failure = `#${index + 1} ${input.action} skipped: the user was typing on the keyboard. Re-check the screen before continuing.`;
|
|
7013
|
+
break;
|
|
7014
|
+
}
|
|
6886
7015
|
lines.push(`#${index + 1} ${outcome.text}`);
|
|
6887
7016
|
await setTimeout$1(60, void 0, { signal: call.signal });
|
|
7017
|
+
if (computer.settings().pauseOnUserInput && computer.overlay.userTypedSince(stepStart - 1)) {
|
|
7018
|
+
failure = `#${index + 1} done, but the user typed on the keyboard meanwhile; remaining actions stopped. Re-check the screen before continuing.`;
|
|
7019
|
+
break;
|
|
7020
|
+
}
|
|
6888
7021
|
} catch (error) {
|
|
6889
7022
|
if (call.signal.aborted) {
|
|
6890
7023
|
await computer.releaseHeld();
|
|
@@ -6910,7 +7043,7 @@ function createTools(host) {
|
|
|
6910
7043
|
description: "App name as shown in the Start menu, an executable path, or an http(s) URL."
|
|
6911
7044
|
} },
|
|
6912
7045
|
output,
|
|
6913
|
-
timeoutMs:
|
|
7046
|
+
timeoutMs: 18e5,
|
|
6914
7047
|
async execute(args, exec) {
|
|
6915
7048
|
const call = await host.context(exec);
|
|
6916
7049
|
const name = String(args.name ?? "").trim();
|
|
@@ -6922,6 +7055,7 @@ function createTools(host) {
|
|
|
6922
7055
|
if (!running || !computer.access.isGranted(call.session, running)) throw new Error(`"${name}" is not granted for this session. Call request_access with ["${name}"] first.`);
|
|
6923
7056
|
}
|
|
6924
7057
|
await computer.overlay.begin(call.agent, `打开 ${name}`);
|
|
7058
|
+
await computer.overlay.yieldToUser(call.signal, false);
|
|
6925
7059
|
const before = await computer.foreground();
|
|
6926
7060
|
let how;
|
|
6927
7061
|
const running = isUrl ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
@@ -6985,6 +7119,7 @@ function createTools(host) {
|
|
|
6985
7119
|
const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
|
|
6986
7120
|
if (denial && !(action === "minimize" && isHostWindow(target))) throw new Error(denial);
|
|
6987
7121
|
await computer.overlay.begin(call.agent, `窗口 ${action}`);
|
|
7122
|
+
await computer.overlay.yieldToUser(call.signal, false);
|
|
6988
7123
|
let text;
|
|
6989
7124
|
if (action === "focus") text = (await computer.focus(target)).focused ? `Focused ${target.exe} ("${target.title.slice(0, 60)}").` : `Windows refused to focus ${target.exe}; try clicking it.`;
|
|
6990
7125
|
else {
|
|
@@ -7140,14 +7275,16 @@ const inject = ["tools", "attachments"];
|
|
|
7140
7275
|
const DEFAULTS = {
|
|
7141
7276
|
accessMode: "per-app",
|
|
7142
7277
|
overlay: true,
|
|
7143
|
-
overlayLabel: "DeepSeek",
|
|
7144
|
-
|
|
7278
|
+
overlayLabel: "DeepSeek Harness",
|
|
7279
|
+
hostWindow: "card",
|
|
7145
7280
|
autoScreenshot: true,
|
|
7146
7281
|
settleMs: 400,
|
|
7147
7282
|
maxLongEdge: 1366,
|
|
7148
7283
|
maxPixels: 115e4,
|
|
7149
7284
|
jpegQuality: 80,
|
|
7150
|
-
blockedApps: []
|
|
7285
|
+
blockedApps: [],
|
|
7286
|
+
pauseOnUserInput: true,
|
|
7287
|
+
userIdleMs: 1500
|
|
7151
7288
|
};
|
|
7152
7289
|
const Config = z.object({
|
|
7153
7290
|
accessMode: z.union([z.const("per-app").i18n({
|
|
@@ -7164,13 +7301,26 @@ const Config = z.object({
|
|
|
7164
7301
|
"zh-CN": { $description: "控制时显示橙色光晕边框和顶部提示条(不会出现在截图里,按 Esc 可停止)" },
|
|
7165
7302
|
"en-US": { $description: "Show the orange glow and status pill while controlling (hidden from screenshots; Esc stops)" }
|
|
7166
7303
|
}),
|
|
7167
|
-
overlayLabel: z.string().default("DeepSeek").volatile().i18n({
|
|
7168
|
-
"zh-CN": { $description: "提示条名称:“<名称>
|
|
7169
|
-
"en-US": { $description: "Name in the pill: \"<name>
|
|
7304
|
+
overlayLabel: z.string().default("DeepSeek Harness").volatile().i18n({
|
|
7305
|
+
"zh-CN": { $description: "提示条名称:“<名称> 正在操控你的电脑”" },
|
|
7306
|
+
"en-US": { $description: "Name in the pill: \"<name> 正在操控你的电脑\"" }
|
|
7170
7307
|
}),
|
|
7171
|
-
|
|
7172
|
-
"
|
|
7173
|
-
|
|
7308
|
+
hostWindow: z.union([
|
|
7309
|
+
z.const("card").i18n({
|
|
7310
|
+
"zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
|
|
7311
|
+
"en-US": { $description: "Shrink to an always-on-top card" }
|
|
7312
|
+
}),
|
|
7313
|
+
z.const("minimize").i18n({
|
|
7314
|
+
"zh-CN": { $description: "最小化" },
|
|
7315
|
+
"en-US": { $description: "Minimize" }
|
|
7316
|
+
}),
|
|
7317
|
+
z.const("keep").i18n({
|
|
7318
|
+
"zh-CN": { $description: "保持不变" },
|
|
7319
|
+
"en-US": { $description: "Leave it as is" }
|
|
7320
|
+
})
|
|
7321
|
+
]).default("card").volatile().i18n({
|
|
7322
|
+
"zh-CN": { $description: "操控期间 DeepSeek Harness 窗口怎么摆放(结束后自动恢复原尺寸和位置)" },
|
|
7323
|
+
"en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
|
|
7174
7324
|
}),
|
|
7175
7325
|
autoScreenshot: z.boolean().default(true).volatile().i18n({
|
|
7176
7326
|
"zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
|
|
@@ -7192,6 +7342,14 @@ const Config = z.object({
|
|
|
7192
7342
|
"zh-CN": { $description: "截图 JPEG 质量" },
|
|
7193
7343
|
"en-US": { $description: "Screenshot JPEG quality" }
|
|
7194
7344
|
}),
|
|
7345
|
+
pauseOnUserInput: z.boolean().default(true).volatile().i18n({
|
|
7346
|
+
"zh-CN": { $description: "检测到你在操作时让出控制:你用键盘打字时暂停、停手后继续;你切换或打开了新窗口时,AI 重新看屏幕再决定(鼠标移动不会触发)" },
|
|
7347
|
+
"en-US": { $description: "Yield to you: pause while you type, and re-check the screen when you bring up another window (mouse movement is ignored)" }
|
|
7348
|
+
}),
|
|
7349
|
+
userIdleMs: z.natural().min(300).max(1e4).default(1500).volatile().i18n({
|
|
7350
|
+
"zh-CN": { $description: "键盘停止多少毫秒后恢复操作" },
|
|
7351
|
+
"en-US": { $description: "Milliseconds of keyboard quiet before resuming" }
|
|
7352
|
+
}),
|
|
7195
7353
|
blockedApps: z.array(z.string()).default([]).volatile().i18n({
|
|
7196
7354
|
"zh-CN": { $description: "禁止操控的应用(名称或 exe,如 “alipay”)。常见密码管理器默认已禁止。" },
|
|
7197
7355
|
"en-US": { $description: "Apps that may never be controlled (names or exe). Common password managers are always blocked." }
|
|
@@ -7210,12 +7368,14 @@ function resolveConfig(raw) {
|
|
|
7210
7368
|
accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
|
|
7211
7369
|
overlay: bool("overlay"),
|
|
7212
7370
|
overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
|
|
7213
|
-
|
|
7371
|
+
hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
|
|
7214
7372
|
autoScreenshot: bool("autoScreenshot"),
|
|
7215
7373
|
settleMs: num("settleMs", 0, 5e3),
|
|
7216
7374
|
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
7217
7375
|
maxPixels: num("maxPixels", 3e5, 8e6),
|
|
7218
7376
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
7377
|
+
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
7378
|
+
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
7219
7379
|
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
7220
7380
|
};
|
|
7221
7381
|
}
|
|
@@ -7228,7 +7388,7 @@ function apply(ctx, config = {}) {
|
|
|
7228
7388
|
const log = (message) => ctx.logger.info(message);
|
|
7229
7389
|
const helper = new HelperClient((message) => ctx.logger.warn(message));
|
|
7230
7390
|
const access = new AccessControl();
|
|
7231
|
-
const overlay = new OverlayController(helper, settings, log);
|
|
7391
|
+
const overlay = new OverlayController(helper, settings, log, helperAssetPath("deepseek-white.png"));
|
|
7232
7392
|
const computer = new Computer(helper, access, overlay, settings);
|
|
7233
7393
|
ctx.effect(() => () => {
|
|
7234
7394
|
overlay.end().finally(() => helper.dispose());
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import type { AccessControl, AccessMode, WindowLike } from './access.js';
|
|
2
2
|
import { type Display, type Point, type Size } from './coords.js';
|
|
3
3
|
import type { HelperLike } from './helper-client.js';
|
|
4
|
-
import type { CancellableAgent, OverlayController } from './overlay.js';
|
|
4
|
+
import type { CancellableAgent, HostWindowMode, OverlayController } from './overlay.js';
|
|
5
5
|
export interface Settings {
|
|
6
6
|
accessMode: AccessMode;
|
|
7
7
|
blockedApps: string[];
|
|
8
8
|
overlay: boolean;
|
|
9
9
|
overlayLabel: string;
|
|
10
|
-
|
|
10
|
+
hostWindow: HostWindowMode;
|
|
11
11
|
maxLongEdge: number;
|
|
12
12
|
maxPixels: number;
|
|
13
13
|
jpegQuality: number;
|
|
14
14
|
autoScreenshot: boolean;
|
|
15
15
|
settleMs: number;
|
|
16
|
+
/** Pause while the user types on the physical keyboard. */
|
|
17
|
+
pauseOnUserInput: boolean;
|
|
18
|
+
/** How long the keyboard must be quiet before resuming. */
|
|
19
|
+
userIdleMs: number;
|
|
16
20
|
}
|
|
17
21
|
export interface WindowInfo extends WindowLike {
|
|
18
22
|
hwnd: number;
|
|
@@ -57,6 +61,8 @@ export interface ActionOutcome {
|
|
|
57
61
|
text: string;
|
|
58
62
|
/** A screenshot or zoom image to return to the model. */
|
|
59
63
|
image?: Shot;
|
|
64
|
+
/** The action was not performed because the user took over the keyboard. */
|
|
65
|
+
skipped?: boolean;
|
|
60
66
|
}
|
|
61
67
|
export declare class Computer {
|
|
62
68
|
readonly helper: HelperLike;
|
|
@@ -77,6 +83,14 @@ export declare class Computer {
|
|
|
77
83
|
offscreen: boolean;
|
|
78
84
|
}>;
|
|
79
85
|
screenshot(): Promise<Shot>;
|
|
86
|
+
/** The foreground window as of the model's latest look at the screen. */
|
|
87
|
+
private seen;
|
|
88
|
+
private remember;
|
|
89
|
+
/**
|
|
90
|
+
* Did another window come to the front since the model last looked, without
|
|
91
|
+
* the agent acting in between? Then the user (or a popup) changed the screen.
|
|
92
|
+
*/
|
|
93
|
+
private foregroundChanged;
|
|
80
94
|
private capture;
|
|
81
95
|
zoom(region: number[] | undefined): Promise<Shot>;
|
|
82
96
|
foreground(): Promise<WindowInfo | undefined>;
|
|
@@ -7,7 +7,8 @@ export interface HelperLike {
|
|
|
7
7
|
onEvent(listener: (event: HelperEvent) => void): () => void;
|
|
8
8
|
dispose(): void;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/** A file in helper/ at the package root: one level up from lib/ or src/, two from lib/types/. */
|
|
11
|
+
export declare function helperAssetPath(name: string): string;
|
|
11
12
|
export declare function helperSourcePath(): string;
|
|
12
13
|
/** Compile the helper if this source version has no cached exe yet; returns the exe path. */
|
|
13
14
|
export declare function ensureHelperExe(source?: string): Promise<string>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -8,12 +8,15 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
8
8
|
import z from '@deepseek-ai/schemastery';
|
|
9
9
|
import { type AccessMode } from './access.js';
|
|
10
10
|
import { type Settings } from './computer.js';
|
|
11
|
+
import { type HostWindowMode } from './overlay.js';
|
|
11
12
|
export declare const name = "@copylee/dsh-computer-use";
|
|
12
13
|
export declare const inject: string[];
|
|
13
14
|
export interface Config {
|
|
14
15
|
accessMode?: AccessMode;
|
|
15
16
|
overlay?: boolean;
|
|
16
17
|
overlayLabel?: string;
|
|
18
|
+
hostWindow?: HostWindowMode;
|
|
19
|
+
/** @deprecated replaced by hostWindow: 'minimize' */
|
|
17
20
|
minimizeHostWindow?: boolean;
|
|
18
21
|
autoScreenshot?: boolean;
|
|
19
22
|
settleMs?: number;
|
|
@@ -21,6 +24,8 @@ export interface Config {
|
|
|
21
24
|
maxPixels?: number;
|
|
22
25
|
jpegQuality?: number;
|
|
23
26
|
blockedApps?: string[];
|
|
27
|
+
pauseOnUserInput?: boolean;
|
|
28
|
+
userIdleMs?: number;
|
|
24
29
|
}
|
|
25
30
|
export declare const Config: z<Config>;
|
|
26
31
|
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
package/lib/types/overlay.d.ts
CHANGED
|
@@ -4,29 +4,68 @@ export interface CancellableAgent {
|
|
|
4
4
|
kind: 'user';
|
|
5
5
|
}): void;
|
|
6
6
|
}
|
|
7
|
+
export type HostWindowMode = 'card' | 'minimize' | 'keep';
|
|
7
8
|
export interface OverlaySettings {
|
|
8
9
|
overlay: boolean;
|
|
9
10
|
overlayLabel: string;
|
|
10
|
-
|
|
11
|
+
hostWindow: HostWindowMode;
|
|
12
|
+
userIdleMs: number;
|
|
11
13
|
}
|
|
14
|
+
interface DisplayRow {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
workX: number;
|
|
20
|
+
workY: number;
|
|
21
|
+
workWidth: number;
|
|
22
|
+
workHeight: number;
|
|
23
|
+
primary: boolean;
|
|
24
|
+
dpi: number;
|
|
25
|
+
}
|
|
26
|
+
/** Card rectangle in the bottom-right corner of a display's work area. */
|
|
27
|
+
export declare function cardRect(display: DisplayRow): {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
12
33
|
export declare class OverlayController {
|
|
13
34
|
private readonly helper;
|
|
14
35
|
private readonly settings;
|
|
15
36
|
private readonly log;
|
|
37
|
+
/** Absolute path of the pill icon (PNG). */
|
|
38
|
+
private readonly iconPath;
|
|
16
39
|
private agent;
|
|
17
40
|
private visible;
|
|
18
41
|
private idleTimer;
|
|
19
|
-
private
|
|
42
|
+
private hostWindows;
|
|
20
43
|
private stopping;
|
|
21
|
-
|
|
44
|
+
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
45
|
+
paused: boolean;
|
|
46
|
+
/** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
|
|
47
|
+
lastUserInput: number;
|
|
48
|
+
constructor(helper: HelperLike, settings: () => OverlaySettings, log: (message: string) => void,
|
|
49
|
+
/** Absolute path of the pill icon (PNG). */
|
|
50
|
+
iconPath?: string);
|
|
22
51
|
/** The agent currently driving the computer, if any. */
|
|
23
52
|
get controller(): CancellableAgent | undefined;
|
|
53
|
+
/** Did the user type after `since`? */
|
|
54
|
+
userTypedSince(since: number): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Hold the next action while the user has paused (Esc) or is typing.
|
|
57
|
+
* Returns whether it had to wait, so the caller can re-check the screen.
|
|
58
|
+
*/
|
|
59
|
+
yieldToUser(signal: AbortSignal, waitForTyping: boolean): Promise<boolean>;
|
|
24
60
|
/** Called before every action: shows the overlay once and updates its status line. */
|
|
25
61
|
begin(agent: CancellableAgent | undefined, status: string): Promise<void>;
|
|
62
|
+
status(status: string): Promise<void>;
|
|
26
63
|
/** Agent finished (idle), was cancelled, or the plugin is stopping. */
|
|
27
64
|
end(agent?: CancellableAgent): Promise<void>;
|
|
28
65
|
private stop;
|
|
29
66
|
private armIdle;
|
|
30
|
-
|
|
67
|
+
/** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
|
|
68
|
+
private shrinkHost;
|
|
31
69
|
private restoreHost;
|
|
32
70
|
}
|
|
71
|
+
export {};
|