@mastra/client-js 0.0.0-message-ordering-20250415215612 → 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 +573 -3
- package/dist/index.cjs +763 -48
- package/dist/index.d.cts +351 -36
- package/dist/index.d.ts +351 -36
- package/dist/index.js +759 -48
- package/package.json +12 -6
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +122 -11
- 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 +28 -36
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -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 +16 -3
- package/src/resources/workflow.ts +234 -96
- package/src/types.ts +105 -15
- package/src/utils/index.ts +11 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,207 @@
|
|
|
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');
|
|
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,34 +588,50 @@ 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
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
* @returns Promise containing the workflow execution results
|
|
606
|
+
* Retrieves all runs for a legacy workflow
|
|
607
|
+
* @param params - Parameters for filtering runs
|
|
608
|
+
* @returns Promise containing legacy workflow runs array
|
|
381
609
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
610
|
+
runs(params) {
|
|
611
|
+
const searchParams = new URLSearchParams();
|
|
612
|
+
if (params?.fromDate) {
|
|
613
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
614
|
+
}
|
|
615
|
+
if (params?.toDate) {
|
|
616
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
617
|
+
}
|
|
618
|
+
if (params?.limit) {
|
|
619
|
+
searchParams.set("limit", String(params.limit));
|
|
620
|
+
}
|
|
621
|
+
if (params?.offset) {
|
|
622
|
+
searchParams.set("offset", String(params.offset));
|
|
623
|
+
}
|
|
624
|
+
if (params?.resourceId) {
|
|
625
|
+
searchParams.set("resourceId", params.resourceId);
|
|
626
|
+
}
|
|
627
|
+
if (searchParams.size) {
|
|
628
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
629
|
+
} else {
|
|
630
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
631
|
+
}
|
|
387
632
|
}
|
|
388
633
|
/**
|
|
389
|
-
* Creates a new workflow run
|
|
634
|
+
* Creates a new legacy workflow run
|
|
390
635
|
* @returns Promise containing the generated run ID
|
|
391
636
|
*/
|
|
392
637
|
createRun(params) {
|
|
@@ -394,34 +639,34 @@ var Workflow = class extends BaseResource {
|
|
|
394
639
|
if (!!params?.runId) {
|
|
395
640
|
searchParams.set("runId", params.runId);
|
|
396
641
|
}
|
|
397
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
642
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
398
643
|
method: "POST"
|
|
399
644
|
});
|
|
400
645
|
}
|
|
401
646
|
/**
|
|
402
|
-
* 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
|
|
403
648
|
* @param params - Object containing the runId and triggerData
|
|
404
649
|
* @returns Promise containing success message
|
|
405
650
|
*/
|
|
406
651
|
start(params) {
|
|
407
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
652
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
408
653
|
method: "POST",
|
|
409
654
|
body: params?.triggerData
|
|
410
655
|
});
|
|
411
656
|
}
|
|
412
657
|
/**
|
|
413
|
-
* 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
|
|
414
659
|
* @param stepId - ID of the step to resume
|
|
415
|
-
* @param runId - ID of the workflow run
|
|
416
|
-
* @param context - Context to resume the workflow with
|
|
417
|
-
* @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
|
|
418
663
|
*/
|
|
419
664
|
resume({
|
|
420
665
|
stepId,
|
|
421
666
|
runId,
|
|
422
667
|
context
|
|
423
668
|
}) {
|
|
424
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
669
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
425
670
|
method: "POST",
|
|
426
671
|
body: {
|
|
427
672
|
stepId,
|
|
@@ -439,18 +684,18 @@ var Workflow = class extends BaseResource {
|
|
|
439
684
|
if (!!params?.runId) {
|
|
440
685
|
searchParams.set("runId", params.runId);
|
|
441
686
|
}
|
|
442
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
687
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
443
688
|
method: "POST",
|
|
444
689
|
body: params?.triggerData
|
|
445
690
|
});
|
|
446
691
|
}
|
|
447
692
|
/**
|
|
448
|
-
* 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
|
|
449
694
|
* @param params - Object containing the runId, stepId, and context
|
|
450
695
|
* @returns Promise containing the workflow resume results
|
|
451
696
|
*/
|
|
452
697
|
resumeAsync(params) {
|
|
453
|
-
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}`, {
|
|
454
699
|
method: "POST",
|
|
455
700
|
body: {
|
|
456
701
|
stepId: params.stepId,
|
|
@@ -489,7 +734,7 @@ var Workflow = class extends BaseResource {
|
|
|
489
734
|
}
|
|
490
735
|
}
|
|
491
736
|
}
|
|
492
|
-
} catch
|
|
737
|
+
} catch {
|
|
493
738
|
}
|
|
494
739
|
}
|
|
495
740
|
if (buffer) {
|
|
@@ -504,16 +749,16 @@ var Workflow = class extends BaseResource {
|
|
|
504
749
|
}
|
|
505
750
|
}
|
|
506
751
|
/**
|
|
507
|
-
* Watches workflow transitions in real-time
|
|
752
|
+
* Watches legacy workflow transitions in real-time
|
|
508
753
|
* @param runId - Optional run ID to filter the watch stream
|
|
509
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
754
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
510
755
|
*/
|
|
511
756
|
async watch({ runId }, onRecord) {
|
|
512
|
-
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}`, {
|
|
513
758
|
stream: true
|
|
514
759
|
});
|
|
515
760
|
if (!response.ok) {
|
|
516
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
761
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
517
762
|
}
|
|
518
763
|
if (!response.body) {
|
|
519
764
|
throw new Error("Response body is null");
|
|
@@ -543,9 +788,387 @@ var Tool = class extends BaseResource {
|
|
|
543
788
|
* @returns Promise containing the tool execution results
|
|
544
789
|
*/
|
|
545
790
|
execute(params) {
|
|
546
|
-
|
|
791
|
+
const url = new URLSearchParams();
|
|
792
|
+
if (params.runId) {
|
|
793
|
+
url.set("runId", params.runId);
|
|
794
|
+
}
|
|
795
|
+
const body = {
|
|
796
|
+
data: params.data,
|
|
797
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
798
|
+
};
|
|
799
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
547
800
|
method: "POST",
|
|
548
|
-
body
|
|
801
|
+
body
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
// src/resources/workflow.ts
|
|
807
|
+
var RECORD_SEPARATOR2 = "";
|
|
808
|
+
var Workflow = class extends BaseResource {
|
|
809
|
+
constructor(options, workflowId) {
|
|
810
|
+
super(options);
|
|
811
|
+
this.workflowId = workflowId;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
815
|
+
* separated by the Record Separator character (\x1E)
|
|
816
|
+
*
|
|
817
|
+
* @param stream - The readable stream to process
|
|
818
|
+
* @returns An async generator that yields parsed records
|
|
819
|
+
*/
|
|
820
|
+
async *streamProcessor(stream) {
|
|
821
|
+
const reader = stream.getReader();
|
|
822
|
+
let doneReading = false;
|
|
823
|
+
let buffer = "";
|
|
824
|
+
try {
|
|
825
|
+
while (!doneReading) {
|
|
826
|
+
const { done, value } = await reader.read();
|
|
827
|
+
doneReading = done;
|
|
828
|
+
if (done && !value) continue;
|
|
829
|
+
try {
|
|
830
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
831
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
832
|
+
buffer = chunks.pop() || "";
|
|
833
|
+
for (const chunk of chunks) {
|
|
834
|
+
if (chunk) {
|
|
835
|
+
if (typeof chunk === "string") {
|
|
836
|
+
try {
|
|
837
|
+
const parsedChunk = JSON.parse(chunk);
|
|
838
|
+
yield parsedChunk;
|
|
839
|
+
} catch {
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
} catch {
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (buffer) {
|
|
848
|
+
try {
|
|
849
|
+
yield JSON.parse(buffer);
|
|
850
|
+
} catch {
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
} finally {
|
|
854
|
+
reader.cancel().catch(() => {
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Retrieves details about the workflow
|
|
860
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
861
|
+
*/
|
|
862
|
+
details() {
|
|
863
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Retrieves all runs for a workflow
|
|
867
|
+
* @param params - Parameters for filtering runs
|
|
868
|
+
* @returns Promise containing workflow runs array
|
|
869
|
+
*/
|
|
870
|
+
runs(params) {
|
|
871
|
+
const searchParams = new URLSearchParams();
|
|
872
|
+
if (params?.fromDate) {
|
|
873
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
874
|
+
}
|
|
875
|
+
if (params?.toDate) {
|
|
876
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
877
|
+
}
|
|
878
|
+
if (params?.limit) {
|
|
879
|
+
searchParams.set("limit", String(params.limit));
|
|
880
|
+
}
|
|
881
|
+
if (params?.offset) {
|
|
882
|
+
searchParams.set("offset", String(params.offset));
|
|
883
|
+
}
|
|
884
|
+
if (params?.resourceId) {
|
|
885
|
+
searchParams.set("resourceId", params.resourceId);
|
|
886
|
+
}
|
|
887
|
+
if (searchParams.size) {
|
|
888
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
889
|
+
} else {
|
|
890
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Creates a new workflow run
|
|
895
|
+
* @param params - Optional object containing the optional runId
|
|
896
|
+
* @returns Promise containing the runId of the created run
|
|
897
|
+
*/
|
|
898
|
+
createRun(params) {
|
|
899
|
+
const searchParams = new URLSearchParams();
|
|
900
|
+
if (!!params?.runId) {
|
|
901
|
+
searchParams.set("runId", params.runId);
|
|
902
|
+
}
|
|
903
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
904
|
+
method: "POST"
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
909
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
910
|
+
* @returns Promise containing success message
|
|
911
|
+
*/
|
|
912
|
+
start(params) {
|
|
913
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
914
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
915
|
+
method: "POST",
|
|
916
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
921
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
922
|
+
* @returns Promise containing success message
|
|
923
|
+
*/
|
|
924
|
+
resume({
|
|
925
|
+
step,
|
|
926
|
+
runId,
|
|
927
|
+
resumeData,
|
|
928
|
+
...rest
|
|
929
|
+
}) {
|
|
930
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
931
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
932
|
+
method: "POST",
|
|
933
|
+
stream: true,
|
|
934
|
+
body: {
|
|
935
|
+
step,
|
|
936
|
+
resumeData,
|
|
937
|
+
runtimeContext
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
943
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
944
|
+
* @returns Promise containing the workflow execution results
|
|
945
|
+
*/
|
|
946
|
+
startAsync(params) {
|
|
947
|
+
const searchParams = new URLSearchParams();
|
|
948
|
+
if (!!params?.runId) {
|
|
949
|
+
searchParams.set("runId", params.runId);
|
|
950
|
+
}
|
|
951
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
952
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
953
|
+
method: "POST",
|
|
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
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
return response.body.pipeThrough(transformStream);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1006
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1007
|
+
* @returns Promise containing the workflow resume results
|
|
1008
|
+
*/
|
|
1009
|
+
resumeAsync(params) {
|
|
1010
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1011
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1012
|
+
method: "POST",
|
|
1013
|
+
body: {
|
|
1014
|
+
step: params.step,
|
|
1015
|
+
resumeData: params.resumeData,
|
|
1016
|
+
runtimeContext
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Watches workflow transitions in real-time
|
|
1022
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
1023
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1024
|
+
*/
|
|
1025
|
+
async watch({ runId }, onRecord) {
|
|
1026
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1027
|
+
stream: true
|
|
1028
|
+
});
|
|
1029
|
+
if (!response.ok) {
|
|
1030
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1031
|
+
}
|
|
1032
|
+
if (!response.body) {
|
|
1033
|
+
throw new Error("Response body is null");
|
|
1034
|
+
}
|
|
1035
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1036
|
+
if (typeof record === "string") {
|
|
1037
|
+
onRecord(JSON.parse(record));
|
|
1038
|
+
} else {
|
|
1039
|
+
onRecord(record);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
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
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
|
|
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) {
|
|
1147
|
+
super(options);
|
|
1148
|
+
this.serverId = serverId;
|
|
1149
|
+
this.toolId = toolId;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1153
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1154
|
+
*/
|
|
1155
|
+
details() {
|
|
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
|
|
549
1172
|
});
|
|
550
1173
|
}
|
|
551
1174
|
};
|
|
@@ -562,6 +1185,21 @@ var MastraClient = class extends BaseResource {
|
|
|
562
1185
|
getAgents() {
|
|
563
1186
|
return this.request("/api/agents");
|
|
564
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
|
+
}
|
|
565
1203
|
/**
|
|
566
1204
|
* Gets an agent instance by ID
|
|
567
1205
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -627,6 +1265,21 @@ var MastraClient = class extends BaseResource {
|
|
|
627
1265
|
getTool(toolId) {
|
|
628
1266
|
return new Tool(this.options, toolId);
|
|
629
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
|
+
}
|
|
630
1283
|
/**
|
|
631
1284
|
* Retrieves all available workflows
|
|
632
1285
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -679,7 +1332,7 @@ var MastraClient = class extends BaseResource {
|
|
|
679
1332
|
* @returns Promise containing telemetry data
|
|
680
1333
|
*/
|
|
681
1334
|
getTelemetry(params) {
|
|
682
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1335
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
683
1336
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
684
1337
|
const searchParams = new URLSearchParams();
|
|
685
1338
|
if (name) {
|
|
@@ -703,6 +1356,12 @@ var MastraClient = class extends BaseResource {
|
|
|
703
1356
|
searchParams.set("attribute", _attribute);
|
|
704
1357
|
}
|
|
705
1358
|
}
|
|
1359
|
+
if (fromDate) {
|
|
1360
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1361
|
+
}
|
|
1362
|
+
if (toDate) {
|
|
1363
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1364
|
+
}
|
|
706
1365
|
if (searchParams.size) {
|
|
707
1366
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
708
1367
|
} else {
|
|
@@ -724,6 +1383,62 @@ var MastraClient = class extends BaseResource {
|
|
|
724
1383
|
getNetwork(networkId) {
|
|
725
1384
|
return new Network(this.options, networkId);
|
|
726
1385
|
}
|
|
1386
|
+
/**
|
|
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.
|
|
1430
|
+
*/
|
|
1431
|
+
getMcpServerTool(serverId, toolId) {
|
|
1432
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
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
|
|
1438
|
+
*/
|
|
1439
|
+
getA2A(agentId) {
|
|
1440
|
+
return new A2A(this.options, agentId);
|
|
1441
|
+
}
|
|
727
1442
|
};
|
|
728
1443
|
|
|
729
1444
|
exports.MastraClient = MastraClient;
|