@mastra/client-js 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-fetch-workflow-runs-20250624231457

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
@@ -4,7 +4,13 @@ var client = require('@ag-ui/client');
4
4
  var rxjs = require('rxjs');
5
5
  var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
- var zodToJsonSchema = require('zod-to-json-schema');
7
+ var originalZodToJsonSchema = require('zod-to-json-schema');
8
+ var tools = require('@mastra/core/tools');
9
+ var runtimeContext = require('@mastra/core/runtime-context');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
8
14
 
9
15
  // src/adapters/agui.ts
10
16
  var AGUIAdapter = class extends client.AbstractAgent {
@@ -44,6 +50,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
44
50
  )
45
51
  }).then((response) => {
46
52
  let currentMessageId = void 0;
53
+ let isInTextMessage = false;
47
54
  return response.processDataStream({
48
55
  onTextPart: (text) => {
49
56
  if (currentMessageId === void 0) {
@@ -54,6 +61,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
54
61
  role: "assistant"
55
62
  };
56
63
  subscriber.next(message2);
64
+ isInTextMessage = true;
57
65
  }
58
66
  const message = {
59
67
  type: client.EventType.TEXT_MESSAGE_CONTENT,
@@ -62,14 +70,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
62
70
  };
63
71
  subscriber.next(message);
64
72
  },
65
- onFinishMessagePart: (message) => {
66
- console.log("onFinishMessagePart", message);
73
+ onFinishMessagePart: () => {
67
74
  if (currentMessageId !== void 0) {
68
- const message2 = {
75
+ const message = {
69
76
  type: client.EventType.TEXT_MESSAGE_END,
70
77
  messageId: currentMessageId
71
78
  };
72
- subscriber.next(message2);
79
+ subscriber.next(message);
80
+ isInTextMessage = false;
73
81
  }
74
82
  subscriber.next({
75
83
  type: client.EventType.RUN_FINISHED,
@@ -80,6 +88,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
80
88
  },
81
89
  onToolCallPart(streamPart) {
82
90
  const parentMessageId = currentMessageId || generateUUID();
91
+ if (isInTextMessage) {
92
+ const message = {
93
+ type: client.EventType.TEXT_MESSAGE_END,
94
+ messageId: parentMessageId
95
+ };
96
+ subscriber.next(message);
97
+ isInTextMessage = false;
98
+ }
83
99
  subscriber.next({
84
100
  type: client.EventType.TOOL_CALL_START,
85
101
  toolCallId: streamPart.toolCallId,
@@ -100,7 +116,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
100
116
  }
101
117
  });
102
118
  }).catch((error) => {
103
- console.log("error", error);
119
+ console.error("error", error);
104
120
  subscriber.error(error);
105
121
  });
106
122
  return () => {
@@ -149,6 +165,17 @@ function convertMessagesToMastraMessages(messages) {
149
165
  role: "assistant",
150
166
  content: parts
151
167
  });
168
+ if (message.toolCalls?.length) {
169
+ result.push({
170
+ role: "tool",
171
+ content: message.toolCalls.map((toolCall) => ({
172
+ type: "tool-result",
173
+ toolCallId: toolCall.id,
174
+ toolName: toolCall.function.name,
175
+ result: JSON.parse(toolCall.function.arguments)
176
+ }))
177
+ });
178
+ }
152
179
  } else if (message.role === "user") {
153
180
  result.push({
154
181
  role: "user",
@@ -170,6 +197,39 @@ function convertMessagesToMastraMessages(messages) {
170
197
  }
171
198
  return result;
172
199
  }
200
+ function zodToJsonSchema(zodSchema) {
201
+ if (!(zodSchema instanceof zod.ZodSchema)) {
202
+ return zodSchema;
203
+ }
204
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
205
+ }
206
+ function processClientTools(clientTools) {
207
+ if (!clientTools) {
208
+ return void 0;
209
+ }
210
+ return Object.fromEntries(
211
+ Object.entries(clientTools).map(([key, value]) => {
212
+ if (tools.isVercelTool(value)) {
213
+ return [
214
+ key,
215
+ {
216
+ ...value,
217
+ parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
218
+ }
219
+ ];
220
+ } else {
221
+ return [
222
+ key,
223
+ {
224
+ ...value,
225
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
226
+ outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
227
+ }
228
+ ];
229
+ }
230
+ })
231
+ );
232
+ }
173
233
 
174
234
  // src/resources/base.ts
175
235
  var BaseResource = class {
@@ -189,9 +249,10 @@ var BaseResource = class {
189
249
  let delay = backoffMs;
190
250
  for (let attempt = 0; attempt <= retries; attempt++) {
191
251
  try {
192
- const response = await fetch(`${baseUrl}${path}`, {
252
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
193
253
  ...options,
194
254
  headers: {
255
+ ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
195
256
  ...headers,
196
257
  ...options.headers
197
258
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
@@ -229,8 +290,15 @@ var BaseResource = class {
229
290
  throw lastError || new Error("Request failed");
230
291
  }
231
292
  };
232
-
233
- // src/resources/agent.ts
293
+ function parseClientRuntimeContext(runtimeContext$1) {
294
+ if (runtimeContext$1) {
295
+ if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
296
+ return Object.fromEntries(runtimeContext$1.entries());
297
+ }
298
+ return runtimeContext$1;
299
+ }
300
+ return void 0;
301
+ }
234
302
  var AgentVoice = class extends BaseResource {
235
303
  constructor(options, agentId) {
236
304
  super(options);
@@ -277,6 +345,13 @@ var AgentVoice = class extends BaseResource {
277
345
  getSpeakers() {
278
346
  return this.request(`/api/agents/${this.agentId}/voice/speakers`);
279
347
  }
348
+ /**
349
+ * Get the listener configuration for the agent's voice provider
350
+ * @returns Promise containing a check if the agent has listening capabilities
351
+ */
352
+ getListener() {
353
+ return this.request(`/api/agents/${this.agentId}/voice/listener`);
354
+ }
280
355
  };
281
356
  var Agent = class extends BaseResource {
282
357
  constructor(options, agentId) {
@@ -292,21 +367,318 @@ var Agent = class extends BaseResource {
292
367
  details() {
293
368
  return this.request(`/api/agents/${this.agentId}`);
294
369
  }
295
- /**
296
- * Generates a response from the agent
297
- * @param params - Generation parameters including prompt
298
- * @returns Promise containing the generated response
299
- */
300
- generate(params) {
370
+ async generate(params) {
301
371
  const processedParams = {
302
372
  ...params,
303
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
304
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
373
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
374
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
375
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
376
+ clientTools: processClientTools(params.clientTools)
305
377
  };
306
- return this.request(`/api/agents/${this.agentId}/generate`, {
378
+ const { runId, resourceId, threadId, runtimeContext } = processedParams;
379
+ const response = await this.request(`/api/agents/${this.agentId}/generate`, {
307
380
  method: "POST",
308
381
  body: processedParams
309
382
  });
383
+ if (response.finishReason === "tool-calls") {
384
+ for (const toolCall of response.toolCalls) {
385
+ const clientTool = params.clientTools?.[toolCall.toolName];
386
+ if (clientTool && clientTool.execute) {
387
+ const result = await clientTool.execute(
388
+ { context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
389
+ {
390
+ messages: response.messages,
391
+ toolCallId: toolCall?.toolCallId
392
+ }
393
+ );
394
+ const updatedMessages = [
395
+ {
396
+ role: "user",
397
+ content: params.messages
398
+ },
399
+ ...response.response.messages,
400
+ {
401
+ role: "tool",
402
+ content: [
403
+ {
404
+ type: "tool-result",
405
+ toolCallId: toolCall.toolCallId,
406
+ toolName: toolCall.toolName,
407
+ result
408
+ }
409
+ ]
410
+ }
411
+ ];
412
+ return this.generate({
413
+ ...params,
414
+ messages: updatedMessages
415
+ });
416
+ }
417
+ }
418
+ }
419
+ return response;
420
+ }
421
+ async processChatResponse({
422
+ stream,
423
+ update,
424
+ onToolCall,
425
+ onFinish,
426
+ getCurrentDate = () => /* @__PURE__ */ new Date(),
427
+ lastMessage
428
+ }) {
429
+ const replaceLastMessage = lastMessage?.role === "assistant";
430
+ let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
431
+ (lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
432
+ return Math.max(max, toolInvocation.step ?? 0);
433
+ }, 0) ?? 0) : 0;
434
+ const message = replaceLastMessage ? structuredClone(lastMessage) : {
435
+ id: crypto.randomUUID(),
436
+ createdAt: getCurrentDate(),
437
+ role: "assistant",
438
+ content: "",
439
+ parts: []
440
+ };
441
+ let currentTextPart = void 0;
442
+ let currentReasoningPart = void 0;
443
+ let currentReasoningTextDetail = void 0;
444
+ function updateToolInvocationPart(toolCallId, invocation) {
445
+ const part = message.parts.find(
446
+ (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
447
+ );
448
+ if (part != null) {
449
+ part.toolInvocation = invocation;
450
+ } else {
451
+ message.parts.push({
452
+ type: "tool-invocation",
453
+ toolInvocation: invocation
454
+ });
455
+ }
456
+ }
457
+ const data = [];
458
+ let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
459
+ const partialToolCalls = {};
460
+ let usage = {
461
+ completionTokens: NaN,
462
+ promptTokens: NaN,
463
+ totalTokens: NaN
464
+ };
465
+ let finishReason = "unknown";
466
+ function execUpdate() {
467
+ const copiedData = [...data];
468
+ if (messageAnnotations?.length) {
469
+ message.annotations = messageAnnotations;
470
+ }
471
+ const copiedMessage = {
472
+ // deep copy the message to ensure that deep changes (msg attachments) are updated
473
+ // with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
474
+ ...structuredClone(message),
475
+ // add a revision id to ensure that the message is updated with SWR. SWR uses a
476
+ // hashing approach by default to detect changes, but it only works for shallow
477
+ // changes. This is why we need to add a revision id to ensure that the message
478
+ // is updated with SWR (without it, the changes get stuck in SWR and are not
479
+ // forwarded to rendering):
480
+ revisionId: crypto.randomUUID()
481
+ };
482
+ update({
483
+ message: copiedMessage,
484
+ data: copiedData,
485
+ replaceLastMessage
486
+ });
487
+ }
488
+ await uiUtils.processDataStream({
489
+ stream,
490
+ onTextPart(value) {
491
+ if (currentTextPart == null) {
492
+ currentTextPart = {
493
+ type: "text",
494
+ text: value
495
+ };
496
+ message.parts.push(currentTextPart);
497
+ } else {
498
+ currentTextPart.text += value;
499
+ }
500
+ message.content += value;
501
+ execUpdate();
502
+ },
503
+ onReasoningPart(value) {
504
+ if (currentReasoningTextDetail == null) {
505
+ currentReasoningTextDetail = { type: "text", text: value };
506
+ if (currentReasoningPart != null) {
507
+ currentReasoningPart.details.push(currentReasoningTextDetail);
508
+ }
509
+ } else {
510
+ currentReasoningTextDetail.text += value;
511
+ }
512
+ if (currentReasoningPart == null) {
513
+ currentReasoningPart = {
514
+ type: "reasoning",
515
+ reasoning: value,
516
+ details: [currentReasoningTextDetail]
517
+ };
518
+ message.parts.push(currentReasoningPart);
519
+ } else {
520
+ currentReasoningPart.reasoning += value;
521
+ }
522
+ message.reasoning = (message.reasoning ?? "") + value;
523
+ execUpdate();
524
+ },
525
+ onReasoningSignaturePart(value) {
526
+ if (currentReasoningTextDetail != null) {
527
+ currentReasoningTextDetail.signature = value.signature;
528
+ }
529
+ },
530
+ onRedactedReasoningPart(value) {
531
+ if (currentReasoningPart == null) {
532
+ currentReasoningPart = {
533
+ type: "reasoning",
534
+ reasoning: "",
535
+ details: []
536
+ };
537
+ message.parts.push(currentReasoningPart);
538
+ }
539
+ currentReasoningPart.details.push({
540
+ type: "redacted",
541
+ data: value.data
542
+ });
543
+ currentReasoningTextDetail = void 0;
544
+ execUpdate();
545
+ },
546
+ onFilePart(value) {
547
+ message.parts.push({
548
+ type: "file",
549
+ mimeType: value.mimeType,
550
+ data: value.data
551
+ });
552
+ execUpdate();
553
+ },
554
+ onSourcePart(value) {
555
+ message.parts.push({
556
+ type: "source",
557
+ source: value
558
+ });
559
+ execUpdate();
560
+ },
561
+ onToolCallStreamingStartPart(value) {
562
+ if (message.toolInvocations == null) {
563
+ message.toolInvocations = [];
564
+ }
565
+ partialToolCalls[value.toolCallId] = {
566
+ text: "",
567
+ step,
568
+ toolName: value.toolName,
569
+ index: message.toolInvocations.length
570
+ };
571
+ const invocation = {
572
+ state: "partial-call",
573
+ step,
574
+ toolCallId: value.toolCallId,
575
+ toolName: value.toolName,
576
+ args: void 0
577
+ };
578
+ message.toolInvocations.push(invocation);
579
+ updateToolInvocationPart(value.toolCallId, invocation);
580
+ execUpdate();
581
+ },
582
+ onToolCallDeltaPart(value) {
583
+ const partialToolCall = partialToolCalls[value.toolCallId];
584
+ partialToolCall.text += value.argsTextDelta;
585
+ const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
586
+ const invocation = {
587
+ state: "partial-call",
588
+ step: partialToolCall.step,
589
+ toolCallId: value.toolCallId,
590
+ toolName: partialToolCall.toolName,
591
+ args: partialArgs
592
+ };
593
+ message.toolInvocations[partialToolCall.index] = invocation;
594
+ updateToolInvocationPart(value.toolCallId, invocation);
595
+ execUpdate();
596
+ },
597
+ async onToolCallPart(value) {
598
+ const invocation = {
599
+ state: "call",
600
+ step,
601
+ ...value
602
+ };
603
+ if (partialToolCalls[value.toolCallId] != null) {
604
+ message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
605
+ } else {
606
+ if (message.toolInvocations == null) {
607
+ message.toolInvocations = [];
608
+ }
609
+ message.toolInvocations.push(invocation);
610
+ }
611
+ updateToolInvocationPart(value.toolCallId, invocation);
612
+ execUpdate();
613
+ if (onToolCall) {
614
+ const result = await onToolCall({ toolCall: value });
615
+ if (result != null) {
616
+ const invocation2 = {
617
+ state: "result",
618
+ step,
619
+ ...value,
620
+ result
621
+ };
622
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
623
+ updateToolInvocationPart(value.toolCallId, invocation2);
624
+ execUpdate();
625
+ }
626
+ }
627
+ },
628
+ onToolResultPart(value) {
629
+ const toolInvocations = message.toolInvocations;
630
+ if (toolInvocations == null) {
631
+ throw new Error("tool_result must be preceded by a tool_call");
632
+ }
633
+ const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
634
+ if (toolInvocationIndex === -1) {
635
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
636
+ }
637
+ const invocation = {
638
+ ...toolInvocations[toolInvocationIndex],
639
+ state: "result",
640
+ ...value
641
+ };
642
+ toolInvocations[toolInvocationIndex] = invocation;
643
+ updateToolInvocationPart(value.toolCallId, invocation);
644
+ execUpdate();
645
+ },
646
+ onDataPart(value) {
647
+ data.push(...value);
648
+ execUpdate();
649
+ },
650
+ onMessageAnnotationsPart(value) {
651
+ if (messageAnnotations == null) {
652
+ messageAnnotations = [...value];
653
+ } else {
654
+ messageAnnotations.push(...value);
655
+ }
656
+ execUpdate();
657
+ },
658
+ onFinishStepPart(value) {
659
+ step += 1;
660
+ currentTextPart = value.isContinued ? currentTextPart : void 0;
661
+ currentReasoningPart = void 0;
662
+ currentReasoningTextDetail = void 0;
663
+ },
664
+ onStartStepPart(value) {
665
+ if (!replaceLastMessage) {
666
+ message.id = value.messageId;
667
+ }
668
+ message.parts.push({ type: "step-start" });
669
+ execUpdate();
670
+ },
671
+ onFinishMessagePart(value) {
672
+ finishReason = value.finishReason;
673
+ if (value.usage != null) {
674
+ usage = value.usage;
675
+ }
676
+ },
677
+ onErrorPart(error) {
678
+ throw new Error(error);
679
+ }
680
+ });
681
+ onFinish?.({ message, finishReason, usage });
310
682
  }
311
683
  /**
312
684
  * Streams a response from the agent
@@ -316,9 +688,30 @@ var Agent = class extends BaseResource {
316
688
  async stream(params) {
317
689
  const processedParams = {
318
690
  ...params,
319
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
320
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
691
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
692
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
693
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
694
+ clientTools: processClientTools(params.clientTools)
321
695
  };
696
+ const { readable, writable } = new TransformStream();
697
+ const response = await this.processStreamResponse(processedParams, writable);
698
+ const streamResponse = new Response(readable, {
699
+ status: response.status,
700
+ statusText: response.statusText,
701
+ headers: response.headers
702
+ });
703
+ streamResponse.processDataStream = async (options = {}) => {
704
+ await uiUtils.processDataStream({
705
+ stream: streamResponse.body,
706
+ ...options
707
+ });
708
+ };
709
+ return streamResponse;
710
+ }
711
+ /**
712
+ * Processes the stream response and handles tool calls
713
+ */
714
+ async processStreamResponse(processedParams, writable) {
322
715
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
323
716
  method: "POST",
324
717
  body: processedParams,
@@ -327,12 +720,79 @@ var Agent = class extends BaseResource {
327
720
  if (!response.body) {
328
721
  throw new Error("No response body");
329
722
  }
330
- response.processDataStream = async (options = {}) => {
331
- await uiUtils.processDataStream({
332
- stream: response.body,
333
- ...options
723
+ try {
724
+ let toolCalls = [];
725
+ let finishReasonToolCalls = false;
726
+ let messages = [];
727
+ let hasProcessedToolCalls = false;
728
+ response.clone().body.pipeTo(writable);
729
+ await this.processChatResponse({
730
+ stream: response.clone().body,
731
+ update: ({ message }) => {
732
+ messages.push(message);
733
+ },
734
+ onFinish: ({ finishReason, message }) => {
735
+ if (finishReason === "tool-calls") {
736
+ finishReasonToolCalls = true;
737
+ const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
738
+ if (toolCall) {
739
+ toolCalls.push(toolCall);
740
+ }
741
+ }
742
+ },
743
+ lastMessage: void 0
334
744
  });
335
- };
745
+ if (finishReasonToolCalls && !hasProcessedToolCalls) {
746
+ hasProcessedToolCalls = true;
747
+ for (const toolCall of toolCalls) {
748
+ const clientTool = processedParams.clientTools?.[toolCall.toolName];
749
+ if (clientTool && clientTool.execute) {
750
+ const result = await clientTool.execute(
751
+ {
752
+ context: toolCall?.args,
753
+ runId: processedParams.runId,
754
+ resourceId: processedParams.resourceId,
755
+ threadId: processedParams.threadId,
756
+ runtimeContext: processedParams.runtimeContext
757
+ },
758
+ {
759
+ messages: response.messages,
760
+ toolCallId: toolCall?.toolCallId
761
+ }
762
+ );
763
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
764
+ const toolInvocationPart = lastMessage?.parts?.find(
765
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall.toolCallId
766
+ );
767
+ if (toolInvocationPart) {
768
+ toolInvocationPart.toolInvocation = {
769
+ ...toolInvocationPart.toolInvocation,
770
+ state: "result",
771
+ result
772
+ };
773
+ }
774
+ const toolInvocation = lastMessage?.toolInvocations?.find(
775
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall.toolCallId
776
+ );
777
+ if (toolInvocation) {
778
+ toolInvocation.state = "result";
779
+ toolInvocation.result = result;
780
+ }
781
+ const originalMessages = processedParams.messages;
782
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
783
+ this.processStreamResponse(
784
+ {
785
+ ...processedParams,
786
+ messages: [...messageArray, ...messages, lastMessage]
787
+ },
788
+ writable
789
+ );
790
+ }
791
+ }
792
+ }
793
+ } catch (error) {
794
+ console.error("Error processing stream response:", error);
795
+ }
336
796
  return response;
337
797
  }
338
798
  /**
@@ -343,6 +803,22 @@ var Agent = class extends BaseResource {
343
803
  getTool(toolId) {
344
804
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
345
805
  }
806
+ /**
807
+ * Executes a tool for the agent
808
+ * @param toolId - ID of the tool to execute
809
+ * @param params - Parameters required for tool execution
810
+ * @returns Promise containing the tool execution results
811
+ */
812
+ executeTool(toolId, params) {
813
+ const body = {
814
+ data: params.data,
815
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
816
+ };
817
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
818
+ method: "POST",
819
+ body
820
+ });
821
+ }
346
822
  /**
347
823
  * Retrieves evaluation results for the agent
348
824
  * @returns Promise containing agent evaluations
@@ -378,8 +854,8 @@ var Network = class extends BaseResource {
378
854
  generate(params) {
379
855
  const processedParams = {
380
856
  ...params,
381
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
382
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
857
+ output: zodToJsonSchema(params.output),
858
+ experimental_output: zodToJsonSchema(params.experimental_output)
383
859
  };
384
860
  return this.request(`/api/networks/${this.networkId}/generate`, {
385
861
  method: "POST",
@@ -394,8 +870,8 @@ var Network = class extends BaseResource {
394
870
  async stream(params) {
395
871
  const processedParams = {
396
872
  ...params,
397
- output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
398
- experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
873
+ output: zodToJsonSchema(params.output),
874
+ experimental_output: zodToJsonSchema(params.experimental_output)
399
875
  };
400
876
  const response = await this.request(`/api/networks/${this.networkId}/stream`, {
401
877
  method: "POST",
@@ -451,10 +927,15 @@ var MemoryThread = class extends BaseResource {
451
927
  }
452
928
  /**
453
929
  * Retrieves messages associated with the thread
930
+ * @param params - Optional parameters including limit for number of messages to retrieve
454
931
  * @returns Promise containing thread messages and UI messages
455
932
  */
456
- getMessages() {
457
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
933
+ getMessages(params) {
934
+ const query = new URLSearchParams({
935
+ agentId: this.agentId,
936
+ ...params?.limit ? { limit: params.limit.toString() } : {}
937
+ });
938
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
458
939
  }
459
940
  };
460
941
 
@@ -524,24 +1005,24 @@ var Vector = class extends BaseResource {
524
1005
  }
525
1006
  };
526
1007
 
527
- // src/resources/workflow.ts
1008
+ // src/resources/legacy-workflow.ts
528
1009
  var RECORD_SEPARATOR = "";
529
- var Workflow = class extends BaseResource {
1010
+ var LegacyWorkflow = class extends BaseResource {
530
1011
  constructor(options, workflowId) {
531
1012
  super(options);
532
1013
  this.workflowId = workflowId;
533
1014
  }
534
1015
  /**
535
- * Retrieves details about the workflow
536
- * @returns Promise containing workflow details including steps and graphs
1016
+ * Retrieves details about the legacy workflow
1017
+ * @returns Promise containing legacy workflow details including steps and graphs
537
1018
  */
538
1019
  details() {
539
- return this.request(`/api/workflows/${this.workflowId}`);
1020
+ return this.request(`/api/workflows/legacy/${this.workflowId}`);
540
1021
  }
541
1022
  /**
542
- * Retrieves all runs for a workflow
1023
+ * Retrieves all runs for a legacy workflow
543
1024
  * @param params - Parameters for filtering runs
544
- * @returns Promise containing workflow runs array
1025
+ * @returns Promise containing legacy workflow runs array
545
1026
  */
546
1027
  runs(params) {
547
1028
  const searchParams = new URLSearchParams();
@@ -561,25 +1042,13 @@ var Workflow = class extends BaseResource {
561
1042
  searchParams.set("resourceId", params.resourceId);
562
1043
  }
563
1044
  if (searchParams.size) {
564
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1045
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
565
1046
  } else {
566
- return this.request(`/api/workflows/${this.workflowId}/runs`);
1047
+ return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
567
1048
  }
568
1049
  }
569
1050
  /**
570
- * @deprecated Use `startAsync` instead
571
- * Executes the workflow with the provided parameters
572
- * @param params - Parameters required for workflow execution
573
- * @returns Promise containing the workflow execution results
574
- */
575
- execute(params) {
576
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
577
- method: "POST",
578
- body: params
579
- });
580
- }
581
- /**
582
- * Creates a new workflow run
1051
+ * Creates a new legacy workflow run
583
1052
  * @returns Promise containing the generated run ID
584
1053
  */
585
1054
  createRun(params) {
@@ -587,34 +1056,34 @@ var Workflow = class extends BaseResource {
587
1056
  if (!!params?.runId) {
588
1057
  searchParams.set("runId", params.runId);
589
1058
  }
590
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
1059
+ return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
591
1060
  method: "POST"
592
1061
  });
593
1062
  }
594
1063
  /**
595
- * Starts a workflow run synchronously without waiting for the workflow to complete
1064
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
596
1065
  * @param params - Object containing the runId and triggerData
597
1066
  * @returns Promise containing success message
598
1067
  */
599
1068
  start(params) {
600
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1069
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
601
1070
  method: "POST",
602
1071
  body: params?.triggerData
603
1072
  });
604
1073
  }
605
1074
  /**
606
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
1075
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
607
1076
  * @param stepId - ID of the step to resume
608
- * @param runId - ID of the workflow run
609
- * @param context - Context to resume the workflow with
610
- * @returns Promise containing the workflow resume results
1077
+ * @param runId - ID of the legacy workflow run
1078
+ * @param context - Context to resume the legacy workflow with
1079
+ * @returns Promise containing the legacy workflow resume results
611
1080
  */
612
1081
  resume({
613
1082
  stepId,
614
1083
  runId,
615
1084
  context
616
1085
  }) {
617
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1086
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
618
1087
  method: "POST",
619
1088
  body: {
620
1089
  stepId,
@@ -632,18 +1101,18 @@ var Workflow = class extends BaseResource {
632
1101
  if (!!params?.runId) {
633
1102
  searchParams.set("runId", params.runId);
634
1103
  }
635
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1104
+ return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
636
1105
  method: "POST",
637
1106
  body: params?.triggerData
638
1107
  });
639
1108
  }
640
1109
  /**
641
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1110
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
642
1111
  * @param params - Object containing the runId, stepId, and context
643
1112
  * @returns Promise containing the workflow resume results
644
1113
  */
645
1114
  resumeAsync(params) {
646
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
1115
+ return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
647
1116
  method: "POST",
648
1117
  body: {
649
1118
  stepId: params.stepId,
@@ -697,16 +1166,16 @@ var Workflow = class extends BaseResource {
697
1166
  }
698
1167
  }
699
1168
  /**
700
- * Watches workflow transitions in real-time
1169
+ * Watches legacy workflow transitions in real-time
701
1170
  * @param runId - Optional run ID to filter the watch stream
702
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
1171
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
703
1172
  */
704
1173
  async watch({ runId }, onRecord) {
705
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
1174
+ const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
706
1175
  stream: true
707
1176
  });
708
1177
  if (!response.ok) {
709
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
1178
+ throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
710
1179
  }
711
1180
  if (!response.body) {
712
1181
  throw new Error("Response body is null");
@@ -718,7 +1187,7 @@ var Workflow = class extends BaseResource {
718
1187
  };
719
1188
 
720
1189
  // src/resources/tool.ts
721
- var Tool = class extends BaseResource {
1190
+ var Tool2 = class extends BaseResource {
722
1191
  constructor(options, toolId) {
723
1192
  super(options);
724
1193
  this.toolId = toolId;
@@ -740,22 +1209,26 @@ var Tool = class extends BaseResource {
740
1209
  if (params.runId) {
741
1210
  url.set("runId", params.runId);
742
1211
  }
1212
+ const body = {
1213
+ data: params.data,
1214
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1215
+ };
743
1216
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
744
1217
  method: "POST",
745
- body: params.data
1218
+ body
746
1219
  });
747
1220
  }
748
1221
  };
749
1222
 
750
- // src/resources/vnext-workflow.ts
1223
+ // src/resources/workflow.ts
751
1224
  var RECORD_SEPARATOR2 = "";
752
- var VNextWorkflow = class extends BaseResource {
1225
+ var Workflow = class extends BaseResource {
753
1226
  constructor(options, workflowId) {
754
1227
  super(options);
755
1228
  this.workflowId = workflowId;
756
1229
  }
757
1230
  /**
758
- * Creates an async generator that processes a readable stream and yields vNext workflow records
1231
+ * Creates an async generator that processes a readable stream and yields workflow records
759
1232
  * separated by the Record Separator character (\x1E)
760
1233
  *
761
1234
  * @param stream - The readable stream to process
@@ -800,16 +1273,16 @@ var VNextWorkflow = class extends BaseResource {
800
1273
  }
801
1274
  }
802
1275
  /**
803
- * Retrieves details about the vNext workflow
804
- * @returns Promise containing vNext workflow details including steps and graphs
1276
+ * Retrieves details about the workflow
1277
+ * @returns Promise containing workflow details including steps and graphs
805
1278
  */
806
1279
  details() {
807
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
1280
+ return this.request(`/api/workflows/${this.workflowId}`);
808
1281
  }
809
1282
  /**
810
- * Retrieves all runs for a vNext workflow
1283
+ * Retrieves all runs for a workflow
811
1284
  * @param params - Parameters for filtering runs
812
- * @returns Promise containing vNext workflow runs array
1285
+ * @returns Promise containing workflow runs array
813
1286
  */
814
1287
  runs(params) {
815
1288
  const searchParams = new URLSearchParams();
@@ -819,23 +1292,39 @@ var VNextWorkflow = class extends BaseResource {
819
1292
  if (params?.toDate) {
820
1293
  searchParams.set("toDate", params.toDate.toISOString());
821
1294
  }
822
- if (params?.limit) {
1295
+ if (params?.limit !== void 0) {
823
1296
  searchParams.set("limit", String(params.limit));
824
1297
  }
825
- if (params?.offset) {
1298
+ if (params?.offset !== void 0) {
826
1299
  searchParams.set("offset", String(params.offset));
827
1300
  }
828
1301
  if (params?.resourceId) {
829
1302
  searchParams.set("resourceId", params.resourceId);
830
1303
  }
831
1304
  if (searchParams.size) {
832
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
1305
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
833
1306
  } else {
834
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
1307
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
835
1308
  }
836
1309
  }
837
1310
  /**
838
- * Creates a new vNext workflow run
1311
+ * Retrieves a specific workflow run by its ID
1312
+ * @param runId - The ID of the workflow run to retrieve
1313
+ * @returns Promise containing the workflow run details
1314
+ */
1315
+ runById(runId) {
1316
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1317
+ }
1318
+ /**
1319
+ * Retrieves the execution result for a specific workflow run by its ID
1320
+ * @param runId - The ID of the workflow run to retrieve the execution result for
1321
+ * @returns Promise containing the workflow run execution result
1322
+ */
1323
+ runExecutionResult(runId) {
1324
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1325
+ }
1326
+ /**
1327
+ * Creates a new workflow run
839
1328
  * @param params - Optional object containing the optional runId
840
1329
  * @returns Promise containing the runId of the created run
841
1330
  */
@@ -844,23 +1333,24 @@ var VNextWorkflow = class extends BaseResource {
844
1333
  if (!!params?.runId) {
845
1334
  searchParams.set("runId", params.runId);
846
1335
  }
847
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
1336
+ return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
848
1337
  method: "POST"
849
1338
  });
850
1339
  }
851
1340
  /**
852
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
1341
+ * Starts a workflow run synchronously without waiting for the workflow to complete
853
1342
  * @param params - Object containing the runId, inputData and runtimeContext
854
1343
  * @returns Promise containing success message
855
1344
  */
856
1345
  start(params) {
857
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
1346
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1347
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
858
1348
  method: "POST",
859
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
1349
+ body: { inputData: params?.inputData, runtimeContext }
860
1350
  });
861
1351
  }
862
1352
  /**
863
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
1353
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
864
1354
  * @param params - Object containing the runId, step, resumeData and runtimeContext
865
1355
  * @returns Promise containing success message
866
1356
  */
@@ -868,9 +1358,10 @@ var VNextWorkflow = class extends BaseResource {
868
1358
  step,
869
1359
  runId,
870
1360
  resumeData,
871
- runtimeContext
1361
+ ...rest
872
1362
  }) {
873
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
1363
+ const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1364
+ return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
874
1365
  method: "POST",
875
1366
  stream: true,
876
1367
  body: {
@@ -881,53 +1372,386 @@ var VNextWorkflow = class extends BaseResource {
881
1372
  });
882
1373
  }
883
1374
  /**
884
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
1375
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
885
1376
  * @param params - Object containing the optional runId, inputData and runtimeContext
886
- * @returns Promise containing the vNext workflow execution results
1377
+ * @returns Promise containing the workflow execution results
887
1378
  */
888
1379
  startAsync(params) {
889
1380
  const searchParams = new URLSearchParams();
890
1381
  if (!!params?.runId) {
891
1382
  searchParams.set("runId", params.runId);
892
1383
  }
893
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
1384
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1385
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
894
1386
  method: "POST",
895
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
1387
+ body: { inputData: params.inputData, runtimeContext }
896
1388
  });
897
1389
  }
898
1390
  /**
899
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
1391
+ * Starts a workflow run and returns a stream
1392
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1393
+ * @returns Promise containing the workflow execution results
1394
+ */
1395
+ async stream(params) {
1396
+ const searchParams = new URLSearchParams();
1397
+ if (!!params?.runId) {
1398
+ searchParams.set("runId", params.runId);
1399
+ }
1400
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1401
+ const response = await this.request(
1402
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1403
+ {
1404
+ method: "POST",
1405
+ body: { inputData: params.inputData, runtimeContext },
1406
+ stream: true
1407
+ }
1408
+ );
1409
+ if (!response.ok) {
1410
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1411
+ }
1412
+ if (!response.body) {
1413
+ throw new Error("Response body is null");
1414
+ }
1415
+ const transformStream = new TransformStream({
1416
+ start() {
1417
+ },
1418
+ async transform(chunk, controller) {
1419
+ try {
1420
+ const decoded = new TextDecoder().decode(chunk);
1421
+ const chunks = decoded.split(RECORD_SEPARATOR2);
1422
+ for (const chunk2 of chunks) {
1423
+ if (chunk2) {
1424
+ try {
1425
+ const parsedChunk = JSON.parse(chunk2);
1426
+ controller.enqueue(parsedChunk);
1427
+ } catch {
1428
+ }
1429
+ }
1430
+ }
1431
+ } catch {
1432
+ }
1433
+ }
1434
+ });
1435
+ return response.body.pipeThrough(transformStream);
1436
+ }
1437
+ /**
1438
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
900
1439
  * @param params - Object containing the runId, step, resumeData and runtimeContext
901
- * @returns Promise containing the vNext workflow resume results
1440
+ * @returns Promise containing the workflow resume results
902
1441
  */
903
1442
  resumeAsync(params) {
904
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
1443
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1444
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
905
1445
  method: "POST",
906
1446
  body: {
907
1447
  step: params.step,
908
1448
  resumeData: params.resumeData,
909
- runtimeContext: params.runtimeContext
1449
+ runtimeContext
910
1450
  }
911
1451
  });
912
1452
  }
913
1453
  /**
914
- * Watches vNext workflow transitions in real-time
1454
+ * Watches workflow transitions in real-time
915
1455
  * @param runId - Optional run ID to filter the watch stream
916
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
1456
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
917
1457
  */
918
1458
  async watch({ runId }, onRecord) {
919
- const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
1459
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
920
1460
  stream: true
921
1461
  });
922
1462
  if (!response.ok) {
923
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
1463
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
924
1464
  }
925
1465
  if (!response.body) {
926
1466
  throw new Error("Response body is null");
927
1467
  }
928
1468
  for await (const record of this.streamProcessor(response.body)) {
929
- onRecord(record);
1469
+ if (typeof record === "string") {
1470
+ onRecord(JSON.parse(record));
1471
+ } else {
1472
+ onRecord(record);
1473
+ }
1474
+ }
1475
+ }
1476
+ /**
1477
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
1478
+ * serializing each as JSON and separating them with the record separator (\x1E).
1479
+ *
1480
+ * @param records - An iterable or async iterable of objects to stream
1481
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
1482
+ */
1483
+ static createRecordStream(records) {
1484
+ const encoder = new TextEncoder();
1485
+ return new ReadableStream({
1486
+ async start(controller) {
1487
+ try {
1488
+ for await (const record of records) {
1489
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1490
+ controller.enqueue(encoder.encode(json));
1491
+ }
1492
+ controller.close();
1493
+ } catch (err) {
1494
+ controller.error(err);
1495
+ }
1496
+ }
1497
+ });
1498
+ }
1499
+ };
1500
+
1501
+ // src/resources/a2a.ts
1502
+ var A2A = class extends BaseResource {
1503
+ constructor(options, agentId) {
1504
+ super(options);
1505
+ this.agentId = agentId;
1506
+ }
1507
+ /**
1508
+ * Get the agent card with metadata about the agent
1509
+ * @returns Promise containing the agent card information
1510
+ */
1511
+ async getCard() {
1512
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
1513
+ }
1514
+ /**
1515
+ * Send a message to the agent and get a response
1516
+ * @param params - Parameters for the task
1517
+ * @returns Promise containing the task response
1518
+ */
1519
+ async sendMessage(params) {
1520
+ const response = await this.request(`/a2a/${this.agentId}`, {
1521
+ method: "POST",
1522
+ body: {
1523
+ method: "tasks/send",
1524
+ params
1525
+ }
1526
+ });
1527
+ return { task: response.result };
1528
+ }
1529
+ /**
1530
+ * Get the status and result of a task
1531
+ * @param params - Parameters for querying the task
1532
+ * @returns Promise containing the task response
1533
+ */
1534
+ async getTask(params) {
1535
+ const response = await this.request(`/a2a/${this.agentId}`, {
1536
+ method: "POST",
1537
+ body: {
1538
+ method: "tasks/get",
1539
+ params
1540
+ }
1541
+ });
1542
+ return response.result;
1543
+ }
1544
+ /**
1545
+ * Cancel a running task
1546
+ * @param params - Parameters identifying the task to cancel
1547
+ * @returns Promise containing the task response
1548
+ */
1549
+ async cancelTask(params) {
1550
+ return this.request(`/a2a/${this.agentId}`, {
1551
+ method: "POST",
1552
+ body: {
1553
+ method: "tasks/cancel",
1554
+ params
1555
+ }
1556
+ });
1557
+ }
1558
+ /**
1559
+ * Send a message and subscribe to streaming updates (not fully implemented)
1560
+ * @param params - Parameters for the task
1561
+ * @returns Promise containing the task response
1562
+ */
1563
+ async sendAndSubscribe(params) {
1564
+ return this.request(`/a2a/${this.agentId}`, {
1565
+ method: "POST",
1566
+ body: {
1567
+ method: "tasks/sendSubscribe",
1568
+ params
1569
+ },
1570
+ stream: true
1571
+ });
1572
+ }
1573
+ };
1574
+
1575
+ // src/resources/mcp-tool.ts
1576
+ var MCPTool = class extends BaseResource {
1577
+ serverId;
1578
+ toolId;
1579
+ constructor(options, serverId, toolId) {
1580
+ super(options);
1581
+ this.serverId = serverId;
1582
+ this.toolId = toolId;
1583
+ }
1584
+ /**
1585
+ * Retrieves details about this specific tool from the MCP server.
1586
+ * @returns Promise containing the tool's information (name, description, schema).
1587
+ */
1588
+ details() {
1589
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1590
+ }
1591
+ /**
1592
+ * Executes this specific tool on the MCP server.
1593
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1594
+ * @returns Promise containing the result of the tool execution.
1595
+ */
1596
+ execute(params) {
1597
+ const body = {};
1598
+ if (params.data !== void 0) body.data = params.data;
1599
+ if (params.runtimeContext !== void 0) {
1600
+ body.runtimeContext = params.runtimeContext;
930
1601
  }
1602
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1603
+ method: "POST",
1604
+ body: Object.keys(body).length > 0 ? body : void 0
1605
+ });
1606
+ }
1607
+ };
1608
+
1609
+ // src/resources/vNextNetwork.ts
1610
+ var RECORD_SEPARATOR3 = "";
1611
+ var VNextNetwork = class extends BaseResource {
1612
+ constructor(options, networkId) {
1613
+ super(options);
1614
+ this.networkId = networkId;
1615
+ }
1616
+ /**
1617
+ * Retrieves details about the network
1618
+ * @returns Promise containing vNext network details
1619
+ */
1620
+ details() {
1621
+ return this.request(`/api/networks/v-next/${this.networkId}`);
1622
+ }
1623
+ /**
1624
+ * Generates a response from the v-next network
1625
+ * @param params - Generation parameters including message
1626
+ * @returns Promise containing the generated response
1627
+ */
1628
+ generate(params) {
1629
+ return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1630
+ method: "POST",
1631
+ body: params
1632
+ });
1633
+ }
1634
+ /**
1635
+ * Generates a response from the v-next network using multiple primitives
1636
+ * @param params - Generation parameters including message
1637
+ * @returns Promise containing the generated response
1638
+ */
1639
+ loop(params) {
1640
+ return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1641
+ method: "POST",
1642
+ body: params
1643
+ });
1644
+ }
1645
+ async *streamProcessor(stream) {
1646
+ const reader = stream.getReader();
1647
+ let doneReading = false;
1648
+ let buffer = "";
1649
+ try {
1650
+ while (!doneReading) {
1651
+ const { done, value } = await reader.read();
1652
+ doneReading = done;
1653
+ if (done && !value) continue;
1654
+ try {
1655
+ const decoded = value ? new TextDecoder().decode(value) : "";
1656
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
1657
+ buffer = chunks.pop() || "";
1658
+ for (const chunk of chunks) {
1659
+ if (chunk) {
1660
+ if (typeof chunk === "string") {
1661
+ try {
1662
+ const parsedChunk = JSON.parse(chunk);
1663
+ yield parsedChunk;
1664
+ } catch {
1665
+ }
1666
+ }
1667
+ }
1668
+ }
1669
+ } catch {
1670
+ }
1671
+ }
1672
+ if (buffer) {
1673
+ try {
1674
+ yield JSON.parse(buffer);
1675
+ } catch {
1676
+ }
1677
+ }
1678
+ } finally {
1679
+ reader.cancel().catch(() => {
1680
+ });
1681
+ }
1682
+ }
1683
+ /**
1684
+ * Streams a response from the v-next network
1685
+ * @param params - Stream parameters including message
1686
+ * @returns Promise containing the results
1687
+ */
1688
+ async stream(params, onRecord) {
1689
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1690
+ method: "POST",
1691
+ body: params,
1692
+ stream: true
1693
+ });
1694
+ if (!response.ok) {
1695
+ throw new Error(`Failed to stream vNext network: ${response.statusText}`);
1696
+ }
1697
+ if (!response.body) {
1698
+ throw new Error("Response body is null");
1699
+ }
1700
+ for await (const record of this.streamProcessor(response.body)) {
1701
+ if (typeof record === "string") {
1702
+ onRecord(JSON.parse(record));
1703
+ } else {
1704
+ onRecord(record);
1705
+ }
1706
+ }
1707
+ }
1708
+ };
1709
+
1710
+ // src/resources/network-memory-thread.ts
1711
+ var NetworkMemoryThread = class extends BaseResource {
1712
+ constructor(options, threadId, networkId) {
1713
+ super(options);
1714
+ this.threadId = threadId;
1715
+ this.networkId = networkId;
1716
+ }
1717
+ /**
1718
+ * Retrieves the memory thread details
1719
+ * @returns Promise containing thread details including title and metadata
1720
+ */
1721
+ get() {
1722
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1723
+ }
1724
+ /**
1725
+ * Updates the memory thread properties
1726
+ * @param params - Update parameters including title and metadata
1727
+ * @returns Promise containing updated thread details
1728
+ */
1729
+ update(params) {
1730
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1731
+ method: "PATCH",
1732
+ body: params
1733
+ });
1734
+ }
1735
+ /**
1736
+ * Deletes the memory thread
1737
+ * @returns Promise containing deletion result
1738
+ */
1739
+ delete() {
1740
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1741
+ method: "DELETE"
1742
+ });
1743
+ }
1744
+ /**
1745
+ * Retrieves messages associated with the thread
1746
+ * @param params - Optional parameters including limit for number of messages to retrieve
1747
+ * @returns Promise containing thread messages and UI messages
1748
+ */
1749
+ getMessages(params) {
1750
+ const query = new URLSearchParams({
1751
+ networkId: this.networkId,
1752
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1753
+ });
1754
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
931
1755
  }
