@mastra/client-js 0.0.0-agui-20250501191909 → 0.0.0-cli-debug-20250611094457

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,9 @@ 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 { isVercelTool } from '@mastra/core/tools';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
6
8
 
7
9
  // src/adapters/agui.ts
8
10
  var AGUIAdapter = class extends AbstractAgent {
@@ -42,6 +44,7 @@ var AGUIAdapter = class extends AbstractAgent {
42
44
  )
43
45
  }).then((response) => {
44
46
  let currentMessageId = void 0;
47
+ let isInTextMessage = false;
45
48
  return response.processDataStream({
46
49
  onTextPart: (text) => {
47
50
  if (currentMessageId === void 0) {
@@ -52,6 +55,7 @@ var AGUIAdapter = class extends AbstractAgent {
52
55
  role: "assistant"
53
56
  };
54
57
  subscriber.next(message2);
58
+ isInTextMessage = true;
55
59
  }
56
60
  const message = {
57
61
  type: EventType.TEXT_MESSAGE_CONTENT,
@@ -60,14 +64,14 @@ var AGUIAdapter = class extends AbstractAgent {
60
64
  };
61
65
  subscriber.next(message);
62
66
  },
63
- onFinishMessagePart: (message) => {
64
- console.log("onFinishMessagePart", message);
67
+ onFinishMessagePart: () => {
65
68
  if (currentMessageId !== void 0) {
66
- const message2 = {
69
+ const message = {
67
70
  type: EventType.TEXT_MESSAGE_END,
68
71
  messageId: currentMessageId
69
72
  };
70
- subscriber.next(message2);
73
+ subscriber.next(message);
74
+ isInTextMessage = false;
71
75
  }
72
76
  subscriber.next({
73
77
  type: EventType.RUN_FINISHED,
@@ -78,6 +82,14 @@ var AGUIAdapter = class extends AbstractAgent {
78
82
  },
79
83
  onToolCallPart(streamPart) {
80
84
  const parentMessageId = currentMessageId || generateUUID();
85
+ if (isInTextMessage) {
86
+ const message = {
87
+ type: EventType.TEXT_MESSAGE_END,
88
+ messageId: parentMessageId
89
+ };
90
+ subscriber.next(message);
91
+ isInTextMessage = false;
92
+ }
81
93
  subscriber.next({
82
94
  type: EventType.TOOL_CALL_START,
83
95
  toolCallId: streamPart.toolCallId,
@@ -98,7 +110,7 @@ var AGUIAdapter = class extends AbstractAgent {
98
110
  }
99
111
  });
100
112
  }).catch((error) => {
101
- console.log("error", error);
113
+ console.error("error", error);
102
114
  subscriber.error(error);
103
115
  });
104
116
  return () => {
@@ -147,6 +159,17 @@ function convertMessagesToMastraMessages(messages) {
147
159
  role: "assistant",
148
160
  content: parts
149
161
  });
162
+ if (message.toolCalls?.length) {
163
+ result.push({
164
+ role: "tool",
165
+ content: message.toolCalls.map((toolCall) => ({
166
+ type: "tool-result",
167
+ toolCallId: toolCall.id,
168
+ toolName: toolCall.function.name,
169
+ result: JSON.parse(toolCall.function.arguments)
170
+ }))
171
+ });
172
+ }
150
173
  } else if (message.role === "user") {
151
174
  result.push({
152
175
  role: "user",
@@ -168,6 +191,39 @@ function convertMessagesToMastraMessages(messages) {
168
191
  }
169
192
  return result;
170
193
  }
194
+ function zodToJsonSchema(zodSchema) {
195
+ if (!(zodSchema instanceof ZodSchema)) {
196
+ return zodSchema;
197
+ }
198
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
199
+ }
200
+ function processClientTools(clientTools) {
201
+ if (!clientTools) {
202
+ return void 0;
203
+ }
204
+ return Object.fromEntries(
205
+ Object.entries(clientTools).map(([key, value]) => {
206
+ if (isVercelTool(value)) {
207
+ return [
208
+ key,
209
+ {
210
+ ...value,
211
+ parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
212
+ }
213
+ ];
214
+ } else {
215
+ return [
216
+ key,
217
+ {
218
+ ...value,
219
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
220
+ outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
221
+ }
222
+ ];
223
+ }
224
+ })
225
+ );
226
+ }
171
227
 
172
228
  // src/resources/base.ts
173
229
  var BaseResource = class {
@@ -187,7 +243,7 @@ var BaseResource = class {
187
243
  let delay = backoffMs;
188
244
  for (let attempt = 0; attempt <= retries; attempt++) {
189
245
  try {
190
- const response = await fetch(`${baseUrl}${path}`, {
246
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
191
247
  ...options,
192
248
  headers: {
193
249
  ...headers,
@@ -227,6 +283,15 @@ var BaseResource = class {
227
283
  throw lastError || new Error("Request failed");
228
284
  }
229
285
  };
286
+ function parseClientRuntimeContext(runtimeContext) {
287
+ if (runtimeContext) {
288
+ if (runtimeContext instanceof RuntimeContext) {
289
+ return Object.fromEntries(runtimeContext.entries());
290
+ }
291
+ return runtimeContext;
292
+ }
293
+ return void 0;
294
+ }
230
295
 
231
296
  // src/resources/agent.ts
232
297
  var AgentVoice = class extends BaseResource {
@@ -275,6 +340,13 @@ var AgentVoice = class extends BaseResource {
275
340
  getSpeakers() {
276
341
  return this.request(`/api/agents/${this.agentId}/voice/speakers`);
277
342
  }
343
+ /**
344
+ * Get the listener configuration for the agent's voice provider
345
+ * @returns Promise containing a check if the agent has listening capabilities
346
+ */
347
+ getListener() {
348
+ return this.request(`/api/agents/${this.agentId}/voice/listener`);
349
+ }
278
350
  };
279
351
  var Agent = class extends BaseResource {
280
352
  constructor(options, agentId) {
@@ -290,16 +362,13 @@ var Agent = class extends BaseResource {
290
362
  details() {
291
363
  return this.request(`/api/agents/${this.agentId}`);
292
364
  }
293
- /**
294
- * Generates a response from the agent
295
- * @param params - Generation parameters including prompt
296
- * @returns Promise containing the generated response
297
- */
298
365
  generate(params) {
299
366
  const processedParams = {
300
367
  ...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
368
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
369
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
370
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
371
+ clientTools: processClientTools(params.clientTools)
303
372
  };
304
373
  return this.request(`/api/agents/${this.agentId}/generate`, {
305
374
  method: "POST",
@@ -314,8 +383,10 @@ var Agent = class extends BaseResource {
314
383
  async stream(params) {
315
384
  const processedParams = {
316
385
  ...params,
317
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
318
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
386
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
387
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
388
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
389
+ clientTools: processClientTools(params.clientTools)
319
390
  };
320
391
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
321
392
  method: "POST",
@@ -341,6 +412,22 @@ var Agent = class extends BaseResource {
341
412
  getTool(toolId) {
342
413
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
343
414
  }
415
+ /**
416
+ * Executes a tool for the agent
417
+ * @param toolId - ID of the tool to execute
418
+ * @param params - Parameters required for tool execution
419
+ * @returns Promise containing the tool execution results
420
+ */
421
+ executeTool(toolId, params) {
422
+ const body = {
423
+ data: params.data,
424
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
425
+ };
426
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
427
+ method: "POST",
428
+ body
429
+ });
430
+ }
344
431
  /**
345
432
  * Retrieves evaluation results for the agent
346
433
  * @returns Promise containing agent evaluations
@@ -376,8 +463,8 @@ var Network = class extends BaseResource {
376
463
  generate(params) {
377
464
  const processedParams = {
378
465
  ...params,
379
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
380
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
466
+ output: zodToJsonSchema(params.output),
467
+ experimental_output: zodToJsonSchema(params.experimental_output)
381
468
  };
382
469
  return this.request(`/api/networks/${this.networkId}/generate`, {
383
470
  method: "POST",
@@ -392,8 +479,8 @@ var Network = class extends BaseResource {
392
479
  async stream(params) {
393
480
  const processedParams = {
394
481
  ...params,
395
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
396
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
482
+ output: zodToJsonSchema(params.output),
483
+ experimental_output: zodToJsonSchema(params.experimental_output)
397
484
  };
398
485
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
399
486
  method: "POST",
@@ -449,10 +536,15 @@ var MemoryThread = class extends BaseResource {
449
536
  }
450
537
  /**
451
538
  * Retrieves messages associated with the thread
539
+ * @param params - Optional parameters including limit for number of messages to retrieve
452
540
  * @returns Promise containing thread messages and UI messages
453
541
  */
454
- getMessages() {
455
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
542
+ getMessages(params) {
543
+ const query = new URLSearchParams({
544
+ agentId: this.agentId,
545
+ ...params?.limit ? { limit: params.limit.toString() } : {}
546
+ });
547
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
456
548
  }
457
549
  };
458
550
 
@@ -522,41 +614,50 @@ var Vector = class extends BaseResource {
522
614
  }
523
615
  };
524
616
 
525
- // src/resources/workflow.ts
617
+ // src/resources/legacy-workflow.ts
526
618
  var RECORD_SEPARATOR = "";
527
- var Workflow = class extends BaseResource {
619
+ var LegacyWorkflow = class extends BaseResource {
528
620
  constructor(options, workflowId) {
529
621
  super(options);
530
622
  this.workflowId = workflowId;
531
623
  }
532
624
  /**
533
- * Retrieves details about the workflow
534
- * @returns Promise containing workflow details including steps and graphs
625
+ * Retrieves details about the legacy workflow
626
+ * @returns Promise containing legacy workflow details including steps and graphs
535
627
  */
536
628
  details() {
537
- return this.request(`/api/workflows/${this.workflowId}`);
629
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
538
630
  }
539
631
  /**
540
- * Retrieves all runs for a workflow
541
- * @returns Promise containing workflow runs array
542
- */
543
- runs() {
544
- return this.request(`/api/workflows/${this.workflowId}/runs`);
545
- }
546
- /**
547
- * @deprecated Use `startAsync` instead
548
- * Executes the workflow with the provided parameters
549
- * @param params - Parameters required for workflow execution
550
- * @returns Promise containing the workflow execution results
632
+ * Retrieves all runs for a legacy workflow
633
+ * @param params - Parameters for filtering runs
634
+ * @returns Promise containing legacy workflow runs array
551
635
  */
552
- execute(params) {
553
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
554
- method: "POST",
555
- body: params
556
- });
636
+ runs(params) {
637
+ const searchParams = new URLSearchParams();
638
+ if (params?.fromDate) {
639
+ searchParams.set("fromDate", params.fromDate.toISOString());
640
+ }
641
+ if (params?.toDate) {
642
+ searchParams.set("toDate", params.toDate.toISOString());
643
+ }
644
+ if (params?.limit) {
645
+ searchParams.set("limit", String(params.limit));
646
+ }
647
+ if (params?.offset) {
648
+ searchParams.set("offset", String(params.offset));
649
+ }
650
+ if (params?.resourceId) {
651
+ searchParams.set("resourceId", params.resourceId);
652
+ }
653
+ if (searchParams.size) {
654
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
655
+ } else {
656
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
657
+ }
557
658
  }
558
659
  /**
559
- * Creates a new workflow run
660
+ * Creates a new legacy workflow run
560
661
  * @returns Promise containing the generated run ID
561
662
  */
562
663
  createRun(params) {
@@ -564,34 +665,34 @@ var Workflow = class extends BaseResource {
564
665
  if (!!params?.runId) {
565
666
  searchParams.set("runId", params.runId);
566
667
  }
567
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
668
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
568
669
  method: "POST"
569
670
  });
570
671
  }
571
672
  /**
572
- * Starts a workflow run synchronously without waiting for the workflow to complete
673
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
573
674
  * @param params - Object containing the runId and triggerData
574
675
  * @returns Promise containing success message
575
676
  */
576
677
  start(params) {
577
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
678
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
578
679
  method: "POST",
579
680
  body: params?.triggerData
580
681
  });
581
682
  }
582
683
  /**
583
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
684
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
584
685
  * @param stepId - ID of the step to resume
585
- * @param runId - ID of the workflow run
586
- * @param context - Context to resume the workflow with
587
- * @returns Promise containing the workflow resume results
686
+ * @param runId - ID of the legacy workflow run
687
+ * @param context - Context to resume the legacy workflow with
688
+ * @returns Promise containing the legacy workflow resume results
588
689
  */
589
690
  resume({
590
691
  stepId,
591
692
  runId,
592
693
  context
593
694
  }) {
594
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
695
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
595
696
  method: "POST",
596
697
  body: {
597
698
  stepId,
@@ -609,18 +710,18 @@ var Workflow = class extends BaseResource {
609
710
  if (!!params?.runId) {
610
711
  searchParams.set("runId", params.runId);
611
712
  }
612
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
713
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
613
714
  method: "POST",
614
715
  body: params?.triggerData
615
716
  });
616
717
  }
617
718
  /**
618
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
719
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
619
720
  * @param params - Object containing the runId, stepId, and context
620
721
  * @returns Promise containing the workflow resume results
621
722
  */
622
723
  resumeAsync(params) {
623
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
724
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
624
725
  method: "POST",
625
726
  body: {
626
727
  stepId: params.stepId,
@@ -674,16 +775,16 @@ var Workflow = class extends BaseResource {
674
775
  }
675
776
  }
676
777
  /**
677
- * Watches workflow transitions in real-time
778
+ * Watches legacy workflow transitions in real-time
678
779
  * @param runId - Optional run ID to filter the watch stream
679
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
780
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
680
781
  */
681
782
  async watch({ runId }, onRecord) {
682
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
783
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
683
784
  stream: true
684
785
  });
685
786
  if (!response.ok) {
686
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
787
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
687
788
  }
688
789
  if (!response.body) {
689
790
  throw new Error("Response body is null");
@@ -717,22 +818,26 @@ var Tool = class extends BaseResource {
717
818
  if (params.runId) {
718
819
  url.set("runId", params.runId);
719
820
  }
821
+ const body = {
822
+ data: params.data,
823
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
824
+ };
720
825
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
721
826
  method: "POST",
722
- body: params.data
827
+ body
723
828
  });
724
829
  }
725
830
  };
726
831
 
727
- // src/resources/vnext-workflow.ts
832
+ // src/resources/workflow.ts
728
833
  var RECORD_SEPARATOR2 = "";
729
- var VNextWorkflow = class extends BaseResource {
834
+ var Workflow = class extends BaseResource {
730
835
  constructor(options, workflowId) {
731
836
  super(options);
732
837
  this.workflowId = workflowId;
733
838
  }
734
839
  /**
735
- * Creates an async generator that processes a readable stream and yields vNext workflow records
840
+ * Creates an async generator that processes a readable stream and yields workflow records
736
841
  * separated by the Record Separator character (\x1E)
737
842
  *
738
843
  * @param stream - The readable stream to process
@@ -777,21 +882,42 @@ var VNextWorkflow = class extends BaseResource {
777
882
  }
778
883
  }
779
884
  /**
780
- * Retrieves details about the vNext workflow
781
- * @returns Promise containing vNext workflow details including steps and graphs
885
+ * Retrieves details about the workflow
886
+ * @returns Promise containing workflow details including steps and graphs
782
887
  */
783
888
  details() {
784
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
889
+ return this.request(`/api/workflows/${this.workflowId}`);
785
890
  }
786
891
  /**
787
- * Retrieves all runs for a vNext workflow
788
- * @returns Promise containing vNext workflow runs array
892
+ * Retrieves all runs for a workflow
893
+ * @param params - Parameters for filtering runs
894
+ * @returns Promise containing workflow runs array
789
895
  */
790
- runs() {
791
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
896
+ runs(params) {
897
+ const searchParams = new URLSearchParams();
898
+ if (params?.fromDate) {
899
+ searchParams.set("fromDate", params.fromDate.toISOString());
900
+ }
901
+ if (params?.toDate) {
902
+ searchParams.set("toDate", params.toDate.toISOString());
903
+ }
904
+ if (params?.limit) {
905
+ searchParams.set("limit", String(params.limit));
906
+ }
907
+ if (params?.offset) {
908
+ searchParams.set("offset", String(params.offset));
909
+ }
910
+ if (params?.resourceId) {
911
+ searchParams.set("resourceId", params.resourceId);
912
+ }
913
+ if (searchParams.size) {
914
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
915
+ } else {
916
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
917
+ }
792
918
  }
793
919
  /**
794
- * Creates a new vNext workflow run
920
+ * Creates a new workflow run
795
921
  * @param params - Optional object containing the optional runId
796
922
  * @returns Promise containing the runId of the created run
797
923
  */
@@ -800,23 +926,24 @@ var VNextWorkflow = class extends BaseResource {
800
926
  if (!!params?.runId) {
801
927
  searchParams.set("runId", params.runId);
802
928
  }
803
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
929
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
804
930
  method: "POST"
805
931
  });
806
932
  }
807
933
  /**
808
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
934
+ * Starts a workflow run synchronously without waiting for the workflow to complete
809
935
  * @param params - Object containing the runId, inputData and runtimeContext
810
936
  * @returns Promise containing success message
811
937
  */
812
938
  start(params) {
813
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
939
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
940
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
814
941
  method: "POST",
815
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
942
+ body: { inputData: params?.inputData, runtimeContext }
816
943
  });
817
944
  }
818
945
  /**
819
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
946
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
820
947
  * @param params - Object containing the runId, step, resumeData and runtimeContext
821
948
  * @returns Promise containing success message
822
949
  */
@@ -824,9 +951,10 @@ var VNextWorkflow = class extends BaseResource {
824
951
  step,
825
952
  runId,
826
953
  resumeData,
827
- runtimeContext
954
+ ...rest
828
955
  }) {
829
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
956
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
957
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
830
958
  method: "POST",
831
959
  stream: true,
832
960
  body: {
@@ -837,53 +965,237 @@ var VNextWorkflow = class extends BaseResource {
837
965
  });
838
966
  }
839
967
  /**
840
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
968
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
841
969
  * @param params - Object containing the optional runId, inputData and runtimeContext
842
- * @returns Promise containing the vNext workflow execution results
970
+ * @returns Promise containing the workflow execution results
843
971
  */
844
972
  startAsync(params) {
845
973
  const searchParams = new URLSearchParams();
846
974
  if (!!params?.runId) {
847
975
  searchParams.set("runId", params.runId);
848
976
  }
849
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
977
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
978
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
850
979
  method: "POST",
851
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
980
+ body: { inputData: params.inputData, runtimeContext }
981
+ });
982
+ }
983
+ /**
984
+ * Starts a vNext workflow run and returns a stream
985
+ * @param params - Object containing the optional runId, inputData and runtimeContext
986
+ * @returns Promise containing the vNext workflow execution results
987
+ */
988
+ async stream(params) {
989
+ const searchParams = new URLSearchParams();
990
+ if (!!params?.runId) {
991
+ searchParams.set("runId", params.runId);
992
+ }
993
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
994
+ const response = await this.request(
995
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
996
+ {
997
+ method: "POST",
998
+ body: { inputData: params.inputData, runtimeContext },
999
+ stream: true
1000
+ }
1001
+ );
1002
+ if (!response.ok) {
1003
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1004
+ }
1005
+ if (!response.body) {
1006
+ throw new Error("Response body is null");
1007
+ }
1008
+ const transformStream = new TransformStream({
1009
+ start() {
1010
+ },
1011
+ async transform(chunk, controller) {
1012
+ try {
1013
+ const decoded = new TextDecoder().decode(chunk);
1014
+ const chunks = decoded.split(RECORD_SEPARATOR2);
1015
+ for (const chunk2 of chunks) {
1016
+ if (chunk2) {
1017
+ try {
1018
+ const parsedChunk = JSON.parse(chunk2);
1019
+ controller.enqueue(parsedChunk);
1020
+ } catch {
1021
+ }
1022
+ }
1023
+ }
1024
+ } catch {
1025
+ }
1026
+ }
852
1027
  });
1028
+ return response.body.pipeThrough(transformStream);
853
1029
  }
854
1030
  /**
855
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1031
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
856
1032
  * @param params - Object containing the runId, step, resumeData and runtimeContext
857
- * @returns Promise containing the vNext workflow resume results
1033
+ * @returns Promise containing the workflow resume results
858
1034
  */
859
1035
  resumeAsync(params) {
860
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1036
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1037
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
861
1038
  method: "POST",
862
1039
  body: {
863
1040
  step: params.step,
864
1041
  resumeData: params.resumeData,
865
- runtimeContext: params.runtimeContext
1042
+ runtimeContext
866
1043
  }
867
1044
  });
868
1045
  }
869
1046
  /**
870
- * Watches vNext workflow transitions in real-time
1047
+ * Watches workflow transitions in real-time
871
1048
  * @param runId - Optional run ID to filter the watch stream
872
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1049
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
873
1050
  */
874
1051
  async watch({ runId }, onRecord) {
875
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1052
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
876
1053
  stream: true
877
1054
  });
878
1055
  if (!response.ok) {
879
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1056
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
880
1057
  }
881
1058
  if (!response.body) {
882
1059
  throw new Error("Response body is null");
883
1060
  }
884
1061
  for await (const record of this.streamProcessor(response.body)) {
885
- onRecord(record);
1062
+ if (typeof record === "string") {
1063
+ onRecord(JSON.parse(record));
1064
+ } else {
1065
+ onRecord(record);
1066
+ }
1067
+ }
1068
+ }
1069
+ /**
1070
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1071
+ * serializing each as JSON and separating them with the record separator (\x1E).
1072
+ *
1073
+ * @param records - An iterable or async iterable of objects to stream
1074
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1075
+ */
1076
+ static createRecordStream(records) {
1077
+ const encoder = new TextEncoder();
1078
+ return new ReadableStream({
1079
+ async start(controller) {
1080
+ try {
1081
+ for await (const record of records) {
1082
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1083
+ controller.enqueue(encoder.encode(json));
1084
+ }
1085
+ controller.close();
1086
+ } catch (err) {
1087
+ controller.error(err);
1088
+ }
1089
+ }
1090
+ });
1091
+ }
1092
+ };
1093
+
1094
+ // src/resources/a2a.ts
1095
+ var A2A = class extends BaseResource {
1096
+ constructor(options, agentId) {
1097
+ super(options);
1098
+ this.agentId = agentId;
1099
+ }
1100
+ /**
1101
+ * Get the agent card with metadata about the agent
1102
+ * @returns Promise containing the agent card information
1103
+ */
1104
+ async getCard() {
1105
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1106
+ }
1107
+ /**
1108
+ * Send a message to the agent and get a response
1109
+ * @param params - Parameters for the task
1110
+ * @returns Promise containing the task response
1111
+ */
1112
+ async sendMessage(params) {
1113
+ const response = await this.request(`/a2a/${this.agentId}`, {
1114
+ method: "POST",
1115
+ body: {
1116
+ method: "tasks/send",
1117
+ params
1118
+ }
1119
+ });
1120
+ return { task: response.result };
1121
+ }
1122
+ /**
1123
+ * Get the status and result of a task
1124
+ * @param params - Parameters for querying the task
1125
+ * @returns Promise containing the task response
1126
+ */
1127
+ async getTask(params) {
1128
+ const response = await this.request(`/a2a/${this.agentId}`, {
1129
+ method: "POST",
1130
+ body: {
1131
+ method: "tasks/get",
1132
+ params
1133
+ }
1134
+ });
1135
+ return response.result;
1136
+ }
1137
+ /**
1138
+ * Cancel a running task
1139
+ * @param params - Parameters identifying the task to cancel
1140
+ * @returns Promise containing the task response
1141
+ */
1142
+ async cancelTask(params) {
1143
+ return this.request(`/a2a/${this.agentId}`, {
1144
+ method: "POST",
1145
+ body: {
1146
+ method: "tasks/cancel",
1147
+ params
1148
+ }
1149
+ });
1150
+ }
1151
+ /**
1152
+ * Send a message and subscribe to streaming updates (not fully implemented)
1153
+ * @param params - Parameters for the task
1154
+ * @returns Promise containing the task response
1155
+ */
1156
+ async sendAndSubscribe(params) {
1157
+ return this.request(`/a2a/${this.agentId}`, {
1158
+ method: "POST",
1159
+ body: {
1160
+ method: "tasks/sendSubscribe",
1161
+ params
1162
+ },
1163
+ stream: true
1164
+ });
1165
+ }
1166
+ };
1167
+
1168
+ // src/resources/mcp-tool.ts
1169
+ var MCPTool = class extends BaseResource {
1170
+ serverId;
1171
+ toolId;
1172
+ constructor(options, serverId, toolId) {
1173
+ super(options);
1174
+ this.serverId = serverId;
1175
+ this.toolId = toolId;
1176
+ }
1177
+ /**
1178
+ * Retrieves details about this specific tool from the MCP server.
1179
+ * @returns Promise containing the tool's information (name, description, schema).
1180
+ */
1181
+ details() {
1182
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1183
+ }
1184
+ /**
1185
+ * Executes this specific tool on the MCP server.
1186
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1187
+ * @returns Promise containing the result of the tool execution.
1188
+ */
1189
+ execute(params) {
1190
+ const body = {};
1191
+ if (params.data !== void 0) body.data = params.data;
1192
+ if (params.runtimeContext !== void 0) {
1193
+ body.runtimeContext = params.runtimeContext;
886
1194
  }
1195
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1196
+ method: "POST",
1197
+ body: Object.keys(body).length > 0 ? body : void 0
1198
+ });
887
1199
  }
888
1200
  };
889
1201
 
@@ -979,6 +1291,21 @@ var MastraClient = class extends BaseResource {
979
1291
  getTool(toolId) {
980
1292
  return new Tool(this.options, toolId);
981
1293
  }
1294
+ /**
1295
+ * Retrieves all available legacy workflows
1296
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1297
+ */
1298
+ getLegacyWorkflows() {
1299
+ return this.request("/api/workflows/legacy");
1300
+ }
1301
+ /**
1302
+ * Gets a legacy workflow instance by ID
1303
+ * @param workflowId - ID of the legacy workflow to retrieve
1304
+ * @returns Legacy Workflow instance
1305
+ */
1306
+ getLegacyWorkflow(workflowId) {
1307
+ return new LegacyWorkflow(this.options, workflowId);
1308
+ }
982
1309
  /**
983
1310
  * Retrieves all available workflows
984
1311
  * @returns Promise containing map of workflow IDs to workflow details
@@ -994,21 +1321,6 @@ var MastraClient = class extends BaseResource {
994
1321
  getWorkflow(workflowId) {
995
1322
  return new Workflow(this.options, workflowId);
996
1323
  }
997
- /**
998
- * Retrieves all available vNext workflows
999
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
1000
- */
1001
- getVNextWorkflows() {
1002
- return this.request("/api/workflows/v-next");
1003
- }
1004
- /**
1005
- * Gets a vNext workflow instance by ID
1006
- * @param workflowId - ID of the vNext workflow to retrieve
1007
- * @returns vNext Workflow instance
1008
- */
1009
- getVNextWorkflow(workflowId) {
1010
- return new VNextWorkflow(this.options, workflowId);
1011
- }
1012
1324
  /**
1013
1325
  * Gets a vector instance by name
1014
1326
  * @param vectorName - Name of the vector to retrieve
@@ -1023,7 +1335,41 @@ var MastraClient = class extends BaseResource {
1023
1335
  * @returns Promise containing array of log messages
1024
1336
  */
1025
1337
  getLogs(params) {
1026
- return this.request(`/api/logs?transportId=${params.transportId}`);
1338
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1339
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1340
+ const searchParams = new URLSearchParams();
1341
+ if (transportId) {
1342
+ searchParams.set("transportId", transportId);
1343
+ }
1344
+ if (fromDate) {
1345
+ searchParams.set("fromDate", fromDate.toISOString());
1346
+ }
1347
+ if (toDate) {
1348
+ searchParams.set("toDate", toDate.toISOString());
1349
+ }
1350
+ if (logLevel) {
1351
+ searchParams.set("logLevel", logLevel);
1352
+ }
1353
+ if (page) {
1354
+ searchParams.set("page", String(page));
1355
+ }
1356
+ if (perPage) {
1357
+ searchParams.set("perPage", String(perPage));
1358
+ }
1359
+ if (_filters) {
1360
+ if (Array.isArray(_filters)) {
1361
+ for (const filter of _filters) {
1362
+ searchParams.append("filters", filter);
1363
+ }
1364
+ } else {
1365
+ searchParams.set("filters", _filters);
1366
+ }
1367
+ }
1368
+ if (searchParams.size) {
1369
+ return this.request(`/api/logs?${searchParams}`);
1370
+ } else {
1371
+ return this.request(`/api/logs`);
1372
+ }
1027
1373
  }
1028
1374
  /**
1029
1375
  * Gets logs for a specific run
@@ -1031,7 +1377,44 @@ var MastraClient = class extends BaseResource {
1031
1377
  * @returns Promise containing array of log messages
1032
1378
  */
1033
1379
  getLogForRun(params) {
1034
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
1380
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1381
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1382
+ const searchParams = new URLSearchParams();
1383
+ if (runId) {
1384
+ searchParams.set("runId", runId);
1385
+ }
1386
+ if (transportId) {
1387
+ searchParams.set("transportId", transportId);
1388
+ }
1389
+ if (fromDate) {
1390
+ searchParams.set("fromDate", fromDate.toISOString());
1391
+ }
1392
+ if (toDate) {
1393
+ searchParams.set("toDate", toDate.toISOString());
1394
+ }
1395
+ if (logLevel) {
1396
+ searchParams.set("logLevel", logLevel);
1397
+ }
1398
+ if (page) {
1399
+ searchParams.set("page", String(page));
1400
+ }
1401
+ if (perPage) {
1402
+ searchParams.set("perPage", String(perPage));
1403
+ }
1404
+ if (_filters) {
1405
+ if (Array.isArray(_filters)) {
1406
+ for (const filter of _filters) {
1407
+ searchParams.append("filters", filter);
1408
+ }
1409
+ } else {
1410
+ searchParams.set("filters", _filters);
1411
+ }
1412
+ }
1413
+ if (searchParams.size) {
1414
+ return this.request(`/api/logs/${runId}?${searchParams}`);
1415
+ } else {
1416
+ return this.request(`/api/logs/${runId}`);
1417
+ }
1035
1418
  }
1036
1419
  /**
1037
1420
  * List of all log transports
@@ -1046,7 +1429,7 @@ var MastraClient = class extends BaseResource {
1046
1429
  * @returns Promise containing telemetry data
1047
1430
  */
1048
1431
  getTelemetry(params) {
1049
- const { name, scope, page, perPage, attribute } = params || {};
1432
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
1050
1433
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
1051
1434
  const searchParams = new URLSearchParams();
1052
1435
  if (name) {
@@ -1070,6 +1453,12 @@ var MastraClient = class extends BaseResource {
1070
1453
  searchParams.set("attribute", _attribute);
1071
1454
  }
1072
1455
  }
1456
+ if (fromDate) {
1457
+ searchParams.set("fromDate", fromDate.toISOString());
1458
+ }
1459
+ if (toDate) {
1460
+ searchParams.set("toDate", toDate.toISOString());
1461
+ }
1073
1462
  if (searchParams.size) {
1074
1463
  return this.request(`/api/telemetry?${searchParams}`);
1075
1464
  } else {
@@ -1091,6 +1480,62 @@ var MastraClient = class extends BaseResource {
1091
1480
  getNetwork(networkId) {
1092
1481
  return new Network(this.options, networkId);
1093
1482
  }
1483
+ /**
1484
+ * Retrieves a list of available MCP servers.
1485
+ * @param params - Optional parameters for pagination (limit, offset).
1486
+ * @returns Promise containing the list of MCP servers and pagination info.
1487
+ */
1488
+ getMcpServers(params) {
1489
+ const searchParams = new URLSearchParams();
1490
+ if (params?.limit !== void 0) {
1491
+ searchParams.set("limit", String(params.limit));
1492
+ }
1493
+ if (params?.offset !== void 0) {
1494
+ searchParams.set("offset", String(params.offset));
1495
+ }
1496
+ const queryString = searchParams.toString();
1497
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1498
+ }
1499
+ /**
1500
+ * Retrieves detailed information for a specific MCP server.
1501
+ * @param serverId - The ID of the MCP server to retrieve.
1502
+ * @param params - Optional parameters, e.g., specific version.
1503
+ * @returns Promise containing the detailed MCP server information.
1504
+ */
1505
+ getMcpServerDetails(serverId, params) {
1506
+ const searchParams = new URLSearchParams();
1507
+ if (params?.version) {
1508
+ searchParams.set("version", params.version);
1509
+ }
1510
+ const queryString = searchParams.toString();
1511
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1512
+ }
1513
+ /**
1514
+ * Retrieves a list of tools for a specific MCP server.
1515
+ * @param serverId - The ID of the MCP server.
1516
+ * @returns Promise containing the list of tools.
1517
+ */
1518
+ getMcpServerTools(serverId) {
1519
+ return this.request(`/api/mcp/${serverId}/tools`);
1520
+ }
1521
+ /**
1522
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1523
+ * This instance can then be used to fetch details or execute the tool.
1524
+ * @param serverId - The ID of the MCP server.
1525
+ * @param toolId - The ID of the tool.
1526
+ * @returns MCPTool instance.
1527
+ */
1528
+ getMcpServerTool(serverId, toolId) {
1529
+ return new MCPTool(this.options, serverId, toolId);
1530
+ }
1531
+ /**
1532
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1533
+ * @param agentId - ID of the agent to interact with
1534
+ * @returns A2A client instance
1535
+ */
1536
+ getA2A(agentId) {
1537
+ return new A2A(this.options, agentId);
1538
+ }
1094
1539
  };
1095
1540
 
1096
1541
  export { MastraClient };