persist and restore assistant tool calls in session jsonl events

This commit is contained in:
DBT
2026-02-24 10:14:46 +00:00
parent 8988002c5a
commit 8dd8eb23dc

View File

@@ -43,8 +43,9 @@ type openClawEvent struct {
Type string `json:"type"` Type string `json:"type"`
Text string `json:"text,omitempty"` Text string `json:"text,omitempty"`
} `json:"content,omitempty"` } `json:"content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"` ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"` ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
} `json:"message,omitempty"` } `json:"message,omitempty"`
} }
@@ -322,13 +323,14 @@ func toOpenClawMessageEvent(msg providers.Message) openClawEvent {
Type: "message", Type: "message",
Timestamp: time.Now().UTC().Format(time.RFC3339Nano), Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
Message: &struct { Message: &struct {
Role string `json:"role"` Role string `json:"role"`
Content []struct { Content []struct {
Type string `json:"type"` Type string `json:"type"`
Text string `json:"text,omitempty"` Text string `json:"text,omitempty"`
} `json:"content,omitempty"` } `json:"content,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"` ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"` ToolName string `json:"toolName,omitempty"`
ToolCalls []providers.ToolCall `json:"toolCalls,omitempty"`
}{ }{
Role: mappedRole, Role: mappedRole,
Content: []struct { Content: []struct {
@@ -338,6 +340,7 @@ func toOpenClawMessageEvent(msg providers.Message) openClawEvent {
{Type: "text", Text: msg.Content}, {Type: "text", Text: msg.Content},
}, },
ToolCallID: msg.ToolCallID, ToolCallID: msg.ToolCallID,
ToolCalls: msg.ToolCalls,
}, },
} }
return e return e
@@ -368,7 +371,7 @@ func fromJSONLLine(line []byte) (providers.Message, bool) {
content += part.Text content += part.Text
} }
} }
return providers.Message{Role: role, Content: content, ToolCallID: event.Message.ToolCallID}, true return providers.Message{Role: role, Content: content, ToolCallID: event.Message.ToolCallID, ToolCalls: event.Message.ToolCalls}, true
} }
func deriveSessionID(key string) string { func deriveSessionID(key string) string {