import type { RegenState, PendingEpochCommit } from "../types.js"; export type { RegenState, PendingEpochCommit } from "../types.js"; import type { OrchestrationInput, SerializableSessionConfig, SessionContextUsage, SubAgentEntry, TurnAction } from "../types.js"; export interface ActiveTimer { deadlineMs: number; originalDurationMs: number; reason: string; type: "wait" | "cron" | "cron_at" | "idle" | "agent-poll" | "input-grace"; shouldRehydrate?: boolean; waitPlan?: { shouldDehydrate: boolean; resetAffinityOnDehydrate: boolean; preserveAffinityOnHydrate: boolean; }; content?: string; question?: string; choices?: string[]; allowFreeform?: boolean; agentIds?: string[]; } export type ShutdownMode = NonNullable["mode"]; export type PendingShutdownState = NonNullable; export type PendingChildDigest = NonNullable; export type PendingInputQuestion = NonNullable; export type CronSchedule = NonNullable; export type CronAtSchedule = NonNullable; export interface InterruptedWaitTimer { remainingSec: number; reason: string; shouldRehydrate: boolean; waitPlan?: ActiveTimer["waitPlan"]; interruptKind?: "child" | "user"; } export interface InterruptedCronTimer { remainingMs: number; reason: string; originalDurationMs?: number; shouldRehydrate?: boolean; } /** Mutable orchestration state — replaces the closure of `let`s in the prior monolith. */ export interface DurableSessionState { config: SerializableSessionConfig; affinityKey: string; iteration: number; loopIteration: number; retryCount: number; needsHydration: boolean; /** * Session lifecycle protocol: last committed snapshot-store version, * recorded from each runTurn result. 0 = no commit recorded yet. * Threaded through continue-as-new; the next turn's activity input * carries it as `snapshot.expectedVersion` for worker self-validation. */ snapshotVersion: number; preserveAffinityOnHydrate: boolean; blobEnabled: boolean; pendingRehydrationMessage?: string; pendingPrompt?: string; /** Attachment refs for the carried pendingPrompt — dropped silently before 1.0.65's carry fix. */ pendingAttachments?: import("../types.js").PromptAttachmentRef[]; pendingRequiredTool?: string; pendingSystemPrompt?: string; runtimeModelNotice?: string; blockedError?: { message: string; authFailure?: boolean; }; pendingCycleOrigin?: "cron" | "cron_at"; bootstrapPrompt: boolean; pendingToolActions: TurnAction[]; subAgents: SubAgentEntry[]; /** Child-side: first completion report already sent to the parent. */ reportedFirstCompletionToParent: boolean; taskContext?: string; cronSchedule?: CronSchedule; cronAtSchedule?: CronAtSchedule; nextSummarizeAt: number; contextUsage?: SessionContextUsage; activeTimer: ActiveTimer | null; pendingInputQuestion: PendingInputQuestion | null; waitingForAgentIds: string[] | null; interruptedWaitTimer: InterruptedWaitTimer | null; interruptedCronTimer: InterruptedCronTimer | null; pendingChildDigest: PendingChildDigest | null; pendingShutdown: PendingShutdownState | null; lastResponseVersion: number; lastCommandVersion: number; lastCommandId?: string; cancelledMessageIds: Set; emittedCancelledMessageIds: Set; recentClientMessageIds: string[]; legacyPendingMessage: unknown; orchestrationResult: string | null; observedSenderKeys: string[]; /** True once a non-owner sender (or a second distinct sender) appears. */ multiWriter: boolean; /** Whether the [SHARED SESSION] preamble has been issued to the agent. */ sharedPreambleSent: boolean; /** Owner display name learned from an owner-relation sender. */ ownerDisplay?: string; /** * Which incarnation of the SDK transcript is live. 0 = original. * Carried across every continue-as-new; incremented only by the * regenerate flip. The turn index is NEVER reset (stopTurn queues, * turn metrics, cascade ids all rely on its monotonicity). */ transcriptEpoch: number; /** * One-shot: the next turn is the first of a fresh epoch and dispatches * as the runTurn2 activity (conditional epoch init). Cleared once that * turn's result is recorded. */ epochStartPending: boolean; /** In-flight regeneration pipeline (cleared at the flip and on abort). */ regen: RegenState | null; /** iteration at the current epoch's start (min-age gate baseline). */ epochStartIteration: number; /** Epoch-ms of the last completed flip (agent cooldown baseline). */ lastRegenAtMs: number; /** * Post-flip boundary record: set by the flip CAN, consumed by the new * execution's first drain, which emits session.epoch_committed + sets * sessions.transcript_epoch in one CMS transaction, then clears this. */ pendingEpochCommit: PendingEpochCommit | null; } /** Immutable per-execution configuration derived from the orchestration input. */ export interface DurableSessionOptions { idleTimeout: number; inputGracePeriod: number; isSystem: boolean; parentSessionId?: string; nestingLevel: number; baseSystemMessage?: string | { mode: "append" | "replace"; content: string; }; } /** Single object passed through every orchestration helper. */ export interface DurableSessionRuntime { ctx: any; input: OrchestrationInput; versions: { currentVersion: string; latestVersion: string; }; manager: any; /** Mutable: reassigned when affinity rotates on hydrate/dehydrate. */ session: any; state: DurableSessionState; options: DurableSessionOptions; } export declare const INTERNAL_SYSTEM_TURN_PROMPT = "Internal orchestration wake-up. The user did not send a new message. Continue with the latest system instructions."; export declare const MAX_RETRIES = 3; export declare const MAX_SUB_AGENTS = 50; export declare const MAX_NESTING_LEVEL = 2; export declare const CHILD_UPDATE_BATCH_MS = 30000; export declare const SHUTDOWN_TIMEOUT_MS = 60000; export declare const SHUTDOWN_POLL_INTERVAL_MS = 5000; export declare const FIRST_SUMMARIZE_DELAY = 60000; export declare const REPEAT_SUMMARIZE_DELAY = 300000; export declare const FIFO_BUCKET_COUNT = 20; export declare const MAX_BUCKET_BYTES: number; export declare const MAX_DRAIN_PER_TURN = 50; export declare const MAX_PREDISPATCH_SWEEP = 50; export declare const MAX_ITERATIONS_PER_EXECUTION = 10; export declare const MAX_HISTORY_SIZE_BEFORE_CONTINUE_AS_NEW_BYTES: number; export declare const HISTORY_SIZE_CHECK_INTERVAL_ITERATIONS = 3; export declare const NON_BLOCKING_TIMER_MS = 10; export declare const PREDISPATCH_CANCEL_SWEEP_MS = 100; export declare const RECENT_CLIENT_MESSAGE_ID_LIMIT = 20; export declare function normalizeRecentClientMessageIds(value: unknown): string[]; export declare function touchRecentClientMessageIds(state: DurableSessionState, ids: string[]): void; export declare function createInitialState(input: OrchestrationInput, options: DurableSessionOptions): DurableSessionState; export declare function deriveOptions(input: OrchestrationInput): DurableSessionOptions; //# sourceMappingURL=state.d.ts.map