@mastra/mcp-docs-server 0.13.26 → 0.13.27
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/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Freact.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
- package/.docs/organized/changelogs/create-mastra.md +47 -47
- package/.docs/organized/changelogs/mastra.md +63 -63
- package/.docs/organized/code-examples/agent.md +19 -14
- package/.docs/organized/code-examples/heads-up-game.md +5 -5
- package/.docs/raw/agents/agent-memory.mdx +86 -125
- package/.docs/raw/agents/input-processors.mdx +3 -3
- package/.docs/raw/agents/output-processors.mdx +4 -4
- package/.docs/raw/agents/overview.mdx +11 -52
- package/.docs/raw/agents/using-tools-and-mcp.mdx +34 -29
- package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +18 -0
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +4 -8
- package/.docs/raw/getting-started/installation.mdx +2 -3
- package/.docs/raw/getting-started/model-providers.mdx +28 -123
- package/.docs/raw/memory/semantic-recall.mdx +1 -1
- package/.docs/raw/reference/agents/agent.mdx +1 -1
- package/.docs/raw/reference/agents/generate.mdx +255 -218
- package/.docs/raw/reference/agents/generateLegacy.mdx +528 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -4
- package/.docs/raw/reference/agents/migration-guide.mdx +291 -0
- package/.docs/raw/reference/client-js/agents.mdx +14 -8
- package/.docs/raw/reference/deployer/vercel.mdx +26 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +4 -4
- package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +13 -13
- package/.docs/raw/reference/streaming/agents/stream.mdx +351 -178
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +515 -0
- package/.docs/raw/reference/{rag → vectors}/astra.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/chroma.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/couchbase.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/lance.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/libsql.mdx +2 -4
- package/.docs/raw/reference/{rag → vectors}/mongodb.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/opensearch.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pg.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pinecone.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/qdrant.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/s3vectors.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/turbopuffer.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/upstash.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/vectorize.mdx +2 -2
- package/.docs/raw/streaming/events.mdx +4 -4
- package/.docs/raw/streaming/overview.mdx +9 -11
- package/.docs/raw/streaming/tool-streaming.mdx +3 -3
- package/.docs/raw/streaming/workflow-streaming.mdx +3 -3
- package/CHANGELOG.md +16 -0
- package/package.json +5 -5
- package/.docs/organized/code-examples/agent-network.md +0 -322
- package/.docs/raw/getting-started/model-capability.mdx +0 -11
- package/.docs/raw/reference/agents/generateVNext.mdx +0 -557
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +0 -67
- package/.docs/raw/reference/streaming/agents/streamVNext.mdx +0 -673
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# Migration Guide: VNext to Standard APIs
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
As of `v 0.20.00`, the `streamVNext()` and `generateVNext()` methods in Mastra agents have been renamed to `stream()` and `generate()` respectively. These are now the standard APIs with full AI SDK v5 compatibility. The original `stream()` and `generate()` methods have been renamed to `streamLegacy()` and `generateLegacy()` to maintain backward compatibility with AI SDK v4.
|
|
6
|
+
|
|
7
|
+
### Continue using AI SDK v4 models
|
|
8
|
+
- Rename all your `stream()` and `generate()` calls to `streamLegacy()` and `generateLegacy()` respectively. No other change is needed.
|
|
9
|
+
|
|
10
|
+
### Continue using AI SDK v5 models
|
|
11
|
+
- Rename all your `streamVNext()` and `generateVNext()` calls to `stream()` and `generate()` respectively. No other change is needed.
|
|
12
|
+
|
|
13
|
+
### Upgrade from AI SDK v4 models to v5 models
|
|
14
|
+
|
|
15
|
+
First bump all your model provider packages by a major version. This will ensure that they are all v5 models now. Follow the guide below to understand the differences.
|
|
16
|
+
|
|
17
|
+
## Key Differences
|
|
18
|
+
|
|
19
|
+
### 1. Model version support
|
|
20
|
+
|
|
21
|
+
- **Legacy APIs (`generateLegacy`, `streamLegacy`)**: Only support AI SDK v4 models (specificationVersion: 'v1')
|
|
22
|
+
- **Current APIs (`generate`, `stream`)**: Only support AI SDK v5 models (specificationVersion: 'v2')
|
|
23
|
+
- This is enforced at runtime with clear error messages
|
|
24
|
+
|
|
25
|
+
### 2. Return types
|
|
26
|
+
|
|
27
|
+
#### Legacy methods return AI SDK v4 types
|
|
28
|
+
|
|
29
|
+
- **`generateLegacy()`**:
|
|
30
|
+
- `GenerateTextResult` or `GenerateObjectResult`
|
|
31
|
+
|
|
32
|
+
- **`streamLegacy()`**:
|
|
33
|
+
- `StreamTextResult` or `StreamObjectResult`
|
|
34
|
+
|
|
35
|
+
#### New stream methods return Mastra/AI SDK v5 types
|
|
36
|
+
|
|
37
|
+
- **`generate()`**:
|
|
38
|
+
- When `format: 'mastra'` (default): Returns `MastraModelOutput.getFullOutput()` result
|
|
39
|
+
- When `format: 'aisdk'`: Returns `AISDKV5OutputStream.getFullOutput()` result (AI SDK v5 compatible)
|
|
40
|
+
- Internally calls `stream()` and awaits `getFullOutput()`
|
|
41
|
+
|
|
42
|
+
- **`stream()`**:
|
|
43
|
+
- When `format: 'mastra'` (default): Returns `MastraModelOutput<OUTPUT>`
|
|
44
|
+
- When `format: 'aisdk'`: Returns `AISDKV5OutputStream<OUTPUT>` (AI SDK v5 compatible)
|
|
45
|
+
|
|
46
|
+
#### Format Control
|
|
47
|
+
|
|
48
|
+
- **Legacy**: No format control, always returns AI SDK v4 types
|
|
49
|
+
- **New stream**: Can choose format via `format` option ('mastra' or 'aisdk')
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Mastra native format (default)
|
|
53
|
+
const result = await agent.stream(messages, {
|
|
54
|
+
format: 'mastra'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// AI SDK v5 compatibility
|
|
58
|
+
const result = await agent.stream(messages, {
|
|
59
|
+
format: 'aisdk'
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. New Options in Non-Legacy APIs
|
|
64
|
+
|
|
65
|
+
The following options are available in `stream()` and `generate()` but NOT in their legacy counterparts:
|
|
66
|
+
|
|
67
|
+
1. **`format`** - Choose between 'mastra' or 'aisdk' output format
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const result = await agent.stream(messages, {
|
|
71
|
+
format: 'aisdk' // or 'mastra' (default)
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
2. **`system`** - Custom system message (separate from instructions)
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const result = await agent.stream(messages, {
|
|
79
|
+
system: 'You are a helpful assistant'
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
3. **`structuredOutput`** - Enhanced structured output with model override and custom options
|
|
84
|
+
|
|
85
|
+
- If no model is added it will use the agent's default model.
|
|
86
|
+
- Error strategy when the object does not conform to the schema is `warn` (log a warning), `error` (throw an error), or `fallback` (return a default fallback value of your choice).
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const result = await agent.generate(messages, {
|
|
90
|
+
structuredOutput: {
|
|
91
|
+
schema: z.object({
|
|
92
|
+
name: z.string(),
|
|
93
|
+
age: z.number()
|
|
94
|
+
}),
|
|
95
|
+
model: openai('gpt-4o-mini'), // Optional model override for structuring
|
|
96
|
+
errorStrategy: 'fallback',
|
|
97
|
+
fallbackValue: { name: 'unknown', age: 0 },
|
|
98
|
+
instructions: 'Extract user information' // Override default structuring instructions
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
4. **`stopWhen`** - Flexible stop conditions (step count, token limit, etc.)
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const result = await agent.stream(messages, {
|
|
107
|
+
stopWhen: ({ steps, totalTokens }) => steps >= 5 || totalTokens >= 10000
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
5. **`providerOptions`** - Provider-specific options (e.g., OpenAI-specific settings)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const result = await agent.stream(messages, {
|
|
115
|
+
providerOptions: {
|
|
116
|
+
openai: {
|
|
117
|
+
store: true,
|
|
118
|
+
metadata: { userId: '123' }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
6. **`onChunk`** - Callback for each streaming chunk
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const result = await agent.stream(messages, {
|
|
128
|
+
onChunk: (chunk) => {
|
|
129
|
+
console.log('Received chunk:', chunk);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
7. **`onError`** - Error callback
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const result = await agent.stream(messages, {
|
|
138
|
+
onError: (error) => {
|
|
139
|
+
console.error('Stream error:', error);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
8. **`onAbort`** - Abort callback
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const result = await agent.stream(messages, {
|
|
148
|
+
onAbort: () => {
|
|
149
|
+
console.log('Stream aborted');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
9. **`activeTools`** - Specify which tools are active for this execution
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const result = await agent.stream(messages, {
|
|
158
|
+
activeTools: ['search', 'calculator'] // Only these tools will be available
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
10. **`abortSignal`** - AbortSignal for cancellation
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const controller = new AbortController();
|
|
166
|
+
const result = await agent.stream(messages, {
|
|
167
|
+
abortSignal: controller.signal
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Later: controller.abort();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
11. **`prepareStep`** - Callback before each step in multi-step execution
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const result = await agent.stream(messages, {
|
|
177
|
+
prepareStep: ({ step, state }) => {
|
|
178
|
+
console.log('About to execute step:', step);
|
|
179
|
+
return { /* modified state */ };
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
12. **`requireToolApproval`** - Require approval for all tool calls
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const result = await agent.stream(messages, {
|
|
188
|
+
requireToolApproval: true
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### 4. Options That Still Exist But Have Been Moved
|
|
193
|
+
|
|
194
|
+
#### `temperature` and Other Model Settings
|
|
195
|
+
|
|
196
|
+
Unified in `modelSettings`
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const result = await agent.stream(messages, {
|
|
200
|
+
modelSettings: {
|
|
201
|
+
temperature: 0.7,
|
|
202
|
+
maxTokens: 1000,
|
|
203
|
+
topP: 0.9
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### `resourceId` and `threadId`
|
|
209
|
+
|
|
210
|
+
Moved to memory object.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
const result = await agent.stream(messages, {
|
|
214
|
+
memory: {
|
|
215
|
+
resource: 'user-123',
|
|
216
|
+
thread: 'thread-456'
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 5. Options That Are Deprecated or Removed
|
|
222
|
+
|
|
223
|
+
#### `experimental_output`
|
|
224
|
+
|
|
225
|
+
Use `structuredOutput` instead to allow for tool calls and an object return.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const result = await agent.generate(messages, {
|
|
229
|
+
structuredOutput: {
|
|
230
|
+
schema: z.object({
|
|
231
|
+
summary: z.string()
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### `output`
|
|
238
|
+
|
|
239
|
+
The `output` property is deprecated in favor of `structuredOutput`, to achieve the same results use maxSteps 1 with `structuredOutput`.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const result = await agent.generate(messages, {
|
|
243
|
+
structuredOutput: {
|
|
244
|
+
schema: {
|
|
245
|
+
z.object({
|
|
246
|
+
name: z.string()
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
maxSteps: 1
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### `memoryOptions` was removed
|
|
255
|
+
|
|
256
|
+
Use `memory` instead
|
|
257
|
+
```typescript
|
|
258
|
+
const result = await agent.generate(messages, {
|
|
259
|
+
memory: {
|
|
260
|
+
...
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 6. Type Changes
|
|
266
|
+
|
|
267
|
+
#### `context`
|
|
268
|
+
|
|
269
|
+
- **Legacy**: `CoreMessage[]`
|
|
270
|
+
- **New format**: `ModelMessage[]`
|
|
271
|
+
|
|
272
|
+
#### `toolChoice` uses the AI SDK v5 `ToolChoice` type
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
|
276
|
+
type: 'tool';
|
|
277
|
+
toolName: Extract<keyof TOOLS, string>;
|
|
278
|
+
};
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
## Migration Checklist
|
|
283
|
+
|
|
284
|
+
### If you're already using `streamVNext` and `generateVNext`
|
|
285
|
+
|
|
286
|
+
Just find/replace the methods to `stream` and `generate` respectively.
|
|
287
|
+
|
|
288
|
+
### If you're using the old `stream` and `generate`
|
|
289
|
+
|
|
290
|
+
Decide whether you want to upgrade or not. If you don't, just find/replace to `streamLegacy` and `generateLegacy`.
|
|
291
|
+
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
title: Mastra Client Agents API
|
|
3
3
|
description: Learn how to interact with Mastra AI agents, including generating responses, streaming interactions, and managing agent tools using the client-js SDK.
|
|
4
4
|
---
|
|
5
|
-
import { StreamVNextCallout } from "@/components/streamVNext-callout.tsx"
|
|
6
5
|
|
|
7
6
|
# Agents API
|
|
8
7
|
|
|
@@ -161,14 +160,13 @@ const liveEvals = await agent.liveEvals();
|
|
|
161
160
|
```
|
|
162
161
|
|
|
163
162
|
|
|
164
|
-
### Stream
|
|
163
|
+
### Stream
|
|
165
164
|
|
|
166
|
-
<StreamVNextCallout />
|
|
167
165
|
|
|
168
|
-
Stream responses using the enhanced
|
|
166
|
+
Stream responses using the enhanced API with improved method signatures. This method provides enhanced capabilities and format flexibility, with support for both Mastra's native format and AI SDK v5 compatibility:
|
|
169
167
|
|
|
170
168
|
```typescript
|
|
171
|
-
const response = await agent.
|
|
169
|
+
const response = await agent.stream(
|
|
172
170
|
"Tell me a story",
|
|
173
171
|
{
|
|
174
172
|
threadId: "thread-1",
|
|
@@ -176,6 +174,14 @@ const response = await agent.streamVNext(
|
|
|
176
174
|
}
|
|
177
175
|
);
|
|
178
176
|
|
|
177
|
+
// AI SDK v5 compatible format
|
|
178
|
+
const response = await agent.stream(
|
|
179
|
+
"Tell me a story",
|
|
180
|
+
{
|
|
181
|
+
format: 'aisdk', // Enable AI SDK v5 compatibility
|
|
182
|
+
threadId: "thread-1",
|
|
183
|
+
}
|
|
184
|
+
);
|
|
179
185
|
|
|
180
186
|
// Process the stream
|
|
181
187
|
response.processDataStream({
|
|
@@ -189,12 +195,12 @@ Currently, AI SDK V5 format is not supported in the client SDK.
|
|
|
189
195
|
For AI SDK v5 compatible format, leverage the `@mastra/ai-sdk` package
|
|
190
196
|
[AI SDK v5 Stream Compatibility](/docs/frameworks/agentic-uis/ai-sdk#enabling-stream-compatibility)
|
|
191
197
|
|
|
192
|
-
### Generate
|
|
198
|
+
### Generate
|
|
193
199
|
|
|
194
|
-
Generate a response using the enhanced
|
|
200
|
+
Generate a response using the enhanced API with improved method signatures and AI SDK v5 compatibility:
|
|
195
201
|
|
|
196
202
|
```typescript
|
|
197
|
-
const response = await agent.
|
|
203
|
+
const response = await agent.generate(
|
|
198
204
|
"Hello, how are you?",
|
|
199
205
|
{
|
|
200
206
|
threadId: "thread-1",
|
|
@@ -18,3 +18,29 @@ export const mastra = new Mastra({
|
|
|
18
18
|
deployer: new VercelDeployer()
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
|
+
|
|
22
|
+
## Constructor options
|
|
23
|
+
|
|
24
|
+
The deployer supports a small set of high‑value overrides that are written to the Vercel Output API function config (`.vc-config.json`):
|
|
25
|
+
|
|
26
|
+
- `maxDuration?: number` — Function execution timeout (in seconds)
|
|
27
|
+
- `memory?: number` — Function memory (in MB)
|
|
28
|
+
- `regions?: string[]` — Regions to deploy the function (e.g. `['sfo1','iad1']`)
|
|
29
|
+
|
|
30
|
+
These options are merged into `.vercel/output/functions/index.func/.vc-config.json` while preserving default fields (`handler`, `launcherType`, `runtime`, `shouldAddHelpers`).
|
|
31
|
+
|
|
32
|
+
### Example with overrides
|
|
33
|
+
|
|
34
|
+
```typescript filename="src/mastra/index.ts" showLineNumbers copy
|
|
35
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
36
|
+
import { VercelDeployer } from "@mastra/deployer-vercel";
|
|
37
|
+
|
|
38
|
+
export const mastra = new Mastra({
|
|
39
|
+
// ...
|
|
40
|
+
deployer: new VercelDeployer({
|
|
41
|
+
maxDuration: 600,
|
|
42
|
+
memory: 1536,
|
|
43
|
+
regions: ["sfo1", "iad1"],
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
```
|
|
@@ -9,7 +9,7 @@ import { PropertiesTable } from "@/components/properties-table";
|
|
|
9
9
|
# ChunkType (Experimental)
|
|
10
10
|
|
|
11
11
|
<Callout type="important">
|
|
12
|
-
<strong className="block">Experimental API: </strong>This type is part of the experimental `.
|
|
12
|
+
<strong className="block">Experimental API: </strong>This type is part of the experimental `.stream()` method. The API may change as we refine the feature based on feedback.
|
|
13
13
|
</Callout>
|
|
14
14
|
|
|
15
15
|
The `ChunkType` type defines the mastra format of stream chunks that can be emitted during streaming responses from agents.
|
|
@@ -766,7 +766,7 @@ Contains metadata about the LLM provider's response. Emitted by some providers a
|
|
|
766
766
|
|
|
767
767
|
### watch
|
|
768
768
|
|
|
769
|
-
Contains monitoring and observability data from agent execution. Can include workflow state information, execution progress, or other runtime details depending on the context where `
|
|
769
|
+
Contains monitoring and observability data from agent execution. Can include workflow state information, execution progress, or other runtime details depending on the context where `stream()` is used.
|
|
770
770
|
|
|
771
771
|
<PropertiesTable
|
|
772
772
|
content={[
|
|
@@ -819,7 +819,7 @@ Emitted when the stream is forcibly terminated due to content being blocked by o
|
|
|
819
819
|
## Usage Example
|
|
820
820
|
|
|
821
821
|
```typescript
|
|
822
|
-
const stream = await agent.
|
|
822
|
+
const stream = await agent.stream("Hello");
|
|
823
823
|
|
|
824
824
|
for await (const chunk of stream.fullStream) {
|
|
825
825
|
switch (chunk.type) {
|
|
@@ -853,6 +853,6 @@ for await (const chunk of stream.fullStream) {
|
|
|
853
853
|
|
|
854
854
|
## Related Types
|
|
855
855
|
|
|
856
|
+
- [.stream()](./stream.mdx) - Method that returns streams emitting these chunks
|
|
856
857
|
- [MastraModelOutput](./agents/MastraModelOutput.mdx) - The stream object that emits these chunks
|
|
857
|
-
- [agent.streamVNext()](./agents/streamVNext.mdx) - Method that returns streams emitting these chunks for agents
|
|
858
858
|
- [workflow.streamVNext()](./workflows/streamVNext.mdx) - Method that returns streams emitting these chunks for workflows
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Reference: MastraModelOutput (Experimental) | Agents | Mastra Docs"
|
|
3
|
-
description: "Complete reference for MastraModelOutput - the stream object returned by agent.
|
|
3
|
+
description: "Complete reference for MastraModelOutput - the stream object returned by agent.stream() with streaming and promise-based access to model outputs."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
import { Callout } from "nextra/components";
|
|
@@ -9,17 +9,17 @@ import { PropertiesTable } from "@/components/properties-table";
|
|
|
9
9
|
# MastraModelOutput (Experimental)
|
|
10
10
|
|
|
11
11
|
<Callout type="important">
|
|
12
|
-
<strong className="block">Experimental API: </strong>This type is part of the experimental `.
|
|
12
|
+
<strong className="block">Experimental API: </strong>This type is part of the experimental `.stream()` method. The API may change as we refine the feature based on feedback.
|
|
13
13
|
</Callout>
|
|
14
14
|
|
|
15
|
-
The `MastraModelOutput` class is returned by [.
|
|
15
|
+
The `MastraModelOutput` class is returned by [.stream()](./stream.mdx) and provides both streaming and promise-based access to model outputs. It supports structured output generation, tool calls, reasoning, and comprehensive usage tracking.
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
// MastraModelOutput is returned by agent.
|
|
19
|
-
const stream = await agent.
|
|
18
|
+
// MastraModelOutput is returned by agent.stream()
|
|
19
|
+
const stream = await agent.stream("Hello world");
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
For setup and basic usage, see the [.
|
|
22
|
+
For setup and basic usage, see the [.stream()](./stream.mdx) method documentation.
|
|
23
23
|
|
|
24
24
|
## Streaming Properties
|
|
25
25
|
|
|
@@ -206,7 +206,7 @@ These properties resolve to final values after the stream completes:
|
|
|
206
206
|
### Basic Text Streaming
|
|
207
207
|
|
|
208
208
|
```typescript
|
|
209
|
-
const stream = await agent.
|
|
209
|
+
const stream = await agent.stream("Write a haiku");
|
|
210
210
|
|
|
211
211
|
// Stream text as it's generated
|
|
212
212
|
for await (const text of stream.textStream) {
|
|
@@ -221,7 +221,7 @@ console.log(fullText);
|
|
|
221
221
|
### Structured Output Streaming
|
|
222
222
|
|
|
223
223
|
```typescript
|
|
224
|
-
const stream = await agent.
|
|
224
|
+
const stream = await agent.stream("Generate user data", {
|
|
225
225
|
output: z.object({
|
|
226
226
|
name: z.string(),
|
|
227
227
|
age: z.number(),
|
|
@@ -242,7 +242,7 @@ console.log("Final:", user); // { name: "John", age: 30, email: "john@example.co
|
|
|
242
242
|
### Tool Calls and Results
|
|
243
243
|
|
|
244
244
|
```typescript
|
|
245
|
-
const stream = await agent.
|
|
245
|
+
const stream = await agent.stream("What's the weather in NYC?", {
|
|
246
246
|
tools: { weather: weatherTool }
|
|
247
247
|
});
|
|
248
248
|
|
|
@@ -257,7 +257,7 @@ console.log("Results:", toolResults);
|
|
|
257
257
|
### Complete Output Access
|
|
258
258
|
|
|
259
259
|
```typescript
|
|
260
|
-
const stream = await agent.
|
|
260
|
+
const stream = await agent.stream("Analyze this data");
|
|
261
261
|
|
|
262
262
|
const output = await stream.getFullOutput();
|
|
263
263
|
console.log({
|
|
@@ -271,7 +271,7 @@ console.log({
|
|
|
271
271
|
### Full Stream Processing
|
|
272
272
|
|
|
273
273
|
```typescript
|
|
274
|
-
const stream = await agent.
|
|
274
|
+
const stream = await agent.stream("Complex task");
|
|
275
275
|
|
|
276
276
|
for await (const chunk of stream.fullStream) {
|
|
277
277
|
switch (chunk.type) {
|
|
@@ -294,7 +294,7 @@ for await (const chunk of stream.fullStream) {
|
|
|
294
294
|
### Error Handling
|
|
295
295
|
|
|
296
296
|
```typescript
|
|
297
|
-
const stream = await agent.
|
|
297
|
+
const stream = await agent.stream("Analyze this data");
|
|
298
298
|
|
|
299
299
|
try {
|
|
300
300
|
// Option 1: Handle errors in consumeStream
|
|
@@ -318,5 +318,5 @@ if (stream.error) {
|
|
|
318
318
|
|
|
319
319
|
## Related Types
|
|
320
320
|
|
|
321
|
+
- [.stream()](./stream.mdx) - Method that returns MastraModelOutput
|
|
321
322
|
- [ChunkType](../ChunkType.mdx) - All possible chunk types in the full stream
|
|
322
|
-
- [.streamVNext()](./streamVNext.mdx) - Method that returns MastraModelOutput
|