From 4a54824f7f5c61c25d2d623d48580274f9934a22 Mon Sep 17 00:00:00 2001 From: Joseph Yaksich <294273268+gitcommit90@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:18:39 +0700 Subject: [PATCH] fix(param-support): handle strip rules without match/drop Cloudflare AI rule only sets flattenContent. Treat missing match as provider-wide and missing drop as empty list to avoid crash. Fixes #1960. Co-authored-by: Cursor --- open-sse/translator/concerns/paramSupport.js | 3 +- tests/unit/param-support.test.js | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/unit/param-support.test.js diff --git a/open-sse/translator/concerns/paramSupport.js b/open-sse/translator/concerns/paramSupport.js index bf344c22..dc030194 100644 --- a/open-sse/translator/concerns/paramSupport.js +++ b/open-sse/translator/concerns/paramSupport.js @@ -16,6 +16,7 @@ const STRIP_RULES = [ // Test a rule's match (regex or predicate) against the model id. function matches(rule, model) { + if (!rule.match) return true; return typeof rule.match === "function" ? rule.match(model) : rule.match.test(model); } @@ -25,7 +26,7 @@ export function stripUnsupportedParams(provider, model, body) { for (const rule of STRIP_RULES) { if (rule.provider && rule.provider !== provider) continue; if (!matches(rule, model)) continue; - for (const key of rule.drop) { + for (const key of rule.drop || []) { if (body[key] !== undefined) delete body[key]; } // CF Workers AI oneOf root schema only accepts content as plain string (#1926) diff --git a/tests/unit/param-support.test.js b/tests/unit/param-support.test.js new file mode 100644 index 00000000..205a5fe2 --- /dev/null +++ b/tests/unit/param-support.test.js @@ -0,0 +1,31 @@ +import { describe, it, expect } from "vitest"; + +import { stripUnsupportedParams } from "../../open-sse/translator/concerns/paramSupport.js"; + +describe("stripUnsupportedParams", () => { + it("flattens Cloudflare AI OpenAI content-part arrays", () => { + const body = { + messages: [ + { + role: "user", + content: [ + { type: "text", text: "hello " }, + { type: "image_url", image_url: { url: "data:image/png;base64,xx" } }, + { type: "text", text: "world" }, + ], + }, + ], + }; + + expect(() => stripUnsupportedParams("cloudflare-ai", "@cf/meta/llama-3.1-8b-instruct", body)).not.toThrow(); + expect(body.messages[0].content).toBe("hello world"); + }); + + it("still drops unsupported GitHub model params", () => { + const body = { temperature: 0.7, top_p: 1 }; + + stripUnsupportedParams("github", "gpt-5.4", body); + + expect(body).toEqual({ top_p: 1 }); + }); +});