@mastra/client-js 0.0.0-add-libsql-changeset-20250910154739 → 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 (41) hide show
  1. package/CHANGELOG.md +529 -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 +660 -619
  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 +659 -620
  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 +92 -43
  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 +105 -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 +5 -1
  34. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  35. package/package.json +6 -6
  36. package/dist/resources/legacy-workflow.d.ts +0 -87
  37. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  38. package/dist/resources/network.d.ts +0 -30
  39. package/dist/resources/network.d.ts.map +0 -1
  40. package/dist/resources/vNextNetwork.d.ts +0 -42
  41. package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var uiUtils = require('@ai-sdk/ui-utils');
4
4
  var uuid = require('@lukeed/uuid');
5
+ var error = require('@mastra/core/error');
5
6
  var runtimeContext = require('@mastra/core/runtime-context');
6
7
  var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
7
8
  var zod = require('zod');
@@ -21,6 +22,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
21
22
  }
22
23
  return void 0;
23
24
  }
25
+ function base64RuntimeContext(runtimeContext) {
26
+ if (runtimeContext) {
27
+ return btoa(JSON.stringify(runtimeContext));
28
+ }
29
+ return void 0;
30
+ }
31
+ function runtimeContextQueryString(runtimeContext) {
32
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
33
+ if (!runtimeContextParam) return "";
34
+ const searchParams = new URLSearchParams();
35
+ searchParams.set("runtimeContext", runtimeContextParam);
36
+ const queryString = searchParams.toString();
37
+ return queryString ? `?${queryString}` : "";
38
+ }
24
39
  function isZodType(value) {
25
40
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
26
41
  }
@@ -32,7 +47,7 @@ function zodToJsonSchema(zodSchema) {
32
47
  const fn = "toJSONSchema";
33
48
  return zod.z[fn].call(zod.z, zodSchema);
34
49
  }
35
- return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
50
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
36
51
  }
37
52
 
38
53
  // src/utils/process-client-tools.ts
@@ -65,7 +80,7 @@ function processClientTools(clientTools) {
65
80
  }
66
81
 
67
82
  // src/utils/process-mastra-stream.ts
