agent-accelerator 0.5.1 → 0.5.3

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.
@@ -29,7 +29,21 @@ export function isTransientError(error: unknown): boolean {
29
29
  return false;
30
30
  }
31
31
 
32
- function readRetryAfterMs(error: unknown): number | undefined {
32
+ /**
33
+ * Whether a FAILED RUN (the provider layer already retried the call) is worth trying again: the failure is transient
34
+ * (HTTP 408/425/429/5xx, network codes, `transient`/`retryable` flags, `incomplete_stream`, a request/stream timeout).
35
+ * Never for aborts, bad configuration or input (401/403/400/404, `ConfigError`, `ValidationError`, `SecurityPolicyError`,
36
+ * `ThinkingLevelError`) and never for budgets or limits, which a retry would only reset or hit again.
37
+ */
38
+ export function isRetryableRun(error: unknown): boolean {
39
+ if (!error || isAbortError(error)) return false;
40
+ const name = (error as { name?: unknown }).name;
41
+ if (name === "TimeoutError") return true; // the loop's own request / first-byte / idle timeouts
42
+ if (["BudgetExceededError", "ConfigError", "ValidationError", "SecurityPolicyError", "SessionLoadError", "ThinkingLevelError", "ToolError"].includes(String(name))) return false;
43
+ return isTransientError(error);
44
+ }
45
+
46
+ export function readRetryAfterMs(error: unknown): number | undefined {
33
47
  const err = error as Record<string, unknown>;
34
48
  // Preferred: milliseconds attached by the adapter from the Retry-After header.
35
49
  const direct = err["retryAfterMs"];
@@ -43,7 +57,8 @@ function readRetryAfterMs(error: unknown): number | undefined {
43
57
  return Math.min(60_000, secs * 1000);
44
58
  }
45
59
 
46
- function sleep(ms: number, signal?: AbortSignal): Promise<void> {
60
+ // Waits `ms`, rejecting with an AbortError as soon as `signal` aborts; in: retry backoff and Google background polling, out: the awaiting caller.
61
+ export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
47
62
  if (ms <= 0) return Promise.resolve();
48
63
  return new Promise((resolve, reject) => {
49
64
  const timer = setTimeout(() => {