@mastra/client-js 0.0.0-support-d1-client-20250701191943 → 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806162745

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 (77) hide show
  1. package/.turbo/turbo-build.log +9 -10
  2. package/CHANGELOG.md +538 -2
  3. package/LICENSE.md +11 -42
  4. package/README.md +1 -0
  5. package/dist/adapters/agui.d.ts +23 -0
  6. package/dist/adapters/agui.d.ts.map +1 -0
  7. package/dist/client.d.ts +265 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/example.d.ts +2 -0
  10. package/dist/example.d.ts.map +1 -0
  11. package/dist/index.cjs +306 -79
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +4 -1152
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +305 -78
  16. package/dist/index.js.map +1 -0
  17. package/dist/resources/a2a.d.ts +44 -0
  18. package/dist/resources/a2a.d.ts.map +1 -0
  19. package/dist/resources/agent.d.ts +112 -0
  20. package/dist/resources/agent.d.ts.map +1 -0
  21. package/dist/resources/base.d.ts +13 -0
  22. package/dist/resources/base.d.ts.map +1 -0
  23. package/dist/resources/index.d.ts +11 -0
  24. package/dist/resources/index.d.ts.map +1 -0
  25. package/dist/resources/legacy-workflow.d.ts +87 -0
  26. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  27. package/dist/resources/mcp-tool.d.ts +27 -0
  28. package/dist/resources/mcp-tool.d.ts.map +1 -0
  29. package/dist/resources/memory-thread.d.ts +53 -0
  30. package/dist/resources/memory-thread.d.ts.map +1 -0
  31. package/dist/resources/network-memory-thread.d.ts +47 -0
  32. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  33. package/dist/resources/network.d.ts +30 -0
  34. package/dist/resources/network.d.ts.map +1 -0
  35. package/dist/resources/tool.d.ts +23 -0
  36. package/dist/resources/tool.d.ts.map +1 -0
  37. package/dist/resources/vNextNetwork.d.ts +42 -0
  38. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  39. package/dist/resources/vector.d.ts +48 -0
  40. package/dist/resources/vector.d.ts.map +1 -0
  41. package/dist/resources/workflow.d.ts +154 -0
  42. package/dist/resources/workflow.d.ts.map +1 -0
  43. package/dist/types.d.ts +422 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/utils/index.d.ts +3 -0
  46. package/dist/utils/index.d.ts.map +1 -0
  47. package/dist/utils/process-client-tools.d.ts +3 -0
  48. package/dist/utils/process-client-tools.d.ts.map +1 -0
  49. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  50. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  51. package/integration-tests/agui-adapter.test.ts +122 -0
  52. package/integration-tests/package.json +18 -0
  53. package/integration-tests/src/mastra/index.ts +35 -0
  54. package/integration-tests/vitest.config.ts +9 -0
  55. package/package.json +15 -9
  56. package/src/adapters/agui.test.ts +145 -3
  57. package/src/adapters/agui.ts +29 -11
  58. package/src/client.ts +145 -2
  59. package/src/example.ts +45 -17
  60. package/src/index.test.ts +402 -6
  61. package/src/index.ts +1 -0
  62. package/src/resources/agent.ts +46 -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 +31 -5
  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/dist/index.d.cts +0 -1152
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);
@@ -953,6 +985,36 @@ var MemoryThread = class extends BaseResource {
953
985
  });
954
986
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
955
987
  }
988
+ /**
989
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
990
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
991
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
992
+ */
993
+ getMessagesPaginated({
994
+ selectBy,
995
+ ...rest
996
+ }) {
997
+ const query = new URLSearchParams({
998
+ ...rest,
999
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1000
+ });
1001
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1002
+ }
1003
+ /**
1004
+ * Deletes one or more messages from the thread
1005
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1006
+ * message object with id property, or array of message objects
1007
+ * @returns Promise containing deletion result
1008
+ */
1009
+ deleteMessages(messageIds) {
1010
+ const query = new URLSearchParams({
1011
+ agentId: this.agentId
1012
+ });
1013
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1014
+ method: "POST",
1015
+ body: { messageIds }
1016
+ });
1017
+ }
956
1018
  };
957
1019
 
958
1020
  // src/resources/vector.ts
