@copylee/dsh-computer-use 0.1.7 → 0.1.9
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 +1 -1
- package/helper/CuHelper.cs +177 -41
- package/lib/client.js +10 -4
- package/lib/index.js +41 -67
- package/lib/types/access.d.ts +7 -0
- package/lib/types/computer.d.ts +0 -1
- package/lib/types/overlay.d.ts +0 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
| 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
|
|
13
13
|
| 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
|
|
14
14
|
| 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
|
|
15
|
-
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 /
|
|
15
|
+
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(每次截图时卡片会透明约 20 毫秒,每个动作只截一次),点击和滚动也直接穿透卡片,卡片不会挪位置 |
|
|
16
16
|
| 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
|
|
17
17
|
| 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
|
|
18
18
|
| 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
|
package/helper/CuHelper.cs
CHANGED
|
@@ -79,6 +79,8 @@ namespace DshComputerUse
|
|
|
79
79
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetClassName(IntPtr hwnd, StringBuilder sb, int max);
|
|
80
80
|
[DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hwnd, uint cmd);
|
|
81
81
|
[DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hwnd, int index);
|
|
82
|
+
[DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hwnd, int index, int value);
|
|
83
|
+
[DllImport("user32.dll")] public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint key, byte alpha, uint flags);
|
|
82
84
|
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);
|
|
83
85
|
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
84
86
|
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd);
|
|
@@ -134,6 +136,11 @@ namespace DshComputerUse
|
|
|
134
136
|
object v; if (!d.TryGetValue(k, out v) || v == null) return def;
|
|
135
137
|
return (int)Math.Round(Convert.ToDouble(v));
|
|
136
138
|
}
|
|
139
|
+
public static double Double(Dictionary<string, object> d, string k, double def)
|
|
140
|
+
{
|
|
141
|
+
object v;
|
|
142
|
+
return d.TryGetValue(k, out v) && v != null ? Convert.ToDouble(v, System.Globalization.CultureInfo.InvariantCulture) : def;
|
|
143
|
+
}
|
|
137
144
|
public static string Str(Dictionary<string, object> d, string k, string def)
|
|
138
145
|
{
|
|
139
146
|
object v; if (!d.TryGetValue(k, out v) || v == null) return def;
|
|
@@ -251,14 +258,12 @@ namespace DshComputerUse
|
|
|
251
258
|
case "displays": return Screen2.Displays();
|
|
252
259
|
case "screenshot": return Screen2.Capture(r);
|
|
253
260
|
case "settle": return Screen2.Settle(r);
|
|
254
|
-
case "shot_mark": Screen2.Mark(r); return null;
|
|
255
|
-
case "shot_diff": return Screen2.Diff(r);
|
|
256
261
|
case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
|
|
257
|
-
case "move": 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;
|
|
258
|
-
case "click": return Input.Click(r);
|
|
259
|
-
case "button": return Input.Button(r);
|
|
260
|
-
case "drag": return Input.Drag(r);
|
|
261
|
-
case "scroll": return Input.Scroll(r);
|
|
262
|
+
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;
|
|
263
|
+
case "click": using (new PassThrough()) return Input.Click(r);
|
|
264
|
+
case "button": using (new PassThrough()) return Input.Button(r);
|
|
265
|
+
case "drag": using (new PassThrough()) return Input.Drag(r);
|
|
266
|
+
case "scroll": using (new PassThrough()) return Input.Scroll(r);
|
|
262
267
|
case "keys": return Input.Keys(r);
|
|
263
268
|
case "key_state": return Input.KeyState(r);
|
|
264
269
|
case "type": return Input.Type(Args.Str(r, "text", ""), Args.Int(r, "chunkDelay", 8));
|
|
@@ -316,6 +321,7 @@ namespace DshComputerUse
|
|
|
316
321
|
}
|
|
317
322
|
|
|
318
323
|
/** Sample every 8th pixel of a screen rectangle (BGR bytes). */
|
|
324
|
+
/** Sample the screen for settle detection; the card area is blanked (no flicker). */
|
|
319
325
|
static byte[] Sample(int x, int y, int w, int h)
|
|
320
326
|
{
|
|
321
327
|
using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
|
|
@@ -326,47 +332,39 @@ namespace DshComputerUse
|
|
|
326
332
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
327
333
|
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
328
334
|
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
335
|
+
CardLayer.Blank(g, x, y);
|
|
329
336
|
}
|
|
330
|
-
|
|
331
|
-
|
|
337
|
+
return SampleBitmap(bmp);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Every 8th pixel of a 24-bit bitmap (BGR bytes). */
|
|
342
|
+
static byte[] SampleBitmap(Bitmap bmp)
|
|
343
|
+
{
|
|
344
|
+
int w = bmp.Width, h = bmp.Height;
|
|
345
|
+
var data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
|
|
346
|
+
try
|
|
347
|
+
{
|
|
348
|
+
int sx = (w + 7) / 8, sy = (h + 7) / 8;
|
|
349
|
+
var row = new byte[data.Stride];
|
|
350
|
+
var outp = new byte[sx * sy * 3];
|
|
351
|
+
int k = 0;
|
|
352
|
+
for (int j = 0; j < sy; j++)
|
|
332
353
|
{
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
var outp = new byte[sx * sy * 3];
|
|
336
|
-
int k = 0;
|
|
337
|
-
for (int j = 0; j < sy; j++)
|
|
338
|
-
{
|
|
339
|
-
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + (long)j * 8 * data.Stride), row, 0, data.Stride);
|
|
340
|
-
for (int i = 0; i < sx; i++) { int o = i * 8 * 3; outp[k++] = row[o]; outp[k++] = row[o + 1]; outp[k++] = row[o + 2]; }
|
|
341
|
-
}
|
|
342
|
-
return outp;
|
|
354
|
+
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + (long)j * 8 * data.Stride), row, 0, data.Stride);
|
|
355
|
+
for (int i = 0; i < sx; i++) { int o = i * 8 * 3; outp[k++] = row[o]; outp[k++] = row[o + 1]; outp[k++] = row[o + 2]; }
|
|
343
356
|
}
|
|
344
|
-
|
|
357
|
+
return outp;
|
|
345
358
|
}
|
|
359
|
+
finally { bmp.UnlockBits(data); }
|
|
346
360
|
}
|
|
347
361
|
|
|
362
|
+
/** What the screen looked like in the last screenshot the model was shown. */
|
|
348
363
|
static byte[] marked;
|
|
349
364
|
static string markedRect;
|
|
350
365
|
|
|
351
366
|
static string RectKey(int x, int y, int w, int h) { return x + "," + y + "," + w + "," + h; }
|
|
352
367
|
|
|
353
|
-
/** Remember what the screen looked like when the model was last shown it. */
|
|
354
|
-
public static void Mark(Dictionary<string, object> r)
|
|
355
|
-
{
|
|
356
|
-
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
357
|
-
marked = Sample(x, y, w, h);
|
|
358
|
-
markedRect = RectKey(x, y, w, h);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/** Fraction of sampled pixels changed since Mark (-1 when there is nothing comparable). */
|
|
362
|
-
public static Dictionary<string, object> Diff(Dictionary<string, object> r)
|
|
363
|
-
{
|
|
364
|
-
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
365
|
-
var d = new Dictionary<string, object>();
|
|
366
|
-
d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h));
|
|
367
|
-
return d;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
368
|
static double Changed(byte[] a, byte[] b)
|
|
371
369
|
{
|
|
372
370
|
int n = a.Length / 3, diff = 0;
|
|
@@ -420,8 +418,28 @@ namespace DshComputerUse
|
|
|
420
418
|
{
|
|
421
419
|
IntPtr dst = g.GetHdc();
|
|
422
420
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
423
|
-
|
|
424
|
-
|
|
421
|
+
// The DSH card is for the user only: capture what is under it
|
|
422
|
+
// (it blinks out for the duration of this one BitBlt).
|
|
423
|
+
using (CardLayer.Hide(new Rectangle(x, y, w, h)))
|
|
424
|
+
{
|
|
425
|
+
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
426
|
+
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// compare: report "unchanged" instead of an identical image; mark: remember for next time.
|
|
430
|
+
bool compare = Args.Bool(r, "compare", false), mark = Args.Bool(r, "mark", false) || compare;
|
|
431
|
+
if (mark)
|
|
432
|
+
{
|
|
433
|
+
string key = RectKey(x, y, w, h);
|
|
434
|
+
byte[] sample = SampleBitmap(bmp);
|
|
435
|
+
if (compare && marked != null && markedRect == key && Changed(marked, sample) < Args.Double(r, "threshold", 0.0005))
|
|
436
|
+
{
|
|
437
|
+
var same = new Dictionary<string, object>();
|
|
438
|
+
same["unchanged"] = true;
|
|
439
|
+
return same;
|
|
440
|
+
}
|
|
441
|
+
marked = sample;
|
|
442
|
+
markedRect = key;
|
|
425
443
|
}
|
|
426
444
|
Bitmap output = bmp;
|
|
427
445
|
Bitmap scaled = null;
|
|
@@ -770,6 +788,111 @@ namespace DshComputerUse
|
|
|
770
788
|
}
|
|
771
789
|
}
|
|
772
790
|
|
|
791
|
+
/**
|
|
792
|
+
* The DeepSeek Harness card floats on top for the user only. To the agent
|
|
793
|
+
* it is transparent: while a screenshot is taken the card is made fully
|
|
794
|
+
* transparent for a few milliseconds (another process's window cannot be
|
|
795
|
+
* excluded from capture), and its pointer input passes through.
|
|
796
|
+
*/
|
|
797
|
+
internal static class CardLayer
|
|
798
|
+
{
|
|
799
|
+
public static IntPtr Hwnd = IntPtr.Zero;
|
|
800
|
+
static int originalEx;
|
|
801
|
+
|
|
802
|
+
static bool Live()
|
|
803
|
+
{
|
|
804
|
+
return Hwnd != IntPtr.Zero && Native.IsWindow(Hwnd) && Native.IsWindowVisible(Hwnd) && !Native.IsIconic(Hwnd);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
public static uint Pid()
|
|
808
|
+
{
|
|
809
|
+
if (!Live()) return 0;
|
|
810
|
+
uint pid; Native.GetWindowThreadProcessId(Hwnd, out pid);
|
|
811
|
+
return pid;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/** The card becomes a (fully opaque) layered window so its alpha can be dropped instantly. */
|
|
815
|
+
public static void Attach(IntPtr hwnd)
|
|
816
|
+
{
|
|
817
|
+
if (Hwnd == hwnd) return;
|
|
818
|
+
Detach();
|
|
819
|
+
Hwnd = hwnd;
|
|
820
|
+
originalEx = Native.GetWindowLong(hwnd, -20);
|
|
821
|
+
Native.SetWindowLong(hwnd, -20, originalEx | 0x80000);
|
|
822
|
+
Native.SetLayeredWindowAttributes(hwnd, 0, 255, 2);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
public static void Detach()
|
|
826
|
+
{
|
|
827
|
+
var hwnd = Hwnd;
|
|
828
|
+
Hwnd = IntPtr.Zero;
|
|
829
|
+
if (hwnd != IntPtr.Zero && Native.IsWindow(hwnd)) Native.SetWindowLong(hwnd, -20, originalEx);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
public static Rectangle Frame(IntPtr hwnd)
|
|
833
|
+
{
|
|
834
|
+
Native.RECT rc;
|
|
835
|
+
if (Native.DwmGetWindowAttribute(hwnd, 9, out rc, Marshal.SizeOf(typeof(Native.RECT))) != 0) Native.GetWindowRect(hwnd, out rc);
|
|
836
|
+
return new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** g draws a bitmap whose (0, 0) is screen (ox, oy): fill the card area with a constant. */
|
|
840
|
+
public static void Blank(Graphics g, int ox, int oy)
|
|
841
|
+
{
|
|
842
|
+
if (!Live()) return;
|
|
843
|
+
var r = Frame(Hwnd);
|
|
844
|
+
r.Inflate(32, 32); // its drop shadow too (wide at 200% scaling)
|
|
845
|
+
g.FillRectangle(Brushes.Black, r.X - ox, r.Y - oy, r.Width, r.Height);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/** Make the card invisible while a capture of `area` runs (dispose to show it again). */
|
|
849
|
+
public static IDisposable Hide(Rectangle area)
|
|
850
|
+
{
|
|
851
|
+
if (!Live()) return new Hidden(IntPtr.Zero);
|
|
852
|
+
var r = Frame(Hwnd);
|
|
853
|
+
r.Inflate(32, 32);
|
|
854
|
+
return new Hidden(r.IntersectsWith(area) ? Hwnd : IntPtr.Zero);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
sealed class Hidden : IDisposable
|
|
858
|
+
{
|
|
859
|
+
readonly IntPtr hwnd;
|
|
860
|
+
public Hidden(IntPtr hwnd)
|
|
861
|
+
{
|
|
862
|
+
this.hwnd = hwnd;
|
|
863
|
+
if (hwnd != IntPtr.Zero) Native.SetLayeredWindowAttributes(hwnd, 0, 0, 2);
|
|
864
|
+
}
|
|
865
|
+
public void Dispose()
|
|
866
|
+
{
|
|
867
|
+
if (hwnd != IntPtr.Zero && Native.IsWindow(hwnd)) Native.SetLayeredWindowAttributes(hwnd, 0, 255, 2);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** While the agent moves, clicks or scrolls, the card lets the mouse through. */
|
|
873
|
+
internal sealed class PassThrough : IDisposable
|
|
874
|
+
{
|
|
875
|
+
readonly IntPtr hwnd;
|
|
876
|
+
readonly int oldEx;
|
|
877
|
+
readonly bool active;
|
|
878
|
+
|
|
879
|
+
public PassThrough()
|
|
880
|
+
{
|
|
881
|
+
hwnd = CardLayer.Hwnd;
|
|
882
|
+
if (hwnd == IntPtr.Zero || !Native.IsWindow(hwnd)) return;
|
|
883
|
+
oldEx = Native.GetWindowLong(hwnd, -20);
|
|
884
|
+
Native.SetWindowLong(hwnd, -20, oldEx | 0x20 | 0x80000); // WS_EX_TRANSPARENT (layered already)
|
|
885
|
+
active = true;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
public void Dispose()
|
|
889
|
+
{
|
|
890
|
+
if (!active) return;
|
|
891
|
+
Thread.Sleep(60); // let the injected input reach its target first
|
|
892
|
+
if (Native.IsWindow(hwnd)) Native.SetWindowLong(hwnd, -20, oldEx);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
773
896
|
internal static class Windows
|
|
774
897
|
{
|
|
775
898
|
public static string ExePath(uint pid)
|
|
@@ -838,7 +961,8 @@ namespace DshComputerUse
|
|
|
838
961
|
if (h != IntPtr.Zero) h = Native.GetAncestor(h, 2); // GA_ROOT
|
|
839
962
|
uint pid = 0;
|
|
840
963
|
if (h != IntPtr.Zero) Native.GetWindowThreadProcessId(h, out pid);
|
|
841
|
-
|
|
964
|
+
uint cardPid = CardLayer.Pid();
|
|
965
|
+
if (h == IntPtr.Zero || pid == (uint)Process.GetCurrentProcess().Id || (cardPid != 0 && pid == cardPid))
|
|
842
966
|
{
|
|
843
967
|
// Our own status pill is under the point (it dodges before the
|
|
844
968
|
// click): report the topmost foreign window there instead.
|
|
@@ -848,8 +972,9 @@ namespace DshComputerUse
|
|
|
848
972
|
{
|
|
849
973
|
if (!Native.IsWindowVisible(w)) return true;
|
|
850
974
|
uint p; Native.GetWindowThreadProcessId(w, out p);
|
|
851
|
-
if (p == self) return true;
|
|
975
|
+
if (p == self || (cardPid != 0 && p == cardPid)) return true; // our overlay, the DSH card
|
|
852
976
|
if ((Native.GetWindowLong(w, -20) & 0x20) != 0) return true; // WS_EX_TRANSPARENT
|
|
977
|
+
if (Native.IsIconic(w)) return true;
|
|
853
978
|
int cloaked;
|
|
854
979
|
if (Native.DwmGetWindowAttribute(w, 14, out cloaked, 4) == 0 && cloaked != 0) return true;
|
|
855
980
|
Native.RECT rc; Native.GetWindowRect(w, out rc);
|
|
@@ -901,6 +1026,15 @@ namespace DshComputerUse
|
|
|
901
1026
|
Native.SendInput(3, inputs, Marshal.SizeOf(typeof(Native.INPUT)));
|
|
902
1027
|
Thread.Sleep(120);
|
|
903
1028
|
}
|
|
1029
|
+
if (Native.GetForegroundWindow() != hwnd)
|
|
1030
|
+
{
|
|
1031
|
+
// Last resort: restoring a minimized window always activates it.
|
|
1032
|
+
bool zoomed = Native.IsZoomed(hwnd);
|
|
1033
|
+
Native.ShowWindow(hwnd, 6); // SW_MINIMIZE
|
|
1034
|
+
Thread.Sleep(150);
|
|
1035
|
+
Native.ShowWindow(hwnd, zoomed ? 3 : 9); // SW_MAXIMIZE / SW_RESTORE
|
|
1036
|
+
Thread.Sleep(200);
|
|
1037
|
+
}
|
|
904
1038
|
}
|
|
905
1039
|
var d = Describe(hwnd);
|
|
906
1040
|
d["focused"] = Native.GetForegroundWindow() == hwnd;
|
|
@@ -913,6 +1047,7 @@ namespace DshComputerUse
|
|
|
913
1047
|
public static object Card(IntPtr hwnd, int x, int y, int w, int h)
|
|
914
1048
|
{
|
|
915
1049
|
if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
|
|
1050
|
+
CardLayer.Attach(hwnd);
|
|
916
1051
|
if (!cards.ContainsKey(hwnd.ToInt64()))
|
|
917
1052
|
{
|
|
918
1053
|
var wp = new Native.WINDOWPLACEMENT();
|
|
@@ -935,6 +1070,7 @@ namespace DshComputerUse
|
|
|
935
1070
|
|
|
936
1071
|
public static object Uncard(IntPtr hwnd)
|
|
937
1072
|
{
|
|
1073
|
+
if (CardLayer.Hwnd == hwnd) CardLayer.Detach();
|
|
938
1074
|
Native.WINDOWPLACEMENT wp;
|
|
939
1075
|
bool known = cards.TryGetValue(hwnd.ToInt64(), out wp);
|
|
940
1076
|
cards.Remove(hwnd.ToInt64());
|
package/lib/client.js
CHANGED
|
@@ -101,23 +101,29 @@ window.__ModuleLoader__.load({
|
|
|
101
101
|
style.textContent = navIconCss;
|
|
102
102
|
document.head.appendChild(style);
|
|
103
103
|
let disposed = false;
|
|
104
|
+
let frame = 0;
|
|
104
105
|
const sync = () => {
|
|
106
|
+
frame = 0;
|
|
105
107
|
if (disposed) return;
|
|
106
|
-
|
|
108
|
+
const dialogs = document.querySelectorAll("[role=\"dialog\"]");
|
|
109
|
+
if (dialogs.length === 0) return;
|
|
110
|
+
for (const dialog of dialogs) for (const button of dialog.querySelectorAll("nav button")) {
|
|
107
111
|
const mine = button.textContent?.trim() === label;
|
|
108
112
|
if (mine && !button.hasAttribute(MARKER)) button.setAttribute(MARKER, "");
|
|
109
113
|
else if (!mine && button.hasAttribute(MARKER)) button.removeAttribute(MARKER);
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
116
|
sync();
|
|
113
|
-
const observer = new MutationObserver(
|
|
117
|
+
const observer = new MutationObserver(() => {
|
|
118
|
+
if (frame === 0) frame = requestAnimationFrame(sync);
|
|
119
|
+
});
|
|
114
120
|
observer.observe(document.body, {
|
|
115
121
|
childList: true,
|
|
116
|
-
subtree: true
|
|
117
|
-
characterData: true
|
|
122
|
+
subtree: true
|
|
118
123
|
});
|
|
119
124
|
return () => {
|
|
120
125
|
disposed = true;
|
|
126
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
121
127
|
observer.disconnect();
|
|
122
128
|
style.remove();
|
|
123
129
|
document.querySelectorAll(`[${MARKER}]`).forEach((element) => element.removeAttribute(MARKER));
|
package/lib/index.js
CHANGED
|
@@ -118,6 +118,15 @@ function sameApp(a, b) {
|
|
|
118
118
|
for (const exe of exeNames(b)) if (x.has(exe)) return true;
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Windows shell surfaces that grab the foreground without being a place to
|
|
123
|
+
* work: the touch-keyboard / IME host and Snap Assist.
|
|
124
|
+
*/
|
|
125
|
+
function isTransientShell(win) {
|
|
126
|
+
const exe = win.exe.toLowerCase();
|
|
127
|
+
if (exe === "textinputhost.exe") return true;
|
|
128
|
+
return exe === "explorer.exe" && (win.className === "XamlExplorerHostIslandWindow" || /贴靠助手|snap assist/i.test(win.title));
|
|
129
|
+
}
|
|
121
130
|
function isHostWindow(win) {
|
|
122
131
|
return HOST_EXES.includes(win.exe.toLowerCase());
|
|
123
132
|
}
|
|
@@ -534,12 +543,10 @@ var Computer = class Computer {
|
|
|
534
543
|
async point(coordinate, field = "coordinate") {
|
|
535
544
|
if (!Array.isArray(coordinate) || coordinate.length !== 2) throw new Error(`${field} must be [x, y] in screenshot pixels.`);
|
|
536
545
|
const display = await this.display();
|
|
537
|
-
|
|
546
|
+
return toPhysical({
|
|
538
547
|
x: coordinate[0],
|
|
539
548
|
y: coordinate[1]
|
|
540
549
|
}, display, this.shotSize(display));
|
|
541
|
-
await this.overlay.dodgeCard(p);
|
|
542
|
-
return p;
|
|
543
550
|
}
|
|
544
551
|
async toModel(point) {
|
|
545
552
|
const display = await this.display();
|
|
@@ -552,32 +559,24 @@ var Computer = class Computer {
|
|
|
552
559
|
await this.refreshDisplays();
|
|
553
560
|
const display = await this.display();
|
|
554
561
|
const size = this.shotSize(display);
|
|
555
|
-
const shot = await this.capture(display, size);
|
|
556
|
-
await this.helper.call("shot_mark", this.rect(display)).catch(() => {});
|
|
562
|
+
const shot = await this.capture(display, size, { mark: true });
|
|
557
563
|
await this.remember();
|
|
558
564
|
return shot;
|
|
559
565
|
}
|
|
560
|
-
rect(display) {
|
|
561
|
-
return {
|
|
562
|
-
x: display.x,
|
|
563
|
-
y: display.y,
|
|
564
|
-
width: display.width,
|
|
565
|
-
height: display.height
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
566
|
/**
|
|
569
567
|
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
570
568
|
* the last one the model saw (saves an image and tells it the action had no
|
|
571
569
|
* visible effect).
|
|
572
570
|
*/
|
|
573
571
|
async freshShot() {
|
|
572
|
+
await this.refreshDisplays();
|
|
574
573
|
const display = await this.display();
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
return
|
|
574
|
+
const shot = await this.capture(display, this.shotSize(display), {
|
|
575
|
+
compare: true,
|
|
576
|
+
threshold: UNCHANGED_DIFF
|
|
577
|
+
});
|
|
578
|
+
await this.remember();
|
|
579
|
+
return shot ?? "unchanged";
|
|
581
580
|
}
|
|
582
581
|
/** The foreground window as of the model's latest look at the screen. */
|
|
583
582
|
seen;
|
|
@@ -600,7 +599,7 @@ var Computer = class Computer {
|
|
|
600
599
|
const now = await this.foreground().catch(() => void 0);
|
|
601
600
|
return now && now.hwnd !== seen.hwnd ? now : void 0;
|
|
602
601
|
}
|
|
603
|
-
async capture(rect, out) {
|
|
602
|
+
async capture(rect, out, options = {}) {
|
|
604
603
|
const result = await this.helper.call("screenshot", {
|
|
605
604
|
x: rect.x,
|
|
606
605
|
y: rect.y,
|
|
@@ -608,8 +607,10 @@ var Computer = class Computer {
|
|
|
608
607
|
height: rect.height,
|
|
609
608
|
outWidth: out.width,
|
|
610
609
|
outHeight: out.height,
|
|
611
|
-
quality: this.settings().jpegQuality
|
|
610
|
+
quality: this.settings().jpegQuality,
|
|
611
|
+
...options
|
|
612
612
|
}, 3e4);
|
|
613
|
+
if (result.unchanged || result.data === void 0) return void 0;
|
|
613
614
|
return {
|
|
614
615
|
data: Buffer.from(result.data, "base64"),
|
|
615
616
|
width: result.width,
|
|
@@ -625,12 +626,12 @@ var Computer = class Computer {
|
|
|
625
626
|
maxLongEdge: s.maxLongEdge,
|
|
626
627
|
maxPixels: s.maxPixels
|
|
627
628
|
});
|
|
628
|
-
return this.capture(rect, out);
|
|
629
|
+
return await this.capture(rect, out);
|
|
629
630
|
}
|
|
630
631
|
async foreground() {
|
|
631
632
|
const win = await this.helper.call("foreground");
|
|
632
633
|
if (!win || typeof win.hwnd !== "number") return void 0;
|
|
633
|
-
if (!isHostWindow(win)) this.lastTarget = win;
|
|
634
|
+
if (!isHostWindow(win) && !isTransientShell(win)) this.lastTarget = win;
|
|
634
635
|
return win;
|
|
635
636
|
}
|
|
636
637
|
/**
|
|
@@ -641,7 +642,7 @@ var Computer = class Computer {
|
|
|
641
642
|
async refocusFromHost() {
|
|
642
643
|
const target = this.lastTarget;
|
|
643
644
|
const fg = await this.foreground().catch(() => void 0);
|
|
644
|
-
if (!fg || !isHostWindow(fg) || !target || target.hwnd === fg.hwnd) return;
|
|
645
|
+
if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
|
|
645
646
|
if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
|
|
646
647
|
}
|
|
647
648
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
@@ -727,7 +728,7 @@ var Computer = class Computer {
|
|
|
727
728
|
}
|
|
728
729
|
if (s.pauseOnUserInput && INPUT.has(action)) {
|
|
729
730
|
const changed = await this.foregroundChanged();
|
|
730
|
-
if (changed && !isHostWindow(changed)) {
|
|
731
|
+
if (changed && !isHostWindow(changed) && !isTransientShell(changed)) {
|
|
731
732
|
await this.overlay.status("检测到窗口切换,重新查看屏幕");
|
|
732
733
|
const image = call.vision ? await this.screenshot() : void 0;
|
|
733
734
|
if (!image) this.seen = changed;
|
|
@@ -1148,8 +1149,6 @@ var OverlayController = class {
|
|
|
1148
1149
|
visible = false;
|
|
1149
1150
|
idleTimer;
|
|
1150
1151
|
hostWindows = [];
|
|
1151
|
-
/** The floating card and the display it lives on, while carded. */
|
|
1152
|
-
card;
|
|
1153
1152
|
stopping = false;
|
|
1154
1153
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
1155
1154
|
paused = false;
|
|
@@ -1283,48 +1282,22 @@ var OverlayController = class {
|
|
|
1283
1282
|
hwnd: main.hwnd,
|
|
1284
1283
|
mode: "card"
|
|
1285
1284
|
}];
|
|
1286
|
-
this.card = {
|
|
1287
|
-
hwnd: main.hwnd,
|
|
1288
|
-
display
|
|
1289
|
-
};
|
|
1290
1285
|
} catch (error) {
|
|
1291
1286
|
this.log(`host window ${mode}: ${String(error)}`);
|
|
1292
1287
|
}
|
|
1293
1288
|
}
|
|
1294
|
-
/**
|
|
1295
|
-
* The agent is about to point at something under the card: move the card to
|
|
1296
|
-
* the opposite bottom corner so the target is visible and clickable.
|
|
1297
|
-
* Returns whether it moved.
|
|
1298
|
-
*/
|
|
1299
|
-
async dodgeCard(point) {
|
|
1300
|
-
const card = this.card;
|
|
1301
|
-
if (!card) return false;
|
|
1302
|
-
try {
|
|
1303
|
-
const win = await this.helper.call("window_at", { ...point });
|
|
1304
|
-
if (!win || win.hwnd !== card.hwnd) return false;
|
|
1305
|
-
const d = card.display;
|
|
1306
|
-
const margin = Math.round(16 * d.dpi / 96);
|
|
1307
|
-
const x = win.x + win.width / 2 > d.workX + d.workWidth / 2 ? d.workX + margin : d.workX + d.workWidth - win.width - margin;
|
|
1308
|
-
await this.helper.call("window_card", {
|
|
1309
|
-
hwnd: card.hwnd,
|
|
1310
|
-
x,
|
|
1311
|
-
y: win.y,
|
|
1312
|
-
width: win.width,
|
|
1313
|
-
height: win.height
|
|
1314
|
-
});
|
|
1315
|
-
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
1316
|
-
return true;
|
|
1317
|
-
} catch (error) {
|
|
1318
|
-
this.log(`card dodge: ${String(error)}`);
|
|
1319
|
-
return false;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
1289
|
async restoreHost() {
|
|
1323
1290
|
const windows = this.hostWindows;
|
|
1324
1291
|
this.hostWindows = [];
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1292
|
+
for (const win of windows) if (win.mode === "card") {
|
|
1293
|
+
await this.helper.call("window_uncard", { hwnd: win.hwnd }).catch(() => {});
|
|
1294
|
+
setTimeout(() => {
|
|
1295
|
+
this.helper.call("windows").then((rows) => rows.some((row) => row.hwnd === win.hwnd) ? void 0 : this.helper.call("window_cmd", {
|
|
1296
|
+
hwnd: win.hwnd,
|
|
1297
|
+
op: "restore"
|
|
1298
|
+
})).catch(() => {});
|
|
1299
|
+
}, 1200).unref();
|
|
1300
|
+
} else await this.helper.call("window_cmd", {
|
|
1328
1301
|
hwnd: win.hwnd,
|
|
1329
1302
|
op: "restore"
|
|
1330
1303
|
}).catch(() => {});
|
|
@@ -1337,8 +1310,9 @@ function promptText(mode) {
|
|
|
1337
1310
|
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
|
|
1338
1311
|
${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.
|
|
1339
1312
|
- 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.
|
|
1340
|
-
- The "DeepSeek Harness.exe" window is your own chat interface
|
|
1341
|
-
-
|
|
1313
|
+
- The "DeepSeek Harness.exe" window is your own chat interface. While you control the computer it floats as a card that only the user sees: your screenshots show what is underneath it and your clicks and scrolls pass through it, so simply ignore it. Never type into DeepSeek Harness; keys go to the window you were working in.
|
|
1314
|
+
- If the target window is small or partly covered by other windows, maximize it (windows maximize) or minimize what is in the way (windows minimize works for any window) instead of working around it.
|
|
1315
|
+
- Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets. When text is too small to read, zoom once on a generous region that contains everything you need (zooming step by step wastes calls).
|
|
1342
1316
|
- Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
|
|
1343
1317
|
- Enter text with type, even long or multi-line text (over 200 characters it is pasted and the user's clipboard is restored). Do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
|
|
1344
1318
|
- Office apps: F12 opens the classic Save As dialog, where you can type a full path in the file name box.
|
|
@@ -7320,7 +7294,7 @@ function createTools(host) {
|
|
|
7320
7294
|
for (let i = 0; i < 32; i++) {
|
|
7321
7295
|
await setTimeout$1(250, void 0, { signal: call.signal });
|
|
7322
7296
|
const now = await computer.foreground();
|
|
7323
|
-
if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
|
|
7297
|
+
if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && !isTransientShell(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
|
|
7324
7298
|
}
|
|
7325
7299
|
}
|
|
7326
7300
|
const fg = await computer.foreground();
|
|
@@ -7362,11 +7336,11 @@ function createTools(host) {
|
|
|
7362
7336
|
const { action, hwnd, name } = args;
|
|
7363
7337
|
const rows = await computer.windows();
|
|
7364
7338
|
if (action === "list") return { text: (await Promise.all(rows.map(async (win) => `hwnd=${win.hwnd} | ${win.exe} | "${win.title.slice(0, 70)}"${win.foreground ? " | FOREGROUND" : ""}${win.minimized ? " | minimized" : ` | ${await computer.windowBox(win)}`}${isHostWindow(win) ? " | (your own DeepSeek Harness chat window)" : ""}`))).join("\n") || "No windows." };
|
|
7365
|
-
const target = hwnd !== void 0 ? rows.find((win) => win.hwnd === hwnd) : name ? rows.find((win) => appMatches(name, win)
|
|
7339
|
+
const target = hwnd !== void 0 ? rows.find((win) => win.hwnd === hwnd) : name ? rows.find((win) => !isHostWindow(win) && appMatches(name, win)) ?? rows.find((win) => !isHostWindow(win) && win.title.toLowerCase().includes(name.toLowerCase())) ?? rows.find((win) => appMatches(name, win)) : void 0;
|
|
7366
7340
|
if (!target) throw new Error("Window not found; call windows with action \"list\".");
|
|
7367
7341
|
const settings = computer.settings();
|
|
7368
7342
|
const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
|
|
7369
|
-
if (denial &&
|
|
7343
|
+
if (denial && action !== "minimize") throw new Error(denial);
|
|
7370
7344
|
await computer.overlay.begin(call.agent, `窗口 ${action}`);
|
|
7371
7345
|
await computer.overlay.yieldToUser(call.signal, false);
|
|
7372
7346
|
let text;
|
package/lib/types/access.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export declare const HOST_EXES: string[];
|
|
|
14
14
|
export declare function normalizeApp(name: string): string;
|
|
15
15
|
/** Do two app names refer to the same program ("explorer" and "文件资源管理器")? */
|
|
16
16
|
export declare function sameApp(a: string, b: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Windows shell surfaces that grab the foreground without being a place to
|
|
19
|
+
* work: the touch-keyboard / IME host and Snap Assist.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTransientShell(win: WindowLike & {
|
|
22
|
+
className?: string;
|
|
23
|
+
}): boolean;
|
|
17
24
|
export declare function isHostWindow(win: WindowLike): boolean;
|
|
18
25
|
/** Does a granted (or requested) app name refer to this window? */
|
|
19
26
|
export declare function appMatches(name: string, win: WindowLike): boolean;
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -89,7 +89,6 @@ export declare class Computer {
|
|
|
89
89
|
offscreen: boolean;
|
|
90
90
|
}>;
|
|
91
91
|
screenshot(): Promise<Shot>;
|
|
92
|
-
private rect;
|
|
93
92
|
/**
|
|
94
93
|
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
95
94
|
* the last one the model saw (saves an image and tells it the action had no
|
package/lib/types/overlay.d.ts
CHANGED
|
@@ -40,8 +40,6 @@ export declare class OverlayController {
|
|
|
40
40
|
private visible;
|
|
41
41
|
private idleTimer;
|
|
42
42
|
private hostWindows;
|
|
43
|
-
/** The floating card and the display it lives on, while carded. */
|
|
44
|
-
private card;
|
|
45
43
|
private stopping;
|
|
46
44
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
47
45
|
paused: boolean;
|
|
@@ -70,15 +68,6 @@ export declare class OverlayController {
|
|
|
70
68
|
private armIdle;
|
|
71
69
|
/** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
|
|
72
70
|
private shrinkHost;
|
|
73
|
-
/**
|
|
74
|
-
* The agent is about to point at something under the card: move the card to
|
|
75
|
-
* the opposite bottom corner so the target is visible and clickable.
|
|
76
|
-
* Returns whether it moved.
|
|
77
|
-
*/
|
|
78
|
-
dodgeCard(point: {
|
|
79
|
-
x: number;
|
|
80
|
-
y: number;
|
|
81
|
-
}): Promise<boolean>;
|
|
82
71
|
private restoreHost;
|
|
83
72
|
}
|
|
84
73
|
export {};
|
package/package.json
CHANGED