@mastra/client-js 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-inject-middleware-20250528213451

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,8 +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
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)
305
347
  };
306
348
  return this.request(`/api/agents/${this.agentId}/generate`, {
307
349
  method: "POST",
@@ -316,8 +358,9 @@ var Agent = class extends BaseResource {
316
358
  async stream(params) {
317
359
  const processedParams = {
318
360
  ...params,
319
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
320
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
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)
321
364
  };
322
365
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
323
366
  method: "POST",
@@ -343,6 +386,22 @@ var Agent = class extends BaseResource {
343
386
  getTool(toolId) {
344
387
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
345
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
+ }
346
405
  /**
347
406
  * Retrieves evaluation results for the agent
348
407
  * @returns Promise containing agent evaluations
@@ -378,8 +437,8 @@ var Network = class extends BaseResource {
378
437
  generate(params) {
379
438
  const processedParams = {
380
439
  ...params,
381
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
382
- 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)
383
442
  };
384
443
  return this.request(`/api/networks/${this.networkId}/generate`, {
385
444
  method: "POST",
@@ -394,8 +453,8 @@ var Network = class extends BaseResource {
394
453
  async stream(params) {
395
454
  const processedParams = {
396
455
  ...params,
397
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
398
- 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)
399
458
  };
400
459
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
401
460
  method: "POST",
@@ -451,10 +510,15 @@ var MemoryThread = class extends BaseResource {
451
510
  }
452
511
  /**
453
512
  * Retrieves messages associated with the thread
513
+ * @param params - Optional parameters including limit for number of messages to retrieve
454
514
  * @returns Promise containing thread messages and UI messages
455
515
  */
456
- getMessages() {
457
- 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()}`);
458
522
  }
459
523
  };
460
524
 
@@ -524,24 +588,24 @@ var Vector = class extends BaseResource {
524
588
  }
525
589
  };
526
590
 
527
- // src/resources/workflow.ts
591
+ // src/resources/legacy-workflow.ts
528
592
  var RECORD_SEPARATOR = "";
529
- var Workflow = class extends BaseResource {
593
+ var LegacyWorkflow = class extends BaseResource {
530
594
  constructor(options, workflowId) {
531
595
  super(options);
532
596
  this.workflowId = workflowId;
533
597
  }
534
598
  /**
535
- * Retrieves details about the workflow
536
- * @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
537
601
  */
538
602
  details() {
539
- return this.request(`/api/workflows/${this.workflowId}`);
603
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
540
604
  }
541
605
  /**
542
- * Retrieves all runs for a workflow
606
+ * Retrieves all runs for a legacy workflow
543
607
  * @param params - Parameters for filtering runs
544
- * @returns Promise containing workflow runs array
608
+ * @returns Promise containing legacy workflow runs array
545
609
  */
546
610
  runs(params) {
547
611
  const searchParams = new URLSearchParams();
@@ -561,25 +625,13 @@ var Workflow = class extends BaseResource {
561
625
  searchParams.set("resourceId", params.resourceId);
562
626
  }
563
627
  if (searchParams.size) {
564
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
628
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
565
629
  } else {
566
- return this.request(`/api/workflows/${this.workflowId}/runs`);
630
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
567
631
  }
568
632
  }
569
633
  /**
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
634
+ * Creates a new legacy workflow run
583
635
  * @returns Promise containing the generated run ID
584
636
  */
585
637
  createRun(params) {
@@ -587,34 +639,34 @@ var Workflow = class extends BaseResource {
587
639
  if (!!params?.runId) {
588
640
  searchParams.set("runId", params.runId);
589
641
  }
590
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
642
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
591
643
  method: "POST"
592
644
  });
593
645
  }
594
646
  /**
595
- * 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
596
648
  * @param params - Object containing the runId and triggerData
597
649
  * @returns Promise containing success message
598
650
  */
599
651
  start(params) {
600
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
652
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
601
653
  method: "POST",
602
654
  body: params?.triggerData
603
655
  });
604
656
  }
605
657
  /**
606
- * 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
607
659
  * @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
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
611
663
  */
612
664
  resume({
613
665
  stepId,
614
666
  runId,
615
667
  context
616
668
  }) {
617
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
669
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
618
670
  method: "POST",
619
671
  body: {
620
672
  stepId,
@@ -632,18 +684,18 @@ var Workflow = class extends BaseResource {
632
684
  if (!!params?.runId) {
633
685
  searchParams.set("runId", params.runId);
634
686
  }
635
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
687
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
636
688
  method: "POST",
637
689
  body: params?.triggerData
638
690
  });
639
691
  }
640
692
  /**
641
- * 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
642
694
  * @param params - Object containing the runId, stepId, and context
643
695
  * @returns Promise containing the workflow resume results
644
696
  */
645
697
  resumeAsync(params) {
646
- 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}`, {
647
699
  method: "POST",
648
700
  body: {
649
701
  stepId: params.stepId,
@@ -697,16 +749,16 @@ var Workflow = class extends BaseResource {
697
749
  }
698
750
  }
699
751
  /**
700
- * Watches workflow transitions in real-time
752
+ * Watches legacy workflow transitions in real-time
701
753
  * @param runId - Optional run ID to filter the watch stream
702
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
754
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
703
755
  */
704
756
  async watch({ runId }, onRecord) {
705
- 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}`, {
706
758
  stream: true
707
759
  });
708
760
  if (!response.ok) {
709
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
761
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
710
762
  }
711
763
  if (!response.body) {
712
764
  throw new Error("Response body is null");
@@ -740,22 +792,26 @@ var Tool = class extends BaseResource {
740
792
  if (params.runId) {
741
793
  url.set("runId", params.runId);
742
794
  }
795
+ const body = {
796
+ data: params.data,
797
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
798
+ };
743
799
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
744
800
  method: "POST",
745
- body: params.data
801
+ body
746
802
  });
747
803
  }
748
804
  };
749
805
 
750
- // src/resources/vnext-workflow.ts
806
+ // src/resources/workflow.ts
751
807
  var RECORD_SEPARATOR2 = "";
752
- var VNextWorkflow = class extends BaseResource {
808
+ var Workflow = class extends BaseResource {
753
809
  constructor(options, workflowId) {
754
810
  super(options);
755
811
  this.workflowId = workflowId;
756
812
  }
757
813
  /**
758
- * 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
759
815
  * separated by the Record Separator character (\x1E)
760
816
  *
761
817
  * @param stream - The readable stream to process
@@ -800,16 +856,16 @@ var VNextWorkflow = class extends BaseResource {
800
856
  }
801
857
  }
802
858
  /**
803
- * Retrieves details about the vNext workflow
804
- * @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
805
861
  */
806
862
  details() {
807
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
863
+ return this.request(`/api/workflows/${this.workflowId}`);
808
864
  }
809
865
  /**
810
- * Retrieves all runs for a vNext workflow
866
+ * Retrieves all runs for a workflow
811
867
  * @param params - Parameters for filtering runs
812
- * @returns Promise containing vNext workflow runs array
868
+ * @returns Promise containing workflow runs array
813
869
  */
814
870
  runs(params) {
815
871
  const searchParams = new URLSearchParams();
@@ -829,13 +885,13 @@ var VNextWorkflow = class extends BaseResource {
829
885
  searchParams.set("resourceId", params.resourceId);
830
886
  }
831
887
  if (searchParams.size) {
832
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
888
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
833
889
  } else {
834
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
890
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
835
891
  }
836
892
  }
837
893
  /**
838
- * Creates a new vNext workflow run
894
+ * Creates a new workflow run
839
895
  * @param params - Optional object containing the optional runId
840
896
  * @returns Promise containing the runId of the created run
841
897
  */
@@ -844,23 +900,24 @@ var VNextWorkflow = class extends BaseResource {
844
900
  if (!!params?.runId) {
845
901
  searchParams.set("runId", params.runId);
846
902
  }
847
- 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()}`, {
848
904
  method: "POST"
849
905
  });
850
906
  }
851
907
  /**
852
- * 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
853
909
  * @param params - Object containing the runId, inputData and runtimeContext
854
910
  * @returns Promise containing success message
855
911
  */
856
912
  start(params) {
857
- 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}`, {
858
915
  method: "POST",
859
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
916
+ body: { inputData: params?.inputData, runtimeContext }
860
917
  });
861
918
  }
862
919
  /**
863
- * 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
864
921
  * @param params - Object containing the runId, step, resumeData and runtimeContext
865
922
  * @returns Promise containing success message
866
923
  */
@@ -868,9 +925,10 @@ var VNextWorkflow = class extends BaseResource {
868
925
  step,
869
926
  runId,
870
927
  resumeData,
871
- runtimeContext
928
+ ...rest
872
929
  }) {
873
- 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}`, {
874
932
  method: "POST",
875
933
  stream: true,
876
934
  body: {
@@ -881,54 +939,238 @@ var VNextWorkflow = class extends BaseResource {
881
939
  });
882
940
  }
883
941
  /**
884
- * 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
885
943
  * @param params - Object containing the optional runId, inputData and runtimeContext
886
- * @returns Promise containing the vNext workflow execution results
944
+ * @returns Promise containing the workflow execution results
887
945
  */
888
946
  startAsync(params) {
889
947
  const searchParams = new URLSearchParams();
890
948
  if (!!params?.runId) {
891
949
  searchParams.set("runId", params.runId);
892
950
  }
893
- 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()}`, {
894
953
  method: "POST",
895
- 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
+ }
896
1001
  });
1002
+ return response.body.pipeThrough(transformStream);
897
1003
  }
898
1004
  /**
899
- * 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
900
1006
  * @param params - Object containing the runId, step, resumeData and runtimeContext
901
- * @returns Promise containing the vNext workflow resume results
1007
+ * @returns Promise containing the workflow resume results
902
1008
  */
903
1009
  resumeAsync(params) {
904
- 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}`, {
905
1012
  method: "POST",
906
1013
  body: {
907
1014
  step: params.step,
908
1015
  resumeData: params.resumeData,
909
- runtimeContext: params.runtimeContext
1016
+ runtimeContext
910
1017
  }
911
1018
  });
912
1019
  }
913
1020
  /**
914
- * Watches vNext workflow transitions in real-time
1021
+ * Watches workflow transitions in real-time
915
1022
  * @param runId - Optional run ID to filter the watch stream
916
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1023
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
917
1024
  */
918
1025
  async watch({ runId }, onRecord) {
919
- 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}`, {
920
1027
  stream: true
921
1028
  });
922
1029
  if (!response.ok) {
923
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1030
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
924
1031
  }
925
1032
  if (!response.body) {
926
1033
  throw new Error("Response body is null");
927
1034
  }
928
1035
  for await (const record of this.streamProcessor(response.body)) {
929
- onRecord(record);
1036
+ if (typeof record === "string") {
1037
+ onRecord(JSON.parse(record));
1038
+ } else {
1039
+ onRecord(record);
1040
+ }
930
1041
  }
931
1042
  }
1043
+ /**
1044
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1045
+ * serializing each as JSON and separating them with the record separator (\x1E).
1046
+ *
1047
+ * @param records - An iterable or async iterable of objects to stream
1048
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1049
+ */
1050
+ static createRecordStream(records) {
1051
+ const encoder = new TextEncoder();
1052
+ return new ReadableStream({
1053
+ async start(controller) {
1054
+ try {
1055
+ for await (const record of records) {
1056
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1057
+ controller.enqueue(encoder.encode(json));
1058
+ }
1059
+ controller.close();
1060
+ } catch (err) {
1061
+ controller.error(err);
1062
+ }
1063
+ }
1064
+ });
1065
+ }
1066
+ };
1067
+
1068
+ // src/resources/a2a.ts
1069
+ var A2A = class extends BaseResource {
1070
+ constructor(options, agentId) {
1071
+ super(options);
1072
+ this.agentId = agentId;
1073
+ }
1074
+ /**
1075
+ * Get the agent card with metadata about the agent
1076
+ * @returns Promise containing the agent card information
1077
+ */
1078
+ async getCard() {
1079
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1080
+ }
1081
+ /**
1082
+ * Send a message to the agent and get a response
1083
+ * @param params - Parameters for the task
1084
+ * @returns Promise containing the task response
1085
+ */
1086
+ async sendMessage(params) {
1087
+ const response = await this.request(`/a2a/${this.agentId}`, {
1088
+ method: "POST",
1089
+ body: {
1090
+ method: "tasks/send",
1091
+ params
1092
+ }
1093
+ });
1094
+ return { task: response.result };
1095
+ }
1096
+ /**
1097
+ * Get the status and result of a task
1098
+ * @param params - Parameters for querying the task
1099
+ * @returns Promise containing the task response
1100
+ */
1101
+ async getTask(params) {
1102
+ const response = await this.request(`/a2a/${this.agentId}`, {
1103
+ method: "POST",
1104
+ body: {
1105
+ method: "tasks/get",
1106
+ params
1107
+ }
1108
+ });
1109
+ return response.result;
1110
+ }
1111
+ /**
1112
+ * Cancel a running task
1113
+ * @param params - Parameters identifying the task to cancel
1114
+ * @returns Promise containing the task response
1115
+ */
1116
+ async cancelTask(params) {
1117
+ return this.request(`/a2a/${this.agentId}`, {
1118
+ method: "POST",
1119
+ body: {
1120
+ method: "tasks/cancel",
1121
+ params
1122
+ }
1123
+ });
1124
+ }
1125
+ /**
1126
+ * Send a message and subscribe to streaming updates (not fully implemented)
1127
+ * @param params - Parameters for the task
1128
+ * @returns Promise containing the task response
1129
+ */
1130
+ async sendAndSubscribe(params) {
1131
+ return this.request(`/a2a/${this.agentId}`, {
1132
+ method: "POST",
1133
+ body: {
1134
+ method: "tasks/sendSubscribe",
1135
+ params
1136
+ },
1137
+ stream: true
1138
+ });
1139
+ }
1140
+ };
1141
+
1142
+ // src/resources/mcp-tool.ts
1143
+ var MCPTool = class extends BaseResource {
1144
+ serverId;
1145
+ toolId;
1146
+ constructor(options, serverId, toolId) {
1147
+ super(options);
1148
+ this.serverId = serverId;
1149
+ this.toolId = toolId;
1150
+ }
1151
+ /**
1152
+ * Retrieves details about this specific tool from the MCP server.
1153
+ * @returns Promise containing the tool's information (name, description, schema).
1154
+ */
1155
+ details() {
1156
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1157
+ }
1158
+ /**
1159
+ * Executes this specific tool on the MCP server.
1160
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1161
+ * @returns Promise containing the result of the tool execution.
1162
+ */
1163
+ execute(params) {
1164
+ const body = {};
1165
+ if (params.data !== void 0) body.data = params.data;
1166
+ if (params.runtimeContext !== void 0) {
1167
+ body.runtimeContext = params.runtimeContext;
1168
+ }
1169
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1170
+ method: "POST",
1171
+ body: Object.keys(body).length > 0 ? body : void 0
1172
+ });
1173
+ }
932
1174
  };
933
1175
 
934
1176
  // src/client.ts
@@ -1023,6 +1265,21 @@ var MastraClient = class extends BaseResource {
1023
1265
  getTool(toolId) {
1024
1266
  return new Tool(this.options, toolId);
1025
1267
  }
1268
+ /**
1269
+ * Retrieves all available legacy workflows
1270
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1271
+ */
1272
+ getLegacyWorkflows() {
1273
+ return this.request("/api/workflows/legacy");
1274
+ }
1275
+ /**
1276
+ * Gets a legacy workflow instance by ID
1277
+ * @param workflowId - ID of the legacy workflow to retrieve
1278
+ * @returns Legacy Workflow instance
1279
+ */
1280
+ getLegacyWorkflow(workflowId) {
1281
+ return new LegacyWorkflow(this.options, workflowId);
1282
+ }
1026
1283
  /**
1027
1284
  * Retrieves all available workflows
1028
1285
  * @returns Promise containing map of workflow IDs to workflow details
@@ -1038,21 +1295,6 @@ var MastraClient = class extends BaseResource {
1038
1295
  getWorkflow(workflowId) {
1039
1296
  return new Workflow(this.options, workflowId);
1040
1297
  }
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
1298
  /**
1057
1299
  * Gets a vector instance by name
1058
1300
  * @param vectorName - Name of the vector to retrieve
@@ -1141,6 +1383,62 @@ var MastraClient = class extends BaseResource {
1141
1383
  getNetwork(networkId) {
1142
1384
  return new Network(this.options, networkId);
1143
1385
  }
1386
+ /**
1387
+ * Retrieves a list of available MCP servers.
1388
+ * @param params - Optional parameters for pagination (limit, offset).
1389
+ * @returns Promise containing the list of MCP servers and pagination info.
1390
+ */
1391
+ getMcpServers(params) {
1392
+ const searchParams = new URLSearchParams();
1393
+ if (params?.limit !== void 0) {
1394
+ searchParams.set("limit", String(params.limit));
1395
+ }
1396
+ if (params?.offset !== void 0) {
1397
+ searchParams.set("offset", String(params.offset));
1398
+ }
1399
+ const queryString = searchParams.toString();
1400
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1401
+ }
1402
+ /**
1403
+ * Retrieves detailed information for a specific MCP server.
1404
+ * @param serverId - The ID of the MCP server to retrieve.
1405
+ * @param params - Optional parameters, e.g., specific version.
1406
+ * @returns Promise containing the detailed MCP server information.
1407
+ */
1408
+ getMcpServerDetails(serverId, params) {
1409
+ const searchParams = new URLSearchParams();
1410
+ if (params?.version) {
1411
+ searchParams.set("version", params.version);
1412
+ }
1413
+ const queryString = searchParams.toString();
1414
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1415
+ }
1416
+ /**
1417
+ * Retrieves a list of tools for a specific MCP server.
1418
+ * @param serverId - The ID of the MCP server.
1419
+ * @returns Promise containing the list of tools.
1420
+ */
1421
+ getMcpServerTools(serverId) {
1422
+ return this.request(`/api/mcp/${serverId}/tools`);
1423
+ }
1424
+ /**
1425
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1426
+ * This instance can then be used to fetch details or execute the tool.
1427
+ * @param serverId - The ID of the MCP server.
1428
+ * @param toolId - The ID of the tool.
1429
+ * @returns MCPTool instance.
1430
+ */
1431
+ getMcpServerTool(serverId, toolId) {
1432
+ return new MCPTool(this.options, serverId, toolId);
1433
+ }
1434
+ /**
1435
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1436
+ * @param agentId - ID of the agent to interact with
1437
+ * @returns A2A client instance
1438
+ */
1439
+ getA2A(agentId) {
1440
+ return new A2A(this.options, agentId);
1441
+ }
1144
1442
  };
1145
1443
 
1146
1444
  exports.MastraClient = MastraClient;