@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
package/dist/index.cjs CHANGED
@@ -5,7 +5,8 @@ var rxjs = require('rxjs');
5
5
  var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
7
  var originalZodToJsonSchema = require('zod-to-json-schema');
8
- var tools = require('@mastra/core/tools');
8
+ var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
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 }; }
@@ -150,6 +151,12 @@ function generateUUID() {
150
151
  }
151
152
  function convertMessagesToMastraMessages(messages) {
152
153
  const result = [];
154
+ const toolCallsWithResults = /* @__PURE__ */ new Set();
155
+ for (const message of messages) {
156
+ if (message.role === "tool" && message.toolCallId) {
157
+ toolCallsWithResults.add(message.toolCallId);
158
+ }
159
+ }
153
160
  for (const message of messages) {
154
161
  if (message.role === "assistant") {
155
162
  const parts = message.content ? [{ type: "text", text: message.content }] : [];
@@ -166,15 +173,22 @@ function convertMessagesToMastraMessages(messages) {
166
173
  content: parts
167
174
  });
168
175
  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
- });
176
+ for (const toolCall of message.toolCalls) {
177
+ if (!toolCallsWithResults.has(toolCall.id)) {
178
+ result.push({
179
+ role: "tool",
180
+ content: [
181
+ {
182
+ type: "tool-result",
183
+ toolCallId: toolCall.id,
184
+ toolName: toolCall.function.name,
185
+ result: JSON.parse(toolCall.function.arguments)
186
+ // This is still wrong but matches test expectations
187
+ }
188
+ ]
189
+ });
190
+ }
191
+ }
178
192
  }