@@ -1308,10 +1370,10 @@ var Workflow = class extends BaseResource {
1308
1370
  if (params?.toDate) {
1309
1371
  searchParams.set("toDate", params.toDate.toISOString());
1310
1372
  }
1311
- if (params?.limit) {
1373
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1312
1374
  searchParams.set("limit", String(params.limit));
1313
1375
  }
1314
- if (params?.offset) {
1376
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1315
1377
  searchParams.set("offset", String(params.offset));
1316
1378
  }
1317
1379
  if (params?.resourceId) {
@@ -1349,6 +1411,17 @@ var Workflow = class extends BaseResource {
1349
1411
  method: "POST"
1350
1412
  });
1351
1413
  }
1414
+ /**
1415
+ * Sends an event to a specific workflow run by its ID
1416
+ * @param params - Object containing the runId, event and data
1417
+ * @returns Promise containing a success message
1418
+ */
1419
+ sendRunEvent(params) {
1420
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1421
+ method: "POST",
1422
+ body: { event: params.event, data: params.data }
1423
+ });
1424
+ }
1352
1425
  /**
1353
1426
  * Creates a new workflow run
1354
1427
  * @param params - Optional object containing the optional runId
@@ -1363,6 +1436,14 @@ var Workflow = class extends BaseResource {
1363
1436
  method: "POST"
1364
1437
  });
1365
1438
  }
1439
+ /**
1440
+ * Creates a new workflow run (alias for createRun)
1441
+ * @param params - Optional object containing the optional runId
1442
+ * @returns Promise containing the runId of the created run
1443
+ */
1444
+ createRunAsync(params) {
1445
+ return this.createRun(params);
1446
+ }
1366
1447
  /**
1367
1448
  * Starts a workflow run synchronously without waiting for the workflow to complete
1368
1449
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1438,6 +1519,7 @@ var Workflow = class extends BaseResource {
1438
1519
  if (!response.body) {
1439
1520
  throw new Error("Response body is null");
1440
1521
  }
1522
+ let failedChunk = void 0;
1441
1523
  const transformStream = new TransformStream({
1442
1524
  start() {
1443
1525
  },
@@ -1447,10 +1529,13 @@ var Workflow = class extends BaseResource {
1447
1529
  const chunks = decoded.split(RECORD_SEPARATOR2);
1448
1530
  for (const chunk2 of chunks) {
1449
1531
  if (chunk2) {
1532
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1450
1533
  try {
1451
- const parsedChunk = JSON.parse(chunk2);
1534
+ const parsedChunk = JSON.parse(newChunk);
1452
1535
  controller.enqueue(parsedChunk);
1453
- } catch {
1536
+ failedChunk = void 0;
1537
+ } catch (error) {
1538
+ failedChunk = newChunk;
1454
1539
  }
1455
1540
  }
1456
1541
  }
@@ -1632,6 +1717,69 @@ var MCPTool = class extends BaseResource {
1632
1717
  }
1633
1718
  };
1634
1719
 
1720
+ // src/resources/network-memory-thread.ts
1721
+ var NetworkMemoryThread = class extends BaseResource {
1722
+ constructor(options, threadId, networkId) {
1723
+ super(options);
1724
+ this.threadId = threadId;
1725
+ this.networkId = networkId;
1726
+ }
1727
+ /**
1728
+ * Retrieves the memory thread details
1729
+ * @returns Promise containing thread details including title and metadata
1730
+ */
1731
+ get() {
1732
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1733
+ }
1734
+ /**
1735
+ * Updates the memory thread properties
1736
+ * @param params - Update parameters including title and metadata
1737
+ * @returns Promise containing updated thread details
1738
+ */
1739
+ update(params) {
1740
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1741
+ method: "PATCH",
1742
+ body: params
1743
+ });
1744
+ }
1745
+ /**
1746
+ * Deletes the memory thread
1747
+ * @returns Promise containing deletion result
1748
+ */
1749
+ delete() {
1750
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1751
+ method: "DELETE"
1752
+ });
1753
+ }
1754
+ /**
1755
+ * Retrieves messages associated with the thread
1756
+ * @param params - Optional parameters including limit for number of messages to retrieve
1757
+ * @returns Promise containing thread messages and UI messages
1758
+ */
1759
+ getMessages(params) {
1760
+ const query = new URLSearchParams({
1761
+ networkId: this.networkId,
1762
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1763
+ });
1764
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1765
+ }
1766
+ /**
1767
+ * Deletes one or more messages from the thread
1768
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1769
+ * message object with id property, or array of message objects
1770
+ * @returns Promise containing deletion result
1771
+ */
1772
+ deleteMessages(messageIds) {
1773
+ const query = new URLSearchParams({
1774
+ networkId: this.networkId
1775
+ });
1776
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1777
+ method: "POST",
1778
+ body: { messageIds }
1779
+ });
1780
+ }
1781
+ };
1782
+
1635
1783
  // src/resources/vNextNetwork.ts
