@mastra/client-js 0.0.0-mcp-changeset-20250707162621 → 0.0.0-message-list-update-20250715150321

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
@@ -6,6 +6,7 @@ var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
7
  var originalZodToJsonSchema = require('zod-to-json-schema');
8
8
  var tools = require('@mastra/core/tools');
9
+ var uuid = require('@lukeed/uuid');
9
10
  var runtimeContext = require('@mastra/core/runtime-context');
10
11
 
11
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -258,6 +259,7 @@ var BaseResource = class {
258
259
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
259
260
  // 'x-mastra-client-type': 'js',
260
261
  },
262
+ signal: this.options.abortSignal,
261
263
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
262
264
  });
263
265
  if (!response.ok) {
@@ -381,7 +383,11 @@ var Agent = class extends BaseResource {
381
383
  body: processedParams
382
384
  });
383
385
  if (response.finishReason === "tool-calls") {
384
- for (const toolCall of response.toolCalls) {
386
+ const toolCalls = response.toolCalls;
387
+ if (!toolCalls || !Array.isArray(toolCalls)) {
388
+ return response;
389
+ }
390
+ for (const toolCall of toolCalls) {
385
391
  const clientTool = params.clientTools?.[toolCall.toolName];
386
392
  if (clientTool && clientTool.execute) {
387
393
  const result = await clientTool.execute(
@@ -424,7 +430,8 @@ var Agent = class extends BaseResource {
424
430
  onToolCall,
425
431
  onFinish,
426
432
  getCurrentDate = () => /* @__PURE__ */ new Date(),
427
- lastMessage
433
+ lastMessage,
434
+ streamProtocol
428
435
  }) {
429
436
  const replaceLastMessage = lastMessage?.role === "assistant";
430
437
  let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
@@ -432,7 +439,7 @@ var Agent = class extends BaseResource {
432
439
  return Math.max(max, toolInvocation.step ?? 0);
433
440
  }, 0) ?? 0) : 0;
434
441
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
435
- id: crypto.randomUUID(),
442
+ id: uuid.v4(),
436
443
  createdAt: getCurrentDate(),
437
444
  role: "assistant",
438
445
  content: "",
@@ -477,7 +484,7 @@ var Agent = class extends BaseResource {
477
484
  // changes. This is why we need to add a revision id to ensure that the message
478
485
  // is updated with SWR (without it, the changes get stuck in SWR and are not
479
486
  // forwarded to rendering):
480
- revisionId: crypto.randomUUID()
487
+ revisionId: uuid.v4()
481
488
  };
482
489
  update({
483
490
  message: copiedMessage,
@@ -485,228 +492,213 @@ var Agent = class extends BaseResource {
485
492
  replaceLastMessage
486
493
  });
487
494
  }
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;
495
+ if (streamProtocol === "text") {
496
+ await uiUtils.processTextStream({
497
+ stream,
498
+ onTextPart(value) {
499
+ message.content += value;
500
+ execUpdate();
499
501
  }
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);
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;
508
516
  }
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 {
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) {
606
579
  if (message.toolInvocations == null) {
607
580
  message.toolInvocations = [];
608
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
+ };
609
595
  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();
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);
625
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);
626
698
  }
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 });
682
- }
683
- /**
684
- * Streams a response from the agent
685
- * @param params - Stream parameters including prompt
686
- * @returns Promise containing the enhanced Response object with processDataStream method
687
- */
688
- async stream(params) {
689
- const processedParams = {
690
- ...params,
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)
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
699
  });
708
- };
709
- return streamResponse;
700
+ onFinish?.({ message, finishReason, usage });
701
+ }
710
702
  }
