import type { IMastraLogger } from '../logger/index.js';
import type { RequestContext } from '../request-context/index.js';
import type { ExecutionGraph } from './execution-engine.js';
import type { Step } from './step.js';
import { getEntryId } from './step-entry.js';
import type { ForeachConcurrencyContext, ForeachOptions, RestartExecutionParams, SingleStepEntry, StepFlowEntry, TimeTravelContext, TimeTravelExecutionParams, WorkflowRunState } from './types.js';
export declare function validateStepInput({ prevOutput, step, validateInputs, }: {
    prevOutput: any;
    step: Partial<Pick<Step<string, any, any>, 'inputSchema'>>;
    validateInputs: boolean;
}): Promise<{
    inputData: any;
    validationError: Error | undefined;
}>;
export declare function validateStepResumeData({ resumeData, step, }: {
    resumeData?: any;
    step: Partial<Pick<Step<string, any, any>, 'resumeSchema'>>;
}): Promise<{
    resumeData: any;
    validationError: Error | undefined;
}>;
export declare function validateStepSuspendData({ suspendData, step, validateInputs, }: {
    suspendData?: any;
    step: Partial<Pick<Step<string, any, any>, 'suspendSchema'>>;
    validateInputs: boolean;
}): Promise<{
    suspendData: any;
    validationError: Error | undefined;
}>;
export declare function validateStepStateData({ stateData, step, validateInputs, }: {
    stateData?: any;
    step: Partial<Pick<Step<string, any, any>, 'stateSchema'>>;
    validateInputs: boolean;
}): Promise<{
    stateData: any;
    validationError: Error | undefined;
}>;
export declare function validateStepRequestContext({ requestContext, step, validateInputs, }: {
    requestContext?: RequestContext;
    step: Pick<Step<string, any, any>, 'id' | 'requestContextSchema'>;
    validateInputs: boolean;
}): Promise<{
    validationError: Error | undefined;
}>;
export declare function getResumeLabelsByStepId(resumeLabels: Record<string, {
    stepId: string;
    foreachIndex?: number;
}>, stepId: string): Record<string, {
    stepId: string;
    foreachIndex?: number;
}>;
/**
 * Calls `callback` once `duration` ms have passed and returns a function that cancels it.
 * Node and Bun fire a `setTimeout` delay above 2^31-1 ms after 1 ms, so a longer duration
 * is waited out in consecutive timers. A duration that is not positive (including NaN)
 * fires at once; `Infinity` never fires.
 * @internal
 */
export declare function setLongTimeout(callback: () => void, duration: number): () => void;
export declare function abortableSleep(duration: number, signal?: AbortSignal): Promise<void>;
export declare const runCountDeprecationMessage = "Warning: 'runCount' is deprecated and will be removed on November 4th, 2025. Please use 'retryCount' instead.";
/**
 * Creates a Proxy that wraps execute function parameters to show deprecation warnings
 * when accessing deprecated properties.
 *
 * Currently handles:
 * - `runCount`: Deprecated in favor of `retryCount`, will be removed on November 4th, 2025
 */
export declare function createDeprecationProxy<T extends Record<string, any>>(params: T, { paramName, deprecationMessage, logger, }: {
    paramName: string;
    deprecationMessage: string;
    logger: IMastraLogger;
}): T;
/**
 * Defines `writer` on execute params as a memoized getter so the stream is only
 * allocated when step code actually reads it. The property stays enumerable so
 * spreading the params still carries `writer` along.
 */
export declare function defineLazyWriter<T extends object, W>(params: T, createWriter: () => W): NoInfer<T> & {
    writer: NoInfer<W>;
};
/**
 * Defines `getState` on step params, resolving to `view()` or only its named top-level keys. On storage
 * v2 runs, reading `state` throws and points to `getState`, as sync `getStepResult` does. That getter
 * isn't enumerable, so spreading the params still works.
 */
