@copylee/dsh-computer-use 0.1.2 → 0.1.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/lib/index.js CHANGED
@@ -635,10 +635,11 @@ var Computer = class Computer {
635
635
  await this.overlay.begin(call.agent, Computer.statusOf(input));
636
636
  const { action } = input;
637
637
  const s = this.settings();
638
- if (s.pauseOnUserInput && INPUT.has(action) && await this.overlay.waitForUserIdle(call.signal, s.userIdleMs)) {
638
+ const wasPaused = this.overlay.paused;
639
+ if (await this.overlay.yieldToUser(call.signal, s.pauseOnUserInput && INPUT.has(action)) && INPUT.has(action)) {
639
640
  await this.overlay.begin(call.agent, Computer.statusOf(input));
640
641
  return {
641
- text: `Not done: 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.`,
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.`,
642
643
  ...call.vision ? { image: await this.screenshot() } : {},
643
644
  skipped: true
644
645
  };
@@ -646,6 +647,7 @@ var Computer = class Computer {
646
647
  if (s.pauseOnUserInput && INPUT.has(action)) {
647
648
  const changed = await this.foregroundChanged();
648
649
  if (changed) {
650
+ await this.overlay.status("检测到窗口切换,重新查看屏幕");
649
651
  const image = call.vision ? await this.screenshot() : void 0;
650
652
  if (!image) this.seen = changed;
651
653
  return {
@@ -824,11 +826,14 @@ const REFERENCES = [
824
826
  "UIAutomationTypes.dll",
825
827
  "WindowsBase.dll"
826
828
  ];
827
- /** The helper source at the package root: one level up from lib/ or src/, two from lib/types/. */
828
- function helperSourcePath() {
829
- const candidates = ["../helper/CuHelper.cs", "../../helper/CuHelper.cs"].map((rel) => fileURLToPath(new URL(rel, import.meta.url)));
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)));
830
832
  return candidates.find((path) => existsSync(path)) ?? candidates[0];
831
833
  }
834
+ function helperSourcePath() {
835
+ return helperAssetPath("CuHelper.cs");
836
+ }
832
837
  function frameworkDir() {
833
838
  const windir = process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows";
834
839
  for (const arch of ["Framework64", "Framework"]) {
@@ -1024,57 +1029,80 @@ var HelperClient = class {
1024
1029
  //#endregion
1025
1030
  //#region lib/types/overlay.js
1026
1031
  /**
1027
- * The "AI is controlling your computer" indicator: an orange glow around
1028
- * every display plus a status pill with a stop button, both excluded from
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
1029
1034
  * screenshots. Shown on the first action of a run, hidden when that agent
1030
- * goes idle; a physical Esc or the stop button cancels the agent.
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.
1031
1038
  */
1032
1039
  /** Without a status change from the host, hide after this long without actions. */
1033
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
+ }
1034
1056
  var OverlayController = class {
1035
1057
  helper;
1036
1058
  settings;
1037
1059
  log;
1060
+ iconPath;
1038
1061
  agent;
1039
1062
  visible = false;
1040
1063
  idleTimer;
1041
- minimizedHost = [];
1064
+ hostWindows = [];
1042
1065
  stopping = false;
1043
- constructor(helper, settings, log) {
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 = "") {
1044
1071
  this.helper = helper;
1045
1072
  this.settings = settings;
1046
1073
  this.log = log;
1074
+ this.iconPath = iconPath;
1047
1075
  helper.onEvent((event) => {
1048
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;
1049
1079
  else if (event.event === "user_input") this.lastUserInput = Date.now();
1050
1080
  });
1051
1081
  }
1052
- /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
1053
- lastUserInput = 0;
1082
+ /** The agent currently driving the computer, if any. */
1083
+ get controller() {
1084
+ return this.agent;
1085
+ }
1054
1086
  /** Did the user type after `since`? */
1055
1087
  userTypedSince(since) {
1056
1088
  return this.lastUserInput > since;
1057
1089
  }
1058
1090
  /**
1059
- * If the user is typing, pause until the keyboard has been quiet for
1060
- * `idleMs`. Throws after `maxMs` so the model can tell the user. Returns
1061
- * whether it had to wait.
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.
1062
1093
  */
1063
- async waitForUserIdle(signal, idleMs, maxMs = 12e4) {
1064
- if (Date.now() - this.lastUserInput >= idleMs) return false;
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;
1065
1098
  const started = Date.now();
1066
- if (this.settings().overlay && this.visible) await this.helper.call("overlay_status", { status: "你正在操作,已暂停" }).catch(() => {});
1067
- while (Date.now() - this.lastUserInput < idleMs) {
1099
+ while (this.paused || typing()) {
1068
1100
  if (signal.aborted) throw new Error("Cancelled.");
1069
- if (Date.now() - started > maxMs) throw new Error("The user has been typing on the keyboard for a while, so computer use is paused. Ask the user whether to continue.");
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.");
1070
1102
  await new Promise((resolve) => setTimeout(resolve, 200));
1071
1103
  }
1072
1104
  return true;
1073
1105
  }
1074
- /** The agent currently driving the computer, if any. */
1075
- get controller() {
1076
- return this.agent;
1077
- }
1078
1106
  /** Called before every action: shows the overlay once and updates its status line. */
1079
1107
  async begin(agent, status) {
1080
1108
  if (agent) this.agent = agent;
@@ -1082,14 +1110,20 @@ var OverlayController = class {
1082
1110
  const settings = this.settings();
1083
1111
  if (!this.visible) {
1084
1112
  this.visible = true;
1085
- if (settings.minimizeHostWindow) await this.minimizeHost();
1113
+ this.paused = false;
1114
+ await this.shrinkHost(settings.hostWindow);
1086
1115
  if (settings.overlay) await this.helper.call("overlay_show", {
1087
- label: `${settings.overlayLabel || "DeepSeek"} 正在使用你的电脑`,
1088
- status
1116
+ label: `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
1117
+ status,
1118
+ icon: this.iconPath,
1119
+ idleMs: settings.userIdleMs
1089
1120
  }).catch((error) => this.log(`overlay: ${String(error)}`));
1090
1121
  return;
1091
1122
  }
1092
- if (settings.overlay) await this.helper.call("overlay_status", { status }).catch(() => {});
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(() => {});
1093
1127
  }
