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