@copylee/dsh-computer-use 0.7.1 → 0.7.3

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
@@ -84,7 +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
+ | 操作时不深度思考(Beta) | 关 | 试验功能,一般不用开。开始操作电脑后,本轮改用模型的最低思考强度,每一步快约 1 秒;下一轮恢复会话里选的思考强度。不思考时模型更容易出错、多走几步;工具参数写坏时会自动重发那一步,为此本轮的回复文字整段出现而不是逐字流出。目前只在 DeepSeek 官方模型上有效 |
88
88
  | 检测到你在操作时让出控制 | 开 | 键盘输入暂停、窗口被切换时重新看屏幕 |
89
89
  | 文字输入方式 | 流式 | 流式(长文本逐段出现)/ 逐字输入(最像打字,最慢)/ 一次粘贴(最快) |
90
90
  | 键盘静止多久后恢复 | 1500 ms | |
package/lib/client.js CHANGED
@@ -1228,8 +1228,8 @@ window.__ModuleLoader__.load({
1228
1228
  ...S.hint,
1229
1229
  fontWeight: 400
1230
1230
  } }, "短文字都会逐字打出来。长文本逐字输入在 Typora、Obsidian、Word 等编辑器里可能被自动补全括号、自动续列表打乱;流式按段落粘贴,既看得到过程又不会乱。")))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "速度"), h(ToggleRow, {
1231
- title: "操作时不深度思考",
1232
- hint: "正在操作电脑的那几轮(看截图、决定下一步点哪里)改用模型的最低思考强度,每一步明显更快、动作更连贯;任务开头的规划和其他对话仍按会话里选的思考强度。模型不支持调整思考强度时不起作用。",
1231
+ title: "操作时不深度思考(Beta)",
1232
+ hint: "试验功能,一般不用开。开始操作电脑后,本轮改用模型的最低思考强度,每一步快约 1 秒;任务开头的规划和之后的对话仍按会话里选的思考强度。代价:不思考时模型更容易出错、多走几步,本轮的回复文字会整段出现而不是逐字流出。目前只在 DeepSeek 官方模型上有效。",
1233
1233
  checked: draft.quickSteps,
1234
1234
  disabled,
1235
1235
  onChange: (value) => edit("quickSteps", value)
package/lib/index.js CHANGED
@@ -2164,22 +2164,32 @@ function resolveConfig(raw) {
2164
2164
  * is "look at the screenshot, pick the next click". Deliberating over that
2165
2165
  * costs seconds per step and is what makes the motion feel halting, so those
2166
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.
2167
+ * not part of operating (planning from the user's message, turns that never
2168
+ * touch the computer) keep the session's own setting.
2169
2169
  */
2170
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?
2171
+ * Has this turn started operating the computer: is there a result of one of
2172
+ * this plugin's tools since the user's last message?
2173
+ *
2174
+ * It has to hold for the rest of the turn, not only right after such a result:
2175
+ * the replies written at the lowered effort carry no reasoning, and a provider
2176
+ * in thinking mode refuses a turn whose earlier tool-calling replies lack it
2177
+ * (DeepSeek: "content[].thinking ... must be passed back"). So once a turn has
2178
+ * a reply written without thinking, every later request of that turn goes
2179
+ * without it too.
2173
2180
  */
2174
2181
  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--) {
2182
+ let start = messages.length;
2183
+ while (start > 0 && messages[start - 1]?.role !== "user") start--;
2184
+ const names = /* @__PURE__ */ new Map();
2185
+ for (let index = start; index < messages.length; index++) {
2178
2186
  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;
2187
+ if (message?.role === "assistant" && Array.isArray(message.content)) {
2188
+ for (const part of message.content) if (part.type === "tool-call" && typeof part.id === "string" && typeof part.name === "string") names.set(part.id, part.name);
2189
+ } else if (message?.role === "tool" && typeof message.toolCallId === "string") {
2190
+ const name = names.get(message.toolCallId);
2191
+ if (name !== void 0 && ownTools.has(name)) return true;
2192
+ }
2183
2193
  }
2184
2194
  return false;
2185
2195
  }
@@ -2198,6 +2208,26 @@ function lowestEffort(efforts) {
2198
2208
  const pick = LOWEST.find((id) => ids.has(id));
2199
2209
  return pick === void 0 ? void 0 : efforts.find((effort) => String(effort.id).toLowerCase() === pick).id;
2200
2210
  }
2211
+ /**
2212
+ * Without deliberation the model now and then writes a tool call whose
2213
+ * arguments are not valid JSON, which the adapter raises as
2214
+ * MALFORMED_RESPONSE and which would end the turn. Such a reply is thrown
2215
+ * away and asked for again. The reply is held back until it is complete, as
2216
+ * events already passed on could not be taken back.
2217
+ */
2218
+ async function* retryMalformed(run, attempts = 3) {
2219
+ for (let attempt = 1;; attempt++) {
2220
+ const events = [];
2221
+ try {
2222
+ for await (const event of run()) events.push(event);
2223
+ } catch (error) {
2224
+ if (attempt < attempts && error?.code === "MALFORMED_RESPONSE") continue;
2225
+ throw error;
2226
+ }
2227
+ yield* events;
2228
+ return;
2229
+ }
2230
+ }
2201
2231
  //#endregion
2202
2232
  //#region lib/types/routes.js
2203
2233
  const STATUS_ROUTE = "/api/dsh-computer-use/status";
@@ -8936,8 +8966,8 @@ const Config = z.object({
8936
8966
  "en-US": { $description: "How text is entered" }
8937
8967
  }),
8938
8968
  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" }
8969
+ "zh-CN": { $description: "(Beta)操作电脑的那一轮用模型的最低思考强度(每步更快);其余沿用会话的思考强度" },
8970
+ "en-US": { $description: "(Beta) 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
8971
  }),
8942
8972
  autoScreenshot: z.boolean().default(true).volatile().i18n({
8943
8973
  "zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
@@ -9104,7 +9134,8 @@ function apply(ctx, config = {}) {
9104
9134
  reasoningEffort: effort
9105
9135
  });
9106
9136
  lowered.add(copy);
9107
- yield* llmCtx.llm.stream(copy);
9137
+ const llm = llmCtx.llm;
9138
+ yield* retryMalformed(() => llm.stream(copy));
9108
9139
  })();
