@mastra/ai-sdk 1.0.0-beta.4 → 1.0.0-beta.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,80 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.0.0-beta.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve JSDoc comments ([#10877](https://github.com/mastra-ai/mastra/pull/10877))
8
+
9
+ - Updated dependencies [[`0d41fe2`](https://github.com/mastra-ai/mastra/commit/0d41fe245355dfc66d61a0d9c85d9400aac351ff), [`6b3ba91`](https://github.com/mastra-ai/mastra/commit/6b3ba91494cc10394df96782f349a4f7b1e152cc), [`7907fd1`](https://github.com/mastra-ai/mastra/commit/7907fd1c5059813b7b870b81ca71041dc807331b)]:
10
+ - @mastra/core@1.0.0-beta.8
11
+
12
+ ## 1.0.0-beta.5
13
+
14
+ ### Minor Changes
15
+
16
+ - Add framework-agnostic stream handlers for use outside of Hono/Mastra server ([#10628](https://github.com/mastra-ai/mastra/pull/10628))
17
+ - `handleChatStream`: Standalone handler for streaming agent chat in AI SDK format
18
+ - `handleWorkflowStream`: Standalone handler for streaming workflow execution in AI SDK format
19
+ - `handleNetworkStream`: Standalone handler for streaming agent network execution in AI SDK format
20
+ These functions accept all arguments explicitly and return a `ReadableStream`, making them usable in any framework (Next.js App Router, Express, etc.) without depending on Hono context.
21
+
22
+ Example usage:
23
+
24
+ ```typescript
25
+ import { handleChatStream } from '@mastra/ai-sdk';
26
+ import { createUIMessageStreamResponse } from 'ai';
27
+ export async function POST(req: Request) {
28
+ const params = await req.json();
29
+ const stream = await handleChatStream({
30
+ mastra,
31
+ agentId: 'weatherAgent',
32
+ params,
33
+ });
34
+ return createUIMessageStreamResponse({ stream });
35
+ }
36
+ ```
37
+
38
+ New exports:
39
+ - handleChatStream, ChatStreamHandlerParams, ChatStreamHandlerOptions
40
+ - handleWorkflowStream, WorkflowStreamHandlerParams, WorkflowStreamHandlerOptions
41
+ - handleNetworkStream, NetworkStreamHandlerParams, NetworkStreamHandlerOptions
42
+
43
+ ### Patch Changes
44
+
45
+ - Support streaming agent text chunks from workflow-step-output ([#10540](https://github.com/mastra-ai/mastra/pull/10540))
46
+
47
+ Adds support for streaming text and tool call chunks from agents running inside workflows via the workflow-step-output event. When you pipe an agent's stream into a workflow step's writer, the text chunks, tool calls, and other streaming events are automatically included in the workflow stream and converted to UI messages.
48
+
49
+ **Features:**
50
+ - Added `includeTextStreamParts` option to `WorkflowStreamToAISDKTransformer` (defaults to `true`)
51
+ - Added `isMastraTextStreamChunk` type guard to identify Mastra chunks with text streaming data
52
+ - Support for streaming text chunks: `text-start`, `text-delta`, `text-end`
53
+ - Support for streaming tool calls: `tool-call`, `tool-result`
54
+ - Comprehensive test coverage in `transformers.test.ts`
55
+ - Updated documentation for workflow streaming and `workflowRoute()`
56
+
57
+ **Example:**
58
+
59
+ ```typescript
60
+ const planActivities = createStep({
61
+ execute: async ({ mastra, writer }) => {
62
+ const agent = mastra?.getAgent('weatherAgent');
63
+ const response = await agent.stream('Plan activities');
64
+ await response.fullStream.pipeTo(writer);
65
+
66
+ return { activities: await response.text };
67
+ },
68
+ });
69
+ ```
70
+
71
+ When served via `workflowRoute()`, the UI receives incremental text updates as the agent generates its response, providing a smooth streaming experience.
72
+
73
+ - Added support for resuming agent streams in the chat route. You can now pass `resumeData` in the request body to continue a previous agent stream, enabling long-running conversations and multi-step agent workflows. ([#10448](https://github.com/mastra-ai/mastra/pull/10448))
74
+
75
+ - Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
76
+ - @mastra/core@1.0.0-beta.6
77
+
3
78
  ## 1.0.0-beta.4
4
79
 
5
80
  ### Patch Changes
package/README.md CHANGED
@@ -93,6 +93,64 @@ export const mastra = new Mastra({
93
93
  });
94
94
  ```
95
95
 
96
+ ## Framework-agnostic handlers
97
+
98
+ For use outside of the Mastra server (e.g., Next.js App Router, Express), you can use the standalone handler functions directly. These handlers return a `ReadableStream` that you can wrap with `createUIMessageStreamResponse`:
99
+
100
+ ### handleChatStream
101
+
102
+ ```typescript
103
+ import { handleChatStream } from '@mastra/ai-sdk';
104
+ import { createUIMessageStreamResponse } from 'ai';
105
+ import { mastra } from '@/src/mastra';
106
+
107
+ export async function POST(req: Request) {
108
+ const params = await req.json();
109
+ const stream = await handleChatStream({
110
+ mastra,
111
+ agentId: 'weatherAgent',
112
+ params,
113
+ });
114
+ return createUIMessageStreamResponse({ stream });
115
+ }
116
+ ```
117
+
118
+ ### handleWorkflowStream
119
+
120
+ ```typescript
121
+ import { handleWorkflowStream } from '@mastra/ai-sdk';
122
+ import { createUIMessageStreamResponse } from 'ai';
123
+ import { mastra } from '@/src/mastra';
124
+
125
+ export async function POST(req: Request) {
126
+ const params = await req.json();
127
+ const stream = await handleWorkflowStream({
128
+ mastra,
129
+ workflowId: 'myWorkflow',
130
+ params,
131
+ });
132
+ return createUIMessageStreamResponse({ stream });
133
+ }
134
+ ```
135
+
136
+ ### handleNetworkStream
137
+
138
+ ```typescript
139
+ import { handleNetworkStream } from '@mastra/ai-sdk';
140
+ import { createUIMessageStreamResponse } from 'ai';
141
+ import { mastra } from '@/src/mastra';
142
+
143
+ export async function POST(req: Request) {
144
+ const params = await req.json();
145
+ const stream = await handleNetworkStream({
146
+ mastra,
147
+ agentId: 'routingAgent',
148
+ params,
149
+ });
150
+ return createUIMessageStreamResponse({ stream });
151
+ }
152
+ ```
153
+
96
154
  ## Manual transformation
97
155
 
98
156
  If you have a raw Mastra `stream`, you can manually transform it to AI SDK UI message parts:
@@ -106,7 +164,9 @@ export async function POST(req: Request) {
106
164
  const agent = mastra.getAgent('weatherAgent');
107
165
  const stream = await agent.stream(messages);
108
166
 
167
+ // deduplicate messages https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages
109
168
  const uiMessageStream = createUIMessageStream({
169
+ originalMessages: messages,
110
170
  execute: async ({ writer }) => {
111
171
  for await (const part of toAISdkFormat(stream, { from: 'agent' })!) {
112
172
  writer.write(part);
@@ -1,8 +1,47 @@
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;
@@ -18,9 +57,8 @@ export type chatRouteOptions<OUTPUT extends OutputSchema = undefined> = {
18
57
  /**
19
58
  * Creates a chat route handler for streaming agent conversations using the AI SDK format.
20
59
  *
21
- * This function registers an HTTP POST endpoint that accepts messages, executes an agent,
22
- * and streams the response back to the client in AI SDK v5 compatible format.
23
- * *
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
+ *
24
62
  * @param {chatRouteOptions} options - Configuration options for the chat route
25
63
  * @param {string} [options.path='/chat/:agentId'] - The route path. Include `:agentId` for dynamic routing
26
64
  * @param {string} [options.agent] - Fixed agent ID when not using dynamic routing
@@ -40,7 +78,6 @@ export type chatRouteOptions<OUTPUT extends OutputSchema = undefined> = {
40
78
  * // Dynamic agent routing
41
79
  * chatRoute({
42
80
  * path: '/chat/:agentId',
43
- * sendReasoning: true,
44
81
  * });
45
82
  *
46
83
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,E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K,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,GAAG;IACA,SAAS,CAAC,EAAE,OAAO,CAAC;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"}
@@ -5,8 +5,7 @@ import type { ZodObject, ZodType } from 'zod';
5
5
  /**
6
6
  * Converts Mastra streams (workflow, agent network, or agent) to AI SDK v5 compatible streams.
7
7
  *
8
- * This function transforms various Mastra stream types into ReadableStream objects that are compatible
9
- * with the AI SDK v5, enabling seamless integration with AI SDK's streaming capabilities.
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.
10
9
  *
11
10
  *
12
11
  * @param {MastraWorkflowStream | WorkflowRunOutput | MastraAgentNetworkStream | MastraModelOutput} stream
@@ -60,9 +59,11 @@ import type { ZodObject, ZodType } from 'zod';
60
59
  */
61
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: {
62
61
  from: 'workflow';
62
+ includeTextStreamParts?: boolean;
63
63
  }): ReadableStream<InferUIMessageChunk<UIMessage>>;
64
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
65
  from: 'workflow';
66
+ includeTextStreamParts?: boolean;
66
67
  }): ReadableStream<InferUIMessageChunk<UIMessage>>;
67
68
  export declare function toAISdkV5Stream(stream: MastraAgentNetworkStream, options: {
68
69
  from: 'network';
@@ -1 +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,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAS9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,OAAO,CAAC,GAAG,CAAC,EAC5B,MAAM,SAAS,OAAO,CAAC,GAAG,CAAC,EAC3B,MAAM,SAAS,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EACtD,MAAM,SAAS,SAAS,CAAC,GAAG,CAAC,EAE7B,MAAM,EAAE,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAC7D,OAAO,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAC5B,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAClD,wBAAgB,eAAe,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M,CAAC,CAAC,EAC1E,OAAO,EAAE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,sBAAsB,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"}
package/dist/index.cjs CHANGED
@@ -10,6 +10,31 @@ var stream = require('@mastra/core/stream');
10
10
  var isDataChunkType = (chunk) => {
11
11
  return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
12
12
  };
13
+ var isMastraTextStreamChunk = (chunk) => {
14
+ return chunk && typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string" && [
15
+ "text-start",
16
+ "text-delta",
17
+ "text-end",
18
+ "reasoning-start",
19
+ "reasoning-delta",
20
+ "reasoning-end",
21
+ "file",
22
+ "source",
23
+ "tool-input-start",
24
+ "tool-input-delta",
25
+ "tool-call",
26
+ "tool-result",
27
+ "tool-error",
28
+ "error",
29
+ "start-step",
30
+ "finish-step",
31
+ "start",
32
+ "finish",
33
+ "abort",
34
+ "tool-input-end",
35
+ "raw"
36
+ ].includes(chunk.type);
37
+ };
13
38
  function safeParseErrorObject(obj) {
14
39
  if (typeof obj !== "object" || obj === null) {
15
40
  return String(obj);
@@ -492,7 +517,9 @@ function convertFullStreamChunkToUIMessageStream({
492
517
 
493
518
  // src/transformers.ts
494
519
  var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
495
- function WorkflowStreamToAISDKTransformer() {
520
+ function WorkflowStreamToAISDKTransformer({
521
+ includeTextStreamParts
522
+ } = {}) {
496
523
  const bufferedWorkflows = /* @__PURE__ */ new Map();
497
524
  return new TransformStream({
498
525
  start(controller) {
@@ -506,7 +533,7 @@ function WorkflowStreamToAISDKTransformer() {
506
533
  });
507
534
  },
508
535
  transform(chunk, controller) {
509
- const transformed = transformWorkflow(chunk, bufferedWorkflows);
536
+ const transformed = transformWorkflow(chunk, bufferedWorkflows, false, includeTextStreamParts);
510
537
  if (transformed) controller.enqueue(transformed);
511
538
  }
512
539
  });
@@ -727,7 +754,7 @@ function transformAgent(payload, bufferedSteps) {
727
754
  }
728
755
  return null;
729
756
  }
730
- function transformWorkflow(payload, bufferedWorkflows, isNested) {
757
+ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStreamParts) {
731
758
  switch (payload.type) {
732
759
  case "workflow-start":
733
760
  bufferedWorkflows.set(payload.runId, {
@@ -822,6 +849,16 @@ function transformWorkflow(payload, bufferedWorkflows, isNested) {
822
849
  }
823
850
  case "workflow-step-output": {
824
851
  const output = payload.payload.output;
852
+ if (includeTextStreamParts && output && isMastraTextStreamChunk(output)) {
853
+ const part = convertMastraChunkToAISDKv5({ chunk: output, mode: "stream" });
854
+ const transformedChunk = convertFullStreamChunkToUIMessageStream({
855
+ part,
856
+ onError(error) {
857
+ return safeParseErrorObject(error);
858
+ }
859
+ });
860
+ return transformedChunk;
861
+ }
825
862
  if (output && isDataChunkType(output)) {
826
863
  if (!("data" in output)) {
827
864
  throw new Error(
@@ -1122,7 +1159,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
1122
1159
  }
1123
1160
  step[PRIMITIVE_CACHE_SYMBOL] = step[PRIMITIVE_CACHE_SYMBOL] || /* @__PURE__ */ new Map();
1124
1161
  const result = transformWorkflow(payload.payload, step[PRIMITIVE_CACHE_SYMBOL]);
1125
- if (result) {
1162
+ if (result && "data" in result) {
1126
1163
  const data = result.data;
1127
1164
  step.task = data;
1128
1165
  if (data.name && step.task) {
@@ -1173,7 +1210,10 @@ function toAISdkV5Stream(stream, options = {
1173
1210
  }) {
1174
1211
  const from = options?.from;
1175
1212
  if (from === "workflow") {
1176
- return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
1213
+ const includeTextStreamParts = options?.includeTextStreamParts ?? true;
1214
+ return stream.pipeThrough(
1215
+ WorkflowStreamToAISDKTransformer({ includeTextStreamParts })
1216
+ );
1177
1217
  }
1178
1218
  if (from === "network") {
1179
1219
  return stream.pipeThrough(AgentNetworkToAISDKTransformer());
@@ -1193,6 +1233,57 @@ function toAISdkV5Stream(stream, options = {
1193
1233
  }
1194
1234
 
1195
1235
  // src/chat-route.ts
1236
+ async function handleChatStream({
1237
+ mastra,
1238
+ agentId,
1239
+ params,
1240
+ defaultOptions,
1241
+ sendStart = true,
1242
+ sendFinish = true,
1243
+ sendReasoning = false,
1244
+ sendSources = false
1245
+ }) {
1246
+ const { messages, resumeData, runId, requestContext, ...rest } = params;
1247
+ if (resumeData && !runId) {
1248
+ throw new Error("runId is required when resumeData is provided");
1249
+ }
1250
+ const agentObj = mastra.getAgentById(agentId);
1251
+ if (!agentObj) {
1252
+ throw new Error(`Agent ${agentId} not found`);
1253
+ }
1254
+ if (!Array.isArray(messages)) {
1255
+ throw new Error("Messages must be an array of UIMessage objects");
1256
+ }
1257
+ const mergedOptions = {
1258
+ ...defaultOptions,
1259
+ ...rest,
1260
+ ...runId && { runId },
1261
+ requestContext: requestContext || defaultOptions?.requestContext
1262
+ };
1263
+ const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messages, mergedOptions);
1264
+ let lastMessageId;
1265
+ if (messages.length) {
1266
+ const lastMessage = messages[messages.length - 1];
1267
+ if (lastMessage?.role === "assistant") {
1268
+ lastMessageId = lastMessage.id;
1269
+ }
1270
+ }
1271
+ return ai.createUIMessageStream({
1272
+ originalMessages: messages,
1273
+ execute: async ({ writer }) => {
1274
+ for await (const part of toAISdkV5Stream(result, {
1275
+ from: "agent",
1276
+ lastMessageId,
1277
+ sendStart,
1278
+ sendFinish,
1279
+ sendReasoning,
1280
+ sendSources
1281
+ })) {
1282
+ writer.write(part);
1283
+ }
1284
+ }
1285
+ });
1286
+ }
1196
1287
  function chatRoute({
1197
1288
  path = "/chat/:agentId",
1198
1289
  agent,
@@ -1229,6 +1320,14 @@ function chatRoute({
1229
1320
  schema: {
1230
1321
  type: "object",
1231
1322
  properties: {
1323
+ resumeData: {
1324
+ type: "object",
1325
+ description: "Resume data for the agent"
1326
+ },
1327
+ runId: {
1328
+ type: "string",
1329
+ description: "The run ID required when resuming an agent execution"
1330
+ },
1232
1331
  messages: {
1233
1332
  type: "array",
1234
1333
  description: "Array of messages in the conversation",
@@ -1299,9 +1398,9 @@ function chatRoute({
1299
1398
  }
1300
1399
  },
1301
1400
  handler: async (c) => {
1302
- const { messages, ...rest } = await c.req.json();
1401
+ const params = await c.req.json();
1303
1402
  const mastra = c.get("mastra");
1304
- const requestContext = c.get("requestContext");
1403
+ const contextRequestContext = c.get("requestContext");
1305
1404
  let agentToUse = agent;
1306
1405
  if (!agent) {
1307
1406
  const agentId = c.req.param("agentId");
@@ -1312,39 +1411,24 @@ function chatRoute({
1312
1411
  `Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
1313
1412
  );
1314
1413
  }
1315
- if (requestContext && defaultOptions?.requestContext) {
1414
+ if (contextRequestContext && defaultOptions?.requestContext) {
1316
1415
  mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
1317
1416
  }
1318
1417
  if (!agentToUse) {
1319
1418
  throw new Error("Agent ID is required");
1320
1419
  }
1321
- const agentObj = mastra.getAgentById(agentToUse);
1322
- if (!agentObj) {
1323
- throw new Error(`Agent ${agentToUse} not found`);
1324
- }
1325
- const result = await agentObj.stream(messages, {
1326
- ...defaultOptions,
1327
- ...rest,
1328
- requestContext: requestContext || defaultOptions?.requestContext
1329
- });
1330
- let lastMessageId;
1331
- if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
1332
- lastMessageId = messages[messages.length - 1].id;
1333
- }
1334
- const uiMessageStream = ai.createUIMessageStream({
1335
- originalMessages: messages,
1336
- execute: async ({ writer }) => {
1337
- for await (const part of toAISdkV5Stream(result, {
1338
- from: "agent",
1339
- lastMessageId,
1340
- sendStart,
1341
- sendFinish,
1342
- sendReasoning,
1343
- sendSources
1344
- })) {
1345
- writer.write(part);
1346
- }
1347
- }
1420
+ const uiMessageStream = await handleChatStream({
1421
+ mastra,
1422
+ agentId: agentToUse,
1423
+ params: {
1424
+ ...params,
1425
+ requestContext: contextRequestContext || params.requestContext
1426
+ },
1427
+ defaultOptions,
1428
+ sendStart,
1429
+ sendFinish,
1430
+ sendReasoning,
1431
+ sendSources
1348
1432
  });
1349
1433
  return ai.createUIMessageStreamResponse({
1350
1434
  stream: uiMessageStream
@@ -1352,9 +1436,31 @@ function chatRoute({
1352
1436
  }
1353
1437
  });
1354
1438
  }
1439
+ async function handleWorkflowStream({
1440
+ mastra,
1441
+ workflowId,
1442
+ params,
1443
+ includeTextStreamParts = true
1444
+ }) {
1445
+ const { runId, resourceId, inputData, resumeData, requestContext, ...rest } = params;
1446
+ const workflowObj = mastra.getWorkflowById(workflowId);
1447
+ if (!workflowObj) {
1448
+ throw new Error(`Workflow ${workflowId} not found`);
1449
+ }
1450
+ const run = await workflowObj.createRun({ runId, resourceId, ...rest });
1451
+ const stream = resumeData ? run.resumeStream({ resumeData, ...rest, requestContext }) : run.stream({ inputData, ...rest, requestContext });
1452
+ return ai.createUIMessageStream({
1453
+ execute: async ({ writer }) => {
1454
+ for await (const part of toAISdkV5Stream(stream, { from: "workflow", includeTextStreamParts })) {
1455
+ writer.write(part);
1456
+ }
1457
+ }
1458
+ });
1459
+ }
1355
1460
  function workflowRoute({
1356
1461
  path = "/api/workflows/:workflowId/stream",
1357
- workflow
1462
+ workflow,
1463
+ includeTextStreamParts = true
1358
1464
  }) {
1359
1465
  if (!workflow && !path.includes("/:workflowId")) {
1360
1466
  throw new Error("Path must include :workflowId to route to the correct workflow or pass the workflow explicitly");
@@ -1405,9 +1511,9 @@ function workflowRoute({
1405
1511
  }
1406
1512
  },
1407
1513
  handler: async (c) => {
1408
- const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
1514
+ const params = await c.req.json();
1409
1515
  const mastra = c.get("mastra");
1410
- const requestContext = c.get("requestContext");
1516
+ const contextRequestContext = c.get("requestContext");
1411
1517
  let workflowToUse = workflow;
1412
1518
  if (!workflow) {
1413
1519
  const workflowId = c.req.param("workflowId");
@@ -1421,28 +1527,47 @@ function workflowRoute({
1421
1527
  if (!workflowToUse) {
1422
1528
  throw new Error("Workflow ID is required");
1423
1529
  }
1424
- const workflowObj = mastra.getWorkflowById(workflowToUse);
1425
- if (!workflowObj) {
1426
- throw new Error(`Workflow ${workflowToUse} not found`);
1427
- }
1428
- if (requestContext && rest.requestContext) {
1530
+ if (contextRequestContext && params.requestContext) {
1429
1531
  mastra.getLogger()?.warn(
1430
1532
  `"requestContext" from the request body will be ignored because "requestContext" is already set in the route options.`
1431
1533
  );
1432
1534
  }
1433
- const run = await workflowObj.createRun({ runId, resourceId, ...rest });
1434
- const stream = resumeData ? run.resumeStream({ resumeData, ...rest, requestContext: requestContext || rest.requestContext }) : run.stream({ inputData, ...rest, requestContext: requestContext || rest.requestContext });
1435
- const uiMessageStream = ai.createUIMessageStream({
1436
- execute: async ({ writer }) => {
1437
- for await (const part of toAISdkV5Stream(stream, { from: "workflow" })) {
1438
- writer.write(part);
1439
- }
1440
- }
1535
+ const uiMessageStream = await handleWorkflowStream({
1536
+ mastra,
1537
+ workflowId: workflowToUse,
1538
+ params: {
1539
+ ...params,
1540
+ requestContext: contextRequestContext || params.requestContext
1541
+ },
1542
+ includeTextStreamParts
1441
1543
  });
1442
1544
  return ai.createUIMessageStreamResponse({ stream: uiMessageStream });
1443
1545
  }
1444
1546
  });
1445
1547
  }
1548
+ async function handleNetworkStream({
1549
+ mastra,
1550
+ agentId,
1551
+ params,
1552
+ defaultOptions
1553
+ }) {
1554
+ const { messages, ...rest } = params;
1555
+ const agentObj = mastra.getAgentById(agentId);
1556
+ if (!agentObj) {
1557
+ throw new Error(`Agent ${agentId} not found`);
1558
+ }
1559
+ const result = await agentObj.network(messages, {
1560
+ ...defaultOptions,
1561
+ ...rest
1562
+ });
1563
+ return ai.createUIMessageStream({
1564
+ execute: async ({ writer }) => {
1565
+ for await (const part of toAISdkV5Stream(result, { from: "network" })) {
1566
+ writer.write(part);
1567
+ }
1568
+ }
1569
+ });
1570
+ }
1446
1571
  function networkRoute({
1447
1572
  path = "/network/:agentId",
1448
1573
  agent,
@@ -1503,7 +1628,7 @@ function networkRoute({
1503
1628
  }
1504
1629
  },
1505
1630
  handler: async (c) => {
1506
- const { messages, ...rest } = await c.req.json();
1631
+ const params = await c.req.json();
1507
1632
  const mastra = c.get("mastra");
1508
1633
  let agentToUse = agent;
1509
1634
  if (!agent) {
@@ -1518,20 +1643,11 @@ function networkRoute({
1518
1643
  if (!agentToUse) {
1519
1644
  throw new Error("Agent ID is required");
1520
1645
  }
1521
- const agentObj = mastra.getAgentById(agentToUse);
1522
- if (!agentObj) {
1523
- throw new Error(`Agent ${agentToUse} not found`);
1524
- }
1525
- const result = await agentObj.network(messages, {
1526
- ...defaultOptions,
1527
- ...rest
1528
- });
1529
- const uiMessageStream = ai.createUIMessageStream({
1530
- execute: async ({ writer }) => {
1531
- for await (const part of toAISdkV5Stream(result, { from: "network" })) {
1532
- writer.write(part);
1533
- }
1534
- }
1646
+ const uiMessageStream = await handleNetworkStream({
1647
+ mastra,
1648
+ agentId: agentToUse,
1649
+ params,
1650
+ defaultOptions
1535
1651
  });
1536
1652
  return ai.createUIMessageStreamResponse({ stream: uiMessageStream });
1537
1653
  }
@@ -1546,6 +1662,9 @@ function toAISdkFormat() {
1546
1662
  }
1547
1663
 
1548
1664
  exports.chatRoute = chatRoute;
1665
+ exports.handleChatStream = handleChatStream;
1666
+ exports.handleNetworkStream = handleNetworkStream;
1667
+ exports.handleWorkflowStream = handleWorkflowStream;
1549
1668
  exports.networkRoute = networkRoute;
1550
1669
  exports.toAISdkFormat = toAISdkFormat;
1551
1670
  exports.toAISdkStream = toAISdkV5Stream;