import { Effect } from "effect"; import { LanguageModel, Response } from "effect/unstable/ai"; import type { IdentityCell } from "./model-attempt-identity.js"; import type { Classification, Interface as Resilience } from "./model-resilience.js"; import type { CandidateIdentity, FailureDisposition } from "./model-registry.js"; import { InvocationCoordinationFailed, type EventPayload, type InvocationCoordinatorInterface, type ModelCallPurpose, type ModelFailureCategory, type ModelFirstOutputKind, type ModelInvocationMethod, type ModelProviderUsage } from "./model-telemetry.js"; export interface InstrumentOptions { readonly emit: (event: EventPayload) => Effect.Effect; readonly turn: number; readonly identity?: IdentityCell; readonly resilience?: Resilience; readonly logicalOperationId?: string; readonly nextCallOrdinal?: (persisted?: number) => number; readonly coordinator?: InvocationCoordinatorInterface; } export interface CallState { attempts: number; usage: Response.Usage | undefined; failedAttemptUsage: ModelProviderUsage | undefined; finishReason: Response.FinishReason | undefined; errorCategory: ModelFailureCategory | undefined; pendingFailure: PendingFailure | undefined; } export interface CallContext { readonly options: InstrumentOptions; readonly modelCallId: string; readonly logicalOperationId: string | undefined; readonly callOrdinal: number; readonly purpose: ModelCallPurpose; readonly provider: string | undefined; readonly model: string | undefined; readonly categorize: (error: unknown) => ModelFailureCategory; readonly classify: (error: unknown) => Classification; readonly state: CallState; } interface PendingFailure { readonly attempt: AttemptContext; readonly category: ModelFailureCategory; readonly classification: Classification; readonly usage: ModelProviderUsage | undefined; } interface Finished { readonly _tag: "Finished"; readonly reason: Response.FinishReason; readonly usage: Response.Usage; readonly at: number; } type Termination = { readonly _tag: "Open"; } | Finished; interface AttemptState { firstOutputs: Set; termination: Termination; settled: boolean; coordinated: boolean; requestId: string | undefined; responseModel: string | undefined; } interface AttemptContext { readonly modelAttemptId: string; readonly attempt: number; readonly method: ModelInvocationMethod; readonly state: AttemptState; readonly identity: CandidateIdentity | undefined; } export declare const settleFailure: { (disposition: FailureDisposition): (context: CallContext) => Effect.Effect; (context: CallContext, disposition: FailureDisposition): Effect.Effect; }; export declare const attemptModel: { (context: CallContext, identity?: CandidateIdentity): (model: LanguageModel.Service) => LanguageModel.Service; (model: LanguageModel.Service, context: CallContext, identity?: CandidateIdentity): LanguageModel.Service; }; export {};