@mastra/client-js 0.0.0-cloud-deployer-for-core-0.19.1-20251001164939 → 0.0.0-cloud-storage-adapter-20251106204059

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,27 +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
319
  }
320
- async generate(params) {
321
- console.warn(
322
- "Deprecation NOTICE: Generate method will switch to use generateVNext implementation the week of September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
323
- );
324
- return this.generateLegacy(params);
320
+ enhanceInstructions(instructions, comment) {
321
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
322
+ method: "POST",
323
+ body: { instructions, comment }
324
+ });
325
325
  }
326
326
  async generateLegacy(params) {
327
327
  const processedParams = {
328
328
  ...params,
329
329
  output: params.output ? zodToJsonSchema(params.output) : void 0,
330
330
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
331
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
331
+ requestContext: parseClientRequestContext(params.requestContext),
332
332
  clientTools: processClientTools(params.clientTools)
333
333
  };
334
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
334
+ const { resourceId, threadId, requestContext } = processedParams;
335
335
  const response = await this.request(
336
336
  `/api/agents/${this.agentId}/generate-legacy`,
337
337
  {
@@ -347,22 +347,18 @@ var Agent = class extends BaseResource {
347
347
  for (const toolCall of toolCalls) {
348
348
  const clientTool = params.clientTools?.[toolCall.toolName];
349
349
  if (clientTool && clientTool.execute) {
350
- const result = await clientTool.execute(
351
- {
352
- context: toolCall?.args,
353
- runId,
354
- resourceId,
355
- threadId,
356
- runtimeContext,
357
- tracingContext: { currentSpan: void 0 },
358
- suspend: async () => {
359
- }
360
- },
361
- {
350
+ const result = await clientTool.execute(toolCall?.args, {
351
+ requestContext,
352
+ tracingContext: { currentSpan: void 0 },
353
+ agent: {
362
354
  messages: response.messages,
363
- toolCallId: toolCall?.toolCallId
355
+ toolCallId: toolCall?.toolCallId,
356
+ suspend: async () => {
357
+ },
358
+ threadId,
359
+ resourceId
364
360
  }
365
- );
361
+ });
366
362
  const updatedMessages = [
367
363
  ...response.response.messages,
368
364
  {
@@ -386,7 +382,7 @@ var Agent = class extends BaseResource {
386
382
  }
387
383
  return response;
388
384
  }
389
- async generateVNext(messagesOrParams, options) {
385
+ async generate(messagesOrParams, options) {
390
386
  let params;
391
387
  if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
392
388
  params = messagesOrParams;
@@ -398,17 +394,16 @@ var Agent = class extends BaseResource {
398
394
  }
399
395
  const processedParams = {
400
396
  ...params,
401
- output: params.output ? zodToJsonSchema(params.output) : void 0,
402
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
397
+ requestContext: parseClientRequestContext(params.requestContext),
403
398
  clientTools: processClientTools(params.clientTools),
404
399
  structuredOutput: params.structuredOutput ? {
405
400
  ...params.structuredOutput,
406
401
  schema: zodToJsonSchema(params.structuredOutput.schema)
407
402
  } : void 0
408
403
  };
409
- const { runId, resourceId, threadId, runtimeContext } = processedParams;
404
+ const { resourceId, threadId, requestContext } = processedParams;
410
405
  const response = await this.request(
411
- `/api/agents/${this.agentId}/generate/vnext`,
406
+ `/api/agents/${this.agentId}/generate`,
412
407
  {
413
408
  method: "POST",
414
409
  body: processedParams
@@ -418,11 +413,10 @@ var Agent = class extends BaseResource {
418
413
  return executeToolCallAndRespond({
419
414
  response,
420
415
  params,
421
- runId,
422
416
  resourceId,
423
417
  threadId,
424
- runtimeContext,
425
- respondFn: this.generateVNext.bind(this)
418
+ requestContext,
419
+ respondFn: this.generate.bind(this)
426
420
  });
427
421
  }
428
422
  return response;
@@ -689,17 +683,6 @@ var Agent = class extends BaseResource {
689
683
  });
690
684
  onFinish?.({ message, finishReason, usage });
691
685
  }
692
- /**
693
- * Streams a response from the agent
694
- * @param params - Stream parameters including prompt
695
- * @returns Promise containing the enhanced Response object with processDataStream method
696
- */
697
- async stream(params) {
698
- console.warn(
699
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation the week of September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
700
- );
701
- return this.streamLegacy(params);
702
- }
703
686
  /**
704
687
  * Streams a response from the agent
705
688
  * @param params - Stream parameters including prompt
@@ -710,11 +693,11 @@ var Agent = class extends BaseResource {
710
693
  ...params,
711
694
  output: params.output ? zodToJsonSchema(params.output) : void 0,
712
695
  experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
713
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
696
+ requestContext: parseClientRequestContext(params.requestContext),
714
697
  clientTools: processClientTools(params.clientTools)
715
698
  };
716
699
  const { readable, writable } = new TransformStream();
717
- const response = await this.processStreamResponse(processedParams, writable);
700
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
718
701
  const streamResponse = new Response(readable, {
719
702
  status: response.status,
720
703
  statusText: response.statusText,
@@ -801,6 +784,14 @@ var Agent = class extends BaseResource {
801
784
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
802
785
  onChunk: async (chunk) => {
803
786
  switch (chunk.type) {
787
+ case "tripwire": {
788
+ message.parts.push({
789
+ type: "text",
790
+ text: chunk.payload.tripwireReason
791
+ });
792
+ execUpdate();
793
+ break;
794
+ }
804
795
  case "step-start": {
805
796
  if (!replaceLastMessage) {
806
797
  message.id = chunk.payload.messageId;
@@ -954,7 +945,10 @@ var Agent = class extends BaseResource {
954
945
  break;
955
946
  }
956
947
  case "error": {
957
- throw new Error(chunk.payload.error);
948
+ throw getErrorFromUnknown(chunk.payload.error, {
949
+ fallbackMessage: "Unknown error in stream",
950
+ supportSerialization: false
951
+ });
958
952
  }
959
953
  case "data": {
960
954
  data.push(...chunk.payload.data);
@@ -981,8 +975,8 @@ var Agent = class extends BaseResource {
981
975
  });
982
976
  onFinish?.({ message, finishReason, usage });
983
977
  }
984
- async processStreamResponse_vNext(processedParams, writable) {
985
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
978
+ async processStreamResponse(processedParams, writable, route = "stream") {
979
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
986
980
  method: "POST",
987
981
  body: processedParams,
988
982
  stream: true
@@ -994,21 +988,20 @@ var Agent = class extends BaseResource {
994
988
  let toolCalls = [];
995
989
  let messages = [];
996
990
  const [streamForWritable, streamForProcessing] = response.body.tee();
997
- const pipePromise = streamForWritable.pipeTo(
991
+ streamForWritable.pipeTo(
998
992
  new WritableStream({
999
993
  async write(chunk) {
994
+ let writer;
1000
995
  try {
996
+ writer = writable.getWriter();
1001
997
  const text = new TextDecoder().decode(chunk);
1002
- if (text.includes("[DONE]")) {
1003
- return;
1004
- }
998
+ const lines = text.split("\n\n");
999
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1000
+ await writer.write(new TextEncoder().encode(readableLines));
1005
1001
  } catch {
1006
- }
1007
- const writer = writable.getWriter();
1008
- try {
1009
- await writer.write(chunk);
1002
+ await writer?.write(chunk);
1010
1003
  } finally {
1011
- writer.releaseLock();
1004
+ writer?.releaseLock();
1012
1005
  }
1013
1006
  }
1014
1007
  }),
@@ -1018,7 +1011,7 @@ var Agent = class extends BaseResource {
1018
1011
  ).catch((error) => {
1019
1012
  console.error("Error piping to writable stream:", error);
1020
1013
  });
1021
- await this.processChatResponse_vNext({
1014
+ this.processChatResponse_vNext({
1022
1015
  stream: streamForProcessing,
1023
1016
  update: ({ message }) => {
1024
1017
  const existingIndex = messages.findIndex((m) => m.id === message.id);
@@ -1039,23 +1032,19 @@ var Agent = class extends BaseResource {
1039
1032
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1040
1033
  if (clientTool && clientTool.execute) {
1041
1034
  shouldExecuteClientTool = true;
1042
- const result = await clientTool.execute(
1043
- {
1044
- context: toolCall2?.args,
1045
- runId: processedParams.runId,
1046
- resourceId: processedParams.resourceId,
1047
- threadId: processedParams.threadId,
1048
- runtimeContext: processedParams.runtimeContext,
1049
- // TODO: Pass proper tracing context when client-js supports tracing
1050
- tracingContext: { currentSpan: void 0 },
1051
- suspend: async () => {
1052
- }
1053
- },
1054
- {
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: {
1055
1040
  messages: response.messages,
1056
- toolCallId: toolCall2?.toolCallId
1041
+ toolCallId: toolCall2?.toolCallId,
1042
+ suspend: async () => {
1043
+ },
1044
+ threadId: processedParams.threadId,
1045
+ resourceId: processedParams.resourceId
1057
1046
  }
1058
- );
1047
+ });
1059
1048
  const lastMessageRaw = messages[messages.length - 1];
1060
1049
  const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
1061
1050
  const toolInvocationPart = lastMessage?.parts?.find(
@@ -1076,26 +1065,31 @@ var Agent = class extends BaseResource {
1076
1065
  toolInvocation.result = result;
1077
1066
  }
1078
1067
  const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1079
- await pipePromise;
1080
- await this.processStreamResponse_vNext(
1068
+ this.processStreamResponse(
1081
1069
  {
1082
1070
  ...processedParams,
1083
1071
  messages: updatedMessages
1084
1072
  },
1085
1073
  writable
1086
- );
1074
+ ).catch((error) => {
1075
+ console.error("Error processing stream response:", error);
1076
+ });
1087
1077
  }
1088
1078
  }
1089
1079
  if (!shouldExecuteClientTool) {
1090
- await pipePromise;
1091
- writable.close();
1080
+ setTimeout(() => {
1081
+ writable.close();
1082
+ }, 0);
1092
1083
  }
1093
1084
  } else {
1094
- await pipePromise;
1095
- writable.close();
1085
+ setTimeout(() => {
1086
+ writable.close();
1087
+ }, 0);
1096
1088
  }
1097
1089
  },
1098
1090
  lastMessage: void 0
1091
+ }).catch((error) => {
1092
+ console.error("Error processing stream response:", error);
1099
1093
  });
1100
1094
  } catch (error) {
1101
1095
  console.error("Error processing stream response:", error);
@@ -1126,7 +1120,7 @@ var Agent = class extends BaseResource {
1126
1120
  };
1127
1121
  return streamResponse;
1128
1122
  }
1129
- async streamVNext(messagesOrParams, options) {
1123
+ async stream(messagesOrParams, options) {
1130
1124
  let params;
1131
1125
  if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1132
1126
  params = messagesOrParams;
@@ -1138,8 +1132,7 @@ var Agent = class extends BaseResource {
1138
1132
  }
1139
1133
  const processedParams = {
1140
1134
  ...params,
1141
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1142
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1135
+ requestContext: parseClientRequestContext(params.requestContext),
1143
1136
  clientTools: processClientTools(params.clientTools),
1144
1137
  structuredOutput: params.structuredOutput ? {
1145
1138
  ...params.structuredOutput,
@@ -1147,7 +1140,43 @@ var Agent = class extends BaseResource {
1147
1140
  } : void 0
1148
1141
  };
1149
1142
  const { readable, writable } = new TransformStream();
1150
- const response = await this.processStreamResponse_vNext(processedParams, writable);
1143
+ const response = await this.processStreamResponse(processedParams, writable);
1144
+ const streamResponse = new Response(readable, {
1145
+ status: response.status,
1146
+ statusText: response.statusText,
1147
+ headers: response.headers
1148
+ });
1149
+ streamResponse.processDataStream = async ({
1150
+ onChunk
1151
+ }) => {
1152
+ await processMastraStream({
1153
+ stream: streamResponse.body,
1154
+ onChunk
1155
+ });
1156
+ };
1157
+ return streamResponse;
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");
1151
1180
  const streamResponse = new Response(readable, {
1152
1181
  status: response.status,
1153
1182
  statusText: response.statusText,
@@ -1166,7 +1195,7 @@ var Agent = class extends BaseResource {
1166
1195
  /**
1167
1196
  * Processes the stream response and handles tool calls
1168
1197
  */
1169
- async processStreamResponse(processedParams, writable) {
1198
+ async processStreamResponseLegacy(processedParams, writable) {
1170
1199
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1171
1200
  method: "POST",
1172
1201
  body: processedParams,
@@ -1203,23 +1232,19 @@ var Agent = class extends BaseResource {
1203
1232
  for (const toolCall2 of toolCalls) {
1204
1233
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1205
1234
  if (clientTool && clientTool.execute) {
1206
- const result = await clientTool.execute(
1207
- {
1208
- context: toolCall2?.args,
1209
- runId: processedParams.runId,
1210
- resourceId: processedParams.resourceId,
1211
- threadId: processedParams.threadId,
1212
- runtimeContext: processedParams.runtimeContext,
1213
- // TODO: Pass proper tracing context when client-js supports tracing
1214
- tracingContext: { currentSpan: void 0 },
1215
- suspend: async () => {
1216
- }
1217
- },
1218
- {
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: {
1219
1240
  messages: response.messages,
1220
- toolCallId: toolCall2?.toolCallId
1241
+ toolCallId: toolCall2?.toolCallId,
1242
+ suspend: async () => {
1243
+ },
1244
+ threadId: processedParams.threadId,
1245
+ resourceId: processedParams.resourceId
1221
1246
  }
1222
- );
1247
+ });
1223
1248
  const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1224
1249
  const toolInvocationPart = lastMessage?.parts?.find(
1225
1250
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
@@ -1251,7 +1276,7 @@ var Agent = class extends BaseResource {
1251
1276
  } finally {
1252
1277
  writer.releaseLock();
1253
1278
  }
1254
- this.processStreamResponse(
1279
+ this.processStreamResponseLegacy(
1255
1280
  {
1256
1281
  ...processedParams,
1257
1282
  messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
@@ -1280,11 +1305,11 @@ var Agent = class extends BaseResource {
1280
1305
  /**
1281
1306
  * Gets details about a specific tool available to the agent
1282
1307
  * @param toolId - ID of the tool to retrieve
1283
- * @param runtimeContext - Optional runtime context to pass as query parameter
1308
+ * @param requestContext - Optional request context to pass as query parameter
1284
1309
  * @returns Promise containing tool details
1285
1310
  */
1286
- getTool(toolId, runtimeContext) {
1287
- 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)}`);
1288
1313
  }
1289
1314
  /**
1290
1315
  * Executes a tool for the agent
@@ -1295,29 +1320,13 @@ var Agent = class extends BaseResource {
1295
1320
  executeTool(toolId, params) {
1296
1321
  const body = {
1297
1322
  data: params.data,
1298
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1323
+ requestContext: parseClientRequestContext(params.requestContext)
1299
1324
  };
1300
1325
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1301
1326
  method: "POST",
1302
1327
  body
1303
1328
  });
1304
1329
  }
1305
- /**
1306
- * Retrieves evaluation results for the agent
1307
- * @param runtimeContext - Optional runtime context to pass as query parameter
1308
- * @returns Promise containing agent evaluations
1309
- */
1310
- evals(runtimeContext) {
1311
- return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1312
- }
1313
- /**
1314
- * Retrieves live evaluation results for the agent
1315
- * @param runtimeContext - Optional runtime context to pass as query parameter
1316
- * @returns Promise containing live agent evaluations
1317
- */
1318
- liveEvals(runtimeContext) {
1319
- return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1320
- }
1321
1330
  /**
1322
1331
  * Updates the model for the agent
1323
1332
  * @param params - Parameters for updating the model
@@ -1329,6 +1338,15 @@ var Agent = class extends BaseResource {
1329
1338
  body: params
1330
1339
  });
1331
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
+ }
1332
1350
  /**
1333
1351
  * Updates the model for the agent in the model list
1334
1352
  * @param params - Parameters for updating the model
@@ -1362,72 +1380,78 @@ var MemoryThread = class extends BaseResource {
1362
1380
  }
1363
1381
  /**
1364
1382
  * Retrieves the memory thread details
1383
+ * @param requestContext - Optional request context to pass as query parameter
1365
1384
  * @returns Promise containing thread details including title and metadata
1366
1385
  */
1367
- get() {
1368
- 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
+ );
1369
1390
  }
1370
1391
  /**
1371
1392
  * Updates the memory thread properties
1372
- * @param params - Update parameters including title and metadata
1393
+ * @param params - Update parameters including title, metadata, and optional request context
1373
1394
  * @returns Promise containing updated thread details
1374
1395
  */
1375
1396
  update(params) {
1376
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1377
- method: "PATCH",
1378
- body: params
1379
- });
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
+ );
1380
1404
  }
1381
1405
  /**
1382
1406
  * Deletes the memory thread
1407
+ * @param requestContext - Optional request context to pass as query parameter
1383
1408
  * @returns Promise containing deletion result
1384
1409
  */
1385
- delete() {
1386
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
1387
- method: "DELETE"
1388
- });
1389
- }
1390
- /**
1391
- * Retrieves messages associated with the thread
1392
- * @param params - Optional parameters including limit for number of messages to retrieve
1393
- * @returns Promise containing thread messages and UI messages
1394
- */
1395
- getMessages(params) {
1396
- const query = new URLSearchParams({
1397
- agentId: this.agentId,
1398
- ...params?.limit ? { limit: params.limit.toString() } : {}
1399
- });
1400
- 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
+ );
1401
1417
  }
1402
1418
  /**
1403
- * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1404
- * @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
1405
1421
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1406
1422
  */
1407
- getMessagesPaginated({
1408
- selectBy,
1409
- ...rest
1410
- }) {
1411
- const query = new URLSearchParams({
1412
- ...rest,
1413
- ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1414
- });
1415
- 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);
1416
1436
  }
1417
1437
  /**
1418
1438
  * Deletes one or more messages from the thread
1419
1439
  * @param messageIds - Can be a single message ID (string), array of message IDs,
1420
1440
  * message object with id property, or array of message objects
1441
+ * @param requestContext - Optional request context to pass as query parameter
1421
1442
  * @returns Promise containing deletion result
1422
1443
  */
1423
- deleteMessages(messageIds) {
1444
+ deleteMessages(messageIds, requestContext) {
1424
1445
  const query = new URLSearchParams({
1425
1446
  agentId: this.agentId
1426
1447
  });
1427
- return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1428
- method: "POST",
1429
- body: { messageIds }
1430
- });
1448
+ return this.request(
1449
+ `/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
1450
+ {
1451
+ method: "POST",
1452
+ body: { messageIds }
1453
+ }
1454
+ );
1431
1455
  }
1432
1456
  };
1433
1457
 
@@ -1440,12 +1464,12 @@ var Vector = class extends BaseResource {
1440
1464
  /**
1441
1465
  * Retrieves details about a specific vector index
1442
1466
  * @param indexName - Name of the index to get details for
1443
- * @param runtimeContext - Optional runtime context to pass as query parameter
1467
+ * @param requestContext - Optional request context to pass as query parameter
1444
1468
  * @returns Promise containing vector index details
1445
1469
  */
1446
- details(indexName, runtimeContext) {
1470
+ details(indexName, requestContext) {
1447
1471
  return this.request(
1448
- `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1472
+ `/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
1449
1473
  );
1450
1474
  }
1451
1475
  /**
@@ -1460,11 +1484,11 @@ var Vector = class extends BaseResource {
1460
1484
  }
1461
1485
  /**
1462
1486
  * Retrieves a list of all available indexes
1463
- * @param runtimeContext - Optional runtime context to pass as query parameter
1487
+ * @param requestContext - Optional request context to pass as query parameter
1464
1488
  * @returns Promise containing array of index names
1465
1489
  */
1466
- getIndexes(runtimeContext) {
1467
- return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1490
+ getIndexes(requestContext) {
1491
+ return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
1468
1492
  }
1469
1493
  /**
1470
1494
  * Creates a new vector index
@@ -1509,11 +1533,11 @@ var Tool = class extends BaseResource {
1509
1533
  }
1510
1534
  /**
1511
1535
  * Retrieves details about the tool
1512
- * @param runtimeContext - Optional runtime context to pass as query parameter
1536
+ * @param requestContext - Optional request context to pass as query parameter
1513
1537
  * @returns Promise containing tool details including description and schemas
1514
1538
  */
1515
- details(runtimeContext) {
1516
- return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1539
+ details(requestContext) {
1540
+ return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
1517
1541
  }
1518
1542
  /**
1519
1543
  * Executes the tool with the provided parameters
@@ -1527,7 +1551,7 @@ var Tool = class extends BaseResource {
1527
1551
  }
1528
1552
  const body = {
1529
1553
  data: params.data,
1530
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1554
+ requestContext: parseClientRequestContext(params.requestContext)
1531
1555
  };
1532
1556
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1533
1557
  method: "POST",
@@ -1543,67 +1567,22 @@ var Workflow = class extends BaseResource {
1543
1567
  super(options);
1544
1568
  this.workflowId = workflowId;
1545
1569
  }
1546
- /**
1547
- * Creates an async generator that processes a readable stream and yields workflow records
1548
- * separated by the Record Separator character (\x1E)
1549
- *
1550
- * @param stream - The readable stream to process
1551
- * @returns An async generator that yields parsed records
1552
- */
1553
- async *streamProcessor(stream) {
1554
- const reader = stream.getReader();
1555
- let doneReading = false;
1556
- let buffer = "";
1557
- try {
1558
- while (!doneReading) {
1559
- const { done, value } = await reader.read();
1560
- doneReading = done;
1561
- if (done && !value) continue;
1562
- try {
1563
- const decoded = value ? new TextDecoder().decode(value) : "";
1564
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1565
- buffer = chunks.pop() || "";
1566
- for (const chunk of chunks) {
1567
- if (chunk) {
1568
- if (typeof chunk === "string") {
1569
- try {
1570
- const parsedChunk = JSON.parse(chunk);
1571
- yield parsedChunk;
1572
- } catch {
1573
- }
1574
- }
1575
- }
1576
- }
1577
- } catch {
1578
- }
1579
- }
1580
- if (buffer) {
1581
- try {
1582
- yield JSON.parse(buffer);
1583
- } catch {
1584
- }
1585
- }
1586
- } finally {
1587
- reader.cancel().catch(() => {
1588
- });
1589
- }
1590
- }
1591
1570
  /**
1592
1571
  * Retrieves details about the workflow
1593
- * @param runtimeContext - Optional runtime context to pass as query parameter
1572
+ * @param requestContext - Optional request context to pass as query parameter
1594
1573
  * @returns Promise containing workflow details including steps and graphs
1595
1574
  */
1596
- details(runtimeContext) {
1597
- return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1575
+ details(requestContext) {
1576
+ return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
1598
1577
  }
1599
1578
  /**
1600
1579
  * Retrieves all runs for a workflow
1601
1580
  * @param params - Parameters for filtering runs
1602
- * @param runtimeContext - Optional runtime context to pass as query parameter
1581
+ * @param requestContext - Optional request context to pass as query parameter
1603
1582
  * @returns Promise containing workflow runs array
1604
1583
  */
1605
- runs(params, runtimeContext) {
1606
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1584
+ runs(params, requestContext) {
1585
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
1607
1586
  const searchParams = new URLSearchParams();
1608
1587
  if (params?.fromDate) {
1609
1588
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1611,17 +1590,21 @@ var Workflow = class extends BaseResource {
1611
1590
  if (params?.toDate) {
1612
1591
  searchParams.set("toDate", params.toDate.toISOString());
1613
1592
  }
1614
- if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1615
- 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
+ }
1616
1599
  }
1617
- if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1618
- 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));
1619
1602
  }
1620
1603
  if (params?.resourceId) {
1621
1604
  searchParams.set("resourceId", params.resourceId);
1622
1605
  }
1623
- if (runtimeContextParam) {
1624
- searchParams.set("runtimeContext", runtimeContextParam);
1606
+ if (requestContextParam) {
1607
+ searchParams.set("requestContext", requestContextParam);
1625
1608
  }
1626
1609
  if (searchParams.size) {
1627
1610
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
@@ -1632,21 +1615,21 @@ var Workflow = class extends BaseResource {
1632
1615
  /**
1633
1616
  * Retrieves a specific workflow run by its ID
1634
1617
  * @param runId - The ID of the workflow run to retrieve
1635
- * @param runtimeContext - Optional runtime context to pass as query parameter
1618
+ * @param requestContext - Optional request context to pass as query parameter
1636
1619
  * @returns Promise containing the workflow run details
1637
1620
  */
1638
- runById(runId, runtimeContext) {
1639
- 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)}`);
1640
1623
  }
1641
1624
  /**
1642
1625
  * Retrieves the execution result for a specific workflow run by its ID
1643
1626
  * @param runId - The ID of the workflow run to retrieve the execution result for
1644
- * @param runtimeContext - Optional runtime context to pass as query parameter
1627
+ * @param requestContext - Optional request context to pass as query parameter
1645
1628
  * @returns Promise containing the workflow run execution result
1646
1629
  */
1647
- runExecutionResult(runId, runtimeContext) {
1630
+ runExecutionResult(runId, requestContext) {
1648
1631
  return this.request(
1649
- `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1632
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
1650
1633
  );
1651
1634
  }
1652
1635
  /**
@@ -1659,32 +1642,12 @@ var Workflow = class extends BaseResource {
1659
1642
  method: "POST"
1660
1643
  });
1661
1644
  }
1662
- /**
1663
- * Sends an event to a specific workflow run by its ID
1664
- * @param params - Object containing the runId, event and data
1665
- * @returns Promise containing a success message
1666
- */
1667
- sendRunEvent(params) {
1668
- return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1669
- method: "POST",
1670
- body: { event: params.event, data: params.data }
1671
- });
1672
- }
1673
- /**
1674
- * @deprecated Use createRunAsync() instead.
1675
- * @throws {Error} Always throws an error directing users to use createRunAsync()
1676
- */
1677
- async createRun(_params) {
1678
- throw new Error(
1679
- "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."
1680
- );
1681
- }
1682
1645
  /**
1683
1646
  * Creates a new workflow run
1684
1647
  * @param params - Optional object containing the optional runId
1685
1648
  * @returns Promise containing the runId of the created run with methods to control execution
1686
1649
  */
1687
- async createRunAsync(params) {
1650
+ async createRun(params) {
1688
1651
  const searchParams = new URLSearchParams();
1689
1652
  if (!!params?.runId) {
1690
1653
  searchParams.set("runId", params.runId);
@@ -1702,7 +1665,7 @@ var Workflow = class extends BaseResource {
1702
1665
  return this.start({
1703
1666
  runId,
1704
1667
  inputData: p.inputData,
1705
- runtimeContext: p.runtimeContext,
1668
+ requestContext: p.requestContext,
1706
1669
  tracingOptions: p.tracingOptions
1707
1670
  });
1708
1671
  },
@@ -1710,22 +1673,19 @@ var Workflow = class extends BaseResource {
1710
1673
  return this.startAsync({
1711
1674
  runId,
1712
1675
  inputData: p.inputData,
1713
- runtimeContext: p.runtimeContext,
1676
+ requestContext: p.requestContext,
1714
1677
  tracingOptions: p.tracingOptions
1715
1678
  });
1716
1679
  },
1717
- watch: async (onRecord) => {
1718
- return this.watch({ runId }, onRecord);
1719
- },
1720
1680
  stream: async (p) => {
1721
- return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1681
+ return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
1722
1682
  },
1723
1683
  resume: async (p) => {
1724
1684
  return this.resume({
1725
1685
  runId,
1726
1686
  step: p.step,
1727
1687
  resumeData: p.resumeData,
1728
- runtimeContext: p.runtimeContext,
1688
+ requestContext: p.requestContext,
1729
1689
  tracingOptions: p.tracingOptions
1730
1690
  });
1731
1691
  },
@@ -1734,7 +1694,7 @@ var Workflow = class extends BaseResource {
1734
1694
  runId,
1735
1695
  step: p.step,
1736
1696
  resumeData: p.resumeData,
1737
- runtimeContext: p.runtimeContext,
1697
+ requestContext: p.requestContext,
1738
1698
  tracingOptions: p.tracingOptions
1739
1699
  });
1740
1700
  },
@@ -1743,26 +1703,26 @@ var Workflow = class extends BaseResource {
1743
1703
  runId,
1744
1704
  step: p.step,
1745
1705
  resumeData: p.resumeData,
1746
- runtimeContext: p.runtimeContext
1706
+ requestContext: p.requestContext
1747
1707
  });
1748
1708
  }
1749
1709
  };
1750
1710
  }
1751
1711
  /**
1752
1712
  * Starts a workflow run synchronously without waiting for the workflow to complete
1753
- * @param params - Object containing the runId, inputData and runtimeContext
1713
+ * @param params - Object containing the runId, inputData and requestContext
1754
1714
  * @returns Promise containing success message
1755
1715
  */
1756
1716
  start(params) {
1757
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1717
+ const requestContext = parseClientRequestContext(params.requestContext);
1758
1718
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1759
1719
  method: "POST",
1760
- body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1720
+ body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
1761
1721
  });
1762
1722
  }
1763
1723
  /**
1764
1724
  * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
1765
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1725
+ * @param params - Object containing the runId, step, resumeData and requestContext
1766
1726
  * @returns Promise containing success message
1767
1727
  */
1768
1728
  resume({
@@ -1772,20 +1732,20 @@ var Workflow = class extends BaseResource {
1772
1732
  tracingOptions,
1773
1733
  ...rest
1774
1734
  }) {
1775
- const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1735
+ const requestContext = parseClientRequestContext(rest.requestContext);
1776
1736
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1777
1737
  method: "POST",
1778
1738
  body: {
1779
1739
  step,
1780
1740
  resumeData,
1781
- runtimeContext,
1741
+ requestContext,
1782
1742
  tracingOptions
1783
1743
  }
1784
1744
  });
1785
1745
  }
1786
1746
  /**
1787
1747
  * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1788
- * @param params - Object containing the optional runId, inputData and runtimeContext
1748
+ * @param params - Object containing the optional runId, inputData and requestContext
1789
1749
  * @returns Promise containing the workflow execution results
1790
1750
  */
1791
1751
  startAsync(params) {
@@ -1793,15 +1753,15 @@ var Workflow = class extends BaseResource {
1793
1753
  if (!!params?.runId) {
1794
1754
  searchParams.set("runId", params.runId);
1795
1755
  }
1796
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1756
+ const requestContext = parseClientRequestContext(params.requestContext);
1797
1757
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1798
1758
  method: "POST",
1799
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1759
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
1800
1760
  });
1801
1761
  }
1802
1762
  /**
1803
1763
  * Starts a workflow run and returns a stream
1804
- * @param params - Object containing the optional runId, inputData and runtimeContext
1764
+ * @param params - Object containing the optional runId, inputData and requestContext
1805
1765
  * @returns Promise containing the workflow execution results
1806
1766
  */
1807
1767
  async stream(params) {
@@ -1809,12 +1769,12 @@ var Workflow = class extends BaseResource {
1809
1769
  if (!!params?.runId) {
1810
1770
  searchParams.set("runId", params.runId);
1811
1771
  }
1812
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1772
+ const requestContext = parseClientRequestContext(params.requestContext);
1813
1773
  const response = await this.request(
1814
1774
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1815
1775
  {
1816
1776
  method: "POST",
1817
- body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1777
+ body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
1818
1778
  stream: true
1819
1779
  }
1820
1780
  );
@@ -1899,7 +1859,7 @@ var Workflow = class extends BaseResource {
1899
1859
  }
1900
1860
  /**
1901
1861
  * Starts a workflow run and returns a stream
1902
- * @param params - Object containing the optional runId, inputData and runtimeContext
1862
+ * @param params - Object containing the optional runId, inputData and requestContext
1903
1863
  * @returns Promise containing the workflow execution results
1904
1864
  */
1905
1865
  async streamVNext(params) {
@@ -1907,14 +1867,14 @@ var Workflow = class extends BaseResource {
1907
1867
  if (!!params?.runId) {
1908
1868
  searchParams.set("runId", params.runId);
1909
1869
  }
1910
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1870
+ const requestContext = parseClientRequestContext(params.requestContext);
1911
1871
  const response = await this.request(
1912
1872
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1913
1873
  {
1914
1874
  method: "POST",
1915
1875
  body: {
1916
1876
  inputData: params.inputData,
1917
- runtimeContext,
1877
+ requestContext,
1918
1878
  closeOnSuspend: params.closeOnSuspend,
1919
1879
  tracingOptions: params.tracingOptions
1920
1880
  },
@@ -1953,62 +1913,123 @@ var Workflow = class extends BaseResource {
1953
1913
  });
1954
1914
  return response.body.pipeThrough(transformStream);
1955
1915
  }
1916
+ /**
1917
+ * Observes workflow vNext stream for a workflow run
1918
+ * @param params - Object containing the runId
1919
+ * @returns Promise containing the workflow execution results
1920
+ */
1921
+ async observeStreamVNext(params) {
1922
+ const searchParams = new URLSearchParams();
1923
+ searchParams.set("runId", params.runId);
1924
+ const response = await this.request(
1925
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
1926
+ {
1927
+ method: "POST",
1928
+ stream: true
1929
+ }
1930
+ );
1931
+ if (!response.ok) {
1932
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
1933
+ }
1934
+ if (!response.body) {
1935
+ throw new Error("Response body is null");
1936
+ }
1937
+ let failedChunk = void 0;
1938
+ const transformStream = new TransformStream({
1939
+ start() {
1940
+ },
1941
+ async transform(chunk, controller) {
1942
+ try {
1943
+ const decoded = new TextDecoder().decode(chunk);
1944
+ const chunks = decoded.split(RECORD_SEPARATOR);
1945
+ for (const chunk2 of chunks) {
1946
+ if (chunk2) {
1947
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1948
+ try {
1949
+ const parsedChunk = JSON.parse(newChunk);
1950
+ controller.enqueue(parsedChunk);
1951
+ failedChunk = void 0;
1952
+ } catch {
1953
+ failedChunk = newChunk;
1954
+ }
1955
+ }
1956
+ }
1957
+ } catch {
1958
+ }
1959
+ }
1960
+ });
1961
+ return response.body.pipeThrough(transformStream);
1962
+ }
1956
1963
  /**
1957
1964
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1958
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1965
+ * @param params - Object containing the runId, step, resumeData and requestContext
1959
1966
  * @returns Promise containing the workflow resume results
1960
1967
  */
1961
1968
  resumeAsync(params) {
1962
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1969
+ const requestContext = parseClientRequestContext(params.requestContext);
1963
1970
  return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
1964
1971
  method: "POST",
1965
1972
  body: {
1966
1973
  step: params.step,
1967
1974
  resumeData: params.resumeData,
1968
- runtimeContext,
1975
+ requestContext,
1969
1976
  tracingOptions: params.tracingOptions
1970
1977
  }
1971
1978
  });
1972
1979
  }
1973
1980
  /**
1974
1981
  * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1975
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1982
+ * @param params - Object containing the runId, step, resumeData and requestContext
1976
1983
  * @returns Promise containing the workflow resume results
1977
1984
  */
1978
- resumeStreamVNext(params) {
1979
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1980
- return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1981
- method: "POST",
1982
- body: {
1983
- step: params.step,
1984
- resumeData: params.resumeData,
1985
- runtimeContext,
1986
- tracingOptions: params.tracingOptions
1985
+ async resumeStreamVNext(params) {
1986
+ const searchParams = new URLSearchParams();
1987
+ searchParams.set("runId", params.runId);
1988
+ const requestContext = parseClientRequestContext(params.requestContext);
1989
+ const response = await this.request(
1990
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
1991
+ {
1992
+ method: "POST",
1993
+ body: {
1994
+ step: params.step,
1995
+ resumeData: params.resumeData,
1996
+ requestContext,
1997
+ tracingOptions: params.tracingOptions
1998
+ },
1999
+ stream: true
1987
2000
  }
1988
- });
1989
- }
1990
- /**
1991
- * Watches workflow transitions in real-time
1992
- * @param runId - Optional run ID to filter the watch stream
1993
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
1994
- */
1995
- async watch({ runId }, onRecord) {
1996
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
1997
- stream: true
1998
- });
2001
+ );
1999
2002
  if (!response.ok) {
2000
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
2003
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2001
2004
  }
2002
2005
  if (!response.body) {
2003
2006
  throw new Error("Response body is null");
2004
2007
  }
2005
- for await (const record of this.streamProcessor(response.body)) {
2006
- if (typeof record === "string") {
2007
- onRecord(JSON.parse(record));
2008
- } else {
2009
- onRecord(record);
2008
+ let failedChunk = void 0;
2009
+ const transformStream = new TransformStream({
2010
+ start() {
2011
+ },
2012
+ async transform(chunk, controller) {
2013
+ try {
2014
+ const decoded = new TextDecoder().decode(chunk);
2015
+ const chunks = decoded.split(RECORD_SEPARATOR);
2016
+ for (const chunk2 of chunks) {
2017
+ if (chunk2) {
2018
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2019
+ try {
2020
+ const parsedChunk = JSON.parse(newChunk);
2021
+ controller.enqueue(parsedChunk);
2022
+ failedChunk = void 0;
2023
+ } catch {
2024
+ failedChunk = newChunk;
2025
+ }
2026
+ }
2027
+ }
2028
+ } catch {
2029
+ }
2010
2030
  }
2011
- }
2031
+ });
2032
+ return response.body.pipeThrough(transformStream);
2012
2033
  }
2013
2034
  /**
2014
2035
  * Creates a new ReadableStream from an iterable or async iterable of objects,
@@ -2121,22 +2142,22 @@ var MCPTool = class extends BaseResource {
2121
2142
  }
2122
2143
  /**
2123
2144
  * Retrieves details about this specific tool from the MCP server.
2124
- * @param runtimeContext - Optional runtime context to pass as query parameter
2145
+ * @param requestContext - Optional request context to pass as query parameter
2125
2146
  * @returns Promise containing the tool's information (name, description, schema).
2126
2147
  */
2127
- details(runtimeContext) {
2128
- 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)}`);
2129
2150
  }
2130
2151
  /**
2131
2152
  * Executes this specific tool on the MCP server.
2132
- * @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.
2133
2154
  * @returns Promise containing the result of the tool execution.
2134
2155
  */
2135
2156
  execute(params) {
2136
2157
  const body = {};
2137
2158
  if (params.data !== void 0) body.data = params.data;
2138
- if (params.runtimeContext !== void 0) {
2139
- body.runtimeContext = params.runtimeContext;
2159
+ if (params.requestContext !== void 0) {
2160
+ body.requestContext = params.requestContext;
2140
2161
  }
2141
2162
  return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
2142
2163
  method: "POST",
@@ -2182,19 +2203,39 @@ var AgentBuilder = class extends BaseResource {
2182
2203
  }
2183
2204
  }
2184
2205
  /**
2185
- * @deprecated Use createRunAsync() instead.
2186
- * @throws {Error} Always throws an error directing users to use createRunAsync()
2206
+ * Creates a transform stream that parses binary chunks into JSON records.
2187
2207
  */
2188
- async createRun(_params) {
2189
- throw new Error(
2190
- "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."
2191
- );
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
+ });
2192
2233
  }
2193
2234
  /**
2194
2235
  * Creates a new agent builder action run and returns the runId.
2195
2236
  * This calls `/api/agent-builder/:actionId/create-run`.
2196
2237
  */
2197
- async createRunAsync(params) {
2238
+ async createRun(params) {
2198
2239
  const searchParams = new URLSearchParams();
2199
2240
  if (!!params?.runId) {
2200
2241
  searchParams.set("runId", params.runId);
@@ -2213,12 +2254,12 @@ var AgentBuilder = class extends BaseResource {
2213
2254
  if (runId) {
2214
2255
  searchParams.set("runId", runId);
2215
2256
  }
2216
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2217
- const { runtimeContext: _, ...actionParams } = params;
2257
+ const requestContext = parseClientRequestContext(params.requestContext);
2258
+ const { requestContext: _, ...actionParams } = params;
2218
2259
  const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2219
2260
  const result = await this.request(url, {
2220
2261
  method: "POST",
2221
- body: { ...actionParams, runtimeContext }
2262
+ body: { ...actionParams, requestContext }
2222
2263
  });
2223
2264
  return this.transformWorkflowResult(result);
2224
2265
  }
@@ -2229,12 +2270,12 @@ var AgentBuilder = class extends BaseResource {
2229
2270
  async startActionRun(params, runId) {
2230
2271
  const searchParams = new URLSearchParams();
2231
2272
  searchParams.set("runId", runId);
2232
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2233
- const { runtimeContext: _, ...actionParams } = params;
2273
+ const requestContext = parseClientRequestContext(params.requestContext);
2274
+ const { requestContext: _, ...actionParams } = params;
2234
2275
  const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2235
2276
  return this.request(url, {
2236
2277
  method: "POST",
2237
- body: { ...actionParams, runtimeContext }
2278
+ body: { ...actionParams, requestContext }
2238
2279
  });
2239
2280
  }
2240
2281
  /**
@@ -2244,12 +2285,12 @@ var AgentBuilder = class extends BaseResource {
2244
2285
  async resume(params, runId) {
2245
2286
  const searchParams = new URLSearchParams();
2246
2287
  searchParams.set("runId", runId);
2247
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2248
- const { runtimeContext: _, ...resumeParams } = params;
2288
+ const requestContext = parseClientRequestContext(params.requestContext);
2289
+ const { requestContext: _, ...resumeParams } = params;
2249
2290
  const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2250
2291
  return this.request(url, {
2251
2292
  method: "POST",
2252
- body: { ...resumeParams, runtimeContext }
2293
+ body: { ...resumeParams, requestContext }
2253
2294
  });
2254
2295
  }
2255
2296
  /**
@@ -2259,12 +2300,12 @@ var AgentBuilder = class extends BaseResource {
2259
2300
  async resumeAsync(params, runId) {
2260
2301
  const searchParams = new URLSearchParams();
2261
2302
  searchParams.set("runId", runId);
2262
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2263
- const { runtimeContext: _, ...resumeParams } = params;
2303
+ const requestContext = parseClientRequestContext(params.requestContext);
2304
+ const { requestContext: _, ...resumeParams } = params;
2264
2305
  const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2265
2306
  const result = await this.request(url, {
2266
2307
  method: "POST",
2267
- body: { ...resumeParams, runtimeContext }
2308
+ body: { ...resumeParams, requestContext }
2268
2309
  });
2269
2310
  return this.transformWorkflowResult(result);
2270
2311
  }
@@ -2322,12 +2363,12 @@ var AgentBuilder = class extends BaseResource {
2322
2363
  if (runId) {
2323
2364
  searchParams.set("runId", runId);
2324
2365
  }
2325
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2326
- const { runtimeContext: _, ...actionParams } = params;
2366
+ const requestContext = parseClientRequestContext(params.requestContext);
2367
+ const { requestContext: _, ...actionParams } = params;
2327
2368
  const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2328
2369
  const response = await this.request(url, {
2329
2370
  method: "POST",
2330
- body: { ...actionParams, runtimeContext },
2371
+ body: { ...actionParams, requestContext },
2331
2372
  stream: true
2332
2373
  });
2333
2374
  if (!response.ok) {
@@ -2336,31 +2377,7 @@ var AgentBuilder = class extends BaseResource {
2336
2377
  if (!response.body) {
2337
2378
  throw new Error("Response body is null");
2338
2379
  }
2339
- let failedChunk = void 0;
2340
- const transformStream = new TransformStream({
2341
- start() {
2342
- },
2343
- async transform(chunk, controller) {
2344
- try {
2345
- const decoded = new TextDecoder().decode(chunk);
2346
- const chunks = decoded.split(RECORD_SEPARATOR2);
2347
- for (const chunk2 of chunks) {
2348
- if (chunk2) {
2349
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2350
- try {
2351
- const parsedChunk = JSON.parse(newChunk);
2352
- controller.enqueue(parsedChunk);
2353
- failedChunk = void 0;
2354
- } catch {
2355
- failedChunk = newChunk;
2356
- }
2357
- }
2358
- }
2359
- } catch {
2360
- }
2361
- }
2362
- });
2363
- return response.body.pipeThrough(transformStream);
2380
+ return response.body.pipeThrough(this.createRecordParserTransform());
2364
2381
  }
2365
2382
  /**
2366
2383
  * Streams agent builder action progress in real-time using VNext streaming.
@@ -2371,12 +2388,12 @@ var AgentBuilder = class extends BaseResource {
2371
2388
  if (runId) {
2372
2389
  searchParams.set("runId", runId);
2373
2390
  }
2374
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2375
- const { runtimeContext: _, ...actionParams } = params;
2391
+ const requestContext = parseClientRequestContext(params.requestContext);
2392
+ const { requestContext: _, ...actionParams } = params;
2376
2393
  const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2377
2394
  const response = await this.request(url, {
2378
2395
  method: "POST",
2379
- body: { ...actionParams, runtimeContext },
2396
+ body: { ...actionParams, requestContext },
2380
2397
  stream: true
2381
2398
  });
2382
2399
  if (!response.ok) {
@@ -2385,57 +2402,94 @@ var AgentBuilder = class extends BaseResource {
2385
2402
  if (!response.body) {
2386
2403
  throw new Error("Response body is null");
2387
2404
  }
2388
- let failedChunk = void 0;
2389
- const transformStream = new TransformStream({
2390
- start() {
2391
- },
2392
- async transform(chunk, controller) {
2393
- try {
2394
- const decoded = new TextDecoder().decode(chunk);
2395
- const chunks = decoded.split(RECORD_SEPARATOR2);
2396
- for (const chunk2 of chunks) {
2397
- if (chunk2) {
2398
- const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2399
- try {
2400
- const parsedChunk = JSON.parse(newChunk);
2401
- controller.enqueue(parsedChunk);
2402
- failedChunk = void 0;
2403
- } catch {
2404
- failedChunk = newChunk;
2405
- }
2406
- }
2407
- }
2408
- } catch {
2409
- }
2410
- }
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
2411
2420
  });
2412
- 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());
2413
2428
  }
2414
2429
  /**
2415
- * Watches an existing agent builder action run by runId.
2416
- * This is used for hot reload recovery - it loads the existing run state
2417
- * and streams any remaining progress.
2418
- * This calls `/api/agent-builder/:actionId/watch`.
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`.
2419
2433
  */
2420
- async watch({ runId, eventType }, onRecord) {
2421
- const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
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()}`;
2422
2438
  const response = await this.request(url, {
2423
- method: "GET",
2439
+ method: "POST",
2424
2440
  stream: true
2425
2441
  });
2426
2442
  if (!response.ok) {
2427
- throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
2443
+ throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
2428
2444
  }
2429
2445
  if (!response.body) {
2430
2446
  throw new Error("Response body is null");
2431
2447
  }
2432
- for await (const record of this.streamProcessor(response.body)) {
2433
- if (typeof record === "string") {
2434
- onRecord(JSON.parse(record));
2435
- } else {
2436
- onRecord(record);
2437
- }
2448
+ return response.body.pipeThrough(this.createRecordParserTransform());
2449
+ }
2450
+ /**
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`.
2454
+ */
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()}`;
2459
+ const response = await this.request(url, {
2460
+ method: "POST",
2461
+ stream: true
2462
+ });
2463
+ if (!response.ok) {
2464
+ throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
2465
+ }
2466
+ if (!response.body) {
2467
+ throw new Error("Response body is null");
2468
+ }
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");
2438
2491
  }
2492
+ return response.body.pipeThrough(this.createRecordParserTransform());
2439
2493
  }
2440
2494
  /**
2441
2495
  * Gets a specific action run by its ID.
@@ -2467,11 +2521,11 @@ var AgentBuilder = class extends BaseResource {
2467
2521
  if (params?.toDate) {
2468
2522
  searchParams.set("toDate", params.toDate.toISOString());
2469
2523
  }
2470
- if (params?.limit !== void 0) {
2471
- searchParams.set("limit", String(params.limit));
2524
+ if (params?.perPage !== void 0) {
2525
+ searchParams.set("perPage", String(params.perPage));
2472
2526
  }
2473
- if (params?.offset !== void 0) {
2474
- searchParams.set("offset", String(params.offset));
2527
+ if (params?.page !== void 0) {
2528
+ searchParams.set("page", String(params.page));
2475
2529
  }
2476
2530
  if (params?.resourceId) {
2477
2531
  searchParams.set("resourceId", params.resourceId);
@@ -2501,17 +2555,6 @@ var AgentBuilder = class extends BaseResource {
2501
2555
  method: "POST"
2502
2556
  });
2503
2557
  }
2504
- /**
2505
- * Sends an event to an agent builder action run.
2506
- * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
2507
- */
2508
- async sendRunEvent(params) {
2509
- const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2510
- return this.request(url, {
2511
- method: "POST",
2512
- body: { event: params.event, data: params.data }
2513
- });
2514
- }
2515
2558
  };
2516
2559
 
2517
2560
  // src/resources/observability.ts
@@ -2520,15 +2563,15 @@ var Observability = class extends BaseResource {
2520
2563
  super(options);
2521
2564
  }
2522
2565
  /**
2523
- * Retrieves a specific AI trace by ID
2566
+ * Retrieves a specific trace by ID
2524
2567
  * @param traceId - ID of the trace to retrieve
2525
- * @returns Promise containing the AI trace with all its spans
2568
+ * @returns Promise containing the trace with all its spans
2526
2569
  */
2527
2570
  getTrace(traceId) {
2528
2571
  return this.request(`/api/observability/traces/${traceId}`);
2529
2572
  }
2530
2573
  /**
2531
- * Retrieves paginated list of AI traces with optional filtering
2574
+ * Retrieves paginated list of traces with optional filtering
2532
2575
  * @param params - Parameters for pagination and filtering
2533
2576
  * @returns Promise containing paginated traces and pagination info
2534
2577
  */
@@ -2568,7 +2611,7 @@ var Observability = class extends BaseResource {
2568
2611
  * @param params - Parameters containing trace ID, span ID, and pagination options
2569
2612
  * @returns Promise containing scores and pagination info
2570
2613
  */
2571
- getScoresBySpan(params) {
2614
+ listScoresBySpan(params) {
2572
2615
  const { traceId, spanId, page, perPage } = params;
2573
2616
  const searchParams = new URLSearchParams();
2574
2617
  if (page !== void 0) {
@@ -2590,208 +2633,6 @@ var Observability = class extends BaseResource {
2590
2633
  }
2591
2634
  };
2592
2635
 
2593
- // src/resources/network-memory-thread.ts
2594
- var NetworkMemoryThread = class extends BaseResource {
2595
- constructor(options, threadId, networkId) {
2596
- super(options);
2597
- this.threadId = threadId;
2598
- this.networkId = networkId;
2599
- }
2600
- /**
2601
- * Retrieves the memory thread details
2602
- * @returns Promise containing thread details including title and metadata
2603
- */
2604
- get() {
2605
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
2606
- }
2607
- /**
2608
- * Updates the memory thread properties
2609
- * @param params - Update parameters including title and metadata
2610
- * @returns Promise containing updated thread details
2611
- */
2612
- update(params) {
2613
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2614
- method: "PATCH",
2615
- body: params
2616
- });
2617
- }
2618
- /**
2619
- * Deletes the memory thread
2620
- * @returns Promise containing deletion result
2621
- */
2622
- delete() {
2623
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
2624
- method: "DELETE"
2625
- });
2626
- }
2627
- /**
2628
- * Retrieves messages associated with the thread
2629
- * @param params - Optional parameters including limit for number of messages to retrieve
2630
- * @returns Promise containing thread messages and UI messages
2631
- */
2632
- getMessages(params) {
2633
- const query = new URLSearchParams({
2634
- networkId: this.networkId,
2635
- ...params?.limit ? { limit: params.limit.toString() } : {}
2636
- });
2637
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
2638
- }
2639
- /**
2640
- * Deletes one or more messages from the thread
2641
- * @param messageIds - Can be a single message ID (string), array of message IDs,
2642
- * message object with id property, or array of message objects
2643
- * @returns Promise containing deletion result
2644
- */
2645
- deleteMessages(messageIds) {
2646
- const query = new URLSearchParams({
2647
- networkId: this.networkId
2648
- });
2649
- return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
2650
- method: "POST",
2651
- body: { messageIds }
2652
- });
2653
- }
2654
- };
2655
-
2656
- // src/resources/vNextNetwork.ts
2657
- var RECORD_SEPARATOR3 = "";
2658
- var VNextNetwork = class extends BaseResource {
2659
- constructor(options, networkId) {
2660
- super(options);
2661
- this.networkId = networkId;
2662
- }
2663
- /**
2664
- * Retrieves details about the network
2665
- * @param runtimeContext - Optional runtime context to pass as query parameter
2666
- * @returns Promise containing vNext network details
2667
- */
2668
- details(runtimeContext) {
2669
- return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2670
- }
2671
- /**
2672
- * Generates a response from the v-next network
2673
- * @param params - Generation parameters including message
2674
- * @returns Promise containing the generated response
2675
- */
2676
- generate(params) {
2677
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2678
- method: "POST",
2679
- body: {
2680
- ...params,
2681
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2682
- }
2683
- });
2684
- }
2685
- /**
2686
- * Generates a response from the v-next network using multiple primitives
2687
- * @param params - Generation parameters including message
2688
- * @returns Promise containing the generated response
2689
- */
2690
- loop(params) {
2691
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2692
- method: "POST",
2693
- body: {
2694
- ...params,
2695
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2696
- }
2697
- });
2698
- }
2699
- async *streamProcessor(stream) {
2700
- const reader = stream.getReader();
2701
- let doneReading = false;
2702
- let buffer = "";
2703
- try {
2704
- while (!doneReading) {
2705
- const { done, value } = await reader.read();
2706
- doneReading = done;
2707
- if (done && !value) continue;
2708
- try {
2709
- const decoded = value ? new TextDecoder().decode(value) : "";
2710
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2711
- buffer = chunks.pop() || "";
2712
- for (const chunk of chunks) {
2713
- if (chunk) {
2714
- if (typeof chunk === "string") {
2715
- try {
2716
- const parsedChunk = JSON.parse(chunk);
2717
- yield parsedChunk;
2718
- } catch {
2719
- }
2720
- }
2721
- }
2722
- }
2723
- } catch {
2724
- }
2725
- }
2726
- if (buffer) {
2727
- try {
2728
- yield JSON.parse(buffer);
2729
- } catch {
2730
- }
2731
- }
2732
- } finally {
2733
- reader.cancel().catch(() => {
2734
- });
2735
- }
2736
- }
2737
- /**
2738
- * Streams a response from the v-next network
2739
- * @param params - Stream parameters including message
2740
- * @returns Promise containing the results
2741
- */
2742
- async stream(params, onRecord) {
2743
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2744
- method: "POST",
2745
- body: {
2746
- ...params,
2747
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2748
- },
2749
- stream: true
2750
- });
2751
- if (!response.ok) {
2752
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2753
- }
2754
- if (!response.body) {
2755
- throw new Error("Response body is null");
2756
- }
2757
- for await (const record of this.streamProcessor(response.body)) {
2758
- if (typeof record === "string") {
2759
- onRecord(JSON.parse(record));
2760
- } else {
2761
- onRecord(record);
2762
- }
2763
- }
2764
- }
2765
- /**
2766
- * Streams a response from the v-next network loop
2767
- * @param params - Stream parameters including message
2768
- * @returns Promise containing the results
2769
- */
2770
- async loopStream(params, onRecord) {
2771
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2772
- method: "POST",
2773
- body: {
2774
- ...params,
2775
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2776
- },
2777
- stream: true
2778
- });
2779
- if (!response.ok) {
2780
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2781
- }
2782
- if (!response.body) {
2783
- throw new Error("Response body is null");
2784
- }
2785
- for await (const record of this.streamProcessor(response.body)) {
2786
- if (typeof record === "string") {
2787
- onRecord(JSON.parse(record));
2788
- } else {
2789
- onRecord(record);
2790
- }
2791
- }
2792
- }
2793
- };
2794
-
2795
2636
  // src/client.ts
2796
2637
  var MastraClient = class extends BaseResource {
2797
2638
  observability;
@@ -2801,18 +2642,21 @@ var MastraClient = class extends BaseResource {
2801
2642
  }
2802
2643
  /**
2803
2644
  * Retrieves all available agents
2804
- * @param runtimeContext - Optional runtime context to pass as query parameter
2645
+ * @param requestContext - Optional request context to pass as query parameter
2805
2646
  * @returns Promise containing map of agent IDs to agent details
2806
2647
  */
2807
- getAgents(runtimeContext) {
2808
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2648
+ listAgents(requestContext) {
2649
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2809
2650
  const searchParams = new URLSearchParams();
2810
- if (runtimeContextParam) {
2811
- searchParams.set("runtimeContext", runtimeContextParam);
2651
+ if (requestContextParam) {
2652
+ searchParams.set("requestContext", requestContextParam);
2812
2653
  }
2813
2654
  const queryString = searchParams.toString();
2814
2655
  return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2815
2656
  }
2657
+ listAgentsModelProviders() {
2658
+ return this.request(`/api/agents/providers`);
2659
+ }
2816
2660
  /**
2817
2661
  * Gets an agent instance by ID
2818
2662
  * @param agentId - ID of the agent to retrieve
@@ -2822,125 +2666,115 @@ var MastraClient = class extends BaseResource {
2822
2666
  return new Agent(this.options, agentId);
2823
2667
  }
2824
2668
  /**
2825
- * Retrieves memory threads for a resource
2826
- * @param params - Parameters containing the resource ID
2827
- * @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
2828
2672
  */
2829
- getMemoryThreads(params) {
2830
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2673
+ async 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
+ const response = await this.request(
2684
+ `/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
2685
+ );
2686
+ const actualResponse = "threads" in response ? response : {
2687
+ threads: response,
2688
+ total: response.length,
2689
+ page: params.page ?? 0,
2690
+ perPage: params.perPage ?? 100,
2691
+ hasMore: false
2692
+ };
2693
+ return actualResponse;
2831
2694
  }
2832
2695
  /**
2833
2696
  * Retrieves memory config for a resource
2834
- * @param params - Parameters containing the resource ID
2835
- * @returns Promise containing array of memory threads
2697
+ * @param params - Parameters containing the resource ID and optional request context
2698
+ * @returns Promise containing memory configuration
2836
2699
  */
2837
2700
  getMemoryConfig(params) {
2838
- return this.request(`/api/memory/config?agentId=${params.agentId}`);
2701
+ return this.request(
2702
+ `/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
2703
+ );
2839
2704
  }
2840
2705
  /**
2841
2706
  * Creates a new memory thread
2842
- * @param params - Parameters for creating the memory thread
2707
+ * @param params - Parameters for creating the memory thread including optional request context
2843
2708
  * @returns Promise containing the created memory thread
2844
2709
  */
2845
2710
  createMemoryThread(params) {
2846
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
2711
+ return this.request(
2712
+ `/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2713
+ { method: "POST", body: params }
2714
+ );
2847
2715
  }
2848
2716
  /**
2849
2717
  * Gets a memory thread instance by ID
2850
2718
  * @param threadId - ID of the memory thread to retrieve
2851
2719
  * @returns MemoryThread instance
2852
2720
  */
2853
- getMemoryThread(threadId, agentId) {
2721
+ getMemoryThread({ threadId, agentId }) {
2854
2722
  return new MemoryThread(this.options, threadId, agentId);
2855
2723
  }
2856
- getThreadMessages(threadId, opts = {}) {
2724
+ listThreadMessages(threadId, opts = {}) {
2725
+ if (!opts.agentId && !opts.networkId) {
2726
+ throw new Error("Either agentId or networkId must be provided");
2727
+ }
2857
2728
  let url = "";
2858
2729
  if (opts.agentId) {
2859
- url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2730
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2860
2731
  } else if (opts.networkId) {
2861
- url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2732
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2862
2733
  }
2863
2734
  return this.request(url);
2864
2735
  }
2865
2736
  deleteThread(threadId, opts = {}) {
2866
2737
  let url = "";
2867
2738
  if (opts.agentId) {
2868
- url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2739
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
2869
2740
  } else if (opts.networkId) {
2870
- url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2741
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
2871
2742
  }
2872
2743
  return this.request(url, { method: "DELETE" });
2873
2744
  }
2874
2745
  /**
2875
2746
  * Saves messages to memory
2876
- * @param params - Parameters containing messages to save
2747
+ * @param params - Parameters containing messages to save and optional request context
2877
2748
  * @returns Promise containing the saved messages
2878
2749
  */
2879
2750
  saveMessageToMemory(params) {
2880
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
2881
- method: "POST",
2882
- body: params
2883
- });
2884
- }
2885
- /**
2886
- * Gets the status of the memory system
2887
- * @returns Promise containing memory system status
2888
- */
2889
- getMemoryStatus(agentId) {
2890
- return this.request(`/api/memory/status?agentId=${agentId}`);
2891
- }
2892
- /**
2893
- * Retrieves memory threads for a resource
2894
- * @param params - Parameters containing the resource ID
2895
- * @returns Promise containing array of memory threads
2896
- */
2897
- getNetworkMemoryThreads(params) {
2898
- return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
2899
- }
2900
- /**
2901
- * Creates a new memory thread
2902
- * @param params - Parameters for creating the memory thread
2903
- * @returns Promise containing the created memory thread
2904
- */
2905
- createNetworkMemoryThread(params) {
2906
- return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
2907
- }
2908
- /**
2909
- * Gets a memory thread instance by ID
2910
- * @param threadId - ID of the memory thread to retrieve
2911
- * @returns MemoryThread instance
2912
- */
2913
- getNetworkMemoryThread(threadId, networkId) {
2914
- return new NetworkMemoryThread(this.options, threadId, networkId);
2915
- }
2916
- /**
2917
- * Saves messages to memory
2918
- * @param params - Parameters containing messages to save
2919
- * @returns Promise containing the saved messages
2920
- */
2921
- saveNetworkMessageToMemory(params) {
2922
- return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
2923
- method: "POST",
2924
- body: params
2925
- });
2751
+ return this.request(
2752
+ `/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
2753
+ {
2754
+ method: "POST",
2755
+ body: params
2756
+ }
2757
+ );
2926
2758
  }
2927
2759
  /**
2928
2760
  * Gets the status of the memory system
2761
+ * @param agentId - The agent ID
2762
+ * @param requestContext - Optional request context to pass as query parameter
2929
2763
  * @returns Promise containing memory system status
2930
2764
  */
2931
- getNetworkMemoryStatus(networkId) {
2932
- return this.request(`/api/memory/network/status?networkId=${networkId}`);
2765
+ getMemoryStatus(agentId, requestContext) {
2766
+ return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
2933
2767
  }
2934
2768
  /**
2935
2769
  * Retrieves all available tools
2936
- * @param runtimeContext - Optional runtime context to pass as query parameter
2770
+ * @param requestContext - Optional request context to pass as query parameter
2937
2771
  * @returns Promise containing map of tool IDs to tool details
2938
2772
  */
2939
- getTools(runtimeContext) {
2940
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2773
+ listTools(requestContext) {
2774
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2941
2775
  const searchParams = new URLSearchParams();
2942
- if (runtimeContextParam) {
2943
- searchParams.set("runtimeContext", runtimeContextParam);
2776
+ if (requestContextParam) {
2777
+ searchParams.set("requestContext", requestContextParam);
2944
2778
  }
2945
2779
  const queryString = searchParams.toString();
2946
2780
  return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
@@ -2955,14 +2789,14 @@ var MastraClient = class extends BaseResource {
2955
2789
  }
2956
2790
  /**
2957
2791
  * Retrieves all available workflows
2958
- * @param runtimeContext - Optional runtime context to pass as query parameter
2792
+ * @param requestContext - Optional request context to pass as query parameter
2959
2793
  * @returns Promise containing map of workflow IDs to workflow details
2960
2794
  */
2961
- getWorkflows(runtimeContext) {
2962
- const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2795
+ listWorkflows(requestContext) {
2796
+ const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
2963
2797
  const searchParams = new URLSearchParams();
2964
- if (runtimeContextParam) {
2965
- searchParams.set("runtimeContext", runtimeContextParam);
2798
+ if (requestContextParam) {
2799
+ searchParams.set("requestContext", requestContextParam);
2966
2800
  }
2967
2801
  const queryString = searchParams.toString();
2968
2802
  return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
@@ -3002,7 +2836,7 @@ var MastraClient = class extends BaseResource {
3002
2836
  * @param params - Parameters for filtering logs
3003
2837
  * @returns Promise containing array of log messages
3004
2838
  */
3005
- getLogs(params) {
2839
+ listLogs(params) {
3006
2840
  const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
3007
2841
  const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
3008
2842
  const searchParams = new URLSearchParams();
@@ -3088,78 +2922,21 @@ var MastraClient = class extends BaseResource {
3088
2922
  * List of all log transports
3089
2923
  * @returns Promise containing list of log transports
3090
2924
  */
3091
- getLogTransports() {
2925
+ listLogTransports() {
3092
2926
  return this.request("/api/logs/transports");
3093
2927
  }
3094
- /**
3095
- * List of all traces (paged)
3096
- * @param params - Parameters for filtering traces
3097
- * @returns Promise containing telemetry data
3098
- */
3099
- getTelemetry(params) {
3100
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3101
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3102
- const searchParams = new URLSearchParams();
3103
- if (name) {
3104
- searchParams.set("name", name);
3105
- }
3106
- if (scope) {
3107
- searchParams.set("scope", scope);
3108
- }
3109
- if (page) {
3110
- searchParams.set("page", String(page));
3111
- }
3112
- if (perPage) {
3113
- searchParams.set("perPage", String(perPage));
3114
- }
3115
- if (_attribute) {
3116
- if (Array.isArray(_attribute)) {
3117
- for (const attr of _attribute) {
3118
- searchParams.append("attribute", attr);
3119
- }
3120
- } else {
3121
- searchParams.set("attribute", _attribute);
3122
- }
3123
- }
3124
- if (fromDate) {
3125
- searchParams.set("fromDate", fromDate.toISOString());
3126
- }
3127
- if (toDate) {
3128
- searchParams.set("toDate", toDate.toISOString());
3129
- }
3130
- if (searchParams.size) {
3131
- return this.request(`/api/telemetry?${searchParams}`);
3132
- } else {
3133
- return this.request(`/api/telemetry`);
3134
- }
3135
- }
3136
- /**
3137
- * Retrieves all available vNext networks
3138
- * @returns Promise containing map of vNext network IDs to vNext network details
3139
- */
3140
- getVNextNetworks() {
3141
- return this.request("/api/networks/v-next");
3142
- }
3143
- /**
3144
- * Gets a vNext network instance by ID
3145
- * @param networkId - ID of the vNext network to retrieve
3146
- * @returns vNext Network instance
3147
- */
3148
- getVNextNetwork(networkId) {
3149
- return new VNextNetwork(this.options, networkId);
3150
- }
3151
2928
  /**
3152
2929
  * Retrieves a list of available MCP servers.
3153
- * @param params - Optional parameters for pagination (limit, offset).
2930
+ * @param params - Optional parameters for pagination (perPage, page).
3154
2931
  * @returns Promise containing the list of MCP servers and pagination info.
3155
2932
  */
3156
2933
  getMcpServers(params) {
3157
2934
  const searchParams = new URLSearchParams();
3158
- if (params?.limit !== void 0) {
3159
- searchParams.set("limit", String(params.limit));
2935
+ if (params?.perPage !== void 0) {
2936
+ searchParams.set("perPage", String(params.perPage));
3160
2937
  }
3161
- if (params?.offset !== void 0) {
3162
- searchParams.set("offset", String(params.offset));
2938
+ if (params?.page !== void 0) {
2939
+ searchParams.set("page", String(params.page));
3163
2940
  }
3164
2941
  const queryString = searchParams.toString();
3165
2942
  return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
@@ -3214,9 +2991,33 @@ var MastraClient = class extends BaseResource {
3214
2991
  getWorkingMemory({
3215
2992
  agentId,
3216
2993
  threadId,
3217
- resourceId
2994
+ resourceId,
2995
+ requestContext
3218
2996
  }) {
3219
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2997
+ return this.request(
2998
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
2999
+ );
3000
+ }
3001
+ searchMemory({
3002
+ agentId,
3003
+ resourceId,
3004
+ threadId,
3005
+ searchQuery,
3006
+ memoryConfig,
3007
+ requestContext
3008
+ }) {
3009
+ const params = new URLSearchParams({
3010
+ searchQuery,
3011
+ resourceId,
3012
+ agentId
3013
+ });
3014
+ if (threadId) {
3015
+ params.append("threadId", threadId);
3016
+ }
3017
+ if (memoryConfig) {
3018
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3019
+ }
3020
+ return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
3220
3021
  }
3221
3022
  /**
3222
3023
  * Updates the working memory for a specific thread (optionally resource-scoped).
@@ -3229,21 +3030,25 @@ var MastraClient = class extends BaseResource {
3229
3030
  agentId,
3230
3031
  threadId,
3231
3032
  workingMemory,
3232
- resourceId
3033
+ resourceId,
3034
+ requestContext
3233
3035
  }) {
3234
- return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3235
- method: "POST",
3236
- body: {
3237
- workingMemory,
3238
- resourceId
3036
+ return this.request(
3037
+ `/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
3038
+ {
3039
+ method: "POST",
3040
+ body: {
3041
+ workingMemory,
3042
+ resourceId
3043
+ }
3239
3044
  }
3240
- });
3045
+ );
3241
3046
  }
3242
3047
  /**
3243
3048
  * Retrieves all available scorers
3244
3049
  * @returns Promise containing list of available scorers
3245
3050
  */
3246
- getScorers() {
3051
+ listScorers() {
3247
3052
  return this.request("/api/scores/scorers");
3248
3053
  }
3249
3054
  /**
@@ -3254,7 +3059,7 @@ var MastraClient = class extends BaseResource {
3254
3059
  getScorer(scorerId) {
3255
3060
  return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3256
3061
  }
3257
- getScoresByScorerId(params) {
3062
+ listScoresByScorerId(params) {
3258
3063
  const { page, perPage, scorerId, entityId, entityType } = params;
3259
3064
  const searchParams = new URLSearchParams();
3260
3065
  if (entityId) {
@@ -3277,7 +3082,7 @@ var MastraClient = class extends BaseResource {
3277
3082
  * @param params - Parameters containing run ID and pagination options
3278
3083
  * @returns Promise containing scores and pagination info
3279
3084
  */
3280
- getScoresByRunId(params) {
3085
+ listScoresByRunId(params) {
3281
3086
  const { runId, page, perPage } = params;
3282
3087
  const searchParams = new URLSearchParams();
3283
3088
  if (page !== void 0) {
@@ -3294,7 +3099,7 @@ var MastraClient = class extends BaseResource {
3294
3099
  * @param params - Parameters containing entity ID, type, and pagination options
3295
3100
  * @returns Promise containing scores and pagination info
3296
3101
  */
3297
- getScoresByEntityId(params) {
3102
+ listScoresByEntityId(params) {
3298
3103
  const { entityId, entityType, page, perPage } = params;
3299
3104
  const searchParams = new URLSearchParams();
3300
3105
  if (page !== void 0) {
@@ -3319,21 +3124,14 @@ var MastraClient = class extends BaseResource {
3319
3124
  body: params
3320
3125
  });
3321
3126
  }
3322
- /**
3323
- * Retrieves model providers with available keys
3324
- * @returns Promise containing model providers with available keys
3325
- */
3326
- getModelProviders() {
3327
- return this.request(`/api/model-providers`);
3328
- }
3329
- getAITrace(traceId) {
3127
+ getTrace(traceId) {
3330
3128
  return this.observability.getTrace(traceId);
3331
3129
  }
3332
- getAITraces(params) {
3130
+ getTraces(params) {
3333
3131
  return this.observability.getTraces(params);
3334
3132
  }
3335
- getScoresBySpan(params) {
3336
- return this.observability.getScoresBySpan(params);
3133
+ listScoresBySpan(params) {
3134
+ return this.observability.listScoresBySpan(params);
3337
3135
  }
3338
3136
  score(params) {
3339
3137
  return this.observability.score(params);