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