@mastra/client-js 0.0.0-a2a-20250421213654 → 0.0.0-add-runtime-context-to-openai-realtime-20250516201052
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 +364 -2
- package/dist/index.cjs +632 -97
- package/dist/index.d.cts +285 -135
- package/dist/index.d.ts +285 -135
- package/dist/index.js +629 -96
- package/package.json +11 -6
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +119 -14
- package/src/example.ts +29 -30
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +60 -71
- package/src/resources/agent.ts +27 -36
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +2 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network.ts +6 -12
- package/src/resources/tool.ts +15 -3
- package/src/resources/vnext-workflow.ts +261 -0
- package/src/resources/workflow.ts +38 -2
- package/src/types.ts +80 -116
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,206 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var client = require('@ag-ui/client');
|
|
4
|
+
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
12
|
+
|
|
13
|
+
// src/adapters/agui.ts
|
|
14
|
+
var AGUIAdapter = class extends client.AbstractAgent {
|
|
15
|
+
agent;
|
|
16
|
+
resourceId;
|
|
17
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
18
|
+
super({
|
|
19
|
+
agentId,
|
|
20
|
+
...rest
|
|
21
|
+
});
|
|
22
|
+
this.agent = agent;
|
|
23
|
+
this.resourceId = resourceId;
|
|
24
|
+
}
|
|
25
|
+
run(input) {
|
|
26
|
+
return new rxjs.Observable((subscriber) => {
|
|
27
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
28
|
+
subscriber.next({
|
|
29
|
+
type: client.EventType.RUN_STARTED,
|
|
30
|
+
threadId: input.threadId,
|
|
31
|
+
runId: input.runId
|
|
32
|
+
});
|
|
33
|
+
this.agent.stream({
|
|
34
|
+
threadId: input.threadId,
|
|
35
|
+
resourceId: this.resourceId ?? "",
|
|
36
|
+
runId: input.runId,
|
|
37
|
+
messages: convertedMessages,
|
|
38
|
+
clientTools: input.tools.reduce(
|
|
39
|
+
(acc, tool) => {
|
|
40
|
+
acc[tool.name] = {
|
|
41
|
+
id: tool.name,
|
|
42
|
+
description: tool.description,
|
|
43
|
+
inputSchema: tool.parameters
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
},
|
|
47
|
+
{}
|
|
48
|
+
)
|
|
49
|
+
}).then((response) => {
|
|
50
|
+
let currentMessageId = void 0;
|
|
51
|
+
let isInTextMessage = false;
|
|
52
|
+
return response.processDataStream({
|
|
53
|
+
onTextPart: (text) => {
|
|
54
|
+
if (currentMessageId === void 0) {
|
|
55
|
+
currentMessageId = generateUUID();
|
|
56
|
+
const message2 = {
|
|
57
|
+
type: client.EventType.TEXT_MESSAGE_START,
|
|
58
|
+
messageId: currentMessageId,
|
|
59
|
+
role: "assistant"
|
|
60
|
+
};
|
|
61
|
+
subscriber.next(message2);
|
|
62
|
+
isInTextMessage = true;
|
|
63
|
+
}
|
|
64
|
+
const message = {
|
|
65
|
+
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
66
|
+
messageId: currentMessageId,
|
|
67
|
+
delta: text
|
|
68
|
+
};
|
|
69
|
+
subscriber.next(message);
|
|
70
|
+
},
|
|
71
|
+
onFinishMessagePart: () => {
|
|
72
|
+
if (currentMessageId !== void 0) {
|
|
73
|
+
const message = {
|
|
74
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
75
|
+
messageId: currentMessageId
|
|
76
|
+
};
|
|
77
|
+
subscriber.next(message);
|
|
78
|
+
isInTextMessage = false;
|
|
79
|
+
}
|
|
80
|
+
subscriber.next({
|
|
81
|
+
type: client.EventType.RUN_FINISHED,
|
|
82
|
+
threadId: input.threadId,
|
|
83
|
+
runId: input.runId
|
|
84
|
+
});
|
|
85
|
+
subscriber.complete();
|
|
86
|
+
},
|
|
87
|
+
onToolCallPart(streamPart) {
|
|
88
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
89
|
+
if (isInTextMessage) {
|
|
90
|
+
const message = {
|
|
91
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
92
|
+
messageId: parentMessageId
|
|
93
|
+
};
|
|
94
|
+
subscriber.next(message);
|
|
95
|
+
isInTextMessage = false;
|
|
96
|
+
}
|
|
97
|
+
subscriber.next({
|
|
98
|
+
type: client.EventType.TOOL_CALL_START,
|
|
99
|
+
toolCallId: streamPart.toolCallId,
|
|
100
|
+
toolCallName: streamPart.toolName,
|
|
101
|
+
parentMessageId
|
|
102
|
+
});
|
|
103
|
+
subscriber.next({
|
|
104
|
+
type: client.EventType.TOOL_CALL_ARGS,
|
|
105
|
+
toolCallId: streamPart.toolCallId,
|
|
106
|
+
delta: JSON.stringify(streamPart.args),
|
|
107
|
+
parentMessageId
|
|
108
|
+
});
|
|
109
|
+
subscriber.next({
|
|
110
|
+
type: client.EventType.TOOL_CALL_END,
|
|
111
|
+
toolCallId: streamPart.toolCallId,
|
|
112
|
+
parentMessageId
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}).catch((error) => {
|
|
117
|
+
console.error("error", error);
|
|
118
|
+
subscriber.error(error);
|
|
119
|
+
});
|
|
120
|
+
return () => {
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function generateUUID() {
|
|
126
|
+
if (typeof crypto !== "undefined") {
|
|
127
|
+
if (typeof crypto.randomUUID === "function") {
|
|
128
|
+
return crypto.randomUUID();
|
|
129
|
+
}
|
|
130
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
131
|
+
const buffer = new Uint8Array(16);
|
|
132
|
+
crypto.getRandomValues(buffer);
|
|
133
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
134
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
135
|
+
let hex = "";
|
|
136
|
+
for (let i = 0; i < 16; i++) {
|
|
137
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
138
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
139
|
+
}
|
|
140
|
+
return hex;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
144
|
+
const r = Math.random() * 16 | 0;
|
|
145
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
146
|
+
return v.toString(16);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function convertMessagesToMastraMessages(messages) {
|
|
150
|
+
const result = [];
|
|
151
|
+
for (const message of messages) {
|
|
152
|
+
if (message.role === "assistant") {
|
|
153
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
154
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
155
|
+
parts.push({
|
|
156
|
+
type: "tool-call",
|
|
157
|
+
toolCallId: toolCall.id,
|
|
158
|
+
toolName: toolCall.function.name,
|
|
159
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
result.push({
|
|
163
|
+
role: "assistant",
|
|
164
|
+
content: parts
|
|
165
|
+
});
|
|
166
|
+
if (message.toolCalls?.length) {
|
|
167
|
+
result.push({
|
|
168
|
+
role: "tool",
|
|
169
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
170
|
+
type: "tool-result",
|
|
171
|
+
toolCallId: toolCall.id,
|
|
172
|
+
toolName: toolCall.function.name,
|
|
173
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
174
|
+
}))
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} else if (message.role === "user") {
|
|
178
|
+
result.push({
|
|
179
|
+
role: "user",
|
|
180
|
+
content: message.content || ""
|
|
181
|
+
});
|
|
182
|
+
} else if (message.role === "tool") {
|
|
183
|
+
result.push({
|
|
184
|
+
role: "tool",
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
type: "tool-result",
|
|
188
|
+
toolCallId: message.toolCallId,
|
|
189
|
+
toolName: "unknown",
|
|
190
|
+
result: message.content
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function zodToJsonSchema(zodSchema) {
|
|
199
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
200
|
+
return zodSchema;
|
|
201
|
+
}
|
|
202
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
203
|
+
}
|
|
8
204
|
|
|
9
205
|
// src/resources/base.ts
|
|
10
206
|
var BaseResource = class {
|
|
@@ -24,7 +220,7 @@ var BaseResource = class {
|
|
|
24
220
|
let delay = backoffMs;
|
|
25
221
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
26
222
|
try {
|
|
27
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
223
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
28
224
|
...options,
|
|
29
225
|
headers: {
|
|
30
226
|
...headers,
|
|
@@ -135,8 +331,9 @@ var Agent = class extends BaseResource {
|
|
|
135
331
|
generate(params) {
|
|
136
332
|
const processedParams = {
|
|
137
333
|
...params,
|
|
138
|
-
output: params.output
|
|
139
|
-
experimental_output: params.experimental_output
|
|
334
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
335
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
336
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
140
337
|
};
|
|
141
338
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
142
339
|
method: "POST",
|
|
@@ -151,8 +348,9 @@ var Agent = class extends BaseResource {
|
|
|
151
348
|
async stream(params) {
|
|
152
349
|
const processedParams = {
|
|
153
350
|
...params,
|
|
154
|
-
output: params.output
|
|
155
|
-
experimental_output: params.experimental_output
|
|
351
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
352
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
353
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
156
354
|
};
|
|
157
355
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
158
356
|
method: "POST",
|
|
@@ -178,6 +376,22 @@ var Agent = class extends BaseResource {
|
|
|
178
376
|
getTool(toolId) {
|
|
179
377
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
180
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Executes a tool for the agent
|
|
381
|
+
* @param toolId - ID of the tool to execute
|
|
382
|
+
* @param params - Parameters required for tool execution
|
|
383
|
+
* @returns Promise containing the tool execution results
|
|
384
|
+
*/
|
|
385
|
+
executeTool(toolId, params) {
|
|
386
|
+
const body = {
|
|
387
|
+
data: params.data,
|
|
388
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
389
|
+
};
|
|
390
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
391
|
+
method: "POST",
|
|
392
|
+
body
|
|
393
|
+
});
|
|
394
|
+
}
|
|
181
395
|
/**
|
|
182
396
|
* Retrieves evaluation results for the agent
|
|
183
397
|
* @returns Promise containing agent evaluations
|
|
@@ -213,8 +427,8 @@ var Network = class extends BaseResource {
|
|
|
213
427
|
generate(params) {
|
|
214
428
|
const processedParams = {
|
|
215
429
|
...params,
|
|
216
|
-
output:
|
|
217
|
-
experimental_output:
|
|
430
|
+
output: zodToJsonSchema(params.output),
|
|
431
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
218
432
|
};
|
|
219
433
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
220
434
|
method: "POST",
|
|
@@ -229,8 +443,8 @@ var Network = class extends BaseResource {
|
|
|
229
443
|
async stream(params) {
|
|
230
444
|
const processedParams = {
|
|
231
445
|
...params,
|
|
232
|
-
output:
|
|
233
|
-
experimental_output:
|
|
446
|
+
output: zodToJsonSchema(params.output),
|
|
447
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
234
448
|
};
|
|
235
449
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
236
450
|
method: "POST",
|
|
@@ -286,10 +500,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
286
500
|
}
|
|
287
501
|
/**
|
|
288
502
|
* Retrieves messages associated with the thread
|
|
503
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
289
504
|
* @returns Promise containing thread messages and UI messages
|
|
290
505
|
*/
|
|
291
|
-
getMessages() {
|
|
292
|
-
|
|
506
|
+
getMessages(params) {
|
|
507
|
+
const query = new URLSearchParams({
|
|
508
|
+
agentId: this.agentId,
|
|
509
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
510
|
+
});
|
|
511
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
293
512
|
}
|
|
294
513
|
};
|
|
295
514
|
|
|
@@ -373,6 +592,34 @@ var Workflow = class extends BaseResource {
|
|
|
373
592
|
details() {
|
|
374
593
|
return this.request(`/api/workflows/${this.workflowId}`);
|
|
375
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Retrieves all runs for a workflow
|
|
597
|
+
* @param params - Parameters for filtering runs
|
|
598
|
+
* @returns Promise containing workflow runs array
|
|
599
|
+
*/
|
|
600
|
+
runs(params) {
|
|
601
|
+
const searchParams = new URLSearchParams();
|
|
602
|
+
if (params?.fromDate) {
|
|
603
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
604
|
+
}
|
|
605
|
+
if (params?.toDate) {
|
|
606
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
607
|
+
}
|
|
608
|
+
if (params?.limit) {
|
|
609
|
+
searchParams.set("limit", String(params.limit));
|
|
610
|
+
}
|
|
611
|
+
if (params?.offset) {
|
|
612
|
+
searchParams.set("offset", String(params.offset));
|
|
613
|
+
}
|
|
614
|
+
if (params?.resourceId) {
|
|
615
|
+
searchParams.set("resourceId", params.resourceId);
|
|
616
|
+
}
|
|
617
|
+
if (searchParams.size) {
|
|
618
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
619
|
+
} else {
|
|
620
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
376
623
|
/**
|
|
377
624
|
* @deprecated Use `startAsync` instead
|
|
378
625
|
* Executes the workflow with the provided parameters
|
|
@@ -489,7 +736,7 @@ var Workflow = class extends BaseResource {
|
|
|
489
736
|
}
|
|
490
737
|
}
|
|
491
738
|
}
|
|
492
|
-
} catch
|
|
739
|
+
} catch {
|
|
493
740
|
}
|
|
494
741
|
}
|
|
495
742
|
if (buffer) {
|
|
@@ -543,89 +790,314 @@ var Tool = class extends BaseResource {
|
|
|
543
790
|
* @returns Promise containing the tool execution results
|
|
544
791
|
*/
|
|
545
792
|
execute(params) {
|
|
546
|
-
|
|
793
|
+
const url = new URLSearchParams();
|
|
794
|
+
if (params.runId) {
|
|
795
|
+
url.set("runId", params.runId);
|
|
796
|
+
}
|
|
797
|
+
const body = {
|
|
798
|
+
data: params.data,
|
|
799
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
800
|
+
};
|
|
801
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
547
802
|
method: "POST",
|
|
548
|
-
body
|
|
803
|
+
body
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// src/resources/vnext-workflow.ts
|
|
809
|
+
var RECORD_SEPARATOR2 = "";
|
|
810
|
+
var VNextWorkflow = class extends BaseResource {
|
|
811
|
+
constructor(options, workflowId) {
|
|
812
|
+
super(options);
|
|
813
|
+
this.workflowId = workflowId;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Creates an async generator that processes a readable stream and yields vNext workflow records
|
|
817
|
+
* separated by the Record Separator character (\x1E)
|
|
818
|
+
*
|
|
819
|
+
* @param stream - The readable stream to process
|
|
820
|
+
* @returns An async generator that yields parsed records
|
|
821
|
+
*/
|
|
822
|
+
async *streamProcessor(stream) {
|
|
823
|
+
const reader = stream.getReader();
|
|
824
|
+
let doneReading = false;
|
|
825
|
+
let buffer = "";
|
|
826
|
+
try {
|
|
827
|
+
while (!doneReading) {
|
|
828
|
+
const { done, value } = await reader.read();
|
|
829
|
+
doneReading = done;
|
|
830
|
+
if (done && !value) continue;
|
|
831
|
+
try {
|
|
832
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
833
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
834
|
+
buffer = chunks.pop() || "";
|
|
835
|
+
for (const chunk of chunks) {
|
|
836
|
+
if (chunk) {
|
|
837
|
+
if (typeof chunk === "string") {
|
|
838
|
+
try {
|
|
839
|
+
const parsedChunk = JSON.parse(chunk);
|
|
840
|
+
yield parsedChunk;
|
|
841
|
+
} catch {
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
} catch {
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
if (buffer) {
|
|
850
|
+
try {
|
|
851
|
+
yield JSON.parse(buffer);
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
} finally {
|
|
856
|
+
reader.cancel().catch(() => {
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Retrieves details about the vNext workflow
|
|
862
|
+
* @returns Promise containing vNext workflow details including steps and graphs
|
|
863
|
+
*/
|
|
864
|
+
details() {
|
|
865
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}`);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Retrieves all runs for a vNext workflow
|
|
869
|
+
* @param params - Parameters for filtering runs
|
|
870
|
+
* @returns Promise containing vNext workflow runs array
|
|
871
|
+
*/
|
|
872
|
+
runs(params) {
|
|
873
|
+
const searchParams = new URLSearchParams();
|
|
874
|
+
if (params?.fromDate) {
|
|
875
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
876
|
+
}
|
|
877
|
+
if (params?.toDate) {
|
|
878
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
879
|
+
}
|
|
880
|
+
if (params?.limit) {
|
|
881
|
+
searchParams.set("limit", String(params.limit));
|
|
882
|
+
}
|
|
883
|
+
if (params?.offset) {
|
|
884
|
+
searchParams.set("offset", String(params.offset));
|
|
885
|
+
}
|
|
886
|
+
if (params?.resourceId) {
|
|
887
|
+
searchParams.set("resourceId", params.resourceId);
|
|
888
|
+
}
|
|
889
|
+
if (searchParams.size) {
|
|
890
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
891
|
+
} else {
|
|
892
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Creates a new vNext workflow run
|
|
897
|
+
* @param params - Optional object containing the optional runId
|
|
898
|
+
* @returns Promise containing the runId of the created run
|
|
899
|
+
*/
|
|
900
|
+
createRun(params) {
|
|
901
|
+
const searchParams = new URLSearchParams();
|
|
902
|
+
if (!!params?.runId) {
|
|
903
|
+
searchParams.set("runId", params.runId);
|
|
904
|
+
}
|
|
905
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
906
|
+
method: "POST"
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Starts a vNext workflow run synchronously without waiting for the workflow to complete
|
|
911
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
912
|
+
* @returns Promise containing success message
|
|
913
|
+
*/
|
|
914
|
+
start(params) {
|
|
915
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
916
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
917
|
+
method: "POST",
|
|
918
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
|
|
923
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
924
|
+
* @returns Promise containing success message
|
|
925
|
+
*/
|
|
926
|
+
resume({
|
|
927
|
+
step,
|
|
928
|
+
runId,
|
|
929
|
+
resumeData,
|
|
930
|
+
...rest
|
|
931
|
+
}) {
|
|
932
|
+
const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
|
|
933
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
934
|
+
method: "POST",
|
|
935
|
+
stream: true,
|
|
936
|
+
body: {
|
|
937
|
+
step,
|
|
938
|
+
resumeData,
|
|
939
|
+
runtimeContext
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
945
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
946
|
+
* @returns Promise containing the vNext workflow execution results
|
|
947
|
+
*/
|
|
948
|
+
startAsync(params) {
|
|
949
|
+
const searchParams = new URLSearchParams();
|
|
950
|
+
if (!!params?.runId) {
|
|
951
|
+
searchParams.set("runId", params.runId);
|
|
952
|
+
}
|
|
953
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
954
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
955
|
+
method: "POST",
|
|
956
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
961
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
962
|
+
* @returns Promise containing the vNext workflow resume results
|
|
963
|
+
*/
|
|
964
|
+
resumeAsync(params) {
|
|
965
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
966
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
967
|
+
method: "POST",
|
|
968
|
+
body: {
|
|
969
|
+
step: params.step,
|
|
970
|
+
resumeData: params.resumeData,
|
|
971
|
+
runtimeContext
|
|
972
|
+
}
|
|
549
973
|
});
|
|
550
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Watches vNext workflow transitions in real-time
|
|
977
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
978
|
+
* @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
|
|
979
|
+
*/
|
|
980
|
+
async watch({ runId }, onRecord) {
|
|
981
|
+
const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
|
|
982
|
+
stream: true
|
|
983
|
+
});
|
|
984
|
+
if (!response.ok) {
|
|
985
|
+
throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
|
|
986
|
+
}
|
|
987
|
+
if (!response.body) {
|
|
988
|
+
throw new Error("Response body is null");
|
|
989
|
+
}
|
|
990
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
991
|
+
onRecord(record);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
551
994
|
};
|
|
552
995
|
|
|
553
996
|
// src/resources/a2a.ts
|
|
554
997
|
var A2A = class extends BaseResource {
|
|
998
|
+
constructor(options, agentId) {
|
|
999
|
+
super(options);
|
|
1000
|
+
this.agentId = agentId;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Get the agent card with metadata about the agent
|
|
1004
|
+
* @returns Promise containing the agent card information
|
|
1005
|
+
*/
|
|
1006
|
+
async getCard() {
|
|
1007
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1008
|
+
}
|
|
555
1009
|
/**
|
|
556
|
-
*
|
|
557
|
-
* @param
|
|
558
|
-
* @returns Promise containing the
|
|
1010
|
+
* Send a message to the agent and get a response
|
|
1011
|
+
* @param params - Parameters for the task
|
|
1012
|
+
* @returns Promise containing the task response
|
|
559
1013
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
1014
|
+
async sendMessage(params) {
|
|
1015
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
562
1016
|
method: "POST",
|
|
563
|
-
body:
|
|
1017
|
+
body: {
|
|
1018
|
+
method: "tasks/send",
|
|
1019
|
+
params
|
|
1020
|
+
}
|
|
564
1021
|
});
|
|
1022
|
+
return { task: response.result };
|
|
565
1023
|
}
|
|
566
1024
|
/**
|
|
567
|
-
*
|
|
568
|
-
* @param params - Parameters for
|
|
569
|
-
* @returns Promise containing the task
|
|
1025
|
+
* Get the status and result of a task
|
|
1026
|
+
* @param params - Parameters for querying the task
|
|
1027
|
+
* @returns Promise containing the task response
|
|
570
1028
|
*/
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
};
|
|
578
|
-
return this.sendRequest(request).then((response) => {
|
|
579
|
-
if ("error" in response) {
|
|
580
|
-
throw new Error(response.error.message);
|
|
1029
|
+
async getTask(params) {
|
|
1030
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1031
|
+
method: "POST",
|
|
1032
|
+
body: {
|
|
1033
|
+
method: "tasks/get",
|
|
1034
|
+
params
|
|
581
1035
|
}
|
|
582
|
-
return response.result;
|
|
583
1036
|
});
|
|
1037
|
+
return response.result;
|
|
584
1038
|
}
|
|
585
1039
|
/**
|
|
586
|
-
*
|
|
587
|
-
* @param params - Parameters
|
|
588
|
-
* @returns Promise containing the task
|
|
1040
|
+
* Cancel a running task
|
|
1041
|
+
* @param params - Parameters identifying the task to cancel
|
|
1042
|
+
* @returns Promise containing the task response
|
|
589
1043
|
*/
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
};
|
|
597
|
-
return this.sendRequest(request).then((response) => {
|
|
598
|
-
if ("error" in response) {
|
|
599
|
-
throw new Error(response.error.message);
|
|
1044
|
+
async cancelTask(params) {
|
|
1045
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1046
|
+
method: "POST",
|
|
1047
|
+
body: {
|
|
1048
|
+
method: "tasks/cancel",
|
|
1049
|
+
params
|
|
600
1050
|
}
|
|
601
|
-
return response.result;
|
|
602
1051
|
});
|
|
603
1052
|
}
|
|
604
1053
|
/**
|
|
605
|
-
*
|
|
606
|
-
* @param params - Parameters for
|
|
607
|
-
* @returns Promise containing the task
|
|
1054
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1055
|
+
* @param params - Parameters for the task
|
|
1056
|
+
* @returns Promise containing the task response
|
|
608
1057
|
*/
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
if ("error" in response) {
|
|
618
|
-
throw new Error(response.error.message);
|
|
619
|
-
}
|
|
620
|
-
return response.result;
|
|
1058
|
+
async sendAndSubscribe(params) {
|
|
1059
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1060
|
+
method: "POST",
|
|
1061
|
+
body: {
|
|
1062
|
+
method: "tasks/sendSubscribe",
|
|
1063
|
+
params
|
|
1064
|
+
},
|
|
1065
|
+
stream: true
|
|
621
1066
|
});
|
|
622
1067
|
}
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
// src/resources/mcp-tool.ts
|
|
1071
|
+
var MCPTool = class extends BaseResource {
|
|
1072
|
+
serverId;
|
|
1073
|
+
toolId;
|
|
1074
|
+
constructor(options, serverId, toolId) {
|
|
1075
|
+
super(options);
|
|
1076
|
+
this.serverId = serverId;
|
|
1077
|
+
this.toolId = toolId;
|
|
1078
|
+
}
|
|
623
1079
|
/**
|
|
624
|
-
*
|
|
625
|
-
* @returns Promise containing the
|
|
1080
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1081
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
626
1082
|
*/
|
|
627
|
-
|
|
628
|
-
return this.request(
|
|
1083
|
+
details() {
|
|
1084
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Executes this specific tool on the MCP server.
|
|
1088
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1089
|
+
* @returns Promise containing the result of the tool execution.
|
|
1090
|
+
*/
|
|
1091
|
+
execute(params) {
|
|
1092
|
+
const body = {};
|
|
1093
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1094
|
+
if (params.runtimeContext !== void 0) {
|
|
1095
|
+
body.runtimeContext = params.runtimeContext;
|
|
1096
|
+
}
|
|
1097
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1098
|
+
method: "POST",
|
|
1099
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1100
|
+
});
|
|
629
1101
|
}
|
|
630
1102
|
};
|
|
631
1103
|
|
|
@@ -641,6 +1113,21 @@ var MastraClient = class extends BaseResource {
|
|
|
641
1113
|
getAgents() {
|
|
642
1114
|
return this.request("/api/agents");
|
|
643
1115
|
}
|
|
1116
|
+
async getAGUI({ resourceId }) {
|
|
1117
|
+
const agents = await this.getAgents();
|
|
1118
|
+
return Object.entries(agents).reduce(
|
|
1119
|
+
(acc, [agentId]) => {
|
|
1120
|
+
const agent = this.getAgent(agentId);
|
|
1121
|
+
acc[agentId] = new AGUIAdapter({
|
|
1122
|
+
agentId,
|
|
1123
|
+
agent,
|
|
1124
|
+
resourceId
|
|
1125
|
+
});
|
|
1126
|
+
return acc;
|
|
1127
|
+
},
|
|
1128
|
+
{}
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
644
1131
|
/**
|
|
645
1132
|
* Gets an agent instance by ID
|
|
646
1133
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -721,6 +1208,21 @@ var MastraClient = class extends BaseResource {
|
|
|
721
1208
|
getWorkflow(workflowId) {
|
|
722
1209
|
return new Workflow(this.options, workflowId);
|
|
723
1210
|
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Retrieves all available vNext workflows
|
|
1213
|
+
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1214
|
+
*/
|
|
1215
|
+
getVNextWorkflows() {
|
|
1216
|
+
return this.request("/api/workflows/v-next");
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Gets a vNext workflow instance by ID
|
|
1220
|
+
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1221
|
+
* @returns vNext Workflow instance
|
|
1222
|
+
*/
|
|
1223
|
+
getVNextWorkflow(workflowId) {
|
|
1224
|
+
return new VNextWorkflow(this.options, workflowId);
|
|
1225
|
+
}
|
|
724
1226
|
/**
|
|
725
1227
|
* Gets a vector instance by name
|
|
726
1228
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -758,7 +1260,7 @@ var MastraClient = class extends BaseResource {
|
|
|
758
1260
|
* @returns Promise containing telemetry data
|
|
759
1261
|
*/
|
|
760
1262
|
getTelemetry(params) {
|
|
761
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1263
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
762
1264
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
763
1265
|
const searchParams = new URLSearchParams();
|
|
764
1266
|
if (name) {
|
|
@@ -782,6 +1284,12 @@ var MastraClient = class extends BaseResource {
|
|
|
782
1284
|
searchParams.set("attribute", _attribute);
|
|
783
1285
|
}
|
|
784
1286
|
}
|
|
1287
|
+
if (fromDate) {
|
|
1288
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1289
|
+
}
|
|
1290
|
+
if (toDate) {
|
|
1291
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1292
|
+
}
|
|
785
1293
|
if (searchParams.size) {
|
|
786
1294
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
787
1295
|
} else {
|
|
@@ -804,34 +1312,61 @@ var MastraClient = class extends BaseResource {
|
|
|
804
1312
|
return new Network(this.options, networkId);
|
|
805
1313
|
}
|
|
806
1314
|
/**
|
|
807
|
-
*
|
|
808
|
-
* @
|
|
1315
|
+
* Retrieves a list of available MCP servers.
|
|
1316
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1317
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
809
1318
|
*/
|
|
810
|
-
|
|
811
|
-
|
|
1319
|
+
getMcpServers(params) {
|
|
1320
|
+
const searchParams = new URLSearchParams();
|
|
1321
|
+
if (params?.limit !== void 0) {
|
|
1322
|
+
searchParams.set("limit", String(params.limit));
|
|
1323
|
+
}
|
|
1324
|
+
if (params?.offset !== void 0) {
|
|
1325
|
+
searchParams.set("offset", String(params.offset));
|
|
1326
|
+
}
|
|
1327
|
+
const queryString = searchParams.toString();
|
|
1328
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1332
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1333
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1334
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1335
|
+
*/
|
|
1336
|
+
getMcpServerDetails(serverId, params) {
|
|
1337
|
+
const searchParams = new URLSearchParams();
|
|
1338
|
+
if (params?.version) {
|
|
1339
|
+
searchParams.set("version", params.version);
|
|
1340
|
+
}
|
|
1341
|
+
const queryString = searchParams.toString();
|
|
1342
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1346
|
+
* @param serverId - The ID of the MCP server.
|
|
1347
|
+
* @returns Promise containing the list of tools.
|
|
1348
|
+
*/
|
|
1349
|
+
getMcpServerTools(serverId) {
|
|
1350
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1354
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1355
|
+
* @param serverId - The ID of the MCP server.
|
|
1356
|
+
* @param toolId - The ID of the tool.
|
|
1357
|
+
* @returns MCPTool instance.
|
|
1358
|
+
*/
|
|
1359
|
+
getMcpServerTool(serverId, toolId) {
|
|
1360
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1364
|
+
* @param agentId - ID of the agent to interact with
|
|
1365
|
+
* @returns A2A client instance
|
|
1366
|
+
*/
|
|
1367
|
+
getA2A(agentId) {
|
|
1368
|
+
return new A2A(this.options, agentId);
|
|
812
1369
|
}
|
|
813
1370
|
};
|
|
814
1371
|
|
|
815
|
-
// src/types.ts
|
|
816
|
-
var TaskState = /* @__PURE__ */ ((TaskState2) => {
|
|
817
|
-
TaskState2["PENDING"] = "pending";
|
|
818
|
-
TaskState2["RUNNING"] = "running";
|
|
819
|
-
TaskState2["COMPLETED"] = "completed";
|
|
820
|
-
TaskState2["FAILED"] = "failed";
|
|
821
|
-
TaskState2["CANCELED"] = "canceled";
|
|
822
|
-
return TaskState2;
|
|
823
|
-
})(TaskState || {});
|
|
824
|
-
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
825
|
-
ErrorCode2[ErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
826
|
-
ErrorCode2[ErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
827
|
-
ErrorCode2[ErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
828
|
-
ErrorCode2[ErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
829
|
-
ErrorCode2[ErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
830
|
-
ErrorCode2[ErrorCode2["TASK_NOT_FOUND"] = -32e3] = "TASK_NOT_FOUND";
|
|
831
|
-
ErrorCode2[ErrorCode2["TASK_NOT_CANCELABLE"] = -32001] = "TASK_NOT_CANCELABLE";
|
|
832
|
-
return ErrorCode2;
|
|
833
|
-
})(ErrorCode || {});
|
|
834
|
-
|
|
835
|
-
exports.ErrorCode = ErrorCode;
|
|
836
1372
|
exports.MastraClient = MastraClient;
|
|
837
|
-
exports.TaskState = TaskState;
|