From e089cc2dacdd9b9b84aa7b5382932fbb2b90f761 Mon Sep 17 00:00:00 2001 From: tt-a1i <53142663+tt-a1i@users.noreply.github.com> Date: Thu, 18 Jun 2026 18:43:54 +0800 Subject: [PATCH] fix(core): preserve invalid schema length strings --- .../openaiContentGenerator/converter.test.ts | 32 +++++++++++++++++++ .../core/openaiContentGenerator/converter.ts | 9 ++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/core/src/core/openaiContentGenerator/converter.test.ts b/packages/core/src/core/openaiContentGenerator/converter.test.ts index cb661c10d3d..9c0193db1a5 100644 --- a/packages/core/src/core/openaiContentGenerator/converter.test.ts +++ b/packages/core/src/core/openaiContentGenerator/converter.test.ts @@ -4186,6 +4186,38 @@ describe('OpenAIContentConverter', () => { }); }); + it('should not truncate non-integer length constraints', () => { + const params = { + type: 'object', + properties: { + text: { + type: 'string', + minLength: '1.5', + maxLength: ' ', + }, + items: { + type: 'array', + minItems: '10px', + maxItems: '1.5', + }, + }, + }; + + const result = converter.convertGeminiToolParametersToOpenAI(params); + const properties = result?.['properties'] as Record; + + expect(properties?.['text']).toEqual({ + type: 'string', + minLength: '1.5', + maxLength: ' ', + }); + expect(properties?.['items']).toEqual({ + type: 'array', + minItems: '10px', + maxItems: '1.5', + }); + }); + it('should handle nested objects', () => { const params = { type: 'object', diff --git a/packages/core/src/core/openaiContentGenerator/converter.ts b/packages/core/src/core/openaiContentGenerator/converter.ts index 877ebf0148d..9c75d8e6b08 100644 --- a/packages/core/src/core/openaiContentGenerator/converter.ts +++ b/packages/core/src/core/openaiContentGenerator/converter.ts @@ -285,8 +285,13 @@ export function convertGeminiToolParametersToOpenAI( key === 'maxItems' ) { // Ensure length constraints are integers, not strings - if (typeof value === 'string' && !isNaN(Number(value))) { - result[key] = parseInt(value, 10); + const numberValue = typeof value === 'string' ? Number(value) : NaN; + if ( + typeof value === 'string' && + value.trim() !== '' && + Number.isInteger(numberValue) + ) { + result[key] = numberValue; } else { result[key] = value; }