@mastra/client-js 0.0.0-storage-20250225005900 → 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 ADDED
@@ -0,0 +1,1445 @@
1
+ import { AbstractAgent, EventType } from '@ag-ui/client';
2
+ import { Observable } from 'rxjs';
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';
7
+
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
+ }
199
+
200
+ // src/resources/base.ts
201
+ var BaseResource = class {
202
+ options;
203
+ constructor(options) {
204
+ this.options = options;
205
+ }
206
+ /**
207
+ * Makes an HTTP request to the API with retries and exponential backoff
208
+ * @param path - The API endpoint path
209
+ * @param options - Optional request configuration
210
+ * @returns Promise containing the response data
211
+ */
212
+ async request(path, options = {}) {
213
+ let lastError = null;
214
+ const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
215
+ let delay = backoffMs;
216
+ for (let attempt = 0; attempt <= retries; attempt++) {
217
+ try {
218
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
219
+ ...options,
220
+ headers: {
221
+ ...headers,
222
+ ...options.headers
223
+ // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
224
+ // 'x-mastra-client-type': 'js',
225
+ },
226
+ body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
227
+ });
228
+ if (!response.ok) {
229
+ const errorBody = await response.text();
230
+ let errorMessage = `HTTP error! status: ${response.status}`;
231
+ try {
232
+ const errorJson = JSON.parse(errorBody);
233
+ errorMessage += ` - ${JSON.stringify(errorJson)}`;
234
+ } catch {
235
+ if (errorBody) {
236
+ errorMessage += ` - ${errorBody}`;
237
+ }
238
+ }
239
+ throw new Error(errorMessage);
240
+ }
241
+ if (options.stream) {
242
+ return response;
243
+ }
244
+ const data = await response.json();
245
+ return data;
246
+ } catch (error) {
247
+ lastError = error;
248
+ if (attempt === retries) {
249
+ break;
250
+ }
251
+ await new Promise((resolve) => setTimeout(resolve, delay));
252
+ delay = Math.min(delay * 2, maxBackoffMs);
253
+ }
254
+ }
255
+ throw lastError || new Error("Request failed");
256
+ }
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
+ }
267
+
268
+ // src/resources/agent.ts
269
+ var AgentVoice = class extends BaseResource {
270
+ constructor(options, agentId) {
271
+ super(options);
272
+ this.agentId = agentId;
273
+ this.agentId = agentId;
274
+ }
275
+ /**
276
+ * Convert text to speech using the agent's voice provider
277
+ * @param text - Text to convert to speech
278
+ * @param options - Optional provider-specific options for speech generation
279
+ * @returns Promise containing the audio data
280
+ */
281
+ async speak(text, options) {
282
+ return this.request(`/api/agents/${this.agentId}/voice/speak`, {
283
+ method: "POST",
284
+ headers: {
285
+ "Content-Type": "application/json"
286
+ },
287
+ body: { input: text, options },
288
+ stream: true
289
+ });
290
+ }
291
+ /**
292
+ * Convert speech to text using the agent's voice provider
293
+ * @param audio - Audio data to transcribe
294
+ * @param options - Optional provider-specific options
295
+ * @returns Promise containing the transcribed text
296
+ */
297
+ listen(audio, options) {
298
+ const formData = new FormData();
299
+ formData.append("audio", audio);
300
+ if (options) {
301
+ formData.append("options", JSON.stringify(options));
302
+ }
303
+ return this.request(`/api/agents/${this.agentId}/voice/listen`, {
304
+ method: "POST",
305
+ body: formData
306
+ });
307
+ }
308
+ /**
309
+ * Get available speakers for the agent's voice provider
310
+ * @returns Promise containing list of available speakers
311
+ */
312
+ getSpeakers() {
313
+ return this.request(`/api/agents/${this.agentId}/voice/speakers`);
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
+ }
322
+ };
323
+ var Agent = class extends BaseResource {
324
+ constructor(options, agentId) {
325
+ super(options);
326
+ this.agentId = agentId;
327
+ this.voice = new AgentVoice(options, this.agentId);
328
+ }
329
+ voice;
330
+ /**
331
+ * Retrieves details about the agent
332
+ * @returns Promise containing agent details including model and instructions
333
+ */
334
+ details() {
335
+ return this.request(`/api/agents/${this.agentId}`);
336
+ }
337
+ /**
338
+ * Generates a response from the agent
339
+ * @param params - Generation parameters including prompt
340
+ * @returns Promise containing the generated response
341
+ */
342
+ generate(params) {
343
+ const processedParams = {
344
+ ...params,
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)
348
+ };
349
+ return this.request(`/api/agents/${this.agentId}/generate`, {
350
+ method: "POST",
351
+ body: processedParams
352
+ });
353
+ }
354
+ /**
355
+ * Streams a response from the agent
356
+ * @param params - Stream parameters including prompt
357
+ * @returns Promise containing the enhanced Response object with processDataStream method
358
+ */
359
+ async stream(params) {
360
+ const processedParams = {
361
+ ...params,
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)
365
+ };
366
+ const response = await this.request(`/api/agents/${this.agentId}/stream`, {
367
+ method: "POST",
368
+ body: processedParams,
369
+ stream: true
370
+ });
371
+ if (!response.body) {
372
+ throw new Error("No response body");
373
+ }
374
+ response.processDataStream = async (options = {}) => {
375
+ await processDataStream({
376
+ stream: response.body,
377
+ ...options
378
+ });
379
+ };
380
+ return response;
381
+ }
382
+ /**
383
+ * Gets details about a specific tool available to the agent
384
+ * @param toolId - ID of the tool to retrieve
385
+ * @returns Promise containing tool details
386
+ */
387
+ getTool(toolId) {
388
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
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
+ }
406
+ /**
407
+ * Retrieves evaluation results for the agent
408
+ * @returns Promise containing agent evaluations
409
+ */
410
+ evals() {
411
+ return this.request(`/api/agents/${this.agentId}/evals/ci`);
412
+ }
413
+ /**
414
+ * Retrieves live evaluation results for the agent
415
+ * @returns Promise containing live agent evaluations
416
+ */
417
+ liveEvals() {
418
+ return this.request(`/api/agents/${this.agentId}/evals/live`);
419
+ }
420
+ };
421
+ var Network = class extends BaseResource {
422
+ constructor(options, networkId) {
423
+ super(options);
424
+ this.networkId = networkId;
425
+ }
426
+ /**
427
+ * Retrieves details about the network
428
+ * @returns Promise containing network details
429
+ */
430
+ details() {
431
+ return this.request(`/api/networks/${this.networkId}`);
432
+ }
433
+ /**
434
+ * Generates a response from the agent
435
+ * @param params - Generation parameters including prompt
436
+ * @returns Promise containing the generated response
437
+ */
438
+ generate(params) {
439
+ const processedParams = {
440
+ ...params,
441
+ output: zodToJsonSchema(params.output),
442
+ experimental_output: zodToJsonSchema(params.experimental_output)
443
+ };
444
+ return this.request(`/api/networks/${this.networkId}/generate`, {
445
+ method: "POST",
446
+ body: processedParams
447
+ });
448
+ }
449
+ /**
450
+ * Streams a response from the agent
451
+ * @param params - Stream parameters including prompt
452
+ * @returns Promise containing the enhanced Response object with processDataStream method
453
+ */
454
+ async stream(params) {
455
+ const processedParams = {
456
+ ...params,
457
+ output: zodToJsonSchema(params.output),
458
+ experimental_output: zodToJsonSchema(params.experimental_output)
459
+ };
460
+ const response = await this.request(`/api/networks/${this.networkId}/stream`, {
461
+ method: "POST",
462
+ body: processedParams,
463
+ stream: true
464
+ });
465
+ if (!response.body) {
466
+ throw new Error("No response body");
467
+ }
468
+ response.processDataStream = async (options = {}) => {
469
+ await processDataStream({
470
+ stream: response.body,
471
+ ...options
472
+ });
473
+ };
474
+ return response;
475
+ }
476
+ };
477
+
478
+ // src/resources/memory-thread.ts
479
+ var MemoryThread = class extends BaseResource {
480
+ constructor(options, threadId, agentId) {
481
+ super(options);
482
+ this.threadId = threadId;
483
+ this.agentId = agentId;
484
+ }
485
+ /**
486
+ * Retrieves the memory thread details
487
+ * @returns Promise containing thread details including title and metadata
488
+ */
489
+ get() {
490
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
491
+ }
492
+ /**
493
+ * Updates the memory thread properties
494
+ * @param params - Update parameters including title and metadata
495
+ * @returns Promise containing updated thread details
496
+ */
497
+ update(params) {
498
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
499
+ method: "PATCH",
500
+ body: params
501
+ });
502
+ }
503
+ /**
504
+ * Deletes the memory thread
505
+ * @returns Promise containing deletion result
506
+ */
507
+ delete() {
508
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
509
+ method: "DELETE"
510
+ });
511
+ }
512
+ /**
513
+ * Retrieves messages associated with the thread
514
+ * @param params - Optional parameters including limit for number of messages to retrieve
515
+ * @returns Promise containing thread messages and UI messages
516
+ */
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()}`);
523
+ }
524
+ };
525
+
526
+ // src/resources/vector.ts
527
+ var Vector = class extends BaseResource {
528
+ constructor(options, vectorName) {
529
+ super(options);
530
+ this.vectorName = vectorName;
531
+ }
532
+ /**
533
+ * Retrieves details about a specific vector index
534
+ * @param indexName - Name of the index to get details for
535
+ * @returns Promise containing vector index details
536
+ */
537
+ details(indexName) {
538
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
539
+ }
540
+ /**
541
+ * Deletes a vector index
542
+ * @param indexName - Name of the index to delete
543
+ * @returns Promise indicating deletion success
544
+ */
545
+ delete(indexName) {
546
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
547
+ method: "DELETE"
548
+ });
549
+ }
550
+ /**
551
+ * Retrieves a list of all available indexes
552
+ * @returns Promise containing array of index names
553
+ */
554
+ getIndexes() {
555
+ return this.request(`/api/vector/${this.vectorName}/indexes`);
556
+ }
557
+ /**
558
+ * Creates a new vector index
559
+ * @param params - Parameters for index creation including dimension and metric
560
+ * @returns Promise indicating creation success
561
+ */
562
+ createIndex(params) {
563
+ return this.request(`/api/vector/${this.vectorName}/create-index`, {
564
+ method: "POST",
565
+ body: params
566
+ });
567
+ }
568
+ /**
569
+ * Upserts vectors into an index
570
+ * @param params - Parameters containing vectors, metadata, and optional IDs
571
+ * @returns Promise containing array of vector IDs
572
+ */
573
+ upsert(params) {
574
+ return this.request(`/api/vector/${this.vectorName}/upsert`, {
575
+ method: "POST",
576
+ body: params
577
+ });
578
+ }
579
+ /**
580
+ * Queries vectors in an index
581
+ * @param params - Query parameters including query vector and search options
582
+ * @returns Promise containing query results
583
+ */
584
+ query(params) {
585
+ return this.request(`/api/vector/${this.vectorName}/query`, {
586
+ method: "POST",
587
+ body: params
588
+ });
589
+ }
590
+ };
591
+
592
+ // src/resources/legacy-workflow.ts
593
+ var RECORD_SEPARATOR = "";
594
+ var LegacyWorkflow = class extends BaseResource {
595
+ constructor(options, workflowId) {
596
+ super(options);
597
+ this.workflowId = workflowId;
598
+ }
599
+ /**
600
+ * Retrieves details about the legacy workflow
601
+ * @returns Promise containing legacy workflow details including steps and graphs
602
+ */
603
+ details() {
604
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
605
+ }
606
+ /**
607
+ * Retrieves all runs for a legacy workflow
608
+ * @param params - Parameters for filtering runs
609
+ * @returns Promise containing legacy workflow runs array
610
+ */
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
+ }
633
+ }
634
+ /**
635
+ * Creates a new legacy workflow run
636
+ * @returns Promise containing the generated run ID
637
+ */
638
+ createRun(params) {
639
+ const searchParams = new URLSearchParams();
640
+ if (!!params?.runId) {
641
+ searchParams.set("runId", params.runId);
642
+ }
643
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
644
+ method: "POST"
645
+ });
646
+ }
647
+ /**
648
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
649
+ * @param params - Object containing the runId and triggerData
650
+ * @returns Promise containing success message
651
+ */
652
+ start(params) {
653
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
654
+ method: "POST",
655
+ body: params?.triggerData
656
+ });
657
+ }
658
+ /**
659
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
660
+ * @param stepId - ID of the step to resume
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
664
+ */
665
+ resume({
666
+ stepId,
667
+ runId,
668
+ context
669
+ }) {
670
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
671
+ method: "POST",
672
+ body: {
673
+ stepId,
674
+ context
675
+ }
676
+ });
677
+ }
678
+ /**
679
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
680
+ * @param params - Object containing the optional runId and triggerData
681
+ * @returns Promise containing the workflow execution results
682
+ */
683
+ startAsync(params) {
684
+ const searchParams = new URLSearchParams();
685
+ if (!!params?.runId) {
686
+ searchParams.set("runId", params.runId);
687
+ }
688
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
689
+ method: "POST",
690
+ body: params?.triggerData
691
+ });
692
+ }
693
+ /**
694
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
695
+ * @param params - Object containing the runId, stepId, and context
696
+ * @returns Promise containing the workflow resume results
697
+ */
698
+ resumeAsync(params) {
699
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
700
+ method: "POST",
701
+ body: {
702
+ stepId: params.stepId,
703
+ context: params.context
704
+ }
705
+ });
706
+ }
707
+ /**
708
+ * Creates an async generator that processes a readable stream and yields records
709
+ * separated by the Record Separator character (\x1E)
710
+ *
711
+ * @param stream - The readable stream to process
712
+ * @returns An async generator that yields parsed records
713
+ */
714
+ async *streamProcessor(stream) {
715
+ const reader = stream.getReader();
716
+ let doneReading = false;
717
+ let buffer = "";
718
+ try {
719
+ while (!doneReading) {
720
+ const { done, value } = await reader.read();
721
+ doneReading = done;
722
+ if (done && !value) continue;
723
+ try {
724
+ const decoded = value ? new TextDecoder().decode(value) : "";
725
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
726
+ buffer = chunks.pop() || "";
727
+ for (const chunk of chunks) {
728
+ if (chunk) {
729
+ if (typeof chunk === "string") {
730
+ try {
731
+ const parsedChunk = JSON.parse(chunk);
732
+ yield parsedChunk;
733
+ } catch {
734
+ }
735
+ }
736
+ }
737
+ }
738
+ } catch {
739
+ }
740
+ }
741
+ if (buffer) {
742
+ try {
743
+ yield JSON.parse(buffer);
744
+ } catch {
745
+ }
746
+ }
747
+ } finally {
748
+ reader.cancel().catch(() => {
749
+ });
750
+ }
751
+ }
752
+ /**
753
+ * Watches legacy workflow transitions in real-time
754
+ * @param runId - Optional run ID to filter the watch stream
755
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
756
+ */
757
+ async watch({ runId }, onRecord) {
758
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
759
+ stream: true
760
+ });
761
+ if (!response.ok) {
762
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
763
+ }
764
+ if (!response.body) {
765
+ throw new Error("Response body is null");
766
+ }
767
+ for await (const record of this.streamProcessor(response.body)) {
768
+ onRecord(record);
769
+ }
770
+ }
771
+ };
772
+
773
+ // src/resources/tool.ts
774
+ var Tool = class extends BaseResource {
775
+ constructor(options, toolId) {
776
+ super(options);
777
+ this.toolId = toolId;
778
+ }
779
+ /**
780
+ * Retrieves details about the tool
781
+ * @returns Promise containing tool details including description and schemas
782
+ */
783
+ details() {
784
+ return this.request(`/api/tools/${this.toolId}`);
785
+ }
786
+ /**
787
+ * Executes the tool with the provided parameters
788
+ * @param params - Parameters required for tool execution
789
+ * @returns Promise containing the tool execution results
790
+ */
791
+ execute(params) {
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()}`, {
801
+ method: "POST",
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
1173
+ });
1174
+ }
1175
+ };
1176
+
1177
+ // src/client.ts
1178
+ var MastraClient = class extends BaseResource {
1179
+ constructor(options) {
1180
+ super(options);
1181
+ }
1182
+ /**
1183
+ * Retrieves all available agents
1184
+ * @returns Promise containing map of agent IDs to agent details
1185
+ */
1186
+ getAgents() {
1187
+ return this.request("/api/agents");
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
+ }
1204
+ /**
1205
+ * Gets an agent instance by ID
1206
+ * @param agentId - ID of the agent to retrieve
1207
+ * @returns Agent instance
1208
+ */
1209
+ getAgent(agentId) {
1210
+ return new Agent(this.options, agentId);
1211
+ }
1212
+ /**
1213
+ * Retrieves memory threads for a resource
1214
+ * @param params - Parameters containing the resource ID
1215
+ * @returns Promise containing array of memory threads
1216
+ */
1217
+ getMemoryThreads(params) {
1218
+ return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
1219
+ }
1220
+ /**
1221
+ * Creates a new memory thread
1222
+ * @param params - Parameters for creating the memory thread
1223
+ * @returns Promise containing the created memory thread
1224
+ */
1225
+ createMemoryThread(params) {
1226
+ return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
1227
+ }
1228
+ /**
1229
+ * Gets a memory thread instance by ID
1230
+ * @param threadId - ID of the memory thread to retrieve
1231
+ * @returns MemoryThread instance
1232
+ */
1233
+ getMemoryThread(threadId, agentId) {
1234
+ return new MemoryThread(this.options, threadId, agentId);
1235
+ }
1236
+ /**
1237
+ * Saves messages to memory
1238
+ * @param params - Parameters containing messages to save
1239
+ * @returns Promise containing the saved messages
1240
+ */
1241
+ saveMessageToMemory(params) {
1242
+ return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
1243
+ method: "POST",
1244
+ body: params
1245
+ });
1246
+ }
1247
+ /**
1248
+ * Gets the status of the memory system
1249
+ * @returns Promise containing memory system status
1250
+ */
1251
+ getMemoryStatus(agentId) {
1252
+ return this.request(`/api/memory/status?agentId=${agentId}`);
1253
+ }
1254
+ /**
1255
+ * Retrieves all available tools
1256
+ * @returns Promise containing map of tool IDs to tool details
1257
+ */
1258
+ getTools() {
1259
+ return this.request("/api/tools");
1260
+ }
1261
+ /**
1262
+ * Gets a tool instance by ID
1263
+ * @param toolId - ID of the tool to retrieve
1264
+ * @returns Tool instance
1265
+ */
1266
+ getTool(toolId) {
1267
+ return new Tool(this.options, toolId);
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
+ }
1284
+ /**
1285
+ * Retrieves all available workflows
1286
+ * @returns Promise containing map of workflow IDs to workflow details
1287
+ */
1288
+ getWorkflows() {
1289
+ return this.request("/api/workflows");
1290
+ }
1291
+ /**
1292
+ * Gets a workflow instance by ID
1293
+ * @param workflowId - ID of the workflow to retrieve
1294
+ * @returns Workflow instance
1295
+ */
1296
+ getWorkflow(workflowId) {
1297
+ return new Workflow(this.options, workflowId);
1298
+ }
1299
+ /**
1300
+ * Gets a vector instance by name
1301
+ * @param vectorName - Name of the vector to retrieve
1302
+ * @returns Vector instance
1303
+ */
1304
+ getVector(vectorName) {
1305
+ return new Vector(this.options, vectorName);
1306
+ }
1307
+ /**
1308
+ * Retrieves logs
1309
+ * @param params - Parameters for filtering logs
1310
+ * @returns Promise containing array of log messages
1311
+ */
1312
+ getLogs(params) {
1313
+ return this.request(`/api/logs?transportId=${params.transportId}`);
1314
+ }
1315
+ /**
1316
+ * Gets logs for a specific run
1317
+ * @param params - Parameters containing run ID to retrieve
1318
+ * @returns Promise containing array of log messages
1319
+ */
1320
+ getLogForRun(params) {
1321
+ return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
1322
+ }
1323
+ /**
1324
+ * List of all log transports
1325
+ * @returns Promise containing list of log transports
1326
+ */
1327
+ getLogTransports() {
1328
+ return this.request("/api/logs/transports");
1329
+ }
1330
+ /**
1331
+ * List of all traces (paged)
1332
+ * @param params - Parameters for filtering traces
1333
+ * @returns Promise containing telemetry data
1334
+ */
1335
+ getTelemetry(params) {
1336
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
1337
+ const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
1338
+ const searchParams = new URLSearchParams();
1339
+ if (name) {
1340
+ searchParams.set("name", name);
1341
+ }
1342
+ if (scope) {
1343
+ searchParams.set("scope", scope);
1344
+ }
1345
+ if (page) {
1346
+ searchParams.set("page", String(page));
1347
+ }
1348
+ if (perPage) {
1349
+ searchParams.set("perPage", String(perPage));
1350
+ }
1351
+ if (_attribute) {
1352
+ if (Array.isArray(_attribute)) {
1353
+ for (const attr of _attribute) {
1354
+ searchParams.append("attribute", attr);
1355
+ }
1356
+ } else {
1357
+ searchParams.set("attribute", _attribute);
1358
+ }
1359
+ }
1360
+ if (fromDate) {
1361
+ searchParams.set("fromDate", fromDate.toISOString());
1362
+ }
1363
+ if (toDate) {
1364
+ searchParams.set("toDate", toDate.toISOString());
1365
+ }
1366
+ if (searchParams.size) {
1367
+ return this.request(`/api/telemetry?${searchParams}`);
1368
+ } else {
1369
+ return this.request(`/api/telemetry`);
1370
+ }
1371
+ }
1372
+ /**
1373
+ * Retrieves all available networks
1374
+ * @returns Promise containing map of network IDs to network details
1375
+ */
1376
+ getNetworks() {
1377
+ return this.request("/api/networks");
1378
+ }
1379
+ /**
1380
+ * Gets a network instance by ID
1381
+ * @param networkId - ID of the network to retrieve
1382
+ * @returns Network instance
1383
+ */
1384
+ getNetwork(networkId) {
1385
+ return new Network(this.options, networkId);
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
+ }
1443
+ };
1444
+
1445
+ export { MastraClient };