workbuddy 0.2.34: REA's surrogate path guard is left out of the tools sent to WorkBuddy AI (#1080)
WorkBuddy AI's deepseek-v4.1-flash-sg refuses a request whose tools carry REA's exact `^[^\uD800-\uDFFF]*$` path guard with "400: invalid function call parameters", before any tool is called. fitSchema now drops that exact pattern from the outbound schema; other patterns, the surrounding allOf and REA's own validation stay. Reviewed at 2f4738e9: workbuddy package on Linux (Bun 1.4.2, temp HOME) 378 pass; bun scripts/check.mjs workbuddy ok; with the new `if` turned off by hand the new guard test goes red. Co-authored-by: zhbcn <zhbcn@users.noreply.github.com>
This commit is contained in:
@@ -253,6 +253,9 @@ models to each shape below and Kimi's, GPT's, Gemini's and GLM's to some:
|
||||
- a tool's parameters with no `type`, empty, or a union (`anyOf`, `oneOf`,
|
||||
`allOf`) at the root are an object, the union's fields merged;
|
||||
- a `pattern`'s `\0` is `\u0000`, which matches the same;
|
||||
- REA's exact `^[^\uD800-\uDFFF]*$` surrogate guard is omitted from the
|
||||
outbound schema: WorkBuddy AI's DeepSeek rejects it with "invalid function
|
||||
call parameters". Other path constraints and REA's own validation stay;
|
||||
- a tuple's `items` (a list) is one schema any of them fits;
|
||||
- an `enum` with no `type` takes its values' type (or that and `"null"`),
|
||||
and an `enum` of several types is an `anyOf` of one typed `enum` for
|
||||
|
||||
@@ -1243,6 +1243,10 @@ function fitSchema(s, depth = 0) {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (s.pattern === "^[^\\uD800-\\uDFFF]*$") {
|
||||
delete s.pattern
|
||||
changed = true
|
||||
}
|
||||
if (Array.isArray(s.items)) {
|
||||
const list = s.items.filter((v) => v && typeof v === "object")
|
||||
s.items = list.length === 0 ? {} : list.length === 1 ? list[0] : { anyOf: list }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-workbuddy-auth",
|
||||
"version": "0.2.33",
|
||||
"version": "0.2.34",
|
||||
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
@@ -25,6 +25,43 @@ test("a pattern's \\0 is sent as \\u0000, at any depth; \\\\0 and \\01 are left"
|
||||
expect(new RegExp(ps.properties.a.pattern).test("ab")).toBe(true)
|
||||
})
|
||||
|
||||
test("REA's surrogate guard is omitted from outbound schemas, keeping other path constraints", () => {
|
||||
const guard = { pattern: "^[^\\uD800-\\uDFFF]*$" }
|
||||
const path = {
|
||||
type: "string", minLength: 1,
|
||||
allOf: [
|
||||
{ pattern: "^[^\\x00]*$" },
|
||||
guard,
|
||||
{ pattern: "^(?:[\\x5C\\x2F]|[A-Za-z]:[\\x5C\\x2F])" },
|
||||
],
|
||||
}
|
||||
const parameters = { type: "object", properties: {
|
||||
expected_server_path: path,
|
||||
paths: { type: "array", items: { type: "string", ...guard } },
|
||||
}, $defs: { path: structuredClone(path) }, additionalProperties: false }
|
||||
const original = structuredClone(parameters)
|
||||
const body = chat([tool("mcp__rea__binary_session", parameters)])
|
||||
const sent = fitted(body).body
|
||||
const schema = JSON.parse(sent).tools[0].function.parameters
|
||||
expect(schema.properties.expected_server_path).toEqual({
|
||||
...path, allOf: [path.allOf[0], {}, path.allOf[2]],
|
||||
})
|
||||
expect(schema.properties.paths.items).toEqual({ type: "string" })
|
||||
expect(schema.$defs.path).toEqual(schema.properties.expected_server_path)
|
||||
expect(schema.additionalProperties).toBe(false)
|
||||
expect(parameters).toEqual(original)
|
||||
expect(fitted(sent).body).toBe(sent)
|
||||
})
|
||||
|
||||
test("other surrogate patterns and literal escape sequences are left alone", () => {
|
||||
const body = chat([tool("t", { type: "object", properties: {
|
||||
mixed: { type: "string", pattern: "^[^\\u0000\\uD800-\\uDFFF]*$" },
|
||||
literal: { type: "string", pattern: "^[^\\\\uD800-\\\\uDFFF]*$" },
|
||||
ordinary: { type: "string", pattern: "^[a-z]+$" },
|
||||
} })])
|
||||
expect(fitted(body).body).toBe(body)
|
||||
})
|
||||
|
||||
test("a root anyOf of objects becomes one object; a field each branch requires stays required", () => {
|
||||
const body = chat([tool("t", { anyOf: [
|
||||
{ type: "object", properties: { kind: { const: "a" }, x: { type: "string" } }, required: ["kind", "x"] },
|
||||
|
||||
Reference in New Issue
Block a user