68
- async function processMastraStream({
83
+ async function sharedProcessMastraStream({
69
84
  stream,
70
85
  onChunk
71
86
  }) {
@@ -83,14 +98,18 @@ async function processMastraStream({
83
98
  if (line.startsWith("data: ")) {
84
99
  const data = line.slice(6);
85
100
  if (data === "[DONE]") {
86
- console.log("\u{1F3C1} Stream finished");
101
+ console.info("\u{1F3C1} Stream finished");
87
102
  return;
88
103
  }
104
+ let json;
89
105
  try {
90
- const json = JSON.parse(data);
91
- await onChunk(json);
106
+ json = JSON.parse(data);
92
107
  } catch (error) {
93
108
  console.error("\u274C JSON parse error:", error, "Data:", data);
109
+ continue;
110
+ }
111
+ if (json) {
112
+ await onChunk(json);
94
113
  }
95
114
  }
96
115
  }
@@ -99,6 +118,24 @@ async function processMastraStream({
99
118
  reader.releaseLock();
100
119
  }
101
120
  }
121
+ async function processMastraNetworkStream({
122
+ stream,
123
+ onChunk
124
+ }) {
125
+ return sharedProcessMastraStream({
126
+ stream,
127
+ onChunk
128
+ });
129
+ }
130
+ async function processMastraStream({
131
+ stream,
132
+ onChunk
133
+ }) {
134
+ return sharedProcessMastraStream({
135
+ stream,
136
+ onChunk
137
+ });
138
+ }
102
139
 
103
140
  // src/resources/base.ts
104
141
  var BaseResource = class {
@@ -187,7 +224,9 @@ async function executeToolCallAndRespond({
187
224
  resourceId,
188
225
  threadId,
189
226
  runtimeContext,
190
- tracingContext: { currentSpan: void 0 }
227
+ tracingContext: { currentSpan: void 0 },
228
+ suspend: async () => {
229
+ }
191
230
  },
192
231
  {
193
232
  messages: response.messages,
@@ -195,11 +234,7 @@ async function executeToolCallAndRespond({
195
234
  }
196
235
  );
197
236
  const updatedMessages = [
198
- {
199
- role: "user",
200
- content: params.messages
201
- },
202
- ...response.response.messages,
237
+ ...response.response.messages || [],
203
238
  {
204
239
  role: "tool",
205
240
  content: [
@@ -261,17 +296,21 @@ var AgentVoice = class extends BaseResource {
261
296
  }
262
297
  /**
263
298
  * Get available speakers for the agent's voice provider
299
+ * @param runtimeContext - Optional runtime context to pass as query parameter
300
+ * @param runtimeContext - Optional runtime context to pass as query parameter
264
301
  * @returns Promise containing list of available speakers
265
302
  */
266
- getSpeakers() {
267
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
303
+ getSpeakers(runtimeContext) {
304
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
268
305
  }
269
306
  /**
270
307
  * Get the listener configuration for the agent's voice provider
308
+ * @param runtimeContext - Optional runtime context to pass as query parameter
309
+ * @param runtimeContext - Optional runtime context to pass as query parameter
271
310
  * @returns Promise containing a check if the agent has listening capabilities
272
311
  */
273
- getListener() {
274
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
312
+ getListener(runtimeContext) {
313
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
275
314
  }
276
315
  };
277
316
  var Agent = class extends BaseResource {
@@ -283,16 +322,17 @@ var Agent = class extends BaseResource {
283
322
  voice;
284
323
  /**
285
324
  * Retrieves details about the agent
325
+ * @param runtimeContext - Optional runtime context to pass as query parameter
286
326
  * @returns Promise containing agent details including model and instructions
287
327
  */
288
- details() {
289
- return this.request(`/api/agents/${this.agentId}`);
328
+ details(runtimeContext) {
329
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
290
330
  }
291
- async generate(params) {
292
- console.warn(
293
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
294
- );
295
- return this.generateLegacy(params);
331
+ enhanceInstructions(instructions, comment) {
332
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
333
+ method: "POST",
334
+ body: { instructions, comment }
335
+ });
296
336
  }
297
337
  async generateLegacy(params) {
298
338
  const processedParams = {
@@ -325,7 +365,9 @@ var Agent = class extends BaseResource {
325
365
  resourceId,
326
366
  threadId,
327
367
  runtimeContext,
328
- tracingContext: { currentSpan: void 0 }
368
+ tracingContext: { currentSpan: void 0 },
369
+ suspend: async () => {
370
+ }
329
371
  },
330
372
  {
331
373
  messages: response.messages,
@@ -333,10 +375,6 @@ var Agent = class extends BaseResource {
333
375
  }
334
376
  );
335
377
  const updatedMessages = [
336
- {
337
- role: "user",
338
- content: params.messages
339
- },
340
378
  ...response.response.messages,
341
379
  {
342
380
  role: "tool",
@@ -359,10 +397,18 @@ var Agent = class extends BaseResource {
359
397
  }
360
398
  return response;
361
399
  }
362
- async generateVNext(params) {
400
+ async generate(messagesOrParams, options) {
401
+ let params;
402
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
403
+ params = messagesOrParams;
404
+ } else {
405
+ params = {
406
+ messages: messagesOrParams,
407
+ ...options
408
+ };
409
+ }
363
410
  const processedParams = {
364
411
  ...params,
365
- output: params.output ? zodToJsonSchema(params.output) : void 0,
366
412
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
367
413
  clientTools: processClientTools(params.clientTools),
368
414
  structuredOutput: params.structuredOutput ? {
@@ -372,7 +418,7 @@ var Agent = class extends BaseResource {
372
418
  };
373
419
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
374
420
  const response = await this.request(
375
- `/api/agents/${this.agentId}/generate/vnext`,
421
+ `/api/agents/${this.agentId}/generate`,
376
422
  {
377
423
  method: "POST",
378
424
  body: processedParams
@@ -386,7 +432,7 @@ var Agent = class extends BaseResource {
386
432
  resourceId,
387
433
  threadId,
388
434
  runtimeContext,
389
- respondFn: this.generateVNext.bind(this)
435
+ respondFn: this.generate.bind(this)
390
436
  });
391
437
  }
392
438
  return response;
@@ -653,17 +699,6 @@ var Agent = class extends BaseResource {
653
699
  });
654
700
  onFinish?.({ message, finishReason, usage });
655
701
  }
656
- /**
657
- * Streams a response from the agent
658
- * @param params - Stream parameters including prompt
659
- * @returns Promise containing the enhanced Response object with processDataStream method
660
- */
661
- async stream(params) {
662
- console.warn(
663
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
664
- );
665
- return this.streamLegacy(params);
666
- }
667
702
  /**
668
703
  * Streams a response from the agent
669
704
  * @param params - Stream parameters including prompt
@@ -678,7 +713,7 @@ var Agent = class extends BaseResource {
678
713
  clientTools: processClientTools(params.clientTools)
679
714
  };
680
715
  const { readable, writable } = new TransformStream();
681
- const response = await this.processStreamResponse(processedParams, writable);
716
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
682
717
  const streamResponse = new Response(readable, {
683
718
  status: response.status,
684
719
  statusText: response.statusText,
@@ -765,6 +800,14 @@ var Agent = class extends BaseResource {
765
800
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
766
801
  onChunk: async (chunk) => {
767
802
  switch (chunk.type) {
803
+ case "tripwire": {
804
+ message.parts.push({
805
+ type: "text",
806
+ text: chunk.payload.tripwireReason
807
+ });
808
+ execUpdate();
809
+ break;
810
+ }
768
811
  case "step-start": {
769
812
  if (!replaceLastMessage) {
770
813
  message.id = chunk.payload.messageId;
@@ -918,7 +961,10 @@ var Agent = class extends BaseResource {
918
961
  break;
919
962
  }
920
963
  case "error": {
921
- throw new Error(chunk.payload.error);
964
+ throw error.getErrorFromUnknown(chunk.payload.error, {
965
+ fallbackMessage: "Unknown error in stream",
966
+ supportSerialization: false
967
+ });
922
968
  }
923
969
  case "data": {
924
970
  data.push(...chunk.payload.data);
@@ -945,8 +991,8 @@ var Agent = class extends BaseResource {
945
991
  });
946
992
  onFinish?.({ message, finishReason, usage });
947
993
  }
948
- async processStreamResponse_vNext(processedParams, writable) {
949
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
994
+ async processStreamResponse(processedParams, writable, route = "stream") {
995
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
950
996
  method: "POST",
951
997
  body: processedParams,
952
998
  stream: true
@@ -961,18 +1007,17 @@ var Agent = class extends BaseResource {
961
1007
  streamForWritable.pipeTo(
962
1008
  new WritableStream({
963
1009
  async write(chunk) {
1010
+ let writer;
964
1011
  try {
1012
+ writer = writable.getWriter();
965
1013
  const text = new TextDecoder().decode(chunk);
966
- if (text.includes("[DONE]")) {
967
- return;
968
- }
1014
+ const lines = text.split("\n\n");
1015
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1016
+ await writer.write(new TextEncoder().encode(readableLines));
969
1017
  } catch {
970
- }
971
- const writer = writable.getWriter();
972
- try {
973
- await writer.write(chunk);
1018
+ await writer?.write(chunk);
974
1019
  } finally {
975
- writer.releaseLock();
1020
+ writer?.releaseLock();
976
1021
  }
977
1022
  }
978
1023
  }),
@@ -998,9 +1043,11 @@ var Agent = class extends BaseResource {
998
1043
  if (toolCall) {
999
1044
  toolCalls.push(toolCall);
1000
1045
  }
1046
+ let shouldExecuteClientTool = false;
1001
1047
  for (const toolCall2 of toolCalls) {
1002
1048
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1003
1049
  if (clientTool && clientTool.execute) {
1050
+ shouldExecuteClientTool = true;
1004
1051
  const result = await clientTool.execute(
1005
1052
  {
1006
1053
  context: toolCall2?.args,
@@ -1009,7 +1056,9 @@ var Agent = class extends BaseResource {
1009
1056
  threadId: processedParams.threadId,
1010
1057
  runtimeContext: processedParams.runtimeContext,
1011
1058
  // TODO: Pass proper tracing context when client-js supports tracing
1012
- tracingContext: { currentSpan: void 0 }
1059
+ tracingContext: { currentSpan: void 0 },
1060
+ suspend: async () => {
1061
+ }
1013
1062
  },
1014
1063
  {
1015
1064
  messages: response.messages,
@@ -1035,10 +1084,8 @@ var Agent = class extends BaseResource {
1035
1084
  toolInvocation.state = "result";
1036
1085
  toolInvocation.result = result;
1037
1086
  }
1038
- const originalMessages = processedParams.messages;
1039
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1040
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1041
- this.processStreamResponse_vNext(
1087
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1088
+ this.processStreamResponse(
1042
1089
  {
1043
1090
  ...processedParams,
1044
1091
  messages: updatedMessages
@@ -1049,6 +1096,11 @@ var Agent = class extends BaseResource {
1049
1096
  });
1050
1097
  }
1051
1098
  }
1099
+ if (!shouldExecuteClientTool) {
1100
+ setTimeout(() => {
1101
+ writable.close();
1102
+ }, 0);
1103
+ }
1052
1104
  } else {
1053
1105
  setTimeout(() => {
1054
1106
  writable.close();
@@ -1064,10 +1116,42 @@ var Agent = class extends BaseResource {
1064
1116
  }
1065
1117
  return response;
1066
1118
  }
1067
- async streamVNext(params) {
1119
+ async network(params) {
1120
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1121
+ method: "POST",
1122
+ body: params,
1123
+ stream: true
1124
+ });
1125
+ if (!response.body) {
1126
+ throw new Error("No response body");
1127
+ }
1128
+ const streamResponse = new Response(response.body, {
1129
+ status: response.status,
1130
+ statusText: response.statusText,
1131
+ headers: response.headers
1132
+ });
1133
+ streamResponse.processDataStream = async ({
1134
+ onChunk
1135
+ }) => {
1136
+ await processMastraNetworkStream({
1137
+ stream: streamResponse.body,
1138
+ onChunk
1139
+ });
1140
+ };
1141
+ return streamResponse;
1142
+ }
1143
+ async stream(messagesOrParams, options) {
1144
+ let params;
1145
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1146
+ params = messagesOrParams;
1147
+ } else {
1148
+ params = {
1149
+ messages: messagesOrParams,
1150
+ ...options
1151
+ };
1152
+ }
1068
1153
  const processedParams = {
1069
1154
  ...params,
1070
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1071
1155
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1072
1156
  clientTools: processClientTools(params.clientTools),
1073
1157
  structuredOutput: params.structuredOutput ? {
@@ -1076,7 +1160,43 @@ var Agent = class extends BaseResource {
1076
1160
  } : void 0
1077
1161
  };
1078
1162
  const { readable, writable } = new TransformStream();
1079
- const response = await this.processStreamResponse_vNext(processedParams, writable);
1163
+ const response = await this.processStreamResponse(processedParams, writable);
1164
+ const streamResponse = new Response(readable, {
1165
+ status: response.status,
1166
+ statusText: response.statusText,
1167
+ headers: response.headers
1168
+ });
1169
+ streamResponse.processDataStream = async ({
1170
+ onChunk
1171
+ }) => {
1172
+ await processMastraStream({
1173
+ stream: streamResponse.body,
1174
+ onChunk
1175
+ });
1176
+ };
1177
+ return streamResponse;
1178
+ }
1179
+ async approveToolCall(params) {
1180
+ const { readable, writable } = new TransformStream();
1181
+ const response = await this.processStreamResponse(params, writable, "approve-tool-call");
1182
+ const streamResponse = new Response(readable, {
1183
+ status: response.status,
1184
+ statusText: response.statusText,
1185
+ headers: response.headers
1186
+ });
1187
+ streamResponse.processDataStream = async ({
1188
+ onChunk
1189
+ }) => {
1190
+ await processMastraStream({
1191
+ stream: streamResponse.body,
1192
+ onChunk
1193
+ });
1194
+ };
1195
+ return streamResponse;
1196
+ }
1197
+ async declineToolCall(params) {
1198
+ const { readable, writable } = new TransformStream();
1199
+ const response = await this.processStreamResponse(params, writable, "decline-tool-call");
1080
1200
  const streamResponse = new Response(readable, {
1081
1201
  status: response.status,
1082
1202
  statusText: response.statusText,
@@ -1095,7 +1215,7 @@ var Agent = class extends BaseResource {
1095
1215
  /**
1096
1216
  * Processes the stream response and handles tool calls
1097
1217
  */
1098
- async processStreamResponse(processedParams, writable) {
1218
+ async processStreamResponseLegacy(processedParams, writable) {
1099
1219
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1100
1220
  method: "POST",
1101
1221
  body: processedParams,
@@ -1140,7 +1260,9 @@ var Agent = class extends BaseResource {
1140
1260
  threadId: processedParams.threadId,
1141
1261
  runtimeContext: processedParams.runtimeContext,
1142
1262
  // TODO: Pass proper tracing context when client-js supports tracing
1143
- tracingContext: { currentSpan: void 0 }
1263
+ tracingContext: { currentSpan: void 0 },
1264
+ suspend: async () => {
1265
+ }
1144
1266
  },
1145
1267
  {
1146
1268
  messages: response.messages,
@@ -1178,12 +1300,10 @@ var Agent = class extends BaseResource {
1178
1300
  } finally {
1179
1301
  writer.releaseLock();
1180
1302
  }
1181
- const originalMessages = processedParams.messages;
1182
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1183
- this.processStreamResponse(
1303
+ this.processStreamResponseLegacy(
1184
1304
  {
1185
1305
  ...processedParams,
1186
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1306
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1187
1307
  },
1188
1308
  writable
1189
1309
  ).catch((error) => {
@@ -1209,10 +1329,11 @@ var Agent = class extends BaseResource {
1209
1329
  /**
1210
1330
  * Gets details about a specific tool available to the agent
1211
1331
  * @param toolId - ID of the tool to retrieve
1332
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1212
1333
  * @returns Promise containing tool details
1213
1334
  */
1214
- getTool(toolId) {
1215
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1335
+ getTool(toolId, runtimeContext) {
1336
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1216
1337
  }
1217
1338
  /**
1218
1339
  * Executes a tool for the agent
@@ -1223,7 +1344,7 @@ var Agent = class extends BaseResource {
1223
1344
  executeTool(toolId, params) {
1224
1345
  const body = {
1225
1346
  data: params.data,
1226
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1347
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1227
1348
  };
1228
1349
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1229
1350
  method: "POST",
@@ -1232,17 +1353,19 @@ var Agent = class extends BaseResource {
1232
1353
  }
1233
1354
  /**
1234
1355
  * Retrieves evaluation results for the agent
1356
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1235
1357
  * @returns Promise containing agent evaluations
1236
1358
  */
1237
- evals() {
1238
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1359
+ evals(runtimeContext) {
1360
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1239
1361
  }
1240
1362
  /**
1241
1363
  * Retrieves live evaluation results for the agent
1364
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1242
1365
  * @returns Promise containing live agent evaluations
1243
1366
  */
1244
- liveEvals() {
1245
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1367
+ liveEvals(runtimeContext) {
1368
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1246
1369
  }
1247
1370
  /**
1248
1371
  * Updates the model for the agent
@@ -1255,61 +1378,33 @@ var Agent = class extends BaseResource {
1255
1378
  body: params
1256
1379
  });
1257
1380
  }
1258
- };
1259
- var Network = class extends BaseResource {
1260
- constructor(options, networkId) {
1261
- super(options);
1262
- this.networkId = networkId;
1263
- }
1264
- /**
1265
- * Retrieves details about the network
1266
- * @returns Promise containing network details
1267
- */
1268
- details() {
1269
- return this.request(`/api/networks/${this.networkId}`);
1270
- }
1271
1381
  /**
1272
- * Generates a response from the agent
1273
- * @param params - Generation parameters including prompt
1274
- * @returns Promise containing the generated response
1382
+ * Updates the model for the agent in the model list
1383
+ * @param params - Parameters for updating the model
1384
+ * @returns Promise containing the updated model
1275
1385
  */
1276
- generate(params) {
1277
- const processedParams = {
1278
- ...params,
1279
- output: zodToJsonSchema(params.output),
1280
- experimental_output: zodToJsonSchema(params.experimental_output)
1281
- };
1282
- return this.request(`/api/networks/${this.networkId}/generate`, {
1386
+ updateModelInModelList({ modelConfigId, ...params }) {
1387
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1283
1388
  method: "POST",
1284
- body: processedParams
1389
+ body: params
1285
1390
  });
1286
1391
  }
1287
1392
  /**
1288
- * Streams a response from the agent
1289
- * @param params - Stream parameters including prompt
1290
- * @returns Promise containing the enhanced Response object with processDataStream method
1393
+ * Reorders the models for the agent
1394
+ * @param params - Parameters for reordering the model list
1395
+ * @returns Promise containing the updated model list
1291
1396
  */
1292
- async stream(params) {
1293
- const processedParams = {
1294
- ...params,
1295
- output: zodToJsonSchema(params.output),
1296
- experimental_output: zodToJsonSchema(params.experimental_output)
1297
- };
1298
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1397
+ reorderModelList(params) {
1398
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1299
1399
  method: "POST",
1300
- body: processedParams,
1301
- stream: true
1400
+ body: params
1302
1401
  });
1303
- if (!response.body) {
1304
- throw new Error("No response body");
1305
- }
1306
- response.processDataStream = async (options = {}) => {
1307
- await uiUtils.processDataStream({
1308
- stream: response.body,
1309
- ...options
1310
- });
1311
- };
1312
- return response;
1402
+ }
1403
+ async generateVNext(_messagesOrParams, _options) {
1404
+ throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1405
+ }
1406
+ async streamVNext(_messagesOrParams, _options) {
1407
+ throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1313
1408
  }
1314
1409
  };
1315
1410
 
@@ -1400,10 +1495,13 @@ var Vector = class extends BaseResource {
1400
1495
  /**
1401
1496
  * Retrieves details about a specific vector index
1402
1497
  * @param indexName - Name of the index to get details for
1498
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1403
1499
  * @returns Promise containing vector index details
1404
1500
  */
1405
- details(indexName) {
1406
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1501
+ details(indexName, runtimeContext) {
1502
+ return this.request(
1503
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1504
+ );
1407
1505
  }
1408
1506
  /**
1409
1507
  * Deletes a vector index
@@ -1417,10 +1515,11 @@ var Vector = class extends BaseResource {
1417
1515
  }
1418
1516
  /**
1419
1517
  * Retrieves a list of all available indexes
1518
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1420
1519
  * @returns Promise containing array of index names
1421
1520
  */
1422
- getIndexes() {
1423
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1521
+ getIndexes(runtimeContext) {
1522
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1424
1523
  }
1425
1524
  /**
1426
1525
  * Creates a new vector index
@@ -1457,123 +1556,50 @@ var Vector = class extends BaseResource {
1457
1556
  }
1458
1557
  };
1459
1558
 
1460
- // src/resources/legacy-workflow.ts
1461
- var RECORD_SEPARATOR = "";
1462
- var LegacyWorkflow = class extends BaseResource {
1463
- constructor(options, workflowId) {
1559
+ // src/resources/tool.ts
1560
+ var Tool = class extends BaseResource {
1561
+ constructor(options, toolId) {
1464
1562
  super(options);
1465
- this.workflowId = workflowId;
1466
- }
1467
- /**
1468
- * Retrieves details about the legacy workflow
1469
- * @returns Promise containing legacy workflow details including steps and graphs
1470
- */
1471
- details() {
1472
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1473
- }
1474
- /**
1475
- * Retrieves all runs for a legacy workflow
1476
- * @param params - Parameters for filtering runs
1477
- * @returns Promise containing legacy workflow runs array
1478
- */
1479
- runs(params) {
1480
- const searchParams = new URLSearchParams();
1481
- if (params?.fromDate) {
1482
- searchParams.set("fromDate", params.fromDate.toISOString());
1483
- }
1484
- if (params?.toDate) {
1485
- searchParams.set("toDate", params.toDate.toISOString());
1486
- }
1487
- if (params?.limit) {
1488
- searchParams.set("limit", String(params.limit));
1489
- }
1490
- if (params?.offset) {
1491
- searchParams.set("offset", String(params.offset));
1492
- }
1493
- if (params?.resourceId) {
1494
- searchParams.set("resourceId", params.resourceId);
1495
- }
1496
- if (searchParams.size) {
1497
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1498
- } else {
1499
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1500
- }
1501
- }
1502
- /**
1503
- * Creates a new legacy workflow run
1504
- * @returns Promise containing the generated run ID
1505
- */
1506
- createRun(params) {
1507
- const searchParams = new URLSearchParams();
1508
- if (!!params?.runId) {
1509
- searchParams.set("runId", params.runId);
1510
- }
1511
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1512
- method: "POST"
1513
- });
1514
- }
1515
- /**
1516
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1517
- * @param params - Object containing the runId and triggerData
1518
- * @returns Promise containing success message
1519
- */
1520
- start(params) {
1521
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1522
- method: "POST",
1523
- body: params?.triggerData
1524
- });
1563
+ this.toolId = toolId;
1525
1564
  }
1526
1565
  /**
1527
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1528
- * @param stepId - ID of the step to resume
1529
- * @param runId - ID of the legacy workflow run
1530
- * @param context - Context to resume the legacy workflow with
1531
- * @returns Promise containing the legacy workflow resume results
1566
+ * Retrieves details about the tool
1567
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1568
+ * @returns Promise containing tool details including description and schemas
1532
1569
  */
1533
- resume({
1534
- stepId,
1535
- runId,
1536
- context
1537
- }) {
1538
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1539
- method: "POST",
1540
- body: {
1541
- stepId,
1542
- context
1543
- }
1544
- });
1570
+ details(runtimeContext) {
1571
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1545
1572
  }
1546
1573
  /**
1547
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1548
- * @param params - Object containing the optional runId and triggerData
1549
- * @returns Promise containing the workflow execution results
1574
+ * Executes the tool with the provided parameters
1575
+ * @param params - Parameters required for tool execution
1576
+ * @returns Promise containing the tool execution results
1550
1577
  */
1551
- startAsync(params) {
1552
- const searchParams = new URLSearchParams();
1553
- if (!!params?.runId) {
1554
- searchParams.set("runId", params.runId);
1578
+ execute(params) {
1579
+ const url = new URLSearchParams();
1580
+ if (params.runId) {
1581
+ url.set("runId", params.runId);
1555
1582
  }
1556
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1583
+ const body = {
1584
+ data: params.data,
1585
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1586
+ };
1587
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1557
1588
  method: "POST",
1558
- body: params?.triggerData
1589
+ body
1559
1590
  });
1560
1591
  }
1561
- /**
1562
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1563
- * @param params - Object containing the runId, stepId, and context
1564
- * @returns Promise containing the workflow resume results
1565
- */
1566
- resumeAsync(params) {
1567
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1568
- method: "POST",
1569
- body: {
1570
- stepId: params.stepId,
1571
- context: params.context
1572
- }
1573
- });
1592
+ };
1593
+
1594
+ // src/resources/workflow.ts
1595
+ var RECORD_SEPARATOR = "";
1596
+ var Workflow = class extends BaseResource {
1597
+ constructor(options, workflowId) {
1598
+ super(options);
1599
+ this.workflowId = workflowId;
1574
1600
  }
1575
1601
  /**
1576
- * Creates an async generator that processes a readable stream and yields records
1602
+ * Creates an async generator that processes a readable stream and yields workflow records
1577
1603
  * separated by the Record Separator character (\x1E)
1578
1604
  *
1579
1605
  * @param stream - The readable stream to process
@@ -1618,125 +1644,21 @@ var LegacyWorkflow = class extends BaseResource {
1618
1644
  }
1619
1645
  }
1620
1646
  /**
1621
- * Watches legacy workflow transitions in real-time
1622
- * @param runId - Optional run ID to filter the watch stream
1623
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1647
+ * Retrieves details about the workflow
1648
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1649
+ * @returns Promise containing workflow details including steps and graphs
1624
1650
  */
1625
- async watch({ runId }, onRecord) {
1626
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1627
- stream: true
1628
- });
1629
- if (!response.ok) {
1630
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1631
- }
1632
- if (!response.body) {
1633
- throw new Error("Response body is null");
1634
- }
1635
- for await (const record of this.streamProcessor(response.body)) {
1636
- onRecord(record);
1637
- }
1638
- }
1639
- };
1640
-
1641
- // src/resources/tool.ts
1642
- var Tool = class extends BaseResource {
1643
- constructor(options, toolId) {
1644
- super(options);
1645
- this.toolId = toolId;
1646
- }
1647
- /**
1648
- * Retrieves details about the tool
1649
- * @returns Promise containing tool details including description and schemas
1650
- */
1651
- details() {
1652
- return this.request(`/api/tools/${this.toolId}`);
1653
- }
1654
- /**
1655
- * Executes the tool with the provided parameters
1656
- * @param params - Parameters required for tool execution
1657
- * @returns Promise containing the tool execution results
1658
- */
1659
- execute(params) {
1660
- const url = new URLSearchParams();
1661
- if (params.runId) {
1662
- url.set("runId", params.runId);
1663
- }
1664
- const body = {
1665
- data: params.data,
1666
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1667
- };
1668
- return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1669
- method: "POST",
1670
- body
1671
- });
1672
- }
1673
- };
1674
-
1675
- // src/resources/workflow.ts
1676
- var RECORD_SEPARATOR2 = "";
1677
- var Workflow = class extends BaseResource {
1678
- constructor(options, workflowId) {
1679
- super(options);
1680
- this.workflowId = workflowId;
1681
- }
1682
- /**
1683
- * Creates an async generator that processes a readable stream and yields workflow records
1684
- * separated by the Record Separator character (\x1E)
1685
- *
1686
- * @param stream - The readable stream to process
1687
- * @returns An async generator that yields parsed records
1688
- */
1689
- async *streamProcessor(stream) {
1690
- const reader = stream.getReader();
1691
- let doneReading = false;
1692
- let buffer = "";
1693
- try {
1694
- while (!doneReading) {
1695
- const { done, value } = await reader.read();
1696
- doneReading = done;
1697
- if (done && !value) continue;
1698
- try {
1699
- const decoded = value ? new TextDecoder().decode(value) : "";
1700
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1701
- buffer = chunks.pop() || "";
1702
- for (const chunk of chunks) {
1703
- if (chunk) {
1704
- if (typeof chunk === "string") {
1705
- try {
1706
- const parsedChunk = JSON.parse(chunk);
1707
- yield parsedChunk;
1708
- } catch {
1709
- }
1710
- }
1711
- }
1712
- }
1713
- } catch {
1714
- }
1715
- }
1716
- if (buffer) {
1717
- try {
1718
- yield JSON.parse(buffer);
1719
- } catch {
1720
- }
1721
- }
1722
- } finally {
1723
- reader.cancel().catch(() => {
1724
- });
1725
- }
1726
- }
1727
- /**
1728
- * Retrieves details about the workflow
1729
- * @returns Promise containing workflow details including steps and graphs
1730
- */
1731
- details() {
1732
- return this.request(`/api/workflows/${this.workflowId}`);
1651
+ details(runtimeContext) {
1652
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1733
1653
  }
1734
1654
  /**
1735
1655
  * Retrieves all runs for a workflow
1736
1656
  * @param params - Parameters for filtering runs
1657
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1737
1658
  * @returns Promise containing workflow runs array
1738
1659
  */
1739
- runs(params) {
1660
+ runs(params, runtimeContext) {
1661
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1740
1662
  const searchParams = new URLSearchParams();
1741
1663
  if (params?.fromDate) {
1742
1664
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1753,6 +1675,9 @@ var Workflow = class extends BaseResource {
1753
1675
  if (params?.resourceId) {
1754
1676
  searchParams.set("resourceId", params.resourceId);
1755
1677
  }
1678
+ if (runtimeContextParam) {
1679
+ searchParams.set("runtimeContext", runtimeContextParam);
1680
+ }
1756
1681
  if (searchParams.size) {
1757
1682
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1758
1683
  } else {
@@ -1762,18 +1687,22 @@ var Workflow = class extends BaseResource {
1762
1687
  /**
1763
1688
  * Retrieves a specific workflow run by its ID
1764
1689
  * @param runId - The ID of the workflow run to retrieve
1690
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1765
1691
  * @returns Promise containing the workflow run details
1766
1692
  */
1767
- runById(runId) {
1768
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1693
+ runById(runId, runtimeContext) {
1694
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1769
1695
  }
1770
1696
  /**
1771
1697
  * Retrieves the execution result for a specific workflow run by its ID
1772
1698
  * @param runId - The ID of the workflow run to retrieve the execution result for
1699
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1773
1700
  * @returns Promise containing the workflow run execution result
1774
1701
  */
1775
- runExecutionResult(runId) {
1776
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1702
+ runExecutionResult(runId, runtimeContext) {
1703
+ return this.request(
1704
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1705
+ );
1777
1706
  }
1778
1707
  /**
1779
1708
  * Cancels a specific workflow run by its ID
@@ -1796,27 +1725,83 @@ var Workflow = class extends BaseResource {
1796
1725
  body: { event: params.event, data: params.data }
1797
1726
  });
1798
1727
  }
1728
+ /**
1729
+ * @deprecated Use createRunAsync() instead.
1730
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1731
+ */
1732
+ async createRun(_params) {
1733
+ throw new Error(
1734
+ "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."
1735
+ );
1736
+ }
1799
1737
  /**
1800
1738
  * Creates a new workflow run
1801
1739
  * @param params - Optional object containing the optional runId
1802
- * @returns Promise containing the runId of the created run
1740
+ * @returns Promise containing the runId of the created run with methods to control execution
1803
1741
  */
1804
- createRun(params) {
1742
+ async createRunAsync(params) {
1805
1743
  const searchParams = new URLSearchParams();
1806
1744
  if (!!params?.runId) {
1807
1745
  searchParams.set("runId", params.runId);
1808
1746
  }
1809
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1810
- method: "POST"
1811
- });
1812
- }
1813
- /**
1814
- * Creates a new workflow run (alias for createRun)
1815
- * @param params - Optional object containing the optional runId
1816
- * @returns Promise containing the runId of the created run
1817
- */
1818
- createRunAsync(params) {
1819
- return this.createRun(params);
1747
+ const res = await this.request(
1748
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1749
+ {
1750
+ method: "POST"
1751
+ }
1752
+ );
1753
+ const runId = res.runId;
1754
+ return {
1755
+ runId,
1756
+ start: async (p) => {
1757
+ return this.start({
1758
+ runId,
1759
+ inputData: p.inputData,
1760
+ runtimeContext: p.runtimeContext,
1761
+ tracingOptions: p.tracingOptions
1762
+ });
1763
+ },
1764
+ startAsync: async (p) => {
1765
+ return this.startAsync({
1766
+ runId,
1767
+ inputData: p.inputData,
1768
+ runtimeContext: p.runtimeContext,
1769
+ tracingOptions: p.tracingOptions
1770
+ });
1771
+ },
1772
+ watch: async (onRecord) => {
1773
+ return this.watch({ runId }, onRecord);
1774
+ },
1775
+ stream: async (p) => {
1776
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1777
+ },
1778
+ resume: async (p) => {
1779
+ return this.resume({
1780
+ runId,
1781
+ step: p.step,
1782
+ resumeData: p.resumeData,
1783
+ runtimeContext: p.runtimeContext,
1784
+ tracingOptions: p.tracingOptions
1785
+ });
1786
+ },
1787
+ resumeAsync: async (p) => {
1788
+ return this.resumeAsync({
1789
+ runId,
1790
+ step: p.step,
1791
+ resumeData: p.resumeData,
1792
+ runtimeContext: p.runtimeContext,
1793
+ tracingOptions: p.tracingOptions
1794
+ });
1795
+ },
1796
+ resumeStreamVNext: async (p) => {
1797
+ return this.resumeStreamVNext({
1798
+ runId,
1799
+ step: p.step,
1800
+ resumeData: p.resumeData,
1801
+ runtimeContext: p.runtimeContext
1802
+ });
1803
+ }
1804
+ };
1820
1805
  }
1821
1806
  /**
1822
1807
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1827,7 +1812,7 @@ var Workflow = class extends BaseResource {
1827
1812
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1828
1813
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1829
1814
  method: "POST",
1830
- body: { inputData: params?.inputData, runtimeContext }
1815
+ body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1831
1816
  });
1832
1817
  }
1833
1818
  /**
@@ -1839,16 +1824,17 @@ var Workflow = class extends BaseResource {
1839
1824
  step,
1840
1825
  runId,
1841
1826
  resumeData,
1827
+ tracingOptions,
1842
1828
  ...rest
1843
1829
  }) {
1844
1830
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1845
1831
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1846
1832
  method: "POST",
1847
- stream: true,
1848
1833
  body: {
1849
1834
  step,
1850
1835
  resumeData,
1851
- runtimeContext
1836
+ runtimeContext,
1837
+ tracingOptions
1852
1838
  }
1853
1839
  });
1854
1840
  }
@@ -1865,7 +1851,7 @@ var Workflow = class extends BaseResource {
1865
1851
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1866
1852
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1867
1853
  method: "POST",
1868
- body: { inputData: params.inputData, runtimeContext }
1854
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1869
1855
  });
1870
1856
  }
1871
1857
  /**
@@ -1883,12 +1869,12 @@ var Workflow = class extends BaseResource {
1883
1869
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1884
1870
  {
1885
1871
  method: "POST",
1886
- body: { inputData: params.inputData, runtimeContext },
1872
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1887
1873
  stream: true
1888
1874
  }
1889
1875
  );
1890
1876
  if (!response.ok) {
1891
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1877
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1892
1878
  }
1893
1879
  if (!response.body) {
1894
1880
  throw new Error("Response body is null");
@@ -1900,7 +1886,54 @@ var Workflow = class extends BaseResource {
1900
1886
  async transform(chunk, controller) {
1901
1887
  try {
1902
1888
  const decoded = new TextDecoder().decode(chunk);
1903
- const chunks = decoded.split(RECORD_SEPARATOR2);
1889
+ const chunks = decoded.split(RECORD_SEPARATOR);
1890
+ for (const chunk2 of chunks) {
1891
+ if (chunk2) {
1892
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1893
+ try {
1894
+ const parsedChunk = JSON.parse(newChunk);
1895
+ controller.enqueue(parsedChunk);
1896
+ failedChunk = void 0;
1897
+ } catch {
1898
+ failedChunk = newChunk;
1899
+ }
1900
+ }
1901
+ }
1902
+ } catch {
1903
+ }
1904
+ }
1905
+ });
1906
+ return response.body.pipeThrough(transformStream);
1907
+ }
1908
+ /**
1909
+ * Observes workflow stream for a workflow run
1910
+ * @param params - Object containing the runId
1911
+ * @returns Promise containing the workflow execution results
1912
+ */
1913
+ async observeStream(params) {
1914
+ const searchParams = new URLSearchParams();
1915
+ searchParams.set("runId", params.runId);
1916
+ const response = await this.request(
1917
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1918
+ {
1919
+ method: "POST",
1920
+ stream: true
1921
+ }
1922
+ );
1923
+ if (!response.ok) {
1924
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1925
+ }
1926
+ if (!response.body) {
1927
+ throw new Error("Response body is null");
1928
+ }
1929
+ let failedChunk = void 0;
1930
+ const transformStream = new TransformStream({
1931
+ start() {
1932
+ },
1933
+ async transform(chunk, controller) {
1934
+ try {
1935
+ const decoded = new TextDecoder().decode(chunk);
1936
+ const chunks = decoded.split(RECORD_SEPARATOR);
1904
1937
  for (const chunk2 of chunks) {
1905
1938
  if (chunk2) {
1906
1939
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1934,7 +1967,12 @@ var Workflow = class extends BaseResource {
1934
1967
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1935
1968
  {
1936
1969
  method: "POST",
1937
- body: { inputData: params.inputData, runtimeContext },
1970
+ body: {
1971
+ inputData: params.inputData,
1972
+ runtimeContext,
1973
+ closeOnSuspend: params.closeOnSuspend,
1974
+ tracingOptions: params.tracingOptions
1975
+ },
1938
1976
  stream: true
1939
1977
  }
1940
1978
  );
@@ -1951,7 +1989,54 @@ var Workflow = class extends BaseResource {
1951
1989
  async transform(chunk, controller) {
1952
1990
  try {
1953
1991
  const decoded = new TextDecoder().decode(chunk);
1954
- const chunks = decoded.split(RECORD_SEPARATOR2);
1992
+ const chunks = decoded.split(RECORD_SEPARATOR);
1993
+ for (const chunk2 of chunks) {
1994
+ if (chunk2) {
1995
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1996
+ try {
1997
+ const parsedChunk = JSON.parse(newChunk);
1998
+ controller.enqueue(parsedChunk);
1999
+ failedChunk = void 0;
2000
+ } catch {
2001
+ failedChunk = newChunk;
2002
+ }
2003
+ }
2004
+ }
2005
+ } catch {
2006
+ }
2007
+ }
2008
+ });
2009
+ return response.body.pipeThrough(transformStream);
2010
+ }
2011
+ /**
2012
+ * Observes workflow vNext stream for a workflow run
2013
+ * @param params - Object containing the runId
2014
+ * @returns Promise containing the workflow execution results
2015
+ */
2016
+ async observeStreamVNext(params) {
2017
+ const searchParams = new URLSearchParams();
2018
+ searchParams.set("runId", params.runId);
2019
+ const response = await this.request(
2020
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
2021
+ {
2022
+ method: "POST",
2023
+ stream: true
2024
+ }
2025
+ );
2026
+ if (!response.ok) {
2027
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
2028
+ }
2029
+ if (!response.body) {
2030
+ throw new Error("Response body is null");
2031
+ }
2032
+ let failedChunk = void 0;
2033
+ const transformStream = new TransformStream({
2034
+ start() {
2035
+ },
2036
+ async transform(chunk, controller) {
2037
+ try {
2038
+ const decoded = new TextDecoder().decode(chunk);
2039
+ const chunks = decoded.split(RECORD_SEPARATOR);
1955
2040
  for (const chunk2 of chunks) {
1956
2041
  if (chunk2) {
1957
2042
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1982,10 +2067,65 @@ var Workflow = class extends BaseResource {
1982
2067
  body: {
1983
2068
  step: params.step,
1984
2069
  resumeData: params.resumeData,
1985
- runtimeContext
2070
+ runtimeContext,
2071
+ tracingOptions: params.tracingOptions
1986
2072
  }
1987
2073
  });
1988
2074
  }
2075
+ /**
2076
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2077
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2078
+ * @returns Promise containing the workflow resume results
2079
+ */
2080
+ async resumeStreamVNext(params) {
2081
+ const searchParams = new URLSearchParams();
2082
+ searchParams.set("runId", params.runId);
2083
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2084
+ const response = await this.request(
2085
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2086
+ {
2087
+ method: "POST",
2088
+ body: {
2089
+ step: params.step,
2090
+ resumeData: params.resumeData,
2091
+ runtimeContext,
2092
+ tracingOptions: params.tracingOptions
2093
+ },
2094
+ stream: true
2095
+ }
2096
+ );
2097
+ if (!response.ok) {
2098
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2099
+ }
2100
+ if (!response.body) {
2101
+ throw new Error("Response body is null");
2102
+ }
2103
+ let failedChunk = void 0;
2104
+ const transformStream = new TransformStream({
2105
+ start() {
2106
+ },
2107
+ async transform(chunk, controller) {
2108
+ try {
2109
+ const decoded = new TextDecoder().decode(chunk);
2110
+ const chunks = decoded.split(RECORD_SEPARATOR);
2111
+ for (const chunk2 of chunks) {
2112
+ if (chunk2) {
2113
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2114
+ try {
2115
+ const parsedChunk = JSON.parse(newChunk);
2116
+ controller.enqueue(parsedChunk);
2117
+ failedChunk = void 0;
2118
+ } catch {
2119
+ failedChunk = newChunk;
2120
+ }
2121
+ }
2122
+ }
2123
+ } catch {
2124
+ }
2125
+ }
2126
+ });
2127
+ return response.body.pipeThrough(transformStream);
2128
+ }
1989
2129
  /**
1990
2130
  * Watches workflow transitions in real-time
1991
2131
  * @param runId - Optional run ID to filter the watch stream
@@ -2022,7 +2162,7 @@ var Workflow = class extends BaseResource {
2022
2162
  async start(controller) {
2023
2163
  try {
2024
2164
  for await (const record of records) {
2025
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2165
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2026
2166
  controller.enqueue(encoder.encode(json));
2027
2167
  }
2028
2168
  controller.close();
@@ -2120,10 +2260,11 @@ var MCPTool = class extends BaseResource {
2120
2260
  }
2121
2261
  /**
2122
2262
  * Retrieves details about this specific tool from the MCP server.
2263
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2123
2264
  * @returns Promise containing the tool's information (name, description, schema).
2124
2265
  */
2125
- details() {
2126
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2266
+ details(runtimeContext) {
2267
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2127
2268
  }
2128
2269
  /**
2129
2270
  * Executes this specific tool on the MCP server.
@@ -2144,7 +2285,7 @@ var MCPTool = class extends BaseResource {
2144
2285
  };
2145
2286
 
2146
2287
  // src/resources/agent-builder.ts
2147
- var RECORD_SEPARATOR3 = "";
2288
+ var RECORD_SEPARATOR2 = "";
2148
2289
  var AgentBuilder = class extends BaseResource {
2149
2290
  constructor(options, actionId) {
2150
2291
  super(options);
@@ -2179,11 +2320,20 @@ var AgentBuilder = class extends BaseResource {
2179
2320
  };
2180
2321
  }
2181
2322
  }
2323
+ /**
2324
+ * @deprecated Use createRunAsync() instead.
2325
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2326
+ */
2327
+ async createRun(_params) {
2328
+ throw new Error(
2329
+ "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."
2330
+ );
2331
+ }
2182
2332
  /**
2183
2333
  * Creates a new agent builder action run and returns the runId.
2184
2334
  * This calls `/api/agent-builder/:actionId/create-run`.
2185
2335
  */
2186
- async createRun(params) {
2336
+ async createRunAsync(params) {
2187
2337
  const searchParams = new URLSearchParams();
2188
2338
  if (!!params?.runId) {
2189
2339
  searchParams.set("runId", params.runId);
@@ -2193,14 +2343,6 @@ var AgentBuilder = class extends BaseResource {
2193
2343
  method: "POST"
2194
2344
  });
2195
2345
  }
2196
- /**
2197
- * Creates a new workflow run (alias for createRun)
2198
- * @param params - Optional object containing the optional runId
2199
- * @returns Promise containing the runId of the created run
2200
- */
2201
- createRunAsync(params) {
2202
- return this.createRun(params);
2203
- }
2204
2346
  /**
2205
2347
  * Starts agent builder action asynchronously and waits for completion.
2206
2348
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2283,7 +2425,7 @@ var AgentBuilder = class extends BaseResource {
2283
2425
  if (done && !value) continue;
2284
2426
  try {
2285
2427
  const decoded = value ? new TextDecoder().decode(value) : "";
2286
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2428
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2287
2429
  buffer = chunks.pop() || "";
2288
2430
  for (const chunk of chunks) {
2289
2431
  if (chunk) {
@@ -2340,7 +2482,7 @@ var AgentBuilder = class extends BaseResource {
2340
2482
  async transform(chunk, controller) {
2341
2483
  try {
2342
2484
  const decoded = new TextDecoder().decode(chunk);
2343
- const chunks = decoded.split(RECORD_SEPARATOR3);
2485
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2344
2486
  for (const chunk2 of chunks) {
2345
2487
  if (chunk2) {
2346
2488
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2389,7 +2531,7 @@ var AgentBuilder = class extends BaseResource {
2389
2531
  async transform(chunk, controller) {
2390
2532
  try {
2391
2533
  const decoded = new TextDecoder().decode(chunk);
2392
- const chunks = decoded.split(RECORD_SEPARATOR3);
2534
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2393
2535
  for (const chunk2 of chunks) {
2394
2536
  if (chunk2) {
2395
2537
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2560,6 +2702,31 @@ var Observability = class extends BaseResource {
2560
2702
  const queryString = searchParams.toString();
2561
2703
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2562
2704
  }
2705
+ /**
2706
+ * Retrieves scores by trace ID and span ID
2707
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2708
+ * @returns Promise containing scores and pagination info
2709
+ */
2710
+ getScoresBySpan(params) {
2711
+ const { traceId, spanId, page, perPage } = params;
2712
+ const searchParams = new URLSearchParams();
2713
+ if (page !== void 0) {
2714
+ searchParams.set("page", String(page));
2715
+ }
2716
+ if (perPage !== void 0) {
2717
+ searchParams.set("perPage", String(perPage));
2718
+ }
2719
+ const queryString = searchParams.toString();
2720
+ return this.request(
2721
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2722
+ );
2723
+ }
2724
+ score(params) {
2725
+ return this.request(`/api/observability/traces/score`, {
2726
+ method: "POST",
2727
+ body: { ...params }
2728
+ });
2729
+ }
2563
2730
  };
2564
2731
 
2565
2732
  // src/resources/network-memory-thread.ts
@@ -2625,144 +2792,6 @@ var NetworkMemoryThread = class extends BaseResource {
2625
2792
  }
2626
2793
  };
2627
2794
 
2628
- // src/resources/vNextNetwork.ts
2629
- var RECORD_SEPARATOR4 = "";
2630
- var VNextNetwork = class extends BaseResource {
2631
- constructor(options, networkId) {
2632
- super(options);
2633
- this.networkId = networkId;
2634
- }
2635
- /**
2636
- * Retrieves details about the network
2637
- * @returns Promise containing vNext network details
2638
- */
2639
- details() {
2640
- return this.request(`/api/networks/v-next/${this.networkId}`);
2641
- }
2642
- /**
2643
- * Generates a response from the v-next network
2644
- * @param params - Generation parameters including message
2645
- * @returns Promise containing the generated response
2646
- */
2647
- generate(params) {
2648
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2649
- method: "POST",
2650
- body: {
2651
- ...params,
2652
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2653
- }
2654
- });
2655
- }
2656
- /**
2657
- * Generates a response from the v-next network using multiple primitives
2658
- * @param params - Generation parameters including message
2659
- * @returns Promise containing the generated response
2660
- */
2661
- loop(params) {
2662
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2663
- method: "POST",
2664
- body: {
2665
- ...params,
2666
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2667
- }
2668
- });
2669
- }
2670
- async *streamProcessor(stream) {
2671
- const reader = stream.getReader();
2672
- let doneReading = false;
2673
- let buffer = "";
2674
- try {
2675
- while (!doneReading) {
2676
- const { done, value } = await reader.read();
2677
- doneReading = done;
2678
- if (done && !value) continue;
2679
- try {
2680
- const decoded = value ? new TextDecoder().decode(value) : "";
2681
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2682
- buffer = chunks.pop() || "";
2683
- for (const chunk of chunks) {
2684
- if (chunk) {
2685
- if (typeof chunk === "string") {
2686
- try {
2687
- const parsedChunk = JSON.parse(chunk);
2688
- yield parsedChunk;
2689
- } catch {
2690
- }
2691
- }
2692
- }
2693
- }
2694
- } catch {
2695
- }
2696
- }
2697
- if (buffer) {
2698
- try {
2699
- yield JSON.parse(buffer);
2700
- } catch {
2701
- }
2702
- }
2703
- } finally {
2704
- reader.cancel().catch(() => {
2705
- });
2706
- }
2707
- }
2708
- /**
2709
- * Streams a response from the v-next network
2710
- * @param params - Stream parameters including message
2711
- * @returns Promise containing the results
2712
- */
2713
- async stream(params, onRecord) {
2714
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2715
- method: "POST",
2716
- body: {
2717
- ...params,
2718
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2719
- },
2720
- stream: true
2721
- });
2722
- if (!response.ok) {
2723
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2724
- }
2725
- if (!response.body) {
2726
- throw new Error("Response body is null");
2727
- }
2728
- for await (const record of this.streamProcessor(response.body)) {
2729
- if (typeof record === "string") {
2730
- onRecord(JSON.parse(record));
2731
- } else {
2732
- onRecord(record);
2733
- }
2734
- }
2735
- }
2736
- /**
2737
- * Streams a response from the v-next network loop
2738
- * @param params - Stream parameters including message
2739
- * @returns Promise containing the results
2740
- */
2741
- async loopStream(params, onRecord) {
2742
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2743
- method: "POST",
2744
- body: {
2745
- ...params,
2746
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2747
- },
2748
- stream: true
2749
- });
2750
- if (!response.ok) {
2751
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2752
- }
2753
- if (!response.body) {
2754
- throw new Error("Response body is null");
2755
- }
2756
- for await (const record of this.streamProcessor(response.body)) {
2757
- if (typeof record === "string") {
2758
- onRecord(JSON.parse(record));
2759
- } else {
2760
- onRecord(record);
2761
- }
2762
- }
2763
- }
2764
- };
2765
-
2766
2795
  // src/client.ts
2767
2796
  var MastraClient = class extends BaseResource {
2768
2797
  observability;
@@ -2772,10 +2801,20 @@ var MastraClient = class extends BaseResource {
2772
2801
  }
2773
2802
  /**
2774
2803
  * Retrieves all available agents
2804
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2775
2805
  * @returns Promise containing map of agent IDs to agent details
2776
2806
  */
2777
- getAgents() {
2778
- return this.request("/api/agents");
2807
+ getAgents(runtimeContext) {
2808
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2809
+ const searchParams = new URLSearchParams();
2810
+ if (runtimeContextParam) {
2811
+ searchParams.set("runtimeContext", runtimeContextParam);
2812
+ }
2813
+ const queryString = searchParams.toString();
2814
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2815
+ }
2816
+ getAgentsModelProviders() {
2817
+ return this.request(`/api/agents/providers`);
2779
2818
  }
2780
2819
  /**
2781
2820
  * Gets an agent instance by ID
@@ -2793,6 +2832,14 @@ var MastraClient = class extends BaseResource {
2793
2832
  getMemoryThreads(params) {
2794
2833
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2795
2834
  }
2835
+ /**
2836
+ * Retrieves memory config for a resource
2837
+ * @param params - Parameters containing the resource ID
2838
+ * @returns Promise containing array of memory threads
2839
+ */
2840
+ getMemoryConfig(params) {
2841
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2842
+ }
2796
2843
  /**
2797
2844
  * Creates a new memory thread
2798
2845
  * @param params - Parameters for creating the memory thread
@@ -2809,6 +2856,24 @@ var MastraClient = class extends BaseResource {
2809
2856
  getMemoryThread(threadId, agentId) {
2810
2857
  return new MemoryThread(this.options, threadId, agentId);
2811
2858
  }
2859
+ getThreadMessages(threadId, opts = {}) {
2860
+ let url = "";
2861
+ if (opts.agentId) {
2862
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2863
+ } else if (opts.networkId) {
2864
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2865
+ }
2866
+ return this.request(url);
2867
+ }
2868
+ deleteThread(threadId, opts = {}) {
2869
+ let url = "";
2870
+ if (opts.agentId) {
2871
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2872
+ } else if (opts.networkId) {
2873
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2874
+ }
2875
+ return this.request(url, { method: "DELETE" });
2876
+ }
2812
2877
  /**
2813
2878
  * Saves messages to memory
2814
2879
  * @param params - Parameters containing messages to save
@@ -2871,10 +2936,17 @@ var MastraClient = class extends BaseResource {
2871
2936
  }
2872
2937
  /**
2873
2938
  * Retrieves all available tools
2939
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2874
2940
  * @returns Promise containing map of tool IDs to tool details
2875
2941
  */
2876
- getTools() {
2877
- return this.request("/api/tools");
2942
+ getTools(runtimeContext) {
2943
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2944
+ const searchParams = new URLSearchParams();
2945
+ if (runtimeContextParam) {
2946
+ searchParams.set("runtimeContext", runtimeContextParam);
2947
+ }
2948
+ const queryString = searchParams.toString();
2949
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2878
2950
  }
2879
2951
  /**
2880
2952
  * Gets a tool instance by ID
@@ -2884,27 +2956,19 @@ var MastraClient = class extends BaseResource {
2884
2956
  getTool(toolId) {
2885
2957
  return new Tool(this.options, toolId);
2886
2958
  }
2887
- /**
2888
- * Retrieves all available legacy workflows
2889
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2890
- */
2891
- getLegacyWorkflows() {
2892
- return this.request("/api/workflows/legacy");
2893
- }
2894
- /**
2895
- * Gets a legacy workflow instance by ID
2896
- * @param workflowId - ID of the legacy workflow to retrieve
2897
- * @returns Legacy Workflow instance
2898
- */
2899
- getLegacyWorkflow(workflowId) {
2900
- return new LegacyWorkflow(this.options, workflowId);
2901
- }
2902
2959
  /**
2903
2960
  * Retrieves all available workflows
2961
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2904
2962
  * @returns Promise containing map of workflow IDs to workflow details
2905
2963
  */
2906
- getWorkflows() {
2907
- return this.request("/api/workflows");
2964
+ getWorkflows(runtimeContext) {
2965
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2966
+ const searchParams = new URLSearchParams();
2967
+ if (runtimeContextParam) {
2968
+ searchParams.set("runtimeContext", runtimeContextParam);
2969
+ }
2970
+ const queryString = searchParams.toString();
2971
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2908
2972
  }
2909
2973
  /**
2910
2974
  * Gets a workflow instance by ID
@@ -3030,78 +3094,6 @@ var MastraClient = class extends BaseResource {
3030
3094
  getLogTransports() {
3031
3095
  return this.request("/api/logs/transports");
3032
3096
  }
3033
- /**
3034
- * List of all traces (paged)
3035
- * @param params - Parameters for filtering traces
3036
- * @returns Promise containing telemetry data
3037
- */
3038
- getTelemetry(params) {
3039
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3040
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3041
- const searchParams = new URLSearchParams();
3042
- if (name) {
3043
- searchParams.set("name", name);
3044
- }
3045
- if (scope) {
3046
- searchParams.set("scope", scope);
3047
- }
3048
- if (page) {
3049
- searchParams.set("page", String(page));
3050
- }
3051
- if (perPage) {
3052
- searchParams.set("perPage", String(perPage));
3053
- }
3054
- if (_attribute) {
3055
- if (Array.isArray(_attribute)) {
3056
- for (const attr of _attribute) {
3057
- searchParams.append("attribute", attr);
3058
- }
3059
- } else {
3060
- searchParams.set("attribute", _attribute);
3061
- }
3062
- }
3063
- if (fromDate) {
3064
- searchParams.set("fromDate", fromDate.toISOString());
3065
- }
3066
- if (toDate) {
3067
- searchParams.set("toDate", toDate.toISOString());
3068
- }
3069
- if (searchParams.size) {
3070
- return this.request(`/api/telemetry?${searchParams}`);
3071
- } else {
3072
- return this.request(`/api/telemetry`);
3073
- }
3074
- }
3075
- /**
3076
- * Retrieves all available networks
3077
- * @returns Promise containing map of network IDs to network details
3078
- */
3079
- getNetworks() {
3080
- return this.request("/api/networks");
3081
- }
3082
- /**
3083
- * Retrieves all available vNext networks
3084
- * @returns Promise containing map of vNext network IDs to vNext network details
3085
- */
3086
- getVNextNetworks() {
3087
- return this.request("/api/networks/v-next");
3088
- }
3089
- /**
3090
- * Gets a network instance by ID
3091
- * @param networkId - ID of the network to retrieve
3092
- * @returns Network instance
3093
- */
3094
- getNetwork(networkId) {
3095
- return new Network(this.options, networkId);
3096
- }
3097
- /**
3098
- * Gets a vNext network instance by ID
3099
- * @param networkId - ID of the vNext network to retrieve
3100
- * @returns vNext Network instance
3101
- */
3102
- getVNextNetwork(networkId) {
3103
- return new VNextNetwork(this.options, networkId);
3104
- }
3105
3097
  /**
3106
3098
  * Retrieves a list of available MCP servers.
3107
3099
  * @param params - Optional parameters for pagination (limit, offset).
@@ -3172,6 +3164,26 @@ var MastraClient = class extends BaseResource {
3172
3164
  }) {
3173
3165
  return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3174
3166
  }
3167
+ searchMemory({
3168
+ agentId,
3169
+ resourceId,
3170
+ threadId,
3171
+ searchQuery,
3172
+ memoryConfig
3173
+ }) {
3174
+ const params = new URLSearchParams({
3175
+ searchQuery,
3176
+ resourceId,
3177
+ agentId
3178
+ });
3179
+ if (threadId) {
3180
+ params.append("threadId", threadId);
3181
+ }
3182
+ if (memoryConfig) {
3183
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3184
+ }
3185
+ return this.request(`/api/memory/search?${params}`);
3186
+ }
3175
3187
  /**
3176
3188
  * Updates the working memory for a specific thread (optionally resource-scoped).
3177
3189
  * @param agentId - ID of the agent.
@@ -3206,7 +3218,7 @@ var MastraClient = class extends BaseResource {
3206
3218
  * @returns Promise containing the scorer
3207
3219
  */
3208
3220
  getScorer(scorerId) {
3209
- return this.request(`/api/scores/scorers/${scorerId}`);
3221
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3210
3222
  }
3211
3223
  getScoresByScorerId(params) {
3212
3224
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3224,7 +3236,7 @@ var MastraClient = class extends BaseResource {
3224
3236
  searchParams.set("perPage", String(perPage));
3225
3237
  }
3226
3238
  const queryString = searchParams.toString();
3227
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3239
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3228
3240
  }
3229
3241
  /**
3230
3242
  * Retrieves scores by run ID
@@ -3241,7 +3253,7 @@ var MastraClient = class extends BaseResource {
3241
3253
  searchParams.set("perPage", String(perPage));
3242
3254
  }
3243
3255
  const queryString = searchParams.toString();
3244
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3256
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3245
3257
  }
3246
3258
  /**
3247
3259
  * Retrieves scores by entity ID and type
@@ -3258,7 +3270,9 @@ var MastraClient = class extends BaseResource {
3258
3270
  searchParams.set("perPage", String(perPage));
3259
3271
  }
3260
3272
  const queryString = searchParams.toString();
3261
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3273
+ return this.request(
3274
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3275
+ );
3262
3276
  }
3263
3277
  /**
3264
3278
  * Saves a score
@@ -3284,8 +3298,35 @@ var MastraClient = class extends BaseResource {
3284
3298
  getAITraces(params) {
3285
3299
  return this.observability.getTraces(params);
3286
3300
  }
3301
+ getScoresBySpan(params) {
3302
+ return this.observability.getScoresBySpan(params);
3303
+ }
3304
+ score(params) {
3305
+ return this.observability.score(params);
3306
+ }
3287
3307
  };
3288
3308
 
3309
+ // src/tools.ts
3310
+ var ClientTool = class {
3311
+ id;
3312
+ description;
3313
+ inputSchema;
3314
+ outputSchema;
3315
+ execute;
3316
+ constructor(opts) {
3317
+ this.id = opts.id;
3318
+ this.description = opts.description;
3319
+ this.inputSchema = opts.inputSchema;
3320
+ this.outputSchema = opts.outputSchema;
3321
+ this.execute = opts.execute;
3322
+ }
3323
+ };
3324
+ function createTool(opts) {
3325
+ return new ClientTool(opts);
3326
+ }
3327
+
3328
+ exports.ClientTool = ClientTool;
3289
3329
  exports.MastraClient = MastraClient;
3330
+ exports.createTool = createTool;
3290
3331
  //# sourceMappingURL=index.cjs.map
3291
3332
  //# sourceMappingURL=index.cjs.map