@mastra/client-js 0.0.0-ai-telementry-ui-20250908102126 → 0.0.0-break-rename-vnext-legacy-20250926163953

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 +305 -10
  2. package/README.md +6 -10
  3. package/dist/client.d.ts +36 -27
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +466 -387
  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 +465 -388
  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 +48 -32
  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 +10 -0
  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/vNextNetwork.d.ts +2 -1
  24. package/dist/resources/vNextNetwork.d.ts.map +1 -1
  25. package/dist/resources/vector.d.ts +5 -2
  26. package/dist/resources/vector.d.ts.map +1 -1
  27. package/dist/resources/workflow.d.ts +110 -10
  28. package/dist/resources/workflow.d.ts.map +1 -1
  29. package/dist/tools.d.ts +22 -0
  30. package/dist/tools.d.ts.map +1 -0
  31. package/dist/types.d.ts +52 -43
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/utils/index.d.ts +2 -0
  34. package/dist/utils/index.d.ts.map +1 -1
  35. package/dist/utils/process-mastra-stream.d.ts +5 -1
  36. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  37. package/package.json +5 -6
  38. package/dist/resources/legacy-workflow.d.ts +0 -87
  39. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  40. package/dist/resources/network.d.ts +0 -30
  41. package/dist/resources/network.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -21,6 +21,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
21
21
  }
22
22
  return void 0;
23
23
  }
24
+ function base64RuntimeContext(runtimeContext) {
25
+ if (runtimeContext) {
26
+ return btoa(JSON.stringify(runtimeContext));
27
+ }
28
+ return void 0;
29
+ }
30
+ function runtimeContextQueryString(runtimeContext) {
31
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
32
+ if (!runtimeContextParam) return "";
33
+ const searchParams = new URLSearchParams();
34
+ searchParams.set("runtimeContext", runtimeContextParam);
35
+ const queryString = searchParams.toString();
36
+ return queryString ? `?${queryString}` : "";
37
+ }
24
38
  function isZodType(value) {
25
39
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
26
40
  }
@@ -32,7 +46,7 @@ function zodToJsonSchema(zodSchema) {
32
46
  const fn = "toJSONSchema";
33
47
  return zod.z[fn].call(zod.z, zodSchema);
34
48
  }
35
- return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
49
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
36
50
  }
37
51
 
38
52
  // src/utils/process-client-tools.ts
@@ -65,7 +79,7 @@ function processClientTools(clientTools) {
65
79
  }
66
80
 
67
81
  // src/utils/process-mastra-stream.ts
