diff --git a/packages/workbuddy/README.md b/packages/workbuddy/README.md index be1393f..adb46e7 100644 --- a/packages/workbuddy/README.md +++ b/packages/workbuddy/README.md @@ -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 diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index 94ebf76..582524c 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -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 } diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index f594a80..9836424 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -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", diff --git a/packages/workbuddy/tools.test.mjs b/packages/workbuddy/tools.test.mjs index 42b39cb..d75a25c 100644 --- a/packages/workbuddy/tools.test.mjs +++ b/packages/workbuddy/tools.test.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"] },