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
15 changes: 15 additions & 0 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,21 @@ export namespace ProviderTransform {
}

export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema | JSONSchema7): JSONSchema7 {
// Strip $schema meta field from Zod 4 toJSONSchema() output.
// Claude API's input_schema rejects this field.
if ("$schema" in schema) {
const { $schema: _, ...rest } = schema as any
schema = rest as JSONSchema.BaseSchema
}

// Claude API (especially thinking models) requires the "required" field
// to be present when "properties" exists, even if it's an empty array.
// Without this, the API returns "JSON schema is invalid" errors.
const s = schema as any
if (s.type === "object" && s.properties && !s.required) {
s.required = []
}

/*
if (["openai", "azure"].includes(providerID)) {
if (schema.type === "object" && schema.properties) {
Expand Down
Loading