@mastra/client-js 0.0.0-mcp-changeset-20250707162621 → 0.0.0-memory-system-message-error-20250813233316

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +527 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +1 -0
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +270 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +333 -98
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -1164
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +332 -97
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +41 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +123 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +15 -9
  55. package/src/adapters/agui.test.ts +145 -3
  56. package/src/adapters/agui.ts +29 -11
  57. package/src/client.ts +153 -2
  58. package/src/example.ts +45 -17
  59. package/src/index.test.ts +402 -6
  60. package/src/index.ts +1 -0
  61. package/src/resources/a2a.ts +35 -25
  62. package/src/resources/agent.ts +58 -24
  63. package/src/resources/base.ts +6 -1
  64. package/src/resources/memory-thread.test.ts +285 -0
  65. package/src/resources/memory-thread.ts +36 -0
  66. package/src/resources/network-memory-thread.test.ts +269 -0
  67. package/src/resources/network-memory-thread.ts +18 -0
  68. package/src/resources/network.ts +4 -3
  69. package/src/resources/vNextNetwork.ts +22 -5
  70. package/src/resources/workflow.ts +17 -3
  71. package/src/types.ts +90 -10
  72. package/src/utils/process-client-tools.ts +1 -1
  73. package/src/v2-messages.test.ts +180 -0
  74. package/tsconfig.build.json +9 -0
  75. package/tsconfig.json +1 -1
  76. package/tsup.config.ts +17 -0
  77. package/.turbo/turbo-build.log +0 -19
  78. package/dist/index.d.cts +0 -1164
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -3,7 +3,8 @@ import { Observable } from 'rxjs';
3
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
- import { isVercelTool } from '@mastra/core/tools';
6
+ import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
7
+ import { v4 } from '@lukeed/uuid';
7
8
  import { RuntimeContext } from '@mastra/core/runtime-context';
8
9
 
9
10
  // src/adapters/agui.ts
@@ -144,6 +145,12 @@ function generateUUID() {
144
145
  }
