@mastra/client-js 0.0.0-add-save-score-validation-on-stores-20250911031242 → 0.0.0-add-crumb-action-20251028105537

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +527 -3
  2. package/README.md +6 -10
  3. package/dist/client.d.ts +45 -45
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +645 -646
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +639 -642
  10. package/dist/index.js.map +1 -1
  11. package/dist/resources/agent-builder.d.ts +5 -6
  12. package/dist/resources/agent-builder.d.ts.map +1 -1
  13. package/dist/resources/agent.d.ts +86 -42
  14. package/dist/resources/agent.d.ts.map +1 -1
  15. package/dist/resources/index.d.ts +0 -2
  16. package/dist/resources/index.d.ts.map +1 -1
  17. package/dist/resources/mcp-tool.d.ts +2 -1
  18. package/dist/resources/mcp-tool.d.ts.map +1 -1
  19. package/dist/resources/observability.d.ts +17 -1
  20. package/dist/resources/observability.d.ts.map +1 -1
  21. package/dist/resources/tool.d.ts +2 -1
  22. package/dist/resources/tool.d.ts.map +1 -1
  23. package/dist/resources/vector.d.ts +5 -2
  24. package/dist/resources/vector.d.ts.map +1 -1
  25. package/dist/resources/workflow.d.ts +119 -19
  26. package/dist/resources/workflow.d.ts.map +1 -1
  27. package/dist/tools.d.ts +22 -0
  28. package/dist/tools.d.ts.map +1 -0
  29. package/dist/types.d.ts +98 -97
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/utils/index.d.ts +2 -0
  32. package/dist/utils/index.d.ts.map +1 -1
  33. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  34. package/package.json +6 -6
  35. package/dist/resources/legacy-workflow.d.ts +0 -87
  36. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  37. package/dist/resources/network.d.ts +0 -30
  38. package/dist/resources/network.d.ts.map +0 -1
  39. package/dist/resources/vNextNetwork.d.ts +0 -42
  40. package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
2
2
  import { v4 } from '@lukeed/uuid';
3
+ import { getErrorFromUnknown } from '@mastra/core/error';
3
4
  import { RuntimeContext } from '@mastra/core/runtime-context';
4
5
  import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
5
6
  import { z } from 'zod';
@@ -15,6 +16,20 @@ function parseClientRuntimeContext(runtimeContext) {
15
16
  }
16
17
  return void 0;
17
18
  }
19
+ function base64RuntimeContext(runtimeContext) {
20
+ if (runtimeContext) {
21
+ return btoa(JSON.stringify(runtimeContext));
22
+ }
23
+ return void 0;
24
+ }
25
+ function runtimeContextQueryString(runtimeContext) {
26
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
27
+ if (!runtimeContextParam) return "";
28
+ const searchParams = new URLSearchParams();
29
+ searchParams.set("runtimeContext", runtimeContextParam);
30
+ const queryString = searchParams.toString();
31
+ return queryString ? `?${queryString}` : "";
32
+ }
18
33
  function isZodType(value) {
19
34
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
20
35
  }
