| 351 | } |
| 352 | |
| 353 | const retryStatusFailures = <A, R>( |
| 354 | effect: Effect.Effect<A, LLMError, R>, |
| 355 | retries = MAX_RETRIES, |
| 356 | attempt = 0, |
| 357 | ): Effect.Effect<A, LLMError, R> => |
| 358 | Effect.catchTag(effect, "LLM.Error", (error): Effect.Effect<A, LLMError, R> => { |
| 359 | if (!error.retryable || retries <= 0) return Effect.fail(error) |
| 360 | return retryDelay(error, attempt).pipe( |
| 361 | Effect.flatMap((delay) => Effect.sleep(delay)), |
| 362 | Effect.flatMap(() => retryStatusFailures(effect, retries - 1, attempt + 1)), |
| 363 | ) |
| 364 | }) |
| 365 | |
| 366 | export const layer: Layer.Layer<Service, never, HttpClient.HttpClient> = Layer.effect( |
| 367 | Service, |