@mastra/client-js 0.1.21 → 0.1.22-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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @mastra/client-js@0.1.21-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.1.22-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
3
  > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Cleaning output folder
10
10
  ESM Build start
11
11
  CJS Build start
12
- CJS dist/index.cjs 35.18 KB
13
- CJS ⚡️ Build success in 1096ms
14
- ESM dist/index.js 34.95 KB
15
- ESM ⚡️ Build success in 1096ms
16
12
  DTS Build start
17
- DTS ⚡️ Build success in 13790ms
18
- DTS dist/index.d.ts 25.12 KB
19
- DTS dist/index.d.cts 25.12 KB
13
+ CJS dist/index.cjs 38.24 KB
14
+ CJS ⚡️ Build success in 1623ms
15
+ ESM dist/index.js 38.02 KB
16
+ ESM ⚡️ Build success in 1628ms
17
+ DTS ⚡️ Build success in 14543ms
18
+ DTS dist/index.d.ts 27.18 KB
19
+ DTS dist/index.d.cts 27.18 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 0.1.22-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [ab80e7e]
8
+ - Updated dependencies [6fa1ad1]
9
+ - Updated dependencies [c28d7a0]
10
+ - Updated dependencies [edf1e88]
11
+ - @mastra/core@0.9.4-alpha.1
12
+
13
+ ## 0.1.22-alpha.0
14
+
15
+ ### Patch Changes
16
+
17
+ - cb1f698: Set runtimeContext from playground for agents, tools, workflows
18
+ - 0b8b868: Added A2A support + streaming
19
+ - Updated dependencies [daf942f]
20
+ - Updated dependencies [0b8b868]
21
+ - @mastra/core@0.9.4-alpha.0
22
+
3
23
  ## 0.1.21
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -355,6 +355,22 @@ var Agent = class extends BaseResource {
355
355
  getTool(toolId) {
356
356
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
357
357
  }
358
+ /**
359
+ * Executes a tool for the agent
360
+ * @param toolId - ID of the tool to execute
361
+ * @param params - Parameters required for tool execution
362
+ * @returns Promise containing the tool execution results
363
+ */
364
+ executeTool(toolId, params) {
365
+ const body = {
366
+ data: params.data,
367
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
368
+ };
369
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
370
+ method: "POST",
371
+ body
372
+ });
373
+ }
358
374
  /**
359
375
  * Retrieves evaluation results for the agent
360
376
  * @returns Promise containing agent evaluations
@@ -752,14 +768,16 @@ var Tool = class extends BaseResource {
752
768
  if (params.runId) {
753
769
  url.set("runId", params.runId);
754
770
  }
771
+ const body = {
772
+ data: params.data,
773
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
774
+ };
755
775
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
756
776
  method: "POST",
757
- body: params.data
777
+ body
758
778
  });
759
779
  }
760
780
  };
761
-
762
- // src/resources/vnext-workflow.ts
763
781
  var RECORD_SEPARATOR2 = "";
764
782
  var VNextWorkflow = class extends BaseResource {
765
783
  constructor(options, workflowId) {
@@ -866,9 +884,10 @@ var VNextWorkflow = class extends BaseResource {
866
884
  * @returns Promise containing success message
867
885
  */
868
886
  start(params) {
887
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
869
888
  return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
870
889
  method: "POST",
871
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
890
+ body: { inputData: params?.inputData, runtimeContext }
872
891
  });
873
892
  }
874
893
  /**
@@ -880,8 +899,9 @@ var VNextWorkflow = class extends BaseResource {
880
899
  step,
881
900
  runId,
882
901
  resumeData,
883
- runtimeContext
902
+ ...rest
884
903
  }) {
904
+ const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
885
905
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
886
906
  method: "POST",
887
907
  stream: true,
@@ -902,9 +922,10 @@ var VNextWorkflow = class extends BaseResource {
902
922
  if (!!params?.runId) {
903
923
  searchParams.set("runId", params.runId);
904
924
  }
925
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
905
926
  return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
906
927
  method: "POST",
907
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
928
+ body: { inputData: params.inputData, runtimeContext }
908
929
  });
909
930
  }
910
931
  /**
@@ -913,12 +934,13 @@ var VNextWorkflow = class extends BaseResource {
913
934
  * @returns Promise containing the vNext workflow resume results
914
935
  */
