@copylee/dsh-computer-use 0.8.7 → 0.8.8

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.
@@ -279,7 +279,12 @@ namespace DshComputerUse
279
279
  case "settle": return Screen2.Settle(r);
280
280
  case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
281
281
  case "move": using (new PassThrough()) { Overlay.Dodge(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); Input.Move(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); } return null;
282
- case "click": using (new PassThrough()) return Input.Click(r);
282
+ case "click":
283
+ Native.POINT clickPoint;
284
+ if (Args.Has(r, "x")) clickPoint = new Native.POINT(Args.Int(r, "x", 0), Args.Int(r, "y", 0));
285
+ else if (!Native.GetCursorPos(out clickPoint)) throw new Exception("Cannot read cursor position");
286
+ using (CardLayer.UncoverClick(clickPoint))
287
+ using (new PassThrough()) return Input.Click(r);
283
288
  case "button": using (new PassThrough()) return Input.Button(r);
284
289
  case "drag": using (new PassThrough()) return Input.Drag(r);
285
290
  case "scroll": using (new PassThrough()) return Input.Scroll(r);
@@ -1007,6 +1012,57 @@ namespace DshComputerUse
1007
1012
  return new Hidden(r.IntersectsWith(area) ? Hwnd : IntPtr.Zero);
1008
1013
  }
1009
1014
 
1015
+ // Chromium cards can swallow SendInput even after WS_EX_TRANSPARENT has
1016
+ // changed the hit test. Hide the card through dispatch only when it covers
1017
+ // the click, keeping its position, z-order and the work window's focus.
1018
+ public static IDisposable UncoverClick(Native.POINT point)
1019
+ {
1020
+ var hwnd = Hwnd;
1021
+ if (!Live()) return null;
1022
+ Native.RECT rect;
1023
+ if (!Native.GetWindowRect(hwnd, out rect)) throw new Exception("Cannot verify the control card bounds");
1024
+ if (point.X < rect.Left || point.X >= rect.Right || point.Y < rect.Top || point.Y >= rect.Bottom) return null;
1025
+ if (Native.GetForegroundWindow() == hwnd) throw new Exception("The control card is focused. Focus the work window before clicking.");
1026
+ object expected;
1027
+ if (!Windows.At(point.X, point.Y).TryGetValue("hwnd", out expected))
1028
+ throw new Exception("No work window found under the control card");
1029
+ var uncovered = new Uncovered(hwnd);
1030
+ try
1031
+ {
1032
+ object hit;
1033
+ if (!Windows.At(point.X, point.Y).TryGetValue("hwnd", out hit) || !Object.Equals(expected, hit))
1034
+ throw new Exception("The window under the control card changed. Look again before clicking.");
1035
+ return uncovered;
1036
+ }
1037
+ catch
1038
+ {
1039
+ uncovered.Dispose();
1040
+ throw;
1041
+ }
1042
+ }
1043
+
1044
+ sealed class Uncovered : IDisposable
1045
+ {
1046
+ // NOSIZE | NOMOVE | NOZORDER | NOACTIVATE | NOOWNERZORDER.
1047
+ const uint PreservePlacement = 0x0217;
1048
+ readonly IntPtr hwnd;
1049
+
1050
+ public Uncovered(IntPtr hwnd)
1051
+ {
1052
+ this.hwnd = hwnd;
1053
+ if (!Native.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, PreservePlacement | 0x0080)
1054
+ || Native.IsWindowVisible(hwnd))
1055
+ throw new Exception("Cannot hide the control card for the click");
1056
+ }
1057
+
1058
+ public void Dispose()
1059
+ {
1060
+ if (Hwnd == hwnd && Native.IsWindow(hwnd)
1061
+ && !Native.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, PreservePlacement | 0x0040))
1062
+ Native.ShowWindow(hwnd, 4); // SW_SHOWNOACTIVATE
1063
+ }
1064
+ }
1065
+
1010
1066
  sealed class Hidden : IDisposable
1011
1067
  {
1012
1068
  readonly IntPtr hwnd;
@@ -1900,8 +1956,12 @@ namespace DshComputerUse
1900
1956
  if (String.Join(",", el.GetRuntimeId()) == runtimeId) { target = el; break; }
1901
1957
  if (el.Current.ControlType == ControlType.Window) break;
1902
1958
  }
1903
- if (target == null || target.Current.IsOffscreen || !target.Current.IsEnabled)
1904
- throw new Exception("The named target changed or is no longer actionable");
1959
+ // Some providers stop the hit test at a host pane. The caller can
1960
+ // re-resolve the control and verify its window before a pointer click.
1961
+ if (target == null) return result;
1962
+ if (target.Current.IsOffscreen) throw new Exception("The named target is offscreen");
1963
+ if (!target.Current.IsEnabled)
1964
+ throw new Exception("The named target is disabled");
1905
1965
  object pattern = null;
1906
1966
  if (action == "invoke" && !target.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) return result;
1907
1967
  if (action == "focus" && !target.Current.IsKeyboardFocusable) return result;
package/lib/index.js CHANGED
@@ -9102,7 +9102,7 @@ function createTools(host) {
9102
9102
  }));
9103
9103
  tools.push(defineTool({
9104
9104
  name: "open_application",
9105
- description: "Open an app by name (e.g. \"Chrome\", \"记事本\", \"微信\", \"Excel\"), an .exe path, or a URL, or bring it to the front if it is already running. Faster and more reliable than clicking the taskbar or Start menu. Returns a screenshot.",
9105
+ description: "Open an app by name (e.g. \"Chrome\", \"记事本\", \"微信\", \"Excel\"), an .exe path, or a URL, or bring it to the front if it is already running. Faster and more reliable than clicking the taskbar or Start menu. Includes a screenshot when automatic screenshots are enabled and the model supports images.",
9106
9106
  parameters: {
9107
9107
  name: {
9108
9108
  type: "string",
@@ -9119,8 +9119,9 @@ function createTools(host) {
9119
9119
  async execute(args, exec) {
9120
9120
  const call = await host.context(exec);
9121
9121
  const text = await openApp(String(args.name ?? ""), args.new_instance === true, call);
9122
+ if (!call.vision || !computer.settings().autoScreenshot) return { text };
9122
9123
  await computer.settle(call.signal);
9123
- return withShot(host, text, call.vision ? await computer.screenshot() : void 0, call);
9124
+ return withShot(host, text, await computer.screenshot(), call);
9124
9125
  },
9125
9126
  presentCall: (args) => card(`打开应用 · ${args.name ?? ""}`)
9126
9127
  }));
@@ -9411,7 +9412,7 @@ function createTools(host) {
9411
9412
  if (index !== void 0) await computer.selectDisplay(index);
9412
9413
  const list = (await computer.refreshDisplays()).map((d, i) => `${i}: ${d.width}x${d.height} at (${d.x}, ${d.y}), ${Math.round(d.dpi / 96 * 100)}% scale${d.primary ? ", primary" : ""}${i === computer.currentIndex ? " ← current" : ""}`).join("\n");
9413
9414
  if (index === void 0) return { text: list };
9414
- const shot = call.vision ? await computer.screenshot() : void 0;
9415
+ const shot = call.vision && computer.settings().autoScreenshot ? await computer.screenshot() : void 0;
9415
9416
  return withShot(host, `Switched to display ${index}.\n${list}`, shot, call);
9416
9417
  },
9417
9418
  presentCall: () => card("切换显示器")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",