@mastra/client-js 0.0.0-scorers-api-v2-20250801171841 → 0.0.0-scorers-ui-refactored-20250916094952

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 (89) hide show
  1. package/CHANGELOG.md +671 -3
  2. package/README.md +5 -3
  3. package/dist/client.d.ts +30 -11
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/index.cjs +1459 -413
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1459 -415
  10. package/dist/index.js.map +1 -1
  11. package/dist/resources/a2a.d.ts +15 -18
  12. package/dist/resources/a2a.d.ts.map +1 -1
  13. package/dist/resources/agent-builder.d.ts +161 -0
  14. package/dist/resources/agent-builder.d.ts.map +1 -0
  15. package/dist/resources/agent.d.ts +78 -15
  16. package/dist/resources/agent.d.ts.map +1 -1
  17. package/dist/resources/base.d.ts +1 -1
  18. package/dist/resources/base.d.ts.map +1 -1
  19. package/dist/resources/index.d.ts +12 -10
  20. package/dist/resources/index.d.ts.map +1 -1
  21. package/dist/resources/legacy-workflow.d.ts +7 -4
  22. package/dist/resources/legacy-workflow.d.ts.map +1 -1
  23. package/dist/resources/mcp-tool.d.ts +4 -3
  24. package/dist/resources/mcp-tool.d.ts.map +1 -1
  25. package/dist/resources/memory-thread.d.ts +3 -3
  26. package/dist/resources/memory-thread.d.ts.map +1 -1
  27. package/dist/resources/network-memory-thread.d.ts +3 -3
  28. package/dist/resources/network-memory-thread.d.ts.map +1 -1
  29. package/dist/resources/network.d.ts +6 -4
  30. package/dist/resources/network.d.ts.map +1 -1
  31. package/dist/resources/observability.d.ts +19 -0
  32. package/dist/resources/observability.d.ts.map +1 -0
  33. package/dist/resources/tool.d.ts +4 -3
  34. package/dist/resources/tool.d.ts.map +1 -1
  35. package/dist/resources/vNextNetwork.d.ts +5 -4
  36. package/dist/resources/vNextNetwork.d.ts.map +1 -1
  37. package/dist/resources/vector.d.ts +7 -4
  38. package/dist/resources/vector.d.ts.map +1 -1
  39. package/dist/resources/workflow.d.ts +80 -6
  40. package/dist/resources/workflow.d.ts.map +1 -1
  41. package/dist/tools.d.ts +22 -0
  42. package/dist/tools.d.ts.map +1 -0
  43. package/dist/types.d.ts +49 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/utils/index.d.ts +2 -0
  46. package/dist/utils/index.d.ts.map +1 -1
  47. package/dist/utils/process-client-tools.d.ts.map +1 -1
  48. package/dist/utils/process-mastra-stream.d.ts +11 -0
  49. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  50. package/dist/utils/zod-to-json-schema.d.ts +2 -104
  51. package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
  52. package/package.json +25 -16
  53. package/dist/adapters/agui.d.ts +0 -23
  54. package/dist/adapters/agui.d.ts.map +0 -1
  55. package/eslint.config.js +0 -6
  56. package/integration-tests/agui-adapter.test.ts +0 -122
  57. package/integration-tests/package.json +0 -18
  58. package/integration-tests/src/mastra/index.ts +0 -35
  59. package/integration-tests/vitest.config.ts +0 -9
  60. package/src/adapters/agui.test.ts +0 -322
  61. package/src/adapters/agui.ts +0 -239
  62. package/src/client.ts +0 -623
  63. package/src/example.ts +0 -95
  64. package/src/index.test.ts +0 -1226
  65. package/src/index.ts +0 -3
  66. package/src/resources/a2a.ts +0 -88
  67. package/src/resources/agent.ts +0 -785
  68. package/src/resources/base.ts +0 -76
  69. package/src/resources/index.ts +0 -10
  70. package/src/resources/legacy-workflow.ts +0 -242
  71. package/src/resources/mcp-tool.ts +0 -48
  72. package/src/resources/memory-thread.test.ts +0 -285
  73. package/src/resources/memory-thread.ts +0 -99
  74. package/src/resources/network-memory-thread.test.ts +0 -269
  75. package/src/resources/network-memory-thread.ts +0 -81
  76. package/src/resources/network.ts +0 -86
  77. package/src/resources/tool.ts +0 -45
  78. package/src/resources/vNextNetwork.ts +0 -194
  79. package/src/resources/vector.ts +0 -83
  80. package/src/resources/workflow.ts +0 -410
  81. package/src/types.ts +0 -502
  82. package/src/utils/index.ts +0 -11
  83. package/src/utils/process-client-tools.ts +0 -32
  84. package/src/utils/zod-to-json-schema.ts +0 -10
  85. package/src/v2-messages.test.ts +0 -180
  86. package/tsconfig.build.json +0 -9
  87. package/tsconfig.json +0 -5
  88. package/tsup.config.ts +0 -22
  89. package/vitest.config.js +0 -8
package/dist/index.cjs CHANGED
@@ -1,209 +1,55 @@
1
1
  'use strict';
2
2
 
3
- var client = require('@ag-ui/client');
4
- var rxjs = require('rxjs');
5
3
  var uiUtils = require('@ai-sdk/ui-utils');
6
- var zod = require('zod');
7
- var originalZodToJsonSchema = require('zod-to-json-schema');
8
- var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
9
4
  var uuid = require('@lukeed/uuid');
10
5
  var runtimeContext = require('@mastra/core/runtime-context');
6
+ var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
7
+ var zod = require('zod');
8
+ var originalZodToJsonSchema = require('zod-to-json-schema');
11
9
 
12
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
11
 
14
12
  var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
15
13
 
16
- // src/adapters/agui.ts
17
- var AGUIAdapter = class extends client.AbstractAgent {
18
- agent;
19
- resourceId;
20
- constructor({ agent, agentId, resourceId, ...rest }) {
21
- super({
22
- agentId,
23
- ...rest
24
- });
25
- this.agent = agent;
26
- this.resourceId = resourceId;
27
- }
28
- run(input) {
29
- return new rxjs.Observable((subscriber) => {
30
- const convertedMessages = convertMessagesToMastraMessages(input.messages);
31
- subscriber.next({
32
- type: client.EventType.RUN_STARTED,
33
- threadId: input.threadId,
34
- runId: input.runId
35
- });
36
- this.agent.stream({
37
- threadId: input.threadId,
38
- resourceId: this.resourceId ?? "",
39
- runId: input.runId,
40
- messages: convertedMessages,
41
- clientTools: input.tools.reduce(
42
- (acc, tool) => {
43
- acc[tool.name] = {
44
- id: tool.name,
45
- description: tool.description,
46
- inputSchema: tool.parameters
47
- };
48
- return acc;
49
- },
50
- {}
51
- )
52
- }).then((response) => {
53
- let currentMessageId = void 0;
54
- let isInTextMessage = false;
55
- return response.processDataStream({
56
- onTextPart: (text) => {
57
- if (currentMessageId === void 0) {
58
- currentMessageId = generateUUID();
59
- const message2 = {
60
- type: client.EventType.TEXT_MESSAGE_START,
61
- messageId: currentMessageId,
62
- role: "assistant"
63
- };
64
- subscriber.next(message2);
65
- isInTextMessage = true;
66
- }
67
- const message = {
68
- type: client.EventType.TEXT_MESSAGE_CONTENT,
69
- messageId: currentMessageId,
70
- delta: text
71
- };
72
- subscriber.next(message);
73
- },
74
- onFinishMessagePart: () => {
75
- if (currentMessageId !== void 0) {
76
- const message = {
77
- type: client.EventType.TEXT_MESSAGE_END,
78
- messageId: currentMessageId
79
- };
80
- subscriber.next(message);
81
- isInTextMessage = false;
82
- }
83
- subscriber.next({
84
- type: client.EventType.RUN_FINISHED,
85
- threadId: input.threadId,
86
- runId: input.runId
87
- });
88
- subscriber.complete();
89
- },
90
- onToolCallPart(streamPart) {
91
- const parentMessageId = currentMessageId || generateUUID();
92
- if (isInTextMessage) {
93
- const message = {
94
- type: client.EventType.TEXT_MESSAGE_END,
95
- messageId: parentMessageId
96
- };
97
- subscriber.next(message);
98
- isInTextMessage = false;
99
- }
100
- subscriber.next({
101
- type: client.EventType.TOOL_CALL_START,
102
- toolCallId: streamPart.toolCallId,
103
- toolCallName: streamPart.toolName,
104
- parentMessageId
105
- });
106
- subscriber.next({
107
- type: client.EventType.TOOL_CALL_ARGS,
108
- toolCallId: streamPart.toolCallId,
109
- delta: JSON.stringify(streamPart.args),
110
- parentMessageId
111
- });
112
- subscriber.next({
113
- type: client.EventType.TOOL_CALL_END,
114
- toolCallId: streamPart.toolCallId,
115
- parentMessageId
116
- });
117
- }
118
- });
119
- }).catch((error) => {
120
- console.error("error", error);
121
- subscriber.error(error);
122
- });
123
- return () => {
124
- };
125
- });
126
- }
127
- };
128
- function generateUUID() {
129
- if (typeof crypto !== "undefined") {
130
- if (typeof crypto.randomUUID === "function") {
131
- return crypto.randomUUID();
132
- }
133
- if (typeof crypto.getRandomValues === "function") {
134
- const buffer = new Uint8Array(16);
135
- crypto.getRandomValues(buffer);
136
- buffer[6] = buffer[6] & 15 | 64;
137
- buffer[8] = buffer[8] & 63 | 128;
138
- let hex = "";
139
- for (let i = 0; i < 16; i++) {
140
- hex += buffer[i].toString(16).padStart(2, "0");
141
- if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
142
- }
143
- return hex;
14
+ // src/resources/agent.ts
15
+ function parseClientRuntimeContext(runtimeContext$1) {
16
+ if (runtimeContext$1) {
17
+ if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
18
+ return Object.fromEntries(runtimeContext$1.entries());
144
19
  }
20
+ return runtimeContext$1;
145
21
  }
146
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
147
- const r = Math.random() * 16 | 0;
148
- const v = c === "x" ? r : r & 3 | 8;
149
- return v.toString(16);
150
- });
22
+ return void 0;
151
23
  }
