@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.cjs CHANGED
@@ -4,7 +4,13 @@ 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 tools = require('@mastra/core/tools');
9
+ var runtimeContext = require('@mastra/core/runtime-context');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
8
14
 
9
15
  // src/adapters/agui.ts
10
16
  var AGUIAdapter = class extends client.AbstractAgent {
@@ -44,6 +50,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
44
50
  )
45
51
  }).then((response) => {
46
52
  let currentMessageId = void 0;
53
+ let isInTextMessage = false;
47
54
  return response.processDataStream({
48
55
  onTextPart: (text) => {
49
56
  if (currentMessageId === void 0) {
@@ -54,6 +61,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
54
61
  role: "assistant"
55
62
  };
56
63
  subscriber.next(message2);
64
+ isInTextMessage = true;
57
65
  }
58
66
  const message = {
59
67
  type: client.EventType.TEXT_MESSAGE_CONTENT,
@@ -62,14 +70,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
62
70
  };
63
71
  subscriber.next(message);
64
72
  },
65
- onFinishMessagePart: (message) => {
66
- console.log("onFinishMessagePart", message);
73
+ onFinishMessagePart: () => {
67
74
  if (currentMessageId !== void 0) {
68
- const message2 = {
75
+ const message = {
69
76
  type: client.EventType.TEXT_MESSAGE_END,
70
77
  messageId: currentMessageId
71
78
  };
72
- subscriber.next(message2);
79
+ subscriber.next(message);
80
+ isInTextMessage = false;
73
81
  }
74
82
  subscriber.next({
75
83
  type: client.EventType.RUN_FINISHED,
@@ -80,6 +88,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
80
88
  },
81
89
  onToolCallPart(streamPart) {
82
90
  const parentMessageId = currentMessageId || generateUUID();
91
+ if (isInTextMessage) {
92
+ const message = {
93
+ type: client.EventType.TEXT_MESSAGE_END,
94
+ messageId: parentMessageId
95
+ };
96
+ subscriber.next(message);
97
+ isInTextMessage = false;
98
+ }
83
99
  subscriber.next({
84
100
  type: client.EventType.TOOL_CALL_START,
85
101
  toolCallId: streamPart.toolCallId,
@@ -100,7 +116,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
100
116
  }
101
117
  });
102
118
  }).catch((error) => {
103
- console.log("error", error);
119
+ console.error("error", error);
104
120
  subscriber.error(error);
105
121
  });
106
122
  return () => {
@@ -149,6 +165,17 @@ function convertMessagesToMastraMessages(messages) {
149
165
  role: "assistant",
150
166
  content: parts
151
167
  });
168
+ if (message.toolCalls?.length) {
169
+ result.push({
170
+ role: "tool",
171
+ content: message.toolCalls.map((toolCall) => ({
172
+ type: "tool-result",
173
+ toolCallId: toolCall.id,
174
+ toolName: toolCall.function.name,
175
+ result: JSON.parse(toolCall.function.arguments)
176
+ }))
177
+ });
178
+ }
152
179
  } else if (message.role === "user") {
153
180
  result.push({
154
181
  role: "user",
@@ -170,6 +197,39 @@ function convertMessagesToMastraMessages(messages) {
170
197
  }
171
198
  return result;
172
199
  }
200
+ function zodToJsonSchema(zodSchema) {
201
+ if (!(zodSchema instanceof zod.ZodSchema)) {
202
+ return zodSchema;
203
+ }
204
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
205
+ }
206
+ function processClientTools(clientTools) {
207
+ if (!clientTools) {
208
+ return void 0;
209
+ }
210
+ return Object.fromEntries(
211
+ Object.entries(clientTools).map(([key, value]) => {
212
+ if (tools.isVercelTool(value)) {
213
+ return [
214
+ key,
215
+ {
216
+ ...value,
217
+ parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
218
+ }
219
+ ];
220
+ } else {
221
+ return [
222
+ key,
223
+ {
224
+ ...value,
225
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
226
+ outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
227
+ }
228
+ ];
229
+ }
230
+ })
231
+ );
232
+ }
173
233
 
174
234
  // src/resources/base.ts
175
235
  var BaseResource = class {
@@ -189,7 +249,7 @@ var BaseResource = class {
189
249
  let delay = backoffMs;
190
250
  for (let attempt = 0; attempt <= retries; attempt++) {
191
251
  try {
192
- const response = await fetch(`${baseUrl}${path}`, {
252
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
193
253
  ...options,
194
254
  headers: {
195
255
  ...headers,
@@ -229,6 +289,15 @@ var BaseResource = class {
229
289
  throw lastError || new Error("Request failed");
230
290
  }
231
291
  };
292
+ function parseClientRuntimeContext(runtimeContext$1) {
293
+ if (runtimeContext$1) {
294
+ if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
295
+ return Object.fromEntries(runtimeContext$1.entries());
296
+ }
297
+ return runtimeContext$1;
298
+ }
299
+ return void 0;
300
+ }
232
301
 
233
302
  // src/resources/agent.ts
234
303
  var AgentVoice = class extends BaseResource {
@@ -277,6 +346,13 @@ var AgentVoice = class extends BaseResource {
277
346
  getSpeakers() {
278
347
  return this.request(`/api/agents/${this.agentId}/voice/speakers`);
279
348
  }
349
+ /**
350
+ * Get the listener configuration for the agent's voice provider
351
+ * @returns Promise containing a check if the agent has listening capabilities
352
+ */
353
+ getListener() {
354
+ return this.request(`/api/agents/${this.agentId}/voice/listener`);
355
+ }
280
356
  };
281
357
  var Agent = class extends BaseResource {
282
358
  constructor(options, agentId) {
@@ -292,16 +368,13 @@ var Agent = class extends BaseResource {
292
368
  details() {
293
369
  return this.request(`/api/agents/${this.agentId}`);
294
370
  }
295
- /**
296
- * Generates a response from the agent
297
- * @param params - Generation parameters including prompt
298
- * @returns Promise containing the generated response
299
- */
300
371
  generate(params) {
301
372
  const processedParams = {
302
373
  ...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
374
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
375
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
376
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
377
+ clientTools: processClientTools(params.clientTools)
305
378
  };
306
379
  return this.request(`/api/agents/${this.agentId}/generate`, {
307
380
  method: "POST",
@@ -316,8 +389,10 @@ var Agent = class extends BaseResource {
316
389
  async stream(params) {
317
390
  const processedParams = {
318
391
  ...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
392
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
393
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
394
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
395
+ clientTools: processClientTools(params.clientTools)
321
396
  };
322
397
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
323
398
  method: "POST",
@@ -343,6 +418,22 @@ var Agent = class extends BaseResource {
343
418
  getTool(toolId) {
344
419
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
345
420
  }
421
+ /**
422
+ * Executes a tool for the agent
423
+ * @param toolId - ID of the tool to execute
424
+ * @param params - Parameters required for tool execution
425
+ * @returns Promise containing the tool execution results
426
+ */
427
+ executeTool(toolId, params) {
428
+ const body = {
429
+ data: params.data,
430
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
431
+ };
432
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
433
+ method: "POST",
434
+ body
435
+ });
436
+ }
346
437
  /**
347
438
  * Retrieves evaluation results for the agent
348
439
  * @returns Promise containing agent evaluations
@@ -378,8 +469,8 @@ var Network = class extends BaseResource {
378
469
  generate(params) {
379
470
  const processedParams = {
380
471
  ...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
472
+ output: zodToJsonSchema(params.output),
473
+ experimental_output: zodToJsonSchema(params.experimental_output)
383
474
  };
384
475
  return this.request(`/api/networks/${this.networkId}/generate`, {
385
476
  method: "POST",
@@ -394,8 +485,8 @@ var Network = class extends BaseResource {
394
485
  async stream(params) {
395
486
  const processedParams = {
396
487
  ...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
488
+ output: zodToJsonSchema(params.output),
489
+ experimental_output: zodToJsonSchema(params.experimental_output)
399
490
  };
400
491
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
401
492
  method: "POST",
@@ -451,10 +542,15 @@ var MemoryThread = class extends BaseResource {
451
542
  }
452
543
  /**
453
544
  * Retrieves messages associated with the thread
545
+ * @param params - Optional parameters including limit for number of messages to retrieve
454
546
  * @returns Promise containing thread messages and UI messages
455
547
  */
456
- getMessages() {
457
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
548
+ getMessages(params) {
549
+ const query = new URLSearchParams({
550
+ agentId: this.agentId,
551
+ ...params?.limit ? { limit: params.limit.toString() } : {}
552
+ });
553
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
458
554
  }
459
555
  };
460
556
 
@@ -524,24 +620,24 @@ var Vector = class extends BaseResource {
524
620
  }
525
621
  };
526
622
 
527
- // src/resources/workflow.ts
623
+ // src/resources/legacy-workflow.ts
528
624
  var RECORD_SEPARATOR = "";
529
- var Workflow = class extends BaseResource {
625
+ var LegacyWorkflow = class extends BaseResource {
530
626
  constructor(options, workflowId) {
531
627
  super(options);
532
628
  this.workflowId = workflowId;
533
629
  }
534
630
  /**
535
- * Retrieves details about the workflow
536
- * @returns Promise containing workflow details including steps and graphs
631
+ * Retrieves details about the legacy workflow
632
+ * @returns Promise containing legacy workflow details including steps and graphs
537
633
  */
538
634
  details() {
539
- return this.request(`/api/workflows/${this.workflowId}`);
635
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
540
636
  }
541
637
  /**
542
- * Retrieves all runs for a workflow
638
+ * Retrieves all runs for a legacy workflow
543
639
  * @param params - Parameters for filtering runs
544
- * @returns Promise containing workflow runs array
640
+ * @returns Promise containing legacy workflow runs array
545
641
  */
546
642
  runs(params) {
547
643
  const searchParams = new URLSearchParams();
@@ -561,25 +657,13 @@ var Workflow = class extends BaseResource {
561
657
  searchParams.set("resourceId", params.resourceId);
562
658
  }
563
659
  if (searchParams.size) {
564
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
660
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
565
661
  } else {
566
- return this.request(`/api/workflows/${this.workflowId}/runs`);
662
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
567
663
  }
568
664
  }
569
665
  /**
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
666
+ * Creates a new legacy workflow run
583
667
  * @returns Promise containing the generated run ID
584
668
  */
585
669
  createRun(params) {
@@ -587,34 +671,34 @@ var Workflow = class extends BaseResource {
587
671
  if (!!params?.runId) {
588
672
  searchParams.set("runId", params.runId);
589
673
  }
590
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
674
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
591
675
  method: "POST"
592
676
  });
593
677
  }
594
678
  /**
595
- * Starts a workflow run synchronously without waiting for the workflow to complete
679
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
596
680
  * @param params - Object containing the runId and triggerData
597
681
  * @returns Promise containing success message
598
682
  */
599
683
  start(params) {
600
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
684
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
601
685
  method: "POST",
602
686
  body: params?.triggerData
603
687
  });
604
688
  }
605
689
  /**
606
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
690
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
607
691
  * @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
692
+ * @param runId - ID of the legacy workflow run
693
+ * @param context - Context to resume the legacy workflow with
694
+ * @returns Promise containing the legacy workflow resume results
611
695
  */
612
696
  resume({
613
697
  stepId,
614
698
  runId,
615
699
  context
616
700
  }) {
617
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
701
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
618
702
  method: "POST",
619
703
  body: {
620
704
  stepId,
@@ -632,18 +716,18 @@ var Workflow = class extends BaseResource {
632
716
  if (!!params?.runId) {
633
717
  searchParams.set("runId", params.runId);
634
718
  }
635
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
719
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
636
720
  method: "POST",
637
721
  body: params?.triggerData
638
722
  });
639
723
  }
640
724
  /**
641
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
725
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
642
726
  * @param params - Object containing the runId, stepId, and context
643
727
  * @returns Promise containing the workflow resume results
644
728
  */
645
729
  resumeAsync(params) {
646
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
730
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
647
731
  method: "POST",
648
732
  body: {
649
733
  stepId: params.stepId,
@@ -697,16 +781,16 @@ var Workflow = class extends BaseResource {
697
781
  }
698
782
  }
699
783
  /**
700
- * Watches workflow transitions in real-time
784
+ * Watches legacy workflow transitions in real-time
701
785
  * @param runId - Optional run ID to filter the watch stream
702
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
786
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
703
787
  */
704
788
  async watch({ runId }, onRecord) {
705
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
789
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
706
790
  stream: true
707
791
  });
708
792
  if (!response.ok) {
709
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
793
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
710
794
  }
711
795
  if (!response.body) {
712
796
  throw new Error("Response body is null");
@@ -740,22 +824,26 @@ var Tool = class extends BaseResource {
740
824
  if (params.runId) {
741
825
  url.set("runId", params.runId);
742
826
  }
827
+ const body = {
828
+ data: params.data,
829
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
830
+ };
743
831
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
744
832
  method: "POST",
745
- body: params.data
833
+ body
746
834
  });
747
835
  }
748
836
  };
749
837
 
750
- // src/resources/vnext-workflow.ts
838
+ // src/resources/workflow.ts
751
839
  var RECORD_SEPARATOR2 = "";
752
- var VNextWorkflow = class extends BaseResource {
840
+ var Workflow = class extends BaseResource {
753
841
  constructor(options, workflowId) {
754
842
  super(options);
755
843
  this.workflowId = workflowId;
756
844
  }
757
845
  /**
758
- * Creates an async generator that processes a readable stream and yields vNext workflow records
846
+ * Creates an async generator that processes a readable stream and yields workflow records
759
847
  * separated by the Record Separator character (\x1E)
760
848
  *
761
849
  * @param stream - The readable stream to process
@@ -800,16 +888,16 @@ var VNextWorkflow = class extends BaseResource {
800
888
  }
801
889
  }
802
890
  /**
803
- * Retrieves details about the vNext workflow
804
- * @returns Promise containing vNext workflow details including steps and graphs
891
+ * Retrieves details about the workflow
892
+ * @returns Promise containing workflow details including steps and graphs
805
893
  */
806
894
  details() {
807
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
895
+ return this.request(`/api/workflows/${this.workflowId}`);
808
896
  }
809
897
  /**
810
- * Retrieves all runs for a vNext workflow
898
+ * Retrieves all runs for a workflow
811
899
  * @param params - Parameters for filtering runs
812
- * @returns Promise containing vNext workflow runs array
900
+ * @returns Promise containing workflow runs array
813
901
  */
814
902
  runs(params) {
815
903
  const searchParams = new URLSearchParams();
@@ -829,13 +917,29 @@ var VNextWorkflow = class extends BaseResource {
829
917
  searchParams.set("resourceId", params.resourceId);
830
918
  }
831
919
  if (searchParams.size) {
832
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
920
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
833
921
  } else {
834
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
922
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
835
923
  }
836
924
  }
837
925
  /**
838
- * Creates a new vNext workflow run
926
+ * Retrieves a specific workflow run by its ID
927
+ * @param runId - The ID of the workflow run to retrieve
928
+ * @returns Promise containing the workflow run details
929
+ */
930
+ runById(runId) {
931
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
932
+ }
933
+ /**
934
+ * Retrieves the execution result for a specific workflow run by its ID
935
+ * @param runId - The ID of the workflow run to retrieve the execution result for
936
+ * @returns Promise containing the workflow run execution result
937
+ */
938
+ runExecutionResult(runId) {
939
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
940
+ }
941
+ /**
942
+ * Creates a new workflow run
839
943
  * @param params - Optional object containing the optional runId
840
944
  * @returns Promise containing the runId of the created run
841
945
  */
@@ -844,23 +948,24 @@ var VNextWorkflow = class extends BaseResource {
844
948
  if (!!params?.runId) {
845
949
  searchParams.set("runId", params.runId);
846
950
  }
847
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
951
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
848
952
  method: "POST"
849
953
  });
850
954
  }
851
955
  /**
852
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
956
+ * Starts a workflow run synchronously without waiting for the workflow to complete
853
957
  * @param params - Object containing the runId, inputData and runtimeContext
854
958
  * @returns Promise containing success message
855
959
  */
856
960
  start(params) {
857
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
961
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
962
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
858
963
  method: "POST",
859
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
964
+ body: { inputData: params?.inputData, runtimeContext }
860
965
  });
861
966
  }
862
967
  /**
863
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
968
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
864
969
  * @param params - Object containing the runId, step, resumeData and runtimeContext
865
970
  * @returns Promise containing success message
866
971
  */
@@ -868,9 +973,10 @@ var VNextWorkflow = class extends BaseResource {
868
973
  step,
869
974
  runId,
870
975
  resumeData,
871
- runtimeContext
976
+ ...rest
872
977
  }) {
873
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
978
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
979
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
874
980
  method: "POST",
875
981
  stream: true,
876
982
  body: {
@@ -881,54 +987,238 @@ var VNextWorkflow = class extends BaseResource {
881
987
  });
882
988
  }
883
989
  /**
884
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
990
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
885
991
  * @param params - Object containing the optional runId, inputData and runtimeContext
886
- * @returns Promise containing the vNext workflow execution results
992
+ * @returns Promise containing the workflow execution results
887
993
  */
888
994
  startAsync(params) {
889
995
  const searchParams = new URLSearchParams();
890
996
  if (!!params?.runId) {
891
997
  searchParams.set("runId", params.runId);
892
998
  }
893
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
999
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1000
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
894
1001
  method: "POST",
895
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
1002
+ body: { inputData: params.inputData, runtimeContext }
1003
+ });
1004
+ }
1005
+ /**
1006
+ * Starts a vNext workflow run and returns a stream
1007
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1008
+ * @returns Promise containing the vNext workflow execution results
1009
+ */
1010
+ async stream(params) {
1011
+ const searchParams = new URLSearchParams();
1012
+ if (!!params?.runId) {
1013
+ searchParams.set("runId", params.runId);
1014
+ }
1015
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1016
+ const response = await this.request(
1017
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1018
+ {
1019
+ method: "POST",
1020
+ body: { inputData: params.inputData, runtimeContext },
1021
+ stream: true
1022
+ }
1023
+ );
1024
+ if (!response.ok) {
1025
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1026
+ }
1027
+ if (!response.body) {
1028
+ throw new Error("Response body is null");
1029
+ }
1030
+ const transformStream = new TransformStream({
1031
+ start() {
1032
+ },
1033
+ async transform(chunk, controller) {
1034
+ try {
1035
+ const decoded = new TextDecoder().decode(chunk);
1036
+ const chunks = decoded.split(RECORD_SEPARATOR2);
1037
+ for (const chunk2 of chunks) {
1038
+ if (chunk2) {
1039
+ try {
1040
+ const parsedChunk = JSON.parse(chunk2);
1041
+ controller.enqueue(parsedChunk);
1042
+ } catch {
1043
+ }
1044
+ }
1045
+ }
1046
+ } catch {
1047
+ }
1048
+ }
896
1049
  });
1050
+ return response.body.pipeThrough(transformStream);
897
1051
  }
898
1052
  /**
899
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1053
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
900
1054
  * @param params - Object containing the runId, step, resumeData and runtimeContext
901
- * @returns Promise containing the vNext workflow resume results
1055
+ * @returns Promise containing the workflow resume results
902
1056
  */
903
1057
  resumeAsync(params) {
904
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1058
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1059
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
905
1060
  method: "POST",
906
1061
  body: {
907
1062
  step: params.step,
908
1063
  resumeData: params.resumeData,
909
- runtimeContext: params.runtimeContext
1064
+ runtimeContext
910
1065
  }
911
1066
  });
912
1067
  }
913
1068
  /**
914
- * Watches vNext workflow transitions in real-time
1069
+ * Watches workflow transitions in real-time
915
1070
  * @param runId - Optional run ID to filter the watch stream
916
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1071
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
917
1072
  */
918
1073
  async watch({ runId }, onRecord) {
919
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1074
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
920
1075
  stream: true
921
1076
  });
922
1077
  if (!response.ok) {
923
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1078
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
924
1079
  }
925
1080
  if (!response.body) {
926
1081
  throw new Error("Response body is null");
927
1082
  }
928
1083
  for await (const record of this.streamProcessor(response.body)) {
929
- onRecord(record);
1084
+ if (typeof record === "string") {
1085
+ onRecord(JSON.parse(record));
1086
+ } else {
1087
+ onRecord(record);
1088
+ }
930
1089
  }
931
1090
  }
1091
+ /**
1092
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1093
+ * serializing each as JSON and separating them with the record separator (\x1E).
1094
+ *
1095
+ * @param records - An iterable or async iterable of objects to stream
1096
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1097
+ */
1098
+ static createRecordStream(records) {
1099
+ const encoder = new TextEncoder();
1100
+ return new ReadableStream({
1101
+ async start(controller) {
1102
+ try {
1103
+ for await (const record of records) {
1104
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1105
+ controller.enqueue(encoder.encode(json));
1106
+ }
1107
+ controller.close();
1108
+ } catch (err) {
1109
+ controller.error(err);
1110
+ }
1111
+ }
1112
+ });
1113
+ }
1114
+ };
1115
+
1116
+ // src/resources/a2a.ts
1117
+ var A2A = class extends BaseResource {
1118
+ constructor(options, agentId) {
1119
+ super(options);
1120
+ this.agentId = agentId;
1121
+ }
1122
+ /**
1123
+ * Get the agent card with metadata about the agent
1124
+ * @returns Promise containing the agent card information
1125
+ */
1126
+ async getCard() {
1127
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1128
+ }
1129
+ /**
1130
+ * Send a message to the agent and get a response
1131
+ * @param params - Parameters for the task
1132
+ * @returns Promise containing the task response
1133
+ */
1134
+ async sendMessage(params) {
1135
+ const response = await this.request(`/a2a/${this.agentId}`, {
1136
+ method: "POST",
1137
+ body: {
1138
+ method: "tasks/send",
1139
+ params
1140
+ }
1141
+ });
1142
+ return { task: response.result };
1143
+ }
1144
+ /**
1145
+ * Get the status and result of a task
1146
+ * @param params - Parameters for querying the task
1147
+ * @returns Promise containing the task response
1148
+ */
1149
+ async getTask(params) {
1150
+ const response = await this.request(`/a2a/${this.agentId}`, {
1151
+ method: "POST",
1152
+ body: {
1153
+ method: "tasks/get",
1154
+ params
1155
+ }
1156
+ });
1157
+ return response.result;
1158
+ }
1159
+ /**
1160
+ * Cancel a running task
1161
+ * @param params - Parameters identifying the task to cancel
1162
+ * @returns Promise containing the task response
1163
+ */
1164
+ async cancelTask(params) {
1165
+ return this.request(`/a2a/${this.agentId}`, {
1166
+ method: "POST",
1167
+ body: {
1168
+ method: "tasks/cancel",
1169
+ params
1170
+ }
1171
+ });
1172
+ }
1173
+ /**
1174
+ * Send a message and subscribe to streaming updates (not fully implemented)
1175
+ * @param params - Parameters for the task
1176
+ * @returns Promise containing the task response
1177
+ */
1178
+ async sendAndSubscribe(params) {
1179
+ return this.request(`/a2a/${this.agentId}`, {
1180
+ method: "POST",
1181
+ body: {
1182
+ method: "tasks/sendSubscribe",
1183
+ params
1184
+ },
1185
+ stream: true
1186
+ });
1187
+ }
1188
+ };
1189
+
1190
+ // src/resources/mcp-tool.ts
1191
+ var MCPTool = class extends BaseResource {
1192
+ serverId;
1193
+ toolId;
1194
+ constructor(options, serverId, toolId) {
1195
+ super(options);
1196
+ this.serverId = serverId;
1197
+ this.toolId = toolId;
1198
+ }
1199
+ /**
1200
+ * Retrieves details about this specific tool from the MCP server.
1201
+ * @returns Promise containing the tool's information (name, description, schema).
1202
+ */
1203
+ details() {
1204
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1205
+ }
1206
+ /**
1207
+ * Executes this specific tool on the MCP server.
1208
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1209
+ * @returns Promise containing the result of the tool execution.
1210
+ */
1211
+ execute(params) {
1212
+ const body = {};
1213
+ if (params.data !== void 0) body.data = params.data;
1214
+ if (params.runtimeContext !== void 0) {
1215
+ body.runtimeContext = params.runtimeContext;
1216
+ }
1217
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1218
+ method: "POST",
1219
+ body: Object.keys(body).length > 0 ? body : void 0
1220
+ });
1221
+ }
932
1222
  };
933
1223
 
934
1224
  // src/client.ts
@@ -1023,6 +1313,21 @@ var MastraClient = class extends BaseResource {
1023
1313
  getTool(toolId) {
1024
1314
  return new Tool(this.options, toolId);
1025
1315
  }
1316
+ /**
1317
+ * Retrieves all available legacy workflows
1318
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1319
+ */
1320
+ getLegacyWorkflows() {
1321
+ return this.request("/api/workflows/legacy");
1322
+ }
1323
+ /**
1324
+ * Gets a legacy workflow instance by ID
1325
+ * @param workflowId - ID of the legacy workflow to retrieve
1326
+ * @returns Legacy Workflow instance
1327
+ */
1328
+ getLegacyWorkflow(workflowId) {
1329
+ return new LegacyWorkflow(this.options, workflowId);
1330
+ }
1026
1331
  /**
1027
1332
  * Retrieves all available workflows
1028
1333
  * @returns Promise containing map of workflow IDs to workflow details
@@ -1038,21 +1343,6 @@ var MastraClient = class extends BaseResource {
1038
1343
  getWorkflow(workflowId) {
1039
1344
  return new Workflow(this.options, workflowId);
1040
1345
  }
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
1346
  /**
1057
1347
  * Gets a vector instance by name
1058
1348
  * @param vectorName - Name of the vector to retrieve
@@ -1067,7 +1357,41 @@ var MastraClient = class extends BaseResource {
1067
1357
  * @returns Promise containing array of log messages
1068
1358
  */
1069
1359
  getLogs(params) {
1070
- return this.request(`/api/logs?transportId=${params.transportId}`);
1360
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1361
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1362
+ const searchParams = new URLSearchParams();
1363
+ if (transportId) {
1364
+ searchParams.set("transportId", transportId);
1365
+ }
1366
+ if (fromDate) {
1367
+ searchParams.set("fromDate", fromDate.toISOString());
1368
+ }
1369
+ if (toDate) {
1370
+ searchParams.set("toDate", toDate.toISOString());
1371
+ }
1372
+ if (logLevel) {
1373
+ searchParams.set("logLevel", logLevel);
1374
+ }
1375
+ if (page) {
1376
+ searchParams.set("page", String(page));
1377
+ }
1378
+ if (perPage) {
1379
+ searchParams.set("perPage", String(perPage));
1380
+ }
1381
+ if (_filters) {
1382
+ if (Array.isArray(_filters)) {
1383
+ for (const filter of _filters) {
1384
+ searchParams.append("filters", filter);
1385
+ }
1386
+ } else {
1387
+ searchParams.set("filters", _filters);
1388
+ }
1389
+ }
1390
+ if (searchParams.size) {
1391
+ return this.request(`/api/logs?${searchParams}`);
1392
+ } else {
1393
+ return this.request(`/api/logs`);
1394
+ }
1071
1395
  }
1072
1396
  /**
1073
1397
  * Gets logs for a specific run
@@ -1075,7 +1399,44 @@ var MastraClient = class extends BaseResource {
1075
1399
  * @returns Promise containing array of log messages
1076
1400
  */
1077
1401
  getLogForRun(params) {
1078
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
1402
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1403
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1404
+ const searchParams = new URLSearchParams();
1405
+ if (runId) {
1406
+ searchParams.set("runId", runId);
1407
+ }
1408
+ if (transportId) {
1409
+ searchParams.set("transportId", transportId);
1410
+ }
1411
+ if (fromDate) {
1412
+ searchParams.set("fromDate", fromDate.toISOString());
1413
+ }
1414
+ if (toDate) {
1415
+ searchParams.set("toDate", toDate.toISOString());
1416
+ }
1417
+ if (logLevel) {
1418
+ searchParams.set("logLevel", logLevel);
1419
+ }
1420
+ if (page) {
1421
+ searchParams.set("page", String(page));
1422
+ }
1423
+ if (perPage) {
1424
+ searchParams.set("perPage", String(perPage));
1425
+ }
1426
+ if (_filters) {
1427
+ if (Array.isArray(_filters)) {
1428
+ for (const filter of _filters) {
1429
+ searchParams.append("filters", filter);
1430
+ }
1431
+ } else {
1432
+ searchParams.set("filters", _filters);
1433
+ }
1434
+ }
1435
+ if (searchParams.size) {
1436
+ return this.request(`/api/logs/${runId}?${searchParams}`);
1437
+ } else {
1438
+ return this.request(`/api/logs/${runId}`);
1439
+ }
1079
1440
  }
1080
1441
  /**
1081
1442
  * List of all log transports
@@ -1141,6 +1502,62 @@ var MastraClient = class extends BaseResource {
1141
1502
  getNetwork(networkId) {
1142
1503
  return new Network(this.options, networkId);
1143
1504
  }
1505
+ /**
1506
+ * Retrieves a list of available MCP servers.
1507
+ * @param params - Optional parameters for pagination (limit, offset).
1508
+ * @returns Promise containing the list of MCP servers and pagination info.
1509
+ */
1510
+ getMcpServers(params) {
1511
+ const searchParams = new URLSearchParams();
1512
+ if (params?.limit !== void 0) {
1513
+ searchParams.set("limit", String(params.limit));
1514
+ }
1515
+ if (params?.offset !== void 0) {
1516
+ searchParams.set("offset", String(params.offset));
1517
+ }
1518
+ const queryString = searchParams.toString();
1519
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1520
+ }
1521
+ /**
1522
+ * Retrieves detailed information for a specific MCP server.
1523
+ * @param serverId - The ID of the MCP server to retrieve.
1524
+ * @param params - Optional parameters, e.g., specific version.
1525
+ * @returns Promise containing the detailed MCP server information.
1526
+ */
1527
+ getMcpServerDetails(serverId, params) {
1528
+ const searchParams = new URLSearchParams();
1529
+ if (params?.version) {
1530
+ searchParams.set("version", params.version);
1531
+ }
1532
+ const queryString = searchParams.toString();
1533
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1534
+ }
1535
+ /**
1536
+ * Retrieves a list of tools for a specific MCP server.
1537
+ * @param serverId - The ID of the MCP server.
1538
+ * @returns Promise containing the list of tools.
1539
+ */
1540
+ getMcpServerTools(serverId) {
1541
+ return this.request(`/api/mcp/${serverId}/tools`);
1542
+ }
1543
+ /**
1544
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1545
+ * This instance can then be used to fetch details or execute the tool.
1546
+ * @param serverId - The ID of the MCP server.
1547
+ * @param toolId - The ID of the tool.
1548
+ * @returns MCPTool instance.
1549
+ */
1550
+ getMcpServerTool(serverId, toolId) {
1551
+ return new MCPTool(this.options, serverId, toolId);
1552
+ }
1553
+ /**
1554
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1555
+ * @param agentId - ID of the agent to interact with
1556
+ * @returns A2A client instance
1557
+ */
1558
+ getA2A(agentId) {
1559
+ return new A2A(this.options, agentId);
1560
+ }
1144
1561
  };
1145
1562
 
1146
1563
  exports.MastraClient = MastraClient;