@copylee/dsh-computer-use 0.1.3 → 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 CHANGED
@@ -61,7 +61,7 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
61
61
 
62
62
  ## 设置
63
63
 
64
- 在 **设置 → 插件 → dsh-computer-use** 中修改,均即时生效:
64
+ 在 **设置 → 电脑控制** 中修改,保存后下一步操作即生效。页面上还能看到运行状态(屏幕分辨率、缩放比例和实际发给模型的截图尺寸),并可点“预览效果”看 3 秒光晕和提示条:
65
65
 
66
66
  | 选项 | 默认 | 说明 |
67
67
  |---|---|---|
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
+ });
package/lib/index.js CHANGED
@@ -1218,6 +1218,120 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1218
1218
  - The user sees an orange border and can press Esc to pause you at any time. If they pause, type on the keyboard or switch windows, you wait; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
1219
1219
  }
1220
1220
  //#endregion
1221
+ //#region lib/types/settings.js
1222
+ /** The Loader entry id (settings namespace); see cordis.patch.yml. */
1223
+ const ENTRY_ID = "copylee-computer-use";
1224
+ const DEFAULTS = {
1225
+ accessMode: "per-app",
1226
+ overlay: true,
1227
+ overlayLabel: "DeepSeek Harness",
1228
+ hostWindow: "card",
1229
+ autoScreenshot: true,
1230
+ settleMs: 400,
1231
+ maxLongEdge: 1366,
1232
+ maxPixels: 115e4,
1233
+ jpegQuality: 80,
1234
+ blockedApps: [],
1235
+ pauseOnUserInput: true,
1236
+ userIdleMs: 1500
1237
+ };
1238
+ /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
1239
+ function resolveConfig(raw) {
1240
+ const out = {};
1241
+ 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;
1242
+ const num = (key, min, max) => {
1243
+ const value = out[key];
1244
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
1245
+ };
1246
+ const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
1247
+ return {
1248
+ accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
1249
+ overlay: bool("overlay"),
1250
+ overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
1251
+ hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
1252
+ autoScreenshot: bool("autoScreenshot"),
1253
+ settleMs: num("settleMs", 0, 5e3),
1254
+ maxLongEdge: num("maxLongEdge", 640, 3840),
1255
+ maxPixels: num("maxPixels", 3e5, 8e6),
1256
+ jpegQuality: num("jpegQuality", 30, 100),
1257
+ pauseOnUserInput: bool("pauseOnUserInput"),
1258
+ userIdleMs: num("userIdleMs", 300, 1e4),
1259
+ blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
1260
+ };
1261
+ }
1262
+ //#endregion
1263
+ //#region lib/types/routes.js
1264
+ const STATUS_ROUTE = "/api/dsh-computer-use/status";
1265
+ const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
1266
+ function json(res, status, body) {
1267
+ res.writeHead(status, {
1268
+ "content-type": "application/json; charset=utf-8",
1269
+ "cache-control": "no-store"
1270
+ });
1271
+ res.end(JSON.stringify(body));
1272
+ }
1273
+ function statusRoute(helper, settings, overlay) {
1274
+ return async (_req, res) => {
1275
+ const s = settings();
1276
+ try {
1277
+ const displays = await helper.call("displays", {}, 3e4);
1278
+ json(res, 200, {
1279
+ ok: true,
1280
+ platform: process.platform,
1281
+ helper: "ready",
1282
+ displays: displays.map((d) => ({
1283
+ ...d,
1284
+ shot: screenshotSize(d, {
1285
+ maxLongEdge: s.maxLongEdge,
1286
+ maxPixels: s.maxPixels
1287
+ })
1288
+ })),
1289
+ controlling: overlay.controller !== void 0
1290
+ });
1291
+ } catch (error) {
1292
+ json(res, 200, {
1293
+ ok: true,
1294
+ platform: process.platform,
1295
+ helper: "error",
1296
+ error: error instanceof Error ? error.message : String(error),
1297
+ displays: [],
1298
+ controlling: false
1299
+ });
1300
+ }
1301
+ };
1302
+ }
1303
+ /** Show the overlay for a few seconds so the user can see how it looks (skipped while an agent is controlling). */
1304
+ function previewRoute(helper, settings, overlay, iconPath) {
1305
+ return async (req, res) => {
1306
+ if (req.method !== "POST") {
1307
+ json(res, 405, {
1308
+ ok: false,
1309
+ error: "POST only"
1310
+ });
1311
+ return;
1312
+ }
1313
+ if (overlay.controller !== void 0) {
1314
+ json(res, 409, {
1315
+ ok: false,
1316
+ error: "busy"
1317
+ });
1318
+ return;
1319
+ }
1320
+ const s = settings();
1321
+ await helper.call("overlay_show", {
1322
+ label: `${s.overlayLabel} 正在操控你的电脑`,
1323
+ status: "预览 · 3 秒后消失",
1324
+ icon: iconPath,
1325
+ idleMs: s.userIdleMs,
1326
+ glow: s.overlay
1327
+ });
1328
+ setTimeout(() => {
1329
+ if (overlay.controller === void 0) helper.call("overlay_hide").catch(() => {});
1330
+ }, 3e3).unref();
1331
+ json(res, 200, { ok: true });
1332
+ };
1333
+ }
1334
+ //#endregion
1221
1335
  //#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