export declare function defineStateAccessors<T extends object>(params: T, view: () => Record<string, any>, storageV2: boolean): NoInfer<T> & {
    getState: (keys?: readonly string[]) => Promise<Record<string, any>>;
};
/** Applies a storage v2 `setState` change set to `state`: a key set to `undefined` is deleted. */
export declare function applyStateDelta(state: Record<string, any>, delta: Record<string, unknown>): void;
/**
 * Whether an entry is a "single step-like" entry: a plain user step or one of the
 * declarative variants (agent / tool / classifier / mapping) that resolve to exactly one step.
 */
export declare function isSingleStepEntry(entry: StepFlowEntry): entry is SingleStepEntry;
/**
 * The id of a single step-like entry. Plain `step` entries key off the wrapped
 * step's id; declarative variants (agent / tool / mapping) carry their own `id`.
 *
 * Public alias of {@link getEntryId} from `./step-entry`.
 */
export declare const getSingleStepEntryId: typeof getEntryId;
export declare const getStepIds: (entry: StepFlowEntry) => string[];
/**
 * Verifies that the live execution graph is consistent with the recorded snapshot
 * before a time-travel reconstruction is built. Without this check, any step id that
 * exists in the live graph but not in the recorded snapshot context silently
 * reconstructs to `{}`, and the execution engine then persists that reconstruction
 * over the original snapshot — irreversibly corrupting it (see issue #21137).
 *
 * Divergence rules:
 * - The target step id must exist in the live graph (enumerated via {@link getStepIds}).
 * - Every step that precedes the target in the live graph must have an entry in the
 *   recorded snapshot context or the caller-supplied context, EXCEPT legitimate
 *   no-entry cases: unselected branch steps of a pre-target conditional entry (the
 *   entry is healthy when at least one of its branch steps was recorded), sleep /
 *   sleepUntil entries, and foreach / loop entries (which may record no per-step
 *   entry when they ran zero iterations).
 * - When the snapshot context records no step entries at all (only the reserved
 *   `input` key, or nothing), the guard is a no-op: there is no recorded data to
 *   protect, and the evented engine legitimately fabricates an empty snapshot
 *   context for nested time travel when no nested snapshot exists.
 */
export declare const assertTimeTravelGraphMatchesSnapshot: (params: {
    targetStepId: string;
    graph: ExecutionGraph;
    snapshot: WorkflowRunState;
    context?: Record<string, any>;
}) => void;
export declare const createTimeTravelExecutionParams: (params: {
    steps: string[];
    inputData?: any;
    resumeData?: any;
    context?: TimeTravelContext<any, any, any, any>;
    nestedStepsContext?: Record<string, TimeTravelContext<any, any, any, any>>;
    snapshot: WorkflowRunState;
    initialState?: any;
    graph: ExecutionGraph;
    perStep?: boolean;
}) => TimeTravelExecutionParams;
export declare const createRestartExecutionParams: ({ snapshot, graph, }: {
    snapshot: WorkflowRunState;
    graph: ExecutionGraph;
}) => RestartExecutionParams;
/**
 * Top-level index the default engine should restart from.
 *
 * The engine checkpoints an entry when it finishes but only moves the pointer
 * when the next entry starts. A checkpoint with nothing running whose
 * pointed-at entry saved only successful results was written in that gap, so
 * restart resumes at the next entry instead of replaying a finished one (#24615).
 * Any other checkpoint resumes at the entry it points to.
 *
 * Skips at most one entry, so a step id reused later in the graph is never
 * mistaken for finished.
 */
export declare function getRestartStartIndex(steps: StepFlowEntry[], restart: RestartExecutionParams): number;
/**
 * Whether a top-level entry saved only successful results, given its results
 * in `getStepIds` order. Agent-loop snapshot pruning makes the same decision to
 * keep the output a restart that skips the entry reads.
 */