1094
1128
  /** Agent finished (idle), was cancelled, or the plugin is stopping. */
1095
1129
  async end(agent) {
@@ -1097,6 +1131,7 @@ var OverlayController = class {
1097
1131
  if (this.idleTimer) clearTimeout(this.idleTimer);
1098
1132
  this.idleTimer = void 0;
1099
1133
  this.agent = void 0;
1134
+ this.paused = false;
1100
1135
  if (!this.visible) return;
1101
1136
  this.visible = false;
1102
1137
  await this.helper.call("overlay_hide").catch(() => {});
@@ -1123,23 +1158,47 @@ var OverlayController = class {
1123
1158
  }, IDLE_HIDE_MS);
1124
1159
  this.idleTimer.unref();
1125
1160
  }
1126
- async minimizeHost() {
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;
1127
1164
  try {
1128
- const host = (await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized);
1129
- for (const row of host) await this.helper.call("window_cmd", {
1130
- hwnd: row.hwnd,
1131
- op: "minimize"
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)
1132
1187
  });
1133
- this.minimizedHost = host.map((row) => row.hwnd);
1188
+ this.hostWindows = [{
1189
+ hwnd: main.hwnd,
1190
+ mode: "card"
1191
+ }];
1134
1192
  } catch (error) {
1135
- this.log(`minimize host window: ${String(error)}`);
1193
+ this.log(`host window ${mode}: ${String(error)}`);
1136
1194
  }
1137
1195
  }
1138
1196
  async restoreHost() {
1139
- const handles = this.minimizedHost;
1140
- this.minimizedHost = [];
1141
- for (const hwnd of handles) await this.helper.call("window_cmd", {
1142
- hwnd,
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,
1143
1202
  op: "restore"
1144
1203
  }).catch(() => {});
1145
1204
  }
