Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat(ui): enhance resource management in ListSpaceSidebar and KnowledgeBaseList

wizardchen10b6c98078dc
diff --git a/frontend/src/components/ListSpaceSidebar.vue b/frontend/src/components/ListSpaceSidebar.vue
index 891feb3b6..b156e2055 100644
--- a/frontend/src/components/ListSpaceSidebar.vue
+++ b/frontend/src/components/ListSpaceSidebar.vue
@@ -20,7 +20,7 @@
</div>
<span v-if="countAll !== undefined" class="item-count">{{ countAll }}</span>
</div>
- <!-- 资源列表模式:我的 + 空间列表 -->
+ <!-- 资源列表模式:我的 + 共享给我 + 空间列表 -->
<template v-if="mode === 'resource'">
<div
class="sidebar-item"
@@ -33,6 +33,18 @@
</div>
<span v-if="countMine !== undefined" class="item-count">{{ countMine }}</span>
</div>
+ <div
+ v-if="countShared !== undefined && countShared > 0"
+ class="sidebar-item"
+ :class="{ active: selected === 'shared' }"
+ @click="select('shared')"
+ >
+ <div class="item-left">
+ <t-icon name="share" class="item-icon" />
+ <span class="item-label">{{ $t('listSpaceSidebar.sharedToMe') }}</span>
+ </div>
+ <span class="item-count">{{ countShared }}</span>
+ </div>
<template v-if="organizationsWithCount.length">
<div class="sidebar-section">
<span class="section-title">{{ $t('listSpaceSidebar.spaces') }}</span>
@@ -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<string, number>
/** 我创建的数量(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 671914cd0..e07d46f53 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 7b731c6d2..850726436 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 2ecdb18a4..9771d5b36 100644
--- a/frontend/src/views/agent/AgentEditorModal.vue
+++ b/frontend/src/views/agent/AgentEditorModal.vue
@@ -665,7 +665,7 @@
<div v-if="kbSelectionMode === 'selected'" class="setting-row">
<div class="setting-info">
<label>{{ $t('agent.editor.selectKnowledgeBases') }}</label>
- <p class="desc">选择要关联的知识库</p>
+ <p class="desc">{{ $t('agent.editor.selectKnowledgeBasesDesc') }}</p>
</div>
<div class="setting-control">
<t-select
@@ -673,21 +673,41 @@
multiple
:placeholder="$t('agent.editor.selectKnowledgeBases')"
filterable
+ :min-collapsed-num="3"
>
- <t-option
- v-for="kb in kbOptions"
- :key="kb.value"
- :value="kb.value"
- :label="kb.label"
- >
- <div class="kb-option-item">
- <span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
- <t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
- </span>
- <span class="kb-option-label">{{ kb.label }}</span>
- <span class="kb-option-count">({{ kb.count || 0 }})</span>
- </div>
- </t-option>
+ <t-option-group v-if="myKbOptions.length" :label="$t('agent.editor.myKnowledgeBases')">
+ <t-option
+ v-for="kb in myKbOptions"
+ :key="kb.value"
+ :value="kb.value"
+ :label="kb.label"
+ >
+ <div class="kb-option-item">
+ <span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
+ <t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
+ </span>
+ <span class="kb-option-label">{{ kb.label }}</span>
+ <span class="kb-option-count">{{ kb.count || 0 }}</span>
+ </div>
+ </t-option>
+ </t-option-group>
+ <t-option-group v-if="sharedKbOptions.length" :label="$t('agent.editor.sharedKnowledgeBases')">
+ <t-option
+ v-for="kb in sharedKbOptions"
+ :key="kb.value"
+ :value="kb.value"
+ :label="kb.label"
+ >
+ <div class="kb-option-item">
+ <span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
+ <t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
+ </span>
+ <span class="kb-option-label">{{ kb.label }}</span>
+ <span v-if="kb.orgName" class="kb-option-org">{{ kb.orgName }}</span>
+ <span class="kb-option-count">{{ kb.count || 0 }}</span>
+ </div>
+ </t-option>
+ </t-option-group>
</t-select>
</div>
</div>
@@ -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<ModelConfig[]>([]);
-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 8fa28f6b4..9e0a2bd73 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"
>
<template #actions>
@@ -340,6 +341,60 @@
</div>
</div>
+ <!-- 卡片网格:共享给我 -->
+ <div v-if="spaceSelection === 'shared' && sharedKbs.length > 0" class="kb-card-wrap">
+ <div
+ v-for="shared in sharedKbs"
+ :key="'shared-' + shared.share_id"
+ class="kb-card shared-kb-card"
+ :class="{
+ 'kb-type-document': (shared.knowledge_base.type || 'document') === 'document',
+ 'kb-type-faq': shared.knowledge_base.type === 'faq'
+ }"
+ @click="handleSharedKbClickFromAll(shared.knowledge_base)"
+ >
+ <div class="card-header">
+ <span class="card-title" :title="shared.knowledge_base.name">{{ shared.knowledge_base.name }}</span>
+ <t-tooltip :content="$t('knowledgeList.menu.viewDetails')" placement="top">
+ <button type="button" class="shared-detail-trigger" @click.stop="openSharedDetail(shared)" :aria-label="$t('knowledgeList.menu.viewDetails')">
+ <t-icon name="info-circle" size="16px" />
+ </button>
+ </t-tooltip>
+ </div>
+ <div class="card-content">
+ <div class="card-description">
+ {{ shared.knowledge_base.description || $t('knowledgeBase.noDescription') }}
+ </div>
+ </div>
+ <div class="card-bottom">
+ <div class="bottom-left">
+ <div class="feature-badges">
+ <t-tooltip :content="shared.knowledge_base.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument')" placement="top">
+ <div class="feature-badge" :class="{ 'type-document': (shared.knowledge_base.type || 'document') === 'document', 'type-faq': shared.knowledge_base.type === 'faq' }">
+ <t-icon :name="shared.knowledge_base.type === 'faq' ? 'chat-bubble-help' : 'folder'" size="14px" />
+ <span class="badge-count">{{ shared.knowledge_base.type === 'faq' ? (shared.knowledge_base.chunk_count || '-') : (shared.knowledge_base.knowledge_count || '-') }}</span>
+ </div>
+ </t-tooltip>
+ </div>
+ </div>
+ <div class="bottom-right">
+ <t-tooltip :content="shared.org_name" placement="top">
+ <div class="org-source">
+ <img src="@/assets/img/organization-green.svg" class="org-source-icon" alt="" aria-hidden="true" />
+ <span>{{ shared.org_name }}</span>
+ </div>
+ </t-tooltip>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 共享给我空状态 -->
+ <div v-if="spaceSelection === 'shared' && sharedKbs.length === 0 && !loading" class="empty-state">
+ <t-icon name="share" size="48px" class="empty-icon" />
+ <p>{{ $t('knowledgeList.emptyShared') }}</p>
+ </div>
+
<!-- 按空间筛选:该空间内全部知识库(含我共享的) -->
<div v-if="spaceSelectionOrgId && spaceKbsLoading" class="kb-list-main-loading">
<t-loading size="large" text="" />
@@ -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
}