🤯 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): strip additionalProperties and leftover $ref in Google tool schemas (#13613)
Arvin Xuca013856667a
diff --git a/packages/model-runtime/src/core/contextBuilders/google.test.ts b/packages/model-runtime/src/core/contextBuilders/google.test.tsindex c3b58fef969..564bbfcaf30 100644--- a/packages/model-runtime/src/core/contextBuilders/google.test.ts+++ b/packages/model-runtime/src/core/contextBuilders/google.test.ts@@ -1406,7 +1406,6 @@ describe('google contextBuilders', () => {expect(result.parameters?.properties).toEqual({query: { type: 'string' },timeIntent: {- additionalProperties: false,properties: {selector: { enum: ['today', 'yesterday', 'month'], type: 'string' },date: { format: 'date-time', type: 'string' },@@ -1545,6 +1544,77 @@ describe('google contextBuilders', () => {field: { description: 'some field' },});});++ it('should strip additionalProperties from schemas', () => {+ const tool: ChatCompletionTool = {+ function: {+ description: 'A tool with additionalProperties',+ name: 'apTool',+ parameters: {+ properties: {+ config: {+ additionalProperties: false,+ properties: {+ nested: {+ additionalProperties: { type: 'string' },+ type: 'object',+ },+ },+ type: 'object',+ },+ },+ type: 'object',+ },+ },+ type: 'function',+ };++ const result = buildGoogleTool(tool);++ expect(result.parameters?.properties).toEqual({+ config: {+ properties: {+ nested: {+ type: 'object',+ },+ },+ type: 'object',+ },+ });+ });++ it('should strip remaining $ref when resolveRefs exceeds depth limit', () => {+ // Build a deeply recursive schema that exceeds depth limit of 10+ const tool: ChatCompletionTool = {+ function: {+ description: 'A tool with deep recursive $ref',+ name: 'deepRefTool',+ parameters: {+ definitions: {+ node: {+ properties: {+ child: { oneOf: [{ type: 'string' }, { $ref: '#/definitions/node' }] },+ },+ type: 'object',+ },+ },+ properties: {+ root: { $ref: '#/definitions/node' },+ },+ type: 'object',+ },+ },+ type: 'function',+ };++ const result = buildGoogleTool(tool);++ // Verify no $ref remains anywhere in the output+ const json = JSON.stringify(result);+ expect(json).not.toContain('"$ref"');+ // Also verify no additionalProperties+ expect(json).not.toContain('"additionalProperties"');+ });});describe('buildGoogleTools', () => {diff --git a/packages/model-runtime/src/core/contextBuilders/google.ts b/packages/model-runtime/src/core/contextBuilders/google.tsindex b3abd2d9729..2372adda55c 100644--- a/packages/model-runtime/src/core/contextBuilders/google.ts+++ b/packages/model-runtime/src/core/contextBuilders/google.ts@@ -252,7 +252,7 @@ export const buildGoogleMessages = async (messages: OpenAIChatMessage[]): Promis* JSON Schema keywords that cause Google GenAI / Vertex AI SDK validation errors.* Other unsupported keywords are silently ignored by the API, so only strip these.*/-const UNSUPPORTED_SCHEMA_KEYS = new Set(['examples', 'default']);+const UNSUPPORTED_SCHEMA_KEYS = new Set(['examples', 'default', 'additionalProperties', '$ref']);/*** Resolve all `$ref` pointers in a JSON Schema tree by inlining definitions.