feat(agent): enhance agent and skill management features
- Updated the API to include disabled agent IDs for better management of user-specific agent visibility. - Introduced a new function to set the disabled state for shared agents, allowing users to manage their shared agent preferences. - Added a new Skills API to retrieve available skills, enhancing the overall agent capabilities. - Improved the AgentSelector and related components to filter out disabled agents, ensuring a cleaner user experience. - Updated localization strings to reflect new features and improve clarity in agent and skill management. This update enhances the user experience by providing better control over agent visibility and introducing new skill management functionalities.
This commit is contained in:
@@ -14,13 +14,15 @@ import (
|
||||
|
||||
// CustomAgentHandler defines the HTTP handler for custom agent operations
|
||||
type CustomAgentHandler struct {
|
||||
service interfaces.CustomAgentService
|
||||
service interfaces.CustomAgentService
|
||||
disabledRepo interfaces.TenantDisabledSharedAgentRepository
|
||||
}
|
||||
|
||||
// NewCustomAgentHandler creates a new custom agent handler instance
|
||||
func NewCustomAgentHandler(service interfaces.CustomAgentService) *CustomAgentHandler {
|
||||
func NewCustomAgentHandler(service interfaces.CustomAgentService, disabledRepo interfaces.TenantDisabledSharedAgentRepository) *CustomAgentHandler {
|
||||
return &CustomAgentHandler{
|
||||
service: service,
|
||||
service: service,
|
||||
disabledRepo: disabledRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +36,10 @@ type CreateAgentRequest struct {
|
||||
|
||||
// UpdateAgentRequest defines the request body for updating an agent
|
||||
type UpdateAgentRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Avatar string `json:"avatar"`
|
||||
Config types.CustomAgentConfig `json:"config"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Avatar string `json:"avatar"`
|
||||
Config types.CustomAgentConfig `json:"config"`
|
||||
}
|
||||
|
||||
// CreateAgent godoc
|
||||
@@ -161,9 +163,14 @@ func (h *CustomAgentHandler) ListAgents(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Per-tenant "disabled by me" for own agents (only affects this tenant's conversation dropdown)
|
||||
tenantID, _ := c.Get(types.TenantIDContextKey.String())
|
||||
disabledOwnIDs, _ := h.disabledRepo.ListDisabledOwnAgentIDs(ctx, tenantID.(uint64))
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": agents,
|
||||
"success": true,
|
||||
"data": agents,
|
||||
"disabled_own_agent_ids": disabledOwnIDs,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,13 @@ import (
|
||||
|
||||
// OrganizationHandler implements HTTP request handlers for organization management
|
||||
type OrganizationHandler struct {
|
||||
orgService interfaces.OrganizationService
|
||||
shareService interfaces.KBShareService
|
||||
agentShareService interfaces.AgentShareService
|
||||
userService interfaces.UserService
|
||||
knowledgeRepo interfaces.KnowledgeRepository
|
||||
chunkRepo interfaces.ChunkRepository
|
||||
orgService interfaces.OrganizationService
|
||||
shareService interfaces.KBShareService
|
||||
agentShareService interfaces.AgentShareService
|
||||
customAgentService interfaces.CustomAgentService
|
||||
userService interfaces.UserService
|
||||
knowledgeRepo interfaces.KnowledgeRepository
|
||||
chunkRepo interfaces.ChunkRepository
|
||||
}
|
||||
|
||||
// NewOrganizationHandler creates a new organization handler
|
||||
@@ -31,17 +32,19 @@ func NewOrganizationHandler(
|
||||
orgService interfaces.OrganizationService,
|
||||
shareService interfaces.KBShareService,
|
||||
agentShareService interfaces.AgentShareService,
|
||||
customAgentService interfaces.CustomAgentService,
|
||||
userService interfaces.UserService,
|
||||
knowledgeRepo interfaces.KnowledgeRepository,
|
||||
chunkRepo interfaces.ChunkRepository,
|
||||
) *OrganizationHandler {
|
||||
return &OrganizationHandler{
|
||||
orgService: orgService,
|
||||
shareService: shareService,
|
||||
agentShareService: agentShareService,
|
||||
userService: userService,
|
||||
knowledgeRepo: knowledgeRepo,
|
||||
chunkRepo: chunkRepo,
|
||||
orgService: orgService,
|
||||
shareService: shareService,
|
||||
agentShareService: agentShareService,
|
||||
customAgentService: customAgentService,
|
||||
userService: userService,
|
||||
knowledgeRepo: knowledgeRepo,
|
||||
chunkRepo: chunkRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1252,6 +1255,46 @@ func (h *OrganizationHandler) ListSharedAgents(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": list, "total": len(list)})
|
||||
}
|
||||
|
||||
// SetSharedAgentDisabledByMeRequest is the body for POST /shared-agents/disabled
|
||||
type SetSharedAgentDisabledByMeRequest struct {
|
||||
AgentID string `json:"agent_id" binding:"required"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
// SetSharedAgentDisabledByMe sets whether the current tenant has disabled this shared agent for their conversation dropdown
|
||||
func (h *OrganizationHandler) SetSharedAgentDisabledByMe(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
userID, _ := c.Get(types.UserIDContextKey.String())
|
||||
tenantID, _ := c.Get(types.TenantIDContextKey.String())
|
||||
uid := userID.(string)
|
||||
tid := tenantID.(uint64)
|
||||
|
||||
var req SetSharedAgentDisabledByMeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.Error(apperrors.NewBadRequestError("Invalid request").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
// Derive sourceTenantID: own agent (current tenant) or from shared list
|
||||
var sourceTenantID uint64
|
||||
agent, err := h.customAgentService.GetAgentByID(ctx, req.AgentID)
|
||||
if err == nil && agent != nil && agent.TenantID == tid {
|
||||
sourceTenantID = tid
|
||||
} else {
|
||||
share, err := h.agentShareService.GetShareByAgentIDForUser(ctx, uid, req.AgentID, tid)
|
||||
if err != nil || share == nil {
|
||||
c.Error(apperrors.NewForbiddenError("No access to this agent"))
|
||||
return
|
||||
}
|
||||
sourceTenantID = share.SourceTenantID
|
||||
}
|
||||
if err := h.agentShareService.SetSharedAgentDisabledByMe(ctx, tid, req.AgentID, sourceTenantID, req.Disabled); err != nil {
|
||||
logger.Errorf(ctx, "SetSharedAgentDisabledByMe failed: %v", err)
|
||||
c.Error(apperrors.NewInternalServerError("Failed to update preference"))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true})
|
||||
}
|
||||
|
||||
// toOrgResponse converts an organization to response format
|
||||
func (h *OrganizationHandler) toOrgResponse(ctx context.Context, org *types.Organization, currentUserID string) types.OrganizationResponse {
|
||||
resp := types.OrganizationResponse{
|
||||
|
||||
Reference in New Issue
Block a user