@mastra/ai-sdk 0.2.0 → 0.2.1-alpha.0

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 0.2.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Update README to include more usage examples ([#8817](https://github.com/mastra-ai/mastra/pull/8817))
8
+
9
+ - Updated dependencies [[`ca85c93`](https://github.com/mastra-ai/mastra/commit/ca85c932b232e6ad820c811ec176d98e68c59b0a), [`a1d40f8`](https://github.com/mastra-ai/mastra/commit/a1d40f88d4ce42c4508774ad22e38ac582157af2), [`01c4a25`](https://github.com/mastra-ai/mastra/commit/01c4a2506c514d5e861c004d3d2fb3791c6391f3), [`cce8aad`](https://github.com/mastra-ai/mastra/commit/cce8aad878a0dd98e5647680f3765caba0b1701c)]:
10
+ - @mastra/core@0.21.1-alpha.0
11
+
3
12
  ## 0.2.0
4
13
 
5
14
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
- `@mastra/ai-sdk` helps you setup custom API routes to more easily support [`useChat()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat).
3
+ The recommended way of using Mastra and AI SDK together is by installing the `@mastra/ai-sdk` package. `@mastra/ai-sdk` provides custom API routes and utilities for streaming Mastra agents in AI SDK-compatible formats. Including chat, workflow, and network route handlers, along with utilities and exported types for UI integrations.
4
4
 
5
5
  ## Installation
6
6
 
@@ -47,9 +47,73 @@ After defining a dynamic route with `:agentId` you can use the `useChat()` hook
47
47
 
48
48
  ```typescript
49
49
  type MyMessage = {};
50
+
50
51
  const { error, status, sendMessage, messages, regenerate, stop } = useChat<MyMessage>({
51
52
  transport: new DefaultChatTransport({
52
53
  api: 'http://localhost:4111/chat/weatherAgent',
53
54
  }),
54
55
  });
55
56
  ```
57
+
58
+ ### Workflow route
59
+
60
+ Stream a workflow in AI SDK-compatible format.
61
+
62
+ ```typescript
63
+ import { workflowRoute } from '@mastra/ai-sdk';
64
+
65
+ export const mastra = new Mastra({
66
+ server: {
67
+ apiRoutes: [
68
+ workflowRoute({
69
+ path: '/workflow',
70
+ agent: 'weatherAgent',
71
+ }),
72
+ ],
73
+ },
74
+ });
75
+ ```
76
+
77
+ ### Network route
78
+
79
+ Stream agent networks (routing + nested agent/workflow/tool executions) in AI SDK-compatible format.
80
+
81
+ ```typescript
82
+ import { networkRoute } from '@mastra/ai-sdk';
83
+
84
+ export const mastra = new Mastra({
85
+ server: {
86
+ apiRoutes: [
87
+ networkRoute({
88
+ path: '/network',
89
+ agent: 'weatherAgent',
90
+ }),
91
+ ],
92
+ },
93
+ });
94
+ ```
95
+
96
+ ## Manual transformation
97
+
98
+ If you have a raw Mastra `stream`, you can manually transform it to AI SDK UI message parts:
99
+
100
+ ```typescript
101
+ import { toAISdkFormat } from '@mastra/ai-sdk';
102
+ import { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
103
+
104
+ export async function POST(req: Request) {
105
+ const { messages } = await req.json();
106
+ const agent = mastra.getAgent('weatherAgent');
107
+ const stream = await agent.stream(messages);
108
+
109
+ const uiMessageStream = createUIMessageStream({
110
+ execute: async ({ writer }) => {
111
+ for await (const part of toAISdkFormat(stream, { from: 'agent' })!) {
112
+ writer.write(part);
113
+ }
114
+ },
115
+ });
116
+
117
+ return createUIMessageStreamResponse({ stream: uiMessageStream });
118
+ }
119
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/ai-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-alpha.0",
4
4
  "description": "Adds custom API routes to be compatible with the AI SDK UI parts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,9 +32,9 @@
32
32
  "typescript": "^5.8.3",
33
33
  "vitest": "^3.2.4",
34
34
  "zod": "^3.25.76",
35
+ "@internal/lint": "0.0.49",
35
36
  "@internal/types-builder": "0.0.24",
36
- "@mastra/core": "0.21.0",
37
- "@internal/lint": "0.0.49"
37
+ "@mastra/core": "0.21.1-alpha.0"
38
38
  },
39
39
  "keywords": [
40
40
  "mastra",