<const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(
...plans: Plans
): ExecutionPlan<{
provides: make.PlanProvides<Plans>
input: make.PlanInput<Plans>
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never
requirements: Plans[number] extends ExecutionPlan<infer T>
? T["requirements"]
: never
}>Combines multiple execution plans by concatenating their steps in order.
When to use
Use to combine separately defined fallback plans into one ordered plan before applying it to an effect or stream.
Details
The resulting plan tries every step from the first plan, then every step from the next plan, and so on.
export const const merge: <
Plans extends NonEmptyReadonlyArray<
ExecutionPlan<any>
>
>(
...plans: Plans
) => ExecutionPlan<{
provides: make.PlanProvides<Plans>
input: make.PlanInput<Plans>
error: Plans[number] extends ExecutionPlan<
infer T
>
? T["error"]
: never
requirements: Plans[number] extends ExecutionPlan<
infer T
>
? T["requirements"]
: never
}>
Combines multiple execution plans by concatenating their steps in order.
When to use
Use to combine separately defined fallback plans into one ordered plan before
applying it to an effect or stream.
Details
The resulting plan tries every step from the first plan, then every step from
the next plan, and so on.
merge = <const function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans extends import NonEmptyReadonlyArrayNonEmptyReadonlyArray<interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<any>>>(
...plans: const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>plans: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans
): interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<{
provides: make.PlanProvides<Plans, unknown>provides: make.type make.PlanProvides<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends readonly [infer Plan, ...infer Rest] ? make.PlanProvides<Rest, Out & (Plan extends ExecutionPlan<infer T extends {
provides: any;
input: any;
error: any;
requirements: any;
}> ? T["provides"] : unknown)> : Out
Computes the intersection of services provided by a list of execution plans.
PlanProvides<function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans>
input: make.PlanInput<Plans, unknown>input: make.type make.PlanInput<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends readonly [infer Plan, ...infer Rest] ? make.PlanInput<Rest, Out & (Plan extends ExecutionPlan<infer T extends {
provides: any;
input: any;
error: any;
requirements: any;
}> ? T["input"] : unknown)> : Out
Computes the combined input type consumed by a list of execution plans.
PlanInput<function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans>
error: Plans[number] extends ExecutionPlan<
infer T
>
? T["error"]
: never
error: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans[number] extends interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<infer function (type parameter) TT> ? function (type parameter) TT["error"] : never
requirements: Plans[number] extends ExecutionPlan<
infer T
>
? T["requirements"]
: never
requirements: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans[number] extends interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<infer function (type parameter) TT> ? function (type parameter) TT["requirements"] : never
}> => const makeProto: <
Provides,
In,
PlanE,
PlanR
>(
steps: ExecutionPlan<{
provides: Provides
input: In
error: PlanE
requirements: PlanR
}>["steps"]
) => any
makeProto(plans: const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>plans.flatMap((plan: ExecutionPlan<any>(parameter) plan: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
plan) => plan: ExecutionPlan<any>(parameter) plan: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
plan.steps) as any)