@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-vector-query-sources-20250516172905
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 +325 -2
- package/dist/index.cjs +661 -18
- package/dist/index.d.cts +305 -7
- package/dist/index.d.ts +305 -7
- package/dist/index.js +657 -18
- package/package.json +9 -7
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +123 -2
- package/src/example.ts +29 -30
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +27 -36
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +3 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- 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 +86 -2
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
|
+
import { ZodSchema } from 'zod';
|
|
5
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
4
6
|
|
|
5
|
-
// src/
|
|
7
|
+
// src/adapters/agui.ts
|
|
8
|
+
var AGUIAdapter = class extends AbstractAgent {
|
|
9
|
+
agent;
|
|
10
|
+
resourceId;
|
|
11
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
12
|
+
super({
|
|
13
|
+
agentId,
|
|
14
|
+
...rest
|
|
15
|
+
});
|
|
16
|
+
this.agent = agent;
|
|
17
|
+
this.resourceId = resourceId;
|
|
18
|
+
}
|
|
19
|
+
run(input) {
|
|
20
|
+
return new Observable((subscriber) => {
|
|
21
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
22
|
+
subscriber.next({
|
|
23
|
+
type: EventType.RUN_STARTED,
|
|
24
|
+
threadId: input.threadId,
|
|
25
|
+
runId: input.runId
|
|
26
|
+
});
|
|
27
|
+
this.agent.stream({
|
|
28
|
+
threadId: input.threadId,
|
|
29
|
+
resourceId: this.resourceId ?? "",
|
|
30
|
+
runId: input.runId,
|
|
31
|
+
messages: convertedMessages,
|
|
32
|
+
clientTools: input.tools.reduce(
|
|
33
|
+
(acc, tool) => {
|
|
34
|
+
acc[tool.name] = {
|
|
35
|
+
id: tool.name,
|
|
36
|
+
description: tool.description,
|
|
37
|
+
inputSchema: tool.parameters
|
|
38
|
+
};
|
|
39
|
+
return acc;
|
|
40
|
+
},
|
|
41
|
+
{}
|
|
42
|
+
)
|
|
43
|
+
}).then((response) => {
|
|
44
|
+
let currentMessageId = void 0;
|
|
45
|
+
let isInTextMessage = false;
|
|
46
|
+
return response.processDataStream({
|
|
47
|
+
onTextPart: (text) => {
|
|
48
|
+
if (currentMessageId === void 0) {
|
|
49
|
+
currentMessageId = generateUUID();
|
|
50
|
+
const message2 = {
|
|
51
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
52
|
+
messageId: currentMessageId,
|
|
53
|
+
role: "assistant"
|
|
54
|
+
};
|
|
55
|
+
subscriber.next(message2);
|
|
56
|
+
isInTextMessage = true;
|
|
57
|
+
}
|
|
58
|
+
const message = {
|
|
59
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
60
|
+
messageId: currentMessageId,
|
|
61
|
+
delta: text
|
|
62
|
+
};
|
|
63
|
+
subscriber.next(message);
|
|
64
|
+
},
|
|
65
|
+
onFinishMessagePart: () => {
|
|
66
|
+
if (currentMessageId !== void 0) {
|
|
67
|
+
const message = {
|
|
68
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
69
|
+
messageId: currentMessageId
|
|
70
|
+
};
|
|
71
|
+
subscriber.next(message);
|
|
72
|
+
isInTextMessage = false;
|
|
73
|
+
}
|
|
74
|
+
subscriber.next({
|
|
75
|
+
type: 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
|
+
if (isInTextMessage) {
|
|
84
|
+
const message = {
|
|
85
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
86
|
+
messageId: parentMessageId
|
|
87
|
+
};
|
|
88
|
+
subscriber.next(message);
|
|
89
|
+
isInTextMessage = false;
|
|
90
|
+
}
|
|
91
|
+
subscriber.next({
|
|
92
|
+
type: EventType.TOOL_CALL_START,
|
|
93
|
+
toolCallId: streamPart.toolCallId,
|
|
94
|
+
toolCallName: streamPart.toolName,
|
|
95
|
+
parentMessageId
|
|
96
|
+
});
|
|
97
|
+
subscriber.next({
|
|
98
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
99
|
+
toolCallId: streamPart.toolCallId,
|
|
100
|
+
delta: JSON.stringify(streamPart.args),
|
|
101
|
+
parentMessageId
|
|
102
|
+
});
|
|
103
|
+
subscriber.next({
|
|
104
|
+
type: EventType.TOOL_CALL_END,
|
|
105
|
+
toolCallId: streamPart.toolCallId,
|
|
106
|
+
parentMessageId
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}).catch((error) => {
|
|
111
|
+
console.error("error", error);
|
|
112
|
+
subscriber.error(error);
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function generateUUID() {
|
|
120
|
+
if (typeof crypto !== "undefined") {
|
|
121
|
+
if (typeof crypto.randomUUID === "function") {
|
|
122
|
+
return crypto.randomUUID();
|
|
123
|
+
}
|
|
124
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
125
|
+
const buffer = new Uint8Array(16);
|
|
126
|
+
crypto.getRandomValues(buffer);
|
|
127
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
128
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
129
|
+
let hex = "";
|
|
130
|
+
for (let i = 0; i < 16; i++) {
|
|
131
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
132
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
133
|
+
}
|
|
134
|
+
return hex;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
138
|
+
const r = Math.random() * 16 | 0;
|
|
139
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
140
|
+
return v.toString(16);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function convertMessagesToMastraMessages(messages) {
|
|
144
|
+
const result = [];
|
|
145
|
+
for (const message of messages) {
|
|
146
|
+
if (message.role === "assistant") {
|
|
147
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
148
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
149
|
+
parts.push({
|
|
150
|
+
type: "tool-call",
|
|
151
|
+
toolCallId: toolCall.id,
|
|
152
|
+
toolName: toolCall.function.name,
|
|
153
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
result.push({
|
|
157
|
+
role: "assistant",
|
|
158
|
+
content: parts
|
|
159
|
+
});
|
|
160
|
+
if (message.toolCalls?.length) {
|
|
161
|
+
result.push({
|
|
162
|
+
role: "tool",
|
|
163
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
164
|
+
type: "tool-result",
|
|
165
|
+
toolCallId: toolCall.id,
|
|
166
|
+
toolName: toolCall.function.name,
|
|
167
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
168
|
+
}))
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
} else if (message.role === "user") {
|
|
172
|
+
result.push({
|
|
173
|
+
role: "user",
|
|
174
|
+
content: message.content || ""
|
|
175
|
+
});
|
|
176
|
+
} else if (message.role === "tool") {
|
|
177
|
+
result.push({
|
|
178
|
+
role: "tool",
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
type: "tool-result",
|
|
182
|
+
toolCallId: message.toolCallId,
|
|
183
|
+
toolName: "unknown",
|
|
184
|
+
result: message.content
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
function zodToJsonSchema(zodSchema) {
|
|
193
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
194
|
+
return zodSchema;
|
|
195
|
+
}
|
|
196
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
197
|
+
}
|
|
6
198
|
|
|
7
199
|
// src/resources/base.ts
|
|
8
200
|
var BaseResource = class {
|
|
@@ -22,7 +214,7 @@ var BaseResource = class {
|
|
|
22
214
|
let delay = backoffMs;
|
|
23
215
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
24
216
|
try {
|
|
25
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
217
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
26
218
|
...options,
|
|
27
219
|
headers: {
|
|
28
220
|
...headers,
|
|
@@ -133,8 +325,9 @@ var Agent = class extends BaseResource {
|
|
|
133
325
|
generate(params) {
|
|
134
326
|
const processedParams = {
|
|
135
327
|
...params,
|
|
136
|
-
output: params.output
|
|
137
|
-
experimental_output: params.experimental_output
|
|
328
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
329
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
330
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
138
331
|
};
|
|
139
332
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
140
333
|
method: "POST",
|
|
@@ -149,8 +342,9 @@ var Agent = class extends BaseResource {
|
|
|
149
342
|
async stream(params) {
|
|
150
343
|
const processedParams = {
|
|
151
344
|
...params,
|
|
152
|
-
output: params.output
|
|
153
|
-
experimental_output: params.experimental_output
|
|
345
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
346
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
347
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
154
348
|
};
|
|
155
349
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
156
350
|
method: "POST",
|
|
@@ -176,6 +370,22 @@ var Agent = class extends BaseResource {
|
|
|
176
370
|
getTool(toolId) {
|
|
177
371
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
178
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Executes a tool for the agent
|
|
375
|
+
* @param toolId - ID of the tool to execute
|
|
376
|
+
* @param params - Parameters required for tool execution
|
|
377
|
+
* @returns Promise containing the tool execution results
|
|
378
|
+
*/
|
|
379
|
+
executeTool(toolId, params) {
|
|
380
|
+
const body = {
|
|
381
|
+
data: params.data,
|
|
382
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
383
|
+
};
|
|
384
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
385
|
+
method: "POST",
|
|
386
|
+
body
|
|
387
|
+
});
|
|
388
|
+
}
|
|
179
389
|
/**
|
|
180
390
|
* Retrieves evaluation results for the agent
|
|
181
391
|
* @returns Promise containing agent evaluations
|
|
@@ -211,8 +421,8 @@ var Network = class extends BaseResource {
|
|
|
211
421
|
generate(params) {
|
|
212
422
|
const processedParams = {
|
|
213
423
|
...params,
|
|
214
|
-
output:
|
|
215
|
-
experimental_output:
|
|
424
|
+
output: zodToJsonSchema(params.output),
|
|
425
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
216
426
|
};
|
|
217
427
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
218
428
|
method: "POST",
|
|
@@ -227,8 +437,8 @@ var Network = class extends BaseResource {
|
|
|
227
437
|
async stream(params) {
|
|
228
438
|
const processedParams = {
|
|
229
439
|
...params,
|
|
230
|
-
output:
|
|
231
|
-
experimental_output:
|
|
440
|
+
output: zodToJsonSchema(params.output),
|
|
441
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
232
442
|
};
|
|
233
443
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
234
444
|
method: "POST",
|
|
@@ -284,10 +494,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
284
494
|
}
|
|
285
495
|
/**
|
|
286
496
|
* Retrieves messages associated with the thread
|
|
497
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
287
498
|
* @returns Promise containing thread messages and UI messages
|
|
288
499
|
*/
|
|
289
|
-
getMessages() {
|
|
290
|
-
|
|
500
|
+
getMessages(params) {
|
|
501
|
+
const query = new URLSearchParams({
|
|
502
|
+
agentId: this.agentId,
|
|
503
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
504
|
+
});
|
|
505
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
291
506
|
}
|
|
292
507
|
};
|
|
293
508
|
|
|
@@ -371,6 +586,34 @@ var Workflow = class extends BaseResource {
|
|
|
371
586
|
details() {
|
|
372
587
|
return this.request(`/api/workflows/${this.workflowId}`);
|
|
373
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* Retrieves all runs for a workflow
|
|
591
|
+
* @param params - Parameters for filtering runs
|
|
592
|
+
* @returns Promise containing workflow runs array
|
|
593
|
+
*/
|
|
594
|
+
runs(params) {
|
|
595
|
+
const searchParams = new URLSearchParams();
|
|
596
|
+
if (params?.fromDate) {
|
|
597
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
598
|
+
}
|
|
599
|
+
if (params?.toDate) {
|
|
600
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
601
|
+
}
|
|
602
|
+
if (params?.limit) {
|
|
603
|
+
searchParams.set("limit", String(params.limit));
|
|
604
|
+
}
|
|
605
|
+
if (params?.offset) {
|
|
606
|
+
searchParams.set("offset", String(params.offset));
|
|
607
|
+
}
|
|
608
|
+
if (params?.resourceId) {
|
|
609
|
+
searchParams.set("resourceId", params.resourceId);
|
|
610
|
+
}
|
|
611
|
+
if (searchParams.size) {
|
|
612
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
613
|
+
} else {
|
|
614
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
374
617
|
/**
|
|
375
618
|
* @deprecated Use `startAsync` instead
|
|
376
619
|
* Executes the workflow with the provided parameters
|
|
@@ -487,7 +730,7 @@ var Workflow = class extends BaseResource {
|
|
|
487
730
|
}
|
|
488
731
|
}
|
|
489
732
|
}
|
|
490
|
-
} catch
|
|
733
|
+
} catch {
|
|
491
734
|
}
|
|
492
735
|
}
|
|
493
736
|
if (buffer) {
|
|
@@ -541,9 +784,313 @@ var Tool = class extends BaseResource {
|
|
|
541
784
|
* @returns Promise containing the tool execution results
|
|
542
785
|
*/
|
|
543
786
|
execute(params) {
|
|
544
|
-
|
|
787
|
+
const url = new URLSearchParams();
|
|
788
|
+
if (params.runId) {
|
|
789
|
+
url.set("runId", params.runId);
|
|
790
|
+
}
|
|
791
|
+
const body = {
|
|
792
|
+
data: params.data,
|
|
793
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
794
|
+
};
|
|
795
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
545
796
|
method: "POST",
|
|
546
|
-
body
|
|
797
|
+
body
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// src/resources/vnext-workflow.ts
|
|
803
|
+
var RECORD_SEPARATOR2 = "";
|
|
804
|
+
var VNextWorkflow = class extends BaseResource {
|
|
805
|
+
constructor(options, workflowId) {
|
|
806
|
+
super(options);
|
|
807
|
+
this.workflowId = workflowId;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Creates an async generator that processes a readable stream and yields vNext workflow records
|
|
811
|
+
* separated by the Record Separator character (\x1E)
|
|
812
|
+
*
|
|
813
|
+
* @param stream - The readable stream to process
|
|
814
|
+
* @returns An async generator that yields parsed records
|
|
815
|
+
*/
|
|
816
|
+
async *streamProcessor(stream) {
|
|
817
|
+
const reader = stream.getReader();
|
|
818
|
+
let doneReading = false;
|
|
819
|
+
let buffer = "";
|
|
820
|
+
try {
|
|
821
|
+
while (!doneReading) {
|
|
822
|
+
const { done, value } = await reader.read();
|
|
823
|
+
doneReading = done;
|
|
824
|
+
if (done && !value) continue;
|
|
825
|
+
try {
|
|
826
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
827
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
828
|
+
buffer = chunks.pop() || "";
|
|
829
|
+
for (const chunk of chunks) {
|
|
830
|
+
if (chunk) {
|
|
831
|
+
if (typeof chunk === "string") {
|
|
832
|
+
try {
|
|
833
|
+
const parsedChunk = JSON.parse(chunk);
|
|
834
|
+
yield parsedChunk;
|
|
835
|
+
} catch {
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
} catch {
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (buffer) {
|
|
844
|
+
try {
|
|
845
|
+
yield JSON.parse(buffer);
|
|
846
|
+
} catch {
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
} finally {
|
|
850
|
+
reader.cancel().catch(() => {
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Retrieves details about the vNext workflow
|
|
856
|
+
* @returns Promise containing vNext workflow details including steps and graphs
|
|
857
|
+
*/
|
|
858
|
+
details() {
|
|
859
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}`);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Retrieves all runs for a vNext workflow
|
|
863
|
+
* @param params - Parameters for filtering runs
|
|
864
|
+
* @returns Promise containing vNext workflow runs array
|
|
865
|
+
*/
|
|
866
|
+
runs(params) {
|
|
867
|
+
const searchParams = new URLSearchParams();
|
|
868
|
+
if (params?.fromDate) {
|
|
869
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
870
|
+
}
|
|
871
|
+
if (params?.toDate) {
|
|
872
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
873
|
+
}
|
|
874
|
+
if (params?.limit) {
|
|
875
|
+
searchParams.set("limit", String(params.limit));
|
|
876
|
+
}
|
|
877
|
+
if (params?.offset) {
|
|
878
|
+
searchParams.set("offset", String(params.offset));
|
|
879
|
+
}
|
|
880
|
+
if (params?.resourceId) {
|
|
881
|
+
searchParams.set("resourceId", params.resourceId);
|
|
882
|
+
}
|
|
883
|
+
if (searchParams.size) {
|
|
884
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
885
|
+
} else {
|
|
886
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Creates a new vNext workflow run
|
|
891
|
+
* @param params - Optional object containing the optional runId
|
|
892
|
+
* @returns Promise containing the runId of the created run
|
|
893
|
+
*/
|
|
894
|
+
createRun(params) {
|
|
895
|
+
const searchParams = new URLSearchParams();
|
|
896
|
+
if (!!params?.runId) {
|
|
897
|
+
searchParams.set("runId", params.runId);
|
|
898
|
+
}
|
|
899
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
900
|
+
method: "POST"
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Starts a vNext workflow run synchronously without waiting for the workflow to complete
|
|
905
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
906
|
+
* @returns Promise containing success message
|
|
907
|
+
*/
|
|
908
|
+
start(params) {
|
|
909
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
910
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
911
|
+
method: "POST",
|
|
912
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
|
|
917
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
918
|
+
* @returns Promise containing success message
|
|
919
|
+
*/
|
|
920
|
+
resume({
|
|
921
|
+
step,
|
|
922
|
+
runId,
|
|
923
|
+
resumeData,
|
|
924
|
+
...rest
|
|
925
|
+
}) {
|
|
926
|
+
const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
|
|
927
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
928
|
+
method: "POST",
|
|
929
|
+
stream: true,
|
|
930
|
+
body: {
|
|
931
|
+
step,
|
|
932
|
+
resumeData,
|
|
933
|
+
runtimeContext
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
939
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
940
|
+
* @returns Promise containing the vNext workflow execution results
|
|
941
|
+
*/
|
|
942
|
+
startAsync(params) {
|
|
943
|
+
const searchParams = new URLSearchParams();
|
|
944
|
+
if (!!params?.runId) {
|
|
945
|
+
searchParams.set("runId", params.runId);
|
|
946
|
+
}
|
|
947
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
948
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
949
|
+
method: "POST",
|
|
950
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
955
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
956
|
+
* @returns Promise containing the vNext workflow resume results
|
|
957
|
+
*/
|
|
958
|
+
resumeAsync(params) {
|
|
959
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
960
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
961
|
+
method: "POST",
|
|
962
|
+
body: {
|
|
963
|
+
step: params.step,
|
|
964
|
+
resumeData: params.resumeData,
|
|
965
|
+
runtimeContext
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Watches vNext workflow transitions in real-time
|
|
971
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
972
|
+
* @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
|
|
973
|
+
*/
|
|
974
|
+
async watch({ runId }, onRecord) {
|
|
975
|
+
const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
|
|
976
|
+
stream: true
|
|
977
|
+
});
|
|
978
|
+
if (!response.ok) {
|
|
979
|
+
throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
|
|
980
|
+
}
|
|
981
|
+
if (!response.body) {
|
|
982
|
+
throw new Error("Response body is null");
|
|
983
|
+
}
|
|
984
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
985
|
+
onRecord(record);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
// src/resources/a2a.ts
|
|
991
|
+
var A2A = class extends BaseResource {
|
|
992
|
+
constructor(options, agentId) {
|
|
993
|
+
super(options);
|
|
994
|
+
this.agentId = agentId;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Get the agent card with metadata about the agent
|
|
998
|
+
* @returns Promise containing the agent card information
|
|
999
|
+
*/
|
|
1000
|
+
async getCard() {
|
|
1001
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Send a message to the agent and get a response
|
|
1005
|
+
* @param params - Parameters for the task
|
|
1006
|
+
* @returns Promise containing the task response
|
|
1007
|
+
*/
|
|
1008
|
+
async sendMessage(params) {
|
|
1009
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1010
|
+
method: "POST",
|
|
1011
|
+
body: {
|
|
1012
|
+
method: "tasks/send",
|
|
1013
|
+
params
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
return { task: response.result };
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Get the status and result of a task
|
|
1020
|
+
* @param params - Parameters for querying the task
|
|
1021
|
+
* @returns Promise containing the task response
|
|
1022
|
+
*/
|
|
1023
|
+
async getTask(params) {
|
|
1024
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1025
|
+
method: "POST",
|
|
1026
|
+
body: {
|
|
1027
|
+
method: "tasks/get",
|
|
1028
|
+
params
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
return response.result;
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Cancel a running task
|
|
1035
|
+
* @param params - Parameters identifying the task to cancel
|
|
1036
|
+
* @returns Promise containing the task response
|
|
1037
|
+
*/
|
|
1038
|
+
async cancelTask(params) {
|
|
1039
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1040
|
+
method: "POST",
|
|
1041
|
+
body: {
|
|
1042
|
+
method: "tasks/cancel",
|
|
1043
|
+
params
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1049
|
+
* @param params - Parameters for the task
|
|
1050
|
+
* @returns Promise containing the task response
|
|
1051
|
+
*/
|
|
1052
|
+
async sendAndSubscribe(params) {
|
|
1053
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1054
|
+
method: "POST",
|
|
1055
|
+
body: {
|
|
1056
|
+
method: "tasks/sendSubscribe",
|
|
1057
|
+
params
|
|
1058
|
+
},
|
|
1059
|
+
stream: true
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
// src/resources/mcp-tool.ts
|
|
1065
|
+
var MCPTool = class extends BaseResource {
|
|
1066
|
+
serverId;
|
|
1067
|
+
toolId;
|
|
1068
|
+
constructor(options, serverId, toolId) {
|
|
1069
|
+
super(options);
|
|
1070
|
+
this.serverId = serverId;
|
|
1071
|
+
this.toolId = toolId;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1075
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1076
|
+
*/
|
|
1077
|
+
details() {
|
|
1078
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Executes this specific tool on the MCP server.
|
|
1082
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1083
|
+
* @returns Promise containing the result of the tool execution.
|
|
1084
|
+
*/
|
|
1085
|
+
execute(params) {
|
|
1086
|
+
const body = {};
|
|
1087
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1088
|
+
if (params.runtimeContext !== void 0) {
|
|
1089
|
+
body.runtimeContext = params.runtimeContext;
|
|
1090
|
+
}
|
|
1091
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1092
|
+
method: "POST",
|
|
1093
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
547
1094
|
});
|
|
548
1095
|
}
|
|
549
1096
|
};
|
|
@@ -560,6 +1107,21 @@ var MastraClient = class extends BaseResource {
|
|
|
560
1107
|
getAgents() {
|
|
561
1108
|
return this.request("/api/agents");
|
|
562
1109
|
}
|
|
1110
|
+
async getAGUI({ resourceId }) {
|
|
1111
|
+
const agents = await this.getAgents();
|
|
1112
|
+
return Object.entries(agents).reduce(
|
|
1113
|
+
(acc, [agentId]) => {
|
|
1114
|
+
const agent = this.getAgent(agentId);
|
|
1115
|
+
acc[agentId] = new AGUIAdapter({
|
|
1116
|
+
agentId,
|
|
1117
|
+
agent,
|
|
1118
|
+
resourceId
|
|
1119
|
+
});
|
|
1120
|
+
return acc;
|
|
1121
|
+
},
|
|
1122
|
+
{}
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
563
1125
|
/**
|
|
564
1126
|
* Gets an agent instance by ID
|
|
565
1127
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -640,6 +1202,21 @@ var MastraClient = class extends BaseResource {
|
|
|
640
1202
|
getWorkflow(workflowId) {
|
|
641
1203
|
return new Workflow(this.options, workflowId);
|
|
642
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Retrieves all available vNext workflows
|
|
1207
|
+
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1208
|
+
*/
|
|
1209
|
+
getVNextWorkflows() {
|
|
1210
|
+
return this.request("/api/workflows/v-next");
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Gets a vNext workflow instance by ID
|
|
1214
|
+
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1215
|
+
* @returns vNext Workflow instance
|
|
1216
|
+
*/
|
|
1217
|
+
getVNextWorkflow(workflowId) {
|
|
1218
|
+
return new VNextWorkflow(this.options, workflowId);
|
|
1219
|
+
}
|
|
643
1220
|
/**
|
|
644
1221
|
* Gets a vector instance by name
|
|
645
1222
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -677,7 +1254,7 @@ var MastraClient = class extends BaseResource {
|
|
|
677
1254
|
* @returns Promise containing telemetry data
|
|
678
1255
|
*/
|
|
679
1256
|
getTelemetry(params) {
|
|
680
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1257
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
681
1258
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
682
1259
|
const searchParams = new URLSearchParams();
|
|
683
1260
|
if (name) {
|
|
@@ -701,6 +1278,12 @@ var MastraClient = class extends BaseResource {
|
|
|
701
1278
|
searchParams.set("attribute", _attribute);
|
|
702
1279
|
}
|
|
703
1280
|
}
|
|
1281
|
+
if (fromDate) {
|
|
1282
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1283
|
+
}
|
|
1284
|
+
if (toDate) {
|
|
1285
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1286
|
+
}
|
|
704
1287
|
if (searchParams.size) {
|
|
705
1288
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
706
1289
|
} else {
|
|
@@ -722,6 +1305,62 @@ var MastraClient = class extends BaseResource {
|
|
|
722
1305
|
getNetwork(networkId) {
|
|
723
1306
|
return new Network(this.options, networkId);
|
|
724
1307
|
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Retrieves a list of available MCP servers.
|
|
1310
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1311
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
1312
|
+
*/
|
|
1313
|
+
getMcpServers(params) {
|
|
1314
|
+
const searchParams = new URLSearchParams();
|
|
1315
|
+
if (params?.limit !== void 0) {
|
|
1316
|
+
searchParams.set("limit", String(params.limit));
|
|
1317
|
+
}
|
|
1318
|
+
if (params?.offset !== void 0) {
|
|
1319
|
+
searchParams.set("offset", String(params.offset));
|
|
1320
|
+
}
|
|
1321
|
+
const queryString = searchParams.toString();
|
|
1322
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1326
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1327
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1328
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1329
|
+
*/
|
|
1330
|
+
getMcpServerDetails(serverId, params) {
|
|
1331
|
+
const searchParams = new URLSearchParams();
|
|
1332
|
+
if (params?.version) {
|
|
1333
|
+
searchParams.set("version", params.version);
|
|
1334
|
+
}
|
|
1335
|
+
const queryString = searchParams.toString();
|
|
1336
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1340
|
+
* @param serverId - The ID of the MCP server.
|
|
1341
|
+
* @returns Promise containing the list of tools.
|
|
1342
|
+
*/
|
|
1343
|
+
getMcpServerTools(serverId) {
|
|
1344
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1348
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1349
|
+
* @param serverId - The ID of the MCP server.
|
|
1350
|
+
* @param toolId - The ID of the tool.
|
|
1351
|
+
* @returns MCPTool instance.
|
|
1352
|
+
*/
|
|
1353
|
+
getMcpServerTool(serverId, toolId) {
|
|
1354
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1358
|
+
* @param agentId - ID of the agent to interact with
|
|
1359
|
+
* @returns A2A client instance
|
|
1360
|
+
*/
|
|
1361
|
+
getA2A(agentId) {
|
|
1362
|
+
return new A2A(this.options, agentId);
|
|
1363
|
+
}
|
|
725
1364
|
};
|
|
726
1365
|
|
|
727
1366
|
export { MastraClient };
|