import { z } from 'zod'; import type { WorkingStateSnapshot } from '../../compaction/wire.js'; import type { SerializedSpanContext } from '../../telemetry/attributes.js'; import type { CostInfo, TokenUsage } from '../common/index.js'; import type { CheckpointId, MessageId, SessionId, TurnId } from '../ids/index.js'; import type { TurnBudgetBinding } from './turn.js'; /** Version of the checkpoint document. An older or unknown version is refused, never migrated. */ export declare const CHECKPOINT_DOCUMENT_VERSION: 1; /** * A checkpoint of one turn, stored at `/checkpoints/.json`. * * It holds NO messages. The context it restores is the fold of the session * log from seq 1 through `throughSeq`, which equals the session's context at * that seq because no other turn can interleave. `throughSha256` is the hash * of the record at `throughSeq`, and the `checkpoint_written` record carries * the document's own hash (`docSha256`): a restore refuses the checkpoint when * either does not match. */ export interface Checkpoint { readonly v: typeof CHECKPOINT_DOCUMENT_VERSION; readonly kind: 'checkpoint'; readonly checkpointId: CheckpointId; readonly sessionId: SessionId; readonly turnId: TurnId; readonly iteration: number; readonly throughSeq: number; readonly throughSha256: string; readonly tokenUsage: TokenUsage; readonly costInfo: CostInfo; /** The ledger reference; the ledger itself stays authoritative. */ readonly budget?: { readonly binding?: TurnBudgetBinding; /** Present for non-durable accounts too; those need the live authority on resume. */ readonly accountId: string; }; readonly guards: { readonly iteration: number; readonly elapsedMs: number; }; /** * Review corrections already consumed at this checkpoint, independent of * compactable history: host structured-output review, prose-answer review * and native structured-output correction. */ readonly review: { readonly structuredAttempts: number; readonly answerAttempts: number; readonly nativeStructuredAttempts: number; }; /** The turn's current operator/goal/steering message, independent of compaction. */ readonly latestUserMessageId?: MessageId; /** Compaction's accumulated working state, when compaction is enabled. */ readonly workingState?: WorkingStateSnapshot; /** The trace the checkpoint was taken inside, so a resume continues it. */ readonly trace?: SerializedSpanContext; /** When the turn was attributed (ISO-8601). Identical on every checkpoint of the turn. */ readonly turnCreatedAt: string; /** When this checkpoint was written (ISO-8601). */ readonly createdAt: string; } export declare const TokenUsageSchema: z.ZodObject<{ promptTokens: z.ZodNumber; completionTokens: z.ZodNumber; totalTokens: z.ZodNumber; cachedTokens: z.ZodNumber; cacheWriteTokens: z.ZodNumber; reasoningTokens: z.ZodOptional; }, "strict", z.ZodTypeAny, { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }, { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }>; export declare const CostInfoSchema: z.ZodObject<{ inputCostPer1M: z.ZodOptional; outputCostPer1M: z.ZodOptional; totalCost: z.ZodNumber; cacheDiscount: z.ZodNumber; unpricedTokens: z.ZodNumber; }, "strict", z.ZodTypeAny, { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }, { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }>; export declare const TurnBudgetBindingSchema: z.ZodObject<{ rootSessionId: z.ZodType; rootTurnId: z.ZodType; accountId: z.ZodString; }, "strict", z.ZodTypeAny, { rootSessionId: string & import("../ids/brand.js").IdBrand<"SessionId">; rootTurnId: string & import("../ids/brand.js").IdBrand<"TurnId">; accountId: string; }, { accountId: string; rootSessionId?: unknown; rootTurnId?: unknown; }>; export declare const CheckpointSchema: z.ZodObject<{ v: z.ZodLiteral<1>; kind: z.ZodLiteral<"checkpoint">; checkpointId: z.ZodType; sessionId: z.ZodType; turnId: z.ZodType; iteration: z.ZodNumber; throughSeq: z.ZodNumber; throughSha256: z.ZodString; tokenUsage: z.ZodObject<{ promptTokens: z.ZodNumber; completionTokens: z.ZodNumber; totalTokens: z.ZodNumber; cachedTokens: z.ZodNumber; cacheWriteTokens: z.ZodNumber; reasoningTokens: z.ZodOptional; }, "strict", z.ZodTypeAny, { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }, { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }>; costInfo: z.ZodObject<{ inputCostPer1M: z.ZodOptional; outputCostPer1M: z.ZodOptional; totalCost: z.ZodNumber; cacheDiscount: z.ZodNumber; unpricedTokens: z.ZodNumber; }, "strict", z.ZodTypeAny, { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }, { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }>; budget: z.ZodOptional; rootTurnId: z.ZodType; accountId: z.ZodString; }, "strict", z.ZodTypeAny, { rootSessionId: string & import("../ids/brand.js").IdBrand<"SessionId">; rootTurnId: string & import("../ids/brand.js").IdBrand<"TurnId">; accountId: string; }, { accountId: string; rootSessionId?: unknown; rootTurnId?: unknown; }>>; accountId: z.ZodString; }, "strict", z.ZodTypeAny, { accountId: string; binding?: { rootSessionId: string & import("../ids/brand.js").IdBrand<"SessionId">; rootTurnId: string & import("../ids/brand.js").IdBrand<"TurnId">; accountId: string; } | undefined; }, { accountId: string; binding?: { accountId: string; rootSessionId?: unknown; rootTurnId?: unknown; } | undefined; }>>; guards: z.ZodObject<{ iteration: z.ZodNumber; elapsedMs: z.ZodNumber; }, "strict", z.ZodTypeAny, { iteration: number; elapsedMs: number; }, { iteration: number; elapsedMs: number; }>; review: z.ZodObject<{ structuredAttempts: z.ZodNumber; answerAttempts: z.ZodNumber; nativeStructuredAttempts: z.ZodNumber; }, "strict", z.ZodTypeAny, { structuredAttempts: number; answerAttempts: number; nativeStructuredAttempts: number; }, { structuredAttempts: number; answerAttempts: number; nativeStructuredAttempts: number; }>; latestUserMessageId: z.ZodOptional>; workingState: z.ZodOptional>; trace: z.ZodOptional>; turnCreatedAt: z.ZodString; createdAt: z.ZodString; }, "strict", z.ZodTypeAny, { kind: "checkpoint"; v: 1; sessionId: string & import("../ids/brand.js").IdBrand<"SessionId">; turnId: string & import("../ids/brand.js").IdBrand<"TurnId">; review: { structuredAttempts: number; answerAttempts: number; nativeStructuredAttempts: number; }; checkpointId: string & import("../ids/brand.js").IdBrand<"CheckpointId">; iteration: number; throughSeq: number; throughSha256: string; tokenUsage: { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }; costInfo: { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }; guards: { iteration: number; elapsedMs: number; }; turnCreatedAt: string; createdAt: string; budget?: { accountId: string; binding?: { rootSessionId: string & import("../ids/brand.js").IdBrand<"SessionId">; rootTurnId: string & import("../ids/brand.js").IdBrand<"TurnId">; accountId: string; } | undefined; } | undefined; latestUserMessageId?: MessageId | undefined; workingState?: WorkingStateSnapshot | undefined; trace?: SerializedSpanContext | undefined; }, { kind: "checkpoint"; v: 1; review: { structuredAttempts: number; answerAttempts: number; nativeStructuredAttempts: number; }; iteration: number; throughSeq: number; throughSha256: string; tokenUsage: { promptTokens: number; completionTokens: number; totalTokens: number; cachedTokens: number; cacheWriteTokens: number; reasoningTokens?: number | undefined; }; costInfo: { totalCost: number; cacheDiscount: number; unpricedTokens: number; inputCostPer1M?: number | undefined; outputCostPer1M?: number | undefined; }; guards: { iteration: number; elapsedMs: number; }; turnCreatedAt: string; createdAt: string; sessionId?: unknown; turnId?: unknown; checkpointId?: unknown; budget?: { accountId: string; binding?: { accountId: string; rootSessionId?: unknown; rootTurnId?: unknown; } | undefined; } | undefined; latestUserMessageId?: unknown; workingState?: WorkingStateSnapshot | undefined; trace?: SerializedSpanContext | undefined; }>; /** Raised for a checkpoint document written by another version or another shape. */ export declare class CheckpointDocumentError extends Error { readonly name = "CheckpointDocumentError"; } /** * Parse a checkpoint document. A document from the run-era layout * (`kind: 'run-checkpoint'`) or any other version is refused by name. */ export declare function parseCheckpoint(value: unknown): Checkpoint; //# sourceMappingURL=checkpoint.d.ts.map