import type { AgentExecutionRefs, AgentExecutionSource, AgentAttemptSource, AgentSidechainType, AgentSidechainRole, AgentSidechainMergePolicy, AgentExecutionSessionStatus, ProxyKeySource, ProxyQuotaSource, TransportResponsePayload, TransportUsageInfo, TransportBillingInfo, ControlApprovalDecision, ControlApprovalSource, ExecutionInterruptReason, ExecutionResumeSource, ExecutionCancelReason } from "./transport.js";
import type { ModelSelectionReason } from "./session.js";
import type { TransportCapabilitySummaryContract, TransportApprovalRequiredToolHintEntry, TransportToolEligibilitySummaryEntry, ToolExecutionStepContext } from "./capability-transport.js";
export interface AgentExecutionRouteInfo {
    requestedModel?: string;
    resolvedModel?: string;
    modelSelectionReason?: ModelSelectionReason;
    aliasId?: string;
    provider?: string;
    model?: string;
    tier?: string;
    keySource?: ProxyKeySource;
    quotaSource?: ProxyQuotaSource;
}
export interface AgentExecutionStartedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    source: AgentExecutionSource;
    capabilitySnapshotVersion?: string;
    capabilitySummary?: TransportCapabilitySummaryContract;
    approvalRequiredToolHint?: TransportApprovalRequiredToolHintEntry[];
    eligibleToolSummary?: TransportToolEligibilitySummaryEntry[];
    ineligibleToolSummary?: TransportToolEligibilitySummaryEntry[];
}
export interface AgentExecutionStartedMsg {
    type: "agent.execution.started";
    id: string;
    payload: AgentExecutionStartedPayload;
}
export interface AgentExecutionCompletedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    outcomeId: string;
    finalAttemptId?: string;
    resolvedModel?: string;
    modelSelectionReason?: ModelSelectionReason;
    routeExplainSummary?: string;
    response?: TransportResponsePayload;
    usage?: TransportUsageInfo;
    billed?: TransportBillingInfo | null;
}
export interface AgentExecutionCompletedMsg {
    type: "agent.execution.completed";
    id: string;
    payload: AgentExecutionCompletedPayload;
}
export interface AgentExecutionFailedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    outcomeId: string;
    failedAttemptId?: string;
    code: string;
    error: string;
    retryable: boolean;
    terminal?: boolean;
}
export interface AgentExecutionFailedMsg {
    type: "agent.execution.failed";
    id: string;
    payload: AgentExecutionFailedPayload;
}
export interface AgentAttemptStartedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    attemptId: string;
    attemptIndex: number;
    source: AgentAttemptSource;
    route?: AgentExecutionRouteInfo;
}
export interface AgentAttemptStartedMsg {
    type: "agent.attempt.started";
    id: string;
    payload: AgentAttemptStartedPayload;
}
export interface AgentAttemptCompletedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    attemptId: string;
    outcomeId: string;
    response?: TransportResponsePayload;
    usage?: TransportUsageInfo;
    route?: AgentExecutionRouteInfo;
}
export interface AgentAttemptCompletedMsg {
    type: "agent.attempt.completed";
    id: string;
    payload: AgentAttemptCompletedPayload;
}
export interface AgentAttemptFailedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    attemptId: string;
    outcomeId: string;
    route?: AgentExecutionRouteInfo;
    code: string;
    error: string;
    retryable: boolean;
}
export interface AgentAttemptFailedMsg {
    type: "agent.attempt.failed";
    id: string;
    payload: AgentAttemptFailedPayload;
}
export type AgentSidechainToolAccessDecision = "allowed" | "denied";
export type AgentSidechainToolAccessInheritance = "inherit" | "shrink";
export type AgentSidechainToolAccessReason = "default-allow" | "always-deny" | "leaf-deny";
export interface AgentSidechainToolAccessRule {
    toolName: string;
    decision: AgentSidechainToolAccessDecision;
    inheritance: AgentSidechainToolAccessInheritance;
    reason: AgentSidechainToolAccessReason;
}
export interface AgentSidechainToolAccess {
    deniedTools: string[];
    canSpawnChildren: boolean;
    defaultDecision: "allowed";
    defaultInheritance: "inherit";
    tools: AgentSidechainToolAccessRule[];
}
export interface AgentSidechainStartedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    parentExecutionId: string;
    sidechainId: string;
    sidechainType: AgentSidechainType;
    role: AgentSidechainRole;
    toolAccess?: AgentSidechainToolAccess;
    mergePolicy?: AgentSidechainMergePolicy;
    trigger?: "planner" | "tool-result" | "repair-policy" | "user-followup";
}
export interface AgentSidechainStartedMsg {
    type: "agent.sidechain.started";
    id: string;
    payload: AgentSidechainStartedPayload;
}
export interface AgentSidechainCompletedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    parentExecutionId: string;
    sidechainId: string;
    outcomeId: string;
    summary?: string;
    usage?: TransportUsageInfo;
}
export interface AgentSidechainCompletedMsg {
    type: "agent.sidechain.completed";
    id: string;
    payload: AgentSidechainCompletedPayload;
}
export interface AgentSidechainFailedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    parentExecutionId: string;
    sidechainId: string;
    outcomeId: string;
    code: string;
    error: string;
    retryable: boolean;
}
export interface AgentSidechainFailedMsg {
    type: "agent.sidechain.failed";
    id: string;
    payload: AgentSidechainFailedPayload;
}
export interface AgentSidechainCancelRequestPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    sidechainId: string;
    requestedAtMs: number;
    reason?: string;
}
export interface AgentSidechainCancelRequestMsg {
    type: "agent.sidechain.cancel.request";
    id: string;
    payload: AgentSidechainCancelRequestPayload;
}
export interface AgentSidechainCancelAckPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    sidechainId: string;
    accepted: boolean;
    cancelledAtMs: number;
    reason?: string;
}
export interface AgentSidechainCancelAckMsg {
    type: "agent.sidechain.cancel.ack";
    id: string;
    payload: AgentSidechainCancelAckPayload;
}
export interface ControlApprovalRequestedPayload extends AgentExecutionRefs, ToolExecutionStepContext {
    sessionId: string;
    turnId: string;
    executionId: string;
    approvalId: string;
    callId?: string;
    toolName?: string;
    reason?: string;
    createdAtMs: number;
    expiresAtMs: number;
    policyScope?: "tool" | "workspace" | "session";
}
export interface ControlApprovalRequestedMsg {
    type: "control.approval.requested";
    id: string;
    payload: ControlApprovalRequestedPayload;
}
export interface ControlApprovalRespondedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    approvalId: string;
    callId?: string;
    decision: ControlApprovalDecision;
    source: ControlApprovalSource;
    respondedAtMs: number;
    note?: string;
}
export interface ControlApprovalRespondedMsg {
    type: "control.approval.responded";
    id: string;
    payload: ControlApprovalRespondedPayload;
}
export interface ExecutionInterruptedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    reason: ExecutionInterruptReason;
    interruptedAtMs: number;
    resumable: boolean;
    callId?: string;
    approvalId?: string;
}
export interface ExecutionInterruptedMsg {
    type: "execution.interrupted";
    id: string;
    payload: ExecutionInterruptedPayload;
}
export interface ExecutionResumedPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    source: ExecutionResumeSource;
    resumedAtMs: number;
    fromEventId?: string;
}
export interface ExecutionResumedMsg {
    type: "execution.resumed";
    id: string;
    payload: ExecutionResumedPayload;
}
export interface ExecutionCancelledPayload extends AgentExecutionRefs {
    sessionId: string;
    turnId: string;
    executionId: string;
    reason: ExecutionCancelReason;
    cancelledAtMs: number;
    callId?: string;
    approvalId?: string;
}
export interface ExecutionCancelledMsg {
    type: "execution.cancelled";
    id: string;
    payload: ExecutionCancelledPayload;
}
export interface AgentExecutionSessionSnapshot {
    requestId: string;
    resumeToken: string;
    createdAt: string;
    leaseExpiresAt: string;
    executionId: string | null;
    rootExecutionId: string | null;
    parentExecutionId?: string | null;
    sidechainId?: string | null;
    attemptId?: string | null;
    sessionId: string | null;
    turnId: string | null;
    status: AgentExecutionSessionStatus;
    lastEventAt: string | null;
    lastEventName: string | null;
    replayCursor: number;
    replayStartCursor: number;
    replayEventCount: number;
    ackCursor: number;
    activeStream: boolean;
}
export interface AgentRuntimeExecutionSessionListQuery {
    executionId?: string;
    rootExecutionId?: string;
    sessionId?: string;
    turnId?: string;
    resumeToken?: string;
    status?: AgentExecutionSessionStatus;
    activeStream?: boolean;
    limit?: number;
}
export interface AgentRuntimeExecutionSessionListPayload {
    items: AgentExecutionSessionSnapshot[];
}
export interface AgentExecutionSessionResumeParams {
    ackCursor?: number;
    timeoutMs?: number;
}
export interface AgentExecutionSessionResumeState {
    requestId: string;
    resumeToken: string;
    replayCursor: number;
    ackCursor: number;
}
export interface AgentSessionEndedPayload {
    sessionId: string;
    sessionKey?: string;
    messageCount: number;
    endedAtMs: number;
}
export interface AgentSessionEndedMsg {
    type: "agent.session.ended";
    id: string;
    payload: AgentSessionEndedPayload;
}
export interface CheckpointRestoreAckPayload {
    executionId: string;
    rootExecutionId?: string;
    parentExecutionId?: string;
    sidechainId?: string;
    attemptId?: string;
    runId: string;
    sessionId?: string;
    checkpointId: string;
    restoreId: string;
    requestedAtMs: number;
    ackedAtMs: number;
    accepted: boolean;
    reason?: string;
    workingDirectory?: string;
    pathHints?: string[];
}
export interface CheckpointRestoreAckMsg {
    type: "checkpoint.restore.ack";
    id: string;
    payload: CheckpointRestoreAckPayload;
}
export interface CheckpointRestoredPayload {
    executionId: string;
    rootExecutionId?: string;
    parentExecutionId?: string;
    sidechainId?: string;
    attemptId?: string;
    runId: string;
    sessionId?: string;
    checkpointId: string;
    restoreId: string;
    restoredAtMs: number;
    reason?: string;
    workingDirectory?: string;
    pathHints?: string[];
}
export interface CheckpointRestoredMsg {
    type: "checkpoint.restored";
    id: string;
    payload: CheckpointRestoredPayload;
}
export interface CheckpointRollbackResultPayload {
    executionId: string;
    rootExecutionId?: string;
    parentExecutionId?: string;
    sidechainId?: string;
    attemptId?: string;
    runId: string;
    sessionId?: string;
    checkpointId: string;
    restoreId: string;
    rollbackCheckpointId: string;
    completedAtMs: number;
    reason?: string;
}
export interface CheckpointRollbackResultMsg {
    type: "checkpoint.rollback.result";
    id: string;
    payload: CheckpointRollbackResultPayload;
}
