perf(types): keep default-heap Node 24 typecheck under the heap limit (#2414)

* fix(types): narrow SDK response schema consumers

* perf(types): bound mixed Zod schema comparisons
This commit is contained in:
JATMN
2026-10-24 18:59:07 -07:00
committed by GitHub
parent 5f91412177
commit fd596210f1
2 changed files with 11 additions and 4 deletions
+4 -3
View File
@@ -134,7 +134,8 @@ function buildRequiresActionDetails(
type PendingRequest<T> = {
resolve: (result: T) => void
reject: (error: unknown) => void
schema?: z.Schema
// Response consumers only parse; avoid comparing Zod's fluent builder types.
schema?: Pick<z.Schema, 'parse'>
request: SDKControlRequest
}
@@ -496,7 +497,7 @@ export class StructuredIO {
private async sendRequest<Response>(
request: SDKControlRequest['request'],
schema: z.Schema,
schema: Pick<z.Schema, 'parse'>,
signal?: AbortSignal,
requestId: string = randomUUID(),
): Promise<Response> {
@@ -798,7 +799,7 @@ export class StructuredIO {
message,
},
z.object({
mcp_response: z.any() as z.Schema<JSONRPCMessage>,
mcp_response: z.any() as z.core.$ZodType<JSONRPCMessage>,
}),
)
return response.mcp_response
+7 -1
View File
@@ -1,6 +1,7 @@
import { describe, expect, test } from 'bun:test'
import { zodOutputFormat } from '@anthropic-ai/sdk/helpers/zod'
import { SandboxRuntimeConfigSchema } from '@anthropic-ai/sandbox-runtime'
import type { AnySchema } from '@modelcontextprotocol/sdk/server/zod-compat.js'
import { parseWithCompat, toJsonSchemaCompat } from '@modelcontextprotocol/sdk/server/zod-json-schema-compat.js'
import { z as legacy } from 'zod/v3'
import { z } from 'zod/v4'
@@ -14,7 +15,12 @@ describe('dependency schema compatibility', () => {
})
test('the protocol converter and parser support both packaged schema generations', () => {
for (const schema of [z.strictObject({ value: z.string() }), legacy.object({ value: legacy.string() }).strict()]) {
// Avoid finding a common type by comparing both versions' fluent builders.
const schemas: AnySchema[] = [
z.strictObject({ value: z.string() }),
legacy.object({ value: legacy.string() }).strict(),
]
for (const schema of schemas) {
expect(toJsonSchemaCompat(schema).type).toBe('object')
expect(parseWithCompat(schema, { value: 'ok' })).toEqual({ value: 'ok' })
expect(() => parseWithCompat(schema, { value: 1 })).toThrow()