@@ -1150,13 +1209,127 @@ function promptText(mode) {
1150
1209
  return `# Computer use (Windows desktop)
1151
1210
  You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
1152
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.
1153
- - 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.
1154
- - 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.
1155
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.
1156
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.
1157
1216
  - If the user has a dedicated tool for a website or service (browser automation, an API tool), prefer it over driving the desktop.
1158
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.
1159
- - The user sees an orange border and can press Esc at any time to stop you. If they type on the keyboard you are paused; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
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.`;
1219
+ }
1220
+ //#endregion
1221
+ //#region lib/types/settings.js
1222
+ /** The Loader entry id (settings namespace); see cordis.patch.yml. */
1223
+ const ENTRY_ID = "copylee-computer-use";
1224
+ const DEFAULTS = {
1225
+ accessMode: "per-app",
1226
+ overlay: true,
1227
+ overlayLabel: "DeepSeek Harness",
1228
+ hostWindow: "card",
1229
+ autoScreenshot: true,
1230
+ settleMs: 400,
1231
+ maxLongEdge: 1366,
1232
+ maxPixels: 115e4,
1233
+ jpegQuality: 80,
1234
+ blockedApps: [],
1235
+ pauseOnUserInput: true,
1236
+ userIdleMs: 1500
1237
+ };
1238
+ /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
1239
+ function resolveConfig(raw) {
1240
+ const out = {};
1241
+ if (raw !== null && typeof raw === "object") for (const [key, value] of Object.entries(raw)) out[key] = value !== null && typeof value === "object" && typeof value.get === "function" ? value.get() : value;
1242
+ const num = (key, min, max) => {
1243
+ const value = out[key];
1244
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
1245
+ };
1246
+ const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
1247
+ return {
1248
+ accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
1249
+ overlay: bool("overlay"),
1250
+ overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
1251
+ hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
1252
+ autoScreenshot: bool("autoScreenshot"),
1253
+ settleMs: num("settleMs", 0, 5e3),
1254
+ maxLongEdge: num("maxLongEdge", 640, 3840),
1255
+ maxPixels: num("maxPixels", 3e5, 8e6),
1256
+ jpegQuality: num("jpegQuality", 30, 100),
1257
+ pauseOnUserInput: bool("pauseOnUserInput"),
1258
+ userIdleMs: num("userIdleMs", 300, 1e4),
1259
+ blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
1260
+ };
1261
+ }
1262
+ //#endregion
1263
+ //#region lib/types/routes.js
1264
+ const STATUS_ROUTE = "/api/dsh-computer-use/status";
1265
+ const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
1266
+ function json(res, status, body) {
1267
+ res.writeHead(status, {
1268
+ "content-type": "application/json; charset=utf-8",
1269
+ "cache-control": "no-store"
1270
+ });
1271
+ res.end(JSON.stringify(body));
1272
+ }
1273
+ function statusRoute(helper, settings, overlay) {
1274
+ return async (_req, res) => {
1275
+ const s = settings();
1276
+ try {
1277
+ const displays = await helper.call("displays", {}, 3e4);
1278
+ json(res, 200, {
1279
+ ok: true,
1280
+ platform: process.platform,
1281
+ helper: "ready",
1282
+ displays: displays.map((d) => ({
1283
+ ...d,
1284
+ shot: screenshotSize(d, {
1285
+ maxLongEdge: s.maxLongEdge,
1286
+ maxPixels: s.maxPixels
1287
+ })
1288
+ })),
1289
+ controlling: overlay.controller !== void 0
1290
+ });
1291
+ } catch (error) {
1292
+ json(res, 200, {
1293
+ ok: true,
1294
+ platform: process.platform,
1295
+ helper: "error",
1296
+ error: error instanceof Error ? error.message : String(error),
1297
+ displays: [],
1298
+ controlling: false
1299
+ });
1300
+ }
1301
+ };
1302
+ }
1303
+ /** Show the overlay for a few seconds so the user can see how it looks (skipped while an agent is controlling). */
1304
+ function previewRoute(helper, settings, overlay, iconPath) {
1305
+ return async (req, res) => {
1306
+ if (req.method !== "POST") {
1307
+ json(res, 405, {
1308
+ ok: false,
1309
+ error: "POST only"
1310
+ });
1311
+ return;
1312
+ }
1313
+ if (overlay.controller !== void 0) {
1314
+ json(res, 409, {
1315
+ ok: false,
1316
+ error: "busy"
1317
+ });
1318
+ return;
1319
+ }
1320
+ const s = settings();
1321
+ await helper.call("overlay_show", {
1322
+ label: `${s.overlayLabel} 正在操控你的电脑`,
1323
+ status: "预览 · 3 秒后消失",
1324
+ icon: iconPath,
1325
+ idleMs: s.userIdleMs,
1326
+ glow: s.overlay
1327
+ });
1328
+ setTimeout(() => {
1329
+ if (overlay.controller === void 0) helper.call("overlay_hide").catch(() => {});
1330
+ }, 3e3).unref();
1331
+ json(res, 200, { ok: true });
1332
+ };
1160
1333
  }