145
146
  function convertMessagesToMastraMessages(messages) {
146
147
  const result = [];
148
+ const toolCallsWithResults = /* @__PURE__ */ new Set();
149
+ for (const message of messages) {
150
+ if (message.role === "tool" && message.toolCallId) {
151
+ toolCallsWithResults.add(message.toolCallId);
152
+ }
153
+ }
147
154
  for (const message of messages) {
148
155
  if (message.role === "assistant") {
149
156
  const parts = message.content ? [{ type: "text", text: message.content }] : [];
@@ -160,15 +167,22 @@ function convertMessagesToMastraMessages(messages) {
160
167
  content: parts
161
168
  });
162
169
  if (message.toolCalls?.length) {
163
- result.push({
164
- role: "tool",
165
- content: message.toolCalls.map((toolCall) => ({
166
- type: "tool-result",
167
- toolCallId: toolCall.id,
168
- toolName: toolCall.function.name,
169
- result: JSON.parse(toolCall.function.arguments)
170
- }))
171
- });
170
+ for (const toolCall of message.toolCalls) {
171
+ if (!toolCallsWithResults.has(toolCall.id)) {
172
+ result.push({
173
+ role: "tool",
174
+ content: [
175
+ {
176
+ type: "tool-result",
177
+ toolCallId: toolCall.id,
178
+ toolName: toolCall.function.name,
179
+ result: JSON.parse(toolCall.function.arguments)
180
+ // This is still wrong but matches test expectations
181
+ }
182
+ ]
183
+ });
184
+ }
185
+ }
172
186
  }
173
187
  } else if (message.role === "user") {
174
188
  result.push({
@@ -181,8 +195,9 @@ function convertMessagesToMastraMessages(messages) {
181
195
  content: [
182
196
  {
183
197
  type: "tool-result",
184
- toolCallId: message.toolCallId,
198
+ toolCallId: message.toolCallId || "unknown",
185
199
  toolName: "unknown",
200
+ // toolName is not available in tool messages from CopilotKit
186
201
  result: message.content
187
202
  }
188
203
  ]
@@ -246,12 +261,13 @@ var BaseResource = class {
246
261
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
247
262
  ...options,
248
263
  headers: {
249
- ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
264
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
250
265
  ...headers,
251
266
  ...options.headers
252
267
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
253
268
  // 'x-mastra-client-type': 'js',
254
269
  },
270
+ signal: this.options.abortSignal,
255
271
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
256
272
  });
257
273
  if (!response.ok) {
@@ -370,12 +386,19 @@ var Agent = class extends BaseResource {
370
386
  clientTools: processClientTools(params.clientTools)
371
387
  };
372
388
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
373
- const response = await this.request(`/api/agents/${this.agentId}/generate`, {
374
- method: "POST",
375
- body: processedParams
376
- });
389
+ const response = await this.request(
390
+ `/api/agents/${this.agentId}/generate`,
391
+ {
392
+ method: "POST",
393
+ body: processedParams
394
+ }
395
+ );
377
396
  if (response.finishReason === "tool-calls") {
378
- for (const toolCall of response.toolCalls) {
397
+ const toolCalls = response.toolCalls;
398
+ if (!toolCalls || !Array.isArray(toolCalls)) {
399
+ return response;
400
+ }
401
+ for (const toolCall of toolCalls) {
379
402
  const clientTool = params.clientTools?.[toolCall.toolName];
380
403
  if (clientTool && clientTool.execute) {
381
404
  const result = await clientTool.execute(
@@ -426,7 +449,7 @@ var Agent = class extends BaseResource {
426
449
  return Math.max(max, toolInvocation.step ?? 0);
427
450
  }, 0) ?? 0) : 0;
428
451
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
429
- id: crypto.randomUUID(),
452
+ id: v4(),
430
453
  createdAt: getCurrentDate(),
431
454
  role: "assistant",
432
455
  content: "",
@@ -471,7 +494,7 @@ var Agent = class extends BaseResource {
471
494
  // changes. This is why we need to add a revision id to ensure that the message
472
495
  // is updated with SWR (without it, the changes get stuck in SWR and are not
473
496
  // forwarded to rendering):
474
- revisionId: crypto.randomUUID()
497
+ revisionId: v4()
475
498
  };
476
499
  update({
477
500
  message: copiedMessage,
@@ -726,7 +749,12 @@ var Agent = class extends BaseResource {
726
749
  this.processChatResponse({
727
750
  stream: streamForProcessing,
728
751
  update: ({ message }) => {
729
- messages.push(message);
752
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
753
+ if (existingIndex !== -1) {
754
+ messages[existingIndex] = message;
755
+ } else {
756
+ messages.push(message);
757
+ }
730
758
  },
731
759
  onFinish: async ({ finishReason, message }) => {
732
760
  if (finishReason === "tool-calls") {
@@ -786,10 +814,12 @@ var Agent = class extends BaseResource {
786
814
  this.processStreamResponse(
787
815
  {
788
816
  ...processedParams,
789
- messages: [...messageArray, ...messages, lastMessage]
817
+ messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
790
818
  },
791
819
  writable
792
- );
820
+ ).catch((error) => {
821
+ console.error("Error processing stream response:", error);
822
+ });
793
823
  }
794
824
  }
795
825
  } else {
@@ -799,6 +829,8 @@ var Agent = class extends BaseResource {
799
829
  }
800
830
  },
801
831
  lastMessage: void 0
832
+ }).catch((error) => {
833
+ console.error("Error processing stream response:", error);
802
834
  });
803
835
  } catch (error) {
804
836
  console.error("Error processing stream response:", error);
@@ -843,6 +875,17 @@ var Agent = class extends BaseResource {
843
875
  liveEvals() {
844
876
  return this.request(`/api/agents/${this.agentId}/evals/live`);
845
877
  }
878
+ /**
879
+ * Updates the model for the agent
880
+ * @param params - Parameters for updating the model
881
+ * @returns Promise containing the updated model
882
+ */
883
+ updateModel(params) {
884
+ return this.request(`/api/agents/${this.agentId}/model`, {
885
+ method: "POST",
886
+ body: params
887
+ });
888
+ }
846
889
  };
847
890
  var Network = class extends BaseResource {
848
891
  constructor(options, networkId) {
@@ -947,6 +990,36 @@ var MemoryThread = class extends BaseResource {
947
990
  });
948
991
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
949
992
  }
993
+ /**
994
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
995
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
996
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
997
+ */
998
+ getMessagesPaginated({
999
+ selectBy,
1000
+ ...rest
1001
+ }) {
1002
+ const query = new URLSearchParams({
1003
+ ...rest,
1004
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1005
+ });
1006
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1007
+ }
1008
+ /**
1009
+ * Deletes one or more messages from the thread
1010
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1011
+ * message object with id property, or array of message objects
1012
+ * @returns Promise containing deletion result
1013
+ */
1014
+ deleteMessages(messageIds) {
1015
+ const query = new URLSearchParams({
1016
+ agentId: this.agentId
1017
+ });
1018
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1019
+ method: "POST",
1020
+ body: { messageIds }
1021
+ });
1022
+ }
950
1023
  };
951
1024
 
952
1025
  // src/resources/vector.ts
@@ -1368,6 +1441,14 @@ var Workflow = class extends BaseResource {
1368
1441
  method: "POST"
1369
1442
  });
1370
1443
  }
1444
+ /**
1445
+ * Creates a new workflow run (alias for createRun)
1446
+ * @param params - Optional object containing the optional runId
1447
+ * @returns Promise containing the runId of the created run
1448
+ */
1449
+ createRunAsync(params) {
1450
+ return this.createRun(params);
1451
+ }
1371
1452
  /**
1372
1453
  * Starts a workflow run synchronously without waiting for the workflow to complete
1373
1454
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1443,6 +1524,7 @@ var Workflow = class extends BaseResource {
1443
1524
  if (!response.body) {
1444
1525
  throw new Error("Response body is null");
1445
1526
  }
1527
+ let failedChunk = void 0;
1446
1528
  const transformStream = new TransformStream({
1447
1529
  start() {
1448
1530
  },
@@ -1452,10 +1534,13 @@ var Workflow = class extends BaseResource {
1452
1534
  const chunks = decoded.split(RECORD_SEPARATOR2);
1453
1535
  for (const chunk2 of chunks) {
1454
1536
  if (chunk2) {
1537
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1455
1538
  try {
1456
- const parsedChunk = JSON.parse(chunk2);
1539
+ const parsedChunk = JSON.parse(newChunk);
1457
1540
  controller.enqueue(parsedChunk);
1458
- } catch {
1541
+ failedChunk = void 0;
1542
+ } catch (error) {
1543
+ failedChunk = newChunk;
1459
1544
  }
1460
1545
  }
1461
1546
  }
@@ -1540,22 +1625,38 @@ var A2A = class extends BaseResource {
1540
1625
  * @returns Promise containing the agent card information
1541
1626
  */
1542
1627
  async getCard() {
1543
- return this.request(`/.well-known/${this.agentId}/agent.json`);
1628
+ return this.request(`/.well-known/${this.agentId}/agent-card.json`);
1544
1629
  }
1545
1630
  /**
1546
- * Send a message to the agent and get a response
1631
+ * Send a message to the agent and gets a message or task response
1547
1632
  * @param params - Parameters for the task
1548
- * @returns Promise containing the task response
1633
+ * @returns Promise containing the response
1549
1634
  */
1550
1635
  async sendMessage(params) {
1551
1636
  const response = await this.request(`/a2a/${this.agentId}`, {
1552
1637
  method: "POST",
1553
1638
  body: {
1554
- method: "tasks/send",
1639
+ method: "message/send",
1640
+ params
1641
+ }
1642
+ });
1643
+ return response;
1644
+ }
1645
+ /**
1646
+ * Sends a message to an agent to initiate/continue a task and subscribes
1647
+ * the client to real-time updates for that task via Server-Sent Events (SSE).
1648
+ * @param params - Parameters for the task
1649
+ * @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
1650
+ */
1651
+ async sendStreamingMessage(params) {
1652
+ const response = await this.request(`/a2a/${this.agentId}`, {
1653
+ method: "POST",
1654
+ body: {
1655
+ method: "message/stream",
1555
1656
  params
1556
1657
  }
1557
1658
  });
1558
- return { task: response.result };
1659
+ return response;
1559
1660
  }
1560
1661
  /**
1561
1662
  * Get the status and result of a task
@@ -1570,7 +1671,7 @@ var A2A = class extends BaseResource {
1570
1671
  params
1571
1672
  }
1572
1673
  });
1573
- return response.result;
1674
+ return response;
1574
1675
  }
1575
1676
  /**
1576
1677
  * Cancel a running task
@@ -1586,21 +1687,6 @@ var A2A = class extends BaseResource {
1586
1687
  }
1587
1688
  });
1588
1689
  }
1589
- /**
1590
- * Send a message and subscribe to streaming updates (not fully implemented)
1591
- * @param params - Parameters for the task
1592
- * @returns Promise containing the task response
1593
- */
1594
- async sendAndSubscribe(params) {
1595
- return this.request(`/a2a/${this.agentId}`, {
1596
- method: "POST",
1597
- body: {
1598
- method: "tasks/sendSubscribe",
1599
- params
1600
- },
1601
- stream: true
1602
- });
1603
- }
1604
1690
  };
1605
1691
 
1606
1692
  // src/resources/mcp-tool.ts
@@ -1637,6 +1723,69 @@ var MCPTool = class extends BaseResource {
1637
1723
  }
1638
1724
  };
1639
1725
 
1726
+ // src/resources/network-memory-thread.ts
1727
+ var NetworkMemoryThread = class extends BaseResource {
1728
+ constructor(options, threadId, networkId) {
1729
+ super(options);
1730
+ this.threadId = threadId;
1731
+ this.networkId = networkId;
1732
+ }
1733
+ /**
1734
+ * Retrieves the memory thread details
1735
+ * @returns Promise containing thread details including title and metadata
1736
+ */
1737
+ get() {
1738
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1739
+ }
1740
+ /**
1741
+ * Updates the memory thread properties
1742
+ * @param params - Update parameters including title and metadata
1743
+ * @returns Promise containing updated thread details
1744
+ */
1745
+ update(params) {
1746
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1747
+ method: "PATCH",
1748
+ body: params
1749
+ });
1750
+ }
1751
+ /**
1752
+ * Deletes the memory thread
1753
+ * @returns Promise containing deletion result
1754
+ */
1755
+ delete() {
1756
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1757
+ method: "DELETE"
1758
+ });
1759
+ }
1760
+ /**
1761
+ * Retrieves messages associated with the thread
1762
+ * @param params - Optional parameters including limit for number of messages to retrieve
1763
+ * @returns Promise containing thread messages and UI messages
1764
+ */
1765
+ getMessages(params) {
1766
+ const query = new URLSearchParams({
1767
+ networkId: this.networkId,
1768
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1769
+ });
1770
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1771
+ }
1772
+ /**
1773
+ * Deletes one or more messages from the thread
1774
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1775
+ * message object with id property, or array of message objects
1776
+ * @returns Promise containing deletion result
1777
+ */
1778
+ deleteMessages(messageIds) {
1779
+ const query = new URLSearchParams({
1780
+ networkId: this.networkId
1781
+ });
1782
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1783
+ method: "POST",
1784
+ body: { messageIds }
1785
+ });
1786
+ }
1787
+ };
1788
+
1640
1789
  // src/resources/vNextNetwork.ts
