@mastra/client-js 0.0.0-separate-trace-data-from-component-20250501042644 → 0.0.0-share-agent-metadata-with-cloud-20250718110128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,236 @@
1
1
  'use strict';
2
2
 
3
+ var client = require('@ag-ui/client');
4
+ var rxjs = require('rxjs');
3
5
  var uiUtils = require('@ai-sdk/ui-utils');
4
6
  var zod = require('zod');
5
- var zodToJsonSchema = require('zod-to-json-schema');
7
+ var originalZodToJsonSchema = require('zod-to-json-schema');
8
+ var tools = require('@mastra/core/tools');
9
+ var uuid = require('@lukeed/uuid');
10
+ var runtimeContext = require('@mastra/core/runtime-context');
6
11
 
7
- // src/resources/agent.ts
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
15
+
16
+ // src/adapters/agui.ts
17
+ var AGUIAdapter = class extends client.AbstractAgent {
18
+ agent;
19
+ resourceId;
20
+ constructor({ agent, agentId, resourceId, ...rest }) {
21
+ super({
22
+ agentId,
23
+ ...rest
24
+ });
25
+ this.agent = agent;
26
+ this.resourceId = resourceId;
27
+ }
28
+ run(input) {
29
+ return new rxjs.Observable((subscriber) => {
30
+ const convertedMessages = convertMessagesToMastraMessages(input.messages);
31
+ subscriber.next({
32
+ type: client.EventType.RUN_STARTED,
33
+ threadId: input.threadId,
34
+ runId: input.runId
35
+ });
36
+ this.agent.stream({
37
+ threadId: input.threadId,
38
+ resourceId: this.resourceId ?? "",
39
+ runId: input.runId,
40
+ messages: convertedMessages,
41
+ clientTools: input.tools.reduce(
42
+ (acc, tool) => {
43
+ acc[tool.name] = {
44
+ id: tool.name,
45
+ description: tool.description,
46
+ inputSchema: tool.parameters
47
+ };
48
+ return acc;
49
+ },
50
+ {}
51
+ )
52
+ }).then((response) => {
53
+ let currentMessageId = void 0;
54
+ let isInTextMessage = false;
55
+ return response.processDataStream({
56
+ onTextPart: (text) => {
57
+ if (currentMessageId === void 0) {
58
+ currentMessageId = generateUUID();
59
+ const message2 = {
60
+ type: client.EventType.TEXT_MESSAGE_START,
61
+ messageId: currentMessageId,
62
+ role: "assistant"
63
+ };
64
+ subscriber.next(message2);
65
+ isInTextMessage = true;
66
+ }
67
+ const message = {
68
+ type: client.EventType.TEXT_MESSAGE_CONTENT,
69
+ messageId: currentMessageId,
70
+ delta: text
71
+ };
72
+ subscriber.next(message);
73
+ },
74
+ onFinishMessagePart: () => {
75
+ if (currentMessageId !== void 0) {
76
+ const message = {
77
+ type: client.EventType.TEXT_MESSAGE_END,
78
+ messageId: currentMessageId
79
+ };
80
+ subscriber.next(message);
81
+ isInTextMessage = false;
82
+ }
83
+ subscriber.next({
84
+ type: client.EventType.RUN_FINISHED,
85
+ threadId: input.threadId,
86
+ runId: input.runId
87
+ });
88
+ subscriber.complete();
89
+ },
90
+ onToolCallPart(streamPart) {
91
+ const parentMessageId = currentMessageId || generateUUID();
92
+ if (isInTextMessage) {
93
+ const message = {
94
+ type: client.EventType.TEXT_MESSAGE_END,
95
+ messageId: parentMessageId
96
+ };
97
+ subscriber.next(message);
98
+ isInTextMessage = false;
99
+ }
100
+ subscriber.next({
101
+ type: client.EventType.TOOL_CALL_START,
102
+ toolCallId: streamPart.toolCallId,
103
+ toolCallName: streamPart.toolName,
104
+ parentMessageId
105
+ });
106
+ subscriber.next({
107
+ type: client.EventType.TOOL_CALL_ARGS,
108
+ toolCallId: streamPart.toolCallId,
109
+ delta: JSON.stringify(streamPart.args),
110
+ parentMessageId
111
+ });
112
+ subscriber.next({
113
+ type: client.EventType.TOOL_CALL_END,
114
+ toolCallId: streamPart.toolCallId,
115
+ parentMessageId
116
+ });
117
+ }
118
+ });
119
+ }).catch((error) => {
120
+ console.error("error", error);
121
+ subscriber.error(error);
122
+ });
123
+ return () => {
124
+ };
125
+ });
126
+ }
127
+ };
128
+ function generateUUID() {
129
+ if (typeof crypto !== "undefined") {
130
+ if (typeof crypto.randomUUID === "function") {
131
+ return crypto.randomUUID();
132
+ }
133
+ if (typeof crypto.getRandomValues === "function") {
134
+ const buffer = new Uint8Array(16);
135
+ crypto.getRandomValues(buffer);
136
+ buffer[6] = buffer[6] & 15 | 64;
137
+ buffer[8] = buffer[8] & 63 | 128;
138
+ let hex = "";
139
+ for (let i = 0; i < 16; i++) {
140
+ hex += buffer[i].toString(16).padStart(2, "0");
141
+ if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
142
+ }
143
+ return hex;
144
+ }
145
+ }
146
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
147
+ const r = Math.random() * 16 | 0;
148
+ const v = c === "x" ? r : r & 3 | 8;
149
+ return v.toString(16);
150
+ });
151
+ }
152
+ function convertMessagesToMastraMessages(messages) {
153
+ const result = [];
154
+ for (const message of messages) {
155
+ if (message.role === "assistant") {
156
+ const parts = message.content ? [{ type: "text", text: message.content }] : [];
157
+ for (const toolCall of message.toolCalls ?? []) {
158
+ parts.push({
159
+ type: "tool-call",
160
+ toolCallId: toolCall.id,
161
+ toolName: toolCall.function.name,
162
+ args: JSON.parse(toolCall.function.arguments)
163
+ });
164
+ }
165
+ result.push({
166
+ role: "assistant",
167
+ content: parts
168
+ });
169
+ if (message.toolCalls?.length) {
170
+ result.push({
171
+ role: "tool",
172
+ content: message.toolCalls.map((toolCall) => ({
173
+ type: "tool-result",
174
+ toolCallId: toolCall.id,
175
+ toolName: toolCall.function.name,
176
+ result: JSON.parse(toolCall.function.arguments)
177
+ }))
178
+ });
179
+ }
180
+ } else if (message.role === "user") {
181
+ result.push({
182
+ role: "user",
183
+ content: message.content || ""
184
+ });
185
+ } else if (message.role === "tool") {
186
+ result.push({
187
+ role: "tool",
188
+ content: [
189
+ {
190
+ type: "tool-result",
191
+ toolCallId: message.toolCallId,
192
+ toolName: "unknown",
193
+ result: message.content
194
+ }
195
+ ]
196
+ });
197
+ }
198
+ }
199
+ return result;
200
+ }
201
+ function zodToJsonSchema(zodSchema) {
202
+ if (!(zodSchema instanceof zod.ZodSchema)) {
203
+ return zodSchema;
204
+ }
205
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
206
+ }
207
+ function processClientTools(clientTools) {
208
+ if (!clientTools) {
209
+ return void 0;
210
+ }
211
+ return Object.fromEntries(
212
+ Object.entries(clientTools).map(([key, value]) => {
213
+ if (tools.isVercelTool(value)) {
214
+ return [
215
+ key,
216
+ {
217
+ ...value,
218
+ parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
219
+ }
220
+ ];
221
+ } else {
222
+ return [
223
+ key,
224
+ {
225
+ ...value,
226
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
227
+ outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
228
+ }
229
+ ];
230
+ }
231
+ })
232
+ );
233
+ }
8
234
 
9
235
  // src/resources/base.ts
