@mastra/client-js 0.0.0-pgvector-index-fix-20250905222058 → 0.0.0-rag-chunk-extract-llm-option-20250926183645

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 +303 -10
  2. package/README.md +2 -6
  3. package/dist/client.d.ts +36 -27
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +470 -375
  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 +469 -376
  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 +47 -11
  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 +51 -42
  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,14 +317,15 @@ 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}`);
323
+ details(runtimeContext) {
324
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
290
325
  }
291
326
  async generate(params) {
292
327
  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."
328
+ "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
294
329
  );
295
330
  return this.generateLegacy(params);
296
331
  }
@@ -325,7 +360,9 @@ var Agent = class extends BaseResource {
325
360
  resourceId,
326
361
  threadId,
327
362
  runtimeContext,
328
- tracingContext: { currentSpan: void 0 }
363
+ tracingContext: { currentSpan: void 0 },
364
+ suspend: async () => {
365
+ }
329
366
  },
330
367
  {
331
368
  messages: response.messages,
@@ -333,10 +370,6 @@ var Agent = class extends BaseResource {
333
370
  }
334
371
  );
335
372
  const updatedMessages = [
336
- {
337
- role: "user",
338
- content: params.messages
339
- },
340
373
  ...response.response.messages,
341
374
  {
342
375
  role: "tool",
@@ -359,12 +392,25 @@ var Agent = class extends BaseResource {
359
392
  }
360
393
  return response;
361
394
  }
362
- async generateVNext(params) {
395
+ async generateVNext(messagesOrParams, options) {
396
+ let params;
397
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
398
+ params = messagesOrParams;
399
+ } else {
400
+ params = {
401
+ messages: messagesOrParams,
402
+ ...options
403
+ };
404
+ }
363
405
  const processedParams = {
364
406
  ...params,
365
407
  output: params.output ? zodToJsonSchema(params.output) : void 0,
366
408
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
367
- clientTools: processClientTools(params.clientTools)
409
+ clientTools: processClientTools(params.clientTools),
410
+ structuredOutput: params.structuredOutput ? {
411
+ ...params.structuredOutput,
412
+ schema: zodToJsonSchema(params.structuredOutput.schema)
413
+ } : void 0
368
414
  };
369
415
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
370
416
  const response = await this.request(
@@ -656,7 +702,7 @@ var Agent = class extends BaseResource {
656
702
  */
657
703
  async stream(params) {
658
704
  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."
705
+ "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
660
706
  );
661
707
  return this.streamLegacy(params);
662
708
  }
@@ -869,7 +915,7 @@ var Agent = class extends BaseResource {
869
915
  step,
870
916
  toolCallId: chunk.payload.toolCallId,
871
917
  toolName: chunk.payload.toolName,
872
- args: void 0
918
+ args: chunk.payload.args
873
919
  };
874
920
  message.toolInvocations.push(invocation);
875
921
  updateToolInvocationPart(chunk.payload.toolCallId, invocation);
@@ -923,14 +969,14 @@ var Agent = class extends BaseResource {
923
969
  }
924
970
  case "step-finish": {
925
971
  step += 1;
926
- currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
972
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
927
973
  currentReasoningPart = void 0;
928
974
  currentReasoningTextDetail = void 0;
929
975
  execUpdate();
930
976
  break;
931
977
  }
932
978
  case "finish": {
933
- finishReason = chunk.payload.finishReason;
979
+ finishReason = chunk.payload.stepResult.reason;
934
980
  if (chunk.payload.usage != null) {
935
981
  usage = chunk.payload.usage;
936
982
  }
@@ -954,9 +1000,28 @@ var Agent = class extends BaseResource {
954
1000
  let toolCalls = [];
955
1001
  let messages = [];
956
1002
  const [streamForWritable, streamForProcessing] = response.body.tee();
957
- streamForWritable.pipeTo(writable, {
958
- preventClose: true
959
- }).catch((error) => {
1003
+ streamForWritable.pipeTo(
1004
+ new WritableStream({
1005
+ async write(chunk) {
1006
+ try {
1007
+ const text = new TextDecoder().decode(chunk);
1008
+ if (text.includes("[DONE]")) {
1009
+ return;
1010
+ }
1011
+ } catch {
1012
+ }
1013
+ const writer = writable.getWriter();
1014
+ try {
1015
+ await writer.write(chunk);
1016
+ } finally {
1017
+ writer.releaseLock();
1018
+ }
1019
+ }
1020
+ }),
1021
+ {
1022
+ preventClose: true
1023
+ }
1024
+ ).catch((error) => {
960
1025
  console.error("Error piping to writable stream:", error);
961
1026
  });
962
1027
  this.processChatResponse_vNext({
@@ -986,14 +1051,17 @@ var Agent = class extends BaseResource {
986
1051
  threadId: processedParams.threadId,
987
1052
  runtimeContext: processedParams.runtimeContext,
988
1053
  // TODO: Pass proper tracing context when client-js supports tracing
989
- tracingContext: { currentSpan: void 0 }
1054
+ tracingContext: { currentSpan: void 0 },
1055
+ suspend: async () => {
1056
+ }
990
1057
  },
991
1058
  {
992
1059
  messages: response.messages,
993
1060
  toolCallId: toolCall2?.toolCallId
994
1061
  }
995
1062
  );
996
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1063
+ const lastMessageRaw = messages[messages.length - 1];
1064
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
997
1065
  const toolInvocationPart = lastMessage?.parts?.find(
998
1066
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
999
1067
  );
@@ -1011,25 +1079,11 @@ var Agent = class extends BaseResource {
1011
1079
  toolInvocation.state = "result";
1012
1080
  toolInvocation.result = result;
1013
1081
  }
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];
1082
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1029
1083
  this.processStreamResponse_vNext(
1030
1084
  {
1031
1085
  ...processedParams,
1032
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1086
+ messages: updatedMessages
1033
1087
  },
1034
1088
  writable
1035
1089
  ).catch((error) => {
@@ -1052,12 +1106,49 @@ var Agent = class extends BaseResource {
1052
1106
  }
1053
1107
  return response;
1054
1108
  }
1055
- async streamVNext(params) {
1109
+ async network(params) {
1110
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1111
+ method: "POST",
1112
+ body: params,
1113
+ stream: true
1114
+ });
1115
+ if (!response.body) {
1116
+ throw new Error("No response body");
1117
+ }
1118
+ const streamResponse = new Response(response.body, {
1119
+ status: response.status,
1120
+ statusText: response.statusText,
1121
+ headers: response.headers
1122
+ });
1123
+ streamResponse.processDataStream = async ({
1124
+ onChunk
1125
+ }) => {
1126
+ await processMastraNetworkStream({
1127
+ stream: streamResponse.body,
1128
+ onChunk
1129
+ });
1130
+ };
1131
+ return streamResponse;
1132
+ }
1133
+ async streamVNext(messagesOrParams, options) {
1134
+ let params;
1135
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1136
+ params = messagesOrParams;
1137
+ } else {
1138
+ params = {
1139
+ messages: messagesOrParams,
1140
+ ...options
1141
+ };
1142
+ }
1056
1143
  const processedParams = {
1057
1144
  ...params,
1058
1145
  output: params.output ? zodToJsonSchema(params.output) : void 0,
1059
1146
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1060
- clientTools: processClientTools(params.clientTools)
1147
+ clientTools: processClientTools(params.clientTools),
1148
+ structuredOutput: params.structuredOutput ? {
1149
+ ...params.structuredOutput,
1150
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1151
+ } : void 0
1061
1152
  };
1062
1153
  const { readable, writable } = new TransformStream();
1063
1154
  const response = await this.processStreamResponse_vNext(processedParams, writable);
@@ -1124,7 +1215,9 @@ var Agent = class extends BaseResource {
1124
1215
  threadId: processedParams.threadId,
1125
1216
  runtimeContext: processedParams.runtimeContext,
1126
1217
  // TODO: Pass proper tracing context when client-js supports tracing
1127
- tracingContext: { currentSpan: void 0 }
1218
+ tracingContext: { currentSpan: void 0 },
1219
+ suspend: async () => {
1220
+ }
1128
1221
  },
1129
1222
  {
1130
1223
  messages: response.messages,
@@ -1162,12 +1255,10 @@ var Agent = class extends BaseResource {
1162
1255
  } finally {
1163
1256
  writer.releaseLock();
1164
1257
  }
1165
- const originalMessages = processedParams.messages;
1166
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1167
1258
  this.processStreamResponse(
1168
1259
  {
1169
1260
  ...processedParams,
1170
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1261
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1171
1262
  },
1172
1263
  writable
1173
1264
  ).catch((error) => {
@@ -1193,10 +1284,11 @@ var Agent = class extends BaseResource {
1193
1284
  /**
1194
1285
  * Gets details about a specific tool available to the agent
1195
1286
  * @param toolId - ID of the tool to retrieve
1287
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1196
1288
  * @returns Promise containing tool details
1197
1289
  */
1198
- getTool(toolId) {
1199
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1290
+ getTool(toolId, runtimeContext) {
1291
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1200
1292
  }
1201
1293
  /**
1202
1294
  * Executes a tool for the agent
@@ -1207,7 +1299,7 @@ var Agent = class extends BaseResource {
1207
1299
  executeTool(toolId, params) {
1208
1300
  const body = {
1209
1301
  data: params.data,
1210
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1302
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1211
1303
  };
1212
1304
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1213
1305
  method: "POST",
@@ -1216,17 +1308,19 @@ var Agent = class extends BaseResource {
1216
1308
  }
1217
1309
  /**
1218
1310
  * Retrieves evaluation results for the agent
1311
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1219
1312
  * @returns Promise containing agent evaluations
1220
1313
  */
1221
- evals() {
1222
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1314
+ evals(runtimeContext) {
1315
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1223
1316
  }
1224
1317
  /**
1225
1318
  * Retrieves live evaluation results for the agent
1319
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1226
1320
  * @returns Promise containing live agent evaluations
1227
1321
  */
1228
- liveEvals() {
1229
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1322
+ liveEvals(runtimeContext) {
1323
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1230
1324
  }
1231
1325
  /**
1232
1326
  * Updates the model for the agent
@@ -1239,61 +1333,27 @@ var Agent = class extends BaseResource {
1239
1333
  body: params
1240
1334
  });
1241
1335
  }
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
1336
  /**
1256
- * Generates a response from the agent
1257
- * @param params - Generation parameters including prompt
1258
- * @returns Promise containing the generated response
1337
+ * Updates the model for the agent in the model list
1338
+ * @param params - Parameters for updating the model
1339
+ * @returns Promise containing the updated model
1259
1340
  */
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`, {
1341
+ updateModelInModelList({ modelConfigId, ...params }) {
1342
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1267
1343
  method: "POST",
1268
- body: processedParams
1344
+ body: params
1269
1345
  });
