@mastra/client-js 0.0.0-fix-zod-to-json-schema-ref-strategy-20250910193441 → 0.0.0-fix-cloud-peer-deps-20250923194656

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 (41) hide show
  1. package/CHANGELOG.md +217 -4
  2. package/README.md +2 -6
  3. package/dist/client.d.ts +36 -16
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +373 -135
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +372 -136
  10. package/dist/index.js.map +1 -1
  11. package/dist/resources/agent-builder.d.ts +5 -6
  12. package/dist/resources/agent-builder.d.ts.map +1 -1
  13. package/dist/resources/agent.d.ts +48 -12
  14. package/dist/resources/agent.d.ts.map +1 -1
  15. package/dist/resources/index.d.ts +0 -1
  16. package/dist/resources/index.d.ts.map +1 -1
  17. package/dist/resources/legacy-workflow.d.ts +5 -2
  18. package/dist/resources/legacy-workflow.d.ts.map +1 -1
  19. package/dist/resources/mcp-tool.d.ts +2 -1
  20. package/dist/resources/mcp-tool.d.ts.map +1 -1
  21. package/dist/resources/observability.d.ts +10 -0
  22. package/dist/resources/observability.d.ts.map +1 -1
  23. package/dist/resources/tool.d.ts +2 -1
  24. package/dist/resources/tool.d.ts.map +1 -1
  25. package/dist/resources/vNextNetwork.d.ts +2 -1
  26. package/dist/resources/vNextNetwork.d.ts.map +1 -1
  27. package/dist/resources/vector.d.ts +5 -2
  28. package/dist/resources/vector.d.ts.map +1 -1
  29. package/dist/resources/workflow.d.ts +96 -11
  30. package/dist/resources/workflow.d.ts.map +1 -1
  31. package/dist/tools.d.ts +22 -0
  32. package/dist/tools.d.ts.map +1 -0
  33. package/dist/types.d.ts +50 -22
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils/index.d.ts +2 -0
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/process-mastra-stream.d.ts +5 -1
  38. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  39. package/package.json +5 -6
  40. package/dist/resources/network.d.ts +0 -30
  41. package/dist/resources/network.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -15,6 +15,20 @@ function parseClientRuntimeContext(runtimeContext) {
15
15
  }
16
16
  return void 0;
17
17
  }
18
+ function base64RuntimeContext(runtimeContext) {
19
+ if (runtimeContext) {
20
+ return btoa(JSON.stringify(runtimeContext));
21
+ }
22
+ return void 0;
23
+ }
24
+ function runtimeContextQueryString(runtimeContext) {
25
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
26
+ if (!runtimeContextParam) return "";
27
+ const searchParams = new URLSearchParams();
28
+ searchParams.set("runtimeContext", runtimeContextParam);
29
+ const queryString = searchParams.toString();
30
+ return queryString ? `?${queryString}` : "";
31
+ }
18
32
  function isZodType(value) {
19
33
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
20
34
  }
@@ -59,7 +73,7 @@ function processClientTools(clientTools) {
59
73
  }
60
74
 
61
75
  // src/utils/process-mastra-stream.ts