10
236
  var BaseResource = class {
@@ -24,14 +250,16 @@ var BaseResource = class {
24
250
  let delay = backoffMs;
25
251
  for (let attempt = 0; attempt <= retries; attempt++) {
26
252
  try {
27
- const response = await fetch(`${baseUrl}${path}`, {
253
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
28
254
  ...options,
29
255
  headers: {
256
+ ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
30
257
  ...headers,
31
258
  ...options.headers
32
259
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
33
260
  // 'x-mastra-client-type': 'js',
34
261
  },
262
+ signal: this.options.abortSignal,
35
263
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
36
264
  });
37
265
  if (!response.ok) {
@@ -64,8 +292,15 @@ var BaseResource = class {
64
292
  throw lastError || new Error("Request failed");
65
293
  }
66
294
  };
67
-
68
- // src/resources/agent.ts
295
+ function parseClientRuntimeContext(runtimeContext$1) {
296
+ if (runtimeContext$1) {
297
+ if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
298
+ return Object.fromEntries(runtimeContext$1.entries());
299
+ }
300
+ return runtimeContext$1;
301
+ }
302
+ return void 0;
303
+ }
69
304
  var AgentVoice = class extends BaseResource {
70
305
  constructor(options, agentId) {
71
306
  super(options);
@@ -112,6 +347,13 @@ var AgentVoice = class extends BaseResource {
112
347
  getSpeakers() {
113
348
  return this.request(`/api/agents/${this.agentId}/voice/speakers`);
114
349
  }
350
+ /**
351
+ * Get the listener configuration for the agent's voice provider
352
+ * @returns Promise containing a check if the agent has listening capabilities
353
+ */
354
+ getListener() {
355
+ return this.request(`/api/agents/${this.agentId}/voice/listener`);
356
+ }
115
357
  };
116
358
  var Agent = class extends BaseResource {
117
359
  constructor(options, agentId) {
@@ -127,33 +369,341 @@ var Agent = class extends BaseResource {
127
369
  details() {
128
370
  return this.request(`/api/agents/${this.agentId}`);
129
371
  }
130
- /**
131
- * Generates a response from the agent
132
- * @param params - Generation parameters including prompt
133
- * @returns Promise containing the generated response
134
- */
135
- generate(params) {
372
+ async generate(params) {
136
373
  const processedParams = {
137
374
  ...params,
138
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
139
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
375
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
376
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
377
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
378
+ clientTools: processClientTools(params.clientTools)
140
379
  };
141
- return this.request(`/api/agents/${this.agentId}/generate`, {
380
+ const { runId, resourceId, threadId, runtimeContext } = processedParams;
381
+ const response = await this.request(`/api/agents/${this.agentId}/generate`, {
142
382
  method: "POST",
143
383
  body: processedParams
144
384
  });
385
+ if (response.finishReason === "tool-calls") {
386
+ const toolCalls = response.toolCalls;
387
+ if (!toolCalls || !Array.isArray(toolCalls)) {
388
+ return response;
389
+ }
390
+ for (const toolCall of toolCalls) {
391
+ const clientTool = params.clientTools?.[toolCall.toolName];
392
+ if (clientTool && clientTool.execute) {
393
+ const result = await clientTool.execute(
394
+ { context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
395
+ {
396
+ messages: response.messages,
397
+ toolCallId: toolCall?.toolCallId
398
+ }
399
+ );
400
+ const updatedMessages = [
401
+ {
402
+ role: "user",
403
+ content: params.messages
404
+ },
405
+ ...response.response.messages,
406
+ {
407
+ role: "tool",
408
+ content: [
409
+ {
410
+ type: "tool-result",
411
+ toolCallId: toolCall.toolCallId,
412
+ toolName: toolCall.toolName,
413
+ result
414
+ }
415
+ ]
416
+ }
417
+ ];
418
+ return this.generate({
419
+ ...params,
420
+ messages: updatedMessages
421
+ });
422
+ }
423
+ }
424
+ }
425
+ return response;
426
+ }
427
+ async processChatResponse({
428
+ stream,
429
+ update,
430
+ onToolCall,
431
+ onFinish,
432
+ getCurrentDate = () => /* @__PURE__ */ new Date(),
433
+ lastMessage,
434
+ streamProtocol
435
+ }) {
436
+ const replaceLastMessage = lastMessage?.role === "assistant";
437
+ let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
438
+ (lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
439
+ return Math.max(max, toolInvocation.step ?? 0);
440
+ }, 0) ?? 0) : 0;
441
+ const message = replaceLastMessage ? structuredClone(lastMessage) : {
442
+ id: uuid.v4(),
443
+ createdAt: getCurrentDate(),
444
+ role: "assistant",
445
+ content: "",
446
+ parts: []
447
+ };
448
+ let currentTextPart = void 0;
449
+ let currentReasoningPart = void 0;
450
+ let currentReasoningTextDetail = void 0;
451
+ function updateToolInvocationPart(toolCallId, invocation) {
452
+ const part = message.parts.find(
453
+ (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
454
+ );
455
+ if (part != null) {
456
+ part.toolInvocation = invocation;
457
+ } else {
458
+ message.parts.push({
459
+ type: "tool-invocation",
460
+ toolInvocation: invocation
461
+ });
462
+ }
463
+ }
464
+ const data = [];
465
+ let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
466
+ const partialToolCalls = {};
467
+ let usage = {
468
+ completionTokens: NaN,
469
+ promptTokens: NaN,
470
+ totalTokens: NaN
471
+ };
472
+ let finishReason = "unknown";
473
+ function execUpdate() {
474
+ const copiedData = [...data];
475
+ if (messageAnnotations?.length) {
476
+ message.annotations = messageAnnotations;
477
+ }
478
+ const copiedMessage = {
479
+ // deep copy the message to ensure that deep changes (msg attachments) are updated
480
+ // with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
481
+ ...structuredClone(message),
482
+ // add a revision id to ensure that the message is updated with SWR. SWR uses a
483
+ // hashing approach by default to detect changes, but it only works for shallow
484
+ // changes. This is why we need to add a revision id to ensure that the message
485
+ // is updated with SWR (without it, the changes get stuck in SWR and are not
486
+ // forwarded to rendering):
487
+ revisionId: uuid.v4()
488
+ };
489
+ update({
490
+ message: copiedMessage,
491
+ data: copiedData,
492
+ replaceLastMessage
493
+ });
494
+ }
495
+ if (streamProtocol === "text") {
496
+ await uiUtils.processTextStream({
497
+ stream,
498
+ onTextPart(value) {
499
+ message.content += value;
500
+ execUpdate();
501
+ }
502
+ });
503
+ onFinish?.({ message, finishReason, usage });
504
+ } else {
505
+ await uiUtils.processDataStream({
506
+ stream,
507
+ onTextPart(value) {
508
+ if (currentTextPart == null) {
509
+ currentTextPart = {
510
+ type: "text",
511
+ text: value
512
+ };
513
+ message.parts.push(currentTextPart);
514
+ } else {
515
+ currentTextPart.text += value;
516
+ }
517
+ message.content += value;
518
+ execUpdate();
519
+ },
520
+ onReasoningPart(value) {
521
+ if (currentReasoningTextDetail == null) {
522
+ currentReasoningTextDetail = { type: "text", text: value };
523
+ if (currentReasoningPart != null) {
524
+ currentReasoningPart.details.push(currentReasoningTextDetail);
525
+ }
526
+ } else {
527
+ currentReasoningTextDetail.text += value;
528
+ }
529
+ if (currentReasoningPart == null) {
530
+ currentReasoningPart = {
531
+ type: "reasoning",
532
+ reasoning: value,
533
+ details: [currentReasoningTextDetail]
534
+ };
535
+ message.parts.push(currentReasoningPart);
536
+ } else {
537
+ currentReasoningPart.reasoning += value;
538
+ }
539
+ message.reasoning = (message.reasoning ?? "") + value;
540
+ execUpdate();
541
+ },
542
+ onReasoningSignaturePart(value) {
543
+ if (currentReasoningTextDetail != null) {
544
+ currentReasoningTextDetail.signature = value.signature;
545
+ }
546
+ },
547
+ onRedactedReasoningPart(value) {
548
+ if (currentReasoningPart == null) {
549
+ currentReasoningPart = {
550
+ type: "reasoning",
551
+ reasoning: "",
552
+ details: []
553
+ };
554
+ message.parts.push(currentReasoningPart);
555
+ }
556
+ currentReasoningPart.details.push({
557
+ type: "redacted",
558
+ data: value.data
559
+ });
560
+ currentReasoningTextDetail = void 0;
561
+ execUpdate();
562
+ },
563
+ onFilePart(value) {
564
+ message.parts.push({
565
+ type: "file",
566
+ mimeType: value.mimeType,
567
+ data: value.data
568
+ });
569
+ execUpdate();
570
+ },
571
+ onSourcePart(value) {
572
+ message.parts.push({
573
+ type: "source",
574
+ source: value
575
+ });
576
+ execUpdate();
577
+ },
578
+ onToolCallStreamingStartPart(value) {
579
+ if (message.toolInvocations == null) {
580
+ message.toolInvocations = [];
581
+ }
582
+ partialToolCalls[value.toolCallId] = {
583
+ text: "",
584
+ step,
585
+ toolName: value.toolName,
586
+ index: message.toolInvocations.length
587
+ };
588
+ const invocation = {
589
+ state: "partial-call",
590
+ step,
591
+ toolCallId: value.toolCallId,
592
+ toolName: value.toolName,
593
+ args: void 0
594
+ };
595
+ message.toolInvocations.push(invocation);
596
+ updateToolInvocationPart(value.toolCallId, invocation);
597
+ execUpdate();
598
+ },
599
+ onToolCallDeltaPart(value) {
600
+ const partialToolCall = partialToolCalls[value.toolCallId];
601
+ partialToolCall.text += value.argsTextDelta;
602
+ const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
603
+ const invocation = {
604
+ state: "partial-call",
605
+ step: partialToolCall.step,
606
+ toolCallId: value.toolCallId,
607
+ toolName: partialToolCall.toolName,
608
+ args: partialArgs
609
+ };
610
+ message.toolInvocations[partialToolCall.index] = invocation;
611
+ updateToolInvocationPart(value.toolCallId, invocation);
612
+ execUpdate();
613
+ },
614
+ async onToolCallPart(value) {
615
+ const invocation = {
616
+ state: "call",
617
+ step,
618
+ ...value
619
+ };
620
+ if (partialToolCalls[value.toolCallId] != null) {
621
+ message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
622
+ } else {
623
+ if (message.toolInvocations == null) {
624
+ message.toolInvocations = [];
625
+ }
626
+ message.toolInvocations.push(invocation);
627
+ }
628
+ updateToolInvocationPart(value.toolCallId, invocation);
629
+ execUpdate();
630
+ if (onToolCall) {
631
+ const result = await onToolCall({ toolCall: value });
632
+ if (result != null) {
633
+ const invocation2 = {
634
+ state: "result",
635
+ step,
636
+ ...value,
637
+ result
638
+ };
639
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
640
+ updateToolInvocationPart(value.toolCallId, invocation2);
641
+ execUpdate();
642
+ }
643
+ }
644
+ },
645
+ onToolResultPart(value) {
646
+ const toolInvocations = message.toolInvocations;
647
+ if (toolInvocations == null) {
648
+ throw new Error("tool_result must be preceded by a tool_call");
649
+ }
650
+ const toolInvocationIndex = toolInvocations.findIndex(
651
+ (invocation2) => invocation2.toolCallId === value.toolCallId
652
+ );
653
+ if (toolInvocationIndex === -1) {
654
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
655
+ }
656
+ const invocation = {
657
+ ...toolInvocations[toolInvocationIndex],
658
+ state: "result",
659
+ ...value
660
+ };
661
+ toolInvocations[toolInvocationIndex] = invocation;
662
+ updateToolInvocationPart(value.toolCallId, invocation);
663
+ execUpdate();
664
+ },
665
+ onDataPart(value) {
666
+ data.push(...value);
667
+ execUpdate();
668
+ },
669
+ onMessageAnnotationsPart(value) {
670
+ if (messageAnnotations == null) {
671
+ messageAnnotations = [...value];
672
+ } else {
673
+ messageAnnotations.push(...value);
674
+ }
675
+ execUpdate();
676
+ },
677
+ onFinishStepPart(value) {
678
+ step += 1;
679
+ currentTextPart = value.isContinued ? currentTextPart : void 0;
680
+ currentReasoningPart = void 0;
681
+ currentReasoningTextDetail = void 0;
682
+ },
683
+ onStartStepPart(value) {
684
+ if (!replaceLastMessage) {
685
+ message.id = value.messageId;
686
+ }
687
+ message.parts.push({ type: "step-start" });
688
+ execUpdate();
689
+ },
690
+ onFinishMessagePart(value) {
691
+ finishReason = value.finishReason;
692
+ if (value.usage != null) {
693
+ usage = value.usage;
694
+ }
695
+ },
696
+ onErrorPart(error) {
697
+ throw new Error(error);
698
+ }
699
+ });
700
+ onFinish?.({ message, finishReason, usage });
701
+ }
145
702
  }
146
703
  /**
147
- * Streams a response from the agent
148
- * @param params - Stream parameters including prompt
149
- * @returns Promise containing the enhanced Response object with processDataStream method
704
+ * Processes the stream response and handles tool calls
150
705
  */
151
- async stream(params) {
152
- const processedParams = {
153
- ...params,
154
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
155
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
156
- };
706
+ async processStreamResponse(processedParams, writable) {
157
707
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
158
708
  method: "POST",
159
709
  body: processedParams,
@@ -162,13 +712,135 @@ var Agent = class extends BaseResource {
162
712
  if (!response.body) {
163
713
  throw new Error("No response body");
164
714
  }
165
- response.processDataStream = async (options = {}) => {
715
+ try {
716
+ const streamProtocol = processedParams.output ? "text" : "data";
717
+ let toolCalls = [];
718
+ let messages = [];
719
+ const [streamForWritable, streamForProcessing] = response.body.tee();
720
+ streamForWritable.pipeTo(writable, {
721
+ preventClose: true
722
+ }).catch((error) => {
723
+ console.error("Error piping to writable stream:", error);
724
+ });
725
+ this.processChatResponse({
726
+ stream: streamForProcessing,
727
+ update: ({ message }) => {
728
+ messages.push(message);
729
+ },
730
+ onFinish: async ({ finishReason, message }) => {
731
+ if (finishReason === "tool-calls") {
732
+ const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
733
+ if (toolCall) {
734
+ toolCalls.push(toolCall);
735
+ }
736
+ for (const toolCall2 of toolCalls) {
737
+ const clientTool = processedParams.clientTools?.[toolCall2.toolName];
738
+ if (clientTool && clientTool.execute) {
739
+ const result = await clientTool.execute(
740
+ {
741
+ context: toolCall2?.args,
742
+ runId: processedParams.runId,
743
+ resourceId: processedParams.resourceId,
744
+ threadId: processedParams.threadId,
745
+ runtimeContext: processedParams.runtimeContext
746
+ },
747
+ {
748
+ messages: response.messages,
749
+ toolCallId: toolCall2?.toolCallId
750
+ }
751
+ );
752
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
753
+ const toolInvocationPart = lastMessage?.parts?.find(
754
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
755
+ );
756
+ if (toolInvocationPart) {
757
+ toolInvocationPart.toolInvocation = {
758
+ ...toolInvocationPart.toolInvocation,
759
+ state: "result",
760
+ result
761
+ };
762
+ }
763
+ const toolInvocation = lastMessage?.toolInvocations?.find(
764
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
765
+ );
766
+ if (toolInvocation) {
767
+ toolInvocation.state = "result";
768
+ toolInvocation.result = result;
769
+ }
770
+ const writer = writable.getWriter();
771
+ try {
772
+ await writer.write(
773
+ new TextEncoder().encode(
774
+ "a:" + JSON.stringify({
775
+ toolCallId: toolCall2.toolCallId,
776
+ result
777
+ }) + "\n"
778
+ )
779
+ );
780
+ } finally {
781
+ writer.releaseLock();
782
+ }
783
+ const originalMessages = processedParams.messages;
784
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
785
+ this.processStreamResponse(
786
+ {
787
+ ...processedParams,
788
+ messages: [...messageArray, ...messages, lastMessage]
789
+ },
790
+ writable
791
+ );
792
+ }
793
+ }
794
+ } else {
795
+ setTimeout(() => {
796
+ if (!writable.locked) {
797
+ writable.close();
798
+ }
799
+ }, 0);
800
+ }
801
+ },
802
+ lastMessage: void 0,
803
+ streamProtocol
804
+ });
805
+ } catch (error) {
806
+ console.error("Error processing stream response:", error);
807
+ }
808
+ return response;
809
+ }
810
+ /**
811
+ * Streams a response from the agent
812
+ * @param params - Stream parameters including prompt
813
+ * @returns Promise containing the enhanced Response object with processDataStream and processTextStream methods
814
+ */
815
+ async stream(params) {
816
+ const processedParams = {
817
+ ...params,
818
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
819
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
820
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
821
+ clientTools: processClientTools(params.clientTools)
822
+ };
823
+ const { readable, writable } = new TransformStream();
824
+ const response = await this.processStreamResponse(processedParams, writable);
825
+ const streamResponse = new Response(readable, {
826
+ status: response.status,
827
+ statusText: response.statusText,
828
+ headers: response.headers
829
+ });
830
+ streamResponse.processDataStream = async (options = {}) => {
166
831
  await uiUtils.processDataStream({
167
- stream: response.body,
832
+ stream: streamResponse.body,
168
833
  ...options
169
834
  });
170
835
  };
171
- return response;
836
+ streamResponse.processTextStream = async (options) => {
837
+ await uiUtils.processTextStream({
838
+ stream: streamResponse.body,
839
+ onTextPart: options?.onTextPart ?? (() => {
840
+ })
841
+ });
842
+ };
843
+ return streamResponse;
172
844
  }
173
845
  /**
174
846
  * Gets details about a specific tool available to the agent
@@ -178,6 +850,22 @@ var Agent = class extends BaseResource {
178
850
  getTool(toolId) {
179
851
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
180
852
  }
853
+ /**
854
+ * Executes a tool for the agent
855
+ * @param toolId - ID of the tool to execute
856
+ * @param params - Parameters required for tool execution
857
+ * @returns Promise containing the tool execution results
858
+ */
859
+ executeTool(toolId, params) {
860
+ const body = {
861
+ data: params.data,
862
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
863
+ };
864
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
865
+ method: "POST",
866
+ body
867
+ });
868
+ }
181
869
  /**
182
870
  * Retrieves evaluation results for the agent
183
871
  * @returns Promise containing agent evaluations
@@ -213,8 +901,8 @@ var Network = class extends BaseResource {
213
901
  generate(params) {
214
902
  const processedParams = {
215
903
  ...params,
216
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
217
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
904
+ output: zodToJsonSchema(params.output),
905
+ experimental_output: zodToJsonSchema(params.experimental_output)
218
906
  };
219
907
  return this.request(`/api/networks/${this.networkId}/generate`, {
220
908
  method: "POST",
@@ -229,8 +917,8 @@ var Network = class extends BaseResource {
229
917
  async stream(params) {
230
918
  const processedParams = {
231
919
  ...params,
232
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
233
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
920
+ output: zodToJsonSchema(params.output),
921
+ experimental_output: zodToJsonSchema(params.experimental_output)
234
922
  };
235
923
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
236
924
  method: "POST",
@@ -286,10 +974,15 @@ var MemoryThread = class extends BaseResource {
286
974
  }
287
975
  /**
288
976
  * Retrieves messages associated with the thread
977
+ * @param params - Optional parameters including limit for number of messages to retrieve
289
978
  * @returns Promise containing thread messages and UI messages
290
979
  */
291
- getMessages() {
292
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
980
+ getMessages(params) {
981
+ const query = new URLSearchParams({
982
+ agentId: this.agentId,
983
+ ...params?.limit ? { limit: params.limit.toString() } : {}
984
+ });
985
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
293
986
  }
294
987
  };
295
988
 
@@ -359,41 +1052,50 @@ var Vector = class extends BaseResource {
359
1052
  }
360
1053
  };
361
1054
 
362
- // src/resources/workflow.ts
1055
+ // src/resources/legacy-workflow.ts
363
1056
  var RECORD_SEPARATOR = "";
364
- var Workflow = class extends BaseResource {
1057
+ var LegacyWorkflow = class extends BaseResource {
365
1058
  constructor(options, workflowId) {
366
1059
  super(options);
367
1060
  this.workflowId = workflowId;
368
1061
  }
369
1062
  /**
370
- * Retrieves details about the workflow
371
- * @returns Promise containing workflow details including steps and graphs
1063
+ * Retrieves details about the legacy workflow
1064
+ * @returns Promise containing legacy workflow details including steps and graphs
372
1065
  */
373
1066
  details() {
374
- return this.request(`/api/workflows/${this.workflowId}`);
375
- }
376
- /**
377
- * Retrieves all runs for a workflow
378
- * @returns Promise containing workflow runs array
379
- */
380
- runs() {
381
- return this.request(`/api/workflows/${this.workflowId}/runs`);
1067
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
382
1068
  }
383
1069
  /**
384
- * @deprecated Use `startAsync` instead
385
- * Executes the workflow with the provided parameters
386
- * @param params - Parameters required for workflow execution
387
- * @returns Promise containing the workflow execution results
1070
+ * Retrieves all runs for a legacy workflow
1071
+ * @param params - Parameters for filtering runs
1072
+ * @returns Promise containing legacy workflow runs array
388
1073
  */
389
- execute(params) {
390
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
391
- method: "POST",
392
- body: params
393
- });
1074
+ runs(params) {
1075
+ const searchParams = new URLSearchParams();
1076
+ if (params?.fromDate) {
1077
+ searchParams.set("fromDate", params.fromDate.toISOString());
1078
+ }
1079
+ if (params?.toDate) {
1080
+ searchParams.set("toDate", params.toDate.toISOString());
1081
+ }
1082
+ if (params?.limit) {
1083
+ searchParams.set("limit", String(params.limit));
1084
+ }
1085
+ if (params?.offset) {
1086
+ searchParams.set("offset", String(params.offset));
1087
+ }
1088
+ if (params?.resourceId) {
1089
+ searchParams.set("resourceId", params.resourceId);
1090
+ }
1091
+ if (searchParams.size) {
1092
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1093
+ } else {
1094
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1095
+ }
394
1096
  }
395
1097
  /**
396
- * Creates a new workflow run
1098
+ * Creates a new legacy workflow run
397
1099
  * @returns Promise containing the generated run ID
398
1100
  */
399
1101
  createRun(params) {
@@ -401,34 +1103,34 @@ var Workflow = class extends BaseResource {
401
1103
  if (!!params?.runId) {
402
1104
  searchParams.set("runId", params.runId);
403
1105
  }
404
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
1106
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
405
1107
  method: "POST"
406
1108
  });
407
1109
  }
408
1110
  /**
409
- * Starts a workflow run synchronously without waiting for the workflow to complete
1111
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
410
1112
  * @param params - Object containing the runId and triggerData
411
1113
  * @returns Promise containing success message
412
1114
  */
413
1115
  start(params) {
414
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1116
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
415
1117
  method: "POST",
416
1118
  body: params?.triggerData
417
1119
  });
418
1120
  }
419
1121
  /**
420
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
1122
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
421
1123
  * @param stepId - ID of the step to resume
422
- * @param runId - ID of the workflow run
423
- * @param context - Context to resume the workflow with
424
- * @returns Promise containing the workflow resume results
1124
+ * @param runId - ID of the legacy workflow run
1125
+ * @param context - Context to resume the legacy workflow with
1126
+ * @returns Promise containing the legacy workflow resume results
425
1127
  */
426
1128
  resume({
427
1129
  stepId,
428
1130
  runId,
429
1131
  context
430
1132
  }) {
431
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1133
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
432
1134
  method: "POST",
433
1135
  body: {
434
1136
  stepId,
@@ -446,18 +1148,18 @@ var Workflow = class extends BaseResource {
446
1148
  if (!!params?.runId) {
447
1149
  searchParams.set("runId", params.runId);
448
1150
  }
449
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1151
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
450
1152
  method: "POST",
451
1153
  body: params?.triggerData
452
1154
  });
453
1155
  }
454
1156
  /**
455
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1157
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
456
1158
  * @param params - Object containing the runId, stepId, and context
457
1159
  * @returns Promise containing the workflow resume results
458
1160
  */
459
1161
  resumeAsync(params) {
460
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
1162
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
461
1163
  method: "POST",
462
1164
  body: {
463
1165
  stepId: params.stepId,
@@ -511,16 +1213,16 @@ var Workflow = class extends BaseResource {
511
1213
  }
512
1214
  }
513
1215
  /**
514
- * Watches workflow transitions in real-time
1216
+ * Watches legacy workflow transitions in real-time
515
1217
  * @param runId - Optional run ID to filter the watch stream
516
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
1218
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
517
1219
  */
518
1220
  async watch({ runId }, onRecord) {
519
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
1221
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
520
1222
  stream: true
521
1223
  });
522
1224
  if (!response.ok) {
523
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
1225
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
524
1226
  }
525
1227
  if (!response.body) {
526
1228
  throw new Error("Response body is null");
@@ -532,7 +1234,7 @@ var Workflow = class extends BaseResource {
532
1234
  };
533
1235
 
534
1236
  // src/resources/tool.ts
535
- var Tool = class extends BaseResource {
1237
+ var Tool2 = class extends BaseResource {
536
1238
  constructor(options, toolId) {
537
1239
  super(options);
538
1240
  this.toolId = toolId;
@@ -554,22 +1256,26 @@ var Tool = class extends BaseResource {
554
1256
  if (params.runId) {
555
1257
  url.set("runId", params.runId);
556
1258
  }
1259
+ const body = {
1260
+ data: params.data,
1261
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1262
+ };
557
1263
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
558
1264
  method: "POST",
559
- body: params.data
1265
+ body
560
1266
  });
561
1267
  }
562
1268
  };
563
1269
 
564
- // src/resources/vnext-workflow.ts
1270
+ // src/resources/workflow.ts
565
1271
  var RECORD_SEPARATOR2 = "";
566
- var VNextWorkflow = class extends BaseResource {
1272
+ var Workflow = class extends BaseResource {
567
1273
  constructor(options, workflowId) {
568
1274
  super(options);
569
1275
  this.workflowId = workflowId;
570
1276
  }
571
1277
  /**
572
- * Creates an async generator that processes a readable stream and yields vNext workflow records
1278
+ * Creates an async generator that processes a readable stream and yields workflow records
573
1279
  * separated by the Record Separator character (\x1E)
574
1280
  *
575
1281
  * @param stream - The readable stream to process
@@ -614,21 +1320,79 @@ var VNextWorkflow = class extends BaseResource {
614
1320
  }
615
1321
  }
616
1322
  /**
617
- * Retrieves details about the vNext workflow
618
- * @returns Promise containing vNext workflow details including steps and graphs
1323
+ * Retrieves details about the workflow
1324
+ * @returns Promise containing workflow details including steps and graphs
619
1325
  */
620
1326
  details() {
621
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
1327
+ return this.request(`/api/workflows/${this.workflowId}`);
1328
+ }
1329
+ /**
1330
+ * Retrieves all runs for a workflow
1331
+ * @param params - Parameters for filtering runs
1332
+ * @returns Promise containing workflow runs array
1333
+ */
1334
+ runs(params) {
1335
+ const searchParams = new URLSearchParams();
1336
+ if (params?.fromDate) {
1337
+ searchParams.set("fromDate", params.fromDate.toISOString());
1338
+ }
1339
+ if (params?.toDate) {
1340
+ searchParams.set("toDate", params.toDate.toISOString());
1341
+ }
1342
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1343
+ searchParams.set("limit", String(params.limit));
1344
+ }
1345
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1346
+ searchParams.set("offset", String(params.offset));
1347
+ }
1348
+ if (params?.resourceId) {
1349
+ searchParams.set("resourceId", params.resourceId);
1350
+ }
1351
+ if (searchParams.size) {
1352
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1353
+ } else {
1354
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
1355
+ }
1356
+ }
1357
+ /**
1358
+ * Retrieves a specific workflow run by its ID
1359
+ * @param runId - The ID of the workflow run to retrieve
1360
+ * @returns Promise containing the workflow run details
1361
+ */
1362
+ runById(runId) {
1363
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1364
+ }
1365
+ /**
1366
+ * Retrieves the execution result for a specific workflow run by its ID
1367
+ * @param runId - The ID of the workflow run to retrieve the execution result for
1368
+ * @returns Promise containing the workflow run execution result
1369
+ */
1370
+ runExecutionResult(runId) {
1371
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1372
+ }
1373
+ /**
1374
+ * Cancels a specific workflow run by its ID
1375
+ * @param runId - The ID of the workflow run to cancel
1376
+ * @returns Promise containing a success message
1377
+ */
1378
+ cancelRun(runId) {
1379
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
1380
+ method: "POST"
1381
+ });
622
1382
  }
623
1383
  /**
624
- * Retrieves all runs for a vNext workflow
625
- * @returns Promise containing vNext workflow runs array
1384
+ * Sends an event to a specific workflow run by its ID
1385
+ * @param params - Object containing the runId, event and data
1386
+ * @returns Promise containing a success message
626
1387
  */
627
- runs() {
628
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
1388
+ sendRunEvent(params) {
1389
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1390
+ method: "POST",
1391
+ body: { event: params.event, data: params.data }
1392
+ });
629
1393
  }
630
1394
  /**
631
- * Creates a new vNext workflow run
1395
+ * Creates a new workflow run
632
1396
  * @param params - Optional object containing the optional runId
633
1397
  * @returns Promise containing the runId of the created run
634
1398
  */
@@ -637,23 +1401,24 @@ var VNextWorkflow = class extends BaseResource {
637
1401
  if (!!params?.runId) {
638
1402
  searchParams.set("runId", params.runId);
639
1403
  }
640
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
1404
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
641
1405
  method: "POST"
642
1406
  });
643
1407
  }
644
1408
  /**
645
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
1409
+ * Starts a workflow run synchronously without waiting for the workflow to complete
646
1410
  * @param params - Object containing the runId, inputData and runtimeContext
647
1411
  * @returns Promise containing success message
648
1412
  */
649
1413
  start(params) {
650
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
1414
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1415
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
651
1416
  method: "POST",
652
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
1417
+ body: { inputData: params?.inputData, runtimeContext }
653
1418
  });
654
1419
  }
655
1420
  /**
656
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
1421
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
657
1422
  * @param params - Object containing the runId, step, resumeData and runtimeContext
658
1423
  * @returns Promise containing success message
659
1424
  */
@@ -661,9 +1426,10 @@ var VNextWorkflow = class extends BaseResource {
661
1426
  step,
662
1427
  runId,
663
1428
  resumeData,
664
- runtimeContext
1429
+ ...rest
665
1430
  }) {
666
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
1431
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1432
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
667
1433
  method: "POST",
668
1434
  stream: true,
669
1435
  body: {
@@ -674,52 +1440,426 @@ var VNextWorkflow = class extends BaseResource {
674
1440
  });
675
1441
  }
676
1442
  /**
677
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
1443
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
678
1444
  * @param params - Object containing the optional runId, inputData and runtimeContext
679
- * @returns Promise containing the vNext workflow execution results
1445
+ * @returns Promise containing the workflow execution results
680
1446
  */
681
1447
  startAsync(params) {
682
1448
  const searchParams = new URLSearchParams();
683
1449
  if (!!params?.runId) {
684
1450
  searchParams.set("runId", params.runId);
685
1451
  }
686
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
1452
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1453
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
687
1454
  method: "POST",
688
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
1455
+ body: { inputData: params.inputData, runtimeContext }
1456
+ });
1457
+ }
1458
+ /**
1459
+ * Starts a workflow run and returns a stream
1460
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1461
+ * @returns Promise containing the workflow execution results
1462
+ */
1463
+ async stream(params) {
1464
+ const searchParams = new URLSearchParams();
1465
+ if (!!params?.runId) {
1466
+ searchParams.set("runId", params.runId);
1467
+ }
1468
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1469
+ const response = await this.request(
1470
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1471
+ {
1472
+ method: "POST",
1473
+ body: { inputData: params.inputData, runtimeContext },
1474
+ stream: true
1475
+ }
1476
+ );
1477
+ if (!response.ok) {
1478
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1479
+ }
1480
+ if (!response.body) {
1481
+ throw new Error("Response body is null");
1482
+ }
1483
+ let failedChunk = void 0;
1484
+ const transformStream = new TransformStream({
1485
+ start() {
1486
+ },
1487
+ async transform(chunk, controller) {
1488
+ try {
1489
+ const decoded = new TextDecoder().decode(chunk);
1490
+ const chunks = decoded.split(RECORD_SEPARATOR2);
1491
+ for (const chunk2 of chunks) {
1492
+ if (chunk2) {
1493
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1494
+ try {
1495
+ const parsedChunk = JSON.parse(newChunk);
1496
+ controller.enqueue(parsedChunk);
1497
+ failedChunk = void 0;
1498
+ } catch (error) {
1499
+ failedChunk = newChunk;
1500
+ }
1501
+ }
1502
+ }
1503
+ } catch {
1504
+ }
1505
+ }
689
1506
  });
1507
+ return response.body.pipeThrough(transformStream);
690
1508
  }
691
1509
  /**
692
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1510
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
693
1511
  * @param params - Object containing the runId, step, resumeData and runtimeContext
694
- * @returns Promise containing the vNext workflow resume results
1512
+ * @returns Promise containing the workflow resume results
695
1513
  */
696
1514
  resumeAsync(params) {
697
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1515
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1516
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
698
1517
  method: "POST",
699
1518
  body: {
700
1519
  step: params.step,
701
1520
  resumeData: params.resumeData,
702
- runtimeContext: params.runtimeContext
1521
+ runtimeContext
703
1522
  }
704
1523
  });
705
1524
  }
706
1525
  /**
707
- * Watches vNext workflow transitions in real-time
1526
+ * Watches workflow transitions in real-time
708
1527
  * @param runId - Optional run ID to filter the watch stream
709
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1528
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
710
1529
  */
711
1530
  async watch({ runId }, onRecord) {
712
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1531
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
713
1532
  stream: true
714
1533
  });
715
1534
  if (!response.ok) {
716
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1535
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
717
1536
  }
718
1537
  if (!response.body) {
719
1538
  throw new Error("Response body is null");
720
1539
  }
721
1540
  for await (const record of this.streamProcessor(response.body)) {
722
- onRecord(record);
1541
+ if (typeof record === "string") {
1542
+ onRecord(JSON.parse(record));
1543
+ } else {
1544
+ onRecord(record);
1545
+ }
1546
+ }
1547
+ }
1548
+ /**
1549
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1550
+ * serializing each as JSON and separating them with the record separator (\x1E).
1551
+ *
1552
+ * @param records - An iterable or async iterable of objects to stream
1553
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1554
+ */
1555
+ static createRecordStream(records) {
1556
+ const encoder = new TextEncoder();
1557
+ return new ReadableStream({
1558
+ async start(controller) {
1559
+ try {
1560
+ for await (const record of records) {
1561
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1562
+ controller.enqueue(encoder.encode(json));
1563
+ }
1564
+ controller.close();
1565
+ } catch (err) {
1566
+ controller.error(err);
1567
+ }
1568
+ }
1569
+ });
1570
+ }
1571
+ };
1572
+
1573
+ // src/resources/a2a.ts
1574
+ var A2A = class extends BaseResource {
1575
+ constructor(options, agentId) {
1576
+ super(options);
1577
+ this.agentId = agentId;
1578
+ }
1579
+ /**
1580
+ * Get the agent card with metadata about the agent
1581
+ * @returns Promise containing the agent card information
1582
+ */
1583
+ async getCard() {
1584
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1585
+ }
1586
+ /**
1587
+ * Send a message to the agent and get a response
1588
+ * @param params - Parameters for the task
1589
+ * @returns Promise containing the task response
1590
+ */
1591
+ async sendMessage(params) {
1592
+ const response = await this.request(`/a2a/${this.agentId}`, {
1593
+ method: "POST",
1594
+ body: {
1595
+ method: "tasks/send",
1596
+ params
1597
+ }
1598
+ });
1599
+ return { task: response.result };
1600
+ }
1601
+ /**
1602
+ * Get the status and result of a task
1603
+ * @param params - Parameters for querying the task
1604
+ * @returns Promise containing the task response
1605
+ */
1606
+ async getTask(params) {
1607
+ const response = await this.request(`/a2a/${this.agentId}`, {
1608
+ method: "POST",
1609
+ body: {
1610
+ method: "tasks/get",
1611
+ params
1612
+ }
1613
+ });
1614
+ return response.result;
1615
+ }
1616
+ /**
1617
+ * Cancel a running task
1618
+ * @param params - Parameters identifying the task to cancel
1619
+ * @returns Promise containing the task response
1620
+ */
1621
+ async cancelTask(params) {
1622
+ return this.request(`/a2a/${this.agentId}`, {
1623
+ method: "POST",
1624
+ body: {
1625
+ method: "tasks/cancel",
1626
+ params
1627
+ }
1628
+ });
1629
+ }
1630
+ /**
1631
+ * Send a message and subscribe to streaming updates (not fully implemented)
1632
+ * @param params - Parameters for the task
1633
+ * @returns Promise containing the task response
1634
+ */
1635
+ async sendAndSubscribe(params) {
1636
+ return this.request(`/a2a/${this.agentId}`, {
1637
+ method: "POST",
1638
+ body: {
1639
+ method: "tasks/sendSubscribe",
1640
+ params
1641
+ },
1642
+ stream: true
1643
+ });
1644
+ }
1645
+ };
1646
+
1647
+ // src/resources/mcp-tool.ts
1648
+ var MCPTool = class extends BaseResource {
1649
+ serverId;
1650
+ toolId;
1651
+ constructor(options, serverId, toolId) {
1652
+ super(options);
1653
+ this.serverId = serverId;
1654
+ this.toolId = toolId;
1655
+ }
1656
+ /**
1657
+ * Retrieves details about this specific tool from the MCP server.
1658
+ * @returns Promise containing the tool's information (name, description, schema).
1659
+ */
1660
+ details() {
1661
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1662
+ }
1663
+ /**
1664
+ * Executes this specific tool on the MCP server.
1665
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1666
+ * @returns Promise containing the result of the tool execution.
1667
+ */
1668
+ execute(params) {
1669
+ const body = {};
1670
+ if (params.data !== void 0) body.data = params.data;
1671
+ if (params.runtimeContext !== void 0) {
1672
+ body.runtimeContext = params.runtimeContext;
1673
+ }
1674
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1675
+ method: "POST",
1676
+ body: Object.keys(body).length > 0 ? body : void 0
1677
+ });
1678
+ }
1679
+ };
1680
+
1681
+ // src/resources/network-memory-thread.ts
1682
+ var NetworkMemoryThread = class extends BaseResource {
1683
+ constructor(options, threadId, networkId) {
1684
+ super(options);
1685
+ this.threadId = threadId;
1686
+ this.networkId = networkId;
1687
+ }
1688
+ /**
1689
+ * Retrieves the memory thread details
1690
+ * @returns Promise containing thread details including title and metadata
1691
+ */
1692
+ get() {
1693
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1694
+ }
1695
+ /**
1696
+ * Updates the memory thread properties
1697
+ * @param params - Update parameters including title and metadata
1698
+ * @returns Promise containing updated thread details
1699
+ */
1700
+ update(params) {
1701
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1702
+ method: "PATCH",
1703
+ body: params
1704
+ });
1705
+ }
1706
+ /**
1707
+ * Deletes the memory thread
1708
+ * @returns Promise containing deletion result
1709
+ */
1710
+ delete() {
1711
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1712
+ method: "DELETE"
1713
+ });
1714
+ }
1715
+ /**
1716
+ * Retrieves messages associated with the thread
1717
+ * @param params - Optional parameters including limit for number of messages to retrieve
1718
+ * @returns Promise containing thread messages and UI messages
1719
+ */
1720
+ getMessages(params) {
1721
+ const query = new URLSearchParams({
1722
+ networkId: this.networkId,
1723
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1724
+ });
1725
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1726
+ }
1727
+ };
1728
+
1729
+ // src/resources/vNextNetwork.ts
1730
+ var RECORD_SEPARATOR3 = "";
1731
+ var VNextNetwork = class extends BaseResource {
1732
+ constructor(options, networkId) {
1733
+ super(options);
1734
+ this.networkId = networkId;
1735
+ }
1736
+ /**
1737
+ * Retrieves details about the network
1738
+ * @returns Promise containing vNext network details
1739
+ */
1740
+ details() {
1741
+ return this.request(`/api/networks/v-next/${this.networkId}`);
1742
+ }
1743
+ /**
1744
+ * Generates a response from the v-next network
1745
+ * @param params - Generation parameters including message
1746
+ * @returns Promise containing the generated response
1747
+ */
1748
+ generate(params) {
1749
+ return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1750
+ method: "POST",
1751
+ body: {
1752
+ ...params,
1753
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1754
+ }
1755
+ });
1756
+ }
1757
+ /**
1758
+ * Generates a response from the v-next network using multiple primitives
1759
+ * @param params - Generation parameters including message
1760
+ * @returns Promise containing the generated response
1761
+ */
1762
+ loop(params) {
1763
+ return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1764
+ method: "POST",
1765
+ body: {
1766
+ ...params,
1767
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1768
+ }
1769
+ });
1770
+ }
1771
+ async *streamProcessor(stream) {
1772
+ const reader = stream.getReader();
1773
+ let doneReading = false;
1774
+ let buffer = "";
1775
+ try {
1776
+ while (!doneReading) {
1777
+ const { done, value } = await reader.read();
1778
+ doneReading = done;
1779
+ if (done && !value) continue;
1780
+ try {
1781
+ const decoded = value ? new TextDecoder().decode(value) : "";
1782
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
1783
+ buffer = chunks.pop() || "";
1784
+ for (const chunk of chunks) {
1785
+ if (chunk) {
1786
+ if (typeof chunk === "string") {
1787
+ try {
1788
+ const parsedChunk = JSON.parse(chunk);
1789
+ yield parsedChunk;
1790
+ } catch {
1791
+ }
1792
+ }
1793
+ }
1794
+ }
1795
+ } catch {
1796
+ }
1797
+ }
1798
+ if (buffer) {
1799
+ try {
1800
+ yield JSON.parse(buffer);
1801
+ } catch {
1802
+ }
1803
+ }
1804
+ } finally {
1805
+ reader.cancel().catch(() => {
1806
+ });
1807
+ }
1808
+ }
1809
+ /**
1810
+ * Streams a response from the v-next network
1811
+ * @param params - Stream parameters including message
1812
+ * @returns Promise containing the results
1813
+ */
1814
+ async stream(params, onRecord) {
1815
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1816
+ method: "POST",
1817
+ body: {
1818
+ ...params,
1819
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1820
+ },
1821
+ stream: true
1822
+ });
1823
+ if (!response.ok) {
1824
+ throw new Error(`Failed to stream vNext network: ${response.statusText}`);
1825
+ }
1826
+ if (!response.body) {
1827
+ throw new Error("Response body is null");
1828
+ }
1829
+ for await (const record of this.streamProcessor(response.body)) {
1830
+ if (typeof record === "string") {
1831
+ onRecord(JSON.parse(record));
1832
+ } else {
1833
+ onRecord(record);
1834
+ }
1835
+ }
1836
+ }
1837
+ /**
1838
+ * Streams a response from the v-next network loop
1839
+ * @param params - Stream parameters including message
1840
+ * @returns Promise containing the results
1841
+ */
1842
+ async loopStream(params, onRecord) {
1843
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1844
+ method: "POST",
1845
+ body: {
1846
+ ...params,
1847
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1848
+ },
1849
+ stream: true
1850
+ });
1851
+ if (!response.ok) {
1852
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
1853
+ }
1854
+ if (!response.body) {
1855
+ throw new Error("Response body is null");
1856
+ }
1857
+ for await (const record of this.streamProcessor(response.body)) {
1858
+ if (typeof record === "string") {
1859
+ onRecord(JSON.parse(record));
1860
+ } else {
1861
+ onRecord(record);
1862
+ }
723
1863
  }
724
1864
  }
725
1865
  };
@@ -736,6 +1876,21 @@ var MastraClient = class extends BaseResource {
736
1876
  getAgents() {
737
1877
  return this.request("/api/agents");
738
1878
  }
1879
+ async getAGUI({ resourceId }) {
1880
+ const agents = await this.getAgents();
1881
+ return Object.entries(agents).reduce(
1882
+ (acc, [agentId]) => {
1883
+ const agent = this.getAgent(agentId);
1884
+ acc[agentId] = new AGUIAdapter({
1885
+ agentId,
1886
+ agent,
1887
+ resourceId
1888
+ });
1889
+ return acc;
1890
+ },
1891
+ {}
1892
+ );
1893
+ }
739
1894
  /**
740
1895
  * Gets an agent instance by ID
741
1896
  * @param agentId - ID of the agent to retrieve
@@ -786,6 +1941,48 @@ var MastraClient = class extends BaseResource {
786
1941
  getMemoryStatus(agentId) {
787
1942
  return this.request(`/api/memory/status?agentId=${agentId}`);
788
1943
  }
1944
+ /**
1945
+ * Retrieves memory threads for a resource
1946
+ * @param params - Parameters containing the resource ID
1947
+ * @returns Promise containing array of memory threads
1948
+ */
1949
+ getNetworkMemoryThreads(params) {
1950
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
1951
+ }
1952
+ /**
1953
+ * Creates a new memory thread
1954
+ * @param params - Parameters for creating the memory thread
1955
+ * @returns Promise containing the created memory thread
1956
+ */
1957
+ createNetworkMemoryThread(params) {
1958
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
1959
+ }
1960
+ /**
1961
+ * Gets a memory thread instance by ID
1962
+ * @param threadId - ID of the memory thread to retrieve
1963
+ * @returns MemoryThread instance
1964
+ */
1965
+ getNetworkMemoryThread(threadId, networkId) {
1966
+ return new NetworkMemoryThread(this.options, threadId, networkId);
1967
+ }
1968
+ /**
1969
+ * Saves messages to memory
1970
+ * @param params - Parameters containing messages to save
1971
+ * @returns Promise containing the saved messages
1972
+ */
1973
+ saveNetworkMessageToMemory(params) {
1974
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
1975
+ method: "POST",
1976
+ body: params
1977
+ });
1978
+ }
1979
+ /**
1980
+ * Gets the status of the memory system
1981
+ * @returns Promise containing memory system status
1982
+ */
1983
+ getNetworkMemoryStatus(networkId) {
1984
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
1985
+ }
789
1986
  /**
790
1987
  * Retrieves all available tools
791
1988
  * @returns Promise containing map of tool IDs to tool details
@@ -799,7 +1996,22 @@ var MastraClient = class extends BaseResource {
799
1996
  * @returns Tool instance
800
1997
  */
801
1998
  getTool(toolId) {
802
- return new Tool(this.options, toolId);
1999
+ return new Tool2(this.options, toolId);
2000
+ }
2001
+ /**
2002
+ * Retrieves all available legacy workflows
2003
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2004
+ */
2005
+ getLegacyWorkflows() {
2006
+ return this.request("/api/workflows/legacy");
2007
+ }
2008
+ /**
2009
+ * Gets a legacy workflow instance by ID
2010
+ * @param workflowId - ID of the legacy workflow to retrieve
2011
+ * @returns Legacy Workflow instance
2012
+ */
2013
+ getLegacyWorkflow(workflowId) {
2014
+ return new LegacyWorkflow(this.options, workflowId);
803
2015
  }
804
2016
  /**
805
2017
  * Retrieves all available workflows
@@ -816,21 +2028,6 @@ var MastraClient = class extends BaseResource {
816
2028
  getWorkflow(workflowId) {
817
2029
  return new Workflow(this.options, workflowId);
818
2030
  }
819
- /**
820
- * Retrieves all available vNext workflows
821
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
822
- */
823
- getVNextWorkflows() {
824
- return this.request("/api/workflows/v-next");
825
- }
826
- /**
827
- * Gets a vNext workflow instance by ID
828
- * @param workflowId - ID of the vNext workflow to retrieve
829
- * @returns vNext Workflow instance
830
- */
831
- getVNextWorkflow(workflowId) {
832
- return new VNextWorkflow(this.options, workflowId);
833
- }
834
2031
  /**
835
2032
  * Gets a vector instance by name
836
2033
  * @param vectorName - Name of the vector to retrieve
@@ -845,7 +2042,41 @@ var MastraClient = class extends BaseResource {
845
2042
  * @returns Promise containing array of log messages
846
2043
  */
847
2044
  getLogs(params) {
848
- return this.request(`/api/logs?transportId=${params.transportId}`);
2045
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
2046
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
2047
+ const searchParams = new URLSearchParams();
2048
+ if (transportId) {
2049
+ searchParams.set("transportId", transportId);
2050
+ }
2051
+ if (fromDate) {
2052
+ searchParams.set("fromDate", fromDate.toISOString());
2053
+ }
2054
+ if (toDate) {
2055
+ searchParams.set("toDate", toDate.toISOString());
2056
+ }
2057
+ if (logLevel) {
2058
+ searchParams.set("logLevel", logLevel);
2059
+ }
2060
+ if (page) {
2061
+ searchParams.set("page", String(page));
2062
+ }
2063
+ if (perPage) {
2064
+ searchParams.set("perPage", String(perPage));
2065
+ }
2066
+ if (_filters) {
2067
+ if (Array.isArray(_filters)) {
2068
+ for (const filter of _filters) {
2069
+ searchParams.append("filters", filter);
2070
+ }
2071
+ } else {
2072
+ searchParams.set("filters", _filters);
2073
+ }
2074
+ }
2075
+ if (searchParams.size) {
2076
+ return this.request(`/api/logs?${searchParams}`);
2077
+ } else {
2078
+ return this.request(`/api/logs`);
2079
+ }
849
2080
  }
850
2081
  /**
851
2082
  * Gets logs for a specific run
@@ -853,7 +2084,44 @@ var MastraClient = class extends BaseResource {
853
2084
  * @returns Promise containing array of log messages
854
2085
  */
855
2086
  getLogForRun(params) {
856
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
2087
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
2088
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
2089
+ const searchParams = new URLSearchParams();
2090
+ if (runId) {
2091
+ searchParams.set("runId", runId);
2092
+ }
2093
+ if (transportId) {
2094
+ searchParams.set("transportId", transportId);
2095
+ }
2096
+ if (fromDate) {
2097
+ searchParams.set("fromDate", fromDate.toISOString());
2098
+ }
2099
+ if (toDate) {
2100
+ searchParams.set("toDate", toDate.toISOString());
2101
+ }
2102
+ if (logLevel) {
2103
+ searchParams.set("logLevel", logLevel);
2104
+ }
2105
+ if (page) {
2106
+ searchParams.set("page", String(page));
2107
+ }
2108
+ if (perPage) {
2109
+ searchParams.set("perPage", String(perPage));
2110
+ }
2111
+ if (_filters) {
2112
+ if (Array.isArray(_filters)) {
2113
+ for (const filter of _filters) {
2114
+ searchParams.append("filters", filter);
2115
+ }
2116
+ } else {
2117
+ searchParams.set("filters", _filters);
2118
+ }
2119
+ }
2120
+ if (searchParams.size) {
2121
+ return this.request(`/api/logs/${runId}?${searchParams}`);
2122
+ } else {
2123
+ return this.request(`/api/logs/${runId}`);
2124
+ }
857
2125
  }
