@mastra/ai-sdk 0.0.0-ai-sdk-workflow-route-20251010135341 → 0.0.0-ai-sdk-network-text-delta-20251017172601
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 +89 -5
- package/README.md +65 -1
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/index.cjs +42 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts +1 -1
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +0 -1
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts +41 -16
- package/dist/transformers.d.ts.map +1 -1
- package/dist/workflow-route.d.ts +1 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,100 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
-
## 0.0.0-ai-sdk-
|
|
3
|
+
## 0.0.0-ai-sdk-network-text-delta-20251017172601
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- Update peer dependencies to match core package version bump (0.
|
|
7
|
+
- Update peer dependencies to match core package version bump (0.21.2) ([`862ec5e`](https://github.com/mastra-ai/mastra/commit/862ec5e0f8c7d8fa2134307af1ad2e294cf5fa54))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Pass original messages in chatRoute to fix uiMessages duplication #8830 ([#8904](https://github.com/mastra-ai/mastra/pull/8904))
|
|
12
|
+
|
|
13
|
+
- network routing agent text delta ai-sdk streaming ([`862ec5e`](https://github.com/mastra-ai/mastra/commit/862ec5e0f8c7d8fa2134307af1ad2e294cf5fa54))
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`691af3a`](https://github.com/mastra-ai/mastra/commit/691af3a28d87294fdb4c66fb3e14480362fcaffa), [`92b7b1c`](https://github.com/mastra-ai/mastra/commit/92b7b1ce08232a14f577715de8d9c005edeb0f05), [`a783845`](https://github.com/mastra-ai/mastra/commit/a783845ae42dbae134289cb56c79366f1d8bbb9d), [`e792061`](https://github.com/mastra-ai/mastra/commit/e7920613f9517958202602d2a414ca88df24b31d), [`862ec5e`](https://github.com/mastra-ai/mastra/commit/862ec5e0f8c7d8fa2134307af1ad2e294cf5fa54), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac)]:
|
|
16
|
+
- @mastra/core@0.0.0-ai-sdk-network-text-delta-20251017172601
|
|
17
|
+
|
|
18
|
+
## 0.2.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Update README to include more usage examples ([#8817](https://github.com/mastra-ai/mastra/pull/8817))
|
|
23
|
+
|
|
24
|
+
- 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)]:
|
|
25
|
+
- @mastra/core@0.21.1
|
|
26
|
+
|
|
27
|
+
## 0.2.1-alpha.0
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Update README to include more usage examples ([#8817](https://github.com/mastra-ai/mastra/pull/8817))
|
|
32
|
+
|
|
33
|
+
- 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)]:
|
|
34
|
+
- @mastra/core@0.21.1-alpha.0
|
|
35
|
+
|
|
36
|
+
## 0.2.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- Update peer dependencies to match core package version bump (0.20.3) ([#8672](https://github.com/mastra-ai/mastra/pull/8672))
|
|
41
|
+
|
|
42
|
+
- Update peer dependencies to match core package version bump (0.20.3) ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- pass runtimeContext to agent stream options in chatRoute ([#8641](https://github.com/mastra-ai/mastra/pull/8641))
|
|
47
|
+
|
|
48
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
|
|
49
|
+
|
|
50
|
+
- Improve types for networkRoute and workflowRoute functions ([#8844](https://github.com/mastra-ai/mastra/pull/8844))
|
|
51
|
+
|
|
52
|
+
- ai-sdk workflow route, agent network route ([#8672](https://github.com/mastra-ai/mastra/pull/8672))
|
|
53
|
+
|
|
54
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
|
|
55
|
+
|
|
56
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
|
|
57
|
+
|
|
58
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
|
|
59
|
+
|
|
60
|
+
- nested ai-sdk workflows and networks streaming support ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`f59fc1e`](https://github.com/mastra-ai/mastra/commit/f59fc1e406b8912e692f6bff6cfd4754cc8d165c), [`158381d`](https://github.com/mastra-ai/mastra/commit/158381d39335be934b81ef8a1947bccace492c25), [`a1799bc`](https://github.com/mastra-ai/mastra/commit/a1799bcc1b5a1cdc188f2ac0165f17a1c4ac6f7b), [`6ff6094`](https://github.com/mastra-ai/mastra/commit/6ff60946f4ecfebdeef6e21d2b230c2204f2c9b8), [`fb703b9`](https://github.com/mastra-ai/mastra/commit/fb703b9634eeaff1a6eb2b5531ce0f9e8fb04727), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`05a9dee`](https://github.com/mastra-ai/mastra/commit/05a9dee3d355694d28847bfffb6289657fcf7dfa), [`e3c1077`](https://github.com/mastra-ai/mastra/commit/e3c107763aedd1643d3def5df450c235da9ff76c), [`1908ca0`](https://github.com/mastra-ai/mastra/commit/1908ca0521f90e43779cc29ab590173ca560443c), [`1bccdb3`](https://github.com/mastra-ai/mastra/commit/1bccdb33eb90cbeba2dc5ece1c2561fb774b26b6), [`5ef944a`](https://github.com/mastra-ai/mastra/commit/5ef944a3721d93105675cac2b2311432ff8cc393), [`d6b186f`](https://github.com/mastra-ai/mastra/commit/d6b186fb08f1caf1b86f73d3a5ee88fb999ca3be), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`65493b3`](https://github.com/mastra-ai/mastra/commit/65493b31c36f6fdb78f9679f7e1ecf0c250aa5ee), [`a998b8f`](https://github.com/mastra-ai/mastra/commit/a998b8f858091c2ec47683e60766cf12d03001e4), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`8a37bdd`](https://github.com/mastra-ai/mastra/commit/8a37bddb6d8614a32c5b70303d583d80c620ea61), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb)]:
|
|
63
|
+
- @mastra/core@0.21.0
|
|
64
|
+
|
|
65
|
+
## 0.2.0-alpha.2
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- Improve types for networkRoute and workflowRoute functions ([#8844](https://github.com/mastra-ai/mastra/pull/8844))
|
|
70
|
+
|
|
71
|
+
- Updated dependencies [[`a1799bc`](https://github.com/mastra-ai/mastra/commit/a1799bcc1b5a1cdc188f2ac0165f17a1c4ac6f7b), [`6ff6094`](https://github.com/mastra-ai/mastra/commit/6ff60946f4ecfebdeef6e21d2b230c2204f2c9b8)]:
|
|
72
|
+
- @mastra/core@0.21.0-alpha.3
|
|
73
|
+
|
|
74
|
+
## 0.2.0-alpha.1
|
|
75
|
+
|
|
76
|
+
### Minor Changes
|
|
77
|
+
|
|
78
|
+
- Update peer dependencies to match core package version bump (0.20.3) ([#8672](https://github.com/mastra-ai/mastra/pull/8672))
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- pass runtimeContext to agent stream options in chatRoute ([#8641](https://github.com/mastra-ai/mastra/pull/8641))
|
|
83
|
+
|
|
84
|
+
- ai-sdk workflow route, agent network route ([#8672](https://github.com/mastra-ai/mastra/pull/8672))
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`158381d`](https://github.com/mastra-ai/mastra/commit/158381d39335be934b81ef8a1947bccace492c25), [`fb703b9`](https://github.com/mastra-ai/mastra/commit/fb703b9634eeaff1a6eb2b5531ce0f9e8fb04727), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`05a9dee`](https://github.com/mastra-ai/mastra/commit/05a9dee3d355694d28847bfffb6289657fcf7dfa), [`e3c1077`](https://github.com/mastra-ai/mastra/commit/e3c107763aedd1643d3def5df450c235da9ff76c), [`1bccdb3`](https://github.com/mastra-ai/mastra/commit/1bccdb33eb90cbeba2dc5ece1c2561fb774b26b6), [`5ef944a`](https://github.com/mastra-ai/mastra/commit/5ef944a3721d93105675cac2b2311432ff8cc393), [`d6b186f`](https://github.com/mastra-ai/mastra/commit/d6b186fb08f1caf1b86f73d3a5ee88fb999ca3be), [`65493b3`](https://github.com/mastra-ai/mastra/commit/65493b31c36f6fdb78f9679f7e1ecf0c250aa5ee), [`a998b8f`](https://github.com/mastra-ai/mastra/commit/a998b8f858091c2ec47683e60766cf12d03001e4), [`8a37bdd`](https://github.com/mastra-ai/mastra/commit/8a37bddb6d8614a32c5b70303d583d80c620ea61)]:
|
|
87
|
+
- @mastra/core@0.21.0-alpha.1
|
|
88
|
+
|
|
89
|
+
## 0.2.0-alpha.0
|
|
90
|
+
|
|
91
|
+
### Minor Changes
|
|
8
92
|
|
|
9
93
|
- Update peer dependencies to match core package version bump (0.20.3) ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
10
94
|
|
|
11
95
|
### Patch Changes
|
|
12
96
|
|
|
13
|
-
-
|
|
97
|
+
- Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
|
|
14
98
|
|
|
15
99
|
- Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
|
|
16
100
|
|
|
@@ -20,8 +104,8 @@
|
|
|
20
104
|
|
|
21
105
|
- nested ai-sdk workflows and networks streaming support ([#8614](https://github.com/mastra-ai/mastra/pull/8614))
|
|
22
106
|
|
|
23
|
-
- Updated dependencies [[`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`
|
|
24
|
-
- @mastra/core@0.0.0
|
|
107
|
+
- Updated dependencies [[`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb), [`59d036d`](https://github.com/mastra-ai/mastra/commit/59d036d4c2706b430b0e3f1f1e0ee853ce16ca04)]:
|
|
108
|
+
- @mastra/core@0.21.0-alpha.0
|
|
25
109
|
|
|
26
110
|
## 0.1.1
|
|
27
111
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
-
`@mastra/ai-sdk`
|
|
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/dist/chat-route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAAI;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzD,GAAG,CACA;IACE,IAAI,EAAE,GAAG,MAAM,WAAW,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,CAAC;AAEF,wBAAgB,SAAS,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACjE,IAAuB,EACvB,KAAK,EACL,cAAc,GACf,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAwJhE"}
|
package/dist/index.cjs
CHANGED
|
@@ -448,11 +448,11 @@ function AgentStreamToAISDKTransformer() {
|
|
|
448
448
|
if (agentTransformed) controller.enqueue(agentTransformed);
|
|
449
449
|
} else if (transformedChunk.type === "tool-workflow") {
|
|
450
450
|
const payload = transformedChunk.payload;
|
|
451
|
-
const workflowChunk = transformWorkflow(payload, bufferedSteps);
|
|
451
|
+
const workflowChunk = transformWorkflow(payload, bufferedSteps, true);
|
|
452
452
|
if (workflowChunk) controller.enqueue(workflowChunk);
|
|
453
453
|
} else if (transformedChunk.type === "tool-network") {
|
|
454
454
|
const payload = transformedChunk.payload;
|
|
455
|
-
const networkChunk = transformNetwork(payload, bufferedSteps);
|
|
455
|
+
const networkChunk = transformNetwork(payload, bufferedSteps, true);
|
|
456
456
|
if (networkChunk) controller.enqueue(networkChunk);
|
|
457
457
|
} else {
|
|
458
458
|
controller.enqueue(transformedChunk);
|
|
@@ -597,7 +597,7 @@ function transformAgent(payload, bufferedSteps) {
|
|
|
597
597
|
}
|
|
598
598
|
return null;
|
|
599
599
|
}
|
|
600
|
-
function transformWorkflow(payload, bufferedWorkflows) {
|
|
600
|
+
function transformWorkflow(payload, bufferedWorkflows, isNested) {
|
|
601
601
|
switch (payload.type) {
|
|
602
602
|
case "workflow-start":
|
|
603
603
|
bufferedWorkflows.set(payload.runId, {
|
|
@@ -605,7 +605,7 @@ function transformWorkflow(payload, bufferedWorkflows) {
|
|
|
605
605
|
steps: {}
|
|
606
606
|
});
|
|
607
607
|
return {
|
|
608
|
-
type: "data-workflow",
|
|
608
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
609
609
|
id: payload.runId,
|
|
610
610
|
data: {
|
|
611
611
|
name: bufferedWorkflows.get(payload.runId).name,
|
|
@@ -624,7 +624,7 @@ function transformWorkflow(payload, bufferedWorkflows) {
|
|
|
624
624
|
};
|
|
625
625
|
bufferedWorkflows.set(payload.runId, current);
|
|
626
626
|
return {
|
|
627
|
-
type: "data-workflow",
|
|
627
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
628
628
|
id: payload.runId,
|
|
629
629
|
data: {
|
|
630
630
|
name: current.name,
|
|
@@ -643,7 +643,7 @@ function transformWorkflow(payload, bufferedWorkflows) {
|
|
|
643
643
|
output: payload.payload.output ?? null
|
|
644
644
|
};
|
|
645
645
|
return {
|
|
646
|
-
type: "data-workflow",
|
|
646
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
647
647
|
id: payload.runId,
|
|
648
648
|
data: {
|
|
649
649
|
name: current.name,
|
|
@@ -657,7 +657,7 @@ function transformWorkflow(payload, bufferedWorkflows) {
|
|
|
657
657
|
const current = bufferedWorkflows.get(payload.runId);
|
|
658
658
|
if (!current) return null;
|
|
659
659
|
return {
|
|
660
|
-
type: "data-workflow",
|
|
660
|
+
type: isNested ? "data-tool-workflow" : "data-workflow",
|
|
661
661
|
id: payload.runId,
|
|
662
662
|
data: {
|
|
663
663
|
name: current.name,
|
|
@@ -671,7 +671,7 @@ function transformWorkflow(payload, bufferedWorkflows) {
|
|
|
671
671
|
return null;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
-
function transformNetwork(payload, bufferedNetworks) {
|
|
674
|
+
function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
675
675
|
switch (payload.type) {
|
|
676
676
|
case "routing-agent-start": {
|
|
677
677
|
if (!bufferedNetworks.has(payload.payload.runId)) {
|
|
@@ -681,7 +681,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
681
681
|
});
|
|
682
682
|
}
|
|
683
683
|
return {
|
|
684
|
-
type: "data-network",
|
|
684
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
685
685
|
id: payload.payload.runId,
|
|
686
686
|
data: {
|
|
687
687
|
name: bufferedNetworks.get(payload.payload.runId).name,
|
|
@@ -691,6 +691,23 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
691
691
|
}
|
|
692
692
|
};
|
|
693
693
|
}
|
|
694
|
+
case "routing-agent-text-start": {
|
|
695
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
696
|
+
if (!current) return null;
|
|
697
|
+
return {
|
|
698
|
+
type: "text-start",
|
|
699
|
+
id: payload.runId
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
case "routing-agent-text-delta": {
|
|
703
|
+
const current = bufferedNetworks.get(payload.runId);
|
|
704
|
+
if (!current) return null;
|
|
705
|
+
return {
|
|
706
|
+
type: "text-delta",
|
|
707
|
+
id: payload.runId,
|
|
708
|
+
delta: payload.payload.text
|
|
709
|
+
};
|
|
710
|
+
}
|
|
694
711
|
case "agent-execution-start": {
|
|
695
712
|
const current = bufferedNetworks.get(payload.payload.runId) || { name: "", steps: [] };
|
|
696
713
|
current.steps.push({
|
|
@@ -701,7 +718,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
701
718
|
});
|
|
702
719
|
bufferedNetworks.set(payload.payload.runId, current);
|
|
703
720
|
return {
|
|
704
|
-
type: "data-network",
|
|
721
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
705
722
|
id: payload.payload.runId,
|
|
706
723
|
data: {
|
|
707
724
|
name: current.name,
|
|
@@ -721,7 +738,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
721
738
|
});
|
|
722
739
|
bufferedNetworks.set(payload.payload.runId, current);
|
|
723
740
|
return {
|
|
724
|
-
type: "data-network",
|
|
741
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
725
742
|
id: payload.payload.runId,
|
|
726
743
|
data: {
|
|
727
744
|
name: current.name,
|
|
@@ -741,7 +758,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
741
758
|
});
|
|
742
759
|
bufferedNetworks.set(payload.payload.runId, current);
|
|
743
760
|
return {
|
|
744
|
-
type: "data-network",
|
|
761
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
745
762
|
id: payload.payload.runId,
|
|
746
763
|
data: {
|
|
747
764
|
name: current.name,
|
|
@@ -761,7 +778,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
761
778
|
output: payload.payload.result
|
|
762
779
|
});
|
|
763
780
|
return {
|
|
764
|
-
type: "data-network",
|
|
781
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
765
782
|
id: payload.runId,
|
|
766
783
|
data: {
|
|
767
784
|
name: current.name,
|
|
@@ -781,7 +798,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
781
798
|
output: payload.payload.result
|
|
782
799
|
});
|
|
783
800
|
return {
|
|
784
|
-
type: "data-network",
|
|
801
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
785
802
|
id: payload.runId,
|
|
786
803
|
data: {
|
|
787
804
|
name: current.name,
|
|
@@ -801,7 +818,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
801
818
|
output: payload.payload.result
|
|
802
819
|
});
|
|
803
820
|
return {
|
|
804
|
-
type: "data-network",
|
|
821
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
805
822
|
id: payload.runId,
|
|
806
823
|
data: {
|
|
807
824
|
name: current.name,
|
|
@@ -815,7 +832,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
815
832
|
const current = bufferedNetworks.get(payload.payload.runId);
|
|
816
833
|
if (!current) return null;
|
|
817
834
|
return {
|
|
818
|
-
type: "data-network",
|
|
835
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
819
836
|
id: payload.payload.runId,
|
|
820
837
|
data: {
|
|
821
838
|
name: current.name,
|
|
@@ -829,7 +846,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
829
846
|
const current = bufferedNetworks.get(payload.payload.runId);
|
|
830
847
|
if (!current) return null;
|
|
831
848
|
return {
|
|
832
|
-
type: "data-network",
|
|
849
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
833
850
|
id: payload.payload.runId,
|
|
834
851
|
data: {
|
|
835
852
|
name: current.name,
|
|
@@ -843,7 +860,7 @@ function transformNetwork(payload, bufferedNetworks) {
|
|
|
843
860
|
const current = bufferedNetworks.get(payload.runId);
|
|
844
861
|
if (!current) return null;
|
|
845
862
|
return {
|
|
846
|
-
type: "data-network",
|
|
863
|
+
type: isNested ? "data-tool-network" : "data-network",
|
|
847
864
|
id: payload.runId,
|
|
848
865
|
data: {
|
|
849
866
|
name: current.name,
|
|
@@ -976,6 +993,7 @@ function chatRoute({
|
|
|
976
993
|
handler: async (c) => {
|
|
977
994
|
const { messages, ...rest } = await c.req.json();
|
|
978
995
|
const mastra = c.get("mastra");
|
|
996
|
+
const runtimeContext = c.get("runtimeContext");
|
|
979
997
|
let agentToUse = agent;
|
|
980
998
|
if (!agent) {
|
|
981
999
|
const agentId = c.req.param("agentId");
|
|
@@ -986,6 +1004,9 @@ function chatRoute({
|
|
|
986
1004
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
987
1005
|
);
|
|
988
1006
|
}
|
|
1007
|
+
if (runtimeContext && defaultOptions?.runtimeContext) {
|
|
1008
|
+
mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
|
|
1009
|
+
}
|
|
989
1010
|
if (!agentToUse) {
|
|
990
1011
|
throw new Error("Agent ID is required");
|
|
991
1012
|
}
|
|
@@ -995,9 +1016,11 @@ function chatRoute({
|
|
|
995
1016
|
}
|
|
996
1017
|
const result = await agentObj.stream(messages, {
|
|
997
1018
|
...defaultOptions,
|
|
998
|
-
...rest
|
|
1019
|
+
...rest,
|
|
1020
|
+
runtimeContext: runtimeContext || defaultOptions?.runtimeContext
|
|
999
1021
|
});
|
|
1000
1022
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1023
|
+
originalMessages: messages,
|
|
1001
1024
|
execute: async ({ writer }) => {
|
|
1002
1025
|
for await (const part of toAISdkFormat(result, { from: "agent" })) {
|
|
1003
1026
|
writer.write(part);
|