build / build (push) Successful in 2m31s
The Zhanlu upstream gateway returns HTTP 400 (请求消息格式错误) for two
message-structure issues that AI coding tools like MiMoCode produce:
1. Multi-part content arrays — OpenAI SDKs send content as
[{type:"text",text:"…"}] arrays; the gateway only accepts string
content. normalizeMessages now flattens text-only arrays into a
concatenated string (non-text parts like images are preserved).
2. Invalid tool_calls — when a tool call fails, MiMoCode emits
{name:"invalid", arguments:{"tool":"task","error":"…"}}
placeholders. The gateway rejects function names not in the tools list
and non-object arguments (e.g. "-1"). normalizeMessages now
sanitizes these in place: the real tool name is extracted from the
arguments' "tool" field (falling back to an arbitrary declared
tool), and non-JSON-object arguments are replaced with "{}". No
messages or tool results are removed, preserving the full
conversation context including error feedback.
Verified with the exact error.md request: 0/10 400 errors after fix
(vs 10/10 before). Model returns valid streaming responses with task
tool calls.