152
- function convertMessagesToMastraMessages(messages) {
153
- const result = [];
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
- result.push({
171
- role: "tool",
172
- content: message.toolCalls.map((toolCall) => ({
173
- type: "tool-result",
174
- toolCallId: toolCall.id,
175
- toolName: toolCall.function.name,
176
- result: JSON.parse(toolCall.function.arguments)
177
- }))
178
- });
179
- }
180
- } else if (message.role === "user") {
181
- result.push({
182
- role: "user",
183
- content: message.content || ""
184
- });
185
- } else if (message.role === "tool") {
186
- result.push({
187
- role: "tool",
188
- content: [
189
- {
190
- type: "tool-result",
191
- toolCallId: message.toolCallId,
192
- toolName: "unknown",
193
- result: message.content
194
- }
195
- ]
196
- });
197
- }
24
+ function base64RuntimeContext(runtimeContext) {
25
+ if (runtimeContext) {
26
+ return btoa(JSON.stringify(runtimeContext));
198
27
  }
199
- return result;
28
+ return void 0;
29
+ }
30
+ function runtimeContextQueryString(runtimeContext) {
31
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
32
+ if (!runtimeContextParam) return "";
33
+ const searchParams = new URLSearchParams();
34
+ searchParams.set("runtimeContext", runtimeContextParam);
35
+ const queryString = searchParams.toString();
36
+ return queryString ? `?${queryString}` : "";
37
+ }
38
+ function isZodType(value) {
39
+ return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
200
40
  }