62
- async function processMastraStream({
76
+ async function sharedProcessMastraStream({
63
77
  stream,
64
78
  onChunk
65
79
  }) {
@@ -77,7 +91,7 @@ async function processMastraStream({
77
91
  if (line.startsWith("data: ")) {
78
92
  const data = line.slice(6);
79
93
  if (data === "[DONE]") {
80
- console.log("\u{1F3C1} Stream finished");
94
+ console.info("\u{1F3C1} Stream finished");
81
95
  return;
82
96
  }
83
97
  try {
@@ -93,6 +107,24 @@ async function processMastraStream({
93
107
  reader.releaseLock();
94
108
  }
95
109
  }
110
+ async function processMastraNetworkStream({
111
+ stream,
112
+ onChunk
113
+ }) {
114
+ return sharedProcessMastraStream({
115
+ stream,
116
+ onChunk
117
+ });
118
+ }
119
+ async function processMastraStream({
120
+ stream,
121
+ onChunk
122
+ }) {
123
+ return sharedProcessMastraStream({
124
+ stream,
125
+ onChunk
126
+ });
127
+ }
96
128
 
97
129
  // src/resources/base.ts
98
130
  var BaseResource = class {
@@ -181,7 +213,9 @@ async function executeToolCallAndRespond({
181
213
  resourceId,
182
214
  threadId,
183
215
  runtimeContext,
184
- tracingContext: { currentSpan: void 0 }
216
+ tracingContext: { currentSpan: void 0 },
217
+ suspend: async () => {
218
+ }
185
219
  },
186
220
  {
187
221
  messages: response.messages,
@@ -255,17 +289,21 @@ var AgentVoice = class extends BaseResource {
255
289
  }
256
290
  /**
257
291
  * Get available speakers for the agent's voice provider
292
+ * @param runtimeContext - Optional runtime context to pass as query parameter
293
+ * @param runtimeContext - Optional runtime context to pass as query parameter
258
294
  * @returns Promise containing list of available speakers
259
295
  */
260
- getSpeakers() {
261
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
296
+ getSpeakers(runtimeContext) {
297
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
262
298
  }
263
299
  /**
264
300
  * Get the listener configuration for the agent's voice provider
301
+ * @param runtimeContext - Optional runtime context to pass as query parameter
302
+ * @param runtimeContext - Optional runtime context to pass as query parameter
265
303
  * @returns Promise containing a check if the agent has listening capabilities
266
304
  */
267
- getListener() {
268
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
305
+ getListener(runtimeContext) {
306
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
269
307
  }
270
308
  };
271
309
  var Agent = class extends BaseResource {
@@ -277,14 +315,15 @@ var Agent = class extends BaseResource {
277
315
  voice;
278
316
  /**
279
317
  * Retrieves details about the agent
318
+ * @param runtimeContext - Optional runtime context to pass as query parameter
280
319
  * @returns Promise containing agent details including model and instructions
281
320
  */
282
- details() {
283
- return this.request(`/api/agents/${this.agentId}`);
321
+ details(runtimeContext) {
322
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
284
323
  }
285
324
  async generate(params) {
286
325
  console.warn(
287
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
326
+ "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
288
327
  );
289
328
  return this.generateLegacy(params);
290
329
  }
@@ -319,7 +358,9 @@ var Agent = class extends BaseResource {
319
358
  resourceId,
320
359
  threadId,
321
360
  runtimeContext,
322
- tracingContext: { currentSpan: void 0 }
361
+ tracingContext: { currentSpan: void 0 },
362
+ suspend: async () => {
363
+ }
323
364
  },
324
365
  {
325
366
  messages: response.messages,
@@ -353,7 +394,16 @@ var Agent = class extends BaseResource {
353
394
  }
354
395
  return response;
355
396
  }
356
- async generateVNext(params) {
397
+ async generateVNext(messagesOrParams, options) {
398
+ let params;
399
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
400
+ params = messagesOrParams;
401
+ } else {
402
+ params = {
403
+ messages: messagesOrParams,
404
+ ...options
405
+ };
406
+ }
357
407
  const processedParams = {
358
408
  ...params,
359
409
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -654,7 +704,7 @@ var Agent = class extends BaseResource {
654
704
  */
655
705
  async stream(params) {
656
706
  console.warn(
657
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
707
+ "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
658
708
  );
659
709
  return this.streamLegacy(params);
660
710
  }
@@ -1003,7 +1053,9 @@ var Agent = class extends BaseResource {
1003
1053
  threadId: processedParams.threadId,
1004
1054
  runtimeContext: processedParams.runtimeContext,
1005
1055
  // TODO: Pass proper tracing context when client-js supports tracing
1006
- tracingContext: { currentSpan: void 0 }
1056
+ tracingContext: { currentSpan: void 0 },
1057
+ suspend: async () => {
1058
+ }
1007
1059
  },
1008
1060
  {
1009
1061
  messages: response.messages,
@@ -1058,7 +1110,40 @@ var Agent = class extends BaseResource {
1058
1110
  }
1059
1111
  return response;
1060
1112
  }
1061
- async streamVNext(params) {
1113
+ async network(params) {
1114
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1115
+ method: "POST",
1116
+ body: params,
1117
+ stream: true
1118
+ });
1119
+ if (!response.body) {
1120
+ throw new Error("No response body");
1121
+ }
1122
+ const streamResponse = new Response(response.body, {
1123
+ status: response.status,
1124
+ statusText: response.statusText,
1125
+ headers: response.headers
1126
+ });
1127
+ streamResponse.processDataStream = async ({
1128
+ onChunk
1129
+ }) => {
1130
+ await processMastraNetworkStream({
1131
+ stream: streamResponse.body,
1132
+ onChunk
1133
+ });
1134
+ };
1135
+ return streamResponse;
1136
+ }
1137
+ async streamVNext(messagesOrParams, options) {
1138
+ let params;
1139
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1140
+ params = messagesOrParams;
1141
+ } else {
1142
+ params = {
1143
+ messages: messagesOrParams,
1144
+ ...options
1145
+ };
1146
+ }
1062
1147
  const processedParams = {
1063
1148
  ...params,
1064
1149
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1134,7 +1219,9 @@ var Agent = class extends BaseResource {
1134
1219
  threadId: processedParams.threadId,
1135
1220
  runtimeContext: processedParams.runtimeContext,
1136
1221
  // TODO: Pass proper tracing context when client-js supports tracing
1137
- tracingContext: { currentSpan: void 0 }
1222
+ tracingContext: { currentSpan: void 0 },
1223
+ suspend: async () => {
1224
+ }
1138
1225
  },
1139
1226
  {
1140
1227
  messages: response.messages,
@@ -1203,10 +1290,11 @@ var Agent = class extends BaseResource {
1203
1290
  /**
1204
1291
  * Gets details about a specific tool available to the agent
1205
1292
  * @param toolId - ID of the tool to retrieve
1293
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1206
1294
  * @returns Promise containing tool details
1207
1295
  */
1208
- getTool(toolId) {
1209
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1296
+ getTool(toolId, runtimeContext) {
1297
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1210
1298
  }
1211
1299
  /**
1212
1300
  * Executes a tool for the agent
@@ -1217,7 +1305,7 @@ var Agent = class extends BaseResource {
1217
1305
  executeTool(toolId, params) {
1218
1306
  const body = {
1219
1307
  data: params.data,
1220
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1308
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1221
1309
  };
1222
1310
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1223
1311
  method: "POST",
@@ -1226,17 +1314,19 @@ var Agent = class extends BaseResource {
1226
1314
  }
1227
1315
  /**
1228
1316
  * Retrieves evaluation results for the agent
1317
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1229
1318
  * @returns Promise containing agent evaluations
1230
1319
  */
1231
- evals() {
1232
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1320
+ evals(runtimeContext) {
1321
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1233
1322
  }
1234
1323
  /**
1235
1324
  * Retrieves live evaluation results for the agent
1325
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1236
1326
  * @returns Promise containing live agent evaluations
1237
1327
  */
1238
- liveEvals() {
1239
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1328
+ liveEvals(runtimeContext) {
1329
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1240
1330
  }
1241
1331
  /**
1242
1332
  * Updates the model for the agent
@@ -1249,61 +1339,27 @@ var Agent = class extends BaseResource {
1249
1339
  body: params
1250
1340
  });
1251
1341
  }
1252
- };
1253
- var Network = class extends BaseResource {
1254
- constructor(options, networkId) {
1255
- super(options);
1256
- this.networkId = networkId;
1257
- }
1258
1342
  /**
1259
- * Retrieves details about the network
1260
- * @returns Promise containing network details
1261
- */
1262
- details() {
1263
- return this.request(`/api/networks/${this.networkId}`);
1264
- }
1265
- /**
1266
- * Generates a response from the agent
1267
- * @param params - Generation parameters including prompt
1268
- * @returns Promise containing the generated response
1343
+ * Updates the model for the agent in the model list
1344
+ * @param params - Parameters for updating the model
1345
+ * @returns Promise containing the updated model
1269
1346
  */
1270
- generate(params) {
1271
- const processedParams = {
1272
- ...params,
1273
- output: zodToJsonSchema(params.output),
1274
- experimental_output: zodToJsonSchema(params.experimental_output)
1275
- };
1276
- return this.request(`/api/networks/${this.networkId}/generate`, {
1347
+ updateModelInModelList({ modelConfigId, ...params }) {
1348
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1277
1349
  method: "POST",
1278
- body: processedParams
1350
+ body: params
1279
1351
  });
1280
1352
  }
1281
1353
  /**
1282
- * Streams a response from the agent
1283
- * @param params - Stream parameters including prompt
1284
- * @returns Promise containing the enhanced Response object with processDataStream method
1354
+ * Reorders the models for the agent
1355
+ * @param params - Parameters for reordering the model list
1356
+ * @returns Promise containing the updated model list
1285
1357
  */
1286
- async stream(params) {
1287
- const processedParams = {
1288
- ...params,
1289
- output: zodToJsonSchema(params.output),
1290
- experimental_output: zodToJsonSchema(params.experimental_output)
1291
- };
1292
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1358
+ reorderModelList(params) {
1359
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1293
1360
  method: "POST",
1294
- body: processedParams,
1295
- stream: true
1361
+ body: params
1296
1362
  });
1297
- if (!response.body) {
1298
- throw new Error("No response body");
1299
- }
1300
- response.processDataStream = async (options = {}) => {
1301
- await processDataStream({
1302
- stream: response.body,
1303
- ...options
1304
- });
1305
- };
1306
- return response;
1307
1363
  }
1308
1364
  };
1309
1365
 
@@ -1394,10 +1450,13 @@ var Vector = class extends BaseResource {
1394
1450
  /**
1395
1451
  * Retrieves details about a specific vector index
1396
1452
  * @param indexName - Name of the index to get details for
1453
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1397
1454
  * @returns Promise containing vector index details
1398
1455
  */
1399
- details(indexName) {
1400
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1456
+ details(indexName, runtimeContext) {
1457
+ return this.request(
1458
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1459
+ );
1401
1460
  }
1402
1461
  /**
1403
1462
  * Deletes a vector index
@@ -1411,10 +1470,11 @@ var Vector = class extends BaseResource {
1411
1470
  }
1412
1471
  /**
1413
1472
  * Retrieves a list of all available indexes
1473
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1414
1474
  * @returns Promise containing array of index names
1415
1475
  */
1416
- getIndexes() {
1417
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1476
+ getIndexes(runtimeContext) {
1477
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1418
1478
  }
1419
1479
  /**
1420
1480
  * Creates a new vector index
@@ -1460,17 +1520,20 @@ var LegacyWorkflow = class extends BaseResource {
1460
1520
  }
1461
1521
  /**
1462
1522
  * Retrieves details about the legacy workflow
1523
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1463
1524
  * @returns Promise containing legacy workflow details including steps and graphs
1464
1525
  */
1465
- details() {
1466
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1526
+ details(runtimeContext) {
1527
+ return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1467
1528
  }
1468
1529
  /**
1469
1530
  * Retrieves all runs for a legacy workflow
1470
1531
  * @param params - Parameters for filtering runs
1532
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1471
1533
  * @returns Promise containing legacy workflow runs array
1472
1534
  */
1473
- runs(params) {
1535
+ runs(params, runtimeContext) {
1536
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1474
1537
  const searchParams = new URLSearchParams();
1475
1538
  if (params?.fromDate) {
1476
1539
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1487,6 +1550,9 @@ var LegacyWorkflow = class extends BaseResource {
1487
1550
  if (params?.resourceId) {
1488
1551
  searchParams.set("resourceId", params.resourceId);
1489
1552
  }
1553
+ if (runtimeContextParam) {
1554
+ searchParams.set("runtimeContext", runtimeContextParam);
1555
+ }
1490
1556
  if (searchParams.size) {
1491
1557
  return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1492
1558
  } else {
@@ -1640,10 +1706,11 @@ var Tool = class extends BaseResource {
1640
1706
  }
1641
1707
  /**
1642
1708
  * Retrieves details about the tool
1709
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1643
1710
  * @returns Promise containing tool details including description and schemas
1644
1711
  */
1645
- details() {
1646
- return this.request(`/api/tools/${this.toolId}`);
1712
+ details(runtimeContext) {
1713
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1647
1714
  }
1648
1715
  /**
1649
1716
  * Executes the tool with the provided parameters
@@ -1720,17 +1787,20 @@ var Workflow = class extends BaseResource {
1720
1787
  }
1721
1788
  /**
1722
1789
  * Retrieves details about the workflow
1790
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1723
1791
  * @returns Promise containing workflow details including steps and graphs
1724
1792
  */
1725
- details() {
1726
- return this.request(`/api/workflows/${this.workflowId}`);
1793
+ details(runtimeContext) {
1794
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1727
1795
  }
1728
1796
  /**
1729
1797
  * Retrieves all runs for a workflow
1730
1798
  * @param params - Parameters for filtering runs
1799
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1731
1800
  * @returns Promise containing workflow runs array
1732
1801
  */
1733
- runs(params) {
1802
+ runs(params, runtimeContext) {
1803
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1734
1804
  const searchParams = new URLSearchParams();
1735
1805
  if (params?.fromDate) {
1736
1806
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1747,6 +1817,9 @@ var Workflow = class extends BaseResource {
1747
1817
  if (params?.resourceId) {
1748
1818
  searchParams.set("resourceId", params.resourceId);
1749
1819
  }
1820
+ if (runtimeContextParam) {
1821
+ searchParams.set("runtimeContext", runtimeContextParam);
1822
+ }
1750
1823
  if (searchParams.size) {
1751
1824
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1752
1825
  } else {
@@ -1756,18 +1829,22 @@ var Workflow = class extends BaseResource {
1756
1829
  /**
1757
1830
  * Retrieves a specific workflow run by its ID
1758
1831
  * @param runId - The ID of the workflow run to retrieve
1832
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1759
1833
  * @returns Promise containing the workflow run details
1760
1834
  */
1761
- runById(runId) {
1762
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1835
+ runById(runId, runtimeContext) {
1836
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1763
1837
  }
1764
1838
  /**
1765
1839
  * Retrieves the execution result for a specific workflow run by its ID
1766
1840
  * @param runId - The ID of the workflow run to retrieve the execution result for
1841
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1767
1842
  * @returns Promise containing the workflow run execution result
1768
1843
  */
1769
- runExecutionResult(runId) {
1770
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1844
+ runExecutionResult(runId, runtimeContext) {
1845
+ return this.request(
1846
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1847
+ );
1771
1848
  }
1772
1849
  /**
1773
1850
  * Cancels a specific workflow run by its ID
@@ -1790,27 +1867,61 @@ var Workflow = class extends BaseResource {
1790
1867
  body: { event: params.event, data: params.data }
1791
1868
  });
1792
1869
  }
1870
+ /**
1871
+ * @deprecated Use createRunAsync() instead.
1872
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1873
+ */
1874
+ async createRun(_params) {
1875
+ throw new Error(
1876
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
1877
+ );
1878
+ }
1793
1879
  /**
1794
1880
  * Creates a new workflow run
1795
1881
  * @param params - Optional object containing the optional runId
1796
- * @returns Promise containing the runId of the created run
1882
+ * @returns Promise containing the runId of the created run with methods to control execution
1797
1883
  */
1798
- createRun(params) {
1884
+ async createRunAsync(params) {
1799
1885
  const searchParams = new URLSearchParams();
1800
1886
  if (!!params?.runId) {
1801
1887
  searchParams.set("runId", params.runId);
1802
1888
  }
1803
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1804
- method: "POST"
1805
- });
1806
- }
1807
- /**
1808
- * Creates a new workflow run (alias for createRun)
1809
- * @param params - Optional object containing the optional runId
1810
- * @returns Promise containing the runId of the created run
1811
- */
1812
- createRunAsync(params) {
1813
- return this.createRun(params);
1889
+ const res = await this.request(
1890
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1891
+ {
1892
+ method: "POST"
1893
+ }
1894
+ );
1895
+ const runId = res.runId;
1896
+ return {
1897
+ runId,
1898
+ start: async (p) => {
1899
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1900
+ },
1901
+ startAsync: async (p) => {
1902
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1903
+ },
1904
+ watch: async (onRecord) => {
1905
+ return this.watch({ runId }, onRecord);
1906
+ },
1907
+ stream: async (p) => {
1908
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1909
+ },
1910
+ resume: async (p) => {
1911
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1912
+ },
1913
+ resumeAsync: async (p) => {
1914
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1915
+ },
1916
+ resumeStreamVNext: async (p) => {
1917
+ return this.resumeStreamVNext({
1918
+ runId,
1919
+ step: p.step,
1920
+ resumeData: p.resumeData,
1921
+ runtimeContext: p.runtimeContext
1922
+ });
1923
+ }
1924
+ };
1814
1925
  }
1815
1926
  /**
1816
1927
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1838,7 +1949,6 @@ var Workflow = class extends BaseResource {
1838
1949
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1839
1950
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1840
1951
  method: "POST",
1841
- stream: true,
1842
1952
  body: {
1843
1953
  step,
1844
1954
  resumeData,
@@ -1882,7 +1992,54 @@ var Workflow = class extends BaseResource {
1882
1992
  }
1883
1993
  );
1884
1994
  if (!response.ok) {
1885
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1995
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1996
+ }
1997
+ if (!response.body) {
1998
+ throw new Error("Response body is null");
1999
+ }
2000
+ let failedChunk = void 0;
2001
+ const transformStream = new TransformStream({
2002
+ start() {
2003
+ },
2004
+ async transform(chunk, controller) {
2005
+ try {
2006
+ const decoded = new TextDecoder().decode(chunk);
2007
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2008
+ for (const chunk2 of chunks) {
2009
+ if (chunk2) {
2010
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2011
+ try {
2012
+ const parsedChunk = JSON.parse(newChunk);
2013
+ controller.enqueue(parsedChunk);
2014
+ failedChunk = void 0;
2015
+ } catch {
2016
+ failedChunk = newChunk;
2017
+ }
2018
+ }
2019
+ }
2020
+ } catch {
2021
+ }
2022
+ }
2023
+ });
2024
+ return response.body.pipeThrough(transformStream);
2025
+ }
2026
+ /**
2027
+ * Observes workflow stream for a workflow run
2028
+ * @param params - Object containing the runId
2029
+ * @returns Promise containing the workflow execution results
2030
+ */
2031
+ async observeStream(params) {
2032
+ const searchParams = new URLSearchParams();
2033
+ searchParams.set("runId", params.runId);
2034
+ const response = await this.request(
2035
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
2036
+ {
2037
+ method: "POST",
2038
+ stream: true
2039
+ }
2040
+ );
2041
+ if (!response.ok) {
2042
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1886
2043
  }
1887
2044
  if (!response.body) {
1888
2045
  throw new Error("Response body is null");
@@ -1928,7 +2085,7 @@ var Workflow = class extends BaseResource {
1928
2085
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1929
2086
  {
1930
2087
  method: "POST",
1931
- body: { inputData: params.inputData, runtimeContext },
2088
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1932
2089
  stream: true
1933
2090
  }
1934
2091
  );
@@ -1980,6 +2137,22 @@ var Workflow = class extends BaseResource {
1980
2137
  }
1981
2138
  });
1982
2139
  }
2140
+ /**
2141
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2142
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2143
+ * @returns Promise containing the workflow resume results
2144
+ */
2145
+ resumeStreamVNext(params) {
2146
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2147
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
2148
+ method: "POST",
2149
+ body: {
2150
+ step: params.step,
2151
+ resumeData: params.resumeData,
2152
+ runtimeContext
2153
+ }
2154
+ });
2155
+ }
1983
2156
  /**
1984
2157
  * Watches workflow transitions in real-time
1985
2158
  * @param runId - Optional run ID to filter the watch stream
@@ -2114,10 +2287,11 @@ var MCPTool = class extends BaseResource {
2114
2287
  }
2115
2288
  /**
2116
2289
  * Retrieves details about this specific tool from the MCP server.
2290
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2117
2291
  * @returns Promise containing the tool's information (name, description, schema).
2118
2292
  */
2119
- details() {
2120
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2293
+ details(runtimeContext) {
2294
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2121
2295
  }
2122
2296
  /**
2123
2297
  * Executes this specific tool on the MCP server.
@@ -2173,11 +2347,20 @@ var AgentBuilder = class extends BaseResource {
2173
2347
  };
2174
2348
  }
2175
2349
  }
2350
+ /**
2351
+ * @deprecated Use createRunAsync() instead.
2352
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2353
+ */
2354
+ async createRun(_params) {
2355
+ throw new Error(
2356
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
2357
+ );
2358
+ }
2176
2359
  /**
2177
2360
  * Creates a new agent builder action run and returns the runId.
2178
2361
  * This calls `/api/agent-builder/:actionId/create-run`.
2179
2362
  */
2180
- async createRun(params) {
2363
+ async createRunAsync(params) {
2181
2364
  const searchParams = new URLSearchParams();
2182
2365
  if (!!params?.runId) {
2183
2366
  searchParams.set("runId", params.runId);
@@ -2187,14 +2370,6 @@ var AgentBuilder = class extends BaseResource {
2187
2370
  method: "POST"
2188
2371
  });
2189
2372
  }
2190
- /**
2191
- * Creates a new workflow run (alias for createRun)
2192
- * @param params - Optional object containing the optional runId
2193
- * @returns Promise containing the runId of the created run
2194
- */
2195
- createRunAsync(params) {
2196
- return this.createRun(params);
2197
- }
2198
2373
  /**
2199
2374
  * Starts agent builder action asynchronously and waits for completion.
2200
2375
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2554,6 +2729,12 @@ var Observability = class extends BaseResource {
2554
2729
  const queryString = searchParams.toString();
2555
2730
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2556
2731
  }
2732
+ score(params) {
2733
+ return this.request(`/api/observability/traces/score`, {
2734
+ method: "POST",
2735
+ body: { ...params }
2736
+ });
2737
+ }
2557
2738
  };
2558
2739
 
2559
2740
  // src/resources/network-memory-thread.ts
@@ -2628,10 +2809,11 @@ var VNextNetwork = class extends BaseResource {
2628
2809
  }
2629
2810
  /**
2630
2811
  * Retrieves details about the network
2812
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2631
2813
  * @returns Promise containing vNext network details
2632
2814
  */
2633
- details() {
2634
- return this.request(`/api/networks/v-next/${this.networkId}`);
2815
+ details(runtimeContext) {
2816
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2635
2817
  }
2636
2818
  /**
2637
2819
  * Generates a response from the v-next network
@@ -2766,10 +2948,17 @@ var MastraClient = class extends BaseResource {
2766
2948
  }
2767
2949
  /**
2768
2950
  * Retrieves all available agents
2951
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2769
2952
  * @returns Promise containing map of agent IDs to agent details
2770
2953
  */
2771
- getAgents() {
2772
- return this.request("/api/agents");
2954
+ getAgents(runtimeContext) {
2955
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2956
+ const searchParams = new URLSearchParams();
2957
+ if (runtimeContextParam) {
2958
+ searchParams.set("runtimeContext", runtimeContextParam);
2959
+ }
2960
+ const queryString = searchParams.toString();
2961
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2773
2962
  }
2774
2963
  /**
2775
2964
  * Gets an agent instance by ID
@@ -2787,6 +2976,14 @@ var MastraClient = class extends BaseResource {
2787
2976
  getMemoryThreads(params) {
2788
2977
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2789
2978
  }
2979
+ /**
2980
+ * Retrieves memory config for a resource
2981
+ * @param params - Parameters containing the resource ID
2982
+ * @returns Promise containing array of memory threads
2983
+ */
2984
+ getMemoryConfig(params) {
2985
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2986
+ }
2790
2987
  /**
2791
2988
  * Creates a new memory thread
2792
2989
  * @param params - Parameters for creating the memory thread
@@ -2803,6 +3000,24 @@ var MastraClient = class extends BaseResource {
2803
3000
  getMemoryThread(threadId, agentId) {
2804
3001
  return new MemoryThread(this.options, threadId, agentId);
2805
3002
  }
3003
+ getThreadMessages(threadId, opts = {}) {
3004
+ let url = "";
3005
+ if (opts.agentId) {
3006
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
3007
+ } else if (opts.networkId) {
3008
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
3009
+ }
3010
+ return this.request(url);
3011
+ }
3012
+ deleteThread(threadId, opts = {}) {
3013
+ let url = "";
3014
+ if (opts.agentId) {
3015
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
3016
+ } else if (opts.networkId) {
3017
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
3018
+ }
3019
+ return this.request(url, { method: "DELETE" });
3020
+ }
2806
3021
  /**
2807
3022
  * Saves messages to memory
2808
3023
  * @param params - Parameters containing messages to save
@@ -2865,10 +3080,17 @@ var MastraClient = class extends BaseResource {
2865
3080
  }
2866
3081
  /**
2867
3082
  * Retrieves all available tools
3083
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2868
3084
  * @returns Promise containing map of tool IDs to tool details
2869
3085
  */
2870
- getTools() {
2871
- return this.request("/api/tools");
3086
+ getTools(runtimeContext) {
3087
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3088
+ const searchParams = new URLSearchParams();
3089
+ if (runtimeContextParam) {
3090
+ searchParams.set("runtimeContext", runtimeContextParam);
3091
+ }
3092
+ const queryString = searchParams.toString();
3093
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2872
3094
  }
2873
3095
  /**
2874
3096
  * Gets a tool instance by ID
@@ -2895,10 +3117,17 @@ var MastraClient = class extends BaseResource {
2895
3117
  }
2896
3118
  /**
2897
3119
  * Retrieves all available workflows
3120
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2898
3121
  * @returns Promise containing map of workflow IDs to workflow details
2899
3122
  */
2900
- getWorkflows() {
2901
- return this.request("/api/workflows");
3123
+ getWorkflows(runtimeContext) {
3124
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3125
+ const searchParams = new URLSearchParams();
3126
+ if (runtimeContextParam) {
3127
+ searchParams.set("runtimeContext", runtimeContextParam);
3128
+ }
3129
+ const queryString = searchParams.toString();
3130
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2902
3131
  }
2903
3132
  /**
2904
3133
  * Gets a workflow instance by ID
@@ -3066,13 +3295,6 @@ var MastraClient = class extends BaseResource {
3066
3295
  return this.request(`/api/telemetry`);
3067
3296
  }
3068
3297
  }
3069
- /**
3070
- * Retrieves all available networks
3071
- * @returns Promise containing map of network IDs to network details
3072
- */
3073
- getNetworks() {
3074
- return this.request("/api/networks");
3075
- }
3076
3298
  /**
3077
3299
  * Retrieves all available vNext networks
3078
3300
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3080,14 +3302,6 @@ var MastraClient = class extends BaseResource {
3080
3302
  getVNextNetworks() {
3081
3303
  return this.request("/api/networks/v-next");
3082
3304
  }
3083
- /**
3084
- * Gets a network instance by ID
3085
- * @param networkId - ID of the network to retrieve
3086
- * @returns Network instance
3087
- */
3088
- getNetwork(networkId) {
3089
- return new Network(this.options, networkId);
3090
- }
3091
3305
  /**
3092
3306
  * Gets a vNext network instance by ID
3093
3307
  * @param networkId - ID of the vNext network to retrieve
@@ -3278,8 +3492,30 @@ var MastraClient = class extends BaseResource {
3278
3492
  getAITraces(params) {
3279
3493
  return this.observability.getTraces(params);
3280
3494
  }
3495
+ score(params) {
3496
+ return this.observability.score(params);
3497
+ }
3498
+ };
3499
+
3500
+ // src/tools.ts
3501
+ var ClientTool = class {
3502
+ id;
3503
+ description;
3504
+ inputSchema;
3505
+ outputSchema;
3506
+ execute;
3507
+ constructor(opts) {
3508
+ this.id = opts.id;
3509
+ this.description = opts.description;
3510
+ this.inputSchema = opts.inputSchema;
3511
+ this.outputSchema = opts.outputSchema;
3512
+ this.execute = opts.execute;
3513
+ }
3281
3514
  };
3515
+ function createTool(opts) {
3516
+ return new ClientTool(opts);
3517
+ }
3282
3518
 
3283
- export { MastraClient };
3519
+ export { ClientTool, MastraClient, createTool };
3284
3520
  //# sourceMappingURL=index.js.map
3285
3521
  //# sourceMappingURL=index.js.map