Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion libs/langgraph/src/graph/zod/zod-registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// @ts-expect-error If zod/v4 is not imported, the module augmentation will fail in build
import type { ZodType } from "zod/v4"; // eslint-disable-line @typescript-eslint/no-unused-vars
import type * as core from "zod/v4/core";
import { getInteropZodDefaultGetter } from "@langchain/core/utils/types";
import { $ZodType, $ZodRegistry, $replace } from "zod/v4/core";
import { SchemaMeta, SchemaMetaRegistry, schemaMetaRegistry } from "./meta.js";
import {
type ReducedZodChannel,
type SchemaMeta,
type SchemaMetaRegistry,
schemaMetaRegistry,
} from "./meta.js";

/**
* A Zod v4-compatible meta registry that extends the base registry.
Expand Down Expand Up @@ -46,4 +54,30 @@ export class LanggraphZodMetaRegistry<
}
}

// Augment the zod/v4 module nudging the `register` method
// to use the user provided input schema if specified.
declare module "zod/v4" {
export interface ZodType<
out Output = unknown,
out Input = unknown,
out Internals extends core.$ZodTypeInternals<
Output,
Input
> = core.$ZodTypeInternals<Output, Input>
> extends core.$ZodType<Output, Input, Internals> {
register<
R extends LanggraphZodMetaRegistry,
TOutput = core.output<this>,
TInput = core.input<this>,
TInternals extends core.$ZodTypeInternals<
TOutput,
TInput
> = core.$ZodTypeInternals<TOutput, TInput>
>(
registry: R,
meta: SchemaMeta<TOutput, TInput>
): ReducedZodChannel<this, ZodType<TOutput, TInput, TInternals>>;
}
}

export const registry = new LanggraphZodMetaRegistry(schemaMetaRegistry);