fix(provider): preserve reasoning content in chat completions

This commit is contained in:
lpf
2026-05-11 18:40:45 +08:00
parent 78d546989c
commit b8cf8ad1b1
5 changed files with 223 additions and 24 deletions

View File

@@ -64,9 +64,10 @@ type openClawEvent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
} `json:"content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
} `json:"message,omitempty"`
}
@@ -577,9 +578,10 @@ func toOpenClawMessageEvent(msg providers.Message) openClawEvent {
Type string `json:"type"`
Text string `json:"text,omitempty"`
} `json:"content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
}{
Role: mappedRole,
Content: []struct {
@@ -588,8 +590,9 @@ func toOpenClawMessageEvent(msg providers.Message) openClawEvent {
}{
{Type: "text", Text: msg.Content},
},
ToolCallID: msg.ToolCallID,
ToolCalls: msg.ToolCalls,
ReasoningContent: msg.ReasoningContent,
ToolCallID: msg.ToolCallID,
ToolCalls: msg.ToolCalls,
},
}
return e
@@ -620,7 +623,7 @@ func fromJSONLLine(line []byte) (providers.Message, bool) {
content += part.Text
}
}
return providers.Message{Role: role, Content: content, ToolCallID: event.Message.ToolCallID, ToolCalls: event.Message.ToolCalls}, true
return providers.Message{Role: role, Content: content, ReasoningContent: event.Message.ReasoningContent, ToolCallID: event.Message.ToolCallID, ToolCalls: event.Message.ToolCalls}, true
}
func deriveSessionID(key string) string {