export type ContractEvent = | { type: "attempt"; attempt: number; prompt: string; } | { type: "parse_error"; attempt: number; rawText: string; error: string; } | { type: "validation_error"; attempt: number; rawText: string; parsed: unknown; issues: ContractIssue[]; } | { type: "success"; attempt: number; rawText: string; data: unknown; } | { type: "failure"; attempts: number; replay: ContractReplay; }; export type ContractIssue = { path: string; message: string; code?: string; }; export type ContractReplay = { prompt: string; attempts: ContractReplayAttempt[]; createdAt: string; }; export type ContractReplayAttempt = { attempt: number; prompt: string; rawText?: string; parsed?: unknown; error?: string; issues?: ContractIssue[]; }; export type ContractSchema = { parse(value: unknown): T; }; export type ContractModel = { generate(prompt: string, context: ContractModelContext): Promise; }; export type ContractModelContext = { attempt: number; signal?: AbortSignal; previous?: ContractReplayAttempt; }; export type ContractModelResponse = | string | { text: string; metadata?: Record; }; export type ContractOptions = { model: ContractModel; schema: ContractSchema; prompt: string; retries?: number; signal?: AbortSignal; onEvent?: (event: ContractEvent) => void; repairPrompt?: (input: RepairPromptInput) => string; }; export type RepairPromptInput = { originalPrompt: string; lastAttempt: ContractReplayAttempt; issues: ContractIssue[]; }; export type ContractResult = { data: T; attempts: number; rawText: string; replay: ContractReplay; };