@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 +38 -27
- package/lib/index.js +21 -11
- package/lib/types/effort.d.ts +11 -4
- package/package.json +1 -1
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
1030
|
-
|
|
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
|
|
1303
|
+
disabled,
|
|
1290
1304
|
onClick: () => {
|
|
1291
|
-
setDraft(draftFrom(
|
|
1292
|
-
setDirty(
|
|
1305
|
+
setDraft(draftFrom({}));
|
|
1306
|
+
setDirty(true);
|
|
1293
1307
|
setMessage(null);
|
|
1294
1308
|
}
|
|
1295
|
-
}, "
|
|
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
|
-
|
|
1301
|
-
setDirty(true);
|
|
1302
|
-
setMessage(null);
|
|
1313
|
+
setFailed(null);
|
|
1303
1314
|
}
|
|
1304
|
-
}, "
|
|
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
|
|
2168
|
-
*
|
|
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
|
-
*
|
|
2172
|
-
*
|
|
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
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
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
|
|
2180
|
-
|
|
2181
|
-
if (
|
|
2182
|
-
|
|
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
|
}
|
package/lib/types/effort.d.ts
CHANGED
|
@@ -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
|
|
7
|
-
*
|
|
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
|
-
*
|
|
11
|
-
*
|
|
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