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