UNPKG

@mastra/core

Version:
44 lines • 1.61 kB
import type { ChunkType } from '../../stream/types.js'; import type { MastraMessagePart } from './state/types.js'; declare const SPAN_CHUNK_TYPES: readonly ['text-start', 'text-delta', 'text-end', 'reasoning-start', 'reasoning-delta', 'reasoning-end', 'redacted-reasoning']; type SpanChunkType = (typeof SPAN_CHUNK_TYPES)[number]; export type SpanChunk = { [T in SpanChunkType]: { type: T; payload: Extract<ChunkType, { type: T; }>['payload']; }; }[SpanChunkType]; export type FoldedSpan = { part: MastraMessagePart; created: boolean; }; type TextPart = Extract<MastraMessagePart, { type: 'text'; }>; type ReasoningPart = Extract<MastraMessagePart, { type: 'reasoning'; }>; export declare function isSpanChunk(chunk: { type: string; }): chunk is SpanChunk; /** * Folds the text and reasoning span chunks of one assistant message into its * parts: a span opens on its first delta, grows on the next ones, and closes on * its end chunk so a provider that numbers content blocks per response cannot * append a later step into an earlier part. */ export declare class MessagePartSpans { #private; constructor({ providerMetadata }?: { providerMetadata?: boolean; }); clear(): void; flushSpansLeftOpen(parts: MastraMessagePart[]): void; openTextSpan(parts: MastraMessagePart[], id: string): TextPart; openReasoningSpan(parts: MastraMessagePart[], id: string): ReasoningPart; fold(parts: MastraMessagePart[], chunk: SpanChunk): FoldedSpan | undefined; } export {}; //# sourceMappingURL=message-part-spans.d.ts.map