932
1756
  };
933
1757
 
@@ -1008,6 +1832,48 @@ var MastraClient = class extends BaseResource {
1008
1832
  getMemoryStatus(agentId) {
1009
1833
  return this.request(`/api/memory/status?agentId=${agentId}`);
1010
1834
  }
1835
+ /**
1836
+ * Retrieves memory threads for a resource
1837
+ * @param params - Parameters containing the resource ID
1838
+ * @returns Promise containing array of memory threads
1839
+ */
1840
+ getNetworkMemoryThreads(params) {
1841
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
1842
+ }
1843
+ /**
1844
+ * Creates a new memory thread
1845
+ * @param params - Parameters for creating the memory thread
1846
+ * @returns Promise containing the created memory thread
1847
+ */
1848
+ createNetworkMemoryThread(params) {
1849
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
1850
+ }
1851
+ /**
1852
+ * Gets a memory thread instance by ID
1853
+ * @param threadId - ID of the memory thread to retrieve
1854
+ * @returns MemoryThread instance
1855
+ */
1856
+ getNetworkMemoryThread(threadId, networkId) {
1857
+ return new NetworkMemoryThread(this.options, threadId, networkId);
1858
+ }
1859
+ /**
1860
+ * Saves messages to memory
1861
+ * @param params - Parameters containing messages to save
1862
+ * @returns Promise containing the saved messages
1863
+ */
1864
+ saveNetworkMessageToMemory(params) {
1865
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
1866
+ method: "POST",
1867
+ body: params
1868
+ });
1869
+ }
1870
+ /**
1871
+ * Gets the status of the memory system
1872
+ * @returns Promise containing memory system status
1873
+ */
1874
+ getNetworkMemoryStatus(networkId) {
1875
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
1876
+ }
1011
1877
  /**
1012
1878
  * Retrieves all available tools
1013
1879
  * @returns Promise containing map of tool IDs to tool details
@@ -1021,7 +1887,22 @@ var MastraClient = class extends BaseResource {
1021
1887
  * @returns Tool instance
1022
1888
  */
