UNPKG

@mastra/core

Version:
36 lines • 1.74 kB
import type { ToolSet } from '../../../_types/@internal_ai-sdk-v5@0.0.98/dist/index.js'; import type { MastraDBMessage } from '../../../agent/message-list/index.js'; /** * A raw chunk collected during the stream. * We only store the type and payload — everything needed to reconstruct messages post-stream. */ export type CollectedChunk = { type: string; payload: any; metadata?: Record<string, any>; }; /** * Build MastraDBMessage entries from the full sequence of stream chunks. * * This replaces the previous approach of flushing text/reasoning deltas into * messages mid-stream. By walking the complete chunk sequence we: * * 1. Produce exactly one text part per text-start/text-end span (no duplicates) * 2. Produce exactly one reasoning part per reasoning-start/reasoning-end span * 3. Preserve correct stream ordering (text before tool-call if that's how they arrived) * 4. Use providerMetadata with "last seen wins" semantics per AI SDK convention. * Exception: Responses item ids — a hosted tool (e.g. OpenAI `tool_search`) * gives its call and output distinct ids, and replay needs both, so the call's * id is kept as `itemId` and the result's stashed as `resultItemId`. * 5. Skip empty text spans (empty-string deltas only) — no more empty text parts in DB * 6. Merge tool-call + tool-result into a single part with state: 'result' when applicable */ export declare function buildMessagesFromChunks({ chunks, messageId, responseModelMetadata, tools, }: { chunks: CollectedChunk[]; messageId: string; responseModelMetadata?: { metadata: Record<string, unknown>; }; tools?: ToolSet; }): MastraDBMessage[]; //# sourceMappingURL=build-messages-from-chunks.d.ts.map