@copylee/dsh-computer-use 0.6.1 → 0.7.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/README.md +1 -0
- package/lib/client.js +50 -29
- package/lib/index.js +82 -1
- package/lib/types/computer.d.ts +2 -0
- package/lib/types/effort.d.ts +17 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,7 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
|
|
|
84
84
|
| 操作后自动截图 | 开 | 关闭可省 token,但模型需要自己截图 |
|
|
85
85
|
| 等待稳定 | 400 ms | 动作后至少等这么久,之后画面静止即截图(最多约 2.5 秒) |
|
|
86
86
|
| 截图最长边 / 总像素 / JPEG 质量 | 1366 / 1.15MP / 70 | 越大越清晰、越费 token |
|
|
87
|
+
| 操作时不深度思考 | 关 | 开启后,正在操作电脑的那几轮请求(看截图、决定下一步)改用模型的最低思考强度,每一步更快;任务开头的规划和其他对话仍按会话里选的思考强度。模型不提供可调的思考强度时不起作用 |
|
|
87
88
|
| 检测到你在操作时让出控制 | 开 | 键盘输入暂停、窗口被切换时重新看屏幕 |
|
|
88
89
|
| 文字输入方式 | 流式 | 流式(长文本逐段出现)/ 逐字输入(最像打字,最慢)/ 一次粘贴(最快) |
|
|
89
90
|
| 键盘静止多久后恢复 | 1500 ms | |
|
package/lib/client.js
CHANGED
|
@@ -45,7 +45,8 @@ window.__ModuleLoader__.load({
|
|
|
45
45
|
blockedApps: [],
|
|
46
46
|
pauseOnUserInput: true,
|
|
47
47
|
userIdleMs: 1500,
|
|
48
|
-
typingMode: "stream"
|
|
48
|
+
typingMode: "stream",
|
|
49
|
+
quickSteps: false
|
|
49
50
|
};
|
|
50
51
|
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
51
52
|
function resolveConfig(raw) {
|
|
@@ -69,6 +70,7 @@ window.__ModuleLoader__.load({
|
|
|
69
70
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
70
71
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
71
72
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
73
|
+
quickSteps: bool("quickSteps"),
|
|
72
74
|
typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
|
|
73
75
|
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
74
76
|
};
|
|
@@ -692,6 +694,7 @@ window.__ModuleLoader__.load({
|
|
|
692
694
|
hostWindow: s.hostWindow,
|
|
693
695
|
cardOpacity: s.cardOpacity,
|
|
694
696
|
typingMode: s.typingMode,
|
|
697
|
+
quickSteps: s.quickSteps,
|
|
695
698
|
pauseOnUserInput: s.pauseOnUserInput,
|
|
696
699
|
userIdleMs: String(s.userIdleMs),
|
|
697
700
|
autoScreenshot: s.autoScreenshot,
|
|
@@ -724,6 +727,7 @@ window.__ModuleLoader__.load({
|
|
|
724
727
|
hostWindow: d.hostWindow,
|
|
725
728
|
cardOpacity: d.cardOpacity,
|
|
726
729
|
typingMode: d.typingMode,
|
|
730
|
+
quickSteps: d.quickSteps,
|
|
727
731
|
pauseOnUserInput: d.pauseOnUserInput,
|
|
728
732
|
userIdleMs: Math.round(Number(d.userIdleMs)),
|
|
729
733
|
autoScreenshot: d.autoScreenshot,
|
|
@@ -911,14 +915,18 @@ window.__ModuleLoader__.load({
|
|
|
911
915
|
const [view, setView] = react.useState(void 0);
|
|
912
916
|
const [draft, setDraft] = react.useState(() => draftFrom(void 0));
|
|
913
917
|
const [dirty, setDirty] = react.useState(false);
|
|
918
|
+
const dirtyRef = react.useRef(false);
|
|
919
|
+
dirtyRef.current = dirty;
|
|
920
|
+
const draftRef = react.useRef(draft);
|
|
921
|
+
draftRef.current = draft;
|
|
914
922
|
const [saving, setSaving] = react.useState(false);
|
|
923
|
+
/** The draft whose save failed: not retried until it is edited again. */
|
|
924
|
+
const [failed, setFailed] = react.useState(null);
|
|
915
925
|
const [message, setMessage] = react.useState(null);
|
|
916
926
|
const [status, setStatus] = react.useState(null);
|
|
917
927
|
const [cache, setCache] = react.useState(null);
|
|
918
928
|
const [cacheBusy, setCacheBusy] = react.useState(false);
|
|
919
929
|
const [cacheNote, setCacheNote] = react.useState(null);
|
|
920
|
-
const dirtyRef = react.useRef(false);
|
|
921
|
-
dirtyRef.current = dirty;
|
|
922
930
|
const load = react.useCallback(async (reset) => {
|
|
923
931
|
try {
|
|
924
932
|
const result = await ctx.remote.settings.describe();
|
|
@@ -927,7 +935,8 @@ window.__ModuleLoader__.load({
|
|
|
927
935
|
setWritable(result.value.writable);
|
|
928
936
|
setView(found);
|
|
929
937
|
if (reset || !dirtyRef.current) {
|
|
930
|
-
|
|
938
|
+
const stored = draftFrom(found?.value);
|
|
939
|
+
if (reset || JSON.stringify(valuesFrom(stored)) !== JSON.stringify(valuesFrom(draftRef.current))) setDraft(stored);
|
|
931
940
|
setDirty(false);
|
|
932
941
|
}
|
|
933
942
|
} catch (error) {
|
|
@@ -1006,12 +1015,13 @@ window.__ModuleLoader__.load({
|
|
|
1006
1015
|
};
|
|
1007
1016
|
const errors = validate(draft);
|
|
1008
1017
|
const invalid = Object.keys(errors).length > 0;
|
|
1009
|
-
const disabled = !writable || view === void 0
|
|
1018
|
+
const disabled = !writable || view === void 0;
|
|
1010
1019
|
const save = async () => {
|
|
1011
1020
|
if (view === void 0 || invalid) return;
|
|
1012
1021
|
setSaving(true);
|
|
1022
|
+
const saved = draft;
|
|
1013
1023
|
try {
|
|
1014
|
-
const values = valuesFrom(
|
|
1024
|
+
const values = valuesFrom(saved);
|
|
1015
1025
|
const result = await ctx.remote.settings.mutate(ENTRY_ID, Object.entries(values).map(([key, value]) => ({
|
|
1016
1026
|
op: "set",
|
|
1017
1027
|
path: [key],
|
|
@@ -1020,12 +1030,16 @@ window.__ModuleLoader__.load({
|
|
|
1020
1030
|
if (!result.ok) throw new Error(result.error.message);
|
|
1021
1031
|
setMessage({
|
|
1022
1032
|
kind: "ok",
|
|
1023
|
-
text: "
|
|
1033
|
+
text: "已自动保存,下一步操作即生效"
|
|
1024
1034
|
});
|
|
1025
|
-
|
|
1026
|
-
|
|
1035
|
+
if (draftRef.current === saved) {
|
|
1036
|
+
dirtyRef.current = false;
|
|
1037
|
+
setDirty(false);
|
|
1038
|
+
}
|
|
1039
|
+
await load(false);
|
|
1027
1040
|
refreshStatus();
|
|
1028
1041
|
} catch (error) {
|
|
1042
|
+
setFailed(saved);
|
|
1029
1043
|
setMessage({
|
|
1030
1044
|
kind: "error",
|
|
1031
1045
|
text: `保存失败:${error.message}`
|
|
@@ -1034,6 +1048,20 @@ window.__ModuleLoader__.load({
|
|
|
1034
1048
|
setSaving(false);
|
|
1035
1049
|
}
|
|
1036
1050
|
};
|
|
1051
|
+
react.useEffect(() => {
|
|
1052
|
+
if (!dirty || invalid || disabled || saving || failed === draft) return;
|
|
1053
|
+
const timer = setTimeout(() => {
|
|
1054
|
+
save();
|
|
1055
|
+
}, 500);
|
|
1056
|
+
return () => clearTimeout(timer);
|
|
1057
|
+
}, [
|
|
1058
|
+
draft,
|
|
1059
|
+
dirty,
|
|
1060
|
+
invalid,
|
|
1061
|
+
disabled,
|
|
1062
|
+
saving,
|
|
1063
|
+
failed
|
|
1064
|
+
]);
|
|
1037
1065
|
const preview = async () => {
|
|
1038
1066
|
try {
|
|
1039
1067
|
const response = await fetch(PREVIEW_ROUTE, {
|
|
@@ -1199,7 +1227,13 @@ window.__ModuleLoader__.load({
|
|
|
1199
1227
|
}), h("span", { style: {
|
|
1200
1228
|
...S.hint,
|
|
1201
1229
|
fontWeight: 400
|
|
1202
|
-
} }, "短文字都会逐字打出来。长文本逐字输入在 Typora、Obsidian、Word 等编辑器里可能被自动补全括号、自动续列表打乱;流式按段落粘贴,既看得到过程又不会乱。")))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "
|
|
1230
|
+
} }, "短文字都会逐字打出来。长文本逐字输入在 Typora、Obsidian、Word 等编辑器里可能被自动补全括号、自动续列表打乱;流式按段落粘贴,既看得到过程又不会乱。")))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "速度"), h(ToggleRow, {
|
|
1231
|
+
title: "操作时不深度思考",
|
|
1232
|
+
hint: "正在操作电脑的那几轮(看截图、决定下一步点哪里)改用模型的最低思考强度,每一步明显更快、动作更连贯;任务开头的规划和其他对话仍按会话里选的思考强度。模型不支持调整思考强度时不起作用。",
|
|
1233
|
+
checked: draft.quickSteps,
|
|
1234
|
+
disabled,
|
|
1235
|
+
onChange: (value) => edit("quickSteps", value)
|
|
1236
|
+
})), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "让出控制"), h(ToggleRow, {
|
|
1203
1237
|
title: "检测到你在操作时暂停",
|
|
1204
1238
|
hint: "你用键盘打字时 AI 等你停手;你切换了窗口时 AI 先重新看屏幕。鼠标移动不会触发。",
|
|
1205
1239
|
checked: draft.pauseOnUserInput,
|
|
@@ -1264,34 +1298,21 @@ window.__ModuleLoader__.load({
|
|
|
1264
1298
|
refreshCache();
|
|
1265
1299
|
}
|
|
1266
1300
|
}, cacheBusy ? "统计中…" : "重新统计"), cacheNote === null ? null : h("span", { style: cacheNote.kind === "ok" ? S.ok : S.error }, cacheNote.text))), h("div", { style: S.actions }, h("button", {
|
|
1267
|
-
type: "button",
|
|
1268
|
-
style: {
|
|
1269
|
-
...S.primary,
|
|
1270
|
-
opacity: disabled || !dirty || invalid ? .5 : 1
|
|
1271
|
-
},
|
|
1272
|
-
disabled: disabled || !dirty || invalid,
|
|
1273
|
-
onClick: () => {
|
|
1274
|
-
save();
|
|
1275
|
-
}
|
|
1276
|
-
}, saving ? "保存中…" : "保存"), h("button", {
|
|
1277
1301
|
type: "button",
|
|
1278
1302
|
style: S.secondary,
|
|
1279
|
-
disabled
|
|
1303
|
+
disabled,
|
|
1280
1304
|
onClick: () => {
|
|
1281
|
-
setDraft(draftFrom(
|
|
1282
|
-
setDirty(
|
|
1305
|
+
setDraft(draftFrom({}));
|
|
1306
|
+
setDirty(true);
|
|
1283
1307
|
setMessage(null);
|
|
1284
1308
|
}
|
|
1285
|
-
}, "
|
|
1309
|
+
}, "恢复默认"), saving ? h("span", { style: S.hint }, "保存中…") : dirty && invalid ? h("span", { style: S.error }, "有数值超出范围,改好后自动保存") : failed === draft && dirty ? h("button", {
|
|
1286
1310
|
type: "button",
|
|
1287
1311
|
style: S.secondary,
|
|
1288
|
-
disabled,
|
|
1289
1312
|
onClick: () => {
|
|
1290
|
-
|
|
1291
|
-
setDirty(true);
|
|
1292
|
-
setMessage(null);
|
|
1313
|
+
setFailed(null);
|
|
1293
1314
|
}
|
|
1294
|
-
}, "
|
|
1315
|
+
}, "重试保存") : null, message === null || dirty && invalid ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)), h(AccentPicker, null));
|
|
1295
1316
|
}
|
|
1296
1317
|
const inject = [
|
|
1297
1318
|
"slots",
|
package/lib/index.js
CHANGED
|
@@ -2127,7 +2127,8 @@ const DEFAULTS = {
|
|
|
2127
2127
|
blockedApps: [],
|
|
2128
2128
|
pauseOnUserInput: true,
|
|
2129
2129
|
userIdleMs: 1500,
|
|
2130
|
-
typingMode: "stream"
|
|
2130
|
+
typingMode: "stream",
|
|
2131
|
+
quickSteps: false
|
|
2131
2132
|
};
|
|
2132
2133
|
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
2133
2134
|
function resolveConfig(raw) {
|
|
@@ -2151,11 +2152,53 @@ function resolveConfig(raw) {
|
|
|
2151
2152
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
2152
2153
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
2153
2154
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
2155
|
+
quickSteps: bool("quickSteps"),
|
|
2154
2156
|
typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
|
|
2155
2157
|
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
2156
2158
|
};
|
|
2157
2159
|
}
|
|
2158
2160
|
//#endregion
|
|
2161
|
+
//#region lib/types/effort.js
|
|
2162
|
+
/**
|
|
2163
|
+
* Quick steps: while the agent is operating the computer, each model request
|
|
2164
|
+
* is "look at the screenshot, pick the next click". Deliberating over that
|
|
2165
|
+
* costs seconds per step and is what makes the motion feel halting, so those
|
|
2166
|
+
* requests can run at the model's lowest reasoning effort. Requests that are
|
|
2167
|
+
* not in the middle of operating (planning from the user's message, working
|
|
2168
|
+
* with other tools) keep the session's own setting.
|
|
2169
|
+
*/
|
|
2170
|
+
/**
|
|
2171
|
+
* Is this request the continuation of computer use: was the last thing in the
|
|
2172
|
+
* conversation the result of one of this plugin's tools?
|
|
2173
|
+
*/
|
|
2174
|
+
function isOperating(messages, ownTools) {
|
|
2175
|
+
const last = messages[messages.length - 1];
|
|
2176
|
+
if (last?.role !== "tool" || typeof last.toolCallId !== "string") return false;
|
|
2177
|
+
for (let index = messages.length - 2; index >= 0; index--) {
|
|
2178
|
+
const message = messages[index];
|
|
2179
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) continue;
|
|
2180
|
+
const call = message.content.find((part) => part.type === "tool-call" && part.id === last.toolCallId);
|
|
2181
|
+
if (call) return typeof call.name === "string" && ownTools.has(call.name);
|
|
2182
|
+
return false;
|
|
2183
|
+
}
|
|
2184
|
+
return false;
|
|
2185
|
+
}
|
|
2186
|
+
/** Effort ids that mean "do not deliberate", best first. Only an exact, advertised id is ever used. */
|
|
2187
|
+
const LOWEST = [
|
|
2188
|
+
"off",
|
|
2189
|
+
"none",
|
|
2190
|
+
"disabled",
|
|
2191
|
+
"minimal",
|
|
2192
|
+
"low"
|
|
2193
|
+
];
|
|
2194
|
+
/** The lowest reasoning effort a model offers, or undefined when it offers none we recognise. */
|
|
2195
|
+
function lowestEffort(efforts) {
|
|
2196
|
+
if (!Array.isArray(efforts)) return void 0;
|
|
2197
|
+
const ids = new Set(efforts.map((effort) => String(effort.id).toLowerCase()));
|
|
2198
|
+
const pick = LOWEST.find((id) => ids.has(id));
|
|
2199
|
+
return pick === void 0 ? void 0 : efforts.find((effort) => String(effort.id).toLowerCase() === pick).id;
|
|
2200
|
+
}
|
|
2201
|
+
//#endregion
|
|
2159
2202
|
//#region lib/types/routes.js
|
|
2160
2203
|
const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
2161
2204
|
const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
@@ -8892,6 +8935,10 @@ const Config = z.object({
|
|
|
8892
8935
|
"zh-CN": { $description: "文字输入方式" },
|
|
8893
8936
|
"en-US": { $description: "How text is entered" }
|
|
8894
8937
|
}),
|
|
8938
|
+
quickSteps: z.boolean().default(false).volatile().i18n({
|
|
8939
|
+
"zh-CN": { $description: "操作电脑的那几轮请求用模型的最低思考强度(每步更快);其余请求沿用会话的思考强度" },
|
|
8940
|
+
"en-US": { $description: "Use the model's lowest reasoning effort for the requests in the middle of operating the computer (faster steps); other requests keep the session's effort" }
|
|
8941
|
+
}),
|
|
8895
8942
|
autoScreenshot: z.boolean().default(true).volatile().i18n({
|
|
8896
8943
|
"zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
|
|
8897
8944
|
"en-US": { $description: "Return a screenshot after every action (saves a round trip)" }
|
|
@@ -9027,6 +9074,40 @@ function apply(ctx, config = {}) {
|
|
|
9027
9074
|
}
|
|
9028
9075
|
};
|
|
9029
9076
|
});
|
|
9077
|
+
ctx.inject(["llm"], (llmCtx) => {
|
|
9078
|
+
const lowest = /* @__PURE__ */ new Map();
|
|
9079
|
+
const lowestFor = (provider, model) => {
|
|
9080
|
+
const key = `${provider}\u0000${model}`;
|
|
9081
|
+
let cached = lowest.get(key);
|
|
9082
|
+
if (!cached) {
|
|
9083
|
+
const llm = llmCtx.llm;
|
|
9084
|
+
cached = typeof llm.resolveModelInfo === "function" ? llm.resolveModelInfo(provider, model).then((info) => lowestEffort(info.reasoning?.efforts)).catch(() => {
|
|
9085
|
+
lowest.delete(key);
|
|
9086
|
+
}) : Promise.resolve(void 0);
|
|
9087
|
+
lowest.set(key, cached);
|
|
9088
|
+
}
|
|
9089
|
+
return cached;
|
|
9090
|
+
};
|
|
9091
|
+
const lowered = /* @__PURE__ */ new WeakSet();
|
|
9092
|
+
llmCtx.effect(() => llmCtx.on("llm/stream", ((options, next) => {
|
|
9093
|
+
if (!settings().quickSteps || !options.provider || !options.model || !Array.isArray(options.messages) || !isOperating(options.messages, OWN_TOOLS)) return next();
|
|
9094
|
+
if (lowered.has(options)) return next();
|
|
9095
|
+
const { provider, model } = options;
|
|
9096
|
+
return (async function* () {
|
|
9097
|
+
const effort = await lowestFor(provider, model);
|
|
9098
|
+
if (effort === void 0 || options.reasoningEffort === effort) {
|
|
9099
|
+
yield* next();
|
|
9100
|
+
return;
|
|
9101
|
+
}
|
|
9102
|
+
const copy = Object.freeze({
|
|
9103
|
+
...options,
|
|
9104
|
+
reasoningEffort: effort
|
|
9105
|
+
});
|
|
9106
|
+
lowered.add(copy);
|
|
9107
|
+
yield* llmCtx.llm.stream(copy);
|
|
9108
|
+
})();
|
|
9109
|
+
}), { global: true }), "computer-use: quick steps");
|
|
9110
|
+
});
|
|
9030
9111
|
ctx.on("agent/assistant-stream", ({ agent, frame }) => {
|
|
9031
9112
|
overlay.stream(agent, frame);
|
|
9032
9113
|
});
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface Settings {
|
|
|
22
22
|
userIdleMs: number;
|
|
23
23
|
/** How text is entered: stream = paste block by block, type = key by key, paste = at once. */
|
|
24
24
|
typingMode: TypingMode;
|
|
25
|
+
/** Run the model at its lowest reasoning effort for the requests in the middle of operating the computer. */
|
|
26
|
+
quickSteps: boolean;
|
|
25
27
|
}
|
|
26
28
|
export type TypingMode = 'stream' | 'type' | 'paste';
|
|
27
29
|
export interface WindowInfo extends WindowLike {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quick steps: while the agent is operating the computer, each model request
|
|
3
|
+
* is "look at the screenshot, pick the next click". Deliberating over that
|
|
4
|
+
* costs seconds per step and is what makes the motion feel halting, so those
|
|
5
|
+
* requests can run at the model's lowest reasoning effort. Requests that are
|
|
6
|
+
* not in the middle of operating (planning from the user's message, working
|
|
7
|
+
* with other tools) keep the session's own setting.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Is this request the continuation of computer use: was the last thing in the
|
|
11
|
+
* conversation the result of one of this plugin's tools?
|
|
12
|
+
*/
|
|
13
|
+
export declare function isOperating(messages: readonly unknown[], ownTools: ReadonlySet<string>): boolean;
|
|
14
|
+
/** The lowest reasoning effort a model offers, or undefined when it offers none we recognise. */
|
|
15
|
+
export declare function lowestEffort(efforts: readonly {
|
|
16
|
+
id: string;
|
|
17
|
+
}[] | undefined): string | undefined;
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED