@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-taofeeqInngest-20250603090617

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
@@ -1,8 +1,201 @@
1
- import { ZodSchema } from 'zod';
2
- import { zodToJsonSchema } from 'zod-to-json-schema';
1
+ import { AbstractAgent, EventType } from '@ag-ui/client';
2
+ import { Observable } from 'rxjs';
3
3
  import { processDataStream } from '@ai-sdk/ui-utils';
4
+ import { ZodSchema } from 'zod';
5
+ import originalZodToJsonSchema from 'zod-to-json-schema';
6
+ import { RuntimeContext } from '@mastra/core/runtime-context';
4
7
 
5
- // src/resources/agent.ts
8
+ // src/adapters/agui.ts
9
+ var AGUIAdapter = class extends AbstractAgent {
10
+ agent;
11
+ resourceId;
12
+ constructor({ agent, agentId, resourceId, ...rest }) {
13
+ super({
14
+ agentId,
15
+ ...rest
16
+ });
17
+ this.agent = agent;
18
+ this.resourceId = resourceId;
19
+ }
20
+ run(input) {
21
+ return new Observable((subscriber) => {
22
+ const convertedMessages = convertMessagesToMastraMessages(input.messages);
23
+ subscriber.next({
24
+ type: EventType.RUN_STARTED,
25
+ threadId: input.threadId,
26
+ runId: input.runId
27
+ });
28
+ this.agent.stream({
29
+ threadId: input.threadId,
30
+ resourceId: this.resourceId ?? "",
31
+ runId: input.runId,
32
+ messages: convertedMessages,
33
+ clientTools: input.tools.reduce(
34
+ (acc, tool) => {
35
+ acc[tool.name] = {
36
+ id: tool.name,
37
+ description: tool.description,
38
+ inputSchema: tool.parameters
39
+ };
40
+ return acc;
41
+ },
42
+ {}
43
+ )
44
+ }).then((response) => {
45
+ let currentMessageId = void 0;
46
+ let isInTextMessage = false;
47
+ return response.processDataStream({
48
+ onTextPart: (text) => {
49
+ if (currentMessageId === void 0) {
50
+ currentMessageId = generateUUID();
51
+ const message2 = {
52
+ type: EventType.TEXT_MESSAGE_START,
53
+ messageId: currentMessageId,
54
+ role: "assistant"
55
+ };
56
+ subscriber.next(message2);
57
+ isInTextMessage = true;
58
+ }
59
+ const message = {
60
+ type: EventType.TEXT_MESSAGE_CONTENT,
61
+ messageId: currentMessageId,
62
+ delta: text
63
+ };
64
+ subscriber.next(message);
65
+ },
66
+ onFinishMessagePart: () => {
67
+ if (currentMessageId !== void 0) {
68
+ const message = {
69
+ type: EventType.TEXT_MESSAGE_END,
70
+ messageId: currentMessageId
71
+ };
72
+ subscriber.next(message);
73
+ isInTextMessage = false;
74
+ }
75
+ subscriber.next({
76
+ type: EventType.RUN_FINISHED,
77
+ threadId: input.threadId,
78
+ runId: input.runId
79
+ });
80
+ subscriber.complete();
81
+ },
82
+ onToolCallPart(streamPart) {
83
+ const parentMessageId = currentMessageId || generateUUID();
84
+ if (isInTextMessage) {
85
+ const message = {
86
+ type: EventType.TEXT_MESSAGE_END,
87
+ messageId: parentMessageId
88
+ };
89
+ subscriber.next(message);
90
+ isInTextMessage = false;
91
+ }
92
+ subscriber.next({
93
+ type: EventType.TOOL_CALL_START,
94
+ toolCallId: streamPart.toolCallId,
95
+ toolCallName: streamPart.toolName,
96
+ parentMessageId
97
+ });
98
+ subscriber.next({
99
+ type: EventType.TOOL_CALL_ARGS,
100
+ toolCallId: streamPart.toolCallId,
101
+ delta: JSON.stringify(streamPart.args),
102
+ parentMessageId
103
+ });
104
+ subscriber.next({
105
+ type: EventType.TOOL_CALL_END,
106
+ toolCallId: streamPart.toolCallId,
107
+ parentMessageId
108
+ });
109
+ }
110
+ });
111
+ }).catch((error) => {
112
+ console.error("error", error);
113
+ subscriber.error(error);
114
+ });
115
+ return () => {
116
+ };
117
+ });
118
+ }
119
+ };
120
+ function generateUUID() {
121
+ if (typeof crypto !== "undefined") {
122
+ if (typeof crypto.randomUUID === "function") {
123
+ return crypto.randomUUID();
124
+ }
125
+ if (typeof crypto.getRandomValues === "function") {
126
+ const buffer = new Uint8Array(16);
127
+ crypto.getRandomValues(buffer);
128
+ buffer[6] = buffer[6] & 15 | 64;
129
+ buffer[8] = buffer[8] & 63 | 128;
130
+ let hex = "";
131
+ for (let i = 0; i < 16; i++) {
132
+ hex += buffer[i].toString(16).padStart(2, "0");
133
+ if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
134
+ }
135
+ return hex;
136
+ }
137
+ }
138
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
139
+ const r = Math.random() * 16 | 0;
140
+ const v = c === "x" ? r : r & 3 | 8;
141
+ return v.toString(16);
142
+ });
143
+ }
144
+ function convertMessagesToMastraMessages(messages) {
145
+ const result = [];
146
+ for (const message of messages) {
147
+ if (message.role === "assistant") {
148
+ const parts = message.content ? [{ type: "text", text: message.content }] : [];
149
+ for (const toolCall of message.toolCalls ?? []) {
150
+ parts.push({
151
+ type: "tool-call",
152
+ toolCallId: toolCall.id,
153
+ toolName: toolCall.function.name,
154
+ args: JSON.parse(toolCall.function.arguments)
155
+ });
156
+ }
157
+ result.push({
158
+ role: "assistant",
159
+ content: parts
160
+ });
161
+ if (message.toolCalls?.length) {
162
+ result.push({
163
+ role: "tool",
164
+ content: message.toolCalls.map((toolCall) => ({
165
+ type: "tool-result",
166
+ toolCallId: toolCall.id,
167
+ toolName: toolCall.function.name,
168
+ result: JSON.parse(toolCall.function.arguments)
169
+ }))
170
+ });
171
+ }
172
+ } else if (message.role === "user") {
173
+ result.push({
174
+ role: "user",
175
+ content: message.content || ""
176
+ });
177
+ } else if (message.role === "tool") {
178
+ result.push({
179
+ role: "tool",
180
+ content: [
181
+ {
182
+ type: "tool-result",
183
+ toolCallId: message.toolCallId,
184
+ toolName: "unknown",
185
+ result: message.content
186
+ }
187
+ ]
188
+ });
189
+ }
190
+ }
191
+ return result;
192
+ }
193
+ function zodToJsonSchema(zodSchema) {
194
+ if (!(zodSchema instanceof ZodSchema)) {
195
+ return zodSchema;
196
+ }
197
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
198
+ }
6
199
 
