@mastra/client-js 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-generate-title-20250616171351

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,24 +614,24 @@ 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
632
+ * Retrieves all runs for a legacy workflow
541
633
  * @param params - Parameters for filtering runs
542
- * @returns Promise containing workflow runs array
634
+ * @returns Promise containing legacy workflow runs array
543
635
  */
544
636
  runs(params) {
545
637
  const searchParams = new URLSearchParams();
@@ -559,25 +651,13 @@ var Workflow = class extends BaseResource {
559
651
  searchParams.set("resourceId", params.resourceId);
560
652
  }
561
653
  if (searchParams.size) {
562
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
654
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
563
655
  } else {
564
- return this.request(`/api/workflows/${this.workflowId}/runs`);
656
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
565
657
  }
566
658
  }
567
659
  /**
568
- * @deprecated Use `startAsync` instead
569
- * Executes the workflow with the provided parameters
570
- * @param params - Parameters required for workflow execution
571
- * @returns Promise containing the workflow execution results
572
- */
573
- execute(params) {
574
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
575
- method: "POST",
576
- body: params
577
- });
578
- }
579
- /**
580
- * Creates a new workflow run
660
+ * Creates a new legacy workflow run
581
661
  * @returns Promise containing the generated run ID
582
662
  */
583
663
  createRun(params) {
@@ -585,34 +665,34 @@ var Workflow = class extends BaseResource {
585
665
  if (!!params?.runId) {
586
666
  searchParams.set("runId", params.runId);
587
667
  }
588
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
668
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
589
669
  method: "POST"
590
670
  });
591
671
  }
592
672
  /**
593
- * 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
594
674
  * @param params - Object containing the runId and triggerData
595
675
  * @returns Promise containing success message
596
676
  */
597
677
  start(params) {
598
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
678
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
599
679
  method: "POST",
600
680
  body: params?.triggerData
601
681
  });
602
682
  }
603
683
  /**
604
- * 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
605
685
  * @param stepId - ID of the step to resume
606
- * @param runId - ID of the workflow run
607
- * @param context - Context to resume the workflow with
608
- * @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
609
689
  */
610
690
  resume({
611
691
  stepId,
612
692
  runId,
613
693
  context
614
694
  }) {
615
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
695
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
616
696
  method: "POST",
617
697
  body: {
618
698
  stepId,
@@ -630,18 +710,18 @@ var Workflow = class extends BaseResource {
630
710
  if (!!params?.runId) {
631
711
  searchParams.set("runId", params.runId);
632
712
  }
633
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
713
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
634
714
  method: "POST",
635
715
  body: params?.triggerData
636
716
  });
637
717
  }
638
718
  /**
639
- * 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
640
720
  * @param params - Object containing the runId, stepId, and context
641
721
  * @returns Promise containing the workflow resume results
642
722
  */
643
723
  resumeAsync(params) {
644
- 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}`, {
645
725
  method: "POST",
646
726
  body: {
647
727
  stepId: params.stepId,
@@ -695,16 +775,16 @@ var Workflow = class extends BaseResource {
695
775
  }
696
776
  }
697
777
  /**
698
- * Watches workflow transitions in real-time
778
+ * Watches legacy workflow transitions in real-time
699
779
  * @param runId - Optional run ID to filter the watch stream
700
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
780
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
701
781
  */
702
782
  async watch({ runId }, onRecord) {
703
- 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}`, {
704
784
  stream: true
705
785
  });
706
786
  if (!response.ok) {
707
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
787
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
708
788
  }
709
789
  if (!response.body) {
710
790
  throw new Error("Response body is null");
@@ -738,22 +818,26 @@ var Tool = class extends BaseResource {
738
818
  if (params.runId) {
739
819
  url.set("runId", params.runId);
740
820
  }
821
+ const body = {
822
+ data: params.data,
823
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
824
+ };
741
825
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
742
826
  method: "POST",
743
- body: params.data
827
+ body
744
828
  });