1270
1346
  }
1271
1347
  /**
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
1348
+ * Reorders the models for the agent
1349
+ * @param params - Parameters for reordering the model list
1350
+ * @returns Promise containing the updated model list
1275
1351
  */
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`, {
1352
+ reorderModelList(params) {
1353
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1283
1354
  method: "POST",
1284
- body: processedParams,
1285
- stream: true
1355
+ body: params
1286
1356
  });
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
1357
  }
1298
1358
  };
1299
1359
 
@@ -1384,10 +1444,13 @@ var Vector = class extends BaseResource {
1384
1444
  /**
1385
1445
  * Retrieves details about a specific vector index
1386
1446
  * @param indexName - Name of the index to get details for
1447
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1387
1448
  * @returns Promise containing vector index details
1388
1449
  */
1389
- details(indexName) {
1390
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1450
+ details(indexName, runtimeContext) {
1451
+ return this.request(
1452
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1453
+ );
1391
1454
  }
1392
1455
  /**
1393
1456
  * Deletes a vector index
@@ -1401,10 +1464,11 @@ var Vector = class extends BaseResource {
1401
1464
  }
1402
1465
  /**
1403
1466
  * Retrieves a list of all available indexes
1467
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1404
1468
  * @returns Promise containing array of index names
1405
1469
  */
1406
- getIndexes() {
1407
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1470
+ getIndexes(runtimeContext) {
1471
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1408
1472
  }
1409
1473
  /**
1410
1474
  * Creates a new vector index
@@ -1441,187 +1505,6 @@ var Vector = class extends BaseResource {
1441
1505
  }
1442
1506
  };
1443
1507
 
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
1508
  // src/resources/tool.ts
1626
1509
  var Tool = class extends BaseResource {
1627
1510
  constructor(options, toolId) {
@@ -1630,10 +1513,11 @@ var Tool = class extends BaseResource {
1630
1513
  }
1631
1514
  /**
1632
1515
  * Retrieves details about the tool
1516
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1633
1517
  * @returns Promise containing tool details including description and schemas
1634
1518
  */
1635
- details() {
1636
- return this.request(`/api/tools/${this.toolId}`);
1519
+ details(runtimeContext) {
1520
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1637
1521
  }
1638
1522
  /**
1639
1523
  * Executes the tool with the provided parameters
@@ -1657,7 +1541,7 @@ var Tool = class extends BaseResource {
1657
1541
  };
1658
1542
 
1659
1543
  // src/resources/workflow.ts
1660
- var RECORD_SEPARATOR2 = "";
1544
+ var RECORD_SEPARATOR = "";
1661
1545
  var Workflow = class extends BaseResource {
1662
1546
  constructor(options, workflowId) {
1663
1547
  super(options);
@@ -1681,7 +1565,7 @@ var Workflow = class extends BaseResource {
1681
1565
  if (done && !value) continue;
1682
1566
  try {
1683
1567
  const decoded = value ? new TextDecoder().decode(value) : "";
1684
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1568
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1685
1569
  buffer = chunks.pop() || "";
1686
1570
  for (const chunk of chunks) {
1687
1571
  if (chunk) {
@@ -1710,17 +1594,20 @@ var Workflow = class extends BaseResource {
1710
1594
  }
1711
1595
  /**
1712
1596
  * Retrieves details about the workflow
1597
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1713
1598
  * @returns Promise containing workflow details including steps and graphs
1714
1599
  */
1715
- details() {
1716
- return this.request(`/api/workflows/${this.workflowId}`);
1600
+ details(runtimeContext) {
1601
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1717
1602
  }
1718
1603
  /**
1719
1604
  * Retrieves all runs for a workflow
1720
1605
  * @param params - Parameters for filtering runs
1606
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1721
1607
  * @returns Promise containing workflow runs array
1722
1608
  */
1723
- runs(params) {
1609
+ runs(params, runtimeContext) {
1610
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1724
1611
  const searchParams = new URLSearchParams();
1725
1612
  if (params?.fromDate) {
1726
1613
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1737,6 +1624,9 @@ var Workflow = class extends BaseResource {
1737
1624
  if (params?.resourceId) {
1738
1625
  searchParams.set("resourceId", params.resourceId);
1739
1626
  }
1627
+ if (runtimeContextParam) {
1628
+ searchParams.set("runtimeContext", runtimeContextParam);
1629
+ }
1740
1630
  if (searchParams.size) {
1741
1631
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1742
1632
  } else {
@@ -1746,18 +1636,22 @@ var Workflow = class extends BaseResource {
1746
1636
  /**
1747
1637
  * Retrieves a specific workflow run by its ID
1748
1638
  * @param runId - The ID of the workflow run to retrieve
1639
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1749
1640
  * @returns Promise containing the workflow run details
1750
1641
  */
1751
- runById(runId) {
1752
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1642
+ runById(runId, runtimeContext) {
1643
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1753
1644
  }
1754
1645
  /**
1755
1646
  * Retrieves the execution result for a specific workflow run by its ID
1756
1647
  * @param runId - The ID of the workflow run to retrieve the execution result for
1648
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1757
1649
  * @returns Promise containing the workflow run execution result
1758
1650
  */
1759
- runExecutionResult(runId) {
1760
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1651
+ runExecutionResult(runId, runtimeContext) {
1652
+ return this.request(
1653
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1654
+ );
1761
1655
  }
1762
1656
  /**
1763
1657
  * Cancels a specific workflow run by its ID
@@ -1780,27 +1674,61 @@ var Workflow = class extends BaseResource {
1780
1674
  body: { event: params.event, data: params.data }
1781
1675
  });
1782
1676
  }
1677
+ /**
1678
+ * @deprecated Use createRunAsync() instead.
1679
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1680
+ */
1681
+ async createRun(_params) {
1682
+ throw new Error(
1683
+ "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."
1684
+ );
1685
+ }
1783
1686
  /**
1784
1687
  * Creates a new workflow run
1785
1688
  * @param params - Optional object containing the optional runId
1786
- * @returns Promise containing the runId of the created run
1689
+ * @returns Promise containing the runId of the created run with methods to control execution
1787
1690
  */
1788
- createRun(params) {
1691
+ async createRunAsync(params) {
1789
1692
  const searchParams = new URLSearchParams();
1790
1693
  if (!!params?.runId) {
1791
1694
  searchParams.set("runId", params.runId);
1792
1695
  }
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);
1696
+ const res = await this.request(
1697
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1698
+ {
1699
+ method: "POST"
1700
+ }
1701
+ );
1702
+ const runId = res.runId;
1703
+ return {
1704
+ runId,
1705
+ start: async (p) => {
1706
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1707
+ },
1708
+ startAsync: async (p) => {
1709
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1710
+ },
1711
+ watch: async (onRecord) => {
1712
+ return this.watch({ runId }, onRecord);
1713
+ },
1714
+ stream: async (p) => {
1715
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1716
+ },
1717
+ resume: async (p) => {
1718
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1719
+ },
1720
+ resumeAsync: async (p) => {
1721
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1722
+ },
1723
+ resumeStreamVNext: async (p) => {
1724
+ return this.resumeStreamVNext({
1725
+ runId,
1726
+ step: p.step,
1727
+ resumeData: p.resumeData,
1728
+ runtimeContext: p.runtimeContext
1729
+ });
1730
+ }
1731
+ };
1804
1732
  }
1805
1733
  /**
1806
1734
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1828,7 +1756,6 @@ var Workflow = class extends BaseResource {
1828
1756
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1829
1757
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1830
1758
  method: "POST",
1831
- stream: true,
1832
1759
  body: {
1833
1760
  step,
1834
1761
  resumeData,
@@ -1871,6 +1798,104 @@ var Workflow = class extends BaseResource {
1871
1798
  stream: true
1872
1799
  }
1873
1800
  );
1801
+ if (!response.ok) {
1802
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1803
+ }
1804
+ if (!response.body) {
1805
+ throw new Error("Response body is null");
1806
+ }
1807
+ let failedChunk = void 0;
1808
+ const transformStream = new TransformStream({
1809
+ start() {
1810
+ },
1811
+ async transform(chunk, controller) {
1812
+ try {
1813
+ const decoded = new TextDecoder().decode(chunk);
1814
+ const chunks = decoded.split(RECORD_SEPARATOR);
1815
+ for (const chunk2 of chunks) {
1816
+ if (chunk2) {
1817
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1818
+ try {
1819
+ const parsedChunk = JSON.parse(newChunk);
1820
+ controller.enqueue(parsedChunk);
1821
+ failedChunk = void 0;
1822
+ } catch {
1823
+ failedChunk = newChunk;
1824
+ }
1825
+ }
1826
+ }
1827
+ } catch {
1828
+ }
1829
+ }
1830
+ });
1831
+ return response.body.pipeThrough(transformStream);
1832
+ }
1833
+ /**
1834
+ * Observes workflow stream for a workflow run
1835
+ * @param params - Object containing the runId
1836
+ * @returns Promise containing the workflow execution results
1837
+ */
1838
+ async observeStream(params) {
1839
+ const searchParams = new URLSearchParams();
1840
+ searchParams.set("runId", params.runId);
1841
+ const response = await this.request(
1842
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1843
+ {
1844
+ method: "POST",
1845
+ stream: true
1846
+ }
1847
+ );
1848
+ if (!response.ok) {
1849
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1850
+ }
1851
+ if (!response.body) {
1852
+ throw new Error("Response body is null");
1853
+ }
1854
+ let failedChunk = void 0;
1855
+ const transformStream = new TransformStream({
1856
+ start() {
1857
+ },
1858
+ async transform(chunk, controller) {
1859
+ try {
1860
+ const decoded = new TextDecoder().decode(chunk);
1861
+ const chunks = decoded.split(RECORD_SEPARATOR);
1862
+ for (const chunk2 of chunks) {
1863
+ if (chunk2) {
1864
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1865
+ try {
1866
+ const parsedChunk = JSON.parse(newChunk);
1867
+ controller.enqueue(parsedChunk);
1868
+ failedChunk = void 0;
1869
+ } catch {
1870
+ failedChunk = newChunk;
1871
+ }
1872
+ }
1873
+ }
1874
+ } catch {
1875
+ }
1876
+ }
1877
+ });
1878
+ return response.body.pipeThrough(transformStream);
1879
+ }
1880
+ /**
1881
+ * Starts a workflow run and returns a stream
1882
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1883
+ * @returns Promise containing the workflow execution results
1884
+ */
1885
+ async streamVNext(params) {
1886
+ const searchParams = new URLSearchParams();
1887
+ if (!!params?.runId) {
1888
+ searchParams.set("runId", params.runId);
1889
+ }
1890
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1891
+ const response = await this.request(
1892
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1893
+ {
1894
+ method: "POST",
1895
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1896
+ stream: true
1897
+ }
1898
+ );
1874
1899
  if (!response.ok) {
1875
1900
  throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1876
1901
  }
@@ -1884,7 +1909,7 @@ var Workflow = class extends BaseResource {
1884
1909
  async transform(chunk, controller) {
1885
1910
  try {
1886
1911
  const decoded = new TextDecoder().decode(chunk);
1887
- const chunks = decoded.split(RECORD_SEPARATOR2);
1912
+ const chunks = decoded.split(RECORD_SEPARATOR);
1888
1913
  for (const chunk2 of chunks) {
1889
1914
  if (chunk2) {
1890
1915
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1919,6 +1944,22 @@ var Workflow = class extends BaseResource {
1919
1944
  }
1920
1945
  });
1921
1946
  }
1947
+ /**
1948
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1949
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1950
+ * @returns Promise containing the workflow resume results
1951
+ */
1952
+ resumeStreamVNext(params) {
1953
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1954
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1955
+ method: "POST",
1956
+ body: {
1957
+ step: params.step,
1958
+ resumeData: params.resumeData,
1959
+ runtimeContext
1960
+ }
1961
+ });
1962
+ }
1922
1963
  /**
1923
1964
  * Watches workflow transitions in real-time
1924
1965
  * @param runId - Optional run ID to filter the watch stream
@@ -1955,7 +1996,7 @@ var Workflow = class extends BaseResource {
1955
1996
  async start(controller) {
1956
1997
  try {
1957
1998
  for await (const record of records) {
1958
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1999
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
1959
2000
  controller.enqueue(encoder.encode(json));
1960
2001
  }
1961
2002
  controller.close();
@@ -2053,10 +2094,11 @@ var MCPTool = class extends BaseResource {
2053
2094
  }
2054
2095
  /**
2055
2096
  * Retrieves details about this specific tool from the MCP server.
2097
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2056
2098
  * @returns Promise containing the tool's information (name, description, schema).
2057
2099
  */
2058
- details() {
2059
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2100
+ details(runtimeContext) {
2101
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2060
2102
  }
2061
2103
  /**
2062
2104
  * Executes this specific tool on the MCP server.
@@ -2077,7 +2119,7 @@ var MCPTool = class extends BaseResource {
2077
2119
  };
2078
2120
 
2079
2121
  // src/resources/agent-builder.ts
2080
- var RECORD_SEPARATOR3 = "";
2122
+ var RECORD_SEPARATOR2 = "";
2081
2123
  var AgentBuilder = class extends BaseResource {
2082
2124
  constructor(options, actionId) {
2083
2125
  super(options);
@@ -2112,11 +2154,20 @@ var AgentBuilder = class extends BaseResource {
2112
2154
  };
2113
2155
  }
2114
2156
  }
2157
+ /**
2158
+ * @deprecated Use createRunAsync() instead.
2159
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2160
+ */
2161
+ async createRun(_params) {
2162
+ throw new Error(
2163
+ "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."
2164
+ );
2165
+ }
2115
2166
  /**
2116
2167
  * Creates a new agent builder action run and returns the runId.
2117
2168
  * This calls `/api/agent-builder/:actionId/create-run`.
2118
2169
  */
2119
- async createRun(params) {
2170
+ async createRunAsync(params) {
2120
2171
  const searchParams = new URLSearchParams();
2121
2172
  if (!!params?.runId) {
2122
2173
  searchParams.set("runId", params.runId);
@@ -2126,14 +2177,6 @@ var AgentBuilder = class extends BaseResource {
2126
2177
  method: "POST"
2127
2178
  });
2128
2179
  }
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
2180
  /**
2138
2181
  * Starts agent builder action asynchronously and waits for completion.
2139
2182
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2216,7 +2259,7 @@ var AgentBuilder = class extends BaseResource {
2216
2259
  if (done && !value) continue;
2217
2260
  try {
2218
2261
  const decoded = value ? new TextDecoder().decode(value) : "";
2219
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2262
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2220
2263
  buffer = chunks.pop() || "";
2221
2264
  for (const chunk of chunks) {
2222
2265
  if (chunk) {
@@ -2273,7 +2316,7 @@ var AgentBuilder = class extends BaseResource {
2273
2316
  async transform(chunk, controller) {
2274
2317
  try {
2275
2318
  const decoded = new TextDecoder().decode(chunk);
2276
- const chunks = decoded.split(RECORD_SEPARATOR3);
2319
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2277
2320
  for (const chunk2 of chunks) {
2278
2321
  if (chunk2) {
2279
2322
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2322,7 +2365,7 @@ var AgentBuilder = class extends BaseResource {
2322
2365
  async transform(chunk, controller) {
2323
2366
  try {
2324
2367
  const decoded = new TextDecoder().decode(chunk);
2325
- const chunks = decoded.split(RECORD_SEPARATOR3);
2368
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2326
2369
  for (const chunk2 of chunks) {
2327
2370
  if (chunk2) {
2328
2371
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2465,7 +2508,7 @@ var Observability = class extends BaseResource {
2465
2508
  getTraces(params) {
2466
2509
  const { pagination, filters } = params;
2467
2510
  const { page, perPage, dateRange } = pagination || {};
2468
- const { name, spanType } = filters || {};
2511
+ const { name, spanType, entityId, entityType } = filters || {};
2469
2512
  const searchParams = new URLSearchParams();
2470
2513
  if (page !== void 0) {
2471
2514
  searchParams.set("page", String(page));
@@ -2479,6 +2522,10 @@ var Observability = class extends BaseResource {
2479
2522
  if (spanType !== void 0) {
2480
2523
  searchParams.set("spanType", String(spanType));
2481
2524
  }
2525
+ if (entityId && entityType) {
2526
+ searchParams.set("entityId", entityId);
2527
+ searchParams.set("entityType", entityType);
2528
+ }
2482
2529
  if (dateRange) {
2483
2530
  const dateRangeStr = JSON.stringify({
2484
2531
  start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
@@ -2489,6 +2536,12 @@ var Observability = class extends BaseResource {
2489
2536
  const queryString = searchParams.toString();
2490
2537
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2491
2538
  }
2539
+ score(params) {
2540
+ return this.request(`/api/observability/traces/score`, {
2541
+ method: "POST",
2542
+ body: { ...params }
2543
+ });
2544
+ }
2492
2545
  };
2493
2546
 
2494
2547
  // src/resources/network-memory-thread.ts
@@ -2555,7 +2608,7 @@ var NetworkMemoryThread = class extends BaseResource {
2555
2608
  };
2556
2609
 
2557
2610
  // src/resources/vNextNetwork.ts
2558
- var RECORD_SEPARATOR4 = "";
2611
+ var RECORD_SEPARATOR3 = "";
2559
2612
  var VNextNetwork = class extends BaseResource {
2560
2613
  constructor(options, networkId) {
2561
2614
  super(options);
@@ -2563,10 +2616,11 @@ var VNextNetwork = class extends BaseResource {
2563
2616
  }
2564
2617
  /**
2565
2618
  * Retrieves details about the network
2619
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2566
2620
  * @returns Promise containing vNext network details
2567
2621
  */
2568
- details() {
2569
- return this.request(`/api/networks/v-next/${this.networkId}`);
2622
+ details(runtimeContext) {
2623
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2570
2624
  }
2571
2625
  /**
2572
2626
  * Generates a response from the v-next network
@@ -2607,7 +2661,7 @@ var VNextNetwork = class extends BaseResource {
2607
2661
  if (done && !value) continue;
2608
2662
  try {
2609
2663
  const decoded = value ? new TextDecoder().decode(value) : "";
2610
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2664
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2611
2665
  buffer = chunks.pop() || "";
2612
2666
  for (const chunk of chunks) {
2613
2667
  if (chunk) {
@@ -2701,10 +2755,17 @@ var MastraClient = class extends BaseResource {
2701
2755
  }
2702
2756
  /**
2703
2757
  * Retrieves all available agents
2758
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2704
2759
  * @returns Promise containing map of agent IDs to agent details
2705
2760
  */
2706
- getAgents() {
2707
- return this.request("/api/agents");
2761
+ getAgents(runtimeContext) {
2762
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2763
+ const searchParams = new URLSearchParams();
2764
+ if (runtimeContextParam) {
2765
+ searchParams.set("runtimeContext", runtimeContextParam);
2766
+ }
2767
+ const queryString = searchParams.toString();
2768
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2708
2769
  }
2709
2770
  /**
2710
2771
  * Gets an agent instance by ID
@@ -2722,6 +2783,14 @@ var MastraClient = class extends BaseResource {
2722
2783
  getMemoryThreads(params) {
2723
2784
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2724
2785
  }
2786
+ /**
2787
+ * Retrieves memory config for a resource
2788
+ * @param params - Parameters containing the resource ID
2789
+ * @returns Promise containing array of memory threads
2790
+ */
2791
+ getMemoryConfig(params) {
2792
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2793
+ }
2725
2794
  /**
2726
2795
  * Creates a new memory thread
2727
2796
  * @param params - Parameters for creating the memory thread
@@ -2738,6 +2807,24 @@ var MastraClient = class extends BaseResource {
2738
2807
  getMemoryThread(threadId, agentId) {
2739
2808
  return new MemoryThread(this.options, threadId, agentId);
2740
2809
  }
2810
+ getThreadMessages(threadId, opts = {}) {
2811
+ let url = "";
2812
+ if (opts.agentId) {
2813
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2814
+ } else if (opts.networkId) {
2815
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2816
+ }
2817
+ return this.request(url);
2818
+ }
2819
+ deleteThread(threadId, opts = {}) {
2820
+ let url = "";
2821
+ if (opts.agentId) {
2822
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2823
+ } else if (opts.networkId) {
2824
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2825
+ }
2826
+ return this.request(url, { method: "DELETE" });
2827
+ }
2741
2828
  /**
2742
2829
  * Saves messages to memory
2743
2830
  * @param params - Parameters containing messages to save
@@ -2800,10 +2887,17 @@ var MastraClient = class extends BaseResource {
2800
2887
  }
2801
2888
  /**
2802
2889
  * Retrieves all available tools
2890
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2803
2891
  * @returns Promise containing map of tool IDs to tool details
2804
2892
  */
2805
- getTools() {
2806
- return this.request("/api/tools");
2893
+ getTools(runtimeContext) {
2894
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2895
+ const searchParams = new URLSearchParams();
2896
+ if (runtimeContextParam) {
2897
+ searchParams.set("runtimeContext", runtimeContextParam);
2898
+ }
2899
+ const queryString = searchParams.toString();
2900
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2807
2901
  }
2808
2902
  /**
2809
2903
  * Gets a tool instance by ID
@@ -2813,27 +2907,19 @@ var MastraClient = class extends BaseResource {
2813
2907
  getTool(toolId) {
2814
2908
  return new Tool(this.options, toolId);
2815
2909
  }
2816
- /**
2817
- * Retrieves all available legacy workflows
2818
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2819
- */
2820
- getLegacyWorkflows() {
2821
- return this.request("/api/workflows/legacy");
2822
- }
2823
- /**
2824
- * Gets a legacy workflow instance by ID
2825
- * @param workflowId - ID of the legacy workflow to retrieve
2826
- * @returns Legacy Workflow instance
2827
- */
2828
- getLegacyWorkflow(workflowId) {
2829
- return new LegacyWorkflow(this.options, workflowId);
2830
- }
2831
2910
  /**
2832
2911
  * Retrieves all available workflows
2912
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2833
2913
  * @returns Promise containing map of workflow IDs to workflow details
2834
2914
  */
2835
- getWorkflows() {
2836
- return this.request("/api/workflows");
2915
+ getWorkflows(runtimeContext) {
2916
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2917
+ const searchParams = new URLSearchParams();
2918
+ if (runtimeContextParam) {
2919
+ searchParams.set("runtimeContext", runtimeContextParam);
2920
+ }
2921
+ const queryString = searchParams.toString();
2922
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2837
2923
  }
2838
2924
  /**
2839
2925
  * Gets a workflow instance by ID
@@ -3001,13 +3087,6 @@ var MastraClient = class extends BaseResource {
3001
3087
  return this.request(`/api/telemetry`);
3002
3088
  }
3003
3089
  }
3004
- /**
3005
- * Retrieves all available networks
3006
- * @returns Promise containing map of network IDs to network details
3007
- */
3008
- getNetworks() {
3009
- return this.request("/api/networks");
3010
- }
3011
3090
  /**
3012
3091
  * Retrieves all available vNext networks
3013
3092
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3015,14 +3094,6 @@ var MastraClient = class extends BaseResource {
3015
3094
  getVNextNetworks() {
3016
3095
  return this.request("/api/networks/v-next");
3017
3096
  }
3018
- /**
3019
- * Gets a network instance by ID
3020
- * @param networkId - ID of the network to retrieve
3021
- * @returns Network instance
3022
- */
3023
- getNetwork(networkId) {
3024
- return new Network(this.options, networkId);
3025
- }
3026
3097
  /**
3027
3098
  * Gets a vNext network instance by ID
3028
3099
  * @param networkId - ID of the vNext network to retrieve
@@ -3213,8 +3284,32 @@ var MastraClient = class extends BaseResource {
3213
3284
  getAITraces(params) {
3214
3285
  return this.observability.getTraces(params);
3215
3286
  }
3287
+ score(params) {
3288
+ return this.observability.score(params);
3289
+ }
3290
+ };
3291
+
3292
+ // src/tools.ts
3293
+ var ClientTool = class {
3294
+ id;
3295
+ description;
3296
+ inputSchema;
3297
+ outputSchema;
3298
+ execute;
3299
+ constructor(opts) {
3300
+ this.id = opts.id;
3301
+ this.description = opts.description;
3302
+ this.inputSchema = opts.inputSchema;
3303
+ this.outputSchema = opts.outputSchema;
3304
+ this.execute = opts.execute;
3305
+ }
3216
3306
  };
3307
+ function createTool(opts) {
3308
+ return new ClientTool(opts);
3309
+ }
3217
3310
 
3311
+ exports.ClientTool = ClientTool;
3218
3312
  exports.MastraClient = MastraClient;
3313
+ exports.createTool = createTool;
3219
3314
  //# sourceMappingURL=index.cjs.map
3220
3315
  //# sourceMappingURL=index.cjs.map