UNPKG

langchain

Version:
45 lines (43 loc) 1.97 kB
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs'); const __langchain_langgraph = require_rolldown_runtime.__toESM(require("@langchain/langgraph")); const zod_v3 = require_rolldown_runtime.__toESM(require("zod/v3")); const __langchain_langgraph_zod = require_rolldown_runtime.__toESM(require("@langchain/langgraph/zod")); //#region src/agents/annotation.ts function createAgentAnnotationConditional(hasStructuredResponse = true, stateSchema, middlewareList = []) { /** * Create Zod schema object to preserve jsonSchemaExtra * metadata for LangGraph Studio using v3-compatible withLangGraph */ const zodSchema = { messages: (0, __langchain_langgraph_zod.withLangGraph)(zod_v3.z.custom(), __langchain_langgraph.MessagesZodMeta), jumpTo: zod_v3.z.union([ zod_v3.z.literal("model_request"), zod_v3.z.literal("tools"), zod_v3.z.undefined() ]).optional() }; const applySchema = (schema) => { const { shape } = schema; for (const [key, schema$1] of Object.entries(shape)) { /** * Skip private state properties */ if (key.startsWith("_")) continue; if (!(key in zodSchema)) zodSchema[key] = schema$1; } }; if (stateSchema && "shape" in stateSchema) applySchema(stateSchema); for (const middleware of middlewareList) if (middleware.stateSchema) applySchema(middleware.stateSchema); if (hasStructuredResponse) zodSchema.structuredResponse = zod_v3.z.any().optional(); return zod_v3.z.object(zodSchema); } const PreHookAnnotation = zod_v3.z.object({ llmInputMessages: (0, __langchain_langgraph_zod.withLangGraph)(zod_v3.z.custom(), { reducer: { fn: (_x, update) => __langchain_langgraph.MessagesZodMeta.reducer.fn([], update) }, default: () => [] }), messages: (0, __langchain_langgraph_zod.withLangGraph)(zod_v3.z.custom(), __langchain_langgraph.MessagesZodMeta) }); //#endregion exports.createAgentAnnotationConditional = createAgentAnnotationConditional; //# sourceMappingURL=annotation.cjs.map