89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/yourname/cyrene-ai/gateway/internal/middleware"
|
|
)
|
|
|
|
// MemoryHandler 记忆查询处理器
|
|
type MemoryHandler struct {
|
|
// MVP阶段:直接透传到AI-Core,Gateway本身不需要记忆存储
|
|
aiCoreURL string
|
|
client *http.Client
|
|
}
|
|
|
|
// NewMemoryHandler 创建记忆处理器
|
|
func NewMemoryHandler(aiCoreURL string) *MemoryHandler {
|
|
return &MemoryHandler{
|
|
aiCoreURL: aiCoreURL,
|
|
client: &http.Client{},
|
|
}
|
|
}
|
|
|
|
// Query 查询用户记忆
|
|
func (h *MemoryHandler) Query(c *gin.Context) {
|
|
userID := middleware.GetUserID(c)
|
|
|
|
query := c.Query("q")
|
|
if query == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "查询参数q不能为空"})
|
|
return
|
|
}
|
|
|
|
// MVP阶段:返回简单的内存数据
|
|
// 后续将请求转发到AI-Core的记忆API
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"user_id": userID,
|
|
"query": query,
|
|
"memories": []gin.H{},
|
|
"message": "记忆查询功能将在后续版本中接入AI-Core",
|
|
})
|
|
}
|
|
|
|
// List 列出用户所有记忆
|
|
func (h *MemoryHandler) List(c *gin.Context) {
|
|
userID := middleware.GetUserID(c)
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"user_id": userID,
|
|
"memories": []gin.H{},
|
|
"message": "记忆列表功能将在后续版本中接入AI-Core",
|
|
})
|
|
}
|
|
|
|
// Add 手动添加记忆
|
|
func (h *MemoryHandler) Add(c *gin.Context) {
|
|
userID := middleware.GetUserID(c)
|
|
|
|
var req struct {
|
|
Content string `json:"content" binding:"required"`
|
|
Category string `json:"category"`
|
|
Priority int `json:"priority"`
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "请求参数无效"})
|
|
return
|
|
}
|
|
|
|
if req.Category == "" {
|
|
req.Category = "other"
|
|
}
|
|
if req.Priority <= 0 {
|
|
req.Priority = 1
|
|
}
|
|
|
|
// MVP阶段:返回成功但暂不持久化
|
|
c.JSON(http.StatusCreated, gin.H{
|
|
"status": "accepted",
|
|
"user_id": userID,
|
|
"content": req.Content,
|
|
"category": req.Category,
|
|
"priority": req.Priority,
|
|
"message": "记忆手动添加功能将在后续版本中接入AI-Core",
|
|
})
|
|
}
|