@zqagent/core 0.3.10 → 0.3.12

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.
Files changed (37) hide show
  1. package/dist/{TurnEngine-BPKhWuSI.d.cts → TurnEngine-BSciNywD.d.cts} +23 -4
  2. package/dist/{TurnEngine-DtGEuVLT.d.ts → TurnEngine-BU4R7q_0.d.ts} +23 -4
  3. package/dist/index.cjs +144 -21
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +53 -4
  6. package/dist/index.d.ts +53 -4
  7. package/dist/index.js +142 -21
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/engine/FileLogHook.d.cts +2 -1
  10. package/dist/internal/engine/FileLogHook.d.ts +2 -1
  11. package/dist/internal/llmConfig.cjs +15 -0
  12. package/dist/internal/llmConfig.cjs.map +1 -1
  13. package/dist/internal/llmConfig.d.cts +15 -0
  14. package/dist/internal/llmConfig.d.ts +15 -0
  15. package/dist/internal/llmConfig.js +15 -0
  16. package/dist/internal/llmConfig.js.map +1 -1
  17. package/dist/internal/providers/diagnostics.cjs +39 -5
  18. package/dist/internal/providers/diagnostics.cjs.map +1 -1
  19. package/dist/internal/providers/diagnostics.d.cts +35 -3
  20. package/dist/internal/providers/diagnostics.d.ts +35 -3
  21. package/dist/internal/providers/diagnostics.js +34 -4
  22. package/dist/internal/providers/diagnostics.js.map +1 -1
  23. package/dist/internal/providers/models.cjs.map +1 -1
  24. package/dist/internal/providers/models.js.map +1 -1
  25. package/dist/internal/update/controller.cjs +2 -2
  26. package/dist/internal/update/controller.cjs.map +1 -1
  27. package/dist/internal/update/controller.js +1 -1
  28. package/dist/internal/update/platform.cjs +2 -2
  29. package/dist/internal/update/platform.cjs.map +1 -1
  30. package/dist/internal/update/platform.js +1 -1
  31. package/dist/tools/explore.cjs +76 -4
  32. package/dist/tools/explore.cjs.map +1 -1
  33. package/dist/tools/explore.d.cts +2 -1
  34. package/dist/tools/explore.d.ts +2 -1
  35. package/dist/tools/explore.js +76 -4
  36. package/dist/tools/explore.js.map +1 -1
  37. package/package.json +4 -3
@@ -1966,6 +1966,76 @@ function applyToolResultBudget(tool, result, opts = {}) {
1966
1966
  return { content, truncated: true, savedPath };
1967
1967
  }
1968
1968
 
1969
+ // src/engine/history.ts
1970
+ function repairToolCallHistoryDetailed(messages) {
1971
+ const out = [];
1972
+ let droppedCalls = 0;
1973
+ let droppedResults = 0;
1974
+ let droppedMessages = 0;
1975
+ let i = 0;
1976
+ while (i < messages.length) {
1977
+ const m = messages[i];
1978
+ if (m.role === "tool") {
1979
+ droppedResults += 1;
1980
+ i += 1;
1981
+ continue;
1982
+ }
1983
+ const calls = m.role === "assistant" ? m.tool_calls : void 0;
1984
+ if (!calls?.length) {
1985
+ if (m.role === "assistant" && m.tool_calls) {
1986
+ const { tool_calls, ...rest } = m;
1987
+ void tool_calls;
1988
+ out.push(rest);
1989
+ } else {
1990
+ out.push(m);
1991
+ }
1992
+ i += 1;
1993
+ continue;
1994
+ }
1995
+ const responders = /* @__PURE__ */ new Map();
1996
+ const notices = [];
1997
+ let j = i + 1;
1998
+ while (j < messages.length) {
1999
+ const t = messages[j];
2000
+ if (t.role === "notice") {
2001
+ notices.push(t);
2002
+ j += 1;
2003
+ continue;
2004
+ }
2005
+ if (t.role !== "tool") break;
2006
+ if (t.tool_call_id && !responders.has(t.tool_call_id)) {
2007
+ responders.set(t.tool_call_id, t);
2008
+ }
2009
+ j += 1;
2010
+ }
2011
+ const kept = calls.filter((tc) => tc.id && responders.has(tc.id));
2012
+ droppedCalls += calls.length - kept.length;
2013
+ droppedResults += responders.size - kept.length;
2014
+ if (kept.length === 0) {
2015
+ const { tool_calls, ...rest } = m;
2016
+ void tool_calls;
2017
+ if ((rest.content ?? "").trim() !== "") out.push(rest);
2018
+ else droppedMessages += 1;
2019
+ out.push(...notices);
2020
+ } else {
2021
+ out.push(kept.length === calls.length ? m : { ...m, tool_calls: kept });
2022
+ for (const tc of kept) out.push(responders.get(tc.id));
2023
+ out.push(...notices);
2024
+ }
2025
+ i = j;
2026
+ }
2027
+ const unchanged = out.length === messages.length && out.every((m, idx) => m === messages[idx]);
2028
+ return {
2029
+ messages: unchanged ? messages : out,
2030
+ droppedCalls,
2031
+ droppedResults,
2032
+ droppedMessages
2033
+ };
2034
+ }
2035
+ function repairToolCallHistory(messages) {
2036
+ return repairToolCallHistoryDetailed(messages).messages;
2037
+ }
2038
+
1969
2039
  // src/engine/TurnEngine.ts
1970
2040
  var crypto = __toESM(require("crypto"), 1);
1971
2041
  var fs3 = __toESM(require("fs"), 1);
@@ -2387,6 +2457,7 @@ ${notice}` : text,
2387
2457
  attachments = routed.attachments;
2388
2458
  this.taskId = taskId;
2389
2459
  this._turnStartTime = Date.now();
2460
+ this.messages = repairToolCallHistory(this.messages);
2390
2461
  this.messages.push({
2391
2462
  role: "user",
2392
2463
  content: userInput,
@@ -3388,7 +3459,7 @@ ${notice}` : text,
3388
3459
  /** 过滤 notice + 剥离 display-only 字段,得到最终发送视图 */
3389
3460
  _finalizeOutbound(sourceMessages) {
3390
3461
  const _STRIP = /* @__PURE__ */ new Set(["source", "_display", "ts", "reasoning", "usage", "attachmentRefs"]);
3391
- return sourceMessages.filter((m) => m.role !== "notice").map((m) => {
3462
+ const stripped = sourceMessages.filter((m) => m.role !== "notice").map((m) => {
3392
3463
  if (m.role === "tool") {
3393
3464
  return {
3394
3465
  role: "tool",
@@ -3397,15 +3468,16 @@ ${notice}` : text,
3397
3468
  };
3398
3469
  }
3399
3470
  const staleAttachments = Boolean(m.attachments?.length) && (m.ts ?? 0) < this._turnStartTime;
3400
- const stripped = {};
3471
+ const plain = {};
3401
3472
  for (const [k, v] of Object.entries(m)) {
3402
3473
  if (staleAttachments && k === "attachments") continue;
3403
3474
  if (!_STRIP.has(k)) {
3404
- stripped[k] = v;
3475
+ plain[k] = v;
3405
3476
  }
3406
3477
  }
3407
- return stripped;
3478
+ return plain;
3408
3479
  });
3480
+ return repairToolCallHistory(stripped);
3409
3481
  }
3410
3482
  /** 软阈值(token 数):达到它只淘汰旧工具结果 */
3411
3483
  _softTriggerTokens() {