@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.js CHANGED
@@ -15,6 +15,20 @@ function parseClientRuntimeContext(runtimeContext) {
15
15
  }
16
16
  return void 0;
17
17
  }
18
+ function base64RuntimeContext(runtimeContext) {
19
+ if (runtimeContext) {
20
+ return btoa(JSON.stringify(runtimeContext));
21
+ }
22
+ return void 0;
23
+ }
24
+ function runtimeContextQueryString(runtimeContext) {
25
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
26
+ if (!runtimeContextParam) return "";
27
+ const searchParams = new URLSearchParams();
28
+ searchParams.set("runtimeContext", runtimeContextParam);
29
+ const queryString = searchParams.toString();
30
+ return queryString ? `?${queryString}` : "";
31
+ }
18
32
  function isZodType(value) {
19
33
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
20
34
  }
@@ -26,7 +40,7 @@ function zodToJsonSchema(zodSchema) {
26
40
  const fn = "toJSONSchema";
27
41
  return z[fn].call(z, zodSchema);
28
42
  }
29
- return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
43
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
30
44
  }
31
45
 
32
46
  // src/utils/process-client-tools.ts
@@ -59,7 +73,7 @@ function processClientTools(clientTools) {
59
73
  }
60
74
 
61
75
  // src/utils/process-mastra-stream.ts
