Skip to content

Commit d3930ea

Browse files
epinzurwardpeetMastra Code (openai/gpt-5.4)
authored
drop support for zod/v3 in several core packages (#14464)
Co-authored-by: wardpeet <ward@coding-tech.com> Co-authored-by: Mastra Code (openai/gpt-5.4) <noreply@mastra.ai>
1 parent 23bd359 commit d3930ea

195 files changed

Lines changed: 447 additions & 797 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/ten-friends-like.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@mastra/client-js': patch
3+
'@mastra/ai-sdk': patch
4+
'@mastra/react': patch
5+
'@mastra/server': patch
6+
'@mastra/core': patch
7+
'@mastra/schema-compat': patch
8+
---
9+
10+
Fix Zod v3 and Zod v4 compatibility across public structured-output APIs.
11+
12+
Mastra agent and client APIs accept schemas from either `zod/v3` or `zod/v4`, matching the documented peer dependency range and preserving TypeScript compatibility for both Zod versions.

client-sdks/ai-sdk/src/__tests__/add-tool-result-message-id.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Mastra } from '@mastra/core/mastra';
2323
import { createTool } from '@mastra/core/tools';
2424
import { convertArrayToReadableStream, MockLanguageModelV2 } from 'ai/test';
2525
import { describe, expect, it } from 'vitest';
26-
import { z } from 'zod';
26+
import { z } from 'zod/v4';
2727

2828
import { handleChatStream } from '../chat-route';
2929

client-sdks/ai-sdk/src/convert-streams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from '@internal/ai-v6';
1111
import type { MastraModelOutput, ChunkType, MastraAgentNetworkStream, WorkflowRunOutput } from '@mastra/core/stream';
1212
import type { MastraWorkflowStream, Step, WorkflowResult } from '@mastra/core/workflows';
13-
import type { ZodObject, ZodType } from 'zod';
13+
import type { ZodObject, ZodType } from 'zod/v4';
1414
import type { V6UIMessageStream } from './public-types';
1515
import {
1616
AgentNetworkToAISDKTransformer,

client-sdks/client-js/src/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import z from 'zod';
1+
import { z } from 'zod/v4';
22
import { MastraClient } from './client';
33
// import type { WorkflowRunResult } from './types';
44

client-sdks/client-js/src/resources/agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ToolsInput } from '@mastra/core/agent';
22
import { RequestContext as RequestContextClass } from '@mastra/core/request-context';
33
import { createTool } from '@mastra/core/tools';
44
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
5-
import { z } from 'zod';
5+
import { z } from 'zod/v4';
66
import { MastraClient } from '../client';
77
import type { StreamParams, ClientOptions } from '../types';
88
import { zodToJsonSchema } from '../utils/zod-to-json-schema';

client-sdks/client-js/src/resources/agent.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import type { FullOutput, MastraModelOutput } from '@mastra/core/stream';
1818
import type { Tool } from '@mastra/core/tools';
1919
import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat/schema';
2020
import type { JSONSchema7 } from 'json-schema';
21-
import type { ZodType } from 'zod/v3';
2221
import type {
22+
ZodSchema,
2323
GenerateLegacyParams,
2424
GetAgentResponse,
2525
GetToolResponse,
@@ -237,15 +237,15 @@ export class Agent extends BaseResource {
237237
params: GenerateLegacyParams<undefined> & { output?: never; experimental_output?: never },
238238
): Promise<GenerateReturn<any, undefined, undefined>>;
239239
// Use `any` in overload return types to avoid "Type instantiation is excessively deep" errors
240-
async generateLegacy<Output extends JSONSchema7 | ZodType>(
240+
async generateLegacy<Output extends JSONSchema7 | ZodSchema>(
241241
params: GenerateLegacyParams<Output> & { output: Output; experimental_output?: never },
242242
): Promise<GenerateReturn<any, any, any>>;
243-
async generateLegacy<StructuredOutput extends JSONSchema7 | ZodType>(
243+
async generateLegacy<StructuredOutput extends JSONSchema7 | ZodSchema>(
244244
params: GenerateLegacyParams<StructuredOutput> & { output?: never; experimental_output: StructuredOutput },
245245
): Promise<GenerateReturn<any, any, any>>;
246246
async generateLegacy<
247-
Output extends JSONSchema7 | ZodType | undefined = undefined,
248-
_StructuredOutput extends JSONSchema7 | ZodType | undefined = undefined,
247+
Output extends JSONSchema7 | ZodSchema | undefined = undefined,
248+
_StructuredOutput extends JSONSchema7 | ZodSchema | undefined = undefined,
249249
>(params: GenerateLegacyParams<Output>): Promise<GenerateReturn<any, any, any>> {
250250
const processedParams = {
251251
...params,
@@ -726,7 +726,7 @@ export class Agent extends BaseResource {
726726
* @param params - Stream parameters including prompt
727727
* @returns Promise containing the enhanced Response object with processDataStream method
728728
*/
729-
async streamLegacy<T extends JSONSchema7 | ZodType | undefined = undefined>(
729+
async streamLegacy<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
730730
params: StreamLegacyParams<T>,
731731
): Promise<
732732
Response & {

client-sdks/client-js/src/resources/agent.vnext.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { APICallError } from '@internal/ai-sdk-v5';
22
import { getErrorFromUnknown } from '@mastra/core/error';
33
import { createTool } from '@mastra/core/tools';
44
import { describe, it, beforeEach, expect, vi } from 'vitest';
5-
import z from 'zod';
5+
import { z } from 'zod/v4';
66
import { MastraClient } from '../client';
77

88
// Mock fetch globally

client-sdks/client-js/src/tools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2-
import { z } from 'zod';
2+
import { z } from 'zod/v4';
33
import { createTool } from './tools';
44

55
describe('createTool', () => {

client-sdks/client-js/src/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ToolCallOptions } from '@internal/ai-sdk-v5';
2-
import type { z } from 'zod';
2+
import type { z } from 'zod/v4';
33

44
// Client-side tool execution context (simplified version without server dependencies)
55
export interface ClientToolExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined> {

client-sdks/client-js/src/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ import type {
4444
WorkflowRunStatus,
4545
WorkflowState,
4646
} from '@mastra/core/workflows';
47-
import type { PublicSchema } from '@mastra/schema-compat';
47+
import type { PublicSchema } from '@mastra/schema-compat/schema';
4848

4949
import type { JSONSchema7 } from 'json-schema';
50-
import type { ZodSchema } from 'zod/v3';
50+
import type { ZodSchema as ZodSchemaV3 } from 'zod/v3';
51+
import type { ZodType as ZodTypeV4 } from 'zod/v4';
52+
53+
export type ZodSchema = ZodSchemaV3 | ZodTypeV4;
5154

5255
export interface ClientOptions {
5356
/** Base URL for API requests */

0 commit comments

Comments
 (0)