缺陷 / 高 / LLM 适配器
electron/harness/adapters/shared/openai-format.ts
构建 OpenAI 兼容消息时:
const message = { role: 'tool', content: toolResult.content ?? undefined, // 错误 tool_call_id: toolCall.id, };
当 toolResult.content 为 null 或空时,赋为 undefined,序列化后字段消失。 OpenAI / DeepSeek / Agnes API 严格要求 tool 消息必须有 content 字段,缺失会返回 400:
toolResult.content
undefined
content
Invalid value for 'messages[].content': field is required
const message = { role: 'tool', content: toolResult.content ?? '', // 空字符串而非 undefined tool_call_id: toolCall.id, };
或保留错误信息:
content: toolResult.content ?? toolResult.error ?? '',
project_memory.md 已要求:
Assistant messages with tool_calls must set content to null (not empty string) to avoid API 400 errors
但 tool 角色消息与 assistant 不同,必须有非空 content。
文件: electron/harness/adapters/shared/openai-format.ts
修复: tool 消息 content 赋值后增加 if (msg.content === undefined) msg.content = '' 检查。JSON.stringify(undefined) 返回 undefined(非字符串),会导致 content 字段在序列化后消失,API 返回 400。
if (msg.content === undefined) msg.content = ''
JSON.stringify(undefined)
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
缺陷 / 高 / LLM 适配器
文件位置
electron/harness/adapters/shared/openai-format.ts问题描述
构建 OpenAI 兼容消息时:
当
toolResult.content为 null 或空时,赋为undefined,序列化后字段消失。OpenAI / DeepSeek / Agnes API 严格要求 tool 消息必须有
content字段,缺失会返回 400:影响
建议修复
或保留错误信息:
project_memory.md 已要求:
但 tool 角色消息与 assistant 不同,必须有非空 content。
修复说明
文件:
electron/harness/adapters/shared/openai-format.ts修复: tool 消息 content 赋值后增加
if (msg.content === undefined) msg.content = ''检查。JSON.stringify(undefined)返回undefined(非字符串),会导致 content 字段在序列化后消失,API 返回 400。验证:
tsc --noEmit类型检查通过。