745
829
  }
746
830
  };
747
831
 
748
- // src/resources/vnext-workflow.ts
832
+ // src/resources/workflow.ts
749
833
  var RECORD_SEPARATOR2 = "";
750
- var VNextWorkflow = class extends BaseResource {
834
+ var Workflow = class extends BaseResource {
751
835
  constructor(options, workflowId) {
752
836
  super(options);
753
837
  this.workflowId = workflowId;
754
838
  }
755
839
  /**
756
- * 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
757
841
  * separated by the Record Separator character (\x1E)
758
842
  *
759
843
  * @param stream - The readable stream to process
@@ -798,16 +882,16 @@ var VNextWorkflow = class extends BaseResource {
798
882
  }
799
883
  }
800
884
  /**
801
- * Retrieves details about the vNext workflow
802
- * @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
803
887
  */
804
888
  details() {
805
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
889
+ return this.request(`/api/workflows/${this.workflowId}`);
806
890
  }
807
891
  /**
808
- * Retrieves all runs for a vNext workflow
892
+ * Retrieves all runs for a workflow
809
893
  * @param params - Parameters for filtering runs
810
- * @returns Promise containing vNext workflow runs array
894
+ * @returns Promise containing workflow runs array
811
895
  */
812
896
  runs(params) {
813
897
  const searchParams = new URLSearchParams();
@@ -827,13 +911,29 @@ var VNextWorkflow = class extends BaseResource {
827
911
  searchParams.set("resourceId", params.resourceId);
828
912
  }
829
913
  if (searchParams.size) {
830
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
914
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
831
915
  } else {
832
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
916
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
833
917
  }
834
918
  }
835
919
  /**
836
- * Creates a new vNext workflow run
920
+ * Retrieves a specific workflow run by its ID
921
+ * @param runId - The ID of the workflow run to retrieve
922
+ * @returns Promise containing the workflow run details
923
+ */
924
+ runById(runId) {
925
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
926
+ }
927
+ /**
928
+ * Retrieves the execution result for a specific workflow run by its ID
929
+ * @param runId - The ID of the workflow run to retrieve the execution result for
930
+ * @returns Promise containing the workflow run execution result
931
+ */
932
+ runExecutionResult(runId) {
933
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
934
+ }
935
+ /**
936
+ * Creates a new workflow run
837
937
  * @param params - Optional object containing the optional runId
838
938
  * @returns Promise containing the runId of the created run
839
939
  */
@@ -842,23 +942,24 @@ var VNextWorkflow = class extends BaseResource {
842
942
  if (!!params?.runId) {
843
943
  searchParams.set("runId", params.runId);
844
944
  }
845
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
945
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
846
946
  method: "POST"
847
947
  });
848
948
  }
849
949
  /**
850
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
950
+ * Starts a workflow run synchronously without waiting for the workflow to complete
851
951
  * @param params - Object containing the runId, inputData and runtimeContext
852
952
  * @returns Promise containing success message
853
953
  */
854
954
  start(params) {
855
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
955
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
956
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
856
957
  method: "POST",
857
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
958
+ body: { inputData: params?.inputData, runtimeContext }
858
959
  });
859
960
  }
860
961
  /**
861
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
962
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
862
963
  * @param params - Object containing the runId, step, resumeData and runtimeContext
863
964
  * @returns Promise containing success message
864
965
  */
@@ -866,9 +967,10 @@ var VNextWorkflow = class extends BaseResource {
866
967
  step,
867
968
  runId,
868
969
  resumeData,
869
- runtimeContext
970
+ ...rest
870
971
  }) {
871
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
972
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
973
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
872
974
  method: "POST",
873
975
  stream: true,
874
976
  body: {
@@ -879,54 +981,238 @@ var VNextWorkflow = class extends BaseResource {
879
981
  });
880
982
  }
