@mastra/client-js 0.0.0-vector-query-tool-provider-options-20250828222356 → 0.0.0-vector-extension-schema-20250922130418

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 (81) hide show
  1. package/CHANGELOG.md +429 -4
  2. package/README.md +7 -9
  3. package/dist/client.d.ts +37 -21
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +871 -417
  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 +869 -417
  10. package/dist/index.js.map +1 -1
  11. package/dist/resources/agent-builder.d.ts +160 -0
  12. package/dist/resources/agent-builder.d.ts.map +1 -0
  13. package/dist/resources/agent.d.ts +56 -11
  14. package/dist/resources/agent.d.ts.map +1 -1
  15. package/dist/resources/index.d.ts +1 -1
  16. package/dist/resources/index.d.ts.map +1 -1
  17. package/dist/resources/legacy-workflow.d.ts +5 -2
  18. package/dist/resources/legacy-workflow.d.ts.map +1 -1
  19. package/dist/resources/mcp-tool.d.ts +2 -1
  20. package/dist/resources/mcp-tool.d.ts.map +1 -1
  21. package/dist/resources/observability.d.ts.map +1 -1
  22. package/dist/resources/tool.d.ts +2 -1
  23. package/dist/resources/tool.d.ts.map +1 -1
  24. package/dist/resources/vNextNetwork.d.ts +2 -1
  25. package/dist/resources/vNextNetwork.d.ts.map +1 -1
  26. package/dist/resources/vector.d.ts +5 -2
  27. package/dist/resources/vector.d.ts.map +1 -1
  28. package/dist/resources/workflow.d.ts +110 -10
  29. package/dist/resources/workflow.d.ts.map +1 -1
  30. package/dist/tools.d.ts +22 -0
  31. package/dist/tools.d.ts.map +1 -0
  32. package/dist/types.d.ts +36 -21
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/utils/index.d.ts +2 -0
  35. package/dist/utils/index.d.ts.map +1 -1
  36. package/dist/utils/process-mastra-stream.d.ts +5 -1
  37. package/dist/utils/process-mastra-stream.d.ts.map +1 -1
  38. package/package.json +19 -15
  39. package/.turbo/turbo-build.log +0 -18
  40. package/dist/adapters/agui.d.ts +0 -23
  41. package/dist/adapters/agui.d.ts.map +0 -1
  42. package/dist/resources/network.d.ts +0 -30
  43. package/dist/resources/network.d.ts.map +0 -1
  44. package/eslint.config.js +0 -11
  45. package/integration-tests/agui-adapter.test.ts +0 -122
  46. package/integration-tests/package.json +0 -18
  47. package/integration-tests/src/mastra/index.ts +0 -35
  48. package/integration-tests/vitest.config.ts +0 -9
  49. package/src/adapters/agui.test.ts +0 -293
  50. package/src/adapters/agui.ts +0 -257
  51. package/src/client.ts +0 -644
  52. package/src/example.ts +0 -95
  53. package/src/index.test.ts +0 -1253
  54. package/src/index.ts +0 -3
  55. package/src/resources/a2a.ts +0 -98
  56. package/src/resources/agent.ts +0 -1460
  57. package/src/resources/base.ts +0 -77
  58. package/src/resources/index.ts +0 -11
  59. package/src/resources/legacy-workflow.ts +0 -242
  60. package/src/resources/mcp-tool.ts +0 -48
  61. package/src/resources/memory-thread.test.ts +0 -285
  62. package/src/resources/memory-thread.ts +0 -99
  63. package/src/resources/network-memory-thread.test.ts +0 -269
  64. package/src/resources/network-memory-thread.ts +0 -81
  65. package/src/resources/network.ts +0 -86
  66. package/src/resources/observability.ts +0 -53
  67. package/src/resources/tool.ts +0 -45
  68. package/src/resources/vNextNetwork.ts +0 -194
  69. package/src/resources/vector.ts +0 -83
  70. package/src/resources/workflow.ts +0 -410
  71. package/src/types.ts +0 -534
  72. package/src/utils/index.ts +0 -11
  73. package/src/utils/process-client-tools.ts +0 -32
  74. package/src/utils/process-mastra-stream.test.ts +0 -353
  75. package/src/utils/process-mastra-stream.ts +0 -49
  76. package/src/utils/zod-to-json-schema.ts +0 -30
  77. package/src/v2-messages.test.ts +0 -180
  78. package/tsconfig.build.json +0 -9
  79. package/tsconfig.json +0 -5
  80. package/tsup.config.ts +0 -17
  81. package/vitest.config.js +0 -8
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import { AbstractAgent, EventType } from '@ag-ui/client';
2
- import { Observable } from 'rxjs';
3
1
  import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
4
2
  import { v4 } from '@lukeed/uuid';
5
3
  import { RuntimeContext } from '@mastra/core/runtime-context';
@@ -7,205 +5,7 @@ import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
7
5
  import { z } from 'zod';
8
6
  import originalZodToJsonSchema from 'zod-to-json-schema';
9
7
 
