feat: 更新 Server 后端服务
- 更新 agent handler 和 service 层 - 新增 chat_group handler 和 service - 删除废弃的 chat_handler - 更新 tool 相关处理 - 更新 API 文档和依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,13 @@ func (r *AgentRepository) FindAll() ([]model.Agent, error) {
|
||||
return agents, err
|
||||
}
|
||||
|
||||
// FindByIDs 根据多个ID查询
|
||||
func (r *AgentRepository) FindByIDs(ids []string) ([]model.Agent, error) {
|
||||
var agents []model.Agent
|
||||
err := r.db.Where("id IN ?", ids).Find(&agents).Error
|
||||
return agents, err
|
||||
}
|
||||
|
||||
func (r *AgentRepository) Update(agent *model.Agent) error {
|
||||
return r.db.Save(agent).Error
|
||||
}
|
||||
@@ -101,6 +108,103 @@ func (r *AgentRepository) DeleteMemory(id string) error {
|
||||
return r.db.Delete(&model.AgentMemory{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// FindMemories 通用查询记忆,支持分类和类型过滤
|
||||
func (r *AgentRepository) FindMemories(agentID, userID, category, memoryType string, limit, offset int) ([]model.AgentMemory, int64, error) {
|
||||
var memories []model.AgentMemory
|
||||
query := r.db.Model(&model.AgentMemory{})
|
||||
|
||||
if agentID != "" {
|
||||
query = query.Where("agent_id = ?", agentID)
|
||||
}
|
||||
if userID != "" {
|
||||
query = query.Where("user_id = ?", userID)
|
||||
}
|
||||
if category != "" {
|
||||
query = query.Where("category = ?", category)
|
||||
}
|
||||
if memoryType != "" {
|
||||
query = query.Where("memory_type = ?", memoryType)
|
||||
}
|
||||
|
||||
// 统计总数
|
||||
var total int64
|
||||
countQuery := query
|
||||
if err := countQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 置顶的记忆优先,然后按重要性降序,最后按创建时间降序
|
||||
err := query.Order("is_pinned DESC, importance DESC, created_at DESC").Limit(limit).Offset(offset).Find(&memories).Error
|
||||
return memories, total, err
|
||||
}
|
||||
|
||||
// SearchMemories 搜索记忆
|
||||
func (r *AgentRepository) SearchMemories(agentID, userID, keyword, tags, category, memoryType string, minScore, limit, offset int) ([]model.AgentMemory, int64, error) {
|
||||
var memories []model.AgentMemory
|
||||
query := r.db.Model(&model.AgentMemory{})
|
||||
|
||||
if agentID != "" {
|
||||
query = query.Where("agent_id = ?", agentID)
|
||||
}
|
||||
if userID != "" {
|
||||
query = query.Where("user_id = ?", userID)
|
||||
}
|
||||
if keyword != "" {
|
||||
keyword = "%" + keyword + "%"
|
||||
query = query.Where("content LIKE ? OR keywords LIKE ? OR tags LIKE ?", keyword, keyword, keyword)
|
||||
}
|
||||
if category != "" {
|
||||
query = query.Where("category = ?", category)
|
||||
}
|
||||
if memoryType != "" {
|
||||
query = query.Where("memory_type = ?", memoryType)
|
||||
}
|
||||
if minScore > 0 {
|
||||
query = query.Where("importance >= ?", minScore)
|
||||
}
|
||||
|
||||
// 统计总数
|
||||
var total int64
|
||||
countQuery := query
|
||||
if err := countQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err := query.Order("is_pinned DESC, importance DESC, created_at DESC").Limit(limit).Offset(offset).Find(&memories).Error
|
||||
return memories, total, err
|
||||
}
|
||||
|
||||
// FindMemoryByID 根据ID查询记忆
|
||||
func (r *AgentRepository) FindMemoryByID(id string) (*model.AgentMemory, error) {
|
||||
var memory model.AgentMemory
|
||||
err := r.db.Where("id = ?", id).First(&memory).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &memory, nil
|
||||
}
|
||||
|
||||
// UpdateMemory 更新记忆
|
||||
func (r *AgentRepository) UpdateMemory(memory *model.AgentMemory) error {
|
||||
return r.db.Save(memory).Error
|
||||
}
|
||||
|
||||
// FindMemoryCategories 获取记忆分类列表
|
||||
func (r *AgentRepository) FindMemoryCategories(agentID, userID string) ([]string, error) {
|
||||
var categories []string
|
||||
query := r.db.Model(&model.AgentMemory{}).Distinct("category")
|
||||
|
||||
if agentID != "" {
|
||||
query = query.Where("agent_id = ?", agentID)
|
||||
}
|
||||
if userID != "" {
|
||||
query = query.Where("user_id = ?", userID)
|
||||
}
|
||||
|
||||
err := query.Pluck("category", &categories).Error
|
||||
return categories, err
|
||||
}
|
||||
|
||||
// AgentTeam 相关方法
|
||||
|
||||
func (r *AgentRepository) CreateAgentTeam(team *model.AgentTeam) error {
|
||||
|
||||
@@ -44,6 +44,15 @@ func (r *ToolRepository) FindByID(id string) (*model.Tool, error) {
|
||||
return &tool, nil
|
||||
}
|
||||
|
||||
func (r *ToolRepository) FindByName(name string) (*model.Tool, error) {
|
||||
var tool model.Tool
|
||||
err := r.db.First(&tool, "name = ?", name).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &tool, nil
|
||||
}
|
||||
|
||||
func (r *ToolRepository) Update(tool *model.Tool) error {
|
||||
return r.db.Save(tool).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user