@copylee/dsh-computer-use 0.8.2 → 0.8.4
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/README.md +45 -138
- package/helper/CuHelper.cs +188 -47
- package/lib/client.js +1 -1
- package/lib/index.js +210 -67
- package/lib/types/browser-host.d.ts +5 -1
- package/lib/types/computer.d.ts +3 -1
- package/lib/types/coords.d.ts +1 -1
- package/lib/types/helper-client.d.ts +1 -0
- package/lib/types/overlay.d.ts +25 -6
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1182,7 +1182,7 @@ window.__ModuleLoader__.load({
|
|
|
1182
1182
|
}), h("span", { style: {
|
|
1183
1183
|
...S.hint,
|
|
1184
1184
|
fontWeight: 400
|
|
1185
|
-
} }, draft.hostWindow === "pet" ? "DSH
|
|
1185
|
+
} }, draft.hostWindow === "pet" ? "卡片上方显示思考,下方显示操作。可拖动、暂停或停止。正文开始输出时,回到 DSH 对话。" : "操控结束或正文开始输出时,恢复 DSH 窗口。")), h("div", { style: S.label }, "悬浮卡片透明度", h(Select, {
|
|
1186
1186
|
label: "悬浮卡片透明度",
|
|
1187
1187
|
disabled: disabled || draft.hostWindow !== "card" && draft.hostWindow !== "pet",
|
|
1188
1188
|
value: String(draft.cardOpacity),
|
package/lib/index.js
CHANGED
|
@@ -216,12 +216,44 @@ function isHarnessAddress(address, harnessUrl) {
|
|
|
216
216
|
const a = new URL(actual), b = new URL(expected);
|
|
217
217
|
return loopback.has(a.hostname) && loopback.has(b.hostname) && a.protocol === b.protocol && a.port === b.port;
|
|
218
218
|
}
|
|
219
|
-
async function readBrowserTab(helper, win) {
|
|
219
|
+
async function readBrowserTab(helper, win, details = false) {
|
|
220
220
|
return await helper.call("browser_tab", {
|
|
221
221
|
hwnd: win.hwnd,
|
|
222
|
-
pid: win.pid
|
|
222
|
+
pid: win.pid,
|
|
223
|
+
...details ? { details } : {}
|
|
223
224
|
}, 2500).catch(() => null) ?? void 0;
|
|
224
225
|
}
|
|
226
|
+
function safeSharedBrowserKeys(combos) {
|
|
227
|
+
return combos.every((combo) => {
|
|
228
|
+
const key = combo.at(-1);
|
|
229
|
+
if (key === void 0) return false;
|
|
230
|
+
const modifiers = combo.slice(0, -1);
|
|
231
|
+
if (modifiers.includes(17)) return modifiers.length === 1 && [
|
|
232
|
+
65,
|
|
233
|
+
67,
|
|
234
|
+
86,
|
|
235
|
+
88,
|
|
236
|
+
89,
|
|
237
|
+
90
|
|
238
|
+
].includes(key);
|
|
239
|
+
return modifiers.every((mod) => mod === 16) && ([
|
|
240
|
+
8,
|
|
241
|
+
9,
|
|
242
|
+
13,
|
|
243
|
+
27,
|
|
244
|
+
32,
|
|
245
|
+
33,
|
|
246
|
+
34,
|
|
247
|
+
35,
|
|
248
|
+
36,
|
|
249
|
+
37,
|
|
250
|
+
38,
|
|
251
|
+
39,
|
|
252
|
+
40,
|
|
253
|
+
46
|
|
254
|
+
].includes(key) || key >= 48 && key <= 90);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
225
257
|
//#endregion
|
|
226
258
|
//#region lib/types/coords.js
|
|
227
259
|
/**
|
|
@@ -975,22 +1007,29 @@ var Computer = class Computer {
|
|
|
975
1007
|
const reason = this.access.denial(call.session, win, s.accessMode, s.blockedApps, verb);
|
|
976
1008
|
if (reason) throw new Error(reason);
|
|
977
1009
|
if (win && s.harnessUrl && isBrowser(win)) {
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
if (
|
|
1010
|
+
const shared = this.overlay.isRememberedWebWindow(win);
|
|
1011
|
+
const tab = await readBrowserTab(this.helper, win, shared);
|
|
1012
|
+
if (isHarnessAddress(tab?.url, s.harnessUrl) || shared && (!tab?.tab || !this.overlay.isWorkTab(tab.tab))) throw new Error("The DeepSeek Harness Web tab is protected. Use open_application with the target URL to open a work tab in the current browser.");
|
|
1013
|
+
if (typeof tab?.url !== "string" || !tab.tab) throw new Error("Could not verify the active browser tab. Use open_application with the target URL or switch to a browser window with a visible address bar.");
|
|
1014
|
+
if (shared) return tab;
|
|
981
1015
|
}
|
|
982
1016
|
}
|
|
1017
|
+
checkWebContent(tab, point) {
|
|
1018
|
+
if (tab && (!tab.content || !contains$1(tab.content, point))) throw new Error("Only the work tab’s page content can be operated in the window containing DeepSeek Harness.");
|
|
1019
|
+
}
|
|
983
1020
|
async checkPointer(call, point, verb) {
|
|
984
1021
|
const target = point ?? await this.cursor();
|
|
985
|
-
await this.assertAllowed(call, await this.windowAt(target), verb);
|
|
1022
|
+
this.checkWebContent(await this.assertAllowed(call, await this.windowAt(target), verb), target);
|
|
986
1023
|
}
|
|
987
1024
|
async checkKeyboard(call, verb) {
|
|
988
1025
|
const window = await this.foreground();
|
|
989
|
-
await this.assertAllowed(call, window, verb);
|
|
1026
|
+
const tab = await this.assertAllowed(call, window, verb);
|
|
1027
|
+
if (tab && !tab.contentFocused) throw new Error("Focus a control in the work tab’s page before sending keyboard input.");
|
|
990
1028
|
return window;
|
|
991
1029
|
}
|
|
992
1030
|
async sendKeys(call, combos, holdMs) {
|
|
993
1031
|
const window = await this.checkKeyboard(call, "send keys to");
|
|
1032
|
+
if (window && this.overlay.isRememberedWebWindow(window) && (holdMs !== void 0 || !safeSharedBrowserKeys(combos))) throw new Error("Browser and window shortcuts are protected in the window containing DeepSeek Harness.");
|
|
994
1033
|
const args = holdMs === void 0 ? {} : { holdMs };
|
|
995
1034
|
if (!this.settings().harnessUrl || !window || !isBrowser(window) || combos.length < 2) {
|
|
996
1035
|
await this.helper.call("keys", {
|
|
@@ -1003,6 +1042,7 @@ var Computer = class Computer {
|
|
|
1003
1042
|
if (index > 0) {
|
|
1004
1043
|
await setTimeout$1(100, void 0, { signal: call.signal });
|
|
1005
1044
|
await this.checkNamed(call, window);
|
|
1045
|
+
if (this.overlay.isRememberedWebWindow(window)) await this.checkKeyboard(call, "send keys to");
|
|
1006
1046
|
}
|
|
1007
1047
|
await this.helper.call("keys", {
|
|
1008
1048
|
combos: [combo],
|
|
@@ -1121,10 +1161,10 @@ var Computer = class Computer {
|
|
|
1121
1161
|
async checkNamed(call, win) {
|
|
1122
1162
|
const current = await this.foreground();
|
|
1123
1163
|
if (current?.hwnd !== win.hwnd || current.pid !== win.pid) throw new Error("The named target window changed. Look again before acting.");
|
|
1124
|
-
|
|
1164
|
+
return this.assertAllowed(call, current, "act on");
|
|
1125
1165
|
}
|
|
1126
1166
|
async checkNamedPoint(call, point, window, element) {
|
|
1127
|
-
await this.checkNamed(call, window);
|
|
1167
|
+
this.checkWebContent(await this.checkNamed(call, window), point);
|
|
1128
1168
|
const hit = await this.windowAt(point);
|
|
1129
1169
|
if (!hit || hit.pid !== window.pid || hit.hwnd !== (element.windowHwnd ?? window.hwnd)) throw new Error("Another window covers the named target. Look again before acting.");
|
|
1130
1170
|
if (hit.hwnd !== window.hwnd && !isBrowser(window)) await this.assertAllowed(call, hit, "click");
|
|
@@ -1161,15 +1201,32 @@ var Computer = class Computer {
|
|
|
1161
1201
|
const until = (input.until ?? "").trim();
|
|
1162
1202
|
const split = until.search(/[::]/);
|
|
1163
1203
|
const prefix = split > 0 ? until.slice(0, split).trim().toLowerCase() : "";
|
|
1164
|
-
const kind = prefix === "window"
|
|
1165
|
-
const subject = (prefix === "window" || prefix === "target" ? until.slice(split + 1) : until).trim();
|
|
1166
|
-
if (subject === "") throw new Error("wait until needs \"window:<title or exe>\"
|
|
1204
|
+
const kind = prefix === "window" || prefix === "text" ? prefix : "target";
|
|
1205
|
+
const subject = (prefix === "window" || prefix === "target" || prefix === "text" ? until.slice(split + 1) : until).trim();
|
|
1206
|
+
if (subject === "") throw new Error("wait until needs \"window:<title or exe>\", \"target:<control name>\", or \"text:<window text>\".");
|
|
1167
1207
|
const gone = input.gone === true;
|
|
1168
1208
|
const timeout = Math.min(60, Math.max(.2, Number(input.duration ?? 10) || 10)) * 1e3;
|
|
1169
1209
|
const needle = subject.toLowerCase();
|
|
1170
1210
|
let suggestions = [];
|
|
1171
1211
|
let firstSeen;
|
|
1212
|
+
const started = Date.now();
|
|
1213
|
+
const textWindow = kind === "text" ? await this.foreground() : void 0;
|
|
1214
|
+
if (kind === "text" && !textWindow) throw new Error("No foreground window to observe for text.");
|
|
1215
|
+
const textTab = textWindow && isBrowser(textWindow) ? (await readBrowserTab(this.helper, textWindow))?.tab : void 0;
|
|
1172
1216
|
const present = async () => {
|
|
1217
|
+
if (textWindow) {
|
|
1218
|
+
const limit = Math.max(100, Math.min(1500, timeout - (Date.now() - started)));
|
|
1219
|
+
if (textTab && (await readBrowserTab(this.helper, textWindow))?.tab !== textTab) return void 0;
|
|
1220
|
+
const result = await this.helper.call("text", {
|
|
1221
|
+
hwnd: textWindow.hwnd,
|
|
1222
|
+
timeoutMs: limit,
|
|
1223
|
+
tail: 2e4
|
|
1224
|
+
}, limit + 1500).catch(() => void 0);
|
|
1225
|
+
if (!result || result.hwnd !== textWindow.hwnd || result.pid !== textWindow.pid || result.source === "none") return void 0;
|
|
1226
|
+
if (textTab && (await readBrowserTab(this.helper, textWindow))?.tab !== textTab) return void 0;
|
|
1227
|
+
const found = result.text.toLowerCase().includes(needle);
|
|
1228
|
+
return !found && result.truncated && gone ? void 0 : found;
|
|
1229
|
+
}
|
|
1173
1230
|
if (kind === "window") {
|
|
1174
1231
|
const matches = (win) => win.title.toLowerCase().includes(needle) || win.exe.toLowerCase().includes(needle) || appMatches(subject, win);
|
|
1175
1232
|
const fg = await this.foreground().catch(() => void 0);
|
|
@@ -1186,17 +1243,17 @@ var Computer = class Computer {
|
|
|
1186
1243
|
if (match.kind === "missing") suggestions = match.suggestions;
|
|
1187
1244
|
return match.kind !== "missing";
|
|
1188
1245
|
};
|
|
1189
|
-
const started = Date.now();
|
|
1190
1246
|
for (;;) {
|
|
1191
1247
|
if (signal.aborted) throw new Error("Cancelled.");
|
|
1192
|
-
|
|
1193
|
-
|
|
1248
|
+
const found = await present();
|
|
1249
|
+
if (found !== void 0 && found !== gone) {
|
|
1250
|
+
const text = `${kind === "window" ? "Window" : kind === "text" ? "Text" : "Control"} "${subject}" ${gone ? "is gone" : "is there"} after ${((Date.now() - started) / 1e3).toFixed(1)}s.`;
|
|
1194
1251
|
await this.settle(signal);
|
|
1195
1252
|
return text;
|
|
1196
1253
|
}
|
|
1197
1254
|
if (Date.now() - started >= timeout) {
|
|
1198
1255
|
const near = !gone && kind === "target" && suggestions.length ? ` Controls there now: ${suggestions.map((name) => `"${name.slice(0, 40)}"`).join(", ")}.` : "";
|
|
1199
|
-
throw new Error(`Timed out after ${Math.round(timeout / 1e3)}s waiting for ${kind === "window" ? "window" : "control"} "${subject}" to ${gone ? "disappear" : "appear"}.${near}`);
|
|
1256
|
+
throw new Error(`Timed out after ${Math.round(timeout / 1e3)}s waiting for ${kind === "window" ? "window" : kind === "text" ? "text" : "control"} "${subject}" to ${gone ? "disappear" : "appear"}.${near}`);
|
|
1200
1257
|
}
|
|
1201
1258
|
await setTimeout$1(POLL_MS, void 0, { signal });
|
|
1202
1259
|
}
|
|
@@ -1290,6 +1347,7 @@ var Computer = class Computer {
|
|
|
1290
1347
|
const from = await this.point(input.start_coordinate, "start_coordinate");
|
|
1291
1348
|
const to = await this.point(input.coordinate);
|
|
1292
1349
|
await this.checkPointer(call, from, "drag in");
|
|
1350
|
+
if (this.settings().harnessUrl) await this.checkPointer(call, to, "drag to");
|
|
1293
1351
|
await this.helper.call("drag", {
|
|
1294
1352
|
x1: from.x,
|
|
1295
1353
|
y1: from.y,
|
|
@@ -1302,7 +1360,11 @@ var Computer = class Computer {
|
|
|
1302
1360
|
case "left_mouse_down":
|
|
1303
1361
|
case "left_mouse_up": {
|
|
1304
1362
|
const p = input.coordinate ? await this.point(input.coordinate) : void 0;
|
|
1305
|
-
if (action === "left_mouse_down")
|
|
1363
|
+
if (action === "left_mouse_down") {
|
|
1364
|
+
const window = await this.windowAt(p ?? await this.cursor());
|
|
1365
|
+
if (window && this.overlay.isRememberedWebWindow(window)) throw new Error("Use a single drag action within the work page instead of holding the mouse button in this browser window.");
|
|
1366
|
+
await this.assertAllowed(call, window, "press the mouse in");
|
|
1367
|
+
}
|
|
1306
1368
|
await this.helper.call("button", {
|
|
1307
1369
|
...p ?? {},
|
|
1308
1370
|
button: "left",
|
|
@@ -1413,6 +1475,7 @@ var Computer = class Computer {
|
|
|
1413
1475
|
const now = await this.foreground().catch(() => void 0);
|
|
1414
1476
|
if (target && now && now.hwnd !== target.hwnd) throw new Error(`Stopped after ${done} of ${items.join("").length} characters: the user paused and ${now.exe} is now in front. Check the screen and continue from where the text stops.`);
|
|
1415
1477
|
}
|
|
1478
|
+
if (index > 0 && target && this.overlay.isRememberedWebWindow(target)) await this.checkKeyboard(call, "type into");
|
|
1416
1479
|
await step(item, index);
|
|
1417
1480
|
done += item.length;
|
|
1418
1481
|
}
|
|
@@ -1555,12 +1618,13 @@ function powershellPath() {
|
|
|
1555
1618
|
const windir = process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows";
|
|
1556
1619
|
return join(windir, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
1557
1620
|
}
|
|
1558
|
-
var HelperClient = class {
|
|
1621
|
+
var HelperClient = class HelperClient {
|
|
1559
1622
|
log;
|
|
1560
1623
|
child;
|
|
1561
1624
|
starting;
|
|
1562
1625
|
pending = /* @__PURE__ */ new Map();
|
|
1563
1626
|
listeners = /* @__PURE__ */ new Set();
|
|
1627
|
+
cardChildren = /* @__PURE__ */ new WeakSet();
|
|
1564
1628
|
nextId = 0;
|
|
1565
1629
|
disposed = false;
|
|
1566
1630
|
constructor(log = () => {}) {
|
|
@@ -1575,6 +1639,7 @@ var HelperClient = class {
|
|
|
1575
1639
|
async call(cmd, args = {}, timeoutMs = 2e4) {
|
|
1576
1640
|
if (this.disposed) throw new Error("computer-use helper is shut down");
|
|
1577
1641
|
const child = await this.ensure();
|
|
1642
|
+
if (this.disposed) throw new Error("computer-use helper is shut down");
|
|
1578
1643
|
const id = ++this.nextId;
|
|
1579
1644
|
return new Promise((resolve, reject) => {
|
|
1580
1645
|
const timer = setTimeout(() => {
|
|
@@ -1585,8 +1650,10 @@ var HelperClient = class {
|
|
|
1585
1650
|
this.pending.set(id, {
|
|
1586
1651
|
resolve,
|
|
1587
1652
|
reject,
|
|
1588
|
-
timer
|
|
1653
|
+
timer,
|
|
1654
|
+
child
|
|
1589
1655
|
});
|
|
1656
|
+
if (cmd === "window_card") this.cardChildren.add(child);
|
|
1590
1657
|
child.stdin.write(`${JSON.stringify({
|
|
1591
1658
|
...args,
|
|
1592
1659
|
id,
|
|
@@ -1672,16 +1739,31 @@ var HelperClient = class {
|
|
|
1672
1739
|
child.stderr.setEncoding("utf8");
|
|
1673
1740
|
child.stderr.on("data", (chunk) => this.log(`helper stderr: ${chunk.trim()}`));
|
|
1674
1741
|
child.on("exit", (code) => {
|
|
1675
|
-
if (this.child === child)
|
|
1676
|
-
|
|
1742
|
+
if (this.child === child) {
|
|
1743
|
+
this.child = void 0;
|
|
1744
|
+
this.starting = void 0;
|
|
1745
|
+
}
|
|
1677
1746
|
for (const [id, entry] of this.pending) {
|
|
1747
|
+
if (entry.child !== child) continue;
|
|
1678
1748
|
clearTimeout(entry.timer);
|
|
1679
1749
|
entry.reject(/* @__PURE__ */ new Error(`computer-use helper exited (code ${String(code)})`));
|
|
1680
1750
|
this.pending.delete(id);
|
|
1681
1751
|
}
|
|
1752
|
+
if (this.cardChildren.has(child) && (!this.disposed || code !== 0)) {
|
|
1753
|
+
const recovery = this.disposed ? new HelperClient(this.log) : this;
|
|
1754
|
+
recovery.call("window_recover").catch((error) => {
|
|
1755
|
+
if (!recovery.disposed) this.log(`recover host window: ${String(error)}`);
|
|
1756
|
+
}).finally(() => {
|
|
1757
|
+
if (recovery !== this) recovery.dispose();
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1682
1760
|
});
|
|
1683
1761
|
await readyPromise;
|
|
1684
1762
|
this.child = child;
|
|
1763
|
+
if (this.disposed) {
|
|
1764
|
+
this.kill();
|
|
1765
|
+
throw new Error("computer-use helper is shut down");
|
|
1766
|
+
}
|
|
1685
1767
|
return child;
|
|
1686
1768
|
}
|
|
1687
1769
|
handle(line, onReady) {
|
|
@@ -1979,22 +2061,21 @@ var OverlayController = class {
|
|
|
1979
2061
|
hostWindows = [];
|
|
1980
2062
|
returnTo;
|
|
1981
2063
|
ending;
|
|
2064
|
+
workTab;
|
|
1982
2065
|
starting;
|
|
1983
2066
|
stopping = false;
|
|
1984
|
-
/** Progress card lines:
|
|
2067
|
+
/** Progress card lines: host-provided reasoning and recent operations. */
|
|
1985
2068
|
streamAgent;
|
|
1986
|
-
text = "";
|
|
1987
2069
|
thinking = "";
|
|
1988
2070
|
/** Recent steps (tool actions), oldest first. */
|
|
1989
2071
|
steps = [];
|
|
1990
|
-
|
|
1991
|
-
thinkingLatest = false;
|
|
1992
|
-
freshAttempt = true;
|
|
2072
|
+
resume;
|
|
1993
2073
|
pushTimer;
|
|
1994
2074
|
/** An instruction the user typed into the progress card. */
|
|
1995
2075
|
onMessage;
|
|
1996
2076
|
/** Called when control starts (before the first action), e.g. to remember the window layout. */
|
|
1997
2077
|
onStart;
|
|
2078
|
+
onRelease;
|
|
1998
2079
|
/** Opacity the card was last given, to apply setting changes while it floats. */
|
|
1999
2080
|
cardOpacity = 100;
|
|
2000
2081
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
@@ -2076,16 +2157,29 @@ var OverlayController = class {
|
|
|
2076
2157
|
}
|
|
2077
2158
|
async start(agent, status, settings) {
|
|
2078
2159
|
await this.rememberHost(settings.harnessUrl).catch((error) => this.log(`remember host: ${String(error)}`));
|
|
2160
|
+
const resume = this.resume;
|
|
2161
|
+
this.resume = void 0;
|
|
2162
|
+
const host = this.returnTo?.window;
|
|
2163
|
+
const foreground = resume && await this.helper.call("foreground").catch(() => null);
|
|
2079
2164
|
await this.onStart?.().catch((error) => this.log(`overlay start: ${String(error)}`));
|
|
2080
2165
|
await this.shrinkHost(settings.hostWindow);
|
|
2166
|
+
if (resume && resume.agent === agent && host?.hwnd === resume.host.hwnd && host.pid === resume.host.pid && foreground?.hwnd === host.hwnd && foreground.pid === host.pid) {
|
|
2167
|
+
const { hwnd, pid } = resume.target;
|
|
2168
|
+
if ((await this.helper.call("focus", {
|
|
2169
|
+
hwnd,
|
|
2170
|
+
pid
|
|
2171
|
+
}, 3e3).catch(() => void 0))?.focused && resume.tab) {
|
|
2172
|
+
if ((await this.helper.call("browser_tab", {
|
|
2173
|
+
hwnd,
|
|
2174
|
+
pid,
|
|
2175
|
+
select: resume.tab
|
|
2176
|
+
}, 2500).catch(() => void 0))?.selected) this.rememberWorkTab(resume.target, resume.tab);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2081
2179
|
const pet = settings.hostWindow === "pet";
|
|
2082
2180
|
if (settings.overlay || pet) {
|
|
2083
|
-
if (this.streamAgent !== agent)
|
|
2084
|
-
this.text = "";
|
|
2085
|
-
this.thinking = "";
|
|
2086
|
-
}
|
|
2181
|
+
if (this.streamAgent !== agent) this.thinking = "";
|
|
2087
2182
|
this.steps = status ? [status] : [];
|
|
2088
|
-
this.thinkingLatest = false;
|
|
2089
2183
|
await this.helper.call("overlay_show", {
|
|
2090
2184
|
label: pet ? `${settings.overlayLabel || "DeepSeek Harness"} 正在操控` : `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
|
|
2091
2185
|
status,
|
|
@@ -2095,7 +2189,7 @@ var OverlayController = class {
|
|
|
2095
2189
|
glow: settings.overlay,
|
|
2096
2190
|
pet,
|
|
2097
2191
|
petOpacity: settings.cardOpacity,
|
|
2098
|
-
|
|
2192
|
+
thinking: this.thinking
|
|
2099
2193
|
}).catch((error) => this.log(`overlay: ${String(error)}`));
|
|
2100
2194
|
}
|
|
2101
2195
|
}
|
|
@@ -2114,35 +2208,30 @@ var OverlayController = class {
|
|
|
2114
2208
|
const line = plainLine(text).trim();
|
|
2115
2209
|
if (line === "" || this.steps.at(-1) === line) return;
|
|
2116
2210
|
this.steps = [...this.steps, line].slice(-8);
|
|
2117
|
-
this.thinkingLatest = false;
|
|
2118
2211
|
this.schedulePush();
|
|
2119
2212
|
}
|
|
2120
2213
|
/** Live model output (DSH agent/assistant-stream) for the progress card. */
|
|
2121
2214
|
stream(agent, frame) {
|
|
2215
|
+
if (this.visible && agent !== this.agent) return;
|
|
2122
2216
|
if (agent !== this.streamAgent) {
|
|
2123
2217
|
this.streamAgent = agent;
|
|
2124
|
-
this.text = "";
|
|
2125
2218
|
this.thinking = "";
|
|
2126
2219
|
this.steps = [];
|
|
2127
2220
|
}
|
|
2128
2221
|
if (frame.type === "start") {
|
|
2129
|
-
this.freshAttempt = true;
|
|
2130
2222
|
this.thinking = "";
|
|
2223
|
+
this.schedulePush();
|
|
2131
2224
|
return;
|
|
2132
2225
|
}
|
|
2133
2226
|
if (this.visible && agent === this.agent) this.armIdle();
|
|
2134
2227
|
const chunk = frame.type === "chunk" ? frame.chunk : void 0;
|
|
2135
2228
|
if (!chunk) return;
|
|
2136
|
-
if (chunk.type === "text-delta" && chunk.text) {
|
|
2137
|
-
if (this.
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
} else if (chunk.type === "reasoning-delta" && chunk.text) {
|
|
2143
|
-
this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
|
|
2144
|
-
this.thinkingLatest = true;
|
|
2145
|
-
} else return;
|
|
2229
|
+
if (chunk.type === "text-delta" && chunk.text?.trim()) {
|
|
2230
|
+
if (this.visible && this.agent && agent === this.agent && !this.paused && !this.stopping) this.end(this.agent, true).catch((error) => this.log(`reply handoff: ${String(error)}`));
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
if (chunk.type !== "reasoning-delta" || !chunk.text) return;
|
|
2234
|
+
this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
|
|
2146
2235
|
this.schedulePush();
|
|
2147
2236
|
}
|
|
2148
2237
|
/** A tool of another plugin started (computer-use tools report their own steps). */
|
|
@@ -2164,16 +2253,14 @@ var OverlayController = class {
|
|
|
2164
2253
|
this.pushTimer = void 0;
|
|
2165
2254
|
if (!this.visible) return;
|
|
2166
2255
|
this.helper.call("pet_update", {
|
|
2167
|
-
text: this.text,
|
|
2168
2256
|
thinking: this.thinking.trim(),
|
|
2169
|
-
steps: this.steps
|
|
2170
|
-
thinkingLatest: this.thinkingLatest
|
|
2257
|
+
steps: this.steps
|
|
2171
2258
|
}).catch(() => {});
|
|
2172
2259
|
}, 80);
|
|
2173
2260
|
this.pushTimer.unref?.();
|
|
2174
2261
|
}
|
|
2175
2262
|
/** Agent finished (idle), was cancelled, or the plugin is stopping. */
|
|
2176
|
-
async end(agent) {
|
|
2263
|
+
async end(agent, replying = false) {
|
|
2177
2264
|
if (this.starting) await this.starting;
|
|
2178
2265
|
if (agent !== void 0 && this.agent !== void 0 && agent !== this.agent) return;
|
|
2179
2266
|
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
@@ -2190,10 +2277,18 @@ var OverlayController = class {
|
|
|
2190
2277
|
this.pushTimer = void 0;
|
|
2191
2278
|
}
|
|
2192
2279
|
this.ending = (async () => {
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2280
|
+
await this.onRelease?.().catch((error) => this.log(`release input: ${String(error)}`));
|
|
2281
|
+
if (replying && agent && this.returnTo) {
|
|
2282
|
+
const host = this.returnTo.window;
|
|
2283
|
+
const target = await this.helper.call("foreground").catch(() => null);
|
|
2284
|
+
if (target?.hwnd && (target.hwnd !== host.hwnd || this.workTab)) this.resume = {
|
|
2285
|
+
agent,
|
|
2286
|
+
host,
|
|
2287
|
+
target,
|
|
2288
|
+
tab: target.hwnd === host.hwnd ? this.workTab : void 0
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
if (!replying && this.settings().hostWindow === "pet" && !this.stopping) await this.helper.call("pet_finish", { holdMs: FINISH_HOLD_MS }).catch(() => {});
|
|
2197
2292
|
else await this.helper.call("overlay_hide").catch(() => {});
|
|
2198
2293
|
await this.restoreHost();
|
|
2199
2294
|
await this.focusRememberedHost().catch((error) => this.log(`restore focus: ${String(error)}`));
|
|
@@ -2208,6 +2303,26 @@ var OverlayController = class {
|
|
|
2208
2303
|
const target = this.returnTo;
|
|
2209
2304
|
return target?.web === true && target.window.hwnd === win.hwnd && target.window.pid === win.pid;
|
|
2210
2305
|
}
|
|
2306
|
+
forgetResume(agent) {
|
|
2307
|
+
const clear = () => {
|
|
2308
|
+
if (this.resume?.agent === agent) this.resume = void 0;
|
|
2309
|
+
};
|
|
2310
|
+
if (this.ending) this.ending.then(clear, clear);
|
|
2311
|
+
else clear();
|
|
2312
|
+
}
|
|
2313
|
+
rememberWorkTab(win, tab) {
|
|
2314
|
+
if (this.isRememberedWebWindow(win)) this.workTab = tab;
|
|
2315
|
+
}
|
|
2316
|
+
rememberWebHost(win, tab) {
|
|
2317
|
+
if (!this.returnTo) this.returnTo = {
|
|
2318
|
+
window: win,
|
|
2319
|
+
web: true,
|
|
2320
|
+
tab
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
isWorkTab(tab) {
|
|
2324
|
+
return this.workTab === tab && this.returnTo?.tab !== tab;
|
|
2325
|
+
}
|
|
2211
2326
|
async rememberHost(harnessUrl) {
|
|
2212
2327
|
const foreground = await this.helper.call("foreground");
|
|
2213
2328
|
if (foreground?.hwnd && isHostWindow(foreground)) {
|
|
@@ -2237,6 +2352,7 @@ var OverlayController = class {
|
|
|
2237
2352
|
async focusRememberedHost() {
|
|
2238
2353
|
const target = this.returnTo;
|
|
2239
2354
|
this.returnTo = void 0;
|
|
2355
|
+
this.workTab = void 0;
|
|
2240
2356
|
if (!target) return;
|
|
2241
2357
|
const { hwnd, pid } = target.window;
|
|
2242
2358
|
if ((await this.helper.call("focus", {
|
|
@@ -2370,7 +2486,7 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
|
|
|
2370
2486
|
- Saving: in any Save As dialog do not click through folders; press alt+n (file name box), ctrl+a, type the full path including the file name, then Return. Office apps: F12 opens that classic dialog directly. To check a saved file, look at the exact path; never search a whole drive or user profile recursively.
|
|
2371
2487
|
- Be fast: what the user waits for is mostly the number of calls you make (each costs seconds). Once you have seen the app's window, put everything predictable into ONE computer_batch, including steps whose target is not on screen yet: name the control with target ("保存", "按钮:确定") instead of a coordinate, and use wait with until ("window:另存为") for a dialog to appear before keys meant for it. Do not end a batch with wait or follow it with a wait or a screenshot: its result already is the settled screen. Do not split work into two batches just to look in between when the second does not depend on what you would see (type the text and format it in the same batch). If you will need to read small text, end the batch with zoom; to read what a window says (a document, a page, a reply, a log) use ui_elements with text: true or finish: "text" instead of scrolling and zooming screenshots. Keep your own text between calls to a line. Avoid shell commands for things you can see on screen.
|
|
2372
2488
|
- When two controls share a name, ui_elements reports automationId; use target "id:<AutomationId>" (or "#<AutomationId>") to pick the intended one.
|
|
2373
|
-
- Open HTTP(S) URLs with open_application
|
|
2489
|
+
- Open HTTP(S) URLs with open_application. To use the user's current Chrome, bring it forward by name first and then pass the URL. This opens a work tab in the current verified browser window when supported. Keep browser chrome and the DeepSeek Harness Web tab untouched. Use new_instance only if the user asks for a separate window.
|
|
2374
2490
|
- To see more of a page or list, scroll (action "scroll" with coordinate over the area, scroll_direction, scroll_amount 5-10) instead of hunting with zoom; for long web pages Page Down / End keys also work.
|
|
2375
2491
|
- If a dedicated tool fits the whole task better (an API, or browser automation attached to the user's own browser), choose it at the start; do not switch tools halfway through a task that is going fine on screen.
|
|
2376
2492
|
- 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.
|
|
@@ -2771,18 +2887,15 @@ function previewRoute(helper, settings, overlay, iconPath) {
|
|
|
2771
2887
|
idleMs: s.userIdleMs,
|
|
2772
2888
|
glow: s.overlay,
|
|
2773
2889
|
pet,
|
|
2774
|
-
petOpacity: s.cardOpacity
|
|
2775
|
-
text: ""
|
|
2890
|
+
petOpacity: s.cardOpacity
|
|
2776
2891
|
});
|
|
2777
2892
|
if (pet) await helper.call("pet_update", {
|
|
2778
|
-
|
|
2779
|
-
thinking: "第二行显示思考过程和最近几步操作",
|
|
2893
|
+
thinking: "先确认表单内容,再核对提交结果。",
|
|
2780
2894
|
steps: [
|
|
2781
2895
|
"打开应用",
|
|
2782
2896
|
"输入文字",
|
|
2783
2897
|
"预览 · 4 秒后消失"
|
|
2784
|
-
]
|
|
2785
|
-
thinkingLatest: false
|
|
2898
|
+
]
|
|
2786
2899
|
}).catch(() => {});
|
|
2787
2900
|
setTimeout(() => {
|
|
2788
2901
|
if (overlay.controller === void 0) helper.call("overlay_hide").catch(() => {});
|
|
@@ -8866,7 +8979,7 @@ const actionProperties = {
|
|
|
8866
8979
|
},
|
|
8867
8980
|
until: {
|
|
8868
8981
|
type: "string",
|
|
8869
|
-
description: "wait:
|
|
8982
|
+
description: "wait: observe \"window:<title or exe part>\", \"target:<control name>\", or \"text:<window text>\" instead of waiting a fixed time."
|
|
8870
8983
|
},
|
|
8871
8984
|
gone: {
|
|
8872
8985
|
type: "boolean",
|
|
@@ -8998,7 +9111,7 @@ function createTools(host) {
|
|
|
8998
9111
|
},
|
|
8999
9112
|
new_instance: {
|
|
9000
9113
|
type: "boolean",
|
|
9001
|
-
description: "
|
|
9114
|
+
description: "Open a separate browser window for a URL, or start another app instance. Use only when explicitly requested."
|
|
9002
9115
|
}
|
|
9003
9116
|
},
|
|
9004
9117
|
output,
|
|
@@ -9029,13 +9142,40 @@ function createTools(host) {
|
|
|
9029
9142
|
await computer.overlay.begin(call.agent, `打开 ${name}`);
|
|
9030
9143
|
await computer.overlay.yieldToUser(call.signal, false);
|
|
9031
9144
|
const before = await computer.foreground();
|
|
9145
|
+
if (isUrl && !newInstance && before?.exe.toLowerCase() === "chrome.exe" && before.className.startsWith("Chrome_WidgetWin")) {
|
|
9146
|
+
const tab = await readBrowserTab(computer.helper, before);
|
|
9147
|
+
if (tab?.tab && typeof tab.url === "string") {
|
|
9148
|
+
const denial = computer.access.denial(call.session, before, call.autoApprove ? "allow-all" : settings.accessMode, settings.blockedApps, "open a new tab in");
|
|
9149
|
+
if (denial) throw new Error(denial);
|
|
9150
|
+
if (settings.harnessUrl && isHarnessAddress(tab.url, settings.harnessUrl)) {
|
|
9151
|
+
computer.overlay.rememberWebHost(before, tab.tab);
|
|
9152
|
+
if (!computer.overlay.isRememberedWebWindow(before)) throw new Error("The current browser shows another DeepSeek Harness session. Switch to the intended browser window before opening the URL.");
|
|
9153
|
+
}
|
|
9154
|
+
if (call.signal.aborted) throw new Error("Cancelled.");
|
|
9155
|
+
const opened = await computer.helper.call("browser_open_tab", {
|
|
9156
|
+
hwnd: before.hwnd,
|
|
9157
|
+
pid: before.pid,
|
|
9158
|
+
tab: tab.tab,
|
|
9159
|
+
url: name
|
|
9160
|
+
}, 12e3);
|
|
9161
|
+
if (!opened?.tab || opened.tab === tab.tab) throw new Error("The browser did not confirm a separate work tab.");
|
|
9162
|
+
computer.overlay.rememberWorkTab(before, opened.tab);
|
|
9163
|
+
if (settings.accessMode === "per-app" && call.autoApprove) computer.access.grant(call.session, [before.exe]);
|
|
9164
|
+
return `Opened ${name} in a new tab of the current ${before.exe} window. ${await computer.describeForeground()}${skillNote(call.session, name, before)}`;
|
|
9165
|
+
}
|
|
9166
|
+
throw new Error("Could not verify the current browser tab. Bring a regular browser tab into view and retry. Use new_instance only if a separate window is wanted.");
|
|
9167
|
+
}
|
|
9032
9168
|
let how;
|
|
9033
9169
|
let openedUrlWindow;
|
|
9034
9170
|
const isUri = isUrl || /^[a-z][a-z0-9+.-]+:(?![\/])/i.test(name);
|
|
9035
|
-
const
|
|
9171
|
+
const matches = (win) => !isHostWindow(win) && appMatches(name, win);
|
|
9172
|
+
const running = isUri || newInstance ? void 0 : before && matches(before) ? before : (await computer.windows()).find(matches);
|
|
9036
9173
|
const hidden = running || isUri || newInstance ? void 0 : (await computer.backgroundApps(false)).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
9037
|
-
if (running)
|
|
9038
|
-
|
|
9174
|
+
if (running) {
|
|
9175
|
+
const denial = computer.access.denial(call.session, running, settings.accessMode, settings.blockedApps, "focus");
|
|
9176
|
+
if (denial) throw new Error(denial);
|
|
9177
|
+
how = (await computer.focus(running)).focused ? `Brought ${running.exe} ("${running.title.slice(0, 60)}") to the front.` : `Tried to bring ${running.exe} to the front, but Windows kept another window focused.`;
|
|
9178
|
+
} else if (hidden) {
|
|
9039
9179
|
const restored = await computer.helper.call("tray_restore", { exe: hidden.exe }, 2e4);
|
|
9040
9180
|
if (restored.window) computer.noteFromTray(restored.window.hwnd);
|
|
9041
9181
|
how = restored.window ? `${hidden.exe} was already running in the system tray: restored its window from the tray icon (no second instance started).` : `${hidden.exe} is already running in the background${restored.icon ? " (system tray)" : ""}, but its window did not come back automatically. Open it from its notification-area icon (click ^ "show hidden icons" on the taskbar first). Do not launch it again (that starts a second instance and login), and never force its hidden window visible from a shell (Electron / Qt apps freeze).`;
|
|
@@ -9419,8 +9559,8 @@ const Config = z.object({
|
|
|
9419
9559
|
}),
|
|
9420
9560
|
hostWindow: z.union([
|
|
9421
9561
|
z.const("pet").i18n({
|
|
9422
|
-
"zh-CN": { $description: "
|
|
9423
|
-
"en-US": { $description: "Minimize it and show a mini progress card (
|
|
9562
|
+
"zh-CN": { $description: "最小化,改用右下角迷你进度卡片(思考与操作时间线)" },
|
|
9563
|
+
"en-US": { $description: "Minimize it and show a mini progress card (reasoning and action timeline)" }
|
|
9424
9564
|
}),
|
|
9425
9565
|
z.const("card").i18n({
|
|
9426
9566
|
"zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
|
|
@@ -9517,6 +9657,7 @@ function apply(ctx, config = {}) {
|
|
|
9517
9657
|
const iconPath = helperAssetPath("deepseek-white.png");
|
|
9518
9658
|
const overlay = new OverlayController(helper, settings, log, iconPath);
|
|
9519
9659
|
const computer = new Computer(helper, access, overlay, settings);
|
|
9660
|
+
overlay.onRelease = () => computer.releaseHeld();
|
|
9520
9661
|
ctx.effect(() => () => {
|
|
9521
9662
|
overlay.end().finally(() => helper.dispose());
|
|
9522
9663
|
}, "computer-use: helper");
|
|
@@ -9677,6 +9818,7 @@ function apply(ctx, config = {}) {
|
|
|
9677
9818
|
};
|
|
9678
9819
|
ctx.on("agent/status", ({ agent, status }) => {
|
|
9679
9820
|
if (status === "running") computer.resetLook();
|
|
9821
|
+
if (status === "idle") overlay.forgetResume(agent);
|
|
9680
9822
|
if (status === "idle" && computer.clipboardAgent === agent) {
|
|
9681
9823
|
computer.clipboardAgent = void 0;
|
|
9682
9824
|
helper.call("clipboard_restore").catch(() => {});
|
|
@@ -9684,6 +9826,7 @@ function apply(ctx, config = {}) {
|
|
|
9684
9826
|
if (status === "idle" && overlay.controller === agent) overlay.end(agent);
|
|
9685
9827
|
});
|
|
9686
9828
|
ctx.on("agent/disposed", ({ agent }) => {
|
|
9829
|
+
overlay.forgetResume(agent);
|
|
9687
9830
|
access.forget(agent.session.id);
|
|
9688
9831
|
if (overlay.controller === agent) overlay.end();
|
|
9689
9832
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HelperLike } from './helper-client.js';
|
|
2
|
+
import type { Rect } from './coords.js';
|
|
2
3
|
interface BrowserWindow {
|
|
3
4
|
hwnd: number;
|
|
4
5
|
pid: number;
|
|
@@ -7,9 +8,12 @@ interface BrowserWindow {
|
|
|
7
8
|
export interface BrowserTab {
|
|
8
9
|
url?: string;
|
|
9
10
|
tab?: string;
|
|
11
|
+
content?: Rect;
|
|
12
|
+
contentFocused?: boolean;
|
|
10
13
|
}
|
|
11
14
|
export declare function isBrowser(win: BrowserWindow): boolean;
|
|
12
15
|
export declare function httpOrigin(value: string): string | undefined;
|
|
13
16
|
export declare function isHarnessAddress(address: string | undefined, harnessUrl: string): boolean;
|
|
14
|
-
export declare function readBrowserTab(helper: HelperLike, win: BrowserWindow): Promise<BrowserTab | undefined>;
|
|
17
|
+
export declare function readBrowserTab(helper: HelperLike, win: BrowserWindow, details?: boolean): Promise<BrowserTab | undefined>;
|
|
18
|
+
export declare function safeSharedBrowserKeys(combos: number[][]): boolean;
|
|
15
19
|
export {};
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AccessControl, type AccessMode, type WindowLike } from './access.js';
|
|
2
|
+
import { type BrowserTab } from './browser-host.js';
|
|
2
3
|
import { type Display, type Point, type Size } from './coords.js';
|
|
3
4
|
import type { HelperLike } from './helper-client.js';
|
|
4
5
|
import { type UiElement } from './target.js';
|
|
@@ -157,7 +158,8 @@ export declare class Computer {
|
|
|
157
158
|
cursor(): Promise<Point>;
|
|
158
159
|
/** Short description of the frontmost window, for result text. */
|
|
159
160
|
describeForeground(): Promise<string>;
|
|
160
|
-
assertAllowed(call: CallContext, win: WindowInfo | undefined, verb: string): Promise<
|
|
161
|
+
assertAllowed(call: CallContext, win: WindowInfo | undefined, verb: string): Promise<BrowserTab | undefined>;
|
|
162
|
+
private checkWebContent;
|
|
161
163
|
private checkPointer;
|
|
162
164
|
private checkKeyboard;
|
|
163
165
|
private sendKeys;
|
package/lib/types/coords.d.ts
CHANGED
|
@@ -36,4 +36,4 @@ export declare function toScreenshot(point: Point, display: Display, shot: Size)
|
|
|
36
36
|
/** Screenshot-space region [x1, y1, x2, y2] → physical rect clamped to the display. */
|
|
37
37
|
export declare function regionToPhysical(region: readonly number[], display: Display, shot: Size): Rect;
|
|
38
38
|
/** Is a physical point on this display? */
|
|
39
|
-
export declare function contains(display:
|
|
39
|
+
export declare function contains(display: Rect, point: Point): boolean;
|