@mastra/ai-sdk 0.0.0-cloud-deployer-for-core-0.19.1-20251001164939 → 0.0.0-cloud-604-map-nested-flow-details-to-side-panel-20251212192149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.stream.d.ts","sourceRoot":"","sources":["../../../src/__tests__/__fixtures__/network.stream.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAu9FhC,CAAC"}
@@ -1,14 +1,101 @@
1
1
  import type { AgentExecutionOptions } from '@mastra/core/agent';
2
+ import type { Mastra } from '@mastra/core/mastra';
2
3
  import { registerApiRoute } from '@mastra/core/server';
3
4
  import type { OutputSchema } from '@mastra/core/stream';
5
+ import type { InferUIMessageChunk, UIMessage } from 'ai';
6
+ export type ChatStreamHandlerParams<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined> = AgentExecutionOptions<OUTPUT, 'mastra'> & {
7
+ messages: UI_MESSAGE[];
8
+ resumeData?: Record<string, any>;
9
+ };
10
+ export type ChatStreamHandlerOptions<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined> = {
11
+ mastra: Mastra;
12
+ agentId: string;
13
+ params: ChatStreamHandlerParams<UI_MESSAGE, OUTPUT>;
14
+ defaultOptions?: AgentExecutionOptions<OUTPUT, 'mastra'>;
15
+ sendStart?: boolean;
16
+ sendFinish?: boolean;
17
+ sendReasoning?: boolean;
18
+ sendSources?: boolean;
19
+ };
20
+ /**
21
+ * Framework-agnostic handler for streaming agent chat in AI SDK-compatible format.
22
+ * Use this function directly when you need to handle chat streaming outside of Hono or Mastra's own apiRoutes feature.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // Next.js App Router
27
+ * import { handleChatStream } from '@mastra/ai-sdk';
28
+ * import { createUIMessageStreamResponse } from 'ai';
29
+ * import { mastra } from '@/src/mastra';
30
+ *
31
+ * export async function POST(req: Request) {
32
+ * const params = await req.json();
33
+ * const stream = await handleChatStream({
34
+ * mastra,
35
+ * agentId: 'weatherAgent',
36
+ * params,
37
+ * });
38
+ * return createUIMessageStreamResponse({ stream });
39
+ * }
40
+ * ```
41
+ */
42
+ export declare function handleChatStream<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined>({ mastra, agentId, params, defaultOptions, sendStart, sendFinish, sendReasoning, sendSources, }: ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>): Promise<ReadableStream<InferUIMessageChunk<UI_MESSAGE>>>;
4
43
  export type chatRouteOptions<OUTPUT extends OutputSchema = undefined> = {
5
- defaultOptions?: AgentExecutionOptions<OUTPUT, 'aisdk'>;
44
+ defaultOptions?: AgentExecutionOptions<OUTPUT, 'mastra'>;
6
45
  } & ({
7
46
  path: `${string}:agentId${string}`;
8
47
  agent?: never;
9
48
  } | {
10
49
  path: string;
11
50
  agent: string;
12
- });
13
- export declare function chatRoute<OUTPUT extends OutputSchema = undefined>({ path, agent, defaultOptions, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
51
+ }) & {
52
+ sendStart?: boolean;
53
+ sendFinish?: boolean;
54
+ sendReasoning?: boolean;
55
+ sendSources?: boolean;
56
+ };
57
+ /**
58
+ * Creates a chat route handler for streaming agent conversations using the AI SDK format.
59
+ *
60
+ * This function registers an HTTP POST endpoint that accepts messages, executes an agent, and streams the response back to the client in AI SDK-compatible format.
61
+ *
62
+ * @param {chatRouteOptions} options - Configuration options for the chat route
63
+ * @param {string} [options.path='/chat/:agentId'] - The route path. Include `:agentId` for dynamic routing
64
+ * @param {string} [options.agent] - Fixed agent ID when not using dynamic routing
65
+ * @param {AgentExecutionOptions} [options.defaultOptions] - Default options passed to agent execution
66
+ * @param {boolean} [options.sendStart=true] - Whether to send start events in the stream
67
+ * @param {boolean} [options.sendFinish=true] - Whether to send finish events in the stream
68
+ * @param {boolean} [options.sendReasoning=false] - Whether to include reasoning steps in the stream
69
+ * @param {boolean} [options.sendSources=false] - Whether to include source citations in the stream
70
+ *
71
+ * @returns {ReturnType<typeof registerApiRoute>} A registered API route handler
72
+ *
73
+ * @throws {Error} When path doesn't include `:agentId` and no fixed agent is specified
74
+ * @throws {Error} When agent ID is missing at runtime
75
+ * @throws {Error} When specified agent is not found in Mastra instance
76
+ *
77
+ * @example
78
+ * // Dynamic agent routing
79
+ * chatRoute({
80
+ * path: '/chat/:agentId',
81
+ * });
82
+ *
83
+ * @example
84
+ * // Fixed agent with custom path
85
+ * chatRoute({
86
+ * path: '/api/support-chat',
87
+ * agent: 'support-agent',
88
+ * defaultOptions: {
89
+ * maxSteps: 5,
90
+ * },
91
+ * });
92
+ *
93
+ * @remarks
94
+ * - The route handler expects a JSON body with a `messages` array
95
+ * - Messages should follow the format: `{ role: 'user' | 'assistant' | 'system', content: string }`
96
+ * - The response is a Server-Sent Events (SSE) stream compatible with AI SDK v5
97
+ * - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
98
+ * - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
99
+ */
100
+ export declare function chatRoute<OUTPUT extends OutputSchema = undefined>({ path, agent, defaultOptions, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
14
101
  //# sourceMappingURL=chat-route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[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AAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,SAAS,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACjE,IAAuB,EACvB,KAAK,EACL,cAAc,EACd,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CA0JhE"}
@@ -0,0 +1,90 @@
1
+ import type { MessageListInput } from '@mastra/core/agent/message-list';
2
+ /**
3
+ * Converts messages from various input formats to AI SDK V5 UI message format.
4
+ *
5
+ * This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5 UIMessage format, which is suitable for use with AI SDK V5 UI components like `useChat()`.
6
+ *
7
+ * @param messages - Messages to convert. Accepts:
8
+ * - `string` - A single text message (treated as user role)
9
+ * - `string[]` - Multiple text messages
10
+ * - `MessageInput` - A single message object in any supported format:
11
+ * - AI SDK V5 UIMessage or ModelMessage
12
+ * - AI SDK V4 UIMessage or CoreMessage
13
+ * - MastraDBMessage (internal storage format)
14
+ * - MastraMessageV1 (legacy format)
15
+ * - `MessageInput[]` - Array of message objects
16
+ *
17
+ * @returns An array of AI SDK V5 UIMessage objects with:
18
+ * - `id` - Unique message identifier
19
+ * - `role` - 'user' | 'assistant' | 'system'
20
+ * - `parts` - Array of UI parts (text, tool results, files, reasoning, etc.)
21
+ * - `metadata` - Optional metadata including createdAt, threadId, resourceId
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { toAISdkV5Messages } from '@mastra/ai-sdk';
26
+ *
27
+ * // Convert simple text messages
28
+ * const messages = toAISdkV5Messages(['Hello', 'How can I help?']);
29
+ *
30
+ * // Convert AI SDK V4 messages to V5 format
31
+ * const v4Messages = [
32
+ * { id: '1', role: 'user', content: 'Hello', parts: [{ type: 'text', text: 'Hello' }] },
33
+ * { id: '2', role: 'assistant', content: 'Hi!', parts: [{ type: 'text', text: 'Hi!' }] }
34
+ * ];
35
+ * const v5Messages = toAISdkV5Messages(v4Messages);
36
+ *
37
+ * // Use with useChat or similar AI SDK V5 hooks
38
+ * const { messages: chatMessages } = useChat({
39
+ * initialMessages: toAISdkV5Messages(storedMessages)
40
+ * });
41
+ * ```
42
+ */
43
+ export declare function toAISdkV5Messages(messages: MessageListInput): import("ai-v5").UIMessage<unknown, import("ai-v5").UIDataTypes, import("ai-v5").UITools>[];
44
+ /**
45
+ * Converts messages from various input formats to AI SDK V4 UI message format.
46
+ *
47
+ * This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V4 UIMessage format, which is suitable for use with AI SDK V4 UI components.
48
+ *
49
+ * @param messages - Messages to convert. Accepts:
50
+ * - `string` - A single text message (treated as user role)
51
+ * - `string[]` - Multiple text messages
52
+ * - `MessageInput` - A single message object in any supported format:
53
+ * - AI SDK V5 UIMessage or ModelMessage
54
+ * - AI SDK V4 UIMessage or CoreMessage
55
+ * - MastraDBMessage (internal storage format)
56
+ * - MastraMessageV1 (legacy format)
57
+ * - `MessageInput[]` - Array of message objects
58
+ *
59
+ * @returns An array of AI SDK V4 UIMessage objects with:
60
+ * - `id` - Unique message identifier
61
+ * - `role` - 'user' | 'assistant' | 'system'
62
+ * - `content` - Text content of the message
63
+ * - `parts` - Array of UI parts (text, tool-invocation, file, reasoning, etc.)
64
+ * - `createdAt` - Message creation timestamp
65
+ * - `toolInvocations` - Optional array of tool invocations (for assistant messages)
66
+ * - `experimental_attachments` - Optional file attachments
67
+ * - `metadata` - Optional custom metadata
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { toAISdkV4Messages } from '@mastra/ai-sdk';
72
+ *
73
+ * // Convert simple text messages
74
+ * const messages = toAISdkV4Messages(['Hello', 'How can I help?']);
75
+ *
76
+ * // Convert AI SDK V5 messages to V4 format for legacy compatibility
77
+ * const v5Messages = [
78
+ * { id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] },
79
+ * { id: '2', role: 'assistant', parts: [{ type: 'text', text: 'Hi!' }] }
80
+ * ];
81
+ * const v4Messages = toAISdkV4Messages(v5Messages);
82
+ *
83
+ * // Use with AI SDK V4 useChat hook
84
+ * const { messages: chatMessages } = useChat({
85
+ * initialMessages: toAISdkV4Messages(storedMessages)
86
+ * });
87
+ * ```
88
+ */
89
+ export declare function toAISdkV4Messages(messages: MessageListInput): import("@mastra/core/agent").UIMessageWithMetadata[];
90
+ //# sourceMappingURL=convert-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-messages.d.ts","sourceRoot":"","sources":["../src/convert-messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,8FAE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,wDAE3D"}
@@ -0,0 +1,81 @@
1
+ import type { MastraModelOutput, OutputSchema, MastraAgentNetworkStream, WorkflowRunOutput } from '@mastra/core/stream';
2
+ import type { MastraWorkflowStream, Step, WorkflowResult } from '@mastra/core/workflows';
3
+ import type { InferUIMessageChunk, UIMessage, UIMessageStreamOptions } from 'ai';
4
+ import type { ZodObject, ZodType } from 'zod';
5
+ /**
6
+ * Converts Mastra streams (workflow, agent network, or agent) to AI SDK v5 compatible streams.
7
+ *
8
+ * This function transforms various Mastra stream types into ReadableStream objects that are compatible with the AI SDK v5, enabling seamless integration with AI SDK's streaming capabilities.
9
+ *
10
+ *
11
+ * @param {MastraWorkflowStream | WorkflowRunOutput | MastraAgentNetworkStream | MastraModelOutput} stream
12
+ * The Mastra stream to convert. Can be one of:
13
+ * - MastraWorkflowStream: A workflow execution stream
14
+ * - WorkflowRunOutput: The output of a workflow run
15
+ * - MastraAgentNetworkStream: An agent network execution stream
16
+ * - MastraModelOutput: An agent model output stream
17
+ *
18
+ * @param {Object} options - Conversion options
19
+ * @param {'workflow' | 'network' | 'agent'} options.from - The type of stream being converted. Defaults to 'agent'
20
+ * @param {string} [options.lastMessageId] - (Agent only) The ID of the last message in the conversation
21
+ * @param {boolean} [options.sendStart=true] - (Agent only) Whether to send start events. Defaults to true
22
+ * @param {boolean} [options.sendFinish=true] - (Agent only) Whether to send finish events. Defaults to true
23
+ * @param {boolean} [options.sendReasoning] - (Agent only) Whether to include reasoning in the output
24
+ * @param {boolean} [options.sendSources] - (Agent only) Whether to include sources in the output
25
+ * @param {Function} [options.messageMetadata] - (Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks
26
+ * @param {Function} [options.onError] - (Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation
27
+ *
28
+ * @returns {ReadableStream<InferUIMessageChunk<UIMessage>>} A ReadableStream compatible with AI SDK v5
29
+ *
30
+ * @example
31
+ * // Convert a workflow stream
32
+ * const workflowStream = await workflowRun.stream(...);
33
+ * const aiSDKStream = toAISdkV5Stream(workflowStream, { from: 'workflow' });
34
+ *
35
+ * @example
36
+ * // Convert an agent network stream
37
+ * const networkStream = await agentNetwork.network(...);
38
+ * const aiSDKStream = toAISdkV5Stream(networkStream, { from: 'network' });
39
+ *
40
+ * @example
41
+ * // Convert an agent stream with custom options
42
+ * const agentStream = await agent.stream(...);
43
+ * const aiSDKStream = toAISdkV5Stream(agentStream, {
44
+ * from: 'agent',
45
+ * lastMessageId: 'msg-123',
46
+ * sendReasoning: true,
47
+ * sendSources: true
48
+ * });
49
+ *
50
+ * @example
51
+ * // Convert an agent stream with messageMetadata
52
+ * const aiSDKStream = toAISdkV5Stream(agentStream, {
53
+ * from: 'agent',
54
+ * messageMetadata: ({ part }) => ({
55
+ * timestamp: Date.now(),
56
+ * partType: part.type
57
+ * })
58
+ * });
59
+ */
60
+ export declare function toAISdkV5Stream<TOutput extends ZodType<any>, TInput extends ZodType<any>, TSteps extends Step<string, any, any, any, any, any>[], TState extends ZodObject<any>>(stream: MastraWorkflowStream<TState, TInput, TOutput, TSteps>, options: {
61
+ from: 'workflow';
62
+ includeTextStreamParts?: boolean;
63
+ }): ReadableStream<InferUIMessageChunk<UIMessage>>;
64
+ export declare function toAISdkV5Stream<TOutput extends ZodType<any>, TInput extends ZodType<any>, TSteps extends Step<string, any, any, any, any, any>[], TState extends ZodObject<any>>(stream: WorkflowRunOutput<WorkflowResult<TState, TInput, TOutput, TSteps>>, options: {
65
+ from: 'workflow';
66
+ includeTextStreamParts?: boolean;
67
+ }): ReadableStream<InferUIMessageChunk<UIMessage>>;
68
+ export declare function toAISdkV5Stream(stream: MastraAgentNetworkStream, options: {
69
+ from: 'network';
70
+ }): ReadableStream<InferUIMessageChunk<UIMessage>>;
71
+ export declare function toAISdkV5Stream<TOutput extends OutputSchema>(stream: MastraModelOutput<TOutput>, options: {
72
+ from: 'agent';
73
+ lastMessageId?: string;
74
+ sendStart?: boolean;
75
+ sendFinish?: boolean;
76
+ sendReasoning?: boolean;
77
+ sendSources?: boolean;
78
+ messageMetadata?: UIMessageStreamOptions<UIMessage>['messageMetadata'];
79
+ onError?: UIMessageStreamOptions<UIMessage>['onError'];
80
+ }): ReadableStream<InferUIMessageChunk<UIMessage>>;
81
+ //# sourceMappingURL=convert-streams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-streams.d.ts","sourceRoot":"","sources":["../src/convert-streams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAEjB,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,qB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AsB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC9D,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAClD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAC3B,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAClD,wBAAgB,eAAe,CAAC,OAAO,SAAS,YAAY,EAC1D,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAClC,OAAO,EAAE;IACP,IAAI,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACvE,OAAO,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;CACxD,GACA,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { PartialSchemaOutput, OutputSchema, DataChunkType, ChunkType, MastraFinishReason } from '@mastra/core/stream';
2
+ import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage, FinishReason } from 'ai';
3
+ /**
4
+ * Maps Mastra's extended finish reasons to AI SDK-compatible values.
5
+ * 'tripwire' and 'retry' are Mastra-specific reasons for processor scenarios,
6
+ * which are mapped to 'other' for AI SDK compatibility.
7
+ */
8
+ export declare function toAISDKFinishReason(reason: MastraFinishReason): FinishReason;
9
+ export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | DataChunkType | undefined;
10
+ export type ToolAgentChunkType = {
11
+ type: 'tool-agent';
12
+ toolCallId: string;
13
+ payload: any;
14
+ };
15
+ export type ToolWorkflowChunkType = {
16
+ type: 'tool-workflow';
17
+ toolCallId: string;
18
+ payload: any;
19
+ };
20
+ export type ToolNetworkChunkType = {
21
+ type: 'tool-network';
22
+ toolCallId: string;
23
+ payload: any;
24
+ };
25
+ export declare function convertMastraChunkToAISDKv5<OUTPUT extends OutputSchema = undefined>({ chunk, mode, }: {
26
+ chunk: ChunkType<OUTPUT>;
27
+ mode?: 'generate' | 'stream';
28
+ }): OutputChunkType<OUTPUT>;
29
+ export declare function convertFullStreamChunkToUIMessageStream<UI_MESSAGE extends UIMessage>({ part, messageMetadataValue, sendReasoning, sendSources, onError, sendStart, sendFinish, responseMessageId, }: {
30
+ part: TextStreamPart<ToolSet> | DataChunkType | {
31
+ type: 'tool-output';
32
+ toolCallId: string;
33
+ output: any;
34
+ };
35
+ messageMetadataValue?: unknown;
36
+ sendReasoning?: boolean;
37
+ sendSources?: boolean;
38
+ onError: (error: unknown) => string;
39
+ sendStart?: boolean;
40
+ sendFinish?: boolean;
41
+ responseMessageId?: string;
42
+ }): InferUIMessageChunk<UI_MESSAGE> | ToolAgentChunkType | ToolWorkflowChunkType | ToolNetworkChunkType | undefined;
43
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAGlH;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAK5E;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