@mastra/client-js 0.0.0-vnext-inngest-20250508131921 → 0.0.0-vnextAgentNetwork-20250527091247

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/dist/index.cjs CHANGED
@@ -4,7 +4,12 @@ var client = require('@ag-ui/client');
4
4
  var rxjs = require('rxjs');
5
5
  var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
- var zodToJsonSchema = require('zod-to-json-schema');
7
+ var originalZodToJsonSchema = require('zod-to-json-schema');
8
+ var runtimeContext = require('@mastra/core/runtime-context');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
8
13
 
9
14
  // src/adapters/agui.ts
10
15
  var AGUIAdapter = class extends client.AbstractAgent {
@@ -44,6 +49,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
44
49
  )
45
50
  }).then((response) => {
46
51
  let currentMessageId = void 0;
52
+ let isInTextMessage = false;
47
53
  return response.processDataStream({
48
54
  onTextPart: (text) => {
49
55
  if (currentMessageId === void 0) {
@@ -54,6 +60,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
54
60
  role: "assistant"
55
61
  };
56
62
  subscriber.next(message2);
63
+ isInTextMessage = true;
57
64
  }
58
65
  const message = {
59
66
  type: client.EventType.TEXT_MESSAGE_CONTENT,
@@ -62,14 +69,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
62
69
  };
63
70
  subscriber.next(message);
64
71
  },
65
- onFinishMessagePart: (message) => {
66
- console.log("onFinishMessagePart", message);
72
+ onFinishMessagePart: () => {
67
73
  if (currentMessageId !== void 0) {
68
- const message2 = {
74
+ const message = {
69
75
  type: client.EventType.TEXT_MESSAGE_END,
70
76
  messageId: currentMessageId
71
77
  };
72
- subscriber.next(message2);
78
+ subscriber.next(message);
79
+ isInTextMessage = false;
73
80
  }
74
81
  subscriber.next({
75
82
  type: client.EventType.RUN_FINISHED,
@@ -80,6 +87,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
80
87
  },
81
88
  onToolCallPart(streamPart) {
82
89
  const parentMessageId = currentMessageId || generateUUID();
90
+ if (isInTextMessage) {
91
+ const message = {
92
+ type: client.EventType.TEXT_MESSAGE_END,
93
+ messageId: parentMessageId
94
+ };
95
+ subscriber.next(message);
96
+ isInTextMessage = false;
97
+ }
83
98
  subscriber.next({
84
99
  type: client.EventType.TOOL_CALL_START,
85
100
  toolCallId: streamPart.toolCallId,
@@ -100,7 +115,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
100
115
  }
101
116
  });
102
117
  }).catch((error) => {
103
- console.log("error", error);
118
+ console.error("error", error);
104
119
  subscriber.error(error);
105
120
  });
106
121
  return () => {
@@ -149,6 +164,17 @@ function convertMessagesToMastraMessages(messages) {
149
164
  role: "assistant",
150
165
  content: parts
151
166
  });
167
+ if (message.toolCalls?.length) {
168
+ result.push({
169
+ role: "tool",
170
+ content: message.toolCalls.map((toolCall) => ({
171
+ type: "tool-result",
172
+ toolCallId: toolCall.id,
173
+ toolName: toolCall.function.name,
174
+ result: JSON.parse(toolCall.function.arguments)
175
+ }))
176
+ });
177
+ }
152
178
  } else if (message.role === "user") {
153
179
  result.push({
154
180
  role: "user",
@@ -170,6 +196,12 @@ function convertMessagesToMastraMessages(messages) {
170
196
  }
171
197
  return result;
172
198
  }
199
+ function zodToJsonSchema(zodSchema) {
200
+ if (!(zodSchema instanceof zod.ZodSchema)) {
201
+ return zodSchema;
202
+ }
203
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
204
+ }
173
205
 
174
206
  // src/resources/base.ts
175
207
  var BaseResource = class {
@@ -189,7 +221,7 @@ var BaseResource = class {
189
221
  let delay = backoffMs;
190
222
  for (let attempt = 0; attempt <= retries; attempt++) {
191
223
  try {
192
- const response = await fetch(`${baseUrl}${path}`, {
224
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
193
225
  ...options,
194
226
  headers: {
195
227
  ...headers,
@@ -229,6 +261,15 @@ var BaseResource = class {
229
261
  throw lastError || new Error("Request failed");
230
262
  }
231
263
  };
264
+ function parseClientRuntimeContext(runtimeContext$1) {
265
+ if (runtimeContext$1) {
266
+ if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
267
+ return Object.fromEntries(runtimeContext$1.entries());
268
+ }
269
+ return runtimeContext$1;
270
+ }
271
+ return void 0;
272
+ }
232
273
 
233
274
  // src/resources/agent.ts
234
275
  var AgentVoice = class extends BaseResource {
@@ -300,9 +341,9 @@ var Agent = class extends BaseResource {
300
341
  generate(params) {
301
342
  const processedParams = {
302
343
  ...params,
303
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
304
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output,
305
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
344
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
345
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
346
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
306
347
  };
307
348
  return this.request(`/api/agents/${this.agentId}/generate`, {
308
349
  method: "POST",
@@ -317,9 +358,9 @@ var Agent = class extends BaseResource {
317
358
  async stream(params) {
318
359
  const processedParams = {
319
360
  ...params,
320
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
321
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output,
322
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
361
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
362
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
363
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
323
364
  };
324
365
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
325
366
  method: "POST",
@@ -345,6 +386,22 @@ var Agent = class extends BaseResource {
345
386
  getTool(toolId) {
346
387
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
347
388
  }
389
+ /**
390
+ * Executes a tool for the agent
391
+ * @param toolId - ID of the tool to execute
392
+ * @param params - Parameters required for tool execution
393
+ * @returns Promise containing the tool execution results
394
+ */
395
+ executeTool(toolId, params) {
396
+ const body = {
397
+ data: params.data,
398
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
399
+ };
400
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
401
+ method: "POST",
402
+ body
403
+ });
404
+ }
348
405
  /**
349
406
  * Retrieves evaluation results for the agent
350
407
  * @returns Promise containing agent evaluations
@@ -380,8 +437,8 @@ var Network = class extends BaseResource {
380
437
  generate(params) {
381
438
  const processedParams = {
382
439
  ...params,
383
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
384
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
440
+ output: zodToJsonSchema(params.output),
441
+ experimental_output: zodToJsonSchema(params.experimental_output)
385
442
  };
386
443
  return this.request(`/api/networks/${this.networkId}/generate`, {
387
444
  method: "POST",
@@ -396,8 +453,8 @@ var Network = class extends BaseResource {
396
453
  async stream(params) {
397
454
  const processedParams = {
398
455
  ...params,
399
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
400
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
456
+ output: zodToJsonSchema(params.output),
457
+ experimental_output: zodToJsonSchema(params.experimental_output)
401
458
  };
402
459
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
403
460
  method: "POST",
@@ -453,10 +510,15 @@ var MemoryThread = class extends BaseResource {
453
510
  }
454
511
  /**
455
512
  * Retrieves messages associated with the thread
513
+ * @param params - Optional parameters including limit for number of messages to retrieve
456
514
  * @returns Promise containing thread messages and UI messages
457
515
  */
458
- getMessages() {
459
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
516
+ getMessages(params) {
517
+ const query = new URLSearchParams({
518
+ agentId: this.agentId,
519
+ ...params?.limit ? { limit: params.limit.toString() } : {}
520
+ });
521
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
460
522
  }
461
523
  };
462
524
 
@@ -526,24 +588,24 @@ var Vector = class extends BaseResource {
526
588
  }
527
589
  };
528
590
 
529
- // src/resources/workflow.ts
591
+ // src/resources/legacy-workflow.ts
530
592
  var RECORD_SEPARATOR = "";
531
- var Workflow = class extends BaseResource {
593
+ var LegacyWorkflow = class extends BaseResource {
532
594
  constructor(options, workflowId) {
533
595
  super(options);
534
596
  this.workflowId = workflowId;
535
597
  }
536
598
  /**
537
- * Retrieves details about the workflow
538
- * @returns Promise containing workflow details including steps and graphs
599
+ * Retrieves details about the legacy workflow
600
+ * @returns Promise containing legacy workflow details including steps and graphs
539
601
  */
540
602
  details() {
541
- return this.request(`/api/workflows/${this.workflowId}`);
603
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
542
604
  }
543
605
  /**
544
- * Retrieves all runs for a workflow
606
+ * Retrieves all runs for a legacy workflow
545
607
  * @param params - Parameters for filtering runs
546
- * @returns Promise containing workflow runs array
608
+ * @returns Promise containing legacy workflow runs array
547
609
  */
548
610
  runs(params) {
549
611
  const searchParams = new URLSearchParams();
@@ -563,25 +625,13 @@ var Workflow = class extends BaseResource {
563
625
  searchParams.set("resourceId", params.resourceId);
564
626
  }
565
627
  if (searchParams.size) {
566
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
628
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
567
629
  } else {
568
- return this.request(`/api/workflows/${this.workflowId}/runs`);
630
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
569
631
  }
570
632
  }
571
633
  /**
572
- * @deprecated Use `startAsync` instead
573
- * Executes the workflow with the provided parameters
574
- * @param params - Parameters required for workflow execution
575
- * @returns Promise containing the workflow execution results
576
- */
577
- execute(params) {
578
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
579
- method: "POST",
580
- body: params
581
- });
582
- }
583
- /**
584
- * Creates a new workflow run
634
+ * Creates a new legacy workflow run
585
635
  * @returns Promise containing the generated run ID
586
636
  */
587
637
  createRun(params) {
@@ -589,34 +639,34 @@ var Workflow = class extends BaseResource {
589
639
  if (!!params?.runId) {
590
640
  searchParams.set("runId", params.runId);
591
641
  }
592
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
642
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
593
643
  method: "POST"
594
644
  });
595
645
  }
596
646
  /**
597
- * Starts a workflow run synchronously without waiting for the workflow to complete
647
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
598
648
  * @param params - Object containing the runId and triggerData
599
649
  * @returns Promise containing success message
600
650
  */
601
651
  start(params) {
602
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
652
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
603
653
  method: "POST",
604
654
  body: params?.triggerData
605
655
  });
606
656
  }
607
657
  /**
608
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
658
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
609
659
  * @param stepId - ID of the step to resume
610
- * @param runId - ID of the workflow run
611
- * @param context - Context to resume the workflow with
612
- * @returns Promise containing the workflow resume results
660
+ * @param runId - ID of the legacy workflow run
661
+ * @param context - Context to resume the legacy workflow with
662
+ * @returns Promise containing the legacy workflow resume results
613
663
  */
614
664
  resume({
615
665
  stepId,
616
666
  runId,
617
667
  context
618
668
  }) {
619
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
669
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
620
670
  method: "POST",
621
671
  body: {
622
672
  stepId,
@@ -634,18 +684,18 @@ var Workflow = class extends BaseResource {
634
684
  if (!!params?.runId) {
635
685
  searchParams.set("runId", params.runId);
636
686
  }
637
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
687
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
638
688
  method: "POST",
639
689
  body: params?.triggerData
640
690
  });
641
691
  }
642
692
  /**
643
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
693
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
644
694
  * @param params - Object containing the runId, stepId, and context
645
695
  * @returns Promise containing the workflow resume results
646
696
  */
647
697
  resumeAsync(params) {
648
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
698
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
649
699
  method: "POST",
650
700
  body: {
651
701
  stepId: params.stepId,
@@ -699,16 +749,16 @@ var Workflow = class extends BaseResource {
699
749
  }
700
750
  }
701
751
  /**
702
- * Watches workflow transitions in real-time
752
+ * Watches legacy workflow transitions in real-time
703
753
  * @param runId - Optional run ID to filter the watch stream
704
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
754
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
705
755
  */
706
756
  async watch({ runId }, onRecord) {
707
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
757
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
708
758
  stream: true
709
759
  });
710
760
  if (!response.ok) {
711
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
761
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
712
762
  }
713
763
  if (!response.body) {
714
764
  throw new Error("Response body is null");
@@ -742,22 +792,26 @@ var Tool = class extends BaseResource {
742
792
  if (params.runId) {
743
793
  url.set("runId", params.runId);
744
794
  }
795
+ const body = {
796
+ data: params.data,
797
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
798
+ };
745
799
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
746
800
  method: "POST",
747
- body: params.data
801
+ body
748
802
  });
749
803
  }
750
804
  };
751
805
 
752
- // src/resources/vnext-workflow.ts
806
+ // src/resources/workflow.ts
753
807
  var RECORD_SEPARATOR2 = "";
754
- var VNextWorkflow = class extends BaseResource {
808
+ var Workflow = class extends BaseResource {
755
809
  constructor(options, workflowId) {
756
810
  super(options);
757
811
  this.workflowId = workflowId;
758
812
  }
759
813
  /**
760
- * Creates an async generator that processes a readable stream and yields vNext workflow records
814
+ * Creates an async generator that processes a readable stream and yields workflow records
761
815
  * separated by the Record Separator character (\x1E)
762
816
  *
763
817
  * @param stream - The readable stream to process
@@ -802,16 +856,16 @@ var VNextWorkflow = class extends BaseResource {
802
856
  }
803
857
  }
804
858
  /**
805
- * Retrieves details about the vNext workflow
806
- * @returns Promise containing vNext workflow details including steps and graphs
859
+ * Retrieves details about the workflow
860
+ * @returns Promise containing workflow details including steps and graphs
807
861
  */
808
862
  details() {
809
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
863
+ return this.request(`/api/workflows/${this.workflowId}`);
810
864
  }
811
865
  /**
812
- * Retrieves all runs for a vNext workflow
866
+ * Retrieves all runs for a workflow
813
867
  * @param params - Parameters for filtering runs
814
- * @returns Promise containing vNext workflow runs array
868
+ * @returns Promise containing workflow runs array
815
869
  */
816
870
  runs(params) {
817
871
  const searchParams = new URLSearchParams();
@@ -831,13 +885,13 @@ var VNextWorkflow = class extends BaseResource {
831
885
  searchParams.set("resourceId", params.resourceId);
832
886
  }
833
887
  if (searchParams.size) {
834
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
888
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
835
889
  } else {
836
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
890
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
837
891
  }
838
892
  }
839
893
  /**
840
- * Creates a new vNext workflow run
894
+ * Creates a new workflow run
841
895
  * @param params - Optional object containing the optional runId
842
896
  * @returns Promise containing the runId of the created run
843
897
  */
@@ -846,23 +900,24 @@ var VNextWorkflow = class extends BaseResource {
846
900
  if (!!params?.runId) {
847
901
  searchParams.set("runId", params.runId);
848
902
  }
849
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
903
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
850
904
  method: "POST"
851
905
  });
852
906
  }
853
907
  /**
854
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
908
+ * Starts a workflow run synchronously without waiting for the workflow to complete
855
909
  * @param params - Object containing the runId, inputData and runtimeContext
856
910
  * @returns Promise containing success message
857
911
  */
858
912
  start(params) {
859
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
913
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
914
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
860
915
  method: "POST",
861
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
916
+ body: { inputData: params?.inputData, runtimeContext }
862
917
  });
863
918
  }
864
919
  /**
865
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
920
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
866
921
  * @param params - Object containing the runId, step, resumeData and runtimeContext
867
922
  * @returns Promise containing success message
868
923
  */
@@ -870,9 +925,10 @@ var VNextWorkflow = class extends BaseResource {
870
925
  step,
871
926
  runId,
872
927
  resumeData,
873
- runtimeContext
928
+ ...rest
874
929
  }) {
875
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
930
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
931
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
876
932
  method: "POST",
877
933
  stream: true,
878
934
  body: {
@@ -883,46 +939,95 @@ var VNextWorkflow = class extends BaseResource {
883
939
  });
884
940
  }
885
941
  /**
886
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
942
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
887
943
  * @param params - Object containing the optional runId, inputData and runtimeContext
888
- * @returns Promise containing the vNext workflow execution results
944
+ * @returns Promise containing the workflow execution results
889
945
  */
890
946
  startAsync(params) {
891
947
  const searchParams = new URLSearchParams();
892
948
  if (!!params?.runId) {
893
949
  searchParams.set("runId", params.runId);
894
950
  }
895
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
951
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
952
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
896
953
  method: "POST",
897
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
954
+ body: { inputData: params.inputData, runtimeContext }
955
+ });
956
+ }
957
+ /**
958
+ * Starts a vNext workflow run and returns a stream
959
+ * @param params - Object containing the optional runId, inputData and runtimeContext
960
+ * @returns Promise containing the vNext workflow execution results
961
+ */
962
+ async stream(params) {
963
+ const searchParams = new URLSearchParams();
964
+ if (!!params?.runId) {
965
+ searchParams.set("runId", params.runId);
966
+ }
967
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
968
+ const response = await this.request(
969
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
970
+ {
971
+ method: "POST",
972
+ body: { inputData: params.inputData, runtimeContext },
973
+ stream: true
974
+ }
975
+ );
976
+ if (!response.ok) {
977
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
978
+ }
979
+ if (!response.body) {
980
+ throw new Error("Response body is null");
981
+ }
982
+ const transformStream = new TransformStream({
983
+ start() {
984
+ },
985
+ async transform(chunk, controller) {
986
+ try {
987
+ const decoded = new TextDecoder().decode(chunk);
988
+ const chunks = decoded.split(RECORD_SEPARATOR2);
989
+ for (const chunk2 of chunks) {
990
+ if (chunk2) {
991
+ try {
992
+ const parsedChunk = JSON.parse(chunk2);
993
+ controller.enqueue(parsedChunk);
994
+ } catch {
995
+ }
996
+ }
997
+ }
998
+ } catch {
999
+ }
1000
+ }
898
1001
  });
1002
+ return response.body.pipeThrough(transformStream);
899
1003
  }
900
1004
  /**
901
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1005
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
902
1006
  * @param params - Object containing the runId, step, resumeData and runtimeContext
903
- * @returns Promise containing the vNext workflow resume results
1007
+ * @returns Promise containing the workflow resume results
904
1008
  */
905
1009
  resumeAsync(params) {
906
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1010
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1011
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
907
1012
  method: "POST",
908
1013
  body: {
909
1014
  step: params.step,
910
1015
  resumeData: params.resumeData,
911
- runtimeContext: params.runtimeContext
1016
+ runtimeContext
912
1017
  }
913
1018
  });
914
1019
  }
915
1020
  /**
916
- * Watches vNext workflow transitions in real-time
1021
+ * Watches workflow transitions in real-time
917
1022
  * @param runId - Optional run ID to filter the watch stream
918
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1023
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
919
1024
  */
920
1025
  async watch({ runId }, onRecord) {
921
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1026
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
922
1027
  stream: true
923
1028
  });
924
1029
  if (!response.ok) {
925
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1030
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
926
1031
  }
927
1032
  if (!response.body) {
928
1033
  throw new Error("Response body is null");
@@ -931,6 +1036,137 @@ var VNextWorkflow = class extends BaseResource {
931
1036
  onRecord(record);
932
1037
  }
933
1038
  }
1039
+ /**
1040
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1041
+ * serializing each as JSON and separating them with the record separator (\x1E).
1042
+ *
1043
+ * @param records - An iterable or async iterable of objects to stream
1044
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1045
+ */
1046
+ static createRecordStream(records) {
1047
+ const encoder = new TextEncoder();
1048
+ return new ReadableStream({
1049
+ async start(controller) {
1050
+ try {
1051
+ for await (const record of records) {
1052
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1053
+ controller.enqueue(encoder.encode(json));
1054
+ }
1055
+ controller.close();
1056
+ } catch (err) {
1057
+ controller.error(err);
1058
+ }
1059
+ }
1060
+ });
1061
+ }
1062
+ };
1063
+
1064
+ // src/resources/a2a.ts
1065
+ var A2A = class extends BaseResource {
1066
+ constructor(options, agentId) {
1067
+ super(options);
1068
+ this.agentId = agentId;
1069
+ }
1070
+ /**
1071
+ * Get the agent card with metadata about the agent
1072
+ * @returns Promise containing the agent card information
1073
+ */
1074
+ async getCard() {
1075
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1076
+ }
1077
+ /**
1078
+ * Send a message to the agent and get a response
1079
+ * @param params - Parameters for the task
1080
+ * @returns Promise containing the task response
1081
+ */
1082
+ async sendMessage(params) {
1083
+ const response = await this.request(`/a2a/${this.agentId}`, {
1084
+ method: "POST",
1085
+ body: {
1086
+ method: "tasks/send",
1087
+ params
1088
+ }
1089
+ });
1090
+ return { task: response.result };
1091
+ }
1092
+ /**
1093
+ * Get the status and result of a task
1094
+ * @param params - Parameters for querying the task
1095
+ * @returns Promise containing the task response
1096
+ */
1097
+ async getTask(params) {
1098
+ const response = await this.request(`/a2a/${this.agentId}`, {
1099
+ method: "POST",
1100
+ body: {
1101
+ method: "tasks/get",
1102
+ params
1103
+ }
1104
+ });
1105
+ return response.result;
1106
+ }
1107
+ /**
1108
+ * Cancel a running task
1109
+ * @param params - Parameters identifying the task to cancel
1110
+ * @returns Promise containing the task response
1111
+ */
1112
+ async cancelTask(params) {
1113
+ return this.request(`/a2a/${this.agentId}`, {
1114
+ method: "POST",
1115
+ body: {
1116
+ method: "tasks/cancel",
1117
+ params
1118
+ }
1119
+ });
1120
+ }
1121
+ /**
1122
+ * Send a message and subscribe to streaming updates (not fully implemented)
1123
+ * @param params - Parameters for the task
1124
+ * @returns Promise containing the task response
1125
+ */
1126
+ async sendAndSubscribe(params) {
1127
+ return this.request(`/a2a/${this.agentId}`, {
1128
+ method: "POST",
1129
+ body: {
1130
+ method: "tasks/sendSubscribe",
1131
+ params
1132
+ },
1133
+ stream: true
1134
+ });
1135
+ }
1136
+ };
1137
+
1138
+ // src/resources/mcp-tool.ts
1139
+ var MCPTool = class extends BaseResource {
1140
+ serverId;
1141
+ toolId;
1142
+ constructor(options, serverId, toolId) {
1143
+ super(options);
1144
+ this.serverId = serverId;
1145
+ this.toolId = toolId;
1146
+ }
1147
+ /**
1148
+ * Retrieves details about this specific tool from the MCP server.
1149
+ * @returns Promise containing the tool's information (name, description, schema).
1150
+ */
1151
+ details() {
1152
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1153
+ }
1154
+ /**
1155
+ * Executes this specific tool on the MCP server.
1156
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1157
+ * @returns Promise containing the result of the tool execution.
1158
+ */
1159
+ execute(params) {
1160
+ const body = {};
1161
+ if (params.data !== void 0) body.data = params.data;
1162
+ if (params.runtimeContext !== void 0) {
1163
+ body.runtimeContext = params.runtimeContext;
1164
+ }
1165
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1166
+ method: "POST",
1167
+ body: Object.keys(body).length > 0 ? body : void 0
1168
+ });
1169
+ }
934
1170
  };
