@mastra/ai-sdk 1.1.4 → 1.2.0-alpha.1
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 +43 -0
- package/README.md +28 -5
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +13493 -0
- package/dist/chat-route.d.ts +21 -6
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/chunk-HDI4ZP7N.js +79 -0
- package/dist/chunk-HDI4ZP7N.js.map +1 -0
- package/dist/chunk-IV3RKEE4.js +439 -0
- package/dist/chunk-IV3RKEE4.js.map +1 -0
- package/dist/chunk-PEZAMDZJ.cjs +84 -0
- package/dist/chunk-PEZAMDZJ.cjs.map +1 -0
- package/dist/chunk-X72VW7EY.cjs +441 -0
- package/dist/chunk-X72VW7EY.cjs.map +1 -0
- package/dist/convert-streams.d.ts +44 -71
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/helpers.d.ts +16 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +6840 -381
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6839 -381
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.d.ts.map +1 -1
- package/dist/network-route.d.ts +19 -9
- package/dist/network-route.d.ts.map +1 -1
- package/dist/public-types.d.ts +9 -0
- package/dist/public-types.d.ts.map +1 -0
- package/dist/token-APYSY3BW-CBIBV5F2.js +61 -0
- package/dist/token-APYSY3BW-CBIBV5F2.js.map +1 -0
- package/dist/token-APYSY3BW-M2K6HVOG.cjs +63 -0
- package/dist/token-APYSY3BW-M2K6HVOG.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs +10 -0
- package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-IOKQM5O3.js +8 -0
- package/dist/token-util-RMHT2CPJ-IOKQM5O3.js.map +1 -0
- package/dist/transformers.d.ts +53 -4
- package/dist/transformers.d.ts.map +1 -1
- package/dist/workflow-route.d.ts +14 -4
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.2.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Exposes `messageMetadata` option in `handleChatStream` for attaching custom metadata to streamed messages. ([#14315](https://github.com/mastra-ai/mastra/pull/14315))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = await handleChatStream({
|
|
11
|
+
mastra,
|
|
12
|
+
agentId: 'my-agent',
|
|
13
|
+
params,
|
|
14
|
+
messageMetadata: () => ({ createdAt: new Date().toISOString() }),
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Fixed `withMastra` to accept `LanguageModelV3` models from the latest AI SDK (`@ai-sdk/openai@3+`, `ai@6+`). Previously, passing a V3 model caused a TypeScript error: `LanguageModelV3 is not assignable to LanguageModelV2`. The function now accepts both `LanguageModelV2` and `LanguageModelV3` via overloads. ([#14380](https://github.com/mastra-ai/mastra/pull/14380))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`9e1a3ed`](https://github.com/mastra-ai/mastra/commit/9e1a3ed07cfafb5e8e19a796ce0bee817002d7c0), [`a579f7a`](https://github.com/mastra-ai/mastra/commit/a579f7a31e582674862b5679bc79af7ccf7429b8)]:
|
|
23
|
+
- @mastra/core@1.15.0-alpha.2
|
|
24
|
+
|
|
25
|
+
## 1.1.5-alpha.0
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Added support for AI SDK v6 response helpers while keeping the existing v5 stream path backwards compatible. ([#14405](https://github.com/mastra-ai/mastra/pull/14405))
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { toAISdkStream } from '@mastra/ai-sdk';
|
|
33
|
+
|
|
34
|
+
// Existing default path for AI SDK v5
|
|
35
|
+
const v5Stream = toAISdkStream(mastraStream, { from: 'agent' });
|
|
36
|
+
|
|
37
|
+
// Use the v6 stream contract with AI SDK v6 response helpers
|
|
38
|
+
const v6Stream = toAISdkStream(mastraStream, { from: 'agent', version: 'v6' });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`toAISdkStream`, the framework-agnostic `handle*Stream()` helpers, and the `chatRoute()` / `networkRoute()` / `workflowRoute()` route helpers keep the existing v5/default behavior. Pass `version: 'v6'` when your app is typed against AI SDK v6 response helpers.
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [[`cb611a1`](https://github.com/mastra-ai/mastra/commit/cb611a1e89a4f4cf74c97b57e0c27bb56f2eceb5), [`62d1d3c`](https://github.com/mastra-ai/mastra/commit/62d1d3cc08fe8182e7080237fd975de862ec8c91), [`8681ecb`](https://github.com/mastra-ai/mastra/commit/8681ecb86184d5907267000e4576cc442a9a83fc), [`28d0249`](https://github.com/mastra-ai/mastra/commit/28d0249295782277040ad1e0d243e695b7ab1ce4), [`bb0f09d`](https://github.com/mastra-ai/mastra/commit/bb0f09dbac58401b36069f483acf5673202db5b5), [`5f7e9d0`](https://github.com/mastra-ai/mastra/commit/5f7e9d0db664020e1f3d97d7d18c6b0b9d4843d0)]:
|
|
44
|
+
- @mastra/core@1.15.0-alpha.0
|
|
45
|
+
|
|
3
46
|
## 1.1.4
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ export const mastra = new Mastra({
|
|
|
97
97
|
|
|
98
98
|
## Framework-agnostic handlers
|
|
99
99
|
|
|
100
|
-
For use outside
|
|
100
|
+
For use outside the Mastra server (e.g., Next.js App Router, Express), you can use the standalone handler functions directly. These handlers return a compatibility `ReadableStream` that can be passed to AI SDK response helpers like `createUIMessageStreamResponse` and `pipeUIMessageStreamToResponse`:
|
|
101
101
|
|
|
102
102
|
### handleChatStream
|
|
103
103
|
|
|
@@ -137,16 +137,21 @@ export async function POST(req: Request) {
|
|
|
137
137
|
|
|
138
138
|
### handleNetworkStream
|
|
139
139
|
|
|
140
|
+
Pass AI SDK `UIMessage[]` from your installed `ai` version so TypeScript can infer the correct stream overload.
|
|
141
|
+
|
|
142
|
+
Handlers keep the existing v5/default behavior. If your app is typed against `ai@6`, pass `version: 'v6'`.
|
|
143
|
+
|
|
140
144
|
```typescript
|
|
141
145
|
import { handleNetworkStream } from '@mastra/ai-sdk';
|
|
142
|
-
import { createUIMessageStreamResponse } from 'ai';
|
|
146
|
+
import { createUIMessageStreamResponse, type UIMessage } from 'ai';
|
|
143
147
|
import { mastra } from '@/src/mastra';
|
|
144
148
|
|
|
145
149
|
export async function POST(req: Request) {
|
|
146
|
-
const params = await req.json();
|
|
150
|
+
const params = (await req.json()) as { messages: UIMessage[] };
|
|
147
151
|
const stream = await handleNetworkStream({
|
|
148
152
|
mastra,
|
|
149
153
|
agentId: 'routingAgent',
|
|
154
|
+
version: 'v6',
|
|
150
155
|
params,
|
|
151
156
|
});
|
|
152
157
|
return createUIMessageStreamResponse({ stream });
|
|
@@ -157,8 +162,10 @@ export async function POST(req: Request) {
|
|
|
157
162
|
|
|
158
163
|
If you have a raw Mastra `stream`, you can manually transform it to AI SDK UI message parts:
|
|
159
164
|
|
|
165
|
+
Use `toAISdkStream` for both versions. If your app is typed against `ai@6`, pass `version: 'v6'`.
|
|
166
|
+
|
|
160
167
|
```typescript
|
|
161
|
-
import {
|
|
168
|
+
import { toAISdkStream } from '@mastra/ai-sdk';
|
|
162
169
|
import { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
|
|
163
170
|
|
|
164
171
|
export async function POST(req: Request) {
|
|
@@ -170,7 +177,7 @@ export async function POST(req: Request) {
|
|
|
170
177
|
const uiMessageStream = createUIMessageStream({
|
|
171
178
|
originalMessages: messages,
|
|
172
179
|
execute: async ({ writer }) => {
|
|
173
|
-
for await (const part of
|
|
180
|
+
for await (const part of toAISdkStream(stream, { from: 'agent' })) {
|
|
174
181
|
writer.write(part);
|
|
175
182
|
}
|
|
176
183
|
},
|
|
@@ -179,3 +186,19 @@ export async function POST(req: Request) {
|
|
|
179
186
|
return createUIMessageStreamResponse({ stream: uiMessageStream });
|
|
180
187
|
}
|
|
181
188
|
```
|
|
189
|
+
|
|
190
|
+
For AI SDK v6, select the v6 stream contract explicitly:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const uiMessageStream = createUIMessageStream({
|
|
194
|
+
originalMessages: messages,
|
|
195
|
+
execute: async ({ writer }) => {
|
|
196
|
+
for await (const part of toAISdkStream(stream, {
|
|
197
|
+
from: 'agent',
|
|
198
|
+
version: 'v6',
|
|
199
|
+
})) {
|
|
200
|
+
writer.write(part);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
```
|