@mastra/client-js 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256

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 (86) hide show
  1. package/CHANGELOG.md +3375 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +11 -13
  4. package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +820 -0
  5. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +10345 -0
  6. package/dist/client.d.ts +397 -75
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/docs/SKILL.md +44 -0
  9. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  10. package/dist/docs/references/docs-server-auth-auth0.md +220 -0
  11. package/dist/docs/references/docs-server-auth-clerk.md +132 -0
  12. package/dist/docs/references/docs-server-auth-firebase.md +272 -0
  13. package/dist/docs/references/docs-server-auth-jwt.md +110 -0
  14. package/dist/docs/references/docs-server-auth-supabase.md +117 -0
  15. package/dist/docs/references/docs-server-auth-workos.md +186 -0
  16. package/dist/docs/references/docs-server-mastra-client.md +243 -0
  17. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +231 -0
  18. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +79 -0
  19. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +76 -0
  20. package/dist/docs/references/reference-client-js-agents.md +437 -0
  21. package/dist/docs/references/reference-client-js-error-handling.md +16 -0
  22. package/dist/docs/references/reference-client-js-logs.md +24 -0
  23. package/dist/docs/references/reference-client-js-mastra-client.md +63 -0
  24. package/dist/docs/references/reference-client-js-memory.md +221 -0
  25. package/dist/docs/references/reference-client-js-observability.md +72 -0
  26. package/dist/docs/references/reference-client-js-telemetry.md +20 -0
  27. package/dist/docs/references/reference-client-js-tools.md +44 -0
  28. package/dist/docs/references/reference-client-js-vectors.md +79 -0
  29. package/dist/docs/references/reference-client-js-workflows.md +199 -0
  30. package/dist/index.cjs +4575 -1896
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +4875 -2193
  33. package/dist/index.js.map +1 -1
  34. package/dist/resources/a2a.d.ts.map +1 -1
  35. package/dist/resources/agent-builder.d.ts +55 -62
  36. package/dist/resources/agent-builder.d.ts.map +1 -1
  37. package/dist/resources/agent.d.ts +89 -51
  38. package/dist/resources/agent.d.ts.map +1 -1
  39. package/dist/resources/base.d.ts +2 -1
  40. package/dist/resources/base.d.ts.map +1 -1
  41. package/dist/resources/index.d.ts +9 -0
  42. package/dist/resources/index.d.ts.map +1 -1
  43. package/dist/resources/mcp-tool.d.ts +5 -5
  44. package/dist/resources/mcp-tool.d.ts.map +1 -1
  45. package/dist/resources/memory-thread.d.ts +31 -16
  46. package/dist/resources/memory-thread.d.ts.map +1 -1
  47. package/dist/resources/observability.d.ts +62 -19
  48. package/dist/resources/observability.d.ts.map +1 -1
  49. package/dist/resources/processor-provider.d.ts +15 -0
  50. package/dist/resources/processor-provider.d.ts.map +1 -0
  51. package/dist/resources/processor.d.ts +20 -0
  52. package/dist/resources/processor.d.ts.map +1 -0
  53. package/dist/resources/run.d.ts +210 -0
  54. package/dist/resources/run.d.ts.map +1 -0
  55. package/dist/resources/stored-agent.d.ts +83 -0
  56. package/dist/resources/stored-agent.d.ts.map +1 -0
  57. package/dist/resources/stored-mcp-client.d.ts +30 -0
  58. package/dist/resources/stored-mcp-client.d.ts.map +1 -0
  59. package/dist/resources/stored-prompt-block.d.ts +83 -0
  60. package/dist/resources/stored-prompt-block.d.ts.map +1 -0
  61. package/dist/resources/stored-scorer.d.ts +83 -0
  62. package/dist/resources/stored-scorer.d.ts.map +1 -0
  63. package/dist/resources/stored-skill.d.ts +30 -0
  64. package/dist/resources/stored-skill.d.ts.map +1 -0
  65. package/dist/resources/tool-provider.d.ts +27 -0
  66. package/dist/resources/tool-provider.d.ts.map +1 -0
  67. package/dist/resources/tool.d.ts +4 -4
  68. package/dist/resources/vector.d.ts +5 -5
  69. package/dist/resources/vector.d.ts.map +1 -1
  70. package/dist/resources/workflow.d.ts +32 -231
  71. package/dist/resources/workflow.d.ts.map +1 -1
  72. package/dist/resources/workspace.d.ts +125 -0
  73. package/dist/resources/workspace.d.ts.map +1 -0
  74. package/dist/tools.d.ts +2 -2
  75. package/dist/tools.d.ts.map +1 -1
  76. package/dist/types.d.ts +1673 -146
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/utils/index.d.ts +56 -4
  79. package/dist/utils/index.d.ts.map +1 -1
  80. package/dist/utils/process-mastra-stream.d.ts +1 -1
  81. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  82. package/dist/utils/zod-to-json-schema.d.ts +9 -1
  83. package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
  84. package/package.json +20 -18
  85. package/dist/resources/network-memory-thread.d.ts +0 -47
  86. package/dist/resources/network-memory-thread.d.ts.map +0 -1
