@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.
Binary file
Binary file
Binary file
package/dsh-plugin.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifestVersion": "0.15",
4
4
  "id": "dsh-bot.core",
5
5
  "name": "dsh-bot",
6
- "version": "0.3.9",
6
+ "version": "0.3.10",
7
7
  "license": "MIT",
8
8
  "facets": {
9
9
  "host": {
package/lib/client.js CHANGED
@@ -38,7 +38,7 @@
38
38
  'use strict';
39
39
 
40
40
  // 构建时由 tsdown 替换为 package.json.version(见 tsdown.config.ts)
41
- const BOT_BUILD = '0.3.9';
41
+ const BOT_BUILD = '0.3.10';
42
42
 
43
43
  // ============================================================
44
44
  // 设计令牌
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
- try {
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
- options.signal = options.signal ? AbortSignal.any([options.signal, idleController.signal]) : idleController.signal;
984
- for await (const chunk of llm.stream(options)) {
985
- resetIdle();
986
- switch (chunk?.type) {
987
- case "text-delta":
988
- text += chunk.text ?? "";
989
- break;
990
- case "reasoning-delta":
991
- reasoning += chunk.text ?? "";
992
- break;
993
- case "usage":
994
- usage = chunk.usage;
995
- break;
996
- case "finish":
997
- stopReason = chunk.stopReason ?? chunk.finishReason ?? chunk.reason;
998
- break;
999
- case "tool-call-delta": {
1000
- const idx = Number(chunk.index ?? 0);
1001
- let partial = streamingToolCalls.get(idx);
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
- streamingToolCalls.set(idx, partial);
1005
+ else stopReason = chunk.stopReason ?? chunk.finishReason ?? reason;
1006
+ break;
1009
1007
  }
1010
- if (typeof chunk.id === "string") partial.id = chunk.id;
1011
- if (typeof chunk.name === "string") partial.name = chunk.name;
1012
- if (typeof chunk.argumentsDelta === "string") partial.args += chunk.argumentsDelta;
1013
- break;
1014
- }
1015
- case "block-end": {
1016
- const block = chunk.block;
1017
- if (block?.type === "text" && !text) text = block.text ?? "";
1018
- if (block?.type === "reasoning" && !reasoning) reasoning = block.text ?? "";
1019
- const tu = asToolUse(block);
1020
- if (tu) toolUses.push(tu);
1021
- break;
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
- if (idleTimer) clearTimeout(idleTimer);
1036
- } catch (e) {
1037
- if (idleTimer) clearTimeout(idleTimer);
1038
- const detail = describeLlmError(e);
1039
- throw new Error(`模型调用失败(${input.provider}/${input.model}):${detail}`);
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 detail = describeLlmError(streamError.error ?? streamError);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zifeng1023/dsh-bot",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "常驻 AI 队友:记得住、守得住、收得回。默认 dry-run 演习、执行前自动快照、可一键回滚,并支持错峰调度省钱。",
5
5
  "repository": {
6
6
  "type": "git",
package/screenshots.json CHANGED
@@ -1,5 +1,5 @@
1
1
  [
2
- "assets/screenshot-v038-1.png",
3
- "assets/screenshot-v038-2.png",
4
- "assets/screenshot-v038-3.png"
2
+ "assets/screenshot-v039-1.jpg",
3
+ "assets/screenshot-v039-2.jpg",
4
+ "assets/screenshot-v039-3.jpg"
5
5
  ]