@mastra/client-js 0.0.0-custom-instrumentation-20250708222033 → 0.0.0-declaration-maps-20250729202623

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 (68) hide show
  1. package/.turbo/turbo-build.log +8 -10
  2. package/CHANGELOG.md +292 -2
  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 +265 -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 +268 -67
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -1165
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +267 -66
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +44 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +112 -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/package.json +6 -5
  51. package/src/client.ts +145 -2
  52. package/src/example.ts +45 -17
  53. package/src/index.test.ts +402 -6
  54. package/src/index.ts +1 -0
  55. package/src/resources/agent.ts +46 -24
  56. package/src/resources/base.ts +5 -1
  57. package/src/resources/memory-thread.test.ts +285 -0
  58. package/src/resources/memory-thread.ts +36 -0
  59. package/src/resources/network-memory-thread.test.ts +269 -0
  60. package/src/resources/network-memory-thread.ts +18 -0
  61. package/src/resources/network.ts +4 -3
  62. package/src/resources/vNextNetwork.ts +22 -5
  63. package/src/resources/workflow.ts +17 -3
  64. package/src/types.ts +83 -7
  65. package/src/utils/process-client-tools.ts +1 -1
  66. package/src/v2-messages.test.ts +180 -0
  67. package/tsconfig.build.json +9 -0
  68. package/dist/index.d.cts +0 -1165
@@ -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
@@ -246,7 +247,7 @@ var BaseResource = class {
246
247
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
247
248
  ...options,
248
249
  headers: {
249
- ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
250
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
250
251
  ...headers,
251
252
  ...options.headers
252
253
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
@@ -371,12 +372,19 @@ var Agent = class extends BaseResource {
371
372
  clientTools: processClientTools(params.clientTools)
372
373
  };
373
374
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
374
- const response = await this.request(`/api/agents/${this.agentId}/generate`, {
375
- method: "POST",
376
- body: processedParams
377
- });
375
+ const response = await this.request(
376
+ `/api/agents/${this.agentId}/generate`,
377
+ {
378
+ method: "POST",
379
+ body: processedParams
380
+ }
381
+ );
378
382
  if (response.finishReason === "tool-calls") {
379
- for (const toolCall of response.toolCalls) {
383
+ const toolCalls = response.toolCalls;
384
+ if (!toolCalls || !Array.isArray(toolCalls)) {
385
+ return response;
386
+ }
387
+ for (const toolCall of toolCalls) {
380
388
  const clientTool = params.clientTools?.[toolCall.toolName];
381
389
  if (clientTool && clientTool.execute) {
382
390
  const result = await clientTool.execute(
@@ -427,7 +435,7 @@ var Agent = class extends BaseResource {
427
435
  return Math.max(max, toolInvocation.step ?? 0);
428
436
  }, 0) ?? 0) : 0;
429
437
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
430
- id: crypto.randomUUID(),
438
+ id: v4(),
431
439
  createdAt: getCurrentDate(),
432
440
  role: "assistant",
433
441
  content: "",
@@ -472,7 +480,7 @@ var Agent = class extends BaseResource {
472
480
  // changes. This is why we need to add a revision id to ensure that the message
473
481
  // is updated with SWR (without it, the changes get stuck in SWR and are not
474
482
  // forwarded to rendering):
475
- revisionId: crypto.randomUUID()
483
+ revisionId: v4()
476
484
  };
477
485
  update({
478
486
  message: copiedMessage,
@@ -727,7 +735,12 @@ var Agent = class extends BaseResource {
727
735
  this.processChatResponse({
728
736
  stream: streamForProcessing,
729
737
  update: ({ message }) => {
730
- messages.push(message);
738
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
739
+ if (existingIndex !== -1) {
740
+ messages[existingIndex] = message;
741
+ } else {
742
+ messages.push(message);
743
+ }
731
744
  },
732
745
  onFinish: async ({ finishReason, message }) => {
733
746
  if (finishReason === "tool-calls") {
@@ -787,10 +800,12 @@ var Agent = class extends BaseResource {
787
800
  this.processStreamResponse(
788
801
  {
789
802
  ...processedParams,
790
- messages: [...messageArray, ...messages, lastMessage]
803
+ messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
791
804
  },
792
805
  writable
793
- );
806
+ ).catch((error) => {
807
+ console.error("Error processing stream response:", error);
808
+ });
794
809
  }
795
810
  }
796
811
  } else {
@@ -800,6 +815,8 @@ var Agent = class extends BaseResource {
800
815
  }
801
816
  },
802
817
  lastMessage: void 0
818
+ }).catch((error) => {
819
+ console.error("Error processing stream response:", error);
803
820
  });
804
821
  } catch (error) {
805
822
  console.error("Error processing stream response:", error);
@@ -948,6 +965,36 @@ var MemoryThread = class extends BaseResource {
948
965
  });
949
966
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
950
967
  }
968
+ /**
969
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
970
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
971
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
972
+ */
973
+ getMessagesPaginated({
974
+ selectBy,
975
+ ...rest
976
+ }) {
977
+ const query = new URLSearchParams({
978
+ ...rest,
979
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
980
+ });
981
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
982
+ }
983
+ /**
984
+ * Deletes one or more messages from the thread
985
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
986
+ * message object with id property, or array of message objects
987
+ * @returns Promise containing deletion result
988
+ */
989
+ deleteMessages(messageIds) {
990
+ const query = new URLSearchParams({
991
+ agentId: this.agentId
992
+ });
993
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
994
+ method: "POST",
995
+ body: { messageIds }
996
+ });
997
+ }
951
998
  };
952
999
 
953
1000
  // src/resources/vector.ts
@@ -1369,6 +1416,14 @@ var Workflow = class extends BaseResource {
1369
1416
  method: "POST"
1370
1417
  });
1371
1418
  }
