Changeset 0.29.0 (#195)
This commit is contained in:
@@ -1,45 +1,44 @@
|
||||
package handlers
|
||||
|
||||
// summarize.go — Manual conversation summarization via HTTP.
|
||||
//
|
||||
// v0.29.0: Raw SQL replaced with ChannelStore methods.
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/compaction"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/database"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/roles"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/store"
|
||||
)
|
||||
|
||||
// SummarizeHandler handles manual conversation summarization via HTTP.
|
||||
type SummarizeHandler struct {
|
||||
stores store.Stores
|
||||
compaction *compaction.Service
|
||||
}
|
||||
|
||||
// NewSummarizeHandler creates a new handler backed by the compaction service.
|
||||
func NewSummarizeHandler(svc *compaction.Service) *SummarizeHandler {
|
||||
return &SummarizeHandler{compaction: svc}
|
||||
func NewSummarizeHandler(stores store.Stores, svc *compaction.Service) *SummarizeHandler {
|
||||
return &SummarizeHandler{stores: stores, compaction: svc}
|
||||
}
|
||||
|
||||
// ── Summarize & Continue ──────────────────
|
||||
// POST /channels/:id/summarize
|
||||
//
|
||||
// User-triggered compaction: calls the utility role to summarize the
|
||||
// conversation history, inserts the summary as a tree node, and returns it.
|
||||
|
||||
func (h *SummarizeHandler) Summarize(c *gin.Context) {
|
||||
channelID := c.Param("id")
|
||||
userID := getUserID(c)
|
||||
|
||||
// ── Verify channel ownership ──
|
||||
var ownerID string
|
||||
err := database.DB.QueryRow(
|
||||
database.Q(`SELECT user_id FROM channels WHERE id = $1`), channelID,
|
||||
).Scan(&ownerID)
|
||||
if err != nil {
|
||||
ch, err := h.stores.Channels.GetByID(c.Request.Context(), channelID)
|
||||
if err != nil || ch == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "channel not found"})
|
||||
return
|
||||
}
|
||||
if ownerID != userID {
|
||||
if ch.UserID != userID {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "not your channel"})
|
||||
return
|
||||
}
|
||||
@@ -73,7 +72,6 @@ func (h *SummarizeHandler) Summarize(c *gin.Context) {
|
||||
Trigger: "manual",
|
||||
})
|
||||
if err != nil {
|
||||
// Map specific errors to HTTP status codes
|
||||
switch err.Error() {
|
||||
case "conversation too short to summarize":
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user