@mastra/client-js 0.0.0-working-memory-per-user-20250620163010 → 0.0.0-zod-v4-compat-part-2-20250820135355

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 (76) hide show
  1. package/CHANGELOG.md +601 -3
  2. package/LICENSE.md +11 -42
  3. package/README.md +1 -0
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +265 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +883 -22
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -952
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +884 -23
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +44 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +112 -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/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.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/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +16 -12
  55. package/src/adapters/agui.test.ts +145 -3
  56. package/src/client.ts +214 -1
  57. package/src/example.ts +46 -15
  58. package/src/index.test.ts +402 -6
  59. package/src/index.ts +1 -0
  60. package/src/resources/agent.ts +593 -25
  61. package/src/resources/base.ts +6 -0
  62. package/src/resources/memory-thread.test.ts +285 -0
  63. package/src/resources/memory-thread.ts +36 -0
  64. package/src/resources/network-memory-thread.test.ts +269 -0
  65. package/src/resources/network-memory-thread.ts +81 -0
  66. package/src/resources/network.ts +6 -6
  67. package/src/resources/vNextNetwork.ts +194 -0
  68. package/src/resources/workflow.ts +45 -8
  69. package/src/types.ts +171 -8
  70. package/src/utils/process-client-tools.ts +4 -3
  71. package/src/utils/zod-to-json-schema.ts +20 -3
  72. package/src/v2-messages.test.ts +180 -0
  73. package/tsconfig.build.json +9 -0
  74. package/tsconfig.json +1 -1
  75. package/tsup.config.ts +22 -0
  76. package/dist/index.d.cts +0 -952
@@ -1,10 +1,9 @@
1
1
  import { processDataStream } from '@ai-sdk/ui-utils';
2
2
  import type { GenerateReturn } from '@mastra/core';
3
3
  import type { JSONSchema7 } from 'json-schema';
4
- import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from '../utils/zod-to-json-schema';
6
-
4
+ import type { ZodSchema } from 'zod';
7
5
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
6
+ import { zodToJsonSchema } from '../utils/zod-to-json-schema';
8
7
 
9
8
  import { BaseResource } from './base';
10
9
 