export declare function isEntryFinished(entryType: string, results: ReadonlyArray<{
    status: string;
} | null | undefined>): boolean;
/**
 * Re-hydrates serialized errors in step results back into proper Error instances.
 * This is useful when errors have been serialized through an event system (e.g., evented engine, Inngest)
 * and need to be converted back to Error instances with their custom properties preserved.
 *
 * @param steps - The workflow step results (context) that may contain serialized errors
 * @returns The same steps object with errors hydrated as Error instances
 */
export declare function hydrateSerializedStepErrors(steps: WorkflowRunState['context']): {
    input?: Record<string, any>;
} & Record<string, import("./types").SerializedStepResult<any, any, any, any>>;
/**
 * Cleans step result data by removing internal properties at known structural levels.
 *
 * Removes:
 * - `__state` properties (internal workflow state for state propagation)
 * - `nestedRunId` from `metadata` objects (internal tracking for nested workflow retrieval)
 *
 * ## Why targeted cleaning instead of recursive?
 *
 * Internal properties only appear at specific, known locations:
 *
 * 1. **`__state`** - Added by step-executor.ts to every step result. For forEach,
 *    suspended iterations store the full result (including __state) while completed
 *    iterations only store the output value. See workflow-event-processor/index.ts:1227-1230.
 *
 * 2. **`metadata.nestedRunId`** - Added when nested workflows complete, stored at the
 *    step result level. For forEach with nested workflows, each iteration result can
 *    have this. See workflow-event-processor/index.ts:1449-1453.
 *
 * By only cleaning at the step result level and forEach iteration level, we avoid
 * accidentally stripping user data that happens to use `__state` as a property name
 * in their actual output values.
 *
 * @param stepResult - A step result object, or an array of iteration results (forEach)
 * @returns The cleaned step result with internal properties removed
 */
export declare function cleanStepResult(stepResult: unknown): unknown;
/**
 * Strips fields that describe a step's *previous* completion from a step-info
 * object before it is published on a watch event.
 *
 * Step-info objects spread the step's prior result (`...stepResults[step.id]`)
 * so persisted snapshots keep resume context (original `payload`, timestamps).
 * Watch events must not re-publish those completion blobs: on a loop, the
 * previous iteration's `output` is byte-identical to the next iteration's
 * `payload`, so every `workflow-step-start` would ship the state twice
 * (megabytes per event for durable agent runs). Result/suspended events get
 * their fresh completion fields from the current execution result instead.
 */
export declare function omitPriorSuspensionFields<T extends Record<string, unknown>>(stepInfo: T): Omit<T, 'suspendedAt' | 'suspendPayload' | 'suspendOutput'>;
export declare function omitPriorCompletionFields<T extends Record<string, unknown>>(stepInfo: T): Omit<T, 'output' | 'error' | 'endedAt' | 'suspendedAt' | 'suspendPayload' | 'suspendOutput' | 'tripwire' | 'nonRetryable'>;
/**
 * Resolves the effective concurrency for a foreach entry at execution time.
 *
 * Supports both a static number and a {@link ForeachConcurrencyResolver}
 * function that derives concurrency from the run's input. Invalid or
 * non-positive values fall back to 1 (sequential).
 */
export declare function resolveForeachConcurrency(opts: ForeachOptions | undefined, context: ForeachConcurrencyContext): number;
export declare const RESUME_SNAPSHOT_POLL_INTERVAL_MS = 25;
export declare const RESUME_SNAPSHOT_WAIT_STATUSES: Set<string>;
export declare function waitForSuspendedSnapshot(workflowsStore: {
    loadWorkflowSnapshot: (args: {
        workflowName: string;
        runId: string;
    }) => Promise<WorkflowRunState | null>;
} | undefined, workflowName: string, runId: string, { timeoutMs, missingSnapshotGraceReads, onClaimedRunFinished, }?: {
    timeoutMs?: number;
    missingSnapshotGraceReads?: number;
    /** Called when a `running`/`pending` row is seen and then disappears (its run finished and was cleaned up). */
    onClaimedRunFinished?: () => void;
}): Promise<WorkflowRunState | null>;
//# sourceMappingURL=utils.d.ts.map