What do you want to change?
Skip empty text parts when convertMessages builds a multi-part user message for the openai-completions API.
Why?
A prompt sent with images and an empty message is stored as [{ type: "text", text: "" }, { type: "image", ... }], and zai rejects that content array:
400: {"code":"1210","message":"API 调用参数有误,请检查文档。"}
The message is replayed on every later turn, so one such prompt ends the session for GLM models for good, while the same history keeps working on other providers. Nothing is billed, so the usage numbers give no hint. I hit this through pi-web, where sending an image with no caption is the normal thing to do, and lost a session I had been using for a day.
Repro on 0.86.0 with pi core only, no extensions:
pi --mode rpc --model zai-coding-cn/glm-5.3-flash -ne
{"type":"prompt","message":"","images":[{"type":"image","mimeType":"image/png","data":"<base64>"}]}
The assistant turn comes back with stopReason "error" and the 1210 message above, and the saved session stores the content array as [{"type":"text","text":""},{"type":"image",...}].
How? (optional)
agent-session.ts prepends { type: "text", text } to the content array unconditionally, so an empty prompt text becomes an empty part, and convertMessages then forwards it as is.
I patched the converter, since that also rescues sessions that already contain such a message, and added a regression test. Happy to move the fix to agent-session or do both. I would like to submit the PR myself.
What do you want to change?
Skip empty text parts when convertMessages builds a multi-part user message for the openai-completions API.
Why?
A prompt sent with images and an empty message is stored as
[{ type: "text", text: "" }, { type: "image", ... }], and zai rejects that content array:The message is replayed on every later turn, so one such prompt ends the session for GLM models for good, while the same history keeps working on other providers. Nothing is billed, so the usage numbers give no hint. I hit this through pi-web, where sending an image with no caption is the normal thing to do, and lost a session I had been using for a day.
Repro on 0.86.0 with pi core only, no extensions:
The assistant turn comes back with stopReason "error" and the 1210 message above, and the saved session stores the content array as
[{"type":"text","text":""},{"type":"image",...}].How? (optional)
agent-session.ts prepends { type: "text", text } to the content array unconditionally, so an empty prompt text becomes an empty part, and convertMessages then forwards it as is.
I patched the converter, since that also rescues sessions that already contain such a message, and added a regression test. Happy to move the fix to agent-session or do both. I would like to submit the PR myself.