@@ -29,9 +28,10 @@ export class Network extends BaseResource {
29
28
  * @param params - Generation parameters including prompt
30
29
  * @returns Promise containing the generated response
31
30
  */
32
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
33
- params: GenerateParams<T>,
34
- ): Promise<GenerateReturn<T>> {
31
+ generate<
32
+ Output extends JSONSchema7 | ZodSchema | undefined = undefined,
33
+ StructuredOutput extends JSONSchema7 | ZodSchema | undefined = undefined,
34
+ >(params: GenerateParams<Output>): Promise<GenerateReturn<any, Output, StructuredOutput>> {
35
35
  const processedParams = {
36
36
  ...params,
37
37
  output: zodToJsonSchema(params.output),
@@ -0,0 +1,194 @@
1
+ import type { WatchEvent } from '@mastra/core/workflows';
2
+
3
+ import type {
4
+ ClientOptions,
5
+ GetVNextNetworkResponse,
6
+ GenerateVNextNetworkResponse,
7
+ LoopVNextNetworkResponse,
8
+ GenerateOrStreamVNextNetworkParams,
9
+ LoopStreamVNextNetworkParams,
10
+ } from '../types';
11
+
12
+ import { BaseResource } from './base';
13
+ import { parseClientRuntimeContext } from '../utils';
14
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
15
+
16
+ const RECORD_SEPARATOR = '\x1E';
17
+
18
+ export class VNextNetwork extends BaseResource {
19
+ constructor(
20
+ options: ClientOptions,
21
+ private networkId: string,
22
+ ) {
23
+ super(options);
24
+ }
25
+
26
+ /**
27
+ * Retrieves details about the network
28
+ * @returns Promise containing vNext network details
29
+ */
30
+ details(): Promise<GetVNextNetworkResponse> {
31
+ return this.request(`/api/networks/v-next/${this.networkId}`);
32
+ }
33
+
34
+ /**
35
+ * Generates a response from the v-next network
36
+ * @param params - Generation parameters including message
37
+ * @returns Promise containing the generated response
38
+ */
39
+ generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse> {
40
+ return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
41
+ method: 'POST',
42
+ body: {
43
+ ...params,
44
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
45
+ },
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Generates a response from the v-next network using multiple primitives
51
+ * @param params - Generation parameters including message
52
+ * @returns Promise containing the generated response
53
+ */
54
+ loop(params: {
55
+ message: string;
56
+ runtimeContext?: RuntimeContext | Record<string, any>;
57
+ }): Promise<LoopVNextNetworkResponse> {
58
+ return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
59
+ method: 'POST',
60
+ body: {
61
+ ...params,
62
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
63
+ },
64
+ });
65
+ }
66
+
67
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WatchEvent, void, unknown> {
68
+ const reader = stream.getReader();
69
+
70
+ // Track if we've finished reading from the stream
71
+ let doneReading = false;
72
+ // Buffer to accumulate partial chunks
73
+ let buffer = '';
74
+
75
+ try {
76
+ while (!doneReading) {
77
+ // Read the next chunk from the stream
78
+ const { done, value } = await reader.read();
79
+ doneReading = done;
80
+
81
+ // Skip processing if we're done and there's no value
82
+ if (done && !value) continue;
83
+
84
+ try {
85
+ // Decode binary data to text
86
+ const decoded = value ? new TextDecoder().decode(value) : '';
87
+
88
+ // Split the combined buffer and new data by record separator
89
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
90
+
91
+ // The last chunk might be incomplete, so save it for the next iteration
92
+ buffer = chunks.pop() || '';
93
+
94
+ // Process complete chunks
95
+ for (const chunk of chunks) {
96
+ if (chunk) {
97
+ // Only process non-empty chunks
98
+ if (typeof chunk === 'string') {
99
+ try {
100
+ const parsedChunk = JSON.parse(chunk);
101
+ yield parsedChunk;
102
+ } catch {
103
+ // Silently ignore parsing errors to maintain stream processing
104
+ // This allows the stream to continue even if one record is malformed
105
+ }
106
+ }
107
+ }
108
+ }
109
+ } catch {
110
+ // Silently ignore parsing errors to maintain stream processing
111
+ // This allows the stream to continue even if one record is malformed
112
+ }
113
+ }
114
+
115
+ // Process any remaining data in the buffer after stream is done
116
+ if (buffer) {
117
+ try {
118
+ yield JSON.parse(buffer);
119
+ } catch {
120
+ // Ignore parsing error for final chunk
121
+ }
122
+ }
123
+ } finally {
124
+ // Always ensure we clean up the reader
125
+ reader.cancel().catch(() => {
126
+ // Ignore cancel errors
127
+ });
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Streams a response from the v-next network
133
+ * @param params - Stream parameters including message
134
+ * @returns Promise containing the results
135
+ */
136
+ async stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
137
+ const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
138
+ method: 'POST',
139
+ body: {
140
+ ...params,
141
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
142
+ },
143
+ stream: true,
144
+ });
145
+
146
+ if (!response.ok) {
147
+ throw new Error(`Failed to stream vNext network: ${response.statusText}`);
148
+ }
149
+
150
+ if (!response.body) {
151
+ throw new Error('Response body is null');
152
+ }
153
+
154
+ for await (const record of this.streamProcessor(response.body)) {
155
+ if (typeof record === 'string') {
156
+ onRecord(JSON.parse(record));
157
+ } else {
158
+ onRecord(record);
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Streams a response from the v-next network loop
165
+ * @param params - Stream parameters including message
166
+ * @returns Promise containing the results
167
+ */
168
+ async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
169
+ const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
170
+ method: 'POST',
171
+ body: {
172
+ ...params,
173
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
174
+ },
175
+ stream: true,
176
+ });
177
+
178
+ if (!response.ok) {
179
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
180
+ }
181
+
182
+ if (!response.body) {
183
+ throw new Error('Response body is null');
184
+ }
185
+
186
+ for await (const record of this.streamProcessor(response.body)) {
187
+ if (typeof record === 'string') {
188
+ onRecord(JSON.parse(record));
189
+ } else {
190
+ onRecord(record);
191
+ }
192
+ }
193
+ }
194
+ }
@@ -115,10 +115,10 @@ export class Workflow extends BaseResource {
115
115
  if (params?.toDate) {
116
116
  searchParams.set('toDate', params.toDate.toISOString());
117
117
  }
118
- if (params?.limit) {
118
+ if (params?.limit !== null && params?.limit !== undefined && !isNaN(Number(params?.limit))) {
119
119
  searchParams.set('limit', String(params.limit));
120
120
  }
121
- if (params?.offset) {
121
+ if (params?.offset !== null && params?.offset !== undefined && !isNaN(Number(params?.offset))) {
122
122
  searchParams.set('offset', String(params.offset));
123
123
  }
124
124
  if (params?.resourceId) {
@@ -150,6 +150,29 @@ export class Workflow extends BaseResource {
150
150
  return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
151
151
  }
152
152
 
153
+ /**
154
+ * Cancels a specific workflow run by its ID
155
+ * @param runId - The ID of the workflow run to cancel
156
+ * @returns Promise containing a success message
157
+ */
158
+ cancelRun(runId: string): Promise<{ message: string }> {
159
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
160
+ method: 'POST',
161
+ });
162
+ }
163
+
164
+ /**
165
+ * Sends an event to a specific workflow run by its ID
166
+ * @param params - Object containing the runId, event and data
167
+ * @returns Promise containing a success message
168
+ */
169
+ sendRunEvent(params: { runId: string; event: string; data: unknown }): Promise<{ message: string }> {
170
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
171
+ method: 'POST',
172
+ body: { event: params.event, data: params.data },
173
+ });
174
+ }
175
+
153
176
  /**
154
177
  * Creates a new workflow run
155
178
  * @param params - Optional object containing the optional runId
@@ -167,6 +190,15 @@ export class Workflow extends BaseResource {
167
190
  });
168
191
  }
169
192
 
193
+ /**
194
+ * Creates a new workflow run (alias for createRun)
195
+ * @param params - Optional object containing the optional runId
196
+ * @returns Promise containing the runId of the created run
197
+ */
198
+ createRunAsync(params?: { runId?: string }): Promise<{ runId: string }> {
199
+ return this.createRun(params);
200
+ }
201
+
170
202
  /**
171
203
  * Starts a workflow run synchronously without waiting for the workflow to complete
172
204
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -237,9 +269,9 @@ export class Workflow extends BaseResource {
237
269
  }
238
270
 
239
271
  /**
240
- * Starts a vNext workflow run and returns a stream
272
+ * Starts a workflow run and returns a stream
241
273
  * @param params - Object containing the optional runId, inputData and runtimeContext
242
- * @returns Promise containing the vNext workflow execution results
274
+ * @returns Promise containing the workflow execution results
243
275
  */
244
276
  async stream(params: { runId?: string; inputData: Record<string, any>; runtimeContext?: RuntimeContext }) {
245
277
  const searchParams = new URLSearchParams();
@@ -266,8 +298,11 @@ export class Workflow extends BaseResource {
266
298
  throw new Error('Response body is null');
267
299
  }
268
300
 
301
+ //using undefined instead of empty string to avoid parsing errors
302
+ let failedChunk: string | undefined = undefined;
303
+
269
304
  // Create a transform stream that processes the response body
270
- const transformStream = new TransformStream<ArrayBuffer, WorkflowWatchResult>({
305
+ const transformStream = new TransformStream<ArrayBuffer, { type: string; payload: any }>({
271
306
  start() {},
272
307
  async transform(chunk, controller) {
273
308
  try {
@@ -280,11 +315,13 @@ export class Workflow extends BaseResource {
280
315
  // Process each chunk
281
316
  for (const chunk of chunks) {
282
317
  if (chunk) {
318
+ const newChunk: string = failedChunk ? failedChunk + chunk : chunk;
283
319
  try {
284
- const parsedChunk = JSON.parse(chunk);
320
+ const parsedChunk = JSON.parse(newChunk);
285
321
  controller.enqueue(parsedChunk);
286
- } catch {
287
- // Silently ignore parsing errors
322
+ failedChunk = undefined;
323
+ } catch (error) {
324
+ failedChunk = newChunk;
288
325
  }
289
326
  }
290
327
  }
package/src/types.ts CHANGED
@@ -7,12 +7,16 @@ import type {
7
7
  WorkflowRuns,
8
8
  WorkflowRun,
9
9
  LegacyWorkflowRuns,
10
+ StorageGetMessagesArg,
11
+ PaginationInfo,
12
+ MastraMessageV2,
10
13
  } from '@mastra/core';
11
- import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
14
+ import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput, UIMessageWithMetadata } from '@mastra/core/agent';
12
15
  import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
13
16
 
14
17
  import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
15
18
  import type { RuntimeContext } from '@mastra/core/runtime-context';
19
+ import type { MastraScorer, MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
16
20
  import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
17
21
  import type {
18
22
  StepAction,
@@ -34,6 +38,7 @@ export interface ClientOptions {
34
38
  /** Custom headers to include with requests */
35
39
  headers?: Record<string, string>;
36
40
  /** Abort signal for request */
41
+ abortSignal?: AbortSignal;
37
42
  }
38
43
 
39
44
  export interface RequestOptions {
@@ -41,7 +46,6 @@ export interface RequestOptions {
41
46
  headers?: Record<string, string>;
42
47
  body?: any;
43
48
  stream?: boolean;
44
- signal?: AbortSignal;
45
49
  }
46
50
 
47
51
  type WithoutMethods<T> = {
@@ -66,20 +70,24 @@ export interface GetAgentResponse {
66
70
  }
67
71
 
68
72
  export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
69
- messages: string | string[] | CoreMessage[] | AiMessageType[];
73
+ messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
70
74
  output?: T;
71
75
  experimental_output?: T;
72
76
  runtimeContext?: RuntimeContext | Record<string, any>;
73
77
  clientTools?: ToolsInput;
74
- } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
78
+ } & WithoutMethods<
79
+ Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
80
+ >;
75
81
 
76
82
  export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
77
- messages: string | string[] | CoreMessage[] | AiMessageType[];
83
+ messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
78
84
  output?: T;
79
85
  experimental_output?: T;
80
86
  runtimeContext?: RuntimeContext | Record<string, any>;
81
87
  clientTools?: ToolsInput;
82
- } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
88
+ } & WithoutMethods<
89
+ Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
90
+ >;
83
91
 
84
92
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
85
93
  evals: any[];
@@ -140,6 +148,17 @@ export interface GetWorkflowResponse {
140
148
  suspendSchema: string;
141
149
  };
142
150
  };
151
+ allSteps: {
152
+ [key: string]: {
153
+ id: string;
154
+ description: string;
155
+ inputSchema: string;
156
+ outputSchema: string;
157
+ resumeSchema: string;
158
+ suspendSchema: string;
159
+ isWorkflow: boolean;
160
+ };
161
+ };
143
162
  stepGraph: Workflow['serializedStepGraph'];
144
163
  inputSchema: string;
145
164
  outputSchema: string;
@@ -179,11 +198,16 @@ export interface GetVectorIndexResponse {
179
198
  }
180
199
 
181
200
  export interface SaveMessageToMemoryParams {
182
- messages: MastraMessageV1[];
201
+ messages: (MastraMessageV1 | MastraMessageV2)[];
183
202
  agentId: string;
184
203
  }
185
204
 
186
- export type SaveMessageToMemoryResponse = MastraMessageV1[];
205
+ export interface SaveNetworkMessageToMemoryParams {
206
+ messages: (MastraMessageV1 | MastraMessageV2)[];
207
+ networkId: string;
208
+ }
209
+
210
+ export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
187
211
 
188
212
  export interface CreateMemoryThreadParams {
189
213
  title?: string;
@@ -193,6 +217,14 @@ export interface CreateMemoryThreadParams {
193
217
  agentId: string;
194
218
  }
195
219
 
220
+ export interface CreateNetworkMemoryThreadParams {
221
+ title?: string;
222
+ metadata?: Record<string, any>;
223
+ resourceId: string;
224
+ threadId?: string;
225
+ networkId: string;
226
+ }
227
+
196
228
  export type CreateMemoryThreadResponse = StorageThreadType;
197
229
 
198
230
  export interface GetMemoryThreadParams {
@@ -200,6 +232,11 @@ export interface GetMemoryThreadParams {
200
232
  agentId: string;
201
233
  }
202
234
 
235
+ export interface GetNetworkMemoryThreadParams {
236
+ resourceId: string;
237
+ networkId: string;
238
+ }
239
+
203
240
  export type GetMemoryThreadResponse = StorageThreadType[];
204
241
 
205
242
  export interface UpdateMemoryThreadParams {
@@ -215,11 +252,17 @@ export interface GetMemoryThreadMessagesParams {
215
252
  limit?: number;
216
253
  }
217
254
 
255
+ export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
256
+
218
257
  export interface GetMemoryThreadMessagesResponse {
219
258
  messages: CoreMessage[];
220
259
  uiMessages: AiMessageType[];
221
260
  }
222
261
 
262
+ export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
263
+ messages: MastraMessageV1[] | MastraMessageV2[];
264
+ };
265
+
223
266
  export interface GetLogsParams {
224
267
  transportId: string;
225
268
  fromDate?: Date;
@@ -306,6 +349,7 @@ export interface GetTelemetryParams {
306
349
  }
307
350
 
308
351
  export interface GetNetworkResponse {
352
+ id: string;
309
353
  name: string;
310
354
  instructions: string;
311
355
  agents: Array<{
@@ -320,6 +364,71 @@ export interface GetNetworkResponse {
320
364
  state?: Record<string, any>;
321
365
  }
322
366
 
367
+ export interface GetVNextNetworkResponse {
368
+ id: string;
369
+ name: string;
370
+ instructions: string;
371
+ agents: Array<{
372
+ name: string;
373
+ provider: string;
374
+ modelId: string;
375
+ }>;
376
+ routingModel: {
377
+ provider: string;
378
+ modelId: string;
379
+ };
380
+ workflows: Array<{
381
+ name: string;
382
+ description: string;
383
+ inputSchema: string | undefined;
384
+ outputSchema: string | undefined;
385
+ }>;
386
+ tools: Array<{
387
+ id: string;
388
+ description: string;
389
+ }>;
390
+ }
391
+
392
+ export interface GenerateVNextNetworkResponse {
393
+ task: string;
394
+ result: string;
395
+ resourceId: string;
396
+ resourceType: 'none' | 'tool' | 'agent' | 'workflow';
397
+ }
398
+
399
+ export interface GenerateOrStreamVNextNetworkParams {
400
+ message: string;
401
+ threadId?: string;
402
+ resourceId?: string;
403
+ runtimeContext?: RuntimeContext | Record<string, any>;
404
+ }
405
+
406
+ export interface LoopStreamVNextNetworkParams {
407
+ message: string;
408
+ threadId?: string;
409
+ resourceId?: string;
410
+ maxIterations?: number;
411
+ runtimeContext?: RuntimeContext | Record<string, any>;
412
+ }
413
+
414
+ export interface LoopVNextNetworkResponse {
415
+ status: 'success';
416
+ result: {
417
+ task: string;
418
+ resourceId: string;
419
+ resourceType: 'agent' | 'workflow' | 'none' | 'tool';
420
+ result: string;
421
+ iteration: number;
422
+ isOneOff: boolean;
423
+ prompt: string;
424
+ threadId?: string | undefined;
425
+ threadResourceId?: string | undefined;
426
+ isComplete?: boolean | undefined;
427
+ completionReason?: string | undefined;
428
+ };
429
+ steps: WorkflowResult<any, any>['steps'];
430
+ }
431
+
323
432
  export interface McpServerListResponse {
324
433
  servers: ServerInfo[];
325
434
  next: string | null;
@@ -337,3 +446,57 @@ export interface McpToolInfo {
337
446
  export interface McpServerToolListResponse {
338
447
  tools: McpToolInfo[];
339
448
  }
449
+
450
+ export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
451
+ createdAt: string;
452
+ updatedAt: string;
453
+ };
454
+
455
+ // Scores-related types
456
+ export interface GetScoresByRunIdParams {
457
+ runId: string;
458
+ page?: number;
459
+ perPage?: number;
460
+ }
461
+
462
+ export interface GetScoresByScorerIdParams {
463
+ scorerId: string;
464
+ entityId?: string;
465
+ entityType?: string;
466
+ page?: number;
467
+ perPage?: number;
468
+ }
469
+
470
+ export interface GetScoresByEntityIdParams {
471
+ entityId: string;
472
+ entityType: string;
473
+ page?: number;
474
+ perPage?: number;
475
+ }
476
+
477
+ export interface SaveScoreParams {
478
+ score: Omit<ScoreRowData, 'id' | 'createdAt' | 'updatedAt'>;
479
+ }
480
+
481
+ export interface GetScoresResponse {
482
+ pagination: {
483
+ total: number;
484
+ page: number;
485
+ perPage: number;
486
+ hasMore: boolean;
487
+ };
488
+ scores: ClientScoreRowData[];
489
+ }
490
+
491
+ export interface SaveScoreResponse {
492
+ score: ClientScoreRowData;
493
+ }
494
+
495
+ export type GetScorerResponse = MastraScorerEntry & {
496
+ agentIds: string[];
497
+ workflowIds: string[];
498
+ };
499
+
500
+ export interface GetScorersResponse {
501
+ scorers: Array<GetScorerResponse>;
502
+ }
@@ -1,7 +1,8 @@
1
- import { isVercelTool } from '@mastra/core/tools';
1
+ import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
2
2
  import { zodToJsonSchema } from './zod-to-json-schema';
3
+ import type { ToolsInput } from '@mastra/core/agent';
3
4
 
4
- export function processClientTools(clientTools: Record<string, any> | undefined): Record<string, any> | undefined {
5
+ export function processClientTools(clientTools: ToolsInput | undefined): ToolsInput | undefined {
5
6
  if (!clientTools) {
6
7
  return undefined;
7
8
  }
@@ -27,5 +28,5 @@ export function processClientTools(clientTools: Record<string, any> | undefined)
27
28
  ];
28
29
  }
29
30
  }),
30
- ) as Record<string, any>;
31
+ );
31
32
  }
@@ -1,10 +1,27 @@
1
- import { ZodSchema } from 'zod';
1
+ import { z, type ZodType } from 'zod';
2
2
  import originalZodToJsonSchema from 'zod-to-json-schema';
3
3
 
4
- export function zodToJsonSchema<T extends ZodSchema | any>(zodSchema: T) {
5
- if (!(zodSchema instanceof ZodSchema)) {
4
+ function isZodType(value: unknown): value is ZodType {
5
+ // Check if it's a Zod schema by looking for common Zod properties and methods
6
+ return (
7
+ typeof value === 'object' &&
8
+ value !== null &&
9
+ '_def' in value &&
10
+ 'parse' in value &&
11
+ typeof (value as any).parse === 'function' &&
12
+ 'safeParse' in value &&
13
+ typeof (value as any).safeParse === 'function'
14
+ );
15
+ }
16
+
17
+ export function zodToJsonSchema<T extends ZodType | any>(zodSchema: T) {
18
+ if (!isZodType(zodSchema)) {
6
19
  return zodSchema;
7
20
  }
8
21
 
22
+ if ('toJSONSchema' in z) {
23
+ return z.toJSONSchema(zodSchema);
24
+ }
25
+
9
26
  return originalZodToJsonSchema(zodSchema, { $refStrategy: 'none' });
10
27
  }