Files
ai-agent/internal/repositories/agent_revision_repository.go
T
mlogclub 847f688398 Refactor AI Agent configuration and workflow handling
- Removed runtime mode handling from AIAgentConfigWorkbench and related components.
- Updated tests to reflect changes in AI Agent policy copy and configuration.
- Changed terminology from "workflow" to "revision" in various components and API responses.
- Simplified agent binding logic in channel editing.
- Cleaned up unused variables and types related to runtime modes.
- Updated localization files for consistency with new terminology.
2026-07-27 23:29:02 +08:00

46 lines
1.1 KiB
Go

package repositories
import (
"agent-desk/internal/models"
"gorm.io/gorm"
)
var AgentRevisionRepository = newAgentRevisionRepository()
func newAgentRevisionRepository() *agentRevisionRepository {
return &agentRevisionRepository{}
}
type agentRevisionRepository struct{}
func (r *agentRevisionRepository) Get(db *gorm.DB, id int64) *models.AgentRevision {
ret := &models.AgentRevision{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *agentRevisionRepository) Create(db *gorm.DB, item *models.AgentRevision) error {
return db.Create(item).Error
}
func (r *agentRevisionRepository) FindByAgentID(db *gorm.DB, agentID int64) []models.AgentRevision {
if agentID <= 0 {
return []models.AgentRevision{}
}
items := make([]models.AgentRevision, 0)
db.Where("agent_id = ?", agentID).Order("revision DESC, id DESC").Find(&items)
return items
}
func (r *agentRevisionRepository) MaxRevisionByAgentID(db *gorm.DB, agentID int64) int {
if agentID <= 0 {
return 0
}
var ret int
db.Model(&models.AgentRevision{}).Where("agent_id = ?", agentID).Select("COALESCE(MAX(revision), 0)").Scan(&ret)
return ret
}