9109
9140
  }), { global: true }), "computer-use: quick steps");
9110
9141
  });
@@ -3,15 +3,30 @@
3
3
  * is "look at the screenshot, pick the next click". Deliberating over that
4
4
  * costs seconds per step and is what makes the motion feel halting, so those
5
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.
6
+ * not part of operating (planning from the user's message, turns that never
7
+ * touch the computer) keep the session's own setting.
8
8
  */
9
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?
10
+ * Has this turn started operating the computer: is there a result of one of
11
+ * this plugin's tools since the user's last message?
12
+ *
13
+ * It has to hold for the rest of the turn, not only right after such a result:
14
+ * the replies written at the lowered effort carry no reasoning, and a provider
15
+ * in thinking mode refuses a turn whose earlier tool-calling replies lack it
16
+ * (DeepSeek: "content[].thinking ... must be passed back"). So once a turn has
17
+ * a reply written without thinking, every later request of that turn goes
18
+ * without it too.
12
19
  */
13
20
  export declare function isOperating(messages: readonly unknown[], ownTools: ReadonlySet<string>): boolean;
14
21
  /** The lowest reasoning effort a model offers, or undefined when it offers none we recognise. */
15
22
  export declare function lowestEffort(efforts: readonly {
16
23
  id: string;
17
24
  }[] | undefined): string | undefined;
25
+ /**
26
+ * Without deliberation the model now and then writes a tool call whose
27
+ * arguments are not valid JSON, which the adapter raises as
28
+ * MALFORMED_RESPONSE and which would end the turn. Such a reply is thrown
29
+ * away and asked for again. The reply is held back until it is complete, as
30
+ * events already passed on could not be taken back.
31
+ */
32
+ export declare function retryMalformed<T>(run: () => AsyncIterable<T>, attempts?: number): AsyncGenerator<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",