{"version":3,"file":"schema.cjs","names":["schemaMetaRegistry"],"sources":["../../../src/graph/zod/schema.ts"],"sourcesContent":["import {\n  type JSONSchema,\n  toJsonSchema as interopToJsonSchema,\n} from \"@langchain/core/utils/json_schema\";\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport {\n  META_EXTRAS_DESCRIPTION_PREFIX,\n  SchemaMetaRegistry,\n  schemaMetaRegistry,\n} from \"./meta.js\";\n\nconst PartialStateSchema = Symbol.for(\"langgraph.state.partial\");\ntype PartialStateSchema = typeof PartialStateSchema;\n\ninterface GraphWithZodLike {\n  builder: {\n    _schemaRuntimeDefinition: InteropZodObject | undefined;\n    _inputRuntimeDefinition: InteropZodObject | PartialStateSchema | undefined;\n    _outputRuntimeDefinition: InteropZodObject | undefined;\n    _configRuntimeSchema: InteropZodObject | undefined;\n  };\n}\n\nfunction isGraphWithZodLike(graph: unknown): graph is GraphWithZodLike {\n  if (!graph || typeof graph !== \"object\") return false;\n  if (\n    !(\"builder\" in graph) ||\n    typeof graph.builder !== \"object\" ||\n    graph.builder == null\n  ) {\n    return false;\n  }\n  return true;\n}\n\nfunction applyJsonSchemaExtrasFromDescription<T>(schema: T): unknown {\n  if (Array.isArray(schema)) {\n    return schema.map(applyJsonSchemaExtrasFromDescription);\n  }\n  if (typeof schema === \"object\" && schema != null) {\n    const output = Object.fromEntries(\n      Object.entries(schema).map(([key, value]) => [\n        key,\n        applyJsonSchemaExtrasFromDescription(value),\n      ])\n    );\n\n    if (\n      \"description\" in output &&\n      typeof output.description === \"string\" &&\n      output.description.startsWith(META_EXTRAS_DESCRIPTION_PREFIX)\n    ) {\n      const strMeta = output.description.slice(\n        META_EXTRAS_DESCRIPTION_PREFIX.length\n      );\n      delete output.description;\n      Object.assign(output, JSON.parse(strMeta));\n    }\n\n    return output as T;\n  }\n  return schema;\n}\n\nfunction toJsonSchema(schema: InteropZodObject): JSONSchema {\n  return applyJsonSchemaExtrasFromDescription(\n    interopToJsonSchema(schema)\n  ) as JSONSchema;\n}\n\n/**\n * Get the state schema for a graph.\n * @param graph - The graph to get the state schema for.\n * @returns The state schema for the graph.\n */\nexport function getStateTypeSchema(\n  graph: unknown,\n  registry: SchemaMetaRegistry = schemaMetaRegistry\n): JSONSchema | undefined {\n  if (!isGraphWithZodLike(graph)) return undefined;\n  const schemaDef = graph.builder._schemaRuntimeDefinition;\n  if (!schemaDef) return undefined;\n\n  return toJsonSchema(\n    registry.getExtendedChannelSchemas(schemaDef, {\n      withJsonSchemaExtrasAsDescription: true,\n    })\n  );\n}\n\n/**\n * Get the update schema for a graph.\n * @param graph - The graph to get the update schema for.\n * @returns The update schema for the graph.\n */\nexport function getUpdateTypeSchema(\n  graph: unknown,\n  registry: SchemaMetaRegistry = schemaMetaRegistry\n): JSONSchema | undefined {\n  if (!isGraphWithZodLike(graph)) return undefined;\n  const schemaDef = graph.builder._schemaRuntimeDefinition;\n  if (!schemaDef) return undefined;\n\n  return toJsonSchema(\n    registry.getExtendedChannelSchemas(schemaDef, {\n      withReducerSchema: true,\n      withJsonSchemaExtrasAsDescription: true,\n      asPartial: true,\n    })\n  );\n}\n\n/**\n * Get the input schema for a graph.\n * @param graph - The graph to get the input schema for.\n * @returns The input schema for the graph.\n */\nexport function getInputTypeSchema(\n  graph: unknown,\n  registry: SchemaMetaRegistry = schemaMetaRegistry\n): JSONSchema | undefined {\n  if (!isGraphWithZodLike(graph)) return undefined;\n  let schemaDef = graph.builder._inputRuntimeDefinition;\n  if (schemaDef === PartialStateSchema) {\n    // No need to pass `.partial()` here, that's being done by `applyPlugin`\n    schemaDef = graph.builder._schemaRuntimeDefinition;\n  }\n  if (!schemaDef) return undefined;\n\n  return toJsonSchema(\n    registry.getExtendedChannelSchemas(schemaDef, {\n      withReducerSchema: true,\n      withJsonSchemaExtrasAsDescription: true,\n      asPartial: true,\n    })\n  );\n}\n\n/**\n * Get the output schema for a graph.\n * @param graph - The graph to get the output schema for.\n * @returns The output schema for the graph.\n */\nexport function getOutputTypeSchema(\n  graph: unknown,\n  registry: SchemaMetaRegistry = schemaMetaRegistry\n): JSONSchema | undefined {\n  if (!isGraphWithZodLike(graph)) return undefined;\n  const schemaDef = graph.builder._outputRuntimeDefinition;\n  if (!schemaDef) return undefined;\n\n  return toJsonSchema(\n    registry.getExtendedChannelSchemas(schemaDef, {\n      withJsonSchemaExtrasAsDescription: true,\n    })\n  );\n}\n\n/**\n * Get the config schema for a graph.\n * @param graph - The graph to get the config schema for.\n * @returns The config schema for the graph.\n */\nexport function getConfigTypeSchema(\n  graph: unknown,\n  registry: SchemaMetaRegistry = schemaMetaRegistry\n): JSONSchema | undefined {\n  if (!isGraphWithZodLike(graph)) return undefined;\n  const configDef = graph.builder._configRuntimeSchema;\n  if (!configDef) return undefined;\n\n  return toJsonSchema(\n    registry.getExtendedChannelSchemas(configDef, {\n      withJsonSchemaExtrasAsDescription: true,\n    })\n  );\n}\n"],"mappings":";;;;AAWA,MAAM,qBAAqB,OAAO,IAAI,0BAA0B;AAYhE,SAAS,mBAAmB,OAA2C;AACrE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,KACE,EAAE,aAAa,UACf,OAAO,MAAM,YAAY,YACzB,MAAM,WAAW,KAEjB,QAAO;AAET,QAAO;;AAGT,SAAS,qCAAwC,QAAoB;AACnE,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,qCAAqC;AAEzD,KAAI,OAAO,WAAW,YAAY,UAAU,MAAM;EAChD,MAAM,SAAS,OAAO,YACpB,OAAO,QAAQ,OAAO,CAAC,KAAK,CAAC,KAAK,WAAW,CAC3C,KACA,qCAAqC,MAAM,CAC5C,CAAC,CACH;AAED,MACE,iBAAiB,UACjB,OAAO,OAAO,gBAAgB,YAC9B,OAAO,YAAY,WAAA,MAA0C,EAC7D;GACA,MAAM,UAAU,OAAO,YAAY,MAAA,EAElC;AACD,UAAO,OAAO;AACd,UAAO,OAAO,QAAQ,KAAK,MAAM,QAAQ,CAAC;;AAG5C,SA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