@mastra/client-js 0.0.0-tsconfig-compile-20250703214351 → 0.0.0-unified-sidebar-20251010130811

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 (78) hide show
  1. package/CHANGELOG.md +1400 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +6 -7
  4. package/dist/client.d.ts +278 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/example.d.ts +2 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/index.cjs +1761 -674
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +5 -1164
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +1759 -674
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/a2a.d.ts +41 -0
  15. package/dist/resources/a2a.d.ts.map +1 -0
  16. package/dist/resources/agent-builder.d.ts +160 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +184 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/mcp-tool.d.ts +28 -0
  25. package/dist/resources/mcp-tool.d.ts.map +1 -0
  26. package/dist/resources/memory-thread.d.ts +53 -0
  27. package/dist/resources/memory-thread.d.ts.map +1 -0
  28. package/dist/resources/network-memory-thread.d.ts +47 -0
  29. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  30. package/dist/resources/observability.d.ts +35 -0
  31. package/dist/resources/observability.d.ts.map +1 -0
  32. package/dist/resources/tool.d.ts +24 -0
  33. package/dist/resources/tool.d.ts.map +1 -0
  34. package/dist/resources/vector.d.ts +51 -0
  35. package/dist/resources/vector.d.ts.map +1 -0
  36. package/dist/resources/workflow.d.ts +269 -0
  37. package/dist/resources/workflow.d.ts.map +1 -0
  38. package/dist/tools.d.ts +22 -0
  39. package/dist/tools.d.ts.map +1 -0
  40. package/dist/types.d.ts +479 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/utils/index.d.ts +5 -0
  43. package/dist/utils/index.d.ts.map +1 -0
  44. package/dist/utils/process-client-tools.d.ts +3 -0
  45. package/dist/utils/process-client-tools.d.ts.map +1 -0
  46. package/dist/utils/process-mastra-stream.d.ts +11 -0
  47. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/package.json +27 -15
  51. package/.turbo/turbo-build.log +0 -19
  52. package/dist/index.d.cts +0 -1164
  53. package/eslint.config.js +0 -6
  54. package/src/adapters/agui.test.ts +0 -180
  55. package/src/adapters/agui.ts +0 -239
  56. package/src/client.ts +0 -480
  57. package/src/example.ts +0 -67
  58. package/src/index.test.ts +0 -830
  59. package/src/index.ts +0 -2
  60. package/src/resources/a2a.ts +0 -88
  61. package/src/resources/agent.ts +0 -763
  62. package/src/resources/base.ts +0 -71
  63. package/src/resources/index.ts +0 -10
  64. package/src/resources/legacy-workflow.ts +0 -242
  65. package/src/resources/mcp-tool.ts +0 -48
  66. package/src/resources/memory-thread.ts +0 -63
  67. package/src/resources/network-memory-thread.ts +0 -63
  68. package/src/resources/network.ts +0 -85
  69. package/src/resources/tool.ts +0 -45
  70. package/src/resources/vNextNetwork.ts +0 -177
  71. package/src/resources/vector.ts +0 -83
  72. package/src/resources/workflow.ts +0 -396
  73. package/src/types.ts +0 -422
  74. package/src/utils/index.ts +0 -11
  75. package/src/utils/process-client-tools.ts +0 -32
  76. package/src/utils/zod-to-json-schema.ts +0 -10
  77. package/tsconfig.json +0 -5
  78. package/vitest.config.js +0 -8
package/dist/index.js CHANGED
@@ -1,202 +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';
2
+ import { v4 } from '@lukeed/uuid';
7
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';
8
7
 
9
- // src/adapters/agui.ts
10
- var AGUIAdapter = class extends AbstractAgent {
11
- agent;
12
- resourceId;
13
- constructor({ agent, agentId, resourceId, ...rest }) {
14
- super({
15
- agentId,
16
- ...rest
17
- });
18
- this.agent = agent;
19
- this.resourceId = resourceId;
20
- }
21
- run(input) {
22
- return new Observable((subscriber) => {
23
- const convertedMessages = convertMessagesToMastraMessages(input.messages);
24
- subscriber.next({
25
- type: EventType.RUN_STARTED,
26
- threadId: input.threadId,
27
- runId: input.runId
28
- });
29
- this.agent.stream({
30
- threadId: input.threadId,
31
- resourceId: this.resourceId ?? "",
32
- runId: input.runId,
33
- messages: convertedMessages,
34
- clientTools: input.tools.reduce(
35
- (acc, tool) => {
36
- acc[tool.name] = {
37
- id: tool.name,
38
- description: tool.description,
39
- inputSchema: tool.parameters
40
- };
41
- return acc;
42
- },
43
- {}
44
- )
45
- }).then((response) => {
46
- let currentMessageId = void 0;
47
- let isInTextMessage = false;
48
- return response.processDataStream({
49
- onTextPart: (text) => {
50
- if (currentMessageId === void 0) {
51
- currentMessageId = generateUUID();
52
- const message2 = {
53
- type: EventType.TEXT_MESSAGE_START,
54
- messageId: currentMessageId,
55
- role: "assistant"
56
- };
57
- subscriber.next(message2);
58
- isInTextMessage = true;
59
- }
60
- const message = {
61
- type: EventType.TEXT_MESSAGE_CONTENT,
62
- messageId: currentMessageId,
63
- delta: text
64
- };
65
- subscriber.next(message);
66
- },
67
- onFinishMessagePart: () => {
68
- if (currentMessageId !== void 0) {
69
- const message = {
70
- type: EventType.TEXT_MESSAGE_END,
71
- messageId: currentMessageId
72
- };
73
- subscriber.next(message);
74
- isInTextMessage = false;
75
- }
76
- subscriber.next({
77
- type: EventType.RUN_FINISHED,
78
- threadId: input.threadId,
79
- runId: input.runId
80
- });
81
- subscriber.complete();
82
- },
83
- onToolCallPart(streamPart) {
84
- const parentMessageId = currentMessageId || generateUUID();
85
- if (isInTextMessage) {
86
- const message = {
87
- type: EventType.TEXT_MESSAGE_END,
88
- messageId: parentMessageId
89
- };
90
- subscriber.next(message);
91
- isInTextMessage = false;
92
- }
93
- subscriber.next({
94
- type: EventType.TOOL_CALL_START,
95
- toolCallId: streamPart.toolCallId,
96
- toolCallName: streamPart.toolName,
97
- parentMessageId
98
- });
99
- subscriber.next({
100
- type: EventType.TOOL_CALL_ARGS,
101
- toolCallId: streamPart.toolCallId,
102
- delta: JSON.stringify(streamPart.args),
103
- parentMessageId
104
- });
105
- subscriber.next({
106
- type: EventType.TOOL_CALL_END,
107
- toolCallId: streamPart.toolCallId,
108
- parentMessageId
109
- });
110
- }
111
- });
112
- }).catch((error) => {
113
- console.error("error", error);
114
- subscriber.error(error);
115
- });
116
- return () => {
117
- };
118
- });
119
- }
120
- };
121
- function generateUUID() {
122
- if (typeof crypto !== "undefined") {
123
- if (typeof crypto.randomUUID === "function") {
124
- return crypto.randomUUID();
125
- }
126
- if (typeof crypto.getRandomValues === "function") {
127
- const buffer = new Uint8Array(16);
128
- crypto.getRandomValues(buffer);
129
- buffer[6] = buffer[6] & 15 | 64;
130
- buffer[8] = buffer[8] & 63 | 128;
131
- let hex = "";
132
- for (let i = 0; i < 16; i++) {
133
- hex += buffer[i].toString(16).padStart(2, "0");
134
- if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
135
- }
136
- 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());
137
13
  }
14
+ return runtimeContext;
138
15
  }
139
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
140
- const r = Math.random() * 16 | 0;
141
- const v = c === "x" ? r : r & 3 | 8;
142
- return v.toString(16);
143
- });
16
+ return void 0;
144
17
  }