881
983
  /**
882
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
984
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
883
985
  * @param params - Object containing the optional runId, inputData and runtimeContext
884
- * @returns Promise containing the vNext workflow execution results
986
+ * @returns Promise containing the workflow execution results
885
987
  */
886
988
  startAsync(params) {
887
989
  const searchParams = new URLSearchParams();
888
990
  if (!!params?.runId) {
889
991
  searchParams.set("runId", params.runId);
890
992
  }
891
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
993
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
994
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
892
995
  method: "POST",
893
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
996
+ body: { inputData: params.inputData, runtimeContext }
997
+ });
998
+ }
999
+ /**
1000
+ * Starts a vNext workflow run and returns a stream
1001
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1002
+ * @returns Promise containing the vNext workflow execution results
1003
+ */
1004
+ async stream(params) {
1005
+ const searchParams = new URLSearchParams();
1006
+ if (!!params?.runId) {
1007
+ searchParams.set("runId", params.runId);
1008
+ }
1009
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1010
+ const response = await this.request(
1011
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1012
+ {
1013
+ method: "POST",
1014
+ body: { inputData: params.inputData, runtimeContext },
1015
+ stream: true
1016
+ }
1017
+ );
1018
+ if (!response.ok) {
1019
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1020
+ }
1021
+ if (!response.body) {
1022
+ throw new Error("Response body is null");
1023
+ }
1024
+ const transformStream = new TransformStream({
1025
+ start() {
1026
+ },
1027
+ async transform(chunk, controller) {
1028
+ try {
1029
+ const decoded = new TextDecoder().decode(chunk);
1030
+ const chunks = decoded.split(RECORD_SEPARATOR2);
1031
+ for (const chunk2 of chunks) {
1032
+ if (chunk2) {
1033
+ try {
1034
+ const parsedChunk = JSON.parse(chunk2);
1035
+ controller.enqueue(parsedChunk);
1036
+ } catch {
1037
+ }
1038
+ }
1039
+ }
1040
+ } catch {
1041
+ }
1042
+ }
894
1043
  });
1044
+ return response.body.pipeThrough(transformStream);
895
1045
  }
896
1046
  /**
897
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1047
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
898
1048
  * @param params - Object containing the runId, step, resumeData and runtimeContext
899
- * @returns Promise containing the vNext workflow resume results
1049
+ * @returns Promise containing the workflow resume results
900
1050
  */
901
1051
  resumeAsync(params) {
902
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1052
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1053
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
903
1054
  method: "POST",
904
1055
  body: {
905
1056
  step: params.step,
906
1057
  resumeData: params.resumeData,
907
- runtimeContext: params.runtimeContext
1058
+ runtimeContext
908
1059
  }
909
1060
  });
910
1061
  }
911
1062
  /**
912
- * Watches vNext workflow transitions in real-time
1063
+ * Watches workflow transitions in real-time
913
1064
  * @param runId - Optional run ID to filter the watch stream
914
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1065
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
915
1066
  */
916
1067
  async watch({ runId }, onRecord) {
917
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1068
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
918
1069
  stream: true
919
1070
  });
920
1071
  if (!response.ok) {
921
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1072
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
922
1073
  }
923
1074
  if (!response.body) {
924
1075
  throw new Error("Response body is null");
925
1076
  }
926
1077
  for await (const record of this.streamProcessor(response.body)) {
927
- onRecord(record);
1078
+ if (typeof record === "string") {
1079
+ onRecord(JSON.parse(record));
1080
+ } else {
1081
+ onRecord(record);
1082
+ }
928
1083
  }
929
1084
  }
