@mastra/client-js 0.0.0-a2a-20250421213654

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,833 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { zodToJsonSchema } from 'zod-to-json-schema';
3
+ import { processDataStream } from '@ai-sdk/ui-utils';
4
+
5
+ // src/resources/agent.ts
6
+
7
+ // src/resources/base.ts
8
+ var BaseResource = class {
9
+ options;
10
+ constructor(options) {
11
+ this.options = options;
12
+ }
13
+ /**
14
+ * Makes an HTTP request to the API with retries and exponential backoff
15
+ * @param path - The API endpoint path
16
+ * @param options - Optional request configuration
17
+ * @returns Promise containing the response data
18
+ */
19
+ async request(path, options = {}) {
20
+ let lastError = null;
21
+ const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
22
+ let delay = backoffMs;
23
+ for (let attempt = 0; attempt <= retries; attempt++) {
24
+ try {
25
+ const response = await fetch(`${baseUrl}${path}`, {
26
+ ...options,
27
+ headers: {
28
+ ...headers,
29
+ ...options.headers
30
+ // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
31
+ // 'x-mastra-client-type': 'js',
32
+ },
33
+ body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
34
+ });
35
+ if (!response.ok) {
36
+ const errorBody = await response.text();
37
+ let errorMessage = `HTTP error! status: ${response.status}`;
38
+ try {
39
+ const errorJson = JSON.parse(errorBody);
40
+ errorMessage += ` - ${JSON.stringify(errorJson)}`;
41
+ } catch {
42
+ if (errorBody) {
43
+ errorMessage += ` - ${errorBody}`;
44
+ }
45
+ }
46
+ throw new Error(errorMessage);
47
+ }
48
+ if (options.stream) {
49
+ return response;
50
+ }
51
+ const data = await response.json();
52
+ return data;
53
+ } catch (error) {
54
+ lastError = error;
55
+ if (attempt === retries) {
56
+ break;
57
+ }
58
+ await new Promise((resolve) => setTimeout(resolve, delay));
59
+ delay = Math.min(delay * 2, maxBackoffMs);
60
+ }
61
+ }
62
+ throw lastError || new Error("Request failed");
63
+ }
64
+ };
65
+
66
+ // src/resources/agent.ts
67
+ var AgentVoice = class extends BaseResource {
68
+ constructor(options, agentId) {
69
+ super(options);
70
+ this.agentId = agentId;
71
+ this.agentId = agentId;
72
+ }
73
+ /**
74
+ * Convert text to speech using the agent's voice provider
75
+ * @param text - Text to convert to speech
76
+ * @param options - Optional provider-specific options for speech generation
77
+ * @returns Promise containing the audio data
78
+ */
79
+ async speak(text, options) {
80
+ return this.request(`/api/agents/${this.agentId}/voice/speak`, {
81
+ method: "POST",
82
+ headers: {
83
+ "Content-Type": "application/json"
84
+ },
85
+ body: { input: text, options },
86
+ stream: true
87
+ });
88
+ }
89
+ /**
90
+ * Convert speech to text using the agent's voice provider
91
+ * @param audio - Audio data to transcribe
92
+ * @param options - Optional provider-specific options
93
+ * @returns Promise containing the transcribed text
94
+ */
95
+ listen(audio, options) {
96
+ const formData = new FormData();
97
+ formData.append("audio", audio);
98
+ if (options) {
99
+ formData.append("options", JSON.stringify(options));
100
+ }
101
+ return this.request(`/api/agents/${this.agentId}/voice/listen`, {
102
+ method: "POST",
103
+ body: formData
104
+ });
105
+ }
106
+ /**
107
+ * Get available speakers for the agent's voice provider
108
+ * @returns Promise containing list of available speakers
109
+ */
110
+ getSpeakers() {
111
+ return this.request(`/api/agents/${this.agentId}/voice/speakers`);
112
+ }
113
+ };
114
+ var Agent = class extends BaseResource {
115
+ constructor(options, agentId) {
116
+ super(options);
117
+ this.agentId = agentId;
118
+ this.voice = new AgentVoice(options, this.agentId);
119
+ }
120
+ voice;
121
+ /**
122
+ * Retrieves details about the agent
123
+ * @returns Promise containing agent details including model and instructions
124
+ */
125
+ details() {
126
+ return this.request(`/api/agents/${this.agentId}`);
127
+ }
128
+ /**
129
+ * Generates a response from the agent
130
+ * @param params - Generation parameters including prompt
131
+ * @returns Promise containing the generated response
132
+ */
133
+ generate(params) {
134
+ const processedParams = {
135
+ ...params,
136
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
137
+ experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
138
+ };
139
+ return this.request(`/api/agents/${this.agentId}/generate`, {
140
+ method: "POST",
141
+ body: processedParams
142
+ });
143
+ }
144
+ /**
145
+ * Streams a response from the agent
146
+ * @param params - Stream parameters including prompt
147
+ * @returns Promise containing the enhanced Response object with processDataStream method
148
+ */
149
+ async stream(params) {
150
+ const processedParams = {
151
+ ...params,
152
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
153
+ experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
154
+ };
155
+ const response = await this.request(`/api/agents/${this.agentId}/stream`, {
156
+ method: "POST",
157
+ body: processedParams,
158
+ stream: true
159
+ });
160
+ if (!response.body) {
161
+ throw new Error("No response body");
162
+ }
163
+ response.processDataStream = async (options = {}) => {
164
+ await processDataStream({
165
+ stream: response.body,
166
+ ...options
167
+ });
168
+ };
169
+ return response;
170
+ }
171
+ /**
172
+ * Gets details about a specific tool available to the agent
173
+ * @param toolId - ID of the tool to retrieve
174
+ * @returns Promise containing tool details
175
+ */
176
+ getTool(toolId) {
177
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
178
+ }
179
+ /**
180
+ * Retrieves evaluation results for the agent
181
+ * @returns Promise containing agent evaluations
182
+ */
183
+ evals() {
184
+ return this.request(`/api/agents/${this.agentId}/evals/ci`);
185
+ }
186
+ /**
187
+ * Retrieves live evaluation results for the agent
188
+ * @returns Promise containing live agent evaluations
189
+ */
190
+ liveEvals() {
191
+ return this.request(`/api/agents/${this.agentId}/evals/live`);
192
+ }
193
+ };
194
+ var Network = class extends BaseResource {
195
+ constructor(options, networkId) {
196
+ super(options);
197
+ this.networkId = networkId;
198
+ }
199
+ /**
200
+ * Retrieves details about the network
201
+ * @returns Promise containing network details
202
+ */
203
+ details() {
204
+ return this.request(`/api/networks/${this.networkId}`);
205
+ }
206
+ /**
207
+ * Generates a response from the agent
208
+ * @param params - Generation parameters including prompt
209
+ * @returns Promise containing the generated response
210
+ */
211
+ generate(params) {
212
+ const processedParams = {
213
+ ...params,
214
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
215
+ experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
216
+ };
217
+ return this.request(`/api/networks/${this.networkId}/generate`, {
218
+ method: "POST",
219
+ body: processedParams
220
+ });
221
+ }
222
+ /**
223
+ * Streams a response from the agent
224
+ * @param params - Stream parameters including prompt
225
+ * @returns Promise containing the enhanced Response object with processDataStream method
226
+ */
227
+ async stream(params) {
228
+ const processedParams = {
229
+ ...params,
230
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
231
+ experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
232
+ };
233
+ const response = await this.request(`/api/networks/${this.networkId}/stream`, {
234
+ method: "POST",
235
+ body: processedParams,
236
+ stream: true
237
+ });
238
+ if (!response.body) {
239
+ throw new Error("No response body");
240
+ }
241
+ response.processDataStream = async (options = {}) => {
242
+ await processDataStream({
243
+ stream: response.body,
244
+ ...options
245
+ });
246
+ };
247
+ return response;
248
+ }
249
+ };
250
+
251
+ // src/resources/memory-thread.ts
252
+ var MemoryThread = class extends BaseResource {
253
+ constructor(options, threadId, agentId) {
254
+ super(options);
255
+ this.threadId = threadId;
256
+ this.agentId = agentId;
257
+ }
258
+ /**
259
+ * Retrieves the memory thread details
260
+ * @returns Promise containing thread details including title and metadata
261
+ */
262
+ get() {
263
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
264
+ }
265
+ /**
266
+ * Updates the memory thread properties
267
+ * @param params - Update parameters including title and metadata
268
+ * @returns Promise containing updated thread details
269
+ */
270
+ update(params) {
271
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
272
+ method: "PATCH",
273
+ body: params
274
+ });
275
+ }
276
+ /**
277
+ * Deletes the memory thread
278
+ * @returns Promise containing deletion result
279
+ */
280
+ delete() {
281
+ return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
282
+ method: "DELETE"
283
+ });
284
+ }
285
+ /**
286
+ * Retrieves messages associated with the thread
287
+ * @returns Promise containing thread messages and UI messages
288
+ */
289
+ getMessages() {
290
+ return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
291
+ }
292
+ };
293
+
294
+ // src/resources/vector.ts
295
+ var Vector = class extends BaseResource {
296
+ constructor(options, vectorName) {
297
+ super(options);
298
+ this.vectorName = vectorName;
299
+ }
300
+ /**
301
+ * Retrieves details about a specific vector index
302
+ * @param indexName - Name of the index to get details for
303
+ * @returns Promise containing vector index details
304
+ */
305
+ details(indexName) {
306
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
307
+ }
308
+ /**
309
+ * Deletes a vector index
310
+ * @param indexName - Name of the index to delete
311
+ * @returns Promise indicating deletion success
312
+ */
313
+ delete(indexName) {
314
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
315
+ method: "DELETE"
316
+ });
317
+ }
318
+ /**
319
+ * Retrieves a list of all available indexes
320
+ * @returns Promise containing array of index names
321
+ */
322
+ getIndexes() {
323
+ return this.request(`/api/vector/${this.vectorName}/indexes`);
324
+ }
325
+ /**
326
+ * Creates a new vector index
327
+ * @param params - Parameters for index creation including dimension and metric
328
+ * @returns Promise indicating creation success
329
+ */
330
+ createIndex(params) {
331
+ return this.request(`/api/vector/${this.vectorName}/create-index`, {
332
+ method: "POST",
333
+ body: params
334
+ });
335
+ }
336
+ /**
337
+ * Upserts vectors into an index
338
+ * @param params - Parameters containing vectors, metadata, and optional IDs
339
+ * @returns Promise containing array of vector IDs
340
+ */
341
+ upsert(params) {
342
+ return this.request(`/api/vector/${this.vectorName}/upsert`, {
343
+ method: "POST",
344
+ body: params
345
+ });
346
+ }
347
+ /**
348
+ * Queries vectors in an index
349
+ * @param params - Query parameters including query vector and search options
350
+ * @returns Promise containing query results
351
+ */
352
+ query(params) {
353
+ return this.request(`/api/vector/${this.vectorName}/query`, {
354
+ method: "POST",
355
+ body: params
356
+ });
357
+ }
358
+ };
359
+
360
+ // src/resources/workflow.ts
361
+ var RECORD_SEPARATOR = "";
362
+ var Workflow = class extends BaseResource {
363
+ constructor(options, workflowId) {
364
+ super(options);
365
+ this.workflowId = workflowId;
366
+ }
367
+ /**
368
+ * Retrieves details about the workflow
369
+ * @returns Promise containing workflow details including steps and graphs
370
+ */
371
+ details() {
372
+ return this.request(`/api/workflows/${this.workflowId}`);
373
+ }
374
+ /**
375
+ * @deprecated Use `startAsync` instead
376
+ * Executes the workflow with the provided parameters
377
+ * @param params - Parameters required for workflow execution
378
+ * @returns Promise containing the workflow execution results
379
+ */
380
+ execute(params) {
381
+ return this.request(`/api/workflows/${this.workflowId}/execute`, {
382
+ method: "POST",
383
+ body: params
384
+ });
385
+ }
386
+ /**
387
+ * Creates a new workflow run
388
+ * @returns Promise containing the generated run ID
389
+ */
390
+ createRun(params) {
391
+ const searchParams = new URLSearchParams();
392
+ if (!!params?.runId) {
393
+ searchParams.set("runId", params.runId);
394
+ }
395
+ return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
396
+ method: "POST"
397
+ });
398
+ }
399
+ /**
400
+ * Starts a workflow run synchronously without waiting for the workflow to complete
401
+ * @param params - Object containing the runId and triggerData
402
+ * @returns Promise containing success message
403
+ */
404
+ start(params) {
405
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
406
+ method: "POST",
407
+ body: params?.triggerData
408
+ });
409
+ }
410
+ /**
411
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
412
+ * @param stepId - ID of the step to resume
413
+ * @param runId - ID of the workflow run
414
+ * @param context - Context to resume the workflow with
415
+ * @returns Promise containing the workflow resume results
416
+ */
417
+ resume({
418
+ stepId,
419
+ runId,
420
+ context
421
+ }) {
422
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
423
+ method: "POST",
424
+ body: {
425
+ stepId,
426
+ context
427
+ }
428
+ });
429
+ }
430
+ /**
431
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
432
+ * @param params - Object containing the optional runId and triggerData
433
+ * @returns Promise containing the workflow execution results
434
+ */
435
+ startAsync(params) {
436
+ const searchParams = new URLSearchParams();
437
+ if (!!params?.runId) {
438
+ searchParams.set("runId", params.runId);
439
+ }
440
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
441
+ method: "POST",
442
+ body: params?.triggerData
443
+ });
444
+ }
445
+ /**
446
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
447
+ * @param params - Object containing the runId, stepId, and context
448
+ * @returns Promise containing the workflow resume results
449
+ */
450
+ resumeAsync(params) {
451
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
452
+ method: "POST",
453
+ body: {
454
+ stepId: params.stepId,
455
+ context: params.context
456
+ }
457
+ });
458
+ }
459
+ /**
460
+ * Creates an async generator that processes a readable stream and yields records
461
+ * separated by the Record Separator character (\x1E)
462
+ *
463
+ * @param stream - The readable stream to process
464
+ * @returns An async generator that yields parsed records
465
+ */
466
+ async *streamProcessor(stream) {
467
+ const reader = stream.getReader();
468
+ let doneReading = false;
469
+ let buffer = "";
470
+ try {
471
+ while (!doneReading) {
472
+ const { done, value } = await reader.read();
473
+ doneReading = done;
474
+ if (done && !value) continue;
475
+ try {
476
+ const decoded = value ? new TextDecoder().decode(value) : "";
477
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
478
+ buffer = chunks.pop() || "";
479
+ for (const chunk of chunks) {
480
+ if (chunk) {
481
+ if (typeof chunk === "string") {
482
+ try {
483
+ const parsedChunk = JSON.parse(chunk);
484
+ yield parsedChunk;
485
+ } catch {
486
+ }
487
+ }
488
+ }
489
+ }
490
+ } catch (error) {
491
+ }
492
+ }
493
+ if (buffer) {
494
+ try {
495
+ yield JSON.parse(buffer);
496
+ } catch {
497
+ }
498
+ }
499
+ } finally {
500
+ reader.cancel().catch(() => {
501
+ });
502
+ }
503
+ }
504
+ /**
505
+ * Watches workflow transitions in real-time
506
+ * @param runId - Optional run ID to filter the watch stream
507
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
508
+ */
509
+ async watch({ runId }, onRecord) {
510
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
511
+ stream: true
512
+ });
513
+ if (!response.ok) {
514
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
515
+ }
516
+ if (!response.body) {
517
+ throw new Error("Response body is null");
518
+ }
519
+ for await (const record of this.streamProcessor(response.body)) {
520
+ onRecord(record);
521
+ }
522
+ }
523
+ };
524
+
525
+ // src/resources/tool.ts
526
+ var Tool = class extends BaseResource {
527
+ constructor(options, toolId) {
528
+ super(options);
529
+ this.toolId = toolId;
530
+ }
531
+ /**
532
+ * Retrieves details about the tool
533
+ * @returns Promise containing tool details including description and schemas
534
+ */
535
+ details() {
536
+ return this.request(`/api/tools/${this.toolId}`);
537
+ }
538
+ /**
539
+ * Executes the tool with the provided parameters
540
+ * @param params - Parameters required for tool execution
541
+ * @returns Promise containing the tool execution results
542
+ */
543
+ execute(params) {
544
+ return this.request(`/api/tools/${this.toolId}/execute`, {
545
+ method: "POST",
546
+ body: params
547
+ });
548
+ }
549
+ };
550
+
551
+ // src/resources/a2a.ts
552
+ var A2A = class extends BaseResource {
553
+ /**
554
+ * Sends an A2A protocol request to the server
555
+ * @param request - The A2A protocol request
556
+ * @returns Promise containing the A2A protocol response
557
+ */
558
+ sendRequest(request) {
559
+ return this.request("/api/a2a", {
560
+ method: "POST",
561
+ body: request
562
+ });
563
+ }
564
+ /**
565
+ * Sends a task to an agent using the A2A protocol
566
+ * @param params - Parameters for sending the task
567
+ * @returns Promise containing the task
568
+ */
569
+ sendTask(params) {
570
+ const request = {
571
+ jsonrpc: "2.0",
572
+ id: `send-${Date.now()}`,
573
+ method: "tasks/send",
574
+ params
575
+ };
576
+ return this.sendRequest(request).then((response) => {
577
+ if ("error" in response) {
578
+ throw new Error(response.error.message);
579
+ }
580
+ return response.result;
581
+ });
582
+ }
583
+ /**
584
+ * Gets a task by ID using the A2A protocol
585
+ * @param params - Parameters for getting the task
586
+ * @returns Promise containing the task
587
+ */
588
+ getTask(params) {
589
+ const request = {
590
+ jsonrpc: "2.0",
591
+ id: `get-${Date.now()}`,
592
+ method: "tasks/get",
593
+ params
594
+ };
595
+ return this.sendRequest(request).then((response) => {
596
+ if ("error" in response) {
597
+ throw new Error(response.error.message);
598
+ }
599
+ return response.result;
600
+ });
601
+ }
602
+ /**
603
+ * Cancels a task by ID using the A2A protocol
604
+ * @param params - Parameters for canceling the task
605
+ * @returns Promise containing the task
606
+ */
607
+ cancelTask(params) {
608
+ const request = {
609
+ jsonrpc: "2.0",
610
+ id: `cancel-${Date.now()}`,
611
+ method: "tasks/cancel",
612
+ params
613
+ };
614
+ return this.sendRequest(request).then((response) => {
615
+ if ("error" in response) {
616
+ throw new Error(response.error.message);
617
+ }
618
+ return response.result;
619
+ });
620
+ }
621
+ /**
622
+ * Gets the agent card for the A2A protocol
623
+ * @returns Promise containing the agent card
624
+ */
625
+ getAgentCard() {
626
+ return this.request("/api/a2a/agent-card");
627
+ }
628
+ };
629
+
630
+ // src/client.ts
631
+ var MastraClient = class extends BaseResource {
632
+ constructor(options) {
633
+ super(options);
634
+ }
635
+ /**
636
+ * Retrieves all available agents
637
+ * @returns Promise containing map of agent IDs to agent details
638
+ */
639
+ getAgents() {
640
+ return this.request("/api/agents");
641
+ }
642
+ /**
643
+ * Gets an agent instance by ID
644
+ * @param agentId - ID of the agent to retrieve
645
+ * @returns Agent instance
646
+ */
647
+ getAgent(agentId) {
648
+ return new Agent(this.options, agentId);
649
+ }
650
+ /**
651
+ * Retrieves memory threads for a resource
652
+ * @param params - Parameters containing the resource ID
653
+ * @returns Promise containing array of memory threads
654
+ */
655
+ getMemoryThreads(params) {
656
+ return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
657
+ }
658
+ /**
659
+ * Creates a new memory thread
660
+ * @param params - Parameters for creating the memory thread
661
+ * @returns Promise containing the created memory thread
662
+ */
663
+ createMemoryThread(params) {
664
+ return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
665
+ }
666
+ /**
667
+ * Gets a memory thread instance by ID
668
+ * @param threadId - ID of the memory thread to retrieve
669
+ * @returns MemoryThread instance
670
+ */
671
+ getMemoryThread(threadId, agentId) {
672
+ return new MemoryThread(this.options, threadId, agentId);
673
+ }
674
+ /**
675
+ * Saves messages to memory
676
+ * @param params - Parameters containing messages to save
677
+ * @returns Promise containing the saved messages
678
+ */
679
+ saveMessageToMemory(params) {
680
+ return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
681
+ method: "POST",
682
+ body: params
683
+ });
684
+ }
685
+ /**
686
+ * Gets the status of the memory system
687
+ * @returns Promise containing memory system status
688
+ */
689
+ getMemoryStatus(agentId) {
690
+ return this.request(`/api/memory/status?agentId=${agentId}`);
691
+ }
692
+ /**
693
+ * Retrieves all available tools
694
+ * @returns Promise containing map of tool IDs to tool details
695
+ */
696
+ getTools() {
697
+ return this.request("/api/tools");
698
+ }
699
+ /**
700
+ * Gets a tool instance by ID
701
+ * @param toolId - ID of the tool to retrieve
702
+ * @returns Tool instance
703
+ */
704
+ getTool(toolId) {
705
+ return new Tool(this.options, toolId);
706
+ }
707
+ /**
708
+ * Retrieves all available workflows
709
+ * @returns Promise containing map of workflow IDs to workflow details
710
+ */
711
+ getWorkflows() {
712
+ return this.request("/api/workflows");
713
+ }
714
+ /**
715
+ * Gets a workflow instance by ID
716
+ * @param workflowId - ID of the workflow to retrieve
717
+ * @returns Workflow instance
718
+ */
719
+ getWorkflow(workflowId) {
720
+ return new Workflow(this.options, workflowId);
721
+ }
722
+ /**
723
+ * Gets a vector instance by name
724
+ * @param vectorName - Name of the vector to retrieve
725
+ * @returns Vector instance
726
+ */
727
+ getVector(vectorName) {
728
+ return new Vector(this.options, vectorName);
729
+ }
730
+ /**
731
+ * Retrieves logs
732
+ * @param params - Parameters for filtering logs
733
+ * @returns Promise containing array of log messages
734
+ */
735
+ getLogs(params) {
736
+ return this.request(`/api/logs?transportId=${params.transportId}`);
737
+ }
738
+ /**
739
+ * Gets logs for a specific run
740
+ * @param params - Parameters containing run ID to retrieve
741
+ * @returns Promise containing array of log messages
742
+ */
743
+ getLogForRun(params) {
744
+ return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
745
+ }
746
+ /**
747
+ * List of all log transports
748
+ * @returns Promise containing list of log transports
749
+ */
750
+ getLogTransports() {
751
+ return this.request("/api/logs/transports");
752
+ }
753
+ /**
754
+ * List of all traces (paged)
755
+ * @param params - Parameters for filtering traces
756
+ * @returns Promise containing telemetry data
757
+ */
758
+ getTelemetry(params) {
759
+ const { name, scope, page, perPage, attribute } = params || {};
760
+ const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
761
+ const searchParams = new URLSearchParams();
762
+ if (name) {
763
+ searchParams.set("name", name);
764
+ }
765
+ if (scope) {
766
+ searchParams.set("scope", scope);
767
+ }
768
+ if (page) {
769
+ searchParams.set("page", String(page));
770
+ }
771
+ if (perPage) {
772
+ searchParams.set("perPage", String(perPage));
773
+ }
774
+ if (_attribute) {
775
+ if (Array.isArray(_attribute)) {
776
+ for (const attr of _attribute) {
777
+ searchParams.append("attribute", attr);
778
+ }
779
+ } else {
780
+ searchParams.set("attribute", _attribute);
781
+ }
782
+ }
783
+ if (searchParams.size) {
784
+ return this.request(`/api/telemetry?${searchParams}`);
785
+ } else {
786
+ return this.request(`/api/telemetry`);
787
+ }
788
+ }
789
+ /**
790
+ * Retrieves all available networks
791
+ * @returns Promise containing map of network IDs to network details
792
+ */
793
+ getNetworks() {
794
+ return this.request("/api/networks");
795
+ }
796
+ /**
797
+ * Gets a network instance by ID
798
+ * @param networkId - ID of the network to retrieve
799
+ * @returns Network instance
800
+ */
801
+ getNetwork(networkId) {
802
+ return new Network(this.options, networkId);
803
+ }
804
+ /**
805
+ * Gets an A2A protocol instance for agent-to-agent communication
806
+ * @returns A2A instance
807
+ */
808
+ getA2A() {
809
+ return new A2A(this.options);
810
+ }
811
+ };
812
+
813
+ // src/types.ts
814
+ var TaskState = /* @__PURE__ */ ((TaskState2) => {
815
+ TaskState2["PENDING"] = "pending";
816
+ TaskState2["RUNNING"] = "running";
817
+ TaskState2["COMPLETED"] = "completed";
818
+ TaskState2["FAILED"] = "failed";
819
+ TaskState2["CANCELED"] = "canceled";
820
+ return TaskState2;
821
+ })(TaskState || {});
822
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
823
+ ErrorCode2[ErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
824
+ ErrorCode2[ErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
825
+ ErrorCode2[ErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
826
+ ErrorCode2[ErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
827
+ ErrorCode2[ErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
828
+ ErrorCode2[ErrorCode2["TASK_NOT_FOUND"] = -32e3] = "TASK_NOT_FOUND";
829
+ ErrorCode2[ErrorCode2["TASK_NOT_CANCELABLE"] = -32001] = "TASK_NOT_CANCELABLE";
830
+ return ErrorCode2;
831
+ })(ErrorCode || {});
832
+
833
+ export { ErrorCode, MastraClient, TaskState };