fix: 为缺少 required 字段的 object schema 注入空数组以兼容 Qwen

Qwen 校验器要求每个 object schema 必须有 required 字段,缺失时报错
"None is not of type 'array'"。在 sanitizeJsonSchema 中补充处理逻辑,
当 object schema 不含 required 键时自动注入 required: []。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Askhz 2026-04-23 20:16:57 +08:00
parent 4e750966a8
commit 278d5dfb6c

View File

@ -48,6 +48,15 @@ function sanitizeJsonSchema(schema: Record<string, unknown>): Record<string, unk
const result = { ...schema }
// Normalize `required` — Qwen (and other strict validators) reject both
// `required: null` and missing `required` on object schemas. Coerce
// null/non-array to an empty array, and inject an empty array when absent.
if ('required' in result && !Array.isArray(result.required)) {
result.required = []
} else if (!('required' in result) && result.type === 'object') {
result.required = []
}
// Convert `const` → `enum: [value]`
if ('const' in result) {
result.enum = [result.const]