🧩 fix: additionalProperties Handling and Ref Resolution in Zod Schemas (#8381)

* fix: false flagging object as empty object when it has `additionalProperties` field

* 🔧 fix: Implement $ref resolution in JSON Schema handling

* 🔧 fix: Resolve JSON Schema references before conversion to Zod

* chore: move zod logic packages/api
This commit is contained in:
Danny Avila 2025-07-10 18:02:34 -04:00 committed by GitHub
parent 8ca4cf3d2f
commit 4bbdc4c402
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 518 additions and 33 deletions

View file

@ -2,16 +2,17 @@ const { z } = require('zod');
const { tool } = require('@langchain/core/tools');
const { logger } = require('@librechat/data-schemas');
const { Time, CacheKeys, StepTypes } = require('librechat-data-provider');
const { sendEvent, normalizeServerName, MCPOAuthHandler } = require('@librechat/api');
const { Constants: AgentConstants, Providers, GraphEvents } = require('@librechat/agents');
const { Constants, ContentTypes, isAssistantsEndpoint } = require('librechat-data-provider');
const {
Constants,
ContentTypes,
isAssistantsEndpoint,
sendEvent,
MCPOAuthHandler,
normalizeServerName,
resolveJsonSchemaRefs,
convertJsonSchemaToZod,
} = require('librechat-data-provider');
const { getMCPManager, getFlowStateManager } = require('~/config');
} = require('@librechat/api');
const { findToken, createToken, updateToken } = require('~/models');
const { getMCPManager, getFlowStateManager } = require('~/config');
const { getCachedTools } = require('./Config');
const { getLogStores } = require('~/cache');
@ -113,7 +114,8 @@ async function createMCPTool({ req, res, toolKey, provider: _provider }) {
/** @type {LCTool} */
const { description, parameters } = toolDefinition;
const isGoogle = _provider === Providers.VERTEXAI || _provider === Providers.GOOGLE;
let schema = convertJsonSchemaToZod(parameters, {
const resolvedJsonSchema = resolveJsonSchemaRefs(parameters);
let schema = convertJsonSchemaToZod(resolvedJsonSchema, {
allowEmptyObject: !isGoogle,
transformOneOfAnyOf: true,
});