145
- function convertMessagesToMastraMessages(messages) {
146
- const result = [];
147
- for (const message of messages) {
148
- if (message.role === "assistant") {
149
- const parts = message.content ? [{ type: "text", text: message.content }] : [];
150
- for (const toolCall of message.toolCalls ?? []) {
151
- parts.push({
152
- type: "tool-call",
153
- toolCallId: toolCall.id,
154
- toolName: toolCall.function.name,
155
- args: JSON.parse(toolCall.function.arguments)
156
- });
157
- }
158
- result.push({
159
- role: "assistant",
160
- content: parts
161
- });
162
- if (message.toolCalls?.length) {
163
- result.push({
164
- role: "tool",
165
- content: message.toolCalls.map((toolCall) => ({
166
- type: "tool-result",
167
- toolCallId: toolCall.id,
168
- toolName: toolCall.function.name,
169
- result: JSON.parse(toolCall.function.arguments)
170
- }))
171
- });
172
- }
173
- } else if (message.role === "user") {
174
- result.push({
175
- role: "user",
176
- content: message.content || ""
177
- });
178
- } else if (message.role === "tool") {
179
- result.push({
180
- role: "tool",
181
- content: [
182
- {
183
- type: "tool-result",
184
- toolCallId: message.toolCallId,
185
- toolName: "unknown",
186
- result: message.content
187
- }
188
- ]
189
- });
190
- }
18
+ function base64RuntimeContext(runtimeContext) {
19
+ if (runtimeContext) {
20
+ return btoa(JSON.stringify(runtimeContext));
191
21
  }
192
- 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";
193
34
  }
194
35
  function zodToJsonSchema(zodSchema) {
195
- if (!(zodSchema instanceof ZodSchema)) {
36
+ if (!isZodType(zodSchema)) {
196
37
  return zodSchema;
197
38
  }
198
- 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" });
199
44
  }
45
+
46
+ // src/utils/process-client-tools.ts
200
47
  function processClientTools(clientTools) {
201
48
  if (!clientTools) {
202
49
  return void 0;
@@ -225,6 +72,60 @@ function processClientTools(clientTools) {
225
72
  );
226
73
  }
227
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.info("\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
+
228
129
  // src/resources/base.ts
229
130
  var BaseResource = class {
230
131
  options;
@@ -239,19 +140,21 @@ var BaseResource = class {
239
140
  */
240
141
  async request(path, options = {}) {
241
142
  let lastError = null;
242
- const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
143
+ const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
243
144
  let delay = backoffMs;
244
145
  for (let attempt = 0; attempt <= retries; attempt++) {
245
146
  try {
246
147
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
247
148
  ...options,
248
149
  headers: {
249
- ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
150
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
250
151
  ...headers,
251
152
  ...options.headers
252
153
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
253
154
  // 'x-mastra-client-type': 'js',
254
155
  },
156
+ signal: this.options.abortSignal,
157
+ credentials: options.credentials ?? credentials,
255
158
  body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
256
159
  });
257
160
  if (!response.ok) {
@@ -284,14 +187,62 @@ var BaseResource = class {
284
187
  throw lastError || new Error("Request failed");
285
188
  }
286
189
  };
287
- function parseClientRuntimeContext(runtimeContext) {
288
- if (runtimeContext) {
289
- if (runtimeContext instanceof RuntimeContext) {
290
- 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
+ suspend: async () => {
218
+ }
219
+ },
220
+ {
221
+ messages: response.messages,
222
+ toolCallId: toolCall?.toolCallId
223
+ }
224
+ );
225
+ const updatedMessages = [
226
+ ...response.response.messages || [],
227
+ {
228
+ role: "tool",
229
+ content: [
230
+ {
231
+ type: "tool-result",
232
+ toolCallId: toolCall.toolCallId,
233
+ toolName: toolCall.toolName,
234
+ result
235
+ }
236
+ ]
237
+ }
238
+ ];
239
+ return respondFn({
240
+ ...params,
241
+ messages: updatedMessages
242
+ });
243
+ }
291
244
  }
292
- return runtimeContext;
293
245
  }
294
- return void 0;
295
246
  }
296
247
  var AgentVoice = class extends BaseResource {
297
248
  constructor(options, agentId) {
@@ -334,17 +285,21 @@ var AgentVoice = class extends BaseResource {
334
285
  }
335
286
  /**
336
287
  * Get available speakers for the agent's voice provider
288
+ * @param runtimeContext - Optional runtime context to pass as query parameter
289
+ * @param runtimeContext - Optional runtime context to pass as query parameter
337
290
  * @returns Promise containing list of available speakers
338
291
  */
339
- getSpeakers() {
340
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
292
+ getSpeakers(runtimeContext) {
293
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
341
294
  }
342
295
  /**
343
296
  * Get the listener configuration for the agent's voice provider
297
+ * @param runtimeContext - Optional runtime context to pass as query parameter
298
+ * @param runtimeContext - Optional runtime context to pass as query parameter
344
299
  * @returns Promise containing a check if the agent has listening capabilities
345
300
  */
346
- getListener() {
347
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
301
+ getListener(runtimeContext) {
302
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
348
303
  }
349
304
  };
350
305
  var Agent = class extends BaseResource {
@@ -356,12 +311,13 @@ var Agent = class extends BaseResource {
356
311
  voice;
357
312
  /**
358
313
  * Retrieves details about the agent
314
+ * @param runtimeContext - Optional runtime context to pass as query parameter
359
315
  * @returns Promise containing agent details including model and instructions
360
316
  */
361
- details() {
362
- return this.request(`/api/agents/${this.agentId}`);
317
+ details(runtimeContext) {
318
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
363
319
  }
364
- async generate(params) {
320
+ async generateLegacy(params) {
365
321
  const processedParams = {
366
322
  ...params,
367
323
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -370,26 +326,38 @@ var Agent = class extends BaseResource {
370
326
  clientTools: processClientTools(params.clientTools)
371
327
  };
372
328
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
373
- const response = await this.request(`/api/agents/${this.agentId}/generate`, {
374
- method: "POST",
375
- body: processedParams
376
- });
329
+ const response = await this.request(
330
+ `/api/agents/${this.agentId}/generate-legacy`,
331
+ {
332
+ method: "POST",
333
+ body: processedParams
334
+ }
335
+ );
377
336
  if (response.finishReason === "tool-calls") {
378
- for (const toolCall of response.toolCalls) {
337
+ const toolCalls = response.toolCalls;
338
+ if (!toolCalls || !Array.isArray(toolCalls)) {
339
+ return response;
340
+ }
341
+ for (const toolCall of toolCalls) {
379
342
  const clientTool = params.clientTools?.[toolCall.toolName];
380
343
  if (clientTool && clientTool.execute) {
381
344
  const result = await clientTool.execute(
382
- { context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
345
+ {
346
+ context: toolCall?.args,
347
+ runId,
348
+ resourceId,
349
+ threadId,
350
+ runtimeContext,
351
+ tracingContext: { currentSpan: void 0 },
352
+ suspend: async () => {
353
+ }
354
+ },
383
355
  {
384
356
  messages: response.messages,
385
357
  toolCallId: toolCall?.toolCallId
386
358
  }
387
359
  );
388
360
  const updatedMessages = [
389
- {
390
- role: "user",
391
- content: params.messages
392
- },
393
361
  ...response.response.messages,
394
362
  {
395
363
  role: "tool",
@@ -412,6 +380,47 @@ var Agent = class extends BaseResource {
412
380
  }
413
381
  return response;
414
382
  }
383
+ async generate(messagesOrParams, options) {
384
+ let params;
385
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
386
+ params = messagesOrParams;
387
+ } else {
388
+ params = {
389
+ messages: messagesOrParams,
390
+ ...options
391
+ };
392
+ }
393
+ const processedParams = {
394
+ ...params,
395
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
396
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
397
+ clientTools: processClientTools(params.clientTools),
398
+ structuredOutput: params.structuredOutput ? {
399
+ ...params.structuredOutput,
400
+ schema: zodToJsonSchema(params.structuredOutput.schema)
401
+ } : void 0
402
+ };
403
+ const { runId, resourceId, threadId, runtimeContext } = processedParams;
404
+ const response = await this.request(
405
+ `/api/agents/${this.agentId}/generate`,
406
+ {
407
+ method: "POST",
408
+ body: processedParams
409
+ }
410
+ );
411
+ if (response.finishReason === "tool-calls") {
412
+ return executeToolCallAndRespond({
413
+ response,
414
+ params,
415
+ runId,
416
+ resourceId,
417
+ threadId,
418
+ runtimeContext,
419
+ respondFn: this.generate.bind(this)
420
+ });
421
+ }
422
+ return response;
423
+ }
415
424
  async processChatResponse({
416
425
  stream,
417
426
  update,
@@ -426,7 +435,7 @@ var Agent = class extends BaseResource {
426
435
  return Math.max(max, toolInvocation.step ?? 0);
427
436
  }, 0) ?? 0) : 0;
428
437
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
429
- id: crypto.randomUUID(),
438
+ id: v4(),
430
439
  createdAt: getCurrentDate(),
431
440
  role: "assistant",
432
441
  content: "",
@@ -471,7 +480,7 @@ var Agent = class extends BaseResource {
471
480
  // changes. This is why we need to add a revision id to ensure that the message
472
481
  // is updated with SWR (without it, the changes get stuck in SWR and are not
473
482
  // forwarded to rendering):
474
- revisionId: crypto.randomUUID()
483
+ revisionId: v4()
475
484
  };
476
485
  update({
477
486
  message: copiedMessage,
@@ -679,7 +688,7 @@ var Agent = class extends BaseResource {
679
688
  * @param params - Stream parameters including prompt
680
689
  * @returns Promise containing the enhanced Response object with processDataStream method
681
690
  */
682
- async stream(params) {
691
+ async streamLegacy(params) {
683
692
  const processedParams = {
684
693
  ...params,
685
694
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -688,7 +697,7 @@ var Agent = class extends BaseResource {
688
697
  clientTools: processClientTools(params.clientTools)
689
698
  };
690
699
  const { readable, writable } = new TransformStream();
691
- const response = await this.processStreamResponse(processedParams, writable);
700
+ const response = await this.processStreamResponseLegacy(processedParams, writable);
692
701
  const streamResponse = new Response(readable, {
693
702
  status: response.status,
694
703
  statusText: response.statusText,
@@ -702,9 +711,267 @@ var Agent = class extends BaseResource {
702
711
  };
703
712
  return streamResponse;
704
713
  }
705
- /**
706
- * Processes the stream response and handles tool calls
707
- */
714
+ async processChatResponse_vNext({
715
+ stream,
716
+ update,
717
+ onToolCall,
718
+ onFinish,
719
+ getCurrentDate = () => /* @__PURE__ */ new Date(),
720
+ lastMessage
721
+ }) {
722
+ const replaceLastMessage = lastMessage?.role === "assistant";
723
+ let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
724
+ (lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
725
+ return Math.max(max, toolInvocation.step ?? 0);
726
+ }, 0) ?? 0) : 0;
727
+ const message = replaceLastMessage ? structuredClone(lastMessage) : {
728
+ id: v4(),
729
+ createdAt: getCurrentDate(),
730
+ role: "assistant",
731
+ content: "",
732
+ parts: []
733
+ };
734
+ let currentTextPart = void 0;
735
+ let currentReasoningPart = void 0;
736
+ let currentReasoningTextDetail = void 0;
737
+ function updateToolInvocationPart(toolCallId, invocation) {
738
+ const part = message.parts.find(
739
+ (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
740
+ );
741
+ if (part != null) {
742
+ part.toolInvocation = invocation;
743
+ } else {
744
+ message.parts.push({
745
+ type: "tool-invocation",
746
+ toolInvocation: invocation
747
+ });
748
+ }
749
+ }
750
+ const data = [];
751
+ let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
752
+ const partialToolCalls = {};
753
+ let usage = {
754
+ completionTokens: NaN,
755
+ promptTokens: NaN,
756
+ totalTokens: NaN
757
+ };
758
+ let finishReason = "unknown";
759
+ function execUpdate() {
760
+ const copiedData = [...data];
761
+ if (messageAnnotations?.length) {
762
+ message.annotations = messageAnnotations;
763
+ }
764
+ const copiedMessage = {
765
+ // deep copy the message to ensure that deep changes (msg attachments) are updated
766
+ // with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
767
+ ...structuredClone(message),
768
+ // add a revision id to ensure that the message is updated with SWR. SWR uses a
769
+ // hashing approach by default to detect changes, but it only works for shallow
770
+ // changes. This is why we need to add a revision id to ensure that the message
771
+ // is updated with SWR (without it, the changes get stuck in SWR and are not
772
+ // forwarded to rendering):
773
+ revisionId: v4()
774
+ };
775
+ update({
776
+ message: copiedMessage,
777
+ data: copiedData,
778
+ replaceLastMessage
779
+ });
780
+ }
781
+ await processMastraStream({
782
+ stream,
783
+ // TODO: casting as any here because the stream types were all typed as any before in core.
784
+ // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
785
+ onChunk: async (chunk) => {
786
+ switch (chunk.type) {
787
+ case "tripwire": {
788
+ message.parts.push({
789
+ type: "text",
790
+ text: chunk.payload.tripwireReason
791
+ });
792
+ execUpdate();
793
+ break;
794
+ }
795
+ case "step-start": {
796
+ if (!replaceLastMessage) {
797
+ message.id = chunk.payload.messageId;
798
+ }
799
+ message.parts.push({ type: "step-start" });
800
+ execUpdate();
801
+ break;
802
+ }
803
+ case "text-delta": {
804
+ if (currentTextPart == null) {
805
+ currentTextPart = {
806
+ type: "text",
807
+ text: chunk.payload.text
808
+ };
809
+ message.parts.push(currentTextPart);
810
+ } else {
811
+ currentTextPart.text += chunk.payload.text;
812
+ }
813
+ message.content += chunk.payload.text;
814
+ execUpdate();
815
+ break;
816
+ }
817
+ case "reasoning-delta": {
818
+ if (currentReasoningTextDetail == null) {
819
+ currentReasoningTextDetail = { type: "text", text: chunk.payload.text };
820
+ if (currentReasoningPart != null) {
821
+ currentReasoningPart.details.push(currentReasoningTextDetail);
822
+ }
823
+ } else {
824
+ currentReasoningTextDetail.text += chunk.payload.text;
825
+ }
826
+ if (currentReasoningPart == null) {
827
+ currentReasoningPart = {
828
+ type: "reasoning",
829
+ reasoning: chunk.payload.text,
830
+ details: [currentReasoningTextDetail]
831
+ };
832
+ message.parts.push(currentReasoningPart);
833
+ } else {
834
+ currentReasoningPart.reasoning += chunk.payload.text;
835
+ }
836
+ message.reasoning = (message.reasoning ?? "") + chunk.payload.text;
837
+ execUpdate();
838
+ break;
839
+ }
840
+ case "file": {
841
+ message.parts.push({
842
+ type: "file",
843
+ mimeType: chunk.payload.mimeType,
844
+ data: chunk.payload.data
845
+ });
846
+ execUpdate();
847
+ break;
848
+ }
849
+ case "source": {
850
+ message.parts.push({
851
+ type: "source",
852
+ source: chunk.payload.source
853
+ });
854
+ execUpdate();
855
+ break;
856
+ }
857
+ case "tool-call": {
858
+ const invocation = {
859
+ state: "call",
860
+ step,
861
+ ...chunk.payload
862
+ };
863
+ if (partialToolCalls[chunk.payload.toolCallId] != null) {
864
+ message.toolInvocations[partialToolCalls[chunk.payload.toolCallId].index] = invocation;
865
+ } else {
866
+ if (message.toolInvocations == null) {
867
+ message.toolInvocations = [];
868
+ }
869
+ message.toolInvocations.push(invocation);
870
+ }
871
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
872
+ execUpdate();
873
+ if (onToolCall) {
874
+ const result = await onToolCall({ toolCall: chunk.payload });
875
+ if (result != null) {
876
+ const invocation2 = {
877
+ state: "result",
878
+ step,
879
+ ...chunk.payload,
880
+ result
881
+ };
882
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
883
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation2);
884
+ execUpdate();
885
+ }
886
+ }
887
+ }
888
+ case "tool-call-input-streaming-start": {
889
+ if (message.toolInvocations == null) {
890
+ message.toolInvocations = [];
891
+ }
892
+ partialToolCalls[chunk.payload.toolCallId] = {
893
+ text: "",
894
+ step,
895
+ toolName: chunk.payload.toolName,
896
+ index: message.toolInvocations.length
897
+ };
898
+ const invocation = {
899
+ state: "partial-call",
900
+ step,
901
+ toolCallId: chunk.payload.toolCallId,
902
+ toolName: chunk.payload.toolName,
903
+ args: chunk.payload.args
904
+ };
905
+ message.toolInvocations.push(invocation);
906
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
907
+ execUpdate();
908
+ break;
909
+ }
910
+ case "tool-call-delta": {
911
+ const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
912
+ partialToolCall.text += chunk.payload.argsTextDelta;
913
+ const { value: partialArgs } = parsePartialJson(partialToolCall.text);
914
+ const invocation = {
915
+ state: "partial-call",
916
+ step: partialToolCall.step,
917
+ toolCallId: chunk.payload.toolCallId,
918
+ toolName: partialToolCall.toolName,
919
+ args: partialArgs
920
+ };
921
+ message.toolInvocations[partialToolCall.index] = invocation;
922
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
923
+ execUpdate();
924
+ break;
925
+ }
926
+ case "tool-result": {
927
+ const toolInvocations = message.toolInvocations;
928
+ if (toolInvocations == null) {
929
+ throw new Error("tool_result must be preceded by a tool_call");
930
+ }
931
+ const toolInvocationIndex = toolInvocations.findIndex(
932
+ (invocation2) => invocation2.toolCallId === chunk.payload.toolCallId
933
+ );
934
+ if (toolInvocationIndex === -1) {
935
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
936
+ }
937
+ const invocation = {
938
+ ...toolInvocations[toolInvocationIndex],
939
+ state: "result",
940
+ ...chunk.payload
941
+ };
942
+ toolInvocations[toolInvocationIndex] = invocation;
943
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation);
944
+ execUpdate();
945
+ break;
946
+ }
947
+ case "error": {
948
+ throw new Error(chunk.payload.error);
949
+ }
950
+ case "data": {
951
+ data.push(...chunk.payload.data);
952
+ execUpdate();
953
+ break;
954
+ }
955
+ case "step-finish": {
956
+ step += 1;
957
+ currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
958
+ currentReasoningPart = void 0;
959
+ currentReasoningTextDetail = void 0;
960
+ execUpdate();
961
+ break;
962
+ }
963
+ case "finish": {
964
+ finishReason = chunk.payload.stepResult.reason;
965
+ if (chunk.payload.usage != null) {
966
+ usage = chunk.payload.usage;
967
+ }
968
+ break;
969
+ }
970
+ }
971
+ }
972
+ });
973
+ onFinish?.({ message, finishReason, usage });
974
+ }
708
975
  async processStreamResponse(processedParams, writable) {
709
976
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
710
977
  method: "POST",
@@ -718,15 +985,38 @@ var Agent = class extends BaseResource {
718
985
  let toolCalls = [];
719
986
  let messages = [];
720
987
  const [streamForWritable, streamForProcessing] = response.body.tee();
721
- streamForWritable.pipeTo(writable, {
722
- preventClose: true
723
- }).catch((error) => {
988
+ streamForWritable.pipeTo(
989
+ new WritableStream({
990
+ async write(chunk) {
991
+ let writer;
992
+ try {
993
+ writer = writable.getWriter();
994
+ const text = new TextDecoder().decode(chunk);
995
+ const lines = text.split("\n\n");
996
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
997
+ await writer.write(new TextEncoder().encode(readableLines));
998
+ } catch {
999
+ await writer?.write(chunk);
1000
+ } finally {
1001
+ writer?.releaseLock();
1002
+ }
1003
+ }
1004
+ }),
1005
+ {
1006
+ preventClose: true
1007
+ }
1008
+ ).catch((error) => {
724
1009
  console.error("Error piping to writable stream:", error);
725
1010
  });
726
- this.processChatResponse({
1011
+ this.processChatResponse_vNext({
727
1012
  stream: streamForProcessing,
728
1013
  update: ({ message }) => {
729
- messages.push(message);
1014
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
1015
+ if (existingIndex !== -1) {
1016
+ messages[existingIndex] = message;
1017
+ } else {
1018
+ messages.push(message);
1019
+ }
730
1020
  },
731
1021
  onFinish: async ({ finishReason, message }) => {
732
1022
  if (finishReason === "tool-calls") {
@@ -734,23 +1024,30 @@ var Agent = class extends BaseResource {
734
1024
  if (toolCall) {
735
1025
  toolCalls.push(toolCall);
736
1026
  }
1027
+ let shouldExecuteClientTool = false;
737
1028
  for (const toolCall2 of toolCalls) {
738
1029
  const clientTool = processedParams.clientTools?.[toolCall2.toolName];
739
1030
  if (clientTool && clientTool.execute) {
1031
+ shouldExecuteClientTool = true;
740
1032
  const result = await clientTool.execute(
741
1033
  {
742
1034
  context: toolCall2?.args,
743
1035
  runId: processedParams.runId,
744
1036
  resourceId: processedParams.resourceId,
745
1037
  threadId: processedParams.threadId,
746
- runtimeContext: processedParams.runtimeContext
1038
+ runtimeContext: processedParams.runtimeContext,
1039
+ // TODO: Pass proper tracing context when client-js supports tracing
1040
+ tracingContext: { currentSpan: void 0 },
1041
+ suspend: async () => {
1042
+ }
747
1043
  },
748
1044
  {
749
1045
  messages: response.messages,
750
1046
  toolCallId: toolCall2?.toolCallId
751
1047
  }
752
1048
  );
753
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1049
+ const lastMessageRaw = messages[messages.length - 1];
1050
+ const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
754
1051
  const toolInvocationPart = lastMessage?.parts?.find(
755
1052
  (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
756
1053
  );
@@ -768,7 +1065,175 @@ var Agent = class extends BaseResource {
768
1065
  toolInvocation.state = "result";
769
1066
  toolInvocation.result = result;
770
1067
  }
771
- const writer = writable.getWriter();
1068
+ const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1069
+ this.processStreamResponse(
1070
+ {
1071
+ ...processedParams,
1072
+ messages: updatedMessages
1073
+ },
1074
+ writable
1075
+ ).catch((error) => {
1076
+ console.error("Error processing stream response:", error);
1077
+ });
1078
+ }
1079
+ }
1080
+ if (!shouldExecuteClientTool) {
1081
+ setTimeout(() => {
1082
+ writable.close();
1083
+ }, 0);
1084
+ }
1085
+ } else {
1086
+ setTimeout(() => {
1087
+ writable.close();
1088
+ }, 0);
1089
+ }
1090
+ },
1091
+ lastMessage: void 0
1092
+ }).catch((error) => {
1093
+ console.error("Error processing stream response:", error);
1094
+ });
1095
+ } catch (error) {
1096
+ console.error("Error processing stream response:", error);
1097
+ }
1098
+ return response;
1099
+ }
1100
+ async network(params) {
1101
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1102
+ method: "POST",
1103
+ body: params,
1104
+ stream: true
1105
+ });
1106
+ if (!response.body) {
1107
+ throw new Error("No response body");
1108
+ }
1109
+ const streamResponse = new Response(response.body, {
1110
+ status: response.status,
1111
+ statusText: response.statusText,
1112
+ headers: response.headers
1113
+ });
1114
+ streamResponse.processDataStream = async ({
1115
+ onChunk
1116
+ }) => {
1117
+ await processMastraNetworkStream({
1118
+ stream: streamResponse.body,
1119
+ onChunk
1120
+ });
1121
+ };
1122
+ return streamResponse;
1123
+ }
1124
+ async stream(messagesOrParams, options) {
1125
+ let params;
1126
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1127
+ params = messagesOrParams;
1128
+ } else {
1129
+ params = {
1130
+ messages: messagesOrParams,
1131
+ ...options
1132
+ };
1133
+ }
1134
+ const processedParams = {
1135
+ ...params,
1136
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
1137
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
1138
+ clientTools: processClientTools(params.clientTools),
1139
+ structuredOutput: params.structuredOutput ? {
1140
+ ...params.structuredOutput,
1141
+ schema: zodToJsonSchema(params.structuredOutput.schema)
1142
+ } : void 0
1143
+ };
1144
+ const { readable, writable } = new TransformStream();
1145
+ const response = await this.processStreamResponse(processedParams, writable);
1146
+ const streamResponse = new Response(readable, {
1147
+ status: response.status,
1148
+ statusText: response.statusText,
1149
+ headers: response.headers
1150
+ });
1151
+ streamResponse.processDataStream = async ({
1152
+ onChunk
1153
+ }) => {
1154
+ await processMastraStream({
1155
+ stream: streamResponse.body,
1156
+ onChunk
1157
+ });
1158
+ };
1159
+ return streamResponse;
1160
+ }
1161
+ /**
1162
+ * Processes the stream response and handles tool calls
1163
+ */
1164
+ async processStreamResponseLegacy(processedParams, writable) {
1165
+ const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1166
+ method: "POST",
1167
+ body: processedParams,
1168
+ stream: true
1169
+ });
1170
+ if (!response.body) {
1171
+ throw new Error("No response body");
1172
+ }
1173
+ try {
1174
+ let toolCalls = [];
1175
+ let messages = [];
1176
+ const [streamForWritable, streamForProcessing] = response.body.tee();
1177
+ streamForWritable.pipeTo(writable, {
1178
+ preventClose: true
1179
+ }).catch((error) => {
1180
+ console.error("Error piping to writable stream:", error);
1181
+ });
1182
+ this.processChatResponse({
1183
+ stream: streamForProcessing,
1184
+ update: ({ message }) => {
1185
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
1186
+ if (existingIndex !== -1) {
1187
+ messages[existingIndex] = message;
1188
+ } else {
1189
+ messages.push(message);
1190
+ }
1191
+ },
1192
+ onFinish: async ({ finishReason, message }) => {
1193
+ if (finishReason === "tool-calls") {
1194
+ const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
1195
+ if (toolCall) {
1196
+ toolCalls.push(toolCall);
1197
+ }
1198
+ for (const toolCall2 of toolCalls) {
1199
+ const clientTool = processedParams.clientTools?.[toolCall2.toolName];
1200
+ if (clientTool && clientTool.execute) {
1201
+ const result = await clientTool.execute(
1202
+ {
1203
+ context: toolCall2?.args,
1204
+ runId: processedParams.runId,
1205
+ resourceId: processedParams.resourceId,
1206
+ threadId: processedParams.threadId,
1207
+ runtimeContext: processedParams.runtimeContext,
1208
+ // TODO: Pass proper tracing context when client-js supports tracing
1209
+ tracingContext: { currentSpan: void 0 },
1210
+ suspend: async () => {
1211
+ }
1212
+ },
1213
+ {
1214
+ messages: response.messages,
1215
+ toolCallId: toolCall2?.toolCallId
1216
+ }
1217
+ );
1218
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
1219
+ const toolInvocationPart = lastMessage?.parts?.find(
1220
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
1221
+ );
1222
+ if (toolInvocationPart) {
1223
+ toolInvocationPart.toolInvocation = {
1224
+ ...toolInvocationPart.toolInvocation,
1225
+ state: "result",
1226
+ result
1227
+ };
1228
+ }
1229
+ const toolInvocation = lastMessage?.toolInvocations?.find(
1230
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
1231
+ );
1232
+ if (toolInvocation) {
1233
+ toolInvocation.state = "result";
1234
+ toolInvocation.result = result;
1235
+ }
1236
+ const writer = writable.getWriter();
772
1237
  try {
773
1238
  await writer.write(
774
1239
  new TextEncoder().encode(
@@ -781,15 +1246,15 @@ var Agent = class extends BaseResource {
781
1246
  } finally {
782
1247
  writer.releaseLock();
783
1248
  }
784
- const originalMessages = processedParams.messages;
785
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
786
- this.processStreamResponse(
1249
+ this.processStreamResponseLegacy(
787
1250
  {
788
1251
  ...processedParams,
789
- messages: [...messageArray, ...messages, lastMessage]
1252
+ messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
790
1253
  },
791
1254
  writable
792
- );
1255
+ ).catch((error) => {
1256
+ console.error("Error processing stream response:", error);
1257
+ });
793
1258
  }
794
1259
  }
795
1260
  } else {
@@ -799,6 +1264,8 @@ var Agent = class extends BaseResource {
799
1264
  }
800
1265
  },
801
1266
  lastMessage: void 0
1267
+ }).catch((error) => {
1268
+ console.error("Error processing stream response:", error);
802
1269
  });
803
1270
  } catch (error) {
804
1271
  console.error("Error processing stream response:", error);
@@ -808,10 +1275,11 @@ var Agent = class extends BaseResource {
808
1275
  /**
809
1276
  * Gets details about a specific tool available to the agent
810
1277
  * @param toolId - ID of the tool to retrieve
1278
+ * @param runtimeContext - Optional runtime context to pass as query parameter
811
1279
  * @returns Promise containing tool details
812
1280
  */
813
- getTool(toolId) {
814
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1281
+ getTool(toolId, runtimeContext) {
1282
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
815
1283
  }
816
1284
  /**
817
1285
  * Executes a tool for the agent
@@ -822,7 +1290,7 @@ var Agent = class extends BaseResource {
822
1290
  executeTool(toolId, params) {
823
1291
  const body = {
824
1292
  data: params.data,
825
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1293
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
826
1294
  };
827
1295
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
828
1296
  method: "POST",
@@ -831,73 +1299,58 @@ var Agent = class extends BaseResource {
831
1299
  }
832
1300
  /**
833
1301
  * Retrieves evaluation results for the agent
1302
+ * @param runtimeContext - Optional runtime context to pass as query parameter
834
1303
  * @returns Promise containing agent evaluations
835
1304
  */
836
- evals() {
837
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1305
+ evals(runtimeContext) {
1306
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
838
1307
  }
839
1308
  /**
840
1309
  * Retrieves live evaluation results for the agent
1310
+ * @param runtimeContext - Optional runtime context to pass as query parameter
841
1311
  * @returns Promise containing live agent evaluations
842
1312
  */
843
- liveEvals() {
844
- return this.request(`/api/agents/${this.agentId}/evals/live`);
845
- }
846
- };
847
- var Network = class extends BaseResource {
848
- constructor(options, networkId) {
849
- super(options);
850
- this.networkId = networkId;
1313
+ liveEvals(runtimeContext) {
1314
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
851
1315
  }
852
1316
  /**
853
- * Retrieves details about the network
854
- * @returns Promise containing network details
1317
+ * Updates the model for the agent
1318
+ * @param params - Parameters for updating the model
1319
+ * @returns Promise containing the updated model
855
1320
  */
856
- details() {
857
- return this.request(`/api/networks/${this.networkId}`);
1321
+ updateModel(params) {
1322
+ return this.request(`/api/agents/${this.agentId}/model`, {
1323
+ method: "POST",
1324
+ body: params
1325
+ });
858
1326
  }
859
1327
  /**
860
- * Generates a response from the agent
861
- * @param params - Generation parameters including prompt
862
- * @returns Promise containing the generated response
1328
+ * Updates the model for the agent in the model list
1329
+ * @param params - Parameters for updating the model
1330
+ * @returns Promise containing the updated model
863
1331
  */
864
- generate(params) {
865
- const processedParams = {
866
- ...params,
867
- output: zodToJsonSchema(params.output),
868
- experimental_output: zodToJsonSchema(params.experimental_output)
869
- };
870
- return this.request(`/api/networks/${this.networkId}/generate`, {
1332
+ updateModelInModelList({ modelConfigId, ...params }) {
1333
+ return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
871
1334
  method: "POST",
872
- body: processedParams
1335
+ body: params
873
1336
  });
874
1337
  }
875
1338
  /**
876
- * Streams a response from the agent
877
- * @param params - Stream parameters including prompt
878
- * @returns Promise containing the enhanced Response object with processDataStream method
1339
+ * Reorders the models for the agent
1340
+ * @param params - Parameters for reordering the model list
1341
+ * @returns Promise containing the updated model list
879
1342
  */
880
- async stream(params) {
881
- const processedParams = {
882
- ...params,
883
- output: zodToJsonSchema(params.output),
884
- experimental_output: zodToJsonSchema(params.experimental_output)
885
- };
886
- const response = await this.request(`/api/networks/${this.networkId}/stream`, {
1343
+ reorderModelList(params) {
1344
+ return this.request(`/api/agents/${this.agentId}/models/reorder`, {
887
1345
  method: "POST",
888
- body: processedParams,
889
- stream: true
1346
+ body: params
890
1347
  });
891
- if (!response.body) {
892
- throw new Error("No response body");
893
- }
894
- response.processDataStream = async (options = {}) => {
895
- await processDataStream({
896
- stream: response.body,
897
- ...options
898
- });
899
- };
900
- return response;
1348
+ }
1349
+ async generateVNext(_messagesOrParams, _options) {
1350
+ throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1351
+ }
1352
+ async streamVNext(_messagesOrParams, _options) {
1353
+ throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
901
1354
  }
902
1355
  };
903
1356
 
@@ -947,6 +1400,36 @@ var MemoryThread = class extends BaseResource {
947
1400
  });
948
1401
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
949
1402
  }
1403
+ /**
1404
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
1405
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
1406
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1407
+ */
1408
+ getMessagesPaginated({
1409
+ selectBy,
1410
+ ...rest
1411
+ }) {
1412
+ const query = new URLSearchParams({
1413
+ ...rest,
1414
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
1415
+ });
1416
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
1417
+ }
1418
+ /**
1419
+ * Deletes one or more messages from the thread
1420
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1421
+ * message object with id property, or array of message objects
1422
+ * @returns Promise containing deletion result
1423
+ */
1424
+ deleteMessages(messageIds) {
1425
+ const query = new URLSearchParams({
1426
+ agentId: this.agentId
1427
+ });
1428
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1429
+ method: "POST",
1430
+ body: { messageIds }
1431
+ });
1432
+ }
950
1433
  };
951
1434
 
952
1435
  // src/resources/vector.ts
@@ -958,10 +1441,13 @@ var Vector = class extends BaseResource {
958
1441
  /**
959
1442
  * Retrieves details about a specific vector index
960
1443
  * @param indexName - Name of the index to get details for
1444
+ * @param runtimeContext - Optional runtime context to pass as query parameter
961
1445
  * @returns Promise containing vector index details
962
1446
  */
963
- details(indexName) {
964
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1447
+ details(indexName, runtimeContext) {
1448
+ return this.request(
1449
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1450
+ );
965
1451
  }
966
1452
  /**
967
1453
  * Deletes a vector index
@@ -975,10 +1461,11 @@ var Vector = class extends BaseResource {
975
1461
  }
976
1462
  /**
977
1463
  * Retrieves a list of all available indexes
1464
+ * @param runtimeContext - Optional runtime context to pass as query parameter
978
1465
  * @returns Promise containing array of index names
979
1466
  */
980
- getIndexes() {
981
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1467
+ getIndexes(runtimeContext) {
1468
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
982
1469
  }
983
1470
  /**
984
1471
  * Creates a new vector index
@@ -1015,199 +1502,19 @@ var Vector = class extends BaseResource {
1015
1502
  }
1016
1503
  };
1017
1504
 
1018
- // src/resources/legacy-workflow.ts
1019
- var RECORD_SEPARATOR = "";
1020
- var LegacyWorkflow = class extends BaseResource {
1021
- constructor(options, workflowId) {
1022
- super(options);
1023
- this.workflowId = workflowId;
1024
- }
1025
- /**
1026
- * Retrieves details about the legacy workflow
1027
- * @returns Promise containing legacy workflow details including steps and graphs
1028
- */
1029
- details() {
1030
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1031
- }
1032
- /**
1033
- * Retrieves all runs for a legacy workflow
1034
- * @param params - Parameters for filtering runs
1035
- * @returns Promise containing legacy workflow runs array
1036
- */
1037
- runs(params) {
1038
- const searchParams = new URLSearchParams();
1039
- if (params?.fromDate) {
1040
- searchParams.set("fromDate", params.fromDate.toISOString());
1041
- }
1042
- if (params?.toDate) {
1043
- searchParams.set("toDate", params.toDate.toISOString());
1044
- }
1045
- if (params?.limit) {
1046
- searchParams.set("limit", String(params.limit));
1047
- }
1048
- if (params?.offset) {
1049
- searchParams.set("offset", String(params.offset));
1050
- }
1051
- if (params?.resourceId) {
1052
- searchParams.set("resourceId", params.resourceId);
1053
- }
1054
- if (searchParams.size) {
1055
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1056
- } else {
1057
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
1058
- }
1059
- }
1060
- /**
1061
- * Creates a new legacy workflow run
1062
- * @returns Promise containing the generated run ID
1063
- */
1064
- createRun(params) {
1065
- const searchParams = new URLSearchParams();
1066
- if (!!params?.runId) {
1067
- searchParams.set("runId", params.runId);
1068
- }
1069
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
1070
- method: "POST"
1071
- });
1072
- }
1073
- /**
1074
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
1075
- * @param params - Object containing the runId and triggerData
1076
- * @returns Promise containing success message
1077
- */
1078
- start(params) {
1079
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
1080
- method: "POST",
1081
- body: params?.triggerData
1082
- });
1083
- }
1084
- /**
1085
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
1086
- * @param stepId - ID of the step to resume
1087
- * @param runId - ID of the legacy workflow run
1088
- * @param context - Context to resume the legacy workflow with
1089
- * @returns Promise containing the legacy workflow resume results
1090
- */
1091
- resume({
1092
- stepId,
1093
- runId,
1094
- context
1095
- }) {
1096
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
1097
- method: "POST",
1098
- body: {
1099
- stepId,
1100
- context
1101
- }
1102
- });
1103
- }
1104
- /**
1105
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1106
- * @param params - Object containing the optional runId and triggerData
1107
- * @returns Promise containing the workflow execution results
1108
- */
1109
- startAsync(params) {
1110
- const searchParams = new URLSearchParams();
1111
- if (!!params?.runId) {
1112
- searchParams.set("runId", params.runId);
1113
- }
1114
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
1115
- method: "POST",
1116
- body: params?.triggerData
1117
- });
1118
- }
1119
- /**
1120
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
1121
- * @param params - Object containing the runId, stepId, and context
1122
- * @returns Promise containing the workflow resume results
1123
- */
1124
- resumeAsync(params) {
1125
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
1126
- method: "POST",
1127
- body: {
1128
- stepId: params.stepId,
1129
- context: params.context
1130
- }
1131
- });
1132
- }
1133
- /**
1134
- * Creates an async generator that processes a readable stream and yields records
1135
- * separated by the Record Separator character (\x1E)
1136
- *
1137
- * @param stream - The readable stream to process
1138
- * @returns An async generator that yields parsed records
1139
- */
1140
- async *streamProcessor(stream) {
1141
- const reader = stream.getReader();
1142
- let doneReading = false;
1143
- let buffer = "";
1144
- try {
1145
- while (!doneReading) {
1146
- const { done, value } = await reader.read();
1147
- doneReading = done;
1148
- if (done && !value) continue;
1149
- try {
1150
- const decoded = value ? new TextDecoder().decode(value) : "";
1151
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1152
- buffer = chunks.pop() || "";
1153
- for (const chunk of chunks) {
1154
- if (chunk) {
1155
- if (typeof chunk === "string") {
1156
- try {
1157
- const parsedChunk = JSON.parse(chunk);
1158
- yield parsedChunk;
1159
- } catch {
1160
- }
1161
- }
1162
- }
1163
- }
1164
- } catch {
1165
- }
1166
- }
1167
- if (buffer) {
1168
- try {
1169
- yield JSON.parse(buffer);
1170
- } catch {
1171
- }
1172
- }
1173
- } finally {
1174
- reader.cancel().catch(() => {
1175
- });
1176
- }
1177
- }
1178
- /**
1179
- * Watches legacy workflow transitions in real-time
1180
- * @param runId - Optional run ID to filter the watch stream
1181
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
1182
- */
1183
- async watch({ runId }, onRecord) {
1184
- const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
1185
- stream: true
1186
- });
1187
- if (!response.ok) {
1188
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
1189
- }
1190
- if (!response.body) {
1191
- throw new Error("Response body is null");
1192
- }
1193
- for await (const record of this.streamProcessor(response.body)) {
1194
- onRecord(record);
1195
- }
1196
- }
1197
- };
1198
-
1199
1505
  // src/resources/tool.ts
1200
- var Tool2 = class extends BaseResource {
1506
+ var Tool = class extends BaseResource {
1201
1507
  constructor(options, toolId) {
1202
1508
  super(options);
1203
1509
  this.toolId = toolId;
1204
1510
  }
1205
1511
  /**
1206
1512
  * Retrieves details about the tool
1513
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1207
1514
  * @returns Promise containing tool details including description and schemas
1208
1515
  */
1209
- details() {
1210
- return this.request(`/api/tools/${this.toolId}`);
1516
+ details(runtimeContext) {
1517
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1211
1518
  }
1212
1519
  /**
1213
1520
  * Executes the tool with the provided parameters
@@ -1231,7 +1538,7 @@ var Tool2 = class extends BaseResource {
1231
1538
  };
1232
1539
 
1233
1540
  // src/resources/workflow.ts
1234
- var RECORD_SEPARATOR2 = "";
1541
+ var RECORD_SEPARATOR = "";
1235
1542
  var Workflow = class extends BaseResource {
1236
1543
  constructor(options, workflowId) {
1237
1544
  super(options);
@@ -1255,7 +1562,7 @@ var Workflow = class extends BaseResource {
1255
1562
  if (done && !value) continue;
1256
1563
  try {
1257
1564
  const decoded = value ? new TextDecoder().decode(value) : "";
1258
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
1565
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
1259
1566
  buffer = chunks.pop() || "";
1260
1567
  for (const chunk of chunks) {
1261
1568
  if (chunk) {
@@ -1284,17 +1591,20 @@ var Workflow = class extends BaseResource {
1284
1591
  }
1285
1592
  /**
1286
1593
  * Retrieves details about the workflow
1594
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1287
1595
  * @returns Promise containing workflow details including steps and graphs
1288
1596
  */
1289
- details() {
1290
- return this.request(`/api/workflows/${this.workflowId}`);
1597
+ details(runtimeContext) {
1598
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1291
1599
  }
1292
1600
  /**
1293
1601
  * Retrieves all runs for a workflow
1294
1602
  * @param params - Parameters for filtering runs
1603
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1295
1604
  * @returns Promise containing workflow runs array
1296
1605
  */
1297
- runs(params) {
1606
+ runs(params, runtimeContext) {
1607
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1298
1608
  const searchParams = new URLSearchParams();
1299
1609
  if (params?.fromDate) {
1300
1610
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1311,6 +1621,9 @@ var Workflow = class extends BaseResource {
1311
1621
  if (params?.resourceId) {
1312
1622
  searchParams.set("resourceId", params.resourceId);
1313
1623
  }
1624
+ if (runtimeContextParam) {
1625
+ searchParams.set("runtimeContext", runtimeContextParam);
1626
+ }
1314
1627
  if (searchParams.size) {
1315
1628
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1316
1629
  } else {
@@ -1320,18 +1633,22 @@ var Workflow = class extends BaseResource {
1320
1633
  /**
1321
1634
  * Retrieves a specific workflow run by its ID
1322
1635
  * @param runId - The ID of the workflow run to retrieve
1636
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1323
1637
  * @returns Promise containing the workflow run details
1324
1638
  */
1325
- runById(runId) {
1326
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1639
+ runById(runId, runtimeContext) {
1640
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1327
1641
  }
1328
1642
  /**
1329
1643
  * Retrieves the execution result for a specific workflow run by its ID
1330
1644
  * @param runId - The ID of the workflow run to retrieve the execution result for
1645
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1331
1646
  * @returns Promise containing the workflow run execution result
1332
1647
  */
1333
- runExecutionResult(runId) {
1334
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1648
+ runExecutionResult(runId, runtimeContext) {
1649
+ return this.request(
1650
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1651
+ );
1335
1652
  }
1336
1653
  /**
1337
1654
  * Cancels a specific workflow run by its ID
@@ -1354,19 +1671,83 @@ var Workflow = class extends BaseResource {
1354
1671
  body: { event: params.event, data: params.data }
1355
1672
  });
1356
1673
  }
1674
+ /**
1675
+ * @deprecated Use createRunAsync() instead.
1676
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
1677
+ */
1678
+ async createRun(_params) {
1679
+ throw new Error(
1680
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
1681
+ );
1682
+ }
1357
1683
  /**
1358
1684
  * Creates a new workflow run
1359
1685
  * @param params - Optional object containing the optional runId
1360
- * @returns Promise containing the runId of the created run
1686
+ * @returns Promise containing the runId of the created run with methods to control execution
1361
1687
  */
1362
- createRun(params) {
1688
+ async createRunAsync(params) {
1363
1689
  const searchParams = new URLSearchParams();
1364
1690
  if (!!params?.runId) {
1365
1691
  searchParams.set("runId", params.runId);
1366
1692
  }
1367
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1368
- method: "POST"
1369
- });
1693
+ const res = await this.request(
1694
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1695
+ {
1696
+ method: "POST"
1697
+ }
1698
+ );
1699
+ const runId = res.runId;
1700
+ return {
1701
+ runId,
1702
+ start: async (p) => {
1703
+ return this.start({
1704
+ runId,
1705
+ inputData: p.inputData,
1706
+ runtimeContext: p.runtimeContext,
1707
+ tracingOptions: p.tracingOptions
1708
+ });
1709
+ },
1710
+ startAsync: async (p) => {
1711
+ return this.startAsync({
1712
+ runId,
1713
+ inputData: p.inputData,
1714
+ runtimeContext: p.runtimeContext,
1715
+ tracingOptions: p.tracingOptions
1716
+ });
1717
+ },
1718
+ watch: async (onRecord) => {
1719
+ return this.watch({ runId }, onRecord);
1720
+ },
1721
+ stream: async (p) => {
1722
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1723
+ },
1724
+ resume: async (p) => {
1725
+ return this.resume({
1726
+ runId,
1727
+ step: p.step,
1728
+ resumeData: p.resumeData,
1729
+ runtimeContext: p.runtimeContext,
1730
+ tracingOptions: p.tracingOptions
1731
+ });
1732
+ },
1733
+ resumeAsync: async (p) => {
1734
+ return this.resumeAsync({
1735
+ runId,
1736
+ step: p.step,
1737
+ resumeData: p.resumeData,
1738
+ runtimeContext: p.runtimeContext,
1739
+ tracingOptions: p.tracingOptions
1740
+ });
1741
+ },
1742
+ resumeStreamVNext: async (p) => {
1743
+ return this.resumeStreamVNext({
1744
+ runId,
1745
+ step: p.step,
1746
+ resumeData: p.resumeData,
1747
+ runtimeContext: p.runtimeContext
1748
+ });
1749
+ }
1750
+ };
1370
1751
  }
1371
1752
  /**
1372
1753
  * Starts a workflow run synchronously without waiting for the workflow to complete
@@ -1377,7 +1758,7 @@ var Workflow = class extends BaseResource {
1377
1758
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1378
1759
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1379
1760
  method: "POST",
1380
- body: { inputData: params?.inputData, runtimeContext }
1761
+ body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1381
1762
  });
1382
1763
  }
1383
1764
  /**
@@ -1389,73 +1770,228 @@ var Workflow = class extends BaseResource {
1389
1770
  step,
1390
1771
  runId,
1391
1772
  resumeData,
1773
+ tracingOptions,
1392
1774
  ...rest
1393
1775
  }) {
1394
1776
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1395
1777
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1396
1778
  method: "POST",
1397
- stream: true,
1398
1779
  body: {
1399
1780
  step,
1400
1781
  resumeData,
1401
- runtimeContext
1782
+ runtimeContext,
1783
+ tracingOptions
1784
+ }
1785
+ });
1786
+ }
1787
+ /**
1788
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1789
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1790
+ * @returns Promise containing the workflow execution results
1791
+ */
1792
+ startAsync(params) {
1793
+ const searchParams = new URLSearchParams();
1794
+ if (!!params?.runId) {
1795
+ searchParams.set("runId", params.runId);
1796
+ }
1797
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1798
+ return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1799
+ method: "POST",
1800
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
1801
+ });
1802
+ }
1803
+ /**
1804
+ * Starts a workflow run and returns a stream
1805
+ * @param params - Object containing the optional runId, inputData and runtimeContext
1806
+ * @returns Promise containing the workflow execution results
1807
+ */
1808
+ async stream(params) {
1809
+ const searchParams = new URLSearchParams();
1810
+ if (!!params?.runId) {
1811
+ searchParams.set("runId", params.runId);
1812
+ }
1813
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1814
+ const response = await this.request(
1815
+ `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1816
+ {
1817
+ method: "POST",
1818
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1819
+ stream: true
1820
+ }
1821
+ );
1822
+ if (!response.ok) {
1823
+ throw new Error(`Failed to stream workflow: ${response.statusText}`);
1824
+ }
1825
+ if (!response.body) {
1826
+ throw new Error("Response body is null");
1827
+ }
1828
+ let failedChunk = void 0;
1829
+ const transformStream = new TransformStream({
1830
+ start() {
1831
+ },
1832
+ async transform(chunk, controller) {
1833
+ try {
1834
+ const decoded = new TextDecoder().decode(chunk);
1835
+ const chunks = decoded.split(RECORD_SEPARATOR);
1836
+ for (const chunk2 of chunks) {
1837
+ if (chunk2) {
1838
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1839
+ try {
1840
+ const parsedChunk = JSON.parse(newChunk);
1841
+ controller.enqueue(parsedChunk);
1842
+ failedChunk = void 0;
1843
+ } catch {
1844
+ failedChunk = newChunk;
1845
+ }
1846
+ }
1847
+ }
1848
+ } catch {
1849
+ }
1850
+ }
1851
+ });
1852
+ return response.body.pipeThrough(transformStream);
1853
+ }
1854
+ /**
1855
+ * Observes workflow stream for a workflow run
1856
+ * @param params - Object containing the runId
1857
+ * @returns Promise containing the workflow execution results
1858
+ */
1859
+ async observeStream(params) {
1860
+ const searchParams = new URLSearchParams();
1861
+ searchParams.set("runId", params.runId);
1862
+ const response = await this.request(
1863
+ `/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
1864
+ {
1865
+ method: "POST",
1866
+ stream: true
1867
+ }
1868
+ );
1869
+ if (!response.ok) {
1870
+ throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
1871
+ }
1872
+ if (!response.body) {
1873
+ throw new Error("Response body is null");
1874
+ }
1875
+ let failedChunk = void 0;
1876
+ const transformStream = new TransformStream({
1877
+ start() {
1878
+ },
1879
+ async transform(chunk, controller) {
1880
+ try {
1881
+ const decoded = new TextDecoder().decode(chunk);
1882
+ const chunks = decoded.split(RECORD_SEPARATOR);
1883
+ for (const chunk2 of chunks) {
1884
+ if (chunk2) {
1885
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1886
+ try {
1887
+ const parsedChunk = JSON.parse(newChunk);
1888
+ controller.enqueue(parsedChunk);
1889
+ failedChunk = void 0;
1890
+ } catch {
1891
+ failedChunk = newChunk;
1892
+ }
1893
+ }
1894
+ }
1895
+ } catch {
1896
+ }
1402
1897
  }
1403
1898
  });
1899
+ return response.body.pipeThrough(transformStream);
1404
1900
  }
1405
1901
  /**
1406
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
1902
+ * Starts a workflow run and returns a stream
1407
1903
  * @param params - Object containing the optional runId, inputData and runtimeContext
1408
1904
  * @returns Promise containing the workflow execution results
1409
1905
  */
1410
- startAsync(params) {
1906
+ async streamVNext(params) {
1411
1907
  const searchParams = new URLSearchParams();
1412
1908
  if (!!params?.runId) {
1413
1909
  searchParams.set("runId", params.runId);
1414
1910
  }
1415
1911
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1416
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1417
- method: "POST",
1418
- body: { inputData: params.inputData, runtimeContext }
1912
+ const response = await this.request(
1913
+ `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1914
+ {
1915
+ method: "POST",
1916
+ body: {
1917
+ inputData: params.inputData,
1918
+ runtimeContext,
1919
+ closeOnSuspend: params.closeOnSuspend,
1920
+ tracingOptions: params.tracingOptions
1921
+ },
1922
+ stream: true
1923
+ }
1924
+ );
1925
+ if (!response.ok) {
1926
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1927
+ }
1928
+ if (!response.body) {
1929
+ throw new Error("Response body is null");
1930
+ }
1931
+ let failedChunk = void 0;
1932
+ const transformStream = new TransformStream({
1933
+ start() {
1934
+ },
1935
+ async transform(chunk, controller) {
1936
+ try {
1937
+ const decoded = new TextDecoder().decode(chunk);
1938
+ const chunks = decoded.split(RECORD_SEPARATOR);
1939
+ for (const chunk2 of chunks) {
1940
+ if (chunk2) {
1941
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1942
+ try {
1943
+ const parsedChunk = JSON.parse(newChunk);
1944
+ controller.enqueue(parsedChunk);
1945
+ failedChunk = void 0;
1946
+ } catch {
1947
+ failedChunk = newChunk;
1948
+ }
1949
+ }
1950
+ }
1951
+ } catch {
1952
+ }
1953
+ }
1419
1954
  });
1955
+ return response.body.pipeThrough(transformStream);
1420
1956
  }
1421
1957
  /**
1422
- * Starts a workflow run and returns a stream
1423
- * @param params - Object containing the optional runId, inputData and runtimeContext
1958
+ * Observes workflow vNext stream for a workflow run
1959
+ * @param params - Object containing the runId
1424
1960
  * @returns Promise containing the workflow execution results
1425
1961
  */
1426
- async stream(params) {
1962
+ async observeStreamVNext(params) {
1427
1963
  const searchParams = new URLSearchParams();
1428
- if (!!params?.runId) {
1429
- searchParams.set("runId", params.runId);
1430
- }
1431
- const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1964
+ searchParams.set("runId", params.runId);
1432
1965
  const response = await this.request(
1433
- `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1966
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
1434
1967
  {
1435
1968
  method: "POST",
1436
- body: { inputData: params.inputData, runtimeContext },
1437
1969
  stream: true
1438
1970
  }
1439
1971
  );
1440
1972
  if (!response.ok) {
1441
- throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
1973
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
1442
1974
  }
1443
1975
  if (!response.body) {
1444
1976
  throw new Error("Response body is null");
1445
1977
  }
1978
+ let failedChunk = void 0;
1446
1979
  const transformStream = new TransformStream({
1447
1980
  start() {
1448
1981
  },
1449
1982
  async transform(chunk, controller) {
1450
1983
  try {
1451
1984
  const decoded = new TextDecoder().decode(chunk);
1452
- const chunks = decoded.split(RECORD_SEPARATOR2);
1985
+ const chunks = decoded.split(RECORD_SEPARATOR);
1453
1986
  for (const chunk2 of chunks) {
1454
1987
  if (chunk2) {
1988
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1455
1989
  try {
1456
- const parsedChunk = JSON.parse(chunk2);
1990
+ const parsedChunk = JSON.parse(newChunk);
1457
1991
  controller.enqueue(parsedChunk);
1992
+ failedChunk = void 0;
1458
1993
  } catch {
1994
+ failedChunk = newChunk;
1459
1995
  }
1460
1996
  }
1461
1997
  }
@@ -1477,9 +2013,64 @@ var Workflow = class extends BaseResource {
1477
2013
  body: {
1478
2014
  step: params.step,
1479
2015
  resumeData: params.resumeData,
1480
- runtimeContext
2016
+ runtimeContext,
2017
+ tracingOptions: params.tracingOptions
2018
+ }
2019
+ });
2020
+ }
2021
+ /**
2022
+ * Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
2023
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
2024
+ * @returns Promise containing the workflow resume results
2025
+ */
2026
+ async resumeStreamVNext(params) {
2027
+ const searchParams = new URLSearchParams();
2028
+ searchParams.set("runId", params.runId);
2029
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2030
+ const response = await this.request(
2031
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2032
+ {
2033
+ method: "POST",
2034
+ body: {
2035
+ step: params.step,
2036
+ resumeData: params.resumeData,
2037
+ runtimeContext,
2038
+ tracingOptions: params.tracingOptions
2039
+ },
2040
+ stream: true
2041
+ }
2042
+ );
2043
+ if (!response.ok) {
2044
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2045
+ }
2046
+ if (!response.body) {
2047
+ throw new Error("Response body is null");
2048
+ }
2049
+ let failedChunk = void 0;
2050
+ const transformStream = new TransformStream({
2051
+ start() {
2052
+ },
2053
+ async transform(chunk, controller) {
2054
+ try {
2055
+ const decoded = new TextDecoder().decode(chunk);
2056
+ const chunks = decoded.split(RECORD_SEPARATOR);
2057
+ for (const chunk2 of chunks) {
2058
+ if (chunk2) {
2059
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2060
+ try {
2061
+ const parsedChunk = JSON.parse(newChunk);
2062
+ controller.enqueue(parsedChunk);
2063
+ failedChunk = void 0;
2064
+ } catch {
2065
+ failedChunk = newChunk;
2066
+ }
2067
+ }
2068
+ }
2069
+ } catch {
2070
+ }
1481
2071
  }
1482
2072
  });
2073
+ return response.body.pipeThrough(transformStream);
1483
2074
  }
1484
2075
  /**
1485
2076
  * Watches workflow transitions in real-time
@@ -1517,7 +2108,7 @@ var Workflow = class extends BaseResource {
1517
2108
  async start(controller) {
1518
2109
  try {
1519
2110
  for await (const record of records) {
1520
- const json = JSON.stringify(record) + RECORD_SEPARATOR2;
2111
+ const json = JSON.stringify(record) + RECORD_SEPARATOR;
1521
2112
  controller.enqueue(encoder.encode(json));
1522
2113
  }
1523
2114
  controller.close();
@@ -1540,22 +2131,38 @@ var A2A = class extends BaseResource {
1540
2131
  * @returns Promise containing the agent card information
1541
2132
  */
1542
2133
  async getCard() {
1543
- return this.request(`/.well-known/${this.agentId}/agent.json`);
2134
+ return this.request(`/.well-known/${this.agentId}/agent-card.json`);
1544
2135
  }
1545
2136
  /**
1546
- * Send a message to the agent and get a response
2137
+ * Send a message to the agent and gets a message or task response
1547
2138
  * @param params - Parameters for the task
1548
- * @returns Promise containing the task response
2139
+ * @returns Promise containing the response
1549
2140
  */
1550
2141
  async sendMessage(params) {
1551
2142
  const response = await this.request(`/a2a/${this.agentId}`, {
1552
2143
  method: "POST",
1553
2144
  body: {
1554
- method: "tasks/send",
2145
+ method: "message/send",
2146
+ params
2147
+ }
2148
+ });
2149
+ return response;
2150
+ }
2151
+ /**
2152
+ * Sends a message to an agent to initiate/continue a task and subscribes
2153
+ * the client to real-time updates for that task via Server-Sent Events (SSE).
2154
+ * @param params - Parameters for the task
2155
+ * @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
2156
+ */
2157
+ async sendStreamingMessage(params) {
2158
+ const response = await this.request(`/a2a/${this.agentId}`, {
2159
+ method: "POST",
2160
+ body: {
2161
+ method: "message/stream",
1555
2162
  params
1556
2163
  }
1557
2164
  });
1558
- return { task: response.result };
2165
+ return response;
1559
2166
  }
1560
2167
  /**
1561
2168
  * Get the status and result of a task
@@ -1570,7 +2177,7 @@ var A2A = class extends BaseResource {
1570
2177
  params
1571
2178
  }
1572
2179
  });
1573
- return response.result;
2180
+ return response;
1574
2181
  }
1575
2182
  /**
1576
2183
  * Cancel a running task
@@ -1586,21 +2193,6 @@ var A2A = class extends BaseResource {
1586
2193
  }
1587
2194
  });
1588
2195
  }
1589
- /**
1590
- * Send a message and subscribe to streaming updates (not fully implemented)
1591
- * @param params - Parameters for the task
1592
- * @returns Promise containing the task response
1593
- */
1594
- async sendAndSubscribe(params) {
1595
- return this.request(`/a2a/${this.agentId}`, {
1596
- method: "POST",
1597
- body: {
1598
- method: "tasks/sendSubscribe",
1599
- params
1600
- },
1601
- stream: true
1602
- });
1603
- }
1604
2196
  };
1605
2197
 
1606
2198
  // src/resources/mcp-tool.ts
@@ -1614,10 +2206,11 @@ var MCPTool = class extends BaseResource {
1614
2206
  }
1615
2207
  /**
1616
2208
  * Retrieves details about this specific tool from the MCP server.
2209
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1617
2210
  * @returns Promise containing the tool's information (name, description, schema).
1618
2211
  */
1619
- details() {
1620
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2212
+ details(runtimeContext) {
2213
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1621
2214
  }
1622
2215
  /**
1623
2216
  * Executes this specific tool on the MCP server.
@@ -1637,93 +2230,286 @@ var MCPTool = class extends BaseResource {
1637
2230
  }
1638
2231
  };
1639
2232
 
1640
- // src/resources/vNextNetwork.ts
1641
- var RECORD_SEPARATOR3 = "";
1642
- var VNextNetwork = class extends BaseResource {
1643
- constructor(options, networkId) {
2233
+ // src/resources/agent-builder.ts
2234
+ var RECORD_SEPARATOR2 = "";
2235
+ var AgentBuilder = class extends BaseResource {
2236
+ constructor(options, actionId) {
1644
2237
  super(options);
1645
- this.networkId = networkId;
2238
+ this.actionId = actionId;
2239
+ }
2240
+ // Helper function to transform workflow result to action result
2241
+ transformWorkflowResult(result) {
2242
+ if (result.status === "success") {
2243
+ return {
2244
+ success: result.result.success || false,
2245
+ applied: result.result.applied || false,
2246
+ branchName: result.result.branchName,
2247
+ message: result.result.message || "Agent builder action completed",
2248
+ validationResults: result.result.validationResults,
2249
+ error: result.result.error,
2250
+ errors: result.result.errors,
2251
+ stepResults: result.result.stepResults
2252
+ };
2253
+ } else if (result.status === "failed") {
2254
+ return {
2255
+ success: false,
2256
+ applied: false,
2257
+ message: `Agent builder action failed: ${result.error.message}`,
2258
+ error: result.error.message
2259
+ };
2260
+ } else {
2261
+ return {
2262
+ success: false,
2263
+ applied: false,
2264
+ message: "Agent builder action was suspended",
2265
+ error: "Workflow suspended - manual intervention required"
2266
+ };
2267
+ }
2268
+ }
2269
+ /**
2270
+ * @deprecated Use createRunAsync() instead.
2271
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
2272
+ */
2273
+ async createRun(_params) {
2274
+ throw new Error(
2275
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
2276
+ );
1646
2277
  }
1647
2278
  /**
1648
- * Retrieves details about the network
1649
- * @returns Promise containing vNext network details
2279
+ * Creates a new agent builder action run and returns the runId.
2280
+ * This calls `/api/agent-builder/:actionId/create-run`.
1650
2281
  */
1651
- details() {
1652
- return this.request(`/api/networks/v-next/${this.networkId}`);
2282
+ async createRunAsync(params) {
2283
+ const searchParams = new URLSearchParams();
2284
+ if (!!params?.runId) {
2285
+ searchParams.set("runId", params.runId);
2286
+ }
2287
+ const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2288
+ return this.request(url, {
2289
+ method: "POST"
2290
+ });
1653
2291
  }
1654
2292
  /**
1655
- * Generates a response from the v-next network
1656
- * @param params - Generation parameters including message
1657
- * @returns Promise containing the generated response
2293
+ * Starts agent builder action asynchronously and waits for completion.
2294
+ * This calls `/api/agent-builder/:actionId/start-async`.
1658
2295
  */
1659
- generate(params) {
1660
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2296
+ async startAsync(params, runId) {
2297
+ const searchParams = new URLSearchParams();
2298
+ if (runId) {
2299
+ searchParams.set("runId", runId);
2300
+ }
2301
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2302
+ const { runtimeContext: _, ...actionParams } = params;
2303
+ const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2304
+ const result = await this.request(url, {
1661
2305
  method: "POST",
1662
- body: params
2306
+ body: { ...actionParams, runtimeContext }
2307
+ });
2308
+ return this.transformWorkflowResult(result);
2309
+ }
2310
+ /**
2311
+ * Starts an existing agent builder action run.
2312
+ * This calls `/api/agent-builder/:actionId/start`.
2313
+ */
2314
+ async startActionRun(params, runId) {
2315
+ const searchParams = new URLSearchParams();
2316
+ searchParams.set("runId", runId);
2317
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2318
+ const { runtimeContext: _, ...actionParams } = params;
2319
+ const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2320
+ return this.request(url, {
2321
+ method: "POST",
2322
+ body: { ...actionParams, runtimeContext }
2323
+ });
2324
+ }
2325
+ /**
2326
+ * Resumes a suspended agent builder action step.
2327
+ * This calls `/api/agent-builder/:actionId/resume`.
2328
+ */
2329
+ async resume(params, runId) {
2330
+ const searchParams = new URLSearchParams();
2331
+ searchParams.set("runId", runId);
2332
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2333
+ const { runtimeContext: _, ...resumeParams } = params;
2334
+ const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2335
+ return this.request(url, {
2336
+ method: "POST",
2337
+ body: { ...resumeParams, runtimeContext }
2338
+ });
2339
+ }
2340
+ /**
2341
+ * Resumes a suspended agent builder action step asynchronously.
2342
+ * This calls `/api/agent-builder/:actionId/resume-async`.
2343
+ */
2344
+ async resumeAsync(params, runId) {
2345
+ const searchParams = new URLSearchParams();
2346
+ searchParams.set("runId", runId);
2347
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2348
+ const { runtimeContext: _, ...resumeParams } = params;
2349
+ const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2350
+ const result = await this.request(url, {
2351
+ method: "POST",
2352
+ body: { ...resumeParams, runtimeContext }
2353
+ });
2354
+ return this.transformWorkflowResult(result);
2355
+ }
2356
+ /**
2357
+ * Creates an async generator that processes a readable stream and yields action records
2358
+ * separated by the Record Separator character (\x1E)
2359
+ *
2360
+ * @param stream - The readable stream to process
2361
+ * @returns An async generator that yields parsed records
2362
+ */
2363
+ async *streamProcessor(stream) {
2364
+ const reader = stream.getReader();
2365
+ let doneReading = false;
2366
+ let buffer = "";
2367
+ try {
2368
+ while (!doneReading) {
2369
+ const { done, value } = await reader.read();
2370
+ doneReading = done;
2371
+ if (done && !value) continue;
2372
+ try {
2373
+ const decoded = value ? new TextDecoder().decode(value) : "";
2374
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
2375
+ buffer = chunks.pop() || "";
2376
+ for (const chunk of chunks) {
2377
+ if (chunk) {
2378
+ if (typeof chunk === "string") {
2379
+ try {
2380
+ const parsedChunk = JSON.parse(chunk);
2381
+ yield parsedChunk;
2382
+ } catch {
2383
+ }
2384
+ }
2385
+ }
2386
+ }
2387
+ } catch {
2388
+ }
2389
+ }
2390
+ if (buffer) {
2391
+ try {
2392
+ yield JSON.parse(buffer);
2393
+ } catch {
2394
+ }
2395
+ }
2396
+ } finally {
2397
+ reader.cancel().catch(() => {
2398
+ });
2399
+ }
2400
+ }
2401
+ /**
2402
+ * Streams agent builder action progress in real-time.
2403
+ * This calls `/api/agent-builder/:actionId/stream`.
2404
+ */
2405
+ async stream(params, runId) {
2406
+ const searchParams = new URLSearchParams();
2407
+ if (runId) {
2408
+ searchParams.set("runId", runId);
2409
+ }
2410
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2411
+ const { runtimeContext: _, ...actionParams } = params;
2412
+ const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2413
+ const response = await this.request(url, {
2414
+ method: "POST",
2415
+ body: { ...actionParams, runtimeContext },
2416
+ stream: true
2417
+ });
2418
+ if (!response.ok) {
2419
+ throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
2420
+ }
2421
+ if (!response.body) {
2422
+ throw new Error("Response body is null");
2423
+ }
2424
+ let failedChunk = void 0;
2425
+ const transformStream = new TransformStream({
2426
+ start() {
2427
+ },
2428
+ async transform(chunk, controller) {
2429
+ try {
2430
+ const decoded = new TextDecoder().decode(chunk);
2431
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2432
+ for (const chunk2 of chunks) {
2433
+ if (chunk2) {
2434
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2435
+ try {
2436
+ const parsedChunk = JSON.parse(newChunk);
2437
+ controller.enqueue(parsedChunk);
2438
+ failedChunk = void 0;
2439
+ } catch {
2440
+ failedChunk = newChunk;
2441
+ }
2442
+ }
2443
+ }
2444
+ } catch {
2445
+ }
2446
+ }
1663
2447
  });
2448
+ return response.body.pipeThrough(transformStream);
1664
2449
  }
1665
2450
  /**
1666
- * Generates a response from the v-next network using multiple primitives
1667
- * @param params - Generation parameters including message
1668
- * @returns Promise containing the generated response
2451
+ * Streams agent builder action progress in real-time using VNext streaming.
2452
+ * This calls `/api/agent-builder/:actionId/streamVNext`.
1669
2453
  */
1670
- loop(params) {
1671
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2454
+ async streamVNext(params, runId) {
2455
+ const searchParams = new URLSearchParams();
2456
+ if (runId) {
2457
+ searchParams.set("runId", runId);
2458
+ }
2459
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2460
+ const { runtimeContext: _, ...actionParams } = params;
2461
+ const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2462
+ const response = await this.request(url, {
1672
2463
  method: "POST",
1673
- body: params
2464
+ body: { ...actionParams, runtimeContext },
2465
+ stream: true
1674
2466
  });
1675
- }
1676
- async *streamProcessor(stream) {
1677
- const reader = stream.getReader();
1678
- let doneReading = false;
1679
- let buffer = "";
1680
- try {
1681
- while (!doneReading) {
1682
- const { done, value } = await reader.read();
1683
- doneReading = done;
1684
- if (done && !value) continue;
2467
+ if (!response.ok) {
2468
+ throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
2469
+ }
2470
+ if (!response.body) {
2471
+ throw new Error("Response body is null");
2472
+ }
2473
+ let failedChunk = void 0;
2474
+ const transformStream = new TransformStream({
2475
+ start() {
2476
+ },
2477
+ async transform(chunk, controller) {
1685
2478
  try {
1686
- const decoded = value ? new TextDecoder().decode(value) : "";
1687
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
1688
- buffer = chunks.pop() || "";
1689
- for (const chunk of chunks) {
1690
- if (chunk) {
1691
- if (typeof chunk === "string") {
1692
- try {
1693
- const parsedChunk = JSON.parse(chunk);
1694
- yield parsedChunk;
1695
- } catch {
1696
- }
2479
+ const decoded = new TextDecoder().decode(chunk);
2480
+ const chunks = decoded.split(RECORD_SEPARATOR2);
2481
+ for (const chunk2 of chunks) {
2482
+ if (chunk2) {
2483
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2484
+ try {
2485
+ const parsedChunk = JSON.parse(newChunk);
2486
+ controller.enqueue(parsedChunk);
2487
+ failedChunk = void 0;
2488
+ } catch {
2489
+ failedChunk = newChunk;
1697
2490
  }
1698
2491
  }
1699
2492
  }
1700
2493
  } catch {
1701
2494
  }
1702
2495
  }
1703
- if (buffer) {
1704
- try {
1705
- yield JSON.parse(buffer);
1706
- } catch {
1707
- }
1708
- }
1709
- } finally {
1710
- reader.cancel().catch(() => {
1711
- });
1712
- }
2496
+ });
2497
+ return response.body.pipeThrough(transformStream);
1713
2498
  }
1714
2499
  /**
1715
- * Streams a response from the v-next network
1716
- * @param params - Stream parameters including message
1717
- * @returns Promise containing the results
2500
+ * Watches an existing agent builder action run by runId.
2501
+ * This is used for hot reload recovery - it loads the existing run state
2502
+ * and streams any remaining progress.
2503
+ * This calls `/api/agent-builder/:actionId/watch`.
1718
2504
  */
1719
- async stream(params, onRecord) {
1720
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1721
- method: "POST",
1722
- body: params,
2505
+ async watch({ runId, eventType }, onRecord) {
2506
+ const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
2507
+ const response = await this.request(url, {
2508
+ method: "GET",
1723
2509
  stream: true
1724
2510
  });
1725
2511
  if (!response.ok) {
1726
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2512
+ throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
1727
2513
  }
1728
2514
  if (!response.body) {
1729
2515
  throw new Error("Response body is null");
@@ -1737,29 +2523,155 @@ var VNextNetwork = class extends BaseResource {
1737
2523
  }
1738
2524
  }
1739
2525
  /**
1740
- * Streams a response from the v-next network loop
1741
- * @param params - Stream parameters including message
1742
- * @returns Promise containing the results
2526
+ * Gets a specific action run by its ID.
2527
+ * This calls `/api/agent-builder/:actionId/runs/:runId`.
2528
+ */
2529
+ async runById(runId) {
2530
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
2531
+ return this.request(url, {
2532
+ method: "GET"
2533
+ });
2534
+ }
2535
+ /**
2536
+ * Gets details about this agent builder action.
2537
+ * This calls `/api/agent-builder/:actionId`.
2538
+ */
2539
+ async details() {
2540
+ const result = await this.request(`/api/agent-builder/${this.actionId}`);
2541
+ return result;
2542
+ }
2543
+ /**
2544
+ * Gets all runs for this agent builder action.
2545
+ * This calls `/api/agent-builder/:actionId/runs`.
2546
+ */
2547
+ async runs(params) {
2548
+ const searchParams = new URLSearchParams();
2549
+ if (params?.fromDate) {
2550
+ searchParams.set("fromDate", params.fromDate.toISOString());
2551
+ }
2552
+ if (params?.toDate) {
2553
+ searchParams.set("toDate", params.toDate.toISOString());
2554
+ }
2555
+ if (params?.limit !== void 0) {
2556
+ searchParams.set("limit", String(params.limit));
2557
+ }
2558
+ if (params?.offset !== void 0) {
2559
+ searchParams.set("offset", String(params.offset));
2560
+ }
2561
+ if (params?.resourceId) {
2562
+ searchParams.set("resourceId", params.resourceId);
2563
+ }
2564
+ const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2565
+ return this.request(url, {
2566
+ method: "GET"
2567
+ });
2568
+ }
2569
+ /**
2570
+ * Gets the execution result of an agent builder action run.
2571
+ * This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
2572
+ */
2573
+ async runExecutionResult(runId) {
2574
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
2575
+ return this.request(url, {
2576
+ method: "GET"
2577
+ });
2578
+ }
2579
+ /**
2580
+ * Cancels an agent builder action run.
2581
+ * This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
2582
+ */
2583
+ async cancelRun(runId) {
2584
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
2585
+ return this.request(url, {
2586
+ method: "POST"
2587
+ });
2588
+ }
2589
+ /**
2590
+ * Sends an event to an agent builder action run.
2591
+ * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
1743
2592
  */
1744
- async loopStream(params, onRecord) {
1745
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2593
+ async sendRunEvent(params) {
2594
+ const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2595
+ return this.request(url, {
1746
2596
  method: "POST",
1747
- body: params,
1748
- stream: true
2597
+ body: { event: params.event, data: params.data }
1749
2598
  });
1750
- if (!response.ok) {
1751
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2599
+ }
2600
+ };
2601
+
2602
+ // src/resources/observability.ts
2603
+ var Observability = class extends BaseResource {
2604
+ constructor(options) {
2605
+ super(options);
2606
+ }
2607
+ /**
2608
+ * Retrieves a specific AI trace by ID
2609
+ * @param traceId - ID of the trace to retrieve
2610
+ * @returns Promise containing the AI trace with all its spans
2611
+ */
2612
+ getTrace(traceId) {
2613
+ return this.request(`/api/observability/traces/${traceId}`);
2614
+ }
2615
+ /**
2616
+ * Retrieves paginated list of AI traces with optional filtering
2617
+ * @param params - Parameters for pagination and filtering
2618
+ * @returns Promise containing paginated traces and pagination info
2619
+ */
2620
+ getTraces(params) {
2621
+ const { pagination, filters } = params;
2622
+ const { page, perPage, dateRange } = pagination || {};
2623
+ const { name, spanType, entityId, entityType } = filters || {};
2624
+ const searchParams = new URLSearchParams();
2625
+ if (page !== void 0) {
2626
+ searchParams.set("page", String(page));
1752
2627
  }
1753
- if (!response.body) {
1754
- throw new Error("Response body is null");
2628
+ if (perPage !== void 0) {
2629
+ searchParams.set("perPage", String(perPage));
1755
2630
  }
1756
- for await (const record of this.streamProcessor(response.body)) {
1757
- if (typeof record === "string") {
1758
- onRecord(JSON.parse(record));
1759
- } else {
1760
- onRecord(record);
1761
- }
2631
+ if (name) {
2632
+ searchParams.set("name", name);
2633
+ }
2634
+ if (spanType !== void 0) {
2635
+ searchParams.set("spanType", String(spanType));
2636
+ }
2637
+ if (entityId && entityType) {
2638
+ searchParams.set("entityId", entityId);
2639
+ searchParams.set("entityType", entityType);
2640
+ }
2641
+ if (dateRange) {
2642
+ const dateRangeStr = JSON.stringify({
2643
+ start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
2644
+ end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
2645
+ });
2646
+ searchParams.set("dateRange", dateRangeStr);
2647
+ }
2648
+ const queryString = searchParams.toString();
2649
+ return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
2650
+ }
2651
+ /**
2652
+ * Retrieves scores by trace ID and span ID
2653
+ * @param params - Parameters containing trace ID, span ID, and pagination options
2654
+ * @returns Promise containing scores and pagination info
2655
+ */
2656
+ getScoresBySpan(params) {
2657
+ const { traceId, spanId, page, perPage } = params;
2658
+ const searchParams = new URLSearchParams();
2659
+ if (page !== void 0) {
2660
+ searchParams.set("page", String(page));
2661
+ }
2662
+ if (perPage !== void 0) {
2663
+ searchParams.set("perPage", String(perPage));
1762
2664
  }
2665
+ const queryString = searchParams.toString();
2666
+ return this.request(
2667
+ `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
2668
+ );
2669
+ }
2670
+ score(params) {
2671
+ return this.request(`/api/observability/traces/score`, {
2672
+ method: "POST",
2673
+ body: { ...params }
2674
+ });
1763
2675
  }
1764
2676
  };
1765
2677
 
@@ -1809,34 +2721,43 @@ var NetworkMemoryThread = class extends BaseResource {
1809
2721
  });
1810
2722
  return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1811
2723
  }
2724
+ /**
2725
+ * Deletes one or more messages from the thread
2726
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
2727
+ * message object with id property, or array of message objects
2728
+ * @returns Promise containing deletion result
2729
+ */
2730
+ deleteMessages(messageIds) {
2731
+ const query = new URLSearchParams({
2732
+ networkId: this.networkId
2733
+ });
2734
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
2735
+ method: "POST",
2736
+ body: { messageIds }
2737
+ });
2738
+ }
1812
2739
  };
1813
2740
 
1814
2741
  // src/client.ts
1815
2742
  var MastraClient = class extends BaseResource {
2743
+ observability;
1816
2744
  constructor(options) {
1817
2745
  super(options);
2746
+ this.observability = new Observability(options);
1818
2747
  }
1819
2748
  /**
1820
2749
  * Retrieves all available agents
2750
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1821
2751
  * @returns Promise containing map of agent IDs to agent details
1822
2752
  */
1823
- getAgents() {
1824
- return this.request("/api/agents");
1825
- }
1826
- async getAGUI({ resourceId }) {
1827
- const agents = await this.getAgents();
1828
- return Object.entries(agents).reduce(
1829
- (acc, [agentId]) => {
1830
- const agent = this.getAgent(agentId);
1831
- acc[agentId] = new AGUIAdapter({
1832
- agentId,
1833
- agent,
1834
- resourceId
1835
- });
1836
- return acc;
1837
- },
1838
- {}
1839
- );
2753
+ getAgents(runtimeContext) {
2754
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2755
+ const searchParams = new URLSearchParams();
2756
+ if (runtimeContextParam) {
2757
+ searchParams.set("runtimeContext", runtimeContextParam);
2758
+ }
2759
+ const queryString = searchParams.toString();
2760
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
1840
2761
  }
1841
2762
  /**
1842
2763
  * Gets an agent instance by ID
@@ -1854,6 +2775,14 @@ var MastraClient = class extends BaseResource {
1854
2775
  getMemoryThreads(params) {
1855
2776
  return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
1856
2777
  }
2778
+ /**
2779
+ * Retrieves memory config for a resource
2780
+ * @param params - Parameters containing the resource ID
2781
+ * @returns Promise containing array of memory threads
2782
+ */
2783
+ getMemoryConfig(params) {
2784
+ return this.request(`/api/memory/config?agentId=${params.agentId}`);
2785
+ }
1857
2786
  /**
1858
2787
  * Creates a new memory thread
1859
2788
  * @param params - Parameters for creating the memory thread
@@ -1870,6 +2799,24 @@ var MastraClient = class extends BaseResource {
1870
2799
  getMemoryThread(threadId, agentId) {
1871
2800
  return new MemoryThread(this.options, threadId, agentId);
1872
2801
  }
2802
+ getThreadMessages(threadId, opts = {}) {
2803
+ let url = "";
2804
+ if (opts.agentId) {
2805
+ url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
2806
+ } else if (opts.networkId) {
2807
+ url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
2808
+ }
2809
+ return this.request(url);
2810
+ }
2811
+ deleteThread(threadId, opts = {}) {
2812
+ let url = "";
2813
+ if (opts.agentId) {
2814
+ url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
2815
+ } else if (opts.networkId) {
2816
+ url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
2817
+ }
2818
+ return this.request(url, { method: "DELETE" });
2819
+ }
1873
2820
  /**
1874
2821
  * Saves messages to memory
1875
2822
  * @param params - Parameters containing messages to save
@@ -1932,10 +2879,17 @@ var MastraClient = class extends BaseResource {
1932
2879
  }
1933
2880
  /**
1934
2881
  * Retrieves all available tools
2882
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1935
2883
  * @returns Promise containing map of tool IDs to tool details
1936
2884
  */
1937
- getTools() {
1938
- return this.request("/api/tools");
2885
+ getTools(runtimeContext) {
2886
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2887
+ const searchParams = new URLSearchParams();
2888
+ if (runtimeContextParam) {
2889
+ searchParams.set("runtimeContext", runtimeContextParam);
2890
+ }
2891
+ const queryString = searchParams.toString();
2892
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
1939
2893
  }
1940
2894
  /**
1941
2895
  * Gets a tool instance by ID
@@ -1943,29 +2897,21 @@ var MastraClient = class extends BaseResource {
1943
2897
  * @returns Tool instance
1944
2898
  */
1945
2899
  getTool(toolId) {
1946
- return new Tool2(this.options, toolId);
1947
- }
1948
- /**
1949
- * Retrieves all available legacy workflows
1950
- * @returns Promise containing map of legacy workflow IDs to legacy workflow details
1951
- */
1952
- getLegacyWorkflows() {
1953
- return this.request("/api/workflows/legacy");
1954
- }
1955
- /**
1956
- * Gets a legacy workflow instance by ID
1957
- * @param workflowId - ID of the legacy workflow to retrieve
1958
- * @returns Legacy Workflow instance
1959
- */
1960
- getLegacyWorkflow(workflowId) {
1961
- return new LegacyWorkflow(this.options, workflowId);
2900
+ return new Tool(this.options, toolId);
1962
2901
  }
1963
2902
  /**
1964
2903
  * Retrieves all available workflows
2904
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1965
2905
  * @returns Promise containing map of workflow IDs to workflow details
1966
2906
  */
1967
- getWorkflows() {
1968
- return this.request("/api/workflows");
2907
+ getWorkflows(runtimeContext) {
2908
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2909
+ const searchParams = new URLSearchParams();
2910
+ if (runtimeContextParam) {
2911
+ searchParams.set("runtimeContext", runtimeContextParam);
2912
+ }
2913
+ const queryString = searchParams.toString();
2914
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
1969
2915
  }
1970
2916
  /**
1971
2917
  * Gets a workflow instance by ID
@@ -1975,6 +2921,20 @@ var MastraClient = class extends BaseResource {
1975
2921
  getWorkflow(workflowId) {
1976
2922
  return new Workflow(this.options, workflowId);
1977
2923
  }
2924
+ /**
2925
+ * Gets all available agent builder actions
2926
+ * @returns Promise containing map of action IDs to action details
2927
+ */
2928
+ getAgentBuilderActions() {
2929
+ return this.request("/api/agent-builder/");
2930
+ }
2931
+ /**
2932
+ * Gets an agent builder instance for executing agent-builder workflows
2933
+ * @returns AgentBuilder instance
2934
+ */
2935
+ getAgentBuilderAction(actionId) {
2936
+ return new AgentBuilder(this.options, actionId);
2937
+ }
1978
2938
  /**
1979
2939
  * Gets a vector instance by name
1980
2940
  * @param vectorName - Name of the vector to retrieve
@@ -2119,36 +3079,6 @@ var MastraClient = class extends BaseResource {
2119
3079
  return this.request(`/api/telemetry`);
2120
3080
  }
2121
3081
  }
2122
- /**
2123
- * Retrieves all available networks
2124
- * @returns Promise containing map of network IDs to network details
2125
- */
2126
- getNetworks() {
2127
- return this.request("/api/networks");
2128
- }
2129
- /**
2130
- * Retrieves all available vNext networks
2131
- * @returns Promise containing map of vNext network IDs to vNext network details
2132
- */
2133
- getVNextNetworks() {
2134
- return this.request("/api/networks/v-next");
2135
- }
2136
- /**
2137
- * Gets a network instance by ID
2138
- * @param networkId - ID of the network to retrieve
2139
- * @returns Network instance
2140
- */
2141
- getNetwork(networkId) {
2142
- return new Network(this.options, networkId);
2143
- }
2144
- /**
2145
- * Gets a vNext network instance by ID
2146
- * @param networkId - ID of the vNext network to retrieve
2147
- * @returns vNext Network instance
2148
- */
2149
- getVNextNetwork(networkId) {
2150
- return new VNextNetwork(this.options, networkId);
2151
- }
2152
3082
  /**
2153
3083
  * Retrieves a list of available MCP servers.
2154
3084
  * @param params - Optional parameters for pagination (limit, offset).
@@ -2205,6 +3135,161 @@ var MastraClient = class extends BaseResource {
2205
3135
  getA2A(agentId) {
2206
3136
  return new A2A(this.options, agentId);
2207
3137
  }
3138
+ /**
3139
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
3140
+ * @param agentId - ID of the agent.
3141
+ * @param threadId - ID of the thread.
3142
+ * @param resourceId - Optional ID of the resource.
3143
+ * @returns Working memory for the specified thread or resource.
3144
+ */
3145
+ getWorkingMemory({
3146
+ agentId,
3147
+ threadId,
3148
+ resourceId
3149
+ }) {
3150
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
3151
+ }
3152
+ /**
3153
+ * Updates the working memory for a specific thread (optionally resource-scoped).
3154
+ * @param agentId - ID of the agent.
3155
+ * @param threadId - ID of the thread.
3156
+ * @param workingMemory - The new working memory content.
3157
+ * @param resourceId - Optional ID of the resource.
3158
+ */
3159
+ updateWorkingMemory({
3160
+ agentId,
3161
+ threadId,
3162
+ workingMemory,
3163
+ resourceId
3164
+ }) {
3165
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
3166
+ method: "POST",
3167
+ body: {
3168
+ workingMemory,
3169
+ resourceId
3170
+ }
3171
+ });
3172
+ }
3173
+ /**
3174
+ * Retrieves all available scorers
3175
+ * @returns Promise containing list of available scorers
3176
+ */
3177
+ getScorers() {
3178
+ return this.request("/api/scores/scorers");
3179
+ }
3180
+ /**
3181
+ * Retrieves a scorer by ID
3182
+ * @param scorerId - ID of the scorer to retrieve
3183
+ * @returns Promise containing the scorer
3184
+ */
3185
+ getScorer(scorerId) {
3186
+ return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
3187
+ }
3188
+ getScoresByScorerId(params) {
3189
+ const { page, perPage, scorerId, entityId, entityType } = params;
3190
+ const searchParams = new URLSearchParams();
3191
+ if (entityId) {
3192
+ searchParams.set("entityId", entityId);
3193
+ }
3194
+ if (entityType) {
3195
+ searchParams.set("entityType", entityType);
3196
+ }
3197
+ if (page !== void 0) {
3198
+ searchParams.set("page", String(page));
3199
+ }
3200
+ if (perPage !== void 0) {
3201
+ searchParams.set("perPage", String(perPage));
3202
+ }
3203
+ const queryString = searchParams.toString();
3204
+ return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
3205
+ }
3206
+ /**
3207
+ * Retrieves scores by run ID
3208
+ * @param params - Parameters containing run ID and pagination options
3209
+ * @returns Promise containing scores and pagination info
3210
+ */
3211
+ getScoresByRunId(params) {
3212
+ const { runId, page, perPage } = params;
3213
+ const searchParams = new URLSearchParams();
3214
+ if (page !== void 0) {
3215
+ searchParams.set("page", String(page));
3216
+ }
3217
+ if (perPage !== void 0) {
3218
+ searchParams.set("perPage", String(perPage));
3219
+ }
3220
+ const queryString = searchParams.toString();
3221
+ return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
3222
+ }
3223
+ /**
3224
+ * Retrieves scores by entity ID and type
3225
+ * @param params - Parameters containing entity ID, type, and pagination options
3226
+ * @returns Promise containing scores and pagination info
3227
+ */
3228
+ getScoresByEntityId(params) {
3229
+ const { entityId, entityType, page, perPage } = params;
3230
+ const searchParams = new URLSearchParams();
3231
+ if (page !== void 0) {
3232
+ searchParams.set("page", String(page));
3233
+ }
3234
+ if (perPage !== void 0) {
3235
+ searchParams.set("perPage", String(perPage));
3236
+ }
3237
+ const queryString = searchParams.toString();
3238
+ return this.request(
3239
+ `/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
3240
+ );
3241
+ }
3242
+ /**
3243
+ * Saves a score
3244
+ * @param params - Parameters containing the score data to save
3245
+ * @returns Promise containing the saved score
3246
+ */
3247
+ saveScore(params) {
3248
+ return this.request("/api/scores", {
3249
+ method: "POST",
3250
+ body: params
3251
+ });
3252
+ }
3253
+ /**
3254
+ * Retrieves model providers with available keys
3255
+ * @returns Promise containing model providers with available keys
3256
+ */
3257
+ getModelProviders() {
3258
+ return this.request(`/api/model-providers`);
3259
+ }
3260
+ getAITrace(traceId) {
3261
+ return this.observability.getTrace(traceId);
3262
+ }
3263
+ getAITraces(params) {
3264
+ return this.observability.getTraces(params);
3265
+ }
3266
+ getScoresBySpan(params) {
3267
+ return this.observability.getScoresBySpan(params);
3268
+ }
3269
+ score(params) {
3270
+ return this.observability.score(params);
3271
+ }
2208
3272
  };
2209
3273
 
2210
- export { MastraClient };
3274
+ // src/tools.ts
3275
+ var ClientTool = class {
3276
+ id;
3277
+ description;
3278
+ inputSchema;
3279
+ outputSchema;
3280
+ execute;
3281
+ constructor(opts) {
3282
+ this.id = opts.id;
3283
+ this.description = opts.description;
3284
+ this.inputSchema = opts.inputSchema;
3285
+ this.outputSchema = opts.outputSchema;
3286
+ this.execute = opts.execute;
3287
+ }
3288
+ };
3289
+ function createTool(opts) {
3290
+ return new ClientTool(opts);
3291
+ }
3292
+
3293
+ export { ClientTool, MastraClient, createTool };
3294
+ //# sourceMappingURL=index.js.map
3295
+ //# sourceMappingURL=index.js.map