feat: Enhance AI Agent and Channel Management
- Updated labels in the AI Agents dashboard for clarity, changing "流程状态" to "Playbook 状态" and "未发布流程" to "未发布 Playbook". - Introduced AI Agent rollout percentage management in channel editing, allowing users to set and rollback rollout percentages. - Added new API endpoints for rolling back AI Agent rollout and fetching agent run metrics. - Implemented new UI components for displaying agent run details, including status, duration, and input/output tokens. - Enhanced type definitions for AdminChannel and AIAgent to include rollout percentages and runtime modes. - Updated navigation to include a section for agent runs. - Added new translations for agent run features in both English and Chinese.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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
|
||||
}
|
||||
|
||||
func (r *agentRevisionRepository) TakeByAgentIDAndWorkflowVersionID(db *gorm.DB, agentID int64, workflowVersionID int64) *models.AgentRevision {
|
||||
if agentID <= 0 || workflowVersionID <= 0 {
|
||||
return nil
|
||||
}
|
||||
ret := &models.AgentRevision{}
|
||||
if err := db.Where("agent_id = ? AND workflow_version_id = ?", agentID, workflowVersionID).Order("id DESC").First(ret).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"agent-desk/internal/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AgentRunQualityFeedbackRepository = newAgentRunQualityFeedbackRepository()
|
||||
|
||||
func newAgentRunQualityFeedbackRepository() *agentRunQualityFeedbackRepository {
|
||||
return &agentRunQualityFeedbackRepository{}
|
||||
}
|
||||
|
||||
type agentRunQualityFeedbackRepository struct{}
|
||||
|
||||
func (r *agentRunQualityFeedbackRepository) GetByAgentRunID(db *gorm.DB, agentRunID int64) *models.AgentRunQualityFeedback {
|
||||
if agentRunID <= 0 {
|
||||
return nil
|
||||
}
|
||||
item := &models.AgentRunQualityFeedback{}
|
||||
if err := db.Where("agent_run_id = ?", agentRunID).First(item).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
func (r *agentRunQualityFeedbackRepository) FindByAgentRunIDs(db *gorm.DB, agentRunIDs []int64) []models.AgentRunQualityFeedback {
|
||||
if len(agentRunIDs) == 0 {
|
||||
return []models.AgentRunQualityFeedback{}
|
||||
}
|
||||
var items []models.AgentRunQualityFeedback
|
||||
if err := db.Where("agent_run_id IN ?", agentRunIDs).Find(&items).Error; err != nil {
|
||||
return []models.AgentRunQualityFeedback{}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (r *agentRunQualityFeedbackRepository) Create(db *gorm.DB, item *models.AgentRunQualityFeedback) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
|
||||
func (r *agentRunQualityFeedbackRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
|
||||
return db.Model(&models.AgentRunQualityFeedback{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AgentRunRepository = newAgentRunRepository()
|
||||
|
||||
func newAgentRunRepository() *agentRunRepository {
|
||||
return &agentRunRepository{}
|
||||
}
|
||||
|
||||
type agentRunRepository struct{}
|
||||
|
||||
func (r *agentRunRepository) Get(db *gorm.DB, id int64) *models.AgentRun {
|
||||
ret := &models.AgentRun{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) TakeByWorkflowRunID(db *gorm.DB, workflowRunID int64) *models.AgentRun {
|
||||
if workflowRunID <= 0 {
|
||||
return nil
|
||||
}
|
||||
ret := &models.AgentRun{}
|
||||
if err := db.Where("workflow_run_id = ?", workflowRunID).Order("id DESC").First(ret).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) Create(db *gorm.DB, item *models.AgentRun) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentRun, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
return list, &sqls.Paging{Page: cnd.Paging.Page, Limit: cnd.Paging.Limit, Total: cnd.Count(db, &models.AgentRun{})}
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) FindPageByParams(db *gorm.DB, queryParams *params.QueryParams) (list []models.AgentRun, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, &queryParams.Cnd)
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
|
||||
return db.Model(&models.AgentRun{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) FindRecent(db *gorm.DB, aiAgentID int64, limit int) []models.AgentRun {
|
||||
if limit <= 0 || limit > 5000 {
|
||||
limit = 5000
|
||||
}
|
||||
query := db.Order("id DESC").Limit(limit)
|
||||
if aiAgentID > 0 {
|
||||
query = query.Where("ai_agent_id = ?", aiAgentID)
|
||||
}
|
||||
var items []models.AgentRun
|
||||
if err := query.Find(&items).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"agent-desk/internal/models"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AgentStepRepository = newAgentStepRepository()
|
||||
|
||||
func newAgentStepRepository() *agentStepRepository {
|
||||
return &agentStepRepository{}
|
||||
}
|
||||
|
||||
type agentStepRepository struct{}
|
||||
|
||||
func (r *agentStepRepository) Create(db *gorm.DB, item *models.AgentStep) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
|
||||
func (r *agentStepRepository) FindByAgentRunID(db *gorm.DB, agentRunID int64) []models.AgentStep {
|
||||
if agentRunID <= 0 {
|
||||
return []models.AgentStep{}
|
||||
}
|
||||
return r.Find(db, sqls.NewCnd().Eq("agent_run_id", agentRunID).Asc("id"))
|
||||
}
|
||||
|
||||
func (r *agentStepRepository) LastByAgentRunID(db *gorm.DB, agentRunID int64) *models.AgentStep {
|
||||
if agentRunID <= 0 {
|
||||
return nil
|
||||
}
|
||||
ret := &models.AgentStep{}
|
||||
if err := db.Where("agent_run_id = ?", agentRunID).Order("id DESC").First(ret).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *agentStepRepository) FindByAgentRunIDs(db *gorm.DB, agentRunIDs []int64) []models.AgentStep {
|
||||
if len(agentRunIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var items []models.AgentStep
|
||||
if err := db.Where("agent_run_id IN ?", agentRunIDs).Find(&items).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (r *agentStepRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentStep) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"agent-desk/internal/models"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AgentToolCallRepository = newAgentToolCallRepository()
|
||||
|
||||
func newAgentToolCallRepository() *agentToolCallRepository {
|
||||
return &agentToolCallRepository{}
|
||||
}
|
||||
|
||||
type agentToolCallRepository struct{}
|
||||
|
||||
func (r *agentToolCallRepository) Create(db *gorm.DB, item *models.AgentToolCall) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
|
||||
func (r *agentToolCallRepository) FindByAgentRunID(db *gorm.DB, agentRunID int64) []models.AgentToolCall {
|
||||
if agentRunID <= 0 {
|
||||
return []models.AgentToolCall{}
|
||||
}
|
||||
return r.Find(db, sqls.NewCnd().Eq("agent_run_id", agentRunID).Asc("id"))
|
||||
}
|
||||
|
||||
func (r *agentToolCallRepository) FindByAgentRunIDs(db *gorm.DB, agentRunIDs []int64) []models.AgentToolCall {
|
||||
if len(agentRunIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var items []models.AgentToolCall
|
||||
if err := db.Where("agent_run_id IN ?", agentRunIDs).Find(&items).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (r *agentToolCallRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AgentToolCall) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"agent-desk/internal/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AgentToolInvocationRepository = newAgentToolInvocationRepository()
|
||||
|
||||
func newAgentToolInvocationRepository() *agentToolInvocationRepository {
|
||||
return &agentToolInvocationRepository{}
|
||||
}
|
||||
|
||||
type agentToolInvocationRepository struct{}
|
||||
|
||||
func (r *agentToolInvocationRepository) GetByIdempotencyKey(db *gorm.DB, conversationID int64, toolCode, idempotencyKey string) *models.AgentToolInvocation {
|
||||
if conversationID <= 0 || toolCode == "" || idempotencyKey == "" {
|
||||
return nil
|
||||
}
|
||||
var item models.AgentToolInvocation
|
||||
if err := db.Where("conversation_id = ? AND tool_code = ? AND idempotency_key = ?", conversationID, toolCode, idempotencyKey).First(&item).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return &item
|
||||
}
|
||||
|
||||
func (r *agentToolInvocationRepository) Create(db *gorm.DB, item *models.AgentToolInvocation) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
|
||||
func (r *agentToolInvocationRepository) Updates(db *gorm.DB, id int64, values map[string]any) error {
|
||||
return db.Model(&models.AgentToolInvocation{}).Where("id = ?", id).Updates(values).Error
|
||||
}
|
||||
@@ -39,6 +39,17 @@ func (r *conversationInterruptRepository) FindLatestPendingByConversationID(db *
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *conversationInterruptRepository) FindByAgentRunIDs(db *gorm.DB, agentRunIDs []int64) []models.ConversationInterrupt {
|
||||
if len(agentRunIDs) == 0 {
|
||||
return []models.ConversationInterrupt{}
|
||||
}
|
||||
var items []models.ConversationInterrupt
|
||||
if err := db.Where("agent_run_id IN ?", agentRunIDs).Find(&items).Error; err != nil {
|
||||
return []models.ConversationInterrupt{}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (r *conversationInterruptRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationInterrupt) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
@@ -72,6 +83,8 @@ func (r *conversationInterruptRepository) UpsertByCheckPointID(db *gorm.DB, item
|
||||
columns := map[string]any{
|
||||
"conversation_id": item.ConversationID,
|
||||
"ai_agent_id": item.AIAgentID,
|
||||
"agent_run_id": item.AgentRunID,
|
||||
"agent_step_id": item.AgentStepID,
|
||||
"source_message_id": item.SourceMessageID,
|
||||
"last_resume_message_id": item.LastResumeMessageID,
|
||||
"workflow_run_id": item.WorkflowRunID,
|
||||
|
||||
@@ -77,6 +77,30 @@ func (r *conversationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Conversation{})
|
||||
}
|
||||
|
||||
func (r *conversationRepository) CountByAIAgentID(db *gorm.DB, aiAgentID int64) int64 {
|
||||
query := db.Model(&models.Conversation{})
|
||||
if aiAgentID > 0 {
|
||||
query = query.Where("ai_agent_id = ?", aiAgentID)
|
||||
}
|
||||
var count int64
|
||||
if err := query.Count(&count).Error; err != nil {
|
||||
return 0
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *conversationRepository) CountHandoffByAIAgentID(db *gorm.DB, aiAgentID int64) int64 {
|
||||
query := db.Model(&models.Conversation{}).Where("handoff_at IS NOT NULL")
|
||||
if aiAgentID > 0 {
|
||||
query = query.Where("ai_agent_id = ?", aiAgentID)
|
||||
}
|
||||
var count int64
|
||||
if err := query.Count(&count).Error; err != nil {
|
||||
return 0
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *conversationRepository) Create(db *gorm.DB, t *models.Conversation) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user