1641
1790
  var RECORD_SEPARATOR3 = "";
1642
1791
  var VNextNetwork = class extends BaseResource {
@@ -1659,7 +1808,10 @@ var VNextNetwork = class extends BaseResource {
1659
1808
  generate(params) {
1660
1809
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1661
1810
  method: "POST",
1662
- body: params
1811
+ body: {
1812
+ ...params,
1813
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1814
+ }
1663
1815
  });
1664
1816
  }
1665
1817
  /**
@@ -1670,7 +1822,10 @@ var VNextNetwork = class extends BaseResource {
1670
1822
  loop(params) {
1671
1823
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1672
1824
  method: "POST",
1673
- body: params
1825
+ body: {
1826
+ ...params,
1827
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1828
+ }
1674
1829
  });
1675
1830
  }
1676
1831
  async *streamProcessor(stream) {
@@ -1719,7 +1874,10 @@ var VNextNetwork = class extends BaseResource {
1719
1874
  async stream(params, onRecord) {
1720
1875
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1721
1876
  method: "POST",
1722
- body: params,
1877
+ body: {
1878
+ ...params,
1879
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1880
+ },
1723
1881
  stream: true
1724
1882
  });
1725
1883
  if (!response.ok) {
@@ -1744,7 +1902,10 @@ var VNextNetwork = class extends BaseResource {
1744
1902
  async loopStream(params, onRecord) {
1745
1903
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1746
1904
  method: "POST",
1747
- body: params,
1905
+ body: {
1906
+ ...params,
1907
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1908
+ },
1748
1909
  stream: true
1749
1910
  });
1750
1911
  if (!response.ok) {
@@ -1763,54 +1924,6 @@ var VNextNetwork = class extends BaseResource {
1763
1924
  }
1764
1925
  };
1765
1926
 
1766
- // src/resources/network-memory-thread.ts
1767
- var NetworkMemoryThread = class extends BaseResource {
1768
- constructor(options, threadId, networkId) {
1769
- super(options);
1770
- this.threadId = threadId;
1771
- this.networkId = networkId;
1772
- }
1773
- /**
1774
- * Retrieves the memory thread details
1775
- * @returns Promise containing thread details including title and metadata
1776
- */
1777
- get() {
1778
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1779
- }
1780
- /**
1781
- * Updates the memory thread properties
1782
- * @param params - Update parameters including title and metadata
1783
- * @returns Promise containing updated thread details
1784
- */
1785
- update(params) {
1786
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1787
- method: "PATCH",
1788
- body: params
1789
- });
1790
- }
1791
- /**
1792
- * Deletes the memory thread
1793
- * @returns Promise containing deletion result
1794
- */
1795
- delete() {
1796
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1797
- method: "DELETE"
1798
- });
1799
- }
1800
- /**
1801
- * Retrieves messages associated with the thread
1802
- * @param params - Optional parameters including limit for number of messages to retrieve
1803
- * @returns Promise containing thread messages and UI messages
1804
- */
1805
- getMessages(params) {
1806
- const query = new URLSearchParams({
1807
- networkId: this.networkId,
1808
- ...params?.limit ? { limit: params.limit.toString() } : {}
1809
- });
1810
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1811
- }
1812
- };
1813
-
1814
1927
  // src/client.ts
