fix(cloudflare-ai): flatten content-part arrays to string to avoid oneOf 400 (#1926)
Workers AI rejects OpenAI content-part array shape; flatten text parts to a plain string per message before sending. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,8 @@ const STRIP_RULES = [
|
||||
{ provider: "github", match: /gpt-5\.4/i, drop: ["temperature"] },
|
||||
// GitHub Copilot Claude (except opus/sonnet 4.6): thinking + reasoning_effort rejected. #713
|
||||
{ provider: "github", match: (m) => /claude/i.test(m) && !/claude.*(opus|sonnet).*4\.6/i.test(m), drop: ["thinking", "reasoning_effort"] },
|
||||
// Cloudflare Workers AI: content must be plain string, rejects OpenAI content-part array (#1926)
|
||||
{ provider: "cloudflare-ai", flattenContent: true },
|
||||
];
|
||||
|
||||
// Test a rule's match (regex or predicate) against the model id.
|
||||
@@ -26,6 +28,16 @@ export function stripUnsupportedParams(provider, model, body) {
|
||||
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)
|
||||
if (rule.flattenContent && Array.isArray(body.messages)) {
|
||||
for (const msg of body.messages) {
|
||||
if (msg && Array.isArray(msg.content)) {
|
||||
msg.content = msg.content
|
||||
.map(b => (b?.type === "text" && typeof b.text === "string") ? b.text : "")
|
||||
.join("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user