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
+61
View File
@@ -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<ApiResponse<SharedKnow
}
}
/**
* List all knowledge bases in an organization (including those shared by current tenant), for list page when a space is selected.
*/
export async function listOrganizationSharedKnowledgeBases(orgId: string): Promise<ApiResponse<OrganizationSharedKnowledgeBaseItem[]>> {
try {
const response = await get(`/api/v1/organizations/${orgId}/shared-knowledge-bases`)
return response as unknown as ApiResponse<OrganizationSharedKnowledgeBaseItem[]>
} 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<ApiResponse<SharedAgentInfo[]>
}
}
/** Response of GET /me/resource-counts: per-org counts for sidebar (one request instead of N). */
export interface MeResourceCountsResponse {
knowledge_bases: { by_organization: Record<string, number> }
agents: { by_organization: Record<string, number> }
}
/**
* Get per-organization resource counts for list sidebar (one request).
* 全部 total is not included; frontend keeps 全部 = 我的 + 他人共享给我.
*/
export async function getMeResourceCounts(): Promise<ApiResponse<MeResourceCountsResponse>> {
try {
const response = await get('/api/v1/me/resource-counts')
return response as unknown as ApiResponse<MeResourceCountsResponse>
} 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<ApiResponse<OrganizationSharedAgentItem[]>> {
try {
const response = await get(`/api/v1/organizations/${orgId}/shared-agents`)
return response as unknown as ApiResponse<OrganizationSharedAgentItem[]>
} catch (error: any) {
return { success: false, message: error.message || 'Failed to list organization shared agents' }
}
}
/** 设置当前用户对某共享智能体的停用状态(仅影响本人对话下拉显示) */
export async function setSharedAgentDisabledByMe(
agentId: string,
@@ -51,7 +51,7 @@
{{ org.share_count ?? 0 }}
</span>
<span class="org-meta-tag">
<t-icon name="control-platform" class="org-meta-icon org-meta-icon-agent" />
<img src="@/assets/img/agent.svg" class="org-meta-icon org-meta-icon-agent" alt="" aria-hidden="true" />
{{ org.agent_share_count ?? 0 }}
</span>
</div>
@@ -107,7 +107,7 @@
</span>
<t-tooltip :content="$t('organization.share.spaceAgentShareCountTip')" placement="top">
<span class="org-meta-tag">
<t-icon name="control-platform" class="org-meta-icon org-meta-icon-agent" />
<img src="@/assets/img/agent.svg" class="org-meta-icon org-meta-icon-agent" alt="" aria-hidden="true" />
{{ getOrgForShare(share.organization_id)?.agent_share_count ?? 0 }}
</span>
</t-tooltip>
@@ -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;
}
}
+10 -3
View File
@@ -7,8 +7,9 @@
</div>
</div>
<nav class="sidebar-nav">
<!-- 全部 -->
<!-- 全部:仅组织模式显示;知识库/智能体列表不展示「全部」 -->
<div
v-if="mode !== 'resource'"
class="sidebar-item"
:class="{ active: selected === 'all' }"
@click="select('all')"
@@ -32,12 +33,12 @@
</div>
<span v-if="countMine !== undefined" class="item-count">{{ countMine }}</span>
</div>
<template v-if="organizations.length">
<template v-if="organizationsWithCount.length">
<div class="sidebar-section">
<span class="section-title">{{ $t('listSpaceSidebar.spaces') }}</span>
</div>
<div
v-for="org in organizations"
v-for="org in organizationsWithCount"
:key="org.id"
class="sidebar-item org-item"
:class="{ active: selected === org.id }"
@@ -117,6 +118,12 @@ const selected = computed({
const organizations = computed(() => orgStore.organizations || [])
/** 资源模式下只展示数量大于 0 的空间 */
const organizationsWithCount = computed(() => {
if (props.mode !== 'resource') return organizations.value
return organizations.value.filter((org) => (props.countByOrg?.[org.id] ?? 0) > 0)
})
function select(value: string) {
selected.value = value
}
@@ -61,6 +61,9 @@
{{ detailCache[item.id].data.org_name || item.orgName }}
</span>
</span>
<span v-if="agentIdForDetail && (detailCache[item.id].data.org_name || item.orgName)" class="detail-readonly-hint">
{{ $t('mentionDetail.readOnlyFromAgent') }}
</span>
</div>
</template>
</div>
@@ -509,6 +512,14 @@ const scrollToItem = (index: number) => {
gap: 6px;
align-items: flex-start;
}
.mention-detail-content .detail-readonly-hint {
display: block;
margin-top: 6px;
font-size: var(--td-font-size-mark-small, 12px);
color: var(--td-text-color-placeholder, #999);
font-style: italic;
}
.mention-detail-content .detail-org,
.mention-detail-content .detail-kb {
display: inline-flex;
+14 -1
View File
@@ -917,6 +917,7 @@ export default {
noResult: 'No results',
},
mentionDetail: {
readOnlyFromAgent: 'Read-only in this conversation; not shown in Knowledge Base list',
faqCount: '{count} Q&A entries',
kbCount: '{count} documents',
belongsToKb: 'Knowledge base: ',
@@ -1115,6 +1116,8 @@ export default {
sharedToOrgs: 'Shared to {count} space(s)',
sharedLabel: 'Shared',
myLabel: 'Mine',
fromAgent: 'From agent {name}',
fromAgentShort: 'Agent: {name}',
tabs: {
all: 'All',
myKnowledgeBases: 'My Knowledge Bases',
@@ -1145,7 +1148,15 @@ export default {
overviewDesc: 'View knowledge base information and source',
permission: 'Permission',
permissionDesc: 'View your permissions for this knowledge base',
sourceOrg: 'Source Space',
sourceType: 'Source',
sourceTypeKbShare: 'KB shared directly to this space',
sourceTypeAgent: 'Visible via shared agent',
sourceOrg: 'Space',
sourceFromAgent: 'Agent',
agentKbStrategy: 'Agent KB strategy',
agentKbStrategyAll: 'All knowledge bases',
agentKbStrategySelected: 'Selected knowledge bases',
agentKbStrategyNone: 'No knowledge bases',
sharedAt: 'Shared At',
myPermission: 'My Permission',
canEdit: 'Can edit knowledge base content',
@@ -2531,6 +2542,8 @@ export default {
sharedAgents: 'Shared Agents',
noSharedAgents: 'No shared agents yet',
sharedAgentsDesc: 'Agents shared to this space; members can use them in chat',
sharedAgentsKbHint: 'Knowledge bases linked to an agent are only available (read-only) when members use that agent in a conversation (via @). They do not appear in the Knowledge Base list. To let members see or edit a knowledge base in the list, share that knowledge base to this space separately.',
sharedAgentsKbHintShort: 'Agent-linked knowledge is read-only in chat; share the KB to this space if members should see or edit it in the list.',
noSharedAgentsTip: 'Admins can share agents to this space from agent settings',
sharePermissionLabel: 'Space permission',
myPermissionLabel: 'My actual permission',
+13
View File
@@ -759,6 +759,7 @@ export default {
kbCount: "共 {count} 个文档",
belongsToKb: "所属知识库:",
belongsToOrg: "所属空间:",
readOnlyFromAgent: "仅在此对话中只读,不显示在知识库列表中",
},
agent: {
taskLabel: "任务:",
@@ -1507,6 +1508,8 @@ export default {
sharedToOrgs: "已共享给 {count} 个空间",
sharedLabel: "共享",
myLabel: "我的",
fromAgent: "来自智能体 {name}",
fromAgentShort: "智能体: {name}",
tabs: {
all: "全部",
myKnowledgeBases: "我的知识库",
@@ -1534,7 +1537,15 @@ export default {
overviewDesc: "查看知识库基本信息和来源",
permission: "权限",
permissionDesc: "查看您在此知识库的操作权限",
sourceType: "来源方式",
sourceTypeKbShare: "知识库直接共享到本空间",
sourceTypeAgent: "智能体可访问(通过共享智能体可见)",
sourceOrg: "来源空间",
sourceFromAgent: "智能体",
agentKbStrategy: "智能体知识库策略",
agentKbStrategyAll: "全部知识库",
agentKbStrategySelected: "指定知识库",
agentKbStrategyNone: "不使用知识库",
sharedAt: "共享时间",
myPermission: "我的权限",
canEdit: "可以编辑知识库内容",
@@ -2536,6 +2547,8 @@ export default {
sharedAgents: "共享智能体",
noSharedAgents: "暂无共享的智能体",
sharedAgentsDesc: "已共享到本空间的智能体,成员可在对话中使用",
sharedAgentsKbHint: "智能体绑定的知识库仅在成员使用该智能体对话时可 @ 使用(只读),不会出现在「知识库列表」中。若需成员在列表中看到或编辑知识库,请单独将知识库共享到本空间。",
sharedAgentsKbHintShort: "智能体绑定知识仅对话内只读;需在列表看到或编辑请单独共享知识库",
noSharedAgentsTip: "管理员可将智能体从智能体设置中共享到本空间",
sharePermissionLabel: "空间权限",
myPermissionLabel: "我的实际权限",
+89 -14
View File
@@ -14,7 +14,7 @@
v-model="spaceSelection"
:count-all="allAgentsCount"
:count-mine="agents.length"
:count-by-org="sharedCountByOrg"
:count-by-org="effectiveSharedCountByOrg"
>
<template #actions>
<t-tooltip :content="$t('agent.createAgent')" placement="top">
@@ -304,17 +304,20 @@
</div>
</div>
<!-- 按空间筛选:该空间下共享给我的智能体 -->
<div v-if="spaceSelectionOrgId && sharedAgentsByOrg.length > 0" class="agent-card-wrap">
<!-- 按空间筛选:该空间内全部智能体(含我共享的) -->
<div v-if="spaceSelectionOrgId && spaceAgentsLoading" class="agent-list-main-loading">
<t-loading size="large" text="" />
</div>
<div v-else-if="spaceSelectionOrgId && spaceAgentsList.length > 0" class="agent-card-wrap">
<div
v-for="shared in sharedAgentsByOrg"
v-for="shared in spaceAgentsList"
:key="'shared-' + shared.share_id"
class="agent-card shared-agent-card"
:class="{
'agent-mode-normal': shared.agent?.config?.agent_mode === 'quick-answer',
'agent-mode-agent': shared.agent?.config?.agent_mode === 'smart-reasoning'
}"
@click="openSharedAgentDetail(shared)"
@click="handleSpaceAgentCardClick(shared)"
>
<div class="card-decoration">
<svg class="star-icon" width="24" height="24" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -329,8 +332,10 @@
<div v-if="shared.agent?.avatar" class="builtin-avatar agent-emoji">{{ shared.agent.avatar }}</div>
<AgentAvatar v-else :name="shared.agent?.name" size="small" />
<span class="card-title" :title="shared.agent?.name">{{ shared.agent?.name }}</span>
<span v-if="shared.is_mine" class="shared-by-me-badge">{{ $t('listSpaceSidebar.mine') }}</span>
</div>
<t-popup
v-if="!shared.is_mine"
:visible="openMoreAgentId === 'shared-tab-' + shared.share_id"
trigger="hover"
overlayClassName="card-more-popup"
@@ -422,8 +427,8 @@
<span>{{ $t('agent.createAgent') }}</span>
</t-button>
</div>
<!-- 空状态:空间下共享给我 -->
<div v-if="spaceSelectionOrgId && sharedAgentsByOrg.length === 0 && !loading" class="empty-state">
<!-- 空状态:空间下 -->
<div v-if="spaceSelectionOrgId && !spaceAgentsLoading && spaceAgentsList.length === 0" class="empty-state">
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
<span class="empty-txt">{{ $t('agent.empty.sharedTitle') }}</span>
<span class="empty-desc">{{ $t('agent.empty.sharedDescription') }}</span>
@@ -527,7 +532,7 @@
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { MessagePlugin, Icon as TIcon } from 'tdesign-vue-next'
import { listAgents, deleteAgent, copyAgent, type CustomAgent } from '@/api/agent'
@@ -535,10 +540,10 @@ import { formatStringDate } from '@/utils/index'
import { useI18n } from 'vue-i18n'
import { createSessions } from '@/api/chat/index'
import { useOrganizationStore } from '@/stores/organization'
import { setSharedAgentDisabledByMe } from '@/api/organization'
import { setSharedAgentDisabledByMe, listOrganizationSharedAgents, getMeResourceCounts } from '@/api/organization'
import { useSettingsStore } from '@/stores/settings'
import { useMenuStore } from '@/stores/menu'
import type { SharedAgentInfo } from '@/api/organization'
import type { SharedAgentInfo, OrganizationSharedAgentItem } from '@/api/organization'
import AgentEditorModal from './AgentEditorModal.vue'
import AgentAvatar from '@/components/AgentAvatar.vue'
import ListSpaceSidebar from '@/components/ListSpaceSidebar.vue'
@@ -557,7 +562,8 @@ interface AgentWithUI extends CustomAgent {
/** Merged agent for "all" tab: my agents (isMine: true) or shared (isMine: false, org_name, source_tenant_id, share_id, disabled_by_me?) */
type DisplayAgent = (AgentWithUI & { isMine: true }) | (CustomAgent & { isMine: false; org_name: string; source_tenant_id: number; share_id: string; showMore?: boolean; disabled_by_me?: boolean })
const spaceSelection = ref<'all' | 'mine' | string>('all')
// 左侧空间选择:我的 / 空间 ID(已去掉「全部」)
const spaceSelection = ref<'all' | 'mine' | string>('mine')
const agents = ref<AgentWithUI[]>([])
const sharedAgents = computed<SharedAgentInfo[]>(() => orgStore.sharedAgents || [])
const allAgentsCount = computed(() => agents.value.length + sharedAgents.value.length)
@@ -573,7 +579,12 @@ const sharedAgentsByOrg = computed(() => {
return sharedAgents.value.filter(s => s.organization_id === orgId)
})
// 各空间下的共享智能体数量(用于侧栏展示,含 0 的也显示)
// 空间视角:该空间内全部智能体(含我共享的),选中空间时请求新接口
const spaceAgentsList = ref<OrganizationSharedAgentItem[]>([])
const spaceAgentsLoading = ref(false)
const spaceAgentCountByOrg = ref<Record<string, number>>({})
// 各空间下的共享智能体数量(用于侧栏展示):优先用接口返回的该空间总数
const sharedCountByOrg = computed<Record<string, number>>(() => {
const map: Record<string, number> = {}
sharedAgents.value.forEach(s => {
@@ -586,6 +597,14 @@ const sharedCountByOrg = computed<Record<string, number>>(() => {
})
return map
})
const effectiveSharedCountByOrg = computed<Record<string, number>>(() => {
const base = sharedCountByOrg.value
const merged = { ...base }
Object.keys(spaceAgentCountByOrg.value).forEach(orgId => {
merged[orgId] = spaceAgentCountByOrg.value[orgId]
})
return merged
})
const filteredAgents = computed<DisplayAgent[]>(() => {
if (spaceSelection.value === 'mine') {
@@ -652,8 +671,16 @@ const fetchList = () => {
}))
checkAndOpenEditModal()
}),
orgStore.fetchSharedAgents()
]).finally(() => loading.value = false)
orgStore.fetchSharedAgents(),
orgStore.fetchOrganizations()
]).finally(() => { loading.value = false }).then(() => {
// 一次请求拉取各空间内全部智能体数量(含我共享的),用于侧栏展示
getMeResourceCounts().then((res) => {
if (res.success && res.data?.agents?.by_organization) {
spaceAgentCountByOrg.value = { ...res.data.agents.by_organization }
}
})
})
}
// 检查 URL 参数并打开编辑模态框
@@ -680,6 +707,25 @@ const handleOpenAgentEditor = (event: CustomEvent) => {
}
}
// 选中空间时请求该空间内全部智能体(含我共享的)
watch(spaceSelection, (val) => {
if (val === 'all' || val === 'mine' || !val) {
spaceAgentsList.value = []
return
}
spaceAgentsLoading.value = true
listOrganizationSharedAgents(val).then((res) => {
if (res.success && res.data) {
spaceAgentsList.value = res.data
spaceAgentCountByOrg.value = { ...spaceAgentCountByOrg.value, [val]: res.data.length }
} else {
spaceAgentsList.value = []
}
}).finally(() => {
spaceAgentsLoading.value = false
})
}, { immediate: true })
onMounted(() => {
fetchList()
window.addEventListener('openAgentEditor', handleOpenAgentEditor as EventListener)
@@ -715,6 +761,15 @@ function openSharedAgentDetail(shared: SharedAgentInfo) {
sharedDetailVisible.value = true
}
/** 空间视角下点击卡片:我共享的进编辑,他人共享的打开详情抽屉 */
function handleSpaceAgentCardClick(shared: OrganizationSharedAgentItem) {
if (shared.is_mine && shared.agent) {
handleEdit({ ...shared.agent, showMore: false, disabled_by_me: shared.disabled_by_me } as AgentWithUI)
} else {
openSharedAgentDetail(shared)
}
}
function closeSharedAgentDetail() {
sharedDetailVisible.value = false
currentSharedAgent.value = null
@@ -907,6 +962,26 @@ defineExpose({
background: #fafbfc;
}
.agent-list-main-loading {
display: flex;
align-items: center;
justify-content: center;
min-height: 200px;
padding: 12px;
background: #fafbfc;
}
.shared-by-me-badge {
display: inline-flex;
align-items: center;
padding: 2px 6px;
background: rgba(7, 192, 95, 0.1);
border-radius: 4px;
font-size: 12px;
color: #07c05f;
margin-left: 6px;
}
.header {
display: flex;
align-items: center;
+10 -3
View File
@@ -64,10 +64,13 @@ const currentSharedKb = computed(() =>
orgStore.sharedKnowledgeBases.find((s) => s.knowledge_base?.id === kbId.value) ?? null,
);
// Effective permission: from direct org share list or from GET /knowledge-bases/:id (e.g. agent-visible KB)
const effectiveKBPermission = computed(() => orgStore.getKBPermission(kbId.value) || kbInfo.value?.my_permission || '');
// Display role label: owner or org role (admin/editor/viewer)
const accessRoleLabel = computed(() => {
if (isOwner.value) return t('knowledgeBase.accessInfo.roleOwner');
const perm = orgStore.getKBPermission(kbId.value);
const perm = effectiveKBPermission.value;
if (perm) return t(`organization.role.${perm}`);
return '--';
});
@@ -75,7 +78,7 @@ const accessRoleLabel = computed(() => {
// Permission summary text for current role
const accessPermissionSummary = computed(() => {
if (isOwner.value) return t('knowledgeBase.accessInfo.permissionOwner');
const perm = orgStore.getKBPermission(kbId.value);
const perm = effectiveKBPermission.value;
if (perm === 'admin') return t('knowledgeBase.accessInfo.permissionAdmin');
if (perm === 'editor') return t('knowledgeBase.accessInfo.permissionEditor');
if (perm === 'viewer') return t('knowledgeBase.accessInfo.permissionViewer');
@@ -1190,7 +1193,7 @@ async function createNewSession(value: string): Promise<void> {
<div v-if="kbInfo" class="kb-access-meta">
<t-tooltip :content="accessPermissionSummary" placement="top">
<span class="kb-access-meta-inner">
<t-tag size="small" :theme="isOwner ? 'success' : (currentSharedKb?.permission === 'admin' ? 'primary' : currentSharedKb?.permission === 'editor' ? 'warning' : 'default')" class="kb-access-role-tag">
<t-tag size="small" :theme="isOwner ? 'success' : (effectiveKBPermission === 'admin' ? 'primary' : effectiveKBPermission === 'editor' ? 'warning' : 'default')" class="kb-access-role-tag">
{{ accessRoleLabel }}
</t-tag>
<template v-if="currentSharedKb">
@@ -1200,6 +1203,10 @@ async function createNewSession(value: string): Promise<void> {
{{ $t('knowledgeBase.accessInfo.sharedAt') }} {{ formatStringDate(new Date(currentSharedKb.shared_at)) }}
</span>
</template>
<template v-else-if="effectiveKBPermission">
<span class="kb-access-meta-sep">·</span>
<span class="kb-access-meta-text">{{ $t('knowledgeList.detail.sourceTypeAgent') }}</span>
</template>
<template v-else-if="kbLastUpdated">
<span class="kb-access-meta-sep">·</span>
<span class="kb-access-meta-text">{{ $t('knowledgeBase.accessInfo.lastUpdated') }} {{ kbLastUpdated }}</span>
@@ -14,7 +14,7 @@
v-model="spaceSelection"
:count-all="allKnowledgeBases"
:count-mine="kbs.length"
:count-by-org="sharedCountByOrg"
:count-by-org="effectiveSharedCountByOrg"
>
<template #actions>
<t-tooltip :content="$t('knowledgeList.create')" placement="top">
@@ -340,11 +340,14 @@
</div>
</div>
<!-- 按空间筛选:该空间下共享给我的知识库 -->
<div v-if="spaceSelectionOrgId && sharedKbsByOrg.length > 0" class="kb-card-wrap">
<!-- 按空间筛选:该空间内全部知识库(含我共享的) -->
<div v-if="spaceSelectionOrgId && spaceKbsLoading" class="kb-list-main-loading">
<t-loading size="large" text="" />
</div>
<div v-else-if="spaceSelectionOrgId && spaceKbsList.length > 0" class="kb-card-wrap">
<div
v-for="shared in sharedKbsByOrg"
:key="'shared-' + shared.share_id"
v-for="shared in spaceKbsList"
:key="'shared-' + (shared.share_id || `agent-${shared.knowledge_base?.id}-${shared.source_from_agent?.agent_id || ''}`)"
class="kb-card shared-kb-card"
:class="{
'kb-type-document': (shared.knowledge_base.type || 'document') === 'document',
@@ -355,7 +358,10 @@
<!-- 卡片头部 -->
<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">
<t-tooltip v-if="shared.is_mine" :content="$t('knowledgeList.myLabel')" placement="top">
<span class="shared-by-me-badge">{{ $t('knowledgeList.myLabel') }}</span>
</t-tooltip>
<t-tooltip v-if="!shared.is_mine" :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>
@@ -415,8 +421,8 @@
</t-button>
</div>
<!-- 空间下共享知识库空状态 -->
<div v-if="spaceSelectionOrgId && sharedKbsByOrg.length === 0 && !loading" class="empty-state">
<!-- 空间下知识库空状态 -->
<div v-if="spaceSelectionOrgId && !spaceKbsLoading && spaceKbsList.length === 0" class="empty-state">
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
<span class="empty-txt">{{ $t('knowledgeList.empty.sharedTitle') || '暂无共享知识库' }}</span>
<span class="empty-desc">{{ $t('knowledgeList.empty.sharedDescription') || '您可以加入组织或请求他人共享知识库给您' }}</span>
@@ -482,10 +488,22 @@
<span class="shared-detail-value">{{ currentSharedKbForDetail.knowledge_base.name }}</span>
</div>
<div class="shared-detail-row">
<span class="shared-detail-label">{{ $t('knowledgeList.detail.sourceOrg') }}</span>
<span class="shared-detail-label">{{ $t('knowledgeList.detail.sourceType') }}</span>
<span class="shared-detail-value shared-detail-source-type">
{{ currentSharedKbForDetail.source_from_agent ? $t('knowledgeList.detail.sourceTypeAgent') : $t('knowledgeList.detail.sourceTypeKbShare') }}
</span>
</div>
<div class="shared-detail-row">
<span class="shared-detail-label">{{ currentSharedKbForDetail.source_from_agent ? $t('knowledgeList.detail.sourceFromAgent') : $t('knowledgeList.detail.sourceOrg') }}</span>
<span class="shared-detail-value shared-detail-org">
<img src="@/assets/img/organization-green.svg" class="shared-detail-org-icon" alt="" aria-hidden="true" />
{{ currentSharedKbForDetail.org_name }}
{{ currentSharedKbForDetail.source_from_agent ? currentSharedKbForDetail.source_from_agent.agent_name : currentSharedKbForDetail.org_name }}
</span>
</div>
<div v-if="currentSharedKbForDetail.source_from_agent" class="shared-detail-row">
<span class="shared-detail-label">{{ $t('knowledgeList.detail.agentKbStrategy') }}</span>
<span class="shared-detail-value">
{{ agentKbStrategyText(currentSharedKbForDetail.source_from_agent?.kb_selection_mode ?? '') }}
</span>
</div>
<div class="shared-detail-row">
@@ -522,7 +540,7 @@ import { listKnowledgeBases, deleteKnowledgeBase } from '@/api/knowledge-base'
import { formatStringDate } from '@/utils/index'
import { useUIStore } from '@/stores/ui'
import { useOrganizationStore } from '@/stores/organization'
import type { SharedKnowledgeBase } from '@/api/organization'
import { listOrganizationSharedKnowledgeBases, getMeResourceCounts, type SharedKnowledgeBase, type OrganizationSharedKnowledgeBaseItem, type SourceFromAgentInfo } from '@/api/organization'
import KnowledgeBaseEditorModal from './KnowledgeBaseEditorModal.vue'
import ShareKnowledgeBaseDialog from '@/components/ShareKnowledgeBaseDialog.vue'
import ListSpaceSidebar from '@/components/ListSpaceSidebar.vue'
@@ -534,8 +552,8 @@ const uiStore = useUIStore()
const orgStore = useOrganizationStore()
const { t } = useI18n()
// 左侧空间选择:全部 / 我的 / 空间 ID
const spaceSelection = ref<'all' | 'mine' | string>('all')
// 左侧空间选择:我的 / 空间 ID(已去掉「全部」)
const spaceSelection = ref<'all' | 'mine' | string>('mine')
interface KB {
id: string;
@@ -586,14 +604,19 @@ const spaceSelectionOrgId = computed(() => {
return s !== 'all' && s !== 'mine' && !!s
})
// 当前空间下共享给我的知识库
// 当前空间下共享给我的知识库(旧:仅他人共享;保留用于兼容)
const sharedKbsByOrg = computed(() => {
const orgId = spaceSelection.value
if (orgId === 'all' || orgId === 'mine') return []
return sharedKbs.value.filter(s => s.organization_id === orgId)
})
// 各空间下的共享知识库数量(用于侧栏展示,含 0 的也显示)
// 空间视角:该空间内全部知识库(含我共享的),选中空间时请求新接口
const spaceKbsList = ref<OrganizationSharedKnowledgeBaseItem[]>([])
const spaceKbsLoading = ref(false)
const spaceCountByOrg = ref<Record<string, number>>({})
// 各空间下的共享知识库数量(用于侧栏展示):优先用接口返回的该空间总数,否则用「共享给我」数量
const sharedCountByOrg = computed<Record<string, number>>(() => {
const map: Record<string, number> = {}
sharedKbs.value.forEach(s => {
@@ -606,6 +629,14 @@ const sharedCountByOrg = computed<Record<string, number>>(() => {
})
return map
})
const effectiveSharedCountByOrg = computed<Record<string, number>>(() => {
const base = sharedCountByOrg.value
const merged = { ...base }
Object.keys(spaceCountByOrg.value).forEach(orgId => {
merged[orgId] = spaceCountByOrg.value[orgId]
})
return merged
})
// Filtered knowledge bases: 全部 = 我的 + 全部共享;我的 = 仅我的
const filteredKnowledgeBases = computed(() => {
@@ -669,10 +700,37 @@ const fetchList = () => {
processing_count: kb.processing_count || 0
}))
}),
orgStore.fetchSharedKnowledgeBases()
]).finally(() => loading.value = false)
orgStore.fetchSharedKnowledgeBases(),
orgStore.fetchOrganizations()
]).finally(() => { loading.value = false }).then(() => {
// 一次请求拉取各空间内全部知识库数量(含我共享的),用于侧栏展示
getMeResourceCounts().then((res) => {
if (res.success && res.data?.knowledge_bases?.by_organization) {
spaceCountByOrg.value = { ...res.data.knowledge_bases.by_organization }
}
})
})
}
// 选中空间时请求该空间内全部知识库(含我共享的)
watch(spaceSelection, (val) => {
if (val === 'all' || val === 'mine' || !val) {
spaceKbsList.value = []
return
}
spaceKbsLoading.value = true
listOrganizationSharedKnowledgeBases(val).then((res) => {
if (res.success && res.data) {
spaceKbsList.value = res.data
spaceCountByOrg.value = { ...spaceCountByOrg.value, [val]: res.data.length }
} else {
spaceKbsList.value = []
}
}).finally(() => {
spaceKbsLoading.value = false
})
}, { immediate: true })
onMounted(() => {
fetchList().then(() => {
// 检查路由参数中是否有需要高亮的知识库ID
@@ -768,9 +826,10 @@ const handleSharedKbClickFromAll = (kb: any) => {
router.push(`/platform/knowledge-bases/${kb.id}`)
}
// 右侧详情面板:共享知识库详情
// 右侧详情面板:共享知识库详情(含直接共享与来自智能体的)
type SharedKbDetailItem = SharedKnowledgeBase & { is_mine?: boolean; source_from_agent?: SourceFromAgentInfo }
const sharedDetailPanelVisible = ref(false)
const currentSharedKbForDetail = ref<SharedKnowledgeBase | null>(null)
const currentSharedKbForDetail = ref<SharedKbDetailItem | null>(null)
const closeSharedDetailPanel = () => {
sharedDetailPanelVisible.value = false
@@ -786,12 +845,19 @@ const openSharedDetailFromAll = (kb: any) => {
}
}
// 打开右侧详情面板(共享给我 Tab)
const openSharedDetail = (sharedKb: SharedKnowledgeBase) => {
// 打开右侧详情面板(空间 Tab:直接共享或来自智能体)
const openSharedDetail = (sharedKb: SharedKbDetailItem) => {
currentSharedKbForDetail.value = sharedKb
sharedDetailPanelVisible.value = true
}
// 智能体对知识库的策略文案(用于抽屉「来源方式」为智能体时)
const agentKbStrategyText = (mode: string) => {
if (mode === 'all') return t('knowledgeList.detail.agentKbStrategyAll')
if (mode === 'selected') return t('knowledgeList.detail.agentKbStrategySelected')
return t('knowledgeList.detail.agentKbStrategyNone')
}
// 从右侧面板进入知识库
const goToSharedKbFromPanel = () => {
if (currentSharedKbForDetail.value) {
@@ -1095,6 +1161,26 @@ const handleUploadFinishedEvent = (event: Event) => {
background: #fafbfc;
}
.kb-list-main-loading {
display: flex;
align-items: center;
justify-content: center;
min-height: 200px;
padding: 12px;
background: #fafbfc;
}
.shared-by-me-badge {
display: inline-flex;
align-items: center;
padding: 2px 6px;
background: rgba(7, 192, 95, 0.1);
border-radius: 4px;
font-size: 12px;
color: #07c05f;
margin-left: 6px;
}
.header-subtitle {
margin: 0;
color: #00000099;
@@ -2119,6 +2205,11 @@ const handleUploadFinishedEvent = (event: Event) => {
line-height: 1.5;
word-break: break-word;
&.shared-detail-source-type {
font-weight: 500;
color: #0d0d0d;
}
&.shared-detail-org {
display: inline-flex;
align-items: center;
@@ -43,7 +43,7 @@
<div v-if="kbInfo" class="faq-access-meta">
<t-tooltip :content="accessPermissionSummary" placement="top">
<span class="faq-access-meta-inner">
<t-tag size="small" :theme="isOwner ? 'success' : (currentSharedKb?.permission === 'admin' ? 'primary' : currentSharedKb?.permission === 'editor' ? 'warning' : 'default')" class="faq-access-role-tag">
<t-tag size="small" :theme="isOwner ? 'success' : (effectiveKBPermission === 'admin' ? 'primary' : effectiveKBPermission === 'editor' ? 'warning' : 'default')" class="faq-access-role-tag">
{{ accessRoleLabel }}
</t-tag>
<template v-if="currentSharedKb">
@@ -53,6 +53,10 @@
{{ $t('knowledgeBase.accessInfo.sharedAt') }} {{ formatImportTime(currentSharedKb.shared_at) }}
</span>
</template>
<template v-else-if="effectiveKBPermission">
<span class="faq-access-meta-sep">·</span>
<span class="faq-access-meta-text">{{ $t('knowledgeList.detail.sourceTypeAgent') }}</span>
</template>
<template v-else-if="kbLastUpdated">
<span class="faq-access-meta-sep">·</span>
<span class="faq-access-meta-text">{{ $t('knowledgeBase.accessInfo.lastUpdated') }} {{ kbLastUpdated }}</span>
@@ -1304,10 +1308,13 @@ const currentSharedKb = computed(() =>
orgStore.sharedKnowledgeBases.find((s) => s.knowledge_base?.id === props.kbId) ?? null,
)
// Effective permission: from direct org share list or from GET /knowledge-bases/:id (e.g. agent-visible KB)
const effectiveKBPermission = computed(() => orgStore.getKBPermission(props.kbId) || kbInfo.value?.my_permission || '')
// Display role label: owner or org role (admin/editor/viewer)
const accessRoleLabel = computed(() => {
if (isOwner.value) return t('knowledgeBase.accessInfo.roleOwner')
const perm = orgStore.getKBPermission(props.kbId)
const perm = effectiveKBPermission.value
if (perm) return t(`organization.role.${perm}`)
return '--'
})
@@ -1315,7 +1322,7 @@ const accessRoleLabel = computed(() => {
// Permission summary text for current role
const accessPermissionSummary = computed(() => {
if (isOwner.value) return t('knowledgeBase.accessInfo.permissionOwner')
const perm = orgStore.getKBPermission(props.kbId)
const perm = effectiveKBPermission.value
if (perm === 'admin') return t('knowledgeBase.accessInfo.permissionAdmin')
if (perm === 'editor') return t('knowledgeBase.accessInfo.permissionEditor')
if (perm === 'viewer') return t('knowledgeBase.accessInfo.permissionViewer')
@@ -47,7 +47,7 @@
{{ org.share_count ?? 0 }}
</span>
<span class="org-meta-tag">
<t-icon name="control-platform" class="org-meta-icon org-meta-icon-agent" />
<img src="@/assets/img/agent.svg" class="org-meta-icon org-meta-icon-agent" alt="" aria-hidden="true" />
{{ org.agent_share_count ?? 0 }}
</span>
</div>
@@ -122,7 +122,7 @@
{{ getOrgForShare(share.organization_id)?.share_count ?? 0 }}
</span>
<span class="org-meta-tag">
<t-icon name="control-platform" class="org-meta-icon org-meta-icon-agent" />
<img src="@/assets/img/agent.svg" class="org-meta-icon org-meta-icon-agent" alt="" aria-hidden="true" />
{{ getOrgForShare(share.organization_id)?.agent_share_count ?? 0 }}
</span>
</div>
@@ -504,7 +504,8 @@ onMounted(async () => {
opacity: 0.75;
}
.org-meta-icon-agent {
font-size: 12px;
width: 12px;
height: 12px;
opacity: 0.75;
}
}
@@ -640,7 +641,8 @@ onMounted(async () => {
opacity: 0.75;
}
.org-meta-icon-agent {
font-size: 12px;
width: 12px;
height: 12px;
opacity: 0.75;
}
}
@@ -556,6 +556,14 @@
<div class="section-header">
<h2>{{ $t('organization.settings.sharedAgents') }}</h2>
<p class="section-description">{{ $t('organization.settings.sharedAgentsDesc') }}</p>
<p class="section-description permission-calc-hint">
<t-tooltip :content="$t('organization.settings.sharedAgentsKbHint')" placement="top" :show-delay="300">
<span class="hint-inner">
<t-icon name="info-circle" size="14px" />
{{ $t('organization.settings.sharedAgentsKbHintShort') }}
</span>
</t-tooltip>
</p>
</div>
<div class="settings-group">
<div v-if="sharedAgents.length === 0" class="empty-shared">