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

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