@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.
Files changed (54) hide show
  1. package/CHANGELOG.md +660 -1
  2. package/README.md +60 -0
  3. package/dist/__tests__/__fixtures__/network.stream.d.ts +2329 -0
  4. package/dist/__tests__/__fixtures__/network.stream.d.ts.map +1 -0
  5. package/dist/_types/@ai-sdk_provider/dist/index.d.ts +1719 -0
  6. package/dist/chat-route.d.ts +90 -3
  7. package/dist/chat-route.d.ts.map +1 -1
  8. package/dist/chunk-DES3K4SD.cjs +17 -0
  9. package/dist/chunk-DES3K4SD.cjs.map +1 -0
  10. package/dist/chunk-KYQEM4AK.js +294 -0
  11. package/dist/chunk-KYQEM4AK.js.map +1 -0
  12. package/dist/chunk-TD7TJ4N5.cjs +297 -0
  13. package/dist/chunk-TD7TJ4N5.cjs.map +1 -0
  14. package/dist/chunk-VUNV25KB.js +14 -0
  15. package/dist/chunk-VUNV25KB.js.map +1 -0
  16. package/dist/convert-messages.d.ts +90 -0
  17. package/dist/convert-messages.d.ts.map +1 -0
  18. package/dist/convert-streams.d.ts +81 -0
  19. package/dist/convert-streams.d.ts.map +1 -0
  20. package/dist/helpers.d.ts +9 -4
  21. package/dist/helpers.d.ts.map +1 -1
  22. package/dist/index.cjs +3986 -153
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +9 -6
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +3975 -166
  27. package/dist/index.js.map +1 -1
  28. package/dist/middleware.d.ts +157 -0
  29. package/dist/middleware.d.ts.map +1 -0
  30. package/dist/network-route.d.ts +63 -2
  31. package/dist/network-route.d.ts.map +1 -1
  32. package/dist/to-ai-sdk-format.d.ts +15 -16
  33. package/dist/to-ai-sdk-format.d.ts.map +1 -1
  34. package/dist/token-5ZTQBFQ6.cjs +63 -0
  35. package/dist/token-5ZTQBFQ6.cjs.map +1 -0
  36. package/dist/token-UOO4N54I.js +61 -0
  37. package/dist/token-UOO4N54I.js.map +1 -0
  38. package/dist/token-util-DUN56AZR.cjs +9 -0
  39. package/dist/token-util-DUN56AZR.cjs.map +1 -0
  40. package/dist/token-util-JCUK3SCT.js +7 -0
  41. package/dist/token-util-JCUK3SCT.js.map +1 -0
  42. package/dist/transformers.d.ts +174 -10
  43. package/dist/transformers.d.ts.map +1 -1
  44. package/dist/ui.cjs +15 -0
  45. package/dist/ui.cjs.map +1 -0
  46. package/dist/ui.d.ts +2 -0
  47. package/dist/ui.d.ts.map +1 -0
  48. package/dist/ui.js +12 -0
  49. package/dist/ui.js.map +1 -0
  50. package/dist/utils.d.ts +9 -1
  51. package/dist/utils.d.ts.map +1 -1
  52. package/dist/workflow-route.d.ts +68 -1
  53. package/dist/workflow-route.d.ts.map +1 -1
  54. 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);