1419
+ /**
1420
+ * Creates a new workflow run (alias for createRun)
1421
+ * @param params - Optional object containing the optional runId
1422
+ * @returns Promise containing the runId of the created run
1423
+ */
1424
+ createRunAsync(params) {
1425
+ return this.createRun(params);
1426
+ }
1372
1427
  /**
1373
1428
  * Starts a workflow run synchronously without waiting for the workflow to complete
1374
1429
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1444,6 +1499,7 @@ var Workflow = class extends BaseResource {
1444
1499
  if (!response.body) {
1445
1500
  throw new Error("Response body is null");
1446
1501
  }
1502
+ let failedChunk = void 0;
1447
1503
  const transformStream = new TransformStream({
1448
1504
  start() {
1449
1505
  },
@@ -1453,10 +1509,13 @@ var Workflow = class extends BaseResource {
1453
1509
  const chunks = decoded.split(RECORD_SEPARATOR2);
1454
1510
  for (const chunk2 of chunks) {
1455
1511
  if (chunk2) {
1512
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1456
1513
  try {
1457
- const parsedChunk = JSON.parse(chunk2);
1514
+ const parsedChunk = JSON.parse(newChunk);
1458
1515
  controller.enqueue(parsedChunk);
1459
- } catch {
1516
+ failedChunk = void 0;
1517
+ } catch (error) {
1518
+ failedChunk = newChunk;
1460
1519
  }
1461
1520
  }
1462
1521
  }
@@ -1638,6 +1697,69 @@ var MCPTool = class extends BaseResource {
1638
1697
  }
1639
1698
  };
1640
1699
 
1700
+ // src/resources/network-memory-thread.ts
1701
+ var NetworkMemoryThread = class extends BaseResource {
1702
+ constructor(options, threadId, networkId) {
1703
+ super(options);
1704
+ this.threadId = threadId;
1705
+ this.networkId = networkId;
1706
+ }
1707
+ /**
1708
+ * Retrieves the memory thread details
1709
+ * @returns Promise containing thread details including title and metadata
1710
+ */
1711
+ get() {
1712
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1713
+ }
1714
+ /**
1715
+ * Updates the memory thread properties
1716
+ * @param params - Update parameters including title and metadata
1717
+ * @returns Promise containing updated thread details
1718
+ */
1719
+ update(params) {
1720
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1721
+ method: "PATCH",
1722
+ body: params
1723
+ });
1724
+ }
1725
+ /**
1726
+ * Deletes the memory thread
1727
+ * @returns Promise containing deletion result
1728
+ */
1729
+ delete() {
1730
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1731
+ method: "DELETE"
1732
+ });
1733
+ }
1734
+ /**
1735
+ * Retrieves messages associated with the thread
1736
+ * @param params - Optional parameters including limit for number of messages to retrieve
1737
+ * @returns Promise containing thread messages and UI messages
1738
+ */
1739
+ getMessages(params) {
1740
+ const query = new URLSearchParams({
1741
+ networkId: this.networkId,
1742
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1743
+ });
1744
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1745
+ }
1746
+ /**
1747
+ * Deletes one or more messages from the thread
1748
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1749
+ * message object with id property, or array of message objects
1750
+ * @returns Promise containing deletion result
1751
+ */
1752
+ deleteMessages(messageIds) {
1753
+ const query = new URLSearchParams({
1754
+ networkId: this.networkId
1755
+ });
1756
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1757
+ method: "POST",
1758
+ body: { messageIds }
1759
+ });
1760
+ }
1761
+ };
1762
+
1641
1763
  // src/resources/vNextNetwork.ts
