feat: 支持多轮工具调用 + Anthropic /v1/messages 兼容层,并修复日志内容丢失 - #201
Open
2561242-cloud wants to merge 3 commits into
Open
2561242-cloud wants to merge 3 commits into
2561242-cloud wants to merge 3 commits into
Conversation
- QwenAiAdapter 改为完整多轮拼接(含 role:'tool' / tool_calls), 使 OpenClaw/Claude Code/Cline 的工具循环能正确回传工具结果 - 新增 extractTextContent 处理数组型 content - 流式解析统一改用 ToolStreamParser,新增幂等 finishStream() - 新增 assertEventStream/drainStream,把 Qwen 上游空响应/错误转成可见报错 - Zai 适配器接入同一套 ToolStreamParser - 新增 routes/messages.ts:Anthropic /v1/messages 兼容层(请求/响应转换、 流式 SSE、走正常 provider 流水线并补日志),在 routes/index.ts 注册
根因有三处,已全部修复:
1) includeBodies 默认 false 导致 body 被丢弃
-> DEFAULT_REQUEST_LOG_CONFIG.includeBodies 改为 true
2) sanitizeRequestLogUpdates 对未提供的字段赋 undefined,
流式结束补全时把已写好的 requestBody/userInput 清空
-> 改为只处理 updates 显式包含的键
3) 无可读摘要,关掉 body 后日志一片空白
-> 新增 extractResponsePreview 提取正文/tool_call/finish_reason/usage,
空响应写 '[empty response] 上游未返回任何内容'
配套:store 增加一次性迁移标记 requestLogBodiesMigrated,
升级后自动打开 includeBodies 并写回(用户后可手动关闭);
Renderer 日志详情页展示 responsePreview,i18n 新增文案。
设置该环境变量后: - 跳过单实例锁,可并行启动第二个实例 - 代理自动以该端口启动,不改动用户真实配置 - 跳过 electron-updater 初始化(调试实例非打包形态,避免 app.getVersion 崩溃) 不影响正常启动行为。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
让 OpenClaw 等 Anthropic 协议客户端能通过本反向代理正常发起 工具调用(tool use),并修复「日志里每条请求/响应看不到具体内容」的问题。
1. 工具调用链路增强
qwen-ai.ts:改写为完整多轮拼接(含role:'tool'/tool_calls),使 OpenClaw / Claude Code / Cline 的工具循环能正确回传工具结果;新增extractTextContent、幂等finishStream()、assertEventStream()/drainStream()(Qwen 上游空响应/错误转为可见报错)zai.ts:接入同一套ToolStreamParserroutes/messages.ts:Anthropic/v1/messages兼容层(请求/响应转换、流式 SSE、走正常 provider 流水线并补日志),在routes/index.ts注册2. 日志内容修复(根因三处)
includeBodies默认false导致 body 被丢弃 -> 改为truesanitizeRequestLogUpdates对未提供字段赋undefined,流式结束补全时清空已写好的requestBody/userInput-> 改为只处理显式包含的键extractResponsePreview提取正文/tool_call/finish_reason/usage,空响应写[empty response]requestLogBodiesMigrated一次性迁移;Renderer 日志详情页展示responsePreview3. 调试便利改动(可选)
新增
C2A_DEBUG_PORT侧载调试开关,正常启动不受影响。验证
verify_tools.py:工具调用 5 项验证check_logs.py:日志内容检查