fix(core): preserve invalid schema length strings (#5312)

This commit is contained in:
tt-a1i 2026-06-19 04:21:00 +08:00 committed by GitHub
parent 41efcf0ff6
commit 5a73dcfc84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 2 deletions

View file

@ -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<string, unknown>;
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',

View file

@ -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;
}