@mastra/client-js 0.0.0-fix-bundle-cleanup-20250911062914 → 0.0.0-fix-cloud-peer-deps-20250929-20250929175756

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 (39) hide show
  1. package/CHANGELOG.md +241 -4
  2. package/README.md +2 -6
  3. package/dist/client.d.ts +37 -27
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +363 -357
  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 +362 -358
  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 +42 -11
  14. package/dist/resources/agent.d.ts.map +1 -1
  15. package/dist/resources/index.d.ts +0 -2
  16. package/dist/resources/index.d.ts.map +1 -1
  17. package/dist/resources/mcp-tool.d.ts +2 -1
  18. package/dist/resources/mcp-tool.d.ts.map +1 -1
  19. package/dist/resources/observability.d.ts +17 -1
  20. package/dist/resources/observability.d.ts.map +1 -1
  21. package/dist/resources/tool.d.ts +2 -1
  22. package/dist/resources/tool.d.ts.map +1 -1
  23. package/dist/resources/vNextNetwork.d.ts +2 -1
  24. package/dist/resources/vNextNetwork.d.ts.map +1 -1
  25. package/dist/resources/vector.d.ts +5 -2
  26. package/dist/resources/vector.d.ts.map +1 -1
  27. package/dist/resources/workflow.d.ts +96 -11
  28. package/dist/resources/workflow.d.ts.map +1 -1
  29. package/dist/tools.d.ts +22 -0
  30. package/dist/tools.d.ts.map +1 -0
  31. package/dist/types.d.ts +49 -42
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/utils/index.d.ts +2 -0
  34. package/dist/utils/index.d.ts.map +1 -1
  35. package/package.json +5 -5
  36. package/dist/resources/legacy-workflow.d.ts +0 -87
  37. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  38. package/dist/resources/network.d.ts +0 -30
  39. package/dist/resources/network.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -21,6 +21,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
21
21
  }
22
22
  return void 0;
23
23
  }
24
+ function base64RuntimeContext(runtimeContext) {
25
+ if (runtimeContext) {
26
+ return btoa(JSON.stringify(runtimeContext));
27
+ }
28
+ return void 0;
29
+ }
30
+ function runtimeContextQueryString(runtimeContext) {
31
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
32
+ if (!runtimeContextParam) return "";
33
+ const searchParams = new URLSearchParams();
34
+ searchParams.set("runtimeContext", runtimeContextParam);
35
+ const queryString = searchParams.toString();
36
+ return queryString ? `?${queryString}` : "";
37
+ }
24
38
  function isZodType(value) {
25
39
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
26
40
  }