1222
1336
  /**
1223
1337
  * Shared insertion-ordered storage and effect ownership for scope-aware registries.
@@ -7272,20 +7386,6 @@ function createTools(host) {
7272
7386
  //#region lib/types/index.js
7273
7387
  const name = "@copylee/dsh-computer-use";
7274
7388
  const inject = ["tools", "attachments"];
7275
- const DEFAULTS = {
7276
- accessMode: "per-app",
7277
- overlay: true,
7278
- overlayLabel: "DeepSeek Harness",
7279
- hostWindow: "card",
7280
- autoScreenshot: true,
7281
- settleMs: 400,
7282
- maxLongEdge: 1366,
7283
- maxPixels: 115e4,
7284
- jpegQuality: 80,
7285
- blockedApps: [],
7286
- pauseOnUserInput: true,
7287
- userIdleMs: 1500
7288
- };
7289
7389
  const Config = z.object({
7290
7390
  accessMode: z.union([z.const("per-app").i18n({
7291
7391
  "zh-CN": { $description: "按应用授权(每个会话由你批准要操控的应用)" },
@@ -7355,30 +7455,6 @@ const Config = z.object({
7355
7455
  "en-US": { $description: "Apps that may never be controlled (names or exe). Common password managers are always blocked." }
7356
7456
  })
7357
7457
  });
7358
- /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
7359
- function resolveConfig(raw) {
7360
- const out = {};
7361
- 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;
7362
- const num = (key, min, max) => {
7363
- const value = out[key];
7364
- return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
7365
- };
7366
- const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
7367
- return {
7368
- accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
7369
- overlay: bool("overlay"),
7370
- overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
7371
- hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
7372
- autoScreenshot: bool("autoScreenshot"),
7373
- settleMs: num("settleMs", 0, 5e3),
7374
- maxLongEdge: num("maxLongEdge", 640, 3840),
7375
- maxPixels: num("maxPixels", 3e5, 8e6),
7376
- jpegQuality: num("jpegQuality", 30, 100),
7377
- pauseOnUserInput: bool("pauseOnUserInput"),
7378
- userIdleMs: num("userIdleMs", 300, 1e4),
7379
- blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
7380
- };
7381
- }
7382
7458
  function apply(ctx, config = {}) {
7383
7459
  if (process.platform !== "win32") {
7384
7460
  ctx.logger.warn("dsh-computer-use only supports Windows; no tools registered.");
@@ -7388,7 +7464,8 @@ function apply(ctx, config = {}) {
7388
7464
  const log = (message) => ctx.logger.info(message);
7389
7465
  const helper = new HelperClient((message) => ctx.logger.warn(message));
7390
7466
  const access = new AccessControl();
7391
- const overlay = new OverlayController(helper, settings, log, helperAssetPath("deepseek-white.png"));
7467
+ const iconPath = helperAssetPath("deepseek-white.png");
7468
+ const overlay = new OverlayController(helper, settings, log, iconPath);
7392
7469
  const computer = new Computer(helper, access, overlay, settings);
7393
7470
  ctx.effect(() => () => {
7394
7471
  overlay.end().finally(() => helper.dispose());
@@ -7456,6 +7533,35 @@ function apply(ctx, config = {}) {
7456
7533
  access.forget(agent.session.id);
7457
7534
  if (overlay.controller === agent) overlay.end();
7458
7535
  });
7536
+ ctx.inject(["webServer"], (webCtx) => {
7537
+ const route = (path, handler) => {
7538
+ const safe = async (req, res) => {
7539
+ try {
7540
+ await handler(req, res);
7541
+ } catch (error) {
7542
+ if (res.headersSent) {
7543
+ res.destroy();
7544
+ return;
7545
+ }
7546
+ res.writeHead(500, {
7547
+ "content-type": "application/json",
7548
+ "cache-control": "no-store"
7549
+ });
7550
+ res.end(JSON.stringify({
7551
+ ok: false,
7552
+ error: error instanceof Error ? error.message : String(error)
7553
+ }));
7554
+ }
7555
+ };
7556
+ webCtx.effect(() => webCtx.webServer.register({
7557
+ kind: "exact",
7558
+ path,
7559
+ handler: safe
7560
+ }), `computer-use: ${path}`);
7561
+ };
7562
+ route(STATUS_ROUTE, statusRoute(helper, settings, overlay));
7563
+ route(PREVIEW_ROUTE, previewRoute(helper, settings, overlay, iconPath));
7564
+ });
7459
7565
  ctx.inject(["systemPrompt"], (promptCtx) => {
7460
7566
  let registered;
7461
7567
  let dispose;
@@ -7482,4 +7588,4 @@ function apply(ctx, config = {}) {
7482
7588
  });
7483
7589
  }
7484
7590
  //#endregion
7485
- export { Config, apply, inject, name, resolveConfig };
7591
+ export { Config, DEFAULTS, ENTRY_ID, apply, inject, name, resolveConfig };
@@ -0,0 +1,39 @@
1
+ type RemoteResult<T> = {
2
+ ok: true;
3
+ value: T;
4
+ } | {
5
+ ok: false;
6
+ error: {
7
+ code?: string;
8
+ message: string;
9
+ };
10
+ };
11
+ interface NamespaceView {
12
+ ns: string;
13
+ value: unknown;
14
+ revision: number;
15
+ }
16
+ interface ClientContext {
17
+ effect(execute: () => (() => void) | void, label?: string): void;
18
+ slots: {
19
+ inject(name: string, register: () => unknown): void;
20
+ register(meta: Record<string, unknown>, render: (props: unknown) => unknown): unknown;
21
+ };
22
+ remote: {
23
+ $on?(event: string, listener: (...args: unknown[]) => void): () => void;
24
+ settings: {
25
+ describe(): Promise<RemoteResult<{
26
+ writable: boolean;
27
+ namespaces: NamespaceView[];
28
+ }>>;
29
+ mutate(ns: string, ops: {
30
+ op: 'set' | 'unset';
31
+ path: string[];
32
+ value?: unknown;
33
+ }[], expectedRevision?: number): Promise<RemoteResult<unknown>>;
34
+ };
35
+ };
36
+ }
37
+ export declare const inject: string[];
38
+ export declare function apply(ctx: ClientContext): void;
39
+ export {};
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
3
+ export declare const selectCss = "\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,.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}\n.dshcu-select:hover{border-color:var(--dsw-alias-border-l3,#888)}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:2px solid var(--dsw-alias-state-business-primary,#2f7cff);outline-offset:2px}\n.dshcu-select:disabled{opacity:.5;cursor:default}\n.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))}\n.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}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}\n";
4
+ export declare function Select<V extends string>({ options, value, disabled, label, onChange }: {
5
+ options: {
6
+ value: V;
7
+ label: string;
8
+ }[];
9
+ value: V;
10
+ disabled?: boolean;
11
+ label: string;
12
+ onChange(value: V): void;
13
+ }): React.DetailedReactHTMLElement<{
14
+ style: {
15
+ minWidth: number;
16
+ };
17
+ }, HTMLElement>;
@@ -7,8 +7,8 @@
7
7
  import type { Context } from '@deepseek-ai/cordis';
8
8
  import z from '@deepseek-ai/schemastery';
9
9
  import { type AccessMode } from './access.js';
10
- import { type Settings } from './computer.js';
11
10
  import { type HostWindowMode } from './overlay.js';
11
+ export { DEFAULTS, ENTRY_ID, resolveConfig } from './settings.js';
12
12
  export declare const name = "@copylee/dsh-computer-use";
13
13
  export declare const inject: string[];
14
14
  export interface Config {
@@ -28,6 +28,4 @@ export interface Config {
28
28
  userIdleMs?: number;
29
29
  }
30
30
  export declare const Config: z<Config>;
31
- /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
32
- export declare function resolveConfig(raw: unknown): Settings;
33
31
  export declare function apply(ctx: Context, config?: Config): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Small HTTP bridge for the settings page: live status (helper, displays,
3
+ * resulting screenshot size) and a short overlay preview.
4
+ */
5
+ import type { IncomingMessage, ServerResponse } from 'node:http';
6
+ import { type Display } from './coords.js';
7
+ import type { Settings } from './computer.js';
8
+ import type { HelperLike } from './helper-client.js';
9
+ import type { OverlayController } from './overlay.js';
10
+ export declare const STATUS_ROUTE = "/api/dsh-computer-use/status";
11
+ export declare const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
12
+ type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
13
+ export interface StatusBody {
14
+ ok: true;
15
+ platform: string;
16
+ helper: 'ready' | 'error';
17
+ error?: string;
18
+ displays: Array<Display & {
19
+ shot: {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ }>;
24
+ controlling: boolean;
25
+ }
26
+ export declare function statusRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController): Handler;
27
+ /** Show the overlay for a few seconds so the user can see how it looks (skipped while an agent is controlling). */
28
+ export declare function previewRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController, iconPath: string): Handler;
29
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Plugin settings shared by the host and the settings page: defaults and the
3
+ * tolerant reader for the Loader entry config. No schemastery here so the
4
+ * browser bundle stays small.
5
+ */
6
+ import type { Settings } from './computer.js';
7
+ /** The Loader entry id (settings namespace); see cordis.patch.yml. */
8
+ export declare const ENTRY_ID = "copylee-computer-use";
9
+ export declare const DEFAULTS: Settings;
10
+ /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
11
+ export declare function resolveConfig(raw: unknown): Settings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",
@@ -19,10 +19,15 @@
19
19
  "types": "./lib/types/index.d.ts",
