@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-vnext-inngest-20250506123700
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 +170 -2
- package/dist/index.cjs +423 -6
- package/dist/index.d.cts +148 -3
- package/dist/index.d.ts +148 -3
- package/dist/index.js +423 -6
- package/package.json +6 -4
- package/src/adapters/agui.test.ts +167 -0
- package/src/adapters/agui.ts +219 -0
- package/src/client.ts +47 -2
- package/src/index.test.ts +4 -4
- package/src/resources/agent.ts +1 -2
- package/src/resources/base.ts +1 -1
- package/src/resources/index.ts +1 -0
- package/src/resources/network.ts +1 -1
- package/src/resources/tool.ts +9 -3
- package/src/resources/vnext-workflow.ts +257 -0
- package/src/resources/workflow.ts +38 -2
- package/src/types.ts +38 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,173 @@
|
|
|
1
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
1
4
|
import { ZodSchema } from 'zod';
|
|
2
5
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
|
-
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
6
|
|
|
5
|
-
// src/
|
|
7
|
+
// src/adapters/agui.ts
|
|
8
|
+
var AGUIAdapter = class extends AbstractAgent {
|
|
9
|
+
agent;
|
|
10
|
+
resourceId;
|
|
11
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
12
|
+
super({
|
|
13
|
+
agentId,
|
|
14
|
+
...rest
|
|
15
|
+
});
|
|
16
|
+
this.agent = agent;
|
|
17
|
+
this.resourceId = resourceId;
|
|
18
|
+
}
|
|
19
|
+
run(input) {
|
|
20
|
+
return new Observable((subscriber) => {
|
|
21
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
22
|
+
subscriber.next({
|
|
23
|
+
type: EventType.RUN_STARTED,
|
|
24
|
+
threadId: input.threadId,
|
|
25
|
+
runId: input.runId
|
|
26
|
+
});
|
|
27
|
+
this.agent.stream({
|
|
28
|
+
threadId: input.threadId,
|
|
29
|
+
resourceId: this.resourceId ?? "",
|
|
30
|
+
runId: input.runId,
|
|
31
|
+
messages: convertedMessages,
|
|
32
|
+
clientTools: input.tools.reduce(
|
|
33
|
+
(acc, tool) => {
|
|
34
|
+
acc[tool.name] = {
|
|
35
|
+
id: tool.name,
|
|
36
|
+
description: tool.description,
|
|
37
|
+
inputSchema: tool.parameters
|
|
38
|
+
};
|
|
39
|
+
return acc;
|
|
40
|
+
},
|
|
41
|
+
{}
|
|
42
|
+
)
|
|
43
|
+
}).then((response) => {
|
|
44
|
+
let currentMessageId = void 0;
|
|
45
|
+
return response.processDataStream({
|
|
46
|
+
onTextPart: (text) => {
|
|
47
|
+
if (currentMessageId === void 0) {
|
|
48
|
+
currentMessageId = generateUUID();
|
|
49
|
+
const message2 = {
|
|
50
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
51
|
+
messageId: currentMessageId,
|
|
52
|
+
role: "assistant"
|
|
53
|
+
};
|
|
54
|
+
subscriber.next(message2);
|
|
55
|
+
}
|
|
56
|
+
const message = {
|
|
57
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
58
|
+
messageId: currentMessageId,
|
|
59
|
+
delta: text
|
|
60
|
+
};
|
|
61
|
+
subscriber.next(message);
|
|
62
|
+
},
|
|
63
|
+
onFinishMessagePart: (message) => {
|
|
64
|
+
console.log("onFinishMessagePart", message);
|
|
65
|
+
if (currentMessageId !== void 0) {
|
|
66
|
+
const message2 = {
|
|
67
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
68
|
+
messageId: currentMessageId
|
|
69
|
+
};
|
|
70
|
+
subscriber.next(message2);
|
|
71
|
+
}
|
|
72
|
+
subscriber.next({
|
|
73
|
+
type: EventType.RUN_FINISHED,
|
|
74
|
+
threadId: input.threadId,
|
|
75
|
+
runId: input.runId
|
|
76
|
+
});
|
|
77
|
+
subscriber.complete();
|
|
78
|
+
},
|
|
79
|
+
onToolCallPart(streamPart) {
|
|
80
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
81
|
+
subscriber.next({
|
|
82
|
+
type: EventType.TOOL_CALL_START,
|
|
83
|
+
toolCallId: streamPart.toolCallId,
|
|
84
|
+
toolCallName: streamPart.toolName,
|
|
85
|
+
parentMessageId
|
|
86
|
+
});
|
|
87
|
+
subscriber.next({
|
|
88
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
89
|
+
toolCallId: streamPart.toolCallId,
|
|
90
|
+
delta: JSON.stringify(streamPart.args),
|
|
91
|
+
parentMessageId
|
|
92
|
+
});
|
|
93
|
+
subscriber.next({
|
|
94
|
+
type: EventType.TOOL_CALL_END,
|
|
95
|
+
toolCallId: streamPart.toolCallId,
|
|
96
|
+
parentMessageId
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
console.log("error", error);
|
|
102
|
+
subscriber.error(error);
|
|
103
|
+
});
|
|
104
|
+
return () => {
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function generateUUID() {
|
|
110
|
+
if (typeof crypto !== "undefined") {
|
|
111
|
+
if (typeof crypto.randomUUID === "function") {
|
|
112
|
+
return crypto.randomUUID();
|
|
113
|
+
}
|
|
114
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
115
|
+
const buffer = new Uint8Array(16);
|
|
116
|
+
crypto.getRandomValues(buffer);
|
|
117
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
118
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
119
|
+
let hex = "";
|
|
120
|
+
for (let i = 0; i < 16; i++) {
|
|
121
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
122
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
123
|
+
}
|
|
124
|
+
return hex;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
128
|
+
const r = Math.random() * 16 | 0;
|
|
129
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
130
|
+
return v.toString(16);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function convertMessagesToMastraMessages(messages) {
|
|
134
|
+
const result = [];
|
|
135
|
+
for (const message of messages) {
|
|
136
|
+
if (message.role === "assistant") {
|
|
137
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
138
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
139
|
+
parts.push({
|
|
140
|
+
type: "tool-call",
|
|
141
|
+
toolCallId: toolCall.id,
|
|
142
|
+
toolName: toolCall.function.name,
|
|
143
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
result.push({
|
|
147
|
+
role: "assistant",
|
|
148
|
+
content: parts
|
|
149
|
+
});
|
|
150
|
+
} else if (message.role === "user") {
|
|
151
|
+
result.push({
|
|
152
|
+
role: "user",
|
|
153
|
+
content: message.content || ""
|
|
154
|
+
});
|
|
155
|
+
} else if (message.role === "tool") {
|
|
156
|
+
result.push({
|
|
157
|
+
role: "tool",
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
type: "tool-result",
|
|
161
|
+
toolCallId: message.toolCallId,
|
|
162
|
+
toolName: "unknown",
|
|
163
|
+
result: message.content
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
6
171
|
|
|
7
172
|
// src/resources/base.ts
|
|
8
173
|
var BaseResource = class {
|
|
@@ -371,6 +536,34 @@ var Workflow = class extends BaseResource {
|
|
|
371
536
|
details() {
|
|
372
537
|
return this.request(`/api/workflows/${this.workflowId}`);
|
|
373
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Retrieves all runs for a workflow
|
|
541
|
+
* @param params - Parameters for filtering runs
|
|
542
|
+
* @returns Promise containing workflow runs array
|
|
543
|
+
*/
|
|
544
|
+
runs(params) {
|
|
545
|
+
const searchParams = new URLSearchParams();
|
|
546
|
+
if (params?.fromDate) {
|
|
547
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
548
|
+
}
|
|
549
|
+
if (params?.toDate) {
|
|
550
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
551
|
+
}
|
|
552
|
+
if (params?.limit) {
|
|
553
|
+
searchParams.set("limit", String(params.limit));
|
|
554
|
+
}
|
|
555
|
+
if (params?.offset) {
|
|
556
|
+
searchParams.set("offset", String(params.offset));
|
|
557
|
+
}
|
|
558
|
+
if (params?.resourceId) {
|
|
559
|
+
searchParams.set("resourceId", params.resourceId);
|
|
560
|
+
}
|
|
561
|
+
if (searchParams.size) {
|
|
562
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
563
|
+
} else {
|
|
564
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
374
567
|
/**
|
|
375
568
|
* @deprecated Use `startAsync` instead
|
|
376
569
|
* Executes the workflow with the provided parameters
|
|
@@ -487,7 +680,7 @@ var Workflow = class extends BaseResource {
|
|
|
487
680
|
}
|
|
488
681
|
}
|
|
489
682
|
}
|
|
490
|
-
} catch
|
|
683
|
+
} catch {
|
|
491
684
|
}
|
|
492
685
|
}
|
|
493
686
|
if (buffer) {
|
|
@@ -541,13 +734,201 @@ var Tool = class extends BaseResource {
|
|
|
541
734
|
* @returns Promise containing the tool execution results
|
|
542
735
|
*/
|
|
543
736
|
execute(params) {
|
|
544
|
-
|
|
737
|
+
const url = new URLSearchParams();
|
|
738
|
+
if (params.runId) {
|
|
739
|
+
url.set("runId", params.runId);
|
|
740
|
+
}
|
|
741
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
545
742
|
method: "POST",
|
|
546
|
-
body: params
|
|
743
|
+
body: params.data
|
|
547
744
|
});
|
|
548
745
|
}
|
|
549
746
|
};
|
|
550
747
|
|
|
748
|
+
// src/resources/vnext-workflow.ts
|
|
749
|
+
var RECORD_SEPARATOR2 = "";
|
|
750
|
+
var VNextWorkflow = class extends BaseResource {
|
|
751
|
+
constructor(options, workflowId) {
|
|
752
|
+
super(options);
|
|
753
|
+
this.workflowId = workflowId;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Creates an async generator that processes a readable stream and yields vNext workflow records
|
|
757
|
+
* separated by the Record Separator character (\x1E)
|
|
758
|
+
*
|
|
759
|
+
* @param stream - The readable stream to process
|
|
760
|
+
* @returns An async generator that yields parsed records
|
|
761
|
+
*/
|
|
762
|
+
async *streamProcessor(stream) {
|
|
763
|
+
const reader = stream.getReader();
|
|
764
|
+
let doneReading = false;
|
|
765
|
+
let buffer = "";
|
|
766
|
+
try {
|
|
767
|
+
while (!doneReading) {
|
|
768
|
+
const { done, value } = await reader.read();
|
|
769
|
+
doneReading = done;
|
|
770
|
+
if (done && !value) continue;
|
|
771
|
+
try {
|
|
772
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
773
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
774
|
+
buffer = chunks.pop() || "";
|
|
775
|
+
for (const chunk of chunks) {
|
|
776
|
+
if (chunk) {
|
|
777
|
+
if (typeof chunk === "string") {
|
|
778
|
+
try {
|
|
779
|
+
const parsedChunk = JSON.parse(chunk);
|
|
780
|
+
yield parsedChunk;
|
|
781
|
+
} catch {
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
} catch {
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (buffer) {
|
|
790
|
+
try {
|
|
791
|
+
yield JSON.parse(buffer);
|
|
792
|
+
} catch {
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
} finally {
|
|
796
|
+
reader.cancel().catch(() => {
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Retrieves details about the vNext workflow
|
|
802
|
+
* @returns Promise containing vNext workflow details including steps and graphs
|
|
803
|
+
*/
|
|
804
|
+
details() {
|
|
805
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}`);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Retrieves all runs for a vNext workflow
|
|
809
|
+
* @param params - Parameters for filtering runs
|
|
810
|
+
* @returns Promise containing vNext workflow runs array
|
|
811
|
+
*/
|
|
812
|
+
runs(params) {
|
|
813
|
+
const searchParams = new URLSearchParams();
|
|
814
|
+
if (params?.fromDate) {
|
|
815
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
816
|
+
}
|
|
817
|
+
if (params?.toDate) {
|
|
818
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
819
|
+
}
|
|
820
|
+
if (params?.limit) {
|
|
821
|
+
searchParams.set("limit", String(params.limit));
|
|
822
|
+
}
|
|
823
|
+
if (params?.offset) {
|
|
824
|
+
searchParams.set("offset", String(params.offset));
|
|
825
|
+
}
|
|
826
|
+
if (params?.resourceId) {
|
|
827
|
+
searchParams.set("resourceId", params.resourceId);
|
|
828
|
+
}
|
|
829
|
+
if (searchParams.size) {
|
|
830
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
831
|
+
} else {
|
|
832
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Creates a new vNext workflow run
|
|
837
|
+
* @param params - Optional object containing the optional runId
|
|
838
|
+
* @returns Promise containing the runId of the created run
|
|
839
|
+
*/
|
|
840
|
+
createRun(params) {
|
|
841
|
+
const searchParams = new URLSearchParams();
|
|
842
|
+
if (!!params?.runId) {
|
|
843
|
+
searchParams.set("runId", params.runId);
|
|
844
|
+
}
|
|
845
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
846
|
+
method: "POST"
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Starts a vNext workflow run synchronously without waiting for the workflow to complete
|
|
851
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
852
|
+
* @returns Promise containing success message
|
|
853
|
+
*/
|
|
854
|
+
start(params) {
|
|
855
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
856
|
+
method: "POST",
|
|
857
|
+
body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
|
|
862
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
863
|
+
* @returns Promise containing success message
|
|
864
|
+
*/
|
|
865
|
+
resume({
|
|
866
|
+
step,
|
|
867
|
+
runId,
|
|
868
|
+
resumeData,
|
|
869
|
+
runtimeContext
|
|
870
|
+
}) {
|
|
871
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
872
|
+
method: "POST",
|
|
873
|
+
stream: true,
|
|
874
|
+
body: {
|
|
875
|
+
step,
|
|
876
|
+
resumeData,
|
|
877
|
+
runtimeContext
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
883
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
884
|
+
* @returns Promise containing the vNext workflow execution results
|
|
885
|
+
*/
|
|
886
|
+
startAsync(params) {
|
|
887
|
+
const searchParams = new URLSearchParams();
|
|
888
|
+
if (!!params?.runId) {
|
|
889
|
+
searchParams.set("runId", params.runId);
|
|
890
|
+
}
|
|
891
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
892
|
+
method: "POST",
|
|
893
|
+
body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
898
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
899
|
+
* @returns Promise containing the vNext workflow resume results
|
|
900
|
+
*/
|
|
901
|
+
resumeAsync(params) {
|
|
902
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
903
|
+
method: "POST",
|
|
904
|
+
body: {
|
|
905
|
+
step: params.step,
|
|
906
|
+
resumeData: params.resumeData,
|
|
907
|
+
runtimeContext: params.runtimeContext
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Watches vNext workflow transitions in real-time
|
|
913
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
914
|
+
* @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
|
|
915
|
+
*/
|
|
916
|
+
async watch({ runId }, onRecord) {
|
|
917
|
+
const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
|
|
918
|
+
stream: true
|
|
919
|
+
});
|
|
920
|
+
if (!response.ok) {
|
|
921
|
+
throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
|
|
922
|
+
}
|
|
923
|
+
if (!response.body) {
|
|
924
|
+
throw new Error("Response body is null");
|
|
925
|
+
}
|
|
926
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
927
|
+
onRecord(record);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
551
932
|
// src/client.ts
|
|
552
933
|
var MastraClient = class extends BaseResource {
|
|
553
934
|
constructor(options) {
|
|
@@ -560,6 +941,21 @@ var MastraClient = class extends BaseResource {
|
|
|
560
941
|
getAgents() {
|
|
561
942
|
return this.request("/api/agents");
|
|
562
943
|
}
|
|
944
|
+
async getAGUI({ resourceId }) {
|
|
945
|
+
const agents = await this.getAgents();
|
|
946
|
+
return Object.entries(agents).reduce(
|
|
947
|
+
(acc, [agentId]) => {
|
|
948
|
+
const agent = this.getAgent(agentId);
|
|
949
|
+
acc[agentId] = new AGUIAdapter({
|
|
950
|
+
agentId,
|
|
951
|
+
agent,
|
|
952
|
+
resourceId
|
|
953
|
+
});
|
|
954
|
+
return acc;
|
|
955
|
+
},
|
|
956
|
+
{}
|
|
957
|
+
);
|
|
958
|
+
}
|
|
563
959
|
/**
|
|
564
960
|
* Gets an agent instance by ID
|
|
565
961
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -640,6 +1036,21 @@ var MastraClient = class extends BaseResource {
|
|
|
640
1036
|
getWorkflow(workflowId) {
|
|
641
1037
|
return new Workflow(this.options, workflowId);
|
|
642
1038
|
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Retrieves all available vNext workflows
|
|
1041
|
+
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1042
|
+
*/
|
|
1043
|
+
getVNextWorkflows() {
|
|
1044
|
+
return this.request("/api/workflows/v-next");
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Gets a vNext workflow instance by ID
|
|
1048
|
+
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1049
|
+
* @returns vNext Workflow instance
|
|
1050
|
+
*/
|
|
1051
|
+
getVNextWorkflow(workflowId) {
|
|
1052
|
+
return new VNextWorkflow(this.options, workflowId);
|
|
1053
|
+
}
|
|
643
1054
|
/**
|
|
644
1055
|
* Gets a vector instance by name
|
|
645
1056
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -677,7 +1088,7 @@ var MastraClient = class extends BaseResource {
|
|
|
677
1088
|
* @returns Promise containing telemetry data
|
|
678
1089
|
*/
|
|
679
1090
|
getTelemetry(params) {
|
|
680
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1091
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
681
1092
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
682
1093
|
const searchParams = new URLSearchParams();
|
|
683
1094
|
if (name) {
|
|
@@ -701,6 +1112,12 @@ var MastraClient = class extends BaseResource {
|
|
|
701
1112
|
searchParams.set("attribute", _attribute);
|
|
702
1113
|
}
|
|
703
1114
|
}
|
|
1115
|
+
if (fromDate) {
|
|
1116
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1117
|
+
}
|
|
1118
|
+
if (toDate) {
|
|
1119
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1120
|
+
}
|
|
704
1121
|
if (searchParams.size) {
|
|
705
1122
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
706
1123
|
} else {
|
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-vnext-inngest-20250506123700",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -22,11 +22,13 @@
|
|
|
22
22
|
"repository": "github:mastra-ai/client-js",
|
|
23
23
|
"license": "Elastic-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@ag-ui/client": "^0.0.27",
|
|
25
26
|
"@ai-sdk/ui-utils": "^1.1.19",
|
|
26
27
|
"json-schema": "^0.4.0",
|
|
28
|
+
"rxjs": "7.8.1",
|
|
27
29
|
"zod": "^3.24.2",
|
|
28
30
|
"zod-to-json-schema": "^3.24.3",
|
|
29
|
-
"@mastra/core": "0.0.0-
|
|
31
|
+
"@mastra/core": "0.0.0-vnext-inngest-20250506123700"
|
|
30
32
|
},
|
|
31
33
|
"peerDependencies": {
|
|
32
34
|
"zod": "^3.24.2"
|
|
@@ -39,8 +41,8 @@
|
|
|
39
41
|
"@types/node": "^20.17.27",
|
|
40
42
|
"tsup": "^8.4.0",
|
|
41
43
|
"typescript": "^5.8.2",
|
|
42
|
-
"vitest": "^3.
|
|
43
|
-
"@internal/lint": "0.0.
|
|
44
|
+
"vitest": "^3.1.2",
|
|
45
|
+
"@internal/lint": "0.0.0-vnext-inngest-20250506123700"
|
|
44
46
|
},
|
|
45
47
|
"scripts": {
|
|
46
48
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Message } from '@ag-ui/client';
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { generateUUID, convertMessagesToMastraMessages } from './agui';
|
|
4
|
+
|
|
5
|
+
describe('generateUUID', () => {
|
|
6
|
+
it('should generate a valid UUID v4 string', () => {
|
|
7
|
+
const uuid = generateUUID();
|
|
8
|
+
// Check UUID format (8-4-4-4-12 hex digits)
|
|
9
|
+
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should generate unique UUIDs', () => {
|
|
13
|
+
const uuids = new Set();
|
|
14
|
+
for (let i = 0; i < 100; i++) {
|
|
15
|
+
uuids.add(generateUUID());
|
|
16
|
+
}
|
|
17
|
+
// All UUIDs should be unique
|
|
18
|
+
expect(uuids.size).toBe(100);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('convertMessagesToMastraMessages', () => {
|
|
23
|
+
it('should convert user messages correctly', () => {
|
|
24
|
+
const messages: Message[] = [
|
|
25
|
+
{
|
|
26
|
+
id: '1',
|
|
27
|
+
role: 'user',
|
|
28
|
+
content: 'Hello, world!',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual([
|
|
35
|
+
{
|
|
36
|
+
role: 'user',
|
|
37
|
+
content: 'Hello, world!',
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should convert assistant messages correctly', () => {
|
|
43
|
+
const messages: Message[] = [
|
|
44
|
+
{
|
|
45
|
+
id: '1',
|
|
46
|
+
role: 'assistant',
|
|
47
|
+
content: 'Hello, I am an assistant',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
52
|
+
|
|
53
|
+
expect(result).toEqual([
|
|
54
|
+
{
|
|
55
|
+
role: 'assistant',
|
|
56
|
+
content: [{ type: 'text', text: 'Hello, I am an assistant' }],
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should convert assistant messages with tool calls correctly', () => {
|
|
62
|
+
const messages: Message[] = [
|
|
63
|
+
{
|
|
64
|
+
id: '1',
|
|
65
|
+
role: 'assistant',
|
|
66
|
+
content: undefined,
|
|
67
|
+
toolCalls: [
|
|
68
|
+
{
|
|
69
|
+
id: 'tool-call-1',
|
|
70
|
+
type: 'function',
|
|
71
|
+
function: {
|
|
72
|
+
name: 'getWeather',
|
|
73
|
+
arguments: '{"location":"San Francisco"}',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
81
|
+
|
|
82
|
+
expect(result).toEqual([
|
|
83
|
+
{
|
|
84
|
+
role: 'assistant',
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: 'tool-call',
|
|
88
|
+
toolCallId: 'tool-call-1',
|
|
89
|
+
toolName: 'getWeather',
|
|
90
|
+
args: { location: 'San Francisco' },
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should convert tool messages correctly', () => {
|
|
98
|
+
const messages: Message[] = [
|
|
99
|
+
{
|
|
100
|
+
id: '1',
|
|
101
|
+
role: 'tool',
|
|
102
|
+
toolCallId: 'tool-call-1',
|
|
103
|
+
content: '{"temperature":72,"unit":"F"}',
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
108
|
+
|
|
109
|
+
expect(result).toEqual([
|
|
110
|
+
{
|
|
111
|
+
role: 'tool',
|
|
112
|
+
content: [
|
|
113
|
+
{
|
|
114
|
+
type: 'tool-result',
|
|
115
|
+
toolCallId: 'tool-call-1',
|
|
116
|
+
toolName: 'unknown',
|
|
117
|
+
result: '{"temperature":72,"unit":"F"}',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should convert a complex conversation correctly', () => {
|
|
125
|
+
const messages: Message[] = [
|
|
126
|
+
{
|
|
127
|
+
id: '1',
|
|
128
|
+
role: 'user',
|
|
129
|
+
content: "What's the weather in San Francisco?",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: '2',
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
content: undefined,
|
|
135
|
+
toolCalls: [
|
|
136
|
+
{
|
|
137
|
+
id: 'tool-call-1',
|
|
138
|
+
type: 'function',
|
|
139
|
+
function: {
|
|
140
|
+
name: 'getWeather',
|
|
141
|
+
arguments: '{"location":"San Francisco"}',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: '3',
|
|
148
|
+
role: 'tool',
|
|
149
|
+
toolCallId: 'tool-call-1',
|
|
150
|
+
content: '{"temperature":72,"unit":"F"}',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: '4',
|
|
154
|
+
role: 'assistant',
|
|
155
|
+
content: 'The weather in San Francisco is 72°F.',
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
160
|
+
|
|
161
|
+
expect(result).toHaveLength(4);
|
|
162
|
+
expect(result[0].role).toBe('user');
|
|
163
|
+
expect(result[1].role).toBe('assistant');
|
|
164
|
+
expect(result[2].role).toBe('tool');
|
|
165
|
+
expect(result[3].role).toBe('assistant');
|
|
166
|
+
});
|
|
167
|
+
});
|