Changeset 0.30.1 (#200)

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
2026-03-18 13:22:15 +00:00
committed by xcaliber
parent 7d14e6a439
commit 8fee53e440
23 changed files with 1294 additions and 846 deletions

View File

@@ -5,13 +5,15 @@ import (
"github.com/gin-gonic/gin"
"git.gobha.me/xcaliber/chat-switchboard/memory"
"git.gobha.me/xcaliber/chat-switchboard/models"
"git.gobha.me/xcaliber/chat-switchboard/store"
)
// MemoryHandler provides REST endpoints for memory management.
type MemoryHandler struct {
stores store.Stores
stores store.Stores
compactor *memory.Compactor
}
// NewMemoryHandler creates a new memory handler.
@@ -19,6 +21,11 @@ func NewMemoryHandler(stores store.Stores) *MemoryHandler {
return &MemoryHandler{stores: stores}
}
// SetCompactor wires the compactor for the /compact endpoint.
func (h *MemoryHandler) SetCompactor(c *memory.Compactor) {
h.compactor = c
}
// ListMyMemories returns the current user's memories with optional filters.
// GET /api/v1/memories?status=active&query=...
func (h *MemoryHandler) ListMyMemories(c *gin.Context) {
@@ -254,3 +261,37 @@ func (h *MemoryHandler) BulkApprove(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"approved": approved})
}
// CompactMemories triggers memory compaction for the current user.
// POST /api/v1/memories/compact
func (h *MemoryHandler) CompactMemories(c *gin.Context) {
if h.compactor == nil {
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "compaction not available"})
return
}
userID := c.GetString("user_id")
if userID == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
return
}
teamID := c.GetString("team_id")
var tID *string
if teamID != "" {
tID = &teamID
}
result, err := h.compactor.Compact(c.Request.Context(), userID, tID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"before": result.Before,
"after": result.After,
"merged": result.Merged,
"archived": result.Archived,
})
}