@copylee/dsh-computer-use 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/helper/CuHelper.cs +180 -58
- package/helper/deepseek-white.png +0 -0
- package/lib/client.js +758 -0
- package/lib/index.js +271 -91
- package/lib/types/client/index.d.ts +39 -0
- package/lib/types/client/select.d.ts +17 -0
- package/lib/types/computer.d.ts +2 -2
- package/lib/types/helper-client.d.ts +2 -1
- package/lib/types/index.d.ts +4 -3
- package/lib/types/overlay.d.ts +39 -10
- package/lib/types/routes.d.ts +29 -0
- package/lib/types/settings.d.ts +11 -0
- package/package.json +25 -3
package/lib/client.js
ADDED
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@copylee/dsh-computer-use",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
//#endregion
|
|
29
|
+
let react = require("react");
|
|
30
|
+
react = __toESM(react, 1);
|
|
31
|
+
//#region lib/types/settings.js
|
|
32
|
+
/** The Loader entry id (settings namespace); see cordis.patch.yml. */
|
|
33
|
+
const ENTRY_ID = "copylee-computer-use";
|
|
34
|
+
const DEFAULTS = {
|
|
35
|
+
accessMode: "per-app",
|
|
36
|
+
overlay: true,
|
|
37
|
+
overlayLabel: "DeepSeek Harness",
|
|
38
|
+
hostWindow: "card",
|
|
39
|
+
autoScreenshot: true,
|
|
40
|
+
settleMs: 400,
|
|
41
|
+
maxLongEdge: 1366,
|
|
42
|
+
maxPixels: 115e4,
|
|
43
|
+
jpegQuality: 80,
|
|
44
|
+
blockedApps: [],
|
|
45
|
+
pauseOnUserInput: true,
|
|
46
|
+
userIdleMs: 1500
|
|
47
|
+
};
|
|
48
|
+
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
49
|
+
function resolveConfig(raw) {
|
|
50
|
+
const out = {};
|
|
51
|
+
if (raw !== null && typeof raw === "object") for (const [key, value] of Object.entries(raw)) out[key] = value !== null && typeof value === "object" && typeof value.get === "function" ? value.get() : value;
|
|
52
|
+
const num = (key, min, max) => {
|
|
53
|
+
const value = out[key];
|
|
54
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
|
|
55
|
+
};
|
|
56
|
+
const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
|
|
57
|
+
return {
|
|
58
|
+
accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
|
|
59
|
+
overlay: bool("overlay"),
|
|
60
|
+
overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
|
|
61
|
+
hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
|
|
62
|
+
autoScreenshot: bool("autoScreenshot"),
|
|
63
|
+
settleMs: num("settleMs", 0, 5e3),
|
|
64
|
+
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
65
|
+
maxPixels: num("maxPixels", 3e5, 8e6),
|
|
66
|
+
jpegQuality: num("jpegQuality", 30, 100),
|
|
67
|
+
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
68
|
+
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
69
|
+
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region lib/types/client/select.js
|
|
74
|
+
const h$1 = react.createElement;
|
|
75
|
+
/** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
|
|
76
|
+
const selectCss = `
|
|
77
|
+
.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,.3));border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer}
|
|
78
|
+
.dshcu-select:hover{border-color:var(--dsw-alias-border-l3,#888)}
|
|
79
|
+
.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:2px solid var(--dsw-alias-state-business-primary,#2f7cff);outline-offset:2px}
|
|
80
|
+
.dshcu-select:disabled{opacity:.5;cursor:default}
|
|
81
|
+
.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:4px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);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 10px 32px rgba(0,0,0,.16),0 0 0 .5px rgba(0,0,0,.1))}
|
|
82
|
+
.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 8px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none}
|
|
83
|
+
.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
|
|
84
|
+
`;
|
|
85
|
+
function Select({ options, value, disabled, label, onChange }) {
|
|
86
|
+
const id = react.useId();
|
|
87
|
+
const trigger = react.useRef(null);
|
|
88
|
+
const list = react.useRef(null);
|
|
89
|
+
const [open, setOpen] = react.useState(false);
|
|
90
|
+
const [active, setActive] = react.useState(0);
|
|
91
|
+
const [pos, setPos] = react.useState({});
|
|
92
|
+
const selected = options.findIndex((option) => option.value === value);
|
|
93
|
+
const place = react.useCallback(() => {
|
|
94
|
+
const r = trigger.current?.getBoundingClientRect();
|
|
95
|
+
if (!r) return;
|
|
96
|
+
const below = window.innerHeight - r.bottom - 12;
|
|
97
|
+
const above = r.top - 12;
|
|
98
|
+
const up = below < Math.min(options.length * 34 + 8, 220) && above > below;
|
|
99
|
+
const width = Math.min(Math.max(r.width, 180), 440, window.innerWidth - 16);
|
|
100
|
+
setPos({
|
|
101
|
+
left: Math.max(8, Math.min(r.left, window.innerWidth - width - 8)),
|
|
102
|
+
width,
|
|
103
|
+
maxHeight: Math.max(0, Math.min(360, (up ? above : below) - 4)),
|
|
104
|
+
...up ? { bottom: window.innerHeight - r.top + 4 } : { top: r.bottom + 4 }
|
|
105
|
+
});
|
|
106
|
+
}, [options.length]);
|
|
107
|
+
const close = (refocus = false) => {
|
|
108
|
+
setOpen(false);
|
|
109
|
+
if (refocus) trigger.current?.focus();
|
|
110
|
+
};
|
|
111
|
+
const choose = (index) => {
|
|
112
|
+
if (!disabled && options[index]) onChange(options[index].value);
|
|
113
|
+
close(true);
|
|
114
|
+
};
|
|
115
|
+
const show = () => {
|
|
116
|
+
if (!disabled) {
|
|
117
|
+
place();
|
|
118
|
+
setActive(Math.max(0, selected));
|
|
119
|
+
setOpen(true);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
react.useEffect(() => {
|
|
123
|
+
if (disabled) setOpen(false);
|
|
124
|
+
}, [disabled]);
|
|
125
|
+
react.useEffect(() => {
|
|
126
|
+
if (!open) return;
|
|
127
|
+
const pointer = (e) => {
|
|
128
|
+
if (!list.current?.contains(e.target) && !trigger.current?.contains(e.target)) setOpen(false);
|
|
129
|
+
};
|
|
130
|
+
const scroll = (e) => {
|
|
131
|
+
if (!list.current?.contains(e.target)) place();
|
|
132
|
+
};
|
|
133
|
+
document.addEventListener("pointerdown", pointer, true);
|
|
134
|
+
window.addEventListener("scroll", scroll, true);
|
|
135
|
+
window.addEventListener("resize", place);
|
|
136
|
+
return () => {
|
|
137
|
+
document.removeEventListener("pointerdown", pointer, true);
|
|
138
|
+
window.removeEventListener("scroll", scroll, true);
|
|
139
|
+
window.removeEventListener("resize", place);
|
|
140
|
+
};
|
|
141
|
+
}, [open, place]);
|
|
142
|
+
react.useEffect(() => {
|
|
143
|
+
list.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
|
|
144
|
+
}, [active, open]);
|
|
145
|
+
return h$1("div", { style: { minWidth: 0 } }, h$1("button", {
|
|
146
|
+
ref: trigger,
|
|
147
|
+
type: "button",
|
|
148
|
+
className: "dshcu-select",
|
|
149
|
+
disabled,
|
|
150
|
+
role: "combobox",
|
|
151
|
+
"aria-label": label,
|
|
152
|
+
"aria-haspopup": "listbox",
|
|
153
|
+
"aria-expanded": open,
|
|
154
|
+
"aria-controls": open ? `${id}-list` : void 0,
|
|
155
|
+
"aria-activedescendant": open ? `${id}-${active}` : void 0,
|
|
156
|
+
onBlur: () => close(),
|
|
157
|
+
onClick: () => open ? close() : show(),
|
|
158
|
+
onKeyDown: (e) => {
|
|
159
|
+
if (disabled) return;
|
|
160
|
+
if (!open) {
|
|
161
|
+
if ([
|
|
162
|
+
"ArrowDown",
|
|
163
|
+
"ArrowUp",
|
|
164
|
+
"Enter",
|
|
165
|
+
" "
|
|
166
|
+
].includes(e.key)) {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
show();
|
|
169
|
+
}
|
|
170
|
+
} else if (e.key === "Escape") {
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
close(true);
|
|
173
|
+
} else if (e.key === "Tab") close();
|
|
174
|
+
else if ([
|
|
175
|
+
"ArrowDown",
|
|
176
|
+
"ArrowUp",
|
|
177
|
+
"Home",
|
|
178
|
+
"End"
|
|
179
|
+
].includes(e.key)) {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
setActive((i) => e.key === "Home" ? 0 : e.key === "End" ? options.length - 1 : (i + (e.key === "ArrowDown" ? 1 : -1) + options.length) % options.length);
|
|
182
|
+
} else if (["Enter", " "].includes(e.key)) {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
choose(active);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}, h$1("span", { style: {
|
|
188
|
+
flex: 1,
|
|
189
|
+
minWidth: 0,
|
|
190
|
+
overflow: "hidden",
|
|
191
|
+
textOverflow: "ellipsis",
|
|
192
|
+
whiteSpace: "nowrap"
|
|
193
|
+
} }, options[selected]?.label), h$1("svg", {
|
|
194
|
+
width: 14,
|
|
195
|
+
height: 14,
|
|
196
|
+
viewBox: "0 0 16 16",
|
|
197
|
+
"aria-hidden": true,
|
|
198
|
+
style: { transform: open ? "rotate(180deg)" : void 0 }
|
|
199
|
+
}, h$1("path", {
|
|
200
|
+
d: "M4 6l4 4 4-4",
|
|
201
|
+
fill: "none",
|
|
202
|
+
stroke: "currentColor",
|
|
203
|
+
strokeWidth: 1.6
|
|
204
|
+
}))), open ? h$1("div", {
|
|
205
|
+
ref: list,
|
|
206
|
+
id: `${id}-list`,
|
|
207
|
+
role: "listbox",
|
|
208
|
+
"aria-label": label,
|
|
209
|
+
className: "dshcu-menu",
|
|
210
|
+
style: pos
|
|
211
|
+
}, ...options.map((option, i) => h$1("div", {
|
|
212
|
+
key: option.value,
|
|
213
|
+
id: `${id}-${i}`,
|
|
214
|
+
role: "option",
|
|
215
|
+
"aria-selected": i === selected,
|
|
216
|
+
"data-index": i,
|
|
217
|
+
"data-active": i === active,
|
|
218
|
+
className: "dshcu-option",
|
|
219
|
+
onPointerMove: () => setActive(i),
|
|
220
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
221
|
+
onClick: () => choose(i)
|
|
222
|
+
}, h$1("span", { style: { flex: 1 } }, option.label), h$1("span", { style: { width: 14 } }, i === selected ? h$1("svg", {
|
|
223
|
+
width: 14,
|
|
224
|
+
height: 14,
|
|
225
|
+
viewBox: "0 0 16 16",
|
|
226
|
+
"aria-hidden": true
|
|
227
|
+
}, h$1("path", {
|
|
228
|
+
d: "M3.5 8.5 6.5 11.5 12.5 4.5",
|
|
229
|
+
fill: "none",
|
|
230
|
+
stroke: "currentColor",
|
|
231
|
+
strokeWidth: 1.7,
|
|
232
|
+
strokeLinecap: "round",
|
|
233
|
+
strokeLinejoin: "round"
|
|
234
|
+
})) : null)))) : null);
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region lib/types/client/index.js
|
|
238
|
+
/**
|
|
239
|
+
* Browser half: the "电脑控制" (Computer use) section in Settings. It reads the
|
|
240
|
+
* plugin's own Loader entry through `remote.settings.describe()` and writes
|
|
241
|
+
* with `remote.settings.mutate()`; every field is volatile, so a save reaches
|
|
242
|
+
* the next action without a restart. Live status and the overlay preview come
|
|
243
|
+
* from the host routes in ../routes.ts.
|
|
244
|
+
*/
|
|
245
|
+
const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
246
|
+
const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
247
|
+
const h = react.createElement;
|
|
248
|
+
function draftFrom(value) {
|
|
249
|
+
const s = resolveConfig(value);
|
|
250
|
+
return {
|
|
251
|
+
accessMode: s.accessMode,
|
|
252
|
+
blockedApps: s.blockedApps.join("\n"),
|
|
253
|
+
overlay: s.overlay,
|
|
254
|
+
overlayLabel: s.overlayLabel,
|
|
255
|
+
hostWindow: s.hostWindow,
|
|
256
|
+
pauseOnUserInput: s.pauseOnUserInput,
|
|
257
|
+
userIdleMs: String(s.userIdleMs),
|
|
258
|
+
autoScreenshot: s.autoScreenshot,
|
|
259
|
+
settleMs: String(s.settleMs),
|
|
260
|
+
maxLongEdge: String(s.maxLongEdge),
|
|
261
|
+
maxMegapixels: String(Math.round(s.maxPixels / 1e4) / 100),
|
|
262
|
+
jpegQuality: String(s.jpegQuality)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** Range-checked numbers; returns field errors keyed by Draft field. */
|
|
266
|
+
function validate(d) {
|
|
267
|
+
const errors = {};
|
|
268
|
+
const check = (key, min, max) => {
|
|
269
|
+
const n = Number(d[key]);
|
|
270
|
+
if (String(d[key]).trim() === "" || !Number.isFinite(n) || n < min || n > max) errors[key] = `${min} – ${max}`;
|
|
271
|
+
};
|
|
272
|
+
check("userIdleMs", 300, 1e4);
|
|
273
|
+
check("settleMs", 0, 5e3);
|
|
274
|
+
check("maxLongEdge", 640, 3840);
|
|
275
|
+
check("maxMegapixels", .3, 8);
|
|
276
|
+
check("jpegQuality", 30, 100);
|
|
277
|
+
return errors;
|
|
278
|
+
}
|
|
279
|
+
function valuesFrom(d) {
|
|
280
|
+
return {
|
|
281
|
+
accessMode: d.accessMode,
|
|
282
|
+
blockedApps: d.blockedApps.split(/[\n,,]/).map((item) => item.trim()).filter(Boolean),
|
|
283
|
+
overlay: d.overlay,
|
|
284
|
+
overlayLabel: d.overlayLabel.trim() || DEFAULTS.overlayLabel,
|
|
285
|
+
hostWindow: d.hostWindow,
|
|
286
|
+
pauseOnUserInput: d.pauseOnUserInput,
|
|
287
|
+
userIdleMs: Math.round(Number(d.userIdleMs)),
|
|
288
|
+
autoScreenshot: d.autoScreenshot,
|
|
289
|
+
settleMs: Math.round(Number(d.settleMs)),
|
|
290
|
+
maxLongEdge: Math.round(Number(d.maxLongEdge)),
|
|
291
|
+
maxPixels: Math.round(Number(d.maxMegapixels) * 1e6),
|
|
292
|
+
jpegQuality: Math.round(Number(d.jpegQuality))
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const S = {
|
|
296
|
+
page: {
|
|
297
|
+
display: "grid",
|
|
298
|
+
gap: 20,
|
|
299
|
+
maxWidth: 880,
|
|
300
|
+
paddingBottom: 32,
|
|
301
|
+
color: "var(--dsw-alias-label-primary, inherit)"
|
|
302
|
+
},
|
|
303
|
+
title: {
|
|
304
|
+
margin: 0,
|
|
305
|
+
fontSize: 20,
|
|
306
|
+
fontWeight: 600
|
|
307
|
+
},
|
|
308
|
+
subtitle: {
|
|
309
|
+
margin: "6px 0 0",
|
|
310
|
+
fontSize: 13,
|
|
311
|
+
lineHeight: 1.6,
|
|
312
|
+
color: "var(--dsw-alias-label-secondary, #666)"
|
|
313
|
+
},
|
|
314
|
+
card: {
|
|
315
|
+
display: "grid",
|
|
316
|
+
gap: 14,
|
|
317
|
+
padding: 16,
|
|
318
|
+
borderRadius: "var(--dsw-radius-lg, 12px)",
|
|
319
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))"
|
|
320
|
+
},
|
|
321
|
+
cardTitle: {
|
|
322
|
+
margin: 0,
|
|
323
|
+
fontSize: 15,
|
|
324
|
+
fontWeight: 600
|
|
325
|
+
},
|
|
326
|
+
hint: {
|
|
327
|
+
margin: 0,
|
|
328
|
+
fontSize: 12,
|
|
329
|
+
lineHeight: 1.55,
|
|
330
|
+
color: "var(--dsw-alias-label-tertiary, #888)"
|
|
331
|
+
},
|
|
332
|
+
label: {
|
|
333
|
+
display: "grid",
|
|
334
|
+
gap: 6,
|
|
335
|
+
fontSize: 13,
|
|
336
|
+
fontWeight: 500
|
|
337
|
+
},
|
|
338
|
+
grid2: {
|
|
339
|
+
display: "grid",
|
|
340
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
|
|
341
|
+
gap: 14
|
|
342
|
+
},
|
|
343
|
+
input: {
|
|
344
|
+
boxSizing: "border-box",
|
|
345
|
+
width: "100%",
|
|
346
|
+
padding: "8px 10px",
|
|
347
|
+
fontSize: 13,
|
|
348
|
+
borderRadius: "var(--dsw-radius-md, 8px)",
|
|
349
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3))",
|
|
350
|
+
background: "transparent",
|
|
351
|
+
color: "inherit"
|
|
352
|
+
},
|
|
353
|
+
toggleRow: {
|
|
354
|
+
display: "flex",
|
|
355
|
+
gap: 12,
|
|
356
|
+
alignItems: "flex-start",
|
|
357
|
+
justifyContent: "space-between"
|
|
358
|
+
},
|
|
359
|
+
toggleText: {
|
|
360
|
+
display: "grid",
|
|
361
|
+
gap: 4,
|
|
362
|
+
fontSize: 13,
|
|
363
|
+
fontWeight: 500
|
|
364
|
+
},
|
|
365
|
+
error: {
|
|
366
|
+
fontSize: 12,
|
|
367
|
+
color: "var(--dsw-alias-state-error-primary, #d33)"
|
|
368
|
+
},
|
|
369
|
+
ok: {
|
|
370
|
+
fontSize: 12,
|
|
371
|
+
color: "var(--dsw-alias-state-success-primary, #2a2)"
|
|
372
|
+
},
|
|
373
|
+
actions: {
|
|
374
|
+
display: "flex",
|
|
375
|
+
gap: 10,
|
|
376
|
+
alignItems: "center",
|
|
377
|
+
flexWrap: "wrap"
|
|
378
|
+
},
|
|
379
|
+
primary: {
|
|
380
|
+
padding: "7px 16px",
|
|
381
|
+
fontSize: 13,
|
|
382
|
+
borderRadius: "var(--dsw-radius-md, 8px)",
|
|
383
|
+
border: "1px solid #D97757",
|
|
384
|
+
background: "#D97757",
|
|
385
|
+
color: "#fff",
|
|
386
|
+
cursor: "pointer"
|
|
387
|
+
},
|
|
388
|
+
secondary: {
|
|
389
|
+
padding: "7px 14px",
|
|
390
|
+
fontSize: 13,
|
|
391
|
+
borderRadius: "var(--dsw-radius-md, 8px)",
|
|
392
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3))",
|
|
393
|
+
background: "transparent",
|
|
394
|
+
color: "inherit",
|
|
395
|
+
cursor: "pointer"
|
|
396
|
+
},
|
|
397
|
+
statusLine: {
|
|
398
|
+
display: "flex",
|
|
399
|
+
gap: 8,
|
|
400
|
+
alignItems: "center",
|
|
401
|
+
fontSize: 13
|
|
402
|
+
},
|
|
403
|
+
dot: {
|
|
404
|
+
width: 8,
|
|
405
|
+
height: 8,
|
|
406
|
+
borderRadius: 4,
|
|
407
|
+
flex: "0 0 auto"
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
function Switch({ checked, disabled, label, onChange }) {
|
|
411
|
+
return h("button", {
|
|
412
|
+
type: "button",
|
|
413
|
+
role: "switch",
|
|
414
|
+
"aria-checked": checked,
|
|
415
|
+
"aria-label": label,
|
|
416
|
+
disabled,
|
|
417
|
+
onClick: () => onChange(!checked),
|
|
418
|
+
style: {
|
|
419
|
+
flex: "0 0 auto",
|
|
420
|
+
width: 40,
|
|
421
|
+
height: 22,
|
|
422
|
+
borderRadius: 11,
|
|
423
|
+
border: "none",
|
|
424
|
+
padding: 2,
|
|
425
|
+
cursor: disabled ? "default" : "pointer",
|
|
426
|
+
background: checked ? "#D97757" : "var(--dsw-alias-border-l3, rgba(127,127,127,.35))",
|
|
427
|
+
opacity: disabled ? .5 : 1,
|
|
428
|
+
transition: "background .15s"
|
|
429
|
+
}
|
|
430
|
+
}, h("span", { style: {
|
|
431
|
+
display: "block",
|
|
432
|
+
width: 18,
|
|
433
|
+
height: 18,
|
|
434
|
+
borderRadius: 9,
|
|
435
|
+
background: "#fff",
|
|
436
|
+
transform: checked ? "translateX(18px)" : "none",
|
|
437
|
+
transition: "transform .15s"
|
|
438
|
+
} }));
|
|
439
|
+
}
|
|
440
|
+
function ToggleRow({ title, hint, checked, disabled, onChange }) {
|
|
441
|
+
return h("div", { style: S.toggleRow }, h("div", { style: S.toggleText }, title, h("span", { style: {
|
|
442
|
+
...S.hint,
|
|
443
|
+
fontWeight: 400
|
|
444
|
+
} }, hint)), h(Switch, {
|
|
445
|
+
checked,
|
|
446
|
+
disabled,
|
|
447
|
+
label: title,
|
|
448
|
+
onChange
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
function NumberField({ label, unit, value, error, disabled, onChange }) {
|
|
452
|
+
return h("label", { style: S.label }, label, h("div", { style: {
|
|
453
|
+
display: "flex",
|
|
454
|
+
gap: 8,
|
|
455
|
+
alignItems: "center"
|
|
456
|
+
} }, h("input", {
|
|
457
|
+
style: S.input,
|
|
458
|
+
inputMode: "decimal",
|
|
459
|
+
value,
|
|
460
|
+
disabled,
|
|
461
|
+
onChange: (e) => onChange(e.target.value)
|
|
462
|
+
}), h("span", { style: {
|
|
463
|
+
...S.hint,
|
|
464
|
+
whiteSpace: "nowrap"
|
|
465
|
+
} }, unit)), error === void 0 ? null : h("span", { style: S.error }, `范围 ${error}`));
|
|
466
|
+
}
|
|
467
|
+
function ComputerUseSection({ ctx }) {
|
|
468
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
469
|
+
const [writable, setWritable] = react.useState(false);
|
|
470
|
+
const [view, setView] = react.useState(void 0);
|
|
471
|
+
const [draft, setDraft] = react.useState(() => draftFrom(void 0));
|
|
472
|
+
const [dirty, setDirty] = react.useState(false);
|
|
473
|
+
const [saving, setSaving] = react.useState(false);
|
|
474
|
+
const [message, setMessage] = react.useState(null);
|
|
475
|
+
const [status, setStatus] = react.useState(null);
|
|
476
|
+
const dirtyRef = react.useRef(false);
|
|
477
|
+
dirtyRef.current = dirty;
|
|
478
|
+
const load = react.useCallback(async (reset) => {
|
|
479
|
+
try {
|
|
480
|
+
const result = await ctx.remote.settings.describe();
|
|
481
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
482
|
+
const found = result.value.namespaces.find((item) => item.ns === ENTRY_ID);
|
|
483
|
+
setWritable(result.value.writable);
|
|
484
|
+
setView(found);
|
|
485
|
+
if (reset || !dirtyRef.current) {
|
|
486
|
+
setDraft(draftFrom(found?.value));
|
|
487
|
+
setDirty(false);
|
|
488
|
+
}
|
|
489
|
+
} catch (error) {
|
|
490
|
+
setMessage({
|
|
491
|
+
kind: "error",
|
|
492
|
+
text: `读取设置失败:${error.message}`
|
|
493
|
+
});
|
|
494
|
+
} finally {
|
|
495
|
+
setLoaded(true);
|
|
496
|
+
}
|
|
497
|
+
}, [ctx]);
|
|
498
|
+
const refreshStatus = react.useCallback(async () => {
|
|
499
|
+
try {
|
|
500
|
+
const response = await fetch(STATUS_ROUTE, { credentials: "same-origin" });
|
|
501
|
+
setStatus(await response.json());
|
|
502
|
+
} catch {
|
|
503
|
+
setStatus(null);
|
|
504
|
+
}
|
|
505
|
+
}, []);
|
|
506
|
+
react.useEffect(() => {
|
|
507
|
+
load(true);
|
|
508
|
+
refreshStatus();
|
|
509
|
+
return ctx.remote.$on?.("settings/document-updated", (ns) => {
|
|
510
|
+
if (ns === "copylee-computer-use") {
|
|
511
|
+
load(false);
|
|
512
|
+
refreshStatus();
|
|
513
|
+
}
|
|
514
|
+
}) ?? void 0;
|
|
515
|
+
}, [
|
|
516
|
+
ctx,
|
|
517
|
+
load,
|
|
518
|
+
refreshStatus
|
|
519
|
+
]);
|
|
520
|
+
const edit = (key, value) => {
|
|
521
|
+
setDraft((previous) => ({
|
|
522
|
+
...previous,
|
|
523
|
+
[key]: value
|
|
524
|
+
}));
|
|
525
|
+
setDirty(true);
|
|
526
|
+
setMessage(null);
|
|
527
|
+
};
|
|
528
|
+
const errors = validate(draft);
|
|
529
|
+
const invalid = Object.keys(errors).length > 0;
|
|
530
|
+
const disabled = !writable || view === void 0 || saving;
|
|
531
|
+
const save = async () => {
|
|
532
|
+
if (view === void 0 || invalid) return;
|
|
533
|
+
setSaving(true);
|
|
534
|
+
try {
|
|
535
|
+
const values = valuesFrom(draft);
|
|
536
|
+
const result = await ctx.remote.settings.mutate(ENTRY_ID, Object.entries(values).map(([key, value]) => ({
|
|
537
|
+
op: "set",
|
|
538
|
+
path: [key],
|
|
539
|
+
value
|
|
540
|
+
})), view.revision);
|
|
541
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
542
|
+
setMessage({
|
|
543
|
+
kind: "ok",
|
|
544
|
+
text: "已保存,下一步操作即生效"
|
|
545
|
+
});
|
|
546
|
+
setDirty(false);
|
|
547
|
+
await load(true);
|
|
548
|
+
refreshStatus();
|
|
549
|
+
} catch (error) {
|
|
550
|
+
setMessage({
|
|
551
|
+
kind: "error",
|
|
552
|
+
text: `保存失败:${error.message}`
|
|
553
|
+
});
|
|
554
|
+
} finally {
|
|
555
|
+
setSaving(false);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
const preview = async () => {
|
|
559
|
+
try {
|
|
560
|
+
const response = await fetch(PREVIEW_ROUTE, {
|
|
561
|
+
method: "POST",
|
|
562
|
+
credentials: "same-origin"
|
|
563
|
+
});
|
|
564
|
+
if (response.status === 409) setMessage({
|
|
565
|
+
kind: "error",
|
|
566
|
+
text: "AI 正在操控电脑,暂时不能预览"
|
|
567
|
+
});
|
|
568
|
+
else if (!response.ok) setMessage({
|
|
569
|
+
kind: "error",
|
|
570
|
+
text: "预览失败"
|
|
571
|
+
});
|
|
572
|
+
} catch {
|
|
573
|
+
setMessage({
|
|
574
|
+
kind: "error",
|
|
575
|
+
text: "预览失败"
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
if (!loaded) return h("div", { style: S.page }, "加载中…");
|
|
580
|
+
const primary = status?.displays.find((d) => d.primary) ?? status?.displays[0];
|
|
581
|
+
const helperOk = status?.helper === "ready";
|
|
582
|
+
return h("div", { style: S.page }, h("style", null, selectCss), h("div", null, h("h2", { style: S.title }, "电脑控制"), h("p", { style: S.subtitle }, "让 AI 看屏幕、点鼠标、敲键盘操控这台 Windows 电脑。操控时屏幕四周泛起橙色光晕;按 Esc 暂停 / 继续,点提示条上的“停止”结束本轮。")), view === void 0 ? h("div", { style: S.error }, "没有找到本插件的设置项(插件可能未启用)。") : null, view !== void 0 && !writable ? h("div", { style: S.error }, "当前设置为只读。") : null, h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "运行状态"), h("div", { style: S.statusLine }, h("span", { style: {
|
|
583
|
+
...S.dot,
|
|
584
|
+
background: status === null ? "#999" : helperOk ? "#2a2" : "#d33"
|
|
585
|
+
} }), status === null ? "无法获取状态" : helperOk ? status.controlling ? "正在操控电脑" : "就绪" : `控制组件不可用:${status.error ?? ""}`), primary ? h("p", { style: S.hint }, `主屏幕 ${primary.width}×${primary.height}(${Math.round(primary.dpi / 96 * 100)}% 缩放),发给模型的截图为 ${primary.shot.width}×${primary.shot.height}。`) : null, status && status.displays.length > 1 ? h("p", { style: S.hint }, `共 ${status.displays.length} 块显示器,模型可用 switch_display 切换。`) : null, h("div", { style: S.actions }, h("button", {
|
|
586
|
+
type: "button",
|
|
587
|
+
style: S.secondary,
|
|
588
|
+
onClick: () => {
|
|
589
|
+
preview();
|
|
590
|
+
}
|
|
591
|
+
}, "预览效果"), h("button", {
|
|
592
|
+
type: "button",
|
|
593
|
+
style: S.secondary,
|
|
594
|
+
onClick: () => {
|
|
595
|
+
refreshStatus();
|
|
596
|
+
}
|
|
597
|
+
}, "刷新状态"), h("span", { style: S.hint }, "预览会显示 3 秒光晕和提示条(按已保存的设置)。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "授权"), h("div", { style: S.label }, "授权方式", h(Select, {
|
|
598
|
+
label: "授权方式",
|
|
599
|
+
disabled,
|
|
600
|
+
value: draft.accessMode,
|
|
601
|
+
options: [{
|
|
602
|
+
value: "per-app",
|
|
603
|
+
label: "按应用授权(每个会话由你批准要操控的应用)"
|
|
604
|
+
}, {
|
|
605
|
+
value: "allow-all",
|
|
606
|
+
label: "全部允许(不弹审批)"
|
|
607
|
+
}],
|
|
608
|
+
onChange: (value) => edit("accessMode", value)
|
|
609
|
+
}), h("span", { style: {
|
|
610
|
+
...S.hint,
|
|
611
|
+
fontWeight: 400
|
|
612
|
+
} }, "会话权限为“完全权限”或“自动审查”时不弹审批,按应用授权会自动批准。无论哪种方式,DeepSeek Harness 自己的窗口都不会被操作。")), h("label", { style: S.label }, "禁止操控的应用", h("textarea", {
|
|
613
|
+
style: {
|
|
614
|
+
...S.input,
|
|
615
|
+
minHeight: 72,
|
|
616
|
+
resize: "vertical"
|
|
617
|
+
},
|
|
618
|
+
value: draft.blockedApps,
|
|
619
|
+
disabled,
|
|
620
|
+
spellCheck: false,
|
|
621
|
+
placeholder: "每行一个,名称或 exe,例如:\nalipay\n网银助手",
|
|
622
|
+
onChange: (e) => edit("blockedApps", e.target.value)
|
|
623
|
+
}), h("span", { style: {
|
|
624
|
+
...S.hint,
|
|
625
|
+
fontWeight: 400
|
|
626
|
+
} }, "1Password、Bitwarden、KeePass 等常见密码管理器始终禁止。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "操控时的显示"), h(ToggleRow, {
|
|
627
|
+
title: "橙色光晕与提示条",
|
|
628
|
+
hint: "不会出现在模型看到的截图里。",
|
|
629
|
+
checked: draft.overlay,
|
|
630
|
+
disabled,
|
|
631
|
+
onChange: (value) => edit("overlay", value)
|
|
632
|
+
}), h("div", { style: S.grid2 }, h("label", { style: S.label }, "提示条名称", h("input", {
|
|
633
|
+
style: S.input,
|
|
634
|
+
value: draft.overlayLabel,
|
|
635
|
+
disabled,
|
|
636
|
+
maxLength: 40,
|
|
637
|
+
onChange: (e) => edit("overlayLabel", e.target.value)
|
|
638
|
+
}), h("span", { style: {
|
|
639
|
+
...S.hint,
|
|
640
|
+
fontWeight: 400
|
|
641
|
+
} }, `显示为“${draft.overlayLabel.trim() || DEFAULTS.overlayLabel} 正在操控你的电脑”`)), h("div", { style: S.label }, "DeepSeek Harness 窗口", h(Select, {
|
|
642
|
+
label: "DeepSeek Harness 窗口",
|
|
643
|
+
disabled,
|
|
644
|
+
value: draft.hostWindow,
|
|
645
|
+
options: [
|
|
646
|
+
{
|
|
647
|
+
value: "card",
|
|
648
|
+
label: "缩成右下角置顶悬浮卡片"
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
value: "minimize",
|
|
652
|
+
label: "最小化"
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
value: "keep",
|
|
656
|
+
label: "保持不变"
|
|
657
|
+
}
|
|
658
|
+
],
|
|
659
|
+
onChange: (value) => edit("hostWindow", value)
|
|
660
|
+
}), h("span", { style: {
|
|
661
|
+
...S.hint,
|
|
662
|
+
fontWeight: 400
|
|
663
|
+
} }, "操控结束后自动恢复原尺寸和位置。")))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "让出控制"), h(ToggleRow, {
|
|
664
|
+
title: "检测到你在操作时暂停",
|
|
665
|
+
hint: "你用键盘打字时 AI 等你停手;你切换了窗口时 AI 先重新看屏幕。鼠标移动不会触发。",
|
|
666
|
+
checked: draft.pauseOnUserInput,
|
|
667
|
+
disabled,
|
|
668
|
+
onChange: (value) => edit("pauseOnUserInput", value)
|
|
669
|
+
}), h("div", { style: S.grid2 }, h(NumberField, {
|
|
670
|
+
label: "停手多久后继续",
|
|
671
|
+
unit: "毫秒",
|
|
672
|
+
value: draft.userIdleMs,
|
|
673
|
+
error: errors.userIdleMs,
|
|
674
|
+
disabled: disabled || !draft.pauseOnUserInput,
|
|
675
|
+
onChange: (value) => edit("userIdleMs", value)
|
|
676
|
+
}))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图"), h(ToggleRow, {
|
|
677
|
+
title: "操作后自动回传截图",
|
|
678
|
+
hint: "省去模型再截一次图的一轮调用;关闭可省 token。",
|
|
679
|
+
checked: draft.autoScreenshot,
|
|
680
|
+
disabled,
|
|
681
|
+
onChange: (value) => edit("autoScreenshot", value)
|
|
682
|
+
}), h("div", { style: S.grid2 }, h(NumberField, {
|
|
683
|
+
label: "操作后等待界面稳定",
|
|
684
|
+
unit: "毫秒",
|
|
685
|
+
value: draft.settleMs,
|
|
686
|
+
error: errors.settleMs,
|
|
687
|
+
disabled,
|
|
688
|
+
onChange: (value) => edit("settleMs", value)
|
|
689
|
+
}), h(NumberField, {
|
|
690
|
+
label: "截图最长边",
|
|
691
|
+
unit: "像素",
|
|
692
|
+
value: draft.maxLongEdge,
|
|
693
|
+
error: errors.maxLongEdge,
|
|
694
|
+
disabled,
|
|
695
|
+
onChange: (value) => edit("maxLongEdge", value)
|
|
696
|
+
}), h(NumberField, {
|
|
697
|
+
label: "截图总像素上限",
|
|
698
|
+
unit: "百万像素",
|
|
699
|
+
value: draft.maxMegapixels,
|
|
700
|
+
error: errors.maxMegapixels,
|
|
701
|
+
disabled,
|
|
702
|
+
onChange: (value) => edit("maxMegapixels", value)
|
|
703
|
+
}), h(NumberField, {
|
|
704
|
+
label: "JPEG 质量",
|
|
705
|
+
unit: "30–100",
|
|
706
|
+
value: draft.jpegQuality,
|
|
707
|
+
error: errors.jpegQuality,
|
|
708
|
+
disabled,
|
|
709
|
+
onChange: (value) => edit("jpegQuality", value)
|
|
710
|
+
})), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h("div", { style: S.actions }, h("button", {
|
|
711
|
+
type: "button",
|
|
712
|
+
style: {
|
|
713
|
+
...S.primary,
|
|
714
|
+
opacity: disabled || !dirty || invalid ? .5 : 1
|
|
715
|
+
},
|
|
716
|
+
disabled: disabled || !dirty || invalid,
|
|
717
|
+
onClick: () => {
|
|
718
|
+
save();
|
|
719
|
+
}
|
|
720
|
+
}, saving ? "保存中…" : "保存"), h("button", {
|
|
721
|
+
type: "button",
|
|
722
|
+
style: S.secondary,
|
|
723
|
+
disabled: !dirty || saving,
|
|
724
|
+
onClick: () => {
|
|
725
|
+
setDraft(draftFrom(view?.value));
|
|
726
|
+
setDirty(false);
|
|
727
|
+
setMessage(null);
|
|
728
|
+
}
|
|
729
|
+
}, "放弃修改"), h("button", {
|
|
730
|
+
type: "button",
|
|
731
|
+
style: S.secondary,
|
|
732
|
+
disabled,
|
|
733
|
+
onClick: () => {
|
|
734
|
+
setDraft(draftFrom({}));
|
|
735
|
+
setDirty(true);
|
|
736
|
+
setMessage(null);
|
|
737
|
+
}
|
|
738
|
+
}, "恢复默认"), dirty ? h("span", { style: S.hint }, "有未保存的修改") : null, message === null ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)));
|
|
739
|
+
}
|
|
740
|
+
const inject = [
|
|
741
|
+
"slots",
|
|
742
|
+
"remote",
|
|
743
|
+
"remote.settings"
|
|
744
|
+
];
|
|
745
|
+
function apply(ctx) {
|
|
746
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
747
|
+
name: "settings.section",
|
|
748
|
+
id: ENTRY_ID,
|
|
749
|
+
order: 61,
|
|
750
|
+
label: () => "电脑控制"
|
|
751
|
+
}, () => h(ComputerUseSection, { ctx })));
|
|
752
|
+
}
|
|
753
|
+
//#endregion
|
|
754
|
+
exports.apply = apply;
|
|
755
|
+
exports.inject = inject;
|
|
756
|
+
return module.exports;
|
|
757
|
+
}
|
|
758
|
+
});
|