68
- async function processMastraStream({
82
+ async function sharedProcessMastraStream({
69
83
  stream,
70
84
  onChunk
71
85
  }) {
@@ -83,7 +97,7 @@ async function processMastraStream({
83
97
  if (line.startsWith("data: ")) {
84
98
  const data = line.slice(6);
85
99
  if (data === "[DONE]") {
86
- console.log("\u{1F3C1} Stream finished");
100
+ console.info("\u{1F3C1} Stream finished");
87
101
  return;
88
102
  }
89
103
  try {
@@ -99,6 +113,24 @@ async function processMastraStream({
99
113
  reader.releaseLock();
100
114
  }
101
115
  }
116
+ async function processMastraNetworkStream({
117
+ stream,
118
+ onChunk
119
+ }) {
120
+ return sharedProcessMastraStream({
121
+ stream,
122
+ onChunk
123
+ });
124
+ }
125
+ async function processMastraStream({
126
+ stream,
127
+ onChunk
128
+ }) {
129
+ return sharedProcessMastraStream({
130
+ stream,
131
+ onChunk
132
+ });
133
+ }
102
134
 
103
135
  // src/resources/base.ts
104
136
  var BaseResource = class {
@@ -187,7 +219,9 @@ async function executeToolCallAndRespond({
187
219
  resourceId,
188
220
  threadId,
189
221
  runtimeContext,
190
- tracingContext: { currentSpan: void 0 }
222
+ tracingContext: { currentSpan: void 0 },
223
+ suspend: async () => {
224
+ }
191
225
  },
192
226
  {
193
227
  messages: response.messages,
@@ -195,11 +229,7 @@ async function executeToolCallAndRespond({
195
229
  }
196
230
  );
197
231
  const updatedMessages = [
198
- {
199
- role: "user",
200
- content: params.messages
201
- },
202
- ...response.response.messages,
232
+ ...response.response.messages || [],
203
233
  {
204
234
  role: "tool",
205
235
  content: [
@@ -261,17 +291,21 @@ var AgentVoice = class extends BaseResource {
261
291
  }
262
292
  /**
263
293
  * Get available speakers for the agent's voice provider
294
+ * @param runtimeContext - Optional runtime context to pass as query parameter
295
+ * @param runtimeContext - Optional runtime context to pass as query parameter
264
296
  * @returns Promise containing list of available speakers
265
297
  */
266
- getSpeakers() {
267
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
298
+ getSpeakers(runtimeContext) {
299
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
268
300
  }
269
301
  /**
270
302
  * Get the listener configuration for the agent's voice provider
303
+ * @param runtimeContext - Optional runtime context to pass as query parameter
304
+ * @param runtimeContext - Optional runtime context to pass as query parameter
271
305
  * @returns Promise containing a check if the agent has listening capabilities
272
306
  */
273
- getListener() {
274
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
307
+ getListener(runtimeContext) {
308
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
275
309
  }
276
310
  };
277
311
  var Agent = class extends BaseResource {
@@ -283,16 +317,11 @@ var Agent = class extends BaseResource {
283
317
  voice;
284
318
  /**
285
319
  * Retrieves details about the agent
320
+ * @param runtimeContext - Optional runtime context to pass as query parameter
286
321
  * @returns Promise containing agent details including model and instructions
287
322
  */
288
- details() {
289
- return this.request(`/api/agents/${this.agentId}`);
290
- }
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);
323
+ details(runtimeContext) {
324
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
296
325
  }
297
326
  async generateLegacy(params) {
298
327
  const processedParams = {
@@ -325,7 +354,9 @@ var Agent = class extends BaseResource {
325
354
  resourceId,
326
355
  threadId,
327
356
  runtimeContext,
328
- tracingContext: { currentSpan: void 0 }
357
+ tracingContext: { currentSpan: void 0 },
358
+ suspend: async () => {
359
+ }
329
360
  },
330
361
  {
331
362
  messages: response.messages,
@@ -333,10 +364,6 @@ var Agent = class extends BaseResource {
333
364
  }
334
365
  );
335
366
  const updatedMessages = [
336
- {
337
- role: "user",
338
- content: params.messages
339
- },
340
367
  ...response.response.messages,
341
368
  {
342
369
  role: "tool",
@@ -359,16 +386,29 @@ var Agent = class extends BaseResource {
359
386
  }
360
387
  return response;
361
388
  }
362
- async generateVNext(params) {
389
+ async generate(messagesOrParams, options) {
390
+ let params;
391
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
392
+ params = messagesOrParams;
393
+ } else {
394
+ params = {
395
+ messages: messagesOrParams,
396
+ ...options
397
+ };
398
+ }
363
399
  const processedParams = {
364
400
  ...params,
365
401
  output: params.output ? zodToJsonSchema(params.output) : void 0,
366
402
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
367
- clientTools: processClientTools(params.clientTools)
403
+ clientTools: processClientTools(params.clientTools),
404
+ structuredOutput: params.structuredOutput ? {
405
+ ...params.structuredOutput,
406
+ schema: zodToJsonSchema(params.structuredOutput.schema)
407
+ } : void 0
368
408
  };
369
409
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
370
410
  const response = await this.request(
371
- `/api/agents/${this.agentId}/generate/vnext`,
411
+ `/api/agents/${this.agentId}/generate`,
372
412
  {
373
413
  method: "POST",
374
414
  body: processedParams
@@ -382,7 +422,7 @@ var Agent = class extends BaseResource {
382
422
  resourceId,
383
423
  threadId,
384
424
  runtimeContext,
385
- respondFn: this.generateVNext.bind(this)
425
+ respondFn: this.generate.bind(this)
386
426
  });
387
427
  }
388
428
  return response;
@@ -654,12 +694,6 @@ var Agent = class extends BaseResource {
654
694
  * @param params - Stream parameters including prompt
655
695
  * @returns Promise containing the enhanced Response object with processDataStream method
656
696
  */
657
- async stream(params) {
658
- console.warn(
659
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
660
- );
661
- return this.streamLegacy(params);
662
- }
663
697
  /**
664
698
  * Streams a response from the agent
665
699
  * @param params - Stream parameters including prompt
@@ -869,7 +903,7 @@ var Agent = class extends BaseResource {
869
903
  step,
870
904
  toolCallId: chunk.payload.toolCallId,
871
905
  toolName: chunk.payload.toolName,
872
- args: void 0
906
+ args: chunk.payload.args
873
907
  };
874
908
  message.toolInvocations.push(invocation);
875
909
  updateToolInvocationPart(chunk.payload.toolCallId, invocation);
@@ -923,14 +957,14 @@ var Agent = class extends BaseResource {
923
957
  }
924
958
  case "step-finish": {
925
959
  step += 1;
926
- currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
960
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
927
961
  currentReasoningPart = void 0;
928
962
  currentReasoningTextDetail = void 0;
929
963
  execUpdate();
930
964
  break;
931
965
  }
932
966
  case "finish": {
933
- finishReason = chunk.payload.finishReason;
967
+ finishReason = chunk.payload.stepResult.reason;
934
968
  if (chunk.payload.usage != null) {
935
969
  usage = chunk.payload.usage;
936
970
  }
@@ -942,7 +976,7 @@ var Agent = class extends BaseResource {
942
976
  onFinish?.({ message, finishReason, usage });
943
977
  }
944
978
  async processStreamResponse_vNext(processedParams, writable) {
945
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
979
+ const response = await this.request(`/api/agents/${this.agentId}/stream`, {
946
980
  method: "POST",
947
981
  body: processedParams,
948
982
  stream: true
@@ -954,9 +988,28 @@ var Agent = class extends BaseResource {
954
988
  let toolCalls = [];
955
989
  let messages = [];
956
990
  const [streamForWritable, streamForProcessing] = response.body.tee();
957
- streamForWritable.pipeTo(writable, {
958
- preventClose: true
959
- }).catch((error) => {
991
+ streamForWritable.pipeTo(
992
+ new WritableStream({
993
+ async write(chunk) {
994
+ try {
995
+ const text = new TextDecoder().decode(chunk);
996
+ if (text.includes("[DONE]")) {
997
+ return;
998
+ }
999
+ } catch {
1000
+ }
1001
+ const writer = writable.getWriter();
1002
+ try {
1003
+ await writer.write(chunk);
1004
+ } finally {
1005
+ writer.releaseLock();
1006
+ }
1007
+ }
1008
+ }),
1009
+ {
1010
+ preventClose: true
1011
+ }
1012
+ ).catch((error) => {
960
1013
  console.error("Error piping to writable stream:", error);
961
1014
  });
962
1015
  this.processChatResponse_vNext({
@@ -986,14 +1039,17 @@ var Agent = class extends BaseResource {
986
1039
  threadId: processedParams.threadId,
987
1040
  runtimeContext: processedParams.runtimeContext,
988
1041
  // TODO: Pass proper tracing context when client-js supports tracing
989
- tracingContext: { currentSpan: void 0 }
1042
+ tracingContext: { currentSpan: void 0 },
1043
+ suspend: async () => {
1044
+ }
990
1045
  },
991
1046
  {
992
1047
  messages: response.messages,
993
1048
  toolCallId: toolCall2?.toolCallId
994
1049
  }
995
1050
  );
996
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1051
+ const lastMessageRaw = messages[messages.length - 1];
1052
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
997
1053
  const toolInvocationPart = lastMessage?.parts?.find(
998
1054
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
999
1055
  );
@@ -1011,25 +1067,11 @@ var Agent = class extends BaseResource {
1011
1067
  toolInvocation.state = "result";
1012
1068
  toolInvocation.result = result;
1013
1069
  }
1014
- const writer = writable.getWriter();
1015
- try {
1016
- await writer.write(
1017
- new TextEncoder().encode(
1018
- "a:" + JSON.stringify({
1019
- toolCallId: toolCall2.toolCallId,
1020
- result
1021
- }) + "\n"
1022
- )
1023
- );
1024
- } finally {
1025
- writer.releaseLock();
1026
- }
1027
- const originalMessages = processedParams.messages;
1028
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1070
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1029
1071
  this.processStreamResponse_vNext(
1030
1072
  {
1031
1073
  ...processedParams,
1032
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1074
+ messages: updatedMessages
1033
1075
  },
1034
1076
  writable
1035
1077
  ).catch((error) => {
@@ -1052,12 +1094,49 @@ var Agent = class extends BaseResource {
1052
1094
  }
1053
1095
  return response;
1054
1096
  }
1055
- async streamVNext(params) {
1097
+ async network(params) {
1098
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1099
+ method: "POST",
1100
+ body: params,
1101
+ stream: true
1102
+ });
1103
+ if (!response.body) {
1104
+ throw new Error("No response body");
1105
+ }
1106
+ const streamResponse = new Response(response.body, {
1107
+ status: response.status,
1108
+ statusText: response.statusText,
1109
+ headers: response.headers
1110
+ });
1111
+ streamResponse.processDataStream = async ({
1112
+ onChunk
1113
+ }) => {
1114
+ await processMastraNetworkStream({
1115
+ stream: streamResponse.body,
1116
+ onChunk
1117
+ });
1118
+ };
1119
+ return streamResponse;
1120
+ }
1121
+ async stream(messagesOrParams, options) {
1122
+ let params;
1123
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1124
+ params = messagesOrParams;
1125
+ } else {
1126
+ params = {
1127
+ messages: messagesOrParams,
1128
+ ...options
1129
+ };
1130
+ }
1056
1131
  const processedParams = {
1057
1132
  ...params,
1058
1133
  output: params.output ? zodToJsonSchema(params.output) : void 0,
1059
1134
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1060
- clientTools: processClientTools(params.clientTools)
1135
+ clientTools: processClientTools(params.clientTools),
1136
+ structuredOutput: params.structuredOutput ? {
1137
+ ...params.structuredOutput,
1138
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1139
+ } : void 0
1061
1140
  };
1062
1141
  const { readable, writable } = new TransformStream();
1063
1142
  const response = await this.processStreamResponse_vNext(processedParams, writable);
@@ -1124,7 +1203,9 @@ var Agent = class extends BaseResource {
1124
1203
  threadId: processedParams.threadId,
1125
1204
  runtimeContext: processedParams.runtimeContext,
1126
1205
  // TODO: Pass proper tracing context when client-js supports tracing
1127
- tracingContext: { currentSpan: void 0 }
1206
+ tracingContext: { currentSpan: void 0 },
1207
+ suspend: async () => {
1208
+ }
1128
1209
  },
1129
1210
  {
1130
1211
  messages: response.messages,
@@ -1162,12 +1243,10 @@ var Agent = class extends BaseResource {
1162
1243
  } finally {
1163
1244
  writer.releaseLock();
1164
1245
  }
1165
- const originalMessages = processedParams.messages;
1166
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1167
1246
  this.processStreamResponse(
1168
1247
  {
1169
1248
  ...processedParams,
1170
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1249
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1171
1250
  },
1172
1251
  writable
1173
1252
  ).catch((error) => {
@@ -1193,10 +1272,11 @@ var Agent = class extends BaseResource {
1193
1272
  /**
1194
1273
  * Gets details about a specific tool available to the agent
1195
1274
  * @param toolId - ID of the tool to retrieve
1275
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1196
1276
  * @returns Promise containing tool details
1197
1277
  */
1198
- getTool(toolId) {
1199
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1278
+ getTool(toolId, runtimeContext) {
1279
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1200
1280
  }
1201
1281
  /**
1202
1282
  * Executes a tool for the agent
@@ -1207,7 +1287,7 @@ var Agent = class extends BaseResource {
1207
1287
  executeTool(toolId, params) {
1208
1288
  const body = {
1209
1289
  data: params.data,
1210
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1290
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1211
1291
  };
1212
1292
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1213
1293
  method: "POST",
@@ -1216,17 +1296,19 @@ var Agent = class extends BaseResource {
1216
1296
  }
1217
1297
  /**
1218
1298
  * Retrieves evaluation results for the agent
1299
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1219
1300
  * @returns Promise containing agent evaluations
1220
1301
  */
1221
- evals() {
1222
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1302
+ evals(runtimeContext) {
1303
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1223
1304
  }
1224
1305
  /**
1225
1306
  * Retrieves live evaluation results for the agent
1307
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1226
1308
  * @returns Promise containing live agent evaluations
1227
1309
  */
1228
- liveEvals() {
1229
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1310
+ liveEvals(runtimeContext) {
1311
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1230
1312
  }
1231
1313
  /**
1232
1314
  * Updates the model for the agent
@@ -1239,61 +1321,27 @@ var Agent = class extends BaseResource {
1239
1321
  body: params
1240
1322
  });
1241
1323
  }
1242
- };
1243
- var Network = class extends BaseResource {
1244
- constructor(options, networkId) {
1245
- super(options);
1246
- this.networkId = networkId;
1247
- }
1248
- /**
1249
- * Retrieves details about the network
1250
- * @returns Promise containing network details
1251
- */
1252
- details() {
1253
- return this.request(`/api/networks/${this.networkId}`);
1254
- }
1255
1324
  /**
1256
- * Generates a response from the agent
1257
- * @param params - Generation parameters including prompt
1258
- * @returns Promise containing the generated response
1325
+ * Updates the model for the agent in the model list
1326
+ * @param params - Parameters for updating the model
1327
+ * @returns Promise containing the updated model
1259
1328
  */
1260
- generate(params) {
1261
- const processedParams = {
1262
- ...params,
1263
- output: zodToJsonSchema(params.output),
1264
- experimental_output: zodToJsonSchema(params.experimental_output)
1265
- };
1266
- return this.request(`/api/networks/${this.networkId}/generate`, {
1329
+ updateModelInModelList({ modelConfigId, ...params }) {
1330
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1267
1331
  method: "POST",
1268
- body: processedParams
1332
+ body: params
1269
1333
  });
1270
1334
  }
1271
1335
  /**
1272
- * Streams a response from the agent
1273
- * @param params - Stream parameters including prompt
1274
- * @returns Promise containing the enhanced Response object with processDataStream method
1336
+ * Reorders the models for the agent
1337
+ * @param params - Parameters for reordering the model list
1338
+ * @returns Promise containing the updated model list
1275
1339
  */
1276
- async stream(params) {
1277
- const processedParams = {
1278
- ...params,
1279
- output: zodToJsonSchema(params.output),
1280
- experimental_output: zodToJsonSchema(params.experimental_output)
1281
- };
1282
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1340
+ reorderModelList(params) {
1341
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1283
1342
  method: "POST",
1284
- body: processedParams,
1285
- stream: true
1343
+ body: params
1286
1344
  });
1287
- if (!response.body) {
1288
- throw new Error("No response body");
1289
- }
1290
- response.processDataStream = async (options = {}) => {
1291
- await uiUtils.processDataStream({
1292
- stream: response.body,
1293
- ...options
1294
- });
1295
- };
1296
- return response;
1297
1345
  }
1298
1346
  };
1299
1347
 
@@ -1384,10 +1432,13 @@ var Vector = class extends BaseResource {
1384
1432
  /**
1385
1433
  * Retrieves details about a specific vector index
1386
1434
  * @param indexName - Name of the index to get details for
1435
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1387
1436
  * @returns Promise containing vector index details
1388
1437
  */
1389
- details(indexName) {
1390
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1438
+ details(indexName, runtimeContext) {
1439
+ return this.request(
1440
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1441
+ );
1391
1442
  }
1392
1443
  /**
1393
1444
  * Deletes a vector index
@@ -1401,10 +1452,11 @@ var Vector = class extends BaseResource {
1401
1452
  }
1402
1453
  /**
1403
1454
  * Retrieves a list of all available indexes
1455
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1404
1456
  * @returns Promise containing array of index names
1405
1457
  */
1406
- getIndexes() {
1407
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1458
+ getIndexes(runtimeContext) {
1459
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1408
1460
  }
1409
1461
  /**
1410
1462
  * Creates a new vector index
@@ -1441,187 +1493,6 @@ var Vector = class extends BaseResource {
1441
1493
  }
1442
1494
  };
1443
1495
 
1444
- // src/resources/legacy-workflow.ts
1445
- var RECORD_SEPARATOR = "";
1446
- var LegacyWorkflow = class extends BaseResource {
1447
- constructor(options, workflowId) {
1448
- super(options);
1449
- this.workflowId = workflowId;
1450
- }
1451
- /**
1452
- * Retrieves details about the legacy workflow
1453
- * @returns Promise containing legacy workflow details including steps and graphs
1454
- */
1455
- details() {
1456
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1457
- }
1458
- /**
1459
- * Retrieves all runs for a legacy workflow
1460
- * @param params - Parameters for filtering runs
1461
- * @returns Promise containing legacy workflow runs array
1462
- */
1463
- runs(params) {
1464
- const searchParams = new URLSearchParams();
1465
- if (params?.fromDate) {
1466
- searchParams.set("fromDate", params.fromDate.toISOString());
1467
- }
1468
- if (params?.toDate) {
1469
- searchParams.set("toDate", params.toDate.toISOString());
1470
- }
1471
- if (params?.limit) {
1472
- searchParams.set("limit", String(params.limit));
1473
- }
1474
- if (params?.offset) {
1475
- searchParams.set("offset", String(params.offset));
1476
- }
1477
- if (params?.resourceId) {
1478
- searchParams.set("resourceId", params.resourceId);
1479
- }
1480
- if (searchParams.size) {
1481
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1482
- } else {
1483
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1484
- }
1485
- }
1486
- /**
1487
- * Creates a new legacy workflow run
1488
- * @returns Promise containing the generated run ID
1489
- */
1490
- createRun(params) {
1491
- const searchParams = new URLSearchParams();
1492
- if (!!params?.runId) {
1493
- searchParams.set("runId", params.runId);
1494
- }
1495
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1496
- method: "POST"
1497
- });
1498
- }
1499
- /**
1500
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1501
- * @param params - Object containing the runId and triggerData
1502
- * @returns Promise containing success message
1503
- */
1504
- start(params) {
1505
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1506
- method: "POST",
1507
- body: params?.triggerData
1508
- });
1509
- }
1510
- /**
1511
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1512
- * @param stepId - ID of the step to resume
1513
- * @param runId - ID of the legacy workflow run
1514
- * @param context - Context to resume the legacy workflow with
1515
- * @returns Promise containing the legacy workflow resume results
1516
- */
1517
- resume({
1518
- stepId,
1519
- runId,
1520
- context
1521
- }) {
1522
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1523
- method: "POST",
1524
- body: {
1525
- stepId,
1526
- context
1527
- }
1528
- });
1529
- }
1530
- /**
1531
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1532
- * @param params - Object containing the optional runId and triggerData
1533
- * @returns Promise containing the workflow execution results
1534
- */
1535
- startAsync(params) {
1536
- const searchParams = new URLSearchParams();
1537
- if (!!params?.runId) {
1538
- searchParams.set("runId", params.runId);
1539
- }
1540
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1541
- method: "POST",
1542
- body: params?.triggerData
1543
- });
1544
- }
1545
- /**
1546
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1547
- * @param params - Object containing the runId, stepId, and context
1548
- * @returns Promise containing the workflow resume results
1549
- */
1550
- resumeAsync(params) {
1551
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1552
- method: "POST",
1553
- body: {
1554
- stepId: params.stepId,
1555
- context: params.context
1556
- }
1557
- });
1558
- }
1559
- /**
1560
- * Creates an async generator that processes a readable stream and yields records
1561
- * separated by the Record Separator character (\x1E)
1562
- *
1563
- * @param stream - The readable stream to process
1564
- * @returns An async generator that yields parsed records
1565
- */
1566
- async *streamProcessor(stream) {
1567
- const reader = stream.getReader();
1568
- let doneReading = false;
1569
- let buffer = "";
1570
- try {
1571
- while (!doneReading) {
1572
- const { done, value } = await reader.read();
1573
- doneReading = done;
1574
- if (done && !value) continue;
1575
- try {
1576
- const decoded = value ? new TextDecoder().decode(value) : "";
1577
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1578
- buffer = chunks.pop() || "";
1579
- for (const chunk of chunks) {
1580
- if (chunk) {
1581
- if (typeof chunk === "string") {
1582
- try {
1583
- const parsedChunk = JSON.parse(chunk);
1584
- yield parsedChunk;
1585
- } catch {
1586
- }
1587
- }
1588
- }
1589
- }
1590
- } catch {
1591
- }
1592
- }
1593
- if (buffer) {
1594
- try {
1595
- yield JSON.parse(buffer);
1596
- } catch {
1597
- }
1598
- }
1599
- } finally {
1600
- reader.cancel().catch(() => {
1601
- });
1602
- }
1603
- }
1604
- /**
1605
- * Watches legacy workflow transitions in real-time
1606
- * @param runId - Optional run ID to filter the watch stream
1607
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1608
- */
1609
- async watch({ runId }, onRecord) {
1610
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1611
- stream: true
1612
- });
1613
- if (!response.ok) {
1614
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1615
- }
1616
- if (!response.body) {
1617
- throw new Error("Response body is null");
1618
- }
1619
- for await (const record of this.streamProcessor(response.body)) {
1620
- onRecord(record);
1621
- }
1622
- }
1623
- };
1624
-
1625
1496
  // src/resources/tool.ts
1626
1497
  var Tool = class extends BaseResource {
1627
1498
  constructor(options, toolId) {
@@ -1630,10 +1501,11 @@ var Tool = class extends BaseResource {
1630
1501
  }
1631
1502
  /**
1632
1503
  * Retrieves details about the tool
1504
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1633
1505
  * @returns Promise containing tool details including description and schemas
1634
1506
  */
1635
- details() {
1636
- return this.request(`/api/tools/${this.toolId}`);
1507
+ details(runtimeContext) {
1508
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1637
1509
  }
1638
1510
  /**
1639
1511
  * Executes the tool with the provided parameters
@@ -1657,7 +1529,7 @@ var Tool = class extends BaseResource {
1657
1529
  };
1658
1530
 
1659
1531
  // src/resources/workflow.ts
1660
- var RECORD_SEPARATOR2 = "";
1532
+ var RECORD_SEPARATOR = "";
1661
1533
  var Workflow = class extends BaseResource {
1662
1534
  constructor(options, workflowId) {
1663
1535
  super(options);
@@ -1681,7 +1553,7 @@ var Workflow = class extends BaseResource {
1681
1553
  if (done && !value) continue;
1682
1554
  try {
1683
1555
  const decoded = value ? new TextDecoder().decode(value) : "";
1684
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1556
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1685
1557
  buffer = chunks.pop() || "";
1686
1558
  for (const chunk of chunks) {
1687
1559
  if (chunk) {
@@ -1710,17 +1582,20 @@ var Workflow = class extends BaseResource {
1710
1582
  }
1711
1583
  /**
1712
1584
  * Retrieves details about the workflow
1585
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1713
1586
  * @returns Promise containing workflow details including steps and graphs
1714
1587
  */
1715
- details() {
1716
- return this.request(`/api/workflows/${this.workflowId}`);
1588
+ details(runtimeContext) {
1589
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1717
1590
  }
1718
1591
  /**
1719
1592
  * Retrieves all runs for a workflow
1720
1593
  * @param params - Parameters for filtering runs
1594
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1721
1595
  * @returns Promise containing workflow runs array
1722
1596
  */
1723
- runs(params) {
1597
+ runs(params, runtimeContext) {
1598
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1724
1599
  const searchParams = new URLSearchParams();
1725
1600
  if (params?.fromDate) {
1726
1601
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1737,6 +1612,9 @@ var Workflow = class extends BaseResource {
1737
1612
  if (params?.resourceId) {
1738
1613
  searchParams.set("resourceId", params.resourceId);
1739
1614
  }
1615
+ if (runtimeContextParam) {
1616
+ searchParams.set("runtimeContext", runtimeContextParam);
1617
+ }
1740
1618
  if (searchParams.size) {
1741
1619
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1742
1620
  } else {
@@ -1746,18 +1624,22 @@ var Workflow = class extends BaseResource {
1746
1624
  /**
1747
1625
  * Retrieves a specific workflow run by its ID
1748
1626
  * @param runId - The ID of the workflow run to retrieve
1627
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1749
1628
  * @returns Promise containing the workflow run details
1750
1629
  */
1751
- runById(runId) {
1752
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1630
+ runById(runId, runtimeContext) {
1631
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1753
1632
  }
1754
1633
  /**
1755
1634
  * Retrieves the execution result for a specific workflow run by its ID
1756
1635
  * @param runId - The ID of the workflow run to retrieve the execution result for
1636
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1757
1637
  * @returns Promise containing the workflow run execution result
1758
1638
  */
1759
- runExecutionResult(runId) {
1760
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1639
+ runExecutionResult(runId, runtimeContext) {
1640
+ return this.request(
1641
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1642
+ );
1761
1643
  }
1762
1644
  /**
1763
1645
  * Cancels a specific workflow run by its ID
@@ -1780,27 +1662,61 @@ var Workflow = class extends BaseResource {
1780
1662
  body: { event: params.event, data: params.data }
1781
1663
  });
1782
1664
  }
1665
+ /**
1666
+ * @deprecated Use createRunAsync() instead.
1667
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1668
+ */
1669
+ async createRun(_params) {
1670
+ throw new Error(
1671
+ "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."
1672
+ );
1673
+ }
1783
1674
  /**
1784
1675
  * Creates a new workflow run
1785
1676
  * @param params - Optional object containing the optional runId
1786
- * @returns Promise containing the runId of the created run
1677
+ * @returns Promise containing the runId of the created run with methods to control execution
1787
1678
  */
1788
- createRun(params) {
1679
+ async createRunAsync(params) {
1789
1680
  const searchParams = new URLSearchParams();
1790
1681
  if (!!params?.runId) {
1791
1682
  searchParams.set("runId", params.runId);
1792
1683
  }
1793
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1794
- method: "POST"
1795
- });
1796
- }
1797
- /**
1798
- * Creates a new workflow run (alias for createRun)
1799
- * @param params - Optional object containing the optional runId
1800
- * @returns Promise containing the runId of the created run
1801
- */
1802
- createRunAsync(params) {
1803
- return this.createRun(params);
1684
+ const res = await this.request(
1685
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1686
+ {
1687
+ method: "POST"
1688
+ }
1689
+ );
1690
+ const runId = res.runId;
1691
+ return {
1692
+ runId,
1693
+ start: async (p) => {
1694
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1695
+ },
1696
+ startAsync: async (p) => {
1697
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1698
+ },
1699
+ watch: async (onRecord) => {
1700
+ return this.watch({ runId }, onRecord);
1701
+ },
1702
+ stream: async (p) => {
1703
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1704
+ },
1705
+ resume: async (p) => {
1706
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1707
+ },
1708
+ resumeAsync: async (p) => {
1709
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1710
+ },
1711
+ resumeStreamVNext: async (p) => {
1712
+ return this.resumeStreamVNext({
1713
+ runId,
1714
+ step: p.step,
1715
+ resumeData: p.resumeData,
1716
+ runtimeContext: p.runtimeContext
1717
+ });
1718
+ }
1719
+ };
1804
1720
  }
1805
1721
  /**
1806
1722
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1828,7 +1744,6 @@ var Workflow = class extends BaseResource {
1828
1744
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1829
1745
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1830
1746
  method: "POST",
1831
- stream: true,
1832
1747
  body: {
1833
1748
  step,
1834
1749
  resumeData,
@@ -1871,6 +1786,104 @@ var Workflow = class extends BaseResource {
1871
1786
  stream: true
1872
1787
  }
1873
1788
  );
1789
+ if (!response.ok) {
1790
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1791
+ }
1792
+ if (!response.body) {
1793
+ throw new Error("Response body is null");
1794
+ }
1795
+ let failedChunk = void 0;
1796
+ const transformStream = new TransformStream({
1797
+ start() {
1798
+ },
1799
+ async transform(chunk, controller) {
1800
+ try {
1801
+ const decoded = new TextDecoder().decode(chunk);
1802
+ const chunks = decoded.split(RECORD_SEPARATOR);
1803
+ for (const chunk2 of chunks) {
1804
+ if (chunk2) {
1805
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1806
+ try {
1807
+ const parsedChunk = JSON.parse(newChunk);
1808
+ controller.enqueue(parsedChunk);
1809
+ failedChunk = void 0;
1810
+ } catch {
1811
+ failedChunk = newChunk;
1812
+ }
1813
+ }
1814
+ }
1815
+ } catch {
1816
+ }
1817
+ }
1818
+ });
1819
+ return response.body.pipeThrough(transformStream);
1820
+ }
1821
+ /**
1822
+ * Observes workflow stream for a workflow run
1823
+ * @param params - Object containing the runId
1824
+ * @returns Promise containing the workflow execution results
1825
+ */
1826
+ async observeStream(params) {
1827
+ const searchParams = new URLSearchParams();
1828
+ searchParams.set("runId", params.runId);
1829
+ const response = await this.request(
1830
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1831
+ {
1832
+ method: "POST",
1833
+ stream: true
1834
+ }
1835
+ );
1836
+ if (!response.ok) {
1837
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1838
+ }
1839
+ if (!response.body) {
1840
+ throw new Error("Response body is null");
1841
+ }
1842
+ let failedChunk = void 0;
1843
+ const transformStream = new TransformStream({
1844
+ start() {
1845
+ },
1846
+ async transform(chunk, controller) {
1847
+ try {
1848
+ const decoded = new TextDecoder().decode(chunk);
1849
+ const chunks = decoded.split(RECORD_SEPARATOR);
1850
+ for (const chunk2 of chunks) {
1851
+ if (chunk2) {
1852
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1853
+ try {
1854
+ const parsedChunk = JSON.parse(newChunk);
1855
+ controller.enqueue(parsedChunk);
1856
+ failedChunk = void 0;
1857
+ } catch {
1858
+ failedChunk = newChunk;
1859
+ }
1860
+ }
1861
+ }
1862
+ } catch {
1863
+ }
1864
+ }
1865
+ });
1866
+ return response.body.pipeThrough(transformStream);
1867
+ }
1868
+ /**
1869
+ * Starts a workflow run and returns a stream
1870
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1871
+ * @returns Promise containing the workflow execution results
1872
+ */
1873
+ async streamVNext(params) {
1874
+ const searchParams = new URLSearchParams();
1875
+ if (!!params?.runId) {
1876
+ searchParams.set("runId", params.runId);
1877
+ }
1878
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1879
+ const response = await this.request(
1880
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1881
+ {
1882
+ method: "POST",
1883
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1884
+ stream: true
1885
+ }
1886
+ );
1874
1887
  if (!response.ok) {
1875
1888
  throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1876
1889
  }
@@ -1884,7 +1897,7 @@ var Workflow = class extends BaseResource {
1884
1897
  async transform(chunk, controller) {
1885
1898
  try {
1886
1899
  const decoded = new TextDecoder().decode(chunk);
1887
- const chunks = decoded.split(RECORD_SEPARATOR2);
1900
+ const chunks = decoded.split(RECORD_SEPARATOR);
1888
1901
  for (const chunk2 of chunks) {
1889
1902
  if (chunk2) {
1890
1903
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1919,6 +1932,22 @@ var Workflow = class extends BaseResource {
1919
1932
  }
1920
1933
  });
1921
1934
  }
1935
+ /**
1936
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1937
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1938
+ * @returns Promise containing the workflow resume results
1939
+ */
1940
+ resumeStreamVNext(params) {
1941
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1942
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1943
+ method: "POST",
1944
+ body: {
1945
+ step: params.step,
1946
+ resumeData: params.resumeData,
1947
+ runtimeContext
1948
+ }
1949
+ });
1950
+ }
1922
1951
  /**
1923
1952
  * Watches workflow transitions in real-time
1924
1953
  * @param runId - Optional run ID to filter the watch stream
@@ -1955,7 +1984,7 @@ var Workflow = class extends BaseResource {
1955
1984
  async start(controller) {
1956
1985
  try {
1957
1986
  for await (const record of records) {
1958
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1987
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
1959
1988
  controller.enqueue(encoder.encode(json));
1960
1989
  }
1961
1990
  controller.close();
@@ -2053,10 +2082,11 @@ var MCPTool = class extends BaseResource {
2053
2082
  }
2054
2083
  /**
2055
2084
  * Retrieves details about this specific tool from the MCP server.
2085
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2056
2086
  * @returns Promise containing the tool's information (name, description, schema).
2057
2087
  */
2058
- details() {
2059
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2088
+ details(runtimeContext) {
2089
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2060
2090
  }
2061
2091
  /**
2062
2092
  * Executes this specific tool on the MCP server.
@@ -2077,7 +2107,7 @@ var MCPTool = class extends BaseResource {
2077
2107
  };
2078
2108
 
2079
2109
  // src/resources/agent-builder.ts
2080
- var RECORD_SEPARATOR3 = "";
2110
+ var RECORD_SEPARATOR2 = "";
2081
2111
  var AgentBuilder = class extends BaseResource {
2082
2112
  constructor(options, actionId) {
2083
2113
  super(options);
@@ -2112,11 +2142,20 @@ var AgentBuilder = class extends BaseResource {
2112
2142
  };
2113
2143
  }
2114
2144
  }
2145
+ /**
2146
+ * @deprecated Use createRunAsync() instead.
2147
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2148
+ */
2149
+ async createRun(_params) {
2150
+ throw new Error(
2151
+ "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."
2152
+ );
2153
+ }
2115
2154
  /**
2116
2155
  * Creates a new agent builder action run and returns the runId.
2117
2156
  * This calls `/api/agent-builder/:actionId/create-run`.
2118
2157
  */
2119
- async createRun(params) {
2158
+ async createRunAsync(params) {
2120
2159
  const searchParams = new URLSearchParams();
2121
2160
  if (!!params?.runId) {
2122
2161
  searchParams.set("runId", params.runId);
@@ -2126,14 +2165,6 @@ var AgentBuilder = class extends BaseResource {
2126
2165
  method: "POST"
2127
2166
  });
2128
2167
  }
2129
- /**
2130
- * Creates a new workflow run (alias for createRun)
2131
- * @param params - Optional object containing the optional runId
2132
- * @returns Promise containing the runId of the created run
2133
- */
2134
- createRunAsync(params) {
2135
- return this.createRun(params);
2136
- }
2137
2168
  /**
2138
2169
  * Starts agent builder action asynchronously and waits for completion.
2139
2170
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2216,7 +2247,7 @@ var AgentBuilder = class extends BaseResource {
2216
2247
  if (done && !value) continue;
2217
2248
  try {
2218
2249
  const decoded = value ? new TextDecoder().decode(value) : "";
2219
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2250
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2220
2251
  buffer = chunks.pop() || "";
2221
2252
  for (const chunk of chunks) {
2222
2253
  if (chunk) {
@@ -2273,7 +2304,7 @@ var AgentBuilder = class extends BaseResource {
2273
2304
  async transform(chunk, controller) {
2274
2305
  try {
2275
2306
  const decoded = new TextDecoder().decode(chunk);
2276
- const chunks = decoded.split(RECORD_SEPARATOR3);
2307
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2277
2308
  for (const chunk2 of chunks) {
2278
2309
  if (chunk2) {
2279
2310
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2322,7 +2353,7 @@ var AgentBuilder = class extends BaseResource {
2322
2353
  async transform(chunk, controller) {
2323
2354
  try {
2324
2355
  const decoded = new TextDecoder().decode(chunk);
2325
- const chunks = decoded.split(RECORD_SEPARATOR3);
2356
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2326
2357
  for (const chunk2 of chunks) {
2327
2358
  if (chunk2) {
2328
2359
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2493,6 +2524,12 @@ var Observability = class extends BaseResource {
2493
2524
  const queryString = searchParams.toString();
2494
2525
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2495
2526
  }
2527
+ score(params) {
2528
+ return this.request(`/api/observability/traces/score`, {
2529
+ method: "POST",
2530
+ body: { ...params }
2531
+ });
2532
+ }
2496
2533
  };
2497
2534
 
2498
2535
  // src/resources/network-memory-thread.ts
@@ -2559,7 +2596,7 @@ var NetworkMemoryThread = class extends BaseResource {
2559
2596
  };
2560
2597
 
2561
2598
  // src/resources/vNextNetwork.ts
2562
- var RECORD_SEPARATOR4 = "";
2599
+ var RECORD_SEPARATOR3 = "";
2563
2600
  var VNextNetwork = class extends BaseResource {
2564
2601
  constructor(options, networkId) {
2565
2602
  super(options);
@@ -2567,10 +2604,11 @@ var VNextNetwork = class extends BaseResource {
2567
2604
  }
2568
2605
  /**
2569
2606
  * Retrieves details about the network
2607
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2570
2608
  * @returns Promise containing vNext network details
2571
2609
  */
2572
- details() {
2573
- return this.request(`/api/networks/v-next/${this.networkId}`);
2610
+ details(runtimeContext) {
2611
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2574
2612
  }
2575
2613
  /**
2576
2614
  * Generates a response from the v-next network
@@ -2611,7 +2649,7 @@ var VNextNetwork = class extends BaseResource {
2611
2649
  if (done && !value) continue;
2612
2650
  try {
2613
2651
  const decoded = value ? new TextDecoder().decode(value) : "";
2614
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2652
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2615
2653
  buffer = chunks.pop() || "";
2616
2654
  for (const chunk of chunks) {
2617
2655
  if (chunk) {
@@ -2705,10 +2743,17 @@ var MastraClient = class extends BaseResource {
2705
2743
  }
2706
2744
  /**
2707
2745
  * Retrieves all available agents
2746
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2708
2747
  * @returns Promise containing map of agent IDs to agent details
2709
2748
  */
2710
- getAgents() {
2711
- return this.request("/api/agents");
2749
+ getAgents(runtimeContext) {
2750
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2751
+ const searchParams = new URLSearchParams();
2752
+ if (runtimeContextParam) {
2753
+ searchParams.set("runtimeContext", runtimeContextParam);
2754
+ }
2755
+ const queryString = searchParams.toString();
2756
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2712
2757
  }
2713
2758
  /**
2714
2759
  * Gets an agent instance by ID
@@ -2726,6 +2771,14 @@ var MastraClient = class extends BaseResource {
2726
2771
  getMemoryThreads(params) {
2727
2772
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2728
2773
  }
2774
+ /**
2775
+ * Retrieves memory config for a resource
2776
+ * @param params - Parameters containing the resource ID
2777
+ * @returns Promise containing array of memory threads
2778
+ */
2779
+ getMemoryConfig(params) {
2780
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2781
+ }
2729
2782
  /**
2730
2783
  * Creates a new memory thread
2731
2784
  * @param params - Parameters for creating the memory thread
@@ -2742,6 +2795,24 @@ var MastraClient = class extends BaseResource {
2742
2795
  getMemoryThread(threadId, agentId) {
2743
2796
  return new MemoryThread(this.options, threadId, agentId);
2744
2797
  }
2798
+ getThreadMessages(threadId, opts = {}) {
2799
+ let url = "";
2800
+ if (opts.agentId) {
2801
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2802
+ } else if (opts.networkId) {
2803
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2804
+ }
2805
+ return this.request(url);
2806
+ }
2807
+ deleteThread(threadId, opts = {}) {
2808
+ let url = "";
2809
+ if (opts.agentId) {
2810
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2811
+ } else if (opts.networkId) {
2812
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2813
+ }
2814
+ return this.request(url, { method: "DELETE" });
2815
+ }
2745
2816
  /**
2746
2817
  * Saves messages to memory
2747
2818
  * @param params - Parameters containing messages to save
@@ -2804,10 +2875,17 @@ var MastraClient = class extends BaseResource {
2804
2875
  }
2805
2876
  /**
2806
2877
  * Retrieves all available tools
2878
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2807
2879
  * @returns Promise containing map of tool IDs to tool details
2808
2880
  */
2809
- getTools() {
2810
- return this.request("/api/tools");
2881
+ getTools(runtimeContext) {
2882
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2883
+ const searchParams = new URLSearchParams();
2884
+ if (runtimeContextParam) {
2885
+ searchParams.set("runtimeContext", runtimeContextParam);
2886
+ }
2887
+ const queryString = searchParams.toString();
2888
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2811
2889
  }
2812
2890
  /**
2813
2891
  * Gets a tool instance by ID
@@ -2817,27 +2895,19 @@ var MastraClient = class extends BaseResource {
2817
2895
  getTool(toolId) {
2818
2896
  return new Tool(this.options, toolId);
2819
2897
  }
2820
- /**
2821
- * Retrieves all available legacy workflows
2822
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2823
- */
2824
- getLegacyWorkflows() {
2825
- return this.request("/api/workflows/legacy");
2826
- }
2827
- /**
2828
- * Gets a legacy workflow instance by ID
2829
- * @param workflowId - ID of the legacy workflow to retrieve
2830
- * @returns Legacy Workflow instance
2831
- */
2832
- getLegacyWorkflow(workflowId) {
2833
- return new LegacyWorkflow(this.options, workflowId);
2834
- }
2835
2898
  /**
2836
2899
  * Retrieves all available workflows
2900
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2837
2901
  * @returns Promise containing map of workflow IDs to workflow details
2838
2902
  */
2839
- getWorkflows() {
2840
- return this.request("/api/workflows");
2903
+ getWorkflows(runtimeContext) {
2904
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2905
+ const searchParams = new URLSearchParams();
2906
+ if (runtimeContextParam) {
2907
+ searchParams.set("runtimeContext", runtimeContextParam);
2908
+ }
2909
+ const queryString = searchParams.toString();
2910
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2841
2911
  }
2842
2912
  /**
2843
2913
  * Gets a workflow instance by ID
@@ -3005,13 +3075,6 @@ var MastraClient = class extends BaseResource {
3005
3075
  return this.request(`/api/telemetry`);
3006
3076
  }
3007
3077
  }
3008
- /**
3009
- * Retrieves all available networks
3010
- * @returns Promise containing map of network IDs to network details
3011
- */
3012
- getNetworks() {
3013
- return this.request("/api/networks");
3014
- }
3015
3078
  /**
3016
3079
  * Retrieves all available vNext networks
3017
3080
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3019,14 +3082,6 @@ var MastraClient = class extends BaseResource {
3019
3082
  getVNextNetworks() {
3020
3083
  return this.request("/api/networks/v-next");
3021
3084
  }
3022
- /**
3023
- * Gets a network instance by ID
3024
- * @param networkId - ID of the network to retrieve
3025
- * @returns Network instance
3026
- */
3027
- getNetwork(networkId) {
3028
- return new Network(this.options, networkId);
3029
- }
3030
3085
  /**
3031
3086
  * Gets a vNext network instance by ID
3032
3087
  * @param networkId - ID of the vNext network to retrieve
@@ -3217,8 +3272,32 @@ var MastraClient = class extends BaseResource {
3217
3272
  getAITraces(params) {
3218
3273
  return this.observability.getTraces(params);
3219
3274
  }
3275
+ score(params) {
3276
+ return this.observability.score(params);
3277
+ }
3278
+ };
3279
+
3280
+ // src/tools.ts
3281
+ var ClientTool = class {
3282
+ id;
3283
+ description;
3284
+ inputSchema;
3285
+ outputSchema;
3286
+ execute;
3287
+ constructor(opts) {
3288
+ this.id = opts.id;
3289
+ this.description = opts.description;
3290
+ this.inputSchema = opts.inputSchema;
3291
+ this.outputSchema = opts.outputSchema;
3292
+ this.execute = opts.execute;
3293
+ }
3220
3294
  };
3295
+ function createTool(opts) {
3296
+ return new ClientTool(opts);
3297
+ }
3221
3298
 
3299
+ exports.ClientTool = ClientTool;
3222
3300
  exports.MastraClient = MastraClient;
3301
+ exports.createTool = createTool;
3223
3302
  //# sourceMappingURL=index.cjs.map
3224
3303
  //# sourceMappingURL=index.cjs.map