@t2000/engine 1.24.13 → 1.24.14

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
@@ -735,6 +735,13 @@ function cbRecord429(now) {
735
735
  cb429Timestamps = [];
736
736
  }
737
737
  }
738
+ function emitTerminalRetry(vendor, attemptZeroIndexed, outcome) {
739
+ getTelemetrySink().counter("external.retry_count", {
740
+ vendor,
741
+ outcome,
742
+ attempts: String(attemptZeroIndexed + 1)
743
+ });
744
+ }
738
745
  async function fetchBlockVisionWithRetry(url, init, opts = {}) {
739
746
  const rng = opts.rng ?? Math.random;
740
747
  const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve, reject) => {
@@ -780,10 +787,12 @@ async function fetchBlockVisionWithRetry(url, init, opts = {}) {
780
787
  }
781
788
  if (lastResponse.ok) {
782
789
  getTelemetrySink().counter("bv.requests", { status: "2xx", attempt: String(attempt) });
790
+ emitTerminalRetry("bv", attempt, attempt === 0 ? "first_try" : "retried_success");
783
791
  return lastResponse;
784
792
  }
785
793
  if (lastResponse.status !== 429 && lastResponse.status < 500) {
786
794
  getTelemetrySink().counter("bv.requests", { status: String(lastResponse.status), attempt: String(attempt) });
795
+ emitTerminalRetry("bv", attempt, attempt === 0 ? "first_try" : "retried_success");
787
796
  return lastResponse;
788
797
  }
789
798
  if (lastResponse.status === 429) {
@@ -791,12 +800,14 @@ async function fetchBlockVisionWithRetry(url, init, opts = {}) {
791
800
  const now = (opts.now ?? Date.now)();
792
801
  cbRecord429(now);
793
802
  if (cbIsOpen(now)) {
803
+ emitTerminalRetry("bv", attempt, "exhausted");
794
804
  return lastResponse;
795
805
  }
796
806
  } else {
797
807
  getTelemetrySink().counter("bv.requests", { status: "5xx", attempt: String(attempt) });
798
808
  }
799
809
  }
810
+ emitTerminalRetry("bv", BV_RETRY_MAX_ATTEMPTS - 1, "exhausted");
800
811
  if (lastResponse) return lastResponse;
801
812
  throw lastError ?? new Error("fetch failed after retries");
802
813
  }
@@ -10085,31 +10096,48 @@ var AnthropicProvider = class {
10085
10096
  }
10086
10097
  async *chat(params) {
10087
10098
  let attempt = 0;
10088
- while (true) {
10089
- let yieldedAnything = false;
10090
- const inner = this.streamOnce(params);
10091
- try {
10092
- for (; ; ) {
10093
- const next = await inner.next();
10094
- if (next.done) return;
10095
- yieldedAnything = true;
10096
- yield next.value;
10097
- }
10098
- } catch (err) {
10099
+ let success = false;
10100
+ try {
10101
+ while (true) {
10102
+ let yieldedAnything = false;
10103
+ const inner = this.streamOnce(params);
10099
10104
  try {
10100
- await inner.return?.(void 0);
10101
- } catch {
10102
- }
10103
- if (!yieldedAnything && isRetriableError(err) && attempt < this.maxRetries) {
10104
- attempt++;
10105
- const delayMs = computeBackoffMs(attempt);
10106
- console.warn(
10107
- `[anthropic] retriable error (attempt ${attempt}/${this.maxRetries}, retrying in ${delayMs}ms): ${rawErrorMessage(err)}`
10108
- );
10109
- await sleep(delayMs);
10110
- continue;
10105
+ for (; ; ) {
10106
+ const next = await inner.next();
10107
+ if (next.done) {
10108
+ success = true;
10109
+ return;
10110
+ }
10111
+ yieldedAnything = true;
10112
+ yield next.value;
10113
+ }
10114
+ } catch (err) {
10115
+ try {
10116
+ await inner.return?.(void 0);
10117
+ } catch {
10118
+ }
10119
+ if (!yieldedAnything && isRetriableError(err) && attempt < this.maxRetries) {
10120
+ attempt++;
10121
+ const delayMs = computeBackoffMs(attempt);
10122
+ console.warn(
10123
+ `[anthropic] retriable error (attempt ${attempt}/${this.maxRetries}, retrying in ${delayMs}ms): ${rawErrorMessage(err)}`
10124
+ );
10125
+ await sleep(delayMs);
10126
+ continue;
10127
+ }
10128
+ throw new Error(friendlyErrorMessage(err));
10111
10129
  }
10112
- throw new Error(friendlyErrorMessage(err));
10130
+ }
10131
+ } finally {
10132
+ const retried = attempt > 0;
10133
+ const outcome = !retried ? "first_try" : success ? "retried_success" : "exhausted";
10134
+ try {
10135
+ getTelemetrySink().counter("external.retry_count", {
10136
+ vendor: "anthropic",
10137
+ outcome,
10138
+ attempts: String(attempt + 1)
10139
+ });
10140
+ } catch {
10113
10141
  }
10114
10142
  }
10115
10143
  }