Skip to content

Commit 0331931

Browse files
committed
fix: sanitize more invalid schema cases for gemini models
1 parent 01e2c9c commit 0331931

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ export namespace ProviderTransform {
275275

276276
// Convert integer enums to string enums for Google/Gemini
277277
if (providerID === "google" || modelID.includes("gemini")) {
278-
const convertIntEnumsToStrings = (obj: any): any => {
278+
const sanitizeGemini = (obj: any): any => {
279279
if (obj === null || typeof obj !== "object") {
280280
return obj
281281
}
282282

283283
if (Array.isArray(obj)) {
284-
return obj.map(convertIntEnumsToStrings)
284+
return obj.map(sanitizeGemini)
285285
}
286286

287287
const result: any = {}
@@ -294,15 +294,21 @@ export namespace ProviderTransform {
294294
result.type = "string"
295295
}
296296
} else if (typeof value === "object" && value !== null) {
297-
result[key] = convertIntEnumsToStrings(value)
297+
result[key] = sanitizeGemini(value)
298298
} else {
299299
result[key] = value
300300
}
301301
}
302+
303+
// Filter required array to only include fields that exist in properties
304+
if (result.type === "object" && result.properties && Array.isArray(result.required)) {
305+
result.required = result.required.filter((field: any) => field in result.properties)
306+
}
307+
302308
return result
303309
}
304310

305-
schema = convertIntEnumsToStrings(schema)
311+
schema = sanitizeGemini(schema)
306312
}
307313

308314
return schema

0 commit comments

Comments
 (0)