import * as _ai_sdk_ui_utils from '@ai-sdk/ui-utils'; import { Message } from 'ai'; /** * Generic MessagePart interface that can handle any part coming from the AI SDK * Messages can have text parts, tool call parts, reasoning parts, etc. */ interface MessagePart { type: string; [key: string]: unknown; } /** * Interface extending the AI SDK Message type * This is only used for type safety in our groupMessageBySteps function */ type MessageWithParts = Message & { parts?: MessagePart[]; }; /** * Groups message parts into steps based on 'step-start' markers. * * This function processes an AI SDK message and groups its parts into logical steps, * making it easier to render or process multi-step interactions like tool calls. * * If no step-start markers are found, all parts will be treated as a single step. * If no parts exist in the message, an empty array is returned. * * @example * ```typescript * // Example message from AI SDK * const message = { * id: 'msg-123', * role: 'assistant', * parts: [ * { type: 'step-start', messageId: 'step-1' }, * { type: 'text', text: 'Hello' }, * { type: 'step-start', messageId: 'step-2' }, * { type: 'text', text: 'Goodbye' } * ] * }; * * // Group the parts into steps * const steps = groupMessageBySteps(message); * * // Result: * // [ * // { id: 'step-1', stepNumber: 1, parts: [{ type: 'text', text: 'Hello' }] }, * // { id: 'step-2', stepNumber: 2, parts: [{ type: 'text', text: 'Goodbye' }] } * // ] * ``` * * @param message The message to process * @returns Array of step objects containing grouped parts */ declare function groupMessageBySteps(message: MessageWithParts): { id: {}; stepNumber: number; parts: (_ai_sdk_ui_utils.TextUIPart | _ai_sdk_ui_utils.ReasoningUIPart | _ai_sdk_ui_utils.ToolInvocationUIPart | _ai_sdk_ui_utils.SourceUIPart | _ai_sdk_ui_utils.FileUIPart | _ai_sdk_ui_utils.StepStartUIPart)[]; }[]; type StepPart = ReturnType[number]["parts"][number]; type Step = ReturnType[number]; export { type MessageWithParts, type Step, type StepPart, groupMessageBySteps };