@copylee/dsh-computer-use 0.12.0 → 0.13.1

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
@@ -91,6 +91,7 @@ window.__ModuleLoader__.load({
91
91
  restorePointer: false,
92
92
  protectPasswords: true,
93
93
  windowChangeGuard: true,
94
+ cdpEnabled: false,
94
95
  cdpPort: 0
95
96
  };
96
97
  /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
@@ -102,6 +103,8 @@ window.__ModuleLoader__.load({
102
103
  return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, Math.round(value))) : DEFAULTS[key];
103
104
  };
104
105
  const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
106
+ const cdpPort = num("cdpPort", 0, 65535);
107
+ const cdpEnabled = typeof out.cdpEnabled === "boolean" ? out.cdpEnabled : cdpPort > 0;
105
108
  const sessionMode = out.sessionMode === "off" || out.sessionMode === "on" || out.sessionMode === "always" ? out.sessionMode : out.defaultSessionEnabled === true ? "on" : DEFAULTS.sessionMode;
106
109
  return {
107
110
  harnessUrl: typeof out.harnessUrl === "string" ? httpOrigin(out.harnessUrl.trim()) : void 0,
@@ -128,7 +131,8 @@ window.__ModuleLoader__.load({
128
131
  restorePointer: bool("restorePointer"),
129
132
  protectPasswords: bool("protectPasswords"),
130
133
  windowChangeGuard: bool("windowChangeGuard"),
131
- cdpPort: num("cdpPort", 0, 65535),
134
+ cdpEnabled,
135
+ cdpPort,
132
136
  typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
133
137
  blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
134
138
  };
@@ -686,18 +690,33 @@ window.__ModuleLoader__.load({
686
690
  //#endregion
687
691
  //#region lib/types/client/skills-card.js
688
692
  /**
689
- * "应用技能" card: the per-app notes the agent keeps (see ../skills.ts). The
690
- * user can read, edit, add and delete them here; built-in skills can be
691
- * overridden and restored.
693
+ * "应用技能" card: per-app notes the agent keeps (see ../skills.ts).
694
+ * Compact collapsible list with live search & source filter, plus a centered
695
+ * modal dialog for viewing, editing, and creating skills.
692
696
  */
693
697
  const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
694
698
  const MAX_CHARS = 4e3;
695
699
  const h$1 = react.createElement;
700
+ const modalCss = `
701
+ @keyframes dshcu-backdrop-in{from{opacity:0}to{opacity:1}}
702
+ @keyframes dshcu-modal-in{from{opacity:0;transform:translateY(8px) scale(.97)}to{opacity:1;transform:translateY(0) scale(1)}}
703
+ .dshcu-skill-list{max-height:300px;overflow-y:auto;padding-right:2px;display:grid;gap:2px}
704
+ .dshcu-skill-row{display:flex;gap:10px;align-items:center;padding:9px 10px;border-radius:10px;border:1px solid transparent;transition:background .15s ease,border-color .15s ease}
705
+ .dshcu-skill-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));border-color:var(--dsw-alias-border-l2,rgba(127,127,127,.18))}
706
+ .dshcu-chip-tab{padding:4px 10px;border-radius:999px;font-size:12px;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#666);transition:background .15s ease,color .15s ease,border-color .15s ease}
707
+ .dshcu-chip-tab:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
708
+ .dshcu-chip-tab[data-active="true"]{background:var(--dshcu-accent-soft,rgba(217,119,87,.14));color:var(--dshcu-accent,#d97757);border-color:var(--dshcu-accent,#d97757);font-weight:600}
709
+ .dshcu-modal-backdrop{position:fixed;inset:0;z-index:9999;background:rgba(15,15,18,.48);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:20px;animation:dshcu-backdrop-in .16s ease}
710
+ .dshcu-modal{width:min(640px,100%);max-height:min(86vh,720px);display:flex;flex-direction:column;border-radius:16px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));box-shadow:0 24px 64px rgba(0,0,0,.28);overflow:hidden;animation:dshcu-modal-in .18s cubic-bezier(.16,1,.3,1)}
711
+ `;
696
712
  function SkillsCard({ S }) {
697
713
  const [skills, setSkills] = react.useState(null);
698
714
  const [dir, setDir] = react.useState("");
699
715
  const [draft, setDraft] = react.useState(null);
700
716
  const [busy, setBusy] = react.useState(false);
717
+ const [expanded, setExpanded] = react.useState(false);
718
+ const [query, setQuery] = react.useState("");
719
+ const [filter, setFilter] = react.useState("all");
701
720
  const [note, setNote] = react.useState(null);
702
721
  const call = react.useCallback(async (body) => {
703
722
  setBusy(true);
@@ -725,6 +744,14 @@ window.__ModuleLoader__.load({
725
744
  react.useEffect(() => {
726
745
  call();
727
746
  }, [call]);
747
+ react.useEffect(() => {
748
+ if (!draft) return;
749
+ const onKey = (e) => {
750
+ if (e.key === "Escape" && !busy) setDraft(null);
751
+ };
752
+ window.addEventListener("keydown", onKey);
753
+ return () => window.removeEventListener("keydown", onKey);
754
+ }, [draft, busy]);
728
755
  const edit = (skill) => {
729
756
  setNote(null);
730
757
  setDraft({
@@ -733,7 +760,20 @@ window.__ModuleLoader__.load({
733
760
  match: skill.match.join(", "),
734
761
  summary: skill.summary,
735
762
  content: skill.content,
736
- isNew: false
763
+ isNew: false,
764
+ source: skill.source,
765
+ overrides: skill.overrides
766
+ });
767
+ };
768
+ const openNew = () => {
769
+ setNote(null);
770
+ setDraft({
771
+ id: "",
772
+ app: "",
773
+ match: "",
774
+ summary: "",
775
+ content: "",
776
+ isNew: true
737
777
  });
738
778
  };
739
779
  const save = async () => {
@@ -767,26 +807,30 @@ window.__ModuleLoader__.load({
767
807
  });
768
808
  }
769
809
  };
770
- const reset = async (skill) => {
810
+ const reset = async (id, app) => {
771
811
  setNote(null);
772
812
  if (await call({
773
813
  op: "reset",
774
- id: skill.id
814
+ id
775
815
  })) {
776
- if (draft?.id === skill.id) setDraft(null);
816
+ if (draft?.id === id) setDraft(null);
777
817
  setNote({
778
818
  kind: "ok",
779
- text: `已恢复“${skill.app}”的内置版本`
819
+ text: `已恢复“${app}”的内置版本`
780
820
  });
781
821
  }
782
822
  };
783
- const row = {
784
- display: "flex",
785
- gap: 10,
786
- alignItems: "center",
787
- padding: "8px 0",
788
- borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
789
- };
823
+ const allSkills = skills ?? [];
824
+ const userCount = allSkills.filter((s) => s.source !== "builtin").length;
825
+ const builtinCount = allSkills.length - userCount;
826
+ const q = query.trim().toLowerCase();
827
+ const showList = expanded || q.length > 0;
828
+ const filtered = allSkills.filter((skill) => {
829
+ if (filter === "user" && skill.source === "builtin") return false;
830
+ if (filter === "builtin" && skill.source !== "builtin") return false;
831
+ if (!q) return true;
832
+ return skill.app.toLowerCase().includes(q) || skill.summary.toLowerCase().includes(q) || skill.match.some((m) => m.toLowerCase().includes(q));
833
+ });
790
834
  const small = {
791
835
  ...S.secondary,
792
836
  padding: "4px 10px",
@@ -801,9 +845,105 @@ window.__ModuleLoader__.load({
801
845
  whiteSpace: "nowrap"
802
846
  };
803
847
  const invalid = draft !== null && (draft.app.trim() === "" || draft.content.trim() === "" || draft.content.length > MAX_CHARS);
804
- return h$1("section", { style: S.card }, h$1("h3", { style: S.cardTitle }, "应用技能"), h$1("p", { style: S.hint }, "AI 对各个应用的操作笔记:每个应用一份,AI 摸索清楚一个不熟悉的应用后会自己记下来,以后打开这个应用时自动读取,不占用系统提示。你可以在这里查看、修改、删除或新建。"), skills === null ? h$1("p", { style: S.hint }, busy ? "正在读取…" : "无法读取应用技能。") : skills.length === 0 ? h$1("p", { style: S.hint }, "还没有应用技能。") : h$1("div", null, ...skills.map((skill) => h$1("div", {
848
+ return h$1("section", {
849
+ className: "dshcu-card",
850
+ style: S.card
851
+ }, h$1("style", null, modalCss), h$1("div", { style: {
852
+ display: "flex",
853
+ alignItems: "center",
854
+ justifyContent: "space-between",
855
+ gap: 10,
856
+ flexWrap: "wrap"
857
+ } }, h$1("div", { style: {
858
+ display: "flex",
859
+ alignItems: "center",
860
+ gap: 8,
861
+ flexWrap: "wrap"
862
+ } }, h$1("h3", { style: S.cardTitle }, "应用技能"), skills !== null ? h$1("span", {
863
+ className: "dshcu-badge",
864
+ style: tag
865
+ }, `共 ${allSkills.length} 项 · ${userCount} 自定义 / ${builtinCount} 内置`) : null), h$1("div", { style: {
866
+ display: "flex",
867
+ gap: 8,
868
+ alignItems: "center"
869
+ } }, h$1("button", {
870
+ type: "button",
871
+ className: "dshcu-btn",
872
+ style: small,
873
+ disabled: busy,
874
+ onClick: openNew
875
+ }, "+ 新建技能"), h$1("button", {
876
+ type: "button",
877
+ className: "dshcu-btn",
878
+ style: small,
879
+ disabled: busy,
880
+ onClick: () => setExpanded((prev) => !prev)
881
+ }, showList && !q ? "收起列表 ▴" : `展开列表 (${allSkills.length}) ▾`))), h$1("p", { style: S.hint }, "AI 对各个应用的操作笔记:打开应用时自动读取,不占用常规系统提示。支持实时搜索,点击「查看 / 编辑」在弹窗中修改。"), h$1("div", { style: {
882
+ display: "flex",
883
+ gap: 8,
884
+ alignItems: "center",
885
+ flexWrap: "wrap"
886
+ } }, h$1("div", { style: {
887
+ position: "relative",
888
+ flex: "1 1 220px",
889
+ minWidth: 180
890
+ } }, h$1("input", {
891
+ style: {
892
+ ...S.input,
893
+ width: "100%",
894
+ boxSizing: "border-box",
895
+ paddingRight: q ? 30 : 12
896
+ },
897
+ value: query,
898
+ placeholder: "搜索应用名、进程名或摘要(输入即可过滤)…",
899
+ onChange: (e) => setQuery(e.target.value)
900
+ }), q ? h$1("button", {
901
+ type: "button",
902
+ "aria-label": "清空搜索",
903
+ onClick: () => setQuery(""),
904
+ style: {
905
+ position: "absolute",
906
+ right: 8,
907
+ top: "50%",
908
+ transform: "translateY(-50%)",
909
+ border: "none",
910
+ background: "transparent",
911
+ color: "var(--dsw-alias-label-tertiary, #888)",
912
+ cursor: "pointer",
913
+ fontSize: 15,
914
+ lineHeight: 1,
915
+ padding: "2px 4px"
916
+ }
917
+ }, "×") : null), showList ? h$1("div", { style: {
918
+ display: "flex",
919
+ gap: 6,
920
+ alignItems: "center"
921
+ } }, h$1("button", {
922
+ type: "button",
923
+ className: "dshcu-chip-tab",
924
+ "data-active": String(filter === "all"),
925
+ onClick: () => setFilter("all")
926
+ }, `全部 (${allSkills.length})`), h$1("button", {
927
+ type: "button",
928
+ className: "dshcu-chip-tab",
929
+ "data-active": String(filter === "user"),
930
+ onClick: () => setFilter("user")
931
+ }, `自定义 (${userCount})`), h$1("button", {
932
+ type: "button",
933
+ className: "dshcu-chip-tab",
934
+ "data-active": String(filter === "builtin"),
935
+ onClick: () => setFilter("builtin")
936
+ }, `内置 (${builtinCount})`), h$1("button", {
937
+ type: "button",
938
+ className: "dshcu-btn",
939
+ style: small,
940
+ disabled: busy,
941
+ onClick: () => {
942
+ call();
943
+ }
944
+ }, "刷新")) : null), skills === null ? h$1("p", { style: S.hint }, busy ? "正在读取…" : "无法读取应用技能。") : !showList ? null : filtered.length === 0 ? h$1("p", { style: S.hint }, q ? `未找到包含「${query}」的应用技能。` : "当前分类下还没有应用技能。") : h$1("div", { className: "dshcu-skill-list" }, ...filtered.map((skill) => h$1("div", {
805
945
  key: skill.id,
806
- style: row
946
+ className: "dshcu-skill-row"
807
947
  }, h$1("div", { style: {
808
948
  flex: 1,
809
949
  minWidth: 0
@@ -820,27 +960,70 @@ window.__ModuleLoader__.load({
820
960
  whiteSpace: "nowrap"
821
961
  } }, `${skill.summary || "(无摘要)"} · ${skill.content.length} 字`)), h$1("button", {
822
962
  type: "button",
963
+ className: "dshcu-btn",
823
964
  style: small,
824
965
  disabled: busy,
825
966
  onClick: () => edit(skill)
826
967
  }, "查看 / 编辑"), skill.overrides ? h$1("button", {
827
968
  type: "button",
969
+ className: "dshcu-btn",
828
970
  style: small,
829
971
  disabled: busy,
830
972
  onClick: () => {
831
- reset(skill);
973
+ reset(skill.id, skill.app);
832
974
  }
833
975
  }, "恢复内置") : null, h$1("button", {
834
976
  type: "button",
977
+ className: "dshcu-btn",
835
978
  style: small,
836
979
  disabled: busy,
837
980
  onClick: () => {
838
981
  remove(skill);
839
982
  }
840
- }, "删除")))), draft === null ? null : h$1("div", { style: {
841
- display: "grid",
983
+ }, "删除")))), note !== null ? h$1("div", { style: {
984
+ fontSize: 12,
985
+ color: (note.kind === "ok" ? S.ok : S.error)?.color
986
+ } }, note.text) : null, showList && dir ? h$1("p", { style: S.hint }, `保存位置:${dir}(每个应用一个 .md 文件,也可直接编辑)。删除内置技能后,新建同名技能即可重新启用。`) : null, draft === null ? null : h$1("div", {
987
+ className: "dshcu-modal-backdrop",
988
+ onClick: (e) => {
989
+ if (e.target === e.currentTarget && !busy) setDraft(null);
990
+ }
991
+ }, h$1("div", {
992
+ className: "dshcu-modal",
993
+ role: "dialog",
994
+ "aria-modal": "true",
995
+ "aria-label": draft.isNew ? "新建应用技能" : `编辑应用技能 ${draft.app}`
996
+ }, h$1("div", { style: {
997
+ display: "flex",
998
+ alignItems: "center",
999
+ justifyContent: "space-between",
842
1000
  gap: 10,
843
- paddingTop: 4
1001
+ padding: "16px 20px",
1002
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
1003
+ } }, h$1("div", { style: {
1004
+ display: "flex",
1005
+ alignItems: "center",
1006
+ gap: 8
1007
+ } }, h$1("strong", { style: { fontSize: 15 } }, draft.isNew ? "新建应用技能" : `编辑技能 · ${draft.app}`), !draft.isNew ? h$1("span", { style: tag }, draft.source === "builtin" ? "内置" : draft.overrides ? "已修改" : "AI / 自定义") : null), h$1("button", {
1008
+ type: "button",
1009
+ "aria-label": "关闭",
1010
+ disabled: busy,
1011
+ onClick: () => setDraft(null),
1012
+ style: {
1013
+ border: "none",
1014
+ background: "transparent",
1015
+ color: "var(--dsw-alias-label-secondary, #666)",
1016
+ cursor: "pointer",
1017
+ fontSize: 20,
1018
+ lineHeight: 1,
1019
+ padding: "2px 6px",
1020
+ borderRadius: 6
1021
+ }
1022
+ }, "×")), h$1("div", { style: {
1023
+ padding: "16px 20px",
1024
+ overflowY: "auto",
1025
+ display: "grid",
1026
+ gap: 12
844
1027
  } }, h$1("div", { style: S.grid2 }, h$1("label", { style: S.label }, "应用名称", h$1("input", {
845
1028
  style: S.input,
846
1029
  value: draft.app,
@@ -872,7 +1055,7 @@ window.__ModuleLoader__.load({
872
1055
  })), h$1("label", { style: S.label }, `内容(${draft.content.length} / ${MAX_CHARS} 字)`, h$1("textarea", {
873
1056
  style: {
874
1057
  ...S.input,
875
- minHeight: 200,
1058
+ minHeight: 240,
876
1059
  resize: "vertical",
877
1060
  fontFamily: "inherit",
878
1061
  lineHeight: 1.55
@@ -883,44 +1066,45 @@ window.__ModuleLoader__.load({
883
1066
  ...draft,
884
1067
  content: e.target.value
885
1068
  })
886
- })), h$1("div", { style: S.actions }, h$1("button", {
887
- type: "button",
888
- style: {
889
- ...S.primary,
890
- opacity: busy || invalid ? .5 : 1
891
- },
892
- disabled: busy || invalid,
893
- onClick: () => {
894
- save();
895
- }
896
- }, "保存技能"), h$1("button", {
897
- type: "button",
898
- style: S.secondary,
899
- disabled: busy,
900
- onClick: () => setDraft(null)
901
- }, "取消"), draft.content.length > MAX_CHARS ? h$1("span", { style: S.error }, "内容过长,请精简") : null)), h$1("div", { style: S.actions }, draft === null ? h$1("button", {
1069
+ })), draft.content.length > MAX_CHARS ? h$1("span", { style: S.error }, "内容过长,请精简至 4000 字以内") : null), h$1("div", { style: {
1070
+ display: "flex",
1071
+ alignItems: "center",
1072
+ justifyContent: "space-between",
1073
+ gap: 10,
1074
+ padding: "14px 20px",
1075
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
1076
+ } }, h$1("div", { style: {
1077
+ display: "flex",
1078
+ gap: 8
1079
+ } }, !draft.isNew && draft.overrides ? h$1("button", {
902
1080
  type: "button",
1081
+ className: "dshcu-btn",
903
1082
  style: S.secondary,
904
1083
  disabled: busy,
905
1084
  onClick: () => {
906
- setNote(null);
907
- setDraft({
908
- id: "",
909
- app: "",
910
- match: "",
911
- summary: "",
912
- content: "",
913
- isNew: true
914
- });
1085
+ reset(draft.id, draft.app);
915
1086
  }
916
- }, "新建技能") : null, h$1("button", {
1087
+ }, "恢复内置版本") : null), h$1("div", { style: {
1088
+ display: "flex",
1089
+ gap: 8
1090
+ } }, h$1("button", {
917
1091
  type: "button",
1092
+ className: "dshcu-btn",
918
1093
  style: S.secondary,
919
1094
  disabled: busy,
1095
+ onClick: () => setDraft(null)
1096
+ }, "取消"), h$1("button", {
1097
+ type: "button",
1098
+ className: "dshcu-btn",
1099
+ style: {
1100
+ ...S.primary,
1101
+ opacity: busy || invalid ? .5 : 1
1102
+ },
1103
+ disabled: busy || invalid,
920
1104
  onClick: () => {
921
- call();
1105
+ save();
922
1106
  }
923
- }, "刷新"), 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);
1107
+ }, "保存技能"))))));
924
1108
  }
925
1109
  //#endregion
926
1110
  //#region lib/types/client/window-refs.js
@@ -1074,6 +1258,7 @@ window.__ModuleLoader__.load({
1074
1258
  restorePointer: s.restorePointer,
1075
1259
  protectPasswords: s.protectPasswords,
1076
1260
  windowChangeGuard: s.windowChangeGuard,
1261
+ cdpEnabled: s.cdpEnabled,
1077
1262
  cdpPort: String(s.cdpPort)
1078
1263
  };
1079
1264
  }
@@ -1118,6 +1303,7 @@ window.__ModuleLoader__.load({
1118
1303
  restorePointer: d.restorePointer,
1119
1304
  protectPasswords: d.protectPasswords,
1120
1305
  windowChangeGuard: d.windowChangeGuard,
1306
+ cdpEnabled: d.cdpEnabled,
1121
1307
  cdpPort: Math.round(Number(d.cdpPort))
1122
1308
  };
1123
1309
  }
@@ -1797,6 +1983,12 @@ window.__ModuleLoader__.load({
1797
1983
  checked: draft.quickSteps,
1798
1984
  disabled,
1799
1985
  onChange: (value) => edit("quickSteps", value)
1986
+ }), h(ToggleRow, {
1987
+ title: "启用本机 Chromium CDP 快车道",
1988
+ hint: "仅在主动开启或填写非 0 端口时连接 127.0.0.1 浏览器调试端口;严格按当前窗口标签匹配,失败自动回退 UIA/OCR,绝不误读其他标签页。",
1989
+ checked: draft.cdpEnabled,
1990
+ disabled,
1991
+ onChange: (value) => edit("cdpEnabled", value)
1800
1992
  }), h("div", { className: "dshcu-divider" }), h("div", { style: S.grid2 }, h(NumberField, {
1801
1993
  label: "停手多久后继续",
1802
1994
  unit: "毫秒",
@@ -1805,11 +1997,11 @@ window.__ModuleLoader__.load({
1805
1997
  disabled: disabled || !draft.pauseOnUserInput,
1806
1998
  onChange: (value) => edit("userIdleMs", value)
1807
1999
  }), h(NumberField, {
1808
- label: "可选 Chromium CDP 端口(0=自动探测 9222/9229)",
2000
+ label: "Chromium CDP 端口(0=默认 9222)",
1809
2001
  unit: "端口",
1810
2002
  value: draft.cdpPort,
1811
2003
  error: errors.cdpPort,
1812
- disabled,
2004
+ disabled: disabled || !draft.cdpEnabled,
1813
2005
  onChange: (value) => edit("cdpPort", value)
1814
2006
  }))), h("section", { className: "dshcu-card" }, h("div", { style: S.cardHeader }, h("h3", { style: S.cardTitle }, "截图与清晰度")), h(ToggleRow, {
1815
2007
  title: "操作后自动回传截图",