🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(model-runtime): filter null values from enum for Gemini compatibility (#11859)
Arvin Xu1163f71f393f
diff --git a/packages/model-runtime/src/core/contextBuilders/google.test.ts b/packages/model-runtime/src/core/contextBuilders/google.test.tsindex 7d2a80dd9a6..fc285fa9012 100644--- a/packages/model-runtime/src/core/contextBuilders/google.test.ts+++ b/packages/model-runtime/src/core/contextBuilders/google.test.ts@@ -1154,6 +1154,79 @@ describe('google contextBuilders', () => {type: 'string',});});++ it('should filter null values from enum arrays for Google compatibility', () => {+ const tool: ChatCompletionTool = {+ function: {+ description: 'A tool with enum containing null',+ name: 'enumTool',+ parameters: {+ properties: {+ memoryType: {+ enum: ['short_term', 'long_term', null, 'working'],+ type: 'string',+ },+ nested: {+ properties: {+ status: {+ enum: [null, 'active', 'inactive', null],+ type: 'string',+ },+ },+ type: 'object',+ },+ },+ type: 'object',+ },+ },+ type: 'function',+ };++ const result = buildGoogleTool(tool);++ // null values should be filtered from enum arrays+ expect(result.parameters?.properties).toEqual({+ memoryType: {+ enum: ['short_term', 'long_term', 'working'],+ type: 'string',+ },+ nested: {+ properties: {+ status: {+ enum: ['active', 'inactive'],+ type: 'string',+ },+ },+ type: 'object',+ },+ });+ });++ it('should handle enum with only null values', () => {+ const tool: ChatCompletionTool = {+ function: {+ description: 'A tool with enum containing only null',+ name: 'nullEnumTool',+ parameters: {+ properties: {+ value: {+ enum: [null],+ type: 'string',+ },+ },+ type: 'object',+ },+ },+ type: 'function',+ };++ const result = buildGoogleTool(tool);++ // When enum only contains null, the enum property should be removed+ expect(result.parameters?.properties?.value).toEqual({+ type: 'string',+ });+ });});describe('buildGoogleTools', () => {diff --git a/packages/model-runtime/src/core/contextBuilders/google.ts b/packages/model-runtime/src/core/contextBuilders/google.tsindex 8e174a9cdaf..8e6a2f0d9a1 100644--- a/packages/model-runtime/src/core/contextBuilders/google.ts+++ b/packages/model-runtime/src/core/contextBuilders/google.ts@@ -248,6 +248,16 @@ const sanitizeSchemaForGoogle = (schema: Record<string, any>): Record<string, ancontinue;}+ // Filter null values from enum arrays (Google doesn't support null in enum)+ if (key === 'enum' && Array.isArray(value)) {+ const filteredEnum = value.filter((item) => item !== null);+ // Only set enum if there are remaining values after filtering+ if (filteredEnum.length > 0) {+ result[key] = filteredEnum;+ }+ continue;+ }+// Recursively process nested objectsif (value && typeof value === 'object') {result[key] = sanitizeSchemaForGoogle(value);