1636
1784
  var RECORD_SEPARATOR3 = "";
1637
1785
  var VNextNetwork = class extends BaseResource {
@@ -1654,7 +1802,10 @@ var VNextNetwork = class extends BaseResource {
1654
1802
  generate(params) {
1655
1803
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1656
1804
  method: "POST",
1657
- body: params
1805
+ body: {
1806
+ ...params,
1807
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1808
+ }
1658
1809
  });
1659
1810
  }
1660
1811
  /**
@@ -1665,7 +1816,10 @@ var VNextNetwork = class extends BaseResource {
1665
1816
  loop(params) {
1666
1817
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1667
1818
  method: "POST",
1668
- body: params
1819
+ body: {
1820
+ ...params,
1821
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1822
+ }
1669
1823
  });
1670
1824
  }
1671
1825
  async *streamProcessor(stream) {
@@ -1714,7 +1868,10 @@ var VNextNetwork = class extends BaseResource {
1714
1868
  async stream(params, onRecord) {
1715
1869
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1716
1870
  method: "POST",
1717
- body: params,
1871
+ body: {
1872
+ ...params,
1873
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1874
+ },
1718
1875
  stream: true
1719
1876
  });
1720
1877
  if (!response.ok) {
@@ -1739,7 +1896,10 @@ var VNextNetwork = class extends BaseResource {
1739
1896
  async loopStream(params, onRecord) {
1740
1897
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1741
1898
  method: "POST",
1742
- body: params,
1899
+ body: {
1900
+ ...params,
1901
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1902
+ },
1743
1903
  stream: true
1744
1904
  });
1745
1905
  if (!response.ok) {
@@ -1758,54 +1918,6 @@ var VNextNetwork = class extends BaseResource {
1758
1918
  }
1759
1919
  };
1760
1920
 
1761
- // src/resources/network-memory-thread.ts
1762
- var NetworkMemoryThread = class extends BaseResource {
1763
- constructor(options, threadId, networkId) {
1764
- super(options);
1765
- this.threadId = threadId;
1766
- this.networkId = networkId;
1767
- }
1768
- /**
1769
- * Retrieves the memory thread details
1770
- * @returns Promise containing thread details including title and metadata
1771
- */
1772
- get() {
1773
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1774
- }
1775
- /**
1776
- * Updates the memory thread properties
1777
- * @param params - Update parameters including title and metadata
1778
- * @returns Promise containing updated thread details
1779
- */
1780
- update(params) {
1781
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1782
- method: "PATCH",
1783
- body: params
1784
- });
1785
- }
1786
- /**
1787
- * Deletes the memory thread
1788
- * @returns Promise containing deletion result
1789
- */
1790
- delete() {
1791
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1792
- method: "DELETE"
1793
- });
1794
- }
1795
- /**
1796
- * Retrieves messages associated with the thread
1797
- * @param params - Optional parameters including limit for number of messages to retrieve
1798
- * @returns Promise containing thread messages and UI messages
1799
- */
1800
- getMessages(params) {
1801
- const query = new URLSearchParams({
1802
- networkId: this.networkId,
1803
- ...params?.limit ? { limit: params.limit.toString() } : {}
1804
- });
1805
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1806
- }
1807
- };
1808
-
1809
1921
  // src/client.ts
