返回 DeepSeek-Reasonix
history_message_content.go
根目录 / internal / serve / history_message_content.go
1 package serve
2
3 import (
4 "reasonix/internal/agent"
5 "reasonix/internal/provider"
6 )
7
8 func historyMessageContent(message provider.Message) string {
9 if message.Role == provider.RoleUser {
10 return agent.UserMessageText(message)
11 }
12 return message.Content
13 }
14
15 type historyToolCall struct {
16 ID string `json:"id"`
17 Name string `json:"name"`
18 Arguments string `json:"arguments"`
19 }
20
21 type historyMessage struct {
22 MessageID string `json:"messageId,omitempty"`
23 ServerSearch []provider.ServerSearchCall `json:"serverSearch,omitempty"`
24 ProtocolRecovery *provider.ProtocolRecoveryAction `json:"protocolRecovery,omitempty"`
25 Role string `json:"role"`
26 Content string `json:"content"`
27 Missing []string `json:"missing,omitempty"`
28 Reasoning string `json:"reasoning,omitempty"`
29 ToolCalls []historyToolCall `json:"toolCalls,omitempty"`
30 ToolCallID string `json:"toolCallId,omitempty"`
31 ToolName string `json:"toolName,omitempty"`
32 PresentedFiles []provider.PresentedFile `json:"presentedFiles,omitempty"`
33 }
34
35 func historyMessages(msgs []provider.Message) []historyMessage {
36 out := make([]historyMessage, 0, len(msgs))
37 for _, m := range historyWithoutPinnedContextRevisions(msgs) {
38 if recovered, handled := finalReadinessHistoryMessage(m); handled {
39 out = append(out, recovered...)
40 continue
41 }
42 // Steer messages are surfaced as a notice, not a user message.
43 if m.Role == provider.RoleUser {
44 if text, handled := agent.ReplaySteerText(m.Content); handled {
45 if text != "" {
46 out = append(out, historyMessage{Role: "notice", Content: "↪ " + text})
47 }
48 continue
49 }
50 }
51 hm := historyMessage{MessageID: m.ID, Role: string(m.Role), Content: historyMessageContent(m)}
52 if m.Role == provider.RoleAssistant {
53 hm.Reasoning = m.ReasoningContent
54 for _, search := range m.ServerSearch {
55 search.Raw = nil
56 hm.ServerSearch = append(hm.ServerSearch, search)
57 }
58 if len(m.ToolCalls) > 0 {
59 hm.ToolCalls = make([]historyToolCall, len(m.ToolCalls))
60 for i, tc := range m.ToolCalls {
61 hm.ToolCalls[i] = historyToolCall{ID: tc.ID, Name: tc.Name, Arguments: tc.Arguments}
62 }
63 }
64 }
65 if m.Role == provider.RoleTool {
66 hm.ToolCallID = m.ToolCallID
67 hm.ToolName = m.Name
68 if m.Name == "present" {
69 hm.PresentedFiles = provider.PresentedFileList(m.PresentedFiles)
70 }
71 }
72 out = append(out, hm)
73 }
74 return out
75 }
76
76 lines GO