@@ -83,7 +97,7 @@ async function sharedProcessMastraStream({
83
97
  if (line.startsWith("data: ")) {
84
98
  const data = line.slice(6);
85
99
  if (data === "[DONE]") {
86
- console.log("\u{1F3C1} Stream finished");
100
+ console.info("\u{1F3C1} Stream finished");
87
101
  return;
88
102
  }
89
103
  try {
@@ -205,7 +219,9 @@ async function executeToolCallAndRespond({
205
219
  resourceId,
206
220
  threadId,
207
221
  runtimeContext,
208
- tracingContext: { currentSpan: void 0 }
222
+ tracingContext: { currentSpan: void 0 },
223
+ suspend: async () => {
224
+ }
209
225
  },
210
226
  {
211
227
  messages: response.messages,
@@ -213,11 +229,7 @@ async function executeToolCallAndRespond({
213
229
  }
214
230
  );
215
231
  const updatedMessages = [
216
- {
217
- role: "user",
218
- content: params.messages
219
- },
220
- ...response.response.messages,
232
+ ...response.response.messages || [],
221
233
  {
222
234
  role: "tool",
223
235
  content: [
@@ -279,17 +291,21 @@ var AgentVoice = class extends BaseResource {
279
291
  }
280
292
  /**
281
293
  * Get available speakers for the agent's voice provider
294
+ * @param runtimeContext - Optional runtime context to pass as query parameter
295
+ * @param runtimeContext - Optional runtime context to pass as query parameter
282
296
  * @returns Promise containing list of available speakers
283
297
  */
284
- getSpeakers() {
285
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
298
+ getSpeakers(runtimeContext) {
299
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
286
300
  }
287
301
  /**
288
302
  * Get the listener configuration for the agent's voice provider
303
+ * @param runtimeContext - Optional runtime context to pass as query parameter
304
+ * @param runtimeContext - Optional runtime context to pass as query parameter
289
305
  * @returns Promise containing a check if the agent has listening capabilities
290
306
  */
291
- getListener() {
292
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
307
+ getListener(runtimeContext) {
308
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
293
309
  }
294
310
  };
295
311
  var Agent = class extends BaseResource {
@@ -301,14 +317,15 @@ var Agent = class extends BaseResource {
301
317
  voice;
302
318
  /**
303
319
  * Retrieves details about the agent
320
+ * @param runtimeContext - Optional runtime context to pass as query parameter
304
321
  * @returns Promise containing agent details including model and instructions
305
322
  */
306
- details() {
307
- return this.request(`/api/agents/${this.agentId}`);
323
+ details(runtimeContext) {
324
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
308
325
  }
309
326
  async generate(params) {
310
327
  console.warn(
311
- "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."
328
+ "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."
312
329
  );
313
330
  return this.generateLegacy(params);
314
331
  }
@@ -343,7 +360,9 @@ var Agent = class extends BaseResource {
343
360
  resourceId,
344
361
  threadId,
345
362
  runtimeContext,
346
- tracingContext: { currentSpan: void 0 }
363
+ tracingContext: { currentSpan: void 0 },
364
+ suspend: async () => {
365
+ }
347
366
  },
348
367
  {
349
368
  messages: response.messages,
@@ -351,10 +370,6 @@ var Agent = class extends BaseResource {
351
370
  }
352
371
  );
353
372
  const updatedMessages = [
354
- {
355
- role: "user",
356
- content: params.messages
357
- },
358
373
  ...response.response.messages,
359
374
  {
360
375
  role: "tool",
@@ -377,7 +392,16 @@ var Agent = class extends BaseResource {
377
392
  }
378
393
  return response;
379
394
  }
380
- async generateVNext(params) {
395
+ async generateVNext(messagesOrParams, options) {
396
+ let params;
397
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
398
+ params = messagesOrParams;
399
+ } else {
400
+ params = {
401
+ messages: messagesOrParams,
402
+ ...options
403
+ };
404
+ }
381
405
  const processedParams = {
382
406
  ...params,
383
407
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -678,7 +702,7 @@ var Agent = class extends BaseResource {
678
702
  */
679
703
  async stream(params) {
680
704
  console.warn(
681
- "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."
705
+ "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."
682
706
  );
683
707
  return this.streamLegacy(params);
684
708
  }
@@ -1027,7 +1051,9 @@ var Agent = class extends BaseResource {
1027
1051
  threadId: processedParams.threadId,
1028
1052
  runtimeContext: processedParams.runtimeContext,
1029
1053
  // TODO: Pass proper tracing context when client-js supports tracing
1030
- tracingContext: { currentSpan: void 0 }
1054
+ tracingContext: { currentSpan: void 0 },
1055
+ suspend: async () => {
1056
+ }
1031
1057
  },
1032
1058
  {
1033
1059
  messages: response.messages,
@@ -1053,9 +1079,7 @@ var Agent = class extends BaseResource {
1053
1079
  toolInvocation.state = "result";
1054
1080
  toolInvocation.result = result;
1055
1081
  }
1056
- const originalMessages = processedParams.messages;
1057
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1058
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1082
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1059
1083
  this.processStreamResponse_vNext(
1060
1084
  {
1061
1085
  ...processedParams,
@@ -1106,7 +1130,16 @@ var Agent = class extends BaseResource {
1106
1130
  };
1107
1131
  return streamResponse;
1108
1132
  }
1109
- async streamVNext(params) {
1133
+ async streamVNext(messagesOrParams, options) {
1134
+ let params;
1135
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1136
+ params = messagesOrParams;
1137
+ } else {
1138
+ params = {
1139
+ messages: messagesOrParams,
1140
+ ...options
1141
+ };
1142
+ }
1110
1143
  const processedParams = {
1111
1144
  ...params,
1112
1145
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1182,7 +1215,9 @@ var Agent = class extends BaseResource {
1182
1215
  threadId: processedParams.threadId,
1183
1216
  runtimeContext: processedParams.runtimeContext,
1184
1217
  // TODO: Pass proper tracing context when client-js supports tracing
1185
- tracingContext: { currentSpan: void 0 }
1218
+ tracingContext: { currentSpan: void 0 },
1219
+ suspend: async () => {
1220
+ }
1186
1221
  },
1187
1222
  {
1188
1223
  messages: response.messages,
@@ -1220,12 +1255,10 @@ var Agent = class extends BaseResource {
1220
1255
  } finally {
1221
1256
  writer.releaseLock();
1222
1257
  }
1223
- const originalMessages = processedParams.messages;
1224
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1225
1258
  this.processStreamResponse(
1226
1259
  {
1227
1260
  ...processedParams,
1228
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1261
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1229
1262
  },
1230
1263
  writable
1231
1264
  ).catch((error) => {
@@ -1251,10 +1284,11 @@ var Agent = class extends BaseResource {
1251
1284
  /**
1252
1285
  * Gets details about a specific tool available to the agent
1253
1286
  * @param toolId - ID of the tool to retrieve
1287
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1254
1288
  * @returns Promise containing tool details
1255
1289
  */
1256
- getTool(toolId) {
1257
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1290
+ getTool(toolId, runtimeContext) {
1291
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1258
1292
  }
1259
1293
  /**
1260
1294
  * Executes a tool for the agent
@@ -1265,7 +1299,7 @@ var Agent = class extends BaseResource {
1265
1299
  executeTool(toolId, params) {
1266
1300
  const body = {
1267
1301
  data: params.data,
1268
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1302
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1269
1303
  };
1270
1304
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1271
1305
  method: "POST",
@@ -1274,17 +1308,19 @@ var Agent = class extends BaseResource {
1274
1308
  }
1275
1309
  /**
1276
1310
  * Retrieves evaluation results for the agent
1311
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1277
1312
  * @returns Promise containing agent evaluations
1278
1313
  */
1279
- evals() {
1280
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1314
+ evals(runtimeContext) {
1315
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1281
1316
  }
1282
1317
  /**
1283
1318
  * Retrieves live evaluation results for the agent
1319
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1284
1320
  * @returns Promise containing live agent evaluations
1285
1321
  */
1286
- liveEvals() {
1287
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1322
+ liveEvals(runtimeContext) {
1323
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1288
1324
  }
1289
1325
  /**
1290
1326
  * Updates the model for the agent
@@ -1297,61 +1333,27 @@ var Agent = class extends BaseResource {
1297
1333
  body: params
1298
1334
  });
1299
1335
  }
1300
- };
1301
- var Network = class extends BaseResource {
1302
- constructor(options, networkId) {
1303
- super(options);
1304
- this.networkId = networkId;
1305
- }
1306
1336
  /**
1307
- * Retrieves details about the network
1308
- * @returns Promise containing network details
1309
- */
1310
- details() {
1311
- return this.request(`/api/networks/${this.networkId}`);
1312
- }
1313
- /**
1314
- * Generates a response from the agent
1315
- * @param params - Generation parameters including prompt
1316
- * @returns Promise containing the generated response
1337
+ * Updates the model for the agent in the model list
1338
+ * @param params - Parameters for updating the model
1339
+ * @returns Promise containing the updated model
1317
1340
  */
1318
- generate(params) {
1319
- const processedParams = {
1320
- ...params,
1321
- output: zodToJsonSchema(params.output),
1322
- experimental_output: zodToJsonSchema(params.experimental_output)
1323
- };
1324
- return this.request(`/api/networks/${this.networkId}/generate`, {
1341
+ updateModelInModelList({ modelConfigId, ...params }) {
1342
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1325
1343
  method: "POST",
1326
- body: processedParams
1344
+ body: params
1327
1345
  });
1328
1346
  }
1329
1347
  /**
1330
- * Streams a response from the agent
1331
- * @param params - Stream parameters including prompt
1332
- * @returns Promise containing the enhanced Response object with processDataStream method
1348
+ * Reorders the models for the agent
1349
+ * @param params - Parameters for reordering the model list
1350
+ * @returns Promise containing the updated model list
1333
1351
  */
1334
- async stream(params) {
1335
- const processedParams = {
1336
- ...params,
1337
- output: zodToJsonSchema(params.output),
1338
- experimental_output: zodToJsonSchema(params.experimental_output)
1339
- };
1340
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1352
+ reorderModelList(params) {
1353
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1341
1354
  method: "POST",
1342
- body: processedParams,
1343
- stream: true
1355
+ body: params
1344
1356
  });
1345
- if (!response.body) {
1346
- throw new Error("No response body");
1347
- }
1348
- response.processDataStream = async (options = {}) => {
1349
- await uiUtils.processDataStream({
1350
- stream: response.body,
1351
- ...options
1352
- });
1353
- };
1354
- return response;
1355
1357
  }
1356
1358
  };
1357
1359
 
@@ -1442,10 +1444,13 @@ var Vector = class extends BaseResource {
1442
1444
  /**
1443
1445
  * Retrieves details about a specific vector index
1444
1446
  * @param indexName - Name of the index to get details for
1447
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1445
1448
  * @returns Promise containing vector index details
1446
1449
  */
1447
- details(indexName) {
1448
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1450
+ details(indexName, runtimeContext) {
1451
+ return this.request(
1452
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1453
+ );
1449
1454
  }
1450
1455
  /**
1451
1456
  * Deletes a vector index
@@ -1459,10 +1464,11 @@ var Vector = class extends BaseResource {
1459
1464
  }
1460
1465
  /**
1461
1466
  * Retrieves a list of all available indexes
1467
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1462
1468
  * @returns Promise containing array of index names
1463
1469
  */
1464
- getIndexes() {
1465
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1470
+ getIndexes(runtimeContext) {
1471
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1466
1472
  }
1467
1473
  /**
1468
1474
  * Creates a new vector index
@@ -1499,187 +1505,6 @@ var Vector = class extends BaseResource {
1499
1505
  }
1500
1506
  };
1501
1507
 
1502
- // src/resources/legacy-workflow.ts
1503
- var RECORD_SEPARATOR = "";
1504
- var LegacyWorkflow = class extends BaseResource {
1505
- constructor(options, workflowId) {
1506
- super(options);
1507
- this.workflowId = workflowId;
1508
- }
1509
- /**
1510
- * Retrieves details about the legacy workflow
1511
- * @returns Promise containing legacy workflow details including steps and graphs
1512
- */
1513
- details() {
1514
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1515
- }
1516
- /**
1517
- * Retrieves all runs for a legacy workflow
1518
- * @param params - Parameters for filtering runs
1519
- * @returns Promise containing legacy workflow runs array
1520
- */
1521
- runs(params) {
1522
- const searchParams = new URLSearchParams();
1523
- if (params?.fromDate) {
1524
- searchParams.set("fromDate", params.fromDate.toISOString());
1525
- }
1526
- if (params?.toDate) {
1527
- searchParams.set("toDate", params.toDate.toISOString());
1528
- }
1529
- if (params?.limit) {
1530
- searchParams.set("limit", String(params.limit));
1531
- }
1532
- if (params?.offset) {
1533
- searchParams.set("offset", String(params.offset));
1534
- }
1535
- if (params?.resourceId) {
1536
- searchParams.set("resourceId", params.resourceId);
1537
- }
1538
- if (searchParams.size) {
1539
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1540
- } else {
1541
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1542
- }
1543
- }
1544
- /**
1545
- * Creates a new legacy workflow run
1546
- * @returns Promise containing the generated run ID
1547
- */
1548
- createRun(params) {
1549
- const searchParams = new URLSearchParams();
1550
- if (!!params?.runId) {
1551
- searchParams.set("runId", params.runId);
1552
- }
1553
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1554
- method: "POST"
1555
- });
1556
- }
1557
- /**
1558
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1559
- * @param params - Object containing the runId and triggerData
1560
- * @returns Promise containing success message
1561
- */
1562
- start(params) {
1563
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1564
- method: "POST",
1565
- body: params?.triggerData
1566
- });
1567
- }
1568
- /**
1569
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1570
- * @param stepId - ID of the step to resume
1571
- * @param runId - ID of the legacy workflow run
1572
- * @param context - Context to resume the legacy workflow with
1573
- * @returns Promise containing the legacy workflow resume results
1574
- */
1575
- resume({
1576
- stepId,
1577
- runId,
1578
- context
1579
- }) {
1580
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1581
- method: "POST",
1582
- body: {
1583
- stepId,
1584
- context
1585
- }
1586
- });
1587
- }
1588
- /**
1589
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1590
- * @param params - Object containing the optional runId and triggerData
1591
- * @returns Promise containing the workflow execution results
1592
- */
1593
- startAsync(params) {
1594
- const searchParams = new URLSearchParams();
1595
- if (!!params?.runId) {
1596
- searchParams.set("runId", params.runId);
1597
- }
1598
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1599
- method: "POST",
1600
- body: params?.triggerData
1601
- });
1602
- }
1603
- /**
1604
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1605
- * @param params - Object containing the runId, stepId, and context
1606
- * @returns Promise containing the workflow resume results
1607
- */
1608
- resumeAsync(params) {
1609
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1610
- method: "POST",
1611
- body: {
1612
- stepId: params.stepId,
1613
- context: params.context
1614
- }
1615
- });
1616
- }
1617
- /**
1618
- * Creates an async generator that processes a readable stream and yields records
1619
- * separated by the Record Separator character (\x1E)
1620
- *
1621
- * @param stream - The readable stream to process
1622
- * @returns An async generator that yields parsed records
1623
- */
1624
- async *streamProcessor(stream) {
1625
- const reader = stream.getReader();
1626
- let doneReading = false;
1627
- let buffer = "";
1628
- try {
1629
- while (!doneReading) {
1630
- const { done, value } = await reader.read();
1631
- doneReading = done;
1632
- if (done && !value) continue;
1633
- try {
1634
- const decoded = value ? new TextDecoder().decode(value) : "";
1635
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1636
- buffer = chunks.pop() || "";
1637
- for (const chunk of chunks) {
1638
- if (chunk) {
1639
- if (typeof chunk === "string") {
1640
- try {
1641
- const parsedChunk = JSON.parse(chunk);
1642
- yield parsedChunk;
1643
- } catch {
1644
- }
1645
- }
1646
- }
1647
- }
1648
- } catch {
1649
- }
1650
- }
1651
- if (buffer) {
1652
- try {
1653
- yield JSON.parse(buffer);
1654
- } catch {
1655
- }
1656
- }
1657
- } finally {
1658
- reader.cancel().catch(() => {
1659
- });
1660
- }
1661
- }
1662
- /**
1663
- * Watches legacy workflow transitions in real-time
1664
- * @param runId - Optional run ID to filter the watch stream
1665
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1666
- */
1667
- async watch({ runId }, onRecord) {
1668
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1669
- stream: true
1670
- });
1671
- if (!response.ok) {
1672
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1673
- }
1674
- if (!response.body) {
1675
- throw new Error("Response body is null");
1676
- }
1677
- for await (const record of this.streamProcessor(response.body)) {
1678
- onRecord(record);
1679
- }
1680
- }
1681
- };
1682
-
1683
1508
  // src/resources/tool.ts
1684
1509
  var Tool = class extends BaseResource {
1685
1510
  constructor(options, toolId) {
@@ -1688,10 +1513,11 @@ var Tool = class extends BaseResource {
1688
1513
  }
1689
1514
  /**
1690
1515
  * Retrieves details about the tool
1516
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1691
1517
  * @returns Promise containing tool details including description and schemas
1692
1518
  */
1693
- details() {
1694
- return this.request(`/api/tools/${this.toolId}`);
1519
+ details(runtimeContext) {
1520
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1695
1521
  }
1696
1522
  /**
1697
1523
  * Executes the tool with the provided parameters
@@ -1715,7 +1541,7 @@ var Tool = class extends BaseResource {
1715
1541
  };
1716
1542
 
1717
1543
  // src/resources/workflow.ts
1718
- var RECORD_SEPARATOR2 = "";
1544
+ var RECORD_SEPARATOR = "";
1719
1545
  var Workflow = class extends BaseResource {
1720
1546
  constructor(options, workflowId) {
1721
1547
  super(options);
@@ -1739,7 +1565,7 @@ var Workflow = class extends BaseResource {
1739
1565
  if (done && !value) continue;
1740
1566
  try {
1741
1567
  const decoded = value ? new TextDecoder().decode(value) : "";
1742
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1568
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1743
1569
  buffer = chunks.pop() || "";
1744
1570
  for (const chunk of chunks) {
1745
1571
  if (chunk) {
@@ -1768,17 +1594,20 @@ var Workflow = class extends BaseResource {
1768
1594
  }
1769
1595
  /**
1770
1596
  * Retrieves details about the workflow
1597
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1771
1598
  * @returns Promise containing workflow details including steps and graphs
1772
1599
  */
1773
- details() {
1774
- return this.request(`/api/workflows/${this.workflowId}`);
1600
+ details(runtimeContext) {
1601
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1775
1602
  }
1776
1603
  /**
1777
1604
  * Retrieves all runs for a workflow
1778
1605
  * @param params - Parameters for filtering runs
1606
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1779
1607
  * @returns Promise containing workflow runs array
1780
1608
  */
1781
- runs(params) {
1609
+ runs(params, runtimeContext) {
1610
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1782
1611
  const searchParams = new URLSearchParams();
1783
1612
  if (params?.fromDate) {
1784
1613
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1795,6 +1624,9 @@ var Workflow = class extends BaseResource {
1795
1624
  if (params?.resourceId) {
1796
1625
  searchParams.set("resourceId", params.resourceId);
1797
1626
  }
1627
+ if (runtimeContextParam) {
1628
+ searchParams.set("runtimeContext", runtimeContextParam);
1629
+ }
1798
1630
  if (searchParams.size) {
1799
1631
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1800
1632
  } else {
@@ -1804,18 +1636,22 @@ var Workflow = class extends BaseResource {
1804
1636
  /**
1805
1637
  * Retrieves a specific workflow run by its ID
1806
1638
  * @param runId - The ID of the workflow run to retrieve
1639
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1807
1640
  * @returns Promise containing the workflow run details
1808
1641
  */
1809
- runById(runId) {
1810
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1642
+ runById(runId, runtimeContext) {
1643
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1811
1644
  }
1812
1645
  /**
1813
1646
  * Retrieves the execution result for a specific workflow run by its ID
1814
1647
  * @param runId - The ID of the workflow run to retrieve the execution result for
1648
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1815
1649
  * @returns Promise containing the workflow run execution result
1816
1650
  */
1817
- runExecutionResult(runId) {
1818
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1651
+ runExecutionResult(runId, runtimeContext) {
1652
+ return this.request(
1653
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1654
+ );
1819
1655
  }
1820
1656
  /**
1821
1657
  * Cancels a specific workflow run by its ID
@@ -1838,27 +1674,61 @@ var Workflow = class extends BaseResource {
1838
1674
  body: { event: params.event, data: params.data }
1839
1675
  });
1840
1676
  }
1677
+ /**
1678
+ * @deprecated Use createRunAsync() instead.
1679
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1680
+ */
1681
+ async createRun(_params) {
1682
+ throw new Error(
1683
+ "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."
1684
+ );
1685
+ }
1841
1686
  /**
1842
1687
  * Creates a new workflow run
1843
1688
  * @param params - Optional object containing the optional runId
1844
- * @returns Promise containing the runId of the created run
1689
+ * @returns Promise containing the runId of the created run with methods to control execution
1845
1690
  */
1846
- createRun(params) {
1691
+ async createRunAsync(params) {
1847
1692
  const searchParams = new URLSearchParams();
1848
1693
  if (!!params?.runId) {
1849
1694
  searchParams.set("runId", params.runId);
1850
1695
  }
1851
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1852
- method: "POST"
1853
- });
1854
- }
1855
- /**
1856
- * Creates a new workflow run (alias for createRun)
1857
- * @param params - Optional object containing the optional runId
1858
- * @returns Promise containing the runId of the created run
1859
- */
1860
- createRunAsync(params) {
1861
- return this.createRun(params);
1696
+ const res = await this.request(
1697
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1698
+ {
1699
+ method: "POST"
1700
+ }
1701
+ );
1702
+ const runId = res.runId;
1703
+ return {
1704
+ runId,
1705
+ start: async (p) => {
1706
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1707
+ },
1708
+ startAsync: async (p) => {
1709
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1710
+ },
1711
+ watch: async (onRecord) => {
1712
+ return this.watch({ runId }, onRecord);
1713
+ },
1714
+ stream: async (p) => {
1715
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1716
+ },
1717
+ resume: async (p) => {
1718
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1719
+ },
1720
+ resumeAsync: async (p) => {
1721
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1722
+ },
1723
+ resumeStreamVNext: async (p) => {
1724
+ return this.resumeStreamVNext({
1725
+ runId,
1726
+ step: p.step,
1727
+ resumeData: p.resumeData,
1728
+ runtimeContext: p.runtimeContext
1729
+ });
1730
+ }
1731
+ };
1862
1732
  }
1863
1733
  /**
1864
1734
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1886,7 +1756,6 @@ var Workflow = class extends BaseResource {
1886
1756
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1887
1757
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1888
1758
  method: "POST",
1889
- stream: true,
1890
1759
  body: {
1891
1760
  step,
1892
1761
  resumeData,
@@ -1930,7 +1799,7 @@ var Workflow = class extends BaseResource {
1930
1799
  }
1931
1800
  );
1932
1801
  if (!response.ok) {
1933
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1802
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1934
1803
  }
1935
1804
  if (!response.body) {
1936
1805
  throw new Error("Response body is null");
@@ -1942,7 +1811,54 @@ var Workflow = class extends BaseResource {
1942
1811
  async transform(chunk, controller) {
1943
1812
  try {
1944
1813
  const decoded = new TextDecoder().decode(chunk);
1945
- const chunks = decoded.split(RECORD_SEPARATOR2);
1814
+ const chunks = decoded.split(RECORD_SEPARATOR);
1815
+ for (const chunk2 of chunks) {
1816
+ if (chunk2) {
1817
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1818
+ try {
1819
+ const parsedChunk = JSON.parse(newChunk);
1820
+ controller.enqueue(parsedChunk);
1821
+ failedChunk = void 0;
1822
+ } catch {
1823
+ failedChunk = newChunk;
1824
+ }
1825
+ }
1826
+ }
1827
+ } catch {
1828
+ }
1829
+ }
1830
+ });
1831
+ return response.body.pipeThrough(transformStream);
1832
+ }
1833
+ /**
1834
+ * Observes workflow stream for a workflow run
1835
+ * @param params - Object containing the runId
1836
+ * @returns Promise containing the workflow execution results
1837
+ */
1838
+ async observeStream(params) {
1839
+ const searchParams = new URLSearchParams();
1840
+ searchParams.set("runId", params.runId);
1841
+ const response = await this.request(
1842
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1843
+ {
1844
+ method: "POST",
1845
+ stream: true
1846
+ }
1847
+ );
1848
+ if (!response.ok) {
1849
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1850
+ }
1851
+ if (!response.body) {
1852
+ throw new Error("Response body is null");
1853
+ }
1854
+ let failedChunk = void 0;
1855
+ const transformStream = new TransformStream({
1856
+ start() {
1857
+ },
1858
+ async transform(chunk, controller) {
1859
+ try {
1860
+ const decoded = new TextDecoder().decode(chunk);
1861
+ const chunks = decoded.split(RECORD_SEPARATOR);
1946
1862
  for (const chunk2 of chunks) {
1947
1863
  if (chunk2) {
1948
1864
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1976,7 +1892,7 @@ var Workflow = class extends BaseResource {
1976
1892
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1977
1893
  {
1978
1894
  method: "POST",
1979
- body: { inputData: params.inputData, runtimeContext },
1895
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1980
1896
  stream: true
1981
1897
  }
1982
1898
  );
@@ -1993,7 +1909,7 @@ var Workflow = class extends BaseResource {
1993
1909
  async transform(chunk, controller) {
1994
1910
  try {
1995
1911
  const decoded = new TextDecoder().decode(chunk);
1996
- const chunks = decoded.split(RECORD_SEPARATOR2);
1912
+ const chunks = decoded.split(RECORD_SEPARATOR);
1997
1913
  for (const chunk2 of chunks) {
1998
1914
  if (chunk2) {
1999
1915
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2028,6 +1944,22 @@ var Workflow = class extends BaseResource {
2028
1944
  }
2029
1945
  });
2030
1946
  }
1947
+ /**
1948
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1949
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1950
+ * @returns Promise containing the workflow resume results
1951
+ */
1952
+ resumeStreamVNext(params) {
1953
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1954
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1955
+ method: "POST",
1956
+ body: {
1957
+ step: params.step,
1958
+ resumeData: params.resumeData,
1959
+ runtimeContext
1960
+ }
1961
+ });
1962
+ }
2031
1963
  /**
2032
1964
  * Watches workflow transitions in real-time
2033
1965
  * @param runId - Optional run ID to filter the watch stream
@@ -2064,7 +1996,7 @@ var Workflow = class extends BaseResource {
2064
1996
  async start(controller) {
2065
1997
  try {
2066
1998
  for await (const record of records) {
2067
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1999
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2068
2000
  controller.enqueue(encoder.encode(json));
2069
2001
  }
2070
2002
  controller.close();
@@ -2162,10 +2094,11 @@ var MCPTool = class extends BaseResource {
2162
2094
  }
2163
2095
  /**
2164
2096
  * Retrieves details about this specific tool from the MCP server.
2097
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2165
2098
  * @returns Promise containing the tool's information (name, description, schema).
2166
2099
  */
2167
- details() {
2168
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2100
+ details(runtimeContext) {
2101
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2169
2102
  }
2170
2103
  /**
2171
2104
  * Executes this specific tool on the MCP server.
@@ -2186,7 +2119,7 @@ var MCPTool = class extends BaseResource {
2186
2119
  };
2187
2120
 
2188
2121
  // src/resources/agent-builder.ts
2189
- var RECORD_SEPARATOR3 = "";
2122
+ var RECORD_SEPARATOR2 = "";
2190
2123
  var AgentBuilder = class extends BaseResource {
2191
2124
  constructor(options, actionId) {
2192
2125
  super(options);
@@ -2221,11 +2154,20 @@ var AgentBuilder = class extends BaseResource {
2221
2154
  };
2222
2155
  }
2223
2156
  }
2157
+ /**
2158
+ * @deprecated Use createRunAsync() instead.
2159
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2160
+ */
2161
+ async createRun(_params) {
2162
+ throw new Error(
2163
+ "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."
2164
+ );
2165
+ }
2224
2166
  /**
2225
2167
  * Creates a new agent builder action run and returns the runId.
2226
2168
  * This calls `/api/agent-builder/:actionId/create-run`.
2227
2169
  */
2228
- async createRun(params) {
2170
+ async createRunAsync(params) {
2229
2171
  const searchParams = new URLSearchParams();
2230
2172
  if (!!params?.runId) {
2231
2173
  searchParams.set("runId", params.runId);
@@ -2235,14 +2177,6 @@ var AgentBuilder = class extends BaseResource {
2235
2177
  method: "POST"
2236
2178
  });
2237
2179
  }
2238
- /**
2239
- * Creates a new workflow run (alias for createRun)
2240
- * @param params - Optional object containing the optional runId
2241
- * @returns Promise containing the runId of the created run
2242
- */
2243
- createRunAsync(params) {
2244
- return this.createRun(params);
2245
- }
2246
2180
  /**
2247
2181
  * Starts agent builder action asynchronously and waits for completion.
2248
2182
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2325,7 +2259,7 @@ var AgentBuilder = class extends BaseResource {
2325
2259
  if (done && !value) continue;
2326
2260
  try {
2327
2261
  const decoded = value ? new TextDecoder().decode(value) : "";
2328
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2262
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2329
2263
  buffer = chunks.pop() || "";
2330
2264
  for (const chunk of chunks) {
2331
2265
  if (chunk) {
@@ -2382,7 +2316,7 @@ var AgentBuilder = class extends BaseResource {
2382
2316
  async transform(chunk, controller) {
2383
2317
  try {
2384
2318
  const decoded = new TextDecoder().decode(chunk);
2385
- const chunks = decoded.split(RECORD_SEPARATOR3);
2319
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2386
2320
  for (const chunk2 of chunks) {
2387
2321
  if (chunk2) {
2388
2322
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2431,7 +2365,7 @@ var AgentBuilder = class extends BaseResource {
2431
2365
  async transform(chunk, controller) {
2432
2366
  try {
2433
2367
  const decoded = new TextDecoder().decode(chunk);
2434
- const chunks = decoded.split(RECORD_SEPARATOR3);
2368
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2435
2369
  for (const chunk2 of chunks) {
2436
2370
  if (chunk2) {
2437
2371
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2602,6 +2536,31 @@ var Observability = class extends BaseResource {
2602
2536
  const queryString = searchParams.toString();
2603
2537
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2604
2538
  }
2539
+ /**
2540
+ * Retrieves scores by trace ID and span ID
2541
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2542
+ * @returns Promise containing scores and pagination info
2543
+ */
2544
+ getScoresBySpan(params) {
2545
+ const { traceId, spanId, page, perPage } = params;
2546
+ const searchParams = new URLSearchParams();
2547
+ if (page !== void 0) {
2548
+ searchParams.set("page", String(page));
2549
+ }
2550
+ if (perPage !== void 0) {
2551
+ searchParams.set("perPage", String(perPage));
2552
+ }
2553
+ const queryString = searchParams.toString();
2554
+ return this.request(
2555
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2556
+ );
2557
+ }
2558
+ score(params) {
2559
+ return this.request(`/api/observability/traces/score`, {
2560
+ method: "POST",
2561
+ body: { ...params }
2562
+ });
2563
+ }
2605
2564
  };
2606
2565
 
2607
2566
  // src/resources/network-memory-thread.ts
@@ -2668,7 +2627,7 @@ var NetworkMemoryThread = class extends BaseResource {
2668
2627
  };
2669
2628
 
2670
2629
  // src/resources/vNextNetwork.ts
2671
- var RECORD_SEPARATOR4 = "";
2630
+ var RECORD_SEPARATOR3 = "";
2672
2631
  var VNextNetwork = class extends BaseResource {
2673
2632
  constructor(options, networkId) {
2674
2633
  super(options);
@@ -2676,10 +2635,11 @@ var VNextNetwork = class extends BaseResource {
2676
2635
  }
2677
2636
  /**
2678
2637
  * Retrieves details about the network
2638
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2679
2639
  * @returns Promise containing vNext network details
2680
2640
  */
2681
- details() {
2682
- return this.request(`/api/networks/v-next/${this.networkId}`);
2641
+ details(runtimeContext) {
2642
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2683
2643
  }
2684
2644
  /**
2685
2645
  * Generates a response from the v-next network
@@ -2720,7 +2680,7 @@ var VNextNetwork = class extends BaseResource {
2720
2680
  if (done && !value) continue;
2721
2681
  try {
2722
2682
  const decoded = value ? new TextDecoder().decode(value) : "";
2723
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2683
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2724
2684
  buffer = chunks.pop() || "";
2725
2685
  for (const chunk of chunks) {
2726
2686
  if (chunk) {
@@ -2814,10 +2774,17 @@ var MastraClient = class extends BaseResource {
2814
2774
  }
2815
2775
  /**
2816
2776
  * Retrieves all available agents
2777
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2817
2778
  * @returns Promise containing map of agent IDs to agent details
2818
2779
  */
2819
- getAgents() {
2820
- return this.request("/api/agents");
2780
+ getAgents(runtimeContext) {
2781
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2782
+ const searchParams = new URLSearchParams();
2783
+ if (runtimeContextParam) {
2784
+ searchParams.set("runtimeContext", runtimeContextParam);
2785
+ }
2786
+ const queryString = searchParams.toString();
2787
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2821
2788
  }
2822
2789
  /**
2823
2790
  * Gets an agent instance by ID
@@ -2835,6 +2802,14 @@ var MastraClient = class extends BaseResource {
2835
2802
  getMemoryThreads(params) {
2836
2803
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2837
2804
  }
2805
+ /**
2806
+ * Retrieves memory config for a resource
2807
+ * @param params - Parameters containing the resource ID
2808
+ * @returns Promise containing array of memory threads
2809
+ */
2810
+ getMemoryConfig(params) {
2811
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2812
+ }
2838
2813
  /**
2839
2814
  * Creates a new memory thread
2840
2815
  * @param params - Parameters for creating the memory thread
@@ -2851,6 +2826,24 @@ var MastraClient = class extends BaseResource {
2851
2826
  getMemoryThread(threadId, agentId) {
2852
2827
  return new MemoryThread(this.options, threadId, agentId);
2853
2828
  }
2829
+ getThreadMessages(threadId, opts = {}) {
2830
+ let url = "";
2831
+ if (opts.agentId) {
2832
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2833
+ } else if (opts.networkId) {
2834
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2835
+ }
2836
+ return this.request(url);
2837
+ }
2838
+ deleteThread(threadId, opts = {}) {
2839
+ let url = "";
2840
+ if (opts.agentId) {
2841
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2842
+ } else if (opts.networkId) {
2843
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2844
+ }
2845
+ return this.request(url, { method: "DELETE" });
2846
+ }
2854
2847
  /**
2855
2848
  * Saves messages to memory
2856
2849
  * @param params - Parameters containing messages to save
@@ -2913,10 +2906,17 @@ var MastraClient = class extends BaseResource {
2913
2906
  }
2914
2907
  /**
2915
2908
  * Retrieves all available tools
2909
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2916
2910
  * @returns Promise containing map of tool IDs to tool details
2917
2911
  */
2918
- getTools() {
2919
- return this.request("/api/tools");
2912
+ getTools(runtimeContext) {
2913
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2914
+ const searchParams = new URLSearchParams();
2915
+ if (runtimeContextParam) {
2916
+ searchParams.set("runtimeContext", runtimeContextParam);
2917
+ }
2918
+ const queryString = searchParams.toString();
2919
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2920
2920
  }
2921
2921
  /**
2922
2922
  * Gets a tool instance by ID
@@ -2926,27 +2926,19 @@ var MastraClient = class extends BaseResource {
2926
2926
  getTool(toolId) {
2927
2927
  return new Tool(this.options, toolId);
2928
2928
  }
2929
- /**
2930
- * Retrieves all available legacy workflows
2931
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2932
- */
2933
- getLegacyWorkflows() {
2934
- return this.request("/api/workflows/legacy");
2935
- }
2936
- /**
2937
- * Gets a legacy workflow instance by ID
2938
- * @param workflowId - ID of the legacy workflow to retrieve
2939
- * @returns Legacy Workflow instance
2940
- */
2941
- getLegacyWorkflow(workflowId) {
2942
- return new LegacyWorkflow(this.options, workflowId);
2943
- }
2944
2929
  /**
2945
2930
  * Retrieves all available workflows
2931
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2946
2932
  * @returns Promise containing map of workflow IDs to workflow details
2947
2933
  */
2948
- getWorkflows() {
2949
- return this.request("/api/workflows");
2934
+ getWorkflows(runtimeContext) {
2935
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2936
+ const searchParams = new URLSearchParams();
2937
+ if (runtimeContextParam) {
2938
+ searchParams.set("runtimeContext", runtimeContextParam);
2939
+ }
2940
+ const queryString = searchParams.toString();
2941
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2950
2942
  }
2951
2943
  /**
2952
2944
  * Gets a workflow instance by ID
@@ -3114,13 +3106,6 @@ var MastraClient = class extends BaseResource {
3114
3106
  return this.request(`/api/telemetry`);
3115
3107
  }
3116
3108
  }
3117
- /**
3118
- * Retrieves all available networks
3119
- * @returns Promise containing map of network IDs to network details
3120
- */
3121
- getNetworks() {
3122
- return this.request("/api/networks");
3123
- }
3124
3109
  /**
3125
3110
  * Retrieves all available vNext networks
3126
3111
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3128,14 +3113,6 @@ var MastraClient = class extends BaseResource {
3128
3113
  getVNextNetworks() {
3129
3114
  return this.request("/api/networks/v-next");
3130
3115
  }
3131
- /**
3132
- * Gets a network instance by ID
3133
- * @param networkId - ID of the network to retrieve
3134
- * @returns Network instance
3135
- */
3136
- getNetwork(networkId) {
3137
- return new Network(this.options, networkId);
3138
- }
3139
3116
  /**
3140
3117
  * Gets a vNext network instance by ID
3141
3118
  * @param networkId - ID of the vNext network to retrieve
@@ -3248,7 +3225,7 @@ var MastraClient = class extends BaseResource {
3248
3225
  * @returns Promise containing the scorer
3249
3226
  */
3250
3227
  getScorer(scorerId) {
3251
- return this.request(`/api/scores/scorers/${scorerId}`);
3228
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3252
3229
  }
3253
3230
  getScoresByScorerId(params) {
3254
3231
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3266,7 +3243,7 @@ var MastraClient = class extends BaseResource {
3266
3243
  searchParams.set("perPage", String(perPage));
3267
3244
  }
3268
3245
  const queryString = searchParams.toString();
3269
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3246
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3270
3247
  }
3271
3248
  /**
3272
3249
  * Retrieves scores by run ID
@@ -3283,7 +3260,7 @@ var MastraClient = class extends BaseResource {
3283
3260
  searchParams.set("perPage", String(perPage));
3284
3261
  }
3285
3262
  const queryString = searchParams.toString();
3286
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3263
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3287
3264
  }
3288
3265
  /**
3289
3266
  * Retrieves scores by entity ID and type
@@ -3300,7 +3277,9 @@ var MastraClient = class extends BaseResource {
3300
3277
  searchParams.set("perPage", String(perPage));
3301
3278
  }
3302
3279
  const queryString = searchParams.toString();
3303
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3280
+ return this.request(
3281
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3282
+ );
3304
3283
  }
3305
3284
  /**
3306
3285
  * Saves a score
@@ -3326,8 +3305,35 @@ var MastraClient = class extends BaseResource {
3326
3305
  getAITraces(params) {
3327
3306
  return this.observability.getTraces(params);
3328
3307
  }
3308
+ getScoresBySpan(params) {
3309
+ return this.observability.getScoresBySpan(params);
3310
+ }
3311
+ score(params) {
3312
+ return this.observability.score(params);
3313
+ }
3329
3314
  };
3330
3315
 
3316
+ // src/tools.ts
3317
+ var ClientTool = class {
3318
+ id;
3319
+ description;
3320
+ inputSchema;
3321
+ outputSchema;
3322
+ execute;
3323
+ constructor(opts) {
3324
+ this.id = opts.id;
3325
+ this.description = opts.description;
3326
+ this.inputSchema = opts.inputSchema;
3327
+ this.outputSchema = opts.outputSchema;
3328
+ this.execute = opts.execute;
3329
+ }
3330
+ };
3331
+ function createTool(opts) {
3332
+ return new ClientTool(opts);
3333
+ }
3334
+
3335
+ exports.ClientTool = ClientTool;
3331
3336
  exports.MastraClient = MastraClient;
3337
+ exports.createTool = createTool;
3332
3338
  //# sourceMappingURL=index.cjs.map
3333
3339
  //# sourceMappingURL=index.cjs.map