858
2126
  /**
859
2127
  * List of all log transports
@@ -868,7 +2136,7 @@ var MastraClient = class extends BaseResource {
868
2136
  * @returns Promise containing telemetry data
869
2137
  */
870
2138
  getTelemetry(params) {
871
- const { name, scope, page, perPage, attribute } = params || {};
2139
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
872
2140
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
873
2141
  const searchParams = new URLSearchParams();
874
2142
  if (name) {
@@ -892,6 +2160,12 @@ var MastraClient = class extends BaseResource {
892
2160
  searchParams.set("attribute", _attribute);
893
2161
  }
894
2162
  }
2163
+ if (fromDate) {
2164
+ searchParams.set("fromDate", fromDate.toISOString());
2165
+ }
2166
+ if (toDate) {
2167
+ searchParams.set("toDate", toDate.toISOString());
2168
+ }
895
2169
  if (searchParams.size) {
896
2170
  return this.request(`/api/telemetry?${searchParams}`);
897
2171
  } else {
@@ -905,6 +2179,13 @@ var MastraClient = class extends BaseResource {
905
2179
  getNetworks() {
906
2180
  return this.request("/api/networks");
907
2181
  }
2182
+ /**
2183
+ * Retrieves all available vNext networks
2184
+ * @returns Promise containing map of vNext network IDs to vNext network details
2185
+ */
2186
+ getVNextNetworks() {
2187
+ return this.request("/api/networks/v-next");
2188
+ }
908
2189
  /**
909
2190
  * Gets a network instance by ID
910
2191
  * @param networkId - ID of the network to retrieve
@@ -913,6 +2194,105 @@ var MastraClient = class extends BaseResource {
913
2194
  getNetwork(networkId) {
914
2195
  return new Network(this.options, networkId);
915
2196
  }
2197
+ /**
2198
+ * Gets a vNext network instance by ID
2199
+ * @param networkId - ID of the vNext network to retrieve
2200
+ * @returns vNext Network instance
2201
+ */
2202
+ getVNextNetwork(networkId) {
2203
+ return new VNextNetwork(this.options, networkId);
2204
+ }
2205
+ /**
2206
+ * Retrieves a list of available MCP servers.
2207
+ * @param params - Optional parameters for pagination (limit, offset).
2208
+ * @returns Promise containing the list of MCP servers and pagination info.
2209
+ */
2210
+ getMcpServers(params) {
2211
+ const searchParams = new URLSearchParams();
2212
+ if (params?.limit !== void 0) {
2213
+ searchParams.set("limit", String(params.limit));
2214
+ }
2215
+ if (params?.offset !== void 0) {
2216
+ searchParams.set("offset", String(params.offset));
2217
+ }
2218
+ const queryString = searchParams.toString();
2219
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
2220
+ }
2221
+ /**
2222
+ * Retrieves detailed information for a specific MCP server.
2223
+ * @param serverId - The ID of the MCP server to retrieve.
2224
+ * @param params - Optional parameters, e.g., specific version.
2225
+ * @returns Promise containing the detailed MCP server information.
2226
+ */
2227
+ getMcpServerDetails(serverId, params) {
2228
+ const searchParams = new URLSearchParams();
2229
+ if (params?.version) {
2230
+ searchParams.set("version", params.version);
2231
+ }
2232
+ const queryString = searchParams.toString();
2233
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
2234
+ }
2235
+ /**
2236
+ * Retrieves a list of tools for a specific MCP server.
2237
+ * @param serverId - The ID of the MCP server.
2238
+ * @returns Promise containing the list of tools.
2239
+ */
2240
+ getMcpServerTools(serverId) {
2241
+ return this.request(`/api/mcp/${serverId}/tools`);
2242
+ }
2243
+ /**
2244
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
2245
+ * This instance can then be used to fetch details or execute the tool.
2246
+ * @param serverId - The ID of the MCP server.
2247
+ * @param toolId - The ID of the tool.
2248
+ * @returns MCPTool instance.
2249
+ */
2250
+ getMcpServerTool(serverId, toolId) {
2251
+ return new MCPTool(this.options, serverId, toolId);
2252
+ }
2253
+ /**
2254
+ * Gets an A2A client for interacting with an agent via the A2A protocol
2255
+ * @param agentId - ID of the agent to interact with
2256
+ * @returns A2A client instance
2257
+ */
2258
+ getA2A(agentId) {
2259
+ return new A2A(this.options, agentId);
2260
+ }
2261
+ /**
2262
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2263
+ * @param agentId - ID of the agent.
2264
+ * @param threadId - ID of the thread.
2265
+ * @param resourceId - Optional ID of the resource.
2266
+ * @returns Working memory for the specified thread or resource.
2267
+ */
2268
+ getWorkingMemory({
2269
+ agentId,
2270
+ threadId,
2271
+ resourceId
2272
+ }) {
2273
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2274
+ }
2275
+ /**
2276
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2277
+ * @param agentId - ID of the agent.
2278
+ * @param threadId - ID of the thread.
2279
+ * @param workingMemory - The new working memory content.
2280
+ * @param resourceId - Optional ID of the resource.
2281
+ */
2282
+ updateWorkingMemory({
2283
+ agentId,
2284
+ threadId,
2285
+ workingMemory,
2286
+ resourceId
2287
+ }) {
2288
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2289
+ method: "POST",
2290
+ body: {
2291
+ workingMemory,
2292
+ resourceId
2293
+ }
2294
+ });
2295
+ }
916
2296
  };
917
2297
 
918
2298
  exports.MastraClient = MastraClient;