1815
1928
  var MastraClient = class extends BaseResource {
1816
1929
  constructor(options) {
@@ -2205,6 +2318,128 @@ var MastraClient = class extends BaseResource {
2205
2318
  getA2A(agentId) {
2206
2319
  return new A2A(this.options, agentId);
2207
2320
  }
2321
+ /**
2322
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2323
+ * @param agentId - ID of the agent.
2324
+ * @param threadId - ID of the thread.
2325
+ * @param resourceId - Optional ID of the resource.
2326
+ * @returns Working memory for the specified thread or resource.
2327
+ */
2328
+ getWorkingMemory({
2329
+ agentId,
2330
+ threadId,
2331
+ resourceId
2332
+ }) {
2333
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2334
+ }
2335
+ /**
2336
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2337
+ * @param agentId - ID of the agent.
2338
+ * @param threadId - ID of the thread.
2339
+ * @param workingMemory - The new working memory content.
2340
+ * @param resourceId - Optional ID of the resource.
2341
+ */
2342
+ updateWorkingMemory({
2343
+ agentId,
2344
+ threadId,
2345
+ workingMemory,
2346
+ resourceId
2347
+ }) {
2348
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2349
+ method: "POST",
2350
+ body: {
2351
+ workingMemory,
2352
+ resourceId
2353
+ }
2354
+ });
2355
+ }
2356
+ /**
2357
+ * Retrieves all available scorers
2358
+ * @returns Promise containing list of available scorers
2359
+ */
2360
+ getScorers() {
2361
+ return this.request("/api/scores/scorers");
2362
+ }
2363
+ /**
2364
+ * Retrieves a scorer by ID
2365
+ * @param scorerId - ID of the scorer to retrieve
2366
+ * @returns Promise containing the scorer
2367
+ */
2368
+ getScorer(scorerId) {
2369
+ return this.request(`/api/scores/scorers/${scorerId}`);
2370
+ }
2371
+ getScoresByScorerId(params) {
2372
+ const { page, perPage, scorerId, entityId, entityType } = params;
2373
+ const searchParams = new URLSearchParams();
2374
+ if (entityId) {
2375
+ searchParams.set("entityId", entityId);
2376
+ }
2377
+ if (entityType) {
2378
+ searchParams.set("entityType", entityType);
2379
+ }
2380
+ if (page !== void 0) {
2381
+ searchParams.set("page", String(page));
2382
+ }
2383
+ if (perPage !== void 0) {
2384
+ searchParams.set("perPage", String(perPage));
2385
+ }
2386
+ const queryString = searchParams.toString();
2387
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2388
+ }
2389
+ /**
2390
+ * Retrieves scores by run ID
2391
+ * @param params - Parameters containing run ID and pagination options
2392
+ * @returns Promise containing scores and pagination info
2393
+ */
2394
+ getScoresByRunId(params) {
2395
+ const { runId, page, perPage } = params;
2396
+ const searchParams = new URLSearchParams();
2397
+ if (page !== void 0) {
2398
+ searchParams.set("page", String(page));
2399
+ }
2400
+ if (perPage !== void 0) {
2401
+ searchParams.set("perPage", String(perPage));
2402
+ }
2403
+ const queryString = searchParams.toString();
2404
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2405
+ }
2406
+ /**
2407
+ * Retrieves scores by entity ID and type
2408
+ * @param params - Parameters containing entity ID, type, and pagination options
2409
+ * @returns Promise containing scores and pagination info
2410
+ */
2411
+ getScoresByEntityId(params) {
2412
+ const { entityId, entityType, page, perPage } = params;
2413
+ const searchParams = new URLSearchParams();
2414
+ if (page !== void 0) {
2415
+ searchParams.set("page", String(page));
2416
+ }
2417
+ if (perPage !== void 0) {
2418
+ searchParams.set("perPage", String(perPage));
2419
+ }
2420
+ const queryString = searchParams.toString();
2421
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2422
+ }
2423
+ /**
2424
+ * Saves a score
2425
+ * @param params - Parameters containing the score data to save
2426
+ * @returns Promise containing the saved score
2427
+ */
2428
+ saveScore(params) {
2429
+ return this.request("/api/scores", {
2430
+ method: "POST",
2431
+ body: params
2432
+ });
2433
+ }
2434
+ /**
2435
+ * Retrieves model providers with available keys
2436
+ * @returns Promise containing model providers with available keys
2437
+ */
2438
+ getModelProviders() {
2439
+ return this.request(`/api/model-providers`);
2440
+ }
2208
2441
  };
2209
2442
 
2210
2443
  export { MastraClient };
2444
+ //# sourceMappingURL=index.js.map
2445
+ //# sourceMappingURL=index.js.map