@mastra/client-js 0.0.0-fix-generate-title-20250616171351 → 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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AbstractAgent, EventType } from '@ag-ui/client';
2
2
  import { Observable } from 'rxjs';
3
- import { processDataStream } from '@ai-sdk/ui-utils';
3
+ import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
4
4
  import { ZodSchema } from 'zod';
5
5
  import originalZodToJsonSchema from 'zod-to-json-schema';
6
6
  import { isVercelTool } from '@mastra/core/tools';
@@ -246,6 +246,7 @@ var BaseResource = class {
246
246
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
247
247
  ...options,
248
248
  headers: {
249
+ ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
249
250
  ...headers,
250
251
  ...options.headers
251
252
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
@@ -292,8 +293,6 @@ function parseClientRuntimeContext(runtimeContext) {
292
293
  }
293
294
  return void 0;
294
295
  }
295
-
296
- // src/resources/agent.ts
297
296
  var AgentVoice = class extends BaseResource {
298
297
  constructor(options, agentId) {
299
298
  super(options);
@@ -362,7 +361,7 @@ var Agent = class extends BaseResource {
362
361
  details() {
363
362
  return this.request(`/api/agents/${this.agentId}`);
364
363
  }
365
- generate(params) {
364
+ async generate(params) {
366
365
  const processedParams = {
367
366
  ...params,
368
367
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -370,10 +369,310 @@ var Agent = class extends BaseResource {
370
369
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
371
370
  clientTools: processClientTools(params.clientTools)
372
371
  };
373
- return this.request(`/api/agents/${this.agentId}/generate`, {
372
+ const { runId, resourceId, threadId, runtimeContext } = processedParams;
373
+ const response = await this.request(`/api/agents/${this.agentId}/generate`, {
374
374
  method: "POST",
375
375
  body: processedParams
376
376
  });
377
+ if (response.finishReason === "tool-calls") {
378
+ for (const toolCall of response.toolCalls) {
379
+ const clientTool = params.clientTools?.[toolCall.toolName];
380
+ if (clientTool && clientTool.execute) {
381
+ const result = await clientTool.execute(
382
+ { context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
383
+ {
384
+ messages: response.messages,
385
+ toolCallId: toolCall?.toolCallId
386
+ }
387
+ );
388
+ const updatedMessages = [
389
+ {
390
+ role: "user",
391
+ content: params.messages
392
+ },
393
+ ...response.response.messages,
394
+ {
395
+ role: "tool",
396
+ content: [
397
+ {
398
+ type: "tool-result",
399
+ toolCallId: toolCall.toolCallId,
400
+ toolName: toolCall.toolName,
401
+ result
402
+ }
403
+ ]
404
+ }
405
+ ];
406
+ return this.generate({
407
+ ...params,
408
+ messages: updatedMessages
409
+ });
410
+ }
411
+ }
412
+ }
413
+ return response;
414
+ }
415
+ async processChatResponse({
416
+ stream,
417
+ update,
418
+ onToolCall,
419
+ onFinish,
420
+ getCurrentDate = () => /* @__PURE__ */ new Date(),
421
+ lastMessage
422
+ }) {
423
+ const replaceLastMessage = lastMessage?.role === "assistant";
424
+ let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
425
+ (lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
426
+ return Math.max(max, toolInvocation.step ?? 0);
427
+ }, 0) ?? 0) : 0;
428
+ const message = replaceLastMessage ? structuredClone(lastMessage) : {
429
+ id: crypto.randomUUID(),
430
+ createdAt: getCurrentDate(),
431
+ role: "assistant",
432
+ content: "",
433
+ parts: []
434
+ };
435
+ let currentTextPart = void 0;
436
+ let currentReasoningPart = void 0;
437
+ let currentReasoningTextDetail = void 0;
438
+ function updateToolInvocationPart(toolCallId, invocation) {
439
+ const part = message.parts.find(
440
+ (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
441
+ );
442
+ if (part != null) {
443
+ part.toolInvocation = invocation;
444
+ } else {
445
+ message.parts.push({
446
+ type: "tool-invocation",
447
+ toolInvocation: invocation
448
+ });
449
+ }
450
+ }
451
+ const data = [];
452
+ let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
453
+ const partialToolCalls = {};
454
+ let usage = {
455
+ completionTokens: NaN,
456
+ promptTokens: NaN,
457
+ totalTokens: NaN
458
+ };
459
+ let finishReason = "unknown";
460
+ function execUpdate() {
461
+ const copiedData = [...data];
462
+ if (messageAnnotations?.length) {
463
+ message.annotations = messageAnnotations;
464
+ }
465
+ const copiedMessage = {
466
+ // deep copy the message to ensure that deep changes (msg attachments) are updated
467
+ // with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
468
+ ...structuredClone(message),
469
+ // add a revision id to ensure that the message is updated with SWR. SWR uses a
470
+ // hashing approach by default to detect changes, but it only works for shallow
471
+ // changes. This is why we need to add a revision id to ensure that the message
472
+ // is updated with SWR (without it, the changes get stuck in SWR and are not
473
+ // forwarded to rendering):
474
+ revisionId: crypto.randomUUID()
475
+ };
476
+ update({
477
+ message: copiedMessage,
478
+ data: copiedData,
479
+ replaceLastMessage
480
+ });
481
+ }
482
+ await processDataStream({
483
+ stream,
484
+ onTextPart(value) {
485
+ if (currentTextPart == null) {
486
+ currentTextPart = {
487
+ type: "text",
488
+ text: value
489
+ };
490
+ message.parts.push(currentTextPart);
491
+ } else {
492
+ currentTextPart.text += value;
493
+ }
494
+ message.content += value;
495
+ execUpdate();
496
+ },
497
+ onReasoningPart(value) {
498
+ if (currentReasoningTextDetail == null) {
499
+ currentReasoningTextDetail = { type: "text", text: value };
500
+ if (currentReasoningPart != null) {
501
+ currentReasoningPart.details.push(currentReasoningTextDetail);
502
+ }
503
+ } else {
504
+ currentReasoningTextDetail.text += value;
505
+ }
506
+ if (currentReasoningPart == null) {
507
+ currentReasoningPart = {
508
+ type: "reasoning",
509
+ reasoning: value,
510
+ details: [currentReasoningTextDetail]
511
+ };
512
+ message.parts.push(currentReasoningPart);
513
+ } else {
514
+ currentReasoningPart.reasoning += value;
515
+ }
516
+ message.reasoning = (message.reasoning ?? "") + value;
517
+ execUpdate();
518
+ },
519
+ onReasoningSignaturePart(value) {
520
+ if (currentReasoningTextDetail != null) {
521
+ currentReasoningTextDetail.signature = value.signature;
522
+ }
523
+ },
524
+ onRedactedReasoningPart(value) {
525
+ if (currentReasoningPart == null) {
526
+ currentReasoningPart = {
527
+ type: "reasoning",
528
+ reasoning: "",
529
+ details: []
530
+ };
531
+ message.parts.push(currentReasoningPart);
532
+ }
533
+ currentReasoningPart.details.push({
534
+ type: "redacted",
535
+ data: value.data
536
+ });
537
+ currentReasoningTextDetail = void 0;
538
+ execUpdate();
539
+ },
540
+ onFilePart(value) {
541
+ message.parts.push({
542
+ type: "file",
543
+ mimeType: value.mimeType,
544
+ data: value.data
545
+ });
546
+ execUpdate();
547
+ },
548
+ onSourcePart(value) {
549
+ message.parts.push({
550
+ type: "source",
551
+ source: value
552
+ });
553
+ execUpdate();
554
+ },
555
+ onToolCallStreamingStartPart(value) {
556
+ if (message.toolInvocations == null) {
557
+ message.toolInvocations = [];
558
+ }
559
+ partialToolCalls[value.toolCallId] = {
560
+ text: "",
561
+ step,
562
+ toolName: value.toolName,
563
+ index: message.toolInvocations.length
564
+ };
565
+ const invocation = {
566
+ state: "partial-call",
567
+ step,
568
+ toolCallId: value.toolCallId,
569
+ toolName: value.toolName,
570
+ args: void 0
571
+ };
572
+ message.toolInvocations.push(invocation);
573
+ updateToolInvocationPart(value.toolCallId, invocation);
574
+ execUpdate();
575
+ },
576
+ onToolCallDeltaPart(value) {
577
+ const partialToolCall = partialToolCalls[value.toolCallId];
578
+ partialToolCall.text += value.argsTextDelta;
579
+ const { value: partialArgs } = parsePartialJson(partialToolCall.text);
580
+ const invocation = {
581
+ state: "partial-call",
582
+ step: partialToolCall.step,
583
+ toolCallId: value.toolCallId,
584
+ toolName: partialToolCall.toolName,
585
+ args: partialArgs
586
+ };
587
+ message.toolInvocations[partialToolCall.index] = invocation;
588
+ updateToolInvocationPart(value.toolCallId, invocation);
589
+ execUpdate();
590
+ },
591
+ async onToolCallPart(value) {
592
+ const invocation = {
593
+ state: "call",
594
+ step,
595
+ ...value
596
+ };
597
+ if (partialToolCalls[value.toolCallId] != null) {
598
+ message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
599
+ } else {
600
+ if (message.toolInvocations == null) {
601
+ message.toolInvocations = [];
602
+ }
603
+ message.toolInvocations.push(invocation);
604
+ }
605
+ updateToolInvocationPart(value.toolCallId, invocation);
606
+ execUpdate();
607
+ if (onToolCall) {
608
+ const result = await onToolCall({ toolCall: value });
609
+ if (result != null) {
610
+ const invocation2 = {
611
+ state: "result",
612
+ step,
613
+ ...value,
614
+ result
615
+ };
616
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
617
+ updateToolInvocationPart(value.toolCallId, invocation2);
618
+ execUpdate();
619
+ }
620
+ }
621
+ },
622
+ onToolResultPart(value) {
623
+ const toolInvocations = message.toolInvocations;
624
+ if (toolInvocations == null) {
625
+ throw new Error("tool_result must be preceded by a tool_call");
626
+ }
627
+ const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
628
+ if (toolInvocationIndex === -1) {
629
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
630
+ }
631
+ const invocation = {
632
+ ...toolInvocations[toolInvocationIndex],
633
+ state: "result",
634
+ ...value
635
+ };
636
+ toolInvocations[toolInvocationIndex] = invocation;
637
+ updateToolInvocationPart(value.toolCallId, invocation);
638
+ execUpdate();
639
+ },
640
+ onDataPart(value) {
641
+ data.push(...value);
642
+ execUpdate();
643
+ },
644
+ onMessageAnnotationsPart(value) {
645
+ if (messageAnnotations == null) {
646
+ messageAnnotations = [...value];
647
+ } else {
648
+ messageAnnotations.push(...value);
649
+ }
650
+ execUpdate();
651
+ },
652
+ onFinishStepPart(value) {
653
+ step += 1;
654
+ currentTextPart = value.isContinued ? currentTextPart : void 0;
655
+ currentReasoningPart = void 0;
656
+ currentReasoningTextDetail = void 0;
657
+ },
658
+ onStartStepPart(value) {
659
+ if (!replaceLastMessage) {
660
+ message.id = value.messageId;
661
+ }
662
+ message.parts.push({ type: "step-start" });
663
+ execUpdate();
664
+ },
665
+ onFinishMessagePart(value) {
666
+ finishReason = value.finishReason;
667
+ if (value.usage != null) {
668
+ usage = value.usage;
669
+ }
670
+ },
671
+ onErrorPart(error) {
672
+ throw new Error(error);
673
+ }
674
+ });
675
+ onFinish?.({ message, finishReason, usage });
377
676
  }
378
677
  /**
379
678
  * Streams a response from the agent
@@ -388,6 +687,25 @@ var Agent = class extends BaseResource {
388
687
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
389
688
  clientTools: processClientTools(params.clientTools)
390
689
  };
690
+ const { readable, writable } = new TransformStream();
691
+ const response = await this.processStreamResponse(processedParams, writable);
692
+ const streamResponse = new Response(readable, {
693
+ status: response.status,
694
+ statusText: response.statusText,
695
+ headers: response.headers
696
+ });
697
+ streamResponse.processDataStream = async (options = {}) => {
698
+ await processDataStream({
699
+ stream: streamResponse.body,
700
+ ...options
701
+ });
702
+ };
703
+ return streamResponse;
704
+ }
705
+ /**
706
+ * Processes the stream response and handles tool calls
707
+ */
708
+ async processStreamResponse(processedParams, writable) {
391
709
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
392
710
  method: "POST",
393
711
  body: processedParams,
@@ -396,12 +714,79 @@ var Agent = class extends BaseResource {
396
714
  if (!response.body) {
397
715
  throw new Error("No response body");
398
716
  }
399
- response.processDataStream = async (options = {}) => {
400
- await processDataStream({
401
- stream: response.body,
402
- ...options
717
+ try {
718
+ let toolCalls = [];
719
+ let finishReasonToolCalls = false;
720
+ let messages = [];
721
+ let hasProcessedToolCalls = false;
722
+ response.clone().body.pipeTo(writable);
723
+ await this.processChatResponse({
724
+ stream: response.clone().body,
725
+ update: ({ message }) => {
726
+ messages.push(message);
727
+ },
728
+ onFinish: ({ finishReason, message }) => {
729
+ if (finishReason === "tool-calls") {
730
+ finishReasonToolCalls = true;
731
+ const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
732
+ if (toolCall) {
733
+ toolCalls.push(toolCall);
734
+ }
735
+ }
736
+ },
737
+ lastMessage: void 0
403
738
  });
404
- };
739
+ if (finishReasonToolCalls && !hasProcessedToolCalls) {
740
+ hasProcessedToolCalls = true;
741
+ for (const toolCall of toolCalls) {
742
+ const clientTool = processedParams.clientTools?.[toolCall.toolName];
743
+ if (clientTool && clientTool.execute) {
744
+ const result = await clientTool.execute(
745
+ {
746
+ context: toolCall?.args,
747
+ runId: processedParams.runId,
748
+ resourceId: processedParams.resourceId,
749
+ threadId: processedParams.threadId,
750
+ runtimeContext: processedParams.runtimeContext
751
+ },
752
+ {
753
+ messages: response.messages,
754
+ toolCallId: toolCall?.toolCallId
755
+ }
756
+ );
757
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
758
+ const toolInvocationPart = lastMessage?.parts?.find(
759
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall.toolCallId
760
+ );
761
+ if (toolInvocationPart) {
762
+ toolInvocationPart.toolInvocation = {
763
+ ...toolInvocationPart.toolInvocation,
764
+ state: "result",
765
+ result
766
+ };
767
+ }
768
+ const toolInvocation = lastMessage?.toolInvocations?.find(
769
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall.toolCallId
770
+ );
771
+ if (toolInvocation) {
772
+ toolInvocation.state = "result";
773
+ toolInvocation.result = result;
774
+ }
775
+ const originalMessages = processedParams.messages;
776
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
777
+ this.processStreamResponse(
778
+ {
779
+ ...processedParams,
780
+ messages: [...messageArray, ...messages, lastMessage]
781
+ },
782
+ writable
783
+ );
784
+ }
785
+ }
786
+ }
787
+ } catch (error) {
788
+ console.error("Error processing stream response:", error);
789
+ }
405
790
  return response;
406
791
  }
407
792
  /**
@@ -796,7 +1181,7 @@ var LegacyWorkflow = class extends BaseResource {
796
1181
  };
797
1182
 
798
1183
  // src/resources/tool.ts
799
- var Tool = class extends BaseResource {
1184
+ var Tool2 = class extends BaseResource {
800
1185
  constructor(options, toolId) {
801
1186
  super(options);
802
1187
  this.toolId = toolId;
@@ -901,10 +1286,10 @@ var Workflow = class extends BaseResource {
901
1286
  if (params?.toDate) {
902
1287
  searchParams.set("toDate", params.toDate.toISOString());
903
1288
  }
904
- if (params?.limit) {
1289
+ if (params?.limit !== void 0) {
905
1290
  searchParams.set("limit", String(params.limit));
906
1291
  }
907
- if (params?.offset) {
1292
+ if (params?.offset !== void 0) {
908
1293
  searchParams.set("offset", String(params.offset));
909
1294
  }
910
1295
  if (params?.resourceId) {
@@ -997,9 +1382,9 @@ var Workflow = class extends BaseResource {
997
1382
  });
998
1383
  }
999
1384
  /**
1000
- * Starts a vNext workflow run and returns a stream
1385
+ * Starts a workflow run and returns a stream
1001
1386
  * @param params - Object containing the optional runId, inputData and runtimeContext
1002
- * @returns Promise containing the vNext workflow execution results
1387
+ * @returns Promise containing the workflow execution results
1003
1388
  */
1004
1389
  async stream(params) {
1005
1390
  const searchParams = new URLSearchParams();
@@ -1215,6 +1600,155 @@ var MCPTool = class extends BaseResource {
1215
1600
  }
1216
1601
  };
1217
1602
 
1603
+ // src/resources/vNextNetwork.ts
1604
+ var RECORD_SEPARATOR3 = "";
1605
+ var VNextNetwork = class extends BaseResource {
1606
+ constructor(options, networkId) {
1607
+ super(options);
1608
+ this.networkId = networkId;
1609
+ }
1610
+ /**
1611
+ * Retrieves details about the network
1612
+ * @returns Promise containing vNext network details
1613
+ */
1614
+ details() {
1615
+ return this.request(`/api/networks/v-next/${this.networkId}`);
1616
+ }
1617
+ /**
1618
+ * Generates a response from the v-next network
1619
+ * @param params - Generation parameters including message
1620
+ * @returns Promise containing the generated response
1621
+ */
1622
+ generate(params) {
1623
+ return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1624
+ method: "POST",
1625
+ body: params
1626
+ });
1627
+ }
1628
+ /**
1629
+ * Generates a response from the v-next network using multiple primitives
1630
+ * @param params - Generation parameters including message
1631
+ * @returns Promise containing the generated response
1632
+ */
1633
+ loop(params) {
1634
+ return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1635
+ method: "POST",
1636
+ body: params
1637
+ });
1638
+ }
1639
+ async *streamProcessor(stream) {
1640
+ const reader = stream.getReader();
1641
+ let doneReading = false;
1642
+ let buffer = "";
1643
+ try {
1644
+ while (!doneReading) {
1645
+ const { done, value } = await reader.read();
1646
+ doneReading = done;
1647
+ if (done && !value) continue;
1648
+ try {
1649
+ const decoded = value ? new TextDecoder().decode(value) : "";
1650
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
1651
+ buffer = chunks.pop() || "";
1652
+ for (const chunk of chunks) {
1653
+ if (chunk) {
1654
+ if (typeof chunk === "string") {
1655
+ try {
1656
+ const parsedChunk = JSON.parse(chunk);
1657
+ yield parsedChunk;
1658
+ } catch {
1659
+ }
1660
+ }
1661
+ }
1662
+ }
1663
+ } catch {
1664
+ }
1665
+ }
1666
+ if (buffer) {
1667
+ try {
1668
+ yield JSON.parse(buffer);
1669
+ } catch {
1670
+ }
1671
+ }
1672
+ } finally {
1673
+ reader.cancel().catch(() => {
1674
+ });
1675
+ }
1676
+ }
1677
+ /**
1678
+ * Streams a response from the v-next network
1679
+ * @param params - Stream parameters including message
1680
+ * @returns Promise containing the results
1681
+ */
1682
+ async stream(params, onRecord) {
1683
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1684
+ method: "POST",
1685
+ body: params,
1686
+ stream: true
1687
+ });
1688
+ if (!response.ok) {
1689
+ throw new Error(`Failed to stream vNext network: ${response.statusText}`);
1690
+ }
1691
+ if (!response.body) {
1692
+ throw new Error("Response body is null");
1693
+ }
1694
+ for await (const record of this.streamProcessor(response.body)) {
1695
+ if (typeof record === "string") {
1696
+ onRecord(JSON.parse(record));
1697
+ } else {
1698
+ onRecord(record);
1699
+ }
1700
+ }
1701
+ }
1702
+ };
1703
+
1704
+ // src/resources/network-memory-thread.ts
1705
+ var NetworkMemoryThread = class extends BaseResource {
1706
+ constructor(options, threadId, networkId) {
1707
+ super(options);
1708
+ this.threadId = threadId;
1709
+ this.networkId = networkId;
1710
+ }
1711
+ /**
1712
+ * Retrieves the memory thread details
1713
+ * @returns Promise containing thread details including title and metadata
1714
+ */
1715
+ get() {
1716
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1717
+ }
1718
+ /**
1719
+ * Updates the memory thread properties
1720
+ * @param params - Update parameters including title and metadata
1721
+ * @returns Promise containing updated thread details
1722
+ */
1723
+ update(params) {
1724
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1725
+ method: "PATCH",
1726
+ body: params
1727
+ });
1728
+ }
1729
+ /**
1730
+ * Deletes the memory thread
1731
+ * @returns Promise containing deletion result
1732
+ */
1733
+ delete() {
1734
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1735
+ method: "DELETE"
1736
+ });
1737
+ }
1738
+ /**
1739
+ * Retrieves messages associated with the thread
1740
+ * @param params - Optional parameters including limit for number of messages to retrieve
1741
+ * @returns Promise containing thread messages and UI messages
1742
+ */
1743
+ getMessages(params) {
1744
+ const query = new URLSearchParams({
1745
+ networkId: this.networkId,
1746
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1747
+ });
1748
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1749
+ }
1750
+ };
1751
+
1218
1752
  // src/client.ts
1219
1753
  var MastraClient = class extends BaseResource {
1220
1754
  constructor(options) {
@@ -1292,6 +1826,48 @@ var MastraClient = class extends BaseResource {
1292
1826
  getMemoryStatus(agentId) {
1293
1827
  return this.request(`/api/memory/status?agentId=${agentId}`);
1294
1828
  }
1829
+ /**
1830
+ * Retrieves memory threads for a resource
1831
+ * @param params - Parameters containing the resource ID
1832
+ * @returns Promise containing array of memory threads
1833
+ */
1834
+ getNetworkMemoryThreads(params) {
1835
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
1836
+ }
1837
+ /**
1838
+ * Creates a new memory thread
1839
+ * @param params - Parameters for creating the memory thread
1840
+ * @returns Promise containing the created memory thread
1841
+ */
1842
+ createNetworkMemoryThread(params) {
1843
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
1844
+ }
1845
+ /**
1846
+ * Gets a memory thread instance by ID
1847
+ * @param threadId - ID of the memory thread to retrieve
1848
+ * @returns MemoryThread instance
1849
+ */
1850
+ getNetworkMemoryThread(threadId, networkId) {
1851
+ return new NetworkMemoryThread(this.options, threadId, networkId);
1852
+ }
1853
+ /**
1854
+ * Saves messages to memory
1855
+ * @param params - Parameters containing messages to save
1856
+ * @returns Promise containing the saved messages
1857
+ */
1858
+ saveNetworkMessageToMemory(params) {
1859
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
1860
+ method: "POST",
1861
+ body: params
1862
+ });
1863
+ }
1864
+ /**
1865
+ * Gets the status of the memory system
1866
+ * @returns Promise containing memory system status
1867
+ */
1868
+ getNetworkMemoryStatus(networkId) {
1869
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
1870
+ }
1295
1871
  /**
1296
1872
  * Retrieves all available tools
1297
1873
  * @returns Promise containing map of tool IDs to tool details
@@ -1305,7 +1881,7 @@ var MastraClient = class extends BaseResource {
1305
1881
  * @returns Tool instance
1306
1882
  */
1307
1883
  getTool(toolId) {
1308
- return new Tool(this.options, toolId);
1884
+ return new Tool2(this.options, toolId);
1309
1885
  }
1310
1886
  /**
1311
1887
  * Retrieves all available legacy workflows
@@ -1488,6 +2064,13 @@ var MastraClient = class extends BaseResource {
1488
2064
  getNetworks() {
1489
2065
  return this.request("/api/networks");
1490
2066
  }
2067
+ /**
2068
+ * Retrieves all available vNext networks
2069
+ * @returns Promise containing map of vNext network IDs to vNext network details
2070
+ */
2071
+ getVNextNetworks() {
2072
+ return this.request("/api/networks/v-next");
2073
+ }
1491
2074
  /**
1492
2075
  * Gets a network instance by ID
1493
2076
  * @param networkId - ID of the network to retrieve
@@ -1496,6 +2079,14 @@ var MastraClient = class extends BaseResource {
1496
2079
  getNetwork(networkId) {
1497
2080
  return new Network(this.options, networkId);
1498
2081
  }
2082
+ /**
2083
+ * Gets a vNext network instance by ID
2084
+ * @param networkId - ID of the vNext network to retrieve
2085
+ * @returns vNext Network instance
2086
+ */
2087
+ getVNextNetwork(networkId) {
2088
+ return new VNextNetwork(this.options, networkId);
2089
+ }
1499
2090
  /**
1500
2091
  * Retrieves a list of available MCP servers.
1501
2092
  * @param params - Optional parameters for pagination (limit, offset).