@mastra/client-js 0.0.0-ai-sdk-workflow-route-20251010135341 → 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938

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,33 +1,34 @@
1
1
  import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
2
2
  import { v4 } from '@lukeed/uuid';
3
- import { RuntimeContext } from '@mastra/core/runtime-context';
3
+ import { getErrorFromUnknown } from '@mastra/core/error';
4
+ import { RequestContext } from '@mastra/core/request-context';
4
5
  import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
5
6
  import { z } from 'zod';
6
7
  import originalZodToJsonSchema from 'zod-to-json-schema';
7
8
 
8
9
  // src/resources/agent.ts
9
- function parseClientRuntimeContext(runtimeContext) {
10
- if (runtimeContext) {
11
- if (runtimeContext instanceof RuntimeContext) {
12
- return Object.fromEntries(runtimeContext.entries());
10
+ function parseClientRequestContext(requestContext) {
11
+ if (requestContext) {
12
+ if (requestContext instanceof RequestContext) {
13
+ return Object.fromEntries(requestContext.entries());
13
14
  }
14
- return runtimeContext;
15
+ return requestContext;
15
16
  }
16
17
  return void 0;
17
18
  }
18
- function base64RuntimeContext(runtimeContext) {
19
- if (runtimeContext) {
20
- return btoa(JSON.stringify(runtimeContext));
19
+ function base64RequestContext(requestContext) {
20
+ if (requestContext) {
21
+ return btoa(JSON.stringify(requestContext));
21
22
  }
22
23
  return void 0;
23
24
  }
24
- function runtimeContextQueryString(runtimeContext) {
25
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
26
- if (!runtimeContextParam) return "";
25
+ function requestContextQueryString(requestContext, delimiter = "?") {
26
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
27
+ if (!requestContextParam) return "";
27
28
  const searchParams = new URLSearchParams();
28
- searchParams.set("runtimeContext", runtimeContextParam);
29
+ searchParams.set("requestContext", requestContextParam);
29
30
  const queryString = searchParams.toString();
30
- return queryString ? `?${queryString}` : "";
31
+ return queryString ? `${delimiter}${queryString}` : "";
31
32
  }
32
33
  function isZodType(value) {
33
34
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
@@ -94,11 +95,15 @@ async function sharedProcessMastraStream({
94
95
  console.info("\u{1F3C1} Stream finished");
95
96
  return;
96
97
  }
98
+ let json;
97
99
  try {
98
- const json = JSON.parse(data);
99
- await onChunk(json);
100
+ json = JSON.parse(data);
100
101
  } catch (error) {
101
102
  console.error("\u274C JSON parse error:", error, "Data:", data);
103
+ continue;
104
+ }
105
+ if (json) {
106
+ await onChunk(json);
102
107
  }
103
108
  }
104
109
  }
@@ -192,10 +197,9 @@ var BaseResource = class {
192
197
  async function executeToolCallAndRespond({
193
198
  response,
194
199
  params,
195
- runId,
196
200
  resourceId,
197
201
  threadId,
198
- runtimeContext,
202
+ requestContext,
199
203
  respondFn
200
204
  }) {
201
205
  if (response.finishReason === "tool-calls") {
@@ -206,22 +210,18 @@ async function executeToolCallAndRespond({
206
210
  for (const toolCall of toolCalls) {
207
211
  const clientTool = params.clientTools?.[toolCall.toolName];
208
212
  if (clientTool && clientTool.execute) {
209
- const result = await clientTool.execute(
210
- {
211
- context: toolCall?.args,
212
- runId,
213
- resourceId,
214
- threadId,
215
- runtimeContext,
216
- tracingContext: { currentSpan: void 0 },
217
- suspend: async () => {
218
- }
219
- },
220
- {
213
+ const result = await clientTool.execute(toolCall?.args, {
214
+ requestContext,
215
+ tracingContext: { currentSpan: void 0 },
216
+ agent: {
221
217
  messages: response.messages,
222
- toolCallId: toolCall?.toolCallId
218
+ toolCallId: toolCall?.toolCallId,
219
+ suspend: async () => {
220
+ },
221
+ threadId,
222
+ resourceId
223
223
  }
224
- );
224
+ });
225
225
  const updatedMessages = [
226
226
  ...response.response.messages || [],
227
227
  {
@@ -285,21 +285,21 @@ var AgentVoice = class extends BaseResource {
285
285
  }
286
286
  /**
287
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
288
+ * @param requestContext - Optional request context to pass as query parameter
289
+ * @param requestContext - Optional request context to pass as query parameter
290
290
  * @returns Promise containing list of available speakers
291
291
  */
292
- getSpeakers(runtimeContext) {
293
- return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
292
+ getSpeakers(requestContext) {
293
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${requestContextQueryString(requestContext)}`);
294
294
  }
295
295
  /**
296
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
297
+ * @param requestContext - Optional request context to pass as query parameter
298
+ * @param requestContext - Optional request context to pass as query parameter
299
299
  * @returns Promise containing a check if the agent has listening capabilities
300
300
  */
301
- getListener(runtimeContext) {
302
- return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
301
+ getListener(requestContext) {
302
+ return this.request(`/api/agents/${this.agentId}/voice/listener${requestContextQueryString(requestContext)}`);
303
303
  }
304
304
  };
305
305
  var Agent = class extends BaseResource {
@@ -311,21 +311,27 @@ var Agent = class extends BaseResource {
311
311
  voice;
312
312
  /**
313
313
  * Retrieves details about the agent
314
- * @param runtimeContext - Optional runtime context to pass as query parameter
314
+ * @param requestContext - Optional request context to pass as query parameter
315
315
  * @returns Promise containing agent details including model and instructions
316
316
  */
317
- details(runtimeContext) {
318
- return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
317
+ details(requestContext) {
318
+ return this.request(`/api/agents/${this.agentId}${requestContextQueryString(requestContext)}`);
319
+ }
320
+ enhanceInstructions(instructions, comment) {
321
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
322
+ method: "POST",
323
+ body: { instructions, comment }
324
+ });
319
325
  }
320
326
  async generateLegacy(params) {
321
327
  const processedParams = {
322
328
  ...params,
323
329
  output: params.output ? zodToJsonSchema(params.output) : void 0,
324
330
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
325
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
331
+ requestContext: parseClientRequestContext(params.requestContext),
326
332
  clientTools: processClientTools(params.clientTools)
327
333
  };
328
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
334
+ const { resourceId, threadId, requestContext } = processedParams;
329
335
  const response = await this.request(
330
336
  `/api/agents/${this.agentId}/generate-legacy`,
331
337
  {
@@ -341,22 +347,18 @@ var Agent = class extends BaseResource {
341
347
  for (const toolCall of toolCalls) {
342
348
  const clientTool = params.clientTools?.[toolCall.toolName];
343
349
  if (clientTool && clientTool.execute) {
344
- const result = await clientTool.execute(
345
- {
346
- context: toolCall?.args,
347
- runId,
348
- resourceId,
349
- threadId,
350
- runtimeContext,
351
- tracingContext: { currentSpan: void 0 },
352
- suspend: async () => {
353
- }
354
- },
355
- {
350
+ const result = await clientTool.execute(toolCall?.args, {
351
+ requestContext,
352
+ tracingContext: { currentSpan: void 0 },
353
+ agent: {
356
354
  messages: response.messages,
357
- toolCallId: toolCall?.toolCallId
355
+ toolCallId: toolCall?.toolCallId,
356
+ suspend: async () => {
357
+ },
358
+ threadId,
359
+ resourceId
358
360
  }
359
- );
361
+ });
360
362
  const updatedMessages = [
361
363
  ...response.response.messages,
362
364
  {
@@ -392,15 +394,14 @@ var Agent = class extends BaseResource {
392
394
  }
393
395
  const processedParams = {
394
396
  ...params,
395
- output: params.output ? zodToJsonSchema(params.output) : void 0,
396
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
397
+ requestContext: parseClientRequestContext(params.requestContext),
397
398
  clientTools: processClientTools(params.clientTools),
398
399
  structuredOutput: params.structuredOutput ? {
399
400
  ...params.structuredOutput,
400
401
  schema: zodToJsonSchema(params.structuredOutput.schema)
401
402
  } : void 0
402
403
  };
403
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
404
+ const { resourceId, threadId, requestContext } = processedParams;
404
405
  const response = await this.request(
405
406
  `/api/agents/${this.agentId}/generate`,
406
407
  {
@@ -412,10 +413,9 @@ var Agent = class extends BaseResource {
412
413
  return executeToolCallAndRespond({
413
414
  response,
414
415
  params,
415
- runId,
416
416
  resourceId,
417
417
  threadId,
418
- runtimeContext,
418
+ requestContext,
419
419
  respondFn: this.generate.bind(this)
420
420
  });
421
421
  }
@@ -693,7 +693,7 @@ var Agent = class extends BaseResource {
693
693
  ...params,
694
694
  output: params.output ? zodToJsonSchema(params.output) : void 0,
695
695
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
696
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
696
+ requestContext: parseClientRequestContext(params.requestContext),
697
697
  clientTools: processClientTools(params.clientTools)
698
698
  };
699
699
  const { readable, writable } = new TransformStream();
@@ -945,7 +945,10 @@ var Agent = class extends BaseResource {
945
945
  break;
946
946
  }
947
947
  case "error": {
948
- throw new Error(chunk.payload.error);
948
+ throw getErrorFromUnknown(chunk.payload.error, {
949
+ fallbackMessage: "Unknown error in stream",
950
+ supportSerialization: false
951
+ });
949
952
  }
950
953
  case "data": {
951
954
  data.push(...chunk.payload.data);
@@ -972,8 +975,8 @@ var Agent = class extends BaseResource {
972
975
  });
973
976
  onFinish?.({ message, finishReason, usage });
974
977
  }
975
- async processStreamResponse(processedParams, writable) {
976
- const response = await this.request(`/api/agents/${this.agentId}/stream`, {
978
+ async processStreamResponse(processedParams, writable, route = "stream") {
979
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
977
980
  method: "POST",
978
981
  body: processedParams,
979
982
  stream: true
@@ -1029,23 +1032,19 @@ var Agent = class extends BaseResource {
1029
1032
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1030
1033
  if (clientTool && clientTool.execute) {
1031
1034
  shouldExecuteClientTool = true;
1032
- const result = await clientTool.execute(
1033
- {
1034
- context: toolCall2?.args,
1035
- runId: processedParams.runId,
1036
- resourceId: processedParams.resourceId,
1037
- threadId: processedParams.threadId,
1038
- runtimeContext: processedParams.runtimeContext,
1039
- // TODO: Pass proper tracing context when client-js supports tracing
1040
- tracingContext: { currentSpan: void 0 },
1041
- suspend: async () => {
1042
- }
1043
- },
1044
- {
1035
+ const result = await clientTool.execute(toolCall2?.args, {
1036
+ requestContext: processedParams.requestContext,
1037
+ // TODO: Pass proper tracing context when client-js supports tracing
1038
+ tracingContext: { currentSpan: void 0 },
1039
+ agent: {
1045
1040
  messages: response.messages,
1046
- toolCallId: toolCall2?.toolCallId
1041
+ toolCallId: toolCall2?.toolCallId,
1042
+ suspend: async () => {
1043
+ },
1044
+ threadId: processedParams.threadId,
1045
+ resourceId: processedParams.resourceId
1047
1046
  }
1048
- );
1047
+ });
1049
1048
  const lastMessageRaw = messages[messages.length - 1];
1050
1049
  const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
1051
1050
  const toolInvocationPart = lastMessage?.parts?.find(
@@ -1133,8 +1132,7 @@ var Agent = class extends BaseResource {
1133
1132
  }
1134
1133
  const processedParams = {
1135
1134
  ...params,
1136
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1137
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1135
+ requestContext: parseClientRequestContext(params.requestContext),
1138
1136
  clientTools: processClientTools(params.clientTools),
1139
1137
  structuredOutput: params.structuredOutput ? {
1140
1138
  ...params.structuredOutput,
@@ -1158,6 +1156,42 @@ var Agent = class extends BaseResource {
1158
1156
  };
1159
1157
  return streamResponse;
1160
1158
  }
1159
+ async approveToolCall(params) {
1160
+ const { readable, writable } = new TransformStream();
1161
+ const response = await this.processStreamResponse(params, writable, "approve-tool-call");
1162
+ const streamResponse = new Response(readable, {
1163
+ status: response.status,
1164
+ statusText: response.statusText,
1165
+ headers: response.headers
1166
+ });
1167
+ streamResponse.processDataStream = async ({
1168
+ onChunk
1169
+ }) => {
1170
+ await processMastraStream({
1171
+ stream: streamResponse.body,
1172
+ onChunk
1173
+ });
1174
+ };
1175
+ return streamResponse;
1176
+ }
1177
+ async declineToolCall(params) {
1178
+ const { readable, writable } = new TransformStream();
1179
+ const response = await this.processStreamResponse(params, writable, "decline-tool-call");
1180
+ const streamResponse = new Response(readable, {
1181
+ status: response.status,
1182
+ statusText: response.statusText,
1183
+ headers: response.headers
1184
+ });
1185
+ streamResponse.processDataStream = async ({
1186
+ onChunk
1187
+ }) => {
1188
+ await processMastraStream({
1189
+ stream: streamResponse.body,
1190
+ onChunk
1191
+ });
1192
+ };
1193
+ return streamResponse;
1194
+ }
1161
1195
  /**
1162
1196
  * Processes the stream response and handles tool calls
1163
1197
  */
@@ -1198,23 +1232,19 @@ var Agent = class extends BaseResource {
1198
1232
  for (const toolCall2 of toolCalls) {
1199
1233
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1200
1234
  if (clientTool && clientTool.execute) {
1201
- const result = await clientTool.execute(
1202
- {
1203
- context: toolCall2?.args,
1204
- runId: processedParams.runId,
1205
- resourceId: processedParams.resourceId,
1206
- threadId: processedParams.threadId,
1207
- runtimeContext: processedParams.runtimeContext,
1208
- // TODO: Pass proper tracing context when client-js supports tracing
1209
- tracingContext: { currentSpan: void 0 },
1210
- suspend: async () => {
1211
- }
1212
- },
1213
- {
1235
+ const result = await clientTool.execute(toolCall2?.args, {
1236
+ requestContext: processedParams.requestContext,
1237
+ // TODO: Pass proper tracing context when client-js supports tracing
1238
+ tracingContext: { currentSpan: void 0 },
1239
+ agent: {
1214
1240
  messages: response.messages,
1215
- toolCallId: toolCall2?.toolCallId
1241
+ toolCallId: toolCall2?.toolCallId,
1242
+ suspend: async () => {
1243
+ },
1244
+ threadId: processedParams.threadId,
1245
+ resourceId: processedParams.resourceId
1216
1246
  }
1217
- );
1247
+ });
1218
1248
  const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1219
1249
  const toolInvocationPart = lastMessage?.parts?.find(
1220
1250
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
@@ -1275,11 +1305,11 @@ var Agent = class extends BaseResource {
1275
1305
  /**
1276
1306
  * Gets details about a specific tool available to the agent
1277
1307
  * @param toolId - ID of the tool to retrieve
1278
- * @param runtimeContext - Optional runtime context to pass as query parameter
1308
+ * @param requestContext - Optional request context to pass as query parameter
1279
1309
  * @returns Promise containing tool details
1280
1310
  */
1281
- getTool(toolId, runtimeContext) {
1282
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1311
+ getTool(toolId, requestContext) {
1312
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
1283
1313
  }
1284
1314
  /**
1285
1315
  * Executes a tool for the agent
@@ -1290,29 +1320,13 @@ var Agent = class extends BaseResource {
1290
1320
  executeTool(toolId, params) {
1291
1321
  const body = {
1292
1322
  data: params.data,
1293
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1323
+ requestContext: parseClientRequestContext(params.requestContext)
1294
1324
  };
1295
1325
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1296
1326
  method: "POST",
1297
1327
  body
1298
1328
  });
1299
1329
  }
1300
- /**
1301
- * Retrieves evaluation results for the agent
1302
- * @param runtimeContext - Optional runtime context to pass as query parameter
1303
- * @returns Promise containing agent evaluations
1304
- */
1305
- evals(runtimeContext) {
1306
- return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1307
- }
1308
- /**
1309
- * Retrieves live evaluation results for the agent
1310
- * @param runtimeContext - Optional runtime context to pass as query parameter
1311
- * @returns Promise containing live agent evaluations
1312
- */
1313
- liveEvals(runtimeContext) {
1314
- return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1315
- }
1316
1330
  /**
1317
1331
  * Updates the model for the agent
1318
1332
  * @param params - Parameters for updating the model
@@ -1324,6 +1338,15 @@ var Agent = class extends BaseResource {
1324
1338
  body: params
1325
1339
  });
1326
1340
  }
1341
+ /**
1342
+ * Resets the agent's model to the original model that was set during construction
1343
+ * @returns Promise containing a success message
1344
+ */
1345
+ resetModel() {
1346
+ return this.request(`/api/agents/${this.agentId}/model/reset`, {
1347
+ method: "POST"
1348
+ });
1349
+ }
1327
1350
  /**
1328
1351
  * Updates the model for the agent in the model list
1329
1352
  * @param params - Parameters for updating the model
@@ -1346,12 +1369,6 @@ var Agent = class extends BaseResource {
1346
1369
  body: params
1347
1370
  });
1348
1371
  }
1349
- async generateVNext(_messagesOrParams, _options) {
1350
- throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1351
- }
1352
- async streamVNext(_messagesOrParams, _options) {
1353
- throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1354
- }
1355
1372
  };
1356
1373
 
1357
1374
  // src/resources/memory-thread.ts
@@ -1363,72 +1380,78 @@ var MemoryThread = class extends BaseResource {
1363
1380
  }
1364
1381
  /**
1365
1382
  * Retrieves the memory thread details
1383
+ * @param requestContext - Optional request context to pass as query parameter
1366
1384
  * @returns Promise containing thread details including title and metadata
1367
1385
  */
1368
- get() {
1369
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
1386
+ get(requestContext) {
1387
+ return this.request(
1388
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
1389
+ );
1370
1390
  }
1371
1391
  /**
1372
1392
  * Updates the memory thread properties
1373
- * @param params - Update parameters including title and metadata
1393
+ * @param params - Update parameters including title, metadata, and optional request context
1374
1394
  * @returns Promise containing updated thread details
1375
1395
  */
1376
1396
  update(params) {
1377
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1378
- method: "PATCH",
1379
- body: params
1380
- });
1397
+ return this.request(
1398
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
1399
+ {
1400
+ method: "PATCH",
1401
+ body: params
1402
+ }
1403
+ );
1381
1404
  }
1382
1405
  /**
1383
1406
  * Deletes the memory thread
1407
+ * @param requestContext - Optional request context to pass as query parameter
1384
1408
  * @returns Promise containing deletion result
1385
1409
  */
1386
- delete() {
1387
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1388
- method: "DELETE"
1389
- });
1390
- }
1391
- /**
1392
- * Retrieves messages associated with the thread
1393
- * @param params - Optional parameters including limit for number of messages to retrieve
1394
- * @returns Promise containing thread messages and UI messages
1395
- */
1396
- getMessages(params) {
1397
- const query = new URLSearchParams({
1398
- agentId: this.agentId,
1399
- ...params?.limit ? { limit: params.limit.toString() } : {}
1400
- });
1401
- return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
1410
+ delete(requestContext) {
1411
+ return this.request(
1412
+ `/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
1413
+ {
1414
+ method: "DELETE"
1415
+ }
1416
+ );
1402
1417
  }
1403
1418
  /**
1404
- * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1405
- * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1419
+ * Retrieves paginated messages associated with the thread with filtering and ordering options
1420
+ * @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
1406
1421
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1407
1422
  */
1408
- getMessagesPaginated({
1409
- selectBy,
1410
- ...rest
1411
- }) {
1412
- const query = new URLSearchParams({
1413
- ...rest,
1414
- ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1415
- });
1416
- return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1423
+ listMessages(params = {}) {
1424
+ const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
1425
+ const queryParams = {};
1426
+ if (resourceId) queryParams.resourceId = resourceId;
1427
+ if (page !== void 0) queryParams.page = String(page);
1428
+ if (perPage !== void 0) queryParams.perPage = String(perPage);
1429
+ if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
1430
+ if (filter) queryParams.filter = JSON.stringify(filter);
1431
+ if (include) queryParams.include = JSON.stringify(include);
1432
+ const query = new URLSearchParams(queryParams);
1433
+ const queryString = query.toString();
1434
+ const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
1435
+ return this.request(url);
1417
1436
  }
1418
1437
  /**
1419
1438
  * Deletes one or more messages from the thread
1420
1439
  * @param messageIds - Can be a single message ID (string), array of message IDs,
1421
1440
  * message object with id property, or array of message objects
1441
+ * @param requestContext - Optional request context to pass as query parameter
1422
1442
  * @returns Promise containing deletion result
1423
1443
  */
1424
- deleteMessages(messageIds) {
1444
+ deleteMessages(messageIds, requestContext) {
1425
1445
  const query = new URLSearchParams({
1426
1446
  agentId: this.agentId
1427
1447
  });
1428
- return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1429
- method: "POST",
1430
- body: { messageIds }
1431
- });
1448
+ return this.request(
1449
+ `/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
1450
+ {
1451
+ method: "POST",
1452
+ body: { messageIds }
1453
+ }
1454
+ );
1432
1455
  }
1433
1456
  };
1434
1457
 
@@ -1441,12 +1464,12 @@ var Vector = class extends BaseResource {
1441
1464
  /**
1442
1465
  * Retrieves details about a specific vector index
1443
1466
  * @param indexName - Name of the index to get details for
1444
- * @param runtimeContext - Optional runtime context to pass as query parameter
1467
+ * @param requestContext - Optional request context to pass as query parameter
1445
1468
  * @returns Promise containing vector index details
1446
1469
  */
1447
- details(indexName, runtimeContext) {
1470
+ details(indexName, requestContext) {
1448
1471
  return this.request(
1449
- `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1472
+ `/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
1450
1473
  );
1451
1474
  }
1452
1475
  /**
@@ -1461,11 +1484,11 @@ var Vector = class extends BaseResource {
1461
1484
  }
1462
1485
  /**
1463
1486
  * Retrieves a list of all available indexes
1464
- * @param runtimeContext - Optional runtime context to pass as query parameter
1487
+ * @param requestContext - Optional request context to pass as query parameter
1465
1488
  * @returns Promise containing array of index names
1466
1489
  */
1467
- getIndexes(runtimeContext) {
1468
- return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1490
+ getIndexes(requestContext) {
1491
+ return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
1469
1492
  }
1470
1493
  /**
1471
1494
  * Creates a new vector index
@@ -1510,11 +1533,11 @@ var Tool = class extends BaseResource {
1510
1533
  }
1511
1534
  /**
1512
1535
  * Retrieves details about the tool
1513
- * @param runtimeContext - Optional runtime context to pass as query parameter
1536
+ * @param requestContext - Optional request context to pass as query parameter
1514
1537
  * @returns Promise containing tool details including description and schemas
1515
1538
  */
1516
- details(runtimeContext) {
1517
- return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1539
+ details(requestContext) {
1540
+ return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
1518
1541
  }
1519
1542
  /**
1520
1543
  * Executes the tool with the provided parameters
@@ -1528,7 +1551,7 @@ var Tool = class extends BaseResource {
1528
1551
  }
1529
1552
  const body = {
1530
1553
  data: params.data,
1531
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1554
+ requestContext: parseClientRequestContext(params.requestContext)
1532
1555
  };
1533
1556
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1534
1557
  method: "POST",
@@ -1544,67 +1567,22 @@ var Workflow = class extends BaseResource {
1544
1567
  super(options);
1545
1568
  this.workflowId = workflowId;
1546
1569
  }
1547
- /**
1548
- * Creates an async generator that processes a readable stream and yields workflow records
1549
- * separated by the Record Separator character (\x1E)
1550
- *
1551
- * @param stream - The readable stream to process
1552
- * @returns An async generator that yields parsed records
1553
- */
1554
- async *streamProcessor(stream) {
1555
- const reader = stream.getReader();
1556
- let doneReading = false;
1557
- let buffer = "";
1558
- try {
1559
- while (!doneReading) {
1560
- const { done, value } = await reader.read();
1561
- doneReading = done;
1562
- if (done && !value) continue;
1563
- try {
1564
- const decoded = value ? new TextDecoder().decode(value) : "";
1565
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1566
- buffer = chunks.pop() || "";
1567
- for (const chunk of chunks) {
1568
- if (chunk) {
1569
- if (typeof chunk === "string") {
1570
- try {
1571
- const parsedChunk = JSON.parse(chunk);
1572
- yield parsedChunk;
1573
- } catch {
1574
- }
1575
- }
1576
- }
1577
- }
1578
- } catch {
1579
- }
1580
- }
1581
- if (buffer) {
1582
- try {
1583
- yield JSON.parse(buffer);
1584
- } catch {
1585
- }
1586
- }
1587
- } finally {
1588
- reader.cancel().catch(() => {
1589
- });
1590
- }
1591
- }
1592
1570
  /**
1593
1571
  * Retrieves details about the workflow
1594
- * @param runtimeContext - Optional runtime context to pass as query parameter
1572
+ * @param requestContext - Optional request context to pass as query parameter
1595
1573
  * @returns Promise containing workflow details including steps and graphs
1596
1574
  */
1597
- details(runtimeContext) {
1598
- return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1575
+ details(requestContext) {
1576
+ return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
1599
1577
  }
1600
1578
  /**
1601
1579
  * Retrieves all runs for a workflow
1602
1580
  * @param params - Parameters for filtering runs
1603
- * @param runtimeContext - Optional runtime context to pass as query parameter
1581
+ * @param requestContext - Optional request context to pass as query parameter
1604
1582
  * @returns Promise containing workflow runs array
1605
1583
  */
1606
- runs(params, runtimeContext) {
1607
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1584
+ runs(params, requestContext) {
1585
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
1608
1586
  const searchParams = new URLSearchParams();
1609
1587
  if (params?.fromDate) {
1610
1588
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1612,17 +1590,21 @@ var Workflow = class extends BaseResource {
1612
1590
  if (params?.toDate) {
1613
1591
  searchParams.set("toDate", params.toDate.toISOString());
1614
1592
  }
1615
- if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1616
- searchParams.set("limit", String(params.limit));
1593
+ if (params?.perPage !== null && params?.perPage !== void 0) {
1594
+ if (params.perPage === false) {
1595
+ searchParams.set("perPage", "false");
1596
+ } else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
1597
+ searchParams.set("perPage", String(params.perPage));
1598
+ }
1617
1599
  }
1618
- if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1619
- searchParams.set("offset", String(params.offset));
1600
+ if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
1601
+ searchParams.set("page", String(params.page));
1620
1602
  }
1621
1603
  if (params?.resourceId) {
1622
1604
  searchParams.set("resourceId", params.resourceId);
1623
1605
  }
1624
- if (runtimeContextParam) {
1625
- searchParams.set("runtimeContext", runtimeContextParam);
1606
+ if (requestContextParam) {
1607
+ searchParams.set("requestContext", requestContextParam);
1626
1608
  }
1627
1609
  if (searchParams.size) {
1628
1610
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
@@ -1633,21 +1615,21 @@ var Workflow = class extends BaseResource {
1633
1615
  /**
1634
1616
  * Retrieves a specific workflow run by its ID
1635
1617
  * @param runId - The ID of the workflow run to retrieve
1636
- * @param runtimeContext - Optional runtime context to pass as query parameter
1618
+ * @param requestContext - Optional request context to pass as query parameter
1637
1619
  * @returns Promise containing the workflow run details
1638
1620
  */
1639
- runById(runId, runtimeContext) {
1640
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1621
+ runById(runId, requestContext) {
1622
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
1641
1623
  }
1642
1624
  /**
1643
1625
  * Retrieves the execution result for a specific workflow run by its ID
1644
1626
  * @param runId - The ID of the workflow run to retrieve the execution result for
1645
- * @param runtimeContext - Optional runtime context to pass as query parameter
1627
+ * @param requestContext - Optional request context to pass as query parameter
1646
1628
  * @returns Promise containing the workflow run execution result
1647
1629
  */
1648
- runExecutionResult(runId, runtimeContext) {
1630
+ runExecutionResult(runId, requestContext) {
1649
1631
  return this.request(
1650
- `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1632
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
1651
1633
  );
1652
1634
  }
1653
1635
  /**
@@ -1660,32 +1642,12 @@ var Workflow = class extends BaseResource {
1660
1642
  method: "POST"
1661
1643
  });
1662
1644
  }
1663
- /**
1664
- * Sends an event to a specific workflow run by its ID
1665
- * @param params - Object containing the runId, event and data
1666
- * @returns Promise containing a success message
1667
- */
1668
- sendRunEvent(params) {
1669
- return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1670
- method: "POST",
1671
- body: { event: params.event, data: params.data }
1672
- });
1673
- }
1674
- /**
1675
- * @deprecated Use createRunAsync() instead.
1676
- * @throws {Error} Always throws an error directing users to use createRunAsync()
1677
- */
1678
- async createRun(_params) {
1679
- throw new Error(
1680
- "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."
1681
- );
1682
- }
1683
1645
  /**
1684
1646
  * Creates a new workflow run
1685
1647
  * @param params - Optional object containing the optional runId
1686
1648
  * @returns Promise containing the runId of the created run with methods to control execution
1687
1649
  */
1688
- async createRunAsync(params) {
1650
+ async createRun(params) {
1689
1651
  const searchParams = new URLSearchParams();
1690
1652
  if (!!params?.runId) {
1691
1653
  searchParams.set("runId", params.runId);
@@ -1703,7 +1665,7 @@ var Workflow = class extends BaseResource {
1703
1665
  return this.start({
1704
1666
  runId,
1705
1667
  inputData: p.inputData,
1706
- runtimeContext: p.runtimeContext,
1668
+ requestContext: p.requestContext,
1707
1669
  tracingOptions: p.tracingOptions
1708
1670
  });
1709
1671
  },
@@ -1711,22 +1673,19 @@ var Workflow = class extends BaseResource {
1711
1673
  return this.startAsync({
1712
1674
  runId,
1713
1675
  inputData: p.inputData,
1714
- runtimeContext: p.runtimeContext,
1676
+ requestContext: p.requestContext,
1715
1677
  tracingOptions: p.tracingOptions
1716
1678
  });
1717
1679
  },
1718
- watch: async (onRecord) => {
1719
- return this.watch({ runId }, onRecord);
1720
- },
1721
1680
  stream: async (p) => {
1722
- return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1681
+ return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
1723
1682
  },
1724
1683
  resume: async (p) => {
1725
1684
  return this.resume({
1726
1685
  runId,
1727
1686
  step: p.step,
1728
1687
  resumeData: p.resumeData,
1729
- runtimeContext: p.runtimeContext,
1688
+ requestContext: p.requestContext,
1730
1689
  tracingOptions: p.tracingOptions
1731
1690
  });
1732
1691
  },
@@ -1735,7 +1694,7 @@ var Workflow = class extends BaseResource {
1735
1694
  runId,
1736
1695
  step: p.step,
1737
1696
  resumeData: p.resumeData,
1738
- runtimeContext: p.runtimeContext,
1697
+ requestContext: p.requestContext,
1739
1698
  tracingOptions: p.tracingOptions
1740
1699
  });
1741
1700
  },
@@ -1744,26 +1703,26 @@ var Workflow = class extends BaseResource {
1744
1703
  runId,
1745
1704
  step: p.step,
1746
1705
  resumeData: p.resumeData,
1747
- runtimeContext: p.runtimeContext
1706
+ requestContext: p.requestContext
1748
1707
  });
1749
1708
  }
1750
1709
  };
1751
1710
  }
1752
1711
  /**
1753
1712
  * Starts a workflow run synchronously without waiting for the workflow to complete
1754
- * @param params - Object containing the runId, inputData and runtimeContext
1713
+ * @param params - Object containing the runId, inputData and requestContext
1755
1714
  * @returns Promise containing success message
1756
1715
  */
1757
1716
  start(params) {
1758
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1717
+ const requestContext = parseClientRequestContext(params.requestContext);
1759
1718
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1760
1719
  method: "POST",
1761
- body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1720
+ body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
1762
1721
  });
1763
1722
  }
1764
1723
  /**
1765
1724
  * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
1766
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1725
+ * @param params - Object containing the runId, step, resumeData and requestContext
1767
1726
  * @returns Promise containing success message
1768
1727
  */
1769
1728
  resume({
@@ -1773,20 +1732,20 @@ var Workflow = class extends BaseResource {
1773
1732
  tracingOptions,
1774
1733
  ...rest
1775
1734
  }) {
1776
- const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1735
+ const requestContext = parseClientRequestContext(rest.requestContext);
1777
1736
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1778
1737
  method: "POST",
1779
1738
  body: {
1780
1739
  step,
1781
1740
  resumeData,
1782
- runtimeContext,
1741
+ requestContext,
1783
1742
  tracingOptions
1784
1743
  }
1785
1744
  });
1786
1745
  }
1787
1746
  /**
1788
1747
  * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1789
- * @param params - Object containing the optional runId, inputData and runtimeContext
1748
+ * @param params - Object containing the optional runId, inputData and requestContext
1790
1749
  * @returns Promise containing the workflow execution results
1791
1750
  */
1792
1751
  startAsync(params) {
@@ -1794,15 +1753,15 @@ var Workflow = class extends BaseResource {
1794
1753
  if (!!params?.runId) {
1795
1754
  searchParams.set("runId", params.runId);
1796
1755
  }
1797
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1756
+ const requestContext = parseClientRequestContext(params.requestContext);
1798
1757
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1799
1758
  method: "POST",
1800
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1759
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
1801
1760
  });
1802
1761
  }
1803
1762
  /**
1804
1763
  * Starts a workflow run and returns a stream
1805
- * @param params - Object containing the optional runId, inputData and runtimeContext
1764
+ * @param params - Object containing the optional runId, inputData and requestContext
1806
1765
  * @returns Promise containing the workflow execution results
1807
1766
  */
1808
1767
  async stream(params) {
@@ -1810,12 +1769,12 @@ var Workflow = class extends BaseResource {
1810
1769
  if (!!params?.runId) {
1811
1770
  searchParams.set("runId", params.runId);
1812
1771
  }
1813
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1772
+ const requestContext = parseClientRequestContext(params.requestContext);
1814
1773
  const response = await this.request(
1815
1774
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1816
1775
  {
1817
1776
  method: "POST",
1818
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1777
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
1819
1778
  stream: true
1820
1779
  }
1821
1780
  );
@@ -1900,7 +1859,7 @@ var Workflow = class extends BaseResource {
1900
1859
  }
1901
1860
  /**
1902
1861
  * Starts a workflow run and returns a stream
1903
- * @param params - Object containing the optional runId, inputData and runtimeContext
1862
+ * @param params - Object containing the optional runId, inputData and requestContext
1904
1863
  * @returns Promise containing the workflow execution results
1905
1864
  */
1906
1865
  async streamVNext(params) {
@@ -1908,14 +1867,14 @@ var Workflow = class extends BaseResource {
1908
1867
  if (!!params?.runId) {
1909
1868
  searchParams.set("runId", params.runId);
1910
1869
  }
1911
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1870
+ const requestContext = parseClientRequestContext(params.requestContext);
1912
1871
  const response = await this.request(
1913
1872
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1914
1873
  {
1915
1874
  method: "POST",
1916
1875
  body: {
1917
1876
  inputData: params.inputData,
1918
- runtimeContext,
1877
+ requestContext,
1919
1878
  closeOnSuspend: params.closeOnSuspend,
1920
1879
  tracingOptions: params.tracingOptions
1921
1880
  },
@@ -2003,30 +1962,30 @@ var Workflow = class extends BaseResource {
2003
1962
  }
2004
1963
  /**
2005
1964
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2006
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1965
+ * @param params - Object containing the runId, step, resumeData and requestContext
2007
1966
  * @returns Promise containing the workflow resume results
2008
1967
  */
2009
1968
  resumeAsync(params) {
2010
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1969
+ const requestContext = parseClientRequestContext(params.requestContext);
2011
1970
  return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2012
1971
  method: "POST",
2013
1972
  body: {
2014
1973
  step: params.step,
2015
1974
  resumeData: params.resumeData,
2016
- runtimeContext,
1975
+ requestContext,
2017
1976
  tracingOptions: params.tracingOptions
2018
1977
  }
2019
1978
  });
2020
1979
  }
2021
1980
  /**
2022
1981
  * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2023
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1982
+ * @param params - Object containing the runId, step, resumeData and requestContext
2024
1983
  * @returns Promise containing the workflow resume results
2025
1984
  */
2026
1985
  async resumeStreamVNext(params) {
2027
1986
  const searchParams = new URLSearchParams();
2028
1987
  searchParams.set("runId", params.runId);
2029
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1988
+ const requestContext = parseClientRequestContext(params.requestContext);
2030
1989
  const response = await this.request(
2031
1990
  `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2032
1991
  {
@@ -2034,7 +1993,7 @@ var Workflow = class extends BaseResource {
2034
1993
  body: {
2035
1994
  step: params.step,
2036
1995
  resumeData: params.resumeData,
2037
- runtimeContext,
1996
+ requestContext,
2038
1997
  tracingOptions: params.tracingOptions
2039
1998
  },
2040
1999
  stream: true
@@ -2072,29 +2031,6 @@ var Workflow = class extends BaseResource {
2072
2031
  });
2073
2032
  return response.body.pipeThrough(transformStream);
2074
2033
  }
2075
- /**
2076
- * Watches workflow transitions in real-time
2077
- * @param runId - Optional run ID to filter the watch stream
2078
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2079
- */
2080
- async watch({ runId }, onRecord) {
2081
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2082
- stream: true
2083
- });
2084
- if (!response.ok) {
2085
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
2086
- }
2087
- if (!response.body) {
2088
- throw new Error("Response body is null");
2089
- }
2090
- for await (const record of this.streamProcessor(response.body)) {
2091
- if (typeof record === "string") {
2092
- onRecord(JSON.parse(record));
2093
- } else {
2094
- onRecord(record);
2095
- }
2096
- }
2097
- }
2098
2034
  /**
2099
2035
  * Creates a new ReadableStream from an iterable or async iterable of objects,
2100
2036
  * serializing each as JSON and separating them with the record separator (\x1E).
@@ -2206,22 +2142,22 @@ var MCPTool = class extends BaseResource {
2206
2142
  }
2207
2143
  /**
2208
2144
  * Retrieves details about this specific tool from the MCP server.
2209
- * @param runtimeContext - Optional runtime context to pass as query parameter
2145
+ * @param requestContext - Optional request context to pass as query parameter
2210
2146
  * @returns Promise containing the tool's information (name, description, schema).
2211
2147
  */
2212
- details(runtimeContext) {
2213
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2148
+ details(requestContext) {
2149
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
2214
2150
  }
2215
2151
  /**
2216
2152
  * Executes this specific tool on the MCP server.
2217
- * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
2153
+ * @param params - Parameters for tool execution, including data/args and optional requestContext.
2218
2154
  * @returns Promise containing the result of the tool execution.
2219
2155
  */
2220
2156
  execute(params) {
2221
2157
  const body = {};
2222
2158
  if (params.data !== void 0) body.data = params.data;
2223
- if (params.runtimeContext !== void 0) {
2224
- body.runtimeContext = params.runtimeContext;
2159
+ if (params.requestContext !== void 0) {
2160
+ body.requestContext = params.requestContext;
2225
2161
  }
2226
2162
  return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
2227
2163
  method: "POST",
@@ -2267,19 +2203,39 @@ var AgentBuilder = class extends BaseResource {
2267
2203
  }
2268
2204
  }
2269
2205
  /**
2270
- * @deprecated Use createRunAsync() instead.
2271
- * @throws {Error} Always throws an error directing users to use createRunAsync()
2206
+ * Creates a transform stream that parses binary chunks into JSON records.
2272
2207
  */
2273
- async createRun(_params) {
2274
- throw new Error(
2275
- "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."
2276
- );
2208
+ createRecordParserTransform() {
2209
+ let failedChunk = void 0;
2210
+ return new TransformStream({
2211
+ start() {
2212
+ },
2213
+ async transform(chunk, controller) {
2214
+ try {
2215
+ const decoded = new TextDecoder().decode(chunk);
2216
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2217
+ for (const chunk2 of chunks) {
2218
+ if (chunk2) {
2219
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2220
+ try {
2221
+ const parsedChunk = JSON.parse(newChunk);
2222
+ controller.enqueue(parsedChunk);
2223
+ failedChunk = void 0;
2224
+ } catch {
2225
+ failedChunk = newChunk;
2226
+ }
2227
+ }
2228
+ }
2229
+ } catch {
2230
+ }
2231
+ }
2232
+ });
2277
2233
  }
2278
2234
  /**
2279
2235
  * Creates a new agent builder action run and returns the runId.
2280
2236
  * This calls `/api/agent-builder/:actionId/create-run`.
2281
2237
  */
2282
- async createRunAsync(params) {
2238
+ async createRun(params) {
2283
2239
  const searchParams = new URLSearchParams();
2284
2240
  if (!!params?.runId) {
2285
2241
  searchParams.set("runId", params.runId);
@@ -2298,12 +2254,12 @@ var AgentBuilder = class extends BaseResource {
2298
2254
  if (runId) {
2299
2255
  searchParams.set("runId", runId);
2300
2256
  }
2301
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2302
- const { runtimeContext: _, ...actionParams } = params;
2257
+ const requestContext = parseClientRequestContext(params.requestContext);
2258
+ const { requestContext: _, ...actionParams } = params;
2303
2259
  const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2304
2260
  const result = await this.request(url, {
2305
2261
  method: "POST",
2306
- body: { ...actionParams, runtimeContext }
2262
+ body: { ...actionParams, requestContext }
2307
2263
  });
2308
2264
  return this.transformWorkflowResult(result);
2309
2265
  }
@@ -2314,12 +2270,12 @@ var AgentBuilder = class extends BaseResource {
2314
2270
  async startActionRun(params, runId) {
2315
2271
  const searchParams = new URLSearchParams();
2316
2272
  searchParams.set("runId", runId);
2317
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2318
- const { runtimeContext: _, ...actionParams } = params;
2273
+ const requestContext = parseClientRequestContext(params.requestContext);
2274
+ const { requestContext: _, ...actionParams } = params;
2319
2275
  const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2320
2276
  return this.request(url, {
2321
2277
  method: "POST",
2322
- body: { ...actionParams, runtimeContext }
2278
+ body: { ...actionParams, requestContext }
2323
2279
  });
2324
2280
  }
2325
2281
  /**
@@ -2329,12 +2285,12 @@ var AgentBuilder = class extends BaseResource {
2329
2285
  async resume(params, runId) {
2330
2286
  const searchParams = new URLSearchParams();
2331
2287
  searchParams.set("runId", runId);
2332
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2333
- const { runtimeContext: _, ...resumeParams } = params;
2288
+ const requestContext = parseClientRequestContext(params.requestContext);
2289
+ const { requestContext: _, ...resumeParams } = params;
2334
2290
  const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2335
2291
  return this.request(url, {
2336
2292
  method: "POST",
2337
- body: { ...resumeParams, runtimeContext }
2293
+ body: { ...resumeParams, requestContext }
2338
2294
  });
2339
2295
  }
2340
2296
  /**
@@ -2344,12 +2300,12 @@ var AgentBuilder = class extends BaseResource {
2344
2300
  async resumeAsync(params, runId) {
2345
2301
  const searchParams = new URLSearchParams();
2346
2302
  searchParams.set("runId", runId);
2347
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2348
- const { runtimeContext: _, ...resumeParams } = params;
2303
+ const requestContext = parseClientRequestContext(params.requestContext);
2304
+ const { requestContext: _, ...resumeParams } = params;
2349
2305
  const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2350
2306
  const result = await this.request(url, {
2351
2307
  method: "POST",
2352
- body: { ...resumeParams, runtimeContext }
2308
+ body: { ...resumeParams, requestContext }
2353
2309
  });
2354
2310
  return this.transformWorkflowResult(result);
2355
2311
  }
@@ -2407,12 +2363,12 @@ var AgentBuilder = class extends BaseResource {
2407
2363
  if (runId) {
2408
2364
  searchParams.set("runId", runId);
2409
2365
  }
2410
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2411
- const { runtimeContext: _, ...actionParams } = params;
2366
+ const requestContext = parseClientRequestContext(params.requestContext);
2367
+ const { requestContext: _, ...actionParams } = params;
2412
2368
  const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2413
2369
  const response = await this.request(url, {
2414
2370
  method: "POST",
2415
- body: { ...actionParams, runtimeContext },
2371
+ body: { ...actionParams, requestContext },
2416
2372
  stream: true
2417
2373
  });
2418
2374
  if (!response.ok) {
@@ -2421,31 +2377,7 @@ var AgentBuilder = class extends BaseResource {
2421
2377
  if (!response.body) {
2422
2378
  throw new Error("Response body is null");
2423
2379
  }
2424
- let failedChunk = void 0;
2425
- const transformStream = new TransformStream({
2426
- start() {
2427
- },
2428
- async transform(chunk, controller) {
2429
- try {
2430
- const decoded = new TextDecoder().decode(chunk);
2431
- const chunks = decoded.split(RECORD_SEPARATOR2);
2432
- for (const chunk2 of chunks) {
2433
- if (chunk2) {
2434
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2435
- try {
2436
- const parsedChunk = JSON.parse(newChunk);
2437
- controller.enqueue(parsedChunk);
2438
- failedChunk = void 0;
2439
- } catch {
2440
- failedChunk = newChunk;
2441
- }
2442
- }
2443
- }
2444
- } catch {
2445
- }
2446
- }
2447
- });
2448
- return response.body.pipeThrough(transformStream);
2380
+ return response.body.pipeThrough(this.createRecordParserTransform());
2449
2381
  }
2450
2382
  /**
2451
2383
  * Streams agent builder action progress in real-time using VNext streaming.
@@ -2456,12 +2388,12 @@ var AgentBuilder = class extends BaseResource {
2456
2388
  if (runId) {
2457
2389
  searchParams.set("runId", runId);
2458
2390
  }
2459
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2460
- const { runtimeContext: _, ...actionParams } = params;
2391
+ const requestContext = parseClientRequestContext(params.requestContext);
2392
+ const { requestContext: _, ...actionParams } = params;
2461
2393
  const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2462
2394
  const response = await this.request(url, {
2463
2395
  method: "POST",
2464
- body: { ...actionParams, runtimeContext },
2396
+ body: { ...actionParams, requestContext },
2465
2397
  stream: true
2466
2398
  });
2467
2399
  if (!response.ok) {
@@ -2470,57 +2402,94 @@ var AgentBuilder = class extends BaseResource {
2470
2402
  if (!response.body) {
2471
2403
  throw new Error("Response body is null");
2472
2404
  }
2473
- let failedChunk = void 0;
2474
- const transformStream = new TransformStream({
2475
- start() {
2476
- },
2477
- async transform(chunk, controller) {
2478
- try {
2479
- const decoded = new TextDecoder().decode(chunk);
2480
- const chunks = decoded.split(RECORD_SEPARATOR2);
2481
- for (const chunk2 of chunks) {
2482
- if (chunk2) {
2483
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2484
- try {
2485
- const parsedChunk = JSON.parse(newChunk);
2486
- controller.enqueue(parsedChunk);
2487
- failedChunk = void 0;
2488
- } catch {
2489
- failedChunk = newChunk;
2490
- }
2491
- }
2492
- }
2493
- } catch {
2494
- }
2495
- }
2405
+ return response.body.pipeThrough(this.createRecordParserTransform());
2406
+ }
2407
+ /**
2408
+ * Observes an existing agent builder action run stream.
2409
+ * Replays cached execution from the beginning, then continues with live stream.
2410
+ * This is the recommended method for recovery after page refresh/hot reload.
2411
+ * This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
2412
+ */
2413
+ async observeStream(params) {
2414
+ const searchParams = new URLSearchParams();
2415
+ searchParams.set("runId", params.runId);
2416
+ const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
2417
+ const response = await this.request(url, {
2418
+ method: "POST",
2419
+ stream: true
2496
2420
  });
2497
- return response.body.pipeThrough(transformStream);
2421
+ if (!response.ok) {
2422
+ throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
2423
+ }
2424
+ if (!response.body) {
2425
+ throw new Error("Response body is null");
2426
+ }
2427
+ return response.body.pipeThrough(this.createRecordParserTransform());
2428
+ }
2429
+ /**
2430
+ * Observes an existing agent builder action run stream using VNext streaming API.
2431
+ * Replays cached execution from the beginning, then continues with live stream.
2432
+ * This calls `/api/agent-builder/:actionId/observe-streamVNext`.
2433
+ */
2434
+ async observeStreamVNext(params) {
2435
+ const searchParams = new URLSearchParams();
2436
+ searchParams.set("runId", params.runId);
2437
+ const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
2438
+ const response = await this.request(url, {
2439
+ method: "POST",
2440
+ stream: true
2441
+ });
2442
+ if (!response.ok) {
2443
+ throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
2444
+ }
2445
+ if (!response.body) {
2446
+ throw new Error("Response body is null");
2447
+ }
2448
+ return response.body.pipeThrough(this.createRecordParserTransform());
2498
2449
  }
2499
2450
  /**
2500
- * Watches an existing agent builder action run by runId.
2501
- * This is used for hot reload recovery - it loads the existing run state
2502
- * and streams any remaining progress.
2503
- * This calls `/api/agent-builder/:actionId/watch`.
2451
+ * Observes an existing agent builder action run stream using legacy streaming API.
2452
+ * Replays cached execution from the beginning, then continues with live stream.
2453
+ * This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
2504
2454
  */
2505
- async watch({ runId, eventType }, onRecord) {
2506
- const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
2455
+ async observeStreamLegacy(params) {
2456
+ const searchParams = new URLSearchParams();
2457
+ searchParams.set("runId", params.runId);
2458
+ const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
2507
2459
  const response = await this.request(url, {
2508
- method: "GET",
2460
+ method: "POST",
2509
2461
  stream: true
2510
2462
  });
2511
2463
  if (!response.ok) {
2512
- throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
2464
+ throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
2513
2465
  }
2514
2466
  if (!response.body) {
2515
2467
  throw new Error("Response body is null");
2516
2468
  }
2517
- for await (const record of this.streamProcessor(response.body)) {
2518
- if (typeof record === "string") {
2519
- onRecord(JSON.parse(record));
2520
- } else {
2521
- onRecord(record);
2522
- }
2469
+ return response.body.pipeThrough(this.createRecordParserTransform());
2470
+ }
2471
+ /**
2472
+ * Resumes a suspended agent builder action and streams the results.
2473
+ * This calls `/api/agent-builder/:actionId/resume-stream`.
2474
+ */
2475
+ async resumeStream(params) {
2476
+ const searchParams = new URLSearchParams();
2477
+ searchParams.set("runId", params.runId);
2478
+ const requestContext = parseClientRequestContext(params.requestContext);
2479
+ const { runId: _, requestContext: __, ...resumeParams } = params;
2480
+ const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
2481
+ const response = await this.request(url, {
2482
+ method: "POST",
2483
+ body: { ...resumeParams, requestContext },
2484
+ stream: true
2485
+ });
2486
+ if (!response.ok) {
2487
+ throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
2488
+ }
2489
+ if (!response.body) {
2490
+ throw new Error("Response body is null");
2523
2491
  }
2492
+ return response.body.pipeThrough(this.createRecordParserTransform());
2524
2493
  }
2525
2494
  /**
2526
2495
  * Gets a specific action run by its ID.
@@ -2552,11 +2521,11 @@ var AgentBuilder = class extends BaseResource {
2552
2521
  if (params?.toDate) {
2553
2522
  searchParams.set("toDate", params.toDate.toISOString());
2554
2523
  }
2555
- if (params?.limit !== void 0) {
2556
- searchParams.set("limit", String(params.limit));
2524
+ if (params?.perPage !== void 0) {
2525
+ searchParams.set("perPage", String(params.perPage));
2557
2526
  }
2558
- if (params?.offset !== void 0) {
2559
- searchParams.set("offset", String(params.offset));
2527
+ if (params?.page !== void 0) {
2528
+ searchParams.set("page", String(params.page));
2560
2529
  }
2561
2530
  if (params?.resourceId) {
2562
2531
  searchParams.set("resourceId", params.resourceId);
@@ -2586,17 +2555,6 @@ var AgentBuilder = class extends BaseResource {
2586
2555
  method: "POST"
2587
2556
  });
2588
2557
  }
2589
- /**
2590
- * Sends an event to an agent builder action run.
2591
- * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
2592
- */
2593
- async sendRunEvent(params) {
2594
- const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2595
- return this.request(url, {
2596
- method: "POST",
2597
- body: { event: params.event, data: params.data }
2598
- });
2599
- }
2600
2558
  };
2601
2559
 
2602
2560
  // src/resources/observability.ts
@@ -2605,15 +2563,15 @@ var Observability = class extends BaseResource {
2605
2563
  super(options);
2606
2564
  }
2607
2565
  /**
2608
- * Retrieves a specific AI trace by ID
2566
+ * Retrieves a specific trace by ID
2609
2567
  * @param traceId - ID of the trace to retrieve
2610
- * @returns Promise containing the AI trace with all its spans
2568
+ * @returns Promise containing the trace with all its spans
2611
2569
  */
2612
2570
  getTrace(traceId) {
2613
2571
  return this.request(`/api/observability/traces/${traceId}`);
2614
2572
  }
2615
2573
  /**
2616
- * Retrieves paginated list of AI traces with optional filtering
2574
+ * Retrieves paginated list of traces with optional filtering
2617
2575
  * @param params - Parameters for pagination and filtering
2618
2576
  * @returns Promise containing paginated traces and pagination info
2619
2577
  */
@@ -2653,7 +2611,7 @@ var Observability = class extends BaseResource {
2653
2611
  * @param params - Parameters containing trace ID, span ID, and pagination options
2654
2612
  * @returns Promise containing scores and pagination info
2655
2613
  */
2656
- getScoresBySpan(params) {
2614
+ listScoresBySpan(params) {
2657
2615
  const { traceId, spanId, page, perPage } = params;
2658
2616
  const searchParams = new URLSearchParams();
2659
2617
  if (page !== void 0) {
@@ -2675,69 +2633,6 @@ var Observability = class extends BaseResource {
2675
2633
  }
2676
2634
  };
2677
2635
 
2678
- // src/resources/network-memory-thread.ts
2679
- var NetworkMemoryThread = class extends BaseResource {
2680
- constructor(options, threadId, networkId) {
2681
- super(options);
2682
- this.threadId = threadId;
2683
- this.networkId = networkId;
2684
- }
2685
- /**
2686
- * Retrieves the memory thread details
2687
- * @returns Promise containing thread details including title and metadata
2688
- */
2689
- get() {
2690
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
2691
- }
2692
- /**
2693
- * Updates the memory thread properties
2694
- * @param params - Update parameters including title and metadata
2695
- * @returns Promise containing updated thread details
2696
- */
2697
- update(params) {
2698
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2699
- method: "PATCH",
2700
- body: params
2701
- });
2702
- }
2703
- /**
2704
- * Deletes the memory thread
2705
- * @returns Promise containing deletion result
2706
- */
2707
- delete() {
2708
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2709
- method: "DELETE"
2710
- });
2711
- }
2712
- /**
2713
- * Retrieves messages associated with the thread
2714
- * @param params - Optional parameters including limit for number of messages to retrieve
2715
- * @returns Promise containing thread messages and UI messages
2716
- */
2717
- getMessages(params) {
2718
- const query = new URLSearchParams({
2719
- networkId: this.networkId,
2720
- ...params?.limit ? { limit: params.limit.toString() } : {}
2721
- });
2722
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
2723
- }
2724
- /**
2725
- * Deletes one or more messages from the thread
2726
- * @param messageIds - Can be a single message ID (string), array of message IDs,
2727
- * message object with id property, or array of message objects
2728
- * @returns Promise containing deletion result
2729
- */
2730
- deleteMessages(messageIds) {
2731
- const query = new URLSearchParams({
2732
- networkId: this.networkId
2733
- });
2734
- return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
2735
- method: "POST",
2736
- body: { messageIds }
2737
- });
2738
- }
2739
- };
2740
-
2741
2636
  // src/client.ts
2742
2637
  var MastraClient = class extends BaseResource {
2743
2638
  observability;
@@ -2747,18 +2642,21 @@ var MastraClient = class extends BaseResource {
2747
2642
  }
2748
2643
  /**
2749
2644
  * Retrieves all available agents
2750
- * @param runtimeContext - Optional runtime context to pass as query parameter
2645
+ * @param requestContext - Optional request context to pass as query parameter
2751
2646
  * @returns Promise containing map of agent IDs to agent details
2752
2647
  */
2753
- getAgents(runtimeContext) {
2754
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2648
+ listAgents(requestContext) {
2649
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2755
2650
  const searchParams = new URLSearchParams();
2756
- if (runtimeContextParam) {
2757
- searchParams.set("runtimeContext", runtimeContextParam);
2651
+ if (requestContextParam) {
2652
+ searchParams.set("requestContext", requestContextParam);
2758
2653
  }
2759
2654
  const queryString = searchParams.toString();
2760
2655
  return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2761
2656
  }
2657
+ listAgentsModelProviders() {
2658
+ return this.request(`/api/agents/providers`);
2659
+ }
2762
2660
  /**
2763
2661
  * Gets an agent instance by ID
2764
2662
  * @param agentId - ID of the agent to retrieve
@@ -2768,125 +2666,107 @@ var MastraClient = class extends BaseResource {
2768
2666
  return new Agent(this.options, agentId);
2769
2667
  }
2770
2668
  /**
2771
- * Retrieves memory threads for a resource
2772
- * @param params - Parameters containing the resource ID
2773
- * @returns Promise containing array of memory threads
2669
+ * Lists memory threads for a resource with pagination support
2670
+ * @param params - Parameters containing resource ID, pagination options, and optional request context
2671
+ * @returns Promise containing paginated array of memory threads with metadata
2774
2672
  */
2775
- getMemoryThreads(params) {
2776
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2673
+ listMemoryThreads(params) {
2674
+ const queryParams = new URLSearchParams({
2675
+ resourceId: params.resourceId,
2676
+ resourceid: params.resourceId,
2677
+ agentId: params.agentId,
2678
+ ...params.page !== void 0 && { page: params.page.toString() },
2679
+ ...params.perPage !== void 0 && { perPage: params.perPage.toString() },
2680
+ ...params.orderBy && { orderBy: params.orderBy },
2681
+ ...params.sortDirection && { sortDirection: params.sortDirection }
2682
+ });
2683
+ return this.request(
2684
+ `/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
2685
+ );
2777
2686
  }
2778
2687
  /**
2779
2688
  * Retrieves memory config for a resource
2780
- * @param params - Parameters containing the resource ID
2781
- * @returns Promise containing array of memory threads
2689
+ * @param params - Parameters containing the resource ID and optional request context
2690
+ * @returns Promise containing memory configuration
2782
2691
  */
2783
2692
  getMemoryConfig(params) {
2784
- return this.request(`/api/memory/config?agentId=${params.agentId}`);
2693
+ return this.request(
2694
+ `/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
2695
+ );
2785
2696
  }
2786
2697
  /**
2787
2698
  * Creates a new memory thread
2788
- * @param params - Parameters for creating the memory thread
2699
+ * @param params - Parameters for creating the memory thread including optional request context
2789
2700
  * @returns Promise containing the created memory thread
2790
2701
  */
2791
2702
  createMemoryThread(params) {
2792
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
2703
+ return this.request(
2704
+ `/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2705
+ { method: "POST", body: params }
2706
+ );
2793
2707
  }
2794
2708
  /**
2795
2709
  * Gets a memory thread instance by ID
2796
2710
  * @param threadId - ID of the memory thread to retrieve
2797
2711
  * @returns MemoryThread instance
2798
2712
  */
2799
- getMemoryThread(threadId, agentId) {
2713
+ getMemoryThread({ threadId, agentId }) {
2800
2714
  return new MemoryThread(this.options, threadId, agentId);
2801
2715
  }
2802
- getThreadMessages(threadId, opts = {}) {
2716
+ listThreadMessages(threadId, opts = {}) {
2717
+ if (!opts.agentId && !opts.networkId) {
2718
+ throw new Error("Either agentId or networkId must be provided");
2719
+ }
2803
2720
  let url = "";
2804
2721
  if (opts.agentId) {
2805
- url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2722
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2806
2723
  } else if (opts.networkId) {
2807
- url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2724
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2808
2725
  }
2809
2726
  return this.request(url);
2810
2727
  }
2811
2728
  deleteThread(threadId, opts = {}) {
2812
2729
  let url = "";
2813
2730
  if (opts.agentId) {
2814
- url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2731
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2815
2732
  } else if (opts.networkId) {
2816
- url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2733
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2817
2734
  }
2818
2735
  return this.request(url, { method: "DELETE" });
2819
2736
  }
2820
2737
  /**
2821
2738
  * Saves messages to memory
2822
- * @param params - Parameters containing messages to save
2739
+ * @param params - Parameters containing messages to save and optional request context
2823
2740
  * @returns Promise containing the saved messages
2824
2741
  */
2825
2742
  saveMessageToMemory(params) {
2826
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
2827
- method: "POST",
2828
- body: params
2829
- });
2830
- }
2831
- /**
2832
- * Gets the status of the memory system
2833
- * @returns Promise containing memory system status
2834
- */
2835
- getMemoryStatus(agentId) {
2836
- return this.request(`/api/memory/status?agentId=${agentId}`);
2837
- }
2838
- /**
2839
- * Retrieves memory threads for a resource
2840
- * @param params - Parameters containing the resource ID
2841
- * @returns Promise containing array of memory threads
2842
- */
2843
- getNetworkMemoryThreads(params) {
2844
- return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
2845
- }
2846
- /**
2847
- * Creates a new memory thread
2848
- * @param params - Parameters for creating the memory thread
2849
- * @returns Promise containing the created memory thread
2850
- */
2851
- createNetworkMemoryThread(params) {
2852
- return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
2853
- }
2854
- /**
2855
- * Gets a memory thread instance by ID
2856
- * @param threadId - ID of the memory thread to retrieve
2857
- * @returns MemoryThread instance
2858
- */
2859
- getNetworkMemoryThread(threadId, networkId) {
2860
- return new NetworkMemoryThread(this.options, threadId, networkId);
2861
- }
2862
- /**
2863
- * Saves messages to memory
2864
- * @param params - Parameters containing messages to save
2865
- * @returns Promise containing the saved messages
2866
- */
2867
- saveNetworkMessageToMemory(params) {
2868
- return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
2869
- method: "POST",
2870
- body: params
2871
- });
2743
+ return this.request(
2744
+ `/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2745
+ {
2746
+ method: "POST",
2747
+ body: params
2748
+ }
2749
+ );
2872
2750
  }
2873
2751
  /**
2874
2752
  * Gets the status of the memory system
2753
+ * @param agentId - The agent ID
2754
+ * @param requestContext - Optional request context to pass as query parameter
2875
2755
  * @returns Promise containing memory system status
2876
2756
  */
2877
- getNetworkMemoryStatus(networkId) {
2878
- return this.request(`/api/memory/network/status?networkId=${networkId}`);
2757
+ getMemoryStatus(agentId, requestContext) {
2758
+ return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
2879
2759
  }
2880
2760
  /**
2881
2761
  * Retrieves all available tools
2882
- * @param runtimeContext - Optional runtime context to pass as query parameter
2762
+ * @param requestContext - Optional request context to pass as query parameter
2883
2763
  * @returns Promise containing map of tool IDs to tool details
2884
2764
  */
2885
- getTools(runtimeContext) {
2886
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2765
+ listTools(requestContext) {
2766
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2887
2767
  const searchParams = new URLSearchParams();
2888
- if (runtimeContextParam) {
2889
- searchParams.set("runtimeContext", runtimeContextParam);
2768
+ if (requestContextParam) {
2769
+ searchParams.set("requestContext", requestContextParam);
2890
2770
  }
2891
2771
  const queryString = searchParams.toString();
2892
2772
  return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
@@ -2901,14 +2781,14 @@ var MastraClient = class extends BaseResource {
2901
2781
  }
2902
2782
  /**
2903
2783
  * Retrieves all available workflows
2904
- * @param runtimeContext - Optional runtime context to pass as query parameter
2784
+ * @param requestContext - Optional request context to pass as query parameter
2905
2785
  * @returns Promise containing map of workflow IDs to workflow details
2906
2786
  */
2907
- getWorkflows(runtimeContext) {
2908
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2787
+ listWorkflows(requestContext) {
2788
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2909
2789
  const searchParams = new URLSearchParams();
2910
- if (runtimeContextParam) {
2911
- searchParams.set("runtimeContext", runtimeContextParam);
2790
+ if (requestContextParam) {
2791
+ searchParams.set("requestContext", requestContextParam);
2912
2792
  }
2913
2793
  const queryString = searchParams.toString();
2914
2794
  return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
@@ -2948,7 +2828,7 @@ var MastraClient = class extends BaseResource {
2948
2828
  * @param params - Parameters for filtering logs
2949
2829
  * @returns Promise containing array of log messages
2950
2830
  */
2951
- getLogs(params) {
2831
+ listLogs(params) {
2952
2832
  const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
2953
2833
  const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
2954
2834
  const searchParams = new URLSearchParams();
@@ -3034,63 +2914,21 @@ var MastraClient = class extends BaseResource {
3034
2914
  * List of all log transports
3035
2915
  * @returns Promise containing list of log transports
3036
2916
  */
3037
- getLogTransports() {
2917
+ listLogTransports() {
3038
2918
  return this.request("/api/logs/transports");
3039
2919
  }
3040
- /**
3041
- * List of all traces (paged)
3042
- * @param params - Parameters for filtering traces
3043
- * @returns Promise containing telemetry data
3044
- */
3045
- getTelemetry(params) {
3046
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3047
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3048
- const searchParams = new URLSearchParams();
3049
- if (name) {
3050
- searchParams.set("name", name);
3051
- }
3052
- if (scope) {
3053
- searchParams.set("scope", scope);
3054
- }
3055
- if (page) {
3056
- searchParams.set("page", String(page));
3057
- }
3058
- if (perPage) {
3059
- searchParams.set("perPage", String(perPage));
3060
- }
3061
- if (_attribute) {
3062
- if (Array.isArray(_attribute)) {
3063
- for (const attr of _attribute) {
3064
- searchParams.append("attribute", attr);
3065
- }
3066
- } else {
3067
- searchParams.set("attribute", _attribute);
3068
- }
3069
- }
3070
- if (fromDate) {
3071
- searchParams.set("fromDate", fromDate.toISOString());
3072
- }
3073
- if (toDate) {
3074
- searchParams.set("toDate", toDate.toISOString());
3075
- }
3076
- if (searchParams.size) {
3077
- return this.request(`/api/telemetry?${searchParams}`);
3078
- } else {
3079
- return this.request(`/api/telemetry`);
3080
- }
3081
- }
3082
2920
  /**
3083
2921
  * Retrieves a list of available MCP servers.
3084
- * @param params - Optional parameters for pagination (limit, offset).
2922
+ * @param params - Optional parameters for pagination (perPage, page).
3085
2923
  * @returns Promise containing the list of MCP servers and pagination info.
3086
2924
  */
3087
2925
  getMcpServers(params) {
3088
2926
  const searchParams = new URLSearchParams();
3089
- if (params?.limit !== void 0) {
3090
- searchParams.set("limit", String(params.limit));
2927
+ if (params?.perPage !== void 0) {
2928
+ searchParams.set("perPage", String(params.perPage));
3091
2929
  }
3092
- if (params?.offset !== void 0) {
3093
- searchParams.set("offset", String(params.offset));
2930
+ if (params?.page !== void 0) {
2931
+ searchParams.set("page", String(params.page));
3094
2932
  }
3095
2933
  const queryString = searchParams.toString();
3096
2934
  return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
@@ -3145,9 +2983,33 @@ var MastraClient = class extends BaseResource {
3145
2983
  getWorkingMemory({
3146
2984
  agentId,
3147
2985
  threadId,
3148
- resourceId
2986
+ resourceId,
2987
+ requestContext
2988
+ }) {
2989
+ return this.request(
2990
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
2991
+ );
2992
+ }
2993
+ searchMemory({
2994
+ agentId,
2995
+ resourceId,
2996
+ threadId,
2997
+ searchQuery,
2998
+ memoryConfig,
2999
+ requestContext
3149
3000
  }) {
3150
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3001
+ const params = new URLSearchParams({
3002
+ searchQuery,
3003
+ resourceId,
3004
+ agentId
3005
+ });
3006
+ if (threadId) {
3007
+ params.append("threadId", threadId);
3008
+ }
3009
+ if (memoryConfig) {
3010
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3011
+ }
3012
+ return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
3151
3013
  }
3152
3014
  /**
3153
3015
  * Updates the working memory for a specific thread (optionally resource-scoped).
@@ -3160,21 +3022,25 @@ var MastraClient = class extends BaseResource {
3160
3022
  agentId,
3161
3023
  threadId,
3162
3024
  workingMemory,
3163
- resourceId
3025
+ resourceId,
3026
+ requestContext
3164
3027
  }) {
3165
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3166
- method: "POST",
3167
- body: {
3168
- workingMemory,
3169
- resourceId
3028
+ return this.request(
3029
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
3030
+ {
3031
+ method: "POST",
3032
+ body: {
3033
+ workingMemory,
3034
+ resourceId
3035
+ }
3170
3036
  }
3171
- });
3037
+ );
3172
3038
  }
3173
3039
  /**
3174
3040
  * Retrieves all available scorers
3175
3041
  * @returns Promise containing list of available scorers
3176
3042
  */
3177
- getScorers() {
3043
+ listScorers() {
3178
3044
  return this.request("/api/scores/scorers");
3179
3045
  }
3180
3046
  /**
@@ -3185,7 +3051,7 @@ var MastraClient = class extends BaseResource {
3185
3051
  getScorer(scorerId) {
3186
3052
  return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3187
3053
  }
3188
- getScoresByScorerId(params) {
3054
+ listScoresByScorerId(params) {
3189
3055
  const { page, perPage, scorerId, entityId, entityType } = params;
3190
3056
  const searchParams = new URLSearchParams();
3191
3057
  if (entityId) {
@@ -3208,7 +3074,7 @@ var MastraClient = class extends BaseResource {
3208
3074
  * @param params - Parameters containing run ID and pagination options
3209
3075
  * @returns Promise containing scores and pagination info
3210
3076
  */
3211
- getScoresByRunId(params) {
3077
+ listScoresByRunId(params) {
3212
3078
  const { runId, page, perPage } = params;
3213
3079
  const searchParams = new URLSearchParams();
3214
3080
  if (page !== void 0) {
@@ -3225,7 +3091,7 @@ var MastraClient = class extends BaseResource {
3225
3091
  * @param params - Parameters containing entity ID, type, and pagination options
3226
3092
  * @returns Promise containing scores and pagination info
3227
3093
  */
3228
- getScoresByEntityId(params) {
3094
+ listScoresByEntityId(params) {
3229
3095
  const { entityId, entityType, page, perPage } = params;
3230
3096
  const searchParams = new URLSearchParams();
3231
3097
  if (page !== void 0) {
@@ -3250,21 +3116,14 @@ var MastraClient = class extends BaseResource {
3250
3116
  body: params
3251
3117
  });
3252
3118
  }
3253
- /**
3254
- * Retrieves model providers with available keys
3255
- * @returns Promise containing model providers with available keys
3256
- */
3257
- getModelProviders() {
3258
- return this.request(`/api/model-providers`);
3259
- }
3260
- getAITrace(traceId) {
3119
+ getTrace(traceId) {
3261
3120
  return this.observability.getTrace(traceId);
3262
3121
  }
3263
- getAITraces(params) {
3122
+ getTraces(params) {
3264
3123
  return this.observability.getTraces(params);
3265
3124
  }
3266
- getScoresBySpan(params) {
3267
- return this.observability.getScoresBySpan(params);
3125
+ listScoresBySpan(params) {
3126
+ return this.observability.listScoresBySpan(params);
3268
3127
  }
3269
3128
  score(params) {
3270
3129
  return this.observability.score(params);