| 1442 | |
| 1443 | if (model.providerID === "moonshotai" || model.api.id.toLowerCase().includes("kimi")) { |
| 1444 | const sanitizeMoonshot = (obj: unknown): unknown => { |
| 1445 | if (obj === null || typeof obj !== "object") return obj |
| 1446 | if (Array.isArray(obj)) return obj.map(sanitizeMoonshot) |
| 1447 | // Moonshot expands $ref before validation and rejects sibling keywords like description on the same node. |
| 1448 | if ("$ref" in obj && typeof obj.$ref === "string") return { $ref: obj.$ref } |
| 1449 | const result = Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, sanitizeMoonshot(value)])) |
| 1450 | // MFJS does not support tuple-style `items` arrays; it requires one schema object for all array items. |
| 1451 | if (Array.isArray(result.items)) result.items = result.items[0] ?? {} |
| 1452 | return result |
| 1453 | } |
| 1454 | |
| 1455 | const sanitized = sanitizeMoonshot(schema) |
| 1456 | if (typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized)) { |