Files
Agent-System/internal/server/chat_recategorize_api.go
T
weichen a9c9a9182e refactor(server): remove 24 mirrored Runtime fields via nil-safe accessors; fix Shutdown-vs-background-loop DATA RACE and goose 00071 duplicate version
- Server no longer mirrors app.Runtime services (gov/svc/pwSvc/...): 574 call sites now use accessors in runtime_accessors.go
- backgroundLoop (mutex+sync.Once) stops sweeper/publisher/reminder/wsGC goroutines race-free (baseline 44161d2a reproduced DATA RACE; now green under -race)
- goose 00071 duplicate (dialogue merge 1da17a28 brought two 00071): context-conflict-adjudications renumbered to 00072; dev DB applied only through 00070 so zero data migration
- task_finalize tests build minimal app.Runtime; test injection via serverTestOverrides + setOverride* (explicit-nil markers for fail-closed cases)
2026-09-25 13:17:22 +00:00

58 lines
1.3 KiB
Go

package server
// chat_recategorize_api.go — 管理端点 POST /api/v1/chat/recategorize (Spec §3.4 A4)
import (
"encoding/json"
"net/http"
"strings"
)
type recategorizeReq struct {
SessionID string `json:"session_id"`
}
func (s *Server) handleChatRecategorize(w http.ResponseWriter, r *http.Request) {
user, ok := s.requireAuthenticatedUser(w, r)
if !ok {
return
}
if s.ctxMgr() == nil {
writeSafeError(w, r, http.StatusServiceUnavailable, "context manager unavailable")
return
}
var req recategorizeReq
if r.Body != nil {
_ = json.NewDecoder(r.Body).Decode(&req)
}
req.SessionID = strings.TrimSpace(req.SessionID)
if req.SessionID == "" {
writeJSONResponse(w, http.StatusBadRequest, map[string]any{
"success": false,
"error": "session_id is required",
})
return
}
if !s.isSystemAdminUser(r.Context(), user) {
if !s.assertSessionOwnedByUser(w, r, req.SessionID, user.ID) {
return
}
}
res, err := s.ctxMgr().RecategorizeMessages(r.Context(), req.SessionID)
if err != nil {
writeJSONResponse(w, http.StatusInternalServerError, map[string]any{
"success": false,
"error": err.Error(),
})
return
}
writeJSONResponse(w, http.StatusOK, map[string]any{
"success": true,
"total_processed": res.TotalProcessed,
"total_updated": res.TotalUpdated,
})
}