Files
Agent-System-Backend/internal/server/rewind.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

57 lines
1.6 KiB
Go

package server
import (
"encoding/json"
"errors"
"net/http"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/runmgr"
)
func (s *Server) listCheckpoints(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
owner := s.owner(r)
if _, err := s.st.GetConversation(owner, id); err != nil {
writeStoreErr(w, err)
return
}
messageID := r.URL.Query().Get("messageId")
plan, err := s.mgr.PlanRewind(owner, id, messageID)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
writeJSON(w, http.StatusOK, map[string]any{"restored": plan.Restored, "skipped": plan.Skipped})
}
func (s *Server) rewindFiles(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
owner := s.owner(r)
if _, err := s.st.GetConversation(owner, id); err != nil {
writeStoreErr(w, err)
return
}
var req struct {
MessageID string `json:"messageId"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || req.MessageID == "" {
http.Error(w, "messageId required", http.StatusBadRequest)
return
}
if err := s.mgr.ClaimConversation(id); err != nil {
if errors.Is(err, runmgr.ErrConversationBusy) {
http.Error(w, "conversation busy", http.StatusConflict)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer s.mgr.ReleaseConversation(id)
res, err := s.mgr.RewindFiles(owner, id, req.MessageID)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
writeJSON(w, http.StatusOK, map[string]any{"restored": res.Restored, "skipped": res.Skipped})
}