UNPKG

@mastra/core

Version:
64 lines 2.69 kB
import type { AgentThreadSubscription } from '../agent/types.js'; import type { RequestContext } from '../request-context/index.js'; import type { Session, SessionMachinery } from './session.js'; import type { AgentControllerMessage } from './types.js'; type StreamState = { currentMessage: AgentControllerMessage; lastFinishedMessage?: AgentControllerMessage; isSuspended: boolean; textContentById: Map<string, { index: number; text: string; }>; thinkingContentById: Map<string, { index: number; text: string; }>; /** * 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); private createEmptyAssistantMessage; private hasCurrentMessageContent; private finishCurrentMessageAndRotate; createStreamState(): StreamState; private abortForOmFailure; /** * Process a stream response (shared between sendMessage and tool approval). */ processStream(response: { fullStream: AsyncIterable<any>; }, requestContextInput?: RequestContext): Promise<{ message: AgentControllerMessage; suspended?: boolean; } | undefined>; processStreamChunk(state: StreamState, chunk: any, requestContext: RequestContext): Promise<{ message: AgentControllerMessage; suspended?: boolean; } | undefined>; private finishStreamState; private finishSubscribedStreamRun; private handleSubscribedStreamError; processSubscribedThreadStream(subscription: AgentThreadSubscription<any>): Promise<void>; } export {}; //# sourceMappingURL=session-run-engine.d.ts.map