import type { MissCode } from "./contract.js"; import { type VisionEnv } from "./env.js"; import type { Kind } from "./kinds.js"; import { type Capability, type Provider, type ProviderCall, type ProviderSource } from "./provider.js"; /** A derivation that could not be made: the miss code, and the cause the model reads. */ export type DeriveMiss = { readonly code: MissCode; readonly detail: string; }; /** The derived value, or the typed miss that says why there is none. */ export type DeriveOutcome = { readonly ok: true; readonly value: T; } | { readonly ok: false; readonly miss: DeriveMiss; }; /** The codes a provider may throw (`ProviderMiss`); the other `MissCode`s are the core's to name. */ export type ProviderMissCode = Extract; /** What a provider throws for a source it cannot serve, so the miss carries the right code. Any other error is `unreadable`. */ export declare class ProviderMiss extends Error { readonly code: ProviderMissCode; constructor(code: ProviderMissCode, message: string); } /** What a derivation runs with: the call's environment, the providers to try, where derived files are kept and the call's signal. */ export type DeriveContext = { readonly env: VisionEnv; /** In the order to try them: a binary first, the zero-install provider last. */ readonly providers: readonly Provider[]; /** Where derivations are kept. Without it nothing is kept. */ readonly deriveDir?: string; readonly signal?: AbortSignal; }; /** `.-`, without an extension: a derivation is named by what it came from and who made it. */ export declare const derivedName: (source: Pick, provider: Pick, version: string, part?: string) => string; /** The files one call keeps for its derivations, named by `derivedName`: where one is, what is in it, and a whole write. */ export type Derivations = { /** Where `name` is kept, or null when the host keeps nothing. */ path(name: string): string | null; /** The kept bytes, or null when there are none, they cannot be read, or they are not bytes this process kept there. */ read(name: string): Promise; /** Writes to a temp name and renames into place, so a reader never sees a partial file; the path, or null when nothing was kept. */ keep(name: string, bytes: Uint8Array): Promise; }; /** The derivation store of one call in `ctx.env`, under `ctx.deriveDir`; with no `deriveDir` nothing is kept. */ export declare function derivations(ctx: Pick): Derivations; /** Runs `attempt` with each provider of `job.kind` that has `job.capability` and runs here, in order, until one answers. * A caller that has stopped waiting gets its own error, never another provider. When none answers the miss is `needs` * if none could run, else the code of the first provider's failure with every distinct cause named. */ export declare function viaProviders(ctx: DeriveContext, job: { readonly kind: Kind; readonly capability: Capability; readonly what: string; }, attempt: (provider: Provider, version: string, call: ProviderCall) => Promise): Promise>;