179
193
  } else if (message.role === "user") {
180
194
  result.push({
@@ -187,8 +201,9 @@ function convertMessagesToMastraMessages(messages) {
187
201
  content: [
188
202
  {
189
203
  type: "tool-result",
190
- toolCallId: message.toolCallId,
204
+ toolCallId: message.toolCallId || "unknown",
191
205
  toolName: "unknown",
206
+ // toolName is not available in tool messages from CopilotKit
192
207
  result: message.content
193
208
  }
194
209
  ]
@@ -209,7 +224,7 @@ function processClientTools(clientTools) {
209
224
  }
210
225
  return Object.fromEntries(
211
226
  Object.entries(clientTools).map(([key, value]) => {
212
- if (tools.isVercelTool(value)) {
227
+ if (isVercelTool.isVercelTool(value)) {
213
228
  return [
214
229
  key,
215
230
  {
@@ -252,12 +267,13 @@ var BaseResource = class {
252
267
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
253
268
  ...options,
254
269
  headers: {
255
- ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
270
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
256
271
  ...headers,
257
272
  ...options.headers
258
273
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
259
274
  // 'x-mastra-client-type': 'js',
260
275
  },
276
+ signal: this.options.abortSignal,
261
277
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
262
278
  });
263
279
  if (!response.ok) {
@@ -376,12 +392,19 @@ var Agent = class extends BaseResource {
376
392
  clientTools: processClientTools(params.clientTools)
377
393
  };
378
394
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
379
- const response = await this.request(`/api/agents/${this.agentId}/generate`, {
380
- method: "POST",
381
- body: processedParams
382
- });
395
+ const response = await this.request(
396
+ `/api/agents/${this.agentId}/generate`,
397
+ {
398
+ method: "POST",
399
+ body: processedParams
400
+ }
401
+ );
383
402
  if (response.finishReason === "tool-calls") {
384
- for (const toolCall of response.toolCalls) {
403
+ const toolCalls = response.toolCalls;
404
+ if (!toolCalls || !Array.isArray(toolCalls)) {
405
+ return response;
406
+ }
407
+ for (const toolCall of toolCalls) {
385
408
  const clientTool = params.clientTools?.[toolCall.toolName];
386
409
  if (clientTool && clientTool.execute) {
387
410
  const result = await clientTool.execute(
@@ -432,7 +455,7 @@ var Agent = class extends BaseResource {
432
455
  return Math.max(max, toolInvocation.step ?? 0);
433
456
  }, 0) ?? 0) : 0;
434
457
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
435
- id: crypto.randomUUID(),
458
+ id: uuid.v4(),
436
459
  createdAt: getCurrentDate(),
437
460
  role: "assistant",
438
461
  content: "",
@@ -477,7 +500,7 @@ var Agent = class extends BaseResource {
477
500
  // changes. This is why we need to add a revision id to ensure that the message
478
501
  // is updated with SWR (without it, the changes get stuck in SWR and are not
479
502
  // forwarded to rendering):
480
- revisionId: crypto.randomUUID()
503
+ revisionId: uuid.v4()
481
504
  };
482
505
  update({
483
506
  message: copiedMessage,
@@ -732,7 +755,12 @@ var Agent = class extends BaseResource {
732
755
  this.processChatResponse({
733
756
  stream: streamForProcessing,
734
757
  update: ({ message }) => {
735
- messages.push(message);
758
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
759
+ if (existingIndex !== -1) {
760
+ messages[existingIndex] = message;
761
+ } else {
762
+ messages.push(message);
763
+ }
736
764
  },
737
765
  onFinish: async ({ finishReason, message }) => {
738
766
  if (finishReason === "tool-calls") {
@@ -792,10 +820,12 @@ var Agent = class extends BaseResource {
792
820
  this.processStreamResponse(
793
821
  {
794
822
  ...processedParams,
795
- messages: [...messageArray, ...messages, lastMessage]
823
+ messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
796
824
  },
797
825
  writable
798
- );
826
+ ).catch((error) => {
827
+ console.error("Error processing stream response:", error);
828
+ });
799
829
  }
800
830
  }
801
831
  } else {
@@ -805,6 +835,8 @@ var Agent = class extends BaseResource {
805
835
  }
806
836
  },
807
837
  lastMessage: void 0
838
+ }).catch((error) => {
839
+ console.error("Error processing stream response:", error);
808
840
  });
809
841
  } catch (error) {
810
842
  console.error("Error processing stream response:", error);
@@ -849,6 +881,17 @@ var Agent = class extends BaseResource {
849
881
  liveEvals() {
850
882
  return this.request(`/api/agents/${this.agentId}/evals/live`);
851
883
  }
884
+ /**
885
+ * Updates the model for the agent
886
+ * @param params - Parameters for updating the model
887
+ * @returns Promise containing the updated model
888
+ */
889
+ updateModel(params) {
890
+ return this.request(`/api/agents/${this.agentId}/model`, {
891
+ method: "POST",
892
+ body: params
893
+ });
894
+ }
852
895
  };
853
896
  var Network = class extends BaseResource {
854
897
  constructor(options, networkId) {
@@ -953,6 +996,36 @@ var MemoryThread = class extends BaseResource {
953
996
  });
954
997
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
955
998
  }
999
+ /**
1000
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1001
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1002
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1003
+ */
1004
+ getMessagesPaginated({
1005
+ selectBy,
1006
+ ...rest
1007
+ }) {
1008
+ const query = new URLSearchParams({
1009
+ ...rest,
1010
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1011
+ });
1012
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1013
+ }
1014
+ /**
1015
+ * Deletes one or more messages from the thread
1016
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1017
+ * message object with id property, or array of message objects
1018
+ * @returns Promise containing deletion result
1019
+ */
1020
+ deleteMessages(messageIds) {
1021
+ const query = new URLSearchParams({
1022
+ agentId: this.agentId
1023
+ });
1024
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1025
+ method: "POST",
1026
+ body: { messageIds }
1027
+ });
1028
+ }
956
1029
  };
957
1030
 
958
1031
  // src/resources/vector.ts
@@ -1374,6 +1447,14 @@ var Workflow = class extends BaseResource {
1374
1447
  method: "POST"
1375
1448
  });
1376
1449
  }
1450
+ /**
1451
+ * Creates a new workflow run (alias for createRun)
1452
+ * @param params - Optional object containing the optional runId
1453
+ * @returns Promise containing the runId of the created run
1454
+ */
1455
+ createRunAsync(params) {
1456
+ return this.createRun(params);
1457
+ }
1377
1458
  /**
1378
1459
  * Starts a workflow run synchronously without waiting for the workflow to complete
1379
1460
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1449,6 +1530,7 @@ var Workflow = class extends BaseResource {
1449
1530
  if (!response.body) {
1450
1531
  throw new Error("Response body is null");
1451
1532
  }
1533
+ let failedChunk = void 0;
1452
1534
  const transformStream = new TransformStream({
1453
1535
  start() {
1454
1536
  },
@@ -1458,10 +1540,13 @@ var Workflow = class extends BaseResource {
1458
1540
  const chunks = decoded.split(RECORD_SEPARATOR2);
1459
1541
  for (const chunk2 of chunks) {
1460
1542
  if (chunk2) {
1543
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1461
1544
  try {
1462
- const parsedChunk = JSON.parse(chunk2);
1545
+ const parsedChunk = JSON.parse(newChunk);
1463
1546
  controller.enqueue(parsedChunk);
1464
- } catch {
1547
+ failedChunk = void 0;
1548
+ } catch (error) {
1549
+ failedChunk = newChunk;
1465
1550
  }
1466
1551
  }
1467
1552
  }
@@ -1546,22 +1631,38 @@ var A2A = class extends BaseResource {
1546
1631
  * @returns Promise containing the agent card information
1547
1632
  */
1548
1633
  async getCard() {
1549
- return this.request(`/.well-known/${this.agentId}/agent.json`);
1634
+ return this.request(`/.well-known/${this.agentId}/agent-card.json`);
1550
1635
  }
1551
1636
  /**
1552
- * Send a message to the agent and get a response
1637
+ * Send a message to the agent and gets a message or task response
1553
1638
  * @param params - Parameters for the task
1554
- * @returns Promise containing the task response
1639
+ * @returns Promise containing the response
1555
1640
  */
1556
1641
  async sendMessage(params) {
1557
1642
  const response = await this.request(`/a2a/${this.agentId}`, {
1558
1643
  method: "POST",
1559
1644
  body: {
1560
- method: "tasks/send",
1645
+ method: "message/send",
1646
+ params
1647
+ }
1648
+ });
1649
+ return response;
1650
+ }
1651
+ /**
1652
+ * Sends a message to an agent to initiate/continue a task and subscribes
1653
+ * the client to real-time updates for that task via Server-Sent Events (SSE).
1654
+ * @param params - Parameters for the task
1655
+ * @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
1656
+ */
1657
+ async sendStreamingMessage(params) {
1658
+ const response = await this.request(`/a2a/${this.agentId}`, {
1659
+ method: "POST",
1660
+ body: {
1661
+ method: "message/stream",
1561
1662
  params
1562
1663
  }
1563
1664
  });
1564
- return { task: response.result };
1665
+ return response;
1565
1666
  }
1566
1667
  /**
1567
1668
  * Get the status and result of a task
@@ -1576,7 +1677,7 @@ var A2A = class extends BaseResource {
1576
1677
  params
1577
1678
  }
1578
1679
  });
1579
- return response.result;
1680
+ return response;
1580
1681
  }
1581
1682
  /**
1582
1683
  * Cancel a running task
@@ -1592,21 +1693,6 @@ var A2A = class extends BaseResource {
1592
1693
  }
1593
1694
  });
1594
1695
  }
1595
- /**
1596
- * Send a message and subscribe to streaming updates (not fully implemented)
1597
- * @param params - Parameters for the task
1598
- * @returns Promise containing the task response
1599
- */
1600
- async sendAndSubscribe(params) {
1601
- return this.request(`/a2a/${this.agentId}`, {
1602
- method: "POST",
1603
- body: {
1604
- method: "tasks/sendSubscribe",
1605
- params
1606
- },
1607
- stream: true
1608
- });
1609
- }
1610
1696
  };
1611
1697
 
1612
1698
  // src/resources/mcp-tool.ts
@@ -1643,6 +1729,69 @@ var MCPTool = class extends BaseResource {
1643
1729
  }
1644
1730
  };
1645
1731
 
1732
+ // src/resources/network-memory-thread.ts
1733
+ var NetworkMemoryThread = class extends BaseResource {
1734
+ constructor(options, threadId, networkId) {
1735
+ super(options);
1736
+ this.threadId = threadId;
1737
+ this.networkId = networkId;
1738
+ }
1739
+ /**
1740
+ * Retrieves the memory thread details
1741
+ * @returns Promise containing thread details including title and metadata
1742
+ */
1743
+ get() {
1744
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1745
+ }
1746
+ /**
1747
+ * Updates the memory thread properties
1748
+ * @param params - Update parameters including title and metadata
1749
+ * @returns Promise containing updated thread details
1750
+ */
1751
+ update(params) {
1752
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1753
+ method: "PATCH",
1754
+ body: params
1755
+ });
1756
+ }
1757
+ /**
1758
+ * Deletes the memory thread
1759
+ * @returns Promise containing deletion result
1760
+ */
1761
+ delete() {
1762
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1763
+ method: "DELETE"
1764
+ });
1765
+ }
1766
+ /**
1767
+ * Retrieves messages associated with the thread
1768
+ * @param params - Optional parameters including limit for number of messages to retrieve
1769
+ * @returns Promise containing thread messages and UI messages
1770
+ */
1771
+ getMessages(params) {
1772
+ const query = new URLSearchParams({
1773
+ networkId: this.networkId,
1774
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1775
+ });
1776
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1777
+ }
1778
+ /**
1779
+ * Deletes one or more messages from the thread
1780
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1781
+ * message object with id property, or array of message objects
1782
+ * @returns Promise containing deletion result
1783
+ */
1784
+ deleteMessages(messageIds) {
1785
+ const query = new URLSearchParams({
1786
+ networkId: this.networkId
1787
+ });
1788
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1789
+ method: "POST",
1790
+ body: { messageIds }
1791
+ });
1792
+ }
1793
+ };
1794
+
1646
1795
  // src/resources/vNextNetwork.ts
1647
1796
  var RECORD_SEPARATOR3 = "";
1648
1797
  var VNextNetwork = class extends BaseResource {
@@ -1665,7 +1814,10 @@ var VNextNetwork = class extends BaseResource {
1665
1814
  generate(params) {
1666
1815
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1667
1816
  method: "POST",
1668
- body: params
1817
+ body: {
1818
+ ...params,
1819
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1820
+ }
1669
1821
  });
1670
1822
  }
1671
1823
  /**
@@ -1676,7 +1828,10 @@ var VNextNetwork = class extends BaseResource {
1676
1828
  loop(params) {
1677
1829
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1678
1830
  method: "POST",
1679
- body: params
1831
+ body: {
1832
+ ...params,
1833
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1834
+ }
1680
1835
  });
1681
1836
  }
1682
1837
  async *streamProcessor(stream) {
@@ -1725,7 +1880,10 @@ var VNextNetwork = class extends BaseResource {
1725
1880
  async stream(params, onRecord) {
1726
1881
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1727
1882
  method: "POST",
1728
- body: params,
1883
+ body: {
1884
+ ...params,
1885
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1886
+ },
1729
1887
  stream: true
1730
1888
  });
1731
1889
  if (!response.ok) {
@@ -1750,7 +1908,10 @@ var VNextNetwork = class extends BaseResource {
1750
1908
  async loopStream(params, onRecord) {
1751
1909
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1752
1910
  method: "POST",
1753
- body: params,
1911
+ body: {
1912
+ ...params,
1913
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1914
+ },
1754
1915
  stream: true
1755
1916
  });
1756
1917
  if (!response.ok) {
@@ -1769,54 +1930,6 @@ var VNextNetwork = class extends BaseResource {
1769
1930
  }
1770
1931
  };
1771
1932
 
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
1933
  // src/client.ts
1821
1934
  var MastraClient = class extends BaseResource {
1822
1935
  constructor(options) {
@@ -2211,6 +2324,128 @@ var MastraClient = class extends BaseResource {
2211
2324
  getA2A(agentId) {
2212
2325
  return new A2A(this.options, agentId);
2213
2326
  }
2327
+ /**
2328
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2329
+ * @param agentId - ID of the agent.
2330
+ * @param threadId - ID of the thread.
2331
+ * @param resourceId - Optional ID of the resource.
2332
+ * @returns Working memory for the specified thread or resource.
2333
+ */
2334
+ getWorkingMemory({
2335
+ agentId,
2336
+ threadId,
2337
+ resourceId
2338
+ }) {
2339
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2340
+ }
2341
+ /**
2342
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2343
+ * @param agentId - ID of the agent.
2344
+ * @param threadId - ID of the thread.
2345
+ * @param workingMemory - The new working memory content.
2346
+ * @param resourceId - Optional ID of the resource.
2347
+ */
2348
+ updateWorkingMemory({
2349
+ agentId,
2350
+ threadId,
2351
+ workingMemory,
2352
+ resourceId
2353
+ }) {
2354
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2355
+ method: "POST",
2356
+ body: {
2357
+ workingMemory,
2358
+ resourceId
2359
+ }
2360
+ });
2361
+ }
2362
+ /**
2363
+ * Retrieves all available scorers
2364
+ * @returns Promise containing list of available scorers
2365
+ */
2366
+ getScorers() {
2367
+ return this.request("/api/scores/scorers");
2368
+ }
2369
+ /**
2370
+ * Retrieves a scorer by ID
2371
+ * @param scorerId - ID of the scorer to retrieve
2372
+ * @returns Promise containing the scorer
2373
+ */
2374
+ getScorer(scorerId) {
2375
+ return this.request(`/api/scores/scorers/${scorerId}`);
2376
+ }
2377
+ getScoresByScorerId(params) {
2378
+ const { page, perPage, scorerId, entityId, entityType } = params;
2379
+ const searchParams = new URLSearchParams();
2380
+ if (entityId) {
2381
+ searchParams.set("entityId", entityId);
2382
+ }
2383
+ if (entityType) {
2384
+ searchParams.set("entityType", entityType);
2385
+ }
2386
+ if (page !== void 0) {
2387
+ searchParams.set("page", String(page));
2388
+ }
2389
+ if (perPage !== void 0) {
2390
+ searchParams.set("perPage", String(perPage));
2391
+ }
2392
+ const queryString = searchParams.toString();
2393
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2394
+ }
2395
+ /**
2396
+ * Retrieves scores by run ID
2397
+ * @param params - Parameters containing run ID and pagination options
2398
+ * @returns Promise containing scores and pagination info
2399
+ */
2400
+ getScoresByRunId(params) {
2401
+ const { runId, page, perPage } = params;
2402
+ const searchParams = new URLSearchParams();
2403
+ if (page !== void 0) {
2404
+ searchParams.set("page", String(page));
2405
+ }
2406
+ if (perPage !== void 0) {
2407
+ searchParams.set("perPage", String(perPage));
2408
+ }
2409
+ const queryString = searchParams.toString();
2410
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2411
+ }
2412
+ /**
2413
+ * Retrieves scores by entity ID and type
2414
+ * @param params - Parameters containing entity ID, type, and pagination options
2415
+ * @returns Promise containing scores and pagination info
2416
+ */
2417
+ getScoresByEntityId(params) {
2418
+ const { entityId, entityType, page, perPage } = params;
2419
+ const searchParams = new URLSearchParams();
2420
+ if (page !== void 0) {
2421
+ searchParams.set("page", String(page));
2422
+ }
2423
+ if (perPage !== void 0) {
2424
+ searchParams.set("perPage", String(perPage));
2425
+ }
2426
+ const queryString = searchParams.toString();
2427
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2428
+ }
2429
+ /**
2430
+ * Saves a score
2431
+ * @param params - Parameters containing the score data to save
2432
+ * @returns Promise containing the saved score
2433
+ */
2434
+ saveScore(params) {
2435
+ return this.request("/api/scores", {
2436
+ method: "POST",
2437
+ body: params
2438
+ });
2439
+ }
2440
+ /**
2441
+ * Retrieves model providers with available keys
2442
+ * @returns Promise containing model providers with available keys
2443
+ */
2444
+ getModelProviders() {
2445
+ return this.request(`/api/model-providers`);
2446
+ }
2214
2447
  };
2215
2448
 
2216
2449
  exports.MastraClient = MastraClient;
2450
+ //# sourceMappingURL=index.cjs.map
2451
+ //# sourceMappingURL=index.cjs.map