@copylee/dsh-computer-use 0.1.9 → 0.2.0
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 +2 -2
- package/helper/CuHelper.cs +130 -5
- package/lib/index.js +23 -3
- package/lib/types/computer.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
| 功能 | 说明 |
|
|
8
8
|
|---|---|
|
|
9
9
|
| 截图即坐标系 | 模型只用最近一张截图的像素坐标,DPI、缩放、多显示器偏移全部由插件换算,高分屏(200% 缩放)也点得准 |
|
|
10
|
-
| 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait`
|
|
10
|
+
| 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait` 也直接带回截图,“等一下再看”只需一步,而且画面一静止就提前结束,不会死等满时长;画面与上一张截图完全相同时不再发图,只告诉模型“没有可见变化”,省 token |
|
|
11
11
|
| 批量动作 | `computer_batch` 一次执行“点输入框 → 输入 → 回车”等多步,最后只截一张图 |
|
|
12
12
|
| 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
|
|
13
13
|
| 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
|
|
14
14
|
| 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
|
|
15
|
-
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI
|
|
15
|
+
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(通过 Windows 放大镜接口截图时把卡片排除在外,不闪烁;该接口不可用时退回为截图瞬间让卡片透明约 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
|
@@ -412,19 +412,38 @@ namespace DshComputerUse
|
|
|
412
412
|
int ow = Args.Int(r, "outWidth", w), oh = Args.Int(r, "outHeight", h);
|
|
413
413
|
int quality = Args.Int(r, "quality", 80);
|
|
414
414
|
if (w <= 0 || h <= 0 || ow <= 0 || oh <= 0) throw new Exception("invalid capture size");
|
|
415
|
+
string via = "blt";
|
|
415
416
|
using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
|
|
416
417
|
{
|
|
417
418
|
using (var g = Graphics.FromImage(bmp))
|
|
418
419
|
{
|
|
419
420
|
IntPtr dst = g.GetHdc();
|
|
420
421
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
421
|
-
// The DSH card is for the user only: capture what is under it
|
|
422
|
-
//
|
|
423
|
-
|
|
422
|
+
// The DSH card is for the user only: capture what is under it.
|
|
423
|
+
// Preferred: the Magnification API renders the screen without
|
|
424
|
+
// the card (no flicker). Fallback: hide the card for one BitBlt.
|
|
425
|
+
bool done = false;
|
|
426
|
+
var area = new Rectangle(x, y, w, h);
|
|
427
|
+
via = "blt";
|
|
428
|
+
if (CardLayer.Covers(area))
|
|
424
429
|
{
|
|
425
|
-
|
|
426
|
-
|
|
430
|
+
g.ReleaseHdc(dst);
|
|
431
|
+
dst = IntPtr.Zero;
|
|
432
|
+
using (var mag = MagCapture.Capture(area, CardLayer.Hwnd))
|
|
433
|
+
{
|
|
434
|
+
if (mag != null) { g.DrawImageUnscaled(mag, 0, 0); done = true; via = "mag"; }
|
|
435
|
+
}
|
|
436
|
+
if (!done) dst = g.GetHdc();
|
|
437
|
+
}
|
|
438
|
+
if (!done)
|
|
439
|
+
{
|
|
440
|
+
using (CardLayer.Hide(area))
|
|
441
|
+
{
|
|
442
|
+
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
443
|
+
finally { g.ReleaseHdc(dst); }
|
|
444
|
+
}
|
|
427
445
|
}
|
|
446
|
+
Native.ReleaseDC(IntPtr.Zero, src);
|
|
428
447
|
}
|
|
429
448
|
// compare: report "unchanged" instead of an identical image; mark: remember for next time.
|
|
430
449
|
bool compare = Args.Bool(r, "compare", false), mark = Args.Bool(r, "mark", false) || compare;
|
|
@@ -468,6 +487,7 @@ namespace DshComputerUse
|
|
|
468
487
|
output.Save(ms, jpegCodec, ep);
|
|
469
488
|
var d = new Dictionary<string, object>();
|
|
470
489
|
d["data"] = Convert.ToBase64String(ms.ToArray());
|
|
490
|
+
d["via"] = via == "blt" && MagCapture.Why.Length > 0 ? "blt (" + MagCapture.Why + ")" : via;
|
|
471
491
|
d["width"] = ow; d["height"] = oh;
|
|
472
492
|
return d;
|
|
473
493
|
}
|
|
@@ -845,6 +865,15 @@ namespace DshComputerUse
|
|
|
845
865
|
g.FillRectangle(Brushes.Black, r.X - ox, r.Y - oy, r.Width, r.Height);
|
|
846
866
|
}
|
|
847
867
|
|
|
868
|
+
/** Is the card visible over (any part of) this screen rectangle? */
|
|
869
|
+
public static bool Covers(Rectangle area)
|
|
870
|
+
{
|
|
871
|
+
if (!Live()) return false;
|
|
872
|
+
var r = Frame(Hwnd);
|
|
873
|
+
r.Inflate(32, 32);
|
|
874
|
+
return r.IntersectsWith(area);
|
|
875
|
+
}
|
|
876
|
+
|
|
848
877
|
/** Make the card invisible while a capture of `area` runs (dispose to show it again). */
|
|
849
878
|
public static IDisposable Hide(Rectangle area)
|
|
850
879
|
{
|
|
@@ -869,6 +898,102 @@ namespace DshComputerUse
|
|
|
869
898
|
}
|
|
870
899
|
}
|
|
871
900
|
|
|
901
|
+
/**
|
|
902
|
+
* Screen capture through the Windows Magnification API, which can leave
|
|
903
|
+
* out windows of other processes (MagSetWindowFilterList). The magnifier
|
|
904
|
+
* control lives in a never-shown host window; MagSetWindowSource renders
|
|
905
|
+
* synchronously into the scaling callback. Any failure disables it for the
|
|
906
|
+
* rest of the run and callers fall back to BitBlt.
|
|
907
|
+
*/
|
|
908
|
+
internal static class MagCapture
|
|
909
|
+
{
|
|
910
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
911
|
+
public struct MAGIMAGEHEADER { public uint width; public uint height; public Guid format; public uint stride; public uint offset; public UIntPtr cbSize; }
|
|
912
|
+
|
|
913
|
+
delegate bool ScalingCallback(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER srcheader, IntPtr destdata, MAGIMAGEHEADER destheader, Native.RECT unclipped, Native.RECT clipped, IntPtr dirty);
|
|
914
|
+
|
|
915
|
+
[DllImport("Magnification.dll")] static extern bool MagInitialize();
|
|
916
|
+
[DllImport("Magnification.dll")] static extern bool MagSetWindowSource(IntPtr hwnd, Native.RECT rect);
|
|
917
|
+
[DllImport("Magnification.dll")] static extern bool MagSetWindowFilterList(IntPtr hwnd, int mode, int count, IntPtr[] list);
|
|
918
|
+
[DllImport("Magnification.dll")] static extern bool MagSetImageScalingCallback(IntPtr hwnd, ScalingCallback cb);
|
|
919
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
|
920
|
+
static extern IntPtr CreateWindowEx(int ex, string cls, string name, int style, int x, int y, int w, int h, IntPtr parent, IntPtr menu, IntPtr inst, IntPtr param);
|
|
921
|
+
|
|
922
|
+
static bool broken;
|
|
923
|
+
public static string Why = "";
|
|
924
|
+
static Form host;
|
|
925
|
+
static IntPtr magnifier = IntPtr.Zero;
|
|
926
|
+
static ScalingCallback callback;
|
|
927
|
+
static Bitmap frame;
|
|
928
|
+
|
|
929
|
+
static bool Ready()
|
|
930
|
+
{
|
|
931
|
+
if (broken) return false;
|
|
932
|
+
if (magnifier != IntPtr.Zero) return true;
|
|
933
|
+
try
|
|
934
|
+
{
|
|
935
|
+
if (!MagInitialize()) { broken = true; Why = "init"; return false; }
|
|
936
|
+
host = new Form { FormBorderStyle = FormBorderStyle.None, ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Location = new Point(0, 0), Size = new Size(16, 16) };
|
|
937
|
+
IntPtr parent = host.Handle; // created, never shown
|
|
938
|
+
magnifier = CreateWindowEx(0, "Magnifier", "cu-magnifier", 0x40000000 | 0x10000000, 0, 0, 16, 16, parent, IntPtr.Zero, Native.GetModuleHandle(null), IntPtr.Zero);
|
|
939
|
+
callback = OnImage;
|
|
940
|
+
if (magnifier == IntPtr.Zero || !MagSetImageScalingCallback(magnifier, callback)) { broken = true; Why = "callback"; return false; }
|
|
941
|
+
return true;
|
|
942
|
+
}
|
|
943
|
+
catch (Exception e) { broken = true; Why = "ready: " + e.Message; return false; }
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/** The screen rectangle without the `exclude` window, or null when unavailable. */
|
|
947
|
+
public static Bitmap Capture(Rectangle area, IntPtr exclude)
|
|
948
|
+
{
|
|
949
|
+
if (!Ready()) return null;
|
|
950
|
+
try
|
|
951
|
+
{
|
|
952
|
+
// The never-shown host must be as large as the capture, or the control is clipped.
|
|
953
|
+
Native.SetWindowPos(host.Handle, IntPtr.Zero, 0, 0, area.Width, area.Height, 0x0004 | 0x0010);
|
|
954
|
+
Native.SetWindowPos(magnifier, IntPtr.Zero, 0, 0, area.Width, area.Height, 0x0004 | 0x0010); // NOZORDER | NOACTIVATE
|
|
955
|
+
if (!MagSetWindowFilterList(magnifier, 0 /* MW_FILTERMODE_EXCLUDE */, 1, new[] { exclude })) { broken = true; Why = "filter"; return null; }
|
|
956
|
+
frame = null;
|
|
957
|
+
var rc = new Native.RECT { Left = area.Left, Top = area.Top, Right = area.Right, Bottom = area.Bottom };
|
|
958
|
+
if (!MagSetWindowSource(magnifier, rc)) { broken = true; Why = "source"; return null; }
|
|
959
|
+
var result = frame;
|
|
960
|
+
frame = null;
|
|
961
|
+
if (result == null || result.Width != area.Width || result.Height != area.Height)
|
|
962
|
+
{
|
|
963
|
+
Why = result == null ? "no frame" : "size " + result.Width + "x" + result.Height;
|
|
964
|
+
if (result != null) result.Dispose();
|
|
965
|
+
broken = true;
|
|
966
|
+
return null;
|
|
967
|
+
}
|
|
968
|
+
return result;
|
|
969
|
+
}
|
|
970
|
+
catch (Exception e) { broken = true; Why = "capture: " + e.Message; return null; }
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
static bool OnImage(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER h, IntPtr destdata, MAGIMAGEHEADER dh, Native.RECT unclipped, Native.RECT clipped, IntPtr dirty)
|
|
974
|
+
{
|
|
975
|
+
try
|
|
976
|
+
{
|
|
977
|
+
var bmp = new Bitmap((int)h.width, (int)h.height, PixelFormat.Format32bppRgb);
|
|
978
|
+
var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
|
|
979
|
+
try
|
|
980
|
+
{
|
|
981
|
+
int rowBytes = (int)h.width * 4;
|
|
982
|
+
var row = new byte[rowBytes];
|
|
983
|
+
for (int y = 0; y < h.height; y++)
|
|
984
|
+
{
|
|
985
|
+
Marshal.Copy(new IntPtr(srcdata.ToInt64() + h.offset + (long)y * h.stride), row, 0, rowBytes);
|
|
986
|
+
Marshal.Copy(row, 0, new IntPtr(data.Scan0.ToInt64() + (long)y * data.Stride), rowBytes);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
finally { bmp.UnlockBits(data); }
|
|
990
|
+
frame = bmp;
|
|
991
|
+
}
|
|
992
|
+
catch (Exception) { frame = null; }
|
|
993
|
+
return true;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
872
997
|
/** While the agent moves, clicks or scrolls, the card lets the mouse through. */
|
|
873
998
|
internal sealed class PassThrough : IDisposable
|
|
874
999
|
{
|
package/lib/index.js
CHANGED
|
@@ -645,6 +645,26 @@ var Computer = class Computer {
|
|
|
645
645
|
if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
|
|
646
646
|
if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
|
|
647
647
|
}
|
|
648
|
+
/** Wait at most `maxMs`, returning once the screen has been still for ~0.8 s. Returns the time waited. */
|
|
649
|
+
async waitForQuiet(maxMs, signal) {
|
|
650
|
+
const started = Date.now();
|
|
651
|
+
if (maxMs <= 600) {
|
|
652
|
+
await setTimeout$1(maxMs, void 0, { signal });
|
|
653
|
+
return maxMs;
|
|
654
|
+
}
|
|
655
|
+
const display = await this.display();
|
|
656
|
+
if (await this.helper.call("settle", {
|
|
657
|
+
x: display.x,
|
|
658
|
+
y: display.y,
|
|
659
|
+
width: display.width,
|
|
660
|
+
height: display.height,
|
|
661
|
+
minMs: 300,
|
|
662
|
+
maxMs,
|
|
663
|
+
quietMs: 800
|
|
664
|
+
}, maxMs + 1e4).catch(() => null) === null) await setTimeout$1(Math.max(0, maxMs - (Date.now() - started)), void 0, { signal });
|
|
665
|
+
if (signal.aborted) throw new Error("Cancelled.");
|
|
666
|
+
return Date.now() - started;
|
|
667
|
+
}
|
|
648
668
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
649
669
|
async settle(signal) {
|
|
650
670
|
const s = this.settings();
|
|
@@ -761,9 +781,9 @@ var Computer = class Computer {
|
|
|
761
781
|
return { text: `Cursor at (${p.x}, ${p.y})${p.offscreen ? " — on another display" : ""}.` };
|
|
762
782
|
}
|
|
763
783
|
case "wait": {
|
|
764
|
-
const seconds = Math.min(30, Math.max(0, input.duration ?? 1));
|
|
765
|
-
await
|
|
766
|
-
return { text: `Waited ${seconds}s.` };
|
|
784
|
+
const seconds = Math.min(30, Math.max(0, Number(input.duration ?? 1) || 0));
|
|
785
|
+
const waited = await this.waitForQuiet(seconds * 1e3, call.signal);
|
|
786
|
+
return { text: waited < seconds * 1e3 - 200 ? `Waited ${(waited / 1e3).toFixed(1)}s (the screen settled early).` : `Waited ${seconds}s.` };
|
|
767
787
|
}
|
|
768
788
|
case "mouse_move": {
|
|
769
789
|
const p = await this.point(input.coordinate);
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -116,6 +116,8 @@ export declare class Computer {
|
|
|
116
116
|
* in front instead of refusing.
|
|
117
117
|
*/
|
|
118
118
|
private refocusFromHost;
|
|
119
|
+
/** Wait at most `maxMs`, returning once the screen has been still for ~0.8 s. Returns the time waited. */
|
|
120
|
+
waitForQuiet(maxMs: number, signal: AbortSignal): Promise<number>;
|
|
119
121
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
120
122
|
settle(signal: AbortSignal): Promise<void>;
|
|
121
123
|
windowAt(point: Point): Promise<WindowInfo | undefined>;
|
package/package.json
CHANGED