@mastra/client-js 0.1.22 → 0.2.0-alpha.1
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 +8 -8
- package/CHANGELOG.md +43 -0
- package/dist/index.cjs +171 -89
- package/dist/index.d.cts +153 -75
- package/dist/index.d.ts +153 -75
- package/dist/index.js +171 -89
- package/package.json +6 -5
- package/src/client.ts +85 -19
- package/src/example.ts +29 -30
- package/src/index.test.ts +91 -1
- package/src/resources/agent.ts +8 -7
- package/src/resources/base.ts +1 -1
- package/src/resources/index.ts +3 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -143
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/tool.ts +4 -3
- package/src/resources/workflow.ts +121 -109
- package/src/types.ts +55 -14
- package/src/utils/index.ts +11 -0
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
6
7
|
|
|
7
8
|
// src/adapters/agui.ts
|
|
8
9
|
var AGUIAdapter = class extends AbstractAgent {
|
|
@@ -214,7 +215,7 @@ var BaseResource = class {
|
|
|
214
215
|
let delay = backoffMs;
|
|
215
216
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
216
217
|
try {
|
|
217
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
218
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
218
219
|
...options,
|
|
219
220
|
headers: {
|
|
220
221
|
...headers,
|
|
@@ -254,6 +255,15 @@ var BaseResource = class {
|
|
|
254
255
|
throw lastError || new Error("Request failed");
|
|
255
256
|
}
|
|
256
257
|
};
|
|
258
|
+
function parseClientRuntimeContext(runtimeContext) {
|
|
259
|
+
if (runtimeContext) {
|
|
260
|
+
if (runtimeContext instanceof RuntimeContext) {
|
|
261
|
+
return Object.fromEntries(runtimeContext.entries());
|
|
262
|
+
}
|
|
263
|
+
return runtimeContext;
|
|
264
|
+
}
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
257
267
|
|
|
258
268
|
// src/resources/agent.ts
|
|
259
269
|
var AgentVoice = class extends BaseResource {
|
|
@@ -325,9 +335,9 @@ var Agent = class extends BaseResource {
|
|
|
325
335
|
generate(params) {
|
|
326
336
|
const processedParams = {
|
|
327
337
|
...params,
|
|
328
|
-
output: zodToJsonSchema(params.output),
|
|
329
|
-
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
330
|
-
runtimeContext:
|
|
338
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
339
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
340
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
331
341
|
};
|
|
332
342
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
333
343
|
method: "POST",
|
|
@@ -342,9 +352,9 @@ var Agent = class extends BaseResource {
|
|
|
342
352
|
async stream(params) {
|
|
343
353
|
const processedParams = {
|
|
344
354
|
...params,
|
|
345
|
-
output: zodToJsonSchema(params.output),
|
|
346
|
-
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
347
|
-
runtimeContext:
|
|
355
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
356
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
357
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
348
358
|
};
|
|
349
359
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
350
360
|
method: "POST",
|
|
@@ -572,24 +582,24 @@ var Vector = class extends BaseResource {
|
|
|
572
582
|
}
|
|
573
583
|
};
|
|
574
584
|
|
|
575
|
-
// src/resources/workflow.ts
|
|
585
|
+
// src/resources/legacy-workflow.ts
|
|
576
586
|
var RECORD_SEPARATOR = "";
|
|
577
|
-
var
|
|
587
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
578
588
|
constructor(options, workflowId) {
|
|
579
589
|
super(options);
|
|
580
590
|
this.workflowId = workflowId;
|
|
581
591
|
}
|
|
582
592
|
/**
|
|
583
|
-
* Retrieves details about the workflow
|
|
584
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
593
|
+
* Retrieves details about the legacy workflow
|
|
594
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
585
595
|
*/
|
|
586
596
|
details() {
|
|
587
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
597
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
588
598
|
}
|
|
589
599
|
/**
|
|
590
|
-
* Retrieves all runs for a workflow
|
|
600
|
+
* Retrieves all runs for a legacy workflow
|
|
591
601
|
* @param params - Parameters for filtering runs
|
|
592
|
-
* @returns Promise containing workflow runs array
|
|
602
|
+
* @returns Promise containing legacy workflow runs array
|
|
593
603
|
*/
|
|
594
604
|
runs(params) {
|
|
595
605
|
const searchParams = new URLSearchParams();
|
|
@@ -609,25 +619,13 @@ var Workflow = class extends BaseResource {
|
|
|
609
619
|
searchParams.set("resourceId", params.resourceId);
|
|
610
620
|
}
|
|
611
621
|
if (searchParams.size) {
|
|
612
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
622
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
613
623
|
} else {
|
|
614
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
624
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
615
625
|
}
|
|
616
626
|
}
|
|
617
627
|
/**
|
|
618
|
-
*
|
|
619
|
-
* Executes the workflow with the provided parameters
|
|
620
|
-
* @param params - Parameters required for workflow execution
|
|
621
|
-
* @returns Promise containing the workflow execution results
|
|
622
|
-
*/
|
|
623
|
-
execute(params) {
|
|
624
|
-
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
625
|
-
method: "POST",
|
|
626
|
-
body: params
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Creates a new workflow run
|
|
628
|
+
* Creates a new legacy workflow run
|
|
631
629
|
* @returns Promise containing the generated run ID
|
|
632
630
|
*/
|
|
633
631
|
createRun(params) {
|
|
@@ -635,34 +633,34 @@ var Workflow = class extends BaseResource {
|
|
|
635
633
|
if (!!params?.runId) {
|
|
636
634
|
searchParams.set("runId", params.runId);
|
|
637
635
|
}
|
|
638
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
636
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
639
637
|
method: "POST"
|
|
640
638
|
});
|
|
641
639
|
}
|
|
642
640
|
/**
|
|
643
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
641
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
644
642
|
* @param params - Object containing the runId and triggerData
|
|
645
643
|
* @returns Promise containing success message
|
|
646
644
|
*/
|
|
647
645
|
start(params) {
|
|
648
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
646
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
649
647
|
method: "POST",
|
|
650
648
|
body: params?.triggerData
|
|
651
649
|
});
|
|
652
650
|
}
|
|
653
651
|
/**
|
|
654
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
652
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
655
653
|
* @param stepId - ID of the step to resume
|
|
656
|
-
* @param runId - ID of the workflow run
|
|
657
|
-
* @param context - Context to resume the workflow with
|
|
658
|
-
* @returns Promise containing the workflow resume results
|
|
654
|
+
* @param runId - ID of the legacy workflow run
|
|
655
|
+
* @param context - Context to resume the legacy workflow with
|
|
656
|
+
* @returns Promise containing the legacy workflow resume results
|
|
659
657
|
*/
|
|
660
658
|
resume({
|
|
661
659
|
stepId,
|
|
662
660
|
runId,
|
|
663
661
|
context
|
|
664
662
|
}) {
|
|
665
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
663
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
666
664
|
method: "POST",
|
|
667
665
|
body: {
|
|
668
666
|
stepId,
|
|
@@ -680,18 +678,18 @@ var Workflow = class extends BaseResource {
|
|
|
680
678
|
if (!!params?.runId) {
|
|
681
679
|
searchParams.set("runId", params.runId);
|
|
682
680
|
}
|
|
683
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
681
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
684
682
|
method: "POST",
|
|
685
683
|
body: params?.triggerData
|
|
686
684
|
});
|
|
687
685
|
}
|
|
688
686
|
/**
|
|
689
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
687
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
690
688
|
* @param params - Object containing the runId, stepId, and context
|
|
691
689
|
* @returns Promise containing the workflow resume results
|
|
692
690
|
*/
|
|
693
691
|
resumeAsync(params) {
|
|
694
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
692
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
695
693
|
method: "POST",
|
|
696
694
|
body: {
|
|
697
695
|
stepId: params.stepId,
|
|
@@ -745,16 +743,16 @@ var Workflow = class extends BaseResource {
|
|
|
745
743
|
}
|
|
746
744
|
}
|
|
747
745
|
/**
|
|
748
|
-
* Watches workflow transitions in real-time
|
|
746
|
+
* Watches legacy workflow transitions in real-time
|
|
749
747
|
* @param runId - Optional run ID to filter the watch stream
|
|
750
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
748
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
751
749
|
*/
|
|
752
750
|
async watch({ runId }, onRecord) {
|
|
753
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
751
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
754
752
|
stream: true
|
|
755
753
|
});
|
|
756
754
|
if (!response.ok) {
|
|
757
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
755
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
758
756
|
}
|
|
759
757
|
if (!response.body) {
|
|
760
758
|
throw new Error("Response body is null");
|
|
@@ -790,7 +788,7 @@ var Tool = class extends BaseResource {
|
|
|
790
788
|
}
|
|
791
789
|
const body = {
|
|
792
790
|
data: params.data,
|
|
793
|
-
runtimeContext:
|
|
791
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
794
792
|
};
|
|
795
793
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
796
794
|
method: "POST",
|
|
@@ -798,14 +796,16 @@ var Tool = class extends BaseResource {
|
|
|
798
796
|
});
|
|
799
797
|
}
|
|
800
798
|
};
|
|
799
|
+
|
|
800
|
+
// src/resources/workflow.ts
|
|
801
801
|
var RECORD_SEPARATOR2 = "";
|
|
802
|
-
var
|
|
802
|
+
var Workflow = class extends BaseResource {
|
|
803
803
|
constructor(options, workflowId) {
|
|
804
804
|
super(options);
|
|
805
805
|
this.workflowId = workflowId;
|
|
806
806
|
}
|
|
807
807
|
/**
|
|
808
|
-
* Creates an async generator that processes a readable stream and yields
|
|
808
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
809
809
|
* separated by the Record Separator character (\x1E)
|
|
810
810
|
*
|
|
811
811
|
* @param stream - The readable stream to process
|
|
@@ -850,16 +850,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
/**
|
|
853
|
-
* Retrieves details about the
|
|
854
|
-
* @returns Promise containing
|
|
853
|
+
* Retrieves details about the workflow
|
|
854
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
855
855
|
*/
|
|
856
856
|
details() {
|
|
857
|
-
return this.request(`/api/workflows
|
|
857
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
858
858
|
}
|
|
859
859
|
/**
|
|
860
|
-
* Retrieves all runs for a
|
|
860
|
+
* Retrieves all runs for a workflow
|
|
861
861
|
* @param params - Parameters for filtering runs
|
|
862
|
-
* @returns Promise containing
|
|
862
|
+
* @returns Promise containing workflow runs array
|
|
863
863
|
*/
|
|
864
864
|
runs(params) {
|
|
865
865
|
const searchParams = new URLSearchParams();
|
|
@@ -879,13 +879,13 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
879
879
|
searchParams.set("resourceId", params.resourceId);
|
|
880
880
|
}
|
|
881
881
|
if (searchParams.size) {
|
|
882
|
-
return this.request(`/api/workflows
|
|
882
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
883
883
|
} else {
|
|
884
|
-
return this.request(`/api/workflows
|
|
884
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
/**
|
|
888
|
-
* Creates a new
|
|
888
|
+
* Creates a new workflow run
|
|
889
889
|
* @param params - Optional object containing the optional runId
|
|
890
890
|
* @returns Promise containing the runId of the created run
|
|
891
891
|
*/
|
|
@@ -894,24 +894,24 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
894
894
|
if (!!params?.runId) {
|
|
895
895
|
searchParams.set("runId", params.runId);
|
|
896
896
|
}
|
|
897
|
-
return this.request(`/api/workflows
|
|
897
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
898
898
|
method: "POST"
|
|
899
899
|
});
|
|
900
900
|
}
|
|
901
901
|
/**
|
|
902
|
-
* Starts a
|
|
902
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
903
903
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
904
904
|
* @returns Promise containing success message
|
|
905
905
|
*/
|
|
906
906
|
start(params) {
|
|
907
|
-
const runtimeContext =
|
|
908
|
-
return this.request(`/api/workflows
|
|
907
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
908
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
909
909
|
method: "POST",
|
|
910
910
|
body: { inputData: params?.inputData, runtimeContext }
|
|
911
911
|
});
|
|
912
912
|
}
|
|
913
913
|
/**
|
|
914
|
-
* Resumes a suspended
|
|
914
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
915
915
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
916
916
|
* @returns Promise containing success message
|
|
917
917
|
*/
|
|
@@ -921,8 +921,8 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
921
921
|
resumeData,
|
|
922
922
|
...rest
|
|
923
923
|
}) {
|
|
924
|
-
const runtimeContext =
|
|
925
|
-
return this.request(`/api/workflows
|
|
924
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
925
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
926
926
|
method: "POST",
|
|
927
927
|
stream: true,
|
|
928
928
|
body: {
|
|
@@ -933,29 +933,29 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
933
933
|
});
|
|
934
934
|
}
|
|
935
935
|
/**
|
|
936
|
-
* Starts a
|
|
936
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
937
937
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
938
|
-
* @returns Promise containing the
|
|
938
|
+
* @returns Promise containing the workflow execution results
|
|
939
939
|
*/
|
|
940
940
|
startAsync(params) {
|
|
941
941
|
const searchParams = new URLSearchParams();
|
|
942
942
|
if (!!params?.runId) {
|
|
943
943
|
searchParams.set("runId", params.runId);
|
|
944
944
|
}
|
|
945
|
-
const runtimeContext =
|
|
946
|
-
return this.request(`/api/workflows
|
|
945
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
946
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
947
947
|
method: "POST",
|
|
948
948
|
body: { inputData: params.inputData, runtimeContext }
|
|
949
949
|
});
|
|
950
950
|
}
|
|
951
951
|
/**
|
|
952
|
-
* Resumes a suspended
|
|
952
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
953
953
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
954
|
-
* @returns Promise containing the
|
|
954
|
+
* @returns Promise containing the workflow resume results
|
|
955
955
|
*/
|
|
956
956
|
resumeAsync(params) {
|
|
957
|
-
const runtimeContext =
|
|
958
|
-
return this.request(`/api/workflows
|
|
957
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
958
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
959
959
|
method: "POST",
|
|
960
960
|
body: {
|
|
961
961
|
step: params.step,
|
|
@@ -965,16 +965,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
965
965
|
});
|
|
966
966
|
}
|
|
967
967
|
/**
|
|
968
|
-
* Watches
|
|
968
|
+
* Watches workflow transitions in real-time
|
|
969
969
|
* @param runId - Optional run ID to filter the watch stream
|
|
970
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
970
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
971
971
|
*/
|
|
972
972
|
async watch({ runId }, onRecord) {
|
|
973
|
-
const response = await this.request(`/api/workflows
|
|
973
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
974
974
|
stream: true
|
|
975
975
|
});
|
|
976
976
|
if (!response.ok) {
|
|
977
|
-
throw new Error(`Failed to watch
|
|
977
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
978
978
|
}
|
|
979
979
|
if (!response.body) {
|
|
980
980
|
throw new Error("Response body is null");
|
|
@@ -1059,6 +1059,40 @@ var A2A = class extends BaseResource {
|
|
|
1059
1059
|
}
|
|
1060
1060
|
};
|
|
1061
1061
|
|
|
1062
|
+
// src/resources/mcp-tool.ts
|
|
1063
|
+
var MCPTool = class extends BaseResource {
|
|
1064
|
+
serverId;
|
|
1065
|
+
toolId;
|
|
1066
|
+
constructor(options, serverId, toolId) {
|
|
1067
|
+
super(options);
|
|
1068
|
+
this.serverId = serverId;
|
|
1069
|
+
this.toolId = toolId;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1073
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1074
|
+
*/
|
|
1075
|
+
details() {
|
|
1076
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Executes this specific tool on the MCP server.
|
|
1080
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1081
|
+
* @returns Promise containing the result of the tool execution.
|
|
1082
|
+
*/
|
|
1083
|
+
execute(params) {
|
|
1084
|
+
const body = {};
|
|
1085
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1086
|
+
if (params.runtimeContext !== void 0) {
|
|
1087
|
+
body.runtimeContext = params.runtimeContext;
|
|
1088
|
+
}
|
|
1089
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1090
|
+
method: "POST",
|
|
1091
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1062
1096
|
// src/client.ts
|
|
1063
1097
|
var MastraClient = class extends BaseResource {
|
|
1064
1098
|
constructor(options) {
|
|
@@ -1151,6 +1185,21 @@ var MastraClient = class extends BaseResource {
|
|
|
1151
1185
|
getTool(toolId) {
|
|
1152
1186
|
return new Tool(this.options, toolId);
|
|
1153
1187
|
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Retrieves all available legacy workflows
|
|
1190
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1191
|
+
*/
|
|
1192
|
+
getLegacyWorkflows() {
|
|
1193
|
+
return this.request("/api/workflows/legacy");
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Gets a legacy workflow instance by ID
|
|
1197
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1198
|
+
* @returns Legacy Workflow instance
|
|
1199
|
+
*/
|
|
1200
|
+
getLegacyWorkflow(workflowId) {
|
|
1201
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1202
|
+
}
|
|
1154
1203
|
/**
|
|
1155
1204
|
* Retrieves all available workflows
|
|
1156
1205
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -1166,21 +1215,6 @@ var MastraClient = class extends BaseResource {
|
|
|
1166
1215
|
getWorkflow(workflowId) {
|
|
1167
1216
|
return new Workflow(this.options, workflowId);
|
|
1168
1217
|
}
|
|
1169
|
-
/**
|
|
1170
|
-
* Retrieves all available vNext workflows
|
|
1171
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1172
|
-
*/
|
|
1173
|
-
getVNextWorkflows() {
|
|
1174
|
-
return this.request("/api/workflows/v-next");
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Gets a vNext workflow instance by ID
|
|
1178
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1179
|
-
* @returns vNext Workflow instance
|
|
1180
|
-
*/
|
|
1181
|
-
getVNextWorkflow(workflowId) {
|
|
1182
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
1183
|
-
}
|
|
1184
1218
|
/**
|
|
1185
1219
|
* Gets a vector instance by name
|
|
1186
1220
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -1269,6 +1303,54 @@ var MastraClient = class extends BaseResource {
|
|
|
1269
1303
|
getNetwork(networkId) {
|
|
1270
1304
|
return new Network(this.options, networkId);
|
|
1271
1305
|
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Retrieves a list of available MCP servers.
|
|
1308
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1309
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
1310
|
+
*/
|
|
1311
|
+
getMcpServers(params) {
|
|
1312
|
+
const searchParams = new URLSearchParams();
|
|
1313
|
+
if (params?.limit !== void 0) {
|
|
1314
|
+
searchParams.set("limit", String(params.limit));
|
|
1315
|
+
}
|
|
1316
|
+
if (params?.offset !== void 0) {
|
|
1317
|
+
searchParams.set("offset", String(params.offset));
|
|
1318
|
+
}
|
|
1319
|
+
const queryString = searchParams.toString();
|
|
1320
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1324
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1325
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1326
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1327
|
+
*/
|
|
1328
|
+
getMcpServerDetails(serverId, params) {
|
|
1329
|
+
const searchParams = new URLSearchParams();
|
|
1330
|
+
if (params?.version) {
|
|
1331
|
+
searchParams.set("version", params.version);
|
|
1332
|
+
}
|
|
1333
|
+
const queryString = searchParams.toString();
|
|
1334
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1338
|
+
* @param serverId - The ID of the MCP server.
|
|
1339
|
+
* @returns Promise containing the list of tools.
|
|
1340
|
+
*/
|
|
1341
|
+
getMcpServerTools(serverId) {
|
|
1342
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1346
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1347
|
+
* @param serverId - The ID of the MCP server.
|
|
1348
|
+
* @param toolId - The ID of the tool.
|
|
1349
|
+
* @returns MCPTool instance.
|
|
1350
|
+
*/
|
|
1351
|
+
getMcpServerTool(serverId, toolId) {
|
|
1352
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1353
|
+
}
|
|
1272
1354
|
/**
|
|
1273
1355
|
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1274
1356
|
* @param agentId - ID of the agent to interact with
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"json-schema": "^0.4.0",
|
|
28
28
|
"rxjs": "7.8.1",
|
|
29
29
|
"zod": "^3.24.3",
|
|
30
|
-
"zod-to-json-schema": "^3.24.5"
|
|
31
|
-
"@mastra/core": "^0.9.4"
|
|
30
|
+
"zod-to-json-schema": "^3.24.5"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
34
|
-
"zod": "^3.0.0"
|
|
33
|
+
"zod": "^3.0.0",
|
|
34
|
+
"@mastra/core": "^0.9.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/preset-env": "^7.26.9",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"tsup": "^8.4.0",
|
|
43
43
|
"typescript": "^5.8.2",
|
|
44
44
|
"vitest": "^3.1.2",
|
|
45
|
-
"@internal/lint": "0.0.5"
|
|
45
|
+
"@internal/lint": "0.0.5",
|
|
46
|
+
"@mastra/core": "0.10.0-alpha.1"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { AbstractAgent } from '@ag-ui/client';
|
|
2
|
+
import type { ServerDetailInfo } from '@mastra/core/mcp';
|
|
2
3
|
import { AGUIAdapter } from './adapters/agui';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Agent,
|
|
6
|
+
MemoryThread,
|
|
7
|
+
Tool,
|
|
8
|
+
Workflow,
|
|
9
|
+
Vector,
|
|
10
|
+
BaseResource,
|
|
11
|
+
Network,
|
|
12
|
+
A2A,
|
|
13
|
+
MCPTool,
|
|
14
|
+
LegacyWorkflow,
|
|
15
|
+
} from './resources';
|
|
4
16
|
import type {
|
|
5
17
|
ClientOptions,
|
|
6
18
|
CreateMemoryThreadParams,
|
|
@@ -15,10 +27,12 @@ import type {
|
|
|
15
27
|
GetTelemetryParams,
|
|
16
28
|
GetTelemetryResponse,
|
|
17
29
|
GetToolResponse,
|
|
18
|
-
GetVNextWorkflowResponse,
|
|
19
30
|
GetWorkflowResponse,
|
|
20
31
|
SaveMessageToMemoryParams,
|
|
21
32
|
SaveMessageToMemoryResponse,
|
|
33
|
+
McpServerListResponse,
|
|
34
|
+
McpServerToolListResponse,
|
|
35
|
+
GetLegacyWorkflowResponse,
|
|
22
36
|
} from './types';
|
|
23
37
|
|
|
24
38
|
export class MastraClient extends BaseResource {
|
|
@@ -126,6 +140,23 @@ export class MastraClient extends BaseResource {
|
|
|
126
140
|
return new Tool(this.options, toolId);
|
|
127
141
|
}
|
|
128
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves all available legacy workflows
|
|
145
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
146
|
+
*/
|
|
147
|
+
public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
|
|
148
|
+
return this.request('/api/workflows/legacy');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Gets a legacy workflow instance by ID
|
|
153
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
154
|
+
* @returns Legacy Workflow instance
|
|
155
|
+
*/
|
|
156
|
+
public getLegacyWorkflow(workflowId: string) {
|
|
157
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
158
|
+
}
|
|
159
|
+
|
|
129
160
|
/**
|
|
130
161
|
* Retrieves all available workflows
|
|
131
162
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -143,23 +174,6 @@ export class MastraClient extends BaseResource {
|
|
|
143
174
|
return new Workflow(this.options, workflowId);
|
|
144
175
|
}
|
|
145
176
|
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves all available vNext workflows
|
|
148
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
149
|
-
*/
|
|
150
|
-
public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
|
|
151
|
-
return this.request('/api/workflows/v-next');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Gets a vNext workflow instance by ID
|
|
156
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
157
|
-
* @returns vNext Workflow instance
|
|
158
|
-
*/
|
|
159
|
-
public getVNextWorkflow(workflowId: string) {
|
|
160
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
177
|
/**
|
|
164
178
|
* Gets a vector instance by name
|
|
165
179
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -257,6 +271,58 @@ export class MastraClient extends BaseResource {
|
|
|
257
271
|
return new Network(this.options, networkId);
|
|
258
272
|
}
|
|
259
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Retrieves a list of available MCP servers.
|
|
276
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
277
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
278
|
+
*/
|
|
279
|
+
public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
|
|
280
|
+
const searchParams = new URLSearchParams();
|
|
281
|
+
if (params?.limit !== undefined) {
|
|
282
|
+
searchParams.set('limit', String(params.limit));
|
|
283
|
+
}
|
|
284
|
+
if (params?.offset !== undefined) {
|
|
285
|
+
searchParams.set('offset', String(params.offset));
|
|
286
|
+
}
|
|
287
|
+
const queryString = searchParams.toString();
|
|
288
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Retrieves detailed information for a specific MCP server.
|
|
293
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
294
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
295
|
+
* @returns Promise containing the detailed MCP server information.
|
|
296
|
+
*/
|
|
297
|
+
public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
|
|
298
|
+
const searchParams = new URLSearchParams();
|
|
299
|
+
if (params?.version) {
|
|
300
|
+
searchParams.set('version', params.version);
|
|
301
|
+
}
|
|
302
|
+
const queryString = searchParams.toString();
|
|
303
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
308
|
+
* @param serverId - The ID of the MCP server.
|
|
309
|
+
* @returns Promise containing the list of tools.
|
|
310
|
+
*/
|
|
311
|
+
public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
|
|
312
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
317
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
318
|
+
* @param serverId - The ID of the MCP server.
|
|
319
|
+
* @param toolId - The ID of the tool.
|
|
320
|
+
* @returns MCPTool instance.
|
|
321
|
+
*/
|
|
322
|
+
public getMcpServerTool(serverId: string, toolId: string): MCPTool {
|
|
323
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
324
|
+
}
|
|
325
|
+
|
|
260
326
|
/**
|
|
261
327
|
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
262
328
|
* @param agentId - ID of the agent to interact with
|