1023
1889
  getTool(toolId) {
1024
- return new Tool(this.options, toolId);
1890
+ return new Tool2(this.options, toolId);
1891
+ }
1892
+ /**
1893
+ * Retrieves all available legacy workflows
1894
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1895
+ */
1896
+ getLegacyWorkflows() {
1897
+ return this.request("/api/workflows/legacy");
1898
+ }
1899
+ /**
1900
+ * Gets a legacy workflow instance by ID
1901
+ * @param workflowId - ID of the legacy workflow to retrieve
1902
+ * @returns Legacy Workflow instance
1903
+ */
1904
+ getLegacyWorkflow(workflowId) {
1905
+ return new LegacyWorkflow(this.options, workflowId);
1025
1906
  }
1026
1907
  /**
1027
1908
  * Retrieves all available workflows
@@ -1038,21 +1919,6 @@ var MastraClient = class extends BaseResource {
1038
1919
  getWorkflow(workflowId) {
1039
1920
  return new Workflow(this.options, workflowId);
1040
1921
  }
1041
- /**
1042
- * Retrieves all available vNext workflows
1043
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
1044
- */
1045
- getVNextWorkflows() {
1046
- return this.request("/api/workflows/v-next");
1047
- }
1048
- /**
1049
- * Gets a vNext workflow instance by ID
1050
- * @param workflowId - ID of the vNext workflow to retrieve
1051
- * @returns vNext Workflow instance
1052
- */
1053
- getVNextWorkflow(workflowId) {
1054
- return new VNextWorkflow(this.options, workflowId);
1055
- }
1056
1922
  /**
1057
1923
  * Gets a vector instance by name
1058
1924
  * @param vectorName - Name of the vector to retrieve
@@ -1067,7 +1933,41 @@ var MastraClient = class extends BaseResource {
1067
1933
  * @returns Promise containing array of log messages
1068
1934
  */