711
703
  /**
712
704
  * Processes the stream response and handles tool calls
@@ -721,6 +713,7 @@ var Agent = class extends BaseResource {
721
713
  throw new Error("No response body");
722
714
  }
723
715
  try {
716
+ const streamProtocol = processedParams.output ? "text" : "data";
724
717
  let toolCalls = [];
725
718
  let messages = [];
726
719
  const [streamForWritable, streamForProcessing] = response.body.tee();
@@ -800,17 +793,55 @@ var Agent = class extends BaseResource {
800
793
  }
801
794
  } else {
802
795
  setTimeout(() => {
803
- writable.close();
796
+ if (!writable.locked) {
797
+ writable.close();
798
+ }
804
799
  }, 0);
805
800
  }
806
801
  },
807
- lastMessage: void 0
802
+ lastMessage: void 0,
803
+ streamProtocol
808
804
  });
809
805
  } catch (error) {
810
806
  console.error("Error processing stream response:", error);
811
807
  }
812
808
  return response;
813
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 = {}) => {
831
+ await uiUtils.processDataStream({
832
+ stream: streamResponse.body,
833
+ ...options
834
+ });
835
+ };
836
+ streamResponse.processTextStream = async (options) => {
837
+ await uiUtils.processTextStream({
838
+ stream: streamResponse.body,
839
+ onTextPart: options?.onTextPart ?? (() => {
840
+ })
841
+ });
842
+ };
843
+ return streamResponse;
844
+ }
814
845
  /**
815
846
  * Gets details about a specific tool available to the agent
816
847
  * @param toolId - ID of the tool to retrieve
@@ -1643,6 +1674,54 @@ var MCPTool = class extends BaseResource {
1643
1674
  }
1644
1675
  };
1645
1676
 
1677
+ // src/resources/network-memory-thread.ts
1678
+ var NetworkMemoryThread = class extends BaseResource {
1679
+ constructor(options, threadId, networkId) {
1680
+ super(options);
1681
+ this.threadId = threadId;
1682
+ this.networkId = networkId;
1683
+ }
1684
+ /**
1685
+ * Retrieves the memory thread details
1686
+ * @returns Promise containing thread details including title and metadata
1687
+ */
1688
+ get() {
1689
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1690
+ }
1691
+ /**
1692
+ * Updates the memory thread properties
1693
+ * @param params - Update parameters including title and metadata
1694
+ * @returns Promise containing updated thread details
1695
+ */
1696
+ update(params) {
1697
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1698
+ method: "PATCH",
1699
+ body: params
1700
+ });
1701
+ }
1702
+ /**
1703
+ * Deletes the memory thread
1704
+ * @returns Promise containing deletion result
1705
+ */
1706
+ delete() {
1707
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1708
+ method: "DELETE"
1709
+ });
1710
+ }
1711
+ /**
1712
+ * Retrieves messages associated with the thread
1713
+ * @param params - Optional parameters including limit for number of messages to retrieve
1714
+ * @returns Promise containing thread messages and UI messages
1715
+ */
1716
+ getMessages(params) {
1717
+ const query = new URLSearchParams({
1718
+ networkId: this.networkId,
1719
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1720
+ });
1721
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1722
+ }
1723
+ };
1724
+
1646
1725
  // src/resources/vNextNetwork.ts
1647
1726
  var RECORD_SEPARATOR3 = "";
1648
1727
  var VNextNetwork = class extends BaseResource {
@@ -1665,7 +1744,10 @@ var VNextNetwork = class extends BaseResource {
1665
1744
  generate(params) {
1666
1745
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1667
1746
  method: "POST",
1668
- body: params
1747
+ body: {
1748
+ ...params,
1749
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1750
+ }
1669
1751
  });
1670
1752
  }
