export interface RetryOptions { maxAttempts: number; delayMs: number; } export const utils = { async sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); }, async retry(fn: () => Promise, options: RetryOptions): Promise { let lastError: Error | undefined; for (let attempt = 1; attempt <= options.maxAttempts; attempt++) { try { return await fn(); } catch (error) { lastError = error as Error; if (attempt < options.maxAttempts) { await this.sleep(options.delayMs); } } } throw lastError; }, async parallel(tasks: Array<() => Promise>): Promise { return Promise.all(tasks.map((task) => task())); }, async sequence(tasks: Array<() => Promise>): Promise { const results: T[] = []; for (const task of tasks) { results.push(await task()); } return results; }, };