@langchain/langgraph
Version:
LangGraph
101 lines • 3.5 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStateTypeSchema = getStateTypeSchema;
exports.getUpdateTypeSchema = getUpdateTypeSchema;
exports.getInputTypeSchema = getInputTypeSchema;
exports.getOutputTypeSchema = getOutputTypeSchema;
exports.getConfigTypeSchema = getConfigTypeSchema;
const zod_to_json_schema_1 = require("zod-to-json-schema");
const state_js_1 = require("./state.cjs");
const PartialStateSchema = Symbol.for("langgraph.state.partial");
function isGraphWithZodLike(graph) {
if (!graph || typeof graph !== "object")
return false;
if (!("builder" in graph) ||
typeof graph.builder !== "object" ||
graph.builder == null) {
return false;
}
return true;
}
function toJsonSchema(schema) {
return (0, state_js_1.applyExtraFromDescription)((0, zod_to_json_schema_1.zodToJsonSchema)(schema));
}
/**
* Get the state schema for a graph.
* @param graph - The graph to get the state schema for.
* @returns The state schema for the graph.
*/
function getStateTypeSchema(graph) {
if (!isGraphWithZodLike(graph))
return undefined;
const schemaDef = graph.builder._schemaRuntimeDefinition;
if (!schemaDef)
return undefined;
return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, { jsonSchemaExtra: true }));
}
/**
* Get the update schema for a graph.
* @param graph - The graph to get the update schema for.
* @returns The update schema for the graph.
*/
function getUpdateTypeSchema(graph) {
if (!isGraphWithZodLike(graph))
return undefined;
const schemaDef = graph.builder._schemaRuntimeDefinition;
if (!schemaDef)
return undefined;
return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, {
reducer: true,
jsonSchemaExtra: true,
partial: true,
}));
}
/**
* Get the input schema for a graph.
* @param graph - The graph to get the input schema for.
* @returns The input schema for the graph.
*/
function getInputTypeSchema(graph) {
if (!isGraphWithZodLike(graph))
return undefined;
let schemaDef = graph.builder._inputRuntimeDefinition;
if (schemaDef === PartialStateSchema) {
// No need to pass `.partial()` here, that's being done by `applyPlugin`
schemaDef = graph.builder._schemaRuntimeDefinition;
}
if (!schemaDef)
return undefined;
return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, {
reducer: true,
jsonSchemaExtra: true,
partial: true,
}));
}
/**
* Get the output schema for a graph.
* @param graph - The graph to get the output schema for.
* @returns The output schema for the graph.
*/
function getOutputTypeSchema(graph) {
if (!isGraphWithZodLike(graph))
return undefined;
const schemaDef = graph.builder._outputRuntimeDefinition;
if (!schemaDef)
return undefined;
return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, { jsonSchemaExtra: true }));
}
/**
* Get the config schema for a graph.
* @param graph - The graph to get the config schema for.
* @returns The config schema for the graph.
*/
function getConfigTypeSchema(graph) {
if (!isGraphWithZodLike(graph))
return undefined;
const configDef = graph.builder._configRuntimeSchema;
if (!configDef)
return undefined;
return toJsonSchema((0, state_js_1.applyZodPlugin)(configDef, { jsonSchemaExtra: true }));
}
//# sourceMappingURL=schema.js.map
;