{"version":3,"file":"plugin.cjs","names":["withLangGraph","z3","zd"],"sources":["../../../src/graph/zod/plugin.ts"],"sourcesContent":["import { z as zd } from \"zod\";\nimport { z as z3 } from \"zod/v3\";\nimport { getInteropZodDefaultGetter } from \"@langchain/core/utils/types\";\nimport { SchemaMeta, withLangGraph } from \"./meta.js\";\n\nconst metaSymbol = Symbol.for(\"langgraph-zod\");\n\ninterface ZodLangGraphTypes<T extends zd.ZodTypeAny, Output> {\n  reducer<Input = zd.output<T>>(\n    transform: (a: Output, arg: Input) => Output,\n    options?: zd.ZodType<Input>\n  ): zd.ZodType<Output, zd.ZodEffectsDef<T>, Input>;\n\n  metadata(payload: {\n    langgraph_nodes?: string[];\n    langgraph_type?: \"prompt\";\n\n    [key: string]: unknown;\n  }): T;\n}\n\ndeclare module \"zod\" {\n  interface ZodType<Output> {\n    /**\n     * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n     * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n     */\n    langgraph: ZodLangGraphTypes<this, Output>;\n  }\n}\n\ndeclare module \"zod/v3\" {\n  interface ZodType<Output> {\n    /**\n     * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n     * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n     */\n    langgraph: ZodLangGraphTypes<this, Output>;\n  }\n}\n\ninterface PluginGlobalType {\n  [metaSymbol]?: WeakSet<object>;\n}\n\nif (!(metaSymbol in globalThis)) {\n  (globalThis as PluginGlobalType)[metaSymbol] = new WeakSet();\n}\n\nfunction applyPluginPrototype<\n  PrototypeToExtend extends\n    | typeof zd.ZodType.prototype\n    | typeof z3.ZodType.prototype\n>(prototype: PrototypeToExtend) {\n  const cache = (globalThis as PluginGlobalType)[metaSymbol]!;\n  if (cache.has(prototype)) {\n    return; // Already applied\n  }\n\n  Object.defineProperty(\n    prototype,\n    \"langgraph\" satisfies keyof PrototypeToExtend,\n    {\n      get(): zd.ZodType[\"langgraph\"] {\n        // Return type is any, actual type provided by module augmentation\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any\n        const zodThis = this as zd.ZodTypeAny;\n        type Output = zd.infer<typeof zodThis>;\n\n        return {\n          metadata(\n            jsonSchemaExtra: SchemaMeta<Output, Output>[\"jsonSchemaExtra\"]\n          ) {\n            return withLangGraph(zodThis, { jsonSchemaExtra });\n          },\n          reducer<Input>(\n            fn: (a: Output, arg: Input) => Output,\n            schema?: zd.ZodType<Input>\n          ) {\n            const defaultFn = getInteropZodDefaultGetter(zodThis);\n            return withLangGraph(zodThis, {\n              default: defaultFn,\n              reducer: { schema, fn },\n            });\n          },\n        };\n      },\n    }\n  );\n  cache.add(prototype);\n}\n\ntry {\n  applyPluginPrototype(z3.ZodType.prototype);\n  applyPluginPrototype(zd.ZodType.prototype);\n} catch (error) {\n  throw new Error(\n    \"Failed to extend Zod with LangGraph-related methods. This is most likely a bug, consider opening an issue and/or using `withLangGraph` to augment your Zod schema.\",\n    { cause: error }\n  );\n}\n"],"mappings":";;;;;;;AAKA,MAAM,aAAa,OAAO,IAAI;AAwC9B,IAAI,EAAE,cAAc,YAClB,CAAC,WAAgC,8BAAc,IAAI;AAGrD,SAAS,qBAIP,WAA8B;CAC9B,MAAM,QAAS,WAAgC;AAC/C,KAAI,MAAM,IAAI,WACZ;AAGF,QAAO,eACL,WACA,aACA,EACE,MAA+B;EAG7B,MAAM,UAAU;AAGhB,SAAO;GACL,SACE,iBACA;AACA,WAAOA,2BAAc,SAAS,EAAE;;GAElC,QACE,IACA,QACA;IACA,MAAM,yEAAuC;AAC7C,WAAOA,2BAAc,SAAS;KAC5B,SAAS;KACT,SAAS;MAAE;MAAQ;;;;;;AAO/B,OAAM,IAAI;;AAGZ,IAAI;AACF,sBAAqBC,SAAG,QAAQ;AAChC,sBAAqBC,MAAG,QAAQ;SACzB,OAAO;AACd,OAAM,IAAI,MACR,sKACA,EAAE,OAAO"}