From 8482c585091bb474412936961220a54e1d14b9b1 Mon Sep 17 00:00:00 2001 From: hannesrudolph Date: Wed, 18 Jun 2025 20:34:28 -0600 Subject: [PATCH] fix: remove unused retry.ts file to resolve knip CI failure --- src/api/retry.ts | 64 ------------------------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 src/api/retry.ts diff --git a/src/api/retry.ts b/src/api/retry.ts deleted file mode 100644 index 3a8849e4af..0000000000 --- a/src/api/retry.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Anthropic } from "@anthropic-ai/sdk" -import { ApiStream, ApiStreamError } from "./transform/stream" -import delay from "delay" - -const RETRIABLE_STATUS_CODES = [408, 429, 500, 502, 503, 504] -const MAX_RETRIES = 5 -const INITIAL_DELAY_MS = 2000 - -// `withRetry` is a decorator that adds retry logic to a method that returns an async generator. -// It will retry the method if it fails with a retriable error. -// It uses exponential backoff with jitter to delay between retries. -export function withRetry ApiStream>( - options: { - maxRetries?: number - baseDelay?: number - maxDelay?: number - } = {}, -) { - const { maxRetries = MAX_RETRIES, baseDelay = INITIAL_DELAY_MS } = options - - return function ( - _target: T, - _context: ClassMethodDecoratorContext, - ): (this: unknown, ...args: Parameters) => ApiStream { - const originalMethod = _target - - return async function* (this: unknown, ...args: Parameters): ApiStream { - let lastError: Error | undefined - for (let i = 0; i < maxRetries; i++) { - try { - yield* originalMethod.apply(this, args) - return - } catch (error: any) { - lastError = error - const isRetriable = - error instanceof Anthropic.APIError && - error.status && - RETRIABLE_STATUS_CODES.includes(error.status) - - if (!isRetriable) { - throw error - } - - const exponentialBackoff = Math.pow(2, i) - const jitter = Math.random() - const delayMs = Math.min( - options.maxDelay || Infinity, - baseDelay * exponentialBackoff * (1 + jitter), - ) - - await delay(delayMs) - } - } - - const error: ApiStreamError = { - type: "error", - error: "Retries exhausted", - message: lastError!.message, - } - - yield error - } - } -}