@mastra/client-js 0.0.0-afterToolExecute-20250415041527 → 0.0.0-agui-20250501191909
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 +247 -2
- package/dist/index.cjs +373 -4
- package/dist/index.d.cts +153 -6
- package/dist/index.d.ts +153 -6
- package/dist/index.js +373 -4
- package/package.json +9 -4
- package/src/adapters/agui.test.ts +167 -0
- package/src/adapters/agui.ts +219 -0
- package/src/client.ts +39 -9
- package/src/index.test.ts +4 -4
- package/src/resources/agent.ts +0 -1
- package/src/resources/base.ts +1 -1
- package/src/resources/index.ts +1 -0
- package/src/resources/memory-thread.ts +1 -8
- package/src/resources/network.ts +1 -1
- package/src/resources/tool.ts +9 -3
- package/src/resources/vnext-workflow.ts +234 -0
- package/src/resources/workflow.ts +10 -2
- package/src/types.ts +32 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,263 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-agui-20250501191909
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 254f5c3: Audit, cleanup MastraClient
|
|
8
|
+
- 0097d50: Add serializedStepGraph to vNext workflow
|
|
9
|
+
Return serializedStepGraph from vNext workflow
|
|
10
|
+
Use serializedStepGraph in vNext workflow graph
|
|
11
|
+
- 2429c74: Add get workflow runs api to client-js
|
|
12
|
+
- Updated dependencies [967b41c]
|
|
13
|
+
- Updated dependencies [26738f4]
|
|
14
|
+
- Updated dependencies [b804723]
|
|
15
|
+
- Updated dependencies [0097d50]
|
|
16
|
+
- @mastra/core@0.0.0-agui-20250501191909
|
|
17
|
+
|
|
18
|
+
## 0.1.20-alpha.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [26738f4]
|
|
23
|
+
- @mastra/core@0.9.2-alpha.2
|
|
24
|
+
|
|
25
|
+
## 0.1.20-alpha.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 254f5c3: Audit, cleanup MastraClient
|
|
30
|
+
- 2429c74: Add get workflow runs api to client-js
|
|
31
|
+
- Updated dependencies [b804723]
|
|
32
|
+
- @mastra/core@0.9.2-alpha.1
|
|
33
|
+
|
|
34
|
+
## 0.1.20-alpha.0
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 0097d50: Add serializedStepGraph to vNext workflow
|
|
39
|
+
Return serializedStepGraph from vNext workflow
|
|
40
|
+
Use serializedStepGraph in vNext workflow graph
|
|
41
|
+
- Updated dependencies [0097d50]
|
|
42
|
+
- @mastra/core@0.9.2-alpha.0
|
|
43
|
+
|
|
44
|
+
## 0.1.19
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- b50b9b7: Add vNext workflow to client-js
|
|
49
|
+
- 11d4485: Show VNext workflows on the playground
|
|
50
|
+
Show running status for step in vNext workflowState
|
|
51
|
+
- Updated dependencies [405b63d]
|
|
52
|
+
- Updated dependencies [81fb7f6]
|
|
53
|
+
- Updated dependencies [20275d4]
|
|
54
|
+
- Updated dependencies [7d1892c]
|
|
55
|
+
- Updated dependencies [a90a082]
|
|
56
|
+
- Updated dependencies [2d17c73]
|
|
57
|
+
- Updated dependencies [61e92f5]
|
|
58
|
+
- Updated dependencies [35955b0]
|
|
59
|
+
- Updated dependencies [6262bd5]
|
|
60
|
+
- Updated dependencies [c1409ef]
|
|
61
|
+
- Updated dependencies [3e7b69d]
|
|
62
|
+
- Updated dependencies [e4943b8]
|
|
63
|
+
- Updated dependencies [11d4485]
|
|
64
|
+
- Updated dependencies [479f490]
|
|
65
|
+
- Updated dependencies [c23a81c]
|
|
66
|
+
- Updated dependencies [2d4001d]
|
|
67
|
+
- Updated dependencies [c71013a]
|
|
68
|
+
- Updated dependencies [1d3b1cd]
|
|
69
|
+
- @mastra/core@0.9.1
|
|
70
|
+
|
|
71
|
+
## 0.1.19-alpha.8
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [2d17c73]
|
|
76
|
+
- @mastra/core@0.9.1-alpha.8
|
|
77
|
+
|
|
78
|
+
## 0.1.19-alpha.7
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [1d3b1cd]
|
|
83
|
+
- @mastra/core@0.9.1-alpha.7
|
|
84
|
+
|
|
85
|
+
## 0.1.19-alpha.6
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- Updated dependencies [c23a81c]
|
|
90
|
+
- @mastra/core@0.9.1-alpha.6
|
|
91
|
+
|
|
92
|
+
## 0.1.19-alpha.5
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- Updated dependencies [3e7b69d]
|
|
97
|
+
- @mastra/core@0.9.1-alpha.5
|
|
98
|
+
|
|
99
|
+
## 0.1.19-alpha.4
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- Updated dependencies [e4943b8]
|
|
104
|
+
- Updated dependencies [479f490]
|
|
105
|
+
- @mastra/core@0.9.1-alpha.4
|
|
106
|
+
|
|
107
|
+
## 0.1.19-alpha.3
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- Updated dependencies [6262bd5]
|
|
112
|
+
- @mastra/core@0.9.1-alpha.3
|
|
113
|
+
|
|
114
|
+
## 0.1.19-alpha.2
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- Updated dependencies [405b63d]
|
|
119
|
+
- Updated dependencies [61e92f5]
|
|
120
|
+
- Updated dependencies [c71013a]
|
|
121
|
+
- @mastra/core@0.9.1-alpha.2
|
|
122
|
+
|
|
123
|
+
## 0.1.19-alpha.1
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- b50b9b7: Add vNext workflow to client-js
|
|
128
|
+
- 11d4485: Show VNext workflows on the playground
|
|
129
|
+
Show running status for step in vNext workflowState
|
|
130
|
+
- Updated dependencies [20275d4]
|
|
131
|
+
- Updated dependencies [7d1892c]
|
|
132
|
+
- Updated dependencies [a90a082]
|
|
133
|
+
- Updated dependencies [35955b0]
|
|
134
|
+
- Updated dependencies [c1409ef]
|
|
135
|
+
- Updated dependencies [11d4485]
|
|
136
|
+
- Updated dependencies [2d4001d]
|
|
137
|
+
- @mastra/core@0.9.1-alpha.1
|
|
138
|
+
|
|
139
|
+
## 0.1.19-alpha.0
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- Updated dependencies [81fb7f6]
|
|
144
|
+
- @mastra/core@0.9.1-alpha.0
|
|
145
|
+
|
|
146
|
+
## 0.1.18
|
|
147
|
+
|
|
148
|
+
### Patch Changes
|
|
149
|
+
|
|
150
|
+
- 2538066: Fix memory thread creation from client SDK
|
|
151
|
+
- Updated dependencies [000a6d4]
|
|
152
|
+
- Updated dependencies [08bb78e]
|
|
153
|
+
- Updated dependencies [ed2f549]
|
|
154
|
+
- Updated dependencies [7e92011]
|
|
155
|
+
- Updated dependencies [9ee4293]
|
|
156
|
+
- Updated dependencies [03f3cd0]
|
|
157
|
+
- Updated dependencies [c0f22b4]
|
|
158
|
+
- Updated dependencies [71d9444]
|
|
159
|
+
- Updated dependencies [157c741]
|
|
160
|
+
- Updated dependencies [8a8a73b]
|
|
161
|
+
- Updated dependencies [0a033fa]
|
|
162
|
+
- Updated dependencies [fe3ae4d]
|
|
163
|
+
- Updated dependencies [9c26508]
|
|
164
|
+
- Updated dependencies [0f4eae3]
|
|
165
|
+
- Updated dependencies [16a8648]
|
|
166
|
+
- Updated dependencies [6f92295]
|
|
167
|
+
- @mastra/core@0.9.0
|
|
168
|
+
|
|
169
|
+
## 0.1.18-alpha.8
|
|
170
|
+
|
|
171
|
+
### Patch Changes
|
|
172
|
+
|
|
173
|
+
- 2538066: Fix memory thread creation from client SDK
|
|
174
|
+
- Updated dependencies [000a6d4]
|
|
175
|
+
- Updated dependencies [ed2f549]
|
|
176
|
+
- Updated dependencies [c0f22b4]
|
|
177
|
+
- Updated dependencies [0a033fa]
|
|
178
|
+
- Updated dependencies [9c26508]
|
|
179
|
+
- Updated dependencies [0f4eae3]
|
|
180
|
+
- Updated dependencies [16a8648]
|
|
181
|
+
- @mastra/core@0.9.0-alpha.8
|
|
182
|
+
|
|
183
|
+
## 0.1.18-alpha.7
|
|
184
|
+
|
|
185
|
+
### Patch Changes
|
|
186
|
+
|
|
187
|
+
- Updated dependencies [71d9444]
|
|
188
|
+
- @mastra/core@0.9.0-alpha.7
|
|
189
|
+
|
|
190
|
+
## 0.1.18-alpha.6
|
|
191
|
+
|
|
192
|
+
### Patch Changes
|
|
193
|
+
|
|
194
|
+
- Updated dependencies [157c741]
|
|
195
|
+
- @mastra/core@0.9.0-alpha.6
|
|
196
|
+
|
|
197
|
+
## 0.1.18-alpha.5
|
|
198
|
+
|
|
199
|
+
### Patch Changes
|
|
200
|
+
|
|
201
|
+
- Updated dependencies [08bb78e]
|
|
202
|
+
- @mastra/core@0.9.0-alpha.5
|
|
203
|
+
|
|
204
|
+
## 0.1.18-alpha.4
|
|
205
|
+
|
|
206
|
+
### Patch Changes
|
|
207
|
+
|
|
208
|
+
- Updated dependencies [7e92011]
|
|
209
|
+
- @mastra/core@0.9.0-alpha.4
|
|
210
|
+
|
|
211
|
+
## 0.1.18-alpha.3
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies [fe3ae4d]
|
|
216
|
+
- @mastra/core@0.9.0-alpha.3
|
|
217
|
+
|
|
218
|
+
## 0.1.18-alpha.2
|
|
219
|
+
|
|
220
|
+
### Patch Changes
|
|
221
|
+
|
|
222
|
+
- Updated dependencies [9ee4293]
|
|
223
|
+
- @mastra/core@0.8.4-alpha.2
|
|
224
|
+
|
|
225
|
+
## 0.1.18-alpha.1
|
|
226
|
+
|
|
227
|
+
### Patch Changes
|
|
228
|
+
|
|
229
|
+
- Updated dependencies [8a8a73b]
|
|
230
|
+
- Updated dependencies [6f92295]
|
|
231
|
+
- @mastra/core@0.8.4-alpha.1
|
|
232
|
+
|
|
233
|
+
## 0.1.18-alpha.0
|
|
234
|
+
|
|
235
|
+
### Patch Changes
|
|
236
|
+
|
|
237
|
+
- Updated dependencies [03f3cd0]
|
|
238
|
+
- @mastra/core@0.8.4-alpha.0
|
|
239
|
+
|
|
240
|
+
## 0.1.17
|
|
4
241
|
|
|
5
242
|
### Patch Changes
|
|
6
243
|
|
|
7
244
|
- 37bb612: Add Elastic-2.0 licensing for packages
|
|
8
245
|
- bc4acb3: updated traces to not be wrapped in traces object
|
|
246
|
+
- Updated dependencies [d72318f]
|
|
9
247
|
- Updated dependencies [0bcc862]
|
|
10
248
|
- Updated dependencies [10a8caf]
|
|
11
249
|
- Updated dependencies [359b089]
|
|
12
250
|
- Updated dependencies [32e7b71]
|
|
13
251
|
- Updated dependencies [37bb612]
|
|
14
252
|
- Updated dependencies [7f1b291]
|
|
15
|
-
- @mastra/core@0.
|
|
253
|
+
- @mastra/core@0.8.3
|
|
254
|
+
|
|
255
|
+
## 0.1.17-alpha.5
|
|
256
|
+
|
|
257
|
+
### Patch Changes
|
|
258
|
+
|
|
259
|
+
- Updated dependencies [d72318f]
|
|
260
|
+
- @mastra/core@0.8.3-alpha.5
|
|
16
261
|
|
|
17
262
|
## 0.1.17-alpha.4
|
|
18
263
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,175 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var client = require('@ag-ui/client');
|
|
4
|
+
var rxjs = require('rxjs');
|
|
3
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
4
6
|
var zod = require('zod');
|
|
5
7
|
var zodToJsonSchema = require('zod-to-json-schema');
|
|
6
8
|
|
|
7
|
-
// src/
|
|
9
|
+
// src/adapters/agui.ts
|
|
10
|
+
var AGUIAdapter = class extends client.AbstractAgent {
|
|
11
|
+
agent;
|
|
12
|
+
resourceId;
|
|
13
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
14
|
+
super({
|
|
15
|
+
agentId,
|
|
16
|
+
...rest
|
|
17
|
+
});
|
|
18
|
+
this.agent = agent;
|
|
19
|
+
this.resourceId = resourceId;
|
|
20
|
+
}
|
|
21
|
+
run(input) {
|
|
22
|
+
return new rxjs.Observable((subscriber) => {
|
|
23
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
24
|
+
subscriber.next({
|
|
25
|
+
type: client.EventType.RUN_STARTED,
|
|
26
|
+
threadId: input.threadId,
|
|
27
|
+
runId: input.runId
|
|
28
|
+
});
|
|
29
|
+
this.agent.stream({
|
|
30
|
+
threadId: input.threadId,
|
|
31
|
+
resourceId: this.resourceId ?? "",
|
|
32
|
+
runId: input.runId,
|
|
33
|
+
messages: convertedMessages,
|
|
34
|
+
clientTools: input.tools.reduce(
|
|
35
|
+
(acc, tool) => {
|
|
36
|
+
acc[tool.name] = {
|
|
37
|
+
id: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
inputSchema: tool.parameters
|
|
40
|
+
};
|
|
41
|
+
return acc;
|
|
42
|
+
},
|
|
43
|
+
{}
|
|
44
|
+
)
|
|
45
|
+
}).then((response) => {
|
|
46
|
+
let currentMessageId = void 0;
|
|
47
|
+
return response.processDataStream({
|
|
48
|
+
onTextPart: (text) => {
|
|
49
|
+
if (currentMessageId === void 0) {
|
|
50
|
+
currentMessageId = generateUUID();
|
|
51
|
+
const message2 = {
|
|
52
|
+
type: client.EventType.TEXT_MESSAGE_START,
|
|
53
|
+
messageId: currentMessageId,
|
|
54
|
+
role: "assistant"
|
|
55
|
+
};
|
|
56
|
+
subscriber.next(message2);
|
|
57
|
+
}
|
|
58
|
+
const message = {
|
|
59
|
+
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
60
|
+
messageId: currentMessageId,
|
|
61
|
+
delta: text
|
|
62
|
+
};
|
|
63
|
+
subscriber.next(message);
|
|
64
|
+
},
|
|
65
|
+
onFinishMessagePart: (message) => {
|
|
66
|
+
console.log("onFinishMessagePart", message);
|
|
67
|
+
if (currentMessageId !== void 0) {
|
|
68
|
+
const message2 = {
|
|
69
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
70
|
+
messageId: currentMessageId
|
|
71
|
+
};
|
|
72
|
+
subscriber.next(message2);
|
|
73
|
+
}
|
|
74
|
+
subscriber.next({
|
|
75
|
+
type: client.EventType.RUN_FINISHED,
|
|
76
|
+
threadId: input.threadId,
|
|
77
|
+
runId: input.runId
|
|
78
|
+
});
|
|
79
|
+
subscriber.complete();
|
|
80
|
+
},
|
|
81
|
+
onToolCallPart(streamPart) {
|
|
82
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
83
|
+
subscriber.next({
|
|
84
|
+
type: client.EventType.TOOL_CALL_START,
|
|
85
|
+
toolCallId: streamPart.toolCallId,
|
|
86
|
+
toolCallName: streamPart.toolName,
|
|
87
|
+
parentMessageId
|
|
88
|
+
});
|
|
89
|
+
subscriber.next({
|
|
90
|
+
type: client.EventType.TOOL_CALL_ARGS,
|
|
91
|
+
toolCallId: streamPart.toolCallId,
|
|
92
|
+
delta: JSON.stringify(streamPart.args),
|
|
93
|
+
parentMessageId
|
|
94
|
+
});
|
|
95
|
+
subscriber.next({
|
|
96
|
+
type: client.EventType.TOOL_CALL_END,
|
|
97
|
+
toolCallId: streamPart.toolCallId,
|
|
98
|
+
parentMessageId
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
console.log("error", error);
|
|
104
|
+
subscriber.error(error);
|
|
105
|
+
});
|
|
106
|
+
return () => {
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function generateUUID() {
|
|
112
|
+
if (typeof crypto !== "undefined") {
|
|
113
|
+
if (typeof crypto.randomUUID === "function") {
|
|
114
|
+
return crypto.randomUUID();
|
|
115
|
+
}
|
|
116
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
117
|
+
const buffer = new Uint8Array(16);
|
|
118
|
+
crypto.getRandomValues(buffer);
|
|
119
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
120
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
121
|
+
let hex = "";
|
|
122
|
+
for (let i = 0; i < 16; i++) {
|
|
123
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
124
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
125
|
+
}
|
|
126
|
+
return hex;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
130
|
+
const r = Math.random() * 16 | 0;
|
|
131
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
132
|
+
return v.toString(16);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function convertMessagesToMastraMessages(messages) {
|
|
136
|
+
const result = [];
|
|
137
|
+
for (const message of messages) {
|
|
138
|
+
if (message.role === "assistant") {
|
|
139
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
140
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
141
|
+
parts.push({
|
|
142
|
+
type: "tool-call",
|
|
143
|
+
toolCallId: toolCall.id,
|
|
144
|
+
toolName: toolCall.function.name,
|
|
145
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
result.push({
|
|
149
|
+
role: "assistant",
|
|
150
|
+
content: parts
|
|
151
|
+
});
|
|
152
|
+
} else if (message.role === "user") {
|
|
153
|
+
result.push({
|
|
154
|
+
role: "user",
|
|
155
|
+
content: message.content || ""
|
|
156
|
+
});
|
|
157
|
+
} else if (message.role === "tool") {
|
|
158
|
+
result.push({
|
|
159
|
+
role: "tool",
|
|
160
|
+
content: [
|
|
161
|
+
{
|
|
162
|
+
type: "tool-result",
|
|
163
|
+
toolCallId: message.toolCallId,
|
|
164
|
+
toolName: "unknown",
|
|
165
|
+
result: message.content
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
8
173
|
|
|
9
174
|
// src/resources/base.ts
|
|
10
175
|
var BaseResource = class {
|
|
@@ -373,6 +538,13 @@ var Workflow = class extends BaseResource {
|
|
|
373
538
|
details() {
|
|
374
539
|
return this.request(`/api/workflows/${this.workflowId}`);
|
|
375
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Retrieves all runs for a workflow
|
|
543
|
+
* @returns Promise containing workflow runs array
|
|
544
|
+
*/
|
|
545
|
+
runs() {
|
|
546
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
547
|
+
}
|
|
376
548
|
/**
|
|
377
549
|
* @deprecated Use `startAsync` instead
|
|
378
550
|
* Executes the workflow with the provided parameters
|
|
@@ -489,7 +661,7 @@ var Workflow = class extends BaseResource {
|
|
|
489
661
|
}
|
|
490
662
|
}
|
|
491
663
|
}
|
|
492
|
-
} catch
|
|
664
|
+
} catch {
|
|
493
665
|
}
|
|
494
666
|
}
|
|
495
667
|
if (buffer) {
|
|
@@ -543,13 +715,180 @@ var Tool = class extends BaseResource {
|
|
|
543
715
|
* @returns Promise containing the tool execution results
|
|
544
716
|
*/
|
|
545
717
|
execute(params) {
|
|
546
|
-
|
|
718
|
+
const url = new URLSearchParams();
|
|
719
|
+
if (params.runId) {
|
|
720
|
+
url.set("runId", params.runId);
|
|
721
|
+
}
|
|
722
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
547
723
|
method: "POST",
|
|
548
|
-
body: params
|
|
724
|
+
body: params.data
|
|
549
725
|
});
|
|
550
726
|
}
|
|
551
727
|
};
|
|
552
728
|
|
|
729
|
+
// src/resources/vnext-workflow.ts
|
|
730
|
+
var RECORD_SEPARATOR2 = "";
|
|
731
|
+
var VNextWorkflow = class extends BaseResource {
|
|
732
|
+
constructor(options, workflowId) {
|
|
733
|
+
super(options);
|
|
734
|
+
this.workflowId = workflowId;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Creates an async generator that processes a readable stream and yields vNext workflow records
|
|
738
|
+
* separated by the Record Separator character (\x1E)
|
|
739
|
+
*
|
|
740
|
+
* @param stream - The readable stream to process
|
|
741
|
+
* @returns An async generator that yields parsed records
|
|
742
|
+
*/
|
|
743
|
+
async *streamProcessor(stream) {
|
|
744
|
+
const reader = stream.getReader();
|
|
745
|
+
let doneReading = false;
|
|
746
|
+
let buffer = "";
|
|
747
|
+
try {
|
|
748
|
+
while (!doneReading) {
|
|
749
|
+
const { done, value } = await reader.read();
|
|
750
|
+
doneReading = done;
|
|
751
|
+
if (done && !value) continue;
|
|
752
|
+
try {
|
|
753
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
754
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
755
|
+
buffer = chunks.pop() || "";
|
|
756
|
+
for (const chunk of chunks) {
|
|
757
|
+
if (chunk) {
|
|
758
|
+
if (typeof chunk === "string") {
|
|
759
|
+
try {
|
|
760
|
+
const parsedChunk = JSON.parse(chunk);
|
|
761
|
+
yield parsedChunk;
|
|
762
|
+
} catch {
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
} catch {
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (buffer) {
|
|
771
|
+
try {
|
|
772
|
+
yield JSON.parse(buffer);
|
|
773
|
+
} catch {
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
} finally {
|
|
777
|
+
reader.cancel().catch(() => {
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Retrieves details about the vNext workflow
|
|
783
|
+
* @returns Promise containing vNext workflow details including steps and graphs
|
|
784
|
+
*/
|
|
785
|
+
details() {
|
|
786
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}`);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Retrieves all runs for a vNext workflow
|
|
790
|
+
* @returns Promise containing vNext workflow runs array
|
|
791
|
+
*/
|
|
792
|
+
runs() {
|
|
793
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Creates a new vNext workflow run
|
|
797
|
+
* @param params - Optional object containing the optional runId
|
|
798
|
+
* @returns Promise containing the runId of the created run
|
|
799
|
+
*/
|
|
800
|
+
createRun(params) {
|
|
801
|
+
const searchParams = new URLSearchParams();
|
|
802
|
+
if (!!params?.runId) {
|
|
803
|
+
searchParams.set("runId", params.runId);
|
|
804
|
+
}
|
|
805
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
806
|
+
method: "POST"
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Starts a vNext workflow run synchronously without waiting for the workflow to complete
|
|
811
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
812
|
+
* @returns Promise containing success message
|
|
813
|
+
*/
|
|
814
|
+
start(params) {
|
|
815
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
816
|
+
method: "POST",
|
|
817
|
+
body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
|
|
822
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
823
|
+
* @returns Promise containing success message
|
|
824
|
+
*/
|
|
825
|
+
resume({
|
|
826
|
+
step,
|
|
827
|
+
runId,
|
|
828
|
+
resumeData,
|
|
829
|
+
runtimeContext
|
|
830
|
+
}) {
|
|
831
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
832
|
+
method: "POST",
|
|
833
|
+
stream: true,
|
|
834
|
+
body: {
|
|
835
|
+
step,
|
|
836
|
+
resumeData,
|
|
837
|
+
runtimeContext
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
843
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
844
|
+
* @returns Promise containing the vNext workflow execution results
|
|
845
|
+
*/
|
|
846
|
+
startAsync(params) {
|
|
847
|
+
const searchParams = new URLSearchParams();
|
|
848
|
+
if (!!params?.runId) {
|
|
849
|
+
searchParams.set("runId", params.runId);
|
|
850
|
+
}
|
|
851
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
852
|
+
method: "POST",
|
|
853
|
+
body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
858
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
859
|
+
* @returns Promise containing the vNext workflow resume results
|
|
860
|
+
*/
|
|
861
|
+
resumeAsync(params) {
|
|
862
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
863
|
+
method: "POST",
|
|
864
|
+
body: {
|
|
865
|
+
step: params.step,
|
|
866
|
+
resumeData: params.resumeData,
|
|
867
|
+
runtimeContext: params.runtimeContext
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Watches vNext workflow transitions in real-time
|
|
873
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
874
|
+
* @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
|
|
875
|
+
*/
|
|
876
|
+
async watch({ runId }, onRecord) {
|
|
877
|
+
const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
|
|
878
|
+
stream: true
|
|
879
|
+
});
|
|
880
|
+
if (!response.ok) {
|
|
881
|
+
throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
|
|
882
|
+
}
|
|
883
|
+
if (!response.body) {
|
|
884
|
+
throw new Error("Response body is null");
|
|
885
|
+
}
|
|
886
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
887
|
+
onRecord(record);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
|
|
553
892
|
// src/client.ts
|
|
554
893
|
var MastraClient = class extends BaseResource {
|
|
555
894
|
constructor(options) {
|
|
@@ -562,6 +901,21 @@ var MastraClient = class extends BaseResource {
|
|
|
562
901
|
getAgents() {
|
|
563
902
|
return this.request("/api/agents");
|
|
564
903
|
}
|
|
904
|
+
async getAGUI({ resourceId }) {
|
|
905
|
+
const agents = await this.getAgents();
|
|
906
|
+
return Object.entries(agents).reduce(
|
|
907
|
+
(acc, [agentId]) => {
|
|
908
|
+
const agent = this.getAgent(agentId);
|
|
909
|
+
acc[agentId] = new AGUIAdapter({
|
|
910
|
+
agentId,
|
|
911
|
+
agent,
|
|
912
|
+
resourceId
|
|
913
|
+
});
|
|
914
|
+
return acc;
|
|
915
|
+
},
|
|
916
|
+
{}
|
|
917
|
+
);
|
|
918
|
+
}
|
|
565
919
|
/**
|
|
566
920
|
* Gets an agent instance by ID
|
|
567
921
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -642,6 +996,21 @@ var MastraClient = class extends BaseResource {
|
|
|
642
996
|
getWorkflow(workflowId) {
|
|
643
997
|
return new Workflow(this.options, workflowId);
|
|
644
998
|
}
|
|
999
|
+
/**
|
|
1000
|
+
* Retrieves all available vNext workflows
|
|
1001
|
+
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1002
|
+
*/
|
|
1003
|
+
getVNextWorkflows() {
|
|
1004
|
+
return this.request("/api/workflows/v-next");
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Gets a vNext workflow instance by ID
|
|
1008
|
+
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1009
|
+
* @returns vNext Workflow instance
|
|
1010
|
+
*/
|
|
1011
|
+
getVNextWorkflow(workflowId) {
|
|
1012
|
+
return new VNextWorkflow(this.options, workflowId);
|
|
1013
|
+
}
|
|
645
1014
|
/**
|
|
646
1015
|
* Gets a vector instance by name
|
|
647
1016
|
* @param vectorName - Name of the vector to retrieve
|