@copylee/dsh-computer-use 0.7.0 → 0.7.2

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
@@ -915,14 +915,18 @@ window.__ModuleLoader__.load({
915
915
  const [view, setView] = react.useState(void 0);
916
916
  const [draft, setDraft] = react.useState(() => draftFrom(void 0));
917
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;
918
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);
919
925
  const [message, setMessage] = react.useState(null);
920
926
  const [status, setStatus] = react.useState(null);
921
927
  const [cache, setCache] = react.useState(null);
922
928
  const [cacheBusy, setCacheBusy] = react.useState(false);
923
929
  const [cacheNote, setCacheNote] = react.useState(null);
924
- const dirtyRef = react.useRef(false);
925
- dirtyRef.current = dirty;
926
930
  const load = react.useCallback(async (reset) => {
927
931
  try {
928
932
  const result = await ctx.remote.settings.describe();
@@ -931,7 +935,8 @@ window.__ModuleLoader__.load({
931
935
  setWritable(result.value.writable);
932
936
  setView(found);
933
937
  if (reset || !dirtyRef.current) {
934
- setDraft(draftFrom(found?.value));
938
+ const stored = draftFrom(found?.value);
939
+ if (reset || JSON.stringify(valuesFrom(stored)) !== JSON.stringify(valuesFrom(draftRef.current))) setDraft(stored);
935
940
  setDirty(false);
936
941
  }
937
942
  } catch (error) {
@@ -1010,12 +1015,13 @@ window.__ModuleLoader__.load({
1010
1015
  };
1011
1016
  const errors = validate(draft);
1012
1017
  const invalid = Object.keys(errors).length > 0;
1013
- const disabled = !writable || view === void 0 || saving;
1018
+ const disabled = !writable || view === void 0;
1014
1019
  const save = async () => {
1015
1020
  if (view === void 0 || invalid) return;
1016
1021
  setSaving(true);
1022
+ const saved = draft;
1017
1023
  try {
1018
- const values = valuesFrom(draft);
1024
+ const values = valuesFrom(saved);
1019
1025
  const result = await ctx.remote.settings.mutate(ENTRY_ID, Object.entries(values).map(([key, value]) => ({
1020
1026
  op: "set",
1021
1027
  path: [key],
@@ -1024,12 +1030,16 @@ window.__ModuleLoader__.load({
1024
1030
  if (!result.ok) throw new Error(result.error.message);
1025
1031
  setMessage({
1026
1032
  kind: "ok",
1027
- text: "已保存,下一步操作即生效"
1033
+ text: "已自动保存,下一步操作即生效"
1028
1034
  });
1029
- setDirty(false);
1030
- await load(true);
1035
+ if (draftRef.current === saved) {
1036
+ dirtyRef.current = false;
1037
+ setDirty(false);
1038
+ }
1039
+ await load(false);
1031
1040
  refreshStatus();
1032
1041
  } catch (error) {
1042
+ setFailed(saved);
1033
1043
  setMessage({
1034
1044
  kind: "error",
1035
1045
  text: `保存失败:${error.message}`
@@ -1038,6 +1048,20 @@ window.__ModuleLoader__.load({
1038
1048
  setSaving(false);
1039
1049
  }
1040
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
+ ]);
1041
1065
  const preview = async () => {
1042
1066
  try {
1043
1067
  const response = await fetch(PREVIEW_ROUTE, {
@@ -1274,34 +1298,21 @@ window.__ModuleLoader__.load({
1274
1298
  refreshCache();
1275
1299
  }
1276
1300
  }, cacheBusy ? "统计中…" : "重新统计"), cacheNote === null ? null : h("span", { style: cacheNote.kind === "ok" ? S.ok : S.error }, cacheNote.text))), h("div", { style: S.actions }, h("button", {
1277
- type: "button",
1278
- style: {
1279
- ...S.primary,
1280
- opacity: disabled || !dirty || invalid ? .5 : 1
1281
- },
1282
- disabled: disabled || !dirty || invalid,
1283
- onClick: () => {
1284
- save();
1285
- }
1286
- }, saving ? "保存中…" : "保存"), h("button", {
1287
1301
  type: "button",
1288
1302
  style: S.secondary,
1289
- disabled: !dirty || saving,
1303
+ disabled,
1290
1304
  onClick: () => {
1291
- setDraft(draftFrom(view?.value));
1292
- setDirty(false);
1305
+ setDraft(draftFrom({}));
1306
+ setDirty(true);
1293
1307
  setMessage(null);
1294
1308
  }
1295
- }, "放弃修改"), h("button", {
1309
+ }, "恢复默认"), saving ? h("span", { style: S.hint }, "保存中…") : dirty && invalid ? h("span", { style: S.error }, "有数值超出范围,改好后自动保存") : failed === draft && dirty ? h("button", {
1296
1310
  type: "button",
1297
1311
  style: S.secondary,
1298
- disabled,
1299
1312
  onClick: () => {
1300
- setDraft(draftFrom({}));
1301
- setDirty(true);
1302
- setMessage(null);
1313
+ setFailed(null);
1303
1314
  }
1304
- }, "恢复默认"), dirty ? h("span", { style: S.hint }, "有未保存的修改") : null, message === null ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)), h(AccentPicker, null));
1315
+ }, "重试保存") : null, message === null || dirty && invalid ? null : h("span", { style: message.kind === "ok" ? S.ok : S.error }, message.text)), h(AccentPicker, null));
1305
1316
  }
1306
1317
  const inject = [
1307
1318
  "slots",
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
  }
@@ -3,12 +3,19 @@
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. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",