(model: Provider.Model, schema: JSONSchema.BaseSchema)
| 373 | } |
| 374 | |
| 375 | export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema) { |
| 376 | /* |
| 377 | if (["openai", "azure"].includes(providerID)) { |
| 378 | if (schema.type === "object" && schema.properties) { |
| 379 | for (const [key, value] of Object.entries(schema.properties)) { |
| 380 | if (schema.required?.includes(key)) continue |
| 381 | schema.properties[key] = { |
| 382 | anyOf: [ |
| 383 | value as JSONSchema.JSONSchema, |
| 384 | { |
| 385 | type: "null", |
| 386 | }, |
| 387 | ], |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | */ |
| 393 | |
| 394 | // Convert integer enums to string enums for Google/Gemini |
| 395 | if (model.providerID === "google" || model.api.id.includes("gemini")) { |
| 396 | const sanitizeGemini = (obj: any): any => { |
| 397 | if (obj === null || typeof obj !== "object") { |
| 398 | return obj |
| 399 | } |
| 400 | |
| 401 | if (Array.isArray(obj)) { |
| 402 | return obj.map(sanitizeGemini) |
| 403 | } |
| 404 | |
| 405 | const result: any = {} |
| 406 | for (const [key, value] of Object.entries(obj)) { |
| 407 | if (key === "enum" && Array.isArray(value)) { |
| 408 | // Convert all enum values to strings |
| 409 | result[key] = value.map((v) => String(v)) |
| 410 | // If we have integer type with enum, change type to string |
| 411 | if (result.type === "integer" || result.type === "number") { |
| 412 | result.type = "string" |
| 413 | } |
| 414 | } else if (typeof value === "object" && value !== null) { |
| 415 | result[key] = sanitizeGemini(value) |
| 416 | } else { |
| 417 | result[key] = value |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | // Filter required array to only include fields that exist in properties |
| 422 | if (result.type === "object" && result.properties && Array.isArray(result.required)) { |
| 423 | result.required = result.required.filter((field: any) => field in result.properties) |
| 424 | } |
| 425 | |
| 426 | return result |
| 427 | } |
| 428 | |
| 429 | schema = sanitizeGemini(schema) |
| 430 | } |
| 431 | |
| 432 | return schema |
nothing calls this directly
no test coverage detected