@mastra/client-js 1.0.0-beta.9 → 1.0.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1638 -0
  2. package/README.md +1 -3
  3. package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +820 -0
  4. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +8511 -0
  5. package/dist/client.d.ts +56 -11
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/docs/README.md +33 -0
  8. package/dist/docs/SKILL.md +34 -0
  9. package/dist/docs/SOURCE_MAP.json +6 -0
  10. package/dist/docs/ai-sdk/01-reference.md +358 -0
  11. package/dist/docs/client-js/01-reference.md +1180 -0
  12. package/dist/docs/server/01-mastra-client.md +256 -0
  13. package/dist/docs/server/02-jwt.md +99 -0
  14. package/dist/docs/server/03-clerk.md +143 -0
  15. package/dist/docs/server/04-supabase.md +128 -0
  16. package/dist/docs/server/05-firebase.md +286 -0
  17. package/dist/docs/server/06-workos.md +201 -0
  18. package/dist/docs/server/07-auth0.md +233 -0
  19. package/dist/index.cjs +1690 -596
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +1688 -594
  22. package/dist/index.js.map +1 -1
  23. package/dist/resources/agent-builder.d.ts +10 -26
  24. package/dist/resources/agent-builder.d.ts.map +1 -1
  25. package/dist/resources/agent.d.ts +43 -8
  26. package/dist/resources/agent.d.ts.map +1 -1
  27. package/dist/resources/index.d.ts +1 -0
  28. package/dist/resources/index.d.ts.map +1 -1
  29. package/dist/resources/memory-thread.d.ts +18 -3
  30. package/dist/resources/memory-thread.d.ts.map +1 -1
  31. package/dist/resources/observability.d.ts +58 -15
  32. package/dist/resources/observability.d.ts.map +1 -1
  33. package/dist/resources/processor.d.ts +20 -0
  34. package/dist/resources/processor.d.ts.map +1 -0
  35. package/dist/resources/run.d.ts +210 -0
  36. package/dist/resources/run.d.ts.map +1 -0
  37. package/dist/resources/workflow.d.ts +19 -224
  38. package/dist/resources/workflow.d.ts.map +1 -1
  39. package/dist/tools.d.ts +2 -2
  40. package/dist/tools.d.ts.map +1 -1
  41. package/dist/types.d.ts +141 -36
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/utils/index.d.ts +26 -0
  44. package/dist/utils/index.d.ts.map +1 -1
  45. package/package.json +13 -12
package/dist/client.d.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import type { ListScoresResponse } from '@mastra/core/evals';
1
2
  import type { ServerDetailInfo } from '@mastra/core/mcp';
2
3
  import type { RequestContext } from '@mastra/core/request-context';
3
- import type { TraceRecord, TracesPaginatedArg } from '@mastra/core/storage';
4
+ import type { TraceRecord, ListTracesArgs, ListTracesResponse } from '@mastra/core/storage';
4
5
  import type { WorkflowInfo } from '@mastra/core/workflows';