7
200
  // src/resources/base.ts
8
201
  var BaseResource = class {
@@ -22,7 +215,7 @@ var BaseResource = class {
22
215
  let delay = backoffMs;
23
216
  for (let attempt = 0; attempt <= retries; attempt++) {
24
217
  try {
25
- const response = await fetch(`${baseUrl}${path}`, {
218
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
26
219
  ...options,
27
220
  headers: {
28
221
  ...headers,
@@ -62,6 +255,15 @@ var BaseResource = class {
62
255
  throw lastError || new Error("Request failed");
63
256
  }
64
257
  };
258
+ function parseClientRuntimeContext(runtimeContext) {
259
+ if (runtimeContext) {
260
+ if (runtimeContext instanceof RuntimeContext) {
261
+ return Object.fromEntries(runtimeContext.entries());
262
+ }
263
+ return runtimeContext;
264
+ }
265
+ return void 0;
266
+ }
65
267
 
66
268
  // src/resources/agent.ts
67
269
  var AgentVoice = class extends BaseResource {
@@ -110,6 +312,13 @@ var AgentVoice = class extends BaseResource {
110
312
  getSpeakers() {
111
313
  return this.request(`/api/agents/${this.agentId}/voice/speakers`);
112
314
  }
315
+ /**
316
+ * Get the listener configuration for the agent's voice provider
317
+ * @returns Promise containing a check if the agent has listening capabilities
318
+ */
319
+ getListener() {
320
+ return this.request(`/api/agents/${this.agentId}/voice/listener`);
321
+ }
113
322
  };
114
323
  var Agent = class extends BaseResource {
115
324
  constructor(options, agentId) {
@@ -133,8 +342,9 @@ var Agent = class extends BaseResource {
133
342
  generate(params) {
134
343
  const processedParams = {
135
344
  ...params,
136
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
137
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
345
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
346
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
347
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
138
348
  };
139
349
  return this.request(`/api/agents/${this.agentId}/generate`, {
140
350
  method: "POST",
@@ -149,8 +359,9 @@ var Agent = class extends BaseResource {
149
359
  async stream(params) {
150
360
  const processedParams = {
151
361
  ...params,
152
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
153
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
362
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
363
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
364
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
154
365
  };
155
366
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
156
367
  method: "POST",
@@ -176,6 +387,22 @@ var Agent = class extends BaseResource {
176
387
  getTool(toolId) {
177
388
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
178
389
  }
390
+ /**
391
+ * Executes a tool for the agent
392
+ * @param toolId - ID of the tool to execute
393
+ * @param params - Parameters required for tool execution
394
+ * @returns Promise containing the tool execution results
395
+ */
396
+ executeTool(toolId, params) {
397
+ const body = {
398
+ data: params.data,
399
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
400
+ };
401
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
402
+ method: "POST",
403
+ body
404
+ });
405
+ }
179
406
  /**
180
407
  * Retrieves evaluation results for the agent
181
408
  * @returns Promise containing agent evaluations
@@ -211,8 +438,8 @@ var Network = class extends BaseResource {
211
438
  generate(params) {
212
439
  const processedParams = {
213
440
  ...params,
214
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
215
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
441
+ output: zodToJsonSchema(params.output),
442
+ experimental_output: zodToJsonSchema(params.experimental_output)
216
443
  };
217
444
  return this.request(`/api/networks/${this.networkId}/generate`, {
218
445
  method: "POST",
@@ -227,8 +454,8 @@ var Network = class extends BaseResource {
227
454
  async stream(params) {
228
455
  const processedParams = {
229
456
  ...params,
230
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
231
- experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
457
+ output: zodToJsonSchema(params.output),
458
+ experimental_output: zodToJsonSchema(params.experimental_output)
232
459
  };
233
460
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
234
461
  method: "POST",
@@ -284,10 +511,15 @@ var MemoryThread = class extends BaseResource {
284
511
  }
285
512
  /**
286
513
  * Retrieves messages associated with the thread
514
+ * @param params - Optional parameters including limit for number of messages to retrieve
287
515
  * @returns Promise containing thread messages and UI messages
288
516
  */
289
- getMessages() {
290
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
517
+ getMessages(params) {
518
+ const query = new URLSearchParams({
519
+ agentId: this.agentId,
520
+ ...params?.limit ? { limit: params.limit.toString() } : {}
521
+ });
522
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
291
523
  }
292
524
  };
293
525
 
@@ -357,34 +589,50 @@ var Vector = class extends BaseResource {
357
589
  }
358
590
  };
359
591
 
360
- // src/resources/workflow.ts
592
+ // src/resources/legacy-workflow.ts
361
593
  var RECORD_SEPARATOR = "";
362
- var Workflow = class extends BaseResource {
594
+ var LegacyWorkflow = class extends BaseResource {
363
595
  constructor(options, workflowId) {
364
596
  super(options);
365
597
  this.workflowId = workflowId;
366
598
  }
367
599
  /**
368
- * Retrieves details about the workflow
369
- * @returns Promise containing workflow details including steps and graphs
600
+ * Retrieves details about the legacy workflow
601
+ * @returns Promise containing legacy workflow details including steps and graphs
370
602
  */
371
603
  details() {
372
- return this.request(`/api/workflows/${this.workflowId}`);
604
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
373
605
  }
374
606
  /**
375
- * @deprecated Use `startAsync` instead
376
- * Executes the workflow with the provided parameters
377
- * @param params - Parameters required for workflow execution
378
- * @returns Promise containing the workflow execution results
607
+ * Retrieves all runs for a legacy workflow
608
+ * @param params - Parameters for filtering runs
609
+ * @returns Promise containing legacy workflow runs array
379
610
  */
380
- execute(params) {
381
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
382
- method: "POST",
383
- body: params
384
- });
611
+ runs(params) {
612
+ const searchParams = new URLSearchParams();
613
+ if (params?.fromDate) {
614
+ searchParams.set("fromDate", params.fromDate.toISOString());
615
+ }
616
+ if (params?.toDate) {
617
+ searchParams.set("toDate", params.toDate.toISOString());
618
+ }
619
+ if (params?.limit) {
620
+ searchParams.set("limit", String(params.limit));
621
+ }
622
+ if (params?.offset) {
623
+ searchParams.set("offset", String(params.offset));
624
+ }
625
+ if (params?.resourceId) {
626
+ searchParams.set("resourceId", params.resourceId);
627
+ }
628
+ if (searchParams.size) {
629
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
630
+ } else {
631
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
632
+ }
385
633
  }
386
634
  /**
387
- * Creates a new workflow run
635
+ * Creates a new legacy workflow run
388
636
  * @returns Promise containing the generated run ID
389
637
  */
390
638
  createRun(params) {
@@ -392,34 +640,34 @@ var Workflow = class extends BaseResource {
392
640
  if (!!params?.runId) {
393
641
  searchParams.set("runId", params.runId);
394
642
  }
395
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
643
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
396
644
  method: "POST"
397
645
  });
398
646
  }
399
647
  /**
400
- * Starts a workflow run synchronously without waiting for the workflow to complete
648
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
401
649
  * @param params - Object containing the runId and triggerData
402
650
  * @returns Promise containing success message
403
651
  */
404
652
  start(params) {
405
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
653
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
406
654
  method: "POST",
407
655
  body: params?.triggerData
408
656
  });
409
657
  }
410
658
  /**
411
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
659
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
412
660
  * @param stepId - ID of the step to resume
413
- * @param runId - ID of the workflow run
414
- * @param context - Context to resume the workflow with
415
- * @returns Promise containing the workflow resume results
661
+ * @param runId - ID of the legacy workflow run
662
+ * @param context - Context to resume the legacy workflow with
663
+ * @returns Promise containing the legacy workflow resume results
416
664
  */
417
665
  resume({
418
666
  stepId,
419
667
  runId,
420
668
  context
421
669
  }) {
422
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
670
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
423
671
  method: "POST",
424
672
  body: {
425
673
  stepId,
@@ -437,18 +685,18 @@ var Workflow = class extends BaseResource {
437
685
  if (!!params?.runId) {
438
686
  searchParams.set("runId", params.runId);
439
687
  }
440
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
688
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
441
689
  method: "POST",
442
690
  body: params?.triggerData
443
691
  });
444
692
  }
445
693
  /**
446
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
694
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
447
695
  * @param params - Object containing the runId, stepId, and context
448
696
  * @returns Promise containing the workflow resume results
449
697
  */
450
698
  resumeAsync(params) {
451
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
699
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
452
700
  method: "POST",
453
701
  body: {
454
702
  stepId: params.stepId,
@@ -487,7 +735,7 @@ var Workflow = class extends BaseResource {
487
735
  }
488
736
  }
489
737
  }
490
- } catch (error) {
738
+ } catch {
491
739
  }
492
740
  }
493
741
  if (buffer) {
@@ -502,16 +750,16 @@ var Workflow = class extends BaseResource {
502
750
  }
503
751
  }
504
752
  /**
505
- * Watches workflow transitions in real-time
753
+ * Watches legacy workflow transitions in real-time
506
754
  * @param runId - Optional run ID to filter the watch stream
507
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
755
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
508
756
  */
509
757
  async watch({ runId }, onRecord) {
510
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
758
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
511
759
  stream: true
512
760
  });
513
761
  if (!response.ok) {
514
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
762
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
515
763
  }
516
764
  if (!response.body) {
517
765
  throw new Error("Response body is null");
@@ -541,9 +789,387 @@ var Tool = class extends BaseResource {
541
789
  * @returns Promise containing the tool execution results
542
790
  */
543
791
  execute(params) {
544
- return this.request(`/api/tools/${this.toolId}/execute`, {
792
+ const url = new URLSearchParams();
793
+ if (params.runId) {
794
+ url.set("runId", params.runId);
795
+ }
796
+ const body = {
797
+ data: params.data,
798
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
799
+ };
800
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
545
801
  method: "POST",
546
- body: params
802
+ body
803
+ });
804
+ }
805
+ };
806
+
807
+ // src/resources/workflow.ts
808
+ var RECORD_SEPARATOR2 = "";
809
+ var Workflow = class extends BaseResource {
810
+ constructor(options, workflowId) {
811
+ super(options);
812
+ this.workflowId = workflowId;
813
+ }
814
+ /**
815
+ * Creates an async generator that processes a readable stream and yields workflow records
816
+ * separated by the Record Separator character (\x1E)
817
+ *
818
+ * @param stream - The readable stream to process
819
+ * @returns An async generator that yields parsed records
820
+ */
821
+ async *streamProcessor(stream) {
822
+ const reader = stream.getReader();
823
+ let doneReading = false;
824
+ let buffer = "";
825
+ try {
826
+ while (!doneReading) {
827
+ const { done, value } = await reader.read();
828
+ doneReading = done;
829
+ if (done && !value) continue;
830
+ try {
831
+ const decoded = value ? new TextDecoder().decode(value) : "";
832
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
833
+ buffer = chunks.pop() || "";
834
+ for (const chunk of chunks) {
835
+ if (chunk) {
836
+ if (typeof chunk === "string") {
837
+ try {
838
+ const parsedChunk = JSON.parse(chunk);
839
+ yield parsedChunk;
840
+ } catch {
841
+ }
842
+ }
843
+ }
844
+ }
845
+ } catch {
846
+ }
847
+ }
848
+ if (buffer) {
849
+ try {
850
+ yield JSON.parse(buffer);
851
+ } catch {
852
+ }
853
+ }
854
+ } finally {
855
+ reader.cancel().catch(() => {
856
+ });
857
+ }
858
+ }
859
+ /**
860
+ * Retrieves details about the workflow
861
+ * @returns Promise containing workflow details including steps and graphs
862
+ */
863
+ details() {
864
+ return this.request(`/api/workflows/${this.workflowId}`);
865
+ }
866
+ /**
867
+ * Retrieves all runs for a workflow
868
+ * @param params - Parameters for filtering runs
869
+ * @returns Promise containing workflow runs array
870
+ */
871
+ runs(params) {
872
+ const searchParams = new URLSearchParams();
873
+ if (params?.fromDate) {
874
+ searchParams.set("fromDate", params.fromDate.toISOString());
875
+ }
876
+ if (params?.toDate) {
877
+ searchParams.set("toDate", params.toDate.toISOString());
878
+ }
879
+ if (params?.limit) {
880
+ searchParams.set("limit", String(params.limit));
881
+ }
882
+ if (params?.offset) {
883
+ searchParams.set("offset", String(params.offset));
884
+ }
885
+ if (params?.resourceId) {
886
+ searchParams.set("resourceId", params.resourceId);
887
+ }
888
+ if (searchParams.size) {
889
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
890
+ } else {
891
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
892
+ }
893
+ }
894
+ /**
895
+ * Creates a new workflow run
896
+ * @param params - Optional object containing the optional runId
897
+ * @returns Promise containing the runId of the created run
898
+ */
899
+ createRun(params) {
900
+ const searchParams = new URLSearchParams();
901
+ if (!!params?.runId) {
902
+ searchParams.set("runId", params.runId);
903
+ }
904
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
905
+ method: "POST"
906
+ });
907
+ }
908
+ /**
909
+ * Starts a workflow run synchronously without waiting for the workflow to complete
910
+ * @param params - Object containing the runId, inputData and runtimeContext
911
+ * @returns Promise containing success message
912
+ */
913
+ start(params) {
914
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
915
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
916
+ method: "POST",
917
+ body: { inputData: params?.inputData, runtimeContext }
918
+ });
919
+ }
920
+ /**
921
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
922
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
923
+ * @returns Promise containing success message
924
+ */
925
+ resume({
926
+ step,
927
+ runId,
928
+ resumeData,
929
+ ...rest
930
+ }) {
931
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
932
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
933
+ method: "POST",
934
+ stream: true,
935
+ body: {
936
+ step,
937
+ resumeData,
938
+ runtimeContext
939
+ }
940
+ });
941
+ }
942
+ /**
943
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
944
+ * @param params - Object containing the optional runId, inputData and runtimeContext
945
+ * @returns Promise containing the workflow execution results
946
+ */
947
+ startAsync(params) {
948
+ const searchParams = new URLSearchParams();
949
+ if (!!params?.runId) {
950
+ searchParams.set("runId", params.runId);
951
+ }
952
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
953
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
954
+ method: "POST",
955
+ body: { inputData: params.inputData, runtimeContext }
956
+ });
957
+ }
958
+ /**
959
+ * Starts a vNext workflow run and returns a stream
960
+ * @param params - Object containing the optional runId, inputData and runtimeContext
961
+ * @returns Promise containing the vNext workflow execution results
962
+ */
963
+ async stream(params) {
964
+ const searchParams = new URLSearchParams();
965
+ if (!!params?.runId) {
966
+ searchParams.set("runId", params.runId);
967
+ }
968
+ const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
969
+ const response = await this.request(
970
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
971
+ {
972
+ method: "POST",
973
+ body: { inputData: params.inputData, runtimeContext },
974
+ stream: true
975
+ }
976
+ );
977
+ if (!response.ok) {
978
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
979
+ }
980
+ if (!response.body) {
981
+ throw new Error("Response body is null");
982
+ }
983
+ const transformStream = new TransformStream({
984
+ start() {
985
+ },
986
+ async transform(chunk, controller) {
987
+ try {
988
+ const decoded = new TextDecoder().decode(chunk);
989
+ const chunks = decoded.split(RECORD_SEPARATOR2);
990
+ for (const chunk2 of chunks) {
991
+ if (chunk2) {
992
+ try {
993
+ const parsedChunk = JSON.parse(chunk2);
994
+ controller.enqueue(parsedChunk);
995
+ } catch {
996
+ }
997
+ }
998
+ }
999
+ } catch {
1000
+ }
1001
+ }
1002
+ });
1003
+ return response.body.pipeThrough(transformStream);
1004
+ }
1005
+ /**
1006
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1007
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1008
+ * @returns Promise containing the workflow resume results
1009
+ */
1010
+ resumeAsync(params) {
1011
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1012
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
1013
+ method: "POST",
1014
+ body: {
1015
+ step: params.step,
1016
+ resumeData: params.resumeData,
1017
+ runtimeContext
1018
+ }
1019
+ });
1020
+ }
1021
+ /**
1022
+ * Watches workflow transitions in real-time
1023
+ * @param runId - Optional run ID to filter the watch stream
1024
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
1025
+ */
1026
+ async watch({ runId }, onRecord) {
1027
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
1028
+ stream: true
1029
+ });
1030
+ if (!response.ok) {
1031
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
1032
+ }
1033
+ if (!response.body) {
1034
+ throw new Error("Response body is null");
1035
+ }
1036
+ for await (const record of this.streamProcessor(response.body)) {
1037
+ if (typeof record === "string") {
1038
+ onRecord(JSON.parse(record));
1039
+ } else {
1040
+ onRecord(record);
1041
+ }
1042
+ }
1043
+ }
1044
+ /**
1045
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1046
+ * serializing each as JSON and separating them with the record separator (\x1E).
1047
+ *
1048
+ * @param records - An iterable or async iterable of objects to stream
1049
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1050
+ */
1051
+ static createRecordStream(records) {
1052
+ const encoder = new TextEncoder();
1053
+ return new ReadableStream({
1054
+ async start(controller) {
1055
+ try {
1056
+ for await (const record of records) {
1057
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1058
+ controller.enqueue(encoder.encode(json));
1059
+ }
1060
+ controller.close();
1061
+ } catch (err) {
1062
+ controller.error(err);
1063
+ }
1064
+ }
1065
+ });
1066
+ }
1067
+ };
1068
+
1069
+ // src/resources/a2a.ts
1070
+ var A2A = class extends BaseResource {
1071
+ constructor(options, agentId) {
1072
+ super(options);
1073
+ this.agentId = agentId;
1074
+ }
1075
+ /**
1076
+ * Get the agent card with metadata about the agent
1077
+ * @returns Promise containing the agent card information
1078
+ */
1079
+ async getCard() {
1080
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1081
+ }
1082
+ /**
1083
+ * Send a message to the agent and get a response
1084
+ * @param params - Parameters for the task
1085
+ * @returns Promise containing the task response
1086
+ */
1087
+ async sendMessage(params) {
1088
+ const response = await this.request(`/a2a/${this.agentId}`, {
1089
+ method: "POST",
1090
+ body: {
1091
+ method: "tasks/send",
1092
+ params
1093
+ }
1094
+ });
1095
+ return { task: response.result };
1096
+ }
1097
+ /**
1098
+ * Get the status and result of a task
1099
+ * @param params - Parameters for querying the task
1100
+ * @returns Promise containing the task response
1101
+ */
1102
+ async getTask(params) {
1103
+ const response = await this.request(`/a2a/${this.agentId}`, {
1104
+ method: "POST",
1105
+ body: {
1106
+ method: "tasks/get",
1107
+ params
1108
+ }
1109
+ });
1110
+ return response.result;
1111
+ }
1112
+ /**
1113
+ * Cancel a running task
1114
+ * @param params - Parameters identifying the task to cancel
1115
+ * @returns Promise containing the task response
1116
+ */
1117
+ async cancelTask(params) {
1118
+ return this.request(`/a2a/${this.agentId}`, {
1119
+ method: "POST",
1120
+ body: {
1121
+ method: "tasks/cancel",
1122
+ params
1123
+ }
1124
+ });
1125
+ }
1126
+ /**
1127
+ * Send a message and subscribe to streaming updates (not fully implemented)
1128
+ * @param params - Parameters for the task
1129
+ * @returns Promise containing the task response
1130
+ */
1131
+ async sendAndSubscribe(params) {
1132
+ return this.request(`/a2a/${this.agentId}`, {
1133
+ method: "POST",
1134
+ body: {
1135
+ method: "tasks/sendSubscribe",
1136
+ params
1137
+ },
1138
+ stream: true
1139
+ });
1140
+ }
1141
+ };
1142
+
1143
+ // src/resources/mcp-tool.ts
1144
+ var MCPTool = class extends BaseResource {
1145
+ serverId;
1146
+ toolId;
1147
+ constructor(options, serverId, toolId) {
1148
+ super(options);
1149
+ this.serverId = serverId;
1150
+ this.toolId = toolId;
1151
+ }
1152
+ /**
1153
+ * Retrieves details about this specific tool from the MCP server.
1154
+ * @returns Promise containing the tool's information (name, description, schema).
1155
+ */
1156
+ details() {
1157
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1158
+ }
1159
+ /**
1160
+ * Executes this specific tool on the MCP server.
1161
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1162
+ * @returns Promise containing the result of the tool execution.
1163
+ */
1164
+ execute(params) {
1165
+ const body = {};
1166
+ if (params.data !== void 0) body.data = params.data;
1167
+ if (params.runtimeContext !== void 0) {
1168
+ body.runtimeContext = params.runtimeContext;
1169
+ }
1170
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1171
+ method: "POST",
1172
+ body: Object.keys(body).length > 0 ? body : void 0
547
1173
  });
