@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.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
  }
@@ -26,7 +41,7 @@ function zodToJsonSchema(zodSchema) {
26
41
  const fn = "toJSONSchema";
27
42
  return z[fn].call(z, zodSchema);
28
43
  }
29
- return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
44
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
30
45
  }
31
46
 
32
47
  // src/utils/process-client-tools.ts
@@ -59,7 +74,7 @@ function processClientTools(clientTools) {
59
74
  }
60
75
 
61
76
  // src/utils/process-mastra-stream.ts
62
- async function processMastraStream({
77
+ async function sharedProcessMastraStream({
63
78
  stream,
64
79
  onChunk
65
80
  }) {
@@ -77,14 +92,18 @@ async function processMastraStream({
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
  }
@@ -93,6 +112,24 @@ async function processMastraStream({
93
112
  reader.releaseLock();
94
113
  }
95
114
  }
115
+ async function processMastraNetworkStream({
116
+ stream,
117
+ onChunk
118
+ }) {
119
+ return sharedProcessMastraStream({
120
+ stream,
121
+ onChunk
122
+ });
123
+ }
124
+ async function processMastraStream({
125
+ stream,
126
+ onChunk
127
+ }) {
128
+ return sharedProcessMastraStream({
129
+ stream,
130
+ onChunk
131
+ });
132
+ }
96
133
 
97
134
  // src/resources/base.ts
98
135
  var BaseResource = class {
@@ -181,7 +218,9 @@ async function executeToolCallAndRespond({
181
218
  resourceId,
182
219
  threadId,
183
220
  runtimeContext,
184
- tracingContext: { currentSpan: void 0 }
221
+ tracingContext: { currentSpan: void 0 },
222
+ suspend: async () => {
223
+ }
185
224
  },
186
225
  {
187
226
  messages: response.messages,
@@ -189,11 +228,7 @@ async function executeToolCallAndRespond({
189
228
  }
190
229
  );
191
230
  const updatedMessages = [
192
- {
193
- role: "user",
194
- content: params.messages
195
- },
196
- ...response.response.messages,
231
+ ...response.response.messages || [],
197
232
  {
198
233
  role: "tool",
199
234
  content: [
@@ -255,17 +290,21 @@ var AgentVoice = class extends BaseResource {
255
290
  }
256
291
  /**
257
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
258
295
  * @returns Promise containing list of available speakers
259
296
  */
260
- getSpeakers() {
261
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
297
+ getSpeakers(runtimeContext) {
298
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
262
299
  }
263
300
  /**
264
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
265
304
  * @returns Promise containing a check if the agent has listening capabilities
266
305
  */
267
- getListener() {
268
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
306
+ getListener(runtimeContext) {
307
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
269
308
  }
270
309
  };
271
310
  var Agent = class extends BaseResource {
@@ -277,16 +316,17 @@ var Agent = class extends BaseResource {
277
316
  voice;
278
317
  /**
279
318
  * Retrieves details about the agent
319
+ * @param runtimeContext - Optional runtime context to pass as query parameter
280
320
  * @returns Promise containing agent details including model and instructions
281
321
  */
282
- details() {
283
- return this.request(`/api/agents/${this.agentId}`);
322
+ details(runtimeContext) {
323
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
284
324
  }
285
- async generate(params) {
286
- console.warn(
287
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
288
- );
289
- 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
+ });
290
330
  }
291
331
  async generateLegacy(params) {
292
332
  const processedParams = {
@@ -319,7 +359,9 @@ var Agent = class extends BaseResource {
319
359
  resourceId,
320
360
  threadId,
321
361
  runtimeContext,
322
- tracingContext: { currentSpan: void 0 }
362
+ tracingContext: { currentSpan: void 0 },
363
+ suspend: async () => {
364
+ }
323
365
  },
324
366
  {
325
367
  messages: response.messages,
@@ -327,10 +369,6 @@ var Agent = class extends BaseResource {
327
369
  }
328
370
  );
329
371
  const updatedMessages = [
330
- {
331
- role: "user",
332
- content: params.messages
333
- },
334
372
  ...response.response.messages,
335
373
  {
336
374
  role: "tool",
@@ -353,10 +391,18 @@ var Agent = class extends BaseResource {
353
391
  }
354
392
  return response;
355
393
  }
356
- 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
+ }
357
404
  const processedParams = {
358
405
  ...params,
359
- output: params.output ? zodToJsonSchema(params.output) : void 0,
360
406
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
361
407
  clientTools: processClientTools(params.clientTools),
362
408
  structuredOutput: params.structuredOutput ? {
@@ -366,7 +412,7 @@ var Agent = class extends BaseResource {
366
412
  };
367
413
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
368
414
  const response = await this.request(
369
- `/api/agents/${this.agentId}/generate/vnext`,
415
+ `/api/agents/${this.agentId}/generate`,
370
416
  {
371
417
  method: "POST",
372
418
  body: processedParams
@@ -380,7 +426,7 @@ var Agent = class extends BaseResource {
380
426
  resourceId,
381
427
  threadId,
382
428
  runtimeContext,
383
- respondFn: this.generateVNext.bind(this)
429
+ respondFn: this.generate.bind(this)
384
430
  });
385
431
  }
386
432
  return response;
@@ -647,17 +693,6 @@ var Agent = class extends BaseResource {
647
693
  });
648
694
  onFinish?.({ message, finishReason, usage });
649
695
  }
650
- /**
651
- * Streams a response from the agent
652
- * @param params - Stream parameters including prompt
653
- * @returns Promise containing the enhanced Response object with processDataStream method
654
- */
655
- async stream(params) {
656
- console.warn(
657
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
658
- );
659
- return this.streamLegacy(params);
660
- }
661
696
  /**
662
697
  * Streams a response from the agent
663
698
  * @param params - Stream parameters including prompt
@@ -672,7 +707,7 @@ var Agent = class extends BaseResource {
672
707
  clientTools: processClientTools(params.clientTools)
673
708
  };
674
709
  const { readable, writable } = new TransformStream();
675
- const response = await this.processStreamResponse(processedParams, writable);
710
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
676
711
  const streamResponse = new Response(readable, {
677
712
  status: response.status,
678
713
  statusText: response.statusText,
@@ -759,6 +794,14 @@ var Agent = class extends BaseResource {
759
794
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
760
795
  onChunk: async (chunk) => {
761
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
+ }
762
805
  case "step-start": {
763
806
  if (!replaceLastMessage) {
764
807
  message.id = chunk.payload.messageId;
@@ -912,7 +955,10 @@ var Agent = class extends BaseResource {
912
955
  break;
913
956
  }
914
957
  case "error": {
915
- throw new Error(chunk.payload.error);
958
+ throw getErrorFromUnknown(chunk.payload.error, {
959
+ fallbackMessage: "Unknown error in stream",
960
+ supportSerialization: false
961
+ });
916
962
  }
917
963
  case "data": {
918
964
  data.push(...chunk.payload.data);
@@ -939,8 +985,8 @@ var Agent = class extends BaseResource {
939
985
  });
940
986
  onFinish?.({ message, finishReason, usage });
941
987
  }
942
- async processStreamResponse_vNext(processedParams, writable) {
943
- 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}`, {
944
990
  method: "POST",
945
991
  body: processedParams,
946
992
  stream: true
@@ -955,18 +1001,17 @@ var Agent = class extends BaseResource {
955
1001
  streamForWritable.pipeTo(
956
1002
  new WritableStream({
957
1003
  async write(chunk) {
1004
+ let writer;
958
1005
  try {
1006
+ writer = writable.getWriter();
959
1007
  const text = new TextDecoder().decode(chunk);
960
- if (text.includes("[DONE]")) {
961
- return;
962
- }
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));
963
1011
  } catch {
964
- }
965
- const writer = writable.getWriter();
966
- try {
967
- await writer.write(chunk);
1012
+ await writer?.write(chunk);
968
1013
  } finally {
969
- writer.releaseLock();
1014
+ writer?.releaseLock();
970
1015
  }
971
1016
  }
972
1017
  }),
@@ -992,9 +1037,11 @@ var Agent = class extends BaseResource {
992
1037
  if (toolCall) {
993
1038
  toolCalls.push(toolCall);
994
1039
  }
1040
+ let shouldExecuteClientTool = false;
995
1041
  for (const toolCall2 of toolCalls) {
996
1042
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
997
1043
  if (clientTool && clientTool.execute) {
1044
+ shouldExecuteClientTool = true;
998
1045
  const result = await clientTool.execute(
999
1046
  {
1000
1047
  context: toolCall2?.args,
@@ -1003,7 +1050,9 @@ var Agent = class extends BaseResource {
1003
1050
  threadId: processedParams.threadId,
1004
1051
  runtimeContext: processedParams.runtimeContext,
1005
1052
  // TODO: Pass proper tracing context when client-js supports tracing
1006
- tracingContext: { currentSpan: void 0 }
1053
+ tracingContext: { currentSpan: void 0 },
1054
+ suspend: async () => {
1055
+ }
1007
1056
  },
1008
1057
  {
1009
1058
  messages: response.messages,
@@ -1029,10 +1078,8 @@ var Agent = class extends BaseResource {
1029
1078
  toolInvocation.state = "result";
1030
1079
  toolInvocation.result = result;
1031
1080
  }
1032
- const originalMessages = processedParams.messages;
1033
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1034
- const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1035
- this.processStreamResponse_vNext(
1081
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1082
+ this.processStreamResponse(
1036
1083
  {
1037
1084
  ...processedParams,
1038
1085
  messages: updatedMessages
@@ -1043,6 +1090,11 @@ var Agent = class extends BaseResource {
1043
1090
  });
1044
1091
  }
1045
1092
  }
1093
+ if (!shouldExecuteClientTool) {
1094
+ setTimeout(() => {
1095
+ writable.close();
1096
+ }, 0);
1097
+ }
1046
1098
  } else {
1047
1099
  setTimeout(() => {
1048
1100
  writable.close();
@@ -1058,10 +1110,42 @@ var Agent = class extends BaseResource {
1058
1110
  }
1059
1111
  return response;
1060
1112
  }
1061
- async streamVNext(params) {
1113
+ async network(params) {
1114
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1115
+ method: "POST",
1116
+ body: params,
1117
+ stream: true
1118
+ });
1119
+ if (!response.body) {
1120
+ throw new Error("No response body");
1121
+ }
1122
+ const streamResponse = new Response(response.body, {
1123
+ status: response.status,
1124
+ statusText: response.statusText,
1125
+ headers: response.headers
1126
+ });
1127
+ streamResponse.processDataStream = async ({
1128
+ onChunk
1129
+ }) => {
1130
+ await processMastraNetworkStream({
1131
+ stream: streamResponse.body,
1132
+ onChunk
1133
+ });
1134
+ };
1135
+ return streamResponse;
1136
+ }
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
+ }
1062
1147
  const processedParams = {
1063
1148
  ...params,
1064
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1065
1149
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1066
1150
  clientTools: processClientTools(params.clientTools),
1067
1151
  structuredOutput: params.structuredOutput ? {
@@ -1070,7 +1154,43 @@ var Agent = class extends BaseResource {
1070
1154
  } : void 0
1071
1155
  };
1072
1156
  const { readable, writable } = new TransformStream();
1073
- 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");
1074
1194
  const streamResponse = new Response(readable, {
1075
1195
  status: response.status,
1076
1196
  statusText: response.statusText,
@@ -1089,7 +1209,7 @@ var Agent = class extends BaseResource {
1089
1209
  /**
1090
1210
  * Processes the stream response and handles tool calls
1091
1211
  */
1092
- async processStreamResponse(processedParams, writable) {
1212
+ async processStreamResponseLegacy(processedParams, writable) {
1093
1213
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1094
1214
  method: "POST",
1095
1215
  body: processedParams,
@@ -1134,7 +1254,9 @@ var Agent = class extends BaseResource {
1134
1254
  threadId: processedParams.threadId,
1135
1255
  runtimeContext: processedParams.runtimeContext,
1136
1256
  // TODO: Pass proper tracing context when client-js supports tracing
1137
- tracingContext: { currentSpan: void 0 }
1257
+ tracingContext: { currentSpan: void 0 },
1258
+ suspend: async () => {
1259
+ }
1138
1260
  },
1139
1261
  {
1140
1262
  messages: response.messages,
@@ -1172,12 +1294,10 @@ var Agent = class extends BaseResource {
1172
1294
  } finally {
1173
1295
  writer.releaseLock();
1174
1296
  }
1175
- const originalMessages = processedParams.messages;
1176
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1177
- this.processStreamResponse(
1297
+ this.processStreamResponseLegacy(
1178
1298
  {
1179
1299
  ...processedParams,
1180
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1300
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1181
1301
  },
1182
1302
  writable
1183
1303
  ).catch((error) => {
@@ -1203,10 +1323,11 @@ var Agent = class extends BaseResource {
1203
1323
  /**
1204
1324
  * Gets details about a specific tool available to the agent
1205
1325
  * @param toolId - ID of the tool to retrieve
1326
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1206
1327
  * @returns Promise containing tool details
1207
1328
  */
1208
- getTool(toolId) {
1209
- 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)}`);
1210
1331
  }
1211
1332
  /**
1212
1333
  * Executes a tool for the agent
@@ -1217,7 +1338,7 @@ var Agent = class extends BaseResource {
1217
1338
  executeTool(toolId, params) {
1218
1339
  const body = {
1219
1340
  data: params.data,
1220
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1341
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1221
1342
  };
1222
1343
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1223
1344
  method: "POST",
@@ -1226,17 +1347,19 @@ var Agent = class extends BaseResource {
1226
1347
  }
1227
1348
  /**
1228
1349
  * Retrieves evaluation results for the agent
1350
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1229
1351
  * @returns Promise containing agent evaluations
1230
1352
  */
1231
- evals() {
1232
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1353
+ evals(runtimeContext) {
1354
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1233
1355
  }
1234
1356
  /**
1235
1357
  * Retrieves live evaluation results for the agent
1358
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1236
1359
  * @returns Promise containing live agent evaluations
1237
1360
  */
1238
- liveEvals() {
1239
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1361
+ liveEvals(runtimeContext) {
1362
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1240
1363
  }
1241
1364
  /**
1242
1365
  * Updates the model for the agent
@@ -1249,61 +1372,33 @@ var Agent = class extends BaseResource {
1249
1372
  body: params
1250
1373
  });
1251
1374
  }
1252
- };
1253
- var Network = class extends BaseResource {
1254
- constructor(options, networkId) {
1255
- super(options);
1256
- this.networkId = networkId;
1257
- }
1258
- /**
1259
- * Retrieves details about the network
1260
- * @returns Promise containing network details
1261
- */
1262
- details() {
1263
- return this.request(`/api/networks/${this.networkId}`);
1264
- }
1265
1375
  /**
1266
- * Generates a response from the agent
1267
- * @param params - Generation parameters including prompt
1268
- * @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
1269
1379
  */
1270
- generate(params) {
1271
- const processedParams = {
1272
- ...params,
1273
- output: zodToJsonSchema(params.output),
1274
- experimental_output: zodToJsonSchema(params.experimental_output)
1275
- };
1276
- return this.request(`/api/networks/${this.networkId}/generate`, {
1380
+ updateModelInModelList({ modelConfigId, ...params }) {
1381
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1277
1382
  method: "POST",
1278
- body: processedParams
1383
+ body: params
1279
1384
  });
1280
1385
  }
1281
1386
  /**
1282
- * Streams a response from the agent
1283
- * @param params - Stream parameters including prompt
1284
- * @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
1285
1390
  */
1286
- async stream(params) {
1287
- const processedParams = {
1288
- ...params,
1289
- output: zodToJsonSchema(params.output),
1290
- experimental_output: zodToJsonSchema(params.experimental_output)
1291
- };
1292
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1391
+ reorderModelList(params) {
1392
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1293
1393
  method: "POST",
1294
- body: processedParams,
1295
- stream: true
1394
+ body: params
1296
1395
  });
1297
- if (!response.body) {
1298
- throw new Error("No response body");
1299
- }
1300
- response.processDataStream = async (options = {}) => {
1301
- await processDataStream({
1302
- stream: response.body,
1303
- ...options
1304
- });
1305
- };
1306
- 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.");
1307
1402
  }
1308
1403
  };
1309
1404
 
@@ -1394,10 +1489,13 @@ var Vector = class extends BaseResource {
1394
1489
  /**
1395
1490
  * Retrieves details about a specific vector index
1396
1491
  * @param indexName - Name of the index to get details for
1492
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1397
1493
  * @returns Promise containing vector index details
1398
1494
  */
1399
- details(indexName) {
1400
- 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
+ );
1401
1499
  }
1402
1500
  /**
1403
1501
  * Deletes a vector index
@@ -1411,10 +1509,11 @@ var Vector = class extends BaseResource {
1411
1509
  }
1412
1510
  /**
1413
1511
  * Retrieves a list of all available indexes
1512
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1414
1513
  * @returns Promise containing array of index names
1415
1514
  */
1416
- getIndexes() {
1417
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1515
+ getIndexes(runtimeContext) {
1516
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1418
1517
  }
1419
1518
  /**
1420
1519
  * Creates a new vector index
@@ -1451,123 +1550,50 @@ var Vector = class extends BaseResource {
1451
1550
  }
1452
1551
  };
1453
1552
 
1454
- // src/resources/legacy-workflow.ts
1455
- var RECORD_SEPARATOR = "";
1456
- var LegacyWorkflow = class extends BaseResource {
1457
- constructor(options, workflowId) {
1553
+ // src/resources/tool.ts
1554
+ var Tool = class extends BaseResource {
1555
+ constructor(options, toolId) {
1458
1556
  super(options);
1459
- this.workflowId = workflowId;
1460
- }
1461
- /**
1462
- * Retrieves details about the legacy workflow
1463
- * @returns Promise containing legacy workflow details including steps and graphs
1464
- */
1465
- details() {
1466
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1467
- }
1468
- /**
1469
- * Retrieves all runs for a legacy workflow
1470
- * @param params - Parameters for filtering runs
1471
- * @returns Promise containing legacy workflow runs array
1472
- */
1473
- runs(params) {
1474
- const searchParams = new URLSearchParams();
1475
- if (params?.fromDate) {
1476
- searchParams.set("fromDate", params.fromDate.toISOString());
1477
- }
1478
- if (params?.toDate) {
1479
- searchParams.set("toDate", params.toDate.toISOString());
1480
- }
1481
- if (params?.limit) {
1482
- searchParams.set("limit", String(params.limit));
1483
- }
1484
- if (params?.offset) {
1485
- searchParams.set("offset", String(params.offset));
1486
- }
1487
- if (params?.resourceId) {
1488
- searchParams.set("resourceId", params.resourceId);
1489
- }
1490
- if (searchParams.size) {
1491
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1492
- } else {
1493
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1494
- }
1495
- }
1496
- /**
1497
- * Creates a new legacy workflow run
1498
- * @returns Promise containing the generated run ID
1499
- */
1500
- createRun(params) {
1501
- const searchParams = new URLSearchParams();
1502
- if (!!params?.runId) {
1503
- searchParams.set("runId", params.runId);
1504
- }
1505
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1506
- method: "POST"
1507
- });
1508
- }
1509
- /**
1510
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1511
- * @param params - Object containing the runId and triggerData
1512
- * @returns Promise containing success message
1513
- */
1514
- start(params) {
1515
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1516
- method: "POST",
1517
- body: params?.triggerData
1518
- });
1557
+ this.toolId = toolId;
1519
1558
  }
1520
1559
  /**
1521
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1522
- * @param stepId - ID of the step to resume
1523
- * @param runId - ID of the legacy workflow run
1524
- * @param context - Context to resume the legacy workflow with
1525
- * @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
1526
1563
  */
1527
- resume({
1528
- stepId,
1529
- runId,
1530
- context
1531
- }) {
1532
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1533
- method: "POST",
1534
- body: {
1535
- stepId,
1536
- context
1537
- }
1538
- });
1564
+ details(runtimeContext) {
1565
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1539
1566
  }
1540
1567
  /**
1541
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1542
- * @param params - Object containing the optional runId and triggerData
1543
- * @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
1544
1571
  */
1545
- startAsync(params) {
1546
- const searchParams = new URLSearchParams();
1547
- if (!!params?.runId) {
1548
- searchParams.set("runId", params.runId);
1572
+ execute(params) {
1573
+ const url = new URLSearchParams();
1574
+ if (params.runId) {
1575
+ url.set("runId", params.runId);
1549
1576
  }
1550
- 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()}`, {
1551
1582
  method: "POST",
1552
- body: params?.triggerData
1583
+ body
1553
1584
  });
1554
1585
  }
1555
- /**
1556
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1557
- * @param params - Object containing the runId, stepId, and context
1558
- * @returns Promise containing the workflow resume results
1559
- */
1560
- resumeAsync(params) {
1561
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1562
- method: "POST",
1563
- body: {
1564
- stepId: params.stepId,
1565
- context: params.context
1566
- }
1567
- });
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;
1568
1594
  }
1569
1595
  /**
1570
- * 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
1571
1597
  * separated by the Record Separator character (\x1E)
1572
1598
  *
1573
1599
  * @param stream - The readable stream to process
@@ -1612,125 +1638,21 @@ var LegacyWorkflow = class extends BaseResource {
1612
1638
  }
1613
1639
  }
1614
1640
  /**
1615
- * Watches legacy workflow transitions in real-time
1616
- * @param runId - Optional run ID to filter the watch stream
1617
- * @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
1618
1644
  */
1619
- async watch({ runId }, onRecord) {
1620
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1621
- stream: true
1622
- });
1623
- if (!response.ok) {
1624
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1625
- }
1626
- if (!response.body) {
1627
- throw new Error("Response body is null");
1628
- }
1629
- for await (const record of this.streamProcessor(response.body)) {
1630
- onRecord(record);
1631
- }
1632
- }
1633
- };
1634
-
1635
- // src/resources/tool.ts
1636
- var Tool = class extends BaseResource {
1637
- constructor(options, toolId) {
1638
- super(options);
1639
- this.toolId = toolId;
1640
- }
1641
- /**
1642
- * Retrieves details about the tool
1643
- * @returns Promise containing tool details including description and schemas
1644
- */
1645
- details() {
1646
- return this.request(`/api/tools/${this.toolId}`);
1647
- }
1648
- /**
1649
- * Executes the tool with the provided parameters
1650
- * @param params - Parameters required for tool execution
1651
- * @returns Promise containing the tool execution results
1652
- */
1653
- execute(params) {
1654
- const url = new URLSearchParams();
1655
- if (params.runId) {
1656
- url.set("runId", params.runId);
1657
- }
1658
- const body = {
1659
- data: params.data,
1660
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1661
- };
1662
- return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1663
- method: "POST",
1664
- body
1665
- });
1666
- }
1667
- };
1668
-
1669
- // src/resources/workflow.ts
1670
- var RECORD_SEPARATOR2 = "";
1671
- var Workflow = class extends BaseResource {
1672
- constructor(options, workflowId) {
1673
- super(options);
1674
- this.workflowId = workflowId;
1675
- }
1676
- /**
1677
- * Creates an async generator that processes a readable stream and yields workflow records
1678
- * separated by the Record Separator character (\x1E)
1679
- *
1680
- * @param stream - The readable stream to process
1681
- * @returns An async generator that yields parsed records
1682
- */
1683
- async *streamProcessor(stream) {
1684
- const reader = stream.getReader();
1685
- let doneReading = false;
1686
- let buffer = "";
1687
- try {
1688
- while (!doneReading) {
1689
- const { done, value } = await reader.read();
1690
- doneReading = done;
1691
- if (done && !value) continue;
1692
- try {
1693
- const decoded = value ? new TextDecoder().decode(value) : "";
1694
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1695
- buffer = chunks.pop() || "";
1696
- for (const chunk of chunks) {
1697
- if (chunk) {
1698
- if (typeof chunk === "string") {
1699
- try {
1700
- const parsedChunk = JSON.parse(chunk);
1701
- yield parsedChunk;
1702
- } catch {
1703
- }
1704
- }
1705
- }
1706
- }
1707
- } catch {
1708
- }
1709
- }
1710
- if (buffer) {
1711
- try {
1712
- yield JSON.parse(buffer);
1713
- } catch {
1714
- }
1715
- }
1716
- } finally {
1717
- reader.cancel().catch(() => {
1718
- });
1719
- }
1720
- }
1721
- /**
1722
- * Retrieves details about the workflow
1723
- * @returns Promise containing workflow details including steps and graphs
1724
- */
1725
- details() {
1726
- return this.request(`/api/workflows/${this.workflowId}`);
1645
+ details(runtimeContext) {
1646
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1727
1647
  }
1728
1648
  /**
1729
1649
  * Retrieves all runs for a workflow
1730
1650
  * @param params - Parameters for filtering runs
1651
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1731
1652
  * @returns Promise containing workflow runs array
1732
1653
  */
1733
- runs(params) {
1654
+ runs(params, runtimeContext) {
1655
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1734
1656
  const searchParams = new URLSearchParams();
1735
1657
  if (params?.fromDate) {
1736
1658
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1747,6 +1669,9 @@ var Workflow = class extends BaseResource {
1747
1669
  if (params?.resourceId) {
1748
1670
  searchParams.set("resourceId", params.resourceId);
1749
1671
  }
1672
+ if (runtimeContextParam) {
1673
+ searchParams.set("runtimeContext", runtimeContextParam);
1674
+ }
1750
1675
  if (searchParams.size) {
1751
1676
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1752
1677
  } else {
@@ -1756,18 +1681,22 @@ var Workflow = class extends BaseResource {
1756
1681
  /**
1757
1682
  * Retrieves a specific workflow run by its ID
1758
1683
  * @param runId - The ID of the workflow run to retrieve
1684
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1759
1685
  * @returns Promise containing the workflow run details
1760
1686
  */
1761
- runById(runId) {
1762
- 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)}`);
1763
1689
  }
1764
1690
  /**
1765
1691
  * Retrieves the execution result for a specific workflow run by its ID
1766
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
1767
1694
  * @returns Promise containing the workflow run execution result
1768
1695
  */
1769
- runExecutionResult(runId) {
1770
- 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
+ );
1771
1700
  }
1772
1701
  /**
1773
1702
  * Cancels a specific workflow run by its ID
@@ -1790,27 +1719,83 @@ var Workflow = class extends BaseResource {
1790
1719
  body: { event: params.event, data: params.data }
1791
1720
  });
1792
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
+ }
1793
1731
  /**
1794
1732
  * Creates a new workflow run
1795
1733
  * @param params - Optional object containing the optional runId
1796
- * @returns Promise containing the runId of the created run
1734
+ * @returns Promise containing the runId of the created run with methods to control execution
1797
1735
  */
1798
- createRun(params) {
1736
+ async createRunAsync(params) {
1799
1737
  const searchParams = new URLSearchParams();
1800
1738
  if (!!params?.runId) {
1801
1739
  searchParams.set("runId", params.runId);
1802
1740
  }
1803
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1804
- method: "POST"
1805
- });
1806
- }
1807
- /**
1808
- * Creates a new workflow run (alias for createRun)
1809
- * @param params - Optional object containing the optional runId
1810
- * @returns Promise containing the runId of the created run
1811
- */
1812
- createRunAsync(params) {
1813
- 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
+ };
1814
1799
  }
1815
1800
  /**
1816
1801
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1821,7 +1806,7 @@ var Workflow = class extends BaseResource {
1821
1806
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1822
1807
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1823
1808
  method: "POST",
1824
- body: { inputData: params?.inputData, runtimeContext }
1809
+ body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1825
1810
  });
1826
1811
  }
1827
1812
  /**
@@ -1833,16 +1818,17 @@ var Workflow = class extends BaseResource {
1833
1818
  step,
1834
1819
  runId,
1835
1820
  resumeData,
1821
+ tracingOptions,
1836
1822
  ...rest
1837
1823
  }) {
1838
1824
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1839
1825
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1840
1826
  method: "POST",
1841
- stream: true,
1842
1827
  body: {
1843
1828
  step,
1844
1829
  resumeData,
1845
- runtimeContext
1830
+ runtimeContext,
1831
+ tracingOptions
1846
1832
  }
1847
1833
  });
1848
1834
  }
@@ -1859,7 +1845,7 @@ var Workflow = class extends BaseResource {
1859
1845
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1860
1846
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1861
1847
  method: "POST",
1862
- body: { inputData: params.inputData, runtimeContext }
1848
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1863
1849
  });
1864
1850
  }
1865
1851
  /**
@@ -1877,12 +1863,12 @@ var Workflow = class extends BaseResource {
1877
1863
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1878
1864
  {
1879
1865
  method: "POST",
1880
- body: { inputData: params.inputData, runtimeContext },
1866
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1881
1867
  stream: true
1882
1868
  }
1883
1869
  );
1884
1870
  if (!response.ok) {
1885
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1871
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1886
1872
  }
1887
1873
  if (!response.body) {
1888
1874
  throw new Error("Response body is null");
@@ -1894,7 +1880,54 @@ var Workflow = class extends BaseResource {
1894
1880
  async transform(chunk, controller) {
1895
1881
  try {
1896
1882
  const decoded = new TextDecoder().decode(chunk);
1897
- 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);
1898
1931
  for (const chunk2 of chunks) {
1899
1932
  if (chunk2) {
1900
1933
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1928,7 +1961,12 @@ var Workflow = class extends BaseResource {
1928
1961
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1929
1962
  {
1930
1963
  method: "POST",
1931
- body: { inputData: params.inputData, runtimeContext },
1964
+ body: {
1965
+ inputData: params.inputData,
1966
+ runtimeContext,
1967
+ closeOnSuspend: params.closeOnSuspend,
1968
+ tracingOptions: params.tracingOptions
1969
+ },
1932
1970
  stream: true
1933
1971
  }
1934
1972
  );
@@ -1945,7 +1983,54 @@ var Workflow = class extends BaseResource {
1945
1983
  async transform(chunk, controller) {
1946
1984
  try {
1947
1985
  const decoded = new TextDecoder().decode(chunk);
1948
- 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);
1949
2034
  for (const chunk2 of chunks) {
1950
2035
  if (chunk2) {
1951
2036
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1976,9 +2061,64 @@ var Workflow = class extends BaseResource {
1976
2061
  body: {
1977
2062
  step: params.step,
1978
2063
  resumeData: params.resumeData,
1979
- runtimeContext
2064
+ runtimeContext,
2065
+ tracingOptions: params.tracingOptions
2066
+ }
2067
+ });
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
+ }
1980
2119
  }
1981
2120
  });
2121
+ return response.body.pipeThrough(transformStream);
1982
2122
  }
1983
2123
  /**
1984
2124
  * Watches workflow transitions in real-time
@@ -2016,7 +2156,7 @@ var Workflow = class extends BaseResource {
2016
2156
  async start(controller) {
2017
2157
  try {
2018
2158
  for await (const record of records) {
2019
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2159
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
2020
2160
  controller.enqueue(encoder.encode(json));
2021
2161
  }
2022
2162
  controller.close();
@@ -2114,10 +2254,11 @@ var MCPTool = class extends BaseResource {
2114
2254
  }
2115
2255
  /**
2116
2256
  * Retrieves details about this specific tool from the MCP server.
2257
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2117
2258
  * @returns Promise containing the tool's information (name, description, schema).
2118
2259
  */
2119
- details() {
2120
- 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)}`);
2121
2262
  }
2122
2263
  /**
2123
2264
  * Executes this specific tool on the MCP server.
@@ -2138,7 +2279,7 @@ var MCPTool = class extends BaseResource {
2138
2279
  };
2139
2280
 
2140
2281
  // src/resources/agent-builder.ts
2141
- var RECORD_SEPARATOR3 = "";
2282
+ var RECORD_SEPARATOR2 = "";
2142
2283
  var AgentBuilder = class extends BaseResource {
2143
2284
  constructor(options, actionId) {
2144
2285
  super(options);
@@ -2173,11 +2314,20 @@ var AgentBuilder = class extends BaseResource {
2173
2314
  };
2174
2315
  }
2175
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
+ }
2176
2326
  /**
2177
2327
  * Creates a new agent builder action run and returns the runId.
2178
2328
  * This calls `/api/agent-builder/:actionId/create-run`.
2179
2329
  */
2180
- async createRun(params) {
2330
+ async createRunAsync(params) {
2181
2331
  const searchParams = new URLSearchParams();
2182
2332
  if (!!params?.runId) {
2183
2333
  searchParams.set("runId", params.runId);
@@ -2187,14 +2337,6 @@ var AgentBuilder = class extends BaseResource {
2187
2337
  method: "POST"
2188
2338
  });
2189
2339
  }
2190
- /**
2191
- * Creates a new workflow run (alias for createRun)
2192
- * @param params - Optional object containing the optional runId
2193
- * @returns Promise containing the runId of the created run
2194
- */
2195
- createRunAsync(params) {
2196
- return this.createRun(params);
2197
- }
2198
2340
  /**
2199
2341
  * Starts agent builder action asynchronously and waits for completion.
2200
2342
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2277,7 +2419,7 @@ var AgentBuilder = class extends BaseResource {
2277
2419
  if (done && !value) continue;
2278
2420
  try {
2279
2421
  const decoded = value ? new TextDecoder().decode(value) : "";
2280
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2422
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2281
2423
  buffer = chunks.pop() || "";
2282
2424
  for (const chunk of chunks) {
2283
2425
  if (chunk) {
@@ -2334,7 +2476,7 @@ var AgentBuilder = class extends BaseResource {
2334
2476
  async transform(chunk, controller) {
2335
2477
  try {
2336
2478
  const decoded = new TextDecoder().decode(chunk);
2337
- const chunks = decoded.split(RECORD_SEPARATOR3);
2479
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2338
2480
  for (const chunk2 of chunks) {
2339
2481
  if (chunk2) {
2340
2482
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2383,7 +2525,7 @@ var AgentBuilder = class extends BaseResource {
2383
2525
  async transform(chunk, controller) {
2384
2526
  try {
2385
2527
  const decoded = new TextDecoder().decode(chunk);
2386
- const chunks = decoded.split(RECORD_SEPARATOR3);
2528
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2387
2529
  for (const chunk2 of chunks) {
2388
2530
  if (chunk2) {
2389
2531
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2554,6 +2696,31 @@ var Observability = class extends BaseResource {
2554
2696
  const queryString = searchParams.toString();
2555
2697
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2556
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
+ }
2557
2724
  };
2558
2725
 
2559
2726
  // src/resources/network-memory-thread.ts
@@ -2619,144 +2786,6 @@ var NetworkMemoryThread = class extends BaseResource {
2619
2786
  }
2620
2787
  };
2621
2788
 
2622
- // src/resources/vNextNetwork.ts
2623
- var RECORD_SEPARATOR4 = "";
2624
- var VNextNetwork = class extends BaseResource {
2625
- constructor(options, networkId) {
2626
- super(options);
2627
- this.networkId = networkId;
2628
- }
2629
- /**
2630
- * Retrieves details about the network
2631
- * @returns Promise containing vNext network details
2632
- */
2633
- details() {
2634
- return this.request(`/api/networks/v-next/${this.networkId}`);
2635
- }
2636
- /**
2637
- * Generates a response from the v-next network
2638
- * @param params - Generation parameters including message
2639
- * @returns Promise containing the generated response
2640
- */
2641
- generate(params) {
2642
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2643
- method: "POST",
2644
- body: {
2645
- ...params,
2646
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2647
- }
2648
- });
2649
- }
2650
- /**
2651
- * Generates a response from the v-next network using multiple primitives
2652
- * @param params - Generation parameters including message
2653
- * @returns Promise containing the generated response
2654
- */
2655
- loop(params) {
2656
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2657
- method: "POST",
2658
- body: {
2659
- ...params,
2660
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2661
- }
2662
- });
2663
- }
2664
- async *streamProcessor(stream) {
2665
- const reader = stream.getReader();
2666
- let doneReading = false;
2667
- let buffer = "";
2668
- try {
2669
- while (!doneReading) {
2670
- const { done, value } = await reader.read();
2671
- doneReading = done;
2672
- if (done && !value) continue;
2673
- try {
2674
- const decoded = value ? new TextDecoder().decode(value) : "";
2675
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2676
- buffer = chunks.pop() || "";
2677
- for (const chunk of chunks) {
2678
- if (chunk) {
2679
- if (typeof chunk === "string") {
2680
- try {
2681
- const parsedChunk = JSON.parse(chunk);
2682
- yield parsedChunk;
2683
- } catch {
2684
- }
2685
- }
2686
- }
2687
- }
2688
- } catch {
2689
- }
2690
- }
2691
- if (buffer) {
2692
- try {
2693
- yield JSON.parse(buffer);
2694
- } catch {
2695
- }
2696
- }
2697
- } finally {
2698
- reader.cancel().catch(() => {
2699
- });
2700
- }
2701
- }
2702
- /**
2703
- * Streams a response from the v-next network
2704
- * @param params - Stream parameters including message
2705
- * @returns Promise containing the results
2706
- */
2707
- async stream(params, onRecord) {
2708
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2709
- method: "POST",
2710
- body: {
2711
- ...params,
2712
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2713
- },
2714
- stream: true
2715
- });
2716
- if (!response.ok) {
2717
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2718
- }
2719
- if (!response.body) {
2720
- throw new Error("Response body is null");
2721
- }
2722
- for await (const record of this.streamProcessor(response.body)) {
2723
- if (typeof record === "string") {
2724
- onRecord(JSON.parse(record));
2725
- } else {
2726
- onRecord(record);
2727
- }
2728
- }
2729
- }
2730
- /**
2731
- * Streams a response from the v-next network loop
2732
- * @param params - Stream parameters including message
2733
- * @returns Promise containing the results
2734
- */
2735
- async loopStream(params, onRecord) {
2736
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2737
- method: "POST",
2738
- body: {
2739
- ...params,
2740
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2741
- },
2742
- stream: true
2743
- });
2744
- if (!response.ok) {
2745
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2746
- }
2747
- if (!response.body) {
2748
- throw new Error("Response body is null");
2749
- }
2750
- for await (const record of this.streamProcessor(response.body)) {
2751
- if (typeof record === "string") {
2752
- onRecord(JSON.parse(record));
2753
- } else {
2754
- onRecord(record);
2755
- }
2756
- }
2757
- }
2758
- };
2759
-
2760
2789
  // src/client.ts
2761
2790
  var MastraClient = class extends BaseResource {
2762
2791
  observability;
@@ -2766,10 +2795,20 @@ var MastraClient = class extends BaseResource {
2766
2795
  }
2767
2796
  /**
2768
2797
  * Retrieves all available agents
2798
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2769
2799
  * @returns Promise containing map of agent IDs to agent details
2770
2800
  */
2771
- getAgents() {
2772
- 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`);
2773
2812
  }
2774
2813
  /**
2775
2814
  * Gets an agent instance by ID
@@ -2787,6 +2826,14 @@ var MastraClient = class extends BaseResource {
2787
2826
  getMemoryThreads(params) {
2788
2827
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2789
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
+ }
2790
2837
  /**
2791
2838
  * Creates a new memory thread
2792
2839
  * @param params - Parameters for creating the memory thread
@@ -2803,6 +2850,24 @@ var MastraClient = class extends BaseResource {
2803
2850
  getMemoryThread(threadId, agentId) {
2804
2851
  return new MemoryThread(this.options, threadId, agentId);
2805
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
+ }
2806
2871
  /**
2807
2872
  * Saves messages to memory
2808
2873
  * @param params - Parameters containing messages to save
@@ -2865,10 +2930,17 @@ var MastraClient = class extends BaseResource {
2865
2930
  }
2866
2931
  /**
2867
2932
  * Retrieves all available tools
2933
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2868
2934
  * @returns Promise containing map of tool IDs to tool details
2869
2935
  */
2870
- getTools() {
2871
- 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}` : ""}`);
2872
2944
  }
2873
2945
  /**
2874
2946
  * Gets a tool instance by ID
@@ -2878,27 +2950,19 @@ var MastraClient = class extends BaseResource {
2878
2950
  getTool(toolId) {
2879
2951
  return new Tool(this.options, toolId);
2880
2952
  }
2881
- /**
2882
- * Retrieves all available legacy workflows
2883
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2884
- */
2885
- getLegacyWorkflows() {
2886
- return this.request("/api/workflows/legacy");
2887
- }
2888
- /**
2889
- * Gets a legacy workflow instance by ID
2890
- * @param workflowId - ID of the legacy workflow to retrieve
2891
- * @returns Legacy Workflow instance
2892
- */
2893
- getLegacyWorkflow(workflowId) {
2894
- return new LegacyWorkflow(this.options, workflowId);
2895
- }
2896
2953
  /**
2897
2954
  * Retrieves all available workflows
2955
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2898
2956
  * @returns Promise containing map of workflow IDs to workflow details
2899
2957
  */
2900
- getWorkflows() {
2901
- 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}` : ""}`);
2902
2966
  }
2903
2967
  /**
2904
2968
  * Gets a workflow instance by ID
@@ -3024,78 +3088,6 @@ var MastraClient = class extends BaseResource {
3024
3088
  getLogTransports() {
3025
3089
  return this.request("/api/logs/transports");
3026
3090
  }
3027
- /**
3028
- * List of all traces (paged)
3029
- * @param params - Parameters for filtering traces
3030
- * @returns Promise containing telemetry data
3031
- */
3032
- getTelemetry(params) {
3033
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
3034
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
3035
- const searchParams = new URLSearchParams();
3036
- if (name) {
3037
- searchParams.set("name", name);
3038
- }
3039
- if (scope) {
3040
- searchParams.set("scope", scope);
3041
- }
3042
- if (page) {
3043
- searchParams.set("page", String(page));
3044
- }
3045
- if (perPage) {
3046
- searchParams.set("perPage", String(perPage));
3047
- }
3048
- if (_attribute) {
3049
- if (Array.isArray(_attribute)) {
3050
- for (const attr of _attribute) {
3051
- searchParams.append("attribute", attr);
3052
- }
3053
- } else {
3054
- searchParams.set("attribute", _attribute);
3055
- }
3056
- }
3057
- if (fromDate) {
3058
- searchParams.set("fromDate", fromDate.toISOString());
3059
- }
3060
- if (toDate) {
3061
- searchParams.set("toDate", toDate.toISOString());
3062
- }
3063
- if (searchParams.size) {
3064
- return this.request(`/api/telemetry?${searchParams}`);
3065
- } else {
3066
- return this.request(`/api/telemetry`);
3067
- }
3068
- }
3069
- /**
3070
- * Retrieves all available networks
3071
- * @returns Promise containing map of network IDs to network details
3072
- */
3073
- getNetworks() {
3074
- return this.request("/api/networks");
3075
- }
3076
- /**
3077
- * Retrieves all available vNext networks
3078
- * @returns Promise containing map of vNext network IDs to vNext network details
3079
- */
3080
- getVNextNetworks() {
3081
- return this.request("/api/networks/v-next");
3082
- }
3083
- /**
3084
- * Gets a network instance by ID
3085
- * @param networkId - ID of the network to retrieve
3086
- * @returns Network instance
3087
- */
3088
- getNetwork(networkId) {
3089
- return new Network(this.options, networkId);
3090
- }
3091
- /**
3092
- * Gets a vNext network instance by ID
3093
- * @param networkId - ID of the vNext network to retrieve
3094
- * @returns vNext Network instance
3095
- */
3096
- getVNextNetwork(networkId) {
3097
- return new VNextNetwork(this.options, networkId);
3098
- }
3099
3091
  /**
3100
3092
  * Retrieves a list of available MCP servers.
3101
3093
  * @param params - Optional parameters for pagination (limit, offset).
@@ -3166,6 +3158,26 @@ var MastraClient = class extends BaseResource {
3166
3158
  }) {
3167
3159
  return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3168
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
+ }
3169
3181
  /**
3170
3182
  * Updates the working memory for a specific thread (optionally resource-scoped).
3171
3183
  * @param agentId - ID of the agent.
@@ -3200,7 +3212,7 @@ var MastraClient = class extends BaseResource {
3200
3212
  * @returns Promise containing the scorer
3201
3213
  */
3202
3214
  getScorer(scorerId) {
3203
- return this.request(`/api/scores/scorers/${scorerId}`);
3215
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3204
3216
  }
3205
3217
  getScoresByScorerId(params) {
3206
3218
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3218,7 +3230,7 @@ var MastraClient = class extends BaseResource {
3218
3230
  searchParams.set("perPage", String(perPage));
3219
3231
  }
3220
3232
  const queryString = searchParams.toString();
3221
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3233
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3222
3234
  }
3223
3235
  /**
3224
3236
  * Retrieves scores by run ID
@@ -3235,7 +3247,7 @@ var MastraClient = class extends BaseResource {
3235
3247
  searchParams.set("perPage", String(perPage));
3236
3248
  }
3237
3249
  const queryString = searchParams.toString();
3238
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3250
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3239
3251
  }
3240
3252
  /**
3241
3253
  * Retrieves scores by entity ID and type
@@ -3252,7 +3264,9 @@ var MastraClient = class extends BaseResource {
3252
3264
  searchParams.set("perPage", String(perPage));
3253
3265
  }
3254
3266
  const queryString = searchParams.toString();
3255
- 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
+ );
3256
3270
  }
3257
3271
  /**
3258
3272
  * Saves a score
@@ -3278,8 +3292,33 @@ var MastraClient = class extends BaseResource {
3278
3292
  getAITraces(params) {
3279
3293
  return this.observability.getTraces(params);
3280
3294
  }
3295
+ getScoresBySpan(params) {
3296
+ return this.observability.getScoresBySpan(params);
3297
+ }
3298
+ score(params) {
3299
+ return this.observability.score(params);
3300
+ }
3281
3301
  };
3282
3302
 
3283
- 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 };
3284
3323
  //# sourceMappingURL=index.js.map
3285
3324
  //# sourceMappingURL=index.js.map