1069
1935
  getLogs(params) {
1070
- return this.request(`/api/logs?transportId=${params.transportId}`);
1936
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1937
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1938
+ const searchParams = new URLSearchParams();
1939
+ if (transportId) {
1940
+ searchParams.set("transportId", transportId);
1941
+ }
1942
+ if (fromDate) {
1943
+ searchParams.set("fromDate", fromDate.toISOString());
1944
+ }
1945
+ if (toDate) {
1946
+ searchParams.set("toDate", toDate.toISOString());
1947
+ }
1948
+ if (logLevel) {
1949
+ searchParams.set("logLevel", logLevel);
1950
+ }
1951
+ if (page) {
1952
+ searchParams.set("page", String(page));
1953
+ }
1954
+ if (perPage) {
1955
+ searchParams.set("perPage", String(perPage));
1956
+ }
1957
+ if (_filters) {
1958
+ if (Array.isArray(_filters)) {
1959
+ for (const filter of _filters) {
1960
+ searchParams.append("filters", filter);
1961
+ }
1962
+ } else {
1963
+ searchParams.set("filters", _filters);
1964
+ }
1965
+ }
1966
+ if (searchParams.size) {
1967
+ return this.request(`/api/logs?${searchParams}`);
1968
+ } else {
1969
+ return this.request(`/api/logs`);
1970
+ }
1071
1971
  }
