feat(ai): add personal summary models and retire Q&A
Add an admin-managed provider model catalog with per-user summary selection, migration backfill, and generation snapshots. Retire report creation and messaging while preserving owner-scoped history. Refs #15 #16 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -17,44 +17,7 @@ type reportRequest struct {
|
||||
}
|
||||
|
||||
func (h *Handler) CreateReport(c *gin.Context) {
|
||||
userID := c.GetString("userID")
|
||||
var req reportRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httputil.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
summary, err := h.repo.GetOwnedSummary(req.SummaryID, userID)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
if summary == nil {
|
||||
httputil.NotFound(c)
|
||||
return
|
||||
}
|
||||
for _, excerpt := range req.Excerpts {
|
||||
if strings.TrimSpace(excerpt) == "" || !strings.Contains(summary.Content, excerpt) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "excerpt must come from the summary"})
|
||||
return
|
||||
}
|
||||
}
|
||||
summaryID := &summary.ID
|
||||
|
||||
// Joindre les extraits avec un séparateur visuel
|
||||
excerpt := buildExcerptContext(req.Excerpts)
|
||||
|
||||
// Créer le rapport en DB avec status=generating, retourner immédiatement
|
||||
report, err := h.repo.CreatePendingReport(userID, summaryID, excerpt, req.Question)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Lancer la génération en arrière-plan
|
||||
h.pipeline.GenerateReportAsync(userID, report.ID, excerpt, req.Question, h.reportManager)
|
||||
|
||||
c.JSON(http.StatusCreated, report)
|
||||
c.JSON(http.StatusGone, gin.H{"error": "reports_read_only"})
|
||||
}
|
||||
|
||||
func (h *Handler) ListReports(c *gin.Context) {
|
||||
@ -64,6 +27,14 @@ func (h *Handler) ListReports(c *gin.Context) {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
// Historical generating records have no worker after Q&A retirement.
|
||||
// Project an honest interrupted state; never rewrite the stored history.
|
||||
for i := range reports {
|
||||
if reports[i].Status == "generating" {
|
||||
reports[i].Status = "error"
|
||||
reports[i].ErrorMsg = "historical_generation_interrupted"
|
||||
}
|
||||
}
|
||||
httputil.OK(c, reports)
|
||||
}
|
||||
|
||||
@ -111,58 +82,16 @@ func (h *Handler) ListReportMessages(c *gin.Context) {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
for i := range msgs {
|
||||
if msgs[i].Status == "generating" {
|
||||
msgs[i].Status = "error"
|
||||
}
|
||||
}
|
||||
httputil.OK(c, msgs)
|
||||
}
|
||||
|
||||
func (h *Handler) CreateReportMessage(c *gin.Context) {
|
||||
userID := c.GetString("userID")
|
||||
reportID := c.Param("id")
|
||||
|
||||
var req struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
httputil.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
report, err := h.repo.GetReport(reportID, userID)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
if report == nil || report.Status != "done" {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Récupérer l'historique pour le contexte IA
|
||||
history, err := h.repo.ListReportMessages(reportID)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Persister le message utilisateur
|
||||
userMsg, err := h.repo.CreateReportMessage(reportID, "user", req.Content, "done")
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Créer le message assistant en attente
|
||||
assistantMsg, err := h.repo.CreateReportMessage(reportID, "assistant", "", "generating")
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Ajouter le message utilisateur à l'historique avant de lancer la génération
|
||||
history = append(history, *userMsg)
|
||||
|
||||
h.pipeline.GenerateReportMessageAsync(assistantMsg.ID, report, history, h.reportManager)
|
||||
|
||||
c.JSON(http.StatusCreated, assistantMsg)
|
||||
c.JSON(http.StatusGone, gin.H{"error": "reports_read_only"})
|
||||
}
|
||||
|
||||
func buildExcerptContext(excerpts []string) string {
|
||||
|
||||
Reference in New Issue
Block a user