@livx.cc/agentx 0.99.132 → 0.99.134

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/dist/index.js CHANGED
@@ -5607,12 +5607,12 @@ var Agent = class _Agent {
5607
5607
  }
5608
5608
  const sc = err?.statusCode;
5609
5609
  const serverSide = sc >= 500 || sc === 408 || /Service Unavailable|overloaded|Internal server error|Bad gateway|Gateway time/i.test(String(err?.message ?? ""));
5610
- const network = !sc && /ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EPIPE|socket hang up|fetch failed|network|terminated|UND_ERR/i.test(String(err?.message ?? err?.code ?? err));
5610
+ const network = !sc && /ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EPIPE|socket hang up|socket connection was closed|closed unexpectedly|stream failed mid-response|premature close|fetch failed|network|terminated|UND_ERR/i.test(String(err?.message ?? err?.code ?? err));
5611
5611
  const stalled = err?.code === "stall";
5612
5612
  const empty = err?.code === "empty" || err?.code === "cursor_silent";
5613
5613
  const maxAttempts = empty ? Math.max(o.emptyRetries, 0) : 2;
5614
- const replaysTool = stalled && this.toolRanThisAttempt;
5615
- if (replaysTool) log9.warn("model stall after tool(s) already ran this step \u2014 not retrying (a retry would replay them)");
5614
+ const replaysTool = (stalled || network) && this.toolRanThisAttempt;
5615
+ if (replaysTool) log9.warn(`model ${stalled ? "stall" : "network drop"} after tool(s) already ran this step \u2014 not retrying (a retry would replay them)`);
5616
5616
  const transient = !o.signal?.aborted && !isAbortError(err) && !replaysTool && attempt < maxAttempts && (network || serverSide || stalled || empty);
5617
5617
  if (!transient) throw err;
5618
5618
  const waitMs = (empty ? o.emptyRetryBaseMs : 1e3) * (attempt + 1);
@@ -6123,7 +6123,7 @@ ${out}`;
6123
6123
  o.host?.notify?.({ kind: "compaction", message: `context full \u2014 auto-trimmed ${dropped} oldest message(s) to fit ~${Math.round(o.maxContextTokens / 1e3)}k tokens` });
6124
6124
  }
6125
6125
  }
6126
- out = dropOrphanToolResults(out);
6126
+ out = answerOpenToolCalls(dropOrphanToolResults(out));
6127
6127
  if (/^google\//.test(o.model ?? "")) out = hoistToolImages(out);
6128
6128
  return scrubBase64(out);
6129
6129
  }
@@ -6299,6 +6299,20 @@ var callIdSet = (msgs) => {
6299
6299
  for (const m of msgs) if (m.role === "assistant") for (const tc of m.tool_calls ?? []) ids.add(tc.id);
6300
6300
  return ids;
6301
6301
  };
6302
+ function answerOpenToolCalls(messages) {
6303
+ const answered = new Set(messages.filter((m) => m.role === "tool").map((m) => m.tool_call_id ?? ""));
6304
+ if (messages.every((m) => m.role !== "assistant" || (m.tool_calls ?? []).every((tc) => answered.has(tc.id)))) return messages;
6305
+ const out = [];
6306
+ for (let i = 0; i < messages.length; i++) {
6307
+ const m = messages[i];
6308
+ out.push(m);
6309
+ const open = m.role === "assistant" ? (m.tool_calls ?? []).filter((tc) => !answered.has(tc.id)) : [];
6310
+ if (!open.length) continue;
6311
+ while (i + 1 < messages.length && messages[i + 1].role === "tool") out.push(messages[++i]);
6312
+ for (const tc of open) out.push({ role: "tool", tool_call_id: tc.id, name: tc.function?.name, content: "not run \u2014 the turn stopped before this call (a limit or an interruption); run it again if it is still needed" });
6313
+ }
6314
+ return out;
6315
+ }
6302
6316
  function dropOrphanToolResults(messages) {
6303
6317
  const ids = callIdSet(messages);
6304
6318
  const ok = (m) => m.role !== "tool" || ids.has(m.tool_call_id ?? "");