import { type ActionId, type ApprovalGrantScope, type ApprovalRequest, type ArtifactObligation, type AssetId, type AskUserAnswers, type AskUserQuestion, type CapabilityRequest, type ClosurePolicy, type FailureRecoverability, type FailureScope, type ItemId, type PhaseResultEnvelope, type PhaseResultPhaseName, type PlanProjection, type ProviderConfig, type ProviderDecisionTransport, type ProviderKind, type ProviderReplayConfig, type ProviderTurnActionPolicy, type RunPhaseName, type SessionUsageOperation, type ThreadEvidenceRecord, type ThreadId, type ThreadMetadata, type ThreadMode, type ToolEffect, type ToolExecutionClass, type ToolFailureKind, type ToolInputValue, type ToolReplayPolicy, type ToolResultEnvelope, type ToolResultItem, type ToolResultOutcome, type TurnId } from "@best-agent/protocol";
import type { RunCheckpoint } from "../core/thread-store.js";
import type { ConversationMessage, ModelProvider, ProviderCacheControl, ProviderDecideInput, ProviderToolOption } from "../provider/model-provider.js";
import type { RequiredToolConstraint } from "./provider-turn/tool-constraint-types.js";
export type PendingProviderToolCall = {
    providerToolName?: string;
    replayToolInputAssetId?: AssetId;
    replayToolInputDigest?: string;
    toolCallId: ItemId;
    toolInput: ToolInputValue;
    toolName: string;
};
export type CompletedProviderToolCall = PendingProviderToolCall & {
    errorCode?: string;
    failureKind?: ToolFailureKind;
    /** @deprecated use inputStableDigest. */
    inputDigest?: string;
    inputStableDigest?: string;
    outcome: ToolResultOutcome;
    replayPolicy?: ToolReplayPolicy;
    toolOutput: string;
};
export type AdvancedPhaseLoopState = {
    closurePolicy: ClosurePolicy;
    hostProfileName: string;
    summaryProfileName: string;
    threadMode: ThreadMode;
};
export type RuntimeToolResumeContext = {
    activeSkillIds: string[];
    allowPhaseResult?: boolean;
    allowPlanUpdate?: boolean;
    advancedPhase?: AdvancedPhaseLoopState;
    artifactObligations?: ArtifactObligation[];
    approvalTurnId?: TurnId;
    availableTools: ProviderToolOption[];
    cacheControl?: ProviderCacheControl;
    completedToolCalls?: CompletedProviderToolCall[];
    customLoopId?: string;
    decisionTransport?: ProviderDecisionTransport;
    fixedRouteConfigOverride?: boolean;
    messages: ConversationMessage[];
    mode: "provider-tool-loop" | "tool-plan" | "custom-loop";
    objective?: string;
    pendingToolCalls?: PendingProviderToolCall[];
    phaseName?: RunPhaseName;
    phaseResultPhaseName?: PhaseResultPhaseName;
    profileName: string;
    providerTurnBudgeted?: boolean;
    providerTurnCount?: number;
    routeConfigOverride?: ProviderConfig;
    repairAttempt?: number;
    executionFailureCount?: number;
    requiredToolConstraint?: RequiredToolConstraint;
    systemPrompt?: string;
    toolCallId: ItemId;
    toolInput: ToolInputValue;
    toolName: string;
    providerToolName?: string;
    toolStepCount: number;
    reasoning?: string;
};
export type ToolResumeContext = RuntimeToolResumeContext;
export type PersistedProviderToolOption = Omit<ProviderToolOption, "effect"> & {
    effect?: ToolEffect;
};
export type PersistedProviderDecideCheckpointRequest = Omit<ProviderDecideCheckpointRequest, "tools"> & {
    tools: PersistedProviderToolOption[];
};
export type PersistedToolResumeContext = Omit<RuntimeToolResumeContext, "availableTools" | "routeConfigOverride"> & {
    activeReplayToolInputAssetId?: AssetId;
    activeReplayToolInputDigest?: string;
    availableTools: PersistedProviderToolOption[];
    routeConfigOverride?: ProviderReplayConfig;
};
export type ApprovalResolution = {
    decision: "allow" | "reject" | "expired";
    scope: ApprovalGrantScope;
};
export type ApprovalGrantActionSource = "legacy" | "raw-request-digest";
export type ActionResolution = {
    answers: AskUserAnswers;
    status: "answered";
} | {
    status: "expired";
};
export type ApprovalCheckpointPayload = PersistedToolResumeContext & {
    approval: ApprovalRequest;
    approvalGrantAction?: string;
    approvalGrantActionSource?: ApprovalGrantActionSource;
    kind: "approval";
    request: CapabilityRequest;
    resolution?: ApprovalResolution;
};
export type ActionCheckpointPayload = PersistedToolResumeContext & {
    actionId: ActionId;
    kind: "action";
    questions: AskUserQuestion[];
    resolution?: ActionResolution;
};
export type ToolOutputCheckpointPayload = PersistedToolResumeContext & {
    evidenceRecords?: ThreadEvidenceRecord[];
    kind: "tool-output";
    toolEnvelope?: ToolResultEnvelope;
    toolInputStableDigest?: string;
    toolOutput: string;
    toolResultItem?: ToolResultItem;
};
export type ToolDispatchCheckpointPayload = PersistedToolResumeContext & {
    executionClass: ToolExecutionClass;
    idempotent: boolean;
    kind: "tool-dispatch";
    replayPolicy?: ToolReplayPolicy;
    toolInputStableDigest?: string;
};
export type SubagentSpawnCheckpointPayload = {
    childThreadId?: ThreadId;
    kind: "subagent-spawn";
};
export type SubagentJoinCheckpointPayload = {
    childThreadIds: ThreadId[];
    kind: "subagent-join";
};
export type ResponseOutputCheckpointPayload = {
    activeSkillIds: string[];
    agentText: string;
    kind: "response-output";
    planProjection?: PlanProjection;
    reasoningSummary?: string;
    reasoningText?: string;
};
export type VerificationVerdictCheckpointPayload = {
    activeSkillIds: string[];
    advancedPhase: AdvancedPhaseLoopState;
    evidenceId?: string;
    kind: "verification-verdict";
    phaseOutput: string;
    phaseResult?: PhaseResultEnvelope;
    sourceItemId: ItemId;
    verdictId: string;
};
export type PhaseTransitionCheckpointPayload = {
    activeSkillIds: string[];
    kind: "phase-transition";
    nextPhaseName: RunPhaseName;
    reopened?: boolean;
    state: AdvancedPhaseLoopState;
    transitionMessage?: string;
};
export type PendingCompactionFollowUpMarker = {
    id: string;
    operation: SessionUsageOperation;
};
export type ProviderCorrectionTrace = {
    code: "PROVIDER_NO_ACTION" | "PROVIDER_DECISION_INVALID" | "TERMINAL_OUTPUT_INVALID" | "PROMPT_DELIVERABLE_MISSING";
    id: string;
    error?: {
        errorCode: string;
        message: string;
        recoverability: FailureRecoverability;
        scope: FailureScope;
    };
};
export type ProviderRequestReplayContext = {
    activeSkillIds?: string[];
    advancedPhase?: AdvancedPhaseLoopState;
    availableTools?: PersistedProviderToolOption[];
    compactionFollowUpMarker?: PendingCompactionFollowUpMarker;
    downgradeEligible?: boolean;
    escalationLevel?: number;
    objective?: string;
    payloadDecisionTransport?: ProviderDecisionTransport;
    phaseName?: RunPhaseName;
    profileName?: string;
    providerTurnBudgeted?: boolean;
    providerTurnCount?: number;
    correctionTrace?: ProviderCorrectionTrace;
    requiredToolConstraint?: RequiredToolConstraint;
    routeConfigOverride?: ProviderReplayConfig;
    toolStepCount?: number;
};
export type ProviderDecideCheckpointRequest = Omit<ProviderDecideInput, "actionPolicy" | "stream" | "toolNameBindings"> & {
    actionPolicy?: ProviderTurnActionPolicy;
};
export type ProviderGenerateCheckpointRequest = Omit<Parameters<ModelProvider["generate"]>[0], "stream" | "toolNameBindings">;
export type ProviderRequestCheckpointPayload = {
    artifactObligations?: ArtifactObligation[];
    decisionTransport?: ProviderDecisionTransport;
    kind: "provider-request";
    model?: string;
    operation: SessionUsageOperation;
    providerConfig?: ProviderReplayConfig;
    providerKind?: ProviderKind;
    replayContext?: ProviderRequestReplayContext;
    correctionTrace?: ProviderCorrectionTrace;
    request?: PersistedProviderDecideCheckpointRequest | ProviderGenerateCheckpointRequest;
    requestKind?: "decide" | "generate";
};
export type ToolResumeCheckpointPayload = ApprovalCheckpointPayload | ActionCheckpointPayload | ToolOutputCheckpointPayload;
type RunCheckpointKind = RunCheckpoint["kind"];
export declare function serializeApprovalCheckpointPayload(payload: ApprovalCheckpointPayload): ThreadMetadata;
export declare function serializeActionCheckpointPayload(payload: ActionCheckpointPayload): ThreadMetadata;
export declare function serializeToolOutputCheckpointPayload(payload: ToolOutputCheckpointPayload): ThreadMetadata;
export declare function serializeToolDispatchCheckpointPayload(payload: ToolDispatchCheckpointPayload): ThreadMetadata;
export declare function serializeSubagentSpawnCheckpointPayload(payload: SubagentSpawnCheckpointPayload): ThreadMetadata;
export declare function serializeSubagentJoinCheckpointPayload(payload: SubagentJoinCheckpointPayload): ThreadMetadata;
export declare function serializeResponseOutputCheckpointPayload(payload: ResponseOutputCheckpointPayload): ThreadMetadata;
export declare function serializeVerificationVerdictCheckpointPayload(payload: VerificationVerdictCheckpointPayload): ThreadMetadata;
export declare function serializePhaseTransitionCheckpointPayload(payload: PhaseTransitionCheckpointPayload): ThreadMetadata;
export declare function serializeProviderRequestCheckpointPayload(payload: ProviderRequestCheckpointPayload): ThreadMetadata;
export declare function parseApprovalCheckpointPayload(checkpoint: RunCheckpoint): ApprovalCheckpointPayload;
export declare function parseActionCheckpointPayload(checkpoint: RunCheckpoint): ActionCheckpointPayload;
export declare function parseToolOutputCheckpointPayload(checkpoint: RunCheckpoint): ToolOutputCheckpointPayload;
export declare function parseToolDispatchCheckpointPayload(checkpoint: RunCheckpoint): ToolDispatchCheckpointPayload;
export declare function parseSubagentSpawnCheckpointPayload(checkpoint: RunCheckpoint): SubagentSpawnCheckpointPayload;
export declare function parseSubagentJoinCheckpointPayload(checkpoint: RunCheckpoint): SubagentJoinCheckpointPayload;
export declare function parseResponseOutputCheckpointPayload(checkpoint: RunCheckpoint): ResponseOutputCheckpointPayload;
export declare function parseVerificationVerdictCheckpointPayload(checkpoint: RunCheckpoint): VerificationVerdictCheckpointPayload;
export declare function parsePhaseTransitionCheckpointPayload(checkpoint: RunCheckpoint): PhaseTransitionCheckpointPayload;
export declare function parseProviderRequestCheckpointPayload(checkpoint: RunCheckpoint): ProviderRequestCheckpointPayload;
export declare function parseToolResumeCheckpointPayload(checkpoint: RunCheckpoint): ToolResumeCheckpointPayload;
export declare function canRunCheckpointSupersede(pendingKind: RunCheckpointKind, nextKind: RunCheckpointKind): boolean;
export {};
//# sourceMappingURL=checkpoint-codec.d.ts.map