@@ -77,14 +92,18 @@ async function sharedProcessMastraStream({
77
92
  if (line.startsWith("data: ")) {
78
93
  const data = line.slice(6);
79
94
  if (data === "[DONE]") {
80
- console.log("\u{1F3C1} Stream finished");
95
+ console.info("\u{1F3C1} Stream finished");
81
96
  return;
82
97
  }
98
+ let json;
83
99
  try {
84
- const json = JSON.parse(data);
85
- await onChunk(json);
100
+ json = JSON.parse(data);
86
101
  } catch (error) {
87
102
  console.error("\u274C JSON parse error:", error, "Data:", data);
103
+ continue;
104
+ }
105
+ if (json) {
106
+ await onChunk(json);
88
107
  }
89
108
  }
90
109
  }
@@ -199,7 +218,9 @@ async function executeToolCallAndRespond({
199
218
  resourceId,
200
219
  threadId,
201
220
  runtimeContext,
202
- tracingContext: { currentSpan: void 0 }
221
+ tracingContext: { currentSpan: void 0 },
222
+ suspend: async () => {
223
+ }
203
224
  },
204
225
  {
205
226
  messages: response.messages,
@@ -207,11 +228,7 @@ async function executeToolCallAndRespond({
207
228
  }
208
229
  );
209
230
  const updatedMessages = [
210
- {
211
- role: "user",
212
- content: params.messages
213
- },
214
- ...response.response.messages,
231
+ ...response.response.messages || [],
215
232
  {
216
233
  role: "tool",
217
234
  content: [
@@ -273,17 +290,21 @@ var AgentVoice = class extends BaseResource {
273
290
  }
274
291
  /**
275
292
  * Get available speakers for the agent's voice provider
293
+ * @param runtimeContext - Optional runtime context to pass as query parameter
294
+ * @param runtimeContext - Optional runtime context to pass as query parameter
276
295
  * @returns Promise containing list of available speakers
277
296
  */
278
- getSpeakers() {
279
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
297
+ getSpeakers(runtimeContext) {
298
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
280
299
  }
281
300
  /**
282
301
  * Get the listener configuration for the agent's voice provider
302
+ * @param runtimeContext - Optional runtime context to pass as query parameter
303
+ * @param runtimeContext - Optional runtime context to pass as query parameter
283
304
  * @returns Promise containing a check if the agent has listening capabilities
284
305
  */
285
- getListener() {
286
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
306
+ getListener(runtimeContext) {
307
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
287
308
  }
288
309
  };
289
310
  var Agent = class extends BaseResource {
@@ -295,16 +316,17 @@ var Agent = class extends BaseResource {
295
316
  voice;
296
317
  /**
297
318
  * Retrieves details about the agent
319
+ * @param runtimeContext - Optional runtime context to pass as query parameter
298
320
  * @returns Promise containing agent details including model and instructions
299
321
  */
300
- details() {
301
- return this.request(`/api/agents/${this.agentId}`);
322
+ details(runtimeContext) {
323
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
302
324
  }
303
- async generate(params) {
304
- console.warn(
305
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
306
- );
307
- return this.generateLegacy(params);
325
+ enhanceInstructions(instructions, comment) {
326
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
327
+ method: "POST",
328
+ body: { instructions, comment }
329
+ });
308
330
  }
309
331
  async generateLegacy(params) {
310
332
  const processedParams = {
@@ -337,7 +359,9 @@ var Agent = class extends BaseResource {
337
359
  resourceId,
338
360
  threadId,
339
361
  runtimeContext,
340
- tracingContext: { currentSpan: void 0 }
362
+ tracingContext: { currentSpan: void 0 },
363
+ suspend: async () => {
364
+ }
341
365
  },
342
366
  {
343
367
  messages: response.messages,
@@ -345,10 +369,6 @@ var Agent = class extends BaseResource {
345
369
  }
346
370
  );
347
371
  const updatedMessages = [
348
- {
349
- role: "user",
350
- content: params.messages
351
- },
352
372
  ...response.response.messages,
353
373
  {
354
374
  role: "tool",
@@ -371,10 +391,18 @@ var Agent = class extends BaseResource {
371
391
  }
372
392
  return response;
373
393
  }
374
- async generateVNext(params) {
394
+ async generate(messagesOrParams, options) {
395
+ let params;
396
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
397
+ params = messagesOrParams;
398
+ } else {
399
+ params = {
400
+ messages: messagesOrParams,
401
+ ...options
402
+ };
403
+ }
375
404
  const processedParams = {
376
405
  ...params,
377
- output: params.output ? zodToJsonSchema(params.output) : void 0,
378
406
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
379
407
  clientTools: processClientTools(params.clientTools),
380
408
  structuredOutput: params.structuredOutput ? {
@@ -384,7 +412,7 @@ var Agent = class extends BaseResource {
384
412
  };
385
413
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
386
414
  const response = await this.request(
387
- `/api/agents/${this.agentId}/generate/vnext`,
415
+ `/api/agents/${this.agentId}/generate`,
388
416
  {
389
417
  method: "POST",
390
418
  body: processedParams
@@ -398,7 +426,7 @@ var Agent = class extends BaseResource {
398
426
  resourceId,
399
427
  threadId,
400
428
  runtimeContext,
401
- respondFn: this.generateVNext.bind(this)
429
+ respondFn: this.generate.bind(this)
402
430
  });
403
431
  }
404
432
  return response;
@@ -665,17 +693,6 @@ var Agent = class extends BaseResource {
665
693
  });
666
694
  onFinish?.({ message, finishReason, usage });
667
695
  }
668
- /**
669
- * Streams a response from the agent
670
- * @param params - Stream parameters including prompt
671
- * @returns Promise containing the enhanced Response object with processDataStream method
672
- */
673
- async stream(params) {
674
- console.warn(
675
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
676
- );
677
- return this.streamLegacy(params);
678
- }
679
696
  /**
680
697
  * Streams a response from the agent
681
698
  * @param params - Stream parameters including prompt
@@ -690,7 +707,7 @@ var Agent = class extends BaseResource {
690
707
  clientTools: processClientTools(params.clientTools)
691
708
  };
692
709
  const { readable, writable } = new TransformStream();
693
- const response = await this.processStreamResponse(processedParams, writable);
710
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
694
711
  const streamResponse = new Response(readable, {
695
712
  status: response.status,
696
713
  statusText: response.statusText,
@@ -777,6 +794,14 @@ var Agent = class extends BaseResource {
777
794
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
778
795
  onChunk: async (chunk) => {
779
796
  switch (chunk.type) {
797
+ case "tripwire": {
798
+ message.parts.push({
799
+ type: "text",
800
+ text: chunk.payload.tripwireReason
801
+ });
802
+ execUpdate();
803
+ break;
804
+ }
780
805
  case "step-start": {
781
806
  if (!replaceLastMessage) {
782
807
  message.id = chunk.payload.messageId;
@@ -930,7 +955,10 @@ var Agent = class extends BaseResource {
930
955
  break;
931
956
  }
932
957
  case "error": {
933
- throw new Error(chunk.payload.error);
958
+ throw getErrorFromUnknown(chunk.payload.error, {
959
+ fallbackMessage: "Unknown error in stream",
960
+ supportSerialization: false
961
+ });
934
962
  }
935
963
  case "data": {
936
964
  data.push(...chunk.payload.data);
@@ -957,8 +985,8 @@ var Agent = class extends BaseResource {
957
985
  });
958
986
  onFinish?.({ message, finishReason, usage });
959
987
  }
960
- async processStreamResponse_vNext(processedParams, writable) {
961
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
988
+ async processStreamResponse(processedParams, writable, route = "stream") {
989
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
962
990
  method: "POST",
963
991
  body: processedParams,
964
992
  stream: true
@@ -973,18 +1001,17 @@ var Agent = class extends BaseResource {
973
1001
  streamForWritable.pipeTo(
974
1002
  new WritableStream({
975
1003
  async write(chunk) {
1004
+ let writer;
976
1005
  try {
1006
+ writer = writable.getWriter();
977
1007
  const text = new TextDecoder().decode(chunk);
978
- if (text.includes("[DONE]")) {
979
- return;
980
- }
1008
+ const lines = text.split("\n\n");
1009
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1010
+ await writer.write(new TextEncoder().encode(readableLines));
981
1011
  } catch {
982
- }
983
- const writer = writable.getWriter();
984
- try {
985
- await writer.write(chunk);
1012
+ await writer?.write(chunk);
986
1013
  } finally {
987
- writer.releaseLock();
1014
+ writer?.releaseLock();
988
1015
  }
989
1016
  }
990
1017
  }),
@@ -1010,9 +1037,11 @@ var Agent = class extends BaseResource {
1010
1037
  if (toolCall) {
1011
1038
  toolCalls.push(toolCall);
1012
1039
  }
1040
+ let shouldExecuteClientTool = false;
1013
1041
  for (const toolCall2 of toolCalls) {
1014
1042
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1015
1043
  if (clientTool && clientTool.execute) {
1044
+ shouldExecuteClientTool = true;
1016
1045
  const result = await clientTool.execute(
1017
1046
  {
1018
1047
  context: toolCall2?.args,
@@ -1021,7 +1050,9 @@ var Agent = class extends BaseResource {
1021
1050
  threadId: processedParams.threadId,
1022
1051
  runtimeContext: processedParams.runtimeContext,
1023
1052
  // TODO: Pass proper tracing context when client-js supports tracing
1024
- tracingContext: { currentSpan: void 0 }
1053
+ tracingContext: { currentSpan: void 0 },
1054
+ suspend: async () => {
1055
+ }
1025
1056
  },
1026
1057
  {
1027
1058
  messages: response.messages,
@@ -1047,10 +1078,8 @@ var Agent = class extends BaseResource {
1047
1078
  toolInvocation.state = "result";
1048
1079
  toolInvocation.result = result;
1049
1080
  }
1050
- const originalMessages = processedParams.messages;
1051
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1052
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1053
- this.processStreamResponse_vNext(
1081
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1082
+ this.processStreamResponse(
1054
1083
  {
1055
1084
  ...processedParams,
1056
1085
  messages: updatedMessages
@@ -1061,6 +1090,11 @@ var Agent = class extends BaseResource {
1061
1090
  });
1062
1091
  }
1063
1092
  }
1093
+ if (!shouldExecuteClientTool) {
1094
+ setTimeout(() => {
1095
+ writable.close();
1096
+ }, 0);
1097
+ }
1064
1098
  } else {
1065
1099
  setTimeout(() => {
1066
1100
  writable.close();
@@ -1100,10 +1134,18 @@ var Agent = class extends BaseResource {
1100
1134
  };
1101
1135
  return streamResponse;
1102
1136
  }
1103
- async streamVNext(params) {
1137
+ async stream(messagesOrParams, options) {
1138
+ let params;
1139
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1140
+ params = messagesOrParams;
1141
+ } else {
1142
+ params = {
1143
+ messages: messagesOrParams,
1144
+ ...options
1145
+ };
1146
+ }
1104
1147
  const processedParams = {
1105
1148
  ...params,
1106
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1107
1149
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1108
1150
  clientTools: processClientTools(params.clientTools),
1109
1151
  structuredOutput: params.structuredOutput ? {
@@ -1112,7 +1154,43 @@ var Agent = class extends BaseResource {
1112
1154
  } : void 0
1113
1155
  };
1114
1156
  const { readable, writable } = new TransformStream();
1115
- const response = await this.processStreamResponse_vNext(processedParams, writable);
1157
+ const response = await this.processStreamResponse(processedParams, writable);
1158
+ const streamResponse = new Response(readable, {
1159
+ status: response.status,
1160
+ statusText: response.statusText,
1161
+ headers: response.headers
1162
+ });
1163
+ streamResponse.processDataStream = async ({
1164
+ onChunk
1165
+ }) => {
1166
+ await processMastraStream({
1167
+ stream: streamResponse.body,
1168
+ onChunk
1169
+ });
1170
+ };
1171
+ return streamResponse;
1172
+ }
1173
+ async approveToolCall(params) {
1174
+ const { readable, writable } = new TransformStream();
1175
+ const response = await this.processStreamResponse(params, writable, "approve-tool-call");
1176
+ const streamResponse = new Response(readable, {
1177
+ status: response.status,
1178
+ statusText: response.statusText,
1179
+ headers: response.headers
1180
+ });
1181
+ streamResponse.processDataStream = async ({
1182
+ onChunk
1183
+ }) => {
1184
+ await processMastraStream({
1185
+ stream: streamResponse.body,
1186
+ onChunk
1187
+ });
1188
+ };
1189
+ return streamResponse;
1190
+ }
1191
+ async declineToolCall(params) {
1192
+ const { readable, writable } = new TransformStream();
1193
+ const response = await this.processStreamResponse(params, writable, "decline-tool-call");
1116
1194
  const streamResponse = new Response(readable, {
1117
1195
  status: response.status,
1118
1196
  statusText: response.statusText,
@@ -1131,7 +1209,7 @@ var Agent = class extends BaseResource {
1131
1209
  /**
1132
1210
  * Processes the stream response and handles tool calls
1133
1211
  */
1134
- async processStreamResponse(processedParams, writable) {
1212
+ async processStreamResponseLegacy(processedParams, writable) {
1135
1213
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1136
1214
  method: "POST",
1137
1215
  body: processedParams,
@@ -1176,7 +1254,9 @@ var Agent = class extends BaseResource {
1176
1254
  threadId: processedParams.threadId,
1177
1255
  runtimeContext: processedParams.runtimeContext,
1178
1256
  // TODO: Pass proper tracing context when client-js supports tracing
1179
- tracingContext: { currentSpan: void 0 }
1257
+ tracingContext: { currentSpan: void 0 },
1258
+ suspend: async () => {
1259
+ }
1180
1260
  },
1181
1261
  {
1182
1262
  messages: response.messages,
@@ -1214,12 +1294,10 @@ var Agent = class extends BaseResource {
1214
1294
  } finally {
1215
1295
  writer.releaseLock();
1216
1296
  }
1217
- const originalMessages = processedParams.messages;
1218
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1219
- this.processStreamResponse(
1297
+ this.processStreamResponseLegacy(
1220
1298
  {
1221
1299
  ...processedParams,
1222
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1300
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1223
1301
  },
1224
1302
  writable
1225
1303
  ).catch((error) => {
@@ -1245,10 +1323,11 @@ var Agent = class extends BaseResource {
1245
1323
  /**
1246
1324
  * Gets details about a specific tool available to the agent
1247
1325
  * @param toolId - ID of the tool to retrieve
1326
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1248
1327
  * @returns Promise containing tool details
1249
1328
  */
1250
- getTool(toolId) {
1251
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1329
+ getTool(toolId, runtimeContext) {
1330
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1252
1331
  }
1253
1332
  /**
1254
1333
  * Executes a tool for the agent
@@ -1259,7 +1338,7 @@ var Agent = class extends BaseResource {
1259
1338
  executeTool(toolId, params) {
1260
1339
  const body = {
1261
1340
  data: params.data,
1262
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1341
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1263
1342
  };
1264
1343
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1265
1344
  method: "POST",
@@ -1268,17 +1347,19 @@ var Agent = class extends BaseResource {
1268
1347
  }
1269
1348
  /**
1270
1349
  * Retrieves evaluation results for the agent
1350
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1271
1351
  * @returns Promise containing agent evaluations
1272
1352
  */
1273
- evals() {
1274
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1353
+ evals(runtimeContext) {
1354
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1275
1355
  }
1276
1356
  /**
1277
1357
  * Retrieves live evaluation results for the agent
1358
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1278
1359
  * @returns Promise containing live agent evaluations
1279
1360
  */
1280
- liveEvals() {
1281
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1361
+ liveEvals(runtimeContext) {
1362
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1282
1363
  }
1283
1364
  /**
1284
1365
  * Updates the model for the agent
@@ -1291,61 +1372,33 @@ var Agent = class extends BaseResource {
1291
1372
  body: params
1292
1373
  });
1293
1374
  }
1294
- };
1295
- var Network = class extends BaseResource {
1296
- constructor(options, networkId) {
1297
- super(options);
1298
- this.networkId = networkId;
1299
- }
1300
1375
  /**
1301
- * Retrieves details about the network
1302
- * @returns Promise containing network details
1303
- */
1304
- details() {
1305
- return this.request(`/api/networks/${this.networkId}`);
1306
- }
1307
- /**
1308
- * Generates a response from the agent
1309
- * @param params - Generation parameters including prompt
1310
- * @returns Promise containing the generated response
1376
+ * Updates the model for the agent in the model list
1377
+ * @param params - Parameters for updating the model
1378
+ * @returns Promise containing the updated model
1311
1379
  */
1312
- generate(params) {
1313
- const processedParams = {
1314
- ...params,
1315
- output: zodToJsonSchema(params.output),
1316
- experimental_output: zodToJsonSchema(params.experimental_output)
1317
- };
1318
- return this.request(`/api/networks/${this.networkId}/generate`, {
1380
+ updateModelInModelList({ modelConfigId, ...params }) {
1381
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1319
1382
  method: "POST",
1320
- body: processedParams
1383
+ body: params
1321
1384
  });
1322
1385
  }
1323
1386
  /**
1324
- * Streams a response from the agent
1325
- * @param params - Stream parameters including prompt
1326
- * @returns Promise containing the enhanced Response object with processDataStream method
1387
+ * Reorders the models for the agent
1388
+ * @param params - Parameters for reordering the model list
1389
+ * @returns Promise containing the updated model list
1327
1390
  */
1328
- async stream(params) {
1329
- const processedParams = {
1330
- ...params,
1331
- output: zodToJsonSchema(params.output),
1332
- experimental_output: zodToJsonSchema(params.experimental_output)
1333
- };
1334
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1391
+ reorderModelList(params) {
1392
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1335
1393
  method: "POST",
1336
- body: processedParams,
1337
- stream: true
1394
+ body: params
1338
1395
  });
1339
- if (!response.body) {
1340
- throw new Error("No response body");
1341
- }
1342
- response.processDataStream = async (options = {}) => {
1343
- await processDataStream({
1344
- stream: response.body,
1345
- ...options
1346
- });
1347
- };
1348
- return response;
1396
+ }
1397
+ async generateVNext(_messagesOrParams, _options) {
1398
+ throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1399
+ }
1400
+ async streamVNext(_messagesOrParams, _options) {
1401
+ throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1349
1402
  }
1350
1403
  };
1351
1404
 
@@ -1436,10 +1489,13 @@ var Vector = class extends BaseResource {
1436
1489
  /**
1437
1490
  * Retrieves details about a specific vector index
1438
1491
  * @param indexName - Name of the index to get details for
1492
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1439
1493
  * @returns Promise containing vector index details
1440
1494
  */
1441
- details(indexName) {
1442
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1495
+ details(indexName, runtimeContext) {
1496
+ return this.request(
1497
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1498
+ );
1443
1499
  }
1444
1500
  /**
1445
1501
  * Deletes a vector index
@@ -1453,10 +1509,11 @@ var Vector = class extends BaseResource {
1453
1509
  }
1454
1510
  /**
1455
1511
  * Retrieves a list of all available indexes
1512
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1456
1513
  * @returns Promise containing array of index names
1457
1514
  */
1458
- getIndexes() {
1459
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1515
+ getIndexes(runtimeContext) {
1516
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1460
1517
  }
1461
1518
  /**
1462
1519
  * Creates a new vector index
@@ -1493,123 +1550,50 @@ var Vector = class extends BaseResource {
1493
1550
  }
1494
1551
  };
1495
1552
 
1496
- // src/resources/legacy-workflow.ts
1497
- var RECORD_SEPARATOR = "";
1498
- var LegacyWorkflow = class extends BaseResource {
1499
- constructor(options, workflowId) {
1553
+ // src/resources/tool.ts
1554
+ var Tool = class extends BaseResource {
1555
+ constructor(options, toolId) {
1500
1556
  super(options);
1501
- this.workflowId = workflowId;
1502
- }
1503
- /**
1504
- * Retrieves details about the legacy workflow
1505
- * @returns Promise containing legacy workflow details including steps and graphs
1506
- */
1507
- details() {
1508
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1509
- }
1510
- /**
1511
- * Retrieves all runs for a legacy workflow
1512
- * @param params - Parameters for filtering runs
1513
- * @returns Promise containing legacy workflow runs array
1514
- */
1515
- runs(params) {
1516
- const searchParams = new URLSearchParams();
1517
- if (params?.fromDate) {
1518
- searchParams.set("fromDate", params.fromDate.toISOString());
1519
- }
1520
- if (params?.toDate) {
1521
- searchParams.set("toDate", params.toDate.toISOString());
1522
- }
1523
- if (params?.limit) {
1524
- searchParams.set("limit", String(params.limit));
1525
- }
1526
- if (params?.offset) {
1527
- searchParams.set("offset", String(params.offset));
1528
- }
1529
- if (params?.resourceId) {
1530
- searchParams.set("resourceId", params.resourceId);
1531
- }
1532
- if (searchParams.size) {
1533
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1534
- } else {
1535
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1536
- }
1537
- }
1538
- /**
1539
- * Creates a new legacy workflow run
1540
- * @returns Promise containing the generated run ID
1541
- */
1542
- createRun(params) {
1543
- const searchParams = new URLSearchParams();
1544
- if (!!params?.runId) {
1545
- searchParams.set("runId", params.runId);
1546
- }
1547
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1548
- method: "POST"
1549
- });
1550
- }
1551
- /**
1552
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1553
- * @param params - Object containing the runId and triggerData
1554
- * @returns Promise containing success message
1555
- */
1556
- start(params) {
1557
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1558
- method: "POST",
1559
- body: params?.triggerData
1560
- });
1557
+ this.toolId = toolId;
1561
1558
  }
1562
1559
  /**
1563
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1564
- * @param stepId - ID of the step to resume
1565
- * @param runId - ID of the legacy workflow run
1566
- * @param context - Context to resume the legacy workflow with
1567
- * @returns Promise containing the legacy workflow resume results
1560
+ * Retrieves details about the tool
1561
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1562
+ * @returns Promise containing tool details including description and schemas
1568
1563
  */
1569
- resume({
1570
- stepId,
1571
- runId,
1572
- context
1573
- }) {
1574
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1575
- method: "POST",
1576
- body: {
1577
- stepId,
1578
- context
1579
- }
1580
- });
1564
+ details(runtimeContext) {
1565
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1581
1566
  }
1582
1567
  /**
1583
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1584
- * @param params - Object containing the optional runId and triggerData
1585
- * @returns Promise containing the workflow execution results
1568
+ * Executes the tool with the provided parameters
1569
+ * @param params - Parameters required for tool execution
1570
+ * @returns Promise containing the tool execution results
1586
1571
  */
1587
- startAsync(params) {
1588
- const searchParams = new URLSearchParams();
1589
- if (!!params?.runId) {
1590
- searchParams.set("runId", params.runId);
1572
+ execute(params) {
1573
+ const url = new URLSearchParams();
1574
+ if (params.runId) {
1575
+ url.set("runId", params.runId);
1591
1576
  }
1592
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1577
+ const body = {
1578
+ data: params.data,
1579
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1580
+ };
1581
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1593
1582
  method: "POST",
1594
- body: params?.triggerData
1583
+ body
1595
1584
  });
1596
1585
  }
1597
- /**
1598
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1599
- * @param params - Object containing the runId, stepId, and context
1600
- * @returns Promise containing the workflow resume results
1601
- */
1602
- resumeAsync(params) {
1603
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1604
- method: "POST",
1605
- body: {
1606
- stepId: params.stepId,
1607
- context: params.context
1608
- }
1609
- });
1586
+ };
1587
+
1588
+ // src/resources/workflow.ts
1589
+ var RECORD_SEPARATOR = "";
1590
+ var Workflow = class extends BaseResource {
1591
+ constructor(options, workflowId) {
1592
+ super(options);
1593
+ this.workflowId = workflowId;
1610
1594
  }
1611
1595
  /**
1612
- * Creates an async generator that processes a readable stream and yields records
1596
+ * Creates an async generator that processes a readable stream and yields workflow records
1613
1597
  * separated by the Record Separator character (\x1E)
1614
1598
  *
1615
1599
  * @param stream - The readable stream to process
@@ -1654,162 +1638,65 @@ var LegacyWorkflow = class extends BaseResource {
1654
1638
  }
1655
1639
  }
1656
1640
  /**
1657
- * Watches legacy workflow transitions in real-time
1658
- * @param runId - Optional run ID to filter the watch stream
1659
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1641
+ * Retrieves details about the workflow
1642
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1643
+ * @returns Promise containing workflow details including steps and graphs
1660
1644
  */
1661
- async watch({ runId }, onRecord) {
1662
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1663
- stream: true
1664
- });
1665
- if (!response.ok) {
1666
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1645
+ details(runtimeContext) {
1646
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1647
+ }
1648
+ /**
1649
+ * Retrieves all runs for a workflow
1650
+ * @param params - Parameters for filtering runs
1651
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1652
+ * @returns Promise containing workflow runs array
1653
+ */
1654
+ runs(params, runtimeContext) {
1655
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1656
+ const searchParams = new URLSearchParams();
1657
+ if (params?.fromDate) {
1658
+ searchParams.set("fromDate", params.fromDate.toISOString());
1667
1659
  }
1668
- if (!response.body) {
1669
- throw new Error("Response body is null");
1660
+ if (params?.toDate) {
1661
+ searchParams.set("toDate", params.toDate.toISOString());
1670
1662
  }
1671
- for await (const record of this.streamProcessor(response.body)) {
1672
- onRecord(record);
1673
- }
1674
- }
1675
- };
1676
-
1677
- // src/resources/tool.ts
1678
- var Tool = class extends BaseResource {
1679
- constructor(options, toolId) {
1680
- super(options);
1681
- this.toolId = toolId;
1682
- }
1683
- /**
1684
- * Retrieves details about the tool
1685
- * @returns Promise containing tool details including description and schemas
1686
- */
1687
- details() {
1688
- return this.request(`/api/tools/${this.toolId}`);
1689
- }
1690
- /**
1691
- * Executes the tool with the provided parameters
1692
- * @param params - Parameters required for tool execution
1693
- * @returns Promise containing the tool execution results
1694
- */
1695
- execute(params) {
1696
- const url = new URLSearchParams();
1697
- if (params.runId) {
1698
- url.set("runId", params.runId);
1699
- }
1700
- const body = {
1701
- data: params.data,
1702
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1703
- };
1704
- return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1705
- method: "POST",
1706
- body
1707
- });
1708
- }
1709
- };
1710
-
1711
- // src/resources/workflow.ts
1712
- var RECORD_SEPARATOR2 = "";
1713
- var Workflow = class extends BaseResource {
1714
- constructor(options, workflowId) {
1715
- super(options);
1716
- this.workflowId = workflowId;
1717
- }
1718
- /**
1719
- * Creates an async generator that processes a readable stream and yields workflow records
1720
- * separated by the Record Separator character (\x1E)
1721
- *
1722
- * @param stream - The readable stream to process
1723
- * @returns An async generator that yields parsed records
1724
- */
1725
- async *streamProcessor(stream) {
1726
- const reader = stream.getReader();
1727
- let doneReading = false;
1728
- let buffer = "";
1729
- try {
1730
- while (!doneReading) {
1731
- const { done, value } = await reader.read();
1732
- doneReading = done;
1733
- if (done && !value) continue;
1734
- try {
1735
- const decoded = value ? new TextDecoder().decode(value) : "";
1736
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1737
- buffer = chunks.pop() || "";
1738
- for (const chunk of chunks) {
1739
- if (chunk) {
1740
- if (typeof chunk === "string") {
1741
- try {
1742
- const parsedChunk = JSON.parse(chunk);
1743
- yield parsedChunk;
1744
- } catch {
1745
- }
1746
- }
1747
- }
1748
- }
1749
- } catch {
1750
- }
1751
- }
1752
- if (buffer) {
1753
- try {
1754
- yield JSON.parse(buffer);
1755
- } catch {
1756
- }
1757
- }
1758
- } finally {
1759
- reader.cancel().catch(() => {
1760
- });
1761
- }
1762
- }
1763
- /**
1764
- * Retrieves details about the workflow
1765
- * @returns Promise containing workflow details including steps and graphs
1766
- */
1767
- details() {
1768
- return this.request(`/api/workflows/${this.workflowId}`);
1769
- }
1770
- /**
1771
- * Retrieves all runs for a workflow
1772
- * @param params - Parameters for filtering runs
1773
- * @returns Promise containing workflow runs array
1774
- */
1775
- runs(params) {
1776
- const searchParams = new URLSearchParams();
1777
- if (params?.fromDate) {
1778
- searchParams.set("fromDate", params.fromDate.toISOString());
1779
- }
1780
- if (params?.toDate) {
1781
- searchParams.set("toDate", params.toDate.toISOString());
1782
- }
1783
- if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1784
- searchParams.set("limit", String(params.limit));
1785
- }
1786
- if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1787
- searchParams.set("offset", String(params.offset));
1788
- }
1789
- if (params?.resourceId) {
1790
- searchParams.set("resourceId", params.resourceId);
1791
- }
1792
- if (searchParams.size) {
1793
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1794
- } else {
1795
- return this.request(`/api/workflows/${this.workflowId}/runs`);
1663
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1664
+ searchParams.set("limit", String(params.limit));
1665
+ }
1666
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1667
+ searchParams.set("offset", String(params.offset));
1668
+ }
1669
+ if (params?.resourceId) {
1670
+ searchParams.set("resourceId", params.resourceId);
1671
+ }
1672
+ if (runtimeContextParam) {
1673
+ searchParams.set("runtimeContext", runtimeContextParam);
1674
+ }
1675
+ if (searchParams.size) {
1676
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1677
+ } else {
1678
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
1796
1679
  }
1797
1680
  }
1798
1681
  /**
1799
1682
  * Retrieves a specific workflow run by its ID
1800
1683
  * @param runId - The ID of the workflow run to retrieve
1684
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1801
1685
  * @returns Promise containing the workflow run details
1802
1686
  */
1803
- runById(runId) {
1804
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1687
+ runById(runId, runtimeContext) {
1688
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1805
1689
  }
1806
1690
  /**
1807
1691
  * Retrieves the execution result for a specific workflow run by its ID
1808
1692
  * @param runId - The ID of the workflow run to retrieve the execution result for
1693
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1809
1694
  * @returns Promise containing the workflow run execution result
1810
1695
  */
1811
- runExecutionResult(runId) {
1812
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1696
+ runExecutionResult(runId, runtimeContext) {
1697
+ return this.request(
1698
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1699
+ );
1813
1700
  }
1814
1701
  /**
1815
1702
  * Cancels a specific workflow run by its ID
@@ -1832,27 +1719,83 @@ var Workflow = class extends BaseResource {
1832
1719
  body: { event: params.event, data: params.data }
1833
1720
  });
1834
1721
  }
1722
+ /**
1723
+ * @deprecated Use createRunAsync() instead.
1724
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1725
+ */
1726
+ async createRun(_params) {
1727
+ throw new Error(
1728
+ "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."
1729
+ );
1730
+ }
1835
1731
  /**
1836
1732
  * Creates a new workflow run
1837
1733
  * @param params - Optional object containing the optional runId
1838
- * @returns Promise containing the runId of the created run
1734
+ * @returns Promise containing the runId of the created run with methods to control execution
1839
1735
  */
1840
- createRun(params) {
1736
+ async createRunAsync(params) {
1841
1737
  const searchParams = new URLSearchParams();
1842
1738
  if (!!params?.runId) {
1843
1739
  searchParams.set("runId", params.runId);
1844
1740
  }
1845
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1846
- method: "POST"
1847
- });
1848
- }
1849
- /**
1850
- * Creates a new workflow run (alias for createRun)
1851
- * @param params - Optional object containing the optional runId
1852
- * @returns Promise containing the runId of the created run
1853
- */
1854
- createRunAsync(params) {
1855
- return this.createRun(params);
1741
+ const res = await this.request(
1742
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1743
+ {
1744
+ method: "POST"
1745
+ }
1746
+ );
1747
+ const runId = res.runId;
1748
+ return {
1749
+ runId,
1750
+ start: async (p) => {
1751
+ return this.start({
1752
+ runId,
1753
+ inputData: p.inputData,
1754
+ runtimeContext: p.runtimeContext,
1755
+ tracingOptions: p.tracingOptions
1756
+ });
1757
+ },
1758
+ startAsync: async (p) => {
1759
+ return this.startAsync({
1760
+ runId,
1761
+ inputData: p.inputData,
1762
+ runtimeContext: p.runtimeContext,
1763
+ tracingOptions: p.tracingOptions
1764
+ });
1765
+ },
1766
+ watch: async (onRecord) => {
1767
+ return this.watch({ runId }, onRecord);
1768
+ },
1769
+ stream: async (p) => {
1770
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1771
+ },
1772
+ resume: async (p) => {
1773
+ return this.resume({
1774
+ runId,
1775
+ step: p.step,
1776
+ resumeData: p.resumeData,
1777
+ runtimeContext: p.runtimeContext,
1778
+ tracingOptions: p.tracingOptions
1779
+ });
1780
+ },
1781
+ resumeAsync: async (p) => {
1782
+ return this.resumeAsync({
1783
+ runId,
1784
+ step: p.step,
1785
+ resumeData: p.resumeData,
1786
+ runtimeContext: p.runtimeContext,
1787
+ tracingOptions: p.tracingOptions
1788
+ });
1789
+ },
1790
+ resumeStreamVNext: async (p) => {
1791
+ return this.resumeStreamVNext({
1792
+ runId,
1793
+ step: p.step,
1794
+ resumeData: p.resumeData,
1795
+ runtimeContext: p.runtimeContext
1796
+ });
1797
+ }
1798
+ };
1856
1799
  }
1857
1800
  /**
1858
1801
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1863,7 +1806,7 @@ var Workflow = class extends BaseResource {
1863
1806
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1864
1807
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1865
1808
  method: "POST",
1866
- body: { inputData: params?.inputData, runtimeContext }
1809
+ body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1867
1810
  });
1868
1811
  }
1869
1812
  /**
@@ -1875,16 +1818,17 @@ var Workflow = class extends BaseResource {
1875
1818
  step,
1876
1819
  runId,
1877
1820
  resumeData,
1821
+ tracingOptions,
1878
1822
  ...rest
1879
1823
  }) {
1880
1824
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1881
1825
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1882
1826
  method: "POST",
1883
- stream: true,
1884
1827
  body: {
1885
1828
  step,
1886
1829
  resumeData,
1887
- runtimeContext
1830
+ runtimeContext,
1831
+ tracingOptions
1888
1832
  }
1889
1833
  });
1890
1834
  }
@@ -1901,7 +1845,7 @@ var Workflow = class extends BaseResource {
1901
1845
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1902
1846
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1903
1847
  method: "POST",
1904
- body: { inputData: params.inputData, runtimeContext }
1848
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1905
1849
  });
1906
1850
  }
1907
1851
  /**
@@ -1919,12 +1863,12 @@ var Workflow = class extends BaseResource {
1919
1863
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1920
1864
  {
1921
1865
  method: "POST",
1922
- body: { inputData: params.inputData, runtimeContext },
1866
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1923
1867
  stream: true
1924
1868
  }
1925
1869
  );
1926
1870
  if (!response.ok) {
1927
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1871
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1928
1872
  }
1929
1873
  if (!response.body) {
1930
1874
  throw new Error("Response body is null");
@@ -1936,7 +1880,54 @@ var Workflow = class extends BaseResource {
1936
1880
  async transform(chunk, controller) {
1937
1881
  try {
1938
1882
  const decoded = new TextDecoder().decode(chunk);
1939
- const chunks = decoded.split(RECORD_SEPARATOR2);
1883
+ const chunks = decoded.split(RECORD_SEPARATOR);
1884
+ for (const chunk2 of chunks) {
1885
+ if (chunk2) {
1886
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1887
+ try {
1888
+ const parsedChunk = JSON.parse(newChunk);
1889
+ controller.enqueue(parsedChunk);
1890
+ failedChunk = void 0;
1891
+ } catch {
1892
+ failedChunk = newChunk;
1893
+ }
1894
+ }
1895
+ }
1896
+ } catch {
1897
+ }
1898
+ }
1899
+ });
1900
+ return response.body.pipeThrough(transformStream);
1901
+ }
1902
+ /**
1903
+ * Observes workflow stream for a workflow run
1904
+ * @param params - Object containing the runId
1905
+ * @returns Promise containing the workflow execution results
1906
+ */
1907
+ async observeStream(params) {
1908
+ const searchParams = new URLSearchParams();
1909
+ searchParams.set("runId", params.runId);
1910
+ const response = await this.request(
1911
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1912
+ {
1913
+ method: "POST",
1914
+ stream: true
1915
+ }
1916
+ );
1917
+ if (!response.ok) {
1918
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1919
+ }
1920
+ if (!response.body) {
1921
+ throw new Error("Response body is null");
1922
+ }
1923
+ let failedChunk = void 0;
1924
+ const transformStream = new TransformStream({
1925
+ start() {
1926
+ },
1927
+ async transform(chunk, controller) {
1928
+ try {
1929
+ const decoded = new TextDecoder().decode(chunk);
1930
+ const chunks = decoded.split(RECORD_SEPARATOR);
1940
1931
  for (const chunk2 of chunks) {
1941
1932
  if (chunk2) {
1942
1933
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1970,7 +1961,12 @@ var Workflow = class extends BaseResource {
1970
1961
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1971
1962
  {
1972
1963
  method: "POST",
1973
- body: { inputData: params.inputData, runtimeContext },
1964
+ body: {
1965
+ inputData: params.inputData,
1966
+ runtimeContext,
1967
+ closeOnSuspend: params.closeOnSuspend,
1968
+ tracingOptions: params.tracingOptions
1969
+ },
1974
1970
  stream: true
1975
1971
  }
1976
1972
  );
@@ -1987,7 +1983,54 @@ var Workflow = class extends BaseResource {
1987
1983
  async transform(chunk, controller) {
1988
1984
  try {
1989
1985
  const decoded = new TextDecoder().decode(chunk);
1990
- const chunks = decoded.split(RECORD_SEPARATOR2);
1986
+ const chunks = decoded.split(RECORD_SEPARATOR);
1987
+ for (const chunk2 of chunks) {
1988
+ if (chunk2) {
1989
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1990
+ try {
1991
+ const parsedChunk = JSON.parse(newChunk);
1992
+ controller.enqueue(parsedChunk);
1993
+ failedChunk = void 0;
1994
+ } catch {
1995
+ failedChunk = newChunk;
1996
+ }
1997
+ }
1998
+ }
1999
+ } catch {
2000
+ }
2001
+ }
2002
+ });
2003
+ return response.body.pipeThrough(transformStream);
2004
+ }
2005
+ /**
2006
+ * Observes workflow vNext stream for a workflow run
2007
+ * @param params - Object containing the runId
2008
+ * @returns Promise containing the workflow execution results
2009
+ */
2010
+ async observeStreamVNext(params) {
2011
+ const searchParams = new URLSearchParams();
2012
+ searchParams.set("runId", params.runId);
2013
+ const response = await this.request(
2014
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
2015
+ {
2016
+ method: "POST",
2017
+ stream: true
2018
+ }
2019
+ );
2020
+ if (!response.ok) {
2021
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
2022
+ }
2023
+ if (!response.body) {
2024
+ throw new Error("Response body is null");
2025
+ }
2026
+ let failedChunk = void 0;
2027
+ const transformStream = new TransformStream({
2028
+ start() {
2029
+ },
2030
+ async transform(chunk, controller) {
2031
+ try {
2032
+ const decoded = new TextDecoder().decode(chunk);
2033
+ const chunks = decoded.split(RECORD_SEPARATOR);
1991
2034
  for (const chunk2 of chunks) {
1992
2035
  if (chunk2) {
1993
2036
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2018,10 +2061,65 @@ var Workflow = class extends BaseResource {
2018
2061
  body: {
2019
2062
  step: params.step,
2020
2063
  resumeData: params.resumeData,
2021
- runtimeContext
2064
+ runtimeContext,
2065
+ tracingOptions: params.tracingOptions
2022
2066
  }
2023
2067
  });
2024
2068
  }
2069
+ /**
2070
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2071
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2072
+ * @returns Promise containing the workflow resume results
2073
+ */
2074
+ async resumeStreamVNext(params) {
2075
+ const searchParams = new URLSearchParams();
2076
+ searchParams.set("runId", params.runId);
2077
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2078
+ const response = await this.request(
2079
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2080
+ {
2081
+ method: "POST",
2082
+ body: {
2083
+ step: params.step,
2084
+ resumeData: params.resumeData,
2085
+ runtimeContext,
2086
+ tracingOptions: params.tracingOptions
2087
+ },
2088
+ stream: true
2089
+ }
2090
+ );
2091
+ if (!response.ok) {
2092
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2093
+ }
2094
+ if (!response.body) {
2095
+ throw new Error("Response body is null");
2096
+ }
2097
+ let failedChunk = void 0;
2098
+ const transformStream = new TransformStream({
2099
+ start() {
2100
+ },
2101
+ async transform(chunk, controller) {
2102
+ try {
2103
+ const decoded = new TextDecoder().decode(chunk);
2104
+ const chunks = decoded.split(RECORD_SEPARATOR);
2105
+ for (const chunk2 of chunks) {
2106
+ if (chunk2) {
2107
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2108
+ try {
2109
+ const parsedChunk = JSON.parse(newChunk);
2110
+ controller.enqueue(parsedChunk);
2111
+ failedChunk = void 0;
2112
+ } catch {
2113
+ failedChunk = newChunk;
2114
+ }
2115
+ }
2116
+ }
2117
+ } catch {
2118
+ }
2119
+ }
2120
+ });
2121
+ return response.body.pipeThrough(transformStream);
2122
+ }
2025
2123
  /**
2026
2124
  * Watches workflow transitions in real-time
2027
2125
  * @param runId - Optional run ID to filter the watch stream
@@ -2058,7 +2156,7 @@ var Workflow = class extends BaseResource {
2058
2156
  async start(controller) {
2059
2157
  try {
2060
2158
  for await (const record of records) {
2061
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2159
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2062
2160
  controller.enqueue(encoder.encode(json));
2063
2161
  }
2064
2162
  controller.close();
@@ -2156,10 +2254,11 @@ var MCPTool = class extends BaseResource {
2156
2254
  }
2157
2255
  /**
2158
2256
  * Retrieves details about this specific tool from the MCP server.
2257
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2159
2258
  * @returns Promise containing the tool's information (name, description, schema).
2160
2259
  */
2161
- details() {
2162
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2260
+ details(runtimeContext) {
2261
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2163
2262
  }
2164
2263
  /**
2165
2264
  * Executes this specific tool on the MCP server.
@@ -2180,7 +2279,7 @@ var MCPTool = class extends BaseResource {
2180
2279
  };
2181
2280
 
2182
2281
  // src/resources/agent-builder.ts
2183
- var RECORD_SEPARATOR3 = "";
2282
+ var RECORD_SEPARATOR2 = "";
2184
2283
  var AgentBuilder = class extends BaseResource {
2185
2284
  constructor(options, actionId) {
2186
2285
  super(options);
@@ -2215,11 +2314,20 @@ var AgentBuilder = class extends BaseResource {
2215
2314
  };
2216
2315
  }
2217
2316
  }
2317
+ /**
2318
+ * @deprecated Use createRunAsync() instead.
2319
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2320
+ */
2321
+ async createRun(_params) {
2322
+ throw new Error(
2323
+ "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."
2324
+ );
2325
+ }
2218
2326
  /**
2219
2327
  * Creates a new agent builder action run and returns the runId.
2220
2328
  * This calls `/api/agent-builder/:actionId/create-run`.
2221
2329
  */
2222
- async createRun(params) {
2330
+ async createRunAsync(params) {
2223
2331
  const searchParams = new URLSearchParams();
2224
2332
  if (!!params?.runId) {
2225
2333
  searchParams.set("runId", params.runId);
@@ -2229,14 +2337,6 @@ var AgentBuilder = class extends BaseResource {
2229
2337
  method: "POST"
2230
2338
  });
2231
2339
  }
2232
- /**
2233
- * Creates a new workflow run (alias for createRun)
2234
- * @param params - Optional object containing the optional runId
2235
- * @returns Promise containing the runId of the created run
2236
- */
2237
- createRunAsync(params) {
2238
- return this.createRun(params);
2239
- }
2240
2340
  /**
2241
2341
  * Starts agent builder action asynchronously and waits for completion.
2242
2342
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2319,7 +2419,7 @@ var AgentBuilder = class extends BaseResource {
2319
2419
  if (done && !value) continue;
2320
2420
  try {
2321
2421
  const decoded = value ? new TextDecoder().decode(value) : "";
2322
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2422
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2323
2423
  buffer = chunks.pop() || "";
2324
2424
  for (const chunk of chunks) {
2325
2425
  if (chunk) {
@@ -2376,7 +2476,7 @@ var AgentBuilder = class extends BaseResource {
2376
2476
  async transform(chunk, controller) {
2377
2477
  try {
2378
2478
  const decoded = new TextDecoder().decode(chunk);
2379
- const chunks = decoded.split(RECORD_SEPARATOR3);
2479
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2380
2480
  for (const chunk2 of chunks) {
2381
2481
  if (chunk2) {
2382
2482
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2425,7 +2525,7 @@ var AgentBuilder = class extends BaseResource {
2425
2525
  async transform(chunk, controller) {
2426
2526
  try {
2427
2527
  const decoded = new TextDecoder().decode(chunk);
2428
- const chunks = decoded.split(RECORD_SEPARATOR3);
2528
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2429
2529
  for (const chunk2 of chunks) {
2430
2530
  if (chunk2) {
2431
2531
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2596,6 +2696,31 @@ var Observability = class extends BaseResource {
2596
2696
  const queryString = searchParams.toString();
2597
2697
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2598
2698
  }
2699
+ /**
2700
+ * Retrieves scores by trace ID and span ID
2701
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2702
+ * @returns Promise containing scores and pagination info
2703
+ */
2704
+ getScoresBySpan(params) {
2705
+ const { traceId, spanId, page, perPage } = params;
2706
+ const searchParams = new URLSearchParams();
2707
+ if (page !== void 0) {
2708
+ searchParams.set("page", String(page));
2709
+ }
2710
+ if (perPage !== void 0) {
2711
+ searchParams.set("perPage", String(perPage));
2712
+ }
2713
+ const queryString = searchParams.toString();
2714
+ return this.request(
2715
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2716
+ );
2717
+ }
2718
+ score(params) {
2719
+ return this.request(`/api/observability/traces/score`, {
2720
+ method: "POST",
2721
+ body: { ...params }
2722
+ });
2723
+ }
2599
2724
  };
2600
2725
 
2601
2726
  // src/resources/network-memory-thread.ts
@@ -2661,144 +2786,6 @@ var NetworkMemoryThread = class extends BaseResource {
2661
2786
  }
2662
2787
  };
2663
2788
 
2664
- // src/resources/vNextNetwork.ts
2665
- var RECORD_SEPARATOR4 = "";
2666
- var VNextNetwork = class extends BaseResource {
2667
- constructor(options, networkId) {
2668
- super(options);
2669
- this.networkId = networkId;
2670
- }
2671
- /**
2672
- * Retrieves details about the network
2673
- * @returns Promise containing vNext network details
2674
- */
2675
- details() {
2676
- return this.request(`/api/networks/v-next/${this.networkId}`);
2677
- }
2678
- /**
2679
- * Generates a response from the v-next network
2680
- * @param params - Generation parameters including message
2681
- * @returns Promise containing the generated response
2682
- */
2683
- generate(params) {
2684
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2685
- method: "POST",
2686
- body: {
2687
- ...params,
2688
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2689
- }
2690
- });
2691
- }
2692
- /**
2693
- * Generates a response from the v-next network using multiple primitives
2694
- * @param params - Generation parameters including message
2695
- * @returns Promise containing the generated response
2696
- */
2697
- loop(params) {
2698
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2699
- method: "POST",
2700
- body: {
2701
- ...params,
2702
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2703
- }
2704
- });
2705
- }
2706
- async *streamProcessor(stream) {
2707
- const reader = stream.getReader();
2708
- let doneReading = false;
2709
- let buffer = "";
2710
- try {
2711
- while (!doneReading) {
2712
- const { done, value } = await reader.read();
2713
- doneReading = done;
2714
- if (done && !value) continue;
2715
- try {
2716
- const decoded = value ? new TextDecoder().decode(value) : "";
2717
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2718
- buffer = chunks.pop() || "";
2719
- for (const chunk of chunks) {
2720
- if (chunk) {
2721
- if (typeof chunk === "string") {
2722
- try {
2723
- const parsedChunk = JSON.parse(chunk);
2724
- yield parsedChunk;
2725
- } catch {
2726
- }
2727
- }
2728
- }
2729
- }
2730
- } catch {
2731
- }
2732
- }
2733
- if (buffer) {
2734
- try {
2735
- yield JSON.parse(buffer);
2736
- } catch {
2737
- }
2738
- }
2739
- } finally {
2740
- reader.cancel().catch(() => {
2741
- });
2742
- }
2743
- }
2744
- /**
2745
- * Streams a response from the v-next network
2746
- * @param params - Stream parameters including message
2747
- * @returns Promise containing the results
2748
- */
2749
- async stream(params, onRecord) {
2750
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2751
- method: "POST",
2752
- body: {
2753
- ...params,
2754
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2755
- },
2756
- stream: true
2757
- });
2758
- if (!response.ok) {
2759
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2760
- }
2761
- if (!response.body) {
2762
- throw new Error("Response body is null");
2763
- }
2764
- for await (const record of this.streamProcessor(response.body)) {
2765
- if (typeof record === "string") {
2766
- onRecord(JSON.parse(record));
2767
- } else {
2768
- onRecord(record);
2769
- }
2770
- }
2771
- }
2772
- /**
2773
- * Streams a response from the v-next network loop
2774
- * @param params - Stream parameters including message
2775
- * @returns Promise containing the results
2776
- */
2777
- async loopStream(params, onRecord) {
2778
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2779
- method: "POST",
2780
- body: {
2781
- ...params,
2782
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2783
- },
2784
- stream: true
2785
- });
2786
- if (!response.ok) {
2787
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2788
- }
2789
- if (!response.body) {
2790
- throw new Error("Response body is null");
2791
- }
2792
- for await (const record of this.streamProcessor(response.body)) {
2793
- if (typeof record === "string") {
2794
- onRecord(JSON.parse(record));
2795
- } else {
2796
- onRecord(record);
2797
- }
2798
- }
2799
- }
2800
- };
2801
-
2802
2789
  // src/client.ts
2803
2790
  var MastraClient = class extends BaseResource {
2804
2791
  observability;
@@ -2808,10 +2795,20 @@ var MastraClient = class extends BaseResource {
2808
2795
  }
2809
2796
  /**
2810
2797
  * Retrieves all available agents
2798
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2811
2799
  * @returns Promise containing map of agent IDs to agent details
2812
2800
  */
2813
- getAgents() {
2814
- return this.request("/api/agents");
2801
+ getAgents(runtimeContext) {
2802
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2803
+ const searchParams = new URLSearchParams();
2804
+ if (runtimeContextParam) {
2805
+ searchParams.set("runtimeContext", runtimeContextParam);
2806
+ }
2807
+ const queryString = searchParams.toString();
2808
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2809
+ }
2810
+ getAgentsModelProviders() {
2811
+ return this.request(`/api/agents/providers`);
2815
2812
  }
2816
2813
  /**
2817
2814
  * Gets an agent instance by ID
@@ -2829,6 +2826,14 @@ var MastraClient = class extends BaseResource {
2829
2826
  getMemoryThreads(params) {
2830
2827
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2831
2828
  }
2829
+ /**
2830
+ * Retrieves memory config for a resource
2831
+ * @param params - Parameters containing the resource ID
2832
+ * @returns Promise containing array of memory threads
2833
+ */
2834
+ getMemoryConfig(params) {
2835
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2836
+ }
2832
2837
  /**
2833
2838
  * Creates a new memory thread
2834
2839
  * @param params - Parameters for creating the memory thread
@@ -2845,6 +2850,24 @@ var MastraClient = class extends BaseResource {
2845
2850
  getMemoryThread(threadId, agentId) {
2846
2851
  return new MemoryThread(this.options, threadId, agentId);
2847
2852
  }
2853
+ getThreadMessages(threadId, opts = {}) {
2854
+ let url = "";
2855
+ if (opts.agentId) {
2856
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2857
+ } else if (opts.networkId) {
2858
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2859
+ }
2860
+ return this.request(url);
2861
+ }
2862
+ deleteThread(threadId, opts = {}) {
2863
+ let url = "";
2864
+ if (opts.agentId) {
2865
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2866
+ } else if (opts.networkId) {
2867
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2868
+ }
2869
+ return this.request(url, { method: "DELETE" });
2870
+ }
2848
2871
  /**
2849
2872
  * Saves messages to memory
2850
2873
  * @param params - Parameters containing messages to save
@@ -2907,10 +2930,17 @@ var MastraClient = class extends BaseResource {
2907
2930
  }
2908
2931
  /**
2909
2932
  * Retrieves all available tools
2933
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2910
2934
  * @returns Promise containing map of tool IDs to tool details
2911
2935
  */
2912
- getTools() {
2913
- return this.request("/api/tools");
2936
+ getTools(runtimeContext) {
2937
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2938
+ const searchParams = new URLSearchParams();
2939
+ if (runtimeContextParam) {
2940
+ searchParams.set("runtimeContext", runtimeContextParam);
2941
+ }
2942
+ const queryString = searchParams.toString();
2943
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2914
2944
  }
2915
2945
  /**
2916
2946
  * Gets a tool instance by ID
@@ -2920,27 +2950,19 @@ var MastraClient = class extends BaseResource {
2920
2950
  getTool(toolId) {
2921
2951
  return new Tool(this.options, toolId);
2922
2952
  }
2923
- /**
2924
- * Retrieves all available legacy workflows
2925
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2926
- */
2927
- getLegacyWorkflows() {
2928
- return this.request("/api/workflows/legacy");
2929
- }
2930
- /**
2931
- * Gets a legacy workflow instance by ID
2932
- * @param workflowId - ID of the legacy workflow to retrieve
2933
- * @returns Legacy Workflow instance
2934
- */
2935
- getLegacyWorkflow(workflowId) {
2936
- return new LegacyWorkflow(this.options, workflowId);
2937
- }
2938
2953
  /**
2939
2954
  * Retrieves all available workflows
2955
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2940
2956
  * @returns Promise containing map of workflow IDs to workflow details
2941
2957
  */
2942
- getWorkflows() {
2943
- return this.request("/api/workflows");
2958
+ getWorkflows(runtimeContext) {
2959
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2960
+ const searchParams = new URLSearchParams();
2961
+ if (runtimeContextParam) {
2962
+ searchParams.set("runtimeContext", runtimeContextParam);
2963
+ }
2964
+ const queryString = searchParams.toString();
2965
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2944
2966
  }
2945
2967
  /**
2946
2968
  * Gets a workflow instance by ID
@@ -3066,78 +3088,6 @@ var MastraClient = class extends BaseResource {
3066
3088
  getLogTransports() {
3067
3089
  return this.request("/api/logs/transports");
3068
3090
  }
3069
- /**
3070
- * List of all traces (paged)
3071
- * @param params - Parameters for filtering traces
3072
- * @returns Promise containing telemetry data
3073
- */
3074
- getTelemetry(params) {
3075
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3076
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3077
- const searchParams = new URLSearchParams();
3078
- if (name) {
3079
- searchParams.set("name", name);
3080
- }
3081
- if (scope) {
3082
- searchParams.set("scope", scope);
3083
- }
3084
- if (page) {
3085
- searchParams.set("page", String(page));
3086
- }
3087
- if (perPage) {
3088
- searchParams.set("perPage", String(perPage));
3089
- }
3090
- if (_attribute) {
3091
- if (Array.isArray(_attribute)) {
3092
- for (const attr of _attribute) {
3093
- searchParams.append("attribute", attr);
3094
- }
3095
- } else {
3096
- searchParams.set("attribute", _attribute);
3097
- }
3098
- }
3099
- if (fromDate) {
3100
- searchParams.set("fromDate", fromDate.toISOString());
3101
- }
3102
- if (toDate) {
3103
- searchParams.set("toDate", toDate.toISOString());
3104
- }
3105
- if (searchParams.size) {
3106
- return this.request(`/api/telemetry?${searchParams}`);
3107
- } else {
3108
- return this.request(`/api/telemetry`);
3109
- }
3110
- }
3111
- /**
3112
- * Retrieves all available networks
3113
- * @returns Promise containing map of network IDs to network details
3114
- */
3115
- getNetworks() {
3116
- return this.request("/api/networks");
3117
- }
3118
- /**
3119
- * Retrieves all available vNext networks
3120
- * @returns Promise containing map of vNext network IDs to vNext network details
3121
- */
3122
- getVNextNetworks() {
3123
- return this.request("/api/networks/v-next");
3124
- }
3125
- /**
3126
- * Gets a network instance by ID
3127
- * @param networkId - ID of the network to retrieve
3128
- * @returns Network instance
3129
- */
3130
- getNetwork(networkId) {
3131
- return new Network(this.options, networkId);
3132
- }
3133
- /**
3134
- * Gets a vNext network instance by ID
3135
- * @param networkId - ID of the vNext network to retrieve
3136
- * @returns vNext Network instance
3137
- */
3138
- getVNextNetwork(networkId) {
3139
- return new VNextNetwork(this.options, networkId);
3140
- }
3141
3091
  /**
3142
3092
  * Retrieves a list of available MCP servers.
3143
3093
  * @param params - Optional parameters for pagination (limit, offset).
@@ -3208,6 +3158,26 @@ var MastraClient = class extends BaseResource {
3208
3158
  }) {
3209
3159
  return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3210
3160
  }
3161
+ searchMemory({
3162
+ agentId,
3163
+ resourceId,
3164
+ threadId,
3165
+ searchQuery,
3166
+ memoryConfig
3167
+ }) {
3168
+ const params = new URLSearchParams({
3169
+ searchQuery,
3170
+ resourceId,
3171
+ agentId
3172
+ });
3173
+ if (threadId) {
3174
+ params.append("threadId", threadId);
3175
+ }
3176
+ if (memoryConfig) {
3177
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3178
+ }
3179
+ return this.request(`/api/memory/search?${params}`);
3180
+ }
3211
3181
  /**
3212
3182
  * Updates the working memory for a specific thread (optionally resource-scoped).
3213
3183
  * @param agentId - ID of the agent.
@@ -3242,7 +3212,7 @@ var MastraClient = class extends BaseResource {
3242
3212
  * @returns Promise containing the scorer
3243
3213
  */
3244
3214
  getScorer(scorerId) {
3245
- return this.request(`/api/scores/scorers/${scorerId}`);
3215
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3246
3216
  }
3247
3217
  getScoresByScorerId(params) {
3248
3218
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3260,7 +3230,7 @@ var MastraClient = class extends BaseResource {
3260
3230
  searchParams.set("perPage", String(perPage));
3261
3231
  }
3262
3232
  const queryString = searchParams.toString();
3263
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3233
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3264
3234
  }
3265
3235
  /**
3266
3236
  * Retrieves scores by run ID
@@ -3277,7 +3247,7 @@ var MastraClient = class extends BaseResource {
3277
3247
  searchParams.set("perPage", String(perPage));
3278
3248
  }
3279
3249
  const queryString = searchParams.toString();
3280
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3250
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3281
3251
  }
3282
3252
  /**
3283
3253
  * Retrieves scores by entity ID and type
@@ -3294,7 +3264,9 @@ var MastraClient = class extends BaseResource {
3294
3264
  searchParams.set("perPage", String(perPage));
3295
3265
  }
3296
3266
  const queryString = searchParams.toString();
3297
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3267
+ return this.request(
3268
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3269
+ );
3298
3270
  }
3299
3271
  /**
3300
3272
  * Saves a score
@@ -3320,8 +3292,33 @@ var MastraClient = class extends BaseResource {
3320
3292
  getAITraces(params) {
3321
3293
  return this.observability.getTraces(params);
3322
3294
  }
3295
+ getScoresBySpan(params) {
3296
+ return this.observability.getScoresBySpan(params);
3297
+ }
3298
+ score(params) {
3299
+ return this.observability.score(params);
3300
+ }
3323
3301
  };
3324
3302
 
3325
- export { MastraClient };
3303
+ // src/tools.ts
3304
+ var ClientTool = class {
3305
+ id;
3306
+ description;
3307
+ inputSchema;
3308
+ outputSchema;
3309
+ execute;
3310
+ constructor(opts) {
3311
+ this.id = opts.id;
3312
+ this.description = opts.description;
3313
+ this.inputSchema = opts.inputSchema;
3314
+ this.outputSchema = opts.outputSchema;
3315
+ this.execute = opts.execute;
3316
+ }
3317
+ };
3318
+ function createTool(opts) {
3319
+ return new ClientTool(opts);
3320
+ }
3321
+
3322
+ export { ClientTool, MastraClient, createTool };
3326
3323
  //# sourceMappingURL=index.js.map
3327
3324
  //# sourceMappingURL=index.js.map