@mastra/client-js 0.0.0-pgvector-index-fix-20250905222058 → 0.0.0-playground-studio-cloud-20251031080052

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 +590 -10
  2. package/README.md +6 -10
  3. package/dist/client.d.ts +45 -45
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +802 -690
  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 +801 -691
  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 +91 -42
  14. package/dist/resources/agent.d.ts.map +1 -1
  15. package/dist/resources/index.d.ts +0 -2
  16. package/dist/resources/index.d.ts.map +1 -1
  17. package/dist/resources/mcp-tool.d.ts +2 -1
  18. package/dist/resources/mcp-tool.d.ts.map +1 -1
  19. package/dist/resources/observability.d.ts +17 -1
  20. package/dist/resources/observability.d.ts.map +1 -1
  21. package/dist/resources/tool.d.ts +2 -1
  22. package/dist/resources/tool.d.ts.map +1 -1
  23. package/dist/resources/vector.d.ts +5 -2
  24. package/dist/resources/vector.d.ts.map +1 -1
  25. package/dist/resources/workflow.d.ts +128 -13
  26. package/dist/resources/workflow.d.ts.map +1 -1
  27. package/dist/tools.d.ts +22 -0
  28. package/dist/tools.d.ts.map +1 -0
  29. package/dist/types.d.ts +105 -96
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/utils/index.d.ts +2 -0
  32. package/dist/utils/index.d.ts.map +1 -1
  33. package/dist/utils/process-mastra-stream.d.ts +5 -1
  34. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  35. package/package.json +6 -6
  36. package/dist/resources/legacy-workflow.d.ts +0 -87
  37. package/dist/resources/legacy-workflow.d.ts.map +0 -1
  38. package/dist/resources/network.d.ts +0 -30
  39. package/dist/resources/network.d.ts.map +0 -1
  40. package/dist/resources/vNextNetwork.d.ts +0 -42
  41. package/dist/resources/vNextNetwork.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var uiUtils = require('@ai-sdk/ui-utils');
4
4
  var uuid = require('@lukeed/uuid');
5
+ var error = require('@mastra/core/error');
5
6
  var runtimeContext = require('@mastra/core/runtime-context');
6
7
  var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
7
8
  var zod = require('zod');
@@ -21,6 +22,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
21
22
  }
22
23
  return void 0;
23
24
  }
25
+ function base64RuntimeContext(runtimeContext) {
26
+ if (runtimeContext) {
27
+ return btoa(JSON.stringify(runtimeContext));
28
+ }
29
+ return void 0;
30
+ }
31
+ function runtimeContextQueryString(runtimeContext) {
32
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
33
+ if (!runtimeContextParam) return "";
34
+ const searchParams = new URLSearchParams();
35
+ searchParams.set("runtimeContext", runtimeContextParam);
36
+ const queryString = searchParams.toString();
37
+ return queryString ? `?${queryString}` : "";
38
+ }
24
39
  function isZodType(value) {
25
40
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
26
41
  }
@@ -32,7 +47,7 @@ function zodToJsonSchema(zodSchema) {
32
47
  const fn = "toJSONSchema";
33
48
  return zod.z[fn].call(zod.z, zodSchema);
34
49
  }
35
- return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
50
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
36
51
  }
37
52
 
38
53
  // src/utils/process-client-tools.ts
@@ -65,7 +80,7 @@ function processClientTools(clientTools) {
65
80
  }
66
81
 
67
82
  // src/utils/process-mastra-stream.ts
