congee949 found that qoder-cn's kmodel_latest (Kimi K3.1 Pro) fails with 502 on dsh's REA tools because of a oneOf with no type whose branches are all objects. With "type": "object" beside each such oneOf, the same requests got 200 in a real dsh run. qoderBody now sends each tool's parameters through typedUnions, which types such a oneOf object when each branch is typed object, directly or through local $refs. Other unions, anyOf, and missing, external or circular $refs are left alone. The work is done on a copy, so the client's schema is not changed. This is the same rule workbuddy 0.1.33 applies. Run: `bun test` in packages/qoder with a sandbox HOME/TMPDIR and a dead HTTPS_PROXY: 225 pass, 0 fail. `bun scripts/check.mjs qoder`: ok. Broken by hand: with qoderBody sending parameters unchanged, schema.test.mjs goes 1 red. Not tried: a real Qoder account.
39 lines
2.4 KiB
JavaScript
39 lines
2.4 KiB
JavaScript
// Qoder CN's kmodel_latest (Kimi K3.1 Pro) fails a chat whose tools hold a
|
|
// oneOf with no type, even of objects only, and takes it with "type":
|
|
// "object" beside it (congee949, #378). The parameters are the issue's own.
|
|
import { expect, test } from "bun:test"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
const { qoderBody, typedUnions } = _internal
|
|
const m = { key: "kmodel_latest", config: { key: "kmodel_latest" }, context: 128_000 }
|
|
const ab = [
|
|
{ type: "object", properties: { mode: { type: "string", const: "a" } } },
|
|
{ type: "object", properties: { mode: { type: "string", const: "b" } } },
|
|
]
|
|
const nested = { type: "object", properties: { x: { $ref: "#/$defs/X" } }, $defs: { X: { type: "object", properties: { y: { oneOf: ab } }, required: ["y"] } } }
|
|
|
|
test("a oneOf of objects with no type goes typed object, the client's tool untouched", () => {
|
|
const parameters = { type: "object", properties: { x: { $ref: "#/$defs/X" } }, $defs: { X: { oneOf: ab } } }
|
|
const chat = { messages: [{ role: "user", content: "Do not call tools. Reply exactly OK." }], tools: [{ type: "function", function: { name: "probe", description: "Diagnostic placeholder.", parameters } }] }
|
|
const before = structuredClone(chat)
|
|
const sent = qoderBody(chat, m).tools[0].function.parameters
|
|
expect(sent.$defs.X).toEqual({ oneOf: ab, type: "object" })
|
|
expect(sent.properties.x).toEqual({ $ref: "#/$defs/X" })
|
|
expect(chat).toEqual(before)
|
|
expect(typedUnions(nested).$defs.X.properties.y.type).toBe("object")
|
|
})
|
|
|
|
test("a oneOf whose branches are $refs to objects is typed; mixed, anyOf, missing, external and circular are left", () => {
|
|
const refs = { type: "object", properties: { s: { $ref: "#/$defs/__schema0" } }, $defs: { __schema0: { oneOf: [{ $ref: "#/$defs/__schema1" }, { $ref: "#/$defs/__schema3" }] }, __schema1: { type: "object" }, __schema3: { $ref: "#/$defs/__schema4" }, __schema4: { type: "object" } } }
|
|
expect(typedUnions(refs).$defs.__schema0.type).toBe("object")
|
|
const left = { type: "object", properties: {
|
|
mixed: { oneOf: [ab[0], { type: "string" }] },
|
|
any: { anyOf: ab },
|
|
missing: { oneOf: [ab[0], { $ref: "#/$defs/Nope" }] },
|
|
external: { oneOf: [ab[0], { $ref: "other.json#/X" }] },
|
|
loop: { oneOf: [ab[0], { $ref: "#/$defs/A" }] },
|
|
examples: { type: "array", examples: [{ oneOf: ab }] },
|
|
}, $defs: { A: { $ref: "#/$defs/B" }, B: { $ref: "#/$defs/A" } } }
|
|
expect(typedUnions(left)).toEqual(left)
|
|
})
|