10
- // src/adapters/agui.ts
11
- var AGUIAdapter = class extends AbstractAgent {
12
- agent;
13
- resourceId;
14
- constructor({ agent, agentId, resourceId, ...rest }) {
15
- super({
16
- agentId,
17
- ...rest
18
- });
19
- this.agent = agent;
20
- this.resourceId = resourceId;
21
- }
22
- run(input) {
23
- return new Observable((subscriber) => {
24
- const convertedMessages = convertMessagesToMastraMessages(input.messages);
25
- subscriber.next({
26
- type: EventType.RUN_STARTED,
27
- threadId: input.threadId,
28
- runId: input.runId
29
- });
30
- this.agent.stream({
31
- threadId: input.threadId,
32
- resourceId: this.resourceId ?? "",
33
- runId: input.runId,
34
- messages: convertedMessages,
35
- clientTools: input.tools.reduce(
36
- (acc, tool) => {
37
- acc[tool.name] = {
38
- id: tool.name,
39
- description: tool.description,
40
- inputSchema: tool.parameters
41
- };
42
- return acc;
43
- },
44
- {}
45
- )
46
- }).then((response) => {
47
- let currentMessageId = void 0;
48
- let isInTextMessage = false;
49
- return response.processDataStream({
50
- onTextPart: (text) => {
51
- if (currentMessageId === void 0) {
52
- currentMessageId = generateUUID();
53
- const message2 = {
54
- type: EventType.TEXT_MESSAGE_START,
55
- messageId: currentMessageId,
56
- role: "assistant"
57
- };
58
- subscriber.next(message2);
59
- isInTextMessage = true;
60
- }
61
- const message = {
62
- type: EventType.TEXT_MESSAGE_CONTENT,
63
- messageId: currentMessageId,
64
- delta: text
65
- };
66
- subscriber.next(message);
67
- },
68
- onFinishMessagePart: () => {
69
- if (currentMessageId !== void 0) {
70
- const message = {
71
- type: EventType.TEXT_MESSAGE_END,
72
- messageId: currentMessageId
73
- };
74
- subscriber.next(message);
75
- isInTextMessage = false;
76
- }
77
- subscriber.next({
78
- type: EventType.RUN_FINISHED,
79
- threadId: input.threadId,
80
- runId: input.runId
81
- });
82
- subscriber.complete();
83
- },
84
- onToolCallPart(streamPart) {
85
- const parentMessageId = currentMessageId || generateUUID();
86
- if (isInTextMessage) {
87
- const message = {
88
- type: EventType.TEXT_MESSAGE_END,
89
- messageId: parentMessageId
90
- };
91
- subscriber.next(message);
92
- isInTextMessage = false;
93
- }
94
- subscriber.next({
95
- type: EventType.TOOL_CALL_START,
96
- toolCallId: streamPart.toolCallId,
97
- toolCallName: streamPart.toolName,
98
- parentMessageId
99
- });
100
- subscriber.next({
101
- type: EventType.TOOL_CALL_ARGS,
102
- toolCallId: streamPart.toolCallId,
103
- delta: JSON.stringify(streamPart.args),
104
- parentMessageId
105
- });
106
- subscriber.next({
107
- type: EventType.TOOL_CALL_END,
108
- toolCallId: streamPart.toolCallId,
109
- parentMessageId
110
- });
111
- }
112
- });
113
- }).catch((error) => {
114
- console.error("error", error);
115
- subscriber.error(error);
116
- });
117
- return () => {
118
- };
119
- });
120
- }
121
- };
122
- function generateUUID() {
123
- if (typeof crypto !== "undefined") {
124
- if (typeof crypto.randomUUID === "function") {
125
- return crypto.randomUUID();
126
- }
127
- if (typeof crypto.getRandomValues === "function") {
128
- const buffer = new Uint8Array(16);
129
- crypto.getRandomValues(buffer);
130
- buffer[6] = buffer[6] & 15 | 64;
131
- buffer[8] = buffer[8] & 63 | 128;
132
- let hex = "";
133
- for (let i = 0; i < 16; i++) {
134
- hex += buffer[i].toString(16).padStart(2, "0");
135
- if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
136
- }
137
- return hex;
138
- }
139
- }
140
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
141
- const r = Math.random() * 16 | 0;
142
- const v = c === "x" ? r : r & 3 | 8;
143
- return v.toString(16);
144
- });
145
- }
146
- function convertMessagesToMastraMessages(messages) {
147
- const result = [];
148
- const toolCallsWithResults = /* @__PURE__ */ new Set();
149
- for (const message of messages) {
150
- if (message.role === "tool" && message.toolCallId) {
151
- toolCallsWithResults.add(message.toolCallId);
152
- }
153
- }
154
- for (const message of messages) {
155
- if (message.role === "assistant") {
156
- const parts = message.content ? [{ type: "text", text: message.content }] : [];
157
- for (const toolCall of message.toolCalls ?? []) {
158
- parts.push({
159
- type: "tool-call",
160
- toolCallId: toolCall.id,
161
- toolName: toolCall.function.name,
162
- args: JSON.parse(toolCall.function.arguments)
163
- });
164
- }
165
- result.push({
166
- role: "assistant",
167
- content: parts
168
- });
169
- if (message.toolCalls?.length) {
170
- for (const toolCall of message.toolCalls) {
171
- if (!toolCallsWithResults.has(toolCall.id)) {
172
- result.push({
173
- role: "tool",
174
- content: [
175
- {
176
- type: "tool-result",
177
- toolCallId: toolCall.id,
178
- toolName: toolCall.function.name,
179
- result: JSON.parse(toolCall.function.arguments)
180
- // This is still wrong but matches test expectations
181
- }
182
- ]
183
- });
184
- }
185
- }
186
- }
187
- } else if (message.role === "user") {
188
- result.push({
189
- role: "user",
190
- content: message.content || ""
191
- });
192
- } else if (message.role === "tool") {
193
- result.push({
194
- role: "tool",
195
- content: [
196
- {
197
- type: "tool-result",
198
- toolCallId: message.toolCallId || "unknown",
199
- toolName: "unknown",
200
- // toolName is not available in tool messages from CopilotKit
201
- result: message.content
202
- }
203
- ]
204
- });
205
- }
206
- }
207
- return result;
208
- }
8
+ // src/resources/agent.ts
209
9
  function parseClientRuntimeContext(runtimeContext) {
210
10
  if (runtimeContext) {
211
11
  if (runtimeContext instanceof RuntimeContext) {
@@ -215,6 +15,20 @@ function parseClientRuntimeContext(runtimeContext) {
215
15
  }
216
16
  return void 0;
217
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
+ }
218
32
  function isZodType(value) {
219
33
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
220
34
  }
@@ -226,7 +40,7 @@ function zodToJsonSchema(zodSchema) {
226
40
  const fn = "toJSONSchema";
227
41
  return z[fn].call(z, zodSchema);
228
42
  }
229
- return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
43
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
230
44
  }
231
45
 
232
46
  // src/utils/process-client-tools.ts
@@ -259,7 +73,7 @@ function processClientTools(clientTools) {
259
73
  }
260
74
 
261
75
  // src/utils/process-mastra-stream.ts
262
- async function processMastraStream({
76
+ async function sharedProcessMastraStream({
263
77
  stream,
264
78
  onChunk
265
79
  }) {
@@ -277,7 +91,7 @@ async function processMastraStream({
277
91
  if (line.startsWith("data: ")) {
278
92
  const data = line.slice(6);
279
93
  if (data === "[DONE]") {
280
- console.log("\u{1F3C1} Stream finished");
94
+ console.info("\u{1F3C1} Stream finished");
281
95
  return;
282
96
  }
283
97
  try {
@@ -293,6 +107,24 @@ async function processMastraStream({
293
107
  reader.releaseLock();
294
108
  }
295
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
+ }
296
128
 
297
129
  // src/resources/base.ts
298
130
  var BaseResource = class {
@@ -455,17 +287,21 @@ var AgentVoice = class extends BaseResource {
455
287
  }
456
288
  /**
457
289
  * Get available speakers for the agent's voice provider
290
+ * @param runtimeContext - Optional runtime context to pass as query parameter
291
+ * @param runtimeContext - Optional runtime context to pass as query parameter
458
292
  * @returns Promise containing list of available speakers
459
293
  */
460
- getSpeakers() {
461
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
294
+ getSpeakers(runtimeContext) {
295
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
462
296
  }
463
297
  /**
464
298
  * Get the listener configuration 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
465
301
  * @returns Promise containing a check if the agent has listening capabilities
466
302
  */
467
- getListener() {
468
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
303
+ getListener(runtimeContext) {
304
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
469
305
  }
470
306
  };
471
307
  var Agent = class extends BaseResource {
@@ -477,12 +313,19 @@ var Agent = class extends BaseResource {
477
313
  voice;
478
314
  /**
479
315
  * Retrieves details about the agent
316
+ * @param runtimeContext - Optional runtime context to pass as query parameter
480
317
  * @returns Promise containing agent details including model and instructions
481
318
  */
482
- details() {
483
- return this.request(`/api/agents/${this.agentId}`);
319
+ details(runtimeContext) {
320
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
484
321
  }
485
322
  async generate(params) {
323
+ console.warn(
324
+ "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 23rd, 2025. Please use generateLegacy if you don't want to upgrade just yet."
325
+ );
326
+ return this.generateLegacy(params);
327
+ }
328
+ async generateLegacy(params) {
486
329
  const processedParams = {
487
330
  ...params,
488
331
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -492,7 +335,7 @@ var Agent = class extends BaseResource {
492
335
  };
493
336
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
494
337
  const response = await this.request(
495
- `/api/agents/${this.agentId}/generate`,
338
+ `/api/agents/${this.agentId}/generate-legacy`,
496
339
  {
497
340
  method: "POST",
498
341
  body: processedParams
@@ -547,12 +390,25 @@ var Agent = class extends BaseResource {
547
390
  }
548
391
  return response;
549
392
  }
550
- async generateVNext(params) {
393
+ async generateVNext(messagesOrParams, options) {
394
+ let params;
395
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
396
+ params = messagesOrParams;
397
+ } else {
398
+ params = {
399
+ messages: messagesOrParams,
400
+ ...options
401
+ };
402
+ }
551
403
  const processedParams = {
552
404
  ...params,
553
405
  output: params.output ? zodToJsonSchema(params.output) : void 0,
554
406
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
555
- clientTools: processClientTools(params.clientTools)
407
+ clientTools: processClientTools(params.clientTools),
408
+ structuredOutput: params.structuredOutput ? {
409
+ ...params.structuredOutput,
410
+ schema: zodToJsonSchema(params.structuredOutput.schema)
411
+ } : void 0
556
412
  };
557
413
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
558
414
  const response = await this.request(
@@ -843,6 +699,17 @@ var Agent = class extends BaseResource {
843
699
  * @returns Promise containing the enhanced Response object with processDataStream method
844
700
  */
845
701
  async stream(params) {
702
+ console.warn(
703
+ "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 23rd, 2025. Please use streamLegacy if you don't want to upgrade just yet."
704
+ );
705
+ return this.streamLegacy(params);
706
+ }
707
+ /**
708
+ * Streams a response from the agent
709
+ * @param params - Stream parameters including prompt
710
+ * @returns Promise containing the enhanced Response object with processDataStream method
711
+ */
712
+ async streamLegacy(params) {
846
713
  const processedParams = {
847
714
  ...params,
848
715
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1046,7 +913,7 @@ var Agent = class extends BaseResource {
1046
913
  step,
1047
914
  toolCallId: chunk.payload.toolCallId,
1048
915
  toolName: chunk.payload.toolName,
1049
- args: void 0
916
+ args: chunk.payload.args
1050
917
  };
1051
918
  message.toolInvocations.push(invocation);
1052
919
  updateToolInvocationPart(chunk.payload.toolCallId, invocation);
@@ -1100,14 +967,14 @@ var Agent = class extends BaseResource {
1100
967
  }
1101
968
  case "step-finish": {
1102
969
  step += 1;
1103
- currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
970
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
1104
971
  currentReasoningPart = void 0;
1105
972
  currentReasoningTextDetail = void 0;
1106
973
  execUpdate();
1107
974
  break;
1108
975
  }
1109
976
  case "finish": {
1110
- finishReason = chunk.payload.finishReason;
977
+ finishReason = chunk.payload.stepResult.reason;
1111
978
  if (chunk.payload.usage != null) {
1112
979
  usage = chunk.payload.usage;
1113
980
  }
@@ -1131,9 +998,28 @@ var Agent = class extends BaseResource {
1131
998
  let toolCalls = [];
1132
999
  let messages = [];
1133
1000
  const [streamForWritable, streamForProcessing] = response.body.tee();
1134
- streamForWritable.pipeTo(writable, {
1135
- preventClose: true
1136
- }).catch((error) => {
1001
+ streamForWritable.pipeTo(
1002
+ new WritableStream({
1003
+ async write(chunk) {
1004
+ try {
1005
+ const text = new TextDecoder().decode(chunk);
1006
+ if (text.includes("[DONE]")) {
1007
+ return;
1008
+ }
1009
+ } catch {
1010
+ }
1011
+ const writer = writable.getWriter();
1012
+ try {
1013
+ await writer.write(chunk);
1014
+ } finally {
1015
+ writer.releaseLock();
1016
+ }
1017
+ }
1018
+ }),
1019
+ {
1020
+ preventClose: true
1021
+ }
1022
+ ).catch((error) => {
1137
1023
  console.error("Error piping to writable stream:", error);
1138
1024
  });
1139
1025
  this.processChatResponse_vNext({
@@ -1170,7 +1056,8 @@ var Agent = class extends BaseResource {
1170
1056
  toolCallId: toolCall2?.toolCallId
1171
1057
  }
1172
1058
  );
1173
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1059
+ const lastMessageRaw = messages[messages.length - 1];
1060
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
1174
1061
  const toolInvocationPart = lastMessage?.parts?.find(
1175
1062
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
1176
1063
  );
@@ -1188,25 +1075,13 @@ var Agent = class extends BaseResource {
1188
1075
  toolInvocation.state = "result";
1189
1076
  toolInvocation.result = result;
1190
1077
  }
1191
- const writer = writable.getWriter();
1192
- try {
1193
- await writer.write(
1194
- new TextEncoder().encode(
1195
- "a:" + JSON.stringify({
1196
- toolCallId: toolCall2.toolCallId,
1197
- result
1198
- }) + "\n"
1199
- )
1200
- );
1201
- } finally {
1202
- writer.releaseLock();
1203
- }
1204
1078
  const originalMessages = processedParams.messages;
1205
1079
  const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1080
+ const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1206
1081
  this.processStreamResponse_vNext(
1207
1082
  {
1208
1083
  ...processedParams,
1209
- messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
1084
+ messages: updatedMessages
1210
1085
  },
1211
1086
  writable
1212
1087
  ).catch((error) => {
@@ -1229,12 +1104,49 @@ var Agent = class extends BaseResource {
1229
1104
  }
1230
1105
  return response;
1231
1106
  }
1232
- async streamVNext(params) {
1107
+ async network(params) {
1108
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1109
+ method: "POST",
1110
+ body: params,
1111
+ stream: true
1112
+ });
1113
+ if (!response.body) {
1114
+ throw new Error("No response body");
1115
+ }
1116
+ const streamResponse = new Response(response.body, {
1117
+ status: response.status,
1118
+ statusText: response.statusText,
1119
+ headers: response.headers
1120
+ });
1121
+ streamResponse.processDataStream = async ({
1122
+ onChunk
1123
+ }) => {
1124
+ await processMastraNetworkStream({
1125
+ stream: streamResponse.body,
1126
+ onChunk
1127
+ });
1128
+ };
1129
+ return streamResponse;
1130
+ }
1131
+ async streamVNext(messagesOrParams, options) {
1132
+ let params;
1133
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1134
+ params = messagesOrParams;
1135
+ } else {
1136
+ params = {
1137
+ messages: messagesOrParams,
1138
+ ...options
1139
+ };
1140
+ }
1233
1141
  const processedParams = {
1234
1142
  ...params,
1235
1143
  output: params.output ? zodToJsonSchema(params.output) : void 0,
1236
1144
  runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1237
- clientTools: processClientTools(params.clientTools)
1145
+ clientTools: processClientTools(params.clientTools),
1146
+ structuredOutput: params.structuredOutput ? {
1147
+ ...params.structuredOutput,
1148
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1149
+ } : void 0
1238
1150
  };
1239
1151
  const { readable, writable } = new TransformStream();
1240
1152
  const response = await this.processStreamResponse_vNext(processedParams, writable);
@@ -1257,7 +1169,7 @@ var Agent = class extends BaseResource {
1257
1169
  * Processes the stream response and handles tool calls
1258
1170
  */
1259
1171
  async processStreamResponse(processedParams, writable) {
1260
- const response = await this.request(`/api/agents/${this.agentId}/stream`, {
1172
+ const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1261
1173
  method: "POST",
1262
1174
  body: processedParams,
1263
1175
  stream: true
@@ -1370,10 +1282,11 @@ var Agent = class extends BaseResource {
1370
1282
  /**
1371
1283
  * Gets details about a specific tool available to the agent
1372
1284
  * @param toolId - ID of the tool to retrieve
1285
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1373
1286
  * @returns Promise containing tool details
1374
1287
  */
1375
- getTool(toolId) {
1376
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1288
+ getTool(toolId, runtimeContext) {
1289
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1377
1290
  }
1378
1291
  /**
1379
1292
  * Executes a tool for the agent
@@ -1384,7 +1297,7 @@ var Agent = class extends BaseResource {
1384
1297
  executeTool(toolId, params) {
1385
1298
  const body = {
1386
1299
  data: params.data,
1387
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1300
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1388
1301
  };
1389
1302
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1390
1303
  method: "POST",
@@ -1393,17 +1306,19 @@ var Agent = class extends BaseResource {
1393
1306
  }
1394
1307
  /**
1395
1308
  * Retrieves evaluation results for the agent
1309
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1396
1310
  * @returns Promise containing agent evaluations
1397
1311
  */
1398
- evals() {
1399
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1312
+ evals(runtimeContext) {
1313
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1400
1314
  }
1401
1315
  /**
1402
1316
  * Retrieves live evaluation results for the agent
1317
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1403
1318
  * @returns Promise containing live agent evaluations
1404
1319
  */
1405
- liveEvals() {
1406
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1320
+ liveEvals(runtimeContext) {
1321
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1407
1322
  }
1408
1323
  /**
1409
1324
  * Updates the model for the agent
@@ -1417,62 +1332,6 @@ var Agent = class extends BaseResource {
1417
1332
  });
1418
1333
  }
1419
1334
  };
1420
- var Network = class extends BaseResource {
1421
- constructor(options, networkId) {
1422
- super(options);
1423
- this.networkId = networkId;
1424
- }
1425
- /**
1426
- * Retrieves details about the network
1427
- * @returns Promise containing network details
1428
- */
1429
- details() {
1430
- return this.request(`/api/networks/${this.networkId}`);
1431
- }
1432
- /**
1433
- * Generates a response from the agent
1434
- * @param params - Generation parameters including prompt
1435
- * @returns Promise containing the generated response
1436
- */
1437
- generate(params) {
1438
- const processedParams = {
1439
- ...params,
1440
- output: zodToJsonSchema(params.output),
1441
- experimental_output: zodToJsonSchema(params.experimental_output)
1442
- };
1443
- return this.request(`/api/networks/${this.networkId}/generate`, {
1444
- method: "POST",
1445
- body: processedParams
1446
- });
1447
- }
1448
- /**
1449
- * Streams a response from the agent
1450
- * @param params - Stream parameters including prompt
1451
- * @returns Promise containing the enhanced Response object with processDataStream method
1452
- */
1453
- async stream(params) {
1454
- const processedParams = {
1455
- ...params,
1456
- output: zodToJsonSchema(params.output),
1457
- experimental_output: zodToJsonSchema(params.experimental_output)
1458
- };
1459
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1460
- method: "POST",
1461
- body: processedParams,
1462
- stream: true
1463
- });
1464
- if (!response.body) {
1465
- throw new Error("No response body");
1466
- }
1467
- response.processDataStream = async (options = {}) => {
1468
- await processDataStream({
1469
- stream: response.body,
1470
- ...options
1471
- });
1472
- };
1473
- return response;
1474
- }
1475
- };
1476
1335
 
1477
1336
  // src/resources/memory-thread.ts
1478
1337
  var MemoryThread = class extends BaseResource {
@@ -1561,10 +1420,13 @@ var Vector = class extends BaseResource {
1561
1420
  /**
1562
1421
  * Retrieves details about a specific vector index
1563
1422
  * @param indexName - Name of the index to get details for
1423
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1564
1424
  * @returns Promise containing vector index details
1565
1425
  */
1566
- details(indexName) {
1567
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1426
+ details(indexName, runtimeContext) {
1427
+ return this.request(
1428
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1429
+ );
1568
1430
  }
1569
1431
  /**
1570
1432
  * Deletes a vector index
@@ -1578,10 +1440,11 @@ var Vector = class extends BaseResource {
1578
1440
  }
1579
1441
  /**
1580
1442
  * Retrieves a list of all available indexes
1443
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1581
1444
  * @returns Promise containing array of index names
1582
1445
  */
1583
- getIndexes() {
1584
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1446
+ getIndexes(runtimeContext) {
1447
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1585
1448
  }
1586
1449
  /**
1587
1450
  * Creates a new vector index
@@ -1627,17 +1490,20 @@ var LegacyWorkflow = class extends BaseResource {
1627
1490
  }
1628
1491
  /**
1629
1492
  * Retrieves details about the legacy workflow
1493
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1630
1494
  * @returns Promise containing legacy workflow details including steps and graphs
1631
1495
  */
1632
- details() {
1633
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1496
+ details(runtimeContext) {
1497
+ return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1634
1498
  }
1635
1499
  /**
1636
1500
  * Retrieves all runs for a legacy workflow
1637
1501
  * @param params - Parameters for filtering runs
1502
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1638
1503
  * @returns Promise containing legacy workflow runs array
1639
1504
  */
1640
- runs(params) {
1505
+ runs(params, runtimeContext) {
1506
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1641
1507
  const searchParams = new URLSearchParams();
1642
1508
  if (params?.fromDate) {
1643
1509
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1654,6 +1520,9 @@ var LegacyWorkflow = class extends BaseResource {
1654
1520
  if (params?.resourceId) {
1655
1521
  searchParams.set("resourceId", params.resourceId);
1656
1522
  }
1523
+ if (runtimeContextParam) {
1524
+ searchParams.set("runtimeContext", runtimeContextParam);
1525
+ }
1657
1526
  if (searchParams.size) {
1658
1527
  return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1659
1528
  } else {
@@ -1807,10 +1676,11 @@ var Tool = class extends BaseResource {
1807
1676
  }
1808
1677
  /**
1809
1678
  * Retrieves details about the tool
1679
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1810
1680
  * @returns Promise containing tool details including description and schemas
1811
1681
  */
1812
- details() {
1813
- return this.request(`/api/tools/${this.toolId}`);
1682
+ details(runtimeContext) {
1683
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1814
1684
  }
1815
1685
  /**
1816
1686
  * Executes the tool with the provided parameters
@@ -1887,17 +1757,20 @@ var Workflow = class extends BaseResource {
1887
1757
  }
1888
1758
  /**
1889
1759
  * Retrieves details about the workflow
1760
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1890
1761
  * @returns Promise containing workflow details including steps and graphs
1891
1762
  */
1892
- details() {
1893
- return this.request(`/api/workflows/${this.workflowId}`);
1763
+ details(runtimeContext) {
1764
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1894
1765
  }
1895
1766
  /**
1896
1767
  * Retrieves all runs for a workflow
1897
1768
  * @param params - Parameters for filtering runs
1769
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1898
1770
  * @returns Promise containing workflow runs array
1899
1771
  */
1900
- runs(params) {
1772
+ runs(params, runtimeContext) {
1773
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1901
1774
  const searchParams = new URLSearchParams();
1902
1775
  if (params?.fromDate) {
1903
1776
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1914,6 +1787,9 @@ var Workflow = class extends BaseResource {
1914
1787
  if (params?.resourceId) {
1915
1788
  searchParams.set("resourceId", params.resourceId);
1916
1789
  }
1790
+ if (runtimeContextParam) {
1791
+ searchParams.set("runtimeContext", runtimeContextParam);
1792
+ }
1917
1793
  if (searchParams.size) {
1918
1794
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1919
1795
  } else {
@@ -1923,18 +1799,22 @@ var Workflow = class extends BaseResource {
1923
1799
  /**
1924
1800
  * Retrieves a specific workflow run by its ID
1925
1801
  * @param runId - The ID of the workflow run to retrieve
1802
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1926
1803
  * @returns Promise containing the workflow run details
1927
1804
  */
1928
- runById(runId) {
1929
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1805
+ runById(runId, runtimeContext) {
1806
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1930
1807
  }
1931
1808
  /**
1932
1809
  * Retrieves the execution result for a specific workflow run by its ID
1933
1810
  * @param runId - The ID of the workflow run to retrieve the execution result for
1811
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1934
1812
  * @returns Promise containing the workflow run execution result
1935
1813
  */
1936
- runExecutionResult(runId) {
1937
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1814
+ runExecutionResult(runId, runtimeContext) {
1815
+ return this.request(
1816
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1817
+ );
1938
1818
  }
1939
1819
  /**
1940
1820
  * Cancels a specific workflow run by its ID
@@ -1957,27 +1837,61 @@ var Workflow = class extends BaseResource {
1957
1837
  body: { event: params.event, data: params.data }
1958
1838
  });
1959
1839
  }
1840
+ /**
1841
+ * @deprecated Use createRunAsync() instead.
1842
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1843
+ */
1844
+ async createRun(_params) {
1845
+ throw new Error(
1846
+ "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."
1847
+ );
1848
+ }
1960
1849
  /**
1961
1850
  * Creates a new workflow run
1962
1851
  * @param params - Optional object containing the optional runId
1963
- * @returns Promise containing the runId of the created run
1852
+ * @returns Promise containing the runId of the created run with methods to control execution
1964
1853
  */
1965
- createRun(params) {
1854
+ async createRunAsync(params) {
1966
1855
  const searchParams = new URLSearchParams();
1967
1856
  if (!!params?.runId) {
1968
1857
  searchParams.set("runId", params.runId);
1969
1858
  }
1970
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1971
- method: "POST"
1972
- });
1973
- }
1974
- /**
1975
- * Creates a new workflow run (alias for createRun)
1976
- * @param params - Optional object containing the optional runId
1977
- * @returns Promise containing the runId of the created run
1978
- */
1979
- createRunAsync(params) {
1980
- return this.createRun(params);
1859
+ const res = await this.request(
1860
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1861
+ {
1862
+ method: "POST"
1863
+ }
1864
+ );
1865
+ const runId = res.runId;
1866
+ return {
1867
+ runId,
1868
+ start: async (p) => {
1869
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1870
+ },
1871
+ startAsync: async (p) => {
1872
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1873
+ },
1874
+ watch: async (onRecord) => {
1875
+ return this.watch({ runId }, onRecord);
1876
+ },
1877
+ stream: async (p) => {
1878
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1879
+ },
1880
+ resume: async (p) => {
1881
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1882
+ },
1883
+ resumeAsync: async (p) => {
1884
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1885
+ },
1886
+ resumeStreamVNext: async (p) => {
1887
+ return this.resumeStreamVNext({
1888
+ runId,
1889
+ step: p.step,
1890
+ resumeData: p.resumeData,
1891
+ runtimeContext: p.runtimeContext
1892
+ });
1893
+ }
1894
+ };
1981
1895
  }
1982
1896
  /**
1983
1897
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -2005,7 +1919,6 @@ var Workflow = class extends BaseResource {
2005
1919
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
2006
1920
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
2007
1921
  method: "POST",
2008
- stream: true,
2009
1922
  body: {
2010
1923
  step,
2011
1924
  resumeData,
@@ -2049,7 +1962,7 @@ var Workflow = class extends BaseResource {
2049
1962
  }
2050
1963
  );
2051
1964
  if (!response.ok) {
2052
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1965
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
2053
1966
  }
2054
1967
  if (!response.body) {
2055
1968
  throw new Error("Response body is null");
@@ -2081,55 +1994,169 @@ var Workflow = class extends BaseResource {
2081
1994
  return response.body.pipeThrough(transformStream);
2082
1995
  }
2083
1996
  /**
2084
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2085
- * @param params - Object containing the runId, step, resumeData and runtimeContext
2086
- * @returns Promise containing the workflow resume results
1997
+ * Observes workflow stream for a workflow run
1998
+ * @param params - Object containing the runId
1999
+ * @returns Promise containing the workflow execution results
2087
2000
  */
2088
- resumeAsync(params) {
2089
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2090
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2091
- method: "POST",
2092
- body: {
2093
- step: params.step,
2094
- resumeData: params.resumeData,
2095
- runtimeContext
2001
+ async observeStream(params) {
2002
+ const searchParams = new URLSearchParams();
2003
+ searchParams.set("runId", params.runId);
2004
+ const response = await this.request(
2005
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
2006
+ {
2007
+ method: "POST",
2008
+ stream: true
2096
2009
  }
2097
- });
2098
- }
2099
- /**
2100
- * Watches workflow transitions in real-time
2101
- * @param runId - Optional run ID to filter the watch stream
2102
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2103
- */
2104
- async watch({ runId }, onRecord) {
2105
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2106
- stream: true
2107
- });
2010
+ );
2108
2011
  if (!response.ok) {
2109
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
2012
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
2110
2013
  }
2111
2014
  if (!response.body) {
2112
2015
  throw new Error("Response body is null");
2113
2016
  }
2114
- for await (const record of this.streamProcessor(response.body)) {
2115
- if (typeof record === "string") {
2116
- onRecord(JSON.parse(record));
2117
- } else {
2118
- onRecord(record);
2119
- }
2120
- }
2121
- }
2122
- /**
2123
- * Creates a new ReadableStream from an iterable or async iterable of objects,
2124
- * serializing each as JSON and separating them with the record separator (\x1E).
2125
- *
2126
- * @param records - An iterable or async iterable of objects to stream
2127
- * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
2128
- */
2129
- static createRecordStream(records) {
2130
- const encoder = new TextEncoder();
2131
- return new ReadableStream({
2132
- async start(controller) {
2017
+ let failedChunk = void 0;
2018
+ const transformStream = new TransformStream({
2019
+ start() {
2020
+ },
2021
+ async transform(chunk, controller) {
2022
+ try {
2023
+ const decoded = new TextDecoder().decode(chunk);
2024
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2025
+ for (const chunk2 of chunks) {
2026
+ if (chunk2) {
2027
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2028
+ try {
2029
+ const parsedChunk = JSON.parse(newChunk);
2030
+ controller.enqueue(parsedChunk);
2031
+ failedChunk = void 0;
2032
+ } catch {
2033
+ failedChunk = newChunk;
2034
+ }
2035
+ }
2036
+ }
2037
+ } catch {
2038
+ }
2039
+ }
2040
+ });
2041
+ return response.body.pipeThrough(transformStream);
2042
+ }
2043
+ /**
2044
+ * Starts a workflow run and returns a stream
2045
+ * @param params - Object containing the optional runId, inputData and runtimeContext
2046
+ * @returns Promise containing the workflow execution results
2047
+ */
2048
+ async streamVNext(params) {
2049
+ const searchParams = new URLSearchParams();
2050
+ if (!!params?.runId) {
2051
+ searchParams.set("runId", params.runId);
2052
+ }
2053
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2054
+ const response = await this.request(
2055
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
2056
+ {
2057
+ method: "POST",
2058
+ body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
2059
+ stream: true
2060
+ }
2061
+ );
2062
+ if (!response.ok) {
2063
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2064
+ }
2065
+ if (!response.body) {
2066
+ throw new Error("Response body is null");
2067
+ }
2068
+ let failedChunk = void 0;
2069
+ const transformStream = new TransformStream({
2070
+ start() {
2071
+ },
2072
+ async transform(chunk, controller) {
2073
+ try {
2074
+ const decoded = new TextDecoder().decode(chunk);
2075
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2076
+ for (const chunk2 of chunks) {
2077
+ if (chunk2) {
2078
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2079
+ try {
2080
+ const parsedChunk = JSON.parse(newChunk);
2081
+ controller.enqueue(parsedChunk);
2082
+ failedChunk = void 0;
2083
+ } catch {
2084
+ failedChunk = newChunk;
2085
+ }
2086
+ }
2087
+ }
2088
+ } catch {
2089
+ }
2090
+ }
2091
+ });
2092
+ return response.body.pipeThrough(transformStream);
2093
+ }
2094
+ /**
2095
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2096
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2097
+ * @returns Promise containing the workflow resume results
2098
+ */
2099
+ resumeAsync(params) {
2100
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2101
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2102
+ method: "POST",
2103
+ body: {
2104
+ step: params.step,
2105
+ resumeData: params.resumeData,
2106
+ runtimeContext
2107
+ }
2108
+ });
2109
+ }
2110
+ /**
2111
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2112
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2113
+ * @returns Promise containing the workflow resume results
2114
+ */
2115
+ resumeStreamVNext(params) {
2116
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2117
+ return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
2118
+ method: "POST",
2119
+ body: {
2120
+ step: params.step,
2121
+ resumeData: params.resumeData,
2122
+ runtimeContext
2123
+ }
2124
+ });
2125
+ }
2126
+ /**
2127
+ * Watches workflow transitions in real-time
2128
+ * @param runId - Optional run ID to filter the watch stream
2129
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2130
+ */
2131
+ async watch({ runId }, onRecord) {
2132
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2133
+ stream: true
2134
+ });
2135
+ if (!response.ok) {
2136
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
2137
+ }
2138
+ if (!response.body) {
2139
+ throw new Error("Response body is null");
2140
+ }
2141
+ for await (const record of this.streamProcessor(response.body)) {
2142
+ if (typeof record === "string") {
2143
+ onRecord(JSON.parse(record));
2144
+ } else {
2145
+ onRecord(record);
2146
+ }
2147
+ }
2148
+ }
2149
+ /**
2150
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
2151
+ * serializing each as JSON and separating them with the record separator (\x1E).
2152
+ *
2153
+ * @param records - An iterable or async iterable of objects to stream
2154
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
2155
+ */
2156
+ static createRecordStream(records) {
2157
+ const encoder = new TextEncoder();
2158
+ return new ReadableStream({
2159
+ async start(controller) {
2133
2160
  try {
2134
2161
  for await (const record of records) {
2135
2162
  const json = JSON.stringify(record) + RECORD_SEPARATOR2;
@@ -2230,10 +2257,11 @@ var MCPTool = class extends BaseResource {
2230
2257
  }
2231
2258
  /**
2232
2259
  * Retrieves details about this specific tool from the MCP server.
2260
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2233
2261
  * @returns Promise containing the tool's information (name, description, schema).
2234
2262
  */
2235
- details() {
2236
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2263
+ details(runtimeContext) {
2264
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2237
2265
  }
2238
2266
  /**
2239
2267
  * Executes this specific tool on the MCP server.
@@ -2253,6 +2281,375 @@ var MCPTool = class extends BaseResource {
2253
2281
  }
2254
2282
  };
2255
2283
 
2284
+ // src/resources/agent-builder.ts
2285
+ var RECORD_SEPARATOR3 = "";
2286
+ var AgentBuilder = class extends BaseResource {
2287
+ constructor(options, actionId) {
2288
+ super(options);
2289
+ this.actionId = actionId;
2290
+ }
2291
+ // Helper function to transform workflow result to action result
2292
+ transformWorkflowResult(result) {
2293
+ if (result.status === "success") {
2294
+ return {
2295
+ success: result.result.success || false,
2296
+ applied: result.result.applied || false,
2297
+ branchName: result.result.branchName,
2298
+ message: result.result.message || "Agent builder action completed",
2299
+ validationResults: result.result.validationResults,
2300
+ error: result.result.error,
2301
+ errors: result.result.errors,
2302
+ stepResults: result.result.stepResults
2303
+ };
2304
+ } else if (result.status === "failed") {
2305
+ return {
2306
+ success: false,
2307
+ applied: false,
2308
+ message: `Agent builder action failed: ${result.error.message}`,
2309
+ error: result.error.message
2310
+ };
2311
+ } else {
2312
+ return {
2313
+ success: false,
2314
+ applied: false,
2315
+ message: "Agent builder action was suspended",
2316
+ error: "Workflow suspended - manual intervention required"
2317
+ };
2318
+ }
2319
+ }
2320
+ /**
2321
+ * @deprecated Use createRunAsync() instead.
2322
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2323
+ */
2324
+ async createRun(_params) {
2325
+ throw new Error(
2326
+ "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."
2327
+ );
2328
+ }
2329
+ /**
2330
+ * Creates a new agent builder action run and returns the runId.
2331
+ * This calls `/api/agent-builder/:actionId/create-run`.
2332
+ */
2333
+ async createRunAsync(params) {
2334
+ const searchParams = new URLSearchParams();
2335
+ if (!!params?.runId) {
2336
+ searchParams.set("runId", params.runId);
2337
+ }
2338
+ const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2339
+ return this.request(url, {
2340
+ method: "POST"
2341
+ });
2342
+ }
2343
+ /**
2344
+ * Starts agent builder action asynchronously and waits for completion.
2345
+ * This calls `/api/agent-builder/:actionId/start-async`.
2346
+ */
2347
+ async startAsync(params, runId) {
2348
+ const searchParams = new URLSearchParams();
2349
+ if (runId) {
2350
+ searchParams.set("runId", runId);
2351
+ }
2352
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2353
+ const { runtimeContext: _, ...actionParams } = params;
2354
+ const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2355
+ const result = await this.request(url, {
2356
+ method: "POST",
2357
+ body: { ...actionParams, runtimeContext }
2358
+ });
2359
+ return this.transformWorkflowResult(result);
2360
+ }
2361
+ /**
2362
+ * Starts an existing agent builder action run.
2363
+ * This calls `/api/agent-builder/:actionId/start`.
2364
+ */
2365
+ async startActionRun(params, runId) {
2366
+ const searchParams = new URLSearchParams();
2367
+ searchParams.set("runId", runId);
2368
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2369
+ const { runtimeContext: _, ...actionParams } = params;
2370
+ const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2371
+ return this.request(url, {
2372
+ method: "POST",
2373
+ body: { ...actionParams, runtimeContext }
2374
+ });
2375
+ }
2376
+ /**
2377
+ * Resumes a suspended agent builder action step.
2378
+ * This calls `/api/agent-builder/:actionId/resume`.
2379
+ */
2380
+ async resume(params, runId) {
2381
+ const searchParams = new URLSearchParams();
2382
+ searchParams.set("runId", runId);
2383
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2384
+ const { runtimeContext: _, ...resumeParams } = params;
2385
+ const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2386
+ return this.request(url, {
2387
+ method: "POST",
2388
+ body: { ...resumeParams, runtimeContext }
2389
+ });
2390
+ }
2391
+ /**
2392
+ * Resumes a suspended agent builder action step asynchronously.
2393
+ * This calls `/api/agent-builder/:actionId/resume-async`.
2394
+ */
2395
+ async resumeAsync(params, runId) {
2396
+ const searchParams = new URLSearchParams();
2397
+ searchParams.set("runId", runId);
2398
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2399
+ const { runtimeContext: _, ...resumeParams } = params;
2400
+ const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2401
+ const result = await this.request(url, {
2402
+ method: "POST",
2403
+ body: { ...resumeParams, runtimeContext }
2404
+ });
2405
+ return this.transformWorkflowResult(result);
2406
+ }
2407
+ /**
2408
+ * Creates an async generator that processes a readable stream and yields action records
2409
+ * separated by the Record Separator character (\x1E)
2410
+ *
2411
+ * @param stream - The readable stream to process
2412
+ * @returns An async generator that yields parsed records
2413
+ */
2414
+ async *streamProcessor(stream) {
2415
+ const reader = stream.getReader();
2416
+ let doneReading = false;
2417
+ let buffer = "";
2418
+ try {
2419
+ while (!doneReading) {
2420
+ const { done, value } = await reader.read();
2421
+ doneReading = done;
2422
+ if (done && !value) continue;
2423
+ try {
2424
+ const decoded = value ? new TextDecoder().decode(value) : "";
2425
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2426
+ buffer = chunks.pop() || "";
2427
+ for (const chunk of chunks) {
2428
+ if (chunk) {
2429
+ if (typeof chunk === "string") {
2430
+ try {
2431
+ const parsedChunk = JSON.parse(chunk);
2432
+ yield parsedChunk;
2433
+ } catch {
2434
+ }
2435
+ }
2436
+ }
2437
+ }
2438
+ } catch {
2439
+ }
2440
+ }
2441
+ if (buffer) {
2442
+ try {
2443
+ yield JSON.parse(buffer);
2444
+ } catch {
2445
+ }
2446
+ }
2447
+ } finally {
2448
+ reader.cancel().catch(() => {
2449
+ });
2450
+ }
2451
+ }
2452
+ /**
2453
+ * Streams agent builder action progress in real-time.
2454
+ * This calls `/api/agent-builder/:actionId/stream`.
2455
+ */
2456
+ async stream(params, runId) {
2457
+ const searchParams = new URLSearchParams();
2458
+ if (runId) {
2459
+ searchParams.set("runId", runId);
2460
+ }
2461
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2462
+ const { runtimeContext: _, ...actionParams } = params;
2463
+ const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2464
+ const response = await this.request(url, {
2465
+ method: "POST",
2466
+ body: { ...actionParams, runtimeContext },
2467
+ stream: true
2468
+ });
2469
+ if (!response.ok) {
2470
+ throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
2471
+ }
2472
+ if (!response.body) {
2473
+ throw new Error("Response body is null");
2474
+ }
2475
+ let failedChunk = void 0;
2476
+ const transformStream = new TransformStream({
2477
+ start() {
2478
+ },
2479
+ async transform(chunk, controller) {
2480
+ try {
2481
+ const decoded = new TextDecoder().decode(chunk);
2482
+ const chunks = decoded.split(RECORD_SEPARATOR3);
2483
+ for (const chunk2 of chunks) {
2484
+ if (chunk2) {
2485
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2486
+ try {
2487
+ const parsedChunk = JSON.parse(newChunk);
2488
+ controller.enqueue(parsedChunk);
2489
+ failedChunk = void 0;
2490
+ } catch {
2491
+ failedChunk = newChunk;
2492
+ }
2493
+ }
2494
+ }
2495
+ } catch {
2496
+ }
2497
+ }
2498
+ });
2499
+ return response.body.pipeThrough(transformStream);
2500
+ }
2501
+ /**
2502
+ * Streams agent builder action progress in real-time using VNext streaming.
2503
+ * This calls `/api/agent-builder/:actionId/streamVNext`.
2504
+ */
2505
+ async streamVNext(params, runId) {
2506
+ const searchParams = new URLSearchParams();
2507
+ if (runId) {
2508
+ searchParams.set("runId", runId);
2509
+ }
2510
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2511
+ const { runtimeContext: _, ...actionParams } = params;
2512
+ const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2513
+ const response = await this.request(url, {
2514
+ method: "POST",
2515
+ body: { ...actionParams, runtimeContext },
2516
+ stream: true
2517
+ });
2518
+ if (!response.ok) {
2519
+ throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
2520
+ }
2521
+ if (!response.body) {
2522
+ throw new Error("Response body is null");
2523
+ }
2524
+ let failedChunk = void 0;
2525
+ const transformStream = new TransformStream({
2526
+ start() {
2527
+ },
2528
+ async transform(chunk, controller) {
2529
+ try {
2530
+ const decoded = new TextDecoder().decode(chunk);
2531
+ const chunks = decoded.split(RECORD_SEPARATOR3);
2532
+ for (const chunk2 of chunks) {
2533
+ if (chunk2) {
2534
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2535
+ try {
2536
+ const parsedChunk = JSON.parse(newChunk);
2537
+ controller.enqueue(parsedChunk);
2538
+ failedChunk = void 0;
2539
+ } catch {
2540
+ failedChunk = newChunk;
2541
+ }
2542
+ }
2543
+ }
2544
+ } catch {
2545
+ }
2546
+ }
2547
+ });
2548
+ return response.body.pipeThrough(transformStream);
2549
+ }
2550
+ /**
2551
+ * Watches an existing agent builder action run by runId.
2552
+ * This is used for hot reload recovery - it loads the existing run state
2553
+ * and streams any remaining progress.
2554
+ * This calls `/api/agent-builder/:actionId/watch`.
2555
+ */
2556
+ async watch({ runId, eventType }, onRecord) {
2557
+ const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
2558
+ const response = await this.request(url, {
2559
+ method: "GET",
2560
+ stream: true
2561
+ });
2562
+ if (!response.ok) {
2563
+ throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
2564
+ }
2565
+ if (!response.body) {
2566
+ throw new Error("Response body is null");
2567
+ }
2568
+ for await (const record of this.streamProcessor(response.body)) {
2569
+ if (typeof record === "string") {
2570
+ onRecord(JSON.parse(record));
2571
+ } else {
2572
+ onRecord(record);
2573
+ }
2574
+ }
2575
+ }
2576
+ /**
2577
+ * Gets a specific action run by its ID.
2578
+ * This calls `/api/agent-builder/:actionId/runs/:runId`.
2579
+ */
2580
+ async runById(runId) {
2581
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
2582
+ return this.request(url, {
2583
+ method: "GET"
2584
+ });
2585
+ }
2586
+ /**
2587
+ * Gets details about this agent builder action.
2588
+ * This calls `/api/agent-builder/:actionId`.
2589
+ */
2590
+ async details() {
2591
+ const result = await this.request(`/api/agent-builder/${this.actionId}`);
2592
+ return result;
2593
+ }
2594
+ /**
2595
+ * Gets all runs for this agent builder action.
2596
+ * This calls `/api/agent-builder/:actionId/runs`.
2597
+ */
2598
+ async runs(params) {
2599
+ const searchParams = new URLSearchParams();
2600
+ if (params?.fromDate) {
2601
+ searchParams.set("fromDate", params.fromDate.toISOString());
2602
+ }
2603
+ if (params?.toDate) {
2604
+ searchParams.set("toDate", params.toDate.toISOString());
2605
+ }
2606
+ if (params?.limit !== void 0) {
2607
+ searchParams.set("limit", String(params.limit));
2608
+ }
2609
+ if (params?.offset !== void 0) {
2610
+ searchParams.set("offset", String(params.offset));
2611
+ }
2612
+ if (params?.resourceId) {
2613
+ searchParams.set("resourceId", params.resourceId);
2614
+ }
2615
+ const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2616
+ return this.request(url, {
2617
+ method: "GET"
2618
+ });
2619
+ }
2620
+ /**
2621
+ * Gets the execution result of an agent builder action run.
2622
+ * This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
2623
+ */
2624
+ async runExecutionResult(runId) {
2625
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
2626
+ return this.request(url, {
2627
+ method: "GET"
2628
+ });
2629
+ }
2630
+ /**
2631
+ * Cancels an agent builder action run.
2632
+ * This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
2633
+ */
2634
+ async cancelRun(runId) {
2635
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
2636
+ return this.request(url, {
2637
+ method: "POST"
2638
+ });
2639
+ }
2640
+ /**
2641
+ * Sends an event to an agent builder action run.
2642
+ * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
2643
+ */
2644
+ async sendRunEvent(params) {
2645
+ const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2646
+ return this.request(url, {
2647
+ method: "POST",
2648
+ body: { event: params.event, data: params.data }
2649
+ });
2650
+ }
2651
+ };
2652
+
2256
2653
  // src/resources/observability.ts
2257
2654
  var Observability = class extends BaseResource {
2258
2655
  constructor(options) {
@@ -2274,7 +2671,7 @@ var Observability = class extends BaseResource {
2274
2671
  getTraces(params) {
2275
2672
  const { pagination, filters } = params;
2276
2673
  const { page, perPage, dateRange } = pagination || {};
2277
- const { name, spanType } = filters || {};
2674
+ const { name, spanType, entityId, entityType } = filters || {};
2278
2675
  const searchParams = new URLSearchParams();
2279
2676
  if (page !== void 0) {
2280
2677
  searchParams.set("page", String(page));
@@ -2288,6 +2685,10 @@ var Observability = class extends BaseResource {
2288
2685
  if (spanType !== void 0) {
2289
2686
  searchParams.set("spanType", String(spanType));
2290
2687
  }
2688
+ if (entityId && entityType) {
2689
+ searchParams.set("entityId", entityId);
2690
+ searchParams.set("entityType", entityType);
2691
+ }
2291
2692
  if (dateRange) {
2292
2693
  const dateRangeStr = JSON.stringify({
2293
2694
  start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
@@ -2364,7 +2765,7 @@ var NetworkMemoryThread = class extends BaseResource {
2364
2765
  };
2365
2766
 
2366
2767
  // src/resources/vNextNetwork.ts
2367
- var RECORD_SEPARATOR3 = "";
2768
+ var RECORD_SEPARATOR4 = "";
2368
2769
  var VNextNetwork = class extends BaseResource {
2369
2770
  constructor(options, networkId) {
2370
2771
  super(options);
@@ -2372,10 +2773,11 @@ var VNextNetwork = class extends BaseResource {
2372
2773
  }
2373
2774
  /**
2374
2775
  * Retrieves details about the network
2776
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2375
2777
  * @returns Promise containing vNext network details
2376
2778
  */
2377
- details() {
2378
- return this.request(`/api/networks/v-next/${this.networkId}`);
2779
+ details(runtimeContext) {
2780
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2379
2781
  }
2380
2782
  /**
2381
2783
  * Generates a response from the v-next network
@@ -2416,7 +2818,7 @@ var VNextNetwork = class extends BaseResource {
2416
2818
  if (done && !value) continue;
2417
2819
  try {
2418
2820
  const decoded = value ? new TextDecoder().decode(value) : "";
2419
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2821
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2420
2822
  buffer = chunks.pop() || "";
2421
2823
  for (const chunk of chunks) {
2422
2824
  if (chunk) {
@@ -2510,25 +2912,17 @@ var MastraClient = class extends BaseResource {
2510
2912
  }
2511
2913
  /**
2512
2914
  * Retrieves all available agents
2915
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2513
2916
  * @returns Promise containing map of agent IDs to agent details
2514
2917
  */
2515
- getAgents() {
2516
- return this.request("/api/agents");
2517
- }
2518
- async getAGUI({ resourceId }) {
2519
- const agents = await this.getAgents();
2520
- return Object.entries(agents).reduce(
2521
- (acc, [agentId]) => {
2522
- const agent = this.getAgent(agentId);
2523
- acc[agentId] = new AGUIAdapter({
2524
- agentId,
2525
- agent,
2526
- resourceId
2527
- });
2528
- return acc;
2529
- },
2530
- {}
2531
- );
2918
+ getAgents(runtimeContext) {
2919
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2920
+ const searchParams = new URLSearchParams();
2921
+ if (runtimeContextParam) {
2922
+ searchParams.set("runtimeContext", runtimeContextParam);
2923
+ }
2924
+ const queryString = searchParams.toString();
2925
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2532
2926
  }
2533
2927
  /**
2534
2928
  * Gets an agent instance by ID
@@ -2546,6 +2940,14 @@ var MastraClient = class extends BaseResource {
2546
2940
  getMemoryThreads(params) {
2547
2941
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
2548
2942
  }
2943
+ /**
2944
+ * Retrieves memory config for a resource
2945
+ * @param params - Parameters containing the resource ID
2946
+ * @returns Promise containing array of memory threads
2947
+ */
2948
+ getMemoryConfig(params) {
2949
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2950
+ }
2549
2951
  /**
2550
2952
  * Creates a new memory thread
2551
2953
  * @param params - Parameters for creating the memory thread
@@ -2562,6 +2964,24 @@ var MastraClient = class extends BaseResource {
2562
2964
  getMemoryThread(threadId, agentId) {
2563
2965
  return new MemoryThread(this.options, threadId, agentId);
2564
2966
  }
2967
+ getThreadMessages(threadId, opts = {}) {
2968
+ let url = "";
2969
+ if (opts.agentId) {
2970
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2971
+ } else if (opts.networkId) {
2972
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2973
+ }
2974
+ return this.request(url);
2975
+ }
2976
+ deleteThread(threadId, opts = {}) {
2977
+ let url = "";
2978
+ if (opts.agentId) {
2979
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2980
+ } else if (opts.networkId) {
2981
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2982
+ }
2983
+ return this.request(url, { method: "DELETE" });
2984
+ }
2565
2985
  /**
2566
2986
  * Saves messages to memory
2567
2987
  * @param params - Parameters containing messages to save
@@ -2624,10 +3044,17 @@ var MastraClient = class extends BaseResource {
2624
3044
  }
2625
3045
  /**
2626
3046
  * Retrieves all available tools
3047
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2627
3048
  * @returns Promise containing map of tool IDs to tool details
2628
3049
  */
2629
- getTools() {
2630
- return this.request("/api/tools");
3050
+ getTools(runtimeContext) {
3051
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3052
+ const searchParams = new URLSearchParams();
3053
+ if (runtimeContextParam) {
3054
+ searchParams.set("runtimeContext", runtimeContextParam);
3055
+ }
3056
+ const queryString = searchParams.toString();
3057
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2631
3058
  }
2632
3059
  /**
2633
3060
  * Gets a tool instance by ID
@@ -2654,10 +3081,17 @@ var MastraClient = class extends BaseResource {
2654
3081
  }
2655
3082
  /**
2656
3083
  * Retrieves all available workflows
3084
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2657
3085
  * @returns Promise containing map of workflow IDs to workflow details
2658
3086
  */
2659
- getWorkflows() {
2660
- return this.request("/api/workflows");
3087
+ getWorkflows(runtimeContext) {
3088
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3089
+ const searchParams = new URLSearchParams();
3090
+ if (runtimeContextParam) {
3091
+ searchParams.set("runtimeContext", runtimeContextParam);
3092
+ }
3093
+ const queryString = searchParams.toString();
3094
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2661
3095
  }
2662
3096
  /**
2663
3097
  * Gets a workflow instance by ID
@@ -2667,6 +3101,20 @@ var MastraClient = class extends BaseResource {
2667
3101
  getWorkflow(workflowId) {
2668
3102
  return new Workflow(this.options, workflowId);
2669
3103
  }
3104
+ /**
3105
+ * Gets all available agent builder actions
3106
+ * @returns Promise containing map of action IDs to action details
3107
+ */
3108
+ getAgentBuilderActions() {
3109
+ return this.request("/api/agent-builder/");
3110
+ }
3111
+ /**
3112
+ * Gets an agent builder instance for executing agent-builder workflows
3113
+ * @returns AgentBuilder instance
3114
+ */
3115
+ getAgentBuilderAction(actionId) {
3116
+ return new AgentBuilder(this.options, actionId);
3117
+ }
2670
3118
  /**
2671
3119
  * Gets a vector instance by name
2672
3120
  * @param vectorName - Name of the vector to retrieve
@@ -2811,13 +3259,6 @@ var MastraClient = class extends BaseResource {
2811
3259
  return this.request(`/api/telemetry`);
2812
3260
  }
2813
3261
  }
2814
- /**
2815
- * Retrieves all available networks
2816
- * @returns Promise containing map of network IDs to network details
2817
- */
2818
- getNetworks() {
2819
- return this.request("/api/networks");
2820
- }
2821
3262
  /**
2822
3263
  * Retrieves all available vNext networks
2823
3264
  * @returns Promise containing map of vNext network IDs to vNext network details
@@ -2825,14 +3266,6 @@ var MastraClient = class extends BaseResource {
2825
3266
  getVNextNetworks() {
2826
3267
  return this.request("/api/networks/v-next");
2827
3268
  }
2828
- /**
2829
- * Gets a network instance by ID
2830
- * @param networkId - ID of the network to retrieve
2831
- * @returns Network instance
2832
- */
2833
- getNetwork(networkId) {
2834
- return new Network(this.options, networkId);
2835
- }
2836
3269
  /**
2837
3270
  * Gets a vNext network instance by ID
2838
3271
  * @param networkId - ID of the vNext network to retrieve
@@ -3025,6 +3458,25 @@ var MastraClient = class extends BaseResource {
3025
3458
  }
3026
3459
  };
3027
3460
 
3028
- export { MastraClient };
3461
+ // src/tools.ts
3462
+ var ClientTool = class {
3463
+ id;
3464
+ description;
3465
+ inputSchema;
3466
+ outputSchema;
3467
+ execute;
3468
+ constructor(opts) {
3469
+ this.id = opts.id;
3470
+ this.description = opts.description;
3471
+ this.inputSchema = opts.inputSchema;
3472
+ this.outputSchema = opts.outputSchema;
3473
+ this.execute = opts.execute;
3474
+ }
3475
+ };
3476
+ function createTool(opts) {
3477
+ return new ClientTool(opts);
3478
+ }
3479
+
3480
+ export { ClientTool, MastraClient, createTool };
3029
3481
  //# sourceMappingURL=index.js.map
3030
3482
  //# sourceMappingURL=index.js.map