agent.libx.js 0.94.9 → 0.94.11

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
@@ -2981,12 +2981,24 @@ var Agent = class _Agent {
2981
2981
  ...o.providerOptions || cursorPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo } } : {}
2982
2982
  };
2983
2983
  try {
2984
- if (useStream) {
2985
- const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: true, signal: o.signal, ...o.toolChoice ? { toolChoice: o.toolChoice } : {}, ...reasonOpts });
2986
- res = await this.consumeStream(r);
2987
- } else {
2988
- const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: false, signal: o.signal, ...o.toolChoice ? { toolChoice: o.toolChoice } : {}, ...reasonOpts });
2989
- res = r;
2984
+ for (let attempt = 0; ; attempt++) {
2985
+ try {
2986
+ if (useStream) {
2987
+ const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: true, signal: o.signal, ...o.toolChoice ? { toolChoice: o.toolChoice } : {}, ...reasonOpts });
2988
+ res = await this.consumeStream(r);
2989
+ } else {
2990
+ const r = await o.ai.chat({ model: o.model, messages: sent, tools: wireTools, stream: false, signal: o.signal, ...o.toolChoice ? { toolChoice: o.toolChoice } : {}, ...reasonOpts });
2991
+ res = r;
2992
+ }
2993
+ break;
2994
+ } catch (err) {
2995
+ const transient = !o.signal?.aborted && !isAbortError(err) && !err?.statusCode && attempt < 2 && /ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EPIPE|socket hang up|fetch failed|network|terminated|UND_ERR/i.test(String(err?.message ?? err?.code ?? err));
2996
+ if (!transient) throw err;
2997
+ const waitMs = 1e3 * (attempt + 1);
2998
+ log3.warn(`network drop mid-step (${err?.message ?? err}) \u2014 retrying in ${waitMs}ms`);
2999
+ o.host?.notify?.({ kind: "retry", message: `connection dropped \u2014 retrying step (#${attempt + 1})` });
3000
+ await new Promise((r) => setTimeout(r, waitMs));
3001
+ }
2990
3002
  }
2991
3003
  } catch (err) {
2992
3004
  if (err?.code === "budget") return kill("budget");