1161
1334
  //#endregion
1162
1335
  //#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
@@ -6897,7 +7070,7 @@ function createTools(host) {
6897
7070
  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.",
6898
7071
  parameters: actionProperties,
6899
7072
  output,
6900
- timeoutMs: 12e4,
7073
+ timeoutMs: 18e5,
6901
7074
  async execute(args, exec) {
6902
7075
  const call = await host.context(exec);
6903
7076
  const input = args;
@@ -6933,7 +7106,7 @@ function createTools(host) {
6933
7106
  }
6934
7107
  } },
6935
7108
  output,
6936
- timeoutMs: 3e5,
7109
+ timeoutMs: 18e5,
6937
7110
  async execute(args, exec) {
6938
7111
  const call = await host.context(exec);
6939
7112
  const actions = args.actions;
@@ -6984,7 +7157,7 @@ function createTools(host) {
6984
7157
  description: "App name as shown in the Start menu, an executable path, or an http(s) URL."
6985
7158
  } },
6986
7159
  output,
6987
- timeoutMs: 6e4,
7160
+ timeoutMs: 18e5,
6988
7161
  async execute(args, exec) {
6989
7162
  const call = await host.context(exec);
6990
7163
  const name = String(args.name ?? "").trim();
@@ -6996,6 +7169,7 @@ function createTools(host) {
6996
7169
  if (!running || !computer.access.isGranted(call.session, running)) throw new Error(`"${name}" is not granted for this session. Call request_access with ["${name}"] first.`);
6997
7170
  }
6998
7171
  await computer.overlay.begin(call.agent, `打开 ${name}`);
7172
+ await computer.overlay.yieldToUser(call.signal, false);
6999
7173
  const before = await computer.foreground();
7000
7174
  let how;
7001
7175
  const running = isUrl ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
@@ -7059,6 +7233,7 @@ function createTools(host) {
7059
7233
  const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
7060
7234
  if (denial && !(action === "minimize" && isHostWindow(target))) throw new Error(denial);
7061
7235
  await computer.overlay.begin(call.agent, `窗口 ${action}`);
7236
+ await computer.overlay.yieldToUser(call.signal, false);
7062
7237
  let text;
7063
7238
  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.`;
7064
7239
  else {
@@ -7211,20 +7386,6 @@ function createTools(host) {
7211
7386
  //#region lib/types/index.js
7212
7387
  const name = "@copylee/dsh-computer-use";
7213
7388
  const inject = ["tools", "attachments"];
7214
- const DEFAULTS = {
7215
- accessMode: "per-app",
7216
- overlay: true,
7217
- overlayLabel: "DeepSeek",
7218
- minimizeHostWindow: false,
7219
- autoScreenshot: true,
7220
- settleMs: 400,
7221
- maxLongEdge: 1366,
7222
- maxPixels: 115e4,
7223
- jpegQuality: 80,
7224
- blockedApps: [],
7225
- pauseOnUserInput: true,
7226
- userIdleMs: 1500
7227
- };
7228
7389
  const Config = z.object({
7229
7390
  accessMode: z.union([z.const("per-app").i18n({
7230
7391
  "zh-CN": { $description: "按应用授权(每个会话由你批准要操控的应用)" },
@@ -7240,13 +7401,26 @@ const Config = z.object({
7240
7401
  "zh-CN": { $description: "控制时显示橙色光晕边框和顶部提示条(不会出现在截图里,按 Esc 可停止)" },
7241
7402
  "en-US": { $description: "Show the orange glow and status pill while controlling (hidden from screenshots; Esc stops)" }
7242
7403
  }),
7243
- overlayLabel: z.string().default("DeepSeek").volatile().i18n({
7244
- "zh-CN": { $description: "提示条名称:“<名称> 正在使用你的电脑”" },
7245
- "en-US": { $description: "Name in the pill: \"<name> 正在使用你的电脑\"" }
7404
+ overlayLabel: z.string().default("DeepSeek Harness").volatile().i18n({
7405
+ "zh-CN": { $description: "提示条名称:“<名称> 正在操控你的电脑”" },
7406
+ "en-US": { $description: "Name in the pill: \"<name> 正在操控你的电脑\"" }
7246
7407
  }),
7247
- minimizeHostWindow: z.boolean().default(false).volatile().i18n({
7248
- "zh-CN": { $description: "控制期间最小化 DeepSeek Harness 窗口,结束后恢复" },
7249
- "en-US": { $description: "Minimize the DeepSeek Harness window while controlling; restore afterwards" }
7408
+ hostWindow: z.union([
7409
+ z.const("card").i18n({
7410
+ "zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
7411
+ "en-US": { $description: "Shrink to an always-on-top card" }
7412
+ }),
7413
+ z.const("minimize").i18n({
7414
+ "zh-CN": { $description: "最小化" },
7415
+ "en-US": { $description: "Minimize" }
7416
+ }),
7417
+ z.const("keep").i18n({
7418
+ "zh-CN": { $description: "保持不变" },
7419
+ "en-US": { $description: "Leave it as is" }
7420
+ })
7421
+ ]).default("card").volatile().i18n({
7422
+ "zh-CN": { $description: "操控期间 DeepSeek Harness 窗口怎么摆放(结束后自动恢复原尺寸和位置)" },
7423
+ "en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
7250
7424
  }),
7251
7425
  autoScreenshot: z.boolean().default(true).volatile().i18n({
7252
7426
  "zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
@@ -7281,30 +7455,6 @@ const Config = z.object({
7281
7455
  "en-US": { $description: "Apps that may never be controlled (names or exe). Common password managers are always blocked." }
7282
7456
  })
7283
7457
  });
7284
- /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
7285
- function resolveConfig(raw) {
7286
- const out = {};
7287
- if (raw !== null && typeof raw === "object") for (const [key, value] of Object.entries(raw)) out[key] = value !== null && typeof value === "object" && typeof value.get === "function" ? value.get() : value;
7288
- const num = (key, min, max) => {
7289
- const value = out[key];
7290
- return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
7291
- };
7292
- const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
7293
- return {
7294
- accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
7295
- overlay: bool("overlay"),
7296
- overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
7297
- minimizeHostWindow: bool("minimizeHostWindow"),
7298
- autoScreenshot: bool("autoScreenshot"),
7299
- settleMs: num("settleMs", 0, 5e3),
7300
- maxLongEdge: num("maxLongEdge", 640, 3840),
7301
- maxPixels: num("maxPixels", 3e5, 8e6),
7302
- jpegQuality: num("jpegQuality", 30, 100),
7303
- pauseOnUserInput: bool("pauseOnUserInput"),
7304
- userIdleMs: num("userIdleMs", 300, 1e4),
7305
- blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
7306
- };
7307
- }
7308
7458
  function apply(ctx, config = {}) {
7309
7459
  if (process.platform !== "win32") {
7310
7460
  ctx.logger.warn("dsh-computer-use only supports Windows; no tools registered.");
@@ -7314,7 +7464,8 @@ function apply(ctx, config = {}) {
7314
7464
  const log = (message) => ctx.logger.info(message);
7315
7465
  const helper = new HelperClient((message) => ctx.logger.warn(message));
7316
7466
  const access = new AccessControl();
7317
- const overlay = new OverlayController(helper, settings, log);
7467
+ const iconPath = helperAssetPath("deepseek-white.png");
7468
+ const overlay = new OverlayController(helper, settings, log, iconPath);
7318
7469
  const computer = new Computer(helper, access, overlay, settings);
7319
7470
  ctx.effect(() => () => {
7320
7471
  overlay.end().finally(() => helper.dispose());
@@ -7382,6 +7533,35 @@ function apply(ctx, config = {}) {
7382
7533
  access.forget(agent.session.id);
7383
7534
  if (overlay.controller === agent) overlay.end();
7384
7535
  });
7536
+ ctx.inject(["webServer"], (webCtx) => {
7537
+ const route = (path, handler) => {
7538
+ const safe = async (req, res) => {
7539
+ try {
7540
+ await handler(req, res);
7541
+ } catch (error) {
7542
+ if (res.headersSent) {
7543
+ res.destroy();
7544
+ return;
7545
+ }
7546
+ res.writeHead(500, {
7547
+ "content-type": "application/json",
7548
+ "cache-control": "no-store"
7549
+ });
7550
+ res.end(JSON.stringify({
7551
+ ok: false,
7552
+ error: error instanceof Error ? error.message : String(error)
7553
+ }));
7554
+ }
7555
+ };
7556
+ webCtx.effect(() => webCtx.webServer.register({
7557
+ kind: "exact",
7558
+ path,
7559
+ handler: safe
7560
+ }), `computer-use: ${path}`);
7561
+ };
7562
+ route(STATUS_ROUTE, statusRoute(helper, settings, overlay));
7563
+ route(PREVIEW_ROUTE, previewRoute(helper, settings, overlay, iconPath));
7564
+ });
7385
7565
  ctx.inject(["systemPrompt"], (promptCtx) => {
7386
7566
  let registered;
7387
7567
  let dispose;
@@ -7408,4 +7588,4 @@ function apply(ctx, config = {}) {
7408
7588
  });
7409
7589
  }
7410
7590
  //#endregion
7411
- export { Config, apply, inject, name, resolveConfig };
7591
+ export { Config, DEFAULTS, ENTRY_ID, apply, inject, name, resolveConfig };
@@ -0,0 +1,39 @@
1
+ type RemoteResult<T> = {
2
+ ok: true;
3
+ value: T;
4
+ } | {
5
+ ok: false;
6
+ error: {
7
+ code?: string;
8
+ message: string;
9
+ };
10
+ };
11
+ interface NamespaceView {
12
+ ns: string;
13
+ value: unknown;
14
+ revision: number;
15
+ }
16
+ interface ClientContext {
17
+ effect(execute: () => (() => void) | void, label?: string): void;
18
+ slots: {
19
+ inject(name: string, register: () => unknown): void;
20
+ register(meta: Record<string, unknown>, render: (props: unknown) => unknown): unknown;
21
+ };
22
+ remote: {
23
+ $on?(event: string, listener: (...args: unknown[]) => void): () => void;
24
+ settings: {
25
+ describe(): Promise<RemoteResult<{
26
+ writable: boolean;
27
+ namespaces: NamespaceView[];
28
+ }>>;
29
+ mutate(ns: string, ops: {
30
+ op: 'set' | 'unset';
31
+ path: string[];
32
+ value?: unknown;
33
+ }[], expectedRevision?: number): Promise<RemoteResult<unknown>>;
34
+ };
35
+ };
36
+ }
37
+ export declare const inject: string[];
38
+ export declare function apply(ctx: ClientContext): void;
39
+ export {};
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
3
+ export declare const selectCss = "\n.dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer}\n.dshcu-select:hover{border-color:var(--dsw-alias-border-l3,#888)}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:2px solid var(--dsw-alias-state-business-primary,#2f7cff);outline-offset:2px}\n.dshcu-select:disabled{opacity:.5;cursor:default}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:4px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 10px 32px rgba(0,0,0,.16),0 0 0 .5px rgba(0,0,0,.1))}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 8px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}\n";
4
+ export declare function Select<V extends string>({ options, value, disabled, label, onChange }: {
5
+ options: {
6
+ value: V;
7
+ label: string;
8
+ }[];
9
+ value: V;
10
+ disabled?: boolean;
11
+ label: string;
12
+ onChange(value: V): void;
13
+ }): React.DetailedReactHTMLElement<{
14
+ style: {
15
+ minWidth: number;
16
+ };
17
+ }, HTMLElement>;
@@ -1,13 +1,13 @@
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
- minimizeHostWindow: boolean;
10
+ hostWindow: HostWindowMode;
11
11
  maxLongEdge: number;
12
12
  maxPixels: number;
13
13
  jpegQuality: number;
@@ -7,7 +7,8 @@ export interface HelperLike {
7
7
  onEvent(listener: (event: HelperEvent) => void): () => void;
8
8
  dispose(): void;
9
9
  }
10
- /** The helper source at the package root: one level up from lib/ or src/, two from lib/types/. */
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>;
@@ -7,13 +7,16 @@
7
7
  import type { Context } from '@deepseek-ai/cordis';
8
8
  import z from '@deepseek-ai/schemastery';
9
9
  import { type AccessMode } from './access.js';
10
- import { type Settings } from './computer.js';
10
+ import { type HostWindowMode } from './overlay.js';
11
+ export { DEFAULTS, ENTRY_ID, resolveConfig } from './settings.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;
@@ -25,6 +28,4 @@ export interface Config {
25
28
  userIdleMs?: number;
26
29
  }
27
30
  export declare const Config: z<Config>;
28
- /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
29
- export declare function resolveConfig(raw: unknown): Settings;
30
31
  export declare function apply(ctx: Context, config?: Config): void;