claude code tools error

This commit is contained in:
Sakurasan
2026-08-19 03:46:39 +08:00
parent 3e7efb3c88
commit 30ab9e842c
4 changed files with 709 additions and 77 deletions
+3 -1
View File
@@ -230,6 +230,7 @@ func anthropicMsgToChat(role string, content json.RawMessage) []any {
var blocks []map[string]any
if json.Unmarshal(content, &blocks) == nil && blocks != nil {
var out []any
var toolMsgs []any // tool_result 单独收集,保证排在 assistant(tool_calls) 之后
var textParts []string
var contentBlocks []any // text / image_url 块,保留原始顺序
var toolCalls []any
@@ -259,7 +260,7 @@ func anthropicMsgToChat(role string, content json.RawMessage) []any {
case "tool_result":
callID, _ := b["tool_use_id"].(string)
res := strField(b["content"])
out = append(out, map[string]any{"role": "tool", "tool_call_id": callID, "content": res})
toolMsgs = append(toolMsgs, map[string]any{"role": "tool", "tool_call_id": callID, "content": res})
}
}
hasImage := false
@@ -282,6 +283,7 @@ func anthropicMsgToChat(role string, content json.RawMessage) []any {
}
out = append(out, msg)
}
out = append(out, toolMsgs...)
if len(out) > 0 {
return out
}