201
41
  function zodToJsonSchema(zodSchema) {
202
- if (!(zodSchema instanceof zod.ZodSchema)) {
42
+ if (!isZodType(zodSchema)) {
203
43
  return zodSchema;
204
44
  }
205
- return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
45
+ if ("toJSONSchema" in zod.z) {
46
+ const fn = "toJSONSchema";
47
+ return zod.z[fn].call(zod.z, zodSchema);
48
+ }
49
+ return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
206
50
  }
51
+
52
+ // src/utils/process-client-tools.ts
207
53
  function processClientTools(clientTools) {
208
54
  if (!clientTools) {
209
55
  return void 0;
@@ -232,6 +78,60 @@ function processClientTools(clientTools) {
232
78
  );
233
79
  }
234
80
 
81
+ // src/utils/process-mastra-stream.ts
82
+ async function sharedProcessMastraStream({
83
+ stream,
84
+ onChunk
85
+ }) {
86
+ const reader = stream.getReader();
87
+ const decoder = new TextDecoder();
88
+ let buffer = "";
89
+ try {
90
+ while (true) {
91
+ const { done, value } = await reader.read();
92
+ if (done) break;
93
+ buffer += decoder.decode(value, { stream: true });
94
+ const lines = buffer.split("\n\n");
95
+ buffer = lines.pop() || "";
96
+ for (const line of lines) {
97
+ if (line.startsWith("data: ")) {
98
+ const data = line.slice(6);
99
+ if (data === "[DONE]") {
100
+ console.log("\u{1F3C1} Stream finished");
101
+ return;
102
+ }
103
+ try {
104
+ const json = JSON.parse(data);
105
+ await onChunk(json);
106
+ } catch (error) {
107
+ console.error("\u274C JSON parse error:", error, "Data:", data);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ } finally {
113
+ reader.releaseLock();
114
+ }
115
+ }
116
+ async function processMastraNetworkStream({
117
+ stream,
118
+ onChunk
119
+ }) {
120
+ return sharedProcessMastraStream({
121
+ stream,
122
+ onChunk
123
+ });
124
+ }
125
+ async function processMastraStream({
126
+ stream,
127
+ onChunk
128
+ }) {
129
+ return sharedProcessMastraStream({
130
+ stream,
131
+ onChunk
132
+ });
133
+ }
134
+
235
135
  // src/resources/base.ts
236
136
  var BaseResource = class {
237
137
  options;
@@ -246,7 +146,7 @@ var BaseResource = class {
246
146
  */
247
147
  async request(path, options = {}) {
248
148
  let lastError = null;
249
- const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
149
+ const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
250
150
  let delay = backoffMs;
251
151
  for (let attempt = 0; attempt <= retries; attempt++) {
252
152
  try {
@@ -260,6 +160,7 @@ var BaseResource = class {
260
160
  // 'x-mastra-client-type': 'js',
261
161
  },
262
162
  signal: this.options.abortSignal,
163
+ credentials: options.credentials ?? credentials,
263
164
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
264
165
  });
265
166
  if (!response.ok) {
@@ -292,14 +193,64 @@ var BaseResource = class {
292
193
  throw lastError || new Error("Request failed");
293
194
  }
294
195
  };
295
- function parseClientRuntimeContext(runtimeContext$1) {
296
- if (runtimeContext$1) {
297
- if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
298
- return Object.fromEntries(runtimeContext$1.entries());
196
+
197
+ // src/resources/agent.ts
198
+ async function executeToolCallAndRespond({
199
+ response,
200
+ params,
201
+ runId,
202
+ resourceId,
203
+ threadId,
204
+ runtimeContext,
205
+ respondFn
206
+ }) {
207
+ if (response.finishReason === "tool-calls") {
208
+ const toolCalls = response.toolCalls;
209
+ if (!toolCalls || !Array.isArray(toolCalls)) {
210
+ return response;
211
+ }
212
+ for (const toolCall of toolCalls) {
213
+ const clientTool = params.clientTools?.[toolCall.toolName];
214
+ if (clientTool && clientTool.execute) {
215
+ const result = await clientTool.execute(
216
+ {
217
+ context: toolCall?.args,
218
+ runId,
219
+ resourceId,
220
+ threadId,
221
+ runtimeContext,
222
+ tracingContext: { currentSpan: void 0 }
223
+ },
224
+ {
225
+ messages: response.messages,
226
+ toolCallId: toolCall?.toolCallId
227
+ }
228
+ );
229
+ const updatedMessages = [
230
+ {
231
+ role: "user",
232
+ content: params.messages
233
+ },
234
+ ...response.response.messages,
235
+ {
236
+ role: "tool",
237
+ content: [
238
+ {
239
+ type: "tool-result",
240
+ toolCallId: toolCall.toolCallId,
241
+ toolName: toolCall.toolName,
242
+ result
243
+ }
244
+ ]
245
+ }
246
+ ];
247
+ return respondFn({
248
+ ...params,
249
+ messages: updatedMessages
250
+ });
251
+ }
299
252
  }
300
- return runtimeContext$1;
301
253
  }
302
- return void 0;
303
254
  }
304
255
  var AgentVoice = class extends BaseResource {
305
256
  constructor(options, agentId) {
@@ -342,17 +293,21 @@ var AgentVoice = class extends BaseResource {
342
293
  }
343
294
  /**
344
295
  * Get available speakers for the agent's voice provider
296
+ * @param runtimeContext - Optional runtime context to pass as query parameter
297
+ * @param runtimeContext - Optional runtime context to pass as query parameter
345
298
  * @returns Promise containing list of available speakers
346
299
  */
347
- getSpeakers() {
348
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
300
+ getSpeakers(runtimeContext) {
301
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
349
302
  }
350
303
  /**
351
304
  * Get the listener configuration for the agent's voice provider
305
+ * @param runtimeContext - Optional runtime context to pass as query parameter
306
+ * @param runtimeContext - Optional runtime context to pass as query parameter
352
307
  * @returns Promise containing a check if the agent has listening capabilities
353
308
  */
354
- getListener() {
355
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
309
+ getListener(runtimeContext) {
310
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
356
311
  }
357
312
  };
358
313
  var Agent = class extends BaseResource {
@@ -364,12 +319,19 @@ var Agent = class extends BaseResource {
364
319
  voice;
365
320
  /**
366
321
  * Retrieves details about the agent
322
+ * @param runtimeContext - Optional runtime context to pass as query parameter
367
323
  * @returns Promise containing agent details including model and instructions
368
324
  */
369
- details() {
370
- return this.request(`/api/agents/${this.agentId}`);
325
+ details(runtimeContext) {
326
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
371
327
  }
372
328
  async generate(params) {
329
+ console.warn(
330
+ "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."
331
+ );
332
+ return this.generateLegacy(params);
333
+ }
334
+ async generateLegacy(params) {
373
335
  const processedParams = {
374
336
  ...params,
375
337
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -379,7 +341,7 @@ var Agent = class extends BaseResource {
379
341
  };
380
342
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
381
343
  const response = await this.request(
382
- `/api/agents/${this.agentId}/generate`,
344
+ `/api/agents/${this.agentId}/generate-legacy`,
383
345
  {
384
346
  method: "POST",
385
347
  body: processedParams
@@ -394,7 +356,14 @@ var Agent = class extends BaseResource {
394
356
  const clientTool = params.clientTools?.[toolCall.toolName];
395
357
  if (clientTool && clientTool.execute) {
396
358
  const result = await clientTool.execute(
397
- { context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
359
+ {
360
+ context: toolCall?.args,
361
+ runId,
362
+ resourceId,
363
+ threadId,
364
+ runtimeContext,
365
+ tracingContext: { currentSpan: void 0 }
366
+ },
398
367
  {
399
368
  messages: response.messages,
400
369
  toolCallId: toolCall?.toolCallId
@@ -427,6 +396,47 @@ var Agent = class extends BaseResource {
427
396
  }
428
397
  return response;
429
398
  }
399
+ async generateVNext(messagesOrParams, options) {
400
+ let params;
401
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
402
+ params = messagesOrParams;
403
+ } else {
404
+ params = {
405
+ messages: messagesOrParams,
406
+ ...options
407
+ };
408
+ }
409
+ const processedParams = {
410
+ ...params,
411
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
412
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
413
+ clientTools: processClientTools(params.clientTools),
414
+ structuredOutput: params.structuredOutput ? {
415
+ ...params.structuredOutput,
416
+ schema: zodToJsonSchema(params.structuredOutput.schema)
417
+ } : void 0
418
+ };
419
+ const { runId, resourceId, threadId, runtimeContext } = processedParams;
420
+ const response = await this.request(
421
+ `/api/agents/${this.agentId}/generate/vnext`,
422
+ {
423
+ method: "POST",
424
+ body: processedParams
425
+ }
426
+ );
427
+ if (response.finishReason === "tool-calls") {
428
+ return executeToolCallAndRespond({
429
+ response,
430
+ params,
431
+ runId,
432
+ resourceId,
433
+ threadId,
434
+ runtimeContext,
435
+ respondFn: this.generateVNext.bind(this)
436
+ });
437
+ }
438
+ return response;
439
+ }
430
440
  async processChatResponse({
431
441
  stream,
432
442
  update,
@@ -695,6 +705,17 @@ var Agent = class extends BaseResource {
695
705
  * @returns Promise containing the enhanced Response object with processDataStream method
696
706
  */
697
707
  async stream(params) {
708
+ console.warn(
709
+ "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."
710
+ );
711
+ return this.streamLegacy(params);
712
+ }
713
+ /**
714
+ * Streams a response from the agent
715
+ * @param params - Stream parameters including prompt
716
+ * @returns Promise containing the enhanced Response object with processDataStream method
717
+ */
718
+ async streamLegacy(params) {
698
719
  const processedParams = {
699
720
  ...params,
700
721
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -717,11 +738,261 @@ var Agent = class extends BaseResource {
717
738
  };
718
739
  return streamResponse;
719
740
  }
720
- /**
721
- * Processes the stream response and handles tool calls
722
- */
723
- async processStreamResponse(processedParams, writable) {
724
- const response = await this.request(`/api/agents/${this.agentId}/stream`, {
741
+ async processChatResponse_vNext({
742
+ stream,
743
+ update,
744
+ onToolCall,
745
+ onFinish,
746
+ getCurrentDate = () => /* @__PURE__ */ new Date(),
747
+ lastMessage
748
+ }) {
749
+ const replaceLastMessage = lastMessage?.role === "assistant";
750
+ let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
751
+ (lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
752
+ return Math.max(max, toolInvocation.step ?? 0);
753
+ }, 0) ?? 0) : 0;
754
+ const message = replaceLastMessage ? structuredClone(lastMessage) : {
755
+ id: uuid.v4(),
756
+ createdAt: getCurrentDate(),
757
+ role: "assistant",
758
+ content: "",
759
+ parts: []
760
+ };
761
+ let currentTextPart = void 0;
762
+ let currentReasoningPart = void 0;
763
+ let currentReasoningTextDetail = void 0;
764
+ function updateToolInvocationPart(toolCallId, invocation) {
765
+ const part = message.parts.find(
766
+ (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
767
+ );
768
+ if (part != null) {
769
+ part.toolInvocation = invocation;
770
+ } else {
771
+ message.parts.push({
772
+ type: "tool-invocation",
773
+ toolInvocation: invocation
774
+ });
775
+ }
776
+ }
777
+ const data = [];
778
+ let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
779
+ const partialToolCalls = {};
780
+ let usage = {
781
+ completionTokens: NaN,
782
+ promptTokens: NaN,
783
+ totalTokens: NaN
784
+ };
785
+ let finishReason = "unknown";
786
+ function execUpdate() {
787
+ const copiedData = [...data];
788
+ if (messageAnnotations?.length) {
789
+ message.annotations = messageAnnotations;
790
+ }
791
+ const copiedMessage = {
792
+ // deep copy the message to ensure that deep changes (msg attachments) are updated
793
+ // with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
794
+ ...structuredClone(message),
795
+ // add a revision id to ensure that the message is updated with SWR. SWR uses a
796
+ // hashing approach by default to detect changes, but it only works for shallow
797
+ // changes. This is why we need to add a revision id to ensure that the message
798
+ // is updated with SWR (without it, the changes get stuck in SWR and are not
799
+ // forwarded to rendering):
800
+ revisionId: uuid.v4()
801
+ };
802
+ update({
803
+ message: copiedMessage,
804
+ data: copiedData,
805
+ replaceLastMessage
806
+ });
807
+ }
808
+ await processMastraStream({
809
+ stream,
810
+ // TODO: casting as any here because the stream types were all typed as any before in core.
811
+ // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
812
+ onChunk: async (chunk) => {
813
+ switch (chunk.type) {
814
+ case "step-start": {
815
+ if (!replaceLastMessage) {
816
+ message.id = chunk.payload.messageId;
817
+ }
818
+ message.parts.push({ type: "step-start" });
819
+ execUpdate();
820
+ break;
821
+ }
822
+ case "text-delta": {
823
+ if (currentTextPart == null) {
824
+ currentTextPart = {
825
+ type: "text",
826
+ text: chunk.payload.text
827
+ };
828
+ message.parts.push(currentTextPart);
829
+ } else {
830
+ currentTextPart.text += chunk.payload.text;
831
+ }
832
+ message.content += chunk.payload.text;
833
+ execUpdate();
834
+ break;
835
+ }
836
+ case "reasoning-delta": {
837
+ if (currentReasoningTextDetail == null) {
838
+ currentReasoningTextDetail = { type: "text", text: chunk.payload.text };
839
+ if (currentReasoningPart != null) {
840
+ currentReasoningPart.details.push(currentReasoningTextDetail);
841
+ }
842
+ } else {
843
+ currentReasoningTextDetail.text += chunk.payload.text;
844
+ }
845
+ if (currentReasoningPart == null) {
846
+ currentReasoningPart = {
847
+ type: "reasoning",
848
+ reasoning: chunk.payload.text,
849
+ details: [currentReasoningTextDetail]
850
+ };
851
+ message.parts.push(currentReasoningPart);
852
+ } else {
853
+ currentReasoningPart.reasoning += chunk.payload.text;
854
+ }
855
+ message.reasoning = (message.reasoning ?? "") + chunk.payload.text;
856
+ execUpdate();
857
+ break;
858
+ }
859
+ case "file": {
860
+ message.parts.push({
861
+ type: "file",
862
+ mimeType: chunk.payload.mimeType,
863
+ data: chunk.payload.data
864
+ });
865
+ execUpdate();
866
+ break;
867
+ }
868
+ case "source": {
869
+ message.parts.push({
870
+ type: "source",
871
+ source: chunk.payload.source
872
+ });
873
+ execUpdate();
874
+ break;
875
+ }
876
+ case "tool-call": {
877
+ const invocation = {
878
+ state: "call",
879
+ step,
880
+ ...chunk.payload
881
+ };
882
+ if (partialToolCalls[chunk.payload.toolCallId] != null) {
883
+ message.toolInvocations[partialToolCalls[chunk.payload.toolCallId].index] = invocation;
884
+ } else {
885
+ if (message.toolInvocations == null) {
886
+ message.toolInvocations = [];
887
+ }
888
+ message.toolInvocations.push(invocation);
889
+ }
890
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
891
+ execUpdate();
892
+ if (onToolCall) {
893
+ const result = await onToolCall({ toolCall: chunk.payload });
894
+ if (result != null) {
895
+ const invocation2 = {
896
+ state: "result",
897
+ step,
898
+ ...chunk.payload,
899
+ result
900
+ };
901
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
902
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation2);
903
+ execUpdate();
904
+ }
905
+ }
906
+ }
907
+ case "tool-call-input-streaming-start": {
908
+ if (message.toolInvocations == null) {
909
+ message.toolInvocations = [];
910
+ }
911
+ partialToolCalls[chunk.payload.toolCallId] = {
912
+ text: "",
913
+ step,
914
+ toolName: chunk.payload.toolName,
915
+ index: message.toolInvocations.length
916
+ };
917
+ const invocation = {
918
+ state: "partial-call",
919
+ step,
920
+ toolCallId: chunk.payload.toolCallId,
921
+ toolName: chunk.payload.toolName,
922
+ args: chunk.payload.args
923
+ };
924
+ message.toolInvocations.push(invocation);
925
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
926
+ execUpdate();
927
+ break;
928
+ }
929
+ case "tool-call-delta": {
930
+ const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
931
+ partialToolCall.text += chunk.payload.argsTextDelta;
932
+ const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
933
+ const invocation = {
934
+ state: "partial-call",
935
+ step: partialToolCall.step,
936
+ toolCallId: chunk.payload.toolCallId,
937
+ toolName: partialToolCall.toolName,
938
+ args: partialArgs
939
+ };
940
+ message.toolInvocations[partialToolCall.index] = invocation;
941
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
942
+ execUpdate();
943
+ break;
944
+ }
945
+ case "tool-result": {
946
+ const toolInvocations = message.toolInvocations;
947
+ if (toolInvocations == null) {
948
+ throw new Error("tool_result must be preceded by a tool_call");
949
+ }
950
+ const toolInvocationIndex = toolInvocations.findIndex(
951
+ (invocation2) => invocation2.toolCallId === chunk.payload.toolCallId
952
+ );
953
+ if (toolInvocationIndex === -1) {
954
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
955
+ }
956
+ const invocation = {
957
+ ...toolInvocations[toolInvocationIndex],
958
+ state: "result",
959
+ ...chunk.payload
960
+ };
961
+ toolInvocations[toolInvocationIndex] = invocation;
962
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
963
+ execUpdate();
964
+ break;
965
+ }
966
+ case "error": {
967
+ throw new Error(chunk.payload.error);
968
+ }
969
+ case "data": {
970
+ data.push(...chunk.payload.data);
971
+ execUpdate();
972
+ break;
973
+ }
974
+ case "step-finish": {
975
+ step += 1;
976
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
977
+ currentReasoningPart = void 0;
978
+ currentReasoningTextDetail = void 0;
979
+ execUpdate();
980
+ break;
981
+ }
982
+ case "finish": {
983
+ finishReason = chunk.payload.stepResult.reason;
984
+ if (chunk.payload.usage != null) {
985
+ usage = chunk.payload.usage;
986
+ }
987
+ break;
988
+ }
989
+ }
990
+ }
991
+ });
992
+ onFinish?.({ message, finishReason, usage });
993
+ }
994
+ async processStreamResponse_vNext(processedParams, writable) {
995
+ const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
725
996
  method: "POST",
726
997
  body: processedParams,
727
998
  stream: true
@@ -733,12 +1004,31 @@ var Agent = class extends BaseResource {
733
1004
  let toolCalls = [];
734
1005
  let messages = [];
735
1006
  const [streamForWritable, streamForProcessing] = response.body.tee();
736
- streamForWritable.pipeTo(writable, {
737
- preventClose: true
738
- }).catch((error) => {
1007
+ streamForWritable.pipeTo(
1008
+ new WritableStream({
1009
+ async write(chunk) {
1010
+ try {
1011
+ const text = new TextDecoder().decode(chunk);
1012
+ if (text.includes("[DONE]")) {
1013
+ return;
1014
+ }
1015
+ } catch {
1016
+ }
1017
+ const writer = writable.getWriter();
1018
+ try {
1019
+ await writer.write(chunk);
1020
+ } finally {
1021
+ writer.releaseLock();
1022
+ }
1023
+ }
1024
+ }),
1025
+ {
1026
+ preventClose: true
1027
+ }
1028
+ ).catch((error) => {
739
1029
  console.error("Error piping to writable stream:", error);
740
1030
  });
741
- this.processChatResponse({
1031
+ this.processChatResponse_vNext({
742
1032
  stream: streamForProcessing,
743
1033
  update: ({ message }) => {
744
1034
  const existingIndex = messages.findIndex((m) => m.id === message.id);
@@ -763,14 +1053,180 @@ var Agent = class extends BaseResource {
763
1053
  runId: processedParams.runId,
764
1054
  resourceId: processedParams.resourceId,
765
1055
  threadId: processedParams.threadId,
766
- runtimeContext: processedParams.runtimeContext
1056
+ runtimeContext: processedParams.runtimeContext,
1057
+ // TODO: Pass proper tracing context when client-js supports tracing
1058
+ tracingContext: { currentSpan: void 0 }
767
1059
  },
768
1060
  {
769
1061
  messages: response.messages,
770
1062
  toolCallId: toolCall2?.toolCallId
771
1063
  }
772
1064
  );
773
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1065
+ const lastMessageRaw = messages[messages.length - 1];
1066
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
1067
+ const toolInvocationPart = lastMessage?.parts?.find(
1068
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
1069
+ );
1070
+ if (toolInvocationPart) {
1071
+ toolInvocationPart.toolInvocation = {
1072
+ ...toolInvocationPart.toolInvocation,
1073
+ state: "result",
1074
+ result
1075
+ };
1076
+ }
1077
+ const toolInvocation = lastMessage?.toolInvocations?.find(
1078
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
1079
+ );
1080
+ if (toolInvocation) {
1081
+ toolInvocation.state = "result";
1082
+ toolInvocation.result = result;
1083
+ }
1084
+ const originalMessages = processedParams.messages;
1085
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
1086
+ const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
1087
+ this.processStreamResponse_vNext(
1088
+ {
1089
+ ...processedParams,
1090
+ messages: updatedMessages
1091
+ },
1092
+ writable
1093
+ ).catch((error) => {
1094
+ console.error("Error processing stream response:", error);
1095
+ });
1096
+ }
1097
+ }
1098
+ } else {
1099
+ setTimeout(() => {
1100
+ writable.close();
1101
+ }, 0);
1102
+ }
1103
+ },
1104
+ lastMessage: void 0
1105
+ }).catch((error) => {
1106
+ console.error("Error processing stream response:", error);
1107
+ });
1108
+ } catch (error) {
1109
+ console.error("Error processing stream response:", error);
1110
+ }
1111
+ return response;
1112
+ }
1113
+ async network(params) {
1114
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1115
+ method: "POST",
1116
+ body: params,
1117
+ stream: true
1118
+ });
1119
+ if (!response.body) {
1120
+ throw new Error("No response body");
1121
+ }
1122
+ const streamResponse = new Response(response.body, {
1123
+ status: response.status,
1124
+ statusText: response.statusText,
1125
+ headers: response.headers
1126
+ });
1127
+ streamResponse.processDataStream = async ({
1128
+ onChunk
1129
+ }) => {
1130
+ await processMastraNetworkStream({
1131
+ stream: streamResponse.body,
1132
+ onChunk
1133
+ });
1134
+ };
1135
+ return streamResponse;
1136
+ }
1137
+ async streamVNext(messagesOrParams, options) {
1138
+ let params;
1139
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1140
+ params = messagesOrParams;
1141
+ } else {
1142
+ params = {
1143
+ messages: messagesOrParams,
1144
+ ...options
1145
+ };
1146
+ }
1147
+ const processedParams = {
1148
+ ...params,
1149
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
1150
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1151
+ clientTools: processClientTools(params.clientTools),
1152
+ structuredOutput: params.structuredOutput ? {
1153
+ ...params.structuredOutput,
1154
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1155
+ } : void 0
1156
+ };
1157
+ const { readable, writable } = new TransformStream();
1158
+ const response = await this.processStreamResponse_vNext(processedParams, writable);
1159
+ const streamResponse = new Response(readable, {
1160
+ status: response.status,
1161
+ statusText: response.statusText,
1162
+ headers: response.headers
1163
+ });
1164
+ streamResponse.processDataStream = async ({
1165
+ onChunk
1166
+ }) => {
1167
+ await processMastraStream({
1168
+ stream: streamResponse.body,
1169
+ onChunk
1170
+ });
1171
+ };
1172
+ return streamResponse;
1173
+ }
1174
+ /**
1175
+ * Processes the stream response and handles tool calls
1176
+ */
1177
+ async processStreamResponse(processedParams, writable) {
1178
+ const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1179
+ method: "POST",
1180
+ body: processedParams,
1181
+ stream: true
1182
+ });
1183
+ if (!response.body) {
1184
+ throw new Error("No response body");
1185
+ }
1186
+ try {
1187
+ let toolCalls = [];
1188
+ let messages = [];
1189
+ const [streamForWritable, streamForProcessing] = response.body.tee();
1190
+ streamForWritable.pipeTo(writable, {
1191
+ preventClose: true
1192
+ }).catch((error) => {
1193
+ console.error("Error piping to writable stream:", error);
1194
+ });
1195
+ this.processChatResponse({
1196
+ stream: streamForProcessing,
1197
+ update: ({ message }) => {
1198
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
1199
+ if (existingIndex !== -1) {
1200
+ messages[existingIndex] = message;
1201
+ } else {
1202
+ messages.push(message);
1203
+ }
1204
+ },
1205
+ onFinish: async ({ finishReason, message }) => {
1206
+ if (finishReason === "tool-calls") {
1207
+ const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
1208
+ if (toolCall) {
1209
+ toolCalls.push(toolCall);
1210
+ }
1211
+ for (const toolCall2 of toolCalls) {
1212
+ const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1213
+ if (clientTool && clientTool.execute) {
1214
+ const result = await clientTool.execute(
1215
+ {
1216
+ context: toolCall2?.args,
1217
+ runId: processedParams.runId,
1218
+ resourceId: processedParams.resourceId,
1219
+ threadId: processedParams.threadId,
1220
+ runtimeContext: processedParams.runtimeContext,
1221
+ // TODO: Pass proper tracing context when client-js supports tracing
1222
+ tracingContext: { currentSpan: void 0 }
1223
+ },
1224
+ {
1225
+ messages: response.messages,
1226
+ toolCallId: toolCall2?.toolCallId
1227
+ }
1228
+ );
1229
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
774
1230
  const toolInvocationPart = lastMessage?.parts?.find(
775
1231
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
776
1232
  );
@@ -832,10 +1288,11 @@ var Agent = class extends BaseResource {
832
1288
  /**
833
1289
  * Gets details about a specific tool available to the agent
834
1290
  * @param toolId - ID of the tool to retrieve
1291
+ * @param runtimeContext - Optional runtime context to pass as query parameter
835
1292
  * @returns Promise containing tool details
836
1293
  */
837
- getTool(toolId) {
838
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1294
+ getTool(toolId, runtimeContext) {
1295
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
839
1296
  }
840
1297
  /**
841
1298
  * Executes a tool for the agent
@@ -846,7 +1303,7 @@ var Agent = class extends BaseResource {
846
1303
  executeTool(toolId, params) {
847
1304
  const body = {
848
1305
  data: params.data,
849
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1306
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
850
1307
  };
851
1308
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
852
1309
  method: "POST",
@@ -855,17 +1312,30 @@ var Agent = class extends BaseResource {
855
1312
  }
856
1313
  /**
857
1314
  * Retrieves evaluation results for the agent
1315
+ * @param runtimeContext - Optional runtime context to pass as query parameter
858
1316
  * @returns Promise containing agent evaluations
859
1317
  */
860
- evals() {
861
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1318
+ evals(runtimeContext) {
1319
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
862
1320
  }
863
1321
  /**
864
1322
  * Retrieves live evaluation results for the agent
1323
+ * @param runtimeContext - Optional runtime context to pass as query parameter
865
1324
  * @returns Promise containing live agent evaluations
866
1325
  */
867
- liveEvals() {
868
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1326
+ liveEvals(runtimeContext) {
1327
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1328
+ }
1329
+ /**
1330
+ * Updates the model for the agent
1331
+ * @param params - Parameters for updating the model
1332
+ * @returns Promise containing the updated model
1333
+ */
1334
+ updateModel(params) {
1335
+ return this.request(`/api/agents/${this.agentId}/model`, {
1336
+ method: "POST",
1337
+ body: params
1338
+ });
869
1339
  }
870
1340
  };
871
1341
  var Network = class extends BaseResource {
@@ -875,10 +1345,11 @@ var Network = class extends BaseResource {
875
1345
  }
876
1346
  /**
877
1347
  * Retrieves details about the network
1348
+ * @param runtimeContext - Optional runtime context to pass as query parameter
878
1349
  * @returns Promise containing network details
879
1350
  */
880
- details() {
881
- return this.request(`/api/networks/${this.networkId}`);
1351
+ details(runtimeContext) {
1352
+ return this.request(`/api/networks/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
882
1353
  }
883
1354
  /**
884
1355
  * Generates a response from the agent
@@ -1012,10 +1483,13 @@ var Vector = class extends BaseResource {
1012
1483
  /**
1013
1484
  * Retrieves details about a specific vector index
1014
1485
  * @param indexName - Name of the index to get details for
1486
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1015
1487
  * @returns Promise containing vector index details
1016
1488
  */
1017
- details(indexName) {
1018
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1489
+ details(indexName, runtimeContext) {
1490
+ return this.request(
1491
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1492
+ );
1019
1493
  }
1020
1494
  /**
1021
1495
  * Deletes a vector index
@@ -1029,10 +1503,11 @@ var Vector = class extends BaseResource {
1029
1503
  }
1030
1504
  /**
1031
1505
  * Retrieves a list of all available indexes
1506
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1032
1507
  * @returns Promise containing array of index names
1033
1508
  */
1034
- getIndexes() {
1035
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1509
+ getIndexes(runtimeContext) {
1510
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1036
1511
  }
1037
1512
  /**
1038
1513
  * Creates a new vector index
@@ -1078,17 +1553,20 @@ var LegacyWorkflow = class extends BaseResource {
1078
1553
  }
1079
1554
  /**
1080
1555
  * Retrieves details about the legacy workflow
1556
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1081
1557
  * @returns Promise containing legacy workflow details including steps and graphs
1082
1558
  */
1083
- details() {
1084
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1559
+ details(runtimeContext) {
1560
+ return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1085
1561
  }
1086
1562
  /**
1087
1563
  * Retrieves all runs for a legacy workflow
1088
1564
  * @param params - Parameters for filtering runs
1565
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1089
1566
  * @returns Promise containing legacy workflow runs array
1090
1567
  */
1091
- runs(params) {
1568
+ runs(params, runtimeContext) {
1569
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1092
1570
  const searchParams = new URLSearchParams();
1093
1571
  if (params?.fromDate) {
1094
1572
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1105,6 +1583,9 @@ var LegacyWorkflow = class extends BaseResource {
1105
1583
  if (params?.resourceId) {
1106
1584
  searchParams.set("resourceId", params.resourceId);
1107
1585
  }
1586
+ if (runtimeContextParam) {
1587
+ searchParams.set("runtimeContext", runtimeContextParam);
1588
+ }
1108
1589
  if (searchParams.size) {
1109
1590
  return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1110
1591
  } else {
@@ -1251,17 +1732,18 @@ var LegacyWorkflow = class extends BaseResource {
1251
1732
  };
1252
1733
 
1253
1734
  // src/resources/tool.ts
1254
- var Tool2 = class extends BaseResource {
1735
+ var Tool = class extends BaseResource {
1255
1736
  constructor(options, toolId) {
1256
1737
  super(options);
1257
1738
  this.toolId = toolId;
1258
1739
  }
1259
1740
  /**
1260
1741
  * Retrieves details about the tool
1742
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1261
1743
  * @returns Promise containing tool details including description and schemas
1262
1744
  */
1263
- details() {
1264
- return this.request(`/api/tools/${this.toolId}`);
1745
+ details(runtimeContext) {
1746
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1265
1747
  }
1266
1748
  /**
1267
1749
  * Executes the tool with the provided parameters
@@ -1338,17 +1820,20 @@ var Workflow = class extends BaseResource {
1338
1820
  }
1339
1821
  /**
1340
1822
  * Retrieves details about the workflow
1823
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1341
1824
  * @returns Promise containing workflow details including steps and graphs
1342
1825
  */
1343
- details() {
1344
- return this.request(`/api/workflows/${this.workflowId}`);
1826
+ details(runtimeContext) {
1827
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1345
1828
  }
1346
1829
  /**
1347
1830
  * Retrieves all runs for a workflow
1348
1831
  * @param params - Parameters for filtering runs
1832
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1349
1833
  * @returns Promise containing workflow runs array
1350
1834
  */
1351
- runs(params) {
1835
+ runs(params, runtimeContext) {
1836
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1352
1837
  const searchParams = new URLSearchParams();
1353
1838
  if (params?.fromDate) {
1354
1839
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1365,6 +1850,9 @@ var Workflow = class extends BaseResource {
1365
1850
  if (params?.resourceId) {
1366
1851
  searchParams.set("resourceId", params.resourceId);
1367
1852
  }
1853
+ if (runtimeContextParam) {
1854
+ searchParams.set("runtimeContext", runtimeContextParam);
1855
+ }
1368
1856
  if (searchParams.size) {
1369
1857
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1370
1858
  } else {
@@ -1374,18 +1862,22 @@ var Workflow = class extends BaseResource {
1374
1862
  /**
1375
1863
  * Retrieves a specific workflow run by its ID
1376
1864
  * @param runId - The ID of the workflow run to retrieve
1865
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1377
1866
  * @returns Promise containing the workflow run details
1378
1867
  */
1379
- runById(runId) {
1380
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1868
+ runById(runId, runtimeContext) {
1869
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1381
1870
  }
1382
1871
  /**
1383
1872
  * Retrieves the execution result for a specific workflow run by its ID
1384
1873
  * @param runId - The ID of the workflow run to retrieve the execution result for
1874
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1385
1875
  * @returns Promise containing the workflow run execution result
1386
1876
  */
1387
- runExecutionResult(runId) {
1388
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1877
+ runExecutionResult(runId, runtimeContext) {
1878
+ return this.request(
1879
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1880
+ );
1389
1881
  }
1390
1882
  /**
1391
1883
  * Cancels a specific workflow run by its ID
@@ -1413,14 +1905,40 @@ var Workflow = class extends BaseResource {
1413
1905
  * @param params - Optional object containing the optional runId
1414
1906
  * @returns Promise containing the runId of the created run
1415
1907
  */
1416
- createRun(params) {
1908
+ /** @deprecated Use createRunAsync instead */
1909
+ async createRun(params) {
1417
1910
  const searchParams = new URLSearchParams();
1418
1911
  if (!!params?.runId) {
1419
1912
  searchParams.set("runId", params.runId);
1420
1913
  }
1421
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1422
- method: "POST"
1423
- });
1914
+ const res = await this.request(
1915
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1916
+ {
1917
+ method: "POST"
1918
+ }
1919
+ );
1920
+ const runId = res.runId;
1921
+ return {
1922
+ runId,
1923
+ start: async (p) => {
1924
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1925
+ },
1926
+ startAsync: async (p) => {
1927
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1928
+ },
1929
+ watch: async (onRecord) => {
1930
+ return this.watch({ runId }, onRecord);
1931
+ },
1932
+ stream: async (p) => {
1933
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1934
+ },
1935
+ resume: async (p) => {
1936
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1937
+ },
1938
+ resumeAsync: async (p) => {
1939
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1940
+ }
1941
+ };
1424
1942
  }
1425
1943
  /**
1426
1944
  * Creates a new workflow run (alias for createRun)
@@ -1456,51 +1974,491 @@ var Workflow = class extends BaseResource {
1456
1974
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1457
1975
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1458
1976
  method: "POST",
1459
- stream: true,
1460
1977
  body: {
1461
1978
  step,
1462
1979
  resumeData,
1463
1980
  runtimeContext
1464
1981
  }
1465
- });
1982
+ });
1983
+ }
1984
+ /**
1985
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1986
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1987
+ * @returns Promise containing the workflow execution results
1988
+ */
1989
+ startAsync(params) {
1990
+ const searchParams = new URLSearchParams();
1991
+ if (!!params?.runId) {
1992
+ searchParams.set("runId", params.runId);
1993
+ }
1994
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1995
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1996
+ method: "POST",
1997
+ body: { inputData: params.inputData, runtimeContext }
1998
+ });
1999
+ }
2000
+ /**
2001
+ * Starts a workflow run and returns a stream
2002
+ * @param params - Object containing the optional runId, inputData and runtimeContext
2003
+ * @returns Promise containing the workflow execution results
2004
+ */
2005
+ async stream(params) {
2006
+ const searchParams = new URLSearchParams();
2007
+ if (!!params?.runId) {
2008
+ searchParams.set("runId", params.runId);
2009
+ }
2010
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2011
+ const response = await this.request(
2012
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
2013
+ {
2014
+ method: "POST",
2015
+ body: { inputData: params.inputData, runtimeContext },
2016
+ stream: true
2017
+ }
2018
+ );
2019
+ if (!response.ok) {
2020
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2021
+ }
2022
+ if (!response.body) {
2023
+ throw new Error("Response body is null");
2024
+ }
2025
+ let failedChunk = void 0;
2026
+ const transformStream = new TransformStream({
2027
+ start() {
2028
+ },
2029
+ async transform(chunk, controller) {
2030
+ try {
2031
+ const decoded = new TextDecoder().decode(chunk);
2032
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2033
+ for (const chunk2 of chunks) {
2034
+ if (chunk2) {
2035
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2036
+ try {
2037
+ const parsedChunk = JSON.parse(newChunk);
2038
+ controller.enqueue(parsedChunk);
2039
+ failedChunk = void 0;
2040
+ } catch {
2041
+ failedChunk = newChunk;
2042
+ }
2043
+ }
2044
+ }
2045
+ } catch {
2046
+ }
2047
+ }
2048
+ });
2049
+ return response.body.pipeThrough(transformStream);
2050
+ }
2051
+ /**
2052
+ * Starts a workflow run and returns a stream
2053
+ * @param params - Object containing the optional runId, inputData and runtimeContext
2054
+ * @returns Promise containing the workflow execution results
2055
+ */
2056
+ async streamVNext(params) {
2057
+ const searchParams = new URLSearchParams();
2058
+ if (!!params?.runId) {
2059
+ searchParams.set("runId", params.runId);
2060
+ }
2061
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2062
+ const response = await this.request(
2063
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
2064
+ {
2065
+ method: "POST",
2066
+ body: { inputData: params.inputData, runtimeContext },
2067
+ stream: true
2068
+ }
2069
+ );
2070
+ if (!response.ok) {
2071
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2072
+ }
2073
+ if (!response.body) {
2074
+ throw new Error("Response body is null");
2075
+ }
2076
+ let failedChunk = void 0;
2077
+ const transformStream = new TransformStream({
2078
+ start() {
2079
+ },
2080
+ async transform(chunk, controller) {
2081
+ try {
2082
+ const decoded = new TextDecoder().decode(chunk);
2083
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2084
+ for (const chunk2 of chunks) {
2085
+ if (chunk2) {
2086
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2087
+ try {
2088
+ const parsedChunk = JSON.parse(newChunk);
2089
+ controller.enqueue(parsedChunk);
2090
+ failedChunk = void 0;
2091
+ } catch {
2092
+ failedChunk = newChunk;
2093
+ }
2094
+ }
2095
+ }
2096
+ } catch {
2097
+ }
2098
+ }
2099
+ });
2100
+ return response.body.pipeThrough(transformStream);
2101
+ }
2102
+ /**
2103
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2104
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2105
+ * @returns Promise containing the workflow resume results
2106
+ */
2107
+ resumeAsync(params) {
2108
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2109
+ return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2110
+ method: "POST",
2111
+ body: {
2112
+ step: params.step,
2113
+ resumeData: params.resumeData,
2114
+ runtimeContext
2115
+ }
2116
+ });
2117
+ }
2118
+ /**
2119
+ * Watches workflow transitions in real-time
2120
+ * @param runId - Optional run ID to filter the watch stream
2121
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2122
+ */
2123
+ async watch({ runId }, onRecord) {
2124
+ const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2125
+ stream: true
2126
+ });
2127
+ if (!response.ok) {
2128
+ throw new Error(`Failed to watch workflow: ${response.statusText}`);
2129
+ }
2130
+ if (!response.body) {
2131
+ throw new Error("Response body is null");
2132
+ }
2133
+ for await (const record of this.streamProcessor(response.body)) {
2134
+ if (typeof record === "string") {
2135
+ onRecord(JSON.parse(record));
2136
+ } else {
2137
+ onRecord(record);
2138
+ }
2139
+ }
2140
+ }
2141
+ /**
2142
+ * Creates a new ReadableStream from an iterable or async iterable of objects,
2143
+ * serializing each as JSON and separating them with the record separator (\x1E).
2144
+ *
2145
+ * @param records - An iterable or async iterable of objects to stream
2146
+ * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
2147
+ */
2148
+ static createRecordStream(records) {
2149
+ const encoder = new TextEncoder();
2150
+ return new ReadableStream({
2151
+ async start(controller) {
2152
+ try {
2153
+ for await (const record of records) {
2154
+ const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2155
+ controller.enqueue(encoder.encode(json));
2156
+ }
2157
+ controller.close();
2158
+ } catch (err) {
2159
+ controller.error(err);
2160
+ }
2161
+ }
2162
+ });
2163
+ }
2164
+ };
2165
+
2166
+ // src/resources/a2a.ts
2167
+ var A2A = class extends BaseResource {
2168
+ constructor(options, agentId) {
2169
+ super(options);
2170
+ this.agentId = agentId;
2171
+ }
2172
+ /**
2173
+ * Get the agent card with metadata about the agent
2174
+ * @returns Promise containing the agent card information
2175
+ */
2176
+ async getCard() {
2177
+ return this.request(`/.well-known/${this.agentId}/agent-card.json`);
2178
+ }
2179
+ /**
2180
+ * Send a message to the agent and gets a message or task response
2181
+ * @param params - Parameters for the task
2182
+ * @returns Promise containing the response
2183
+ */
2184
+ async sendMessage(params) {
2185
+ const response = await this.request(`/a2a/${this.agentId}`, {
2186
+ method: "POST",
2187
+ body: {
2188
+ method: "message/send",
2189
+ params
2190
+ }
2191
+ });
2192
+ return response;
2193
+ }
2194
+ /**
2195
+ * Sends a message to an agent to initiate/continue a task and subscribes
2196
+ * the client to real-time updates for that task via Server-Sent Events (SSE).
2197
+ * @param params - Parameters for the task
2198
+ * @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
2199
+ */
2200
+ async sendStreamingMessage(params) {
2201
+ const response = await this.request(`/a2a/${this.agentId}`, {
2202
+ method: "POST",
2203
+ body: {
2204
+ method: "message/stream",
2205
+ params
2206
+ }
2207
+ });
2208
+ return response;
2209
+ }
2210
+ /**
2211
+ * Get the status and result of a task
2212
+ * @param params - Parameters for querying the task
2213
+ * @returns Promise containing the task response
2214
+ */
2215
+ async getTask(params) {
2216
+ const response = await this.request(`/a2a/${this.agentId}`, {
2217
+ method: "POST",
2218
+ body: {
2219
+ method: "tasks/get",
2220
+ params
2221
+ }
2222
+ });
2223
+ return response;
2224
+ }
2225
+ /**
2226
+ * Cancel a running task
2227
+ * @param params - Parameters identifying the task to cancel
2228
+ * @returns Promise containing the task response
2229
+ */
2230
+ async cancelTask(params) {
2231
+ return this.request(`/a2a/${this.agentId}`, {
2232
+ method: "POST",
2233
+ body: {
2234
+ method: "tasks/cancel",
2235
+ params
2236
+ }
2237
+ });
2238
+ }
2239
+ };
2240
+
2241
+ // src/resources/mcp-tool.ts
2242
+ var MCPTool = class extends BaseResource {
2243
+ serverId;
2244
+ toolId;
2245
+ constructor(options, serverId, toolId) {
2246
+ super(options);
2247
+ this.serverId = serverId;
2248
+ this.toolId = toolId;
2249
+ }
2250
+ /**
2251
+ * Retrieves details about this specific tool from the MCP server.
2252
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2253
+ * @returns Promise containing the tool's information (name, description, schema).
2254
+ */
2255
+ details(runtimeContext) {
2256
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2257
+ }
2258
+ /**
2259
+ * Executes this specific tool on the MCP server.
2260
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
2261
+ * @returns Promise containing the result of the tool execution.
2262
+ */
2263
+ execute(params) {
2264
+ const body = {};
2265
+ if (params.data !== void 0) body.data = params.data;
2266
+ if (params.runtimeContext !== void 0) {
2267
+ body.runtimeContext = params.runtimeContext;
2268
+ }
2269
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
2270
+ method: "POST",
2271
+ body: Object.keys(body).length > 0 ? body : void 0
2272
+ });
2273
+ }
2274
+ };
2275
+
2276
+ // src/resources/agent-builder.ts
2277
+ var RECORD_SEPARATOR3 = "";
2278
+ var AgentBuilder = class extends BaseResource {
2279
+ constructor(options, actionId) {
2280
+ super(options);
2281
+ this.actionId = actionId;
2282
+ }
2283
+ // Helper function to transform workflow result to action result
2284
+ transformWorkflowResult(result) {
2285
+ if (result.status === "success") {
2286
+ return {
2287
+ success: result.result.success || false,
2288
+ applied: result.result.applied || false,
2289
+ branchName: result.result.branchName,
2290
+ message: result.result.message || "Agent builder action completed",
2291
+ validationResults: result.result.validationResults,
2292
+ error: result.result.error,
2293
+ errors: result.result.errors,
2294
+ stepResults: result.result.stepResults
2295
+ };
2296
+ } else if (result.status === "failed") {
2297
+ return {
2298
+ success: false,
2299
+ applied: false,
2300
+ message: `Agent builder action failed: ${result.error.message}`,
2301
+ error: result.error.message
2302
+ };
2303
+ } else {
2304
+ return {
2305
+ success: false,
2306
+ applied: false,
2307
+ message: "Agent builder action was suspended",
2308
+ error: "Workflow suspended - manual intervention required"
2309
+ };
2310
+ }
2311
+ }
2312
+ /**
2313
+ * Creates a new agent builder action run and returns the runId.
2314
+ * This calls `/api/agent-builder/:actionId/create-run`.
2315
+ */
2316
+ async createRun(params) {
2317
+ const searchParams = new URLSearchParams();
2318
+ if (!!params?.runId) {
2319
+ searchParams.set("runId", params.runId);
2320
+ }
2321
+ const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2322
+ return this.request(url, {
2323
+ method: "POST"
2324
+ });
2325
+ }
2326
+ /**
2327
+ * Creates a new workflow run (alias for createRun)
2328
+ * @param params - Optional object containing the optional runId
2329
+ * @returns Promise containing the runId of the created run
2330
+ */
2331
+ createRunAsync(params) {
2332
+ return this.createRun(params);
2333
+ }
2334
+ /**
2335
+ * Starts agent builder action asynchronously and waits for completion.
2336
+ * This calls `/api/agent-builder/:actionId/start-async`.
2337
+ */
2338
+ async startAsync(params, runId) {
2339
+ const searchParams = new URLSearchParams();
2340
+ if (runId) {
2341
+ searchParams.set("runId", runId);
2342
+ }
2343
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2344
+ const { runtimeContext: _, ...actionParams } = params;
2345
+ const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2346
+ const result = await this.request(url, {
2347
+ method: "POST",
2348
+ body: { ...actionParams, runtimeContext }
2349
+ });
2350
+ return this.transformWorkflowResult(result);
2351
+ }
2352
+ /**
2353
+ * Starts an existing agent builder action run.
2354
+ * This calls `/api/agent-builder/:actionId/start`.
2355
+ */
2356
+ async startActionRun(params, runId) {
2357
+ const searchParams = new URLSearchParams();
2358
+ searchParams.set("runId", runId);
2359
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2360
+ const { runtimeContext: _, ...actionParams } = params;
2361
+ const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2362
+ return this.request(url, {
2363
+ method: "POST",
2364
+ body: { ...actionParams, runtimeContext }
2365
+ });
2366
+ }
2367
+ /**
2368
+ * Resumes a suspended agent builder action step.
2369
+ * This calls `/api/agent-builder/:actionId/resume`.
2370
+ */
2371
+ async resume(params, runId) {
2372
+ const searchParams = new URLSearchParams();
2373
+ searchParams.set("runId", runId);
2374
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2375
+ const { runtimeContext: _, ...resumeParams } = params;
2376
+ const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2377
+ return this.request(url, {
2378
+ method: "POST",
2379
+ body: { ...resumeParams, runtimeContext }
2380
+ });
2381
+ }
2382
+ /**
2383
+ * Resumes a suspended agent builder action step asynchronously.
2384
+ * This calls `/api/agent-builder/:actionId/resume-async`.
2385
+ */
2386
+ async resumeAsync(params, runId) {
2387
+ const searchParams = new URLSearchParams();
2388
+ searchParams.set("runId", runId);
2389
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2390
+ const { runtimeContext: _, ...resumeParams } = params;
2391
+ const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2392
+ const result = await this.request(url, {
2393
+ method: "POST",
2394
+ body: { ...resumeParams, runtimeContext }
2395
+ });
2396
+ return this.transformWorkflowResult(result);
2397
+ }
2398
+ /**
2399
+ * Creates an async generator that processes a readable stream and yields action records
2400
+ * separated by the Record Separator character (\x1E)
2401
+ *
2402
+ * @param stream - The readable stream to process
2403
+ * @returns An async generator that yields parsed records
2404
+ */
2405
+ async *streamProcessor(stream) {
2406
+ const reader = stream.getReader();
2407
+ let doneReading = false;
2408
+ let buffer = "";
2409
+ try {
2410
+ while (!doneReading) {
2411
+ const { done, value } = await reader.read();
2412
+ doneReading = done;
2413
+ if (done && !value) continue;
2414
+ try {
2415
+ const decoded = value ? new TextDecoder().decode(value) : "";
2416
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2417
+ buffer = chunks.pop() || "";
2418
+ for (const chunk of chunks) {
2419
+ if (chunk) {
2420
+ if (typeof chunk === "string") {
2421
+ try {
2422
+ const parsedChunk = JSON.parse(chunk);
2423
+ yield parsedChunk;
2424
+ } catch {
2425
+ }
2426
+ }
2427
+ }
2428
+ }
2429
+ } catch {
2430
+ }
2431
+ }
2432
+ if (buffer) {
2433
+ try {
2434
+ yield JSON.parse(buffer);
2435
+ } catch {
2436
+ }
2437
+ }
2438
+ } finally {
2439
+ reader.cancel().catch(() => {
2440
+ });
2441
+ }
1466
2442
  }
1467
2443
  /**
1468
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1469
- * @param params - Object containing the optional runId, inputData and runtimeContext
1470
- * @returns Promise containing the workflow execution results
2444
+ * Streams agent builder action progress in real-time.
2445
+ * This calls `/api/agent-builder/:actionId/stream`.
1471
2446
  */
1472
- startAsync(params) {
2447
+ async stream(params, runId) {
1473
2448
  const searchParams = new URLSearchParams();
1474
- if (!!params?.runId) {
1475
- searchParams.set("runId", params.runId);
2449
+ if (runId) {
2450
+ searchParams.set("runId", runId);
1476
2451
  }
1477
2452
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1478
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
2453
+ const { runtimeContext: _, ...actionParams } = params;
2454
+ const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2455
+ const response = await this.request(url, {
1479
2456
  method: "POST",
1480
- body: { inputData: params.inputData, runtimeContext }
2457
+ body: { ...actionParams, runtimeContext },
2458
+ stream: true
1481
2459
  });
1482
- }
1483
- /**
1484
- * Starts a workflow run and returns a stream
1485
- * @param params - Object containing the optional runId, inputData and runtimeContext
1486
- * @returns Promise containing the workflow execution results
1487
- */
1488
- async stream(params) {
1489
- const searchParams = new URLSearchParams();
1490
- if (!!params?.runId) {
1491
- searchParams.set("runId", params.runId);
1492
- }
1493
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1494
- const response = await this.request(
1495
- `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1496
- {
1497
- method: "POST",
1498
- body: { inputData: params.inputData, runtimeContext },
1499
- stream: true
1500
- }
1501
- );
1502
2460
  if (!response.ok) {
1503
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2461
+ throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
1504
2462
  }
1505
2463
  if (!response.body) {
1506
2464
  throw new Error("Response body is null");
@@ -1512,7 +2470,7 @@ var Workflow = class extends BaseResource {
1512
2470
  async transform(chunk, controller) {
1513
2471
  try {
1514
2472
  const decoded = new TextDecoder().decode(chunk);
1515
- const chunks = decoded.split(RECORD_SEPARATOR2);
2473
+ const chunks = decoded.split(RECORD_SEPARATOR3);
1516
2474
  for (const chunk2 of chunks) {
1517
2475
  if (chunk2) {
1518
2476
  const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
@@ -1520,7 +2478,7 @@ var Workflow = class extends BaseResource {
1520
2478
  const parsedChunk = JSON.parse(newChunk);
1521
2479
  controller.enqueue(parsedChunk);
1522
2480
  failedChunk = void 0;
1523
- } catch (error) {
2481
+ } catch {
1524
2482
  failedChunk = newChunk;
1525
2483
  }
1526
2484
  }
@@ -1532,32 +2490,68 @@ var Workflow = class extends BaseResource {
1532
2490
  return response.body.pipeThrough(transformStream);
1533
2491
  }
1534
2492
  /**
1535
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1536
- * @param params - Object containing the runId, step, resumeData and runtimeContext
1537
- * @returns Promise containing the workflow resume results
2493
+ * Streams agent builder action progress in real-time using VNext streaming.
2494
+ * This calls `/api/agent-builder/:actionId/streamVNext`.
1538
2495
  */
1539
- resumeAsync(params) {
2496
+ async streamVNext(params, runId) {
2497
+ const searchParams = new URLSearchParams();
2498
+ if (runId) {
2499
+ searchParams.set("runId", runId);
2500
+ }
1540
2501
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1541
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
2502
+ const { runtimeContext: _, ...actionParams } = params;
2503
+ const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2504
+ const response = await this.request(url, {
1542
2505
  method: "POST",
1543
- body: {
1544
- step: params.step,
1545
- resumeData: params.resumeData,
1546
- runtimeContext
2506
+ body: { ...actionParams, runtimeContext },
2507
+ stream: true
2508
+ });
2509
+ if (!response.ok) {
2510
+ throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
2511
+ }
2512
+ if (!response.body) {
2513
+ throw new Error("Response body is null");
2514
+ }
2515
+ let failedChunk = void 0;
2516
+ const transformStream = new TransformStream({
2517
+ start() {
2518
+ },
2519
+ async transform(chunk, controller) {
2520
+ try {
2521
+ const decoded = new TextDecoder().decode(chunk);
2522
+ const chunks = decoded.split(RECORD_SEPARATOR3);
2523
+ for (const chunk2 of chunks) {
2524
+ if (chunk2) {
2525
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2526
+ try {
2527
+ const parsedChunk = JSON.parse(newChunk);
2528
+ controller.enqueue(parsedChunk);
2529
+ failedChunk = void 0;
2530
+ } catch {
2531
+ failedChunk = newChunk;
2532
+ }
2533
+ }
2534
+ }
2535
+ } catch {
2536
+ }
1547
2537
  }
1548
2538
  });
2539
+ return response.body.pipeThrough(transformStream);
1549
2540
  }
1550
2541
  /**
1551
- * Watches workflow transitions in real-time
1552
- * @param runId - Optional run ID to filter the watch stream
1553
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
2542
+ * Watches an existing agent builder action run by runId.
2543
+ * This is used for hot reload recovery - it loads the existing run state
2544
+ * and streams any remaining progress.
2545
+ * This calls `/api/agent-builder/:actionId/watch`.
1554
2546
  */
1555
- async watch({ runId }, onRecord) {
1556
- const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
2547
+ async watch({ runId, eventType }, onRecord) {
2548
+ const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
2549
+ const response = await this.request(url, {
2550
+ method: "GET",
1557
2551
  stream: true
1558
2552
  });
1559
2553
  if (!response.ok) {
1560
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
2554
+ throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
1561
2555
  }
1562
2556
  if (!response.body) {
1563
2557
  throw new Error("Response body is null");
@@ -1571,135 +2565,130 @@ var Workflow = class extends BaseResource {
1571
2565
  }
1572
2566
  }
1573
2567
  /**
1574
- * Creates a new ReadableStream from an iterable or async iterable of objects,
1575
- * serializing each as JSON and separating them with the record separator (\x1E).
1576
- *
1577
- * @param records - An iterable or async iterable of objects to stream
1578
- * @returns A ReadableStream emitting the records as JSON strings separated by the record separator
2568
+ * Gets a specific action run by its ID.
2569
+ * This calls `/api/agent-builder/:actionId/runs/:runId`.
1579
2570
  */
1580
- static createRecordStream(records) {
1581
- const encoder = new TextEncoder();
1582
- return new ReadableStream({
1583
- async start(controller) {
1584
- try {
1585
- for await (const record of records) {
1586
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
1587
- controller.enqueue(encoder.encode(json));
1588
- }
1589
- controller.close();
1590
- } catch (err) {
1591
- controller.error(err);
1592
- }
1593
- }
2571
+ async runById(runId) {
2572
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
2573
+ return this.request(url, {
2574
+ method: "GET"
1594
2575
  });
1595
2576
  }
1596
- };
1597
-
1598
- // src/resources/a2a.ts
1599
- var A2A = class extends BaseResource {
1600
- constructor(options, agentId) {
1601
- super(options);
1602
- this.agentId = agentId;
1603
- }
1604
2577
  /**
1605
- * Get the agent card with metadata about the agent
1606
- * @returns Promise containing the agent card information
2578
+ * Gets details about this agent builder action.
2579
+ * This calls `/api/agent-builder/:actionId`.
1607
2580
  */
1608
- async getCard() {
1609
- return this.request(`/.well-known/${this.agentId}/agent.json`);
2581
+ async details() {
2582
+ const result = await this.request(`/api/agent-builder/${this.actionId}`);
2583
+ return result;
1610
2584
  }
1611
2585
  /**
1612
- * Send a message to the agent and get a response
1613
- * @param params - Parameters for the task
1614
- * @returns Promise containing the task response
2586
+ * Gets all runs for this agent builder action.
2587
+ * This calls `/api/agent-builder/:actionId/runs`.
1615
2588
  */
1616
- async sendMessage(params) {
1617
- const response = await this.request(`/a2a/${this.agentId}`, {
1618
- method: "POST",
1619
- body: {
1620
- method: "tasks/send",
1621
- params
1622
- }
2589
+ async runs(params) {
2590
+ const searchParams = new URLSearchParams();
2591
+ if (params?.fromDate) {
2592
+ searchParams.set("fromDate", params.fromDate.toISOString());
2593
+ }
2594
+ if (params?.toDate) {
2595
+ searchParams.set("toDate", params.toDate.toISOString());
2596
+ }
2597
+ if (params?.limit !== void 0) {
2598
+ searchParams.set("limit", String(params.limit));
2599
+ }
2600
+ if (params?.offset !== void 0) {
2601
+ searchParams.set("offset", String(params.offset));
2602
+ }
2603
+ if (params?.resourceId) {
2604
+ searchParams.set("resourceId", params.resourceId);
2605
+ }
2606
+ const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2607
+ return this.request(url, {
2608
+ method: "GET"
1623
2609
  });
1624
- return { task: response.result };
1625
2610
  }
1626
2611
  /**
1627
- * Get the status and result of a task
1628
- * @param params - Parameters for querying the task
1629
- * @returns Promise containing the task response
2612
+ * Gets the execution result of an agent builder action run.
2613
+ * This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
1630
2614
  */
1631
- async getTask(params) {
1632
- const response = await this.request(`/a2a/${this.agentId}`, {
1633
- method: "POST",
1634
- body: {
1635
- method: "tasks/get",
1636
- params
1637
- }
2615
+ async runExecutionResult(runId) {
2616
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
2617
+ return this.request(url, {
2618
+ method: "GET"
1638
2619
  });
1639
- return response.result;
1640
2620
  }
1641
2621
  /**
1642
- * Cancel a running task
1643
- * @param params - Parameters identifying the task to cancel
1644
- * @returns Promise containing the task response
2622
+ * Cancels an agent builder action run.
2623
+ * This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
1645
2624
  */
1646
- async cancelTask(params) {
1647
- return this.request(`/a2a/${this.agentId}`, {
1648
- method: "POST",
1649
- body: {
1650
- method: "tasks/cancel",
1651
- params
1652
- }
2625
+ async cancelRun(runId) {
2626
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
2627
+ return this.request(url, {
2628
+ method: "POST"
1653
2629
  });
1654
2630
  }
1655
2631
  /**
1656
- * Send a message and subscribe to streaming updates (not fully implemented)
1657
- * @param params - Parameters for the task
1658
- * @returns Promise containing the task response
2632
+ * Sends an event to an agent builder action run.
2633
+ * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
1659
2634
  */
1660
- async sendAndSubscribe(params) {
1661
- return this.request(`/a2a/${this.agentId}`, {
2635
+ async sendRunEvent(params) {
2636
+ const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2637
+ return this.request(url, {
1662
2638
  method: "POST",
1663
- body: {
1664
- method: "tasks/sendSubscribe",
1665
- params
1666
- },
1667
- stream: true
2639
+ body: { event: params.event, data: params.data }
1668
2640
  });
1669
2641
  }
1670
2642
  };
1671
2643
 
1672
- // src/resources/mcp-tool.ts
1673
- var MCPTool = class extends BaseResource {
1674
- serverId;
1675
- toolId;
1676
- constructor(options, serverId, toolId) {
2644
+ // src/resources/observability.ts
2645
+ var Observability = class extends BaseResource {
2646
+ constructor(options) {
1677
2647
  super(options);
1678
- this.serverId = serverId;
1679
- this.toolId = toolId;
1680
2648
  }
1681
2649
  /**
1682
- * Retrieves details about this specific tool from the MCP server.
1683
- * @returns Promise containing the tool's information (name, description, schema).
2650
+ * Retrieves a specific AI trace by ID
2651
+ * @param traceId - ID of the trace to retrieve
2652
+ * @returns Promise containing the AI trace with all its spans
1684
2653
  */
1685
- details() {
1686
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2654
+ getTrace(traceId) {
2655
+ return this.request(`/api/observability/traces/${traceId}`);
1687
2656
  }
1688
2657
  /**
1689
- * Executes this specific tool on the MCP server.
1690
- * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1691
- * @returns Promise containing the result of the tool execution.
2658
+ * Retrieves paginated list of AI traces with optional filtering
2659
+ * @param params - Parameters for pagination and filtering
2660
+ * @returns Promise containing paginated traces and pagination info
1692
2661
  */
1693
- execute(params) {
1694
- const body = {};
1695
- if (params.data !== void 0) body.data = params.data;
1696
- if (params.runtimeContext !== void 0) {
1697
- body.runtimeContext = params.runtimeContext;
2662
+ getTraces(params) {
2663
+ const { pagination, filters } = params;
2664
+ const { page, perPage, dateRange } = pagination || {};
2665
+ const { name, spanType, entityId, entityType } = filters || {};
2666
+ const searchParams = new URLSearchParams();
2667
+ if (page !== void 0) {
2668
+ searchParams.set("page", String(page));
1698
2669
  }
1699
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1700
- method: "POST",
1701
- body: Object.keys(body).length > 0 ? body : void 0
1702
- });
2670
+ if (perPage !== void 0) {
2671
+ searchParams.set("perPage", String(perPage));
2672
+ }
2673
+ if (name) {
2674
+ searchParams.set("name", name);
2675
+ }
2676
+ if (spanType !== void 0) {
2677
+ searchParams.set("spanType", String(spanType));
2678
+ }
2679
+ if (entityId && entityType) {
2680
+ searchParams.set("entityId", entityId);
2681
+ searchParams.set("entityType", entityType);
2682
+ }
2683
+ if (dateRange) {
2684
+ const dateRangeStr = JSON.stringify({
2685
+ start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
2686
+ end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
2687
+ });
2688
+ searchParams.set("dateRange", dateRangeStr);
2689
+ }
2690
+ const queryString = searchParams.toString();
2691
+ return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
1703
2692
  }
1704
2693
  };
1705
2694
 
@@ -1767,7 +2756,7 @@ var NetworkMemoryThread = class extends BaseResource {
1767
2756
  };
1768
2757
 
1769
2758
  // src/resources/vNextNetwork.ts
1770
- var RECORD_SEPARATOR3 = "";
2759
+ var RECORD_SEPARATOR4 = "";
1771
2760
  var VNextNetwork = class extends BaseResource {
1772
2761
  constructor(options, networkId) {
1773
2762
  super(options);
@@ -1775,10 +2764,11 @@ var VNextNetwork = class extends BaseResource {
1775
2764
  }
1776
2765
  /**
1777
2766
  * Retrieves details about the network
2767
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1778
2768
  * @returns Promise containing vNext network details
1779
2769
  */
1780
- details() {
1781
- return this.request(`/api/networks/v-next/${this.networkId}`);
2770
+ details(runtimeContext) {
2771
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
1782
2772
  }
1783
2773
  /**
1784
2774
  * Generates a response from the v-next network
@@ -1819,7 +2809,7 @@ var VNextNetwork = class extends BaseResource {
1819
2809
  if (done && !value) continue;
1820
2810
  try {
1821
2811
  const decoded = value ? new TextDecoder().decode(value) : "";
1822
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2812
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
1823
2813
  buffer = chunks.pop() || "";
1824
2814
  for (const chunk of chunks) {
1825
2815
  if (chunk) {
@@ -1906,30 +2896,24 @@ var VNextNetwork = class extends BaseResource {
1906
2896
 
1907
2897
  // src/client.ts
1908
2898
  var MastraClient = class extends BaseResource {
2899
+ observability;
1909
2900
  constructor(options) {
1910
2901
  super(options);
2902
+ this.observability = new Observability(options);
1911
2903
  }
1912
2904
  /**
1913
2905
  * Retrieves all available agents
2906
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1914
2907
  * @returns Promise containing map of agent IDs to agent details
1915
2908
  */
1916
- getAgents() {
1917
- return this.request("/api/agents");
1918
- }
1919
- async getAGUI({ resourceId }) {
1920
- const agents = await this.getAgents();
1921
- return Object.entries(agents).reduce(
1922
- (acc, [agentId]) => {
1923
- const agent = this.getAgent(agentId);
1924
- acc[agentId] = new AGUIAdapter({
1925
- agentId,
1926
- agent,
1927
- resourceId
1928
- });
1929
- return acc;
1930
- },
1931
- {}
1932
- );
2909
+ getAgents(runtimeContext) {
2910
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2911
+ const searchParams = new URLSearchParams();
2912
+ if (runtimeContextParam) {
2913
+ searchParams.set("runtimeContext", runtimeContextParam);
2914
+ }
2915
+ const queryString = searchParams.toString();
2916
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
1933
2917
  }
1934
2918
  /**
1935
2919
  * Gets an agent instance by ID
@@ -2025,10 +3009,17 @@ var MastraClient = class extends BaseResource {
2025
3009
  }
2026
3010
  /**
2027
3011
  * Retrieves all available tools
3012
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2028
3013
  * @returns Promise containing map of tool IDs to tool details
2029
3014
  */
2030
- getTools() {
2031
- return this.request("/api/tools");
3015
+ getTools(runtimeContext) {
3016
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3017
+ const searchParams = new URLSearchParams();
3018
+ if (runtimeContextParam) {
3019
+ searchParams.set("runtimeContext", runtimeContextParam);
3020
+ }
3021
+ const queryString = searchParams.toString();
3022
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2032
3023
  }
2033
3024
  /**
2034
3025
  * Gets a tool instance by ID
@@ -2036,7 +3027,7 @@ var MastraClient = class extends BaseResource {
2036
3027
  * @returns Tool instance
2037
3028
  */
2038
3029
  getTool(toolId) {
2039
- return new Tool2(this.options, toolId);
3030
+ return new Tool(this.options, toolId);
2040
3031
  }
2041
3032
  /**
2042
3033
  * Retrieves all available legacy workflows
@@ -2055,10 +3046,17 @@ var MastraClient = class extends BaseResource {
2055
3046
  }
2056
3047
  /**
2057
3048
  * Retrieves all available workflows
3049
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2058
3050
  * @returns Promise containing map of workflow IDs to workflow details
2059
3051
  */
2060
- getWorkflows() {
2061
- return this.request("/api/workflows");
3052
+ getWorkflows(runtimeContext) {
3053
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3054
+ const searchParams = new URLSearchParams();
3055
+ if (runtimeContextParam) {
3056
+ searchParams.set("runtimeContext", runtimeContextParam);
3057
+ }
3058
+ const queryString = searchParams.toString();
3059
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2062
3060
  }
2063
3061
  /**
2064
3062
  * Gets a workflow instance by ID
@@ -2068,6 +3066,20 @@ var MastraClient = class extends BaseResource {
2068
3066
  getWorkflow(workflowId) {
2069
3067
  return new Workflow(this.options, workflowId);
2070
3068
  }
3069
+ /**
3070
+ * Gets all available agent builder actions
3071
+ * @returns Promise containing map of action IDs to action details
3072
+ */
3073
+ getAgentBuilderActions() {
3074
+ return this.request("/api/agent-builder/");
3075
+ }
3076
+ /**
3077
+ * Gets an agent builder instance for executing agent-builder workflows
3078
+ * @returns AgentBuilder instance
3079
+ */
3080
+ getAgentBuilderAction(actionId) {
3081
+ return new AgentBuilder(this.options, actionId);
3082
+ }
2071
3083
  /**
2072
3084
  * Gets a vector instance by name
2073
3085
  * @param vectorName - Name of the vector to retrieve
@@ -2411,8 +3423,42 @@ var MastraClient = class extends BaseResource {
2411
3423
  body: params
2412
3424
  });
2413
3425
  }
3426
+ /**
3427
+ * Retrieves model providers with available keys
3428
+ * @returns Promise containing model providers with available keys
3429
+ */
3430
+ getModelProviders() {
3431
+ return this.request(`/api/model-providers`);
3432
+ }
3433
+ getAITrace(traceId) {
3434
+ return this.observability.getTrace(traceId);
3435
+ }
3436
+ getAITraces(params) {
3437
+ return this.observability.getTraces(params);
3438
+ }
2414
3439
  };
2415
3440
 
3441
+ // src/tools.ts
3442
+ var ClientTool = class {
3443
+ id;
3444
+ description;
3445
+ inputSchema;
3446
+ outputSchema;
3447
+ execute;
3448
+ constructor(opts) {
3449
+ this.id = opts.id;
3450
+ this.description = opts.description;
3451
+ this.inputSchema = opts.inputSchema;
3452
+ this.outputSchema = opts.outputSchema;
3453
+ this.execute = opts.execute;
3454
+ }
3455
+ };
3456
+ function createTool(opts) {
3457
+ return new ClientTool(opts);
3458
+ }
3459
+
3460
+ exports.ClientTool = ClientTool;
2416
3461
  exports.MastraClient = MastraClient;
3462
+ exports.createTool = createTool;
2417
3463
  //# sourceMappingURL=index.cjs.map
2418
3464
  //# sourceMappingURL=index.cjs.map