@mastra/client-js 0.0.0-fix-memory-search-fetch-20251027160505 → 0.0.0-fix-persist-session-cache-option-mcp-server-20251030161352

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.
package/dist/index.js CHANGED
@@ -1,34 +1,34 @@
1
1
  import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
2
2
  import { v4 } from '@lukeed/uuid';
3
3
  import { getErrorFromUnknown } from '@mastra/core/error';
4
- import { RuntimeContext } from '@mastra/core/runtime-context';
4
+ import { RequestContext } from '@mastra/core/request-context';
5
5
  import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
6
6
  import { z } from 'zod';
7
7
  import originalZodToJsonSchema from 'zod-to-json-schema';
8
8
 
9
9
  // src/resources/agent.ts
10
- function parseClientRuntimeContext(runtimeContext) {
11
- if (runtimeContext) {
12
- if (runtimeContext instanceof RuntimeContext) {
13
- return Object.fromEntries(runtimeContext.entries());
10
+ function parseClientRequestContext(requestContext) {
11
+ if (requestContext) {
12
+ if (requestContext instanceof RequestContext) {
13
+ return Object.fromEntries(requestContext.entries());
14
14
  }
15
- return runtimeContext;
15
+ return requestContext;
16
16
  }
17
17
  return void 0;
18
18
  }
19
- function base64RuntimeContext(runtimeContext) {
20
- if (runtimeContext) {
21
- return btoa(JSON.stringify(runtimeContext));
19
+ function base64RequestContext(requestContext) {
20
+ if (requestContext) {
21
+ return btoa(JSON.stringify(requestContext));
22
22
  }
23
23
  return void 0;
24
24
  }
25
- function runtimeContextQueryString(runtimeContext) {
26
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
27
- if (!runtimeContextParam) return "";
25
+ function requestContextQueryString(requestContext, delimiter = "?") {
26
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
27
+ if (!requestContextParam) return "";
28
28
  const searchParams = new URLSearchParams();
29
- searchParams.set("runtimeContext", runtimeContextParam);
29
+ searchParams.set("requestContext", requestContextParam);
30
30
  const queryString = searchParams.toString();
31
- return queryString ? `?${queryString}` : "";
31
+ return queryString ? `${delimiter}${queryString}` : "";
32
32
  }
33
33
  function isZodType(value) {
34
34
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
@@ -200,7 +200,7 @@ async function executeToolCallAndRespond({
200
200
  runId,
201
201
  resourceId,
202
202
  threadId,
203
- runtimeContext,
203
+ requestContext,
204
204
  respondFn
205
205
  }) {
206
206
  if (response.finishReason === "tool-calls") {
@@ -217,7 +217,7 @@ async function executeToolCallAndRespond({
217
217
  runId,
218
218
  resourceId,
219
219
  threadId,
220
- runtimeContext,
220
+ requestContext,
221
221
  tracingContext: { currentSpan: void 0 },
222
222
  suspend: async () => {
223
223
  }
@@ -290,21 +290,21 @@ var AgentVoice = class extends BaseResource {
290
290
  }
291
291
  /**
292
292
  * Get available speakers for the agent's voice provider
293
- * @param runtimeContext - Optional runtime context to pass as query parameter
294
- * @param runtimeContext - Optional runtime context to pass as query parameter
293
+ * @param requestContext - Optional request context to pass as query parameter
294
+ * @param requestContext - Optional request context to pass as query parameter
295
295
  * @returns Promise containing list of available speakers
296
296
  */
297
- getSpeakers(runtimeContext) {
298
- return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
297
+ getSpeakers(requestContext) {
298
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${requestContextQueryString(requestContext)}`);
299
299
  }
300
300
  /**
301
301
  * Get the listener configuration for the agent's voice provider
302
- * @param runtimeContext - Optional runtime context to pass as query parameter
303
- * @param runtimeContext - Optional runtime context to pass as query parameter
302
+ * @param requestContext - Optional request context to pass as query parameter
303
+ * @param requestContext - Optional request context to pass as query parameter
304
304
  * @returns Promise containing a check if the agent has listening capabilities
305
305
  */
306
- getListener(runtimeContext) {
307
- return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
306
+ getListener(requestContext) {
307
+ return this.request(`/api/agents/${this.agentId}/voice/listener${requestContextQueryString(requestContext)}`);
308
308
  }
309
309
  };
310
310
  var Agent = class extends BaseResource {
@@ -316,11 +316,11 @@ var Agent = class extends BaseResource {
316
316
  voice;
317
317
  /**
318
318
  * Retrieves details about the agent
319
- * @param runtimeContext - Optional runtime context to pass as query parameter
319
+ * @param requestContext - Optional request context to pass as query parameter
320
320
  * @returns Promise containing agent details including model and instructions
321
321
  */
322
- details(runtimeContext) {
323
- return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
322
+ details(requestContext) {
323
+ return this.request(`/api/agents/${this.agentId}${requestContextQueryString(requestContext)}`);
324
324
  }
325
325
  enhanceInstructions(instructions, comment) {
326
326
  return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
@@ -333,10 +333,10 @@ var Agent = class extends BaseResource {
333
333
  ...params,
334
334
  output: params.output ? zodToJsonSchema(params.output) : void 0,
335
335
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
336
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
336
+ requestContext: parseClientRequestContext(params.requestContext),
337
337
  clientTools: processClientTools(params.clientTools)
338
338
  };
339
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
339
+ const { runId, resourceId, threadId, requestContext } = processedParams;
340
340
  const response = await this.request(
341
341
  `/api/agents/${this.agentId}/generate-legacy`,
342
342
  {
@@ -358,7 +358,7 @@ var Agent = class extends BaseResource {
358
358
  runId,
359
359
  resourceId,
360
360
  threadId,
361
- runtimeContext,
361
+ requestContext,
362
362
  tracingContext: { currentSpan: void 0 },
363
363
  suspend: async () => {
364
364
  }
@@ -403,14 +403,14 @@ var Agent = class extends BaseResource {
403
403
  }
404
404
  const processedParams = {
405
405
  ...params,
406
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
406
+ requestContext: parseClientRequestContext(params.requestContext),
407
407
  clientTools: processClientTools(params.clientTools),
408
408
  structuredOutput: params.structuredOutput ? {
409
409
  ...params.structuredOutput,
410
410
  schema: zodToJsonSchema(params.structuredOutput.schema)
411
411
  } : void 0
412
412
  };
413
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
413
+ const { runId, resourceId, threadId, requestContext } = processedParams;
414
414
  const response = await this.request(
415
415
  `/api/agents/${this.agentId}/generate`,
416
416
  {
@@ -425,7 +425,7 @@ var Agent = class extends BaseResource {
425
425
  runId,
426
426
  resourceId,
427
427
  threadId,
428
- runtimeContext,
428
+ requestContext,
429
429
  respondFn: this.generate.bind(this)
430
430
  });
431
431
  }
@@ -703,7 +703,7 @@ var Agent = class extends BaseResource {
703
703
  ...params,
704
704
  output: params.output ? zodToJsonSchema(params.output) : void 0,
705
705
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
706
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
706
+ requestContext: parseClientRequestContext(params.requestContext),
707
707
  clientTools: processClientTools(params.clientTools)
708
708
  };
709
709
  const { readable, writable } = new TransformStream();
@@ -1048,7 +1048,7 @@ var Agent = class extends BaseResource {
1048
1048
  runId: processedParams.runId,
1049
1049
  resourceId: processedParams.resourceId,
1050
1050
  threadId: processedParams.threadId,
1051
- runtimeContext: processedParams.runtimeContext,
1051
+ requestContext: processedParams.requestContext,
1052
1052
  // TODO: Pass proper tracing context when client-js supports tracing
1053
1053
  tracingContext: { currentSpan: void 0 },
1054
1054
  suspend: async () => {
@@ -1146,7 +1146,7 @@ var Agent = class extends BaseResource {
1146
1146
  }
1147
1147
  const processedParams = {
1148
1148
  ...params,
1149
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1149
+ requestContext: parseClientRequestContext(params.requestContext),
1150
1150
  clientTools: processClientTools(params.clientTools),
1151
1151
  structuredOutput: params.structuredOutput ? {
1152
1152
  ...params.structuredOutput,
@@ -1252,7 +1252,7 @@ var Agent = class extends BaseResource {
1252
1252
  runId: processedParams.runId,
1253
1253
  resourceId: processedParams.resourceId,
1254
1254
  threadId: processedParams.threadId,
1255
- runtimeContext: processedParams.runtimeContext,
1255
+ requestContext: processedParams.requestContext,
1256
1256
  // TODO: Pass proper tracing context when client-js supports tracing
1257
1257
  tracingContext: { currentSpan: void 0 },
1258
1258
  suspend: async () => {
@@ -1323,11 +1323,11 @@ var Agent = class extends BaseResource {
1323
1323
  /**
1324
1324
  * Gets details about a specific tool available to the agent
1325
1325
  * @param toolId - ID of the tool to retrieve
1326
- * @param runtimeContext - Optional runtime context to pass as query parameter
1326
+ * @param requestContext - Optional request context to pass as query parameter
1327
1327
  * @returns Promise containing tool details
1328
1328
  */
1329
- getTool(toolId, runtimeContext) {
1330
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1329
+ getTool(toolId, requestContext) {
1330
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
1331
1331
  }
1332
1332
  /**
1333
1333
  * Executes a tool for the agent
@@ -1338,29 +1338,13 @@ var Agent = class extends BaseResource {
1338
1338
  executeTool(toolId, params) {
1339
1339
  const body = {
1340
1340
  data: params.data,
1341
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1341
+ requestContext: parseClientRequestContext(params.requestContext)
1342
1342
  };
1343
1343
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1344
1344
  method: "POST",
1345
1345
  body
1346
1346
  });
1347
1347
  }
1348
- /**
1349
- * Retrieves evaluation results for the agent
1350
- * @param runtimeContext - Optional runtime context to pass as query parameter
1351
- * @returns Promise containing agent evaluations
1352
- */
1353
- evals(runtimeContext) {
1354
- return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1355
- }
1356
- /**
1357
- * Retrieves live evaluation results for the agent
1358
- * @param runtimeContext - Optional runtime context to pass as query parameter
1359
- * @returns Promise containing live agent evaluations
1360
- */
1361
- liveEvals(runtimeContext) {
1362
- return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1363
- }
1364
1348
  /**
1365
1349
  * Updates the model for the agent
1366
1350
  * @param params - Parameters for updating the model
@@ -1372,6 +1356,15 @@ var Agent = class extends BaseResource {
1372
1356
  body: params
1373
1357
  });
1374
1358
  }
1359
+ /**
1360
+ * Resets the agent's model to the original model that was set during construction
1361
+ * @returns Promise containing a success message
1362
+ */
1363
+ resetModel() {
1364
+ return this.request(`/api/agents/${this.agentId}/model/reset`, {
1365
+ method: "POST"
1366
+ });
1367
+ }
1375
1368
  /**
1376
1369
  * Updates the model for the agent in the model list
1377
1370
  * @param params - Parameters for updating the model
@@ -1411,34 +1404,44 @@ var MemoryThread = class extends BaseResource {
1411
1404
  }
1412
1405
  /**
1413
1406
  * Retrieves the memory thread details
1407
+ * @param requestContext - Optional request context to pass as query parameter
1414
1408
  * @returns Promise containing thread details including title and metadata
1415
1409
  */
1416
- get() {
1417
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
1410
+ get(requestContext) {
1411
+ return this.request(
1412
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
1413
+ );
1418
1414
  }
1419
1415
  /**
1420
1416
  * Updates the memory thread properties
1421
- * @param params - Update parameters including title and metadata
1417
+ * @param params - Update parameters including title, metadata, and optional request context
1422
1418
  * @returns Promise containing updated thread details
1423
1419
  */
1424
1420
  update(params) {
1425
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1426
- method: "PATCH",
1427
- body: params
1428
- });
1421
+ return this.request(
1422
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
1423
+ {
1424
+ method: "PATCH",
1425
+ body: params
1426
+ }
1427
+ );
1429
1428
  }
1430
1429
  /**
1431
1430
  * Deletes the memory thread
1431
+ * @param requestContext - Optional request context to pass as query parameter
1432
1432
  * @returns Promise containing deletion result
1433
1433
  */
1434
- delete() {
1435
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1436
- method: "DELETE"
1437
- });
1434
+ delete(requestContext) {
1435
+ return this.request(
1436
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
1437
+ {
1438
+ method: "DELETE"
1439
+ }
1440
+ );
1438
1441
  }
1439
1442
  /**
1440
1443
  * Retrieves messages associated with the thread
1441
- * @param params - Optional parameters including limit for number of messages to retrieve
1444
+ * @param params - Optional parameters including limit for number of messages to retrieve and request context
1442
1445
  * @returns Promise containing thread messages and UI messages
1443
1446
  */
1444
1447
  getMessages(params) {
@@ -1446,37 +1449,46 @@ var MemoryThread = class extends BaseResource {
1446
1449
  agentId: this.agentId,
1447
1450
  ...params?.limit ? { limit: params.limit.toString() } : {}
1448
1451
  });
1449
- return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
1452
+ return this.request(
1453
+ `/api/memory/threads/${this.threadId}/messages?${query.toString()}${requestContextQueryString(params?.requestContext, "&")}`
1454
+ );
1450
1455
  }
1451
1456
  /**
1452
1457
  * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1453
- * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1458
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, message inclusion options, and request context
1454
1459
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1455
1460
  */
1456
1461
  getMessagesPaginated({
1457
1462
  selectBy,
1463
+ requestContext,
1458
1464
  ...rest
1459
1465
  }) {
1460
1466
  const query = new URLSearchParams({
1461
1467
  ...rest,
1462
1468
  ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1463
1469
  });
1464
- return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1470
+ return this.request(
1471
+ `/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}${requestContextQueryString(requestContext, "&")}`
1472
+ );
1465
1473
  }
1466
1474
  /**
1467
1475
  * Deletes one or more messages from the thread
1468
1476
  * @param messageIds - Can be a single message ID (string), array of message IDs,
1469
1477
  * message object with id property, or array of message objects
1478
+ * @param requestContext - Optional request context to pass as query parameter
1470
1479
  * @returns Promise containing deletion result
1471
1480
  */
1472
- deleteMessages(messageIds) {
1481
+ deleteMessages(messageIds, requestContext) {
1473
1482
  const query = new URLSearchParams({
1474
1483
  agentId: this.agentId
1475
1484
  });
1476
- return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1477
- method: "POST",
1478
- body: { messageIds }
1479
- });
1485
+ return this.request(
1486
+ `/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
1487
+ {
1488
+ method: "POST",
1489
+ body: { messageIds }
1490
+ }
1491
+ );
1480
1492
  }
1481
1493
  };
1482
1494
 
@@ -1489,12 +1501,12 @@ var Vector = class extends BaseResource {
1489
1501
  /**
1490
1502
  * Retrieves details about a specific vector index
1491
1503
  * @param indexName - Name of the index to get details for
1492
- * @param runtimeContext - Optional runtime context to pass as query parameter
1504
+ * @param requestContext - Optional request context to pass as query parameter
1493
1505
  * @returns Promise containing vector index details
1494
1506
  */
1495
- details(indexName, runtimeContext) {
1507
+ details(indexName, requestContext) {
1496
1508
  return this.request(
1497
- `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1509
+ `/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
1498
1510
  );
1499
1511
  }
1500
1512
  /**
@@ -1509,11 +1521,11 @@ var Vector = class extends BaseResource {
1509
1521
  }
1510
1522
  /**
1511
1523
  * Retrieves a list of all available indexes
1512
- * @param runtimeContext - Optional runtime context to pass as query parameter
1524
+ * @param requestContext - Optional request context to pass as query parameter
1513
1525
  * @returns Promise containing array of index names
1514
1526
  */
1515
- getIndexes(runtimeContext) {
1516
- return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1527
+ getIndexes(requestContext) {
1528
+ return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
1517
1529
  }
1518
1530
  /**
1519
1531
  * Creates a new vector index
@@ -1558,11 +1570,11 @@ var Tool = class extends BaseResource {
1558
1570
  }
1559
1571
  /**
1560
1572
  * Retrieves details about the tool
1561
- * @param runtimeContext - Optional runtime context to pass as query parameter
1573
+ * @param requestContext - Optional request context to pass as query parameter
1562
1574
  * @returns Promise containing tool details including description and schemas
1563
1575
  */
1564
- details(runtimeContext) {
1565
- return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1576
+ details(requestContext) {
1577
+ return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
1566
1578
  }
1567
1579
  /**
1568
1580
  * Executes the tool with the provided parameters
@@ -1576,7 +1588,7 @@ var Tool = class extends BaseResource {
1576
1588
  }
1577
1589
  const body = {
1578
1590
  data: params.data,
1579
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1591
+ requestContext: parseClientRequestContext(params.requestContext)
1580
1592
  };
1581
1593
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1582
1594
  method: "POST",
@@ -1639,20 +1651,20 @@ var Workflow = class extends BaseResource {
1639
1651
  }
1640
1652
  /**
1641
1653
  * Retrieves details about the workflow
1642
- * @param runtimeContext - Optional runtime context to pass as query parameter
1654
+ * @param requestContext - Optional request context to pass as query parameter
1643
1655
  * @returns Promise containing workflow details including steps and graphs
1644
1656
  */
1645
- details(runtimeContext) {
1646
- return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1657
+ details(requestContext) {
1658
+ return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
1647
1659
  }
1648
1660
  /**
1649
1661
  * Retrieves all runs for a workflow
1650
1662
  * @param params - Parameters for filtering runs
1651
- * @param runtimeContext - Optional runtime context to pass as query parameter
1663
+ * @param requestContext - Optional request context to pass as query parameter
1652
1664
  * @returns Promise containing workflow runs array
1653
1665
  */
1654
- runs(params, runtimeContext) {
1655
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1666
+ runs(params, requestContext) {
1667
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
1656
1668
  const searchParams = new URLSearchParams();
1657
1669
  if (params?.fromDate) {
1658
1670
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1669,8 +1681,8 @@ var Workflow = class extends BaseResource {
1669
1681
  if (params?.resourceId) {
1670
1682
  searchParams.set("resourceId", params.resourceId);
1671
1683
  }
1672
- if (runtimeContextParam) {
1673
- searchParams.set("runtimeContext", runtimeContextParam);
1684
+ if (requestContextParam) {
1685
+ searchParams.set("requestContext", requestContextParam);
1674
1686
  }
1675
1687
  if (searchParams.size) {
1676
1688
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
@@ -1681,21 +1693,21 @@ var Workflow = class extends BaseResource {
1681
1693
  /**
1682
1694
  * Retrieves a specific workflow run by its ID
1683
1695
  * @param runId - The ID of the workflow run to retrieve
1684
- * @param runtimeContext - Optional runtime context to pass as query parameter
1696
+ * @param requestContext - Optional request context to pass as query parameter
1685
1697
  * @returns Promise containing the workflow run details
1686
1698
  */
1687
- runById(runId, runtimeContext) {
1688
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1699
+ runById(runId, requestContext) {
1700
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
1689
1701
  }
1690
1702
  /**
1691
1703
  * Retrieves the execution result for a specific workflow run by its ID
1692
1704
  * @param runId - The ID of the workflow run to retrieve the execution result for
1693
- * @param runtimeContext - Optional runtime context to pass as query parameter
1705
+ * @param requestContext - Optional request context to pass as query parameter
1694
1706
  * @returns Promise containing the workflow run execution result
1695
1707
  */
1696
- runExecutionResult(runId, runtimeContext) {
1708
+ runExecutionResult(runId, requestContext) {
1697
1709
  return this.request(
1698
- `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1710
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
1699
1711
  );
1700
1712
  }
1701
1713
  /**
@@ -1751,7 +1763,7 @@ var Workflow = class extends BaseResource {
1751
1763
  return this.start({
1752
1764
  runId,
1753
1765
  inputData: p.inputData,
1754
- runtimeContext: p.runtimeContext,
1766
+ requestContext: p.requestContext,
1755
1767
  tracingOptions: p.tracingOptions
1756
1768
  });
1757
1769
  },
@@ -1759,7 +1771,7 @@ var Workflow = class extends BaseResource {
1759
1771
  return this.startAsync({
1760
1772
  runId,
1761
1773
  inputData: p.inputData,
1762
- runtimeContext: p.runtimeContext,
1774
+ requestContext: p.requestContext,
1763
1775
  tracingOptions: p.tracingOptions
1764
1776
  });
1765
1777
  },
@@ -1767,14 +1779,14 @@ var Workflow = class extends BaseResource {
1767
1779
  return this.watch({ runId }, onRecord);
1768
1780
  },
1769
1781
  stream: async (p) => {
1770
- return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1782
+ return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
1771
1783
  },
1772
1784
  resume: async (p) => {
1773
1785
  return this.resume({
1774
1786
  runId,
1775
1787
  step: p.step,
1776
1788
  resumeData: p.resumeData,
1777
- runtimeContext: p.runtimeContext,
1789
+ requestContext: p.requestContext,
1778
1790
  tracingOptions: p.tracingOptions
1779
1791
  });
1780
1792
  },
@@ -1783,7 +1795,7 @@ var Workflow = class extends BaseResource {
1783
1795
  runId,
1784
1796
  step: p.step,
1785
1797
  resumeData: p.resumeData,
1786
- runtimeContext: p.runtimeContext,
1798
+ requestContext: p.requestContext,
1787
1799
  tracingOptions: p.tracingOptions
1788
1800
  });
1789
1801
  },
@@ -1792,26 +1804,26 @@ var Workflow = class extends BaseResource {
1792
1804
  runId,
1793
1805
  step: p.step,
1794
1806
  resumeData: p.resumeData,
1795
- runtimeContext: p.runtimeContext
1807
+ requestContext: p.requestContext
1796
1808
  });
1797
1809
  }
1798
1810
  };
1799
1811
  }
1800
1812
  /**
1801
1813
  * Starts a workflow run synchronously without waiting for the workflow to complete
1802
- * @param params - Object containing the runId, inputData and runtimeContext
1814
+ * @param params - Object containing the runId, inputData and requestContext
1803
1815
  * @returns Promise containing success message
1804
1816
  */
1805
1817
  start(params) {
1806
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1818
+ const requestContext = parseClientRequestContext(params.requestContext);
1807
1819
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1808
1820
  method: "POST",
1809
- body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1821
+ body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
1810
1822
  });
1811
1823
  }
1812
1824
  /**
1813
1825
  * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
1814
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1826
+ * @param params - Object containing the runId, step, resumeData and requestContext
1815
1827
  * @returns Promise containing success message
1816
1828
  */
1817
1829
  resume({
@@ -1821,20 +1833,20 @@ var Workflow = class extends BaseResource {
1821
1833
  tracingOptions,
1822
1834
  ...rest
1823
1835
  }) {
1824
- const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1836
+ const requestContext = parseClientRequestContext(rest.requestContext);
1825
1837
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1826
1838
  method: "POST",
1827
1839
  body: {
1828
1840
  step,
1829
1841
  resumeData,
1830
- runtimeContext,
1842
+ requestContext,
1831
1843
  tracingOptions
1832
1844
  }
1833
1845
  });
1834
1846
  }
1835
1847
  /**
1836
1848
  * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1837
- * @param params - Object containing the optional runId, inputData and runtimeContext
1849
+ * @param params - Object containing the optional runId, inputData and requestContext
1838
1850
  * @returns Promise containing the workflow execution results
1839
1851
  */
1840
1852
  startAsync(params) {
@@ -1842,15 +1854,15 @@ var Workflow = class extends BaseResource {
1842
1854
  if (!!params?.runId) {
1843
1855
  searchParams.set("runId", params.runId);
1844
1856
  }
1845
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1857
+ const requestContext = parseClientRequestContext(params.requestContext);
1846
1858
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1847
1859
  method: "POST",
1848
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1860
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
1849
1861
  });
1850
1862
  }
1851
1863
  /**
1852
1864
  * Starts a workflow run and returns a stream
1853
- * @param params - Object containing the optional runId, inputData and runtimeContext
1865
+ * @param params - Object containing the optional runId, inputData and requestContext
1854
1866
  * @returns Promise containing the workflow execution results
1855
1867
  */
1856
1868
  async stream(params) {
@@ -1858,12 +1870,12 @@ var Workflow = class extends BaseResource {
1858
1870
  if (!!params?.runId) {
1859
1871
  searchParams.set("runId", params.runId);
1860
1872
  }
1861
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1873
+ const requestContext = parseClientRequestContext(params.requestContext);
1862
1874
  const response = await this.request(
1863
1875
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1864
1876
  {
1865
1877
  method: "POST",
1866
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1878
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
1867
1879
  stream: true
1868
1880
  }
1869
1881
  );
@@ -1948,7 +1960,7 @@ var Workflow = class extends BaseResource {
1948
1960
  }
1949
1961
  /**
1950
1962
  * Starts a workflow run and returns a stream
1951
- * @param params - Object containing the optional runId, inputData and runtimeContext
1963
+ * @param params - Object containing the optional runId, inputData and requestContext
1952
1964
  * @returns Promise containing the workflow execution results
1953
1965
  */
1954
1966
  async streamVNext(params) {
@@ -1956,14 +1968,14 @@ var Workflow = class extends BaseResource {
1956
1968
  if (!!params?.runId) {
1957
1969
  searchParams.set("runId", params.runId);
1958
1970
  }
1959
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1971
+ const requestContext = parseClientRequestContext(params.requestContext);
1960
1972
  const response = await this.request(
1961
1973
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1962
1974
  {
1963
1975
  method: "POST",
1964
1976
  body: {
1965
1977
  inputData: params.inputData,
1966
- runtimeContext,
1978
+ requestContext,
1967
1979
  closeOnSuspend: params.closeOnSuspend,
1968
1980
  tracingOptions: params.tracingOptions
1969
1981
  },
@@ -2051,30 +2063,30 @@ var Workflow = class extends BaseResource {
2051
2063
  }
2052
2064
  /**
2053
2065
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2054
- * @param params - Object containing the runId, step, resumeData and runtimeContext
2066
+ * @param params - Object containing the runId, step, resumeData and requestContext
2055
2067
  * @returns Promise containing the workflow resume results
2056
2068
  */
2057
2069
  resumeAsync(params) {
2058
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2070
+ const requestContext = parseClientRequestContext(params.requestContext);
2059
2071
  return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2060
2072
  method: "POST",
2061
2073
  body: {
2062
2074
  step: params.step,
2063
2075
  resumeData: params.resumeData,
2064
- runtimeContext,
2076
+ requestContext,
2065
2077
  tracingOptions: params.tracingOptions
2066
2078
  }
2067
2079
  });
2068
2080
  }
2069
2081
  /**
2070
2082
  * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2071
- * @param params - Object containing the runId, step, resumeData and runtimeContext
2083
+ * @param params - Object containing the runId, step, resumeData and requestContext
2072
2084
  * @returns Promise containing the workflow resume results
2073
2085
  */
2074
2086
  async resumeStreamVNext(params) {
2075
2087
  const searchParams = new URLSearchParams();
2076
2088
  searchParams.set("runId", params.runId);
2077
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2089
+ const requestContext = parseClientRequestContext(params.requestContext);
2078
2090
  const response = await this.request(
2079
2091
  `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2080
2092
  {
@@ -2082,7 +2094,7 @@ var Workflow = class extends BaseResource {
2082
2094
  body: {
2083
2095
  step: params.step,
2084
2096
  resumeData: params.resumeData,
2085
- runtimeContext,
2097
+ requestContext,
2086
2098
  tracingOptions: params.tracingOptions
2087
2099
  },
2088
2100
  stream: true
@@ -2254,22 +2266,22 @@ var MCPTool = class extends BaseResource {
2254
2266
  }
2255
2267
  /**
2256
2268
  * Retrieves details about this specific tool from the MCP server.
2257
- * @param runtimeContext - Optional runtime context to pass as query parameter
2269
+ * @param requestContext - Optional request context to pass as query parameter
2258
2270
  * @returns Promise containing the tool's information (name, description, schema).
2259
2271
  */
2260
- details(runtimeContext) {
2261
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2272
+ details(requestContext) {
2273
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
2262
2274
  }
2263
2275
  /**
2264
2276
  * Executes this specific tool on the MCP server.
2265
- * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
2277
+ * @param params - Parameters for tool execution, including data/args and optional requestContext.
2266
2278
  * @returns Promise containing the result of the tool execution.
2267
2279
  */
2268
2280
  execute(params) {
2269
2281
  const body = {};
2270
2282
  if (params.data !== void 0) body.data = params.data;
2271
- if (params.runtimeContext !== void 0) {
2272
- body.runtimeContext = params.runtimeContext;
2283
+ if (params.requestContext !== void 0) {
2284
+ body.requestContext = params.requestContext;
2273
2285
  }
2274
2286
  return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
2275
2287
  method: "POST",
@@ -2314,6 +2326,35 @@ var AgentBuilder = class extends BaseResource {
2314
2326
  };
2315
2327
  }
2316
2328
  }
2329
+ /**
2330
+ * Creates a transform stream that parses binary chunks into JSON records.
2331
+ */
2332
+ createRecordParserTransform() {
2333
+ let failedChunk = void 0;
2334
+ return new TransformStream({
2335
+ start() {
2336
+ },
2337
+ async transform(chunk, controller) {
2338
+ try {
2339
+ const decoded = new TextDecoder().decode(chunk);
2340
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2341
+ for (const chunk2 of chunks) {
2342
+ if (chunk2) {
2343
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2344
+ try {
2345
+ const parsedChunk = JSON.parse(newChunk);
2346
+ controller.enqueue(parsedChunk);
2347
+ failedChunk = void 0;
2348
+ } catch {
2349
+ failedChunk = newChunk;
2350
+ }
2351
+ }
2352
+ }
2353
+ } catch {
2354
+ }
2355
+ }
2356
+ });
2357
+ }
2317
2358
  /**
2318
2359
  * @deprecated Use createRunAsync() instead.
2319
2360
  * @throws {Error} Always throws an error directing users to use createRunAsync()
@@ -2346,12 +2387,12 @@ var AgentBuilder = class extends BaseResource {
2346
2387
  if (runId) {
2347
2388
  searchParams.set("runId", runId);
2348
2389
  }
2349
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2350
- const { runtimeContext: _, ...actionParams } = params;
2390
+ const requestContext = parseClientRequestContext(params.requestContext);
2391
+ const { requestContext: _, ...actionParams } = params;
2351
2392
  const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2352
2393
  const result = await this.request(url, {
2353
2394
  method: "POST",
2354
- body: { ...actionParams, runtimeContext }
2395
+ body: { ...actionParams, requestContext }
2355
2396
  });
2356
2397
  return this.transformWorkflowResult(result);
2357
2398
  }
@@ -2362,12 +2403,12 @@ var AgentBuilder = class extends BaseResource {
2362
2403
  async startActionRun(params, runId) {
2363
2404
  const searchParams = new URLSearchParams();
2364
2405
  searchParams.set("runId", runId);
2365
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2366
- const { runtimeContext: _, ...actionParams } = params;
2406
+ const requestContext = parseClientRequestContext(params.requestContext);
2407
+ const { requestContext: _, ...actionParams } = params;
2367
2408
  const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2368
2409
  return this.request(url, {
2369
2410
  method: "POST",
2370
- body: { ...actionParams, runtimeContext }
2411
+ body: { ...actionParams, requestContext }
2371
2412
  });
2372
2413
  }
2373
2414
  /**
@@ -2377,12 +2418,12 @@ var AgentBuilder = class extends BaseResource {
2377
2418
  async resume(params, runId) {
2378
2419
  const searchParams = new URLSearchParams();
2379
2420
  searchParams.set("runId", runId);
2380
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2381
- const { runtimeContext: _, ...resumeParams } = params;
2421
+ const requestContext = parseClientRequestContext(params.requestContext);
2422
+ const { requestContext: _, ...resumeParams } = params;
2382
2423
  const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2383
2424
  return this.request(url, {
2384
2425
  method: "POST",
2385
- body: { ...resumeParams, runtimeContext }
2426
+ body: { ...resumeParams, requestContext }
2386
2427
  });
2387
2428
  }
2388
2429
  /**
@@ -2392,12 +2433,12 @@ var AgentBuilder = class extends BaseResource {
2392
2433
  async resumeAsync(params, runId) {
2393
2434
  const searchParams = new URLSearchParams();
2394
2435
  searchParams.set("runId", runId);
2395
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2396
- const { runtimeContext: _, ...resumeParams } = params;
2436
+ const requestContext = parseClientRequestContext(params.requestContext);
2437
+ const { requestContext: _, ...resumeParams } = params;
2397
2438
  const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2398
2439
  const result = await this.request(url, {
2399
2440
  method: "POST",
2400
- body: { ...resumeParams, runtimeContext }
2441
+ body: { ...resumeParams, requestContext }
2401
2442
  });
2402
2443
  return this.transformWorkflowResult(result);
2403
2444
  }
@@ -2455,12 +2496,12 @@ var AgentBuilder = class extends BaseResource {
2455
2496
  if (runId) {
2456
2497
  searchParams.set("runId", runId);
2457
2498
  }
2458
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2459
- const { runtimeContext: _, ...actionParams } = params;
2499
+ const requestContext = parseClientRequestContext(params.requestContext);
2500
+ const { requestContext: _, ...actionParams } = params;
2460
2501
  const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2461
2502
  const response = await this.request(url, {
2462
2503
  method: "POST",
2463
- body: { ...actionParams, runtimeContext },
2504
+ body: { ...actionParams, requestContext },
2464
2505
  stream: true
2465
2506
  });
2466
2507
  if (!response.ok) {
@@ -2469,31 +2510,7 @@ var AgentBuilder = class extends BaseResource {
2469
2510
  if (!response.body) {
2470
2511
  throw new Error("Response body is null");
2471
2512
  }
2472
- let failedChunk = void 0;
2473
- const transformStream = new TransformStream({
2474
- start() {
2475
- },
2476
- async transform(chunk, controller) {
2477
- try {
2478
- const decoded = new TextDecoder().decode(chunk);
2479
- const chunks = decoded.split(RECORD_SEPARATOR2);
2480
- for (const chunk2 of chunks) {
2481
- if (chunk2) {
2482
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2483
- try {
2484
- const parsedChunk = JSON.parse(newChunk);
2485
- controller.enqueue(parsedChunk);
2486
- failedChunk = void 0;
2487
- } catch {
2488
- failedChunk = newChunk;
2489
- }
2490
- }
2491
- }
2492
- } catch {
2493
- }
2494
- }
2495
- });
2496
- return response.body.pipeThrough(transformStream);
2513
+ return response.body.pipeThrough(this.createRecordParserTransform());
2497
2514
  }
2498
2515
  /**
2499
2516
  * Streams agent builder action progress in real-time using VNext streaming.
@@ -2504,12 +2521,12 @@ var AgentBuilder = class extends BaseResource {
2504
2521
  if (runId) {
2505
2522
  searchParams.set("runId", runId);
2506
2523
  }
2507
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2508
- const { runtimeContext: _, ...actionParams } = params;
2524
+ const requestContext = parseClientRequestContext(params.requestContext);
2525
+ const { requestContext: _, ...actionParams } = params;
2509
2526
  const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2510
2527
  const response = await this.request(url, {
2511
2528
  method: "POST",
2512
- body: { ...actionParams, runtimeContext },
2529
+ body: { ...actionParams, requestContext },
2513
2530
  stream: true
2514
2531
  });
2515
2532
  if (!response.ok) {
@@ -2518,31 +2535,7 @@ var AgentBuilder = class extends BaseResource {
2518
2535
  if (!response.body) {
2519
2536
  throw new Error("Response body is null");
2520
2537
  }
2521
- let failedChunk = void 0;
2522
- const transformStream = new TransformStream({
2523
- start() {
2524
- },
2525
- async transform(chunk, controller) {
2526
- try {
2527
- const decoded = new TextDecoder().decode(chunk);
2528
- const chunks = decoded.split(RECORD_SEPARATOR2);
2529
- for (const chunk2 of chunks) {
2530
- if (chunk2) {
2531
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2532
- try {
2533
- const parsedChunk = JSON.parse(newChunk);
2534
- controller.enqueue(parsedChunk);
2535
- failedChunk = void 0;
2536
- } catch {
2537
- failedChunk = newChunk;
2538
- }
2539
- }
2540
- }
2541
- } catch {
2542
- }
2543
- }
2544
- });
2545
- return response.body.pipeThrough(transformStream);
2538
+ return response.body.pipeThrough(this.createRecordParserTransform());
2546
2539
  }
2547
2540
  /**
2548
2541
  * Watches an existing agent builder action run by runId.
@@ -2570,6 +2563,93 @@ var AgentBuilder = class extends BaseResource {
2570
2563
  }
2571
2564
  }
2572
2565
  }
2566
+ /**
2567
+ * Observes an existing agent builder action run stream.
2568
+ * Replays cached execution from the beginning, then continues with live stream.
2569
+ * This is the recommended method for recovery after page refresh/hot reload.
2570
+ * This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
2571
+ */
2572
+ async observeStream(params) {
2573
+ const searchParams = new URLSearchParams();
2574
+ searchParams.set("runId", params.runId);
2575
+ const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
2576
+ const response = await this.request(url, {
2577
+ method: "POST",
2578
+ stream: true
2579
+ });
2580
+ if (!response.ok) {
2581
+ throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
2582
+ }
2583
+ if (!response.body) {
2584
+ throw new Error("Response body is null");
2585
+ }
2586
+ return response.body.pipeThrough(this.createRecordParserTransform());
2587
+ }
2588
+ /**
2589
+ * Observes an existing agent builder action run stream using VNext streaming API.
2590
+ * Replays cached execution from the beginning, then continues with live stream.
2591
+ * This calls `/api/agent-builder/:actionId/observe-streamVNext`.
2592
+ */
2593
+ async observeStreamVNext(params) {
2594
+ const searchParams = new URLSearchParams();
2595
+ searchParams.set("runId", params.runId);
2596
+ const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
2597
+ const response = await this.request(url, {
2598
+ method: "POST",
2599
+ stream: true
2600
+ });
2601
+ if (!response.ok) {
2602
+ throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
2603
+ }
2604
+ if (!response.body) {
2605
+ throw new Error("Response body is null");
2606
+ }
2607
+ return response.body.pipeThrough(this.createRecordParserTransform());
2608
+ }
2609
+ /**
2610
+ * Observes an existing agent builder action run stream using legacy streaming API.
2611
+ * Replays cached execution from the beginning, then continues with live stream.
2612
+ * This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
2613
+ */
2614
+ async observeStreamLegacy(params) {
2615
+ const searchParams = new URLSearchParams();
2616
+ searchParams.set("runId", params.runId);
2617
+ const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
2618
+ const response = await this.request(url, {
2619
+ method: "POST",
2620
+ stream: true
2621
+ });
2622
+ if (!response.ok) {
2623
+ throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
2624
+ }
2625
+ if (!response.body) {
2626
+ throw new Error("Response body is null");
2627
+ }
2628
+ return response.body.pipeThrough(this.createRecordParserTransform());
2629
+ }
2630
+ /**
2631
+ * Resumes a suspended agent builder action and streams the results.
2632
+ * This calls `/api/agent-builder/:actionId/resume-stream`.
2633
+ */
2634
+ async resumeStream(params) {
2635
+ const searchParams = new URLSearchParams();
2636
+ searchParams.set("runId", params.runId);
2637
+ const requestContext = parseClientRequestContext(params.requestContext);
2638
+ const { runId: _, requestContext: __, ...resumeParams } = params;
2639
+ const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
2640
+ const response = await this.request(url, {
2641
+ method: "POST",
2642
+ body: { ...resumeParams, requestContext },
2643
+ stream: true
2644
+ });
2645
+ if (!response.ok) {
2646
+ throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
2647
+ }
2648
+ if (!response.body) {
2649
+ throw new Error("Response body is null");
2650
+ }
2651
+ return response.body.pipeThrough(this.createRecordParserTransform());
2652
+ }
2573
2653
  /**
2574
2654
  * Gets a specific action run by its ID.
2575
2655
  * This calls `/api/agent-builder/:actionId/runs/:runId`.
@@ -2723,69 +2803,6 @@ var Observability = class extends BaseResource {
2723
2803
  }
2724
2804
  };
2725
2805
 
2726
- // src/resources/network-memory-thread.ts
2727
- var NetworkMemoryThread = class extends BaseResource {
2728
- constructor(options, threadId, networkId) {
2729
- super(options);
2730
- this.threadId = threadId;
2731
- this.networkId = networkId;
2732
- }
2733
- /**
2734
- * Retrieves the memory thread details
2735
- * @returns Promise containing thread details including title and metadata
2736
- */
2737
- get() {
2738
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
2739
- }
2740
- /**
2741
- * Updates the memory thread properties
2742
- * @param params - Update parameters including title and metadata
2743
- * @returns Promise containing updated thread details
2744
- */
2745
- update(params) {
2746
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2747
- method: "PATCH",
2748
- body: params
2749
- });
2750
- }
2751
- /**
2752
- * Deletes the memory thread
2753
- * @returns Promise containing deletion result
2754
- */
2755
- delete() {
2756
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2757
- method: "DELETE"
2758
- });
2759
- }
2760
- /**
2761
- * Retrieves messages associated with the thread
2762
- * @param params - Optional parameters including limit for number of messages to retrieve
2763
- * @returns Promise containing thread messages and UI messages
2764
- */
2765
- getMessages(params) {
2766
- const query = new URLSearchParams({
2767
- networkId: this.networkId,
2768
- ...params?.limit ? { limit: params.limit.toString() } : {}
2769
- });
2770
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
2771
- }
2772
- /**
2773
- * Deletes one or more messages from the thread
2774
- * @param messageIds - Can be a single message ID (string), array of message IDs,
2775
- * message object with id property, or array of message objects
2776
- * @returns Promise containing deletion result
2777
- */
2778
- deleteMessages(messageIds) {
2779
- const query = new URLSearchParams({
2780
- networkId: this.networkId
2781
- });
2782
- return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
2783
- method: "POST",
2784
- body: { messageIds }
2785
- });
2786
- }
2787
- };
2788
-
2789
2806
  // src/client.ts
2790
2807
  var MastraClient = class extends BaseResource {
2791
2808
  observability;
@@ -2795,18 +2812,21 @@ var MastraClient = class extends BaseResource {
2795
2812
  }
2796
2813
  /**
2797
2814
  * Retrieves all available agents
2798
- * @param runtimeContext - Optional runtime context to pass as query parameter
2815
+ * @param requestContext - Optional request context to pass as query parameter
2799
2816
  * @returns Promise containing map of agent IDs to agent details
2800
2817
  */
2801
- getAgents(runtimeContext) {
2802
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2818
+ listAgents(requestContext) {
2819
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2803
2820
  const searchParams = new URLSearchParams();
2804
- if (runtimeContextParam) {
2805
- searchParams.set("runtimeContext", runtimeContextParam);
2821
+ if (requestContextParam) {
2822
+ searchParams.set("requestContext", requestContextParam);
2806
2823
  }
2807
2824
  const queryString = searchParams.toString();
2808
2825
  return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2809
2826
  }
2827
+ listAgentsModelProviders() {
2828
+ return this.request(`/api/agents/providers`);
2829
+ }
2810
2830
  /**
2811
2831
  * Gets an agent instance by ID
2812
2832
  * @param agentId - ID of the agent to retrieve
@@ -2816,125 +2836,103 @@ var MastraClient = class extends BaseResource {
2816
2836
  return new Agent(this.options, agentId);
2817
2837
  }
2818
2838
  /**
2819
- * Retrieves memory threads for a resource
2820
- * @param params - Parameters containing the resource ID
2821
- * @returns Promise containing array of memory threads
2839
+ * Lists memory threads for a resource with pagination support
2840
+ * @param params - Parameters containing resource ID, pagination options, and optional request context
2841
+ * @returns Promise containing paginated array of memory threads with metadata
2822
2842
  */
2823
- getMemoryThreads(params) {
2824
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2843
+ listMemoryThreads(params) {
2844
+ const queryParams = new URLSearchParams({
2845
+ resourceId: params.resourceId,
2846
+ agentId: params.agentId,
2847
+ ...params.offset !== void 0 && { offset: params.offset.toString() },
2848
+ ...params.limit !== void 0 && { limit: params.limit.toString() },
2849
+ ...params.orderBy && { orderBy: params.orderBy },
2850
+ ...params.sortDirection && { sortDirection: params.sortDirection }
2851
+ });
2852
+ return this.request(
2853
+ `/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
2854
+ );
2825
2855
  }
2826
2856
  /**
2827
2857
  * Retrieves memory config for a resource
2828
- * @param params - Parameters containing the resource ID
2829
- * @returns Promise containing array of memory threads
2858
+ * @param params - Parameters containing the resource ID and optional request context
2859
+ * @returns Promise containing memory configuration
2830
2860
  */
2831
2861
  getMemoryConfig(params) {
2832
- return this.request(`/api/memory/config?agentId=${params.agentId}`);
2862
+ return this.request(
2863
+ `/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
2864
+ );
2833
2865
  }
2834
2866
  /**
2835
2867
  * Creates a new memory thread
2836
- * @param params - Parameters for creating the memory thread
2868
+ * @param params - Parameters for creating the memory thread including optional request context
2837
2869
  * @returns Promise containing the created memory thread
2838
2870
  */
2839
2871
  createMemoryThread(params) {
2840
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
2872
+ return this.request(
2873
+ `/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2874
+ { method: "POST", body: params }
2875
+ );
2841
2876
  }
2842
2877
  /**
2843
2878
  * Gets a memory thread instance by ID
2844
2879
  * @param threadId - ID of the memory thread to retrieve
2845
2880
  * @returns MemoryThread instance
2846
2881
  */
2847
- getMemoryThread(threadId, agentId) {
2882
+ getMemoryThread({ threadId, agentId }) {
2848
2883
  return new MemoryThread(this.options, threadId, agentId);
2849
2884
  }
2850
2885
  getThreadMessages(threadId, opts = {}) {
2851
2886
  let url = "";
2852
2887
  if (opts.agentId) {
2853
- url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2888
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2854
2889
  } else if (opts.networkId) {
2855
- url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2890
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2856
2891
  }
2857
2892
  return this.request(url);
2858
2893
  }
2859
2894
  deleteThread(threadId, opts = {}) {
2860
2895
  let url = "";
2861
2896
  if (opts.agentId) {
2862
- url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2897
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2863
2898
  } else if (opts.networkId) {
2864
- url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2899
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2865
2900
  }
2866
2901
  return this.request(url, { method: "DELETE" });
2867
2902
  }
2868
2903
  /**
2869
2904
  * Saves messages to memory
2870
- * @param params - Parameters containing messages to save
2905
+ * @param params - Parameters containing messages to save and optional request context
2871
2906
  * @returns Promise containing the saved messages
2872
2907
  */
2873
2908
  saveMessageToMemory(params) {
2874
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
2875
- method: "POST",
2876
- body: params
2877
- });
2878
- }
2879
- /**
2880
- * Gets the status of the memory system
2881
- * @returns Promise containing memory system status
2882
- */
2883
- getMemoryStatus(agentId) {
2884
- return this.request(`/api/memory/status?agentId=${agentId}`);
2885
- }
2886
- /**
2887
- * Retrieves memory threads for a resource
2888
- * @param params - Parameters containing the resource ID
2889
- * @returns Promise containing array of memory threads
2890
- */
2891
- getNetworkMemoryThreads(params) {
2892
- return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
2893
- }
2894
- /**
2895
- * Creates a new memory thread
2896
- * @param params - Parameters for creating the memory thread
2897
- * @returns Promise containing the created memory thread
2898
- */
2899
- createNetworkMemoryThread(params) {
2900
- return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
2901
- }
2902
- /**
2903
- * Gets a memory thread instance by ID
2904
- * @param threadId - ID of the memory thread to retrieve
2905
- * @returns MemoryThread instance
2906
- */
2907
- getNetworkMemoryThread(threadId, networkId) {
2908
- return new NetworkMemoryThread(this.options, threadId, networkId);
2909
- }
2910
- /**
2911
- * Saves messages to memory
2912
- * @param params - Parameters containing messages to save
2913
- * @returns Promise containing the saved messages
2914
- */
2915
- saveNetworkMessageToMemory(params) {
2916
- return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
2917
- method: "POST",
2918
- body: params
2919
- });
2909
+ return this.request(
2910
+ `/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2911
+ {
2912
+ method: "POST",
2913
+ body: params
2914
+ }
2915
+ );
2920
2916
  }
2921
2917
  /**
2922
2918
  * Gets the status of the memory system
2919
+ * @param agentId - The agent ID
2920
+ * @param requestContext - Optional request context to pass as query parameter
2923
2921
  * @returns Promise containing memory system status
2924
2922
  */
2925
- getNetworkMemoryStatus(networkId) {
2926
- return this.request(`/api/memory/network/status?networkId=${networkId}`);
2923
+ getMemoryStatus(agentId, requestContext) {
2924
+ return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
2927
2925
  }
2928
2926
  /**
2929
2927
  * Retrieves all available tools
2930
- * @param runtimeContext - Optional runtime context to pass as query parameter
2928
+ * @param requestContext - Optional request context to pass as query parameter
2931
2929
  * @returns Promise containing map of tool IDs to tool details
2932
2930
  */
2933
- getTools(runtimeContext) {
2934
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2931
+ listTools(requestContext) {
2932
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2935
2933
  const searchParams = new URLSearchParams();
2936
- if (runtimeContextParam) {
2937
- searchParams.set("runtimeContext", runtimeContextParam);
2934
+ if (requestContextParam) {
2935
+ searchParams.set("requestContext", requestContextParam);
2938
2936
  }
2939
2937
  const queryString = searchParams.toString();
2940
2938
  return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
@@ -2949,14 +2947,14 @@ var MastraClient = class extends BaseResource {
2949
2947
  }
2950
2948
  /**
2951
2949
  * Retrieves all available workflows
2952
- * @param runtimeContext - Optional runtime context to pass as query parameter
2950
+ * @param requestContext - Optional request context to pass as query parameter
2953
2951
  * @returns Promise containing map of workflow IDs to workflow details
2954
2952
  */
2955
- getWorkflows(runtimeContext) {
2956
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2953
+ listWorkflows(requestContext) {
2954
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2957
2955
  const searchParams = new URLSearchParams();
2958
- if (runtimeContextParam) {
2959
- searchParams.set("runtimeContext", runtimeContextParam);
2956
+ if (requestContextParam) {
2957
+ searchParams.set("requestContext", requestContextParam);
2960
2958
  }
2961
2959
  const queryString = searchParams.toString();
2962
2960
  return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
@@ -2996,7 +2994,7 @@ var MastraClient = class extends BaseResource {
2996
2994
  * @param params - Parameters for filtering logs
2997
2995
  * @returns Promise containing array of log messages
2998
2996
  */
2999
- getLogs(params) {
2997
+ listLogs(params) {
3000
2998
  const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
3001
2999
  const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
3002
3000
  const searchParams = new URLSearchParams();
@@ -3082,7 +3080,7 @@ var MastraClient = class extends BaseResource {
3082
3080
  * List of all log transports
3083
3081
  * @returns Promise containing list of log transports
3084
3082
  */
3085
- getLogTransports() {
3083
+ listLogTransports() {
3086
3084
  return this.request("/api/logs/transports");
3087
3085
  }
3088
3086
  /**
@@ -3151,16 +3149,20 @@ var MastraClient = class extends BaseResource {
3151
3149
  getWorkingMemory({
3152
3150
  agentId,
3153
3151
  threadId,
3154
- resourceId
3152
+ resourceId,
3153
+ requestContext
3155
3154
  }) {
3156
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3155
+ return this.request(
3156
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
3157
+ );
3157
3158
  }
3158
3159
  searchMemory({
3159
3160
  agentId,
3160
3161
  resourceId,
3161
3162
  threadId,
3162
3163
  searchQuery,
3163
- memoryConfig
3164
+ memoryConfig,
3165
+ requestContext
3164
3166
  }) {
3165
3167
  const params = new URLSearchParams({
3166
3168
  searchQuery,
@@ -3173,7 +3175,7 @@ var MastraClient = class extends BaseResource {
3173
3175
  if (memoryConfig) {
3174
3176
  params.append("memoryConfig", JSON.stringify(memoryConfig));
3175
3177
  }
3176
- return this.request(`/api/memory/search?${params}`);
3178
+ return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
3177
3179
  }
3178
3180
  /**
3179
3181
  * Updates the working memory for a specific thread (optionally resource-scoped).
@@ -3186,21 +3188,25 @@ var MastraClient = class extends BaseResource {
3186
3188
  agentId,
3187
3189
  threadId,
3188
3190
  workingMemory,
3189
- resourceId
3191
+ resourceId,
3192
+ requestContext
3190
3193
  }) {
3191
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3192
- method: "POST",
3193
- body: {
3194
- workingMemory,
3195
- resourceId
3194
+ return this.request(
3195
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
3196
+ {
3197
+ method: "POST",
3198
+ body: {
3199
+ workingMemory,
3200
+ resourceId
3201
+ }
3196
3202
  }
3197
- });
3203
+ );
3198
3204
  }
3199
3205
  /**
3200
3206
  * Retrieves all available scorers
3201
3207
  * @returns Promise containing list of available scorers
3202
3208
  */
3203
- getScorers() {
3209
+ listScorers() {
3204
3210
  return this.request("/api/scores/scorers");
3205
3211
  }
3206
3212
  /**