915
936
  resumeAsync(params) {
937
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
916
938
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
917
939
  method: "POST",
918
940
  body: {
919
941
  step: params.step,
920
942
  resumeData: params.resumeData,
921
- runtimeContext: params.runtimeContext
943
+ runtimeContext
922
944
  }
923
945
  });
924
946
  }
@@ -943,6 +965,80 @@ var VNextWorkflow = class extends BaseResource {
943
965
  }
944
966
  };
945
967
 
968
+ // src/resources/a2a.ts
969
+ var A2A = class extends BaseResource {
970
+ constructor(options, agentId) {
971
+ super(options);
972
+ this.agentId = agentId;
973
+ }
974
+ /**
975
+ * Get the agent card with metadata about the agent
976
+ * @returns Promise containing the agent card information
977
+ */
978
+ async getCard() {
979
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
980
+ }
981
+ /**
982
+ * Send a message to the agent and get a response
983
+ * @param params - Parameters for the task
984
+ * @returns Promise containing the task response
985
+ */
986
+ async sendMessage(params) {
987
+ const response = await this.request(`/a2a/${this.agentId}`, {
988
+ method: "POST",
989
+ body: {
990
+ method: "tasks/send",
991
+ params
992
+ }
993
+ });
994
+ return { task: response.result };
995
+ }
996
+ /**
997
+ * Get the status and result of a task
998
+ * @param params - Parameters for querying the task
999
+ * @returns Promise containing the task response
1000
+ */
1001
+ async getTask(params) {
1002
+ const response = await this.request(`/a2a/${this.agentId}`, {
1003
+ method: "POST",
1004
+ body: {
1005
+ method: "tasks/get",
1006
+ params
1007
+ }
1008
+ });
1009
+ return response.result;
1010
+ }
1011
+ /**
1012
+ * Cancel a running task
1013
+ * @param params - Parameters identifying the task to cancel
1014
+ * @returns Promise containing the task response
1015
+ */
1016
+ async cancelTask(params) {
1017
+ return this.request(`/a2a/${this.agentId}`, {
1018
+ method: "POST",
1019
+ body: {
1020
+ method: "tasks/cancel",
1021
+ params
1022
+ }
1023
+ });
1024
+ }
1025
+ /**
1026
+ * Send a message and subscribe to streaming updates (not fully implemented)
1027
+ * @param params - Parameters for the task
1028
+ * @returns Promise containing the task response
1029
+ */
1030
+ async sendAndSubscribe(params) {
1031
+ return this.request(`/a2a/${this.agentId}`, {
1032
+ method: "POST",
1033
+ body: {
1034
+ method: "tasks/sendSubscribe",
1035
+ params
1036
+ },
1037
+ stream: true
1038
+ });
1039
+ }
1040
+ };
1041
+
946
1042
  // src/client.ts
