fix: parse tool_use/tool_result messages and add OpenCode SQLite backend#1401
Open
BlueOcean223 wants to merge 2 commits intofarion1231:mainfrom
Open
fix: parse tool_use/tool_result messages and add OpenCode SQLite backend#1401BlueOcean223 wants to merge 2 commits intofarion1231:mainfrom
BlueOcean223 wants to merge 2 commits intofarion1231:mainfrom
Conversation
cf8820d to
1047a34
Compare
- Claude: reclassify user messages containing tool_result as "tool" role - Codex: handle function_call and function_call_output payload types - Gemini: support array content and toolCalls extraction, filter info/error types - OpenCode: add SQLite session scan, load and delete alongside legacy JSON - utils: extend parse_timestamp_to_ms for integer timestamps, extract tool_use/tool_result in shared extract_text
- Claude: fix role misclassification for mixed user+tool_result messages (any → all) - OpenCode: extract duplicate part text logic into extract_part_text() - OpenCode: add path validation for SQLite delete to prevent foreign DB access - OpenCode: wrap SQLite deletion in transaction for atomicity - openclaw_config: remove redundant as_deref() on Option<&str>
f314dfd to
eb01c6d
Compare
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.
问题
之前 session 消息加载存在以下问题:
tool_use/tool_result会被解析为用户消息。Codex 的function_call/function_call_output会被直接忽略。Gemini 的toolCalls在加载会话时被忽略或显示为空,导致对话历史不完整,工具交互过程无法回溯 。 前端提供了工具的卡片,但由于后端错误导致实际上没有使用。opencode.db)存储 session,当前只读取旧版 JSON 文件,新版用户看不到任何会话记录parse_timestamp_to_ms仅支持 RFC3339 字符串,OpenCode SQLite中存储的整数时间戳(秒/毫秒)无法解析
content字段有时为[{text: "..."}]数组格式,之前仅处理了字符串格式;
info/error类型的系统消息也被错误地展示出来更新
[Tool: name]格式展示,tool_result 归类为
tool角色opencode.db)的 session 扫描、消息加载和删除支持,与原 JSON 存储自动合并去重parse_timestamp_to_ms支持整数(秒/毫秒)和 RFC3339 字符串content为字符串或[{text: ...}]数组两种格式,过滤info/error类型消息效果比对
claude code
修改前
会将工具信息解析为用户信息

修改后
codex
修复前
修复后
gemini
修复前
消息丢失

修复后
opencode
修复前
无法解析用户的最新消息,且时间解析错误

修复后