@mastra/client-js 0.0.0-agui-20250501191909 → 0.0.0-cloud-transporter-20250513033346
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +160 -2
- package/dist/index.cjs +218 -28
- package/dist/index.d.cts +97 -29
- package/dist/index.d.ts +97 -29
- package/dist/index.js +214 -28
- package/package.json +6 -6
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +20 -4
- package/src/index.test.ts +30 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +26 -34
- package/src/resources/index.ts +1 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network.ts +5 -11
- package/src/resources/tool.ts +8 -2
- package/src/resources/vnext-workflow.ts +34 -7
- package/src/resources/workflow.ts +31 -3
- package/src/types.ts +20 -2
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import
|
|
5
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
// src/adapters/agui.ts
|
|
8
8
|
var AGUIAdapter = class extends AbstractAgent {
|
|
@@ -42,6 +42,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
42
42
|
)
|
|
43
43
|
}).then((response) => {
|
|
44
44
|
let currentMessageId = void 0;
|
|
45
|
+
let isInTextMessage = false;
|
|
45
46
|
return response.processDataStream({
|
|
46
47
|
onTextPart: (text) => {
|
|
47
48
|
if (currentMessageId === void 0) {
|
|
@@ -52,6 +53,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
52
53
|
role: "assistant"
|
|
53
54
|
};
|
|
54
55
|
subscriber.next(message2);
|
|
56
|
+
isInTextMessage = true;
|
|
55
57
|
}
|
|
56
58
|
const message = {
|
|
57
59
|
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
@@ -60,14 +62,14 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
60
62
|
};
|
|
61
63
|
subscriber.next(message);
|
|
62
64
|
},
|
|
63
|
-
onFinishMessagePart: (
|
|
64
|
-
console.log("onFinishMessagePart", message);
|
|
65
|
+
onFinishMessagePart: () => {
|
|
65
66
|
if (currentMessageId !== void 0) {
|
|
66
|
-
const
|
|
67
|
+
const message = {
|
|
67
68
|
type: EventType.TEXT_MESSAGE_END,
|
|
68
69
|
messageId: currentMessageId
|
|
69
70
|
};
|
|
70
|
-
subscriber.next(
|
|
71
|
+
subscriber.next(message);
|
|
72
|
+
isInTextMessage = false;
|
|
71
73
|
}
|
|
72
74
|
subscriber.next({
|
|
73
75
|
type: EventType.RUN_FINISHED,
|
|
@@ -78,6 +80,14 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
78
80
|
},
|
|
79
81
|
onToolCallPart(streamPart) {
|
|
80
82
|
const parentMessageId = currentMessageId || generateUUID();
|
|
83
|
+
if (isInTextMessage) {
|
|
84
|
+
const message = {
|
|
85
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
86
|
+
messageId: parentMessageId
|
|
87
|
+
};
|
|
88
|
+
subscriber.next(message);
|
|
89
|
+
isInTextMessage = false;
|
|
90
|
+
}
|
|
81
91
|
subscriber.next({
|
|
82
92
|
type: EventType.TOOL_CALL_START,
|
|
83
93
|
toolCallId: streamPart.toolCallId,
|
|
@@ -98,7 +108,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
98
108
|
}
|
|
99
109
|
});
|
|
100
110
|
}).catch((error) => {
|
|
101
|
-
console.
|
|
111
|
+
console.error("error", error);
|
|
102
112
|
subscriber.error(error);
|
|
103
113
|
});
|
|
104
114
|
return () => {
|
|
@@ -147,6 +157,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
147
157
|
role: "assistant",
|
|
148
158
|
content: parts
|
|
149
159
|
});
|
|
160
|
+
if (message.toolCalls?.length) {
|
|
161
|
+
result.push({
|
|
162
|
+
role: "tool",
|
|
163
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
164
|
+
type: "tool-result",
|
|
165
|
+
toolCallId: toolCall.id,
|
|
166
|
+
toolName: toolCall.function.name,
|
|
167
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
168
|
+
}))
|
|
169
|
+
});
|
|
170
|
+
}
|
|
150
171
|
} else if (message.role === "user") {
|
|
151
172
|
result.push({
|
|
152
173
|
role: "user",
|
|
@@ -168,6 +189,12 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
168
189
|
}
|
|
169
190
|
return result;
|
|
170
191
|
}
|
|
192
|
+
function zodToJsonSchema(zodSchema) {
|
|
193
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
194
|
+
return zodSchema;
|
|
195
|
+
}
|
|
196
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
197
|
+
}
|
|
171
198
|
|
|
172
199
|
// src/resources/base.ts
|
|
173
200
|
var BaseResource = class {
|
|
@@ -298,8 +325,9 @@ var Agent = class extends BaseResource {
|
|
|
298
325
|
generate(params) {
|
|
299
326
|
const processedParams = {
|
|
300
327
|
...params,
|
|
301
|
-
output:
|
|
302
|
-
experimental_output:
|
|
328
|
+
output: zodToJsonSchema(params.output),
|
|
329
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
330
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
303
331
|
};
|
|
304
332
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
305
333
|
method: "POST",
|
|
@@ -314,8 +342,9 @@ var Agent = class extends BaseResource {
|
|
|
314
342
|
async stream(params) {
|
|
315
343
|
const processedParams = {
|
|
316
344
|
...params,
|
|
317
|
-
output:
|
|
318
|
-
experimental_output:
|
|
345
|
+
output: zodToJsonSchema(params.output),
|
|
346
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
347
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
319
348
|
};
|
|
320
349
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
321
350
|
method: "POST",
|
|
@@ -341,6 +370,22 @@ var Agent = class extends BaseResource {
|
|
|
341
370
|
getTool(toolId) {
|
|
342
371
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
343
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Executes a tool for the agent
|
|
375
|
+
* @param toolId - ID of the tool to execute
|
|
376
|
+
* @param params - Parameters required for tool execution
|
|
377
|
+
* @returns Promise containing the tool execution results
|
|
378
|
+
*/
|
|
379
|
+
executeTool(toolId, params) {
|
|
380
|
+
const body = {
|
|
381
|
+
data: params.data,
|
|
382
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
383
|
+
};
|
|
384
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
385
|
+
method: "POST",
|
|
386
|
+
body
|
|
387
|
+
});
|
|
388
|
+
}
|
|
344
389
|
/**
|
|
345
390
|
* Retrieves evaluation results for the agent
|
|
346
391
|
* @returns Promise containing agent evaluations
|
|
@@ -376,8 +421,8 @@ var Network = class extends BaseResource {
|
|
|
376
421
|
generate(params) {
|
|
377
422
|
const processedParams = {
|
|
378
423
|
...params,
|
|
379
|
-
output:
|
|
380
|
-
experimental_output:
|
|
424
|
+
output: zodToJsonSchema(params.output),
|
|
425
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
381
426
|
};
|
|
382
427
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
383
428
|
method: "POST",
|
|
@@ -392,8 +437,8 @@ var Network = class extends BaseResource {
|
|
|
392
437
|
async stream(params) {
|
|
393
438
|
const processedParams = {
|
|
394
439
|
...params,
|
|
395
|
-
output:
|
|
396
|
-
experimental_output:
|
|
440
|
+
output: zodToJsonSchema(params.output),
|
|
441
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
397
442
|
};
|
|
398
443
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
399
444
|
method: "POST",
|
|
@@ -449,10 +494,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
449
494
|
}
|
|
450
495
|
/**
|
|
451
496
|
* Retrieves messages associated with the thread
|
|
497
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
452
498
|
* @returns Promise containing thread messages and UI messages
|
|
453
499
|
*/
|
|
454
|
-
getMessages() {
|
|
455
|
-
|
|
500
|
+
getMessages(params) {
|
|
501
|
+
const query = new URLSearchParams({
|
|
502
|
+
agentId: this.agentId,
|
|
503
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
504
|
+
});
|
|
505
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
456
506
|
}
|
|
457
507
|
};
|
|
458
508
|
|
|
@@ -538,10 +588,31 @@ var Workflow = class extends BaseResource {
|
|
|
538
588
|
}
|
|
539
589
|
/**
|
|
540
590
|
* Retrieves all runs for a workflow
|
|
591
|
+
* @param params - Parameters for filtering runs
|
|
541
592
|
* @returns Promise containing workflow runs array
|
|
542
593
|
*/
|
|
543
|
-
runs() {
|
|
544
|
-
|
|
594
|
+
runs(params) {
|
|
595
|
+
const searchParams = new URLSearchParams();
|
|
596
|
+
if (params?.fromDate) {
|
|
597
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
598
|
+
}
|
|
599
|
+
if (params?.toDate) {
|
|
600
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
601
|
+
}
|
|
602
|
+
if (params?.limit) {
|
|
603
|
+
searchParams.set("limit", String(params.limit));
|
|
604
|
+
}
|
|
605
|
+
if (params?.offset) {
|
|
606
|
+
searchParams.set("offset", String(params.offset));
|
|
607
|
+
}
|
|
608
|
+
if (params?.resourceId) {
|
|
609
|
+
searchParams.set("resourceId", params.resourceId);
|
|
610
|
+
}
|
|
611
|
+
if (searchParams.size) {
|
|
612
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
613
|
+
} else {
|
|
614
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
615
|
+
}
|
|
545
616
|
}
|
|
546
617
|
/**
|
|
547
618
|
* @deprecated Use `startAsync` instead
|
|
@@ -717,14 +788,16 @@ var Tool = class extends BaseResource {
|
|
|
717
788
|
if (params.runId) {
|
|
718
789
|
url.set("runId", params.runId);
|
|
719
790
|
}
|
|
791
|
+
const body = {
|
|
792
|
+
data: params.data,
|
|
793
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
794
|
+
};
|
|
720
795
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
721
796
|
method: "POST",
|
|
722
|
-
body
|
|
797
|
+
body
|
|
723
798
|
});
|
|
724
799
|
}
|
|
725
800
|
};
|
|
726
|
-
|
|
727
|
-
// src/resources/vnext-workflow.ts
|
|
728
801
|
var RECORD_SEPARATOR2 = "";
|
|
729
802
|
var VNextWorkflow = class extends BaseResource {
|
|
730
803
|
constructor(options, workflowId) {
|
|
@@ -785,10 +858,31 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
785
858
|
}
|
|
786
859
|
/**
|
|
787
860
|
* Retrieves all runs for a vNext workflow
|
|
861
|
+
* @param params - Parameters for filtering runs
|
|
788
862
|
* @returns Promise containing vNext workflow runs array
|
|
789
863
|
*/
|
|
790
|
-
runs() {
|
|
791
|
-
|
|
864
|
+
runs(params) {
|
|
865
|
+
const searchParams = new URLSearchParams();
|
|
866
|
+
if (params?.fromDate) {
|
|
867
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
868
|
+
}
|
|
869
|
+
if (params?.toDate) {
|
|
870
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
871
|
+
}
|
|
872
|
+
if (params?.limit) {
|
|
873
|
+
searchParams.set("limit", String(params.limit));
|
|
874
|
+
}
|
|
875
|
+
if (params?.offset) {
|
|
876
|
+
searchParams.set("offset", String(params.offset));
|
|
877
|
+
}
|
|
878
|
+
if (params?.resourceId) {
|
|
879
|
+
searchParams.set("resourceId", params.resourceId);
|
|
880
|
+
}
|
|
881
|
+
if (searchParams.size) {
|
|
882
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
883
|
+
} else {
|
|
884
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
885
|
+
}
|
|
792
886
|
}
|
|
793
887
|
/**
|
|
794
888
|
* Creates a new vNext workflow run
|
|
@@ -810,9 +904,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
810
904
|
* @returns Promise containing success message
|
|
811
905
|
*/
|
|
812
906
|
start(params) {
|
|
907
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
813
908
|
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
814
909
|
method: "POST",
|
|
815
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
910
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
816
911
|
});
|
|
817
912
|
}
|
|
818
913
|
/**
|
|
@@ -824,8 +919,9 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
824
919
|
step,
|
|
825
920
|
runId,
|
|
826
921
|
resumeData,
|
|
827
|
-
|
|
922
|
+
...rest
|
|
828
923
|
}) {
|
|
924
|
+
const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
|
|
829
925
|
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
830
926
|
method: "POST",
|
|
831
927
|
stream: true,
|
|
@@ -846,9 +942,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
846
942
|
if (!!params?.runId) {
|
|
847
943
|
searchParams.set("runId", params.runId);
|
|
848
944
|
}
|
|
945
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
849
946
|
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
850
947
|
method: "POST",
|
|
851
|
-
body: { inputData: params.inputData, runtimeContext
|
|
948
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
852
949
|
});
|
|
853
950
|
}
|
|
854
951
|
/**
|
|
@@ -857,12 +954,13 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
857
954
|
* @returns Promise containing the vNext workflow resume results
|
|
858
955
|
*/
|
|
859
956
|
resumeAsync(params) {
|
|
957
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
860
958
|
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
861
959
|
method: "POST",
|
|
862
960
|
body: {
|
|
863
961
|
step: params.step,
|
|
864
962
|
resumeData: params.resumeData,
|
|
865
|
-
runtimeContext
|
|
963
|
+
runtimeContext
|
|
866
964
|
}
|
|
867
965
|
});
|
|
868
966
|
}
|
|
@@ -887,6 +985,80 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
887
985
|
}
|
|
888
986
|
};
|
|
889
987
|
|
|
988
|
+
// src/resources/a2a.ts
|
|
989
|
+
var A2A = class extends BaseResource {
|
|
990
|
+
constructor(options, agentId) {
|
|
991
|
+
super(options);
|
|
992
|
+
this.agentId = agentId;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Get the agent card with metadata about the agent
|
|
996
|
+
* @returns Promise containing the agent card information
|
|
997
|
+
*/
|
|
998
|
+
async getCard() {
|
|
999
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Send a message to the agent and get a response
|
|
1003
|
+
* @param params - Parameters for the task
|
|
1004
|
+
* @returns Promise containing the task response
|
|
1005
|
+
*/
|
|
1006
|
+
async sendMessage(params) {
|
|
1007
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1008
|
+
method: "POST",
|
|
1009
|
+
body: {
|
|
1010
|
+
method: "tasks/send",
|
|
1011
|
+
params
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
return { task: response.result };
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Get the status and result of a task
|
|
1018
|
+
* @param params - Parameters for querying the task
|
|
1019
|
+
* @returns Promise containing the task response
|
|
1020
|
+
*/
|
|
1021
|
+
async getTask(params) {
|
|
1022
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1023
|
+
method: "POST",
|
|
1024
|
+
body: {
|
|
1025
|
+
method: "tasks/get",
|
|
1026
|
+
params
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
return response.result;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Cancel a running task
|
|
1033
|
+
* @param params - Parameters identifying the task to cancel
|
|
1034
|
+
* @returns Promise containing the task response
|
|
1035
|
+
*/
|
|
1036
|
+
async cancelTask(params) {
|
|
1037
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1038
|
+
method: "POST",
|
|
1039
|
+
body: {
|
|
1040
|
+
method: "tasks/cancel",
|
|
1041
|
+
params
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1047
|
+
* @param params - Parameters for the task
|
|
1048
|
+
* @returns Promise containing the task response
|
|
1049
|
+
*/
|
|
1050
|
+
async sendAndSubscribe(params) {
|
|
1051
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1052
|
+
method: "POST",
|
|
1053
|
+
body: {
|
|
1054
|
+
method: "tasks/sendSubscribe",
|
|
1055
|
+
params
|
|
1056
|
+
},
|
|
1057
|
+
stream: true
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
|
|
890
1062
|
// src/client.ts
|
|
891
1063
|
var MastraClient = class extends BaseResource {
|
|
892
1064
|
constructor(options) {
|
|
@@ -1046,7 +1218,7 @@ var MastraClient = class extends BaseResource {
|
|
|
1046
1218
|
* @returns Promise containing telemetry data
|
|
1047
1219
|
*/
|
|
1048
1220
|
getTelemetry(params) {
|
|
1049
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1221
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
1050
1222
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
1051
1223
|
const searchParams = new URLSearchParams();
|
|
1052
1224
|
if (name) {
|
|
@@ -1070,6 +1242,12 @@ var MastraClient = class extends BaseResource {
|
|
|
1070
1242
|
searchParams.set("attribute", _attribute);
|
|
1071
1243
|
}
|
|
1072
1244
|
}
|
|
1245
|
+
if (fromDate) {
|
|
1246
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1247
|
+
}
|
|
1248
|
+
if (toDate) {
|
|
1249
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1250
|
+
}
|
|
1073
1251
|
if (searchParams.size) {
|
|
1074
1252
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
1075
1253
|
} else {
|
|
@@ -1091,6 +1269,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1091
1269
|
getNetwork(networkId) {
|
|
1092
1270
|
return new Network(this.options, networkId);
|
|
1093
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1274
|
+
* @param agentId - ID of the agent to interact with
|
|
1275
|
+
* @returns A2A client instance
|
|
1276
|
+
*/
|
|
1277
|
+
getA2A(agentId) {
|
|
1278
|
+
return new A2A(this.options, agentId);
|
|
1279
|
+
}
|
|
1094
1280
|
};
|
|
1095
1281
|
|
|
1096
1282
|
export { MastraClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-cloud-transporter-20250513033346",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"@ai-sdk/ui-utils": "^1.1.19",
|
|
27
27
|
"json-schema": "^0.4.0",
|
|
28
28
|
"rxjs": "7.8.1",
|
|
29
|
-
"zod": "^3.24.
|
|
30
|
-
"zod-to-json-schema": "^3.24.
|
|
31
|
-
"@mastra/core": "0.0.0-
|
|
29
|
+
"zod": "^3.24.3",
|
|
30
|
+
"zod-to-json-schema": "^3.24.5",
|
|
31
|
+
"@mastra/core": "0.0.0-cloud-transporter-20250513033346"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"zod": "^3.
|
|
34
|
+
"zod": "^3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/preset-env": "^7.26.9",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"tsup": "^8.4.0",
|
|
43
43
|
"typescript": "^5.8.2",
|
|
44
44
|
"vitest": "^3.1.2",
|
|
45
|
-
"@internal/lint": "0.0.
|
|
45
|
+
"@internal/lint": "0.0.0-cloud-transporter-20250513033346"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
|
@@ -91,6 +91,17 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
91
91
|
},
|
|
92
92
|
],
|
|
93
93
|
},
|
|
94
|
+
{
|
|
95
|
+
role: 'tool',
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'tool-result',
|
|
99
|
+
toolCallId: 'tool-call-1',
|
|
100
|
+
toolName: 'getWeather',
|
|
101
|
+
result: { location: 'San Francisco' },
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
94
105
|
]);
|
|
95
106
|
});
|
|
96
107
|
|
|
@@ -143,12 +154,6 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
143
154
|
},
|
|
144
155
|
],
|
|
145
156
|
},
|
|
146
|
-
{
|
|
147
|
-
id: '3',
|
|
148
|
-
role: 'tool',
|
|
149
|
-
toolCallId: 'tool-call-1',
|
|
150
|
-
content: '{"temperature":72,"unit":"F"}',
|
|
151
|
-
},
|
|
152
157
|
{
|
|
153
158
|
id: '4',
|
|
154
159
|
role: 'assistant',
|
|
@@ -162,6 +167,14 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
162
167
|
expect(result[0].role).toBe('user');
|
|
163
168
|
expect(result[1].role).toBe('assistant');
|
|
164
169
|
expect(result[2].role).toBe('tool');
|
|
170
|
+
expect(result[2].content).toEqual([
|
|
171
|
+
{
|
|
172
|
+
type: 'tool-result',
|
|
173
|
+
toolCallId: 'tool-call-1',
|
|
174
|
+
toolName: 'getWeather',
|
|
175
|
+
result: { location: 'San Francisco' },
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
165
178
|
expect(result[3].role).toBe('assistant');
|
|
166
179
|
});
|
|
167
180
|
});
|
package/src/adapters/agui.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Cross-platform UUID generation function
|
|
2
|
-
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
3
2
|
import type {
|
|
3
|
+
AgentConfig,
|
|
4
4
|
BaseEvent,
|
|
5
|
+
Message,
|
|
5
6
|
RunAgentInput,
|
|
6
|
-
AgentConfig,
|
|
7
|
-
RunStartedEvent,
|
|
8
7
|
RunFinishedEvent,
|
|
9
|
-
|
|
8
|
+
RunStartedEvent,
|
|
10
9
|
TextMessageContentEvent,
|
|
11
10
|
TextMessageEndEvent,
|
|
12
|
-
|
|
13
|
-
ToolCallStartEvent,
|
|
11
|
+
TextMessageStartEvent,
|
|
14
12
|
ToolCallArgsEvent,
|
|
15
13
|
ToolCallEndEvent,
|
|
14
|
+
ToolCallStartEvent,
|
|
16
15
|
} from '@ag-ui/client';
|
|
16
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
17
17
|
import type { CoreMessage } from '@mastra/core';
|
|
18
18
|
import { Observable } from 'rxjs';
|
|
19
19
|
import type { Agent } from '../resources/agent';
|
|
@@ -39,7 +39,6 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
39
39
|
protected run(input: RunAgentInput): Observable<BaseEvent> {
|
|
40
40
|
return new Observable<BaseEvent>(subscriber => {
|
|
41
41
|
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
42
|
-
|
|
43
42
|
subscriber.next({
|
|
44
43
|
type: EventType.RUN_STARTED,
|
|
45
44
|
threadId: input.threadId,
|
|
@@ -66,17 +65,18 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
66
65
|
})
|
|
67
66
|
.then(response => {
|
|
68
67
|
let currentMessageId: string | undefined = undefined;
|
|
68
|
+
let isInTextMessage = false;
|
|
69
69
|
return response.processDataStream({
|
|
70
70
|
onTextPart: text => {
|
|
71
71
|
if (currentMessageId === undefined) {
|
|
72
72
|
currentMessageId = generateUUID();
|
|
73
|
-
|
|
74
73
|
const message: TextMessageStartEvent = {
|
|
75
74
|
type: EventType.TEXT_MESSAGE_START,
|
|
76
75
|
messageId: currentMessageId,
|
|
77
76
|
role: 'assistant',
|
|
78
77
|
};
|
|
79
78
|
subscriber.next(message);
|
|
79
|
+
isInTextMessage = true;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const message: TextMessageContentEvent = {
|
|
@@ -86,14 +86,14 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
86
86
|
};
|
|
87
87
|
subscriber.next(message);
|
|
88
88
|
},
|
|
89
|
-
onFinishMessagePart:
|
|
90
|
-
console.log('onFinishMessagePart', message);
|
|
89
|
+
onFinishMessagePart: () => {
|
|
91
90
|
if (currentMessageId !== undefined) {
|
|
92
91
|
const message: TextMessageEndEvent = {
|
|
93
92
|
type: EventType.TEXT_MESSAGE_END,
|
|
94
93
|
messageId: currentMessageId,
|
|
95
94
|
};
|
|
96
95
|
subscriber.next(message);
|
|
96
|
+
isInTextMessage = false;
|
|
97
97
|
}
|
|
98
98
|
// Emit run finished event
|
|
99
99
|
subscriber.next({
|
|
@@ -107,6 +107,15 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
107
107
|
},
|
|
108
108
|
onToolCallPart(streamPart) {
|
|
109
109
|
const parentMessageId = currentMessageId || generateUUID();
|
|
110
|
+
if (isInTextMessage) {
|
|
111
|
+
const message: TextMessageEndEvent = {
|
|
112
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
113
|
+
messageId: parentMessageId,
|
|
114
|
+
};
|
|
115
|
+
subscriber.next(message);
|
|
116
|
+
isInTextMessage = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
subscriber.next({
|
|
111
120
|
type: EventType.TOOL_CALL_START,
|
|
112
121
|
toolCallId: streamPart.toolCallId,
|
|
@@ -130,7 +139,7 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
130
139
|
});
|
|
131
140
|
})
|
|
132
141
|
.catch(error => {
|
|
133
|
-
console.
|
|
142
|
+
console.error('error', error);
|
|
134
143
|
// Handle error
|
|
135
144
|
subscriber.error(error);
|
|
136
145
|
});
|
|
@@ -195,6 +204,17 @@ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessag
|
|
|
195
204
|
role: 'assistant',
|
|
196
205
|
content: parts,
|
|
197
206
|
});
|
|
207
|
+
if (message.toolCalls?.length) {
|
|
208
|
+
result.push({
|
|
209
|
+
role: 'tool',
|
|
210
|
+
content: message.toolCalls.map(toolCall => ({
|
|
211
|
+
type: 'tool-result',
|
|
212
|
+
toolCallId: toolCall.id,
|
|
213
|
+
toolName: toolCall.function.name,
|
|
214
|
+
result: JSON.parse(toolCall.function.arguments),
|
|
215
|
+
})),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
198
218
|
} else if (message.role === 'user') {
|
|
199
219
|
result.push({
|
|
200
220
|
role: 'user',
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AbstractAgent } from '@ag-ui/client';
|
|
1
2
|
import { AGUIAdapter } from './adapters/agui';
|
|
2
|
-
import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
|
|
3
|
+
import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow, A2A } from './resources';
|
|
3
4
|
import type {
|
|
4
5
|
ClientOptions,
|
|
5
6
|
CreateMemoryThreadParams,
|
|
@@ -33,7 +34,7 @@ export class MastraClient extends BaseResource {
|
|
|
33
34
|
return this.request('/api/agents');
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string,
|
|
37
|
+
public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
|
|
37
38
|
const agents = await this.getAgents();
|
|
38
39
|
|
|
39
40
|
return Object.entries(agents).reduce(
|
|
@@ -48,7 +49,7 @@ export class MastraClient extends BaseResource {
|
|
|
48
49
|
|
|
49
50
|
return acc;
|
|
50
51
|
},
|
|
51
|
-
{} as Record<string,
|
|
52
|
+
{} as Record<string, AbstractAgent>,
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -200,7 +201,7 @@ export class MastraClient extends BaseResource {
|
|
|
200
201
|
* @returns Promise containing telemetry data
|
|
201
202
|
*/
|
|
202
203
|
public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
|
|
203
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
204
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
204
205
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
205
206
|
|
|
206
207
|
const searchParams = new URLSearchParams();
|
|
@@ -225,6 +226,12 @@ export class MastraClient extends BaseResource {
|
|
|
225
226
|
searchParams.set('attribute', _attribute);
|
|
226
227
|
}
|
|
227
228
|
}
|
|
229
|
+
if (fromDate) {
|
|
230
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
231
|
+
}
|
|
232
|
+
if (toDate) {
|
|
233
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
234
|
+
}
|
|
228
235
|
|
|
229
236
|
if (searchParams.size) {
|
|
230
237
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
@@ -249,4 +256,13 @@ export class MastraClient extends BaseResource {
|
|
|
249
256
|
public getNetwork(networkId: string) {
|
|
250
257
|
return new Network(this.options, networkId);
|
|
251
258
|
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
262
|
+
* @param agentId - ID of the agent to interact with
|
|
263
|
+
* @returns A2A client instance
|
|
264
|
+
*/
|
|
265
|
+
public getA2A(agentId: string) {
|
|
266
|
+
return new A2A(this.options, agentId);
|
|
267
|
+
}
|
|
252
268
|
}
|