Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,11 +1537,13 @@ export function schema(model: Provider.Model, schema: JSONSchema7): JSONSchema7
schema = sanitizeGemini(schema)
}

// DeepSeek rejects function schemas whose root type is implicit. Effect
// emits object-only discriminated unions as a root `anyOf`; retaining the
// union while declaring its shared object type preserves every branch.
// OpenAI-compatible backends (DeepSeek, GLM, and other relays) reject
// function schemas whose root type is implicit — the model emits empty
// tool arguments instead of erroring. Effect emits object-only
// discriminated unions as a root `anyOf`; retaining the union while
// declaring its shared object type preserves every branch.
if (
model.api.id.toLowerCase().includes("deepseek") &&
model.api.npm === "@ai-sdk/openai-compatible" &&
schema.type === undefined &&
Array.isArray(schema.anyOf) &&
schema.anyOf.length > 0 &&
Expand Down
14 changes: 14 additions & 0 deletions packages/opencode/test/tool/workflow-provider-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const deepseekModel = {
providerID: "deepseek",
api: { id: "deepseek-v4-pro", npm: "@ai-sdk/openai-compatible" },
} as never
const glmModel = {
providerID: "local-proxy",
api: { id: "glm-5.3", npm: "@ai-sdk/openai-compatible" },
} as never

type JsonSchemaNode = {
anyOf?: JsonSchemaNode[]
Expand Down Expand Up @@ -131,6 +135,16 @@ describe("workflow provider-facing schema", () => {
expect(branchByAction(transformed, "start", "spec_path")).toHaveLength(1)
})

test("OpenAI-compatible transports (GLM relay) also get the object-root union", () => {
const transformed = ProviderTransform.schema(
glmModel,
ToolJsonSchema.fromSchema(Parameters as never),
) as JsonSchemaNode
expect(transformed.type).toBe("object")
expect(branches(transformed)).toHaveLength(10)
expect(branchByAction(transformed, "start", "spec_path")).toHaveLength(1)
})

test("post-change byte sizes stay at the recorded evidence", async () => {
const evidence = (await Bun.file(
new URL("./fixtures/workflow-parameters-post-change.json", import.meta.url),
Expand Down
Loading