diff --git a/frontend/src/components/ListSpaceSidebar.vue b/frontend/src/components/ListSpaceSidebar.vue index 891feb3b..b156e205 100644 --- a/frontend/src/components/ListSpaceSidebar.vue +++ b/frontend/src/components/ListSpaceSidebar.vue @@ -20,7 +20,7 @@ {{ countAll }} - + {{ countMine }} + + + + {{ $t('listSpaceSidebar.sharedToMe') }} + + {{ countShared }} + {{ $t('listSpaceSidebar.spaces') }} @@ -89,13 +101,15 @@ import { useOrganizationStore } from '@/stores/organization' const props = withDefaults( defineProps<{ - /** resource = 知识库/智能体(全部+我的+空间列表);organization = 共享空间(全部+我创建的+我加入的) */ + /** resource = 知识库/智能体(全部+我的+共享给我+空间列表);organization = 共享空间(全部+我创建的+我加入的) */ mode?: 'resource' | 'organization' modelValue: string /** 全部数量(可选) */ countAll?: number /** 我的数量(resource 模式) */ countMine?: number + /** 共享给我的数量(resource 模式) */ + countShared?: number /** 各空间下的数量(resource 模式),key 为 organization_id */ countByOrg?: Record /** 我创建的数量(organization 模式) */ @@ -103,7 +117,7 @@ const props = withDefaults( /** 我加入的数量(organization 模式) */ countJoined?: number }>(), - { mode: 'resource', countAll: undefined, countMine: undefined, countByOrg: () => ({}), countCreated: undefined, countJoined: undefined } + { mode: 'resource', countAll: undefined, countMine: undefined, countShared: undefined, countByOrg: () => ({}), countCreated: undefined, countJoined: undefined } ) const emit = defineEmits<{ diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 671914cd..e07d46f5 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -18,6 +18,7 @@ export default { title: 'Filter', all: 'All', mine: 'Mine', + sharedToMe: 'Collaborative', spaces: 'Spaces' }, knowledgeBase: { @@ -387,6 +388,9 @@ export default { noKnowledgeBase: 'No Knowledge Base', noKnowledgeBaseDesc: 'Pure model conversation, no knowledge retrieval', selectKnowledgeBases: 'Select Knowledge Bases', + selectKnowledgeBasesDesc: 'Select knowledge bases to associate (including collaborative ones)', + myKnowledgeBases: 'My Knowledge Bases', + sharedKnowledgeBases: 'Collaborative Knowledge Bases', retrieveKBOnlyWhenMentioned: 'Retrieve Only When Mentioned', retrieveKBOnlyWhenMentionedDesc: "Off: auto-retrieve configured KBs; On: retrieve only when user {'@'} mentions", rerankModel: 'ReRank Model', @@ -1124,6 +1128,7 @@ export default { sharedToMe: 'Shared with me', }, uninitializedBanner: 'Some knowledge bases are not initialized. Configure model information in settings before adding documents.', + emptyShared: 'No collaborative knowledge bases yet. Join a shared space to access knowledge bases from others.', empty: { title: 'No knowledge bases yet', description: 'Click "Create Knowledge Base" in the top-right corner to add your first one.', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 7b731c6d..85072643 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -18,6 +18,7 @@ export default { title: "筛选", all: "全部", mine: "我的", + sharedToMe: "协作", spaces: "空间", }, knowledgeBase: { @@ -926,6 +927,9 @@ export default { noKnowledgeBase: "不使用知识库", noKnowledgeBaseDesc: "纯模型对话,不检索知识库", selectKnowledgeBases: "选择知识库", + selectKnowledgeBasesDesc: "选择要关联的知识库(包括协作知识库)", + myKnowledgeBases: "我的知识库", + sharedKnowledgeBases: "协作知识库", retrieveKBOnlyWhenMentioned: "仅在 {'@'} 提及时检索", retrieveKBOnlyWhenMentionedDesc: "关闭:自动检索已配置的知识库,开启:仅当用户 {'@'} 提及时才检索", rerankModel: "ReRank 模型", @@ -1517,6 +1521,7 @@ export default { }, uninitializedBanner: "部分知识库尚未初始化,需要先在设置中配置模型信息才能添加知识文档", + emptyShared: "暂无协作知识库,可以加入共享空间获取他人共享的知识库", empty: { title: "暂无知识库", description: '点击左侧快捷操作"新建知识库"按钮创建第一个知识库', diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vue index 2ecdb18a..9771d5b3 100644 --- a/frontend/src/views/agent/AgentEditorModal.vue +++ b/frontend/src/views/agent/AgentEditorModal.vue @@ -665,7 +665,7 @@ {{ $t('agent.editor.selectKnowledgeBases') }} - 选择要关联的知识库 + {{ $t('agent.editor.selectKnowledgeBasesDesc') }} - - - - - - {{ kb.label }} - ({{ kb.count || 0 }}) - - + + + + + + + {{ kb.label }} + {{ kb.count || 0 }} + + + + + + + + + + {{ kb.label }} + {{ kb.orgName }} + {{ kb.count || 0 }} + + + @@ -1048,12 +1068,14 @@ import { listMCPServices, type MCPService } from '@/api/mcp-service'; import { listSkills, type SkillInfo } from '@/api/skill'; import { getAgentConfig, getConversationConfig } from '@/api/system'; import { useUIStore } from '@/stores/ui'; +import { useOrganizationStore } from '@/stores/organization'; import AgentAvatar from '@/components/AgentAvatar.vue'; import PromptTemplateSelector from '@/components/PromptTemplateSelector.vue'; import ModelSelector from '@/components/ModelSelector.vue'; import AgentShareSettings from '@/components/AgentShareSettings.vue'; const uiStore = useUIStore(); +const orgStore = useOrganizationStore(); const { t } = useI18n(); @@ -1072,7 +1094,7 @@ const emit = defineEmits<{ const currentSection = ref(props.initialSection || 'basic'); const saving = ref(false); const allModels = ref([]); -const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number }[]>([]); +const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number; shared?: boolean; orgName?: string }[]>([]); const mcpOptions = ref<{ label: string; value: string }[]>([]); const skillOptions = ref<{ name: string; description: string }[]>([]); // 是否允许启用 Skills(取决于后端沙箱是否启用,disabled 时为 false;未请求前为 false 避免闪显) @@ -1124,6 +1146,10 @@ const allTools = [ { value: 'data_schema', label: '查看数据元信息', description: '获取表格文件的元信息', requiresKB: true }, ]; +// 知识库分组:我的 vs 共享的 +const myKbOptions = computed(() => kbOptions.value.filter(kb => !kb.shared)); +const sharedKbOptions = computed(() => kbOptions.value.filter(kb => kb.shared)); + // 根据知识库配置动态计算是否有知识库能力 const hasKnowledgeBase = computed(() => { return kbSelectionMode.value !== 'none'; @@ -1635,17 +1661,46 @@ const loadDependencies = async () => { allModels.value = models; } - // 加载知识库列表 + // 加载知识库列表(我的 + 共享的) const kbRes: any = await listKnowledgeBases(); + const myKbs: typeof kbOptions.value = []; if (kbRes.data) { - kbOptions.value = kbRes.data.map((kb: any) => ({ - label: kb.name, - value: kb.id, - type: kb.type || 'document', - count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0) - })); + kbRes.data.forEach((kb: any) => { + myKbs.push({ + label: kb.name, + value: kb.id, + type: kb.type || 'document', + count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0), + shared: false, + }); + }); } + // 加载共享给我的知识库 + const sharedKbs: typeof kbOptions.value = []; + try { + const sharedList = await orgStore.fetchSharedKnowledgeBases(); + if (sharedList && sharedList.length > 0) { + const myKbIds = new Set(myKbs.map(kb => kb.value)); + sharedList.forEach((shared: any) => { + const kb = shared.knowledge_base; + if (!kb || myKbIds.has(kb.id)) return; + sharedKbs.push({ + label: kb.name, + value: kb.id, + type: kb.type || 'document', + count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0), + shared: true, + orgName: shared.org_name, + }); + }); + } + } catch (e) { + console.warn('Failed to load shared knowledge bases', e); + } + + kbOptions.value = [...myKbs, ...sharedKbs]; + // 加载 MCP 服务列表(只加载启用的) try { const mcpList = await listMCPServices(); @@ -3404,7 +3459,8 @@ const handleSave = async () => { .kb-option-item { display: flex; align-items: center; - gap: 6px; + gap: 8px; + padding: 2px 0; } .kb-option-icon { @@ -3412,15 +3468,20 @@ const handleSave = async () => { align-items: center; justify-content: center; flex-shrink: 0; - font-size: 16px; + width: 24px; + height: 24px; + border-radius: 6px; + font-size: 14px; - // Document KB - Greenish + // Document KB &.doc-icon { + background: rgba(16, 185, 129, 0.1); color: #10b981; } - // FAQ KB - Blueish + // FAQ KB &.faq-icon { + background: rgba(0, 82, 217, 0.1); color: #0052d9; } } @@ -3430,12 +3491,30 @@ const handleSave = async () => { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + font-size: 13px; + color: #1d2129; +} + +.kb-option-org { + flex-shrink: 0; + font-size: 11px; + color: #8c8c8c; + background: #f2f3f5; + padding: 1px 6px; + border-radius: 4px; + max-width: 100px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .kb-option-count { flex-shrink: 0; - font-size: 12px; - color: #999; + font-size: 11px; + color: #8c8c8c; + background: #f2f3f5; + padding: 1px 6px; + border-radius: 4px; } // FAQ 策略区域样式 diff --git a/frontend/src/views/knowledge/KnowledgeBaseList.vue b/frontend/src/views/knowledge/KnowledgeBaseList.vue index 8fa28f6b..9e0a2bd7 100644 --- a/frontend/src/views/knowledge/KnowledgeBaseList.vue +++ b/frontend/src/views/knowledge/KnowledgeBaseList.vue @@ -14,6 +14,7 @@ v-model="spaceSelection" :count-all="allKnowledgeBases" :count-mine="kbs.length" + :count-shared="sharedKbs.length" :count-by-org="effectiveSharedCountByOrg" > @@ -340,6 +341,60 @@ + + + + + {{ shared.knowledge_base.name }} + + + + + + + + + {{ shared.knowledge_base.description || $t('knowledgeBase.noDescription') }} + + + + + + + + + {{ shared.knowledge_base.type === 'faq' ? (shared.knowledge_base.chunk_count || '-') : (shared.knowledge_base.knowledge_count || '-') }} + + + + + + + + + {{ shared.org_name }} + + + + + + + + + + + {{ $t('knowledgeList.emptyShared') }} + + @@ -553,7 +608,7 @@ const orgStore = useOrganizationStore() const { t } = useI18n() // 左侧空间选择:我的 / 空间 ID(已去掉「全部」) -const spaceSelection = ref<'all' | 'mine' | string>('mine') +const spaceSelection = ref<'all' | 'mine' | 'shared' | string>('mine') interface KB { id: string; @@ -601,7 +656,7 @@ const allKnowledgeBases = computed(() => kbs.value.length + sharedKbs.value.leng // 当前选中的是空间 ID(非全部、非我的) const spaceSelectionOrgId = computed(() => { const s = spaceSelection.value - return s !== 'all' && s !== 'mine' && !!s + return s !== 'all' && s !== 'mine' && s !== 'shared' && !!s }) // 当前空间下共享给我的知识库(旧:仅他人共享;保留用于兼容) @@ -711,7 +766,7 @@ const fetchList = () => { // 选中空间时请求该空间内全部知识库(含我共享的) watch(spaceSelection, (val) => { - if (val === 'all' || val === 'mine' || !val) { + if (val === 'all' || val === 'mine' || val === 'shared' || !val) { spaceKbsList.value = [] return }
选择要关联的知识库
{{ $t('agent.editor.selectKnowledgeBasesDesc') }}
{{ $t('knowledgeList.emptyShared') }}