@copylee/dsh-computer-use 0.8.7 → 0.9.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/helper/CuHelper.cs +312 -15
- package/lib/client.js +263 -4
- package/lib/index.js +519 -63
- package/lib/native-worker.js +41 -8
- package/lib/types/client/composer-pill.d.ts +19 -0
- package/lib/types/computer.d.ts +49 -11
- package/lib/types/coords.d.ts +12 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/types/routes.d.ts +7 -5
- package/lib/types/sessions.d.ts +56 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -271,6 +271,30 @@ function screenshotSize(display, limits) {
|
|
|
271
271
|
height: Math.max(1, Math.round(height * scale))
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
+
/** Output size together with which limit (`longEdge`, `pixels`, or neither) actually constrained it. */
|
|
275
|
+
function describeScreenshotSize(display, limits) {
|
|
276
|
+
const { width, height } = display;
|
|
277
|
+
const edgeScale = limits.maxLongEdge / Math.max(width, height);
|
|
278
|
+
const pixelScale = Math.sqrt(limits.maxPixels / (width * height));
|
|
279
|
+
const scale = Math.min(1, edgeScale, pixelScale);
|
|
280
|
+
const limitedBy = scale >= 1 ? "none" : pixelScale < edgeScale ? "pixels" : "longEdge";
|
|
281
|
+
const outWidth = Math.max(1, Math.round(width * scale));
|
|
282
|
+
const outHeight = Math.max(1, Math.round(height * scale));
|
|
283
|
+
return {
|
|
284
|
+
width: outWidth,
|
|
285
|
+
height: outHeight,
|
|
286
|
+
megapixels: Math.round(outWidth * outHeight / 1e4) / 100,
|
|
287
|
+
limitedBy
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/** Lower-cost screenshot budget for quick confirmation shots (~30–40% fewer bytes). */
|
|
291
|
+
function compactLimits(budget) {
|
|
292
|
+
return {
|
|
293
|
+
maxLongEdge: Math.max(640, Math.min(budget.maxLongEdge, Math.round(budget.maxLongEdge * .78))),
|
|
294
|
+
maxPixels: Math.max(3e5, Math.min(budget.maxPixels, Math.round(budget.maxPixels * .58))),
|
|
295
|
+
jpegQuality: Math.max(45, Math.min(budget.jpegQuality, budget.jpegQuality - 8))
|
|
296
|
+
};
|
|
297
|
+
}
|
|
274
298
|
/** Screenshot pixels → physical virtual-screen pixels. Throws when outside the image. */
|
|
275
299
|
function toPhysical(point, display, shot) {
|
|
276
300
|
const { x, y } = point;
|
|
@@ -776,6 +800,12 @@ const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot:
|
|
|
776
800
|
const TARGET_WAIT_MS = 3e3;
|
|
777
801
|
/** Pause between looks while waiting for a control or a window. */
|
|
778
802
|
const POLL_MS = 200;
|
|
803
|
+
/** Same-spot click warning window (2 minutes) and radius (±24 physical pixels). */
|
|
804
|
+
const REPEAT_WINDOW_MS = 12e4;
|
|
805
|
+
const REPEAT_RADIUS_PX = 24;
|
|
806
|
+
function displayKey(display) {
|
|
807
|
+
return `${display.x},${display.y},${display.width},${display.height}`;
|
|
808
|
+
}
|
|
779
809
|
var Computer = class Computer {
|
|
780
810
|
helper;
|
|
781
811
|
access;
|
|
@@ -784,6 +814,10 @@ var Computer = class Computer {
|
|
|
784
814
|
displays = [];
|
|
785
815
|
displayIndex = -1;
|
|
786
816
|
heldButton = false;
|
|
817
|
+
/** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
|
|
818
|
+
lastShot;
|
|
819
|
+
/** Recent click locations (fallback repeat counter when helper does not report repeat). */
|
|
820
|
+
clickHistory = [];
|
|
787
821
|
/** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
|
|
788
822
|
clipboardAgent;
|
|
789
823
|
constructor(helper, access, overlay, settings) {
|
|
@@ -808,17 +842,27 @@ var Computer = class Computer {
|
|
|
808
842
|
const rows = await this.refreshDisplays();
|
|
809
843
|
if (!Number.isInteger(index) || index < 0 || index >= rows.length) throw new Error(`Display ${index} does not exist; there are ${rows.length} (0-${rows.length - 1}).`);
|
|
810
844
|
this.displayIndex = index;
|
|
845
|
+
this.lastShot = void 0;
|
|
811
846
|
return rows[index];
|
|
812
847
|
}
|
|
813
848
|
get currentIndex() {
|
|
814
849
|
return Math.max(0, this.displayIndex);
|
|
815
850
|
}
|
|
816
|
-
|
|
851
|
+
shotBudget(detail = "high") {
|
|
817
852
|
const s = this.settings();
|
|
818
|
-
|
|
853
|
+
const base = {
|
|
819
854
|
maxLongEdge: s.maxLongEdge,
|
|
820
|
-
maxPixels: s.maxPixels
|
|
821
|
-
|
|
855
|
+
maxPixels: s.maxPixels,
|
|
856
|
+
jpegQuality: s.jpegQuality
|
|
857
|
+
};
|
|
858
|
+
return detail === "low" ? compactLimits(base) : base;
|
|
859
|
+
}
|
|
860
|
+
shotSize(display, detail = "high") {
|
|
861
|
+
return screenshotSize(display, this.shotBudget(detail));
|
|
862
|
+
}
|
|
863
|
+
/** Coordinate space of the latest full screenshot of `display` (or its default full size before any capture). */
|
|
864
|
+
coordSize(display) {
|
|
865
|
+
return this.lastShot?.displayKey === displayKey(display) ? this.lastShot.size : this.shotSize(display);
|
|
822
866
|
}
|
|
823
867
|
async point(coordinate, field = "coordinate") {
|
|
824
868
|
if (!Array.isArray(coordinate) || coordinate.length !== 2) throw new Error(`${field} must be [x, y] in screenshot pixels.`);
|
|
@@ -826,35 +870,88 @@ var Computer = class Computer {
|
|
|
826
870
|
return toPhysical({
|
|
827
871
|
x: coordinate[0],
|
|
828
872
|
y: coordinate[1]
|
|
829
|
-
}, display, this.
|
|
873
|
+
}, display, this.coordSize(display));
|
|
830
874
|
}
|
|
831
875
|
async toModel(point) {
|
|
832
876
|
const display = await this.display();
|
|
833
877
|
return {
|
|
834
|
-
...toScreenshot(point, display, this.
|
|
878
|
+
...toScreenshot(point, display, this.coordSize(display)),
|
|
835
879
|
offscreen: !contains$1(display, point)
|
|
836
880
|
};
|
|
837
881
|
}
|
|
838
|
-
|
|
882
|
+
/** Unconditional full screenshot (used when the model must see a fresh frame, e.g. after pause/switch). */
|
|
883
|
+
async screenshot(detail = "high") {
|
|
839
884
|
await this.refreshDisplays();
|
|
840
885
|
const display = await this.display();
|
|
841
|
-
const
|
|
842
|
-
const
|
|
886
|
+
const budget = this.shotBudget(detail);
|
|
887
|
+
const size = screenshotSize(display, budget);
|
|
888
|
+
const shot = await this.capture(display, size, {
|
|
889
|
+
mark: true,
|
|
890
|
+
slot: "full",
|
|
891
|
+
quality: budget.jpegQuality
|
|
892
|
+
});
|
|
893
|
+
this.lastShot = {
|
|
894
|
+
displayKey: displayKey(display),
|
|
895
|
+
size: {
|
|
896
|
+
width: shot.width,
|
|
897
|
+
height: shot.height
|
|
898
|
+
}
|
|
899
|
+
};
|
|
843
900
|
await this.remember();
|
|
844
901
|
return shot;
|
|
845
902
|
}
|
|
846
903
|
/**
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
|
|
904
|
+
* Explicit model-requested screenshot: deduplicates against the last full
|
|
905
|
+
* screenshot shown to the model unless `force: true` or higher detail is asked.
|
|
906
|
+
*/
|
|
907
|
+
async takeScreenshot(options = {}) {
|
|
908
|
+
const detail = options.detail ?? "high";
|
|
909
|
+
if (options.force) return this.screenshot(detail);
|
|
910
|
+
await this.refreshDisplays();
|
|
911
|
+
const display = await this.display();
|
|
912
|
+
const budget = this.shotBudget(detail);
|
|
913
|
+
const size = screenshotSize(display, budget);
|
|
914
|
+
const shot = await this.capture(display, size, {
|
|
915
|
+
compare: true,
|
|
916
|
+
threshold: UNCHANGED_DIFF,
|
|
917
|
+
slot: "full",
|
|
918
|
+
quality: budget.jpegQuality
|
|
919
|
+
});
|
|
920
|
+
if (shot) this.lastShot = {
|
|
921
|
+
displayKey: displayKey(display),
|
|
922
|
+
size: {
|
|
923
|
+
width: shot.width,
|
|
924
|
+
height: shot.height
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
await this.remember();
|
|
928
|
+
return shot ?? "unchanged";
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* A fresh post-action screenshot, or 'unchanged' when the screen looks the
|
|
932
|
+
* same as in the last one the model saw (saves an image and tells it the
|
|
933
|
+
* action had no visible effect). Respects `autoScreenshotDetail` unless
|
|
934
|
+
* overridden by an explicit `detail`.
|
|
850
935
|
*/
|
|
851
|
-
async freshShot() {
|
|
936
|
+
async freshShot(detail) {
|
|
852
937
|
await this.refreshDisplays();
|
|
853
938
|
const display = await this.display();
|
|
854
|
-
const
|
|
939
|
+
const effective = detail ?? (this.settings().autoScreenshotDetail === "compact" ? "low" : "high");
|
|
940
|
+
const budget = this.shotBudget(effective);
|
|
941
|
+
const size = screenshotSize(display, budget);
|
|
942
|
+
const shot = await this.capture(display, size, {
|
|
855
943
|
compare: true,
|
|
856
|
-
threshold: UNCHANGED_DIFF
|
|
944
|
+
threshold: UNCHANGED_DIFF,
|
|
945
|
+
slot: "full",
|
|
946
|
+
quality: budget.jpegQuality
|
|
857
947
|
});
|
|
948
|
+
if (shot) this.lastShot = {
|
|
949
|
+
displayKey: displayKey(display),
|
|
950
|
+
size: {
|
|
951
|
+
width: shot.width,
|
|
952
|
+
height: shot.height
|
|
953
|
+
}
|
|
954
|
+
};
|
|
858
955
|
await this.remember();
|
|
859
956
|
return shot ?? "unchanged";
|
|
860
957
|
}
|
|
@@ -881,6 +978,7 @@ var Computer = class Computer {
|
|
|
881
978
|
return now && now.hwnd !== seen.hwnd && now.pid !== seen.pid ? now : void 0;
|
|
882
979
|
}
|
|
883
980
|
async capture(rect, out, options = {}) {
|
|
981
|
+
const { quality, ...rest } = options;
|
|
884
982
|
const result = await this.helper.call("screenshot", {
|
|
885
983
|
x: rect.x,
|
|
886
984
|
y: rect.y,
|
|
@@ -888,8 +986,8 @@ var Computer = class Computer {
|
|
|
888
986
|
height: rect.height,
|
|
889
987
|
outWidth: out.width,
|
|
890
988
|
outHeight: out.height,
|
|
891
|
-
quality: this.settings().jpegQuality,
|
|
892
|
-
...
|
|
989
|
+
quality: quality ?? this.settings().jpegQuality,
|
|
990
|
+
...rest
|
|
893
991
|
}, 3e4);
|
|
894
992
|
if (result.unchanged || result.data === void 0) return void 0;
|
|
895
993
|
return {
|
|
@@ -898,16 +996,36 @@ var Computer = class Computer {
|
|
|
898
996
|
height: result.height
|
|
899
997
|
};
|
|
900
998
|
}
|
|
901
|
-
async zoom(region) {
|
|
999
|
+
async zoom(region, options = {}) {
|
|
902
1000
|
if (!Array.isArray(region)) throw new Error("zoom needs region: [x1, y1, x2, y2] in screenshot pixels.");
|
|
903
1001
|
const display = await this.display();
|
|
904
|
-
const rect = regionToPhysical(region, display, this.
|
|
905
|
-
const
|
|
906
|
-
const out = screenshotSize(rect,
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1002
|
+
const rect = regionToPhysical(region, display, this.coordSize(display));
|
|
1003
|
+
const budget = this.shotBudget(options.detail ?? "high");
|
|
1004
|
+
const out = screenshotSize(rect, budget);
|
|
1005
|
+
return await this.capture(rect, out, {
|
|
1006
|
+
mark: true,
|
|
1007
|
+
...options.force ? {} : {
|
|
1008
|
+
compare: true,
|
|
1009
|
+
threshold: UNCHANGED_DIFF
|
|
1010
|
+
},
|
|
1011
|
+
slot: "zoom",
|
|
1012
|
+
quality: budget.jpegQuality
|
|
1013
|
+
}) ?? "unchanged";
|
|
1014
|
+
}
|
|
1015
|
+
/** Record a physical click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
|
|
1016
|
+
noteClick(point, helperRepeat) {
|
|
1017
|
+
const now = Date.now();
|
|
1018
|
+
while (this.clickHistory.length > 0 && now - this.clickHistory[0].at > REPEAT_WINDOW_MS) this.clickHistory.shift();
|
|
1019
|
+
let local = 0;
|
|
1020
|
+
if (point) {
|
|
1021
|
+
this.clickHistory.push({
|
|
1022
|
+
x: point.x,
|
|
1023
|
+
y: point.y,
|
|
1024
|
+
at: now
|
|
1025
|
+
});
|
|
1026
|
+
for (const entry of this.clickHistory) if (Math.abs(entry.x - point.x) <= REPEAT_RADIUS_PX && Math.abs(entry.y - point.y) <= REPEAT_RADIUS_PX) local++;
|
|
1027
|
+
}
|
|
1028
|
+
return typeof helperRepeat === "number" && Number.isFinite(helperRepeat) && helperRepeat > 0 ? helperRepeat : local;
|
|
911
1029
|
}
|
|
912
1030
|
async foreground() {
|
|
913
1031
|
const win = await this.helper.call("foreground");
|
|
@@ -1290,14 +1408,22 @@ var Computer = class Computer {
|
|
|
1290
1408
|
if (KEYBOARD.has(action)) await this.refocusFromHost();
|
|
1291
1409
|
switch (action) {
|
|
1292
1410
|
case "screenshot": {
|
|
1293
|
-
const shot = await this.
|
|
1411
|
+
const shot = await this.takeScreenshot({
|
|
1412
|
+
force: input.force === true,
|
|
1413
|
+
...input.detail ? { detail: input.detail } : {}
|
|
1414
|
+
});
|
|
1415
|
+
if (shot === "unchanged") return { text: `Screenshot unchanged for display ${this.currentIndex}: the screen looks identical to your previous screenshot (pass force: true to capture anyway).` };
|
|
1294
1416
|
return {
|
|
1295
1417
|
text: `Screenshot ${shot.width}x${shot.height} of display ${this.currentIndex}.`,
|
|
1296
1418
|
image: shot
|
|
1297
1419
|
};
|
|
1298
1420
|
}
|
|
1299
1421
|
case "zoom": {
|
|
1300
|
-
const shot = await this.zoom(input.region
|
|
1422
|
+
const shot = await this.zoom(input.region, {
|
|
1423
|
+
force: input.force === true,
|
|
1424
|
+
...input.detail ? { detail: input.detail } : {}
|
|
1425
|
+
});
|
|
1426
|
+
if (shot === "unchanged") return { text: `Zoomed view of region [${(input.region ?? []).join(", ")}] is unchanged from your previous zoom of this region (pass force: true to capture anyway).` };
|
|
1301
1427
|
return {
|
|
1302
1428
|
text: `Zoomed view of region [${(input.region ?? []).join(", ")}] at ${shot.width}x${shot.height}. Pixel positions in this image are NOT screen coordinates; keep using full-screenshot coordinates for actions.`,
|
|
1303
1429
|
image: shot
|
|
@@ -1335,13 +1461,27 @@ var Computer = class Computer {
|
|
|
1335
1461
|
if (await this.semanticAction(call, named, semantic)) return { text: `${semantic === "focus" ? "Focused" : "Invoked"}${label}.` };
|
|
1336
1462
|
}
|
|
1337
1463
|
if (named) p = await this.namedClickPoint(call, input.target, named);
|
|
1338
|
-
|
|
1464
|
+
const labelCoord = input.coordinate ? {
|
|
1465
|
+
labelX: Math.round(input.coordinate[0]),
|
|
1466
|
+
labelY: Math.round(input.coordinate[1])
|
|
1467
|
+
} : p ? await this.toModel(p).then((m) => ({
|
|
1468
|
+
labelX: m.x,
|
|
1469
|
+
labelY: m.y
|
|
1470
|
+
})) : {};
|
|
1471
|
+
const clickRes = await this.helper.call("click", {
|
|
1339
1472
|
...p ?? {},
|
|
1473
|
+
...labelCoord,
|
|
1340
1474
|
button,
|
|
1341
1475
|
count,
|
|
1342
1476
|
modifiers
|
|
1343
1477
|
});
|
|
1344
|
-
|
|
1478
|
+
const clickedAt = p ?? (typeof clickRes?.x === "number" && typeof clickRes?.y === "number" ? {
|
|
1479
|
+
x: clickRes.x,
|
|
1480
|
+
y: clickRes.y
|
|
1481
|
+
} : void 0);
|
|
1482
|
+
const repeat = this.noteClick(clickedAt, clickRes?.repeat);
|
|
1483
|
+
const repeatHint = repeat >= 3 ? ` (same spot clicked ${repeat} times — screenshot before clicking again)` : "";
|
|
1484
|
+
return { text: `${action.replace("_", " ")}${label}${modifiers.length ? ` holding ${input.modifiers ?? input.text}` : ""}.${repeatHint}` };
|
|
1345
1485
|
}
|
|
1346
1486
|
case "left_click_drag": {
|
|
1347
1487
|
const from = await this.point(input.start_coordinate, "start_coordinate");
|
|
@@ -1494,12 +1634,12 @@ var Computer = class Computer {
|
|
|
1494
1634
|
* (vision models only). A wait already waited, so it is captured at once:
|
|
1495
1635
|
* "wait, then look" should be one step, not two.
|
|
1496
1636
|
*/
|
|
1497
|
-
async after(inputs, call) {
|
|
1637
|
+
async after(inputs, call, detail) {
|
|
1498
1638
|
if (!this.settings().autoScreenshot || !call.vision) return void 0;
|
|
1499
1639
|
const mutating = inputs.some((input) => MUTATING.has(input.action));
|
|
1500
1640
|
if (!mutating && !inputs.some((input) => input.action === "wait")) return void 0;
|
|
1501
1641
|
if (mutating) await this.settle(call.signal);
|
|
1502
|
-
return this.freshShot();
|
|
1642
|
+
return this.freshShot(detail ?? inputs.at(-1)?.detail);
|
|
1503
1643
|
}
|
|
1504
1644
|
/** Bring a window forward and verify it is the foreground window. */
|
|
1505
1645
|
async focus(win) {
|
|
@@ -2480,7 +2620,8 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
|
|
|
2480
2620
|
- The "DeepSeek Harness.exe" window is your own chat interface. While you control the computer it floats as a card that only the user sees: your screenshots show what is underneath it and your clicks and scrolls pass through it, so simply ignore it. Never type into DeepSeek Harness; keys go to the window you were working in.
|
|
2481
2621
|
- If the target window is small or partly covered by other windows, maximize it (windows maximize) or minimize what is in the way (windows minimize works for any window) instead of working around it.
|
|
2482
2622
|
- Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets. When text is too small to read, zoom once on a generous region that contains everything you need (zooming step by step wastes calls).
|
|
2483
|
-
- Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
|
|
2623
|
+
- Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call. Explicit screenshot and zoom skip sending duplicate pixels when nothing changed (pass force: true to capture anyway); pass detail: "low" when you only need a quick visual confirmation rather than reading small text.
|
|
2624
|
+
- When the overlay is enabled, a colored target ring briefly stays visible in the next screenshot at the click position (blue = left click, purple = double click, green = right click, cyan = middle click, orange = triple click) so you can verify exactly where your click landed. If you see a repeat-click warning on the same spot, inspect the screen before clicking again.
|
|
2484
2625
|
- When the user asks you to write something in an app, enter it there with type, even long or multi-line Markdown: the user watches it appear (long text is streamed in paragraph by paragraph, literally, without the editor's auto-formatting getting in the way). Do not write the file from a shell and reopen it instead, and do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
|
|
2485
2626
|
- App skills: open_application returns your saved notes for the app it opens; follow them instead of rediscovering how the app behaves. After working out an unfamiliar app (or finding a note wrong), record the reusable part with app_skill rather than in general memory.
|
|
2486
2627
|
- Saving: in any Save As dialog do not click through folders; press alt+n (file name box), ctrl+a, type the full path including the file name, then Return. Office apps: F12 opens that classic dialog directly. To check a saved file, look at the exact path; never search a whole drive or user profile recursively.
|
|
@@ -2700,11 +2841,13 @@ var SkillStore = class {
|
|
|
2700
2841
|
const ENTRY_ID = "copylee-computer-use";
|
|
2701
2842
|
const DEFAULTS = {
|
|
2702
2843
|
accessMode: "per-app",
|
|
2844
|
+
defaultSessionEnabled: false,
|
|
2703
2845
|
overlay: true,
|
|
2704
2846
|
overlayLabel: "DeepSeek Harness",
|
|
2705
2847
|
hostWindow: "pet",
|
|
2706
2848
|
cardOpacity: 80,
|
|
2707
2849
|
autoScreenshot: true,
|
|
2850
|
+
autoScreenshotDetail: "standard",
|
|
2708
2851
|
settleMs: 400,
|
|
2709
2852
|
maxLongEdge: 1366,
|
|
2710
2853
|
maxPixels: 115e4,
|
|
@@ -2728,11 +2871,13 @@ function resolveConfig(raw) {
|
|
|
2728
2871
|
return {
|
|
2729
2872
|
harnessUrl: typeof out.harnessUrl === "string" ? httpOrigin(out.harnessUrl.trim()) : void 0,
|
|
2730
2873
|
accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
|
|
2874
|
+
defaultSessionEnabled: bool("defaultSessionEnabled"),
|
|
2731
2875
|
overlay: bool("overlay"),
|
|
2732
2876
|
overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
|
|
2733
2877
|
hostWindow: out.hostWindow === "pet" || out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
|
|
2734
2878
|
cardOpacity: num("cardOpacity", 30, 100),
|
|
2735
2879
|
autoScreenshot: bool("autoScreenshot"),
|
|
2880
|
+
autoScreenshotDetail: out.autoScreenshotDetail === "compact" || out.autoScreenshotDetail === "standard" ? out.autoScreenshotDetail : DEFAULTS.autoScreenshotDetail,
|
|
2736
2881
|
settleMs: num("settleMs", 0, 5e3),
|
|
2737
2882
|
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
2738
2883
|
maxPixels: num("maxPixels", 3e5, 8e6),
|
|
@@ -2823,6 +2968,7 @@ const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
|
2823
2968
|
const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
|
|
2824
2969
|
const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
|
|
2825
2970
|
const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
|
|
2971
|
+
const SESSION_ROUTE = "/api/dsh-computer-use/session";
|
|
2826
2972
|
function json(res, status, body) {
|
|
2827
2973
|
res.writeHead(status, {
|
|
2828
2974
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -2833,6 +2979,11 @@ function json(res, status, body) {
|
|
|
2833
2979
|
function statusRoute(helper, settings, overlay) {
|
|
2834
2980
|
return async (_req, res) => {
|
|
2835
2981
|
const s = settings();
|
|
2982
|
+
const compact = compactLimits({
|
|
2983
|
+
maxLongEdge: s.maxLongEdge,
|
|
2984
|
+
maxPixels: s.maxPixels,
|
|
2985
|
+
jpegQuality: s.jpegQuality
|
|
2986
|
+
});
|
|
2836
2987
|
try {
|
|
2837
2988
|
const displays = await helper.call("displays", {}, 3e4);
|
|
2838
2989
|
json(res, 200, {
|
|
@@ -2841,10 +2992,11 @@ function statusRoute(helper, settings, overlay) {
|
|
|
2841
2992
|
helper: "ready",
|
|
2842
2993
|
displays: displays.map((d) => ({
|
|
2843
2994
|
...d,
|
|
2844
|
-
shot:
|
|
2995
|
+
shot: describeScreenshotSize(d, {
|
|
2845
2996
|
maxLongEdge: s.maxLongEdge,
|
|
2846
2997
|
maxPixels: s.maxPixels
|
|
2847
|
-
})
|
|
2998
|
+
}),
|
|
2999
|
+
compactShot: describeScreenshotSize(d, compact)
|
|
2848
3000
|
})),
|
|
2849
3001
|
controlling: overlay.controller !== void 0
|
|
2850
3002
|
});
|
|
@@ -2991,6 +3143,54 @@ function skillsRoute(skills) {
|
|
|
2991
3143
|
});
|
|
2992
3144
|
};
|
|
2993
3145
|
}
|
|
3146
|
+
/** Per-session computer-use toggle: GET ?sessionId=... reads resolved state; POST { sessionId, enabled } updates and syncs live agents. */
|
|
3147
|
+
function sessionRoute(gate, settings, parentIdsFor, sync) {
|
|
3148
|
+
return async (req, res) => {
|
|
3149
|
+
if (req.method === "POST") {
|
|
3150
|
+
const input = await body(req);
|
|
3151
|
+
const sessionId = typeof input.sessionId === "string" ? input.sessionId.trim() : "";
|
|
3152
|
+
if (sessionId === "") {
|
|
3153
|
+
json(res, 400, {
|
|
3154
|
+
ok: false,
|
|
3155
|
+
error: "sessionId is required"
|
|
3156
|
+
});
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
if (typeof input.enabled !== "boolean") {
|
|
3160
|
+
json(res, 400, {
|
|
3161
|
+
ok: false,
|
|
3162
|
+
error: "enabled must be a boolean"
|
|
3163
|
+
});
|
|
3164
|
+
return;
|
|
3165
|
+
}
|
|
3166
|
+
gate.set(sessionId, input.enabled);
|
|
3167
|
+
sync();
|
|
3168
|
+
json(res, 200, {
|
|
3169
|
+
ok: true,
|
|
3170
|
+
...gate.status(sessionId, {
|
|
3171
|
+
defaultEnabled: settings().defaultSessionEnabled,
|
|
3172
|
+
parentIds: parentIdsFor(sessionId)
|
|
3173
|
+
})
|
|
3174
|
+
});
|
|
3175
|
+
return;
|
|
3176
|
+
}
|
|
3177
|
+
const sessionId = (new URL(req.url ?? "/api/dsh-computer-use/session", "http://127.0.0.1").searchParams.get("sessionId") ?? "").trim();
|
|
3178
|
+
if (sessionId === "") {
|
|
3179
|
+
json(res, 400, {
|
|
3180
|
+
ok: false,
|
|
3181
|
+
error: "sessionId is required"
|
|
3182
|
+
});
|
|
3183
|
+
return;
|
|
3184
|
+
}
|
|
3185
|
+
json(res, 200, {
|
|
3186
|
+
ok: true,
|
|
3187
|
+
...gate.status(sessionId, {
|
|
3188
|
+
defaultEnabled: settings().defaultSessionEnabled,
|
|
3189
|
+
parentIds: parentIdsFor(sessionId)
|
|
3190
|
+
})
|
|
3191
|
+
});
|
|
3192
|
+
};
|
|
3193
|
+
}
|
|
2994
3194
|
//#endregion
|
|
2995
3195
|
//#region lib/types/screenshots.js
|
|
2996
3196
|
/**
|
|
@@ -3232,6 +3432,161 @@ function decodeFrames(data, zstd) {
|
|
|
3232
3432
|
return Buffer.concat(parts).toString("utf8");
|
|
3233
3433
|
}
|
|
3234
3434
|
//#endregion
|
|
3435
|
+
//#region lib/types/sessions.js
|
|
3436
|
+
/**
|
|
3437
|
+
* Per-session toggle for computer-use tools and system prompt guidance.
|
|
3438
|
+
*
|
|
3439
|
+
* Each session remembers its explicit on/off choice on disk so restarts and
|
|
3440
|
+
* resumed sessions keep the user's decision. Subagents and forked sessions
|
|
3441
|
+
* inherit their ancestor's choice unless overridden. New sessions without an
|
|
3442
|
+
* explicit decision fall back to `defaultEnabled` (off by default).
|
|
3443
|
+
*/
|
|
3444
|
+
const MAX_ENTRIES = 500;
|
|
3445
|
+
function defaultSessionsFile() {
|
|
3446
|
+
return join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "dsh-computer-use", "sessions.json");
|
|
3447
|
+
}
|
|
3448
|
+
/**
|
|
3449
|
+
* Walk an agent's parent chain (nearest ancestor first), combining durable
|
|
3450
|
+
* `session.header.parentSession` with runtime parent ownership for subagents.
|
|
3451
|
+
*/
|
|
3452
|
+
function parentSessionChain(agent, registry) {
|
|
3453
|
+
if (!agent) return [];
|
|
3454
|
+
const chain = [];
|
|
3455
|
+
const seen = /* @__PURE__ */ new Set([agent.session.id]);
|
|
3456
|
+
let current = agent;
|
|
3457
|
+
for (let depth = 0; depth < 16 && current; depth++) {
|
|
3458
|
+
let parentId = current.session.header?.parentSession;
|
|
3459
|
+
let parentAgent = parentId ? registry?.get?.(parentId) : void 0;
|
|
3460
|
+
if (!parentId && registry?.list && registry.isOwnedBy) {
|
|
3461
|
+
const currentId = current.id ?? current.session.id;
|
|
3462
|
+
const isOwnedBy = registry.isOwnedBy;
|
|
3463
|
+
const owner = registry.list().find((candidate) => candidate !== current && isOwnedBy(currentId, candidate));
|
|
3464
|
+
if (owner) {
|
|
3465
|
+
parentAgent = owner;
|
|
3466
|
+
parentId = owner.session.id;
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
if (!parentId || seen.has(parentId)) break;
|
|
3470
|
+
seen.add(parentId);
|
|
3471
|
+
chain.push(parentId);
|
|
3472
|
+
current = parentAgent;
|
|
3473
|
+
}
|
|
3474
|
+
return chain;
|
|
3475
|
+
}
|
|
3476
|
+
var SessionGate = class {
|
|
3477
|
+
storeFile;
|
|
3478
|
+
log;
|
|
3479
|
+
entries = /* @__PURE__ */ new Map();
|
|
3480
|
+
saving = Promise.resolve();
|
|
3481
|
+
constructor(storeFile = defaultSessionsFile(), log = () => {}) {
|
|
3482
|
+
this.storeFile = storeFile;
|
|
3483
|
+
this.log = log;
|
|
3484
|
+
if (this.storeFile !== null) this.loadSync(this.storeFile);
|
|
3485
|
+
}
|
|
3486
|
+
/** Explicit decision stored for `sessionId`, or undefined when unset. */
|
|
3487
|
+
explicit(sessionId) {
|
|
3488
|
+
return this.entries.get(sessionId)?.enabled;
|
|
3489
|
+
}
|
|
3490
|
+
/** Effective enabled state for `sessionId`, inheriting ancestors before falling back to `defaultEnabled`. */
|
|
3491
|
+
isEnabled(sessionId, options = {}) {
|
|
3492
|
+
if (sessionId) {
|
|
3493
|
+
const own = this.entries.get(sessionId);
|
|
3494
|
+
if (own !== void 0) return own.enabled;
|
|
3495
|
+
}
|
|
3496
|
+
if (options.parentIds) for (const parentId of options.parentIds) {
|
|
3497
|
+
const inherited = this.entries.get(parentId);
|
|
3498
|
+
if (inherited !== void 0) return inherited.enabled;
|
|
3499
|
+
}
|
|
3500
|
+
return options.defaultEnabled === true;
|
|
3501
|
+
}
|
|
3502
|
+
/** Inspect the resolved state plus whether it came from an explicit choice or ancestor inheritance. */
|
|
3503
|
+
status(sessionId, options = {}) {
|
|
3504
|
+
const defaultEnabled = options.defaultEnabled === true;
|
|
3505
|
+
const own = this.entries.get(sessionId);
|
|
3506
|
+
if (own !== void 0) return {
|
|
3507
|
+
sessionId,
|
|
3508
|
+
enabled: own.enabled,
|
|
3509
|
+
explicit: true,
|
|
3510
|
+
inherited: false,
|
|
3511
|
+
defaultEnabled
|
|
3512
|
+
};
|
|
3513
|
+
if (options.parentIds) for (const parentId of options.parentIds) {
|
|
3514
|
+
const inherited = this.entries.get(parentId);
|
|
3515
|
+
if (inherited !== void 0) return {
|
|
3516
|
+
sessionId,
|
|
3517
|
+
enabled: inherited.enabled,
|
|
3518
|
+
explicit: false,
|
|
3519
|
+
inherited: true,
|
|
3520
|
+
defaultEnabled
|
|
3521
|
+
};
|
|
3522
|
+
}
|
|
3523
|
+
return {
|
|
3524
|
+
sessionId,
|
|
3525
|
+
enabled: defaultEnabled,
|
|
3526
|
+
explicit: false,
|
|
3527
|
+
inherited: false,
|
|
3528
|
+
defaultEnabled
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
/** Persist an explicit on/off choice for `sessionId`. */
|
|
3532
|
+
set(sessionId, enabled) {
|
|
3533
|
+
const id = sessionId.trim();
|
|
3534
|
+
if (id === "") return;
|
|
3535
|
+
this.entries.set(id, {
|
|
3536
|
+
enabled,
|
|
3537
|
+
updatedAt: Date.now()
|
|
3538
|
+
});
|
|
3539
|
+
this.trim();
|
|
3540
|
+
this.persist();
|
|
3541
|
+
}
|
|
3542
|
+
/** Remove an explicit choice so the session falls back to inheritance / default. */
|
|
3543
|
+
clear(sessionId) {
|
|
3544
|
+
if (this.entries.delete(sessionId)) this.persist();
|
|
3545
|
+
}
|
|
3546
|
+
/** Wait for any pending write to settle (used by tests). */
|
|
3547
|
+
flush() {
|
|
3548
|
+
return this.saving;
|
|
3549
|
+
}
|
|
3550
|
+
trim() {
|
|
3551
|
+
if (this.entries.size <= MAX_ENTRIES) return;
|
|
3552
|
+
const sorted = [...this.entries.entries()].sort((a, b) => b[1].updatedAt - a[1].updatedAt);
|
|
3553
|
+
this.entries.clear();
|
|
3554
|
+
for (const [id, entry] of sorted.slice(0, MAX_ENTRIES)) this.entries.set(id, entry);
|
|
3555
|
+
}
|
|
3556
|
+
loadSync(file) {
|
|
3557
|
+
try {
|
|
3558
|
+
const map = JSON.parse(readFileSync(file, "utf8"))?.sessions;
|
|
3559
|
+
if (!map || typeof map !== "object") return;
|
|
3560
|
+
for (const [id, value] of Object.entries(map)) if (typeof value === "boolean") this.entries.set(id, {
|
|
3561
|
+
enabled: value,
|
|
3562
|
+
updatedAt: 0
|
|
3563
|
+
});
|
|
3564
|
+
else if (value && typeof value === "object" && typeof value.enabled === "boolean") {
|
|
3565
|
+
const updatedAt = typeof value.updatedAt === "number" && Number.isFinite(value.updatedAt) ? value.updatedAt : 0;
|
|
3566
|
+
this.entries.set(id, {
|
|
3567
|
+
enabled: value.enabled,
|
|
3568
|
+
updatedAt
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
this.trim();
|
|
3572
|
+
} catch {}
|
|
3573
|
+
}
|
|
3574
|
+
persist() {
|
|
3575
|
+
const file = this.storeFile;
|
|
3576
|
+
if (file === null) return;
|
|
3577
|
+
const snapshot = Object.fromEntries(this.entries);
|
|
3578
|
+
this.saving = this.saving.then(async () => {
|
|
3579
|
+
await mkdir(dirname(file), { recursive: true });
|
|
3580
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
3581
|
+
await writeFile(tmp, JSON.stringify({
|
|
3582
|
+
version: 1,
|
|
3583
|
+
sessions: snapshot
|
|
3584
|
+
}));
|
|
3585
|
+
await rename(tmp, file);
|
|
3586
|
+
}).catch((error) => this.log(`session toggle save: ${String(error)}`));
|
|
3587
|
+
}
|
|
3588
|
+
};
|
|
3589
|
+
//#endregion
|
|
3235
3590
|
//#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_0d6b19188928ab894325adc32e18b0b5/node_modules/@deepseek-ai/dsh-scope/lib/index.js
|
|
3236
3591
|
/**
|
|
3237
3592
|
* Shared insertion-ordered storage and effect ownership for scope-aware registries.
|
|
@@ -8989,6 +9344,15 @@ const actionProperties = {
|
|
|
8989
9344
|
type: "array",
|
|
8990
9345
|
items: { type: "number" },
|
|
8991
9346
|
description: "zoom: [x1, y1, x2, y2] in screenshot pixels."
|
|
9347
|
+
},
|
|
9348
|
+
force: {
|
|
9349
|
+
type: "boolean",
|
|
9350
|
+
description: "screenshot / zoom: capture and return a fresh image even when the pixels look identical to your previous view."
|
|
9351
|
+
},
|
|
9352
|
+
detail: {
|
|
9353
|
+
type: "string",
|
|
9354
|
+
enum: ["high", "low"],
|
|
9355
|
+
description: "Screenshot detail: \"high\" uses full configured resolution; \"low\" uses a smaller, cheaper image for quick visual confirmation."
|
|
8992
9356
|
}
|
|
8993
9357
|
};
|
|
8994
9358
|
const BATCH_ACTIONS = ACTIONS.filter((action) => action !== "screenshot");
|
|
@@ -9007,6 +9371,7 @@ function createTools(host) {
|
|
|
9007
9371
|
try {
|
|
9008
9372
|
const outcome = await computer.run(input, call);
|
|
9009
9373
|
if (outcome.image) return withShot(host, outcome.text, outcome.image, call);
|
|
9374
|
+
if (input.action === "screenshot" || input.action === "zoom") return { text: outcome.text };
|
|
9010
9375
|
const shot = await computer.after([input], call);
|
|
9011
9376
|
return withShot(host, shot === void 0 && input.action !== "wait" && input.action !== "cursor_position" ? `${outcome.text} ${await computer.describeForeground()}` : outcome.text, shot, call);
|
|
9012
9377
|
} catch (error) {
|
|
@@ -9044,6 +9409,11 @@ function createTools(host) {
|
|
|
9044
9409
|
"none"
|
|
9045
9410
|
],
|
|
9046
9411
|
description: "What to return after the actions: screenshot (default), text (what the foreground window says, read as text: cheaper and exact when you only need the words), or none."
|
|
9412
|
+
},
|
|
9413
|
+
detail: {
|
|
9414
|
+
type: "string",
|
|
9415
|
+
enum: ["high", "low"],
|
|
9416
|
+
description: "Detail for the final screenshot when finish is \"screenshot\": \"low\" uses a smaller, cheaper image for quick confirmation."
|
|
9047
9417
|
}
|
|
9048
9418
|
},
|
|
9049
9419
|
output,
|
|
@@ -9052,7 +9422,9 @@ function createTools(host) {
|
|
|
9052
9422
|
const call = await host.context(exec);
|
|
9053
9423
|
const actions = args.actions;
|
|
9054
9424
|
const finish = args.finish ?? "screenshot";
|
|
9425
|
+
const detail = args.detail;
|
|
9055
9426
|
let zoomed;
|
|
9427
|
+
let endedWithZoom = false;
|
|
9056
9428
|
if (!Array.isArray(actions) || actions.length === 0) throw new Error("actions must be a non-empty array.");
|
|
9057
9429
|
if (actions.length > 30) throw new Error("At most 30 actions per batch.");
|
|
9058
9430
|
const lines = [];
|
|
@@ -9066,7 +9438,10 @@ function createTools(host) {
|
|
|
9066
9438
|
const stepStart = Date.now();
|
|
9067
9439
|
if (input.action === "zoom" && index > 0) await computer.settle(call.signal);
|
|
9068
9440
|
const outcome = await computer.run(input, call);
|
|
9069
|
-
if (input.action === "zoom")
|
|
9441
|
+
if (input.action === "zoom") {
|
|
9442
|
+
endedWithZoom = true;
|
|
9443
|
+
zoomed = outcome.image;
|
|
9444
|
+
}
|
|
9070
9445
|
if (outcome.skipped) {
|
|
9071
9446
|
failure = `#${index + 1} ${input.action} skipped: the user was typing on the keyboard. Re-check the screen before continuing.`;
|
|
9072
9447
|
break;
|
|
@@ -9088,21 +9463,21 @@ function createTools(host) {
|
|
|
9088
9463
|
}
|
|
9089
9464
|
const done = lines.join("\n");
|
|
9090
9465
|
const summary = failure === void 0 ? `All ${actions.length} actions done.\n${done}` : `Stopped: ${failure}${done ? `\nCompleted before it:\n${done}` : ""}\nRemaining actions were skipped.`;
|
|
9091
|
-
if (
|
|
9466
|
+
if (endedWithZoom && failure === void 0) return zoomed ? withShot(host, summary, zoomed, call) : { text: summary };
|
|
9092
9467
|
if (failure === void 0 && finish === "none") return { text: `${summary}\n${await computer.describeForeground()}` };
|
|
9093
9468
|
if (failure === void 0 && finish === "text") {
|
|
9094
9469
|
await computer.settle(call.signal);
|
|
9095
9470
|
return { text: `${summary}\n${await windowText(computer, void 0, void 0).catch((error) => `Could not read the window text: ${error instanceof Error ? error.message : String(error)}`)}` };
|
|
9096
9471
|
}
|
|
9097
9472
|
const waited = failure === void 0 && actions[actions.length - 1]?.action === "wait";
|
|
9098
|
-
const shot = call.vision && computer.settings().autoScreenshot ? await (waited ? Promise.resolve() : computer.settle(call.signal)).then(() => computer.freshShot()) : void 0;
|
|
9473
|
+
const shot = call.vision && computer.settings().autoScreenshot ? await (waited ? Promise.resolve() : computer.settle(call.signal)).then(() => computer.freshShot(detail)) : void 0;
|
|
9099
9474
|
return withShot(host, shot === void 0 ? `${summary}\n${await computer.describeForeground()}` : summary, shot, call);
|
|
9100
9475
|
},
|
|
9101
9476
|
presentCall: (args) => card(`电脑操作 · 批量 ${args.actions?.length ?? 0} 步`)
|
|
9102
9477
|
}));
|
|
9103
9478
|
tools.push(defineTool({
|
|
9104
9479
|
name: "open_application",
|
|
9105
|
-
description: "Open an app by name (e.g. \"Chrome\", \"记事本\", \"微信\", \"Excel\"), an .exe path, or a URL, or bring it to the front if it is already running. Faster and more reliable than clicking the taskbar or Start menu.
|
|
9480
|
+
description: "Open an app by name (e.g. \"Chrome\", \"记事本\", \"微信\", \"Excel\"), an .exe path, or a URL, or bring it to the front if it is already running. Faster and more reliable than clicking the taskbar or Start menu. Includes a screenshot when automatic screenshots are enabled and the model supports images.",
|
|
9106
9481
|
parameters: {
|
|
9107
9482
|
name: {
|
|
9108
9483
|
type: "string",
|
|
@@ -9119,8 +9494,9 @@ function createTools(host) {
|
|
|
9119
9494
|
async execute(args, exec) {
|
|
9120
9495
|
const call = await host.context(exec);
|
|
9121
9496
|
const text = await openApp(String(args.name ?? ""), args.new_instance === true, call);
|
|
9497
|
+
if (!call.vision || !computer.settings().autoScreenshot) return { text };
|
|
9122
9498
|
await computer.settle(call.signal);
|
|
9123
|
-
return withShot(host, text,
|
|
9499
|
+
return withShot(host, text, await computer.screenshot(), call);
|
|
9124
9500
|
},
|
|
9125
9501
|
presentCall: (args) => card(`打开应用 · ${args.name ?? ""}`)
|
|
9126
9502
|
}));
|
|
@@ -9411,7 +9787,7 @@ function createTools(host) {
|
|
|
9411
9787
|
if (index !== void 0) await computer.selectDisplay(index);
|
|
9412
9788
|
const list = (await computer.refreshDisplays()).map((d, i) => `${i}: ${d.width}x${d.height} at (${d.x}, ${d.y}), ${Math.round(d.dpi / 96 * 100)}% scale${d.primary ? ", primary" : ""}${i === computer.currentIndex ? " ← current" : ""}`).join("\n");
|
|
9413
9789
|
if (index === void 0) return { text: list };
|
|
9414
|
-
const shot = call.vision ? await computer.screenshot() : void 0;
|
|
9790
|
+
const shot = call.vision && computer.settings().autoScreenshot ? await computer.screenshot() : void 0;
|
|
9415
9791
|
return withShot(host, `Switched to display ${index}.\n${list}`, shot, call);
|
|
9416
9792
|
},
|
|
9417
9793
|
presentCall: () => card("切换显示器")
|
|
@@ -9549,6 +9925,10 @@ const Config = z.object({
|
|
|
9549
9925
|
"zh-CN": { $description: "授权方式。无论哪种,DeepSeek Harness 自身窗口和下方“禁止操控的应用”都不会被操作。" },
|
|
9550
9926
|
"en-US": { $description: "Access mode. DeepSeek Harness itself and blocked apps are never controlled." }
|
|
9551
9927
|
}),
|
|
9928
|
+
defaultSessionEnabled: z.boolean().default(false).volatile().i18n({
|
|
9929
|
+
"zh-CN": { $description: "新会话默认开启电脑控制。关闭时(推荐),新会话隐藏桌面工具和提示词,需要在输入框点击「电脑控制」胶囊按需开启。" },
|
|
9930
|
+
"en-US": { $description: "Enable computer use by default for new sessions. Off (recommended) hides desktop tools and prompt guidance until turned on from the composer pill." }
|
|
9931
|
+
}),
|
|
9552
9932
|
overlay: z.boolean().default(true).volatile().i18n({
|
|
9553
9933
|
"zh-CN": { $description: "控制时显示橙色光晕边框和顶部提示条(不会出现在截图里,按 Esc 可停止)" },
|
|
9554
9934
|
"en-US": { $description: "Show the orange glow and status pill while controlling (hidden from screenshots; Esc stops)" }
|
|
@@ -9607,6 +9987,16 @@ const Config = z.object({
|
|
|
9607
9987
|
"zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
|
|
9608
9988
|
"en-US": { $description: "Return a screenshot after every action (saves a round trip)" }
|
|
9609
9989
|
}),
|
|
9990
|
+
autoScreenshotDetail: z.union([z.const("standard").i18n({
|
|
9991
|
+
"zh-CN": { $description: "标准(使用上方截图分辨率与质量)" },
|
|
9992
|
+
"en-US": { $description: "Standard (use the full screenshot limits below)" }
|
|
9993
|
+
}), z.const("compact").i18n({
|
|
9994
|
+
"zh-CN": { $description: "紧凑(自动降一档,省约 30%–40% 字节;显式 screenshot / zoom 仍保持标准清晰度)" },
|
|
9995
|
+
"en-US": { $description: "Compact (downscale auto-screenshots to save ~30-40% bytes; explicit screenshot/zoom keep full clarity)" }
|
|
9996
|
+
})]).default("standard").volatile().i18n({
|
|
9997
|
+
"zh-CN": { $description: "操作后自动回传截图的清晰度档位" },
|
|
9998
|
+
"en-US": { $description: "Detail tier for automatic post-action screenshots" }
|
|
9999
|
+
}),
|
|
9610
10000
|
settleMs: z.natural().max(5e3).default(400).volatile().i18n({
|
|
9611
10001
|
"zh-CN": { $description: "操作后至少等待的毫秒数;之后画面静止即截图(最多约 2.5 秒)" },
|
|
9612
10002
|
"en-US": { $description: "Minimum wait after an action; then the screenshot is taken once the screen stops changing (up to ~2.5 s)" }
|
|
@@ -9640,6 +10030,9 @@ const Config = z.object({
|
|
|
9640
10030
|
"en-US": { $description: "Apps that may never be controlled (names or exe). Common password managers are always blocked." }
|
|
9641
10031
|
})
|
|
9642
10032
|
});
|
|
10033
|
+
function isAgentLike(value) {
|
|
10034
|
+
return value !== null && typeof value === "object" && typeof value.session?.id === "string";
|
|
10035
|
+
}
|
|
9643
10036
|
function apply(ctx, config = {}) {
|
|
9644
10037
|
if (process.platform !== "win32") {
|
|
9645
10038
|
ctx.logger.warn("dsh-computer-use only supports Windows; no tools registered.");
|
|
@@ -9729,6 +10122,69 @@ function apply(ctx, config = {}) {
|
|
|
9729
10122
|
});
|
|
9730
10123
|
for (const tool of tools) ctx.effect(() => ctx.tools.register(tool), `computer-use: tool ${tool.name}`);
|
|
9731
10124
|
const OWN_TOOLS = new Set(tools.map((tool) => tool.name));
|
|
10125
|
+
const ownToolNames = [...OWN_TOOLS];
|
|
10126
|
+
const sessionGate = new SessionGate(void 0, log);
|
|
10127
|
+
const agentsRegistry = () => ctx.get("agents");
|
|
10128
|
+
const restricted = /* @__PURE__ */ new Map();
|
|
10129
|
+
const isSessionEnabled = (agent) => sessionGate.isEnabled(agent.session.id, {
|
|
10130
|
+
defaultEnabled: settings().defaultSessionEnabled,
|
|
10131
|
+
parentIds: parentSessionChain(agent, agentsRegistry())
|
|
10132
|
+
});
|
|
10133
|
+
const syncAgent = (agent) => {
|
|
10134
|
+
const enabled = isSessionEnabled(agent);
|
|
10135
|
+
const active = restricted.get(agent);
|
|
10136
|
+
if (enabled) {
|
|
10137
|
+
if (active) {
|
|
10138
|
+
restricted.delete(agent);
|
|
10139
|
+
try {
|
|
10140
|
+
active();
|
|
10141
|
+
} catch {}
|
|
10142
|
+
}
|
|
10143
|
+
return;
|
|
10144
|
+
}
|
|
10145
|
+
if (active) return;
|
|
10146
|
+
const restrict = agent.ctx?.tools?.restrict;
|
|
10147
|
+
if (typeof restrict !== "function") return;
|
|
10148
|
+
try {
|
|
10149
|
+
const dispose = restrict.call(agent.ctx.tools, { deny: ownToolNames });
|
|
10150
|
+
restricted.set(agent, dispose);
|
|
10151
|
+
} catch (error) {
|
|
10152
|
+
log(`session toggle restrict skipped for ${agent.session.id}: ${String(error)}`);
|
|
10153
|
+
}
|
|
10154
|
+
};
|
|
10155
|
+
const syncAllAgents = () => {
|
|
10156
|
+
const list = agentsRegistry()?.list?.();
|
|
10157
|
+
if (!list) return;
|
|
10158
|
+
for (const agent of list) syncAgent(agent);
|
|
10159
|
+
};
|
|
10160
|
+
const parentIdsFor = (sessionId) => {
|
|
10161
|
+
const registry = agentsRegistry();
|
|
10162
|
+
const agent = registry?.get?.(sessionId);
|
|
10163
|
+
return agent ? parentSessionChain(agent, registry) : [];
|
|
10164
|
+
};
|
|
10165
|
+
ctx.effect(() => ctx.tools.guard((exec) => {
|
|
10166
|
+
if (!OWN_TOOLS.has(exec.name)) return void 0;
|
|
10167
|
+
const agent = exec.agent;
|
|
10168
|
+
if (!agent || isSessionEnabled(agent)) return void 0;
|
|
10169
|
+
return "Computer use is disabled for this session. Ask the user to enable the \"电脑控制\" (Computer use) toggle in the chat composer.";
|
|
10170
|
+
}), "computer-use: session guard");
|
|
10171
|
+
ctx.effect(() => {
|
|
10172
|
+
syncAllAgents();
|
|
10173
|
+
return () => {
|
|
10174
|
+
for (const dispose of restricted.values()) try {
|
|
10175
|
+
dispose();
|
|
10176
|
+
} catch {}
|
|
10177
|
+
restricted.clear();
|
|
10178
|
+
};
|
|
10179
|
+
}, "computer-use: session restrictions");
|
|
10180
|
+
ctx.on("agent/created", ({ agent }) => {
|
|
10181
|
+
syncAgent(agent);
|
|
10182
|
+
});
|
|
10183
|
+
ctx.on("agent/pre-step", ({ agent }, next) => {
|
|
10184
|
+
syncAgent(agent);
|
|
10185
|
+
return next();
|
|
10186
|
+
});
|
|
10187
|
+
ctx.on("loader/volatile-update", (() => syncAllAgents()));
|
|
9732
10188
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
9733
10189
|
if (exec.name !== "request_access" || settings().accessMode !== "per-app") return next();
|
|
9734
10190
|
const agent = exec.agent;
|
|
@@ -9826,8 +10282,16 @@ function apply(ctx, config = {}) {
|
|
|
9826
10282
|
if (status === "idle" && overlay.controller === agent) overlay.end(agent);
|
|
9827
10283
|
});
|
|
9828
10284
|
ctx.on("agent/disposed", ({ agent }) => {
|
|
10285
|
+
const target = agent;
|
|
10286
|
+
const dispose = restricted.get(target);
|
|
10287
|
+
if (dispose) {
|
|
10288
|
+
restricted.delete(target);
|
|
10289
|
+
try {
|
|
10290
|
+
dispose();
|
|
10291
|
+
} catch {}
|
|
10292
|
+
}
|
|
9829
10293
|
overlay.forgetResume(agent);
|
|
9830
|
-
access.forget(
|
|
10294
|
+
access.forget(target.session.id);
|
|
9831
10295
|
if (overlay.controller === agent) overlay.end();
|
|
9832
10296
|
});
|
|
9833
10297
|
ctx.inject(["webServer"], (webCtx) => {
|
|
@@ -9861,30 +10325,22 @@ function apply(ctx, config = {}) {
|
|
|
9861
10325
|
route(SCREENSHOTS_ROUTE, screenshotsRoute(screenshots));
|
|
9862
10326
|
route(SCREENSHOTS_CLEAN_ROUTE, screenshotsCleanRoute(screenshots));
|
|
9863
10327
|
route(SKILLS_ROUTE, skillsRoute(skills));
|
|
10328
|
+
route(SESSION_ROUTE, sessionRoute(sessionGate, settings, parentIdsFor, syncAllAgents));
|
|
9864
10329
|
});
|
|
9865
10330
|
ctx.inject(["systemPrompt"], (promptCtx) => {
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
}
|
|
9878
|
-
};
|
|
9879
|
-
promptCtx.effect(() => {
|
|
9880
|
-
refresh();
|
|
9881
|
-
return () => {
|
|
9882
|
-
dispose?.();
|
|
9883
|
-
dispose = void 0;
|
|
9884
|
-
registered = void 0;
|
|
9885
|
-
};
|
|
9886
|
-
}, "computer-use: prompt");
|
|
9887
|
-
promptCtx.on("loader/volatile-update", (() => refresh()));
|
|
10331
|
+
promptCtx.effect(() => promptCtx.systemPrompt.section({
|
|
10332
|
+
name: "computer-use:guide",
|
|
10333
|
+
order: 72,
|
|
10334
|
+
text: (assembleCtx) => {
|
|
10335
|
+
const c = assembleCtx;
|
|
10336
|
+
const agent = isAgentLike(c?.agent) ? c.agent : isAgentLike(c?.scope) ? c.scope : void 0;
|
|
10337
|
+
const s = settings();
|
|
10338
|
+
if (agent) {
|
|
10339
|
+
if (!isSessionEnabled(agent)) return "";
|
|
10340
|
+
} else if (!s.defaultSessionEnabled) return "";
|
|
10341
|
+
return promptText(s.accessMode);
|
|
10342
|
+
}
|
|
10343
|
+
}), "computer-use: prompt");
|
|
9888
10344
|
});
|
|
9889
10345
|
}
|
|
9890
10346
|
//#endregion
|