1085
+ /**
1086
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1087
+ * serializing each as JSON and separating them with the record separator (\x1E).
1088
+ *
1089
+ * @param records - An iterable or async iterable of objects to stream
1090
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1091
+ */
1092
+ static createRecordStream(records) {
1093
+ const encoder = new TextEncoder();
1094
+ return new ReadableStream({
1095
+ async start(controller) {
1096
+ try {
1097
+ for await (const record of records) {
1098
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1099
+ controller.enqueue(encoder.encode(json));
1100
+ }
1101
+ controller.close();
1102
+ } catch (err) {
1103
+ controller.error(err);
1104
+ }
1105
+ }
1106
+ });
1107
+ }
1108
+ };
1109
+
1110
+ // src/resources/a2a.ts
1111
+ var A2A = class extends BaseResource {
1112
+ constructor(options, agentId) {
1113
+ super(options);
1114
+ this.agentId = agentId;
1115
+ }
1116
+ /**
1117
+ * Get the agent card with metadata about the agent
1118
+ * @returns Promise containing the agent card information
1119
+ */
1120
+ async getCard() {
1121
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1122
+ }
1123
+ /**
1124
+ * Send a message to the agent and get a response
1125
+ * @param params - Parameters for the task
1126
+ * @returns Promise containing the task response
1127
+ */
1128
+ async sendMessage(params) {
1129
+ const response = await this.request(`/a2a/${this.agentId}`, {
1130
+ method: "POST",
1131
+ body: {
1132
+ method: "tasks/send",
1133
+ params
1134
+ }
1135
+ });
1136
+ return { task: response.result };
1137
+ }
1138
+ /**
1139
+ * Get the status and result of a task
1140
+ * @param params - Parameters for querying the task
1141
+ * @returns Promise containing the task response
1142
+ */
1143
+ async getTask(params) {
1144
+ const response = await this.request(`/a2a/${this.agentId}`, {
1145
+ method: "POST",
1146
+ body: {
1147
+ method: "tasks/get",
1148
+ params
1149
+ }
1150
+ });
1151
+ return response.result;
1152
+ }
1153
+ /**
1154
+ * Cancel a running task
1155
+ * @param params - Parameters identifying the task to cancel
1156
+ * @returns Promise containing the task response
1157
+ */
1158
+ async cancelTask(params) {
1159
+ return this.request(`/a2a/${this.agentId}`, {
1160
+ method: "POST",
1161
+ body: {
1162
+ method: "tasks/cancel",
1163
+ params
1164
+ }
1165
+ });
1166
+ }
1167
+ /**
1168
+ * Send a message and subscribe to streaming updates (not fully implemented)
1169
+ * @param params - Parameters for the task
1170
+ * @returns Promise containing the task response
1171
+ */
1172
+ async sendAndSubscribe(params) {
1173
+ return this.request(`/a2a/${this.agentId}`, {
1174
+ method: "POST",
1175
+ body: {
1176
+ method: "tasks/sendSubscribe",
1177
+ params
1178
+ },
1179
+ stream: true
1180
+ });
1181
+ }
1182
+ };
1183
+
1184
+ // src/resources/mcp-tool.ts
1185
+ var MCPTool = class extends BaseResource {
1186
+ serverId;
1187
+ toolId;
1188
+ constructor(options, serverId, toolId) {
1189
+ super(options);
1190
+ this.serverId = serverId;
1191
+ this.toolId = toolId;
1192
+ }
1193
+ /**
1194
+ * Retrieves details about this specific tool from the MCP server.
1195
+ * @returns Promise containing the tool's information (name, description, schema).
1196
+ */
1197
+ details() {
1198
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1199
+ }
1200
+ /**
1201
+ * Executes this specific tool on the MCP server.
1202
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1203
+ * @returns Promise containing the result of the tool execution.
1204
+ */
1205
+ execute(params) {
1206
+ const body = {};
1207
+ if (params.data !== void 0) body.data = params.data;
1208
+ if (params.runtimeContext !== void 0) {
1209
+ body.runtimeContext = params.runtimeContext;
1210
+ }
1211
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1212
+ method: "POST",
1213
+ body: Object.keys(body).length > 0 ? body : void 0
1214
+ });
1215
+ }
930
1216
  };