1671
1753
  /**
@@ -1676,7 +1758,10 @@ var VNextNetwork = class extends BaseResource {
1676
1758
  loop(params) {
1677
1759
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1678
1760
  method: "POST",
1679
- body: params
1761
+ body: {
1762
+ ...params,
1763
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1764
+ }
1680
1765
  });
1681
1766
  }
1682
1767
  async *streamProcessor(stream) {
@@ -1725,7 +1810,10 @@ var VNextNetwork = class extends BaseResource {
1725
1810
  async stream(params, onRecord) {
1726
1811
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1727
1812
  method: "POST",
1728
- body: params,
1813
+ body: {
1814
+ ...params,
1815
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1816
+ },
1729
1817
  stream: true
1730
1818
  });
1731
1819
  if (!response.ok) {
@@ -1750,7 +1838,10 @@ var VNextNetwork = class extends BaseResource {
1750
1838
  async loopStream(params, onRecord) {
1751
1839
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1752
1840
  method: "POST",
1753
- body: params,
1841
+ body: {
1842
+ ...params,
1843
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1844
+ },
1754
1845
  stream: true
1755
1846
  });
1756
1847
  if (!response.ok) {
@@ -1769,54 +1860,6 @@ var VNextNetwork = class extends BaseResource {
1769
1860
  }
1770
1861
  };
1771
1862
 
1772
- // src/resources/network-memory-thread.ts
1773
- var NetworkMemoryThread = class extends BaseResource {
1774
- constructor(options, threadId, networkId) {
1775
- super(options);
1776
- this.threadId = threadId;
1777
- this.networkId = networkId;
1778
- }
1779
- /**
1780
- * Retrieves the memory thread details
1781
- * @returns Promise containing thread details including title and metadata
1782
- */
1783
- get() {
1784
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1785
- }
1786
- /**
1787
- * Updates the memory thread properties
1788
- * @param params - Update parameters including title and metadata
1789
- * @returns Promise containing updated thread details
1790
- */
1791
- update(params) {
1792
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1793
- method: "PATCH",
1794
- body: params
1795
- });
1796
- }
1797
- /**
1798
- * Deletes the memory thread
1799
- * @returns Promise containing deletion result
1800
- */
1801
- delete() {
1802
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1803
- method: "DELETE"
1804
- });
1805
- }
1806
- /**
1807
- * Retrieves messages associated with the thread
1808
- * @param params - Optional parameters including limit for number of messages to retrieve
1809
- * @returns Promise containing thread messages and UI messages
1810
- */
1811
- getMessages(params) {
1812
- const query = new URLSearchParams({
1813
- networkId: this.networkId,
1814
- ...params?.limit ? { limit: params.limit.toString() } : {}
1815
- });
1816
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1817
- }
1818
- };
1819
-
1820
1863
  // src/client.ts
1821
1864
  var MastraClient = class extends BaseResource {
1822
1865
  constructor(options) {
@@ -2211,6 +2254,41 @@ var MastraClient = class extends BaseResource {
2211
2254
  getA2A(agentId) {
2212
2255
  return new A2A(this.options, agentId);
2213
2256
  }
2257
+ /**
2258
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2259
+ * @param agentId - ID of the agent.
2260
+ * @param threadId - ID of the thread.
2261
+ * @param resourceId - Optional ID of the resource.
2262
+ * @returns Working memory for the specified thread or resource.
2263
+ */
2264
+ getWorkingMemory({
2265
+ agentId,
2266
+ threadId,
2267
+ resourceId
2268
+ }) {
2269
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2270
+ }
2271
+ /**
2272
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2273
+ * @param agentId - ID of the agent.
2274
+ * @param threadId - ID of the thread.
2275
+ * @param workingMemory - The new working memory content.
2276
+ * @param resourceId - Optional ID of the resource.
2277
+ */
2278
+ updateWorkingMemory({
2279
+ agentId,
2280
+ threadId,
2281
+ workingMemory,
2282
+ resourceId
2283
+ }) {
2284
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2285
+ method: "POST",
2286
+ body: {
2287
+ workingMemory,
2288
+ resourceId
2289
+ }
2290
+ });
2291
+ }
2214
2292
  };
2215
2293
 
2216
2294
  exports.MastraClient = MastraClient;