62
- async function processMastraStream({
76
+ async function sharedProcessMastraStream({
63
77
  stream,
64
78
  onChunk
65
79
  }) {
@@ -77,7 +91,7 @@ async function processMastraStream({
77
91
  if (line.startsWith("data: ")) {
78
92
  const data = line.slice(6);
79
93
  if (data === "[DONE]") {
80
- console.log("\u{1F3C1} Stream finished");
94
+ console.info("\u{1F3C1} Stream finished");
81
95
  return;
82
96
  }
83
97
  try {
@@ -93,6 +107,24 @@ async function processMastraStream({
93
107
  reader.releaseLock();
94
108
  }
95
109
  }
110
+ async function processMastraNetworkStream({
111
+ stream,
112
+ onChunk
113
+ }) {
114
+ return sharedProcessMastraStream({
115
+ stream,
116
+ onChunk
117
+ });
118
+ }
119
+ async function processMastraStream({
120
+ stream,
121
+ onChunk
122
+ }) {
123
+ return sharedProcessMastraStream({
124
+ stream,
125
+ onChunk
126
+ });
127
+ }
96
128
 
97
129
  // src/resources/base.ts
98
130
  var BaseResource = class {
@@ -181,7 +213,9 @@ async function executeToolCallAndRespond({
181
213
  resourceId,
182
214
  threadId,
183
215
  runtimeContext,
184
- tracingContext: { currentSpan: void 0 }
216
+ tracingContext: { currentSpan: void 0 },
217
+ suspend: async () => {
218
+ }
185
219
  },
186
220
  {
187
221
  messages: response.messages,
@@ -189,11 +223,7 @@ async function executeToolCallAndRespond({
189
223
  }
190
224
  );
191
225
  const updatedMessages = [
192
- {
193
- role: "user",
194
- content: params.messages
195
- },
196
- ...response.response.messages,
226
+ ...response.response.messages || [],
197
227
  {
198
228
  role: "tool",
199
229
  content: [
@@ -255,17 +285,21 @@ var AgentVoice = class extends BaseResource {
255
285
  }
256
286
  /**
257
287
  * Get available speakers for the agent's voice provider
288
+ * @param runtimeContext - Optional runtime context to pass as query parameter
289
+ * @param runtimeContext - Optional runtime context to pass as query parameter
258
290
  * @returns Promise containing list of available speakers
259
291
  */
260
- getSpeakers() {
261
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
292
+ getSpeakers(runtimeContext) {
293
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
262
294
  }
263
295
  /**
264
296
  * Get the listener configuration for the agent's voice provider
297
+ * @param runtimeContext - Optional runtime context to pass as query parameter
298
+ * @param runtimeContext - Optional runtime context to pass as query parameter
265
299
  * @returns Promise containing a check if the agent has listening capabilities
266
300
  */
267
- getListener() {
268
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
301
+ getListener(runtimeContext) {
302
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
269
303
  }
270
304
  };
271
305
  var Agent = class extends BaseResource {
@@ -277,14 +311,15 @@ var Agent = class extends BaseResource {
277
311
  voice;
278
312
  /**
279
313
  * Retrieves details about the agent
314
+ * @param runtimeContext - Optional runtime context to pass as query parameter
280
315
  * @returns Promise containing agent details including model and instructions
281
316
  */
282
- details() {
283
- return this.request(`/api/agents/${this.agentId}`);
317
+ details(runtimeContext) {
318
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
284
319
  }
285
320
  async generate(params) {
286
321
  console.warn(
287
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
322
+ "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."
288
323
  );
289
324
  return this.generateLegacy(params);
290
325
  }
@@ -319,7 +354,9 @@ var Agent = class extends BaseResource {
319
354
  resourceId,
320
355
  threadId,
321
356
  runtimeContext,
322
- tracingContext: { currentSpan: void 0 }
357
+ tracingContext: { currentSpan: void 0 },
358
+ suspend: async () => {
359
+ }
323
360
  },
324
361
  {
325
362
  messages: response.messages,
@@ -327,10 +364,6 @@ var Agent = class extends BaseResource {
327
364
  }
328
365
  );
329
366
  const updatedMessages = [
330
- {
331
- role: "user",
332
- content: params.messages
333
- },
334
367
  ...response.response.messages,
335
368
  {
336
369
  role: "tool",
@@ -353,12 +386,25 @@ var Agent = class extends BaseResource {
353
386
  }
354
387
  return response;
355
388
  }
356
- async generateVNext(params) {
389
+ async generateVNext(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
+ }
357
399
  const processedParams = {
358
400
  ...params,
359
401
  output: params.output ? zodToJsonSchema(params.output) : void 0,
360
402
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
361
- 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
362
408
  };
363
409
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
364
410
  const response = await this.request(
@@ -650,7 +696,7 @@ var Agent = class extends BaseResource {
650
696
  */
651
697
  async stream(params) {
652
698
  console.warn(
653
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
699
+ "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."
654
700
  );
655
701
  return this.streamLegacy(params);
656
702
  }
@@ -863,7 +909,7 @@ var Agent = class extends BaseResource {
863
909
  step,
864
910
  toolCallId: chunk.payload.toolCallId,
865
911
  toolName: chunk.payload.toolName,
866
- args: void 0
912
+ args: chunk.payload.args
867
913
  };
868
914
  message.toolInvocations.push(invocation);
869
915
  updateToolInvocationPart(chunk.payload.toolCallId, invocation);
@@ -917,14 +963,14 @@ var Agent = class extends BaseResource {
917
963
  }
918
964
  case "step-finish": {
919
965
  step += 1;
920
- currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
966
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
921
967
  currentReasoningPart = void 0;
922
968
  currentReasoningTextDetail = void 0;
923
969
  execUpdate();
924
970
  break;
925
971
  }
926
972
  case "finish": {
927
- finishReason = chunk.payload.finishReason;
973
+ finishReason = chunk.payload.stepResult.reason;
928
974
  if (chunk.payload.usage != null) {
929
975
  usage = chunk.payload.usage;
930
976
  }
@@ -948,9 +994,28 @@ var Agent = class extends BaseResource {
948
994
  let toolCalls = [];
949
995
  let messages = [];
950
996
  const [streamForWritable, streamForProcessing] = response.body.tee();
951
- streamForWritable.pipeTo(writable, {
952
- preventClose: true
953
- }).catch((error) => {
997
+ streamForWritable.pipeTo(
998
+ new WritableStream({
999
+ async write(chunk) {
1000
+ try {
1001
+ const text = new TextDecoder().decode(chunk);
1002
+ if (text.includes("[DONE]")) {
1003
+ return;
1004
+ }
1005
+ } catch {
1006
+ }
1007
+ const writer = writable.getWriter();
1008
+ try {
1009
+ await writer.write(chunk);
1010
+ } finally {
1011
+ writer.releaseLock();
1012
+ }
1013
+ }
1014
+ }),
1015
+ {
1016
+ preventClose: true
1017
+ }
1018
+ ).catch((error) => {
954
1019
  console.error("Error piping to writable stream:", error);
955
1020
  });
956
1021
  this.processChatResponse_vNext({
@@ -980,14 +1045,17 @@ var Agent = class extends BaseResource {
980
1045
  threadId: processedParams.threadId,
981
1046
  runtimeContext: processedParams.runtimeContext,
982
1047
  // TODO: Pass proper tracing context when client-js supports tracing
983
- tracingContext: { currentSpan: void 0 }
1048
+ tracingContext: { currentSpan: void 0 },
1049
+ suspend: async () => {
1050
+ }
984
1051
  },
985
1052
  {
986
1053
  messages: response.messages,
987
1054
  toolCallId: toolCall2?.toolCallId
988
1055
  }
989
1056
  );
990
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1057
+ const lastMessageRaw = messages[messages.length - 1];
1058
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
991
1059
  const toolInvocationPart = lastMessage?.parts?.find(
992
1060
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
993
1061
  );
@@ -1005,25 +1073,11 @@ var Agent = class extends BaseResource {
1005
1073
  toolInvocation.state = "result";
1006
1074
  toolInvocation.result = result;
1007
1075
  }
1008
- const writer = writable.getWriter();
1009
- try {
1010
- await writer.write(
1011
- new TextEncoder().encode(
1012
- "a:" + JSON.stringify({
1013
- toolCallId: toolCall2.toolCallId,
1014
- result
1015
- }) + "\n"
1016
- )
1017
- );
1018
- } finally {
1019
- writer.releaseLock();
1020
- }
1021
- const originalMessages = processedParams.messages;
1022
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1076
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1023
1077
  this.processStreamResponse_vNext(
1024
1078
  {
1025
1079
  ...processedParams,
1026
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1080
+ messages: updatedMessages
1027
1081
  },
1028
1082
  writable
1029
1083
  ).catch((error) => {
@@ -1046,12 +1100,49 @@ var Agent = class extends BaseResource {
1046
1100
  }
1047
1101
  return response;
1048
1102
  }
1049
- async streamVNext(params) {
1103
+ async network(params) {
1104
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1105
+ method: "POST",
1106
+ body: params,
1107
+ stream: true
1108
+ });
1109
+ if (!response.body) {
1110
+ throw new Error("No response body");
1111
+ }
1112
+ const streamResponse = new Response(response.body, {
1113
+ status: response.status,
1114
+ statusText: response.statusText,
1115
+ headers: response.headers
1116
+ });
1117
+ streamResponse.processDataStream = async ({
1118
+ onChunk
1119
+ }) => {
1120
+ await processMastraNetworkStream({
1121
+ stream: streamResponse.body,
1122
+ onChunk
1123
+ });
1124
+ };
1125
+ return streamResponse;
1126
+ }
1127
+ async streamVNext(messagesOrParams, options) {
1128
+ let params;
1129
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1130
+ params = messagesOrParams;
1131
+ } else {
1132
+ params = {
1133
+ messages: messagesOrParams,
1134
+ ...options
1135
+ };
1136
+ }
1050
1137
  const processedParams = {
1051
1138
  ...params,
1052
1139
  output: params.output ? zodToJsonSchema(params.output) : void 0,
1053
1140
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1054
- clientTools: processClientTools(params.clientTools)
1141
+ clientTools: processClientTools(params.clientTools),
1142
+ structuredOutput: params.structuredOutput ? {
1143
+ ...params.structuredOutput,
1144
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1145
+ } : void 0
1055
1146
  };
1056
1147
  const { readable, writable } = new TransformStream();
1057
1148
  const response = await this.processStreamResponse_vNext(processedParams, writable);
@@ -1118,7 +1209,9 @@ var Agent = class extends BaseResource {
1118
1209
  threadId: processedParams.threadId,
1119
1210
  runtimeContext: processedParams.runtimeContext,
1120
1211
  // TODO: Pass proper tracing context when client-js supports tracing
1121
- tracingContext: { currentSpan: void 0 }
1212
+ tracingContext: { currentSpan: void 0 },
1213
+ suspend: async () => {
1214
+ }
1122
1215
  },
1123
1216
  {
1124
1217
  messages: response.messages,
@@ -1156,12 +1249,10 @@ var Agent = class extends BaseResource {
1156
1249
  } finally {
1157
1250
  writer.releaseLock();
1158
1251
  }
1159
- const originalMessages = processedParams.messages;
1160
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1161
1252
  this.processStreamResponse(
1162
1253
  {
1163
1254
  ...processedParams,
1164
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1255
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1165
1256
  },
1166
1257
  writable
1167
1258
  ).catch((error) => {
@@ -1187,10 +1278,11 @@ var Agent = class extends BaseResource {
1187
1278
  /**
1188
1279
  * Gets details about a specific tool available to the agent
1189
1280
  * @param toolId - ID of the tool to retrieve
1281
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1190
1282
  * @returns Promise containing tool details
1191
1283
  */
1192
- getTool(toolId) {
1193
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1284
+ getTool(toolId, runtimeContext) {
1285
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1194
1286
  }
1195
1287
  /**
1196
1288
  * Executes a tool for the agent
@@ -1201,7 +1293,7 @@ var Agent = class extends BaseResource {
1201
1293
  executeTool(toolId, params) {
1202
1294
  const body = {
1203
1295
  data: params.data,
1204
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1296
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1205
1297
  };
1206
1298
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1207
1299
  method: "POST",
@@ -1210,17 +1302,19 @@ var Agent = class extends BaseResource {
1210
1302
  }
1211
1303
  /**
1212
1304
  * Retrieves evaluation results for the agent
1305
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1213
1306
  * @returns Promise containing agent evaluations
1214
1307
  */
1215
- evals() {
1216
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1308
+ evals(runtimeContext) {
1309
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1217
1310
  }
1218
1311
  /**
1219
1312
  * Retrieves live evaluation results for the agent
1313
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1220
1314
  * @returns Promise containing live agent evaluations
1221
1315
  */
1222
- liveEvals() {
1223
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1316
+ liveEvals(runtimeContext) {
1317
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1224
1318
  }
1225
1319
  /**
1226
1320
  * Updates the model for the agent
@@ -1233,61 +1327,27 @@ var Agent = class extends BaseResource {
1233
1327
  body: params
1234
1328
  });
1235
1329
  }
1236
- };
1237
- var Network = class extends BaseResource {
1238
- constructor(options, networkId) {
1239
- super(options);
1240
- this.networkId = networkId;
1241
- }
1242
1330
  /**
1243
- * Retrieves details about the network
1244
- * @returns Promise containing network details
1245
- */
1246
- details() {
1247
- return this.request(`/api/networks/${this.networkId}`);
1248
- }
1249
- /**
1250
- * Generates a response from the agent
1251
- * @param params - Generation parameters including prompt
1252
- * @returns Promise containing the generated response
1331
+ * Updates the model for the agent in the model list
1332
+ * @param params - Parameters for updating the model
1333
+ * @returns Promise containing the updated model
1253
1334
  */
1254
- generate(params) {
1255
- const processedParams = {
1256
- ...params,
1257
- output: zodToJsonSchema(params.output),
1258
- experimental_output: zodToJsonSchema(params.experimental_output)
1259
- };
1260
- return this.request(`/api/networks/${this.networkId}/generate`, {
1335
+ updateModelInModelList({ modelConfigId, ...params }) {
1336
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1261
1337
  method: "POST",
1262
- body: processedParams
1338
+ body: params
1263
1339
  });
1264
1340
  }
1265
1341
  /**
1266
- * Streams a response from the agent
1267
- * @param params - Stream parameters including prompt
1268
- * @returns Promise containing the enhanced Response object with processDataStream method
1342
+ * Reorders the models for the agent
1343
+ * @param params - Parameters for reordering the model list
1344
+ * @returns Promise containing the updated model list
1269
1345
  */
1270
- async stream(params) {
1271
- const processedParams = {
1272
- ...params,
1273
- output: zodToJsonSchema(params.output),
1274
- experimental_output: zodToJsonSchema(params.experimental_output)
1275
- };
1276
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1346
+ reorderModelList(params) {
1347
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1277
1348
  method: "POST",
1278
- body: processedParams,
1279
- stream: true
1349
+ body: params
1280
1350
  });
1281
- if (!response.body) {
1282
- throw new Error("No response body");
1283
- }
1284
- response.processDataStream = async (options = {}) => {
1285
- await processDataStream({
1286
- stream: response.body,
1287
- ...options
1288
- });
1289
- };
1290
- return response;
1291
1351
  }
1292
1352
  };
1293
1353
 
@@ -1378,10 +1438,13 @@ var Vector = class extends BaseResource {
1378
1438
  /**
1379
1439
  * Retrieves details about a specific vector index
1380
1440
  * @param indexName - Name of the index to get details for
1441
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1381
1442
  * @returns Promise containing vector index details
1382
1443
  */
1383
- details(indexName) {
1384
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1444
+ details(indexName, runtimeContext) {
1445
+ return this.request(
1446
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1447
+ );
1385
1448
  }
1386
1449
  /**
1387
1450
  * Deletes a vector index
@@ -1395,10 +1458,11 @@ var Vector = class extends BaseResource {
1395
1458
  }
1396
1459
  /**
1397
1460
  * Retrieves a list of all available indexes
1461
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1398
1462
  * @returns Promise containing array of index names
1399
1463
  */
1400
- getIndexes() {
1401
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1464
+ getIndexes(runtimeContext) {
1465
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1402
1466
  }
1403
1467
  /**
1404
1468
  * Creates a new vector index
@@ -1435,187 +1499,6 @@ var Vector = class extends BaseResource {
1435
1499
  }
1436
1500
  };
1437
1501
 
1438
- // src/resources/legacy-workflow.ts
1439
- var RECORD_SEPARATOR = "";
1440
- var LegacyWorkflow = class extends BaseResource {
1441
- constructor(options, workflowId) {
1442
- super(options);
1443
- this.workflowId = workflowId;
1444
- }
1445
- /**
1446
- * Retrieves details about the legacy workflow
1447
- * @returns Promise containing legacy workflow details including steps and graphs
1448
- */
1449
- details() {
1450
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1451
- }
1452
- /**
1453
- * Retrieves all runs for a legacy workflow
1454
- * @param params - Parameters for filtering runs
1455
- * @returns Promise containing legacy workflow runs array
1456
- */
1457
- runs(params) {
1458
- const searchParams = new URLSearchParams();
1459
- if (params?.fromDate) {
1460
- searchParams.set("fromDate", params.fromDate.toISOString());
1461
- }
1462
- if (params?.toDate) {
1463
- searchParams.set("toDate", params.toDate.toISOString());
1464
- }
1465
- if (params?.limit) {
1466
- searchParams.set("limit", String(params.limit));
1467
- }
1468
- if (params?.offset) {
1469
- searchParams.set("offset", String(params.offset));
1470
- }
1471
- if (params?.resourceId) {
1472
- searchParams.set("resourceId", params.resourceId);
1473
- }
1474
- if (searchParams.size) {
1475
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1476
- } else {
1477
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1478
- }
1479
- }
1480
- /**
1481
- * Creates a new legacy workflow run
1482
- * @returns Promise containing the generated run ID
1483
- */
1484
- createRun(params) {
1485
- const searchParams = new URLSearchParams();
1486
- if (!!params?.runId) {
1487
- searchParams.set("runId", params.runId);
1488
- }
1489
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1490
- method: "POST"
1491
- });
1492
- }
1493
- /**
1494
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1495
- * @param params - Object containing the runId and triggerData
1496
- * @returns Promise containing success message
1497
- */
1498
- start(params) {
1499
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1500
- method: "POST",
1501
- body: params?.triggerData
1502
- });
1503
- }
1504
- /**
1505
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1506
- * @param stepId - ID of the step to resume
1507
- * @param runId - ID of the legacy workflow run
1508
- * @param context - Context to resume the legacy workflow with
1509
- * @returns Promise containing the legacy workflow resume results
1510
- */
1511
- resume({
1512
- stepId,
1513
- runId,
1514
- context
1515
- }) {
1516
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1517
- method: "POST",
1518
- body: {
1519
- stepId,
1520
- context
1521
- }
1522
- });
1523
- }
1524
- /**
1525
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1526
- * @param params - Object containing the optional runId and triggerData
1527
- * @returns Promise containing the workflow execution results
1528
- */
1529
- startAsync(params) {
1530
- const searchParams = new URLSearchParams();
1531
- if (!!params?.runId) {
1532
- searchParams.set("runId", params.runId);
1533
- }
1534
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1535
- method: "POST",
1536
- body: params?.triggerData
1537
- });
1538
- }
1539
- /**
1540
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1541
- * @param params - Object containing the runId, stepId, and context
1542
- * @returns Promise containing the workflow resume results
1543
- */
1544
- resumeAsync(params) {
1545
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1546
- method: "POST",
1547
- body: {
1548
- stepId: params.stepId,
1549
- context: params.context
1550
- }
1551
- });
1552
- }
1553
- /**
1554
- * Creates an async generator that processes a readable stream and yields records
1555
- * separated by the Record Separator character (\x1E)
1556
- *
1557
- * @param stream - The readable stream to process
1558
- * @returns An async generator that yields parsed records
1559
- */
1560
- async *streamProcessor(stream) {
1561
- const reader = stream.getReader();
1562
- let doneReading = false;
1563
- let buffer = "";
1564
- try {
1565
- while (!doneReading) {
1566
- const { done, value } = await reader.read();
1567
- doneReading = done;
1568
- if (done && !value) continue;
1569
- try {
1570
- const decoded = value ? new TextDecoder().decode(value) : "";
1571
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1572
- buffer = chunks.pop() || "";
1573
- for (const chunk of chunks) {
1574
- if (chunk) {
1575
- if (typeof chunk === "string") {
1576
- try {
1577
- const parsedChunk = JSON.parse(chunk);
1578
- yield parsedChunk;
1579
- } catch {
1580
- }
1581
- }
1582
- }
1583
- }
1584
- } catch {
1585
- }
1586
- }
1587
- if (buffer) {
1588
- try {
1589
- yield JSON.parse(buffer);
1590
- } catch {
1591
- }
1592
- }
1593
- } finally {
1594
- reader.cancel().catch(() => {
1595
- });
1596
- }
1597
- }
1598
- /**
1599
- * Watches legacy workflow transitions in real-time
1600
- * @param runId - Optional run ID to filter the watch stream
1601
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1602
- */
1603
- async watch({ runId }, onRecord) {
1604
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1605
- stream: true
1606
- });
1607
- if (!response.ok) {
1608
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1609
- }
1610
- if (!response.body) {
1611
- throw new Error("Response body is null");
1612
- }
1613
- for await (const record of this.streamProcessor(response.body)) {
1614
- onRecord(record);
1615
- }
1616
- }
1617
- };
1618
-
1619
1502
  // src/resources/tool.ts
1620
1503
  var Tool = class extends BaseResource {
1621
1504
  constructor(options, toolId) {
@@ -1624,10 +1507,11 @@ var Tool = class extends BaseResource {
1624
1507
  }
1625
1508
  /**
1626
1509
  * Retrieves details about the tool
1510
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1627
1511
  * @returns Promise containing tool details including description and schemas
1628
1512
  */
1629
- details() {
1630
- return this.request(`/api/tools/${this.toolId}`);
1513
+ details(runtimeContext) {
1514
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1631
1515
  }
1632
1516
  /**
1633
1517
  * Executes the tool with the provided parameters
@@ -1651,7 +1535,7 @@ var Tool = class extends BaseResource {
1651
1535
  };
1652
1536
 
1653
1537
  // src/resources/workflow.ts
1654
- var RECORD_SEPARATOR2 = "";
1538
+ var RECORD_SEPARATOR = "";
1655
1539
  var Workflow = class extends BaseResource {
1656
1540
  constructor(options, workflowId) {
1657
1541
  super(options);
@@ -1675,7 +1559,7 @@ var Workflow = class extends BaseResource {
1675
1559
  if (done && !value) continue;
1676
1560
  try {
1677
1561
  const decoded = value ? new TextDecoder().decode(value) : "";
1678
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1562
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1679
1563
  buffer = chunks.pop() || "";
1680
1564
  for (const chunk of chunks) {
1681
1565
  if (chunk) {
@@ -1704,17 +1588,20 @@ var Workflow = class extends BaseResource {
1704
1588
  }
1705
1589
  /**
1706
1590
  * Retrieves details about the workflow
1591
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1707
1592
  * @returns Promise containing workflow details including steps and graphs
1708
1593
  */
1709
- details() {
1710
- return this.request(`/api/workflows/${this.workflowId}`);
1594
+ details(runtimeContext) {
1595
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1711
1596
  }
1712
1597
  /**
1713
1598
  * Retrieves all runs for a workflow
1714
1599
  * @param params - Parameters for filtering runs
1600
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1715
1601
  * @returns Promise containing workflow runs array
1716
1602
  */
1717
- runs(params) {
1603
+ runs(params, runtimeContext) {
1604
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1718
1605
  const searchParams = new URLSearchParams();
1719
1606
  if (params?.fromDate) {
1720
1607
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1731,6 +1618,9 @@ var Workflow = class extends BaseResource {
1731
1618
  if (params?.resourceId) {
1732
1619
  searchParams.set("resourceId", params.resourceId);
1733
1620
  }
1621
+ if (runtimeContextParam) {
1622
+ searchParams.set("runtimeContext", runtimeContextParam);
1623
+ }
1734
1624
  if (searchParams.size) {
1735
1625
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1736
1626
  } else {
@@ -1740,18 +1630,22 @@ var Workflow = class extends BaseResource {
1740
1630
  /**
1741
1631
  * Retrieves a specific workflow run by its ID
1742
1632
  * @param runId - The ID of the workflow run to retrieve
1633
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1743
1634
  * @returns Promise containing the workflow run details
1744
1635
  */
1745
- runById(runId) {
1746
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1636
+ runById(runId, runtimeContext) {
1637
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1747
1638
  }
1748
1639
  /**
1749
1640
  * Retrieves the execution result for a specific workflow run by its ID
1750
1641
  * @param runId - The ID of the workflow run to retrieve the execution result for
1642
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1751
1643
  * @returns Promise containing the workflow run execution result
1752
1644
  */
1753
- runExecutionResult(runId) {
1754
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1645
+ runExecutionResult(runId, runtimeContext) {
1646
+ return this.request(
1647
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1648
+ );
1755
1649
  }
1756
1650
  /**
1757
1651
  * Cancels a specific workflow run by its ID
@@ -1774,27 +1668,61 @@ var Workflow = class extends BaseResource {
1774
1668
  body: { event: params.event, data: params.data }
1775
1669
  });
1776
1670
  }
1671
+ /**
1672
+ * @deprecated Use createRunAsync() instead.
1673
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1674
+ */
1675
+ async createRun(_params) {
1676
+ throw new Error(
1677
+ "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."
1678
+ );
1679
+ }
1777
1680
  /**
1778
1681
  * Creates a new workflow run
1779
1682
  * @param params - Optional object containing the optional runId
1780
- * @returns Promise containing the runId of the created run
1683
+ * @returns Promise containing the runId of the created run with methods to control execution
1781
1684
  */
1782
- createRun(params) {
1685
+ async createRunAsync(params) {
1783
1686
  const searchParams = new URLSearchParams();
1784
1687
  if (!!params?.runId) {
1785
1688
  searchParams.set("runId", params.runId);
1786
1689
  }
1787
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1788
- method: "POST"
1789
- });
1790
- }
1791
- /**
1792
- * Creates a new workflow run (alias for createRun)
1793
- * @param params - Optional object containing the optional runId
1794
- * @returns Promise containing the runId of the created run
1795
- */
1796
- createRunAsync(params) {
1797
- return this.createRun(params);
1690
+ const res = await this.request(
1691
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1692
+ {
1693
+ method: "POST"
1694
+ }
1695
+ );
1696
+ const runId = res.runId;
1697
+ return {
1698
+ runId,
1699
+ start: async (p) => {
1700
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1701
+ },
1702
+ startAsync: async (p) => {
1703
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1704
+ },
1705
+ watch: async (onRecord) => {
1706
+ return this.watch({ runId }, onRecord);
1707
+ },
1708
+ stream: async (p) => {
1709
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1710
+ },
1711
+ resume: async (p) => {
1712
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1713
+ },
1714
+ resumeAsync: async (p) => {
1715
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1716
+ },
1717
+ resumeStreamVNext: async (p) => {
1718
+ return this.resumeStreamVNext({
1719
+ runId,
1720
+ step: p.step,
1721
+ resumeData: p.resumeData,
1722
+ runtimeContext: p.runtimeContext
1723
+ });
1724
+ }
1725
+ };
1798
1726
  }
1799
1727
  /**
1800
1728
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1822,7 +1750,6 @@ var Workflow = class extends BaseResource {
1822
1750
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1823
1751
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1824
1752
  method: "POST",
1825
- stream: true,
1826
1753
  body: {
1827
1754
  step,
1828
1755
  resumeData,
@@ -1865,6 +1792,104 @@ var Workflow = class extends BaseResource {
1865
1792
  stream: true
1866
1793
  }
1867
1794
  );
1795
+ if (!response.ok) {
1796
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1797
+ }
1798
+ if (!response.body) {
1799
+ throw new Error("Response body is null");
1800
+ }
1801
+ let failedChunk = void 0;
1802
+ const transformStream = new TransformStream({
1803
+ start() {
1804
+ },
1805
+ async transform(chunk, controller) {
1806
+ try {
1807
+ const decoded = new TextDecoder().decode(chunk);
1808
+ const chunks = decoded.split(RECORD_SEPARATOR);
1809
+ for (const chunk2 of chunks) {
1810
+ if (chunk2) {
1811
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1812
+ try {
1813
+ const parsedChunk = JSON.parse(newChunk);
1814
+ controller.enqueue(parsedChunk);
1815
+ failedChunk = void 0;
1816
+ } catch {
1817
+ failedChunk = newChunk;
1818
+ }
1819
+ }
1820
+ }
1821
+ } catch {
1822
+ }
1823
+ }
1824
+ });
1825
+ return response.body.pipeThrough(transformStream);
1826
+ }
1827
+ /**
1828
+ * Observes workflow stream for a workflow run
1829
+ * @param params - Object containing the runId
1830
+ * @returns Promise containing the workflow execution results
1831
+ */
1832
+ async observeStream(params) {
1833
+ const searchParams = new URLSearchParams();
1834
+ searchParams.set("runId", params.runId);
1835
+ const response = await this.request(
1836
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1837
+ {
1838
+ method: "POST",
1839
+ stream: true
1840
+ }
1841
+ );
1842
+ if (!response.ok) {
1843
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1844
+ }
1845
+ if (!response.body) {
1846
+ throw new Error("Response body is null");
1847
+ }
1848
+ let failedChunk = void 0;
1849
+ const transformStream = new TransformStream({
1850
+ start() {
1851
+ },
1852
+ async transform(chunk, controller) {
1853
+ try {
1854
+ const decoded = new TextDecoder().decode(chunk);
1855
+ const chunks = decoded.split(RECORD_SEPARATOR);
1856
+ for (const chunk2 of chunks) {
1857
+ if (chunk2) {
1858
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1859
+ try {
1860
+ const parsedChunk = JSON.parse(newChunk);
1861
+ controller.enqueue(parsedChunk);
1862
+ failedChunk = void 0;
1863
+ } catch {
1864
+ failedChunk = newChunk;
1865
+ }
1866
+ }
1867
+ }
1868
+ } catch {
1869
+ }
1870
+ }
1871
+ });
1872
+ return response.body.pipeThrough(transformStream);
1873
+ }
1874
+ /**
1875
+ * Starts a workflow run and returns a stream
1876
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1877
+ * @returns Promise containing the workflow execution results
1878
+ */
1879
+ async streamVNext(params) {
1880
+ const searchParams = new URLSearchParams();
1881
+ if (!!params?.runId) {
1882
+ searchParams.set("runId", params.runId);
1883
+ }
1884
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1885
+ const response = await this.request(
1886
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1887
+ {
1888
+ method: "POST",
1889
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1890
+ stream: true
1891
+ }
1892
+ );
1868
1893
  if (!response.ok) {
1869
1894
  throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1870
1895
  }
@@ -1878,7 +1903,7 @@ var Workflow = class extends BaseResource {
1878
1903
  async transform(chunk, controller) {
1879
1904
  try {
1880
1905
  const decoded = new TextDecoder().decode(chunk);
1881
- const chunks = decoded.split(RECORD_SEPARATOR2);
1906
+ const chunks = decoded.split(RECORD_SEPARATOR);
1882
1907
  for (const chunk2 of chunks) {
1883
1908
  if (chunk2) {
1884
1909
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1913,6 +1938,22 @@ var Workflow = class extends BaseResource {
1913
1938
  }
1914
1939
  });
1915
1940
  }
1941
+ /**
1942
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
1943
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
1944
+ * @returns Promise containing the workflow resume results
1945
+ */
1946
+ resumeStreamVNext(params) {
1947
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1948
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1949
+ method: "POST",
1950
+ body: {
1951
+ step: params.step,
1952
+ resumeData: params.resumeData,
1953
+ runtimeContext
1954
+ }
1955
+ });
1956
+ }
1916
1957
  /**
1917
1958
  * Watches workflow transitions in real-time
1918
1959
  * @param runId - Optional run ID to filter the watch stream
@@ -1949,7 +1990,7 @@ var Workflow = class extends BaseResource {
1949
1990
  async start(controller) {
1950
1991
  try {
1951
1992
  for await (const record of records) {
1952
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1993
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
1953
1994
  controller.enqueue(encoder.encode(json));
1954
1995
  }
1955
1996
  controller.close();
@@ -2047,10 +2088,11 @@ var MCPTool = class extends BaseResource {
2047
2088
  }
2048
2089
  /**
2049
2090
  * Retrieves details about this specific tool from the MCP server.
2091
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2050
2092
  * @returns Promise containing the tool's information (name, description, schema).
2051
2093
  */
2052
- details() {
2053
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2094
+ details(runtimeContext) {
2095
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2054
2096
  }
2055
2097
  /**
2056
2098
  * Executes this specific tool on the MCP server.
@@ -2071,7 +2113,7 @@ var MCPTool = class extends BaseResource {
2071
2113
  };
2072
2114
 
2073
2115
  // src/resources/agent-builder.ts
2074
- var RECORD_SEPARATOR3 = "";
2116
+ var RECORD_SEPARATOR2 = "";
2075
2117
  var AgentBuilder = class extends BaseResource {
2076
2118
  constructor(options, actionId) {
2077
2119
  super(options);
@@ -2106,11 +2148,20 @@ var AgentBuilder = class extends BaseResource {
2106
2148
  };
2107
2149
  }
2108
2150
  }
2151
+ /**
2152
+ * @deprecated Use createRunAsync() instead.
2153
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2154
+ */
2155
+ async createRun(_params) {
2156
+ throw new Error(
2157
+ "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."
2158
+ );
2159
+ }
2109
2160
  /**
2110
2161
  * Creates a new agent builder action run and returns the runId.
2111
2162
  * This calls `/api/agent-builder/:actionId/create-run`.
2112
2163
  */
2113
- async createRun(params) {
2164
+ async createRunAsync(params) {
2114
2165
  const searchParams = new URLSearchParams();
2115
2166
  if (!!params?.runId) {
2116
2167
  searchParams.set("runId", params.runId);
@@ -2120,14 +2171,6 @@ var AgentBuilder = class extends BaseResource {
2120
2171
  method: "POST"
2121
2172
  });
2122
2173
  }
2123
- /**
2124
- * Creates a new workflow run (alias for createRun)
2125
- * @param params - Optional object containing the optional runId
2126
- * @returns Promise containing the runId of the created run
2127
- */
2128
- createRunAsync(params) {
2129
- return this.createRun(params);
2130
- }
2131
2174
  /**
2132
2175
  * Starts agent builder action asynchronously and waits for completion.
2133
2176
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2210,7 +2253,7 @@ var AgentBuilder = class extends BaseResource {
2210
2253
  if (done && !value) continue;
2211
2254
  try {
2212
2255
  const decoded = value ? new TextDecoder().decode(value) : "";
2213
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2256
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2214
2257
  buffer = chunks.pop() || "";
2215
2258
  for (const chunk of chunks) {
2216
2259
  if (chunk) {
@@ -2267,7 +2310,7 @@ var AgentBuilder = class extends BaseResource {
2267
2310
  async transform(chunk, controller) {
2268
2311
  try {
2269
2312
  const decoded = new TextDecoder().decode(chunk);
2270
- const chunks = decoded.split(RECORD_SEPARATOR3);
2313
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2271
2314
  for (const chunk2 of chunks) {
2272
2315
  if (chunk2) {
2273
2316
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2316,7 +2359,7 @@ var AgentBuilder = class extends BaseResource {
2316
2359
  async transform(chunk, controller) {
2317
2360
  try {
2318
2361
  const decoded = new TextDecoder().decode(chunk);
2319
- const chunks = decoded.split(RECORD_SEPARATOR3);
2362
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2320
2363
  for (const chunk2 of chunks) {
2321
2364
  if (chunk2) {
2322
2365
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2459,7 +2502,7 @@ var Observability = class extends BaseResource {
2459
2502
  getTraces(params) {
2460
2503
  const { pagination, filters } = params;
2461
2504
  const { page, perPage, dateRange } = pagination || {};
2462
- const { name, spanType } = filters || {};
2505
+ const { name, spanType, entityId, entityType } = filters || {};
2463
2506
  const searchParams = new URLSearchParams();
2464
2507
  if (page !== void 0) {
2465
2508
  searchParams.set("page", String(page));
@@ -2473,6 +2516,10 @@ var Observability = class extends BaseResource {
2473
2516
  if (spanType !== void 0) {
2474
2517
  searchParams.set("spanType", String(spanType));
2475
2518
  }
2519
+ if (entityId && entityType) {
2520
+ searchParams.set("entityId", entityId);
2521
+ searchParams.set("entityType", entityType);
2522
+ }
2476
2523
  if (dateRange) {
2477
2524
  const dateRangeStr = JSON.stringify({
2478
2525
  start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
@@ -2483,6 +2530,12 @@ var Observability = class extends BaseResource {
2483
2530
  const queryString = searchParams.toString();
2484
2531
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2485
2532
  }
2533
+ score(params) {
2534
+ return this.request(`/api/observability/traces/score`, {
2535
+ method: "POST",
2536
+ body: { ...params }
2537
+ });
2538
+ }
2486
2539
  };
2487
2540
 
2488
2541
  // src/resources/network-memory-thread.ts
@@ -2549,7 +2602,7 @@ var NetworkMemoryThread = class extends BaseResource {
2549
2602
  };
2550
2603
 
2551
2604
  // src/resources/vNextNetwork.ts
2552
- var RECORD_SEPARATOR4 = "";
2605
+ var RECORD_SEPARATOR3 = "";
2553
2606
  var VNextNetwork = class extends BaseResource {
2554
2607
  constructor(options, networkId) {
2555
2608
  super(options);
@@ -2557,10 +2610,11 @@ var VNextNetwork = class extends BaseResource {
2557
2610
  }
2558
2611
  /**
2559
2612
  * Retrieves details about the network
2613
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2560
2614
  * @returns Promise containing vNext network details
2561
2615
  */
2562
- details() {
2563
- return this.request(`/api/networks/v-next/${this.networkId}`);
2616
+ details(runtimeContext) {
2617
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2564
2618
  }
2565
2619
  /**
2566
2620
  * Generates a response from the v-next network
@@ -2601,7 +2655,7 @@ var VNextNetwork = class extends BaseResource {
2601
2655
  if (done && !value) continue;
2602
2656
  try {
2603
2657
  const decoded = value ? new TextDecoder().decode(value) : "";
2604
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2658
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2605
2659
  buffer = chunks.pop() || "";
2606
2660
  for (const chunk of chunks) {
2607
2661
  if (chunk) {
@@ -2695,10 +2749,17 @@ var MastraClient = class extends BaseResource {
2695
2749
  }
2696
2750
  /**
2697
2751
  * Retrieves all available agents
2752
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2698
2753
  * @returns Promise containing map of agent IDs to agent details
2699
2754
  */
2700
- getAgents() {
2701
- return this.request("/api/agents");
2755
+ getAgents(runtimeContext) {
2756
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2757
+ const searchParams = new URLSearchParams();
2758
+ if (runtimeContextParam) {
2759
+ searchParams.set("runtimeContext", runtimeContextParam);
2760
+ }
2761
+ const queryString = searchParams.toString();
2762
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2702
2763
  }
2703
2764
  /**
2704
2765
  * Gets an agent instance by ID
@@ -2716,6 +2777,14 @@ var MastraClient = class extends BaseResource {
2716
2777
  getMemoryThreads(params) {
2717
2778
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2718
2779
  }
2780
+ /**
2781
+ * Retrieves memory config for a resource
2782
+ * @param params - Parameters containing the resource ID
2783
+ * @returns Promise containing array of memory threads
2784
+ */
2785
+ getMemoryConfig(params) {
2786
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2787
+ }
2719
2788
  /**
2720
2789
  * Creates a new memory thread
2721
2790
  * @param params - Parameters for creating the memory thread
@@ -2732,6 +2801,24 @@ var MastraClient = class extends BaseResource {
2732
2801
  getMemoryThread(threadId, agentId) {
2733
2802
  return new MemoryThread(this.options, threadId, agentId);
2734
2803
  }
2804
+ getThreadMessages(threadId, opts = {}) {
2805
+ let url = "";
2806
+ if (opts.agentId) {
2807
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2808
+ } else if (opts.networkId) {
2809
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2810
+ }
2811
+ return this.request(url);
2812
+ }
2813
+ deleteThread(threadId, opts = {}) {
2814
+ let url = "";
2815
+ if (opts.agentId) {
2816
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2817
+ } else if (opts.networkId) {
2818
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2819
+ }
2820
+ return this.request(url, { method: "DELETE" });
2821
+ }
2735
2822
  /**
2736
2823
  * Saves messages to memory
2737
2824
  * @param params - Parameters containing messages to save
@@ -2794,10 +2881,17 @@ var MastraClient = class extends BaseResource {
2794
2881
  }
2795
2882
  /**
2796
2883
  * Retrieves all available tools
2884
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2797
2885
  * @returns Promise containing map of tool IDs to tool details
2798
2886
  */
2799
- getTools() {
2800
- return this.request("/api/tools");
2887
+ getTools(runtimeContext) {
2888
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2889
+ const searchParams = new URLSearchParams();
2890
+ if (runtimeContextParam) {
2891
+ searchParams.set("runtimeContext", runtimeContextParam);
2892
+ }
2893
+ const queryString = searchParams.toString();
2894
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2801
2895
  }
2802
2896
  /**
2803
2897
  * Gets a tool instance by ID
@@ -2807,27 +2901,19 @@ var MastraClient = class extends BaseResource {
2807
2901
  getTool(toolId) {
2808
2902
  return new Tool(this.options, toolId);
2809
2903
  }
2810
- /**
2811
- * Retrieves all available legacy workflows
2812
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
2813
- */
2814
- getLegacyWorkflows() {
2815
- return this.request("/api/workflows/legacy");
2816
- }
2817
- /**
2818
- * Gets a legacy workflow instance by ID
2819
- * @param workflowId - ID of the legacy workflow to retrieve
2820
- * @returns Legacy Workflow instance
2821
- */
2822
- getLegacyWorkflow(workflowId) {
2823
- return new LegacyWorkflow(this.options, workflowId);
2824
- }
2825
2904
  /**
2826
2905
  * Retrieves all available workflows
2906
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2827
2907
  * @returns Promise containing map of workflow IDs to workflow details
2828
2908
  */
2829
- getWorkflows() {
2830
- return this.request("/api/workflows");
2909
+ getWorkflows(runtimeContext) {
2910
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2911
+ const searchParams = new URLSearchParams();
2912
+ if (runtimeContextParam) {
2913
+ searchParams.set("runtimeContext", runtimeContextParam);
2914
+ }
2915
+ const queryString = searchParams.toString();
2916
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2831
2917
  }
2832
2918
  /**
2833
2919
  * Gets a workflow instance by ID
@@ -2995,13 +3081,6 @@ var MastraClient = class extends BaseResource {
2995
3081
  return this.request(`/api/telemetry`);
2996
3082
  }
2997
3083
  }
2998
- /**
2999
- * Retrieves all available networks
3000
- * @returns Promise containing map of network IDs to network details
3001
- */
3002
- getNetworks() {
3003
- return this.request("/api/networks");
3004
- }
3005
3084
  /**
3006
3085
  * Retrieves all available vNext networks
3007
3086
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -3009,14 +3088,6 @@ var MastraClient = class extends BaseResource {
3009
3088
  getVNextNetworks() {
3010
3089
  return this.request("/api/networks/v-next");
3011
3090
  }
3012
- /**
3013
- * Gets a network instance by ID
3014
- * @param networkId - ID of the network to retrieve
3015
- * @returns Network instance
3016
- */
3017
- getNetwork(networkId) {
3018
- return new Network(this.options, networkId);
3019
- }
3020
3091
  /**
3021
3092
  * Gets a vNext network instance by ID
3022
3093
  * @param networkId - ID of the vNext network to retrieve
@@ -3207,8 +3278,30 @@ var MastraClient = class extends BaseResource {
3207
3278
  getAITraces(params) {
3208
3279
  return this.observability.getTraces(params);
3209
3280
  }
3281
+ score(params) {
3282
+ return this.observability.score(params);
3283
+ }
3284
+ };
3285
+
3286
+ // src/tools.ts
3287
+ var ClientTool = class {
3288
+ id;
3289
+ description;
3290
+ inputSchema;
3291
+ outputSchema;
3292
+ execute;
3293
+ constructor(opts) {
3294
+ this.id = opts.id;
3295
+ this.description = opts.description;
3296
+ this.inputSchema = opts.inputSchema;
3297
+ this.outputSchema = opts.outputSchema;
3298
+ this.execute = opts.execute;
3299
+ }
3210
3300
  };
3301
+ function createTool(opts) {
3302
+ return new ClientTool(opts);
3303
+ }
3211
3304
 
3212
- export { MastraClient };
3305
+ export { ClientTool, MastraClient, createTool };
3213
3306
  //# sourceMappingURL=index.js.map
3214
3307
  //# sourceMappingURL=index.js.map