import type { MastraDBMessage } from '../agent/message-list/state/types.js';
import type { AgentThreadSubscription } from '../agent/types.js';
import type { RequestContext } from '../request-context/index.js';
import type { Session, SessionMachinery } from './session.js';
type StreamChunkBase<TType extends string> = {
    type: TType;
    runId?: string | null;
    metadata?: unknown;
};
type StreamPayloadChunk<TType extends string> = StreamChunkBase<TType> & {
    payload?: unknown;
};
type StreamObjectChunk<TType extends string> = StreamChunkBase<TType> & {
    object?: unknown;
};
type StreamDataChunk<TType extends `data-${string}`> = StreamChunkBase<TType> & {
    data?: unknown;
};
type StreamIgnoredChunk = StreamPayloadChunk<'start'> | StreamPayloadChunk<'abort'> | StreamPayloadChunk<'response-metadata'> | StreamPayloadChunk<'text-end'> | StreamPayloadChunk<'reasoning-end'> | StreamPayloadChunk<'reasoning-signature'> | StreamPayloadChunk<'redacted-reasoning'> | StreamPayloadChunk<'source'> | StreamPayloadChunk<'file'> | StreamPayloadChunk<'raw'> | StreamPayloadChunk<'step-start'> | StreamPayloadChunk<'tool-output'> | StreamPayloadChunk<'step-output'> | StreamPayloadChunk<'watch'> | StreamPayloadChunk<'tripwire'> | StreamPayloadChunk<'is-task-complete'> | StreamPayloadChunk<'background-task-started'> | StreamPayloadChunk<'background-task-completed'> | StreamPayloadChunk<'background-task-failed'> | StreamPayloadChunk<'background-task-progress'> | StreamPayloadChunk<'background-task-running'> | StreamPayloadChunk<'background-task-cancelled'> | StreamPayloadChunk<'background-task-output'> | StreamPayloadChunk<'background-task-suspended'> | StreamPayloadChunk<'background-task-resumed'> | StreamObjectChunk<'object'> | StreamObjectChunk<'object-result'>;
type StreamChunk = StreamIgnoredChunk | StreamPayloadChunk<'text-start'> | StreamPayloadChunk<'text-delta'> | StreamPayloadChunk<'reasoning-start'> | StreamPayloadChunk<'reasoning-delta'> | StreamPayloadChunk<'tool-call-input-streaming-start'> | StreamPayloadChunk<'tool-call-delta'> | StreamPayloadChunk<'tool-call-input-streaming-end'> | StreamPayloadChunk<'tool-call'> | StreamPayloadChunk<'tool-result'> | StreamPayloadChunk<'tool-error'> | StreamPayloadChunk<'tool-call-approval'> | StreamPayloadChunk<'tool-call-suspended'> | StreamPayloadChunk<'error'> | StreamPayloadChunk<'step-finish'> | StreamPayloadChunk<'finish'> | StreamPayloadChunk<'goal'> | StreamDataChunk<'data-om-status'> | StreamDataChunk<'data-om-observation-start'> | StreamDataChunk<'data-om-observation-end'> | StreamDataChunk<'data-om-observation-failed'> | StreamDataChunk<'data-om-buffering-start'> | StreamDataChunk<'data-om-buffering-end'> | StreamDataChunk<'data-om-buffering-failed'> | StreamDataChunk<'data-signal'> | StreamDataChunk<'data-user-message'> | StreamDataChunk<'data-system-reminder'> | StreamDataChunk<'data-om-activation'> | StreamDataChunk<'data-om-thread-update'> | StreamDataChunk<'data-mastracode-tool-progress'> | StreamDataChunk<'data-sandbox-stdout'> | StreamDataChunk<'data-sandbox-stderr'>;
type StreamState = {
    currentMessage: MastraDBMessage;
    lastFinishedMessage?: MastraDBMessage;
    isSuspended: boolean;
    textContentById: Map<string, {
        index: number;
        text: string;
    }>;
    thinkingContentById: Map<string, {
        index: number;
        text: string;
    }>;
    toolPartById: Map<string, number>;
    /**
     * Set when a stream ends on a non-success finish reason (e.g. `content-filter`,
     * `error`, `length`). Carries the user-facing message so the run finalizes
     * into an explicit terminal error state instead of silently completing.
     */
    terminalError?: string;
};
/**
 * The per-session agent run engine: it consumes an agent's event stream, folds
 * each chunk into the session's display messages and token usage, drives tool
 * approval/suspension, and finalizes the run. In the multi-user host the run
 * loop, run state, and thread stream are per-session and cannot be shared, so
 * they live on the Session — this engine is owned by exactly one Session.
 *
 * It reaches the host only through the narrow {@link SessionMachinery} it is
 * constructed with (resolve the agent, build run/stream options, persist usage,
 * drive tool approval/resume, drain follow-ups). It never reaches back into the
 * AgentController or another session: all per-run state is read and written on its own
 * {@link Session}.
 */
export declare class SessionRunEngine {
    #private;
    constructor(session: Session, machinery: SessionMachinery);
    setRequestContext(requestContext?: RequestContext): void;
    private createEmptyAssistantMessage;
    /**
     * Build a DB-native signal message from a streamed `data-signal` /
     * `data-user-message` / `data-system-reminder` chunk. The raw data-part is
     * carried verbatim on `content.parts` and the signal identity is preserved on
     * `content.metadata.signal` so consumers read the native shape (no flattening).
     */
    private createSignalMessage;
    private hasCurrentMessageContent;
    /**
     * Snapshot a message for emission. The engine mutates parts in place
     * (text/reasoning deltas, tool-invocation upgrades) and `setStopReason` /
     * `setErrorMessage` mutate `content.metadata`, so emitted snapshots must
     * deep-clone the content or later mutations rewrite earlier snapshots.
     */
    private cloneMessage;
    private setStopReason;
    private setErrorMessage;
    private finishCurrentMessageAndRotate;
    createStreamState(): StreamState;
    private abortForOmFailure;
    /**
     * Process a stream response (shared between sendMessage and tool approval).
     */
    processStream(response: {
        fullStream: AsyncIterable<StreamChunk>;
    }, requestContextInput?: RequestContext): Promise<{
        message: MastraDBMessage;
        suspended?: boolean;
    } | undefined>;
    processStreamChunk(state: StreamState, chunk: StreamChunk, requestContext: RequestContext): Promise<{
        message: MastraDBMessage;
        suspended?: boolean;
    } | undefined>;
    private finishStreamState;
    private finishSubscribedStreamRun;
    private handleSubscribedStreamError;
    processSubscribedThreadStream(subscription: AgentThreadSubscription<StreamChunk>): Promise<void>;
}
export {};
//# sourceMappingURL=session-run-engine.d.ts.map