返回 DeepSeek-Reasonix
history_slice_before_controller.go
根目录 / desktop / history_slice_before_controller.go
1 package main
2
3 import (
4 "log/slog"
5 "strings"
6 )
7
8 // historySliceBeforeController keeps durable history observable when model
9 // configuration prevents the tab's execution controller from starting.
10 func (a *App) historySliceBeforeController(tabID, sessionDir, sessionPath, sessionID string, req HistorySliceRequest) HistorySlice {
11 if sessionID != "" {
12 query, ref, err := a.canonicalSessionQuery(tabID)
13 if err != nil {
14 return failedHistorySlice(err.Error())
15 }
16 slice, err := a.canonicalHistorySlice(query, ref, sessionDir, sessionPath, req)
17 if err != nil {
18 slog.Debug("desktop: cold canonical history slice failed", "session", ref.SessionID, "err", err)
19 return failedHistorySlice(err.Error())
20 }
21 return slice
22 }
23 if strings.TrimSpace(sessionPath) == "" {
24 return failedHistorySlice("session path unavailable before controller ready")
25 }
26 slice, err := a.coldHistorySlice(sessionDir, sessionPath, req)
27 if err != nil {
28 slog.Debug("desktop: cold history slice failed", "path", sessionPath, "err", err)
29 return failedHistorySlice(err.Error())
30 }
31 return slice
32 }
33
34 func (a *App) canonicalHistoryContentBeforeController(
35 tabID, sessionDir, sessionPath, sessionID string,
36 msgIndex, sub int,
37 ref HistoryContentRef,
38 chunkIndex int,
39 out HistoryContentChunk,
40 ) HistoryContentChunk {
41 query, sessionRef, err := a.canonicalSessionQuery(tabID)
42 if err != nil || entryIDSession(ref.EntryID) != sessionID || sessionRef.SessionID != sessionID {
43 out.Stale = true
44 return out
45 }
46 src, err := canonicalHistorySliceSource(query, sessionRef)
47 if err != nil || !src.identityMatches(ref.Revision, ref.RevKnown, ref.Digest) {
48 out.Stale = true
49 return out
50 }
51 value, found, stale := a.historyFieldValueForSource(src, msgIndex, sub, ref, sessionDisplayResolver(sessionDir, sessionPath), nil, nil)
52 if stale || !found || len(value) != ref.Size {
53 out.Stale = true
54 return out
55 }
56 out.Data, out.Chunks = historyContentChunkAt(value, chunkIndex)
57 out.Done = chunkIndex >= out.Chunks-1
58 return out
59 }
60
60 lines GO