1642
1764
  var RECORD_SEPARATOR3 = "";
1643
1765
  var VNextNetwork = class extends BaseResource {
@@ -1660,7 +1782,10 @@ var VNextNetwork = class extends BaseResource {
1660
1782
  generate(params) {
1661
1783
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1662
1784
  method: "POST",
1663
- body: params
1785
+ body: {
1786
+ ...params,
1787
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1788
+ }
1664
1789
  });
1665
1790
  }
1666
1791
  /**
@@ -1671,7 +1796,10 @@ var VNextNetwork = class extends BaseResource {
1671
1796
  loop(params) {
1672
1797
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1673
1798
  method: "POST",
1674
- body: params
1799
+ body: {
1800
+ ...params,
1801
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1802
+ }
1675
1803
  });
1676
1804
  }
1677
1805
  async *streamProcessor(stream) {
@@ -1720,7 +1848,10 @@ var VNextNetwork = class extends BaseResource {
1720
1848
  async stream(params, onRecord) {
1721
1849
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1722
1850
  method: "POST",
1723
- body: params,
1851
+ body: {
1852
+ ...params,
1853
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1854
+ },
1724
1855
  stream: true
1725
1856
  });
1726
1857
  if (!response.ok) {
@@ -1745,7 +1876,10 @@ var VNextNetwork = class extends BaseResource {
1745
1876
  async loopStream(params, onRecord) {
1746
1877
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1747
1878
  method: "POST",
1748
- body: params,
1879
+ body: {
1880
+ ...params,
1881
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1882
+ },
1749
1883
  stream: true
1750
1884
  });
1751
1885
  if (!response.ok) {
@@ -1764,54 +1898,6 @@ var VNextNetwork = class extends BaseResource {
1764
1898
  }
1765
1899
  };
1766
1900
 
1767
- // src/resources/network-memory-thread.ts
1768
- var NetworkMemoryThread = class extends BaseResource {
1769
- constructor(options, threadId, networkId) {
1770
- super(options);
1771
- this.threadId = threadId;
1772
- this.networkId = networkId;
1773
- }
1774
- /**
1775
- * Retrieves the memory thread details
1776
- * @returns Promise containing thread details including title and metadata
1777
- */
1778
- get() {
1779
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1780
- }
1781
- /**
1782
- * Updates the memory thread properties
1783
- * @param params - Update parameters including title and metadata
1784
- * @returns Promise containing updated thread details
1785
- */
1786
- update(params) {
1787
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1788
- method: "PATCH",
1789
- body: params
1790
- });
1791
- }
1792
- /**
1793
- * Deletes the memory thread
1794
- * @returns Promise containing deletion result
1795
- */
1796
- delete() {
1797
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1798
- method: "DELETE"
1799
- });
1800
- }
1801
- /**
1802
- * Retrieves messages associated with the thread
1803
- * @param params - Optional parameters including limit for number of messages to retrieve
1804
- * @returns Promise containing thread messages and UI messages
1805
- */
1806
- getMessages(params) {
1807
- const query = new URLSearchParams({
1808
- networkId: this.networkId,
1809
- ...params?.limit ? { limit: params.limit.toString() } : {}
1810
- });
1811
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1812
- }
1813
- };
1814
-
1815
1901
  // src/client.ts
