@zifeng1023/dsh-bot 0.3.9 → 0.3.10
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/assets/screenshot-v039-1.jpg +0 -0
- package/assets/screenshot-v039-2.jpg +0 -0
- package/assets/screenshot-v039-3.jpg +0 -0
- package/dsh-plugin.json +1 -1
- package/lib/client.js +1 -1
- package/lib/index.js +103 -56
- package/package.json +1 -1
- package/screenshots.json +3 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dsh-plugin.json
CHANGED
package/lib/client.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -933,9 +933,10 @@ function createLlmInvoker(ctx) {
|
|
|
933
933
|
const options = {
|
|
934
934
|
provider: input.provider,
|
|
935
935
|
model: input.model,
|
|
936
|
-
messages
|
|
937
|
-
reasoningEffort: input.reasoningEffort
|
|
936
|
+
messages
|
|
938
937
|
};
|
|
938
|
+
const sentEffort = input.reasoningEffort;
|
|
939
|
+
if (sentEffort !== void 0) options.reasoningEffort = sentEffort;
|
|
939
940
|
if (input.maxTokens !== void 0) options.maxTokens = input.maxTokens;
|
|
940
941
|
else {
|
|
941
942
|
const hit = [
|
|
@@ -972,7 +973,8 @@ function createLlmInvoker(ctx) {
|
|
|
972
973
|
}
|
|
973
974
|
if (input.signal) options.signal = input.signal;
|
|
974
975
|
if (input.tools?.length) options.tools = input.tools;
|
|
975
|
-
|
|
976
|
+
/** 把「一次流式尝试」跑完,结果写回上面的状态变量(供失败重试用) */
|
|
977
|
+
const consumeStream = async (opts) => {
|
|
976
978
|
const IDLE_MS = 9e4;
|
|
977
979
|
const idleController = new AbortController();
|
|
978
980
|
const resetIdle = () => {
|
|
@@ -980,63 +982,99 @@ function createLlmInvoker(ctx) {
|
|
|
980
982
|
idleTimer = setTimeout(() => idleController.abort(/* @__PURE__ */ new Error("stream idle > 90s")), IDLE_MS);
|
|
981
983
|
};
|
|
982
984
|
resetIdle();
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
if (!partial) {
|
|
1003
|
-
partial = {
|
|
1004
|
-
id: void 0,
|
|
1005
|
-
name: void 0,
|
|
1006
|
-
args: ""
|
|
985
|
+
opts.signal = opts.signal ? AbortSignal.any([opts.signal, idleController.signal]) : idleController.signal;
|
|
986
|
+
try {
|
|
987
|
+
for await (const chunk of llm.stream(opts)) {
|
|
988
|
+
resetIdle();
|
|
989
|
+
switch (chunk?.type) {
|
|
990
|
+
case "text-delta":
|
|
991
|
+
text += chunk.text ?? "";
|
|
992
|
+
break;
|
|
993
|
+
case "reasoning-delta":
|
|
994
|
+
reasoning += chunk.text ?? "";
|
|
995
|
+
break;
|
|
996
|
+
case "usage":
|
|
997
|
+
usage = chunk.usage;
|
|
998
|
+
break;
|
|
999
|
+
case "finish": {
|
|
1000
|
+
const reason = chunk.reason;
|
|
1001
|
+
if (reason && typeof reason === "object" && reason.kind !== void 0 && reason.kind !== "stop" && reason.kind !== "length") streamError = {
|
|
1002
|
+
type: "finish",
|
|
1003
|
+
reason
|
|
1007
1004
|
};
|
|
1008
|
-
|
|
1005
|
+
else stopReason = chunk.stopReason ?? chunk.finishReason ?? reason;
|
|
1006
|
+
break;
|
|
1009
1007
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1008
|
+
case "tool-call-delta": {
|
|
1009
|
+
const idx = Number(chunk.index ?? 0);
|
|
1010
|
+
let partial = streamingToolCalls.get(idx);
|
|
1011
|
+
if (!partial) {
|
|
1012
|
+
partial = {
|
|
1013
|
+
id: void 0,
|
|
1014
|
+
name: void 0,
|
|
1015
|
+
args: ""
|
|
1016
|
+
};
|
|
1017
|
+
streamingToolCalls.set(idx, partial);
|
|
1018
|
+
}
|
|
1019
|
+
if (typeof chunk.id === "string") partial.id = chunk.id;
|
|
1020
|
+
if (typeof chunk.name === "string") partial.name = chunk.name;
|
|
1021
|
+
if (typeof chunk.argumentsDelta === "string") partial.args += chunk.argumentsDelta;
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
case "block-end": {
|
|
1025
|
+
const block2 = chunk.block;
|
|
1026
|
+
if (block2?.type === "text" && !text) text = block2.text ?? "";
|
|
1027
|
+
if (block2?.type === "reasoning" && !reasoning) reasoning = block2.text ?? "";
|
|
1028
|
+
const tu = asToolUse(block2);
|
|
1029
|
+
if (tu) toolUses.push(tu);
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
case "error":
|
|
1033
|
+
case "adapter-failure":
|
|
1034
|
+
case "aborted":
|
|
1035
|
+
streamError = chunk;
|
|
1036
|
+
break;
|
|
1037
|
+
case "block-start":
|
|
1038
|
+
case "block-delta": break;
|
|
1039
|
+
default:
|
|
1040
|
+
if (chunk?.type) oddChunks.push(String(chunk.type));
|
|
1041
|
+
break;
|
|
1022
1042
|
}
|
|
1023
|
-
case "error":
|
|
1024
|
-
case "adapter-failure":
|
|
1025
|
-
case "aborted":
|
|
1026
|
-
streamError = chunk;
|
|
1027
|
-
break;
|
|
1028
|
-
case "block-start":
|
|
1029
|
-
case "block-delta": break;
|
|
1030
|
-
default:
|
|
1031
|
-
if (chunk?.type) oddChunks.push(String(chunk.type));
|
|
1032
|
-
break;
|
|
1033
1043
|
}
|
|
1044
|
+
} catch (e) {
|
|
1045
|
+
streamError = {
|
|
1046
|
+
type: "thrown",
|
|
1047
|
+
error: e
|
|
1048
|
+
};
|
|
1049
|
+
} finally {
|
|
1050
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
1034
1051
|
}
|
|
1035
|
-
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1052
|
+
};
|
|
1053
|
+
/** 从任意失败形状里取出 { code, message }(宿主用 reason.failure,我们归一后用 error) */
|
|
1054
|
+
const failureOf = (err) => {
|
|
1055
|
+
if (!err) return {};
|
|
1056
|
+
const f = err.reason?.failure ?? err.failure ?? err.error ?? err;
|
|
1057
|
+
if (!f) return {};
|
|
1058
|
+
return {
|
|
1059
|
+
code: typeof f.code === "string" ? f.code : void 0,
|
|
1060
|
+
message: typeof f.message === "string" ? f.message : void 0
|
|
1061
|
+
};
|
|
1062
|
+
};
|
|
1063
|
+
await consumeStream(options);
|
|
1064
|
+
const notes = [];
|
|
1065
|
+
if (streamError && sentEffort !== void 0 && failureOf(streamError).code === "UNSUPPORTED_REASONING_EFFORT") {
|
|
1066
|
+
text = "";
|
|
1067
|
+
reasoning = "";
|
|
1068
|
+
usage = void 0;
|
|
1069
|
+
stopReason = void 0;
|
|
1070
|
+
streamError = void 0;
|
|
1071
|
+
oddChunks.length = 0;
|
|
1072
|
+
toolUses.length = 0;
|
|
1073
|
+
streamingToolCalls.clear();
|
|
1074
|
+
const retryOptions = { ...options };
|
|
1075
|
+
delete retryOptions.reasoningEffort;
|
|
1076
|
+
await consumeStream(retryOptions);
|
|
1077
|
+
if (!streamError) notes.push(`模型 ${input.provider}/${input.model} 未声明推理级别,已自动关闭 reasoningEffort=${sentEffort} 重试。要保留该设置,请在模型条目里声明 reasoningEfforts。`);
|
|
1040
1078
|
}
|
|
1041
1079
|
if (streamingToolCalls.size > 0) for (const [, partial] of [...streamingToolCalls.entries()].sort((a, b) => a[0] - b[0])) {
|
|
1042
1080
|
if (!partial.name) continue;
|
|
@@ -1048,7 +1086,11 @@ function createLlmInvoker(ctx) {
|
|
|
1048
1086
|
});
|
|
1049
1087
|
}
|
|
1050
1088
|
if (streamError && !text && toolUses.length === 0) {
|
|
1051
|
-
const
|
|
1089
|
+
const f = failureOf(streamError);
|
|
1090
|
+
const detail = describeLlmError({
|
|
1091
|
+
code: f.code,
|
|
1092
|
+
message: f.message
|
|
1093
|
+
});
|
|
1052
1094
|
throw new Error(`模型返回错误(${input.provider}/${input.model}):${detail}`);
|
|
1053
1095
|
}
|
|
1054
1096
|
if (!text.trim() && toolUses.length === 0) {
|
|
@@ -1071,6 +1113,7 @@ function createLlmInvoker(ctx) {
|
|
|
1071
1113
|
outputTokens
|
|
1072
1114
|
});
|
|
1073
1115
|
return {
|
|
1116
|
+
notes: notes.length ? notes : void 0,
|
|
1074
1117
|
text,
|
|
1075
1118
|
reasoning: reasoning || void 0,
|
|
1076
1119
|
usage: {
|
|
@@ -5283,6 +5326,10 @@ var RoutineRunner = class {
|
|
|
5283
5326
|
signal
|
|
5284
5327
|
});
|
|
5285
5328
|
record.usage = addUsage(record.usage, out.usage);
|
|
5329
|
+
if (out.notes?.length) stepRecord.args = {
|
|
5330
|
+
...stepRecord.args ?? {},
|
|
5331
|
+
notes: out.notes
|
|
5332
|
+
};
|
|
5286
5333
|
const over = this.overBudget(bot, baseline, record.usage.costCny);
|
|
5287
5334
|
if (over) {
|
|
5288
5335
|
record.status = "budget_exceeded";
|
package/package.json
CHANGED
package/screenshots.json
CHANGED