import type { MastraLanguageModel } from '../../llm/model/shared.types'; import type { StreamInternal } from '../types'; type State = { stepResult: Record | undefined; responseMetadata: Record | undefined; modelMetadata: { modelId: string; modelVersion: string; modelProvider: string; }; hasErrored: boolean; apiError: unknown | undefined; deferredErrorChunk: any | undefined; providerOptions: Record | undefined; /** Assistant text emitted so far for the in-flight step. Surfaced to `onAbort` when a run is cancelled mid-stream. */ partialText: string; }; export class AgenticRunState { #state: State; constructor({ _internal, model }: { _internal: StreamInternal; model: MastraLanguageModel }) { this.#state = { responseMetadata: { id: _internal?.generateId?.(), timestamp: _internal?.currentDate?.(), modelId: model.modelId, modelVersion: model.specificationVersion, modelProvider: model.provider, headers: undefined, }, modelMetadata: { modelId: model.modelId, modelVersion: model.specificationVersion, modelProvider: model.provider, }, providerOptions: undefined, hasErrored: false, apiError: undefined, deferredErrorChunk: undefined, stepResult: undefined, partialText: '', }; } setState(state: Partial) { this.#state = { ...this.#state, ...state, }; } get state() { return this.#state; } }