feat(agent): enhance agent sharing and selection features
- Updated the AgentSelector component to improve agent selection logic, ensuring accurate representation of selected agents. - Introduced new AgentShareSettings component for managing agent sharing with organizations, including UI for selecting organizations and displaying shared agents. - Enhanced API interactions for sharing agents, including new methods for listing and managing agent shares. - Improved localization support for agent sharing features across multiple languages. - Updated various components to reflect changes in agent capabilities and sharing status, enhancing user experience and clarity. This update strengthens the agent management features, providing users with better tools for sharing and selecting agents within organizations.
This commit is contained in:
@@ -19,7 +19,7 @@ type CustomAgentService interface {
|
||||
// - Possible errors such as insufficient permissions, validation errors, etc.
|
||||
CreateAgent(ctx context.Context, agent *types.CustomAgent) (*types.CustomAgent, error)
|
||||
|
||||
// GetAgentByID retrieves agent information by ID
|
||||
// GetAgentByID retrieves agent information by ID (uses tenant from context)
|
||||
// Parameters:
|
||||
// - ctx: Context information
|
||||
// - id: Unique identifier of the agent
|
||||
@@ -28,6 +28,9 @@ type CustomAgentService interface {
|
||||
// - Possible errors such as not existing, insufficient permissions, etc.
|
||||
GetAgentByID(ctx context.Context, id string) (*types.CustomAgent, error)
|
||||
|
||||
// GetAgentByIDAndTenant retrieves agent by ID and tenant (for shared agents; skips built-in resolution)
|
||||
GetAgentByIDAndTenant(ctx context.Context, id string, tenantID uint64) (*types.CustomAgent, error)
|
||||
|
||||
// ListAgents lists all agents under the current tenant (including built-in agents)
|
||||
// Parameters:
|
||||
// - ctx: Context information, containing tenant information
|
||||
|
||||
@@ -146,6 +146,8 @@ type KnowledgeService interface {
|
||||
// SearchKnowledge searches knowledge items by keyword across the tenant.
|
||||
// fileTypes: optional list of file extensions to filter by (e.g., ["csv", "xlsx"])
|
||||
SearchKnowledge(ctx context.Context, keyword string, offset, limit int, fileTypes []string) ([]*types.Knowledge, bool, error)
|
||||
// SearchKnowledgeForScopes searches knowledge within the given (tenant_id, kb_id) scopes (e.g. for shared agent context).
|
||||
SearchKnowledgeForScopes(ctx context.Context, scopes []types.KnowledgeSearchScope, keyword string, offset, limit int, fileTypes []string) ([]*types.Knowledge, bool, error)
|
||||
}
|
||||
|
||||
// KnowledgeRepository defines the interface for knowledge repositories.
|
||||
|
||||
@@ -42,6 +42,12 @@ type KnowledgeBaseService interface {
|
||||
// - Possible errors such as not existing, etc.
|
||||
GetKnowledgeBaseByIDOnly(ctx context.Context, id string) (*types.KnowledgeBase, error)
|
||||
|
||||
// GetKnowledgeBasesByIDsOnly retrieves knowledge bases by IDs without tenant filter (batch).
|
||||
GetKnowledgeBasesByIDsOnly(ctx context.Context, ids []string) ([]*types.KnowledgeBase, error)
|
||||
|
||||
// FillKnowledgeBaseCounts fills KnowledgeCount, ChunkCount, IsProcessing, ProcessingCount for the given KB (uses kb.TenantID).
|
||||
FillKnowledgeBaseCounts(ctx context.Context, kb *types.KnowledgeBase) error
|
||||
|
||||
// ListKnowledgeBases lists all knowledge bases under the current tenant
|
||||
// Parameters:
|
||||
// - ctx: Context information, containing tenant information
|
||||
@@ -49,6 +55,8 @@ type KnowledgeBaseService interface {
|
||||
// - List of knowledge base objects
|
||||
// - Possible errors such as insufficient permissions, etc.
|
||||
ListKnowledgeBases(ctx context.Context) ([]*types.KnowledgeBase, error)
|
||||
// ListKnowledgeBasesByTenantID lists all knowledge bases for a specific tenant (e.g. for shared agent context).
|
||||
ListKnowledgeBasesByTenantID(ctx context.Context, tenantID uint64) ([]*types.KnowledgeBase, error)
|
||||
|
||||
// UpdateKnowledgeBase updates knowledge base information
|
||||
// Parameters:
|
||||
|
||||
@@ -127,3 +127,32 @@ type KBShareRepository interface {
|
||||
CountSharesByKnowledgeBaseID(ctx context.Context, kbID string) (int64, error)
|
||||
CountSharesByKnowledgeBaseIDs(ctx context.Context, kbIDs []string) (map[string]int64, error)
|
||||
}
|
||||
|
||||
// AgentShareService defines the agent sharing service interface
|
||||
type AgentShareService interface {
|
||||
ShareAgent(ctx context.Context, agentID string, orgID string, userID string, tenantID uint64, permission types.OrgMemberRole) (*types.AgentShare, error)
|
||||
RemoveShare(ctx context.Context, shareID string, userID string) error
|
||||
ListSharesByAgent(ctx context.Context, agentID string) ([]*types.AgentShare, error)
|
||||
ListSharesByOrganization(ctx context.Context, orgID string) ([]*types.AgentShare, error)
|
||||
ListSharedAgents(ctx context.Context, userID string, currentTenantID uint64) ([]*types.SharedAgentInfo, error)
|
||||
// GetSharedAgentForUser returns the shared agent by agentID if the user has access (source tenant is resolved from share); used to resolve KB scope for @ mention.
|
||||
GetSharedAgentForUser(ctx context.Context, userID string, currentTenantID uint64, agentID string) (*types.CustomAgent, error)
|
||||
GetShare(ctx context.Context, shareID string) (*types.AgentShare, error)
|
||||
GetShareByAgentAndOrg(ctx context.Context, agentID string, orgID string) (*types.AgentShare, error)
|
||||
}
|
||||
|
||||
// AgentShareRepository defines the agent sharing repository interface
|
||||
type AgentShareRepository interface {
|
||||
Create(ctx context.Context, share *types.AgentShare) error
|
||||
GetByID(ctx context.Context, id string) (*types.AgentShare, error)
|
||||
GetByAgentAndOrg(ctx context.Context, agentID string, orgID string) (*types.AgentShare, error)
|
||||
Update(ctx context.Context, share *types.AgentShare) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
DeleteByAgentIDAndSourceTenant(ctx context.Context, agentID string, sourceTenantID uint64) error
|
||||
DeleteByOrganizationID(ctx context.Context, orgID string) error
|
||||
ListByAgent(ctx context.Context, agentID string) ([]*types.AgentShare, error)
|
||||
ListByOrganization(ctx context.Context, orgID string) ([]*types.AgentShare, error)
|
||||
ListSharedAgentsForUser(ctx context.Context, userID string) ([]*types.AgentShare, error)
|
||||
// GetShareByAgentIDForUser returns one share for the given agentID that the user can access (user in org), excluding source_tenant_id == excludeTenantID.
|
||||
GetShareByAgentIDForUser(ctx context.Context, userID, agentID string, excludeTenantID uint64) (*types.AgentShare, error)
|
||||
}
|
||||
|
||||
@@ -210,6 +210,39 @@ type SharedKnowledgeBaseInfo struct {
|
||||
SharedAt time.Time `json:"shared_at"`
|
||||
}
|
||||
|
||||
// AgentShare represents a sharing record of an agent to an organization
|
||||
type AgentShare struct {
|
||||
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
||||
AgentID string `json:"agent_id" gorm:"type:varchar(36);not null;index"`
|
||||
OrganizationID string `json:"organization_id" gorm:"type:varchar(36);not null;index"`
|
||||
SharedByUserID string `json:"shared_by_user_id" gorm:"type:varchar(36);not null"`
|
||||
SourceTenantID uint64 `json:"source_tenant_id" gorm:"not null;index"`
|
||||
Permission OrgMemberRole `json:"permission" gorm:"type:varchar(32);not null;default:'viewer'"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
Agent *CustomAgent `json:"agent,omitempty" gorm:"foreignKey:AgentID,SourceTenantID;references:ID,TenantID"`
|
||||
Organization *Organization `json:"organization,omitempty" gorm:"foreignKey:OrganizationID"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (AgentShare) TableName() string {
|
||||
return "agent_shares"
|
||||
}
|
||||
|
||||
// SharedAgentInfo represents a shared agent with additional sharing info
|
||||
type SharedAgentInfo struct {
|
||||
Agent *CustomAgent `json:"agent"`
|
||||
ShareID string `json:"share_id"`
|
||||
OrganizationID string `json:"organization_id"`
|
||||
OrgName string `json:"org_name"`
|
||||
Permission OrgMemberRole `json:"permission"`
|
||||
SourceTenantID uint64 `json:"source_tenant_id"`
|
||||
SharedAt time.Time `json:"shared_at"`
|
||||
SharedByUserID string `json:"shared_by_user_id,omitempty"`
|
||||
SharedByUsername string `json:"shared_by_username,omitempty"`
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// Request/Response Types
|
||||
// ----------------------
|
||||
@@ -302,6 +335,7 @@ type OrganizationResponse struct {
|
||||
MemberLimit int `json:"member_limit"` // 0 = unlimited
|
||||
MemberCount int `json:"member_count"`
|
||||
ShareCount int `json:"share_count"` // 共享到该组织的知识库数量
|
||||
AgentShareCount int `json:"agent_share_count"` // 共享到该组织的智能体数量
|
||||
PendingJoinRequestCount int `json:"pending_join_request_count"` // 待审批加入申请数(仅管理员可见)
|
||||
IsOwner bool `json:"is_owner"`
|
||||
MyRole string `json:"my_role,omitempty"`
|
||||
@@ -342,6 +376,30 @@ type KnowledgeBaseShareResponse struct {
|
||||
RequireApproval bool `json:"require_approval"`
|
||||
}
|
||||
|
||||
// AgentShareResponse represents an agent share record in API responses
|
||||
type AgentShareResponse struct {
|
||||
ID string `json:"id"`
|
||||
AgentID string `json:"agent_id"`
|
||||
AgentName string `json:"agent_name"`
|
||||
OrganizationID string `json:"organization_id"`
|
||||
OrganizationName string `json:"organization_name"`
|
||||
SharedByUserID string `json:"shared_by_user_id"`
|
||||
SharedByUsername string `json:"shared_by_username"`
|
||||
SourceTenantID uint64 `json:"source_tenant_id"`
|
||||
Permission string `json:"permission"`
|
||||
MyRoleInOrg string `json:"my_role_in_org,omitempty"`
|
||||
MyPermission string `json:"my_permission,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// Agent scope summary for list display (from agent config when available)
|
||||
ScopeKB string `json:"scope_kb,omitempty"` // "all" | "selected" | "none"
|
||||
ScopeKBCount int `json:"scope_kb_count,omitempty"` // when selected
|
||||
ScopeWebSearch bool `json:"scope_web_search,omitempty"`
|
||||
ScopeMCP string `json:"scope_mcp,omitempty"` // "all" | "selected" | "none"
|
||||
ScopeMCPCount int `json:"scope_mcp_count,omitempty"` // when selected
|
||||
// Agent avatar (emoji or icon name) for list display
|
||||
AgentAvatar string `json:"agent_avatar,omitempty"`
|
||||
}
|
||||
|
||||
// ListOrganizationsResponse represents the response for listing organizations
|
||||
type ListOrganizationsResponse struct {
|
||||
Organizations []OrganizationResponse `json:"organizations"`
|
||||
@@ -357,6 +415,7 @@ type SearchableOrganizationItem struct {
|
||||
MemberCount int `json:"member_count"`
|
||||
MemberLimit int `json:"member_limit"` // 0 = unlimited
|
||||
ShareCount int `json:"share_count"`
|
||||
AgentShareCount int `json:"agent_share_count"` // 共享到该组织的智能体数量
|
||||
IsAlreadyMember bool `json:"is_already_member"`
|
||||
RequireApproval bool `json:"require_approval"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user