5
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, A2A, MCPTool, AgentBuilder, StoredAgent } from './resources/index.js';
6
- import type { ClientOptions, CreateMemoryThreadParams, CreateMemoryThreadResponse, GetAgentResponse, GetLogParams, GetLogsParams, GetLogsResponse, GetToolResponse, GetWorkflowResponse, SaveMessageToMemoryParams, SaveMessageToMemoryResponse, McpServerListResponse, McpServerToolListResponse, GetScorerResponse, ListScoresByScorerIdParams, ListScoresResponse, ListScoresByRunIdParams, ListScoresByEntityIdParams, ListScoresBySpanParams, SaveScoreParams, SaveScoreResponse, GetTracesResponse, GetMemoryConfigParams, GetMemoryConfigResponse, ListMemoryThreadMessagesResponse, MemorySearchResponse, ListAgentsModelProvidersResponse, ListMemoryThreadsParams, ListMemoryThreadsResponse, ListStoredAgentsParams, ListStoredAgentsResponse, CreateStoredAgentParams, StoredAgentResponse } from './types.js';
6
+ import { Agent, MemoryThread, Tool, Processor, Workflow, Vector, BaseResource, A2A, MCPTool, AgentBuilder, StoredAgent } from './resources/index.js';
7
+ import type { ListScoresBySpanParams, LegacyTracesPaginatedArg, LegacyGetTracesResponse } from './resources/observability.js';
8
+ import type { ClientOptions, CreateMemoryThreadParams, CreateMemoryThreadResponse, GetAgentResponse, GetLogParams, GetLogsParams, GetLogsResponse, GetToolResponse, GetProcessorResponse, GetWorkflowResponse, SaveMessageToMemoryParams, SaveMessageToMemoryResponse, McpServerListResponse, McpServerToolListResponse, GetScorerResponse, ListScoresByScorerIdParams, ListScoresByRunIdParams, ListScoresByEntityIdParams, SaveScoreParams, SaveScoreResponse, GetMemoryConfigParams, GetMemoryConfigResponse, ListMemoryThreadMessagesResponse, MemorySearchResponse, ListAgentsModelProvidersResponse, ListMemoryThreadsParams, ListMemoryThreadsResponse, ListStoredAgentsParams, ListStoredAgentsResponse, CreateStoredAgentParams, StoredAgentResponse, GetSystemPackagesResponse, ListScoresResponse as ListScoresResponseOld } from './types.js';
7
9
  export declare class MastraClient extends BaseResource {
8
10
  private observability;
9
11
  constructor(options: ClientOptions);
@@ -21,11 +23,11 @@ export declare class MastraClient extends BaseResource {
21
23
  */
22
24
  getAgent(agentId: string): Agent;
23
25
  /**
24
- * Lists memory threads for a resource with pagination support
25
- * @param params - Parameters containing resource ID, pagination options, and optional request context
26
+ * Lists memory threads with optional filtering by resourceId and/or metadata
27
+ * @param params - Parameters containing optional filters, pagination options, and request context
26
28
  * @returns Promise containing paginated array of memory threads with metadata
27
29
  */
28
- listMemoryThreads(params: ListMemoryThreadsParams): Promise<ListMemoryThreadsResponse>;
30
+ listMemoryThreads(params?: ListMemoryThreadsParams): Promise<ListMemoryThreadsResponse>;
29
31
  /**
30
32
  * Retrieves memory config for a resource
31
33
  * @param params - Parameters containing the resource ID and optional request context
@@ -41,12 +43,22 @@ export declare class MastraClient extends BaseResource {
41
43
  /**
42
44
  * Gets a memory thread instance by ID
43
45
  * @param threadId - ID of the memory thread to retrieve
46
+ * @param agentId - Optional agent ID. When not provided, uses storage directly
44
47
  * @returns MemoryThread instance
45
48
  */
46
49
  getMemoryThread({ threadId, agentId }: {
47
50
  threadId: string;
48
- agentId: string;
51
+ agentId?: string;
49
52
  }): MemoryThread;
53
+ /**
54
+ * Lists messages for a thread.
55
+ * @param threadId - ID of the thread
56
+ * @param opts - Optional parameters including agentId, networkId, and requestContext
57
+ * - When agentId is provided, uses the agent's memory
58
+ * - When networkId is provided, uses the network endpoint
59
+ * - When neither is provided, uses storage directly
60
+ * @returns Promise containing the thread messages
61
+ */
50
62
  listThreadMessages(threadId: string, opts?: {
51
63
  agentId?: string;
52
64
  networkId?: string;
@@ -87,6 +99,18 @@ export declare class MastraClient extends BaseResource {
87
99
  * @returns Tool instance
88
100
  */
89
101
  getTool(toolId: string): Tool;
102
+ /**
103
+ * Retrieves all available processors
104
+ * @param requestContext - Optional request context to pass as query parameter
105
+ * @returns Promise containing map of processor IDs to processor details
106
+ */
107
+ listProcessors(requestContext?: RequestContext | Record<string, any>): Promise<Record<string, GetProcessorResponse>>;
108
+ /**
109
+ * Gets a processor instance by ID
110
+ * @param processorId - ID of the processor to retrieve
111
+ * @returns Processor instance
112
+ */
113
+ getProcessor(processorId: string): Processor;
90
114
  /**
91
115
  * Retrieves all available workflows
92
116
  * @param requestContext - Optional request context to pass as query parameter
@@ -222,19 +246,19 @@ export declare class MastraClient extends BaseResource {
222
246
  * @returns Promise containing the scorer
223
247
  */
224
248
  getScorer(scorerId: string): Promise<GetScorerResponse>;
225
- listScoresByScorerId(params: ListScoresByScorerIdParams): Promise<ListScoresResponse>;
249
+ listScoresByScorerId(params: ListScoresByScorerIdParams): Promise<ListScoresResponseOld>;
226
250
  /**
227
251
  * Retrieves scores by run ID
228
252
  * @param params - Parameters containing run ID and pagination options
229
253
  * @returns Promise containing scores and pagination info
230
254
  */
231
- listScoresByRunId(params: ListScoresByRunIdParams): Promise<ListScoresResponse>;
255
+ listScoresByRunId(params: ListScoresByRunIdParams): Promise<ListScoresResponseOld>;
232
256
  /**
233
257
  * Retrieves scores by entity ID and type
234
258
  * @param params - Parameters containing entity ID, type, and pagination options
235
259
  * @returns Promise containing scores and pagination info
236
260
  */
237
- listScoresByEntityId(params: ListScoresByEntityIdParams): Promise<ListScoresResponse>;
261
+ listScoresByEntityId(params: ListScoresByEntityIdParams): Promise<ListScoresResponseOld>;
238
262
  /**
239
263
  * Saves a score
240
264
  * @param params - Parameters containing the score data to save
@@ -242,7 +266,23 @@ export declare class MastraClient extends BaseResource {
242
266
  */
243
267
  saveScore(params: SaveScoreParams): Promise<SaveScoreResponse>;
244
268
  getTrace(traceId: string): Promise<TraceRecord>;
245
- getTraces(params: TracesPaginatedArg): Promise<GetTracesResponse>;
269
+ /**
270
+ * Retrieves paginated list of traces with optional filtering.
271
+ * This is the legacy API preserved for backward compatibility.
272
+ *
273
+ * @param params - Parameters for pagination and filtering (legacy format)
274
+ * @returns Promise containing paginated traces and pagination info
275
+ * @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
276
+ */
277
+ getTraces(params: LegacyTracesPaginatedArg): Promise<LegacyGetTracesResponse>;
278
+ /**
279
+ * Retrieves paginated list of traces with optional filtering and sorting.
280
+ * This is the new API with improved filtering options.
281
+ *
282
+ * @param params - Parameters for pagination, filtering, and ordering
283
+ * @returns Promise containing paginated traces and pagination info
284
+ */
285
+ listTraces(params?: ListTracesArgs): Promise<ListTracesResponse>;
246
286
  listScoresBySpan(params: ListScoresBySpanParams): Promise<ListScoresResponse>;
247
287
  score(params: {
248
288
  scorerName: string;
@@ -272,5 +312,10 @@ export declare class MastraClient extends BaseResource {
272
312
  * @returns StoredAgent instance
273
313
  */
274
314
  getStoredAgent(storedAgentId: string): StoredAgent;
315
+ /**
316
+ * Retrieves installed Mastra packages and their versions
317
+ * @returns Promise containing the list of installed Mastra packages
318
+ */
319
+ getSystemPackages(): Promise<GetSystemPackagesResponse>;
275
320
  }
276
321
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAA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WAAW,CAAC;IAI/C;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAI7E;;;;;;OAMG;IACH,UAAU,CAAC,MAAM,GAAE,cAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIpE,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI7E,KAAK,CAAC,MAAM,EAAE;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,KAAK,CAAC;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACtD,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAQhD;;;;OAIG;IACI,gBAAgB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAsB3F;;;;OAIG;IACI,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAOvF;;;;OAIG;IACI,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW;IAQzD;;;OAGG;IACI,iBAAiB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAG/D"}
@@ -0,0 +1,33 @@
1
+ # @mastra/client-js Documentation
2
+
3
+ > Embedded documentation for coding agents
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Read the skill overview
9
+ cat docs/SKILL.md
10
+
11
+ # Get the source map
12
+ cat docs/SOURCE_MAP.json
13
+
14
+ # Read topic documentation
15
+ cat docs/<topic>/01-overview.md
16
+ ```
17
+
18
+ ## Structure
19
+
20
+ ```
21
+ docs/
22
+ ├── SKILL.md # Entry point
23
+ ├── README.md # This file
24
+ ├── SOURCE_MAP.json # Export index
25
+ ├── ai-sdk/ (3 files)
26
+ ├── client-js/ (10 files)
27
+ ├── server/ (7 files)
28
+ ```
29
+
30
+ ## Version
31
+
32
+ Package: @mastra/client-js
33
+ Version: 1.0.0
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: mastra-client-js-docs
3
+ description: Documentation for @mastra/client-js. Includes links to type definitions and readable implementation code in dist/.
4
+ ---
5
+
6
+ # @mastra/client-js Documentation
7
+
8
+ > **Version**: 1.0.0
9
+ > **Package**: @mastra/client-js
10
+
11
+ ## Quick Navigation
12
+
13
+ Use SOURCE_MAP.json to find any export:
14
+
15
+ ```bash
16
+ cat docs/SOURCE_MAP.json
17
+ ```
18
+
19
+ Each export maps to:
20
+ - **types**: `.d.ts` file with JSDoc and API signatures
21
+ - **implementation**: `.js` chunk file with readable source
22
+ - **docs**: Conceptual documentation in `docs/`
23
+
24
+ ## Top Exports
25
+
26
+
27
+
28
+ See SOURCE_MAP.json for the complete list.
29
+
30
+ ## Available Topics
31
+
32
+ - [Ai sdk](ai-sdk/) - 3 file(s)
33
+ - [Client js](client-js/) - 10 file(s)
34
+ - [Server](server/) - 7 file(s)
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "package": "@mastra/client-js",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,358 @@
1
+ # Ai sdk API Reference
2
+
3
+ > API reference for ai sdk - 3 entries
4
+
5
+
6
+ ---
7
+
8
+ ## Reference: toAISdkStream()
9
+
10
+ > API reference for toAISdkStream(), a function to convert Mastra streams to AI SDK-compatible streams.
11
+
12
+ Converts Mastra streams (agent, network, or workflow) to AI SDK-compatible streams. Use this function when you need to manually transform Mastra streams for use with AI SDK's `createUIMessageStream()` and `createUIMessageStreamResponse()`.
13
+
14
+ This is useful when building custom streaming endpoints outside Mastra's provided route helpers such as [`chatRoute()`](https://mastra.ai/reference/v1/ai-sdk/chat-route) or [`workflowRoute()`](https://mastra.ai/reference/v1/ai-sdk/workflow-route).
15
+
16
+ ## Usage example
17
+
18
+ Next.js App Router example:
19
+
20
+ ```typescript title="app/api/chat/route.ts"
21
+ import { mastra } from "../../mastra";
22
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
23
+ import { toAISdkStream } from "@mastra/ai-sdk";
24
+
25
+ export async function POST(req: Request) {
26
+ const { messages } = await req.json();
27
+ const myAgent = mastra.getAgent("weatherAgent");
28
+ const stream = await myAgent.stream(messages);
29
+
30
+ const uiMessageStream = createUIMessageStream({
31
+ originalMessages: messages,
32
+ execute: async ({ writer }) => {
33
+ for await (const part of toAISdkStream(stream, { from: "agent" })) {
34
+ await writer.write(part);
35
+ }
36
+ },
37
+ });
38
+
39
+ return createUIMessageStreamResponse({
40
+ stream: uiMessageStream,
41
+ });
42
+ }
43
+ ```
44
+
45
+ > **Note:**
46
+
47
+ Pass `messages` to `originalMessages` in `createUIMessageStream()` to avoid duplicated assistant messages in the UI. See [Troubleshooting: Repeated Assistant Messages](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) for details.
48
+
49
+ ## Parameters
50
+
51
+ The first parameter is the Mastra stream to convert. It can be one of:
52
+ - `MastraModelOutput` - An agent stream from `agent.stream()`
53
+ - `MastraAgentNetworkStream` - A network stream from `agent.network()`
54
+ - `MastraWorkflowStream` or `WorkflowRunOutput` - A workflow stream
55
+
56
+ The second parameter is an options object:
57
+
58
+ ## Examples
59
+
60
+ ### Converting a workflow stream
61
+
62
+ ```typescript title="app/api/workflow/route.ts" {13}
63
+ import { mastra } from "../../mastra";
64
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
65
+ import { toAISdkStream } from "@mastra/ai-sdk";
66
+
67
+ export async function POST(req: Request) {
68
+ const { input } = await req.json();
69
+ const workflow = mastra.getWorkflow("myWorkflow");
70
+ const run = workflow.createRun();
71
+ const stream = await run.stream({ inputData: input });
72
+
73
+ const uiMessageStream = createUIMessageStream({
74
+ execute: async ({ writer }) => {
75
+ for await (const part of toAISdkStream(stream, { from: "workflow" })) {
76
+ await writer.write(part);
77
+ }
78
+ },
79
+ });
80
+
81
+ return createUIMessageStreamResponse({
82
+ stream: uiMessageStream,
83
+ });
84
+ }
85
+ ```
86
+
87
+ ### Converting a network stream
88
+
89
+ ```typescript title="app/api/network/route.ts" {12}
90
+ import { mastra } from "../../mastra";
91
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
92
+ import { toAISdkStream } from "@mastra/ai-sdk";
93
+
94
+ export async function POST(req: Request) {
95
+ const { messages } = await req.json();
96
+ const routingAgent = mastra.getAgent("routingAgent");
97
+ const stream = await routingAgent.network(messages);
98
+
99
+ const uiMessageStream = createUIMessageStream({
100
+ execute: async ({ writer }) => {
101
+ for await (const part of toAISdkStream(stream, { from: "network" })) {
102
+ await writer.write(part);
103
+ }
104
+ },
105
+ });
106
+
107
+ return createUIMessageStreamResponse({
108
+ stream: uiMessageStream,
109
+ });
110
+ }
111
+ ```
112
+
113
+ ### Converting an agent stream with reasoning enabled
114
+
115
+ ```typescript title="app/api/reasoning/route.ts" {8-12,17-20}
116
+ import { mastra } from "../../mastra";
117
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
118
+ import { toAISdkStream } from "@mastra/ai-sdk";
119
+
120
+ export async function POST(req: Request) {
121
+ const { messages } = await req.json();
122
+ const reasoningAgent = mastra.getAgent("reasoningAgent");
123
+ const stream = await reasoningAgent.stream(messages, {
124
+ providerOptions: {
125
+ openai: { reasoningEffort: "high" },
126
+ },
127
+ });
128
+
129
+ const uiMessageStream = createUIMessageStream({
130
+ originalMessages: messages,
131
+ execute: async ({ writer }) => {
132
+ for await (const part of toAISdkStream(stream, {
133
+ from: "agent",
134
+ sendReasoning: true,
135
+ })) {
136
+ await writer.write(part);
137
+ }
138
+ },
139
+ });
140
+
141
+ return createUIMessageStreamResponse({
142
+ stream: uiMessageStream,
143
+ });
144
+ }
145
+ ```
146
+
147
+ ### Using messageMetadata
148
+
149
+ ```typescript title="app/api/chat-with-metadata/route.ts" {13-19}
150
+ import { mastra } from "../../mastra";
151
+ import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
152
+ import { toAISdkStream } from "@mastra/ai-sdk";
153
+
154
+ export async function POST(req: Request) {
155
+ const { messages } = await req.json();
156
+ const myAgent = mastra.getAgent("weatherAgent");
157
+ const stream = await myAgent.stream(messages);
158
+
159
+ const uiMessageStream = createUIMessageStream({
160
+ originalMessages: messages,
161
+ execute: async ({ writer }) => {
162
+ for await (const part of toAISdkStream(stream, {
163
+ from: "agent",
164
+ messageMetadata: ({ part }) => ({
165
+ timestamp: Date.now(),
166
+ partType: part.type,
167
+ }),
168
+ })) {
169
+ await writer.write(part);
170
+ }
171
+ },
172
+ });
173
+
174
+ return createUIMessageStreamResponse({
175
+ stream: uiMessageStream,
176
+ });
177
+ }
178
+ ```
179
+
180
+ ### Client-side stream transformation
181
+
182
+ If you're using the Mastra client SDK (`@mastra/client-js`) on the client side and want to convert streams to AI SDK format:
183
+
184
+ ```typescript title="client-stream-to-ai-sdk.ts" {14-23,25-35}
185
+ import { MastraClient } from "@mastra/client-js";
186
+ import { createUIMessageStream } from "ai";
187
+ import { toAISdkStream } from "@mastra/ai-sdk";
188
+ import type { ChunkType, MastraModelOutput } from "@mastra/core/stream";
189
+
190
+ const client = new MastraClient({
191
+ baseUrl: "http://localhost:4111",
192
+ });
193
+
194
+ const agent = client.getAgent("weatherAgent");
195
+ const response = await agent.stream("What is the weather in Tokyo?");
196
+
197
+ // Convert the client SDK stream to a ReadableStream<ChunkType>
198
+ const chunkStream = new ReadableStream<ChunkType>({
199
+ async start(controller) {
200
+ await response.processDataStream({
201
+ onChunk: async (chunk) => {
202
+ controller.enqueue(chunk);
203
+ },
204
+ });
205
+ controller.close();
206
+ },
207
+ });
208
+
209
+ // Transform to AI SDK format
210
+ const uiMessageStream = createUIMessageStream({
211
+ execute: async ({ writer }) => {
212
+ for await (const part of toAISdkStream(
213
+ chunkStream as unknown as MastraModelOutput,
214
+ { from: "agent" }
215
+ )) {
216
+ await writer.write(part);
217
+ }
218
+ },
219
+ });
220
+
221
+ for await (const part of uiMessageStream) {
222
+ console.log(part);
223
+ }
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Reference: toAISdkV4Messages()
229
+
230
+ > API reference for toAISdkV4Messages(), a function to convert Mastra messages to AI SDK v4 UI messages.
231
+
232
+ Converts messages from various input formats to AI SDK V4 UI message format. 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 UI components like `useChat()`.
233
+
234
+ ## Usage example
235
+
236
+ ```typescript title="app/chat/page.tsx"
237
+ import { toAISdkV4Messages } from "@mastra/ai-sdk";
238
+ import { useChat } from "ai/react"; // AI SDK V4
239
+
240
+ // Stored messages from your database, memory or API
241
+ const storedMessages = [
242
+ { id: "1", role: "user", parts: [{ type: "text", text: "Hello" }] },
243
+ { id: "2", role: "assistant", parts: [{ type: "text", text: "Hi there!" }] }
244
+ ];
245
+
246
+ export default function Chat() {
247
+ const { messages } = useChat({
248
+ initialMessages: toAISdkV4Messages(storedMessages)
249
+ });
250
+
251
+ return (
252
+ <div>
253
+ {messages.map((message) => (
254
+ <div key={message.id}>
255
+ {message.role}: {message.content}
256
+ </div>
257
+ ))}
258
+ </div>
259
+ );
260
+ }
261
+ ```
262
+
263
+ ## Parameters
264
+
265
+ ## Returns
266
+
267
+ Returns an array of AI SDK V4 `UIMessage` objects with the following structure:
268
+
269
+ ## Examples
270
+
271
+ ### Converting simple text messages
272
+
273
+ ```typescript
274
+ import { toAISdkV4Messages } from "@mastra/ai-sdk";
275
+
276
+ const messages = toAISdkV4Messages(["Hello", "How can I help you today?"]);
277
+ // Returns array of UIMessage objects with user role and content string
278
+ ```
279
+
280
+ ### Loading messages with Mastra client
281
+
282
+ ```typescript
283
+ import { MastraClient } from "@mastra/client-js";
284
+ import { toAISdkV4Messages } from "@mastra/ai-sdk";
285
+
286
+ const client = new MastraClient();
287
+
288
+ const { messages } = await client.listThreadMessages("thread-id", { agentId: "myAgent" });
289
+ const uiMessages = toAISdkV4Messages(messages);
290
+ ```
291
+
292
+ ---
293
+
294
+ ## Reference: toAISdkV5Messages()
295
+
296
+ > API reference for toAISdkV5Messages(), a function to convert Mastra messages to AI SDK v5 UI messages.
297
+
298
+ Converts messages from various input formats to AI SDK V5 (and later) UI message format. 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 UI components like `useChat()`.
299
+
300
+ ## Usage example
301
+
302
+ ```typescript title="app/chat/page.tsx"
303
+ import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
304
+ import { useChat } from "ai/react";
305
+
306
+ // Stored messages from your database, memory or API
307
+ const storedMessages = [
308
+ { id: "1", role: "user", content: "Hello", parts: [{ type: "text", text: "Hello" }] },
309
+ { id: "2", role: "assistant", content: "Hi there!", parts: [{ type: "text", text: "Hi there!" }] }
310
+ ];
311
+
312
+ export default function Chat() {
313
+ const { messages } = useChat({
314
+ initialMessages: toAISdkV5Messages(storedMessages)
315
+ });
316
+
317
+ return (
318
+ <div>
319
+ {messages.map((message) => (
320
+ <div key={message.id}>
321
+ {message.role}: {message.parts.map(part =>
322
+ part.type === "text" ? part.text : null
323
+ )}
324
+ </div>
325
+ ))}
326
+ </div>
327
+ );
328
+ }
329
+ ```
330
+
331
+ ## Parameters
332
+
333
+ ## Returns
334
+
335
+ Returns an array of AI SDK V5+ `UIMessage` objects with the following structure:
336
+
337
+ ## Examples
338
+
339
+ ### Converting simple text messages
340
+
341
+ ```typescript
342
+ import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
343
+
344
+ const messages = toAISdkV5Messages(["Hello", "How can I help you today?"]);
345
+ // Returns array of UIMessage objects with user role
346
+ ```
347
+
348
+ ### Loading messages with Mastra client
349
+
350
+ ```typescript
351
+ import { MastraClient } from "@mastra/client-js";
352
+ import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
353
+
354
+ const client = new MastraClient();
355
+
356
+ const { messages } = await client.listThreadMessages("thread-id", { agentId: "myAgent" });
357
+ const uiMessages = toAISdkV5Messages(messages);
358
+ ```