返回 DeepSeek-Reasonix
compact.go
根目录 / internal / serve / compact.go
1 package serve
2
3 import (
4 "encoding/json"
5 "io"
6 "log/slog"
7 "net/http"
8 "strings"
9 )
10
11 func (s *Server) compact(w http.ResponseWriter, r *http.Request) {
12 var body struct {
13 Instructions string `json:"instructions"`
14 }
15 if err := json.NewDecoder(r.Body).Decode(&body); err != nil && err != io.EOF {
16 http.Error(w, "bad body", http.StatusBadRequest)
17 return
18 }
19 if err := s.ctl().Compact(r.Context(), strings.TrimSpace(body.Instructions)); err != nil {
20 http.Error(w, err.Error(), http.StatusInternalServerError)
21 return
22 }
23 // Persist the compacted session to disk — ctrl.Compact() only mutates in-memory.
24 if err := s.ctl().Snapshot(); err != nil {
25 slog.Warn("serve: snapshot after compact", "err", err)
26 }
27 w.WriteHeader(http.StatusNoContent)
28 }
29
29 lines GO