@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.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
  }
@@ -77,7 +91,7 @@ async function sharedProcessMastraStream({
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 {
@@ -199,7 +213,9 @@ async function executeToolCallAndRespond({
199
213
  resourceId,
200
214
  threadId,
201
215
  runtimeContext,
202
- tracingContext: { currentSpan: void 0 }
216
+ tracingContext: { currentSpan: void 0 },
217
+ suspend: async () => {
218
+ }
203
219
  },
204
220
  {
205
221
  messages: response.messages,
@@ -207,11 +223,7 @@ async function executeToolCallAndRespond({
207
223
  }
208
224
  );
209
225
  const updatedMessages = [
210
- {
211
- role: "user",
212
- content: params.messages
213
- },
214
- ...response.response.messages,
226
+ ...response.response.messages || [],
215
227
  {
216
228
  role: "tool",
217
229
  content: [
@@ -273,17 +285,21 @@ var AgentVoice = class extends BaseResource {
273
285
  }
274
286
  /**
275
287
  * Get available speakers for the agent's voice provider
288
+ * @param runtimeContext - Optional runtime context to pass as query parameter
289
+ * @param runtimeContext - Optional runtime context to pass as query parameter
276
290
  * @returns Promise containing list of available speakers
277
291
  */
278
- getSpeakers() {
279
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
292
+ getSpeakers(runtimeContext) {
293
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
280
294
  }
281
295
  /**
282
296
  * Get the listener configuration for the agent's voice provider
297
+ * @param runtimeContext - Optional runtime context to pass as query parameter
298
+ * @param runtimeContext - Optional runtime context to pass as query parameter
283
299
  * @returns Promise containing a check if the agent has listening capabilities
284
300
  */
285
- getListener() {
286
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
301
+ getListener(runtimeContext) {
302
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
287
303
  }
288
304
  };
289
305
  var Agent = class extends BaseResource {
@@ -295,14 +311,15 @@ var Agent = class extends BaseResource {
295
311
  voice;
296
312
  /**
297
313
  * Retrieves details about the agent
314
+ * @param runtimeContext - Optional runtime context to pass as query parameter
298
315
  * @returns Promise containing agent details including model and instructions
299
316
  */
300
- details() {
301
- return this.request(`/api/agents/${this.agentId}`);
317
+ details(runtimeContext) {
318
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
302
319
  }
303
320
  async generate(params) {
304
321
  console.warn(
305
- "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."
322
+ "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."
306
323
  );
307
324
  return this.generateLegacy(params);
308
325
  }
@@ -337,7 +354,9 @@ var Agent = class extends BaseResource {
337
354
  resourceId,
338
355
  threadId,
339
356
  runtimeContext,
340
- tracingContext: { currentSpan: void 0 }
357
+ tracingContext: { currentSpan: void 0 },
358
+ suspend: async () => {
359
+ }
341
360
  },
342
361
  {
343
362
  messages: response.messages,
@@ -345,10 +364,6 @@ var Agent = class extends BaseResource {
345
364
  }
346
365
  );
347
366
  const updatedMessages = [
348
- {
349
- role: "user",
350
- content: params.messages
351
- },
352
367
  ...response.response.messages,
353
368
  {
354
369
  role: "tool",
@@ -371,7 +386,16 @@ var Agent = class extends BaseResource {
371
386
  }
372
387
  return response;
373
388
  }
374
- async generateVNext(params) {
389
+ async generateVNext(messagesOrParams, options) {
390
+ let params;
391
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
392
+ params = messagesOrParams;
393
+ } else {
394
+ params = {
395
+ messages: messagesOrParams,
396
+ ...options
397
+ };
398
+ }
375
399
  const processedParams = {
376
400
  ...params,
377
401
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -672,7 +696,7 @@ var Agent = class extends BaseResource {
672
696
  */
673
697
  async stream(params) {
674
698
  console.warn(
675
- "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."
699
+ "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."
676
700
  );
677
701
  return this.streamLegacy(params);
678
702
  }
@@ -1021,7 +1045,9 @@ var Agent = class extends BaseResource {
1021
1045
  threadId: processedParams.threadId,
1022
1046
  runtimeContext: processedParams.runtimeContext,
1023
1047
  // TODO: Pass proper tracing context when client-js supports tracing
1024
- tracingContext: { currentSpan: void 0 }
1048
+ tracingContext: { currentSpan: void 0 },
1049
+ suspend: async () => {
1050
+ }
1025
1051
  },
1026
1052
  {
1027
1053
  messages: response.messages,
@@ -1047,9 +1073,7 @@ var Agent = class extends BaseResource {
1047
1073
  toolInvocation.state = "result";
1048
1074
  toolInvocation.result = result;
1049
1075
  }
1050
- const originalMessages = processedParams.messages;
1051
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1052
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1076
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1053
1077
  this.processStreamResponse_vNext(
1054
1078
  {
1055
1079
  ...processedParams,
@@ -1100,7 +1124,16 @@ var Agent = class extends BaseResource {
1100
1124
  };
1101
1125
  return streamResponse;
1102
1126
  }
1103
- async streamVNext(params) {
1127
+ async streamVNext(messagesOrParams, options) {
1128
+ let params;
1129
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1130
+ params = messagesOrParams;
1131
+ } else {
1132
+ params = {
1133
+ messages: messagesOrParams,
1134
+ ...options
1135
+ };
1136
+ }
1104
1137
  const processedParams = {
1105
1138
  ...params,
1106
1139
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1176,7 +1209,9 @@ var Agent = class extends BaseResource {
1176
1209
  threadId: processedParams.threadId,
1177
1210
  runtimeContext: processedParams.runtimeContext,
1178
1211
  // TODO: Pass proper tracing context when client-js supports tracing
1179
- tracingContext: { currentSpan: void 0 }
1212
+ tracingContext: { currentSpan: void 0 },
1213
+ suspend: async () => {
1214
+ }
1180
1215
  },
1181
1216
  {
1182
1217
  messages: response.messages,
@@ -1214,12 +1249,10 @@ var Agent = class extends BaseResource {
1214
1249
  } finally {
1215
1250
  writer.releaseLock();
1216
1251
  }
1217
- const originalMessages = processedParams.messages;
1218
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1219
1252
  this.processStreamResponse(
1220
1253
  {
1221
1254
  ...processedParams,
1222
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1255
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1223
1256
  },
1224
1257
  writable
1225
1258
  ).catch((error) => {
@@ -1245,10 +1278,11 @@ var Agent = class extends BaseResource {
1245
1278
  /**
1246
1279
  * Gets details about a specific tool available to the agent
1247
1280
  * @param toolId - ID of the tool to retrieve
1281
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1248
1282
  * @returns Promise containing tool details
1249
1283
  */
1250
- getTool(toolId) {
1251
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1284
+ getTool(toolId, runtimeContext) {
1285
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1252
1286
  }
1253
1287
  /**
1254
1288
  * Executes a tool for the agent
@@ -1259,7 +1293,7 @@ var Agent = class extends BaseResource {
1259
1293
  executeTool(toolId, params) {
1260
1294
  const body = {
1261
1295
  data: params.data,
1262
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1296
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1263
1297
  };
1264
1298
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1265
1299
  method: "POST",
@@ -1268,17 +1302,19 @@ var Agent = class extends BaseResource {
1268
1302
  }
1269
1303
  /**
1270
1304
  * Retrieves evaluation results for the agent
1305
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1271
1306
  * @returns Promise containing agent evaluations
1272
1307
  */
1273
- evals() {
1274
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1308
+ evals(runtimeContext) {
1309
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1275
1310
  }
1276
1311
  /**
1277
1312
  * Retrieves live evaluation results for the agent
1313
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1278
1314
  * @returns Promise containing live agent evaluations
1279
1315
  */
1280
- liveEvals() {
1281
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1316
+ liveEvals(runtimeContext) {
1317
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1282
1318
  }
1283
1319
  /**
1284
1320
  * Updates the model for the agent
@@ -1291,61 +1327,27 @@ var Agent = class extends BaseResource {
1291
1327
  body: params
1292
1328
  });
1293
1329
  }
1294
- };
1295
- var Network = class extends BaseResource {
1296
- constructor(options, networkId) {
1297
- super(options);
1298
- this.networkId = networkId;
1299
- }
1300
1330
  /**
1301
- * Retrieves details about the network
1302
- * @returns Promise containing network details
1303
- */
1304
- details() {
1305
- return this.request(`/api/networks/${this.networkId}`);
1306
- }
1307
- /**
1308
- * Generates a response from the agent
1309
- * @param params - Generation parameters including prompt
1310
- * @returns Promise containing the generated response
1331
+ * Updates the model for the agent in the model list
1332
+ * @param params - Parameters for updating the model
1333
+ * @returns Promise containing the updated model
1311
1334
  */
1312
- generate(params) {
1313
- const processedParams = {
1314
- ...params,
1315
- output: zodToJsonSchema(params.output),
1316
- experimental_output: zodToJsonSchema(params.experimental_output)
1317
- };
1318
- return this.request(`/api/networks/${this.networkId}/generate`, {
1335
+ updateModelInModelList({ modelConfigId, ...params }) {
1336
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1319
1337
  method: "POST",
1320
- body: processedParams
1338
+ body: params
1321
1339
  });
1322
1340
  }
1323
1341
  /**
1324
- * Streams a response from the agent
1325
- * @param params - Stream parameters including prompt
1326
- * @returns Promise containing the enhanced Response object with processDataStream method
1342
+ * Reorders the models for the agent
1343
+ * @param params - Parameters for reordering the model list
1344
+ * @returns Promise containing the updated model list
1327
1345
  */
1328
- async stream(params) {
1329
- const processedParams = {
1330
- ...params,
1331
- output: zodToJsonSchema(params.output),
1332
- experimental_output: zodToJsonSchema(params.experimental_output)
1333
- };
1334
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1346
+ reorderModelList(params) {
1347
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1335
1348
  method: "POST",
1336
- body: processedParams,
1337
- stream: true
1349
+ body: params
1338
1350
  });
1339
- if (!response.body) {
1340
- throw new Error("No response body");
1341
- }
1342
- response.processDataStream = async (options = {}) => {
1343
- await processDataStream({
1344
- stream: response.body,
1345
- ...options
1346
- });
1347
- };
1348
- return response;
1349
1351
  }
1350
1352
  };
1351
1353
 
@@ -1436,10 +1438,13 @@ var Vector = class extends BaseResource {
1436
1438
  /**
1437
1439
  * Retrieves details about a specific vector index
1438
1440
  * @param indexName - Name of the index to get details for
1441
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1439
1442
  * @returns Promise containing vector index details
1440
1443
  */
1441
- details(indexName) {
1442
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1444
+ details(indexName, runtimeContext) {
1445
+ return this.request(
1446
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1447
+ );
1443
1448
  }
1444
1449
  /**
1445
1450
  * Deletes a vector index
@@ -1453,10 +1458,11 @@ var Vector = class extends BaseResource {
1453
1458
  }
1454
1459
  /**
1455
1460
  * Retrieves a list of all available indexes
1461
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1456
1462
  * @returns Promise containing array of index names
1457
1463
  */
1458
- getIndexes() {
1459
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1464
+ getIndexes(runtimeContext) {
1465
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1460
1466
  }
1461
1467
  /**
1462
1468
  * Creates a new vector index
@@ -1493,187 +1499,6 @@ var Vector = class extends BaseResource {
1493
1499
  }
1494
1500
  };
1495
1501
 
1496
- // src/resources/legacy-workflow.ts
1497
- var RECORD_SEPARATOR = "";
1498
- var LegacyWorkflow = class extends BaseResource {
1499
- constructor(options, workflowId) {
1500
- super(options);
1501
- this.workflowId = workflowId;
1502
- }
1503
- /**
1504
- * Retrieves details about the legacy workflow
1505
- * @returns Promise containing legacy workflow details including steps and graphs
1506
- */
1507
- details() {
1508
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1509
- }
1510
- /**
1511
- * Retrieves all runs for a legacy workflow
1512
- * @param params - Parameters for filtering runs
1513
- * @returns Promise containing legacy workflow runs array
1514
- */
1515
- runs(params) {
1516
- const searchParams = new URLSearchParams();
1517
- if (params?.fromDate) {
1518
- searchParams.set("fromDate", params.fromDate.toISOString());
1519
- }
1520
- if (params?.toDate) {
1521
- searchParams.set("toDate", params.toDate.toISOString());
1522
- }
1523
- if (params?.limit) {
1524
- searchParams.set("limit", String(params.limit));
1525
- }
1526
- if (params?.offset) {
1527
- searchParams.set("offset", String(params.offset));
1528
- }
1529
- if (params?.resourceId) {
1530
- searchParams.set("resourceId", params.resourceId);
1531
- }
1532
- if (searchParams.size) {
1533
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1534
- } else {
1535
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1536
- }
1537
- }
1538
- /**
1539
- * Creates a new legacy workflow run
1540
- * @returns Promise containing the generated run ID
1541
- */
1542
- createRun(params) {
1543
- const searchParams = new URLSearchParams();
1544
- if (!!params?.runId) {
1545
- searchParams.set("runId", params.runId);
1546
- }
1547
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1548
- method: "POST"
1549
- });
1550
- }
1551
- /**
1552
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1553
- * @param params - Object containing the runId and triggerData
1554
- * @returns Promise containing success message
1555
- */
1556
- start(params) {
1557
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1558
- method: "POST",
1559
- body: params?.triggerData
1560
- });
1561
- }
1562
- /**
1563
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1564
- * @param stepId - ID of the step to resume
1565
- * @param runId - ID of the legacy workflow run
1566
- * @param context - Context to resume the legacy workflow with
1567
- * @returns Promise containing the legacy workflow resume results
1568
- */
1569
- resume({
1570
- stepId,
1571
- runId,
1572
- context
1573
- }) {
1574
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1575
- method: "POST",
1576
- body: {
1577
- stepId,
1578
- context
1579
- }
1580
- });
1581
- }
1582
- /**
1583
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1584
- * @param params - Object containing the optional runId and triggerData
1585
- * @returns Promise containing the workflow execution results
1586
- */
1587
- startAsync(params) {
1588
- const searchParams = new URLSearchParams();
1589
- if (!!params?.runId) {
1590
- searchParams.set("runId", params.runId);
1591
- }
1592
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1593
- method: "POST",
1594
- body: params?.triggerData
1595
- });
1596
- }
1597
- /**
1598
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1599
- * @param params - Object containing the runId, stepId, and context
1600
- * @returns Promise containing the workflow resume results
1601
- */
1602
- resumeAsync(params) {
1603
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1604
- method: "POST",
1605
- body: {
1606
- stepId: params.stepId,
1607
- context: params.context
1608
- }
1609
- });
1610
- }
1611
- /**
1612
- * Creates an async generator that processes a readable stream and yields records
1613
- * separated by the Record Separator character (\x1E)
1614
- *
1615
- * @param stream - The readable stream to process
1616
- * @returns An async generator that yields parsed records
1617
- */
1618
- async *streamProcessor(stream) {
1619
- const reader = stream.getReader();
1620
- let doneReading = false;
1621
- let buffer = "";
1622
- try {
1623
- while (!doneReading) {
1624
- const { done, value } = await reader.read();
1625
- doneReading = done;
1626
- if (done && !value) continue;
1627
- try {
1628
- const decoded = value ? new TextDecoder().decode(value) : "";
1629
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1630
- buffer = chunks.pop() || "";
1631
- for (const chunk of chunks) {
1632
- if (chunk) {
1633
- if (typeof chunk === "string") {
1634
- try {
1635
- const parsedChunk = JSON.parse(chunk);
1636
- yield parsedChunk;
1637
- } catch {
1638
- }
1639
- }
1640
- }
1641
- }
1642
- } catch {
1643
- }
1644
- }
1645
- if (buffer) {
1646
- try {
1647
- yield JSON.parse(buffer);
1648
- } catch {
1649
- }
1650
- }
1651
- } finally {
1652
- reader.cancel().catch(() => {
1653
- });
1654
- }
1655
- }
1656
- /**
1657
- * Watches legacy workflow transitions in real-time
1658
- * @param runId - Optional run ID to filter the watch stream
1659
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1660
- */
1661
- async watch({ runId }, onRecord) {
1662
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1663
- stream: true
1664
- });
1665
- if (!response.ok) {
1666
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1667
- }
1668
- if (!response.body) {
1669
- throw new Error("Response body is null");
1670
- }
1671
- for await (const record of this.streamProcessor(response.body)) {
1672
- onRecord(record);
1673
- }
1674
- }
1675
- };
1676
-
1677
1502
  // src/resources/tool.ts
1678
1503
  var Tool = class extends BaseResource {
1679
1504
  constructor(options, toolId) {
@@ -1682,10 +1507,11 @@ var Tool = class extends BaseResource {
1682
1507
  }
1683
1508
  /**
1684
1509
  * Retrieves details about the tool
1510
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1685
1511
  * @returns Promise containing tool details including description and schemas
1686
1512
  */
1687
- details() {
1688
- return this.request(`/api/tools/${this.toolId}`);
1513
+ details(runtimeContext) {
1514
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1689
1515
  }
1690
1516
  /**
1691
1517
  * Executes the tool with the provided parameters
@@ -1709,7 +1535,7 @@ var Tool = class extends BaseResource {
1709
1535
  };
1710
1536
 
1711
1537
  // src/resources/workflow.ts
1712
- var RECORD_SEPARATOR2 = "";
1538
+ var RECORD_SEPARATOR = "";
1713
1539
  var Workflow = class extends BaseResource {
1714
1540
  constructor(options, workflowId) {
1715
1541
  super(options);
@@ -1733,7 +1559,7 @@ var Workflow = class extends BaseResource {
1733
1559
  if (done && !value) continue;
1734
1560
  try {
1735
1561
  const decoded = value ? new TextDecoder().decode(value) : "";
1736
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1562
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1737
1563
  buffer = chunks.pop() || "";
1738
1564
  for (const chunk of chunks) {
1739
1565
  if (chunk) {
@@ -1762,17 +1588,20 @@ var Workflow = class extends BaseResource {
1762
1588
  }
1763
1589
  /**
1764
1590
  * Retrieves details about the workflow
1591
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1765
1592
  * @returns Promise containing workflow details including steps and graphs
1766
1593
  */
1767
- details() {
1768
- return this.request(`/api/workflows/${this.workflowId}`);
1594
+ details(runtimeContext) {
1595
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1769
1596
  }
1770
1597
  /**
1771
1598
  * Retrieves all runs for a workflow
1772
1599
  * @param params - Parameters for filtering runs
1600
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1773
1601
  * @returns Promise containing workflow runs array
1774
1602
  */
1775
- runs(params) {
1603
+ runs(params, runtimeContext) {
1604
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1776
1605
  const searchParams = new URLSearchParams();
1777
1606
  if (params?.fromDate) {
1778
1607
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1789,6 +1618,9 @@ var Workflow = class extends BaseResource {
1789
1618
  if (params?.resourceId) {
1790
1619
  searchParams.set("resourceId", params.resourceId);
1791
1620
  }
1621
+ if (runtimeContextParam) {
1622
+ searchParams.set("runtimeContext", runtimeContextParam);
1623
+ }
1792
1624
  if (searchParams.size) {
1793
1625
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1794
1626
  } else {
@@ -1798,18 +1630,22 @@ var Workflow = class extends BaseResource {
1798
1630
  /**
1799
1631
  * Retrieves a specific workflow run by its ID
1800
1632
  * @param runId - The ID of the workflow run to retrieve
1633
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1801
1634
  * @returns Promise containing the workflow run details
1802
1635
  */
1803
- runById(runId) {
1804
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1636
+ runById(runId, runtimeContext) {
1637
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1805
1638
  }
1806
1639
  /**
1807
1640
  * Retrieves the execution result for a specific workflow run by its ID
1808
1641
  * @param runId - The ID of the workflow run to retrieve the execution result for
1642
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1809
1643
  * @returns Promise containing the workflow run execution result
1810
1644
  */
1811
- runExecutionResult(runId) {
1812
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1645
+ runExecutionResult(runId, runtimeContext) {
1646
+ return this.request(
1647
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1648
+ );
1813
1649
  }
1814
1650
  /**
1815
1651
  * Cancels a specific workflow run by its ID
@@ -1832,27 +1668,61 @@ var Workflow = class extends BaseResource {
1832
1668
  body: { event: params.event, data: params.data }
1833
1669
  });
1834
1670
  }
1671
+ /**
1672
+ * @deprecated Use createRunAsync() instead.
1673
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1674
+ */
1675
+ async createRun(_params) {
1676
+ throw new Error(
1677
+ "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."
1678
+ );
1679
+ }
1835
1680
  /**
1836
1681
  * Creates a new workflow run
1837
1682
  * @param params - Optional object containing the optional runId
1838
- * @returns Promise containing the runId of the created run
1683
+ * @returns Promise containing the runId of the created run with methods to control execution
1839
1684
  */
1840
- createRun(params) {
1685
+ async createRunAsync(params) {
1841
1686
  const searchParams = new URLSearchParams();
1842
1687
  if (!!params?.runId) {
1843
1688
  searchParams.set("runId", params.runId);
1844
1689
  }
1845
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1846
- method: "POST"
1847
- });
1848
- }
1849
- /**
1850
- * Creates a new workflow run (alias for createRun)
1851
- * @param params - Optional object containing the optional runId
1852
- * @returns Promise containing the runId of the created run
1853
- */
1854
- createRunAsync(params) {
1855
- return this.createRun(params);
1690
+ const res = await this.request(
1691
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1692
+ {
1693
+ method: "POST"
1694
+ }
1695
+ );
1696
+ const runId = res.runId;
1697
+ return {
1698
+ runId,
1699
+ start: async (p) => {
1700
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1701
+ },
1702
+ startAsync: async (p) => {
1703
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1704
+ },
1705
+ watch: async (onRecord) => {
1706
+ return this.watch({ runId }, onRecord);
1707
+ },
1708
+ stream: async (p) => {
1709
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1710
+ },
1711
+ resume: async (p) => {
1712
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1713
+ },
1714
+ resumeAsync: async (p) => {
1715
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1716
+ },
1717
+ resumeStreamVNext: async (p) => {
1718
+ return this.resumeStreamVNext({
1719
+ runId,
1720
+ step: p.step,
1721
+ resumeData: p.resumeData,
1722
+ runtimeContext: p.runtimeContext
1723
+ });
1724
+ }
1725
+ };
1856
1726
  }
1857
1727
  /**
1858
1728
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1880,7 +1750,6 @@ var Workflow = class extends BaseResource {
1880
1750
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1881
1751
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1882
1752
  method: "POST",
1883
- stream: true,
1884
1753
  body: {
1885
1754
  step,
1886
1755
  resumeData,
@@ -1924,7 +1793,7 @@ var Workflow = class extends BaseResource {
1924
1793
  }
1925
1794
  );
1926
1795
  if (!response.ok) {
1927
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1796
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1928
1797
  }
1929
1798
  if (!response.body) {
1930
1799
  throw new Error("Response body is null");
@@ -1936,7 +1805,54 @@ var Workflow = class extends BaseResource {
1936
1805
  async transform(chunk, controller) {
1937
1806
  try {
1938
1807
  const decoded = new TextDecoder().decode(chunk);
1939
- const chunks = decoded.split(RECORD_SEPARATOR2);
1808
+ const chunks = decoded.split(RECORD_SEPARATOR);
1809
+ for (const chunk2 of chunks) {
1810
+ if (chunk2) {
1811
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1812
+ try {
1813
+ const parsedChunk = JSON.parse(newChunk);
1814
+ controller.enqueue(parsedChunk);
1815
+ failedChunk = void 0;
1816
+ } catch {
1817
+ failedChunk = newChunk;
1818
+ }
1819
+ }
1820
+ }
1821
+ } catch {
1822
+ }
1823
+ }
1824
+ });
1825
+ return response.body.pipeThrough(transformStream);
1826
+ }
1827
+ /**
1828
+ * Observes workflow stream for a workflow run
1829
+ * @param params - Object containing the runId
1830
+ * @returns Promise containing the workflow execution results
1831
+ */
1832
+ async observeStream(params) {
1833
+ const searchParams = new URLSearchParams();
1834
+ searchParams.set("runId", params.runId);
1835
+ const response = await this.request(
1836
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1837
+ {
1838
+ method: "POST",
1839
+ stream: true
1840
+ }
1841
+ );
1842
+ if (!response.ok) {
1843
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1844
+ }
1845
+ if (!response.body) {
1846
+ throw new Error("Response body is null");
1847
+ }
1848
+ let failedChunk = void 0;
1849
+ const transformStream = new TransformStream({
1850
+ start() {
1851
+ },
1852
+ async transform(chunk, controller) {
1853
+ try {
1854
+ const decoded = new TextDecoder().decode(chunk);
1855
+ const chunks = decoded.split(RECORD_SEPARATOR);
1940
1856
  for (const chunk2 of chunks) {
1941
1857
  if (chunk2) {
1942
1858
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1970,7 +1886,7 @@ var Workflow = class extends BaseResource {
1970
1886
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1971
1887
  {
1972
1888
  method: "POST",
1973
- body: { inputData: params.inputData, runtimeContext },
1889
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1974
1890
  stream: true
1975
1891
  }
1976
1892
  );
@@ -1987,7 +1903,7 @@ var Workflow = class extends BaseResource {
1987
1903
  async transform(chunk, controller) {
1988
1904
  try {
1989
1905
  const decoded = new TextDecoder().decode(chunk);
1990
- const chunks = decoded.split(RECORD_SEPARATOR2);
1906
+ const chunks = decoded.split(RECORD_SEPARATOR);
1991
1907
  for (const chunk2 of chunks) {
1992
1908
  if (chunk2) {
1993
1909
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2022,6 +1938,22 @@ var Workflow = class extends BaseResource {
2022
1938
  }
2023
1939
  });
2024
1940
  }
1941
+ /**
1942
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1943
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1944
+ * @returns Promise containing the workflow resume results
1945
+ */
1946
+ resumeStreamVNext(params) {
1947
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1948
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1949
+ method: "POST",
1950
+ body: {
1951
+ step: params.step,
1952
+ resumeData: params.resumeData,
1953
+ runtimeContext
1954
+ }
1955
+ });
1956
+ }
2025
1957
  /**
2026
1958
  * Watches workflow transitions in real-time
2027
1959
  * @param runId - Optional run ID to filter the watch stream
@@ -2058,7 +1990,7 @@ var Workflow = class extends BaseResource {
2058
1990
  async start(controller) {
2059
1991
  try {
2060
1992
  for await (const record of records) {
2061
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1993
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2062
1994
  controller.enqueue(encoder.encode(json));
2063
1995
  }
2064
1996
  controller.close();
@@ -2156,10 +2088,11 @@ var MCPTool = class extends BaseResource {
2156
2088
  }
2157
2089
  /**
2158
2090
  * Retrieves details about this specific tool from the MCP server.
2091
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2159
2092
  * @returns Promise containing the tool's information (name, description, schema).
2160
2093
  */
2161
- details() {
2162
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2094
+ details(runtimeContext) {
2095
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2163
2096
  }
2164
2097
  /**
2165
2098
  * Executes this specific tool on the MCP server.
@@ -2180,7 +2113,7 @@ var MCPTool = class extends BaseResource {
2180
2113
  };
2181
2114
 
2182
2115
  // src/resources/agent-builder.ts
2183
- var RECORD_SEPARATOR3 = "";
2116
+ var RECORD_SEPARATOR2 = "";
2184
2117
  var AgentBuilder = class extends BaseResource {
2185
2118
  constructor(options, actionId) {
2186
2119
  super(options);
@@ -2215,11 +2148,20 @@ var AgentBuilder = class extends BaseResource {
2215
2148
  };
2216
2149
  }
2217
2150
  }
2151
+ /**
2152
+ * @deprecated Use createRunAsync() instead.
2153
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2154
+ */
2155
+ async createRun(_params) {
2156
+ throw new Error(
2157
+ "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."
2158
+ );
2159
+ }
2218
2160
  /**
2219
2161
  * Creates a new agent builder action run and returns the runId.
2220
2162
  * This calls `/api/agent-builder/:actionId/create-run`.
2221
2163
  */
2222
- async createRun(params) {
2164
+ async createRunAsync(params) {
2223
2165
  const searchParams = new URLSearchParams();
2224
2166
  if (!!params?.runId) {
2225
2167
  searchParams.set("runId", params.runId);
@@ -2229,14 +2171,6 @@ var AgentBuilder = class extends BaseResource {
2229
2171
  method: "POST"
2230
2172
  });
2231
2173
  }
2232
- /**
2233
- * Creates a new workflow run (alias for createRun)
2234
- * @param params - Optional object containing the optional runId
2235
- * @returns Promise containing the runId of the created run
2236
- */
2237
- createRunAsync(params) {
2238
- return this.createRun(params);
2239
- }
2240
2174
  /**
2241
2175
  * Starts agent builder action asynchronously and waits for completion.
2242
2176
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2319,7 +2253,7 @@ var AgentBuilder = class extends BaseResource {
2319
2253
  if (done && !value) continue;
2320
2254
  try {
2321
2255
  const decoded = value ? new TextDecoder().decode(value) : "";
2322
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2256
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2323
2257
  buffer = chunks.pop() || "";
2324
2258
  for (const chunk of chunks) {
2325
2259
  if (chunk) {
@@ -2376,7 +2310,7 @@ var AgentBuilder = class extends BaseResource {
2376
2310
  async transform(chunk, controller) {
2377
2311
  try {
2378
2312
  const decoded = new TextDecoder().decode(chunk);
2379
- const chunks = decoded.split(RECORD_SEPARATOR3);
2313
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2380
2314
  for (const chunk2 of chunks) {
2381
2315
  if (chunk2) {
2382
2316
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2425,7 +2359,7 @@ var AgentBuilder = class extends BaseResource {
2425
2359
  async transform(chunk, controller) {
2426
2360
  try {
2427
2361
  const decoded = new TextDecoder().decode(chunk);
2428
- const chunks = decoded.split(RECORD_SEPARATOR3);
2362
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2429
2363
  for (const chunk2 of chunks) {
2430
2364
  if (chunk2) {
2431
2365
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2596,6 +2530,31 @@ var Observability = class extends BaseResource {
2596
2530
  const queryString = searchParams.toString();
2597
2531
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2598
2532
  }
2533
+ /**
2534
+ * Retrieves scores by trace ID and span ID
2535
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2536
+ * @returns Promise containing scores and pagination info
2537
+ */
2538
+ getScoresBySpan(params) {
2539
+ const { traceId, spanId, page, perPage } = params;
2540
+ const searchParams = new URLSearchParams();
2541
+ if (page !== void 0) {
2542
+ searchParams.set("page", String(page));
2543
+ }
2544
+ if (perPage !== void 0) {
2545
+ searchParams.set("perPage", String(perPage));
2546
+ }
2547
+ const queryString = searchParams.toString();
2548
+ return this.request(
2549
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2550
+ );
2551
+ }
2552
+ score(params) {
2553
+ return this.request(`/api/observability/traces/score`, {
2554
+ method: "POST",
2555
+ body: { ...params }
2556
+ });
2557
+ }
2599
2558
  };
2600
2559
 
2601
2560
  // src/resources/network-memory-thread.ts
@@ -2662,7 +2621,7 @@ var NetworkMemoryThread = class extends BaseResource {
2662
2621
  };
2663
2622
 
2664
2623
  // src/resources/vNextNetwork.ts
2665
- var RECORD_SEPARATOR4 = "";
2624
+ var RECORD_SEPARATOR3 = "";
2666
2625
  var VNextNetwork = class extends BaseResource {
2667
2626
  constructor(options, networkId) {
2668
2627
  super(options);
@@ -2670,10 +2629,11 @@ var VNextNetwork = class extends BaseResource {
2670
2629
  }
2671
2630
  /**
2672
2631
  * Retrieves details about the network
2632
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2673
2633
  * @returns Promise containing vNext network details
2674
2634
  */
2675
- details() {
2676
- return this.request(`/api/networks/v-next/${this.networkId}`);
2635
+ details(runtimeContext) {
2636
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2677
2637
  }
2678
2638
  /**
2679
2639
  * Generates a response from the v-next network
@@ -2714,7 +2674,7 @@ var VNextNetwork = class extends BaseResource {
2714
2674
  if (done && !value) continue;
2715
2675
  try {
2716
2676
  const decoded = value ? new TextDecoder().decode(value) : "";
2717
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2677
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2718
2678
  buffer = chunks.pop() || "";
2719
2679
  for (const chunk of chunks) {
2720
2680
  if (chunk) {
@@ -2808,10 +2768,17 @@ var MastraClient = class extends BaseResource {
2808
2768
  }
2809
2769
  /**
2810
2770
  * Retrieves all available agents
2771
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2811
2772
  * @returns Promise containing map of agent IDs to agent details
2812
2773
  */
2813
- getAgents() {
2814
- return this.request("/api/agents");
2774
+ getAgents(runtimeContext) {
2775
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2776
+ const searchParams = new URLSearchParams();
2777
+ if (runtimeContextParam) {
2778
+ searchParams.set("runtimeContext", runtimeContextParam);
2779
+ }
2780
+ const queryString = searchParams.toString();
2781
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2815
2782
  }
2816
2783
  /**
2817
2784
  * Gets an agent instance by ID
@@ -2829,6 +2796,14 @@ var MastraClient = class extends BaseResource {
2829
2796
  getMemoryThreads(params) {
2830
2797
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2831
2798
  }
2799
+ /**
2800
+ * Retrieves memory config for a resource
2801
+ * @param params - Parameters containing the resource ID
2802
+ * @returns Promise containing array of memory threads
2803
+ */
2804
+ getMemoryConfig(params) {
2805
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2806
+ }
2832
2807
  /**
2833
2808
  * Creates a new memory thread
2834
2809
  * @param params - Parameters for creating the memory thread
@@ -2845,6 +2820,24 @@ var MastraClient = class extends BaseResource {
2845
2820
  getMemoryThread(threadId, agentId) {
2846
2821
  return new MemoryThread(this.options, threadId, agentId);
2847
2822
  }
2823
+ getThreadMessages(threadId, opts = {}) {
2824
+ let url = "";
2825
+ if (opts.agentId) {
2826
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2827
+ } else if (opts.networkId) {
2828
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2829
+ }
2830
+ return this.request(url);
2831
+ }
2832
+ deleteThread(threadId, opts = {}) {
2833
+ let url = "";
2834
+ if (opts.agentId) {
2835
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2836
+ } else if (opts.networkId) {
2837
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2838
+ }
2839
+ return this.request(url, { method: "DELETE" });
2840
+ }
2848
2841
  /**
2849
2842
  * Saves messages to memory
2850
2843
  * @param params - Parameters containing messages to save
@@ -2907,10 +2900,17 @@ var MastraClient = class extends BaseResource {
2907
2900
  }
2908
2901
  /**
2909
2902
  * Retrieves all available tools
2903
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2910
2904
  * @returns Promise containing map of tool IDs to tool details
2911
2905
  */
2912
- getTools() {
2913
- return this.request("/api/tools");
2906
+ getTools(runtimeContext) {
2907
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2908
+ const searchParams = new URLSearchParams();
2909
+ if (runtimeContextParam) {
2910
+ searchParams.set("runtimeContext", runtimeContextParam);
2911
+ }
2912
+ const queryString = searchParams.toString();
2913
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2914
2914
  }
2915
2915
  /**
2916
2916
  * Gets a tool instance by ID
@@ -2920,27 +2920,19 @@ var MastraClient = class extends BaseResource {
2920
2920
  getTool(toolId) {
2921
2921
  return new Tool(this.options, toolId);
2922
2922
  }
2923
- /**
2924
- * Retrieves all available legacy workflows
2925
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2926
- */
2927
- getLegacyWorkflows() {
2928
- return this.request("/api/workflows/legacy");
2929
- }
2930
- /**
2931
- * Gets a legacy workflow instance by ID
2932
- * @param workflowId - ID of the legacy workflow to retrieve
2933
- * @returns Legacy Workflow instance
2934
- */
2935
- getLegacyWorkflow(workflowId) {
2936
- return new LegacyWorkflow(this.options, workflowId);
2937
- }
2938
2923
  /**
2939
2924
  * Retrieves all available workflows
2925
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2940
2926
  * @returns Promise containing map of workflow IDs to workflow details
2941
2927
  */
2942
- getWorkflows() {
2943
- return this.request("/api/workflows");
2928
+ getWorkflows(runtimeContext) {
2929
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2930
+ const searchParams = new URLSearchParams();
2931
+ if (runtimeContextParam) {
2932
+ searchParams.set("runtimeContext", runtimeContextParam);
2933
+ }
2934
+ const queryString = searchParams.toString();
2935
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2944
2936
  }
2945
2937
  /**
2946
2938
  * Gets a workflow instance by ID
@@ -3108,13 +3100,6 @@ var MastraClient = class extends BaseResource {
3108
3100
  return this.request(`/api/telemetry`);
3109
3101
  }
3110
3102
  }
3111
- /**
3112
- * Retrieves all available networks
3113
- * @returns Promise containing map of network IDs to network details
3114
- */
3115
- getNetworks() {
3116
- return this.request("/api/networks");
3117
- }
3118
3103
  /**
3119
3104
  * Retrieves all available vNext networks
3120
3105
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3122,14 +3107,6 @@ var MastraClient = class extends BaseResource {
3122
3107
  getVNextNetworks() {
3123
3108
  return this.request("/api/networks/v-next");
3124
3109
  }
3125
- /**
3126
- * Gets a network instance by ID
3127
- * @param networkId - ID of the network to retrieve
3128
- * @returns Network instance
3129
- */
3130
- getNetwork(networkId) {
3131
- return new Network(this.options, networkId);
3132
- }
3133
3110
  /**
3134
3111
  * Gets a vNext network instance by ID
3135
3112
  * @param networkId - ID of the vNext network to retrieve
@@ -3242,7 +3219,7 @@ var MastraClient = class extends BaseResource {
3242
3219
  * @returns Promise containing the scorer
3243
3220
  */
3244
3221
  getScorer(scorerId) {
3245
- return this.request(`/api/scores/scorers/${scorerId}`);
3222
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3246
3223
  }
3247
3224
  getScoresByScorerId(params) {
3248
3225
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3260,7 +3237,7 @@ var MastraClient = class extends BaseResource {
3260
3237
  searchParams.set("perPage", String(perPage));
3261
3238
  }
3262
3239
  const queryString = searchParams.toString();
3263
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3240
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3264
3241
  }
3265
3242
  /**
3266
3243
  * Retrieves scores by run ID
@@ -3277,7 +3254,7 @@ var MastraClient = class extends BaseResource {
3277
3254
  searchParams.set("perPage", String(perPage));
3278
3255
  }
3279
3256
  const queryString = searchParams.toString();
3280
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3257
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3281
3258
  }
3282
3259
  /**
3283
3260
  * Retrieves scores by entity ID and type
@@ -3294,7 +3271,9 @@ var MastraClient = class extends BaseResource {
3294
3271
  searchParams.set("perPage", String(perPage));
3295
3272
  }
3296
3273
  const queryString = searchParams.toString();
3297
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3274
+ return this.request(
3275
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3276
+ );
3298
3277
  }
3299
3278
  /**
3300
3279
  * Saves a score
@@ -3320,8 +3299,33 @@ var MastraClient = class extends BaseResource {
3320
3299
  getAITraces(params) {
3321
3300
  return this.observability.getTraces(params);
3322
3301
  }
3302
+ getScoresBySpan(params) {
3303
+ return this.observability.getScoresBySpan(params);
3304
+ }
3305
+ score(params) {
3306
+ return this.observability.score(params);
3307
+ }
3323
3308
  };
3324
3309
 
3325
- export { MastraClient };
3310
+ // src/tools.ts
3311
+ var ClientTool = class {
3312
+ id;
3313
+ description;
3314
+ inputSchema;
3315
+ outputSchema;
3316
+ execute;
3317
+ constructor(opts) {
3318
+ this.id = opts.id;
3319
+ this.description = opts.description;
3320
+ this.inputSchema = opts.inputSchema;
3321
+ this.outputSchema = opts.outputSchema;
3322
+ this.execute = opts.execute;
3323
+ }
3324
+ };
3325
+ function createTool(opts) {
3326
+ return new ClientTool(opts);
3327
+ }
3328
+
3329
+ export { ClientTool, MastraClient, createTool };
3326
3330
  //# sourceMappingURL=index.js.map
3327
3331
  //# sourceMappingURL=index.js.map