947
1043
  var MastraClient = class extends BaseResource {
948
1044
  constructor(options) {
@@ -1153,6 +1249,14 @@ var MastraClient = class extends BaseResource {
1153
1249
  getNetwork(networkId) {
1154
1250
  return new Network(this.options, networkId);
1155
1251
  }
1252
+ /**
1253
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1254
+ * @param agentId - ID of the agent to interact with
1255
+ * @returns A2A client instance
1256
+ */
1257
+ getA2A(agentId) {
1258
+ return new A2A(this.options, agentId);
1259
+ }
1156
1260
  };
1157
1261
 
1158
1262
  exports.MastraClient = MastraClient;
package/dist/index.d.cts CHANGED
@@ -5,7 +5,9 @@ import { JSONSchema7 } from 'json-schema';
5
5
  import { ZodSchema } from 'zod';
6
6
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
7
7
  import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
8
- import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { RuntimeContext } from '@mastra/core/di';
9
+ import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
10
+ import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
9
11
 
10
12
  interface ClientOptions {
11
13
  /** Base URL for API requests */
@@ -293,6 +295,16 @@ declare class Agent extends BaseResource {
293
295
  * @returns Promise containing tool details
294
296
  */
295
297
  getTool(toolId: string): Promise<GetToolResponse>;
298
+ /**
299
+ * Executes a tool for the agent
300
+ * @param toolId - ID of the tool to execute
301
+ * @param params - Parameters required for tool execution
302
+ * @returns Promise containing the tool execution results
303
+ */
304
+ executeTool(toolId: string, params: {
305
+ data: any;
306
+ runtimeContext?: RuntimeContext;
307
+ }): Promise<any>;
296
308
  /**
297
309
  * Retrieves evaluation results for the agent
298
310
  * @returns Promise containing agent evaluations
@@ -512,6 +524,7 @@ declare class Tool extends BaseResource {
512
524
  execute(params: {
513
525
  data: any;
514
526
  runId?: string;
527
+ runtimeContext?: RuntimeContext;
515
528
  }): Promise<any>;
516
529
  }
517
530
 
@@ -555,7 +568,7 @@ declare class VNextWorkflow extends BaseResource {
555
568
  start(params: {
556
569
  runId: string;
557
570
  inputData: Record<string, any>;
558
- runtimeContext?: RuntimeContext;
571
+ runtimeContext?: RuntimeContext$1;
559
572
  }): Promise<{
560
573
  message: string;
561
574
  }>;
@@ -564,11 +577,11 @@ declare class VNextWorkflow extends BaseResource {
564
577
  * @param params - Object containing the runId, step, resumeData and runtimeContext
565
578
  * @returns Promise containing success message
566
579
  */
567
- resume({ step, runId, resumeData, runtimeContext, }: {
580
+ resume({ step, runId, resumeData, ...rest }: {
568
581
  step: string | string[];
569
582
  runId: string;
570
583
  resumeData?: Record<string, any>;
571
- runtimeContext?: RuntimeContext;
584
+ runtimeContext?: RuntimeContext$1;
572
585
  }): Promise<{
573
586
  message: string;
574
587
  }>;
@@ -580,7 +593,7 @@ declare class VNextWorkflow extends BaseResource {
580
593
  startAsync(params: {
581
594
  runId?: string;
582
595
  inputData: Record<string, any>;
583
- runtimeContext?: RuntimeContext;
596
+ runtimeContext?: RuntimeContext$1;
584
597
  }): Promise<VNextWorkflowRunResult>;
585
598
  /**
586
599
  * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
@@ -591,7 +604,7 @@ declare class VNextWorkflow extends BaseResource {
591
604
  runId: string;
592
605
  step: string | string[];
593
606
  resumeData?: Record<string, any>;
594
- runtimeContext?: RuntimeContext;
607
+ runtimeContext?: RuntimeContext$1;
595
608
  }): Promise<VNextWorkflowRunResult>;
596
609
  /**
597
610
  * Watches vNext workflow transitions in real-time
@@ -603,6 +616,47 @@ declare class VNextWorkflow extends BaseResource {
603
616
  }, onRecord: (record: VNextWorkflowWatchResult) => void): Promise<void>;
604
617
  }
605
618
 
619
+ /**
620
+ * Class for interacting with an agent via the A2A protocol
621
+ */
622
+ declare class A2A extends BaseResource {
623
+ private agentId;
624
+ constructor(options: ClientOptions, agentId: string);
625
+ /**
626
+ * Get the agent card with metadata about the agent
627
+ * @returns Promise containing the agent card information
628
+ */
629
+ getCard(): Promise<AgentCard>;
630
+ /**
631
+ * Send a message to the agent and get a response
632
+ * @param params - Parameters for the task
633
+ * @returns Promise containing the task response
634
+ */
635
+ sendMessage(params: TaskSendParams): Promise<{
636
+ task: Task;
637
+ }>;
638
+ /**
639
+ * Get the status and result of a task
640
+ * @param params - Parameters for querying the task
641
+ * @returns Promise containing the task response
642
+ */
643
+ getTask(params: TaskQueryParams): Promise<Task>;
644
+ /**
645
+ * Cancel a running task
646
+ * @param params - Parameters identifying the task to cancel
647
+ * @returns Promise containing the task response
648
+ */
649
+ cancelTask(params: TaskIdParams): Promise<{
650
+ task: Task;
651
+ }>;
652
+ /**
653
+ * Send a message and subscribe to streaming updates (not fully implemented)
654
+ * @param params - Parameters for the task
655
+ * @returns Promise containing the task response
656
+ */
657
+ sendAndSubscribe(params: TaskSendParams): Promise<Response>;
658
+ }
659
+
606
660
  declare class MastraClient extends BaseResource {
607
661
  constructor(options: ClientOptions);
608
662
  /**
@@ -725,6 +779,12 @@ declare class MastraClient extends BaseResource {
725
779
  * @returns Network instance
726
780
  */
727
781
  getNetwork(networkId: string): Network;
782
+ /**
783
+ * Gets an A2A client for interacting with an agent via the A2A protocol
784
+ * @param agentId - ID of the agent to interact with
785
+ * @returns A2A client instance
786
+ */
787
+ getA2A(agentId: string): A2A;
728
788
  }
729
789
 
730
790
  export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,9 @@ import { JSONSchema7 } from 'json-schema';
5
5
  import { ZodSchema } from 'zod';
6
6
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
7
7
  import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
8
- import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { RuntimeContext } from '@mastra/core/di';
9
+ import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
10
+ import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
9
11
 
10
12
  interface ClientOptions {
11
13
  /** Base URL for API requests */
@@ -293,6 +295,16 @@ declare class Agent extends BaseResource {
293
295
  * @returns Promise containing tool details
294
296
  */
295
297
  getTool(toolId: string): Promise<GetToolResponse>;
298
+ /**
299
+ * Executes a tool for the agent
300
+ * @param toolId - ID of the tool to execute
301
+ * @param params - Parameters required for tool execution
302
+ * @returns Promise containing the tool execution results
303
+ */
304
+ executeTool(toolId: string, params: {
305
+ data: any;
306
+ runtimeContext?: RuntimeContext;
307
+ }): Promise<any>;
296
308
  /**
297
309
  * Retrieves evaluation results for the agent
298
310
  * @returns Promise containing agent evaluations
@@ -512,6 +524,7 @@ declare class Tool extends BaseResource {
512
524
  execute(params: {
513
525
  data: any;
514
526
  runId?: string;
527
+ runtimeContext?: RuntimeContext;
515
528
  }): Promise<any>;
516
529
  }
517
530
 
@@ -555,7 +568,7 @@ declare class VNextWorkflow extends BaseResource {
555
568
  start(params: {
556
569
  runId: string;
557
570
  inputData: Record<string, any>;
558
- runtimeContext?: RuntimeContext;
571
+ runtimeContext?: RuntimeContext$1;
559
572
  }): Promise<{
560
573
  message: string;
561
574
  }>;
@@ -564,11 +577,11 @@ declare class VNextWorkflow extends BaseResource {
564
577
  * @param params - Object containing the runId, step, resumeData and runtimeContext
565
578
  * @returns Promise containing success message
566
579
  */
567
- resume({ step, runId, resumeData, runtimeContext, }: {
580
+ resume({ step, runId, resumeData, ...rest }: {
568
581
  step: string | string[];
569
582
  runId: string;
570
583
  resumeData?: Record<string, any>;
571
- runtimeContext?: RuntimeContext;
584
+ runtimeContext?: RuntimeContext$1;
572
585
  }): Promise<{
573
586
  message: string;
574
587
  }>;
@@ -580,7 +593,7 @@ declare class VNextWorkflow extends BaseResource {
580
593
  startAsync(params: {
581
594
  runId?: string;
582
595
  inputData: Record<string, any>;
583
- runtimeContext?: RuntimeContext;
596
+ runtimeContext?: RuntimeContext$1;
584
597
  }): Promise<VNextWorkflowRunResult>;
585
598
  /**
586
599
  * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
@@ -591,7 +604,7 @@ declare class VNextWorkflow extends BaseResource {
591
604
  runId: string;
592
605
  step: string | string[];
593
606
  resumeData?: Record<string, any>;
594
- runtimeContext?: RuntimeContext;
607
+ runtimeContext?: RuntimeContext$1;
595
608
  }): Promise<VNextWorkflowRunResult>;
596
609
  /**
597
610
  * Watches vNext workflow transitions in real-time
@@ -603,6 +616,47 @@ declare class VNextWorkflow extends BaseResource {
603
616
  }, onRecord: (record: VNextWorkflowWatchResult) => void): Promise<void>;
604
617
  }
605
618
 
619
+ /**
620
+ * Class for interacting with an agent via the A2A protocol
621
+ */
622
+ declare class A2A extends BaseResource {
623
+ private agentId;
624
+ constructor(options: ClientOptions, agentId: string);
625
+ /**
626
+ * Get the agent card with metadata about the agent
627
+ * @returns Promise containing the agent card information
628
+ */
629
+ getCard(): Promise<AgentCard>;
630
+ /**
631
+ * Send a message to the agent and get a response
632
+ * @param params - Parameters for the task
633
+ * @returns Promise containing the task response
634
+ */
635
+ sendMessage(params: TaskSendParams): Promise<{
636
+ task: Task;
637
+ }>;
638
+ /**
639
+ * Get the status and result of a task
640
+ * @param params - Parameters for querying the task
641
+ * @returns Promise containing the task response
642
+ */
643
+ getTask(params: TaskQueryParams): Promise<Task>;
644
+ /**
645
+ * Cancel a running task
646
+ * @param params - Parameters identifying the task to cancel
647
+ * @returns Promise containing the task response
648
+ */
649
+ cancelTask(params: TaskIdParams): Promise<{
650
+ task: Task;
651
+ }>;
652
+ /**
653
+ * Send a message and subscribe to streaming updates (not fully implemented)
654
+ * @param params - Parameters for the task
655
+ * @returns Promise containing the task response
656
+ */
657
+ sendAndSubscribe(params: TaskSendParams): Promise<Response>;
658
+ }
659
+
606
660
  declare class MastraClient extends BaseResource {
607
661
  constructor(options: ClientOptions);
608
662
  /**
@@ -725,6 +779,12 @@ declare class MastraClient extends BaseResource {
725
779
  * @returns Network instance
726
780
  */
727
781
  getNetwork(networkId: string): Network;
782
+ /**
783
+ * Gets an A2A client for interacting with an agent via the A2A protocol
784
+ * @param agentId - ID of the agent to interact with
785
+ * @returns A2A client instance
786
+ */
787
+ getA2A(agentId: string): A2A;
728
788
  }
729
789
 
730
790
  export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.js CHANGED
@@ -353,6 +353,22 @@ var Agent = class extends BaseResource {
353
353
  getTool(toolId) {
354
354
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
355
355
  }
356
+ /**
357
+ * Executes a tool for the agent
358
+ * @param toolId - ID of the tool to execute
359
+ * @param params - Parameters required for tool execution
360
+ * @returns Promise containing the tool execution results
361
+ */
362
+ executeTool(toolId, params) {
363
+ const body = {
364
+ data: params.data,
365
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
366
+ };
367
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
368
+ method: "POST",
369
+ body
370
+ });
371
+ }
356
372
  /**
357
373
  * Retrieves evaluation results for the agent
358
374
  * @returns Promise containing agent evaluations
@@ -750,14 +766,16 @@ var Tool = class extends BaseResource {
750
766
  if (params.runId) {
751
767
  url.set("runId", params.runId);
752
768
  }
769
+ const body = {
770
+ data: params.data,
771
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
772
+ };
753
773
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
754
774
  method: "POST",
755
- body: params.data
775
+ body
756
776
  });
757
777
  }
758
778
  };
759
-
760
- // src/resources/vnext-workflow.ts
761
779
  var RECORD_SEPARATOR2 = "";
762
780
  var VNextWorkflow = class extends BaseResource {
763
781
  constructor(options, workflowId) {
@@ -864,9 +882,10 @@ var VNextWorkflow = class extends BaseResource {
864
882
  * @returns Promise containing success message
865
883
  */
866
884
  start(params) {
885
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
867
886
  return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
868
887
  method: "POST",
869
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
888
+ body: { inputData: params?.inputData, runtimeContext }
870
889
  });
871
890
  }
872
891
  /**
@@ -878,8 +897,9 @@ var VNextWorkflow = class extends BaseResource {
878
897
  step,
879
898
  runId,
880
899
  resumeData,
881
- runtimeContext
900
+ ...rest
882
901
  }) {
902
+ const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : void 0;
883
903
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
884
904
  method: "POST",
885
905
  stream: true,
@@ -900,9 +920,10 @@ var VNextWorkflow = class extends BaseResource {
900
920
  if (!!params?.runId) {
901
921
  searchParams.set("runId", params.runId);
902
922
  }
923
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
903
924
  return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
904
925
  method: "POST",
905
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
926
+ body: { inputData: params.inputData, runtimeContext }
906
927
  });
907
928
  }
908
929
  /**
@@ -911,12 +932,13 @@ var VNextWorkflow = class extends BaseResource {
911
932
  * @returns Promise containing the vNext workflow resume results
912
933
  */
913
934
  resumeAsync(params) {
935
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
914
936
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
915
937
  method: "POST",
916
938
  body: {
917
939
  step: params.step,
918
940
  resumeData: params.resumeData,
919
- runtimeContext: params.runtimeContext
941
+ runtimeContext
920
942
  }
921
943
  });
922
944
  }
@@ -941,6 +963,80 @@ var VNextWorkflow = class extends BaseResource {
941
963
  }
942
964
  };
943
965
 
966
+ // src/resources/a2a.ts
967
+ var A2A = class extends BaseResource {
968
+ constructor(options, agentId) {
969
+ super(options);
970
+ this.agentId = agentId;
971
+ }
972
+ /**
973
+ * Get the agent card with metadata about the agent
974
+ * @returns Promise containing the agent card information
975
+ */
976
+ async getCard() {
977
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
978
+ }
979
+ /**
980
+ * Send a message to the agent and get a response
981
+ * @param params - Parameters for the task
982
+ * @returns Promise containing the task response
983
+ */
984
+ async sendMessage(params) {
985
+ const response = await this.request(`/a2a/${this.agentId}`, {
986
+ method: "POST",
987
+ body: {
988
+ method: "tasks/send",
989
+ params
990
+ }
991
+ });
992
+ return { task: response.result };
993
+ }
994
+ /**
995
+ * Get the status and result of a task
996
+ * @param params - Parameters for querying the task
997
+ * @returns Promise containing the task response
998
+ */
999
+ async getTask(params) {
1000
+ const response = await this.request(`/a2a/${this.agentId}`, {
1001
+ method: "POST",
1002
+ body: {
1003
+ method: "tasks/get",
1004
+ params
1005
+ }
1006
+ });
1007
+ return response.result;
1008
+ }
1009
+ /**
1010
+ * Cancel a running task
1011
+ * @param params - Parameters identifying the task to cancel
1012
+ * @returns Promise containing the task response
1013
+ */
1014
+ async cancelTask(params) {
1015
+ return this.request(`/a2a/${this.agentId}`, {
1016
+ method: "POST",
1017
+ body: {
1018
+ method: "tasks/cancel",
1019
+ params
1020
+ }
1021
+ });
1022
+ }
1023
+ /**
1024
+ * Send a message and subscribe to streaming updates (not fully implemented)
1025
+ * @param params - Parameters for the task
1026
+ * @returns Promise containing the task response
1027
+ */
1028
+ async sendAndSubscribe(params) {
1029
+ return this.request(`/a2a/${this.agentId}`, {
1030
+ method: "POST",
1031
+ body: {
1032
+ method: "tasks/sendSubscribe",
1033
+ params
1034
+ },
1035
+ stream: true
1036
+ });
1037
+ }
1038
+ };
1039
+
944
1040
  // src/client.ts
945
1041
  var MastraClient = class extends BaseResource {
946
1042
  constructor(options) {
@@ -1151,6 +1247,14 @@ var MastraClient = class extends BaseResource {
1151
1247
  getNetwork(networkId) {
1152
1248
  return new Network(this.options, networkId);
1153
1249
  }
1250
+ /**
1251
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1252
+ * @param agentId - ID of the agent to interact with
1253
+ * @returns A2A client instance
1254
+ */
1255
+ getA2A(agentId) {
1256
+ return new A2A(this.options, agentId);
1257
+ }
1154
1258
  };
1155
1259
 
1156
1260
  export { MastraClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.21",
3
+ "version": "0.1.22-alpha.1",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -28,10 +28,10 @@
28
28
  "rxjs": "7.8.1",
29
29
  "zod": "^3.24.3",
30
30
  "zod-to-json-schema": "^3.24.5",
31
- "@mastra/core": "^0.9.3"
31
+ "@mastra/core": "^0.9.4-alpha.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "zod": "^3.24.2"
34
+ "zod": "^3.0.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/preset-env": "^7.26.9",
package/src/client.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AbstractAgent } from '@ag-ui/client';
2
2
  import { AGUIAdapter } from './adapters/agui';
3
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
3
+ import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow, A2A } from './resources';
4
4
  import type {
5
5
  ClientOptions,
6
6
  CreateMemoryThreadParams,
@@ -256,4 +256,13 @@ export class MastraClient extends BaseResource {
256
256
  public getNetwork(networkId: string) {
257
257
  return new Network(this.options, networkId);
258
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
+ }
259
268
  }
@@ -0,0 +1,88 @@
1
+ import type { TaskSendParams, TaskQueryParams, TaskIdParams, Task, AgentCard, JSONRPCResponse } from '@mastra/core/a2a';
2
+ import type { ClientOptions } from '../types';
3
+ import { BaseResource } from './base';
4
+
5
+ /**
6
+ * Class for interacting with an agent via the A2A protocol
7
+ */
8
+ export class A2A extends BaseResource {
9
+ constructor(
10
+ options: ClientOptions,
11
+ private agentId: string,
12
+ ) {
13
+ super(options);
14
+ }
15
+
16
+ /**
17
+ * Get the agent card with metadata about the agent
18
+ * @returns Promise containing the agent card information
19
+ */
20
+ async getCard(): Promise<AgentCard> {
21
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
22
+ }
23
+
24
+ /**
25
+ * Send a message to the agent and get a response
26
+ * @param params - Parameters for the task
27
+ * @returns Promise containing the task response
28
+ */
29
+ async sendMessage(params: TaskSendParams): Promise<{ task: Task }> {
30
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
31
+ method: 'POST',
32
+ body: {
33
+ method: 'tasks/send',
34
+ params,
35
+ },
36
+ });
37
+
38
+ return { task: response.result! };
39
+ }
40
+
41
+ /**
42
+ * Get the status and result of a task
43
+ * @param params - Parameters for querying the task
44
+ * @returns Promise containing the task response
45
+ */
46
+ async getTask(params: TaskQueryParams): Promise<Task> {
47
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
48
+ method: 'POST',
49
+ body: {
50
+ method: 'tasks/get',
51
+ params,
52
+ },
53
+ });
54
+
55
+ return response.result!;
56
+ }
57
+
58
+ /**
59
+ * Cancel a running task
60
+ * @param params - Parameters identifying the task to cancel
61
+ * @returns Promise containing the task response
62
+ */
63
+ async cancelTask(params: TaskIdParams): Promise<{ task: Task }> {
64
+ return this.request(`/a2a/${this.agentId}`, {
65
+ method: 'POST',
66
+ body: {
67
+ method: 'tasks/cancel',
68
+ params,
69
+ },
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Send a message and subscribe to streaming updates (not fully implemented)
75
+ * @param params - Parameters for the task
76
+ * @returns Promise containing the task response
77
+ */
78
+ async sendAndSubscribe(params: TaskSendParams): Promise<Response> {
79
+ return this.request(`/a2a/${this.agentId}`, {
80
+ method: 'POST',
81
+ body: {
82
+ method: 'tasks/sendSubscribe',
83
+ params,
84
+ },
85
+ stream: true,
86
+ });
87
+ }
88
+ }
@@ -14,28 +14,7 @@ import type {
14
14
  } from '../types';
15
15
 
16
16
  import { BaseResource } from './base';
17
-
18
- export class AgentTool extends BaseResource {
19
- constructor(
20
- options: ClientOptions,
21
- private agentId: string,
22
- private toolId: string,
23
- ) {
24
- super(options);
25
- }
26
-
27
- /**
28
- * Executes a specific tool for an agent
29
- * @param params - Parameters required for tool execution
30
- * @returns Promise containing tool execution results
31
- */
32
- execute(params: { data: any }): Promise<any> {
33
- return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
34
- method: 'POST',
35
- body: params,
36
- });
37
- }
38
- }
17
+ import type { RuntimeContext } from '@mastra/core/di';
39
18
 
40
19
  export class AgentVoice extends BaseResource {
41
20
  constructor(
@@ -188,6 +167,23 @@ export class Agent extends BaseResource {
188
167
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
189
168
  }
190
169
 
170
+ /**
171
+ * Executes a tool for the agent
172
+ * @param toolId - ID of the tool to execute
173
+ * @param params - Parameters required for tool execution
174
+ * @returns Promise containing the tool execution results
175
+ */
176
+ executeTool(toolId: string, params: { data: any; runtimeContext?: RuntimeContext }): Promise<any> {
177
+ const body = {
178
+ data: params.data,
179
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
180
+ };
181
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
182
+ method: 'POST',
183
+ body,
184
+ });
185
+ }
186
+
191
187
  /**
192
188
  * Retrieves evaluation results for the agent
193
189
  * @returns Promise containing agent evaluations
@@ -6,3 +6,4 @@ export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
8
  export * from './vnext-workflow';
9
+ export * from './a2a';
@@ -1,3 +1,4 @@
1
+ import type { RuntimeContext } from '@mastra/core/di';
1
2
  import type { GetToolResponse, ClientOptions } from '../types';
2
3
 
3
4
  import { BaseResource } from './base';
@@ -23,16 +24,21 @@ export class Tool extends BaseResource {
23
24
  * @param params - Parameters required for tool execution
24
25
  * @returns Promise containing the tool execution results
25
26
  */
26
- execute(params: { data: any; runId?: string }): Promise<any> {
27
+ execute(params: { data: any; runId?: string; runtimeContext?: RuntimeContext }): Promise<any> {
27
28
  const url = new URLSearchParams();
28
29
 
29
30
  if (params.runId) {
30
31
  url.set('runId', params.runId);
31
32
  }
32
33
 
34
+ const body = {
35
+ data: params.data,
36
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
37
+ };
38
+
33
39
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
34
40
  method: 'POST',
35
- body: params.data,
41
+ body,
36
42
  });
37
43
  }
38
44
  }
@@ -1,4 +1,4 @@
1
- import type { RuntimeContext } from '@mastra/core/runtime-context';
1
+ import { RuntimeContext } from '@mastra/core/runtime-context';
2
2
  import type {
3
3
  ClientOptions,
4
4
  GetVNextWorkflowResponse,
@@ -156,9 +156,10 @@ export class VNextWorkflow extends BaseResource {
156
156
  inputData: Record<string, any>;
157
157
  runtimeContext?: RuntimeContext;
158
158
  }): Promise<{ message: string }> {
159
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
159
160
  return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
160
161
  method: 'POST',
161
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
162
+ body: { inputData: params?.inputData, runtimeContext },
162
163
  });
163
164
  }
164
165
 
@@ -171,13 +172,14 @@ export class VNextWorkflow extends BaseResource {
171
172
  step,
172
173
  runId,
173
174
  resumeData,
174
- runtimeContext,
175
+ ...rest
175
176
  }: {
176
177
  step: string | string[];
177
178
  runId: string;
178
179
  resumeData?: Record<string, any>;
179
180
  runtimeContext?: RuntimeContext;
180
181
  }): Promise<{ message: string }> {
182
+ const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : undefined;
181
183
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
182
184
  method: 'POST',
183
185
  stream: true,
@@ -205,9 +207,10 @@ export class VNextWorkflow extends BaseResource {
205
207
  searchParams.set('runId', params.runId);
206
208
  }
207
209
 
210
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
208
211
  return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
209
212
  method: 'POST',
210
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
213
+ body: { inputData: params.inputData, runtimeContext },
211
214
  });
212
215
  }
213
216
 
@@ -222,12 +225,13 @@ export class VNextWorkflow extends BaseResource {
222
225
  resumeData?: Record<string, any>;
223
226
  runtimeContext?: RuntimeContext;
224
227
  }): Promise<VNextWorkflowRunResult> {
228
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
225
229
  return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
226
230
  method: 'POST',
227
231
  body: {
228
232
  step: params.step,
229
233
  resumeData: params.resumeData,
230
- runtimeContext: params.runtimeContext,
234
+ runtimeContext,
231
235
  },
232
236
  });
233
237
  }