935
1171
 
936
1172
  // src/client.ts
@@ -1025,6 +1261,21 @@ var MastraClient = class extends BaseResource {
1025
1261
  getTool(toolId) {
1026
1262
  return new Tool(this.options, toolId);
1027
1263
  }
1264
+ /**
1265
+ * Retrieves all available legacy workflows
1266
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1267
+ */
1268
+ getLegacyWorkflows() {
1269
+ return this.request("/api/workflows/legacy");
1270
+ }
1271
+ /**
1272
+ * Gets a legacy workflow instance by ID
1273
+ * @param workflowId - ID of the legacy workflow to retrieve
1274
+ * @returns Legacy Workflow instance
1275
+ */
1276
+ getLegacyWorkflow(workflowId) {
1277
+ return new LegacyWorkflow(this.options, workflowId);
1278
+ }
1028
1279
  /**
1029
1280
  * Retrieves all available workflows
1030
1281
  * @returns Promise containing map of workflow IDs to workflow details
@@ -1040,21 +1291,6 @@ var MastraClient = class extends BaseResource {
1040
1291
  getWorkflow(workflowId) {
1041
1292
  return new Workflow(this.options, workflowId);
1042
1293
  }
1043
- /**
1044
- * Retrieves all available vNext workflows
1045
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
1046
- */
1047
- getVNextWorkflows() {
1048
- return this.request("/api/workflows/v-next");
1049
- }
1050
- /**
1051
- * Gets a vNext workflow instance by ID
1052
- * @param workflowId - ID of the vNext workflow to retrieve
1053
- * @returns vNext Workflow instance
1054
- */
1055
- getVNextWorkflow(workflowId) {
1056
- return new VNextWorkflow(this.options, workflowId);
1057
- }
1058
1294
  /**
1059
1295
  * Gets a vector instance by name
1060
1296
  * @param vectorName - Name of the vector to retrieve
@@ -1143,6 +1379,62 @@ var MastraClient = class extends BaseResource {
1143
1379
  getNetwork(networkId) {
1144
1380
  return new Network(this.options, networkId);
1145
1381
  }
1382
+ /**
1383
+ * Retrieves a list of available MCP servers.
1384
+ * @param params - Optional parameters for pagination (limit, offset).
1385
+ * @returns Promise containing the list of MCP servers and pagination info.
1386
+ */
1387
+ getMcpServers(params) {
1388
+ const searchParams = new URLSearchParams();
1389
+ if (params?.limit !== void 0) {
1390
+ searchParams.set("limit", String(params.limit));
1391
+ }
1392
+ if (params?.offset !== void 0) {
1393
+ searchParams.set("offset", String(params.offset));
1394
+ }
1395
+ const queryString = searchParams.toString();
1396
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1397
+ }
1398
+ /**
1399
+ * Retrieves detailed information for a specific MCP server.
1400
+ * @param serverId - The ID of the MCP server to retrieve.
1401
+ * @param params - Optional parameters, e.g., specific version.
1402
+ * @returns Promise containing the detailed MCP server information.
1403
+ */
1404
+ getMcpServerDetails(serverId, params) {
1405
+ const searchParams = new URLSearchParams();
1406
+ if (params?.version) {
1407
+ searchParams.set("version", params.version);
1408
+ }
1409
+ const queryString = searchParams.toString();
1410
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1411
+ }
1412
+ /**
1413
+ * Retrieves a list of tools for a specific MCP server.
1414
+ * @param serverId - The ID of the MCP server.
1415
+ * @returns Promise containing the list of tools.
1416
+ */
1417
+ getMcpServerTools(serverId) {
1418
+ return this.request(`/api/mcp/${serverId}/tools`);
1419
+ }
1420
+ /**
1421
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1422
+ * This instance can then be used to fetch details or execute the tool.
1423
+ * @param serverId - The ID of the MCP server.
1424
+ * @param toolId - The ID of the tool.
1425
+ * @returns MCPTool instance.
1426
+ */
1427
+ getMcpServerTool(serverId, toolId) {
1428
+ return new MCPTool(this.options, serverId, toolId);
1429
+ }
1430
+ /**
1431
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1432
+ * @param agentId - ID of the agent to interact with
1433
+ * @returns A2A client instance
1434
+ */
1435
+ getA2A(agentId) {
1436
+ return new A2A(this.options, agentId);
1437
+ }
1146
1438
  };
1147
1439
 
1148
1440
  exports.MastraClient = MastraClient;