@@ -0,0 +1,231 @@
1
+ # toAISdkStream()
2
+
3
+ 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()`.
4
+
5
+ This is useful when building custom streaming endpoints outside Mastra's provided route helpers such as [`chatRoute()`](https://mastra.ai/reference/ai-sdk/chat-route) or [`workflowRoute()`](https://mastra.ai/reference/ai-sdk/workflow-route).
6
+
7
+ ## Usage example
8
+
9
+ Next.js App Router example:
10
+
11
+ ```typescript
12
+ import { mastra } from '../../mastra'
13
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai'
14
+ import { toAISdkStream } from '@mastra/ai-sdk'
15
+
16
+ export async function POST(req: Request) {
17
+ const { messages } = await req.json()
18
+ const myAgent = mastra.getAgent('weatherAgent')
19
+ const stream = await myAgent.stream(messages)
20
+
21
+ const uiMessageStream = createUIMessageStream({
22
+ originalMessages: messages,
23
+ execute: async ({ writer }) => {
24
+ for await (const part of toAISdkStream(stream, { from: 'agent' })) {
25
+ await writer.write(part)
26
+ }
27
+ },
28
+ })
29
+
30
+ return createUIMessageStreamResponse({
31
+ stream: uiMessageStream,
32
+ })
33
+ }
34
+ ```
35
+
36
+ > **Tip:** 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.
37
+
38
+ ## Parameters
39
+
40
+ The first parameter is the Mastra stream to convert. It can be one of:
41
+
42
+ - `MastraModelOutput` - An agent stream from `agent.stream()`
43
+ - `MastraAgentNetworkStream` - A network stream from `agent.network()`
44
+ - `MastraWorkflowStream` or `WorkflowRunOutput` - A workflow stream
45
+
46
+ The second parameter is an options object:
47
+
48
+ **from:** (`'agent' | 'network' | 'workflow'`): The type of Mastra stream being converted. (Default: `'agent'`)
49
+
50
+ **lastMessageId?:** (`string`): (Agent only) The ID of the last message in the conversation.
51
+
52
+ **sendStart?:** (`boolean`): (Agent only) Whether to send start events in the stream. (Default: `true`)
53
+
54
+ **sendFinish?:** (`boolean`): (Agent only) Whether to send finish events in the stream. (Default: `true`)
55
+
56
+ **sendReasoning?:** (`boolean`): (Agent only) Whether to include reasoning-delta chunks in the stream. Set to true to stream reasoning content from models that support extended thinking. (Default: `false`)
57
+
58
+ **sendSources?:** (`boolean`): (Agent only) Whether to include source citations in the output. (Default: `false`)
59
+
60
+ **includeTextStreamParts?:** (`boolean`): (Workflow only) Whether to include text stream parts in the output. (Default: `true`)
61
+
62
+ **messageMetadata?:** (`(options: { part: UIMessageStreamPart }) => Record<string, unknown> | undefined`): (Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks.
63
+
64
+ **onError?:** (`(error: unknown) => string`): (Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation.
65
+
66
+ ## Examples
67
+
68
+ ### Converting a workflow stream
69
+
70
+ ```typescript
71
+ import { mastra } from '../../mastra'
72
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai'
73
+ import { toAISdkStream } from '@mastra/ai-sdk'
74
+
75
+ export async function POST(req: Request) {
76
+ const { input } = await req.json()
77
+ const workflow = mastra.getWorkflow('myWorkflow')
78
+ const run = workflow.createRun()
79
+ const stream = await run.stream({ inputData: input })
80
+
81
+ const uiMessageStream = createUIMessageStream({
82
+ execute: async ({ writer }) => {
83
+ for await (const part of toAISdkStream(stream, { from: 'workflow' })) {
84
+ await writer.write(part)
85
+ }
86
+ },
87
+ })
88
+
89
+ return createUIMessageStreamResponse({
90
+ stream: uiMessageStream,
91
+ })
92
+ }
93
+ ```
94
+
95
+ ### Converting a network stream
96
+
97
+ ```typescript
98
+ import { mastra } from '../../mastra'
99
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai'
100
+ import { toAISdkStream } from '@mastra/ai-sdk'
101
+
102
+ export async function POST(req: Request) {
103
+ const { messages } = await req.json()
104
+ const routingAgent = mastra.getAgent('routingAgent')
105
+ const stream = await routingAgent.network(messages)
106
+
107
+ const uiMessageStream = createUIMessageStream({
108
+ execute: async ({ writer }) => {
109
+ for await (const part of toAISdkStream(stream, { from: 'network' })) {
110
+ await writer.write(part)
111
+ }
112
+ },
113
+ })
114
+
115
+ return createUIMessageStreamResponse({
116
+ stream: uiMessageStream,
117
+ })
118
+ }
119
+ ```
120
+
121
+ ### Converting an agent stream with reasoning enabled
122
+
123
+ ```typescript
124
+ import { mastra } from '../../mastra'
125
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai'
126
+ import { toAISdkStream } from '@mastra/ai-sdk'
127
+
128
+ export async function POST(req: Request) {
129
+ const { messages } = await req.json()
130
+ const reasoningAgent = mastra.getAgent('reasoningAgent')
131
+ const stream = await reasoningAgent.stream(messages, {
132
+ providerOptions: {
133
+ openai: { reasoningEffort: 'high' },
134
+ },
135
+ })
136
+
137
+ const uiMessageStream = createUIMessageStream({
138
+ originalMessages: messages,
139
+ execute: async ({ writer }) => {
140
+ for await (const part of toAISdkStream(stream, {
141
+ from: 'agent',
142
+ sendReasoning: true,
143
+ })) {
144
+ await writer.write(part)
145
+ }
146
+ },
147
+ })
148
+
149
+ return createUIMessageStreamResponse({
150
+ stream: uiMessageStream,
151
+ })
152
+ }
153
+ ```
154
+
155
+ ### Using messageMetadata
156
+
157
+ ```typescript
158
+ import { mastra } from '../../mastra'
159
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai'
160
+ import { toAISdkStream } from '@mastra/ai-sdk'
161
+
162
+ export async function POST(req: Request) {
163
+ const { messages } = await req.json()
164
+ const myAgent = mastra.getAgent('weatherAgent')
165
+ const stream = await myAgent.stream(messages)
166
+
167
+ const uiMessageStream = createUIMessageStream({
168
+ originalMessages: messages,
169
+ execute: async ({ writer }) => {
170
+ for await (const part of toAISdkStream(stream, {
171
+ from: 'agent',
172
+ messageMetadata: ({ part }) => ({
173
+ timestamp: Date.now(),
174
+ partType: part.type,
175
+ }),
176
+ })) {
177
+ await writer.write(part)
178
+ }
179
+ },
180
+ })
181
+
182
+ return createUIMessageStreamResponse({
183
+ stream: uiMessageStream,
184
+ })
185
+ }
186
+ ```
187
+
188
+ ### Client-side stream transformation
189
+
190
+ If you're using the Mastra client SDK (`@mastra/client-js`) on the client side and want to convert streams to AI SDK format:
191
+
192
+ ```typescript
193
+ import { MastraClient } from '@mastra/client-js'
194
+ import { createUIMessageStream } from 'ai'
195
+ import { toAISdkStream } from '@mastra/ai-sdk'
196
+ import type { ChunkType, MastraModelOutput } from '@mastra/core/stream'
197
+
198
+ const client = new MastraClient({
199
+ baseUrl: 'http://localhost:4111',
200
+ })
201
+
202
+ const agent = client.getAgent('weatherAgent')
203
+ const response = await agent.stream('What is the weather in Tokyo?')
204
+
205
+ // Convert the client SDK stream to a ReadableStream<ChunkType>
206
+ const chunkStream = new ReadableStream<ChunkType>({
207
+ async start(controller) {
208
+ await response.processDataStream({
209
+ onChunk: async chunk => {
210
+ controller.enqueue(chunk)
211
+ },
212
+ })
213
+ controller.close()
214
+ },
215
+ })
216
+
217
+ // Transform to AI SDK format
218
+ const uiMessageStream = createUIMessageStream({
219
+ execute: async ({ writer }) => {
220
+ for await (const part of toAISdkStream(chunkStream as unknown as MastraModelOutput, {
221
+ from: 'agent',
222
+ })) {
223
+ await writer.write(part)
224
+ }
225
+ },
226
+ })
227
+
228
+ for await (const part of uiMessageStream) {
229
+ console.log(part)
230
+ }
231
+ ```
@@ -0,0 +1,79 @@
1
+ # toAISdkV4Messages()
2
+
3
+ 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()`.
4
+
5
+ ## Usage example
6
+
7
+ ```typescript
8
+ import { toAISdkV4Messages } from '@mastra/ai-sdk'
9
+ import { useChat } from 'ai/react' // AI SDK V4
10
+
11
+ // Stored messages from your database, memory or API
12
+ const storedMessages = [
13
+ { id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] },
14
+ { id: '2', role: 'assistant', parts: [{ type: 'text', text: 'Hi there!' }] },
15
+ ]
16
+
17
+ export default function Chat() {
18
+ const { messages } = useChat({
19
+ initialMessages: toAISdkV4Messages(storedMessages),
20
+ })
21
+
22
+ return (
23
+ <div>
24
+ {messages.map(message => (
25
+ <div key={message.id}>
26
+ {message.role}: {message.content}
27
+ </div>
28
+ ))}
29
+ </div>
30
+ )
31
+ }
32
+ ```
33
+
34
+ ## Parameters
35
+
36
+ **messages:** (`MessageListInput`): Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.
37
+
38
+ ## Returns
39
+
40
+ Returns an array of AI SDK V4 `UIMessage` objects with the following structure:
41
+
42
+ **id:** (`string`): Unique message identifier.
43
+
44
+ **role:** (`'user' | 'assistant' | 'system'`): The role of the message sender.
45
+
46
+ **content:** (`string`): Text content of the message.
47
+
48
+ **parts:** (`UIMessagePart[]`): Array of UI parts including text, tool-invocation, file, reasoning, source, and step markers.
49
+
50
+ **createdAt:** (`Date`): Message creation timestamp.
51
+
52
+ **toolInvocations?:** (`ToolInvocation[]`): Array of tool invocations for assistant messages.
53
+
54
+ **experimental\_attachments?:** (`Attachment[]`): File attachments on the message.
55
+
56
+ **metadata?:** (`Record<string, unknown>`): Custom metadata attached to the message.
57
+
58
+ ## Examples
59
+
60
+ ### Converting simple text messages
61
+
62
+ ```typescript
63
+ import { toAISdkV4Messages } from '@mastra/ai-sdk'
64
+
65
+ const messages = toAISdkV4Messages(['Hello', 'How can I help you today?'])
66
+ // Returns array of UIMessage objects with user role and content string
67
+ ```
68
+
69
+ ### Loading messages with Mastra client
70
+
71
+ ```typescript
72
+ import { MastraClient } from '@mastra/client-js'
73
+ import { toAISdkV4Messages } from '@mastra/ai-sdk'
74
+
75
+ const client = new MastraClient()
76
+
77
+ const { messages } = await client.listThreadMessages('thread-id', { agentId: 'myAgent' })
78
+ const uiMessages = toAISdkV4Messages(messages)
79
+ ```
@@ -0,0 +1,76 @@
1
+ # toAISdkV5Messages()
2
+
3
+ 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()`.
4
+
5
+ ## Usage example
6
+
7
+ ```typescript
8
+ import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
9
+ import { useChat } from 'ai/react'
10
+
11
+ // Stored messages from your database, memory or API
12
+ const storedMessages = [
13
+ { id: '1', role: 'user', content: 'Hello', parts: [{ type: 'text', text: 'Hello' }] },
14
+ {
15
+ id: '2',
16
+ role: 'assistant',
17
+ content: 'Hi there!',
18
+ parts: [{ type: 'text', text: 'Hi there!' }],
19
+ },
20
+ ]
21
+
22
+ export default function Chat() {
23
+ const { messages } = useChat({
24
+ initialMessages: toAISdkV5Messages(storedMessages),
25
+ })
26
+
27
+ return (
28
+ <div>
29
+ {messages.map(message => (
30
+ <div key={message.id}>
31
+ {message.role}: {message.parts.map(part => (part.type === 'text' ? part.text : null))}
32
+ </div>
33
+ ))}
34
+ </div>
35
+ )
36
+ }
37
+ ```
38
+
39
+ ## Parameters
40
+
41
+ **messages:** (`MessageListInput`): Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.
42
+
43
+ ## Returns
44
+
45
+ Returns an array of AI SDK V5+ `UIMessage` objects with the following structure:
46
+
47
+ **id:** (`string`): Unique message identifier.
48
+
49
+ **role:** (`'user' | 'assistant' | 'system'`): The role of the message sender.
50
+
51
+ **parts:** (`UIMessagePart[]`): Array of UI parts including text, tool results, files, reasoning, sources, and step markers.
52
+
53
+ **metadata?:** (`Record<string, unknown>`): Optional metadata including createdAt, threadId, resourceId, and custom fields.
54
+
55
+ ## Examples
56
+
57
+ ### Converting simple text messages
58
+
59
+ ```typescript
60
+ import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
61
+
62
+ const messages = toAISdkV5Messages(['Hello', 'How can I help you today?'])
63
+ // Returns array of UIMessage objects with user role
64
+ ```
65
+
66
+ ### Loading messages with Mastra client
67
+
68
+ ```typescript
69
+ import { MastraClient } from '@mastra/client-js'
70
+ import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
71
+
72
+ const client = new MastraClient()
73
+
74
+ const { messages } = await client.listThreadMessages('thread-id', { agentId: 'myAgent' })
75
+ const uiMessages = toAISdkV5Messages(messages)
76
+ ```