1816
1902
  var MastraClient = class extends BaseResource {
1817
1903
  constructor(options) {
@@ -2206,6 +2292,121 @@ var MastraClient = class extends BaseResource {
2206
2292
  getA2A(agentId) {
2207
2293
  return new A2A(this.options, agentId);
2208
2294
  }
2295
+ /**
2296
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2297
+ * @param agentId - ID of the agent.
2298
+ * @param threadId - ID of the thread.
2299
+ * @param resourceId - Optional ID of the resource.
2300
+ * @returns Working memory for the specified thread or resource.
2301
+ */
2302
+ getWorkingMemory({
2303
+ agentId,
2304
+ threadId,
2305
+ resourceId
2306
+ }) {
2307
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2308
+ }
2309
+ /**
2310
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2311
+ * @param agentId - ID of the agent.
2312
+ * @param threadId - ID of the thread.
2313
+ * @param workingMemory - The new working memory content.
2314
+ * @param resourceId - Optional ID of the resource.
2315
+ */
2316
+ updateWorkingMemory({
2317
+ agentId,
2318
+ threadId,
2319
+ workingMemory,
2320
+ resourceId
2321
+ }) {
2322
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2323
+ method: "POST",
2324
+ body: {
2325
+ workingMemory,
2326
+ resourceId
2327
+ }
2328
+ });
2329
+ }
2330
+ /**
2331
+ * Retrieves all available scorers
2332
+ * @returns Promise containing list of available scorers
2333
+ */
2334
+ getScorers() {
2335
+ return this.request("/api/scores/scorers");
2336
+ }
2337
+ /**
2338
+ * Retrieves a scorer by ID
2339
+ * @param scorerId - ID of the scorer to retrieve
2340
+ * @returns Promise containing the scorer
2341
+ */
2342
+ getScorer(scorerId) {
2343
+ return this.request(`/api/scores/scorers/${scorerId}`);
2344
+ }
2345
+ getScoresByScorerId(params) {
2346
+ const { page, perPage, scorerId, entityId, entityType } = params;
2347
+ const searchParams = new URLSearchParams();
2348
+ if (entityId) {
2349
+ searchParams.set("entityId", entityId);
2350
+ }
2351
+ if (entityType) {
2352
+ searchParams.set("entityType", entityType);
2353
+ }
2354
+ if (page !== void 0) {
2355
+ searchParams.set("page", String(page));
2356
+ }
2357
+ if (perPage !== void 0) {
2358
+ searchParams.set("perPage", String(perPage));
2359
+ }
2360
+ const queryString = searchParams.toString();
2361
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2362
+ }
2363
+ /**
2364
+ * Retrieves scores by run ID
2365
+ * @param params - Parameters containing run ID and pagination options
2366
+ * @returns Promise containing scores and pagination info
2367
+ */
2368
+ getScoresByRunId(params) {
2369
+ const { runId, page, perPage } = params;
2370
+ const searchParams = new URLSearchParams();
2371
+ if (page !== void 0) {
2372
+ searchParams.set("page", String(page));
2373
+ }
2374
+ if (perPage !== void 0) {
2375
+ searchParams.set("perPage", String(perPage));
2376
+ }
2377
+ const queryString = searchParams.toString();
2378
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2379
+ }
2380
+ /**
2381
+ * Retrieves scores by entity ID and type
2382
+ * @param params - Parameters containing entity ID, type, and pagination options
2383
+ * @returns Promise containing scores and pagination info
2384
+ */
2385
+ getScoresByEntityId(params) {
2386
+ const { entityId, entityType, page, perPage } = params;
2387
+ const searchParams = new URLSearchParams();
2388
+ if (page !== void 0) {
2389
+ searchParams.set("page", String(page));
2390
+ }
2391
+ if (perPage !== void 0) {
2392
+ searchParams.set("perPage", String(perPage));
2393
+ }
2394
+ const queryString = searchParams.toString();
2395
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2396
+ }
2397
+ /**
2398
+ * Saves a score
2399
+ * @param params - Parameters containing the score data to save
2400
+ * @returns Promise containing the saved score
2401
+ */
2402
+ saveScore(params) {
2403
+ return this.request("/api/scores", {
2404
+ method: "POST",
2405
+ body: params
2406
+ });
2407
+ }
2209
2408
  };
2210
2409
 
2211
2410
  export { MastraClient };
2411
+ //# sourceMappingURL=index.js.map
2412
+ //# sourceMappingURL=index.js.map