From 9a073d62bfe001c7740d4426f9284d0cc97fc8e6 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Sun, 8 Feb 2026 14:32:18 +0800 Subject: [PATCH] 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. --- frontend/src/api/organization/index.ts | 61 +++++ .../src/components/AgentShareSettings.vue | 10 +- frontend/src/components/ListSpaceSidebar.vue | 13 +- frontend/src/components/MentionSelector.vue | 11 + frontend/src/i18n/locales/en-US.ts | 15 +- frontend/src/i18n/locales/zh-CN.ts | 13 + frontend/src/views/agent/AgentList.vue | 103 +++++++- .../src/views/knowledge/KnowledgeBase.vue | 13 +- .../src/views/knowledge/KnowledgeBaseList.vue | 133 ++++++++-- .../knowledge/components/FAQEntryManager.vue | 13 +- .../knowledge/settings/KBShareSettings.vue | 10 +- .../OrganizationSettingsModal.vue | 8 + .../application/repository/agent_share.go | 30 +++ internal/application/repository/kbshare.go | 30 +++ internal/application/service/agent_share.go | 110 ++++++++ internal/application/service/kbshare.go | 64 +++++ internal/handler/chunk.go | 34 ++- internal/handler/faq.go | 164 ++++++++++-- internal/handler/knowledge.go | 24 +- internal/handler/knowledgebase.go | 64 +++-- internal/handler/organization.go | 246 ++++++++++++++++++ internal/handler/tag.go | 21 +- internal/router/router.go | 6 + internal/types/interfaces/organization.go | 10 + internal/types/organization.go | 31 +++ 25 files changed, 1119 insertions(+), 118 deletions(-) diff --git a/frontend/src/api/organization/index.ts b/frontend/src/api/organization/index.ts index 41baf4e5..86ada70e 100644 --- a/frontend/src/api/organization/index.ts +++ b/frontend/src/api/organization/index.ts @@ -74,6 +74,21 @@ export interface SharedKnowledgeBase { shared_at: string } +/** When set, this KB is visible in the space via a shared agent (read-only, no direct KB share) */ +export interface SourceFromAgentInfo { + agent_id: string + agent_name: string + /** "all" | "selected" | "none" — for showing agent's KB strategy in the drawer */ + kb_selection_mode?: string +} + +/** Item from GET /organizations/:id/shared-knowledge-bases (space-scoped list including mine and agent-carried) */ +export type OrganizationSharedKnowledgeBaseItem = SharedKnowledgeBase & { + is_mine: boolean + /** Present when the KB is from a shared agent's config (not directly shared to the space) */ + source_from_agent?: SourceFromAgentInfo +} + export interface OrganizationPreview { id: string name: string @@ -245,6 +260,9 @@ export interface SharedAgentInfo { disabled_by_me?: boolean } +/** Item from GET /organizations/:id/shared-agents (space-scoped list including mine) */ +export type OrganizationSharedAgentItem = SharedAgentInfo & { is_mine: boolean } + export interface ListAgentSharesResponse { shares: AgentShareResponse[] total: number @@ -554,6 +572,18 @@ export async function listSharedKnowledgeBases(): Promise> { + try { + const response = await get(`/api/v1/organizations/${orgId}/shared-knowledge-bases`) + return response as unknown as ApiResponse + } catch (error: any) { + return { success: false, message: error.message || 'Failed to list organization shared knowledge bases' } + } +} + /** * List knowledge bases shared to a specific organization */ @@ -612,6 +642,37 @@ export async function listSharedAgents(): Promise } } +/** Response of GET /me/resource-counts: per-org counts for sidebar (one request instead of N). */ +export interface MeResourceCountsResponse { + knowledge_bases: { by_organization: Record } + agents: { by_organization: Record } +} + +/** + * Get per-organization resource counts for list sidebar (one request). + * 全部 total is not included; frontend keeps 全部 = 我的 + 他人共享给我. + */ +export async function getMeResourceCounts(): Promise> { + try { + const response = await get('/api/v1/me/resource-counts') + return response as unknown as ApiResponse + } catch (error: any) { + return { success: false, message: error.message || 'Failed to get resource counts' } + } +} + +/** + * List all agents in an organization (including those shared by current tenant), for list page when a space is selected. + */ +export async function listOrganizationSharedAgents(orgId: string): Promise> { + try { + const response = await get(`/api/v1/organizations/${orgId}/shared-agents`) + return response as unknown as ApiResponse + } catch (error: any) { + return { success: false, message: error.message || 'Failed to list organization shared agents' } + } +} + /** 设置当前用户对某共享智能体的停用状态(仅影响本人对话下拉显示) */ export async function setSharedAgentDisabledByMe( agentId: string, diff --git a/frontend/src/components/AgentShareSettings.vue b/frontend/src/components/AgentShareSettings.vue index 150c8db9..1094654b 100644 --- a/frontend/src/components/AgentShareSettings.vue +++ b/frontend/src/components/AgentShareSettings.vue @@ -51,7 +51,7 @@ {{ org.share_count ?? 0 }} - + {{ org.agent_share_count ?? 0 }} @@ -107,7 +107,7 @@ - + {{ getOrgForShare(share.organization_id)?.agent_share_count ?? 0 }} @@ -378,7 +378,8 @@ defineExpose({ loadShares }) opacity: 0.75; } .org-meta-icon-agent { - font-size: 12px; + width: 12px; + height: 12px; opacity: 0.75; } } @@ -491,7 +492,8 @@ defineExpose({ loadShares }) opacity: 0.75; } .org-meta-icon-agent { - font-size: 12px; + width: 12px; + height: 12px; opacity: 0.75; } } diff --git a/frontend/src/components/ListSpaceSidebar.vue b/frontend/src/components/ListSpaceSidebar.vue index cb88110d..891feb3b 100644 --- a/frontend/src/components/ListSpaceSidebar.vue +++ b/frontend/src/components/ListSpaceSidebar.vue @@ -7,8 +7,9 @@