@copylee/dsh-computer-use 0.15.0 → 0.16.1
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/helper/Input.cs +17 -10
- package/helper/Native.cs +2 -0
- package/helper/Overlay.cs +62 -24
- package/helper/Program.cs +2 -1
- package/helper/Uia.cs +38 -0
- package/lib/client.js +45 -30
- package/lib/index.js +293 -10
- package/lib/types/client/accent.d.ts +8 -9
- package/lib/types/client/select.d.ts +1 -1
- package/lib/types/computer.d.ts +9 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/retention.d.ts +60 -0
- package/lib/types/screenshots.d.ts +14 -1
- package/lib/types/tools.d.ts +8 -1
- package/package.json +1 -1
package/helper/Input.cs
CHANGED
|
@@ -230,19 +230,17 @@ namespace DshComputerUse
|
|
|
230
230
|
int x1 = Args.Int(r, "x1", 0), y1 = Args.Int(r, "y1", 0), x2 = Args.Int(r, "x2", 0), y2 = Args.Int(r, "y2", 0);
|
|
231
231
|
uint down, up; Flags(Args.Str(r, "button", "left"), out down, out up);
|
|
232
232
|
Overlay.Dodge(x1, y1); Overlay.Dodge(x2, y2);
|
|
233
|
-
Move(x1, y1);
|
|
234
233
|
if (Overlay.ShowClickTarget) Overlay.MarkPointer(x1, y1, "拖动", 1200);
|
|
234
|
+
Move(x1, y1);
|
|
235
235
|
Thread.Sleep(40);
|
|
236
236
|
Send(new List<Native.INPUT> { Mouse(down, 0) });
|
|
237
237
|
try
|
|
238
238
|
{
|
|
239
239
|
Thread.Sleep(60);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
{
|
|
243
|
-
|
|
244
|
-
Thread.Sleep(12);
|
|
245
|
-
}
|
|
240
|
+
double dist = Math.Sqrt((double)(x2 - x1) * (x2 - x1) + (double)(y2 - y1) * (y2 - y1));
|
|
241
|
+
// Frame-paced, eased path; every step is a real move so the app sees the drag.
|
|
242
|
+
Overlay.AnimatePointer(x1, y1, x2, y2, Math.Max(240.0, Overlay.GlideDurationMs(dist) * 1.4), delegate(int ix, int iy) { Move(ix, iy); });
|
|
243
|
+
Move(x2, y2);
|
|
246
244
|
Thread.Sleep(60);
|
|
247
245
|
}
|
|
248
246
|
finally { Send(new List<Native.INPUT> { Mouse(up, 0) }); }
|
|
@@ -254,9 +252,18 @@ namespace DshComputerUse
|
|
|
254
252
|
{
|
|
255
253
|
int sx = 0, sy = 0;
|
|
256
254
|
bool hasPos = Args.Has(r, "x");
|
|
257
|
-
if (hasPos)
|
|
258
|
-
|
|
259
|
-
|
|
255
|
+
if (hasPos)
|
|
256
|
+
{
|
|
257
|
+
sx = Args.Int(r, "x", 0); sy = Args.Int(r, "y", 0); Overlay.Dodge(sx, sy);
|
|
258
|
+
// Glide first (the badge travels with the pointer), then the real move apps react to.
|
|
259
|
+
if (Overlay.ShowClickTarget) Overlay.MarkPointer(sx, sy, "滚动", 900);
|
|
260
|
+
Move(sx, sy); Thread.Sleep(30);
|
|
261
|
+
}
|
|
262
|
+
else
|
|
263
|
+
{
|
|
264
|
+
Native.POINT p; if (Native.GetCursorPos(out p)) { sx = p.X; sy = p.Y; }
|
|
265
|
+
if (Overlay.ShowClickTarget) Overlay.MarkPointer(sx, sy, "滚动", 900);
|
|
266
|
+
}
|
|
260
267
|
int dx = Args.Int(r, "dx", 0), dy = Args.Int(r, "dy", 0);
|
|
261
268
|
var mods = Args.Ints(r, "modifiers");
|
|
262
269
|
Modifiers(mods, false);
|
package/helper/Native.cs
CHANGED
|
@@ -53,6 +53,8 @@ namespace DshComputerUse
|
|
|
53
53
|
[DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, out bool pvParam, uint fWinIni);
|
|
54
54
|
[DllImport("winmm.dll")] public static extern uint timeBeginPeriod(uint uPeriod);
|
|
55
55
|
[DllImport("winmm.dll")] public static extern uint timeEndPeriod(uint uPeriod);
|
|
56
|
+
/** Blocks until the next DWM composition (vblank-locked frame pacing). */
|
|
57
|
+
[DllImport("dwmapi.dll")] public static extern int DwmFlush();
|
|
56
58
|
[StructLayout(LayoutKind.Sequential)]
|
|
57
59
|
public struct BITMAPINFOHEADER { public uint biSize; public int biWidth; public int biHeight; public ushort biPlanes; public ushort biBitCount; public uint biCompression; public uint biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public uint biClrUsed; public uint biClrImportant; }
|
|
58
60
|
[DllImport("gdi32.dll")] public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFOHEADER pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
|
package/helper/Overlay.cs
CHANGED
|
@@ -1111,7 +1111,12 @@ namespace DshComputerUse
|
|
|
1111
1111
|
PlaceMarkOnUi(latestMouseX, latestMouseY, cursorBadge, Accent, 0, false, false, true);
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
|
-
/**
|
|
1114
|
+
/**
|
|
1115
|
+
* Glide the OS cursor and the DSH badge to (x, y) together. Frames are
|
|
1116
|
+
* locked to the display's refresh (DwmFlush), positions follow a
|
|
1117
|
+
* minimum-jerk curve sampled from a stopwatch, and the duration grows
|
|
1118
|
+
* with the distance, so the pointer moves like a hand, not in steps.
|
|
1119
|
+
*/
|
|
1115
1120
|
public static void GlideMark(int x, int y, string text, Color color, int holdMs, bool capturable, bool ripple)
|
|
1116
1121
|
{
|
|
1117
1122
|
int startX, startY;
|
|
@@ -1119,35 +1124,68 @@ namespace DshComputerUse
|
|
|
1119
1124
|
if (Native.GetCursorPos(out cur)) { startX = cur.X; startY = cur.Y; }
|
|
1120
1125
|
else if (hasLastMark) { startX = lastMarkX; startY = lastMarkY; }
|
|
1121
1126
|
else { startX = x; startY = y; }
|
|
1122
|
-
|
|
1123
|
-
if (dist >= 24.0)
|
|
1127
|
+
AnimatePointer(startX, startY, x, y, 0, delegate(int ix, int iy)
|
|
1124
1128
|
{
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1129
|
+
try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
|
|
1130
|
+
Mark(ix, iy, text, color, holdMs, false, false);
|
|
1131
|
+
});
|
|
1132
|
+
try { Native.SetCursorPos(x, y); } catch (Exception) { }
|
|
1133
|
+
Mark(x, y, text, color, holdMs, false, false);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/** Glide duration for a move of `dist` pixels: short hops stay quick, long sweeps stay readable. */
|
|
1137
|
+
public static double GlideDurationMs(double dist)
|
|
1138
|
+
{
|
|
1139
|
+
return Math.Max(150.0, Math.Min(420.0, 110.0 + Math.Sqrt(dist) * 9.5));
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/** Minimum-jerk position profile (10t^3 - 15t^4 + 6t^5): zero velocity and acceleration at both ends. */
|
|
1143
|
+
public static double MinimumJerk(double t)
|
|
1144
|
+
{
|
|
1145
|
+
if (t <= 0) return 0;
|
|
1146
|
+
if (t >= 1) return 1;
|
|
1147
|
+
return t * t * t * (10.0 + t * (-15.0 + 6.0 * t));
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Drive `step` once per displayed frame from (x0, y0) to (x1, y1), stopping
|
|
1152
|
+
* just before the end (callers place the final point themselves).
|
|
1153
|
+
* durationMs <= 0 picks GlideDurationMs. Moves under 10 px are not animated.
|
|
1154
|
+
*/
|
|
1155
|
+
public static void AnimatePointer(int x0, int y0, int x1, int y1, double durationMs, Action<int, int> step)
|
|
1156
|
+
{
|
|
1157
|
+
double dist = Math.Sqrt((double)(x1 - x0) * (x1 - x0) + (double)(y1 - y0) * (y1 - y0));
|
|
1158
|
+
if (dist < 10.0) return;
|
|
1159
|
+
if (durationMs <= 0) durationMs = GlideDurationMs(dist);
|
|
1160
|
+
bool highRes = false;
|
|
1161
|
+
bool vsync = true;
|
|
1162
|
+
int lastX = x0, lastY = y0;
|
|
1163
|
+
try
|
|
1164
|
+
{
|
|
1165
|
+
highRes = Native.timeBeginPeriod(1) == 0;
|
|
1166
|
+
var sw = Stopwatch.StartNew();
|
|
1167
|
+
while (true)
|
|
1128
1168
|
{
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
while (true)
|
|
1169
|
+
// Wait for the next composed frame first, then place the pointer for that frame's time.
|
|
1170
|
+
if (vsync)
|
|
1132
1171
|
{
|
|
1133
|
-
|
|
1134
|
-
if (elapsed >= durationMs) break;
|
|
1135
|
-
double t = elapsed / durationMs;
|
|
1136
|
-
double ease = 1.0 - Math.Pow(1.0 - t, 3.0); // EaseOutCubic
|
|
1137
|
-
int ix = startX + (int)Math.Round((x - startX) * ease);
|
|
1138
|
-
int iy = startY + (int)Math.Round((y - startY) * ease);
|
|
1139
|
-
try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
|
|
1140
|
-
Mark(ix, iy, text, color, holdMs, false, false);
|
|
1141
|
-
Thread.Sleep(7);
|
|
1172
|
+
try { vsync = Native.DwmFlush() == 0; } catch (Exception) { vsync = false; }
|
|
1142
1173
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1174
|
+
if (!vsync) Thread.Sleep(4);
|
|
1175
|
+
double elapsed = sw.Elapsed.TotalMilliseconds;
|
|
1176
|
+
if (elapsed >= durationMs) break;
|
|
1177
|
+
double e = MinimumJerk(elapsed / durationMs);
|
|
1178
|
+
int ix = x0 + (int)Math.Round((x1 - x0) * e);
|
|
1179
|
+
int iy = y0 + (int)Math.Round((y1 - y0) * e);
|
|
1180
|
+
if (ix == lastX && iy == lastY) continue;
|
|
1181
|
+
lastX = ix; lastY = iy;
|
|
1182
|
+
step(ix, iy);
|
|
1147
1183
|
}
|
|
1148
1184
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1185
|
+
finally
|
|
1186
|
+
{
|
|
1187
|
+
if (highRes) { try { Native.timeEndPeriod(1); } catch (Exception) { } }
|
|
1188
|
+
}
|
|
1151
1189
|
}
|
|
1152
1190
|
|
|
1153
1191
|
static void ShowRestingMarkOnUi(int x, int y)
|
package/helper/Program.cs
CHANGED
|
@@ -179,8 +179,8 @@ namespace DshComputerUse
|
|
|
179
179
|
{
|
|
180
180
|
int mx = Args.Int(r, "x", 0), my = Args.Int(r, "y", 0);
|
|
181
181
|
Overlay.Dodge(mx, my);
|
|
182
|
-
Input.Move(mx, my);
|
|
183
182
|
if (Overlay.ShowClickTarget) Overlay.MarkPointer(mx, my, "DSH", 900);
|
|
183
|
+
Input.Move(mx, my);
|
|
184
184
|
}
|
|
185
185
|
return null;
|
|
186
186
|
case "click":
|
|
@@ -227,6 +227,7 @@ namespace DshComputerUse
|
|
|
227
227
|
case "ocr": return Ocr.Read(r);
|
|
228
228
|
case "marks": return Uia.Marks(r);
|
|
229
229
|
case "password_focus": return Uia.PasswordFocus();
|
|
230
|
+
case "focused_value": return Uia.FocusedValue(Math.Max(64, Math.Min(20000, Args.Int(r, "maxChars", 4000))));
|
|
230
231
|
case "ui_point_click": return Uia.ClickAtPoint(r);
|
|
231
232
|
case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
|
|
232
233
|
case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
|
package/helper/Uia.cs
CHANGED
|
@@ -815,6 +815,44 @@ namespace DshComputerUse
|
|
|
815
815
|
return d;
|
|
816
816
|
}
|
|
817
817
|
|
|
818
|
+
/**
|
|
819
|
+
* The focused control's ValuePattern value (capped), so a `type` can be checked
|
|
820
|
+
* against what the field now holds. Never reads password fields.
|
|
821
|
+
*/
|
|
822
|
+
public static object FocusedValue(int maxChars)
|
|
823
|
+
{
|
|
824
|
+
bool readable = false;
|
|
825
|
+
string value = "", role = "", name = "";
|
|
826
|
+
var worker = new Thread(delegate ()
|
|
827
|
+
{
|
|
828
|
+
try
|
|
829
|
+
{
|
|
830
|
+
var focused = AutomationElement.FocusedElement;
|
|
831
|
+
if (focused == null || IsPasswordElement(focused)) return;
|
|
832
|
+
role = focused.Current.ControlType.ProgrammaticName.Replace("ControlType.", "");
|
|
833
|
+
name = focused.Current.Name ?? "";
|
|
834
|
+
object pattern;
|
|
835
|
+
if (focused.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
|
|
836
|
+
{
|
|
837
|
+
string v = ((ValuePattern)pattern).Current.Value ?? "";
|
|
838
|
+
value = v.Length > maxChars ? v.Substring(v.Length - maxChars) : v;
|
|
839
|
+
readable = true;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
catch (Exception) { }
|
|
843
|
+
});
|
|
844
|
+
worker.IsBackground = true;
|
|
845
|
+
worker.SetApartmentState(ApartmentState.MTA);
|
|
846
|
+
worker.Start();
|
|
847
|
+
worker.Join(800);
|
|
848
|
+
var d = new Dictionary<string, object>();
|
|
849
|
+
d["readable"] = readable;
|
|
850
|
+
d["value"] = readable ? value : "";
|
|
851
|
+
d["role"] = role;
|
|
852
|
+
d["name"] = name.Length > 60 ? name.Substring(0, 60) : name;
|
|
853
|
+
return d;
|
|
854
|
+
}
|
|
855
|
+
|
|
818
856
|
/** Lightweight bounded lookup of the UIA control at physical point (x, y) for user-takeover feedback. */
|
|
819
857
|
public static void DescribeAtPoint(int x, int y, out string role, out string name, out bool isPassword)
|
|
820
858
|
{
|
package/lib/client.js
CHANGED
|
@@ -80,6 +80,7 @@ window.__ModuleLoader__.load({
|
|
|
80
80
|
maxLongEdge: 1366,
|
|
81
81
|
maxPixels: 115e4,
|
|
82
82
|
jpegQuality: 70,
|
|
83
|
+
keepScreenshots: 2,
|
|
83
84
|
blockedApps: [],
|
|
84
85
|
pauseOnUserInput: true,
|
|
85
86
|
reportUserActions: true,
|
|
@@ -122,6 +123,7 @@ window.__ModuleLoader__.load({
|
|
|
122
123
|
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
123
124
|
maxPixels: num("maxPixels", 3e5, 8e6),
|
|
124
125
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
126
|
+
keepScreenshots: num("keepScreenshots", 0, 20),
|
|
125
127
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
126
128
|
reportUserActions: bool("reportUserActions"),
|
|
127
129
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
@@ -140,17 +142,20 @@ window.__ModuleLoader__.load({
|
|
|
140
142
|
//#endregion
|
|
141
143
|
//#region lib/types/client/accent.js
|
|
142
144
|
/**
|
|
143
|
-
*
|
|
145
|
+
* This plugin's own accent colour (settings page, composer pill).
|
|
144
146
|
*
|
|
145
|
-
* One choice —
|
|
146
|
-
* browser under a key
|
|
147
|
-
* `<body
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* This file is identical in every plugin; change it in all of them together.
|
|
147
|
+
* One choice — black by default, terracotta orange or blue — is kept in the
|
|
148
|
+
* browser under a key only this plugin reads, and painted as two CSS
|
|
149
|
+
* variables on `<body>` that only this plugin's styles use
|
|
150
|
+
* (`var(--dshcu-accent)` / `var(--dshcu-accent-ink)`). Changing it here does
|
|
151
|
+
* not recolour the other copylee plugins, and theirs does not recolour this one.
|
|
152
152
|
*/
|
|
153
153
|
const ACCENTS = {
|
|
154
|
+
black: {
|
|
155
|
+
name: "黑色",
|
|
156
|
+
accent: "var(--dsw-alias-label-primary, #1F1E1D)",
|
|
157
|
+
ink: "var(--dsw-alias-bg-base, #FFFFFF)"
|
|
158
|
+
},
|
|
154
159
|
orange: {
|
|
155
160
|
name: "陶土橙",
|
|
156
161
|
accent: "#D97757",
|
|
@@ -160,20 +165,15 @@ window.__ModuleLoader__.load({
|
|
|
160
165
|
name: "蓝色",
|
|
161
166
|
accent: "#3D63E6",
|
|
162
167
|
ink: "#FFFFFF"
|
|
163
|
-
},
|
|
164
|
-
black: {
|
|
165
|
-
name: "黑色",
|
|
166
|
-
accent: "var(--dsw-alias-label-primary, #1F1E1D)",
|
|
167
|
-
ink: "var(--dsw-alias-bg-base, #FFFFFF)"
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
170
|
const ACCENT_IDS = Object.keys(ACCENTS);
|
|
171
|
-
const DEFAULT_ACCENT = "
|
|
171
|
+
const DEFAULT_ACCENT = "black";
|
|
172
172
|
/** Use these in styles; the fallbacks cover the moment before the first paint. */
|
|
173
|
-
const ACCENT = `var(--
|
|
174
|
-
const ACCENT_INK = `var(--
|
|
175
|
-
const KEY = "copylee.dsh.accent";
|
|
176
|
-
const EVENT = "
|
|
173
|
+
const ACCENT = `var(--dshcu-accent, ${ACCENTS[DEFAULT_ACCENT].accent})`;
|
|
174
|
+
const ACCENT_INK = `var(--dshcu-accent-ink, ${ACCENTS[DEFAULT_ACCENT].ink})`;
|
|
175
|
+
const KEY = "copylee.dsh.computer-use.accent";
|
|
176
|
+
const EVENT = "dsh-computer-use-accent";
|
|
177
177
|
function isAccent(value) {
|
|
178
178
|
return typeof value === "string" && Object.hasOwn(ACCENTS, value);
|
|
179
179
|
}
|
|
@@ -187,14 +187,14 @@ window.__ModuleLoader__.load({
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
function readAccent() {
|
|
190
|
-
return storedAccent() ?? "
|
|
190
|
+
return storedAccent() ?? "black";
|
|
191
191
|
}
|
|
192
192
|
function paint() {
|
|
193
193
|
const colors = ACCENTS[readAccent()];
|
|
194
|
-
document.body?.style.setProperty("--
|
|
195
|
-
document.body?.style.setProperty("--
|
|
194
|
+
document.body?.style.setProperty("--dshcu-accent", colors.accent);
|
|
195
|
+
document.body?.style.setProperty("--dshcu-accent-ink", colors.ink);
|
|
196
196
|
}
|
|
197
|
-
/** Choose
|
|
197
|
+
/** Choose this plugin's accent. */
|
|
198
198
|
function writeAccent(accent) {
|
|
199
199
|
try {
|
|
200
200
|
localStorage.setItem(KEY, accent);
|
|
@@ -207,11 +207,16 @@ window.__ModuleLoader__.load({
|
|
|
207
207
|
if (typeof document === "undefined") return () => {};
|
|
208
208
|
paint();
|
|
209
209
|
if (document.body === null) document.addEventListener("DOMContentLoaded", paint, { once: true });
|
|
210
|
+
const onStorage = (event) => {
|
|
211
|
+
if (event.key === null || event.key === KEY) paint();
|
|
212
|
+
};
|
|
210
213
|
window.addEventListener(EVENT, paint);
|
|
211
|
-
window.addEventListener("storage",
|
|
214
|
+
window.addEventListener("storage", onStorage);
|
|
212
215
|
return () => {
|
|
216
|
+
document.body?.style.removeProperty("--dshcu-accent");
|
|
217
|
+
document.body?.style.removeProperty("--dshcu-accent-ink");
|
|
213
218
|
window.removeEventListener(EVENT, paint);
|
|
214
|
-
window.removeEventListener("storage",
|
|
219
|
+
window.removeEventListener("storage", onStorage);
|
|
215
220
|
};
|
|
216
221
|
}
|
|
217
222
|
function useAccent() {
|
|
@@ -527,14 +532,14 @@ window.__ModuleLoader__.load({
|
|
|
527
532
|
const selectCss = `
|
|
528
533
|
@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}
|
|
529
534
|
.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,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}
|
|
530
|
-
.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--
|
|
531
|
-
.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--
|
|
535
|
+
.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}
|
|
536
|
+
.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--dshcu-accent,#1F1E1D);box-shadow:0 0 0 3px color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 20%,transparent)}
|
|
532
537
|
.dshcu-select:disabled{opacity:.48;cursor:default}
|
|
533
538
|
.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}
|
|
534
539
|
.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));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 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}
|
|
535
540
|
.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}
|
|
536
541
|
.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}
|
|
537
|
-
.dshcu-option[aria-selected=true]{font-weight:500;color:var(--
|
|
542
|
+
.dshcu-option[aria-selected=true]{font-weight:500;color:var(--dshcu-accent,#1F1E1D)}
|
|
538
543
|
`;
|
|
539
544
|
function Select({ options, value, disabled, label, onChange }) {
|
|
540
545
|
const id = react.useId();
|
|
@@ -705,7 +710,7 @@ window.__ModuleLoader__.load({
|
|
|
705
710
|
.dshcu-skill-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));border-color:var(--dsw-alias-border-l2,rgba(127,127,127,.18))}
|
|
706
711
|
.dshcu-chip-tab{padding:4px 10px;border-radius:999px;font-size:12px;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#666);transition:background .15s ease,color .15s ease,border-color .15s ease}
|
|
707
712
|
.dshcu-chip-tab:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
|
|
708
|
-
.dshcu-chip-tab[data-active="true"]{background:var(--dshcu-accent
|
|
713
|
+
.dshcu-chip-tab[data-active="true"]{background:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 12%,transparent);color:var(--dshcu-accent,#1F1E1D);border-color:var(--dshcu-accent,#1F1E1D);font-weight:600}
|
|
709
714
|
.dshcu-modal-backdrop{position:fixed;inset:0;z-index:9999;background:rgba(15,15,18,.48);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:20px;animation:dshcu-backdrop-in .16s ease}
|
|
710
715
|
.dshcu-modal{width:min(640px,100%);max-height:min(86vh,720px);display:flex;flex-direction:column;border-radius:16px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));box-shadow:0 24px 64px rgba(0,0,0,.28);overflow:hidden;animation:dshcu-modal-in .18s cubic-bezier(.16,1,.3,1)}
|
|
711
716
|
`;
|
|
@@ -1254,6 +1259,7 @@ window.__ModuleLoader__.load({
|
|
|
1254
1259
|
maxLongEdge: String(s.maxLongEdge),
|
|
1255
1260
|
maxMegapixels: String(Math.round(s.maxPixels / 1e4) / 100),
|
|
1256
1261
|
jpegQuality: String(s.jpegQuality),
|
|
1262
|
+
keepScreenshots: String(s.keepScreenshots),
|
|
1257
1263
|
elementFirstClick: s.elementFirstClick,
|
|
1258
1264
|
restorePointer: s.restorePointer,
|
|
1259
1265
|
protectPasswords: s.protectPasswords,
|
|
@@ -1274,6 +1280,7 @@ window.__ModuleLoader__.load({
|
|
|
1274
1280
|
check("maxLongEdge", 640, 3840);
|
|
1275
1281
|
check("maxMegapixels", .3, 8);
|
|
1276
1282
|
check("jpegQuality", 30, 100);
|
|
1283
|
+
check("keepScreenshots", 0, 20);
|
|
1277
1284
|
check("cdpPort", 0, 65535);
|
|
1278
1285
|
return errors;
|
|
1279
1286
|
}
|
|
@@ -1299,6 +1306,7 @@ window.__ModuleLoader__.load({
|
|
|
1299
1306
|
maxLongEdge: Math.round(Number(d.maxLongEdge)),
|
|
1300
1307
|
maxPixels: Math.round(Number(d.maxMegapixels) * 1e6),
|
|
1301
1308
|
jpegQuality: Math.round(Number(d.jpegQuality)),
|
|
1309
|
+
keepScreenshots: Math.round(Number(d.keepScreenshots)),
|
|
1302
1310
|
elementFirstClick: d.elementFirstClick,
|
|
1303
1311
|
restorePointer: d.restorePointer,
|
|
1304
1312
|
protectPasswords: d.protectPasswords,
|
|
@@ -2052,14 +2060,21 @@ window.__ModuleLoader__.load({
|
|
|
2052
2060
|
error: errors.jpegQuality,
|
|
2053
2061
|
disabled,
|
|
2054
2062
|
onChange: (value) => edit("jpegQuality", value)
|
|
2055
|
-
})), liveShot ? h("div", { className: "dshcu-metric-bar" }, h("strong", null, `主屏实际输出 ${liveShot.width}×${liveShot.height}`), h("span", { style: S.hint }, `${liveShot.megapixels} MP · ${limitLabel(liveShot.limitedBy)}${liveCompactShot ? ` | 紧凑档 ${liveCompactShot.width}×${liveCompactShot.height}(${liveCompactShot.megapixels} MP)` : ""}`)) : h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。最长边与总像素上限同时生效,取更紧的一项。")), h(SkillsCard, { S }), h("section", { className: "dshcu-card" }, h("div", { style: S.cardHeader }, h("h3", { style: S.cardTitle }, "截图缓存")), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)}
|
|
2063
|
+
})), liveShot ? h("div", { className: "dshcu-metric-bar" }, h("strong", null, `主屏实际输出 ${liveShot.width}×${liveShot.height}`), h("span", { style: S.hint }, `${liveShot.megapixels} MP · ${limitLabel(liveShot.limitedBy)}${liveCompactShot ? ` | 紧凑档 ${liveCompactShot.width}×${liveCompactShot.height}(${liveCompactShot.megapixels} MP)` : ""}`)) : h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。最长边与总像素上限同时生效,取更紧的一项。")), h(SkillsCard, { S }), h("section", { className: "dshcu-card" }, h("div", { style: S.cardHeader }, h("h3", { style: S.cardTitle }, "截图缓存")), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})已不再需要(已被新截图替换或所属会话已删除),可以安全清理。`), h("div", { style: S.grid2 }, h(NumberField, {
|
|
2064
|
+
label: "对话里保留的截图",
|
|
2065
|
+
unit: "张(0 = 全部保留)",
|
|
2066
|
+
value: draft.keepScreenshots,
|
|
2067
|
+
error: errors.keepScreenshots,
|
|
2068
|
+
disabled,
|
|
2069
|
+
onChange: (value) => edit("keepScreenshots", value)
|
|
2070
|
+
})), h("p", { style: S.hint }, "模型每次请求都会重发对话里所有截图。这里只保留最近几张,更早的换成一行文字占位(省 token),文件在几分钟后自动删除;已删除会话的截图在启动后及每 12 小时清理。"), h("div", { style: S.actions }, h("button", {
|
|
2056
2071
|
type: "button",
|
|
2057
2072
|
className: "dshcu-btn",
|
|
2058
2073
|
disabled: cacheBusy || !cache?.orphans,
|
|
2059
2074
|
onClick: () => {
|
|
2060
2075
|
cleanCache();
|
|
2061
2076
|
}
|
|
2062
|
-
}, "
|
|
2077
|
+
}, "立即清理不再需要的截图"), h("button", {
|
|
2063
2078
|
type: "button",
|
|
2064
2079
|
className: "dshcu-btn",
|
|
2065
2080
|
disabled: cacheBusy,
|
package/lib/index.js
CHANGED
|
@@ -1768,6 +1768,14 @@ const MUTATING = /* @__PURE__ */ new Set([
|
|
|
1768
1768
|
"mouse_move",
|
|
1769
1769
|
"ui_action"
|
|
1770
1770
|
]);
|
|
1771
|
+
/** Whitespace-insensitive tail of typed text, as it should appear in the field afterwards. */
|
|
1772
|
+
function typedTextLanded(typed, fieldValue) {
|
|
1773
|
+
const norm = (v) => v.replace(/\s+/g, "");
|
|
1774
|
+
const want = norm(typed);
|
|
1775
|
+
if (want === "") return true;
|
|
1776
|
+
const tail = want.length > 24 ? want.slice(-24) : want;
|
|
1777
|
+
return norm(fieldValue).includes(tail);
|
|
1778
|
+
}
|
|
1771
1779
|
/** Actions that wait for the user to stop typing before they run. */
|
|
1772
1780
|
const INPUT = new Set([...MUTATING].filter((action) => action !== "mouse_move"));
|
|
1773
1781
|
/** Actions whose input goes to the foreground window. */
|
|
@@ -2741,6 +2749,22 @@ var Computer = class Computer {
|
|
|
2741
2749
|
}
|
|
2742
2750
|
return `\nRecent user actions during takeover (screenshot coordinates):\n${lines.join("\n")}\nRespect what the user just did and adapt your plan accordingly (do not undo or overwrite their changes).`;
|
|
2743
2751
|
}
|
|
2752
|
+
/** Compare the focused field with what was just typed (ValuePattern only; rich editors report 'sent'). */
|
|
2753
|
+
async readBackTyped(text) {
|
|
2754
|
+
const field = await this.helper.call("focused_value", { maxChars: Math.min(2e4, text.length + 4e3) }, 1500).catch(() => null);
|
|
2755
|
+
if (!field?.readable) return {
|
|
2756
|
+
verification: "sent",
|
|
2757
|
+
note: ""
|
|
2758
|
+
};
|
|
2759
|
+
if (typedTextLanded(text, field.value ?? "")) return {
|
|
2760
|
+
verification: "observed",
|
|
2761
|
+
note: " Verified: the focused field contains it."
|
|
2762
|
+
};
|
|
2763
|
+
return {
|
|
2764
|
+
verification: "unconfirmed",
|
|
2765
|
+
note: ` Unconfirmed: the focused ${`${field.role || "field"}${field.name ? ` "${field.name.slice(0, 40)}"` : ""}`} does not show the typed text (autocomplete, an input method or a different focus may have taken it). Check before continuing.`
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2744
2768
|
/** Run one action. Returns text plus an image for screenshot/zoom. */
|
|
2745
2769
|
async run(input, call) {
|
|
2746
2770
|
if (call.signal.aborted) throw new Error("Cancelled.");
|
|
@@ -2998,7 +3022,12 @@ var Computer = class Computer {
|
|
|
2998
3022
|
await this.sendKeys(call, parseKeys("ctrl+a"));
|
|
2999
3023
|
await setTimeout$1(50, void 0, { signal: call.signal });
|
|
3000
3024
|
}
|
|
3001
|
-
|
|
3025
|
+
const entered = `${await this.enterText(text, call)}${input.replace === true ? " (replaced existing text)" : ""}${into}`;
|
|
3026
|
+
const check = await this.readBackTyped(text);
|
|
3027
|
+
return {
|
|
3028
|
+
text: `${entered}${check.note}`,
|
|
3029
|
+
verification: check.verification
|
|
3030
|
+
};
|
|
3002
3031
|
}
|
|
3003
3032
|
case "key": {
|
|
3004
3033
|
const combos = parseKeys(input.text ?? "");
|
|
@@ -4131,6 +4160,7 @@ const DEFAULTS = {
|
|
|
4131
4160
|
maxLongEdge: 1366,
|
|
4132
4161
|
maxPixels: 115e4,
|
|
4133
4162
|
jpegQuality: 70,
|
|
4163
|
+
keepScreenshots: 2,
|
|
4134
4164
|
blockedApps: [],
|
|
4135
4165
|
pauseOnUserInput: true,
|
|
4136
4166
|
reportUserActions: true,
|
|
@@ -4173,6 +4203,7 @@ function resolveConfig(raw) {
|
|
|
4173
4203
|
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
4174
4204
|
maxPixels: num("maxPixels", 3e5, 8e6),
|
|
4175
4205
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
4206
|
+
keepScreenshots: num("keepScreenshots", 0, 20),
|
|
4176
4207
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
4177
4208
|
reportUserActions: bool("reportUserActions"),
|
|
4178
4209
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
@@ -4648,13 +4679,17 @@ function windowsRoute(helper) {
|
|
|
4648
4679
|
* DeepSeek Harness's content-addressed store (<DSH_HOME>/attachments/v1/objects/<2>/<sha256>),
|
|
4649
4680
|
* which has no retention policy yet. Attachments still referenced by a session
|
|
4650
4681
|
* must stay byte-for-byte (DSH verifies their hash, and a missing one fails the
|
|
4651
|
-
* whole turn), so only
|
|
4652
|
-
* no session, archive or plugin store references
|
|
4653
|
-
* was deleted)
|
|
4682
|
+
* whole turn), so only screenshots no request can need any more are removed:
|
|
4683
|
+
* ones this plugin made that no session, archive or plugin store references
|
|
4684
|
+
* (e.g. the session was deleted), and ones whose every occurrence in the
|
|
4685
|
+
* session logs was offloaded (`image/offload`, see retention.ts): an offloaded
|
|
4686
|
+
* image is sent as a text placeholder, so its bytes are never read again.
|
|
4654
4687
|
*/
|
|
4655
4688
|
const HEX = /^[0-9a-f]{64}$/;
|
|
4656
4689
|
/** Newly saved screenshots may not be in a session log yet. */
|
|
4657
4690
|
const GRACE_MS = 864e5;
|
|
4691
|
+
/** A screenshot seen offloaded is still left alone this long after it was (last) saved. */
|
|
4692
|
+
const OFFLOADED_MIN_AGE_MS = 12e4;
|
|
4658
4693
|
/** Places outside the session logs that can reference attachments. */
|
|
4659
4694
|
const OTHER_REFERENCE_DIRS = [
|
|
4660
4695
|
"storages",
|
|
@@ -4670,6 +4705,9 @@ var ScreenshotCache = class {
|
|
|
4670
4705
|
index;
|
|
4671
4706
|
saving = Promise.resolve();
|
|
4672
4707
|
busy = Promise.resolve();
|
|
4708
|
+
/** Parsed session logs keyed by path, reused while their size and mtime stay the same. */
|
|
4709
|
+
files = /* @__PURE__ */ new Map();
|
|
4710
|
+
soon;
|
|
4673
4711
|
constructor(dshHome = process.env.DSH_HOME || join(homedir(), ".dsh"), indexFile = join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "dsh-computer-use", "screenshots.json"), log = () => {}) {
|
|
4674
4712
|
this.dshHome = dshHome;
|
|
4675
4713
|
this.indexFile = indexFile;
|
|
@@ -4713,7 +4751,20 @@ var ScreenshotCache = class {
|
|
|
4713
4751
|
};
|
|
4714
4752
|
});
|
|
4715
4753
|
}
|
|
4716
|
-
/**
|
|
4754
|
+
/** Run `clean()` once, `delayMs` after the last call (screenshots were just offloaded). */
|
|
4755
|
+
cleanSoon(delayMs = 18e4) {
|
|
4756
|
+
if (this.soon) clearTimeout(this.soon);
|
|
4757
|
+
this.soon = setTimeout(() => {
|
|
4758
|
+
this.soon = void 0;
|
|
4759
|
+
this.clean().catch((error) => this.log(`screenshot cleanup skipped: ${String(error)}`));
|
|
4760
|
+
}, delayMs);
|
|
4761
|
+
this.soon.unref?.();
|
|
4762
|
+
}
|
|
4763
|
+
dispose() {
|
|
4764
|
+
if (this.soon) clearTimeout(this.soon);
|
|
4765
|
+
this.soon = void 0;
|
|
4766
|
+
}
|
|
4767
|
+
/** Delete screenshots no request can need any more. */
|
|
4717
4768
|
async clean() {
|
|
4718
4769
|
return this.exclusive(async () => {
|
|
4719
4770
|
const { orphans } = await this.classify();
|
|
@@ -4735,7 +4786,7 @@ var ScreenshotCache = class {
|
|
|
4735
4786
|
}
|
|
4736
4787
|
this.persist();
|
|
4737
4788
|
await this.saving;
|
|
4738
|
-
if (removed > 0) this.log(`screenshot cleanup: removed ${removed}
|
|
4789
|
+
if (removed > 0) this.log(`screenshot cleanup: removed ${removed} screenshots (${(bytes / 1048576).toFixed(1)} MB)`);
|
|
4739
4790
|
return {
|
|
4740
4791
|
removed,
|
|
4741
4792
|
bytes
|
|
@@ -4756,7 +4807,7 @@ var ScreenshotCache = class {
|
|
|
4756
4807
|
const orphans = /* @__PURE__ */ new Set();
|
|
4757
4808
|
for (const [hex, savedAt] of index) {
|
|
4758
4809
|
if (scan.referenced.has(hex)) continue;
|
|
4759
|
-
if (savedAt > 0
|
|
4810
|
+
if ((savedAt > 0 ? now - savedAt : Infinity) < (scan.offloaded.has(hex) ? OFFLOADED_MIN_AGE_MS : GRACE_MS)) continue;
|
|
4760
4811
|
orphans.add(hex);
|
|
4761
4812
|
}
|
|
4762
4813
|
return {
|
|
@@ -4770,19 +4821,52 @@ var ScreenshotCache = class {
|
|
|
4770
4821
|
if (typeof zstd !== "function") throw new Error("This runtime cannot read DeepSeek Harness session logs (no zstd); cleanup skipped.");
|
|
4771
4822
|
const referenced = /* @__PURE__ */ new Set();
|
|
4772
4823
|
const ours = /* @__PURE__ */ new Set();
|
|
4824
|
+
const offloaded = /* @__PURE__ */ new Set();
|
|
4825
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4826
|
+
const merge = (part) => {
|
|
4827
|
+
for (const hex of part.referenced) referenced.add(hex);
|
|
4828
|
+
for (const hex of part.ours) ours.add(hex);
|
|
4829
|
+
for (const hex of part.offloaded) offloaded.add(hex);
|
|
4830
|
+
};
|
|
4773
4831
|
const sessions = join(this.dshHome, "sessions");
|
|
4774
4832
|
for (const file of await walk(sessions)) {
|
|
4833
|
+
seen.add(file);
|
|
4834
|
+
let info;
|
|
4835
|
+
try {
|
|
4836
|
+
info = await stat(file);
|
|
4837
|
+
} catch {
|
|
4838
|
+
continue;
|
|
4839
|
+
}
|
|
4840
|
+
const cached = this.files.get(file);
|
|
4841
|
+
if (cached && cached.mtimeMs === info.mtimeMs && cached.size === info.size) {
|
|
4842
|
+
merge(cached);
|
|
4843
|
+
continue;
|
|
4844
|
+
}
|
|
4775
4845
|
const text = await readText(file, zstd);
|
|
4776
4846
|
if (text === void 0) throw new Error(`Could not read ${file}; cleanup skipped to stay safe.`);
|
|
4777
|
-
|
|
4847
|
+
const part = {
|
|
4848
|
+
referenced: /* @__PURE__ */ new Set(),
|
|
4849
|
+
ours: /* @__PURE__ */ new Set(),
|
|
4850
|
+
offloaded: /* @__PURE__ */ new Set()
|
|
4851
|
+
};
|
|
4852
|
+
collectLog(text, part.referenced, part.ours, part.offloaded);
|
|
4853
|
+
this.files.set(file, {
|
|
4854
|
+
...part,
|
|
4855
|
+
mtimeMs: info.mtimeMs,
|
|
4856
|
+
size: info.size
|
|
4857
|
+
});
|
|
4858
|
+
merge(part);
|
|
4778
4859
|
}
|
|
4860
|
+
for (const file of this.files.keys()) if (!seen.has(file)) this.files.delete(file);
|
|
4779
4861
|
for (const dir of OTHER_REFERENCE_DIRS) for (const file of await walk(join(this.dshHome, dir))) {
|
|
4780
4862
|
const text = await readText(file, zstd);
|
|
4781
4863
|
if (text !== void 0) collect(text, referenced, ours);
|
|
4782
4864
|
}
|
|
4865
|
+
for (const hex of referenced) offloaded.delete(hex);
|
|
4783
4866
|
return {
|
|
4784
4867
|
referenced,
|
|
4785
|
-
ours
|
|
4868
|
+
ours,
|
|
4869
|
+
offloaded
|
|
4786
4870
|
};
|
|
4787
4871
|
}
|
|
4788
4872
|
async size(hex) {
|
|
@@ -4829,6 +4913,72 @@ function collect(text, referenced, ours) {
|
|
|
4829
4913
|
for (const match of line.matchAll(/"attachmentId":"sha256:([0-9a-f]{64})"[^{}]*?"name":"screenshot\.jpg"/g)) ours.add(match[1]);
|
|
4830
4914
|
}
|
|
4831
4915
|
}
|
|
4916
|
+
const SHA = /sha256:([0-9a-f]{64})/g;
|
|
4917
|
+
function contentOf(event) {
|
|
4918
|
+
const data = event.data;
|
|
4919
|
+
const content = event.type === "tool/result" ? data?.message?.content : event.type === "user/message" ? data?.content : void 0;
|
|
4920
|
+
return Array.isArray(content) ? content : void 0;
|
|
4921
|
+
}
|
|
4922
|
+
/**
|
|
4923
|
+
* Read one session log. An image occurrence (message seq, top-level image
|
|
4924
|
+
* index) named by an `image/offload` event is offloaded; every other mention
|
|
4925
|
+
* of an attachment, in any event, keeps it referenced. Lines that do not parse
|
|
4926
|
+
* keep everything they mention.
|
|
4927
|
+
*/
|
|
4928
|
+
function collectLog(text, referenced, ours, offloaded) {
|
|
4929
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
4930
|
+
const marks = /* @__PURE__ */ new Set();
|
|
4931
|
+
for (const line of text.split("\n")) {
|
|
4932
|
+
const mentionsAttachment = line.includes("sha256:");
|
|
4933
|
+
if (!mentionsAttachment && !line.includes("\"image/offload\"")) continue;
|
|
4934
|
+
let event;
|
|
4935
|
+
try {
|
|
4936
|
+
event = JSON.parse(line);
|
|
4937
|
+
} catch {
|
|
4938
|
+
for (const match of line.matchAll(SHA)) referenced.add(match[1]);
|
|
4939
|
+
continue;
|
|
4940
|
+
}
|
|
4941
|
+
if (event.type === "image/offload") {
|
|
4942
|
+
const targets = event.data?.targets;
|
|
4943
|
+
if (Array.isArray(targets)) for (const target of targets) {
|
|
4944
|
+
if (typeof target?.seq !== "number" || !Array.isArray(target.imageIndexes)) continue;
|
|
4945
|
+
for (const index of target.imageIndexes) if (typeof index === "number") marks.add(`${target.seq}:${index}`);
|
|
4946
|
+
}
|
|
4947
|
+
for (const match of line.matchAll(SHA)) referenced.add(match[1]);
|
|
4948
|
+
continue;
|
|
4949
|
+
}
|
|
4950
|
+
if (!mentionsAttachment) continue;
|
|
4951
|
+
const content = contentOf(event);
|
|
4952
|
+
const images = [];
|
|
4953
|
+
const counted = /* @__PURE__ */ new Map();
|
|
4954
|
+
if (content !== void 0) {
|
|
4955
|
+
const addressable = typeof event.seq === "number";
|
|
4956
|
+
for (const block of content) {
|
|
4957
|
+
if (block?.type !== "image") continue;
|
|
4958
|
+
const id = String(block.attachment?.attachmentId ?? "");
|
|
4959
|
+
const hex = id.startsWith("sha256:") ? id.slice(7) : "";
|
|
4960
|
+
if (!HEX.test(hex)) {
|
|
4961
|
+
images.push("");
|
|
4962
|
+
continue;
|
|
4963
|
+
}
|
|
4964
|
+
if (event.type === "tool/result" && block.attachment?.name === "screenshot.jpg") ours.add(hex);
|
|
4965
|
+
if (!addressable) continue;
|
|
4966
|
+
images.push(block.offloaded === true ? "" : hex);
|
|
4967
|
+
if (block.offloaded === true) offloaded.add(hex);
|
|
4968
|
+
counted.set(hex, (counted.get(hex) ?? 0) + 1);
|
|
4969
|
+
}
|
|
4970
|
+
if (addressable) occurrences.set(event.seq, images);
|
|
4971
|
+
}
|
|
4972
|
+
const mentions = /* @__PURE__ */ new Map();
|
|
4973
|
+
for (const match of line.matchAll(SHA)) mentions.set(match[1], (mentions.get(match[1]) ?? 0) + 1);
|
|
4974
|
+
for (const [hex, n] of mentions) if (n > (counted.get(hex) ?? 0)) referenced.add(hex);
|
|
4975
|
+
}
|
|
4976
|
+
for (const [seq, images] of occurrences) images.forEach((hex, index) => {
|
|
4977
|
+
if (!HEX.test(hex)) return;
|
|
4978
|
+
if (marks.has(`${seq}:${index}`)) offloaded.add(hex);
|
|
4979
|
+
else referenced.add(hex);
|
|
4980
|
+
});
|
|
4981
|
+
}
|
|
4832
4982
|
async function walk(dir) {
|
|
4833
4983
|
const out = [];
|
|
4834
4984
|
let entries;
|
|
@@ -4881,6 +5031,87 @@ function decodeFrames(data, zstd) {
|
|
|
4881
5031
|
}
|
|
4882
5032
|
return Buffer.concat(parts).toString("utf8");
|
|
4883
5033
|
}
|
|
5034
|
+
/** Raw content of a tool result event, read without deriving (cheap pre-filter). */
|
|
5035
|
+
function rawContent(event) {
|
|
5036
|
+
const message = event.data?.message;
|
|
5037
|
+
return Array.isArray(message?.content) ? message.content : void 0;
|
|
5038
|
+
}
|
|
5039
|
+
function isOurs(block) {
|
|
5040
|
+
return block.type === "image" && block.attachment?.name === "screenshot.jpg" && typeof block.attachment.attachmentId === "string";
|
|
5041
|
+
}
|
|
5042
|
+
/**
|
|
5043
|
+
* The image/offload targets that leave only the newest `keep` of this plugin's
|
|
5044
|
+
* retained screenshots. Image indexes count every top-level image block of the
|
|
5045
|
+
* message, offloaded ones included, exactly as the Host's projection does.
|
|
5046
|
+
*/
|
|
5047
|
+
function planOffload(session, keep) {
|
|
5048
|
+
const none = {
|
|
5049
|
+
targets: [],
|
|
5050
|
+
attachmentIds: []
|
|
5051
|
+
};
|
|
5052
|
+
if (keep <= 0 || typeof session.eventAt !== "function" || typeof session.deriveEventMessage !== "function") return none;
|
|
5053
|
+
const nodes = session.surface?.nodes;
|
|
5054
|
+
if (nodes === void 0) return none;
|
|
5055
|
+
const retained = [];
|
|
5056
|
+
for (const seq of nodes) {
|
|
5057
|
+
let event;
|
|
5058
|
+
try {
|
|
5059
|
+
event = session.eventAt(seq);
|
|
5060
|
+
} catch {
|
|
5061
|
+
continue;
|
|
5062
|
+
}
|
|
5063
|
+
if (event?.type !== "tool/result") continue;
|
|
5064
|
+
if (!rawContent(event)?.some(isOurs)) continue;
|
|
5065
|
+
let content;
|
|
5066
|
+
try {
|
|
5067
|
+
content = session.deriveEventMessage(event).content;
|
|
5068
|
+
} catch {
|
|
5069
|
+
continue;
|
|
5070
|
+
}
|
|
5071
|
+
if (!Array.isArray(content)) continue;
|
|
5072
|
+
let index = 0;
|
|
5073
|
+
for (const block of content) {
|
|
5074
|
+
if (block?.type !== "image") continue;
|
|
5075
|
+
if (block.offloaded !== true && isOurs(block)) retained.push({
|
|
5076
|
+
seq,
|
|
5077
|
+
index,
|
|
5078
|
+
attachmentId: String(block.attachment.attachmentId)
|
|
5079
|
+
});
|
|
5080
|
+
index++;
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
const drop = retained.slice(0, Math.max(0, retained.length - keep));
|
|
5084
|
+
if (drop.length === 0) return none;
|
|
5085
|
+
const bySeq = /* @__PURE__ */ new Map();
|
|
5086
|
+
for (const item of drop) {
|
|
5087
|
+
let list = bySeq.get(item.seq);
|
|
5088
|
+
if (!list) bySeq.set(item.seq, list = []);
|
|
5089
|
+
list.push(item.index);
|
|
5090
|
+
}
|
|
5091
|
+
return {
|
|
5092
|
+
targets: [...bySeq].map(([seq, imageIndexes]) => ({
|
|
5093
|
+
seq,
|
|
5094
|
+
imageIndexes: imageIndexes.sort((a, b) => a - b)
|
|
5095
|
+
})),
|
|
5096
|
+
attachmentIds: drop.map((item) => item.attachmentId)
|
|
5097
|
+
};
|
|
5098
|
+
}
|
|
5099
|
+
/**
|
|
5100
|
+
* Offload this plugin's screenshots older than the newest `keep` in `session`.
|
|
5101
|
+
* Returns the attachment ids offloaded (empty when nothing changed). Never throws.
|
|
5102
|
+
*/
|
|
5103
|
+
function offloadOldScreenshots(session, keep, log = () => {}) {
|
|
5104
|
+
if (!session || typeof session.append !== "function") return [];
|
|
5105
|
+
try {
|
|
5106
|
+
const plan = planOffload(session, keep);
|
|
5107
|
+
if (plan.targets.length === 0) return [];
|
|
5108
|
+
session.append("image/offload", { targets: plan.targets });
|
|
5109
|
+
return plan.attachmentIds;
|
|
5110
|
+
} catch (error) {
|
|
5111
|
+
log(`screenshot offload skipped: ${String(error)}`);
|
|
5112
|
+
return [];
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
4884
5115
|
//#endregion
|
|
4885
5116
|
//#region lib/types/sessions.js
|
|
4886
5117
|
/**
|
|
@@ -10903,6 +11134,34 @@ function toJson(ref) {
|
|
|
10903
11134
|
} }
|
|
10904
11135
|
};
|
|
10905
11136
|
}
|
|
11137
|
+
/** A mouse action aimed by coordinate (not by target): only valid on the screen the model last saw. */
|
|
11138
|
+
function usesScreenCoordinates(input) {
|
|
11139
|
+
if (input.target !== void 0 && input.target !== "") return false;
|
|
11140
|
+
return (input.action === "left_click" || input.action === "right_click" || input.action === "middle_click" || input.action === "double_click" || input.action === "triple_click" || input.action === "mouse_move" || input.action === "left_click_drag" || input.action === "scroll" || input.action === "left_mouse_down") && Array.isArray(input.coordinate);
|
|
11141
|
+
}
|
|
11142
|
+
/** How the foreground changed in a way that invalidates planned coordinates, or undefined. */
|
|
11143
|
+
function screenChange(before, after) {
|
|
11144
|
+
if (!before || !after) return void 0;
|
|
11145
|
+
if (after.hwnd !== before.hwnd) return `the foreground switched to ${after.exe} ("${after.title.slice(0, 50)}") — a new window or dialog`;
|
|
11146
|
+
if (isBrowser(after) && after.title !== before.title) return `${after.exe} navigated to "${after.title.slice(0, 50)}"`;
|
|
11147
|
+
}
|
|
11148
|
+
/** Observation budget for element lists: every row stays short, and the list stops at a size the model can afford. */
|
|
11149
|
+
const OBSERVATION_MAX_CHARS = 12e3;
|
|
11150
|
+
const OBSERVATION_MAX_LINE = 300;
|
|
11151
|
+
function capObservation(text, maxChars = OBSERVATION_MAX_CHARS, maxLine = OBSERVATION_MAX_LINE) {
|
|
11152
|
+
const lines = text.split("\n").map((line) => line.length > maxLine ? `${line.slice(0, maxLine - 1)}…` : line);
|
|
11153
|
+
const out = [];
|
|
11154
|
+
let used = 0;
|
|
11155
|
+
for (const [index, line] of lines.entries()) {
|
|
11156
|
+
if (index > 0 && used + line.length + 1 > maxChars) {
|
|
11157
|
+
out.push(`… ${lines.length - index} more lines omitted (output capped at ${Math.round(maxChars / 1e3)}k characters). Narrow it with query, role, hwnd or max.`);
|
|
11158
|
+
break;
|
|
11159
|
+
}
|
|
11160
|
+
out.push(line);
|
|
11161
|
+
used += line.length + 1;
|
|
11162
|
+
}
|
|
11163
|
+
return out.join("\n");
|
|
11164
|
+
}
|
|
10906
11165
|
async function withShot(host, text, shot, call) {
|
|
10907
11166
|
if (shot === void 0) return { text };
|
|
10908
11167
|
if (shot === "unchanged") return { text: `${text}
|
|
@@ -11108,7 +11367,7 @@ function createTools(host) {
|
|
|
11108
11367
|
}));
|
|
11109
11368
|
tools.push(defineTool({
|
|
11110
11369
|
name: "computer_batch",
|
|
11111
|
-
description: "Run several computer actions in order in one call (or replay a saved macro by name), then get one screenshot (taken once the screen settles, so do not end with a wait). Stops at the first failing action and shows you the screen. The screen is not shown to you between actions, so for steps whose target only appears along the way (a menu item, a dialog button) use target instead of coordinate, and wait with until for a window or control to appear. Example: [key \"ctrl+s\", wait until \"window:另存为\", type target \"文件名\" text \"C:\\a.txt\", left_click target \"保存\"].",
|
|
11370
|
+
description: "Run several computer actions in order in one call (or replay a saved macro by name), then get one screenshot (taken once the screen settles, so do not end with a wait). Stops at the first failing action, or before a coordinate action once another window or dialog takes the foreground or the browser navigates, and shows you the screen. The screen is not shown to you between actions, so for steps whose target only appears along the way (a menu item, a dialog button) use target instead of coordinate, and wait with until for a window or control to appear. Example: [key \"ctrl+s\", wait until \"window:另存为\", type target \"文件名\" text \"C:\\a.txt\", left_click target \"保存\"].",
|
|
11112
11371
|
parameters: {
|
|
11113
11372
|
actions: {
|
|
11114
11373
|
type: "array",
|
|
@@ -11172,11 +11431,19 @@ function createTools(host) {
|
|
|
11172
11431
|
let endedWithZoom = false;
|
|
11173
11432
|
const lines = [];
|
|
11174
11433
|
let failure;
|
|
11434
|
+
const startWindow = await computer.foreground().catch(() => void 0);
|
|
11175
11435
|
for (const [index, input] of actions.entries()) {
|
|
11176
11436
|
if (input.action === "screenshot" || input.action === "zoom" && index !== actions.length - 1) {
|
|
11177
11437
|
failure = `#${index + 1} ${input.action}: ${input.action === "zoom" ? "only allowed as the last action of a batch" : "not allowed in a batch"}.`;
|
|
11178
11438
|
break;
|
|
11179
11439
|
}
|
|
11440
|
+
if (index > 0 && usesScreenCoordinates(input)) {
|
|
11441
|
+
const change = screenChange(startWindow, await computer.foreground().catch(() => void 0));
|
|
11442
|
+
if (change) {
|
|
11443
|
+
failure = `#${index + 1} ${input.action} not run: ${change} since the batch started, so its coordinates may point at the wrong thing.`;
|
|
11444
|
+
break;
|
|
11445
|
+
}
|
|
11446
|
+
}
|
|
11180
11447
|
try {
|
|
11181
11448
|
const stepStart = Date.now();
|
|
11182
11449
|
if (input.action === "zoom" && index > 0) await computer.settle(call.signal);
|
|
@@ -11191,6 +11458,10 @@ function createTools(host) {
|
|
|
11191
11458
|
break;
|
|
11192
11459
|
}
|
|
11193
11460
|
lines.push(`#${index + 1} ${outcome.text}`);
|
|
11461
|
+
if (outcome.verification === "unconfirmed" && index < actions.length - 1) {
|
|
11462
|
+
failure = `#${index + 1} ${input.action} could not be confirmed; later actions depend on it.`;
|
|
11463
|
+
break;
|
|
11464
|
+
}
|
|
11194
11465
|
await setTimeout$1(60, void 0, { signal: call.signal });
|
|
11195
11466
|
if (computer.settings().pauseOnUserInput && (computer.overlay.userTypedSince(stepStart - 1) || computer.overlay.hasUserActions?.())) {
|
|
11196
11467
|
const notes = await computer.drainUserActionNotes();
|
|
@@ -11662,6 +11933,9 @@ function createTools(host) {
|
|
|
11662
11933
|
for (const [index, el] of result.elements.entries()) lines.push(await formatEl(`[${index}]`, el));
|
|
11663
11934
|
const head = `${result.exe} — "${String(result.title ?? "").slice(0, 80)}": ${result.elements.length} elements${diff === true ? " (baseline captured; next diff: true returns changes only)" : ""}.`;
|
|
11664
11935
|
return { text: lines.length ? `${head}\n${lines.join("\n")}` : `${head} This window exposes no UI Automation elements; use ui_elements with ocr: true or screenshots.` };
|
|
11936
|
+
}).then((value) => text === true ? value : {
|
|
11937
|
+
...value,
|
|
11938
|
+
text: capObservation(value.text)
|
|
11665
11939
|
});
|
|
11666
11940
|
},
|
|
11667
11941
|
presentCall: (args) => {
|
|
@@ -12056,6 +12330,10 @@ const Config = z.object({
|
|
|
12056
12330
|
"zh-CN": { $description: "截图 JPEG 质量" },
|
|
12057
12331
|
"en-US": { $description: "Screenshot JPEG quality" }
|
|
12058
12332
|
}),
|
|
12333
|
+
keepScreenshots: z.natural().min(0).max(20).default(2).volatile().i18n({
|
|
12334
|
+
"zh-CN": { $description: "对话里保留几张截图给模型看(含最新一张)。更早的截图换成一行文字占位,不再随每次请求重发,几分钟后从磁盘删除。0 = 全部保留(旧行为)" },
|
|
12335
|
+
"en-US": { $description: "Screenshots kept as images in a conversation (including the latest). Older ones become a one-line text placeholder, are no longer resent with every request, and are deleted from disk a few minutes later. 0 keeps all (old behaviour)" }
|
|
12336
|
+
}),
|
|
12059
12337
|
pauseOnUserInput: z.boolean().default(true).volatile().i18n({
|
|
12060
12338
|
"zh-CN": { $description: "检测到你在操作时让出控制:你用键盘打字或点击鼠标/滚轮时暂停、停手后继续;你切换或打开了新窗口时,AI 重新看屏幕再决定(纯鼠标移动不会触发)" },
|
|
12061
12339
|
"en-US": { $description: "Yield to you: pause while you type or click/scroll physically, and re-check the screen when you switch windows (pure mouse movement is ignored)" }
|
|
@@ -12165,6 +12443,7 @@ function apply(ctx, config = {}) {
|
|
|
12165
12443
|
return () => {
|
|
12166
12444
|
clearTimeout(first);
|
|
12167
12445
|
clearInterval(every);
|
|
12446
|
+
screenshots.dispose();
|
|
12168
12447
|
};
|
|
12169
12448
|
}, "computer-use: screenshot cleanup");
|
|
12170
12449
|
const skills = new SkillStore(helperAssetPath("skills"));
|
|
@@ -12281,6 +12560,10 @@ function apply(ctx, config = {}) {
|
|
|
12281
12560
|
});
|
|
12282
12561
|
ctx.on("agent/pre-step", ({ agent }, next) => {
|
|
12283
12562
|
syncAgent(agent);
|
|
12563
|
+
const keep = settings().keepScreenshots;
|
|
12564
|
+
if (keep > 0) {
|
|
12565
|
+
if (offloadOldScreenshots(agent.session, keep, log).length > 0) screenshots.cleanSoon();
|
|
12566
|
+
}
|
|
12284
12567
|
return next();
|
|
12285
12568
|
});
|
|
12286
12569
|
ctx.on("loader/volatile-update", (() => syncAllAgents()));
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* This plugin's own accent colour (settings page, composer pill).
|
|
3
3
|
*
|
|
4
|
-
* One choice —
|
|
5
|
-
* browser under a key
|
|
6
|
-
* `<body
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This file is identical in every plugin; change it in all of them together.
|
|
4
|
+
* One choice — black by default, terracotta orange or blue — is kept in the
|
|
5
|
+
* browser under a key only this plugin reads, and painted as two CSS
|
|
6
|
+
* variables on `<body>` that only this plugin's styles use
|
|
7
|
+
* (`var(--dshcu-accent)` / `var(--dshcu-accent-ink)`). Changing it here does
|
|
8
|
+
* not recolour the other copylee plugins, and theirs does not recolour this one.
|
|
11
9
|
*/
|
|
12
10
|
import * as React from 'react';
|
|
13
11
|
export type Accent = 'orange' | 'blue' | 'black';
|
|
@@ -21,11 +19,12 @@ export declare const DEFAULT_ACCENT: Accent;
|
|
|
21
19
|
/** Use these in styles; the fallbacks cover the moment before the first paint. */
|
|
22
20
|
export declare const ACCENT: string;
|
|
23
21
|
export declare const ACCENT_INK: string;
|
|
22
|
+
export declare const ACCENT_KEY = "copylee.dsh.computer-use.accent";
|
|
24
23
|
export declare function isAccent(value: unknown): value is Accent;
|
|
25
24
|
/** The choice made in this browser, or null while none has been made. */
|
|
26
25
|
export declare function storedAccent(): Accent | null;
|
|
27
26
|
export declare function readAccent(): Accent;
|
|
28
|
-
/** Choose
|
|
27
|
+
/** Choose this plugin's accent. */
|
|
29
28
|
export declare function writeAccent(accent: Accent): void;
|
|
30
29
|
/** Paint the current accent and keep it current. Returns the undo for plugin disposal. */
|
|
31
30
|
export declare function installAccent(): () => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
/** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
|
|
3
|
-
export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\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,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--
|
|
3
|
+
export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\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,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--dshcu-accent,#1F1E1D);box-shadow:0 0 0 3px color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 20%,transparent)}\n.dshcu-select:disabled{opacity:.48;cursor:default}\n.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));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 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}\n.dshcu-option[aria-selected=true]{font-weight:500;color:var(--dshcu-accent,#1F1E1D)}\n";
|
|
4
4
|
export declare function Select<V extends string>({ options, value, disabled, label, onChange }: {
|
|
5
5
|
options: {
|
|
6
6
|
value: V;
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface Settings {
|
|
|
27
27
|
maxLongEdge: number;
|
|
28
28
|
maxPixels: number;
|
|
29
29
|
jpegQuality: number;
|
|
30
|
+
/** Screenshots kept as images in a conversation; older ones become text placeholders and their files are cleaned up. 0 keeps all. */
|
|
31
|
+
keepScreenshots: number;
|
|
30
32
|
autoScreenshot: boolean;
|
|
31
33
|
/** Detail tier for automatic post-action screenshots: standard or compact (smaller/cheaper). */
|
|
32
34
|
autoScreenshotDetail: AutoScreenshotDetail;
|
|
@@ -128,7 +130,12 @@ export interface ActionOutcome {
|
|
|
128
130
|
skipped?: boolean;
|
|
129
131
|
/** True when a deterministic UIA Control Pattern read back and verified the desired post-state. */
|
|
130
132
|
verified?: boolean;
|
|
133
|
+
/** For input actions: 'observed' = read back from the control, 'unconfirmed' = read back and it does not match, 'sent' = input sent, nothing to read back. */
|
|
134
|
+
verification?: Verification;
|
|
131
135
|
}
|
|
136
|
+
export type Verification = 'observed' | 'unconfirmed' | 'sent';
|
|
137
|
+
/** Whitespace-insensitive tail of typed text, as it should appear in the field afterwards. */
|
|
138
|
+
export declare function typedTextLanded(typed: string, fieldValue: string): boolean;
|
|
132
139
|
export interface ClickResult {
|
|
133
140
|
x?: number;
|
|
134
141
|
y?: number;
|
|
@@ -346,6 +353,8 @@ export declare class Computer {
|
|
|
346
353
|
drainUserActionNotes(): Promise<string>;
|
|
347
354
|
/** Format physical user takeover actions into concise screenshot-coordinate context for the model. */
|
|
348
355
|
private formatUserActions;
|
|
356
|
+
/** Compare the focused field with what was just typed (ValuePattern only; rich editors report 'sent'). */
|
|
357
|
+
private readBackTyped;
|
|
349
358
|
/** Run one action. Returns text plus an image for screenshot/zoom. */
|
|
350
359
|
run(input: ActionInput, call: CallContext): Promise<ActionOutcome>;
|
|
351
360
|
/**
|
package/lib/types/index.d.ts
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screenshot retention inside a conversation.
|
|
3
|
+
*
|
|
4
|
+
* DeepSeek Harness resends every image still in the history with each model
|
|
5
|
+
* request (up to its per-request budget), so a long computer-use task pays for
|
|
6
|
+
* dozens of stale screenshots on every step, and none of their files can ever
|
|
7
|
+
* be deleted. The Host's own image offload (`@deepseek-ai/dsh-compaction-image-offload`)
|
|
8
|
+
* only kicks in once a request is rejected as over budget.
|
|
9
|
+
*
|
|
10
|
+
* Before each step this plugin records the same durable `image/offload`
|
|
11
|
+
* decision for its own screenshots older than the newest `keep`: the model
|
|
12
|
+
* then sees a one-line placeholder in their place, provider caching restarts
|
|
13
|
+
* only at that (recent) point, and the screenshot files are no longer read
|
|
14
|
+
* for requests, so `ScreenshotCache` may delete them. User images and images
|
|
15
|
+
* from other tools are never touched.
|
|
16
|
+
*/
|
|
17
|
+
/** The attachment name every screenshot of this plugin carries. */
|
|
18
|
+
export declare const SCREENSHOT_NAME = "screenshot.jpg";
|
|
19
|
+
interface BlockLike {
|
|
20
|
+
type?: unknown;
|
|
21
|
+
offloaded?: unknown;
|
|
22
|
+
attachment?: {
|
|
23
|
+
attachmentId?: unknown;
|
|
24
|
+
name?: unknown;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface EventLike {
|
|
28
|
+
type?: unknown;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** The parts of a Host Session this module uses (all optional: older hosts lack some). */
|
|
32
|
+
export interface RetentionSession {
|
|
33
|
+
surface?: {
|
|
34
|
+
nodes?: Iterable<number>;
|
|
35
|
+
};
|
|
36
|
+
eventAt?(seq: number): EventLike;
|
|
37
|
+
deriveEventMessage?(event: EventLike): {
|
|
38
|
+
content?: readonly BlockLike[];
|
|
39
|
+
};
|
|
40
|
+
append?(type: string, data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface OffloadTarget {
|
|
43
|
+
seq: number;
|
|
44
|
+
imageIndexes: number[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The image/offload targets that leave only the newest `keep` of this plugin's
|
|
48
|
+
* retained screenshots. Image indexes count every top-level image block of the
|
|
49
|
+
* message, offloaded ones included, exactly as the Host's projection does.
|
|
50
|
+
*/
|
|
51
|
+
export declare function planOffload(session: RetentionSession, keep: number): {
|
|
52
|
+
targets: OffloadTarget[];
|
|
53
|
+
attachmentIds: string[];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Offload this plugin's screenshots older than the newest `keep` in `session`.
|
|
57
|
+
* Returns the attachment ids offloaded (empty when nothing changed). Never throws.
|
|
58
|
+
*/
|
|
59
|
+
export declare function offloadOldScreenshots(session: RetentionSession | undefined, keep: number, log?: (message: string) => void): string[];
|
|
60
|
+
export {};
|
|
@@ -18,13 +18,19 @@ export declare class ScreenshotCache {
|
|
|
18
18
|
private index;
|
|
19
19
|
private saving;
|
|
20
20
|
private busy;
|
|
21
|
+
/** Parsed session logs keyed by path, reused while their size and mtime stay the same. */
|
|
22
|
+
private files;
|
|
23
|
+
private soon;
|
|
21
24
|
constructor(dshHome?: string, indexFile?: string, log?: (message: string) => void);
|
|
22
25
|
private get objects();
|
|
23
26
|
private path;
|
|
24
27
|
/** Remember a screenshot attachment ("sha256:<hex>") this plugin saved. */
|
|
25
28
|
record(attachmentId: string): void;
|
|
26
29
|
stats(): Promise<ScreenshotStats>;
|
|
27
|
-
/**
|
|
30
|
+
/** Run `clean()` once, `delayMs` after the last call (screenshots were just offloaded). */
|
|
31
|
+
cleanSoon(delayMs?: number): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
/** Delete screenshots no request can need any more. */
|
|
28
34
|
clean(): Promise<CleanResult>;
|
|
29
35
|
private classify;
|
|
30
36
|
/** Every attachment id referenced anywhere DSH keeps conversation state. */
|
|
@@ -36,6 +42,13 @@ export declare class ScreenshotCache {
|
|
|
36
42
|
}
|
|
37
43
|
/** Ids in `text`; ids of our own screenshots (tool results named screenshot.jpg) also go to `ours`. */
|
|
38
44
|
export declare function collect(text: string, referenced: Set<string>, ours: Set<string>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Read one session log. An image occurrence (message seq, top-level image
|
|
47
|
+
* index) named by an `image/offload` event is offloaded; every other mention
|
|
48
|
+
* of an attachment, in any event, keeps it referenced. Lines that do not parse
|
|
49
|
+
* keep everything they mention.
|
|
50
|
+
*/
|
|
51
|
+
export declare function collectLog(text: string, referenced: Set<string>, ours: Set<string>, offloaded: Set<string>): void;
|
|
39
52
|
/** Split at frame magics; when a split falls inside a frame, merge with the next piece and retry. */
|
|
40
53
|
export declare function decodeFrames(data: Buffer, zstd: ZstdDecompress): string | undefined;
|
|
41
54
|
export {};
|
package/lib/types/tools.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
|
|
|
2
2
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
3
3
|
import { type MacroStore } from './macros.js';
|
|
4
4
|
import { type SkillStore } from './skills.js';
|
|
5
|
-
import { Computer, type CallContext, type Shot } from './computer.js';
|
|
5
|
+
import { Computer, type ActionInput, type CallContext, type Shot, type WindowInfo } from './computer.js';
|
|
6
6
|
type ToolDefinition = ReturnType<typeof defineTool>;
|
|
7
7
|
export interface ToolHost {
|
|
8
8
|
computer: Computer;
|
|
@@ -17,5 +17,12 @@ export interface ToolHost {
|
|
|
17
17
|
/** True when the sibling `@copylee/dsh-office` COM plugin is active in DSH. */
|
|
18
18
|
hasOfficePlugin?: () => boolean;
|
|
19
19
|
}
|
|
20
|
+
/** A mouse action aimed by coordinate (not by target): only valid on the screen the model last saw. */
|
|
21
|
+
export declare function usesScreenCoordinates(input: ActionInput): boolean;
|
|
22
|
+
/** How the foreground changed in a way that invalidates planned coordinates, or undefined. */
|
|
23
|
+
export declare function screenChange(before: WindowInfo | undefined, after: WindowInfo | undefined): string | undefined;
|
|
24
|
+
/** Observation budget for element lists: every row stays short, and the list stops at a size the model can afford. */
|
|
25
|
+
export declare const OBSERVATION_MAX_CHARS = 12000;
|
|
26
|
+
export declare function capObservation(text: string, maxChars?: number, maxLine?: number): string;
|
|
20
27
|
export declare function createTools(host: ToolHost): ToolDefinition[];
|
|
21
28
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copylee/dsh-computer-use",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"type": "module",
|