548
1174
  }
549
1175
  };
@@ -560,6 +1186,21 @@ var MastraClient = class extends BaseResource {
560
1186
  getAgents() {
561
1187
  return this.request("/api/agents");
562
1188
  }
1189
+ async getAGUI({ resourceId }) {
1190
+ const agents = await this.getAgents();
1191
+ return Object.entries(agents).reduce(
1192
+ (acc, [agentId]) => {
1193
+ const agent = this.getAgent(agentId);
1194
+ acc[agentId] = new AGUIAdapter({
1195
+ agentId,
1196
+ agent,
1197
+ resourceId
1198
+ });
1199
+ return acc;
1200
+ },
1201
+ {}
1202
+ );
1203
+ }
563
1204
  /**
564
1205
  * Gets an agent instance by ID
565
1206
  * @param agentId - ID of the agent to retrieve
@@ -625,6 +1266,21 @@ var MastraClient = class extends BaseResource {
625
1266
  getTool(toolId) {
626
1267
  return new Tool(this.options, toolId);
627
1268
  }
1269
+ /**
1270
+ * Retrieves all available legacy workflows
1271
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1272
+ */
1273
+ getLegacyWorkflows() {
1274
+ return this.request("/api/workflows/legacy");
1275
+ }
1276
+ /**
1277
+ * Gets a legacy workflow instance by ID
1278
+ * @param workflowId - ID of the legacy workflow to retrieve
1279
+ * @returns Legacy Workflow instance
1280
+ */
1281
+ getLegacyWorkflow(workflowId) {
1282
+ return new LegacyWorkflow(this.options, workflowId);
1283
+ }
628
1284
  /**
629
1285
  * Retrieves all available workflows
630
1286
  * @returns Promise containing map of workflow IDs to workflow details
@@ -677,7 +1333,7 @@ var MastraClient = class extends BaseResource {
677
1333
  * @returns Promise containing telemetry data
678
1334
  */
679
1335
  getTelemetry(params) {
680
- const { name, scope, page, perPage, attribute } = params || {};
1336
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
681
1337
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
682
1338
  const searchParams = new URLSearchParams();
683
1339
  if (name) {
@@ -701,6 +1357,12 @@ var MastraClient = class extends BaseResource {
701
1357
  searchParams.set("attribute", _attribute);
702
1358
  }
703
1359
  }
1360
+ if (fromDate) {
1361
+ searchParams.set("fromDate", fromDate.toISOString());
1362
+ }
1363
+ if (toDate) {
1364
+ searchParams.set("toDate", toDate.toISOString());
1365
+ }
704
1366
  if (searchParams.size) {
705
1367
  return this.request(`/api/telemetry?${searchParams}`);
706
1368
  } else {
@@ -722,6 +1384,62 @@ var MastraClient = class extends BaseResource {
722
1384
  getNetwork(networkId) {
723
1385
  return new Network(this.options, networkId);
724
1386
  }
1387
+ /**
1388
+ * Retrieves a list of available MCP servers.
1389
+ * @param params - Optional parameters for pagination (limit, offset).
1390
+ * @returns Promise containing the list of MCP servers and pagination info.
1391
+ */
1392
+ getMcpServers(params) {
1393
+ const searchParams = new URLSearchParams();
1394
+ if (params?.limit !== void 0) {
1395
+ searchParams.set("limit", String(params.limit));
1396
+ }
1397
+ if (params?.offset !== void 0) {
1398
+ searchParams.set("offset", String(params.offset));
1399
+ }
1400
+ const queryString = searchParams.toString();
1401
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1402
+ }
1403
+ /**
1404
+ * Retrieves detailed information for a specific MCP server.
1405
+ * @param serverId - The ID of the MCP server to retrieve.
1406
+ * @param params - Optional parameters, e.g., specific version.
1407
+ * @returns Promise containing the detailed MCP server information.
1408
+ */
1409
+ getMcpServerDetails(serverId, params) {
1410
+ const searchParams = new URLSearchParams();
1411
+ if (params?.version) {
1412
+ searchParams.set("version", params.version);
1413
+ }
1414
+ const queryString = searchParams.toString();
1415
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1416
+ }
1417
+ /**
1418
+ * Retrieves a list of tools for a specific MCP server.
1419
+ * @param serverId - The ID of the MCP server.
1420
+ * @returns Promise containing the list of tools.
1421
+ */
1422
+ getMcpServerTools(serverId) {
1423
+ return this.request(`/api/mcp/${serverId}/tools`);
1424
+ }
1425
+ /**
1426
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1427
+ * This instance can then be used to fetch details or execute the tool.
1428
+ * @param serverId - The ID of the MCP server.
1429
+ * @param toolId - The ID of the tool.
1430
+ * @returns MCPTool instance.
1431
+ */
1432
+ getMcpServerTool(serverId, toolId) {
1433
+ return new MCPTool(this.options, serverId, toolId);
1434
+ }
1435
+ /**
1436
+ * Gets an A2A client for interacting with an agent via the A2A protocol
1437
+ * @param agentId - ID of the agent to interact with
1438
+ * @returns A2A client instance
1439
+ */
1440
+ getA2A(agentId) {
1441
+ return new A2A(this.options, agentId);
1442
+ }
725
1443
  };
726
1444
 
727
1445
  export { MastraClient };