Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,22 @@ export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema | JS
}
*/

// Ensure `required` is present when `properties` exists. Claude and other
// providers reject schemas that have properties but no required field.
const ensureRequired = (obj: unknown): unknown => {
if (obj === null || typeof obj !== "object" || Array.isArray(obj)) return obj
const node = obj as Record<string, unknown>
const result: Record<string, unknown> = {}
for (const [key, value] of Object.entries(node)) {
result[key] = typeof value === "object" && value !== null ? ensureRequired(value) : value
}
if (result.type === "object" && result.properties && !Array.isArray(result.required)) {
result.required = []
}
return result
}
schema = ensureRequired(schema) as JSONSchema.BaseSchema | JSONSchema7

if (model.providerID === "moonshotai" || model.api.id.toLowerCase().includes("kimi")) {
const sanitizeMoonshot = (obj: unknown): unknown => {
if (obj === null || typeof obj !== "object") return obj
Expand Down
Loading