feat(api): enhance organization shared knowledge base and agent functionalities

- Introduced new interfaces for handling shared knowledge bases and agents, including visibility and selection modes for agents.
- Added API functions to list shared knowledge bases and agents within an organization, improving data retrieval for UI components.
- Updated existing components to utilize the new API endpoints and interfaces, ensuring accurate representation of shared resources.
- Enhanced error handling in API calls to provide clearer feedback on failures.

This update improves the functionality and user experience by providing better access to shared resources and enhancing the overall data structure within the application.
This commit is contained in:
wizardchen
2026-02-08 14:32:18 +08:00
committed by lyingbug
parent 1bdd9a4693
commit 9a073d62bf
25 changed files with 1119 additions and 118 deletions
+10
View File
@@ -90,6 +90,7 @@ type KBShareService interface {
ListSharesByKnowledgeBase(ctx context.Context, kbID string, tenantID uint64) ([]*types.KnowledgeBaseShare, error)
ListSharesByOrganization(ctx context.Context, orgID string) ([]*types.KnowledgeBaseShare, error)
ListSharedKnowledgeBases(ctx context.Context, userID string, currentTenantID uint64) ([]*types.SharedKnowledgeBaseInfo, error)
ListSharedKnowledgeBasesInOrganization(ctx context.Context, orgID string, userID string, currentTenantID uint64) ([]*types.OrganizationSharedKnowledgeBaseItem, error)
GetShare(ctx context.Context, shareID string) (*types.KnowledgeBaseShare, error)
GetShareByKBAndOrg(ctx context.Context, kbID string, orgID string) (*types.KnowledgeBaseShare, error)
@@ -102,6 +103,8 @@ type KBShareService interface {
// Count shares for knowledge bases
CountSharesByKnowledgeBaseIDs(ctx context.Context, kbIDs []string) (map[string]int64, error)
// CountByOrganizations returns share counts per organization (for sidebar); excludes deleted KBs
CountByOrganizations(ctx context.Context, orgIDs []string) (map[string]int64, error)
}
// KBShareRepository defines the knowledge base sharing repository interface
@@ -120,6 +123,7 @@ type KBShareRepository interface {
// List
ListByKnowledgeBase(ctx context.Context, kbID string) ([]*types.KnowledgeBaseShare, error)
ListByOrganization(ctx context.Context, orgID string) ([]*types.KnowledgeBaseShare, error)
CountByOrganizations(ctx context.Context, orgIDs []string) (map[string]int64, error)
// Query for user's accessible shared knowledge bases
ListSharedKBsForUser(ctx context.Context, userID string) ([]*types.KnowledgeBaseShare, error)
@@ -136,14 +140,19 @@ type AgentShareService interface {
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)
ListSharedAgentsInOrganization(ctx context.Context, orgID string, userID string, currentTenantID uint64) ([]*types.OrganizationSharedAgentItem, error)
// SetSharedAgentDisabledByMe sets whether the current tenant has "disabled" this shared agent for their conversation dropdown (per-user preference).
SetSharedAgentDisabledByMe(ctx context.Context, tenantID uint64, agentID string, sourceTenantID uint64, disabled bool) 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)
// UserCanAccessKBViaSomeSharedAgent returns true if the user has at least one shared agent that can access the given KB (for opening KB detail from "通过智能体可见" list without passing agent_id).
UserCanAccessKBViaSomeSharedAgent(ctx context.Context, userID string, currentTenantID uint64, kb *types.KnowledgeBase) (bool, error)
GetShare(ctx context.Context, shareID string) (*types.AgentShare, error)
GetShareByAgentAndOrg(ctx context.Context, agentID string, orgID string) (*types.AgentShare, error)
// GetShareByAgentIDForUser returns one share for the given agentID that the user can access, excluding source_tenant_id == excludeTenantID (e.g. current tenant to get shared-from-other only).
GetShareByAgentIDForUser(ctx context.Context, userID, agentID string, excludeTenantID uint64) (*types.AgentShare, error)
// CountByOrganizations returns share counts per organization (for sidebar); excludes deleted agents
CountByOrganizations(ctx context.Context, orgIDs []string) (map[string]int64, error)
}
// AgentShareRepository defines the agent sharing repository interface
@@ -158,6 +167,7 @@ type AgentShareRepository interface {
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)
CountByOrganizations(ctx context.Context, orgIDs []string) (map[string]int64, 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)
}
+31
View File
@@ -245,6 +245,27 @@ type SharedAgentInfo struct {
DisabledByMe bool `json:"disabled_by_me"`
}
// SourceFromAgentInfo indicates the KB is visible in the space via a shared agent (read-only, no KB share record).
type SourceFromAgentInfo struct {
AgentID string `json:"agent_id"`
AgentName string `json:"agent_name"`
KBSelectionMode string `json:"kb_selection_mode"` // "all" | "selected" | "none"; for drawer copy "该智能体对知识库的策略"
}
// OrganizationSharedKnowledgeBaseItem is used by GET /organizations/:id/shared-knowledge-bases (space-scoped list including mine).
// When SourceFromAgent is set, the KB is from a shared agent's config (no direct KB share); show as read-only and "来自智能体 XXX".
type OrganizationSharedKnowledgeBaseItem struct {
SharedKnowledgeBaseInfo
IsMine bool `json:"is_mine"`
SourceFromAgent *SourceFromAgentInfo `json:"source_from_agent,omitempty"`
}
// OrganizationSharedAgentItem is used by GET /organizations/:id/shared-agents (space-scoped list including mine).
type OrganizationSharedAgentItem struct {
SharedAgentInfo
IsMine bool `json:"is_mine"`
}
// TenantDisabledSharedAgent records that a tenant has "disabled" a shared agent for their own dropdown
type TenantDisabledSharedAgent struct {
TenantID uint64 `json:"tenant_id" gorm:"primaryKey"`
@@ -421,6 +442,16 @@ type ListOrganizationsResponse struct {
Total int64 `json:"total"`
}
// ResourceCountsByOrgResponse is the response for GET /me/resource-counts (sidebar counts per space)
type ResourceCountsByOrgResponse struct {
KnowledgeBases struct {
ByOrganization map[string]int `json:"by_organization"`
} `json:"knowledge_bases"`
Agents struct {
ByOrganization map[string]int `json:"by_organization"`
} `json:"agents"`
}
// SearchableOrganizationItem is a searchable org item for discovery (no invite code)
type SearchableOrganizationItem struct {
ID string `json:"id"`