@mastra/client-js 0.0.0-mcp-server-deploy-20250507160341 → 0.0.0-pass-headers-for-create-mastra-client-20250529190531
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +317 -2
- package/dist/index.cjs +560 -112
- package/dist/index.d.cts +236 -96
- package/dist/index.d.ts +236 -96
- package/dist/index.js +556 -112
- package/package.json +9 -6
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +98 -30
- package/src/example.ts +29 -30
- package/src/index.test.ts +121 -1
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +27 -34
- package/src/resources/base.ts +1 -1
- package/src/resources/index.ts +4 -3
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network.ts +5 -11
- package/src/resources/tool.ts +9 -2
- package/src/resources/workflow.ts +202 -100
- package/src/types.ts +65 -24
- package/src/utils/index.ts +11 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/src/resources/mcp.ts +0 -22
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,207 @@
|
|
|
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
|
-
var
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
13
|
+
|
|
14
|
+
// src/adapters/agui.ts
|
|
15
|
+
var AGUIAdapter = class extends client.AbstractAgent {
|
|
16
|
+
agent;
|
|
17
|
+
resourceId;
|
|
18
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
19
|
+
super({
|
|
20
|
+
agentId,
|
|
21
|
+
...rest
|
|
22
|
+
});
|
|
23
|
+
this.agent = agent;
|
|
24
|
+
this.resourceId = resourceId;
|
|
25
|
+
}
|
|
26
|
+
run(input) {
|
|
27
|
+
return new rxjs.Observable((subscriber) => {
|
|
28
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
29
|
+
subscriber.next({
|
|
30
|
+
type: client.EventType.RUN_STARTED,
|
|
31
|
+
threadId: input.threadId,
|
|
32
|
+
runId: input.runId
|
|
33
|
+
});
|
|
34
|
+
this.agent.stream({
|
|
35
|
+
threadId: input.threadId,
|
|
36
|
+
resourceId: this.resourceId ?? "",
|
|
37
|
+
runId: input.runId,
|
|
38
|
+
messages: convertedMessages,
|
|
39
|
+
clientTools: input.tools.reduce(
|
|
40
|
+
(acc, tool) => {
|
|
41
|
+
acc[tool.name] = {
|
|
42
|
+
id: tool.name,
|
|
43
|
+
description: tool.description,
|
|
44
|
+
inputSchema: tool.parameters
|
|
45
|
+
};
|
|
46
|
+
return acc;
|
|
47
|
+
},
|
|
48
|
+
{}
|
|
49
|
+
)
|
|
50
|
+
}).then((response) => {
|
|
51
|
+
let currentMessageId = void 0;
|
|
52
|
+
let isInTextMessage = false;
|
|
53
|
+
return response.processDataStream({
|
|
54
|
+
onTextPart: (text) => {
|
|
55
|
+
if (currentMessageId === void 0) {
|
|
56
|
+
currentMessageId = generateUUID();
|
|
57
|
+
const message2 = {
|
|
58
|
+
type: client.EventType.TEXT_MESSAGE_START,
|
|
59
|
+
messageId: currentMessageId,
|
|
60
|
+
role: "assistant"
|
|
61
|
+
};
|
|
62
|
+
subscriber.next(message2);
|
|
63
|
+
isInTextMessage = true;
|
|
64
|
+
}
|
|
65
|
+
const message = {
|
|
66
|
+
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
67
|
+
messageId: currentMessageId,
|
|
68
|
+
delta: text
|
|
69
|
+
};
|
|
70
|
+
subscriber.next(message);
|
|
71
|
+
},
|
|
72
|
+
onFinishMessagePart: () => {
|
|
73
|
+
if (currentMessageId !== void 0) {
|
|
74
|
+
const message = {
|
|
75
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
76
|
+
messageId: currentMessageId
|
|
77
|
+
};
|
|
78
|
+
subscriber.next(message);
|
|
79
|
+
isInTextMessage = false;
|
|
80
|
+
}
|
|
81
|
+
subscriber.next({
|
|
82
|
+
type: client.EventType.RUN_FINISHED,
|
|
83
|
+
threadId: input.threadId,
|
|
84
|
+
runId: input.runId
|
|
85
|
+
});
|
|
86
|
+
subscriber.complete();
|
|
87
|
+
},
|
|
88
|
+
onToolCallPart(streamPart) {
|
|
89
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
90
|
+
if (isInTextMessage) {
|
|
91
|
+
const message = {
|
|
92
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
93
|
+
messageId: parentMessageId
|
|
94
|
+
};
|
|
95
|
+
subscriber.next(message);
|
|
96
|
+
isInTextMessage = false;
|
|
97
|
+
}
|
|
98
|
+
subscriber.next({
|
|
99
|
+
type: client.EventType.TOOL_CALL_START,
|
|
100
|
+
toolCallId: streamPart.toolCallId,
|
|
101
|
+
toolCallName: streamPart.toolName,
|
|
102
|
+
parentMessageId
|
|
103
|
+
});
|
|
104
|
+
subscriber.next({
|
|
105
|
+
type: client.EventType.TOOL_CALL_ARGS,
|
|
106
|
+
toolCallId: streamPart.toolCallId,
|
|
107
|
+
delta: JSON.stringify(streamPart.args),
|
|
108
|
+
parentMessageId
|
|
109
|
+
});
|
|
110
|
+
subscriber.next({
|
|
111
|
+
type: client.EventType.TOOL_CALL_END,
|
|
112
|
+
toolCallId: streamPart.toolCallId,
|
|
113
|
+
parentMessageId
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}).catch((error) => {
|
|
118
|
+
console.error("error", error);
|
|
119
|
+
subscriber.error(error);
|
|
120
|
+
});
|
|
121
|
+
return () => {
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function generateUUID() {
|
|
127
|
+
if (typeof crypto !== "undefined") {
|
|
128
|
+
if (typeof crypto.randomUUID === "function") {
|
|
129
|
+
return crypto.randomUUID();
|
|
130
|
+
}
|
|
131
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
132
|
+
const buffer = new Uint8Array(16);
|
|
133
|
+
crypto.getRandomValues(buffer);
|
|
134
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
135
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
136
|
+
let hex = "";
|
|
137
|
+
for (let i = 0; i < 16; i++) {
|
|
138
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
139
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
140
|
+
}
|
|
141
|
+
return hex;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
145
|
+
const r = Math.random() * 16 | 0;
|
|
146
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
147
|
+
return v.toString(16);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function convertMessagesToMastraMessages(messages) {
|
|
151
|
+
const result = [];
|
|
152
|
+
for (const message of messages) {
|
|
153
|
+
if (message.role === "assistant") {
|
|
154
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
155
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
156
|
+
parts.push({
|
|
157
|
+
type: "tool-call",
|
|
158
|
+
toolCallId: toolCall.id,
|
|
159
|
+
toolName: toolCall.function.name,
|
|
160
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
result.push({
|
|
164
|
+
role: "assistant",
|
|
165
|
+
content: parts
|
|
166
|
+
});
|
|
167
|
+
if (message.toolCalls?.length) {
|
|
168
|
+
result.push({
|
|
169
|
+
role: "tool",
|
|
170
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
171
|
+
type: "tool-result",
|
|
172
|
+
toolCallId: toolCall.id,
|
|
173
|
+
toolName: toolCall.function.name,
|
|
174
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
175
|
+
}))
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
} else if (message.role === "user") {
|
|
179
|
+
result.push({
|
|
180
|
+
role: "user",
|
|
181
|
+
content: message.content || ""
|
|
182
|
+
});
|
|
183
|
+
} else if (message.role === "tool") {
|
|
184
|
+
result.push({
|
|
185
|
+
role: "tool",
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "tool-result",
|
|
189
|
+
toolCallId: message.toolCallId,
|
|
190
|
+
toolName: "unknown",
|
|
191
|
+
result: message.content
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
function zodToJsonSchema(zodSchema) {
|
|
200
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
201
|
+
return zodSchema;
|
|
202
|
+
}
|
|
203
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
204
|
+
}
|
|
8
205
|
|
|
9
206
|
// src/resources/base.ts
|
|
10
207
|
var BaseResource = class {
|
|
@@ -24,7 +221,7 @@ var BaseResource = class {
|
|
|
24
221
|
let delay = backoffMs;
|
|
25
222
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
26
223
|
try {
|
|
27
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
224
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
28
225
|
...options,
|
|
29
226
|
headers: {
|
|
30
227
|
...headers,
|
|
@@ -64,6 +261,15 @@ var BaseResource = class {
|
|
|
64
261
|
throw lastError || new Error("Request failed");
|
|
65
262
|
}
|
|
66
263
|
};
|
|
264
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
265
|
+
if (runtimeContext$1) {
|
|
266
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
267
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
268
|
+
}
|
|
269
|
+
return runtimeContext$1;
|
|
270
|
+
}
|
|
271
|
+
return void 0;
|
|
272
|
+
}
|
|
67
273
|
|
|
68
274
|
// src/resources/agent.ts
|
|
69
275
|
var AgentVoice = class extends BaseResource {
|
|
@@ -135,8 +341,9 @@ var Agent = class extends BaseResource {
|
|
|
135
341
|
generate(params) {
|
|
136
342
|
const processedParams = {
|
|
137
343
|
...params,
|
|
138
|
-
output: params.output
|
|
139
|
-
experimental_output: params.experimental_output
|
|
344
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
345
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
346
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
140
347
|
};
|
|
141
348
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
142
349
|
method: "POST",
|
|
@@ -151,8 +358,9 @@ var Agent = class extends BaseResource {
|
|
|
151
358
|
async stream(params) {
|
|
152
359
|
const processedParams = {
|
|
153
360
|
...params,
|
|
154
|
-
output: params.output
|
|
155
|
-
experimental_output: params.experimental_output
|
|
361
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
362
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
363
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
156
364
|
};
|
|
157
365
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
158
366
|
method: "POST",
|
|
@@ -178,6 +386,22 @@ var Agent = class extends BaseResource {
|
|
|
178
386
|
getTool(toolId) {
|
|
179
387
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
180
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Executes a tool for the agent
|
|
391
|
+
* @param toolId - ID of the tool to execute
|
|
392
|
+
* @param params - Parameters required for tool execution
|
|
393
|
+
* @returns Promise containing the tool execution results
|
|
394
|
+
*/
|
|
395
|
+
executeTool(toolId, params) {
|
|
396
|
+
const body = {
|
|
397
|
+
data: params.data,
|
|
398
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
399
|
+
};
|
|
400
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
401
|
+
method: "POST",
|
|
402
|
+
body
|
|
403
|
+
});
|
|
404
|
+
}
|
|
181
405
|
/**
|
|
182
406
|
* Retrieves evaluation results for the agent
|
|
183
407
|
* @returns Promise containing agent evaluations
|
|
@@ -213,8 +437,8 @@ var Network = class extends BaseResource {
|
|
|
213
437
|
generate(params) {
|
|
214
438
|
const processedParams = {
|
|
215
439
|
...params,
|
|
216
|
-
output:
|
|
217
|
-
experimental_output:
|
|
440
|
+
output: zodToJsonSchema(params.output),
|
|
441
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
218
442
|
};
|
|
219
443
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
220
444
|
method: "POST",
|
|
@@ -229,8 +453,8 @@ var Network = class extends BaseResource {
|
|
|
229
453
|
async stream(params) {
|
|
230
454
|
const processedParams = {
|
|
231
455
|
...params,
|
|
232
|
-
output:
|
|
233
|
-
experimental_output:
|
|
456
|
+
output: zodToJsonSchema(params.output),
|
|
457
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
234
458
|
};
|
|
235
459
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
236
460
|
method: "POST",
|
|
@@ -286,10 +510,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
286
510
|
}
|
|
287
511
|
/**
|
|
288
512
|
* Retrieves messages associated with the thread
|
|
513
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
289
514
|
* @returns Promise containing thread messages and UI messages
|
|
290
515
|
*/
|
|
291
|
-
getMessages() {
|
|
292
|
-
|
|
516
|
+
getMessages(params) {
|
|
517
|
+
const query = new URLSearchParams({
|
|
518
|
+
agentId: this.agentId,
|
|
519
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
520
|
+
});
|
|
521
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
293
522
|
}
|
|
294
523
|
};
|
|
295
524
|
|
|
@@ -359,24 +588,24 @@ var Vector = class extends BaseResource {
|
|
|
359
588
|
}
|
|
360
589
|
};
|
|
361
590
|
|
|
362
|
-
// src/resources/workflow.ts
|
|
591
|
+
// src/resources/legacy-workflow.ts
|
|
363
592
|
var RECORD_SEPARATOR = "";
|
|
364
|
-
var
|
|
593
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
365
594
|
constructor(options, workflowId) {
|
|
366
595
|
super(options);
|
|
367
596
|
this.workflowId = workflowId;
|
|
368
597
|
}
|
|
369
598
|
/**
|
|
370
|
-
* Retrieves details about the workflow
|
|
371
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
599
|
+
* Retrieves details about the legacy workflow
|
|
600
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
372
601
|
*/
|
|
373
602
|
details() {
|
|
374
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
603
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
375
604
|
}
|
|
376
605
|
/**
|
|
377
|
-
* Retrieves all runs for a workflow
|
|
606
|
+
* Retrieves all runs for a legacy workflow
|
|
378
607
|
* @param params - Parameters for filtering runs
|
|
379
|
-
* @returns Promise containing workflow runs array
|
|
608
|
+
* @returns Promise containing legacy workflow runs array
|
|
380
609
|
*/
|
|
381
610
|
runs(params) {
|
|
382
611
|
const searchParams = new URLSearchParams();
|
|
@@ -396,25 +625,13 @@ var Workflow = class extends BaseResource {
|
|
|
396
625
|
searchParams.set("resourceId", params.resourceId);
|
|
397
626
|
}
|
|
398
627
|
if (searchParams.size) {
|
|
399
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
628
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
400
629
|
} else {
|
|
401
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
630
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
402
631
|
}
|
|
403
632
|
}
|
|
404
633
|
/**
|
|
405
|
-
*
|
|
406
|
-
* Executes the workflow with the provided parameters
|
|
407
|
-
* @param params - Parameters required for workflow execution
|
|
408
|
-
* @returns Promise containing the workflow execution results
|
|
409
|
-
*/
|
|
410
|
-
execute(params) {
|
|
411
|
-
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
412
|
-
method: "POST",
|
|
413
|
-
body: params
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Creates a new workflow run
|
|
634
|
+
* Creates a new legacy workflow run
|
|
418
635
|
* @returns Promise containing the generated run ID
|
|
419
636
|
*/
|
|
420
637
|
createRun(params) {
|
|
@@ -422,34 +639,34 @@ var Workflow = class extends BaseResource {
|
|
|
422
639
|
if (!!params?.runId) {
|
|
423
640
|
searchParams.set("runId", params.runId);
|
|
424
641
|
}
|
|
425
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
642
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
426
643
|
method: "POST"
|
|
427
644
|
});
|
|
428
645
|
}
|
|
429
646
|
/**
|
|
430
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
647
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
431
648
|
* @param params - Object containing the runId and triggerData
|
|
432
649
|
* @returns Promise containing success message
|
|
433
650
|
*/
|
|
434
651
|
start(params) {
|
|
435
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
652
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
436
653
|
method: "POST",
|
|
437
654
|
body: params?.triggerData
|
|
438
655
|
});
|
|
439
656
|
}
|
|
440
657
|
/**
|
|
441
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
658
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
442
659
|
* @param stepId - ID of the step to resume
|
|
443
|
-
* @param runId - ID of the workflow run
|
|
444
|
-
* @param context - Context to resume the workflow with
|
|
445
|
-
* @returns Promise containing the workflow resume results
|
|
660
|
+
* @param runId - ID of the legacy workflow run
|
|
661
|
+
* @param context - Context to resume the legacy workflow with
|
|
662
|
+
* @returns Promise containing the legacy workflow resume results
|
|
446
663
|
*/
|
|
447
664
|
resume({
|
|
448
665
|
stepId,
|
|
449
666
|
runId,
|
|
450
667
|
context
|
|
451
668
|
}) {
|
|
452
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
669
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
453
670
|
method: "POST",
|
|
454
671
|
body: {
|
|
455
672
|
stepId,
|
|
@@ -467,18 +684,18 @@ var Workflow = class extends BaseResource {
|
|
|
467
684
|
if (!!params?.runId) {
|
|
468
685
|
searchParams.set("runId", params.runId);
|
|
469
686
|
}
|
|
470
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
687
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
471
688
|
method: "POST",
|
|
472
689
|
body: params?.triggerData
|
|
473
690
|
});
|
|
474
691
|
}
|
|
475
692
|
/**
|
|
476
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
693
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
477
694
|
* @param params - Object containing the runId, stepId, and context
|
|
478
695
|
* @returns Promise containing the workflow resume results
|
|
479
696
|
*/
|
|
480
697
|
resumeAsync(params) {
|
|
481
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
698
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
482
699
|
method: "POST",
|
|
483
700
|
body: {
|
|
484
701
|
stepId: params.stepId,
|
|
@@ -532,16 +749,16 @@ var Workflow = class extends BaseResource {
|
|
|
532
749
|
}
|
|
533
750
|
}
|
|
534
751
|
/**
|
|
535
|
-
* Watches workflow transitions in real-time
|
|
752
|
+
* Watches legacy workflow transitions in real-time
|
|
536
753
|
* @param runId - Optional run ID to filter the watch stream
|
|
537
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
754
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
538
755
|
*/
|
|
539
756
|
async watch({ runId }, onRecord) {
|
|
540
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
757
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
541
758
|
stream: true
|
|
542
759
|
});
|
|
543
760
|
if (!response.ok) {
|
|
544
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
761
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
545
762
|
}
|
|
546
763
|
if (!response.body) {
|
|
547
764
|
throw new Error("Response body is null");
|
|
@@ -575,22 +792,26 @@ var Tool = class extends BaseResource {
|
|
|
575
792
|
if (params.runId) {
|
|
576
793
|
url.set("runId", params.runId);
|
|
577
794
|
}
|
|
795
|
+
const body = {
|
|
796
|
+
data: params.data,
|
|
797
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
798
|
+
};
|
|
578
799
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
579
800
|
method: "POST",
|
|
580
|
-
body
|
|
801
|
+
body
|
|
581
802
|
});
|
|
582
803
|
}
|
|
583
804
|
};
|
|
584
805
|
|
|
585
|
-
// src/resources/
|
|
806
|
+
// src/resources/workflow.ts
|
|
586
807
|
var RECORD_SEPARATOR2 = "";
|
|
587
|
-
var
|
|
808
|
+
var Workflow = class extends BaseResource {
|
|
588
809
|
constructor(options, workflowId) {
|
|
589
810
|
super(options);
|
|
590
811
|
this.workflowId = workflowId;
|
|
591
812
|
}
|
|
592
813
|
/**
|
|
593
|
-
* Creates an async generator that processes a readable stream and yields
|
|
814
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
594
815
|
* separated by the Record Separator character (\x1E)
|
|
595
816
|
*
|
|
596
817
|
* @param stream - The readable stream to process
|
|
@@ -635,16 +856,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
635
856
|
}
|
|
636
857
|
}
|
|
637
858
|
/**
|
|
638
|
-
* Retrieves details about the
|
|
639
|
-
* @returns Promise containing
|
|
859
|
+
* Retrieves details about the workflow
|
|
860
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
640
861
|
*/
|
|
641
862
|
details() {
|
|
642
|
-
return this.request(`/api/workflows
|
|
863
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
643
864
|
}
|
|
644
865
|
/**
|
|
645
|
-
* Retrieves all runs for a
|
|
866
|
+
* Retrieves all runs for a workflow
|
|
646
867
|
* @param params - Parameters for filtering runs
|
|
647
|
-
* @returns Promise containing
|
|
868
|
+
* @returns Promise containing workflow runs array
|
|
648
869
|
*/
|
|
649
870
|
runs(params) {
|
|
650
871
|
const searchParams = new URLSearchParams();
|
|
@@ -664,13 +885,13 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
664
885
|
searchParams.set("resourceId", params.resourceId);
|
|
665
886
|
}
|
|
666
887
|
if (searchParams.size) {
|
|
667
|
-
return this.request(`/api/workflows
|
|
888
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
668
889
|
} else {
|
|
669
|
-
return this.request(`/api/workflows
|
|
890
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
670
891
|
}
|
|
671
892
|
}
|
|
672
893
|
/**
|
|
673
|
-
* Creates a new
|
|
894
|
+
* Creates a new workflow run
|
|
674
895
|
* @param params - Optional object containing the optional runId
|
|
675
896
|
* @returns Promise containing the runId of the created run
|
|
676
897
|
*/
|
|
@@ -679,23 +900,24 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
679
900
|
if (!!params?.runId) {
|
|
680
901
|
searchParams.set("runId", params.runId);
|
|
681
902
|
}
|
|
682
|
-
return this.request(`/api/workflows
|
|
903
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
683
904
|
method: "POST"
|
|
684
905
|
});
|
|
685
906
|
}
|
|
686
907
|
/**
|
|
687
|
-
* Starts a
|
|
908
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
688
909
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
689
910
|
* @returns Promise containing success message
|
|
690
911
|
*/
|
|
691
912
|
start(params) {
|
|
692
|
-
|
|
913
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
914
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
693
915
|
method: "POST",
|
|
694
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
916
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
695
917
|
});
|
|
696
918
|
}
|
|
697
919
|
/**
|
|
698
|
-
* Resumes a suspended
|
|
920
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
699
921
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
700
922
|
* @returns Promise containing success message
|
|
701
923
|
*/
|
|
@@ -703,9 +925,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
703
925
|
step,
|
|
704
926
|
runId,
|
|
705
927
|
resumeData,
|
|
706
|
-
|
|
928
|
+
...rest
|
|
707
929
|
}) {
|
|
708
|
-
|
|
930
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
931
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
709
932
|
method: "POST",
|
|
710
933
|
stream: true,
|
|
711
934
|
body: {
|
|
@@ -716,68 +939,237 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
716
939
|
});
|
|
717
940
|
}
|
|
718
941
|
/**
|
|
719
|
-
* Starts a
|
|
942
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
720
943
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
721
|
-
* @returns Promise containing the
|
|
944
|
+
* @returns Promise containing the workflow execution results
|
|
722
945
|
*/
|
|
723
946
|
startAsync(params) {
|
|
724
947
|
const searchParams = new URLSearchParams();
|
|
725
948
|
if (!!params?.runId) {
|
|
726
949
|
searchParams.set("runId", params.runId);
|
|
727
950
|
}
|
|
728
|
-
|
|
951
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
952
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
729
953
|
method: "POST",
|
|
730
|
-
body: { inputData: params.inputData, runtimeContext
|
|
954
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Starts a vNext workflow run and returns a stream
|
|
959
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
960
|
+
* @returns Promise containing the vNext workflow execution results
|
|
961
|
+
*/
|
|
962
|
+
async stream(params) {
|
|
963
|
+
const searchParams = new URLSearchParams();
|
|
964
|
+
if (!!params?.runId) {
|
|
965
|
+
searchParams.set("runId", params.runId);
|
|
966
|
+
}
|
|
967
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
968
|
+
const response = await this.request(
|
|
969
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
970
|
+
{
|
|
971
|
+
method: "POST",
|
|
972
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
973
|
+
stream: true
|
|
974
|
+
}
|
|
975
|
+
);
|
|
976
|
+
if (!response.ok) {
|
|
977
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
978
|
+
}
|
|
979
|
+
if (!response.body) {
|
|
980
|
+
throw new Error("Response body is null");
|
|
981
|
+
}
|
|
982
|
+
const transformStream = new TransformStream({
|
|
983
|
+
start() {
|
|
984
|
+
},
|
|
985
|
+
async transform(chunk, controller) {
|
|
986
|
+
try {
|
|
987
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
988
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
989
|
+
for (const chunk2 of chunks) {
|
|
990
|
+
if (chunk2) {
|
|
991
|
+
try {
|
|
992
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
993
|
+
controller.enqueue(parsedChunk);
|
|
994
|
+
} catch {
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
} catch {
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
731
1001
|
});
|
|
1002
|
+
return response.body.pipeThrough(transformStream);
|
|
732
1003
|
}
|
|
733
1004
|
/**
|
|
734
|
-
* Resumes a suspended
|
|
1005
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
735
1006
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
736
|
-
* @returns Promise containing the
|
|
1007
|
+
* @returns Promise containing the workflow resume results
|
|
737
1008
|
*/
|
|
738
1009
|
resumeAsync(params) {
|
|
739
|
-
|
|
1010
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1011
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
740
1012
|
method: "POST",
|
|
741
1013
|
body: {
|
|
742
1014
|
step: params.step,
|
|
743
1015
|
resumeData: params.resumeData,
|
|
744
|
-
runtimeContext
|
|
1016
|
+
runtimeContext
|
|
745
1017
|
}
|
|
746
1018
|
});
|
|
747
1019
|
}
|
|
748
1020
|
/**
|
|
749
|
-
* Watches
|
|
1021
|
+
* Watches workflow transitions in real-time
|
|
750
1022
|
* @param runId - Optional run ID to filter the watch stream
|
|
751
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
1023
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
752
1024
|
*/
|
|
753
1025
|
async watch({ runId }, onRecord) {
|
|
754
|
-
const response = await this.request(`/api/workflows
|
|
1026
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
755
1027
|
stream: true
|
|
756
1028
|
});
|
|
757
1029
|
if (!response.ok) {
|
|
758
|
-
throw new Error(`Failed to watch
|
|
1030
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
759
1031
|
}
|
|
760
1032
|
if (!response.body) {
|
|
761
1033
|
throw new Error("Response body is null");
|
|
762
1034
|
}
|
|
763
1035
|
for await (const record of this.streamProcessor(response.body)) {
|
|
764
|
-
|
|
1036
|
+
if (typeof record === "string") {
|
|
1037
|
+
onRecord(JSON.parse(record));
|
|
1038
|
+
} else {
|
|
1039
|
+
onRecord(record);
|
|
1040
|
+
}
|
|
765
1041
|
}
|
|
766
1042
|
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1045
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1046
|
+
*
|
|
1047
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1048
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1049
|
+
*/
|
|
1050
|
+
static createRecordStream(records) {
|
|
1051
|
+
const encoder = new TextEncoder();
|
|
1052
|
+
return new ReadableStream({
|
|
1053
|
+
async start(controller) {
|
|
1054
|
+
try {
|
|
1055
|
+
for await (const record of records) {
|
|
1056
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1057
|
+
controller.enqueue(encoder.encode(json));
|
|
1058
|
+
}
|
|
1059
|
+
controller.close();
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
controller.error(err);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
767
1066
|
};
|
|
768
1067
|
|
|
769
|
-
// src/resources/
|
|
770
|
-
var
|
|
771
|
-
constructor(options,
|
|
1068
|
+
// src/resources/a2a.ts
|
|
1069
|
+
var A2A = class extends BaseResource {
|
|
1070
|
+
constructor(options, agentId) {
|
|
1071
|
+
super(options);
|
|
1072
|
+
this.agentId = agentId;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Get the agent card with metadata about the agent
|
|
1076
|
+
* @returns Promise containing the agent card information
|
|
1077
|
+
*/
|
|
1078
|
+
async getCard() {
|
|
1079
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Send a message to the agent and get a response
|
|
1083
|
+
* @param params - Parameters for the task
|
|
1084
|
+
* @returns Promise containing the task response
|
|
1085
|
+
*/
|
|
1086
|
+
async sendMessage(params) {
|
|
1087
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1088
|
+
method: "POST",
|
|
1089
|
+
body: {
|
|
1090
|
+
method: "tasks/send",
|
|
1091
|
+
params
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
return { task: response.result };
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Get the status and result of a task
|
|
1098
|
+
* @param params - Parameters for querying the task
|
|
1099
|
+
* @returns Promise containing the task response
|
|
1100
|
+
*/
|
|
1101
|
+
async getTask(params) {
|
|
1102
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1103
|
+
method: "POST",
|
|
1104
|
+
body: {
|
|
1105
|
+
method: "tasks/get",
|
|
1106
|
+
params
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
return response.result;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Cancel a running task
|
|
1113
|
+
* @param params - Parameters identifying the task to cancel
|
|
1114
|
+
* @returns Promise containing the task response
|
|
1115
|
+
*/
|
|
1116
|
+
async cancelTask(params) {
|
|
1117
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1118
|
+
method: "POST",
|
|
1119
|
+
body: {
|
|
1120
|
+
method: "tasks/cancel",
|
|
1121
|
+
params
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1127
|
+
* @param params - Parameters for the task
|
|
1128
|
+
* @returns Promise containing the task response
|
|
1129
|
+
*/
|
|
1130
|
+
async sendAndSubscribe(params) {
|
|
1131
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1132
|
+
method: "POST",
|
|
1133
|
+
body: {
|
|
1134
|
+
method: "tasks/sendSubscribe",
|
|
1135
|
+
params
|
|
1136
|
+
},
|
|
1137
|
+
stream: true
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
// src/resources/mcp-tool.ts
|
|
1143
|
+
var MCPTool = class extends BaseResource {
|
|
1144
|
+
serverId;
|
|
1145
|
+
toolId;
|
|
1146
|
+
constructor(options, serverId, toolId) {
|
|
772
1147
|
super(options);
|
|
773
1148
|
this.serverId = serverId;
|
|
1149
|
+
this.toolId = toolId;
|
|
774
1150
|
}
|
|
775
1151
|
/**
|
|
776
|
-
*
|
|
777
|
-
* @returns Promise containing
|
|
1152
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1153
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
778
1154
|
*/
|
|
779
1155
|
details() {
|
|
780
|
-
return this.request(`/api/mcp
|
|
1156
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Executes this specific tool on the MCP server.
|
|
1160
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1161
|
+
* @returns Promise containing the result of the tool execution.
|
|
1162
|
+
*/
|
|
1163
|
+
execute(params) {
|
|
1164
|
+
const body = {};
|
|
1165
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1166
|
+
if (params.runtimeContext !== void 0) {
|
|
1167
|
+
body.runtimeContext = params.runtimeContext;
|
|
1168
|
+
}
|
|
1169
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1170
|
+
method: "POST",
|
|
1171
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1172
|
+
});
|
|
781
1173
|
}
|
|
782
1174
|
};
|
|
783
1175
|
|
|
@@ -793,6 +1185,21 @@ var MastraClient = class extends BaseResource {
|
|
|
793
1185
|
getAgents() {
|
|
794
1186
|
return this.request("/api/agents");
|
|
795
1187
|
}
|
|
1188
|
+
async getAGUI({ resourceId }) {
|
|
1189
|
+
const agents = await this.getAgents();
|
|
1190
|
+
return Object.entries(agents).reduce(
|
|
1191
|
+
(acc, [agentId]) => {
|
|
1192
|
+
const agent = this.getAgent(agentId);
|
|
1193
|
+
acc[agentId] = new AGUIAdapter({
|
|
1194
|
+
agentId,
|
|
1195
|
+
agent,
|
|
1196
|
+
resourceId
|
|
1197
|
+
});
|
|
1198
|
+
return acc;
|
|
1199
|
+
},
|
|
1200
|
+
{}
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
796
1203
|
/**
|
|
797
1204
|
* Gets an agent instance by ID
|
|
798
1205
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -858,6 +1265,21 @@ var MastraClient = class extends BaseResource {
|
|
|
858
1265
|
getTool(toolId) {
|
|
859
1266
|
return new Tool(this.options, toolId);
|
|
860
1267
|
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Retrieves all available legacy workflows
|
|
1270
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1271
|
+
*/
|
|
1272
|
+
getLegacyWorkflows() {
|
|
1273
|
+
return this.request("/api/workflows/legacy");
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Gets a legacy workflow instance by ID
|
|
1277
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1278
|
+
* @returns Legacy Workflow instance
|
|
1279
|
+
*/
|
|
1280
|
+
getLegacyWorkflow(workflowId) {
|
|
1281
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1282
|
+
}
|
|
861
1283
|
/**
|
|
862
1284
|
* Retrieves all available workflows
|
|
863
1285
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -873,21 +1295,6 @@ var MastraClient = class extends BaseResource {
|
|
|
873
1295
|
getWorkflow(workflowId) {
|
|
874
1296
|
return new Workflow(this.options, workflowId);
|
|
875
1297
|
}
|
|
876
|
-
/**
|
|
877
|
-
* Retrieves all available vNext workflows
|
|
878
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
879
|
-
*/
|
|
880
|
-
getVNextWorkflows() {
|
|
881
|
-
return this.request("/api/workflows/v-next");
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Gets a vNext workflow instance by ID
|
|
885
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
886
|
-
* @returns vNext Workflow instance
|
|
887
|
-
*/
|
|
888
|
-
getVNextWorkflow(workflowId) {
|
|
889
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
890
|
-
}
|
|
891
1298
|
/**
|
|
892
1299
|
* Gets a vector instance by name
|
|
893
1300
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -977,19 +1384,60 @@ var MastraClient = class extends BaseResource {
|
|
|
977
1384
|
return new Network(this.options, networkId);
|
|
978
1385
|
}
|
|
979
1386
|
/**
|
|
980
|
-
* Retrieves
|
|
981
|
-
* @
|
|
1387
|
+
* Retrieves a list of available MCP servers.
|
|
1388
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1389
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
1390
|
+
*/
|
|
1391
|
+
getMcpServers(params) {
|
|
1392
|
+
const searchParams = new URLSearchParams();
|
|
1393
|
+
if (params?.limit !== void 0) {
|
|
1394
|
+
searchParams.set("limit", String(params.limit));
|
|
1395
|
+
}
|
|
1396
|
+
if (params?.offset !== void 0) {
|
|
1397
|
+
searchParams.set("offset", String(params.offset));
|
|
1398
|
+
}
|
|
1399
|
+
const queryString = searchParams.toString();
|
|
1400
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1404
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1405
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1406
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1407
|
+
*/
|
|
1408
|
+
getMcpServerDetails(serverId, params) {
|
|
1409
|
+
const searchParams = new URLSearchParams();
|
|
1410
|
+
if (params?.version) {
|
|
1411
|
+
searchParams.set("version", params.version);
|
|
1412
|
+
}
|
|
1413
|
+
const queryString = searchParams.toString();
|
|
1414
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1418
|
+
* @param serverId - The ID of the MCP server.
|
|
1419
|
+
* @returns Promise containing the list of tools.
|
|
1420
|
+
*/
|
|
1421
|
+
getMcpServerTools(serverId) {
|
|
1422
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1426
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1427
|
+
* @param serverId - The ID of the MCP server.
|
|
1428
|
+
* @param toolId - The ID of the tool.
|
|
1429
|
+
* @returns MCPTool instance.
|
|
982
1430
|
*/
|
|
983
|
-
|
|
984
|
-
return this.
|
|
1431
|
+
getMcpServerTool(serverId, toolId) {
|
|
1432
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
985
1433
|
}
|
|
986
1434
|
/**
|
|
987
|
-
* Gets an
|
|
988
|
-
* @param
|
|
989
|
-
* @returns
|
|
1435
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1436
|
+
* @param agentId - ID of the agent to interact with
|
|
1437
|
+
* @returns A2A client instance
|
|
990
1438
|
*/
|
|
991
|
-
|
|
992
|
-
return new
|
|
1439
|
+
getA2A(agentId) {
|
|
1440
|
+
return new A2A(this.options, agentId);
|
|
993
1441
|
}
|
|
994
1442
|
};
|
|
995
1443
|
|