@mastra/client-js 0.0.0-agui-20250501191909 → 0.0.0-cli-debug-20250611094457
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 +465 -2
- package/dist/index.cjs +558 -109
- package/dist/index.d.cts +304 -98
- package/dist/index.d.ts +304 -98
- package/dist/index.js +554 -109
- package/package.json +9 -9
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +182 -24
- 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 +48 -35
- package/src/resources/base.ts +1 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +140 -132
- 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 +230 -100
- package/src/types.ts +104 -22
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +31 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,13 @@ var client = require('@ag-ui/client');
|
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
6
|
var zod = require('zod');
|
|
7
|
-
var
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var tools = require('@mastra/core/tools');
|
|
9
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
8
14
|
|
|
9
15
|
// src/adapters/agui.ts
|
|
10
16
|
var AGUIAdapter = class extends client.AbstractAgent {
|
|
@@ -44,6 +50,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
44
50
|
)
|
|
45
51
|
}).then((response) => {
|
|
46
52
|
let currentMessageId = void 0;
|
|
53
|
+
let isInTextMessage = false;
|
|
47
54
|
return response.processDataStream({
|
|
48
55
|
onTextPart: (text) => {
|
|
49
56
|
if (currentMessageId === void 0) {
|
|
@@ -54,6 +61,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
54
61
|
role: "assistant"
|
|
55
62
|
};
|
|
56
63
|
subscriber.next(message2);
|
|
64
|
+
isInTextMessage = true;
|
|
57
65
|
}
|
|
58
66
|
const message = {
|
|
59
67
|
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
@@ -62,14 +70,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
62
70
|
};
|
|
63
71
|
subscriber.next(message);
|
|
64
72
|
},
|
|
65
|
-
onFinishMessagePart: (
|
|
66
|
-
console.log("onFinishMessagePart", message);
|
|
73
|
+
onFinishMessagePart: () => {
|
|
67
74
|
if (currentMessageId !== void 0) {
|
|
68
|
-
const
|
|
75
|
+
const message = {
|
|
69
76
|
type: client.EventType.TEXT_MESSAGE_END,
|
|
70
77
|
messageId: currentMessageId
|
|
71
78
|
};
|
|
72
|
-
subscriber.next(
|
|
79
|
+
subscriber.next(message);
|
|
80
|
+
isInTextMessage = false;
|
|
73
81
|
}
|
|
74
82
|
subscriber.next({
|
|
75
83
|
type: client.EventType.RUN_FINISHED,
|
|
@@ -80,6 +88,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
80
88
|
},
|
|
81
89
|
onToolCallPart(streamPart) {
|
|
82
90
|
const parentMessageId = currentMessageId || generateUUID();
|
|
91
|
+
if (isInTextMessage) {
|
|
92
|
+
const message = {
|
|
93
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
94
|
+
messageId: parentMessageId
|
|
95
|
+
};
|
|
96
|
+
subscriber.next(message);
|
|
97
|
+
isInTextMessage = false;
|
|
98
|
+
}
|
|
83
99
|
subscriber.next({
|
|
84
100
|
type: client.EventType.TOOL_CALL_START,
|
|
85
101
|
toolCallId: streamPart.toolCallId,
|
|
@@ -100,7 +116,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
100
116
|
}
|
|
101
117
|
});
|
|
102
118
|
}).catch((error) => {
|
|
103
|
-
console.
|
|
119
|
+
console.error("error", error);
|
|
104
120
|
subscriber.error(error);
|
|
105
121
|
});
|
|
106
122
|
return () => {
|
|
@@ -149,6 +165,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
149
165
|
role: "assistant",
|
|
150
166
|
content: parts
|
|
151
167
|
});
|
|
168
|
+
if (message.toolCalls?.length) {
|
|
169
|
+
result.push({
|
|
170
|
+
role: "tool",
|
|
171
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
172
|
+
type: "tool-result",
|
|
173
|
+
toolCallId: toolCall.id,
|
|
174
|
+
toolName: toolCall.function.name,
|
|
175
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
176
|
+
}))
|
|
177
|
+
});
|
|
178
|
+
}
|
|
152
179
|
} else if (message.role === "user") {
|
|
153
180
|
result.push({
|
|
154
181
|
role: "user",
|
|
@@ -170,6 +197,39 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
170
197
|
}
|
|
171
198
|
return result;
|
|
172
199
|
}
|
|
200
|
+
function zodToJsonSchema(zodSchema) {
|
|
201
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
202
|
+
return zodSchema;
|
|
203
|
+
}
|
|
204
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
205
|
+
}
|
|
206
|
+
function processClientTools(clientTools) {
|
|
207
|
+
if (!clientTools) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return Object.fromEntries(
|
|
211
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
212
|
+
if (tools.isVercelTool(value)) {
|
|
213
|
+
return [
|
|
214
|
+
key,
|
|
215
|
+
{
|
|
216
|
+
...value,
|
|
217
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
} else {
|
|
221
|
+
return [
|
|
222
|
+
key,
|
|
223
|
+
{
|
|
224
|
+
...value,
|
|
225
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
226
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
}
|
|
173
233
|
|
|
174
234
|
// src/resources/base.ts
|
|
175
235
|
var BaseResource = class {
|
|
@@ -189,7 +249,7 @@ var BaseResource = class {
|
|
|
189
249
|
let delay = backoffMs;
|
|
190
250
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
191
251
|
try {
|
|
192
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
252
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
193
253
|
...options,
|
|
194
254
|
headers: {
|
|
195
255
|
...headers,
|
|
@@ -229,6 +289,15 @@ var BaseResource = class {
|
|
|
229
289
|
throw lastError || new Error("Request failed");
|
|
230
290
|
}
|
|
231
291
|
};
|
|
292
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
293
|
+
if (runtimeContext$1) {
|
|
294
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
295
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
296
|
+
}
|
|
297
|
+
return runtimeContext$1;
|
|
298
|
+
}
|
|
299
|
+
return void 0;
|
|
300
|
+
}
|
|
232
301
|
|
|
233
302
|
// src/resources/agent.ts
|
|
234
303
|
var AgentVoice = class extends BaseResource {
|
|
@@ -277,6 +346,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
277
346
|
getSpeakers() {
|
|
278
347
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
279
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Get the listener configuration for the agent's voice provider
|
|
351
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
352
|
+
*/
|
|
353
|
+
getListener() {
|
|
354
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
355
|
+
}
|
|
280
356
|
};
|
|
281
357
|
var Agent = class extends BaseResource {
|
|
282
358
|
constructor(options, agentId) {
|
|
@@ -292,16 +368,13 @@ var Agent = class extends BaseResource {
|
|
|
292
368
|
details() {
|
|
293
369
|
return this.request(`/api/agents/${this.agentId}`);
|
|
294
370
|
}
|
|
295
|
-
/**
|
|
296
|
-
* Generates a response from the agent
|
|
297
|
-
* @param params - Generation parameters including prompt
|
|
298
|
-
* @returns Promise containing the generated response
|
|
299
|
-
*/
|
|
300
371
|
generate(params) {
|
|
301
372
|
const processedParams = {
|
|
302
373
|
...params,
|
|
303
|
-
output: params.output
|
|
304
|
-
experimental_output: params.experimental_output
|
|
374
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
375
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
376
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
377
|
+
clientTools: processClientTools(params.clientTools)
|
|
305
378
|
};
|
|
306
379
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
307
380
|
method: "POST",
|
|
@@ -316,8 +389,10 @@ var Agent = class extends BaseResource {
|
|
|
316
389
|
async stream(params) {
|
|
317
390
|
const processedParams = {
|
|
318
391
|
...params,
|
|
319
|
-
output: params.output
|
|
320
|
-
experimental_output: params.experimental_output
|
|
392
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
393
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
394
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
395
|
+
clientTools: processClientTools(params.clientTools)
|
|
321
396
|
};
|
|
322
397
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
323
398
|
method: "POST",
|
|
@@ -343,6 +418,22 @@ var Agent = class extends BaseResource {
|
|
|
343
418
|
getTool(toolId) {
|
|
344
419
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
345
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Executes a tool for the agent
|
|
423
|
+
* @param toolId - ID of the tool to execute
|
|
424
|
+
* @param params - Parameters required for tool execution
|
|
425
|
+
* @returns Promise containing the tool execution results
|
|
426
|
+
*/
|
|
427
|
+
executeTool(toolId, params) {
|
|
428
|
+
const body = {
|
|
429
|
+
data: params.data,
|
|
430
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
431
|
+
};
|
|
432
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
433
|
+
method: "POST",
|
|
434
|
+
body
|
|
435
|
+
});
|
|
436
|
+
}
|
|
346
437
|
/**
|
|
347
438
|
* Retrieves evaluation results for the agent
|
|
348
439
|
* @returns Promise containing agent evaluations
|
|
@@ -378,8 +469,8 @@ var Network = class extends BaseResource {
|
|
|
378
469
|
generate(params) {
|
|
379
470
|
const processedParams = {
|
|
380
471
|
...params,
|
|
381
|
-
output:
|
|
382
|
-
experimental_output:
|
|
472
|
+
output: zodToJsonSchema(params.output),
|
|
473
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
383
474
|
};
|
|
384
475
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
385
476
|
method: "POST",
|
|
@@ -394,8 +485,8 @@ var Network = class extends BaseResource {
|
|
|
394
485
|
async stream(params) {
|
|
395
486
|
const processedParams = {
|
|
396
487
|
...params,
|
|
397
|
-
output:
|
|
398
|
-
experimental_output:
|
|
488
|
+
output: zodToJsonSchema(params.output),
|
|
489
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
399
490
|
};
|
|
400
491
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
401
492
|
method: "POST",
|
|
@@ -451,10 +542,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
451
542
|
}
|
|
452
543
|
/**
|
|
453
544
|
* Retrieves messages associated with the thread
|
|
545
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
454
546
|
* @returns Promise containing thread messages and UI messages
|
|
455
547
|
*/
|
|
456
|
-
getMessages() {
|
|
457
|
-
|
|
548
|
+
getMessages(params) {
|
|
549
|
+
const query = new URLSearchParams({
|
|
550
|
+
agentId: this.agentId,
|
|
551
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
552
|
+
});
|
|
553
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
458
554
|
}
|
|
459
555
|
};
|
|
460
556
|
|
|
@@ -524,41 +620,50 @@ var Vector = class extends BaseResource {
|
|
|
524
620
|
}
|
|
525
621
|
};
|
|
526
622
|
|
|
527
|
-
// src/resources/workflow.ts
|
|
623
|
+
// src/resources/legacy-workflow.ts
|
|
528
624
|
var RECORD_SEPARATOR = "";
|
|
529
|
-
var
|
|
625
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
530
626
|
constructor(options, workflowId) {
|
|
531
627
|
super(options);
|
|
532
628
|
this.workflowId = workflowId;
|
|
533
629
|
}
|
|
534
630
|
/**
|
|
535
|
-
* Retrieves details about the workflow
|
|
536
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
631
|
+
* Retrieves details about the legacy workflow
|
|
632
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
537
633
|
*/
|
|
538
634
|
details() {
|
|
539
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
635
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
540
636
|
}
|
|
541
637
|
/**
|
|
542
|
-
* Retrieves all runs for a workflow
|
|
543
|
-
* @
|
|
544
|
-
|
|
545
|
-
runs() {
|
|
546
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* @deprecated Use `startAsync` instead
|
|
550
|
-
* Executes the workflow with the provided parameters
|
|
551
|
-
* @param params - Parameters required for workflow execution
|
|
552
|
-
* @returns Promise containing the workflow execution results
|
|
638
|
+
* Retrieves all runs for a legacy workflow
|
|
639
|
+
* @param params - Parameters for filtering runs
|
|
640
|
+
* @returns Promise containing legacy workflow runs array
|
|
553
641
|
*/
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
642
|
+
runs(params) {
|
|
643
|
+
const searchParams = new URLSearchParams();
|
|
644
|
+
if (params?.fromDate) {
|
|
645
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
646
|
+
}
|
|
647
|
+
if (params?.toDate) {
|
|
648
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
649
|
+
}
|
|
650
|
+
if (params?.limit) {
|
|
651
|
+
searchParams.set("limit", String(params.limit));
|
|
652
|
+
}
|
|
653
|
+
if (params?.offset) {
|
|
654
|
+
searchParams.set("offset", String(params.offset));
|
|
655
|
+
}
|
|
656
|
+
if (params?.resourceId) {
|
|
657
|
+
searchParams.set("resourceId", params.resourceId);
|
|
658
|
+
}
|
|
659
|
+
if (searchParams.size) {
|
|
660
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
661
|
+
} else {
|
|
662
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
663
|
+
}
|
|
559
664
|
}
|
|
560
665
|
/**
|
|
561
|
-
* Creates a new workflow run
|
|
666
|
+
* Creates a new legacy workflow run
|
|
562
667
|
* @returns Promise containing the generated run ID
|
|
563
668
|
*/
|
|
564
669
|
createRun(params) {
|
|
@@ -566,34 +671,34 @@ var Workflow = class extends BaseResource {
|
|
|
566
671
|
if (!!params?.runId) {
|
|
567
672
|
searchParams.set("runId", params.runId);
|
|
568
673
|
}
|
|
569
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
674
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
570
675
|
method: "POST"
|
|
571
676
|
});
|
|
572
677
|
}
|
|
573
678
|
/**
|
|
574
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
679
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
575
680
|
* @param params - Object containing the runId and triggerData
|
|
576
681
|
* @returns Promise containing success message
|
|
577
682
|
*/
|
|
578
683
|
start(params) {
|
|
579
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
684
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
580
685
|
method: "POST",
|
|
581
686
|
body: params?.triggerData
|
|
582
687
|
});
|
|
583
688
|
}
|
|
584
689
|
/**
|
|
585
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
690
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
586
691
|
* @param stepId - ID of the step to resume
|
|
587
|
-
* @param runId - ID of the workflow run
|
|
588
|
-
* @param context - Context to resume the workflow with
|
|
589
|
-
* @returns Promise containing the workflow resume results
|
|
692
|
+
* @param runId - ID of the legacy workflow run
|
|
693
|
+
* @param context - Context to resume the legacy workflow with
|
|
694
|
+
* @returns Promise containing the legacy workflow resume results
|
|
590
695
|
*/
|
|
591
696
|
resume({
|
|
592
697
|
stepId,
|
|
593
698
|
runId,
|
|
594
699
|
context
|
|
595
700
|
}) {
|
|
596
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
701
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
597
702
|
method: "POST",
|
|
598
703
|
body: {
|
|
599
704
|
stepId,
|
|
@@ -611,18 +716,18 @@ var Workflow = class extends BaseResource {
|
|
|
611
716
|
if (!!params?.runId) {
|
|
612
717
|
searchParams.set("runId", params.runId);
|
|
613
718
|
}
|
|
614
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
719
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
615
720
|
method: "POST",
|
|
616
721
|
body: params?.triggerData
|
|
617
722
|
});
|
|
618
723
|
}
|
|
619
724
|
/**
|
|
620
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
725
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
621
726
|
* @param params - Object containing the runId, stepId, and context
|
|
622
727
|
* @returns Promise containing the workflow resume results
|
|
623
728
|
*/
|
|
624
729
|
resumeAsync(params) {
|
|
625
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
730
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
626
731
|
method: "POST",
|
|
627
732
|
body: {
|
|
628
733
|
stepId: params.stepId,
|
|
@@ -676,16 +781,16 @@ var Workflow = class extends BaseResource {
|
|
|
676
781
|
}
|
|
677
782
|
}
|
|
678
783
|
/**
|
|
679
|
-
* Watches workflow transitions in real-time
|
|
784
|
+
* Watches legacy workflow transitions in real-time
|
|
680
785
|
* @param runId - Optional run ID to filter the watch stream
|
|
681
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
786
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
682
787
|
*/
|
|
683
788
|
async watch({ runId }, onRecord) {
|
|
684
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
789
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
685
790
|
stream: true
|
|
686
791
|
});
|
|
687
792
|
if (!response.ok) {
|
|
688
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
793
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
689
794
|
}
|
|
690
795
|
if (!response.body) {
|
|
691
796
|
throw new Error("Response body is null");
|
|
@@ -719,22 +824,26 @@ var Tool = class extends BaseResource {
|
|
|
719
824
|
if (params.runId) {
|
|
720
825
|
url.set("runId", params.runId);
|
|
721
826
|
}
|
|
827
|
+
const body = {
|
|
828
|
+
data: params.data,
|
|
829
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
830
|
+
};
|
|
722
831
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
723
832
|
method: "POST",
|
|
724
|
-
body
|
|
833
|
+
body
|
|
725
834
|
});
|
|
726
835
|
}
|
|
727
836
|
};
|
|
728
837
|
|
|
729
|
-
// src/resources/
|
|
838
|
+
// src/resources/workflow.ts
|
|
730
839
|
var RECORD_SEPARATOR2 = "";
|
|
731
|
-
var
|
|
840
|
+
var Workflow = class extends BaseResource {
|
|
732
841
|
constructor(options, workflowId) {
|
|
733
842
|
super(options);
|
|
734
843
|
this.workflowId = workflowId;
|
|
735
844
|
}
|
|
736
845
|
/**
|
|
737
|
-
* Creates an async generator that processes a readable stream and yields
|
|
846
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
738
847
|
* separated by the Record Separator character (\x1E)
|
|
739
848
|
*
|
|
740
849
|
* @param stream - The readable stream to process
|
|
@@ -779,21 +888,42 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
779
888
|
}
|
|
780
889
|
}
|
|
781
890
|
/**
|
|
782
|
-
* Retrieves details about the
|
|
783
|
-
* @returns Promise containing
|
|
891
|
+
* Retrieves details about the workflow
|
|
892
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
784
893
|
*/
|
|
785
894
|
details() {
|
|
786
|
-
return this.request(`/api/workflows
|
|
895
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
787
896
|
}
|
|
788
897
|
/**
|
|
789
|
-
* Retrieves all runs for a
|
|
790
|
-
* @
|
|
898
|
+
* Retrieves all runs for a workflow
|
|
899
|
+
* @param params - Parameters for filtering runs
|
|
900
|
+
* @returns Promise containing workflow runs array
|
|
791
901
|
*/
|
|
792
|
-
runs() {
|
|
793
|
-
|
|
902
|
+
runs(params) {
|
|
903
|
+
const searchParams = new URLSearchParams();
|
|
904
|
+
if (params?.fromDate) {
|
|
905
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
906
|
+
}
|
|
907
|
+
if (params?.toDate) {
|
|
908
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
909
|
+
}
|
|
910
|
+
if (params?.limit) {
|
|
911
|
+
searchParams.set("limit", String(params.limit));
|
|
912
|
+
}
|
|
913
|
+
if (params?.offset) {
|
|
914
|
+
searchParams.set("offset", String(params.offset));
|
|
915
|
+
}
|
|
916
|
+
if (params?.resourceId) {
|
|
917
|
+
searchParams.set("resourceId", params.resourceId);
|
|
918
|
+
}
|
|
919
|
+
if (searchParams.size) {
|
|
920
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
921
|
+
} else {
|
|
922
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
923
|
+
}
|
|
794
924
|
}
|
|
795
925
|
/**
|
|
796
|
-
* Creates a new
|
|
926
|
+
* Creates a new workflow run
|
|
797
927
|
* @param params - Optional object containing the optional runId
|
|
798
928
|
* @returns Promise containing the runId of the created run
|
|
799
929
|
*/
|
|
@@ -802,23 +932,24 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
802
932
|
if (!!params?.runId) {
|
|
803
933
|
searchParams.set("runId", params.runId);
|
|
804
934
|
}
|
|
805
|
-
return this.request(`/api/workflows
|
|
935
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
806
936
|
method: "POST"
|
|
807
937
|
});
|
|
808
938
|
}
|
|
809
939
|
/**
|
|
810
|
-
* Starts a
|
|
940
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
811
941
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
812
942
|
* @returns Promise containing success message
|
|
813
943
|
*/
|
|
814
944
|
start(params) {
|
|
815
|
-
|
|
945
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
946
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
816
947
|
method: "POST",
|
|
817
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
948
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
818
949
|
});
|
|
819
950
|
}
|
|
820
951
|
/**
|
|
821
|
-
* Resumes a suspended
|
|
952
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
822
953
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
823
954
|
* @returns Promise containing success message
|
|
824
955
|
*/
|
|
@@ -826,9 +957,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
826
957
|
step,
|
|
827
958
|
runId,
|
|
828
959
|
resumeData,
|
|
829
|
-
|
|
960
|
+
...rest
|
|
830
961
|
}) {
|
|
831
|
-
|
|
962
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
963
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
832
964
|
method: "POST",
|
|
833
965
|
stream: true,
|
|
834
966
|
body: {
|
|
@@ -839,53 +971,237 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
839
971
|
});
|
|
840
972
|
}
|
|
841
973
|
/**
|
|
842
|
-
* Starts a
|
|
974
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
843
975
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
844
|
-
* @returns Promise containing the
|
|
976
|
+
* @returns Promise containing the workflow execution results
|
|
845
977
|
*/
|
|
846
978
|
startAsync(params) {
|
|
847
979
|
const searchParams = new URLSearchParams();
|
|
848
980
|
if (!!params?.runId) {
|
|
849
981
|
searchParams.set("runId", params.runId);
|
|
850
982
|
}
|
|
851
|
-
|
|
983
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
984
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
852
985
|
method: "POST",
|
|
853
|
-
body: { inputData: params.inputData, runtimeContext
|
|
986
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Starts a vNext workflow run and returns a stream
|
|
991
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
992
|
+
* @returns Promise containing the vNext workflow execution results
|
|
993
|
+
*/
|
|
994
|
+
async stream(params) {
|
|
995
|
+
const searchParams = new URLSearchParams();
|
|
996
|
+
if (!!params?.runId) {
|
|
997
|
+
searchParams.set("runId", params.runId);
|
|
998
|
+
}
|
|
999
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
1000
|
+
const response = await this.request(
|
|
1001
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1002
|
+
{
|
|
1003
|
+
method: "POST",
|
|
1004
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1005
|
+
stream: true
|
|
1006
|
+
}
|
|
1007
|
+
);
|
|
1008
|
+
if (!response.ok) {
|
|
1009
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1010
|
+
}
|
|
1011
|
+
if (!response.body) {
|
|
1012
|
+
throw new Error("Response body is null");
|
|
1013
|
+
}
|
|
1014
|
+
const transformStream = new TransformStream({
|
|
1015
|
+
start() {
|
|
1016
|
+
},
|
|
1017
|
+
async transform(chunk, controller) {
|
|
1018
|
+
try {
|
|
1019
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1020
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1021
|
+
for (const chunk2 of chunks) {
|
|
1022
|
+
if (chunk2) {
|
|
1023
|
+
try {
|
|
1024
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
1025
|
+
controller.enqueue(parsedChunk);
|
|
1026
|
+
} catch {
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
} catch {
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
854
1033
|
});
|
|
1034
|
+
return response.body.pipeThrough(transformStream);
|
|
855
1035
|
}
|
|
856
1036
|
/**
|
|
857
|
-
* Resumes a suspended
|
|
1037
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
858
1038
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
859
|
-
* @returns Promise containing the
|
|
1039
|
+
* @returns Promise containing the workflow resume results
|
|
860
1040
|
*/
|
|
861
1041
|
resumeAsync(params) {
|
|
862
|
-
|
|
1042
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1043
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
863
1044
|
method: "POST",
|
|
864
1045
|
body: {
|
|
865
1046
|
step: params.step,
|
|
866
1047
|
resumeData: params.resumeData,
|
|
867
|
-
runtimeContext
|
|
1048
|
+
runtimeContext
|
|
868
1049
|
}
|
|
869
1050
|
});
|
|
870
1051
|
}
|
|
871
1052
|
/**
|
|
872
|
-
* Watches
|
|
1053
|
+
* Watches workflow transitions in real-time
|
|
873
1054
|
* @param runId - Optional run ID to filter the watch stream
|
|
874
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
1055
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
875
1056
|
*/
|
|
876
1057
|
async watch({ runId }, onRecord) {
|
|
877
|
-
const response = await this.request(`/api/workflows
|
|
1058
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
878
1059
|
stream: true
|
|
879
1060
|
});
|
|
880
1061
|
if (!response.ok) {
|
|
881
|
-
throw new Error(`Failed to watch
|
|
1062
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
882
1063
|
}
|
|
883
1064
|
if (!response.body) {
|
|
884
1065
|
throw new Error("Response body is null");
|
|
885
1066
|
}
|
|
886
1067
|
for await (const record of this.streamProcessor(response.body)) {
|
|
887
|
-
|
|
1068
|
+
if (typeof record === "string") {
|
|
1069
|
+
onRecord(JSON.parse(record));
|
|
1070
|
+
} else {
|
|
1071
|
+
onRecord(record);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1077
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1078
|
+
*
|
|
1079
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1080
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1081
|
+
*/
|
|
1082
|
+
static createRecordStream(records) {
|
|
1083
|
+
const encoder = new TextEncoder();
|
|
1084
|
+
return new ReadableStream({
|
|
1085
|
+
async start(controller) {
|
|
1086
|
+
try {
|
|
1087
|
+
for await (const record of records) {
|
|
1088
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1089
|
+
controller.enqueue(encoder.encode(json));
|
|
1090
|
+
}
|
|
1091
|
+
controller.close();
|
|
1092
|
+
} catch (err) {
|
|
1093
|
+
controller.error(err);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
// src/resources/a2a.ts
|
|
1101
|
+
var A2A = class extends BaseResource {
|
|
1102
|
+
constructor(options, agentId) {
|
|
1103
|
+
super(options);
|
|
1104
|
+
this.agentId = agentId;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Get the agent card with metadata about the agent
|
|
1108
|
+
* @returns Promise containing the agent card information
|
|
1109
|
+
*/
|
|
1110
|
+
async getCard() {
|
|
1111
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Send a message to the agent and get a response
|
|
1115
|
+
* @param params - Parameters for the task
|
|
1116
|
+
* @returns Promise containing the task response
|
|
1117
|
+
*/
|
|
1118
|
+
async sendMessage(params) {
|
|
1119
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1120
|
+
method: "POST",
|
|
1121
|
+
body: {
|
|
1122
|
+
method: "tasks/send",
|
|
1123
|
+
params
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
return { task: response.result };
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Get the status and result of a task
|
|
1130
|
+
* @param params - Parameters for querying the task
|
|
1131
|
+
* @returns Promise containing the task response
|
|
1132
|
+
*/
|
|
1133
|
+
async getTask(params) {
|
|
1134
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1135
|
+
method: "POST",
|
|
1136
|
+
body: {
|
|
1137
|
+
method: "tasks/get",
|
|
1138
|
+
params
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
return response.result;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Cancel a running task
|
|
1145
|
+
* @param params - Parameters identifying the task to cancel
|
|
1146
|
+
* @returns Promise containing the task response
|
|
1147
|
+
*/
|
|
1148
|
+
async cancelTask(params) {
|
|
1149
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1150
|
+
method: "POST",
|
|
1151
|
+
body: {
|
|
1152
|
+
method: "tasks/cancel",
|
|
1153
|
+
params
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1159
|
+
* @param params - Parameters for the task
|
|
1160
|
+
* @returns Promise containing the task response
|
|
1161
|
+
*/
|
|
1162
|
+
async sendAndSubscribe(params) {
|
|
1163
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1164
|
+
method: "POST",
|
|
1165
|
+
body: {
|
|
1166
|
+
method: "tasks/sendSubscribe",
|
|
1167
|
+
params
|
|
1168
|
+
},
|
|
1169
|
+
stream: true
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
// src/resources/mcp-tool.ts
|
|
1175
|
+
var MCPTool = class extends BaseResource {
|
|
1176
|
+
serverId;
|
|
1177
|
+
toolId;
|
|
1178
|
+
constructor(options, serverId, toolId) {
|
|
1179
|
+
super(options);
|
|
1180
|
+
this.serverId = serverId;
|
|
1181
|
+
this.toolId = toolId;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1185
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1186
|
+
*/
|
|
1187
|
+
details() {
|
|
1188
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Executes this specific tool on the MCP server.
|
|
1192
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1193
|
+
* @returns Promise containing the result of the tool execution.
|
|
1194
|
+
*/
|
|
1195
|
+
execute(params) {
|
|
1196
|
+
const body = {};
|
|
1197
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1198
|
+
if (params.runtimeContext !== void 0) {
|
|
1199
|
+
body.runtimeContext = params.runtimeContext;
|
|
888
1200
|
}
|
|
1201
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1202
|
+
method: "POST",
|
|
1203
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1204
|
+
});
|
|
889
1205
|
}
|
|
890
1206
|
};
|
|
891
1207
|
|
|
@@ -981,6 +1297,21 @@ var MastraClient = class extends BaseResource {
|
|
|
981
1297
|
getTool(toolId) {
|
|
982
1298
|
return new Tool(this.options, toolId);
|
|
983
1299
|
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Retrieves all available legacy workflows
|
|
1302
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1303
|
+
*/
|
|
1304
|
+
getLegacyWorkflows() {
|
|
1305
|
+
return this.request("/api/workflows/legacy");
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Gets a legacy workflow instance by ID
|
|
1309
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1310
|
+
* @returns Legacy Workflow instance
|
|
1311
|
+
*/
|
|
1312
|
+
getLegacyWorkflow(workflowId) {
|
|
1313
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1314
|
+
}
|
|
984
1315
|
/**
|
|
985
1316
|
* Retrieves all available workflows
|
|
986
1317
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -996,21 +1327,6 @@ var MastraClient = class extends BaseResource {
|
|
|
996
1327
|
getWorkflow(workflowId) {
|
|
997
1328
|
return new Workflow(this.options, workflowId);
|
|
998
1329
|
}
|
|
999
|
-
/**
|
|
1000
|
-
* Retrieves all available vNext workflows
|
|
1001
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1002
|
-
*/
|
|
1003
|
-
getVNextWorkflows() {
|
|
1004
|
-
return this.request("/api/workflows/v-next");
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Gets a vNext workflow instance by ID
|
|
1008
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1009
|
-
* @returns vNext Workflow instance
|
|
1010
|
-
*/
|
|
1011
|
-
getVNextWorkflow(workflowId) {
|
|
1012
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
1013
|
-
}
|
|
1014
1330
|
/**
|
|
1015
1331
|
* Gets a vector instance by name
|
|
1016
1332
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -1025,7 +1341,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1025
1341
|
* @returns Promise containing array of log messages
|
|
1026
1342
|
*/
|
|
1027
1343
|
getLogs(params) {
|
|
1028
|
-
|
|
1344
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1345
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1346
|
+
const searchParams = new URLSearchParams();
|
|
1347
|
+
if (transportId) {
|
|
1348
|
+
searchParams.set("transportId", transportId);
|
|
1349
|
+
}
|
|
1350
|
+
if (fromDate) {
|
|
1351
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1352
|
+
}
|
|
1353
|
+
if (toDate) {
|
|
1354
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1355
|
+
}
|
|
1356
|
+
if (logLevel) {
|
|
1357
|
+
searchParams.set("logLevel", logLevel);
|
|
1358
|
+
}
|
|
1359
|
+
if (page) {
|
|
1360
|
+
searchParams.set("page", String(page));
|
|
1361
|
+
}
|
|
1362
|
+
if (perPage) {
|
|
1363
|
+
searchParams.set("perPage", String(perPage));
|
|
1364
|
+
}
|
|
1365
|
+
if (_filters) {
|
|
1366
|
+
if (Array.isArray(_filters)) {
|
|
1367
|
+
for (const filter of _filters) {
|
|
1368
|
+
searchParams.append("filters", filter);
|
|
1369
|
+
}
|
|
1370
|
+
} else {
|
|
1371
|
+
searchParams.set("filters", _filters);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
if (searchParams.size) {
|
|
1375
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1376
|
+
} else {
|
|
1377
|
+
return this.request(`/api/logs`);
|
|
1378
|
+
}
|
|
1029
1379
|
}
|
|
1030
1380
|
/**
|
|
1031
1381
|
* Gets logs for a specific run
|
|
@@ -1033,7 +1383,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1033
1383
|
* @returns Promise containing array of log messages
|
|
1034
1384
|
*/
|
|
1035
1385
|
getLogForRun(params) {
|
|
1036
|
-
|
|
1386
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1387
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1388
|
+
const searchParams = new URLSearchParams();
|
|
1389
|
+
if (runId) {
|
|
1390
|
+
searchParams.set("runId", runId);
|
|
1391
|
+
}
|
|
1392
|
+
if (transportId) {
|
|
1393
|
+
searchParams.set("transportId", transportId);
|
|
1394
|
+
}
|
|
1395
|
+
if (fromDate) {
|
|
1396
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1397
|
+
}
|
|
1398
|
+
if (toDate) {
|
|
1399
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1400
|
+
}
|
|
1401
|
+
if (logLevel) {
|
|
1402
|
+
searchParams.set("logLevel", logLevel);
|
|
1403
|
+
}
|
|
1404
|
+
if (page) {
|
|
1405
|
+
searchParams.set("page", String(page));
|
|
1406
|
+
}
|
|
1407
|
+
if (perPage) {
|
|
1408
|
+
searchParams.set("perPage", String(perPage));
|
|
1409
|
+
}
|
|
1410
|
+
if (_filters) {
|
|
1411
|
+
if (Array.isArray(_filters)) {
|
|
1412
|
+
for (const filter of _filters) {
|
|
1413
|
+
searchParams.append("filters", filter);
|
|
1414
|
+
}
|
|
1415
|
+
} else {
|
|
1416
|
+
searchParams.set("filters", _filters);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
if (searchParams.size) {
|
|
1420
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
1421
|
+
} else {
|
|
1422
|
+
return this.request(`/api/logs/${runId}`);
|
|
1423
|
+
}
|
|
1037
1424
|
}
|
|
1038
1425
|
/**
|
|
1039
1426
|
* List of all log transports
|
|
@@ -1048,7 +1435,7 @@ var MastraClient = class extends BaseResource {
|
|
|
1048
1435
|
* @returns Promise containing telemetry data
|
|
1049
1436
|
*/
|
|
1050
1437
|
getTelemetry(params) {
|
|
1051
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1438
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
1052
1439
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
1053
1440
|
const searchParams = new URLSearchParams();
|
|
1054
1441
|
if (name) {
|
|
@@ -1072,6 +1459,12 @@ var MastraClient = class extends BaseResource {
|
|
|
1072
1459
|
searchParams.set("attribute", _attribute);
|
|
1073
1460
|
}
|
|
1074
1461
|
}
|
|
1462
|
+
if (fromDate) {
|
|
1463
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1464
|
+
}
|
|
1465
|
+
if (toDate) {
|
|
1466
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1467
|
+
}
|
|
1075
1468
|
if (searchParams.size) {
|
|
1076
1469
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
1077
1470
|
} else {
|
|
@@ -1093,6 +1486,62 @@ var MastraClient = class extends BaseResource {
|
|
|
1093
1486
|
getNetwork(networkId) {
|
|
1094
1487
|
return new Network(this.options, networkId);
|
|
1095
1488
|
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Retrieves a list of available MCP servers.
|
|
1491
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1492
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
1493
|
+
*/
|
|
1494
|
+
getMcpServers(params) {
|
|
1495
|
+
const searchParams = new URLSearchParams();
|
|
1496
|
+
if (params?.limit !== void 0) {
|
|
1497
|
+
searchParams.set("limit", String(params.limit));
|
|
1498
|
+
}
|
|
1499
|
+
if (params?.offset !== void 0) {
|
|
1500
|
+
searchParams.set("offset", String(params.offset));
|
|
1501
|
+
}
|
|
1502
|
+
const queryString = searchParams.toString();
|
|
1503
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1507
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1508
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1509
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1510
|
+
*/
|
|
1511
|
+
getMcpServerDetails(serverId, params) {
|
|
1512
|
+
const searchParams = new URLSearchParams();
|
|
1513
|
+
if (params?.version) {
|
|
1514
|
+
searchParams.set("version", params.version);
|
|
1515
|
+
}
|
|
1516
|
+
const queryString = searchParams.toString();
|
|
1517
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1521
|
+
* @param serverId - The ID of the MCP server.
|
|
1522
|
+
* @returns Promise containing the list of tools.
|
|
1523
|
+
*/
|
|
1524
|
+
getMcpServerTools(serverId) {
|
|
1525
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1529
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1530
|
+
* @param serverId - The ID of the MCP server.
|
|
1531
|
+
* @param toolId - The ID of the tool.
|
|
1532
|
+
* @returns MCPTool instance.
|
|
1533
|
+
*/
|
|
1534
|
+
getMcpServerTool(serverId, toolId) {
|
|
1535
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1539
|
+
* @param agentId - ID of the agent to interact with
|
|
1540
|
+
* @returns A2A client instance
|
|
1541
|
+
*/
|
|
1542
|
+
getA2A(agentId) {
|
|
1543
|
+
return new A2A(this.options, agentId);
|
|
1544
|
+
}
|
|
1096
1545
|
};
|
|
1097
1546
|
|
|
1098
1547
|
exports.MastraClient = MastraClient;
|