1072
1972
  /**
1073
1973
  * Gets logs for a specific run
@@ -1075,7 +1975,44 @@ var MastraClient = class extends BaseResource {
1075
1975
  * @returns Promise containing array of log messages
1076
1976
  */
1077
1977
  getLogForRun(params) {
1078
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
1978
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
1979
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
1980
+ const searchParams = new URLSearchParams();
1981
+ if (runId) {
1982
+ searchParams.set("runId", runId);
1983
+ }
1984
+ if (transportId) {
1985
+ searchParams.set("transportId", transportId);
1986
+ }
1987
+ if (fromDate) {
1988
+ searchParams.set("fromDate", fromDate.toISOString());
1989
+ }
1990
+ if (toDate) {
1991
+ searchParams.set("toDate", toDate.toISOString());
1992
+ }
1993
+ if (logLevel) {
1994
+ searchParams.set("logLevel", logLevel);
1995
+ }
1996
+ if (page) {
1997
+ searchParams.set("page", String(page));
1998
+ }
1999
+ if (perPage) {
2000
+ searchParams.set("perPage", String(perPage));
2001
+ }
2002
+ if (_filters) {
2003
+ if (Array.isArray(_filters)) {
2004
+ for (const filter of _filters) {
2005
+ searchParams.append("filters", filter);
2006
+ }
2007
+ } else {
2008
+ searchParams.set("filters", _filters);
2009
+ }
2010
+ }
2011
+ if (searchParams.size) {
2012
+ return this.request(`/api/logs/${runId}?${searchParams}`);
2013
+ } else {
2014
+ return this.request(`/api/logs/${runId}`);
2015
+ }
1079
2016
  }
