export async function retryWithExponentialBackoff( fn: () => Promise, maxRetries: number = 3, delayMs: number = 1000 ): Promise { let lastError: Error | undefined for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await fn() } catch (error) { lastError = error instanceof Error ? error : new Error(String(error)) if (attempt < maxRetries) { console.log(`Attempt ${attempt} failed, retrying in ${delayMs}ms...`) await new Promise(resolve => setTimeout(resolve, delayMs)) delayMs *= 2 } } } throw lastError }