deepseek-computer-use 0.1.1 → 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/CHANGELOG.md +22 -0
- package/README.md +82 -24
- package/assets/cover-whale-girl.png +0 -0
- package/lib/bridge.js +153 -150
- package/lib/build-helper.mjs +18 -4
- package/lib/build.mjs +2 -2
- package/lib/index.js +58 -35
- package/lib/parameters.js +50 -0
- package/lib/safety.js +2 -9
- package/lib/tools.js +131 -32
- package/lib/update-client.js +408 -0
- package/native/Driver.cs +1906 -1857
- package/native/Json.cs +274 -274
- package/native/Overlay.cs +732 -725
- package/native/Program.cs +160 -157
- package/native/audio/Program.cs +95 -95
- package/native/wgcfw/Program.cs +249 -249
- package/package.json +26 -8
- package/skills/computer-use/SKILL.md +5 -2
package/native/wgcfw/Program.cs
CHANGED
|
@@ -1,249 +1,249 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Drawing;
|
|
3
|
-
using System.Drawing.Imaging;
|
|
4
|
-
using System.Runtime.InteropServices;
|
|
5
|
-
using System.Threading;
|
|
6
|
-
using SharpDX.Direct3D;
|
|
7
|
-
using SharpDX.Direct3D11;
|
|
8
|
-
using SharpDX.DXGI;
|
|
9
|
-
using Windows.Graphics.Capture;
|
|
10
|
-
using Windows.Graphics.DirectX;
|
|
11
|
-
using Windows.Graphics.DirectX.Direct3D11;
|
|
12
|
-
using D3D11Device = SharpDX.Direct3D11.Device;
|
|
13
|
-
using D3D11Texture2D = SharpDX.Direct3D11.Texture2D;
|
|
14
|
-
using DXGIDevice = SharpDX.DXGI.Device;
|
|
15
|
-
|
|
16
|
-
namespace DshCuCapture
|
|
17
|
-
{
|
|
18
|
-
/// Windows.Graphics.Capture for .NET Framework 4.8 - the same API Codex uses,
|
|
19
|
-
/// with no .NET 8 runtime dependency (Framework 4.8 ships with Windows 10/11).
|
|
20
|
-
internal static class Program
|
|
21
|
-
{
|
|
22
|
-
[ComImport]
|
|
23
|
-
[Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
|
|
24
|
-
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
25
|
-
private interface IDirect3DDxgiInterfaceAccess
|
|
26
|
-
{
|
|
27
|
-
[PreserveSig] int GetInterface(ref Guid iid, out IntPtr result);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
[DllImport("d3d11.dll", ExactSpelling = true)]
|
|
31
|
-
private static extern int CreateDirect3D11DeviceFromDXGIDevice(IntPtr dxgiDevice, out IntPtr graphicsDevice);
|
|
32
|
-
|
|
33
|
-
[DllImport("combase.dll", CharSet = CharSet.Unicode)]
|
|
34
|
-
private static extern int WindowsCreateString(string source, int length, out IntPtr hstring);
|
|
35
|
-
|
|
36
|
-
[DllImport("combase.dll")]
|
|
37
|
-
private static extern int RoGetActivationFactory(IntPtr activatableClassId, ref Guid iid, out IntPtr factory);
|
|
38
|
-
|
|
39
|
-
[DllImport("combase.dll")]
|
|
40
|
-
private static extern int WindowsDeleteString(IntPtr hstring);
|
|
41
|
-
|
|
42
|
-
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
|
|
43
|
-
private static extern void CopyMemory(IntPtr destination, IntPtr source, int length);
|
|
44
|
-
|
|
45
|
-
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
|
46
|
-
private delegate int CreateForWindowDelegate(IntPtr thisPtr, IntPtr hwnd, ref Guid iid, out IntPtr item);
|
|
47
|
-
private delegate int CreateForMonitorDelegate(IntPtr thisPtr, IntPtr hmon, ref Guid iid, out IntPtr item);
|
|
48
|
-
|
|
49
|
-
[DllImport("user32.dll")] private static extern IntPtr MonitorFromPoint(POINT pt, uint flags);
|
|
50
|
-
[StructLayout(LayoutKind.Sequential)] private struct POINT { public int X, Y; }
|
|
51
|
-
|
|
52
|
-
private static bool _suppressBorder = true;
|
|
53
|
-
|
|
54
|
-
private sealed class Slot
|
|
55
|
-
{
|
|
56
|
-
public Bitmap Bitmap;
|
|
57
|
-
public Exception Error;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private static int Main(string[] args)
|
|
61
|
-
{
|
|
62
|
-
long hwnd = 0;
|
|
63
|
-
bool monitor = false;
|
|
64
|
-
bool redactAll = false;
|
|
65
|
-
bool suppressBorder = true;
|
|
66
|
-
var redactRects = new System.Collections.Generic.List<System.Drawing.Rectangle>();
|
|
67
|
-
string output = "capture.png";
|
|
68
|
-
int timeoutMs = 2000;
|
|
69
|
-
for (int i = 0; i < args.Length - 1; i++)
|
|
70
|
-
{
|
|
71
|
-
if (args[i] == "--redact")
|
|
72
|
-
{
|
|
73
|
-
string[] parts = args[i + 1].Split(',');
|
|
74
|
-
if (parts.Length == 4)
|
|
75
|
-
redactRects.Add(new System.Drawing.Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])));
|
|
76
|
-
}
|
|
77
|
-
else if (args[i] == "--hwnd") long.TryParse(args[i + 1], out hwnd);
|
|
78
|
-
else if (args[i] == "--out") output = args[i + 1];
|
|
79
|
-
else if (args[i] == "--timeout") int.TryParse(args[i + 1], out timeoutMs);
|
|
80
|
-
}
|
|
81
|
-
for (int i = 0; i < args.Length; i++)
|
|
82
|
-
{
|
|
83
|
-
if (args[i] == "--monitor") monitor = true;
|
|
84
|
-
else if (args[i] == "--redact-all") redactAll = true;
|
|
85
|
-
else if (args[i] == "--keep-border") suppressBorder = false;
|
|
86
|
-
}
|
|
87
|
-
if (hwnd == 0 && !monitor) { Console.Error.WriteLine("--hwnd or --monitor is required"); return 2; }
|
|
88
|
-
|
|
89
|
-
try
|
|
90
|
-
{
|
|
91
|
-
GraphicsCaptureItem item = monitor ? CreateMonitorItem() : CreateItem(new IntPtr(hwnd));
|
|
92
|
-
using (D3D11Device device = new D3D11Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport))
|
|
93
|
-
using (DXGIDevice dxgi = device.QueryInterface<DXGIDevice>())
|
|
94
|
-
{
|
|
95
|
-
int hr = CreateDirect3D11DeviceFromDXGIDevice(dxgi.NativePointer, out IntPtr winrtDevicePtr);
|
|
96
|
-
if (hr < 0) { Console.Error.WriteLine("CreateDirect3D11DeviceFromDXGIDevice hr=0x" + hr.ToString("X8")); return 3; }
|
|
97
|
-
IDirect3DDevice winrtDevice;
|
|
98
|
-
try { winrtDevice = (IDirect3DDevice)Marshal.GetObjectForIUnknown(winrtDevicePtr); }
|
|
99
|
-
finally { Marshal.Release(winrtDevicePtr); }
|
|
100
|
-
|
|
101
|
-
_suppressBorder = suppressBorder;
|
|
102
|
-
var slot = new Slot();
|
|
103
|
-
using (var pool = Direct3D11CaptureFramePool.CreateFreeThreaded(
|
|
104
|
-
winrtDevice, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size))
|
|
105
|
-
using (var session = pool.CreateCaptureSession(item))
|
|
106
|
-
using (var done = new ManualResetEventSlim(false))
|
|
107
|
-
{
|
|
108
|
-
try { session.IsCursorCaptureEnabled = false; } catch { }
|
|
109
|
-
// Windows 11 draws a yellow frame around any captured window. Kill it
|
|
110
|
-
// (Codex does the same through its capture-border access path) so the
|
|
111
|
-
// border never shows up in the picture or on the user's desktop.
|
|
112
|
-
if (_suppressBorder) { try { session.IsBorderRequired = false; } catch { } }
|
|
113
|
-
|
|
114
|
-
Direct3D11CaptureFramePool owner = pool;
|
|
115
|
-
D3D11Device gpu = device;
|
|
116
|
-
pool.FrameArrived += (sender, e) =>
|
|
117
|
-
{
|
|
118
|
-
if (slot.Bitmap != null) return;
|
|
119
|
-
try
|
|
120
|
-
{
|
|
121
|
-
using (var frame = owner.TryGetNextFrame())
|
|
122
|
-
{
|
|
123
|
-
if (frame == null) return;
|
|
124
|
-
var access = (IDirect3DDxgiInterfaceAccess)frame.Surface;
|
|
125
|
-
Guid iid = new Guid("6f15aaf2-d208-4e89-9ab4-489535d34f9c"); // ID3D11Texture2D
|
|
126
|
-
IntPtr texPtr;
|
|
127
|
-
if (access.GetInterface(ref iid, out texPtr) < 0 || texPtr == IntPtr.Zero) return;
|
|
128
|
-
using (var texture = new D3D11Texture2D(texPtr))
|
|
129
|
-
{
|
|
130
|
-
var desc = texture.Description;
|
|
131
|
-
var stagingDesc = new Texture2DDescription
|
|
132
|
-
{
|
|
133
|
-
Width = desc.Width,
|
|
134
|
-
Height = desc.Height,
|
|
135
|
-
MipLevels = 1,
|
|
136
|
-
ArraySize = 1,
|
|
137
|
-
Format = desc.Format,
|
|
138
|
-
SampleDescription = new SampleDescription(1, 0),
|
|
139
|
-
Usage = ResourceUsage.Staging,
|
|
140
|
-
BindFlags = BindFlags.None,
|
|
141
|
-
CpuAccessFlags = CpuAccessFlags.Read,
|
|
142
|
-
OptionFlags = ResourceOptionFlags.None,
|
|
143
|
-
};
|
|
144
|
-
using (var staging = new D3D11Texture2D(gpu, stagingDesc))
|
|
145
|
-
{
|
|
146
|
-
var context = gpu.ImmediateContext;
|
|
147
|
-
context.CopyResource(texture, staging);
|
|
148
|
-
SharpDX.DataBox box = context.MapSubresource(staging, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
|
|
149
|
-
try
|
|
150
|
-
{
|
|
151
|
-
Bitmap bmp = new Bitmap(desc.Width, desc.Height, PixelFormat.Format32bppArgb);
|
|
152
|
-
BitmapData data = bmp.LockBits(new Rectangle(0, 0, desc.Width, desc.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
|
153
|
-
for (int y = 0; y < desc.Height; y++)
|
|
154
|
-
{
|
|
155
|
-
IntPtr src = IntPtr.Add(box.DataPointer, y * box.RowPitch);
|
|
156
|
-
IntPtr dst = IntPtr.Add(data.Scan0, y * data.Stride);
|
|
157
|
-
CopyMemory(dst, src, desc.Width * 4);
|
|
158
|
-
}
|
|
159
|
-
bmp.UnlockBits(data);
|
|
160
|
-
slot.Bitmap = bmp;
|
|
161
|
-
}
|
|
162
|
-
finally { context.UnmapSubresource(staging, 0); }
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
catch (Exception ex) { slot.Error = ex; }
|
|
168
|
-
finally { done.Set(); }
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
session.StartCapture();
|
|
172
|
-
done.Wait(timeoutMs);
|
|
173
|
-
try { session.Dispose(); } catch { }
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (slot.Error != null) { Console.Error.WriteLine(slot.Error.GetType().Name + ": " + slot.Error.Message); return 6; }
|
|
177
|
-
if (slot.Bitmap == null) { Console.Error.WriteLine("no frame arrived (timeout or empty surface)"); return 4; }
|
|
178
|
-
|
|
179
|
-
if (redactAll || redactRects.Count > 0)
|
|
180
|
-
{
|
|
181
|
-
using (var g = Graphics.FromImage(slot.Bitmap))
|
|
182
|
-
{
|
|
183
|
-
g.Clear(redactAll ? Color.Black : Color.Transparent);
|
|
184
|
-
foreach (var rect in redactRects) g.FillRectangle(Brushes.Black, rect);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
int w = slot.Bitmap.Width, h = slot.Bitmap.Height;
|
|
188
|
-
slot.Bitmap.Save(output, ImageFormat.Png);
|
|
189
|
-
slot.Bitmap.Dispose();
|
|
190
|
-
Console.WriteLine("wgc " + w + "x" + h + " -> " + output);
|
|
191
|
-
return 0;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
catch (Exception ex)
|
|
195
|
-
{
|
|
196
|
-
Console.Error.WriteLine(ex.GetType().Name + ": " + ex.Message);
|
|
197
|
-
return 5;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private static GraphicsCaptureItem CreateMonitorItem()
|
|
202
|
-
{
|
|
203
|
-
POINT origin = new POINT { X = 0, Y = 0 };
|
|
204
|
-
IntPtr monitorHandle = MonitorFromPoint(origin, 2); // MONITOR_DEFAULTTONEAREST
|
|
205
|
-
const string className = "Windows.Graphics.Capture.GraphicsCaptureItem";
|
|
206
|
-
WindowsCreateString(className, className.Length, out IntPtr hstr);
|
|
207
|
-
try
|
|
208
|
-
{
|
|
209
|
-
Guid interopIid = new Guid("3628E81B-3CAC-4C60-B7F4-23CE0E0C3356");
|
|
210
|
-
int hr = RoGetActivationFactory(hstr, ref interopIid, out IntPtr factoryPtr);
|
|
211
|
-
if (hr < 0) throw new COMException("RoGetActivationFactory hr=0x" + hr.ToString("X8"), hr);
|
|
212
|
-
IntPtr vtable = Marshal.ReadIntPtr(factoryPtr);
|
|
213
|
-
IntPtr fn = Marshal.ReadIntPtr(vtable, 4 * IntPtr.Size); // CreateForMonitor
|
|
214
|
-
var createForMonitor = (CreateForMonitorDelegate)Marshal.GetDelegateForFunctionPointer(fn, typeof(CreateForMonitorDelegate));
|
|
215
|
-
Guid itemIid = new Guid("79C3F95B-31F7-4EC2-A464-632EF5D30760");
|
|
216
|
-
int hrItem = createForMonitor(factoryPtr, monitorHandle, ref itemIid, out IntPtr itemPtr);
|
|
217
|
-
Marshal.Release(factoryPtr);
|
|
218
|
-
if (hrItem < 0) throw new COMException("CreateForMonitor hr=0x" + hrItem.ToString("X8"), hrItem);
|
|
219
|
-
try { return (GraphicsCaptureItem)Marshal.GetObjectForIUnknown(itemPtr); }
|
|
220
|
-
finally { Marshal.Release(itemPtr); }
|
|
221
|
-
}
|
|
222
|
-
finally { WindowsDeleteString(hstr); }
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private static GraphicsCaptureItem CreateItem(IntPtr hwnd)
|
|
226
|
-
{
|
|
227
|
-
const string className = "Windows.Graphics.Capture.GraphicsCaptureItem";
|
|
228
|
-
WindowsCreateString(className, className.Length, out IntPtr hstr);
|
|
229
|
-
try
|
|
230
|
-
{
|
|
231
|
-
Guid interopIid = new Guid("3628E81B-3CAC-4C60-B7F4-23CE0E0C3356");
|
|
232
|
-
int hr = RoGetActivationFactory(hstr, ref interopIid, out IntPtr factoryPtr);
|
|
233
|
-
if (hr < 0) throw new COMException("RoGetActivationFactory hr=0x" + hr.ToString("X8"), hr);
|
|
234
|
-
|
|
235
|
-
IntPtr vtable = Marshal.ReadIntPtr(factoryPtr);
|
|
236
|
-
IntPtr fn = Marshal.ReadIntPtr(vtable, 3 * IntPtr.Size);
|
|
237
|
-
var createForWindow = (CreateForWindowDelegate)Marshal.GetDelegateForFunctionPointer(fn, typeof(CreateForWindowDelegate));
|
|
238
|
-
|
|
239
|
-
Guid itemIid = new Guid("79C3F95B-31F7-4EC2-A464-632EF5D30760");
|
|
240
|
-
int hrItem = createForWindow(factoryPtr, hwnd, ref itemIid, out IntPtr itemPtr);
|
|
241
|
-
Marshal.Release(factoryPtr);
|
|
242
|
-
if (hrItem < 0) throw new COMException("CreateForWindow hr=0x" + hrItem.ToString("X8"), hrItem);
|
|
243
|
-
try { return (GraphicsCaptureItem)Marshal.GetObjectForIUnknown(itemPtr); }
|
|
244
|
-
finally { Marshal.Release(itemPtr); }
|
|
245
|
-
}
|
|
246
|
-
finally { WindowsDeleteString(hstr); }
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Drawing;
|
|
3
|
+
using System.Drawing.Imaging;
|
|
4
|
+
using System.Runtime.InteropServices;
|
|
5
|
+
using System.Threading;
|
|
6
|
+
using SharpDX.Direct3D;
|
|
7
|
+
using SharpDX.Direct3D11;
|
|
8
|
+
using SharpDX.DXGI;
|
|
9
|
+
using Windows.Graphics.Capture;
|
|
10
|
+
using Windows.Graphics.DirectX;
|
|
11
|
+
using Windows.Graphics.DirectX.Direct3D11;
|
|
12
|
+
using D3D11Device = SharpDX.Direct3D11.Device;
|
|
13
|
+
using D3D11Texture2D = SharpDX.Direct3D11.Texture2D;
|
|
14
|
+
using DXGIDevice = SharpDX.DXGI.Device;
|
|
15
|
+
|
|
16
|
+
namespace DshCuCapture
|
|
17
|
+
{
|
|
18
|
+
/// Windows.Graphics.Capture for .NET Framework 4.8 - the same API Codex uses,
|
|
19
|
+
/// with no .NET 8 runtime dependency (Framework 4.8 ships with Windows 10/11).
|
|
20
|
+
internal static class Program
|
|
21
|
+
{
|
|
22
|
+
[ComImport]
|
|
23
|
+
[Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
|
|
24
|
+
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
25
|
+
private interface IDirect3DDxgiInterfaceAccess
|
|
26
|
+
{
|
|
27
|
+
[PreserveSig] int GetInterface(ref Guid iid, out IntPtr result);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[DllImport("d3d11.dll", ExactSpelling = true)]
|
|
31
|
+
private static extern int CreateDirect3D11DeviceFromDXGIDevice(IntPtr dxgiDevice, out IntPtr graphicsDevice);
|
|
32
|
+
|
|
33
|
+
[DllImport("combase.dll", CharSet = CharSet.Unicode)]
|
|
34
|
+
private static extern int WindowsCreateString(string source, int length, out IntPtr hstring);
|
|
35
|
+
|
|
36
|
+
[DllImport("combase.dll")]
|
|
37
|
+
private static extern int RoGetActivationFactory(IntPtr activatableClassId, ref Guid iid, out IntPtr factory);
|
|
38
|
+
|
|
39
|
+
[DllImport("combase.dll")]
|
|
40
|
+
private static extern int WindowsDeleteString(IntPtr hstring);
|
|
41
|
+
|
|
42
|
+
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
|
|
43
|
+
private static extern void CopyMemory(IntPtr destination, IntPtr source, int length);
|
|
44
|
+
|
|
45
|
+
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
|
46
|
+
private delegate int CreateForWindowDelegate(IntPtr thisPtr, IntPtr hwnd, ref Guid iid, out IntPtr item);
|
|
47
|
+
private delegate int CreateForMonitorDelegate(IntPtr thisPtr, IntPtr hmon, ref Guid iid, out IntPtr item);
|
|
48
|
+
|
|
49
|
+
[DllImport("user32.dll")] private static extern IntPtr MonitorFromPoint(POINT pt, uint flags);
|
|
50
|
+
[StructLayout(LayoutKind.Sequential)] private struct POINT { public int X, Y; }
|
|
51
|
+
|
|
52
|
+
private static bool _suppressBorder = true;
|
|
53
|
+
|
|
54
|
+
private sealed class Slot
|
|
55
|
+
{
|
|
56
|
+
public Bitmap Bitmap;
|
|
57
|
+
public Exception Error;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private static int Main(string[] args)
|
|
61
|
+
{
|
|
62
|
+
long hwnd = 0;
|
|
63
|
+
bool monitor = false;
|
|
64
|
+
bool redactAll = false;
|
|
65
|
+
bool suppressBorder = true;
|
|
66
|
+
var redactRects = new System.Collections.Generic.List<System.Drawing.Rectangle>();
|
|
67
|
+
string output = "capture.png";
|
|
68
|
+
int timeoutMs = 2000;
|
|
69
|
+
for (int i = 0; i < args.Length - 1; i++)
|
|
70
|
+
{
|
|
71
|
+
if (args[i] == "--redact")
|
|
72
|
+
{
|
|
73
|
+
string[] parts = args[i + 1].Split(',');
|
|
74
|
+
if (parts.Length == 4)
|
|
75
|
+
redactRects.Add(new System.Drawing.Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])));
|
|
76
|
+
}
|
|
77
|
+
else if (args[i] == "--hwnd") long.TryParse(args[i + 1], out hwnd);
|
|
78
|
+
else if (args[i] == "--out") output = args[i + 1];
|
|
79
|
+
else if (args[i] == "--timeout") int.TryParse(args[i + 1], out timeoutMs);
|
|
80
|
+
}
|
|
81
|
+
for (int i = 0; i < args.Length; i++)
|
|
82
|
+
{
|
|
83
|
+
if (args[i] == "--monitor") monitor = true;
|
|
84
|
+
else if (args[i] == "--redact-all") redactAll = true;
|
|
85
|
+
else if (args[i] == "--keep-border") suppressBorder = false;
|
|
86
|
+
}
|
|
87
|
+
if (hwnd == 0 && !monitor) { Console.Error.WriteLine("--hwnd or --monitor is required"); return 2; }
|
|
88
|
+
|
|
89
|
+
try
|
|
90
|
+
{
|
|
91
|
+
GraphicsCaptureItem item = monitor ? CreateMonitorItem() : CreateItem(new IntPtr(hwnd));
|
|
92
|
+
using (D3D11Device device = new D3D11Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport))
|
|
93
|
+
using (DXGIDevice dxgi = device.QueryInterface<DXGIDevice>())
|
|
94
|
+
{
|
|
95
|
+
int hr = CreateDirect3D11DeviceFromDXGIDevice(dxgi.NativePointer, out IntPtr winrtDevicePtr);
|
|
96
|
+
if (hr < 0) { Console.Error.WriteLine("CreateDirect3D11DeviceFromDXGIDevice hr=0x" + hr.ToString("X8")); return 3; }
|
|
97
|
+
IDirect3DDevice winrtDevice;
|
|
98
|
+
try { winrtDevice = (IDirect3DDevice)Marshal.GetObjectForIUnknown(winrtDevicePtr); }
|
|
99
|
+
finally { Marshal.Release(winrtDevicePtr); }
|
|
100
|
+
|
|
101
|
+
_suppressBorder = suppressBorder;
|
|
102
|
+
var slot = new Slot();
|
|
103
|
+
using (var pool = Direct3D11CaptureFramePool.CreateFreeThreaded(
|
|
104
|
+
winrtDevice, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size))
|
|
105
|
+
using (var session = pool.CreateCaptureSession(item))
|
|
106
|
+
using (var done = new ManualResetEventSlim(false))
|
|
107
|
+
{
|
|
108
|
+
try { session.IsCursorCaptureEnabled = false; } catch { }
|
|
109
|
+
// Windows 11 draws a yellow frame around any captured window. Kill it
|
|
110
|
+
// (Codex does the same through its capture-border access path) so the
|
|
111
|
+
// border never shows up in the picture or on the user's desktop.
|
|
112
|
+
if (_suppressBorder) { try { session.IsBorderRequired = false; } catch { } }
|
|
113
|
+
|
|
114
|
+
Direct3D11CaptureFramePool owner = pool;
|
|
115
|
+
D3D11Device gpu = device;
|
|
116
|
+
pool.FrameArrived += (sender, e) =>
|
|
117
|
+
{
|
|
118
|
+
if (slot.Bitmap != null) return;
|
|
119
|
+
try
|
|
120
|
+
{
|
|
121
|
+
using (var frame = owner.TryGetNextFrame())
|
|
122
|
+
{
|
|
123
|
+
if (frame == null) return;
|
|
124
|
+
var access = (IDirect3DDxgiInterfaceAccess)frame.Surface;
|
|
125
|
+
Guid iid = new Guid("6f15aaf2-d208-4e89-9ab4-489535d34f9c"); // ID3D11Texture2D
|
|
126
|
+
IntPtr texPtr;
|
|
127
|
+
if (access.GetInterface(ref iid, out texPtr) < 0 || texPtr == IntPtr.Zero) return;
|
|
128
|
+
using (var texture = new D3D11Texture2D(texPtr))
|
|
129
|
+
{
|
|
130
|
+
var desc = texture.Description;
|
|
131
|
+
var stagingDesc = new Texture2DDescription
|
|
132
|
+
{
|
|
133
|
+
Width = desc.Width,
|
|
134
|
+
Height = desc.Height,
|
|
135
|
+
MipLevels = 1,
|
|
136
|
+
ArraySize = 1,
|
|
137
|
+
Format = desc.Format,
|
|
138
|
+
SampleDescription = new SampleDescription(1, 0),
|
|
139
|
+
Usage = ResourceUsage.Staging,
|
|
140
|
+
BindFlags = BindFlags.None,
|
|
141
|
+
CpuAccessFlags = CpuAccessFlags.Read,
|
|
142
|
+
OptionFlags = ResourceOptionFlags.None,
|
|
143
|
+
};
|
|
144
|
+
using (var staging = new D3D11Texture2D(gpu, stagingDesc))
|
|
145
|
+
{
|
|
146
|
+
var context = gpu.ImmediateContext;
|
|
147
|
+
context.CopyResource(texture, staging);
|
|
148
|
+
SharpDX.DataBox box = context.MapSubresource(staging, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
|
|
149
|
+
try
|
|
150
|
+
{
|
|
151
|
+
Bitmap bmp = new Bitmap(desc.Width, desc.Height, PixelFormat.Format32bppArgb);
|
|
152
|
+
BitmapData data = bmp.LockBits(new Rectangle(0, 0, desc.Width, desc.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
|
153
|
+
for (int y = 0; y < desc.Height; y++)
|
|
154
|
+
{
|
|
155
|
+
IntPtr src = IntPtr.Add(box.DataPointer, y * box.RowPitch);
|
|
156
|
+
IntPtr dst = IntPtr.Add(data.Scan0, y * data.Stride);
|
|
157
|
+
CopyMemory(dst, src, desc.Width * 4);
|
|
158
|
+
}
|
|
159
|
+
bmp.UnlockBits(data);
|
|
160
|
+
slot.Bitmap = bmp;
|
|
161
|
+
}
|
|
162
|
+
finally { context.UnmapSubresource(staging, 0); }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (Exception ex) { slot.Error = ex; }
|
|
168
|
+
finally { done.Set(); }
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
session.StartCapture();
|
|
172
|
+
done.Wait(timeoutMs);
|
|
173
|
+
try { session.Dispose(); } catch { }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (slot.Error != null) { Console.Error.WriteLine(slot.Error.GetType().Name + ": " + slot.Error.Message); return 6; }
|
|
177
|
+
if (slot.Bitmap == null) { Console.Error.WriteLine("no frame arrived (timeout or empty surface)"); return 4; }
|
|
178
|
+
|
|
179
|
+
if (redactAll || redactRects.Count > 0)
|
|
180
|
+
{
|
|
181
|
+
using (var g = Graphics.FromImage(slot.Bitmap))
|
|
182
|
+
{
|
|
183
|
+
g.Clear(redactAll ? Color.Black : Color.Transparent);
|
|
184
|
+
foreach (var rect in redactRects) g.FillRectangle(Brushes.Black, rect);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
int w = slot.Bitmap.Width, h = slot.Bitmap.Height;
|
|
188
|
+
slot.Bitmap.Save(output, ImageFormat.Png);
|
|
189
|
+
slot.Bitmap.Dispose();
|
|
190
|
+
Console.WriteLine("wgc " + w + "x" + h + " -> " + output);
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (Exception ex)
|
|
195
|
+
{
|
|
196
|
+
Console.Error.WriteLine(ex.GetType().Name + ": " + ex.Message);
|
|
197
|
+
return 5;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private static GraphicsCaptureItem CreateMonitorItem()
|
|
202
|
+
{
|
|
203
|
+
POINT origin = new POINT { X = 0, Y = 0 };
|
|
204
|
+
IntPtr monitorHandle = MonitorFromPoint(origin, 2); // MONITOR_DEFAULTTONEAREST
|
|
205
|
+
const string className = "Windows.Graphics.Capture.GraphicsCaptureItem";
|
|
206
|
+
WindowsCreateString(className, className.Length, out IntPtr hstr);
|
|
207
|
+
try
|
|
208
|
+
{
|
|
209
|
+
Guid interopIid = new Guid("3628E81B-3CAC-4C60-B7F4-23CE0E0C3356");
|
|
210
|
+
int hr = RoGetActivationFactory(hstr, ref interopIid, out IntPtr factoryPtr);
|
|
211
|
+
if (hr < 0) throw new COMException("RoGetActivationFactory hr=0x" + hr.ToString("X8"), hr);
|
|
212
|
+
IntPtr vtable = Marshal.ReadIntPtr(factoryPtr);
|
|
213
|
+
IntPtr fn = Marshal.ReadIntPtr(vtable, 4 * IntPtr.Size); // CreateForMonitor
|
|
214
|
+
var createForMonitor = (CreateForMonitorDelegate)Marshal.GetDelegateForFunctionPointer(fn, typeof(CreateForMonitorDelegate));
|
|
215
|
+
Guid itemIid = new Guid("79C3F95B-31F7-4EC2-A464-632EF5D30760");
|
|
216
|
+
int hrItem = createForMonitor(factoryPtr, monitorHandle, ref itemIid, out IntPtr itemPtr);
|
|
217
|
+
Marshal.Release(factoryPtr);
|
|
218
|
+
if (hrItem < 0) throw new COMException("CreateForMonitor hr=0x" + hrItem.ToString("X8"), hrItem);
|
|
219
|
+
try { return (GraphicsCaptureItem)Marshal.GetObjectForIUnknown(itemPtr); }
|
|
220
|
+
finally { Marshal.Release(itemPtr); }
|
|
221
|
+
}
|
|
222
|
+
finally { WindowsDeleteString(hstr); }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private static GraphicsCaptureItem CreateItem(IntPtr hwnd)
|
|
226
|
+
{
|
|
227
|
+
const string className = "Windows.Graphics.Capture.GraphicsCaptureItem";
|
|
228
|
+
WindowsCreateString(className, className.Length, out IntPtr hstr);
|
|
229
|
+
try
|
|
230
|
+
{
|
|
231
|
+
Guid interopIid = new Guid("3628E81B-3CAC-4C60-B7F4-23CE0E0C3356");
|
|
232
|
+
int hr = RoGetActivationFactory(hstr, ref interopIid, out IntPtr factoryPtr);
|
|
233
|
+
if (hr < 0) throw new COMException("RoGetActivationFactory hr=0x" + hr.ToString("X8"), hr);
|
|
234
|
+
|
|
235
|
+
IntPtr vtable = Marshal.ReadIntPtr(factoryPtr);
|
|
236
|
+
IntPtr fn = Marshal.ReadIntPtr(vtable, 3 * IntPtr.Size);
|
|
237
|
+
var createForWindow = (CreateForWindowDelegate)Marshal.GetDelegateForFunctionPointer(fn, typeof(CreateForWindowDelegate));
|
|
238
|
+
|
|
239
|
+
Guid itemIid = new Guid("79C3F95B-31F7-4EC2-A464-632EF5D30760");
|
|
240
|
+
int hrItem = createForWindow(factoryPtr, hwnd, ref itemIid, out IntPtr itemPtr);
|
|
241
|
+
Marshal.Release(factoryPtr);
|
|
242
|
+
if (hrItem < 0) throw new COMException("CreateForWindow hr=0x" + hrItem.ToString("X8"), hrItem);
|
|
243
|
+
try { return (GraphicsCaptureItem)Marshal.GetObjectForIUnknown(itemPtr); }
|
|
244
|
+
finally { Marshal.Release(itemPtr); }
|
|
245
|
+
}
|
|
246
|
+
finally { WindowsDeleteString(hstr); }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepseek-computer-use",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "在 DSH 中查看和操作 Windows 桌面软件,支持窗口截图、鼠标键盘与控件操作。 欢迎提交 issues 和 PR。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./lib/index.js",
|
|
9
9
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
10
|
-
"./package.json": "./package.json"
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
"./client": "./lib/update-client.js"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"lib",
|
|
@@ -20,23 +21,36 @@
|
|
|
20
21
|
"native/wgcfw/Capture.csproj",
|
|
21
22
|
"native/wgcfw/Program.cs",
|
|
22
23
|
"skills",
|
|
24
|
+
"assets/cover-whale-girl.png",
|
|
23
25
|
"cordis.patch.yml",
|
|
24
26
|
"README.md",
|
|
27
|
+
"CHANGELOG.md",
|
|
25
28
|
"LICENSE"
|
|
26
29
|
],
|
|
27
30
|
"scripts": {
|
|
28
|
-
"build": "node lib/build.mjs",
|
|
31
|
+
"build": "node lib/build.mjs && node scripts/build-updates.mjs",
|
|
29
32
|
"build:helper": "node lib/build.mjs",
|
|
30
|
-
"test": "node test/integration.mjs",
|
|
31
|
-
"test:
|
|
33
|
+
"test": "node scripts/build-updates.mjs && node --test test/contracts.test.mjs test/bridge.test.mjs && node test/integration.mjs",
|
|
34
|
+
"test:contracts": "node --test test/contracts.test.mjs test/bridge.test.mjs",
|
|
35
|
+
"test:harness": "node test/harness.mjs",
|
|
36
|
+
"test:all": "npm test && node test/parity.mjs && node test/parity-js.mjs"
|
|
32
37
|
},
|
|
33
38
|
"dsh": {
|
|
34
39
|
"bundle": {
|
|
35
40
|
"patch": "./cordis.patch.yml"
|
|
41
|
+
},
|
|
42
|
+
"client": {
|
|
43
|
+
"platform": "web",
|
|
44
|
+
"inject": [
|
|
45
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
46
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
47
|
+
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
48
|
+
]
|
|
36
49
|
}
|
|
37
50
|
},
|
|
38
51
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
52
|
+
"node": "^22.19.0 || >=24.0.0",
|
|
53
|
+
"dsh": ">=0.2.1-rc.3"
|
|
40
54
|
},
|
|
41
55
|
"keywords": [
|
|
42
56
|
"dsh",
|
|
@@ -64,5 +78,9 @@
|
|
|
64
78
|
],
|
|
65
79
|
"publishConfig": {
|
|
66
80
|
"access": "public"
|
|
67
|
-
}
|
|
81
|
+
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"@stardustlc/dsh-updates": "0.1.0"
|
|
84
|
+
},
|
|
85
|
+
"packageManager": "pnpm@11.7.0"
|
|
68
86
|
}
|
|
@@ -5,7 +5,8 @@ description: Drive Windows desktop apps through DSH Computer Use tools (UIA obse
|
|
|
5
5
|
|
|
6
6
|
# Computer Use (Windows)
|
|
7
7
|
|
|
8
|
-
The `deepseek-computer-use` plugin
|
|
8
|
+
The `deepseek-computer-use` plugin provides Windows desktop tools for DSH,
|
|
9
|
+
using window2-style action and observation semantics.
|
|
9
10
|
Prefer shell, files and web tools whenever they can do the job: GUI automation is
|
|
10
11
|
the slowest, most fragile option and it moves the user's real mouse and keyboard.
|
|
11
12
|
|
|
@@ -81,10 +82,12 @@ submit, publish, install, 删除, 卸载, 支付, 提交 …) asks for confirmat
|
|
|
81
82
|
|---|---|---|
|
|
82
83
|
| `stale_snapshot` | element indexes expired | `get_window_state include_text:true` again |
|
|
83
84
|
| `stale_screenshot` | coordinate screenshot expired | observe again and use the new id |
|
|
85
|
+
| `fresh_observation_required` | an earlier input or capture failed | observe again; discard every old index, screenshot id and coordinate before deciding the next action |
|
|
86
|
+
| `timeout` | the old helper was stopped and its snapshots discarded | take a fresh observation; never repeat an input whose outcome is unknown |
|
|
87
|
+
| `cancelled` / `turn_ended` | the active native request was stopped | stop issuing input and wait for a new turn |
|
|
84
88
|
| `window_gone` | app closed / handle changed | `list_windows` again |
|
|
85
89
|
| `window_minimized` | nothing to observe | `activate_window`, then observe |
|
|
86
90
|
| `focus_failed` | another window holds the foreground | stop, ask the user; do not retry in a loop |
|
|
87
91
|
| `screen_locked` | the desktop is locked (LockApp) | stop and ask the user to unlock |
|
|
88
92
|
| `hard_denied` | the surface is never automatable | tell the user, do not route around it |
|
|
89
|
-
| `turn_ended` | the turn is over | wait for the user to continue |
|
|
90
93
|
| empty tree | Electron/Canvas surface | observe with the screenshot and act by coordinates |
|