1080
2017
  /**
1081
2018
  * List of all log transports
@@ -1133,6 +2070,13 @@ var MastraClient = class extends BaseResource {
1133
2070
  getNetworks() {
1134
2071
  return this.request("/api/networks");
1135
2072
  }
2073
+ /**
2074
+ * Retrieves all available vNext networks
2075
+ * @returns Promise containing map of vNext network IDs to vNext network details
2076
+ */
2077
+ getVNextNetworks() {
2078
+ return this.request("/api/networks/v-next");
2079
+ }
1136
2080
  /**
1137
2081
  * Gets a network instance by ID
1138
2082
  * @param networkId - ID of the network to retrieve
@@ -1141,6 +2085,70 @@ var MastraClient = class extends BaseResource {
1141
2085
  getNetwork(networkId) {
1142
2086
  return new Network(this.options, networkId);
1143
2087
  }
2088
+ /**
2089
+ * Gets a vNext network instance by ID
2090
+ * @param networkId - ID of the vNext network to retrieve
2091
+ * @returns vNext Network instance
2092
+ */
2093
+ getVNextNetwork(networkId) {
2094
+ return new VNextNetwork(this.options, networkId);
2095
+ }
2096
+ /**
2097
+ * Retrieves a list of available MCP servers.
2098
+ * @param params - Optional parameters for pagination (limit, offset).
2099
+ * @returns Promise containing the list of MCP servers and pagination info.
2100
+ */
2101
+ getMcpServers(params) {
2102
+ const searchParams = new URLSearchParams();
2103
+ if (params?.limit !== void 0) {
2104
+ searchParams.set("limit", String(params.limit));
2105
+ }
2106
+ if (params?.offset !== void 0) {
2107
+ searchParams.set("offset", String(params.offset));
2108
+ }
2109
+ const queryString = searchParams.toString();
2110
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
2111
+ }
2112
+ /**
2113
+ * Retrieves detailed information for a specific MCP server.
2114
+ * @param serverId - The ID of the MCP server to retrieve.
2115
+ * @param params - Optional parameters, e.g., specific version.
2116
+ * @returns Promise containing the detailed MCP server information.
2117
+ */
2118
+ getMcpServerDetails(serverId, params) {
2119
+ const searchParams = new URLSearchParams();
2120
+ if (params?.version) {
2121
+ searchParams.set("version", params.version);
2122
+ }
2123
+ const queryString = searchParams.toString();
2124
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
2125
+ }
2126
+ /**
2127
+ * Retrieves a list of tools for a specific MCP server.
2128
+ * @param serverId - The ID of the MCP server.
2129
+ * @returns Promise containing the list of tools.
2130
+ */
2131
+ getMcpServerTools(serverId) {
2132
+ return this.request(`/api/mcp/${serverId}/tools`);
2133
+ }
2134
+ /**
2135
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
2136
+ * This instance can then be used to fetch details or execute the tool.
2137
+ * @param serverId - The ID of the MCP server.
2138
+ * @param toolId - The ID of the tool.
2139
+ * @returns MCPTool instance.
2140
+ */
2141
+ getMcpServerTool(serverId, toolId) {
2142
+ return new MCPTool(this.options, serverId, toolId);
2143
+ }
2144
+ /**
2145
+ * Gets an A2A client for interacting with an agent via the A2A protocol
2146
+ * @param agentId - ID of the agent to interact with
2147
+ * @returns A2A client instance
2148
+ */
2149
+ getA2A(agentId) {
2150
+ return new A2A(this.options, agentId);
2151
+ }
1144
2152
  };
1145
2153
 
1146
2154
  exports.MastraClient = MastraClient;