68
- async function processMastraStream({
83
+ async function sharedProcessMastraStream({
69
84
  stream,
70
85
  onChunk
71
86
  }) {
@@ -83,14 +98,18 @@ async function processMastraStream({
83
98
  if (line.startsWith("data: ")) {
84
99
  const data = line.slice(6);
85
100
  if (data === "[DONE]") {
86
- console.log("\u{1F3C1} Stream finished");
101
+ console.info("\u{1F3C1} Stream finished");
87
102
  return;
88
103
  }
104
+ let json;
89
105
  try {
90
- const json = JSON.parse(data);
91
- await onChunk(json);
106
+ json = JSON.parse(data);
92
107
  } catch (error) {
93
108
  console.error("\u274C JSON parse error:", error, "Data:", data);
109
+ continue;
110
+ }
111
+ if (json) {
112
+ await onChunk(json);
94
113
  }
95
114
  }
96
115
  }
@@ -99,6 +118,24 @@ async function processMastraStream({
99
118
  reader.releaseLock();
100
119
  }
101
120
  }
121
+ async function processMastraNetworkStream({
122
+ stream,
123
+ onChunk
124
+ }) {
125
+ return sharedProcessMastraStream({
126
+ stream,
127
+ onChunk
128
+ });
129
+ }
130
+ async function processMastraStream({
131
+ stream,
132
+ onChunk
133
+ }) {
134
+ return sharedProcessMastraStream({
135
+ stream,
136
+ onChunk
137
+ });
138
+ }
102
139
 
103
140
  // src/resources/base.ts
104
141
  var BaseResource = class {
@@ -187,7 +224,9 @@ async function executeToolCallAndRespond({
187
224
  resourceId,
188
225
  threadId,
189
226
  runtimeContext,
190
- tracingContext: { currentSpan: void 0 }
227
+ tracingContext: { currentSpan: void 0 },
228
+ suspend: async () => {
229
+ }
191
230
  },
192
231
  {
193
232
  messages: response.messages,
@@ -195,11 +234,7 @@ async function executeToolCallAndRespond({
195
234
  }
196
235
  );
197
236
  const updatedMessages = [
198
- {
199
- role: "user",
200
- content: params.messages
201
- },
202
- ...response.response.messages,
237
+ ...response.response.messages || [],
203
238
  {
204
239
  role: "tool",
205
240
  content: [
@@ -261,17 +296,21 @@ var AgentVoice = class extends BaseResource {
261
296
  }
262
297
  /**
263
298
  * Get available speakers for the agent's voice provider
299
+ * @param runtimeContext - Optional runtime context to pass as query parameter
300
+ * @param runtimeContext - Optional runtime context to pass as query parameter
264
301
  * @returns Promise containing list of available speakers
265
302
  */
266
- getSpeakers() {
267
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
303
+ getSpeakers(runtimeContext) {
304
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
268
305
  }
269
306
  /**
270
307
  * Get the listener configuration for the agent's voice provider
308
+ * @param runtimeContext - Optional runtime context to pass as query parameter
309
+ * @param runtimeContext - Optional runtime context to pass as query parameter
271
310
  * @returns Promise containing a check if the agent has listening capabilities
272
311
  */
273
- getListener() {
274
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
312
+ getListener(runtimeContext) {
313
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
275
314
  }
276
315
  };
277
316
  var Agent = class extends BaseResource {
@@ -283,16 +322,17 @@ var Agent = class extends BaseResource {
283
322
  voice;
284
323
  /**
285
324
  * Retrieves details about the agent
325
+ * @param runtimeContext - Optional runtime context to pass as query parameter
286
326
  * @returns Promise containing agent details including model and instructions
287
327
  */
288
- details() {
289
- return this.request(`/api/agents/${this.agentId}`);
328
+ details(runtimeContext) {
329
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
290
330
  }
291
- async generate(params) {
292
- console.warn(
293
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
294
- );
295
- return this.generateLegacy(params);
331
+ enhanceInstructions(instructions, comment) {
332
+ return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
333
+ method: "POST",
334
+ body: { instructions, comment }
335
+ });
296
336
  }
297
337
  async generateLegacy(params) {
298
338
  const processedParams = {
@@ -325,7 +365,9 @@ var Agent = class extends BaseResource {
325
365
  resourceId,
326
366
  threadId,
327
367
  runtimeContext,
328
- tracingContext: { currentSpan: void 0 }
368
+ tracingContext: { currentSpan: void 0 },
369
+ suspend: async () => {
370
+ }
329
371
  },
330
372
  {
331
373
  messages: response.messages,
@@ -333,10 +375,6 @@ var Agent = class extends BaseResource {
333
375
  }
334
376
  );
335
377
  const updatedMessages = [
336
- {
337
- role: "user",
338
- content: params.messages
339
- },
340
378
  ...response.response.messages,
341
379
  {
342
380
  role: "tool",
@@ -359,16 +397,28 @@ var Agent = class extends BaseResource {
359
397
  }
360
398
  return response;
361
399
  }
362
- async generateVNext(params) {
400
+ async generate(messagesOrParams, options) {
401
+ let params;
402
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
403
+ params = messagesOrParams;
404
+ } else {
405
+ params = {
406
+ messages: messagesOrParams,
407
+ ...options
408
+ };
409
+ }
363
410
  const processedParams = {
364
411
  ...params,
365
- output: params.output ? zodToJsonSchema(params.output) : void 0,
366
412
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
367
- clientTools: processClientTools(params.clientTools)
413
+ clientTools: processClientTools(params.clientTools),
414
+ structuredOutput: params.structuredOutput ? {
415
+ ...params.structuredOutput,
416
+ schema: zodToJsonSchema(params.structuredOutput.schema)
417
+ } : void 0
368
418
  };
369
419
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
370
420
  const response = await this.request(
371
- `/api/agents/${this.agentId}/generate/vnext`,
421
+ `/api/agents/${this.agentId}/generate`,
372
422
  {
373
423
  method: "POST",
374
424
  body: processedParams
@@ -382,7 +432,7 @@ var Agent = class extends BaseResource {
382
432
  resourceId,
383
433
  threadId,
384
434
  runtimeContext,
385
- respondFn: this.generateVNext.bind(this)
435
+ respondFn: this.generate.bind(this)
386
436
  });
387
437
  }
388
438
  return response;
@@ -649,17 +699,6 @@ var Agent = class extends BaseResource {
649
699
  });
650
700
  onFinish?.({ message, finishReason, usage });
651
701
  }
652
- /**
653
- * Streams a response from the agent
654
- * @param params - Stream parameters including prompt
655
- * @returns Promise containing the enhanced Response object with processDataStream method
656
- */
657
- async stream(params) {
658
- console.warn(
659
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
660
- );
661
- return this.streamLegacy(params);
662
- }
663
702
  /**
664
703
  * Streams a response from the agent
665
704
  * @param params - Stream parameters including prompt
@@ -674,7 +713,7 @@ var Agent = class extends BaseResource {
674
713
  clientTools: processClientTools(params.clientTools)
675
714
  };
676
715
  const { readable, writable } = new TransformStream();
677
- const response = await this.processStreamResponse(processedParams, writable);
716
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
678
717
  const streamResponse = new Response(readable, {
679
718
  status: response.status,
680
719
  statusText: response.statusText,
@@ -761,6 +800,14 @@ var Agent = class extends BaseResource {
761
800
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
762
801
  onChunk: async (chunk) => {
763
802
  switch (chunk.type) {
803
+ case "tripwire": {
804
+ message.parts.push({
805
+ type: "text",
806
+ text: chunk.payload.tripwireReason
807
+ });
808
+ execUpdate();
809
+ break;
810
+ }
764
811
  case "step-start": {
765
812
  if (!replaceLastMessage) {
766
813
  message.id = chunk.payload.messageId;
@@ -869,7 +916,7 @@ var Agent = class extends BaseResource {
869
916
  step,
870
917
  toolCallId: chunk.payload.toolCallId,
871
918
  toolName: chunk.payload.toolName,
872
- args: void 0
919
+ args: chunk.payload.args
873
920
  };
874
921
  message.toolInvocations.push(invocation);
875
922
  updateToolInvocationPart(chunk.payload.toolCallId, invocation);
@@ -914,7 +961,10 @@ var Agent = class extends BaseResource {
914
961
  break;
915
962
  }
916
963
  case "error": {
917
- throw new Error(chunk.payload.error);
964
+ throw error.getErrorFromUnknown(chunk.payload.error, {
965
+ fallbackMessage: "Unknown error in stream",
966
+ supportSerialization: false
967
+ });
918
968
  }
919
969
  case "data": {
920
970
  data.push(...chunk.payload.data);
@@ -923,14 +973,14 @@ var Agent = class extends BaseResource {
923
973
  }
924
974
  case "step-finish": {
925
975
  step += 1;
926
- currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
976
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
927
977
  currentReasoningPart = void 0;
928
978
  currentReasoningTextDetail = void 0;
929
979
  execUpdate();
930
980
  break;
931
981
  }
932
982
  case "finish": {
933
- finishReason = chunk.payload.finishReason;
983
+ finishReason = chunk.payload.stepResult.reason;
934
984
  if (chunk.payload.usage != null) {
935
985
  usage = chunk.payload.usage;
936
986
  }
@@ -941,8 +991,8 @@ var Agent = class extends BaseResource {
941
991
  });
942
992
  onFinish?.({ message, finishReason, usage });
943
993
  }
944
- async processStreamResponse_vNext(processedParams, writable) {
945
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
994
+ async processStreamResponse(processedParams, writable, route = "stream") {
995
+ const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
946
996
  method: "POST",
947
997
  body: processedParams,
948
998
  stream: true
@@ -954,9 +1004,27 @@ var Agent = class extends BaseResource {
954
1004
  let toolCalls = [];
955
1005
  let messages = [];
956
1006
  const [streamForWritable, streamForProcessing] = response.body.tee();
957
- streamForWritable.pipeTo(writable, {
958
- preventClose: true
959
- }).catch((error) => {
1007
+ streamForWritable.pipeTo(
1008
+ new WritableStream({
1009
+ async write(chunk) {
1010
+ let writer;
1011
+ try {
1012
+ writer = writable.getWriter();
1013
+ const text = new TextDecoder().decode(chunk);
1014
+ const lines = text.split("\n\n");
1015
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1016
+ await writer.write(new TextEncoder().encode(readableLines));
1017
+ } catch {
1018
+ await writer?.write(chunk);
1019
+ } finally {
1020
+ writer?.releaseLock();
1021
+ }
1022
+ }
1023
+ }),
1024
+ {
1025
+ preventClose: true
1026
+ }
1027
+ ).catch((error) => {
960
1028
  console.error("Error piping to writable stream:", error);
961
1029
  });
962
1030
  this.processChatResponse_vNext({
@@ -975,9 +1043,11 @@ var Agent = class extends BaseResource {
975
1043
  if (toolCall) {
976
1044
  toolCalls.push(toolCall);
977
1045
  }
1046
+ let shouldExecuteClientTool = false;
978
1047
  for (const toolCall2 of toolCalls) {
979
1048
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
980
1049
  if (clientTool && clientTool.execute) {
1050
+ shouldExecuteClientTool = true;
981
1051
  const result = await clientTool.execute(
982
1052
  {
983
1053
  context: toolCall2?.args,
@@ -986,14 +1056,17 @@ var Agent = class extends BaseResource {
986
1056
  threadId: processedParams.threadId,
987
1057
  runtimeContext: processedParams.runtimeContext,
988
1058
  // TODO: Pass proper tracing context when client-js supports tracing
989
- tracingContext: { currentSpan: void 0 }
1059
+ tracingContext: { currentSpan: void 0 },
1060
+ suspend: async () => {
1061
+ }
990
1062
  },
991
1063
  {
992
1064
  messages: response.messages,
993
1065
  toolCallId: toolCall2?.toolCallId
994
1066
  }
995
1067
  );
996
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1068
+ const lastMessageRaw = messages[messages.length - 1];
1069
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
997
1070
  const toolInvocationPart = lastMessage?.parts?.find(
998
1071
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
999
1072
  );
@@ -1011,25 +1084,11 @@ var Agent = class extends BaseResource {
1011
1084
  toolInvocation.state = "result";
1012
1085
  toolInvocation.result = result;
1013
1086
  }
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];
1029
- this.processStreamResponse_vNext(
1087
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1088
+ this.processStreamResponse(
1030
1089
  {
1031
1090
  ...processedParams,
1032
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1091
+ messages: updatedMessages
1033
1092
  },
1034
1093
  writable
1035
1094
  ).catch((error) => {
@@ -1037,6 +1096,11 @@ var Agent = class extends BaseResource {
1037
1096
  });
1038
1097
  }
1039
1098
  }
1099
+ if (!shouldExecuteClientTool) {
1100
+ setTimeout(() => {
1101
+ writable.close();
1102
+ }, 0);
1103
+ }
1040
1104
  } else {
1041
1105
  setTimeout(() => {
1042
1106
  writable.close();
@@ -1052,15 +1116,87 @@ var Agent = class extends BaseResource {
1052
1116
  }
1053
1117
  return response;
1054
1118
  }
1055
- async streamVNext(params) {
1119
+ async network(params) {
1120
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1121
+ method: "POST",
1122
+ body: params,
1123
+ stream: true
1124
+ });
1125
+ if (!response.body) {
1126
+ throw new Error("No response body");
1127
+ }
1128
+ const streamResponse = new Response(response.body, {
1129
+ status: response.status,
1130
+ statusText: response.statusText,
1131
+ headers: response.headers
1132
+ });
1133
+ streamResponse.processDataStream = async ({
1134
+ onChunk
1135
+ }) => {
1136
+ await processMastraNetworkStream({
1137
+ stream: streamResponse.body,
1138
+ onChunk
1139
+ });
1140
+ };
1141
+ return streamResponse;
1142
+ }
1143
+ async stream(messagesOrParams, options) {
1144
+ let params;
1145
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1146
+ params = messagesOrParams;
1147
+ } else {
1148
+ params = {
1149
+ messages: messagesOrParams,
1150
+ ...options
1151
+ };
1152
+ }
1056
1153
  const processedParams = {
1057
1154
  ...params,
1058
- output: params.output ? zodToJsonSchema(params.output) : void 0,
1059
1155
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1060
- clientTools: processClientTools(params.clientTools)
1156
+ clientTools: processClientTools(params.clientTools),
1157
+ structuredOutput: params.structuredOutput ? {
1158
+ ...params.structuredOutput,
1159
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1160
+ } : void 0
1161
+ };
1162
+ const { readable, writable } = new TransformStream();
1163
+ const response = await this.processStreamResponse(processedParams, writable);
1164
+ const streamResponse = new Response(readable, {
1165
+ status: response.status,
1166
+ statusText: response.statusText,
1167
+ headers: response.headers
1168
+ });
1169
+ streamResponse.processDataStream = async ({
1170
+ onChunk
1171
+ }) => {
1172
+ await processMastraStream({
1173
+ stream: streamResponse.body,
1174
+ onChunk
1175
+ });
1176
+ };
1177
+ return streamResponse;
1178
+ }
1179
+ async approveToolCall(params) {
1180
+ const { readable, writable } = new TransformStream();
1181
+ const response = await this.processStreamResponse(params, writable, "approve-tool-call");
1182
+ const streamResponse = new Response(readable, {
1183
+ status: response.status,
1184
+ statusText: response.statusText,
1185
+ headers: response.headers
1186
+ });
1187
+ streamResponse.processDataStream = async ({
1188
+ onChunk
1189
+ }) => {
1190
+ await processMastraStream({
1191
+ stream: streamResponse.body,
1192
+ onChunk
1193
+ });
1061
1194
  };
1195
+ return streamResponse;
1196
+ }
1197
+ async declineToolCall(params) {
1062
1198
  const { readable, writable } = new TransformStream();
1063
- const response = await this.processStreamResponse_vNext(processedParams, writable);
1199
+ const response = await this.processStreamResponse(params, writable, "decline-tool-call");
1064
1200
  const streamResponse = new Response(readable, {
1065
1201
  status: response.status,
1066
1202
  statusText: response.statusText,
@@ -1079,7 +1215,7 @@ var Agent = class extends BaseResource {
1079
1215
  /**
1080
1216
  * Processes the stream response and handles tool calls
1081
1217
  */
1082
- async processStreamResponse(processedParams, writable) {
1218
+ async processStreamResponseLegacy(processedParams, writable) {
1083
1219
  const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1084
1220
  method: "POST",
1085
1221
  body: processedParams,
@@ -1124,7 +1260,9 @@ var Agent = class extends BaseResource {
1124
1260
  threadId: processedParams.threadId,
1125
1261
  runtimeContext: processedParams.runtimeContext,
1126
1262
  // TODO: Pass proper tracing context when client-js supports tracing
1127
- tracingContext: { currentSpan: void 0 }
1263
+ tracingContext: { currentSpan: void 0 },
1264
+ suspend: async () => {
1265
+ }
1128
1266
  },
1129
1267
  {
1130
1268
  messages: response.messages,
@@ -1162,12 +1300,10 @@ var Agent = class extends BaseResource {
1162
1300
  } finally {
1163
1301
  writer.releaseLock();
1164
1302
  }
1165
- const originalMessages = processedParams.messages;
1166
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1167
- this.processStreamResponse(
1303
+ this.processStreamResponseLegacy(
1168
1304
  {
1169
1305
  ...processedParams,
1170
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1306
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1171
1307
  },
1172
1308
  writable
1173
1309
  ).catch((error) => {
@@ -1193,10 +1329,11 @@ var Agent = class extends BaseResource {
1193
1329
  /**
1194
1330
  * Gets details about a specific tool available to the agent
1195
1331
  * @param toolId - ID of the tool to retrieve
1332
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1196
1333
  * @returns Promise containing tool details
1197
1334
  */
1198
- getTool(toolId) {
1199
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1335
+ getTool(toolId, runtimeContext) {
1336
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1200
1337
  }
1201
1338
  /**
1202
1339
  * Executes a tool for the agent
@@ -1207,7 +1344,7 @@ var Agent = class extends BaseResource {
1207
1344
  executeTool(toolId, params) {
1208
1345
  const body = {
1209
1346
  data: params.data,
1210
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1347
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1211
1348
  };
1212
1349
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1213
1350
  method: "POST",
@@ -1216,17 +1353,19 @@ var Agent = class extends BaseResource {
1216
1353
  }
1217
1354
  /**
1218
1355
  * Retrieves evaluation results for the agent
1356
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1219
1357
  * @returns Promise containing agent evaluations
1220
1358
  */
1221
- evals() {
1222
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1359
+ evals(runtimeContext) {
1360
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1223
1361
  }
1224
1362
  /**
1225
1363
  * Retrieves live evaluation results for the agent
1364
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1226
1365
  * @returns Promise containing live agent evaluations
1227
1366
  */
1228
- liveEvals() {
1229
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1367
+ liveEvals(runtimeContext) {
1368
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1230
1369
  }
1231
1370
  /**
1232
1371
  * Updates the model for the agent
@@ -1239,61 +1378,33 @@ var Agent = class extends BaseResource {
1239
1378
  body: params
1240
1379
  });
1241
1380
  }
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
1381
  /**
1256
- * Generates a response from the agent
1257
- * @param params - Generation parameters including prompt
1258
- * @returns Promise containing the generated response
1382
+ * Updates the model for the agent in the model list
1383
+ * @param params - Parameters for updating the model
1384
+ * @returns Promise containing the updated model
1259
1385
  */
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`, {
1386
+ updateModelInModelList({ modelConfigId, ...params }) {
1387
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
1267
1388
  method: "POST",
1268
- body: processedParams
1389
+ body: params
1269
1390
  });
1270
1391
  }
1271
1392
  /**
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
1393
+ * Reorders the models for the agent
1394
+ * @param params - Parameters for reordering the model list
1395
+ * @returns Promise containing the updated model list
1275
1396
  */
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`, {
1397
+ reorderModelList(params) {
1398
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
1283
1399
  method: "POST",
1284
- body: processedParams,
1285
- stream: true
1400
+ body: params
1286
1401
  });
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;
1402
+ }
1403
+ async generateVNext(_messagesOrParams, _options) {
1404
+ throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1405
+ }
1406
+ async streamVNext(_messagesOrParams, _options) {
1407
+ throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1297
1408
  }
1298
1409
  };
1299
1410
 
@@ -1384,10 +1495,13 @@ var Vector = class extends BaseResource {
1384
1495
  /**
1385
1496
  * Retrieves details about a specific vector index
1386
1497
  * @param indexName - Name of the index to get details for
1498
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1387
1499
  * @returns Promise containing vector index details
1388
1500
  */
1389
- details(indexName) {
1390
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1501
+ details(indexName, runtimeContext) {
1502
+ return this.request(
1503
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1504
+ );
1391
1505
  }
1392
1506
  /**
1393
1507
  * Deletes a vector index
@@ -1401,10 +1515,11 @@ var Vector = class extends BaseResource {
1401
1515
  }
1402
1516
  /**
1403
1517
  * Retrieves a list of all available indexes
1518
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1404
1519
  * @returns Promise containing array of index names
1405
1520
  */
1406
- getIndexes() {
1407
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1521
+ getIndexes(runtimeContext) {
1522
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1408
1523
  }
1409
1524
  /**
1410
1525
  * Creates a new vector index
@@ -1441,26 +1556,109 @@ var Vector = class extends BaseResource {
1441
1556
  }
1442
1557
  };
1443
1558
 
1444
- // src/resources/legacy-workflow.ts
1559
+ // src/resources/tool.ts
1560
+ var Tool = class extends BaseResource {
1561
+ constructor(options, toolId) {
1562
+ super(options);
1563
+ this.toolId = toolId;
1564
+ }
1565
+ /**
1566
+ * Retrieves details about the tool
1567
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1568
+ * @returns Promise containing tool details including description and schemas
1569
+ */
1570
+ details(runtimeContext) {
1571
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1572
+ }
1573
+ /**
1574
+ * Executes the tool with the provided parameters
1575
+ * @param params - Parameters required for tool execution
1576
+ * @returns Promise containing the tool execution results
1577
+ */
1578
+ execute(params) {
1579
+ const url = new URLSearchParams();
1580
+ if (params.runId) {
1581
+ url.set("runId", params.runId);
1582
+ }
1583
+ const body = {
1584
+ data: params.data,
1585
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1586
+ };
1587
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1588
+ method: "POST",
1589
+ body
1590
+ });
1591
+ }
1592
+ };
1593
+
1594
+ // src/resources/workflow.ts
1445
1595
  var RECORD_SEPARATOR = "";
1446
- var LegacyWorkflow = class extends BaseResource {
1596
+ var Workflow = class extends BaseResource {
1447
1597
  constructor(options, workflowId) {
1448
1598
  super(options);
1449
1599
  this.workflowId = workflowId;
1450
1600
  }
1451
1601
  /**
1452
- * Retrieves details about the legacy workflow
1453
- * @returns Promise containing legacy workflow details including steps and graphs
1602
+ * Creates an async generator that processes a readable stream and yields workflow records
1603
+ * separated by the Record Separator character (\x1E)
1604
+ *
1605
+ * @param stream - The readable stream to process
1606
+ * @returns An async generator that yields parsed records
1607
+ */
1608
+ async *streamProcessor(stream) {
1609
+ const reader = stream.getReader();
1610
+ let doneReading = false;
1611
+ let buffer = "";
1612
+ try {
1613
+ while (!doneReading) {
1614
+ const { done, value } = await reader.read();
1615
+ doneReading = done;
1616
+ if (done && !value) continue;
1617
+ try {
1618
+ const decoded = value ? new TextDecoder().decode(value) : "";
1619
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1620
+ buffer = chunks.pop() || "";
1621
+ for (const chunk of chunks) {
1622
+ if (chunk) {
1623
+ if (typeof chunk === "string") {
1624
+ try {
1625
+ const parsedChunk = JSON.parse(chunk);
1626
+ yield parsedChunk;
1627
+ } catch {
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1632
+ } catch {
1633
+ }
1634
+ }
1635
+ if (buffer) {
1636
+ try {
1637
+ yield JSON.parse(buffer);
1638
+ } catch {
1639
+ }
1640
+ }
1641
+ } finally {
1642
+ reader.cancel().catch(() => {
1643
+ });
1644
+ }
1645
+ }
1646
+ /**
1647
+ * Retrieves details about the workflow
1648
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1649
+ * @returns Promise containing workflow details including steps and graphs
1454
1650
  */
1455
- details() {
1456
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1651
+ details(runtimeContext) {
1652
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1457
1653
  }
1458
1654
  /**
1459
- * Retrieves all runs for a legacy workflow
1655
+ * Retrieves all runs for a workflow
1460
1656
  * @param params - Parameters for filtering runs
1461
- * @returns Promise containing legacy workflow runs array
1657
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1658
+ * @returns Promise containing workflow runs array
1462
1659
  */
1463
- runs(params) {
1660
+ runs(params, runtimeContext) {
1661
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1464
1662
  const searchParams = new URLSearchParams();
1465
1663
  if (params?.fromDate) {
1466
1664
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1468,296 +1666,43 @@ var LegacyWorkflow = class extends BaseResource {
1468
1666
  if (params?.toDate) {
1469
1667
  searchParams.set("toDate", params.toDate.toISOString());
1470
1668
  }
1471
- if (params?.limit) {
1669
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1472
1670
  searchParams.set("limit", String(params.limit));
1473
1671
  }
1474
- if (params?.offset) {
1672
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1475
1673
  searchParams.set("offset", String(params.offset));
1476
1674
  }
1477
1675
  if (params?.resourceId) {
1478
1676
  searchParams.set("resourceId", params.resourceId);
1479
1677
  }
1678
+ if (runtimeContextParam) {
1679
+ searchParams.set("runtimeContext", runtimeContextParam);
1680
+ }
1480
1681
  if (searchParams.size) {
1481
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1682
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1482
1683
  } 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
- // src/resources/tool.ts
1626
- var Tool = class extends BaseResource {
1627
- constructor(options, toolId) {
1628
- super(options);
1629
- this.toolId = toolId;
1630
- }
1631
- /**
1632
- * Retrieves details about the tool
1633
- * @returns Promise containing tool details including description and schemas
1634
- */
1635
- details() {
1636
- return this.request(`/api/tools/${this.toolId}`);
1637
- }
1638
- /**
1639
- * Executes the tool with the provided parameters
1640
- * @param params - Parameters required for tool execution
1641
- * @returns Promise containing the tool execution results
1642
- */
1643
- execute(params) {
1644
- const url = new URLSearchParams();
1645
- if (params.runId) {
1646
- url.set("runId", params.runId);
1647
- }
1648
- const body = {
1649
- data: params.data,
1650
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1651
- };
1652
- return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
1653
- method: "POST",
1654
- body
1655
- });
1656
- }
1657
- };
1658
-
1659
- // src/resources/workflow.ts
1660
- var RECORD_SEPARATOR2 = "";
1661
- var Workflow = class extends BaseResource {
1662
- constructor(options, workflowId) {
1663
- super(options);
1664
- this.workflowId = workflowId;
1665
- }
1666
- /**
1667
- * Creates an async generator that processes a readable stream and yields workflow records
1668
- * separated by the Record Separator character (\x1E)
1669
- *
1670
- * @param stream - The readable stream to process
1671
- * @returns An async generator that yields parsed records
1672
- */
1673
- async *streamProcessor(stream) {
1674
- const reader = stream.getReader();
1675
- let doneReading = false;
1676
- let buffer = "";
1677
- try {
1678
- while (!doneReading) {
1679
- const { done, value } = await reader.read();
1680
- doneReading = done;
1681
- if (done && !value) continue;
1682
- try {
1683
- const decoded = value ? new TextDecoder().decode(value) : "";
1684
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1685
- buffer = chunks.pop() || "";
1686
- for (const chunk of chunks) {
1687
- if (chunk) {
1688
- if (typeof chunk === "string") {
1689
- try {
1690
- const parsedChunk = JSON.parse(chunk);
1691
- yield parsedChunk;
1692
- } catch {
1693
- }
1694
- }
1695
- }
1696
- }
1697
- } catch {
1698
- }
1699
- }
1700
- if (buffer) {
1701
- try {
1702
- yield JSON.parse(buffer);
1703
- } catch {
1704
- }
1705
- }
1706
- } finally {
1707
- reader.cancel().catch(() => {
1708
- });
1709
- }
1710
- }
1711
- /**
1712
- * Retrieves details about the workflow
1713
- * @returns Promise containing workflow details including steps and graphs
1714
- */
1715
- details() {
1716
- return this.request(`/api/workflows/${this.workflowId}`);
1717
- }
1718
- /**
1719
- * Retrieves all runs for a workflow
1720
- * @param params - Parameters for filtering runs
1721
- * @returns Promise containing workflow runs array
1722
- */
1723
- runs(params) {
1724
- const searchParams = new URLSearchParams();
1725
- if (params?.fromDate) {
1726
- searchParams.set("fromDate", params.fromDate.toISOString());
1727
- }
1728
- if (params?.toDate) {
1729
- searchParams.set("toDate", params.toDate.toISOString());
1730
- }
1731
- if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1732
- searchParams.set("limit", String(params.limit));
1733
- }
1734
- if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1735
- searchParams.set("offset", String(params.offset));
1736
- }
1737
- if (params?.resourceId) {
1738
- searchParams.set("resourceId", params.resourceId);
1739
- }
1740
- if (searchParams.size) {
1741
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1742
- } else {
1743
- return this.request(`/api/workflows/${this.workflowId}/runs`);
1684
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
1744
1685
  }
1745
1686
  }
1746
1687
  /**
1747
1688
  * Retrieves a specific workflow run by its ID
1748
1689
  * @param runId - The ID of the workflow run to retrieve
1690
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1749
1691
  * @returns Promise containing the workflow run details
1750
1692
  */
1751
- runById(runId) {
1752
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1693
+ runById(runId, runtimeContext) {
1694
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1753
1695
  }
1754
1696
  /**
1755
1697
  * Retrieves the execution result for a specific workflow run by its ID
1756
1698
  * @param runId - The ID of the workflow run to retrieve the execution result for
1699
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1757
1700
  * @returns Promise containing the workflow run execution result
1758
1701
  */
1759
- runExecutionResult(runId) {
1760
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1702
+ runExecutionResult(runId, runtimeContext) {
1703
+ return this.request(
1704
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1705
+ );
1761
1706
  }
1762
1707
  /**
1763
1708
  * Cancels a specific workflow run by its ID
@@ -1780,27 +1725,83 @@ var Workflow = class extends BaseResource {
1780
1725
  body: { event: params.event, data: params.data }
1781
1726
  });
1782
1727
  }
1728
+ /**
1729
+ * @deprecated Use createRunAsync() instead.
1730
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1731
+ */
1732
+ async createRun(_params) {
1733
+ throw new Error(
1734
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
1735
+ );
1736
+ }
1783
1737
  /**
1784
1738
  * Creates a new workflow run
1785
1739
  * @param params - Optional object containing the optional runId
1786
- * @returns Promise containing the runId of the created run
1740
+ * @returns Promise containing the runId of the created run with methods to control execution
1787
1741
  */
1788
- createRun(params) {
1742
+ async createRunAsync(params) {
1789
1743
  const searchParams = new URLSearchParams();
1790
1744
  if (!!params?.runId) {
1791
1745
  searchParams.set("runId", params.runId);
1792
1746
  }
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);
1747
+ const res = await this.request(
1748
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1749
+ {
1750
+ method: "POST"
1751
+ }
1752
+ );
1753
+ const runId = res.runId;
1754
+ return {
1755
+ runId,
1756
+ start: async (p) => {
1757
+ return this.start({
1758
+ runId,
1759
+ inputData: p.inputData,
1760
+ runtimeContext: p.runtimeContext,
1761
+ tracingOptions: p.tracingOptions
1762
+ });
1763
+ },
1764
+ startAsync: async (p) => {
1765
+ return this.startAsync({
1766
+ runId,
1767
+ inputData: p.inputData,
1768
+ runtimeContext: p.runtimeContext,
1769
+ tracingOptions: p.tracingOptions
1770
+ });
1771
+ },
1772
+ watch: async (onRecord) => {
1773
+ return this.watch({ runId }, onRecord);
1774
+ },
1775
+ stream: async (p) => {
1776
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1777
+ },
1778
+ resume: async (p) => {
1779
+ return this.resume({
1780
+ runId,
1781
+ step: p.step,
1782
+ resumeData: p.resumeData,
1783
+ runtimeContext: p.runtimeContext,
1784
+ tracingOptions: p.tracingOptions
1785
+ });
1786
+ },
1787
+ resumeAsync: async (p) => {
1788
+ return this.resumeAsync({
1789
+ runId,
1790
+ step: p.step,
1791
+ resumeData: p.resumeData,
1792
+ runtimeContext: p.runtimeContext,
1793
+ tracingOptions: p.tracingOptions
1794
+ });
1795
+ },
1796
+ resumeStreamVNext: async (p) => {
1797
+ return this.resumeStreamVNext({
1798
+ runId,
1799
+ step: p.step,
1800
+ resumeData: p.resumeData,
1801
+ runtimeContext: p.runtimeContext
1802
+ });
1803
+ }
1804
+ };
1804
1805
  }
1805
1806
  /**
1806
1807
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1811,7 +1812,7 @@ var Workflow = class extends BaseResource {
1811
1812
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1812
1813
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1813
1814
  method: "POST",
1814
- body: { inputData: params?.inputData, runtimeContext }
1815
+ body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1815
1816
  });
1816
1817
  }
1817
1818
  /**
@@ -1823,16 +1824,17 @@ var Workflow = class extends BaseResource {
1823
1824
  step,
1824
1825
  runId,
1825
1826
  resumeData,
1827
+ tracingOptions,
1826
1828
  ...rest
1827
1829
  }) {
1828
1830
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1829
1831
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1830
1832
  method: "POST",
1831
- stream: true,
1832
1833
  body: {
1833
1834
  step,
1834
1835
  resumeData,
1835
- runtimeContext
1836
+ runtimeContext,
1837
+ tracingOptions
1836
1838
  }
1837
1839
  });
1838
1840
  }
@@ -1849,7 +1851,7 @@ var Workflow = class extends BaseResource {
1849
1851
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1850
1852
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1851
1853
  method: "POST",
1852
- body: { inputData: params.inputData, runtimeContext }
1854
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1853
1855
  });
1854
1856
  }
1855
1857
  /**
@@ -1864,15 +1866,165 @@ var Workflow = class extends BaseResource {
1864
1866
  }
1865
1867
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1866
1868
  const response = await this.request(
1867
- `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1869
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1870
+ {
1871
+ method: "POST",
1872
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1873
+ stream: true
1874
+ }
1875
+ );
1876
+ if (!response.ok) {
1877
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1878
+ }
1879
+ if (!response.body) {
1880
+ throw new Error("Response body is null");
1881
+ }
1882
+ let failedChunk = void 0;
1883
+ const transformStream = new TransformStream({
1884
+ start() {
1885
+ },
1886
+ async transform(chunk, controller) {
1887
+ try {
1888
+ const decoded = new TextDecoder().decode(chunk);
1889
+ const chunks = decoded.split(RECORD_SEPARATOR);
1890
+ for (const chunk2 of chunks) {
1891
+ if (chunk2) {
1892
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1893
+ try {
1894
+ const parsedChunk = JSON.parse(newChunk);
1895
+ controller.enqueue(parsedChunk);
1896
+ failedChunk = void 0;
1897
+ } catch {
1898
+ failedChunk = newChunk;
1899
+ }
1900
+ }
1901
+ }
1902
+ } catch {
1903
+ }
1904
+ }
1905
+ });
1906
+ return response.body.pipeThrough(transformStream);
1907
+ }
1908
+ /**
1909
+ * Observes workflow stream for a workflow run
1910
+ * @param params - Object containing the runId
1911
+ * @returns Promise containing the workflow execution results
1912
+ */
1913
+ async observeStream(params) {
1914
+ const searchParams = new URLSearchParams();
1915
+ searchParams.set("runId", params.runId);
1916
+ const response = await this.request(
1917
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1918
+ {
1919
+ method: "POST",
1920
+ stream: true
1921
+ }
1922
+ );
1923
+ if (!response.ok) {
1924
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1925
+ }
1926
+ if (!response.body) {
1927
+ throw new Error("Response body is null");
1928
+ }
1929
+ let failedChunk = void 0;
1930
+ const transformStream = new TransformStream({
1931
+ start() {
1932
+ },
1933
+ async transform(chunk, controller) {
1934
+ try {
1935
+ const decoded = new TextDecoder().decode(chunk);
1936
+ const chunks = decoded.split(RECORD_SEPARATOR);
1937
+ for (const chunk2 of chunks) {
1938
+ if (chunk2) {
1939
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1940
+ try {
1941
+ const parsedChunk = JSON.parse(newChunk);
1942
+ controller.enqueue(parsedChunk);
1943
+ failedChunk = void 0;
1944
+ } catch {
1945
+ failedChunk = newChunk;
1946
+ }
1947
+ }
1948
+ }
1949
+ } catch {
1950
+ }
1951
+ }
1952
+ });
1953
+ return response.body.pipeThrough(transformStream);
1954
+ }
1955
+ /**
1956
+ * Starts a workflow run and returns a stream
1957
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1958
+ * @returns Promise containing the workflow execution results
1959
+ */
1960
+ async streamVNext(params) {
1961
+ const searchParams = new URLSearchParams();
1962
+ if (!!params?.runId) {
1963
+ searchParams.set("runId", params.runId);
1964
+ }
1965
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1966
+ const response = await this.request(
1967
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1968
+ {
1969
+ method: "POST",
1970
+ body: {
1971
+ inputData: params.inputData,
1972
+ runtimeContext,
1973
+ closeOnSuspend: params.closeOnSuspend,
1974
+ tracingOptions: params.tracingOptions
1975
+ },
1976
+ stream: true
1977
+ }
1978
+ );
1979
+ if (!response.ok) {
1980
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1981
+ }
1982
+ if (!response.body) {
1983
+ throw new Error("Response body is null");
1984
+ }
1985
+ let failedChunk = void 0;
1986
+ const transformStream = new TransformStream({
1987
+ start() {
1988
+ },
1989
+ async transform(chunk, controller) {
1990
+ try {
1991
+ const decoded = new TextDecoder().decode(chunk);
1992
+ const chunks = decoded.split(RECORD_SEPARATOR);
1993
+ for (const chunk2 of chunks) {
1994
+ if (chunk2) {
1995
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1996
+ try {
1997
+ const parsedChunk = JSON.parse(newChunk);
1998
+ controller.enqueue(parsedChunk);
1999
+ failedChunk = void 0;
2000
+ } catch {
2001
+ failedChunk = newChunk;
2002
+ }
2003
+ }
2004
+ }
2005
+ } catch {
2006
+ }
2007
+ }
2008
+ });
2009
+ return response.body.pipeThrough(transformStream);
2010
+ }
2011
+ /**
2012
+ * Observes workflow vNext stream for a workflow run
2013
+ * @param params - Object containing the runId
2014
+ * @returns Promise containing the workflow execution results
2015
+ */
2016
+ async observeStreamVNext(params) {
2017
+ const searchParams = new URLSearchParams();
2018
+ searchParams.set("runId", params.runId);
2019
+ const response = await this.request(
2020
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
1868
2021
  {
1869
2022
  method: "POST",
1870
- body: { inputData: params.inputData, runtimeContext },
1871
2023
  stream: true
1872
2024
  }
1873
2025
  );
1874
2026
  if (!response.ok) {
1875
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2027
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
1876
2028
  }
1877
2029
  if (!response.body) {
1878
2030
  throw new Error("Response body is null");
@@ -1884,7 +2036,7 @@ var Workflow = class extends BaseResource {
1884
2036
  async transform(chunk, controller) {
1885
2037
  try {
1886
2038
  const decoded = new TextDecoder().decode(chunk);
1887
- const chunks = decoded.split(RECORD_SEPARATOR2);
2039
+ const chunks = decoded.split(RECORD_SEPARATOR);
1888
2040
  for (const chunk2 of chunks) {
1889
2041
  if (chunk2) {
1890
2042
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1915,9 +2067,64 @@ var Workflow = class extends BaseResource {
1915
2067
  body: {
1916
2068
  step: params.step,
1917
2069
  resumeData: params.resumeData,
1918
- runtimeContext
2070
+ runtimeContext,
2071
+ tracingOptions: params.tracingOptions
2072
+ }
2073
+ });
2074
+ }
2075
+ /**
2076
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2077
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2078
+ * @returns Promise containing the workflow resume results
2079
+ */
2080
+ async resumeStreamVNext(params) {
2081
+ const searchParams = new URLSearchParams();
2082
+ searchParams.set("runId", params.runId);
2083
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2084
+ const response = await this.request(
2085
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2086
+ {
2087
+ method: "POST",
2088
+ body: {
2089
+ step: params.step,
2090
+ resumeData: params.resumeData,
2091
+ runtimeContext,
2092
+ tracingOptions: params.tracingOptions
2093
+ },
2094
+ stream: true
2095
+ }
2096
+ );
2097
+ if (!response.ok) {
2098
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2099
+ }
2100
+ if (!response.body) {
2101
+ throw new Error("Response body is null");
2102
+ }
2103
+ let failedChunk = void 0;
2104
+ const transformStream = new TransformStream({
2105
+ start() {
2106
+ },
2107
+ async transform(chunk, controller) {
2108
+ try {
2109
+ const decoded = new TextDecoder().decode(chunk);
2110
+ const chunks = decoded.split(RECORD_SEPARATOR);
2111
+ for (const chunk2 of chunks) {
2112
+ if (chunk2) {
2113
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2114
+ try {
2115
+ const parsedChunk = JSON.parse(newChunk);
2116
+ controller.enqueue(parsedChunk);
2117
+ failedChunk = void 0;
2118
+ } catch {
2119
+ failedChunk = newChunk;
2120
+ }
2121
+ }
2122
+ }
2123
+ } catch {
2124
+ }
1919
2125
  }
1920
2126
  });
2127
+ return response.body.pipeThrough(transformStream);
1921
2128
  }
1922
2129
  /**
1923
2130
  * Watches workflow transitions in real-time
@@ -1955,7 +2162,7 @@ var Workflow = class extends BaseResource {
1955
2162
  async start(controller) {
1956
2163
  try {
1957
2164
  for await (const record of records) {
1958
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2165
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
1959
2166
  controller.enqueue(encoder.encode(json));
1960
2167
  }
1961
2168
  controller.close();
@@ -2053,10 +2260,11 @@ var MCPTool = class extends BaseResource {
2053
2260
  }
2054
2261
  /**
2055
2262
  * Retrieves details about this specific tool from the MCP server.
2263
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2056
2264
  * @returns Promise containing the tool's information (name, description, schema).
2057
2265
  */
2058
- details() {
2059
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2266
+ details(runtimeContext) {
2267
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2060
2268
  }
2061
2269
  /**
2062
2270
  * Executes this specific tool on the MCP server.
@@ -2077,7 +2285,7 @@ var MCPTool = class extends BaseResource {
2077
2285
  };
2078
2286
 
2079
2287
  // src/resources/agent-builder.ts
2080
- var RECORD_SEPARATOR3 = "";
2288
+ var RECORD_SEPARATOR2 = "";
2081
2289
  var AgentBuilder = class extends BaseResource {
2082
2290
  constructor(options, actionId) {
2083
2291
  super(options);
@@ -2112,11 +2320,20 @@ var AgentBuilder = class extends BaseResource {
2112
2320
  };
2113
2321
  }
2114
2322
  }
2323
+ /**
2324
+ * @deprecated Use createRunAsync() instead.
2325
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2326
+ */
2327
+ async createRun(_params) {
2328
+ throw new Error(
2329
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
2330
+ );
2331
+ }
2115
2332
  /**
2116
2333
  * Creates a new agent builder action run and returns the runId.
2117
2334
  * This calls `/api/agent-builder/:actionId/create-run`.
2118
2335
  */
2119
- async createRun(params) {
2336
+ async createRunAsync(params) {
2120
2337
  const searchParams = new URLSearchParams();
2121
2338
  if (!!params?.runId) {
2122
2339
  searchParams.set("runId", params.runId);
@@ -2126,14 +2343,6 @@ var AgentBuilder = class extends BaseResource {
2126
2343
  method: "POST"
2127
2344
  });
2128
2345
  }
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
2346
  /**
2138
2347
  * Starts agent builder action asynchronously and waits for completion.
2139
2348
  * This calls `/api/agent-builder/:actionId/start-async`.
@@ -2216,7 +2425,7 @@ var AgentBuilder = class extends BaseResource {
2216
2425
  if (done && !value) continue;
2217
2426
  try {
2218
2427
  const decoded = value ? new TextDecoder().decode(value) : "";
2219
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2428
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2220
2429
  buffer = chunks.pop() || "";
2221
2430
  for (const chunk of chunks) {
2222
2431
  if (chunk) {
@@ -2273,7 +2482,7 @@ var AgentBuilder = class extends BaseResource {
2273
2482
  async transform(chunk, controller) {
2274
2483
  try {
2275
2484
  const decoded = new TextDecoder().decode(chunk);
2276
- const chunks = decoded.split(RECORD_SEPARATOR3);
2485
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2277
2486
  for (const chunk2 of chunks) {
2278
2487
  if (chunk2) {
2279
2488
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2322,7 +2531,7 @@ var AgentBuilder = class extends BaseResource {
2322
2531
  async transform(chunk, controller) {
2323
2532
  try {
2324
2533
  const decoded = new TextDecoder().decode(chunk);
2325
- const chunks = decoded.split(RECORD_SEPARATOR3);
2534
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2326
2535
  for (const chunk2 of chunks) {
2327
2536
  if (chunk2) {
2328
2537
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -2465,7 +2674,7 @@ var Observability = class extends BaseResource {
2465
2674
  getTraces(params) {
2466
2675
  const { pagination, filters } = params;
2467
2676
  const { page, perPage, dateRange } = pagination || {};
2468
- const { name, spanType } = filters || {};
2677
+ const { name, spanType, entityId, entityType } = filters || {};
2469
2678
  const searchParams = new URLSearchParams();
2470
2679
  if (page !== void 0) {
2471
2680
  searchParams.set("page", String(page));
@@ -2479,6 +2688,10 @@ var Observability = class extends BaseResource {
2479
2688
  if (spanType !== void 0) {
2480
2689
  searchParams.set("spanType", String(spanType));
2481
2690
  }
2691
+ if (entityId && entityType) {
2692
+ searchParams.set("entityId", entityId);
2693
+ searchParams.set("entityType", entityType);
2694
+ }
2482
2695
  if (dateRange) {
2483
2696
  const dateRangeStr = JSON.stringify({
2484
2697
  start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
@@ -2489,6 +2702,31 @@ var Observability = class extends BaseResource {
2489
2702
  const queryString = searchParams.toString();
2490
2703
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2491
2704
  }
2705
+ /**
2706
+ * Retrieves scores by trace ID and span ID
2707
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2708
+ * @returns Promise containing scores and pagination info
2709
+ */
2710
+ getScoresBySpan(params) {
2711
+ const { traceId, spanId, page, perPage } = params;
2712
+ const searchParams = new URLSearchParams();
2713
+ if (page !== void 0) {
2714
+ searchParams.set("page", String(page));
2715
+ }
2716
+ if (perPage !== void 0) {
2717
+ searchParams.set("perPage", String(perPage));
2718
+ }
2719
+ const queryString = searchParams.toString();
2720
+ return this.request(
2721
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2722
+ );
2723
+ }
2724
+ score(params) {
2725
+ return this.request(`/api/observability/traces/score`, {
2726
+ method: "POST",
2727
+ body: { ...params }
2728
+ });
2729
+ }
2492
2730
  };
2493
2731
 
2494
2732
  // src/resources/network-memory-thread.ts
@@ -2554,144 +2792,6 @@ var NetworkMemoryThread = class extends BaseResource {
2554
2792
  }
2555
2793
  };
2556
2794
 
2557
- // src/resources/vNextNetwork.ts
2558
- var RECORD_SEPARATOR4 = "";
2559
- var VNextNetwork = class extends BaseResource {
2560
- constructor(options, networkId) {
2561
- super(options);
2562
- this.networkId = networkId;
2563
- }
2564
- /**
2565
- * Retrieves details about the network
2566
- * @returns Promise containing vNext network details
2567
- */
2568
- details() {
2569
- return this.request(`/api/networks/v-next/${this.networkId}`);
2570
- }
2571
- /**
2572
- * Generates a response from the v-next network
2573
- * @param params - Generation parameters including message
2574
- * @returns Promise containing the generated response
2575
- */
2576
- generate(params) {
2577
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2578
- method: "POST",
2579
- body: {
2580
- ...params,
2581
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2582
- }
2583
- });
2584
- }
2585
- /**
2586
- * Generates a response from the v-next network using multiple primitives
2587
- * @param params - Generation parameters including message
2588
- * @returns Promise containing the generated response
2589
- */
2590
- loop(params) {
2591
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2592
- method: "POST",
2593
- body: {
2594
- ...params,
2595
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2596
- }
2597
- });
2598
- }
2599
- async *streamProcessor(stream) {
2600
- const reader = stream.getReader();
2601
- let doneReading = false;
2602
- let buffer = "";
2603
- try {
2604
- while (!doneReading) {
2605
- const { done, value } = await reader.read();
2606
- doneReading = done;
2607
- if (done && !value) continue;
2608
- try {
2609
- const decoded = value ? new TextDecoder().decode(value) : "";
2610
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2611
- buffer = chunks.pop() || "";
2612
- for (const chunk of chunks) {
2613
- if (chunk) {
2614
- if (typeof chunk === "string") {
2615
- try {
2616
- const parsedChunk = JSON.parse(chunk);
2617
- yield parsedChunk;
2618
- } catch {
2619
- }
2620
- }
2621
- }
2622
- }
2623
- } catch {
2624
- }
2625
- }
2626
- if (buffer) {
2627
- try {
2628
- yield JSON.parse(buffer);
2629
- } catch {
2630
- }
2631
- }
2632
- } finally {
2633
- reader.cancel().catch(() => {
2634
- });
2635
- }
2636
- }
2637
- /**
2638
- * Streams a response from the v-next network
2639
- * @param params - Stream parameters including message
2640
- * @returns Promise containing the results
2641
- */
2642
- async stream(params, onRecord) {
2643
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2644
- method: "POST",
2645
- body: {
2646
- ...params,
2647
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2648
- },
2649
- stream: true
2650
- });
2651
- if (!response.ok) {
2652
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2653
- }
2654
- if (!response.body) {
2655
- throw new Error("Response body is null");
2656
- }
2657
- for await (const record of this.streamProcessor(response.body)) {
2658
- if (typeof record === "string") {
2659
- onRecord(JSON.parse(record));
2660
- } else {
2661
- onRecord(record);
2662
- }
2663
- }
2664
- }
2665
- /**
2666
- * Streams a response from the v-next network loop
2667
- * @param params - Stream parameters including message
2668
- * @returns Promise containing the results
2669
- */
2670
- async loopStream(params, onRecord) {
2671
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2672
- method: "POST",
2673
- body: {
2674
- ...params,
2675
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2676
- },
2677
- stream: true
2678
- });
2679
- if (!response.ok) {
2680
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2681
- }
2682
- if (!response.body) {
2683
- throw new Error("Response body is null");
2684
- }
2685
- for await (const record of this.streamProcessor(response.body)) {
2686
- if (typeof record === "string") {
2687
- onRecord(JSON.parse(record));
2688
- } else {
2689
- onRecord(record);
2690
- }
2691
- }
2692
- }
2693
- };
2694
-
2695
2795
  // src/client.ts
2696
2796
  var MastraClient = class extends BaseResource {
2697
2797
  observability;
@@ -2701,10 +2801,20 @@ var MastraClient = class extends BaseResource {
2701
2801
  }
2702
2802
  /**
2703
2803
  * Retrieves all available agents
2804
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2704
2805
  * @returns Promise containing map of agent IDs to agent details
2705
2806
  */
2706
- getAgents() {
2707
- return this.request("/api/agents");
2807
+ getAgents(runtimeContext) {
2808
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2809
+ const searchParams = new URLSearchParams();
2810
+ if (runtimeContextParam) {
2811
+ searchParams.set("runtimeContext", runtimeContextParam);
2812
+ }
2813
+ const queryString = searchParams.toString();
2814
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2815
+ }
2816
+ getAgentsModelProviders() {
2817
+ return this.request(`/api/agents/providers`);
2708
2818
  }
2709
2819
  /**
2710
2820
  * Gets an agent instance by ID
@@ -2722,6 +2832,14 @@ var MastraClient = class extends BaseResource {
2722
2832
  getMemoryThreads(params) {
2723
2833
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2724
2834
  }
2835
+ /**
2836
+ * Retrieves memory config for a resource
2837
+ * @param params - Parameters containing the resource ID
2838
+ * @returns Promise containing array of memory threads
2839
+ */
2840
+ getMemoryConfig(params) {
2841
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2842
+ }
2725
2843
  /**
2726
2844
  * Creates a new memory thread
2727
2845
  * @param params - Parameters for creating the memory thread
@@ -2738,6 +2856,24 @@ var MastraClient = class extends BaseResource {
2738
2856
  getMemoryThread(threadId, agentId) {
2739
2857
  return new MemoryThread(this.options, threadId, agentId);
2740
2858
  }
2859
+ getThreadMessages(threadId, opts = {}) {
2860
+ let url = "";
2861
+ if (opts.agentId) {
2862
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2863
+ } else if (opts.networkId) {
2864
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2865
+ }
2866
+ return this.request(url);
2867
+ }
2868
+ deleteThread(threadId, opts = {}) {
2869
+ let url = "";
2870
+ if (opts.agentId) {
2871
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2872
+ } else if (opts.networkId) {
2873
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2874
+ }
2875
+ return this.request(url, { method: "DELETE" });
2876
+ }
2741
2877
  /**
2742
2878
  * Saves messages to memory
2743
2879
  * @param params - Parameters containing messages to save
@@ -2800,10 +2936,17 @@ var MastraClient = class extends BaseResource {
2800
2936
  }
2801
2937
  /**
2802
2938
  * Retrieves all available tools
2939
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2803
2940
  * @returns Promise containing map of tool IDs to tool details
2804
2941
  */
2805
- getTools() {
2806
- return this.request("/api/tools");
2942
+ getTools(runtimeContext) {
2943
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2944
+ const searchParams = new URLSearchParams();
2945
+ if (runtimeContextParam) {
2946
+ searchParams.set("runtimeContext", runtimeContextParam);
2947
+ }
2948
+ const queryString = searchParams.toString();
2949
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2807
2950
  }
2808
2951
  /**
2809
2952
  * Gets a tool instance by ID
@@ -2813,27 +2956,19 @@ var MastraClient = class extends BaseResource {
2813
2956
  getTool(toolId) {
2814
2957
  return new Tool(this.options, toolId);
2815
2958
  }
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
2959
  /**
2832
2960
  * Retrieves all available workflows
2961
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2833
2962
  * @returns Promise containing map of workflow IDs to workflow details
2834
2963
  */
2835
- getWorkflows() {
2836
- return this.request("/api/workflows");
2964
+ getWorkflows(runtimeContext) {
2965
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2966
+ const searchParams = new URLSearchParams();
2967
+ if (runtimeContextParam) {
2968
+ searchParams.set("runtimeContext", runtimeContextParam);
2969
+ }
2970
+ const queryString = searchParams.toString();
2971
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2837
2972
  }
2838
2973
  /**
2839
2974
  * Gets a workflow instance by ID
@@ -2959,78 +3094,6 @@ var MastraClient = class extends BaseResource {
2959
3094
  getLogTransports() {
2960
3095
  return this.request("/api/logs/transports");
2961
3096
  }
2962
- /**
2963
- * List of all traces (paged)
2964
- * @param params - Parameters for filtering traces
2965
- * @returns Promise containing telemetry data
2966
- */
2967
- getTelemetry(params) {
2968
- const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
2969
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
2970
- const searchParams = new URLSearchParams();
2971
- if (name) {
2972
- searchParams.set("name", name);
2973
- }
2974
- if (scope) {
2975
- searchParams.set("scope", scope);
2976
- }
2977
- if (page) {
2978
- searchParams.set("page", String(page));
2979
- }
2980
- if (perPage) {
2981
- searchParams.set("perPage", String(perPage));
2982
- }
2983
- if (_attribute) {
2984
- if (Array.isArray(_attribute)) {
2985
- for (const attr of _attribute) {
2986
- searchParams.append("attribute", attr);
2987
- }
2988
- } else {
2989
- searchParams.set("attribute", _attribute);
2990
- }
2991
- }
2992
- if (fromDate) {
2993
- searchParams.set("fromDate", fromDate.toISOString());
2994
- }
2995
- if (toDate) {
2996
- searchParams.set("toDate", toDate.toISOString());
2997
- }
2998
- if (searchParams.size) {
2999
- return this.request(`/api/telemetry?${searchParams}`);
3000
- } else {
3001
- return this.request(`/api/telemetry`);
3002
- }
3003
- }
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
- /**
3012
- * Retrieves all available vNext networks
3013
- * @returns Promise containing map of vNext network IDs to vNext network details
3014
- */
3015
- getVNextNetworks() {
3016
- return this.request("/api/networks/v-next");
3017
- }
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
- /**
3027
- * Gets a vNext network instance by ID
3028
- * @param networkId - ID of the vNext network to retrieve
3029
- * @returns vNext Network instance
3030
- */
3031
- getVNextNetwork(networkId) {
3032
- return new VNextNetwork(this.options, networkId);
3033
- }
3034
3097
  /**
3035
3098
  * Retrieves a list of available MCP servers.
3036
3099
  * @param params - Optional parameters for pagination (limit, offset).
@@ -3101,6 +3164,26 @@ var MastraClient = class extends BaseResource {
3101
3164
  }) {
3102
3165
  return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3103
3166
  }
3167
+ searchMemory({
3168
+ agentId,
3169
+ resourceId,
3170
+ threadId,
3171
+ searchQuery,
3172
+ memoryConfig
3173
+ }) {
3174
+ const params = new URLSearchParams({
3175
+ searchQuery,
3176
+ resourceId,
3177
+ agentId
3178
+ });
3179
+ if (threadId) {
3180
+ params.append("threadId", threadId);
3181
+ }
3182
+ if (memoryConfig) {
3183
+ params.append("memoryConfig", JSON.stringify(memoryConfig));
3184
+ }
3185
+ return this.request(`/api/memory/search?${params}`);
3186
+ }
3104
3187
  /**
3105
3188
  * Updates the working memory for a specific thread (optionally resource-scoped).
3106
3189
  * @param agentId - ID of the agent.
@@ -3135,7 +3218,7 @@ var MastraClient = class extends BaseResource {
3135
3218
  * @returns Promise containing the scorer
3136
3219
  */
3137
3220
  getScorer(scorerId) {
3138
- return this.request(`/api/scores/scorers/${scorerId}`);
3221
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3139
3222
  }
3140
3223
  getScoresByScorerId(params) {
3141
3224
  const { page, perPage, scorerId, entityId, entityType } = params;
@@ -3153,7 +3236,7 @@ var MastraClient = class extends BaseResource {
3153
3236
  searchParams.set("perPage", String(perPage));
3154
3237
  }
3155
3238
  const queryString = searchParams.toString();
3156
- return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
3239
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3157
3240
  }
3158
3241
  /**
3159
3242
  * Retrieves scores by run ID
@@ -3170,7 +3253,7 @@ var MastraClient = class extends BaseResource {
3170
3253
  searchParams.set("perPage", String(perPage));
3171
3254
  }
3172
3255
  const queryString = searchParams.toString();
3173
- return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
3256
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3174
3257
  }
3175
3258
  /**
3176
3259
  * Retrieves scores by entity ID and type
@@ -3187,7 +3270,9 @@ var MastraClient = class extends BaseResource {
3187
3270
  searchParams.set("perPage", String(perPage));
3188
3271
  }
3189
3272
  const queryString = searchParams.toString();
3190
- return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
3273
+ return this.request(
3274
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3275
+ );
3191
3276
  }
3192
3277
  /**
3193
3278
  * Saves a score
@@ -3213,8 +3298,35 @@ var MastraClient = class extends BaseResource {
3213
3298
  getAITraces(params) {
3214
3299
  return this.observability.getTraces(params);
3215
3300
  }
3301
+ getScoresBySpan(params) {
3302
+ return this.observability.getScoresBySpan(params);
3303
+ }
3304
+ score(params) {
3305
+ return this.observability.score(params);
3306
+ }
3216
3307
  };
3217
3308
 
3309
+ // src/tools.ts
3310
+ var ClientTool = class {
3311
+ id;
3312
+ description;
3313
+ inputSchema;
3314
+ outputSchema;
3315
+ execute;
3316
+ constructor(opts) {
3317
+ this.id = opts.id;
3318
+ this.description = opts.description;
3319
+ this.inputSchema = opts.inputSchema;
3320
+ this.outputSchema = opts.outputSchema;
3321
+ this.execute = opts.execute;
3322
+ }
3323
+ };
3324
+ function createTool(opts) {
3325
+ return new ClientTool(opts);
3326
+ }
3327
+
3328
+ exports.ClientTool = ClientTool;
3218
3329
  exports.MastraClient = MastraClient;
3330
+ exports.createTool = createTool;
3219
3331
  //# sourceMappingURL=index.cjs.map
3220
3332
  //# sourceMappingURL=index.cjs.map