返回 DeepSeek-Reasonix
search_footnotes.go
根目录 / internal / cli / search_footnotes.go
1 package cli
2
3 import (
4 "encoding/json"
5 "reasonix/internal/event"
6 "reasonix/internal/i18n"
7 "reasonix/internal/provider"
8 "strings"
9 )
10
11 func (m *chatTUI) rememberSearchResult(t event.Tool) {
12 if t.Name == "web_search" && t.Err == "" {
13 m.searchSources = provider.ParseServerSearchOutput(t.Output)
14 }
15 }
16
17 func (m *chatTUI) writeSearchFootnotes() {
18 notes := provider.FormatServerSearchFootnotes(m.searchSources)
19 if notes == "" {
20 return
21 }
22 m.pending.WriteString(notes)
23 m.searchSources = nil
24 }
25
26 // Only an explicitly recorded status supplies the missing-source notice. Old
27 // histories and links in generated summary text cannot establish provenance.
28 func searchHistorySections(m provider.Message, width int, renderAssistant func(string, int) string) []string {
29 if m.Role == provider.RoleAssistant {
30 for _, call := range m.ServerSearch {
31 if call.SourcesStatus == provider.SourcesNotProvided {
32 return []string{" · " + i18n.M.SearchSourcesNotProvided + "\n\n"}
33 }
34 }
35 }
36 if m.Role == provider.RoleTool && m.Name == "web_search" {
37 var result struct {
38 SourcesStatus string `json:"sources_status"`
39 Summary string `json:"summary"`
40 }
41 if json.Unmarshal([]byte(m.Content), &result) == nil && result.SourcesStatus == provider.SourcesNotProvided {
42 out := []string{" · " + i18n.M.SearchSourcesNotProvided + "\n\n"}
43 if strings.TrimSpace(result.Summary) != "" {
44 out = append(out, renderAssistant(result.Summary, width)+"\n\n")
45 }
46 return out
47 }
48 }
49 return nil
50 }
51
51 lines GO