@copylee/dsh-computer-use 0.8.8 → 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/lib/client.js CHANGED
@@ -28,6 +28,32 @@ window.__ModuleLoader__.load({
28
28
  //#endregion
29
29
  let react = require("react");
30
30
  react = __toESM(react, 1);
31
+ //#region lib/types/coords.js
32
+ /** Output size together with which limit (`longEdge`, `pixels`, or neither) actually constrained it. */
33
+ function describeScreenshotSize(display, limits) {
34
+ const { width, height } = display;
35
+ const edgeScale = limits.maxLongEdge / Math.max(width, height);
36
+ const pixelScale = Math.sqrt(limits.maxPixels / (width * height));
37
+ const scale = Math.min(1, edgeScale, pixelScale);
38
+ const limitedBy = scale >= 1 ? "none" : pixelScale < edgeScale ? "pixels" : "longEdge";
39
+ const outWidth = Math.max(1, Math.round(width * scale));
40
+ const outHeight = Math.max(1, Math.round(height * scale));
41
+ return {
42
+ width: outWidth,
43
+ height: outHeight,
44
+ megapixels: Math.round(outWidth * outHeight / 1e4) / 100,
45
+ limitedBy
46
+ };
47
+ }
48
+ /** Lower-cost screenshot budget for quick confirmation shots (~30–40% fewer bytes). */
49
+ function compactLimits(budget) {
50
+ return {
51
+ maxLongEdge: Math.max(640, Math.min(budget.maxLongEdge, Math.round(budget.maxLongEdge * .78))),
52
+ maxPixels: Math.max(3e5, Math.min(budget.maxPixels, Math.round(budget.maxPixels * .58))),
53
+ jpegQuality: Math.max(45, Math.min(budget.jpegQuality, budget.jpegQuality - 8))
54
+ };
55
+ }
56
+ //#endregion
31
57
  //#region lib/types/browser-host.js
32
58
  function httpOrigin(value) {
33
59
  try {
@@ -41,11 +67,13 @@ window.__ModuleLoader__.load({
41
67
  const ENTRY_ID = "copylee-computer-use";
42
68
  const DEFAULTS = {
43
69
  accessMode: "per-app",
70
+ defaultSessionEnabled: false,
44
71
  overlay: true,
45
72
  overlayLabel: "DeepSeek Harness",
46
73
  hostWindow: "pet",
47
74
  cardOpacity: 80,
48
75
  autoScreenshot: true,
76
+ autoScreenshotDetail: "standard",
49
77
  settleMs: 400,
50
78
  maxLongEdge: 1366,
51
79
  maxPixels: 115e4,
@@ -69,11 +97,13 @@ window.__ModuleLoader__.load({
69
97
  return {
70
98
  harnessUrl: typeof out.harnessUrl === "string" ? httpOrigin(out.harnessUrl.trim()) : void 0,
71
99
  accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
100
+ defaultSessionEnabled: bool("defaultSessionEnabled"),
72
101
  overlay: bool("overlay"),
73
102
  overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
74
103
  hostWindow: out.hostWindow === "pet" || out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
75
104
  cardOpacity: num("cardOpacity", 30, 100),
76
105
  autoScreenshot: bool("autoScreenshot"),
106
+ autoScreenshotDetail: out.autoScreenshotDetail === "compact" || out.autoScreenshotDetail === "standard" ? out.autoScreenshotDetail : DEFAULTS.autoScreenshotDetail,
77
107
  settleMs: num("settleMs", 0, 5e3),
78
108
  maxLongEdge: num("maxLongEdge", 640, 3840),
79
109
  maxPixels: num("maxPixels", 3e5, 8e6),
@@ -218,6 +248,189 @@ window.__ModuleLoader__.load({
218
248
  } }, hint ? `${name(accent)} · ${hint}` : name(accent)));
219
249
  }
220
250
  //#endregion
251
+ //#region lib/types/client/composer-pill.js
252
+ /**
253
+ * Per-session computer-use toggle pill rendered in the conversation composer's
254
+ * left tool row (`conversation.input.left`). Clicking turns computer-use tools
255
+ * and system-prompt guidance on or off for the current session without restart.
256
+ */
257
+ const SESSION_ROUTE = "/api/dsh-computer-use/session";
258
+ const STYLE_ID = "copylee-computer-use-composer-pill";
259
+ const h$3 = react.createElement;
260
+ /** Client-side cache so switching between sessions does not flash stale state. */
261
+ const cache = /* @__PURE__ */ new Map();
262
+ const PILL_CSS = `
263
+ .cl-cu-pill {
264
+ display: inline-flex;
265
+ align-items: center;
266
+ gap: 5px;
267
+ height: 28px;
268
+ padding: 0 10px;
269
+ border-radius: 999px;
270
+ border: 1px solid var(--dsw-alias-border-l2, rgba(127, 127, 127, .28));
271
+ background: transparent;
272
+ color: var(--dsw-alias-label-secondary, #666);
273
+ font-size: 12px;
274
+ line-height: 1;
275
+ font-weight: 500;
276
+ cursor: pointer;
277
+ white-space: nowrap;
278
+ flex: none;
279
+ transition: background-color .12s, border-color .12s, color .12s, opacity .12s;
280
+ }
281
+ .cl-cu-pill:hover:not(:disabled) {
282
+ background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .08));
283
+ color: var(--dsw-alias-label-primary, inherit);
284
+ }
285
+ .cl-cu-pill[data-active="true"] {
286
+ border-color: color-mix(in srgb, ${ACCENT} 55%, transparent);
287
+ background: color-mix(in srgb, ${ACCENT} 12%, transparent);
288
+ color: ${ACCENT};
289
+ }
290
+ .cl-cu-pill[data-active="true"]:hover:not(:disabled) {
291
+ background: color-mix(in srgb, ${ACCENT} 18%, transparent);
292
+ }
293
+ .cl-cu-pill:focus-visible {
294
+ outline: 2px solid ${ACCENT};
295
+ outline-offset: 2px;
296
+ }
297
+ .cl-cu-pill:disabled {
298
+ opacity: .55;
299
+ cursor: default;
300
+ }
301
+ .cl-cu-pill-dot {
302
+ width: 6px;
303
+ height: 6px;
304
+ border-radius: 999px;
305
+ background: currentColor;
306
+ flex: none;
307
+ }
308
+ `;
309
+ function ensureStyle() {
310
+ if (typeof document === "undefined") return;
311
+ if (document.getElementById(STYLE_ID)) return;
312
+ const style = document.createElement("style");
313
+ style.id = STYLE_ID;
314
+ style.textContent = PILL_CSS;
315
+ document.head.appendChild(style);
316
+ }
317
+ function isZh() {
318
+ if (typeof document === "undefined") return true;
319
+ return (document.documentElement.lang || navigator.language || "zh").toLowerCase().startsWith("zh");
320
+ }
321
+ function MonitorIcon() {
322
+ return h$3("svg", {
323
+ width: 14,
324
+ height: 14,
325
+ viewBox: "0 0 16 16",
326
+ fill: "none",
327
+ stroke: "currentColor",
328
+ strokeWidth: 1.4,
329
+ strokeLinecap: "round",
330
+ strokeLinejoin: "round",
331
+ "aria-hidden": "true"
332
+ }, h$3("rect", {
333
+ x: 1.75,
334
+ y: 2.5,
335
+ width: 12.5,
336
+ height: 8.5,
337
+ rx: 1.5
338
+ }), h$3("path", { d: "M5.5 13.5h5M8 11v2.5" }));
339
+ }
340
+ function createComposerPill(subscribeSettings) {
341
+ return function ComposerPill(props) {
342
+ const sessionId = typeof props?.sessionId === "string" && props.sessionId.trim() !== "" ? props.sessionId : void 0;
343
+ const [enabled, setEnabled] = react.useState(() => sessionId ? cache.get(sessionId) ?? false : false);
344
+ const [ready, setReady] = react.useState(() => sessionId ? cache.has(sessionId) : false);
345
+ const [busy, setBusy] = react.useState(false);
346
+ react.useEffect(() => {
347
+ ensureStyle();
348
+ }, []);
349
+ const fetchState = react.useCallback(async (id, cancelled) => {
350
+ try {
351
+ const res = await fetch(`${SESSION_ROUTE}?sessionId=${encodeURIComponent(id)}`, {
352
+ credentials: "same-origin",
353
+ cache: "no-store"
354
+ });
355
+ if (!res.ok) return;
356
+ const body = await res.json();
357
+ if (cancelled.current) return;
358
+ const value = body.enabled === true;
359
+ cache.set(id, value);
360
+ setEnabled(value);
361
+ setReady(true);
362
+ } catch {
363
+ if (!cancelled.current) setReady(true);
364
+ }
365
+ }, []);
366
+ react.useEffect(() => {
367
+ if (!sessionId) return;
368
+ const cancelled = { current: false };
369
+ if (cache.has(sessionId)) {
370
+ setEnabled(cache.get(sessionId));
371
+ setReady(true);
372
+ } else {
373
+ setEnabled(false);
374
+ setReady(false);
375
+ }
376
+ fetchState(sessionId, cancelled);
377
+ const unsub = subscribeSettings?.(() => {
378
+ fetchState(sessionId, cancelled);
379
+ });
380
+ return () => {
381
+ cancelled.current = true;
382
+ unsub?.();
383
+ };
384
+ }, [sessionId, fetchState]);
385
+ if (!sessionId) return null;
386
+ const zh = isZh();
387
+ const label = zh ? "电脑控制" : "Computer";
388
+ const title = enabled ? zh ? "当前会话已开启电脑控制,点击关闭" : "Computer use is enabled for this session (click to disable)" : zh ? "当前会话未开启电脑控制,点击开启" : "Computer use is disabled for this session (click to enable)";
389
+ const toggle = async () => {
390
+ if (busy) return;
391
+ const next = !enabled;
392
+ setBusy(true);
393
+ setEnabled(next);
394
+ cache.set(sessionId, next);
395
+ try {
396
+ const res = await fetch(SESSION_ROUTE, {
397
+ method: "POST",
398
+ credentials: "same-origin",
399
+ headers: { "content-type": "application/json" },
400
+ body: JSON.stringify({
401
+ sessionId,
402
+ enabled: next
403
+ })
404
+ });
405
+ if (!res.ok) throw new Error("toggle failed");
406
+ const settled = (await res.json()).enabled === true;
407
+ cache.set(sessionId, settled);
408
+ setEnabled(settled);
409
+ } catch {
410
+ cache.set(sessionId, !next);
411
+ setEnabled(!next);
412
+ } finally {
413
+ setBusy(false);
414
+ }
415
+ };
416
+ return h$3("button", {
417
+ type: "button",
418
+ className: "cl-cu-pill",
419
+ "data-active": enabled ? "true" : "false",
420
+ "aria-pressed": enabled,
421
+ "aria-label": title,
422
+ title,
423
+ disabled: busy || !ready,
424
+ onClick: () => {
425
+ toggle();
426
+ }
427
+ }, h$3(MonitorIcon, null), h$3("span", null, label), enabled ? h$3("span", {
428
+ className: "cl-cu-pill-dot",
429
+ "aria-hidden": "true"
430
+ }) : null);
431
+ };
432
+ }
433
+ //#endregion
221
434
  //#region lib/types/client/nav-icon.js
222
435
  /**
223
436
  * Give the "电脑控制" row in the DSH settings navigation a mouse-pointer icon
@@ -701,6 +914,7 @@ window.__ModuleLoader__.load({
701
914
  const s = resolveConfig(value);
702
915
  return {
703
916
  accessMode: s.accessMode,
917
+ defaultSessionEnabled: s.defaultSessionEnabled,
704
918
  blockedApps: s.blockedApps.join("\n"),
705
919
  overlay: s.overlay,
706
920
  overlayLabel: s.overlayLabel,
@@ -711,6 +925,7 @@ window.__ModuleLoader__.load({
711
925
  pauseOnUserInput: s.pauseOnUserInput,
712
926
  userIdleMs: String(s.userIdleMs),
713
927
  autoScreenshot: s.autoScreenshot,
928
+ autoScreenshotDetail: s.autoScreenshotDetail,
714
929
  settleMs: String(s.settleMs),
715
930
  maxLongEdge: String(s.maxLongEdge),
716
931
  maxMegapixels: String(Math.round(s.maxPixels / 1e4) / 100),
@@ -734,6 +949,7 @@ window.__ModuleLoader__.load({
734
949
  function valuesFrom(d) {
735
950
  return {
736
951
  accessMode: d.accessMode,
952
+ defaultSessionEnabled: d.defaultSessionEnabled,
737
953
  blockedApps: d.blockedApps.split(/[\n,,]/).map((item) => item.trim()).filter(Boolean),
738
954
  overlay: d.overlay,
739
955
  overlayLabel: d.overlayLabel.trim() || DEFAULTS.overlayLabel,
@@ -744,6 +960,7 @@ window.__ModuleLoader__.load({
744
960
  pauseOnUserInput: d.pauseOnUserInput,
745
961
  userIdleMs: Math.round(Number(d.userIdleMs)),
746
962
  autoScreenshot: d.autoScreenshot,
963
+ autoScreenshotDetail: d.autoScreenshotDetail,
747
964
  settleMs: Math.round(Number(d.settleMs)),
748
965
  maxLongEdge: Math.round(Number(d.maxLongEdge)),
749
966
  maxPixels: Math.round(Number(d.maxMegapixels) * 1e6),
@@ -1099,6 +1316,19 @@ window.__ModuleLoader__.load({
1099
1316
  if (!loaded) return h("div", { style: S.page }, "加载中…");
1100
1317
  const primary = status?.displays.find((d) => d.primary) ?? status?.displays[0];
1101
1318
  const helperOk = status?.helper === "ready";
1319
+ const limitLabel = (by) => by === "pixels" ? "受限于总像素上限" : by === "longEdge" ? "受限于最长边" : "未缩放";
1320
+ const draftMaxEdge = Number(draft.maxLongEdge);
1321
+ const draftMaxPixels = Number(draft.maxMegapixels) * 1e6;
1322
+ const draftQuality = Number(draft.jpegQuality);
1323
+ const liveShot = primary && Number.isFinite(draftMaxEdge) && draftMaxEdge >= 640 && Number.isFinite(draftMaxPixels) && draftMaxPixels >= 3e5 ? describeScreenshotSize(primary, {
1324
+ maxLongEdge: Math.round(draftMaxEdge),
1325
+ maxPixels: Math.round(draftMaxPixels)
1326
+ }) : primary?.shot;
1327
+ const liveCompactShot = primary && Number.isFinite(draftMaxEdge) && draftMaxEdge >= 640 && Number.isFinite(draftMaxPixels) && draftMaxPixels >= 3e5 ? describeScreenshotSize(primary, compactLimits({
1328
+ maxLongEdge: Math.round(draftMaxEdge),
1329
+ maxPixels: Math.round(draftMaxPixels),
1330
+ jpegQuality: Number.isFinite(draftQuality) ? Math.round(draftQuality) : DEFAULTS.jpegQuality
1331
+ })) : primary?.compactShot;
1102
1332
  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: {
1103
1333
  ...S.dot,
1104
1334
  background: status === null ? "#999" : helperOk ? "#2a2" : "#d33"
@@ -1114,7 +1344,13 @@ window.__ModuleLoader__.load({
1114
1344
  onClick: () => {
1115
1345
  refreshStatus();
1116
1346
  }
1117
- }, "刷新状态"), h("span", { style: S.hint }, "预览 4 秒:按已保存的设置显示光晕,以及迷你进度卡片或提示条。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "授权"), h("div", { style: S.label }, "授权方式", h(Select, {
1347
+ }, "刷新状态"), h("span", { style: S.hint }, "预览 4 秒:按已保存的设置显示光晕,以及迷你进度卡片或提示条。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "授权"), h(ToggleRow, {
1348
+ title: "新会话默认开启电脑控制",
1349
+ hint: "关闭时(推荐),普通对话不会加载桌面工具与系统提示;需要在输入框左下角点击「电脑控制」胶囊为当前会话按需开启,子代理自动继承。",
1350
+ checked: draft.defaultSessionEnabled,
1351
+ disabled,
1352
+ onChange: (value) => edit("defaultSessionEnabled", value)
1353
+ }), h("div", { style: S.label }, "授权方式", h(Select, {
1118
1354
  label: "授权方式",
1119
1355
  disabled,
1120
1356
  value: draft.accessMode,
@@ -1261,11 +1497,26 @@ window.__ModuleLoader__.load({
1261
1497
  onChange: (value) => edit("userIdleMs", value)
1262
1498
  }))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图"), h(ToggleRow, {
1263
1499
  title: "操作后自动回传截图",
1264
- hint: "省去模型再截一次图的一轮调用;关闭可省 token。",
1500
+ hint: "省去模型再截一次图的一轮调用;关闭可省 token。画面未变化时自动跳过重复图片。",
1265
1501
  checked: draft.autoScreenshot,
1266
1502
  disabled,
1267
1503
  onChange: (value) => edit("autoScreenshot", value)
1268
- }), h("div", { style: S.grid2 }, h(NumberField, {
1504
+ }), h("div", { style: S.label }, "自动回传截图清晰度", h(Select, {
1505
+ label: "自动回传截图清晰度",
1506
+ disabled: disabled || !draft.autoScreenshot,
1507
+ value: draft.autoScreenshotDetail,
1508
+ options: [{
1509
+ value: "standard",
1510
+ label: "标准(与下方分辨率一致)"
1511
+ }, {
1512
+ value: "compact",
1513
+ label: "紧凑(自动降一档,省约 30%–40% 字节)"
1514
+ }],
1515
+ onChange: (value) => edit("autoScreenshotDetail", value)
1516
+ }), h("span", { style: {
1517
+ ...S.hint,
1518
+ fontWeight: 400
1519
+ } }, "紧凑档只降低操作后的自动确认截图;模型显式调用 screenshot / zoom 时仍保持标准清晰度。")), h("div", { style: S.grid2 }, h(NumberField, {
1269
1520
  label: "操作后至少等待(之后画面静止即截图,最多约 2.5 秒)",
1270
1521
  unit: "毫秒",
1271
1522
  value: draft.settleMs,
@@ -1293,7 +1544,7 @@ window.__ModuleLoader__.load({
1293
1544
  error: errors.jpegQuality,
1294
1545
  disabled,
1295
1546
  onChange: (value) => edit("jpegQuality", value)
1296
- })), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h(SkillsCard, { S }), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图缓存"), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "截图作为附件保存在会话历史里。仍在会话中的截图不会被删除:删除后继续那个会话会直接报错。删除会话后,它留下的截图会在启动 DeepSeek Harness 几分钟后及之后每 12 小时自动清理,也可以在这里立即清理。"), h("div", { style: S.actions }, h("button", {
1547
+ })), liveShot ? h("p", { style: S.hint }, `当前主屏实际输出:${liveShot.width}×${liveShot.height}(${liveShot.megapixels} MP,${limitLabel(liveShot.limitedBy)})${liveCompactShot ? `;紧凑档:${liveCompactShot.width}×${liveCompactShot.height}(${liveCompactShot.megapixels} MP)` : ""}。最长边与总像素上限同时生效,取更紧的一项。`) : h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。最长边与总像素上限同时生效,取更紧的一项;默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h(SkillsCard, { S }), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图缓存"), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "截图作为附件保存在会话历史里。仍在会话中的截图不会被删除:删除后继续那个会话会直接报错。删除会话后,它留下的截图会在启动 DeepSeek Harness 几分钟后及之后每 12 小时自动清理,也可以在这里立即清理。"), h("div", { style: S.actions }, h("button", {
1297
1548
  type: "button",
1298
1549
  style: {
1299
1550
  ...S.secondary,
@@ -1341,6 +1592,14 @@ window.__ModuleLoader__.load({
1341
1592
  order: 61,
1342
1593
  label: () => "电脑控制"
1343
1594
  }, () => h(ComputerUseSection, { ctx })));
1595
+ const ComposerPill = createComposerPill((listener) => ctx.remote.$on?.("settings/document-updated", (ns) => {
1596
+ if (ns === "copylee-computer-use") listener();
1597
+ }));
1598
+ ctx.slots.inject("conversation.input.left", () => ctx.slots.register({
1599
+ name: "conversation.input.left",
1600
+ id: ENTRY_ID,
1601
+ order: 40
1602
+ }, (props) => h(ComposerPill, props)));
1344
1603
  }
1345
1604
  //#endregion
1346
1605
  exports.apply = apply;