Files
ai-agent/internal/repositories/dashboard_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

109 lines
2.7 KiB
Go

package repositories
import (
"agent-desk/internal/models"
"agent-desk/internal/pkg/enums"
"time"
"gorm.io/gorm"
)
var DashboardRepository = newDashboardRepository()
func newDashboardRepository() *dashboardRepository {
return &dashboardRepository{}
}
type dashboardRepository struct {
}
func (r *dashboardRepository) CountConversations(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.Conversation{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) ListConversations(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) []models.Conversation {
var list []models.Conversation
tx := db.Model(&models.Conversation{})
if query != nil {
tx = query(tx)
}
tx.Find(&list)
return list
}
func (r *dashboardRepository) ListEnabledAgentProfiles(db *gorm.DB) []models.AgentProfile {
var list []models.AgentProfile
db.Model(&models.AgentProfile{}).Where("status = ?", enums.StatusOk).Find(&list)
return list
}
func (r *dashboardRepository) ListEnabledAgentTeams(db *gorm.DB) []models.AgentTeam {
var list []models.AgentTeam
db.Model(&models.AgentTeam{}).Where("status = ?", enums.StatusOk).Order("id asc").Find(&list)
return list
}
func (r *dashboardRepository) ListActiveTeamSchedules(db *gorm.DB, startAt, endAt time.Time) []models.AgentTeamSchedule {
var list []models.AgentTeamSchedule
db.Model(&models.AgentTeamSchedule{}).
Where("status = ? AND start_at <= ? AND end_at >= ?", enums.StatusOk, endAt, startAt).
Find(&list)
return list
}
func (r *dashboardRepository) CountAIAgents(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.AIAgent{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) ListAIAgents(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) []models.AIAgent {
var list []models.AIAgent
tx := db.Model(&models.AIAgent{})
if query != nil {
tx = query(tx)
}
tx.Find(&list)
return list
}
func (r *dashboardRepository) CountChannels(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.Channel{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) CountKnowledgeRetrieveLogs(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.KnowledgeRetrieveLog{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}
func (r *dashboardRepository) CountAgentRuns(db *gorm.DB, query func(tx *gorm.DB) *gorm.DB) int64 {
var count int64
tx := db.Model(&models.AgentRun{})
if query != nil {
tx = query(tx)
}
tx.Count(&count)
return count
}