931
1217
 
932
1218
  // src/client.ts
@@ -1021,6 +1307,21 @@ var MastraClient = class extends BaseResource {
1021
1307
  getTool(toolId) {
1022
1308
  return new Tool(this.options, toolId);
1023
1309
  }
1310
+ /**
1311
+ * Retrieves all available legacy workflows
1312
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1313
+ */
1314
+ getLegacyWorkflows() {
1315
+ return this.request("/api/workflows/legacy");
1316
+ }
1317
+ /**
1318
+ * Gets a legacy workflow instance by ID
1319
+ * @param workflowId - ID of the legacy workflow to retrieve
1320
+ * @returns Legacy Workflow instance
1321
+ */
1322
+ getLegacyWorkflow(workflowId) {
1323
+ return new LegacyWorkflow(this.options, workflowId);
1324
+ }
1024
1325
  /**
1025
1326
  * Retrieves all available workflows
1026
1327
  * @returns Promise containing map of workflow IDs to workflow details
@@ -1036,21 +1337,6 @@ var MastraClient = class extends BaseResource {
1036
1337
  getWorkflow(workflowId) {
1037
1338
  return new Workflow(this.options, workflowId);
1038
1339
  }
1039
- /**
1040
- * Retrieves all available vNext workflows
1041
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
1042
- */
1043
- getVNextWorkflows() {
1044
- return this.request("/api/workflows/v-next");
1045
- }
1046
- /**
1047
- * Gets a vNext workflow instance by ID
1048
- * @param workflowId - ID of the vNext workflow to retrieve
1049
- * @returns vNext Workflow instance
1050
- */
1051
- getVNextWorkflow(workflowId) {
1052
- return new VNextWorkflow(this.options, workflowId);
1053
- }
1054
1340
  /**
1055
1341
  * Gets a vector instance by name
1056
1342
  * @param vectorName - Name of the vector to retrieve
@@ -1065,7 +1351,41 @@ var MastraClient = class extends BaseResource {
1065
1351
  * @returns Promise containing array of log messages
1066
1352
  */
1067
1353
  getLogs(params) {
1068
- return this.request(`/api/logs?transportId=${params.transportId}`);
1354
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1355
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1356
+ const searchParams = new URLSearchParams();
1357
+ if (transportId) {
1358
+ searchParams.set("transportId", transportId);
1359
+ }
1360
+ if (fromDate) {
1361
+ searchParams.set("fromDate", fromDate.toISOString());
1362
+ }
1363
+ if (toDate) {
1364
+ searchParams.set("toDate", toDate.toISOString());
1365
+ }
1366
+ if (logLevel) {
1367
+ searchParams.set("logLevel", logLevel);
1368
+ }
1369
+ if (page) {
1370
+ searchParams.set("page", String(page));
1371
+ }
1372
+ if (perPage) {
1373
+ searchParams.set("perPage", String(perPage));
1374
+ }
1375
+ if (_filters) {
1376
+ if (Array.isArray(_filters)) {
1377
+ for (const filter of _filters) {
1378
+ searchParams.append("filters", filter);
1379
+ }
1380
+ } else {
1381
+ searchParams.set("filters", _filters);
1382
+ }
1383
+ }
1384
+ if (searchParams.size) {
1385
+ return this.request(`/api/logs?${searchParams}`);
1386
+ } else {
1387
+ return this.request(`/api/logs`);
1388
+ }
1069
1389
  }
1070
1390
  /**
1071
1391
  * Gets logs for a specific run
@@ -1073,7 +1393,44 @@ var MastraClient = class extends BaseResource {
1073
1393
  * @returns Promise containing array of log messages
1074
1394
  */
1075
1395
  getLogForRun(params) {
1076
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
1396
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1397
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1398
+ const searchParams = new URLSearchParams();
1399
+ if (runId) {
1400
+ searchParams.set("runId", runId);
1401
+ }
1402
+ if (transportId) {
1403
+ searchParams.set("transportId", transportId);
1404
+ }
1405
+ if (fromDate) {
1406
+ searchParams.set("fromDate", fromDate.toISOString());
1407
+ }
1408
+ if (toDate) {
1409
+ searchParams.set("toDate", toDate.toISOString());
1410
+ }
1411
+ if (logLevel) {
1412
+ searchParams.set("logLevel", logLevel);
1413
+ }
1414
+ if (page) {
1415
+ searchParams.set("page", String(page));
1416
+ }
1417
+ if (perPage) {
1418
+ searchParams.set("perPage", String(perPage));
1419
+ }
1420
+ if (_filters) {
1421
+ if (Array.isArray(_filters)) {
1422
+ for (const filter of _filters) {
1423
+ searchParams.append("filters", filter);
1424
+ }
1425
+ } else {
1426
+ searchParams.set("filters", _filters);
1427
+ }
1428
+ }
1429
+ if (searchParams.size) {
1430
+ return this.request(`/api/logs/${runId}?${searchParams}`);
1431
+ } else {
1432
+ return this.request(`/api/logs/${runId}`);
1433
+ }
1077
1434
  }
1078
1435
  /**
1079
1436
  * List of all log transports
@@ -1139,6 +1496,62 @@ var MastraClient = class extends BaseResource {
1139
1496
  getNetwork(networkId) {
1140
1497
  return new Network(this.options, networkId);
1141
1498
  }
1499
+ /**
1500
+ * Retrieves a list of available MCP servers.
1501
+ * @param params - Optional parameters for pagination (limit, offset).
1502
+ * @returns Promise containing the list of MCP servers and pagination info.
1503
+ */
1504
+ getMcpServers(params) {
1505
+ const searchParams = new URLSearchParams();
1506
+ if (params?.limit !== void 0) {
1507
+ searchParams.set("limit", String(params.limit));
1508
+ }
1509
+ if (params?.offset !== void 0) {
1510
+ searchParams.set("offset", String(params.offset));
1511
+ }
1512
+ const queryString = searchParams.toString();
1513
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1514
+ }
1515
+ /**
1516
+ * Retrieves detailed information for a specific MCP server.
1517
+ * @param serverId - The ID of the MCP server to retrieve.
1518
+ * @param params - Optional parameters, e.g., specific version.
1519
+ * @returns Promise containing the detailed MCP server information.
1520
+ */
1521
+ getMcpServerDetails(serverId, params) {
1522
+ const searchParams = new URLSearchParams();
1523
+ if (params?.version) {
1524
+ searchParams.set("version", params.version);
1525
+ }
1526
+ const queryString = searchParams.toString();
1527
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1528
+ }
1529
+ /**
1530
+ * Retrieves a list of tools for a specific MCP server.
1531
+ * @param serverId - The ID of the MCP server.
1532
+ * @returns Promise containing the list of tools.
1533
+ */
1534
+ getMcpServerTools(serverId) {
1535
+ return this.request(`/api/mcp/${serverId}/tools`);
1536
+ }
1537
+ /**
1538
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1539
+ * This instance can then be used to fetch details or execute the tool.
1540
+ * @param serverId - The ID of the MCP server.
1541
+ * @param toolId - The ID of the tool.
1542
+ * @returns MCPTool instance.
1543
+ */
1544
+ getMcpServerTool(serverId, toolId) {
1545
+ return new MCPTool(this.options, serverId, toolId);
1546
+ }
1547
+ /**
1548
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1549
+ * @param agentId - ID of the agent to interact with
1550
+ * @returns A2A client instance
1551
+ */
1552
+ getA2A(agentId) {
1553
+ return new A2A(this.options, agentId);
1554
+ }
1142
1555
  };
1143
1556
 
1144
1557
  export { MastraClient };