20
20
  "default": "./lib/index.js"
21
21
  },
22
+ "./client": {
23
+ "types": "./lib/types/client/index.d.ts",
24
+ "default": "./lib/client.js"
25
+ },
22
26
  "./package.json": "./package.json"
23
27
  },
24
28
  "files": [
25
29
  "lib/index.js",
30
+ "lib/client.js",
26
31
  "lib/types/**/*.d.ts",
27
32
  "helper/CuHelper.cs",
28
33
  "helper/deepseek-white.png",
@@ -39,6 +44,15 @@
39
44
  },
40
45
  "engines": {
41
46
  "dsh": ">=0.2.0-rc.2"
47
+ },
48
+ "client": {
49
+ "inject": [
50
+ "@deepseek-ai/dsh-client-connection",
51
+ "@deepseek-ai/dsh-api-remotes",
52
+ "@deepseek-ai/dsh-client-ui-settings",
53
+ "@deepseek-ai/dsh-client-locale"
54
+ ],
55
+ "platform": "web"
42
56
  }
43
57
  },
44
58
  "scripts": {
@@ -70,7 +84,8 @@
70
84
  ],
71
85
  "peerDependencies": {
72
86
  "@deepseek-ai/cordis": ">=4.0.0 <5",
73
- "@deepseek-ai/schemastery": ">=3.18.0 <4"
87
+ "@deepseek-ai/schemastery": ">=3.18.0 <4",
88
+ "react": ">=18.2.0 <19"
74
89
  },
75
90
  "peerDependenciesMeta": {
76
91
  "@deepseek-ai/cordis": {
@@ -78,17 +93,23 @@
78
93
  },
79
94
  "@deepseek-ai/schemastery": {
80
95
  "optional": true
96
+ },
97
+ "react": {
98
+ "optional": true
81
99
  }
82
100
  },
83
101
  "devDependencies": {
84
102
  "@deepseek-ai/cordis": "4.0.4",
85
103
  "@deepseek-ai/dsh-agent": "0.2.0-rc.2",
86
104
  "@deepseek-ai/dsh-attachment": "0.2.0-rc.2",
105
+ "@deepseek-ai/dsh-host-webserver": "0.2.0-rc.2",
87
106
  "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
88
107
  "@deepseek-ai/dsh-session": "0.2.0-rc.2",
89
108
  "@deepseek-ai/dsh-tools": "0.2.0-rc.2",
90
109
  "@deepseek-ai/schemastery": "3.18.4",
91
110
  "@types/node": "^22.20.0",
111
+ "@types/react": "~18.3.31",
112
+ "react": "^18.3.1",
92
113
  "tsdown": "^0.22.2",
93
114
  "typescript": "^6.0.3",
94
115
  "vitest": "^4.1.8"