@copylee/dsh-computer-use 0.10.0 → 0.11.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
@@ -84,7 +84,12 @@ window.__ModuleLoader__.load({
84
84
  userIdleMs: 1500,
85
85
  typingMode: "stream",
86
86
  quickSteps: false,
87
- nativeHelper: true
87
+ nativeHelper: true,
88
+ elementFirstClick: true,
89
+ restorePointer: false,
90
+ protectPasswords: true,
91
+ windowChangeGuard: true,
92
+ cdpPort: 0
88
93
  };
89
94
  /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
90
95
  function resolveConfig(raw) {
@@ -115,6 +120,11 @@ window.__ModuleLoader__.load({
115
120
  userIdleMs: num("userIdleMs", 300, 1e4),
116
121
  quickSteps: bool("quickSteps"),
117
122
  nativeHelper: bool("nativeHelper"),
123
+ elementFirstClick: bool("elementFirstClick"),
124
+ restorePointer: bool("restorePointer"),
125
+ protectPasswords: bool("protectPasswords"),
126
+ windowChangeGuard: bool("windowChangeGuard"),
127
+ cdpPort: num("cdpPort", 0, 65535),
118
128
  typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
119
129
  blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
120
130
  };
@@ -319,7 +329,7 @@ window.__ModuleLoader__.load({
319
329
  style.textContent = PILL_CSS;
320
330
  document.head.appendChild(style);
321
331
  }
322
- function isZh() {
332
+ function isZh$1() {
323
333
  if (typeof document === "undefined") return true;
324
334
  return (document.documentElement.lang || navigator.language || "zh").toLowerCase().startsWith("zh");
325
335
  }
@@ -393,7 +403,7 @@ window.__ModuleLoader__.load({
393
403
  };
394
404
  }, [sessionId, fetchState]);
395
405
  if (!sessionId || hidden || !ready && cachedHidden !== false) return null;
396
- const zh = isZh();
406
+ const zh = isZh$1();
397
407
  const label = zh ? "电脑控制" : "Computer";
398
408
  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)";
399
409
  const toggle = async () => {
@@ -906,6 +916,115 @@ window.__ModuleLoader__.load({
906
916
  }, "刷新"), note === null ? null : h$1("span", { style: note.kind === "ok" ? S.ok : S.error }, note.text)), dir ? h$1("p", { style: S.hint }, `保存位置:${dir}(每个应用一个 .md 文件,也可以直接用编辑器改)。删除内置技能后,新建同名技能即可重新启用。`) : null);
907
917
  }
908
918
  //#endregion
919
+ //#region lib/types/client/window-refs.js
920
+ /**
921
+ * Composer `@` reference source for running Windows application windows.
922
+ * Uses DSH's optional `inputTriggers` service (`ctx.inject(['inputTriggers'])`)
923
+ * and queries the passive read-only `/api/dsh-computer-use/windows` endpoint
924
+ * without ever lighting up the overlay or focusing any window.
925
+ */
926
+ const WINDOWS_ROUTE = "/api/dsh-computer-use/windows";
927
+ const SOURCE_NAME = "copylee-computer-use:windows";
928
+ const REF_PREFIX = "cu-window:";
929
+ function isZh() {
930
+ if (typeof document === "undefined") return true;
931
+ return (document.documentElement.lang || navigator.language || "zh").toLowerCase().startsWith("zh");
932
+ }
933
+ function formatRefText(win) {
934
+ return `[窗口: ${win.title.replace(/[\r\n\]]+/g, " ").trim().slice(0, 80)} | exe=${win.exe} | hwnd=${win.hwnd} | pid=${win.pid}]`;
935
+ }
936
+ function parseWindowRef(ref) {
937
+ if (!ref.startsWith(REF_PREFIX)) return void 0;
938
+ const parts = ref.slice(10).split("|");
939
+ const hwnd = Number.parseInt(parts[0] ?? "", 10);
940
+ const pid = Number.parseInt(parts[1] ?? "", 10);
941
+ if (!Number.isFinite(hwnd) || !Number.isFinite(pid)) return void 0;
942
+ return {
943
+ hwnd,
944
+ pid,
945
+ exe: decodeURIComponent(parts[2] ?? ""),
946
+ title: decodeURIComponent(parts[3] ?? "")
947
+ };
948
+ }
949
+ function registerWindowReferenceSource(scope) {
950
+ const triggers = scope.inputTriggers;
951
+ if (typeof triggers?.registerSource !== "function") return;
952
+ const zh = isZh();
953
+ const section = zh ? "运行中的窗口" : "Running windows";
954
+ scope.effect(() => triggers.registerSource({
955
+ trigger: "@",
956
+ name: SOURCE_NAME,
957
+ showGroupTitle: false,
958
+ lexicon: () => [],
959
+ subscribeLexicon: () => () => {},
960
+ async candidates(_session, request) {
961
+ if (request?.quoted || request?.drilled) return [];
962
+ const narrowed = (request?.query ?? "").trim().replace(/^(窗口|应用|win|window|app)\s*[::]\s*/i, "");
963
+ try {
964
+ const res = await fetch(`${WINDOWS_ROUTE}?q=${encodeURIComponent(narrowed)}`, {
965
+ credentials: "same-origin",
966
+ cache: "no-store",
967
+ ...request?.signal ? { signal: request.signal } : {}
968
+ });
969
+ if (!res.ok) return [];
970
+ const body = await res.json();
971
+ return (Array.isArray(body.windows) ? body.windows : []).map((win) => {
972
+ const shortTitle = win.title.slice(0, 48);
973
+ const ref = `${REF_PREFIX}${win.hwnd}|${win.pid}|${encodeURIComponent(win.exe)}|${encodeURIComponent(shortTitle)}`;
974
+ return {
975
+ name: shortTitle,
976
+ label: `${shortTitle}`,
977
+ description: `${win.exe}${win.minimized ? zh ? " · 已最小化" : " · minimized" : ""}`,
978
+ icon: "window",
979
+ section,
980
+ value: {
981
+ kind: "cu-window",
982
+ ref,
983
+ win
984
+ }
985
+ };
986
+ });
987
+ } catch {
988
+ return [];
989
+ }
990
+ },
991
+ onPick(pick) {
992
+ const value = pick?.candidate?.value;
993
+ if (value?.kind !== "cu-window" || !value.ref || !value.win) return { text: "" };
994
+ const label = value.win.title.slice(0, 32) || value.win.exe;
995
+ return { insert: {
996
+ source: SOURCE_NAME,
997
+ ref: value.ref,
998
+ label,
999
+ appearance: "file",
1000
+ clipboardText: formatRefText(value.win)
1001
+ } };
1002
+ },
1003
+ codec: {
1004
+ clipboardText: (ref) => {
1005
+ const parsed = parseWindowRef(ref);
1006
+ return parsed ? formatRefText(parsed) : ref;
1007
+ },
1008
+ async serialize(ref, signal) {
1009
+ const parsed = parseWindowRef(ref);
1010
+ if (!parsed) return ref;
1011
+ try {
1012
+ const res = await fetch(WINDOWS_ROUTE, {
1013
+ credentials: "same-origin",
1014
+ cache: "no-store",
1015
+ ...signal ? { signal } : {}
1016
+ });
1017
+ if (res.ok) {
1018
+ const live = (await res.json()).windows?.find((w) => w.hwnd === parsed.hwnd && w.pid === parsed.pid);
1019
+ if (live) return formatRefText(live);
1020
+ }
1021
+ } catch {}
1022
+ return formatRefText(parsed);
1023
+ }
1024
+ }
1025
+ }), "computer-use: @window reference source");
1026
+ }
1027
+ //#endregion
909
1028
  //#region lib/types/client/index.js
910
1029
  /**
911
1030
  * Browser half: the "电脑控制" (Computer use) section in Settings. It reads the
@@ -918,6 +1037,7 @@ window.__ModuleLoader__.load({
918
1037
  const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
919
1038
  const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
920
1039
  const DIAGNOSTICS_ROUTE = "/api/dsh-computer-use/diagnostics";
1040
+ const UPDATE_ROUTE = "/api/dsh-computer-use/update";
921
1041
  const mb = (bytes) => `${(bytes / 1048576).toFixed(1)} MB`;
922
1042
  const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
923
1043
  const h = react.createElement;
@@ -940,7 +1060,12 @@ window.__ModuleLoader__.load({
940
1060
  settleMs: String(s.settleMs),
941
1061
  maxLongEdge: String(s.maxLongEdge),
942
1062
  maxMegapixels: String(Math.round(s.maxPixels / 1e4) / 100),
943
- jpegQuality: String(s.jpegQuality)
1063
+ jpegQuality: String(s.jpegQuality),
1064
+ elementFirstClick: s.elementFirstClick,
1065
+ restorePointer: s.restorePointer,
1066
+ protectPasswords: s.protectPasswords,
1067
+ windowChangeGuard: s.windowChangeGuard,
1068
+ cdpPort: String(s.cdpPort)
944
1069
  };
945
1070
  }
946
1071
  /** Range-checked numbers; returns field errors keyed by Draft field. */
@@ -955,6 +1080,7 @@ window.__ModuleLoader__.load({
955
1080
  check("maxLongEdge", 640, 3840);
956
1081
  check("maxMegapixels", .3, 8);
957
1082
  check("jpegQuality", 30, 100);
1083
+ check("cdpPort", 0, 65535);
958
1084
  return errors;
959
1085
  }
960
1086
  function valuesFrom(d) {
@@ -976,7 +1102,12 @@ window.__ModuleLoader__.load({
976
1102
  settleMs: Math.round(Number(d.settleMs)),
977
1103
  maxLongEdge: Math.round(Number(d.maxLongEdge)),
978
1104
  maxPixels: Math.round(Number(d.maxMegapixels) * 1e6),
979
- jpegQuality: Math.round(Number(d.jpegQuality))
1105
+ jpegQuality: Math.round(Number(d.jpegQuality)),
1106
+ elementFirstClick: d.elementFirstClick,
1107
+ restorePointer: d.restorePointer,
1108
+ protectPasswords: d.protectPasswords,
1109
+ windowChangeGuard: d.windowChangeGuard,
1110
+ cdpPort: Math.round(Number(d.cdpPort))
980
1111
  };
981
1112
  }
982
1113
  const S = {
@@ -1169,6 +1300,8 @@ window.__ModuleLoader__.load({
1169
1300
  const [cache, setCache] = react.useState(null);
1170
1301
  const [cacheBusy, setCacheBusy] = react.useState(false);
1171
1302
  const [cacheNote, setCacheNote] = react.useState(null);
1303
+ const [updateBusy, setUpdateBusy] = react.useState(false);
1304
+ const [updateInfo, setUpdateInfo] = react.useState(null);
1172
1305
  const load = react.useCallback(async (reset) => {
1173
1306
  try {
1174
1307
  const result = await ctx.remote.settings.describe();
@@ -1353,6 +1486,24 @@ window.__ModuleLoader__.load({
1353
1486
  });
1354
1487
  }
1355
1488
  };
1489
+ const checkUpdate = async () => {
1490
+ setUpdateBusy(true);
1491
+ try {
1492
+ const response = await fetch(UPDATE_ROUTE, {
1493
+ credentials: "same-origin",
1494
+ cache: "no-store"
1495
+ });
1496
+ setUpdateInfo(await response.json());
1497
+ } catch (error) {
1498
+ setUpdateInfo({
1499
+ current: status?.version ?? "0.0.0",
1500
+ hasUpdate: false,
1501
+ error: error.message
1502
+ });
1503
+ } finally {
1504
+ setUpdateBusy(false);
1505
+ }
1506
+ };
1356
1507
  if (!loaded) return h("div", { style: S.page }, "加载中…");
1357
1508
  const primary = status?.displays.find((d) => d.primary) ?? status?.displays[0];
1358
1509
  const helperOk = status?.helper === "ready";
@@ -1372,7 +1523,10 @@ window.__ModuleLoader__.load({
1372
1523
  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: {
1373
1524
  ...S.dot,
1374
1525
  background: status === null ? "#999" : helperOk ? "#2a2" : "#d33"
1375
- } }), 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", {
1526
+ } }), status === null ? "无法获取状态" : helperOk ? status.controlling ? "正在操控电脑" : "就绪" : `控制组件不可用:${status.error ?? ""}`, status?.version ? h("span", { style: {
1527
+ ...S.hint,
1528
+ marginLeft: 4
1529
+ } }, `v${status.version}`) : null), 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, updateInfo ? h("p", { style: updateInfo.error ? S.error : updateInfo.hasUpdate ? S.ok : S.hint }, updateInfo.error ? `检查更新失败:${updateInfo.error}` : updateInfo.hasUpdate ? `发现新版本 v${updateInfo.latest}(当前 v${updateInfo.current},来源 ${updateInfo.source}),可在「插件」页更新。` : `已是最新版本 v${updateInfo.current}(${updateInfo.source ?? "npm"})。`) : null, h("div", { style: S.actions }, h("button", {
1376
1530
  type: "button",
1377
1531
  style: S.secondary,
1378
1532
  onClick: () => {
@@ -1385,6 +1539,13 @@ window.__ModuleLoader__.load({
1385
1539
  refreshStatus();
1386
1540
  }
1387
1541
  }, "刷新状态"), h("button", {
1542
+ type: "button",
1543
+ style: S.secondary,
1544
+ disabled: updateBusy,
1545
+ onClick: () => {
1546
+ checkUpdate();
1547
+ }
1548
+ }, updateBusy ? "检查中…" : "检查更新"), h("button", {
1388
1549
  type: "button",
1389
1550
  style: S.secondary,
1390
1551
  onClick: () => {
@@ -1441,7 +1602,19 @@ window.__ModuleLoader__.load({
1441
1602
  }), h("span", { style: {
1442
1603
  ...S.hint,
1443
1604
  fontWeight: 400
1444
- } }, "1Password、Bitwarden、KeePass 等常见密码管理器始终禁止。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "操控时的显示"), h(ToggleRow, {
1605
+ } }, "1Password、Bitwarden、KeePass 等常见密码管理器始终禁止。")), h(ToggleRow, {
1606
+ title: "密码框硬保护",
1607
+ hint: "检测 UIA IsPassword 与 Win32 ES_PASSWORD 结构位:自动脱敏密码框内容为 [password],并拒绝向密码框自动输入文本。",
1608
+ checked: draft.protectPasswords,
1609
+ disabled,
1610
+ onChange: (value) => edit("protectPasswords", value)
1611
+ }), h(ToggleRow, {
1612
+ title: "窗口位移 / 遮挡防误点",
1613
+ hint: "坐标点击前核对前台窗口自上次截图后是否移动/缩放或被新弹窗遮挡,发生变化时阻止盲点并提示模型先重看屏幕。",
1614
+ checked: draft.windowChangeGuard,
1615
+ disabled,
1616
+ onChange: (value) => edit("windowChangeGuard", value)
1617
+ })), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "操控时的显示"), h(ToggleRow, {
1445
1618
  title: "橙色光晕与提示条",
1446
1619
  hint: "不会出现在模型看到的截图里。",
1447
1620
  checked: draft.overlay,
@@ -1550,6 +1723,18 @@ window.__ModuleLoader__.load({
1550
1723
  checked: draft.pauseOnUserInput,
1551
1724
  disabled,
1552
1725
  onChange: (value) => edit("pauseOnUserInput", value)
1726
+ }), h(ToggleRow, {
1727
+ title: "坐标点击优先后台控件触发",
1728
+ hint: "坐标左键点击命中原生按钮、复选框或标签页时,优先走后台 UIA 语义触发,不移动真实鼠标也不抢焦点。",
1729
+ checked: draft.elementFirstClick,
1730
+ disabled,
1731
+ onChange: (value) => edit("elementFirstClick", value)
1732
+ }), h(ToggleRow, {
1733
+ title: "物理点击后还原鼠标位置",
1734
+ hint: "需要真实物理点击时,点击完成后立即把你的鼠标指针还原到原来的位置。",
1735
+ checked: draft.restorePointer,
1736
+ disabled,
1737
+ onChange: (value) => edit("restorePointer", value)
1553
1738
  }), h("div", { style: S.grid2 }, h(NumberField, {
1554
1739
  label: "停手多久后继续",
1555
1740
  unit: "毫秒",
@@ -1557,6 +1742,13 @@ window.__ModuleLoader__.load({
1557
1742
  error: errors.userIdleMs,
1558
1743
  disabled: disabled || !draft.pauseOnUserInput,
1559
1744
  onChange: (value) => edit("userIdleMs", value)
1745
+ }), h(NumberField, {
1746
+ label: "可选 Chromium CDP 端口(0=自动探测 9222/9229)",
1747
+ unit: "端口",
1748
+ value: draft.cdpPort,
1749
+ error: errors.cdpPort,
1750
+ disabled,
1751
+ onChange: (value) => edit("cdpPort", value)
1560
1752
  }))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图"), h(ToggleRow, {
1561
1753
  title: "操作后自动回传截图",
1562
1754
  hint: "省去模型再截一次图的一轮调用;关闭可省 token。画面未变化时自动跳过重复图片。",
@@ -1662,6 +1854,9 @@ window.__ModuleLoader__.load({
1662
1854
  id: ENTRY_ID,
1663
1855
  order: 40
1664
1856
  }, (props) => h(ComposerPill, props)));
1857
+ ctx.inject?.(["inputTriggers"], (scope) => {
1858
+ registerWindowReferenceSource(scope);
1859
+ });
1665
1860
  }
1666
1861
  //#endregion
1667
1862
  exports.apply = apply;