@mastra/ai-sdk 0.0.0-moving-fetching-hooks-to-playground-ui-and-expose-them-20251023071821 → 0.0.0-new-button-export-20251219130424
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 +660 -1
- package/README.md +60 -0
- package/dist/__tests__/__fixtures__/network.stream.d.ts +2329 -0
- package/dist/__tests__/__fixtures__/network.stream.d.ts.map +1 -0
- package/dist/_types/@ai-sdk_provider/dist/index.d.ts +1719 -0
- package/dist/chat-route.d.ts +90 -3
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/chunk-DES3K4SD.cjs +17 -0
- package/dist/chunk-DES3K4SD.cjs.map +1 -0
- package/dist/chunk-KYQEM4AK.js +294 -0
- package/dist/chunk-KYQEM4AK.js.map +1 -0
- package/dist/chunk-TD7TJ4N5.cjs +297 -0
- package/dist/chunk-TD7TJ4N5.cjs.map +1 -0
- package/dist/chunk-VUNV25KB.js +14 -0
- package/dist/chunk-VUNV25KB.js.map +1 -0
- package/dist/convert-messages.d.ts +90 -0
- package/dist/convert-messages.d.ts.map +1 -0
- package/dist/convert-streams.d.ts +81 -0
- package/dist/convert-streams.d.ts.map +1 -0
- package/dist/helpers.d.ts +9 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +3986 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3975 -166
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +157 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/network-route.d.ts +63 -2
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +15 -16
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/token-5ZTQBFQ6.cjs +63 -0
- package/dist/token-5ZTQBFQ6.cjs.map +1 -0
- package/dist/token-UOO4N54I.js +61 -0
- package/dist/token-UOO4N54I.js.map +1 -0
- package/dist/token-util-DUN56AZR.cjs +9 -0
- package/dist/token-util-DUN56AZR.cjs.map +1 -0
- package/dist/token-util-JCUK3SCT.js +7 -0
- package/dist/token-util-JCUK3SCT.js.map +1 -0
- package/dist/transformers.d.ts +174 -10
- package/dist/transformers.d.ts.map +1 -1
- package/dist/ui.cjs +15 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.ts +2 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +12 -0
- package/dist/ui.js.map +1 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-route.d.ts +68 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +23 -8
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);
|