1810
1922
  var MastraClient = class extends BaseResource {
1811
1923
  constructor(options) {
@@ -2200,6 +2312,121 @@ var MastraClient = class extends BaseResource {
2200
2312
  getA2A(agentId) {
2201
2313
  return new A2A(this.options, agentId);
2202
2314
  }
2315
+ /**
2316
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2317
+ * @param agentId - ID of the agent.
2318
+ * @param threadId - ID of the thread.
2319
+ * @param resourceId - Optional ID of the resource.
2320
+ * @returns Working memory for the specified thread or resource.
2321
+ */
2322
+ getWorkingMemory({
2323
+ agentId,
2324
+ threadId,
2325
+ resourceId
2326
+ }) {
2327
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2328
+ }
2329
+ /**
2330
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2331
+ * @param agentId - ID of the agent.
2332
+ * @param threadId - ID of the thread.
2333
+ * @param workingMemory - The new working memory content.
2334
+ * @param resourceId - Optional ID of the resource.
2335
+ */
2336
+ updateWorkingMemory({
2337
+ agentId,
2338
+ threadId,
2339
+ workingMemory,
2340
+ resourceId
2341
+ }) {
2342
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2343
+ method: "POST",
2344
+ body: {
2345
+ workingMemory,
2346
+ resourceId
2347
+ }
2348
+ });
2349
+ }
2350
+ /**
2351
+ * Retrieves all available scorers
2352
+ * @returns Promise containing list of available scorers
2353
+ */
2354
+ getScorers() {
2355
+ return this.request("/api/scores/scorers");
2356
+ }
2357
+ /**
2358
+ * Retrieves a scorer by ID
2359
+ * @param scorerId - ID of the scorer to retrieve
2360
+ * @returns Promise containing the scorer
2361
+ */
2362
+ getScorer(scorerId) {
2363
+ return this.request(`/api/scores/scorers/${scorerId}`);
2364
+ }
2365
+ getScoresByScorerId(params) {
2366
+ const { page, perPage, scorerId, entityId, entityType } = params;
2367
+ const searchParams = new URLSearchParams();
2368
+ if (entityId) {
2369
+ searchParams.set("entityId", entityId);
2370
+ }
2371
+ if (entityType) {
2372
+ searchParams.set("entityType", entityType);
2373
+ }
2374
+ if (page !== void 0) {
2375
+ searchParams.set("page", String(page));
2376
+ }
2377
+ if (perPage !== void 0) {
2378
+ searchParams.set("perPage", String(perPage));
2379
+ }
2380
+ const queryString = searchParams.toString();
2381
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2382
+ }
2383
+ /**
2384
+ * Retrieves scores by run ID
2385
+ * @param params - Parameters containing run ID and pagination options
2386
+ * @returns Promise containing scores and pagination info
2387
+ */
2388
+ getScoresByRunId(params) {
2389
+ const { runId, page, perPage } = params;
2390
+ const searchParams = new URLSearchParams();
2391
+ if (page !== void 0) {
2392
+ searchParams.set("page", String(page));
2393
+ }
2394
+ if (perPage !== void 0) {
2395
+ searchParams.set("perPage", String(perPage));
2396
+ }
2397
+ const queryString = searchParams.toString();
2398
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2399
+ }
2400
+ /**
2401
+ * Retrieves scores by entity ID and type
2402
+ * @param params - Parameters containing entity ID, type, and pagination options
2403
+ * @returns Promise containing scores and pagination info
2404
+ */
2405
+ getScoresByEntityId(params) {
2406
+ const { entityId, entityType, page, perPage } = params;
2407
+ const searchParams = new URLSearchParams();
2408
+ if (page !== void 0) {
2409
+ searchParams.set("page", String(page));
2410
+ }
2411
+ if (perPage !== void 0) {
2412
+ searchParams.set("perPage", String(perPage));
2413
+ }
2414
+ const queryString = searchParams.toString();
2415
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2416
+ }
2417
+ /**
2418
+ * Saves a score
2419
+ * @param params - Parameters containing the score data to save
2420
+ * @returns Promise containing the saved score
2421
+ */
2422
+ saveScore(params) {
2423
+ return this.request("/api/scores", {
2424
+ method: "POST",
2425
+ body: params
2426
+ });
2427
+ }
2203
2428
  };
2204
2429
 
2205
2430
  exports.MastraClient = MastraClient;
2431
+ //# sourceMappingURL=index.cjs.map
2432
+ //# sourceMappingURL=index.cjs.map